@artu-ai/compliance-sdk 0.4.1 → 0.4.3

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.
Files changed (110) hide show
  1. package/package.json +3 -4
  2. package/src/errors/api.ts +0 -305
  3. package/src/errors/base.ts +0 -127
  4. package/src/errors/index.ts +0 -63
  5. package/src/errors/upload.ts +0 -204
  6. package/src/errors/validation.ts +0 -163
  7. package/src/exports/base.ts +0 -139
  8. package/src/exports/index.ts +0 -187
  9. package/src/exports/mexico/actividad-vulnerable/avi.ts +0 -207
  10. package/src/exports/mexico/actividad-vulnerable/jys.ts +0 -214
  11. package/src/exports/mexico/actividad-vulnerable/tsc.ts +0 -202
  12. package/src/exports/mexico/index.ts +0 -215
  13. package/src/models/Address.ts +0 -235
  14. package/src/models/BankAccount.ts +0 -235
  15. package/src/models/Client.ts +0 -363
  16. package/src/models/ContactMethod.ts +0 -197
  17. package/src/models/Document.ts +0 -355
  18. package/src/models/LinkedClient.ts +0 -84
  19. package/src/models/Report.ts +0 -193
  20. package/src/models/ReportItem.ts +0 -211
  21. package/src/models/Transaction.ts +0 -219
  22. package/src/models/base.ts +0 -56
  23. package/src/models/index.ts +0 -148
  24. package/src/models/mex/MexAddress.ts +0 -184
  25. package/src/models/mex/MexBankAccount.ts +0 -121
  26. package/src/models/mex/MexClient.ts +0 -177
  27. package/src/models/mex/MexDocument.ts +0 -890
  28. package/src/models/mex/MexReport.ts +0 -99
  29. package/src/models/mex/MexReportItem.ts +0 -79
  30. package/src/models/mex/MexTransaction.ts +0 -105
  31. package/src/models/mex/actividad-vulnerable/MexActividadVulnerableClient.ts +0 -66
  32. package/src/models/mex/actividad-vulnerable/MexActividadVulnerableReport.ts +0 -73
  33. package/src/models/mex/actividad-vulnerable/MexActividadVulnerableReportItem.ts +0 -74
  34. package/src/models/mex/actividad-vulnerable/MexActividadVulnerableTransaction.ts +0 -50
  35. package/src/models/mex/actividad-vulnerable/avi/MexAVIClient.ts +0 -80
  36. package/src/models/mex/actividad-vulnerable/avi/MexAVIReport.ts +0 -114
  37. package/src/models/mex/actividad-vulnerable/avi/MexAVIReportItem.ts +0 -105
  38. package/src/models/mex/actividad-vulnerable/avi/MexAVITransaction.ts +0 -157
  39. package/src/models/mex/actividad-vulnerable/index.ts +0 -78
  40. package/src/models/mex/actividad-vulnerable/jys/MexJYSClient.ts +0 -73
  41. package/src/models/mex/actividad-vulnerable/jys/MexJYSReport.ts +0 -114
  42. package/src/models/mex/actividad-vulnerable/jys/MexJYSReportItem.ts +0 -105
  43. package/src/models/mex/actividad-vulnerable/jys/MexJYSTransaction.ts +0 -178
  44. package/src/models/mex/actividad-vulnerable/tsc/MexTSCClient.ts +0 -73
  45. package/src/models/mex/actividad-vulnerable/tsc/MexTSCReport.ts +0 -114
  46. package/src/models/mex/actividad-vulnerable/tsc/MexTSCReportItem.ts +0 -105
  47. package/src/models/mex/actividad-vulnerable/tsc/MexTSCTransaction.ts +0 -104
  48. package/src/models/mex/index.ts +0 -57
  49. package/src/models/types.ts +0 -196
  50. package/src/namespaces/index.ts +0 -29
  51. package/src/namespaces/mexico/actividad-vulnerable/avi/index.ts +0 -62
  52. package/src/namespaces/mexico/actividad-vulnerable/index.ts +0 -79
  53. package/src/namespaces/mexico/actividad-vulnerable/jys/index.ts +0 -72
  54. package/src/namespaces/mexico/actividad-vulnerable/tsc/index.ts +0 -60
  55. package/src/namespaces/mexico/index.ts +0 -325
  56. package/src/resources/addresses.ts +0 -391
  57. package/src/resources/bank-accounts.ts +0 -417
  58. package/src/resources/base.ts +0 -327
  59. package/src/resources/clients.ts +0 -808
  60. package/src/resources/contact-methods.ts +0 -412
  61. package/src/resources/documents.ts +0 -688
  62. package/src/resources/index.ts +0 -40
  63. package/src/resources/mex/actividad-vulnerable/avi/clients.ts +0 -559
  64. package/src/resources/mex/actividad-vulnerable/avi/index.ts +0 -7
  65. package/src/resources/mex/actividad-vulnerable/avi/reports.ts +0 -609
  66. package/src/resources/mex/actividad-vulnerable/avi/transactions.ts +0 -404
  67. package/src/resources/mex/actividad-vulnerable/index.ts +0 -12
  68. package/src/resources/mex/actividad-vulnerable/jys/clients.ts +0 -445
  69. package/src/resources/mex/actividad-vulnerable/jys/index.ts +0 -7
  70. package/src/resources/mex/actividad-vulnerable/jys/reports.ts +0 -591
  71. package/src/resources/mex/actividad-vulnerable/jys/transactions.ts +0 -395
  72. package/src/resources/mex/actividad-vulnerable/tsc/clients.ts +0 -445
  73. package/src/resources/mex/actividad-vulnerable/tsc/index.ts +0 -7
  74. package/src/resources/mex/actividad-vulnerable/tsc/reports.ts +0 -591
  75. package/src/resources/mex/actividad-vulnerable/tsc/transactions.ts +0 -404
  76. package/src/resources/mex/addresses.ts +0 -493
  77. package/src/resources/mex/bank-accounts.ts +0 -283
  78. package/src/resources/mex/clients.ts +0 -758
  79. package/src/resources/mex/ebr.ts +0 -621
  80. package/src/resources/mex/index.ts +0 -23
  81. package/src/resources/mex/reports.ts +0 -643
  82. package/src/resources/mex/transactions.ts +0 -422
  83. package/src/resources/reports.ts +0 -515
  84. package/src/resources/transactions.ts +0 -358
  85. package/src/sdk/ComplianceSDK.ts +0 -812
  86. package/src/sdk/base.ts +0 -43
  87. package/src/sdk/index.ts +0 -98
  88. package/src/sdk/mex/ComplianceSDK.ts +0 -147
  89. package/src/sdk/mex/actividad-vulnerable/avi/ComplianceSDK.ts +0 -55
  90. package/src/sdk/mex/actividad-vulnerable/avi/index.ts +0 -16
  91. package/src/sdk/mex/actividad-vulnerable/avi/types.ts +0 -86
  92. package/src/sdk/mex/actividad-vulnerable/index.ts +0 -58
  93. package/src/sdk/mex/actividad-vulnerable/jys/ComplianceSDK.ts +0 -54
  94. package/src/sdk/mex/actividad-vulnerable/jys/index.ts +0 -16
  95. package/src/sdk/mex/actividad-vulnerable/jys/types.ts +0 -86
  96. package/src/sdk/mex/actividad-vulnerable/tsc/ComplianceSDK.ts +0 -54
  97. package/src/sdk/mex/actividad-vulnerable/tsc/index.ts +0 -16
  98. package/src/sdk/mex/actividad-vulnerable/tsc/types.ts +0 -86
  99. package/src/sdk/mex/index.ts +0 -66
  100. package/src/sdk/mex/types.ts +0 -88
  101. package/src/sdk/resource-registry.ts +0 -204
  102. package/src/sdk/sdk-registry.ts +0 -99
  103. package/src/sdk/types.ts +0 -304
  104. package/src/utils/environment.ts +0 -187
  105. package/src/utils/filters.ts +0 -412
  106. package/src/utils/index.ts +0 -134
  107. package/src/utils/pagination.ts +0 -143
  108. package/src/utils/session.ts +0 -303
  109. package/src/utils/trpc-client.ts +0 -242
  110. package/src/utils/upload.ts +0 -388
