@offscript/sdk 0.1.8 → 0.1.9

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkZB2LSKD2_cjs = require('./chunk-ZB2LSKD2.cjs');
3
+ var chunkM2E6CWGK_cjs = require('./chunk-M2E6CWGK.cjs');
4
4
 
5
5
  // src/types/config.ts
6
6
  var DEFAULT_RECORDING = {
@@ -347,7 +347,7 @@ var ActionRecorder = class {
347
347
  this.scrollState = /* @__PURE__ */ new Map();
348
348
  this.move = [];
349
349
  const r = sink.config.recording;
350
- this.gen = new chunkZB2LSKD2_cjs.SelectorGenerator({ testIdAttributes: r.testIdAttributes, stableAttributes: r.stableAttributes });
350
+ this.gen = new chunkM2E6CWGK_cjs.SelectorGenerator({ testIdAttributes: r.testIdAttributes, stableAttributes: r.stableAttributes });
351
351
  }
352
352
  start() {
353
353
  const d = this.d;
@@ -411,7 +411,7 @@ var ActionRecorder = class {
411
411
  emit(draft, el, extra) {
412
412
  const s = this.sink.sanitizer;
413
413
  const data = {
414
- schemaVersion: chunkZB2LSKD2_cjs.ACTION_SCHEMA_VERSION,
414
+ schemaVersion: chunkM2E6CWGK_cjs.ACTION_SCHEMA_VERSION,
415
415
  type: draft.type,
416
416
  url: s.sanitizeUrl(location.href),
417
417
  viewport: { width: window.innerWidth, height: window.innerHeight },
@@ -672,7 +672,7 @@ function collectContext(reason, captureSensitiveValues = false) {
672
672
  timezone: safe(() => Intl.DateTimeFormat().resolvedOptions().timeZone),
673
673
  online: nav.onLine,
674
674
  visibility: document.visibilityState,
675
- sdkVersion: chunkZB2LSKD2_cjs.SDK_VERSION,
675
+ sdkVersion: chunkM2E6CWGK_cjs.SDK_VERSION,
676
676
  captureSensitiveValues
677
677
  };
678
678
  }
@@ -1297,7 +1297,6 @@ var RRWebRecorder = class {
1297
1297
  // erros internos do rrweb não propagam
1298
1298
  };
1299
1299
  this.stopFn = mod.record(options) ?? void 0;
1300
- this.scheduleSnapshot();
1301
1300
  }
1302
1301
  /** Captura o DOM depois do ciclo de renderização atual (Vue, React, etc.). */
1303
1302
  scheduleSnapshot() {
@@ -1365,7 +1364,9 @@ var RRWebRecorder = class {
1365
1364
  const emitted = this.sink.emit("rrweb", event, { priority, at: event.timestamp });
1366
1365
  if (event.type === 2) {
1367
1366
  this.needsSnapshot = !emitted;
1368
- if (emitted) this.snapshotsTaken++;
1367
+ if (emitted) {
1368
+ this.snapshotsTaken++;
1369
+ }
1369
1370
  }
1370
1371
  if (!emitted && event.type === 3) this.needsSnapshot = true;
1371
1372
  });
@@ -1426,7 +1427,8 @@ var RRWebRecorder = class {
1426
1427
  this.takeFullSnapshot();
1427
1428
  }
1428
1429
  stop() {
1429
- if (!this.stopped && !this.paused) this.takeFullSnapshot();
1430
+ const snapshotPending = this.settling || this.scheduledSnapshotFrame !== void 0;
1431
+ if (!this.stopped && !this.paused && snapshotPending) this.takeFullSnapshot();
1430
1432
  this.stopped = true;
1431
1433
  this.cancelScheduledSnapshot();
1432
1434
  safe(() => this.stopFn?.());
@@ -2295,6 +2297,23 @@ function tokenFingerprint(token) {
2295
2297
  }
2296
2298
  return `${first >>> 0}.${second >>> 0}`;
2297
2299
  }
2300
+ async function encodeRecordingPayload(payload) {
2301
+ const json = JSON.stringify(payload);
2302
+ const CompressionStreamCtor = globalThis.CompressionStream;
2303
+ if (!CompressionStreamCtor) return { body: json };
2304
+ try {
2305
+ const stream = new CompressionStreamCtor("gzip");
2306
+ const writer = stream.writable.getWriter();
2307
+ await writer.write(new TextEncoder().encode(json));
2308
+ await writer.close();
2309
+ return {
2310
+ body: await new Response(stream.readable).blob(),
2311
+ contentEncoding: "gzip"
2312
+ };
2313
+ } catch {
2314
+ return { body: json };
2315
+ }
2316
+ }
2298
2317
  var Offscript = class {
2299
2318
  constructor(config = {}) {
2300
2319
  this.bus = new Emitter();
@@ -2526,10 +2545,17 @@ var Offscript = class {
2526
2545
  if (!["https:", "http:"].includes(url.protocol)) throw new ConfigError("Endpoint HTTP inv\xE1lido");
2527
2546
  const payload = await this.stopRecording();
2528
2547
  try {
2548
+ const encodedPayload = await encodeRecordingPayload(payload);
2549
+ const headers = {
2550
+ "Content-Type": "application/json",
2551
+ Accept: "application/json",
2552
+ Authorization: `Bearer ${token}`
2553
+ };
2554
+ if (encodedPayload.contentEncoding) headers["Content-Encoding"] = encodedPayload.contentEncoding;
2529
2555
  const response = await fetch(url.href, {
2530
2556
  method: "POST",
2531
- headers: { "Content-Type": "application/json", Accept: "application/json", Authorization: `Bearer ${token}` },
2532
- body: JSON.stringify(payload)
2557
+ headers,
2558
+ body: encodedPayload.body
2533
2559
  });
2534
2560
  if (!response.ok) throw new OffscriptError("TRANSPORT_FAILED", `Falha ao enviar grava\xE7\xE3o: HTTP ${response.status}`, { status: response.status });
2535
2561
  this.submitted = true;
@@ -2591,7 +2617,7 @@ var Offscript = class {
2591
2617
  this.destroyed = true;
2592
2618
  }
2593
2619
  exportPlaywrightData() {
2594
- return chunkZB2LSKD2_cjs.buildPlaywrightContract({ actions: this.actionLog, contexts: this.contextLog });
2620
+ return chunkM2E6CWGK_cjs.buildPlaywrightContract({ actions: this.actionLog, contexts: this.contextLog });
2595
2621
  }
2596
2622
  getRecordedActions() {
2597
2623
  return this.actionLog;
@@ -2736,7 +2762,7 @@ var Offscript = class {
2736
2762
  this.bus.emit("statusChange", { from, to });
2737
2763
  }
2738
2764
  };
2739
- Offscript.version = chunkZB2LSKD2_cjs.SDK_VERSION;
2765
+ Offscript.version = chunkM2E6CWGK_cjs.SDK_VERSION;
2740
2766
 
2741
2767
  exports.ConfigError = ConfigError;
2742
2768
  exports.DEFAULT_PRIVACY = DEFAULT_PRIVACY;
@@ -2745,5 +2771,5 @@ exports.DataSanitizer = DataSanitizer;
2745
2771
  exports.InvalidStateError = InvalidStateError;
2746
2772
  exports.Offscript = Offscript;
2747
2773
  exports.OffscriptError = OffscriptError;
2748
- //# sourceMappingURL=chunk-E53R6UOC.cjs.map
2749
- //# sourceMappingURL=chunk-E53R6UOC.cjs.map
2774
+ //# sourceMappingURL=chunk-YPGRVKY4.cjs.map
2775
+ //# sourceMappingURL=chunk-YPGRVKY4.cjs.map