@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.4 → 0.0.1-alpha.42

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.
Files changed (73) hide show
  1. package/lib/client/chat.client.d.ts +3 -2
  2. package/lib/client/chat.client.js +98 -33
  3. package/lib/client/contact-method.client.d.ts +9 -1
  4. package/lib/client/contact-method.client.js +48 -32
  5. package/lib/client/http.client.d.ts +11 -7
  6. package/lib/client/http.client.js +138 -41
  7. package/lib/client/middleware.client.d.ts +4 -3
  8. package/lib/client/middleware.client.js +100 -35
  9. package/lib/contract/custom-component/contact-method-item.d.ts +1 -0
  10. package/lib/contract/custom-component/contact-method-item.js +10 -64
  11. package/lib/contract/custom-component/contact-method-list.js +6 -34
  12. package/lib/contract/custom-component/contact-method.js +12 -17
  13. package/lib/contract/enum/server-entry-type.enum.d.ts +3 -2
  14. package/lib/contract/enum/server-entry-type.enum.js +5 -7
  15. package/lib/contract/model/conversation-api-model/list.model.js +1 -2
  16. package/lib/contract/model/conversation-api-model/message.model.js +1 -2
  17. package/lib/contract/model/http/action.model.js +1 -2
  18. package/lib/contract/model/http/client-action.model.js +1 -2
  19. package/lib/contract/model/http/client-envelope.model.js +1 -2
  20. package/lib/contract/model/http/connect-options.model.js +1 -2
  21. package/lib/contract/model/http/global-state.model.js +1 -2
  22. package/lib/contract/model/http/http-client-options.model.js +1 -2
  23. package/lib/contract/model/http/server-entry.model.js +1 -2
  24. package/lib/contract/model/http/server-envelope.model.js +1 -2
  25. package/lib/contract/model/middleware/aggregator-state.model.js +1 -2
  26. package/lib/contract/model/shared/loose-object.model.js +1 -2
  27. package/lib/helper/chat.helper.js +1 -4
  28. package/lib/helper/http.helper.d.ts +1 -1
  29. package/lib/helper/http.helper.js +8 -13
  30. package/lib/helper/middleware.helper.d.ts +1 -1
  31. package/lib/helper/middleware.helper.js +7 -11
  32. package/lib/helper/store.helper.d.ts +4 -3
  33. package/lib/helper/store.helper.js +105 -16
  34. package/lib/index.js +2 -8
  35. package/lib/interface/entry.interface.d.ts +6 -3
  36. package/lib/interface/entry.interface.js +207 -63
  37. package/lib/interface/middleware/paging.interface.js +3 -5
  38. package/lib/interface/middleware/processor.interface.js +2 -4
  39. package/lib/plugin.d.ts +2 -2
  40. package/lib/plugin.js +73 -90
  41. package/lib/utils.d.ts +2 -0
  42. package/lib/utils.js +79 -0
  43. package/lib-esm/client/chat.client.d.ts +3 -2
  44. package/lib-esm/client/chat.client.js +81 -11
  45. package/lib-esm/client/contact-method.client.d.ts +9 -1
  46. package/lib-esm/client/contact-method.client.js +28 -6
  47. package/lib-esm/client/http.client.d.ts +11 -7
  48. package/lib-esm/client/http.client.js +125 -22
  49. package/lib-esm/client/middleware.client.d.ts +4 -3
  50. package/lib-esm/client/middleware.client.js +89 -19
  51. package/lib-esm/contract/custom-component/contact-method-item.d.ts +1 -0
  52. package/lib-esm/contract/custom-component/contact-method-item.js +7 -36
  53. package/lib-esm/contract/custom-component/contact-method-list.js +1 -1
  54. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +3 -2
  55. package/lib-esm/contract/enum/server-entry-type.enum.js +3 -2
  56. package/lib-esm/helper/http.helper.d.ts +1 -1
  57. package/lib-esm/helper/http.helper.js +7 -9
  58. package/lib-esm/helper/middleware.helper.d.ts +1 -1
  59. package/lib-esm/helper/middleware.helper.js +5 -6
  60. package/lib-esm/helper/store.helper.d.ts +4 -3
  61. package/lib-esm/helper/store.helper.js +103 -11
  62. package/lib-esm/interface/entry.interface.d.ts +6 -3
  63. package/lib-esm/interface/entry.interface.js +191 -45
  64. package/lib-esm/interface/middleware/processor.interface.js +1 -1
  65. package/lib-esm/plugin.d.ts +2 -2
  66. package/lib-esm/plugin.js +66 -55
  67. package/lib-esm/utils.d.ts +2 -0
  68. package/lib-esm/utils.js +79 -0
  69. package/package.json +45 -45
  70. package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
  71. package/lib/interface/middleware/contact-expanded.interface.js +0 -50
  72. package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
  73. package/lib/interface/middleware/legacy-contact-methods.interface.js +0 -394
