@delopay/sdk 0.180.0 → 0.181.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.
@@ -9219,6 +9219,18 @@ function withoutHeader(headers, name) {
9219
9219
  }
9220
9220
  return out;
9221
9221
  }
9222
+ async function gzipJson(value) {
9223
+ const ctor = globalThis.CompressionStream;
9224
+ if (typeof ctor !== "function") return null;
9225
+ try {
9226
+ const bytes = new TextEncoder().encode(JSON.stringify(value));
9227
+ return await new Response(
9228
+ new Blob([bytes]).stream().pipeThrough(new ctor("gzip"))
9229
+ ).arrayBuffer();
9230
+ } catch {
9231
+ return null;
9232
+ }
9233
+ }
9222
9234
  var CheckoutSession = class {
9223
9235
  constructor(options) {
9224
9236
  this.merchantId = options.merchantId;
@@ -9370,18 +9382,38 @@ var CheckoutSession = class {
9370
9382
  * away (a redirect rail); browsers refuse keepalive bodies over ~64 KiB, so
9371
9383
  * only a small final slice should carry it.
9372
9384
  *
9385
+ * Pass `compress: true` to send the slice gzipped. Recorded page events
9386
+ * compress heavily, so this is mostly a saving on the buyer's connection. It
9387
+ * is opt-in and degrades silently: a runtime without `CompressionStream`
9388
+ * sends the same slice uncompressed rather than failing, so a caller never
9389
+ * has to feature-test before asking for it.
9390
+ *
9391
+ * ⚠️ `keepalive` overrides it. Compressing means awaiting a stream read
9392
+ * before the request is made, and `keepalive` protects a request only once
9393
+ * it has been initiated — so a page torn down mid-compression would drop the
9394
+ * final slice altogether. A slice sent with `keepalive` therefore always
9395
+ * travels uncompressed, whatever `compress` says. Passing both is allowed and
9396
+ * is what a recorder should do: every ordinary slice compresses, and the last
9397
+ * one is sent the way that actually arrives.
9398
+ *
9373
9399
  * `POST /payments/{paymentId}/replay/slice` (publishable key)
9374
9400
  */
9375
9401
  async storeReplaySlice(params, options) {
9376
- const { keepalive, ...extras } = options ?? {};
9402
+ const { keepalive, compress, ...extras } = options ?? {};
9403
+ const body = { ...params, client_secret: this.requireClientSecret() };
9404
+ const headers = this.pkHeaders(extras.headers);
9405
+ const gzipped = compress === true && keepalive !== true ? await gzipJson(body) : null;
9377
9406
  return this.client.request(
9378
9407
  "POST",
9379
9408
  `/payments/${encodeURIComponent(this.paymentId)}/replay/slice`,
9380
9409
  {
9381
- body: { ...params, client_secret: this.requireClientSecret() },
9410
+ body: gzipped ?? body,
9382
9411
  ...keepalive !== void 0 ? { keepalive } : {},
9383
9412
  ...extras,
9384
- headers: this.pkHeaders(extras.headers)
9413
+ // `Content-Type` has to be stated for the compressed body: the client
9414
+ // only sets it for a body it serialises itself, and the bytes are
9415
+ // still JSON — gzip is how they travel, not what they are.
9416
+ headers: gzipped === null ? headers : { ...headers, "Content-Type": "application/json", "Content-Encoding": "gzip" }
9385
9417
  }
9386
9418
  );
9387
9419
  }
@@ -10330,4 +10362,4 @@ export {
10330
10362
  decodeNativePanes,
10331
10363
  encodeNativePanes
10332
10364
  };
10333
- //# sourceMappingURL=chunk-OTLLSSM7.js.map
10365
+ //# sourceMappingURL=chunk-3GSFUNXW.js.map