@delopay/sdk 0.147.0 → 0.150.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
@@ -1348,7 +1348,7 @@ var Events = class {
1348
1348
  }
1349
1349
  /**
1350
1350
  * Fire an outgoing webhook event by hand for one object.
1351
- * `POST /events/{merchant_id}/trigger` (be#318)
1351
+ * `POST /events/{merchant_id}/trigger`
1352
1352
  *
1353
1353
  * Not a replay — see {@link EventManualTriggerRequest}. Needs the
1354
1354
  * `WebhookEventTrigger` permission, which is separate from the one that
@@ -1371,7 +1371,7 @@ var Events = class {
1371
1371
  }
1372
1372
  /**
1373
1373
  * Fire an outgoing webhook event by hand (profile-scoped).
1374
- * `POST /events/profile/trigger` (be#318)
1374
+ * `POST /events/profile/trigger`
1375
1375
  *
1376
1376
  * The shop-user twin of {@link trigger}; the shop is taken from the auth
1377
1377
  * context, so `profile_id` on the body is ignored.
@@ -2064,9 +2064,8 @@ var Payments = class {
2064
2064
  );
2065
2065
  }
2066
2066
  /**
2067
- * Open a playback of the payment's stored checkout recording
2068
- * (delopay-backend#1501, delopay-control-center#779): the audited act of
2069
- * watching. Answers the manifest — which slices exist, how long the
2067
+ * Open a playback of the payment's stored checkout recording: the audited
2068
+ * act of watching. Answers the manifest — which slices exist, how long the
2070
2069
  * recording runs, whether a pause in it is expected — and the
2071
2070
  * `playback_id` every {@link Payments.replaySlice} call carries.
2072
2071
  *
@@ -4676,6 +4675,15 @@ var Audit = class {
4676
4675
  };
4677
4676
 
4678
4677
  // src/resources/settlement.ts
4678
+ function exportHeaders(options, accept) {
4679
+ const headers = new Headers(options?.headers);
4680
+ headers.set("Accept", accept);
4681
+ const output = {};
4682
+ headers.forEach((value, key) => {
4683
+ output[key] = value;
4684
+ });
4685
+ return output;
4686
+ }
4679
4687
  var Settlement = class {
4680
4688
  constructor(request) {
4681
4689
  this.request = request;
@@ -4828,6 +4836,45 @@ var Settlement = class {
4828
4836
  { body: params, ...options }
4829
4837
  );
4830
4838
  }
4839
+ /** Append one external transfer record. Send a stable idempotency_key for safe retries. */
4840
+ async recordStatementPayout(statementId, params, options) {
4841
+ return this.request(
4842
+ "POST",
4843
+ `/settlement/statements/${encodeURIComponent(statementId)}/payout`,
4844
+ {
4845
+ body: params,
4846
+ ...options,
4847
+ bodyIdempotencyKey: params.idempotency_key ?? null
4848
+ }
4849
+ );
4850
+ }
4851
+ /** Read individual transfer records, their signed total, and any overpayment. */
4852
+ async listStatementPayouts(statementId, options) {
4853
+ return this.request(
4854
+ "GET",
4855
+ `/settlement/statements/${encodeURIComponent(statementId)}/payouts`,
4856
+ options
4857
+ );
4858
+ }
4859
+ /** Record a transfer against a shop's month before its statement exists. */
4860
+ async recordAdvance(params, options) {
4861
+ return this.request("POST", "/settlement/advances", {
4862
+ body: params,
4863
+ ...options,
4864
+ bodyIdempotencyKey: params.idempotency_key ?? null
4865
+ });
4866
+ }
4867
+ async listAdvances(params, options) {
4868
+ return this.request("GET", "/settlement/advances", {
4869
+ query: {
4870
+ profile_id: params.profile_id,
4871
+ year: params.year,
4872
+ month: params.month,
4873
+ test_mode: params.test_mode
4874
+ },
4875
+ ...options
4876
+ });
4877
+ }
4831
4878
  /**
4832
4879
  * Export a statement as PDF. Returns the raw PDF bytes as a `Blob`, with
4833
4880
  * the same auth, retries and error handling as every other call — persist
@@ -4945,6 +4992,109 @@ var Settlement = class {
4945
4992
  options
4946
4993
  );
4947
4994
  }
4995
+ /**
4996
+ * Calculate a period in its transaction currency. Requires a host-level
4997
+ * dashboard JWT and settlement read permission. Profile users and roles
4998
+ * restricted to selected connector accounts cannot read this aggregate.
4999
+ * Rates apply once to the period total. Unknown or estimated fees keep
5000
+ * dependent amounts provisional. Native money values remain integer strings.
5001
+ */
5002
+ async previewNative(params, options) {
5003
+ return this.request("POST", "/settlement/native/preview", { body: params, ...options });
5004
+ }
5005
+ /**
5006
+ * Recalculate and freeze an immutable report version. Requires settlement
5007
+ * edit permission. Explicitly allow provisional figures when source fees
5008
+ * are incomplete. A report records a calculation and sends no money.
5009
+ * Reuse the same idempotency key when retrying the same request.
5010
+ */
5011
+ async createNativeReport(params, options) {
5012
+ return this.request("POST", "/settlement/native/reports", {
5013
+ body: params,
5014
+ ...options,
5015
+ bodyIdempotencyKey: params.idempotency_key
5016
+ });
5017
+ }
5018
+ async retrieveNativeReport(reportId, options) {
5019
+ return this.request(
5020
+ "GET",
5021
+ `/settlement/native/reports/${encodeURIComponent(reportId)}`,
5022
+ options
5023
+ );
5024
+ }
5025
+ /** List report summaries without fetching every source row in each saved snapshot. */
5026
+ async listNativeReports(params, options) {
5027
+ return this.request("GET", "/settlement/native/reports", {
5028
+ query: {
5029
+ profile_id: params.profile_id,
5030
+ currency: params.currency,
5031
+ test_mode: params.test_mode,
5032
+ limit: params.limit,
5033
+ offset: params.offset
5034
+ },
5035
+ ...options
5036
+ });
5037
+ }
5038
+ /**
5039
+ * Record a transfer already made, under settlement write permission and
5040
+ * the caller's payout limits. This method never sends money. Native minor
5041
+ * units remain strings; negative records must name a same-scope reversal.
5042
+ * These records belong to the native ledger, separate from monthly USD
5043
+ * statement payouts and advances.
5044
+ */
5045
+ async recordNativePayout(params, options) {
5046
+ return this.request("POST", "/settlement/native/payouts", {
5047
+ body: params,
5048
+ ...options,
5049
+ bodyIdempotencyKey: params.idempotency_key
5050
+ });
5051
+ }
5052
+ async listNativePayouts(params, options) {
5053
+ return this.request("GET", "/settlement/native/payouts", {
5054
+ query: {
5055
+ profile_id: params.profile_id,
5056
+ currency: params.currency,
5057
+ test_mode: params.test_mode,
5058
+ limit: params.limit,
5059
+ offset: params.offset
5060
+ },
5061
+ ...options
5062
+ });
5063
+ }
5064
+ /** Refresh a bounded page of provider fee evidence. Follow next_offset while has_more is true. */
5065
+ async refreshNativeFees(params, options) {
5066
+ return this.request("POST", "/settlement/native/fees/refresh", { body: params, ...options });
5067
+ }
5068
+ async downloadNativeReportPdf(reportId, params, options) {
5069
+ return this.request("GET", `/settlement/native/reports/${encodeURIComponent(reportId)}/pdf`, {
5070
+ query: { include_transactions: params?.include_transactions },
5071
+ responseType: "blob",
5072
+ ...options
5073
+ });
5074
+ }
5075
+ /** Download the frozen source rows and calculation as CSV. */
5076
+ async downloadNativeReportCsv(reportId, options) {
5077
+ return this.request(
5078
+ "GET",
5079
+ `/settlement/native/reports/${encodeURIComponent(reportId)}/export`,
5080
+ {
5081
+ ...options,
5082
+ headers: exportHeaders(options, "text/csv"),
5083
+ responseType: "blob"
5084
+ }
5085
+ );
5086
+ }
5087
+ /** Export the frozen report as JSON, excluding host account-level costs. */
5088
+ async exportNativeReportJson(reportId, options) {
5089
+ return this.request(
5090
+ "GET",
5091
+ `/settlement/native/reports/${encodeURIComponent(reportId)}/export`,
5092
+ {
5093
+ ...options,
5094
+ headers: exportHeaders(options, "application/json")
5095
+ }
5096
+ );
5097
+ }
4948
5098
  };
