@corsa-labs/sdk 3.1.4 → 3.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @corsa-labs/sdk
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/%40corsa-labs%2Fsdk)
|
|
4
4
|
|
|
5
|
-
SDK for
|
|
5
|
+
SDK for integrating with Corsa API
|
|
6
6
|
|
|
7
7
|
## Table of Contents
|
|
8
8
|
|
|
@@ -26,9 +26,9 @@ SDK for Compliance API
|
|
|
26
26
|
You can install the package using npm or yarn:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
npm install @
|
|
29
|
+
npm install @corsa-labs/sdk
|
|
30
30
|
# or
|
|
31
|
-
yarn add @
|
|
31
|
+
yarn add @corsa-labs/sdk
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
---
|
|
@@ -42,7 +42,7 @@ This section covers how to use the SDK to interact with the Compliance API endpo
|
|
|
42
42
|
First, import the `ComplianceClient` and configure it with your API details:
|
|
43
43
|
|
|
44
44
|
```typescript
|
|
45
|
-
import { ComplianceClient, OpenAPI } from '@
|
|
45
|
+
import { ComplianceClient, OpenAPI } from '@corsa-labs/sdk';
|
|
46
46
|
|
|
47
47
|
// Configure API key (or other authentication methods) via Headers
|
|
48
48
|
// OpenAPI.TOKEN = 'YOUR_API_KEY'; // Deprecated: Use HEADERS instead
|
|
@@ -80,7 +80,7 @@ Each service exposes methods corresponding to the API endpoints. Refer to the ty
|
|
|
80
80
|
|
|
81
81
|
### Working Example For API requests
|
|
82
82
|
```ts
|
|
83
|
-
import { ClientRiskDto, ComplianceClient, CreateIndividualClientDto, IndividualClientCustomFieldDataDto, IndividualClientGeneralInformationDto } from "@
|
|
83
|
+
import { ClientRiskDto, ComplianceClient, CreateIndividualClientDto, IndividualClientCustomFieldDataDto, IndividualClientGeneralInformationDto } from "@corsa-labs/sdk";
|
|
84
84
|
import { v4 as uuidv4 } from 'uuid';
|
|
85
85
|
|
|
86
86
|
async function main() {
|
|
@@ -203,7 +203,7 @@ When receiving webhooks, inspect the following HTTP headers:
|
|
|
203
203
|
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.
|
|
204
204
|
|
|
205
205
|
```typescript
|
|
206
|
-
import { verifyWebhookSignature } from '@
|
|
206
|
+
import { verifyWebhookSignature } from '@corsa-labs/sdk';
|
|
207
207
|
|
|
208
208
|
async function verifyWebhookRequest(request: Request) { // Assuming a standard Request object
|
|
209
209
|
const signature = request.headers.get('x-hub-signature-256');
|
|
@@ -246,7 +246,7 @@ The following webhook event types are available (defined in `WebhookEventType`):
|
|
|
246
246
|
* `case.created`: Triggered when a case is created.
|
|
247
247
|
* `case.updated`: Triggered when a case is updated.
|
|
248
248
|
|
|
249
|
-
The payload structure for each event type (`WebhookEvent`, `EntityCreatedPayload`, `EntityUpdatedPayload`) and the `WebhookEventType` enum can be imported from `@
|
|
249
|
+
The payload structure for each event type (`WebhookEvent`, `EntityCreatedPayload`, `EntityUpdatedPayload`) and the `WebhookEventType` enum can be imported from `@corsa-labs/sdk`.
|
|
250
250
|
|
|
251
251
|
For a practical example of how to set up a webhook handler, see the [Webhook Example](./docs/WEBHOOK_EXAMPLE.md).
|
|
252
252
|
|
|
@@ -12,10 +12,10 @@ const node_crypto_1 = require("node:crypto");
|
|
|
12
12
|
*/
|
|
13
13
|
function signWebhookPayload(secret, payload) {
|
|
14
14
|
if (!secret || !payload) {
|
|
15
|
-
throw new TypeError('[@
|
|
15
|
+
throw new TypeError('[@corsa-labs/sdk] secret & payload required for sign()');
|
|
16
16
|
}
|
|
17
17
|
if (typeof payload !== 'string') {
|
|
18
|
-
throw new TypeError('[@
|
|
18
|
+
throw new TypeError('[@corsa-labs/sdk] payload must be a string');
|
|
19
19
|
}
|
|
20
20
|
const algorithm = 'sha256';
|
|
21
21
|
return `${algorithm}=${(0, node_crypto_1.createHmac)(algorithm, secret)
|
|
@@ -31,10 +31,10 @@ function signWebhookPayload(secret, payload) {
|
|
|
31
31
|
*/
|
|
32
32
|
function verifyWebhookSignature(secret, eventPayload, signature) {
|
|
33
33
|
if (!secret || !eventPayload || !signature) {
|
|
34
|
-
throw new TypeError('[@
|
|
34
|
+
throw new TypeError('[@corsa-labs/sdk] secret, eventPayload & signature required');
|
|
35
35
|
}
|
|
36
36
|
if (typeof eventPayload !== 'string') {
|
|
37
|
-
throw new TypeError('[@
|
|
37
|
+
throw new TypeError('[@corsa-labs/sdk] eventPayload must be a string');
|
|
38
38
|
}
|
|
39
39
|
const signatureBuffer = Buffer.from(signature);
|
|
40
40
|
const verificationBuffer = Buffer.from(signWebhookPayload(secret, eventPayload));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-signature.js","sourceRoot":"","sources":["../../webhooks/verify-signature.ts"],"names":[],"mappings":";;AAUA,gDAgBC;AASD,wDA6BC;AAhED,6CAA0D;AAE1D,oFAAoF;AAEpF;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAc,EAAE,OAAe;IAChE,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,SAAS,CACjB,
|
|
1
|
+
{"version":3,"file":"verify-signature.js","sourceRoot":"","sources":["../../webhooks/verify-signature.ts"],"names":[],"mappings":";;AAUA,gDAgBC;AASD,wDA6BC;AAhED,6CAA0D;AAE1D,oFAAoF;AAEpF;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAc,EAAE,OAAe;IAChE,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,SAAS,CACjB,wDAAwD,CACzD,CAAA;IACH,CAAC;IAED,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,4CAA4C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