@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.3 → 0.0.1-alpha.32

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 (129) hide show
  1. package/LICENSE.txt +5 -5
  2. package/README.md +12 -12
  3. package/lib/client/chat.client.d.ts +16 -15
  4. package/lib/client/chat.client.js +79 -80
  5. package/lib/client/contact-method.client.d.ts +25 -22
  6. package/lib/client/contact-method.client.js +282 -276
  7. package/lib/client/http.client.d.ts +23 -22
  8. package/lib/client/http.client.js +160 -115
  9. package/lib/client/middleware.client.d.ts +14 -13
  10. package/lib/client/middleware.client.js +104 -60
  11. package/lib/contract/custom-component/contact-method-item.d.ts +8 -8
  12. package/lib/contract/custom-component/contact-method-item.js +54 -76
  13. package/lib/contract/custom-component/contact-method-list.d.ts +7 -7
  14. package/lib/contract/custom-component/contact-method-list.js +13 -41
  15. package/lib/contract/custom-component/contact-method.d.ts +3 -3
  16. package/lib/contract/custom-component/contact-method.js +34 -38
  17. package/lib/contract/enum/server-entry-type.enum.d.ts +7 -6
  18. package/lib/contract/enum/server-entry-type.enum.js +8 -10
  19. package/lib/contract/model/conversation-api-model/list.model.d.ts +5 -5
  20. package/lib/contract/model/conversation-api-model/list.model.js +0 -2
  21. package/lib/contract/model/conversation-api-model/message.model.d.ts +7 -7
  22. package/lib/contract/model/conversation-api-model/message.model.js +0 -2
  23. package/lib/contract/model/http/action.model.d.ts +3 -3
  24. package/lib/contract/model/http/action.model.js +0 -2
  25. package/lib/contract/model/http/client-action.model.d.ts +4 -4
  26. package/lib/contract/model/http/client-action.model.js +1 -3
  27. package/lib/contract/model/http/client-envelope.model.d.ts +9 -9
  28. package/lib/contract/model/http/client-envelope.model.js +0 -2
  29. package/lib/contract/model/http/connect-options.model.d.ts +5 -5
  30. package/lib/contract/model/http/connect-options.model.js +0 -2
  31. package/lib/contract/model/http/global-state.model.d.ts +8 -8
  32. package/lib/contract/model/http/global-state.model.js +0 -2
  33. package/lib/contract/model/http/http-client-options.model.d.ts +5 -5
  34. package/lib/contract/model/http/http-client-options.model.js +0 -2
  35. package/lib/contract/model/http/server-entry.model.d.ts +11 -11
  36. package/lib/contract/model/http/server-entry.model.js +0 -2
  37. package/lib/contract/model/http/server-envelope.model.d.ts +10 -10
  38. package/lib/contract/model/http/server-envelope.model.js +0 -2
  39. package/lib/contract/model/middleware/aggregator-state.model.d.ts +4 -4
  40. package/lib/contract/model/middleware/aggregator-state.model.js +1 -3
  41. package/lib/contract/model/shared/loose-object.model.d.ts +3 -3
  42. package/lib/contract/model/shared/loose-object.model.js +0 -2
  43. package/lib/helper/chat.helper.d.ts +8 -8
  44. package/lib/helper/chat.helper.js +18 -21
  45. package/lib/helper/http.helper.d.ts +13 -13
  46. package/lib/helper/http.helper.js +28 -33
  47. package/lib/helper/middleware.helper.d.ts +12 -12
  48. package/lib/helper/middleware.helper.js +67 -72
  49. package/lib/helper/store.helper.d.ts +22 -22
  50. package/lib/helper/store.helper.js +77 -80
  51. package/lib/index.d.ts +2 -2
  52. package/lib/index.js +2 -8
  53. package/lib/interface/_mocked-contact-method.json +375 -0
  54. package/lib/interface/convert.d.ts +1 -0
  55. package/lib/interface/convert.js +68 -0
  56. package/lib/interface/entry.interface.d.ts +20 -17
  57. package/lib/interface/entry.interface.js +262 -139
  58. package/lib/interface/middleware/paging.interface.d.ts +4 -4
  59. package/lib/interface/middleware/paging.interface.js +53 -55
  60. package/lib/interface/middleware/processor.interface.d.ts +10 -10
  61. package/lib/interface/middleware/processor.interface.js +118 -120
  62. package/lib/plugin.d.ts +3 -3
  63. package/lib/plugin.js +147 -169
  64. package/lib-esm/client/chat.client.d.ts +16 -15
  65. package/lib-esm/client/chat.client.js +79 -75
  66. package/lib-esm/client/contact-method.client.d.ts +25 -22
  67. package/lib-esm/client/contact-method.client.js +282 -270
  68. package/lib-esm/client/http.client.d.ts +23 -22
  69. package/lib-esm/client/http.client.js +160 -109
  70. package/lib-esm/client/middleware.client.d.ts +14 -13
  71. package/lib-esm/client/middleware.client.js +104 -55
  72. package/lib-esm/contract/custom-component/contact-method-item.d.ts +8 -8
  73. package/lib-esm/contract/custom-component/contact-method-item.js +54 -51
  74. package/lib-esm/contract/custom-component/contact-method-list.d.ts +7 -7
  75. package/lib-esm/contract/custom-component/contact-method-list.js +13 -13
  76. package/lib-esm/contract/custom-component/contact-method.d.ts +3 -3
  77. package/lib-esm/contract/custom-component/contact-method.js +34 -33
  78. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +7 -6
  79. package/lib-esm/contract/enum/server-entry-type.enum.js +8 -7
  80. package/lib-esm/contract/model/conversation-api-model/list.model.d.ts +5 -5
  81. package/lib-esm/contract/model/conversation-api-model/list.model.js +0 -1
  82. package/lib-esm/contract/model/conversation-api-model/message.model.d.ts +7 -7
  83. package/lib-esm/contract/model/conversation-api-model/message.model.js +0 -1
  84. package/lib-esm/contract/model/http/action.model.d.ts +3 -3
  85. package/lib-esm/contract/model/http/action.model.js +0 -1
  86. package/lib-esm/contract/model/http/client-action.model.d.ts +4 -4
  87. package/lib-esm/contract/model/http/client-action.model.js +1 -2
  88. package/lib-esm/contract/model/http/client-envelope.model.d.ts +9 -9
  89. package/lib-esm/contract/model/http/client-envelope.model.js +0 -1
  90. package/lib-esm/contract/model/http/connect-options.model.d.ts +5 -5
  91. package/lib-esm/contract/model/http/connect-options.model.js +0 -1
  92. package/lib-esm/contract/model/http/global-state.model.d.ts +8 -8
  93. package/lib-esm/contract/model/http/global-state.model.js +0 -1
  94. package/lib-esm/contract/model/http/http-client-options.model.d.ts +5 -5
  95. package/lib-esm/contract/model/http/http-client-options.model.js +0 -1
  96. package/lib-esm/contract/model/http/server-entry.model.d.ts +11 -11
  97. package/lib-esm/contract/model/http/server-entry.model.js +0 -1
  98. package/lib-esm/contract/model/http/server-envelope.model.d.ts +10 -10
  99. package/lib-esm/contract/model/http/server-envelope.model.js +0 -1
  100. package/lib-esm/contract/model/middleware/aggregator-state.model.d.ts +4 -4
  101. package/lib-esm/contract/model/middleware/aggregator-state.model.js +1 -2
  102. package/lib-esm/contract/model/shared/loose-object.model.d.ts +3 -3
  103. package/lib-esm/contract/model/shared/loose-object.model.js +0 -1
  104. package/lib-esm/helper/chat.helper.d.ts +8 -8
  105. package/lib-esm/helper/chat.helper.js +18 -18
  106. package/lib-esm/helper/http.helper.d.ts +13 -13
  107. package/lib-esm/helper/http.helper.js +28 -30
  108. package/lib-esm/helper/middleware.helper.d.ts +12 -12
  109. package/lib-esm/helper/middleware.helper.js +67 -69
  110. package/lib-esm/helper/store.helper.d.ts +22 -22
  111. package/lib-esm/helper/store.helper.js +77 -77
  112. package/lib-esm/index.d.ts +2 -2
  113. package/lib-esm/index.js +2 -2
  114. package/lib-esm/interface/_mocked-contact-method.json +375 -0
  115. package/lib-esm/interface/convert.d.ts +1 -0
  116. package/lib-esm/interface/convert.js +68 -0
  117. package/lib-esm/interface/entry.interface.d.ts +20 -17
  118. package/lib-esm/interface/entry.interface.js +262 -137
  119. package/lib-esm/interface/middleware/paging.interface.d.ts +4 -4
  120. package/lib-esm/interface/middleware/paging.interface.js +53 -53
  121. package/lib-esm/interface/middleware/processor.interface.d.ts +10 -10
  122. package/lib-esm/interface/middleware/processor.interface.js +118 -118
  123. package/lib-esm/plugin.d.ts +3 -3
  124. package/lib-esm/plugin.js +147 -141
  125. package/package.json +54 -45
  126. package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
  127. package/lib/interface/middleware/contact-expanded.interface.js +0 -50
  128. package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
  129. package/lib/interface/middleware/legacy-contact-methods.interface.js +0 -394
