@telia-ace/knowledge-widget-bot-provider 0.0.1-alpha.6 → 0.0.1-alpha.62

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 (126) hide show
  1. package/{lib-esm → dist}/client/chat.client.d.ts +2 -1
  2. package/{lib → dist}/client/contact-method.client.d.ts +4 -1
  3. package/{lib → dist}/client/http.client.d.ts +5 -4
  4. package/{lib → dist}/client/middleware.client.d.ts +4 -3
  5. package/dist/contact-method.15886c3d.js +66 -0
  6. package/dist/contact-method.15886c3d.js.map +1 -0
  7. package/{lib-esm → dist}/contract/custom-component/contact-method-item.d.ts +0 -0
  8. package/{lib-esm → dist}/contract/custom-component/contact-method-list.d.ts +0 -0
  9. package/{lib-esm → dist}/contract/custom-component/contact-method.d.ts +0 -0
  10. package/{lib → dist}/contract/enum/server-entry-type.enum.d.ts +3 -2
  11. package/{lib-esm → dist}/contract/model/conversation-api-model/list.model.d.ts +0 -0
  12. package/{lib-esm → dist}/contract/model/conversation-api-model/message.model.d.ts +0 -0
  13. package/{lib-esm → dist}/contract/model/http/action.model.d.ts +0 -0
  14. package/{lib-esm → dist}/contract/model/http/client-action.model.d.ts +0 -0
  15. package/{lib-esm → dist}/contract/model/http/client-envelope.model.d.ts +0 -0
  16. package/{lib-esm → dist}/contract/model/http/connect-options.model.d.ts +0 -0
  17. package/{lib-esm → dist}/contract/model/http/global-state.model.d.ts +0 -0
  18. package/{lib-esm → dist}/contract/model/http/http-client-options.model.d.ts +0 -0
  19. package/{lib-esm → dist}/contract/model/http/server-entry.model.d.ts +0 -0
  20. package/{lib-esm → dist}/contract/model/http/server-envelope.model.d.ts +0 -0
  21. package/{lib-esm → dist}/contract/model/middleware/aggregator-state.model.d.ts +0 -0
  22. package/{lib-esm → dist}/contract/model/shared/loose-object.model.d.ts +0 -0
  23. package/{lib-esm → dist}/helper/chat.helper.d.ts +0 -0
  24. package/{lib-esm → dist}/helper/http.helper.d.ts +1 -1
  25. package/{lib-esm → dist}/helper/middleware.helper.d.ts +1 -1
  26. package/{lib-esm → dist}/helper/store.helper.d.ts +0 -0
  27. package/{lib-esm → dist}/index.d.ts +0 -0
  28. package/dist/index.js +672 -0
  29. package/dist/index.js.map +1 -0
  30. package/{lib-esm → dist}/interface/entry.interface.d.ts +6 -3
  31. package/{lib-esm → dist}/interface/middleware/paging.interface.d.ts +0 -0
  32. package/{lib-esm → dist}/interface/middleware/processor.interface.d.ts +0 -0
  33. package/dist/plugin.d.ts +3 -0
  34. package/package.json +46 -45
  35. package/lib/client/chat.client.d.ts +0 -15
  36. package/lib/client/chat.client.js +0 -80
  37. package/lib/client/contact-method.client.js +0 -276
  38. package/lib/client/http.client.js +0 -114
  39. package/lib/client/middleware.client.js +0 -60
  40. package/lib/contract/custom-component/contact-method-item.d.ts +0 -8
  41. package/lib/contract/custom-component/contact-method-item.js +0 -76
  42. package/lib/contract/custom-component/contact-method-list.d.ts +0 -7
  43. package/lib/contract/custom-component/contact-method-list.js +0 -41
  44. package/lib/contract/custom-component/contact-method.d.ts +0 -3
  45. package/lib/contract/custom-component/contact-method.js +0 -38
  46. package/lib/contract/enum/server-entry-type.enum.js +0 -10
  47. package/lib/contract/model/conversation-api-model/list.model.d.ts +0 -5
  48. package/lib/contract/model/conversation-api-model/list.model.js +0 -2
  49. package/lib/contract/model/conversation-api-model/message.model.d.ts +0 -7
  50. package/lib/contract/model/conversation-api-model/message.model.js +0 -2
  51. package/lib/contract/model/http/action.model.d.ts +0 -3
  52. package/lib/contract/model/http/action.model.js +0 -2
  53. package/lib/contract/model/http/client-action.model.d.ts +0 -4
  54. package/lib/contract/model/http/client-action.model.js +0 -3
  55. package/lib/contract/model/http/client-envelope.model.d.ts +0 -9
  56. package/lib/contract/model/http/client-envelope.model.js +0 -2
  57. package/lib/contract/model/http/connect-options.model.d.ts +0 -5
  58. package/lib/contract/model/http/connect-options.model.js +0 -2
  59. package/lib/contract/model/http/global-state.model.d.ts +0 -8
  60. package/lib/contract/model/http/global-state.model.js +0 -2
  61. package/lib/contract/model/http/http-client-options.model.d.ts +0 -5
  62. package/lib/contract/model/http/http-client-options.model.js +0 -2
  63. package/lib/contract/model/http/server-entry.model.d.ts +0 -11
  64. package/lib/contract/model/http/server-entry.model.js +0 -2
  65. package/lib/contract/model/http/server-envelope.model.d.ts +0 -10
  66. package/lib/contract/model/http/server-envelope.model.js +0 -2
  67. package/lib/contract/model/middleware/aggregator-state.model.d.ts +0 -4
  68. package/lib/contract/model/middleware/aggregator-state.model.js +0 -3
  69. package/lib/contract/model/shared/loose-object.model.d.ts +0 -3
  70. package/lib/contract/model/shared/loose-object.model.js +0 -2
  71. package/lib/helper/chat.helper.d.ts +0 -8
  72. package/lib/helper/chat.helper.js +0 -21
  73. package/lib/helper/http.helper.d.ts +0 -13
  74. package/lib/helper/http.helper.js +0 -33
  75. package/lib/helper/middleware.helper.d.ts +0 -12
  76. package/lib/helper/middleware.helper.js +0 -72
  77. package/lib/helper/store.helper.d.ts +0 -22
  78. package/lib/helper/store.helper.js +0 -80
  79. package/lib/index.d.ts +0 -2
  80. package/lib/index.js +0 -8
  81. package/lib/interface/entry.interface.d.ts +0 -17
  82. package/lib/interface/entry.interface.js +0 -138
  83. package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
  84. package/lib/interface/middleware/contact-expanded.interface.js +0 -50
  85. package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
  86. package/lib/interface/middleware/legacy-contact-methods.interface.js +0 -394
  87. package/lib/interface/middleware/paging.interface.d.ts +0 -4
  88. package/lib/interface/middleware/paging.interface.js +0 -55
  89. package/lib/interface/middleware/processor.interface.d.ts +0 -10
  90. package/lib/interface/middleware/processor.interface.js +0 -120
  91. package/lib/plugin.d.ts +0 -3
  92. package/lib/plugin.js +0 -171
  93. package/lib-esm/client/chat.client.js +0 -75
  94. package/lib-esm/client/contact-method.client.d.ts +0 -22
  95. package/lib-esm/client/contact-method.client.js +0 -270
  96. package/lib-esm/client/http.client.d.ts +0 -22
  97. package/lib-esm/client/http.client.js +0 -108
  98. package/lib-esm/client/middleware.client.d.ts +0 -13
  99. package/lib-esm/client/middleware.client.js +0 -55
  100. package/lib-esm/contract/custom-component/contact-method-item.js +0 -51
  101. package/lib-esm/contract/custom-component/contact-method-list.js +0 -13
  102. package/lib-esm/contract/custom-component/contact-method.js +0 -33
  103. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +0 -6
  104. package/lib-esm/contract/enum/server-entry-type.enum.js +0 -7
  105. package/lib-esm/contract/model/conversation-api-model/list.model.js +0 -1
  106. package/lib-esm/contract/model/conversation-api-model/message.model.js +0 -1
  107. package/lib-esm/contract/model/http/action.model.js +0 -1
  108. package/lib-esm/contract/model/http/client-action.model.js +0 -2
  109. package/lib-esm/contract/model/http/client-envelope.model.js +0 -1
  110. package/lib-esm/contract/model/http/connect-options.model.js +0 -1
  111. package/lib-esm/contract/model/http/global-state.model.js +0 -1
  112. package/lib-esm/contract/model/http/http-client-options.model.js +0 -1
  113. package/lib-esm/contract/model/http/server-entry.model.js +0 -1
  114. package/lib-esm/contract/model/http/server-envelope.model.js +0 -1
  115. package/lib-esm/contract/model/middleware/aggregator-state.model.js +0 -2
  116. package/lib-esm/contract/model/shared/loose-object.model.js +0 -1
  117. package/lib-esm/helper/chat.helper.js +0 -18
  118. package/lib-esm/helper/http.helper.js +0 -30
  119. package/lib-esm/helper/middleware.helper.js +0 -69
  120. package/lib-esm/helper/store.helper.js +0 -77
  121. package/lib-esm/index.js +0 -2
  122. package/lib-esm/interface/entry.interface.js +0 -136
  123. package/lib-esm/interface/middleware/paging.interface.js +0 -53
  124. package/lib-esm/interface/middleware/processor.interface.js +0 -118
  125. package/lib-esm/plugin.d.ts +0 -3
  126. package/lib-esm/plugin.js +0 -143
