@extn/segi-js 0.2.17 → 0.2.18
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/README.md +186 -58
- package/dist/cdn.global.js +37 -37
- package/dist/chunk-USYEDAPQ.js +41 -0
- package/dist/chunk-YOSYA5HJ.mjs +41 -0
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +41 -8
- package/dist/index.mjs +40 -7
- package/dist/replay/index.d.mts +10 -2
- package/dist/replay/index.d.ts +10 -2
- package/dist/replay/index.js +48 -14
- package/dist/replay/index.mjs +40 -6
- package/dist/{types-CsgcNSc1.d.mts → types-BU4h40xl.d.mts} +10 -1
- package/dist/{types-CsgcNSc1.d.ts → types-BU4h40xl.d.ts} +10 -1
- package/package.json +3 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/replay/token.ts
|
|
2
|
+
function withReplay(options = {}) {
|
|
3
|
+
return { __segi_replay: true, options };
|
|
4
|
+
}
|
|
5
|
+
function isObject(v) {
|
|
6
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7
|
+
}
|
|
8
|
+
function sanitizeReplayOptions(raw) {
|
|
9
|
+
if (!isObject(raw)) return {};
|
|
10
|
+
const out = {};
|
|
11
|
+
if (typeof raw.enabled === "boolean") out.enabled = raw.enabled;
|
|
12
|
+
const sample = typeof raw.sample === "string" ? Number(raw.sample) : raw.sample;
|
|
13
|
+
if (typeof sample === "number" && Number.isFinite(sample)) out.sample = sample;
|
|
14
|
+
if (Array.isArray(raw.blockRoutes)) {
|
|
15
|
+
out.blockRoutes = raw.blockRoutes.filter((p) => typeof p === "string");
|
|
16
|
+
}
|
|
17
|
+
if (isObject(raw.mask)) {
|
|
18
|
+
const mask = {};
|
|
19
|
+
if (raw.mask.inputs === "all" || raw.mask.inputs === "sensitive" || raw.mask.inputs === "none") {
|
|
20
|
+
mask.inputs = raw.mask.inputs;
|
|
21
|
+
}
|
|
22
|
+
if (typeof raw.mask.class === "string") mask.class = raw.mask.class;
|
|
23
|
+
out.mask = mask;
|
|
24
|
+
}
|
|
25
|
+
if (typeof raw.endpoint === "string" && raw.endpoint) out.endpoint = raw.endpoint;
|
|
26
|
+
if (typeof raw.trackRoutes === "boolean") out.trackRoutes = raw.trackRoutes;
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function normalizeReplayToken(value) {
|
|
30
|
+
try {
|
|
31
|
+
if (!isObject(value) || value.__segi_replay !== true) return null;
|
|
32
|
+
return withReplay(sanitizeReplayOptions(value.options));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
exports.withReplay = withReplay; exports.normalizeReplayToken = normalizeReplayToken;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/replay/token.ts
|
|
2
|
+
function withReplay(options = {}) {
|
|
3
|
+
return { __segi_replay: true, options };
|
|
4
|
+
}
|
|
5
|
+
function isObject(v) {
|
|
6
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
7
|
+
}
|
|
8
|
+
function sanitizeReplayOptions(raw) {
|
|
9
|
+
if (!isObject(raw)) return {};
|
|
10
|
+
const out = {};
|
|
11
|
+
if (typeof raw.enabled === "boolean") out.enabled = raw.enabled;
|
|
12
|
+
const sample = typeof raw.sample === "string" ? Number(raw.sample) : raw.sample;
|
|
13
|
+
if (typeof sample === "number" && Number.isFinite(sample)) out.sample = sample;
|
|
14
|
+
if (Array.isArray(raw.blockRoutes)) {
|
|
15
|
+
out.blockRoutes = raw.blockRoutes.filter((p) => typeof p === "string");
|
|
16
|
+
}
|
|
17
|
+
if (isObject(raw.mask)) {
|
|
18
|
+
const mask = {};
|
|
19
|
+
if (raw.mask.inputs === "all" || raw.mask.inputs === "sensitive" || raw.mask.inputs === "none") {
|
|
20
|
+
mask.inputs = raw.mask.inputs;
|
|
21
|
+
}
|
|
22
|
+
if (typeof raw.mask.class === "string") mask.class = raw.mask.class;
|
|
23
|
+
out.mask = mask;
|
|
24
|
+
}
|
|
25
|
+
if (typeof raw.endpoint === "string" && raw.endpoint) out.endpoint = raw.endpoint;
|
|
26
|
+
if (typeof raw.trackRoutes === "boolean") out.trackRoutes = raw.trackRoutes;
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function normalizeReplayToken(value) {
|
|
30
|
+
try {
|
|
31
|
+
if (!isObject(value) || value.__segi_replay !== true) return null;
|
|
32
|
+
return withReplay(sanitizeReplayOptions(value.options));
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
withReplay,
|
|
40
|
+
normalizeReplayToken
|
|
41
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SegiClientOptions, SegiEventDto, SegiUser, SegiBreadcrumb } from '@extn/segi-shared';
|
|
2
2
|
export { SegiBreadcrumb, SegiClientOptions, SegiEventDto, SegiUser } from '@extn/segi-shared';
|
|
3
|
-
import { R as ReplayConfig } from './types-
|
|
3
|
+
import { R as ReplayConfig, a as ReplayOptions } from './types-BU4h40xl.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Turn whatever `captureException` was handed into an Error worth reporting,
|
|
@@ -69,6 +69,12 @@ declare const Segi: {
|
|
|
69
69
|
* the duplicate-init warning.
|
|
70
70
|
*/
|
|
71
71
|
init(options: SegiInitOptions, opts?: InitOptions): void;
|
|
72
|
+
/**
|
|
73
|
+
* Build the replay activation token for `Segi.init({ replay })`. Same as
|
|
74
|
+
* `withReplay` from `@extn/segi-js/replay`; on the CDN global it defaults
|
|
75
|
+
* `trackRoutes` to true.
|
|
76
|
+
*/
|
|
77
|
+
withReplay(options?: ReplayOptions): ReplayConfig;
|
|
72
78
|
/** True if init() has been called successfully on this bundle. */
|
|
73
79
|
isInitialized(): boolean;
|
|
74
80
|
/** Tear down listeners and reset state. Mostly for tests / hot-reload. */
|
|
@@ -80,4 +86,4 @@ declare const Segi: {
|
|
|
80
86
|
addBreadcrumb(breadcrumb: SegiBreadcrumb): void;
|
|
81
87
|
};
|
|
82
88
|
|
|
83
|
-
export { type InitOptions, Segi, type SegiInitOptions, Segi as default, normalizeError };
|
|
89
|
+
export { type InitOptions, ReplayConfig, ReplayOptions, Segi, type SegiInitOptions, Segi as default, normalizeError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SegiClientOptions, SegiEventDto, SegiUser, SegiBreadcrumb } from '@extn/segi-shared';
|
|
2
2
|
export { SegiBreadcrumb, SegiClientOptions, SegiEventDto, SegiUser } from '@extn/segi-shared';
|
|
3
|
-
import { R as ReplayConfig } from './types-
|
|
3
|
+
import { R as ReplayConfig, a as ReplayOptions } from './types-BU4h40xl.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Turn whatever `captureException` was handed into an Error worth reporting,
|
|
@@ -69,6 +69,12 @@ declare const Segi: {
|
|
|
69
69
|
* the duplicate-init warning.
|
|
70
70
|
*/
|
|
71
71
|
init(options: SegiInitOptions, opts?: InitOptions): void;
|
|
72
|
+
/**
|
|
73
|
+
* Build the replay activation token for `Segi.init({ replay })`. Same as
|
|
74
|
+
* `withReplay` from `@extn/segi-js/replay`; on the CDN global it defaults
|
|
75
|
+
* `trackRoutes` to true.
|
|
76
|
+
*/
|
|
77
|
+
withReplay(options?: ReplayOptions): ReplayConfig;
|
|
72
78
|
/** True if init() has been called successfully on this bundle. */
|
|
73
79
|
isInitialized(): boolean;
|
|
74
80
|
/** Tear down listeners and reset state. Mostly for tests / hot-reload. */
|
|
@@ -80,4 +86,4 @@ declare const Segi: {
|
|
|
80
86
|
addBreadcrumb(breadcrumb: SegiBreadcrumb): void;
|
|
81
87
|
};
|
|
82
88
|
|
|
83
|
-
export { type InitOptions, Segi, type SegiInitOptions, Segi as default, normalizeError };
|
|
89
|
+
export { type InitOptions, ReplayConfig, ReplayOptions, Segi, type SegiInitOptions, Segi as default, normalizeError };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkUSYEDAPQjs = require('./chunk-USYEDAPQ.js');
|
|
5
|
+
|
|
6
|
+
// src/core.ts
|
|
2
7
|
var DEFAULT_MAX_BREADCRUMBS = 50;
|
|
3
8
|
function createState() {
|
|
4
9
|
return {
|
|
@@ -278,6 +283,7 @@ function detachListeners() {
|
|
|
278
283
|
}
|
|
279
284
|
var pendingReplayErrors = [];
|
|
280
285
|
var replayEnabled = false;
|
|
286
|
+
var replayRequested = false;
|
|
281
287
|
var replayEpoch = 0;
|
|
282
288
|
var noopReplay = {
|
|
283
289
|
_captureError(signal) {
|
|
@@ -314,12 +320,25 @@ var Segi = {
|
|
|
314
320
|
init(options, opts = {}) {
|
|
315
321
|
try {
|
|
316
322
|
const w = typeof window !== "undefined" ? window : null;
|
|
323
|
+
if (!options || options.enabled === false) {
|
|
324
|
+
if (opts.force && state.initialized) Segi.close();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const replay = _chunkUSYEDAPQjs.normalizeReplayToken.call(void 0, options.replay);
|
|
328
|
+
const wantsReplay = !!replay && replay.options.enabled !== false;
|
|
317
329
|
const already = state.initialized || _optionalChain([w, 'optionalAccess', _2 => _2.__segiInitialized]) === true;
|
|
318
330
|
if (already && !opts.force) {
|
|
319
331
|
if (!opts.silent && typeof console !== "undefined") {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
332
|
+
const firstHadReplay = state.initialized ? replayRequested : _optionalChain([w, 'optionalAccess', _3 => _3.__segiReplayRequested]) === true;
|
|
333
|
+
if (wantsReplay && !firstHadReplay) {
|
|
334
|
+
console.warn(
|
|
335
|
+
`[segi] init() was already called WITHOUT session replay (first init wins \u2014 often the CDN auto-init from window.SegiConfig or the script's data-project-key), so the replay option of this call was ignored and nothing is being recorded. Fix: enable replay in that first init (window.SegiConfig = { projectKey, replay: true } or data-replay="true" on the script tag) and drop this call, or call Segi.init({...}, { force: true }) to replace the first init.`
|
|
336
|
+
);
|
|
337
|
+
} else {
|
|
338
|
+
console.warn(
|
|
339
|
+
"[segi] init() called more than once; ignoring. Pass { force: true } to override."
|
|
340
|
+
);
|
|
341
|
+
}
|
|
323
342
|
}
|
|
324
343
|
return;
|
|
325
344
|
}
|
|
@@ -328,13 +347,17 @@ var Segi = {
|
|
|
328
347
|
Segi.replay = noopReplay;
|
|
329
348
|
pendingReplayErrors = [];
|
|
330
349
|
const epoch = ++replayEpoch;
|
|
331
|
-
const { replay, ...core } = options;
|
|
332
|
-
replayEnabled =
|
|
350
|
+
const { replay: _ignored, ...core } = options;
|
|
351
|
+
replayEnabled = wantsReplay;
|
|
352
|
+
replayRequested = wantsReplay;
|
|
333
353
|
state.options = { ...core };
|
|
334
354
|
state.initialized = true;
|
|
335
|
-
if (w)
|
|
355
|
+
if (w) {
|
|
356
|
+
w.__segiInitialized = true;
|
|
357
|
+
w.__segiReplayRequested = wantsReplay;
|
|
358
|
+
}
|
|
336
359
|
attachListeners();
|
|
337
|
-
if (
|
|
360
|
+
if (replay && wantsReplay) {
|
|
338
361
|
void Promise.resolve().then(() => _interopRequireWildcard(require("./replay/index.js"))).then((mod) => {
|
|
339
362
|
if (epoch !== replayEpoch || !state.initialized) return;
|
|
340
363
|
Segi.replay = mod.replayApi;
|
|
@@ -359,6 +382,14 @@ var Segi = {
|
|
|
359
382
|
} catch (e11) {
|
|
360
383
|
}
|
|
361
384
|
},
|
|
385
|
+
/**
|
|
386
|
+
* Build the replay activation token for `Segi.init({ replay })`. Same as
|
|
387
|
+
* `withReplay` from `@extn/segi-js/replay`; on the CDN global it defaults
|
|
388
|
+
* `trackRoutes` to true.
|
|
389
|
+
*/
|
|
390
|
+
withReplay(options = {}) {
|
|
391
|
+
return _chunkUSYEDAPQjs.withReplay.call(void 0, options);
|
|
392
|
+
},
|
|
362
393
|
/** True if init() has been called successfully on this bundle. */
|
|
363
394
|
isInitialized() {
|
|
364
395
|
return state.initialized;
|
|
@@ -369,6 +400,7 @@ var Segi = {
|
|
|
369
400
|
detachListeners();
|
|
370
401
|
replayEpoch++;
|
|
371
402
|
replayEnabled = false;
|
|
403
|
+
replayRequested = false;
|
|
372
404
|
Segi.replay._stop();
|
|
373
405
|
Segi.replay = noopReplay;
|
|
374
406
|
pendingReplayErrors = [];
|
|
@@ -379,6 +411,7 @@ var Segi = {
|
|
|
379
411
|
if (typeof window !== "undefined") {
|
|
380
412
|
const w = window;
|
|
381
413
|
w.__segiInitialized = false;
|
|
414
|
+
w.__segiReplayRequested = false;
|
|
382
415
|
}
|
|
383
416
|
} catch (e12) {
|
|
384
417
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeReplayToken,
|
|
3
|
+
withReplay
|
|
4
|
+
} from "./chunk-YOSYA5HJ.mjs";
|
|
5
|
+
|
|
1
6
|
// src/core.ts
|
|
2
7
|
var DEFAULT_MAX_BREADCRUMBS = 50;
|
|
3
8
|
function createState() {
|
|
@@ -278,6 +283,7 @@ function detachListeners() {
|
|
|
278
283
|
}
|
|
279
284
|
var pendingReplayErrors = [];
|
|
280
285
|
var replayEnabled = false;
|
|
286
|
+
var replayRequested = false;
|
|
281
287
|
var replayEpoch = 0;
|
|
282
288
|
var noopReplay = {
|
|
283
289
|
_captureError(signal) {
|
|
@@ -314,12 +320,25 @@ var Segi = {
|
|
|
314
320
|
init(options, opts = {}) {
|
|
315
321
|
try {
|
|
316
322
|
const w = typeof window !== "undefined" ? window : null;
|
|
323
|
+
if (!options || options.enabled === false) {
|
|
324
|
+
if (opts.force && state.initialized) Segi.close();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const replay = normalizeReplayToken(options.replay);
|
|
328
|
+
const wantsReplay = !!replay && replay.options.enabled !== false;
|
|
317
329
|
const already = state.initialized || w?.__segiInitialized === true;
|
|
318
330
|
if (already && !opts.force) {
|
|
319
331
|
if (!opts.silent && typeof console !== "undefined") {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
332
|
+
const firstHadReplay = state.initialized ? replayRequested : w?.__segiReplayRequested === true;
|
|
333
|
+
if (wantsReplay && !firstHadReplay) {
|
|
334
|
+
console.warn(
|
|
335
|
+
`[segi] init() was already called WITHOUT session replay (first init wins \u2014 often the CDN auto-init from window.SegiConfig or the script's data-project-key), so the replay option of this call was ignored and nothing is being recorded. Fix: enable replay in that first init (window.SegiConfig = { projectKey, replay: true } or data-replay="true" on the script tag) and drop this call, or call Segi.init({...}, { force: true }) to replace the first init.`
|
|
336
|
+
);
|
|
337
|
+
} else {
|
|
338
|
+
console.warn(
|
|
339
|
+
"[segi] init() called more than once; ignoring. Pass { force: true } to override."
|
|
340
|
+
);
|
|
341
|
+
}
|
|
323
342
|
}
|
|
324
343
|
return;
|
|
325
344
|
}
|
|
@@ -328,13 +347,17 @@ var Segi = {
|
|
|
328
347
|
Segi.replay = noopReplay;
|
|
329
348
|
pendingReplayErrors = [];
|
|
330
349
|
const epoch = ++replayEpoch;
|
|
331
|
-
const { replay, ...core } = options;
|
|
332
|
-
replayEnabled =
|
|
350
|
+
const { replay: _ignored, ...core } = options;
|
|
351
|
+
replayEnabled = wantsReplay;
|
|
352
|
+
replayRequested = wantsReplay;
|
|
333
353
|
state.options = { ...core };
|
|
334
354
|
state.initialized = true;
|
|
335
|
-
if (w)
|
|
355
|
+
if (w) {
|
|
356
|
+
w.__segiInitialized = true;
|
|
357
|
+
w.__segiReplayRequested = wantsReplay;
|
|
358
|
+
}
|
|
336
359
|
attachListeners();
|
|
337
|
-
if (replay
|
|
360
|
+
if (replay && wantsReplay) {
|
|
338
361
|
void import("./replay/index.mjs").then((mod) => {
|
|
339
362
|
if (epoch !== replayEpoch || !state.initialized) return;
|
|
340
363
|
Segi.replay = mod.replayApi;
|
|
@@ -359,6 +382,14 @@ var Segi = {
|
|
|
359
382
|
} catch {
|
|
360
383
|
}
|
|
361
384
|
},
|
|
385
|
+
/**
|
|
386
|
+
* Build the replay activation token for `Segi.init({ replay })`. Same as
|
|
387
|
+
* `withReplay` from `@extn/segi-js/replay`; on the CDN global it defaults
|
|
388
|
+
* `trackRoutes` to true.
|
|
389
|
+
*/
|
|
390
|
+
withReplay(options = {}) {
|
|
391
|
+
return withReplay(options);
|
|
392
|
+
},
|
|
362
393
|
/** True if init() has been called successfully on this bundle. */
|
|
363
394
|
isInitialized() {
|
|
364
395
|
return state.initialized;
|
|
@@ -369,6 +400,7 @@ var Segi = {
|
|
|
369
400
|
detachListeners();
|
|
370
401
|
replayEpoch++;
|
|
371
402
|
replayEnabled = false;
|
|
403
|
+
replayRequested = false;
|
|
372
404
|
Segi.replay._stop();
|
|
373
405
|
Segi.replay = noopReplay;
|
|
374
406
|
pendingReplayErrors = [];
|
|
@@ -379,6 +411,7 @@ var Segi = {
|
|
|
379
411
|
if (typeof window !== "undefined") {
|
|
380
412
|
const w = window;
|
|
381
413
|
w.__segiInitialized = false;
|
|
414
|
+
w.__segiReplayRequested = false;
|
|
382
415
|
}
|
|
383
416
|
} catch {
|
|
384
417
|
}
|
package/dist/replay/index.d.mts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ReplayOptions, R as ReplayConfig } from '../types-BU4h40xl.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replay activation token helpers. Kept separate from ./index so the main
|
|
5
|
+
* entry can build/validate tokens without statically importing the replay
|
|
6
|
+
* runtime (which stays behind a dynamic import).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Build the replay activation token passed as `Segi.init({ replay })`. */
|
|
10
|
+
declare function withReplay(options?: ReplayOptions): ReplayConfig;
|
|
2
11
|
|
|
3
12
|
/**
|
|
4
13
|
* Replay orchestrator. Exposed at `@extn/segi-js/replay`.
|
|
@@ -29,7 +38,6 @@ import { R as ReplayConfig, a as ReplayOptions } from '../types-CsgcNSc1.mjs';
|
|
|
29
38
|
* in pay zero rrweb bytes. Chunks POST to /api/trace/replay.
|
|
30
39
|
*/
|
|
31
40
|
|
|
32
|
-
declare function withReplay(options?: ReplayOptions): ReplayConfig;
|
|
33
41
|
type ErrorSignal = {
|
|
34
42
|
ts: string;
|
|
35
43
|
url?: string;
|
package/dist/replay/index.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ReplayOptions, R as ReplayConfig } from '../types-BU4h40xl.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replay activation token helpers. Kept separate from ./index so the main
|
|
5
|
+
* entry can build/validate tokens without statically importing the replay
|
|
6
|
+
* runtime (which stays behind a dynamic import).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Build the replay activation token passed as `Segi.init({ replay })`. */
|
|
10
|
+
declare function withReplay(options?: ReplayOptions): ReplayConfig;
|
|
2
11
|
|
|
3
12
|
/**
|
|
4
13
|
* Replay orchestrator. Exposed at `@extn/segi-js/replay`.
|
|
@@ -29,7 +38,6 @@ import { R as ReplayConfig, a as ReplayOptions } from '../types-CsgcNSc1.js';
|
|
|
29
38
|
* in pay zero rrweb bytes. Chunks POST to /api/trace/replay.
|
|
30
39
|
*/
|
|
31
40
|
|
|
32
|
-
declare function withReplay(options?: ReplayOptions): ReplayConfig;
|
|
33
41
|
type ErrorSignal = {
|
|
34
42
|
ts: string;
|
|
35
43
|
url?: string;
|
package/dist/replay/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkUSYEDAPQjs = require('../chunk-USYEDAPQ.js');
|
|
4
|
+
|
|
5
|
+
// src/replay/session.ts
|
|
2
6
|
var UID_KEY = "_bd_session_uid";
|
|
3
7
|
var UID_TS_KEY = "_bd_session_at";
|
|
4
8
|
var ANON_KEY = "_bd_anon";
|
|
@@ -122,9 +126,6 @@ function beaconTrace(cfg, path, body) {
|
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
// src/replay/index.ts
|
|
125
|
-
function withReplay(options = {}) {
|
|
126
|
-
return { __segi_replay: true, options };
|
|
127
|
-
}
|
|
128
129
|
async function gzipString(str) {
|
|
129
130
|
try {
|
|
130
131
|
if (typeof CompressionStream === "undefined") return null;
|
|
@@ -167,6 +168,10 @@ function sendError(signal) {
|
|
|
167
168
|
}] });
|
|
168
169
|
}
|
|
169
170
|
var pendingUser = void 0;
|
|
171
|
+
var lastPageViewUrl = null;
|
|
172
|
+
function pageKey(url) {
|
|
173
|
+
return url.split("#")[0];
|
|
174
|
+
}
|
|
170
175
|
function deviceClass() {
|
|
171
176
|
if (typeof window === "undefined") return "desktop";
|
|
172
177
|
const w = window.innerWidth;
|
|
@@ -213,24 +218,47 @@ async function activateReplay(args) {
|
|
|
213
218
|
const epoch = activationEpoch;
|
|
214
219
|
const suspendExcluded = () => {
|
|
215
220
|
if (active && !pathAllowed()) {
|
|
221
|
+
lastPageViewUrl = null;
|
|
216
222
|
active.routePaused = true;
|
|
217
223
|
active.paused = true;
|
|
218
224
|
_optionalChain([active, 'access', _2 => _2.rrweb, 'optionalAccess', _3 => _3.pause, 'call', _4 => _4()]);
|
|
219
225
|
}
|
|
220
226
|
};
|
|
227
|
+
let routeTimer = null;
|
|
228
|
+
let routeTracking = args.config.options.trackRoutes === true;
|
|
229
|
+
const trackRoute = () => {
|
|
230
|
+
if (!routeTracking) return;
|
|
231
|
+
if (routeTimer) clearTimeout(routeTimer);
|
|
232
|
+
routeTimer = setTimeout(() => {
|
|
233
|
+
routeTimer = null;
|
|
234
|
+
if (!routeTracking) return;
|
|
235
|
+
try {
|
|
236
|
+
replayApi.notifyRouteChange();
|
|
237
|
+
} catch (e12) {
|
|
238
|
+
}
|
|
239
|
+
}, 100);
|
|
240
|
+
};
|
|
241
|
+
cleanup.push(() => {
|
|
242
|
+
routeTracking = false;
|
|
243
|
+
if (routeTimer) clearTimeout(routeTimer);
|
|
244
|
+
});
|
|
245
|
+
const onHistoryChange = () => {
|
|
246
|
+
suspendExcluded();
|
|
247
|
+
trackRoute();
|
|
248
|
+
};
|
|
221
249
|
for (const method of ["pushState", "replaceState"]) {
|
|
222
250
|
const original = history[method];
|
|
223
251
|
const wrapped = function(...params) {
|
|
224
252
|
original.apply(this, params);
|
|
225
|
-
|
|
253
|
+
onHistoryChange();
|
|
226
254
|
};
|
|
227
255
|
history[method] = wrapped;
|
|
228
256
|
cleanup.push(() => {
|
|
229
257
|
if (history[method] === wrapped) history[method] = original;
|
|
230
258
|
});
|
|
231
259
|
}
|
|
232
|
-
window.addEventListener("popstate",
|
|
233
|
-
cleanup.push(() => window.removeEventListener("popstate",
|
|
260
|
+
window.addEventListener("popstate", onHistoryChange);
|
|
261
|
+
cleanup.push(() => window.removeEventListener("popstate", onHistoryChange));
|
|
234
262
|
let inFlight = false;
|
|
235
263
|
const load = async () => {
|
|
236
264
|
if (inFlight || configured || epoch !== activationEpoch) return;
|
|
@@ -244,7 +272,7 @@ async function activateReplay(args) {
|
|
|
244
272
|
if (epoch !== activationEpoch || typeof policy.recordingEnabled !== "boolean" || !Array.isArray(policy.recordingDenyList) || policy.recordingDenyList.some((p) => typeof p !== "string" || !p.startsWith("/"))) return;
|
|
245
273
|
configured = true;
|
|
246
274
|
clearInterval(timer);
|
|
247
|
-
waiting = { ...args, config: withReplay({
|
|
275
|
+
waiting = { ...args, config: _chunkUSYEDAPQjs.withReplay.call(void 0, {
|
|
248
276
|
...args.config.options,
|
|
249
277
|
blockRoutes: [..._nullishCoalesce(args.config.options.blockRoutes, () => ( [])), ...policy.recordingDenyList]
|
|
250
278
|
}) };
|
|
@@ -255,12 +283,12 @@ async function activateReplay(args) {
|
|
|
255
283
|
pendingErrors = pendingErrors.filter((e) => {
|
|
256
284
|
try {
|
|
257
285
|
return !isPathBlocked(waiting.config.options, new URL(_nullishCoalesce(e.url, () => ( location.href)), location.href).pathname);
|
|
258
|
-
} catch (
|
|
286
|
+
} catch (e13) {
|
|
259
287
|
return false;
|
|
260
288
|
}
|
|
261
289
|
});
|
|
262
290
|
await startWhenAllowed();
|
|
263
|
-
} catch (
|
|
291
|
+
} catch (e14) {
|
|
264
292
|
} finally {
|
|
265
293
|
clearTimeout(timeout);
|
|
266
294
|
inFlight = false;
|
|
@@ -325,7 +353,7 @@ async function startReplay(args) {
|
|
|
325
353
|
const body = await res.json().catch(() => ({}));
|
|
326
354
|
recordingEnabled = body.recordingEnabled === true;
|
|
327
355
|
}
|
|
328
|
-
} catch (
|
|
356
|
+
} catch (e15) {
|
|
329
357
|
}
|
|
330
358
|
if (epoch !== activationEpoch) return;
|
|
331
359
|
if (!recordingEnabled) {
|
|
@@ -420,7 +448,7 @@ async function startReplay(args) {
|
|
|
420
448
|
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
421
449
|
navigator.sendBeacon(url, blob);
|
|
422
450
|
}
|
|
423
|
-
} catch (
|
|
451
|
+
} catch (e16) {
|
|
424
452
|
}
|
|
425
453
|
return;
|
|
426
454
|
}
|
|
@@ -445,7 +473,7 @@ async function startReplay(args) {
|
|
|
445
473
|
active.rrweb = null;
|
|
446
474
|
}
|
|
447
475
|
}
|
|
448
|
-
} catch (
|
|
476
|
+
} catch (e17) {
|
|
449
477
|
}
|
|
450
478
|
}
|
|
451
479
|
}).then(resolve, () => resolve(null));
|
|
@@ -458,6 +486,7 @@ async function startReplay(args) {
|
|
|
458
486
|
} else _optionalChain([handles, 'optionalAccess', _12 => _12.stop, 'call', _13 => _13()]);
|
|
459
487
|
}).catch(() => {
|
|
460
488
|
});
|
|
489
|
+
if (canCollect()) lastPageViewUrl = pageKey(location.href);
|
|
461
490
|
if (canCollect()) void postTrace(transportCfg, "/events", {
|
|
462
491
|
events: [
|
|
463
492
|
{
|
|
@@ -522,6 +551,7 @@ var replayApi = {
|
|
|
522
551
|
active = null;
|
|
523
552
|
pendingErrors = [];
|
|
524
553
|
pendingUser = void 0;
|
|
554
|
+
lastPageViewUrl = null;
|
|
525
555
|
},
|
|
526
556
|
pause() {
|
|
527
557
|
manualPaused = true;
|
|
@@ -580,6 +610,7 @@ var replayApi = {
|
|
|
580
610
|
bumpSessionActivity();
|
|
581
611
|
const nowBlocked = isPathBlocked(active.options, location.pathname);
|
|
582
612
|
if (nowBlocked) {
|
|
613
|
+
lastPageViewUrl = null;
|
|
583
614
|
active.routePaused = true;
|
|
584
615
|
if (!active.paused) {
|
|
585
616
|
_optionalChain([active, 'access', _37 => _37.rrweb, 'optionalAccess', _38 => _38.pause, 'call', _39 => _39()]);
|
|
@@ -594,6 +625,9 @@ var replayApi = {
|
|
|
594
625
|
_optionalChain([active, 'access', _40 => _40.rrweb, 'optionalAccess', _41 => _41.resume, 'call', _42 => _42()]);
|
|
595
626
|
if (pendingUser !== void 0) replayApi.setUser(pendingUser);
|
|
596
627
|
}
|
|
628
|
+
const key = pageKey(_nullishCoalesce(url, () => ( location.href)));
|
|
629
|
+
if (key === lastPageViewUrl) return;
|
|
630
|
+
lastPageViewUrl = key;
|
|
597
631
|
active.pagesVisited += 1;
|
|
598
632
|
saveProgress();
|
|
599
633
|
_optionalChain([active, 'access', _43 => _43.rrweb, 'optionalAccess', _44 => _44.takeFullSnapshot, 'call', _45 => _45()]);
|
|
@@ -619,4 +653,4 @@ var replayApi = {
|
|
|
619
653
|
|
|
620
654
|
|
|
621
655
|
|
|
622
|
-
exports.activateReplay = activateReplay; exports.isPathBlocked = isPathBlocked; exports.replayApi = replayApi; exports.withReplay = withReplay;
|
|
656
|
+
exports.activateReplay = activateReplay; exports.isPathBlocked = isPathBlocked; exports.replayApi = replayApi; exports.withReplay = _chunkUSYEDAPQjs.withReplay;
|
package/dist/replay/index.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withReplay
|
|
3
|
+
} from "../chunk-YOSYA5HJ.mjs";
|
|
4
|
+
|
|
1
5
|
// src/replay/session.ts
|
|
2
6
|
var UID_KEY = "_bd_session_uid";
|
|
3
7
|
var UID_TS_KEY = "_bd_session_at";
|
|
@@ -122,9 +126,6 @@ function beaconTrace(cfg, path, body) {
|
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
// src/replay/index.ts
|
|
125
|
-
function withReplay(options = {}) {
|
|
126
|
-
return { __segi_replay: true, options };
|
|
127
|
-
}
|
|
128
129
|
async function gzipString(str) {
|
|
129
130
|
try {
|
|
130
131
|
if (typeof CompressionStream === "undefined") return null;
|
|
@@ -167,6 +168,10 @@ function sendError(signal) {
|
|
|
167
168
|
}] });
|
|
168
169
|
}
|
|
169
170
|
var pendingUser = void 0;
|
|
171
|
+
var lastPageViewUrl = null;
|
|
172
|
+
function pageKey(url) {
|
|
173
|
+
return url.split("#")[0];
|
|
174
|
+
}
|
|
170
175
|
function deviceClass() {
|
|
171
176
|
if (typeof window === "undefined") return "desktop";
|
|
172
177
|
const w = window.innerWidth;
|
|
@@ -213,24 +218,47 @@ async function activateReplay(args) {
|
|
|
213
218
|
const epoch = activationEpoch;
|
|
214
219
|
const suspendExcluded = () => {
|
|
215
220
|
if (active && !pathAllowed()) {
|
|
221
|
+
lastPageViewUrl = null;
|
|
216
222
|
active.routePaused = true;
|
|
217
223
|
active.paused = true;
|
|
218
224
|
active.rrweb?.pause();
|
|
219
225
|
}
|
|
220
226
|
};
|
|
227
|
+
let routeTimer = null;
|
|
228
|
+
let routeTracking = args.config.options.trackRoutes === true;
|
|
229
|
+
const trackRoute = () => {
|
|
230
|
+
if (!routeTracking) return;
|
|
231
|
+
if (routeTimer) clearTimeout(routeTimer);
|
|
232
|
+
routeTimer = setTimeout(() => {
|
|
233
|
+
routeTimer = null;
|
|
234
|
+
if (!routeTracking) return;
|
|
235
|
+
try {
|
|
236
|
+
replayApi.notifyRouteChange();
|
|
237
|
+
} catch {
|
|
238
|
+
}
|
|
239
|
+
}, 100);
|
|
240
|
+
};
|
|
241
|
+
cleanup.push(() => {
|
|
242
|
+
routeTracking = false;
|
|
243
|
+
if (routeTimer) clearTimeout(routeTimer);
|
|
244
|
+
});
|
|
245
|
+
const onHistoryChange = () => {
|
|
246
|
+
suspendExcluded();
|
|
247
|
+
trackRoute();
|
|
248
|
+
};
|
|
221
249
|
for (const method of ["pushState", "replaceState"]) {
|
|
222
250
|
const original = history[method];
|
|
223
251
|
const wrapped = function(...params) {
|
|
224
252
|
original.apply(this, params);
|
|
225
|
-
|
|
253
|
+
onHistoryChange();
|
|
226
254
|
};
|
|
227
255
|
history[method] = wrapped;
|
|
228
256
|
cleanup.push(() => {
|
|
229
257
|
if (history[method] === wrapped) history[method] = original;
|
|
230
258
|
});
|
|
231
259
|
}
|
|
232
|
-
window.addEventListener("popstate",
|
|
233
|
-
cleanup.push(() => window.removeEventListener("popstate",
|
|
260
|
+
window.addEventListener("popstate", onHistoryChange);
|
|
261
|
+
cleanup.push(() => window.removeEventListener("popstate", onHistoryChange));
|
|
234
262
|
let inFlight = false;
|
|
235
263
|
const load = async () => {
|
|
236
264
|
if (inFlight || configured || epoch !== activationEpoch) return;
|
|
@@ -458,6 +486,7 @@ async function startReplay(args) {
|
|
|
458
486
|
} else handles?.stop();
|
|
459
487
|
}).catch(() => {
|
|
460
488
|
});
|
|
489
|
+
if (canCollect()) lastPageViewUrl = pageKey(location.href);
|
|
461
490
|
if (canCollect()) void postTrace(transportCfg, "/events", {
|
|
462
491
|
events: [
|
|
463
492
|
{
|
|
@@ -522,6 +551,7 @@ var replayApi = {
|
|
|
522
551
|
active = null;
|
|
523
552
|
pendingErrors = [];
|
|
524
553
|
pendingUser = void 0;
|
|
554
|
+
lastPageViewUrl = null;
|
|
525
555
|
},
|
|
526
556
|
pause() {
|
|
527
557
|
manualPaused = true;
|
|
@@ -580,6 +610,7 @@ var replayApi = {
|
|
|
580
610
|
bumpSessionActivity();
|
|
581
611
|
const nowBlocked = isPathBlocked(active.options, location.pathname);
|
|
582
612
|
if (nowBlocked) {
|
|
613
|
+
lastPageViewUrl = null;
|
|
583
614
|
active.routePaused = true;
|
|
584
615
|
if (!active.paused) {
|
|
585
616
|
active.rrweb?.pause();
|
|
@@ -594,6 +625,9 @@ var replayApi = {
|
|
|
594
625
|
active.rrweb?.resume();
|
|
595
626
|
if (pendingUser !== void 0) replayApi.setUser(pendingUser);
|
|
596
627
|
}
|
|
628
|
+
const key = pageKey(url ?? location.href);
|
|
629
|
+
if (key === lastPageViewUrl) return;
|
|
630
|
+
lastPageViewUrl = key;
|
|
597
631
|
active.pagesVisited += 1;
|
|
598
632
|
saveProgress();
|
|
599
633
|
active.rrweb?.takeFullSnapshot();
|