@clearlayer/sdk
v1.0.0
Published
TypeScript SDK for the Clearlayer compliance API
Maintainers
Readme
@clearlayer/sdk
TypeScript SDK for the Clearlayer compliance API.
Install
npm install @clearlayer/sdkQuickstart
import { Clearlayer } from '@clearlayer/sdk'
const client = new Clearlayer({ apiKey: 'cl_...' })
// Create an investor
const investor = await client.investors.create({
name: 'Alice Johnson',
type: 'individual',
country: 'US',
kyc_status: 'verified',
accredited_status: true,
})
// Create a wallet (auto-screened via TRM Labs)
const wallet = await client.wallets.create({
address: '0xABCDEF1234567890ABCDEF1234567890ABCDEF12',
investor_id: investor.id,
})
// Create a policy
const policy = await client.policies.create({
name: 'US Accredited Only',
requires_kyc: true,
requires_accredited: true,
allowed_countries: ['US'],
wallet_must_be_verified: true,
})
// Run a compliance decision
const decision = await client.decisions.create({
investor_id: investor.id,
wallet_id: wallet.id,
asset_policy_id: policy.id,
action: 'transfer',
})
console.log(decision)
// { decision: 'allow', reasons: ['policy_requirements_satisfied'], audit_id: 'dec_...', ... }Configuration
const client = new Clearlayer({
apiKey: 'cl_...',
baseUrl: 'http://localhost:3000', // defaults to production URL
})Resources
Organizations
// Create a new org (returns org + API key, no auth required)
const org = await client.organizations.create({ name: 'My Protocol' })
console.log(org.api_key) // use this key for all subsequent callsInvestors
await client.investors.create({ name, type, country, kyc_status, accredited_status })
await client.investors.list()
await client.investors.updateReviewStatus(id, { review_status: 'approved' })Wallets
await client.wallets.create({ address, investor_id })
await client.wallets.screen(id) // re-screen via TRM LabsPolicies
await client.policies.create({ name, requires_kyc, requires_accredited, ... })
await client.policies.list()Decisions
await client.decisions.create({ investor_id, wallet_id, asset_policy_id, action })
await client.decisions.get(id)
await client.decisions.list() // all decisions
await client.decisions.list('deny') // filter by resultError handling
import { Clearlayer, ClearlayerError } from '@clearlayer/sdk'
try {
await client.decisions.get('dec_nonexistent')
} catch (err) {
if (err instanceof ClearlayerError) {
console.log(err.status) // 404
console.log(err.error) // "decision_not_found"
console.log(err.message) // "No decision found with id dec_nonexistent..."
console.log(err.docs) // "https://docs.clearlayer.io/decisions"
}
}