@@ -1,276 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.ContactMethodClient = void 0;
54
- var knowledge_widget_types_grid_1 = require("@telia-ace/knowledge-widget-types-grid");
55
- var widget_forms_1 = require("@telia-ace/widget-forms");
56
- var uuid_1 = require("uuid");
57
- var store_helper_1 = require("../helper/store.helper");
58
- var chat_client_1 = __importDefault(require("./chat.client"));
59
- var ContactMethodClient = /** @class */ (function () {
60
- function ContactMethodClient() {
61
- var _this = this;
62
- this.chatClient = new chat_client_1.default();
63
- this.handleNewForm = function (errors, entry) { return __awaiter(_this, void 0, void 0, function () {
64
- return __generator(this, function (_a) {
65
- this.updateForm(entry.contactMethods, {
66
- submit: 'Submit',
67
- errors: errors,
68
- });
69
- entry.entry.update({
70
- contactMethods: entry.contactMethods,
71
- type: 'ace-knowledge-contact-method',
72
- noPadding: true,
73
- });
74
- return [2 /*return*/];
75
- });
76
- }); };
77
- this.handleContactMethod = function (input) {
78
- if (input === void 0) { input = ''; }
79
- return __awaiter(_this, void 0, void 0, function () {
80
- var contactMethods;
81
- var _a;
82
- return __generator(this, function (_b) {
83
- switch (_b.label) {
84
- case 0:
85
- if (!(input == 'contact')) return [3 /*break*/, 2];
86
- return [4 /*yield*/, this.handleContactCategoryList(input)];
87
- case 1:
88
- _b.sent();
89
- return [3 /*break*/, 4];
90
- case 2: return [4 /*yield*/, this.loadContactMethods(input.split('/')[1], // type
91
- input.split('/')[0] // id
92
- )];
93
- case 3:
94
- contactMethods = _b.sent();
95
- if (!!((_a = contactMethods.body) === null || _a === void 0 ? void 0 : _a.form)) {
96
- this.handleForm(input, contactMethods);
97
- }
98
- else if (!contactMethods.expanded && contactMethods.inline) {
99
- this.handleSingleContactMethod(contactMethods);
100
- }
101
- else if (!!contactMethods.contactMethods) {
102
- this.handleContactMethodList(input, contactMethods);
103
- }
104
- _b.label = 4;
105
- case 4: return [2 /*return*/];
106
- }
107
- });
108
- });
109
- };
110
- this.handleContactCategoryList = function (input) { return __awaiter(_this, void 0, void 0, function () {
111
- var newGuid, type, contactMethods;
112
- return __generator(this, function (_a) {
113
- switch (_a.label) {
114
- case 0:
115
- newGuid = (0, uuid_1.v4)();
116
- type = knowledge_widget_types_grid_1.DataType.ContactMethodCategories;
117
- return [4 /*yield*/, this.loadContactMethods(type)];
118
- case 1:
119
- contactMethods = _a.sent();
120
- this.chatClient.printUserMessageAndStoreIt(input);
121
- this.printMessage(newGuid, contactMethods);
122
- return [2 /*return*/];
123
- }
124
- });
125
- }); };
126
- this.updateForm = function (contactMethod, properties) {
127
- var _a;
128
- if ((_a = contactMethod === null || contactMethod === void 0 ? void 0 : contactMethod.body) === null || _a === void 0 ? void 0 : _a.form) {
129
- var body = contactMethod.body;
130
- var builder = new widget_forms_1.FormBuilder(body.form);
131
- if (!body.form.layout || !body.form.layout.submit) {
132
- builder.createComponent((0, widget_forms_1.submitButton)(properties.submit, 'submit'));
133
- }
134
- if (properties.errors) {
135
- builder.setValidationErrors(properties.errors);
136
- }
137
- return __assign(__assign({}, body), { form: builder.get() });
138
- }
139
- return (contactMethod === null || contactMethod === void 0 ? void 0 : contactMethod.body) || {};
140
- };
141
- }
142
- ContactMethodClient.initialize = function (dataClient, contactMethodPlatform, agent) {
143
- this.dataClient = dataClient;
144
- this.contactMethodPlatform = contactMethodPlatform;
145
- this.agent = agent;
146
- };
147
- ContactMethodClient.prototype.validate = function (form) {
148
- var _this = this;
149
- var entry = ContactMethodClient.contactMessageEntryArray.find(function (o) { return o.id == form.schema.id; });
150
- ContactMethodClient.contactMethodPlatform.validate(entry.contactMethods).then(function (result) {
151
- _this.handleNewForm(result.errors, entry);
152
- if (result.valid) {
153
- _this.submit(entry);
154
- _this.removeForm(entry);
155
- }
156
- });
157
- };
158
- ContactMethodClient.prototype.handleForm = function (input, contactMethods) {
159
- var title = input.split('/')[2];
160
- contactMethods.expanded = true;
161
- this.updateForm(contactMethods, {
162
- submit: 'Submit',
163
- errors: undefined,
164
- });
165
- this.printMessage(contactMethods.id, contactMethods, title);
166
- };
167
- ContactMethodClient.prototype.handleContactMethodList = function (input, contactMethods) {
168
- var title = input.split('/')[2];
169
- var newGuid = (0, uuid_1.v4)();
170
- this.printMessage(newGuid, contactMethods, title);
171
- };
172
- ContactMethodClient.prototype.handleSingleContactMethod = function (contactMethods) {
173
- var entry = ContactMethodClient.contactMessageEntryArray.find(function (o) {
174
- return o.contactMethods.contactMethods.find(function (t) { return t.id == contactMethods.id; });
175
- });
176
- var curCM = entry.contactMethods.contactMethods.find(function (t) { return t.id == contactMethods.id; });
177
- curCM.expanded = true;
178
- var message = {
179
- contactMethods: entry.contactMethods,
180
- type: 'ace-knowledge-contact-method',
181
- noPadding: true,
182
- };
183
- store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore([
184
- {
185
- id: entry.id,
186
- message: message,
187
- isUser: false,
188
- },
189
- ]);
190
- entry.entry.update(message);
191
- };
192
- ContactMethodClient.prototype.submit = function (entry) {
193
- ContactMethodClient.contactMethodPlatform.submit(entry.contactMethods).then(function (result) {
194
- if (!!result)
195
- ContactMethodClient.agent.print(result);
196
- });
197
- };
198
- ContactMethodClient.prototype.removeForm = function (entry) {
199
- entry.entry.remove();
200
- ContactMethodClient.contactMessageEntryArray.splice(ContactMethodClient.contactMessageEntryArray.indexOf(entry), 1);
201
- };
202
- ContactMethodClient.prototype.printMessage = function (newGuid, contactMethods, title) {
203
- if (title === void 0) { title = undefined; }
204
- if (ContactMethodClient.contactMessageEntryArray.find(function (o) { return o.id == contactMethods.id; })) {
205
- var entry = ContactMethodClient.contactMessageEntryArray.find(function (o) { return o.id == contactMethods.id; });
206
- var message = {
207
- contactMethods: contactMethods,
208
- type: 'ace-knowledge-contact-method',
209
- noPadding: true,
210
- };
211
- entry.entry.update(message);
212
- store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore([
213
- {
214
- id: entry.guid,
215
- message: message,
216
- isUser: false,
217
- },
218
- ]);
219
- }
220
- else {
221
- if (title)
222
- this.chatClient.printUserMessageAndStoreIt(title);
223
- var message = {
224
- contactMethods: contactMethods,
225
- type: 'ace-knowledge-contact-method',
226
- noPadding: true,
227
- };
228
- var entry = ContactMethodClient.agent.print(message);
229
- store_helper_1.StoreHelper.insertOrUpdateMessageArrayStore([
230
- {
231
- id: newGuid,
232
- message: message,
233
- isUser: false,
234
- },
235
- ]);
236
- ContactMethodClient.contactMessageEntryArray.push({
237
- id: newGuid,
238
- contactMethods: contactMethods,
239
- entry: entry,
240
- });
241
- }
242
- };
243
- ContactMethodClient.prototype.loadContactMethods = function (dataType, id) {
244
- if (id === void 0) { id = undefined; }
245
- switch (dataType) {
246
- case knowledge_widget_types_grid_1.DataType.ContactMethodCategories: {
247
- return ContactMethodClient.dataClient
248
- .fetch(knowledge_widget_types_grid_1.DataType.ContactMethods, { contactMethodCategoryId: id })
249
- .then(function (contactMethods) { return contactMethods; });
250
- }
251
- case knowledge_widget_types_grid_1.DataType.ContactMethods: {
252
- if (!!id) {
253
- return ContactMethodClient.dataClient
254
- .fetch(knowledge_widget_types_grid_1.DataType.ContactMethod, { contactMethodId: id })
255
- .then(function (contactMethods) { return contactMethods; });
256
- }
257
- else {
258
- return ContactMethodClient.dataClient
259
- .fetch(knowledge_widget_types_grid_1.DataType.ContactMethods, {})
260
- .then(function (contactMethods) { return contactMethods; });
261
- }
262
- }
263
- case knowledge_widget_types_grid_1.DataType.ContactMethodCategories: {
264
- return ContactMethodClient.dataClient
265
- .fetch(knowledge_widget_types_grid_1.DataType.ContactMethods, { contactMethodCategoryId: id })
266
- .then(function (contactMethods) { return contactMethods; });
267
- }
268
- default: {
269
- return Promise.resolve(undefined);
270
- }
271
- }
272
- };
273
- ContactMethodClient.contactMessageEntryArray = [];
274
- return ContactMethodClient;
275
- }());
276
- exports.ContactMethodClient = ContactMethodClient;
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HttpClient = void 0;
7
- var http_helper_1 = require("../helper/http.helper");
8
- var middleware_helper_1 = require("../helper/middleware.helper");
9
- var store_helper_1 = require("../helper/store.helper");
10
- var chat_client_1 = __importDefault(require("./chat.client"));
11
- var middleware_client_1 = __importDefault(require("./middleware.client"));
12
- var HttpClient = /** @class */ (function () {
13
- function HttpClient(endpoint) {
14
- this.options = {
15
- credentials: http_helper_1.HttpHelper.getCredentials(),
16
- clientId: '84d96a63-b8ba-33ec-22d5-515255f866f8',
17
- };
18
- this.apiEndpoint = endpoint;
19
- this.projectionPath = window.location.href;
20
- this.endpointUrl = http_helper_1.HttpHelper.combineUrl(this.projectionPath, 'conversations');
21
- this.clientId = this.options.clientId;
22
- this.middlewareClient = new middleware_client_1.default();
23
- this.chatClient = new chat_client_1.default();
24
- }
25
- HttpClient.prototype.firstHit = function () {
26
- var _this = this;
27
- // On first hit if there are entries stored in the storage, use them
28
- // Otherwise start a new session
29
- middleware_helper_1.MiddlewareHelper.getEntrySessionStorage().then(function (o) {
30
- if (o && o.length > 0)
31
- _this.chatClient.processMessageArrayAndStoreIt(o);
32
- else {
33
- var envelope = _this.constructFirstHitEnvelope();
34
- _this.postAndHandleTheData(envelope);
35
- }
36
- });
37
- };
38
- // for updates, such as paging changes
39
- HttpClient.prototype.handleUpdate = function (action) {
40
- var envelope = this.constructInputEnvelope(action);
41
- return this.postAndReturnTheData(envelope, action).then(function (o) {
42
- return o.entries;
43
- });
44
- };
45
- // for action clicks
46
- HttpClient.prototype.handleInput = function (action) {
47
- var envelope = this.constructInputEnvelope(action);
48
- this.postAndHandleTheData(envelope, action);
49
- };
50
- // for text entries by user
51
- HttpClient.prototype.handlePhrase = function (phrase) {
52
- var envelope = this.constructPhraseEnvelope(phrase);
53
- this.postAndHandleTheData(envelope);
54
- };
55
- HttpClient.prototype.postAndHandleTheData = function (envelope, action) {
56
- var _this = this;
57
- return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
58
- .then(function (response) {
59
- if (response.ok)
60
- return response.json();
61
- throw response;
62
- })
63
- .then(function (data) {
64
- _this.handleResponseData(data, action);
65
- })
66
- .catch(function (err) { return console.log(err); });
67
- };
68
- HttpClient.prototype.postAndReturnTheData = function (envelope, action) {
69
- return fetch(this.apiEndpoint, this.getHttpOptions(envelope))
70
- .then(function (response) {
71
- if (response.ok)
72
- return response.json();
73
- throw response;
74
- })
75
- .then(function (data) {
76
- return data;
77
- })
78
- .catch(function (err) { return console.log(err); });
79
- };
80
- HttpClient.prototype.getHttpOptions = function (envelope) {
81
- return Object.assign({}, http_helper_1.HttpHelper.fetchOptions, {
82
- body: JSON.stringify(envelope),
83
- credentials: this.options.credentials,
84
- });
85
- };
86
- HttpClient.prototype.constructInputEnvelope = function (action) {
87
- return {
88
- action: store_helper_1.StoreHelper.getAction(action),
89
- localState: store_helper_1.StoreHelper.getLocalState(action),
90
- globalState: store_helper_1.StoreHelper.getGlobalState(),
91
- clientId: this.clientId,
92
- };
93
- };
94
- HttpClient.prototype.constructPhraseEnvelope = function (phrase) {
95
- return {
96
- command: { phrase: phrase },
97
- globalState: store_helper_1.StoreHelper.getGlobalState(),
98
- clientId: this.clientId,
99
- };
100
- };
101
- HttpClient.prototype.constructFirstHitEnvelope = function () {
102
- return {
103
- command: { site: this.endpointUrl },
104
- clientId: this.clientId,
105
- globalState: {},
106
- };
107
- };
108
- HttpClient.prototype.handleResponseData = function (envelope, action) {
109
- store_helper_1.StoreHelper.setGlobalState(envelope.globalState);
110
- this.middlewareClient.handleEntries(envelope.entries, action);
111
- };
112
- return HttpClient;
113
- }());
114
- exports.HttpClient = HttpClient;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var middleware_helper_1 = require("../helper/middleware.helper");
7
- var store_helper_1 = require("../helper/store.helper");
8
- var entry_interface_1 = __importDefault(require("../interface/entry.interface"));
9
- // import ContactExpandedInterface from "../interface/middleware/contact-expanded.interface";
10
- // import ContactInterface from "../interface/middleware/legacy-contact-methods.interface";
11
- var paging_interface_1 = __importDefault(require("../interface/middleware/paging.interface"));
12
- var processor_interface_1 = __importDefault(require("../interface/middleware/processor.interface"));
13
- var chat_client_1 = __importDefault(require("./chat.client"));
14
- var http_client_1 = require("./http.client");
15
- var MiddlewareClient = /** @class */ (function () {
16
- function MiddlewareClient() {
17
- // this.contactExpanded = new ContactExpandedInterface();
18
- // this.legacyContact = new ContactInterface();
19
- this.paging = new paging_interface_1.default();
20
- this.processor = new processor_interface_1.default();
21
- this.entryInterface = new entry_interface_1.default();
22
- this.chatClient = new chat_client_1.default();
23
- }
24
- MiddlewareClient.initialize = function (container, widget) {
25
- middleware_helper_1.MiddlewareHelper.setContainer(container);
26
- middleware_helper_1.MiddlewareHelper.setWidget(widget);
27
- };
28
- // called on all standart scenarios like actions and user messages
29
- MiddlewareClient.prototype.handleEntries = function (entries, action) {
30
- var o = this.executeMiddlewares(entries, false, action);
31
- var messageArray = this.entryInterface.transformArray(o);
32
- this.chatClient.processMessageArrayAndStoreIt(messageArray);
33
- };
34
- // called on situations such as paging changes
35
- // when no new entries will be printed
36
- MiddlewareClient.prototype.handleUpdate = function (input, endpoint) {
37
- var _this = this;
38
- var httpClient = new http_client_1.HttpClient(endpoint);
39
- httpClient.handleUpdate(input).then(function (entries) {
40
- var o = _this.executeMiddlewares(entries, true, input);
41
- var messageArray = _this.entryInterface.transformArray(o);
42
- _this.chatClient.updateMessageArrayAndStoreIt(messageArray);
43
- });
44
- };
45
- // checks whether the action was of an update type
46
- MiddlewareClient.prototype.checkForUpdate = function (input) {
47
- return input === 'next';
48
- };
49
- MiddlewareClient.prototype.executeMiddlewares = function (entries, isUpdate, action) {
50
- if (isUpdate && action)
51
- entries = this.processor.processUpdate(store_helper_1.StoreHelper.getEntry(action), entries);
52
- else {
53
- entries = this.processor.process(entries);
54
- }
55
- entries = this.paging.process(entries);
56
- return entries;
57
- };
58
- return MiddlewareClient;
59
- }());
60
- exports.default = MiddlewareClient;
@@ -1,8 +0,0 @@
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,76 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- var __read = (this && this.__read) || function (o, n) {
37
- var m = typeof Symbol === "function" && o[Symbol.iterator];
38
- if (!m) return o;
39
- var i = m.call(o), r, ar = [], e;
40
- try {
41
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
42
- }
43
- catch (error) { e = { error: error }; }
44
- finally {
45
- try {
46
- if (r && !r.done && (m = i["return"])) m.call(i);
47
- }
48
- finally { if (e) throw e.error; }
49
- }
50
- return ar;
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- var knowledge_widget_adapters_1 = require("@telia-ace/knowledge-widget-adapters");
54
- var widget_ui_1 = require("@telia-ace/widget-ui");
55
- var react_1 = __importStar(require("react"));
56
- var ContactMethodItem = function (props) {
57
- var dispatch = (0, widget_ui_1.useDispatch)();
58
- var container = (0, widget_ui_1.useContainer)();
59
- var _a = __read((0, react_1.useState)(props.contactMethod.body), 2), body = _a[0], setBody = _a[1];
60
- (0, react_1.useEffect)(function () {
61
- var events = container.get('$widget').events;
62
- events.subscribe('form:validated', function (_event, _data) {
63
- // TODO: this is a due to props not being updated when props.contactMethod.body changes
64
- // perhaps there is a cleaner way of doing this
65
- setBody(props.contactMethod.body);
66
- });
67
- }, [container]);
68
- return (react_1.default.createElement(knowledge_widget_adapters_1.ContactMethod, __assign({ className: props.className, onClick: function () {
69
- dispatch('action', "".concat(props.contactMethod.id, "/").concat(props.type.toString(), "/").concat(props.contactMethod.title));
70
- // dispatch(
71
- // "expand",
72
- // `${props.contactMethod.id}/${props.type.toString()}`
73
- // );
74
- }, dispatch: dispatch }, props.contactMethod, { body: body, expanded: props.contactMethod.expanded })));
75
- };
76
- exports.default = ContactMethodItem;
@@ -1,7 +0,0 @@
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,41 +0,0 @@
1
- "use strict";
2
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
- return cooked;
5
- };
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || function (mod) {
23
- if (mod && mod.__esModule) return mod;
24
- var result = {};
25
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
- __setModuleDefault(result, mod);
27
- return result;
28
- };
29
- var __importDefault = (this && this.__importDefault) || function (mod) {
30
- return (mod && mod.__esModule) ? mod : { "default": mod };
31
- };
32
- Object.defineProperty(exports, "__esModule", { value: true });
33
- var react_1 = __importStar(require("react"));
34
- var styled_components_1 = __importDefault(require("styled-components"));
35
- var contact_method_item_1 = __importDefault(require("./contact-method-item"));
36
- var ContactMethodList = function (props) {
37
- return (react_1.default.createElement(react_1.Fragment, null, props.contactMethodList.map(function (contactMethod) { return (react_1.default.createElement(StyledContactMethod, { key: contactMethod.id, type: props.type, contactMethod: contactMethod })); })));
38
- };
39
- var StyledContactMethod = (0, styled_components_1.default)(contact_method_item_1.default)(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; });
40
- exports.default = ContactMethodList;
41
- var templateObject_1;
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const ContactMethod: React.FC;
3
- export default ContactMethod;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
- return cooked;
5
- };
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- var knowledge_widget_types_grid_1 = require("@telia-ace/knowledge-widget-types-grid");
11
- var react_1 = __importDefault(require("react"));
12
- var styled_components_1 = __importDefault(require("styled-components"));
13
- var contact_method_item_1 = __importDefault(require("./contact-method-item"));
14
- var contact_method_list_1 = __importDefault(require("./contact-method-list"));
15
- var ContactMethod = function (props) {
16
- var _a, _b;
17
- var type;
18
- var methodList;
19
- if (props.contactMethods && ((_a = props.contactMethods.contactMethods) === null || _a === void 0 ? void 0 : _a.length) > 0) {
20
- type = knowledge_widget_types_grid_1.DataType.ContactMethods;
21
- methodList = props.contactMethods.contactMethods;
22
- }
23
- else if (props.contactMethods.categories && ((_b = props.contactMethods.categories) === null || _b === void 0 ? void 0 : _b.length) > 0) {
24
- type = knowledge_widget_types_grid_1.DataType.ContactMethodCategories;
25
- methodList = props.contactMethods.categories.filter(function (o) { return o.matches > 0; });
26
- }
27
- else {
28
- type = knowledge_widget_types_grid_1.DataType.ContactMethod;
29
- methodList = props.contactMethods;
30
- }
31
- if (!methodList.length) {
32
- return react_1.default.createElement(StyledContactMethodItem, { type: type, contactMethod: methodList });
33
- }
34
- return react_1.default.createElement(contact_method_list_1.default, { type: type, contactMethodList: methodList });
35
- };
36
- var StyledContactMethodItem = (0, styled_components_1.default)(contact_method_item_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: ", ";\n"], ["\n padding: ", ";\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; });
37
- exports.default = ContactMethod;
38
- var templateObject_1;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServerEntryTypeEnum = void 0;
4
- var ServerEntryTypeEnum;
5
- (function (ServerEntryTypeEnum) {
6
- ServerEntryTypeEnum[ServerEntryTypeEnum["Widget"] = 0] = "Widget";
7
- ServerEntryTypeEnum[ServerEntryTypeEnum["Text"] = 1] = "Text";
8
- ServerEntryTypeEnum[ServerEntryTypeEnum["List"] = 2] = "List";
9
- ServerEntryTypeEnum[ServerEntryTypeEnum["Error"] = 3] = "Error";
10
- })(ServerEntryTypeEnum = exports.ServerEntryTypeEnum || (exports.ServerEntryTypeEnum = {}));
@@ -1,5 +0,0 @@
1
- export interface List {
2
- title?: string;
3
- body?: string;
4
- items: object;
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- export interface Message {
2
- id: string;
3
- message: any;
4
- entry?: any;
5
- conversationEntry?: any;
6
- isUser: boolean;
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });