@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.
- package/dist/index.cjs +345 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +328 -1
- package/dist/index.js.map +1 -1
- package/dist/payments/currency/index.d.ts +37 -0
- package/dist/payments/events/emitter/index.d.ts +1 -0
- package/dist/payments/events/emitter/types.d.ts +333 -0
- package/dist/payments/events/enums.d.ts +110 -0
- package/dist/payments/events/index.d.ts +4 -0
- package/dist/payments/events/types.d.ts +151 -0
- package/dist/payments/events/unified-event/enums.d.ts +14 -0
- package/dist/payments/events/unified-event/index.d.ts +2 -0
- package/dist/payments/events/unified-event/types.d.ts +346 -0
- package/dist/payments/gateways/index.d.ts +2 -0
- package/dist/payments/gateways/provider/index.d.ts +1 -0
- package/dist/payments/gateways/provider/types.d.ts +435 -0
- package/dist/payments/gateways/routings/enums.d.ts +87 -0
- package/dist/payments/gateways/routings/index.d.ts +2 -0
- package/dist/payments/gateways/routings/types.d.ts +512 -0
- package/dist/payments/index.cjs +351 -0
- package/dist/payments/index.cjs.map +1 -0
- package/dist/payments/index.d.ts +7 -0
- package/dist/payments/index.js +332 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/payments/provider/adapter/index.d.ts +1 -0
- package/dist/payments/provider/adapter/types.d.ts +208 -0
- package/dist/payments/provider/core/index.d.ts +1 -0
- package/dist/payments/provider/core/types.d.ts +508 -0
- package/dist/payments/provider/index.d.ts +4 -0
- package/dist/payments/provider/payment-provider/index.d.ts +1 -0
- package/dist/payments/provider/payment-provider/types.d.ts +269 -0
- package/dist/payments/provider/provider-capability/enums.d.ts +116 -0
- package/dist/payments/provider/provider-capability/index.d.ts +1 -0
- package/dist/payments/request/enums.d.ts +19 -0
- package/dist/payments/request/index.d.ts +2 -0
- package/dist/payments/request/types.d.ts +221 -0
- package/dist/payments/service/index.d.ts +1 -0
- package/dist/payments/service/types.d.ts +48 -0
- package/dist/payments/transaction/index.d.ts +1 -0
- package/dist/payments/transaction/types.d.ts +120 -0
- package/package.json +6 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import type { PAYMENTPROVIDERTYPE, PAYMENTSTATUS } from '../../provider';
|
|
2
|
+
import type { PAYMENTEVENTTYPE } from '../enums';
|
|
3
|
+
import type { PaymentEventPayload } from '../types';
|
|
4
|
+
import type { EVENTPROCESSINGSTATUS } from './enums';
|
|
5
|
+
/**
|
|
6
|
+
* Unified provider event interface that normalizes all provider events
|
|
7
|
+
* into a consistent format while preserving original provider data.
|
|
8
|
+
*
|
|
9
|
+
* This system enables:
|
|
10
|
+
* - Consistent event processing across all providers
|
|
11
|
+
* - Provider-specific data preservation for debugging
|
|
12
|
+
* - Configurable event mapping and normalization
|
|
13
|
+
* - Quality metrics for normalization accuracy
|
|
14
|
+
*/
|
|
15
|
+
export interface UnifiedProviderEvent<TRawEvent extends object = {}, TNormalizedData extends PaymentEventPayload = PaymentEventPayload, TProcessingMetadata extends EventProcessingMetadata = EventProcessingMetadata> {
|
|
16
|
+
/** Unique event ID generated by our system */
|
|
17
|
+
id: string;
|
|
18
|
+
/** Provider that sent this event */
|
|
19
|
+
provider: PAYMENTPROVIDERTYPE;
|
|
20
|
+
/** Provider's original event ID for reference */
|
|
21
|
+
providerEventId: string;
|
|
22
|
+
/** Provider's original event type as received */
|
|
23
|
+
providerEventType: string;
|
|
24
|
+
/** Our normalized event type */
|
|
25
|
+
normalizedEventType: PAYMENTEVENTTYPE;
|
|
26
|
+
/** Normalized event data in our standard format */
|
|
27
|
+
normalizedData: TNormalizedData;
|
|
28
|
+
/** Original raw event data from provider (for debugging/audit) */
|
|
29
|
+
rawEventData: TRawEvent;
|
|
30
|
+
/** Processing metadata and quality metrics */
|
|
31
|
+
processingMetadata: TProcessingMetadata;
|
|
32
|
+
/** Timestamp when we received the event from provider */
|
|
33
|
+
receivedAt: Date;
|
|
34
|
+
/** Timestamp when event occurred at provider (if available) */
|
|
35
|
+
providerTimestamp?: Date;
|
|
36
|
+
/** Signature verification result */
|
|
37
|
+
signatureVerified: boolean;
|
|
38
|
+
/** Event processing status */
|
|
39
|
+
processingStatus: EVENTPROCESSINGSTATUS;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Event processing metadata for quality tracking and debugging.
|
|
43
|
+
*/
|
|
44
|
+
export interface EventProcessingMetadata {
|
|
45
|
+
/** Whether event was successfully normalized */
|
|
46
|
+
normalized: boolean;
|
|
47
|
+
/** Confidence level of normalization (0.0 - 1.0) */
|
|
48
|
+
normalizationConfidence: number;
|
|
49
|
+
/** Quality score based on data completeness (0.0 - 1.0) */
|
|
50
|
+
qualityScore: number;
|
|
51
|
+
/** Issues encountered during normalization */
|
|
52
|
+
normalizationIssues: EventNormalizationIssue[];
|
|
53
|
+
/** Whether this event type is fully supported */
|
|
54
|
+
fullySupported: boolean;
|
|
55
|
+
/** Mapping rule version used for normalization */
|
|
56
|
+
mappingRuleVersion: string;
|
|
57
|
+
/** Processing time in milliseconds */
|
|
58
|
+
processingTime: number;
|
|
59
|
+
/** Data extraction results */
|
|
60
|
+
extractionResults: DataExtractionResult[];
|
|
61
|
+
/** Additional processing notes and warnings */
|
|
62
|
+
processingNotes: string[];
|
|
63
|
+
/** Fallback rules applied during processing */
|
|
64
|
+
fallbacksApplied: string[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Normalization issue types for tracking processing problems.
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* Normalization issue types for tracking processing problems.
|
|
71
|
+
*/
|
|
72
|
+
export interface EventNormalizationIssue<TExpected extends object | string | number | boolean | null = {}, TActual extends object | string | number | boolean | null = {}> {
|
|
73
|
+
/** Severity level of the issue */
|
|
74
|
+
severity: 'info' | 'warning' | 'error' | 'critical';
|
|
75
|
+
/** Issue code for programmatic handling */
|
|
76
|
+
code: string;
|
|
77
|
+
/** Human-readable description */
|
|
78
|
+
description: string;
|
|
79
|
+
/** Field or data path where issue occurred */
|
|
80
|
+
fieldPath?: string;
|
|
81
|
+
/** Expected value or format */
|
|
82
|
+
expected?: TExpected;
|
|
83
|
+
/** Actual value received */
|
|
84
|
+
actual?: TActual;
|
|
85
|
+
/** Suggested resolution */
|
|
86
|
+
resolution?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Data extraction result for tracking field extraction success.
|
|
90
|
+
*/
|
|
91
|
+
export interface DataExtractionResult<TValue extends object | string | number | boolean | null = {}> {
|
|
92
|
+
/** Field name being extracted */
|
|
93
|
+
fieldName: string;
|
|
94
|
+
/** Whether extraction was successful */
|
|
95
|
+
success: boolean;
|
|
96
|
+
/** Extracted value */
|
|
97
|
+
value?: TValue;
|
|
98
|
+
/** Data path used for extraction */
|
|
99
|
+
extractionPath: string | string[];
|
|
100
|
+
/** Confidence level of extraction (0.0 - 1.0) */
|
|
101
|
+
confidence: number;
|
|
102
|
+
/** Fallback method used if primary extraction failed */
|
|
103
|
+
fallbackMethod?: string;
|
|
104
|
+
/** Error message if extraction failed */
|
|
105
|
+
error?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Provider event mapping configuration for dynamic event processing.
|
|
109
|
+
* This configuration allows updating event processing rules without code changes.
|
|
110
|
+
*/
|
|
111
|
+
export interface ProviderEventMapping {
|
|
112
|
+
/** Provider this mapping applies to */
|
|
113
|
+
provider: PAYMENTPROVIDERTYPE;
|
|
114
|
+
/** Provider API version this mapping supports */
|
|
115
|
+
providerApiVersion?: string;
|
|
116
|
+
/** Mapping configuration version */
|
|
117
|
+
mappingVersion: string;
|
|
118
|
+
/** Event type mappings from provider to normalized types */
|
|
119
|
+
eventTypeMappings: EventTypeMapping[];
|
|
120
|
+
/** Status mappings from provider to normalized statuses */
|
|
121
|
+
statusMappings: StatusMapping[];
|
|
122
|
+
/** Data extraction rules for converting provider data */
|
|
123
|
+
dataExtractionRules: ProviderDataExtractionRules;
|
|
124
|
+
/** Validation rules for provider events */
|
|
125
|
+
validationRules: ProviderValidationRules;
|
|
126
|
+
/** Default values for missing or invalid data */
|
|
127
|
+
defaultValues: DefaultValueRules;
|
|
128
|
+
/** Special handling rules for edge cases */
|
|
129
|
+
specialHandlingRules: SpecialHandlingRule[];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Event type mapping from provider-specific to normalized events.
|
|
133
|
+
*/
|
|
134
|
+
export interface EventTypeMapping {
|
|
135
|
+
/** Provider's event type */
|
|
136
|
+
providerEventType: string;
|
|
137
|
+
/** Our normalized event type */
|
|
138
|
+
normalizedEventType: PAYMENTEVENTTYPE;
|
|
139
|
+
/** Confidence level of this mapping (0.0 - 1.0) */
|
|
140
|
+
confidence: number;
|
|
141
|
+
/** Whether this mapping is currently active */
|
|
142
|
+
active: boolean;
|
|
143
|
+
/** Additional conditions for this mapping to apply */
|
|
144
|
+
conditions?: MappingCondition[];
|
|
145
|
+
/** Priority if multiple mappings match (higher = more priority) */
|
|
146
|
+
priority: number;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Status mapping from provider-specific to normalized statuses.
|
|
150
|
+
*/
|
|
151
|
+
export interface StatusMapping<TContext extends object = {}> {
|
|
152
|
+
/** Provider's status value */
|
|
153
|
+
providerStatus: string;
|
|
154
|
+
/** Our normalized status */
|
|
155
|
+
normalizedStatus: PAYMENTSTATUS;
|
|
156
|
+
/** Additional context required for this mapping */
|
|
157
|
+
context?: TContext;
|
|
158
|
+
/** Whether this is a terminal status */
|
|
159
|
+
terminal: boolean;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Comprehensive data extraction rules for provider events.
|
|
163
|
+
*/
|
|
164
|
+
export interface ProviderDataExtractionRules {
|
|
165
|
+
/** How to extract transaction ID from provider event */
|
|
166
|
+
transactionId: DataExtractionRule;
|
|
167
|
+
/** How to extract payment amount */
|
|
168
|
+
amount?: DataExtractionRule;
|
|
169
|
+
/** How to extract currency information */
|
|
170
|
+
currency?: DataExtractionRule;
|
|
171
|
+
/** How to extract payment status */
|
|
172
|
+
status?: DataExtractionRule;
|
|
173
|
+
/** How to extract error information */
|
|
174
|
+
error?: DataExtractionRule;
|
|
175
|
+
/** How to extract provider transaction ID */
|
|
176
|
+
providerTransactionId?: DataExtractionRule;
|
|
177
|
+
/** How to extract customer/user information */
|
|
178
|
+
customerId?: DataExtractionRule;
|
|
179
|
+
/** How to extract payment method information */
|
|
180
|
+
paymentMethod?: DataExtractionRule;
|
|
181
|
+
/** How to extract metadata and custom fields */
|
|
182
|
+
metadata?: DataExtractionRule;
|
|
183
|
+
/** Custom extraction rules for provider-specific fields */
|
|
184
|
+
customFields?: Record<string, DataExtractionRule>;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Individual data extraction rule configuration.
|
|
188
|
+
*/
|
|
189
|
+
export interface DataExtractionRule<T extends string | number | boolean | object | null = string | number | boolean | object | null> {
|
|
190
|
+
/** Primary extraction path (JSONPath or dot notation) */
|
|
191
|
+
primaryPath: string | string[];
|
|
192
|
+
/** Fallback extraction paths if primary fails */
|
|
193
|
+
fallbackPaths?: Array<string | string[]>;
|
|
194
|
+
/** Data transformation function to apply */
|
|
195
|
+
transformation?: DataTransformation;
|
|
196
|
+
/** Validation rules for extracted data */
|
|
197
|
+
validation?: DataValidationRule;
|
|
198
|
+
/** Default value if extraction fails */
|
|
199
|
+
defaultValue?: T;
|
|
200
|
+
/** Whether this field is required */
|
|
201
|
+
required: boolean;
|
|
202
|
+
/** Data type expected */
|
|
203
|
+
expectedType: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Data transformation configuration.
|
|
207
|
+
*/
|
|
208
|
+
export interface DataTransformation<TParams extends object = {}> {
|
|
209
|
+
/** Type of transformation to apply */
|
|
210
|
+
type: 'map' | 'format' | 'calculate' | 'normalize' | 'custom';
|
|
211
|
+
/** Transformation parameters */
|
|
212
|
+
parameters: TParams;
|
|
213
|
+
/** Custom transformation function reference */
|
|
214
|
+
customFunction?: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Data validation rule configuration.
|
|
218
|
+
*/
|
|
219
|
+
/**
|
|
220
|
+
* Data validation rule configuration.
|
|
221
|
+
*/
|
|
222
|
+
export interface DataValidationRule<TParams extends object = Record<string, string | number | boolean>> {
|
|
223
|
+
/** Validation type */
|
|
224
|
+
type: 'regex' | 'range' | 'enum' | 'length' | 'custom';
|
|
225
|
+
/** Validation parameters — strongly typed using generics */
|
|
226
|
+
parameters: TParams;
|
|
227
|
+
/** Error message if validation fails */
|
|
228
|
+
errorMessage?: string;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Mapping condition for conditional event type mapping.
|
|
232
|
+
*/
|
|
233
|
+
export interface MappingCondition<TValue = string | number | boolean> {
|
|
234
|
+
/** Field path to check */
|
|
235
|
+
fieldPath: string;
|
|
236
|
+
/** Condition operator */
|
|
237
|
+
operator: 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'exists' | 'not_exists' | 'regex';
|
|
238
|
+
/** Value to compare against */
|
|
239
|
+
value?: TValue;
|
|
240
|
+
/** Whether condition is required or optional */
|
|
241
|
+
required: boolean;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Provider validation rules for incoming events.
|
|
245
|
+
*/
|
|
246
|
+
export interface ProviderValidationRules<TSchema extends object = object> {
|
|
247
|
+
/** Required fields that must be present */
|
|
248
|
+
requiredFields: string[];
|
|
249
|
+
/** Field format validations */
|
|
250
|
+
fieldValidations: Record<string, DataValidationRule>;
|
|
251
|
+
/** Event structure validation schema */
|
|
252
|
+
structureValidation?: TSchema;
|
|
253
|
+
/** Business logic validations */
|
|
254
|
+
businessValidations?: BusinessValidationRule[];
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Business validation rule for provider events.
|
|
258
|
+
*/
|
|
259
|
+
export interface BusinessValidationRule {
|
|
260
|
+
/** Rule identifier */
|
|
261
|
+
ruleId: string;
|
|
262
|
+
/** Rule description */
|
|
263
|
+
description: string;
|
|
264
|
+
/** Validation logic */
|
|
265
|
+
validation: {
|
|
266
|
+
/** Field to validate */
|
|
267
|
+
field: string;
|
|
268
|
+
/** Validation conditions */
|
|
269
|
+
conditions: ValidationCondition[];
|
|
270
|
+
};
|
|
271
|
+
/** Error details if validation fails */
|
|
272
|
+
error: {
|
|
273
|
+
code: string;
|
|
274
|
+
message: string;
|
|
275
|
+
severity: 'warning' | 'error' | 'critical';
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Validation condition for business rules.
|
|
280
|
+
*/
|
|
281
|
+
export interface ValidationCondition<TParams extends object = Record<string, string | number | boolean>> {
|
|
282
|
+
/** Condition type */
|
|
283
|
+
type: 'range' | 'enum' | 'pattern' | 'custom';
|
|
284
|
+
/** Condition parameters */
|
|
285
|
+
parameters: TParams;
|
|
286
|
+
/** Whether condition must pass */
|
|
287
|
+
mustPass: boolean;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Default value rules for missing or invalid data.
|
|
291
|
+
*/
|
|
292
|
+
export interface DefaultValueRules<TField extends string = string, TValue = string | number | boolean> {
|
|
293
|
+
fieldDefaults: Record<TField, TValue>;
|
|
294
|
+
conditionalDefaults: ConditionalDefault<TField, TValue>[];
|
|
295
|
+
generationRules: DefaultGenerationRule<TField>[];
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Conditional default value configuration.
|
|
299
|
+
*/
|
|
300
|
+
export interface ConditionalDefault<TField extends string = string, TValue = string | number | boolean> {
|
|
301
|
+
/** Condition that must be met */
|
|
302
|
+
condition: MappingCondition<TValue>;
|
|
303
|
+
/** Field to set default value for */
|
|
304
|
+
targetField: TField;
|
|
305
|
+
/** Default value to use */
|
|
306
|
+
defaultValue: TValue;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Default value generation rule.
|
|
310
|
+
*/
|
|
311
|
+
export interface DefaultGenerationRule<TField extends string = string, TParams extends object = Record<string, string | number | boolean>> {
|
|
312
|
+
/** Field to generate default for */
|
|
313
|
+
field: TField;
|
|
314
|
+
/** Generation method */
|
|
315
|
+
method: 'uuid' | 'timestamp' | 'calculated' | 'derived' | 'custom';
|
|
316
|
+
/** Generation parameters */
|
|
317
|
+
parameters?: TParams;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Special handling rule for edge cases and provider-specific behavior.
|
|
321
|
+
*/
|
|
322
|
+
export interface SpecialHandlingRule {
|
|
323
|
+
/** Rule identifier */
|
|
324
|
+
ruleId: string;
|
|
325
|
+
/** Rule description */
|
|
326
|
+
description: string;
|
|
327
|
+
/** Conditions that trigger this rule */
|
|
328
|
+
triggers: MappingCondition[];
|
|
329
|
+
/** Actions to take when rule is triggered */
|
|
330
|
+
actions: SpecialHandlingAction[];
|
|
331
|
+
/** Priority of this rule (higher = more priority) */
|
|
332
|
+
priority: number;
|
|
333
|
+
/** Whether rule is currently active */
|
|
334
|
+
active: boolean;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Special handling action configuration.
|
|
338
|
+
*/
|
|
339
|
+
export interface SpecialHandlingAction<TParams extends object = Record<string, string | number | boolean>> {
|
|
340
|
+
/** Action type */
|
|
341
|
+
type: 'modify_data' | 'set_status' | 'add_metadata' | 'trigger_event' | 'log_warning' | 'custom';
|
|
342
|
+
/** Action parameters — strongly typed using generics */
|
|
343
|
+
parameters: TParams;
|
|
344
|
+
/** Whether action is critical */
|
|
345
|
+
critical: boolean;
|
|
346
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|