@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,303 +0,0 @@
1
- import type { Environment } from "./environment";
2
-
3
- export type SessionType = "session" | "apiKey";
4
-
5
- export interface SessionInfo {
6
- organizationId: string;
7
- permissions: string[];
8
- environment: Environment;
9
- userId: string;
10
- type: SessionType;
11
- }
12
-
13
- // ===========================
14
- // Session Options
15
- // ===========================
16
-
17
- /**
18
- * Base options for fetchSession.
19
- */
20
- interface SessionOptionsBase {
21
- /**
22
- * Base URL for the API (e.g. https://api.artu.ai)
23
- */
24
- baseUrl: string;
25
-
26
- /**
27
- * Environment header value ("test" | "live")
28
- */
29
- environment: Environment;
30
-
31
- /**
32
- * Credentials policy for fetch. Defaults to "include".
33
- */
34
- credentials?: "include" | "omit" | "same-origin";
35
-
36
- /**
37
- * Custom headers to include with the request.
38
- * Useful for server-side cookie forwarding.
39
- */
40
- headers?: Record<string, string>;
41
-
42
- /**
43
- * Custom fetch implementation (optional).
44
- */
45
- fetchImpl?: typeof fetch;
46
-
47
- /**
48
- * Optional organization ID to lock the login to a specific organization.
49
- * When provided, users will only be able to log in to this organization.
50
- * Useful for custom apps to prevent users from logging into the wrong organization.
51
- */
52
- organizationId?: string;
53
- }
54
-
55
- /**
56
- * Options for fetchSession when returnTo is provided.
57
- */
58
- export interface SessionOptionsWithReturnTo extends SessionOptionsBase {
59
- /**
60
- * Full URL to return to after authentication.
61
- * When provided, redirectUrl will be included in the result when not authenticated.
62
- */
63
- returnTo: string;
64
- }
65
-
66
- /**
67
- * Options for fetchSession when returnTo is not provided.
68
- */
69
- export interface SessionOptionsWithoutReturnTo extends SessionOptionsBase {
70
- returnTo?: never;
71
- }
72
-
73
- /**
74
- * Combined session options type.
75
- */
76
- export type SessionOptions =
77
- | SessionOptionsWithReturnTo
78
- | SessionOptionsWithoutReturnTo;
79
-
80
- // ===========================
81
- // SDK Session Method Options
82
- // (Used by sdk.session() - doesn't require baseUrl/environment)
83
- // ===========================
84
-
85
- /**
86
- * Base SDK session options shared across all variants.
87
- */
88
- interface SDKSessionOptionsBase {
89
- /**
90
- * Optional organization ID to lock the login to a specific organization.
91
- * When provided, users will only be able to log in to this organization.
92
- * Useful for custom apps to prevent users from logging into the wrong organization.
93
- */
94
- organizationId?: string;
95
- }
96
-
97
- /**
98
- * Options for sdk.session() when returnTo is provided.
99
- * Result will include redirectUrl when not authenticated.
100
- */
101
- export interface SDKSessionOptionsWithReturnTo extends SDKSessionOptionsBase {
102
- /**
103
- * Full URL to return to after authentication.
104
- * When provided, redirectUrl will be included in the result when not authenticated.
105
- */
106
- returnTo: string;
107
- }
108
-
109
- /**
110
- * Options for sdk.session() when returnTo is not provided.
111
- */
112
- export interface SDKSessionOptionsWithoutReturnTo extends SDKSessionOptionsBase {
113
- returnTo?: never;
114
- }
115
-
116
- /**
117
- * Combined SDK session options type.
118
- */
119
- export type SDKSessionOptions =
120
- | SDKSessionOptionsWithReturnTo
121
- | SDKSessionOptionsWithoutReturnTo;
122
-
123
- // ===========================
124
- // Session Results
125
- // ===========================
126
-
127
- /**
128
- * Result when user is authenticated.
129
- */
130
- export interface SessionResultAuthenticated {
131
- session: SessionInfo;
132
- isAuthenticated: true;
133
- redirectUrl?: never;
134
- }
135
-
136
- /**
137
- * Result when user is NOT authenticated and returnTo was provided.
138
- */
139
- export interface SessionResultUnauthenticatedWithRedirect {
140
- session: null;
141
- isAuthenticated: false;
142
- redirectUrl: string;
143
- }
144
-
145
- /**
146
- * Result when user is NOT authenticated and returnTo was NOT provided.
147
- */
148
- export interface SessionResultUnauthenticatedNoRedirect {
149
- session: null;
150
- isAuthenticated: false;
151
- redirectUrl?: never;
152
- }
153
-
154
- /**
155
- * Session result when returnTo is provided.
156
- * Either authenticated (session present, no redirect) or unauthenticated (no session, redirect present).
157
- * This allows TypeScript to narrow: if redirectUrl exists, session is null; otherwise session is present.
158
- */
159
- export type SessionResultWithRedirect =
160
- | SessionResultAuthenticated
161
- | SessionResultUnauthenticatedWithRedirect;
162
-
163
- /**
164
- * Session result when returnTo is NOT provided.
165
- */
166
- export type SessionResultWithoutRedirect =
167
- | SessionResultAuthenticated
168
- | SessionResultUnauthenticatedNoRedirect;
169
-
170
- /**
171
- * Generic session result type.
172
- */
173
- export type SessionResult =
174
- | SessionResultAuthenticated
175
- | SessionResultUnauthenticatedWithRedirect
176
- | SessionResultUnauthenticatedNoRedirect;
177
-
178
- // ===========================
179
- // Helper
180
- // ===========================
181
-
182
- export function createAuthLoginUrl(options: {
183
- apiBaseUrl: string;
184
- returnTo: string;
185
- organizationId?: string;
186
- }): string {
187
- const { apiBaseUrl, returnTo, organizationId } = options;
188
- const loginUrl = new URL("/auth/login", apiBaseUrl);
189
- loginUrl.searchParams.set("return_to", returnTo);
190
- if (organizationId) {
191
- loginUrl.searchParams.set("organization_id", organizationId);
192
- }
193
- return loginUrl.toString();
194
- }
195
-
196
- // ===========================
197
- // Fetch Session
198
- // ===========================
199
-
200
- /**
201
- * Fetches session from /auth/me.
202
- * Returns a result object with session info if authenticated,
203
- * or null session with optional redirectUrl if not.
204
- *
205
- * @example With returnTo (includes redirectUrl when not authenticated)
206
- * ```typescript
207
- * const result = await fetchSession({
208
- * baseUrl: "https://api.artu.ai",
209
- * environment: "test",
210
- * returnTo: "https://dashboard.artu.ai/env/test/dashboard",
211
- * });
212
- *
213
- * if (result.redirectUrl) {
214
- * redirect(result.redirectUrl);
215
- * }
216
- *
217
- * // TypeScript knows session is guaranteed here
218
- * console.log("User:", result.session.userId);
219
- * ```
220
- *
221
- * @example Without returnTo (just check if authenticated)
222
- * ```typescript
223
- * const result = await fetchSession({
224
- * baseUrl: "https://api.artu.ai",
225
- * environment: "test",
226
- * });
227
- *
228
- * if (result.isAuthenticated) {
229
- * console.log("User:", result.session.userId);
230
- * }
231
- * ```
232
- */
233
- export function fetchSession(
234
- options: SessionOptionsWithReturnTo
235
- ): Promise<SessionResultWithRedirect>;
236
- export function fetchSession(
237
- options: SessionOptionsWithoutReturnTo
238
- ): Promise<SessionResultWithoutRedirect>;
239
- export async function fetchSession(
240
- options: SessionOptions
241
- ): Promise<SessionResult> {
242
- const {
243
- baseUrl,
244
- environment,
245
- credentials = "include",
246
- headers: customHeaders = {},
247
- fetchImpl = fetch,
248
- returnTo,
249
- } = options;
250
-
251
- // Extract organizationId only when returnTo is provided
252
- const organizationId =
253
- "organizationId" in options
254
- ? (options as SessionOptionsWithReturnTo).organizationId
255
- : undefined;
256
-
257
- const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
258
-
259
- const handleUnauthenticated = ():
260
- | SessionResultUnauthenticatedWithRedirect
261
- | SessionResultUnauthenticatedNoRedirect => {
262
- if (returnTo) {
263
- return {
264
- session: null,
265
- isAuthenticated: false,
266
- redirectUrl: createAuthLoginUrl({
267
- apiBaseUrl: normalizedBaseUrl,
268
- returnTo,
269
- organizationId,
270
- }),
271
- };
272
- }
273
-
274
- return {
275
- session: null,
276
- isAuthenticated: false,
277
- };
278
- };
279
-
280
- try {
281
- const res = await fetchImpl(`${normalizedBaseUrl}/auth/me`, {
282
- headers: {
283
- ...customHeaders,
284
- "X-Environment": environment,
285
- },
286
- credentials,
287
- });
288
-
289
- if (res.status === 401 || !res.ok) {
290
- return handleUnauthenticated();
291
- }
292
-
293
- const session = (await res.json()) as SessionInfo;
294
-
295
- return {
296
- session,
297
- isAuthenticated: true,
298
- };
299
- } catch {
300
- // Network error or other failure - treat as not authenticated
301
- return handleUnauthenticated();
302
- }
303
- }
@@ -1,242 +0,0 @@
1
- /**
2
- * tRPC Client Factory
3
- *
4
- * Creates a type-safe tRPC client for communicating with the Compliance API.
5
- * Uses httpBatchLink for efficient request batching.
6
- */
7
-
8
- import { createTRPCClient, httpBatchLink, TRPCClientError } from "@trpc/client";
9
-
10
- // Type-only import from API (no runtime dependency)
11
- import type { AppRouter } from "api";
12
-
13
- // ===========================
14
- // Types
15
- // ===========================
16
-
17
- /**
18
- * Supported API versions
19
- */
20
- export type APIVersion = "v1";
21
-
22
- /**
23
- * SDK Environment - determines data isolation
24
- */
25
- export type SDKEnvironment = "test" | "live";
26
-
27
- /**
28
- * Configuration for creating a tRPC client
29
- */
30
- export type TRPCAuthMode = "apiKey" | "cookie";
31
-
32
- export interface TRPCAPIKeyAuthConfig {
33
- mode?: "apiKey";
34
- apiKey: string;
35
- }
36
-
37
- export interface TRPCCookieAuthConfig {
38
- mode: "cookie";
39
- credentials?: "include" | "omit" | "same-origin";
40
- /**
41
- * Custom headers to include with each request.
42
- * Useful for server-side cookie forwarding in Next.js.
43
- *
44
- * @example
45
- * ```typescript
46
- * // Forward cookies in Next.js server component
47
- * const cookieStore = await cookies();
48
- * const sdk = new ComplianceSDK({
49
- * mode: "cookie",
50
- * headers: { Cookie: cookieStore.toString() },
51
- * });
52
- * ```
53
- */
54
- headers?: Record<string, string>;
55
- }
56
-
57
- export type TRPCAuthConfig = TRPCAPIKeyAuthConfig | TRPCCookieAuthConfig;
58
-
59
- export type TRPCClientConfig = TRPCAuthConfig & {
60
- /**
61
- * Base URL for the API
62
- * @example "https://api.compliance.artu.com"
63
- */
64
- baseUrl: string;
65
-
66
- /**
67
- * Target environment for data isolation
68
- */
69
- environment: SDKEnvironment;
70
-
71
- /**
72
- * API version to use. Defaults to latest stable version.
73
- * @default "v1"
74
- */
75
- apiVersion?: APIVersion;
76
-
77
- /**
78
- * Request timeout in milliseconds
79
- * @default 30000
80
- */
81
- timeout?: number;
82
-
83
- /**
84
- * Organization ID for request validation.
85
- * When provided, the API validates that the authenticated
86
- * user/API key belongs to this organization.
87
- */
88
- organizationId?: string;
89
- };
90
-
91
- /**
92
- * tRPC client type - inferred from AppRouter
93
- */
94
- export type TRPCClient = ReturnType<typeof createTRPCClient<AppRouter>>;
95
-
96
- // ===========================
97
- // Constants
98
- // ===========================
99
-
100
- /**
101
- * Current stable API version
102
- */
103
- export const LATEST_API_VERSION: APIVersion = "v1";
104
-
105
- /**
106
- * Default request timeout in milliseconds
107
- */
108
- export const DEFAULT_TIMEOUT = 30000;
109
-
110
- // ===========================
111
- // Client Factory
112
- // ===========================
113
-
114
- /**
115
- * Creates a tRPC client configured for the Compliance API
116
- *
117
- * @param config - Client configuration
118
- * @returns Configured tRPC client
119
- *
120
- * @example
121
- * ```typescript
122
- * const client = createAPIClient({
123
- * apiKey: "sk_test_org123_abc123...",
124
- * baseUrl: "https://api.compliance.artu.com",
125
- * environment: "test",
126
- * });
127
- *
128
- * // Make type-safe API calls
129
- * const health = await client.health.check.query();
130
- * ```
131
- */
132
- export function createAPIClient(config: TRPCClientConfig) {
133
- const {
134
- mode: rawMode,
135
- baseUrl,
136
- environment,
137
- apiVersion = LATEST_API_VERSION,
138
- timeout = DEFAULT_TIMEOUT,
139
- organizationId,
140
- } = config;
141
-
142
- const mode: TRPCAuthMode = rawMode ?? "apiKey";
143
-
144
- let authHeaders: Record<string, string> = {};
145
- let resolvedCredentials: TRPCCookieAuthConfig["credentials"] | undefined;
146
-
147
- let customHeaders: Record<string, string> = {};
148
-
149
- if (mode === "apiKey") {
150
- const apiKey = (config as TRPCAPIKeyAuthConfig).apiKey;
151
- if (!apiKey || typeof apiKey !== "string") {
152
- throw new Error("API key is required when auth mode is apiKey.");
153
- }
154
- authHeaders = { Authorization: `Bearer ${apiKey}` };
155
- } else {
156
- const cookieConfig = config as TRPCCookieAuthConfig;
157
- resolvedCredentials = cookieConfig.credentials ?? "include";
158
- customHeaders = cookieConfig.headers ?? {};
159
- }
160
-
161
- const baseHeaders: Record<string, string> = {
162
- ...customHeaders,
163
- ...authHeaders,
164
- "X-Environment": environment,
165
- "X-Request-ID": generateRequestId(),
166
- ...(organizationId ? { "X-Organization-ID": organizationId } : {}),
167
- };
168
-
169
- // Normalize baseUrl (remove trailing slash)
170
- const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
171
-
172
- return createTRPCClient<AppRouter>({
173
- links: [
174
- httpBatchLink({
175
- url: `${normalizedBaseUrl}/${apiVersion}/trpc`,
176
- headers: () => baseHeaders,
177
- fetch: (url, options) => {
178
- return fetch(url, {
179
- ...options,
180
- signal: AbortSignal.timeout(timeout),
181
- ...(resolvedCredentials
182
- ? { credentials: resolvedCredentials }
183
- : {}),
184
- });
185
- },
186
- }),
187
- ],
188
- });
189
- }
190
-
191
- // ===========================
192
- // Helpers
193
- // ===========================
194
-
195
- /**
196
- * Generates a unique request ID for tracing and debugging
197
- *
198
- * Format: req_{timestamp}_{random}
199
- * @example "req_m1abc23_xk9z4w2"
200
- */
201
- export function generateRequestId(): string {
202
- const timestamp = Date.now().toString(36);
203
- const random = Math.random().toString(36).slice(2, 9);
204
- return `req_${timestamp}_${random}`;
205
- }
206
-
207
- /**
208
- * Type guard for tRPC client errors
209
- *
210
- * @param error - Unknown error value
211
- * @returns True if error is a TRPCClientError
212
- *
213
- * @example
214
- * ```typescript
215
- * try {
216
- * await client.clients.create.mutate({ name: "Test" });
217
- * } catch (error) {
218
- * if (isTRPCError(error)) {
219
- * console.log("tRPC error code:", error.data?.code);
220
- * }
221
- * }
222
- * ```
223
- */
224
- export function isTRPCError(
225
- error: unknown
226
- ): error is TRPCClientError<AppRouter> {
227
- return error instanceof TRPCClientError;
228
- }
229
-
230
- /**
231
- * Extracts the request ID from a tRPC error if available
232
- *
233
- * @param error - tRPC client error
234
- * @returns Request ID or undefined
235
- */
236
- export function getRequestIdFromError(
237
- error: TRPCClientError<AppRouter>
238
- ): string | undefined {
239
- // The request ID may be in the error meta or headers
240
- // This will be populated when the API returns it
241
- return error.meta?.requestId as string | undefined;
242
- }