@malleon/replay 1.0.5

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 ADDED
@@ -0,0 +1,108 @@
1
+ # Replay SDK
2
+
3
+ A JavaScript SDK for capturing and replaying user interactions on web pages.
4
+
5
+ ## Compile
6
+ ## Dev
7
+ clear && npm run dist
8
+ ## Prod
9
+ clear && npm run dist:prod
10
+
11
+ ## Basic Usage
12
+
13
+ ```javascript
14
+ // Initialize replay for an app
15
+ initReplay('your-app-id');
16
+
17
+ // Add tags to the current replay
18
+ addTagToReplay('userType', 'premium', 'STR');
19
+ addTagToReplay('sessionId', 'abc123', 'STR');
20
+ addTagToReplay('isLoggedIn', true, 'BOOL');
21
+ addTagToReplay('loginTime', new Date(), 'DATETIME');
22
+ addTagToReplay('score', 95, 'NUM');
23
+
24
+ // Add multiple tags at once
25
+ addTagsToReplay([
26
+ { name: 'browser', value: 'chrome', type: 'STR' },
27
+ { name: 'device', value: 'desktop', type: 'STR' },
28
+ { name: 'timestamp', value: new Date(), type: 'DATETIME' },
29
+ { name: 'version', value: 2.1, type: 'NUM' }
30
+ ]);
31
+
32
+ // Update user data for the replay
33
+ updateReplayUserData({
34
+ userId: 'user123',
35
+ username: 'john_doe',
36
+ userEmail: 'john@example.com',
37
+ userRole: 'admin',
38
+ userStatus: 'active'
39
+ });
40
+ ```
41
+
42
+ ## API Reference
43
+
44
+ ### `initReplay(appId: string): void`
45
+ Initializes the replay system for the specified app ID. Must be called before using other functions.
46
+
47
+ ### `addTagToReplay(name: string, value: string | number | boolean | Date, type: TagType): Promise<void>`
48
+ Adds a single tag to the current replay. The `type` parameter is required and must match one of the supported tag types.
49
+
50
+ ### `addTagsToReplay(tags: ReplayTag[]): Promise<void>`
51
+ Adds multiple tags to the current replay at once. Each tag must include a `name`, `value`, and `type`.
52
+
53
+ ### `updateReplayUserData(userData: ReplayUserData): Promise<void>`
54
+ Updates user metadata for the current replay. All fields are optional.
55
+
56
+ ## Types and Interfaces
57
+
58
+ All types and interfaces are exported from `./types/replay-types` and can be imported for use in TypeScript projects:
59
+
60
+ ```typescript
61
+ import { TagType, ReplayTag, ReplayUserData } from './types/replay-types';
62
+ ```
63
+
64
+ ### `TagType`
65
+ ```typescript
66
+ type TagType = 'STR' | 'LARGE_STR' | 'NUM' | 'DATETIME' | 'BOOL';
67
+ ```
68
+
69
+ ### `ReplayTag`
70
+ ```typescript
71
+ interface ReplayTag {
72
+ name: string;
73
+ value: string | number | boolean | Date;
74
+ type: TagType;
75
+ }
76
+ ```
77
+
78
+ ### `ReplayUserData`
79
+ ```typescript
80
+ interface ReplayUserData {
81
+ userId?: string;
82
+ username?: string;
83
+ userEmail?: string;
84
+ userRole?: string;
85
+ userStatus?: string;
86
+ }
87
+ ```
88
+
89
+ ## Tag Types
90
+
91
+ The following tag types are supported:
92
+ - `'STR'` - Short string values
93
+ - `'LARGE_STR'` - Long string values
94
+ - `'NUM'` - Numeric values
95
+ - `'DATETIME'` - Date and time values
96
+ - `'BOOL'` - Boolean values (true/false)
97
+
98
+ **Note:** The `ReplayTag` interface now uses `name` instead of `key` to match the backend `TagInput` class exactly, eliminating the need for field mapping.
99
+
100
+ ## Requirements
101
+
102
+ - Must call `initReplay()` first to initialize the replay system
103
+ - Functions will warn if called before initialization
104
+ - All functions are asynchronous and return promises
105
+ - Functions are also available globally on the `window` object
106
+ - Tag functions require a `type` parameter to specify the data type
107
+
108
+
@@ -0,0 +1,21 @@
1
+ import { TagType, ReplayTag, ReplayUserData } from "./types/replay-types";
2
+ declare global {
3
+ interface Window {
4
+ __REPLAY_STARTED__?: boolean;
5
+ __REPLAY_DISABLED__?: boolean;
6
+ __replay__appId?: string;
7
+ addTagsToReplay?: typeof addTagsToReplay;
8
+ addTagToReplay?: typeof addTagToReplay;
9
+ updateReplayUserData?: typeof updateReplayUserData;
10
+ trackStateTransition?: typeof trackStateTransition;
11
+ }
12
+ }
13
+ export declare function initReplay(appId: string, options?: {
14
+ release?: string;
15
+ dist?: string;
16
+ }): void;
17
+ export declare function addTagsToReplay(tags: ReplayTag[]): Promise<void>;
18
+ export declare function addTagToReplay(name: string, value: string | number | boolean | Date, type: TagType): Promise<void>;
19
+ export declare function updateReplayUserData(userData: ReplayUserData): Promise<void>;
20
+ export declare function trackStateTransition(from: string, to: string, trigger: string): void;
21
+ export type { TagType, ReplayTag, ReplayUserData } from "./types/replay-types";