@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.
Files changed (110) hide show
  1. package/package.json +4 -5
  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,325 +0,0 @@
1
- /**
2
- * Mexico namespace
3
- *
4
- * All Mexico-specific functionality organized in one place:
5
- * - Enums (ActividadEconomica, GiroMercantil, DocumentType)
6
- * - Validators (RFC, CURP, CLABE)
7
- * - Models (MexClient, MexTransaction, etc.)
8
- * - Resources (MexClientsResource, etc.)
9
- * - TypeGuards (isMexClient, etc.)
10
- * - Types (MexJurisdictionData, etc.)
11
- * - ActividadVulnerable (AVI, JYS, TSC subnamespaces)
12
- *
13
- * @example
14
- * ```ts
15
- * import { Mexico } from "@artu/compliance-sdk";
16
- *
17
- * // General enums
18
- * Mexico.Enums.ActividadEconomica.Comercio
19
- * Mexico.Enums.DocumentType.INE
20
- *
21
- * // Validators
22
- * Mexico.Validators.Rfc.validate("GOAP820528H00")
23
- *
24
- * // Models
25
- * Mexico.Models.Client // MexClient
26
- *
27
- * // Actividad Vulnerable (nested)
28
- * Mexico.ActividadVulnerable.Enums.CodigoActividad.AVI
29
- * Mexico.ActividadVulnerable.AVI.Enums.TipoOperacion.Buy
30
- * Mexico.ActividadVulnerable.AVI.Models.Client // MexAVIClient
31
- * ```
32
- */
33
-
34
- import {
35
- ActividadEconomica,
36
- ActividadesEconomicas,
37
- GiroMercantil,
38
- GirosMercantiles,
39
- MexDocumentType,
40
- MexDocumentTypes,
41
- AddressProofServiceType,
42
- AddressProofServiceTypes,
43
- MexEntityType,
44
- MexEntityTypes,
45
- PoderType,
46
- PoderTypes,
47
- Rfc,
48
- Curp,
49
- Clabe,
50
- } from "@artu-ai/shared";
51
-
52
- import type {
53
- MexJurisdictionData,
54
- MexPersonJurisdictionData,
55
- MexCompanyJurisdictionData,
56
- MexTrustJurisdictionData,
57
- ActividadVulnerableClientData,
58
- MexBankAccountData as MexBankAccountDataType,
59
- MexDocument as MexDocumentSchema,
60
- CreateMexDocumentInput,
61
- UpdateMexDocumentInput,
62
- // Document field types
63
- IneFrontFields,
64
- IneBackFields,
65
- CurpDocumentFields,
66
- RfcConstanciaFields,
67
- AddressProofFields,
68
- ActaConstitutivaFields,
69
- PoderNotarialFields,
70
- // Create input types per document type
71
- CreateMexIneFrontInput,
72
- CreateMexIneBackInput,
73
- CreateMexPassportInput,
74
- CreateMexCurpInput,
75
- CreateMexRfcConstanciaInput,
76
- CreateMexAddressProofInput,
77
- CreateMexActaConstitutivaInput,
78
- CreateMexPoderNotarialInput,
79
- // Update input types per document type
80
- UpdateMexIneFrontInput,
81
- UpdateMexIneBackInput,
82
- UpdateMexPassportInput,
83
- UpdateMexCurpInput,
84
- UpdateMexRfcConstanciaInput,
85
- UpdateMexAddressProofInput,
86
- UpdateMexActaConstitutivaInput,
87
- UpdateMexPoderNotarialInput,
88
- } from "@artu-ai/shared";
89
-
90
- import {
91
- MexClient,
92
- MexTransaction,
93
- MexBankAccount,
94
- MexAddress,
95
- MexReport,
96
- MexReportItem,
97
- // Document models
98
- MexDocument,
99
- MexIneFrontDocument,
100
- MexIneBackDocument,
101
- MexPassportDocument,
102
- MexCurpDocument,
103
- MexRfcConstanciaDocument,
104
- MexAddressProofDocument,
105
- MexActaConstitutivaDocument,
106
- MexPoderNotarialDocument,
107
- // Type guards
108
- isMexClient,
109
- isMexTransaction,
110
- isMexBankAccount,
111
- isMexAddress,
112
- isMexReport,
113
- isMexReportItem,
114
- isMexDocument,
115
- isMexIneFront,
116
- isMexIneBack,
117
- isMexPassport,
118
- isMexCurp,
119
- isMexRfcConstancia,
120
- isMexAddressProof,
121
- isMexActaConstitutiva,
122
- isMexPoderNotarial,
123
- } from "../../models";
124
-
125
- import {
126
- MexClientsResource,
127
- MexTransactionsResource,
128
- MexBankAccountsResource,
129
- MexReportsResource,
130
- } from "../../resources";
131
-
132
- // Actividad Vulnerable namespace
133
- import { ActividadVulnerable, AVI, JYS, TSC } from "./actividad-vulnerable";
134
-
135
- // Re-export for convenience
136
- export { ActividadVulnerable, AVI, JYS, TSC } from "./actividad-vulnerable";
137
-
138
- // ===========================
139
- // Enums
140
- // ===========================
141
-
142
- export const Enums = {
143
- // Enum values
144
- ActividadEconomica,
145
- GiroMercantil,
146
- DocumentType: MexDocumentType,
147
- AddressProofServiceType,
148
- EntityType: MexEntityType,
149
- PoderType,
150
- // Enum utilities (with .enum, .map, .codes, .options, .schema())
151
- ActividadesEconomicas,
152
- GirosMercantiles,
153
- DocumentTypes: MexDocumentTypes,
154
- AddressProofServiceTypes,
155
- EntityTypes: MexEntityTypes,
156
- PoderTypes,
157
- } as const;
158
-
159
- // ===========================
160
- // Validators
161
- // ===========================
162
-
163
- export const Validators = {
164
- Rfc,
165
- Curp,
166
- Clabe,
167
- } as const;
168
-
169
- // ===========================
170
- // Models
171
- // ===========================
172
-
173
- export const Models = {
174
- Client: MexClient,
175
- Transaction: MexTransaction,
176
- BankAccount: MexBankAccount,
177
- Address: MexAddress,
178
- Report: MexReport,
179
- ReportItem: MexReportItem,
180
- // Document models
181
- Document: MexDocument,
182
- IneFrontDocument: MexIneFrontDocument,
183
- IneBackDocument: MexIneBackDocument,
184
- PassportDocument: MexPassportDocument,
185
- CurpDocument: MexCurpDocument,
186
- RfcConstanciaDocument: MexRfcConstanciaDocument,
187
- AddressProofDocument: MexAddressProofDocument,
188
- ActaConstitutivaDocument: MexActaConstitutivaDocument,
189
- PoderNotarialDocument: MexPoderNotarialDocument,
190
- } as const;
191
-
192
- // ===========================
193
- // Resources
194
- // ===========================
195
-
196
- export const Resources = {
197
- Clients: MexClientsResource,
198
- Transactions: MexTransactionsResource,
199
- BankAccounts: MexBankAccountsResource,
200
- Reports: MexReportsResource,
201
- } as const;
202
-
203
- // ===========================
204
- // TypeGuards
205
- // ===========================
206
-
207
- export const TypeGuards = {
208
- isClient: isMexClient,
209
- isTransaction: isMexTransaction,
210
- isBankAccount: isMexBankAccount,
211
- isAddress: isMexAddress,
212
- isReport: isMexReport,
213
- isReportItem: isMexReportItem,
214
- // Document guards
215
- isDocument: isMexDocument,
216
- isIneFront: isMexIneFront,
217
- isIneBack: isMexIneBack,
218
- isPassport: isMexPassport,
219
- isCurp: isMexCurp,
220
- isRfcConstancia: isMexRfcConstancia,
221
- isAddressProof: isMexAddressProof,
222
- isActaConstitutiva: isMexActaConstitutiva,
223
- isPoderNotarial: isMexPoderNotarial,
224
- } as const;
225
-
226
- // ===========================
227
- // Types
228
- // ===========================
229
-
230
- export interface Types {
231
- JurisdictionData: MexJurisdictionData;
232
- PersonJurisdictionData: MexPersonJurisdictionData;
233
- CompanyJurisdictionData: MexCompanyJurisdictionData;
234
- TrustJurisdictionData: MexTrustJurisdictionData;
235
- ActividadVulnerableClientData: ActividadVulnerableClientData;
236
- BankAccountData: MexBankAccountDataType;
237
- Document: MexDocumentSchema;
238
- CreateDocumentInput: CreateMexDocumentInput;
239
- UpdateDocumentInput: UpdateMexDocumentInput;
240
- // Document field types
241
- IneFrontFields: IneFrontFields;
242
- IneBackFields: IneBackFields;
243
- CurpDocumentFields: CurpDocumentFields;
244
- RfcConstanciaFields: RfcConstanciaFields;
245
- AddressProofFields: AddressProofFields;
246
- ActaConstitutivaFields: ActaConstitutivaFields;
247
- PoderNotarialFields: PoderNotarialFields;
248
- }
249
-
250
- // Re-export types for direct usage
251
- export type {
252
- MexJurisdictionData,
253
- MexPersonJurisdictionData,
254
- MexCompanyJurisdictionData,
255
- MexTrustJurisdictionData,
256
- ActividadVulnerableClientData,
257
- MexBankAccountDataType as MexBankAccountData,
258
- MexDocumentSchema as MexDocument,
259
- CreateMexDocumentInput,
260
- UpdateMexDocumentInput,
261
- // Document field types
262
- IneFrontFields,
263
- IneBackFields,
264
- CurpDocumentFields,
265
- RfcConstanciaFields,
266
- AddressProofFields,
267
- ActaConstitutivaFields,
268
- PoderNotarialFields,
269
- // Create input types per document type
270
- CreateMexIneFrontInput,
271
- CreateMexIneBackInput,
272
- CreateMexPassportInput,
273
- CreateMexCurpInput,
274
- CreateMexRfcConstanciaInput,
275
- CreateMexAddressProofInput,
276
- CreateMexActaConstitutivaInput,
277
- CreateMexPoderNotarialInput,
278
- // Update input types per document type
279
- UpdateMexIneFrontInput,
280
- UpdateMexIneBackInput,
281
- UpdateMexPassportInput,
282
- UpdateMexCurpInput,
283
- UpdateMexRfcConstanciaInput,
284
- UpdateMexAddressProofInput,
285
- UpdateMexActaConstitutivaInput,
286
- UpdateMexPoderNotarialInput,
287
- };
288
-
289
- // ===========================
290
- // SDK Types
291
- // ===========================
292
-
293
- export type {
294
- ComplianceSDKOptionsMexico,
295
- MexicoSDKOptions,
296
- MexicoComplianceSDK,
297
- AVISDKOptions,
298
- AVIComplianceSDK,
299
- JYSSDKOptions,
300
- JYSComplianceSDK,
301
- TSCSDKOptions,
302
- TSCComplianceSDK,
303
- } from "../../sdk/mex";
304
-
305
- // ===========================
306
- // Main Mexico Namespace
307
- // ===========================
308
-
309
- /**
310
- * Mexico namespace - all Mexico-specific SDK functionality
311
- */
312
- export const Mexico = {
313
- Enums,
314
- Validators,
315
- Models,
316
- Resources,
317
- TypeGuards,
318
- ActividadVulnerable,
319
- // Shortcuts to activity namespaces
320
- AVI,
321
- JYS,
322
- TSC,
323
- } as const;
324
-
325
- export default Mexico;
@@ -1,391 +0,0 @@
1
- /**
2
- * Addresses Resource
3
- *
4
- * Manages physical and mailing addresses for clients.
5
- */
6
-
7
- import { z } from "zod";
8
- import type {
9
- CreateAddressInput,
10
- UpdateAddressInput,
11
- AddressFilter,
12
- AddressSort,
13
- AddressType,
14
- ListOptions,
15
- PaginatedResponse,
16
- AtomicBatchResult,
17
- PartialBatchResult,
18
- SyncItem,
19
- SyncResult,
20
- } from "@artu-ai/shared";
21
- import {
22
- createAddressInputSchema,
23
- updateAddressInputSchema,
24
- replaceSyncItemSchema,
25
- } from "@artu-ai/shared";
26
- import { BaseResource } from "./base";
27
- import { Address, type AddressData } from "../models/Address";
28
- import type { BatchOptions } from "./clients";
29
-
30
- // ===========================
31
- // AddressesResource
32
- // ===========================
33
-
34
- /**
35
- * Resource for managing client addresses.
36
- *
37
- * @example
38
- * ```typescript
39
- * // Create an address for a client
40
- * const address = await sdk.addresses.create({
41
- * clientId: "client_123",
42
- * type: "home",
43
- * street1: "Avenida Reforma 123",
44
- * city: "Ciudad de México",
45
- * state: "CDMX",
46
- * postalCode: "06600",
47
- * country: "MX",
48
- * isPrimary: true,
49
- * });
50
- *
51
- * // List all addresses for a client
52
- * const addresses = await sdk.addresses.listByClient("client_123");
53
- * ```
54
- */
55
- export class AddressesResource<
56
- TSort = AddressSort,
57
- > extends BaseResource<
58
- Address,
59
- CreateAddressInput,
60
- UpdateAddressInput,
61
- AddressFilter,
62
- TSort
63
- > {
64
- // ─────────────────────────────────────────────────────────────────
65
- // CRUD Operations
66
- // ─────────────────────────────────────────────────────────────────
67
-
68
- /**
69
- * Creates an address for a client
70
- *
71
- * @param data - Address data including clientId
72
- * @returns The created Address
73
- */
74
- async create(data: CreateAddressInput): Promise<Address> {
75
- const validated = this.validate(createAddressInputSchema, data);
76
-
77
- const response = await this.execute(() =>
78
- this.trpc.addresses.create.mutate(validated)
79
- );
80
- return this.instantiate(response);
81
- }
82
-
83
- /**
84
- * Retrieves an address by ID
85
- *
86
- * @param id - The address ID
87
- * @returns The Address
88
- */
89
- async retrieve(id: string): Promise<Address> {
90
- const response = await this.execute(() =>
91
- this.trpc.addresses.retrieve.query({ id })
92
- );
93
- return this.instantiate(response);
94
- }
95
-
96
- /**
97
- * Retrieves an address by metadata key/value.
98
- */
99
- async retrieveByMetadata(key: string, value: string): Promise<Address> {
100
- const response = await this.execute(() =>
101
- this.trpc.addresses.retrieveByMetadata.query({ key, value })
102
- );
103
- return this.instantiate(response);
104
- }
105
-
106
- /**
107
- * Retrieves an address by externalId
108
- */
109
- async retrieveByExternalId(externalId: string): Promise<Address> {
110
- const response = await this.execute(() =>
111
- this.trpc.addresses.retrieveByExternalId.query({ externalId })
112
- );
113
- return this.instantiate(response);
114
- }
115
-
116
- /**
117
- * Updates an address
118
- *
119
- * @param id - The address ID
120
- * @param data - Fields to update
121
- * @returns The updated Address
122
- */
123
- async update(id: string, data: UpdateAddressInput): Promise<Address> {
124
- const validated = this.validate(updateAddressInputSchema, data);
125
-
126
- const response = await this.execute(() =>
127
- this.trpc.addresses.update.mutate({ id, data: validated })
128
- );
129
- return this.instantiate(response);
130
- }
131
-
132
- /**
133
- * Deletes an address
134
- *
135
- * @param id - The address ID
136
- */
137
- async delete(id: string): Promise<void> {
138
- await this.execute(() => this.trpc.addresses.delete.mutate({ id }));
139
- }
140
-
141
- // ─────────────────────────────────────────────────────────────────
142
- // List Operations
143
- // ─────────────────────────────────────────────────────────────────
144
-
145
- /**
146
- * Lists addresses with optional filtering
147
- *
148
- * @param options - Filtering and pagination options
149
- * @returns Paginated list of Addresses
150
- */
151
- async list(
152
- options?: ListOptions<AddressFilter, TSort>
153
- ): Promise<PaginatedResponse<Address>> {
154
- const response = await this.execute(() =>
155
- this.trpc.addresses.list.query(options as ListOptions<AddressFilter, AddressSort>)
156
- );
157
- return {
158
- data: response.data.map((a) => this.instantiate(a)),
159
- pagination: response.pagination,
160
- };
161
- }
162
-
163
- /**
164
- * Lists all addresses for a specific client
165
- *
166
- * @param clientId - The client ID
167
- * @param options - Optional pagination options
168
- * @returns Paginated list of Addresses
169
- */
170
- async listByClient(
171
- clientId: string,
172
- options?: { cursor?: string; limit?: number }
173
- ): Promise<PaginatedResponse<Address>> {
174
- const response = await this.execute(() =>
175
- this.trpc.addresses.listByClient.query({ clientId, ...options })
176
- );
177
- return {
178
- data: response.data.map((a) => this.instantiate(a)),
179
- pagination: response.pagination,
180
- };
181
- }
182
-
183
- /**
184
- * Returns an async iterator over all addresses matching the filter.
185
- */
186
- iterate(filter?: AddressFilter): AsyncGenerator<Address, void, undefined> {
187
- return this.createIterator({ filter });
188
- }
189
-
190
- // ─────────────────────────────────────────────────────────────────
191
- // Batch Operations
192
- // ─────────────────────────────────────────────────────────────────
193
-
194
- /**
195
- * Creates multiple addresses in a single request.
196
- *
197
- * @param addresses - Array of address creation data (each includes clientId)
198
- * @param options - Batch options (atomic: true by default)
199
- * @returns Atomic result with data array, or partial result with succeeded/failed
200
- */
201
- async createMany(
202
- addresses: CreateAddressInput[],
203
- options?: { atomic?: true }
204
- ): Promise<AtomicBatchResult<Address>>;
205
- async createMany(
206
- addresses: CreateAddressInput[],
207
- options: { atomic: false }
208
- ): Promise<PartialBatchResult<Address>>;
209
- async createMany(
210
- addresses: CreateAddressInput[],
211
- options: BatchOptions = {}
212
- ): Promise<AtomicBatchResult<Address> | PartialBatchResult<Address>> {
213
- const atomic = options.atomic ?? true;
214
- const validated = this.validate(
215
- z.array(createAddressInputSchema),
216
- addresses
217
- );
218
-
219
- const response = await this.execute(() =>
220
- this.trpc.addresses.createMany.mutate({ items: validated, atomic })
221
- );
222
-
223
- if (response.atomic) {
224
- return {
225
- atomic: true,
226
- data: response.data.map((a) => this.instantiate(a)),
227
- };
228
- } else {
229
- return {
230
- atomic: false,
231
- succeeded: response.succeeded.map((item) => ({
232
- index: item.index,
233
- data: this.instantiate(item.data),
234
- })),
235
- failed: response.failed,
236
- };
237
- }
238
- }
239
-
240
- /**
241
- * Updates multiple addresses in a single request.
242
- *
243
- * @param updates - Array of { id, data } updates
244
- * @param options - Batch options (atomic: true by default)
245
- * @returns Atomic result with data array, or partial result with succeeded/failed
246
- */
247
- async updateMany(
248
- updates: { id: string; data: UpdateAddressInput }[],
249
- options?: { atomic?: true }
250
- ): Promise<AtomicBatchResult<Address>>;
251
- async updateMany(
252
- updates: { id: string; data: UpdateAddressInput }[],
253
- options: { atomic: false }
254
- ): Promise<PartialBatchResult<Address>>;
255
- async updateMany(
256
- updates: { id: string; data: UpdateAddressInput }[],
257
- options: BatchOptions = {}
258
- ): Promise<AtomicBatchResult<Address> | PartialBatchResult<Address>> {
259
- const atomic = options.atomic ?? true;
260
- const updateItemSchema = z.object({
261
- id: z.uuid(),
262
- data: updateAddressInputSchema,
263
- });
264
-
265
- const validated = this.validate(z.array(updateItemSchema), updates);
266
-
267
- const response = await this.execute(() =>
268
- this.trpc.addresses.updateMany.mutate({ items: validated, atomic })
269
- );
270
-
271
- if (response.atomic) {
272
- return {
273
- atomic: true,
274
- data: response.data.map((a) => this.instantiate(a)),
275
- };
276
- } else {
277
- return {
278
- atomic: false,
279
- succeeded: response.succeeded.map((item) => ({
280
- index: item.index,
281
- data: this.instantiate(item.data),
282
- })),
283
- failed: response.failed,
284
- };
285
- }
286
- }
287
-
288
- // ─────────────────────────────────────────────────────────────────
289
- // Sync Operations
290
- // ─────────────────────────────────────────────────────────────────
291
-
292
- /**
293
- * Syncs addresses for a client - handles create, update, and delete in bulk.
294
- *
295
- * This is the most efficient way to reconcile a set of addresses for a client.
296
- *
297
- * @param clientId - The client ID
298
- * @param items - Array of sync items:
299
- * - Without `id`: create new address
300
- * - With `id` and `_delete: true`: delete existing address
301
- * - With `id` (no `_delete`): update existing address
302
- * @param options - Sync options
303
- * @param options.replaceMode - When true, items not in the array are deleted (default: false)
304
- * @returns Sync result with created, updated, and deleted arrays
305
- *
306
- * @example
307
- * ```typescript
308
- * // Patch mode (default) - only mentioned items are affected
309
- * const result = await sdk.addresses.sync("client_123", [
310
- * // Create new address (no id)
311
- * { street: "123 New St", city: "Mexico City", country: "MX" },
312
- * // Update existing address (has id)
313
- * { id: "addr_456", street: "456 Updated Ave" },
314
- * // Delete address (has id and _delete: true)
315
- * { id: "addr_789", _delete: true },
316
- * ]);
317
- *
318
- * // Replace mode - provided array becomes the complete set
319
- * const result = await sdk.addresses.sync("client_123", addresses, { replaceMode: true });
320
- *
321
- * console.log(result.created); // newly created addresses
322
- * console.log(result.updated); // updated addresses
323
- * console.log(result.deleted); // array of deleted address IDs
324
- * ```
325
- */
326
- async sync(
327
- clientId: string,
328
- items: SyncItem<CreateAddressInput>[],
329
- options?: { replaceMode: true }
330
- ): Promise<SyncResult<Address>>;
331
- async sync(
332
- clientId: string,
333
- items: SyncItem<UpdateAddressInput>[],
334
- options?: { replaceMode?: boolean }
335
- ): Promise<SyncResult<Address>>;
336
- async sync(
337
- clientId: string,
338
- items: SyncItem<UpdateAddressInput | CreateAddressInput>[],
339
- options?: { replaceMode?: boolean }
340
- ): Promise<SyncResult<Address>> {
341
- const validated = this.validate(
342
- z.array(
343
- replaceSyncItemSchema(createAddressInputSchema, updateAddressInputSchema)
344
- ),
345
- items
346
- );
347
-
348
- const response = await this.execute(() =>
349
- this.trpc.addresses.sync.mutate({
350
- clientId,
351
- items: validated,
352
- replaceMode: options?.replaceMode,
353
- })
354
- );
355
-
356
- return {
357
- created: response.created.map((a) => this.instantiate(a)),
358
- updated: response.updated.map((a) => this.instantiate(a)),
359
- deleted: response.deleted,
360
- };
361
- }
362
-
363
- // ─────────────────────────────────────────────────────────────────
364
- // Helper Methods
365
- // ─────────────────────────────────────────────────────────────────
366
-
367
- /**
368
- * Gets the primary address for a client
369
- *
370
- * @param clientId - The client ID
371
- * @param type - Optional address type filter
372
- * @returns The primary Address or null
373
- */
374
- async getPrimary(
375
- clientId: string,
376
- type?: AddressType
377
- ): Promise<Address | null> {
378
- const response = await this.execute(() =>
379
- this.trpc.addresses.getPrimary.query({ clientId, type })
380
- );
381
- return response ? this.instantiate(response) : null;
382
- }
383
-
384
- // ─────────────────────────────────────────────────────────────────
385
- // Instantiation
386
- // ─────────────────────────────────────────────────────────────────
387
-
388
- protected instantiate(data: AddressData): Address {
389
- return new Address(data);
390
- }
391
- }