@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.
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
package/src/sdk/types.ts DELETED
@@ -1,304 +0,0 @@
1
- /**
2
- * SDK Core Types
3
- *
4
- * Base types for SDK configuration that are shared across all jurisdictions.
5
- * Jurisdiction-specific types (like MexicoSDKOptions) are defined in their
6
- * respective namespace modules.
7
- */
8
-
9
- import { Jurisdiction, type CodigoActividad } from "@artu-ai/shared";
10
- import type { APIVersion } from "../utils/trpc-client";
11
- import type {
12
- SDKSessionOptions,
13
- SDKSessionOptionsWithReturnTo,
14
- SessionResultWithRedirect,
15
- SessionResultWithoutRedirect,
16
- } from "../utils/session";
17
-
18
- // ===========================
19
- // Environment Types
20
- // ===========================
21
-
22
- /**
23
- * SDK environment mode
24
- * - "test": Uses test data, no real regulatory submissions
25
- * - "live": Uses production data, real regulatory submissions
26
- */
27
- export type Environment = "test" | "live";
28
-
29
- // ===========================
30
- // Base SDK Options
31
- // ===========================
32
-
33
- /**
34
- * Base SDK configuration options (common to all scopes)
35
- */
36
- /**
37
- * Authentication configuration.
38
- *
39
- * - apiKey (default): use WorkOS API key (header)
40
- * - cookie: rely on browser/forwarded cookies (no auth header, credentials include)
41
- */
42
- export type ComplianceAuthMode = "apiKey" | "cookie";
43
-
44
- export interface ComplianceAPIKeyAuth {
45
- /**
46
- * Authentication mode
47
- * - "apiKey": use WorkOS API key (header)
48
- * - "cookie": rely on browser/forwarded cookies (no auth header, credentials include)
49
- */
50
- mode?: "apiKey";
51
- /**
52
- * API key for authentication.
53
- * Obtained from WorkOS dashboard.
54
- *
55
- * If not provided, falls back to the `ARTU_API_KEY` environment variable.
56
- *
57
- * @example "ak_test_abc123..."
58
- */
59
- apiKey?: string;
60
- }
61
-
62
- export type FetchCredentials = "include" | "omit" | "same-origin";
63
-
64
- export interface ComplianceCookieAuth {
65
- /**
66
- * Authentication mode
67
- * - "apiKey": use WorkOS API key (header)
68
- * - "cookie": rely on browser/forwarded cookies (no auth header, credentials include)
69
- */
70
- mode?: "cookie";
71
- /**
72
- * Optional fetch credentials policy override.
73
- * Defaults to "include" when using cookie mode.
74
- */
75
- credentials?: FetchCredentials;
76
- /**
77
- * Custom headers to include with each request.
78
- * Useful for server-side cookie forwarding in Next.js.
79
- *
80
- * @example
81
- * ```typescript
82
- * // Forward cookies in Next.js server component
83
- * const cookieStore = await cookies();
84
- * const sdk = new ComplianceSDK({
85
- * mode: "cookie",
86
- * environment: "test",
87
- * headers: { Cookie: cookieStore.toString() },
88
- * });
89
- * ```
90
- */
91
- headers?: Record<string, string>;
92
- }
93
-
94
- export type ComplianceAuthOptions = ComplianceAPIKeyAuth | ComplianceCookieAuth;
95
-
96
- export type ComplianceSDKOptionsBase = ComplianceAuthOptions & {
97
- /**
98
- * Target environment for data isolation.
99
- * - "test": Uses test data, no real regulatory submissions
100
- * - "live": Uses production data, real regulatory submissions
101
- *
102
- * Priority order:
103
- * 1. Explicit environment option
104
- * 2. `ARTU_ENVIRONMENT` environment variable
105
- * 3. Default: "test"
106
- *
107
- * The API key must have permissions for the requested environment.
108
- */
109
- environment?: Environment;
110
-
111
- /**
112
- * Base URL for the API.
113
- *
114
- * Priority order:
115
- * 1. Explicit baseUrl option
116
- * 2. `ARTU_BASE_URL` environment variable
117
- * 3. Default production URL: https://api.artu.ai
118
- *
119
- * Override for local development or custom deployments.
120
- *
121
- * @example "http://localhost:3001"
122
- */
123
- baseUrl?: string;
124
-
125
- /**
126
- * Organization ID for cookie authentication.
127
- *
128
- * When using cookie auth mode, this restricts login to a specific organization.
129
- * Useful for custom apps to prevent users from logging into the wrong organization.
130
- *
131
- * Priority order:
132
- * 1. Explicit organizationId option
133
- * 2. `ARTU_ORGANIZATION_ID` environment variable
134
- */
135
- organizationId?: string;
136
-
137
- /**
138
- * API version to use.
139
- * Defaults to latest stable version.
140
- *
141
- * @default "v1"
142
- */
143
- apiVersion?: APIVersion;
144
-
145
- /**
146
- * Request timeout in milliseconds.
147
- *
148
- * @default 30000 (30 seconds)
149
- */
150
- timeout?: number;
151
- };
152
-
153
- /**
154
- * Distributive version of Omit that preserves union members.
155
- *
156
- * Important when omitting keys from option types that include unions (like auth modes),
157
- * otherwise `Omit` can erase mode-specific keys (e.g. `apiKey`) due to `keyof` behavior on unions.
158
- */
159
- export type DistributiveOmit<T, K extends PropertyKey> = T extends unknown
160
- ? Omit<T, K>
161
- : never;
162
-
163
- // ===========================
164
- // Scope Types
165
- // ===========================
166
-
167
- /**
168
- * SDK scope configuration - base (unscoped or non-Mexico)
169
- */
170
- export interface SDKScopeBase {
171
- jurisdiction?: Jurisdiction;
172
- }
173
-
174
- /**
175
- * SDK scope configuration - Mexico with optional Actividad Vulnerable
176
- */
177
- export interface SDKScopeMexico {
178
- jurisdiction: typeof Jurisdiction.Mexico;
179
- actividadVulnerable?: CodigoActividad;
180
- }
181
-
182
- /**
183
- * SDK scope configuration
184
- */
185
- export type SDKScope = SDKScopeBase | SDKScopeMexico;
186
-
187
- /**
188
- * Type guard to check if scope is Mexico-scoped
189
- */
190
- export function isMexicoScope(scope: SDKScope): scope is SDKScopeMexico {
191
- return scope.jurisdiction === Jurisdiction.Mexico;
192
- }
193
-
194
- /**
195
- * Builds an SDKScope from jurisdiction and actividadVulnerable options.
196
- *
197
- * @param jurisdiction - Target jurisdiction (optional)
198
- * @param actividadVulnerable - Target activity code (only for Mexico)
199
- * @returns Properly typed SDKScope
200
- *
201
- * @example
202
- * ```typescript
203
- * const scope = buildScope("MX", "AVI");
204
- * // { jurisdiction: "MX", actividadVulnerable: "AVI" }
205
- *
206
- * const unscopedScope = buildScope();
207
- * // {}
208
- * ```
209
- */
210
- export function buildScope(
211
- jurisdiction?: Jurisdiction | "MX" | "US",
212
- actividadVulnerable?: CodigoActividad | "AVI" | "JYS" | "TSC"
213
- ): SDKScope {
214
- if (jurisdiction === Jurisdiction.Mexico) {
215
- return {
216
- jurisdiction: Jurisdiction.Mexico,
217
- actividadVulnerable: actividadVulnerable as CodigoActividad | undefined,
218
- };
219
- }
220
-
221
- if (jurisdiction) {
222
- return { jurisdiction: jurisdiction as Jurisdiction };
223
- }
224
-
225
- return {};
226
- }
227
-
228
- // ===========================
229
- // Unscoped SDK Options
230
- // ===========================
231
-
232
- /**
233
- * SDK options - unscoped or non-Mexico jurisdiction
234
- */
235
- export type ComplianceSDKOptionsUnscoped = ComplianceSDKOptionsBase & {
236
- jurisdiction?: Jurisdiction | "MX" | "US";
237
- };
238
-
239
- /**
240
- * Options for creating an unscoped SDK (no jurisdiction)
241
- */
242
- export type UnscopedSDKOptions = ComplianceSDKOptionsBase & {
243
- jurisdiction?: undefined;
244
- };
245
-
246
- /**
247
- * Options for creating an SDK with a non-Mexico jurisdiction.
248
- * Returns an unscoped SDK since only Mexico has specialized resources.
249
- */
250
- export type OtherJurisdictionSDKOptions = ComplianceSDKOptionsBase & {
251
- jurisdiction: typeof Jurisdiction.UnitedStates | "US";
252
- };
253
-
254
- // ===========================
255
- // Base SDK Interface
256
- // ===========================
257
-
258
- /**
259
- * Base SDK properties shared across all SDK scopes.
260
- * Contains environment info, scope helpers, and supporting resources.
261
- */
262
- export interface BaseComplianceSDK {
263
- // Environment getters
264
- readonly environment: Environment;
265
- readonly apiVersion: APIVersion;
266
- readonly isTest: boolean;
267
- readonly isLive: boolean;
268
-
269
- // Scope getters
270
- readonly jurisdiction: Jurisdiction | undefined;
271
- readonly actividadVulnerable: CodigoActividad | undefined;
272
- readonly scope: Readonly<SDKScope>;
273
- readonly isScoped: boolean;
274
- readonly isMexico: boolean;
275
- readonly isUnitedStates: boolean;
276
- readonly isActividadVulnerable: boolean;
277
-
278
- /**
279
- * Fetches current session info from the API (/auth/me).
280
- * Only available in cookie auth mode.
281
- *
282
- * @example Basic usage (session can be null)
283
- * ```typescript
284
- * const result = await sdk.session();
285
- * if (result.isAuthenticated) {
286
- * console.log("User:", result.session.userId);
287
- * }
288
- * ```
289
- *
290
- * @example With returnTo (strongly typed - redirectUrl is present when not authenticated)
291
- * ```typescript
292
- * const result = await sdk.session({ returnTo: "https://..." });
293
- * if (result.redirectUrl) {
294
- * redirect(result.redirectUrl);
295
- * }
296
- * // result.session is guaranteed here (TypeScript knows it's not null)
297
- * console.log("User:", result.session.userId);
298
- * ```
299
- */
300
- session(
301
- options: SDKSessionOptionsWithReturnTo
302
- ): Promise<SessionResultWithRedirect>;
303
- session(options?: SDKSessionOptions): Promise<SessionResultWithoutRedirect>;
304
- }
@@ -1,187 +0,0 @@
1
- /**
2
- * Environment utilities
3
- *
4
- * Handles environment validation and base URL resolution.
5
- * API keys are generated via WorkOS and do not encode the environment.
6
- * The environment is user-specified and validated by the API.
7
- */
8
-
9
- import { z } from "zod";
10
-
11
- // ===========================
12
- // Types
13
- // ===========================
14
-
15
- /**
16
- * SDK environment schema
17
- */
18
- export const environmentSchema = z.enum(["test", "live"]);
19
-
20
- /**
21
- * SDK environment type
22
- */
23
- export type Environment = z.infer<typeof environmentSchema>;
24
-
25
- /**
26
- * SDK environment configuration
27
- */
28
- export interface SDKEnvironmentConfig {
29
- /**
30
- * The environment to operate in.
31
- * - "test": Uses test data, no real regulatory submissions
32
- * - "live": Uses production data, real regulatory submissions
33
- */
34
- environment: Environment;
35
-
36
- /**
37
- * Optional custom base URL (overrides default).
38
- * Useful for local development or custom deployments.
39
- */
40
- baseUrl?: string;
41
- }
42
-
43
- // ===========================
44
- // Constants
45
- // ===========================
46
-
47
- /**
48
- * Default production API base URL.
49
- * Both test and live environments use the same server.
50
- * Environment isolation is handled via the X-Environment header.
51
- */
52
- export const DEFAULT_BASE_URL = "https://api.artu.ai";
53
-
54
- // ===========================
55
- // Functions
56
- // ===========================
57
-
58
- /**
59
- * Validates that the environment is valid
60
- *
61
- * @param env - Environment string to validate
62
- * @returns Validated environment
63
- * @throws Error if environment is invalid
64
- *
65
- * @example
66
- * ```typescript
67
- * const env = validateEnvironment("test"); // "test"
68
- * validateEnvironment("staging"); // throws: Invalid environment
69
- * ```
70
- */
71
- export function validateEnvironment(env: string): Environment {
72
- const result = environmentSchema.safeParse(env);
73
- if (!result.success) {
74
- throw new Error(`Invalid environment: "${env}". Must be "test" or "live".`);
75
- }
76
- return result.data;
77
- }
78
-
79
- /**
80
- * Checks if a string is a valid environment
81
- *
82
- * @param env - Environment string to check
83
- * @returns True if valid environment
84
- *
85
- * @example
86
- * ```typescript
87
- * isValidEnvironment("test"); // true
88
- * isValidEnvironment("staging"); // false
89
- * ```
90
- */
91
- export function isValidEnvironment(env: string): env is Environment {
92
- return environmentSchema.safeParse(env).success;
93
- }
94
-
95
- /**
96
- * Gets the default base URL.
97
- * Both test and live environments use the same server.
98
- *
99
- * @returns Default production base URL
100
- *
101
- * @example
102
- * ```typescript
103
- * getDefaultBaseUrl(); // "https://api.artu.ai"
104
- * ```
105
- */
106
- export function getDefaultBaseUrl(): string {
107
- return DEFAULT_BASE_URL;
108
- }
109
-
110
- /**
111
- * Resolves the base URL - uses custom if provided, falls back to env var, then default
112
- *
113
- * Priority order:
114
- * 1. Explicit baseUrl option
115
- * 2. ARTU_BASE_URL environment variable
116
- * 3. Default production URL
117
- *
118
- * @param config - SDK environment configuration
119
- * @returns Resolved base URL
120
- *
121
- * @example
122
- * ```typescript
123
- * resolveBaseUrl({ environment: "test" });
124
- * // "https://api.artu.ai" (or ARTU_BASE_URL if set)
125
- *
126
- * resolveBaseUrl({ environment: "test", baseUrl: "http://localhost:3001" });
127
- * // "http://localhost:3001"
128
- * ```
129
- */
130
- export function resolveBaseUrl(config: SDKEnvironmentConfig): string {
131
- // 1. Explicit baseUrl takes priority
132
- if (config.baseUrl) {
133
- // Normalize: remove trailing slash
134
- return config.baseUrl.replace(/\/$/, "");
135
- }
136
-
137
- // 2. Fall back to ARTU_BASE_URL environment variable
138
- const envBaseUrl = process.env.ARTU_BASE_URL;
139
- if (envBaseUrl) {
140
- return envBaseUrl.replace(/\/$/, "");
141
- }
142
-
143
- // 3. Default to production URL
144
- return getDefaultBaseUrl();
145
- }
146
-
147
- /**
148
- * Resolves the environment - uses explicit value if provided, falls back to env var
149
- *
150
- * Priority order:
151
- * 1. Explicit environment option
152
- * 2. ARTU_ENVIRONMENT environment variable
153
- * 3. Default to "test"
154
- *
155
- * @param environment - Optional explicit environment
156
- * @returns Resolved environment
157
- *
158
- * @example
159
- * ```typescript
160
- * resolveEnvironment("live"); // "live"
161
- * resolveEnvironment(); // ARTU_ENVIRONMENT or "test"
162
- * ```
163
- */
164
- export function resolveEnvironment(environment?: string): Environment {
165
- // 1. Explicit environment takes priority
166
- if (environment) {
167
- return validateEnvironment(environment);
168
- }
169
-
170
- // 2. Fall back to ARTU_ENVIRONMENT environment variable
171
- const envEnvironment = process.env.ARTU_ENVIRONMENT;
172
- if (envEnvironment) {
173
- return validateEnvironment(envEnvironment);
174
- }
175
-
176
- // 3. Default to test
177
- return "test";
178
- }
179
-
180
- /**
181
- * Resolves the organization ID from environment variable
182
- *
183
- * @returns Organization ID from ARTU_ORGANIZATION_ID or undefined
184
- */
185
- export function resolveOrganizationId(): string | undefined {
186
- return process.env.ARTU_ORGANIZATION_ID;
187
- }