@telia-ace/knowledge-widget-types-grid 1.0.12 → 1.0.15

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.
File without changes
File without changes
File without changes
File without changes
package/dist/index.js ADDED
@@ -0,0 +1,686 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import { Widget } from "@telia-ace/widget-types-grid";
41
+ export { Component, DetachedComponent, NotFound, genericComponentStyling } from "@telia-ace/widget-types-grid";
42
+ import { DialogItemType, WidgetRenderState } from "@telia-ace/knowledge-widget-core";
43
+ import { removeNullAndUndefinedValues, shallowCompare, deepClone } from "@telia-ace/widget-utilities";
44
+ import { FormBuilder } from "@telia-ace/widget-forms";
45
+ const convertLegacySymbol = (symbol) => {
46
+ if (symbol) {
47
+ const { Type, Content } = symbol;
48
+ if (Type && Content) {
49
+ return { type: Type, content: Content };
50
+ }
51
+ }
52
+ };
53
+ const mapLegacyCategoriesRecursively = (categories) => {
54
+ return categories.map((c) => {
55
+ const category = {
56
+ id: c.Id.toString(),
57
+ title: c.Name,
58
+ symbol: convertLegacySymbol(c.DefaultIcon),
59
+ activeSymbol: c.ActiveIcon && convertLegacySymbol(c.ActiveIcon),
60
+ description: c.Description || c.Attributes && c.Attributes.description || "",
61
+ matches: c.GuidesCount
62
+ };
63
+ if (c.Children && c.Children.length) {
64
+ category.items = mapLegacyCategoriesRecursively(c.Children);
65
+ }
66
+ return category;
67
+ });
68
+ };
69
+ const mapNotices = (source, type) => {
70
+ return source.filter(({ Type }) => Type === type).map(({ Id, Title, Body }) => ({
71
+ id: Id.toString(),
72
+ title: Title,
73
+ body: Body
74
+ }));
75
+ };
76
+ const mapNotificationLists = (source) => {
77
+ return source.map(({ Id, Title, DefaultIcon, ListNotices, Notices }) => ({
78
+ id: Id.toString(),
79
+ title: Title,
80
+ symbol: convertLegacySymbol(DefaultIcon),
81
+ defaultHeaderOptions: {
82
+ visible: !!ListNotices.length
83
+ },
84
+ notifications: (ListNotices || []).concat(Notices || []).map(({ Id: Id2, Title: Title2, Body, Type, Modified }) => ({
85
+ id: Id2.toString(),
86
+ title: Title2,
87
+ body: Body,
88
+ modified: Modified,
89
+ expandable: Type === "listNotice"
90
+ }))
91
+ }));
92
+ };
93
+ const mapContactMethodSettings = ({
94
+ Id,
95
+ Title,
96
+ DefaultIcon,
97
+ Exits: [Exit],
98
+ ExitType,
99
+ ConfirmationText,
100
+ ExpandFormAutomatically,
101
+ Form,
102
+ Description
103
+ }, Validation) => {
104
+ const { Adapter } = Exit || { Adapter: {} };
105
+ const { ClientName = "", Settings = {}, CustomClientName = "" } = Adapter;
106
+ const settings = {
107
+ id: Id.toString(),
108
+ title: Title,
109
+ description: Description,
110
+ symbol: convertLegacySymbol(DefaultIcon),
111
+ clientName: ClientName === "custom.adapter" ? CustomClientName : ClientName,
112
+ expanded: true,
113
+ inline: true,
114
+ body: {}
115
+ };
116
+ if (ClientName.indexOf("phone") > -1 || ClientName.indexOf("freetext") > -1) {
117
+ const { displayTextBeforeClick, textBeforeClick } = Settings;
118
+ if (displayTextBeforeClick === "true") {
119
+ settings.expanded = false;
120
+ settings.title = textBeforeClick;
121
+ }
122
+ if (ClientName.indexOf("phone.text") > -1) {
123
+ settings.body.phoneNumber = Settings.phoneNumber;
124
+ } else {
125
+ settings.body.freetext = Settings.freetext;
126
+ }
127
+ }
128
+ if (ClientName.indexOf("chat.popup") > -1 || ClientName.indexOf("link") > -1 || ClientName === "custom.adapter" && ExitType === "custom") {
129
+ settings.body = Settings;
130
+ settings.body.confirmationFallback = ConfirmationText;
131
+ }
132
+ if (ClientName.indexOf("ace") > -1) {
133
+ settings.body = Settings;
134
+ }
135
+ if (Form && Form.HasValueComponents) {
136
+ if (Validation) {
137
+ settings.body.form = FormBuilder.fromLegacyForm(Id.toString(), Form, Validation).get();
138
+ } else {
139
+ settings.body.form = FormBuilder.fromLegacyForm(Id.toString(), Form).get();
140
+ }
141
+ if (!ExpandFormAutomatically) {
142
+ settings.expanded = settings.inline = false;
143
+ }
144
+ }
145
+ return settings;
146
+ };
147
+ const mapTags = (tags = []) => {
148
+ return tags.map(({ Id, Title, TotalMatches, Symbol: Symbol2, DefaultIcon, ActiveIcon }) => ({
149
+ id: Id.toString(),
150
+ title: Title,
151
+ matches: TotalMatches,
152
+ symbol: convertLegacySymbol(DefaultIcon || Symbol2),
153
+ defaultIcon: convertLegacySymbol(DefaultIcon),
154
+ activeIcon: convertLegacySymbol(ActiveIcon)
155
+ }));
156
+ };
157
+ const mapGuides = (guides) => {
158
+ return guides.map(({ Id, Title, Tags, FirstPublishedDate, Modified }) => ({
159
+ id: Id.toString(),
160
+ title: Title,
161
+ tags: mapTags(Tags),
162
+ published: FirstPublishedDate,
163
+ modified: Modified
164
+ }));
165
+ };
166
+ const formatLegacyData = (type, data) => {
167
+ switch (type) {
168
+ case ServiceClientQueryType.MatchByCategory:
169
+ case ServiceClientQueryType.Match: {
170
+ const result = {
171
+ guides: [],
172
+ matches: 0,
173
+ topNotifications: [],
174
+ middleNotifications: [],
175
+ bottomNotifications: [],
176
+ notificationLists: [],
177
+ tags: [],
178
+ byCategory: []
179
+ };
180
+ const {
181
+ Matches,
182
+ TotalMatches,
183
+ Notices,
184
+ NoticeLists,
185
+ Tags,
186
+ ByCategory
187
+ } = data;
188
+ result.guides = mapGuides(Matches);
189
+ result.matches = TotalMatches;
190
+ result.byCategory = (ByCategory || []).map(({ Id, Matches: Matches2, TotalMatches: TotalMatches2 }) => ({
191
+ id: Id,
192
+ guides: mapGuides(Matches2),
193
+ matches: TotalMatches2
194
+ }));
195
+ result.tags = mapTags(Tags);
196
+ result.notificationLists = mapNotificationLists(NoticeLists || []);
197
+ result.topNotifications = mapNotices(Notices || [], "noticeRowTop");
198
+ result.middleNotifications = mapNotices(Notices || [], "noticeRowMiddle");
199
+ result.bottomNotifications = mapNotices(Notices || [], "footerNotice");
200
+ return result;
201
+ }
202
+ case ServiceClientQueryType.Categories: {
203
+ const { Children, GuidesCountTotal } = data;
204
+ const result = {
205
+ categories: mapLegacyCategoriesRecursively(Children || []),
206
+ matches: GuidesCountTotal
207
+ };
208
+ return result;
209
+ }
210
+ case ServiceClientQueryType.Guide: {
211
+ const {
212
+ Id,
213
+ Title,
214
+ Body,
215
+ Related,
216
+ Options,
217
+ ConnectionId,
218
+ ContactMethods,
219
+ EnableFeedback,
220
+ HandoverExists,
221
+ FirstPublishedDate,
222
+ Modified,
223
+ ModifiedByDisplayName,
224
+ FirstPublishedByDisplayName,
225
+ Categories,
226
+ Tags,
227
+ SeoMetaDescription,
228
+ SeoAllowIndex,
229
+ Perspectives,
230
+ PerspectiveKey,
231
+ Translations
232
+ } = data;
233
+ const perspective = PerspectiveKey || Object.values(Perspectives).find((connection) => connection === ConnectionId) || Perspectives["Default"] || null;
234
+ const result = {
235
+ guide: {
236
+ id: Id.toString(),
237
+ title: Title,
238
+ body: Body,
239
+ modified: Modified,
240
+ published: FirstPublishedDate,
241
+ modifiedBy: ModifiedByDisplayName,
242
+ publishedBy: FirstPublishedByDisplayName,
243
+ connection: ConnectionId,
244
+ categories: Categories,
245
+ hasHandover: HandoverExists,
246
+ allowFeedback: EnableFeedback,
247
+ seoMetaDescription: SeoMetaDescription,
248
+ seoAllowIndex: SeoAllowIndex,
249
+ perspectives: Perspectives,
250
+ perspective,
251
+ translations: Object.keys(Translations || {}).reduce((acc, key) => {
252
+ acc[key] = Translations[key].toString();
253
+ return acc;
254
+ }, {})
255
+ },
256
+ related: mapGuides(Related || []),
257
+ dialog: [],
258
+ contactMethods: (ContactMethods || []).map((cm) => mapContactMethodSettings(cm)),
259
+ tags: mapTags(Tags)
260
+ };
261
+ (Options || []).forEach(({ CanAccess, Description, ConnectionId: ConnectionId2, Properties }) => {
262
+ if (!CanAccess) {
263
+ return;
264
+ }
265
+ const item = {
266
+ id: Id.toString(),
267
+ title: Description,
268
+ connection: ConnectionId2,
269
+ type: DialogItemType.default,
270
+ parent: {
271
+ id: Id.toString(),
272
+ title: Title,
273
+ tags: mapTags(Tags)
274
+ }
275
+ };
276
+ if (Properties.Type === "Guide" || Properties.Type === "Link") {
277
+ Properties.Id && (item.id = Properties.Id.toString());
278
+ Properties.Uri && (item.href = Properties.Uri);
279
+ Properties.Target && (item.target = Properties.Target);
280
+ switch (Properties.Type) {
281
+ case "Guide":
282
+ item.type = DialogItemType.guide;
283
+ break;
284
+ case "Link":
285
+ item.type = DialogItemType.link;
286
+ break;
287
+ }
288
+ }
289
+ result.dialog.push(item);
290
+ });
291
+ return result;
292
+ }
293
+ case ServiceClientQueryType.Contacts: {
294
+ const { Children, Matches, Notices, NoticeLists } = data;
295
+ const result = {
296
+ contactMethods: (Matches || []).map((cm) => mapContactMethodSettings(cm)),
297
+ categories: mapLegacyCategoriesRecursively(Children || []),
298
+ topNotifications: mapNotices(Notices || [], "noticeRowTop"),
299
+ middleNotifications: mapNotices(Notices || [], "noticeRowMiddle"),
300
+ bottomNotifications: mapNotices(Notices || [], "footerNotice"),
301
+ notificationLists: mapNotificationLists(NoticeLists || [])
302
+ };
303
+ return result;
304
+ }
305
+ case ServiceClientQueryType.ContactMethod: {
306
+ const { ContactMethod: ContactMethod2 } = data;
307
+ return mapContactMethodSettings(ContactMethod2 || {});
308
+ }
309
+ case ServiceClientQueryType.Tags:
310
+ case ServiceClientQueryType.TagsOnGuides: {
311
+ return mapTags(data || []);
312
+ }
313
+ case ServiceClientQueryType.Notifications: {
314
+ const { Notices, NoticeLists } = data;
315
+ return {
316
+ topNotifications: mapNotices(Notices || [], "noticeRowTop"),
317
+ middleNotifications: mapNotices(Notices || [], "noticeRowMiddle"),
318
+ bottomNotifications: mapNotices(Notices || [], "footerNotice"),
319
+ notificationLists: mapNotificationLists(NoticeLists || [])
320
+ };
321
+ }
322
+ default:
323
+ return {};
324
+ }
325
+ };
326
+ var DataType = /* @__PURE__ */ ((DataType2) => {
327
+ DataType2["Guide"] = "guide";
328
+ DataType2["Guides"] = "guides";
329
+ DataType2["GuidesByCategory"] = "guides-by-category";
330
+ DataType2["RowNotifications"] = "row-notices";
331
+ DataType2["NotificationLists"] = "notification-lists";
332
+ DataType2["GuideCategories"] = "guide-categories";
333
+ DataType2["ContactMethodCategories"] = "contact-method-categories";
334
+ DataType2["ContactMethod"] = "contact-method";
335
+ DataType2["ContactMethods"] = "contact-methods";
336
+ DataType2["Tags"] = "tags";
337
+ DataType2["TagsOnGuides"] = "tagsonguides";
338
+ return DataType2;
339
+ })(DataType || {});
340
+ var ServiceClientQueryType = /* @__PURE__ */ ((ServiceClientQueryType2) => {
341
+ ServiceClientQueryType2["Match"] = "match";
342
+ ServiceClientQueryType2["Categories"] = "categories";
343
+ ServiceClientQueryType2["Guide"] = "guide";
344
+ ServiceClientQueryType2["Contacts"] = "contacts";
345
+ ServiceClientQueryType2["ContactMethod"] = "contact-method";
346
+ ServiceClientQueryType2["MatchByCategory"] = "match-by-category";
347
+ ServiceClientQueryType2["Tags"] = "tags";
348
+ ServiceClientQueryType2["TagsOnGuides"] = "tagsonguides";
349
+ ServiceClientQueryType2["Notifications"] = "notifications";
350
+ return ServiceClientQueryType2;
351
+ })(ServiceClientQueryType || {});
352
+ var FeedbackType = /* @__PURE__ */ ((FeedbackType2) => {
353
+ FeedbackType2["Positive"] = "Positive";
354
+ FeedbackType2["Negative"] = "Negative";
355
+ return FeedbackType2;
356
+ })(FeedbackType || {});
357
+ var SortingType = /* @__PURE__ */ ((SortingType2) => {
358
+ SortingType2["POPULARITY_DESCENDING"] = "popularity-descending";
359
+ SortingType2["ALPHABETIC_ASCENDING"] = "alphabetic-ascending";
360
+ SortingType2["ALPHABETIC_DESCENDING"] = "alphabetic-descending";
361
+ SortingType2["MODIFIED_ASCENDING"] = "modified-ascending";
362
+ SortingType2["MODIFIED_DESCENDING"] = "modified-descending";
363
+ SortingType2["PUBLISHED_ASCENDING"] = "published-ascending";
364
+ SortingType2["PUBLISHED_DESCENDING"] = "published-descending";
365
+ return SortingType2;
366
+ })(SortingType || {});
367
+ const determineServiceClientQueryType = (type) => {
368
+ switch (type) {
369
+ case "guides":
370
+ return "match";
371
+ case "guides-by-category":
372
+ return "match-by-category";
373
+ case "guide":
374
+ return "guide";
375
+ case "guide-categories":
376
+ return "categories";
377
+ case "contact-method-categories":
378
+ case "contact-methods":
379
+ return "contacts";
380
+ case "contact-method":
381
+ return "contact-method";
382
+ case "tags":
383
+ return "tags";
384
+ case "tagsonguides":
385
+ return "tagsonguides";
386
+ case "notification-lists":
387
+ case "row-notices":
388
+ return "notifications";
389
+ default:
390
+ throw "error";
391
+ }
392
+ };
393
+ const widgetIsHidden = (container) => __async(this, null, function* () {
394
+ const { invoke } = container.get("$widget");
395
+ const renderState = yield invoke("renderState");
396
+ return renderState === WidgetRenderState.hidden;
397
+ });
398
+ class DataClient {
399
+ constructor(container, matchingClient) {
400
+ this.container = container;
401
+ this.matchingClient = matchingClient;
402
+ this.queries = /* @__PURE__ */ new Map();
403
+ this.lastTake = 0;
404
+ this.getUnresolvedQueries = () => {
405
+ let unresolvedCount = 0;
406
+ this.queries.forEach((queries, type) => {
407
+ const hasUnresolved = queries.some((query) => !query.resolved);
408
+ if (hasUnresolved) {
409
+ unresolvedCount = 1;
410
+ }
411
+ });
412
+ return unresolvedCount;
413
+ };
414
+ this.events = container.get("$widget").events;
415
+ this.events.subscribe("widget:settings-updated", () => this.queries = /* @__PURE__ */ new Map());
416
+ this.events.subscribe("widget:render-state-changed", (event, { next, previous }) => {
417
+ if (previous === WidgetRenderState.hidden && next === WidgetRenderState.open) {
418
+ this.fetchAllUnresolvedQueries();
419
+ }
420
+ });
421
+ }
422
+ static getInstance(container) {
423
+ return container.getAsync("dataClient");
424
+ }
425
+ fetch(type, params) {
426
+ return new Promise((resolve, reject) => {
427
+ if (params.take) {
428
+ this.lastTake = +(params.take || 0);
429
+ }
430
+ removeNullAndUndefinedValues(params);
431
+ const serviceClientQueryType = determineServiceClientQueryType(type);
432
+ const queries = this.queries.get(serviceClientQueryType) || [];
433
+ const query = queries.find((q) => shallowCompare(q.params, params));
434
+ if (query) {
435
+ const index = queries.indexOf(query);
436
+ if (query.resolved) {
437
+ this.events.dispatch("data-client:fetched", {
438
+ params,
439
+ type: serviceClientQueryType,
440
+ response: query.data,
441
+ unresolvedQueries: this.getUnresolvedQueries()
442
+ });
443
+ this.track(query.data, serviceClientQueryType, query.error);
444
+ if (query.data && query.error) {
445
+ reject({ error: query.error });
446
+ } else {
447
+ resolve(query.data);
448
+ }
449
+ } else {
450
+ query.resolvers.push({ resolve, reject });
451
+ }
452
+ queries.splice(index, 1);
453
+ queries.push(query);
454
+ this.queries.set(serviceClientQueryType, queries);
455
+ if (!query.loading && !query.resolved) {
456
+ return this.runQuery(serviceClientQueryType, params);
457
+ }
458
+ } else {
459
+ queries.push({
460
+ params,
461
+ resolved: false,
462
+ loading: true,
463
+ data: {},
464
+ resolvers: [{ resolve, reject }]
465
+ });
466
+ this.queries.set(serviceClientQueryType, queries);
467
+ return this.runQuery(serviceClientQueryType, params);
468
+ }
469
+ }).then((res) => deepClone(res));
470
+ }
471
+ read(type, options) {
472
+ const { select } = options;
473
+ const serviceClientQueryType = determineServiceClientQueryType(type);
474
+ const queries = this.queries.get(serviceClientQueryType) || [];
475
+ const result = queries.reduce((acc, query) => {
476
+ if (typeof select === "function") {
477
+ const match = select(query.data);
478
+ if (match) {
479
+ acc.push(match);
480
+ }
481
+ } else {
482
+ acc.push(query.data);
483
+ }
484
+ return acc;
485
+ }, []);
486
+ return result;
487
+ }
488
+ feedback(id, connection, feedback) {
489
+ return this.matchingClient.giveFeedback(id, connection, feedback);
490
+ }
491
+ setLoadingStatus(type, params, loading) {
492
+ const queries = this.queries.get(type) || [];
493
+ const query = queries.find((q) => shallowCompare(q.params, params));
494
+ if (query) {
495
+ query.loading = loading;
496
+ }
497
+ this.queries.set(type, queries);
498
+ }
499
+ runQuery(type, params) {
500
+ return __async(this, null, function* () {
501
+ const {
502
+ searchPhrase = "",
503
+ categories = "0",
504
+ contactMethodCategoryId = "0",
505
+ contactMethodId = "0",
506
+ tagId = void 0,
507
+ take = 5,
508
+ connection = "",
509
+ guideId,
510
+ expandCategories = "descendants",
511
+ currentCategory,
512
+ sorting = "popularity-descending",
513
+ guideIds = []
514
+ } = params;
515
+ const trimmedPhrase = searchPhrase.toString().trim();
516
+ if (yield widgetIsHidden(this.container)) {
517
+ return Promise.resolve();
518
+ }
519
+ switch (type) {
520
+ case "match": {
521
+ const formatSortingValues = (sorting2) => {
522
+ const [type2, direction] = sorting2.split("-");
523
+ const sortKeysMap = /* @__PURE__ */ new Map([
524
+ ["popularity", "popularity"],
525
+ ["alphabetic", "title"],
526
+ ["modified", "lastModified"],
527
+ ["published", "firstPublished"]
528
+ ]);
529
+ return {
530
+ type: sortKeysMap.get(type2),
531
+ direction
532
+ };
533
+ };
534
+ if (guideIds.length) {
535
+ return this.matchingClient.customRequest("guides", "POST", {
536
+ configuration: { ids: guideIds, take: +take }
537
+ }).then((matches) => matches && this.handleResponse(matches, type, params));
538
+ }
539
+ return this.matchingClient.match(trimmedPhrase, {
540
+ categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories],
541
+ take: +take,
542
+ tags: tagId,
543
+ sorting: formatSortingValues(sorting),
544
+ ids: guideIds
545
+ }).then((matches) => matches && this.handleResponse(matches, type, params));
546
+ }
547
+ case "match-by-category": {
548
+ return this.matchingClient.match(trimmedPhrase, {
549
+ groupByCategory: true,
550
+ categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories],
551
+ take: +take,
552
+ tags: tagId
553
+ }).then((matches) => matches && this.handleResponse(matches, type, params));
554
+ }
555
+ case "guide": {
556
+ return this.matchingClient.getGuide(guideId, { connectionId: connection }).then((guide) => {
557
+ if (guide) {
558
+ this.handleResponse(guide, type, params);
559
+ }
560
+ }).catch((e) => {
561
+ const error = {
562
+ message: "Something went wrong.",
563
+ status: e.status || 400
564
+ };
565
+ if (error.status === 404) {
566
+ error.message = "The guide could not be found.";
567
+ }
568
+ this.handleResponse({}, type, params, error);
569
+ });
570
+ }
571
+ case "categories": {
572
+ return this.matchingClient.getCategories({ phrase: trimmedPhrase, expand: expandCategories, tags: tagId }).then((categories2) => categories2 && this.handleResponse(categories2, type, params));
573
+ }
574
+ case "contacts": {
575
+ if (guideId) {
576
+ return this.matchingClient.contactMethods(+guideId, { phrase: trimmedPhrase }).then((result) => result && this.handleResponse(result, type, params));
577
+ }
578
+ return this.matchingClient.contacts(+contactMethodCategoryId, { phrase: trimmedPhrase }).then((result) => result && this.handleResponse(result, type, params));
579
+ }
580
+ case "contact-method": {
581
+ return this.matchingClient.getContactMethod(+contactMethodId, { guideId, currentCategory }).then((result) => result && this.handleResponse(result, type, params));
582
+ }
583
+ case "tags": {
584
+ return this.matchingClient.customRequest("tags", "GET", {
585
+ configuration: {
586
+ take: 999999,
587
+ phrase: trimmedPhrase,
588
+ categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories]
589
+ }
590
+ }).then((result) => result && this.handleResponse(result, type, params));
591
+ }
592
+ case "tagsonguides": {
593
+ return this.matchingClient.customRequest("tagsonguides", "GET", {
594
+ configuration: {
595
+ take: 999999,
596
+ phrase: trimmedPhrase,
597
+ categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories],
598
+ tags: tagId
599
+ }
600
+ }).then((result) => result && this.handleResponse(result, type, params));
601
+ }
602
+ case "notifications": {
603
+ return this.matchingClient.customRequest("notices", "GET", {
604
+ configuration: {
605
+ phrase: trimmedPhrase,
606
+ categories: categories === "0" ? [] : Array.isArray(categories) ? categories : [+categories]
607
+ }
608
+ }).then((result) => result && this.handleResponse(result, type, params));
609
+ }
610
+ }
611
+ });
612
+ }
613
+ handleResponse(data = {}, type, params, error) {
614
+ const queries = this.queries.get(type) || [];
615
+ const existing = queries.find((q) => shallowCompare(q.params, params));
616
+ if (existing) {
617
+ const formatted = error ? error : formatLegacyData(type, data);
618
+ this.track(formatted, type, error);
619
+ existing.resolvers.forEach((r) => {
620
+ if (error) {
621
+ r.reject({ error: formatted });
622
+ } else {
623
+ r.resolve(formatted);
624
+ }
625
+ });
626
+ const index = queries.indexOf(existing);
627
+ if (index > -1) {
628
+ queries.splice(index, 1);
629
+ }
630
+ queries.push(__spreadProps(__spreadValues({}, existing), { error, resolvers: [], data: formatted, resolved: true }));
631
+ this.setLoadingStatus(type, params, false);
632
+ this.queries.set(type, queries);
633
+ if (!error) {
634
+ this.events.dispatch("data-client:fetched", {
635
+ type,
636
+ params,
637
+ response: formatted,
638
+ unresolvedQueries: this.getUnresolvedQueries()
639
+ });
640
+ }
641
+ }
642
+ }
643
+ fetchAllUnresolvedQueries() {
644
+ for (const [queryType, queries] of this.queries) {
645
+ queries.filter((query) => !query.resolved).forEach((query) => {
646
+ this.runQuery(queryType, query.params);
647
+ });
648
+ }
649
+ }
650
+ track(data = {}, type, error) {
651
+ const widget = this.container.get("$widget");
652
+ if (widget && !error) {
653
+ widget.events.dispatch("tracking:service-client-response", {
654
+ type,
655
+ data
656
+ });
657
+ } else if (widget) {
658
+ widget.events.dispatch("tracking:service-client-error", {
659
+ type,
660
+ error
661
+ });
662
+ }
663
+ }
664
+ static create(container) {
665
+ return container.getAsync("matchingClient").then((matchingClient) => new DataClient(container, matchingClient));
666
+ }
667
+ }
668
+ const createContactMethodPlatform = (container) => {
669
+ return import("@telia-ace/knowledge-widget-adapters").then(({ ContactMethodPlatform }) => {
670
+ return ContactMethodPlatform.create(container);
671
+ });
672
+ };
673
+ const createDataClient = (container) => {
674
+ return import("./index2.js").then(({ DataClient: DataClient2 }) => {
675
+ return DataClient2.create(container);
676
+ });
677
+ };
678
+ class ExtendedWidget extends Widget {
679
+ constructor(container) {
680
+ super(container);
681
+ this.container.registerAsync("contactMethods", () => createContactMethodPlatform(this.container));
682
+ this.container.registerAsync("dataClient", () => createDataClient(this.container));
683
+ }
684
+ }
685
+ export { DataClient, DataType, FeedbackType, ExtendedWidget as GridWidget, ServiceClientQueryType, SortingType, determineServiceClientQueryType, formatLegacyData };
686
+ //# sourceMappingURL=index.js.map