@artu-ai/compliance-sdk 0.4.0 → 0.4.2
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/package.json +4 -5
- package/src/errors/api.ts +0 -305
- package/src/errors/base.ts +0 -127
- package/src/errors/index.ts +0 -63
- package/src/errors/upload.ts +0 -204
- package/src/errors/validation.ts +0 -163
- package/src/exports/base.ts +0 -139
- package/src/exports/index.ts +0 -187
- package/src/exports/mexico/actividad-vulnerable/avi.ts +0 -207
- package/src/exports/mexico/actividad-vulnerable/jys.ts +0 -214
- package/src/exports/mexico/actividad-vulnerable/tsc.ts +0 -202
- package/src/exports/mexico/index.ts +0 -215
- package/src/models/Address.ts +0 -235
- package/src/models/BankAccount.ts +0 -235
- package/src/models/Client.ts +0 -363
- package/src/models/ContactMethod.ts +0 -197
- package/src/models/Document.ts +0 -355
- package/src/models/LinkedClient.ts +0 -84
- package/src/models/Report.ts +0 -193
- package/src/models/ReportItem.ts +0 -211
- package/src/models/Transaction.ts +0 -219
- package/src/models/base.ts +0 -56
- package/src/models/index.ts +0 -148
- package/src/models/mex/MexAddress.ts +0 -184
- package/src/models/mex/MexBankAccount.ts +0 -121
- package/src/models/mex/MexClient.ts +0 -177
- package/src/models/mex/MexDocument.ts +0 -890
- package/src/models/mex/MexReport.ts +0 -99
- package/src/models/mex/MexReportItem.ts +0 -79
- package/src/models/mex/MexTransaction.ts +0 -105
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableClient.ts +0 -66
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableReport.ts +0 -73
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableReportItem.ts +0 -74
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableTransaction.ts +0 -50
- package/src/models/mex/actividad-vulnerable/avi/MexAVIClient.ts +0 -80
- package/src/models/mex/actividad-vulnerable/avi/MexAVIReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/avi/MexAVIReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/avi/MexAVITransaction.ts +0 -157
- package/src/models/mex/actividad-vulnerable/index.ts +0 -78
- package/src/models/mex/actividad-vulnerable/jys/MexJYSClient.ts +0 -73
- package/src/models/mex/actividad-vulnerable/jys/MexJYSReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/jys/MexJYSReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/jys/MexJYSTransaction.ts +0 -178
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCClient.ts +0 -73
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCTransaction.ts +0 -104
- package/src/models/mex/index.ts +0 -57
- package/src/models/types.ts +0 -196
- package/src/namespaces/index.ts +0 -29
- package/src/namespaces/mexico/actividad-vulnerable/avi/index.ts +0 -62
- package/src/namespaces/mexico/actividad-vulnerable/index.ts +0 -79
- package/src/namespaces/mexico/actividad-vulnerable/jys/index.ts +0 -72
- package/src/namespaces/mexico/actividad-vulnerable/tsc/index.ts +0 -60
- package/src/namespaces/mexico/index.ts +0 -325
- package/src/resources/addresses.ts +0 -391
- package/src/resources/bank-accounts.ts +0 -417
- package/src/resources/base.ts +0 -327
- package/src/resources/clients.ts +0 -808
- package/src/resources/contact-methods.ts +0 -412
- package/src/resources/documents.ts +0 -688
- package/src/resources/index.ts +0 -40
- package/src/resources/mex/actividad-vulnerable/avi/clients.ts +0 -559
- package/src/resources/mex/actividad-vulnerable/avi/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/avi/reports.ts +0 -609
- package/src/resources/mex/actividad-vulnerable/avi/transactions.ts +0 -404
- package/src/resources/mex/actividad-vulnerable/index.ts +0 -12
- package/src/resources/mex/actividad-vulnerable/jys/clients.ts +0 -445
- package/src/resources/mex/actividad-vulnerable/jys/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/jys/reports.ts +0 -591
- package/src/resources/mex/actividad-vulnerable/jys/transactions.ts +0 -395
- package/src/resources/mex/actividad-vulnerable/tsc/clients.ts +0 -445
- package/src/resources/mex/actividad-vulnerable/tsc/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/tsc/reports.ts +0 -591
- package/src/resources/mex/actividad-vulnerable/tsc/transactions.ts +0 -404
- package/src/resources/mex/addresses.ts +0 -493
- package/src/resources/mex/bank-accounts.ts +0 -283
- package/src/resources/mex/clients.ts +0 -758
- package/src/resources/mex/ebr.ts +0 -621
- package/src/resources/mex/index.ts +0 -23
- package/src/resources/mex/reports.ts +0 -643
- package/src/resources/mex/transactions.ts +0 -422
- package/src/resources/reports.ts +0 -515
- package/src/resources/transactions.ts +0 -358
- package/src/sdk/ComplianceSDK.ts +0 -812
- package/src/sdk/base.ts +0 -43
- package/src/sdk/index.ts +0 -98
- package/src/sdk/mex/ComplianceSDK.ts +0 -147
- package/src/sdk/mex/actividad-vulnerable/avi/ComplianceSDK.ts +0 -55
- package/src/sdk/mex/actividad-vulnerable/avi/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/avi/types.ts +0 -86
- package/src/sdk/mex/actividad-vulnerable/index.ts +0 -58
- package/src/sdk/mex/actividad-vulnerable/jys/ComplianceSDK.ts +0 -54
- package/src/sdk/mex/actividad-vulnerable/jys/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/jys/types.ts +0 -86
- package/src/sdk/mex/actividad-vulnerable/tsc/ComplianceSDK.ts +0 -54
- package/src/sdk/mex/actividad-vulnerable/tsc/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/tsc/types.ts +0 -86
- package/src/sdk/mex/index.ts +0 -66
- package/src/sdk/mex/types.ts +0 -88
- package/src/sdk/resource-registry.ts +0 -204
- package/src/sdk/sdk-registry.ts +0 -99
- package/src/sdk/types.ts +0 -304
- package/src/utils/environment.ts +0 -187
- package/src/utils/filters.ts +0 -412
- package/src/utils/index.ts +0 -134
- package/src/utils/pagination.ts +0 -143
- package/src/utils/session.ts +0 -303
- package/src/utils/trpc-client.ts +0 -242
- package/src/utils/upload.ts +0 -388
package/src/sdk/ComplianceSDK.ts
DELETED
|
@@ -1,812 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ComplianceSDK - Main SDK entry point
|
|
3
|
-
*
|
|
4
|
-
* This class provides access to all compliance API resources.
|
|
5
|
-
* It initializes the tRPC client and all resource managers.
|
|
6
|
-
*
|
|
7
|
-
* The SDK can be scoped to a specific jurisdiction and/or actividadVulnerable,
|
|
8
|
-
* which automatically applies to all resource operations.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* // Unscoped SDK - works with any jurisdiction
|
|
13
|
-
* const sdk = new ComplianceSDK({
|
|
14
|
-
* apiKey: process.env.COMPLIANCE_API_KEY!,
|
|
15
|
-
* environment: "test",
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* // Mexico-scoped SDK
|
|
19
|
-
* const mexSDK = new ComplianceSDK({
|
|
20
|
-
* apiKey: process.env.COMPLIANCE_API_KEY!,
|
|
21
|
-
* environment: "test",
|
|
22
|
-
* jurisdiction: "MX",
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* // Mexico AVI-scoped SDK
|
|
26
|
-
* const aviSDK = new ComplianceSDK({
|
|
27
|
-
* apiKey: process.env.COMPLIANCE_API_KEY!,
|
|
28
|
-
* environment: "test",
|
|
29
|
-
* jurisdiction: "MX",
|
|
30
|
-
* actividadVulnerable: CodigoActividad.AVI,
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* // When scoped, resources automatically use the jurisdiction/actividadVulnerable
|
|
34
|
-
* const client = await aviSDK.clients.create({
|
|
35
|
-
* type: ClientType.Person,
|
|
36
|
-
* name: "Juan García",
|
|
37
|
-
* // primaryJurisdiction defaults to "MX"
|
|
38
|
-
* // jurisdictions.MX.actividadVulnerable.AVI is auto-initialized
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
import { Jurisdiction, CodigoActividad } from "@artu-ai/shared";
|
|
44
|
-
import {
|
|
45
|
-
createAPIClient,
|
|
46
|
-
type TRPCClient,
|
|
47
|
-
type APIVersion,
|
|
48
|
-
type SDKEnvironment,
|
|
49
|
-
LATEST_API_VERSION,
|
|
50
|
-
DEFAULT_TIMEOUT,
|
|
51
|
-
} from "../utils/trpc-client";
|
|
52
|
-
import {
|
|
53
|
-
resolveEnvironment,
|
|
54
|
-
resolveBaseUrl,
|
|
55
|
-
resolveOrganizationId,
|
|
56
|
-
} from "../utils/environment";
|
|
57
|
-
import {
|
|
58
|
-
type SDKScope,
|
|
59
|
-
type Environment,
|
|
60
|
-
type BaseComplianceSDK,
|
|
61
|
-
type OtherJurisdictionSDKOptions,
|
|
62
|
-
type ComplianceAuthMode,
|
|
63
|
-
type FetchCredentials,
|
|
64
|
-
isMexicoScope,
|
|
65
|
-
buildScope,
|
|
66
|
-
} from "./types";
|
|
67
|
-
import { getResourceFactories } from "./resource-registry";
|
|
68
|
-
import { getSDKClass } from "./sdk-registry";
|
|
69
|
-
import { type UnscopedSDKOptions } from "./base";
|
|
70
|
-
// Import Mexico types from type files directly to avoid circular dependency through barrel
|
|
71
|
-
import {
|
|
72
|
-
type ComplianceSDKOptionsMexico,
|
|
73
|
-
type MexicoSDKOptions,
|
|
74
|
-
type MexicoComplianceSDK,
|
|
75
|
-
} from "./mex/types";
|
|
76
|
-
import {
|
|
77
|
-
type AVISDKOptions,
|
|
78
|
-
type AVIComplianceSDK,
|
|
79
|
-
} from "./mex/actividad-vulnerable/avi/types";
|
|
80
|
-
import {
|
|
81
|
-
type JYSSDKOptions,
|
|
82
|
-
type JYSComplianceSDK,
|
|
83
|
-
} from "./mex/actividad-vulnerable/jys/types";
|
|
84
|
-
import {
|
|
85
|
-
type TSCSDKOptions,
|
|
86
|
-
type TSCComplianceSDK,
|
|
87
|
-
} from "./mex/actividad-vulnerable/tsc/types";
|
|
88
|
-
import {
|
|
89
|
-
fetchSession,
|
|
90
|
-
type SDKSessionOptions,
|
|
91
|
-
type SDKSessionOptionsWithReturnTo,
|
|
92
|
-
type SessionResult,
|
|
93
|
-
type SessionResultWithRedirect,
|
|
94
|
-
type SessionResultWithoutRedirect,
|
|
95
|
-
} from "../utils/session";
|
|
96
|
-
|
|
97
|
-
// Re-export base options type for sub-exports
|
|
98
|
-
export type { ComplianceSDKOptionsBase } from "./types";
|
|
99
|
-
|
|
100
|
-
// Resources
|
|
101
|
-
import {
|
|
102
|
-
type ClientsResource,
|
|
103
|
-
type TransactionsResource,
|
|
104
|
-
type ReportsResource,
|
|
105
|
-
BankAccountsResource,
|
|
106
|
-
AddressesResource,
|
|
107
|
-
ContactMethodsResource,
|
|
108
|
-
DocumentsResource,
|
|
109
|
-
} from "../resources";
|
|
110
|
-
|
|
111
|
-
// ===========================
|
|
112
|
-
// Re-exports
|
|
113
|
-
// ===========================
|
|
114
|
-
|
|
115
|
-
// Re-export SDKScope for external use
|
|
116
|
-
export type { SDKScope };
|
|
117
|
-
|
|
118
|
-
// Re-export Mexico SDK types for convenience
|
|
119
|
-
export type {
|
|
120
|
-
ComplianceSDKOptionsMexico,
|
|
121
|
-
MexicoSDKOptions,
|
|
122
|
-
AVISDKOptions,
|
|
123
|
-
JYSSDKOptions,
|
|
124
|
-
TSCSDKOptions,
|
|
125
|
-
MexicoComplianceSDK,
|
|
126
|
-
AVIComplianceSDK,
|
|
127
|
-
JYSComplianceSDK,
|
|
128
|
-
TSCComplianceSDK,
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// ===========================
|
|
132
|
-
// SDK Options Types
|
|
133
|
-
// ===========================
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* SDK configuration options.
|
|
137
|
-
*
|
|
138
|
-
* Use `actividadVulnerable` only when `jurisdiction` is `Jurisdiction.Mexico`.
|
|
139
|
-
*/
|
|
140
|
-
export type ComplianceSDKOptions =
|
|
141
|
-
| UnscopedSDKOptions
|
|
142
|
-
| ComplianceSDKOptionsMexico;
|
|
143
|
-
|
|
144
|
-
// ===========================
|
|
145
|
-
// Typed SDK Interfaces
|
|
146
|
-
// ===========================
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Unscoped SDK - uses base resource types
|
|
150
|
-
*/
|
|
151
|
-
export interface UnscopedComplianceSDK extends BaseComplianceSDK {
|
|
152
|
-
// Core resources (base types)
|
|
153
|
-
readonly clients: ClientsResource;
|
|
154
|
-
readonly transactions: TransactionsResource;
|
|
155
|
-
readonly reports: ReportsResource;
|
|
156
|
-
readonly bankAccounts: BankAccountsResource;
|
|
157
|
-
|
|
158
|
-
// Supporting resources (base types)
|
|
159
|
-
readonly addresses: AddressesResource;
|
|
160
|
-
readonly contactMethods: ContactMethodsResource;
|
|
161
|
-
readonly documents: DocumentsResource;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// ===========================
|
|
165
|
-
// ComplianceSDK Class
|
|
166
|
-
// ===========================
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Main entry point for the Compliance SDK.
|
|
170
|
-
*
|
|
171
|
-
* Provides access to all API resources:
|
|
172
|
-
* - `clients` - Client management (individuals, companies, trusts)
|
|
173
|
-
* - `transactions` - Transaction management
|
|
174
|
-
* - `addresses` - Address management
|
|
175
|
-
* - `contactMethods` - Contact method management
|
|
176
|
-
* - `bankAccounts` - Bank account management
|
|
177
|
-
* - `documents` - Document upload and management
|
|
178
|
-
* - `reports` - Regulatory report generation and submission
|
|
179
|
-
*
|
|
180
|
-
* ## Scoping
|
|
181
|
-
*
|
|
182
|
-
* The SDK can be scoped to a specific jurisdiction and/or actividadVulnerable:
|
|
183
|
-
*
|
|
184
|
-
* ```typescript
|
|
185
|
-
* // Unscoped - generic SDK
|
|
186
|
-
* const sdk = new ComplianceSDK({ apiKey, environment: "test" });
|
|
187
|
-
*
|
|
188
|
-
* // Scoped to Mexico
|
|
189
|
-
* const mexSDK = new ComplianceSDK({
|
|
190
|
-
* apiKey,
|
|
191
|
-
* environment: "test",
|
|
192
|
-
* jurisdiction: Jurisdiction.Mexico,
|
|
193
|
-
* });
|
|
194
|
-
*
|
|
195
|
-
* // Scoped to Mexico AVI actividadVulnerable
|
|
196
|
-
* const aviSDK = new ComplianceSDK({
|
|
197
|
-
* apiKey,
|
|
198
|
-
* environment: "test",
|
|
199
|
-
* jurisdiction: Jurisdiction.Mexico,
|
|
200
|
-
* actividadVulnerable: CodigoActividad.AVI,
|
|
201
|
-
* });
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* When scoped:
|
|
205
|
-
* - Create operations default to the specified jurisdiction/actividadVulnerable
|
|
206
|
-
* - List operations filter by the specified jurisdiction/actividadVulnerable
|
|
207
|
-
* - Models returned are the appropriate type for the scope
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```typescript
|
|
211
|
-
* import { ComplianceSDK, ClientType, Jurisdiction, CodigoActividad } from "@artu/compliance-sdk";
|
|
212
|
-
*
|
|
213
|
-
* const sdk = new ComplianceSDK({
|
|
214
|
-
* apiKey: process.env.COMPLIANCE_API_KEY!,
|
|
215
|
-
* environment: "test",
|
|
216
|
-
* jurisdiction: Jurisdiction.Mexico,
|
|
217
|
-
* actividadVulnerable: CodigoActividad.AVI,
|
|
218
|
-
* });
|
|
219
|
-
*
|
|
220
|
-
* // Check scope
|
|
221
|
-
* console.log(sdk.jurisdiction); // "MX"
|
|
222
|
-
* console.log(sdk.actividadVulnerable); // "AVI"
|
|
223
|
-
* console.log(sdk.isMexico); // true
|
|
224
|
-
*
|
|
225
|
-
* // Create a client - jurisdiction/actividadVulnerable are auto-applied
|
|
226
|
-
* const client = await sdk.clients.create({
|
|
227
|
-
* type: ClientType.Person,
|
|
228
|
-
* name: "Juan García",
|
|
229
|
-
* });
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
export class ComplianceSDKImpl {
|
|
233
|
-
// ===========================
|
|
234
|
-
// Protected Properties (accessible by subclasses)
|
|
235
|
-
// ===========================
|
|
236
|
-
|
|
237
|
-
/** tRPC client for API communication */
|
|
238
|
-
protected readonly trpc!: TRPCClient;
|
|
239
|
-
|
|
240
|
-
/** Current environment */
|
|
241
|
-
protected readonly _environment!: Environment;
|
|
242
|
-
|
|
243
|
-
/** Current API version */
|
|
244
|
-
protected readonly _apiVersion!: APIVersion;
|
|
245
|
-
|
|
246
|
-
/** SDK scope (jurisdiction and actividadVulnerable) */
|
|
247
|
-
protected readonly _scope!: SDKScope;
|
|
248
|
-
|
|
249
|
-
/** Resolved base URL */
|
|
250
|
-
protected readonly _baseUrl!: string;
|
|
251
|
-
|
|
252
|
-
/** Auth mode */
|
|
253
|
-
protected readonly _authMode!: ComplianceAuthMode;
|
|
254
|
-
|
|
255
|
-
/** Credentials policy (cookie mode) */
|
|
256
|
-
protected readonly _credentials?: FetchCredentials;
|
|
257
|
-
|
|
258
|
-
/** Custom headers (cookie mode, for server-side cookie forwarding) */
|
|
259
|
-
protected readonly _headers?: Record<string, string>;
|
|
260
|
-
|
|
261
|
-
/** Organization ID for session login (cookie mode) */
|
|
262
|
-
protected readonly _organizationId?: string;
|
|
263
|
-
|
|
264
|
-
// ===========================
|
|
265
|
-
// Resource Managers
|
|
266
|
-
// ===========================
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Clients resource manager.
|
|
270
|
-
*
|
|
271
|
-
* Provides CRUD operations for clients (individuals, companies, trusts).
|
|
272
|
-
* When SDK is scoped, creates and lists are automatically scoped.
|
|
273
|
-
*
|
|
274
|
-
* @example
|
|
275
|
-
* ```typescript
|
|
276
|
-
* // Create a client (uses SDK scope for jurisdiction/activity)
|
|
277
|
-
* const client = await sdk.clients.create({
|
|
278
|
-
* type: ClientType.Person,
|
|
279
|
-
* name: "Juan García",
|
|
280
|
-
* });
|
|
281
|
-
*
|
|
282
|
-
* // List clients (filtered by SDK scope)
|
|
283
|
-
* const clients = await sdk.clients.list();
|
|
284
|
-
*
|
|
285
|
-
* // Iterate through all clients in scope
|
|
286
|
-
* for await (const client of sdk.clients.iterate()) {
|
|
287
|
-
* console.log(client.name);
|
|
288
|
-
* }
|
|
289
|
-
* ```
|
|
290
|
-
*/
|
|
291
|
-
public readonly clients!: ClientsResource;
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Transactions resource manager.
|
|
295
|
-
*
|
|
296
|
-
* Provides CRUD operations for transactions and client linking.
|
|
297
|
-
* When SDK is scoped, creates and lists are automatically scoped.
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* ```typescript
|
|
301
|
-
* // Create a transaction (uses SDK scope)
|
|
302
|
-
* const txn = await sdk.transactions.create({
|
|
303
|
-
* amount: 50000,
|
|
304
|
-
* currency: Currency.MXN,
|
|
305
|
-
* });
|
|
306
|
-
*
|
|
307
|
-
* // Link a client to transaction
|
|
308
|
-
* await sdk.transactions.linkClient(txn.id, clientId, "originator");
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
|
-
public readonly transactions!: TransactionsResource;
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Addresses resource manager.
|
|
315
|
-
*
|
|
316
|
-
* Provides CRUD operations for client addresses.
|
|
317
|
-
*
|
|
318
|
-
* @example
|
|
319
|
-
* ```typescript
|
|
320
|
-
* const address = await sdk.addresses.create({
|
|
321
|
-
* clientId,
|
|
322
|
-
* type: AddressType.Home,
|
|
323
|
-
* street: "Av. Reforma 222",
|
|
324
|
-
* city: "México",
|
|
325
|
-
* country: Country.Mexico,
|
|
326
|
-
* });
|
|
327
|
-
* ```
|
|
328
|
-
*/
|
|
329
|
-
public readonly addresses!: AddressesResource;
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Contact methods resource manager.
|
|
333
|
-
*
|
|
334
|
-
* Provides CRUD operations for client contact methods (email, phone).
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```typescript
|
|
338
|
-
* const contact = await sdk.contactMethods.create({
|
|
339
|
-
* clientId,
|
|
340
|
-
* type: ContactMethodType.Email,
|
|
341
|
-
* value: "juan@example.com",
|
|
342
|
-
* });
|
|
343
|
-
* ```
|
|
344
|
-
*/
|
|
345
|
-
public readonly contactMethods!: ContactMethodsResource;
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Bank accounts resource manager.
|
|
349
|
-
*
|
|
350
|
-
* Provides CRUD operations for client bank accounts.
|
|
351
|
-
*
|
|
352
|
-
* @example
|
|
353
|
-
* ```typescript
|
|
354
|
-
* const account = await sdk.bankAccounts.create({
|
|
355
|
-
* clientId,
|
|
356
|
-
* type: BankAccountType.Checking,
|
|
357
|
-
* bankName: "BBVA",
|
|
358
|
-
* });
|
|
359
|
-
* ```
|
|
360
|
-
*/
|
|
361
|
-
public readonly bankAccounts!: BankAccountsResource;
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Documents resource manager.
|
|
365
|
-
*
|
|
366
|
-
* Provides upload, download, and management for client documents.
|
|
367
|
-
*
|
|
368
|
-
* @example
|
|
369
|
-
* ```typescript
|
|
370
|
-
* const doc = await sdk.documents.upload({
|
|
371
|
-
* clientId,
|
|
372
|
-
* category: DocumentCategory.Identification,
|
|
373
|
-
* type: MexDocumentType.INE,
|
|
374
|
-
* file: buffer,
|
|
375
|
-
* filename: "ine.pdf",
|
|
376
|
-
* });
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
public readonly documents!: DocumentsResource;
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Reports resource manager.
|
|
383
|
-
*
|
|
384
|
-
* Provides CRUD operations for regulatory reports.
|
|
385
|
-
* When SDK is scoped, creates and lists are automatically scoped.
|
|
386
|
-
*
|
|
387
|
-
* @example
|
|
388
|
-
* ```typescript
|
|
389
|
-
* // Create a report (uses SDK scope for jurisdiction/activity)
|
|
390
|
-
* const report = await sdk.reports.create({
|
|
391
|
-
* // mesReportado is required for AVI scope
|
|
392
|
-
* jurisdictions: {
|
|
393
|
-
* MX: {
|
|
394
|
-
* actividadVulnerable: {
|
|
395
|
-
* AVI: { mesReportado: "202403" },
|
|
396
|
-
* },
|
|
397
|
-
* },
|
|
398
|
-
* },
|
|
399
|
-
* });
|
|
400
|
-
*
|
|
401
|
-
* // Validate and generate
|
|
402
|
-
* const validation = await sdk.reports.validateReport(report.id);
|
|
403
|
-
* if (validation.valid) {
|
|
404
|
-
* const result = await sdk.reports.generate(report.id);
|
|
405
|
-
* }
|
|
406
|
-
* ```
|
|
407
|
-
*/
|
|
408
|
-
public readonly reports!: ReportsResource;
|
|
409
|
-
|
|
410
|
-
// ===========================
|
|
411
|
-
// Constructor
|
|
412
|
-
// ===========================
|
|
413
|
-
|
|
414
|
-
constructor(options: ComplianceSDKOptions) {
|
|
415
|
-
const {
|
|
416
|
-
environment,
|
|
417
|
-
baseUrl,
|
|
418
|
-
organizationId,
|
|
419
|
-
apiVersion = LATEST_API_VERSION,
|
|
420
|
-
timeout = DEFAULT_TIMEOUT,
|
|
421
|
-
jurisdiction,
|
|
422
|
-
mode,
|
|
423
|
-
...authOptions
|
|
424
|
-
} = options;
|
|
425
|
-
|
|
426
|
-
// Extract actividadVulnerable only for Mexico options
|
|
427
|
-
const actividadVulnerable =
|
|
428
|
-
"actividadVulnerable" in options
|
|
429
|
-
? options.actividadVulnerable
|
|
430
|
-
: undefined;
|
|
431
|
-
|
|
432
|
-
// Build scope early for SDK class dispatch
|
|
433
|
-
const scope = buildScope(jurisdiction, actividadVulnerable);
|
|
434
|
-
|
|
435
|
-
// === SDK Class Dispatch ===
|
|
436
|
-
// If we're directly constructing ComplianceSDKImpl (not via super() from subclass),
|
|
437
|
-
// check if a jurisdiction-specific SDK class is registered and return that instead.
|
|
438
|
-
if (new.target === ComplianceSDKImpl) {
|
|
439
|
-
const SDKClass = getSDKClass(scope);
|
|
440
|
-
if (SDKClass) {
|
|
441
|
-
// Return instance of jurisdiction-specific SDK
|
|
442
|
-
return new SDKClass(options) as this;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// === Normal base SDK initialization ===
|
|
447
|
-
|
|
448
|
-
const authMode: ComplianceAuthMode = mode ?? "apiKey";
|
|
449
|
-
|
|
450
|
-
const resolvedApiKey =
|
|
451
|
-
authMode === "apiKey"
|
|
452
|
-
? "apiKey" in authOptions
|
|
453
|
-
? authOptions.apiKey
|
|
454
|
-
: process.env.ARTU_API_KEY
|
|
455
|
-
: undefined;
|
|
456
|
-
|
|
457
|
-
const resolvedCredentials: FetchCredentials | undefined =
|
|
458
|
-
authMode === "cookie"
|
|
459
|
-
? "credentials" in authOptions
|
|
460
|
-
? authOptions.credentials
|
|
461
|
-
: "include"
|
|
462
|
-
: undefined;
|
|
463
|
-
|
|
464
|
-
const resolvedHeaders: Record<string, string> | undefined =
|
|
465
|
-
authMode === "cookie" && "headers" in authOptions
|
|
466
|
-
? authOptions.headers
|
|
467
|
-
: undefined;
|
|
468
|
-
|
|
469
|
-
// Validate API key when using apiKey auth mode
|
|
470
|
-
if (authMode === "apiKey") {
|
|
471
|
-
if (!resolvedApiKey || typeof resolvedApiKey !== "string") {
|
|
472
|
-
throw new Error(
|
|
473
|
-
"API key is required. Provide it via auth.apiKey, options.apiKey, or set the ARTU_API_KEY environment variable."
|
|
474
|
-
);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
// Resolve environment (from options or env var, defaults to "test")
|
|
479
|
-
const resolvedEnv = resolveEnvironment(environment);
|
|
480
|
-
this._environment = resolvedEnv;
|
|
481
|
-
this._apiVersion = apiVersion;
|
|
482
|
-
|
|
483
|
-
// Resolve organization ID (from options or env var)
|
|
484
|
-
this._organizationId = organizationId ?? resolveOrganizationId();
|
|
485
|
-
|
|
486
|
-
// Validate actividadVulnerable requires Mexico jurisdiction
|
|
487
|
-
if (actividadVulnerable && jurisdiction !== Jurisdiction.Mexico) {
|
|
488
|
-
throw new Error(
|
|
489
|
-
`actividadVulnerable can only be specified when jurisdiction is Mexico. ` +
|
|
490
|
-
`Got jurisdiction: ${jurisdiction}`
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// Resolve base URL
|
|
495
|
-
const resolvedBaseUrl = resolveBaseUrl({
|
|
496
|
-
environment: resolvedEnv,
|
|
497
|
-
baseUrl,
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
// Store scope and base config
|
|
501
|
-
this._scope = scope;
|
|
502
|
-
this._baseUrl = resolvedBaseUrl;
|
|
503
|
-
this._authMode = authMode;
|
|
504
|
-
this._credentials = resolvedCredentials;
|
|
505
|
-
this._headers = resolvedHeaders;
|
|
506
|
-
|
|
507
|
-
// Create tRPC client
|
|
508
|
-
const trpcConfig =
|
|
509
|
-
authMode === "apiKey"
|
|
510
|
-
? {
|
|
511
|
-
mode: authMode,
|
|
512
|
-
apiKey: resolvedApiKey as string,
|
|
513
|
-
baseUrl: resolvedBaseUrl,
|
|
514
|
-
environment: resolvedEnv as SDKEnvironment,
|
|
515
|
-
apiVersion,
|
|
516
|
-
timeout,
|
|
517
|
-
organizationId: this._organizationId,
|
|
518
|
-
}
|
|
519
|
-
: {
|
|
520
|
-
mode: authMode,
|
|
521
|
-
credentials: resolvedCredentials,
|
|
522
|
-
headers: resolvedHeaders,
|
|
523
|
-
baseUrl: resolvedBaseUrl,
|
|
524
|
-
environment: resolvedEnv as SDKEnvironment,
|
|
525
|
-
apiVersion,
|
|
526
|
-
timeout,
|
|
527
|
-
organizationId: this._organizationId,
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
this.trpc = createAPIClient(trpcConfig);
|
|
531
|
-
|
|
532
|
-
// Initialize resource managers using registry
|
|
533
|
-
const resourceConfig = {
|
|
534
|
-
trpc: this.trpc,
|
|
535
|
-
scope: this._scope,
|
|
536
|
-
environment: resolvedEnv,
|
|
537
|
-
};
|
|
538
|
-
const factories = getResourceFactories(this._scope);
|
|
539
|
-
|
|
540
|
-
// Create scoped resources from registry
|
|
541
|
-
this.clients = factories.clients(resourceConfig);
|
|
542
|
-
this.transactions = factories.transactions(resourceConfig);
|
|
543
|
-
this.reports = factories.reports(resourceConfig);
|
|
544
|
-
|
|
545
|
-
// Bank accounts and addresses can be scoped or use base
|
|
546
|
-
this.bankAccounts = factories.bankAccounts
|
|
547
|
-
? factories.bankAccounts(resourceConfig)
|
|
548
|
-
: new BankAccountsResource(resourceConfig);
|
|
549
|
-
this.addresses = factories.addresses
|
|
550
|
-
? factories.addresses(resourceConfig)
|
|
551
|
-
: new AddressesResource(resourceConfig);
|
|
552
|
-
|
|
553
|
-
// Supporting resources (not scoped by jurisdiction)
|
|
554
|
-
this.contactMethods = new ContactMethodsResource(resourceConfig);
|
|
555
|
-
this.documents = new DocumentsResource(resourceConfig);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
// ===========================
|
|
559
|
-
// Public Getters - Environment
|
|
560
|
-
// ===========================
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* Current environment ("test" or "live").
|
|
564
|
-
*
|
|
565
|
-
* @example
|
|
566
|
-
* ```typescript
|
|
567
|
-
* console.log(`Running in ${sdk.environment} mode`);
|
|
568
|
-
* ```
|
|
569
|
-
*/
|
|
570
|
-
get environment(): Environment {
|
|
571
|
-
return this._environment;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Current API version.
|
|
576
|
-
*
|
|
577
|
-
* @example
|
|
578
|
-
* ```typescript
|
|
579
|
-
* console.log(`Using API version ${sdk.apiVersion}`);
|
|
580
|
-
* ```
|
|
581
|
-
*/
|
|
582
|
-
get apiVersion(): APIVersion {
|
|
583
|
-
return this._apiVersion;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* Whether SDK is running in test environment.
|
|
588
|
-
*
|
|
589
|
-
* @example
|
|
590
|
-
* ```typescript
|
|
591
|
-
* if (sdk.isTest) {
|
|
592
|
-
* console.log("Running in test mode - no real data affected");
|
|
593
|
-
* }
|
|
594
|
-
* ```
|
|
595
|
-
*/
|
|
596
|
-
get isTest(): boolean {
|
|
597
|
-
return this._environment === "test";
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Whether SDK is running in live environment.
|
|
602
|
-
*
|
|
603
|
-
* @example
|
|
604
|
-
* ```typescript
|
|
605
|
-
* if (sdk.isLive) {
|
|
606
|
-
* console.log("CAUTION: Live environment - real data will be affected");
|
|
607
|
-
* }
|
|
608
|
-
* ```
|
|
609
|
-
*/
|
|
610
|
-
get isLive(): boolean {
|
|
611
|
-
return this._environment === "live";
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
// ===========================
|
|
615
|
-
// Public Getters - Scope
|
|
616
|
-
// ===========================
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Current jurisdiction scope, or undefined if unscoped.
|
|
620
|
-
*
|
|
621
|
-
* @example
|
|
622
|
-
* ```typescript
|
|
623
|
-
* if (sdk.jurisdiction === Jurisdiction.Mexico) {
|
|
624
|
-
* console.log("SDK is scoped to Mexico");
|
|
625
|
-
* }
|
|
626
|
-
* ```
|
|
627
|
-
*/
|
|
628
|
-
get jurisdiction(): Jurisdiction | undefined {
|
|
629
|
-
return this._scope.jurisdiction;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* Current actividadVulnerable scope, or undefined if unscoped.
|
|
634
|
-
* Only available when jurisdiction is Mexico.
|
|
635
|
-
*
|
|
636
|
-
* @example
|
|
637
|
-
* ```typescript
|
|
638
|
-
* if (sdk.actividadVulnerable === CodigoActividad.AVI) {
|
|
639
|
-
* console.log("SDK is scoped to Activos Virtuales");
|
|
640
|
-
* }
|
|
641
|
-
* ```
|
|
642
|
-
*/
|
|
643
|
-
get actividadVulnerable(): CodigoActividad | undefined {
|
|
644
|
-
return isMexicoScope(this._scope)
|
|
645
|
-
? this._scope.actividadVulnerable
|
|
646
|
-
: undefined;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
* The complete scope configuration.
|
|
651
|
-
*
|
|
652
|
-
* @example
|
|
653
|
-
* ```typescript
|
|
654
|
-
* console.log(sdk.scope); // { jurisdiction: "MX", actividadVulnerable: "AVI" }
|
|
655
|
-
* ```
|
|
656
|
-
*/
|
|
657
|
-
get scope(): Readonly<SDKScope> {
|
|
658
|
-
return { ...this._scope };
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Whether SDK is scoped to any jurisdiction.
|
|
663
|
-
*/
|
|
664
|
-
get isScoped(): boolean {
|
|
665
|
-
return this._scope.jurisdiction !== undefined;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
* Whether SDK is scoped to Mexico jurisdiction.
|
|
670
|
-
*/
|
|
671
|
-
get isMexico(): boolean {
|
|
672
|
-
return this._scope.jurisdiction === Jurisdiction.Mexico;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
/**
|
|
676
|
-
* Whether SDK is scoped to United States jurisdiction.
|
|
677
|
-
*/
|
|
678
|
-
get isUnitedStates(): boolean {
|
|
679
|
-
return this._scope.jurisdiction === Jurisdiction.UnitedStates;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
/**
|
|
683
|
-
* Whether SDK is scoped to an Actividad Vulnerable activity.
|
|
684
|
-
*/
|
|
685
|
-
get isActividadVulnerable(): boolean {
|
|
686
|
-
return (
|
|
687
|
-
isMexicoScope(this._scope) &&
|
|
688
|
-
this._scope.actividadVulnerable !== undefined
|
|
689
|
-
);
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Fetches current session info from the API (/auth/me).
|
|
694
|
-
* Only available in cookie auth mode.
|
|
695
|
-
*
|
|
696
|
-
* @example Basic usage (session can be null)
|
|
697
|
-
* ```typescript
|
|
698
|
-
* const result = await sdk.session();
|
|
699
|
-
* if (result.isAuthenticated) {
|
|
700
|
-
* console.log("User:", result.session.userId);
|
|
701
|
-
* }
|
|
702
|
-
* ```
|
|
703
|
-
*
|
|
704
|
-
* @example With returnTo (strongly typed - redirectUrl present when not authenticated)
|
|
705
|
-
* ```typescript
|
|
706
|
-
* // In Next.js Server Component
|
|
707
|
-
* import { redirect, headers } from "next/navigation";
|
|
708
|
-
*
|
|
709
|
-
* const h = await headers();
|
|
710
|
-
* const host = h.get("host") ?? "localhost:3000";
|
|
711
|
-
* const proto = h.get("x-forwarded-proto") ?? "http";
|
|
712
|
-
* const returnTo = `${proto}://${host}/env/test/dashboard`;
|
|
713
|
-
*
|
|
714
|
-
* const result = await sdk.session({ returnTo });
|
|
715
|
-
*
|
|
716
|
-
* if (result.redirectUrl) {
|
|
717
|
-
* redirect(result.redirectUrl);
|
|
718
|
-
* }
|
|
719
|
-
*
|
|
720
|
-
* // result.session is guaranteed here (TypeScript knows it's not null)
|
|
721
|
-
* console.log("User:", result.session.userId);
|
|
722
|
-
* ```
|
|
723
|
-
*/
|
|
724
|
-
async session(
|
|
725
|
-
options: SDKSessionOptionsWithReturnTo
|
|
726
|
-
): Promise<SessionResultWithRedirect>;
|
|
727
|
-
async session(
|
|
728
|
-
options?: SDKSessionOptions
|
|
729
|
-
): Promise<SessionResultWithoutRedirect>;
|
|
730
|
-
async session(options?: SDKSessionOptions): Promise<SessionResult> {
|
|
731
|
-
if (this._authMode !== "cookie") {
|
|
732
|
-
throw new Error(
|
|
733
|
-
"session() is only available when using cookie auth mode."
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
const baseOptions = {
|
|
738
|
-
baseUrl: this._baseUrl,
|
|
739
|
-
environment: this._environment,
|
|
740
|
-
credentials: this._credentials ?? "include",
|
|
741
|
-
headers: this._headers,
|
|
742
|
-
// Use provided organizationId or fall back to SDK-level config
|
|
743
|
-
organizationId: options?.organizationId ?? this._organizationId,
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
if (options?.returnTo) {
|
|
747
|
-
return fetchSession({
|
|
748
|
-
...baseOptions,
|
|
749
|
-
returnTo: options.returnTo,
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
return fetchSession(baseOptions);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// ===========================
|
|
758
|
-
// Constructor Interface
|
|
759
|
-
// ===========================
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* ComplianceSDK constructor with overloaded signatures.
|
|
763
|
-
*
|
|
764
|
-
* This interface enables `new ComplianceSDK(options)` to return the correct
|
|
765
|
-
* typed SDK interface based on the jurisdiction and actividadVulnerable options.
|
|
766
|
-
*
|
|
767
|
-
* @example
|
|
768
|
-
* ```typescript
|
|
769
|
-
* // Unscoped SDK - base types
|
|
770
|
-
* const sdk = new ComplianceSDK({
|
|
771
|
-
* apiKey: "...",
|
|
772
|
-
* environment: "test",
|
|
773
|
-
* });
|
|
774
|
-
* // sdk.clients is ClientsResource
|
|
775
|
-
*
|
|
776
|
-
* // Mexico-scoped SDK
|
|
777
|
-
* const mexSdk = new ComplianceSDK({
|
|
778
|
-
* apiKey: "...",
|
|
779
|
-
* environment: "test",
|
|
780
|
-
* jurisdiction: "MX",
|
|
781
|
-
* });
|
|
782
|
-
* // mexSdk.clients is MexClientsResource
|
|
783
|
-
*
|
|
784
|
-
* // AVI-scoped SDK
|
|
785
|
-
* const aviSdk = new ComplianceSDK({
|
|
786
|
-
* apiKey: "...",
|
|
787
|
-
* environment: "test",
|
|
788
|
-
* jurisdiction: "MX",
|
|
789
|
-
* actividadVulnerable: "AVI",
|
|
790
|
-
* });
|
|
791
|
-
* // aviSdk.clients is AVIClientsResource
|
|
792
|
-
* // aviSdk.clients.create() accepts CreateAVIClientInput
|
|
793
|
-
* ```
|
|
794
|
-
*/
|
|
795
|
-
export interface ComplianceSDKConstructor {
|
|
796
|
-
new (options: AVISDKOptions): AVIComplianceSDK;
|
|
797
|
-
new (options: JYSSDKOptions): JYSComplianceSDK;
|
|
798
|
-
new (options: TSCSDKOptions): TSCComplianceSDK;
|
|
799
|
-
new (options: MexicoSDKOptions): MexicoComplianceSDK;
|
|
800
|
-
new (
|
|
801
|
-
options: OtherJurisdictionSDKOptions | UnscopedSDKOptions
|
|
802
|
-
): UnscopedComplianceSDK;
|
|
803
|
-
new (options: ComplianceSDKOptions): ComplianceSDK;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
// Cast the class to use the overloaded constructor interface
|
|
807
|
-
// This enables proper type inference when using `new ComplianceSDK(options)`
|
|
808
|
-
export const ComplianceSDK: ComplianceSDKConstructor =
|
|
809
|
-
ComplianceSDKImpl as ComplianceSDKConstructor;
|
|
810
|
-
|
|
811
|
-
// Also export as a type for those who need it
|
|
812
|
-
export type ComplianceSDK = InstanceType<typeof ComplianceSDKImpl>;
|