@scalemule/chat 0.0.4 → 0.0.7
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/dist/{ChatClient-COmdEJ11.d.ts → ChatClient-DQPHdUHX.d.cts} +21 -2
- package/dist/{ChatClient-BoZaTtyM.d.cts → ChatClient-DtUKF-4c.d.ts} +21 -2
- package/dist/chat.embed.global.js +1 -1
- package/dist/chat.umd.global.js +288 -12
- package/dist/{chunk-ZLMMNFZL.js → chunk-5O5YLRJL.js} +386 -16
- package/dist/chunk-GTMAK3IA.js +285 -0
- package/dist/chunk-TRCELAZQ.cjs +287 -0
- package/dist/{chunk-YDLRISR7.cjs → chunk-W2PWFS3E.cjs} +386 -15
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core/ChatClient.d.ts +96 -0
- package/dist/core/ChatClient.d.ts.map +1 -0
- package/dist/core/EventEmitter.d.ts +11 -0
- package/dist/core/EventEmitter.d.ts.map +1 -0
- package/dist/core/MessageCache.d.ts +18 -0
- package/dist/core/MessageCache.d.ts.map +1 -0
- package/dist/core/OfflineQueue.d.ts +19 -0
- package/dist/core/OfflineQueue.d.ts.map +1 -0
- package/dist/element.cjs +542 -51
- package/dist/element.d.ts +2 -2
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +541 -50
- package/dist/embed/index.d.ts +2 -0
- package/dist/embed/index.d.ts.map +1 -0
- package/dist/factory.d.ts +8 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/iframe.d.cts +1 -1
- package/dist/iframe.d.ts +3 -5
- package/dist/iframe.d.ts.map +1 -0
- package/dist/index.cjs +34 -5
- package/dist/index.d.cts +93 -4
- package/dist/index.d.ts +8 -77
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -4
- package/dist/react-components/ChatInput.d.ts +16 -0
- package/dist/react-components/ChatInput.d.ts.map +1 -0
- package/dist/react-components/ChatMessageItem.d.ts +13 -0
- package/dist/react-components/ChatMessageItem.d.ts.map +1 -0
- package/dist/react-components/ChatMessageList.d.ts +15 -0
- package/dist/react-components/ChatMessageList.d.ts.map +1 -0
- package/dist/react-components/ChatThread.d.ts +12 -0
- package/dist/react-components/ChatThread.d.ts.map +1 -0
- package/dist/react-components/ConversationList.d.ts +13 -0
- package/dist/react-components/ConversationList.d.ts.map +1 -0
- package/dist/react-components/EmojiPicker.d.ts +8 -0
- package/dist/react-components/EmojiPicker.d.ts.map +1 -0
- package/dist/react-components/index.d.ts +8 -0
- package/dist/react-components/index.d.ts.map +1 -0
- package/dist/react-components/theme.d.ts +19 -0
- package/dist/react-components/theme.d.ts.map +1 -0
- package/dist/react-components/utils.d.ts +4 -0
- package/dist/react-components/utils.d.ts.map +1 -0
- package/dist/react.cjs +1213 -53
- package/dist/react.d.cts +100 -4
- package/dist/react.d.ts +38 -15
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +1167 -18
- package/dist/shared/ChatController.d.ts +65 -0
- package/dist/shared/ChatController.d.ts.map +1 -0
- package/dist/shared/upload.d.ts +3 -0
- package/dist/shared/upload.d.ts.map +1 -0
- package/dist/support-widget.global.js +485 -157
- package/dist/support.d.ts +99 -0
- package/dist/support.d.ts.map +1 -0
- package/dist/transport/HttpTransport.d.ts +20 -0
- package/dist/transport/HttpTransport.d.ts.map +1 -0
- package/dist/transport/WebSocketTransport.d.ts +78 -0
- package/dist/transport/WebSocketTransport.d.ts.map +1 -0
- package/dist/{types-BmD7f1gV.d.cts → types-COPVrm3K.d.cts} +25 -1
- package/dist/{types-BmD7f1gV.d.ts → types-COPVrm3K.d.ts} +25 -1
- package/dist/types.d.ts +271 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/umd.d.ts +6 -0
- package/dist/umd.d.ts.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/widget/icons.d.ts +8 -0
- package/dist/widget/icons.d.ts.map +1 -0
- package/dist/widget/index.d.ts +2 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/storage.d.ts +5 -0
- package/dist/widget/storage.d.ts.map +1 -0
- package/dist/widget/styles.d.ts +3 -0
- package/dist/widget/styles.d.ts.map +1 -0
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTRCELAZQ_cjs = require('./chunk-TRCELAZQ.cjs');
|
|
4
|
+
var chunkW2PWFS3E_cjs = require('./chunk-W2PWFS3E.cjs');
|
|
4
5
|
|
|
5
6
|
// src/support.ts
|
|
6
7
|
var STORAGE_PREFIX = "sm_support_";
|
|
@@ -13,6 +14,7 @@ var SupportClient = class {
|
|
|
13
14
|
this.userId = null;
|
|
14
15
|
this.apiKey = config.apiKey;
|
|
15
16
|
this.apiBaseUrl = config.apiBaseUrl ?? "https://api.scalemule.com";
|
|
17
|
+
this.wsUrl = config.wsUrl;
|
|
16
18
|
this.storageKey = STORAGE_PREFIX + config.apiKey.substring(0, 8);
|
|
17
19
|
const stored = this.loadState();
|
|
18
20
|
if (stored) {
|
|
@@ -79,7 +81,9 @@ var SupportClient = class {
|
|
|
79
81
|
name: this.visitorName,
|
|
80
82
|
email: this.visitorEmail,
|
|
81
83
|
page_url: meta?.page_url ?? (typeof location !== "undefined" ? location.href : void 0),
|
|
82
|
-
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
|
|
84
|
+
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
85
|
+
attachments: meta?.attachments,
|
|
86
|
+
metadata: meta?.metadata
|
|
83
87
|
})
|
|
84
88
|
});
|
|
85
89
|
if (!resp.ok) {
|
|
@@ -111,6 +115,20 @@ var SupportClient = class {
|
|
|
111
115
|
}
|
|
112
116
|
return active ?? null;
|
|
113
117
|
}
|
|
118
|
+
/** Fetch widget configuration and live support availability. */
|
|
119
|
+
async getWidgetConfig() {
|
|
120
|
+
const resp = await fetch(`${this.apiBaseUrl}/v1/chat/support/widget/config`, {
|
|
121
|
+
headers: {
|
|
122
|
+
"x-api-key": this.apiKey
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
if (!resp.ok) {
|
|
126
|
+
const body = await resp.text();
|
|
127
|
+
throw new Error(`Get widget config failed: ${resp.status} ${body}`);
|
|
128
|
+
}
|
|
129
|
+
const result = await resp.json();
|
|
130
|
+
return result.data;
|
|
131
|
+
}
|
|
114
132
|
/** Get the underlying ChatClient for messaging, events, typing indicators, etc. */
|
|
115
133
|
get chat() {
|
|
116
134
|
if (!this.chatClient) {
|
|
@@ -122,6 +140,12 @@ var SupportClient = class {
|
|
|
122
140
|
get isInitialized() {
|
|
123
141
|
return this.chatClient !== null;
|
|
124
142
|
}
|
|
143
|
+
connect() {
|
|
144
|
+
this.chat.connect();
|
|
145
|
+
}
|
|
146
|
+
disconnect() {
|
|
147
|
+
this.chat.disconnect();
|
|
148
|
+
}
|
|
125
149
|
/** The visitor's user ID (available after initVisitorSession). */
|
|
126
150
|
get visitorUserId() {
|
|
127
151
|
return this.userId;
|
|
@@ -139,6 +163,7 @@ var SupportClient = class {
|
|
|
139
163
|
const config = {
|
|
140
164
|
apiKey: this.apiKey,
|
|
141
165
|
apiBaseUrl: this.apiBaseUrl,
|
|
166
|
+
wsUrl: this.wsUrl,
|
|
142
167
|
// Proactive token refresh: check expiry before each request.
|
|
143
168
|
// HttpTransport and WebSocketTransport call getToken() once per request
|
|
144
169
|
// and do NOT retry on 401/null, so the token must be valid when returned.
|
|
@@ -153,7 +178,7 @@ var SupportClient = class {
|
|
|
153
178
|
return this.accessToken;
|
|
154
179
|
}
|
|
155
180
|
};
|
|
156
|
-
this.chatClient = new
|
|
181
|
+
this.chatClient = new chunkW2PWFS3E_cjs.ChatClient(config);
|
|
157
182
|
}
|
|
158
183
|
async refreshAccessToken() {
|
|
159
184
|
if (!this.refreshToken) throw new Error("No refresh token");
|
|
@@ -198,11 +223,15 @@ var SupportClient = class {
|
|
|
198
223
|
};
|
|
199
224
|
|
|
200
225
|
// src/version.ts
|
|
201
|
-
var CHAT_VERSION = "0.0.
|
|
226
|
+
var CHAT_VERSION = "0.0.7";
|
|
202
227
|
|
|
228
|
+
Object.defineProperty(exports, "ChatController", {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
get: function () { return chunkTRCELAZQ_cjs.ChatController; }
|
|
231
|
+
});
|
|
203
232
|
Object.defineProperty(exports, "ChatClient", {
|
|
204
233
|
enumerable: true,
|
|
205
|
-
get: function () { return
|
|
234
|
+
get: function () { return chunkW2PWFS3E_cjs.ChatClient; }
|
|
206
235
|
});
|
|
207
236
|
exports.CHAT_VERSION = CHAT_VERSION;
|
|
208
237
|
exports.SupportClient = SupportClient;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { C as ChatClient } from './ChatClient-
|
|
2
|
-
|
|
1
|
+
import { C as ChatClient, E as EventEmitter } from './ChatClient-DQPHdUHX.cjs';
|
|
2
|
+
import { f as Attachment, e as ChatMessage, R as ReadStatus, A as ApiResponse } from './types-COPVrm3K.cjs';
|
|
3
|
+
export { k as ApiError, g as ChannelSettings, h as ChannelWithSettings, C as ChatConfig, a as ChatEventMap, l as ChatReaction, b as ConnectionStatus, d as Conversation, c as CreateConversationOptions, i as CreateEphemeralChannelOptions, j as CreateLargeRoomOptions, G as GetMessagesOptions, L as ListConversationsOptions, m as MessageEditedEvent, M as MessagesResponse, P as Participant, n as PresenceMember, o as ReactionEvent, p as ReactionSummary, S as SendMessageOptions, U as UnreadTotalResponse } from './types-COPVrm3K.cjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* SupportClient — High-level client for the support chat widget.
|
|
@@ -30,14 +31,35 @@ interface SupportConversation {
|
|
|
30
31
|
created_at: string;
|
|
31
32
|
existing?: boolean;
|
|
32
33
|
}
|
|
34
|
+
interface SupportWidgetPreChatField {
|
|
35
|
+
key: string;
|
|
36
|
+
label: string;
|
|
37
|
+
type: string;
|
|
38
|
+
required: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface SupportWidgetConfig {
|
|
41
|
+
title: string;
|
|
42
|
+
subtitle: string;
|
|
43
|
+
primary_color: string;
|
|
44
|
+
position: 'left' | 'right';
|
|
45
|
+
pre_chat_fields: SupportWidgetPreChatField[];
|
|
46
|
+
business_hours: Record<string, unknown>;
|
|
47
|
+
realtime_enabled: boolean;
|
|
48
|
+
welcome_message: string;
|
|
49
|
+
offline_message: string;
|
|
50
|
+
reps_online: boolean;
|
|
51
|
+
online_count: number;
|
|
52
|
+
}
|
|
33
53
|
interface SupportClientConfig {
|
|
34
54
|
apiKey: string;
|
|
35
55
|
apiBaseUrl?: string;
|
|
56
|
+
wsUrl?: string;
|
|
36
57
|
}
|
|
37
58
|
declare class SupportClient {
|
|
38
59
|
private chatClient;
|
|
39
60
|
private apiKey;
|
|
40
61
|
private apiBaseUrl;
|
|
62
|
+
private wsUrl?;
|
|
41
63
|
private storageKey;
|
|
42
64
|
private anonymousId;
|
|
43
65
|
private refreshToken;
|
|
@@ -55,13 +77,19 @@ declare class SupportClient {
|
|
|
55
77
|
/** Start a new support conversation with the first message. */
|
|
56
78
|
startConversation(message: string, meta?: {
|
|
57
79
|
page_url?: string;
|
|
80
|
+
attachments?: Attachment[];
|
|
81
|
+
metadata?: Record<string, unknown>;
|
|
58
82
|
}): Promise<SupportConversation>;
|
|
59
83
|
/** Get the visitor's active/waiting support conversation, if any. */
|
|
60
84
|
getActiveConversation(): Promise<SupportConversation | null>;
|
|
85
|
+
/** Fetch widget configuration and live support availability. */
|
|
86
|
+
getWidgetConfig(): Promise<SupportWidgetConfig>;
|
|
61
87
|
/** Get the underlying ChatClient for messaging, events, typing indicators, etc. */
|
|
62
88
|
get chat(): ChatClient;
|
|
63
89
|
/** Whether a visitor session has been initialized. */
|
|
64
90
|
get isInitialized(): boolean;
|
|
91
|
+
connect(): void;
|
|
92
|
+
disconnect(): void;
|
|
65
93
|
/** The visitor's user ID (available after initVisitorSession). */
|
|
66
94
|
get visitorUserId(): string | null;
|
|
67
95
|
/** Clean up all resources. */
|
|
@@ -72,6 +100,67 @@ declare class SupportClient {
|
|
|
72
100
|
private saveState;
|
|
73
101
|
}
|
|
74
102
|
|
|
75
|
-
|
|
103
|
+
interface PresenceStateMember {
|
|
104
|
+
userId: string;
|
|
105
|
+
status: string;
|
|
106
|
+
userData?: unknown;
|
|
107
|
+
}
|
|
108
|
+
interface ChatControllerInitOptions {
|
|
109
|
+
realtime?: boolean;
|
|
110
|
+
presence?: boolean;
|
|
111
|
+
}
|
|
112
|
+
interface ChatControllerState {
|
|
113
|
+
conversationId: string;
|
|
114
|
+
messages: ChatMessage[];
|
|
115
|
+
readStatuses: ReadStatus[];
|
|
116
|
+
typingUsers: string[];
|
|
117
|
+
members: PresenceStateMember[];
|
|
118
|
+
hasMore: boolean;
|
|
119
|
+
isLoading: boolean;
|
|
120
|
+
error: string | null;
|
|
121
|
+
}
|
|
122
|
+
interface ChatControllerEvents {
|
|
123
|
+
state: ChatControllerState;
|
|
124
|
+
ready: ChatControllerState;
|
|
125
|
+
error: {
|
|
126
|
+
message: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
declare class ChatController extends EventEmitter<ChatControllerEvents> {
|
|
130
|
+
private readonly client;
|
|
131
|
+
private readonly conversationId;
|
|
132
|
+
private readonly typingTimers;
|
|
133
|
+
private unsubscribers;
|
|
134
|
+
private state;
|
|
135
|
+
constructor(client: ChatClient, conversationId: string);
|
|
136
|
+
getState(): ChatControllerState;
|
|
137
|
+
init(options?: ChatControllerInitOptions): Promise<ChatControllerState>;
|
|
138
|
+
loadMore(): Promise<void>;
|
|
139
|
+
sendMessage(content: string, attachments?: Attachment[]): Promise<void>;
|
|
140
|
+
stageOptimisticMessage(message: ChatMessage): ChatMessage;
|
|
141
|
+
uploadAttachment(file: File | Blob, onProgress?: (percent: number) => void, signal?: AbortSignal): Promise<ApiResponse<Attachment>>;
|
|
142
|
+
refreshAttachmentUrl(messageId: string, fileId: string): Promise<ApiResponse<{
|
|
143
|
+
url: string;
|
|
144
|
+
}>>;
|
|
145
|
+
addReaction(messageId: string, emoji: string): Promise<void>;
|
|
146
|
+
removeReaction(messageId: string, emoji: string): Promise<void>;
|
|
147
|
+
reportMessage(messageId: string, reason: 'spam' | 'harassment' | 'hate' | 'violence' | 'other', description?: string): Promise<ApiResponse<{
|
|
148
|
+
reported: boolean;
|
|
149
|
+
}>>;
|
|
150
|
+
muteConversation(mutedUntil?: string): Promise<ApiResponse<{
|
|
151
|
+
muted: boolean;
|
|
152
|
+
}>>;
|
|
153
|
+
unmuteConversation(): Promise<ApiResponse<{
|
|
154
|
+
muted: boolean;
|
|
155
|
+
}>>;
|
|
156
|
+
markRead(): Promise<void>;
|
|
157
|
+
refreshReadStatus(): Promise<ReadStatus[]>;
|
|
158
|
+
sendTyping(isTyping?: boolean): void;
|
|
159
|
+
destroy(): void;
|
|
160
|
+
private bindEvents;
|
|
161
|
+
private patchState;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
declare const CHAT_VERSION = "0.0.7";
|
|
76
165
|
|
|
77
|
-
export { CHAT_VERSION, ChatClient, SupportClient, type SupportClientConfig, type SupportConversation };
|
|
166
|
+
export { ApiResponse, Attachment, CHAT_VERSION, ChatClient, ChatController, type ChatControllerState, ChatMessage, ReadStatus, SupportClient, type SupportClientConfig, type SupportConversation, type SupportWidgetConfig, type SupportWidgetPreChatField };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,77 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* ```ts
|
|
12
|
-
* const support = new SupportClient({ apiKey: 'pb_...', apiBaseUrl: 'https://api.scalemule.com' });
|
|
13
|
-
* await support.initVisitorSession({ name: 'Jane' });
|
|
14
|
-
* const conversation = await support.startConversation('Hi, I need help!', { page_url: location.href });
|
|
15
|
-
* support.chat.on('message', (msg) => console.log(msg));
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
interface SupportConversation {
|
|
20
|
-
id: string;
|
|
21
|
-
conversation_id: string;
|
|
22
|
-
status: string;
|
|
23
|
-
visitor_name?: string;
|
|
24
|
-
visitor_email?: string;
|
|
25
|
-
visitor_page_url?: string;
|
|
26
|
-
assigned_rep_id?: string;
|
|
27
|
-
assigned_rep_name?: string;
|
|
28
|
-
last_message_preview?: string;
|
|
29
|
-
last_message_at?: string;
|
|
30
|
-
created_at: string;
|
|
31
|
-
existing?: boolean;
|
|
32
|
-
}
|
|
33
|
-
interface SupportClientConfig {
|
|
34
|
-
apiKey: string;
|
|
35
|
-
apiBaseUrl?: string;
|
|
36
|
-
}
|
|
37
|
-
declare class SupportClient {
|
|
38
|
-
private chatClient;
|
|
39
|
-
private apiKey;
|
|
40
|
-
private apiBaseUrl;
|
|
41
|
-
private storageKey;
|
|
42
|
-
private anonymousId;
|
|
43
|
-
private refreshToken;
|
|
44
|
-
private accessToken;
|
|
45
|
-
private tokenExpiresAt;
|
|
46
|
-
private userId;
|
|
47
|
-
private visitorName;
|
|
48
|
-
private visitorEmail;
|
|
49
|
-
constructor(config: SupportClientConfig);
|
|
50
|
-
/** Create or restore a visitor session. Call before startConversation(). */
|
|
51
|
-
initVisitorSession(info?: {
|
|
52
|
-
name?: string;
|
|
53
|
-
email?: string;
|
|
54
|
-
}): Promise<void>;
|
|
55
|
-
/** Start a new support conversation with the first message. */
|
|
56
|
-
startConversation(message: string, meta?: {
|
|
57
|
-
page_url?: string;
|
|
58
|
-
}): Promise<SupportConversation>;
|
|
59
|
-
/** Get the visitor's active/waiting support conversation, if any. */
|
|
60
|
-
getActiveConversation(): Promise<SupportConversation | null>;
|
|
61
|
-
/** Get the underlying ChatClient for messaging, events, typing indicators, etc. */
|
|
62
|
-
get chat(): ChatClient;
|
|
63
|
-
/** Whether a visitor session has been initialized. */
|
|
64
|
-
get isInitialized(): boolean;
|
|
65
|
-
/** The visitor's user ID (available after initVisitorSession). */
|
|
66
|
-
get visitorUserId(): string | null;
|
|
67
|
-
/** Clean up all resources. */
|
|
68
|
-
destroy(): void;
|
|
69
|
-
private initChatClient;
|
|
70
|
-
private refreshAccessToken;
|
|
71
|
-
private loadState;
|
|
72
|
-
private saveState;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
declare const CHAT_VERSION = "0.0.1";
|
|
76
|
-
|
|
77
|
-
export { CHAT_VERSION, ChatClient, SupportClient, type SupportClientConfig, type SupportConversation };
|
|
1
|
+
export { ChatClient } from './core/ChatClient';
|
|
2
|
+
export { SupportClient } from './support';
|
|
3
|
+
export { ChatController } from './shared/ChatController';
|
|
4
|
+
export type { SupportConversation, SupportClientConfig, SupportWidgetConfig, SupportWidgetPreChatField, } from './support';
|
|
5
|
+
export type { ChatControllerState } from './shared/ChatController';
|
|
6
|
+
export { CHAT_VERSION } from './version';
|
|
7
|
+
export type { ApiError, ApiResponse, Attachment, ChannelSettings, ChannelWithSettings, ChatConfig, ChatEventMap, ChatMessage, ChatReaction, ConnectionStatus, Conversation, CreateConversationOptions, CreateEphemeralChannelOptions, CreateLargeRoomOptions, GetMessagesOptions, ListConversationsOptions, MessageEditedEvent, MessagesResponse, Participant, PresenceMember, ReactionEvent, ReactionSummary, ReadStatus, SendMessageOptions, UnreadTotalResponse, } from './types';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EACV,QAAQ,EACR,WAAW,EACX,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,yBAAyB,EACzB,6BAA6B,EAC7B,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,aAAa,EACb,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { ChatController } from './chunk-GTMAK3IA.js';
|
|
2
|
+
import { ChatClient } from './chunk-5O5YLRJL.js';
|
|
3
|
+
export { ChatClient } from './chunk-5O5YLRJL.js';
|
|
3
4
|
|
|
4
5
|
// src/support.ts
|
|
5
6
|
var STORAGE_PREFIX = "sm_support_";
|
|
@@ -12,6 +13,7 @@ var SupportClient = class {
|
|
|
12
13
|
this.userId = null;
|
|
13
14
|
this.apiKey = config.apiKey;
|
|
14
15
|
this.apiBaseUrl = config.apiBaseUrl ?? "https://api.scalemule.com";
|
|
16
|
+
this.wsUrl = config.wsUrl;
|
|
15
17
|
this.storageKey = STORAGE_PREFIX + config.apiKey.substring(0, 8);
|
|
16
18
|
const stored = this.loadState();
|
|
17
19
|
if (stored) {
|
|
@@ -78,7 +80,9 @@ var SupportClient = class {
|
|
|
78
80
|
name: this.visitorName,
|
|
79
81
|
email: this.visitorEmail,
|
|
80
82
|
page_url: meta?.page_url ?? (typeof location !== "undefined" ? location.href : void 0),
|
|
81
|
-
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
|
|
83
|
+
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
84
|
+
attachments: meta?.attachments,
|
|
85
|
+
metadata: meta?.metadata
|
|
82
86
|
})
|
|
83
87
|
});
|
|
84
88
|
if (!resp.ok) {
|
|
@@ -110,6 +114,20 @@ var SupportClient = class {
|
|
|
110
114
|
}
|
|
111
115
|
return active ?? null;
|
|
112
116
|
}
|
|
117
|
+
/** Fetch widget configuration and live support availability. */
|
|
118
|
+
async getWidgetConfig() {
|
|
119
|
+
const resp = await fetch(`${this.apiBaseUrl}/v1/chat/support/widget/config`, {
|
|
120
|
+
headers: {
|
|
121
|
+
"x-api-key": this.apiKey
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
if (!resp.ok) {
|
|
125
|
+
const body = await resp.text();
|
|
126
|
+
throw new Error(`Get widget config failed: ${resp.status} ${body}`);
|
|
127
|
+
}
|
|
128
|
+
const result = await resp.json();
|
|
129
|
+
return result.data;
|
|
130
|
+
}
|
|
113
131
|
/** Get the underlying ChatClient for messaging, events, typing indicators, etc. */
|
|
114
132
|
get chat() {
|
|
115
133
|
if (!this.chatClient) {
|
|
@@ -121,6 +139,12 @@ var SupportClient = class {
|
|
|
121
139
|
get isInitialized() {
|
|
122
140
|
return this.chatClient !== null;
|
|
123
141
|
}
|
|
142
|
+
connect() {
|
|
143
|
+
this.chat.connect();
|
|
144
|
+
}
|
|
145
|
+
disconnect() {
|
|
146
|
+
this.chat.disconnect();
|
|
147
|
+
}
|
|
124
148
|
/** The visitor's user ID (available after initVisitorSession). */
|
|
125
149
|
get visitorUserId() {
|
|
126
150
|
return this.userId;
|
|
@@ -138,6 +162,7 @@ var SupportClient = class {
|
|
|
138
162
|
const config = {
|
|
139
163
|
apiKey: this.apiKey,
|
|
140
164
|
apiBaseUrl: this.apiBaseUrl,
|
|
165
|
+
wsUrl: this.wsUrl,
|
|
141
166
|
// Proactive token refresh: check expiry before each request.
|
|
142
167
|
// HttpTransport and WebSocketTransport call getToken() once per request
|
|
143
168
|
// and do NOT retry on 401/null, so the token must be valid when returned.
|
|
@@ -197,6 +222,6 @@ var SupportClient = class {
|
|
|
197
222
|
};
|
|
198
223
|
|
|
199
224
|
// src/version.ts
|
|
200
|
-
var CHAT_VERSION = "0.0.
|
|
225
|
+
var CHAT_VERSION = "0.0.7";
|
|
201
226
|
|
|
202
227
|
export { CHAT_VERSION, SupportClient };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Attachment } from '../types';
|
|
3
|
+
interface ChatInputProps {
|
|
4
|
+
onSend: (content: string, attachments: Attachment[]) => void | Promise<void>;
|
|
5
|
+
onTypingChange?: (isTyping: boolean) => void;
|
|
6
|
+
onUploadAttachment?: (file: File | Blob, onProgress?: (percent: number) => void, signal?: AbortSignal) => Promise<{
|
|
7
|
+
data: Attachment | null;
|
|
8
|
+
error: {
|
|
9
|
+
message: string;
|
|
10
|
+
} | null;
|
|
11
|
+
} | undefined>;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function ChatInput({ onSend, onTypingChange, onUploadAttachment, placeholder, }: ChatInputProps): React.JSX.Element;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=ChatInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInput.d.ts","sourceRoot":"","sources":["../../src/react-components/ChatInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,UAAU,cAAc;IACtB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7E,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,kBAAkB,CAAC,EAAE,CACnB,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,EACtC,MAAM,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC;QAAE,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,GAAG,IAAI,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IACzF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAUD,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,cAAc,EACd,kBAAkB,EAClB,WAAiC,GAClC,EAAE,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAmOpC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChatMessage } from '../types';
|
|
3
|
+
interface ChatMessageItemProps {
|
|
4
|
+
message: ChatMessage;
|
|
5
|
+
currentUserId?: string;
|
|
6
|
+
onAddReaction?: (messageId: string, emoji: string) => void | Promise<void>;
|
|
7
|
+
onRemoveReaction?: (messageId: string, emoji: string) => void | Promise<void>;
|
|
8
|
+
onReport?: (messageId: string) => void | Promise<void>;
|
|
9
|
+
highlight?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function ChatMessageItem({ message, currentUserId, onAddReaction, onRemoveReaction, onReport, highlight, }: ChatMessageItemProps): React.JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=ChatMessageItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatMessageItem.d.ts","sourceRoot":"","sources":["../../src/react-components/ChatMessageItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C,UAAU,oBAAoB;IAC5B,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAyFD,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,SAAiB,GAClB,EAAE,oBAAoB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA2H1C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChatMessage } from '../types';
|
|
3
|
+
interface ChatMessageListProps {
|
|
4
|
+
messages: ChatMessage[];
|
|
5
|
+
currentUserId?: string;
|
|
6
|
+
unreadSince?: string;
|
|
7
|
+
scrollToUnreadOnMount?: boolean;
|
|
8
|
+
onAddReaction?: (messageId: string, emoji: string) => void | Promise<void>;
|
|
9
|
+
onRemoveReaction?: (messageId: string, emoji: string) => void | Promise<void>;
|
|
10
|
+
onReport?: (messageId: string) => void | Promise<void>;
|
|
11
|
+
emptyState?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare function ChatMessageList({ messages, currentUserId, unreadSince, scrollToUnreadOnMount, onAddReaction, onRemoveReaction, onReport, emptyState, }: ChatMessageListProps): React.JSX.Element;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=ChatMessageList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatMessageList.d.ts","sourceRoot":"","sources":["../../src/react-components/ChatMessageList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B;AAOD,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,aAAa,EACb,WAAW,EACX,qBAA4B,EAC5B,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,UAAU,GACX,EAAE,oBAAoB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA2J1C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChatTheme } from './theme';
|
|
3
|
+
interface ChatThreadProps {
|
|
4
|
+
conversationId: string;
|
|
5
|
+
theme?: ChatTheme;
|
|
6
|
+
currentUserId?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
subtitle?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function ChatThread({ conversationId, theme, currentUserId, title, subtitle, }: ChatThreadProps): React.JSX.Element;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=ChatThread.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatThread.d.ts","sourceRoot":"","sources":["../../src/react-components/ChatThread.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAMlD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,UAAU,eAAe;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAUD,wBAAgB,UAAU,CAAC,EACzB,cAAc,EACd,KAAK,EACL,aAAa,EACb,KAAc,EACd,QAAQ,GACT,EAAE,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAmJrC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Conversation } from '../types';
|
|
3
|
+
import type { ChatTheme } from './theme';
|
|
4
|
+
interface ConversationListProps {
|
|
5
|
+
conversationType?: Conversation['conversation_type'];
|
|
6
|
+
selectedConversationId?: string | null;
|
|
7
|
+
onSelect?: (conversation: Conversation) => void;
|
|
8
|
+
theme?: ChatTheme;
|
|
9
|
+
title?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function ConversationList({ conversationType, selectedConversationId, onSelect, theme, title, }: ConversationListProps): React.JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=ConversationList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversationList.d.ts","sourceRoot":"","sources":["../../src/react-components/ConversationList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAGjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,UAAU,qBAAqB;IAC7B,gBAAgB,CAAC,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAC;IACrD,sBAAsB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IAChD,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAUD,wBAAgB,gBAAgB,CAAC,EAC/B,gBAAgB,EAChB,sBAAsB,EACtB,QAAQ,EACR,KAAK,EACL,KAAuB,GACxB,EAAE,qBAAqB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA4J3C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface EmojiPickerProps {
|
|
3
|
+
onSelect: (emoji: string) => void;
|
|
4
|
+
emojis?: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function EmojiPicker({ onSelect, emojis, }: EmojiPickerProps): React.JSX.Element;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=EmojiPicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmojiPicker.d.ts","sourceRoot":"","sources":["../../src/react-components/EmojiPicker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,UAAU,gBAAgB;IACxB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,MAAuB,GACxB,EAAE,gBAAgB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAkCtC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ChatInput } from './ChatInput';
|
|
2
|
+
export { ChatMessageItem } from './ChatMessageItem';
|
|
3
|
+
export { ChatMessageList } from './ChatMessageList';
|
|
4
|
+
export { ChatThread } from './ChatThread';
|
|
5
|
+
export { ConversationList } from './ConversationList';
|
|
6
|
+
export { EmojiPicker } from './EmojiPicker';
|
|
7
|
+
export type { ChatTheme } from './theme';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react-components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
export interface ChatTheme {
|
|
3
|
+
primary?: string;
|
|
4
|
+
ownBubble?: string;
|
|
5
|
+
ownText?: string;
|
|
6
|
+
otherBubble?: string;
|
|
7
|
+
otherText?: string;
|
|
8
|
+
surface?: string;
|
|
9
|
+
surfaceMuted?: string;
|
|
10
|
+
borderColor?: string;
|
|
11
|
+
textColor?: string;
|
|
12
|
+
mutedText?: string;
|
|
13
|
+
borderRadius?: number | string;
|
|
14
|
+
fontFamily?: string;
|
|
15
|
+
}
|
|
16
|
+
type ThemeStyle = CSSProperties & Record<string, string | number | undefined>;
|
|
17
|
+
export declare function themeToStyle(theme?: ChatTheme): ThemeStyle;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/react-components/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,KAAK,UAAU,GAAG,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;AAE9E,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,UAAU,CAmB1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/react-components/utils.ts"],"names":[],"mappings":"AAWA,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAGxD;AAED,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAUhE"}
|