@microsoft/omnichannel-chat-widget 1.0.3 → 1.0.4-main.5c98fd0

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.
@@ -112,6 +112,9 @@ _defineProperty(Constants, "SessionCacheSuffix", "session");
112
112
  _defineProperty(Constants, "PopoutCacheSuffix", "popout");
113
113
  // Visibility timeout for conversation details
114
114
  _defineProperty(Constants, "LWICheckOnVisibilityTimeout", 3 * 60 * 1000);
115
+ // 3 minute
116
+ // Popup mode custom context response event message name
117
+ _defineProperty(Constants, "InitContextParamsResponse", "initContextParamsResponse");
115
118
  const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
116
119
  exports.Regex = Regex;
117
120
  class HtmlIdNames {}
@@ -130,7 +130,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
130
130
  try {
131
131
  var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
132
132
  // Set custom context params
133
- setCustomContextParams(props);
133
+ await setCustomContextParams(props);
134
134
  const defaultOptionalParams = {
135
135
  sendDefaultInitContext: true,
136
136
  isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
@@ -286,7 +286,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
286
286
  };
287
287
 
288
288
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
289
- const setCustomContextParams = props => {
289
+ const setCustomContextParams = async props => {
290
290
  var _props$chatConfig, _props$chatConfig$Liv, _persistedState$domai8;
291
291
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
292
  const isAuthenticatedChat = props !== null && props !== void 0 && (_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 ? true : false;
@@ -303,11 +303,18 @@ const setCustomContextParams = props => {
303
303
  var _persistedState$domai9;
304
304
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
305
305
  Event: _TelemetryConstants.TelemetryEvent.SetCustomContext,
306
- Description: "Setting custom context for unauthenicated chat"
306
+ Description: "Setting custom context for unauthenticated chat"
307
307
  });
308
308
  optionalParams = Object.assign({}, optionalParams, {
309
309
  customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
310
310
  });
311
+ } else {
312
+ const customContextFromParent = await getInitContextParamsForPopout();
313
+ if (!(0, _utils.isUndefinedOrEmpty)(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
314
+ optionalParams = Object.assign({}, optionalParams, {
315
+ customContext: customContextFromParent.contextVariables
316
+ });
317
+ }
311
318
  }
312
319
  };
313
320
  const canStartPopoutChat = async props => {
@@ -369,4 +376,34 @@ const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
369
376
  return false;
370
377
  }
371
378
  };
372
- exports.checkIfConversationStillValid = checkIfConversationStillValid;
379
+
380
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
381
+ exports.checkIfConversationStillValid = checkIfConversationStillValid;
382
+ const getInitContextParamsForPopout = async () => {
383
+ return window.opener ? await getInitContextParamForPopoutFromOuterScope(window.opener) : null;
384
+ };
385
+
386
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
387
+ const getInitContextParamForPopoutFromOuterScope = async scope => {
388
+ let payload;
389
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
390
+ let waitPromiseResolve;
391
+ const waitPromise = new Promise((res, rej) => {
392
+ waitPromiseResolve = res;
393
+ setTimeout(() => rej("Failed to find method in outer scope"), 5000);
394
+ }).catch(rej => console.warn(rej));
395
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
396
+ const getInitContextParamsFromParent = e => {
397
+ if (e.data && e.data.messageName == _Constants.Constants.InitContextParamsResponse) {
398
+ payload = e.data.payload;
399
+ waitPromiseResolve();
400
+ }
401
+ };
402
+ window.addEventListener("message", getInitContextParamsFromParent, false);
403
+ scope.postMessage({
404
+ messageName: _Constants.Constants.InitContextParamsResponse
405
+ }, "*");
406
+ await waitPromise;
407
+ window.removeEventListener("message", getInitContextParamsFromParent, false);
408
+ return payload;
409
+ };
@@ -105,6 +105,9 @@ _defineProperty(Constants, "SessionCacheSuffix", "session");
105
105
  _defineProperty(Constants, "PopoutCacheSuffix", "popout");
106
106
  // Visibility timeout for conversation details
107
107
  _defineProperty(Constants, "LWICheckOnVisibilityTimeout", 3 * 60 * 1000);
108
+ // 3 minute
109
+ // Popup mode custom context response event message name
110
+ _defineProperty(Constants, "InitContextParamsResponse", "initContextParamsResponse");
108
111
  export const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
109
112
  export class HtmlIdNames {}
110
113
  _defineProperty(HtmlIdNames, "MSLiveChatWidget", "MSLiveChatWidget");
@@ -1,5 +1,5 @@
1
1
  import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
- import { ChatSDKError, LiveWorkItemState } from "../../../common/Constants";
2
+ import { ChatSDKError, Constants, LiveWorkItemState } from "../../../common/Constants";
3
3
  import { createTimer, getStateFromCache, getWidgetCacheIdfromProps, isNullOrEmptyString, isUndefinedOrEmpty } from "../../../common/utils";
4
4
  import { getAuthClientFunction, handleAuthentication } from "./authHelper";
5
5
  import { ActivityStreamHandler } from "./ActivityStreamHandler";
@@ -123,7 +123,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
123
123
  try {
124
124
  var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
125
125
  // Set custom context params
126
- setCustomContextParams(props);
126
+ await setCustomContextParams(props);
127
127
  const defaultOptionalParams = {
128
128
  sendDefaultInitContext: true,
129
129
  isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
@@ -278,7 +278,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
278
278
  };
279
279
 
280
280
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
281
- const setCustomContextParams = props => {
281
+ const setCustomContextParams = async props => {
282
282
  var _props$chatConfig, _props$chatConfig$Liv, _persistedState$domai8;
283
283
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
284
284
  const isAuthenticatedChat = props !== null && props !== void 0 && (_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 ? true : false;
@@ -295,11 +295,18 @@ const setCustomContextParams = props => {
295
295
  var _persistedState$domai9;
296
296
  TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
297
297
  Event: TelemetryEvent.SetCustomContext,
298
- Description: "Setting custom context for unauthenicated chat"
298
+ Description: "Setting custom context for unauthenticated chat"
299
299
  });
300
300
  optionalParams = Object.assign({}, optionalParams, {
301
301
  customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
302
302
  });
303
+ } else {
304
+ const customContextFromParent = await getInitContextParamsForPopout();
305
+ if (!isUndefinedOrEmpty(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
306
+ optionalParams = Object.assign({}, optionalParams, {
307
+ customContext: customContextFromParent.contextVariables
308
+ });
309
+ }
303
310
  }
304
311
  };
305
312
  const canStartPopoutChat = async props => {
@@ -361,4 +368,34 @@ const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
361
368
  return false;
362
369
  }
363
370
  };
371
+
372
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
373
+ const getInitContextParamsForPopout = async () => {
374
+ return window.opener ? await getInitContextParamForPopoutFromOuterScope(window.opener) : null;
375
+ };
376
+
377
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
378
+ const getInitContextParamForPopoutFromOuterScope = async scope => {
379
+ let payload;
380
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
381
+ let waitPromiseResolve;
382
+ const waitPromise = new Promise((res, rej) => {
383
+ waitPromiseResolve = res;
384
+ setTimeout(() => rej("Failed to find method in outer scope"), 5000);
385
+ }).catch(rej => console.warn(rej));
386
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
387
+ const getInitContextParamsFromParent = e => {
388
+ if (e.data && e.data.messageName == Constants.InitContextParamsResponse) {
389
+ payload = e.data.payload;
390
+ waitPromiseResolve();
391
+ }
392
+ };
393
+ window.addEventListener("message", getInitContextParamsFromParent, false);
394
+ scope.postMessage({
395
+ messageName: Constants.InitContextParamsResponse
396
+ }, "*");
397
+ await waitPromise;
398
+ window.removeEventListener("message", getInitContextParamsFromParent, false);
399
+ return payload;
400
+ };
364
401
  export { prepareStartChat, initStartChat, setPreChatAndInitiateChat, checkIfConversationStillValid };
@@ -84,6 +84,7 @@ export declare class Constants {
84
84
  static readonly SessionCacheSuffix = "session";
85
85
  static readonly PopoutCacheSuffix = "popout";
86
86
  static readonly LWICheckOnVisibilityTimeout: number;
87
+ static readonly InitContextParamsResponse = "initContextParamsResponse";
87
88
  }
88
89
  export declare const Regex: {
89
90
  new (): {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.0.3",
3
+ "version": "1.0.4-main.5c98fd0",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -111,4 +111,4 @@
111
111
  "**/abort-controller-es5": "^2.0.1",
112
112
  "**/minimist": "1.2.6"
113
113
  }
114
- }
114
+ }