@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,388 +0,0 @@
1
- /**
2
- * Document Upload Utilities
3
- *
4
- * Provides browser and Node.js compatible file upload with progress tracking.
5
- * Handles the complete upload flow: presigned URL → S3 upload → confirmation.
6
- */
7
-
8
- import type { PresignedUploadUrl } from "@artu-ai/shared";
9
- import {
10
- UploadError,
11
- UploadAbortedError,
12
- UploadTimeoutError,
13
- FileTooLargeError,
14
- } from "../errors/upload";
15
-
16
- // ─────────────────────────────────────────────────────────────────
17
- // Constants
18
- // ─────────────────────────────────────────────────────────────────
19
-
20
- /**
21
- * Maximum file size in bytes (25 MB).
22
- * Must match the server-side limit.
23
- */
24
- export const MAX_FILE_SIZE_BYTES = 25 * 1024 * 1024;
25
-
26
- /**
27
- * Default upload timeout in milliseconds (5 minutes).
28
- */
29
- export const DEFAULT_UPLOAD_TIMEOUT_MS = 5 * 60 * 1000;
30
-
31
- // ─────────────────────────────────────────────────────────────────
32
- // Types
33
- // ─────────────────────────────────────────────────────────────────
34
-
35
- /**
36
- * File-like object that can be uploaded.
37
- * Compatible with browser File, Blob, and Node.js Buffer.
38
- */
39
- export interface UploadableFile {
40
- /** File name */
41
- name: string;
42
- /** MIME type */
43
- type: string;
44
- /** File size in bytes */
45
- size: number;
46
- /** For browser: the file/blob itself. For Node: Buffer or stream. */
47
- data: Blob | Buffer | ArrayBuffer;
48
- }
49
-
50
- /**
51
- * Progress callback function.
52
- * @param progress - Upload progress from 0 to 1
53
- */
54
- export type ProgressCallback = (progress: number) => void;
55
-
56
- /**
57
- * Options for uploading a file to S3.
58
- */
59
- export interface UploadToS3Options {
60
- /** Progress callback (0-1) */
61
- onProgress?: ProgressCallback;
62
- /** AbortSignal for cancellation */
63
- signal?: AbortSignal;
64
- /** Timeout in milliseconds */
65
- timeout?: number;
66
- }
67
-
68
- /**
69
- * Result of a successful S3 upload.
70
- */
71
- export interface UploadToS3Result {
72
- /** Whether the upload was successful */
73
- success: true;
74
- }
75
-
76
- // ─────────────────────────────────────────────────────────────────
77
- // Environment Detection
78
- // ─────────────────────────────────────────────────────────────────
79
-
80
- /**
81
- * Detects if we're running in a browser environment.
82
- */
83
- function isBrowser(): boolean {
84
- return (
85
- typeof window !== "undefined" &&
86
- typeof window.XMLHttpRequest !== "undefined"
87
- );
88
- }
89
-
90
- // ─────────────────────────────────────────────────────────────────
91
- // File Normalization
92
- // ─────────────────────────────────────────────────────────────────
93
-
94
- /**
95
- * Normalizes a file input to an UploadableFile.
96
- * Accepts browser File/Blob or Node.js Buffer with metadata.
97
- */
98
- export function normalizeFile(
99
- file:
100
- | File
101
- | Blob
102
- | UploadableFile
103
- | { buffer: Buffer; name: string; type: string }
104
- ): UploadableFile {
105
- // Browser File
106
- if (typeof File !== "undefined" && file instanceof File) {
107
- return {
108
- name: file.name,
109
- type: file.type,
110
- size: file.size,
111
- data: file,
112
- };
113
- }
114
-
115
- // Browser Blob (no name)
116
- if (
117
- typeof Blob !== "undefined" &&
118
- file instanceof Blob &&
119
- !("name" in file)
120
- ) {
121
- return {
122
- name: "upload",
123
- type: file.type || "application/octet-stream",
124
- size: file.size,
125
- data: file,
126
- };
127
- }
128
-
129
- // Node.js Buffer with metadata
130
- if ("buffer" in file && Buffer.isBuffer(file.buffer)) {
131
- return {
132
- name: file.name,
133
- type: file.type,
134
- size: file.buffer.length,
135
- data: file.buffer,
136
- };
137
- }
138
-
139
- // Already normalized
140
- if ("data" in file && "name" in file && "type" in file && "size" in file) {
141
- return file as UploadableFile;
142
- }
143
-
144
- throw new UploadError(
145
- "Invalid file input. Expected File, Blob, or UploadableFile.",
146
- "request"
147
- );
148
- }
149
-
150
- /**
151
- * Validates file size before upload.
152
- * @throws FileTooLargeError if file exceeds limit
153
- */
154
- export function validateFileSize(size: number): void {
155
- if (size > MAX_FILE_SIZE_BYTES) {
156
- throw new FileTooLargeError(size, MAX_FILE_SIZE_BYTES);
157
- }
158
- }
159
-
160
- // ─────────────────────────────────────────────────────────────────
161
- // S3 Upload Implementation
162
- // ─────────────────────────────────────────────────────────────────
163
-
164
- /**
165
- * Uploads a file to S3 using a presigned POST URL.
166
- *
167
- * Uses XMLHttpRequest in browsers for progress tracking,
168
- * falls back to fetch in Node.js (no progress).
169
- *
170
- * @param file - The file to upload
171
- * @param presigned - Presigned URL info from the API
172
- * @param options - Upload options
173
- * @returns Upload result
174
- * @throws UploadError on failure
175
- */
176
- export async function uploadToS3(
177
- file: UploadableFile,
178
- presigned: PresignedUploadUrl,
179
- options: UploadToS3Options = {}
180
- ): Promise<UploadToS3Result> {
181
- const { onProgress, signal, timeout = DEFAULT_UPLOAD_TIMEOUT_MS } = options;
182
-
183
- // Check if already aborted
184
- if (signal?.aborted) {
185
- throw new UploadAbortedError();
186
- }
187
-
188
- // Use XHR in browser for progress, fetch in Node.js
189
- if (isBrowser() && onProgress) {
190
- return uploadWithXHR(file, presigned, { onProgress, signal, timeout });
191
- } else {
192
- return uploadWithFetch(file, presigned, { signal, timeout });
193
- }
194
- }
195
-
196
- /**
197
- * Uploads using XMLHttpRequest (browser only).
198
- * Provides progress tracking.
199
- */
200
- async function uploadWithXHR(
201
- file: UploadableFile,
202
- presigned: PresignedUploadUrl,
203
- options: Required<Pick<UploadToS3Options, "onProgress" | "timeout">> & {
204
- signal?: AbortSignal;
205
- }
206
- ): Promise<UploadToS3Result> {
207
- const { onProgress, signal, timeout } = options;
208
-
209
- return new Promise((resolve, reject) => {
210
- const xhr = new XMLHttpRequest();
211
-
212
- // Build FormData
213
- const formData = new FormData();
214
-
215
- // Add presigned fields first (order matters for S3)
216
- for (const [key, value] of Object.entries(presigned.fields)) {
217
- formData.append(key, value);
218
- }
219
-
220
- // Add content-type and file last
221
- formData.append("Content-Type", file.type);
222
- formData.append("file", file.data as Blob, file.name);
223
-
224
- // Manual timeout (XHR timeout doesn't include upload time)
225
- const timeoutId = setTimeout(() => {
226
- xhr.abort();
227
- reject(new UploadTimeoutError(timeout));
228
- }, timeout);
229
-
230
- // Progress tracking
231
- xhr.upload.onprogress = (event) => {
232
- if (event.lengthComputable) {
233
- onProgress(event.loaded / event.total);
234
- }
235
- };
236
-
237
- // Success handler
238
- xhr.onload = () => {
239
- clearTimeout(timeoutId);
240
-
241
- if (xhr.status >= 200 && xhr.status < 300) {
242
- onProgress(1); // Ensure we report 100%
243
- resolve({ success: true });
244
- } else {
245
- reject(
246
- new UploadError(
247
- `S3 upload failed with status ${xhr.status}: ${xhr.statusText}`,
248
- "upload"
249
- )
250
- );
251
- }
252
- };
253
-
254
- // Error handler
255
- xhr.onerror = () => {
256
- clearTimeout(timeoutId);
257
- reject(new UploadError("Network error during upload", "upload"));
258
- };
259
-
260
- // Abort handler
261
- xhr.onabort = () => {
262
- clearTimeout(timeoutId);
263
- reject(new UploadAbortedError());
264
- };
265
-
266
- // Timeout handler
267
- xhr.ontimeout = () => {
268
- clearTimeout(timeoutId);
269
- reject(new UploadTimeoutError(timeout));
270
- };
271
-
272
- // AbortSignal support
273
- if (signal) {
274
- signal.addEventListener("abort", () => {
275
- xhr.abort();
276
- });
277
- }
278
-
279
- // Configure and send
280
- xhr.open("POST", presigned.url);
281
- xhr.timeout = timeout;
282
- xhr.send(formData);
283
- });
284
- }
285
-
286
- /**
287
- * Uploads using fetch (Node.js compatible).
288
- * No progress tracking available.
289
- */
290
- async function uploadWithFetch(
291
- file: UploadableFile,
292
- presigned: PresignedUploadUrl,
293
- options: { signal?: AbortSignal; timeout: number }
294
- ): Promise<UploadToS3Result> {
295
- const { signal, timeout } = options;
296
-
297
- // Create timeout signal
298
- const timeoutController = new AbortController();
299
- const timeoutId = setTimeout(() => timeoutController.abort(), timeout);
300
-
301
- // Combine with user signal if provided
302
- const combinedSignal = signal
303
- ? anySignal([signal, timeoutController.signal])
304
- : timeoutController.signal;
305
-
306
- try {
307
- // Build FormData
308
- // In Node.js 18+, FormData is available globally
309
- const formData = new FormData();
310
-
311
- // Add presigned fields first
312
- for (const [key, value] of Object.entries(presigned.fields)) {
313
- formData.append(key, value);
314
- }
315
-
316
- // Add content-type and file
317
- formData.append("Content-Type", file.type);
318
-
319
- // Handle different data types - convert to Blob for FormData compatibility
320
- let blob: Blob;
321
- if (file.data instanceof Blob) {
322
- blob = file.data;
323
- } else if (file.data instanceof ArrayBuffer) {
324
- blob = new Blob([file.data], { type: file.type });
325
- } else {
326
- // Buffer - convert to Uint8Array first for cross-platform compatibility
327
- const uint8 = new Uint8Array(file.data);
328
- blob = new Blob([uint8], { type: file.type });
329
- }
330
- formData.append("file", blob, file.name);
331
-
332
- const response = await fetch(presigned.url, {
333
- method: "POST",
334
- body: formData,
335
- signal: combinedSignal,
336
- });
337
-
338
- if (!response.ok) {
339
- const text = await response.text().catch(() => "");
340
- throw new UploadError(
341
- `S3 upload failed with status ${response.status}: ${text}`,
342
- "upload"
343
- );
344
- }
345
-
346
- return { success: true };
347
- } catch (error) {
348
- if (error instanceof UploadError) {
349
- throw error;
350
- }
351
-
352
- if (error instanceof Error) {
353
- if (error.name === "AbortError") {
354
- // Check which signal caused the abort
355
- if (signal?.aborted) {
356
- throw new UploadAbortedError();
357
- }
358
- throw new UploadTimeoutError(timeout);
359
- }
360
- throw new UploadError(error.message, "upload");
361
- }
362
-
363
- throw new UploadError("Unknown upload error", "upload");
364
- } finally {
365
- clearTimeout(timeoutId);
366
- }
367
- }
368
-
369
- /**
370
- * Combines multiple AbortSignals into one.
371
- * Aborts when any of the input signals abort.
372
- */
373
- function anySignal(signals: AbortSignal[]): AbortSignal {
374
- const controller = new AbortController();
375
-
376
- for (const signal of signals) {
377
- if (signal.aborted) {
378
- controller.abort(signal.reason);
379
- return controller.signal;
380
- }
381
-
382
- signal.addEventListener("abort", () => controller.abort(signal.reason), {
383
- once: true,
384
- });
385
- }
386
-
387
- return controller.signal;
388
- }