Installation
Copy
npm install @txcloud/sdk
# or
yarn add @txcloud/sdk
# or
pnpm add @txcloud/sdk
Quick Start
Copy
import TXCloud from '@txcloud/sdk';
const txcloud = new TXCloud({
apiKey: process.env.TXCLOUD_API_KEY,
environment: 'production' // or 'sandbox'
});
// Verify identity
const verification = await txcloud.identity.verify({
document_front: documentBase64,
country: 'MA',
document_type: 'national_id'
});
console.log(verification.status);
Configuration
Copy
const txcloud = new TXCloud({
apiKey: 'txc_live_xxx',
environment: 'production',
timeout: 30000, // 30 seconds
maxRetries: 3
});
TypeScript Support
Full TypeScript definitions included:Copy
import TXCloud, { Verification, VerifyRequest } from '@txcloud/sdk';
const request: VerifyRequest = {
document_front: '...',
country: 'MA'
};
const verification: Verification = await txcloud.identity.verify(request);
Error Handling
Copy
import { TXCloudError, ValidationError, RateLimitError } from '@txcloud/sdk';
try {
const result = await txcloud.identity.verify({ ... });
} catch (error) {
if (error instanceof ValidationError) {
console.log('Validation failed:', error.message);
} else if (error instanceof RateLimitError) {
console.log('Rate limited, retry after:', error.retryAfter);
} else if (error instanceof TXCloudError) {
console.log('API error:', error.code);
}
}
Webhook Verification
Copy
import { verifyWebhookSignature } from '@txcloud/sdk';
app.post('/webhooks', (req, res) => {
const isValid = verifyWebhookSignature(
req.body,
req.headers['x-txcloud-signature'],
webhookSecret
);
if (!isValid) {
return res.status(401).send('Invalid signature');
}
// Process webhook
});
API Reference
All API methods are available:Copy
// Identity
txcloud.identity.verify()
txcloud.identity.verifications.get()
txcloud.identity.verifications.list()
// Fraud
txcloud.fraud.devices.register()
txcloud.fraud.duplicates.search()
txcloud.fraud.rules.create()
// Transactions
txcloud.transactions.score()
txcloud.transactions.report()
// Lending
txcloud.lending.assess()
txcloud.lending.statements.upload()
// KYB
txcloud.kyb.verify()
txcloud.kyb.companies.getUBOs()
// Watchlist
txcloud.watchlist.screen()
txcloud.watchlist.screenBatch()
// Developers
txcloud.developers.webhooks.create()
txcloud.developers.usage.summary()