@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/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkYDLRISR7_cjs = require('./chunk-YDLRISR7.cjs');
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 chunkYDLRISR7_cjs.ChatClient(config);
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.1";
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 chunkYDLRISR7_cjs.ChatClient; }
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
- import { ChatClient } from './chunk-ZLMMNFZL.js';
2
- export { ChatClient } from './chunk-ZLMMNFZL.js';
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.1";
225
+ var CHAT_VERSION = "0.0.7";
201
226
 
202
227
  export { CHAT_VERSION, SupportClient };