@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/dist/index.cjs CHANGED
@@ -1003,19 +1003,21 @@ var Payments = class {
1003
1003
  * Create a new payment intent.
1004
1004
  *
1005
1005
  * @param params - Payment creation parameters including amount and currency.
1006
+ * @param options - Optional per-call extras: extra `headers` (e.g. an
1007
+ * `Idempotency-Key` to make the create safe to retry), a `timeout` override,
1008
+ * and an `AbortSignal`.
1006
1009
  * @returns The created payment intent.
1007
1010
  *
1008
1011
  * @example
1009
1012
  * ```typescript
1010
- * const payment = await delopay.payments.create({
1011
- * amount: 5000,
1012
- * currency: 'EUR',
1013
- * customer_id: 'cus_123',
1014
- * });
1013
+ * const payment = await delopay.payments.create(
1014
+ * { amount: 5000, currency: 'EUR', customer_id: 'cus_123' },
1015
+ * { headers: { 'Idempotency-Key': 'order_1001' } },
1016
+ * );
1015
1017
  * ```
1016
1018
  */
1017
- async create(params) {
1018
- return this.request("POST", "/payments", { body: params });
1019
+ async create(params, options) {
1020
+ return this.request("POST", "/payments", { body: params, ...options });
1019
1021
  }
1020
1022
  /**
1021
1023
  * Retrieve a payment by its ID.
@@ -1099,6 +1101,8 @@ var Payments = class {
1099
1101
  * List payment intents, optionally filtered by customer or date range.
1100
1102
  *
1101
1103
  * @param params - Optional filter and pagination parameters.
1104
+ * @param options - Optional per-call extras: extra `headers`, a `timeout`
1105
+ * override, and an `AbortSignal` for cancellation.
1102
1106
  * @returns Paginated list of payment intents.
1103
1107
  *
1104
1108
  * @example
@@ -1106,9 +1110,10 @@ var Payments = class {
1106
1110
  * const { data } = await delopay.payments.list({ customer_id: 'cus_123', limit: 25 });
1107
1111
  * ```
1108
1112
  */
1109
- async list(params) {
1113
+ async list(params, options) {
1110
1114
  return this.request("GET", "/payments/list", {
1111
- query: params
1115
+ query: params,
1116
+ ...options
1112
1117
  });
1113
1118
  }
1114
1119
  // --- Advanced operations (Task 3.2) ---
@@ -1829,7 +1834,7 @@ var Shops = class {
1829
1834
  *
1830
1835
  * @example
1831
1836
  * ```typescript
1832
- * const shop = await delopay.shops.create('merch_123', { profile_name: 'EU Store' });
1837
+ * const shop = await delopay.shops.create('merch_123', { shop_name: 'EU Store' });
1833
1838
  * ```
1834
1839
  */
1835
1840
  async create(merchantId, params) {
@@ -2589,11 +2594,16 @@ var Subscriptions = class {
2589
2594
  constructor(request) {
2590
2595
  this.request = request;
2591
2596
  }
2592
- /** Create and immediately confirm a subscription. `POST /subscriptions` */
2597
+ /**
2598
+ * Create and immediately confirm a subscription. `POST /subscriptions`
2599
+ *
2600
+ * For billing processors that require buyer approval (e.g. PayPal), the
2601
+ * response carries a `redirect_url` the customer must be sent to.
2602
+ */
2593
2603
  async createAndConfirm(params) {
2594
2604
  return this.request("POST", "/subscriptions", { body: params });
2595
2605
  }
2596
- /** Create a subscription (without confirming). `POST /subscriptions/create` */
2606
+ /** Create a subscription without confirming it. `POST /subscriptions/create` */
2597
2607
  async create(params) {
2598
2608
  return this.request("POST", "/subscriptions/create", { body: params });
2599
2609
  }
@@ -2601,43 +2611,58 @@ var Subscriptions = class {
2601
2611
  async retrieve(subscriptionId) {
2602
2612
  return this.request("GET", `/subscriptions/${encodeURIComponent(subscriptionId)}`);
2603
2613
  }
2604
- /** Confirm a subscription. `POST /subscriptions/{subscriptionId}/confirm` */
2614
+ /**
2615
+ * Confirm a previously created subscription. `POST /subscriptions/{subscriptionId}/confirm`
2616
+ *
2617
+ * Like {@link createAndConfirm}, the response may carry a `redirect_url` for
2618
+ * processors that require buyer approval.
2619
+ */
2605
2620
  async confirm(subscriptionId, params) {
2606
2621
  return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/confirm`, {
2607
2622
  body: params
2608
2623
  });
2609
2624
  }
2610
- /** Update a subscription. `PUT /subscriptions/{subscriptionId}/update` */
2625
+ /** Update a subscription's plan/price. `PUT /subscriptions/{subscriptionId}/update` */
2611
2626
  async update(subscriptionId, params) {
2612
2627
  return this.request("PUT", `/subscriptions/${encodeURIComponent(subscriptionId)}/update`, {
2613
2628
  body: params
2614
2629
  });
2615
2630
  }
2616
- /** List subscriptions. `GET /subscriptions/list` */
2631
+ /** List subscriptions for the profile. `GET /subscriptions/list` */
2617
2632
  async list(params) {
2618
2633
  return this.request("GET", "/subscriptions/list", {
2619
2634
  query: params
2620
2635
  });
2621
2636
  }
2622
- /** Get subscription estimate. `GET /subscriptions/estimate` */
2637
+ /** Estimate the cost of a subscription before creating it. `GET /subscriptions/estimate` */
2623
2638
  async getEstimate(params) {
2624
- return this.request("GET", "/subscriptions/estimate", { query: params });
2639
+ return this.request("GET", "/subscriptions/estimate", {
2640
+ query: params
2641
+ });
2625
2642
  }
2626
- /** Get subscription items. `GET /subscriptions/items` */
2643
+ /** List purchasable subscription items (plans/addons). `GET /subscriptions/items` */
2627
2644
  async getItems(params) {
2628
- return this.request("GET", "/subscriptions/items", { query: params });
2645
+ return this.request("GET", "/subscriptions/items", {
2646
+ query: params
2647
+ });
2629
2648
  }
2630
2649
  /** Pause a subscription. `POST /subscriptions/{subscriptionId}/pause` */
2631
- async pause(subscriptionId) {
2632
- return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/pause`);
2650
+ async pause(subscriptionId, params) {
2651
+ return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/pause`, {
2652
+ body: params
2653
+ });
2633
2654
  }
2634
- /** Resume a subscription. `POST /subscriptions/{subscriptionId}/resume` */
2635
- async resume(subscriptionId) {
2636
- return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/resume`);
2655
+ /** Resume a paused subscription. `POST /subscriptions/{subscriptionId}/resume` */
2656
+ async resume(subscriptionId, params) {
2657
+ return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/resume`, {
2658
+ body: params
2659
+ });
2637
2660
  }
2638
2661
  /** Cancel a subscription. `POST /subscriptions/{subscriptionId}/cancel` */
2639
- async cancel(subscriptionId) {
2640
- return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`);
2662
+ async cancel(subscriptionId, params) {
2663
+ return this.request("POST", `/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`, {
2664
+ body: params
2665
+ });
2641
2666
  }
2642
2667
  };
2643
2668
 
@@ -2722,7 +2747,7 @@ var Delopay = class {
2722
2747
  /**
2723
2748
  * Create a new Delopay client.
2724
2749
  *
2725
- * @param apiKey - Your Delopay API key (e.g. `sk_live_...` or `sk_test_...`).
2750
+ * @param apiKey - Your Delopay API key (e.g. `prd_...` or `snd_...`).
2726
2751
  * Pass an empty string or omit for JWT-only usage (e.g. dashboard apps).
2727
2752
  * @param options - Optional configuration (sandbox mode, base URL override, timeout).
2728
2753
  */
@@ -2979,34 +3004,64 @@ var Delopay = class {
2979
3004
  * Auto-paginate a list endpoint. Yields items one by one, fetching
2980
3005
  * the next page automatically when the current one is exhausted.
2981
3006
  *
2982
- * @param listFn - A function that takes `{ limit, offset }` and returns `{ data: T[] }` or `T[]`.
3007
+ * Delopay list endpoints use one of two pagination styles, so this helper
3008
+ * supports both:
3009
+ * - **Offset** (default) — for endpoints like `customers.list` that accept
3010
+ * `offset`/`limit`. Each page advances `offset` by the number of items returned.
3011
+ * - **Cursor** — for endpoints like `payments.list` and `payouts.list` that page
3012
+ * with `starting_after`/`limit` (they ignore `offset`). Pass a `cursor` extractor
3013
+ * that returns the id of an item; the next page is requested with
3014
+ * `starting_after` set to the last item's id.
3015
+ *
3016
+ * @param listFn - A function that takes the paging params and returns `{ data: T[] }` or `T[]`.
2983
3017
  * @param params - Additional parameters to pass to every page request.
2984
- * @param pageSize - Number of items per page. Defaults to `50`.
3018
+ * @param options - Page size (number) for offset mode, or `{ pageSize?, cursor? }`.
3019
+ * Provide `cursor` to switch to cursor pagination.
2985
3020
  *
2986
3021
  * @example
2987
3022
  * ```typescript
3023
+ * // Offset endpoint (customers):
3024
+ * for await (const c of delopay.paginate((p) => delopay.customers.list(p))) {
3025
+ * console.log(c.customer_id);
3026
+ * }
3027
+ *
3028
+ * // Cursor endpoint (payments): extract the id used as the next cursor.
2988
3029
  * for await (const payment of delopay.paginate(
2989
3030
  * (p) => delopay.payments.list(p),
3031
+ * undefined,
3032
+ * { cursor: (p) => p.payment_id },
2990
3033
  * )) {
2991
3034
  * console.log(payment.payment_id);
2992
3035
  * }
2993
3036
  * ```
2994
3037
  */
2995
- async *paginate(listFn, params, pageSize = 50) {
3038
+ async *paginate(listFn, params, options) {
3039
+ const pageSize = typeof options === "number" ? options : options?.pageSize ?? 50;
3040
+ const cursorOf = typeof options === "object" ? options.cursor : void 0;
2996
3041
  let offset = 0;
3042
+ let after;
2997
3043
  while (true) {
2998
- const result = await listFn({
2999
- ...params ?? {},
3000
- limit: pageSize,
3001
- offset
3002
- });
3044
+ const page = { ...params ?? {}, limit: pageSize };
3045
+ if (cursorOf) {
3046
+ if (after !== void 0) page.starting_after = after;
3047
+ } else {
3048
+ page.offset = offset;
3049
+ }
3050
+ const result = await listFn(page);
3003
3051
  const items = Array.isArray(result) ? result : result.data;
3004
3052
  if (items.length === 0) break;
3005
3053
  for (const item of items) {
3006
3054
  yield item;
3007
3055
  }
3008
3056
  if (items.length < pageSize) break;
3009
- offset += items.length;
3057
+ if (cursorOf) {
3058
+ const last = items[items.length - 1];
3059
+ if (last === void 0) break;
3060
+ after = cursorOf(last);
3061
+ if (after === void 0) break;
3062
+ } else {
3063
+ offset += items.length;
3064
+ }
3010
3065
  }
3011
3066
  }
3012
3067
  };