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

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 (69) 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.js +12 -34
  10. package/lib/contract/custom-component/contact-method-list.js +6 -34
  11. package/lib/contract/custom-component/contact-method.js +12 -17
  12. package/lib/contract/enum/server-entry-type.enum.d.ts +3 -2
  13. package/lib/contract/enum/server-entry-type.enum.js +5 -7
  14. package/lib/contract/model/conversation-api-model/list.model.js +1 -2
  15. package/lib/contract/model/conversation-api-model/message.model.js +1 -2
  16. package/lib/contract/model/http/action.model.js +1 -2
  17. package/lib/contract/model/http/client-action.model.js +1 -2
  18. package/lib/contract/model/http/client-envelope.model.js +1 -2
  19. package/lib/contract/model/http/connect-options.model.js +1 -2
  20. package/lib/contract/model/http/global-state.model.js +1 -2
  21. package/lib/contract/model/http/http-client-options.model.js +1 -2
  22. package/lib/contract/model/http/server-entry.model.js +1 -2
  23. package/lib/contract/model/http/server-envelope.model.js +1 -2
  24. package/lib/contract/model/middleware/aggregator-state.model.js +1 -2
  25. package/lib/contract/model/shared/loose-object.model.js +1 -2
  26. package/lib/helper/chat.helper.js +1 -4
  27. package/lib/helper/http.helper.d.ts +1 -1
  28. package/lib/helper/http.helper.js +8 -13
  29. package/lib/helper/middleware.helper.d.ts +1 -1
  30. package/lib/helper/middleware.helper.js +7 -11
  31. package/lib/helper/store.helper.d.ts +4 -3
  32. package/lib/helper/store.helper.js +105 -16
  33. package/lib/index.js +2 -8
  34. package/lib/interface/entry.interface.d.ts +6 -3
  35. package/lib/interface/entry.interface.js +176 -57
  36. package/lib/interface/middleware/paging.interface.js +3 -5
  37. package/lib/interface/middleware/processor.interface.js +1 -3
  38. package/lib/plugin.d.ts +2 -2
  39. package/lib/plugin.js +73 -90
  40. package/lib/utils.d.ts +1 -0
  41. package/lib/utils.js +5 -0
  42. package/lib-esm/client/chat.client.d.ts +3 -2
  43. package/lib-esm/client/chat.client.js +81 -11
  44. package/lib-esm/client/contact-method.client.d.ts +9 -1
  45. package/lib-esm/client/contact-method.client.js +28 -6
  46. package/lib-esm/client/http.client.d.ts +11 -7
  47. package/lib-esm/client/http.client.js +125 -22
  48. package/lib-esm/client/middleware.client.d.ts +4 -3
  49. package/lib-esm/client/middleware.client.js +89 -19
  50. package/lib-esm/contract/custom-component/contact-method-item.js +4 -1
  51. package/lib-esm/contract/enum/server-entry-type.enum.d.ts +3 -2
  52. package/lib-esm/contract/enum/server-entry-type.enum.js +3 -2
  53. package/lib-esm/helper/http.helper.d.ts +1 -1
  54. package/lib-esm/helper/http.helper.js +7 -9
  55. package/lib-esm/helper/middleware.helper.d.ts +1 -1
  56. package/lib-esm/helper/middleware.helper.js +5 -6
  57. package/lib-esm/helper/store.helper.d.ts +4 -3
  58. package/lib-esm/helper/store.helper.js +103 -11
  59. package/lib-esm/interface/entry.interface.d.ts +6 -3
  60. package/lib-esm/interface/entry.interface.js +160 -39
  61. package/lib-esm/plugin.d.ts +2 -2
  62. package/lib-esm/plugin.js +66 -55
  63. package/lib-esm/utils.d.ts +1 -0
  64. package/lib-esm/utils.js +5 -0
  65. package/package.json +45 -45
  66. package/lib/interface/middleware/contact-expanded.interface.d.ts +0 -0
  67. package/lib/interface/middleware/contact-expanded.interface.js +0 -50
  68. package/lib/interface/middleware/legacy-contact-methods.interface.d.ts +0 -0
  69. package/lib/interface/middleware/legacy-contact-methods.interface.js +0 -394
