@corsa-labs/sdk

中文文档
5.0.1发布于 2026/10/20MITTypeScriptCommonJS近 30 天下载 1.7万

Official Node.js SDK for Corsa (corsa.finance), the agentic compliance OS: AML transaction monitoring, alerts, cases, KYC/KYB and risk APIs.

原始使用文档
文档目录15 节
  1. Table of Contents
  2. Installation
  3. API Client Usage
  4. Configuration
  5. Available Services
  6. Working Example For API requests
  7. Webhook Handling
  8. Webhook Headers
  9. Verifying Signatures
  10. Event Types
  11. Development
  12. Building
  13. Testing
  14. Contributing
  15. License

@corsa-labs/sdk

npm version

Official Node.js SDK for Corsa, the agentic compliance OS for banks, financial institutions and fintechs. Use it to send clients, accounts and transactions to Corsa, manage alerts, cases and monitoring rules, and handle webhooks.

Documentation: docs.corsa.finance

Table of Contents

Installation

You can install the package using npm or yarn:

npm install @corsa-labs/sdk
# or
yarn add @corsa-labs/sdk

API Client Usage

This section covers how to use the SDK to interact with the Compliance API endpoints.

Configuration

First, import the ComplianceClient and configure it with your API details:

import { ComplianceClient, OpenAPI } from '@corsa-labs/sdk';

// Configure API key (or other authentication methods) via Headers
// OpenAPI.TOKEN = 'YOUR_API_KEY'; // Deprecated: Use HEADERS instead

// Configure the base URL
OpenAPI.BASE = 'https://api.corsa.finance'; 

// Configure Headers for Authentication (Recommended)
OpenAPI.HEADERS = {
  "Authorization": `Bearer ${process.env.API_TOKEN}` 
};

const client = new ComplianceClient();

// Or configure directly in the constructor
const clientWithConfig = new ComplianceClient({
    BASE: "https://api.corsa.finance",
    HEADERS: {
        "Authorization": `Bearer ${process.env.API_TOKEN}`
    }
});

Available Services

The SDK provides access to the following services via the ComplianceClient instance:

  • client.alerts: Manage compliance alerts.
  • client.clients: Manage individual and corporate clients.
  • client.health: Check the health status of the API.
  • client.operations: Manage financial operations (deposits, withdrawals, trades).
  • client.transactions: Manage transactions.

Each service exposes methods corresponding to the API endpoints. Refer to the type definitions (exported from index.ts and within the models/ and services/ directories) for detailed request and response structures.

Working Example For API requests

import { ClientRiskDto, ComplianceClient, CreateIndividualClientDto, IndividualClientCustomFieldDataDto, IndividualClientGeneralInformationDto } from "@corsa-labs/sdk";
import { v4 as uuidv4 } from 'uuid';

async function main() {
    const client = new ComplianceClient({
        BASE: "https://api.corsa.finance",
        HEADERS: {
            "Authorization": `Bearer ${process.env.API_TOKEN}` // Use Authorization header
        }
    });

    const referenceId = uuidv4();
    const { id } = await client.clients.createIndividualClient({
        referenceId,
        activityStatus: CreateIndividualClientDto.activityStatus.ACTIVE,
        accountStatus: CreateIndividualClientDto.accountStatus.APPROVED,
        currentRisk: {
            score: 75,
            level: ClientRiskDto.level.HIGH,
            reason: "Multiple high-value transactions in high-risk jurisdictions",
            calculatedAt: "2023-08-15T14:30:00Z"
        },
        tags: ["high-value", "vip-client"],
        controls: ["enhanced-due-diligence", "quarterly-review"],
        address: {
            addressLine1: "123 Main Street",
            addressLine2: "Apt 4B",
            city: "New York",
            country: "USA",
            postalCode: "10001"
        },
        adverseMedia: {
            isAdverseMedia: false
        },
        application: {
            submittedAt: "2023-08-15T10:30:00Z",
            onboardedAt: "2023-08-20T14:00:00Z",
            onboardingRisk: {
                score: 75,
                level: ClientRiskDto.level.HIGH,
                reason: "Multiple high-value transactions in high-risk jurisdictions",
                calculatedAt: "2023-08-15T14:30:00Z"
            },
            nextPeriodicReview: "2024-08-20T14:00:00Z"
        },
        riskHistory: [{
            score: 75,
            level: ClientRiskDto.level.HIGH,
            reason: "Multiple high-value transactions in high-risk jurisdictions",
            calculatedAt: "2023-08-15T14:30:00Z"
        }],
        contact: {
            emailAddress: "[email protected]",
            phoneNumber: "+1-555-123-4567"
        },
        customFields: {
            additionalProp1: {
                label: "Preferred Contact Time",
                value: "Morning",
                category: IndividualClientCustomFieldDataDto.category.GENERAL
            },
            additionalProp2: {
                label: "Preferred Contact Time",
                value: "Morning",
                category: IndividualClientCustomFieldDataDto.category.GENERAL
            },
            additionalProp3: {
                label: "Preferred Contact Time",
                value: "Morning",
                category: IndividualClientCustomFieldDataDto.category.GENERAL
            }
        },
        financial: {
            annualDepositEstimate: "100000"
        },
        general: {
            firstName: "Yarin SDK",
            lastName: "Test",
            gender: IndividualClientGeneralInformationDto.gender.MALE,
            dateOfBirth: "1980-01-15",
            citizenship: "USA",
            personalId: "123-45-6789"
        },
        politicalExposure: {
            isPoliticallyExposed: false
        },
        sanctions: {
            isSanctioned: false
        },
        work: {
            occupation: "Software Engineer"
        }
    });

    console.log(id);
    await client.clients.updateIndividualClient(id, {
        activityStatus: CreateIndividualClientDto.activityStatus.NOT_ACTIVE,
    });
}

