@sessionvision/core 0.2.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.
Files changed (104) hide show
  1. package/README.md +361 -0
  2. package/dist/react/capture/autocapture.d.ts +45 -0
  3. package/dist/react/capture/event.d.ts +29 -0
  4. package/dist/react/capture/pageview.d.ts +27 -0
  5. package/dist/react/capture/properties.d.ts +25 -0
  6. package/dist/react/core/config.d.ts +21 -0
  7. package/dist/react/core/init.d.ts +53 -0
  8. package/dist/react/core/queue.d.ts +22 -0
  9. package/dist/react/identity/anonymous.d.ts +30 -0
  10. package/dist/react/identity/identify.d.ts +46 -0
  11. package/dist/react/identity/session.d.ts +49 -0
  12. package/dist/react/index.cjs.js +48 -0
  13. package/dist/react/index.cjs.js.map +1 -0
  14. package/dist/react/index.d.ts +13 -0
  15. package/dist/react/index.esm.js +42 -0
  16. package/dist/react/index.esm.js.map +1 -0
  17. package/dist/react/react/SessionVisionProvider.d.ts +8 -0
  18. package/dist/react/react/context.d.ts +3 -0
  19. package/dist/react/react/hooks.d.ts +3 -0
  20. package/dist/react/react/index.d.ts +4 -0
  21. package/dist/react/stub.d.ts +9 -0
  22. package/dist/react/transport/buffer.d.ts +50 -0
  23. package/dist/react/transport/compress.d.ts +22 -0
  24. package/dist/react/transport/send.d.ts +30 -0
  25. package/dist/react/types.d.ts +228 -0
  26. package/dist/react/utils/dom.d.ts +51 -0
  27. package/dist/react/utils/pii.d.ts +26 -0
  28. package/dist/react/utils/selector.d.ts +12 -0
  29. package/dist/react/utils/storage.d.ts +44 -0
  30. package/dist/react/utils/uuid.d.ts +13 -0
  31. package/dist/react/vue/composables.d.ts +4 -0
  32. package/dist/react/vue/index.d.ts +2 -0
  33. package/dist/react/vue/plugin.d.ts +4 -0
  34. package/dist/sessionvision.cjs.js +1903 -0
  35. package/dist/sessionvision.cjs.js.map +1 -0
  36. package/dist/sessionvision.esm.js +1901 -0
  37. package/dist/sessionvision.esm.js.map +1 -0
  38. package/dist/sessionvision.js +1909 -0
  39. package/dist/sessionvision.js.map +1 -0
  40. package/dist/sessionvision.min.js +7 -0
  41. package/dist/sessionvision.min.js.map +1 -0
  42. package/dist/stub-template.ts +41 -0
  43. package/dist/stub.min.js +1 -0
  44. package/dist/types/capture/autocapture.d.ts +45 -0
  45. package/dist/types/capture/event.d.ts +29 -0
  46. package/dist/types/capture/pageview.d.ts +27 -0
  47. package/dist/types/capture/properties.d.ts +25 -0
  48. package/dist/types/core/config.d.ts +21 -0
  49. package/dist/types/core/init.d.ts +53 -0
  50. package/dist/types/core/queue.d.ts +22 -0
  51. package/dist/types/identity/anonymous.d.ts +30 -0
  52. package/dist/types/identity/identify.d.ts +46 -0
  53. package/dist/types/identity/session.d.ts +49 -0
  54. package/dist/types/index.d.ts +13 -0
  55. package/dist/types/react/SessionVisionProvider.d.ts +8 -0
  56. package/dist/types/react/context.d.ts +3 -0
  57. package/dist/types/react/hooks.d.ts +3 -0
  58. package/dist/types/react/index.d.ts +4 -0
  59. package/dist/types/stub.d.ts +9 -0
  60. package/dist/types/transport/buffer.d.ts +50 -0
  61. package/dist/types/transport/compress.d.ts +22 -0
  62. package/dist/types/transport/send.d.ts +30 -0
  63. package/dist/types/types.d.ts +228 -0
  64. package/dist/types/utils/dom.d.ts +51 -0
  65. package/dist/types/utils/pii.d.ts +26 -0
  66. package/dist/types/utils/selector.d.ts +12 -0
  67. package/dist/types/utils/storage.d.ts +44 -0
  68. package/dist/types/utils/uuid.d.ts +13 -0
  69. package/dist/types/vue/composables.d.ts +4 -0
  70. package/dist/types/vue/index.d.ts +2 -0
  71. package/dist/types/vue/plugin.d.ts +4 -0
  72. package/dist/vue/capture/autocapture.d.ts +45 -0
  73. package/dist/vue/capture/event.d.ts +29 -0
  74. package/dist/vue/capture/pageview.d.ts +27 -0
  75. package/dist/vue/capture/properties.d.ts +25 -0
  76. package/dist/vue/core/config.d.ts +21 -0
  77. package/dist/vue/core/init.d.ts +53 -0
  78. package/dist/vue/core/queue.d.ts +22 -0
  79. package/dist/vue/identity/anonymous.d.ts +30 -0
  80. package/dist/vue/identity/identify.d.ts +46 -0
  81. package/dist/vue/identity/session.d.ts +49 -0
  82. package/dist/vue/index.cjs.js +43 -0
  83. package/dist/vue/index.cjs.js.map +1 -0
  84. package/dist/vue/index.d.ts +13 -0
  85. package/dist/vue/index.esm.js +38 -0
  86. package/dist/vue/index.esm.js.map +1 -0
  87. package/dist/vue/react/SessionVisionProvider.d.ts +8 -0
  88. package/dist/vue/react/context.d.ts +3 -0
  89. package/dist/vue/react/hooks.d.ts +3 -0
  90. package/dist/vue/react/index.d.ts +4 -0
  91. package/dist/vue/stub.d.ts +9 -0
  92. package/dist/vue/transport/buffer.d.ts +50 -0
  93. package/dist/vue/transport/compress.d.ts +22 -0
  94. package/dist/vue/transport/send.d.ts +30 -0
  95. package/dist/vue/types.d.ts +228 -0
  96. package/dist/vue/utils/dom.d.ts +51 -0
  97. package/dist/vue/utils/pii.d.ts +26 -0
  98. package/dist/vue/utils/selector.d.ts +12 -0
  99. package/dist/vue/utils/storage.d.ts +44 -0
  100. package/dist/vue/utils/uuid.d.ts +13 -0
  101. package/dist/vue/vue/composables.d.ts +4 -0
  102. package/dist/vue/vue/index.d.ts +2 -0
  103. package/dist/vue/vue/plugin.d.ts +4 -0
  104. package/package.json +109 -0
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Session ID management
3
+ * Manages session lifecycle with configurable inactivity timeout
4
+ */
5
+ /**
6
+ * Set the session timeout duration (for server-side configuration)
7
+ */
8
+ export declare function setSessionTimeout(timeoutMinutes: number): void;
9
+ /**
10
+ * Get the current session timeout in milliseconds
11
+ */
12
+ export declare function getSessionTimeout(): number;
13
+ /**
14
+ * Get or create a session ID
15
+ * Creates a new session if:
16
+ * - No existing session
17
+ * - Session has timed out (30 minutes of inactivity by default)
18
+ */
19
+ export declare function getSessionId(): string;
20
+ /**
21
+ * Force start a new session
22
+ */
23
+ export declare function startNewSession(): string;
24
+ /**
25
+ * Reset the session (clear storage and cache)
26
+ */
27
+ export declare function resetSession(): string;
28
+ /**
29
+ * Check if the current session has expired
30
+ */
31
+ export declare function isSessionExpired(): boolean;
32
+ /**
33
+ * Get the time remaining in the current session (in milliseconds)
34
+ * Returns 0 if session has expired
35
+ */
36
+ export declare function getSessionTimeRemaining(): number;
37
+ /**
38
+ * Touch the session to keep it alive
39
+ * Called on user activity
40
+ */
41
+ export declare function touchSession(): void;
42
+ /**
43
+ * Clear the in-memory cache (for testing)
44
+ */
45
+ export declare function _clearCache(): void;
46
+ /**
47
+ * Reset timeout to default (for testing)
48
+ */
49
+ export declare function _resetTimeout(): void;
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var sessionvision = require('@sessionvision/core');
6
+
7
+ const SessionVisionContext = react.createContext(null);
8
+ function useSessionVision() {
9
+ const context = react.useContext(SessionVisionContext);
10
+ if (!context) {
11
+ throw new Error('useSessionVision must be used within a SessionVisionProvider. ' +
12
+ 'Wrap your app in <SessionVisionProvider apiKey="...">.');
13
+ }
14
+ return context;
15
+ }
16
+
17
+ function SessionVisionProvider({ apiKey, options, children }) {
18
+ react.useEffect(() => {
19
+ if (typeof window === 'undefined')
20
+ return;
21
+ if (sessionvision.__SV)
22
+ return;
23
+ sessionvision.init(apiKey, options);
24
+ // options intentionally excluded - provider only reads them on mount
25
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ }, [apiKey]);
27
+ return (jsxRuntime.jsx(SessionVisionContext.Provider, { value: sessionvision, children: children }));
28
+ }
29
+
30
+ function useCapture() {
31
+ const sessionvision = useSessionVision();
32
+ return react.useCallback((eventName, properties) => {
33
+ sessionvision.capture(eventName, properties);
34
+ }, [sessionvision]);
35
+ }
36
+ function useIdentify() {
37
+ const sessionvision = useSessionVision();
38
+ return react.useCallback((userId, traits) => {
39
+ sessionvision.identify(userId, traits);
40
+ }, [sessionvision]);
41
+ }
42
+
43
+ exports.SessionVisionContext = SessionVisionContext;
44
+ exports.SessionVisionProvider = SessionVisionProvider;
45
+ exports.useCapture = useCapture;
46
+ exports.useIdentify = useIdentify;
47
+ exports.useSessionVision = useSessionVision;
48
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../../src/react/context.ts","../../src/react/SessionVisionProvider.tsx","../../src/react/hooks.ts"],"sourcesContent":[null,null,null],"names":["createContext","useContext","useEffect","_jsx","useCallback"],"mappings":";;;;;;MAGa,oBAAoB,GAAGA,mBAAa,CAA0B,IAAI;SAE/D,gBAAgB,GAAA;AAC9B,IAAA,MAAM,OAAO,GAAGC,gBAAU,CAAC,oBAAoB,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,gEAAgE;AAC9D,YAAA,wDAAwD,CAC3D;IACH;AAEA,IAAA,OAAO,OAAO;AAChB;;ACJM,SAAU,qBAAqB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAA8B,EAAA;IAC7FC,eAAS,CAAC,MAAK;QACb,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE;QACnC,IAAI,aAAa,CAAC,IAAI;YAAE;AAExB,QAAA,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;;;AAGrC,IAAA,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAEZ,IAAA,QACEC,cAAA,CAAC,oBAAoB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,aAAa,EAAA,QAAA,EAChD,QAAQ,EAAA,CACqB;AAEpC;;SCvBgB,UAAU,GAAA;AACxB,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;AAExC,IAAA,OAAOC,iBAAW,CAChB,CAAC,SAAiB,EAAE,UAA4B,KAAI;AAClD,QAAA,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC;AAC9C,IAAA,CAAC,EACD,CAAC,aAAa,CAAC,CAChB;AACH;SAEgB,WAAW,GAAA;AACzB,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;AAExC,IAAA,OAAOA,iBAAW,CAChB,CAAC,MAAc,EAAE,MAAmB,KAAI;AACtC,QAAA,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACxC,IAAA,CAAC,EACD,CAAC,aAAa,CAAC,CAChB;AACH;;;;;;;;"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Session Vision JavaScript Snippet
3
+ * Main SDK entry point
4
+ *
5
+ * @version __SESSIONVISION_VERSION__
6
+ */
7
+ import { SessionVisionConfig, EventProperties, UserTraits, SessionVisionAPI } from './types';
8
+ /**
9
+ * Session Vision SDK instance
10
+ */
11
+ declare const sessionvision: SessionVisionAPI;
12
+ export default sessionvision;
13
+ export type { SessionVisionConfig, EventProperties, UserTraits };
@@ -0,0 +1,42 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { createContext, useContext, useEffect, useCallback } from 'react';
3
+ import sessionvision from '@sessionvision/core';
4
+
5
+ const SessionVisionContext = createContext(null);
6
+ function useSessionVision() {
7
+ const context = useContext(SessionVisionContext);
8
+ if (!context) {
9
+ throw new Error('useSessionVision must be used within a SessionVisionProvider. ' +
10
+ 'Wrap your app in <SessionVisionProvider apiKey="...">.');
11
+ }
12
+ return context;
13
+ }
14
+
15
+ function SessionVisionProvider({ apiKey, options, children }) {
16
+ useEffect(() => {
17
+ if (typeof window === 'undefined')
18
+ return;
19
+ if (sessionvision.__SV)
20
+ return;
21
+ sessionvision.init(apiKey, options);
22
+ // options intentionally excluded - provider only reads them on mount
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ }, [apiKey]);
25
+ return (jsx(SessionVisionContext.Provider, { value: sessionvision, children: children }));
26
+ }
27
+
28
+ function useCapture() {
29
+ const sessionvision = useSessionVision();
30
+ return useCallback((eventName, properties) => {
31
+ sessionvision.capture(eventName, properties);
32
+ }, [sessionvision]);
33
+ }
34
+ function useIdentify() {
35
+ const sessionvision = useSessionVision();
36
+ return useCallback((userId, traits) => {
37
+ sessionvision.identify(userId, traits);
38
+ }, [sessionvision]);
39
+ }
40
+
41
+ export { SessionVisionContext, SessionVisionProvider, useCapture, useIdentify, useSessionVision };
42
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../../src/react/context.ts","../../src/react/SessionVisionProvider.tsx","../../src/react/hooks.ts"],"sourcesContent":[null,null,null],"names":["_jsx"],"mappings":";;;;MAGa,oBAAoB,GAAG,aAAa,CAA0B,IAAI;SAE/D,gBAAgB,GAAA;AAC9B,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,gEAAgE;AAC9D,YAAA,wDAAwD,CAC3D;IACH;AAEA,IAAA,OAAO,OAAO;AAChB;;ACJM,SAAU,qBAAqB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAA8B,EAAA;IAC7F,SAAS,CAAC,MAAK;QACb,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE;QACnC,IAAI,aAAa,CAAC,IAAI;YAAE;AAExB,QAAA,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;;;AAGrC,IAAA,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAEZ,IAAA,QACEA,GAAA,CAAC,oBAAoB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,aAAa,EAAA,QAAA,EAChD,QAAQ,EAAA,CACqB;AAEpC;;SCvBgB,UAAU,GAAA;AACxB,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;AAExC,IAAA,OAAO,WAAW,CAChB,CAAC,SAAiB,EAAE,UAA4B,KAAI;AAClD,QAAA,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC;AAC9C,IAAA,CAAC,EACD,CAAC,aAAa,CAAC,CAChB;AACH;SAEgB,WAAW,GAAA;AACzB,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;AAExC,IAAA,OAAO,WAAW,CAChB,CAAC,MAAc,EAAE,MAAmB,KAAI;AACtC,QAAA,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACxC,IAAA,CAAC,EACD,CAAC,aAAa,CAAC,CAChB;AACH;;;;"}
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { SessionVisionConfig } from '../types';
3
+ export interface SessionVisionProviderProps {
4
+ apiKey: string;
5
+ options?: Omit<SessionVisionConfig, 'apiHost'>;
6
+ children: ReactNode;
7
+ }
8
+ export declare function SessionVisionProvider({ apiKey, options, children }: SessionVisionProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import type { SessionVisionAPI } from '../types';
2
+ export declare const SessionVisionContext: import("react").Context<SessionVisionAPI | null>;
3
+ export declare function useSessionVision(): SessionVisionAPI;
@@ -0,0 +1,3 @@
1
+ import type { EventProperties, UserTraits } from '../types';
2
+ export declare function useCapture(): (eventName: string, properties?: EventProperties) => void;
3
+ export declare function useIdentify(): (userId: string, traits?: UserTraits) => void;
@@ -0,0 +1,4 @@
1
+ export { SessionVisionProvider } from './SessionVisionProvider';
2
+ export type { SessionVisionProviderProps } from './SessionVisionProvider';
3
+ export { SessionVisionContext, useSessionVision } from './context';
4
+ export { useCapture, useIdentify } from './hooks';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Session Vision Inline Stub
3
+ *
4
+ * This is the minimal script that customers paste in their <head> tag.
5
+ * It creates the sessionvision global, queues method calls, and loads the main SDK.
6
+ *
7
+ * Target size: < 1KB minified
8
+ */
9
+ export {};
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Event buffer module
3
+ * Buffers events and flushes them periodically or when buffer is full
4
+ */
5
+ import { CapturedEvent, ResolvedConfig } from '../types';
6
+ /**
7
+ * Set the configuration
8
+ */
9
+ export declare function setBufferConfig(cfg: ResolvedConfig): void;
10
+ /**
11
+ * Add an event to the buffer
12
+ */
13
+ export declare function addToBuffer(event: CapturedEvent): void;
14
+ /**
15
+ * Flush the event buffer
16
+ * Sends all buffered events to the server
17
+ */
18
+ export declare function flush(): Promise<void>;
19
+ /**
20
+ * Start the flush timer
21
+ */
22
+ export declare function startFlushTimer(): void;
23
+ /**
24
+ * Stop the flush timer
25
+ */
26
+ export declare function stopFlushTimer(): void;
27
+ /**
28
+ * Initialize visibility change handler for flushing on tab hide
29
+ */
30
+ export declare function initVisibilityHandler(): void;
31
+ /**
32
+ * Get the current buffer size
33
+ */
34
+ export declare function getBufferSize(): number;
35
+ /**
36
+ * Check if the buffer is full
37
+ */
38
+ export declare function isBufferFull(): boolean;
39
+ /**
40
+ * Clear the buffer (for testing or shutdown)
41
+ */
42
+ export declare function clearBuffer(): void;
43
+ /**
44
+ * Get buffer contents (for testing)
45
+ */
46
+ export declare function _getBuffer(): CapturedEvent[];
47
+ /**
48
+ * Reset buffer state (for testing)
49
+ */
50
+ export declare function _reset(): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Payload compression module
3
+ * Uses CompressionStream API when available
4
+ */
5
+ /**
6
+ * Check if compression is supported
7
+ */
8
+ export declare function isCompressionSupported(): boolean;
9
+ /**
10
+ * Compress a string using gzip
11
+ * Returns the compressed data as a Blob, or null if compression is not supported
12
+ */
13
+ export declare function compressPayload(data: string): Promise<Blob | null>;
14
+ /**
15
+ * Get the size of data in bytes
16
+ */
17
+ export declare function getByteSize(data: string): number;
18
+ /**
19
+ * Check if payload should be compressed (based on size threshold)
20
+ * Only compress if payload is larger than 1KB
21
+ */
22
+ export declare function shouldCompress(data: string): boolean;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * HTTP transport module
3
+ * Handles sending events to the ingest API
4
+ */
5
+ import { EventBatchPayload, ResolvedConfig } from '../types';
6
+ /**
7
+ * Set the configuration
8
+ */
9
+ export declare function setTransportConfig(cfg: ResolvedConfig): void;
10
+ /**
11
+ * Send events to the ingest API
12
+ * Handles compression and retry logic
13
+ */
14
+ export declare function sendEvents(payload: EventBatchPayload): Promise<boolean>;
15
+ /**
16
+ * Get the number of consecutive failures
17
+ */
18
+ export declare function getConsecutiveFailures(): number;
19
+ /**
20
+ * Check if we should stop retrying (3+ consecutive failures)
21
+ */
22
+ export declare function shouldStopRetrying(): boolean;
23
+ /**
24
+ * Reset failure counter (for testing)
25
+ */
26
+ export declare function _resetFailures(): void;
27
+ /**
28
+ * Reset config (for testing)
29
+ */
30
+ export declare function _resetConfig(): void;
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Session Vision Snippet Type Definitions
3
+ */
4
+ /**
5
+ * Autocapture configuration options
6
+ */
7
+ export interface AutocaptureConfig {
8
+ /** Capture $pageview events (default: true) */
9
+ pageview?: boolean;
10
+ /** Capture $click events (default: true) */
11
+ clicks?: boolean;
12
+ /** Capture $form_submit events (default: true) */
13
+ formSubmit?: boolean;
14
+ }
15
+ /**
16
+ * SDK configuration options passed to init()
17
+ */
18
+ export interface SessionVisionConfig {
19
+ /** CDN endpoint for SDK loading (default: 'https://cdn.sessionvision.com') */
20
+ apiHost?: string;
21
+ /** API endpoint for event ingestion and config (default: 'https://app.sessionvision.com') */
22
+ ingestHost?: string;
23
+ /** SDK version to load (default: 'latest') */
24
+ version?: string;
25
+ /** Enable console logging of all events (default: false) */
26
+ debug?: boolean;
27
+ /** Disable all tracking for consent management (default: false) */
28
+ optOut?: boolean;
29
+ /** Mask all input values in recordings (default: true) */
30
+ maskAllInputs?: boolean;
31
+ /** Enable/disable auto-capture (default: true) */
32
+ autocapture?: boolean | AutocaptureConfig;
33
+ }
34
+ /**
35
+ * Internal resolved configuration
36
+ */
37
+ export interface ResolvedConfig {
38
+ projectToken: string;
39
+ apiHost: string;
40
+ ingestHost: string;
41
+ version: string;
42
+ debug: boolean;
43
+ optOut: boolean;
44
+ maskAllInputs: boolean;
45
+ autocapture: {
46
+ pageview: boolean;
47
+ clicks: boolean;
48
+ formSubmit: boolean;
49
+ };
50
+ }
51
+ /**
52
+ * Remote configuration fetched from server
53
+ */
54
+ export interface RemoteConfig {
55
+ recording?: {
56
+ enabled: boolean;
57
+ sampleRate: number;
58
+ };
59
+ session?: {
60
+ timeoutMinutes: number;
61
+ };
62
+ version?: string;
63
+ }
64
+ /**
65
+ * User traits for identify()
66
+ */
67
+ export interface UserTraits {
68
+ email?: string;
69
+ name?: string;
70
+ [key: string]: unknown;
71
+ }
72
+ /**
73
+ * Event properties
74
+ */
75
+ export interface EventProperties {
76
+ [key: string]: unknown;
77
+ }
78
+ /**
79
+ * Automatic properties attached to every event
80
+ */
81
+ export interface AutomaticProperties {
82
+ $current_url: string;
83
+ $referrer: string;
84
+ $browser: string;
85
+ $browser_version: string;
86
+ $os: string;
87
+ $device_type: string;
88
+ $screen_width: number;
89
+ $screen_height: number;
90
+ $viewport_width: number;
91
+ $viewport_height: number;
92
+ $timezone: string;
93
+ $locale: string;
94
+ $connection_type: string | null;
95
+ $lib_version: string;
96
+ }
97
+ /**
98
+ * Internal event structure
99
+ */
100
+ export interface CapturedEvent {
101
+ event: string;
102
+ timestamp: number;
103
+ properties: EventProperties & Partial<AutomaticProperties>;
104
+ anonymousId: string;
105
+ userId: string | null;
106
+ sessionId: string;
107
+ }
108
+ /**
109
+ * Event batch payload sent to server
110
+ */
111
+ export interface EventBatchPayload {
112
+ projectToken: string;
113
+ events: CapturedEvent[];
114
+ }
115
+ /**
116
+ * Click event properties
117
+ */
118
+ export interface ClickEventProperties extends EventProperties {
119
+ $element_tag: string;
120
+ $element_text: string;
121
+ $element_classes: string;
122
+ $element_id: string | null;
123
+ $element_selector: string;
124
+ $element_href: string | null;
125
+ }
126
+ /**
127
+ * Form submit event properties
128
+ */
129
+ export interface FormSubmitEventProperties extends EventProperties {
130
+ $form_id: string | null;
131
+ $form_action: string;
132
+ $form_method: string;
133
+ $form_name: string | null;
134
+ }
135
+ /**
136
+ * Pageview event properties
137
+ */
138
+ export interface PageviewEventProperties extends EventProperties {
139
+ $current_url: string;
140
+ $referrer: string;
141
+ $title: string;
142
+ }
143
+ /**
144
+ * Session data stored in sessionStorage
145
+ */
146
+ export interface SessionData {
147
+ id: string;
148
+ lastActivity: number;
149
+ }
150
+ /**
151
+ * Identity data stored in localStorage
152
+ */
153
+ export interface IdentityData {
154
+ anonymousId: string;
155
+ userId: string | null;
156
+ }
157
+ /**
158
+ * Registered properties stored in localStorage
159
+ */
160
+ export interface RegisteredProperties {
161
+ [key: string]: unknown;
162
+ }
163
+ /**
164
+ * Queued method call before SDK loads
165
+ */
166
+ export interface QueuedCall {
167
+ method: string;
168
+ args: unknown[];
169
+ }
170
+ /**
171
+ * Public API interface
172
+ */
173
+ export interface SessionVisionAPI {
174
+ /** Initialize the SDK with project token and config */
175
+ init(projectToken: string, config?: SessionVisionConfig): void;
176
+ /** Capture a custom event */
177
+ capture(eventName: string, properties?: EventProperties): void;
178
+ /** Identify a user */
179
+ identify(userId: string, traits?: UserTraits): void;
180
+ /** Reset identity (for logout) */
181
+ reset(): void;
182
+ /** Get the current distinct ID (userId if identified, anonymousId otherwise) */
183
+ getDistinctId(): string;
184
+ /** Register properties to be sent with every event */
185
+ register(properties: EventProperties): void;
186
+ /** Register properties only if they don't already exist */
187
+ registerOnce(properties: EventProperties): void;
188
+ /** SDK version */
189
+ version: string;
190
+ /** Internal: queued method calls before SDK loads */
191
+ _q?: QueuedCall[];
192
+ /** Internal: init calls */
193
+ _i?: Array<[string, SessionVisionConfig?]>;
194
+ /** Internal: SDK version marker */
195
+ __SV?: number;
196
+ }
197
+ /**
198
+ * Storage key constants
199
+ */
200
+ export declare const STORAGE_KEYS: {
201
+ readonly ANONYMOUS_ID: "sessionvision_anonymous_id";
202
+ readonly USER_ID: "sessionvision_user_id";
203
+ readonly SESSION: "sessionvision_session";
204
+ readonly REGISTERED_PROPS: "sessionvision_registered";
205
+ readonly REGISTERED_ONCE_PROPS: "sessionvision_registered_once";
206
+ readonly CONFIG_CACHE: "sessionvision_config";
207
+ };
208
+ /**
209
+ * Default configuration values
210
+ */
211
+ export declare const DEFAULT_CONFIG: Omit<ResolvedConfig, 'projectToken'>;
212
+ /**
213
+ * Session timeout in milliseconds (30 minutes)
214
+ */
215
+ export declare const SESSION_TIMEOUT_MS: number;
216
+ /**
217
+ * Event buffer configuration
218
+ */
219
+ export declare const BUFFER_CONFIG: {
220
+ readonly MAX_EVENTS: 10;
221
+ readonly FLUSH_INTERVAL_MS: 5000;
222
+ readonly MAX_RETRIES: 3;
223
+ readonly RETRY_DELAYS_MS: readonly [1000, 2000, 4000];
224
+ };
225
+ /**
226
+ * Config cache TTL in milliseconds (1 hour)
227
+ */
228
+ export declare const CONFIG_CACHE_TTL_MS: number;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * DOM utility functions for element inspection and event handling
3
+ */
4
+ /**
5
+ * Get the visible text content of an element, truncated to maxLength
6
+ */
7
+ export declare function getElementText(element: Element, maxLength?: number): string;
8
+ /**
9
+ * Get CSS classes of an element as a space-separated string
10
+ */
11
+ export declare function getElementClasses(element: Element): string;
12
+ /**
13
+ * Get the tag name of an element in lowercase
14
+ */
15
+ export declare function getElementTag(element: Element): string;
16
+ /**
17
+ * Get the ID of an element, or null if not present
18
+ */
19
+ export declare function getElementId(element: Element): string | null;
20
+ /**
21
+ * Get the href attribute for anchor elements
22
+ */
23
+ export declare function getElementHref(element: Element): string | null;
24
+ /**
25
+ * Check if an element should be ignored for tracking
26
+ */
27
+ export declare function shouldIgnoreElement(element: Element): boolean;
28
+ /**
29
+ * Check if an element is interactive (clickable, input, etc.)
30
+ */
31
+ export declare function isInteractiveElement(element: Element): boolean;
32
+ /**
33
+ * Get the closest interactive parent element
34
+ */
35
+ export declare function getInteractiveParent(element: Element): Element | null;
36
+ /**
37
+ * Safe document ready check
38
+ */
39
+ export declare function onDocumentReady(callback: () => void): void;
40
+ /**
41
+ * Get the current page URL
42
+ */
43
+ export declare function getCurrentUrl(): string;
44
+ /**
45
+ * Get the document referrer
46
+ */
47
+ export declare function getReferrer(): string;
48
+ /**
49
+ * Get the document title
50
+ */
51
+ export declare function getDocumentTitle(): string;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * PII (Personally Identifiable Information) detection utility
3
+ * Detects and masks sensitive data patterns in text
4
+ */
5
+ /**
6
+ * Check if text contains PII
7
+ */
8
+ export declare function containsPII(text: string): boolean;
9
+ /**
10
+ * Mask PII in text
11
+ */
12
+ export declare function maskPII(text: string): string;
13
+ /**
14
+ * Detect which types of PII are present in text
15
+ */
16
+ export declare function detectPIITypes(text: string): string[];
17
+ /**
18
+ * Check if a string looks like a password field value
19
+ * (all masked characters or very short alphanumeric)
20
+ */
21
+ export declare function looksLikePassword(value: string): boolean;
22
+ /**
23
+ * Safely mask a value that might be sensitive
24
+ * Returns masked version if PII detected, original otherwise
25
+ */
26
+ export declare function safeMaskValue(value: string, alwaysMask?: boolean): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * CSS Selector generation utility
3
+ * Generates stable, unique selectors for DOM elements
4
+ */
5
+ /**
6
+ * Generate a CSS selector for an element
7
+ * Priority:
8
+ * 1. data-sessionvision-id attribute
9
+ * 2. ID attribute (if unique)
10
+ * 3. Path-based selector with classes
11
+ */
12
+ export declare function generateSelector(element: Element): string;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Storage utility for localStorage and sessionStorage operations
3
+ * Provides safe access with error handling for environments where storage is unavailable
4
+ */
5
+ /**
6
+ * Check if localStorage is available
7
+ */
8
+ export declare function isLocalStorageAvailable(): boolean;
9
+ /**
10
+ * Check if sessionStorage is available
11
+ */
12
+ export declare function isSessionStorageAvailable(): boolean;
13
+ /**
14
+ * Get a value from localStorage
15
+ */
16
+ export declare function getLocalStorage<T>(key: string): T | null;
17
+ /**
18
+ * Set a value in localStorage
19
+ */
20
+ export declare function setLocalStorage<T>(key: string, value: T): boolean;
21
+ /**
22
+ * Remove a value from localStorage
23
+ */
24
+ export declare function removeLocalStorage(key: string): boolean;
25
+ /**
26
+ * Get a value from sessionStorage
27
+ */
28
+ export declare function getSessionStorage<T>(key: string): T | null;
29
+ /**
30
+ * Set a value in sessionStorage
31
+ */
32
+ export declare function setSessionStorage<T>(key: string, value: T): boolean;
33
+ /**
34
+ * Remove a value from sessionStorage
35
+ */
36
+ export declare function removeSessionStorage(key: string): boolean;
37
+ /**
38
+ * Get a raw string value from localStorage (without JSON parsing)
39
+ */
40
+ export declare function getLocalStorageRaw(key: string): string | null;
41
+ /**
42
+ * Set a raw string value in localStorage (without JSON stringifying)
43
+ */
44
+ export declare function setLocalStorageRaw(key: string, value: string): boolean;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * UUID v4 generation utility
3
+ * Generates cryptographically random UUIDs when available, falls back to Math.random
4
+ */
5
+ /**
6
+ * Generate a UUID v4 string
7
+ * Uses crypto.randomUUID() when available, falls back to manual generation
8
+ */
9
+ export declare function generateUUID(): string;
10
+ /**
11
+ * Validate a UUID string format
12
+ */
13
+ export declare function isValidUUID(uuid: string): boolean;