@microsoft/omnichannel-chat-widget 1.7.4-main.562254b → 1.7.4-main.8d43b20
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/lib/cjs/common/facades/FacadeChatSDK.js +298 -0
- package/lib/cjs/common/facades/types/IFacadeChatSDKInput.js +1 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +5 -0
- package/lib/cjs/common/telemetry/TelemetryHelper.js +10 -0
- package/lib/cjs/common/utils.js +2 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
- package/lib/cjs/components/footerstateful/FooterStateful.js +4 -5
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/cjs/components/livechatwidget/LiveChatWidget.js +26 -3
- package/lib/cjs/components/livechatwidget/common/authHelper.js +14 -5
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -9
- package/lib/cjs/components/livechatwidget/common/endChat.js +21 -22
- package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +3 -3
- package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +2 -3
- package/lib/cjs/components/livechatwidget/common/persistentChatHelper.js +4 -4
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -12
- package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
- package/lib/cjs/components/livechatwidget/common/startChat.js +42 -36
- package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +7 -7
- package/lib/cjs/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
- package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/cjs/contexts/FacadeChatSDKStore.js +10 -0
- package/lib/cjs/hooks/useFacadeChatSDKStore.js +17 -0
- package/lib/cjs/index.js +9 -2
- package/lib/cjs/plugins/createChatTranscript.js +2 -2
- package/lib/esm/common/facades/FacadeChatSDK.js +291 -0
- package/lib/esm/common/facades/types/IFacadeChatSDKInput.js +1 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +5 -0
- package/lib/esm/common/telemetry/TelemetryHelper.js +10 -0
- package/lib/esm/common/utils.js +2 -2
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
- package/lib/esm/components/footerstateful/FooterStateful.js +4 -5
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/esm/components/livechatwidget/LiveChatWidget.js +26 -3
- package/lib/esm/components/livechatwidget/common/authHelper.js +14 -5
- package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -9
- package/lib/esm/components/livechatwidget/common/endChat.js +21 -22
- package/lib/esm/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +3 -3
- package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +2 -4
- package/lib/esm/components/livechatwidget/common/persistentChatHelper.js +4 -4
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -12
- package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +42 -36
- package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +7 -7
- package/lib/esm/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
- package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/esm/contexts/FacadeChatSDKStore.js +4 -0
- package/lib/esm/hooks/useFacadeChatSDKStore.js +10 -0
- package/lib/esm/index.js +5 -4
- package/lib/esm/plugins/createChatTranscript.js +2 -2
- package/lib/types/common/facades/FacadeChatSDK.d.ts +71 -0
- package/lib/types/common/facades/types/IFacadeChatSDKInput.d.ts +13 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +6 -1
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +6 -0
- package/lib/types/common/utils.d.ts +2 -1
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +3 -2
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +14 -1
- package/lib/types/components/livechatwidget/common/createAdapter.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
- package/lib/types/components/livechatwidget/common/initCallingSdk.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/persistentChatHelper.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +3 -2
- package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -4
- package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/updateSessionDataForTelemetry.d.ts +2 -1
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +2 -1
- package/lib/types/contexts/FacadeChatSDKStore.d.ts +1 -0
- package/lib/types/hooks/useFacadeChatSDKStore.d.ts +3 -0
- package/lib/types/index.d.ts +4 -3
- package/lib/types/plugins/createChatTranscript.d.ts +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FacadeChatSDK = void 0;
|
|
7
|
+
var _TelemetryConstants = require("../telemetry/TelemetryConstants");
|
|
8
|
+
var _authHelper = require("../../components/livechatwidget/common/authHelper");
|
|
9
|
+
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
10
|
+
var _TelemetryHelper = require("../telemetry/TelemetryHelper");
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
class FacadeChatSDK {
|
|
16
|
+
isSDKMocked() {
|
|
17
|
+
return this.sdkMocked;
|
|
18
|
+
}
|
|
19
|
+
getChatSDK() {
|
|
20
|
+
return this.chatSDK;
|
|
21
|
+
}
|
|
22
|
+
destroy() {
|
|
23
|
+
this.token = null;
|
|
24
|
+
this.expiration = 0;
|
|
25
|
+
}
|
|
26
|
+
isTokenSet() {
|
|
27
|
+
return !(0, _utils.isNullOrEmptyString)(this.token);
|
|
28
|
+
}
|
|
29
|
+
constructor(input) {
|
|
30
|
+
_defineProperty(this, "chatSDK", void 0);
|
|
31
|
+
_defineProperty(this, "chatConfig", void 0);
|
|
32
|
+
_defineProperty(this, "token", "");
|
|
33
|
+
_defineProperty(this, "expiration", 0);
|
|
34
|
+
_defineProperty(this, "isAuthenticated", void 0);
|
|
35
|
+
_defineProperty(this, "getAuthToken", void 0);
|
|
36
|
+
_defineProperty(this, "sdkMocked", void 0);
|
|
37
|
+
this.chatSDK = input.chatSDK;
|
|
38
|
+
this.chatConfig = input.chatConfig;
|
|
39
|
+
this.getAuthToken = input.getAuthToken;
|
|
40
|
+
this.isAuthenticated = input.isAuthenticated;
|
|
41
|
+
this.sdkMocked = input.isSDKMocked;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//set default expiration to zero, for undefined or missed exp in jwt
|
|
45
|
+
convertExpiration() {
|
|
46
|
+
let expiration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
47
|
+
// Converting expiration to seconds, if contains decimals or is identified as milliseconds
|
|
48
|
+
if (expiration.toString().length === 13) {
|
|
49
|
+
return Math.floor(expiration / 1000);
|
|
50
|
+
}
|
|
51
|
+
// If the epoch value is already in seconds, return it as is
|
|
52
|
+
return expiration;
|
|
53
|
+
}
|
|
54
|
+
isTokenExpired() {
|
|
55
|
+
// if expiration is 0, token is not going to be validated ( this is to cover the case of token with no expiration)
|
|
56
|
+
if (this.expiration === 0) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// obtain current time in seconds
|
|
61
|
+
const now = Math.floor(Date.now() / 1000);
|
|
62
|
+
|
|
63
|
+
// compare expiration time with current time
|
|
64
|
+
if (now > this.expiration) {
|
|
65
|
+
console.log("Token is expired", now, this.expiration, now > this.expiration);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
async setToken(token) {
|
|
71
|
+
// token must be not null, and must be new
|
|
72
|
+
if (!(0, _utils.isNullOrEmptyString)(token) && token !== this.token) {
|
|
73
|
+
var _this$token;
|
|
74
|
+
const instant = Math.floor(Date.now() / 1000);
|
|
75
|
+
this.token = token;
|
|
76
|
+
// decompose token
|
|
77
|
+
const tokenParts = (_this$token = this.token) === null || _this$token === void 0 ? void 0 : _this$token.split(".");
|
|
78
|
+
if (!tokenParts || tokenParts.length <= 1) {
|
|
79
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
80
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
81
|
+
Description: "Invalid token format",
|
|
82
|
+
ExceptionDetails: "Token must be in JWT format"
|
|
83
|
+
});
|
|
84
|
+
throw new Error("Invalid token format, must be in JWT format");
|
|
85
|
+
}
|
|
86
|
+
// decode token
|
|
87
|
+
const tokenDecoded = JSON.parse(atob(tokenParts[1]));
|
|
88
|
+
// calculate expiration time
|
|
89
|
+
this.expiration = this.convertExpiration(tokenDecoded.exp);
|
|
90
|
+
|
|
91
|
+
// this is a control , in case the getAuthToken function returns same token
|
|
92
|
+
if (this.expiration > 0 && this.expiration < instant) {
|
|
93
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
94
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenExpired,
|
|
95
|
+
Description: "New token is already expired",
|
|
96
|
+
ExceptionDetails: {
|
|
97
|
+
"Instant": instant,
|
|
98
|
+
"Expiration": this.expiration
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
throw new Error("New token is already expired, with epoch time " + this.expiration);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async tokenRing() {
|
|
106
|
+
// this is needed for storybooks, specifically for reconnect pane which requires authentication bypass
|
|
107
|
+
if (this.sdkMocked === true) {
|
|
108
|
+
return {
|
|
109
|
+
result: true,
|
|
110
|
+
message: "Authentication not needed"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (!this.isAuthenticated) {
|
|
114
|
+
return {
|
|
115
|
+
result: true,
|
|
116
|
+
message: "Authentication not needed"
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (this.isTokenSet() && !this.isTokenExpired()) {
|
|
120
|
+
return {
|
|
121
|
+
result: true,
|
|
122
|
+
message: "Token is valid"
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (this.getAuthToken === undefined) {
|
|
126
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
127
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
128
|
+
Description: "GetAuthToken function is not present",
|
|
129
|
+
ExceptionDetails: "Missing function : " + (0, _authHelper.getAuthClientFunction)(this.chatConfig)
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
result: false,
|
|
133
|
+
message: "GetAuthToken function is not present"
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// if token is not set, or token is already expired , then go to grab a token
|
|
138
|
+
this.token = "";
|
|
139
|
+
this.expiration = 0;
|
|
140
|
+
try {
|
|
141
|
+
const ring = await (0, _authHelper.handleAuthentication)(this.chatSDK, this.chatConfig, this.getAuthToken);
|
|
142
|
+
if (ring.result === true && ring.token) {
|
|
143
|
+
await this.setToken(ring.token);
|
|
144
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
145
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenSuccess,
|
|
146
|
+
Description: "New Token obtained",
|
|
147
|
+
Data: {
|
|
148
|
+
"Token_Expiration": this.expiration
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
result: true,
|
|
153
|
+
message: "New Token obtained"
|
|
154
|
+
};
|
|
155
|
+
} else {
|
|
156
|
+
var _ring$error, _ring$error2;
|
|
157
|
+
console.error("Failed to get token", ring);
|
|
158
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
159
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
160
|
+
Description: (_ring$error = ring.error) === null || _ring$error === void 0 ? void 0 : _ring$error.message,
|
|
161
|
+
ExceptionDetails: ring.error
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
result: false,
|
|
165
|
+
message: ((_ring$error2 = ring.error) === null || _ring$error2 === void 0 ? void 0 : _ring$error2.message) || "Failed to get token"
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.error("Unexpected error while getting token", e);
|
|
170
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
171
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
172
|
+
Description: "Unexpected error while getting token",
|
|
173
|
+
ExceptionDetails: e
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
result: false,
|
|
177
|
+
message: "Unexpected error while getting token"
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async validateAndExecuteCall(functionName, fn) {
|
|
182
|
+
const pingResponse = await this.tokenRing();
|
|
183
|
+
if (pingResponse.result === true) {
|
|
184
|
+
return fn();
|
|
185
|
+
}
|
|
186
|
+
const executionErrorMessage = `Authentication failed: Process to get a token failed for ${functionName}, ${pingResponse.message}`;
|
|
187
|
+
//telemetry is already logged in tokenRing, so no need to log again, just return the error and communicate to the console
|
|
188
|
+
console.error(executionErrorMessage);
|
|
189
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
190
|
+
eventName: _TelemetryConstants.BroadcastEvent.OnWidgetError,
|
|
191
|
+
payload: {
|
|
192
|
+
errorMessage: executionErrorMessage
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
throw new Error(executionErrorMessage);
|
|
196
|
+
}
|
|
197
|
+
async initialize() {
|
|
198
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
199
|
+
return this.validateAndExecuteCall("initialize", () => this.chatSDK.initialize(optionalParams));
|
|
200
|
+
}
|
|
201
|
+
async getChatReconnectContext() {
|
|
202
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
203
|
+
return this.validateAndExecuteCall("getChatReconnectContext", () => this.chatSDK.getChatReconnectContext(optionalParams));
|
|
204
|
+
}
|
|
205
|
+
async startChat() {
|
|
206
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
207
|
+
return this.validateAndExecuteCall("startChat", () => this.chatSDK.startChat(optionalParams));
|
|
208
|
+
}
|
|
209
|
+
async endChat() {
|
|
210
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
211
|
+
return this.validateAndExecuteCall("endChat", () => this.chatSDK.endChat(optionalParams));
|
|
212
|
+
}
|
|
213
|
+
async getCurrentLiveChatContext() {
|
|
214
|
+
return this.validateAndExecuteCall("getCurrentLiveChatContext", () => this.chatSDK.getCurrentLiveChatContext());
|
|
215
|
+
}
|
|
216
|
+
async getConversationDetails() {
|
|
217
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
218
|
+
return this.validateAndExecuteCall("getConversationDetails", () => this.chatSDK.getConversationDetails(optionalParams));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
|
+
async getPreChatSurvey() {
|
|
223
|
+
let parse = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
224
|
+
//prechat survey is obtained from config object, which is not required to be authenticated
|
|
225
|
+
// removing the tokenRing function from this call for backward compatibility
|
|
226
|
+
// TODO :: wrap this function around authentication
|
|
227
|
+
return this.chatSDK.getPreChatSurvey(parse);
|
|
228
|
+
}
|
|
229
|
+
async getLiveChatConfig(optionalParams) {
|
|
230
|
+
return this.validateAndExecuteCall("getLiveChatConfig", () => this.chatSDK.getLiveChatConfig(optionalParams));
|
|
231
|
+
}
|
|
232
|
+
async getChatToken() {
|
|
233
|
+
let cached = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
234
|
+
let optionalParams = arguments.length > 1 ? arguments[1] : undefined;
|
|
235
|
+
return this.validateAndExecuteCall("getChatToken", () => this.chatSDK.getChatToken(cached, optionalParams));
|
|
236
|
+
}
|
|
237
|
+
async getCallingToken() {
|
|
238
|
+
return this.validateAndExecuteCall("getCallingToken", () => this.chatSDK.getCallingToken());
|
|
239
|
+
}
|
|
240
|
+
async getMessages() {
|
|
241
|
+
return this.validateAndExecuteCall("getMessages", () => this.chatSDK.getMessages());
|
|
242
|
+
}
|
|
243
|
+
async getDataMaskingRules() {
|
|
244
|
+
return this.validateAndExecuteCall("getDataMaskingRules", () => this.chatSDK.getDataMaskingRules());
|
|
245
|
+
}
|
|
246
|
+
async sendMessage(message) {
|
|
247
|
+
return this.validateAndExecuteCall("sendMessage", () => this.chatSDK.sendMessage(message));
|
|
248
|
+
}
|
|
249
|
+
async onNewMessage(onNewMessageCallback) {
|
|
250
|
+
let optionalParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
251
|
+
return this.validateAndExecuteCall("onNewMessage", () => this.chatSDK.onNewMessage(onNewMessageCallback, optionalParams));
|
|
252
|
+
}
|
|
253
|
+
async sendTypingEvent() {
|
|
254
|
+
return this.validateAndExecuteCall("sendTypingEvent", () => this.chatSDK.sendTypingEvent());
|
|
255
|
+
}
|
|
256
|
+
async onTypingEvent(onTypingEventCallback) {
|
|
257
|
+
return this.validateAndExecuteCall("onTypingEvent", () => this.chatSDK.onTypingEvent(onTypingEventCallback));
|
|
258
|
+
}
|
|
259
|
+
async onAgentEndSession(onAgentEndSessionCallback) {
|
|
260
|
+
return this.validateAndExecuteCall("onAgentEndSession", () => this.chatSDK.onAgentEndSession(onAgentEndSessionCallback));
|
|
261
|
+
}
|
|
262
|
+
async uploadFileAttachment(fileInfo) {
|
|
263
|
+
return this.validateAndExecuteCall("uploadFileAttachment", () => this.chatSDK.uploadFileAttachment(fileInfo));
|
|
264
|
+
}
|
|
265
|
+
async downloadFileAttachment(fileMetadata) {
|
|
266
|
+
return this.validateAndExecuteCall("downloadFileAttachment", () => this.chatSDK.downloadFileAttachment(fileMetadata));
|
|
267
|
+
}
|
|
268
|
+
async emailLiveChatTranscript(body) {
|
|
269
|
+
let optionalParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
270
|
+
return this.validateAndExecuteCall("emailLiveChatTranscript", () => this.chatSDK.emailLiveChatTranscript(body, optionalParams));
|
|
271
|
+
}
|
|
272
|
+
async getLiveChatTranscript() {
|
|
273
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
274
|
+
return this.validateAndExecuteCall("getLiveChatTranscript", () => this.chatSDK.getLiveChatTranscript(optionalParams));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// response from origin is unknown, but this definition breaks create adapter for shimAdapter, switching to any until type is returned from origin
|
|
278
|
+
async createChatAdapter() {
|
|
279
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
280
|
+
return this.validateAndExecuteCall("createChatAdapter", () => this.chatSDK.createChatAdapter(optionalParams));
|
|
281
|
+
}
|
|
282
|
+
async isVoiceVideoCallingEnabled() {
|
|
283
|
+
this.tokenRing();
|
|
284
|
+
return this.chatSDK.isVoiceVideoCallingEnabled();
|
|
285
|
+
}
|
|
286
|
+
async getVoiceVideoCalling() {
|
|
287
|
+
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
288
|
+
return this.validateAndExecuteCall("getVoiceVideoCalling", () => this.chatSDK.getVoiceVideoCalling(params));
|
|
289
|
+
}
|
|
290
|
+
async getPostChatSurveyContext() {
|
|
291
|
+
return this.validateAndExecuteCall("getPostChatSurveyContext", () => this.chatSDK.getPostChatSurveyContext());
|
|
292
|
+
}
|
|
293
|
+
async getAgentAvailability() {
|
|
294
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
295
|
+
return this.validateAndExecuteCall("getAgentAvailability", () => this.chatSDK.getAgentAvailability(optionalParams));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.FacadeChatSDK = FacadeChatSDK;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -188,6 +188,7 @@ exports.TelemetryEvent = TelemetryEvent;
|
|
|
188
188
|
TelemetryEvent["SendTypingIndicatorSucceeded"] = "SendTypingIndicatorSucceeded";
|
|
189
189
|
TelemetryEvent["SendTypingIndicatorFailed"] = "SendTypingIndicatorFailed";
|
|
190
190
|
TelemetryEvent["WebChatEvent"] = "WebChatEvent";
|
|
191
|
+
TelemetryEvent["FacadeChatSDKEvent"] = "FacadeChatSDKEvent";
|
|
191
192
|
TelemetryEvent["PreChatSurveyStartChatMethodFailed"] = "PreChatSurveyStartChatMethodFailed";
|
|
192
193
|
TelemetryEvent["ChatAlreadyTriggered"] = "ChatAlreadyTriggered";
|
|
193
194
|
TelemetryEvent["StartProactiveChatEventReceived"] = "StartProactiveChatEventReceived";
|
|
@@ -218,6 +219,10 @@ exports.TelemetryEvent = TelemetryEvent;
|
|
|
218
219
|
TelemetryEvent["ChatDisconnectThreadEventReceived"] = "ChatDisconnectThreadEventReceived";
|
|
219
220
|
TelemetryEvent["HiddenAdaptiveCardMessageReceived"] = "HiddenAdaptiveCardMessageReceived";
|
|
220
221
|
TelemetryEvent["EndingAdapterAfterDisconnectionError"] = "EndingAdapterAfterDisconnectionError";
|
|
222
|
+
TelemetryEvent["NewTokenSuccess"] = "NewTokenSuccess";
|
|
223
|
+
TelemetryEvent["NewTokenFailed"] = "NewTokenFailed";
|
|
224
|
+
TelemetryEvent["NewTokenExpired"] = "NewTokenExpired";
|
|
225
|
+
TelemetryEvent["TokenEmptyOrSame"] = "TokenEmptyOrSame";
|
|
221
226
|
})(TelemetryEvent || (exports.TelemetryEvent = TelemetryEvent = {}));
|
|
222
227
|
class TelemetryConstants {
|
|
223
228
|
static map(eventTypeOrScenarioType) {
|
|
@@ -264,4 +264,14 @@ _defineProperty(TelemetryHelper, "logWebChatEvent", (logLevel, payload) => {
|
|
|
264
264
|
}
|
|
265
265
|
};
|
|
266
266
|
_omnichannelChatComponents.BroadcastService.postMessage(telemetryEvent);
|
|
267
|
+
});
|
|
268
|
+
_defineProperty(TelemetryHelper, "logFacadeChatSDKEvent", (logLevel, payload) => {
|
|
269
|
+
const telemetryEvent = {
|
|
270
|
+
eventName: (payload === null || payload === void 0 ? void 0 : payload.Event) ?? _TelemetryConstants.TelemetryEvent.FacadeChatSDKEvent,
|
|
271
|
+
logLevel: logLevel,
|
|
272
|
+
payload: {
|
|
273
|
+
...payload
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
_omnichannelChatComponents.BroadcastService.postMessage(telemetryEvent);
|
|
267
277
|
});
|
package/lib/cjs/common/utils.js
CHANGED
|
@@ -390,7 +390,7 @@ const isThisSessionPopout = href => {
|
|
|
390
390
|
};
|
|
391
391
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
392
392
|
exports.isThisSessionPopout = isThisSessionPopout;
|
|
393
|
-
const getConversationDetailsCall = async function (
|
|
393
|
+
const getConversationDetailsCall = async function (facadeChatSDK) {
|
|
394
394
|
let liveChatContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
395
395
|
let conversationDetails = undefined; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
396
396
|
const optionalParams = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
@@ -403,7 +403,7 @@ const getConversationDetailsCall = async function (chatSDK) {
|
|
|
403
403
|
Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsCallStarted,
|
|
404
404
|
Description: "Conversation details call started"
|
|
405
405
|
});
|
|
406
|
-
conversationDetails = await
|
|
406
|
+
conversationDetails = await facadeChatSDK.getConversationDetails(optionalParams);
|
|
407
407
|
} catch (error) {
|
|
408
408
|
checkContactIdError(error);
|
|
409
409
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
@@ -10,18 +10,14 @@ var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components
|
|
|
10
10
|
var _LiveChatWidgetActionType = require("../../contexts/common/LiveChatWidgetActionType");
|
|
11
11
|
var _TelemetryHelper = require("../../common/telemetry/TelemetryHelper");
|
|
12
12
|
var _useChatContextStore = _interopRequireDefault(require("../../hooks/useChatContextStore"));
|
|
13
|
-
var
|
|
13
|
+
var _useFacadeChatSDKStore = _interopRequireDefault(require("../../hooks/useFacadeChatSDKStore"));
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
17
|
const CallingContainerStateful = props => {
|
|
18
18
|
var _props$controlProps, _props$controlProps2, _props$controlProps2$, _props$controlProps3, _props$controlProps3$, _props$controlProps3$2, _props$controlProps4, _props$controlProps4$, _props$controlProps4$2, _props$controlProps5;
|
|
19
|
-
//TODO : Close button confirmation implmentation is pending
|
|
20
|
-
|
|
21
19
|
const [state, dispatch] = (0, _useChatContextStore.default)();
|
|
22
|
-
|
|
23
|
-
const chatSDK = (0, _useChatSDKStore.default)();
|
|
24
|
-
|
|
20
|
+
const [facadeChatSDK] = (0, _useFacadeChatSDKStore.default)();
|
|
25
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
22
|
const {
|
|
27
23
|
voiceVideoCallingSdk
|
|
@@ -54,7 +50,7 @@ const CallingContainerStateful = props => {
|
|
|
54
50
|
(0, _react.useEffect)(() => {
|
|
55
51
|
const init = async () => {
|
|
56
52
|
try {
|
|
57
|
-
var _controlProps$current, _controlProps$current2, _controlProps$current3, _controlProps$current4;
|
|
53
|
+
var _controlProps$current, _controlProps$current2, _controlProps$current3, _controlProps$current4, _facadeChatSDK$getCha;
|
|
58
54
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
55
|
_TelemetryHelper.TelemetryHelper.callId = callId;
|
|
60
56
|
await voiceVideoCallingSdk.initialize({
|
|
@@ -63,7 +59,7 @@ const CallingContainerStateful = props => {
|
|
|
63
59
|
// HTML element id where video stream of the agent will be rendered
|
|
64
60
|
remoteVideoHTMLElementId: (_controlProps$current3 = controlProps.currentCallControlProps) === null || _controlProps$current3 === void 0 ? void 0 : (_controlProps$current4 = _controlProps$current3.nonActionIds) === null || _controlProps$current4 === void 0 ? void 0 : _controlProps$current4.remoteVideoTileId,
|
|
65
61
|
// HTML element id where video stream of the customer will be rendered
|
|
66
|
-
OCClient:
|
|
62
|
+
OCClient: (_facadeChatSDK$getCha = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha === void 0 ? void 0 : _facadeChatSDK$getCha.OCClient
|
|
67
63
|
});
|
|
68
64
|
} catch (e) {
|
|
69
65
|
_TelemetryHelper.TelemetryHelper.logCallingEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
@@ -14,9 +14,9 @@ var _NotificationHandler = require("../webchatcontainerstateful/webchatcontrolle
|
|
|
14
14
|
var _NotificationScenarios = require("../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios");
|
|
15
15
|
var _Constants = require("../../common/Constants");
|
|
16
16
|
var _TelemetryHelper = require("../../common/telemetry/TelemetryHelper");
|
|
17
|
-
var _useChatContextStore = _interopRequireDefault(require("../../hooks/useChatContextStore"));
|
|
18
|
-
var _useChatSDKStore = _interopRequireDefault(require("../../hooks/useChatSDKStore"));
|
|
19
17
|
var _defaultMiddlewareLocalizedTexts = require("../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts");
|
|
18
|
+
var _useChatContextStore = _interopRequireDefault(require("../../hooks/useChatContextStore"));
|
|
19
|
+
var _useFacadeChatSDKStore = _interopRequireDefault(require("../../hooks/useFacadeChatSDKStore"));
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -25,8 +25,7 @@ const EmailTranscriptPaneStateful = props => {
|
|
|
25
25
|
const initialTabIndexMap = new Map();
|
|
26
26
|
let elements = [];
|
|
27
27
|
const [state, dispatch] = (0, _useChatContextStore.default)();
|
|
28
|
-
|
|
29
|
-
const chatSDK = (0, _useChatSDKStore.default)();
|
|
28
|
+
const [facadeChatSDK] = (0, _useFacadeChatSDKStore.default)();
|
|
30
29
|
const [initialEmail, setInitialEmail] = (0, _react.useState)("");
|
|
31
30
|
const closeEmailTranscriptPane = () => {
|
|
32
31
|
dispatch({
|
|
@@ -54,7 +53,7 @@ const EmailTranscriptPaneStateful = props => {
|
|
|
54
53
|
attachmentMessage: (props === null || props === void 0 ? void 0 : props.attachmentMessage) ?? "The following attachment was uploaded during the conversation:"
|
|
55
54
|
};
|
|
56
55
|
try {
|
|
57
|
-
await (
|
|
56
|
+
await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.emailLiveChatTranscript(chatTranscriptBody, {
|
|
58
57
|
liveChatContext
|
|
59
58
|
}));
|
|
60
59
|
_NotificationHandler.NotificationHandler.notifySuccess(_NotificationScenarios.NotificationScenarios.EmailAddressSaved, _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts === null || _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts === void 0 ? void 0 : _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS);
|
|
@@ -72,7 +71,7 @@ const EmailTranscriptPaneStateful = props => {
|
|
|
72
71
|
const message = (0, _utils.formatTemplateString)(_defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR, [email]);
|
|
73
72
|
_NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.EmailTranscriptError, (props === null || props === void 0 ? void 0 : props.bannerMessageOnError) ?? message);
|
|
74
73
|
}
|
|
75
|
-
}, [props.attachmentMessage, props.bannerMessageOnError,
|
|
74
|
+
}, [props.attachmentMessage, props.bannerMessageOnError, facadeChatSDK, state.domainStates.liveChatContext]);
|
|
76
75
|
const controlProps = {
|
|
77
76
|
id: "oclcw-emailTranscriptDialogContainer",
|
|
78
77
|
dir: state.domainStates.globalDir,
|
|
@@ -8,6 +8,7 @@ var _TelemetryConstants = require("../../common/telemetry/TelemetryConstants");
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _AudioNotificationStateful = _interopRequireDefault(require("./audionotificationstateful/AudioNotificationStateful"));
|
|
10
10
|
var _Constants = require("../../common/Constants");
|
|
11
|
+
var _ConversationState = require("../../contexts/common/ConversationState");
|
|
11
12
|
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
12
13
|
var _LiveChatWidgetActionType = require("../../contexts/common/LiveChatWidgetActionType");
|
|
13
14
|
var _Audios = require("../../assets/Audios");
|
|
@@ -16,8 +17,7 @@ var _NotificationScenarios = require("../webchatcontainerstateful/webchatcontrol
|
|
|
16
17
|
var _TelemetryHelper = require("../../common/telemetry/TelemetryHelper");
|
|
17
18
|
var _DownloadTranscriptStateful = require("./downloadtranscriptstateful/DownloadTranscriptStateful");
|
|
18
19
|
var _useChatContextStore = _interopRequireDefault(require("../../hooks/useChatContextStore"));
|
|
19
|
-
var
|
|
20
|
-
var _ConversationState = require("../../contexts/common/ConversationState");
|
|
20
|
+
var _useFacadeChatSDKStore = _interopRequireDefault(require("../../hooks/useFacadeChatSDKStore"));
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
22
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
23
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -34,8 +34,7 @@ const FooterStateful = props => {
|
|
|
34
34
|
audioNotificationProps,
|
|
35
35
|
hideFooterDisplay
|
|
36
36
|
} = props;
|
|
37
|
-
|
|
38
|
-
const chatSDK = (0, _useChatSDKStore.default)();
|
|
37
|
+
const [facadeChatSDK] = (0, _useFacadeChatSDKStore.default)();
|
|
39
38
|
const controlProps = {
|
|
40
39
|
id: "oc-lcw-footer",
|
|
41
40
|
dir: state.domainStates.globalDir,
|
|
@@ -45,7 +44,7 @@ const FooterStateful = props => {
|
|
|
45
44
|
Event: _TelemetryConstants.TelemetryEvent.DownloadTranscriptButtonClicked,
|
|
46
45
|
Description: "Download Transcript button clicked."
|
|
47
46
|
});
|
|
48
|
-
await (0, _DownloadTranscriptStateful.downloadTranscript)(
|
|
47
|
+
await (0, _DownloadTranscriptStateful.downloadTranscript)(facadeChatSDK, downloadTranscriptProps, state);
|
|
49
48
|
} catch (ex) {
|
|
50
49
|
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
51
50
|
Event: _TelemetryConstants.TelemetryEvent.DownloadTranscriptFailed,
|
package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js
CHANGED
|
@@ -5,15 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.downloadTranscript = void 0;
|
|
7
7
|
var _Constants = require("../../../common/Constants");
|
|
8
|
-
var
|
|
8
|
+
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
9
|
+
var _utils = require("../../../common/utils");
|
|
10
|
+
var _dompurify = _interopRequireDefault(require("dompurify"));
|
|
11
|
+
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
9
12
|
var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
|
|
13
|
+
var _NotificationScenarios = require("../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios");
|
|
10
14
|
var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
11
|
-
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
12
15
|
var _createChatTranscript = _interopRequireDefault(require("../../../plugins/createChatTranscript"));
|
|
13
|
-
var _dompurify = _interopRequireDefault(require("dompurify"));
|
|
14
|
-
var _utils = require("../../../common/utils");
|
|
15
16
|
var _createReducer = require("../../../contexts/createReducer");
|
|
16
|
-
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
const processDisplayName = displayName => {
|
|
19
19
|
// if displayname matches "teamsvisitor:<some alphanumeric string>", we replace it with "Customer"
|
|
@@ -163,9 +163,7 @@ const beautifyChatTranscripts = (chatTranscripts, renderMarkDown, attachmentMess
|
|
|
163
163
|
const str = docTypeTag + docStartTag + docMetaTag + bodyStartTag + mainTranscriptSection + beautifiedChats + divEndTag + bodyEndTag + docEndTag;
|
|
164
164
|
return str;
|
|
165
165
|
};
|
|
166
|
-
|
|
167
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
|
-
const downloadTranscript = async (chatSDK, downloadTranscriptProps, state) => {
|
|
166
|
+
const downloadTranscript = async (facadeChatSDK, downloadTranscriptProps, state) => {
|
|
169
167
|
var _state$domainStates;
|
|
170
168
|
// Need to keep existing live chat context for scenarios when transcript is downloaded after endchat
|
|
171
169
|
let liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext;
|
|
@@ -176,7 +174,7 @@ const downloadTranscript = async (chatSDK, downloadTranscriptProps, state) => {
|
|
|
176
174
|
});
|
|
177
175
|
liveChatContext = inMemoryState.domainStates.liveChatContext;
|
|
178
176
|
}
|
|
179
|
-
let data = await (
|
|
177
|
+
let data = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getLiveChatTranscript({
|
|
180
178
|
liveChatContext
|
|
181
179
|
}));
|
|
182
180
|
if (typeof data === _Constants.Constants.String) {
|
|
@@ -194,7 +192,7 @@ const downloadTranscript = async (chatSDK, downloadTranscriptProps, state) => {
|
|
|
194
192
|
const transcriptOptions = {
|
|
195
193
|
...webChatTranscript
|
|
196
194
|
};
|
|
197
|
-
await (0, _createChatTranscript.default)(data[_Constants.Constants.ChatMessagesJson],
|
|
195
|
+
await (0, _createChatTranscript.default)(data[_Constants.Constants.ChatMessagesJson], facadeChatSDK, false, transcriptOptions);
|
|
198
196
|
} else {
|
|
199
197
|
// Legacy Transcript
|
|
200
198
|
const chatTranscripts = window.btoa(encodeURIComponent(beautifyChatTranscripts(data[_Constants.Constants.ChatMessagesJson], renderMarkDown, attachmentMessage)));
|
|
@@ -8,29 +8,52 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _ChatAdapterStore = require("../../contexts/ChatAdapterStore");
|
|
9
9
|
var _ChatContextStore = require("../../contexts/ChatContextStore");
|
|
10
10
|
var _ChatSDKStore = require("../../contexts/ChatSDKStore");
|
|
11
|
+
var _FacadeChatSDK = require("../../common/facades/FacadeChatSDK");
|
|
12
|
+
var _FacadeChatSDKStore = require("../../contexts/FacadeChatSDKStore");
|
|
11
13
|
var _LiveChatWidgetStateful = _interopRequireDefault(require("./livechatwidgetstateful/LiveChatWidgetStateful"));
|
|
12
14
|
var _createReducer = require("../../contexts/createReducer");
|
|
13
15
|
var _LiveChatWidgetContextInitialState = require("../../contexts/common/LiveChatWidgetContextInitialState");
|
|
14
16
|
var _getMockChatSDKIfApplicable = require("./common/getMockChatSDKIfApplicable");
|
|
17
|
+
var _utils = require("../../common/utils");
|
|
15
18
|
var _overridePropsOnMockIfApplicable = _interopRequireDefault(require("./common/overridePropsOnMockIfApplicable"));
|
|
16
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
21
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
22
|
const LiveChatWidget = props => {
|
|
20
|
-
var _props$mock;
|
|
23
|
+
var _props$mock, _props$chatConfig, _props$chatConfig$Liv;
|
|
21
24
|
const reducer = (0, _createReducer.createReducer)();
|
|
22
25
|
const [state, dispatch] = (0, _react.useReducer)(reducer, (0, _LiveChatWidgetContextInitialState.getLiveChatWidgetContextInitialState)(props));
|
|
23
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
27
|
const [adapter, setAdapter] = (0, _react.useState)(undefined);
|
|
28
|
+
const [facadeChatSDK, setFacadeChatSDK] = (0, _react.useState)(undefined);
|
|
25
29
|
const chatSDK = (0, _getMockChatSDKIfApplicable.getMockChatSDKIfApplicable)(props.chatSDK, props === null || props === void 0 ? void 0 : (_props$mock = props.mock) === null || _props$mock === void 0 ? void 0 : _props$mock.type);
|
|
26
30
|
(0, _overridePropsOnMockIfApplicable.default)(props);
|
|
27
|
-
|
|
31
|
+
if (!props.chatConfig) {
|
|
32
|
+
throw new Error("chatConfig is required");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
const isAuthenticatedChat = !!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction);
|
|
37
|
+
if (!facadeChatSDK) {
|
|
38
|
+
var _props$mock2;
|
|
39
|
+
setFacadeChatSDK(new _FacadeChatSDK.FacadeChatSDK({
|
|
40
|
+
"chatSDK": chatSDK,
|
|
41
|
+
"chatConfig": props.chatConfig,
|
|
42
|
+
"isAuthenticated": isAuthenticatedChat,
|
|
43
|
+
"getAuthToken": props === null || props === void 0 ? void 0 : props.getAuthToken,
|
|
44
|
+
//when type is not undefined, it means the SDK is mocked
|
|
45
|
+
"isSDKMocked": !(0, _utils.isNullOrUndefined)(props === null || props === void 0 ? void 0 : (_props$mock2 = props.mock) === null || _props$mock2 === void 0 ? void 0 : _props$mock2.type)
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
return /*#__PURE__*/_react.default.createElement(_FacadeChatSDKStore.FacadeChatSDKStore.Provider, {
|
|
49
|
+
value: [facadeChatSDK, setFacadeChatSDK]
|
|
50
|
+
}, /*#__PURE__*/_react.default.createElement(_ChatSDKStore.ChatSDKStore.Provider, {
|
|
28
51
|
value: chatSDK
|
|
29
52
|
}, /*#__PURE__*/_react.default.createElement(_ChatAdapterStore.ChatAdapterStore.Provider, {
|
|
30
53
|
value: [adapter, setAdapter]
|
|
31
54
|
}, /*#__PURE__*/_react.default.createElement(_ChatContextStore.ChatContextStore.Provider, {
|
|
32
55
|
value: [state, dispatch]
|
|
33
|
-
}, /*#__PURE__*/_react.default.createElement(_LiveChatWidgetStateful.default, props))));
|
|
56
|
+
}, /*#__PURE__*/_react.default.createElement(_LiveChatWidgetStateful.default, props)))));
|
|
34
57
|
};
|
|
35
58
|
exports.LiveChatWidget = LiveChatWidget;
|
|
36
59
|
var _default = LiveChatWidget;
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.removeAuthTokenProvider = exports.handleAuthentication = exports.getAuthClientFunction = void 0;
|
|
7
7
|
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
8
8
|
var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
9
|
-
var _utils = require("../../../common/utils");
|
|
10
9
|
var _Constants = require("../../../common/Constants");
|
|
10
|
+
var _utils = require("../../../common/utils");
|
|
11
11
|
const getAuthClientFunction = chatConfig => {
|
|
12
12
|
let authClientFunction = undefined;
|
|
13
13
|
if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
|
|
@@ -16,8 +16,6 @@ const getAuthClientFunction = chatConfig => {
|
|
|
16
16
|
}
|
|
17
17
|
return authClientFunction;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
19
|
exports.getAuthClientFunction = getAuthClientFunction;
|
|
22
20
|
const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
23
21
|
const authClientFunction = getAuthClientFunction(chatConfig);
|
|
@@ -31,7 +29,10 @@ const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
|
31
29
|
chatSDK.setAuthTokenProvider(async () => {
|
|
32
30
|
return token;
|
|
33
31
|
});
|
|
34
|
-
return
|
|
32
|
+
return {
|
|
33
|
+
"result": true,
|
|
34
|
+
"token": token
|
|
35
|
+
};
|
|
35
36
|
} else {
|
|
36
37
|
// instead of returning false, it's more appropiate to thrown an error to force error handling on the caller side
|
|
37
38
|
// this will help to avoid the error to be ignored and the chat to be started
|
|
@@ -41,7 +42,15 @@ const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
|
41
42
|
throw new Error(_Constants.WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
"result": false,
|
|
47
|
+
"token": null,
|
|
48
|
+
"error": {
|
|
49
|
+
"message": "No auth client function or getAuthToken function provided",
|
|
50
|
+
"getAuthTokenPresent": getAuthToken ? true : false,
|
|
51
|
+
"authClientFunctionPresent": authClientFunction ? true : false
|
|
52
|
+
}
|
|
53
|
+
};
|
|
45
54
|
};
|
|
46
55
|
|
|
47
56
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|