@extn/segi-js 0.2.12 → 0.2.14

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.js CHANGED
@@ -223,6 +223,12 @@ var Segi = {
223
223
  if (_optionalChain([replay, 'optionalAccess', _3 => _3.__segi_replay])) {
224
224
  void Promise.resolve().then(() => _interopRequireWildcard(require("./replay/index.js"))).then((mod) => {
225
225
  Segi.replay = mod.replayApi;
226
+ if (state.user) {
227
+ mod.replayApi.setUser({
228
+ id: state.user.id,
229
+ email: state.user.email
230
+ });
231
+ }
226
232
  return mod.activateReplay({
227
233
  projectKey: core.projectKey,
228
234
  // Empty/undefined here is fine — the replay transport falls
@@ -295,6 +301,7 @@ var Segi = {
295
301
  setUser(user) {
296
302
  try {
297
303
  state.user = user;
304
+ Segi.replay.setUser(user ? { id: user.id, email: user.email } : null);
298
305
  } catch (e9) {
299
306
  }
300
307
  },
package/dist/index.mjs CHANGED
@@ -223,6 +223,12 @@ var Segi = {
223
223
  if (replay?.__segi_replay) {
224
224
  void import("./replay/index.mjs").then((mod) => {
225
225
  Segi.replay = mod.replayApi;
226
+ if (state.user) {
227
+ mod.replayApi.setUser({
228
+ id: state.user.id,
229
+ email: state.user.email
230
+ });
231
+ }
226
232
  return mod.activateReplay({
227
233
  projectKey: core.projectKey,
228
234
  // Empty/undefined here is fine — the replay transport falls
@@ -295,6 +301,7 @@ var Segi = {
295
301
  setUser(user) {
296
302
  try {
297
303
  state.user = user;
304
+ Segi.replay.setUser(user ? { id: user.id, email: user.email } : null);
298
305
  } catch {
299
306
  }
300
307
  },
@@ -109,7 +109,21 @@ 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;
126
+ var pendingUser = void 0;
113
127
  function deviceClass() {
114
128
  if (typeof window === "undefined") return "desktop";
115
129
  const w = window.innerWidth;
@@ -121,7 +135,7 @@ function readQuery(name) {
121
135
  if (typeof location === "undefined") return void 0;
122
136
  try {
123
137
  return _nullishCoalesce(new URLSearchParams(location.search).get(name), () => ( void 0));
124
- } catch (e6) {
138
+ } catch (e7) {
125
139
  return void 0;
126
140
  }
127
141
  }
@@ -168,7 +182,7 @@ async function activateReplay(args) {
168
182
  const body = await res.json().catch(() => ({}));
169
183
  if (body.recordingEnabled === false) recordingEnabled = false;
170
184
  }
171
- } catch (e7) {
185
+ } catch (e8) {
172
186
  }
173
187
  if (!recordingEnabled) {
174
188
  active = {
@@ -184,6 +198,7 @@ async function activateReplay(args) {
184
198
  clickCount: 0,
185
199
  recordingEnabled: false
186
200
  };
201
+ if (pendingUser !== void 0) replayApi.setUser(pendingUser);
187
202
  return;
188
203
  }
189
204
  active = {
@@ -199,6 +214,7 @@ async function activateReplay(args) {
199
214
  clickCount: 0,
200
215
  recordingEnabled: true
201
216
  };
217
+ if (pendingUser !== void 0) replayApi.setUser(pendingUser);
202
218
  let lastSessionBump = Date.now();
203
219
  const bumpIfStale = () => {
204
220
  const now = Date.now();
@@ -247,18 +263,23 @@ async function activateReplay(args) {
247
263
  if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
248
264
  navigator.sendBeacon(url, blob);
249
265
  }
250
- } catch (e8) {
266
+ } catch (e9) {
251
267
  }
252
268
  return;
253
269
  }
254
270
  try {
271
+ const gz = await gzipString(bodyStr);
255
272
  const res = await fetch(`${base}/api/trace/replay`, {
256
273
  method: "POST",
257
- headers: {
274
+ headers: gz ? {
275
+ "Content-Type": "application/json",
276
+ "Content-Encoding": "gzip",
277
+ "X-Segi-Project-Key": transportCfg.projectKey
278
+ } : {
258
279
  "Content-Type": "application/json",
259
280
  "X-Segi-Project-Key": transportCfg.projectKey
260
281
  },
261
- body: bodyStr
282
+ body: _nullishCoalesce(gz, () => ( bodyStr))
262
283
  });
263
284
  if (res.status === 429) {
264
285
  if (active) {
@@ -267,7 +288,7 @@ async function activateReplay(args) {
267
288
  active.rrweb = null;
268
289
  }
269
290
  }
270
- } catch (e9) {
291
+ } catch (e10) {
271
292
  }
272
293
  }
273
294
  }).then(resolve, () => resolve(null));
@@ -327,8 +348,9 @@ var replayApi = {
327
348
  bumpSessionActivity();
328
349
  },
329
350
  setUser(user) {
351
+ pendingUser = user;
330
352
  if (!active) return;
331
- active.userId = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _22 => _22.id]), () => ( null));
353
+ active.userId = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _22 => _22.id, 'optionalAccess', _23 => _23.slice, 'call', _24 => _24(0, 128)]), () => ( null));
332
354
  void postTrace(active.config, "/session/start", {
333
355
  sessionUid: active.sessionUid,
334
356
  anonId: getOrCreateAnonId(),
@@ -364,17 +386,17 @@ var replayApi = {
364
386
  const nowBlocked = isPathBlocked(active.options, location.pathname);
365
387
  if (nowBlocked) {
366
388
  if (!active.paused) {
367
- _optionalChain([active, 'access', _23 => _23.rrweb, 'optionalAccess', _24 => _24.pause, 'call', _25 => _25()]);
389
+ _optionalChain([active, 'access', _25 => _25.rrweb, 'optionalAccess', _26 => _26.pause, 'call', _27 => _27()]);
368
390
  active.paused = true;
369
391
  }
370
392
  return;
371
393
  }
372
394
  if (active.paused) {
373
- _optionalChain([active, 'access', _26 => _26.rrweb, 'optionalAccess', _27 => _27.resume, 'call', _28 => _28()]);
395
+ _optionalChain([active, 'access', _28 => _28.rrweb, 'optionalAccess', _29 => _29.resume, 'call', _30 => _30()]);
374
396
  active.paused = false;
375
397
  }
376
398
  active.pagesVisited += 1;
377
- _optionalChain([active, 'access', _29 => _29.rrweb, 'optionalAccess', _30 => _30.takeFullSnapshot, 'call', _31 => _31()]);
399
+ _optionalChain([active, 'access', _31 => _31.rrweb, 'optionalAccess', _32 => _32.takeFullSnapshot, 'call', _33 => _33()]);
378
400
  void postTrace(active.config, "/events", {
379
401
  events: [
380
402
  {
@@ -389,7 +411,7 @@ var replayApi = {
389
411
  },
390
412
  /** Test seam: returns null when replay was not activated for this session. */
391
413
  _sessionUid() {
392
- return _nullishCoalesce(_optionalChain([active, 'optionalAccess', _32 => _32.sessionUid]), () => ( null));
414
+ return _nullishCoalesce(_optionalChain([active, 'optionalAccess', _34 => _34.sessionUid]), () => ( null));
393
415
  }
394
416
  };
395
417
 
@@ -109,7 +109,21 @@ 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;
126
+ var pendingUser = void 0;
113
127
  function deviceClass() {
114
128
  if (typeof window === "undefined") return "desktop";
115
129
  const w = window.innerWidth;
@@ -184,6 +198,7 @@ async function activateReplay(args) {
184
198
  clickCount: 0,
185
199
  recordingEnabled: false
186
200
  };
201
+ if (pendingUser !== void 0) replayApi.setUser(pendingUser);
187
202
  return;
188
203
  }
189
204
  active = {
@@ -199,6 +214,7 @@ async function activateReplay(args) {
199
214
  clickCount: 0,
200
215
  recordingEnabled: true
201
216
  };
217
+ if (pendingUser !== void 0) replayApi.setUser(pendingUser);
202
218
  let lastSessionBump = Date.now();
203
219
  const bumpIfStale = () => {
204
220
  const now = Date.now();
@@ -252,13 +268,18 @@ async function activateReplay(args) {
252
268
  return;
253
269
  }
254
270
  try {
271
+ const gz = await gzipString(bodyStr);
255
272
  const res = await fetch(`${base}/api/trace/replay`, {
256
273
  method: "POST",
257
- headers: {
274
+ headers: gz ? {
275
+ "Content-Type": "application/json",
276
+ "Content-Encoding": "gzip",
277
+ "X-Segi-Project-Key": transportCfg.projectKey
278
+ } : {
258
279
  "Content-Type": "application/json",
259
280
  "X-Segi-Project-Key": transportCfg.projectKey
260
281
  },
261
- body: bodyStr
282
+ body: gz ?? bodyStr
262
283
  });
263
284
  if (res.status === 429) {
264
285
  if (active) {
@@ -327,8 +348,9 @@ var replayApi = {
327
348
  bumpSessionActivity();
328
349
  },
329
350
  setUser(user) {
351
+ pendingUser = user;
330
352
  if (!active) return;
331
- active.userId = user?.id ?? null;
353
+ active.userId = user?.id?.slice(0, 128) ?? null;
332
354
  void postTrace(active.config, "/session/start", {
333
355
  sessionUid: active.sessionUid,
334
356
  anonId: getOrCreateAnonId(),
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.14",
4
4
  "description": "Browser JavaScript SDK for the segi error monitoring service",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",