4949
5099
 
4950
5100
  // src/resources/operationLimits.ts
@@ -5302,7 +5452,7 @@ var Delopay = class {
5302
5452
  url += `?${qs}`;
5303
5453
  }
5304
5454
  }
5305
- const headers = {
5455
+ let headers = {
5306
5456
  ...this.jwtToken ? { Authorization: `Bearer ${this.jwtToken}` } : this.apiKey ? { "api-key": this.apiKey } : {},
5307
5457
  ...options?.headers
5308
5458
  };
@@ -5310,14 +5460,40 @@ var Delopay = class {
5310
5460
  if (options?.body && !isRawBody) {
5311
5461
  headers["Content-Type"] = "application/json";
5312
5462
  }
5313
- const idempotencyKey = findIdempotencyKey(headers)?.trim();
5314
- const isRetryable = method === "GET" || method === "DELETE" || idempotencyKey !== void 0 && idempotencyKey !== "";
5315
5463
  let serializedBody;
5316
5464
  if (isRawBody) {
5317
5465
  serializedBody = options?.body;
5318
5466
  } else if (options?.body) {
5319
5467
  serializedBody = JSON.stringify(options.body);
5320
5468
  }
5469
+ let idempotencyKey = findIdempotencyKey(headers)?.trim();
5470
+ if (options && Object.prototype.hasOwnProperty.call(options, "bodyIdempotencyKey")) {
5471
+ const bodyKey = options?.bodyIdempotencyKey;
5472
+ const serialized = !isRawBody && typeof serializedBody === "string" ? JSON.parse(serializedBody) : null;
5473
+ const actualKey = serialized && typeof serialized === "object" && !Array.isArray(serialized) ? serialized.idempotency_key ?? null : null;
5474
+ const suppliedHeaders = Object.keys(headers).filter(
5475
+ (name) => name.toLowerCase() === "idempotency-key"
5476
+ );
5477
+ if (bodyKey !== null && typeof bodyKey !== "string" || actualKey !== bodyKey || suppliedHeaders.some(
5478
+ (name) => headers[name] !== bodyKey || headers[name]?.trim() !== headers[name]
5479
+ )) {
5480
+ throw new DelopayError("Request retry keys must match the JSON body key", {
5481
+ status: 0,
5482
+ code: "IDEMPOTENCY_KEY_MISMATCH",
5483
+ type: "invalid_request"
5484
+ });
5485
+ }
5486
+ idempotencyKey = bodyKey?.trim();
5487
+ if (suppliedHeaders.length > 0) {
5488
+ headers = {
5489
+ ...Object.fromEntries(
5490
+ Object.entries(headers).filter(([name]) => name.toLowerCase() !== "idempotency-key")
5491
+ ),
5492
+ "Idempotency-Key": idempotencyKey ?? ""
5493
+ };
5494
+ }
5495
+ }
5496
+ const isRetryable = method === "GET" || method === "DELETE" || idempotencyKey !== void 0 && idempotencyKey !== "";
5321
5497
  const callerSignal = options?.signal;
5322
5498
  if (callerSignal?.aborted) {
5323
5499
  throw new DelopayError("Request aborted", {
@@ -7658,10 +7834,9 @@ var CheckoutSession = class {
7658
7834
  }
7659
7835
  }
7660
7836
  /**
7661
- * Store one slice of the buyer's checkout recording on our own side
7662
- * (delopay-backend#1501, delopay-control-center#779). Called by the hosted
7663
- * checkout as the buyer works through the page; the client secret is
7664
- * attached automatically.
7837
+ * Store one slice of the buyer's checkout recording on our own side.
7838
+ * Called by the hosted checkout as the buyer works through the page; the
7839
+ * client secret is attached automatically.
7665
7840
  *
7666
7841
  * **Not telemetry semantics, on purpose.** Unlike
7667
7842
  * {@link CheckoutSession.recordEvent}, this rejects with a `DelopayError`
@@ -7717,20 +7892,6 @@ var CheckoutSession = class {
7717
7892
  }
7718
7893
  );
7719
7894
  }
7720
- /**
7721
- * The Paysepro rail catalog for the buyer's country.
7722
- *
7723
- * `GET /payment-link/{merchantId}/{paymentId}/paysepro/methods`
7724
- *
7725
- * @param country - Lowercase ISO 3166-1 alpha-2 country code.
7726
- */
7727
- async payseproMethods(country, options) {
7728
- return this.client.request("GET", `${this.linkBase}/paysepro/methods`, {
7729
- query: { cc: country },
7730
- ...options,
7731
- headers: this.bearerHeaders(options?.headers)
7732
- });
7733
- }
7734
7895
  /**
7735
7896
  * The e-Payouts rail catalog for the buyer's country, plus the set of
7736
7897
  * countries that have at least one vendor.