@extn/segi-js 0.2.12 → 0.2.13

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.
@@ -109,6 +109,19 @@ function beaconTrace(cfg, path, body) {
109
109
  function withReplay(options = {}) {
110
110
  return { __segi_replay: true, options };
111
111
  }
112
+ async function gzipString(str) {
113
+ try {
114
+ if (typeof CompressionStream === "undefined") return null;
115
+ const cs = new CompressionStream("gzip");
116
+ const writer = cs.writable.getWriter();
117
+ void writer.write(new TextEncoder().encode(str));
118
+ void writer.close();
119
+ const buf = await new Response(cs.readable).arrayBuffer();
120
+ return new Uint8Array(buf);
121
+ } catch (e6) {
122
+ return null;
123
+ }
124
+ }
112
125
  var active = null;
113
126
  function deviceClass() {
114
127
  if (typeof window === "undefined") return "desktop";
@@ -121,7 +134,7 @@ function readQuery(name) {
121
134
  if (typeof location === "undefined") return void 0;
122
135
  try {
123
136
  return _nullishCoalesce(new URLSearchParams(location.search).get(name), () => ( void 0));
124
- } catch (e6) {
137
+ } catch (e7) {
125
138
  return void 0;
126
139
  }
127
140
  }
@@ -168,7 +181,7 @@ async function activateReplay(args) {
168
181
  const body = await res.json().catch(() => ({}));
169
182
  if (body.recordingEnabled === false) recordingEnabled = false;
170
183
  }
171
- } catch (e7) {
184
+ } catch (e8) {
172
185
  }
173
186
  if (!recordingEnabled) {
174
187
  active = {
@@ -247,18 +260,23 @@ async function activateReplay(args) {
247
260
  if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
248
261
  navigator.sendBeacon(url, blob);
249
262
  }
250
- } catch (e8) {
263
+ } catch (e9) {
251
264
  }
252
265
  return;
253
266
  }
254
267
  try {
268
+ const gz = await gzipString(bodyStr);
255
269
  const res = await fetch(`${base}/api/trace/replay`, {
256
270
  method: "POST",
257
- headers: {
271
+ headers: gz ? {
272
+ "Content-Type": "application/json",
273
+ "Content-Encoding": "gzip",
274
+ "X-Segi-Project-Key": transportCfg.projectKey
275
+ } : {
258
276
  "Content-Type": "application/json",
259
277
  "X-Segi-Project-Key": transportCfg.projectKey
260
278
  },
261
- body: bodyStr
279
+ body: _nullishCoalesce(gz, () => ( bodyStr))
262
280
  });
263
281
  if (res.status === 429) {
264
282
  if (active) {
@@ -267,7 +285,7 @@ async function activateReplay(args) {
267
285
  active.rrweb = null;
268
286
  }
269
287
  }
270
- } catch (e9) {
288
+ } catch (e10) {
271
289
  }
272
290
  }
273
291
  }).then(resolve, () => resolve(null));
@@ -109,6 +109,19 @@ function beaconTrace(cfg, path, body) {
109
109
  function withReplay(options = {}) {
110
110
  return { __segi_replay: true, options };
111
111
  }
112
+ async function gzipString(str) {
113
+ try {
114
+ if (typeof CompressionStream === "undefined") return null;
115
+ const cs = new CompressionStream("gzip");
116
+ const writer = cs.writable.getWriter();
117
+ void writer.write(new TextEncoder().encode(str));
118
+ void writer.close();
119
+ const buf = await new Response(cs.readable).arrayBuffer();
120
+ return new Uint8Array(buf);
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
112
125
  var active = null;
113
126
  function deviceClass() {
114
127
  if (typeof window === "undefined") return "desktop";
@@ -252,13 +265,18 @@ async function activateReplay(args) {
252
265
  return;
253
266
  }
254
267
  try {
268
+ const gz = await gzipString(bodyStr);
255
269
  const res = await fetch(`${base}/api/trace/replay`, {
256
270
  method: "POST",
257
- headers: {
271
+ headers: gz ? {
272
+ "Content-Type": "application/json",
273
+ "Content-Encoding": "gzip",
274
+ "X-Segi-Project-Key": transportCfg.projectKey
275
+ } : {
258
276
  "Content-Type": "application/json",
259
277
  "X-Segi-Project-Key": transportCfg.projectKey
260
278
  },
261
- body: bodyStr
279
+ body: gz ?? bodyStr
262
280
  });
263
281
  if (res.status === 429) {
264
282
  if (active) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extn/segi-js",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "Browser JavaScript SDK for the segi error monitoring service",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",