vesant-sdk 1.0.4

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 (50) hide show
  1. package/README.md +247 -0
  2. package/dist/client-CA9Wr_qb.d.ts +1108 -0
  3. package/dist/client-DMNkESa0.d.mts +1108 -0
  4. package/dist/compliance/index.d.mts +543 -0
  5. package/dist/compliance/index.d.ts +543 -0
  6. package/dist/compliance/index.js +2133 -0
  7. package/dist/compliance/index.js.map +1 -0
  8. package/dist/compliance/index.mjs +2130 -0
  9. package/dist/compliance/index.mjs.map +1 -0
  10. package/dist/geolocation/index.d.mts +73 -0
  11. package/dist/geolocation/index.d.ts +73 -0
  12. package/dist/geolocation/index.js +1100 -0
  13. package/dist/geolocation/index.js.map +1 -0
  14. package/dist/geolocation/index.mjs +1094 -0
  15. package/dist/geolocation/index.mjs.map +1 -0
  16. package/dist/index.d.mts +50 -0
  17. package/dist/index.d.ts +50 -0
  18. package/dist/index.js +2968 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/index.mjs +2948 -0
  21. package/dist/index.mjs.map +1 -0
  22. package/dist/kyc/core.d.mts +3 -0
  23. package/dist/kyc/core.d.ts +3 -0
  24. package/dist/kyc/core.js +773 -0
  25. package/dist/kyc/core.js.map +1 -0
  26. package/dist/kyc/core.mjs +771 -0
  27. package/dist/kyc/core.mjs.map +1 -0
  28. package/dist/kyc/index.d.mts +734 -0
  29. package/dist/kyc/index.d.ts +734 -0
  30. package/dist/kyc/index.js +773 -0
  31. package/dist/kyc/index.js.map +1 -0
  32. package/dist/kyc/index.mjs +771 -0
  33. package/dist/kyc/index.mjs.map +1 -0
  34. package/dist/react.d.mts +487 -0
  35. package/dist/react.d.ts +487 -0
  36. package/dist/react.js +1122 -0
  37. package/dist/react.js.map +1 -0
  38. package/dist/react.mjs +1102 -0
  39. package/dist/react.mjs.map +1 -0
  40. package/dist/risk-profile/index.d.mts +228 -0
  41. package/dist/risk-profile/index.d.ts +228 -0
  42. package/dist/risk-profile/index.js +548 -0
  43. package/dist/risk-profile/index.js.map +1 -0
  44. package/dist/risk-profile/index.mjs +546 -0
  45. package/dist/risk-profile/index.mjs.map +1 -0
  46. package/dist/types-Bnsnejor.d.mts +150 -0
  47. package/dist/types-Bnsnejor.d.ts +150 -0
  48. package/dist/types-CFupjwi8.d.ts +213 -0
  49. package/dist/types-CqOLbaXk.d.mts +213 -0
  50. package/package.json +94 -0
