@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/README.md CHANGED
@@ -118,14 +118,16 @@ const customer = await delopay.customers.create({
118
118
  });
119
119
 
120
120
  // List saved payment methods
121
- const methods = await delopay.paymentMethods.list(customer.customer_id);
121
+ const { customer_payment_methods } = await delopay.paymentMethods.listForCustomer(
122
+ customer.customer_id,
123
+ );
122
124
 
123
125
  // Use a saved method on a new payment
124
126
  const payment = await delopay.payments.create({
125
127
  amount: 1000,
126
128
  currency: 'EUR',
127
129
  customer_id: customer.customer_id,
128
- payment_token: methods[0]?.payment_token,
130
+ payment_token: customer_payment_methods[0]?.payment_token,
129
131
  confirm: true,
130
132
  });
131
133
  ```
@@ -133,11 +135,15 @@ const payment = await delopay.payments.create({
133
135
  ### Handle disputes
134
136
 
135
137
  ```typescript
136
- const disputes = await delopay.disputes.list({ payment_id: 'pay_abc123' });
138
+ // Disputes for one payment come from the payment object:
139
+ const payment = await delopay.payments.retrieve('pay_abc123');
137
140
 
138
- for (const dispute of disputes) {
141
+ for (const dispute of payment.disputes ?? []) {
139
142
  console.log(dispute.dispute_id, dispute.dispute_stage, dispute.dispute_status);
140
143
  }
144
+
145
+ // Or list disputes across the account, filtered by status:
146
+ const open = await delopay.disputes.list({ dispute_status: 'dispute_opened' });
141
147
  ```
142
148
 
143
149
  ### Manage shops and gateways
@@ -936,19 +936,21 @@ var Payments = class {
936
936
  * Create a new payment intent.
937
937
  *
938
938
  * @param params - Payment creation parameters including amount and currency.
939
+ * @param options - Optional per-call extras: extra `headers` (e.g. an
940
+ * `Idempotency-Key` to make the create safe to retry), a `timeout` override,
941
+ * and an `AbortSignal`.
939
942
  * @returns The created payment intent.
940
943
  *
941
944
  * @example
942
945
  * ```typescript
943
- * const payment = await delopay.payments.create({
944
- * amount: 5000,
945
- * currency: 'EUR',
946
- * customer_id: 'cus_123',
947
- * });
946
+ * const payment = await delopay.payments.create(
947
+ * { amount: 5000, currency: 'EUR', customer_id: 'cus_123' },
948
+ * { headers: { 'Idempotency-Key': 'order_1001' } },
949
+ * );
948
950
  * ```
949
951
  */
950
- async create(params) {
951
- return this.request("POST", "/payments", { body: params });
952
+ async create(params, options) {
953
+ return this.request("POST", "/payments", { body: params, ...options });
952
954
  }
953
955
  /**
954
956
  * Retrieve a payment by its ID.
@@ -1032,6 +1034,8 @@ var Payments = class {
1032
1034
  * List payment intents, optionally filtered by customer or date range.
1033
1035
  *
1034
1036
  * @param params - Optional filter and pagination parameters.
1037
+ * @param options - Optional per-call extras: extra `headers`, a `timeout`
1038
+ * override, and an `AbortSignal` for cancellation.
1035
1039
  * @returns Paginated list of payment intents.
1036
1040
  *
1037
1041
  * @example
@@ -1039,9 +1043,10 @@ var Payments = class {
1039
1043
  * const { data } = await delopay.payments.list({ customer_id: 'cus_123', limit: 25 });
1040
1044
  * ```
1041
1045
  */
1042
- async list(params) {
1046
+ async list(params, options) {
1043
1047
  return this.request("GET", "/payments/list", {
1044
- query: params
1048
+ query: params,
1049
+ ...options
1045
1050
  });
1046
1051
  }
1047
1052
  // --- Advanced operations (Task 3.2) ---
@@ -1762,7 +1767,7 @@ var Shops = class {
1762
1767
  *
1763
1768
  * @example
1764
1769
  * ```typescript
1765
- * const shop = await delopay.shops.create('merch_123', { profile_name: 'EU Store' });
1770
+ * const shop = await delopay.shops.create('merch_123', { shop_name: 'EU Store' });
1766
1771
  * ```
1767
1772
  */
1768
1773
  async create(merchantId, params) {
@@ -2655,7 +2660,7 @@ var Delopay = class {
2655
2660
  /**
2656
2661
  * Create a new Delopay client.
2657
2662
  *
2658
- * @param apiKey - Your Delopay API key (e.g. `sk_live_...` or `sk_test_...`).
2663
+ * @param apiKey - Your Delopay API key (e.g. `prd_...` or `snd_...`).
2659
2664
  * Pass an empty string or omit for JWT-only usage (e.g. dashboard apps).
2660
2665
  * @param options - Optional configuration (sandbox mode, base URL override, timeout).
2661
2666
  */
@@ -2912,34 +2917,64 @@ var Delopay = class {
2912
2917
  * Auto-paginate a list endpoint. Yields items one by one, fetching
2913
2918
  * the next page automatically when the current one is exhausted.
2914
2919
  *
2915
- * @param listFn - A function that takes `{ limit, offset }` and returns `{ data: T[] }` or `T[]`.
2920
+ * Delopay list endpoints use one of two pagination styles, so this helper
2921
+ * supports both:
2922
+ * - **Offset** (default) — for endpoints like `customers.list` that accept
2923
+ * `offset`/`limit`. Each page advances `offset` by the number of items returned.
2924
+ * - **Cursor** — for endpoints like `payments.list` and `payouts.list` that page
2925
+ * with `starting_after`/`limit` (they ignore `offset`). Pass a `cursor` extractor
2926
+ * that returns the id of an item; the next page is requested with
2927
+ * `starting_after` set to the last item's id.
2928
+ *
2929
+ * @param listFn - A function that takes the paging params and returns `{ data: T[] }` or `T[]`.
2916
2930
  * @param params - Additional parameters to pass to every page request.
2917
- * @param pageSize - Number of items per page. Defaults to `50`.
2931
+ * @param options - Page size (number) for offset mode, or `{ pageSize?, cursor? }`.
2932
+ * Provide `cursor` to switch to cursor pagination.
2918
2933
  *
2919
2934
  * @example
2920
2935
  * ```typescript
2936
+ * // Offset endpoint (customers):
2937
+ * for await (const c of delopay.paginate((p) => delopay.customers.list(p))) {
2938
+ * console.log(c.customer_id);
2939
+ * }
2940
+ *
2941
+ * // Cursor endpoint (payments): extract the id used as the next cursor.
2921
2942
  * for await (const payment of delopay.paginate(
2922
2943
  * (p) => delopay.payments.list(p),
2944
+ * undefined,
2945
+ * { cursor: (p) => p.payment_id },
2923
2946
  * )) {
2924
2947
  * console.log(payment.payment_id);
2925
2948
  * }
2926
2949
  * ```
2927
2950
  */
2928
- async *paginate(listFn, params, pageSize = 50) {
2951
+ async *paginate(listFn, params, options) {
2952
+ const pageSize = typeof options === "number" ? options : options?.pageSize ?? 50;
2953
+ const cursorOf = typeof options === "object" ? options.cursor : void 0;
2929
2954
  let offset = 0;
2955
+ let after;
2930
2956
  while (true) {
2931
- const result = await listFn({
2932
- ...params ?? {},
2933
- limit: pageSize,
2934
- offset
2935
- });
2957
+ const page = { ...params ?? {}, limit: pageSize };
2958
+ if (cursorOf) {
2959
+ if (after !== void 0) page.starting_after = after;
2960
+ } else {
2961
+ page.offset = offset;
2962
+ }
2963
+ const result = await listFn(page);
2936
2964
  const items = Array.isArray(result) ? result : result.data;
2937
2965
  if (items.length === 0) break;
2938
2966
  for (const item of items) {
2939
2967
  yield item;
2940
2968
  }
2941
2969
  if (items.length < pageSize) break;
2942
- offset += items.length;
2970
+ if (cursorOf) {
2971
+ const last = items[items.length - 1];
2972
+ if (last === void 0) break;
2973
+ after = cursorOf(last);
2974
+ if (after === void 0) break;
2975
+ } else {
2976
+ offset += items.length;
2977
+ }
2943
2978
  }
2944
2979
  }
2945
2980
  };
@@ -3621,4 +3656,4 @@ export {
3621
3656
  applyBrandingVariables,
3622
3657
  shadowFor
3623
3658
  };
3624
- //# sourceMappingURL=chunk-INP6UXMJ.js.map
3659
+ //# sourceMappingURL=chunk-5C42YTV2.js.map