@delopay/sdk 0.30.0 → 0.31.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) {
@@ -2722,7 +2727,7 @@ var Delopay = class {
2722
2727
  /**
2723
2728
  * Create a new Delopay client.
2724
2729
  *
2725
- * @param apiKey - Your Delopay API key (e.g. `sk_live_...` or `sk_test_...`).
2730
+ * @param apiKey - Your Delopay API key (e.g. `prd_...` or `snd_...`).
2726
2731
  * Pass an empty string or omit for JWT-only usage (e.g. dashboard apps).
2727
2732
  * @param options - Optional configuration (sandbox mode, base URL override, timeout).
2728
2733
  */
@@ -2979,34 +2984,64 @@ var Delopay = class {
2979
2984
  * Auto-paginate a list endpoint. Yields items one by one, fetching
2980
2985
  * the next page automatically when the current one is exhausted.
2981
2986
  *
2982
- * @param listFn - A function that takes `{ limit, offset }` and returns `{ data: T[] }` or `T[]`.
2987
+ * Delopay list endpoints use one of two pagination styles, so this helper
2988
+ * supports both:
2989
+ * - **Offset** (default) — for endpoints like `customers.list` that accept
2990
+ * `offset`/`limit`. Each page advances `offset` by the number of items returned.
2991
+ * - **Cursor** — for endpoints like `payments.list` and `payouts.list` that page
2992
+ * with `starting_after`/`limit` (they ignore `offset`). Pass a `cursor` extractor
2993
+ * that returns the id of an item; the next page is requested with
2994
+ * `starting_after` set to the last item's id.
2995
+ *
2996
+ * @param listFn - A function that takes the paging params and returns `{ data: T[] }` or `T[]`.
2983
2997
  * @param params - Additional parameters to pass to every page request.
2984
- * @param pageSize - Number of items per page. Defaults to `50`.
2998
+ * @param options - Page size (number) for offset mode, or `{ pageSize?, cursor? }`.
2999
+ * Provide `cursor` to switch to cursor pagination.
2985
3000
  *
2986
3001
  * @example
2987
3002
  * ```typescript
3003
+ * // Offset endpoint (customers):
3004
+ * for await (const c of delopay.paginate((p) => delopay.customers.list(p))) {
3005
+ * console.log(c.customer_id);
3006
+ * }
3007
+ *
3008
+ * // Cursor endpoint (payments): extract the id used as the next cursor.
2988
3009
  * for await (const payment of delopay.paginate(
2989
3010
  * (p) => delopay.payments.list(p),
3011
+ * undefined,
3012
+ * { cursor: (p) => p.payment_id },
2990
3013
  * )) {
2991
3014
  * console.log(payment.payment_id);
2992
3015
  * }
2993
3016
  * ```
2994
3017
  */
2995
- async *paginate(listFn, params, pageSize = 50) {
3018
+ async *paginate(listFn, params, options) {
3019
+ const pageSize = typeof options === "number" ? options : options?.pageSize ?? 50;
3020
+ const cursorOf = typeof options === "object" ? options.cursor : void 0;
2996
3021
  let offset = 0;
3022
+ let after;
2997
3023
  while (true) {
2998
- const result = await listFn({
2999
- ...params ?? {},
3000
- limit: pageSize,
3001
- offset
3002
- });
3024
+ const page = { ...params ?? {}, limit: pageSize };
3025
+ if (cursorOf) {
3026
+ if (after !== void 0) page.starting_after = after;
3027
+ } else {
3028
+ page.offset = offset;
3029
+ }
3030
+ const result = await listFn(page);
3003
3031
  const items = Array.isArray(result) ? result : result.data;
3004
3032
  if (items.length === 0) break;
3005
3033
  for (const item of items) {
3006
3034
  yield item;
3007
3035
  }
3008
3036
  if (items.length < pageSize) break;
3009
- offset += items.length;
3037
+ if (cursorOf) {
3038
+ const last = items[items.length - 1];
3039
+ if (last === void 0) break;
3040
+ after = cursorOf(last);
3041
+ if (after === void 0) break;
3042
+ } else {
3043
+ offset += items.length;
3044
+ }
3010
3045
  }
3011
3046
  }
3012
3047
  };