@epam/ai-dial-overlay 0.11.0-rc.8 → 0.11.0

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/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { overlayAppName, OverlayEvents, OverlayRequests } from '@epam/ai-dial-shared';
1
+ import { overlayAppName, OverlayEvents, Task, setStyles, overlayLibName, DeferredRequest, OverlayRequests } from '@epam/ai-dial-shared';
2
2
  export { Feature } from '@epam/ai-dial-shared';
3
3
 
4
4
  /******************************************************************************
@@ -31,93 +31,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
31
31
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
32
  };
33
33
 
34
- const defaultRequestTimeout = 10000;
35
- class DeferredRequest {
36
- constructor(type, params) {
37
- this.type = type;
38
- this.params = params;
39
- this.requestId = DeferredRequest.generateRequestId();
40
- this._isReplied = false;
41
- this.promise = Promise.race([
42
- new Promise((resolve) => {
43
- this.resolve = resolve;
44
- }),
45
- new Promise((_, reject) => {
46
- var _a;
47
- setTimeout(() => {
48
- var _a;
49
- reject(`[ChatOverlay] Request ${type} failed. Timeout ${((_a = this.params) === null || _a === void 0 ? void 0 : _a.timeout) || defaultRequestTimeout}`);
50
- }, ((_a = this.params) === null || _a === void 0 ? void 0 : _a.timeout) || defaultRequestTimeout);
51
- }),
52
- ]);
53
- }
54
- match(type, requestId) {
55
- return this.type + '/RESPONSE' === type && this.requestId === requestId;
56
- }
57
- reply(payload) {
58
- if (this.isReplied)
59
- return;
60
- this._isReplied = true;
61
- this.resolve(payload);
62
- }
63
- toPostMessage() {
64
- var _a;
65
- return {
66
- type: this.type,
67
- payload: (_a = this.params) === null || _a === void 0 ? void 0 : _a.payload,
68
- requestId: this.requestId,
69
- };
70
- }
71
- get isReplied() {
72
- return this._isReplied;
73
- }
74
- static generateRequestId() {
75
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
76
- const r = (Math.random() * 16) | 0;
77
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
78
- return v.toString(16);
79
- });
80
- }
81
- }
82
-
83
- class Task {
84
- constructor() {
85
- this.isResolved = false;
86
- this.promise = new Promise((resolve, reject) => {
87
- this.resolve = resolve;
88
- this.reject = reject;
89
- });
90
- }
91
- complete() {
92
- if (this.isResolved)
93
- return;
94
- this.isResolved = true;
95
- this.resolve(true);
96
- }
97
- fail(reason = 'Task failed') {
98
- if (this.isResolved)
99
- return;
100
- this.reject(reason);
101
- }
102
- ready() {
103
- return this.promise;
104
- }
105
- }
106
-
107
- /**
108
- * Add styles to the html element
109
- * @param htmlElement {HTMLElement} element for which styles should be added
110
- * @param styles {Styles} styles that should be added to element
111
- */
112
- function setStyles(htmlElement, styles) {
113
- for (const key in styles) {
114
- const value = styles[key];
115
- if (!value)
116
- continue;
117
- htmlElement.style[key] = value;
118
- }
119
- }
120
-
121
34
  const defaultLoaderSVG = `<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
122
35
  <path d="M24 39V46.5" stroke="#7F8792" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
123
36
  <path opacity="0.4" d="M9 24H1.5" stroke="#7F8792" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
@@ -260,7 +173,7 @@ class ChatOverlay {
260
173
  if (typeof root === 'string') {
261
174
  const element = document.querySelector(root);
262
175
  if (!element) {
263
- throw new Error(`[ChatOverlay] There is no element with selector ${root} to append iframe`);
176
+ throw new Error(`[${overlayLibName}] There is no element with selector ${root} to append iframe`);
264
177
  }
265
178
  return element;
266
179
  }
@@ -277,7 +190,7 @@ class ChatOverlay {
277
190
  */
278
191
  openFullscreen() {
279
192
  if (!this.iframe.requestFullscreen) {
280
- throw new Error('[ChatOverlay] Fullscreen is not allowed. Allow it first');
193
+ throw new Error(`[${overlayLibName}] Fullscreen is not allowed. Allow it first`);
281
194
  }
282
195
  this.iframe.requestFullscreen();
283
196
  }
@@ -308,12 +221,12 @@ class ChatOverlay {
308
221
  yield this.iframeInteraction.ready();
309
222
  }
310
223
  if (!this.iframe.contentWindow) {
311
- throw new Error('[ChatOverlay] There is no content window to send requests');
224
+ throw new Error(`[${overlayLibName}] There is no content window to send requests`);
312
225
  }
313
226
  const request = new DeferredRequest(`${overlayAppName}/${type}`, {
314
227
  payload,
315
228
  timeout: (_a = this.options) === null || _a === void 0 ? void 0 : _a.requestTimeout,
316
- });
229
+ }, overlayLibName);
317
230
  this.requests.push(request);
318
231
  this.iframe.contentWindow.postMessage(request.toPostMessage(), '*');
319
232
  return request.promise;
@@ -378,6 +291,7 @@ class ChatOverlay {
378
291
  window.removeEventListener('message', this.process);
379
292
  this.iframeInteraction.fail('Chat Overlay destroyed');
380
293
  this.root.removeChild(this.iframe);
294
+ this.root.removeChild(this.loader);
381
295
  }
382
296
  }
383
297
 
package/package.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@epam/ai-dial-overlay",
3
3
  "description": "Package for opening dial in overlay",
4
4
  "homepage": "https://epam-rail.com",
5
- "version": "0.11.0-rc.8",
5
+ "version": "0.11.0",
6
6
  "dependencies": {
7
- "@epam/ai-dial-shared": "0.11.0-rc.8"
7
+ "@epam/ai-dial-shared": "0.11.0"
8
8
  },
9
9
  "type": "module",
10
10
  "bugs": {
@@ -1,6 +1,4 @@
1
- import { DeferredRequest } from './utils/DeferredRequest';
2
- import { Task } from './utils/Task';
3
- import { ChatOverlayOptions, OverlayRequest, OverlayRequests, Styles } from '@epam/ai-dial-shared';
1
+ import { ChatOverlayOptions, DeferredRequest, OverlayRequest, OverlayRequests, Styles, Task } from '@epam/ai-dial-shared';
4
2
  interface Subscription {
5
3
  eventType: string;
6
4
  callback: (payload: unknown) => void;
@@ -1,20 +0,0 @@
1
- import { OverlayRequest } from '@epam/ai-dial-shared';
2
- interface RequestParams {
3
- payload: unknown;
4
- timeout?: number;
5
- }
6
- export declare class DeferredRequest {
7
- promise: Promise<unknown>;
8
- private type;
9
- private requestId;
10
- private _isReplied;
11
- private resolve;
12
- private params;
13
- constructor(type: string, params: RequestParams);
14
- match(type: string, requestId: string): boolean;
15
- reply(payload: unknown): void;
16
- toPostMessage(): OverlayRequest;
17
- get isReplied(): boolean;
18
- private static generateRequestId;
19
- }
20
- export {};
@@ -1,10 +0,0 @@
1
- export declare class Task {
2
- protected promise: Promise<boolean>;
3
- protected resolve: (value: boolean) => void;
4
- protected reject: (reason: string) => void;
5
- protected isResolved: boolean;
6
- constructor();
7
- complete(): void;
8
- fail(reason?: string): void;
9
- ready(): Promise<boolean>;
10
- }
@@ -1,7 +0,0 @@
1
- import { Styles } from '@epam/ai-dial-shared';
2
- /**
3
- * Add styles to the html element
4
- * @param htmlElement {HTMLElement} element for which styles should be added
5
- * @param styles {Styles} styles that should be added to element
6
- */
7
- export declare function setStyles(htmlElement: HTMLElement, styles: Styles): void;