@vaultsaas/core 0.1.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/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/index.cjs +4314 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +814 -0
- package/dist/index.d.ts +814 -0
- package/dist/index.js +4250 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,814 @@
|
|
|
1
|
+
type VaultEventType = 'payment.completed' | 'payment.failed' | 'payment.pending' | 'payment.requires_action' | 'payment.refunded' | 'payment.partially_refunded' | 'payment.disputed' | 'payment.dispute_resolved' | 'payout.completed' | 'payout.failed';
|
|
2
|
+
interface VaultEvent {
|
|
3
|
+
id: string;
|
|
4
|
+
type: VaultEventType;
|
|
5
|
+
provider: string;
|
|
6
|
+
transactionId?: string;
|
|
7
|
+
providerEventId: string;
|
|
8
|
+
data: Record<string, unknown>;
|
|
9
|
+
rawPayload: unknown;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @description Normalized payment status across all providers.
|
|
15
|
+
* Each adapter maps provider-specific statuses to one of these canonical values.
|
|
16
|
+
*/
|
|
17
|
+
type PaymentStatus = 'completed' | 'pending' | 'requires_action' | 'declined' | 'failed' | 'cancelled' | 'authorized';
|
|
18
|
+
/**
|
|
19
|
+
* @description Payment method input discriminated by `type`. Supports card (token or raw),
|
|
20
|
+
* bank transfer, wallet, PIX, and boleto payment methods.
|
|
21
|
+
*/
|
|
22
|
+
type PaymentMethodInput = {
|
|
23
|
+
type: 'card';
|
|
24
|
+
token: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'card';
|
|
27
|
+
number: string;
|
|
28
|
+
expMonth: number;
|
|
29
|
+
expYear: number;
|
|
30
|
+
cvc: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'bank_transfer';
|
|
33
|
+
bankCode: string;
|
|
34
|
+
accountNumber: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'wallet';
|
|
37
|
+
walletType: string;
|
|
38
|
+
token: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'pix';
|
|
41
|
+
} | {
|
|
42
|
+
type: 'boleto';
|
|
43
|
+
customerDocument: string;
|
|
44
|
+
};
|
|
45
|
+
/** @description Customer billing or shipping address. */
|
|
46
|
+
interface AddressInput {
|
|
47
|
+
line1: string;
|
|
48
|
+
line2?: string;
|
|
49
|
+
city: string;
|
|
50
|
+
state?: string;
|
|
51
|
+
postalCode: string;
|
|
52
|
+
/** ISO 3166-1 alpha-2 country code (e.g. "US", "BR"). */
|
|
53
|
+
country: string;
|
|
54
|
+
}
|
|
55
|
+
/** @description Customer details passed with a charge or authorize request. */
|
|
56
|
+
interface CustomerInput {
|
|
57
|
+
email?: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
phone?: string;
|
|
60
|
+
/** Tax ID or national document number (e.g. CPF in Brazil). */
|
|
61
|
+
document?: string;
|
|
62
|
+
address?: AddressInput;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @description Per-request routing overrides. Force a specific provider or exclude
|
|
66
|
+
* providers from selection.
|
|
67
|
+
*/
|
|
68
|
+
interface RoutingPreference {
|
|
69
|
+
/** Force routing to this provider, bypassing rules. */
|
|
70
|
+
provider?: string;
|
|
71
|
+
/** Provider names to exclude from routing consideration. */
|
|
72
|
+
exclude?: string[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @description Request payload for a one-step charge (immediate capture).
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const request: ChargeRequest = {
|
|
80
|
+
* amount: 5000,
|
|
81
|
+
* currency: 'USD',
|
|
82
|
+
* paymentMethod: { type: 'card', token: 'tok_visa' },
|
|
83
|
+
* idempotencyKey: 'order-123',
|
|
84
|
+
* };
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
interface ChargeRequest {
|
|
88
|
+
/** Amount in the smallest currency unit (e.g. cents for USD). */
|
|
89
|
+
amount: number;
|
|
90
|
+
/** ISO 4217 currency code (e.g. "USD", "BRL"). */
|
|
91
|
+
currency: string;
|
|
92
|
+
paymentMethod: PaymentMethodInput;
|
|
93
|
+
customer?: CustomerInput;
|
|
94
|
+
description?: string;
|
|
95
|
+
/** Arbitrary key-value pairs forwarded to the provider. */
|
|
96
|
+
metadata?: Record<string, string>;
|
|
97
|
+
/** Prevents duplicate charges when retrying the same request. */
|
|
98
|
+
idempotencyKey?: string;
|
|
99
|
+
routing?: RoutingPreference;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @description Request payload for a two-step authorization (hold funds without capture).
|
|
103
|
+
* Identical shape to {@link ChargeRequest}; the client calls `authorize` instead of `charge`.
|
|
104
|
+
*/
|
|
105
|
+
type AuthorizeRequest = ChargeRequest;
|
|
106
|
+
/**
|
|
107
|
+
* @description Request payload to capture a previously authorized transaction.
|
|
108
|
+
*/
|
|
109
|
+
interface CaptureRequest {
|
|
110
|
+
/** The transaction ID returned from a prior `authorize` call. */
|
|
111
|
+
transactionId: string;
|
|
112
|
+
/** Partial capture amount. Omit to capture the full authorized amount. */
|
|
113
|
+
amount?: number;
|
|
114
|
+
idempotencyKey?: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @description Request payload to refund a completed transaction (full or partial).
|
|
118
|
+
*/
|
|
119
|
+
interface RefundRequest {
|
|
120
|
+
/** The transaction ID of the original charge or capture. */
|
|
121
|
+
transactionId: string;
|
|
122
|
+
/** Partial refund amount. Omit to refund the full amount. */
|
|
123
|
+
amount?: number;
|
|
124
|
+
/** Human-readable reason forwarded to the provider. */
|
|
125
|
+
reason?: string;
|
|
126
|
+
idempotencyKey?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @description Request payload to void (cancel) an authorized transaction before capture.
|
|
130
|
+
*/
|
|
131
|
+
interface VoidRequest {
|
|
132
|
+
/** The transaction ID of the authorization to void. */
|
|
133
|
+
transactionId: string;
|
|
134
|
+
idempotencyKey?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @description Normalized result returned by `charge`, `authorize`, and `capture` operations.
|
|
138
|
+
* Provider-specific data is available via `providerMetadata`.
|
|
139
|
+
*/
|
|
140
|
+
interface PaymentResult {
|
|
141
|
+
/** VaultSaaS-normalized transaction identifier. */
|
|
142
|
+
id: string;
|
|
143
|
+
status: PaymentStatus;
|
|
144
|
+
/** Name of the provider that processed the transaction (e.g. "stripe"). */
|
|
145
|
+
provider: string;
|
|
146
|
+
/** Provider's own identifier for this transaction. */
|
|
147
|
+
providerId: string;
|
|
148
|
+
/** Amount in smallest currency unit. */
|
|
149
|
+
amount: number;
|
|
150
|
+
/** ISO 4217 currency code. */
|
|
151
|
+
currency: string;
|
|
152
|
+
/** Snapshot of the payment method used. */
|
|
153
|
+
paymentMethod: {
|
|
154
|
+
type: string;
|
|
155
|
+
last4?: string;
|
|
156
|
+
brand?: string;
|
|
157
|
+
expiryMonth?: number;
|
|
158
|
+
expiryYear?: number;
|
|
159
|
+
};
|
|
160
|
+
customer?: {
|
|
161
|
+
id?: string;
|
|
162
|
+
email?: string;
|
|
163
|
+
};
|
|
164
|
+
/** Merged metadata from the request and provider response. */
|
|
165
|
+
metadata: Record<string, string>;
|
|
166
|
+
/** How the provider was selected for this transaction. */
|
|
167
|
+
routing: {
|
|
168
|
+
source: 'local' | 'platform';
|
|
169
|
+
reason: string;
|
|
170
|
+
};
|
|
171
|
+
/** ISO 8601 timestamp. */
|
|
172
|
+
createdAt: string;
|
|
173
|
+
/** Raw provider-specific fields not mapped to the normalized schema. */
|
|
174
|
+
providerMetadata: Record<string, unknown>;
|
|
175
|
+
}
|
|
176
|
+
/** @description Normalized result returned by a `refund` operation. */
|
|
177
|
+
interface RefundResult {
|
|
178
|
+
/** Unique refund identifier. */
|
|
179
|
+
id: string;
|
|
180
|
+
/** The original transaction that was refunded. */
|
|
181
|
+
transactionId: string;
|
|
182
|
+
status: 'completed' | 'pending' | 'failed';
|
|
183
|
+
/** Refunded amount in smallest currency unit. */
|
|
184
|
+
amount: number;
|
|
185
|
+
currency: string;
|
|
186
|
+
provider: string;
|
|
187
|
+
providerId: string;
|
|
188
|
+
reason?: string;
|
|
189
|
+
/** ISO 8601 timestamp. */
|
|
190
|
+
createdAt: string;
|
|
191
|
+
}
|
|
192
|
+
/** @description Normalized result returned by a `void` (cancellation) operation. */
|
|
193
|
+
interface VoidResult {
|
|
194
|
+
id: string;
|
|
195
|
+
/** The original authorized transaction that was voided. */
|
|
196
|
+
transactionId: string;
|
|
197
|
+
status: 'completed' | 'failed';
|
|
198
|
+
provider: string;
|
|
199
|
+
/** ISO 8601 timestamp. */
|
|
200
|
+
createdAt: string;
|
|
201
|
+
}
|
|
202
|
+
/** @description A single entry in a transaction's status history timeline. */
|
|
203
|
+
interface StatusChange {
|
|
204
|
+
status: PaymentStatus;
|
|
205
|
+
/** ISO 8601 timestamp when this status was recorded. */
|
|
206
|
+
timestamp: string;
|
|
207
|
+
reason?: string;
|
|
208
|
+
}
|
|
209
|
+
/** @description Full transaction status including status history, returned by `getStatus`. */
|
|
210
|
+
interface TransactionStatus {
|
|
211
|
+
id: string;
|
|
212
|
+
status: PaymentStatus;
|
|
213
|
+
provider: string;
|
|
214
|
+
providerId: string;
|
|
215
|
+
amount: number;
|
|
216
|
+
currency: string;
|
|
217
|
+
/** Chronological status changes for this transaction. */
|
|
218
|
+
history: StatusChange[];
|
|
219
|
+
/** ISO 8601 timestamp of the most recent status update. */
|
|
220
|
+
updatedAt: string;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* @description Describes a payment method supported by a provider for a given
|
|
224
|
+
* country/currency combination. Returned by `listPaymentMethods`.
|
|
225
|
+
*/
|
|
226
|
+
interface PaymentMethodInfo {
|
|
227
|
+
/** Payment method type identifier (e.g. "card", "pix", "bank_transfer"). */
|
|
228
|
+
type: string;
|
|
229
|
+
provider: string;
|
|
230
|
+
/** Human-readable display name. */
|
|
231
|
+
name: string;
|
|
232
|
+
/** ISO 4217 currency codes this method supports. */
|
|
233
|
+
currencies: string[];
|
|
234
|
+
/** ISO 3166-1 alpha-2 country codes this method supports. */
|
|
235
|
+
countries: string[];
|
|
236
|
+
/** Minimum amount in smallest currency unit, if applicable. */
|
|
237
|
+
minAmount?: number;
|
|
238
|
+
/** Maximum amount in smallest currency unit, if applicable. */
|
|
239
|
+
maxAmount?: number;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Static provider capability declaration used by routing validation. */
|
|
243
|
+
interface AdapterMetadata {
|
|
244
|
+
readonly supportedMethods: readonly string[];
|
|
245
|
+
readonly supportedCurrencies: readonly string[];
|
|
246
|
+
readonly supportedCountries: readonly string[];
|
|
247
|
+
}
|
|
248
|
+
/** Runtime adapter contract used by `VaultClient`. */
|
|
249
|
+
interface PaymentAdapter {
|
|
250
|
+
readonly name: string;
|
|
251
|
+
readonly metadata: AdapterMetadata;
|
|
252
|
+
charge(request: ChargeRequest): Promise<PaymentResult>;
|
|
253
|
+
authorize(request: AuthorizeRequest): Promise<PaymentResult>;
|
|
254
|
+
capture(request: CaptureRequest): Promise<PaymentResult>;
|
|
255
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
256
|
+
void(request: VoidRequest): Promise<VoidResult>;
|
|
257
|
+
getStatus(transactionId: string): Promise<TransactionStatus>;
|
|
258
|
+
listPaymentMethods(country: string, currency: string): Promise<PaymentMethodInfo[]>;
|
|
259
|
+
handleWebhook?(payload: Buffer | string, headers: Record<string, string>): Promise<VaultEvent> | VaultEvent;
|
|
260
|
+
}
|
|
261
|
+
/** Adapter class contract used in provider configuration. */
|
|
262
|
+
interface PaymentAdapterConstructor {
|
|
263
|
+
new (config: Record<string, unknown>): PaymentAdapter;
|
|
264
|
+
readonly supportedMethods: readonly string[];
|
|
265
|
+
readonly supportedCurrencies: readonly string[];
|
|
266
|
+
readonly supportedCountries: readonly string[];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
declare const DEFAULT_IDEMPOTENCY_TTL_MS = 86400000;
|
|
270
|
+
interface IdempotencyRecord<T = unknown> {
|
|
271
|
+
key: string;
|
|
272
|
+
payloadHash: string;
|
|
273
|
+
result: T;
|
|
274
|
+
expiresAt: number;
|
|
275
|
+
}
|
|
276
|
+
interface IdempotencyStore<T = unknown> {
|
|
277
|
+
get(key: string): Promise<IdempotencyRecord<T> | null> | IdempotencyRecord<T> | null;
|
|
278
|
+
set(record: IdempotencyRecord<T>): Promise<void> | void;
|
|
279
|
+
delete(key: string): Promise<void> | void;
|
|
280
|
+
clearExpired(now?: number): Promise<void> | void;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
declare class MemoryIdempotencyStore<T = unknown> implements IdempotencyStore<T> {
|
|
284
|
+
private readonly records;
|
|
285
|
+
get(key: string): IdempotencyRecord<T> | null;
|
|
286
|
+
set(record: IdempotencyRecord<T>): void;
|
|
287
|
+
delete(key: string): void;
|
|
288
|
+
clearExpired(now?: number): void;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
declare function hashIdempotencyPayload(payload: unknown): string;
|
|
292
|
+
|
|
293
|
+
type RoutingMatchValue = string | string[];
|
|
294
|
+
interface RoutingMatch {
|
|
295
|
+
currency?: RoutingMatchValue;
|
|
296
|
+
country?: RoutingMatchValue;
|
|
297
|
+
paymentMethod?: RoutingMatchValue;
|
|
298
|
+
amountMin?: number;
|
|
299
|
+
amountMax?: number;
|
|
300
|
+
metadata?: Record<string, string>;
|
|
301
|
+
default?: boolean;
|
|
302
|
+
}
|
|
303
|
+
interface RoutingRule {
|
|
304
|
+
match: RoutingMatch;
|
|
305
|
+
provider: string;
|
|
306
|
+
weight?: number;
|
|
307
|
+
}
|
|
308
|
+
interface RoutingContext {
|
|
309
|
+
currency?: string;
|
|
310
|
+
country?: string;
|
|
311
|
+
paymentMethod?: string;
|
|
312
|
+
amount?: number;
|
|
313
|
+
metadata?: Record<string, string>;
|
|
314
|
+
providerOverride?: string;
|
|
315
|
+
exclude?: string[];
|
|
316
|
+
}
|
|
317
|
+
interface RoutingDecision {
|
|
318
|
+
provider: string;
|
|
319
|
+
reason: string;
|
|
320
|
+
rule: RoutingRule;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Logger contract used by `VaultClient` and `PlatformConnector`. */
|
|
324
|
+
interface LoggerInterface {
|
|
325
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
326
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
327
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
328
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
329
|
+
}
|
|
330
|
+
/** Config for a single provider adapter instance. */
|
|
331
|
+
interface ProviderConfig {
|
|
332
|
+
adapter: PaymentAdapterConstructor;
|
|
333
|
+
config: Record<string, unknown>;
|
|
334
|
+
priority?: number;
|
|
335
|
+
enabled?: boolean;
|
|
336
|
+
}
|
|
337
|
+
/** Root configuration object accepted by `new VaultClient(config)`. */
|
|
338
|
+
interface VaultConfig {
|
|
339
|
+
providers: Record<string, ProviderConfig>;
|
|
340
|
+
routing?: {
|
|
341
|
+
rules: RoutingRule[];
|
|
342
|
+
};
|
|
343
|
+
idempotency?: {
|
|
344
|
+
store?: IdempotencyStore;
|
|
345
|
+
ttlMs?: number;
|
|
346
|
+
};
|
|
347
|
+
platformApiKey?: string;
|
|
348
|
+
platform?: {
|
|
349
|
+
baseUrl?: string;
|
|
350
|
+
timeoutMs?: number;
|
|
351
|
+
batchSize?: number;
|
|
352
|
+
flushIntervalMs?: number;
|
|
353
|
+
maxRetries?: number;
|
|
354
|
+
initialBackoffMs?: number;
|
|
355
|
+
};
|
|
356
|
+
logging?: {
|
|
357
|
+
level?: 'silent' | 'error' | 'warn' | 'info' | 'debug';
|
|
358
|
+
logger?: LoggerInterface;
|
|
359
|
+
};
|
|
360
|
+
timeout?: number;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
declare class DLocalAdapter implements PaymentAdapter {
|
|
364
|
+
readonly name = "dlocal";
|
|
365
|
+
static readonly supportedMethods: readonly ["card", "pix", "boleto", "bank_transfer"];
|
|
366
|
+
static readonly supportedCurrencies: readonly ["BRL", "MXN", "ARS", "CLP", "COP", "PEN", "UYU", "BOB", "PYG", "CRC", "GTQ", "PAB", "DOP", "USD"];
|
|
367
|
+
static readonly supportedCountries: readonly ["BR", "MX", "AR", "CL", "CO", "PE", "UY", "BO", "PY", "CR", "GT", "PA", "DO", "EC", "SV", "NI", "HN"];
|
|
368
|
+
readonly metadata: {
|
|
369
|
+
supportedMethods: readonly ["card", "pix", "boleto", "bank_transfer"];
|
|
370
|
+
supportedCurrencies: readonly ["BRL", "MXN", "ARS", "CLP", "COP", "PEN", "UYU", "BOB", "PYG", "CRC", "GTQ", "PAB", "DOP", "USD"];
|
|
371
|
+
supportedCountries: readonly ["BR", "MX", "AR", "CL", "CO", "PE", "UY", "BO", "PY", "CR", "GT", "PA", "DO", "EC", "SV", "NI", "HN"];
|
|
372
|
+
};
|
|
373
|
+
private readonly config;
|
|
374
|
+
constructor(rawConfig: Record<string, unknown>);
|
|
375
|
+
charge(request: ChargeRequest): Promise<PaymentResult>;
|
|
376
|
+
authorize(request: AuthorizeRequest): Promise<PaymentResult>;
|
|
377
|
+
capture(request: CaptureRequest): Promise<PaymentResult>;
|
|
378
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
379
|
+
void(request: VoidRequest): Promise<VoidResult>;
|
|
380
|
+
getStatus(transactionId: string): Promise<TransactionStatus>;
|
|
381
|
+
listPaymentMethods(country: string, currency: string): Promise<PaymentMethodInfo[]>;
|
|
382
|
+
handleWebhook(payload: Buffer | string, headers: Record<string, string>): Promise<VaultEvent>;
|
|
383
|
+
private verifyWebhook;
|
|
384
|
+
private createPayment;
|
|
385
|
+
private normalizePaymentResult;
|
|
386
|
+
private buildHeaders;
|
|
387
|
+
private request;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
declare class PaystackAdapter implements PaymentAdapter {
|
|
391
|
+
readonly name = "paystack";
|
|
392
|
+
static readonly supportedMethods: readonly ["card", "bank_transfer", "wallet"];
|
|
393
|
+
static readonly supportedCurrencies: readonly ["NGN", "GHS", "ZAR", "KES", "USD"];
|
|
394
|
+
static readonly supportedCountries: readonly ["NG", "GH", "ZA", "KE"];
|
|
395
|
+
readonly metadata: {
|
|
396
|
+
supportedMethods: readonly ["card", "bank_transfer", "wallet"];
|
|
397
|
+
supportedCurrencies: readonly ["NGN", "GHS", "ZAR", "KES", "USD"];
|
|
398
|
+
supportedCountries: readonly ["NG", "GH", "ZA", "KE"];
|
|
399
|
+
};
|
|
400
|
+
private readonly config;
|
|
401
|
+
constructor(rawConfig: Record<string, unknown>);
|
|
402
|
+
charge(request: ChargeRequest): Promise<PaymentResult>;
|
|
403
|
+
authorize(request: AuthorizeRequest): Promise<PaymentResult>;
|
|
404
|
+
capture(request: CaptureRequest): Promise<PaymentResult>;
|
|
405
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
406
|
+
void(request: VoidRequest): Promise<VoidResult>;
|
|
407
|
+
getStatus(transactionId: string): Promise<TransactionStatus>;
|
|
408
|
+
listPaymentMethods(country: string, currency: string): Promise<PaymentMethodInfo[]>;
|
|
409
|
+
handleWebhook(payload: Buffer | string, headers: Record<string, string>): Promise<VaultEvent>;
|
|
410
|
+
private verifyWebhook;
|
|
411
|
+
private buildChargePayload;
|
|
412
|
+
private normalizePaymentResult;
|
|
413
|
+
private request;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
declare class StripeAdapter implements PaymentAdapter {
|
|
417
|
+
readonly name = "stripe";
|
|
418
|
+
static readonly supportedMethods: readonly ["card", "bank_transfer", "wallet"];
|
|
419
|
+
static readonly supportedCurrencies: readonly ["USD", "EUR", "GBP", "CAD", "AUD", "JPY", "CHF", "SEK", "NOK", "DKK", "NZD", "SGD", "HKD", "MXN", "BRL", "PLN", "CZK", "HUF", "RON", "BGN", "INR", "MYR", "THB"];
|
|
420
|
+
static readonly supportedCountries: readonly ["US", "GB", "DE", "FR", "CA", "AU", "JP", "IT", "ES", "NL", "BE", "AT", "CH", "SE", "NO", "DK", "FI", "IE", "PT", "LU", "NZ", "SG", "HK", "MY", "MX", "BR", "PL", "CZ", "HU", "RO", "BG", "HR", "CY", "EE", "GR", "LV", "LT", "MT", "SK", "SI", "IN", "TH"];
|
|
421
|
+
readonly metadata: {
|
|
422
|
+
supportedMethods: readonly ["card", "bank_transfer", "wallet"];
|
|
423
|
+
supportedCurrencies: readonly ["USD", "EUR", "GBP", "CAD", "AUD", "JPY", "CHF", "SEK", "NOK", "DKK", "NZD", "SGD", "HKD", "MXN", "BRL", "PLN", "CZK", "HUF", "RON", "BGN", "INR", "MYR", "THB"];
|
|
424
|
+
supportedCountries: readonly ["US", "GB", "DE", "FR", "CA", "AU", "JP", "IT", "ES", "NL", "BE", "AT", "CH", "SE", "NO", "DK", "FI", "IE", "PT", "LU", "NZ", "SG", "HK", "MY", "MX", "BR", "PL", "CZ", "HU", "RO", "BG", "HR", "CY", "EE", "GR", "LV", "LT", "MT", "SK", "SI", "IN", "TH"];
|
|
425
|
+
};
|
|
426
|
+
private readonly config;
|
|
427
|
+
constructor(rawConfig: Record<string, unknown>);
|
|
428
|
+
charge(request: ChargeRequest): Promise<PaymentResult>;
|
|
429
|
+
authorize(request: AuthorizeRequest): Promise<PaymentResult>;
|
|
430
|
+
capture(request: CaptureRequest): Promise<PaymentResult>;
|
|
431
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
432
|
+
void(request: VoidRequest): Promise<VoidResult>;
|
|
433
|
+
getStatus(transactionId: string): Promise<TransactionStatus>;
|
|
434
|
+
listPaymentMethods(country: string, currency: string): Promise<PaymentMethodInfo[]>;
|
|
435
|
+
handleWebhook(payload: Buffer | string, headers: Record<string, string>): Promise<VaultEvent>;
|
|
436
|
+
private verifyWebhook;
|
|
437
|
+
private createPaymentIntent;
|
|
438
|
+
private normalizePaymentResult;
|
|
439
|
+
private get;
|
|
440
|
+
private postForm;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** Main orchestration client for charge, auth/capture, refund, void, and webhooks. */
|
|
444
|
+
declare class VaultClient {
|
|
445
|
+
readonly config: VaultConfig;
|
|
446
|
+
private readonly adapters;
|
|
447
|
+
private readonly providerOrder;
|
|
448
|
+
private readonly router;
|
|
449
|
+
private readonly platformConnector;
|
|
450
|
+
private readonly idempotencyStore;
|
|
451
|
+
private readonly idempotencyTtlMs;
|
|
452
|
+
private readonly transactionProviderIndex;
|
|
453
|
+
constructor(config: VaultConfig);
|
|
454
|
+
charge(request: ChargeRequest): Promise<PaymentResult>;
|
|
455
|
+
authorize(request: AuthorizeRequest): Promise<PaymentResult>;
|
|
456
|
+
capture(request: CaptureRequest): Promise<PaymentResult>;
|
|
457
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
458
|
+
void(request: VoidRequest): Promise<VoidResult>;
|
|
459
|
+
getStatus(transactionId: string): Promise<TransactionStatus>;
|
|
460
|
+
listPaymentMethods(country: string, currency: string): Promise<PaymentMethodInfo[]>;
|
|
461
|
+
handleWebhook(provider: string, payload: Buffer | string, headers: Record<string, string>): Promise<VaultEvent>;
|
|
462
|
+
private resolveProviderForCharge;
|
|
463
|
+
private resolveProviderFromPlatform;
|
|
464
|
+
private resolveProviderForTransaction;
|
|
465
|
+
private getAdapter;
|
|
466
|
+
private withRouting;
|
|
467
|
+
private parseWebhookPayload;
|
|
468
|
+
private extractCardBin;
|
|
469
|
+
private queueTransactionReport;
|
|
470
|
+
private queueWebhookEvent;
|
|
471
|
+
private executeIdempotentOperation;
|
|
472
|
+
private wrapProviderCall;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
type VaultErrorCategory = 'card_declined' | 'authentication_required' | 'invalid_request' | 'provider_error' | 'fraud_suspected' | 'rate_limited' | 'network_error' | 'configuration_error' | 'routing_error' | 'unknown';
|
|
476
|
+
|
|
477
|
+
interface VaultErrorCodeDefinition {
|
|
478
|
+
category: VaultErrorCategory;
|
|
479
|
+
suggestion: string;
|
|
480
|
+
retriable: boolean;
|
|
481
|
+
docsPath?: string;
|
|
482
|
+
}
|
|
483
|
+
declare const VAULT_ERROR_CODE_DEFINITIONS: Record<string, VaultErrorCodeDefinition>;
|
|
484
|
+
declare function getVaultErrorCodeDefinition(code: string): VaultErrorCodeDefinition;
|
|
485
|
+
declare function buildVaultErrorDocsUrl(code: string, docsPath?: string): string;
|
|
486
|
+
|
|
487
|
+
interface VaultErrorContext {
|
|
488
|
+
provider?: string;
|
|
489
|
+
operation?: string;
|
|
490
|
+
requestId?: string;
|
|
491
|
+
providerCode?: string;
|
|
492
|
+
providerMessage?: string;
|
|
493
|
+
[key: string]: unknown;
|
|
494
|
+
}
|
|
495
|
+
interface VaultErrorOptions {
|
|
496
|
+
code: string;
|
|
497
|
+
category?: VaultErrorCategory;
|
|
498
|
+
suggestion?: string;
|
|
499
|
+
docsUrl?: string;
|
|
500
|
+
retriable?: boolean;
|
|
501
|
+
context?: VaultErrorContext;
|
|
502
|
+
}
|
|
503
|
+
declare class VaultError extends Error {
|
|
504
|
+
readonly code: string;
|
|
505
|
+
readonly category: VaultErrorCategory;
|
|
506
|
+
readonly suggestion: string;
|
|
507
|
+
readonly docsUrl: string;
|
|
508
|
+
readonly retriable: boolean;
|
|
509
|
+
readonly context: VaultErrorContext;
|
|
510
|
+
constructor(message: string, options: VaultErrorOptions);
|
|
511
|
+
}
|
|
512
|
+
interface VaultSubclassOptions extends Omit<VaultErrorOptions, 'code'> {
|
|
513
|
+
code?: string;
|
|
514
|
+
}
|
|
515
|
+
declare class VaultConfigError extends VaultError {
|
|
516
|
+
constructor(message: string, options?: VaultErrorContext | VaultSubclassOptions);
|
|
517
|
+
}
|
|
518
|
+
declare class VaultRoutingError extends VaultError {
|
|
519
|
+
constructor(message: string, options?: VaultErrorContext | VaultSubclassOptions);
|
|
520
|
+
}
|
|
521
|
+
declare class VaultProviderError extends VaultError {
|
|
522
|
+
constructor(message: string, options?: VaultErrorContext | VaultSubclassOptions);
|
|
523
|
+
}
|
|
524
|
+
declare class VaultNetworkError extends VaultError {
|
|
525
|
+
constructor(message: string, options?: VaultErrorContext | VaultSubclassOptions);
|
|
526
|
+
}
|
|
527
|
+
declare class WebhookVerificationError extends VaultError {
|
|
528
|
+
constructor(message: string, options?: VaultErrorContext | VaultSubclassOptions);
|
|
529
|
+
}
|
|
530
|
+
declare class VaultIdempotencyConflictError extends VaultError {
|
|
531
|
+
constructor(message: string, options?: VaultErrorContext | VaultSubclassOptions);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Optional provider-side fields used to improve error classification. */
|
|
535
|
+
interface ProviderErrorHint {
|
|
536
|
+
providerCode?: string;
|
|
537
|
+
providerMessage?: string;
|
|
538
|
+
requestId?: string;
|
|
539
|
+
httpStatus?: number;
|
|
540
|
+
declineCode?: string;
|
|
541
|
+
type?: string;
|
|
542
|
+
isNetworkError?: boolean;
|
|
543
|
+
isTimeout?: boolean;
|
|
544
|
+
raw?: unknown;
|
|
545
|
+
}
|
|
546
|
+
/** Context attached to mapped provider errors. */
|
|
547
|
+
interface ProviderErrorMappingContext {
|
|
548
|
+
provider: string;
|
|
549
|
+
operation: string;
|
|
550
|
+
}
|
|
551
|
+
declare function isProviderErrorHint(value: unknown): value is ProviderErrorHint;
|
|
552
|
+
/** Normalizes unknown provider errors into Vault error classes with stable codes. */
|
|
553
|
+
declare function mapProviderError(error: unknown, mappingContext: ProviderErrorMappingContext): VaultError;
|
|
554
|
+
|
|
555
|
+
declare class BatchBuffer<T> {
|
|
556
|
+
private readonly maxSize;
|
|
557
|
+
private readonly items;
|
|
558
|
+
constructor(maxSize: number);
|
|
559
|
+
push(item: T): T[] | null;
|
|
560
|
+
flush(): T[];
|
|
561
|
+
size(): number;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** Platform telemetry and routing client configuration. */
|
|
565
|
+
interface PlatformConnectorConfig {
|
|
566
|
+
apiKey: string;
|
|
567
|
+
baseUrl?: string;
|
|
568
|
+
timeoutMs?: number;
|
|
569
|
+
batchSize?: number;
|
|
570
|
+
flushIntervalMs?: number;
|
|
571
|
+
maxRetries?: number;
|
|
572
|
+
initialBackoffMs?: number;
|
|
573
|
+
logger?: LoggerInterface;
|
|
574
|
+
fetchFn?: typeof fetch;
|
|
575
|
+
}
|
|
576
|
+
interface ResolvedPlatformConnectorConfig extends PlatformConnectorConfig {
|
|
577
|
+
baseUrl: string;
|
|
578
|
+
timeoutMs: number;
|
|
579
|
+
batchSize: number;
|
|
580
|
+
flushIntervalMs: number;
|
|
581
|
+
maxRetries: number;
|
|
582
|
+
initialBackoffMs: number;
|
|
583
|
+
}
|
|
584
|
+
interface PlatformRoutingRequest {
|
|
585
|
+
currency: string;
|
|
586
|
+
amount: number;
|
|
587
|
+
paymentMethod: string;
|
|
588
|
+
country?: string;
|
|
589
|
+
cardBin?: string;
|
|
590
|
+
metadata?: Record<string, string>;
|
|
591
|
+
}
|
|
592
|
+
/** Response shape for remote routing decisions. */
|
|
593
|
+
interface PlatformRoutingDecision {
|
|
594
|
+
provider: string | null;
|
|
595
|
+
source?: string;
|
|
596
|
+
reason?: string;
|
|
597
|
+
decisionId?: string;
|
|
598
|
+
ttlMs?: number;
|
|
599
|
+
cascade?: string[];
|
|
600
|
+
}
|
|
601
|
+
/** Transaction telemetry event sent to the VaultSaaS platform. */
|
|
602
|
+
interface PlatformTransactionReport {
|
|
603
|
+
id: string;
|
|
604
|
+
provider: string;
|
|
605
|
+
providerId?: string;
|
|
606
|
+
status: string;
|
|
607
|
+
amount: number;
|
|
608
|
+
currency: string;
|
|
609
|
+
country?: string;
|
|
610
|
+
paymentMethod?: string;
|
|
611
|
+
cardBin?: string;
|
|
612
|
+
cardBrand?: string;
|
|
613
|
+
latencyMs?: number;
|
|
614
|
+
errorCategory?: string | null;
|
|
615
|
+
routingSource?: 'local' | 'platform';
|
|
616
|
+
routingDecisionId?: string;
|
|
617
|
+
idempotencyKey?: string;
|
|
618
|
+
timestamp: string;
|
|
619
|
+
}
|
|
620
|
+
/** Webhook forwarding payload sent to the VaultSaaS platform. */
|
|
621
|
+
interface PlatformWebhookForwardEvent {
|
|
622
|
+
id: string;
|
|
623
|
+
type: string;
|
|
624
|
+
provider: string;
|
|
625
|
+
transactionId?: string;
|
|
626
|
+
providerEventId: string;
|
|
627
|
+
data: Record<string, unknown>;
|
|
628
|
+
timestamp: string;
|
|
629
|
+
}
|
|
630
|
+
/** Batches platform routing/telemetry requests with retry and timeout controls. */
|
|
631
|
+
declare class PlatformConnector {
|
|
632
|
+
private static readonly DEFAULT_BASE_URL;
|
|
633
|
+
private static readonly DEFAULT_TIMEOUT_MS;
|
|
634
|
+
private static readonly DEFAULT_BATCH_SIZE;
|
|
635
|
+
private static readonly DEFAULT_FLUSH_INTERVAL_MS;
|
|
636
|
+
private static readonly DEFAULT_MAX_RETRIES;
|
|
637
|
+
private static readonly DEFAULT_INITIAL_BACKOFF_MS;
|
|
638
|
+
readonly config: ResolvedPlatformConnectorConfig;
|
|
639
|
+
readonly transactionBuffer: BatchBuffer<PlatformTransactionReport>;
|
|
640
|
+
readonly webhookBuffer: BatchBuffer<PlatformWebhookForwardEvent>;
|
|
641
|
+
private readonly fetchFn;
|
|
642
|
+
private readonly logger?;
|
|
643
|
+
private readonly flushTimer;
|
|
644
|
+
private transactionSendQueue;
|
|
645
|
+
private webhookSendQueue;
|
|
646
|
+
constructor(config: PlatformConnectorConfig);
|
|
647
|
+
close(): void;
|
|
648
|
+
decideRouting(request: PlatformRoutingRequest): Promise<PlatformRoutingDecision | null>;
|
|
649
|
+
queueTransactionReport(transaction: PlatformTransactionReport): void;
|
|
650
|
+
queueWebhookEvent(event: PlatformWebhookForwardEvent): void;
|
|
651
|
+
flush(): Promise<void>;
|
|
652
|
+
private enqueueTransactionBatch;
|
|
653
|
+
private enqueueWebhookBatch;
|
|
654
|
+
private postJson;
|
|
655
|
+
private fetchWithTimeout;
|
|
656
|
+
private normalizeRoutingDecision;
|
|
657
|
+
private backoffForAttempt;
|
|
658
|
+
private urlFor;
|
|
659
|
+
private delay;
|
|
660
|
+
private debug;
|
|
661
|
+
private warn;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/** Optional controls for routing behavior and capability validation. */
|
|
665
|
+
interface RouterOptions {
|
|
666
|
+
random?: () => number;
|
|
667
|
+
adapterMetadata?: Record<string, AdapterMetadata>;
|
|
668
|
+
logger?: {
|
|
669
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
/** Deterministic routing engine for selecting a provider from ordered rules. */
|
|
673
|
+
declare class Router {
|
|
674
|
+
readonly rules: RoutingRule[];
|
|
675
|
+
private readonly random;
|
|
676
|
+
private readonly adapterMetadata;
|
|
677
|
+
private readonly logger?;
|
|
678
|
+
constructor(rules: RoutingRule[], options?: RouterOptions);
|
|
679
|
+
decide(context: RoutingContext): RoutingDecision | null;
|
|
680
|
+
private providerSupportsContext;
|
|
681
|
+
private getWeightedCandidates;
|
|
682
|
+
private selectWeightedRule;
|
|
683
|
+
private buildRuleReason;
|
|
684
|
+
private buildWeightedReason;
|
|
685
|
+
private getMatchCriteria;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
declare function ruleMatchesContext(rule: RoutingRule, context: RoutingContext): boolean;
|
|
689
|
+
|
|
690
|
+
declare class AdapterComplianceError extends Error {
|
|
691
|
+
readonly operation: string;
|
|
692
|
+
readonly field?: string;
|
|
693
|
+
constructor(operation: string, message: string, field?: string);
|
|
694
|
+
}
|
|
695
|
+
declare function validatePaymentResult(value: PaymentResult, operation: string, expectedProvider?: string): void;
|
|
696
|
+
declare function validateRefundResult(value: RefundResult, operation?: string, expectedProvider?: string): void;
|
|
697
|
+
declare function validateVoidResult(value: VoidResult, operation?: string, expectedProvider?: string): void;
|
|
698
|
+
declare function validateTransactionStatus(value: TransactionStatus, operation?: string, expectedProvider?: string): void;
|
|
699
|
+
declare function validatePaymentMethods(methods: PaymentMethodInfo[], operation?: string, expectedProvider?: string): void;
|
|
700
|
+
declare function validateWebhookEvent(event: VaultEvent, operation?: string, expectedProvider?: string): void;
|
|
701
|
+
interface AdapterComplianceHarness {
|
|
702
|
+
charge(request: ChargeRequest): Promise<PaymentResult>;
|
|
703
|
+
authorize(request: AuthorizeRequest): Promise<PaymentResult>;
|
|
704
|
+
capture(request: CaptureRequest): Promise<PaymentResult>;
|
|
705
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
706
|
+
void(request: VoidRequest): Promise<VoidResult>;
|
|
707
|
+
getStatus(transactionId: string): Promise<TransactionStatus>;
|
|
708
|
+
listPaymentMethods(country: string, currency: string): Promise<PaymentMethodInfo[]>;
|
|
709
|
+
handleWebhook(payload: Buffer | string, headers: Record<string, string>): Promise<VaultEvent>;
|
|
710
|
+
}
|
|
711
|
+
interface AdapterComplianceHarnessOptions {
|
|
712
|
+
expectedProvider?: string;
|
|
713
|
+
}
|
|
714
|
+
declare function createAdapterComplianceHarness(adapter: PaymentAdapter, options?: AdapterComplianceHarnessOptions): AdapterComplianceHarness;
|
|
715
|
+
|
|
716
|
+
type SyncOrAsync<T> = T | Promise<T>;
|
|
717
|
+
type ListPaymentMethodsInput = {
|
|
718
|
+
country: string;
|
|
719
|
+
currency: string;
|
|
720
|
+
};
|
|
721
|
+
type HandleWebhookInput = {
|
|
722
|
+
payload: Buffer | string;
|
|
723
|
+
headers: Record<string, string>;
|
|
724
|
+
};
|
|
725
|
+
type HandlerMap = {
|
|
726
|
+
charge: (request: ChargeRequest) => Promise<PaymentResult>;
|
|
727
|
+
authorize: (request: AuthorizeRequest) => Promise<PaymentResult>;
|
|
728
|
+
capture: (request: CaptureRequest) => Promise<PaymentResult>;
|
|
729
|
+
refund: (request: RefundRequest) => Promise<RefundResult>;
|
|
730
|
+
void: (request: VoidRequest) => Promise<VoidResult>;
|
|
731
|
+
getStatus: (transactionId: string) => Promise<TransactionStatus>;
|
|
732
|
+
listPaymentMethods: (country: string, currency: string) => Promise<PaymentMethodInfo[]>;
|
|
733
|
+
handleWebhook: (payload: Buffer | string, headers: Record<string, string>) => SyncOrAsync<VaultEvent>;
|
|
734
|
+
};
|
|
735
|
+
type MockAdapterHandlers = Partial<HandlerMap>;
|
|
736
|
+
type MockAdapterScenario<Input, Output> = Output | Error | ((input: Input) => SyncOrAsync<Output>);
|
|
737
|
+
interface MockAdapterScenarios {
|
|
738
|
+
charge: MockAdapterScenario<ChargeRequest, PaymentResult>[];
|
|
739
|
+
authorize: MockAdapterScenario<AuthorizeRequest, PaymentResult>[];
|
|
740
|
+
capture: MockAdapterScenario<CaptureRequest, PaymentResult>[];
|
|
741
|
+
refund: MockAdapterScenario<RefundRequest, RefundResult>[];
|
|
742
|
+
void: MockAdapterScenario<VoidRequest, VoidResult>[];
|
|
743
|
+
getStatus: MockAdapterScenario<string, TransactionStatus>[];
|
|
744
|
+
listPaymentMethods: MockAdapterScenario<ListPaymentMethodsInput, PaymentMethodInfo[]>[];
|
|
745
|
+
handleWebhook: MockAdapterScenario<HandleWebhookInput, VaultEvent>[];
|
|
746
|
+
}
|
|
747
|
+
interface MockAdapterOptions {
|
|
748
|
+
name?: string;
|
|
749
|
+
metadata?: AdapterMetadata;
|
|
750
|
+
handlers?: MockAdapterHandlers;
|
|
751
|
+
scenarios?: Partial<MockAdapterScenarios>;
|
|
752
|
+
}
|
|
753
|
+
declare class MockAdapter implements PaymentAdapter {
|
|
754
|
+
static readonly supportedMethods: readonly string[];
|
|
755
|
+
static readonly supportedCurrencies: readonly string[];
|
|
756
|
+
static readonly supportedCountries: readonly string[];
|
|
757
|
+
readonly name: string;
|
|
758
|
+
readonly metadata: AdapterMetadata;
|
|
759
|
+
private readonly handlers;
|
|
760
|
+
private readonly chargeScenarios;
|
|
761
|
+
private readonly authorizeScenarios;
|
|
762
|
+
private readonly captureScenarios;
|
|
763
|
+
private readonly refundScenarios;
|
|
764
|
+
private readonly voidScenarios;
|
|
765
|
+
private readonly statusScenarios;
|
|
766
|
+
private readonly paymentMethodsScenarios;
|
|
767
|
+
private readonly webhookScenarios;
|
|
768
|
+
constructor(options?: MockAdapterOptions | MockAdapterHandlers);
|
|
769
|
+
enqueue(method: 'charge', scenario: MockAdapterScenario<ChargeRequest, PaymentResult>): this;
|
|
770
|
+
enqueue(method: 'authorize', scenario: MockAdapterScenario<AuthorizeRequest, PaymentResult>): this;
|
|
771
|
+
enqueue(method: 'capture', scenario: MockAdapterScenario<CaptureRequest, PaymentResult>): this;
|
|
772
|
+
enqueue(method: 'refund', scenario: MockAdapterScenario<RefundRequest, RefundResult>): this;
|
|
773
|
+
enqueue(method: 'void', scenario: MockAdapterScenario<VoidRequest, VoidResult>): this;
|
|
774
|
+
enqueue(method: 'getStatus', scenario: MockAdapterScenario<string, TransactionStatus>): this;
|
|
775
|
+
enqueue(method: 'listPaymentMethods', scenario: MockAdapterScenario<ListPaymentMethodsInput, PaymentMethodInfo[]>): this;
|
|
776
|
+
enqueue(method: 'handleWebhook', scenario: MockAdapterScenario<HandleWebhookInput, VaultEvent>): this;
|
|
777
|
+
charge(request: ChargeRequest): Promise<PaymentResult>;
|
|
778
|
+
authorize(request: AuthorizeRequest): Promise<PaymentResult>;
|
|
779
|
+
capture(request: CaptureRequest): Promise<PaymentResult>;
|
|
780
|
+
refund(request: RefundRequest): Promise<RefundResult>;
|
|
781
|
+
void(request: VoidRequest): Promise<VoidResult>;
|
|
782
|
+
getStatus(transactionId: string): Promise<TransactionStatus>;
|
|
783
|
+
listPaymentMethods(country: string, currency: string): Promise<PaymentMethodInfo[]>;
|
|
784
|
+
handleWebhook(payload: Buffer | string, headers: Record<string, string>): Promise<VaultEvent>;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
interface SignedWebhookPayload {
|
|
788
|
+
payload: string;
|
|
789
|
+
headers: Record<string, string>;
|
|
790
|
+
}
|
|
791
|
+
type WebhookSigningProvider = 'stripe' | 'dlocal' | 'paystack' | 'generic';
|
|
792
|
+
interface SignedWebhookPayloadOptions {
|
|
793
|
+
provider?: WebhookSigningProvider;
|
|
794
|
+
timestamp?: number | string;
|
|
795
|
+
headerName?: string;
|
|
796
|
+
}
|
|
797
|
+
declare function createSignedWebhookPayload(payload: unknown, secret: string, options?: SignedWebhookPayloadOptions): SignedWebhookPayload;
|
|
798
|
+
declare function createStripeSignedWebhookPayload(payload: unknown, secret: string, options?: Omit<SignedWebhookPayloadOptions, 'provider'>): SignedWebhookPayload;
|
|
799
|
+
declare function createDLocalSignedWebhookPayload(payload: unknown, secret: string, options?: Omit<SignedWebhookPayloadOptions, 'provider'>): SignedWebhookPayload;
|
|
800
|
+
declare function createPaystackSignedWebhookPayload(payload: unknown, secret: string, options?: Omit<SignedWebhookPayloadOptions, 'provider'>): SignedWebhookPayload;
|
|
801
|
+
|
|
802
|
+
declare const DEFAULT_VAULT_EVENT_TYPES: readonly VaultEventType[];
|
|
803
|
+
|
|
804
|
+
interface ProviderWebhookPayload {
|
|
805
|
+
id?: string;
|
|
806
|
+
type?: string;
|
|
807
|
+
transactionId?: string;
|
|
808
|
+
providerEventId?: string;
|
|
809
|
+
data?: Record<string, unknown>;
|
|
810
|
+
timestamp?: string;
|
|
811
|
+
}
|
|
812
|
+
declare function normalizeWebhookEvent(provider: string, payload: ProviderWebhookPayload, rawPayload?: unknown): VaultEvent;
|
|
813
|
+
|
|
814
|
+
export { AdapterComplianceError, type AdapterMetadata, type AddressInput, type AuthorizeRequest, BatchBuffer, type CaptureRequest, type ChargeRequest, type CustomerInput, DEFAULT_IDEMPOTENCY_TTL_MS, DEFAULT_VAULT_EVENT_TYPES, DLocalAdapter, type IdempotencyRecord, type IdempotencyStore, type LoggerInterface, MemoryIdempotencyStore, MockAdapter, type MockAdapterHandlers, type MockAdapterOptions, type MockAdapterScenario, type MockAdapterScenarios, type PaymentAdapter, type PaymentAdapterConstructor, type PaymentMethodInfo, type PaymentMethodInput, type PaymentResult, type PaymentStatus, PaystackAdapter, PlatformConnector, type PlatformConnectorConfig, type PlatformRoutingDecision, type PlatformRoutingRequest, type PlatformTransactionReport, type PlatformWebhookForwardEvent, type ProviderConfig, type ProviderErrorHint, type ProviderErrorMappingContext, type ProviderWebhookPayload, type RefundRequest, type RefundResult, Router, type RouterOptions, type RoutingContext, type RoutingDecision, type RoutingMatch, type RoutingMatchValue, type RoutingPreference, type RoutingRule, type SignedWebhookPayload, type SignedWebhookPayloadOptions, type StatusChange, StripeAdapter, type TransactionStatus, VAULT_ERROR_CODE_DEFINITIONS, VaultClient, type VaultConfig, VaultConfigError, VaultError, type VaultErrorCategory, type VaultErrorContext, type VaultEvent, type VaultEventType, VaultIdempotencyConflictError, VaultNetworkError, VaultProviderError, VaultRoutingError, type VoidRequest, type VoidResult, type WebhookSigningProvider, WebhookVerificationError, buildVaultErrorDocsUrl, createAdapterComplianceHarness, createDLocalSignedWebhookPayload, createPaystackSignedWebhookPayload, createSignedWebhookPayload, createStripeSignedWebhookPayload, getVaultErrorCodeDefinition, hashIdempotencyPayload, isProviderErrorHint, mapProviderError, normalizeWebhookEvent, ruleMatchesContext, validatePaymentMethods, validatePaymentResult, validateRefundResult, validateTransactionStatus, validateVoidResult, validateWebhookEvent };
|