@telia-ace/knowledge-data-client-flamingo 1.0.23 → 1.0.43

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.
package/dist/index.js DELETED
@@ -1,982 +0,0 @@
1
- var ce = Object.defineProperty, de = Object.defineProperties;
2
- var le = Object.getOwnPropertyDescriptors;
3
- var V = Object.getOwnPropertySymbols;
4
- var ge = Object.prototype.hasOwnProperty, ue = Object.prototype.propertyIsEnumerable;
5
- var Y = (n, e, t) => e in n ? ce(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, Z = (n, e) => {
6
- for (var t in e || (e = {}))
7
- ge.call(e, t) && Y(n, t, e[t]);
8
- if (V)
9
- for (var t of V(e))
10
- ue.call(e, t) && Y(n, t, e[t]);
11
- return n;
12
- }, J = (n, e) => de(n, le(e));
13
- var x = (n, e, t) => new Promise((s, i) => {
14
- var o = (c) => {
15
- try {
16
- r(t.next(c));
17
- } catch (d) {
18
- i(d);
19
- }
20
- }, a = (c) => {
21
- try {
22
- r(t.throw(c));
23
- } catch (d) {
24
- i(d);
25
- }
26
- }, r = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(o, a);
27
- r((t = t.apply(n, e)).next());
28
- });
29
- const D = (n, e, t, ...s) => {
30
- const i = `[${n.get("$environment").name || "webprovisions"}] ${t}`;
31
- switch (e) {
32
- case "info":
33
- console.info(i, ...s);
34
- break;
35
- case "warning":
36
- console.warn(i, ...s);
37
- break;
38
- case "error":
39
- console.error(i, ...s);
40
- break;
41
- }
42
- }, he = (n) => {
43
- const e = n.container || n;
44
- return {
45
- info: (t, ...s) => D(e, "info", t, ...s),
46
- warn: (t, ...s) => D(e, "warning", t, ...s),
47
- error: (t, ...s) => D(e, "error", t, ...s)
48
- };
49
- };
50
- var R = /* @__PURE__ */ ((n) => (n.Implementation = "implementation", n.Widget = "widget", n))(R || {}), w = /* @__PURE__ */ ((n) => (n.Pre = "pre", n.Post = "post", n))(w || {});
51
- const me = (n, e, t, s) => {
52
- try {
53
- const i = new e(t, s);
54
- return {
55
- name: n,
56
- invoke: (o, a) => {
57
- let r;
58
- return i[o] && (r = i[o].call(i, a)), Promise.resolve(r);
59
- },
60
- getInstance: () => i
61
- };
62
- } catch (i) {
63
- if (i.message && i.message.indexOf("is not a constructor") >= 0)
64
- return {
65
- name: n,
66
- invoke: (o) => {
67
- let a;
68
- return o === "initialize" && (a = e(t, s)), Promise.resolve(a);
69
- },
70
- getInstance: () => e
71
- };
72
- throw i;
73
- }
74
- };
75
- function X(n, e) {
76
- return typeof n == "undefined" ? e : n;
77
- }
78
- let fe = class {
79
- constructor(n = {}) {
80
- this.part = n;
81
- }
82
- createCommand(n, e, t) {
83
- let s;
84
- typeof e == "function" ? s = {
85
- scope: R.Widget,
86
- stage: w.Post,
87
- defaultArgs: void 0,
88
- handlerResolver: e
89
- } : s = {
90
- scope: X(e.scope, R.Widget),
91
- stage: X(e.stage, w.Post),
92
- defaultArgs: e.defaultArgs,
93
- handlerResolver: t
94
- };
95
- let i = this.part;
96
- const o = n.split(".");
97
- return o.forEach((a, r) => {
98
- r === o.length - 1 ? i[a] || (i[a] = () => s) : i = this.part[a] = this.part[a] || {};
99
- }), this;
100
- }
101
- get() {
102
- return this.part;
103
- }
104
- };
105
- const se = (n) => {
106
- const e = new fe({});
107
- return n(e), e.get();
108
- };
109
- se((n) => {
110
- n.createCommand(
111
- "types.register",
112
- { scope: R.Implementation, stage: w.Pre },
113
- (e) => (t, s) => {
114
- e.container.get("$types")[t] = s;
115
- }
116
- ).createCommand(
117
- "type",
118
- { stage: w.Pre },
119
- (e) => (t) => {
120
- e.container.register("$type", t);
121
- }
122
- ).createCommand(
123
- "settings",
124
- { stage: w.Pre, defaultArgs: [null] },
125
- (e) => (t) => {
126
- e.events.dispatch(
127
- "settings:change",
128
- t,
129
- { bubbles: !0 }
130
- ), e.container.register("$settings", t);
131
- }
132
- ).createCommand(
133
- "plugin",
134
- { stage: w.Pre },
135
- (e) => (t, s, i) => {
136
- const { container: o } = e;
137
- let a = null, r = t, c = s;
138
- typeof t == "string" && (a = t, r = s, c = i);
139
- const d = (g) => {
140
- const { transformPluginSettings: m } = e.container.get("$environmentOptions"), u = m ? m(
141
- c || {},
142
- a,
143
- e.container,
144
- r
145
- ) : s;
146
- try {
147
- const h = me(
148
- a,
149
- r,
150
- o,
151
- u
152
- );
153
- o.get("$plugins").push(h), g && h.invoke("initialize", null);
154
- } catch (h) {
155
- he(e).warn("Error when initializing plugin", h);
156
- }
157
- };
158
- e.container.get("$instance") ? d(!0) : e.events.subscribeOnce("widget:instance-created", () => d(!1));
159
- }
160
- ).createCommand(
161
- "container.register",
162
- (e) => (t, s) => {
163
- e.container.register(t, s);
164
- }
165
- ).createCommand(
166
- "container.registerAsync",
167
- (e) => (t, s) => {
168
- e.container.registerAsync(t, s);
169
- }
170
- ).createCommand(
171
- "container.registerFactory",
172
- (e) => (t, s) => {
173
- e.container.registerFactory(t, s);
174
- }
175
- ).createCommand(
176
- "container.touch",
177
- (e) => (t, s) => {
178
- e.container.touch(t, s);
179
- }
180
- ).createCommand(
181
- "csp",
182
- {},
183
- (e) => (t) => {
184
- e.container.register("csp", t);
185
- }
186
- );
187
- });
188
- se((n) => {
189
- n.createCommand(
190
- "ready",
191
- { scope: R.Implementation, stage: w.Pre },
192
- (e) => (t) => {
193
- const { container: s } = e, i = s.owner;
194
- s.get("bootstrapping").ready ? t(i) : i.events.subscribeOnce("bootstrap:ready", () => {
195
- t(i);
196
- });
197
- }
198
- );
199
- });
200
- const U = (n, e, t, ...s) => {
201
- const i = `[${n.get("$environment").name || "webprovisions"}] ${t}`;
202
- switch (e) {
203
- case "info":
204
- console.info(i, ...s);
205
- break;
206
- case "warning":
207
- console.warn(i, ...s);
208
- break;
209
- case "error":
210
- console.error(i, ...s);
211
- break;
212
- }
213
- }, pe = (n) => {
214
- const e = n.container || n;
215
- return {
216
- info: (t, ...s) => U(e, "info", t, ...s),
217
- warn: (t, ...s) => U(e, "warning", t, ...s),
218
- error: (t, ...s) => U(e, "error", t, ...s)
219
- };
220
- };
221
- var T = /* @__PURE__ */ ((n) => (n.Implementation = "implementation", n.Widget = "widget", n))(T || {}), N = /* @__PURE__ */ ((n) => (n.Pre = "pre", n.Post = "post", n))(N || {});
222
- const ye = (n, e, t, s) => {
223
- try {
224
- const i = new e(t, s);
225
- return {
226
- name: n,
227
- invoke: (o, a) => {
228
- let r;
229
- return i[o] && (r = i[o].call(i, a)), Promise.resolve(r);
230
- },
231
- getInstance: () => i
232
- };
233
- } catch (i) {
234
- if (i.message && i.message.indexOf("is not a constructor") >= 0)
235
- return {
236
- name: n,
237
- invoke: (o) => {
238
- let a;
239
- return o === "initialize" && (a = e(t, s)), Promise.resolve(a);
240
- },
241
- getInstance: () => e
242
- };
243
- throw i;
244
- }
245
- };
246
- function ee(n, e) {
247
- return typeof n == "undefined" ? e : n;
248
- }
249
- class ve {
250
- constructor(e = {}) {
251
- this.part = e;
252
- }
253
- createCommand(e, t, s) {
254
- let i;
255
- typeof t == "function" ? i = {
256
- scope: T.Widget,
257
- stage: N.Post,
258
- defaultArgs: void 0,
259
- handlerResolver: t
260
- } : i = {
261
- scope: ee(t.scope, T.Widget),
262
- stage: ee(t.stage, N.Post),
263
- defaultArgs: t.defaultArgs,
264
- handlerResolver: s
265
- };
266
- let o = this.part;
267
- const a = e.split(".");
268
- return a.forEach((r, c) => {
269
- c === a.length - 1 ? o[r] || (o[r] = () => i) : o = this.part[r] = this.part[r] || {};
270
- }), this;
271
- }
272
- get() {
273
- return this.part;
274
- }
275
- }
276
- const ie = (n) => {
277
- const e = new ve({});
278
- return n(e), e.get();
279
- };
280
- ie((n) => {
281
- n.createCommand(
282
- "types.register",
283
- { scope: T.Implementation, stage: N.Pre },
284
- (e) => (t, s) => {
285
- e.container.get("$types")[t] = s;
286
- }
287
- ).createCommand(
288
- "type",
289
- { stage: N.Pre },
290
- (e) => (t) => {
291
- e.container.register("$type", t);
292
- }
293
- ).createCommand(
294
- "settings",
295
- { stage: N.Pre, defaultArgs: [null] },
296
- (e) => (t) => {
297
- e.events.dispatch(
298
- "settings:change",
299
- t,
300
- { bubbles: !0 }
301
- ), e.container.register("$settings", t);
302
- }
303
- ).createCommand(
304
- "plugin",
305
- { stage: N.Pre },
306
- (e) => (t, s, i) => {
307
- const { container: o } = e;
308
- let a = null, r = t, c = s;
309
- typeof t == "string" && (a = t, r = s, c = i);
310
- const d = (g) => {
311
- const { transformPluginSettings: m } = e.container.get("$environmentOptions"), u = m ? m(
312
- c || {},
313
- a,
314
- e.container,
315
- r
316
- ) : s;
317
- try {
318
- const h = ye(
319
- a,
320
- r,
321
- o,
322
- u
323
- );
324
- o.get("$plugins").push(h), g && h.invoke("initialize", null);
325
- } catch (h) {
326
- pe(e).warn("Error when initializing plugin", h);
327
- }
328
- };
329
- e.container.get("$instance") ? d(!0) : e.events.subscribeOnce("widget:instance-created", () => d(!1));
330
- }
331
- ).createCommand(
332
- "container.register",
333
- (e) => (t, s) => {
334
- e.container.register(t, s);
335
- }
336
- ).createCommand(
337
- "container.registerAsync",
338
- (e) => (t, s) => {
339
- e.container.registerAsync(t, s);
340
- }
341
- ).createCommand(
342
- "container.registerFactory",
343
- (e) => (t, s) => {
344
- e.container.registerFactory(t, s);
345
- }
346
- ).createCommand(
347
- "container.touch",
348
- (e) => (t, s) => {
349
- e.container.touch(t, s);
350
- }
351
- ).createCommand(
352
- "csp",
353
- {},
354
- (e) => (t) => {
355
- e.container.register("csp", t);
356
- }
357
- );
358
- });
359
- ie((n) => {
360
- n.createCommand("components", (e) => (t) => {
361
- e.events.subscribeOnce(
362
- "components:platform-created",
363
- (s, { platform: i }) => {
364
- t.handlers && t.handlers.forEach(([o, a]) => {
365
- i.addComponentHandler(o, a);
366
- });
367
- }
368
- );
369
- });
370
- });
371
- var L = /* @__PURE__ */ ((n) => (n.open = "open", n.closed = "closed", n.hidden = "hidden", n))(L || {});
372
- const j = (n, e, ...t) => typeof e == "string" ? n(`[humany] ${e}`, ...t) : n(e, ...t), M = class {
373
- constructor() {
374
- this.keys = [], this.log = (n, ...e) => this.lookup(n, () => M.log(...e)), this.warn = (n, ...e) => this.lookup(n, () => M.warn(...e)), this.error = (n, ...e) => this.lookup(n, () => M.error(...e)), this.info = (n, ...e) => this.lookup(n, () => M.info(...e));
375
- }
376
- lookup(n, e) {
377
- this.keys.indexOf(n) === -1 && (this.keys.push(n), e());
378
- }
379
- };
380
- let S = M;
381
- S.log = (...n) => j(console.log, ...n);
382
- S.warn = (...n) => j(console.warn, ...n);
383
- S.error = (...n) => j(console.error, ...n);
384
- S.info = (...n) => j(console.info, ...n);
385
- const oe = (n) => {
386
- let e = {}, t, s;
387
- if (typeof n != "object" || n === null)
388
- return n;
389
- e = Array.isArray(n) ? [] : {};
390
- for (s in n)
391
- t = n[s], e[s] = typeof t == "object" && t !== null ? oe(t) : t;
392
- return e;
393
- }, Ce = oe;
394
- class be {
395
- constructor(e, t) {
396
- this.lockWarningTime = e, this.lockErrorTime = t, this.tasks = [], this.current = Promise.resolve(), this.next = this.next.bind(this);
397
- }
398
- add(e, t, s, i) {
399
- this.tasks.push({ task: e, resolve: t, reject: s, done: i }), this.next();
400
- }
401
- next() {
402
- this.current = this.current.then(() => {
403
- const e = this.tasks.shift();
404
- if (e) {
405
- let t;
406
- const s = setTimeout(() => {
407
- process.env.NODE_ENV !== "production" && S.warn(
408
- `A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,
409
- e
410
- ), t = setTimeout(() => {
411
- e.reject("lock timeout exceeded");
412
- }, this.lockErrorTime);
413
- }, this.lockWarningTime), i = Promise.resolve(e.task()).then((o) => (clearTimeout(s), clearTimeout(t), o));
414
- return Promise.resolve(i).then(this.next).then(
415
- () => i.then((o) => {
416
- e.done(), e.resolve(o);
417
- })
418
- ).catch((o) => (e.done(), e.reject(o), this.next()));
419
- }
420
- return Promise.resolve();
421
- });
422
- }
423
- }
424
- const q = /* @__PURE__ */ new WeakMap();
425
- function we(n, e = 5e3, t = 1e3) {
426
- return q.has(n) || q.set(n, new be(e, t)), (s) => new Promise((i, o) => {
427
- const a = q.get(n);
428
- a.add(s, i, o, () => {
429
- a.tasks.length || q.delete(n);
430
- });
431
- });
432
- }
433
- const ke = (n = {}) => (Object.keys(n).forEach((e) => {
434
- (n[e] === null || typeof n[e] == "undefined") && delete n[e];
435
- }), n), Ne = ke, G = (n, e) => {
436
- let t = !0;
437
- return Object.keys(n).length !== Object.keys(e).length || Object.keys(n).some((s) => !Object.keys(e).some((i) => s === i)) ? !1 : (Object.keys(n).forEach((s) => {
438
- if (t) {
439
- const i = typeof n[s] == "undefined" ? "" : n[s], o = typeof e[s] == "undefined" ? "" : e[s];
440
- t = i.toString() === o.toString();
441
- }
442
- }), t);
443
- }, te = (n) => import("./index-d70f1e69.js").then(
444
- ({ ServiceClient: e, ServiceProxy: t }) => n.get("settings").then((s) => {
445
- const { name: i, events: o } = n.get("$widget"), {
446
- data: { projection: a = "", site: r = "current", forceHttps: c = !1 }
447
- } = s, d = new t(a, {
448
- credentials: "same-origin"
449
- }), g = new e(
450
- d,
451
- {
452
- funnel: i.replace("_contact-method", "").replace("_contact", ""),
453
- site: Ae(r, c)
454
- },
455
- null,
456
- n
457
- );
458
- return o.subscribe("widget:settings-updated", (m, { data: u }) => {
459
- u && u.projection !== a && g.proxy.setBaseUrl(u.projection);
460
- }), g;
461
- })
462
- ), Ae = (n, e) => () => {
463
- const t = (i) => {
464
- const o = document.createElement("a");
465
- return o.href = i, o;
466
- };
467
- let s = window.location;
468
- return n === "referrer" && document.referrer && (s = t(document.referrer)), [
469
- e ? "https:" : "",
470
- "//",
471
- s.host,
472
- s.pathname
473
- ].join("");
474
- }, A = (n) => {
475
- if (n) {
476
- const { Type: e, Content: t } = n;
477
- if (e && t)
478
- return { type: e, content: t };
479
- }
480
- }, W = (n) => n.map((e) => {
481
- const t = {
482
- id: e.Id.toString(),
483
- title: e.Name,
484
- symbol: A(e.DefaultIcon),
485
- activeSymbol: e.ActiveIcon && A(e.ActiveIcon),
486
- description: e.Description || e.Attributes && e.Attributes.description || "",
487
- matches: e.GuidesCount
488
- };
489
- return e.Children && e.Children.length && (t.items = W(e.Children)), t;
490
- }), C = (n, e) => n.filter(({ Type: t }) => t === e).map(({ Id: t, Title: s, Body: i }) => ({
491
- id: t.toString(),
492
- title: s,
493
- body: i
494
- })), H = (n) => n.map(({ Id: e, Title: t, DefaultIcon: s, ListNotices: i, Notices: o }) => ({
495
- id: e.toString(),
496
- title: t,
497
- symbol: A(s),
498
- defaultHeaderOptions: {
499
- visible: !!i.length
500
- },
501
- notifications: (i || []).concat(o || []).map(({ Id: a, Title: r, Body: c, Type: d, Modified: g }) => ({
502
- id: a.toString(),
503
- title: r,
504
- body: c,
505
- modified: g,
506
- expandable: d === "listNotice"
507
- }))
508
- })), _ = ({
509
- Id: n,
510
- Title: e,
511
- DefaultIcon: t,
512
- Exits: [s],
513
- ExitType: i,
514
- ConfirmationText: o,
515
- Description: a
516
- }, r) => {
517
- const { Adapter: c } = s || { Adapter: {} }, { ClientName: d = "", Settings: g = {}, CustomClientName: m = "" } = c, u = {
518
- id: n.toString(),
519
- title: e,
520
- description: a,
521
- symbol: A(t),
522
- clientName: d === "custom.adapter" ? m : d,
523
- expanded: !0,
524
- inline: !0,
525
- body: {}
526
- };
527
- if (d.indexOf("phone") > -1 || d.indexOf("freetext") > -1) {
528
- const { displayTextBeforeClick: h, textBeforeClick: k } = g;
529
- h === "true" && (u.expanded = !1, u.title = k), d.indexOf("phone.text") > -1 ? u.body.phoneNumber = g.phoneNumber : u.body.freetext = g.freetext;
530
- }
531
- return (d.indexOf("chat.popup") > -1 || d.indexOf("link") > -1 || d === "custom.adapter" && i === "custom") && (u.body = g, u.body.confirmationFallback = o), d.indexOf("ace") > -1 && (u.body = g), u;
532
- }, P = (n = []) => n.map(
533
- ({ Id: e, Title: t, TotalMatches: s, Symbol: i, DefaultIcon: o, ActiveIcon: a }) => ({
534
- id: e.toString(),
535
- title: t,
536
- matches: s,
537
- symbol: A(o || i),
538
- defaultIcon: A(o),
539
- activeIcon: A(a)
540
- })
541
- ), F = (n) => n.map(({ Id: e, Title: t, Tags: s, FirstPublishedDate: i, Modified: o }) => ({
542
- id: e.toString(),
543
- title: t,
544
- tags: P(s),
545
- published: i,
546
- modified: o
547
- })), Ie = (n, e) => {
548
- switch (n) {
549
- case v.MatchByCategory:
550
- case v.Match: {
551
- const t = {
552
- guides: [],
553
- matches: 0,
554
- topNotifications: [],
555
- middleNotifications: [],
556
- bottomNotifications: [],
557
- notificationLists: [],
558
- tags: [],
559
- byCategory: []
560
- }, {
561
- Matches: s,
562
- TotalMatches: i,
563
- Notices: o,
564
- NoticeLists: a,
565
- Tags: r,
566
- ByCategory: c
567
- } = e;
568
- return t.guides = F(s), t.matches = i, t.byCategory = (c || []).map(
569
- ({ Id: d, Matches: g, TotalMatches: m }) => ({
570
- id: d,
571
- guides: F(g),
572
- matches: m
573
- })
574
- ), t.tags = P(r), t.notificationLists = H(a || []), t.topNotifications = C(o || [], "noticeRowTop"), t.middleNotifications = C(o || [], "noticeRowMiddle"), t.bottomNotifications = C(o || [], "footerNotice"), t;
575
- }
576
- case v.Categories: {
577
- const { Children: t, GuidesCountTotal: s } = e;
578
- return {
579
- categories: W(t || []),
580
- matches: s
581
- };
582
- }
583
- case v.Guide: {
584
- const {
585
- Id: t,
586
- Title: s,
587
- Body: i,
588
- Related: o,
589
- Options: a,
590
- ConnectionId: r,
591
- ContactMethods: c,
592
- EnableFeedback: d,
593
- HandoverExists: g,
594
- FirstPublishedDate: m,
595
- Modified: u,
596
- ModifiedByDisplayName: h,
597
- FirstPublishedByDisplayName: k,
598
- Categories: p,
599
- Tags: l,
600
- SeoMetaDescription: f,
601
- SeoAllowIndex: B,
602
- Perspectives: E,
603
- PerspectiveKey: z,
604
- Translations: K
605
- } = e, re = z || Object.values(E).find(
606
- (b) => b === r
607
- ) || E.Default || null, Q = {
608
- guide: {
609
- id: t.toString(),
610
- title: s,
611
- body: i,
612
- modified: u,
613
- published: m,
614
- modifiedBy: h,
615
- publishedBy: k,
616
- connection: r,
617
- categories: p,
618
- hasHandover: g,
619
- allowFeedback: d,
620
- seoMetaDescription: f,
621
- seoAllowIndex: B,
622
- perspectives: E,
623
- perspective: re,
624
- translations: Object.keys(K || {}).reduce((b, $) => (b[$] = K[$].toString(), b), {})
625
- },
626
- related: F(o || []),
627
- dialog: [],
628
- contactMethods: (c || []).map(
629
- (b) => _(b)
630
- ),
631
- tags: P(l)
632
- };
633
- return (a || []).forEach(
634
- ({ CanAccess: b, Description: $, ConnectionId: ae, Properties: y }) => {
635
- if (!b)
636
- return;
637
- const I = {
638
- id: t.toString(),
639
- title: $,
640
- connection: ae,
641
- connectionKey: y.ConnectionKey,
642
- type: "default",
643
- parent: {
644
- id: t.toString(),
645
- title: s,
646
- tags: P(l)
647
- }
648
- };
649
- if (y.Type === "Guide" || y.Type === "Link")
650
- switch (y.Id && (I.id = y.Id.toString()), y.Uri && (I.href = y.Uri), y.Target && (I.target = y.Target), y.Type) {
651
- case "Guide":
652
- I.type = "guide";
653
- break;
654
- case "Link":
655
- I.type = "link";
656
- break;
657
- }
658
- Q.dialog.push(I);
659
- }
660
- ), Q;
661
- }
662
- case v.Contacts: {
663
- const {
664
- Children: t,
665
- Matches: s,
666
- Notices: i,
667
- NoticeLists: o
668
- } = e;
669
- return {
670
- contactMethods: (s || []).map(
671
- (r) => _(r)
672
- ),
673
- categories: W(t || []),
674
- topNotifications: C(i || [], "noticeRowTop"),
675
- middleNotifications: C(i || [], "noticeRowMiddle"),
676
- bottomNotifications: C(i || [], "footerNotice"),
677
- notificationLists: H(o || [])
678
- };
679
- }
680
- case v.ContactMethod: {
681
- const { ContactMethod: t } = e;
682
- return _(t || {});
683
- }
684
- case v.Tags:
685
- case v.TagsOnGuides:
686
- return P(e || []);
687
- case v.Notifications: {
688
- const { Notices: t, NoticeLists: s } = e;
689
- return {
690
- topNotifications: C(t || [], "noticeRowTop"),
691
- middleNotifications: C(t || [], "noticeRowMiddle"),
692
- bottomNotifications: C(t || [], "footerNotice"),
693
- notificationLists: H(s || [])
694
- };
695
- }
696
- default:
697
- return {};
698
- }
699
- };
700
- var xe = /* @__PURE__ */ ((n) => (n.Guide = "guide", n.Guides = "guides", n.GuidesByCategory = "guides-by-category", n.RowNotifications = "row-notices", n.NotificationLists = "notification-lists", n.GuideCategories = "guide-categories", n.ContactMethodCategories = "contact-method-categories", n.ContactMethod = "contact-method", n.ContactMethods = "contact-methods", n.Tags = "tags", n.TagsOnGuides = "tagsonguides", n))(xe || {}), v = /* @__PURE__ */ ((n) => (n.Match = "match", n.Categories = "categories", n.Guide = "guide", n.Contacts = "contacts", n.ContactMethod = "contact-method", n.MatchByCategory = "match-by-category", n.Tags = "tags", n.TagsOnGuides = "tagsonguides", n.Notifications = "notifications", n))(v || {}), Ee = /* @__PURE__ */ ((n) => (n.Positive = "Positive", n.Negative = "Negative", n))(Ee || {}), Me = /* @__PURE__ */ ((n) => (n.POPULARITY_DESCENDING = "popularity-descending", n.ALPHABETIC_ASCENDING = "alphabetic-ascending", n.ALPHABETIC_DESCENDING = "alphabetic-descending", n.MODIFIED_ASCENDING = "modified-ascending", n.MODIFIED_DESCENDING = "modified-descending", n.PUBLISHED_ASCENDING = "published-ascending", n.PUBLISHED_DESCENDING = "published-descending", n))(Me || {});
701
- const ne = (n) => {
702
- switch (n) {
703
- case "guides":
704
- return "match";
705
- case "guides-by-category":
706
- return "match-by-category";
707
- case "guide":
708
- return "guide";
709
- case "guide-categories":
710
- return "categories";
711
- case "contact-method-categories":
712
- case "contact-methods":
713
- return "contacts";
714
- case "contact-method":
715
- return "contact-method";
716
- case "tags":
717
- return "tags";
718
- case "tagsonguides":
719
- return "tagsonguides";
720
- case "notification-lists":
721
- case "row-notices":
722
- return "notifications";
723
- default:
724
- throw "error";
725
- }
726
- }, Pe = (n) => x(void 0, null, function* () {
727
- const { invoke: e } = n.get("$widget");
728
- return (yield e("renderState")) === L.hidden;
729
- });
730
- class O {
731
- constructor(e, t) {
732
- this.container = e, this.matchingClient = t, this.queries = /* @__PURE__ */ new Map(), this.getUnresolvedQueries = () => {
733
- let s = 0;
734
- return this.queries.forEach((i, o) => {
735
- i.some((r) => !r.resolved) && (s = 1);
736
- }), s;
737
- }, this.events = e.get("$widget").events, this.events.subscribe(
738
- "widget:settings-updated",
739
- () => this.queries = /* @__PURE__ */ new Map()
740
- ), this.events.subscribe(
741
- "widget:render-state-changed",
742
- (s, { next: i, previous: o }) => {
743
- o === L.hidden && i === L.open && this.fetchAllUnresolvedQueries();
744
- }
745
- );
746
- }
747
- static getInstance(e, t = "dataClient") {
748
- return we(this)(() => e.getAsync(t).then((s) => x(this, null, function* () {
749
- let i = yield e.getAsync("matchingClient");
750
- i || (i = yield te(e), e.registerAsync("matchingClient", () => i));
751
- let o = s;
752
- return o || (o = new O(e, i), e.registerAsync(t, () => o)), o;
753
- })));
754
- }
755
- fetch(e, t, s) {
756
- return new Promise((i, o) => {
757
- t.take, Ne(t);
758
- const a = ne(e);
759
- let r = this.queries.get(a) || [], c = r.find((d) => G(d.params, t)) || null;
760
- if (c && (s != null && s.noCache)) {
761
- const d = r.findIndex(
762
- (g) => G(g.params, t)
763
- );
764
- r = [...r.slice(0, d), ...r.slice(d + 1)], c = null;
765
- }
766
- if (c) {
767
- const d = r.indexOf(c);
768
- if (c.resolved ? (this.events.dispatch("data-client:fetched", {
769
- params: t,
770
- type: a,
771
- response: c.data,
772
- unresolvedQueries: this.getUnresolvedQueries()
773
- }), this.track(c.data, a, c.error), c.data && c.error ? o({ error: c.error }) : i(c.data)) : c.resolvers.push({ resolve: i, reject: o }), r.splice(d, 1), r.push(c), this.queries.set(a, r), !c.loading && !c.resolved)
774
- return this.runQuery(a, t);
775
- } else
776
- return r.push({
777
- params: t,
778
- resolved: !1,
779
- loading: !0,
780
- data: {},
781
- resolvers: [{ resolve: i, reject: o }]
782
- }), this.queries.set(a, r), this.runQuery(a, t);
783
- }).then((i) => Ce(i));
784
- }
785
- // query the cached data
786
- read(e, t) {
787
- const { select: s } = t, i = ne(e);
788
- return (this.queries.get(i) || []).reduce((r, c) => {
789
- if (typeof s == "function") {
790
- const d = s(c.data);
791
- d && r.push(d);
792
- } else
793
- r.push(c.data);
794
- return r;
795
- }, []);
796
- }
797
- feedback(e, t, s) {
798
- return this.matchingClient.giveFeedback(e, t, s);
799
- }
800
- setLoadingStatus(e, t, s) {
801
- const i = this.queries.get(e) || [], o = i.find((a) => G(a.params, t));
802
- o && (o.loading = s), this.queries.set(e, i);
803
- }
804
- runQuery(e, t) {
805
- return x(this, null, function* () {
806
- const {
807
- searchPhrase: s = "",
808
- categories: i = "0",
809
- contactMethodCategoryId: o = "0",
810
- contactMethodId: a = "0",
811
- tagId: r = void 0,
812
- take: c = 5,
813
- connection: d = "",
814
- guideId: g,
815
- expandCategories: m = "descendants",
816
- currentCategory: u,
817
- sorting: h = "popularity-descending",
818
- guideIds: k = []
819
- } = t, p = s.toString().trim();
820
- if (yield Pe(this.container))
821
- return Promise.resolve();
822
- switch (e) {
823
- case "match": {
824
- const l = (f) => {
825
- const [B, E] = f.split("-");
826
- return {
827
- type: (/* @__PURE__ */ new Map([
828
- ["popularity", "popularity"],
829
- ["alphabetic", "title"],
830
- ["modified", "lastModified"],
831
- ["published", "firstPublished"]
832
- ])).get(B),
833
- direction: E
834
- };
835
- };
836
- return k.length ? this.matchingClient.customRequest("guides", "POST", {
837
- configuration: { ids: k, take: +c }
838
- }).then(
839
- (f) => f && this.handleResponse(f, e, t)
840
- ) : this.matchingClient.match(p, {
841
- categories: i === "0" ? [] : Array.isArray(i) ? i : [+i],
842
- take: +c,
843
- tags: r,
844
- sorting: l(h),
845
- ids: k
846
- }).then(
847
- (f) => f && this.handleResponse(f, e, t)
848
- );
849
- }
850
- case "match-by-category":
851
- return this.matchingClient.match(p, {
852
- groupByCategory: !0,
853
- categories: i === "0" ? [] : Array.isArray(i) ? i : [+i],
854
- take: +c,
855
- tags: r
856
- }).then(
857
- (l) => l && this.handleResponse(l, e, t)
858
- );
859
- case "guide":
860
- return this.matchingClient.getGuide(g, { connectionId: d }).then((l) => {
861
- l && this.handleResponse(l, e, t);
862
- }).catch((l) => {
863
- const f = {
864
- message: "Something went wrong.",
865
- status: l.status || 400
866
- };
867
- f.status === 404 && (f.message = "The guide could not be found."), this.handleResponse({}, e, t, f);
868
- });
869
- case "categories":
870
- return this.matchingClient.getCategories({
871
- phrase: p,
872
- expand: m,
873
- tags: r
874
- }).then(
875
- (l) => l && this.handleResponse(l, e, t)
876
- );
877
- case "contacts":
878
- return g ? this.matchingClient.contactMethods(+g, { phrase: p }).then(
879
- (l) => l && this.handleResponse(l, e, t)
880
- ) : this.matchingClient.contacts(+o, { phrase: p }).then(
881
- (l) => l && this.handleResponse(l, e, t)
882
- );
883
- case "contact-method":
884
- return this.matchingClient.getContactMethod(+a, { guideId: g, currentCategory: u }).then(
885
- (l) => l && this.handleResponse(l, e, t)
886
- );
887
- case "tags":
888
- return this.matchingClient.customRequest("tags", "GET", {
889
- configuration: {
890
- take: 999999,
891
- phrase: p,
892
- categories: i === "0" ? [] : Array.isArray(i) ? i : [+i]
893
- }
894
- }).then(
895
- (l) => l && this.handleResponse(l, e, t)
896
- );
897
- case "tagsonguides":
898
- return this.matchingClient.customRequest("tagsonguides", "GET", {
899
- configuration: {
900
- take: 999999,
901
- phrase: p,
902
- categories: i === "0" ? [] : Array.isArray(i) ? i : [+i],
903
- tags: r
904
- }
905
- }).then(
906
- (l) => l && this.handleResponse(l, e, t)
907
- );
908
- case "notifications":
909
- return this.matchingClient.customRequest("notices", "GET", {
910
- configuration: {
911
- phrase: p,
912
- categories: i === "0" ? [] : Array.isArray(i) ? i : [+i]
913
- }
914
- }).then(
915
- (l) => l && this.handleResponse(l, e, t)
916
- );
917
- }
918
- });
919
- }
920
- handleResponse(e = {}, t, s, i) {
921
- const o = this.queries.get(t) || [], a = o.find((r) => G(r.params, s));
922
- if (a) {
923
- const r = i || Ie(t, e);
924
- this.track(r, t, i), a.resolvers.forEach((d) => {
925
- i ? d.reject({ error: r }) : d.resolve(r);
926
- });
927
- const c = o.indexOf(a);
928
- c > -1 && o.splice(c, 1), o.push(J(Z({}, a), {
929
- error: i,
930
- resolvers: [],
931
- data: r,
932
- resolved: !0
933
- })), this.setLoadingStatus(t, s, !1), this.queries.set(t, o), i || this.events.dispatch("data-client:fetched", {
934
- type: t,
935
- params: s,
936
- response: r,
937
- unresolvedQueries: this.getUnresolvedQueries()
938
- });
939
- }
940
- }
941
- fetchAllUnresolvedQueries() {
942
- for (const [e, t] of this.queries)
943
- t.filter((s) => !s.resolved).forEach((s) => {
944
- this.runQuery(e, s.params);
945
- });
946
- }
947
- track(e = {}, t, s) {
948
- const i = this.container.get("$widget");
949
- i && !s ? i.events.dispatch("tracking:service-client-response", {
950
- type: t,
951
- data: e
952
- }) : i && i.events.dispatch("tracking:service-client-error", {
953
- type: t,
954
- error: s
955
- });
956
- }
957
- static create(e) {
958
- return e.getAsync("matchingClient").then((t) => x(this, null, function* () {
959
- if (t)
960
- return new O(e, t);
961
- const s = yield te(e);
962
- return e.registerAsync("matchingClient", () => s), new O(e, s);
963
- }));
964
- }
965
- getClient() {
966
- return this.matchingClient;
967
- }
968
- }
969
- const Re = (n) => x(void 0, null, function* () {
970
- n.registerAsync("dataClient", () => O.create(n));
971
- });
972
- export {
973
- O as DataClient,
974
- xe as DataType,
975
- Ee as FeedbackType,
976
- Re as KnowledgeDataClientPlugin,
977
- v as ServiceClientQueryType,
978
- Me as SortingType,
979
- ne as determineServiceClientQueryType,
980
- Ie as formatLegacyData
981
- };
982
- //# sourceMappingURL=index.js.map