@plyaz/types 1.11.4 → 1.12.0

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 (42) hide show
  1. package/dist/index.cjs +345 -0
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +328 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/payments/currency/index.d.ts +37 -0
  7. package/dist/payments/events/emitter/index.d.ts +1 -0
  8. package/dist/payments/events/emitter/types.d.ts +333 -0
  9. package/dist/payments/events/enums.d.ts +110 -0
  10. package/dist/payments/events/index.d.ts +4 -0
  11. package/dist/payments/events/types.d.ts +151 -0
  12. package/dist/payments/events/unified-event/enums.d.ts +14 -0
  13. package/dist/payments/events/unified-event/index.d.ts +2 -0
  14. package/dist/payments/events/unified-event/types.d.ts +346 -0
  15. package/dist/payments/gateways/index.d.ts +2 -0
  16. package/dist/payments/gateways/provider/index.d.ts +1 -0
  17. package/dist/payments/gateways/provider/types.d.ts +435 -0
  18. package/dist/payments/gateways/routings/enums.d.ts +87 -0
  19. package/dist/payments/gateways/routings/index.d.ts +2 -0
  20. package/dist/payments/gateways/routings/types.d.ts +512 -0
  21. package/dist/payments/index.cjs +351 -0
  22. package/dist/payments/index.cjs.map +1 -0
  23. package/dist/payments/index.d.ts +7 -0
  24. package/dist/payments/index.js +332 -0
  25. package/dist/payments/index.js.map +1 -0
  26. package/dist/payments/provider/adapter/index.d.ts +1 -0
  27. package/dist/payments/provider/adapter/types.d.ts +208 -0
  28. package/dist/payments/provider/core/index.d.ts +1 -0
  29. package/dist/payments/provider/core/types.d.ts +508 -0
  30. package/dist/payments/provider/index.d.ts +4 -0
  31. package/dist/payments/provider/payment-provider/index.d.ts +1 -0
  32. package/dist/payments/provider/payment-provider/types.d.ts +269 -0
  33. package/dist/payments/provider/provider-capability/enums.d.ts +116 -0
  34. package/dist/payments/provider/provider-capability/index.d.ts +1 -0
  35. package/dist/payments/request/enums.d.ts +19 -0
  36. package/dist/payments/request/index.d.ts +2 -0
  37. package/dist/payments/request/types.d.ts +221 -0
  38. package/dist/payments/service/index.d.ts +1 -0
  39. package/dist/payments/service/types.d.ts +48 -0
  40. package/dist/payments/transaction/index.d.ts +1 -0
  41. package/dist/payments/transaction/types.d.ts +120 -0
  42. package/package.json +6 -1