@@ -1,394 +0,0 @@
1
- "use strict";
2
- // import { Container } from "@webprovisions/platform";
3
- // import { ServerEntry } from "../../contract/model/http/server-entry.model";
4
- // import { MiddlewareHelper } from "../../helper/middleware.helper";
5
- // export const mapContactMethodType = (cm: any): string => {
6
- // const a = cm.exitConfiguration.split(".");
7
- // if (a.indexOf("phone") > -1) {
8
- // return "phone";
9
- // }
10
- // if (a.indexOf("freetext") > -1) {
11
- // return "free-text";
12
- // }
13
- // if (a.indexOf("email") > -1) {
14
- // return "email";
15
- // }
16
- // if (a.indexOf("link") > -1) {
17
- // return "link";
18
- // }
19
- // if (a.indexOf("custom") > -1 && a.indexOf("adapter") > -1) {
20
- // return "custom-adapter";
21
- // }
22
- // if (a.indexOf("chat") > -1) {
23
- // return "chat";
24
- // }
25
- // if (a.indexOf("callback") > -1) {
26
- // return "callback";
27
- // }
28
- // return "";
29
- // };
30
- // const fetchContactMethods = (
31
- // matchingServiceClient: ServiceClient,
32
- // guideId: string,
33
- // connectionKey: string
34
- // ): any => {
35
- // return new Promise((resolve) => {
36
- // if (guideId) {
37
- // matchingServiceClient.getGuide(
38
- // guideId,
39
- // connectionKey,
40
- // { statisticsDisabled: true },
41
- // (guide: GuideViewApiResponse) => {
42
- // const contactMethods = [guide.ContactMethod].concat(
43
- // guide.ContactMethods ? guide.ContactMethods : []
44
- // );
45
- // resolve(contactMethods);
46
- // }
47
- // );
48
- // } else {
49
- // matchingServiceClient.contactMethods((contactMethods: any) => {
50
- // resolve(contactMethods.Matches);
51
- // });
52
- // }
53
- // });
54
- // };
55
- // export const mapContactMethod = (
56
- // match: any,
57
- // contactMethods: ContactMethodPlatform,
58
- // entryId?: string,
59
- // actionKey?: string
60
- // ) => {
61
- // const adapter = match.exits[0].adapter;
62
- // const clientName = adapter.customClientName || adapter.clientName;
63
- // // const contactMethodType =
64
- // // contactMethods.get(clientName) || <ContactMethodType>{};
65
- // const contactMethod: any = {
66
- // entryId,
67
- // actionKey,
68
- // clientName,
69
- // canRender: true,
70
- // id: `${match.id}`,
71
- // title: match.title,
72
- // body: adapter.settings,
73
- // type: mapContactMethodType(match),
74
- // description:
75
- // match.description && match.description.length
76
- // ? match.description
77
- // : undefined,
78
- // expanded: false,
79
- // inline: true,
80
- // uriName: match.uriName,
81
- // };
82
- // if (
83
- // match.defaultIcon &&
84
- // match.defaultIcon.content &&
85
- // match.defaultIcon.type
86
- // ) {
87
- // contactMethod.symbol = {
88
- // type: match.defaultIcon.type,
89
- // content: match.defaultIcon.content,
90
- // };
91
- // }
92
- // const hasForm =
93
- // match.form &&
94
- // (match.form.hasValueComponents || match.form.HasValueComponents);
95
- // if (hasForm) {
96
- // const formId = contactMethod.id || "";
97
- // const builder = FormBuilder.fromLegacyForm(formId, match.form, null);
98
- // // builder.createComponent(submitButton(texts.get("forms.submit"), "submit"));
99
- // contactMethod.body.form = builder.get();
100
- // contactMethod.inline = false;
101
- // if (match.expandFormAutomatically) {
102
- // contactMethod.expanded = true;
103
- // contactMethod.inline = true;
104
- // }
105
- // }
106
- // if (contactMethod.type === "free-text" || contactMethod.type === "phone") {
107
- // contactMethod.expanded =
108
- // contactMethod.body.displayTextBeforeClick === "false";
109
- // }
110
- // if (contactMethod.type === "link") {
111
- // contactMethod.expanded = true;
112
- // }
113
- // if (match.exitConfiguration === "custom.adapter") {
114
- // if (hasForm) {
115
- // contactMethod.inline = false;
116
- // } else {
117
- // contactMethod.expanded = true;
118
- // }
119
- // }
120
- // return contactMethod;
121
- // };
122
- // // Displays confirmation text after contact method form has been submitted
123
- // // const respondContactMethodSubmitted = (
124
- // // dataSource: DataSource,
125
- // // data: { entryId: string; confirmationText: string; type: string },
126
- // // ) => {
127
- // // dataSource.respond(data.entryId, data.type, {
128
- // // completedMessage: data.confirmationText,
129
- // // });
130
- // // };
131
- // const modifyActionsForExpandedItems = (entry: ServerEntry) => {
132
- // const keysToModify = entry.content.items
133
- // .filter((item: any) => {
134
- // if (!item.data) {
135
- // return false;
136
- // }
137
- // return item.data.expandFormAutomatically;
138
- // })
139
- // .map((item: any) => item.actionKey);
140
- // return Object.keys(entry.actions).reduce<any>((acc, actionKey: any) => {
141
- // const action = entry.actions[actionKey];
142
- // if (keysToModify.indexOf(actionKey) > -1) {
143
- // acc[actionKey] = {
144
- // ...action,
145
- // $type:
146
- // "Humany.Matching.Bots.Conversations.Actions.ContactMethodCompleted, Humany.Matching",
147
- // };
148
- // } else {
149
- // acc[actionKey] = action;
150
- // }
151
- // return acc;
152
- // }, {});
153
- // };
154
- // const storeLegacyContactMethod = (container: any, legacyContactMethod: any) => {
155
- // return lock(container)(() => {
156
- // return container.getAsync("storage").then((storage: StorageProvider) => {
157
- // return storage.session
158
- // .getItem("legacyContactMethods")
159
- // .then((legacyContactMethods) => {
160
- // return legacyContactMethods || container.get("legacyContactMethods");
161
- // })
162
- // .then((legacyContactMethods) => {
163
- // let legacyContactMethodsToStore = legacyContactMethods;
164
- // if (!legacyContactMethodsToStore) {
165
- // legacyContactMethodsToStore = {};
166
- // container.register(
167
- // "legacyContactMethods",
168
- // legacyContactMethodsToStore
169
- // );
170
- // }
171
- // legacyContactMethodsToStore[legacyContactMethod.id] = {
172
- // entity: legacyContactMethod,
173
- // };
174
- // return storage.session.setItem(
175
- // "legacyContactMethods",
176
- // legacyContactMethods
177
- // );
178
- // });
179
- // });
180
- // });
181
- // };
182
- // class ContactMethodResolver {
183
- // cache: Map<string, Promise<any>> = new Map<string, Promise<any>>();
184
- // constructor(
185
- // private matchingClient: ServiceClient,
186
- // private container: any,
187
- // private contactMethods: ContactMethodPlatform
188
- // ) {}
189
- // add(content: any, entryId: string) {
190
- // const { id, guideId, connectionKey } = content;
191
- // const key = (guideId || "") + (connectionKey || "") || "all";
192
- // let promise = this.cache.get(key);
193
- // if (promise) {
194
- // promise.then((contactMethodEntity) => {
195
- // Object.assign(
196
- // content,
197
- // mapContactMethod(
198
- // contactMethodEntity,
199
- // this.contactMethods,
200
- // entryId
201
- // )
202
- // );
203
- // });
204
- // } else {
205
- // promise = <Promise<any>>fetchContactMethods(
206
- // this.matchingClient,
207
- // guideId,
208
- // connectionKey
209
- // )
210
- // .then((contactMethodEntites: any) => {
211
- // const contactMethodEntity = contactMethodEntites.find(
212
- // (entity: any) => entity.Id === id
213
- // );
214
- // const { Form } = contactMethodEntity;
215
- // return Object.assign({}, camilize(contactMethodEntity), {
216
- // form: Form,
217
- // });
218
- // })
219
- // .then((contactMethodEntity: any) => {
220
- // storeLegacyContactMethod(this.container, contactMethodEntity);
221
- // Object.assign(
222
- // content,
223
- // mapContactMethod(
224
- // contactMethodEntity,
225
- // this.contactMethods,
226
- // entryId
227
- // )
228
- // );
229
- // return contactMethodEntity;
230
- // });
231
- // this.cache.set(key, promise);
232
- // }
233
- // }
234
- // wait(): Promise<any> {
235
- // return Promise.all(Array.from(this.cache.values()));
236
- // }
237
- // }
238
- // export default class ContactInterface {
239
- // name = "contact";
240
- // private container: Container;
241
- // constructor() {
242
- // this.initalize();
243
- // this.container = <Container>MiddlewareHelper.getContainer();
244
- // }
245
- // process(entries: ServerEntry[]): Promise<ServerEntry[]> {
246
- // return Promise.all([
247
- // <Promise<ContactMethodPlatform>>this.container.getAsync("contactMethods"),
248
- // <Promise<ServiceClient>>this.container.getAsync("matchingClient")
249
- // ])
250
- // .then(result => {
251
- // let contactMethods = result[0];
252
- // let matchingClient = result[1];
253
- // // remove Text entries without text or html props.
254
- // const updatedEntries = entries.filter(
255
- // (entry) =>
256
- // !(
257
- // entry.type === "Text" &&
258
- // entry.content &&
259
- // !entry.content.text &&
260
- // !entry.content.html
261
- // )
262
- // );
263
- // const resolver = new ContactMethodResolver(
264
- // matchingClient,
265
- // this.container,
266
- // contactMethods
267
- // );
268
- // // get all contact method lists
269
- // const lists = updatedEntries.filter(
270
- // (entry) => entry.type === "List" && entry.tags.indexOf("contact") > -1
271
- // );
272
- // // iterate and patch legacy items by mapping the 'data' attribute
273
- // lists.forEach((entry) => {
274
- // if (entry.content.items) {
275
- // // if the list contains already expanded contact methods,
276
- // // we do not want to use the action type ContactMethodCompleted
277
- // // instead of ContactMethodSelected
278
- // entry.actions = modifyActionsForExpandedItems(entry);
279
- // entry.content.items.forEach((item: any) => {
280
- // if (item.data) {
281
- // storeLegacyContactMethod(this.container, item.data);
282
- // Object.assign(
283
- // item,
284
- // mapContactMethod(
285
- // item.data,
286
- // contactMethods,
287
- // entry.id,
288
- // item.actionKey
289
- // )
290
- // );
291
- // delete item.data;
292
- // }
293
- // });
294
- // }
295
- // });
296
- // // get all single contact methods
297
- // const singles = updatedEntries.filter(
298
- // (entry) =>
299
- // entry.type === "Contact" &&
300
- // entry.content.id &&
301
- // !entry.content.clientName
302
- // );
303
- // singles.forEach((entry) => resolver.add(entry.content, entry.id));
304
- // return resolver.wait().then(() => {
305
- // // patch with ContactMethodType
306
- // updatedEntries
307
- // .filter(
308
- // (entry) =>
309
- // entry.type === "Contact" &&
310
- // entry.content &&
311
- // !entry.content.contactMethodType
312
- // )
313
- // .forEach((entry) => {
314
- // // // const contactMethodType =
315
- // // // contactMethods.get(entry.content.clientName) ||
316
- // // // <ContactMethodType>{};
317
- // entry.content.canRender = true;
318
- // });
319
- // updatedEntries
320
- // .filter((entry) => entry.type === "Contact")
321
- // .forEach((entry) => {
322
- // entry.type = "List";
323
- // const { timestamp, ...content } = entry.content;
324
- // entry.content = { timestamp, items: [{ ...content }] };
325
- // if (entry.tags.indexOf("contact") === -1) {
326
- // entry.tags.push("contact");
327
- // }
328
- // });
329
- // return entries;
330
- // });
331
- // });
332
- // }
333
- // initalize() {
334
- // // this.widget.events.subscribe(
335
- // // 'contact-method:invoked',
336
- // // async (event, data) => {
337
- // // const { method, contactMethod, result } = data;
338
- // // const { entryId } = contactMethod;
339
- // // // TODO: Currently we need to look up the contact method entry in the full "unwashed"
340
- // // // stream as it does not exist in the "regular" washed stream.
341
- // // // This should be handled differently by perhaps storing a reference in
342
- // // // the parent entity to the contact method entry in some way.
343
- // // const entry = StoreHelper.getEntryStore()
344
- // // .find(e => e.id === entryId);
345
- // // if (method === 'submit' && result.success && !result.preventResponse) {
346
- // // let actionType = 'submitted';
347
- // // if (
348
- // // entry &&
349
- // // entry.actions &&
350
- // // Object.keys(entry.actions).length >= 1 &&
351
- // // !entry.actions.submitted
352
- // // ) {
353
- // // const item = entry.content.items
354
- // // .find((item: any) => item.id === contactMethod.id);
355
- // // if (item && item.actionKey && entry.actions[item.actionKey]) {
356
- // // actionType = item.actionKey;
357
- // // }
358
- // // }
359
- // // // respondContactMethodSubmitted(dataSource, {
360
- // // // entryId,
361
- // // // type: actionType,
362
- // // // confirmationText: result.confirmationText,
363
- // // // });
364
- // // if (entry) {
365
- // // // Disable form
366
- // // const item = entry.content.items
367
- // // .find((item: any) => item.id === contactMethod.id);
368
- // // if (item && item.body && item.body.form) {
369
- // // item.body.form.layout['ui:disabled'] = true;
370
- // // }
371
- // // }
372
- // // }
373
- // // if (entry) {
374
- // // if (entry.type === 'List') {
375
- // // const updatedItems = entry.content.items.map((item: any) => {
376
- // // if (item.id === contactMethod.id) {
377
- // // return contactMethod;
378
- // // }
379
- // // return item;
380
- // // });
381
- // // writer.update(entryId, { items: updatedItems });
382
- // // writer.commit();
383
- // // } else if (
384
- // // entry.type === 'ContactMethod' ||
385
- // // entry.type === 'Contact'
386
- // // ) {
387
- // // writer.update(contactMethod.entryId, contactMethod);
388
- // // writer.commit();
389
- // // }
390
- // // }
391
- // // },
392
- // // );
393
- // }
394
- // }