@@ -1,40 +1,110 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { createStorageWriter, StorageCategory } from '@telia-ace/widget-services';
38
+ import { ChatHelper } from '../helper/chat.helper';
1
39
  import { MiddlewareHelper } from '../helper/middleware.helper';
2
40
  import { StoreHelper } from '../helper/store.helper';
3
41
  import EntryInterface from '../interface/entry.interface';
4
- // import ContactExpandedInterface from "../interface/middleware/contact-expanded.interface";
5
- // import ContactInterface from "../interface/middleware/legacy-contact-methods.interface";
6
42
  import PagingInterface from '../interface/middleware/paging.interface';
7
43
  import ProcessorInterface from '../interface/middleware/processor.interface';
8
44
  import ChatClient from './chat.client';
9
- import { HttpClient } from './http.client';
10
45
  var MiddlewareClient = /** @class */ (function () {
11
- function MiddlewareClient() {
12
- // this.contactExpanded = new ContactExpandedInterface();
13
- // this.legacyContact = new ContactInterface();
46
+ function MiddlewareClient(container) {
14
47
  this.paging = new PagingInterface();
15
48
  this.processor = new ProcessorInterface();
16
- this.entryInterface = new EntryInterface();
17
- this.chatClient = new ChatClient();
49
+ this.entryInterface = new EntryInterface(container);
50
+ this.chatClient = new ChatClient(container);
18
51
  }
19
52
  MiddlewareClient.initialize = function (container, widget) {
20
53
  MiddlewareHelper.setContainer(container);
21
54
  MiddlewareHelper.setWidget(widget);
22
55
  };
23
- // called on all standart scenarios like actions and user messages
56
+ // called on all standard scenarios like actions and user messages
24
57
  MiddlewareClient.prototype.handleEntries = function (entries, action) {
25
- var o = this.executeMiddlewares(entries, false, action);
26
- var messageArray = this.entryInterface.transformArray(o);
27
- this.chatClient.processMessageArrayAndStoreIt(messageArray);
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var widgetEntry, agent, write, o, messageArray;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ widgetEntry = (entries || []).find(function (e) { return e.type === 'Widget'; });
64
+ if (!widgetEntry) return [3 /*break*/, 2];
65
+ agent = ChatHelper.getAgent();
66
+ if (!agent) return [3 /*break*/, 2];
67
+ agent.update({
68
+ name: widgetEntry.content.agent.name,
69
+ avatar: widgetEntry.content.agent.avatar,
70
+ });
71
+ return [4 /*yield*/, createStorageWriter(MiddlewareHelper.getContainer(), 'bot-provider-conversation-meta', StorageCategory.Necessary)];
72
+ case 1:
73
+ write = _a.sent();
74
+ write({
75
+ agent: {
76
+ name: widgetEntry.content.agent.name,
77
+ avatar: widgetEntry.content.agent.avatar,
78
+ },
79
+ });
80
+ _a.label = 2;
81
+ case 2:
82
+ o = this.executeMiddlewares(entries, false, action);
83
+ return [4 /*yield*/, this.entryInterface.transformArray(o)];
84
+ case 3:
85
+ messageArray = _a.sent();
86
+ this.chatClient.processMessageArrayAndStoreIt(messageArray);
87
+ return [2 /*return*/];
88
+ }
89
+ });
90
+ });
28
91
  };
