@corsa-labs/sdk 3.9.1 → 3.11.0

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
@@ -48,7 +48,7 @@ import { ComplianceClient, OpenAPI } from '@corsa-labs/sdk';
48
48
  // OpenAPI.TOKEN = 'YOUR_API_KEY'; // Deprecated: Use HEADERS instead
49
49
 
50
50
  // Configure the base URL
51
- OpenAPI.BASE = 'https://api-compliance.prod.paytweed.com';
51
+ OpenAPI.BASE = 'https://api.corsa.finance';
52
52
 
53
53
  // Configure Headers for Authentication (Recommended)
54
54
  OpenAPI.HEADERS = {
@@ -59,7 +59,7 @@ const client = new ComplianceClient();
59
59
 
60
60
  // Or configure directly in the constructor
61
61
  const clientWithConfig = new ComplianceClient({
62
- BASE: "https://api-compliance.prod.paytweed.com",
62
+ BASE: "https://api.corsa.finance",
63
63
  HEADERS: {
64
64
  "Authorization": `Bearer ${process.env.API_TOKEN}`
65
65
  }
@@ -85,7 +85,7 @@ import { v4 as uuidv4 } from 'uuid';
85
85
 
86
86
  async function main() {
87
87
  const client = new ComplianceClient({
88
- BASE: "https://api-compliance.prod.paytweed.com",
88
+ BASE: "https://api.corsa.finance",
89
89
  HEADERS: {
90
90
  "Authorization": `Bearer ${process.env.API_TOKEN}` // Use Authorization header
91
91
  }
@@ -194,9 +194,9 @@ The SDK provides utilities for handling webhooks sent from the Compliance API.
194
194
  When receiving webhooks, inspect the following HTTP headers:
195
195
 
196
196
  * `x-hub-signature-256`: The HMAC SHA256 signature of the request payload. Used for verifying the webhook's authenticity. (See Verifying Signatures below).
197
- * `x-tweed-event`: The type of event that triggered the webhook (e.g., `individual_client.created`).
198
- * `x-tweed-hook-id`: The unique identifier of the webhook configuration that sent this request.
199
- * `x-tweed-delivery`: A unique identifier for this specific delivery attempt.
197
+ * `x-hook-event`: The type of event that triggered the webhook (e.g., `individual_client.created`).
198
+ * `x-hook-id`: The unique identifier of the webhook configuration that sent this request.
199
+ * `x-hook-delivery`: A unique identifier for this specific delivery attempt.
200
200
 
201
201
  ### Verifying Signatures
202
202
 
@@ -279,4 +279,4 @@ Contributions are welcome! Please follow standard practices for pull requests.
279
279
 
280
280
  ## License
281
281
 
282
- [MIT](LICENSE)
282
+ [MIT](LICENSE)
@@ -0,0 +1,19 @@
1
+ import type { ApiRequestOptions } from "./ApiRequestOptions";
2
+ import { CancelablePromise } from "./CancelablePromise";
3
+ import type { EncryptionMiddleware } from "./EncryptionMiddleware";
4
+ import { FetchHttpRequest } from "./FetchHttpRequest";
5
+ import type { OpenAPIConfig } from "./OpenAPI";
6
+ /**
7
+ * HTTP Request class with field-level encryption support
8
+ */
9
+ export declare class EncryptedFetchHttpRequest extends FetchHttpRequest {
10
+ private encryptionMiddleware?;
11
+ constructor(config: OpenAPIConfig, encryptionMiddleware?: EncryptionMiddleware);
12
+ /**
13
+ * Request method with encryption middleware
14
+ * @param options The request options from the service
15
+ * @returns CancelablePromise<T>
16
+ * @throws ApiError
17
+ */
18
+ request<T>(options: ApiRequestOptions): CancelablePromise<T>;
19
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptedFetchHttpRequest = void 0;
4
+ const CancelablePromise_1 = require("./CancelablePromise");
5
+ const FetchHttpRequest_1 = require("./FetchHttpRequest");
6
+ const request_1 = require("./request");
7
+ /**
8
+ * HTTP Request class with field-level encryption support
9
+ */
10
+ class EncryptedFetchHttpRequest extends FetchHttpRequest_1.FetchHttpRequest {
11
+ encryptionMiddleware;
12
+ constructor(config, encryptionMiddleware) {
13
+ super(config);
14
+ this.encryptionMiddleware = encryptionMiddleware;
15
+ }
16
+ /**
17
+ * Request method with encryption middleware
18
+ * @param options The request options from the service
19
+ * @returns CancelablePromise<T>
20
+ * @throws ApiError
21
+ */
22
+ request(options) {
23
+ // If no middleware is configured, use the default request implementation
24
+ if (!this.encryptionMiddleware) {
25
+ return super.request(options);
26
+ }
27
+ // With middleware, process the request through it first
28
+ const middleware = this.encryptionMiddleware;
29
+ return new CancelablePromise_1.CancelablePromise(async (resolve, reject, onCancel) => {
30
+ try {
31
+ // Apply encryption middleware
32
+ const processedOptions = await middleware.processRequest(options);
33
+ // Call the parent request implementation with processed options
34
+ const promise = (0, request_1.request)(this.config, processedOptions);
35
+ // Handle cancellation
36
+ onCancel(() => promise.cancel());
37
+ // Resolve or reject the promise
38
+ const result = await promise;
39
+ resolve(result);
40
+ }
41
+ catch (error) {
42
+ reject(error);
43
+ }
44
+ });
45
+ }
46
+ }
47
+ exports.EncryptedFetchHttpRequest = EncryptedFetchHttpRequest;
48
+ //# sourceMappingURL=EncryptedFetchHttpRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedFetchHttpRequest.js","sourceRoot":"","sources":["../../core/EncryptedFetchHttpRequest.ts"],"names":[],"mappings":";;;AACA,2DAAwD;AAExD,yDAAsD;AAEtD,uCAAiD;AAEjD;;GAEG;AACH,MAAa,yBAA0B,SAAQ,mCAAgB;IACrD,oBAAoB,CAAwB;IAEpD,YACE,MAAqB,EACrB,oBAA2C;QAE3C,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACa,OAAO,CAAI,OAA0B;QACnD,yEAAyE;QACzE,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAC,OAAO,CAAI,OAAO,CAAC,CAAC;QACnC,CAAC;QAED,wDAAwD;QACxD,MAAM,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAC;QAE7C,OAAO,IAAI,qCAAiB,CAAI,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;YAClE,IAAI,CAAC;gBACH,8BAA8B;gBAC9B,MAAM,gBAAgB,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;gBAElE,gEAAgE;gBAChE,MAAM,OAAO,GAAG,IAAA,iBAAS,EAAI,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;gBAE5D,sBAAsB;gBACtB,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;gBAEjC,gCAAgC;gBAChC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;gBAC7B,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7CD,8DA6CC"}
@@ -0,0 +1,46 @@
1
+ import { EncryptedFieldSchema } from "@corsa-labs/encryption-node";
2
+ import type { ApiRequestOptions } from "./ApiRequestOptions";
3
+ /**
4
+ * Interface for the encryption service that will handle actual encryption
5
+ */
6
+ export interface EncryptionService {
7
+ /**
8
+ * Encrypts a string value
9
+ * @param value Value to encrypt
10
+ * @returns Encrypted value
11
+ */
12
+ encrypt(value: string): Promise<string>;
13
+ /**
14
+ * Decrypts a string value
15
+ * @param value Value to decrypt
16
+ * @returns Decrypted value
17
+ */
18
+ decrypt(value: string): Promise<string>;
19
+ }
20
+ /**
21
+ * Class that handles field-level encryption based on a unified schema
22
+ */
23
+ export declare class EncryptionMiddleware {
24
+ private schema;
25
+ private encryptionService;
26
+ private salt?;
27
+ /**
28
+ * Create a new encryption middleware
29
+ * @param schema Unified field encryption schema
30
+ * @param encryptionService Service that handles actual encryption
31
+ * @param salt Optional salt for hash generation
32
+ */
33
+ constructor(schema: EncryptedFieldSchema, encryptionService: EncryptionService, salt?: string);
34
+ /**
35
+ * Process an API request, encrypting fields as specified in the schema
36
+ * @param options API request options
37
+ * @returns Modified API request options with encrypted fields
38
+ */
39
+ processRequest(options: ApiRequestOptions): Promise<ApiRequestOptions>;
40
+ /**
41
+ * Extract an operation identifier from the request options
42
+ * @param options API request options
43
+ * @returns Operation identifier (usually the URL path)
44
+ */
45
+ private getOperationIdentifier;
46
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptionMiddleware = void 0;
4
+ /* istanbul ignore file */
5
+ /* tslint:disable */
6
+ /* eslint-disable */
7
+ const encryption_node_1 = require("@corsa-labs/encryption-node");
8
+ /**
9
+ * Class that handles field-level encryption based on a unified schema
10
+ */
11
+ class EncryptionMiddleware {
12
+ schema;
13
+ encryptionService;
14
+ salt;
15
+ /**
16
+ * Create a new encryption middleware
17
+ * @param schema Unified field encryption schema
18
+ * @param encryptionService Service that handles actual encryption
19
+ * @param salt Optional salt for hash generation
20
+ */
21
+ constructor(schema, encryptionService, salt) {
22
+ this.schema = schema;
23
+ this.encryptionService = encryptionService;
24
+ this.salt = salt;
25
+ }
26
+ /**
27
+ * Process an API request, encrypting fields as specified in the schema
28
+ * @param options API request options
29
+ * @returns Modified API request options with encrypted fields
30
+ */
31
+ async processRequest(options) {
32
+ // Only process POST and PUT requests that may contain a body
33
+ if (options.body &&
34
+ (options.method === "POST" || options.method === "PUT")) {
35
+ const operationPath = this.getOperationIdentifier(options);
36
+ const cryptoOps = new encryption_node_1.NodeCryptoOps();
37
+ const processor = new encryption_node_1.EncryptedFieldProcessor(cryptoOps);
38
+ const result = await processor.processFields(options.body, this.schema, {
39
+ operation: encryption_node_1.FieldOperation.ENCRYPT,
40
+ encryptionService: this.encryptionService,
41
+ operationPath,
42
+ salt: this.salt,
43
+ });
44
+ if (!result.success) {
45
+ throw new Error(`Field encryption failed: ${result.errors
46
+ ?.map((e) => `${e.path}: ${e.message}`)
47
+ .join(", ")}`);
48
+ }
49
+ return {
50
+ ...options,
51
+ body: result.data,
52
+ };
53
+ }
54
+ return options;
55
+ }
56
+ /**
57
+ * Extract an operation identifier from the request options
58
+ * @param options API request options
59
+ * @returns Operation identifier (usually the URL path)
60
+ */
61
+ getOperationIdentifier(options) {
62
+ // We'll use the URL as the operation identifier
63
+ // This could be expanded to include the HTTP method if needed
64
+ return options.url || null;
65
+ }
66
+ }
67
+ exports.EncryptionMiddleware = EncryptionMiddleware;
68
+ //# sourceMappingURL=EncryptionMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptionMiddleware.js","sourceRoot":"","sources":["../../core/EncryptionMiddleware.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AAC1B,oBAAoB;AACpB,oBAAoB;AACpB,iEAKqC;AAsBrC;;GAEG;AACH,MAAa,oBAAoB;IACvB,MAAM,CAAuB;IAC7B,iBAAiB,CAAoB;IACrC,IAAI,CAAU;IAEtB;;;;;OAKG;IACH,YACE,MAA4B,EAC5B,iBAAoC,EACpC,IAAa;QAEb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,cAAc,CACzB,OAA0B;QAE1B,6DAA6D;QAC7D,IACE,OAAO,CAAC,IAAI;YACZ,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,EACvD,CAAC;YACD,MAAM,aAAa,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;YAC3D,MAAM,SAAS,GAAG,IAAI,+BAAa,EAAE,CAAC;YACtC,MAAM,SAAS,GAAG,IAAI,yCAAuB,CAAC,SAAS,CAAC,CAAC;YACzD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;gBACtE,SAAS,EAAE,gCAAc,CAAC,OAAO;gBACjC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;gBACzC,aAAa;gBACb,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CACb,4BAA4B,MAAM,CAAC,MAAM;oBACvC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;qBACtC,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,GAAG,OAAO;gBACV,IAAI,EAAE,MAAM,CAAC,IAAI;aAClB,CAAC;QACJ,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACK,sBAAsB,CAAC,OAA0B;QACvD,gDAAgD;QAChD,8DAA8D;QAC9D,OAAO,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC;IAC7B,CAAC;CACF;AAvED,oDAuEC"}
@@ -0,0 +1,90 @@
1
+ import { ComplianceClient } from "../ComplianceClient";
2
+ import { EncryptionMiddleware } from "../core/EncryptionMiddleware";
3
+ import { FetchHttpRequest } from "../core/FetchHttpRequest";
4
+ import type { OpenAPIConfig } from "../core/OpenAPI";
5
+ import { EncryptedFieldSchema } from "@corsa-labs/encryption-node";
6
+ /**
7
+ * Configuration for encrypted data encryption setup
8
+ */
9
+ export interface EncryptedClientConfig {
10
+ /** Base URL for the compliance API */
11
+ baseUrl: string;
12
+ /** API key for authentication */
13
+ apiKey: string;
14
+ /** Optional: Custom encryption service URL (defaults to production) */
15
+ encryptionServiceUrl?: string;
16
+ /** Optional: Platform ID for encryption (defaults to 'corsa') */
17
+ platformId?: string;
18
+ /** Optional: API secret for encryption service auth */
19
+ apiSecret?: string;
20
+ /** Optional: Pass the compliance API authorization header to encryption service requests */
21
+ passAuthToEncryption?: boolean;
22
+ }
23
+ /**
24
+ * Compliance client with field-level encryption capabilities
25
+ *
26
+ * This client automatically encrypts fields (like emails, phone numbers,
27
+ * personal IDs, etc.) before sending data to the API, based on a configurable mapping.
28
+ *
29
+ * The encryption is handled transparently - the client interface remains the same,
30
+ * but specified fields are encrypted using the built-in encryption system.
31
+ */
32
+ export declare class EncryptedComplianceClient extends ComplianceClient {
33
+ /**
34
+ * Create a compliance client with field-level encryption
35
+ *
36
+ * @param config Client configuration including API credentials and encryption settings
37
+ * @param schema Unified field encryption schema
38
+ * @returns ComplianceClient instance with field encryption enabled
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { EncryptedComplianceClient } from '@corsa-labs/compliance-sdk';
43
+ *
44
+ * // Configure which fields to encrypt using unified schema
45
+ * const encryptionSchema = {
46
+ * fields: {
47
+ * emailAddress: { type: 'string', encrypt: true, validate: true },
48
+ * phoneNumber: { type: 'string', encrypt: true },
49
+ * personalId: { type: 'string', encrypt: true, generateHash: true }
50
+ * },
51
+ * operations: {
52
+ * '/v1/clients/individuals': {
53
+ * 'contact': ['emailAddress', 'phoneNumber'],
54
+ * 'general': ['personalId']
55
+ * }
56
+ * }
57
+ * };
58
+ *
59
+ * // Create client with field encryption - encryption manager is created automatically
60
+ * const client = EncryptedComplianceClient.withEncryptedFields({
61
+ * baseUrl: 'https://api-compliance.corsa.finance',
62
+ * apiKey: 'your-api-key',
63
+ * apiSecret: 'your-encryption-api-secret', // Required for encryption service
64
+ * passAuthToEncryption: true // Optional: pass the API key as Authorization header to encryption service
65
+ * }, encryptionSchema);
66
+ *
67
+ * // Use normally - specified fields will be automatically encrypted
68
+ * const individual = await client.clients.createIndividualClient({
69
+ * referenceId: 'ref-123',
70
+ * contact: {
71
+ * emailAddress: 'user@example.com', // Automatically encrypted
72
+ * phoneNumber: '+1234567890', // Automatically encrypted
73
+ * },
74
+ * general: {
75
+ * firstName: 'John',
76
+ * lastName: 'Doe',
77
+ * personalId: '123-45-6789', // Automatically encrypted
78
+ * }
79
+ * });
80
+ * ```
81
+ */
82
+ static withEncryptedFields(config: EncryptedClientConfig, schema: EncryptedFieldSchema): EncryptedComplianceClient;
83
+ /**
84
+ * Constructor for EncryptedComplianceClient
85
+ *
86
+ * Note: In most cases, you should use the static `withEncryptedFields()` method instead
87
+ * of calling this constructor directly.
88
+ */
89
+ constructor(config?: Partial<OpenAPIConfig>, HttpRequestConstructor?: typeof FetchHttpRequest, encryptionMiddleware?: EncryptionMiddleware);
90
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ /* istanbul ignore file */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EncryptedComplianceClient = void 0;
7
+ const ComplianceClient_1 = require("../ComplianceClient");
8
+ const EncryptedFetchHttpRequest_1 = require("../core/EncryptedFetchHttpRequest");
9
+ const EncryptionMiddleware_1 = require("../core/EncryptionMiddleware");
10
+ const FetchHttpRequest_1 = require("../core/FetchHttpRequest");
11
+ const EncryptedFieldAdapter_1 = require("./EncryptedFieldAdapter");
12
+ const encryption_node_1 = require("@corsa-labs/encryption-node");
13
+ /**
14
+ * Compliance client with field-level encryption capabilities
15
+ *
16
+ * This client automatically encrypts fields (like emails, phone numbers,
17
+ * personal IDs, etc.) before sending data to the API, based on a configurable mapping.
18
+ *
19
+ * The encryption is handled transparently - the client interface remains the same,
20
+ * but specified fields are encrypted using the built-in encryption system.
21
+ */
22
+ class EncryptedComplianceClient extends ComplianceClient_1.ComplianceClient {
23
+ /**
24
+ * Create a compliance client with field-level encryption
25
+ *
26
+ * @param config Client configuration including API credentials and encryption settings
27
+ * @param schema Unified field encryption schema
28
+ * @returns ComplianceClient instance with field encryption enabled
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { EncryptedComplianceClient } from '@corsa-labs/compliance-sdk';
33
+ *
34
+ * // Configure which fields to encrypt using unified schema
35
+ * const encryptionSchema = {
36
+ * fields: {
37
+ * emailAddress: { type: 'string', encrypt: true, validate: true },
38
+ * phoneNumber: { type: 'string', encrypt: true },
39
+ * personalId: { type: 'string', encrypt: true, generateHash: true }
40
+ * },
41
+ * operations: {
42
+ * '/v1/clients/individuals': {
43
+ * 'contact': ['emailAddress', 'phoneNumber'],
44
+ * 'general': ['personalId']
45
+ * }
46
+ * }
47
+ * };
48
+ *
49
+ * // Create client with field encryption - encryption manager is created automatically
50
+ * const client = EncryptedComplianceClient.withEncryptedFields({
51
+ * baseUrl: 'https://api-compliance.corsa.finance',
52
+ * apiKey: 'your-api-key',
53
+ * apiSecret: 'your-encryption-api-secret', // Required for encryption service
54
+ * passAuthToEncryption: true // Optional: pass the API key as Authorization header to encryption service
55
+ * }, encryptionSchema);
56
+ *
57
+ * // Use normally - specified fields will be automatically encrypted
58
+ * const individual = await client.clients.createIndividualClient({
59
+ * referenceId: 'ref-123',
60
+ * contact: {
61
+ * emailAddress: 'user@example.com', // Automatically encrypted
62
+ * phoneNumber: '+1234567890', // Automatically encrypted
63
+ * },
64
+ * general: {
65
+ * firstName: 'John',
66
+ * lastName: 'Doe',
67
+ * personalId: '123-45-6789', // Automatically encrypted
68
+ * }
69
+ * });
70
+ * ```
71
+ */
72
+ static withEncryptedFields(config, schema) {
73
+ // Validate required parameters
74
+ if (!config) {
75
+ throw new Error("EncryptedClientConfig is required for field encryption.");
76
+ }
77
+ if (!schema) {
78
+ throw new Error("EncryptedFieldSchema is required for field encryption. Provide a unified schema mapping fields to encryption settings.");
79
+ }
80
+ // Create the encryption manager internally using wire-format
81
+ // Note: Always use WIRE_FORMAT for compliance API to ensure encrypted fields
82
+ // are sent as "__enc__<base64>" format. This is not configurable by users to
83
+ // prevent format inconsistencies.
84
+ const encryptionManager = (0, encryption_node_1.createNodeEncryptionClient)({
85
+ serviceUrl: config.encryptionServiceUrl || "https://encryption.corsa.finance",
86
+ apiSecret: config.apiSecret,
87
+ platformId: config.platformId || "corsa",
88
+ wireFormat: encryption_node_1.WireFormat.PREFIXED, // Always use prefixed format for compliance API
89
+ ...(config.passAuthToEncryption && {
90
+ authorizationHeader: `Bearer ${config.apiKey}`,
91
+ }),
92
+ });
93
+ // Create the field encryption adapter
94
+ const encryptedFieldAdapter = new EncryptedFieldAdapter_1.EncryptedFieldAdapter(encryptionManager);
95
+ // Create the encryption middleware with the unified schema
96
+ const middleware = new EncryptionMiddleware_1.EncryptionMiddleware(schema, encryptedFieldAdapter);
97
+ // Create OpenAPI config from the provided config
98
+ const openApiConfig = {
99
+ BASE: config.baseUrl,
100
+ HEADERS: {
101
+ Authorization: `Bearer ${config.apiKey}`,
102
+ },
103
+ };
104
+ // Create the client with the encrypted HTTP request handler
105
+ const client = new EncryptedComplianceClient(openApiConfig, FetchHttpRequest_1.FetchHttpRequest, middleware);
106
+ return client;
107
+ }
108
+ /**
109
+ * Constructor for EncryptedComplianceClient
110
+ *
111
+ * Note: In most cases, you should use the static `withEncryptedFields()` method instead
112
+ * of calling this constructor directly.
113
+ */
114
+ constructor(config, HttpRequestConstructor = FetchHttpRequest_1.FetchHttpRequest, encryptionMiddleware) {
115
+ // If encryption middleware is provided, use EncryptedFetchHttpRequest
116
+ if (encryptionMiddleware) {
117
+ const openApiConfig = {
118
+ BASE: config?.BASE ?? "",
119
+ VERSION: config?.VERSION ?? "1.0",
120
+ WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
121
+ CREDENTIALS: config?.CREDENTIALS ?? "include",
122
+ TOKEN: config?.TOKEN,
123
+ USERNAME: config?.USERNAME,
124
+ PASSWORD: config?.PASSWORD,
125
+ HEADERS: config?.HEADERS,
126
+ ENCODE_PATH: config?.ENCODE_PATH,
127
+ };
128
+ // Create the encrypted HTTP request with middleware
129
+ const encryptedRequest = new EncryptedFetchHttpRequest_1.EncryptedFetchHttpRequest(openApiConfig, encryptionMiddleware);
130
+ // Call parent constructor with our custom request handler
131
+ // We need to pass it as if it were a constructor, so we create a wrapper
132
+ super(config, class extends FetchHttpRequest_1.FetchHttpRequest {
133
+ request = encryptedRequest.request.bind(encryptedRequest);
134
+ constructor(cfg) {
135
+ super(cfg);
136
+ }
137
+ });
138
+ }
139
+ else {
140
+ // No encryption middleware, use standard client
141
+ super(config, HttpRequestConstructor);
142
+ }
143
+ }
144
+ }
145
+ exports.EncryptedComplianceClient = EncryptedComplianceClient;
146
+ //# sourceMappingURL=EncryptedComplianceClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedComplianceClient.js","sourceRoot":"","sources":["../../extensions/EncryptedComplianceClient.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,25 @@
1
+ import type { NodeEncryptionClient } from "@corsa-labs/encryption-node";
2
+ import type { EncryptionService } from "../core/EncryptionMiddleware";
3
+ /**
4
+ * Adapter that integrates the encryption-sdk's NodeEncryptionClient
5
+ * with the compliance-sdk's EncryptionService interface
6
+ *
7
+ * This adapter assumes the NodeEncryptionClient is configured with PREFIXED
8
+ * wire format, which returns "__enc__<base64>" strings ready for API transmission.
9
+ */
10
+ export declare class EncryptedFieldAdapter implements EncryptionService {
11
+ private encryptionManager;
12
+ constructor(encryptionManager: NodeEncryptionClient);
13
+ /**
14
+ * Encrypts a value using the encryption-sdk
15
+ * @param value The plaintext value to encrypt
16
+ * @returns Wire-format encrypted string ("__enc__<base64>")
17
+ */
18
+ encrypt(value: string): Promise<string>;
19
+ /**
20
+ * Decrypts a wire-format encrypted value using the encryption-sdk
21
+ * @param value Wire-format encrypted string ("__enc__<base64>")
22
+ * @returns Decrypted plaintext value
23
+ */
24
+ decrypt(value: string): Promise<string>;
25
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptedFieldAdapter = void 0;
4
+ /**
5
+ * Adapter that integrates the encryption-sdk's NodeEncryptionClient
6
+ * with the compliance-sdk's EncryptionService interface
7
+ *
8
+ * This adapter assumes the NodeEncryptionClient is configured with PREFIXED
9
+ * wire format, which returns "__enc__<base64>" strings ready for API transmission.
10
+ */
11
+ class EncryptedFieldAdapter {
12
+ encryptionManager;
13
+ constructor(encryptionManager) {
14
+ this.encryptionManager = encryptionManager;
15
+ }
16
+ /**
17
+ * Encrypts a value using the encryption-sdk
18
+ * @param value The plaintext value to encrypt
19
+ * @returns Wire-format encrypted string ("__enc__<base64>")
20
+ */
21
+ async encrypt(value) {
22
+ try {
23
+ const result = await this.encryptionManager.encrypt(value);
24
+ if (typeof result === "string") {
25
+ return result;
26
+ }
27
+ throw new Error("The encryption manager returned an unexpected value. Please check the encryption manager configuration.");
28
+ }
29
+ catch (error) {
30
+ throw new Error(`Failed to encrypt field: ${error instanceof Error ? error.message : "Unknown error"}`);
31
+ }
32
+ }
33
+ /**
34
+ * Decrypts a wire-format encrypted value using the encryption-sdk
35
+ * @param value Wire-format encrypted string ("__enc__<base64>")
36
+ * @returns Decrypted plaintext value
37
+ */
38
+ async decrypt(value) {
39
+ try {
40
+ // Validate wire format
41
+ if (typeof value !== "string" || !value.startsWith("__enc__")) {
42
+ throw new Error('Invalid encrypted value format. Expected "__enc__<base64>" string.');
43
+ }
44
+ // NodeEncryptionClient.decrypt accepts string when in PREFIXED wire format mode
45
+ return await this.encryptionManager.decrypt(value);
46
+ }
47
+ catch (error) {
48
+ throw new Error(`Failed to decrypt field: ${error instanceof Error ? error.message : "Unknown error"}`);
49
+ }
50
+ }
51
+ }
52
+ exports.EncryptedFieldAdapter = EncryptedFieldAdapter;
53
+ //# sourceMappingURL=EncryptedFieldAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedFieldAdapter.js","sourceRoot":"","sources":["../../extensions/EncryptedFieldAdapter.ts"],"names":[],"mappings":";;;AAMA;;;;;;GAMG;AACH,MAAa,qBAAqB;IACZ;IAApB,YAAoB,iBAAuC;QAAvC,sBAAiB,GAAjB,iBAAiB,CAAsB;IAAG,CAAC;IAE/D;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,KAAa;QACzB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAE3D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC/B,OAAO,MAAM,CAAC;YAChB,CAAC;YAED,MAAM,IAAI,KAAK,CACb,yGAAyG,CAC1G,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,4BACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAC3C,EAAE,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,KAAa;QACzB,IAAI,CAAC;YACH,uBAAuB;YACvB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9D,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;YACJ,CAAC;YAED,gFAAgF;YAChF,OAAO,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,4BACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAC3C,EAAE,CACH,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AApDD,sDAoDC"}
package/dist/main.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ export { type EncryptedFieldSchema } from "@corsa-labs/encryption-core";
2
+ export { EncryptedComplianceClient } from "./extensions/EncryptedComplianceClient";
1
3
  export * from "./index";
2
4
  export * from "./webhooks";
package/dist/main.js CHANGED
@@ -14,6 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.EncryptedComplianceClient = void 0;
18
+ var EncryptedComplianceClient_1 = require("./extensions/EncryptedComplianceClient");
19
+ Object.defineProperty(exports, "EncryptedComplianceClient", { enumerable: true, get: function () { return EncryptedComplianceClient_1.EncryptedComplianceClient; } });
17
20
  __exportStar(require("./index"), exports);
18
21
  __exportStar(require("./webhooks"), exports);
19
22
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,6CAA2B"}
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,oFAAmF;AAA1E,sIAAA,yBAAyB,OAAA;AAClC,0CAAwB;AACxB,6CAA2B"}
@@ -24,7 +24,7 @@ export type CreateAlertDto = {
24
24
  /**
25
25
  * External reference ID for the alert
26
26
  */
27
- referenceId: string;
27
+ referenceId?: string;
28
28
  /**
29
29
  * Source information for the alert
30
30
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corsa-labs/sdk",
3
- "version": "3.9.1",
3
+ "version": "3.11.0",
4
4
  "description": "SDK for Corsa API",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -16,10 +16,10 @@
16
16
  },
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
+ "@corsa-labs/encryption-node": "1.0.8",
19
20
  "axios": "^0.30.0",
20
21
  "uuid": "^11.1.0"
21
22
  },
22
- "peerDependencies": {},
23
23
  "devDependencies": {
24
24
  "@semantic-release/npm": "^12.0.1",
25
25
  "@types/node": "^22.15.2",