@artu-ai/compliance-sdk 0.4.1 → 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.
- package/package.json +3 -4
- package/src/errors/api.ts +0 -305
- package/src/errors/base.ts +0 -127
- package/src/errors/index.ts +0 -63
- package/src/errors/upload.ts +0 -204
- package/src/errors/validation.ts +0 -163
- package/src/exports/base.ts +0 -139
- package/src/exports/index.ts +0 -187
- package/src/exports/mexico/actividad-vulnerable/avi.ts +0 -207
- package/src/exports/mexico/actividad-vulnerable/jys.ts +0 -214
- package/src/exports/mexico/actividad-vulnerable/tsc.ts +0 -202
- package/src/exports/mexico/index.ts +0 -215
- package/src/models/Address.ts +0 -235
- package/src/models/BankAccount.ts +0 -235
- package/src/models/Client.ts +0 -363
- package/src/models/ContactMethod.ts +0 -197
- package/src/models/Document.ts +0 -355
- package/src/models/LinkedClient.ts +0 -84
- package/src/models/Report.ts +0 -193
- package/src/models/ReportItem.ts +0 -211
- package/src/models/Transaction.ts +0 -219
- package/src/models/base.ts +0 -56
- package/src/models/index.ts +0 -148
- package/src/models/mex/MexAddress.ts +0 -184
- package/src/models/mex/MexBankAccount.ts +0 -121
- package/src/models/mex/MexClient.ts +0 -177
- package/src/models/mex/MexDocument.ts +0 -890
- package/src/models/mex/MexReport.ts +0 -99
- package/src/models/mex/MexReportItem.ts +0 -79
- package/src/models/mex/MexTransaction.ts +0 -105
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableClient.ts +0 -66
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableReport.ts +0 -73
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableReportItem.ts +0 -74
- package/src/models/mex/actividad-vulnerable/MexActividadVulnerableTransaction.ts +0 -50
- package/src/models/mex/actividad-vulnerable/avi/MexAVIClient.ts +0 -80
- package/src/models/mex/actividad-vulnerable/avi/MexAVIReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/avi/MexAVIReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/avi/MexAVITransaction.ts +0 -157
- package/src/models/mex/actividad-vulnerable/index.ts +0 -78
- package/src/models/mex/actividad-vulnerable/jys/MexJYSClient.ts +0 -73
- package/src/models/mex/actividad-vulnerable/jys/MexJYSReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/jys/MexJYSReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/jys/MexJYSTransaction.ts +0 -178
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCClient.ts +0 -73
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCReport.ts +0 -114
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCReportItem.ts +0 -105
- package/src/models/mex/actividad-vulnerable/tsc/MexTSCTransaction.ts +0 -104
- package/src/models/mex/index.ts +0 -57
- package/src/models/types.ts +0 -196
- package/src/namespaces/index.ts +0 -29
- package/src/namespaces/mexico/actividad-vulnerable/avi/index.ts +0 -62
- package/src/namespaces/mexico/actividad-vulnerable/index.ts +0 -79
- package/src/namespaces/mexico/actividad-vulnerable/jys/index.ts +0 -72
- package/src/namespaces/mexico/actividad-vulnerable/tsc/index.ts +0 -60
- package/src/namespaces/mexico/index.ts +0 -325
- package/src/resources/addresses.ts +0 -391
- package/src/resources/bank-accounts.ts +0 -417
- package/src/resources/base.ts +0 -327
- package/src/resources/clients.ts +0 -808
- package/src/resources/contact-methods.ts +0 -412
- package/src/resources/documents.ts +0 -688
- package/src/resources/index.ts +0 -40
- package/src/resources/mex/actividad-vulnerable/avi/clients.ts +0 -559
- package/src/resources/mex/actividad-vulnerable/avi/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/avi/reports.ts +0 -609
- package/src/resources/mex/actividad-vulnerable/avi/transactions.ts +0 -404
- package/src/resources/mex/actividad-vulnerable/index.ts +0 -12
- package/src/resources/mex/actividad-vulnerable/jys/clients.ts +0 -445
- package/src/resources/mex/actividad-vulnerable/jys/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/jys/reports.ts +0 -591
- package/src/resources/mex/actividad-vulnerable/jys/transactions.ts +0 -395
- package/src/resources/mex/actividad-vulnerable/tsc/clients.ts +0 -445
- package/src/resources/mex/actividad-vulnerable/tsc/index.ts +0 -7
- package/src/resources/mex/actividad-vulnerable/tsc/reports.ts +0 -591
- package/src/resources/mex/actividad-vulnerable/tsc/transactions.ts +0 -404
- package/src/resources/mex/addresses.ts +0 -493
- package/src/resources/mex/bank-accounts.ts +0 -283
- package/src/resources/mex/clients.ts +0 -758
- package/src/resources/mex/ebr.ts +0 -621
- package/src/resources/mex/index.ts +0 -23
- package/src/resources/mex/reports.ts +0 -643
- package/src/resources/mex/transactions.ts +0 -422
- package/src/resources/reports.ts +0 -515
- package/src/resources/transactions.ts +0 -358
- package/src/sdk/ComplianceSDK.ts +0 -812
- package/src/sdk/base.ts +0 -43
- package/src/sdk/index.ts +0 -98
- package/src/sdk/mex/ComplianceSDK.ts +0 -147
- package/src/sdk/mex/actividad-vulnerable/avi/ComplianceSDK.ts +0 -55
- package/src/sdk/mex/actividad-vulnerable/avi/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/avi/types.ts +0 -86
- package/src/sdk/mex/actividad-vulnerable/index.ts +0 -58
- package/src/sdk/mex/actividad-vulnerable/jys/ComplianceSDK.ts +0 -54
- package/src/sdk/mex/actividad-vulnerable/jys/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/jys/types.ts +0 -86
- package/src/sdk/mex/actividad-vulnerable/tsc/ComplianceSDK.ts +0 -54
- package/src/sdk/mex/actividad-vulnerable/tsc/index.ts +0 -16
- package/src/sdk/mex/actividad-vulnerable/tsc/types.ts +0 -86
- package/src/sdk/mex/index.ts +0 -66
- package/src/sdk/mex/types.ts +0 -88
- package/src/sdk/resource-registry.ts +0 -204
- package/src/sdk/sdk-registry.ts +0 -99
- package/src/sdk/types.ts +0 -304
- package/src/utils/environment.ts +0 -187
- package/src/utils/filters.ts +0 -412
- package/src/utils/index.ts +0 -134
- package/src/utils/pagination.ts +0 -143
- package/src/utils/session.ts +0 -303
- package/src/utils/trpc-client.ts +0 -242
- package/src/utils/upload.ts +0 -388
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artu-ai/compliance-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "TypeScript SDK for the Artu Compliance API",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"dist",
|
|
46
|
-
"src",
|
|
47
46
|
"README.md"
|
|
48
47
|
],
|
|
49
48
|
"publishConfig": {
|
|
@@ -57,7 +56,7 @@
|
|
|
57
56
|
},
|
|
58
57
|
"license": "UNLICENSED",
|
|
59
58
|
"dependencies": {
|
|
60
|
-
"@artu-ai/shared": "0.4.
|
|
59
|
+
"@artu-ai/shared": "0.4.2",
|
|
61
60
|
"@trpc/client": "^11.7.2"
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
|
@@ -68,4 +67,4 @@
|
|
|
68
67
|
"vitest": "^4.0.14",
|
|
69
68
|
"zod": "^4.1.12"
|
|
70
69
|
}
|
|
71
|
-
}
|
|
70
|
+
}
|
package/src/errors/api.ts
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API error classes
|
|
3
|
-
*
|
|
4
|
-
* Errors thrown when the API returns error responses.
|
|
5
|
-
* Includes specific error types for common scenarios.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { TRPCClientError } from "@trpc/client";
|
|
9
|
-
import { ComplianceError, type ComplianceErrorOptions } from "./base";
|
|
10
|
-
import { ValidationError, type ValidationIssue } from "./validation";
|
|
11
|
-
|
|
12
|
-
// ===========================
|
|
13
|
-
// API Error Base Class
|
|
14
|
-
// ===========================
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Error thrown when the API returns an error response.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* try {
|
|
22
|
-
* await sdk.clients.create({ ... });
|
|
23
|
-
* } catch (error) {
|
|
24
|
-
* if (error instanceof APIError) {
|
|
25
|
-
* console.log("Status:", error.statusCode);
|
|
26
|
-
* console.log("Code:", error.code);
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export class APIError extends ComplianceError {
|
|
32
|
-
/**
|
|
33
|
-
* HTTP status code (if available)
|
|
34
|
-
*/
|
|
35
|
-
public readonly statusCode?: number;
|
|
36
|
-
|
|
37
|
-
constructor(
|
|
38
|
-
message: string,
|
|
39
|
-
code: string,
|
|
40
|
-
options?: ComplianceErrorOptions & { statusCode?: number }
|
|
41
|
-
) {
|
|
42
|
-
super(message, code, options);
|
|
43
|
-
this.name = "APIError";
|
|
44
|
-
this.statusCode = options?.statusCode;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// ===========================
|
|
49
|
-
// Specific API Errors
|
|
50
|
-
// ===========================
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Resource not found error (404).
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* try {
|
|
58
|
-
* await sdk.clients.retrieve("invalid-id");
|
|
59
|
-
* } catch (error) {
|
|
60
|
-
* if (error instanceof NotFoundError) {
|
|
61
|
-
* console.log(`${error.resourceType} '${error.resourceId}' not found`);
|
|
62
|
-
* }
|
|
63
|
-
* }
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export class NotFoundError extends APIError {
|
|
67
|
-
/**
|
|
68
|
-
* Type of resource that was not found (e.g., "Client", "Transaction")
|
|
69
|
-
*/
|
|
70
|
-
public readonly resourceType: string;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* ID of the resource that was not found
|
|
74
|
-
*/
|
|
75
|
-
public readonly resourceId: string;
|
|
76
|
-
|
|
77
|
-
constructor(resourceType: string, resourceId: string, requestId?: string) {
|
|
78
|
-
super(`${resourceType} with ID '${resourceId}' not found`, "NOT_FOUND", {
|
|
79
|
-
statusCode: 404,
|
|
80
|
-
requestId,
|
|
81
|
-
details: { resourceType, resourceId },
|
|
82
|
-
});
|
|
83
|
-
this.name = "NotFoundError";
|
|
84
|
-
this.resourceType = resourceType;
|
|
85
|
-
this.resourceId = resourceId;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Authentication failed error (401).
|
|
91
|
-
* Thrown when the API key is invalid or missing.
|
|
92
|
-
*/
|
|
93
|
-
export class UnauthorizedError extends APIError {
|
|
94
|
-
constructor(message = "Invalid or missing API key", requestId?: string) {
|
|
95
|
-
super(message, "UNAUTHORIZED", { statusCode: 401, requestId });
|
|
96
|
-
this.name = "UnauthorizedError";
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Permission denied error (403).
|
|
102
|
-
* Thrown when the API key lacks permission for the operation.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```typescript
|
|
106
|
-
* // Using test API key with live environment
|
|
107
|
-
* const sdk = new ComplianceSDK({
|
|
108
|
-
* apiKey: "sk_test_...",
|
|
109
|
-
* environment: "live", // No permission!
|
|
110
|
-
* });
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export class ForbiddenError extends APIError {
|
|
114
|
-
constructor(message = "Permission denied", requestId?: string) {
|
|
115
|
-
super(message, "FORBIDDEN", { statusCode: 403, requestId });
|
|
116
|
-
this.name = "ForbiddenError";
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Rate limit exceeded error (429).
|
|
122
|
-
* Includes retry information when available.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```typescript
|
|
126
|
-
* try {
|
|
127
|
-
* await sdk.clients.list();
|
|
128
|
-
* } catch (error) {
|
|
129
|
-
* if (error instanceof RateLimitError) {
|
|
130
|
-
* console.log(`Rate limited. Retry after ${error.retryAfter}s`);
|
|
131
|
-
* await sleep(error.retryAfter * 1000);
|
|
132
|
-
* // Retry...
|
|
133
|
-
* }
|
|
134
|
-
* }
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
export class RateLimitError extends APIError {
|
|
138
|
-
/**
|
|
139
|
-
* Seconds to wait before retrying (if provided by API)
|
|
140
|
-
*/
|
|
141
|
-
public readonly retryAfter?: number;
|
|
142
|
-
|
|
143
|
-
constructor(retryAfter?: number, requestId?: string) {
|
|
144
|
-
const message = retryAfter
|
|
145
|
-
? `Rate limit exceeded. Retry after ${retryAfter} seconds`
|
|
146
|
-
: "Rate limit exceeded";
|
|
147
|
-
super(message, "RATE_LIMITED", {
|
|
148
|
-
statusCode: 429,
|
|
149
|
-
requestId,
|
|
150
|
-
details: retryAfter ? { retryAfter } : undefined,
|
|
151
|
-
});
|
|
152
|
-
this.name = "RateLimitError";
|
|
153
|
-
this.retryAfter = retryAfter;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Server error (5xx).
|
|
159
|
-
* Indicates an unexpected error on the API server.
|
|
160
|
-
*/
|
|
161
|
-
export class ServerError extends APIError {
|
|
162
|
-
constructor(message = "Internal server error", requestId?: string) {
|
|
163
|
-
super(message, "SERVER_ERROR", { statusCode: 500, requestId });
|
|
164
|
-
this.name = "ServerError";
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Network/connection error.
|
|
170
|
-
* Thrown when the request fails to reach the server.
|
|
171
|
-
*/
|
|
172
|
-
export class NetworkError extends APIError {
|
|
173
|
-
constructor(message = "Network error", cause?: Error) {
|
|
174
|
-
super(message, "NETWORK_ERROR", { cause });
|
|
175
|
-
this.name = "NetworkError";
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Request timeout error.
|
|
181
|
-
* Thrown when the request exceeds the configured timeout.
|
|
182
|
-
*/
|
|
183
|
-
export class TimeoutError extends APIError {
|
|
184
|
-
/**
|
|
185
|
-
* Timeout duration in milliseconds
|
|
186
|
-
*/
|
|
187
|
-
public readonly timeout: number;
|
|
188
|
-
|
|
189
|
-
constructor(timeout: number, requestId?: string) {
|
|
190
|
-
super(`Request timed out after ${timeout}ms`, "TIMEOUT", {
|
|
191
|
-
requestId,
|
|
192
|
-
details: { timeout },
|
|
193
|
-
});
|
|
194
|
-
this.name = "TimeoutError";
|
|
195
|
-
this.timeout = timeout;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// ===========================
|
|
200
|
-
// tRPC Error Mapping
|
|
201
|
-
// ===========================
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Maps a tRPC client error to an SDK-specific error.
|
|
205
|
-
*
|
|
206
|
-
* This function converts tRPC errors into the appropriate
|
|
207
|
-
* SDK error class for better error handling.
|
|
208
|
-
*
|
|
209
|
-
* @param error - tRPC client error
|
|
210
|
-
* @returns SDK-specific error
|
|
211
|
-
*
|
|
212
|
-
* @example
|
|
213
|
-
* ```typescript
|
|
214
|
-
* try {
|
|
215
|
-
* await trpcClient.clients.retrieve.query({ id: "..." });
|
|
216
|
-
* } catch (error) {
|
|
217
|
-
* if (isTRPCError(error)) {
|
|
218
|
-
* throw mapTRPCError(error);
|
|
219
|
-
* }
|
|
220
|
-
* throw error;
|
|
221
|
-
* }
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
-
export function mapTRPCError(error: TRPCClientError<any>): ComplianceError {
|
|
226
|
-
// Extract error data from tRPC response
|
|
227
|
-
const data = error.data as Record<string, unknown> | undefined;
|
|
228
|
-
const code = data?.code as string | undefined;
|
|
229
|
-
const requestId = data?.requestId as string | undefined;
|
|
230
|
-
|
|
231
|
-
// Handle specific error codes
|
|
232
|
-
switch (code) {
|
|
233
|
-
case "NOT_FOUND":
|
|
234
|
-
return new NotFoundError(
|
|
235
|
-
(data?.resourceType as string) ?? "Resource",
|
|
236
|
-
(data?.resourceId as string) ?? "unknown",
|
|
237
|
-
requestId
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
case "UNAUTHORIZED":
|
|
241
|
-
return new UnauthorizedError(error.message, requestId);
|
|
242
|
-
|
|
243
|
-
case "FORBIDDEN":
|
|
244
|
-
return new ForbiddenError(error.message, requestId);
|
|
245
|
-
|
|
246
|
-
case "BAD_REQUEST": {
|
|
247
|
-
// Check for Zod validation errors
|
|
248
|
-
const zodError = data?.zodError as
|
|
249
|
-
| { issues?: ValidationIssue[] }
|
|
250
|
-
| undefined;
|
|
251
|
-
if (zodError?.issues) {
|
|
252
|
-
return new ValidationError(zodError.issues, requestId);
|
|
253
|
-
}
|
|
254
|
-
return new ValidationError(
|
|
255
|
-
[{ path: [], message: error.message }],
|
|
256
|
-
requestId
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
case "TOO_MANY_REQUESTS":
|
|
261
|
-
return new RateLimitError(
|
|
262
|
-
data?.retryAfter as number | undefined,
|
|
263
|
-
requestId
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
case "INTERNAL_SERVER_ERROR":
|
|
267
|
-
return new ServerError(error.message, requestId);
|
|
268
|
-
|
|
269
|
-
case "TIMEOUT":
|
|
270
|
-
return new TimeoutError((data?.timeout as number) ?? 30000, requestId);
|
|
271
|
-
|
|
272
|
-
default:
|
|
273
|
-
// Check for network errors
|
|
274
|
-
if (
|
|
275
|
-
error.message.includes("fetch failed") ||
|
|
276
|
-
error.message.includes("network") ||
|
|
277
|
-
error.message.includes("ECONNREFUSED")
|
|
278
|
-
) {
|
|
279
|
-
return new NetworkError(error.message, error);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Generic API error
|
|
283
|
-
return new APIError(error.message, code ?? "UNKNOWN_ERROR", {
|
|
284
|
-
requestId,
|
|
285
|
-
cause: error,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Type guard to check if an error is a specific API error type.
|
|
292
|
-
*
|
|
293
|
-
* @param error - Error to check
|
|
294
|
-
* @param type - Error class to check against
|
|
295
|
-
* @returns True if error is an instance of the specified type
|
|
296
|
-
*/
|
|
297
|
-
export function isAPIError<T extends typeof APIError>(
|
|
298
|
-
error: unknown,
|
|
299
|
-
type?: T
|
|
300
|
-
): error is InstanceType<T> {
|
|
301
|
-
if (type) {
|
|
302
|
-
return error instanceof type;
|
|
303
|
-
}
|
|
304
|
-
return error instanceof APIError;
|
|
305
|
-
}
|
package/src/errors/base.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base error class for SDK errors
|
|
3
|
-
*
|
|
4
|
-
* All SDK errors extend this class, providing consistent
|
|
5
|
-
* structure for error handling and serialization.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// ===========================
|
|
9
|
-
// Types
|
|
10
|
-
// ===========================
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Options for creating a ComplianceError
|
|
14
|
-
*/
|
|
15
|
-
export interface ComplianceErrorOptions {
|
|
16
|
-
/**
|
|
17
|
-
* Request ID for tracing (from X-Request-ID header)
|
|
18
|
-
*/
|
|
19
|
-
requestId?: string;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Additional error details
|
|
23
|
-
*/
|
|
24
|
-
details?: Record<string, unknown>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Original error that caused this error
|
|
28
|
-
*/
|
|
29
|
-
cause?: Error;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* JSON representation of a ComplianceError
|
|
34
|
-
*/
|
|
35
|
-
export interface ComplianceErrorJSON {
|
|
36
|
-
name: string;
|
|
37
|
-
code: string;
|
|
38
|
-
message: string;
|
|
39
|
-
requestId?: string;
|
|
40
|
-
details?: Record<string, unknown>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// ===========================
|
|
44
|
-
// Base Error Class
|
|
45
|
-
// ===========================
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Base error class for all SDK errors.
|
|
49
|
-
*
|
|
50
|
-
* Provides consistent structure for:
|
|
51
|
-
* - Error codes for programmatic handling
|
|
52
|
-
* - Request IDs for debugging
|
|
53
|
-
* - Additional details
|
|
54
|
-
* - JSON serialization
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* try {
|
|
59
|
-
* await sdk.clients.retrieve("invalid-id");
|
|
60
|
-
* } catch (error) {
|
|
61
|
-
* if (error instanceof ComplianceError) {
|
|
62
|
-
* console.log("Error code:", error.code);
|
|
63
|
-
* console.log("Request ID:", error.requestId);
|
|
64
|
-
* // Send to logging service
|
|
65
|
-
* logger.error(error.toJSON());
|
|
66
|
-
* }
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export class ComplianceError extends Error {
|
|
71
|
-
/**
|
|
72
|
-
* Error code for programmatic handling.
|
|
73
|
-
* Examples: "VALIDATION_ERROR", "NOT_FOUND", "UNAUTHORIZED"
|
|
74
|
-
*/
|
|
75
|
-
public readonly code: string;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Request ID for tracing (from X-Request-ID header).
|
|
79
|
-
* Useful for debugging with support.
|
|
80
|
-
*/
|
|
81
|
-
public readonly requestId?: string;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Additional error details.
|
|
85
|
-
* Structure varies by error type.
|
|
86
|
-
*/
|
|
87
|
-
public readonly details?: Record<string, unknown>;
|
|
88
|
-
|
|
89
|
-
constructor(message: string, code: string, options?: ComplianceErrorOptions) {
|
|
90
|
-
super(message, { cause: options?.cause });
|
|
91
|
-
this.name = "ComplianceError";
|
|
92
|
-
this.code = code;
|
|
93
|
-
this.requestId = options?.requestId;
|
|
94
|
-
this.details = options?.details;
|
|
95
|
-
|
|
96
|
-
// Maintain proper prototype chain for instanceof checks
|
|
97
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Serializes the error to a JSON-compatible object.
|
|
102
|
-
* Useful for logging and error reporting.
|
|
103
|
-
*
|
|
104
|
-
* @returns JSON representation of the error
|
|
105
|
-
*/
|
|
106
|
-
toJSON(): ComplianceErrorJSON {
|
|
107
|
-
return {
|
|
108
|
-
name: this.name,
|
|
109
|
-
code: this.code,
|
|
110
|
-
message: this.message,
|
|
111
|
-
requestId: this.requestId,
|
|
112
|
-
details: this.details,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Returns a string suitable for sending to support.
|
|
118
|
-
* Includes request ID if available.
|
|
119
|
-
*/
|
|
120
|
-
toSupportInfo(): string {
|
|
121
|
-
const parts = [`Error: ${this.message}`, `Code: ${this.code}`];
|
|
122
|
-
if (this.requestId) {
|
|
123
|
-
parts.push(`Request ID: ${this.requestId}`);
|
|
124
|
-
}
|
|
125
|
-
return parts.join("\n");
|
|
126
|
-
}
|
|
127
|
-
}
|
package/src/errors/index.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK Error Classes
|
|
3
|
-
*
|
|
4
|
-
* This module exports all error classes used by the SDK.
|
|
5
|
-
* All errors extend ComplianceError and provide consistent
|
|
6
|
-
* structure for error handling and serialization.
|
|
7
|
-
*
|
|
8
|
-
* Error Hierarchy:
|
|
9
|
-
* ```
|
|
10
|
-
* ComplianceError (base)
|
|
11
|
-
* ├── ValidationError # Zod validation failures
|
|
12
|
-
* ├── APIError # tRPC/HTTP errors from server
|
|
13
|
-
* │ ├── NotFoundError
|
|
14
|
-
* │ ├── UnauthorizedError
|
|
15
|
-
* │ ├── ForbiddenError
|
|
16
|
-
* │ ├── RateLimitError
|
|
17
|
-
* │ ├── ServerError
|
|
18
|
-
* │ ├── NetworkError
|
|
19
|
-
* │ └── TimeoutError
|
|
20
|
-
* └── UploadError # File upload failures
|
|
21
|
-
* ├── FileTooLargeError
|
|
22
|
-
* ├── UploadTimeoutError
|
|
23
|
-
* ├── InvalidFileTypeError
|
|
24
|
-
* ├── UploadAbortedError
|
|
25
|
-
* └── UploadUrlExpiredError
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
// Base error
|
|
30
|
-
export {
|
|
31
|
-
ComplianceError,
|
|
32
|
-
type ComplianceErrorOptions,
|
|
33
|
-
type ComplianceErrorJSON,
|
|
34
|
-
} from "./base";
|
|
35
|
-
|
|
36
|
-
// Validation errors
|
|
37
|
-
export { ValidationError, type ValidationIssue } from "./validation";
|
|
38
|
-
|
|
39
|
-
// API errors
|
|
40
|
-
export {
|
|
41
|
-
APIError,
|
|
42
|
-
NotFoundError,
|
|
43
|
-
UnauthorizedError,
|
|
44
|
-
ForbiddenError,
|
|
45
|
-
RateLimitError,
|
|
46
|
-
ServerError,
|
|
47
|
-
NetworkError,
|
|
48
|
-
TimeoutError,
|
|
49
|
-
mapTRPCError,
|
|
50
|
-
isAPIError,
|
|
51
|
-
} from "./api";
|
|
52
|
-
|
|
53
|
-
// Upload errors
|
|
54
|
-
export {
|
|
55
|
-
UploadError,
|
|
56
|
-
FileTooLargeError,
|
|
57
|
-
UploadTimeoutError,
|
|
58
|
-
InvalidFileTypeError,
|
|
59
|
-
UploadAbortedError,
|
|
60
|
-
UploadUrlExpiredError,
|
|
61
|
-
isUploadError,
|
|
62
|
-
type UploadStage,
|
|
63
|
-
} from "./upload";
|