@delopay/sdk 0.1.7 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +567 -204
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +221 -299
- package/dist/index.d.ts +221 -299
- package/dist/index.js +567 -211
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.cjs
CHANGED
|
@@ -47,11 +47,19 @@ var DelopayError = class extends Error {
|
|
|
47
47
|
this.status = options.status;
|
|
48
48
|
this.code = options.code;
|
|
49
49
|
this.type = options.type;
|
|
50
|
+
if (options.requestId !== void 0) this.requestId = options.requestId;
|
|
51
|
+
if (options.rawBody !== void 0) this.rawBody = options.rawBody;
|
|
50
52
|
}
|
|
51
53
|
};
|
|
52
54
|
var DelopayAuthenticationError = class extends DelopayError {
|
|
53
|
-
constructor(message = "Invalid API key") {
|
|
54
|
-
super(message, {
|
|
55
|
+
constructor(message = "Invalid API key", options) {
|
|
56
|
+
super(message, {
|
|
57
|
+
status: 401,
|
|
58
|
+
code: "AUTH_01",
|
|
59
|
+
type: "authentication_error",
|
|
60
|
+
requestId: options?.requestId,
|
|
61
|
+
rawBody: options?.rawBody
|
|
62
|
+
});
|
|
55
63
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
56
64
|
this.name = "DelopayAuthenticationError";
|
|
57
65
|
}
|
|
@@ -71,16 +79,27 @@ var Admin = class {
|
|
|
71
79
|
async createTenant(params) {
|
|
72
80
|
return this.request("POST", "/admin/tenant_signup", { body: params });
|
|
73
81
|
}
|
|
74
|
-
|
|
75
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Create a new merchant admin user and merchant account atomically.
|
|
84
|
+
*
|
|
85
|
+
* This is the correct endpoint for bootstrapping the first admin user in a
|
|
86
|
+
* fresh deployment — `internal_signup`/`tenant_signup` both require
|
|
87
|
+
* pre-existing merchant records that don't exist on a clean database.
|
|
88
|
+
*
|
|
89
|
+
* `POST /admin/signup_with_merchant_id`
|
|
90
|
+
*/
|
|
91
|
+
async signupWithMerchantId(params) {
|
|
92
|
+
return this.request("POST", "/admin/signup_with_merchant_id", { body: params });
|
|
93
|
+
}
|
|
94
|
+
/** Toggle public signup on/off. `POST /admin/settings/signup` */
|
|
76
95
|
async setSignupSettings(params) {
|
|
77
|
-
return this.request("POST", "/admin/
|
|
96
|
+
return this.request("POST", "/admin/settings/signup", { body: params });
|
|
78
97
|
}
|
|
79
|
-
/**
|
|
98
|
+
/** Read current public-signup status. `GET /admin/settings/signup` */
|
|
80
99
|
async getSignupSettings() {
|
|
81
|
-
return this.request("GET", "/admin/
|
|
100
|
+
return this.request("GET", "/admin/settings/signup");
|
|
82
101
|
}
|
|
83
|
-
/**
|
|
102
|
+
/** Full merchant bootstrap — user + merchant + project + profile + keys. `POST /admin/onboard_merchant` */
|
|
84
103
|
async onboardMerchant(params) {
|
|
85
104
|
return this.request("POST", "/admin/onboard_merchant", { body: params });
|
|
86
105
|
}
|
|
@@ -97,7 +116,7 @@ var AdminPortal = class {
|
|
|
97
116
|
});
|
|
98
117
|
}
|
|
99
118
|
async getCustomer(customerId) {
|
|
100
|
-
return this.request("GET", `/admin-portal/customers/${customerId}`);
|
|
119
|
+
return this.request("GET", `/admin-portal/customers/${encodeURIComponent(customerId)}`);
|
|
101
120
|
}
|
|
102
121
|
async listTransactions(params) {
|
|
103
122
|
return this.request("GET", "/admin-portal/transactions", {
|
|
@@ -137,7 +156,7 @@ var ApiKeys = class {
|
|
|
137
156
|
* ```
|
|
138
157
|
*/
|
|
139
158
|
async create(merchantId, params) {
|
|
140
|
-
return this.request("POST", `/api_keys/${merchantId}`, { body: params });
|
|
159
|
+
return this.request("POST", `/api_keys/${encodeURIComponent(merchantId)}`, { body: params });
|
|
141
160
|
}
|
|
142
161
|
/**
|
|
143
162
|
* Retrieve metadata about an API key (does not return the plaintext secret).
|
|
@@ -147,7 +166,10 @@ var ApiKeys = class {
|
|
|
147
166
|
* @returns The API key metadata.
|
|
148
167
|
*/
|
|
149
168
|
async retrieve(merchantId, keyId) {
|
|
150
|
-
return this.request(
|
|
169
|
+
return this.request(
|
|
170
|
+
"GET",
|
|
171
|
+
`/api_keys/${encodeURIComponent(merchantId)}/${encodeURIComponent(keyId)}`
|
|
172
|
+
);
|
|
151
173
|
}
|
|
152
174
|
/**
|
|
153
175
|
* Update an API key's name or expiry.
|
|
@@ -158,7 +180,11 @@ var ApiKeys = class {
|
|
|
158
180
|
* @returns The updated API key metadata.
|
|
159
181
|
*/
|
|
160
182
|
async update(merchantId, keyId, params) {
|
|
161
|
-
return this.request(
|
|
183
|
+
return this.request(
|
|
184
|
+
"POST",
|
|
185
|
+
`/api_keys/${encodeURIComponent(merchantId)}/${encodeURIComponent(keyId)}`,
|
|
186
|
+
{ body: params }
|
|
187
|
+
);
|
|
162
188
|
}
|
|
163
189
|
/**
|
|
164
190
|
* Revoke an API key, immediately invalidating it.
|
|
@@ -168,7 +194,10 @@ var ApiKeys = class {
|
|
|
168
194
|
* @returns Revocation confirmation.
|
|
169
195
|
*/
|
|
170
196
|
async revoke(merchantId, keyId) {
|
|
171
|
-
return this.request(
|
|
197
|
+
return this.request(
|
|
198
|
+
"DELETE",
|
|
199
|
+
`/api_keys/${encodeURIComponent(merchantId)}/${encodeURIComponent(keyId)}`
|
|
200
|
+
);
|
|
172
201
|
}
|
|
173
202
|
/**
|
|
174
203
|
* List all API keys for a merchant.
|
|
@@ -177,7 +206,7 @@ var ApiKeys = class {
|
|
|
177
206
|
* @returns Array of API key metadata objects.
|
|
178
207
|
*/
|
|
179
208
|
async list(merchantId) {
|
|
180
|
-
return this.request("GET", `/api_keys/${merchantId}/list`);
|
|
209
|
+
return this.request("GET", `/api_keys/${encodeURIComponent(merchantId)}/list`);
|
|
181
210
|
}
|
|
182
211
|
};
|
|
183
212
|
|
|
@@ -192,7 +221,7 @@ var AuditLogs = class {
|
|
|
192
221
|
});
|
|
193
222
|
}
|
|
194
223
|
async retrieve(logId) {
|
|
195
|
-
return this.request("GET", `/admin-portal/audit/${logId}`);
|
|
224
|
+
return this.request("GET", `/admin-portal/audit/${encodeURIComponent(logId)}`);
|
|
196
225
|
}
|
|
197
226
|
};
|
|
198
227
|
|
|
@@ -205,27 +234,39 @@ var Authentication = class {
|
|
|
205
234
|
return this.request("POST", "/authentication", { body: params });
|
|
206
235
|
}
|
|
207
236
|
async checkEligibility(authId) {
|
|
208
|
-
return this.request("POST", `/authentication/${authId}/eligibility`);
|
|
237
|
+
return this.request("POST", `/authentication/${encodeURIComponent(authId)}/eligibility`);
|
|
209
238
|
}
|
|
210
239
|
async authenticate(authId, params) {
|
|
211
|
-
return this.request("POST", `/authentication/${authId}/authenticate`, {
|
|
240
|
+
return this.request("POST", `/authentication/${encodeURIComponent(authId)}/authenticate`, {
|
|
241
|
+
body: params
|
|
242
|
+
});
|
|
212
243
|
}
|
|
213
244
|
async sync(authId, params) {
|
|
214
|
-
return this.request("POST", `/authentication/${authId}/sync`, {
|
|
245
|
+
return this.request("POST", `/authentication/${encodeURIComponent(authId)}/sync`, {
|
|
246
|
+
body: params
|
|
247
|
+
});
|
|
215
248
|
}
|
|
216
249
|
/** Redirect after authentication. `POST /authentication/{authId}/redirect` */
|
|
217
250
|
async redirect(authId, params) {
|
|
218
|
-
return this.request("POST", `/authentication/${authId}/redirect`, {
|
|
251
|
+
return this.request("POST", `/authentication/${encodeURIComponent(authId)}/redirect`, {
|
|
252
|
+
body: params
|
|
253
|
+
});
|
|
219
254
|
}
|
|
220
255
|
/** Enable authn methods token. `POST /authentication/{authId}/enabled_authn_methods_token` */
|
|
221
256
|
async enabledAuthnMethodsToken(authId, params) {
|
|
222
|
-
return this.request(
|
|
223
|
-
|
|
224
|
-
|
|
257
|
+
return this.request(
|
|
258
|
+
"POST",
|
|
259
|
+
`/authentication/${encodeURIComponent(authId)}/enabled_authn_methods_token`,
|
|
260
|
+
{
|
|
261
|
+
body: params
|
|
262
|
+
}
|
|
263
|
+
);
|
|
225
264
|
}
|
|
226
265
|
/** Submit eligibility check. `POST /authentication/{authId}/eligibility-check` */
|
|
227
266
|
async eligibilityCheck(authId, params) {
|
|
228
|
-
return this.request("POST", `/authentication/${authId}/eligibility-check`, {
|
|
267
|
+
return this.request("POST", `/authentication/${encodeURIComponent(authId)}/eligibility-check`, {
|
|
268
|
+
body: params
|
|
269
|
+
});
|
|
229
270
|
}
|
|
230
271
|
};
|
|
231
272
|
|
|
@@ -242,7 +283,11 @@ var BillingAllocations = class {
|
|
|
242
283
|
* @returns The allocation transfer result.
|
|
243
284
|
*/
|
|
244
285
|
async transferIn(merchantId, params) {
|
|
245
|
-
return this.request(
|
|
286
|
+
return this.request(
|
|
287
|
+
"POST",
|
|
288
|
+
`/billing/${encodeURIComponent(merchantId)}/allocations/transfer-in`,
|
|
289
|
+
{ body: params }
|
|
290
|
+
);
|
|
246
291
|
}
|
|
247
292
|
/**
|
|
248
293
|
* Transfer funds from a shop's allocation back to the host merchant treasury.
|
|
@@ -252,9 +297,13 @@ var BillingAllocations = class {
|
|
|
252
297
|
* @returns The allocation transfer result.
|
|
253
298
|
*/
|
|
254
299
|
async transferOut(merchantId, params) {
|
|
255
|
-
return this.request(
|
|
256
|
-
|
|
257
|
-
|
|
300
|
+
return this.request(
|
|
301
|
+
"POST",
|
|
302
|
+
`/billing/${encodeURIComponent(merchantId)}/allocations/transfer-out`,
|
|
303
|
+
{
|
|
304
|
+
body: params
|
|
305
|
+
}
|
|
306
|
+
);
|
|
258
307
|
}
|
|
259
308
|
/**
|
|
260
309
|
* List all shop balance allocations for a merchant.
|
|
@@ -263,7 +312,7 @@ var BillingAllocations = class {
|
|
|
263
312
|
* @returns List of shop allocations.
|
|
264
313
|
*/
|
|
265
314
|
async list(merchantId) {
|
|
266
|
-
return this.request("GET", `/billing/${merchantId}/allocations`);
|
|
315
|
+
return this.request("GET", `/billing/${encodeURIComponent(merchantId)}/allocations`);
|
|
267
316
|
}
|
|
268
317
|
/**
|
|
269
318
|
* Get the balance allocation for a specific shop.
|
|
@@ -273,7 +322,10 @@ var BillingAllocations = class {
|
|
|
273
322
|
* @returns The shop's balance allocation.
|
|
274
323
|
*/
|
|
275
324
|
async get(merchantId, profileId) {
|
|
276
|
-
return this.request(
|
|
325
|
+
return this.request(
|
|
326
|
+
"GET",
|
|
327
|
+
`/billing/${encodeURIComponent(merchantId)}/allocations/${encodeURIComponent(profileId)}`
|
|
328
|
+
);
|
|
277
329
|
}
|
|
278
330
|
};
|
|
279
331
|
var Billing = class {
|
|
@@ -294,7 +346,7 @@ var Billing = class {
|
|
|
294
346
|
* ```
|
|
295
347
|
*/
|
|
296
348
|
async getProfile(merchantId) {
|
|
297
|
-
return this.request("GET", `/billing/${merchantId}`);
|
|
349
|
+
return this.request("GET", `/billing/${encodeURIComponent(merchantId)}`);
|
|
298
350
|
}
|
|
299
351
|
/**
|
|
300
352
|
* Start a Stripe SetupIntent flow to collect a payment card for auto-recharge.
|
|
@@ -304,7 +356,9 @@ var Billing = class {
|
|
|
304
356
|
* @returns The Stripe client secret needed to render the card element.
|
|
305
357
|
*/
|
|
306
358
|
async setup(merchantId, params) {
|
|
307
|
-
return this.request("POST", `/billing/${merchantId}/setup`, {
|
|
359
|
+
return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/setup`, {
|
|
360
|
+
body: params
|
|
361
|
+
});
|
|
308
362
|
}
|
|
309
363
|
/**
|
|
310
364
|
* Confirm card setup after the Stripe SetupIntent completes on the frontend.
|
|
@@ -314,7 +368,9 @@ var Billing = class {
|
|
|
314
368
|
* @returns The updated billing profile.
|
|
315
369
|
*/
|
|
316
370
|
async completeSetup(merchantId, params) {
|
|
317
|
-
return this.request("POST", `/billing/${merchantId}/setup/complete`, {
|
|
371
|
+
return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/setup/complete`, {
|
|
372
|
+
body: params
|
|
373
|
+
});
|
|
318
374
|
}
|
|
319
375
|
/**
|
|
320
376
|
* Manually top up a merchant's prepaid balance by charging their saved card.
|
|
@@ -324,7 +380,9 @@ var Billing = class {
|
|
|
324
380
|
* @returns The top-up result.
|
|
325
381
|
*/
|
|
326
382
|
async topup(merchantId, params) {
|
|
327
|
-
return this.request("POST", `/billing/${merchantId}/topup`, {
|
|
383
|
+
return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/topup`, {
|
|
384
|
+
body: params
|
|
385
|
+
});
|
|
328
386
|
}
|
|
329
387
|
/**
|
|
330
388
|
* List the balance ledger (credits and debits) for a merchant.
|
|
@@ -334,7 +392,7 @@ var Billing = class {
|
|
|
334
392
|
* @returns The ledger entries.
|
|
335
393
|
*/
|
|
336
394
|
async listLedger(merchantId, params) {
|
|
337
|
-
return this.request("GET", `/billing/${merchantId}/ledger`, {
|
|
395
|
+
return this.request("GET", `/billing/${encodeURIComponent(merchantId)}/ledger`, {
|
|
338
396
|
query: params
|
|
339
397
|
});
|
|
340
398
|
}
|
|
@@ -346,7 +404,9 @@ var Billing = class {
|
|
|
346
404
|
* @returns The updated billing profile.
|
|
347
405
|
*/
|
|
348
406
|
async updateAutoRecharge(merchantId, params) {
|
|
349
|
-
return this.request("PATCH", `/billing/${merchantId}/auto-recharge`, {
|
|
407
|
+
return this.request("PATCH", `/billing/${encodeURIComponent(merchantId)}/auto-recharge`, {
|
|
408
|
+
body: params
|
|
409
|
+
});
|
|
350
410
|
}
|
|
351
411
|
/**
|
|
352
412
|
* Admin: manually credit a merchant's balance (e.g. promotional credit).
|
|
@@ -356,7 +416,9 @@ var Billing = class {
|
|
|
356
416
|
* @returns The adjustment result.
|
|
357
417
|
*/
|
|
358
418
|
async adminCredit(merchantId, params) {
|
|
359
|
-
return this.request("POST", `/billing/${merchantId}/admin/credit`, {
|
|
419
|
+
return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/admin/credit`, {
|
|
420
|
+
body: params
|
|
421
|
+
});
|
|
360
422
|
}
|
|
361
423
|
/**
|
|
362
424
|
* Admin: manually debit a merchant's balance.
|
|
@@ -366,7 +428,9 @@ var Billing = class {
|
|
|
366
428
|
* @returns The adjustment result.
|
|
367
429
|
*/
|
|
368
430
|
async adminDebit(merchantId, params) {
|
|
369
|
-
return this.request("POST", `/billing/${merchantId}/admin/debit`, {
|
|
431
|
+
return this.request("POST", `/billing/${encodeURIComponent(merchantId)}/admin/debit`, {
|
|
432
|
+
body: params
|
|
433
|
+
});
|
|
370
434
|
}
|
|
371
435
|
};
|
|
372
436
|
|
|
@@ -400,7 +464,7 @@ var CardIssuers = class {
|
|
|
400
464
|
return this.request("POST", "/card_issuers", { body: params });
|
|
401
465
|
}
|
|
402
466
|
async update(issuerId, params) {
|
|
403
|
-
return this.request("PUT", `/card_issuers/${issuerId}`, { body: params });
|
|
467
|
+
return this.request("PUT", `/card_issuers/${encodeURIComponent(issuerId)}`, { body: params });
|
|
404
468
|
}
|
|
405
469
|
async list() {
|
|
406
470
|
return this.request("GET", "/card_issuers");
|
|
@@ -413,21 +477,33 @@ var Connectors = class {
|
|
|
413
477
|
this.request = request;
|
|
414
478
|
}
|
|
415
479
|
async create(accountId, params) {
|
|
416
|
-
return this.request("POST", `/account/${accountId}/connectors`, {
|
|
480
|
+
return this.request("POST", `/account/${encodeURIComponent(accountId)}/connectors`, {
|
|
481
|
+
body: params
|
|
482
|
+
});
|
|
417
483
|
}
|
|
418
484
|
async retrieve(accountId, connectorId) {
|
|
419
|
-
return this.request(
|
|
485
|
+
return this.request(
|
|
486
|
+
"GET",
|
|
487
|
+
`/account/${encodeURIComponent(accountId)}/connectors/${encodeURIComponent(connectorId)}`
|
|
488
|
+
);
|
|
420
489
|
}
|
|
421
490
|
async list(accountId) {
|
|
422
|
-
return this.request("GET", `/account/${accountId}/connectors`);
|
|
491
|
+
return this.request("GET", `/account/${encodeURIComponent(accountId)}/connectors`);
|
|
423
492
|
}
|
|
424
493
|
async update(accountId, connectorId, params) {
|
|
425
|
-
return this.request(
|
|
426
|
-
|
|
427
|
-
|
|
494
|
+
return this.request(
|
|
495
|
+
"POST",
|
|
496
|
+
`/account/${encodeURIComponent(accountId)}/connectors/${encodeURIComponent(connectorId)}`,
|
|
497
|
+
{
|
|
498
|
+
body: params
|
|
499
|
+
}
|
|
500
|
+
);
|
|
428
501
|
}
|
|
429
502
|
async delete(accountId, connectorId) {
|
|
430
|
-
return this.request(
|
|
503
|
+
return this.request(
|
|
504
|
+
"DELETE",
|
|
505
|
+
`/account/${encodeURIComponent(accountId)}/connectors/${encodeURIComponent(connectorId)}`
|
|
506
|
+
);
|
|
431
507
|
}
|
|
432
508
|
// --- Advanced operations (Task 4.8) ---
|
|
433
509
|
/** Verify connector credentials. `POST /account/connectors/verify` */
|
|
@@ -436,11 +512,17 @@ var Connectors = class {
|
|
|
436
512
|
}
|
|
437
513
|
/** Register a webhook for a connector. `POST /account/{merchantId}/connectors/webhooks/{connectorId}` */
|
|
438
514
|
async registerWebhook(merchantId, connectorId) {
|
|
439
|
-
return this.request(
|
|
515
|
+
return this.request(
|
|
516
|
+
"POST",
|
|
517
|
+
`/account/${encodeURIComponent(merchantId)}/connectors/webhooks/${encodeURIComponent(connectorId)}`
|
|
518
|
+
);
|
|
440
519
|
}
|
|
441
520
|
/** Get a webhook for a connector. `GET /account/{merchantId}/connectors/webhooks/{connectorId}` */
|
|
442
521
|
async getWebhook(merchantId, connectorId) {
|
|
443
|
-
return this.request(
|
|
522
|
+
return this.request(
|
|
523
|
+
"GET",
|
|
524
|
+
`/account/${encodeURIComponent(merchantId)}/connectors/webhooks/${encodeURIComponent(connectorId)}`
|
|
525
|
+
);
|
|
444
526
|
}
|
|
445
527
|
/** List available payment methods. `GET /account/payment_methods` */
|
|
446
528
|
async listPaymentMethods() {
|
|
@@ -482,7 +564,7 @@ var Customers = class {
|
|
|
482
564
|
* ```
|
|
483
565
|
*/
|
|
484
566
|
async retrieve(customerId) {
|
|
485
|
-
return this.request("GET", `/customers/${customerId}`);
|
|
567
|
+
return this.request("GET", `/customers/${encodeURIComponent(customerId)}`);
|
|
486
568
|
}
|
|
487
569
|
/**
|
|
488
570
|
* Update an existing customer's details.
|
|
@@ -492,7 +574,7 @@ var Customers = class {
|
|
|
492
574
|
* @returns The updated customer.
|
|
493
575
|
*/
|
|
494
576
|
async update(customerId, params) {
|
|
495
|
-
return this.request("POST", `/customers/${customerId}`, { body: params });
|
|
577
|
+
return this.request("POST", `/customers/${encodeURIComponent(customerId)}`, { body: params });
|
|
496
578
|
}
|
|
497
579
|
/**
|
|
498
580
|
* Delete a customer and all their saved payment methods.
|
|
@@ -501,7 +583,7 @@ var Customers = class {
|
|
|
501
583
|
* @returns The deleted customer object.
|
|
502
584
|
*/
|
|
503
585
|
async delete(customerId) {
|
|
504
|
-
return this.request("DELETE", `/customers/${customerId}`);
|
|
586
|
+
return this.request("DELETE", `/customers/${encodeURIComponent(customerId)}`);
|
|
505
587
|
}
|
|
506
588
|
/**
|
|
507
589
|
* List customers, optionally filtered by email.
|
|
@@ -523,7 +605,7 @@ var Customers = class {
|
|
|
523
605
|
}
|
|
524
606
|
/** List mandates for a customer. `GET /customers/{customerId}/mandates` */
|
|
525
607
|
async listMandates(customerId) {
|
|
526
|
-
return this.request("GET", `/customers/${customerId}/mandates`);
|
|
608
|
+
return this.request("GET", `/customers/${encodeURIComponent(customerId)}/mandates`);
|
|
527
609
|
}
|
|
528
610
|
};
|
|
529
611
|
|
|
@@ -539,7 +621,7 @@ var Disputes = class {
|
|
|
539
621
|
* @returns The dispute.
|
|
540
622
|
*/
|
|
541
623
|
async retrieve(disputeId) {
|
|
542
|
-
return this.request("GET", `/disputes/${disputeId}`);
|
|
624
|
+
return this.request("GET", `/disputes/${encodeURIComponent(disputeId)}`);
|
|
543
625
|
}
|
|
544
626
|
/**
|
|
545
627
|
* List disputes, optionally filtered by status, stage, or date range.
|
|
@@ -559,7 +641,7 @@ var Disputes = class {
|
|
|
559
641
|
* @returns The updated dispute.
|
|
560
642
|
*/
|
|
561
643
|
async accept(disputeId) {
|
|
562
|
-
return this.request("POST", `/disputes/accept/${disputeId}`);
|
|
644
|
+
return this.request("POST", `/disputes/accept/${encodeURIComponent(disputeId)}`);
|
|
563
645
|
}
|
|
564
646
|
/**
|
|
565
647
|
* Submit evidence to challenge a dispute.
|
|
@@ -585,7 +667,7 @@ var Disputes = class {
|
|
|
585
667
|
* @returns The submitted evidence.
|
|
586
668
|
*/
|
|
587
669
|
async retrieveEvidence(disputeId) {
|
|
588
|
-
return this.request("GET", `/disputes/evidence/${disputeId}`);
|
|
670
|
+
return this.request("GET", `/disputes/evidence/${encodeURIComponent(disputeId)}`);
|
|
589
671
|
}
|
|
590
672
|
/**
|
|
591
673
|
* Delete submitted evidence for a dispute.
|
|
@@ -619,9 +701,17 @@ var Disputes = class {
|
|
|
619
701
|
async aggregateByProfile(params) {
|
|
620
702
|
return this.request("GET", "/disputes/profile/aggregate", { query: params });
|
|
621
703
|
}
|
|
622
|
-
/**
|
|
623
|
-
|
|
624
|
-
|
|
704
|
+
/**
|
|
705
|
+
* Fetch the latest dispute state from the connector (gateway).
|
|
706
|
+
* `GET /disputes/{connectorId}/fetch`
|
|
707
|
+
*
|
|
708
|
+
* Note: the path parameter is the **connector dispute id** on the gateway, not the
|
|
709
|
+
* Delopay dispute id. Method is GET (not POST) and this method signature was
|
|
710
|
+
* previously wrong — callers depending on the old `POST /disputes/{id}/fetch_from_connector`
|
|
711
|
+
* path were silently hitting 404s.
|
|
712
|
+
*/
|
|
713
|
+
async fetchFromConnector(connectorId) {
|
|
714
|
+
return this.request("GET", `/disputes/${encodeURIComponent(connectorId)}/fetch`);
|
|
625
715
|
}
|
|
626
716
|
};
|
|
627
717
|
|
|
@@ -652,7 +742,7 @@ var EphemeralKeys = class {
|
|
|
652
742
|
* @returns The deleted key object.
|
|
653
743
|
*/
|
|
654
744
|
async delete(keyId) {
|
|
655
|
-
return this.request("DELETE", `/ephemeral_keys/${keyId}`);
|
|
745
|
+
return this.request("DELETE", `/ephemeral_keys/${encodeURIComponent(keyId)}`);
|
|
656
746
|
}
|
|
657
747
|
};
|
|
658
748
|
|
|
@@ -662,13 +752,19 @@ var Events = class {
|
|
|
662
752
|
this.request = request;
|
|
663
753
|
}
|
|
664
754
|
async list(merchantId, params) {
|
|
665
|
-
return this.request("POST", `/events/${merchantId}`, { body: params });
|
|
755
|
+
return this.request("POST", `/events/${encodeURIComponent(merchantId)}`, { body: params });
|
|
666
756
|
}
|
|
667
757
|
async listDeliveryAttempts(merchantId, eventId) {
|
|
668
|
-
return this.request(
|
|
758
|
+
return this.request(
|
|
759
|
+
"GET",
|
|
760
|
+
`/events/${encodeURIComponent(merchantId)}/${encodeURIComponent(eventId)}/attempts`
|
|
761
|
+
);
|
|
669
762
|
}
|
|
670
763
|
async retryDelivery(merchantId, eventId) {
|
|
671
|
-
return this.request(
|
|
764
|
+
return this.request(
|
|
765
|
+
"POST",
|
|
766
|
+
`/events/${encodeURIComponent(merchantId)}/${encodeURIComponent(eventId)}/retry`
|
|
767
|
+
);
|
|
672
768
|
}
|
|
673
769
|
// --- Profile-scoped listing (Task 4.12) ---
|
|
674
770
|
/** List events (profile-scoped). `POST /events/profile/list` */
|
|
@@ -713,7 +809,7 @@ var PlatformFees = class {
|
|
|
713
809
|
* @returns The fee schedule.
|
|
714
810
|
*/
|
|
715
811
|
async retrieve(feeId) {
|
|
716
|
-
return this.request("GET", `/admin/fees/${feeId}`);
|
|
812
|
+
return this.request("GET", `/admin/fees/${encodeURIComponent(feeId)}`);
|
|
717
813
|
}
|
|
718
814
|
/**
|
|
719
815
|
* Update a fee schedule (admin only).
|
|
@@ -723,7 +819,7 @@ var PlatformFees = class {
|
|
|
723
819
|
* @returns The updated fee schedule.
|
|
724
820
|
*/
|
|
725
821
|
async update(feeId, params) {
|
|
726
|
-
return this.request("PUT", `/admin/fees/${feeId}`, { body: params });
|
|
822
|
+
return this.request("PUT", `/admin/fees/${encodeURIComponent(feeId)}`, { body: params });
|
|
727
823
|
}
|
|
728
824
|
/**
|
|
729
825
|
* Delete a fee schedule (admin only).
|
|
@@ -732,7 +828,7 @@ var PlatformFees = class {
|
|
|
732
828
|
* @returns The deleted fee schedule.
|
|
733
829
|
*/
|
|
734
830
|
async delete(feeId) {
|
|
735
|
-
return this.request("DELETE", `/admin/fees/${feeId}`);
|
|
831
|
+
return this.request("DELETE", `/admin/fees/${encodeURIComponent(feeId)}`);
|
|
736
832
|
}
|
|
737
833
|
};
|
|
738
834
|
var MerchantFees = class {
|
|
@@ -771,7 +867,7 @@ var MerchantFees = class {
|
|
|
771
867
|
* @returns The updated fee schedule.
|
|
772
868
|
*/
|
|
773
869
|
async update(feeId, params) {
|
|
774
|
-
return this.request("PUT", `/merchant_fees/${feeId}`, { body: params });
|
|
870
|
+
return this.request("PUT", `/merchant_fees/${encodeURIComponent(feeId)}`, { body: params });
|
|
775
871
|
}
|
|
776
872
|
/**
|
|
777
873
|
* Delete a merchant-scoped fee schedule.
|
|
@@ -780,7 +876,7 @@ var MerchantFees = class {
|
|
|
780
876
|
* @returns The deleted fee schedule.
|
|
781
877
|
*/
|
|
782
878
|
async delete(feeId) {
|
|
783
|
-
return this.request("DELETE", `/merchant_fees/${feeId}`);
|
|
879
|
+
return this.request("DELETE", `/merchant_fees/${encodeURIComponent(feeId)}`);
|
|
784
880
|
}
|
|
785
881
|
};
|
|
786
882
|
var Fees = class {
|
|
@@ -821,7 +917,7 @@ var Mandates = class {
|
|
|
821
917
|
* @returns The mandate.
|
|
822
918
|
*/
|
|
823
919
|
async retrieve(mandateId) {
|
|
824
|
-
return this.request("GET", `/mandates/${mandateId}`);
|
|
920
|
+
return this.request("GET", `/mandates/${encodeURIComponent(mandateId)}`);
|
|
825
921
|
}
|
|
826
922
|
/**
|
|
827
923
|
* Revoke an active mandate, preventing future charges.
|
|
@@ -830,7 +926,7 @@ var Mandates = class {
|
|
|
830
926
|
* @returns Revocation confirmation.
|
|
831
927
|
*/
|
|
832
928
|
async revoke(mandateId) {
|
|
833
|
-
return this.request("POST", `/mandates/revoke/${mandateId}`);
|
|
929
|
+
return this.request("POST", `/mandates/revoke/${encodeURIComponent(mandateId)}`);
|
|
834
930
|
}
|
|
835
931
|
/**
|
|
836
932
|
* List mandates, optionally filtered by customer or status.
|
|
@@ -854,13 +950,13 @@ var MerchantAccounts = class {
|
|
|
854
950
|
return this.request("POST", "/accounts", { body: params });
|
|
855
951
|
}
|
|
856
952
|
async retrieve(accountId) {
|
|
857
|
-
return this.request("GET", `/accounts/${accountId}`);
|
|
953
|
+
return this.request("GET", `/accounts/${encodeURIComponent(accountId)}`);
|
|
858
954
|
}
|
|
859
955
|
async update(accountId, params) {
|
|
860
|
-
return this.request("POST", `/accounts/${accountId}`, { body: params });
|
|
956
|
+
return this.request("POST", `/accounts/${encodeURIComponent(accountId)}`, { body: params });
|
|
861
957
|
}
|
|
862
958
|
async delete(accountId) {
|
|
863
|
-
return this.request("DELETE", `/accounts/${accountId}`);
|
|
959
|
+
return this.request("DELETE", `/accounts/${encodeURIComponent(accountId)}`);
|
|
864
960
|
}
|
|
865
961
|
// --- Advanced operations (Task 4.9) ---
|
|
866
962
|
/** List all merchant accounts. `GET /accounts/list` */
|
|
@@ -869,15 +965,15 @@ var MerchantAccounts = class {
|
|
|
869
965
|
}
|
|
870
966
|
/** Toggle key-value store for a merchant. `POST /accounts/{accountId}/kv` */
|
|
871
967
|
async toggleKv(accountId) {
|
|
872
|
-
return this.request("POST", `/accounts/${accountId}/kv`);
|
|
968
|
+
return this.request("POST", `/accounts/${encodeURIComponent(accountId)}/kv`);
|
|
873
969
|
}
|
|
874
970
|
/** Get KV status for a merchant. `GET /accounts/{accountId}/kv` */
|
|
875
971
|
async getKvStatus(accountId) {
|
|
876
|
-
return this.request("GET", `/accounts/${accountId}/kv`);
|
|
972
|
+
return this.request("GET", `/accounts/${encodeURIComponent(accountId)}/kv`);
|
|
877
973
|
}
|
|
878
|
-
/** Transfer keys between merchants. `POST /accounts/
|
|
974
|
+
/** Transfer keys between merchants. `POST /accounts/transfer` */
|
|
879
975
|
async transferKeys(params) {
|
|
880
|
-
return this.request("POST", "/accounts/
|
|
976
|
+
return this.request("POST", "/accounts/transfer", { body: params });
|
|
881
977
|
}
|
|
882
978
|
};
|
|
883
979
|
|
|
@@ -893,7 +989,7 @@ var PaymentLinks = class {
|
|
|
893
989
|
* @returns The payment link details.
|
|
894
990
|
*/
|
|
895
991
|
async retrieve(linkId) {
|
|
896
|
-
return this.request("GET", `/payment_link/${linkId}`);
|
|
992
|
+
return this.request("GET", `/payment_link/${encodeURIComponent(linkId)}`);
|
|
897
993
|
}
|
|
898
994
|
/**
|
|
899
995
|
* List payment links, optionally filtered by status or date range.
|
|
@@ -906,11 +1002,17 @@ var PaymentLinks = class {
|
|
|
906
1002
|
}
|
|
907
1003
|
/** Initiate (render) a payment link page. `GET /payment_link/{merchantId}/{paymentId}` */
|
|
908
1004
|
async initiate(merchantId, paymentId) {
|
|
909
|
-
return this.request(
|
|
1005
|
+
return this.request(
|
|
1006
|
+
"GET",
|
|
1007
|
+
`/payment_link/${encodeURIComponent(merchantId)}/${encodeURIComponent(paymentId)}`
|
|
1008
|
+
);
|
|
910
1009
|
}
|
|
911
1010
|
/** Get payment link status. `GET /payment_linkstatus/{merchantId}/{paymentId}` */
|
|
912
1011
|
async status(merchantId, paymentId) {
|
|
913
|
-
return this.request(
|
|
1012
|
+
return this.request(
|
|
1013
|
+
"GET",
|
|
1014
|
+
`/payment_linkstatus/${encodeURIComponent(merchantId)}/${encodeURIComponent(paymentId)}`
|
|
1015
|
+
);
|
|
914
1016
|
}
|
|
915
1017
|
};
|
|
916
1018
|
|
|
@@ -944,7 +1046,7 @@ var PaymentMethods = class {
|
|
|
944
1046
|
* @returns The payment method.
|
|
945
1047
|
*/
|
|
946
1048
|
async retrieve(methodId) {
|
|
947
|
-
return this.request("GET", `/payment_methods/${methodId}`);
|
|
1049
|
+
return this.request("GET", `/payment_methods/${encodeURIComponent(methodId)}`);
|
|
948
1050
|
}
|
|
949
1051
|
/**
|
|
950
1052
|
* Update an existing payment method (e.g. update card expiry).
|
|
@@ -954,7 +1056,9 @@ var PaymentMethods = class {
|
|
|
954
1056
|
* @returns The updated payment method.
|
|
955
1057
|
*/
|
|
956
1058
|
async update(methodId, params) {
|
|
957
|
-
return this.request("POST", `/payment_methods/${methodId}/update`, {
|
|
1059
|
+
return this.request("POST", `/payment_methods/${encodeURIComponent(methodId)}/update`, {
|
|
1060
|
+
body: params
|
|
1061
|
+
});
|
|
958
1062
|
}
|
|
959
1063
|
/**
|
|
960
1064
|
* Delete a saved payment method.
|
|
@@ -963,7 +1067,7 @@ var PaymentMethods = class {
|
|
|
963
1067
|
* @returns Deletion confirmation.
|
|
964
1068
|
*/
|
|
965
1069
|
async delete(methodId) {
|
|
966
|
-
return this.request("DELETE", `/payment_methods/${methodId}`);
|
|
1070
|
+
return this.request("DELETE", `/payment_methods/${encodeURIComponent(methodId)}`);
|
|
967
1071
|
}
|
|
968
1072
|
/**
|
|
969
1073
|
* List payment methods using a client secret.
|
|
@@ -977,18 +1081,25 @@ var PaymentMethods = class {
|
|
|
977
1081
|
});
|
|
978
1082
|
}
|
|
979
1083
|
/**
|
|
980
|
-
* List all saved payment methods for a customer.
|
|
1084
|
+
* List all saved payment methods for a customer, optionally filtered.
|
|
981
1085
|
*
|
|
982
1086
|
* @param customerId - The customer ID.
|
|
1087
|
+
* @param params - Optional filters: `client_secret`, `accepted_countries`, `accepted_currencies`,
|
|
1088
|
+
* `amount`, `recurring_enabled`, `installment_payment_enabled`, `limit`, `card_networks`.
|
|
983
1089
|
* @returns Customer's saved payment methods.
|
|
984
1090
|
*
|
|
985
1091
|
* @example
|
|
986
1092
|
* ```typescript
|
|
987
|
-
* const { customer_payment_methods } = await delopay.paymentMethods.listForCustomer(
|
|
1093
|
+
* const { customer_payment_methods } = await delopay.paymentMethods.listForCustomer(
|
|
1094
|
+
* 'cus_123',
|
|
1095
|
+
* { accepted_currencies: ['EUR'], amount: 5000 },
|
|
1096
|
+
* );
|
|
988
1097
|
* ```
|
|
989
1098
|
*/
|
|
990
|
-
async listForCustomer(customerId) {
|
|
991
|
-
return this.request("GET", `/customers/${customerId}/payment_methods
|
|
1099
|
+
async listForCustomer(customerId, params) {
|
|
1100
|
+
return this.request("GET", `/customers/${encodeURIComponent(customerId)}/payment_methods`, {
|
|
1101
|
+
query: params
|
|
1102
|
+
});
|
|
992
1103
|
}
|
|
993
1104
|
/**
|
|
994
1105
|
* Set a payment method as the default for a customer.
|
|
@@ -998,7 +1109,10 @@ var PaymentMethods = class {
|
|
|
998
1109
|
* @returns The updated payment method.
|
|
999
1110
|
*/
|
|
1000
1111
|
async setDefault(customerId, methodId) {
|
|
1001
|
-
return this.request(
|
|
1112
|
+
return this.request(
|
|
1113
|
+
"POST",
|
|
1114
|
+
`/customers/${encodeURIComponent(customerId)}/payment_methods/${encodeURIComponent(methodId)}/default`
|
|
1115
|
+
);
|
|
1002
1116
|
}
|
|
1003
1117
|
// --- Advanced operations (Task 3.3) ---
|
|
1004
1118
|
/** Migrate a payment method. `POST /payment_methods/migrate` */
|
|
@@ -1031,7 +1145,9 @@ var PaymentMethods = class {
|
|
|
1031
1145
|
}
|
|
1032
1146
|
/** Save a payment method. `POST /payment_methods/{methodId}/save` */
|
|
1033
1147
|
async save(methodId, params) {
|
|
1034
|
-
return this.request("POST", `/payment_methods/${methodId}/save`, {
|
|
1148
|
+
return this.request("POST", `/payment_methods/${encodeURIComponent(methodId)}/save`, {
|
|
1149
|
+
body: params
|
|
1150
|
+
});
|
|
1035
1151
|
}
|
|
1036
1152
|
/** Create payment method auth link token. `POST /payment_methods/auth/link` */
|
|
1037
1153
|
async createAuthLink(params) {
|
|
@@ -1043,7 +1159,9 @@ var PaymentMethods = class {
|
|
|
1043
1159
|
}
|
|
1044
1160
|
/** Tokenize card using existing PM. `POST /payment_methods/{methodId}/tokenize-card` */
|
|
1045
1161
|
async tokenizeCardForMethod(methodId, params) {
|
|
1046
|
-
return this.request("POST", `/payment_methods/${methodId}/tokenize-card`, {
|
|
1162
|
+
return this.request("POST", `/payment_methods/${encodeURIComponent(methodId)}/tokenize-card`, {
|
|
1163
|
+
body: params
|
|
1164
|
+
});
|
|
1047
1165
|
}
|
|
1048
1166
|
};
|
|
1049
1167
|
|
|
@@ -1082,7 +1200,7 @@ var Payments = class {
|
|
|
1082
1200
|
* ```
|
|
1083
1201
|
*/
|
|
1084
1202
|
async retrieve(paymentId) {
|
|
1085
|
-
return this.request("GET", `/payments/${paymentId}`);
|
|
1203
|
+
return this.request("GET", `/payments/${encodeURIComponent(paymentId)}`);
|
|
1086
1204
|
}
|
|
1087
1205
|
/**
|
|
1088
1206
|
* Update an existing payment intent before it is confirmed.
|
|
@@ -1092,7 +1210,7 @@ var Payments = class {
|
|
|
1092
1210
|
* @returns The updated payment intent.
|
|
1093
1211
|
*/
|
|
1094
1212
|
async update(paymentId, params) {
|
|
1095
|
-
return this.request("POST", `/payments/${paymentId}`, { body: params });
|
|
1213
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}`, { body: params });
|
|
1096
1214
|
}
|
|
1097
1215
|
/**
|
|
1098
1216
|
* Confirm a payment intent, triggering authorisation with the selected gateway.
|
|
@@ -1102,7 +1220,9 @@ var Payments = class {
|
|
|
1102
1220
|
* @returns The updated payment intent.
|
|
1103
1221
|
*/
|
|
1104
1222
|
async confirm(paymentId, params) {
|
|
1105
|
-
return this.request("POST", `/payments/${paymentId}/confirm`, {
|
|
1223
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/confirm`, {
|
|
1224
|
+
body: params
|
|
1225
|
+
});
|
|
1106
1226
|
}
|
|
1107
1227
|
/**
|
|
1108
1228
|
* Capture a previously authorised payment.
|
|
@@ -1112,7 +1232,9 @@ var Payments = class {
|
|
|
1112
1232
|
* @returns The updated payment intent.
|
|
1113
1233
|
*/
|
|
1114
1234
|
async capture(paymentId, params) {
|
|
1115
|
-
return this.request("POST", `/payments/${paymentId}/capture`, {
|
|
1235
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/capture`, {
|
|
1236
|
+
body: params
|
|
1237
|
+
});
|
|
1116
1238
|
}
|
|
1117
1239
|
/**
|
|
1118
1240
|
* Cancel a payment intent that has not yet been captured.
|
|
@@ -1122,7 +1244,9 @@ var Payments = class {
|
|
|
1122
1244
|
* @returns The updated payment intent.
|
|
1123
1245
|
*/
|
|
1124
1246
|
async cancel(paymentId, params) {
|
|
1125
|
-
return this.request("POST", `/payments/${paymentId}/cancel`, {
|
|
1247
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/cancel`, {
|
|
1248
|
+
body: params
|
|
1249
|
+
});
|
|
1126
1250
|
}
|
|
1127
1251
|
/**
|
|
1128
1252
|
* List payment intents, optionally filtered by customer or date range.
|
|
@@ -1151,33 +1275,47 @@ var Payments = class {
|
|
|
1151
1275
|
}
|
|
1152
1276
|
/** Cancel after partial capture. `POST /payments/{paymentId}/cancel_post_capture` */
|
|
1153
1277
|
async cancelPostCapture(paymentId, params) {
|
|
1154
|
-
return this.request("POST", `/payments/${paymentId}/cancel_post_capture`, {
|
|
1278
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/cancel_post_capture`, {
|
|
1279
|
+
body: params
|
|
1280
|
+
});
|
|
1155
1281
|
}
|
|
1156
1282
|
/** Incrementally authorize more funds. `POST /payments/{paymentId}/incremental_authorization` */
|
|
1157
1283
|
async incrementalAuthorization(paymentId, params) {
|
|
1158
|
-
return this.request(
|
|
1159
|
-
|
|
1160
|
-
|
|
1284
|
+
return this.request(
|
|
1285
|
+
"POST",
|
|
1286
|
+
`/payments/${encodeURIComponent(paymentId)}/incremental_authorization`,
|
|
1287
|
+
{
|
|
1288
|
+
body: params
|
|
1289
|
+
}
|
|
1290
|
+
);
|
|
1161
1291
|
}
|
|
1162
1292
|
/** Extend authorization window. `POST /payments/{paymentId}/extend_authorization` */
|
|
1163
1293
|
async extendAuthorization(paymentId, params) {
|
|
1164
|
-
return this.request("POST", `/payments/${paymentId}/extend_authorization`, {
|
|
1294
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/extend_authorization`, {
|
|
1295
|
+
body: params
|
|
1296
|
+
});
|
|
1165
1297
|
}
|
|
1166
1298
|
/** Complete authorization. `POST /payments/{paymentId}/complete_authorize` */
|
|
1167
1299
|
async completeAuthorize(paymentId, params) {
|
|
1168
|
-
return this.request("POST", `/payments/${paymentId}/complete_authorize`, {
|
|
1300
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/complete_authorize`, {
|
|
1301
|
+
body: params
|
|
1302
|
+
});
|
|
1169
1303
|
}
|
|
1170
1304
|
/** Dynamic tax calculation. `POST /payments/{paymentId}/calculate_tax` */
|
|
1171
1305
|
async calculateTax(paymentId, params) {
|
|
1172
|
-
return this.request("POST", `/payments/${paymentId}/calculate_tax`, {
|
|
1306
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/calculate_tax`, {
|
|
1307
|
+
body: params
|
|
1308
|
+
});
|
|
1173
1309
|
}
|
|
1174
1310
|
/** Update payment metadata. `POST /payments/{paymentId}/update_metadata` */
|
|
1175
1311
|
async updateMetadata(paymentId, params) {
|
|
1176
|
-
return this.request("POST", `/payments/${paymentId}/update_metadata`, {
|
|
1312
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/update_metadata`, {
|
|
1313
|
+
body: params
|
|
1314
|
+
});
|
|
1177
1315
|
}
|
|
1178
1316
|
/** Retrieve extended card info. `GET /payments/{paymentId}/extended_card_info` */
|
|
1179
1317
|
async extendedCardInfo(paymentId) {
|
|
1180
|
-
return this.request("GET", `/payments/${paymentId}/extended_card_info`);
|
|
1318
|
+
return this.request("GET", `/payments/${encodeURIComponent(paymentId)}/extended_card_info`);
|
|
1181
1319
|
}
|
|
1182
1320
|
// --- OLAP extensions (Task 4.2) ---
|
|
1183
1321
|
/** List payments (profile-scoped). `GET /payments/profile/list` */
|
|
@@ -1214,19 +1352,27 @@ var Payments = class {
|
|
|
1214
1352
|
}
|
|
1215
1353
|
/** Manually update payment status. `PUT /payments/{paymentId}/manual-update` */
|
|
1216
1354
|
async manualUpdate(paymentId, params) {
|
|
1217
|
-
return this.request("PUT", `/payments/${paymentId}/manual-update`, {
|
|
1355
|
+
return this.request("PUT", `/payments/${encodeURIComponent(paymentId)}/manual-update`, {
|
|
1356
|
+
body: params
|
|
1357
|
+
});
|
|
1218
1358
|
}
|
|
1219
1359
|
/** Approve a payment waiting for review. `POST /payments/{paymentId}/approve` */
|
|
1220
1360
|
async approve(paymentId, params) {
|
|
1221
|
-
return this.request("POST", `/payments/${paymentId}/approve`, {
|
|
1361
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/approve`, {
|
|
1362
|
+
body: params
|
|
1363
|
+
});
|
|
1222
1364
|
}
|
|
1223
1365
|
/** Reject a payment waiting for review. `POST /payments/{paymentId}/reject` */
|
|
1224
1366
|
async reject(paymentId, params) {
|
|
1225
|
-
return this.request("POST", `/payments/${paymentId}/reject`, {
|
|
1367
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/reject`, {
|
|
1368
|
+
body: params
|
|
1369
|
+
});
|
|
1226
1370
|
}
|
|
1227
1371
|
/** Initiate external 3DS authentication. `POST /payments/{paymentId}/3ds/authentication` */
|
|
1228
1372
|
async threeDsAuthentication(paymentId, params) {
|
|
1229
|
-
return this.request("POST", `/payments/${paymentId}/3ds/authentication`, {
|
|
1373
|
+
return this.request("POST", `/payments/${encodeURIComponent(paymentId)}/3ds/authentication`, {
|
|
1374
|
+
body: params
|
|
1375
|
+
});
|
|
1230
1376
|
}
|
|
1231
1377
|
};
|
|
1232
1378
|
|
|
@@ -1260,7 +1406,7 @@ var Payouts = class {
|
|
|
1260
1406
|
* @returns The payout.
|
|
1261
1407
|
*/
|
|
1262
1408
|
async retrieve(payoutId) {
|
|
1263
|
-
return this.request("GET", `/payouts/${payoutId}`);
|
|
1409
|
+
return this.request("GET", `/payouts/${encodeURIComponent(payoutId)}`);
|
|
1264
1410
|
}
|
|
1265
1411
|
/**
|
|
1266
1412
|
* Update a payout before it is confirmed.
|
|
@@ -1270,7 +1416,7 @@ var Payouts = class {
|
|
|
1270
1416
|
* @returns The updated payout.
|
|
1271
1417
|
*/
|
|
1272
1418
|
async update(payoutId, params) {
|
|
1273
|
-
return this.request("PUT", `/payouts/${payoutId}`, { body: params });
|
|
1419
|
+
return this.request("PUT", `/payouts/${encodeURIComponent(payoutId)}`, { body: params });
|
|
1274
1420
|
}
|
|
1275
1421
|
/**
|
|
1276
1422
|
* Confirm a payout, triggering the actual transfer.
|
|
@@ -1280,7 +1426,9 @@ var Payouts = class {
|
|
|
1280
1426
|
* @returns The updated payout.
|
|
1281
1427
|
*/
|
|
1282
1428
|
async confirm(payoutId, params) {
|
|
1283
|
-
return this.request("POST", `/payouts/${payoutId}/confirm`, {
|
|
1429
|
+
return this.request("POST", `/payouts/${encodeURIComponent(payoutId)}/confirm`, {
|
|
1430
|
+
body: params
|
|
1431
|
+
});
|
|
1284
1432
|
}
|
|
1285
1433
|
/**
|
|
1286
1434
|
* Cancel a payout before it is fulfilled.
|
|
@@ -1289,7 +1437,7 @@ var Payouts = class {
|
|
|
1289
1437
|
* @returns The cancelled payout.
|
|
1290
1438
|
*/
|
|
1291
1439
|
async cancel(payoutId) {
|
|
1292
|
-
return this.request("POST", `/payouts/${payoutId}/cancel`);
|
|
1440
|
+
return this.request("POST", `/payouts/${encodeURIComponent(payoutId)}/cancel`);
|
|
1293
1441
|
}
|
|
1294
1442
|
/**
|
|
1295
1443
|
* Mark a payout as fulfilled (manual confirmation of successful transfer).
|
|
@@ -1298,7 +1446,7 @@ var Payouts = class {
|
|
|
1298
1446
|
* @returns The fulfilled payout.
|
|
1299
1447
|
*/
|
|
1300
1448
|
async fulfill(payoutId) {
|
|
1301
|
-
return this.request("POST", `/payouts/${payoutId}/fulfill`);
|
|
1449
|
+
return this.request("POST", `/payouts/${encodeURIComponent(payoutId)}/fulfill`);
|
|
1302
1450
|
}
|
|
1303
1451
|
/**
|
|
1304
1452
|
* List payouts, optionally filtered by status or date range.
|
|
@@ -1340,7 +1488,9 @@ var Payouts = class {
|
|
|
1340
1488
|
}
|
|
1341
1489
|
/** Manually update payout status. `PUT /payouts/{payoutId}/manual-update` */
|
|
1342
1490
|
async manualUpdate(payoutId, params) {
|
|
1343
|
-
return this.request("PUT", `/payouts/${payoutId}/manual-update`, {
|
|
1491
|
+
return this.request("PUT", `/payouts/${encodeURIComponent(payoutId)}/manual-update`, {
|
|
1492
|
+
body: params
|
|
1493
|
+
});
|
|
1344
1494
|
}
|
|
1345
1495
|
};
|
|
1346
1496
|
|
|
@@ -1350,7 +1500,7 @@ var Poll = class {
|
|
|
1350
1500
|
this.request = request;
|
|
1351
1501
|
}
|
|
1352
1502
|
async getStatus(pollId) {
|
|
1353
|
-
return this.request("GET", `/poll/status/${pollId}`);
|
|
1503
|
+
return this.request("GET", `/poll/status/${encodeURIComponent(pollId)}`);
|
|
1354
1504
|
}
|
|
1355
1505
|
};
|
|
1356
1506
|
|
|
@@ -1363,9 +1513,13 @@ var ProfileAcquirers = class {
|
|
|
1363
1513
|
return this.request("POST", "/profile_acquirer", { body: params });
|
|
1364
1514
|
}
|
|
1365
1515
|
async update(profileId, profileAcquirerId, params) {
|
|
1366
|
-
return this.request(
|
|
1367
|
-
|
|
1368
|
-
|
|
1516
|
+
return this.request(
|
|
1517
|
+
"POST",
|
|
1518
|
+
`/profile_acquirer/${encodeURIComponent(profileId)}/${encodeURIComponent(profileAcquirerId)}`,
|
|
1519
|
+
{
|
|
1520
|
+
body: params
|
|
1521
|
+
}
|
|
1522
|
+
);
|
|
1369
1523
|
}
|
|
1370
1524
|
};
|
|
1371
1525
|
|
|
@@ -1375,35 +1529,47 @@ var Profiles = class {
|
|
|
1375
1529
|
this.request = request;
|
|
1376
1530
|
}
|
|
1377
1531
|
async create(accountId, params) {
|
|
1378
|
-
return this.request("POST", `/account/${accountId}/business_profile`, {
|
|
1532
|
+
return this.request("POST", `/account/${encodeURIComponent(accountId)}/business_profile`, {
|
|
1533
|
+
body: params
|
|
1534
|
+
});
|
|
1379
1535
|
}
|
|
1380
1536
|
async retrieve(accountId, profileId) {
|
|
1381
|
-
return this.request(
|
|
1537
|
+
return this.request(
|
|
1538
|
+
"GET",
|
|
1539
|
+
`/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}`
|
|
1540
|
+
);
|
|
1382
1541
|
}
|
|
1383
1542
|
async list(accountId) {
|
|
1384
|
-
return this.request("GET", `/account/${accountId}/business_profile`);
|
|
1543
|
+
return this.request("GET", `/account/${encodeURIComponent(accountId)}/business_profile`);
|
|
1385
1544
|
}
|
|
1386
1545
|
async update(accountId, profileId, params) {
|
|
1387
|
-
return this.request(
|
|
1388
|
-
|
|
1389
|
-
|
|
1546
|
+
return this.request(
|
|
1547
|
+
"POST",
|
|
1548
|
+
`/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}`,
|
|
1549
|
+
{
|
|
1550
|
+
body: params
|
|
1551
|
+
}
|
|
1552
|
+
);
|
|
1390
1553
|
}
|
|
1391
1554
|
async delete(accountId, profileId) {
|
|
1392
|
-
return this.request(
|
|
1555
|
+
return this.request(
|
|
1556
|
+
"DELETE",
|
|
1557
|
+
`/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}`
|
|
1558
|
+
);
|
|
1393
1559
|
}
|
|
1394
1560
|
// --- Advanced operations (Task 4.8) ---
|
|
1395
1561
|
/** Toggle extended card info for a profile. `POST /account/{accountId}/business_profile/{profileId}/toggle_extended_card_info` */
|
|
1396
1562
|
async toggleExtendedCardInfo(accountId, profileId) {
|
|
1397
1563
|
return this.request(
|
|
1398
1564
|
"POST",
|
|
1399
|
-
`/account/${accountId}/business_profile/${profileId}/toggle_extended_card_info`
|
|
1565
|
+
`/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}/toggle_extended_card_info`
|
|
1400
1566
|
);
|
|
1401
1567
|
}
|
|
1402
1568
|
/** Toggle connector agnostic MIT. `POST /account/{accountId}/business_profile/{profileId}/toggle_connector_agnostic_mit` */
|
|
1403
1569
|
async toggleConnectorAgnosticMit(accountId, profileId) {
|
|
1404
1570
|
return this.request(
|
|
1405
1571
|
"POST",
|
|
1406
|
-
`/account/${accountId}/business_profile/${profileId}/toggle_connector_agnostic_mit`
|
|
1572
|
+
`/account/${encodeURIComponent(accountId)}/business_profile/${encodeURIComponent(profileId)}/toggle_connector_agnostic_mit`
|
|
1407
1573
|
);
|
|
1408
1574
|
}
|
|
1409
1575
|
};
|
|
@@ -1438,7 +1604,7 @@ var Projects = class {
|
|
|
1438
1604
|
* @returns The project.
|
|
1439
1605
|
*/
|
|
1440
1606
|
async retrieve(projectId) {
|
|
1441
|
-
return this.request("GET", `/projects/${projectId}`);
|
|
1607
|
+
return this.request("GET", `/projects/${encodeURIComponent(projectId)}`);
|
|
1442
1608
|
}
|
|
1443
1609
|
/**
|
|
1444
1610
|
* Update a project's details.
|
|
@@ -1448,7 +1614,7 @@ var Projects = class {
|
|
|
1448
1614
|
* @returns The updated project.
|
|
1449
1615
|
*/
|
|
1450
1616
|
async update(projectId, params) {
|
|
1451
|
-
return this.request("PUT", `/projects/${projectId}`, { body: params });
|
|
1617
|
+
return this.request("PUT", `/projects/${encodeURIComponent(projectId)}`, { body: params });
|
|
1452
1618
|
}
|
|
1453
1619
|
/**
|
|
1454
1620
|
* Delete a project.
|
|
@@ -1457,7 +1623,7 @@ var Projects = class {
|
|
|
1457
1623
|
* @returns The deleted project object.
|
|
1458
1624
|
*/
|
|
1459
1625
|
async delete(projectId) {
|
|
1460
|
-
return this.request("DELETE", `/projects/${projectId}`);
|
|
1626
|
+
return this.request("DELETE", `/projects/${encodeURIComponent(projectId)}`);
|
|
1461
1627
|
}
|
|
1462
1628
|
/**
|
|
1463
1629
|
* List all projects for a merchant.
|
|
@@ -1528,7 +1694,7 @@ var Refunds = class {
|
|
|
1528
1694
|
* ```
|
|
1529
1695
|
*/
|
|
1530
1696
|
async retrieve(refundId) {
|
|
1531
|
-
return this.request("GET", `/refunds/${refundId}`);
|
|
1697
|
+
return this.request("GET", `/refunds/${encodeURIComponent(refundId)}`);
|
|
1532
1698
|
}
|
|
1533
1699
|
/**
|
|
1534
1700
|
* Update the reason or metadata on an existing refund.
|
|
@@ -1538,7 +1704,7 @@ var Refunds = class {
|
|
|
1538
1704
|
* @returns The updated refund.
|
|
1539
1705
|
*/
|
|
1540
1706
|
async update(refundId, params) {
|
|
1541
|
-
return this.request("POST", `/refunds/${refundId}`, { body: params });
|
|
1707
|
+
return this.request("POST", `/refunds/${encodeURIComponent(refundId)}`, { body: params });
|
|
1542
1708
|
}
|
|
1543
1709
|
/**
|
|
1544
1710
|
* List refunds, optionally filtered by payment, status, or date range.
|
|
@@ -1572,7 +1738,9 @@ var Refunds = class {
|
|
|
1572
1738
|
}
|
|
1573
1739
|
/** Manually update refund status. `PUT /refunds/{refundId}/manual-update` */
|
|
1574
1740
|
async manualUpdate(refundId, params) {
|
|
1575
|
-
return this.request("PUT", `/refunds/${refundId}/manual-update`, {
|
|
1741
|
+
return this.request("PUT", `/refunds/${encodeURIComponent(refundId)}/manual-update`, {
|
|
1742
|
+
body: params
|
|
1743
|
+
});
|
|
1576
1744
|
}
|
|
1577
1745
|
};
|
|
1578
1746
|
|
|
@@ -1585,7 +1753,7 @@ var Relay = class {
|
|
|
1585
1753
|
return this.request("POST", "/relay", { body: params });
|
|
1586
1754
|
}
|
|
1587
1755
|
async retrieve(relayId) {
|
|
1588
|
-
return this.request("GET", `/relay/${relayId}`);
|
|
1756
|
+
return this.request("GET", `/relay/${encodeURIComponent(relayId)}`);
|
|
1589
1757
|
}
|
|
1590
1758
|
};
|
|
1591
1759
|
|
|
@@ -1619,7 +1787,7 @@ var Routing = class {
|
|
|
1619
1787
|
* @returns The routing configuration.
|
|
1620
1788
|
*/
|
|
1621
1789
|
async retrieve(algorithmId) {
|
|
1622
|
-
return this.request("GET", `/routing/${algorithmId}`);
|
|
1790
|
+
return this.request("GET", `/routing/${encodeURIComponent(algorithmId)}`);
|
|
1623
1791
|
}
|
|
1624
1792
|
/**
|
|
1625
1793
|
* Activate a routing algorithm, making it the active routing strategy for the shop.
|
|
@@ -1628,7 +1796,7 @@ var Routing = class {
|
|
|
1628
1796
|
* @returns The activated routing configuration.
|
|
1629
1797
|
*/
|
|
1630
1798
|
async activate(algorithmId) {
|
|
1631
|
-
return this.request("POST", `/routing/${algorithmId}/activate`);
|
|
1799
|
+
return this.request("POST", `/routing/${encodeURIComponent(algorithmId)}/activate`);
|
|
1632
1800
|
}
|
|
1633
1801
|
/**
|
|
1634
1802
|
* Deactivate the currently active routing algorithm (falls back to default routing).
|
|
@@ -1661,7 +1829,9 @@ var Routing = class {
|
|
|
1661
1829
|
}
|
|
1662
1830
|
/** Update default config for a profile. `POST /routing/default/profile/{profileId}` */
|
|
1663
1831
|
async updateDefaultProfile(profileId, params) {
|
|
1664
|
-
return this.request("POST", `/routing/default/profile/${profileId}`, {
|
|
1832
|
+
return this.request("POST", `/routing/default/profile/${encodeURIComponent(profileId)}`, {
|
|
1833
|
+
body: params
|
|
1834
|
+
});
|
|
1665
1835
|
}
|
|
1666
1836
|
/** List routing configs for profile. `GET /routing/list/profile` */
|
|
1667
1837
|
async listForProfile() {
|
|
@@ -1728,7 +1898,11 @@ var ShopGateways = class {
|
|
|
1728
1898
|
* @returns The created gateway connection.
|
|
1729
1899
|
*/
|
|
1730
1900
|
async connect(merchantId, shopId, params) {
|
|
1731
|
-
return this.request(
|
|
1901
|
+
return this.request(
|
|
1902
|
+
"POST",
|
|
1903
|
+
`/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}/gateways`,
|
|
1904
|
+
{ body: params }
|
|
1905
|
+
);
|
|
1732
1906
|
}
|
|
1733
1907
|
/**
|
|
1734
1908
|
* List all gateway connections for a shop.
|
|
@@ -1738,7 +1912,10 @@ var ShopGateways = class {
|
|
|
1738
1912
|
* @returns Array of gateway connections.
|
|
1739
1913
|
*/
|
|
1740
1914
|
async list(merchantId, shopId) {
|
|
1741
|
-
return this.request(
|
|
1915
|
+
return this.request(
|
|
1916
|
+
"GET",
|
|
1917
|
+
`/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}/gateways`
|
|
1918
|
+
);
|
|
1742
1919
|
}
|
|
1743
1920
|
/**
|
|
1744
1921
|
* Disconnect a gateway from a shop.
|
|
@@ -1749,7 +1926,10 @@ var ShopGateways = class {
|
|
|
1749
1926
|
* @returns The removed gateway connection.
|
|
1750
1927
|
*/
|
|
1751
1928
|
async disconnect(merchantId, shopId, gatewayId) {
|
|
1752
|
-
return this.request(
|
|
1929
|
+
return this.request(
|
|
1930
|
+
"DELETE",
|
|
1931
|
+
`/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}/gateways/${encodeURIComponent(gatewayId)}`
|
|
1932
|
+
);
|
|
1753
1933
|
}
|
|
1754
1934
|
};
|
|
1755
1935
|
var Shops = class {
|
|
@@ -1770,7 +1950,7 @@ var Shops = class {
|
|
|
1770
1950
|
* ```
|
|
1771
1951
|
*/
|
|
1772
1952
|
async create(merchantId, params) {
|
|
1773
|
-
return this.request("POST", `/shops/${merchantId}`, { body: params });
|
|
1953
|
+
return this.request("POST", `/shops/${encodeURIComponent(merchantId)}`, { body: params });
|
|
1774
1954
|
}
|
|
1775
1955
|
/**
|
|
1776
1956
|
* Retrieve a shop by its ID.
|
|
@@ -1780,7 +1960,10 @@ var Shops = class {
|
|
|
1780
1960
|
* @returns The shop.
|
|
1781
1961
|
*/
|
|
1782
1962
|
async retrieve(merchantId, shopId) {
|
|
1783
|
-
return this.request(
|
|
1963
|
+
return this.request(
|
|
1964
|
+
"GET",
|
|
1965
|
+
`/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}`
|
|
1966
|
+
);
|
|
1784
1967
|
}
|
|
1785
1968
|
/**
|
|
1786
1969
|
* Update a shop's configuration.
|
|
@@ -1791,7 +1974,11 @@ var Shops = class {
|
|
|
1791
1974
|
* @returns The updated shop.
|
|
1792
1975
|
*/
|
|
1793
1976
|
async update(merchantId, shopId, params) {
|
|
1794
|
-
return this.request(
|
|
1977
|
+
return this.request(
|
|
1978
|
+
"PUT",
|
|
1979
|
+
`/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}`,
|
|
1980
|
+
{ body: params }
|
|
1981
|
+
);
|
|
1795
1982
|
}
|
|
1796
1983
|
/**
|
|
1797
1984
|
* Delete a shop.
|
|
@@ -1801,7 +1988,10 @@ var Shops = class {
|
|
|
1801
1988
|
* @returns The deleted shop object.
|
|
1802
1989
|
*/
|
|
1803
1990
|
async delete(merchantId, shopId) {
|
|
1804
|
-
return this.request(
|
|
1991
|
+
return this.request(
|
|
1992
|
+
"DELETE",
|
|
1993
|
+
`/shops/${encodeURIComponent(merchantId)}/${encodeURIComponent(shopId)}`
|
|
1994
|
+
);
|
|
1805
1995
|
}
|
|
1806
1996
|
/**
|
|
1807
1997
|
* List all shops under a merchant account.
|
|
@@ -1810,7 +2000,7 @@ var Shops = class {
|
|
|
1810
2000
|
* @returns Array of shops.
|
|
1811
2001
|
*/
|
|
1812
2002
|
async list(merchantId) {
|
|
1813
|
-
return this.request("GET", `/shops/${merchantId}`);
|
|
2003
|
+
return this.request("GET", `/shops/${encodeURIComponent(merchantId)}`);
|
|
1814
2004
|
}
|
|
1815
2005
|
};
|
|
1816
2006
|
|
|
@@ -2068,11 +2258,11 @@ var Users = class {
|
|
|
2068
2258
|
}
|
|
2069
2259
|
/** Get role by ID. `GET /user/role/{roleId}` */
|
|
2070
2260
|
async getRoleById(roleId) {
|
|
2071
|
-
return this.request("GET", `/user/role/${roleId}`);
|
|
2261
|
+
return this.request("GET", `/user/role/${encodeURIComponent(roleId)}`);
|
|
2072
2262
|
}
|
|
2073
2263
|
/** Update role by ID. `PUT /user/role/{roleId}` */
|
|
2074
2264
|
async updateRole(roleId, params) {
|
|
2075
|
-
return this.request("PUT", `/user/role/${roleId}`, { body: params });
|
|
2265
|
+
return this.request("PUT", `/user/role/${encodeURIComponent(roleId)}`, { body: params });
|
|
2076
2266
|
}
|
|
2077
2267
|
};
|
|
2078
2268
|
|
|
@@ -2082,7 +2272,9 @@ var Verification = class {
|
|
|
2082
2272
|
this.request = request;
|
|
2083
2273
|
}
|
|
2084
2274
|
async registerApplePayDomains(merchantId, params) {
|
|
2085
|
-
return this.request("POST", `/verify/apple_pay/${merchantId}`, {
|
|
2275
|
+
return this.request("POST", `/verify/apple_pay/${encodeURIComponent(merchantId)}`, {
|
|
2276
|
+
body: params
|
|
2277
|
+
});
|
|
2086
2278
|
}
|
|
2087
2279
|
async getApplePayVerifiedDomains(params) {
|
|
2088
2280
|
return this.request("GET", "/verify/applepay_verified_domains", {
|
|
@@ -2092,10 +2284,23 @@ var Verification = class {
|
|
|
2092
2284
|
};
|
|
2093
2285
|
|
|
2094
2286
|
// src/resources/webhooks.ts
|
|
2287
|
+
function hexToBytes(hex) {
|
|
2288
|
+
if (hex.length === 0 || hex.length % 2 !== 0) return null;
|
|
2289
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
2290
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
2291
|
+
const byte = Number.parseInt(hex.slice(i, i + 2), 16);
|
|
2292
|
+
if (Number.isNaN(byte)) return null;
|
|
2293
|
+
bytes[i / 2] = byte;
|
|
2294
|
+
}
|
|
2295
|
+
return bytes;
|
|
2296
|
+
}
|
|
2095
2297
|
var Webhooks = {
|
|
2096
2298
|
/**
|
|
2097
2299
|
* Verify the signature of an incoming Delopay webhook and return the parsed event.
|
|
2098
2300
|
*
|
|
2301
|
+
* Uses the Web Crypto API (`globalThis.crypto.subtle`), so it runs unchanged in
|
|
2302
|
+
* Node 18+, modern browsers, Deno, Bun, and edge runtimes (Cloudflare Workers, Vercel Edge).
|
|
2303
|
+
*
|
|
2099
2304
|
* This method is available as a static property on the `Delopay` class
|
|
2100
2305
|
* (`Delopay.webhooks.verify`) and does not require a client instance.
|
|
2101
2306
|
*
|
|
@@ -2103,14 +2308,14 @@ var Webhooks = {
|
|
|
2103
2308
|
* @param signatureHeader - The value of the `delopay-signature` HTTP header.
|
|
2104
2309
|
* @param secret - Your webhook signing secret from the Delopay dashboard.
|
|
2105
2310
|
* @param options - Optional verification settings (replay tolerance).
|
|
2106
|
-
* @returns
|
|
2311
|
+
* @returns Promise that resolves to the parsed webhook event.
|
|
2107
2312
|
* @throws {Error} When the signature is invalid, the timestamp is missing, or the event is too old.
|
|
2108
2313
|
*
|
|
2109
2314
|
* @example
|
|
2110
2315
|
* ```typescript
|
|
2111
2316
|
* // Express example
|
|
2112
|
-
* app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
|
|
2113
|
-
* const event = Delopay.webhooks.verify(
|
|
2317
|
+
* app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
2318
|
+
* const event = await Delopay.webhooks.verify(
|
|
2114
2319
|
* req.body.toString(),
|
|
2115
2320
|
* req.headers['delopay-signature'] as string,
|
|
2116
2321
|
* process.env.DELOPAY_WEBHOOK_SECRET!,
|
|
@@ -2120,7 +2325,7 @@ var Webhooks = {
|
|
|
2120
2325
|
* });
|
|
2121
2326
|
* ```
|
|
2122
2327
|
*/
|
|
2123
|
-
verify(rawBody, signatureHeader, secret, options) {
|
|
2328
|
+
async verify(rawBody, signatureHeader, secret, options) {
|
|
2124
2329
|
const tolerance = options?.tolerance ?? 300;
|
|
2125
2330
|
const parts = signatureHeader.split(",");
|
|
2126
2331
|
const timestampPart = parts.find((p) => p.startsWith("t="));
|
|
@@ -2128,19 +2333,29 @@ var Webhooks = {
|
|
|
2128
2333
|
if (!timestampPart || !signaturePart) {
|
|
2129
2334
|
throw new Error("Invalid webhook signature format");
|
|
2130
2335
|
}
|
|
2131
|
-
const timestamp = parseInt(timestampPart.slice(2), 10);
|
|
2336
|
+
const timestamp = Number.parseInt(timestampPart.slice(2), 10);
|
|
2132
2337
|
if (!Number.isFinite(timestamp)) {
|
|
2133
2338
|
throw new Error("Invalid webhook timestamp");
|
|
2134
2339
|
}
|
|
2135
|
-
const
|
|
2136
|
-
const
|
|
2137
|
-
const
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
const
|
|
2340
|
+
const signatureHex = signaturePart.slice(3);
|
|
2341
|
+
const signatureBytes = hexToBytes(signatureHex);
|
|
2342
|
+
const subtle = globalThis.crypto?.subtle;
|
|
2343
|
+
if (!subtle) {
|
|
2344
|
+
throw new Error(
|
|
2345
|
+
"Web Crypto unavailable: Delopay.webhooks.verify requires globalThis.crypto.subtle (Node 18+, modern browsers, Workers, Deno)"
|
|
2346
|
+
);
|
|
2347
|
+
}
|
|
2348
|
+
const encoder = new TextEncoder();
|
|
2349
|
+
const asBufferSource = (bytes) => bytes;
|
|
2350
|
+
const key = await subtle.importKey(
|
|
2351
|
+
"raw",
|
|
2352
|
+
asBufferSource(encoder.encode(secret)),
|
|
2353
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
2354
|
+
false,
|
|
2355
|
+
["verify"]
|
|
2356
|
+
);
|
|
2357
|
+
const signedPayload = asBufferSource(encoder.encode(`${timestamp}.${rawBody}`));
|
|
2358
|
+
const signaturesMatch = signatureBytes !== null && await subtle.verify("HMAC", key, asBufferSource(signatureBytes), signedPayload);
|
|
2144
2359
|
if (!signaturesMatch) {
|
|
2145
2360
|
throw new Error("Invalid webhook signature");
|
|
2146
2361
|
}
|
|
@@ -2161,22 +2376,30 @@ var AnalyticsDomain = class {
|
|
|
2161
2376
|
/** Get metrics. `POST /analytics/v1/metrics/{domain}` */
|
|
2162
2377
|
async metrics(params, scope) {
|
|
2163
2378
|
const prefix = scope ? `/analytics/v1/${scope}` : "/analytics/v1";
|
|
2164
|
-
return this.request("POST", `${prefix}/metrics/${this.domain}`, {
|
|
2379
|
+
return this.request("POST", `${prefix}/metrics/${encodeURIComponent(this.domain)}`, {
|
|
2380
|
+
body: [params]
|
|
2381
|
+
});
|
|
2165
2382
|
}
|
|
2166
2383
|
/** Get filters. `POST /analytics/v1/filters/{domain}` */
|
|
2167
2384
|
async filters(params, scope) {
|
|
2168
2385
|
const prefix = scope ? `/analytics/v1/${scope}` : "/analytics/v1";
|
|
2169
|
-
return this.request("POST", `${prefix}/filters/${this.domain}`, {
|
|
2386
|
+
return this.request("POST", `${prefix}/filters/${encodeURIComponent(this.domain)}`, {
|
|
2387
|
+
body: params
|
|
2388
|
+
});
|
|
2170
2389
|
}
|
|
2171
2390
|
/** Generate report. `POST /analytics/v1/report/{domain}` */
|
|
2172
2391
|
async report(params, scope) {
|
|
2173
2392
|
const prefix = scope ? `/analytics/v1/${scope}` : "/analytics/v1";
|
|
2174
|
-
return this.request("POST", `${prefix}/report/${this.domain}`, {
|
|
2393
|
+
return this.request("POST", `${prefix}/report/${encodeURIComponent(this.domain)}`, {
|
|
2394
|
+
body: params
|
|
2395
|
+
});
|
|
2175
2396
|
}
|
|
2176
2397
|
/** Sankey chart data. `POST /analytics/v1/metrics/{domain}/sankey` */
|
|
2177
2398
|
async sankey(params, scope) {
|
|
2178
2399
|
const prefix = scope ? `/analytics/v1/${scope}` : "/analytics/v1";
|
|
2179
|
-
return this.request("POST", `${prefix}/metrics/${this.domain}/sankey`, {
|
|
2400
|
+
return this.request("POST", `${prefix}/metrics/${encodeURIComponent(this.domain)}/sankey`, {
|
|
2401
|
+
body: params
|
|
2402
|
+
});
|
|
2180
2403
|
}
|
|
2181
2404
|
};
|
|
2182
2405
|
var Analytics = class {
|
|
@@ -2197,11 +2420,13 @@ var Analytics = class {
|
|
|
2197
2420
|
}
|
|
2198
2421
|
/** Domain-specific search. `POST /analytics/v1/search/{domain}` */
|
|
2199
2422
|
async searchDomain(domain, params) {
|
|
2200
|
-
return this.request("POST", `/analytics/v1/search/${domain}`, {
|
|
2423
|
+
return this.request("POST", `/analytics/v1/search/${encodeURIComponent(domain)}`, {
|
|
2424
|
+
body: params
|
|
2425
|
+
});
|
|
2201
2426
|
}
|
|
2202
2427
|
/** Get analytics info. `GET /analytics/v1/{domain}/info` */
|
|
2203
2428
|
async getInfo(domain) {
|
|
2204
|
-
return this.request("GET", `/analytics/v1/${domain}/info`);
|
|
2429
|
+
return this.request("GET", `/analytics/v1/${encodeURIComponent(domain)}/info`);
|
|
2205
2430
|
}
|
|
2206
2431
|
/** Get API event logs. `GET /analytics/v1/api_event_logs` */
|
|
2207
2432
|
async apiEventLogs(params) {
|
|
@@ -2247,7 +2472,7 @@ var Cache = class {
|
|
|
2247
2472
|
}
|
|
2248
2473
|
/** Invalidate a cache entry by key. `POST /cache/invalidate/{key}` */
|
|
2249
2474
|
async invalidate(key) {
|
|
2250
|
-
return this.request("POST", `/cache/invalidate/${key}`);
|
|
2475
|
+
return this.request("POST", `/cache/invalidate/${encodeURIComponent(key)}`);
|
|
2251
2476
|
}
|
|
2252
2477
|
};
|
|
2253
2478
|
|
|
@@ -2266,7 +2491,7 @@ var Cards = class {
|
|
|
2266
2491
|
}
|
|
2267
2492
|
/** Retrieve card info by BIN. `GET /cards/{bin}` */
|
|
2268
2493
|
async retrieve(bin) {
|
|
2269
|
-
return this.request("GET", `/cards/${bin}`);
|
|
2494
|
+
return this.request("GET", `/cards/${encodeURIComponent(bin)}`);
|
|
2270
2495
|
}
|
|
2271
2496
|
};
|
|
2272
2497
|
|
|
@@ -2281,15 +2506,15 @@ var Configs = class {
|
|
|
2281
2506
|
}
|
|
2282
2507
|
/** Retrieve a config by key. `GET /configs/{key}` */
|
|
2283
2508
|
async retrieve(key) {
|
|
2284
|
-
return this.request("GET", `/configs/${key}`);
|
|
2509
|
+
return this.request("GET", `/configs/${encodeURIComponent(key)}`);
|
|
2285
2510
|
}
|
|
2286
2511
|
/** Update a config. `PUT /configs/{key}` */
|
|
2287
2512
|
async update(key, params) {
|
|
2288
|
-
return this.request("PUT", `/configs/${key}`, { body: params });
|
|
2513
|
+
return this.request("PUT", `/configs/${encodeURIComponent(key)}`, { body: params });
|
|
2289
2514
|
}
|
|
2290
2515
|
/** Delete a config. `DELETE /configs/{key}` */
|
|
2291
2516
|
async delete(key) {
|
|
2292
|
-
return this.request("DELETE", `/configs/${key}`);
|
|
2517
|
+
return this.request("DELETE", `/configs/${encodeURIComponent(key)}`);
|
|
2293
2518
|
}
|
|
2294
2519
|
};
|
|
2295
2520
|
|
|
@@ -2326,11 +2551,11 @@ var Files = class {
|
|
|
2326
2551
|
}
|
|
2327
2552
|
/** Retrieve/download a file. `GET /files/{fileId}` */
|
|
2328
2553
|
async retrieve(fileId) {
|
|
2329
|
-
return this.request("GET", `/files/${fileId}`);
|
|
2554
|
+
return this.request("GET", `/files/${encodeURIComponent(fileId)}`);
|
|
2330
2555
|
}
|
|
2331
2556
|
/** Delete a file. `DELETE /files/{fileId}` */
|
|
2332
2557
|
async delete(fileId) {
|
|
2333
|
-
return this.request("DELETE", `/files/${fileId}`);
|
|
2558
|
+
return this.request("DELETE", `/files/${encodeURIComponent(fileId)}`);
|
|
2334
2559
|
}
|
|
2335
2560
|
};
|
|
2336
2561
|
|
|
@@ -2360,15 +2585,15 @@ var Regions = class {
|
|
|
2360
2585
|
}
|
|
2361
2586
|
/** Retrieve a region by ID. `GET /regions/{regionId}` */
|
|
2362
2587
|
async retrieve(regionId) {
|
|
2363
|
-
return this.request("GET", `/regions/${regionId}`);
|
|
2588
|
+
return this.request("GET", `/regions/${encodeURIComponent(regionId)}`);
|
|
2364
2589
|
}
|
|
2365
2590
|
/** Update a region. `PUT /regions/{regionId}` */
|
|
2366
2591
|
async update(regionId, params) {
|
|
2367
|
-
return this.request("PUT", `/regions/${regionId}`, { body: params });
|
|
2592
|
+
return this.request("PUT", `/regions/${encodeURIComponent(regionId)}`, { body: params });
|
|
2368
2593
|
}
|
|
2369
2594
|
/** Delete a region. `DELETE /regions/{regionId}` */
|
|
2370
2595
|
async delete(regionId) {
|
|
2371
|
-
return this.request("DELETE", `/regions/${regionId}`);
|
|
2596
|
+
return this.request("DELETE", `/regions/${encodeURIComponent(regionId)}`);
|
|
2372
2597
|
}
|
|
2373
2598
|
/** List all regions. `GET /regions/list` */
|
|
2374
2599
|
async list() {
|
|
@@ -2391,17 +2616,19 @@ var Subscriptions = class {
|
|
|
2391
2616
|
}
|
|
2392
2617
|
/** Retrieve a subscription by ID. `GET /subscriptions/{subscriptionId}` */
|
|
2393
2618
|
async retrieve(subscriptionId) {
|
|
2394
|
-
return this.request("GET", `/subscriptions/${subscriptionId}`);
|
|
2619
|
+
return this.request("GET", `/subscriptions/${encodeURIComponent(subscriptionId)}`);
|
|
2395
2620
|
}
|
|
2396
2621
|
/** Confirm a subscription. `POST /subscriptions/{subscriptionId}/confirm` */
|
|
2397
2622
|
async confirm(subscriptionId, params) {
|
|
2398
|
-
return this.request("POST", `/subscriptions/${subscriptionId}/confirm`, {
|
|
2623
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/confirm`, {
|
|
2399
2624
|
body: params
|
|
2400
2625
|
});
|
|
2401
2626
|
}
|
|
2402
2627
|
/** Update a subscription. `PUT /subscriptions/{subscriptionId}/update` */
|
|
2403
2628
|
async update(subscriptionId, params) {
|
|
2404
|
-
return this.request("PUT", `/subscriptions/${subscriptionId}/update`, {
|
|
2629
|
+
return this.request("PUT", `/subscriptions/${encodeURIComponent(subscriptionId)}/update`, {
|
|
2630
|
+
body: params
|
|
2631
|
+
});
|
|
2405
2632
|
}
|
|
2406
2633
|
/** List subscriptions. `GET /subscriptions/list` */
|
|
2407
2634
|
async list(params) {
|
|
@@ -2419,21 +2646,95 @@ var Subscriptions = class {
|
|
|
2419
2646
|
}
|
|
2420
2647
|
/** Pause a subscription. `POST /subscriptions/{subscriptionId}/pause` */
|
|
2421
2648
|
async pause(subscriptionId) {
|
|
2422
|
-
return this.request("POST", `/subscriptions/${subscriptionId}/pause`);
|
|
2649
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/pause`);
|
|
2423
2650
|
}
|
|
2424
2651
|
/** Resume a subscription. `POST /subscriptions/{subscriptionId}/resume` */
|
|
2425
2652
|
async resume(subscriptionId) {
|
|
2426
|
-
return this.request("POST", `/subscriptions/${subscriptionId}/resume`);
|
|
2653
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/resume`);
|
|
2427
2654
|
}
|
|
2428
2655
|
/** Cancel a subscription. `POST /subscriptions/{subscriptionId}/cancel` */
|
|
2429
2656
|
async cancel(subscriptionId) {
|
|
2430
|
-
return this.request("POST", `/subscriptions/${subscriptionId}/cancel`);
|
|
2657
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`);
|
|
2431
2658
|
}
|
|
2432
2659
|
};
|
|
2433
2660
|
|
|
2434
2661
|
// src/client.ts
|
|
2435
2662
|
var PRODUCTION_URL = "https://api.delopay.net";
|
|
2436
2663
|
var SANDBOX_URL = "https://sandbox.delopay.net";
|
|
2664
|
+
var MAX_RAW_BODY_BYTES = 2048;
|
|
2665
|
+
var MAX_RETRY_AFTER_MS = 3e4;
|
|
2666
|
+
function parseRetryAfter(header) {
|
|
2667
|
+
if (!header) return null;
|
|
2668
|
+
const trimmed = header.trim();
|
|
2669
|
+
const seconds = Number(trimmed);
|
|
2670
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
2671
|
+
return Math.min(seconds * 1e3, MAX_RETRY_AFTER_MS);
|
|
2672
|
+
}
|
|
2673
|
+
const date = Date.parse(trimmed);
|
|
2674
|
+
if (Number.isFinite(date)) {
|
|
2675
|
+
const delta = date - Date.now();
|
|
2676
|
+
return delta > 0 ? Math.min(delta, MAX_RETRY_AFTER_MS) : 0;
|
|
2677
|
+
}
|
|
2678
|
+
return null;
|
|
2679
|
+
}
|
|
2680
|
+
function truncateRawBody(raw) {
|
|
2681
|
+
if (!raw) return void 0;
|
|
2682
|
+
return raw.length > MAX_RAW_BODY_BYTES ? raw.slice(0, MAX_RAW_BODY_BYTES) + "\u2026" : raw;
|
|
2683
|
+
}
|
|
2684
|
+
function findIdempotencyKey(headers) {
|
|
2685
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
2686
|
+
if (k.toLowerCase() === "idempotency-key") return v;
|
|
2687
|
+
}
|
|
2688
|
+
return void 0;
|
|
2689
|
+
}
|
|
2690
|
+
function noop() {
|
|
2691
|
+
}
|
|
2692
|
+
function combineSignals(signals) {
|
|
2693
|
+
const controller = new AbortController();
|
|
2694
|
+
const listeners = [];
|
|
2695
|
+
const dispose = () => {
|
|
2696
|
+
for (const { signal, handler } of listeners) {
|
|
2697
|
+
signal.removeEventListener("abort", handler);
|
|
2698
|
+
}
|
|
2699
|
+
listeners.length = 0;
|
|
2700
|
+
};
|
|
2701
|
+
for (const signal of signals) {
|
|
2702
|
+
if (signal.aborted) {
|
|
2703
|
+
controller.abort(signal.reason);
|
|
2704
|
+
dispose();
|
|
2705
|
+
return { signal: controller.signal, dispose: noop };
|
|
2706
|
+
}
|
|
2707
|
+
const handler = () => {
|
|
2708
|
+
controller.abort(signal.reason);
|
|
2709
|
+
dispose();
|
|
2710
|
+
};
|
|
2711
|
+
signal.addEventListener("abort", handler, { once: true });
|
|
2712
|
+
listeners.push({ signal, handler });
|
|
2713
|
+
}
|
|
2714
|
+
return { signal: controller.signal, dispose };
|
|
2715
|
+
}
|
|
2716
|
+
var SENSITIVE_QUERY_KEYS = /* @__PURE__ */ new Set([
|
|
2717
|
+
"client_secret",
|
|
2718
|
+
"ephemeral_key",
|
|
2719
|
+
"api_key",
|
|
2720
|
+
"publishable_key"
|
|
2721
|
+
]);
|
|
2722
|
+
function redactUrlForLogging(url) {
|
|
2723
|
+
const qIdx = url.indexOf("?");
|
|
2724
|
+
if (qIdx === -1) return url;
|
|
2725
|
+
const base = url.slice(0, qIdx);
|
|
2726
|
+
const query = url.slice(qIdx + 1);
|
|
2727
|
+
const parts = query.split("&").map((pair) => {
|
|
2728
|
+
const eqIdx = pair.indexOf("=");
|
|
2729
|
+
if (eqIdx === -1) return pair;
|
|
2730
|
+
const key = pair.slice(0, eqIdx);
|
|
2731
|
+
if (SENSITIVE_QUERY_KEYS.has(decodeURIComponent(key).toLowerCase())) {
|
|
2732
|
+
return `${key}=REDACTED`;
|
|
2733
|
+
}
|
|
2734
|
+
return pair;
|
|
2735
|
+
});
|
|
2736
|
+
return `${base}?${parts.join("&")}`;
|
|
2737
|
+
}
|
|
2437
2738
|
var Delopay = class {
|
|
2438
2739
|
/**
|
|
2439
2740
|
* Create a new Delopay client.
|
|
@@ -2447,6 +2748,7 @@ var Delopay = class {
|
|
|
2447
2748
|
this.timeout = options?.timeout ?? 3e4;
|
|
2448
2749
|
this.maxRetries = options?.maxRetries ?? 2;
|
|
2449
2750
|
this.debug = options?.debug ?? false;
|
|
2751
|
+
if (options?.logger !== void 0) this.logger = options.logger;
|
|
2450
2752
|
if (options?.baseUrl !== void 0) {
|
|
2451
2753
|
this.baseUrl = options.baseUrl;
|
|
2452
2754
|
} else if (options?.sandbox) {
|
|
@@ -2532,7 +2834,12 @@ var Delopay = class {
|
|
|
2532
2834
|
if (options?.query) {
|
|
2533
2835
|
const params = new URLSearchParams();
|
|
2534
2836
|
for (const [key, value] of Object.entries(options.query)) {
|
|
2535
|
-
if (value
|
|
2837
|
+
if (value === void 0 || value === null) continue;
|
|
2838
|
+
if (Array.isArray(value)) {
|
|
2839
|
+
for (const v of value) {
|
|
2840
|
+
if (v !== void 0 && v !== null) params.append(key, String(v));
|
|
2841
|
+
}
|
|
2842
|
+
} else {
|
|
2536
2843
|
params.set(key, String(value));
|
|
2537
2844
|
}
|
|
2538
2845
|
}
|
|
@@ -2548,46 +2855,94 @@ var Delopay = class {
|
|
|
2548
2855
|
if (options?.body) {
|
|
2549
2856
|
headers["Content-Type"] = "application/json";
|
|
2550
2857
|
}
|
|
2551
|
-
const
|
|
2858
|
+
const idempotencyKey = findIdempotencyKey(headers)?.trim();
|
|
2859
|
+
const isRetryable = method === "GET" || method === "DELETE" || idempotencyKey !== void 0 && idempotencyKey !== "";
|
|
2860
|
+
const serializedBody = options?.body ? JSON.stringify(options.body) : void 0;
|
|
2861
|
+
const callerSignal = options?.signal;
|
|
2862
|
+
if (callerSignal?.aborted) {
|
|
2863
|
+
throw new DelopayError("Request aborted", {
|
|
2864
|
+
status: 0,
|
|
2865
|
+
code: "ABORTED",
|
|
2866
|
+
type: "abort_error"
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
const timeoutMs = options?.timeout ?? this.timeout;
|
|
2552
2870
|
let lastError;
|
|
2871
|
+
let retryAfterOverrideMs = null;
|
|
2872
|
+
const safeUrl = () => redactUrlForLogging(url);
|
|
2873
|
+
const emit = (event, data) => {
|
|
2874
|
+
if (!this.debug) return;
|
|
2875
|
+
if (this.logger) {
|
|
2876
|
+
this.logger(event, data);
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2879
|
+
if (event === "request")
|
|
2880
|
+
console.log(`[delopay] ${data.method} ${data.url}`);
|
|
2881
|
+
else if (event === "response")
|
|
2882
|
+
console.log(
|
|
2883
|
+
`[delopay] ${data.status} ${data.method} ${data.path}`
|
|
2884
|
+
);
|
|
2885
|
+
else
|
|
2886
|
+
console.log(
|
|
2887
|
+
`[delopay] retry ${data.attempt}/${data.maxRetries} ${data.method} ${data.path}`
|
|
2888
|
+
);
|
|
2889
|
+
};
|
|
2553
2890
|
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
2554
2891
|
if (attempt > 0) {
|
|
2555
|
-
const
|
|
2892
|
+
const base = Math.min(500 * 2 ** (attempt - 1), 5e3);
|
|
2893
|
+
const jittered = Math.random() * base;
|
|
2894
|
+
const delay = Math.max(retryAfterOverrideMs ?? 0, jittered);
|
|
2895
|
+
retryAfterOverrideMs = null;
|
|
2556
2896
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2557
|
-
|
|
2558
|
-
console.log(`[delopay] retry ${attempt}/${this.maxRetries} ${method} ${path}`);
|
|
2559
|
-
}
|
|
2897
|
+
emit("retry", { attempt, maxRetries: this.maxRetries, method, path });
|
|
2560
2898
|
}
|
|
2561
|
-
const
|
|
2562
|
-
const timeoutId = setTimeout(() =>
|
|
2899
|
+
const timeoutCtrl = new AbortController();
|
|
2900
|
+
const timeoutId = setTimeout(() => timeoutCtrl.abort(), timeoutMs);
|
|
2901
|
+
const combined = combineSignals(
|
|
2902
|
+
callerSignal ? [timeoutCtrl.signal, callerSignal] : [timeoutCtrl.signal]
|
|
2903
|
+
);
|
|
2563
2904
|
try {
|
|
2564
|
-
|
|
2565
|
-
console.log(`[delopay] ${method} ${url}`);
|
|
2566
|
-
}
|
|
2905
|
+
emit("request", { method, url: safeUrl(), path });
|
|
2567
2906
|
const response = await fetch(url, {
|
|
2568
2907
|
method,
|
|
2569
2908
|
headers,
|
|
2570
|
-
body:
|
|
2571
|
-
signal:
|
|
2909
|
+
body: serializedBody,
|
|
2910
|
+
signal: combined.signal
|
|
2572
2911
|
});
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
}
|
|
2912
|
+
const requestId = response.headers?.get("x-request-id") ?? response.headers?.get("x-trace-id") ?? void 0;
|
|
2913
|
+
emit("response", { status: response.status, method, path, requestId });
|
|
2576
2914
|
if (!response.ok) {
|
|
2577
|
-
const
|
|
2578
|
-
|
|
2915
|
+
const rawBody = await response.text().catch(() => "");
|
|
2916
|
+
let parsed = {};
|
|
2917
|
+
if (rawBody) {
|
|
2918
|
+
try {
|
|
2919
|
+
parsed = JSON.parse(rawBody);
|
|
2920
|
+
} catch {
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
const err = parsed.error ?? parsed;
|
|
2579
2924
|
const message = err.message ?? `Request failed with status ${response.status}`;
|
|
2580
2925
|
const code = err.code ?? "";
|
|
2581
2926
|
const type = err.error_type ?? err.type ?? "";
|
|
2927
|
+
const truncatedRaw = truncateRawBody(rawBody);
|
|
2582
2928
|
if (response.status === 401) {
|
|
2583
|
-
throw new DelopayAuthenticationError(message
|
|
2929
|
+
throw new DelopayAuthenticationError(message, {
|
|
2930
|
+
requestId,
|
|
2931
|
+
rawBody: truncatedRaw
|
|
2932
|
+
});
|
|
2584
2933
|
}
|
|
2585
2934
|
const error = new DelopayError(message, {
|
|
2586
2935
|
status: response.status,
|
|
2587
2936
|
code,
|
|
2588
|
-
type
|
|
2937
|
+
type,
|
|
2938
|
+
requestId,
|
|
2939
|
+
rawBody: truncatedRaw
|
|
2589
2940
|
});
|
|
2590
|
-
|
|
2941
|
+
const isTransientStatus = response.status >= 500 || response.status === 429;
|
|
2942
|
+
if (isTransientStatus && isRetryable && attempt < this.maxRetries) {
|
|
2943
|
+
if (response.status === 429) {
|
|
2944
|
+
retryAfterOverrideMs = parseRetryAfter(response.headers?.get("retry-after") ?? null);
|
|
2945
|
+
}
|
|
2591
2946
|
lastError = error;
|
|
2592
2947
|
continue;
|
|
2593
2948
|
}
|
|
@@ -2599,7 +2954,14 @@ var Delopay = class {
|
|
|
2599
2954
|
if (err instanceof DelopayError || err instanceof DelopayAuthenticationError) {
|
|
2600
2955
|
throw err;
|
|
2601
2956
|
}
|
|
2602
|
-
if (err instanceof
|
|
2957
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
2958
|
+
if (callerSignal?.aborted) {
|
|
2959
|
+
throw new DelopayError("Request aborted", {
|
|
2960
|
+
status: 0,
|
|
2961
|
+
code: "ABORTED",
|
|
2962
|
+
type: "abort_error"
|
|
2963
|
+
});
|
|
2964
|
+
}
|
|
2603
2965
|
lastError = new DelopayError("Request timed out", {
|
|
2604
2966
|
status: 0,
|
|
2605
2967
|
code: "TIMEOUT",
|
|
@@ -2620,6 +2982,7 @@ var Delopay = class {
|
|
|
2620
2982
|
throw err;
|
|
2621
2983
|
} finally {
|
|
2622
2984
|
clearTimeout(timeoutId);
|
|
2985
|
+
combined.dispose();
|
|
2623
2986
|
}
|
|
2624
2987
|
}
|
|
2625
2988
|
throw lastError;
|