29
92
  // called on situations such as paging changes
30
93
  // when no new entries will be printed
31
- MiddlewareClient.prototype.handleUpdate = function (input, endpoint) {
32
- var _this = this;
33
- var httpClient = new HttpClient(endpoint);
34
- httpClient.handleUpdate(input).then(function (entries) {
35
- var o = _this.executeMiddlewares(entries, true, input);
36
- var messageArray = _this.entryInterface.transformArray(o);
37
- _this.chatClient.updateMessageArrayAndStoreIt(messageArray);
94
+ MiddlewareClient.prototype.handleUpdate = function (entries, action) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var o, messageArray;
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0:
100
+ o = this.executeMiddlewares(entries, true, action);
101
+ return [4 /*yield*/, this.entryInterface.transformArray(o)];
102
+ case 1:
103
+ messageArray = _a.sent();
104
+ this.chatClient.updateMessageArrayAndStoreIt(messageArray);
105
+ return [2 /*return*/];
106
+ }
107
+ });
38
108
  });
39
109
  };
40
110
  // checks whether the action was of an update type
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  interface PropsType {
3
3
  contactMethod: any;
4
4
  type: any;
5
+ expanded?: boolean;
5
6
  className?: any;
6
7
  }
7
8
  declare const ContactMethodItem: React.FC<PropsType>;
@@ -9,43 +9,14 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var __read = (this && this.__read) || function (o, n) {
13
- var m = typeof Symbol === "function" && o[Symbol.iterator];
14
- if (!m) return o;
15
- var i = m.call(o), r, ar = [], e;
16
- try {
17
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
- }
19
- catch (error) { e = { error: error }; }
20
- finally {
21
- try {
22
- if (r && !r.done && (m = i["return"])) m.call(i);
23
- }
24
- finally { if (e) throw e.error; }
25
- }
26
- return ar;
27
- };
28
12
  import { ContactMethod as GenericContactMethod } from '@telia-ace/knowledge-widget-adapters';
29
- import { useContainer, useDispatch } from '@telia-ace/widget-ui';
30
- import React, { useEffect, useState } from 'react';
31
- var ContactMethodItem = function (props) {
13
+ import { useDispatch } from '@telia-ace/knowledge-widget-ui';
14
+ import React from 'react';
15
+ var ContactMethodItem = function (_a) {
16
+ var contactMethod = _a.contactMethod, className = _a.className;
32
17
  var dispatch = useDispatch();
33
- var container = useContainer();
34
- var _a = __read(useState(props.contactMethod.body), 2), body = _a[0], setBody = _a[1];
35
- useEffect(function () {
36
- var events = container.get('$widget').events;
37
- events.subscribe('form:validated', function (_event, _data) {
38
- // TODO: this is a due to props not being updated when props.contactMethod.body changes
39
- // perhaps there is a cleaner way of doing this
40
- setBody(props.contactMethod.body);
41
- });
42
- }, [container]);
43
- return (React.createElement(GenericContactMethod, __assign({ className: props.className, onClick: function () {
44
- dispatch('action', "".concat(props.contactMethod.id, "/").concat(props.type.toString(), "/").concat(props.contactMethod.title));
45
- // dispatch(
46
- // "expand",
47
- // `${props.contactMethod.id}/${props.type.toString()}`
48
- // );
49
- }, dispatch: dispatch }, props.contactMethod, { body: body, expanded: props.contactMethod.expanded })));
18
+ return (React.createElement(GenericContactMethod, __assign({ className: className, onClick: function () {
19
+ dispatch('action', "".concat(contactMethod.id, "/contact-methods/").concat(contactMethod.title));
20
+ }, dispatch: dispatch }, contactMethod)));
50
21
  };
51
22
  export default ContactMethodItem;
@@ -6,7 +6,7 @@ import React, { Fragment } from 'react';
6
6
  import styled from 'styled-components';
7
7
  import ContactMethodItem from './contact-method-item';
8
8
  var ContactMethodList = function (props) {
9
- return (React.createElement(Fragment, null, props.contactMethodList.map(function (contactMethod) { return (React.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod })); })));
9
+ return (React.createElement(Fragment, null, props.contactMethodList.map(function (contactMethod) { return (React.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod, expanded: !!contactMethod.executeImmediately || undefined })); })));
10
10
  };
