@delopay/sdk 0.30.0 → 0.32.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/README.md +10 -4
- package/dist/{chunk-INP6UXMJ.js → chunk-ML3Z6JBP.js} +92 -37
- package/dist/chunk-ML3Z6JBP.js.map +1 -0
- package/dist/index.cjs +91 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +372 -56
- package/dist/index.d.ts +372 -56
- package/dist/index.js +1 -1
- package/dist/internal.cjs +91 -36
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/package.json +16 -16
- package/dist/chunk-INP6UXMJ.js.map +0 -1
package/dist/internal.cjs
CHANGED
|
@@ -1014,19 +1014,21 @@ var Payments = class {
|
|
|
1014
1014
|
* Create a new payment intent.
|
|
1015
1015
|
*
|
|
1016
1016
|
* @param params - Payment creation parameters including amount and currency.
|
|
1017
|
+
* @param options - Optional per-call extras: extra `headers` (e.g. an
|
|
1018
|
+
* `Idempotency-Key` to make the create safe to retry), a `timeout` override,
|
|
1019
|
+
* and an `AbortSignal`.
|
|
1017
1020
|
* @returns The created payment intent.
|
|
1018
1021
|
*
|
|
1019
1022
|
* @example
|
|
1020
1023
|
* ```typescript
|
|
1021
|
-
* const payment = await delopay.payments.create(
|
|
1022
|
-
* amount: 5000,
|
|
1023
|
-
*
|
|
1024
|
-
*
|
|
1025
|
-
* });
|
|
1024
|
+
* const payment = await delopay.payments.create(
|
|
1025
|
+
* { amount: 5000, currency: 'EUR', customer_id: 'cus_123' },
|
|
1026
|
+
* { headers: { 'Idempotency-Key': 'order_1001' } },
|
|
1027
|
+
* );
|
|
1026
1028
|
* ```
|
|
1027
1029
|
*/
|
|
1028
|
-
async create(params) {
|
|
1029
|
-
return this.request("POST", "/payments", { body: params });
|
|
1030
|
+
async create(params, options) {
|
|
1031
|
+
return this.request("POST", "/payments", { body: params, ...options });
|
|
1030
1032
|
}
|
|
1031
1033
|
/**
|
|
1032
1034
|
* Retrieve a payment by its ID.
|
|
@@ -1110,6 +1112,8 @@ var Payments = class {
|
|
|
1110
1112
|
* List payment intents, optionally filtered by customer or date range.
|
|
1111
1113
|
*
|
|
1112
1114
|
* @param params - Optional filter and pagination parameters.
|
|
1115
|
+
* @param options - Optional per-call extras: extra `headers`, a `timeout`
|
|
1116
|
+
* override, and an `AbortSignal` for cancellation.
|
|
1113
1117
|
* @returns Paginated list of payment intents.
|
|
1114
1118
|
*
|
|
1115
1119
|
* @example
|
|
@@ -1117,9 +1121,10 @@ var Payments = class {
|
|
|
1117
1121
|
* const { data } = await delopay.payments.list({ customer_id: 'cus_123', limit: 25 });
|
|
1118
1122
|
* ```
|
|
1119
1123
|
*/
|
|
1120
|
-
async list(params) {
|
|
1124
|
+
async list(params, options) {
|
|
1121
1125
|
return this.request("GET", "/payments/list", {
|
|
1122
|
-
query: params
|
|
1126
|
+
query: params,
|
|
1127
|
+
...options
|
|
1123
1128
|
});
|
|
1124
1129
|
}
|
|
1125
1130
|
// --- Advanced operations (Task 3.2) ---
|
|
@@ -1840,7 +1845,7 @@ var Shops = class {
|
|
|
1840
1845
|
*
|
|
1841
1846
|
* @example
|
|
1842
1847
|
* ```typescript
|
|
1843
|
-
* const shop = await delopay.shops.create('merch_123', {
|
|
1848
|
+
* const shop = await delopay.shops.create('merch_123', { shop_name: 'EU Store' });
|
|
1844
1849
|
* ```
|
|
1845
1850
|
*/
|
|
1846
1851
|
async create(merchantId, params) {
|
|
@@ -2600,11 +2605,16 @@ var Subscriptions = class {
|
|
|
2600
2605
|
constructor(request) {
|
|
2601
2606
|
this.request = request;
|
|
2602
2607
|
}
|
|
2603
|
-
/**
|
|
2608
|
+
/**
|
|
2609
|
+
* Create and immediately confirm a subscription. `POST /subscriptions`
|
|
2610
|
+
*
|
|
2611
|
+
* For billing processors that require buyer approval (e.g. PayPal), the
|
|
2612
|
+
* response carries a `redirect_url` the customer must be sent to.
|
|
2613
|
+
*/
|
|
2604
2614
|
async createAndConfirm(params) {
|
|
2605
2615
|
return this.request("POST", "/subscriptions", { body: params });
|
|
2606
2616
|
}
|
|
2607
|
-
/** Create a subscription
|
|
2617
|
+
/** Create a subscription without confirming it. `POST /subscriptions/create` */
|
|
2608
2618
|
async create(params) {
|
|
2609
2619
|
return this.request("POST", "/subscriptions/create", { body: params });
|
|
2610
2620
|
}
|
|
@@ -2612,43 +2622,58 @@ var Subscriptions = class {
|
|
|
2612
2622
|
async retrieve(subscriptionId) {
|
|
2613
2623
|
return this.request("GET", `/subscriptions/${encodeURIComponent(subscriptionId)}`);
|
|
2614
2624
|
}
|
|
2615
|
-
/**
|
|
2625
|
+
/**
|
|
2626
|
+
* Confirm a previously created subscription. `POST /subscriptions/{subscriptionId}/confirm`
|
|
2627
|
+
*
|
|
2628
|
+
* Like {@link createAndConfirm}, the response may carry a `redirect_url` for
|
|
2629
|
+
* processors that require buyer approval.
|
|
2630
|
+
*/
|
|
2616
2631
|
async confirm(subscriptionId, params) {
|
|
2617
2632
|
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/confirm`, {
|
|
2618
2633
|
body: params
|
|
2619
2634
|
});
|
|
2620
2635
|
}
|
|
2621
|
-
/** Update a subscription. `PUT /subscriptions/{subscriptionId}/update` */
|
|
2636
|
+
/** Update a subscription's plan/price. `PUT /subscriptions/{subscriptionId}/update` */
|
|
2622
2637
|
async update(subscriptionId, params) {
|
|
2623
2638
|
return this.request("PUT", `/subscriptions/${encodeURIComponent(subscriptionId)}/update`, {
|
|
2624
2639
|
body: params
|
|
2625
2640
|
});
|
|
2626
2641
|
}
|
|
2627
|
-
/** List subscriptions. `GET /subscriptions/list` */
|
|
2642
|
+
/** List subscriptions for the profile. `GET /subscriptions/list` */
|
|
2628
2643
|
async list(params) {
|
|
2629
2644
|
return this.request("GET", "/subscriptions/list", {
|
|
2630
2645
|
query: params
|
|
2631
2646
|
});
|
|
2632
2647
|
}
|
|
2633
|
-
/**
|
|
2648
|
+
/** Estimate the cost of a subscription before creating it. `GET /subscriptions/estimate` */
|
|
2634
2649
|
async getEstimate(params) {
|
|
2635
|
-
return this.request("GET", "/subscriptions/estimate", {
|
|
2650
|
+
return this.request("GET", "/subscriptions/estimate", {
|
|
2651
|
+
query: params
|
|
2652
|
+
});
|
|
2636
2653
|
}
|
|
2637
|
-
/**
|
|
2654
|
+
/** List purchasable subscription items (plans/addons). `GET /subscriptions/items` */
|
|
2638
2655
|
async getItems(params) {
|
|
2639
|
-
return this.request("GET", "/subscriptions/items", {
|
|
2656
|
+
return this.request("GET", "/subscriptions/items", {
|
|
2657
|
+
query: params
|
|
2658
|
+
});
|
|
2640
2659
|
}
|
|
2641
2660
|
/** Pause a subscription. `POST /subscriptions/{subscriptionId}/pause` */
|
|
2642
|
-
async pause(subscriptionId) {
|
|
2643
|
-
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/pause
|
|
2661
|
+
async pause(subscriptionId, params) {
|
|
2662
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/pause`, {
|
|
2663
|
+
body: params
|
|
2664
|
+
});
|
|
2644
2665
|
}
|
|
2645
|
-
/** Resume a subscription. `POST /subscriptions/{subscriptionId}/resume` */
|
|
2646
|
-
async resume(subscriptionId) {
|
|
2647
|
-
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/resume
|
|
2666
|
+
/** Resume a paused subscription. `POST /subscriptions/{subscriptionId}/resume` */
|
|
2667
|
+
async resume(subscriptionId, params) {
|
|
2668
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/resume`, {
|
|
2669
|
+
body: params
|
|
2670
|
+
});
|
|
2648
2671
|
}
|
|
2649
2672
|
/** Cancel a subscription. `POST /subscriptions/{subscriptionId}/cancel` */
|
|
2650
|
-
async cancel(subscriptionId) {
|
|
2651
|
-
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel
|
|
2673
|
+
async cancel(subscriptionId, params) {
|
|
2674
|
+
return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`, {
|
|
2675
|
+
body: params
|
|
2676
|
+
});
|
|
2652
2677
|
}
|
|
2653
2678
|
};
|
|
2654
2679
|
|
|
@@ -2733,7 +2758,7 @@ var Delopay = class {
|
|
|
2733
2758
|
/**
|
|
2734
2759
|
* Create a new Delopay client.
|
|
2735
2760
|
*
|
|
2736
|
-
* @param apiKey - Your Delopay API key (e.g. `
|
|
2761
|
+
* @param apiKey - Your Delopay API key (e.g. `prd_...` or `snd_...`).
|
|
2737
2762
|
* Pass an empty string or omit for JWT-only usage (e.g. dashboard apps).
|
|
2738
2763
|
* @param options - Optional configuration (sandbox mode, base URL override, timeout).
|
|
2739
2764
|
*/
|
|
@@ -2990,34 +3015,64 @@ var Delopay = class {
|
|
|
2990
3015
|
* Auto-paginate a list endpoint. Yields items one by one, fetching
|
|
2991
3016
|
* the next page automatically when the current one is exhausted.
|
|
2992
3017
|
*
|
|
2993
|
-
*
|
|
3018
|
+
* Delopay list endpoints use one of two pagination styles, so this helper
|
|
3019
|
+
* supports both:
|
|
3020
|
+
* - **Offset** (default) — for endpoints like `customers.list` that accept
|
|
3021
|
+
* `offset`/`limit`. Each page advances `offset` by the number of items returned.
|
|
3022
|
+
* - **Cursor** — for endpoints like `payments.list` and `payouts.list` that page
|
|
3023
|
+
* with `starting_after`/`limit` (they ignore `offset`). Pass a `cursor` extractor
|
|
3024
|
+
* that returns the id of an item; the next page is requested with
|
|
3025
|
+
* `starting_after` set to the last item's id.
|
|
3026
|
+
*
|
|
3027
|
+
* @param listFn - A function that takes the paging params and returns `{ data: T[] }` or `T[]`.
|
|
2994
3028
|
* @param params - Additional parameters to pass to every page request.
|
|
2995
|
-
* @param
|
|
3029
|
+
* @param options - Page size (number) for offset mode, or `{ pageSize?, cursor? }`.
|
|
3030
|
+
* Provide `cursor` to switch to cursor pagination.
|
|
2996
3031
|
*
|
|
2997
3032
|
* @example
|
|
2998
3033
|
* ```typescript
|
|
3034
|
+
* // Offset endpoint (customers):
|
|
3035
|
+
* for await (const c of delopay.paginate((p) => delopay.customers.list(p))) {
|
|
3036
|
+
* console.log(c.customer_id);
|
|
3037
|
+
* }
|
|
3038
|
+
*
|
|
3039
|
+
* // Cursor endpoint (payments): extract the id used as the next cursor.
|
|
2999
3040
|
* for await (const payment of delopay.paginate(
|
|
3000
3041
|
* (p) => delopay.payments.list(p),
|
|
3042
|
+
* undefined,
|
|
3043
|
+
* { cursor: (p) => p.payment_id },
|
|
3001
3044
|
* )) {
|
|
3002
3045
|
* console.log(payment.payment_id);
|
|
3003
3046
|
* }
|
|
3004
3047
|
* ```
|
|
3005
3048
|
*/
|
|
3006
|
-
async *paginate(listFn, params,
|
|
3049
|
+
async *paginate(listFn, params, options) {
|
|
3050
|
+
const pageSize = typeof options === "number" ? options : options?.pageSize ?? 50;
|
|
3051
|
+
const cursorOf = typeof options === "object" ? options.cursor : void 0;
|
|
3007
3052
|
let offset = 0;
|
|
3053
|
+
let after;
|
|
3008
3054
|
while (true) {
|
|
3009
|
-
const
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3055
|
+
const page = { ...params ?? {}, limit: pageSize };
|
|
3056
|
+
if (cursorOf) {
|
|
3057
|
+
if (after !== void 0) page.starting_after = after;
|
|
3058
|
+
} else {
|
|
3059
|
+
page.offset = offset;
|
|
3060
|
+
}
|
|
3061
|
+
const result = await listFn(page);
|
|
3014
3062
|
const items = Array.isArray(result) ? result : result.data;
|
|
3015
3063
|
if (items.length === 0) break;
|
|
3016
3064
|
for (const item of items) {
|
|
3017
3065
|
yield item;
|
|
3018
3066
|
}
|
|
3019
3067
|
if (items.length < pageSize) break;
|
|
3020
|
-
|
|
3068
|
+
if (cursorOf) {
|
|
3069
|
+
const last = items[items.length - 1];
|
|
3070
|
+
if (last === void 0) break;
|
|
3071
|
+
after = cursorOf(last);
|
|
3072
|
+
if (after === void 0) break;
|
|
3073
|
+
} else {
|
|
3074
|
+
offset += items.length;
|
|
3075
|
+
}
|
|
3021
3076
|
}
|
|
3022
3077
|
}
|
|
3023
3078
|
};
|