@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,136 @@
1
+ import { Root } from "react-dom/client";
2
+ //#region src/types.d.ts
3
+ type WidgetSenderType = "visitor" | "operator" | "system";
4
+ interface WidgetConfig {
5
+ brandColor?: string | null;
6
+ greeting?: string | null;
7
+ }
8
+ interface WidgetConversation {
9
+ id: string;
10
+ status: string;
11
+ }
12
+ interface WidgetContact {
13
+ email: string;
14
+ id: string;
15
+ name: string;
16
+ }
17
+ interface WidgetSummary {
18
+ config: WidgetConfig;
19
+ name: string;
20
+ widgetId: string;
21
+ }
22
+ interface WidgetMessage {
23
+ author: string | null;
24
+ body: string;
25
+ createdAt: string;
26
+ id: string;
27
+ senderType: WidgetSenderType;
28
+ }
29
+ interface WidgetSessionPayload {
30
+ contact: WidgetContact;
31
+ conversation: WidgetConversation;
32
+ expiresAt: string;
33
+ messages: WidgetMessage[];
34
+ /** Absolute socket URL returned by Clivly's bootstrap. */
35
+ socketUrl?: string;
36
+ token: string;
37
+ visitorToken: string;
38
+ widget: WidgetSummary;
39
+ }
40
+ interface ChatWidgetVisitor {
41
+ email: string;
42
+ name: string;
43
+ }
44
+ interface GetSessionOptions {
45
+ visitor: ChatWidgetVisitor;
46
+ visitorToken?: string | null;
47
+ widgetId: string;
48
+ }
49
+ type GetSession = (options: GetSessionOptions) => Promise<WidgetSessionPayload>;
50
+ interface WidgetClientCreateMessageEvent {
51
+ body: string;
52
+ id: string;
53
+ type: "message.create";
54
+ }
55
+ interface WidgetSessionReadyEvent {
56
+ conversationId: string;
57
+ type: "session.ready";
58
+ }
59
+ interface WidgetConversationSnapshotEvent {
60
+ messages: WidgetMessage[];
61
+ type: "conversation.snapshot";
62
+ }
63
+ interface WidgetMessageCreatedEvent {
64
+ clientMessageId?: string;
65
+ message: WidgetMessage;
66
+ type: "message.created";
67
+ }
68
+ interface WidgetMessageAckEvent {
69
+ clientMessageId: string;
70
+ message: WidgetMessage;
71
+ type: "message.ack";
72
+ }
73
+ interface WidgetErrorEvent {
74
+ message: string;
75
+ type: "error";
76
+ }
77
+ type WidgetServerEvent = WidgetConversationSnapshotEvent | WidgetErrorEvent | WidgetMessageAckEvent | WidgetMessageCreatedEvent | WidgetSessionReadyEvent;
78
+ //#endregion
79
+ //#region src/transport.d.ts
80
+ interface ChatTransportHandlers {
81
+ onClose: () => void;
82
+ onError: (error: Error) => void;
83
+ onEvent: (event: WidgetServerEvent) => void;
84
+ onOpen?: () => void;
85
+ }
86
+ interface ChatTransportConnection {
87
+ close: () => void;
88
+ sendMessage: (event: WidgetClientCreateMessageEvent) => void;
89
+ }
90
+ interface CreateChatTransportOptions {
91
+ handlers: ChatTransportHandlers;
92
+ session: WidgetSessionPayload;
93
+ }
94
+ type CreateChatTransport = (options: CreateChatTransportOptions) => ChatTransportConnection;
95
+ //#endregion
96
+ //#region src/chat-widget.d.ts
97
+ interface ChatWidgetProps {
98
+ className?: string;
99
+ createTransport?: CreateChatTransport;
100
+ getSession: GetSession;
101
+ initiallyOpen?: boolean;
102
+ launcherLabel?: string;
103
+ storage?: Pick<Storage, "getItem" | "setItem">;
104
+ widgetId: string;
105
+ }
106
+ //#endregion
107
+ //#region src/browser-mount.d.ts
108
+ interface MountChatWidgetOptions$1 extends Omit<ChatWidgetProps, "getSession" | "widgetId"> {
109
+ container: Element | ShadowRoot;
110
+ sessionUrl: string;
111
+ socketUrlTemplate?: string;
112
+ widgetId: string;
113
+ }
114
+ declare function mountChatWidget$1({
115
+ container,
116
+ createTransport,
117
+ sessionUrl,
118
+ socketUrlTemplate,
119
+ widgetId,
120
+ ...props
121
+ }: MountChatWidgetOptions$1): Root;
122
+ interface ScriptMountResult$1 {
123
+ root: Root;
124
+ shadowRoot: ShadowRoot;
125
+ }
126
+ declare function mountChatWidgetScript$1(script?: HTMLScriptElement): ScriptMountResult$1;
127
+ declare function autoMountChatWidgetScript$1(script?: HTMLScriptElement | null): ScriptMountResult$1 | null;
128
+ //#endregion
129
+ //#region src/browser.d.ts
130
+ type MountChatWidgetOptions = MountChatWidgetOptions$1;
131
+ type ScriptMountResult = ScriptMountResult$1;
132
+ declare const mountChatWidget: typeof mountChatWidget$1;
133
+ declare const mountChatWidgetScript: typeof mountChatWidgetScript$1;
134
+ declare const autoMountChatWidgetScript: typeof autoMountChatWidgetScript$1;
135
+ //#endregion
136
+ export { MountChatWidgetOptions, ScriptMountResult, autoMountChatWidgetScript, mountChatWidget, mountChatWidgetScript };
@@ -0,0 +1,136 @@
1
+ import { Root } from "react-dom/client";
2
+ //#region src/types.d.ts
3
+ type WidgetSenderType = "visitor" | "operator" | "system";
4
+ interface WidgetConfig {
5
+ brandColor?: string | null;
6
+ greeting?: string | null;
7
+ }
8
+ interface WidgetConversation {
9
+ id: string;
10
+ status: string;
11
+ }
12
+ interface WidgetContact {
13
+ email: string;
14
+ id: string;
15
+ name: string;
16
+ }
17
+ interface WidgetSummary {
18
+ config: WidgetConfig;
19
+ name: string;
20
+ widgetId: string;
21
+ }
22
+ interface WidgetMessage {
23
+ author: string | null;
24
+ body: string;
25
+ createdAt: string;
26
+ id: string;
27
+ senderType: WidgetSenderType;
28
+ }
29
+ interface WidgetSessionPayload {
30
+ contact: WidgetContact;
31
+ conversation: WidgetConversation;
32
+ expiresAt: string;
33
+ messages: WidgetMessage[];
34
+ /** Absolute socket URL returned by Clivly's bootstrap. */
35
+ socketUrl?: string;
36
+ token: string;
37
+ visitorToken: string;
38
+ widget: WidgetSummary;
39
+ }
40
+ interface ChatWidgetVisitor {
41
+ email: string;
42
+ name: string;
43
+ }
44
+ interface GetSessionOptions {
45
+ visitor: ChatWidgetVisitor;
46
+ visitorToken?: string | null;
47
+ widgetId: string;
48
+ }
49
+ type GetSession = (options: GetSessionOptions) => Promise<WidgetSessionPayload>;
50
+ interface WidgetClientCreateMessageEvent {
51
+ body: string;
52
+ id: string;
53
+ type: "message.create";
54
+ }
55
+ interface WidgetSessionReadyEvent {
56
+ conversationId: string;
57
+ type: "session.ready";
58
+ }
59
+ interface WidgetConversationSnapshotEvent {
60
+ messages: WidgetMessage[];
61
+ type: "conversation.snapshot";
62
+ }
63
+ interface WidgetMessageCreatedEvent {
64
+ clientMessageId?: string;
65
+ message: WidgetMessage;
66
+ type: "message.created";
67
+ }
68
+ interface WidgetMessageAckEvent {
69
+ clientMessageId: string;
70
+ message: WidgetMessage;
71
+ type: "message.ack";
72
+ }
73
+ interface WidgetErrorEvent {
74
+ message: string;
75
+ type: "error";
76
+ }
77
+ type WidgetServerEvent = WidgetConversationSnapshotEvent | WidgetErrorEvent | WidgetMessageAckEvent | WidgetMessageCreatedEvent | WidgetSessionReadyEvent;
78
+ //#endregion
79
+ //#region src/transport.d.ts
80
+ interface ChatTransportHandlers {
81
+ onClose: () => void;
82
+ onError: (error: Error) => void;
83
+ onEvent: (event: WidgetServerEvent) => void;
84
+ onOpen?: () => void;
85
+ }
86
+ interface ChatTransportConnection {
87
+ close: () => void;
88
+ sendMessage: (event: WidgetClientCreateMessageEvent) => void;
89
+ }
90
+ interface CreateChatTransportOptions {
91
+ handlers: ChatTransportHandlers;
92
+ session: WidgetSessionPayload;
93
+ }
94
+ type CreateChatTransport = (options: CreateChatTransportOptions) => ChatTransportConnection;
95
+ //#endregion
96
+ //#region src/chat-widget.d.ts
97
+ interface ChatWidgetProps {
98
+ className?: string;
99
+ createTransport?: CreateChatTransport;
100
+ getSession: GetSession;
101
+ initiallyOpen?: boolean;
102
+ launcherLabel?: string;
103
+ storage?: Pick<Storage, "getItem" | "setItem">;
104
+ widgetId: string;
105
+ }
106
+ //#endregion
107
+ //#region src/browser-mount.d.ts
108
+ interface MountChatWidgetOptions$1 extends Omit<ChatWidgetProps, "getSession" | "widgetId"> {
109
+ container: Element | ShadowRoot;
110
+ sessionUrl: string;
111
+ socketUrlTemplate?: string;
112
+ widgetId: string;
113
+ }
114
+ declare function mountChatWidget$1({
115
+ container,
116
+ createTransport,
117
+ sessionUrl,
118
+ socketUrlTemplate,
119
+ widgetId,
120
+ ...props
121
+ }: MountChatWidgetOptions$1): Root;
122
+ interface ScriptMountResult$1 {
123
+ root: Root;
124
+ shadowRoot: ShadowRoot;
125
+ }
126
+ declare function mountChatWidgetScript$1(script?: HTMLScriptElement): ScriptMountResult$1;
127
+ declare function autoMountChatWidgetScript$1(script?: HTMLScriptElement | null): ScriptMountResult$1 | null;
128
+ //#endregion
129
+ //#region src/browser.d.ts
130
+ type MountChatWidgetOptions = MountChatWidgetOptions$1;
131
+ type ScriptMountResult = ScriptMountResult$1;
132
+ declare const mountChatWidget: typeof mountChatWidget$1;
133
+ declare const mountChatWidgetScript: typeof mountChatWidgetScript$1;
134
+ declare const autoMountChatWidgetScript: typeof autoMountChatWidgetScript$1;
135
+ //#endregion
136
+ export { MountChatWidgetOptions, ScriptMountResult, autoMountChatWidgetScript, mountChatWidget, mountChatWidgetScript };