@clivly/chat-widget 0.3.0-next.6

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.
@@ -0,0 +1,198 @@
1
+ import { Root } from "react-dom/client";
2
+ import { ReactElement } from "react";
3
+
4
+ //#region src/types.d.ts
5
+ type WidgetSenderType = "visitor" | "operator" | "system";
6
+ interface WidgetConfig {
7
+ brandColor?: string | null;
8
+ greeting?: string | null;
9
+ }
10
+ interface WidgetConversation {
11
+ id: string;
12
+ status: string;
13
+ }
14
+ interface WidgetContact {
15
+ email: string;
16
+ id: string;
17
+ name: string;
18
+ }
19
+ interface WidgetSummary {
20
+ config: WidgetConfig;
21
+ name: string;
22
+ widgetId: string;
23
+ }
24
+ interface WidgetMessage {
25
+ author: string | null;
26
+ body: string;
27
+ createdAt: string;
28
+ id: string;
29
+ senderType: WidgetSenderType;
30
+ }
31
+ interface WidgetSessionPayload {
32
+ contact: WidgetContact;
33
+ conversation: WidgetConversation;
34
+ expiresAt: string;
35
+ messages: WidgetMessage[];
36
+ /** Absolute socket URL returned by Clivly's bootstrap. */
37
+ socketUrl?: string;
38
+ token: string;
39
+ visitorToken: string;
40
+ widget: WidgetSummary;
41
+ }
42
+ interface ChatWidgetVisitor {
43
+ email: string;
44
+ name: string;
45
+ }
46
+ interface GetSessionOptions {
47
+ visitor: ChatWidgetVisitor;
48
+ visitorToken?: string | null;
49
+ widgetId: string;
50
+ }
51
+ type GetSession = (options: GetSessionOptions) => Promise<WidgetSessionPayload>;
52
+ interface WidgetClientCreateMessageEvent {
53
+ body: string;
54
+ id: string;
55
+ type: "message.create";
56
+ }
57
+ type WidgetClientEvent = WidgetClientCreateMessageEvent;
58
+ interface WidgetSessionReadyEvent {
59
+ conversationId: string;
60
+ type: "session.ready";
61
+ }
62
+ interface WidgetConversationSnapshotEvent {
63
+ messages: WidgetMessage[];
64
+ type: "conversation.snapshot";
65
+ }
66
+ interface WidgetMessageCreatedEvent {
67
+ clientMessageId?: string;
68
+ message: WidgetMessage;
69
+ type: "message.created";
70
+ }
71
+ interface WidgetMessageAckEvent {
72
+ clientMessageId: string;
73
+ message: WidgetMessage;
74
+ type: "message.ack";
75
+ }
76
+ interface WidgetErrorEvent {
77
+ message: string;
78
+ type: "error";
79
+ }
80
+ type WidgetServerEvent = WidgetConversationSnapshotEvent | WidgetErrorEvent | WidgetMessageAckEvent | WidgetMessageCreatedEvent | WidgetSessionReadyEvent;
81
+ //#endregion
82
+ //#region src/transport.d.ts
83
+ interface ChatTransportHandlers {
84
+ onClose: () => void;
85
+ onError: (error: Error) => void;
86
+ onEvent: (event: WidgetServerEvent) => void;
87
+ onOpen?: () => void;
88
+ }
89
+ interface ChatTransportConnection {
90
+ close: () => void;
91
+ sendMessage: (event: WidgetClientCreateMessageEvent) => void;
92
+ }
93
+ interface CreateChatTransportOptions {
94
+ handlers: ChatTransportHandlers;
95
+ session: WidgetSessionPayload;
96
+ }
97
+ type CreateChatTransport = (options: CreateChatTransportOptions) => ChatTransportConnection;
98
+ interface CreateWebSocketTransportOptions {
99
+ createSocket?: (url: string, protocols?: string | string[]) => WebSocket;
100
+ getProtocols?: (session: WidgetSessionPayload) => string | string[] | undefined;
101
+ resolveUrl: (session: WidgetSessionPayload) => string;
102
+ }
103
+ declare function createWebSocketTransport({
104
+ createSocket,
105
+ getProtocols,
106
+ resolveUrl
107
+ }: CreateWebSocketTransportOptions): CreateChatTransport;
108
+ interface CreateLoopbackTransportOptions {
109
+ operatorName?: string;
110
+ operatorReply?: (body: string) => string | null;
111
+ replyDelayMs?: number;
112
+ }
113
+ declare function createLoopbackTransport({
114
+ operatorName,
115
+ operatorReply,
116
+ replyDelayMs
117
+ }?: CreateLoopbackTransportOptions): CreateChatTransport;
118
+ //#endregion
119
+ //#region src/chat-widget.d.ts
120
+ interface ChatWidgetProps {
121
+ className?: string;
122
+ createTransport?: CreateChatTransport;
123
+ getSession: GetSession;
124
+ initiallyOpen?: boolean;
125
+ launcherLabel?: string;
126
+ storage?: Pick<Storage, "getItem" | "setItem">;
127
+ widgetId: string;
128
+ }
129
+ declare function ChatWidget({
130
+ className,
131
+ createTransport,
132
+ getSession,
133
+ initiallyOpen,
134
+ launcherLabel,
135
+ storage,
136
+ widgetId
137
+ }: ChatWidgetProps): ReactElement;
138
+ declare function ChatLauncher(): null;
139
+ declare function ChatPanel(): null;
140
+ declare function MessageComposer(): null;
141
+ declare function PreChatForm(): null;
142
+ declare function ConversationView(): null;
143
+ //#endregion
144
+ //#region src/browser-mount.d.ts
145
+ interface MountChatWidgetOptions$1 extends Omit<ChatWidgetProps, "getSession" | "widgetId"> {
146
+ container: Element | ShadowRoot;
147
+ sessionUrl: string;
148
+ socketUrlTemplate?: string;
149
+ widgetId: string;
150
+ }
151
+ declare function mountChatWidget$1({
152
+ container,
153
+ createTransport,
154
+ sessionUrl,
155
+ socketUrlTemplate,
156
+ widgetId,
157
+ ...props
158
+ }: MountChatWidgetOptions$1): Root;
159
+ interface ScriptMountResult$1 {
160
+ root: Root;
161
+ shadowRoot: ShadowRoot;
162
+ }
163
+ declare function mountChatWidgetScript$1(script?: HTMLScriptElement): ScriptMountResult$1;
164
+ declare function autoMountChatWidgetScript$1(script?: HTMLScriptElement | null): ScriptMountResult$1 | null;
165
+ //#endregion
166
+ //#region src/clivly-transport.d.ts
167
+ interface CreateClivlyTransportOptions$1 {
168
+ createSocket?: (url: string, protocols?: string | string[]) => WebSocket;
169
+ }
170
+ /**
171
+ * The transport a host app should use against a real Clivly backend.
172
+ *
173
+ * The URL comes from the bootstrap response rather than host configuration, so
174
+ * no host page hardcodes Clivly's hostname and a misconfigured template cannot
175
+ * produce a silently dead socket.
176
+ */
177
+ declare function createClivlyTransport$1(options?: CreateClivlyTransportOptions$1): CreateChatTransport;
178
+ //#endregion
179
+ //#region src/session.d.ts
180
+ interface CreateSessionFetcherOptions {
181
+ fetchImpl?: typeof fetch;
182
+ sessionUrl: string;
183
+ }
184
+ declare function createSessionFetcher({
185
+ fetchImpl,
186
+ sessionUrl
187
+ }: CreateSessionFetcherOptions): GetSession;
188
+ //#endregion
189
+ //#region src/index.d.ts
190
+ type MountChatWidgetOptions = MountChatWidgetOptions$1;
191
+ type ScriptMountResult = ScriptMountResult$1;
192
+ declare const autoMountChatWidgetScript: typeof autoMountChatWidgetScript$1;
193
+ type CreateClivlyTransportOptions = CreateClivlyTransportOptions$1;
194
+ declare const createClivlyTransport: typeof createClivlyTransport$1;
195
+ declare const mountChatWidget: typeof mountChatWidget$1;
196
+ declare const mountChatWidgetScript: typeof mountChatWidgetScript$1;
197
+ //#endregion
198
+ export { ChatLauncher, ChatPanel, type ChatTransportConnection, type ChatTransportHandlers, ChatWidget, type ChatWidgetVisitor, ConversationView, type CreateChatTransport, type CreateChatTransportOptions, CreateClivlyTransportOptions, type CreateLoopbackTransportOptions, type CreateWebSocketTransportOptions, type GetSession, type GetSessionOptions, MessageComposer, MountChatWidgetOptions, PreChatForm, ScriptMountResult, type WidgetClientCreateMessageEvent, type WidgetClientEvent, type WidgetConfig, type WidgetContact, type WidgetConversation, type WidgetConversationSnapshotEvent, type WidgetErrorEvent, type WidgetMessage, type WidgetMessageAckEvent, type WidgetMessageCreatedEvent, type WidgetSenderType, type WidgetServerEvent, type WidgetSessionPayload, type WidgetSessionReadyEvent, type WidgetSummary, autoMountChatWidgetScript, createClivlyTransport, createLoopbackTransport, createSessionFetcher, createWebSocketTransport, mountChatWidget, mountChatWidgetScript };
@@ -0,0 +1,198 @@
1
+ import { Root } from "react-dom/client";
2
+ import { ReactElement } from "react";
3
+
4
+ //#region src/types.d.ts
5
+ type WidgetSenderType = "visitor" | "operator" | "system";
6
+ interface WidgetConfig {
7
+ brandColor?: string | null;
8
+ greeting?: string | null;
9
+ }
10
+ interface WidgetConversation {
11
+ id: string;
12
+ status: string;
13
+ }
14
+ interface WidgetContact {
15
+ email: string;
16
+ id: string;
17
+ name: string;
18
+ }
19
+ interface WidgetSummary {
20
+ config: WidgetConfig;
21
+ name: string;
22
+ widgetId: string;
23
+ }
24
+ interface WidgetMessage {
25
+ author: string | null;
26
+ body: string;
27
+ createdAt: string;
28
+ id: string;
29
+ senderType: WidgetSenderType;
30
+ }
31
+ interface WidgetSessionPayload {
32
+ contact: WidgetContact;
33
+ conversation: WidgetConversation;
34
+ expiresAt: string;
35
+ messages: WidgetMessage[];
36
+ /** Absolute socket URL returned by Clivly's bootstrap. */
37
+ socketUrl?: string;
38
+ token: string;
39
+ visitorToken: string;
40
+ widget: WidgetSummary;
41
+ }
42
+ interface ChatWidgetVisitor {
43
+ email: string;
44
+ name: string;
45
+ }
46
+ interface GetSessionOptions {
47
+ visitor: ChatWidgetVisitor;
48
+ visitorToken?: string | null;
49
+ widgetId: string;
50
+ }
51
+ type GetSession = (options: GetSessionOptions) => Promise<WidgetSessionPayload>;
52
+ interface WidgetClientCreateMessageEvent {
53
+ body: string;
54
+ id: string;
55
+ type: "message.create";
56
+ }
57
+ type WidgetClientEvent = WidgetClientCreateMessageEvent;
58
+ interface WidgetSessionReadyEvent {
59
+ conversationId: string;
60
+ type: "session.ready";
61
+ }
62
+ interface WidgetConversationSnapshotEvent {
63
+ messages: WidgetMessage[];
64
+ type: "conversation.snapshot";
65
+ }
66
+ interface WidgetMessageCreatedEvent {
67
+ clientMessageId?: string;
68
+ message: WidgetMessage;
69
+ type: "message.created";
70
+ }
71
+ interface WidgetMessageAckEvent {
72
+ clientMessageId: string;
73
+ message: WidgetMessage;
74
+ type: "message.ack";
75
+ }
76
+ interface WidgetErrorEvent {
77
+ message: string;
78
+ type: "error";
79
+ }
80
+ type WidgetServerEvent = WidgetConversationSnapshotEvent | WidgetErrorEvent | WidgetMessageAckEvent | WidgetMessageCreatedEvent | WidgetSessionReadyEvent;
81
+ //#endregion
82
+ //#region src/transport.d.ts
83
+ interface ChatTransportHandlers {
84
+ onClose: () => void;
85
+ onError: (error: Error) => void;
86
+ onEvent: (event: WidgetServerEvent) => void;
87
+ onOpen?: () => void;
88
+ }
89
+ interface ChatTransportConnection {
90
+ close: () => void;
91
+ sendMessage: (event: WidgetClientCreateMessageEvent) => void;
92
+ }
93
+ interface CreateChatTransportOptions {
94
+ handlers: ChatTransportHandlers;
95
+ session: WidgetSessionPayload;
96
+ }
97
+ type CreateChatTransport = (options: CreateChatTransportOptions) => ChatTransportConnection;
98
+ interface CreateWebSocketTransportOptions {
99
+ createSocket?: (url: string, protocols?: string | string[]) => WebSocket;
100
+ getProtocols?: (session: WidgetSessionPayload) => string | string[] | undefined;
101
+ resolveUrl: (session: WidgetSessionPayload) => string;
102
+ }
103
+ declare function createWebSocketTransport({
104
+ createSocket,
105
+ getProtocols,
106
+ resolveUrl
107
+ }: CreateWebSocketTransportOptions): CreateChatTransport;
108
+ interface CreateLoopbackTransportOptions {
109
+ operatorName?: string;
110
+ operatorReply?: (body: string) => string | null;
111
+ replyDelayMs?: number;
112
+ }
113
+ declare function createLoopbackTransport({
114
+ operatorName,
115
+ operatorReply,
116
+ replyDelayMs
117
+ }?: CreateLoopbackTransportOptions): CreateChatTransport;
118
+ //#endregion
119
+ //#region src/chat-widget.d.ts
120
+ interface ChatWidgetProps {
121
+ className?: string;
122
+ createTransport?: CreateChatTransport;
123
+ getSession: GetSession;
124
+ initiallyOpen?: boolean;
125
+ launcherLabel?: string;
126
+ storage?: Pick<Storage, "getItem" | "setItem">;
127
+ widgetId: string;
128
+ }
129
+ declare function ChatWidget({
130
+ className,
131
+ createTransport,
132
+ getSession,
133
+ initiallyOpen,
134
+ launcherLabel,
135
+ storage,
136
+ widgetId
137
+ }: ChatWidgetProps): ReactElement;
138
+ declare function ChatLauncher(): null;
139
+ declare function ChatPanel(): null;
140
+ declare function MessageComposer(): null;
141
+ declare function PreChatForm(): null;
142
+ declare function ConversationView(): null;
143
+ //#endregion
144
+ //#region src/browser-mount.d.ts
145
+ interface MountChatWidgetOptions$1 extends Omit<ChatWidgetProps, "getSession" | "widgetId"> {
146
+ container: Element | ShadowRoot;
147
+ sessionUrl: string;
148
+ socketUrlTemplate?: string;
149
+ widgetId: string;
150
+ }
151
+ declare function mountChatWidget$1({
152
+ container,
153
+ createTransport,
154
+ sessionUrl,
155
+ socketUrlTemplate,
156
+ widgetId,
157
+ ...props
158
+ }: MountChatWidgetOptions$1): Root;
159
+ interface ScriptMountResult$1 {
160
+ root: Root;
161
+ shadowRoot: ShadowRoot;
162
+ }
163
+ declare function mountChatWidgetScript$1(script?: HTMLScriptElement): ScriptMountResult$1;
164
+ declare function autoMountChatWidgetScript$1(script?: HTMLScriptElement | null): ScriptMountResult$1 | null;
165
+ //#endregion
166
+ //#region src/clivly-transport.d.ts
167
+ interface CreateClivlyTransportOptions$1 {
168
+ createSocket?: (url: string, protocols?: string | string[]) => WebSocket;
169
+ }
170
+ /**
171
+ * The transport a host app should use against a real Clivly backend.
172
+ *
173
+ * The URL comes from the bootstrap response rather than host configuration, so
174
+ * no host page hardcodes Clivly's hostname and a misconfigured template cannot
175
+ * produce a silently dead socket.
176
+ */
177
+ declare function createClivlyTransport$1(options?: CreateClivlyTransportOptions$1): CreateChatTransport;
178
+ //#endregion
179
+ //#region src/session.d.ts
180
+ interface CreateSessionFetcherOptions {
181
+ fetchImpl?: typeof fetch;
182
+ sessionUrl: string;
183
+ }
184
+ declare function createSessionFetcher({
185
+ fetchImpl,
186
+ sessionUrl
187
+ }: CreateSessionFetcherOptions): GetSession;
188
+ //#endregion
189
+ //#region src/index.d.ts
190
+ type MountChatWidgetOptions = MountChatWidgetOptions$1;
191
+ type ScriptMountResult = ScriptMountResult$1;
192
+ declare const autoMountChatWidgetScript: typeof autoMountChatWidgetScript$1;
193
+ type CreateClivlyTransportOptions = CreateClivlyTransportOptions$1;
194
+ declare const createClivlyTransport: typeof createClivlyTransport$1;
195
+ declare const mountChatWidget: typeof mountChatWidget$1;
196
+ declare const mountChatWidgetScript: typeof mountChatWidgetScript$1;
197
+ //#endregion
198
+ export { ChatLauncher, ChatPanel, type ChatTransportConnection, type ChatTransportHandlers, ChatWidget, type ChatWidgetVisitor, ConversationView, type CreateChatTransport, type CreateChatTransportOptions, CreateClivlyTransportOptions, type CreateLoopbackTransportOptions, type CreateWebSocketTransportOptions, type GetSession, type GetSessionOptions, MessageComposer, MountChatWidgetOptions, PreChatForm, ScriptMountResult, type WidgetClientCreateMessageEvent, type WidgetClientEvent, type WidgetConfig, type WidgetContact, type WidgetConversation, type WidgetConversationSnapshotEvent, type WidgetErrorEvent, type WidgetMessage, type WidgetMessageAckEvent, type WidgetMessageCreatedEvent, type WidgetSenderType, type WidgetServerEvent, type WidgetSessionPayload, type WidgetSessionReadyEvent, type WidgetSummary, autoMountChatWidgetScript, createClivlyTransport, createLoopbackTransport, createSessionFetcher, createWebSocketTransport, mountChatWidget, mountChatWidgetScript };