@microsoft/omnichannel-chat-widget 1.7.8-main.29ce174 → 1.7.8-main.50111af
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/Constants.js +57 -18
- package/lib/cjs/common/KeyCodes.js +6 -1
- package/lib/cjs/common/contextDataStore/DataStoreManager.js +6 -1
- package/lib/cjs/common/facades/FacadeChatSDK.js +385 -292
- package/lib/cjs/common/storage/default/defaultCacheManager.js +6 -3
- package/lib/cjs/common/telemetry/TelemetryConstants.js +137 -116
- package/lib/cjs/common/telemetry/TelemetryHelper.js +219 -181
- package/lib/cjs/common/telemetry/TelemetryManager.js +9 -2
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +4 -5
- package/lib/cjs/components/headerstateful/HeaderStateful.js +3 -5
- package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +32 -19
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +71 -56
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +17 -8
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/HiddenAdaptiveCardActivitySubscriber.js +65 -52
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +31 -18
- package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +14 -6
- package/lib/cjs/components/livechatwidget/common/Deferred.js +14 -6
- package/lib/cjs/components/livechatwidget/common/chatDisconnectHelper.js +3 -1
- package/lib/cjs/components/livechatwidget/common/endChat.js +4 -18
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +0 -5
- package/lib/cjs/components/livechatwidget/common/startChat.js +2 -23
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +3 -3
- package/lib/cjs/components/ooohpanestateful/OOOHPaneStateful.js +6 -4
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +7 -6
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +4 -3
- package/lib/cjs/components/webchatcontainerstateful/common/DemoChatAdapter.js +88 -65
- package/lib/cjs/components/webchatcontainerstateful/common/DemoChatSDK.js +26 -7
- package/lib/cjs/components/webchatcontainerstateful/common/DesignerChatAdapter.js +49 -26
- package/lib/cjs/components/webchatcontainerstateful/common/DesignerChatSDK.js +57 -35
- package/lib/cjs/components/webchatcontainerstateful/common/mockadapter.js +62 -52
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +95 -61
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +6 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +6 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/markdownrenderers/HyperlinkTextOverrideRenderer.js +53 -39
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +4 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/notification/NotificationHandler.js +88 -60
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +18 -6
- package/lib/cjs/firstresponselatency/Constants.js +13 -0
- package/lib/cjs/firstresponselatency/FirstMessageTrackerFromBot.js +118 -0
- package/lib/cjs/firstresponselatency/FirstResponseLatencyTracker.js +201 -0
- package/lib/cjs/firstresponselatency/util.js +98 -0
- package/lib/cjs/plugins/createChatTranscript.js +88 -58
- package/lib/cjs/plugins/newMessageEventHandler.js +102 -88
- package/lib/esm/common/Constants.js +57 -18
- package/lib/esm/common/KeyCodes.js +6 -1
- package/lib/esm/common/contextDataStore/DataStoreManager.js +6 -1
- package/lib/esm/common/facades/FacadeChatSDK.js +385 -292
- package/lib/esm/common/storage/default/defaultCacheManager.js +6 -1
- package/lib/esm/common/telemetry/TelemetryConstants.js +137 -116
- package/lib/esm/common/telemetry/TelemetryHelper.js +219 -181
- package/lib/esm/common/telemetry/TelemetryManager.js +9 -2
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -5
- package/lib/esm/components/headerstateful/HeaderStateful.js +3 -5
- package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +32 -19
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +71 -56
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +17 -8
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/HiddenAdaptiveCardActivitySubscriber.js +65 -52
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +31 -18
- package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +14 -6
- package/lib/esm/components/livechatwidget/common/Deferred.js +14 -6
- package/lib/esm/components/livechatwidget/common/chatDisconnectHelper.js +3 -1
- package/lib/esm/components/livechatwidget/common/endChat.js +4 -18
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +1 -6
- package/lib/esm/components/livechatwidget/common/startChat.js +3 -24
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +3 -3
- package/lib/esm/components/ooohpanestateful/OOOHPaneStateful.js +6 -4
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +7 -6
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +4 -3
- package/lib/esm/components/webchatcontainerstateful/common/DemoChatAdapter.js +88 -65
- package/lib/esm/components/webchatcontainerstateful/common/DemoChatSDK.js +26 -7
- package/lib/esm/components/webchatcontainerstateful/common/DesignerChatAdapter.js +49 -26
- package/lib/esm/components/webchatcontainerstateful/common/DesignerChatSDK.js +57 -35
- package/lib/esm/components/webchatcontainerstateful/common/mockadapter.js +63 -52
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +95 -61
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +6 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +6 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/markdownrenderers/HyperlinkTextOverrideRenderer.js +53 -39
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +4 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/notification/NotificationHandler.js +88 -60
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +18 -6
- package/lib/esm/firstresponselatency/Constants.js +6 -0
- package/lib/esm/firstresponselatency/FirstMessageTrackerFromBot.js +112 -0
- package/lib/esm/firstresponselatency/FirstResponseLatencyTracker.js +194 -0
- package/lib/esm/firstresponselatency/util.js +87 -0
- package/lib/esm/plugins/createChatTranscript.js +88 -58
- package/lib/esm/plugins/newMessageEventHandler.js +100 -86
- package/lib/types/common/facades/FacadeChatSDK.d.ts +1 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +8 -1
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatProps.d.ts +2 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
- package/lib/types/firstresponselatency/Constants.d.ts +30 -0
- package/lib/types/firstresponselatency/FirstMessageTrackerFromBot.d.ts +1 -0
- package/lib/types/firstresponselatency/FirstResponseLatencyTracker.d.ts +22 -0
- package/lib/types/firstresponselatency/util.d.ts +7 -0
- package/package.json +18 -6
|
@@ -9,24 +9,15 @@ var _authHelper = require("../../components/livechatwidget/common/authHelper");
|
|
|
9
9
|
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
10
10
|
var _TelemetryHelper = require("../telemetry/TelemetryHelper");
|
|
11
11
|
var _utils = require("../utils");
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
15
|
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
16
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
17
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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, disableReauthentication) {
|
|
18
|
+
let FacadeChatSDK = /*#__PURE__*/function () {
|
|
19
|
+
function FacadeChatSDK(input, disableReauthentication) {
|
|
20
|
+
_classCallCheck(this, FacadeChatSDK);
|
|
30
21
|
_defineProperty(this, "chatSDK", void 0);
|
|
31
22
|
_defineProperty(this, "chatConfig", void 0);
|
|
32
23
|
_defineProperty(this, "token", "");
|
|
@@ -44,311 +35,413 @@ class FacadeChatSDK {
|
|
|
44
35
|
}
|
|
45
36
|
|
|
46
37
|
//set default expiration to zero, for undefined or missed exp in jwt
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
38
|
+
_createClass(FacadeChatSDK, [{
|
|
39
|
+
key: "isSDKMocked",
|
|
40
|
+
value: function isSDKMocked() {
|
|
41
|
+
return this.sdkMocked;
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "getChatSDK",
|
|
45
|
+
value: function getChatSDK() {
|
|
46
|
+
return this.chatSDK;
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "destroy",
|
|
50
|
+
value: function destroy() {
|
|
51
|
+
this.token = null;
|
|
52
|
+
this.expiration = 0;
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "isTokenSet",
|
|
56
|
+
value: function isTokenSet() {
|
|
57
|
+
return !(0, _utils.isNullOrEmptyString)(this.token);
|
|
60
58
|
}
|
|
59
|
+
}, {
|
|
60
|
+
key: "convertExpiration",
|
|
61
|
+
value: function convertExpiration() {
|
|
62
|
+
let expiration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
63
|
+
// Converting expiration to seconds, if contains decimals or is identified as milliseconds
|
|
64
|
+
if (expiration.toString().length === 13) {
|
|
65
|
+
return Math.floor(expiration / 1000);
|
|
66
|
+
}
|
|
67
|
+
// If the epoch value is already in seconds, return it as is
|
|
68
|
+
return expiration;
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "isTokenExpired",
|
|
72
|
+
value: function isTokenExpired() {
|
|
73
|
+
// if expiration is 0, token is not going to be validated ( this is to cover the case of token with no expiration)
|
|
74
|
+
if (this.expiration === 0) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
61
77
|
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
// obtain current time in seconds
|
|
79
|
+
const now = Math.floor(Date.now() / 1000);
|
|
64
80
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
// compare expiration time with current time
|
|
82
|
+
if (now > this.expiration) {
|
|
83
|
+
console.error("Token is expired", now, this.expiration, now > this.expiration);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
69
87
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
}, {
|
|
89
|
+
key: "enforceBase64Encoding",
|
|
90
|
+
value: function enforceBase64Encoding(payload) {
|
|
91
|
+
//base64url when present, switches the "-" and "_" characters with "+" and "/"
|
|
92
|
+
const base64Payload = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
93
|
+
// since base64 encoding requires padding, we need to add padding to the payload
|
|
94
|
+
return base64Payload.padEnd(base64Payload.length + (4 - base64Payload.length % 4) % 4, "=");
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "extractExpFromToken",
|
|
98
|
+
value: function extractExpFromToken(token) {
|
|
99
|
+
const tokenParts = token.split(".");
|
|
100
|
+
const last3digits = token.slice(-3);
|
|
81
101
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
const payload = this.enforceBase64Encoding(tokenParts[1]);
|
|
96
|
-
// decode payload
|
|
97
|
-
const decodedPayload = atob(payload);
|
|
98
|
-
const jsonPayload = JSON.parse(decodedPayload);
|
|
99
|
-
// check if exp is present in payload
|
|
100
|
-
if (jsonPayload) {
|
|
101
|
-
if (jsonPayload.exp) {
|
|
102
|
-
return jsonPayload.exp;
|
|
103
|
-
}
|
|
104
|
-
return 0;
|
|
102
|
+
// token must have 3 parts as JWT format
|
|
103
|
+
if (tokenParts.length !== 3) {
|
|
104
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
105
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
106
|
+
Description: "Invalid token format",
|
|
107
|
+
ExceptionDetails: {
|
|
108
|
+
message: "Invalid token format, must be in JWT format",
|
|
109
|
+
token: last3digits
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
throw new Error("Invalid token format, must be in JWT format");
|
|
105
113
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
118
|
-
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
119
|
-
Description: "Failed to decode token",
|
|
120
|
-
ExceptionDetails: {
|
|
121
|
-
message: "Failed to decode token",
|
|
122
|
-
token: last3digits
|
|
114
|
+
try {
|
|
115
|
+
const payload = this.enforceBase64Encoding(tokenParts[1]);
|
|
116
|
+
// decode payload
|
|
117
|
+
const decodedPayload = atob(payload);
|
|
118
|
+
const jsonPayload = JSON.parse(decodedPayload);
|
|
119
|
+
// check if exp is present in payload
|
|
120
|
+
if (jsonPayload) {
|
|
121
|
+
if (jsonPayload.exp) {
|
|
122
|
+
return jsonPayload.exp;
|
|
123
|
+
}
|
|
124
|
+
return 0;
|
|
123
125
|
}
|
|
124
|
-
});
|
|
125
|
-
throw new Error("Failed to decode token");
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async setToken(token) {
|
|
129
|
-
// token must be not null, and must be new
|
|
130
|
-
if (!(0, _utils.isNullOrEmptyString)(token) && token !== this.token) {
|
|
131
|
-
const last3digits = token.slice(-3);
|
|
132
|
-
const instant = Math.floor(Date.now() / 1000);
|
|
133
|
-
this.token = token;
|
|
134
|
-
// calculate expiration time
|
|
135
|
-
this.expiration = this.convertExpiration(this.extractExpFromToken(token) || 0);
|
|
136
|
-
// this is a control , in case the getAuthToken function returns same token
|
|
137
|
-
if (this.expiration > 0 && this.expiration < instant) {
|
|
138
126
|
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
139
|
-
Event: _TelemetryConstants.TelemetryEvent.
|
|
140
|
-
Description: "
|
|
127
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
128
|
+
Description: "Invalid token payload",
|
|
141
129
|
ExceptionDetails: {
|
|
142
|
-
"
|
|
143
|
-
|
|
144
|
-
"Token": last3digits
|
|
130
|
+
message: "Token payload is not valid JSON",
|
|
131
|
+
token: last3digits
|
|
145
132
|
}
|
|
146
133
|
});
|
|
147
|
-
throw new Error(
|
|
134
|
+
throw new Error("Invalid token payload, payload is not valid JSON");
|
|
135
|
+
} catch (e) {
|
|
136
|
+
console.error("Failed to decode token", e);
|
|
137
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
138
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
139
|
+
Description: "Failed to decode token",
|
|
140
|
+
ExceptionDetails: {
|
|
141
|
+
message: "Failed to decode token",
|
|
142
|
+
token: last3digits
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
throw new Error("Failed to decode token");
|
|
148
146
|
}
|
|
149
147
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (this.isTokenSet() && !this.isTokenExpired()) {
|
|
175
|
-
return {
|
|
176
|
-
result: true,
|
|
177
|
-
message: "Token is valid"
|
|
178
|
-
};
|
|
148
|
+
}, {
|
|
149
|
+
key: "setToken",
|
|
150
|
+
value: async function setToken(token) {
|
|
151
|
+
// token must be not null, and must be new
|
|
152
|
+
if (!(0, _utils.isNullOrEmptyString)(token) && token !== this.token) {
|
|
153
|
+
const last3digits = token.slice(-3);
|
|
154
|
+
const instant = Math.floor(Date.now() / 1000);
|
|
155
|
+
this.token = token;
|
|
156
|
+
// calculate expiration time
|
|
157
|
+
this.expiration = this.convertExpiration(this.extractExpFromToken(token) || 0);
|
|
158
|
+
// this is a control , in case the getAuthToken function returns same token
|
|
159
|
+
if (this.expiration > 0 && this.expiration < instant) {
|
|
160
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
161
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenExpired,
|
|
162
|
+
Description: "New token is already expired",
|
|
163
|
+
ExceptionDetails: {
|
|
164
|
+
"Instant": instant,
|
|
165
|
+
"Expiration": this.expiration,
|
|
166
|
+
"Token": last3digits
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
throw new Error(`New token is already expired, with epoch time ${this.expiration} , last 3 digits of token: ${last3digits}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
179
172
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
};
|
|
173
|
+
}, {
|
|
174
|
+
key: "corroborateTokenIsSet",
|
|
175
|
+
value: async function corroborateTokenIsSet(chatSDK) {
|
|
176
|
+
var _chatSDK$chatSDKConfi;
|
|
177
|
+
// if getAuthToken is not set, it's because handleAuthentication hasnt being called
|
|
178
|
+
// so we need to call it
|
|
179
|
+
if (this.isAuthenticated && (chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$chatSDKConfi = chatSDK.chatSDKConfig) === null || _chatSDK$chatSDKConfi === void 0 ? void 0 : _chatSDK$chatSDKConfi.getAuthToken) === undefined) {
|
|
180
|
+
(0, _authHelper.handleAuthentication)(this.chatSDK, this.chatConfig, this.getAuthToken);
|
|
181
|
+
}
|
|
190
182
|
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "tokenRing",
|
|
185
|
+
value: async function tokenRing() {
|
|
186
|
+
var _this$chatSDK$chatSDK;
|
|
187
|
+
if (this.disableReauthentication === true) {
|
|
188
|
+
// Since we are not validating the token anymore, we at least need to check if the token is set
|
|
189
|
+
// no need to validate anything other that the token is set
|
|
190
|
+
await this.corroborateTokenIsSet(this.chatSDK);
|
|
191
|
+
// facade feature is disabled, so we are bypassing the re authentication and let it fail.
|
|
192
|
+
return {
|
|
193
|
+
result: true,
|
|
194
|
+
message: "Facade is disabled"
|
|
195
|
+
};
|
|
196
|
+
}
|
|
191
197
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
this.expiration = 0;
|
|
195
|
-
try {
|
|
196
|
-
const ring = await (0, _authHelper.handleAuthentication)(this.chatSDK, this.chatConfig, this.getAuthToken);
|
|
197
|
-
if (ring.result === true && ring.token) {
|
|
198
|
-
await this.setToken(ring.token);
|
|
199
|
-
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
200
|
-
Event: _TelemetryConstants.TelemetryEvent.NewTokenSuccess,
|
|
201
|
-
Description: "New Token obtained",
|
|
202
|
-
Data: {
|
|
203
|
-
"Token_Expiration": this.expiration
|
|
204
|
-
}
|
|
205
|
-
});
|
|
198
|
+
// this is needed for storybooks, specifically for reconnect pane which requires authentication bypass
|
|
199
|
+
if (this.sdkMocked === true) {
|
|
206
200
|
return {
|
|
207
201
|
result: true,
|
|
208
|
-
message: "
|
|
202
|
+
message: "Authentication not needed"
|
|
209
203
|
};
|
|
210
|
-
}
|
|
211
|
-
|
|
204
|
+
}
|
|
205
|
+
if (!this.isAuthenticated) {
|
|
206
|
+
return {
|
|
207
|
+
result: true,
|
|
208
|
+
message: "Authentication not needed"
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (this.isTokenSet() && !this.isTokenExpired()) {
|
|
212
|
+
return {
|
|
213
|
+
result: true,
|
|
214
|
+
message: "Token is valid"
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
if (this.getAuthToken === undefined && ((_this$chatSDK$chatSDK = this.chatSDK.chatSDKConfig) === null || _this$chatSDK$chatSDK === void 0 ? void 0 : _this$chatSDK$chatSDK.getAuthToken) === undefined) {
|
|
212
218
|
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
213
219
|
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
214
|
-
Description:
|
|
215
|
-
ExceptionDetails:
|
|
220
|
+
Description: "GetAuthToken function is not present",
|
|
221
|
+
ExceptionDetails: "Missing function : " + (0, _authHelper.getAuthClientFunction)(this.chatConfig)
|
|
216
222
|
});
|
|
217
223
|
return {
|
|
218
224
|
result: false,
|
|
219
|
-
message:
|
|
225
|
+
message: "GetAuthToken function is not present"
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// if token is not set, or token is already expired , then go to grab a token
|
|
230
|
+
this.token = "";
|
|
231
|
+
this.expiration = 0;
|
|
232
|
+
try {
|
|
233
|
+
const ring = await (0, _authHelper.handleAuthentication)(this.chatSDK, this.chatConfig, this.getAuthToken);
|
|
234
|
+
if ((ring === null || ring === void 0 ? void 0 : ring.result) === true && ring !== null && ring !== void 0 && ring.token) {
|
|
235
|
+
await this.setToken(ring.token);
|
|
236
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
237
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenSuccess,
|
|
238
|
+
Description: "New Token obtained",
|
|
239
|
+
Data: {
|
|
240
|
+
"Token_Expiration": this.expiration
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
result: true,
|
|
245
|
+
message: "New Token obtained"
|
|
246
|
+
};
|
|
247
|
+
} else {
|
|
248
|
+
var _ring$error, _ring$error2;
|
|
249
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
250
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
251
|
+
Description: ring === null || ring === void 0 ? void 0 : (_ring$error = ring.error) === null || _ring$error === void 0 ? void 0 : _ring$error.message,
|
|
252
|
+
ExceptionDetails: ring === null || ring === void 0 ? void 0 : ring.error
|
|
253
|
+
});
|
|
254
|
+
return {
|
|
255
|
+
result: false,
|
|
256
|
+
message: (ring === null || ring === void 0 ? void 0 : (_ring$error2 = ring.error) === null || _ring$error2 === void 0 ? void 0 : _ring$error2.message) || "Failed to get token"
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
} catch (e) {
|
|
260
|
+
console.error("Unexpected error while getting token", e);
|
|
261
|
+
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
262
|
+
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
263
|
+
Description: "Unexpected error while getting token",
|
|
264
|
+
ExceptionDetails: e
|
|
265
|
+
});
|
|
266
|
+
return {
|
|
267
|
+
result: false,
|
|
268
|
+
message: "Unexpected error while getting token"
|
|
220
269
|
};
|
|
221
270
|
}
|
|
222
|
-
} catch (e) {
|
|
223
|
-
console.error("Unexpected error while getting token", e);
|
|
224
|
-
_TelemetryHelper.TelemetryHelper.logFacadeChatSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
225
|
-
Event: _TelemetryConstants.TelemetryEvent.NewTokenFailed,
|
|
226
|
-
Description: "Unexpected error while getting token",
|
|
227
|
-
ExceptionDetails: e
|
|
228
|
-
});
|
|
229
|
-
return {
|
|
230
|
-
result: false,
|
|
231
|
-
message: "Unexpected error while getting token"
|
|
232
|
-
};
|
|
233
271
|
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const executionErrorMessage = `Authentication failed: Process to get a token failed for ${functionName}, ${pingResponse.message}`;
|
|
241
|
-
//telemetry is already logged in tokenRing, so no need to log again, just return the error and communicate to the console
|
|
242
|
-
console.error(executionErrorMessage);
|
|
243
|
-
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
244
|
-
eventName: _TelemetryConstants.BroadcastEvent.OnWidgetError,
|
|
245
|
-
payload: {
|
|
246
|
-
errorMessage: executionErrorMessage
|
|
272
|
+
}, {
|
|
273
|
+
key: "validateAndExecuteCall",
|
|
274
|
+
value: async function validateAndExecuteCall(functionName, fn) {
|
|
275
|
+
const pingResponse = await this.tokenRing();
|
|
276
|
+
if (pingResponse.result === true) {
|
|
277
|
+
return fn();
|
|
247
278
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
279
|
+
const executionErrorMessage = `Authentication failed: Process to get a token failed for ${functionName}, ${pingResponse.message}`;
|
|
280
|
+
//telemetry is already logged in tokenRing, so no need to log again, just return the error and communicate to the console
|
|
281
|
+
console.error(executionErrorMessage);
|
|
282
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
283
|
+
eventName: _TelemetryConstants.BroadcastEvent.OnWidgetError,
|
|
284
|
+
payload: {
|
|
285
|
+
errorMessage: executionErrorMessage
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
throw new Error(executionErrorMessage);
|
|
289
|
+
}
|
|
290
|
+
}, {
|
|
291
|
+
key: "initialize",
|
|
292
|
+
value: async function initialize() {
|
|
293
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
294
|
+
return this.validateAndExecuteCall("initialize", () => this.chatSDK.initialize(optionalParams));
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
key: "getChatReconnectContext",
|
|
298
|
+
value: async function getChatReconnectContext() {
|
|
299
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
300
|
+
return this.validateAndExecuteCall("getChatReconnectContext", () => this.chatSDK.getChatReconnectContext(optionalParams));
|
|
301
|
+
}
|
|
302
|
+
}, {
|
|
303
|
+
key: "startChat",
|
|
304
|
+
value: async function startChat() {
|
|
305
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
306
|
+
return this.validateAndExecuteCall("startChat", () => this.chatSDK.startChat(optionalParams));
|
|
307
|
+
}
|
|
308
|
+
}, {
|
|
309
|
+
key: "endChat",
|
|
310
|
+
value: async function endChat() {
|
|
311
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
312
|
+
return this.validateAndExecuteCall("endChat", () => this.chatSDK.endChat(optionalParams));
|
|
313
|
+
}
|
|
314
|
+
}, {
|
|
315
|
+
key: "getCurrentLiveChatContext",
|
|
316
|
+
value: async function getCurrentLiveChatContext() {
|
|
317
|
+
return this.validateAndExecuteCall("getCurrentLiveChatContext", () => this.chatSDK.getCurrentLiveChatContext());
|
|
318
|
+
}
|
|
319
|
+
}, {
|
|
320
|
+
key: "getConversationDetails",
|
|
321
|
+
value: async function getConversationDetails() {
|
|
322
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
323
|
+
return this.validateAndExecuteCall("getConversationDetails", () => this.chatSDK.getConversationDetails(optionalParams));
|
|
324
|
+
}
|
|
274
325
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
326
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
327
|
+
}, {
|
|
328
|
+
key: "getPreChatSurvey",
|
|
329
|
+
value: async function getPreChatSurvey() {
|
|
330
|
+
let parse = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
331
|
+
//prechat survey is obtained from config object, which is not required to be authenticated
|
|
332
|
+
// removing the tokenRing function from this call for backward compatibility
|
|
333
|
+
// TODO :: wrap this function around authentication
|
|
334
|
+
return this.chatSDK.getPreChatSurvey(parse);
|
|
335
|
+
}
|
|
336
|
+
}, {
|
|
337
|
+
key: "getLiveChatConfig",
|
|
338
|
+
value: async function getLiveChatConfig(optionalParams) {
|
|
339
|
+
return this.validateAndExecuteCall("getLiveChatConfig", () => this.chatSDK.getLiveChatConfig(optionalParams));
|
|
340
|
+
}
|
|
341
|
+
}, {
|
|
342
|
+
key: "getChatToken",
|
|
343
|
+
value: async function getChatToken() {
|
|
344
|
+
let cached = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
345
|
+
let optionalParams = arguments.length > 1 ? arguments[1] : undefined;
|
|
346
|
+
return this.validateAndExecuteCall("getChatToken", () => this.chatSDK.getChatToken(cached, optionalParams));
|
|
347
|
+
}
|
|
348
|
+
}, {
|
|
349
|
+
key: "getCallingToken",
|
|
350
|
+
value: async function getCallingToken() {
|
|
351
|
+
return this.validateAndExecuteCall("getCallingToken", () => this.chatSDK.getCallingToken());
|
|
352
|
+
}
|
|
353
|
+
}, {
|
|
354
|
+
key: "getMessages",
|
|
355
|
+
value: async function getMessages() {
|
|
356
|
+
return this.validateAndExecuteCall("getMessages", () => this.chatSDK.getMessages());
|
|
357
|
+
}
|
|
358
|
+
}, {
|
|
359
|
+
key: "getDataMaskingRules",
|
|
360
|
+
value: async function getDataMaskingRules() {
|
|
361
|
+
return this.validateAndExecuteCall("getDataMaskingRules", () => this.chatSDK.getDataMaskingRules());
|
|
362
|
+
}
|
|
363
|
+
}, {
|
|
364
|
+
key: "sendMessage",
|
|
365
|
+
value: async function sendMessage(message) {
|
|
366
|
+
return this.validateAndExecuteCall("sendMessage", () => this.chatSDK.sendMessage(message));
|
|
367
|
+
}
|
|
368
|
+
}, {
|
|
369
|
+
key: "onNewMessage",
|
|
370
|
+
value: async function onNewMessage(onNewMessageCallback) {
|
|
371
|
+
let optionalParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
372
|
+
disablePolling: false
|
|
373
|
+
};
|
|
374
|
+
return this.validateAndExecuteCall("onNewMessage", () => this.chatSDK.onNewMessage(onNewMessageCallback, optionalParams));
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
key: "sendTypingEvent",
|
|
378
|
+
value: async function sendTypingEvent() {
|
|
379
|
+
return this.validateAndExecuteCall("sendTypingEvent", () => this.chatSDK.sendTypingEvent());
|
|
380
|
+
}
|
|
381
|
+
}, {
|
|
382
|
+
key: "onTypingEvent",
|
|
383
|
+
value: async function onTypingEvent(onTypingEventCallback) {
|
|
384
|
+
return this.validateAndExecuteCall("onTypingEvent", () => this.chatSDK.onTypingEvent(onTypingEventCallback));
|
|
385
|
+
}
|
|
386
|
+
}, {
|
|
387
|
+
key: "onAgentEndSession",
|
|
388
|
+
value: async function onAgentEndSession(onAgentEndSessionCallback) {
|
|
389
|
+
return this.validateAndExecuteCall("onAgentEndSession", () => this.chatSDK.onAgentEndSession(onAgentEndSessionCallback));
|
|
390
|
+
}
|
|
391
|
+
}, {
|
|
392
|
+
key: "uploadFileAttachment",
|
|
393
|
+
value: async function uploadFileAttachment(fileInfo) {
|
|
394
|
+
return this.validateAndExecuteCall("uploadFileAttachment", () => this.chatSDK.uploadFileAttachment(fileInfo));
|
|
395
|
+
}
|
|
396
|
+
}, {
|
|
397
|
+
key: "downloadFileAttachment",
|
|
398
|
+
value: async function downloadFileAttachment(fileMetadata) {
|
|
399
|
+
return this.validateAndExecuteCall("downloadFileAttachment", () => this.chatSDK.downloadFileAttachment(fileMetadata));
|
|
400
|
+
}
|
|
401
|
+
}, {
|
|
402
|
+
key: "emailLiveChatTranscript",
|
|
403
|
+
value: async function emailLiveChatTranscript(body) {
|
|
404
|
+
let optionalParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
405
|
+
return this.validateAndExecuteCall("emailLiveChatTranscript", () => this.chatSDK.emailLiveChatTranscript(body, optionalParams));
|
|
406
|
+
}
|
|
407
|
+
}, {
|
|
408
|
+
key: "getLiveChatTranscript",
|
|
409
|
+
value: async function getLiveChatTranscript() {
|
|
410
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
411
|
+
return this.validateAndExecuteCall("getLiveChatTranscript", () => this.chatSDK.getLiveChatTranscript(optionalParams));
|
|
412
|
+
}
|
|
332
413
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
414
|
+
// response from origin is unknown, but this definition breaks create adapter for shimAdapter, switching to any until type is returned from origin
|
|
415
|
+
}, {
|
|
416
|
+
key: "createChatAdapter",
|
|
417
|
+
value: async function createChatAdapter() {
|
|
418
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
419
|
+
return this.validateAndExecuteCall("createChatAdapter", () => this.chatSDK.createChatAdapter(optionalParams));
|
|
420
|
+
}
|
|
421
|
+
}, {
|
|
422
|
+
key: "isVoiceVideoCallingEnabled",
|
|
423
|
+
value: async function isVoiceVideoCallingEnabled() {
|
|
424
|
+
this.tokenRing();
|
|
425
|
+
return this.chatSDK.isVoiceVideoCallingEnabled();
|
|
426
|
+
}
|
|
427
|
+
}, {
|
|
428
|
+
key: "getVoiceVideoCalling",
|
|
429
|
+
value: async function getVoiceVideoCalling() {
|
|
430
|
+
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
431
|
+
return this.validateAndExecuteCall("getVoiceVideoCalling", () => this.chatSDK.getVoiceVideoCalling(params));
|
|
432
|
+
}
|
|
433
|
+
}, {
|
|
434
|
+
key: "getPostChatSurveyContext",
|
|
435
|
+
value: async function getPostChatSurveyContext() {
|
|
436
|
+
return this.validateAndExecuteCall("getPostChatSurveyContext", () => this.chatSDK.getPostChatSurveyContext());
|
|
437
|
+
}
|
|
438
|
+
}, {
|
|
439
|
+
key: "getAgentAvailability",
|
|
440
|
+
value: async function getAgentAvailability() {
|
|
441
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
442
|
+
return this.validateAndExecuteCall("getAgentAvailability", () => this.chatSDK.getAgentAvailability(optionalParams));
|
|
443
|
+
}
|
|
444
|
+
}]);
|
|
445
|
+
return FacadeChatSDK;
|
|
446
|
+
}();
|
|
354
447
|
exports.FacadeChatSDK = FacadeChatSDK;
|