@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,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var chunkE53R6UOC_cjs = require('../chunk-E53R6UOC.cjs');
4
- require('../chunk-ZB2LSKD2.cjs');
3
+ var chunkYPGRVKY4_cjs = require('../chunk-YPGRVKY4.cjs');
4
+ require('../chunk-M2E6CWGK.cjs');
5
5
 
6
6
  // src/adapters/nuxt.ts
7
7
  function createNuxtOffscript(config) {
8
8
  if (typeof window === "undefined") return null;
9
- const sdk = new chunkE53R6UOC_cjs.Offscript(config);
9
+ const sdk = new chunkYPGRVKY4_cjs.Offscript(config);
10
10
  void sdk.init().catch(() => void 0);
11
11
  return sdk;
12
12
  }
@@ -1,5 +1,5 @@
1
- import { Offscript } from '../chunk-W27UMAEC.js';
2
- import '../chunk-AQG5MIW5.js';
1
+ import { Offscript } from '../chunk-5F637PDG.js';
2
+ import '../chunk-KKEYBVTX.js';
3
3
 
4
4
  // src/adapters/nuxt.ts
5
5
  function createNuxtOffscript(config) {
@@ -1,18 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var chunkYIKWNN5R_cjs = require('../chunk-YIKWNN5R.cjs');
4
- require('../chunk-E53R6UOC.cjs');
5
- require('../chunk-ZB2LSKD2.cjs');
3
+ var chunkWK242AJ2_cjs = require('../chunk-WK242AJ2.cjs');
4
+ require('../chunk-YPGRVKY4.cjs');
5
+ require('../chunk-M2E6CWGK.cjs');
6
6
 
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, "createOffscript", {
10
10
  enumerable: true,
11
- get: function () { return chunkYIKWNN5R_cjs.createOffscript; }
11
+ get: function () { return chunkWK242AJ2_cjs.createOffscript; }
12
12
  });
13
13
  Object.defineProperty(exports, "startOffscript", {
14
14
  enumerable: true,
15
- get: function () { return chunkYIKWNN5R_cjs.startOffscript; }
15
+ get: function () { return chunkWK242AJ2_cjs.startOffscript; }
16
16
  });
17
17
  //# sourceMappingURL=vanilla.cjs.map
18
18
  //# sourceMappingURL=vanilla.cjs.map
@@ -1,5 +1,5 @@
1
- export { createOffscript, startOffscript } from '../chunk-IOIVKJTV.js';
2
- import '../chunk-W27UMAEC.js';
3
- import '../chunk-AQG5MIW5.js';
1
+ export { createOffscript, startOffscript } from '../chunk-U232L3JD.js';
2
+ import '../chunk-5F637PDG.js';
3
+ import '../chunk-KKEYBVTX.js';
4
4
  //# sourceMappingURL=vanilla.js.map
5
5
  //# sourceMappingURL=vanilla.js.map
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkE53R6UOC_cjs = require('../chunk-E53R6UOC.cjs');
4
- require('../chunk-ZB2LSKD2.cjs');
3
+ var chunkYPGRVKY4_cjs = require('../chunk-YPGRVKY4.cjs');
4
+ require('../chunk-M2E6CWGK.cjs');
5
5
 
6
6
  // src/adapters/vue.ts
7
7
  var OFFSCRIPT_KEY = "$offscript";
