@delopay/sdk 0.29.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
@@ -185,16 +185,21 @@ var Authentication = class {
185
185
  body: params
186
186
  });
187
187
  }
188
- async sync(authId, params) {
189
- return this.request("POST", `/authentication/${encodeURIComponent(authId)}/sync`, {
190
- body: params
191
- });
188
+ /** Sync authentication status. `POST /authentication/{merchantId}/{authId}/sync` */
189
+ async sync(merchantId, authId, params) {
190
+ return this.request(
191
+ "POST",
192
+ `/authentication/${encodeURIComponent(merchantId)}/${encodeURIComponent(authId)}/sync`,
193
+ { body: params }
194
+ );
192
195
  }
193
- /** Redirect after authentication. `POST /authentication/{authId}/redirect` */
194
- async redirect(authId, params) {
195
- return this.request("POST", `/authentication/${encodeURIComponent(authId)}/redirect`, {
196
- body: params
197
- });
196
+ /** Redirect after authentication. `POST /authentication/{merchantId}/{authId}/redirect` */
197
+ async redirect(merchantId, authId, params) {
198
+ return this.request(
199
+ "POST",
200
+ `/authentication/${encodeURIComponent(merchantId)}/${encodeURIComponent(authId)}/redirect`,
201
+ { body: params }
202
+ );
198
203
  }
199
204
  /** Enable authn methods token. `POST /authentication/{authId}/enabled-authn-methods-token` */
200
205
  async enabledAuthnMethodsToken(authId, params) {
@@ -831,11 +836,11 @@ var PaymentLinks = class {
831
836
  `/payment-link/${encodeURIComponent(merchantId)}/${encodeURIComponent(paymentId)}`
832
837
  );
833
838
  }
834
- /** Get payment link status. `GET /payment-linkstatus/{merchantId}/{paymentId}` */
839
+ /** Get payment link status. `GET /payment-link/status/{merchantId}/{paymentId}` */
835
840
  async status(merchantId, paymentId) {
836
841
  return this.request(
837
842
  "GET",
838
- `/payment-linkstatus/${encodeURIComponent(merchantId)}/${encodeURIComponent(paymentId)}`
843
+ `/payment-link/status/${encodeURIComponent(merchantId)}/${encodeURIComponent(paymentId)}`
839
844
  );
840
845
  }
841
846
  };
@@ -998,19 +1003,21 @@ var Payments = class {
998
1003
  * Create a new payment intent.
999
1004
  *
1000
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`.
1001
1009
  * @returns The created payment intent.
1002
1010
  *
1003
1011
  * @example
1004
1012
  * ```typescript
1005
- * const payment = await delopay.payments.create({
1006
- * amount: 5000,
1007
- * currency: 'EUR',
1008
- * customer_id: 'cus_123',
1009
- * });
1013
+ * const payment = await delopay.payments.create(
1014
+ * { amount: 5000, currency: 'EUR', customer_id: 'cus_123' },
1015
+ * { headers: { 'Idempotency-Key': 'order_1001' } },
1016
+ * );
1010
1017
  * ```
1011
1018
  */
1012
- async create(params) {
1013
- return this.request("POST", "/payments", { body: params });
1019
+ async create(params, options) {
1020
+ return this.request("POST", "/payments", { body: params, ...options });
1014
1021
  }
1015
1022
  /**
1016
1023
  * Retrieve a payment by its ID.
@@ -1094,6 +1101,8 @@ var Payments = class {
1094
1101
  * List payment intents, optionally filtered by customer or date range.
1095
1102
  *
1096
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.
1097
1106
  * @returns Paginated list of payment intents.
1098
1107
  *
1099
1108
  * @example
@@ -1101,9 +1110,10 @@ var Payments = class {
1101
1110
  * const { data } = await delopay.payments.list({ customer_id: 'cus_123', limit: 25 });
1102
1111
  * ```
1103
1112
  */
1104
- async list(params) {
1113
+ async list(params, options) {
1105
1114
  return this.request("GET", "/payments/list", {
1106
- query: params
1115
+ query: params,
1116
+ ...options
1107
1117
  });
1108
1118
  }
1109
1119
  // --- Advanced operations (Task 3.2) ---
@@ -1308,13 +1318,13 @@ var Payouts = class {
1308
1318
  async listByFilter(params) {
1309
1319
  return this.request("POST", "/payouts/list", { body: params });
1310
1320
  }
1311
- /** Get payout filter options. `POST /payouts/filter` */
1321
+ /** Get payout filter options. `GET /payouts/filter` */
1312
1322
  async getFilters(params) {
1313
- return this.request("POST", "/payouts/filter", { body: params });
1323
+ return this.request("GET", "/payouts/filter", { query: params });
1314
1324
  }
1315
- /** Get payout filters (profile-scoped). `POST /payouts/profile/filter` */
1325
+ /** Get payout filters (profile-scoped). `GET /payouts/profile/filter` */
1316
1326
  async getFiltersByProfile(params) {
1317
- return this.request("POST", "/payouts/profile/filter", { body: params });
1327
+ return this.request("GET", "/payouts/profile/filter", { query: params });
1318
1328
  }
1319
1329
  /** Get payout aggregates. `GET /payouts/aggregate` */
1320
1330
  async aggregate(params) {
@@ -1824,7 +1834,7 @@ var Shops = class {
1824
1834
  *
1825
1835
  * @example
1826
1836
  * ```typescript
1827
- * 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' });
1828
1838
  * ```
1829
1839
  */
1830
1840
  async create(merchantId, params) {
@@ -2088,7 +2098,7 @@ var Users = class {
2088
2098
  return this.request("POST", "/user/employees/invite", { body: params });
2089
2099
  }
2090
2100
  async acceptInvitation(params) {
2091
- return this.request("POST", "/user/invite/accept", { body: params });
2101
+ return this.request("POST", "/user/employees/invite/accept", { body: params });
2092
2102
  }
2093
2103
  /**
2094
2104
  * Accept an invitation via the email-link flow.
@@ -2217,9 +2227,9 @@ var Users = class {
2217
2227
  query: params
2218
2228
  });
2219
2229
  }
2220
- /** Resend invite. `POST /user/employees/resend-invite` */
2230
+ /** Resend invite. `POST /user/resend-invite` */
2221
2231
  async resendInvite(params) {
2222
- return this.request("POST", "/user/employees/resend-invite", { body: params });
2232
+ return this.request("POST", "/user/resend-invite", { body: params });
2223
2233
  }
2224
2234
  /**
2225
2235
  * Get the caller's parent permission groups + scopes.
@@ -2248,14 +2258,6 @@ var Users = class {
2248
2258
  async listUpdatableRoles() {
2249
2259
  return this.request("GET", "/user/role/list/update");
2250
2260
  }
2251
- /** Get permission info. `GET /user/permission-info` */
2252
- async getPermissionInfo() {
2253
- return this.request("GET", "/user/permission-info");
2254
- }
2255
- /** Get module list. `GET /user/module/list` */
2256
- async getModuleList() {
2257
- return this.request("GET", "/user/module/list");
2258
- }
2259
2261
  /** Get parent list. `GET /user/parent/list` */
2260
2262
  async getParentList() {
2261
2263
  return this.request("GET", "/user/parent/list");
@@ -2725,7 +2727,7 @@ var Delopay = class {
2725
2727
  /**
2726
2728
  * Create a new Delopay client.
2727
2729
  *
2728
- * @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_...`).
2729
2731
  * Pass an empty string or omit for JWT-only usage (e.g. dashboard apps).
2730
2732
  * @param options - Optional configuration (sandbox mode, base URL override, timeout).
2731
2733
  */
@@ -2982,34 +2984,64 @@ var Delopay = class {
2982
2984
  * Auto-paginate a list endpoint. Yields items one by one, fetching
2983
2985
  * the next page automatically when the current one is exhausted.
2984
2986
  *
2985
- * @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[]`.
2986
2997
  * @param params - Additional parameters to pass to every page request.
2987
- * @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.
2988
3000
  *
2989
3001
  * @example
2990
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.
2991
3009
  * for await (const payment of delopay.paginate(
2992
3010
  * (p) => delopay.payments.list(p),
3011
+ * undefined,
3012
+ * { cursor: (p) => p.payment_id },
2993
3013
  * )) {
2994
3014
  * console.log(payment.payment_id);
2995
3015
  * }
2996
3016
  * ```
2997
3017
  */
2998
- 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;
2999
3021
  let offset = 0;
3022
+ let after;
3000
3023
  while (true) {
3001
- const result = await listFn({
3002
- ...params ?? {},
3003
- limit: pageSize,
3004
- offset
3005
- });
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);
3006
3031
  const items = Array.isArray(result) ? result : result.data;
3007
3032
  if (items.length === 0) break;
3008
3033
  for (const item of items) {
3009
3034
  yield item;
3010
3035
  }
3011
3036
  if (items.length < pageSize) break;
3012
- 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
+ }
3013
3045
  }
3014
3046
  }
3015
3047
  };