@delopay/sdk 0.146.0 → 0.149.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.
@@ -1153,7 +1153,7 @@ var Events = class {
1153
1153
  }
1154
1154
  /**
1155
1155
  * Fire an outgoing webhook event by hand for one object.
1156
- * `POST /events/{merchant_id}/trigger` (be#318)
1156
+ * `POST /events/{merchant_id}/trigger`
1157
1157
  *
1158
1158
  * Not a replay — see {@link EventManualTriggerRequest}. Needs the
1159
1159
  * `WebhookEventTrigger` permission, which is separate from the one that
@@ -1176,7 +1176,7 @@ var Events = class {
1176
1176
  }
1177
1177
  /**
1178
1178
  * Fire an outgoing webhook event by hand (profile-scoped).
1179
- * `POST /events/profile/trigger` (be#318)
1179
+ * `POST /events/profile/trigger`
1180
1180
  *
1181
1181
  * The shop-user twin of {@link trigger}; the shop is taken from the auth
1182
1182
  * context, so `profile_id` on the body is ignored.
@@ -1868,6 +1868,61 @@ var Payments = class {
1868
1868
  options
1869
1869
  );
1870
1870
  }
1871
+ /**
1872
+ * Open a playback of the payment's stored checkout recording: the audited
1873
+ * act of watching. Answers the manifest — which slices exist, how long the
1874
+ * recording runs, whether a pause in it is expected — and the
1875
+ * `playback_id` every {@link Payments.replaySlice} call carries.
1876
+ *
1877
+ * A payment that was never recorded answers `200` with `slices: []` and
1878
+ * `session_id: null` — the ordinary case for every payment made before the
1879
+ * checkout started recording — not a `404`. `404` means the payment does not
1880
+ * exist. Fetch the slices in `sequence` order; a number missing from the
1881
+ * list is a gap, not the end.
1882
+ *
1883
+ * A `POST`, because it writes one audit row: the SDK retries `GET` on its
1884
+ * own, and a lost response must not open three playbacks. Calling this
1885
+ * again deliberately opens another playback.
1886
+ *
1887
+ * Requires the `PaymentReplay` permission on a dashboard session in addition
1888
+ * to payment read access.
1889
+ *
1890
+ * `POST /payments/{paymentId}/replay/playback`
1891
+ *
1892
+ * @param paymentId - The payment intent ID.
1893
+ * @param options - Optional per-call extras: extra `headers`, a `timeout`
1894
+ * override, and an `AbortSignal`.
1895
+ */
1896
+ async openReplayPlayback(paymentId, options) {
1897
+ return this.request(
1898
+ "POST",
1899
+ `/payments/${encodeURIComponent(paymentId)}/replay/playback`,
1900
+ options
1901
+ );
1902
+ }
1903
+ /**
1904
+ * One slice of the payment's stored checkout recording, read against an
1905
+ * open playback: the rrweb events the checkout recorded under that number.
1906
+ * `playbackId` and the numbers come from {@link Payments.openReplayPlayback};
1907
+ * a `playbackId` that names no playback of this payment opened by this
1908
+ * caller, and a number the manifest does not list, both answer `404`.
1909
+ * Not audited per slice — the playback was.
1910
+ *
1911
+ * `GET /payments/{paymentId}/replay/playback/{playbackId}/slices/{sequence}`
1912
+ *
1913
+ * @param paymentId - The payment intent ID.
1914
+ * @param playbackId - The playback, from `openReplayPlayback`.
1915
+ * @param sequence - The slice number, from the playback's manifest.
1916
+ * @param options - Optional per-call extras: extra `headers`, a `timeout`
1917
+ * override, and an `AbortSignal`.
1918
+ */
1919
+ async replaySlice(paymentId, playbackId, sequence, options) {
1920
+ return this.request(
1921
+ "GET",
1922
+ `/payments/${encodeURIComponent(paymentId)}/replay/playback/${encodeURIComponent(playbackId)}/slices/${encodeURIComponent(String(sequence))}`,
1923
+ options
1924
+ );
1925
+ }
1871
1926
  /**
1872
1927
  * Soft-delete a payment. Only payments whose status is in the merchant's
1873
1928
  * delete policy (see {@link Payments.getDeletePolicy}) can be deleted;
@@ -4425,6 +4480,15 @@ var Audit = class {
4425
4480
  };
4426
4481
 
4427
4482
  // src/resources/settlement.ts
4483
+ function exportHeaders(options, accept) {
4484
+ const headers = new Headers(options?.headers);
4485
+ headers.set("Accept", accept);
4486
+ const output = {};
4487
+ headers.forEach((value, key) => {
4488
+ output[key] = value;
4489
+ });
4490
+ return output;
4491
+ }
4428
4492
  var Settlement = class {
4429
4493
  constructor(request) {
4430
4494
  this.request = request;
@@ -4577,6 +4641,45 @@ var Settlement = class {
4577
4641
  { body: params, ...options }
4578
4642
  );
4579
4643
  }
4644
+ /** Append one external transfer record. Send a stable idempotency_key for safe retries. */
4645
+ async recordStatementPayout(statementId, params, options) {
4646
+ return this.request(
4647
+ "POST",
4648
+ `/settlement/statements/${encodeURIComponent(statementId)}/payout`,
4649
+ {
4650
+ body: params,
4651
+ ...options,
4652
+ bodyIdempotencyKey: params.idempotency_key ?? null
4653
+ }
4654
+ );
4655
+ }
4656
+ /** Read individual transfer records, their signed total, and any overpayment. */
4657
+ async listStatementPayouts(statementId, options) {
4658
+ return this.request(
4659
+ "GET",
4660
+ `/settlement/statements/${encodeURIComponent(statementId)}/payouts`,
4661
+ options
4662
+ );
4663
+ }
4664
+ /** Record a transfer against a shop's month before its statement exists. */
4665
+ async recordAdvance(params, options) {
4666
+ return this.request("POST", "/settlement/advances", {
4667
+ body: params,
4668
+ ...options,
4669
+ bodyIdempotencyKey: params.idempotency_key ?? null
4670
+ });
4671
+ }
4672
+ async listAdvances(params, options) {
4673
+ return this.request("GET", "/settlement/advances", {
4674
+ query: {
4675
+ profile_id: params.profile_id,
4676
+ year: params.year,
4677
+ month: params.month,
4678
+ test_mode: params.test_mode
4679
+ },
4680
+ ...options
4681
+ });
4682
+ }
4580
4683
  /**
4581
4684
  * Export a statement as PDF. Returns the raw PDF bytes as a `Blob`, with
4582
4685
  * the same auth, retries and error handling as every other call — persist
@@ -4694,6 +4797,109 @@ var Settlement = class {
4694
4797
  options
4695
4798
  );
4696
4799
  }
4800
+ /**
4801
+ * Calculate a period in its transaction currency. Requires a host-level
4802
+ * dashboard JWT and settlement read permission. Profile users and roles
4803
+ * restricted to selected connector accounts cannot read this aggregate.
4804
+ * Rates apply once to the period total. Unknown or estimated fees keep
4805
+ * dependent amounts provisional. Native money values remain integer strings.
4806
+ */
4807
+ async previewNative(params, options) {
4808
+ return this.request("POST", "/settlement/native/preview", { body: params, ...options });
4809
+ }
4810
+ /**
4811
+ * Recalculate and freeze an immutable report version. Requires settlement
4812
+ * edit permission. Explicitly allow provisional figures when source fees
4813
+ * are incomplete. A report records a calculation and sends no money.
4814
+ * Reuse the same idempotency key when retrying the same request.
4815
+ */
4816
+ async createNativeReport(params, options) {
4817
+ return this.request("POST", "/settlement/native/reports", {
4818
+ body: params,
4819
+ ...options,
4820
+ bodyIdempotencyKey: params.idempotency_key
4821
+ });
4822
+ }
4823
+ async retrieveNativeReport(reportId, options) {
4824
+ return this.request(
4825
+ "GET",
4826
+ `/settlement/native/reports/${encodeURIComponent(reportId)}`,
4827
+ options
4828
+ );
4829
+ }
4830
+ /** List report summaries without fetching every source row in each saved snapshot. */
4831
+ async listNativeReports(params, options) {
4832
+ return this.request("GET", "/settlement/native/reports", {
4833
+ query: {
4834
+ profile_id: params.profile_id,
4835
+ currency: params.currency,
4836
+ test_mode: params.test_mode,
4837
+ limit: params.limit,
4838
+ offset: params.offset
4839
+ },
4840
+ ...options
4841
+ });
4842
+ }
4843
+ /**
4844
+ * Record a transfer already made, under settlement write permission and
4845
+ * the caller's payout limits. This method never sends money. Native minor
4846
+ * units remain strings; negative records must name a same-scope reversal.
4847
+ * These records belong to the native ledger, separate from monthly USD
4848
+ * statement payouts and advances.
4849
+ */
4850
+ async recordNativePayout(params, options) {
4851
+ return this.request("POST", "/settlement/native/payouts", {
4852
+ body: params,
4853
+ ...options,
4854
+ bodyIdempotencyKey: params.idempotency_key
4855
+ });
4856
+ }
4857
+ async listNativePayouts(params, options) {
4858
+ return this.request("GET", "/settlement/native/payouts", {
4859
+ query: {
4860
+ profile_id: params.profile_id,
4861
+ currency: params.currency,
4862
+ test_mode: params.test_mode,
4863
+ limit: params.limit,
4864
+ offset: params.offset
4865
+ },
4866
+ ...options
4867
+ });
4868
+ }
4869
+ /** Refresh a bounded page of provider fee evidence. Follow next_offset while has_more is true. */
4870
+ async refreshNativeFees(params, options) {
4871
+ return this.request("POST", "/settlement/native/fees/refresh", { body: params, ...options });
4872
+ }
4873
+ async downloadNativeReportPdf(reportId, params, options) {
4874
+ return this.request("GET", `/settlement/native/reports/${encodeURIComponent(reportId)}/pdf`, {
4875
+ query: { include_transactions: params?.include_transactions },
4876
+ responseType: "blob",
4877
+ ...options
4878
+ });
4879
+ }
4880
+ /** Download the frozen source rows and calculation as CSV. */
4881
+ async downloadNativeReportCsv(reportId, options) {
4882
+ return this.request(
4883
+ "GET",
4884
+ `/settlement/native/reports/${encodeURIComponent(reportId)}/export`,
4885
+ {
4886
+ ...options,
4887
+ headers: exportHeaders(options, "text/csv"),
4888
+ responseType: "blob"
4889
+ }
4890
+ );
4891
+ }
4892
+ /** Export the frozen report as JSON, excluding host account-level costs. */
4893
+ async exportNativeReportJson(reportId, options) {
4894
+ return this.request(
4895
+ "GET",
4896
+ `/settlement/native/reports/${encodeURIComponent(reportId)}/export`,
4897
+ {
4898
+ ...options,
4899
+ headers: exportHeaders(options, "application/json")
4900
+ }
4901
+ );
4902
+ }
4697
4903
  };