@@ -0,0 +1,771 @@
1
+ // src/core/errors.ts
2
+ var CGSError = class _CGSError extends Error {
3
+ constructor(message, code, statusCode, details) {
4
+ super(message);
5
+ this.code = code;
6
+ this.statusCode = statusCode;
7
+ this.details = details;
8
+ this.name = "CGSError";
9
+ Object.setPrototypeOf(this, _CGSError.prototype);
10
+ }
11
+ };
12
+ var NetworkError = class _NetworkError extends CGSError {
13
+ constructor(message, originalError) {
14
+ super(message, "NETWORK_ERROR", void 0, { originalError });
15
+ this.originalError = originalError;
16
+ this.name = "NetworkError";
17
+ Object.setPrototypeOf(this, _NetworkError.prototype);
18
+ }
19
+ };
20
+ var ServiceUnavailableError = class _ServiceUnavailableError extends CGSError {
21
+ constructor(service) {
22
+ super(`${service} is unavailable`, "SERVICE_UNAVAILABLE", 503, { service });
23
+ this.name = "ServiceUnavailableError";
24
+ Object.setPrototypeOf(this, _ServiceUnavailableError.prototype);
25
+ }
26
+ };
27
+ var AuthenticationError = class _AuthenticationError extends CGSError {
28
+ constructor(message = "Authentication failed") {
29
+ super(message, "AUTHENTICATION_ERROR", 401);
30
+ this.name = "AuthenticationError";
31
+ Object.setPrototypeOf(this, _AuthenticationError.prototype);
32
+ }
33
+ };
34
+ var RateLimitError = class _RateLimitError extends CGSError {
35
+ constructor(retryAfter) {
36
+ super("Rate limit exceeded", "RATE_LIMIT_EXCEEDED", 429, { retryAfter });
37
+ this.retryAfter = retryAfter;
38
+ this.name = "RateLimitError";
39
+ Object.setPrototypeOf(this, _RateLimitError.prototype);
40
+ }
41
+ };
42
+ var TimeoutError = class _TimeoutError extends CGSError {
43
+ constructor(timeout) {
44
+ super(`Request timeout after ${timeout}ms`, "TIMEOUT", 408, { timeout });
45
+ this.timeout = timeout;
46
+ this.name = "TimeoutError";
47
+ Object.setPrototypeOf(this, _TimeoutError.prototype);
48
+ }
49
+ };
50
+
51
+ // src/core/client.ts
52
+ var BaseClient = class {
53
+ constructor(config) {
54
+ this.config = {
55
+ baseURL: config.baseURL,
56
+ tenantId: config.tenantId,
57
+ apiKey: config.apiKey || "",
58
+ headers: config.headers || {},
59
+ timeout: config.timeout || 1e4,
60
+ retries: config.retries || 3,
61
+ debug: config.debug || false
62
+ };
63
+ }
64
+ /**
65
+ * Make an HTTP request with timeout and error handling
66
+ */
67
+ async request(endpoint, options = {}, serviceURL) {
68
+ const url = `${serviceURL || this.config.baseURL}${endpoint}`;
69
+ const headers = {
70
+ "Content-Type": "application/json",
71
+ "X-Tenant-ID": this.config.tenantId,
72
+ ...this.config.headers,
73
+ ...options.headers || {}
74
+ };
75
+ if (this.config.apiKey) {
76
+ headers["Authorization"] = `Bearer ${this.config.apiKey}`;
77
+ }
78
+ const controller = new AbortController();
79
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
80
+ try {
81
+ if (this.config.debug) {
82
+ console.log(`[CGS SDK] ${options.method || "GET"} ${url}`, {
83
+ headers,
84
+ body: options.body
85
+ });
86
+ }
87
+ const response = await fetch(url, {
88
+ ...options,
89
+ headers,
90
+ signal: controller.signal
91
+ });
92
+ clearTimeout(timeoutId);
93
+ const data = await response.json();
94
+ if (!response.ok) {
95
+ this.handleErrorResponse(response.status, data);
96
+ }
97
+ if (this.config.debug) {
98
+ console.log(`[CGS SDK] Response:`, data);
99
+ }
100
+ return data;
101
+ } catch (error) {
102
+ clearTimeout(timeoutId);
103
+ if (error instanceof Error) {
104
+ if (error.name === "AbortError") {
105
+ throw new TimeoutError(this.config.timeout);
106
+ }
107
+ if (error instanceof CGSError) {
108
+ throw error;
109
+ }
110
+ }
111
+ throw new NetworkError("Network request failed", error);
112
+ }
113
+ }
114
+ /**
115
+ * Make an HTTP request with retry logic
116
+ */
117
+ async requestWithRetry(endpoint, options = {}, serviceURL, retries = this.config.retries) {
118
+ let lastError;
119
+ for (let attempt = 0; attempt <= retries; attempt++) {
120
+ try {
121
+ return await this.request(endpoint, options, serviceURL);
122
+ } catch (error) {
123
+ lastError = error instanceof Error ? error : new Error("Unknown error");
124
+ if (lastError instanceof CGSError && lastError.statusCode && lastError.statusCode >= 400 && lastError.statusCode < 500) {
125
+ throw lastError;
126
+ }
127
+ if (attempt === retries) {
128
+ break;
129
+ }
130
+ const delay = Math.min(1e3 * Math.pow(2, attempt) + Math.random() * 1e3, 1e4);
131
+ await new Promise((resolve) => setTimeout(resolve, delay));
132
+ if (this.config.debug) {
133
+ console.log(`[CGS SDK] Retry attempt ${attempt + 1}/${retries} after ${delay.toFixed(0)}ms`);
134
+ }
135
+ }
136
+ }
137
+ throw new NetworkError(`Request failed after ${retries} retries`, lastError);
138
+ }
139
+ /**
140
+ * Handle error responses from API
141
+ */
142
+ handleErrorResponse(status, data) {
143
+ const message = data.error || data.message || `HTTP ${status}`;
144
+ switch (status) {
145
+ case 400:
146
+ throw new CGSError(message, "BAD_REQUEST", 400, data);
147
+ case 401:
148
+ throw new AuthenticationError(message);
149
+ case 403:
150
+ throw new CGSError(message, "FORBIDDEN", 403, data);
151
+ case 404:
152
+ throw new CGSError(message, "NOT_FOUND", 404, data);
153
+ case 429:
154
+ const retryAfter = data.retry_after || data.retryAfter;
155
+ throw new RateLimitError(retryAfter);
156
+ case 500:
157
+ case 502:
158
+ case 503:
159
+ case 504:
160
+ throw new ServiceUnavailableError(message);
161
+ default:
162
+ throw new CGSError(message, "UNKNOWN_ERROR", status, data);
163
+ }
164
+ }
165
+ /**
166
+ * Build query string from parameters
167
+ */
168
+ buildQueryString(params) {
169
+ const query = new URLSearchParams();
170
+ Object.entries(params).forEach(([key, value]) => {
171
+ if (value !== void 0 && value !== null) {
172
+ if (Array.isArray(value)) {
173
+ value.forEach((item) => query.append(key, String(item)));
174
+ } else {
175
+ query.append(key, String(value));
176
+ }
177
+ }
178
+ });
179
+ const queryString = query.toString();
180
+ return queryString ? `?${queryString}` : "";
181
+ }
182
+ /**
183
+ * Update client configuration
184
+ */
185
+ updateConfig(config) {
186
+ this.config = {
187
+ ...this.config,
188
+ ...config,
189
+ headers: {
190
+ ...this.config.headers,
191
+ ...config.headers || {}
192
+ }
193
+ };
194
+ }
195
+ /**
196
+ * Get current configuration (readonly)
197
+ */
198
+ getConfig() {
199
+ return { ...this.config };
200
+ }
201
+ /**
202
+ * Health check endpoint
203
+ */
204
+ async healthCheck() {
205
+ return this.request("/api/v1/health");
206
+ }
207
+ };
208
+
209
+ // src/kyc/client.ts
210
+ function addFilterParam(params, key, value) {
211
+ if (value !== void 0) {
212
+ params[key] = Array.isArray(value) ? value.join(",") : value;
213
+ }
214
+ }
215
+ function addSimpleParams(params, source, keys) {
216
+ for (const key of keys) {
217
+ if (source[key] !== void 0) {
218
+ params[key] = source[key];
219
+ }
220
+ }
221
+ }
222
+ var KycClient = class extends BaseClient {
223
+ constructor(config) {
224
+ const baseConfig = {
225
+ baseURL: config.baseURL,
226
+ tenantId: config.tenantId,
227
+ apiKey: config.apiKey,
228
+ headers: config.headers,
229
+ timeout: config.timeout,
230
+ retries: 3,
231
+ // Default retry count for KYC calls
232
+ debug: config.debug
233
+ };
234
+ super(baseConfig);
235
+ this.userId = config.userId;
236
+ this.riskProfileBaseURL = config.riskProfileBaseURL;
237
+ }
238
+ /**
239
+ * Set the user ID for operations requiring user context
240
+ */
241
+ setUserId(userId) {
242
+ this.userId = userId;
243
+ }
244
+ /**
245
+ * Get current user ID
246
+ */
247
+ getUserId() {
248
+ return this.userId;
249
+ }
250
+ /**
251
+ * Build headers including user ID if available
252
+ */
253
+ getUserHeaders() {
254
+ const headers = {};
255
+ if (this.userId) {
256
+ headers["X-User-ID"] = this.userId;
257
+ }
258
+ return headers;
259
+ }
260
+ // ============================================================================
261
+ // Document Verification
262
+ // ============================================================================
263
+ /**
264
+ * Request a KYC submission redirect URL for a user
265
+ *
266
+ * Generates a link that the user can visit to submit their KYC documents.
267
+ *
268
+ * @param request - Request containing the user ID
269
+ * @returns Response containing the redirect link
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * const result = await client.requestKycSubmitLink({
274
+ * user_id: "user_123"
275
+ * });
276
+ *
277
+ * console.log(`Redirect user to: ${result.link}`);
278
+ * ```
279
+ */
280
+ async requestKycSubmitLink(request) {
281
+ return this.requestWithRetry("/api/v1/kyc/request", {
282
+ method: "POST",
283
+ body: JSON.stringify(request),
284
+ headers: this.getUserHeaders()
285
+ });
286
+ }
287
+ /**
288
+ * Check KYC status for a user
289
+ *
290
+ * Returns the current KYC status:
291
+ * - "complete" → KYC verified, show "Continue to Login"
292
+ * - "processing" → Under review, show "Continue to Login"
293
+ * - "failed" / "declined" → Show error + retry option
294
+ * - "pending" / "in_progress" → Keep polling
295
+ *
296
+ * @param request - Request containing user_id and token
297
+ * @returns Response with kyc_status and message (reason)
298
+ *
299
+ * @example
300
+ * ```typescript
301
+ * const result = await client.checkKycStatus({
302
+ * user_id: "user_123",
303
+ * token: "auth_token_xyz"
304
+ * });
305
+ *
306
+ * if (result.kyc_status === 'complete') {
307
+ * // Show "Continue to Login"
308
+ * } else if (result.kyc_status === 'failed' || result.kyc_status === 'declined') {
309
+ * // Show error + retry option
310
+ * } else {
311
+ * // Keep polling
312
+ * }
313
+ * ```
314
+ */
315
+ async checkKycStatus(request) {
316
+ const params = {
317
+ user_id: request.user_id,
318
+ kyc_id: request.kyc_id
319
+ };
320
+ return this.requestWithRetry(
321
+ `/api/v1/kyc/request/status${this.buildQueryString(params)}`,
322
+ {
323
+ method: "GET",
324
+ headers: this.getUserHeaders()
325
+ }
326
+ );
327
+ }
328
+ /**
329
+ * Submit a document verification request with OCR
330
+ *
331
+ * Uses requestWithRetry() for automatic retry on transient failures.
332
+ *
333
+ * @param request - Document verification request with documents and customer info
334
+ * @returns Verification response with status and reference
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * const result = await client.submitVerification({
339
+ * reference: "customer_123",
340
+ * email: "customer@example.com",
341
+ * country: "US",
342
+ * document: {
343
+ * proof: base64EncodedImage,
344
+ * selected_type: ["id_card", "passport"],
345
+ * name: { first_name: "John", last_name: "Doe" },
346
+ * dob: "1990-01-15"
347
+ * },
348
+ * face: {
349
+ * proof: base64EncodedSelfie
350
+ * }
351
+ * });
352
+ *
353
+ * console.log(`Verification submitted: ${result.reference}`);
354
+ * ```
355
+ */
356
+ async submitVerification(request) {
357
+ return this.requestWithRetry("/api/v1/kyc/submit", {
358
+ method: "POST",
359
+ body: JSON.stringify(request),
360
+ headers: this.getUserHeaders()
361
+ });
362
+ }
363
+ /**
364
+ * Get a KYC request by ID
365
+ *
366
+ * @param id - KYC request ID
367
+ * @returns KYC request details including proofs and alerts
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * const kyc = await client.getKycRequest("kyc_abc123");
372
+ * console.log(`Status: ${kyc.status}, ID Verified: ${kyc.id_verified}`);
373
+ * ```
374
+ */
375
+ async getKycRequest(id) {
376
+ return this.request(`/api/v1/kyc/requests/${id}`);
377
+ }
378
+ /**
379
+ * List KYC requests with filters and pagination
380
+ *
381
+ * @param filters - Optional filters (status, search, date range)
382
+ * @param pagination - Optional pagination (page, page_size)
383
+ * @returns Paginated list of KYC requests
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * const requests = await client.listKycRequests(
388
+ * { status: "pending", search: "john" },
389
+ * { page: 1, page_size: 20 }
390
+ * );
391
+ * console.log(`Found ${requests.total} pending requests`);
392
+ * ```
393
+ */
394
+ async listKycRequests(filters, pagination) {
395
+ const params = {};
396
+ if (filters) {
397
+ addFilterParam(params, "status", filters.status);
398
+ addSimpleParams(params, filters, ["search", "fromDate", "toDate", "sortBy", "order"]);
399
+ }
400
+ if (pagination) {
401
+ if (pagination.page) params.page = pagination.page;
402
+ if (pagination.page_size) params.limit = pagination.page_size;
403
+ }
404
+ return this.request(
405
+ `/api/v1/kyc/requests${this.buildQueryString(params)}`,
406
+ { headers: this.getUserHeaders() }
407
+ );
408
+ }
409
+ /**
410
+ * Update KYC request status (accept/decline)
411
+ *
412
+ * @param request - Status update request with reference, status, and reason
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * // Accept a KYC request
417
+ * await client.updateKycStatus({
418
+ * reference: "shufti_ref_123",
419
+ * status: "accepted",
420
+ * reason: "All documents verified successfully"
421
+ * });
422
+ *
423
+ * // Decline a KYC request
424
+ * await client.updateKycStatus({
425
+ * reference: "shufti_ref_456",
426
+ * status: "declined",
427
+ * reason: "Document expired"
428
+ * });
429
+ * ```
430
+ */
431
+ async updateKycStatus(request) {
432
+ await this.request("/api/v1/kyc/status", {
433
+ method: "PUT",
434
+ body: JSON.stringify(request),
435
+ headers: this.getUserHeaders()
436
+ });
437
+ }
438
+ /**
439
+ * Request additional documents from customer
440
+ *
441
+ * @param request - Request with KYC ID and document types needed
442
+ *
443
+ * @example
444
+ * ```typescript
445
+ * await client.requestAdditionalDocuments({
446
+ * id: "kyc_abc123",
447
+ * document_types: ["address", "document_two"],
448
+ * message: "Please provide proof of address and secondary ID"
449
+ * });
450
+ * ```
451
+ */
452
+ async requestAdditionalDocuments(request) {
453
+ await this.request("/api/v1/kyc/requests", {
454
+ method: "PUT",
455
+ body: JSON.stringify(request),
456
+ headers: this.getUserHeaders()
457
+ });
458
+ }
459
+ /**
460
+ * Get downloadable URLs for KYC proofs/documents
461
+ *
462
+ * @param kycId - KYC request ID
463
+ * @returns Array of proof download URLs with expiration
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const proofs = await client.getProofDownloadURLs("kyc_abc123");
468
+ * proofs.forEach(proof => {
469
+ * console.log(`${proof.type}: ${proof.url} (expires: ${proof.expires_at})`);
470
+ * });
471
+ * ```
472
+ */
473
+ async getProofDownloadURLs(kycId) {
474
+ return this.request(
475
+ `/api/v1/kyc/proofs/${kycId}`,
476
+ { headers: this.getUserHeaders() }
477
+ );
478
+ }
479
+ // ============================================================================
480
+ // KYC Overview & Statistics
481
+ // ============================================================================
482
+ /**
483
+ * Get KYC overview statistics
484
+ *
485
+ * @param fromDate - Optional start date (ISO 8601)
486
+ * @param toDate - Optional end date (ISO 8601)
487
+ * @returns KYC statistics including counts by status
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * const overview = await client.getOverview(
492
+ * "2024-01-01T00:00:00Z",
493
+ * "2024-12-31T23:59:59Z"
494
+ * );
495
+ * console.log(`Total: ${overview.total}, Pending: ${overview.pending}`);
496
+ * console.log(`Approved: ${overview.approved}, Rejected: ${overview.rejected}`);
497
+ * ```
498
+ */
499
+ async getOverview(fromDate, toDate) {
500
+ const params = {};
501
+ if (fromDate) params.fromDate = fromDate;
502
+ if (toDate) params.toDate = toDate;
503
+ return this.request(
504
+ `/api/v1/kyc/overview${this.buildQueryString(params)}`
505
+ );
506
+ }
507
+ // ============================================================================
508
+ // Alert Management
509
+ // ============================================================================
510
+ /**
511
+ * Get a KYC alert by ID
512
+ *
513
+ * @param alertId - Alert ID
514
+ * @returns Alert details
515
+ */
516
+ async getAlert(alertId) {
517
+ return this.request(`/api/v1/kyc/alerts/${alertId}`);
518
+ }
519
+ /**
520
+ * List KYC alerts with filters and pagination
521
+ *
522
+ * @param filters - Optional filters (status, risk, alert_type, assigned_for, etc.)
523
+ * @param pagination - Optional pagination (page, page_size)
524
+ * @returns Paginated list of alerts
525
+ *
526
+ * @example
527
+ * ```typescript
528
+ * const alerts = await client.listAlerts(
529
+ * {
530
+ * status: ["pending", "in_progress"],
531
+ * risk: "critical",
532
+ * alert_type: "kyc"
533
+ * },
534
+ * { page: 1, page_size: 20 }
535
+ * );
536
+ * console.log(`Found ${alerts.total} alerts`);
537
+ * ```
538
+ */
539
+ async listAlerts(filters, pagination) {
540
+ const params = {};
541
+ if (filters) {
542
+ addFilterParam(params, "kyc_id", filters.kyc_id);
543
+ addFilterParam(params, "alert_type", filters.alert_type);
544
+ addFilterParam(params, "assigned_for", filters.assigned_for);
545
+ addFilterParam(params, "status", filters.status);
546
+ addFilterParam(params, "risk", filters.risk);
547
+ addSimpleParams(params, filters, ["search", "fromDate", "toDate", "sort_by", "order"]);
548
+ }
549
+ if (pagination) {
550
+ if (pagination.page) params.page = pagination.page;
551
+ if (pagination.page_size) params.limit = pagination.page_size;
552
+ }
553
+ return this.request(
554
+ `/api/v1/kyc/alerts${this.buildQueryString(params)}`
555
+ );
556
+ }
557
+ /**
558
+ * Update a KYC alert
559
+ *
560
+ * @param alertId - Alert ID
561
+ * @param update - Fields to update (status, assigned_for, reason, alert_type)
562
+ *
563
+ * @example
564
+ * ```typescript
565
+ * // Assign an alert
566
+ * await client.updateAlert("alert_123", {
567
+ * assigned_for: "analyst_user_id",
568
+ * status: "in_progress"
569
+ * });
570
+ *
571
+ * // Resolve an alert
572
+ * await client.updateAlert("alert_123", {
573
+ * status: "resolved",
574
+ * reason: "Customer verified via phone call"
575
+ * });
576
+ *
577
+ * // Escalate an alert
578
+ * await client.updateAlert("alert_123", {
579
+ * status: "escalated",
580
+ * assigned_for: "manager_user_id",
581
+ * reason: "Requires senior review - suspicious documents"
582
+ * });
583
+ * ```
584
+ */
585
+ async updateAlert(alertId, update) {
586
+ await this.request(`/api/v1/kyc/alerts/${alertId}`, {
587
+ method: "PUT",
588
+ body: JSON.stringify(update),
589
+ headers: this.getUserHeaders()
590
+ });
591
+ }
592
+ // ============================================================================
593
+ // KYC Preferences
594
+ // ============================================================================
595
+ /**
596
+ * Get KYC preferences for the tenant
597
+ *
598
+ * @returns KYC preferences configuration
599
+ *
600
+ * @example
601
+ * ```typescript
602
+ * const prefs = await client.getPreferences();
603
+ * console.log(`Face verification required: ${prefs.is_face_verification_required}`);
604
+ * console.log(`Required documents: ${prefs.required_document_count}`);
605
+ * ```
606
+ */
607
+ async getPreferences() {
608
+ return this.request("/api/v1/kyc/preferences");
609
+ }
610
+ /**
611
+ * Update KYC preferences for the tenant
612
+ *
613
+ * @param update - Fields to update
614
+ * @returns Updated preferences
615
+ *
616
+ * @example
617
+ * ```typescript
618
+ * await client.updatePreferences({
619
+ * is_face_verification_required: true,
620
+ * is_address_verification_required: true,
621
+ * required_document_count: 2,
622
+ * reasons: [
623
+ * "Documents verified",
624
+ * "Identity confirmed",
625
+ * "Address matched"
626
+ * ]
627
+ * });
628
+ * ```
629
+ */
630
+ async updatePreferences(update) {
631
+ return this.request("/api/v1/kyc/preferences", {
632
+ method: "PUT",
633
+ body: JSON.stringify(update)
634
+ });
635
+ }
636
+ // ============================================================================
637
+ // Customer Profile Management (Risk Profile Service)
638
+ // ============================================================================
639
+ /**
640
+ * Make a request to the Risk Profile Service
641
+ * Uses riskProfileBaseURL if configured, otherwise falls back to baseURL
642
+ */
643
+ async riskProfileRequest(path, options = {}) {
644
+ if (!this.riskProfileBaseURL) {
645
+ throw new Error(
646
+ "Risk Profile Service URL not configured. Please provide riskProfileBaseURL in KycClientConfig."
647
+ );
648
+ }
649
+ const url = `${this.riskProfileBaseURL}${path}`;
650
+ const config = this.getConfig();
651
+ const headers = {
652
+ "Content-Type": "application/json",
653
+ "X-Tenant-ID": config.tenantId,
654
+ ...config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : {},
655
+ ...this.getUserHeaders(),
656
+ ...options.headers
657
+ };
658
+ const response = await fetch(url, {
659
+ ...options,
660
+ headers
661
+ });
662
+ if (!response.ok) {
663
+ const errorData = await response.json().catch(() => ({}));
664
+ return this.handleErrorResponse(response.status, errorData);
665
+ }
666
+ return response.json();
667
+ }
668
+ /**
669
+ * List customer profiles for the tenant
670
+ *
671
+ * @param filters - Optional filters (risk_category, entity_type, status, search, etc.)
672
+ * @param pagination - Optional pagination (limit, offset)
673
+ * @returns Paginated list of customer profiles
674
+ *
675
+ * @example
676
+ * ```typescript
677
+ * const profiles = await client.listCustomerProfiles(
678
+ * { risk_category: 'high', entity_type: 'individual' },
679
+ * { limit: 20, offset: 0 }
680
+ * );
681
+ * console.log(`Found ${profiles.total} profiles`);
682
+ * profiles.profiles.forEach(p => console.log(p.customer_id, p.full_name));
683
+ * ```
684
+ */
685
+ async listCustomerProfiles(filters, pagination) {
686
+ const params = {};
687
+ if (filters) {
688
+ if (filters.risk_category) {
689
+ params.risk_category = Array.isArray(filters.risk_category) ? filters.risk_category : [filters.risk_category];
690
+ }
691
+ if (filters.entity_type) {
692
+ params.entity_type = Array.isArray(filters.entity_type) ? filters.entity_type : [filters.entity_type];
693
+ }
694
+ if (filters.status) {
695
+ params.status = Array.isArray(filters.status) ? filters.status : [filters.status];
696
+ }
697
+ addSimpleParams(params, filters, [
698
+ "search",
699
+ "is_pep",
700
+ "has_sanctions",
701
+ "requires_edd",
702
+ "sort_by",
703
+ "sort_order"
704
+ ]);
705
+ }
706
+ if (pagination) {
707
+ addSimpleParams(params, pagination, ["limit", "offset"]);
708
+ }
709
+ return this.riskProfileRequest(
710
+ `/api/v1/risk-dashboard/profiles${this.buildQueryString(params)}`
711
+ );
712
+ }
713
+ /**
714
+ * Get a customer profile by ID
715
+ *
716
+ * @param profileId - The profile UUID
717
+ * @returns Customer profile details
718
+ *
719
+ * @example
720
+ * ```typescript
721
+ * const profile = await client.getCustomerProfile('uuid-here');
722
+ * console.log(`Customer: ${profile.full_name}, Risk: ${profile.risk_category}`);
723
+ * ```
724
+ */
725
+ async getCustomerProfile(profileId) {
726
+ return this.riskProfileRequest(
727
+ `/api/v1/risk-dashboard/profiles/${profileId}`
728
+ );
729
+ }
730
+ /**
731
+ * Create a new customer profile
732
+ *
733
+ * A customer profile must exist before submitting KYC verification.
734
+ * The customer_id field will be used as the 'reference' in KYC submissions.
735
+ *
736
+ * @param profile - Customer profile data
737
+ * @returns Created customer profile
738
+ *
739
+ * @example
740
+ * ```typescript
741
+ * const profile = await client.createCustomerProfile({
742
+ * customer_id: 'cust_123',
743
+ * entity_type: 'individual',
744
+ * full_name: 'John Doe',
745
+ * email_address: 'john@example.com',
746
+ * country_of_residence: 'US'
747
+ * });
748
+ * console.log(`Created profile: ${profile.id}`);
749
+ *
750
+ * // Now you can submit KYC using the customer_id as reference
751
+ * await client.submitVerification({
752
+ * reference: profile.customer_id, // 'cust_123'
753
+ * email: 'john@example.com',
754
+ * // ... other fields
755
+ * });
756
+ * ```
757
+ */
758
+ async createCustomerProfile(profile) {
759
+ return this.riskProfileRequest("/api/v1/profiles", {
760
+ method: "POST",
761
+ body: JSON.stringify(profile)
762
+ });
763
+ }
764
+ // ============================================================================
765
+ // Utility Methods (inherited from BaseClient: healthCheck, updateConfig, getConfig, buildQueryString)
766
+ // ============================================================================
767
+ };
768
+
769
+ export { KycClient };
770
+ //# sourceMappingURL=core.mjs.map
771
+ //# sourceMappingURL=core.mjs.map