customer-chat-sdk 1.1.6 → 1.1.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/customer-sdk.cjs.js +58 -6
- package/dist/customer-sdk.esm.js +58 -7
- package/dist/customer-sdk.min.js +1 -1
- package/dist/index.d.ts +21 -3
- package/dist/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/customer-sdk.cjs.js
CHANGED
|
@@ -20797,19 +20797,33 @@ class CustomerServiceSDK {
|
|
|
20797
20797
|
* 初始化 SDK
|
|
20798
20798
|
* @param config SDK配置
|
|
20799
20799
|
* @param options UI选项(可选)
|
|
20800
|
+
* @param forceReinit 是否强制重新初始化(用于更新token等配置)
|
|
20800
20801
|
* @returns 返回初始化信息(包含设备ID等)
|
|
20801
20802
|
*/
|
|
20802
|
-
async init(config, options) {
|
|
20803
|
-
|
|
20803
|
+
async init(config, options, forceReinit = false) {
|
|
20804
|
+
// 如果已经初始化且不强制重新初始化,返回之前保存的初始化信息
|
|
20805
|
+
if (this.isInitialized && !forceReinit) {
|
|
20804
20806
|
if (this.debug) {
|
|
20805
|
-
console.warn('CustomerSDK already initialized');
|
|
20807
|
+
console.warn('CustomerSDK already initialized, returning cached result. Use forceReinit=true to reinitialize.');
|
|
20806
20808
|
}
|
|
20807
|
-
// 如果已经初始化,返回之前保存的初始化信息
|
|
20808
20809
|
if (this.initResult) {
|
|
20809
20810
|
return this.initResult;
|
|
20810
20811
|
}
|
|
20811
20812
|
throw new Error('SDK already initialized but cannot retrieve initialization info');
|
|
20812
20813
|
}
|
|
20814
|
+
// 如果需要强制重新初始化,先清理旧资源
|
|
20815
|
+
if (this.isInitialized && forceReinit) {
|
|
20816
|
+
if (this.debug) {
|
|
20817
|
+
console.log('Force reinitializing SDK...');
|
|
20818
|
+
}
|
|
20819
|
+
// 清理旧的 iframe 和截图管理器,但保留图标管理器(保持图标位置等状态)
|
|
20820
|
+
this.iframeManager?.destroy();
|
|
20821
|
+
this.screenshotManager?.destroy();
|
|
20822
|
+
this.iframeManager = null;
|
|
20823
|
+
this.screenshotManager = null;
|
|
20824
|
+
// 重置初始化标志,但保留图标管理器
|
|
20825
|
+
this.isInitialized = false;
|
|
20826
|
+
}
|
|
20813
20827
|
this.config = config;
|
|
20814
20828
|
this.debug = config.debug ?? false;
|
|
20815
20829
|
try {
|
|
@@ -21043,6 +21057,31 @@ class CustomerServiceSDK {
|
|
|
21043
21057
|
console.log('📸 截图配置已更新:', options);
|
|
21044
21058
|
}
|
|
21045
21059
|
}
|
|
21060
|
+
/**
|
|
21061
|
+
* 更新 token(用于用户登录/退出场景)
|
|
21062
|
+
* 如果已初始化,会重新创建 iframe 并更新 URL
|
|
21063
|
+
* @param token 新的 token(传空字符串或 undefined 表示移除 token)
|
|
21064
|
+
* @param options UI选项(可选,用于重新初始化时的配置)
|
|
21065
|
+
* @returns 返回更新后的初始化信息
|
|
21066
|
+
*/
|
|
21067
|
+
async updateToken(token, options) {
|
|
21068
|
+
if (!this.isInitialized) {
|
|
21069
|
+
throw new Error('SDK not initialized. Call init() first.');
|
|
21070
|
+
}
|
|
21071
|
+
if (!this.config) {
|
|
21072
|
+
throw new Error('SDK config not found');
|
|
21073
|
+
}
|
|
21074
|
+
// 更新配置中的 token
|
|
21075
|
+
const updatedConfig = {
|
|
21076
|
+
...this.config,
|
|
21077
|
+
token: token && token.trim() !== '' ? token : undefined
|
|
21078
|
+
};
|
|
21079
|
+
if (this.debug) {
|
|
21080
|
+
console.log('Updating token:', token ? 'Token provided' : 'Token removed');
|
|
21081
|
+
}
|
|
21082
|
+
// 强制重新初始化以应用新的 token
|
|
21083
|
+
return await this.init(updatedConfig, options, true);
|
|
21084
|
+
}
|
|
21046
21085
|
/**
|
|
21047
21086
|
* 销毁 SDK
|
|
21048
21087
|
*/
|
|
@@ -21126,13 +21165,14 @@ let globalSDKInstance = null;
|
|
|
21126
21165
|
* 初始化 Customer SDK
|
|
21127
21166
|
* @param config SDK配置
|
|
21128
21167
|
* @param options UI选项(可选)
|
|
21168
|
+
* @param forceReinit 是否强制重新初始化(用于更新token等配置)
|
|
21129
21169
|
* @returns 返回初始化信息(包含设备ID等)
|
|
21130
21170
|
*/
|
|
21131
|
-
const init = async (config, options) => {
|
|
21171
|
+
const init = async (config, options, forceReinit = false) => {
|
|
21132
21172
|
if (!globalSDKInstance) {
|
|
21133
21173
|
globalSDKInstance = new CustomerServiceSDK();
|
|
21134
21174
|
}
|
|
21135
|
-
return await globalSDKInstance.init(config, options);
|
|
21175
|
+
return await globalSDKInstance.init(config, options, forceReinit);
|
|
21136
21176
|
};
|
|
21137
21177
|
/**
|
|
21138
21178
|
* 获取全局SDK实例
|
|
@@ -21241,6 +21281,16 @@ const updateScreenshotOptions = (options) => {
|
|
|
21241
21281
|
const sdk = getInstance();
|
|
21242
21282
|
sdk.updateScreenshotOptions(options);
|
|
21243
21283
|
};
|
|
21284
|
+
/**
|
|
21285
|
+
* 更新 token(用于用户登录/退出场景)
|
|
21286
|
+
* @param token 新的 token(传空字符串或 undefined 表示移除 token)
|
|
21287
|
+
* @param options UI选项(可选)
|
|
21288
|
+
* @returns 返回更新后的初始化信息
|
|
21289
|
+
*/
|
|
21290
|
+
const updateToken = async (token, options) => {
|
|
21291
|
+
const sdk = getInstance();
|
|
21292
|
+
return await sdk.updateToken(token, options);
|
|
21293
|
+
};
|
|
21244
21294
|
// 默认导出
|
|
21245
21295
|
var index = {
|
|
21246
21296
|
init,
|
|
@@ -21263,6 +21313,7 @@ var index = {
|
|
|
21263
21313
|
enableScreenshot,
|
|
21264
21314
|
getScreenshotState,
|
|
21265
21315
|
updateScreenshotOptions,
|
|
21316
|
+
updateToken,
|
|
21266
21317
|
destroy
|
|
21267
21318
|
};
|
|
21268
21319
|
|
|
@@ -21289,3 +21340,4 @@ exports.setScreenshotTarget = setScreenshotTarget;
|
|
|
21289
21340
|
exports.showIcon = showIcon;
|
|
21290
21341
|
exports.showNotification = showNotification;
|
|
21291
21342
|
exports.updateScreenshotOptions = updateScreenshotOptions;
|
|
21343
|
+
exports.updateToken = updateToken;
|
package/dist/customer-sdk.esm.js
CHANGED
|
@@ -20793,19 +20793,33 @@ class CustomerServiceSDK {
|
|
|
20793
20793
|
* 初始化 SDK
|
|
20794
20794
|
* @param config SDK配置
|
|
20795
20795
|
* @param options UI选项(可选)
|
|
20796
|
+
* @param forceReinit 是否强制重新初始化(用于更新token等配置)
|
|
20796
20797
|
* @returns 返回初始化信息(包含设备ID等)
|
|
20797
20798
|
*/
|
|
20798
|
-
async init(config, options) {
|
|
20799
|
-
|
|
20799
|
+
async init(config, options, forceReinit = false) {
|
|
20800
|
+
// 如果已经初始化且不强制重新初始化,返回之前保存的初始化信息
|
|
20801
|
+
if (this.isInitialized && !forceReinit) {
|
|
20800
20802
|
if (this.debug) {
|
|
20801
|
-
console.warn('CustomerSDK already initialized');
|
|
20803
|
+
console.warn('CustomerSDK already initialized, returning cached result. Use forceReinit=true to reinitialize.');
|
|
20802
20804
|
}
|
|
20803
|
-
// 如果已经初始化,返回之前保存的初始化信息
|
|
20804
20805
|
if (this.initResult) {
|
|
20805
20806
|
return this.initResult;
|
|
20806
20807
|
}
|
|
20807
20808
|
throw new Error('SDK already initialized but cannot retrieve initialization info');
|
|
20808
20809
|
}
|
|
20810
|
+
// 如果需要强制重新初始化,先清理旧资源
|
|
20811
|
+
if (this.isInitialized && forceReinit) {
|
|
20812
|
+
if (this.debug) {
|
|
20813
|
+
console.log('Force reinitializing SDK...');
|
|
20814
|
+
}
|
|
20815
|
+
// 清理旧的 iframe 和截图管理器,但保留图标管理器(保持图标位置等状态)
|
|
20816
|
+
this.iframeManager?.destroy();
|
|
20817
|
+
this.screenshotManager?.destroy();
|
|
20818
|
+
this.iframeManager = null;
|
|
20819
|
+
this.screenshotManager = null;
|
|
20820
|
+
// 重置初始化标志,但保留图标管理器
|
|
20821
|
+
this.isInitialized = false;
|
|
20822
|
+
}
|
|
20809
20823
|
this.config = config;
|
|
20810
20824
|
this.debug = config.debug ?? false;
|
|
20811
20825
|
try {
|
|
@@ -21039,6 +21053,31 @@ class CustomerServiceSDK {
|
|
|
21039
21053
|
console.log('📸 截图配置已更新:', options);
|
|
21040
21054
|
}
|
|
21041
21055
|
}
|
|
21056
|
+
/**
|
|
21057
|
+
* 更新 token(用于用户登录/退出场景)
|
|
21058
|
+
* 如果已初始化,会重新创建 iframe 并更新 URL
|
|
21059
|
+
* @param token 新的 token(传空字符串或 undefined 表示移除 token)
|
|
21060
|
+
* @param options UI选项(可选,用于重新初始化时的配置)
|
|
21061
|
+
* @returns 返回更新后的初始化信息
|
|
21062
|
+
*/
|
|
21063
|
+
async updateToken(token, options) {
|
|
21064
|
+
if (!this.isInitialized) {
|
|
21065
|
+
throw new Error('SDK not initialized. Call init() first.');
|
|
21066
|
+
}
|
|
21067
|
+
if (!this.config) {
|
|
21068
|
+
throw new Error('SDK config not found');
|
|
21069
|
+
}
|
|
21070
|
+
// 更新配置中的 token
|
|
21071
|
+
const updatedConfig = {
|
|
21072
|
+
...this.config,
|
|
21073
|
+
token: token && token.trim() !== '' ? token : undefined
|
|
21074
|
+
};
|
|
21075
|
+
if (this.debug) {
|
|
21076
|
+
console.log('Updating token:', token ? 'Token provided' : 'Token removed');
|
|
21077
|
+
}
|
|
21078
|
+
// 强制重新初始化以应用新的 token
|
|
21079
|
+
return await this.init(updatedConfig, options, true);
|
|
21080
|
+
}
|
|
21042
21081
|
/**
|
|
21043
21082
|
* 销毁 SDK
|
|
21044
21083
|
*/
|
|
@@ -21122,13 +21161,14 @@ let globalSDKInstance = null;
|
|
|
21122
21161
|
* 初始化 Customer SDK
|
|
21123
21162
|
* @param config SDK配置
|
|
21124
21163
|
* @param options UI选项(可选)
|
|
21164
|
+
* @param forceReinit 是否强制重新初始化(用于更新token等配置)
|
|
21125
21165
|
* @returns 返回初始化信息(包含设备ID等)
|
|
21126
21166
|
*/
|
|
21127
|
-
const init = async (config, options) => {
|
|
21167
|
+
const init = async (config, options, forceReinit = false) => {
|
|
21128
21168
|
if (!globalSDKInstance) {
|
|
21129
21169
|
globalSDKInstance = new CustomerServiceSDK();
|
|
21130
21170
|
}
|
|
21131
|
-
return await globalSDKInstance.init(config, options);
|
|
21171
|
+
return await globalSDKInstance.init(config, options, forceReinit);
|
|
21132
21172
|
};
|
|
21133
21173
|
/**
|
|
21134
21174
|
* 获取全局SDK实例
|
|
@@ -21237,6 +21277,16 @@ const updateScreenshotOptions = (options) => {
|
|
|
21237
21277
|
const sdk = getInstance();
|
|
21238
21278
|
sdk.updateScreenshotOptions(options);
|
|
21239
21279
|
};
|
|
21280
|
+
/**
|
|
21281
|
+
* 更新 token(用于用户登录/退出场景)
|
|
21282
|
+
* @param token 新的 token(传空字符串或 undefined 表示移除 token)
|
|
21283
|
+
* @param options UI选项(可选)
|
|
21284
|
+
* @returns 返回更新后的初始化信息
|
|
21285
|
+
*/
|
|
21286
|
+
const updateToken = async (token, options) => {
|
|
21287
|
+
const sdk = getInstance();
|
|
21288
|
+
return await sdk.updateToken(token, options);
|
|
21289
|
+
};
|
|
21240
21290
|
// 默认导出
|
|
21241
21291
|
var index = {
|
|
21242
21292
|
init,
|
|
@@ -21259,7 +21309,8 @@ var index = {
|
|
|
21259
21309
|
enableScreenshot,
|
|
21260
21310
|
getScreenshotState,
|
|
21261
21311
|
updateScreenshotOptions,
|
|
21312
|
+
updateToken,
|
|
21262
21313
|
destroy
|
|
21263
21314
|
};
|
|
21264
21315
|
|
|
21265
|
-
export { CustomerServiceSDK, captureScreenshot, clearNotification, closeChat, index as default, destroy, enableScreenshot, getConnectionStatus, getInitResult, getInstance, getScreenshotState, hideIcon, init, isChatOpen, openChat, sendToIframe, setIconCoordinates, setIconPosition, setIconStyle, setScreenshotTarget, showIcon, showNotification, updateScreenshotOptions };
|
|
21316
|
+
export { CustomerServiceSDK, captureScreenshot, clearNotification, closeChat, index as default, destroy, enableScreenshot, getConnectionStatus, getInitResult, getInstance, getScreenshotState, hideIcon, init, isChatOpen, openChat, sendToIframe, setIconCoordinates, setIconPosition, setIconStyle, setScreenshotTarget, showIcon, showNotification, updateScreenshotOptions, updateToken };
|