@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,53 @@
1
+ /**
2
+ * SDK initialization module
3
+ * Orchestrates the initialization of all SDK components
4
+ */
5
+ import { SessionVisionConfig, ResolvedConfig, UserTraits, EventProperties } from '../types';
6
+ /**
7
+ * Initialize the SDK
8
+ */
9
+ export declare function init(projectToken: string, config?: SessionVisionConfig): Promise<void>;
10
+ /**
11
+ * Capture a custom event
12
+ */
13
+ export declare function capture(eventName: string, properties?: EventProperties): void;
14
+ /**
15
+ * Identify a user
16
+ */
17
+ export declare function identify(userId: string, traits?: UserTraits): void;
18
+ /**
19
+ * Reset user identity (for logout)
20
+ */
21
+ export declare function reset(): void;
22
+ /**
23
+ * Get the current distinct ID
24
+ */
25
+ export declare function getDistinctIdValue(): string;
26
+ /**
27
+ * Register properties to send with every event
28
+ */
29
+ export declare function register(properties: EventProperties): void;
30
+ /**
31
+ * Register properties only if they don't exist
32
+ */
33
+ export declare function registerOnce(properties: EventProperties): void;
34
+ /**
35
+ * Manually flush the event buffer
36
+ */
37
+ export declare function flushEvents(): Promise<void>;
38
+ /**
39
+ * Shutdown the SDK
40
+ */
41
+ export declare function shutdown(): void;
42
+ /**
43
+ * Check if the SDK is initialized
44
+ */
45
+ export declare function isSDKInitialized(): boolean;
46
+ /**
47
+ * Get the current configuration
48
+ */
49
+ export declare function getConfig(): ResolvedConfig | null;
50
+ /**
51
+ * Reset for testing
52
+ */
53
+ export declare function _reset(): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Queue replay module
3
+ * Handles replaying method calls that were queued before SDK loaded
4
+ */
5
+ import { QueuedCall, SessionVisionAPI } from '../types';
6
+ /**
7
+ * Replay queued method calls
8
+ * The stub queues calls like ['capture', 'event_name', {...}] before SDK loads
9
+ */
10
+ export declare function replayQueue(queue: QueuedCall[] | undefined, api: SessionVisionAPI): void;
11
+ /**
12
+ * Parse the legacy array-style queue format
13
+ * PostHog-style: sessionvision._q = [['capture', 'event', {}], ...]
14
+ */
15
+ export declare function parseLegacyQueue(legacyQueue: unknown[][] | undefined): QueuedCall[];
16
+ /**
17
+ * Get init calls from _i array
18
+ */
19
+ export declare function getInitCalls(initArray: Array<[string, unknown?]> | undefined): Array<{
20
+ projectToken: string;
21
+ config?: unknown;
22
+ }>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Anonymous ID management
3
+ * Generates and persists anonymous user identifiers using UUID v4
4
+ */
5
+ /**
6
+ * Get the current anonymous ID, creating one if it doesn't exist
7
+ */
8
+ export declare function getAnonymousId(): string;
9
+ /**
10
+ * Set a specific anonymous ID (used when migrating from another analytics tool)
11
+ */
12
+ export declare function setAnonymousId(id: string): void;
13
+ /**
14
+ * Reset the anonymous ID (generates a new one)
15
+ * Called during reset() when user logs out
16
+ */
17
+ export declare function resetAnonymousId(): string;
18
+ /**
19
+ * Clear the anonymous ID from storage and cache
20
+ * Used internally during full reset
21
+ */
22
+ export declare function clearAnonymousId(): void;
23
+ /**
24
+ * Check if an anonymous ID exists
25
+ */
26
+ export declare function hasAnonymousId(): boolean;
27
+ /**
28
+ * Clear the in-memory cache (for testing)
29
+ */
30
+ export declare function _clearCache(): void;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * User identification management
3
+ * Handles identify() calls and user ID persistence
4
+ */
5
+ import { UserTraits } from '../types';
6
+ /**
7
+ * Set the callback to be called when identify() is invoked
8
+ * Used by the SDK to capture an $identify event
9
+ */
10
+ export declare function setIdentifyCallback(callback: (userId: string, traits?: UserTraits) => void): void;
11
+ /**
12
+ * Get the current user ID, or null if not identified
13
+ */
14
+ export declare function getUserId(): string | null;
15
+ /**
16
+ * Identify a user with an ID and optional traits
17
+ * - Sets the user ID in localStorage
18
+ * - Triggers an $identify event with traits
19
+ * - Forward-only: does not retroactively link past anonymous events
20
+ */
21
+ export declare function identify(userId: string, traits?: UserTraits): void;
22
+ /**
23
+ * Check if a user is currently identified
24
+ */
25
+ export declare function isIdentified(): boolean;
26
+ /**
27
+ * Get the distinct ID (user ID if identified, anonymous ID otherwise)
28
+ */
29
+ export declare function getDistinctId(): string;
30
+ /**
31
+ * Reset user identity
32
+ * - Clears user ID
33
+ * - Generates new anonymous ID
34
+ * - Starts new session
35
+ * Used on logout
36
+ */
37
+ export declare function reset(): void;
38
+ /**
39
+ * Clear the user ID only (without resetting anonymous ID or session)
40
+ * Used internally
41
+ */
42
+ export declare function clearUserId(): void;
43
+ /**
44
+ * Clear the in-memory cache (for testing)
45
+ */
46
+ export declare function _clearCache(): void;
@@ -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,43 @@
1
+ 'use strict';
2
+
3
+ var sessionvision = require('@sessionvision/core');
4
+ var vue = require('vue');
5
+
6
+ const sessionVisionKey = Symbol('SessionVision');
7
+ function createSessionVision(apiKey, options) {
8
+ return {
9
+ install(app) {
10
+ if (typeof window !== 'undefined' && !sessionvision.__SV) {
11
+ sessionvision.init(apiKey, options);
12
+ }
13
+ app.provide(sessionVisionKey, sessionvision);
14
+ },
15
+ };
16
+ }
17
+
18
+ function useSessionVision() {
19
+ const instance = vue.inject(sessionVisionKey);
20
+ if (!instance) {
21
+ throw new Error('useSessionVision must be used after installing the Session Vision plugin. ' +
22
+ 'Call app.use(createSessionVision(...)) before this composable.');
23
+ }
24
+ return instance;
25
+ }
26
+ function useCapture() {
27
+ const sessionvision = useSessionVision();
28
+ return (eventName, properties) => {
29
+ sessionvision.capture(eventName, properties);
30
+ };
31
+ }
32
+ function useIdentify() {
33
+ const sessionvision = useSessionVision();
34
+ return (userId, traits) => {
35
+ sessionvision.identify(userId, traits);
36
+ };
37
+ }
38
+
39
+ exports.createSessionVision = createSessionVision;
40
+ exports.useCapture = useCapture;
41
+ exports.useIdentify = useIdentify;
42
+ exports.useSessionVision = useSessionVision;
43
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../../src/vue/plugin.ts","../../src/vue/composables.ts"],"sourcesContent":[null,null],"names":["inject"],"mappings":";;;;;AAIO,MAAM,gBAAgB,GAAmC,MAAM,CAAC,eAAe,CAAC;AAEjF,SAAU,mBAAmB,CACjC,MAAc,EACd,OAA8C,EAAA;IAE9C,OAAO;AACL,QAAA,OAAO,CAAC,GAAQ,EAAA;YACd,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;AACxD,gBAAA,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YACrC;AAEA,YAAA,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,aAAa,CAAC;QAC9C,CAAC;KACF;AACH;;SCfgB,gBAAgB,GAAA;AAC9B,IAAA,MAAM,QAAQ,GAAGA,UAAM,CAAC,gBAAgB,CAAC;IAEzC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CACb,4EAA4E;AAC1E,YAAA,gEAAgE,CACnE;IACH;AAEA,IAAA,OAAO,QAAQ;AACjB;SAEgB,UAAU,GAAA;AACxB,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;AAExC,IAAA,OAAO,CAAC,SAAiB,EAAE,UAA4B,KAAI;AACzD,QAAA,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC;AAC9C,IAAA,CAAC;AACH;SAEgB,WAAW,GAAA;AACzB,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;AAExC,IAAA,OAAO,CAAC,MAAc,EAAE,MAAmB,KAAI;AAC7C,QAAA,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACxC,IAAA,CAAC;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,38 @@
1
+ import sessionvision from '@sessionvision/core';
2
+ import { inject } from 'vue';
3
+
4
+ const sessionVisionKey = Symbol('SessionVision');
5
+ function createSessionVision(apiKey, options) {
6
+ return {
7
+ install(app) {
8
+ if (typeof window !== 'undefined' && !sessionvision.__SV) {
9
+ sessionvision.init(apiKey, options);
10
+ }
11
+ app.provide(sessionVisionKey, sessionvision);
12
+ },
13
+ };
14
+ }
15
+
16
+ function useSessionVision() {
17
+ const instance = inject(sessionVisionKey);
18
+ if (!instance) {
19
+ throw new Error('useSessionVision must be used after installing the Session Vision plugin. ' +
20
+ 'Call app.use(createSessionVision(...)) before this composable.');
21
+ }
22
+ return instance;
23
+ }
24
+ function useCapture() {
25
+ const sessionvision = useSessionVision();
26
+ return (eventName, properties) => {
27
+ sessionvision.capture(eventName, properties);
28
+ };
29
+ }
30
+ function useIdentify() {
31
+ const sessionvision = useSessionVision();
32
+ return (userId, traits) => {
33
+ sessionvision.identify(userId, traits);
34
+ };
35
+ }
36
+
37
+ export { createSessionVision, useCapture, useIdentify, useSessionVision };
38
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../../src/vue/plugin.ts","../../src/vue/composables.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;;AAIO,MAAM,gBAAgB,GAAmC,MAAM,CAAC,eAAe,CAAC;AAEjF,SAAU,mBAAmB,CACjC,MAAc,EACd,OAA8C,EAAA;IAE9C,OAAO;AACL,QAAA,OAAO,CAAC,GAAQ,EAAA;YACd,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;AACxD,gBAAA,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YACrC;AAEA,YAAA,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,aAAa,CAAC;QAC9C,CAAC;KACF;AACH;;SCfgB,gBAAgB,GAAA;AAC9B,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAEzC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CACb,4EAA4E;AAC1E,YAAA,gEAAgE,CACnE;IACH;AAEA,IAAA,OAAO,QAAQ;AACjB;SAEgB,UAAU,GAAA;AACxB,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;AAExC,IAAA,OAAO,CAAC,SAAiB,EAAE,UAA4B,KAAI;AACzD,QAAA,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC;AAC9C,IAAA,CAAC;AACH;SAEgB,WAAW,GAAA;AACzB,IAAA,MAAM,aAAa,GAAG,gBAAgB,EAAE;AAExC,IAAA,OAAO,CAAC,MAAc,EAAE,MAAmB,KAAI;AAC7C,QAAA,aAAa,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;AACxC,IAAA,CAAC;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;