@extn/segi-js 0.2.14 → 0.2.16

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.d.mts CHANGED
@@ -16,7 +16,14 @@ interface InitOptions {
16
16
  type SegiInitOptions = SegiClientOptions & {
17
17
  replay?: ReplayConfig;
18
18
  };
19
+ type ErrorSignal = {
20
+ ts: string;
21
+ url?: string;
22
+ };
19
23
  type ReplayApi = {
24
+ _captureError(signal: ErrorSignal): void;
25
+ _sessionUid(): string | null;
26
+ _stop(): void;
20
27
  pause(): void;
21
28
  resume(): void;
22
29
  setUser(user: {
package/dist/index.d.ts CHANGED
@@ -16,7 +16,14 @@ interface InitOptions {
16
16
  type SegiInitOptions = SegiClientOptions & {
17
17
  replay?: ReplayConfig;
18
18
  };
19
+ type ErrorSignal = {
20
+ ts: string;
21
+ url?: string;
22
+ };
19
23
  type ReplayApi = {
24
+ _captureError(signal: ErrorSignal): void;
25
+ _sessionUid(): string | null;
26
+ _stop(): void;
20
27
  pause(): void;
21
28
  resume(): void;
22
29
  setUser(user: {
package/dist/index.js CHANGED
@@ -178,7 +178,18 @@ function detachListeners() {
178
178
  window.removeEventListener("error", captureWindowError, true);
179
179
  window.removeEventListener("unhandledrejection", captureWindowError, true);
180
180
  }
181
+ var pendingReplayErrors = [];
182
+ var replayEnabled = false;
183
+ var replayEpoch = 0;
181
184
  var noopReplay = {
185
+ _captureError(signal) {
186
+ if (pendingReplayErrors.length < 20) pendingReplayErrors.push(signal);
187
+ },
188
+ _sessionUid() {
189
+ return null;
190
+ },
191
+ _stop() {
192
+ },
182
193
  pause() {
183
194
  },
184
195
  resume() {
@@ -215,14 +226,22 @@ var Segi = {
215
226
  return;
216
227
  }
217
228
  if (state.initialized) detachListeners();
229
+ Segi.replay._stop();
230
+ Segi.replay = noopReplay;
231
+ pendingReplayErrors = [];
232
+ const epoch = ++replayEpoch;
218
233
  const { replay, ...core } = options;
234
+ replayEnabled = !!_optionalChain([replay, 'optionalAccess', _3 => _3.__segi_replay]) && replay.options.enabled !== false;
219
235
  state.options = { ...core };
220
236
  state.initialized = true;
221
237
  if (w) w.__segiInitialized = true;
222
238
  attachListeners();
223
- if (_optionalChain([replay, 'optionalAccess', _3 => _3.__segi_replay])) {
239
+ if (_optionalChain([replay, 'optionalAccess', _4 => _4.__segi_replay])) {
224
240
  void Promise.resolve().then(() => _interopRequireWildcard(require("./replay/index.js"))).then((mod) => {
241
+ if (epoch !== replayEpoch || !state.initialized) return;
225
242
  Segi.replay = mod.replayApi;
243
+ for (const error of pendingReplayErrors) mod.replayApi._captureError(error);
244
+ pendingReplayErrors = [];
226
245
  if (state.user) {
227
246
  mod.replayApi.setUser({
228
247
  id: state.user.id,
@@ -250,6 +269,11 @@ var Segi = {
250
269
  close() {
251
270
  try {
252
271
  detachListeners();
272
+ replayEpoch++;
273
+ replayEnabled = false;
274
+ Segi.replay._stop();
275
+ Segi.replay = noopReplay;
276
+ pendingReplayErrors = [];
253
277
  state.initialized = false;
254
278
  state.user = null;
255
279
  state.tags = {};
@@ -275,8 +299,15 @@ var Segi = {
275
299
  runtime: "browser",
276
300
  url: _nullishCoalesce(context.url, () => ( (typeof location !== "undefined" ? location.href : void 0))),
277
301
  userAgent: _nullishCoalesce(context.userAgent, () => ( (typeof navigator !== "undefined" ? navigator.userAgent : void 0))),
278
- ...context
302
+ ...context,
303
+ extra: {
304
+ ...context.extra,
305
+ ...Segi.replay._sessionUid() ? { sessionUid: Segi.replay._sessionUid() } : {}
306
+ }
279
307
  });
308
+ if (replayEnabled && !evt._drop) {
309
+ Segi.replay._captureError({ ts: evt.timestamp || (/* @__PURE__ */ new Date()).toISOString(), url: evt.url });
310
+ }
280
311
  send(state.options.endpoint, state.options.projectKey, evt);
281
312
  } catch (e7) {
282
313
  }
@@ -292,8 +323,15 @@ var Segi = {
292
323
  runtime: "browser",
293
324
  url: typeof location !== "undefined" ? location.href : void 0,
294
325
  userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
295
- ...context
326
+ ...context,
327
+ extra: {
328
+ ...context.extra,
329
+ ...Segi.replay._sessionUid() ? { sessionUid: Segi.replay._sessionUid() } : {}
330
+ }
296
331
  });
332
+ if (replayEnabled && (evt.level === "error" || evt.level === "fatal") && !evt._drop) {
333
+ Segi.replay._captureError({ ts: evt.timestamp || (/* @__PURE__ */ new Date()).toISOString(), url: evt.url });
334
+ }
297
335
  send(state.options.endpoint, state.options.projectKey, evt);
298
336
  } catch (e8) {
299
337
  }
package/dist/index.mjs CHANGED
@@ -178,7 +178,18 @@ function detachListeners() {
178
178
  window.removeEventListener("error", captureWindowError, true);
179
179
  window.removeEventListener("unhandledrejection", captureWindowError, true);
180
180
  }
181
+ var pendingReplayErrors = [];
182
+ var replayEnabled = false;
183
+ var replayEpoch = 0;
181
184
  var noopReplay = {
185
+ _captureError(signal) {
186
+ if (pendingReplayErrors.length < 20) pendingReplayErrors.push(signal);
187
+ },
188
+ _sessionUid() {
189
+ return null;
190
+ },
191
+ _stop() {
192
+ },
182
193
  pause() {
183
194
  },
184
195
  resume() {
@@ -215,14 +226,22 @@ var Segi = {
215
226
  return;
216
227
  }
217
228
  if (state.initialized) detachListeners();
229
+ Segi.replay._stop();
230
+ Segi.replay = noopReplay;
231
+ pendingReplayErrors = [];
232
+ const epoch = ++replayEpoch;
218
233
  const { replay, ...core } = options;
234
+ replayEnabled = !!replay?.__segi_replay && replay.options.enabled !== false;
219
235
  state.options = { ...core };
220
236
  state.initialized = true;
221
237
  if (w) w.__segiInitialized = true;
222
238
  attachListeners();
223
239
  if (replay?.__segi_replay) {
224
240
  void import("./replay/index.mjs").then((mod) => {
241
+ if (epoch !== replayEpoch || !state.initialized) return;
225
242
  Segi.replay = mod.replayApi;
243
+ for (const error of pendingReplayErrors) mod.replayApi._captureError(error);
244
+ pendingReplayErrors = [];
226
245
  if (state.user) {
227
246
  mod.replayApi.setUser({
228
247
  id: state.user.id,
@@ -250,6 +269,11 @@ var Segi = {
250
269
  close() {
251
270
  try {
252
271
  detachListeners();
272
+ replayEpoch++;
273
+ replayEnabled = false;
274
+ Segi.replay._stop();
275
+ Segi.replay = noopReplay;
276
+ pendingReplayErrors = [];
253
277
  state.initialized = false;
254
278
  state.user = null;
255
279
  state.tags = {};
@@ -275,8 +299,15 @@ var Segi = {
275
299
  runtime: "browser",
276
300
  url: context.url ?? (typeof location !== "undefined" ? location.href : void 0),
277
301
  userAgent: context.userAgent ?? (typeof navigator !== "undefined" ? navigator.userAgent : void 0),
278
- ...context
302
+ ...context,
303
+ extra: {
304
+ ...context.extra,
305
+ ...Segi.replay._sessionUid() ? { sessionUid: Segi.replay._sessionUid() } : {}
306
+ }
279
307
  });
308
+ if (replayEnabled && !evt._drop) {
309
+ Segi.replay._captureError({ ts: evt.timestamp || (/* @__PURE__ */ new Date()).toISOString(), url: evt.url });
310
+ }
280
311
  send(state.options.endpoint, state.options.projectKey, evt);
281
312
  } catch {
282
313
  }
@@ -292,8 +323,15 @@ var Segi = {
292
323
  runtime: "browser",
293
324
  url: typeof location !== "undefined" ? location.href : void 0,
294
325
  userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
295
- ...context
326
+ ...context,
327
+ extra: {
328
+ ...context.extra,
329
+ ...Segi.replay._sessionUid() ? { sessionUid: Segi.replay._sessionUid() } : {}
330
+ }
296
331
  });
332
+ if (replayEnabled && (evt.level === "error" || evt.level === "fatal") && !evt._drop) {
333
+ Segi.replay._captureError({ ts: evt.timestamp || (/* @__PURE__ */ new Date()).toISOString(), url: evt.url });
334
+ }
297
335
  send(state.options.endpoint, state.options.projectKey, evt);
298
336
  } catch {
299
337
  }
@@ -30,18 +30,23 @@ import { R as ReplayConfig, a as ReplayOptions } from '../types-CsgcNSc1.mjs';
30
30
  */
31
31
 
32
32
  declare function withReplay(options?: ReplayOptions): ReplayConfig;
33
- /**
34
- * Internal entry-point invoked by Segi.init() when a ReplayConfig was
35
- * passed. Not part of the public surface.
36
- */
37
- declare function activateReplay(args: {
33
+ type ErrorSignal = {
34
+ ts: string;
35
+ url?: string;
36
+ };
37
+ declare function isPathBlocked(opts: ReplayOptions, path: string): boolean;
38
+ type Activation = {
38
39
  projectKey: string;
39
- /** Optional — replay transport defaults to https://segiapi.extn.ai. */
40
40
  endpoint?: string;
41
41
  config: ReplayConfig;
42
- }): Promise<void>;
42
+ };
43
+ /** Fetch policy before recording. Failure keeps replay off; retry every 30s until configured. */
44
+ declare function activateReplay(args: Activation): Promise<void>;
43
45
  /** Public Segi.replay namespace, attached by the main index.ts. */
44
46
  declare const replayApi: {
47
+ /** Internal bridge from the error SDK; no stack/message is copied to trace. */
48
+ _captureError(signal: ErrorSignal): void;
49
+ _stop(): void;
45
50
  pause(): void;
46
51
  resume(): void;
47
52
  setUser(user: {
@@ -58,4 +63,4 @@ declare const replayApi: {
58
63
  _sessionUid(): string | null;
59
64
  };
60
65
 
61
- export { ReplayConfig, ReplayOptions, activateReplay, replayApi, withReplay };
66
+ export { ReplayConfig, ReplayOptions, activateReplay, isPathBlocked, replayApi, withReplay };
@@ -30,18 +30,23 @@ import { R as ReplayConfig, a as ReplayOptions } from '../types-CsgcNSc1.js';
30
30
  */
31
31
 
32
32
  declare function withReplay(options?: ReplayOptions): ReplayConfig;
33
- /**
34
- * Internal entry-point invoked by Segi.init() when a ReplayConfig was
35
- * passed. Not part of the public surface.
36
- */
37
- declare function activateReplay(args: {
33
+ type ErrorSignal = {
34
+ ts: string;
35
+ url?: string;
36
+ };
37
+ declare function isPathBlocked(opts: ReplayOptions, path: string): boolean;
38
+ type Activation = {
38
39
  projectKey: string;
39
- /** Optional — replay transport defaults to https://segiapi.extn.ai. */
40
40
  endpoint?: string;
41
41
  config: ReplayConfig;
42
- }): Promise<void>;
42
+ };
43
+ /** Fetch policy before recording. Failure keeps replay off; retry every 30s until configured. */
44
+ declare function activateReplay(args: Activation): Promise<void>;
43
45
  /** Public Segi.replay namespace, attached by the main index.ts. */
44
46
  declare const replayApi: {
47
+ /** Internal bridge from the error SDK; no stack/message is copied to trace. */
48
+ _captureError(signal: ErrorSignal): void;
49
+ _stop(): void;
45
50
  pause(): void;
46
51
  resume(): void;
47
52
  setUser(user: {
@@ -58,4 +63,4 @@ declare const replayApi: {
58
63
  _sessionUid(): string | null;
59
64
  };
60
65
 
61
- export { ReplayConfig, ReplayOptions, activateReplay, replayApi, withReplay };
66
+ export { ReplayConfig, ReplayOptions, activateReplay, isPathBlocked, replayApi, withReplay };