@emplorium/sdk 0.1.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/LICENSE +27 -0
- package/README.md +82 -0
- package/dist/chunk-DYG422DG.mjs +434 -0
- package/dist/chunk-DYG422DG.mjs.map +1 -0
- package/dist/index.d.mts +157 -0
- package/dist/index.d.ts +157 -0
- package/dist/index.js +460 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +7 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/index.d.mts +28 -0
- package/dist/react/index.d.ts +28 -0
- package/dist/react/index.js +550 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +85 -0
- package/dist/react/index.mjs.map +1 -0
- package/package.json +45 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
type EmploriumUser = {
|
|
2
|
+
/**
|
|
3
|
+
* Display name for the visitor (legacy field, prefer firstName/lastName).
|
|
4
|
+
*/
|
|
5
|
+
name?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Visitor's first name. Used for personalized greetings in AI conversations.
|
|
8
|
+
*/
|
|
9
|
+
firstName?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Visitor's last name.
|
|
12
|
+
*/
|
|
13
|
+
lastName?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Visitor's email address.
|
|
16
|
+
*/
|
|
17
|
+
email?: string;
|
|
18
|
+
/**
|
|
19
|
+
* External identifier from host application.
|
|
20
|
+
*/
|
|
21
|
+
externalId?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
type WidgetVisibilityState = "unknown" | "open" | "closed";
|
|
25
|
+
type EmploriumEventMap = {
|
|
26
|
+
ready: void;
|
|
27
|
+
open: void;
|
|
28
|
+
close: void;
|
|
29
|
+
toggle: {
|
|
30
|
+
open: boolean;
|
|
31
|
+
};
|
|
32
|
+
widgetSettingsLoaded: boolean;
|
|
33
|
+
wsInitiated: boolean;
|
|
34
|
+
missedMessages: number;
|
|
35
|
+
launcherProperties: Record<string, unknown>;
|
|
36
|
+
previewOpen: {
|
|
37
|
+
url?: string;
|
|
38
|
+
fileType?: string;
|
|
39
|
+
};
|
|
40
|
+
error: Error;
|
|
41
|
+
};
|
|
42
|
+
type EmploriumConfig = {
|
|
43
|
+
/**
|
|
44
|
+
* Account/site identifier (the same value used in the snippet path).
|
|
45
|
+
*/
|
|
46
|
+
accountId: string;
|
|
47
|
+
/**
|
|
48
|
+
* Override the loader script URL. Defaults to
|
|
49
|
+
* https://widget.emplorium.io/widget-script/${accountId}
|
|
50
|
+
*/
|
|
51
|
+
scriptUrl?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Origin of the widget host (used for postMessage targetOrigin).
|
|
54
|
+
* Derived from scriptUrl if omitted.
|
|
55
|
+
*/
|
|
56
|
+
widgetOrigin?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Additional script attributes to attach to the loader tag.
|
|
59
|
+
*/
|
|
60
|
+
scriptAttributes?: Record<string, string>;
|
|
61
|
+
/**
|
|
62
|
+
* Custom allowed origins for postMessage; the host origin is always allowed.
|
|
63
|
+
*/
|
|
64
|
+
allowedOrigins?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Whether to auto-load the loader script on init.
|
|
67
|
+
*/
|
|
68
|
+
autoLoad?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether to automatically open the widget after the loader is ready.
|
|
71
|
+
*/
|
|
72
|
+
autoOpen?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Logger implementation. Defaults to console-safe no-ops.
|
|
75
|
+
*/
|
|
76
|
+
logger?: Logger;
|
|
77
|
+
/**
|
|
78
|
+
* User identity information to pre-populate.
|
|
79
|
+
* These values are passed to the backend as authoritative visitor data.
|
|
80
|
+
*/
|
|
81
|
+
user?: EmploriumVisitorIdentity;
|
|
82
|
+
/**
|
|
83
|
+
* Control widget visibility. When set to false, the widget is completely hidden.
|
|
84
|
+
* Defaults to true.
|
|
85
|
+
*/
|
|
86
|
+
enabled?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Visitor identity information that can be provided during SDK initialization.
|
|
90
|
+
* When provided, these values are treated as authoritative by backend services.
|
|
91
|
+
*/
|
|
92
|
+
type EmploriumVisitorIdentity = {
|
|
93
|
+
/**
|
|
94
|
+
* Visitor's first name. Used for personalized AI greetings.
|
|
95
|
+
*/
|
|
96
|
+
firstName?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Visitor's last name.
|
|
99
|
+
*/
|
|
100
|
+
lastName?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Visitor's email address.
|
|
103
|
+
*/
|
|
104
|
+
email?: string;
|
|
105
|
+
};
|
|
106
|
+
type EmploriumState = {
|
|
107
|
+
initialized: boolean;
|
|
108
|
+
loaderLoaded: boolean;
|
|
109
|
+
widgetReady: boolean;
|
|
110
|
+
visibility: WidgetVisibilityState;
|
|
111
|
+
};
|
|
112
|
+
type Logger = {
|
|
113
|
+
debug?: (...args: unknown[]) => void;
|
|
114
|
+
info?: (...args: unknown[]) => void;
|
|
115
|
+
warn?: (...args: unknown[]) => void;
|
|
116
|
+
error?: (...args: unknown[]) => void;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
declare class EmploriumClient {
|
|
120
|
+
private readonly config;
|
|
121
|
+
private readonly emitter;
|
|
122
|
+
private readonly logger;
|
|
123
|
+
private readonly bridge;
|
|
124
|
+
private state;
|
|
125
|
+
private initPromise;
|
|
126
|
+
private readyPromise;
|
|
127
|
+
private resolveReady;
|
|
128
|
+
private isEnabled;
|
|
129
|
+
constructor(config: EmploriumConfig);
|
|
130
|
+
init: () => Promise<void>;
|
|
131
|
+
on: <K extends keyof EmploriumEventMap>(event: K, listener: (payload: EmploriumEventMap[K]) => void) => () => void;
|
|
132
|
+
off: <K extends keyof EmploriumEventMap>(event: K, listener: (payload: EmploriumEventMap[K]) => void) => void;
|
|
133
|
+
ready: () => Promise<void>;
|
|
134
|
+
open: () => void;
|
|
135
|
+
close: () => void;
|
|
136
|
+
toggle: () => void;
|
|
137
|
+
setUser: (user: EmploriumUser) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Enable the widget (show it). Only has effect if widget was previously disabled.
|
|
140
|
+
*/
|
|
141
|
+
enable: () => void;
|
|
142
|
+
/**
|
|
143
|
+
* Disable the widget (hide it completely).
|
|
144
|
+
*/
|
|
145
|
+
disable: () => void;
|
|
146
|
+
/**
|
|
147
|
+
* Check if the widget is currently enabled.
|
|
148
|
+
*/
|
|
149
|
+
isWidgetEnabled: () => boolean;
|
|
150
|
+
getState: () => EmploriumState;
|
|
151
|
+
destroy: () => void;
|
|
152
|
+
private bindApiMethods;
|
|
153
|
+
private setVisibility;
|
|
154
|
+
private bindBridgeEvents;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { EmploriumClient, type EmploriumConfig, type EmploriumEventMap, type EmploriumState, type EmploriumUser, type EmploriumVisitorIdentity, type WidgetVisibilityState };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
type EmploriumUser = {
|
|
2
|
+
/**
|
|
3
|
+
* Display name for the visitor (legacy field, prefer firstName/lastName).
|
|
4
|
+
*/
|
|
5
|
+
name?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Visitor's first name. Used for personalized greetings in AI conversations.
|
|
8
|
+
*/
|
|
9
|
+
firstName?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Visitor's last name.
|
|
12
|
+
*/
|
|
13
|
+
lastName?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Visitor's email address.
|
|
16
|
+
*/
|
|
17
|
+
email?: string;
|
|
18
|
+
/**
|
|
19
|
+
* External identifier from host application.
|
|
20
|
+
*/
|
|
21
|
+
externalId?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
type WidgetVisibilityState = "unknown" | "open" | "closed";
|
|
25
|
+
type EmploriumEventMap = {
|
|
26
|
+
ready: void;
|
|
27
|
+
open: void;
|
|
28
|
+
close: void;
|
|
29
|
+
toggle: {
|
|
30
|
+
open: boolean;
|
|
31
|
+
};
|
|
32
|
+
widgetSettingsLoaded: boolean;
|
|
33
|
+
wsInitiated: boolean;
|
|
34
|
+
missedMessages: number;
|
|
35
|
+
launcherProperties: Record<string, unknown>;
|
|
36
|
+
previewOpen: {
|
|
37
|
+
url?: string;
|
|
38
|
+
fileType?: string;
|
|
39
|
+
};
|
|
40
|
+
error: Error;
|
|
41
|
+
};
|
|
42
|
+
type EmploriumConfig = {
|
|
43
|
+
/**
|
|
44
|
+
* Account/site identifier (the same value used in the snippet path).
|
|
45
|
+
*/
|
|
46
|
+
accountId: string;
|
|
47
|
+
/**
|
|
48
|
+
* Override the loader script URL. Defaults to
|
|
49
|
+
* https://widget.emplorium.io/widget-script/${accountId}
|
|
50
|
+
*/
|
|
51
|
+
scriptUrl?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Origin of the widget host (used for postMessage targetOrigin).
|
|
54
|
+
* Derived from scriptUrl if omitted.
|
|
55
|
+
*/
|
|
56
|
+
widgetOrigin?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Additional script attributes to attach to the loader tag.
|
|
59
|
+
*/
|
|
60
|
+
scriptAttributes?: Record<string, string>;
|
|
61
|
+
/**
|
|
62
|
+
* Custom allowed origins for postMessage; the host origin is always allowed.
|
|
63
|
+
*/
|
|
64
|
+
allowedOrigins?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Whether to auto-load the loader script on init.
|
|
67
|
+
*/
|
|
68
|
+
autoLoad?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether to automatically open the widget after the loader is ready.
|
|
71
|
+
*/
|
|
72
|
+
autoOpen?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Logger implementation. Defaults to console-safe no-ops.
|
|
75
|
+
*/
|
|
76
|
+
logger?: Logger;
|
|
77
|
+
/**
|
|
78
|
+
* User identity information to pre-populate.
|
|
79
|
+
* These values are passed to the backend as authoritative visitor data.
|
|
80
|
+
*/
|
|
81
|
+
user?: EmploriumVisitorIdentity;
|
|
82
|
+
/**
|
|
83
|
+
* Control widget visibility. When set to false, the widget is completely hidden.
|
|
84
|
+
* Defaults to true.
|
|
85
|
+
*/
|
|
86
|
+
enabled?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Visitor identity information that can be provided during SDK initialization.
|
|
90
|
+
* When provided, these values are treated as authoritative by backend services.
|
|
91
|
+
*/
|
|
92
|
+
type EmploriumVisitorIdentity = {
|
|
93
|
+
/**
|
|
94
|
+
* Visitor's first name. Used for personalized AI greetings.
|
|
95
|
+
*/
|
|
96
|
+
firstName?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Visitor's last name.
|
|
99
|
+
*/
|
|
100
|
+
lastName?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Visitor's email address.
|
|
103
|
+
*/
|
|
104
|
+
email?: string;
|
|
105
|
+
};
|
|
106
|
+
type EmploriumState = {
|
|
107
|
+
initialized: boolean;
|
|
108
|
+
loaderLoaded: boolean;
|
|
109
|
+
widgetReady: boolean;
|
|
110
|
+
visibility: WidgetVisibilityState;
|
|
111
|
+
};
|
|
112
|
+
type Logger = {
|
|
113
|
+
debug?: (...args: unknown[]) => void;
|
|
114
|
+
info?: (...args: unknown[]) => void;
|
|
115
|
+
warn?: (...args: unknown[]) => void;
|
|
116
|
+
error?: (...args: unknown[]) => void;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
declare class EmploriumClient {
|
|
120
|
+
private readonly config;
|
|
121
|
+
private readonly emitter;
|
|
122
|
+
private readonly logger;
|
|
123
|
+
private readonly bridge;
|
|
124
|
+
private state;
|
|
125
|
+
private initPromise;
|
|
126
|
+
private readyPromise;
|
|
127
|
+
private resolveReady;
|
|
128
|
+
private isEnabled;
|
|
129
|
+
constructor(config: EmploriumConfig);
|
|
130
|
+
init: () => Promise<void>;
|
|
131
|
+
on: <K extends keyof EmploriumEventMap>(event: K, listener: (payload: EmploriumEventMap[K]) => void) => () => void;
|
|
132
|
+
off: <K extends keyof EmploriumEventMap>(event: K, listener: (payload: EmploriumEventMap[K]) => void) => void;
|
|
133
|
+
ready: () => Promise<void>;
|
|
134
|
+
open: () => void;
|
|
135
|
+
close: () => void;
|
|
136
|
+
toggle: () => void;
|
|
137
|
+
setUser: (user: EmploriumUser) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Enable the widget (show it). Only has effect if widget was previously disabled.
|
|
140
|
+
*/
|
|
141
|
+
enable: () => void;
|
|
142
|
+
/**
|
|
143
|
+
* Disable the widget (hide it completely).
|
|
144
|
+
*/
|
|
145
|
+
disable: () => void;
|
|
146
|
+
/**
|
|
147
|
+
* Check if the widget is currently enabled.
|
|
148
|
+
*/
|
|
149
|
+
isWidgetEnabled: () => boolean;
|
|
150
|
+
getState: () => EmploriumState;
|
|
151
|
+
destroy: () => void;
|
|
152
|
+
private bindApiMethods;
|
|
153
|
+
private setVisibility;
|
|
154
|
+
private bindBridgeEvents;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { EmploriumClient, type EmploriumConfig, type EmploriumEventMap, type EmploriumState, type EmploriumUser, type EmploriumVisitorIdentity, type WidgetVisibilityState };
|