@@ -1,758 +0,0 @@
1
- /**
2
- * Mexico Clients Resource
3
- *
4
- * Extends ClientsResource with Mexico-specific behavior:
5
- * - Accepts flattened CreateMexClientInput (MX fields at root level)
6
- * - Automatically sets primaryJurisdiction to Mexico
7
- * - Filters list/iterate to Mexico clients only
8
- * - Returns MexClient models
9
- */
10
-
11
- import { z } from "zod";
12
- import type {
13
- CreateClientInput,
14
- UpdateClientInput,
15
- ClientFilter,
16
- ClientSort,
17
- ListOptions,
18
- PaginatedResponse,
19
- CreateMexClientInput,
20
- UpdateMexClientInput,
21
- AtomicBatchResult,
22
- PartialBatchResult,
23
- ClientRelationshipType,
24
- LinkedClient as LinkedClientInput,
25
- CreateAddressInput,
26
- UpdateAddressInput,
27
- CreateMexAddressInput,
28
- UpdateMexAddressInput,
29
- CreateContactMethodInput,
30
- UpdateContactMethodInput,
31
- CreateBankAccountInput,
32
- UpdateBankAccountInput,
33
- SyncItem,
34
- SyncResult,
35
- MexClientFilter,
36
- MexClientSort,
37
- } from "@artu-ai/shared";
38
- import {
39
- Jurisdiction,
40
- createMexClientInputSchema,
41
- updateMexClientInputSchema,
42
- linkedClientSchema,
43
- createMexAddressInputSchema,
44
- updateMexAddressInputSchema,
45
- createContactMethodInputSchema,
46
- updateContactMethodInputSchema,
47
- createBankAccountInputSchema,
48
- updateBankAccountInputSchema,
49
- replaceSyncItemSchema,
50
- transformSort,
51
- mexClientFieldMapping,
52
- } from "@artu-ai/shared";
53
- import {
54
- ClientsResource,
55
- type BatchOptions,
56
- type ClientIncludeMap,
57
- } from "../clients";
58
- import {
59
- MexClient,
60
- MexAddress,
61
- MexBankAccount,
62
- ContactMethod,
63
- LinkedClient,
64
- type ClientData,
65
- } from "../../models";
66
-
67
- // ===========================
68
- // MexClientsResource
69
- // ===========================
70
-
71
- /**
72
- * Mexico-scoped clients resource.
73
- *
74
- * Provides the same operations as ClientsResource but with:
75
- * - Flattened input types (MX fields at root level)
76
- * - Automatic jurisdiction scoping
77
- * - MexClient model return type
78
- *
79
- * @example
80
- * ```typescript
81
- * const mexSdk = new ComplianceSDK({
82
- * apiKey,
83
- * environment: "test",
84
- * jurisdiction: Jurisdiction.Mexico,
85
- * });
86
- *
87
- * // Create with flattened input
88
- * const client = await mexSdk.clients.create({
89
- * type: ClientType.Person,
90
- * name: "Juan García",
91
- * rfc: "GAJL850101ABC", // MX field at root
92
- * curp: "GAJL850101HDFRRL09", // MX field at root
93
- * actividadVulnerable: { // Activity data keyed by code
94
- * AVI: { username: "JGARCIA" },
95
- * },
96
- * });
97
- *
98
- * // List returns only Mexico clients
99
- * const { data } = await mexSdk.clients.list();
100
- * // data is MexClient[]
101
- * ```
102
- */
103
- export class MexClientsResource<
104
- TSort = MexClientSort,
105
- > extends ClientsResource<TSort> {
106
- // ─────────────────────────────────────────────────────────────────
107
- // CRUD Operations (override with flattened input types)
108
- // ─────────────────────────────────────────────────────────────────
109
-
110
- /**
111
- * Creates a new Mexico client with flattened input.
112
- *
113
- * @param data - Client creation data with MX fields at root level
114
- * @returns The created MexClient model
115
- */
116
- async create(data: CreateMexClientInput): Promise<MexClient> {
117
- const validated = this.validate(createMexClientInputSchema, data);
118
- const nestedData = this.transformToNested(validated);
119
-
120
- const response = await this.execute(() =>
121
- this.trpc.clients.create.mutate(nestedData)
122
- );
123
-
124
- return this.instantiate(response);
125
- }
126
-
127
- /**
128
- * Retrieves a client by ID.
129
- */
130
- async retrieve(id: string, include?: ClientIncludeMap): Promise<MexClient> {
131
- const response = await this.execute(() =>
132
- this.trpc.clients.retrieve.query({ id, include })
133
- );
134
- return this.instantiate(response);
135
- }
136
-
137
- /**
138
- * Retrieves a Mexico client by externalId.
139
- */
140
- async retrieveByExternalId(externalId: string): Promise<MexClient> {
141
- const response = await this.execute(() =>
142
- this.trpc.clients.retrieveByExternalId.query({ externalId })
143
- );
144
- return this.instantiate(response);
145
- }
146
-
147
- /**
148
- * Updates a Mexico client with flattened input.
149
- */
150
- async update(id: string, data: UpdateMexClientInput): Promise<MexClient> {
151
- const validated = this.validate(updateMexClientInputSchema, data);
152
- const nestedData = this.transformUpdateToNested(validated);
153
-
154
- const response = await this.execute(() =>
155
- this.trpc.clients.update.mutate({ id, data: nestedData })
156
- );
157
- return this.instantiate(response);
158
- }
159
-
160
- // ─────────────────────────────────────────────────────────────────
161
- // List & Pagination (scoped to Mexico)
162
- // ─────────────────────────────────────────────────────────────────
163
-
164
- /**
165
- * Lists Mexico clients with optional filtering.
166
- *
167
- * Accepts flattened Mexico filter (MX fields at root level) and automatically
168
- * transforms to nested format before calling the API.
169
- *
170
- * @example
171
- * ```typescript
172
- * // Filter with flattened MX fields
173
- * const { data } = await mexSdk.clients.list({
174
- * filter: {
175
- * name: { contains: "García" },
176
- * rfc: { startsWith: "GAJL" }, // MX field at root!
177
- * },
178
- * });
179
- * ```
180
- */
181
- async list(
182
- options?: ListOptions<MexClientFilter, TSort> & { includePrimaryContacts?: boolean }
183
- ): Promise<PaginatedResponse<MexClient>> {
184
- const scopedFilter = this.applyScopeToFilter(options?.filter);
185
- const scopedSort = this.applyScopeToSort(options?.sort);
186
-
187
- const response = await this.execute(() =>
188
- this.trpc.clients.list.query({
189
- ...options,
190
- filter: scopedFilter,
191
- sort: scopedSort,
192
- })
193
- );
194
-
195
- return {
196
- data: response.data.map((c) => this.instantiate(c)),
197
- pagination: response.pagination,
198
- };
199
- }
200
-
201
- /**
202
- * Iterates over Mexico clients.
203
- *
204
- * Accepts flattened Mexico filter (MX fields at root level) and automatically
205
- * transforms to nested format before calling the API.
206
- */
207
- iterate(filter?: MexClientFilter): AsyncGenerator<MexClient, void, undefined> {
208
- const scopedFilter = this.applyScopeToFilter(filter);
209
- return this.createIterator<MexClient>({ filter: scopedFilter });
210
- }
211
-
212
- // ─────────────────────────────────────────────────────────────────
213
- // Batch Operations
214
- // ─────────────────────────────────────────────────────────────────
215
-
216
- /**
217
- * Creates multiple Mexico clients with flattened input.
218
- */
219
- async createMany(
220
- clients: CreateMexClientInput[],
221
- options?: { atomic?: true }
222
- ): Promise<AtomicBatchResult<MexClient>>;
223
- async createMany(
224
- clients: CreateMexClientInput[],
225
- options: { atomic: false }
226
- ): Promise<PartialBatchResult<MexClient>>;
227
- async createMany(
228
- clients: CreateMexClientInput[],
229
- options: BatchOptions = {}
230
- ): Promise<AtomicBatchResult<MexClient> | PartialBatchResult<MexClient>> {
231
- const atomic = options.atomic ?? true;
232
- const validated = this.validate(
233
- z.array(createMexClientInputSchema),
234
- clients
235
- );
236
- const nestedClients = validated.map((c) => this.transformToNested(c));
237
-
238
- const response = await this.execute(() =>
239
- this.trpc.clients.createMany.mutate({ items: nestedClients, atomic })
240
- );
241
-
242
- if (response.atomic) {
243
- return {
244
- atomic: true,
245
- data: response.data.map((c) => this.instantiate(c)),
246
- };
247
- } else {
248
- return {
249
- atomic: false,
250
- succeeded: response.succeeded.map((item) => ({
251
- index: item.index,
252
- data: this.instantiate(item.data),
253
- })),
254
- failed: response.failed,
255
- };
256
- }
257
- }
258
-
259
- /**
260
- * Updates multiple Mexico clients.
261
- */
262
- async updateMany(
263
- updates: { id: string; data: UpdateMexClientInput }[],
264
- options?: { atomic?: true }
265
- ): Promise<AtomicBatchResult<MexClient>>;
266
- async updateMany(
267
- updates: { id: string; data: UpdateMexClientInput }[],
268
- options: { atomic: false }
269
- ): Promise<PartialBatchResult<MexClient>>;
270
- async updateMany(
271
- updates: { id: string; data: UpdateMexClientInput }[],
272
- options: BatchOptions = {}
273
- ): Promise<AtomicBatchResult<MexClient> | PartialBatchResult<MexClient>> {
274
- const atomic = options.atomic ?? true;
275
- const updateItemSchema = z.object({
276
- id: z.uuid(),
277
- data: updateMexClientInputSchema,
278
- });
279
-
280
- const validated = this.validate(z.array(updateItemSchema), updates);
281
- const nestedUpdates = validated.map((u) => ({
282
- id: u.id,
283
- data: this.transformUpdateToNested(u.data),
284
- }));
285
-
286
- const response = await this.execute(() =>
287
- this.trpc.clients.updateMany.mutate({ items: nestedUpdates, atomic })
288
- );
289
-
290
- if (response.atomic) {
291
- return {
292
- atomic: true,
293
- data: response.data.map((c) => this.instantiate(c)),
294
- };
295
- } else {
296
- return {
297
- atomic: false,
298
- succeeded: response.succeeded.map((item) => ({
299
- index: item.index,
300
- data: this.instantiate(item.data),
301
- })),
302
- failed: response.failed,
303
- };
304
- }
305
- }
306
-
307
- // ─────────────────────────────────────────────────────────────────
308
- // Client-to-Client Relationship Management (scoped returns)
309
- // ─────────────────────────────────────────────────────────────────
310
-
311
- async linkClient(
312
- parentClientId: string,
313
- childClientId: string,
314
- relationshipType: ClientRelationshipType,
315
- metadata?: Record<string, unknown>
316
- ): Promise<MexClient> {
317
- const response = await this.execute(() =>
318
- this.trpc.clients.linkClient.mutate({
319
- parentClientId,
320
- childClientId,
321
- relationshipType,
322
- metadata,
323
- })
324
- );
325
- return this.instantiate(response);
326
- }
327
-
328
- async unlinkClient(
329
- parentClientId: string,
330
- childClientId: string,
331
- relationshipType: ClientRelationshipType
332
- ): Promise<MexClient> {
333
- const response = await this.execute(() =>
334
- this.trpc.clients.unlinkClient.mutate({
335
- parentClientId,
336
- childClientId,
337
- relationshipType,
338
- })
339
- );
340
- return this.instantiate(response);
341
- }
342
-
343
- async listLinkedClients(
344
- parentClientId: string,
345
- relationshipType?: ClientRelationshipType
346
- ): Promise<LinkedClient[]> {
347
- return super.listLinkedClients(parentClientId, relationshipType);
348
- }
349
-
350
- async setLinkedClients(
351
- parentClientId: string,
352
- linkedClients: LinkedClientInput[]
353
- ): Promise<MexClient> {
354
- const validated = this.validate(z.array(linkedClientSchema), linkedClients);
355
-
356
- const response = await this.execute(() =>
357
- this.trpc.clients.setLinkedClients.mutate({
358
- parentClientId,
359
- linkedClients: validated,
360
- })
361
- );
362
- return this.instantiate(response);
363
- }
364
-
365
- // ─────────────────────────────────────────────────────────────────
366
- // Sync All (Atomic)
367
- // ─────────────────────────────────────────────────────────────────
368
-
369
- /**
370
- * Atomically updates a Mexico client and all related resources in a single transaction.
371
- *
372
- * Accepts flattened Mexico address input types for convenience.
373
- */
374
- async syncAll(
375
- clientId: string,
376
- data: {
377
- client?: UpdateMexClientInput;
378
- addresses?: SyncItem<CreateMexAddressInput>[];
379
- contactMethods?: SyncItem<CreateContactMethodInput>[];
380
- bankAccounts?: SyncItem<CreateBankAccountInput>[];
381
- linkedClients?: LinkedClientInput[];
382
- },
383
- options: { replaceMode: true }
384
- ): Promise<{
385
- client: MexClient;
386
- addresses: SyncResult<MexAddress>;
387
- contactMethods: SyncResult<ContactMethod>;
388
- bankAccounts: SyncResult<MexBankAccount>;
389
- }>;
390
- async syncAll(
391
- clientId: string,
392
- data: {
393
- client?: UpdateMexClientInput;
394
- addresses?: SyncItem<UpdateMexAddressInput>[];
395
- contactMethods?: SyncItem<UpdateContactMethodInput>[];
396
- bankAccounts?: SyncItem<UpdateBankAccountInput>[];
397
- linkedClients?: LinkedClientInput[];
398
- },
399
- options?: { replaceMode?: boolean }
400
- ): Promise<{
401
- client: MexClient;
402
- addresses: SyncResult<MexAddress>;
403
- contactMethods: SyncResult<ContactMethod>;
404
- bankAccounts: SyncResult<MexBankAccount>;
405
- }>;
406
- async syncAll(
407
- clientId: string,
408
- data: {
409
- client?: UpdateMexClientInput;
410
- addresses?: SyncItem<UpdateMexAddressInput | CreateMexAddressInput>[];
411
- contactMethods?: SyncItem<UpdateContactMethodInput | CreateContactMethodInput>[];
412
- bankAccounts?: SyncItem<UpdateBankAccountInput | CreateBankAccountInput>[];
413
- linkedClients?: LinkedClientInput[];
414
- },
415
- options?: { replaceMode?: boolean }
416
- ): Promise<{
417
- client: MexClient;
418
- addresses: SyncResult<MexAddress>;
419
- contactMethods: SyncResult<ContactMethod>;
420
- bankAccounts: SyncResult<MexBankAccount>;
421
- }> {
422
- // Validate and transform client input
423
- const validatedClient = data.client
424
- ? this.transformUpdateToNested(
425
- this.validate(updateMexClientInputSchema, data.client)
426
- )
427
- : undefined;
428
-
429
- // Validate and transform addresses (flattened MX → nested)
430
- let validatedAddresses: SyncItem<UpdateAddressInput | CreateAddressInput>[] | undefined;
431
- if (data.addresses) {
432
- const validated = this.validate(
433
- z.array(
434
- replaceSyncItemSchema(
435
- createMexAddressInputSchema,
436
- updateMexAddressInputSchema
437
- )
438
- ),
439
- data.addresses
440
- );
441
- validatedAddresses = validated.map((item) =>
442
- this.transformAddressSyncItem(item)
443
- );
444
- }
445
-
446
- // Validate contact methods (base types, no transform)
447
- const validatedContactMethods = data.contactMethods
448
- ? this.validate(
449
- z.array(
450
- replaceSyncItemSchema(
451
- createContactMethodInputSchema,
452
- updateContactMethodInputSchema
453
- )
454
- ),
455
- data.contactMethods
456
- )
457
- : undefined;
458
-
459
- // Validate bank accounts (base types, no transform)
460
- const validatedBankAccounts = data.bankAccounts
461
- ? this.validate(
462
- z.array(
463
- replaceSyncItemSchema(
464
- createBankAccountInputSchema,
465
- updateBankAccountInputSchema
466
- )
467
- ),
468
- data.bankAccounts
469
- )
470
- : undefined;
471
-
472
- const validatedLinkedClients = data.linkedClients
473
- ? this.validate(z.array(linkedClientSchema), data.linkedClients)
474
- : undefined;
475
-
476
- // Use type from trpc mutation to avoid type mismatch between imported types
477
- // and trpc's inferred types
478
- type SyncAllInput = Parameters<typeof this.trpc.clients.syncAll.mutate>[0];
479
-
480
- const response = await this.execute(() =>
481
- this.trpc.clients.syncAll.mutate({
482
- clientId,
483
- client: validatedClient,
484
- addresses: validatedAddresses as SyncAllInput["addresses"],
485
- contactMethods: validatedContactMethods,
486
- bankAccounts: validatedBankAccounts,
487
- linkedClients: validatedLinkedClients,
488
- replaceMode: options?.replaceMode,
489
- })
490
- );
491
-
492
- return {
493
- client: this.instantiate(response.client),
494
- addresses: {
495
- created: response.addresses.created.map((a) => new MexAddress(a)),
496
- updated: response.addresses.updated.map((a) => new MexAddress(a)),
497
- deleted: response.addresses.deleted,
498
- },
499
- contactMethods: {
500
- created: response.contactMethods.created.map((c) => new ContactMethod(c)),
501
- updated: response.contactMethods.updated.map((c) => new ContactMethod(c)),
502
- deleted: response.contactMethods.deleted,
503
- },
504
- bankAccounts: {
505
- created: response.bankAccounts.created.map((b) => new MexBankAccount(b)),
506
- updated: response.bankAccounts.updated.map((b) => new MexBankAccount(b)),
507
- deleted: response.bankAccounts.deleted,
508
- },
509
- };
510
- }
511
-
512
- // ─────────────────────────────────────────────────────────────────
513
- // Protected Helpers
514
- // ─────────────────────────────────────────────────────────────────
515
-
516
- /**
517
- * Transforms a flattened MexClientFilter to nested ClientFilter format
518
- * and applies Mexico jurisdiction scoping.
519
- *
520
- * Extracts MX-specific fields (rfc, curp, actividadEconomica, giroMercantil,
521
- * actividadVulnerable) from root level and nests them under jurisdictions.MX.
522
- */
523
- protected applyScopeToFilter(filter?: MexClientFilter): ClientFilter {
524
- if (!filter) {
525
- return {
526
- availableJurisdictions: Jurisdiction.Mexico,
527
- };
528
- }
529
-
530
- // Extract MX-specific filter fields
531
- const {
532
- rfc,
533
- curp,
534
- actividadEconomica,
535
- giroMercantil,
536
- actividadVulnerable,
537
- ...baseFields
538
- } = filter;
539
-
540
- // Build MX jurisdiction filter if any MX fields are present
541
- const hasMexFields =
542
- rfc !== undefined ||
543
- curp !== undefined ||
544
- actividadEconomica !== undefined ||
545
- giroMercantil !== undefined ||
546
- actividadVulnerable !== undefined;
547
-
548
- const mexFilter: Record<string, unknown> = {};
549
- if (rfc !== undefined) mexFilter.rfc = rfc;
550
- if (curp !== undefined) mexFilter.curp = curp;
551
- if (actividadEconomica !== undefined)
552
- mexFilter.actividadEconomica = actividadEconomica;
553
- if (giroMercantil !== undefined) mexFilter.giroMercantil = giroMercantil;
554
- if (actividadVulnerable !== undefined)
555
- mexFilter.actividadVulnerable = actividadVulnerable;
556
-
557
- return {
558
- ...baseFields,
559
- availableJurisdictions: Jurisdiction.Mexico,
560
- ...(hasMexFields && { jurisdictions: { MX: mexFilter } }),
561
- } as ClientFilter;
562
- }
563
-
564
- /**
565
- * Transforms a flattened MexClientSort to nested ClientSort format.
566
- *
567
- * Maps flattened field names (rfc, curp, actividadVulnerable.AVI.username)
568
- * to their full API paths (jurisdictions.MX.rfc, etc.).
569
- *
570
- * Note: Uses unknown parameter to allow derived classes to override with their own sort types.
571
- */
572
- protected applyScopeToSort(sort?: TSort): ClientSort | undefined {
573
- if (!sort || !Array.isArray(sort) || sort.length === 0) {
574
- return undefined;
575
- }
576
- return transformSort(sort as MexClientSort, mexClientFieldMapping);
577
- }
578
-
579
- /**
580
- * Transforms flattened MX input to nested API format.
581
- */
582
- protected transformToNested(data: CreateMexClientInput): CreateClientInput {
583
- const {
584
- rfc,
585
- curp,
586
- actividadEconomica,
587
- giroMercantil,
588
- actividadVulnerable,
589
- ...baseFields
590
- } = data as Record<string, unknown>;
591
-
592
- // Build MX jurisdiction data
593
- const mexData: Record<string, unknown> = {};
594
- if (rfc !== undefined) mexData.rfc = rfc;
595
- if (curp !== undefined) mexData.curp = curp;
596
- if (actividadEconomica !== undefined)
597
- mexData.actividadEconomica = actividadEconomica;
598
- if (giroMercantil !== undefined) mexData.giroMercantil = giroMercantil;
599
- if (actividadVulnerable !== undefined)
600
- mexData.actividadVulnerable = actividadVulnerable;
601
-
602
- return {
603
- ...baseFields,
604
- primaryJurisdiction: Jurisdiction.Mexico,
605
- jurisdictions: {
606
- MX: mexData,
607
- },
608
- } as CreateClientInput;
609
- }
610
-
611
- /**
612
- * Transforms flattened MX update input to nested API format.
613
- */
614
- protected transformUpdateToNested(
615
- data: UpdateMexClientInput
616
- ): UpdateClientInput {
617
- const {
618
- rfc,
619
- curp,
620
- actividadEconomica,
621
- giroMercantil,
622
- actividadVulnerable,
623
- ...baseFields
624
- } = data;
625
-
626
- // Only include MX data if any MX fields are present
627
- const hasMexFields =
628
- rfc !== undefined ||
629
- curp !== undefined ||
630
- actividadEconomica !== undefined ||
631
- giroMercantil !== undefined ||
632
- actividadVulnerable !== undefined;
633
-
634
- if (!hasMexFields) {
635
- return baseFields as UpdateClientInput;
636
- }
637
-
638
- const mexData: Record<string, unknown> = {};
639
- if (rfc !== undefined) mexData.rfc = rfc;
640
- if (curp !== undefined) mexData.curp = curp;
641
- if (actividadEconomica !== undefined)
642
- mexData.actividadEconomica = actividadEconomica;
643
- if (giroMercantil !== undefined) mexData.giroMercantil = giroMercantil;
644
- if (actividadVulnerable !== undefined)
645
- mexData.actividadVulnerable = actividadVulnerable;
646
-
647
- return {
648
- ...baseFields,
649
- jurisdictions: {
650
- MX: mexData,
651
- },
652
- } as UpdateClientInput;
653
- }
654
-
655
- /**
656
- * Transforms a flattened MX address sync item to nested API format.
657
- */
658
- protected transformAddressSyncItem(
659
- item: SyncItem<UpdateMexAddressInput | CreateMexAddressInput>
660
- ): SyncItem<UpdateAddressInput | CreateAddressInput> {
661
- if ("_delete" in item && item._delete) {
662
- // Delete items pass through unchanged
663
- return item as SyncItem<UpdateAddressInput>;
664
- }
665
- if ("id" in item && item.id) {
666
- // Update items - transform the data fields
667
- const { id, ...data } = item;
668
- return {
669
- id,
670
- ...this.transformAddressUpdateToNested(data as UpdateMexAddressInput),
671
- } as SyncItem<UpdateAddressInput>;
672
- }
673
- // Create items - transform full item
674
- return this.transformAddressToNested(
675
- item as CreateMexAddressInput
676
- ) as SyncItem<CreateAddressInput>;
677
- }
678
-
679
- /**
680
- * Transforms flattened MX address input to nested API format.
681
- */
682
- protected transformAddressToNested(
683
- data: CreateMexAddressInput
684
- ): CreateAddressInput {
685
- const {
686
- exteriorNumber,
687
- interiorNumber,
688
- neighborhood,
689
- municipality,
690
- betweenStreets,
691
- reference,
692
- ...baseFields
693
- } = data;
694
-
695
- const mexData: Record<string, unknown> = {
696
- exteriorNumber,
697
- neighborhood,
698
- };
699
- if (interiorNumber !== undefined) mexData.interiorNumber = interiorNumber;
700
- if (municipality !== undefined) mexData.municipality = municipality;
701
- if (betweenStreets !== undefined) mexData.betweenStreets = betweenStreets;
702
- if (reference !== undefined) mexData.reference = reference;
703
-
704
- return {
705
- ...baseFields,
706
- jurisdictions: { MX: mexData },
707
- } as CreateAddressInput;
708
- }
709
-
710
- /**
711
- * Transforms flattened MX address update input to nested API format.
712
- */
713
- protected transformAddressUpdateToNested(
714
- data: UpdateMexAddressInput
715
- ): UpdateAddressInput {
716
- const {
717
- exteriorNumber,
718
- interiorNumber,
719
- neighborhood,
720
- municipality,
721
- betweenStreets,
722
- reference,
723
- ...baseFields
724
- } = data;
725
-
726
- const hasMexFields =
727
- exteriorNumber !== undefined ||
728
- interiorNumber !== undefined ||
729
- neighborhood !== undefined ||
730
- municipality !== undefined ||
731
- betweenStreets !== undefined ||
732
- reference !== undefined;
733
-
734
- if (!hasMexFields) {
735
- return baseFields as UpdateAddressInput;
736
- }
737
-
738
- const mexData: Record<string, unknown> = {};
739
- if (exteriorNumber !== undefined) mexData.exteriorNumber = exteriorNumber;
740
- if (interiorNumber !== undefined) mexData.interiorNumber = interiorNumber;
741
- if (neighborhood !== undefined) mexData.neighborhood = neighborhood;
742
- if (municipality !== undefined) mexData.municipality = municipality;
743
- if (betweenStreets !== undefined) mexData.betweenStreets = betweenStreets;
744
- if (reference !== undefined) mexData.reference = reference;
745
-
746
- return {
747
- ...baseFields,
748
- jurisdictions: { MX: mexData },
749
- } as UpdateAddressInput;
750
- }
751
-
752
- /**
753
- * Instantiates a MexClient model.
754
- */
755
- protected override instantiate(data: ClientData): MexClient {
756
- return new MexClient(data);
757
- }
758
- }