@@ -0,0 +1,512 @@
1
+ import type { CURRENCY } from '../../currency';
2
+ import type { PAYMENTMETHOD, PAYMENTPROVIDERTYPE, TRANSACTIONTYPE, USERTYPE } from '../../provider';
3
+ import type { VolumeTier } from '../provider/types';
4
+ import type { COSTOPTIMIZATIONSTRATEGY, FAILOVERSTRATEGY, LOADBALANCINGSTRATEGY, PERFORMANCEMETRICTYPE, REGULATORYFRAMEWORK, ROUTINGSTRATEGY } from './enums';
5
+ /**
6
+ * Comprehensive payment routing configuration for optimizing
7
+ * payment processing across multiple providers and methods.
8
+ */
9
+ export interface PaymentRoutingConfiguration {
10
+ /** Overall routing strategy */
11
+ strategy: ROUTINGSTRATEGY;
12
+ /** Provider selection rules */
13
+ providerSelection: ProviderSelectionRules;
14
+ /** Cost optimization settings */
15
+ costOptimization: CostOptimizationConfig;
16
+ /** Failover and redundancy configuration */
17
+ failover: FailoverConfiguration;
18
+ /** Geographic routing preferences */
19
+ geographic: GeographicRoutingConfig;
20
+ /** Load balancing configuration */
21
+ loadBalancing: LoadBalancingConfig;
22
+ /** Performance monitoring */
23
+ performance: PerformanceMonitoringConfig;
24
+ /** A/B testing configuration */
25
+ abTesting: ABTestingConfig;
26
+ }
27
+ /**
28
+ * Provider selection rules and criteria.
29
+ */
30
+ export interface ProviderSelectionRules {
31
+ /** Default provider preferences */
32
+ defaultProviders: ProviderPreference[];
33
+ /** Payment method specific preferences */
34
+ methodSpecificProviders: Record<PAYMENTMETHOD, ProviderPreference[]>;
35
+ /** Amount-based provider selection */
36
+ amountBasedSelection: AmountBasedRule[];
37
+ /** Currency-specific provider preferences */
38
+ currencySpecificProviders: Record<CURRENCY, ProviderPreference[]>;
39
+ /** Region-specific provider preferences */
40
+ regionSpecificProviders: Record<string, ProviderPreference[]>;
41
+ /** User type specific preferences */
42
+ userTypeProviders: Record<USERTYPE, ProviderPreference[]>;
43
+ /** Time-based provider selection */
44
+ timeBasedSelection: TimeBasedRule[];
45
+ /** Custom selection rules */
46
+ customRules: CustomSelectionRule[];
47
+ }
48
+ /**
49
+ * Provider preference configuration.
50
+ */
51
+ export interface ProviderPreference {
52
+ /** Provider identifier */
53
+ provider: PAYMENTPROVIDERTYPE;
54
+ /** Weight/priority (higher = preferred) */
55
+ weight: number;
56
+ /** Traffic allocation percentage */
57
+ trafficPercentage: number;
58
+ /** Conditions for using this provider */
59
+ conditions: ProviderCondition[];
60
+ /** Maximum transaction amount for this provider */
61
+ maxAmount?: {
62
+ amount: number;
63
+ currency: CURRENCY;
64
+ };
65
+ /** Minimum transaction amount for this provider */
66
+ minAmount?: {
67
+ amount: number;
68
+ currency: CURRENCY;
69
+ };
70
+ /** Health check requirements */
71
+ healthRequirements: {
72
+ /** Minimum success rate required */
73
+ minSuccessRate: number;
74
+ /** Maximum response time allowed */
75
+ maxResponseTime: number;
76
+ /** Check interval in minutes */
77
+ checkInterval: number;
78
+ };
79
+ }
80
+ /**
81
+ * Provider selection condition.
82
+ */
83
+ export interface ProviderCondition<T = string | number | boolean | string[] | number[]> {
84
+ /** Condition type */
85
+ type: 'currency' | 'amount' | 'region' | 'time' | 'user_type' | 'payment_method' | 'custom';
86
+ /** Condition operator */
87
+ operator: 'equals' | 'not_equals' | 'in' | 'not_in' | 'greater_than' | 'less_than' | 'between';
88
+ /** Condition value(s) */
89
+ value: T;
90
+ /** Whether condition is required */
91
+ required: boolean;
92
+ }
93
+ /**
94
+ * Amount-based provider selection rule.
95
+ */
96
+ export interface AmountBasedRule {
97
+ /** Rule name */
98
+ name: string;
99
+ /** Amount range */
100
+ amountRange: {
101
+ min: {
102
+ amount: number;
103
+ currency: CURRENCY;
104
+ };
105
+ max: {
106
+ amount: number;
107
+ currency: CURRENCY;
108
+ };
109
+ };
110
+ /** Preferred providers for this amount range */
111
+ preferredProviders: ProviderPreference[];
112
+ /** Special handling rules */
113
+ specialHandling?: {
114
+ /** Require additional verification */
115
+ requireVerification: boolean;
116
+ /** Apply additional security checks */
117
+ enhancedSecurity: boolean;
118
+ /** Manual review required */
119
+ manualReview: boolean;
120
+ };
121
+ }
122
+ /**
123
+ * Time-based provider selection rule.
124
+ */
125
+ export interface TimeBasedRule {
126
+ /** Rule name */
127
+ name: string;
128
+ /** Time conditions */
129
+ timeConditions: {
130
+ /** Days of week (0=Sunday, 6=Saturday) */
131
+ daysOfWeek: number[];
132
+ /** Hours of day (0-23) */
133
+ hoursOfDay: number[];
134
+ /** Time zones */
135
+ timeZones: string[];
136
+ };
137
+ /** Provider preferences during these times */
138
+ providerPreferences: ProviderPreference[];
139
+ /** Reason for time-based routing */
140
+ reason: string;
141
+ }
142
+ /**
143
+ * Custom selection rule configuration.
144
+ */
145
+ export interface CustomSelectionRule {
146
+ /** Rule identifier */
147
+ ruleId: string;
148
+ /** Rule name */
149
+ name: string;
150
+ /** Rule description */
151
+ description: string;
152
+ /** Rule conditions */
153
+ conditions: {
154
+ /** JavaScript condition expression */
155
+ expression: string;
156
+ /** Required context variables */
157
+ requiredContext: string[];
158
+ };
159
+ /** Provider selection when rule matches */
160
+ providerSelection: {
161
+ /** Providers to prefer */
162
+ preferred: PAYMENTPROVIDERTYPE[];
163
+ /** Providers to avoid */
164
+ excluded: PAYMENTPROVIDERTYPE[];
165
+ /** Weight adjustments */
166
+ weightAdjustments: Record<PAYMENTPROVIDERTYPE, number>;
167
+ };
168
+ /** Rule priority */
169
+ priority: number;
170
+ /** Rule enabled status */
171
+ enabled: boolean;
172
+ }
173
+ /**
174
+ * Cost optimization configuration.
175
+ */
176
+ export interface CostOptimizationConfig {
177
+ /** Enable cost optimization */
178
+ enabled: boolean;
179
+ /** Optimization strategy */
180
+ strategy: COSTOPTIMIZATIONSTRATEGY;
181
+ /** Cost calculation settings */
182
+ calculation: {
183
+ /** Include network/gas fees */
184
+ includeNetworkFees: boolean;
185
+ /** Include currency conversion costs */
186
+ includeFxCosts: boolean;
187
+ /** Include opportunity costs */
188
+ includeOpportunityCosts: boolean;
189
+ /** Cost update frequency */
190
+ updateFrequency: number;
191
+ };
192
+ /** Fee structure preferences */
193
+ feePreferences: {
194
+ /** Prefer percentage vs fixed fees */
195
+ preferenceType: 'percentage' | 'fixed' | 'hybrid' | 'lowest_total';
196
+ /** Percentage fee weight */
197
+ percentageWeight: number;
198
+ /** Fixed fee weight */
199
+ fixedWeight: number;
200
+ };
201
+ /** Volume-based optimization */
202
+ volumeOptimization: {
203
+ /** Enable volume-based routing */
204
+ enabled: boolean;
205
+ /** Volume tracking window */
206
+ trackingWindow: number;
207
+ /** Volume tiers */
208
+ volumeTiers: VolumeTier[];
209
+ };
210
+ /** Currency conversion optimization */
211
+ currencyOptimization: {
212
+ /** Enable FX optimization */
213
+ enabled: boolean;
214
+ /** FX rate providers */
215
+ rateProviders: string[];
216
+ /** Rate update frequency */
217
+ updateFrequency: number;
218
+ /** Spread tolerance */
219
+ spreadTolerance: number;
220
+ };
221
+ }
222
+ /**
223
+ * Failover configuration for handling provider failures.
224
+ */
225
+ export interface FailoverConfiguration {
226
+ /** Enable automatic failover */
227
+ enabled: boolean;
228
+ /** Failover strategy */
229
+ strategy: FAILOVERSTRATEGY;
230
+ /** Provider priority order for failover */
231
+ providerOrder: PAYMENTPROVIDERTYPE[];
232
+ /** Failure detection settings */
233
+ failureDetection: {
234
+ /** Consecutive failures before failover */
235
+ consecutiveFailureThreshold: number;
236
+ /** Error rate threshold (percentage) */
237
+ errorRateThreshold: number;
238
+ /** Response time threshold (ms) */
239
+ responseTimeThreshold: number;
240
+ /** Health check interval */
241
+ healthCheckInterval: number;
242
+ };
243
+ /** Retry configuration */
244
+ retry: {
245
+ /** Enable retries before failover */
246
+ enabled: boolean;
247
+ /** Maximum retry attempts */
248
+ maxAttempts: number;
249
+ /** Retry delays */
250
+ delays: number[];
251
+ /** Exponential backoff */
252
+ exponentialBackoff: boolean;
253
+ };
254
+ /** Recovery configuration */
255
+ recovery: {
256
+ /** Automatic recovery enabled */
257
+ autoRecovery: boolean;
258
+ /** Recovery check interval */
259
+ recoveryInterval: number;
260
+ /** Successful transactions needed for recovery */
261
+ recoveryThreshold: number;
262
+ /** Gradual traffic restoration */
263
+ gradualRestoration: boolean;
264
+ };
265
+ /** Circuit breaker configuration */
266
+ circuitBreaker: {
267
+ /** Enable circuit breaker */
268
+ enabled: boolean;
269
+ /** Failure threshold to open circuit */
270
+ failureThreshold: number;
271
+ /** Success threshold to close circuit */
272
+ successThreshold: number;
273
+ /** Timeout before retry attempt */
274
+ timeout: number;
275
+ };
276
+ }
277
+ /**
278
+ * Geographic routing configuration.
279
+ */
280
+ export interface GeographicRoutingConfig {
281
+ /** Enable geographic routing */
282
+ enabled: boolean;
283
+ /** Region-specific provider preferences */
284
+ regionPreferences: Record<string, RegionRoutingConfig>;
285
+ /** Cross-border payment handling */
286
+ crossBorder: {
287
+ /** Enable cross-border payments */
288
+ enabled: boolean;
289
+ /** Preferred providers for cross-border */
290
+ preferredProviders: PAYMENTPROVIDERTYPE[];
291
+ /** Additional fees for cross-border */
292
+ additionalFees: {
293
+ percentage: number;
294
+ fixed?: number;
295
+ };
296
+ };
297
+ /** Compliance-based routing */
298
+ compliance: {
299
+ /** Enable compliance routing */
300
+ enabled: boolean;
301
+ /** Compliance rules per region */
302
+ rules: Record<string, ComplianceRule[]>;
303
+ };
304
+ /** Currency zone optimization */
305
+ currencyZones: {
306
+ /** Enable currency zone routing */
307
+ enabled: boolean;
308
+ /** Zone definitions */
309
+ zones: Record<string, {
310
+ currencies: CURRENCY[];
311
+ preferredProviders: PAYMENTPROVIDERTYPE[];
312
+ }>;
313
+ };
314
+ }
315
+ /**
316
+ * Region-specific routing configuration.
317
+ */
318
+ export interface RegionRoutingConfig {
319
+ /** Region identifier */
320
+ regionId: string;
321
+ /** Preferred providers for this region */
322
+ preferredProviders: ProviderPreference[];
323
+ /** Local payment methods */
324
+ localPaymentMethods: PAYMENTMETHOD[];
325
+ /** Regulatory requirements */
326
+ regulations: {
327
+ /** KYC requirements */
328
+ kycRequired: boolean;
329
+ /** Transaction limits */
330
+ transactionLimits: {
331
+ daily: {
332
+ amount: number;
333
+ currency: CURRENCY;
334
+ };
335
+ monthly: {
336
+ amount: number;
337
+ currency: CURRENCY;
338
+ };
339
+ };
340
+ /** Required licenses */
341
+ requiredLicenses: string[];
342
+ };
343
+ /** Performance optimizations */
344
+ optimizations: {
345
+ /** Preferred data centers */
346
+ preferredDataCenters: string[];
347
+ /** CDN endpoints */
348
+ cdnEndpoints: string[];
349
+ /** Caching strategy */
350
+ cachingStrategy: 'aggressive' | 'standard' | 'minimal';
351
+ };
352
+ }
353
+ /**
354
+ * Compliance rule configuration.
355
+ */
356
+ export interface ComplianceRule {
357
+ /** Rule identifier */
358
+ ruleId: string;
359
+ /** Rule description */
360
+ description: string;
361
+ /** Regulatory framework */
362
+ framework: REGULATORYFRAMEWORK;
363
+ /** Rule conditions */
364
+ conditions: {
365
+ /** Transaction types affected */
366
+ transactionTypes: TRANSACTIONTYPE[];
367
+ /** Amount thresholds */
368
+ amountThresholds?: {
369
+ min?: {
370
+ amount: number;
371
+ currency: CURRENCY;
372
+ };
373
+ max?: {
374
+ amount: number;
375
+ currency: CURRENCY;
376
+ };
377
+ };
378
+ /** User types affected */
379
+ userTypes?: USERTYPE[];
380
+ };
381
+ /** Required actions */
382
+ actions: {
383
+ /** Additional verification required */
384
+ verification?: string[];
385
+ /** Documentation required */
386
+ documentation?: string[];
387
+ /** Reporting required */
388
+ reporting?: boolean;
389
+ /** Approval required */
390
+ approval?: boolean;
391
+ };
392
+ /** Enforcement level */
393
+ enforcement: 'mandatory' | 'recommended' | 'optional';
394
+ }
395
+ /**
396
+ * Load balancing configuration.
397
+ */
398
+ export interface LoadBalancingConfig {
399
+ /** Enable load balancing */
400
+ enabled: boolean;
401
+ /** Load balancing strategy */
402
+ strategy: LOADBALANCINGSTRATEGY;
403
+ /** Traffic weights per provider */
404
+ providerWeights: Record<PAYMENTPROVIDERTYPE, number>;
405
+ /** Maximum concurrent connections per provider */
406
+ maxConnections?: Record<PAYMENTPROVIDERTYPE, number>;
407
+ /** Session stickiness settings */
408
+ stickiness?: {
409
+ enabled: boolean;
410
+ /** Duration to stick to the same provider in seconds */
411
+ duration: number;
412
+ /** Key for stickiness (e.g., userId, region, sessionId) */
413
+ key: 'user' | 'region' | 'session' | 'custom';
414
+ };
415
+ /** Auto-rebalance configuration */
416
+ autoRebalance?: {
417
+ enabled: boolean;
418
+ /** Check interval in seconds */
419
+ interval: number;
420
+ /** Rebalance based on performance metrics */
421
+ basedOn: 'latency' | 'success_rate' | 'cost' | 'mixed';
422
+ };
423
+ }
424
+ /**
425
+ * Performance monitoring configuration.
426
+ */
427
+ export interface PerformanceMonitoringConfig {
428
+ /** Enable performance monitoring */
429
+ enabled: boolean;
430
+ /** Metrics to collect */
431
+ metrics: PERFORMANCEMETRICTYPE[];
432
+ /** Data retention period in minutes */
433
+ retentionPeriod: number;
434
+ /** Sampling rate (0–1) */
435
+ samplingRate: number;
436
+ /** Alerting configuration */
437
+ alerting: {
438
+ enabled: boolean;
439
+ /** Error rate threshold to trigger alert (%) */
440
+ errorRateThreshold: number;
441
+ /** Latency threshold in ms */
442
+ latencyThreshold: number;
443
+ /** Success rate threshold (%) */
444
+ successRateThreshold: number;
445
+ /** Minimum sample size for alerts */
446
+ minSampleSize: number;
447
+ };
448
+ /** Integration hooks for monitoring tools */
449
+ integrations?: {
450
+ /** Metrics push to observability stack (e.g., Prometheus, Datadog) */
451
+ metricsSink?: string;
452
+ /** Log forwarding destination */
453
+ logSink?: string;
454
+ };
455
+ }
456
+ /**
457
+ * A/B testing configuration.
458
+ */
459
+ export interface ABTestingConfig {
460
+ /** Enable A/B testing */
461
+ enabled: boolean;
462
+ /** Default experiment ID */
463
+ defaultExperimentId?: string;
464
+ /** A/B test experiments */
465
+ experiments: ABTestExperiment[];
466
+ /** Fallback behavior if test fails */
467
+ fallback: {
468
+ /** Use control strategy if experiment fails */
469
+ useControlOnFailure: boolean;
470
+ /** Log experiment errors */
471
+ logErrors: boolean;
472
+ };
473
+ }
474
+ /**
475
+ * A/B test experiment definition.
476
+ */
477
+ export interface ABTestExperiment {
478
+ /** Unique experiment ID */
479
+ id: string;
480
+ /** Description of experiment */
481
+ description: string;
482
+ /** Traffic allocation */
483
+ allocation: {
484
+ control: number;
485
+ variant: number;
486
+ };
487
+ /** Experiment strategy overrides */
488
+ overrides: {
489
+ /** Routing strategy for variant group */
490
+ strategy?: ROUTINGSTRATEGY;
491
+ /** Preferred provider list */
492
+ preferredProviders?: PAYMENTPROVIDERTYPE[];
493
+ /** Special fee or cost weighting */
494
+ costOptimization?: Partial<CostOptimizationConfig>;
495
+ };
496
+ /** Targeting rules */
497
+ targeting?: {
498
+ /** Regions to include */
499
+ regions?: string[];
500
+ /** User types to include */
501
+ userTypes?: USERTYPE[];
502
+ /** Payment methods to include */
503
+ paymentMethods?: PAYMENTMETHOD[];
504
+ };
505
+ /** Start and end times */
506
+ schedule?: {
507
+ start?: Date;
508
+ end?: Date;
509
+ };
510
+ /** Experiment active status */
511
+ active: boolean;
512
+ }