11
11
  var StyledContactMethod = styled(ContactMethodItem)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n"], ["\n border-bottom: 1px solid rgb(239, 239, 239);\n padding: ", ";\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
12
12
  export default ContactMethodList;
@@ -1,6 +1,7 @@
1
1
  export declare enum ServerEntryTypeEnum {
2
2
  Widget = 0,
3
3
  Text = 1,
4
- List = 2,
5
- Error = 3
4
+ Contact = 2,
5
+ List = 3,
6
+ Error = 4
6
7
  }
@@ -2,6 +2,7 @@ export var ServerEntryTypeEnum;
2
2
  (function (ServerEntryTypeEnum) {
3
3
  ServerEntryTypeEnum[ServerEntryTypeEnum["Widget"] = 0] = "Widget";
4
4
  ServerEntryTypeEnum[ServerEntryTypeEnum["Text"] = 1] = "Text";
5
- ServerEntryTypeEnum[ServerEntryTypeEnum["List"] = 2] = "List";
6
- ServerEntryTypeEnum[ServerEntryTypeEnum["Error"] = 3] = "Error";
5
+ ServerEntryTypeEnum[ServerEntryTypeEnum["Contact"] = 2] = "Contact";
6
+ ServerEntryTypeEnum[ServerEntryTypeEnum["List"] = 3] = "List";
7
+ ServerEntryTypeEnum[ServerEntryTypeEnum["Error"] = 4] = "Error";
7
8
  })(ServerEntryTypeEnum || (ServerEntryTypeEnum = {}));
@@ -3,7 +3,7 @@ export declare class HttpHelper {
3
3
  method: string;
4
4
  headers: {
5
5
  Accept: string;
6
- "Content-Type": string;
6
+ 'Content-Type': string;
7
7
  };
8
8
  };
9
9
  static combineUrl(basePath: string, path: string): string;