@@ -1,109 +1,160 @@
1
- import { HttpHelper } from '../helper/http.helper';
2
- import { MiddlewareHelper } from '../helper/middleware.helper';
3
- import { StoreHelper } from '../helper/store.helper';
4
- import ChatClient from './chat.client';
5
- import MiddlewareClient from './middleware.client';
6
- var HttpClient = /** @class */ (function () {
7
- function HttpClient(endpoint) {
8
- this.options = {
9
- credentials: HttpHelper.getCredentials(),
10
- clientId: '84d96a63-b8ba-33ec-22d5-515255f866f8',
11
- };
12
- console.log(endpoint);
13
- this.apiEndpoint = endpoint;
14
- this.projectionPath = window.location.href;
15
- this.endpointUrl = HttpHelper.combineUrl(this.projectionPath, 'conversations');
16
- this.clientId = this.options.clientId;
17
- this.middlewareClient = new MiddlewareClient();
18
- this.chatClient = new ChatClient();
19
- }
20
- HttpClient.prototype.firstHit = function () {
21
- var _this = this;
22
- // On first hit if there are entries stored in the storage, use them
23
- // Otherwise start a new session
24
- MiddlewareHelper.getEntrySessionStorage().then(function (o) {
25
- if (o && o.length > 0)
26
- _this.chatClient.processMessageArrayAndStoreIt(o);
27
- else {
28
- var envelope = _this.constructFirstHitEnvelope();
29
- _this.postAndHandleTheData(envelope);
30
- }
31
- });
32
- };
33
- // for updates, such as paging changes
34
- HttpClient.prototype.handleUpdate = function (action) {
35
- var envelope = this.constructInputEnvelope(action);
36
- return this.postAndReturnTheData(envelope, action).then(function (o) {
37
- return o.entries;
38
- });
39
- };
40
- // for action clicks
41
- HttpClient.prototype.handleInput = function (action) {
42
- var envelope = this.constructInputEnvelope(action);
43
- this.postAndHandleTheData(envelope, action);
44
- };
45
- // for text entries by user
46
- HttpClient.prototype.handlePhrase = function (phrase) {
47
- var envelope = this.constructPhraseEnvelope(phrase);
48
- this.postAndHandleTheData(envelope);
49
- };
50
- HttpClient.prototype.postAndHandleTheData = function (envelope, action) {
51
- var _this = this;
52
- return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
53
- .then(function (response) {
54
- if (response.ok)
55
- return response.json();
56
- throw response;
57
- })
58
- .then(function (data) {
59
- _this.handleResponseData(data, action);
60
- })
61
- .catch(function (err) { return console.log(err); });
62
- };
63
- HttpClient.prototype.postAndReturnTheData = function (envelope, action) {
64
- return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
65
- .then(function (response) {
66
- if (response.ok)
67
- return response.json();
68
- throw response;
69
- })
70
- .then(function (data) {
71
- return data;
72
- })
73
- .catch(function (err) { return console.log(err); });
74
- };
75
- HttpClient.prototype.getHttpOptions = function (envelope) {
76
- return Object.assign({}, HttpHelper.fetchOptions, {
77
- body: JSON.stringify(envelope),
78
- credentials: this.options.credentials,
79
- });
80
- };
81
- HttpClient.prototype.constructInputEnvelope = function (action) {
82
- return {
83
- action: StoreHelper.getAction(action),
84
- localState: StoreHelper.getLocalState(action),
85
- globalState: StoreHelper.getGlobalState(),
86
- clientId: this.clientId,
87
- };
88
- };
89
- HttpClient.prototype.constructPhraseEnvelope = function (phrase) {
90
- return {
91
- command: { phrase: phrase },
92
- globalState: StoreHelper.getGlobalState(),
93
- clientId: this.clientId,
94
- };
95
- };
96
- HttpClient.prototype.constructFirstHitEnvelope = function () {
97
- return {
98
- command: { site: this.endpointUrl },
99
- clientId: this.clientId,
100
- globalState: {},
101
- };
102
- };
103
- HttpClient.prototype.handleResponseData = function (envelope, action) {
104
- StoreHelper.setGlobalState(envelope.globalState);
105
- this.middlewareClient.handleEntries(envelope.entries, action);
106
- };
107
- return HttpClient;
108
- }());
109
- export { HttpClient };
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 { HttpHelper } from '../helper/http.helper';
38
+ import { MiddlewareHelper } from '../helper/middleware.helper';
39
+ import { StoreHelper } from '../helper/store.helper';
40
+ import ChatClient from './chat.client';
41
+ import MiddlewareClient from './middleware.client';
42
+ var HttpClient = /** @class */ (function () {
43
+ function HttpClient(endpoint, clientId, container) {
44
+ this.options = {
45
+ credentials: HttpHelper.getCredentials(),
46
+ clientId: clientId,
47
+ };
48
+ this.apiEndpoint = endpoint;
49
+ this.projectionPath = window.location.href;
50
+ this.endpointUrl = HttpHelper.combineUrl(this.projectionPath, 'conversations');
51
+ this.clientId = this.options.clientId;
52
+ this.middlewareClient = new MiddlewareClient(container);
53
+ this.chatClient = new ChatClient(container);
54
+ }
55
+ HttpClient.prototype.firstHit = function () {
56
+ var _this = this;
57
+ // On first hit if there are entries stored in the storage, use them
58
+ // Otherwise start a new session
59
+ return MiddlewareHelper.getEntrySessionStorage().then(function (o) { return __awaiter(_this, void 0, void 0, function () {
60
+ var envelope, response;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ if (!(o && o.length > 0)) return [3 /*break*/, 1];
65
+ this.chatClient.processMessageArrayAndStoreIt(o);
66
+ return [3 /*break*/, 3];
67
+ case 1:
68
+ envelope = this.constructFirstHitEnvelope();
69
+ return [4 /*yield*/, this.postAndHandleTheData(envelope)];
70
+ case 2:
71
+ response = _a.sent();
72
+ return [2 /*return*/, response];
73
+ case 3: return [2 /*return*/];
74
+ }
75
+ });
76
+ }); });
77
+ };
78
+ // for updates, such as paging changes
79
+ HttpClient.prototype.handleUpdate = function (action) {
80
+ var envelope = this.constructInputEnvelope(action);
81
+ this.postAndHandleTheUpdateData(envelope, action);
82
+ // return this.postAndReturnTheData(envelope, action).then((o) => {
83
+ // return o.entries;
84
+ // });
85
+ };
86
+ // for action clicks
87
+ HttpClient.prototype.handleInput = function (action) {
88
+ var envelope = this.constructInputEnvelope(action);
89
+ this.postAndHandleTheData(envelope, action);
90
+ };
91
+ // for text entries by user
92
+ HttpClient.prototype.handlePhrase = function (phrase) {
93
+ var envelope = this.constructPhraseEnvelope(phrase);
94
+ this.postAndHandleTheData(envelope);
95
+ };
96
+ HttpClient.prototype.postAndHandleTheData = function (envelope, action) {
97
+ var _this = this;
98
+ return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
99
+ .then(function (response) {
100
+ if (response.ok)
101
+ return response.json();
102
+ throw response;
103
+ })
104
+ .then(function (data) {
105
+ _this.handleResponseData(data, action);
106
+ return data;
107
+ })
108
+ .catch(function (err) { return console.log(err); });
109
+ };
110
+ HttpClient.prototype.postAndHandleTheUpdateData = function (envelope, action) {
111
+ var _this = this;
112
+ return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
113
+ .then(function (response) {
114
+ if (response.ok)
115
+ return response.json();
116
+ throw response;
117
+ })
118
+ .then(function (data) {
119
+ _this.handleUpdateResponseData(data, action);
120
+ })
121
+ .catch(function (err) { return console.log(err); });
122
+ };
123
+ HttpClient.prototype.getHttpOptions = function (envelope) {
124
+ return Object.assign({}, HttpHelper.fetchOptions, {
125
+ body: JSON.stringify(envelope),
126
+ credentials: this.options.credentials,
127
+ });
128
+ };
129
+ HttpClient.prototype.constructInputEnvelope = function (action) {
130
+ return {
131
+ action: StoreHelper.getAction(action),
132
+ localState: StoreHelper.getLocalState(action),
133
+ globalState: StoreHelper.getGlobalState(),
134
+ clientId: this.clientId,
135
+ };
136
+ };
137
+ HttpClient.prototype.constructPhraseEnvelope = function (phrase) {
138
+ return {
139
+ command: { phrase: phrase },
140
+ globalState: StoreHelper.getGlobalState(),
141
+ clientId: this.clientId,
142
+ };
143
+ };
144
+ HttpClient.prototype.constructFirstHitEnvelope = function () {
145
+ return {
146
+ command: { site: this.endpointUrl },
147
+ clientId: this.clientId,
148
+ globalState: {},
149
+ };
150
+ };
151
+ HttpClient.prototype.handleResponseData = function (envelope, action) {
152
+ StoreHelper.setGlobalState(envelope.globalState);
153
+ this.middlewareClient.handleEntries(envelope.entries, action);
154
+ };
155
+ HttpClient.prototype.handleUpdateResponseData = function (envelope, action) {
156
+ this.middlewareClient.handleUpdate(envelope.entries, action);
157
+ };
158
+ return HttpClient;
159
+ }());
160
+ export { HttpClient };
@@ -1,13 +1,14 @@
1
- import { ServerEntry } from '../contract/model/http/server-entry.model';
2
- export default class MiddlewareClient {
3
- private paging;
4
- private processor;
5
- private entryInterface;
6
- private chatClient;
7
- constructor();
8
- static initialize(container: any, widget: any): void;
9
- handleEntries(entries: ServerEntry[], action?: string): void;
10
- handleUpdate(input: string, endpoint: string): void;
11
- checkForUpdate(input: string): boolean;
12
- private executeMiddlewares;
13
- }
1
+ import { Container } from '@webprovisions/platform';
2
+ import { ServerEntry } from '../contract/model/http/server-entry.model';
3
+ export default class MiddlewareClient {
4
+ private paging;
5
+ private processor;
6
+ private entryInterface;
7
+ private chatClient;
8
+ constructor(container: Container);
9
+ static initialize(container: any, widget: any): void;
10
+ handleEntries(entries: ServerEntry[], action?: string): Promise<void>;
11
+ handleUpdate(entries: ServerEntry[], action?: string): Promise<void>;
12
+ checkForUpdate(input: string): boolean;
13
+ private executeMiddlewares;
14
+ }
@@ -1,55 +1,104 @@
1
- import { MiddlewareHelper } from '../helper/middleware.helper';
2
- import { StoreHelper } from '../helper/store.helper';
3
- 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
- import PagingInterface from '../interface/middleware/paging.interface';
7
- import ProcessorInterface from '../interface/middleware/processor.interface';
8
- import ChatClient from './chat.client';
9
- import { HttpClient } from './http.client';
10
- var MiddlewareClient = /** @class */ (function () {
11
- function MiddlewareClient() {
12
- // this.contactExpanded = new ContactExpandedInterface();
13
- // this.legacyContact = new ContactInterface();
14
- this.paging = new PagingInterface();
15
- this.processor = new ProcessorInterface();
16
- this.entryInterface = new EntryInterface();
17
- this.chatClient = new ChatClient();
18
- }
19
- MiddlewareClient.initialize = function (container, widget) {
20
- MiddlewareHelper.setContainer(container);
21
- MiddlewareHelper.setWidget(widget);
22
- };
23
- // called on all standart scenarios like actions and user messages
24
- 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);
28
- };
29
- // called on situations such as paging changes
30
- // 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);
38
- });
39
- };
40
- // checks whether the action was of an update type
41
- MiddlewareClient.prototype.checkForUpdate = function (input) {
42
- return input === 'next';
43
- };
44
- MiddlewareClient.prototype.executeMiddlewares = function (entries, isUpdate, action) {
45
- if (isUpdate && action)
46
- entries = this.processor.processUpdate(StoreHelper.getEntry(action), entries);
47
- else {
48
- entries = this.processor.process(entries);
49
- }
50
- entries = this.paging.process(entries);
51
- return entries;
52
- };
53
- return MiddlewareClient;
54
- }());
55
- export default MiddlewareClient;
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 { MiddlewareHelper } from '../helper/middleware.helper';
38
+ import { StoreHelper } from '../helper/store.helper';
39
+ import EntryInterface from '../interface/entry.interface';
40
+ import PagingInterface from '../interface/middleware/paging.interface';
41
+ import ProcessorInterface from '../interface/middleware/processor.interface';
42
+ import ChatClient from './chat.client';
43
+ var MiddlewareClient = /** @class */ (function () {
44
+ function MiddlewareClient(container) {
45
+ this.paging = new PagingInterface();
46
+ this.processor = new ProcessorInterface();
47
+ this.entryInterface = new EntryInterface(container);
48
+ this.chatClient = new ChatClient(container);
49
+ }
50
+ MiddlewareClient.initialize = function (container, widget) {
51
+ MiddlewareHelper.setContainer(container);
52
+ MiddlewareHelper.setWidget(widget);
53
+ };
54
+ // called on all standart scenarios like actions and user messages
55
+ MiddlewareClient.prototype.handleEntries = function (entries, action) {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var o, messageArray;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0:
61
+ o = this.executeMiddlewares(entries, false, action);
62
+ return [4 /*yield*/, this.entryInterface.transformArray(o)];
63
+ case 1:
64
+ messageArray = _a.sent();
65
+ this.chatClient.processMessageArrayAndStoreIt(messageArray);
66
+ return [2 /*return*/];
67
+ }
68
+ });
69
+ });
70
+ };
71
+ // called on situations such as paging changes
72
+ // when no new entries will be printed
73
+ MiddlewareClient.prototype.handleUpdate = function (entries, action) {
74
+ return __awaiter(this, void 0, void 0, function () {
75
+ var o, messageArray;
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0:
79
+ o = this.executeMiddlewares(entries, true, action);
80
+ return [4 /*yield*/, this.entryInterface.transformArray(o)];
81
+ case 1:
82
+ messageArray = _a.sent();
83
+ this.chatClient.updateMessageArrayAndStoreIt(messageArray);
84
+ return [2 /*return*/];
85
+ }
86
+ });
87
+ });
88
+ };
89
+ // checks whether the action was of an update type
90
+ MiddlewareClient.prototype.checkForUpdate = function (input) {
91
+ return input === 'next';
92
+ };
93
+ MiddlewareClient.prototype.executeMiddlewares = function (entries, isUpdate, action) {
94
+ if (isUpdate && action)
95
+ entries = this.processor.processUpdate(StoreHelper.getEntry(action), entries);
96
+ else {
97
+ entries = this.processor.process(entries);
98
+ }
99
+ entries = this.paging.process(entries);
100
+ return entries;
101
+ };
102
+ return MiddlewareClient;
103
+ }());
104
+ export default MiddlewareClient;
@@ -1,8 +1,8 @@
1
- import React from 'react';
2
- interface PropsType {
3
- contactMethod: any;
4
- type: any;
5
- className?: any;
6
- }
7
- declare const ContactMethodItem: React.FC<PropsType>;
8
- export default ContactMethodItem;
1
+ import React from 'react';
2
+ interface PropsType {
3
+ contactMethod: any;
4
+ type: any;
5
+ className?: any;
6
+ }
7
+ declare const ContactMethodItem: React.FC<PropsType>;
8
+ export default ContactMethodItem;
@@ -1,51 +1,54 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
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
- 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) {
32
- 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 })));
50
- };
51
- export default ContactMethodItem;
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
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
+ import { ContactMethod as GenericContactMethod } from '@humany/widget-adapters';
29
+ import { useContainer, useDispatch } from '@humany/widget-ui';
30
+ import React, { useEffect, useState } from 'react';
31
+ var ContactMethodItem = function (props) {
32
+ 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
+ if (!container || !container.get('$widget')) {
37
+ return;
38
+ }
39
+ var events = container.get('$widget').events;
40
+ events.subscribe('form:validated', function (_event, _data) {
41
+ // TODO: this is a due to props not being updated when props.contactMethod.body changes
42
+ // perhaps there is a cleaner way of doing this
43
+ setBody(props.contactMethod.body);
44
+ });
45
+ }, [container]);
46
+ return (React.createElement(GenericContactMethod, __assign({ className: props.className, onClick: function () {
47
+ dispatch('action', props.contactMethod.id + "/" + props.type.toString() + "/" + props.contactMethod.title);
48
+ // dispatch(
49
+ // "expand",
50
+ // `${props.contactMethod.id}/${props.type.toString()}`
51
+ // );
52
+ }, dispatch: dispatch }, props.contactMethod, { body: body, expanded: props.contactMethod.expanded })));
53
+ };
54
+ export default ContactMethodItem;
@@ -1,7 +1,7 @@
1
- import React from 'react';
2
- interface PropsType {
3
- contactMethodList: any;
4
- type: any;
5
- }
6
- declare const ContactMethodList: React.FC<PropsType>;
7
- export default ContactMethodList;
1
+ import React from 'react';
2
+ interface PropsType {
3
+ contactMethodList: any;
4
+ type: any;
5
+ }
6
+ declare const ContactMethodList: React.FC<PropsType>;
7
+ export default ContactMethodList;