main();

Webhook Handling

The SDK provides utilities for handling webhooks sent from the Compliance API.

Webhook Headers

When receiving webhooks, inspect the following HTTP headers:

  • x-hub-signature-256: The HMAC SHA256 signature of the request payload. Used for verifying the webhook's authenticity. (See Verifying Signatures below).
  • x-hook-event: The type of event that triggered the webhook (e.g., individual_client.created).
  • x-hook-id: The unique identifier of the webhook configuration that sent this request.
  • x-hook-delivery: A unique identifier for this specific delivery attempt.
  • x-request-id: A unique identifier of the request that originated the webhook.
  • x-request-origin: The origin of the request that originated the webhook (either API or WEB)

Verifying Signatures

It's crucial to verify the signature of incoming webhooks to ensure they originated from the Compliance API and were not tampered with. Use the verifyWebhookSignature function exported from the SDK.

import { verifyWebhookSignature } from '@corsa-labs/sdk';

async function verifyWebhookRequest(request: Request) { // Assuming a standard Request object
  const signature = request.headers.get('x-hub-signature-256'); 
  const payload = await request.text(); // Raw request body
  const secret = process.env.WEBHOOK_SECRET; // Your webhook secret

  if (!signature || !secret) {
      console.error("Missing signature or secret");
      // Return an error response (e.g., HTTP 400 Bad Request)
      return false; 
  }

  const isValid = await verifyWebhookSignature(secret, payload, signature);

  if (!isValid) {
    console.error('Invalid webhook signature');
    // Return an error response (e.g., HTTP 401 Unauthorized)
    return false;
  }

  console.log("Webhook signature verified successfully!");
  // Signature is valid, proceed with processing the webhook payload
  // const webhookEvent = JSON.parse(payload);
  // console.log('Received valid webhook:', webhookEvent.type);
  // ... process event ...
  return true;
}

Event Types

The following webhook event types are available (defined in WebhookEventType):

  • individual_client.created: Triggered when an individual client is created.
  • individual_client.updated: Triggered when an individual client is updated.
  • corporate_client.created: Triggered when a corporate client is created.
  • corporate_client.updated: Triggered when a corporate client is updated.
  • alert.created: Triggered when an alert is created.
  • alert.updated: Triggered when an alert is updated.
  • case.created: Triggered when a case is created.
  • case.updated: Triggered when a case is updated.

The payload structure for each event type (WebhookEvent, EntityCreatedPayload, EntityUpdatedPayload) and the WebhookEventType enum can be imported from @corsa-labs/sdk.

For a practical example of how to set up a webhook handler, see the Webhook Example.


Development

Building

To build the project locally:

yarn install
yarn build

Testing

Run the tests using:

yarn test

Contributing

Contributions are welcome! Please follow standard practices for pull requests.

License

MIT

版本与发布记录

@corsa-labs/sdk 共发布 96 个版本,首次发布于 2025/05/27;过去 12 个月发布了 56 个版本。

版本发布日期距今
5.0.1latest2026/10/2021 天前
5.0.02026/10/1130 天前
4.53.02026/10/061 个月前
4.52.02026/08/182 个月前
4.51.12026/08/182 个月前
4.51.02026/08/182 个月前

关于 @corsa-labs/sdk 的常见问题

@corsa-labs/sdk 是什么?

Official Node.js SDK for Corsa (corsa.finance), the agentic compliance OS: AML transaction monitoring, alerts, cases, KYC/KYB and risk APIs.

如何安装 @corsa-labs/sdk?

在项目目录运行 npm install @corsa-labs/sdk,或使用 pnpm add / yarn add / bun add。

@corsa-labs/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@corsa-labs/sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@corsa-labs/sdk 可以商用吗?

@corsa-labs/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@corsa-labs/sdk 的下载量有多少?

根据 npm 官方下载统计,@corsa-labs/sdk 在 2026/10/11 – 2026/11/09 这 30 天内被下载 16,594 次,日均约 553 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@corsa-labs/sdk 还在维护吗?

最新版本 5.0.1 发布于 2026/10/20(21 天前);至今共发布 96 个版本,其中过去 12 个月发布了 56 个;首次发布于 2025/05/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。