@@ -5,22 +5,20 @@ var HttpHelper = /** @class */ (function () {
5
5
  return basePath + path;
6
6
  };
7
7
  HttpHelper.getCredentials = function () {
8
- return "same-origin";
8
+ return 'same-origin';
9
9
  };
10
- var _a;
11
- _a = HttpHelper;
12
10
  HttpHelper.fetchOptions = {
13
- method: "POST",
11
+ method: 'POST',
14
12
  headers: {
15
- Accept: "application/json",
16
- "Content-Type": "application/json",
13
+ Accept: 'application/json',
14
+ 'Content-Type': 'application/json',
17
15
  },
18
16
  };
19
- HttpHelper.managedSubdomainSuffixes = ["stage", "alpha", "beta", "gamma"];
17
+ HttpHelper.managedSubdomainSuffixes = ['stage', 'alpha', 'beta', 'gamma'];
20
18
  HttpHelper.parseSubdomain = function (input) {
21
- var index = input.lastIndexOf("-");
19
+ var index = input.lastIndexOf('-');
22
20
  var lastPart = input.substr(index + 1);
23
- if (_a.managedSubdomainSuffixes.indexOf(lastPart) > -1) {
21
+ if (HttpHelper.managedSubdomainSuffixes.indexOf(lastPart) > -1) {
24
22
  return input.substr(0, index);
25
23
  }
26
24
  return input;
@@ -1,4 +1,4 @@
1
- import { Message } from "../contract/model/conversation-api-model/message.model";
1
+ import { Message } from '../contract/model/conversation-api-model/message.model';
2
2
  export declare class MiddlewareHelper {
3
3
  private static sessionMessageStorageVariable;
4
4
  private static container;
@@ -34,12 +34,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import { createStorageWriter, readStorage, StorageCategory } from "@telia-ace/widget-services";
37
+ import { createStorageWriter, readStorage, StorageCategory } from '@telia-ace/widget-services';
38
38
  var MiddlewareHelper = /** @class */ (function () {
39
39
  function MiddlewareHelper() {
40
40
  }
41
41
  MiddlewareHelper.setContainer = function (container) {
42
- this.container = container;
42
+ MiddlewareHelper.container = container;
43
43
  };
44
44
  MiddlewareHelper.setWidget = function (widget) {
45
45
  this.widget = widget;
@@ -58,10 +58,9 @@ var MiddlewareHelper = /** @class */ (function () {
58
58
  MiddlewareHelper.sessionMessageStorageVariable = 'conversation-plugin-messages';
59
59
  MiddlewareHelper.setEntrySessionStorage = function (messages) { return __awaiter(void 0, void 0, void 0, function () {
60
60
  return __generator(_a, function (_b) {
61
- createStorageWriter(this.container, this.sessionMessageStorageVariable, StorageCategory.Necessary).then(function (write) {
62
- return write(messages);
63
- });
64
- return [2 /*return*/];
61
+ return [2 /*return*/, createStorageWriter(MiddlewareHelper.container, MiddlewareHelper.sessionMessageStorageVariable, StorageCategory.Necessary).then(function (write) {
62
+ return write(messages);
63
+ })];
65
64
  });
66
65
  }); };
67
66
  return MiddlewareHelper;
@@ -7,16 +7,17 @@ export declare class StoreHelper {
7
7
  private static messageStore;
8
8
  private static globalState;
9
9
  constructor();
10
- static insertOrUpdateMessageArrayStore(messageArray: Message[], entry?: any): void;
11
- private static insertMessageToStore;
10
+ static insertOrUpdateMessageArrayStore(messageArray: Message[], entry?: any): Promise<void>;
11
+ static insertMessageToStore(message: Message): void;
12
12
  private static updateMessageInStore;
13
13
  static checkIdInMessageStore(id: string): boolean;
14
14
  static getLocalState(action: string): LooseObject | undefined;
15
15
  static getGlobalState(): GlobalState;
16
- static setGlobalState(state: GlobalState): void;
16
+ static setGlobalState(state: GlobalState): Promise<void>;
17
17
  static getAction(action: string): ClientAction;
18
18
  static getCommand(text: string): LooseObject;
19
19
  static getEntry(action: string): ServerEntry | undefined;
20
20
  static getMessage(id: string): Message | undefined;
21
21
  static getEntryStore(): ServerEntry[];
22
+ static rehydrateState(): Promise<void>;
22
23
  }
@@ -1,25 +1,98 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __values = (this && this.__values) || function(o) {
38
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
+ if (m) return m.call(o);
40
+ if (o && typeof o.length === "number") return {
41
+ next: function () {
42
+ if (o && i >= o.length) o = void 0;
43
+ return { value: o && o[i++], done: !o };
44
+ }
45
+ };
46
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
+ };
48
+ import { createStorageWriter, readStorage, StorageCategory } from '@telia-ace/widget-services';
1
49
  import { MiddlewareHelper } from './middleware.helper';
50
+ var botProviderGlobalStateSessionKey = 'bot-provider-global-state';
2
51
  var StoreHelper = /** @class */ (function () {
3
52
  function StoreHelper() {
4
53
  StoreHelper.globalState = {
5
54
  completedInteractionsCount: 0,
6
55
  lastBotGuide: 0,
7
- site: 'https://localhost:8080/',
56
+ site: '',
8
57
  invincibleParameters: {},
9
58
  };
10
59
  }
11
60
  StoreHelper.insertOrUpdateMessageArrayStore = function (messageArray, entry) {
12
- var _this = this;
13
- messageArray
14
- .filter(function (o) { return !!o; })
15
- .forEach(function (t) {
16
- if (!_this.messageStore.find(function (o) { return o.id == t.id; }))
17
- _this.insertMessageToStore(t);
18
- else {
19
- _this.updateMessageInStore(t, entry);
20
- }
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var _loop_1, this_1, _a, _b, message;
63
+ var e_1, _c;
64
+ return __generator(this, function (_d) {
65
+ switch (_d.label) {
66
+ case 0:
67
+ _loop_1 = function (message) {
68
+ if (!this_1.messageStore.find(function (o) { return o.id == message.id; })) {
69
+ this_1.insertMessageToStore(message);
70
+ }
71
+ else {
72
+ this_1.updateMessageInStore(message, entry);
73
+ }
74
+ };
75
+ this_1 = this;
76
+ try {
77
+ for (_a = __values(messageArray.filter(function (o) { return !!o; })), _b = _a.next(); !_b.done; _b = _a.next()) {
78
+ message = _b.value;
79
+ _loop_1(message);
80
+ }
81
+ }
82
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
83
+ finally {
84
+ try {
85
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
86
+ }
87
+ finally { if (e_1) throw e_1.error; }
88
+ }
89
+ return [4 /*yield*/, MiddlewareHelper.setEntrySessionStorage(this.messageStore)];
90
+ case 1:
91
+ _d.sent();
92
+ return [2 /*return*/];
93
+ }
94
+ });
21
95
  });
22
- MiddlewareHelper.setEntrySessionStorage(this.messageStore);
23
96
  };
24
97
  StoreHelper.insertMessageToStore = function (message) {
25
98
  this.messageStore.push(message);
@@ -41,6 +114,9 @@ var StoreHelper = /** @class */ (function () {
41
114
  };
42
115
  StoreHelper.setGlobalState = function (state) {
43
116
  StoreHelper.globalState = state;
117
+ return createStorageWriter(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey, StorageCategory.Necessary).then(function (write) {
118
+ return write(state);
119
+ });
44
120
  };
45
121
  StoreHelper.getAction = function (action) {
46
122
  var entry = this.getEntry(action);
@@ -71,6 +147,22 @@ var StoreHelper = /** @class */ (function () {
71
147
  return o.entry;
72
148
  });
73
149
  };
150
+ StoreHelper.rehydrateState = function () {
151
+ return __awaiter(this, void 0, void 0, function () {
152
+ var state;
153
+ return __generator(this, function (_a) {
154
+ switch (_a.label) {
155
+ case 0: return [4 /*yield*/, readStorage(MiddlewareHelper.getContainer(), botProviderGlobalStateSessionKey)];
156
+ case 1:
157
+ state = _a.sent();
158
+ if (state) {
159
+ this.setGlobalState(state);
160
+ }
161
+ return [2 /*return*/];
162
+ }
163
+ });
164
+ });
165
+ };
74
166
  StoreHelper.messageStore = [];
75
167
  return StoreHelper;
76
168
  }());
@@ -1,11 +1,14 @@
1
+ import { Container } from '@webprovisions/platform';
1
2
  import { Message } from '../contract/model/conversation-api-model/message.model';
2
3
  import { ServerEntry } from '../contract/model/http/server-entry.model';
3
4
  export default class EntryInterface {
5
+ private container;
4
6
  private helpActionKey;
5
7
  private nextActionKey;
6
- constructor();
7
- transform(entry: ServerEntry): Message | undefined;
8
- transformArray(entryArray: ServerEntry[]): Message[];
8
+ constructor(container: Container);
9
+ transform(entry: ServerEntry, feedbackEntry?: ServerEntry): Promise<Message | undefined>;
10
+ transformContactMethod(entry: ServerEntry): Promise<any>;
11
+ transformArray(entryArray: ServerEntry[]): Promise<Message[]>;
9
12
  getUserMessage(action: string): string | undefined;
10
13
  private listTransform;
11
14
  private getContentText;