@interfere/next 0.0.0-alpha.10 → 0.0.0
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 +1 -0
- package/dist/__tests__/build/with-interfere-coverage.test.d.ts +2 -0
- package/dist/__tests__/build/with-interfere-coverage.test.d.ts.map +1 -0
- package/dist/__tests__/build/with-interfere-coverage.test.js +338 -0
- package/dist/__tests__/build/with-interfere-coverage.test.js.map +1 -0
- package/dist/__tests__/build/with-interfere.test.d.ts +2 -0
- package/dist/__tests__/build/with-interfere.test.d.ts.map +1 -0
- package/dist/__tests__/build/with-interfere.test.js +466 -0
- package/dist/__tests__/build/with-interfere.test.js.map +1 -0
- package/dist/__tests__/core/client.test.d.ts +2 -0
- package/dist/__tests__/core/client.test.d.ts.map +1 -0
- package/dist/__tests__/core/client.test.js +373 -0
- package/dist/__tests__/core/client.test.js.map +1 -0
- package/dist/__tests__/core/debug.test.d.ts +2 -0
- package/dist/__tests__/core/debug.test.d.ts.map +1 -0
- package/dist/__tests__/core/debug.test.js +277 -0
- package/dist/__tests__/core/debug.test.js.map +1 -0
- package/dist/__tests__/core/encoders.test.d.ts +2 -0
- package/dist/__tests__/core/encoders.test.d.ts.map +1 -0
- package/dist/__tests__/core/encoders.test.js +56 -0
- package/dist/__tests__/core/encoders.test.js.map +1 -0
- package/dist/__tests__/core/persistence.test.d.ts +2 -0
- package/dist/__tests__/core/persistence.test.d.ts.map +1 -0
- package/dist/__tests__/core/persistence.test.js +129 -0
- package/dist/__tests__/core/persistence.test.js.map +1 -0
- package/dist/__tests__/core/rage-click.test.d.ts +2 -0
- package/dist/__tests__/core/rage-click.test.d.ts.map +1 -0
- package/dist/__tests__/core/rage-click.test.js +121 -0
- package/dist/__tests__/core/rage-click.test.js.map +1 -0
- package/dist/__tests__/core/session-manager.test.d.ts +2 -0
- package/dist/__tests__/core/session-manager.test.d.ts.map +1 -0
- package/dist/__tests__/core/session-manager.test.js +1132 -0
- package/dist/__tests__/core/session-manager.test.js.map +1 -0
- package/dist/__tests__/integration/release-upload.test.d.ts +2 -0
- package/dist/__tests__/integration/release-upload.test.d.ts.map +1 -0
- package/dist/__tests__/integration/release-upload.test.js +173 -0
- package/dist/__tests__/integration/release-upload.test.js.map +1 -0
- package/dist/__tests__/react/provider.test.d.ts +2 -0
- package/dist/__tests__/react/provider.test.d.ts.map +1 -0
- package/dist/__tests__/react/provider.test.jsx +166 -0
- package/dist/__tests__/react/provider.test.jsx.map +1 -0
- package/dist/__tests__/session/persistence.test.d.ts +2 -0
- package/dist/__tests__/session/persistence.test.d.ts.map +1 -0
- package/dist/__tests__/session/persistence.test.js +129 -0
- package/dist/__tests__/session/persistence.test.js.map +1 -0
- package/dist/__tests__/session/replay.test.d.ts +2 -0
- package/dist/__tests__/session/replay.test.d.ts.map +1 -0
- package/dist/__tests__/session/replay.test.js +296 -0
- package/dist/__tests__/session/replay.test.js.map +1 -0
- package/dist/__tests__/session/session-summary.test.d.ts +2 -0
- package/dist/__tests__/session/session-summary.test.d.ts.map +1 -0
- package/dist/__tests__/session/session-summary.test.js +763 -0
- package/dist/__tests__/session/session-summary.test.js.map +1 -0
- package/dist/build/index.d.ts +3 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +2 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/with-interfere.d.ts +54 -0
- package/dist/build/with-interfere.d.ts.map +1 -0
- package/dist/build/with-interfere.js +267 -0
- package/dist/build/with-interfere.js.map +1 -0
- package/dist/core/client-core.d.ts +27 -0
- package/dist/core/client-core.d.ts.map +1 -0
- package/dist/core/client-core.js +164 -0
- package/dist/core/client-core.js.map +1 -0
- package/dist/core/client.d.ts +70 -18
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +112 -104
- package/dist/core/client.js.map +1 -1
- package/dist/core/client.test.js +227 -92
- package/dist/core/client.test.js.map +1 -1
- package/dist/core/constants.d.ts +12 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +17 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/debug.d.ts +47 -0
- package/dist/core/debug.d.ts.map +1 -0
- package/dist/core/debug.js +79 -0
- package/dist/core/debug.js.map +1 -0
- package/dist/core/encoders.test.js +20 -19
- package/dist/core/encoders.test.js.map +1 -1
- package/dist/core/error-handlers.d.ts.map +1 -1
- package/dist/core/error-handlers.js +42 -41
- package/dist/core/error-handlers.js.map +1 -1
- package/dist/core/runtime.d.ts +7 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +16 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/next/error-boundary.d.ts +5 -5
- package/dist/next/error-boundary.d.ts.map +1 -1
- package/dist/next/error-boundary.jsx +5 -5
- package/dist/next/middleware.d.ts +1 -1
- package/dist/next/middleware.js +13 -13
- package/dist/persistence/index.d.ts +5 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +67 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/storage.d.ts +5 -0
- package/dist/persistence/storage.d.ts.map +1 -0
- package/dist/persistence/storage.js +67 -0
- package/dist/persistence/storage.js.map +1 -0
- package/dist/react/provider.d.ts +9 -5
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.jsx +33 -10
- package/dist/react/provider.jsx.map +1 -1
- package/dist/session/constants.d.ts +19 -0
- package/dist/session/constants.d.ts.map +1 -0
- package/dist/session/constants.js +34 -0
- package/dist/session/constants.js.map +1 -0
- package/dist/session/persistence.d.ts +58 -0
- package/dist/session/persistence.d.ts.map +1 -0
- package/dist/session/persistence.js +180 -0
- package/dist/session/persistence.js.map +1 -0
- package/dist/session/persistence.test.d.ts +2 -0
- package/dist/session/persistence.test.d.ts.map +1 -0
- package/dist/session/persistence.test.js +129 -0
- package/dist/session/persistence.test.js.map +1 -0
- package/dist/session/rage-click.d.ts +17 -0
- package/dist/session/rage-click.d.ts.map +1 -0
- package/dist/session/rage-click.js +104 -0
- package/dist/session/rage-click.js.map +1 -0
- package/dist/session/rage-click.test.d.ts +2 -0
- package/dist/session/rage-click.test.d.ts.map +1 -0
- package/dist/session/rage-click.test.js +124 -0
- package/dist/session/rage-click.test.js.map +1 -0
- package/dist/session/replay.d.ts +2 -2
- package/dist/session/replay.d.ts.map +1 -1
- package/dist/session/replay.js +57 -24
- package/dist/session/replay.js.map +1 -1
- package/dist/session/session-manager.d.ts +126 -0
- package/dist/session/session-manager.d.ts.map +1 -0
- package/dist/session/session-manager.js +635 -0
- package/dist/session/session-manager.js.map +1 -0
- package/dist/session/session-manager.test.d.ts +2 -0
- package/dist/session/session-manager.test.d.ts.map +1 -0
- package/dist/session/session-manager.test.js +1134 -0
- package/dist/session/session-manager.test.js.map +1 -0
- package/dist/session/session-summary.d.ts +2 -2
- package/dist/session/session-summary.d.ts.map +1 -1
- package/dist/session/session-summary.js +94 -47
- package/dist/session/session-summary.js.map +1 -1
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +67 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/types/storage.d.ts +7 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +2 -0
- package/dist/types/storage.js.map +1 -0
- package/package.json +24 -7
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const createStorage = (storageType) => {
|
|
2
|
+
const memoryStore = {};
|
|
3
|
+
const isSupported = () => {
|
|
4
|
+
if (storageType === "memory") {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (typeof window === "undefined") {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const storage = window[storageType];
|
|
12
|
+
const testKey = "__interfere_test__";
|
|
13
|
+
storage.setItem(testKey, "test");
|
|
14
|
+
storage.removeItem(testKey);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const getStorage = () => {
|
|
22
|
+
if (storageType === "memory" || !isSupported()) {
|
|
23
|
+
return {
|
|
24
|
+
getItem: (key) => memoryStore[key] ?? null,
|
|
25
|
+
setItem: (key, value) => {
|
|
26
|
+
memoryStore[key] = value;
|
|
27
|
+
},
|
|
28
|
+
removeItem: (key) => {
|
|
29
|
+
delete memoryStore[key];
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return window[storageType];
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
_is_supported: isSupported,
|
|
37
|
+
_parse: (key) => {
|
|
38
|
+
try {
|
|
39
|
+
const value = getStorage().getItem(key);
|
|
40
|
+
return value ? JSON.parse(value) : null;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
_set: (key, value) => {
|
|
47
|
+
try {
|
|
48
|
+
getStorage().setItem(key, JSON.stringify(value));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Silently fail
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
_remove: (key) => {
|
|
55
|
+
try {
|
|
56
|
+
getStorage().removeItem(key);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Silently fail
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export const localStore = createStorage("localStorage");
|
|
65
|
+
export const sessionStore = createStorage("sessionStorage");
|
|
66
|
+
export const memoryStore = createStorage("memory");
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/persistence/index.ts"],"names":[],"mappings":"AAEA,MAAM,aAAa,GAAG,CACpB,WAAyD,EACxC,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AC;gBACxC,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC1C,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,GAAW,EAAE,KAAc,EAAE,EAAE;YACpC,IAAI,CAAC;gBACH,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YACnD,CAAC;YAAC,MAAM,CAAC;gBACP,gBAAgB;YAClB,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE;YACvB,IAAI,CAAC;gBACH,UAAU,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACP,gBAAgB;YAClB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;AACxD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/persistence/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAoExD,eAAO,MAAM,UAAU,iBAAgC,CAAC;AACxD,eAAO,MAAM,YAAY,iBAAkC,CAAC;AAC5D,eAAO,MAAM,WAAW,iBAA0B,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const createStorage = (storageType) => {
|
|
2
|
+
const memoryStore = {};
|
|
3
|
+
const isSupported = () => {
|
|
4
|
+
if (storageType === "memory") {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (typeof window === "undefined") {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const storage = window[storageType];
|
|
12
|
+
const testKey = "__interfere_test__";
|
|
13
|
+
storage.setItem(testKey, "test");
|
|
14
|
+
storage.removeItem(testKey);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const getStorage = () => {
|
|
22
|
+
if (storageType === "memory" || !isSupported()) {
|
|
23
|
+
return {
|
|
24
|
+
getItem: (key) => memoryStore[key] ?? null,
|
|
25
|
+
setItem: (key, value) => {
|
|
26
|
+
memoryStore[key] = value;
|
|
27
|
+
},
|
|
28
|
+
removeItem: (key) => {
|
|
29
|
+
delete memoryStore[key];
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return window[storageType];
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
_is_supported: isSupported,
|
|
37
|
+
_parse: (key) => {
|
|
38
|
+
try {
|
|
39
|
+
const value = getStorage().getItem(key);
|
|
40
|
+
return value ? JSON.parse(value) : null;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
_set: (key, value) => {
|
|
47
|
+
try {
|
|
48
|
+
getStorage().setItem(key, JSON.stringify(value));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Silently fail
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
_remove: (key) => {
|
|
55
|
+
try {
|
|
56
|
+
getStorage().removeItem(key);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Silently fail
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export const localStore = createStorage("localStorage");
|
|
65
|
+
export const sessionStore = createStorage("sessionStorage");
|
|
66
|
+
export const memoryStore = createStorage("memory");
|
|
67
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/persistence/storage.ts"],"names":[],"mappings":"AAEA,MAAM,aAAa,GAAG,CACpB,WAAyD,EACxC,EAAE;IACnB,MAAM,WAAW,GAA2B,EAAE,CAAC;IAE/C,MAAM,WAAW,GAAG,GAAY,EAAE;QAChC,IAAI,WAAW,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;YACpC,MAAM,OAAO,GAAG,oBAAoB,CAAC;YACrC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACjC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,UAAU,GAAG,GAAG,EAAE;QACtB,IAAI,WAAW,KAAK,QAAQ,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/C,OAAO;gBACL,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,IAAI;gBAClD,OAAO,EAAE,CAAC,GAAW,EAAE,KAAa,EAAE,EAAE;oBACtC,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBAC3B,CAAC;gBACD,UAAU,EAAE,CAAC,GAAW,EAAE,EAAE;oBAC1B,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;gBAC1B,CAAC;aACF,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,OAAO;QACL,aAAa,EAAE,WAAW;QAC1B,MAAM,EAAE,CAAC,GAAW,EAAE,EAAE;YACtB,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBACxC,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC1C,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,GAAW,EAAE,KAAc,EAAE,EAAE;YACpC,IAAI,CAAC;gBACH,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YACnD,CAAC;YAAC,MAAM,CAAC;gBACP,gBAAgB;YAClB,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE;YACvB,IAAI,CAAC;gBACH,UAAU,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACP,gBAAgB;YAClB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;AACxD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC"}
|
package/dist/react/provider.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import type { Config
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import type { Config } from "@interfere/schemas/config";
|
|
2
|
+
import type { SurfaceId } from "@interfere/schemas/surface";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
import { capture, flush, getDebugInfo, getSessionId, getWindowId, resetSession } from "../core/client.js";
|
|
5
|
+
type InterfereProviderProps = {
|
|
5
6
|
surface: SurfaceId;
|
|
6
7
|
options?: Partial<Config>;
|
|
7
8
|
children: ReactNode;
|
|
8
|
-
}
|
|
9
|
+
};
|
|
9
10
|
export declare function InterfereProvider(props: InterfereProviderProps): import("react").JSX.Element;
|
|
10
11
|
export declare function useInterfere(): {
|
|
11
12
|
capture: typeof capture;
|
|
12
13
|
flush: typeof flush;
|
|
13
14
|
getSessionId: typeof getSessionId;
|
|
15
|
+
getWindowId: typeof getWindowId;
|
|
16
|
+
getDebugInfo: typeof getDebugInfo;
|
|
17
|
+
resetSession: typeof resetSession;
|
|
14
18
|
};
|
|
15
19
|
export {};
|
|
16
20
|
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAiB,KAAK,SAAS,EAAyB,MAAM,OAAO,CAAC;AAC7E,OAAO,EACL,OAAO,EACP,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,WAAW,EAEX,YAAY,EACb,MAAM,mBAAmB,CAAC;AAiB3B,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,SAAS,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1B,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,+BAoC9D;AAED,wBAAgB,YAAY;aApDjB,OAAO,OAAO;WAChB,OAAO,KAAK;kBACL,OAAO,YAAY;iBACpB,OAAO,WAAW;kBACjB,OAAO,YAAY;kBACnB,OAAO,YAAY;EAqDlC"}
|
package/dist/react/provider.jsx
CHANGED
|
@@ -1,24 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
import { createContext, useContext, useEffect } from
|
|
3
|
-
import { capture, flush, getSessionId, init } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext, useEffect } from "react";
|
|
3
|
+
import { capture, flush, getDebugInfo, getSessionId, getWindowId, init, resetSession, } from "../core/client.js";
|
|
4
|
+
import { setupRageClick } from "../session/rage-click.js";
|
|
5
|
+
import { setupReplay, stopReplay } from "../session/replay.js";
|
|
6
|
+
import { setupSessionSummary, stopSessionSummary, } from "../session/session-summary.js";
|
|
6
7
|
const InterfereContext = createContext(null);
|
|
7
8
|
export function InterfereProvider(props) {
|
|
8
9
|
useEffect(() => {
|
|
9
10
|
init(props);
|
|
10
|
-
setupSessionSummary(
|
|
11
|
-
setupReplay(
|
|
12
|
-
|
|
11
|
+
setupSessionSummary();
|
|
12
|
+
setupReplay();
|
|
13
|
+
setupRageClick();
|
|
14
|
+
return () => {
|
|
15
|
+
try {
|
|
16
|
+
stopSessionSummary();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
/* no-op */
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
stopReplay();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
/* no-op */
|
|
26
|
+
}
|
|
27
|
+
flush();
|
|
28
|
+
};
|
|
13
29
|
}, [props]);
|
|
14
|
-
return (<InterfereContext.Provider value={{
|
|
30
|
+
return (<InterfereContext.Provider value={{
|
|
31
|
+
capture,
|
|
32
|
+
flush,
|
|
33
|
+
getSessionId,
|
|
34
|
+
getWindowId,
|
|
35
|
+
getDebugInfo,
|
|
36
|
+
resetSession,
|
|
37
|
+
}}>
|
|
15
38
|
{props.children}
|
|
16
39
|
</InterfereContext.Provider>);
|
|
17
40
|
}
|
|
18
41
|
export function useInterfere() {
|
|
19
42
|
const context = useContext(InterfereContext);
|
|
20
43
|
if (!context) {
|
|
21
|
-
throw new Error(
|
|
44
|
+
throw new Error("useInterfere() must be used within InterfereProvider");
|
|
22
45
|
}
|
|
23
46
|
return context;
|
|
24
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.jsx","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.jsx","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAKb,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7E,OAAO,EACL,OAAO,EACP,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,IAAI,EACJ,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC,MAAM,gBAAgB,GAAG,aAAa,CAO5B,IAAI,CAAC,CAAC;AAQhB,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,CAAC,CAAC;QACZ,mBAAmB,EAAE,CAAC;QACtB,WAAW,EAAE,CAAC;QACd,cAAc,EAAE,CAAC;QAEjB,OAAO,GAAG,EAAE;YACV,IAAI,CAAC;gBACH,kBAAkB,EAAE,CAAC;YACvB,CAAC;YAAC,MAAM,CAAC;gBACP,WAAW;YACb,CAAC;YACD,IAAI,CAAC;gBACH,UAAU,EAAE,CAAC;YACf,CAAC;YAAC,MAAM,CAAC;gBACP,WAAW;YACb,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,CACL,CAAC,gBAAgB,CAAC,QAAQ,CACxB,KAAK,CAAC,CAAC;YACL,OAAO;YACP,KAAK;YACL,YAAY;YACZ,WAAW;YACX,YAAY;YACZ,YAAY;SACb,CAAC,CAEF;MAAA,CAAC,KAAK,CAAC,QAAQ,CACjB;IAAA,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAC7B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const SESSION_ID = "$session_id";
|
|
2
|
+
export declare const WINDOW_ID = "$window_id";
|
|
3
|
+
export declare const toMs: (seconds: number) => number;
|
|
4
|
+
export declare const toSeconds: (milliseconds: number) => number;
|
|
5
|
+
export declare const DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS: number;
|
|
6
|
+
export declare const MAX_SESSION_IDLE_TIMEOUT_SECONDS: number;
|
|
7
|
+
export declare const MIN_SESSION_IDLE_TIMEOUT_SECONDS = 60;
|
|
8
|
+
export declare const SESSION_LENGTH_LIMIT_MILLISECONDS: number;
|
|
9
|
+
export declare const SESSION_SUMMARY_ENABLED = true;
|
|
10
|
+
export declare const SESSION_SUMMARY_WINDOW_MS = 10000;
|
|
11
|
+
export declare const SESSION_SUMMARY_MAX_EVENTS = 200;
|
|
12
|
+
export declare const ALLOW_BROWSER_AI = true;
|
|
13
|
+
export declare const REPLAY_ENABLED = true;
|
|
14
|
+
export declare const REPLAY_CHUNK_MS = 10000;
|
|
15
|
+
export declare const RAGE_CLICK_ENABLED = true;
|
|
16
|
+
export declare const RAGE_CLICK_RADIUS_PX = 30;
|
|
17
|
+
export declare const RAGE_CLICK_TIMEOUT_MS = 1000;
|
|
18
|
+
export declare const RAGE_CLICK_COUNT = 3;
|
|
19
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/session/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,gBAAgB,CAAC;AACxC,eAAO,MAAM,SAAS,eAAe,CAAC;AAUtC,eAAO,MAAM,IAAI,GAAI,SAAS,MAAM,KAAG,MACL,CAAC;AACnC,eAAO,MAAM,SAAS,GAAI,cAAc,MAAM,KAAG,MACE,CAAC;AAIpD,eAAO,MAAM,oCAAoC,QACC,CAAC;AACnD,eAAO,MAAM,gCAAgC,QAAuB,CAAC;AACrE,eAAO,MAAM,gCAAgC,KAAoB,CAAC;AAGlE,eAAO,MAAM,iCAAiC,QAA4B,CAAC;AAM3E,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAChD,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAGrC,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,eAAO,MAAM,eAAe,QAAS,CAAC;AAGtC,eAAO,MAAM,kBAAkB,OAAO,CAAC;AACvC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,gBAAgB,IAAI,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const SESSION_ID = "$session_id";
|
|
2
|
+
export const WINDOW_ID = "$window_id";
|
|
3
|
+
// Time constants - all in milliseconds internally
|
|
4
|
+
const SECONDS_IN_MINUTE = 60;
|
|
5
|
+
const MINUTES_IN_HOUR = 60;
|
|
6
|
+
const MILLISECONDS_IN_SECOND = 1000;
|
|
7
|
+
const SECONDS_IN_HOUR = MINUTES_IN_HOUR * SECONDS_IN_MINUTE;
|
|
8
|
+
const MILLISECONDS_IN_HOUR = SECONDS_IN_HOUR * MILLISECONDS_IN_SECOND;
|
|
9
|
+
// Time utility functions
|
|
10
|
+
export const toMs = (seconds) => seconds * MILLISECONDS_IN_SECOND;
|
|
11
|
+
export const toSeconds = (milliseconds) => Math.floor(milliseconds / MILLISECONDS_IN_SECOND);
|
|
12
|
+
// Session timeout constants (exported in seconds for config compatibility)
|
|
13
|
+
const DEFAULT_IDLE_TIMEOUT_MINUTES = 30;
|
|
14
|
+
export const DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS = DEFAULT_IDLE_TIMEOUT_MINUTES * SECONDS_IN_MINUTE; // 30 minutes
|
|
15
|
+
export const MAX_SESSION_IDLE_TIMEOUT_SECONDS = 10 * SECONDS_IN_HOUR; // 10 hours
|
|
16
|
+
export const MIN_SESSION_IDLE_TIMEOUT_SECONDS = SECONDS_IN_MINUTE; // 1 minute
|
|
17
|
+
// Session length limit (in milliseconds)
|
|
18
|
+
export const SESSION_LENGTH_LIMIT_MILLISECONDS = 24 * MILLISECONDS_IN_HOUR; // 24 hours
|
|
19
|
+
// Static SDK configuration values
|
|
20
|
+
// These may become server-configurable in the future
|
|
21
|
+
// Session summary
|
|
22
|
+
export const SESSION_SUMMARY_ENABLED = true; // Always enabled
|
|
23
|
+
export const SESSION_SUMMARY_WINDOW_MS = 10_000; // 10 seconds
|
|
24
|
+
export const SESSION_SUMMARY_MAX_EVENTS = 200;
|
|
25
|
+
export const ALLOW_BROWSER_AI = true;
|
|
26
|
+
// Session replay
|
|
27
|
+
export const REPLAY_ENABLED = true; // Always enabled
|
|
28
|
+
export const REPLAY_CHUNK_MS = 10_000; // 10 seconds
|
|
29
|
+
// Rage click detection
|
|
30
|
+
export const RAGE_CLICK_ENABLED = true; // Always enabled
|
|
31
|
+
export const RAGE_CLICK_RADIUS_PX = 30;
|
|
32
|
+
export const RAGE_CLICK_TIMEOUT_MS = 1000; // 1 second
|
|
33
|
+
export const RAGE_CLICK_COUNT = 3; // 3 rapid clicks trigger rage click
|
|
34
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/session/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,YAAY,CAAC;AAEtC,kDAAkD;AAClD,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,eAAe,GAAG,eAAe,GAAG,iBAAiB,CAAC;AAC5D,MAAM,oBAAoB,GAAG,eAAe,GAAG,sBAAsB,CAAC;AAEtE,yBAAyB;AACzB,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAe,EAAU,EAAE,CAC9C,OAAO,GAAG,sBAAsB,CAAC;AACnC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,YAAoB,EAAU,EAAE,CACxD,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,sBAAsB,CAAC,CAAC;AAEpD,2EAA2E;AAC3E,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,oCAAoC,GAC/C,4BAA4B,GAAG,iBAAiB,CAAC,CAAC,aAAa;AACjE,MAAM,CAAC,MAAM,gCAAgC,GAAG,EAAE,GAAG,eAAe,CAAC,CAAC,WAAW;AACjF,MAAM,CAAC,MAAM,gCAAgC,GAAG,iBAAiB,CAAC,CAAC,WAAW;AAE9E,yCAAyC;AACzC,MAAM,CAAC,MAAM,iCAAiC,GAAG,EAAE,GAAG,oBAAoB,CAAC,CAAC,WAAW;AAEvF,kCAAkC;AAClC,qDAAqD;AAErD,kBAAkB;AAClB,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,CAAC,iBAAiB;AAC9D,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,CAAC,aAAa;AAC9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC,iBAAiB;AACjB,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,iBAAiB;AACrD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,CAAC,aAAa;AAEpD,uBAAuB;AACvB,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC,CAAC,iBAAiB;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,CAAC,WAAW;AACtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,CAAC,oCAAoC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Config } from "@interfere/schemas/config";
|
|
2
|
+
import type { PersistentStore } from "../types/storage.js";
|
|
3
|
+
export type Properties = {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
export type PersistenceOptions = {
|
|
7
|
+
/** Use deep equality check for register method (slower but more accurate for objects) */
|
|
8
|
+
useDeepEquality?: boolean;
|
|
9
|
+
/** Custom storage implementation for testing */
|
|
10
|
+
customStorage?: PersistentStore;
|
|
11
|
+
};
|
|
12
|
+
export declare class InterferePersistence {
|
|
13
|
+
private readonly _config;
|
|
14
|
+
private _props;
|
|
15
|
+
private readonly _storage;
|
|
16
|
+
private readonly _name;
|
|
17
|
+
private _disabled;
|
|
18
|
+
private readonly _useDeepEquality;
|
|
19
|
+
constructor(config: Partial<Config>, surface: string, isDisabled?: boolean, options?: PersistenceOptions);
|
|
20
|
+
private _parseName;
|
|
21
|
+
private _buildStorage;
|
|
22
|
+
isDisabled(): boolean;
|
|
23
|
+
load(): void;
|
|
24
|
+
save(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Deep equality helper for objects and arrays
|
|
27
|
+
*/
|
|
28
|
+
private _deepEqual;
|
|
29
|
+
register(props: Properties): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Remove a single property from persistence
|
|
32
|
+
*/
|
|
33
|
+
removeProp(prop: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get a property value with optional generic typing
|
|
36
|
+
*/
|
|
37
|
+
getProperty<T = unknown>(prop: string): T | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Set a property value
|
|
40
|
+
*/
|
|
41
|
+
setProperty<T = unknown>(prop: string, value: T): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get all properties (immutable copy)
|
|
44
|
+
*/
|
|
45
|
+
getAllProperties(): Readonly<Properties>;
|
|
46
|
+
/**
|
|
47
|
+
* Remove all data from storage and memory
|
|
48
|
+
*/
|
|
49
|
+
removeAll(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Clear both storage and in-memory props (alias for removeAll)
|
|
52
|
+
*/
|
|
53
|
+
clear(): void;
|
|
54
|
+
setDisabled(disabled: boolean): void;
|
|
55
|
+
/** @deprecated Use removeProp instead */
|
|
56
|
+
unregister(prop: string): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../src/session/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAmB,MAAM,2BAA2B,CAAC;AAQzE,OAAO,KAAK,EAAE,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I;IAcjB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAWpC,yCAAyC;IACzC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAG/B"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { localStore, memoryStore, sessionStore, } from "../persistence/storage.js";
|
|
2
|
+
export class InterferePersistence {
|
|
3
|
+
_config;
|
|
4
|
+
_props = {};
|
|
5
|
+
_storage;
|
|
6
|
+
_name;
|
|
7
|
+
_disabled;
|
|
8
|
+
_useDeepEquality;
|
|
9
|
+
constructor(config, surface, isDisabled = false, options = {}) {
|
|
10
|
+
this._config = config;
|
|
11
|
+
this._name = this._parseName(surface);
|
|
12
|
+
this._disabled = isDisabled;
|
|
13
|
+
this._useDeepEquality = options.useDeepEquality ?? false;
|
|
14
|
+
// Short-circuit storage building if disabled
|
|
15
|
+
this._storage = this._disabled
|
|
16
|
+
? null
|
|
17
|
+
: (options.customStorage ?? this._buildStorage());
|
|
18
|
+
this.load();
|
|
19
|
+
}
|
|
20
|
+
_parseName(surface) {
|
|
21
|
+
// Normalize consecutive non-alphanumerics to single underscore
|
|
22
|
+
const cleanSurface = surface.replace(/[^a-zA-Z0-9]+/g, "_");
|
|
23
|
+
return `interfere_${cleanSurface}`;
|
|
24
|
+
}
|
|
25
|
+
_buildStorage() {
|
|
26
|
+
const persistenceType = this._config.persistence || "localStorage";
|
|
27
|
+
switch (persistenceType) {
|
|
28
|
+
case "localStorage":
|
|
29
|
+
return localStore._is_supported() ? localStore : memoryStore;
|
|
30
|
+
case "sessionStorage":
|
|
31
|
+
return sessionStore._is_supported() ? sessionStore : memoryStore;
|
|
32
|
+
case "memory":
|
|
33
|
+
return memoryStore;
|
|
34
|
+
default:
|
|
35
|
+
// TypeScript ensures exhaustiveness, but keep default for safety
|
|
36
|
+
return localStore._is_supported() ? localStore : memoryStore;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
isDisabled() {
|
|
40
|
+
return this._disabled;
|
|
41
|
+
}
|
|
42
|
+
load() {
|
|
43
|
+
if (this._disabled || !this._storage) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const entry = this._storage._parse(this._name);
|
|
48
|
+
if (entry && typeof entry === "object" && entry !== null) {
|
|
49
|
+
this._props = { ...entry };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Gracefully handle parse errors, keep existing props
|
|
54
|
+
// In production, we silently fail to avoid console noise
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
save() {
|
|
58
|
+
if (this._disabled || !this._storage) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
this._storage._set(this._name, this._props);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Gracefully handle storage errors (e.g., quota exceeded)
|
|
66
|
+
// In production, we silently fail to avoid console noise
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Deep equality helper for objects and arrays
|
|
71
|
+
*/
|
|
72
|
+
_deepEqual(a, b) {
|
|
73
|
+
if (a === b) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
if (a == null || b == null) {
|
|
77
|
+
return a === b;
|
|
78
|
+
}
|
|
79
|
+
if (typeof a !== typeof b) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
83
|
+
return a === b;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Fallback to shallow comparison for non-serializable objects
|
|
90
|
+
return a === b;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
register(props) {
|
|
94
|
+
if (!props || typeof props !== "object") {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
let hasChanges = false;
|
|
98
|
+
for (const [prop, val] of Object.entries(props)) {
|
|
99
|
+
const currentVal = this._props[prop];
|
|
100
|
+
const isEqual = this._useDeepEquality
|
|
101
|
+
? this._deepEqual(currentVal, val)
|
|
102
|
+
: currentVal === val;
|
|
103
|
+
if (!isEqual) {
|
|
104
|
+
this._props[prop] = val;
|
|
105
|
+
hasChanges = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// biome-ignore lint/nursery/noUnnecessaryConditions: false positive, hasChanges can be true
|
|
109
|
+
if (hasChanges) {
|
|
110
|
+
this.save();
|
|
111
|
+
}
|
|
112
|
+
return hasChanges;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Remove a single property from persistence
|
|
116
|
+
*/
|
|
117
|
+
removeProp(prop) {
|
|
118
|
+
if (prop in this._props) {
|
|
119
|
+
delete this._props[prop];
|
|
120
|
+
this.save();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get a property value with optional generic typing
|
|
125
|
+
*/
|
|
126
|
+
getProperty(prop) {
|
|
127
|
+
return this._props[prop];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Set a property value
|
|
131
|
+
*/
|
|
132
|
+
setProperty(prop, value) {
|
|
133
|
+
this._props[prop] = value;
|
|
134
|
+
this.save();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get all properties (immutable copy)
|
|
138
|
+
*/
|
|
139
|
+
getAllProperties() {
|
|
140
|
+
return { ...this._props };
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Remove all data from storage and memory
|
|
144
|
+
*/
|
|
145
|
+
removeAll() {
|
|
146
|
+
this._props = {};
|
|
147
|
+
if (!this._storage) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
this._storage._remove(this._name);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Gracefully handle removal errors
|
|
155
|
+
// In production, we silently fail to avoid console noise
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Clear both storage and in-memory props (alias for removeAll)
|
|
160
|
+
*/
|
|
161
|
+
clear() {
|
|
162
|
+
this.removeAll();
|
|
163
|
+
}
|
|
164
|
+
setDisabled(disabled) {
|
|
165
|
+
this._disabled = disabled;
|
|
166
|
+
if (this._disabled) {
|
|
167
|
+
this.removeAll();
|
|
168
|
+
}
|
|
169
|
+
else if (Object.keys(this._props).length > 0) {
|
|
170
|
+
// Only save if we have properties to persist
|
|
171
|
+
this.save();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// Deprecated methods for backward compatibility
|
|
175
|
+
/** @deprecated Use removeProp instead */
|
|
176
|
+
unregister(prop) {
|
|
177
|
+
this.removeProp(prop);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=persistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../src/session/persistence.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,GACb,MAAM,2BAA2B,CAAC;AAenC,MAAM,OAAO,oBAAoB;IACd,OAAO,CAAkB;IAClC,MAAM,GAAe,EAAE,CAAC;IACf,QAAQ,CAAyB;IACjC,KAAK,CAAS;IACvB,SAAS,CAAU;IACV,gBAAgB,CAAU;IAE3C,YACE,MAAuB,EACvB,OAAe,EACf,UAAU,GAAG,KAAK,EAClB,UAA8B,EAAE;QAEhC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC;QAEzD,6C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,CAAC;IAED;;OAEG;IACH,SAAS;QACP,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,mCAAmC;YACnC,yDAAyD;QAC3D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAED,WAAW,CAAC,QAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,CAAC;aAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/C,6CAA6C;YAC7C,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;IACH,CAAC;IAED,gDAAgD;IAChD,yCAAyC;IACzC,UAAU,CAAC,IAAY;QACrB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.test.d.ts","sourceRoot":"","sources":["../../src/session/persistence.test.ts"],"names":[],"mappings":""}
|