@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,515 +0,0 @@
1
- /**
2
- * Reports Resource
3
- *
4
- * CRUD operations, report items management, validation, and generation.
5
- *
6
- * This is the base (unscoped) resource. For jurisdiction-scoped SDKs, use:
7
- * - MexReportsResource - Mexico-scoped with flattened MX fields
8
- * - AVIReportsResource - Mexico AVI-scoped with flattened AVI fields
9
- * - JYSReportsResource - Mexico JYS-scoped with flattened JYS fields
10
- * - TSCReportsResource - Mexico TSC-scoped with flattened TSC fields
11
- */
12
-
13
- import { z } from "zod";
14
- import type {
15
- CreateReportInput,
16
- UpdateReportInput,
17
- UpdateReportStatusInput,
18
- CreateReportItemInput,
19
- UpdateReportItemInput,
20
- ReportFilter,
21
- ReportSort,
22
- ReportItemFilter,
23
- ReportItemSort,
24
- ValidationResult,
25
- GenerateResult,
26
- SubmitReportInput,
27
- SubmissionResult,
28
- ListOptions,
29
- PaginatedResponse,
30
- AtomicBatchResult,
31
- PartialBatchResult,
32
- ReportDefaultsInput,
33
- } from "@artu-ai/shared";
34
- import {
35
- createReportInputSchema,
36
- updateReportInputSchema,
37
- updateReportStatusInputSchema,
38
- createReportItemInputSchema,
39
- updateReportItemInputSchema,
40
- reportDefaultsInputSchema,
41
- submitReportInputSchema,
42
- } from "@artu-ai/shared";
43
- import type { BatchOptions } from "./clients";
44
- import { BaseResource } from "./base";
45
- import {
46
- Report,
47
- ReportItem,
48
- type ReportData,
49
- type ReportItemData,
50
- } from "../models";
51
-
52
- // ===========================
53
- // Types
54
- // ===========================
55
-
56
- // Re-export filter types for backwards compatibility
57
- export type { ReportFilter, ReportItemFilter, ReportItemSort };
58
-
59
- /**
60
- * Add items result
61
- */
62
- export interface AddItemsResult {
63
- added: number;
64
- items: ReportItem[];
65
- }
66
-
67
- // ===========================
68
- // ReportsResource
69
- // ===========================
70
-
71
- /**
72
- * Base resource manager for report operations.
73
- *
74
- * Provides:
75
- * - CRUD operations (create, retrieve, update, delete)
76
- * - Report items management (add, update, remove items)
77
- * - Validation and generation
78
- *
79
- * @example
80
- * ```typescript
81
- * // Create a report with full nested format
82
- * const report = await sdk.reports.create({
83
- * jurisdictions: {
84
- * MX: {
85
- * actividadVulnerable: {
86
- * AVI: { mesReportado: "202401" }
87
- * }
88
- * }
89
- * }
90
- * });
91
- *
92
- * // Add items to the report
93
- * await sdk.reports.addItem(report.id, {
94
- * transactionId: "txn_123",
95
- * });
96
- *
97
- * // Validate the report
98
- * const result = await sdk.reports.validate(report.id);
99
- * if (result.valid) {
100
- * // Generate XML
101
- * const xml = await sdk.reports.generate(report.id);
102
- * }
103
- * ```
104
- */
105
- export class ReportsResource<
106
- TSort = ReportSort,
107
- TDefaults = ReportDefaultsInput,
108
- > extends BaseResource<
109
- Report,
110
- CreateReportInput,
111
- UpdateReportInput,
112
- ReportFilter,
113
- TSort
114
- > {
115
- // ─────────────────────────────────────────────────────────────────
116
- // Report CRUD
117
- // ─────────────────────────────────────────────────────────────────
118
-
119
- /**
120
- * Creates a new report.
121
- *
122
- * @param data - Report creation data in nested format
123
- * @returns The created report model
124
- */
125
- async create(data: CreateReportInput): Promise<Report> {
126
- const validated = this.validate(createReportInputSchema, data);
127
-
128
- const response = await this.execute(() =>
129
- this.trpc.reports.create.mutate(validated)
130
- );
131
-
132
- return this.instantiate(response);
133
- }
134
-
135
- /**
136
- * Retrieves a report by ID.
137
- */
138
- async retrieve(id: string): Promise<Report> {
139
- const response = await this.execute(() =>
140
- this.trpc.reports.retrieve.query({ id })
141
- );
142
- return this.instantiate(response);
143
- }
144
-
145
- /**
146
- * Retrieves a report by metadata key/value.
147
- */
148
- async retrieveByMetadata(key: string, value: string): Promise<Report> {
149
- const response = await this.execute(() =>
150
- this.trpc.reports.retrieveByMetadata.query({ key, value })
151
- );
152
- return this.instantiate(response);
153
- }
154
-
155
- /**
156
- * Retrieves a report by externalId.
157
- */
158
- async retrieveByExternalId(externalId: string): Promise<Report> {
159
- const response = await this.execute(() =>
160
- this.trpc.reports.retrieveByExternalId.query({ externalId })
161
- );
162
- return this.instantiate(response);
163
- }
164
-
165
- /**
166
- * Updates a report.
167
- */
168
- async update(id: string, data: UpdateReportInput): Promise<Report> {
169
- const validated = this.validate(updateReportInputSchema, data);
170
-
171
- const response = await this.execute(() =>
172
- this.trpc.reports.update.mutate({ id, data: validated })
173
- );
174
- return this.instantiate(response);
175
- }
176
-
177
- /**
178
- * Updates a report's status.
179
- *
180
- * Restrictions:
181
- * - Can only manually set to: Draft
182
- * - Cannot change from: Accepted (terminal), Submitted (awaiting response)
183
- *
184
- * Use this to reset a report back to Draft status for re-editing.
185
- */
186
- async updateStatus(id: string, data: UpdateReportStatusInput): Promise<Report> {
187
- const validated = this.validate(updateReportStatusInputSchema, data);
188
-
189
- const response = await this.execute(() =>
190
- this.trpc.reports.updateStatus.mutate({ id, data: validated })
191
- );
192
- return this.instantiate(response);
193
- }
194
-
195
- /**
196
- * Deletes a report.
197
- */
198
- async delete(id: string): Promise<void> {
199
- await this.execute(() => this.trpc.reports.delete.mutate({ id }));
200
- }
201
-
202
- /**
203
- * Lists reports with optional filtering and pagination.
204
- */
205
- async list(
206
- options?: ListOptions<ReportFilter, TSort>
207
- ): Promise<PaginatedResponse<Report>> {
208
- const response = await this.execute(() =>
209
- this.trpc.reports.list.query(
210
- options as ListOptions<ReportFilter, ReportSort>
211
- )
212
- );
213
-
214
- return {
215
- data: response.data.map((r) => this.instantiate(r)),
216
- pagination: response.pagination,
217
- };
218
- }
219
-
220
- /**
221
- * Returns an async iterator over all reports matching the filter.
222
- */
223
- iterate(filter?: ReportFilter): AsyncGenerator<Report, void, undefined> {
224
- return this.createIterator({ filter });
225
- }
226
-
227
- // ─────────────────────────────────────────────────────────────────
228
- // Report Items
229
- // ─────────────────────────────────────────────────────────────────
230
-
231
- /**
232
- * Adds an item to a report.
233
- */
234
- async addItem(
235
- reportId: string,
236
- data: CreateReportItemInput
237
- ): Promise<ReportItem> {
238
- const validated = this.validate(createReportItemInputSchema, data);
239
-
240
- const response = await this.execute(() =>
241
- this.trpc.reports.addItem.mutate({ reportId, data: validated })
242
- );
243
-
244
- return this.instantiateItem(response);
245
- }
246
-
247
- /**
248
- * Gets a specific report item.
249
- */
250
- async getItem(reportId: string, itemId: string): Promise<ReportItem> {
251
- const response = await this.execute(() =>
252
- this.trpc.reports.getItem.query({ reportId, itemId })
253
- );
254
- return this.instantiateItem(response);
255
- }
256
-
257
- /**
258
- * Updates a report item.
259
- */
260
- async updateItem(
261
- reportId: string,
262
- itemId: string,
263
- data: UpdateReportItemInput
264
- ): Promise<ReportItem> {
265
- const validated = this.validate(updateReportItemInputSchema, data);
266
-
267
- const response = await this.execute(() =>
268
- this.trpc.reports.updateItem.mutate({ reportId, itemId, data: validated })
269
- );
270
- return this.instantiateItem(response);
271
- }
272
-
273
- /**
274
- * Removes an item from a report.
275
- */
276
- async removeItem(reportId: string, itemId: string): Promise<void> {
277
- await this.execute(() =>
278
- this.trpc.reports.removeItem.mutate({ reportId, itemId })
279
- );
280
- }
281
-
282
- /**
283
- * Lists items in a report with filtering, sorting, and pagination.
284
- */
285
- async listItems(
286
- reportId: string,
287
- options?: ListOptions<ReportItemFilter, ReportItemSort>
288
- ): Promise<PaginatedResponse<ReportItem>> {
289
- const response = await this.execute(() =>
290
- this.trpc.reports.listItems.query({
291
- reportId,
292
- ...options,
293
- })
294
- );
295
-
296
- return {
297
- data: response.data.map((i) => this.instantiateItem(i)),
298
- pagination: response.pagination,
299
- };
300
- }
301
-
302
- /**
303
- * Adds multiple items to a report.
304
- * Validates all items upfront - fails fast if any item is invalid.
305
- */
306
- async addItems(
307
- reportId: string,
308
- items: CreateReportItemInput[]
309
- ): Promise<AddItemsResult> {
310
- const validated = this.validate(
311
- z.array(createReportItemInputSchema),
312
- items
313
- );
314
-
315
- const response = await this.execute(() =>
316
- this.trpc.reports.addItems.mutate({ reportId, items: validated })
317
- );
318
-
319
- return {
320
- added: response.added,
321
- items: response.items.map((i) => this.instantiateItem(i)),
322
- };
323
- }
324
-
325
- /**
326
- * Removes multiple items from a report.
327
- */
328
- async removeItems(
329
- reportId: string,
330
- itemIds: string[]
331
- ): Promise<{ removed: number }> {
332
- return this.execute(() =>
333
- this.trpc.reports.removeItems.mutate({ reportId, itemIds })
334
- );
335
- }
336
-
337
- // ─────────────────────────────────────────────────────────────────
338
- // Validation & Generation
339
- // ─────────────────────────────────────────────────────────────────
340
-
341
- /**
342
- * Validates a report and its items.
343
- *
344
- * Requires jurisdiction-specific defaults.
345
- * For scoped SDKs, use the scoped resource which provides a simpler API.
346
- *
347
- * @param reportId - The report ID to validate
348
- * @param defaults - Jurisdiction-specific defaults for validation
349
- */
350
- async validateReport(
351
- reportId: string,
352
- defaults: TDefaults
353
- ): Promise<ValidationResult> {
354
- const validated = this.validate(reportDefaultsInputSchema, defaults);
355
- return this.execute(() =>
356
- this.trpc.reports.validate.mutate({ reportId, ...validated })
357
- );
358
- }
359
-
360
- /**
361
- * Validates and generates the report output (e.g., XML for Mexico reports).
362
- *
363
- * Performs validation first:
364
- * - If validation fails, returns `{ status: "validation_failed", validation: {...} }`
365
- * - If validation passes, returns `{ status: "success", xml: "...", ... }`
366
- *
367
- * Use `validateReport` for dry-run/preview validation without generating XML.
368
- *
369
- * @param reportId - The report ID to generate
370
- * @param defaults - Jurisdiction-specific defaults for generation
371
- * @returns GenerateResult with status "success" or "validation_failed"
372
- */
373
- async generateReport(
374
- reportId: string,
375
- defaults: TDefaults
376
- ): Promise<GenerateResult> {
377
- const validated = this.validate(reportDefaultsInputSchema, defaults);
378
- return this.execute(() =>
379
- this.trpc.reports.generate.mutate({ reportId, ...validated })
380
- );
381
- }
382
-
383
- // ─────────────────────────────────────────────────────────────────
384
- // Submission
385
- // ─────────────────────────────────────────────────────────────────
386
-
387
- /**
388
- * Submits a validated report.
389
- *
390
- * The report must be in "valid" status. After submission, the report
391
- * is locked and cannot be edited.
392
- *
393
- * @param reportId - The report ID
394
- * @param input - Submission data with jurisdiction-specific structure
395
- */
396
- async submit(input: SubmitReportInput): Promise<SubmissionResult> {
397
- const validated = this.validate(submitReportInputSchema, input);
398
- return this.execute(() => this.trpc.reports.submit.mutate(validated));
399
- }
400
-
401
- // ─────────────────────────────────────────────────────────────────
402
- // Batch Operations
403
- // ─────────────────────────────────────────────────────────────────
404
-
405
- /**
406
- * Creates multiple reports in a single request.
407
- *
408
- * @param reports - Array of report creation data
409
- * @param options - Batch options (atomic: true by default)
410
- * @returns Atomic result with data array, or partial result with succeeded/failed
411
- */
412
- async createMany(
413
- reports: CreateReportInput[],
414
- options?: { atomic?: true }
415
- ): Promise<AtomicBatchResult<Report>>;
416
- async createMany(
417
- reports: CreateReportInput[],
418
- options: { atomic: false }
419
- ): Promise<PartialBatchResult<Report>>;
420
- async createMany(
421
- reports: CreateReportInput[],
422
- options: BatchOptions = {}
423
- ): Promise<AtomicBatchResult<Report> | PartialBatchResult<Report>> {
424
- const atomic = options.atomic ?? true;
425
- const validated = this.validate(z.array(createReportInputSchema), reports);
426
-
427
- const response = await this.execute(() =>
428
- this.trpc.reports.createMany.mutate({ items: validated, atomic })
429
- );
430
-
431
- if (response.atomic) {
432
- return {
433
- atomic: true,
434
- data: response.data.map((r) => this.instantiate(r)),
435
- };
436
- } else {
437
- return {
438
- atomic: false,
439
- succeeded: response.succeeded.map((item) => ({
440
- index: item.index,
441
- data: this.instantiate(item.data),
442
- })),
443
- failed: response.failed,
444
- };
445
- }
446
- }
447
-
448
- /**
449
- * Updates multiple reports in a single request.
450
- *
451
- * @param updates - Array of { id, data } updates
452
- * @param options - Batch options (atomic: true by default)
453
- * @returns Atomic result with data array, or partial result with succeeded/failed
454
- */
455
- async updateMany(
456
- updates: { id: string; data: UpdateReportInput }[],
457
- options?: { atomic?: true }
458
- ): Promise<AtomicBatchResult<Report>>;
459
- async updateMany(
460
- updates: { id: string; data: UpdateReportInput }[],
461
- options: { atomic: false }
462
- ): Promise<PartialBatchResult<Report>>;
463
- async updateMany(
464
- updates: { id: string; data: UpdateReportInput }[],
465
- options: BatchOptions = {}
466
- ): Promise<AtomicBatchResult<Report> | PartialBatchResult<Report>> {
467
- const atomic = options.atomic ?? true;
468
- const updateItemSchema = z.object({
469
- id: z.uuid(),
470
- data: updateReportInputSchema,
471
- });
472
-
473
- const validated = this.validate(z.array(updateItemSchema), updates);
474
-
475
- const response = await this.execute(() =>
476
- this.trpc.reports.updateMany.mutate({ items: validated, atomic })
477
- );
478
-
479
- if (response.atomic) {
480
- return {
481
- atomic: true,
482
- data: response.data.map((r) => this.instantiate(r)),
483
- };
484
- } else {
485
- return {
486
- atomic: false,
487
- succeeded: response.succeeded.map((item) => ({
488
- index: item.index,
489
- data: this.instantiate(item.data),
490
- })),
491
- failed: response.failed,
492
- };
493
- }
494
- }
495
-
496
- // ─────────────────────────────────────────────────────────────────
497
- // Instantiation (protected for subclasses to override)
498
- // ─────────────────────────────────────────────────────────────────
499
-
500
- /**
501
- * Instantiates a Report model from API response data.
502
- * Subclasses override this to return their specific model type.
503
- */
504
- protected instantiate(data: ReportData): Report {
505
- return new Report(data);
506
- }
507
-
508
- /**
509
- * Instantiates a ReportItem model from API response data.
510
- * Subclasses override this to return their specific model type.
511
- */
512
- protected instantiateItem(data: ReportItemData): ReportItem {
513
- return new ReportItem(data);
514
- }
515
- }