@delopay/sdk 0.5.1 → 0.6.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.
@@ -0,0 +1,2959 @@
1
+ // src/error.ts
2
+ var DelopayError = class extends Error {
3
+ constructor(message, options) {
4
+ super(message);
5
+ Object.setPrototypeOf(this, new.target.prototype);
6
+ this.name = "DelopayError";
7
+ this.status = options.status;
8
+ this.code = options.code;
9
+ this.type = options.type;
10
+ if (options.requestId !== void 0) this.requestId = options.requestId;
11
+ if (options.rawBody !== void 0) this.rawBody = options.rawBody;
12
+ }
13
+ };
14
+ var DelopayAuthenticationError = class extends DelopayError {
15
+ constructor(message = "Invalid API key", options) {
16
+ super(message, {
17
+ status: 401,
18
+ // Default to the generic "invalid API key" code, but let callers pass
19
+ // through the server-reported code (e.g. `UR_05` for unverified-email
20
+ // 401s) so they can differentiate between auth failure reasons.
21
+ code: options?.code || "AUTH_01",
22
+ type: options?.type || "authentication_error",
23
+ requestId: options?.requestId,
24
+ rawBody: options?.rawBody
25
+ });
26
+ Object.setPrototypeOf(this, new.target.prototype);
27
+ this.name = "DelopayAuthenticationError";
28
+ }
29
+ };
30
+
31
+ // src/resources/apiKeys.ts
32
+ var ApiKeys = class {
33
+ constructor(request) {
34
+ this.request = request;
35
+ }
36
+ /**
37
+ * Create a new API key for a merchant.
38
+ *
39
+ * @param merchantId - The merchant account ID.
40
+ * @param params - Key creation parameters (name, expiry, etc.).
41
+ * @returns The newly created key including the plaintext secret (shown once only).
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const { key_value } = await delopay.apiKeys.create('merch_123', { name: 'Production key' });
46
+ * ```
47
+ */
48
+ async create(merchantId, params) {
49
+ return this.request("POST", `/api_keys/${encodeURIComponent(merchantId)}`, { body: params });
50
+ }
51
+ /**
52
+ * Retrieve metadata about an API key (does not return the plaintext secret).
53
+ *
54
+ * @param merchantId - The merchant account ID.
55
+ * @param keyId - The API key ID.
56
+ * @returns The API key metadata.
57
+ */
58
+ async retrieve(merchantId, keyId) {
59
+ return this.request(
60
+ "GET",
61
+ `/api_keys/${encodeURIComponent(merchantId)}/${encodeURIComponent(keyId)}`
62
+ );
63
+ }
64
+ /**
65
+ * Update an API key's name or expiry.
66
+ *
67
+ * @param merchantId - The merchant account ID.
68
+ * @param keyId - The API key ID to update.
69
+ * @param params - Fields to update.
70
+ * @returns The updated API key metadata.
71
+ */
72
+ async update(merchantId, keyId, params) {
73
+ return this.request(
74
+ "POST",
75
+ `/api_keys/${encodeURIComponent(merchantId)}/${encodeURIComponent(keyId)}`,
76
+ { body: params }
77
+ );
78
+ }
79
+ /**
80
+ * Revoke an API key, immediately invalidating it.
81
+ *
82
+ * @param merchantId - The merchant account ID.
83
+ * @param keyId - The API key ID to revoke.
84
+ * @returns Revocation confirmation.
85
+ */
86
+ async revoke(merchantId, keyId) {
87
+ return this.request(
88
+ "DELETE",
89
+ `/api_keys/${encodeURIComponent(merchantId)}/${encodeURIComponent(keyId)}`
90
+ );
91
+ }
92
+ /**
93
+ * List all API keys for a merchant.
94
+ *
95
+ * @param merchantId - The merchant account ID.
96
+ * @returns Array of API key metadata objects.
97
+ */
98
+ async list(merchantId) {
99
+ return this.request("GET", `/api_keys/${encodeURIComponent(merchantId)}/list`);
100
+ }
101
+ };
102
+
103
+ // src/resources/authentication.ts
104
+ var Authentication = class {
105
+ constructor(request) {
106
+ this.request = request;
107
+ }
108
+ async create(params) {
109
+ return this.request("POST", "/authentication", { body: params });
110
+ }
111
+ async checkEligibility(authId) {
112
+ return this.request("POST", `/authentication/${encodeURIComponent(authId)}/eligibility`);
113
+ }
114
+ async authenticate(authId, params) {
115
+ return this.request("POST", `/authentication/${encodeURIComponent(authId)}/authenticate`, {
116
+ body: params
117
+ });
118
+ }
119
+ async sync(authId, params) {
120
+ return this.request("POST", `/authentication/${encodeURIComponent(authId)}/sync`, {
121
+ body: params
122
+ });
123
+ }
124
+ /** Redirect after authentication. `POST /authentication/{authId}/redirect` */
125
+ async redirect(authId, params) {
126
+ return this.request("POST", `/authentication/${encodeURIComponent(authId)}/redirect`, {
127
+ body: params
128
+ });
129
+ }
130
+ /** Enable authn methods token. `POST /authentication/{authId}/enabled_authn_methods_token` */
131
+ async enabledAuthnMethodsToken(authId, params) {
132
+ return this.request(
133
+ "POST",
134
+ `/authentication/${encodeURIComponent(authId)}/enabled_authn_methods_token`,
135
+ {
136
+ body: params
137
+ }
138
+ );
139
+ }
140
+ /** Submit eligibility check. `POST /authentication/{authId}/eligibility-check` */
141
+ async eligibilityCheck(authId, params) {
142
+ return this.request("POST", `/authentication/${encodeURIComponent(authId)}/eligibility-check`, {
143
+ body: params
144
+ });
145
+ }
146
+ };
147
+
148
+ // src/resources/billing.ts
149
+ var BillingAllocations = class {
150
+ constructor(request) {
151
+ this.request = request;
152
+ }
153
+ /**
154
+ * Transfer funds from the host merchant treasury into a shop's allocation.
155
+ *
156
+ * @param merchantId - The host merchant account ID.
157
+ * @param params - Transfer details (amount, target profile/shop ID).
158
+ * @returns The allocation transfer result.
159
+ */
160
+ async transferIn(merchantId, params) {
161
+ return this.request(
162
+ "POST",
163
+ `/billing/${encodeURIComponent(merchantId)}/allocations/transfer-in`,
164
+ { body: params }
165
+ );
166
+ }
167
+ /**
168
+ * Transfer funds from a shop's allocation back to the host merchant treasury.
169
+ *
170
+ * @param merchantId - The host merchant account ID.
171
+ * @param params - Transfer details (amount, source profile/shop ID).
172
+ * @returns The allocation transfer result.
173
+ */
174
+ async transferOut(merchantId, params) {
175
+ return this.request(
176
+ "POST",
177
+ `/billing/${encodeURIComponent(merchantId)}/allocations/transfer-out`,
178
+ {
179
+ body: params
180
+ }
181
+ );
182
+ }
183
+ /**
184
+ * List all shop balance allocations for a merchant.
185
+ *
186
+ * @param merchantId - The merchant account ID.
187
+ * @returns List of shop allocations.
188
+ */
189
+ async list(merchantId) {
190
+ return this.request("GET", `/billing/${encodeURIComponent(merchantId)}/allocations`);
191
+ }
192
+ /**
193
+ * Get the balance allocation for a specific shop.
194
+ *
195
+ * @param merchantId - The merchant account ID.
196
+ * @param profileId - The shop (business profile) ID.
197
+ * @returns The shop's balance allocation.
198
+ */
199
+ async get(merchantId, profileId) {
200
+ return this.request(
201
+ "GET",
202
+ `/billing/${encodeURIComponent(merchantId)}/allocations/${encodeURIComponent(profileId)}`
203
+ );
204
+ }
205
+ };
206
+ var Billing = class {
207
+ constructor(request) {
208
+ this.request = request;
209
+ this.allocations = new BillingAllocations(request);
210
+ }
211
+ /**
212
+ * Retrieve a merchant's billing profile (balance, status, auto-recharge config).
213
+ *
214
+ * @param merchantId - The merchant account ID.
215
+ * @returns The billing profile.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * const profile = await delopay.billing.getProfile('merch_123');
220
+ * console.log(profile.balance, profile.status);
221
+ * ```
222
+ */
223
+ async getProfile(merchantId) {
224
+ return this.request("GET", `/billing/${encodeURIComponent(merchantId)}`);
225
+ }
226
+ /**
227
+ * Start a Stripe SetupIntent flow to collect a payment card for auto-recharge.
228
+ *
229
+ * @param merchantId - The merchant account ID.
230
+ * @param params - Optional setup parameters.
231
+ * @returns The Stripe client secret needed to render the card element.
232
+ */
233
+ async setup(merchantId, params) {
234
+ return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/setup`, {
235
+ body: params
236
+ });
237
+ }
238
+ /**
239
+ * Confirm card setup after the Stripe SetupIntent completes on the frontend.
240
+ *
241
+ * @param merchantId - The merchant account ID.
242
+ * @param params - The Stripe SetupIntent ID to confirm.
243
+ * @returns The updated billing profile.
244
+ */
245
+ async completeSetup(merchantId, params) {
246
+ return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/setup/complete`, {
247
+ body: params
248
+ });
249
+ }
250
+ /**
251
+ * Manually top up a merchant's prepaid balance by charging their saved card.
252
+ *
253
+ * @param merchantId - The merchant account ID.
254
+ * @param params - Top-up amount and currency.
255
+ * @returns The top-up result.
256
+ */
257
+ async topup(merchantId, params) {
258
+ return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/topup`, {
259
+ body: params
260
+ });
261
+ }
262
+ /**
263
+ * List the balance ledger (credits and debits) for a merchant.
264
+ *
265
+ * @param merchantId - The merchant account ID.
266
+ * @param params - Optional pagination parameters.
267
+ * @returns The ledger entries.
268
+ */
269
+ async listLedger(merchantId, params) {
270
+ return this.request("GET", `/billing/${encodeURIComponent(merchantId)}/ledger`, {
271
+ query: params
272
+ });
273
+ }
274
+ /**
275
+ * Update auto-recharge configuration (threshold, top-up amount, enabled flag).
276
+ *
277
+ * @param merchantId - The merchant account ID.
278
+ * @param params - Auto-recharge settings to update.
279
+ * @returns The updated billing profile.
280
+ */
281
+ async updateAutoRecharge(merchantId, params) {
282
+ return this.request("PATCH", `/billing/${encodeURIComponent(merchantId)}/auto-recharge`, {
283
+ body: params
284
+ });
285
+ }
286
+ /**
287
+ * Admin: manually credit a merchant's balance (e.g. promotional credit).
288
+ *
289
+ * @param merchantId - The merchant account ID.
290
+ * @param params - Credit amount and reason.
291
+ * @returns The adjustment result.
292
+ */
293
+ async adminCredit(merchantId, params) {
294
+ return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/admin/credit`, {
295
+ body: params
296
+ });
297
+ }
298
+ /**
299
+ * Admin: manually debit a merchant's balance.
300
+ *
301
+ * @param merchantId - The merchant account ID.
302
+ * @param params - Debit amount and reason.
303
+ * @returns The adjustment result.
304
+ */
305
+ async adminDebit(merchantId, params) {
306
+ return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/admin/debit`, {
307
+ body: params
308
+ });
309
+ }
310
+ };
311
+
312
+ // src/resources/blocklist.ts
313
+ var Blocklist = class {
314
+ constructor(request) {
315
+ this.request = request;
316
+ }
317
+ async add(params) {
318
+ return this.request("POST", "/blocklist", { body: params });
319
+ }
320
+ async remove(params) {
321
+ return this.request("DELETE", "/blocklist", { body: params });
322
+ }
323
+ async list(params) {
324
+ return this.request("GET", "/blocklist", {
325
+ query: params
326
+ });
327
+ }
328
+ async toggle(params) {
329
+ return this.request("POST", "/blocklist/toggle", { body: params });
330
+ }
331
+ };
332
+
333
+ // src/resources/cardIssuers.ts
334
+ var CardIssuers = class {
335
+ constructor(request) {
336
+ this.request = request;
337
+ }
338
+ async create(params) {
339
+ return this.request("POST", "/card_issuers", { body: params });
340
+ }
341
+ async update(issuerId, params) {
342
+ return this.request("PUT", `/card_issuers/${encodeURIComponent(issuerId)}`, { body: params });
343
+ }
344
+ async list() {
345
+ return this.request("GET", "/card_issuers");
346
+ }
347
+ };
348
+
349
+ // src/resources/connectors.ts
350
+ var Connectors = class {
351
+ constructor(request) {
352
+ this.request = request;
353
+ }
354
+ async create(accountId, params) {
355
+ return this.request("POST", `/account/${encodeURIComponent(accountId)}/connectors`, {
356
+ body: params
357
+ });
358
+ }
359
+ async retrieve(accountId, connectorId) {
360
+ return this.request(
361
+ "GET",
362
+ `/account/${encodeURIComponent(accountId)}/connectors/${encodeURIComponent(connectorId)}`
363
+ );
364
+ }
365
+ async list(accountId) {
366
+ return this.request("GET", `/account/${encodeURIComponent(accountId)}/connectors`);
367
+ }
368
+ async update(accountId, connectorId, params) {
369
+ return this.request(
370
+ "POST",
371
+ `/account/${encodeURIComponent(accountId)}/connectors/${encodeURIComponent(connectorId)}`,
372
+ {
373
+ body: params
374
+ }
375
+ );
376
+ }
377
+ async delete(accountId, connectorId) {
378
+ return this.request(
379
+ "DELETE",
380
+ `/account/${encodeURIComponent(accountId)}/connectors/${encodeURIComponent(connectorId)}`
381
+ );
382
+ }
383
+ // --- Advanced operations (Task 4.8) ---
384
+ /** Verify connector credentials. `POST /account/connectors/verify` */
385
+ async verify(params) {
386
+ return this.request("POST", "/account/connectors/verify", { body: params });
387
+ }
388
+ /** Register a webhook for a connector. `POST /account/{merchantId}/connectors/webhooks/{connectorId}` */
389
+ async registerWebhook(merchantId, connectorId) {
390
+ return this.request(
391
+ "POST",
392
+ `/account/${encodeURIComponent(merchantId)}/connectors/webhooks/${encodeURIComponent(connectorId)}`
393
+ );
394
+ }
395
+ /** Get a webhook for a connector. `GET /account/{merchantId}/connectors/webhooks/{connectorId}` */
396
+ async getWebhook(merchantId, connectorId) {
397
+ return this.request(
398
+ "GET",
399
+ `/account/${encodeURIComponent(merchantId)}/connectors/webhooks/${encodeURIComponent(connectorId)}`
400
+ );
401
+ }
402
+ /** List available payment methods. `GET /account/payment_methods` */
403
+ async listPaymentMethods() {
404
+ return this.request("GET", "/account/payment_methods");
405
+ }
406
+ };
407
+
408
+ // src/resources/customers.ts
409
+ var Customers = class {
410
+ constructor(request) {
411
+ this.request = request;
412
+ }
413
+ /**
414
+ * Create a new customer.
415
+ *
416
+ * @param params - Customer creation parameters (name, email, phone, address, etc.).
417
+ * @returns The created customer.
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * const customer = await delopay.customers.create({
422
+ * email: 'alice@example.com',
423
+ * name: 'Alice Smith',
424
+ * });
425
+ * ```
426
+ */
427
+ async create(params) {
428
+ return this.request("POST", "/customers", { body: params });
429
+ }
430
+ /**
431
+ * Retrieve a customer by their ID.
432
+ *
433
+ * @param customerId - The unique customer ID.
434
+ * @returns The customer.
435
+ *
436
+ * @example
437
+ * ```typescript
438
+ * const customer = await delopay.customers.retrieve('cus_abc123');
439
+ * ```
440
+ */
441
+ async retrieve(customerId) {
442
+ return this.request("GET", `/customers/${encodeURIComponent(customerId)}`);
443
+ }
444
+ /**
445
+ * Update an existing customer's details.
446
+ *
447
+ * @param customerId - The customer ID to update.
448
+ * @param params - Fields to update (name, email, address, metadata, etc.).
449
+ * @returns The updated customer.
450
+ */
451
+ async update(customerId, params) {
452
+ return this.request("POST", `/customers/${encodeURIComponent(customerId)}`, { body: params });
453
+ }
454
+ /**
455
+ * Delete a customer and all their saved payment methods.
456
+ *
457
+ * @param customerId - The customer ID to delete.
458
+ * @returns The deleted customer object.
459
+ */
460
+ async delete(customerId) {
461
+ return this.request("DELETE", `/customers/${encodeURIComponent(customerId)}`);
462
+ }
463
+ /**
464
+ * List customers, optionally filtered by email.
465
+ *
466
+ * @param params - Optional filter and pagination parameters.
467
+ * @returns Array of customer objects.
468
+ */
469
+ async list(params) {
470
+ return this.request("GET", "/customers/list", {
471
+ query: params
472
+ });
473
+ }
474
+ // --- OLAP extensions (Task 4.6) ---
475
+ /** List customers with count. `GET /customers/list_with_count` */
476
+ async listWithCount(params) {
477
+ return this.request("GET", "/customers/list_with_count", {
478
+ query: params
479
+ });
480
+ }
481
+ /** List mandates for a customer. `GET /customers/{customerId}/mandates` */
482
+ async listMandates(customerId) {
483
+ return this.request("GET", `/customers/${encodeURIComponent(customerId)}/mandates`);
484
+ }
485
+ };
486
+
487
+ // src/resources/disputes.ts
488
+ var Disputes = class {
489
+ constructor(request) {
490
+ this.request = request;
491
+ }
492
+ /**
493
+ * Retrieve a dispute by its ID.
494
+ *
495
+ * @param disputeId - The unique dispute ID.
496
+ * @returns The dispute.
497
+ */
498
+ async retrieve(disputeId) {
499
+ return this.request("GET", `/disputes/${encodeURIComponent(disputeId)}`);
500
+ }
501
+ /**
502
+ * List disputes, optionally filtered by status, stage, or date range.
503
+ *
504
+ * @param params - Optional filter and pagination parameters.
505
+ * @returns Array of disputes.
506
+ */
507
+ async list(params) {
508
+ return this.request("GET", "/disputes/list", {
509
+ query: params
510
+ });
511
+ }
512
+ /**
513
+ * Accept a dispute, conceding the chargeback to the customer.
514
+ *
515
+ * @param disputeId - The dispute ID to accept.
516
+ * @returns The updated dispute.
517
+ */
518
+ async accept(disputeId) {
519
+ return this.request("POST", `/disputes/accept/${encodeURIComponent(disputeId)}`);
520
+ }
521
+ /**
522
+ * Submit evidence to challenge a dispute.
523
+ *
524
+ * @param params - Evidence details and the dispute ID to contest.
525
+ * @returns The updated dispute.
526
+ */
527
+ async submitEvidence(params) {
528
+ return this.request("POST", "/disputes/evidence", { body: params });
529
+ }
530
+ /**
531
+ * Attach evidence (e.g. file upload metadata) to a dispute.
532
+ *
533
+ * Uses `PUT /disputes/evidence`.
534
+ */
535
+ async attachEvidence(params) {
536
+ return this.request("PUT", "/disputes/evidence", { body: params });
537
+ }
538
+ /**
539
+ * Retrieve previously submitted evidence for a dispute.
540
+ *
541
+ * @param disputeId - The dispute ID.
542
+ * @returns The submitted evidence.
543
+ */
544
+ async retrieveEvidence(disputeId) {
545
+ return this.request("GET", `/disputes/evidence/${encodeURIComponent(disputeId)}`);
546
+ }
547
+ /**
548
+ * Delete submitted evidence for a dispute.
549
+ *
550
+ * @param params - Evidence request body identifying what to delete.
551
+ * @returns The updated dispute.
552
+ */
553
+ async deleteEvidence(params) {
554
+ return this.request("DELETE", "/disputes/evidence", { body: params });
555
+ }
556
+ // --- OLAP extensions (Task 4.4) ---
557
+ /** List disputes (profile-scoped). `GET /disputes/profile/list` */
558
+ async listByProfile(params) {
559
+ return this.request("GET", "/disputes/profile/list", {
560
+ query: params
561
+ });
562
+ }
563
+ /** Get dispute filter options. `GET /disputes/filter` */
564
+ async getFilters(params) {
565
+ return this.request("GET", "/disputes/filter", { query: params });
566
+ }
567
+ /** Get dispute filters (profile-scoped). `GET /disputes/profile/filter` */
568
+ async getFiltersByProfile(params) {
569
+ return this.request("GET", "/disputes/profile/filter", { query: params });
570
+ }
571
+ /** Get dispute aggregates. `GET /disputes/aggregate` */
572
+ async aggregate(params) {
573
+ return this.request("GET", "/disputes/aggregate", { query: params });
574
+ }
575
+ /** Get dispute aggregates (profile-scoped). `GET /disputes/profile/aggregate` */
576
+ async aggregateByProfile(params) {
577
+ return this.request("GET", "/disputes/profile/aggregate", { query: params });
578
+ }
579
+ /**
580
+ * Fetch the latest dispute state from the connector (gateway).
581
+ * `GET /disputes/{connectorId}/fetch`
582
+ *
583
+ * Note: the path parameter is the **connector dispute id** on the gateway, not the
584
+ * Delopay dispute id. Method is GET (not POST) and this method signature was
585
+ * previously wrong — callers depending on the old `POST /disputes/{id}/fetch_from_connector`
586
+ * path were silently hitting 404s.
587
+ */
588
+ async fetchFromConnector(connectorId) {
589
+ return this.request("GET", `/disputes/${encodeURIComponent(connectorId)}/fetch`);
590
+ }
591
+ };
592
+
593
+ // src/resources/ephemeralKeys.ts
594
+ var EphemeralKeys = class {
595
+ constructor(request) {
596
+ this.request = request;
597
+ }
598
+ /**
599
+ * Create an ephemeral key scoped to a specific customer.
600
+ *
601
+ * @param params - Customer ID and optional expiry.
602
+ * @returns The ephemeral key with its plaintext secret and expiry timestamp.
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * const ephKey = await delopay.ephemeralKeys.create({ customer_id: 'cus_123' });
607
+ * // Pass ephKey.secret to your mobile app.
608
+ * ```
609
+ */
610
+ async create(params) {
611
+ return this.request("POST", "/ephemeral_keys", { body: params });
612
+ }
613
+ /**
614
+ * Invalidate an ephemeral key before it expires.
615
+ *
616
+ * @param keyId - The ephemeral key ID to delete.
617
+ * @returns The deleted key object.
618
+ */
619
+ async delete(keyId) {
620
+ return this.request("DELETE", `/ephemeral_keys/${encodeURIComponent(keyId)}`);
621
+ }
622
+ };
623
+
624
+ // src/resources/events.ts
625
+ var Events = class {
626
+ constructor(request) {
627
+ this.request = request;
628
+ }
629
+ async list(merchantId, params) {
630
+ return this.request("POST", `/events/${encodeURIComponent(merchantId)}`, { body: params });
631
+ }
632
+ async listDeliveryAttempts(merchantId, eventId) {
633
+ return this.request(
634
+ "GET",
635
+ `/events/${encodeURIComponent(merchantId)}/${encodeURIComponent(eventId)}/attempts`
636
+ );
637
+ }
638
+ async retryDelivery(merchantId, eventId) {
639
+ return this.request(
640
+ "POST",
641
+ `/events/${encodeURIComponent(merchantId)}/${encodeURIComponent(eventId)}/retry`
642
+ );
643
+ }
644
+ // --- Profile-scoped listing (Task 4.12) ---
645
+ /** List events (profile-scoped). `POST /events/profile/list` */
646
+ async listByProfile(params) {
647
+ return this.request("POST", "/events/profile/list", { body: params });
648
+ }
649
+ };
650
+
651
+ // src/resources/fees.ts
652
+ var PlatformFees = class {
653
+ constructor(request) {
654
+ this.request = request;
655
+ }
656
+ /**
657
+ * Create a new platform fee schedule for a merchant (admin only).
658
+ *
659
+ * @param params - Fee schedule parameters (percentage, flat fee, min/max).
660
+ * @param merchantId - The merchant account to attach the schedule to.
661
+ * @returns The created fee schedule.
662
+ */
663
+ async create(params, merchantId) {
664
+ return this.request("POST", "/admin/fees", {
665
+ body: params,
666
+ query: { merchant_id: merchantId }
667
+ });
668
+ }
669
+ /**
670
+ * List all platform fee schedules for a merchant (admin only).
671
+ *
672
+ * @param merchantId - The merchant account ID.
673
+ * @returns Array of fee schedules.
674
+ */
675
+ async list(merchantId) {
676
+ return this.request("GET", "/admin/fees/list", {
677
+ query: { merchant_id: merchantId }
678
+ });
679
+ }
680
+ /**
681
+ * Retrieve a single fee schedule by ID (admin only).
682
+ *
683
+ * @param feeId - The fee schedule ID.
684
+ * @returns The fee schedule.
685
+ */
686
+ async retrieve(feeId) {
687
+ return this.request("GET", `/admin/fees/${encodeURIComponent(feeId)}`);
688
+ }
689
+ /**
690
+ * Update a fee schedule (admin only).
691
+ *
692
+ * @param feeId - The fee schedule ID to update.
693
+ * @param params - Fields to update.
694
+ * @returns The updated fee schedule.
695
+ */
696
+ async update(feeId, params) {
697
+ return this.request("PUT", `/admin/fees/${encodeURIComponent(feeId)}`, { body: params });
698
+ }
699
+ /**
700
+ * Delete a fee schedule (admin only).
701
+ *
702
+ * @param feeId - The fee schedule ID to delete.
703
+ * @returns The deleted fee schedule.
704
+ */
705
+ async delete(feeId) {
706
+ return this.request("DELETE", `/admin/fees/${encodeURIComponent(feeId)}`);
707
+ }
708
+ };
709
+ var MerchantFees = class {
710
+ constructor(request) {
711
+ this.request = request;
712
+ }
713
+ /**
714
+ * Create a merchant-scoped fee schedule override for a specific shop.
715
+ *
716
+ * @param params - Fee schedule parameters.
717
+ * @param merchantId - The merchant account ID.
718
+ * @returns The created fee schedule.
719
+ */
720
+ async create(params, merchantId) {
721
+ return this.request("POST", "/merchant_fees", {
722
+ body: params,
723
+ query: { merchant_id: merchantId }
724
+ });
725
+ }
726
+ /**
727
+ * List merchant-scoped fee schedules.
728
+ *
729
+ * @param merchantId - The merchant account ID.
730
+ * @returns Array of fee schedules.
731
+ */
732
+ async list(merchantId) {
733
+ return this.request("GET", "/merchant_fees/list", {
734
+ query: { merchant_id: merchantId }
735
+ });
736
+ }
737
+ /**
738
+ * Update a merchant-scoped fee schedule.
739
+ *
740
+ * @param feeId - The fee schedule ID to update.
741
+ * @param params - Fields to update.
742
+ * @returns The updated fee schedule.
743
+ */
744
+ async update(feeId, params) {
745
+ return this.request("PUT", `/merchant_fees/${encodeURIComponent(feeId)}`, { body: params });
746
+ }
747
+ /**
748
+ * Delete a merchant-scoped fee schedule.
749
+ *
750
+ * @param feeId - The fee schedule ID to delete.
751
+ * @returns The deleted fee schedule.
752
+ */
753
+ async delete(feeId) {
754
+ return this.request("DELETE", `/merchant_fees/${encodeURIComponent(feeId)}`);
755
+ }
756
+ };
757
+ var Fees = class {
758
+ constructor(request) {
759
+ this.platform = new PlatformFees(request);
760
+ this.merchant = new MerchantFees(request);
761
+ }
762
+ };
763
+
764
+ // src/resources/gsm.ts
765
+ var Gsm = class {
766
+ constructor(request) {
767
+ this.request = request;
768
+ }
769
+ async create(params) {
770
+ return this.request("POST", "/gsm", { body: params });
771
+ }
772
+ async retrieve(params) {
773
+ return this.request("POST", "/gsm/get", { body: params });
774
+ }
775
+ async update(params) {
776
+ return this.request("POST", "/gsm/update", { body: params });
777
+ }
778
+ async delete(params) {
779
+ return this.request("POST", "/gsm/delete", { body: params });
780
+ }
781
+ };
782
+
783
+ // src/resources/mandates.ts
784
+ var Mandates = class {
785
+ constructor(request) {
786
+ this.request = request;
787
+ }
788
+ /**
789
+ * Retrieve a mandate by its ID.
790
+ *
791
+ * @param mandateId - The unique mandate ID.
792
+ * @returns The mandate.
793
+ */
794
+ async retrieve(mandateId) {
795
+ return this.request("GET", `/mandates/${encodeURIComponent(mandateId)}`);
796
+ }
797
+ /**
798
+ * Revoke an active mandate, preventing future charges.
799
+ *
800
+ * @param mandateId - The mandate ID to revoke.
801
+ * @returns Revocation confirmation.
802
+ */
803
+ async revoke(mandateId) {
804
+ return this.request("POST", `/mandates/revoke/${encodeURIComponent(mandateId)}`);
805
+ }
806
+ /**
807
+ * List mandates, optionally filtered by customer or status.
808
+ *
809
+ * @param params - Optional filter and pagination parameters.
810
+ * @returns Array of mandates.
811
+ */
812
+ async list(params) {
813
+ return this.request("GET", "/mandates/list", {
814
+ query: params
815
+ });
816
+ }
817
+ };
818
+
819
+ // src/resources/merchantAccounts.ts
820
+ var MerchantAccounts = class {
821
+ constructor(request) {
822
+ this.request = request;
823
+ }
824
+ async create(params) {
825
+ return this.request("POST", "/accounts", { body: params });
826
+ }
827
+ async retrieve(accountId) {
828
+ return this.request("GET", `/accounts/${encodeURIComponent(accountId)}`);
829
+ }
830
+ async update(accountId, params) {
831
+ return this.request("POST", `/accounts/${encodeURIComponent(accountId)}`, { body: params });
832
+ }
833
+ async delete(accountId) {
834
+ return this.request("DELETE", `/accounts/${encodeURIComponent(accountId)}`);
835
+ }
836
+ // --- Advanced operations (Task 4.9) ---
837
+ /** List all merchant accounts. `GET /accounts/list` */
838
+ async list() {
839
+ return this.request("GET", "/accounts/list");
840
+ }
841
+ /** Toggle key-value store for a merchant. `POST /accounts/{accountId}/kv` */
842
+ async toggleKv(accountId) {
843
+ return this.request("POST", `/accounts/${encodeURIComponent(accountId)}/kv`);
844
+ }
845
+ /** Get KV status for a merchant. `GET /accounts/{accountId}/kv` */
846
+ async getKvStatus(accountId) {
847
+ return this.request("GET", `/accounts/${encodeURIComponent(accountId)}/kv`);
848
+ }
849
+ /** Transfer keys between merchants. `POST /accounts/transfer` */
850
+ async transferKeys(params) {
851
+ return this.request("POST", "/accounts/transfer", { body: params });
852
+ }
853
+ };
854
+
855
+ // src/resources/paymentLinks.ts
856
+ var PaymentLinks = class {
857
+ constructor(request) {
858
+ this.request = request;
859
+ }
860
+ /**
861
+ * Retrieve a payment link by its ID.
862
+ *
863
+ * @param linkId - The unique payment link ID.
864
+ * @returns The payment link details.
865
+ */
866
+ async retrieve(linkId) {
867
+ return this.request("GET", `/payment_link/${encodeURIComponent(linkId)}`);
868
+ }
869
+ /**
870
+ * List payment links, optionally filtered by status or date range.
871
+ *
872
+ * @param params - Optional filter and pagination parameters.
873
+ * @returns Paginated list of payment links.
874
+ */
875
+ async list(params) {
876
+ return this.request("POST", "/payment_link/list", { body: params });
877
+ }
878
+ /** Initiate (render) a payment link page. `GET /payment_link/{merchantId}/{paymentId}` */
879
+ async initiate(merchantId, paymentId) {
880
+ return this.request(
881
+ "GET",
882
+ `/payment_link/${encodeURIComponent(merchantId)}/${encodeURIComponent(paymentId)}`
883
+ );
884
+ }
885
+ /** Get payment link status. `GET /payment_linkstatus/{merchantId}/{paymentId}` */
886
+ async status(merchantId, paymentId) {
887
+ return this.request(
888
+ "GET",
889
+ `/payment_linkstatus/${encodeURIComponent(merchantId)}/${encodeURIComponent(paymentId)}`
890
+ );
891
+ }
892
+ };
893
+
894
+ // src/resources/paymentMethods.ts
895
+ var PaymentMethods = class {
896
+ constructor(request) {
897
+ this.request = request;
898
+ }
899
+ /**
900
+ * Save a new payment method (card, bank account, wallet, etc.).
901
+ *
902
+ * @param params - Payment method data including type and card/bank details.
903
+ * @returns The saved payment method.
904
+ *
905
+ * @example
906
+ * ```typescript
907
+ * const pm = await delopay.paymentMethods.create({
908
+ * payment_method: 'card',
909
+ * customer_id: 'cus_123',
910
+ * client_secret: 'cs_...',
911
+ * });
912
+ * ```
913
+ */
914
+ async create(params) {
915
+ return this.request("POST", "/payment_methods", { body: params });
916
+ }
917
+ /**
918
+ * Retrieve a saved payment method by its ID.
919
+ *
920
+ * @param methodId - The payment method ID.
921
+ * @returns The payment method.
922
+ */
923
+ async retrieve(methodId) {
924
+ return this.request("GET", `/payment_methods/${encodeURIComponent(methodId)}`);
925
+ }
926
+ /**
927
+ * Update an existing payment method (e.g. update card expiry).
928
+ *
929
+ * @param methodId - The payment method ID to update.
930
+ * @param params - Fields to update (card expiry, holder name, etc.).
931
+ * @returns The updated payment method.
932
+ */
933
+ async update(methodId, params) {
934
+ return this.request("POST", `/payment_methods/${encodeURIComponent(methodId)}/update`, {
935
+ body: params
936
+ });
937
+ }
938
+ /**
939
+ * Delete a saved payment method.
940
+ *
941
+ * @param methodId - The payment method ID to delete.
942
+ * @returns Deletion confirmation.
943
+ */
944
+ async delete(methodId) {
945
+ return this.request("DELETE", `/payment_methods/${encodeURIComponent(methodId)}`);
946
+ }
947
+ /**
948
+ * List payment methods using a client secret.
949
+ *
950
+ * @param params - Filter by `client_secret`.
951
+ * @returns Array of payment methods.
952
+ */
953
+ async list(params) {
954
+ return this.request("GET", "/payment_methods", {
955
+ query: params
956
+ });
957
+ }
958
+ /**
959
+ * List all saved payment methods for a customer, optionally filtered.
960
+ *
961
+ * @param customerId - The customer ID.
962
+ * @param params - Optional filters: `client_secret`, `accepted_countries`, `accepted_currencies`,
963
+ * `amount`, `recurring_enabled`, `installment_payment_enabled`, `limit`, `card_networks`.
964
+ * @returns Customer's saved payment methods.
965
+ *
966
+ * @example
967
+ * ```typescript
968
+ * const { customer_payment_methods } = await delopay.paymentMethods.listForCustomer(
969
+ * 'cus_123',
970
+ * { accepted_currencies: ['EUR'], amount: 5000 },
971
+ * );
972
+ * ```
973
+ */
974
+ async listForCustomer(customerId, params) {
975
+ return this.request("GET", `/customers/${encodeURIComponent(customerId)}/payment_methods`, {
976
+ query: params
977
+ });
978
+ }
979
+ /**
980
+ * Set a payment method as the default for a customer.
981
+ *
982
+ * @param customerId - The customer ID.
983
+ * @param methodId - The payment method ID to set as default.
984
+ * @returns The updated payment method.
985
+ */
986
+ async setDefault(customerId, methodId) {
987
+ return this.request(
988
+ "POST",
989
+ `/customers/${encodeURIComponent(customerId)}/payment_methods/${encodeURIComponent(methodId)}/default`
990
+ );
991
+ }
992
+ // --- Advanced operations (Task 3.3) ---
993
+ /** Migrate a payment method. `POST /payment_methods/migrate` */
994
+ async migrate(params) {
995
+ return this.request("POST", "/payment_methods/migrate", { body: params });
996
+ }
997
+ /** Batch migrate payment methods. `POST /payment_methods/migrate-batch` */
998
+ async migrateBatch(params) {
999
+ return this.request("POST", "/payment_methods/migrate-batch", { body: params });
1000
+ }
1001
+ /** Batch update payment methods. `POST /payment_methods/update-batch` */
1002
+ async updateBatch(params) {
1003
+ return this.request("POST", "/payment_methods/update-batch", { body: params });
1004
+ }
1005
+ /** Batch retrieve payment methods. `GET /payment_methods/batch` */
1006
+ async batchRetrieve(params) {
1007
+ return this.request("GET", "/payment_methods/batch", { query: params });
1008
+ }
1009
+ /** Tokenize a card. `POST /payment_methods/tokenize-card` */
1010
+ async tokenizeCard(params) {
1011
+ return this.request("POST", "/payment_methods/tokenize-card", { body: params });
1012
+ }
1013
+ /** Batch tokenize cards. `POST /payment_methods/tokenize-card-batch` */
1014
+ async tokenizeCardBatch(params) {
1015
+ return this.request("POST", "/payment_methods/tokenize-card-batch", { body: params });
1016
+ }
1017
+ /** Initiate payment method collect link flow. `POST /payment_methods/collect` */
1018
+ async collect(params) {
1019
+ return this.request("POST", "/payment_methods/collect", { body: params });
1020
+ }
1021
+ /** Save a payment method. `POST /payment_methods/{methodId}/save` */
1022
+ async save(methodId, params) {
1023
+ return this.request("POST", `/payment_methods/${encodeURIComponent(methodId)}/save`, {
1024
+ body: params
1025
+ });
1026
+ }
1027
+ /** Create payment method auth link token. `POST /payment_methods/auth/link` */
1028
+ async createAuthLink(params) {
1029
+ return this.request("POST", "/payment_methods/auth/link", { body: params });
1030
+ }
1031
+ /** Exchange payment method auth token. `POST /payment_methods/auth/exchange` */
1032
+ async exchangeAuthToken(params) {
1033
+ return this.request("POST", "/payment_methods/auth/exchange", { body: params });
1034
+ }
1035
+ /** Tokenize card using existing PM. `POST /payment_methods/{methodId}/tokenize-card` */
1036
+ async tokenizeCardForMethod(methodId, params) {
1037
+ return this.request("POST", `/payment_methods/${encodeURIComponent(methodId)}/tokenize-card`, {
1038
+ body: params
1039
+ });
1040
+ }
1041
+ };
1042
+
1043
+ // src/resources/payments.ts
1044
+ var Payments = class {
1045
+ constructor(request) {
1046
+ this.request = request;
1047
+ }
1048
+ /**
1049
+ * Create a new payment intent.
1050
+ *
1051
+ * @param params - Payment creation parameters including amount and currency.
1052
+ * @returns The created payment intent.
1053
+ *
1054
+ * @example
1055
+ * ```typescript
1056
+ * const payment = await delopay.payments.create({
1057
+ * amount: 5000,
1058
+ * currency: 'EUR',
1059
+ * customer_id: 'cus_123',
1060
+ * });
1061
+ * ```
1062
+ */
1063
+ async create(params) {
1064
+ return this.request("POST", "/payments", { body: params });
1065
+ }
1066
+ /**
1067
+ * Retrieve a payment by its ID.
1068
+ *
1069
+ * @param paymentId - The unique payment intent ID.
1070
+ * @returns The payment intent.
1071
+ *
1072
+ * @example
1073
+ * ```typescript
1074
+ * const payment = await delopay.payments.retrieve('pay_abc123');
1075
+ * ```
1076
+ */
1077
+ async retrieve(paymentId) {
1078
+ return this.request("GET", `/payments/${encodeURIComponent(paymentId)}`);
1079
+ }
1080
+ /**
1081
+ * Update an existing payment intent before it is confirmed.
1082
+ *
1083
+ * @param paymentId - The payment intent ID to update.
1084
+ * @param params - Fields to update (amount, currency, metadata, etc.).
1085
+ * @returns The updated payment intent.
1086
+ */
1087
+ async update(paymentId, params) {
1088
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}`, { body: params });
1089
+ }
1090
+ /**
1091
+ * Confirm a payment intent, triggering authorisation with the selected gateway.
1092
+ *
1093
+ * @param paymentId - The payment intent ID to confirm.
1094
+ * @param params - Confirmation parameters (payment method data, return URL, etc.).
1095
+ * @returns The updated payment intent.
1096
+ */
1097
+ async confirm(paymentId, params) {
1098
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/confirm`, {
1099
+ body: params
1100
+ });
1101
+ }
1102
+ /**
1103
+ * Capture a previously authorised payment.
1104
+ *
1105
+ * @param paymentId - The payment intent ID to capture.
1106
+ * @param params - Optional capture parameters (partial capture amount, etc.).
1107
+ * @returns The updated payment intent.
1108
+ */
1109
+ async capture(paymentId, params) {
1110
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/capture`, {
1111
+ body: params
1112
+ });
1113
+ }
1114
+ /**
1115
+ * Cancel a payment intent that has not yet been captured.
1116
+ *
1117
+ * @param paymentId - The payment intent ID to cancel.
1118
+ * @param params - Optional cancellation reason.
1119
+ * @returns The updated payment intent.
1120
+ */
1121
+ async cancel(paymentId, params) {
1122
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/cancel`, {
1123
+ body: params
1124
+ });
1125
+ }
1126
+ /**
1127
+ * List payment intents, optionally filtered by customer or date range.
1128
+ *
1129
+ * @param params - Optional filter and pagination parameters.
1130
+ * @returns Paginated list of payment intents.
1131
+ *
1132
+ * @example
1133
+ * ```typescript
1134
+ * const { data } = await delopay.payments.list({ customer_id: 'cus_123', limit: 25 });
1135
+ * ```
1136
+ */
1137
+ async list(params) {
1138
+ return this.request("GET", "/payments/list", {
1139
+ query: params
1140
+ });
1141
+ }
1142
+ // --- Advanced operations (Task 3.2) ---
1143
+ /** Generate session tokens. `POST /payments/session_tokens` */
1144
+ async sessionTokens(params) {
1145
+ return this.request("POST", "/payments/session_tokens", { body: params });
1146
+ }
1147
+ /** Retrieve payment with gateway credentials. `POST /payments/sync` */
1148
+ async sync(params) {
1149
+ return this.request("POST", "/payments/sync", { body: params });
1150
+ }
1151
+ /** Cancel after partial capture. `POST /payments/{paymentId}/cancel_post_capture` */
1152
+ async cancelPostCapture(paymentId, params) {
1153
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/cancel_post_capture`, {
1154
+ body: params
1155
+ });
1156
+ }
1157
+ /** Incrementally authorize more funds. `POST /payments/{paymentId}/incremental_authorization` */
1158
+ async incrementalAuthorization(paymentId, params) {
1159
+ return this.request(
1160
+ "POST",
1161
+ `/payments/${encodeURIComponent(paymentId)}/incremental_authorization`,
1162
+ {
1163
+ body: params
1164
+ }
1165
+ );
1166
+ }
1167
+ /** Extend authorization window. `POST /payments/{paymentId}/extend_authorization` */
1168
+ async extendAuthorization(paymentId, params) {
1169
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/extend_authorization`, {
1170
+ body: params
1171
+ });
1172
+ }
1173
+ /** Complete authorization. `POST /payments/{paymentId}/complete_authorize` */
1174
+ async completeAuthorize(paymentId, params) {
1175
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/complete_authorize`, {
1176
+ body: params
1177
+ });
1178
+ }
1179
+ /** Dynamic tax calculation. `POST /payments/{paymentId}/calculate_tax` */
1180
+ async calculateTax(paymentId, params) {
1181
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/calculate_tax`, {
1182
+ body: params
1183
+ });
1184
+ }
1185
+ /** Update payment metadata. `POST /payments/{paymentId}/update_metadata` */
1186
+ async updateMetadata(paymentId, params) {
1187
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/update_metadata`, {
1188
+ body: params
1189
+ });
1190
+ }
1191
+ /** Retrieve extended card info. `GET /payments/{paymentId}/extended_card_info` */
1192
+ async extendedCardInfo(paymentId) {
1193
+ return this.request("GET", `/payments/${encodeURIComponent(paymentId)}/extended_card_info`);
1194
+ }
1195
+ // --- OLAP extensions (Task 4.2) ---
1196
+ /** List payments (profile-scoped). `GET /payments/profile/list` */
1197
+ async listByProfile(params) {
1198
+ return this.request("GET", "/payments/profile/list", {
1199
+ query: params
1200
+ });
1201
+ }
1202
+ /** List payments across all shops. `GET /payments/list-all-shops` */
1203
+ async listAllShops(params) {
1204
+ return this.request("GET", "/payments/list-all-shops", {
1205
+ query: params
1206
+ });
1207
+ }
1208
+ /** List payments by filter (POST body). `POST /payments/list` */
1209
+ async listByFilter(params) {
1210
+ return this.request("POST", "/payments/list", { body: params });
1211
+ }
1212
+ /** Get payment filter options. `POST /payments/filter` */
1213
+ async getFilters(params) {
1214
+ return this.request("POST", "/payments/filter", { body: params });
1215
+ }
1216
+ /** Get payment filters (v2). `GET /payments/v2/filter` */
1217
+ async getFiltersV2(params) {
1218
+ return this.request("GET", "/payments/v2/filter", { query: params });
1219
+ }
1220
+ /** Get payment aggregates. `GET /payments/aggregate` */
1221
+ async aggregate(params) {
1222
+ return this.request("GET", "/payments/aggregate", { query: params });
1223
+ }
1224
+ /** Get payment aggregates (profile-scoped). `GET /payments/profile/aggregate` */
1225
+ async aggregateByProfile(params) {
1226
+ return this.request("GET", "/payments/profile/aggregate", { query: params });
1227
+ }
1228
+ /** Manually update payment status. `PUT /payments/{paymentId}/manual-update` */
1229
+ async manualUpdate(paymentId, params) {
1230
+ return this.request("PUT", `/payments/${encodeURIComponent(paymentId)}/manual-update`, {
1231
+ body: params
1232
+ });
1233
+ }
1234
+ /** Approve a payment waiting for review. `POST /payments/{paymentId}/approve` */
1235
+ async approve(paymentId, params) {
1236
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/approve`, {
1237
+ body: params
1238
+ });
1239
+ }
1240
+ /** Reject a payment waiting for review. `POST /payments/{paymentId}/reject` */
1241
+ async reject(paymentId, params) {
1242
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/reject`, {
1243
+ body: params
1244
+ });
1245
+ }
1246
+ /** Initiate external 3DS authentication. `POST /payments/{paymentId}/3ds/authentication` */
1247
+ async threeDsAuthentication(paymentId, params) {
1248
+ return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/3ds/authentication`, {
1249
+ body: params
1250
+ });
1251
+ }
1252
+ };
1253
+
1254
+ // src/resources/payouts.ts
1255
+ var Payouts = class {
1256
+ constructor(request) {
1257
+ this.request = request;
1258
+ }
1259
+ /**
1260
+ * Create a new payout.
1261
+ *
1262
+ * @param params - Payout parameters including amount, currency, and destination.
1263
+ * @returns The created payout.
1264
+ *
1265
+ * @example
1266
+ * ```typescript
1267
+ * const payout = await delopay.payouts.create({
1268
+ * amount: 10000,
1269
+ * currency: 'EUR',
1270
+ * customer_id: 'cus_123',
1271
+ * });
1272
+ * ```
1273
+ */
1274
+ async create(params) {
1275
+ return this.request("POST", "/payouts/create", { body: params });
1276
+ }
1277
+ /**
1278
+ * Retrieve a payout by its ID.
1279
+ *
1280
+ * @param payoutId - The unique payout ID.
1281
+ * @returns The payout.
1282
+ */
1283
+ async retrieve(payoutId) {
1284
+ return this.request("GET", `/payouts/${encodeURIComponent(payoutId)}`);
1285
+ }
1286
+ /**
1287
+ * Update a payout before it is confirmed.
1288
+ *
1289
+ * @param payoutId - The payout ID to update.
1290
+ * @param params - Fields to update.
1291
+ * @returns The updated payout.
1292
+ */
1293
+ async update(payoutId, params) {
1294
+ return this.request("PUT", `/payouts/${encodeURIComponent(payoutId)}`, { body: params });
1295
+ }
1296
+ /**
1297
+ * Confirm a payout, triggering the actual transfer.
1298
+ *
1299
+ * @param payoutId - The payout ID to confirm.
1300
+ * @param params - Optional confirmation parameters.
1301
+ * @returns The updated payout.
1302
+ */
1303
+ async confirm(payoutId, params) {
1304
+ return this.request("POST", `/payouts/${encodeURIComponent(payoutId)}/confirm`, {
1305
+ body: params
1306
+ });
1307
+ }
1308
+ /**
1309
+ * Cancel a payout before it is fulfilled.
1310
+ *
1311
+ * @param payoutId - The payout ID to cancel.
1312
+ * @returns The cancelled payout.
1313
+ */
1314
+ async cancel(payoutId) {
1315
+ return this.request("POST", `/payouts/${encodeURIComponent(payoutId)}/cancel`);
1316
+ }
1317
+ /**
1318
+ * Mark a payout as fulfilled (manual confirmation of successful transfer).
1319
+ *
1320
+ * @param payoutId - The payout ID to fulfil.
1321
+ * @returns The fulfilled payout.
1322
+ */
1323
+ async fulfill(payoutId) {
1324
+ return this.request("POST", `/payouts/${encodeURIComponent(payoutId)}/fulfill`);
1325
+ }
1326
+ /**
1327
+ * List payouts, optionally filtered by status or date range.
1328
+ *
1329
+ * @param params - Optional filter and pagination parameters.
1330
+ * @returns Paginated list of payouts.
1331
+ */
1332
+ async list(params) {
1333
+ return this.request("GET", "/payouts/list", {
1334
+ query: params
1335
+ });
1336
+ }
1337
+ // --- OLAP extensions (Task 4.5) ---
1338
+ /** List payouts (profile-scoped). `GET /payouts/profile/list` */
1339
+ async listByProfile(params) {
1340
+ return this.request("GET", "/payouts/profile/list", {
1341
+ query: params
1342
+ });
1343
+ }
1344
+ /** List payouts by filter (POST body). `POST /payouts/list` */
1345
+ async listByFilter(params) {
1346
+ return this.request("POST", "/payouts/list", { body: params });
1347
+ }
1348
+ /** Get payout filter options. `POST /payouts/filter` */
1349
+ async getFilters(params) {
1350
+ return this.request("POST", "/payouts/filter", { body: params });
1351
+ }
1352
+ /** Get payout filters (profile-scoped). `POST /payouts/profile/filter` */
1353
+ async getFiltersByProfile(params) {
1354
+ return this.request("POST", "/payouts/profile/filter", { body: params });
1355
+ }
1356
+ /** Get payout aggregates. `GET /payouts/aggregate` */
1357
+ async aggregate(params) {
1358
+ return this.request("GET", "/payouts/aggregate", { query: params });
1359
+ }
1360
+ /** Get payout aggregates (profile-scoped). `GET /payouts/profile/aggregate` */
1361
+ async aggregateByProfile(params) {
1362
+ return this.request("GET", "/payouts/profile/aggregate", { query: params });
1363
+ }
1364
+ /** Manually update payout status. `PUT /payouts/{payoutId}/manual-update` */
1365
+ async manualUpdate(payoutId, params) {
1366
+ return this.request("PUT", `/payouts/${encodeURIComponent(payoutId)}/manual-update`, {
1367
+ body: params
1368
+ });
1369
+ }
1370
+ };
1371
+
1372
+ // src/resources/poll.ts
1373
+ var Poll = class {
1374
+ constructor(request) {
1375
+ this.request = request;
1376
+ }
1377
+ async getStatus(pollId) {
1378
+ return this.request("GET", `/poll/status/${encodeURIComponent(pollId)}`);
1379
+ }
1380
+ };
1381
+
1382
+ // src/resources/profileAcquirers.ts
1383
+ var ProfileAcquirers = class {
1384
+ constructor(request) {
1385
+ this.request = request;
1386
+ }
1387
+ async create(params) {
1388
+ return this.request("POST", "/profile_acquirer", { body: params });
1389
+ }
1390
+ async update(profileId, profileAcquirerId, params) {
1391
+ return this.request(
1392
+ "POST",
1393
+ `/profile_acquirer/${encodeURIComponent(profileId)}/${encodeURIComponent(profileAcquirerId)}`,
1394
+ {
1395
+ body: params
1396
+ }
1397
+ );
1398
+ }
1399
+ };
1400
+
1401
+ // src/resources/profiles.ts
1402
+ var Profiles = class {
1403
+ constructor(request) {
1404
+ this.request = request;
1405
+ }
1406
+ async create(accountId, params) {
1407
+ return this.request("POST", `/account/${encodeURIComponent(accountId)}/business_profile`, {
1408
+ body: params
1409
+ });
1410
+ }
1411
+ async retrieve(accountId, profileId) {
1412
+ return this.request(
1413
+ "GET",
1414
+ `/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}`
1415
+ );
1416
+ }
1417
+ async list(accountId) {
1418
+ return this.request("GET", `/account/${encodeURIComponent(accountId)}/business_profile`);
1419
+ }
1420
+ async update(accountId, profileId, params) {
1421
+ return this.request(
1422
+ "POST",
1423
+ `/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}`,
1424
+ {
1425
+ body: params
1426
+ }
1427
+ );
1428
+ }
1429
+ async delete(accountId, profileId) {
1430
+ return this.request(
1431
+ "DELETE",
1432
+ `/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}`
1433
+ );
1434
+ }
1435
+ // --- Advanced operations (Task 4.8) ---
1436
+ /** Toggle extended card info for a profile. `POST /account/{accountId}/business_profile/{profileId}/toggle_extended_card_info` */
1437
+ async toggleExtendedCardInfo(accountId, profileId) {
1438
+ return this.request(
1439
+ "POST",
1440
+ `/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}/toggle_extended_card_info`
1441
+ );
1442
+ }
1443
+ /** Toggle connector agnostic MIT. `POST /account/{accountId}/business_profile/{profileId}/toggle_connector_agnostic_mit` */
1444
+ async toggleConnectorAgnosticMit(accountId, profileId) {
1445
+ return this.request(
1446
+ "POST",
1447
+ `/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}/toggle_connector_agnostic_mit`
1448
+ );
1449
+ }
1450
+ };
1451
+
1452
+ // src/resources/projects.ts
1453
+ var Projects = class {
1454
+ constructor(request) {
1455
+ this.request = request;
1456
+ }
1457
+ /**
1458
+ * Create a new project under a merchant account.
1459
+ *
1460
+ * @param params - Project creation parameters (name, description, etc.).
1461
+ * @param merchantId - The merchant account ID that owns this project.
1462
+ * @returns The created project.
1463
+ *
1464
+ * @example
1465
+ * ```typescript
1466
+ * const project = await delopay.projects.create({ name: 'EU Stores' }, 'merch_123');
1467
+ * ```
1468
+ */
1469
+ async create(params, merchantId) {
1470
+ return this.request("POST", "/projects", {
1471
+ body: params,
1472
+ query: { merchant_id: merchantId }
1473
+ });
1474
+ }
1475
+ /**
1476
+ * Retrieve a project by its ID.
1477
+ *
1478
+ * @param projectId - The unique project ID.
1479
+ * @returns The project.
1480
+ */
1481
+ async retrieve(projectId) {
1482
+ return this.request("GET", `/projects/${encodeURIComponent(projectId)}`);
1483
+ }
1484
+ /**
1485
+ * Update a project's details.
1486
+ *
1487
+ * @param projectId - The project ID to update.
1488
+ * @param params - Fields to update.
1489
+ * @returns The updated project.
1490
+ */
1491
+ async update(projectId, params) {
1492
+ return this.request("PUT", `/projects/${encodeURIComponent(projectId)}`, { body: params });
1493
+ }
1494
+ /**
1495
+ * Delete a project.
1496
+ *
1497
+ * @param projectId - The project ID to delete.
1498
+ * @returns The deleted project object.
1499
+ */
1500
+ async delete(projectId) {
1501
+ return this.request("DELETE", `/projects/${encodeURIComponent(projectId)}`);
1502
+ }
1503
+ /**
1504
+ * List all projects for a merchant.
1505
+ *
1506
+ * @param merchantId - The merchant account ID.
1507
+ * @returns Array of projects.
1508
+ */
1509
+ async list(merchantId) {
1510
+ return this.request("GET", "/projects/list", {
1511
+ query: { merchant_id: merchantId }
1512
+ });
1513
+ }
1514
+ /**
1515
+ * Get aggregate payment statistics across all projects for a merchant.
1516
+ *
1517
+ * @param merchantId - The merchant account ID.
1518
+ * @returns Project statistics.
1519
+ */
1520
+ async stats(merchantId) {
1521
+ return this.request("GET", "/projects/stats", {
1522
+ query: { merchant_id: merchantId }
1523
+ });
1524
+ }
1525
+ /**
1526
+ * Get a high-level overview (volume, counts, top connectors) for a merchant.
1527
+ *
1528
+ * @param merchantId - The merchant account ID.
1529
+ * @returns Merchant overview data.
1530
+ */
1531
+ async overview(merchantId) {
1532
+ return this.request("GET", "/projects/overview", {
1533
+ query: { merchant_id: merchantId }
1534
+ });
1535
+ }
1536
+ };
1537
+
1538
+ // src/resources/refunds.ts
1539
+ var Refunds = class {
1540
+ constructor(request) {
1541
+ this.request = request;
1542
+ }
1543
+ /**
1544
+ * Create a refund for a payment.
1545
+ *
1546
+ * @param params - Refund parameters, including the required `payment_id` and optional amount.
1547
+ * @returns The created refund.
1548
+ *
1549
+ * @example
1550
+ * ```typescript
1551
+ * const refund = await delopay.refunds.create({
1552
+ * payment_id: 'pay_abc123',
1553
+ * amount: 2500, // partial refund of 25.00 EUR
1554
+ * });
1555
+ * ```
1556
+ */
1557
+ async create(params) {
1558
+ return this.request("POST", "/refunds", { body: params });
1559
+ }
1560
+ /**
1561
+ * Retrieve a refund by its ID.
1562
+ *
1563
+ * @param refundId - The unique refund ID.
1564
+ * @returns The refund.
1565
+ *
1566
+ * @example
1567
+ * ```typescript
1568
+ * const refund = await delopay.refunds.retrieve('ref_abc123');
1569
+ * ```
1570
+ */
1571
+ async retrieve(refundId) {
1572
+ return this.request("GET", `/refunds/${encodeURIComponent(refundId)}`);
1573
+ }
1574
+ /**
1575
+ * Update the reason or metadata on an existing refund.
1576
+ *
1577
+ * @param refundId - The refund ID to update.
1578
+ * @param params - Fields to update (reason, metadata).
1579
+ * @returns The updated refund.
1580
+ */
1581
+ async update(refundId, params) {
1582
+ return this.request("POST", `/refunds/${encodeURIComponent(refundId)}`, { body: params });
1583
+ }
1584
+ /**
1585
+ * List refunds, optionally filtered by payment, status, or date range.
1586
+ *
1587
+ * @param params - Optional filter and pagination parameters.
1588
+ * @returns Paginated list of refunds.
1589
+ */
1590
+ async list(params) {
1591
+ return this.request("POST", "/refunds/list", { body: params });
1592
+ }
1593
+ // --- OLAP extensions (Task 4.3) ---
1594
+ /** List refunds (profile-scoped). `POST /refunds/profile/list` */
1595
+ async listByProfile(params) {
1596
+ return this.request("POST", "/refunds/profile/list", { body: params });
1597
+ }
1598
+ /** Get refund filter options. `POST /refunds/filter` */
1599
+ async getFilters(params) {
1600
+ return this.request("POST", "/refunds/filter", { body: params });
1601
+ }
1602
+ /** Get refund filters (v2). `GET /refunds/v2/filter` */
1603
+ async getFiltersV2(params) {
1604
+ return this.request("GET", "/refunds/v2/filter", { query: params });
1605
+ }
1606
+ /** Get refund aggregates. `GET /refunds/aggregate` */
1607
+ async aggregate(params) {
1608
+ return this.request("GET", "/refunds/aggregate", { query: params });
1609
+ }
1610
+ /** Get refund aggregates (profile-scoped). `GET /refunds/profile/aggregate` */
1611
+ async aggregateByProfile(params) {
1612
+ return this.request("GET", "/refunds/profile/aggregate", { query: params });
1613
+ }
1614
+ /** Manually update refund status. `PUT /refunds/{refundId}/manual-update` */
1615
+ async manualUpdate(refundId, params) {
1616
+ return this.request("PUT", `/refunds/${encodeURIComponent(refundId)}/manual-update`, {
1617
+ body: params
1618
+ });
1619
+ }
1620
+ };
1621
+
1622
+ // src/resources/relay.ts
1623
+ var Relay = class {
1624
+ constructor(request) {
1625
+ this.request = request;
1626
+ }
1627
+ async create(params) {
1628
+ return this.request("POST", "/relay", { body: params });
1629
+ }
1630
+ async retrieve(relayId) {
1631
+ return this.request("GET", `/relay/${encodeURIComponent(relayId)}`);
1632
+ }
1633
+ };
1634
+
1635
+ // src/resources/routing.ts
1636
+ var Routing = class {
1637
+ constructor(request) {
1638
+ this.request = request;
1639
+ this.decision = new RoutingDecisionManager(request);
1640
+ }
1641
+ /**
1642
+ * Create a new routing algorithm.
1643
+ *
1644
+ * @param params - Routing algorithm definition (rule-based, priority, or volume-based).
1645
+ * @returns The created routing configuration.
1646
+ *
1647
+ * @example
1648
+ * ```typescript
1649
+ * const config = await delopay.routing.create({
1650
+ * name: 'EU Priority',
1651
+ * algorithm: { type: 'priority', data: [{ connector: 'stripe' }] },
1652
+ * });
1653
+ * ```
1654
+ */
1655
+ async create(params) {
1656
+ return this.request("POST", "/routing", { body: params });
1657
+ }
1658
+ /**
1659
+ * Retrieve a routing algorithm by its ID.
1660
+ *
1661
+ * @param algorithmId - The routing algorithm ID.
1662
+ * @returns The routing configuration.
1663
+ */
1664
+ async retrieve(algorithmId) {
1665
+ return this.request("GET", `/routing/${encodeURIComponent(algorithmId)}`);
1666
+ }
1667
+ /**
1668
+ * Activate a routing algorithm, making it the active routing strategy for the shop.
1669
+ *
1670
+ * @param algorithmId - The routing algorithm ID to activate.
1671
+ * @returns The activated routing configuration.
1672
+ */
1673
+ async activate(algorithmId) {
1674
+ return this.request("POST", `/routing/${encodeURIComponent(algorithmId)}/activate`);
1675
+ }
1676
+ /**
1677
+ * Deactivate the currently active routing algorithm (falls back to default routing).
1678
+ *
1679
+ * @returns The deactivated routing configuration.
1680
+ */
1681
+ async deactivate() {
1682
+ return this.request("POST", "/routing/deactivate");
1683
+ }
1684
+ /**
1685
+ * List all routing algorithms for the current shop.
1686
+ *
1687
+ * @returns Array of routing configurations.
1688
+ */
1689
+ async list() {
1690
+ return this.request("GET", "/routing");
1691
+ }
1692
+ // --- Advanced operations (Task 3.4) ---
1693
+ /** Get active routing config. `GET /routing/active` */
1694
+ async getActive() {
1695
+ return this.request("GET", "/routing/active");
1696
+ }
1697
+ /** Update default routing config. `POST /routing/default` */
1698
+ async updateDefault(params) {
1699
+ return this.request("POST", "/routing/default", { body: params });
1700
+ }
1701
+ /** Retrieve default config for profiles. `GET /routing/default/profile` */
1702
+ async getDefaultProfile() {
1703
+ return this.request("GET", "/routing/default/profile");
1704
+ }
1705
+ /** Update default config for a profile. `POST /routing/default/profile/{profileId}` */
1706
+ async updateDefaultProfile(profileId, params) {
1707
+ return this.request("POST", `/routing/default/profile/${encodeURIComponent(profileId)}`, {
1708
+ body: params
1709
+ });
1710
+ }
1711
+ /** List routing configs for profile. `GET /routing/list/profile` */
1712
+ async listForProfile() {
1713
+ return this.request("GET", "/routing/list/profile");
1714
+ }
1715
+ /** Evaluate a routing rule. `POST /routing/rule/evaluate` */
1716
+ async evaluateRule(params) {
1717
+ return this.request("POST", "/routing/rule/evaluate", { body: params });
1718
+ }
1719
+ /** Migrate routing rules for profile. `POST /routing/rule/migrate` */
1720
+ async migrateRule(params) {
1721
+ return this.request("POST", "/routing/rule/migrate", { body: params });
1722
+ }
1723
+ /** Evaluate routing for a payment. `POST /routing/evaluate` */
1724
+ async evaluate(params) {
1725
+ return this.request("POST", "/routing/evaluate", { body: params });
1726
+ }
1727
+ /** Update gateway scores for dynamic routing. `POST /routing/feedback` */
1728
+ async feedback(params) {
1729
+ return this.request("POST", "/routing/feedback", { body: params });
1730
+ }
1731
+ };
1732
+ var RoutingDecisionManager = class {
1733
+ constructor(request) {
1734
+ this.request = request;
1735
+ }
1736
+ /** Upsert decision manager config. `PUT /routing/decision` */
1737
+ async upsert(params) {
1738
+ return this.request("PUT", "/routing/decision", { body: params });
1739
+ }
1740
+ /** Retrieve decision manager config. `GET /routing/decision` */
1741
+ async retrieve() {
1742
+ return this.request("GET", "/routing/decision");
1743
+ }
1744
+ /** Delete decision manager config. `DELETE /routing/decision` */
1745
+ async delete() {
1746
+ return this.request("DELETE", "/routing/decision");
1747
+ }
1748
+ /** Upsert surcharge decision config. `PUT /routing/decision/surcharge` */
1749
+ async upsertSurcharge(params) {
1750
+ return this.request("PUT", "/routing/decision/surcharge", { body: params });
1751
+ }
1752
+ /** Retrieve surcharge decision config. `GET /routing/decision/surcharge` */
1753
+ async retrieveSurcharge() {
1754
+ return this.request("GET", "/routing/decision/surcharge");
1755
+ }
1756
+ /** Delete surcharge decision config. `DELETE /routing/decision/surcharge` */
1757
+ async deleteSurcharge() {
1758
+ return this.request("DELETE", "/routing/decision/surcharge");
1759
+ }
1760
+ };
1761
+
1762
+ // src/resources/shops.ts
1763
+ var ShopGateways = class {
1764
+ constructor(request) {
1765
+ this.request = request;
1766
+ }
1767
+ /**
1768
+ * Connect a payment gateway to a shop.
1769
+ *
1770
+ * @param merchantId - The merchant account ID.
1771
+ * @param shopId - The shop (business profile) ID.
1772
+ * @param params - Gateway connector credentials and configuration.
1773
+ * @returns The created gateway connection.
1774
+ */
1775
+ async connect(merchantId, shopId, params) {
1776
+ return this.request(
1777
+ "POST",
1778
+ `/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}/gateways`,
1779
+ { body: params }
1780
+ );
1781
+ }
1782
+ /**
1783
+ * List all gateway connections for a shop.
1784
+ *
1785
+ * @param merchantId - The merchant account ID.
1786
+ * @param shopId - The shop ID.
1787
+ * @returns Array of gateway connections.
1788
+ */
1789
+ async list(merchantId, shopId) {
1790
+ return this.request(
1791
+ "GET",
1792
+ `/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}/gateways`
1793
+ );
1794
+ }
1795
+ /**
1796
+ * Disconnect a gateway from a shop.
1797
+ *
1798
+ * @param merchantId - The merchant account ID.
1799
+ * @param shopId - The shop ID.
1800
+ * @param gatewayId - The gateway connector ID to remove.
1801
+ * @returns The removed gateway connection.
1802
+ */
1803
+ async disconnect(merchantId, shopId, gatewayId) {
1804
+ return this.request(
1805
+ "DELETE",
1806
+ `/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}/gateways/${encodeURIComponent(gatewayId)}`
1807
+ );
1808
+ }
1809
+ };
1810
+ var Shops = class {
1811
+ constructor(request) {
1812
+ this.request = request;
1813
+ this.gateways = new ShopGateways(request);
1814
+ }
1815
+ /**
1816
+ * Create a new shop under a merchant account.
1817
+ *
1818
+ * @param merchantId - The merchant account ID.
1819
+ * @param params - Shop creation parameters (name, etc.).
1820
+ * @returns The created shop.
1821
+ *
1822
+ * @example
1823
+ * ```typescript
1824
+ * const shop = await delopay.shops.create('merch_123', { profile_name: 'EU Store' });
1825
+ * ```
1826
+ */
1827
+ async create(merchantId, params) {
1828
+ return this.request("POST", `/shops/${encodeURIComponent(merchantId)}`, { body: params });
1829
+ }
1830
+ /**
1831
+ * Retrieve a shop by its ID.
1832
+ *
1833
+ * @param merchantId - The merchant account ID.
1834
+ * @param shopId - The shop ID.
1835
+ * @returns The shop.
1836
+ */
1837
+ async retrieve(merchantId, shopId) {
1838
+ return this.request(
1839
+ "GET",
1840
+ `/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}`
1841
+ );
1842
+ }
1843
+ /**
1844
+ * Update a shop's configuration.
1845
+ *
1846
+ * @param merchantId - The merchant account ID.
1847
+ * @param shopId - The shop ID to update.
1848
+ * @param params - Fields to update.
1849
+ * @returns The updated shop.
1850
+ */
1851
+ async update(merchantId, shopId, params) {
1852
+ return this.request(
1853
+ "PUT",
1854
+ `/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}`,
1855
+ { body: params }
1856
+ );
1857
+ }
1858
+ /**
1859
+ * Delete a shop.
1860
+ *
1861
+ * @param merchantId - The merchant account ID.
1862
+ * @param shopId - The shop ID to delete.
1863
+ * @returns The deleted shop object.
1864
+ */
1865
+ async delete(merchantId, shopId) {
1866
+ return this.request(
1867
+ "DELETE",
1868
+ `/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}`
1869
+ );
1870
+ }
1871
+ /**
1872
+ * List all shops under a merchant account.
1873
+ *
1874
+ * @param merchantId - The merchant account ID.
1875
+ * @returns Array of shops.
1876
+ */
1877
+ async list(merchantId) {
1878
+ return this.request("GET", `/shops/${encodeURIComponent(merchantId)}`);
1879
+ }
1880
+ };
1881
+
1882
+ // src/resources/stripeConnect.ts
1883
+ var StripeConnect = class {
1884
+ constructor(request) {
1885
+ this.request = request;
1886
+ }
1887
+ async createAccount(params) {
1888
+ return this.request("POST", "/connector_onboarding/stripe/accounts", { body: params });
1889
+ }
1890
+ async createAccountLink(params) {
1891
+ return this.request("POST", "/connector_onboarding/stripe/account_links", { body: params });
1892
+ }
1893
+ // --- Generic connector onboarding (Task 4.11) ---
1894
+ /** Get onboarding action URL. `POST /connector_onboarding/action_url` */
1895
+ async getActionUrl(params) {
1896
+ return this.request("POST", "/connector_onboarding/action_url", { body: params });
1897
+ }
1898
+ /** Sync onboarding status. `POST /connector_onboarding/sync` */
1899
+ async syncOnboarding(params) {
1900
+ return this.request("POST", "/connector_onboarding/sync", { body: params });
1901
+ }
1902
+ /** Reset tracking ID. `POST /connector_onboarding/reset_tracking_id` */
1903
+ async resetTrackingId(params) {
1904
+ return this.request("POST", "/connector_onboarding/reset_tracking_id", { body: params });
1905
+ }
1906
+ };
1907
+
1908
+ // src/resources/threeDsRules.ts
1909
+ var ThreeDsRules = class {
1910
+ constructor(request) {
1911
+ this.request = request;
1912
+ }
1913
+ async execute(params) {
1914
+ return this.request("POST", "/three_ds_decision/execute", { body: params });
1915
+ }
1916
+ };
1917
+
1918
+ // src/resources/users.ts
1919
+ var Users = class {
1920
+ constructor(request) {
1921
+ this.request = request;
1922
+ }
1923
+ async signUp(params) {
1924
+ return this.request("POST", "/user/signup", { body: params });
1925
+ }
1926
+ async signIn(params) {
1927
+ return this.request("POST", "/user/signin", { body: params });
1928
+ }
1929
+ async signOut() {
1930
+ return this.request("POST", "/user/signout");
1931
+ }
1932
+ async getDetails() {
1933
+ return this.request("GET", "/user");
1934
+ }
1935
+ async update(params) {
1936
+ return this.request("POST", "/user/update", { body: params });
1937
+ }
1938
+ async changePassword(params) {
1939
+ return this.request("POST", "/user/change_password", { body: params });
1940
+ }
1941
+ async rotatePassword(params) {
1942
+ return this.request("POST", "/user/rotate_password", { body: params });
1943
+ }
1944
+ async forgotPassword(params) {
1945
+ return this.request("POST", "/user/forgot_password", { body: params });
1946
+ }
1947
+ /**
1948
+ * Commit a password reset.
1949
+ *
1950
+ * The caller is responsible for obtaining a `SinglePurposeToken` with
1951
+ * `purpose: reset_password` via the email-token exchange + TOTP flow
1952
+ * (see `fromEmail`, `beginTotp`, `updateTotp`/`verifyTotp`,
1953
+ * `generateRecoveryCodes`, `terminate2fa`) and setting it on the client
1954
+ * via `setJwtToken` before calling this method. `body.token` must still
1955
+ * be the original `EmailToken` from the reset-link URL — the handler
1956
+ * decodes it a second time to find the user.
1957
+ */
1958
+ async resetPassword(params) {
1959
+ return this.request("POST", "/user/reset_password", { body: params });
1960
+ }
1961
+ /**
1962
+ * Exchange an email-link token (`EmailToken`) for a single-purpose JWT
1963
+ * that drives the next step of the flow (TOTP, verify email, accept
1964
+ * invitation, etc.). No authentication required.
1965
+ *
1966
+ * The `token_type` in the response tells you which step to run next.
1967
+ */
1968
+ async fromEmail(params) {
1969
+ return this.request("POST", "/user/from_email", { body: params });
1970
+ }
1971
+ async verifyEmail(params) {
1972
+ return this.request("POST", "/user/verify_email", { body: params });
1973
+ }
1974
+ async sendVerificationEmail(params) {
1975
+ return this.request("POST", "/user/verify_email_request", { body: params });
1976
+ }
1977
+ async createMerchant(params) {
1978
+ return this.request("POST", "/user/create_merchant", { body: params });
1979
+ }
1980
+ async switchMerchant(params) {
1981
+ return this.request("POST", "/user/switch/merchant", { body: params });
1982
+ }
1983
+ async switchProfile(params) {
1984
+ return this.request("POST", "/user/switch/profile", { body: params });
1985
+ }
1986
+ async listMerchants() {
1987
+ return this.request("GET", "/user/list/merchant");
1988
+ }
1989
+ async listProfiles() {
1990
+ return this.request("GET", "/user/list/profile");
1991
+ }
1992
+ async inviteUsers(params) {
1993
+ return this.request("POST", "/user/user/invite_multiple", { body: params });
1994
+ }
1995
+ async acceptInvitation(params) {
1996
+ return this.request("POST", "/user/user/invite/accept", { body: params });
1997
+ }
1998
+ /**
1999
+ * Start TOTP setup (or no-op if already set).
2000
+ *
2001
+ * Returns the QR-code payload when the user has no TOTP configured yet;
2002
+ * returns `{ secret: null }` when the user is already set up (caller
2003
+ * should then prompt for a 6-digit code and call `verifyTotp`).
2004
+ *
2005
+ * Requires `Authorization: Bearer <SPT{purpose:totp}>`.
2006
+ */
2007
+ async beginTotp() {
2008
+ return this.request("GET", "/user/2fa/totp/begin");
2009
+ }
2010
+ /**
2011
+ * Verify a 6-digit TOTP code for a user whose TOTP is already set up.
2012
+ * Marks the code as used in Redis so subsequent flow steps can advance.
2013
+ *
2014
+ * Requires `Authorization: Bearer <SPT{purpose:totp}>`.
2015
+ */
2016
+ async verifyTotp(params) {
2017
+ return this.request("POST", "/user/2fa/totp/verify", { body: params });
2018
+ }
2019
+ async resetTotp() {
2020
+ return this.request("GET", "/user/2fa/totp/reset");
2021
+ }
2022
+ async generateRecoveryCodes() {
2023
+ return this.request("GET", "/user/2fa/recovery_code/generate");
2024
+ }
2025
+ async verifyRecoveryCode(params) {
2026
+ return this.request("POST", "/user/2fa/recovery_code/verify", { body: params });
2027
+ }
2028
+ async sendPhoneOtp(params) {
2029
+ return this.request("POST", "/user/phone/send-otp", { body: params });
2030
+ }
2031
+ async verifyPhoneOtp(params) {
2032
+ return this.request("POST", "/user/phone/verify-otp", { body: params });
2033
+ }
2034
+ async getRoleFromToken() {
2035
+ return this.request("GET", "/user/role");
2036
+ }
2037
+ async listRoles() {
2038
+ return this.request("GET", "/user/role/list");
2039
+ }
2040
+ async listUserRoles(params) {
2041
+ return this.request("POST", "/user/user", { body: params });
2042
+ }
2043
+ async updateUserRole(params) {
2044
+ return this.request("POST", "/user/user/update_role", { body: params });
2045
+ }
2046
+ async deleteUserRole(params) {
2047
+ return this.request("DELETE", "/user/user/delete", { body: params });
2048
+ }
2049
+ // --- Advanced methods (Task 4.7) ---
2050
+ /** Sign in (v2). `POST /user/v2/signin` */
2051
+ async signInV2(params) {
2052
+ return this.request("POST", "/user/v2/signin", { body: params });
2053
+ }
2054
+ /** Sign in via OIDC. `POST /user/oidc` */
2055
+ async signInOidc(params) {
2056
+ return this.request("POST", "/user/oidc", { body: params });
2057
+ }
2058
+ /** Transfer key. `POST /user/key/transfer` */
2059
+ async transferKey(params) {
2060
+ return this.request("POST", "/user/key/transfer", { body: params });
2061
+ }
2062
+ /** List invitations. `GET /user/list/invitation` */
2063
+ async listInvitations() {
2064
+ return this.request("GET", "/user/list/invitation");
2065
+ }
2066
+ /** Check 2FA status. `GET /user/2fa` */
2067
+ async check2faStatus() {
2068
+ return this.request("GET", "/user/2fa");
2069
+ }
2070
+ /** Check 2FA status (v2). `GET /user/2fa/v2` */
2071
+ async check2faStatusV2() {
2072
+ return this.request("GET", "/user/2fa/v2");
2073
+ }
2074
+ /**
2075
+ * Finish first-time TOTP setup: commit the secret generated by `beginTotp`
2076
+ * against a 6-digit code from the user's authenticator app.
2077
+ *
2078
+ * `PUT /user/2fa/totp/verify`. Requires `Authorization: Bearer <SPT{purpose:totp}>`.
2079
+ */
2080
+ async updateTotp(params) {
2081
+ return this.request("PUT", "/user/2fa/totp/verify", { body: params });
2082
+ }
2083
+ /**
2084
+ * Complete the TOTP step and advance to the next flow stage (e.g.
2085
+ * `reset_password`). Returns a fresh single-purpose token with the
2086
+ * next `token_type`.
2087
+ *
2088
+ * `GET /user/2fa/terminate`. Requires `Authorization: Bearer <SPT{purpose:totp}>`.
2089
+ */
2090
+ async terminate2fa(query) {
2091
+ if (query === void 0) {
2092
+ return this.request("GET", "/user/2fa/terminate");
2093
+ }
2094
+ return this.request("GET", "/user/2fa/terminate", {
2095
+ query
2096
+ });
2097
+ }
2098
+ /** Create auth method. `POST /user/auth` */
2099
+ async createAuthMethod(params) {
2100
+ return this.request("POST", "/user/auth", { body: params });
2101
+ }
2102
+ /** Update auth method. `PUT /user/auth` */
2103
+ async updateAuthMethod(params) {
2104
+ return this.request("PUT", "/user/auth", { body: params });
2105
+ }
2106
+ /** List auth methods. `GET /user/auth/list` */
2107
+ async listAuthMethods() {
2108
+ return this.request("GET", "/user/auth/list");
2109
+ }
2110
+ /** Get auth URL. `GET /user/auth/url` */
2111
+ async getAuthUrl() {
2112
+ return this.request("GET", "/user/auth/url");
2113
+ }
2114
+ /** Select auth method. `POST /user/auth/select` */
2115
+ async selectAuth(params) {
2116
+ return this.request("POST", "/user/auth/select", { body: params });
2117
+ }
2118
+ /** List user roles (v2). `POST /user/user/v2` */
2119
+ async listUserRolesV2(params) {
2120
+ return this.request("POST", "/user/user/v2", { body: params });
2121
+ }
2122
+ /** List users in lineage. `GET /user/user/list` */
2123
+ async listUsersInLineage() {
2124
+ return this.request("GET", "/user/user/list");
2125
+ }
2126
+ /** List users in lineage (v2). `GET /user/user/v2/list` */
2127
+ async listUsersInLineageV2() {
2128
+ return this.request("GET", "/user/user/v2/list");
2129
+ }
2130
+ /** Accept invitation (v2). `POST /user/user/invite/accept/v2` */
2131
+ async acceptInvitationV2(params) {
2132
+ return this.request("POST", "/user/user/invite/accept/v2", { body: params });
2133
+ }
2134
+ /** Resend invite. `POST /user/user/resend_invite` */
2135
+ async resendInvite(params) {
2136
+ return this.request("POST", "/user/user/resend_invite", { body: params });
2137
+ }
2138
+ /** Get role (v2). `GET /user/role/v2` */
2139
+ async getRoleV2() {
2140
+ return this.request("GET", "/user/role/v2");
2141
+ }
2142
+ /** Get role (v3). `GET /user/role/v3` */
2143
+ async getRoleV3() {
2144
+ return this.request("GET", "/user/role/v3");
2145
+ }
2146
+ /** List roles (v2). `GET /user/role/v2/list` */
2147
+ async listRolesV2() {
2148
+ return this.request("GET", "/user/role/v2/list");
2149
+ }
2150
+ /** List invitable roles. `GET /user/role/list/invite` */
2151
+ async listInvitableRoles() {
2152
+ return this.request("GET", "/user/role/list/invite");
2153
+ }
2154
+ /** List updatable roles. `GET /user/role/list/update` */
2155
+ async listUpdatableRoles() {
2156
+ return this.request("GET", "/user/role/list/update");
2157
+ }
2158
+ /** Get permission info. `GET /user/permission_info` */
2159
+ async getPermissionInfo() {
2160
+ return this.request("GET", "/user/permission_info");
2161
+ }
2162
+ /** Get module list. `GET /user/module/list` */
2163
+ async getModuleList() {
2164
+ return this.request("GET", "/user/module/list");
2165
+ }
2166
+ /** Get parent list. `GET /user/parent/list` */
2167
+ async getParentList() {
2168
+ return this.request("GET", "/user/parent/list");
2169
+ }
2170
+ /** Create a role. `POST /user/role` */
2171
+ async createRole(params) {
2172
+ return this.request("POST", "/user/role", { body: params });
2173
+ }
2174
+ /** Get role by ID. `GET /user/role/{roleId}` */
2175
+ async getRoleById(roleId) {
2176
+ return this.request("GET", `/user/role/${encodeURIComponent(roleId)}`);
2177
+ }
2178
+ /** Update role by ID. `PUT /user/role/{roleId}` */
2179
+ async updateRole(roleId, params) {
2180
+ return this.request("PUT", `/user/role/${encodeURIComponent(roleId)}`, { body: params });
2181
+ }
2182
+ };
2183
+
2184
+ // src/resources/verification.ts
2185
+ var Verification = class {
2186
+ constructor(request) {
2187
+ this.request = request;
2188
+ }
2189
+ async registerApplePayDomains(merchantId, params) {
2190
+ return this.request("POST", `/verify/apple_pay/${encodeURIComponent(merchantId)}`, {
2191
+ body: params
2192
+ });
2193
+ }
2194
+ async getApplePayVerifiedDomains(params) {
2195
+ return this.request("GET", "/verify/applepay_verified_domains", {
2196
+ query: params
2197
+ });
2198
+ }
2199
+ };
2200
+
2201
+ // src/resources/webhooks.ts
2202
+ function hexToBytes(hex) {
2203
+ if (hex.length === 0 || hex.length % 2 !== 0) return null;
2204
+ const bytes = new Uint8Array(hex.length / 2);
2205
+ for (let i = 0; i < hex.length; i += 2) {
2206
+ const byte = Number.parseInt(hex.slice(i, i + 2), 16);
2207
+ if (Number.isNaN(byte)) return null;
2208
+ bytes[i / 2] = byte;
2209
+ }
2210
+ return bytes;
2211
+ }
2212
+ var Webhooks = {
2213
+ /**
2214
+ * Verify the signature of an incoming Delopay webhook and return the parsed event.
2215
+ *
2216
+ * Uses the Web Crypto API (`globalThis.crypto.subtle`), so it runs unchanged in
2217
+ * Node 18+, modern browsers, Deno, Bun, and edge runtimes (Cloudflare Workers, Vercel Edge).
2218
+ *
2219
+ * This method is available as a static property on the `Delopay` class
2220
+ * (`Delopay.webhooks.verify`) and does not require a client instance.
2221
+ *
2222
+ * @param rawBody - The raw request body string (do **not** parse it before passing).
2223
+ * @param signatureHeader - The value of the `delopay-signature` HTTP header.
2224
+ * @param secret - Your webhook signing secret from the Delopay dashboard.
2225
+ * @param options - Optional verification settings (replay tolerance).
2226
+ * @returns Promise that resolves to the parsed webhook event.
2227
+ * @throws {Error} When the signature is invalid, the timestamp is missing, or the event is too old.
2228
+ *
2229
+ * @example
2230
+ * ```typescript
2231
+ * // Express example
2232
+ * app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
2233
+ * const event = await Delopay.webhooks.verify(
2234
+ * req.body.toString(),
2235
+ * req.headers['delopay-signature'] as string,
2236
+ * process.env.DELOPAY_WEBHOOK_SECRET!,
2237
+ * );
2238
+ * console.log(event.type, event.data);
2239
+ * res.sendStatus(200);
2240
+ * });
2241
+ * ```
2242
+ */
2243
+ async verify(rawBody, signatureHeader, secret, options) {
2244
+ const tolerance = options?.tolerance ?? 300;
2245
+ const parts = signatureHeader.split(",");
2246
+ const timestampPart = parts.find((p) => p.startsWith("t="));
2247
+ const signaturePart = parts.find((p) => p.startsWith("v1="));
2248
+ if (!timestampPart || !signaturePart) {
2249
+ throw new Error("Invalid webhook signature format");
2250
+ }
2251
+ const timestamp = Number.parseInt(timestampPart.slice(2), 10);
2252
+ if (!Number.isFinite(timestamp)) {
2253
+ throw new Error("Invalid webhook timestamp");
2254
+ }
2255
+ const signatureHex = signaturePart.slice(3);
2256
+ const signatureBytes = hexToBytes(signatureHex);
2257
+ const subtle = globalThis.crypto?.subtle;
2258
+ if (!subtle) {
2259
+ throw new Error(
2260
+ "Web Crypto unavailable: Delopay.webhooks.verify requires globalThis.crypto.subtle (Node 18+, modern browsers, Workers, Deno)"
2261
+ );
2262
+ }
2263
+ const encoder = new TextEncoder();
2264
+ const asBufferSource = (bytes) => bytes;
2265
+ const key = await subtle.importKey(
2266
+ "raw",
2267
+ asBufferSource(encoder.encode(secret)),
2268
+ { name: "HMAC", hash: "SHA-256" },
2269
+ false,
2270
+ ["verify"]
2271
+ );
2272
+ const signedPayload = asBufferSource(encoder.encode(`${timestamp}.${rawBody}`));
2273
+ const signaturesMatch = signatureBytes !== null && await subtle.verify("HMAC", key, asBufferSource(signatureBytes), signedPayload);
2274
+ if (!signaturesMatch) {
2275
+ throw new Error("Invalid webhook signature");
2276
+ }
2277
+ const age = Math.floor(Date.now() / 1e3) - timestamp;
2278
+ if (Math.abs(age) > tolerance) {
2279
+ throw new Error("Webhook timestamp too old");
2280
+ }
2281
+ return JSON.parse(rawBody);
2282
+ }
2283
+ };
2284
+
2285
+ // src/resources/analytics.ts
2286
+ var AnalyticsDomain = class {
2287
+ constructor(request, domain) {
2288
+ this.request = request;
2289
+ this.domain = domain;
2290
+ }
2291
+ /** Get metrics. `POST /analytics/v1/metrics/{domain}` */
2292
+ async metrics(params, scope) {
2293
+ const prefix = scope ? `/analytics/v1/${scope}` : "/analytics/v1";
2294
+ return this.request("POST", `${prefix}/metrics/${encodeURIComponent(this.domain)}`, {
2295
+ body: [params]
2296
+ });
2297
+ }
2298
+ /** Get filters. `POST /analytics/v1/filters/{domain}` */
2299
+ async filters(params, scope) {
2300
+ const prefix = scope ? `/analytics/v1/${scope}` : "/analytics/v1";
2301
+ return this.request("POST", `${prefix}/filters/${encodeURIComponent(this.domain)}`, {
2302
+ body: params
2303
+ });
2304
+ }
2305
+ /** Generate report. `POST /analytics/v1/report/{domain}` */
2306
+ async report(params, scope) {
2307
+ const prefix = scope ? `/analytics/v1/${scope}` : "/analytics/v1";
2308
+ return this.request("POST", `${prefix}/report/${encodeURIComponent(this.domain)}`, {
2309
+ body: params
2310
+ });
2311
+ }
2312
+ /** Sankey chart data. `POST /analytics/v1/metrics/{domain}/sankey` */
2313
+ async sankey(params, scope) {
2314
+ const prefix = scope ? `/analytics/v1/${scope}` : "/analytics/v1";
2315
+ return this.request("POST", `${prefix}/metrics/${encodeURIComponent(this.domain)}/sankey`, {
2316
+ body: params
2317
+ });
2318
+ }
2319
+ };
2320
+ var Analytics = class {
2321
+ constructor(request) {
2322
+ this.request = request;
2323
+ this.payments = new AnalyticsDomain(request, "payments");
2324
+ this.refunds = new AnalyticsDomain(request, "refunds");
2325
+ this.disputes = new AnalyticsDomain(request, "disputes");
2326
+ this.authEvents = new AnalyticsDomain(request, "auth_events");
2327
+ this.sdkEvents = new AnalyticsDomain(request, "sdk_events");
2328
+ this.frm = new AnalyticsDomain(request, "frm");
2329
+ this.apiEvents = new AnalyticsDomain(request, "api_events");
2330
+ this.routing = new AnalyticsDomain(request, "routing");
2331
+ }
2332
+ /** Global search. `POST /analytics/v1/search` */
2333
+ async search(params) {
2334
+ return this.request("POST", "/analytics/v1/search", { body: params });
2335
+ }
2336
+ /** Domain-specific search. `POST /analytics/v1/search/{domain}` */
2337
+ async searchDomain(domain, params) {
2338
+ return this.request("POST", `/analytics/v1/search/${encodeURIComponent(domain)}`, {
2339
+ body: params
2340
+ });
2341
+ }
2342
+ /** Get analytics info. `GET /analytics/v1/{domain}/info` */
2343
+ async getInfo(domain) {
2344
+ return this.request("GET", `/analytics/v1/${encodeURIComponent(domain)}/info`);
2345
+ }
2346
+ /** Get API event logs. `GET /analytics/v1/api_event_logs` */
2347
+ async apiEventLogs(params) {
2348
+ return this.request("GET", "/analytics/v1/api_event_logs", { query: params });
2349
+ }
2350
+ /** Get SDK event logs. `POST /analytics/v1/sdk_event_logs` */
2351
+ async sdkEventLogs(params) {
2352
+ return this.request("POST", "/analytics/v1/sdk_event_logs", { body: params });
2353
+ }
2354
+ /** Get connector event logs. `GET /analytics/v1/connector_event_logs` */
2355
+ async connectorEventLogs(params) {
2356
+ return this.request("GET", "/analytics/v1/connector_event_logs", { query: params });
2357
+ }
2358
+ /** Get routing event logs. `GET /analytics/v1/routing_event_logs` */
2359
+ async routingEventLogs(params) {
2360
+ return this.request("GET", "/analytics/v1/routing_event_logs", { query: params });
2361
+ }
2362
+ /** Get outgoing webhook event logs. `GET /analytics/v1/outgoing_webhook_event_logs` */
2363
+ async outgoingWebhookEventLogs(params) {
2364
+ return this.request("GET", "/analytics/v1/outgoing_webhook_event_logs", { query: params });
2365
+ }
2366
+ };
2367
+
2368
+ // src/resources/analyticsDashboard.ts
2369
+ var AnalyticsDashboard = class {
2370
+ constructor(request) {
2371
+ this.request = request;
2372
+ }
2373
+ /** Get analytics dashboard data. `GET /analytics-dashboard` */
2374
+ async retrieve(params) {
2375
+ return this.request("GET", "/analytics-dashboard", { query: params });
2376
+ }
2377
+ /** Generate analytics dashboard report. `POST /analytics-dashboard` */
2378
+ async generate(params) {
2379
+ return this.request("POST", "/analytics-dashboard", { body: params });
2380
+ }
2381
+ };
2382
+
2383
+ // src/resources/cache.ts
2384
+ var Cache = class {
2385
+ constructor(request) {
2386
+ this.request = request;
2387
+ }
2388
+ /** Invalidate a cache entry by key. `POST /cache/invalidate/{key}` */
2389
+ async invalidate(key) {
2390
+ return this.request("POST", `/cache/invalidate/${encodeURIComponent(key)}`);
2391
+ }
2392
+ };
2393
+
2394
+ // src/resources/cards.ts
2395
+ var Cards = class {
2396
+ constructor(request) {
2397
+ this.request = request;
2398
+ }
2399
+ /** Create a card. `POST /cards/create` */
2400
+ async create(params) {
2401
+ return this.request("POST", "/cards/create", { body: params });
2402
+ }
2403
+ /** Update a card. `POST /cards/update` */
2404
+ async update(params) {
2405
+ return this.request("POST", "/cards/update", { body: params });
2406
+ }
2407
+ /** Retrieve card info by BIN. `GET /cards/{bin}` */
2408
+ async retrieve(bin) {
2409
+ return this.request("GET", `/cards/${encodeURIComponent(bin)}`);
2410
+ }
2411
+ };
2412
+
2413
+ // src/resources/configs.ts
2414
+ var Configs = class {
2415
+ constructor(request) {
2416
+ this.request = request;
2417
+ }
2418
+ /** Create a config. `POST /configs` */
2419
+ async create(params) {
2420
+ return this.request("POST", "/configs", { body: params });
2421
+ }
2422
+ /** Retrieve a config by key. `GET /configs/{key}` */
2423
+ async retrieve(key) {
2424
+ return this.request("GET", `/configs/${encodeURIComponent(key)}`);
2425
+ }
2426
+ /** Update a config. `PUT /configs/{key}` */
2427
+ async update(key, params) {
2428
+ return this.request("PUT", `/configs/${encodeURIComponent(key)}`, { body: params });
2429
+ }
2430
+ /** Delete a config. `DELETE /configs/{key}` */
2431
+ async delete(key) {
2432
+ return this.request("DELETE", `/configs/${encodeURIComponent(key)}`);
2433
+ }
2434
+ };
2435
+
2436
+ // src/resources/export.ts
2437
+ var Export = class {
2438
+ constructor(request) {
2439
+ this.request = request;
2440
+ }
2441
+ /** Export transactions. `POST /export/transactions` */
2442
+ async transactions(params) {
2443
+ return this.request("POST", "/export/transactions", { body: params });
2444
+ }
2445
+ };
2446
+
2447
+ // src/resources/featureMatrix.ts
2448
+ var FeatureMatrix = class {
2449
+ constructor(request) {
2450
+ this.request = request;
2451
+ }
2452
+ /** Retrieve the feature matrix. `GET /feature_matrix` */
2453
+ async retrieve() {
2454
+ return this.request("GET", "/feature_matrix");
2455
+ }
2456
+ };
2457
+
2458
+ // src/resources/files.ts
2459
+ var Files = class {
2460
+ constructor(request) {
2461
+ this.request = request;
2462
+ }
2463
+ /** Upload a file. `POST /files` */
2464
+ async create(params) {
2465
+ return this.request("POST", "/files", { body: params });
2466
+ }
2467
+ /** Retrieve/download a file. `GET /files/{fileId}` */
2468
+ async retrieve(fileId) {
2469
+ return this.request("GET", `/files/${encodeURIComponent(fileId)}`);
2470
+ }
2471
+ /** Delete a file. `DELETE /files/{fileId}` */
2472
+ async delete(fileId) {
2473
+ return this.request("DELETE", `/files/${encodeURIComponent(fileId)}`);
2474
+ }
2475
+ };
2476
+
2477
+ // src/resources/forex.ts
2478
+ var Forex = class {
2479
+ constructor(request) {
2480
+ this.request = request;
2481
+ }
2482
+ /** Retrieve forex rates. `GET /forex/rates` */
2483
+ async getRates(params) {
2484
+ return this.request("GET", "/forex/rates", { query: params });
2485
+ }
2486
+ /** Convert from minor currency. `GET /forex/convert_from_minor` */
2487
+ async convertFromMinor(params) {
2488
+ return this.request("GET", "/forex/convert_from_minor", { query: params });
2489
+ }
2490
+ };
2491
+
2492
+ // src/resources/regions.ts
2493
+ var Regions = class {
2494
+ constructor(request) {
2495
+ this.request = request;
2496
+ }
2497
+ /** Create a region. `POST /regions` */
2498
+ async create(params) {
2499
+ return this.request("POST", "/regions", { body: params });
2500
+ }
2501
+ /** Retrieve a region by ID. `GET /regions/{regionId}` */
2502
+ async retrieve(regionId) {
2503
+ return this.request("GET", `/regions/${encodeURIComponent(regionId)}`);
2504
+ }
2505
+ /** Update a region. `PUT /regions/{regionId}` */
2506
+ async update(regionId, params) {
2507
+ return this.request("PUT", `/regions/${encodeURIComponent(regionId)}`, { body: params });
2508
+ }
2509
+ /** Delete a region. `DELETE /regions/{regionId}` */
2510
+ async delete(regionId) {
2511
+ return this.request("DELETE", `/regions/${encodeURIComponent(regionId)}`);
2512
+ }
2513
+ /** List all regions. `GET /regions/list` */
2514
+ async list() {
2515
+ return this.request("GET", "/regions/list");
2516
+ }
2517
+ };
2518
+
2519
+ // src/resources/subscriptions.ts
2520
+ var Subscriptions = class {
2521
+ constructor(request) {
2522
+ this.request = request;
2523
+ }
2524
+ /** Create and immediately confirm a subscription. `POST /subscriptions` */
2525
+ async createAndConfirm(params) {
2526
+ return this.request("POST", "/subscriptions", { body: params });
2527
+ }
2528
+ /** Create a subscription (without confirming). `POST /subscriptions/create` */
2529
+ async create(params) {
2530
+ return this.request("POST", "/subscriptions/create", { body: params });
2531
+ }
2532
+ /** Retrieve a subscription by ID. `GET /subscriptions/{subscriptionId}` */
2533
+ async retrieve(subscriptionId) {
2534
+ return this.request("GET", `/subscriptions/${encodeURIComponent(subscriptionId)}`);
2535
+ }
2536
+ /** Confirm a subscription. `POST /subscriptions/{subscriptionId}/confirm` */
2537
+ async confirm(subscriptionId, params) {
2538
+ return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/confirm`, {
2539
+ body: params
2540
+ });
2541
+ }
2542
+ /** Update a subscription. `PUT /subscriptions/{subscriptionId}/update` */
2543
+ async update(subscriptionId, params) {
2544
+ return this.request("PUT", `/subscriptions/${encodeURIComponent(subscriptionId)}/update`, {
2545
+ body: params
2546
+ });
2547
+ }
2548
+ /** List subscriptions. `GET /subscriptions/list` */
2549
+ async list(params) {
2550
+ return this.request("GET", "/subscriptions/list", {
2551
+ query: params
2552
+ });
2553
+ }
2554
+ /** Get subscription estimate. `GET /subscriptions/estimate` */
2555
+ async getEstimate(params) {
2556
+ return this.request("GET", "/subscriptions/estimate", { query: params });
2557
+ }
2558
+ /** Get subscription items. `GET /subscriptions/items` */
2559
+ async getItems(params) {
2560
+ return this.request("GET", "/subscriptions/items", { query: params });
2561
+ }
2562
+ /** Pause a subscription. `POST /subscriptions/{subscriptionId}/pause` */
2563
+ async pause(subscriptionId) {
2564
+ return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/pause`);
2565
+ }
2566
+ /** Resume a subscription. `POST /subscriptions/{subscriptionId}/resume` */
2567
+ async resume(subscriptionId) {
2568
+ return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/resume`);
2569
+ }
2570
+ /** Cancel a subscription. `POST /subscriptions/{subscriptionId}/cancel` */
2571
+ async cancel(subscriptionId) {
2572
+ return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`);
2573
+ }
2574
+ };
2575
+
2576
+ // src/client.ts
2577
+ var PRODUCTION_URL = "https://api.delopay.net";
2578
+ var SANDBOX_URL = "https://sandbox.delopay.net";
2579
+ var MAX_RAW_BODY_BYTES = 2048;
2580
+ var MAX_RETRY_AFTER_MS = 3e4;
2581
+ function parseRetryAfter(header) {
2582
+ if (!header) return null;
2583
+ const trimmed = header.trim();
2584
+ const seconds = Number(trimmed);
2585
+ if (Number.isFinite(seconds) && seconds >= 0) {
2586
+ return Math.min(seconds * 1e3, MAX_RETRY_AFTER_MS);
2587
+ }
2588
+ const date = Date.parse(trimmed);
2589
+ if (Number.isFinite(date)) {
2590
+ const delta = date - Date.now();
2591
+ return delta > 0 ? Math.min(delta, MAX_RETRY_AFTER_MS) : 0;
2592
+ }
2593
+ return null;
2594
+ }
2595
+ function truncateRawBody(raw) {
2596
+ if (!raw) return void 0;
2597
+ return raw.length > MAX_RAW_BODY_BYTES ? raw.slice(0, MAX_RAW_BODY_BYTES) + "\u2026" : raw;
2598
+ }
2599
+ function findIdempotencyKey(headers) {
2600
+ for (const [k, v] of Object.entries(headers)) {
2601
+ if (k.toLowerCase() === "idempotency-key") return v;
2602
+ }
2603
+ return void 0;
2604
+ }
2605
+ function noop() {
2606
+ }
2607
+ function combineSignals(signals) {
2608
+ const controller = new AbortController();
2609
+ const listeners = [];
2610
+ const dispose = () => {
2611
+ for (const { signal, handler } of listeners) {
2612
+ signal.removeEventListener("abort", handler);
2613
+ }
2614
+ listeners.length = 0;
2615
+ };
2616
+ for (const signal of signals) {
2617
+ if (signal.aborted) {
2618
+ controller.abort(signal.reason);
2619
+ dispose();
2620
+ return { signal: controller.signal, dispose: noop };
2621
+ }
2622
+ const handler = () => {
2623
+ controller.abort(signal.reason);
2624
+ dispose();
2625
+ };
2626
+ signal.addEventListener("abort", handler, { once: true });
2627
+ listeners.push({ signal, handler });
2628
+ }
2629
+ return { signal: controller.signal, dispose };
2630
+ }
2631
+ var SENSITIVE_QUERY_KEYS = /* @__PURE__ */ new Set([
2632
+ "client_secret",
2633
+ "ephemeral_key",
2634
+ "api_key",
2635
+ "publishable_key"
2636
+ ]);
2637
+ function redactUrlForLogging(url) {
2638
+ const qIdx = url.indexOf("?");
2639
+ if (qIdx === -1) return url;
2640
+ const base = url.slice(0, qIdx);
2641
+ const query = url.slice(qIdx + 1);
2642
+ const parts = query.split("&").map((pair) => {
2643
+ const eqIdx = pair.indexOf("=");
2644
+ if (eqIdx === -1) return pair;
2645
+ const key = pair.slice(0, eqIdx);
2646
+ if (SENSITIVE_QUERY_KEYS.has(decodeURIComponent(key).toLowerCase())) {
2647
+ return `${key}=REDACTED`;
2648
+ }
2649
+ return pair;
2650
+ });
2651
+ return `${base}?${parts.join("&")}`;
2652
+ }
2653
+ var Delopay = class {
2654
+ /**
2655
+ * Create a new Delopay client.
2656
+ *
2657
+ * @param apiKey - Your Delopay API key (e.g. `sk_live_...` or `sk_test_...`).
2658
+ * Pass an empty string or omit for JWT-only usage (e.g. dashboard apps).
2659
+ * @param options - Optional configuration (sandbox mode, base URL override, timeout).
2660
+ */
2661
+ constructor(apiKey, options) {
2662
+ this.apiKey = apiKey ?? "";
2663
+ this.timeout = options?.timeout ?? 3e4;
2664
+ this.maxRetries = options?.maxRetries ?? 2;
2665
+ this.debug = options?.debug ?? false;
2666
+ if (options?.logger !== void 0) this.logger = options.logger;
2667
+ if (options?.baseUrl !== void 0) {
2668
+ this.baseUrl = options.baseUrl;
2669
+ } else if (options?.sandbox) {
2670
+ this.baseUrl = SANDBOX_URL;
2671
+ } else {
2672
+ this.baseUrl = PRODUCTION_URL;
2673
+ }
2674
+ const request = this.request.bind(this);
2675
+ this.payments = new Payments(request);
2676
+ this.refunds = new Refunds(request);
2677
+ this.customers = new Customers(request);
2678
+ this.paymentMethods = new PaymentMethods(request);
2679
+ this.paymentLinks = new PaymentLinks(request);
2680
+ this.mandates = new Mandates(request);
2681
+ this.disputes = new Disputes(request);
2682
+ this.payouts = new Payouts(request);
2683
+ this.ephemeralKeys = new EphemeralKeys(request);
2684
+ this.events = new Events(request);
2685
+ this.poll = new Poll(request);
2686
+ this.connectors = new Connectors(request);
2687
+ this.routing = new Routing(request);
2688
+ this.profiles = new Profiles(request);
2689
+ this.shops = new Shops(request);
2690
+ this.profileAcquirers = new ProfileAcquirers(request);
2691
+ this.authentication = new Authentication(request);
2692
+ this.verification = new Verification(request);
2693
+ this.users = new Users(request);
2694
+ this.apiKeys = new ApiKeys(request);
2695
+ this.billing = new Billing(request);
2696
+ this.blocklist = new Blocklist(request);
2697
+ this.cardIssuers = new CardIssuers(request);
2698
+ this.fees = new Fees(request);
2699
+ this.gsm = new Gsm(request);
2700
+ this.merchantAccounts = new MerchantAccounts(request);
2701
+ this.projects = new Projects(request);
2702
+ this.relay = new Relay(request);
2703
+ this.stripeConnect = new StripeConnect(request);
2704
+ this.threeDsRules = new ThreeDsRules(request);
2705
+ this.subscriptions = new Subscriptions(request);
2706
+ this.files = new Files(request);
2707
+ this.export = new Export(request);
2708
+ this.forex = new Forex(request);
2709
+ this.regions = new Regions(request);
2710
+ this.analytics = new Analytics(request);
2711
+ this.analyticsDashboard = new AnalyticsDashboard(request);
2712
+ this.featureMatrix = new FeatureMatrix(request);
2713
+ this.cards = new Cards(request);
2714
+ this.configs = new Configs(request);
2715
+ this.cache = new Cache(request);
2716
+ }
2717
+ /**
2718
+ * Set a JWT token for subsequent requests.
2719
+ * When set, requests use `Authorization: Bearer <token>` instead of `api-key`.
2720
+ * Useful after `users.signIn()` returns a JWT for dashboard operations.
2721
+ */
2722
+ setJwtToken(token) {
2723
+ this.jwtToken = token;
2724
+ }
2725
+ /**
2726
+ * Clear the JWT token, reverting to API key authentication.
2727
+ */
2728
+ clearJwtToken() {
2729
+ this.jwtToken = void 0;
2730
+ }
2731
+ /**
2732
+ * Make a raw HTTP request to the Delopay API.
2733
+ *
2734
+ * You rarely need to call this directly — prefer the typed resource methods.
2735
+ * Use it only for endpoints not yet covered by a resource class.
2736
+ *
2737
+ * @param method - HTTP method (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`).
2738
+ * @param path - API path starting with `/` (e.g. `/payments`).
2739
+ * @param options - Optional body, query parameters, and headers.
2740
+ * @returns Parsed JSON response body typed as `T`.
2741
+ * @throws {DelopayAuthenticationError} On 401 responses.
2742
+ * @throws {DelopayError} On all other non-2xx responses, timeouts, and network errors.
2743
+ */
2744
+ async request(method, path, options) {
2745
+ let url = `${this.baseUrl}${path}`;
2746
+ if (options?.query) {
2747
+ const params = new URLSearchParams();
2748
+ for (const [key, value] of Object.entries(options.query)) {
2749
+ if (value === void 0 || value === null) continue;
2750
+ if (Array.isArray(value)) {
2751
+ for (const v of value) {
2752
+ if (v !== void 0 && v !== null) params.append(key, String(v));
2753
+ }
2754
+ } else {
2755
+ params.set(key, String(value));
2756
+ }
2757
+ }
2758
+ const qs = params.toString();
2759
+ if (qs) {
2760
+ url += `?${qs}`;
2761
+ }
2762
+ }
2763
+ const headers = {
2764
+ ...this.jwtToken ? { Authorization: `Bearer ${this.jwtToken}` } : this.apiKey ? { "api-key": this.apiKey } : {},
2765
+ ...options?.headers
2766
+ };
2767
+ if (options?.body) {
2768
+ headers["Content-Type"] = "application/json";
2769
+ }
2770
+ const idempotencyKey = findIdempotencyKey(headers)?.trim();
2771
+ const isRetryable = method === "GET" || method === "DELETE" || idempotencyKey !== void 0 && idempotencyKey !== "";
2772
+ const serializedBody = options?.body ? JSON.stringify(options.body) : void 0;
2773
+ const callerSignal = options?.signal;
2774
+ if (callerSignal?.aborted) {
2775
+ throw new DelopayError("Request aborted", {
2776
+ status: 0,
2777
+ code: "ABORTED",
2778
+ type: "abort_error"
2779
+ });
2780
+ }
2781
+ const timeoutMs = options?.timeout ?? this.timeout;
2782
+ let lastError;
2783
+ let retryAfterOverrideMs = null;
2784
+ const safeUrl = () => redactUrlForLogging(url);
2785
+ const emit = (event, data) => {
2786
+ if (!this.debug) return;
2787
+ if (this.logger) {
2788
+ this.logger(event, data);
2789
+ return;
2790
+ }
2791
+ if (event === "request")
2792
+ console.log(`[delopay] ${data.method} ${data.url}`);
2793
+ else if (event === "response")
2794
+ console.log(
2795
+ `[delopay] ${data.status} ${data.method} ${data.path}`
2796
+ );
2797
+ else
2798
+ console.log(
2799
+ `[delopay] retry ${data.attempt}/${data.maxRetries} ${data.method} ${data.path}`
2800
+ );
2801
+ };
2802
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
2803
+ if (attempt > 0) {
2804
+ const base = Math.min(500 * 2 ** (attempt - 1), 5e3);
2805
+ const jittered = Math.random() * base;
2806
+ const delay = Math.max(retryAfterOverrideMs ?? 0, jittered);
2807
+ retryAfterOverrideMs = null;
2808
+ await new Promise((resolve) => setTimeout(resolve, delay));
2809
+ emit("retry", { attempt, maxRetries: this.maxRetries, method, path });
2810
+ }
2811
+ const timeoutCtrl = new AbortController();
2812
+ const timeoutId = setTimeout(() => timeoutCtrl.abort(), timeoutMs);
2813
+ const combined = combineSignals(
2814
+ callerSignal ? [timeoutCtrl.signal, callerSignal] : [timeoutCtrl.signal]
2815
+ );
2816
+ try {
2817
+ emit("request", { method, url: safeUrl(), path });
2818
+ const response = await fetch(url, {
2819
+ method,
2820
+ headers,
2821
+ body: serializedBody,
2822
+ signal: combined.signal
2823
+ });
2824
+ const requestId = response.headers?.get("x-request-id") ?? response.headers?.get("x-trace-id") ?? void 0;
2825
+ emit("response", { status: response.status, method, path, requestId });
2826
+ if (!response.ok) {
2827
+ const rawBody = await response.text().catch(() => "");
2828
+ let parsed = {};
2829
+ if (rawBody) {
2830
+ try {
2831
+ parsed = JSON.parse(rawBody);
2832
+ } catch {
2833
+ }
2834
+ }
2835
+ const err = parsed.error ?? parsed;
2836
+ const message = err.message ?? `Request failed with status ${response.status}`;
2837
+ const code = err.code ?? "";
2838
+ const type = err.error_type ?? err.type ?? "";
2839
+ const truncatedRaw = truncateRawBody(rawBody);
2840
+ if (response.status === 401) {
2841
+ throw new DelopayAuthenticationError(message, {
2842
+ code,
2843
+ type,
2844
+ requestId,
2845
+ rawBody: truncatedRaw
2846
+ });
2847
+ }
2848
+ const error = new DelopayError(message, {
2849
+ status: response.status,
2850
+ code,
2851
+ type,
2852
+ requestId,
2853
+ rawBody: truncatedRaw
2854
+ });
2855
+ const isTransientStatus = response.status >= 500 || response.status === 429;
2856
+ if (isTransientStatus && isRetryable && attempt < this.maxRetries) {
2857
+ if (response.status === 429) {
2858
+ retryAfterOverrideMs = parseRetryAfter(response.headers?.get("retry-after") ?? null);
2859
+ }
2860
+ lastError = error;
2861
+ continue;
2862
+ }
2863
+ throw error;
2864
+ }
2865
+ const text = await response.text();
2866
+ return text ? JSON.parse(text) : void 0;
2867
+ } catch (err) {
2868
+ if (err instanceof DelopayError || err instanceof DelopayAuthenticationError) {
2869
+ throw err;
2870
+ }
2871
+ if (err instanceof Error && err.name === "AbortError") {
2872
+ if (callerSignal?.aborted) {
2873
+ throw new DelopayError("Request aborted", {
2874
+ status: 0,
2875
+ code: "ABORTED",
2876
+ type: "abort_error"
2877
+ });
2878
+ }
2879
+ lastError = new DelopayError("Request timed out", {
2880
+ status: 0,
2881
+ code: "TIMEOUT",
2882
+ type: "timeout_error"
2883
+ });
2884
+ if (isRetryable && attempt < this.maxRetries) continue;
2885
+ throw lastError;
2886
+ }
2887
+ if (err instanceof TypeError) {
2888
+ lastError = new DelopayError(`Network error: ${err.message}`, {
2889
+ status: 0,
2890
+ code: "NETWORK",
2891
+ type: "network_error"
2892
+ });
2893
+ if (isRetryable && attempt < this.maxRetries) continue;
2894
+ throw lastError;
2895
+ }
2896
+ throw err;
2897
+ } finally {
2898
+ clearTimeout(timeoutId);
2899
+ combined.dispose();
2900
+ }
2901
+ }
2902
+ throw lastError;
2903
+ }
2904
+ /**
2905
+ * Auto-paginate a list endpoint. Yields items one by one, fetching
2906
+ * the next page automatically when the current one is exhausted.
2907
+ *
2908
+ * @param listFn - A function that takes `{ limit, offset }` and returns `{ data: T[] }` or `T[]`.
2909
+ * @param params - Additional parameters to pass to every page request.
2910
+ * @param pageSize - Number of items per page. Defaults to `50`.
2911
+ *
2912
+ * @example
2913
+ * ```typescript
2914
+ * for await (const payment of delopay.paginate(
2915
+ * (p) => delopay.payments.list(p),
2916
+ * )) {
2917
+ * console.log(payment.payment_id);
2918
+ * }
2919
+ * ```
2920
+ */
2921
+ async *paginate(listFn, params, pageSize = 50) {
2922
+ let offset = 0;
2923
+ while (true) {
2924
+ const result = await listFn({
2925
+ ...params ?? {},
2926
+ limit: pageSize,
2927
+ offset
2928
+ });
2929
+ const items = Array.isArray(result) ? result : result.data;
2930
+ if (items.length === 0) break;
2931
+ for (const item of items) {
2932
+ yield item;
2933
+ }
2934
+ if (items.length < pageSize) break;
2935
+ offset += items.length;
2936
+ }
2937
+ }
2938
+ };
2939
+ /** Utility for verifying incoming webhook signatures (static, no instance needed). */
2940
+ Delopay.webhooks = Webhooks;
2941
+
2942
+ export {
2943
+ DelopayError,
2944
+ DelopayAuthenticationError,
2945
+ Webhooks,
2946
+ Analytics,
2947
+ AnalyticsDashboard,
2948
+ Cache,
2949
+ Cards,
2950
+ Configs,
2951
+ Export,
2952
+ FeatureMatrix,
2953
+ Files,
2954
+ Forex,
2955
+ Regions,
2956
+ Subscriptions,
2957
+ Delopay
2958
+ };
2959
+ //# sourceMappingURL=chunk-LCF7ILAH.js.map