cgs-compliance-sdk 2.0.4 → 2.0.5

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.
@@ -0,0 +1,619 @@
1
+ import { P as PaginationParams } from './types-mQdu71xf.mjs';
2
+
3
+ /**
4
+ * TypeScript type definitions for CGS Geolocation Service API
5
+ *
6
+ * These types match the Go API structures in:
7
+ * - services/geolocation-service/internal/domain/
8
+ * - services/geolocation-service/internal/service/
9
+ * - services/geolocation-service/internal/handler/
10
+ */
11
+
12
+ interface DeviceFingerprintRequest {
13
+ device_id: string;
14
+ user_agent: string;
15
+ platform: string;
16
+ browser?: string;
17
+ browser_version?: string;
18
+ os?: string;
19
+ os_version?: string;
20
+ screen_resolution?: string;
21
+ language?: string;
22
+ timezone?: string;
23
+ }
24
+ interface VerifyIPRequest {
25
+ ip_address: string;
26
+ user_id: string;
27
+ event_type: string;
28
+ device_fingerprint?: DeviceFingerprintRequest;
29
+ }
30
+ interface GeoIPResult {
31
+ country: string;
32
+ country_iso: string;
33
+ city: string;
34
+ region: string;
35
+ postal_code: string;
36
+ latitude: number;
37
+ longitude: number;
38
+ timezone: string;
39
+ is_vpn: boolean;
40
+ is_proxy: boolean;
41
+ is_tor: boolean;
42
+ is_hosting: boolean;
43
+ is_anonymizer: boolean;
44
+ }
45
+ interface JurisdictionConfig {
46
+ id: string;
47
+ tenant_id: string;
48
+ country_iso: string;
49
+ country_name: string;
50
+ status: 'allowed' | 'restricted' | 'blocked' | 'sanctioned';
51
+ risk_level: 'low' | 'medium' | 'high';
52
+ allow_login: boolean;
53
+ allow_registration: boolean;
54
+ allow_transactions: boolean;
55
+ max_transaction_amount?: number;
56
+ require_kyc: boolean;
57
+ require_enhanced_verification: boolean;
58
+ compliance_notes?: string;
59
+ created_at: string;
60
+ updated_at: string;
61
+ }
62
+ interface GeofenceEvaluation {
63
+ matched_rules: string[];
64
+ blocked: boolean;
65
+ should_alert: boolean;
66
+ reasons: string[];
67
+ }
68
+ interface DeviceFingerprint {
69
+ id: string;
70
+ tenant_id: string;
71
+ user_id: string;
72
+ device_id: string;
73
+ user_agent: string;
74
+ platform: string;
75
+ browser?: string;
76
+ browser_version?: string;
77
+ os?: string;
78
+ os_version?: string;
79
+ screen_resolution?: string;
80
+ language?: string;
81
+ timezone?: string;
82
+ ip_address?: string;
83
+ last_ip_address?: string;
84
+ last_location?: string;
85
+ is_trusted: boolean;
86
+ trust_score: number;
87
+ risk_flags?: string;
88
+ first_seen_at: string;
89
+ last_seen_at: string;
90
+ login_count: number;
91
+ location_changes: number;
92
+ }
93
+ interface DeviceTrustResult {
94
+ device: DeviceFingerprint;
95
+ is_new_device: boolean;
96
+ is_trusted: boolean;
97
+ trust_score: number;
98
+ risk_factors: string[];
99
+ recommendations: string[];
100
+ }
101
+ interface LocationVerification {
102
+ ip_address: string;
103
+ location: GeoIPResult;
104
+ is_compliant: boolean;
105
+ is_blocked: boolean;
106
+ risk_level: 'low' | 'medium' | 'high' | 'critical';
107
+ risk_score: number;
108
+ risk_reasons: string[];
109
+ jurisdiction?: JurisdictionConfig;
110
+ geofence_evaluation?: GeofenceEvaluation;
111
+ device_trust?: DeviceTrustResult;
112
+ record_id: string;
113
+ }
114
+ interface ComplianceCheckResponse {
115
+ jurisdiction?: JurisdictionConfig;
116
+ is_compliant: boolean;
117
+ message: string;
118
+ }
119
+ type AlertStatus = 'active' | 'under_review' | 'resolved' | 'false_positive' | 'blocked';
120
+ type AlertSeverity = 'low' | 'medium' | 'high' | 'critical';
121
+ type AlertType = 'high_risk_login' | 'sanctioned_region' | 'geofence_violation' | 'tor_detected' | 'vpn_detected' | 'proxy_detected' | 'anonymization_detected' | 'anonymization_tool_detected' | 'high_risk_country' | 'impossible_travel' | 'device_fingerprint_mismatch';
122
+ interface GeolocationAlert {
123
+ id: string;
124
+ tenant_id: string;
125
+ user_id: string;
126
+ alert_type: AlertType;
127
+ severity: AlertSeverity;
128
+ status: AlertStatus;
129
+ ip_address?: string;
130
+ location?: string;
131
+ risk_score?: number;
132
+ risk_factors?: string;
133
+ geolocation_record_id?: string;
134
+ assigned_to?: string;
135
+ resolution?: string;
136
+ notes?: string;
137
+ resolved_by?: string;
138
+ resolved_at?: string;
139
+ created_at: string;
140
+ updated_at: string;
141
+ }
142
+ interface AlertFilters {
143
+ status?: AlertStatus;
144
+ severity?: AlertSeverity;
145
+ alert_type?: AlertType;
146
+ user_id?: string;
147
+ assigned_to?: string;
148
+ start_date?: string;
149
+ end_date?: string;
150
+ }
151
+ interface AlertListResponse {
152
+ alerts: GeolocationAlert[];
153
+ total: number;
154
+ page: number;
155
+ page_size: number;
156
+ }
157
+ interface DashboardMetrics {
158
+ total_alerts: number;
159
+ active_alerts: number;
160
+ critical_alerts: number;
161
+ high_alerts: number;
162
+ alerts_by_status: Record<AlertStatus, number>;
163
+ alerts_by_severity: Record<AlertSeverity, number>;
164
+ alerts_by_type: Record<string, number>;
165
+ top_risk_users: Array<{
166
+ user_id: string;
167
+ alert_count: number;
168
+ max_risk_score: number;
169
+ }>;
170
+ top_risk_countries: Array<{
171
+ country: string;
172
+ alert_count: number;
173
+ }>;
174
+ }
175
+ interface CreateJurisdictionRequest {
176
+ country_iso: string;
177
+ country_name: string;
178
+ status: 'allowed' | 'restricted' | 'blocked' | 'sanctioned';
179
+ risk_level: 'low' | 'medium' | 'high';
180
+ allow_login: boolean;
181
+ allow_registration: boolean;
182
+ allow_transactions: boolean;
183
+ max_transaction_amount?: number;
184
+ require_kyc: boolean;
185
+ require_enhanced_verification: boolean;
186
+ compliance_notes?: string;
187
+ }
188
+ interface UpdateJurisdictionRequest extends Partial<CreateJurisdictionRequest> {
189
+ }
190
+ type GeofenceRuleType = 'block_list' | 'allow_list' | 'risk_threshold';
191
+ type GeofenceAction = 'block' | 'alert' | 'allow_with_warning';
192
+ interface GeofenceRule {
193
+ id: string;
194
+ tenant_id: string;
195
+ name: string;
196
+ description?: string;
197
+ rule_type: GeofenceRuleType;
198
+ action: GeofenceAction;
199
+ priority: number;
200
+ countries?: string;
201
+ cities?: string;
202
+ latitude?: number;
203
+ longitude?: number;
204
+ radius_km?: number;
205
+ risk_threshold?: number;
206
+ event_types?: string;
207
+ is_active: boolean;
208
+ created_by: string;
209
+ created_at: string;
210
+ updated_at: string;
211
+ }
212
+ interface CreateGeofenceRuleRequest {
213
+ name: string;
214
+ description?: string;
215
+ rule_type: GeofenceRuleType;
216
+ action: GeofenceAction;
217
+ priority?: number;
218
+ countries?: string[];
219
+ cities?: string[];
220
+ latitude?: number;
221
+ longitude?: number;
222
+ radius_km?: number;
223
+ risk_threshold?: number;
224
+ event_types?: string[];
225
+ is_active?: boolean;
226
+ }
227
+ interface UpdateGeofenceRuleRequest extends Partial<CreateGeofenceRuleRequest> {
228
+ }
229
+ interface UpdateDeviceTrustRequest {
230
+ device_id: string;
231
+ action: 'trust' | 'untrust';
232
+ }
233
+ interface GeolocationRecord {
234
+ id: string;
235
+ tenant_id: string;
236
+ user_id: string;
237
+ ip_address: string;
238
+ event_type: string;
239
+ country: string;
240
+ country_iso: string;
241
+ city: string;
242
+ region: string;
243
+ postal_code?: string;
244
+ latitude: number;
245
+ longitude: number;
246
+ timezone?: string;
247
+ is_vpn: boolean;
248
+ is_proxy: boolean;
249
+ is_tor: boolean;
250
+ is_hosting: boolean;
251
+ is_anonymizer: boolean;
252
+ risk_score: number;
253
+ risk_level: string;
254
+ provider: string;
255
+ provider_response?: string;
256
+ created_at: string;
257
+ }
258
+ interface APIError {
259
+ error: string;
260
+ message?: string;
261
+ details?: Record<string, unknown>;
262
+ }
263
+ interface GeolocationClientConfig {
264
+ /** Base URL of the API Gateway (e.g., "https://api.example.com") */
265
+ baseURL: string;
266
+ /** Tenant ID for multi-tenancy */
267
+ tenantId: string;
268
+ /** API key or JWT token for authentication */
269
+ apiKey?: string;
270
+ /** Custom headers to include in every request */
271
+ headers?: Record<string, string>;
272
+ /** Request timeout in milliseconds (default: 10000) */
273
+ timeout?: number;
274
+ /** Enable debug logging */
275
+ debug?: boolean;
276
+ }
277
+ interface UseGeolocationOptions {
278
+ /** Auto-detect and verify user's IP on mount */
279
+ autoVerify?: boolean;
280
+ /** Event type for verification */
281
+ eventType?: string;
282
+ /** Include device fingerprint in verification */
283
+ includeDeviceFingerprint?: boolean;
284
+ }
285
+ interface UseGeolocationResult {
286
+ /** Current verification result */
287
+ verification: LocationVerification | null;
288
+ /** Loading state */
289
+ loading: boolean;
290
+ /** Error state */
291
+ error: Error | null;
292
+ /** Verify an IP address */
293
+ verifyIP: (request: VerifyIPRequest) => Promise<LocationVerification>;
294
+ /** Check compliance for a country */
295
+ checkCompliance: (countryISO: string) => Promise<ComplianceCheckResponse>;
296
+ /** Refresh verification */
297
+ refresh: () => Promise<void>;
298
+ }
299
+ interface UseAlertsOptions {
300
+ /** Auto-fetch alerts on mount */
301
+ autoFetch?: boolean;
302
+ /** Initial filters */
303
+ filters?: AlertFilters;
304
+ /** Pagination settings */
305
+ pagination?: PaginationParams;
306
+ /** Poll interval in milliseconds (0 = no polling) */
307
+ pollInterval?: number;
308
+ }
309
+ interface UseAlertsResult {
310
+ /** List of alerts */
311
+ alerts: GeolocationAlert[];
312
+ /** Total count */
313
+ total: number;
314
+ /** Loading state */
315
+ loading: boolean;
316
+ /** Error state */
317
+ error: Error | null;
318
+ /** Fetch alerts with filters */
319
+ fetchAlerts: (filters?: AlertFilters, pagination?: PaginationParams) => Promise<void>;
320
+ /** Update alert status */
321
+ updateStatus: (alertId: string, status: AlertStatus) => Promise<void>;
322
+ /** Assign alert */
323
+ assignAlert: (alertId: string, assignedTo: string) => Promise<void>;
324
+ /** Resolve alert */
325
+ resolveAlert: (alertId: string, resolution: string, notes?: string) => Promise<void>;
326
+ /** Dismiss alert as false positive */
327
+ dismissAlert: (alertId: string, notes?: string) => Promise<void>;
328
+ /** Refresh alerts */
329
+ refresh: () => Promise<void>;
330
+ }
331
+
332
+ /**
333
+ * GeolocationClient - TypeScript SDK for CGS Geolocation & Compliance Service
334
+ *
335
+ * Provides type-safe methods to interact with the geolocation service API.
336
+ */
337
+
338
+ declare class GeolocationClient {
339
+ private config;
340
+ constructor(config: GeolocationClientConfig);
341
+ private request;
342
+ private buildQueryString;
343
+ /**
344
+ * Verify an IP address and check compliance
345
+ *
346
+ * @param request - Verification request with IP, user ID, event type, and optional device fingerprint
347
+ * @returns Location verification result with risk assessment
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * const result = await client.verifyIP({
352
+ * ip_address: "8.8.8.8",
353
+ * user_id: "user_123",
354
+ * event_type: "login",
355
+ * device_fingerprint: {
356
+ * device_id: "device_abc",
357
+ * user_agent: navigator.userAgent,
358
+ * platform: "web"
359
+ * }
360
+ * });
361
+ *
362
+ * if (result.is_blocked) {
363
+ * console.log("Access blocked:", result.risk_reasons);
364
+ * }
365
+ * ```
366
+ */
367
+ verifyIP(request: VerifyIPRequest): Promise<LocationVerification>;
368
+ /**
369
+ * Check compliance for a specific country
370
+ *
371
+ * @param countryISO - ISO 3166-1 alpha-2 country code (e.g., "US", "GB")
372
+ * @returns Jurisdiction configuration and compliance status
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * const compliance = await client.checkCompliance("KP"); // North Korea
377
+ * if (!compliance.is_compliant) {
378
+ * console.log("Country is not allowed:", compliance.jurisdiction?.status);
379
+ * }
380
+ * ```
381
+ */
382
+ checkCompliance(countryISO: string): Promise<ComplianceCheckResponse>;
383
+ /**
384
+ * Get location history for a user
385
+ *
386
+ * @param userId - User ID to retrieve history for
387
+ * @param limit - Maximum number of records to return (default: 100)
388
+ * @returns Array of geolocation records
389
+ */
390
+ getUserLocationHistory(userId: string, limit?: number): Promise<GeolocationRecord[]>;
391
+ /**
392
+ * Get a specific alert by ID
393
+ *
394
+ * @param alertId - Alert ID
395
+ * @returns Alert details
396
+ */
397
+ getAlert(alertId: string): Promise<GeolocationAlert>;
398
+ /**
399
+ * List alerts with filters and pagination
400
+ *
401
+ * @param filters - Optional filters (status, severity, type, user, dates)
402
+ * @param pagination - Optional pagination (page, page_size)
403
+ * @returns Paginated list of alerts
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * const alerts = await client.listAlerts(
408
+ * { status: "active", severity: "critical" },
409
+ * { page: 1, page_size: 20 }
410
+ * );
411
+ * console.log(`Found ${alerts.total} critical alerts`);
412
+ * ```
413
+ */
414
+ listAlerts(filters?: AlertFilters, pagination?: PaginationParams): Promise<AlertListResponse>;
415
+ /**
416
+ * Update alert status
417
+ *
418
+ * @param alertId - Alert ID
419
+ * @param status - New status
420
+ */
421
+ updateAlertStatus(alertId: string, status: AlertStatus): Promise<void>;
422
+ /**
423
+ * Assign an alert to an analyst
424
+ *
425
+ * @param alertId - Alert ID
426
+ * @param assignedTo - User ID to assign to
427
+ */
428
+ assignAlert(alertId: string, assignedTo: string): Promise<void>;
429
+ /**
430
+ * Resolve an alert
431
+ *
432
+ * @param alertId - Alert ID
433
+ * @param resolution - Resolution type
434
+ * @param notes - Optional notes
435
+ */
436
+ resolveAlert(alertId: string, resolution: string, notes?: string): Promise<void>;
437
+ /**
438
+ * Dismiss an alert as false positive
439
+ *
440
+ * @param alertId - Alert ID
441
+ * @param notes - Optional notes explaining why it's a false positive
442
+ */
443
+ dismissAlert(alertId: string, notes?: string): Promise<void>;
444
+ /**
445
+ * Escalate an alert to higher severity or different assignee
446
+ *
447
+ * @param alertId - Alert ID
448
+ * @param assignedTo - New assignee user ID
449
+ * @param severity - New severity level
450
+ * @param notes - Escalation notes
451
+ */
452
+ escalateAlert(alertId: string, assignedTo: string, severity: string, notes: string): Promise<void>;
453
+ /**
454
+ * Block an alert (mark as blocked)
455
+ *
456
+ * @param alertId - Alert ID
457
+ * @param notes - Optional notes
458
+ */
459
+ blockAlert(alertId: string, notes?: string): Promise<void>;
460
+ /**
461
+ * Get dashboard metrics
462
+ *
463
+ * @param timeRangeHours - Time range in hours (default: 24)
464
+ * @returns Dashboard metrics and statistics
465
+ *
466
+ * @example
467
+ * ```typescript
468
+ * const metrics = await client.getDashboardMetrics(168); // Last 7 days
469
+ * console.log(`${metrics.critical_alerts} critical alerts in last week`);
470
+ * ```
471
+ */
472
+ getDashboardMetrics(timeRangeHours?: number): Promise<DashboardMetrics>;
473
+ /**
474
+ * List all jurisdiction configurations
475
+ *
476
+ * @returns Array of jurisdiction configurations
477
+ */
478
+ listJurisdictions(): Promise<JurisdictionConfig[]>;
479
+ /**
480
+ * Get a jurisdiction configuration by ID
481
+ *
482
+ * @param jurisdictionId - Jurisdiction ID
483
+ * @returns Jurisdiction configuration
484
+ */
485
+ getJurisdiction(jurisdictionId: string): Promise<JurisdictionConfig>;
486
+ /**
487
+ * Create a new jurisdiction configuration
488
+ *
489
+ * @param request - Jurisdiction configuration data
490
+ * @returns Created jurisdiction
491
+ *
492
+ * @example
493
+ * ```typescript
494
+ * const jurisdiction = await client.createJurisdiction({
495
+ * country_iso: "US",
496
+ * country_name: "United States",
497
+ * status: "allowed",
498
+ * risk_level: "low",
499
+ * allow_login: true,
500
+ * allow_registration: true,
501
+ * allow_transactions: true,
502
+ * require_kyc: false,
503
+ * require_enhanced_verification: false
504
+ * });
505
+ * ```
506
+ */
507
+ createJurisdiction(request: CreateJurisdictionRequest): Promise<JurisdictionConfig>;
508
+ /**
509
+ * Update a jurisdiction configuration
510
+ *
511
+ * @param jurisdictionId - Jurisdiction ID
512
+ * @param request - Updated fields
513
+ * @returns Updated jurisdiction
514
+ */
515
+ updateJurisdiction(jurisdictionId: string, request: UpdateJurisdictionRequest): Promise<JurisdictionConfig>;
516
+ /**
517
+ * Delete a jurisdiction configuration
518
+ *
519
+ * @param jurisdictionId - Jurisdiction ID
520
+ */
521
+ deleteJurisdiction(jurisdictionId: string): Promise<void>;
522
+ /**
523
+ * List all geofence rules
524
+ *
525
+ * @returns Array of geofence rules
526
+ */
527
+ listGeofenceRules(): Promise<GeofenceRule[]>;
528
+ /**
529
+ * Get a geofence rule by ID
530
+ *
531
+ * @param ruleId - Geofence rule ID
532
+ * @returns Geofence rule
533
+ */
534
+ getGeofenceRule(ruleId: string): Promise<GeofenceRule>;
535
+ /**
536
+ * Create a new geofence rule
537
+ *
538
+ * @param request - Geofence rule data
539
+ * @returns Created geofence rule
540
+ *
541
+ * @example
542
+ * ```typescript
543
+ * const rule = await client.createGeofenceRule({
544
+ * name: "Block High Risk Countries",
545
+ * rule_type: "block_list",
546
+ * action: "block",
547
+ * countries: ["KP", "IR", "SY"],
548
+ * event_types: ["login", "transaction"],
549
+ * priority: 100
550
+ * });
551
+ * ```
552
+ */
553
+ createGeofenceRule(request: CreateGeofenceRuleRequest): Promise<GeofenceRule>;
554
+ /**
555
+ * Update a geofence rule
556
+ *
557
+ * @param ruleId - Geofence rule ID
558
+ * @param request - Updated fields
559
+ * @returns Updated geofence rule
560
+ */
561
+ updateGeofenceRule(ruleId: string, request: UpdateGeofenceRuleRequest): Promise<GeofenceRule>;
562
+ /**
563
+ * Delete a geofence rule
564
+ *
565
+ * @param ruleId - Geofence rule ID
566
+ */
567
+ deleteGeofenceRule(ruleId: string): Promise<void>;
568
+ /**
569
+ * Get all devices for a user
570
+ *
571
+ * @param userId - User ID
572
+ * @returns Array of device fingerprints
573
+ */
574
+ getUserDevices(userId: string): Promise<DeviceFingerprint[]>;
575
+ /**
576
+ * Get a specific device by device ID
577
+ *
578
+ * @param deviceId - Device ID
579
+ * @returns Device fingerprint
580
+ */
581
+ getDevice(deviceId: string): Promise<DeviceFingerprint>;
582
+ /**
583
+ * Update device trust status
584
+ *
585
+ * @param deviceId - Device ID
586
+ * @param action - "trust" or "untrust"
587
+ *
588
+ * @example
589
+ * ```typescript
590
+ * // Mark a device as trusted
591
+ * await client.updateDeviceTrust("device_abc", "trust");
592
+ *
593
+ * // Mark a device as untrusted
594
+ * await client.updateDeviceTrust("device_xyz", "untrust");
595
+ * ```
596
+ */
597
+ updateDeviceTrust(deviceId: string, action: 'trust' | 'untrust'): Promise<void>;
598
+ /**
599
+ * Check service health
600
+ *
601
+ * @returns Health status object
602
+ */
603
+ healthCheck(): Promise<{
604
+ status: string;
605
+ timestamp: string;
606
+ }>;
607
+ /**
608
+ * Update client configuration
609
+ *
610
+ * @param config - Partial configuration to update
611
+ */
612
+ updateConfig(config: Partial<GeolocationClientConfig>): void;
613
+ /**
614
+ * Get current configuration (readonly)
615
+ */
616
+ getConfig(): Readonly<GeolocationClientConfig>;
617
+ }
618
+
619
+ export { type AlertStatus as A, type ComplianceCheckResponse as C, type DeviceFingerprintRequest as D, GeolocationClient as G, type JurisdictionConfig as J, type LocationVerification as L, type UpdateJurisdictionRequest as U, type VerifyIPRequest as V, type GeoIPResult as a, type GeofenceEvaluation as b, type DeviceFingerprint as c, type DeviceTrustResult as d, type AlertSeverity as e, type AlertType as f, type GeolocationAlert as g, type AlertFilters as h, type AlertListResponse as i, type DashboardMetrics as j, type CreateJurisdictionRequest as k, type GeofenceRuleType as l, type GeofenceAction as m, type GeofenceRule as n, type CreateGeofenceRuleRequest as o, type UpdateGeofenceRuleRequest as p, type UpdateDeviceTrustRequest as q, type GeolocationRecord as r, type APIError as s, type GeolocationClientConfig as t, type UseGeolocationOptions as u, type UseGeolocationResult as v, type UseAlertsOptions as w, type UseAlertsResult as x };