@scalemule/chat 0.0.5 → 0.0.8
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/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/element.cjs +542 -51
- package/dist/element.js +541 -50
- package/dist/index.cjs +34 -5
- package/dist/index.js +29 -4
- package/dist/react.cjs +1260 -50
- package/dist/react.js +1212 -13
- package/dist/support-widget.global.js +485 -157
- package/package.json +5 -2
- package/dist/ChatClient-BoZaTtyM.d.cts +0 -88
- package/dist/ChatClient-COmdEJ11.d.ts +0 -88
- package/dist/element.d.cts +0 -2
- package/dist/element.d.ts +0 -2
- package/dist/iframe.d.cts +0 -17
- package/dist/iframe.d.ts +0 -17
- package/dist/index.d.cts +0 -77
- package/dist/index.d.ts +0 -77
- package/dist/react.d.cts +0 -49
- package/dist/react.d.ts +0 -49
- package/dist/types-BmD7f1gV.d.cts +0 -232
- package/dist/types-BmD7f1gV.d.ts +0 -232
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.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 };
|