@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,327 +0,0 @@
1
- /**
2
- * Base Resource Class
3
- *
4
- * Abstract base class for all resource managers.
5
- * Provides common patterns: validation, error mapping, pagination.
6
- */
7
-
8
- import type { ZodType } from "zod";
9
- import { TRPCClientError } from "@trpc/client";
10
- import type {
11
- PaginatedResponse,
12
- ListOptions,
13
- IterateOptions,
14
- } from "@artu-ai/shared";
15
- import { Jurisdiction, type CodigoActividad } from "@artu-ai/shared";
16
- import type { TRPCClient } from "../utils/trpc-client";
17
- import { mapTRPCError, ValidationError } from "../errors";
18
- import { createPaginatedIterator } from "../utils/pagination";
19
-
20
- import { type SDKScope, type Environment, isMexicoScope } from "../sdk/types";
21
-
22
- /**
23
- * Type guard for tRPC client errors
24
- */
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- function isTRPCError(error: unknown): error is TRPCClientError<any> {
27
- return error instanceof TRPCClientError;
28
- }
29
-
30
- /**
31
- * Configuration for creating a resource manager
32
- */
33
- export interface ResourceConfig {
34
- /**
35
- * tRPC client instance for API communication
36
- */
37
- trpc: TRPCClient;
38
-
39
- /**
40
- * Optional SDK scope for jurisdiction/activity scoping
41
- */
42
- scope?: SDKScope;
43
-
44
- /**
45
- * SDK environment (test or live)
46
- */
47
- environment?: Environment;
48
- }
49
- // ===========================
50
- // Base Resource Class
51
- // ===========================
52
-
53
- /**
54
- * Abstract base class for all resource managers.
55
- *
56
- * Provides:
57
- * - Input validation with Zod schemas
58
- * - Automatic error mapping from tRPC to SDK errors
59
- * - Pagination iterator factory
60
- *
61
- * @typeParam TModel - The model type returned by this resource
62
- * @typeParam TCreateInput - Input type for create operations
63
- * @typeParam TUpdateInput - Input type for update operations
64
- * @typeParam TFilter - Filter type for list operations
65
- *
66
- * @example
67
- * ```typescript
68
- * class ClientsResource extends BaseResource<
69
- * Client,
70
- * CreateClientInput,
71
- * UpdateClientInput,
72
- * ClientFilter
73
- * > {
74
- * async create(data: CreateClientInput): Promise<Client> {
75
- * const validated = this.validate(createClientInputSchema, data);
76
- * return this.execute(() =>
77
- * this.trpc.clients.create.mutate(validated)
78
- * );
79
- * }
80
- * }
81
- * ```
82
- */
83
- export abstract class BaseResource<
84
- TModel,
85
- TCreateInput,
86
- TUpdateInput,
87
- TFilter = Record<string, unknown>,
88
- TSort = unknown,
89
- TCreateResult = TModel,
90
- > {
91
- /**
92
- * tRPC client for API communication
93
- */
94
- protected readonly trpc: TRPCClient;
95
-
96
- /**
97
- * SDK scope (jurisdiction and actividadVulnerable)
98
- */
99
- protected readonly scope: SDKScope;
100
-
101
- constructor(config: ResourceConfig) {
102
- this.trpc = config.trpc;
103
- this.scope = config.scope ?? {};
104
- }
105
-
106
- /**
107
- * Whether this resource is scoped to a jurisdiction
108
- */
109
- protected get isScoped(): boolean {
110
- return this.scope.jurisdiction !== undefined;
111
- }
112
-
113
- /**
114
- * Whether this resource is scoped to Mexico
115
- */
116
- protected get isMexicoScoped(): boolean {
117
- return this.scope.jurisdiction === Jurisdiction.Mexico;
118
- }
119
-
120
- /**
121
- * Whether this resource is scoped to an Actividad Vulnerable activity
122
- */
123
- protected get isActivityScoped(): boolean {
124
- return (
125
- isMexicoScope(this.scope) && this.scope.actividadVulnerable !== undefined
126
- );
127
- }
128
-
129
- /**
130
- * Gets the actividadVulnerable code if scoped, undefined otherwise
131
- */
132
- protected get scopedActivity(): CodigoActividad | undefined {
133
- return isMexicoScope(this.scope)
134
- ? this.scope.actividadVulnerable
135
- : undefined;
136
- }
137
-
138
- // ===========================
139
- // Abstract Methods
140
- // ===========================
141
-
142
- /**
143
- * Creates a new resource
144
- * @param data - Creation data
145
- * @returns The created model (or custom result type)
146
- */
147
- abstract create(data: TCreateInput): Promise<TCreateResult>;
148
-
149
- /**
150
- * Retrieves a resource by ID
151
- * @param id - Resource ID
152
- * @returns The retrieved model
153
- */
154
- abstract retrieve(id: string): Promise<TModel>;
155
-
156
- /**
157
- * Updates an existing resource
158
- * @param id - Resource ID
159
- * @param data - Update data
160
- * @returns The updated model
161
- */
162
- abstract update(id: string, data: TUpdateInput): Promise<TModel>;
163
-
164
- /**
165
- * Deletes a resource by ID
166
- * @param id - Resource ID
167
- */
168
- abstract delete(id: string): Promise<void>;
169
-
170
- /**
171
- * Lists resources with optional filtering and pagination
172
- * @param options - List options
173
- * @returns Paginated response
174
- */
175
- abstract list(
176
- options?: ListOptions<TFilter, TSort>
177
- ): Promise<PaginatedResponse<TModel>>;
178
-
179
- // ===========================
180
- // Protected Helpers
181
- // ===========================
182
-
183
- /**
184
- * Validates input against a Zod schema.
185
- * Throws ValidationError if validation fails.
186
- *
187
- * @param schema - Zod schema to validate against
188
- * @param data - Data to validate
189
- * @returns Validated and typed data
190
- * @throws ValidationError if validation fails
191
- *
192
- * @example
193
- * ```typescript
194
- * const validated = this.validate(createClientSchema, data);
195
- * // validated is now typed as CreateClientInput
196
- * ```
197
- */
198
- protected validate<T>(schema: ZodType<T>, data: unknown): T {
199
- const result = schema.safeParse(data);
200
- if (!result.success) {
201
- throw ValidationError.fromZodError(result.error);
202
- }
203
- return result.data;
204
- }
205
-
206
- /**
207
- * Wraps a tRPC operation with error mapping.
208
- * Converts tRPC errors to SDK-specific errors.
209
- *
210
- * @param operation - Async operation to execute
211
- * @returns Result of the operation
212
- * @throws SDK-specific error if operation fails
213
- *
214
- * @example
215
- * ```typescript
216
- * const result = await this.execute(() =>
217
- * this.trpc.clients.create.mutate(data)
218
- * );
219
- * ```
220
- */
221
- protected async execute<T>(operation: () => Promise<T>): Promise<T> {
222
- try {
223
- return await operation();
224
- } catch (error) {
225
- if (isTRPCError(error)) {
226
- throw mapTRPCError(error);
227
- }
228
- throw error;
229
- }
230
- }
231
-
232
- /**
233
- * Creates an async iterator for paginated results.
234
- * Automatically fetches subsequent pages as you iterate.
235
- *
236
- * @typeParam T - The model type to return (defaults to TModel, can be overridden by subclasses)
237
- * @param options - Iterator options
238
- * @returns Async generator yielding individual items
239
- *
240
- * @example
241
- * ```typescript
242
- * for await (const client of this.iterate({ filter: { type: "individual" } })) {
243
- * console.log(client.name);
244
- * }
245
- * ```
246
- */
247
- protected createIterator<T = TModel>(
248
- options?: IterateOptions<TFilter, TSort>
249
- ): AsyncGenerator<T, void, undefined> {
250
- return createPaginatedIterator<T>(
251
- (pagination) =>
252
- this.list({
253
- filter: options?.filter,
254
- sort: options?.sort,
255
- ...pagination,
256
- }) as unknown as Promise<PaginatedResponse<T>>,
257
- { limit: options?.pageSize }
258
- );
259
- }
260
- }
261
-
262
- // ===========================
263
- // Read-Only Resource Base
264
- // ===========================
265
-
266
- /**
267
- * Base class for read-only resources (no create/update/delete).
268
- * Useful for resources that are managed elsewhere.
269
- *
270
- * @typeParam TModel - The model type returned by this resource
271
- * @typeParam TFilter - Filter type for list operations
272
- * @typeParam TSort - Sort type for list operations
273
- */
274
- export abstract class ReadOnlyResource<
275
- TModel,
276
- TFilter = Record<string, unknown>,
277
- TSort = unknown,
278
- > {
279
- protected readonly trpc: TRPCClient;
280
-
281
- constructor(config: ResourceConfig) {
282
- this.trpc = config.trpc;
283
- }
284
-
285
- /**
286
- * Retrieves a resource by ID
287
- */
288
- abstract retrieve(id: string): Promise<TModel>;
289
-
290
- /**
291
- * Lists resources with optional filtering and pagination
292
- */
293
- abstract list(
294
- options?: ListOptions<TFilter, TSort>
295
- ): Promise<PaginatedResponse<TModel>>;
296
-
297
- /**
298
- * Wraps a tRPC operation with error mapping
299
- */
300
- protected async execute<T>(operation: () => Promise<T>): Promise<T> {
301
- try {
302
- return await operation();
303
- } catch (error) {
304
- if (isTRPCError(error)) {
305
- throw mapTRPCError(error);
306
- }
307
- throw error;
308
- }
309
- }
310
-
311
- /**
312
- * Creates an async iterator for paginated results
313
- */
314
- protected createIterator<T = TModel>(
315
- options?: IterateOptions<TFilter, TSort>
316
- ): AsyncGenerator<T, void, undefined> {
317
- return createPaginatedIterator<T>(
318
- (pagination) =>
319
- this.list({
320
- filter: options?.filter,
321
- sort: options?.sort,
322
- ...pagination,
323
- }) as unknown as Promise<PaginatedResponse<T>>,
324
- { limit: options?.pageSize }
325
- );
326
- }
327
- }