4698
4904
 
4699
4905
  // src/resources/operationLimits.ts
@@ -5051,7 +5257,7 @@ var Delopay = class {
5051
5257
  url += `?${qs}`;
5052
5258
  }
5053
5259
  }
5054
- const headers = {
5260
+ let headers = {
5055
5261
  ...this.jwtToken ? { Authorization: `Bearer ${this.jwtToken}` } : this.apiKey ? { "api-key": this.apiKey } : {},
5056
5262
  ...options?.headers
5057
5263
  };
@@ -5059,14 +5265,40 @@ var Delopay = class {
5059
5265
  if (options?.body && !isRawBody) {
5060
5266
  headers["Content-Type"] = "application/json";
5061
5267
  }
5062
- const idempotencyKey = findIdempotencyKey(headers)?.trim();
5063
- const isRetryable = method === "GET" || method === "DELETE" || idempotencyKey !== void 0 && idempotencyKey !== "";
5064
5268
  let serializedBody;
5065
5269
  if (isRawBody) {
5066
5270
  serializedBody = options?.body;
5067
5271
  } else if (options?.body) {
5068
5272
  serializedBody = JSON.stringify(options.body);
5069
5273
  }
5274
+ let idempotencyKey = findIdempotencyKey(headers)?.trim();
5275
+ if (options && Object.prototype.hasOwnProperty.call(options, "bodyIdempotencyKey")) {
5276
+ const bodyKey = options?.bodyIdempotencyKey;
5277
+ const serialized = !isRawBody && typeof serializedBody === "string" ? JSON.parse(serializedBody) : null;
5278
+ const actualKey = serialized && typeof serialized === "object" && !Array.isArray(serialized) ? serialized.idempotency_key ?? null : null;
5279
+ const suppliedHeaders = Object.keys(headers).filter(
5280
+ (name) => name.toLowerCase() === "idempotency-key"
5281
+ );
5282
+ if (bodyKey !== null && typeof bodyKey !== "string" || actualKey !== bodyKey || suppliedHeaders.some(
5283
+ (name) => headers[name] !== bodyKey || headers[name]?.trim() !== headers[name]
5284
+ )) {
5285
+ throw new DelopayError("Request retry keys must match the JSON body key", {
5286
+ status: 0,
5287
+ code: "IDEMPOTENCY_KEY_MISMATCH",
5288
+ type: "invalid_request"
5289
+ });
5290
+ }
5291
+ idempotencyKey = bodyKey?.trim();
5292
+ if (suppliedHeaders.length > 0) {
5293
+ headers = {
5294
+ ...Object.fromEntries(
5295
+ Object.entries(headers).filter(([name]) => name.toLowerCase() !== "idempotency-key")
5296
+ ),
5297
+ "Idempotency-Key": idempotencyKey ?? ""
5298
+ };
5299
+ }
5300
+ }
5301
+ const isRetryable = method === "GET" || method === "DELETE" || idempotencyKey !== void 0 && idempotencyKey !== "";
5070
5302
  const callerSignal = options?.signal;
5071
5303
  if (callerSignal?.aborted) {
5072
5304
  throw new DelopayError("Request aborted", {
@@ -7406,6 +7638,41 @@ var CheckoutSession = class {
7406
7638
  } catch {
7407
7639
  }
7408
7640
  }
7641
+ /**
7642
+ * Store one slice of the buyer's checkout recording on our own side.
7643
+ * Called by the hosted checkout as the buyer works through the page; the
7644
+ * client secret is attached automatically.
7645
+ *
7646
+ * **Not telemetry semantics, on purpose.** Unlike
7647
+ * {@link CheckoutSession.recordEvent}, this rejects with a `DelopayError`
7648
+ * like every other payment call, because the recorder has to tell the
7649
+ * answers apart: a `400` with code `IR_16` means the backend will not take
7650
+ * this recording (recording is off on that deployment, the recording is
7651
+ * full, the payment is already recording a different session, or this
7652
+ * number is stored with different content) and the recorder must stop; any
7653
+ * other `400` is the slice itself being refused; a transport failure may be
7654
+ * retried with the **same** bytes under the **same** number, which the
7655
+ * backend answers with `duplicate: true`.
7656
+ *
7657
+ * Pass `keepalive: true` for the last slice of a page that is navigating
7658
+ * away (a redirect rail); browsers refuse keepalive bodies over ~64 KiB, so
7659
+ * only a small final slice should carry it.
7660
+ *
7661
+ * `POST /payments/{paymentId}/replay/slice` (publishable key)
7662
+ */
7663
+ async storeReplaySlice(params, options) {
7664
+ const { keepalive, ...extras } = options ?? {};
7665
+ return this.client.request(
7666
+ "POST",
7667
+ `/payments/${encodeURIComponent(this.paymentId)}/replay/slice`,
7668
+ {
7669
+ body: { ...params, client_secret: this.requireClientSecret() },
7670
+ ...keepalive !== void 0 ? { keepalive } : {},
7671
+ ...extras,
7672
+ headers: this.pkHeaders(extras.headers)
7673
+ }
7674
+ );
7675
+ }
7409
7676
  /**
7410
7677
  * Confirm a subscription (PayPal approval rail). The client secret is
7411
7678
  * attached automatically; the shop's profile id travels as the
@@ -7430,20 +7697,6 @@ var CheckoutSession = class {
7430
7697
  }
7431
7698
  );
7432
7699
  }
7433
- /**
7434
- * The Paysepro rail catalog for the buyer's country.
7435
- *
7436
- * `GET /payment-link/{merchantId}/{paymentId}/paysepro/methods`
7437
- *
7438
- * @param country - Lowercase ISO 3166-1 alpha-2 country code.
7439
- */
7440
- async payseproMethods(country, options) {
7441
- return this.client.request("GET", `${this.linkBase}/paysepro/methods`, {
7442
- query: { cc: country },
7443
- ...options,
7444
- headers: this.bearerHeaders(options?.headers)
7445
- });
7446
- }
7447
7700
  /**
7448
7701
  * The e-Payouts rail catalog for the buyer's country, plus the set of
7449
7702
  * countries that have at least one vendor.
@@ -8204,4 +8457,4 @@ export {
8204
8457
  decodeNativePanes,
8205
8458
  encodeNativePanes
8206
8459
  };
8207
- //# sourceMappingURL=chunk-NRLTXUV7.js.map
8460
+ //# sourceMappingURL=chunk-DQOEWKNX.js.map