8
8
  var OffscriptPlugin = {
9
9
  install(app, config) {
10
- const sdk = new chunkE53R6UOC_cjs.Offscript(config);
10
+ const sdk = new chunkYPGRVKY4_cjs.Offscript(config);
11
11
  void sdk.init().catch(() => void 0);
12
12
  if (app.config?.globalProperties) {
13
13
  app.config.globalProperties[OFFSCRIPT_KEY] = sdk;
@@ -1,5 +1,5 @@
1
- import { Offscript } from '../chunk-W27UMAEC.js';
2
- import '../chunk-AQG5MIW5.js';
1
+ import { Offscript } from '../chunk-5F637PDG.js';
2
+ import '../chunk-KKEYBVTX.js';
3
3
 
4
4
  // src/adapters/vue.ts
5
5
  var OFFSCRIPT_KEY = "$offscript";
@@ -1,4 +1,4 @@
1
- import { buildPlaywrightContract, SDK_VERSION, SelectorGenerator, ACTION_SCHEMA_VERSION } from './chunk-AQG5MIW5.js';
1
+ import { buildPlaywrightContract, SDK_VERSION, SelectorGenerator, ACTION_SCHEMA_VERSION } from './chunk-KKEYBVTX.js';
2
2
 
3
3
  // src/types/config.ts
4
4
  var DEFAULT_RECORDING = {
@@ -1295,7 +1295,6 @@ var RRWebRecorder = class {
1295
1295
  // erros internos do rrweb não propagam
1296
1296
  };
1297
1297
  this.stopFn = mod.record(options) ?? void 0;
1298
- this.scheduleSnapshot();
1299
1298
  }
1300
1299
  /** Captura o DOM depois do ciclo de renderização atual (Vue, React, etc.). */
1301
1300
  scheduleSnapshot() {
@@ -1363,7 +1362,9 @@ var RRWebRecorder = class {
1363
1362
  const emitted = this.sink.emit("rrweb", event, { priority, at: event.timestamp });
1364
1363
  if (event.type === 2) {
1365
1364
  this.needsSnapshot = !emitted;
1366
- if (emitted) this.snapshotsTaken++;
1365
+ if (emitted) {
1366
+ this.snapshotsTaken++;
1367
+ }
1367
1368
  }
1368
1369
  if (!emitted && event.type === 3) this.needsSnapshot = true;
1369
1370
  });
@@ -1424,7 +1425,8 @@ var RRWebRecorder = class {
1424
1425
  this.takeFullSnapshot();
1425
1426
  }
1426
1427
  stop() {
1427
- if (!this.stopped && !this.paused) this.takeFullSnapshot();
1428
+ const snapshotPending = this.settling || this.scheduledSnapshotFrame !== void 0;
1429
+ if (!this.stopped && !this.paused && snapshotPending) this.takeFullSnapshot();
1428
1430
  this.stopped = true;
1429
1431
  this.cancelScheduledSnapshot();
1430
1432
  safe(() => this.stopFn?.());
@@ -2293,6 +2295,23 @@ function tokenFingerprint(token) {
2293
2295
  }
2294
2296
  return `${first >>> 0}.${second >>> 0}`;
2295
2297
  }
2298
+ async function encodeRecordingPayload(payload) {
2299
+ const json = JSON.stringify(payload);
2300
+ const CompressionStreamCtor = globalThis.CompressionStream;
2301
+ if (!CompressionStreamCtor) return { body: json };
2302
+ try {
2303
+ const stream = new CompressionStreamCtor("gzip");
2304
+ const writer = stream.writable.getWriter();
2305
+ await writer.write(new TextEncoder().encode(json));
2306
+ await writer.close();
2307
+ return {
2308
+ body: await new Response(stream.readable).blob(),
2309
+ contentEncoding: "gzip"
2310
+ };
2311
+ } catch {
2312
+ return { body: json };
2313
+ }
2314
+ }
2296
2315
  var Offscript = class {
2297
2316
  constructor(config = {}) {
2298
2317
  this.bus = new Emitter();
@@ -2524,10 +2543,17 @@ var Offscript = class {
2524
2543
  if (!["https:", "http:"].includes(url.protocol)) throw new ConfigError("Endpoint HTTP inv\xE1lido");
2525
2544
  const payload = await this.stopRecording();
2526
2545
  try {
2546
+ const encodedPayload = await encodeRecordingPayload(payload);
2547
+ const headers = {
2548
+ "Content-Type": "application/json",
2549
+ Accept: "application/json",
2550
+ Authorization: `Bearer ${token}`
2551
+ };
2552
+ if (encodedPayload.contentEncoding) headers["Content-Encoding"] = encodedPayload.contentEncoding;
2527
2553
  const response = await fetch(url.href, {
2528
2554
  method: "POST",
2529
- headers: { "Content-Type": "application/json", Accept: "application/json", Authorization: `Bearer ${token}` },
2530
- body: JSON.stringify(payload)
2555
+ headers,
2556
+ body: encodedPayload.body
2531
2557
  });
2532
2558
  if (!response.ok) throw new OffscriptError("TRANSPORT_FAILED", `Falha ao enviar grava\xE7\xE3o: HTTP ${response.status}`, { status: response.status });
2533
2559
  this.submitted = true;
@@ -2737,5 +2763,5 @@ var Offscript = class {
2737
2763
  Offscript.version = SDK_VERSION;
2738
2764
 
2739
2765
  export { ConfigError, DEFAULT_PRIVACY, DEFAULT_RECORDING, DataSanitizer, InvalidStateError, Offscript, OffscriptError };
2740
- //# sourceMappingURL=chunk-W27UMAEC.js.map
2741
- //# sourceMappingURL=chunk-W27UMAEC.js.map
2766
+ //# sourceMappingURL=chunk-5F637PDG.js.map
2767
+ //# sourceMappingURL=chunk-5F637PDG.js.map