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

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/index.mjs ADDED
@@ -0,0 +1,1743 @@
1
+ const K = (n, e, t, ...i) => {
2
+ const s = `[${n.get("$environment").name || "webprovisions"}] ${t}`;
3
+ switch (e) {
4
+ case "info":
5
+ console.info(s, ...i);
6
+ break;
7
+ case "warning":
8
+ console.warn(s, ...i);
9
+ break;
10
+ case "error":
11
+ console.error(s, ...i);
12
+ break;
13
+ }
14
+ }, De = (n) => {
15
+ const e = n.container || n;
16
+ return {
17
+ info: (t, ...i) => K(e, "info", t, ...i),
18
+ warn: (t, ...i) => K(e, "warning", t, ...i),
19
+ error: (t, ...i) => K(e, "error", t, ...i)
20
+ };
21
+ };
22
+ var D = /* @__PURE__ */ ((n) => (n.Implementation = "implementation", n.Widget = "widget", n))(D || {}), x = /* @__PURE__ */ ((n) => (n.Pre = "pre", n.Post = "post", n))(x || {});
23
+ const Ge = (n, e, t, i) => {
24
+ try {
25
+ const s = new e(t, i);
26
+ return {
27
+ name: n,
28
+ invoke: (r, a) => {
29
+ let o;
30
+ return s[r] && (o = s[r].call(s, a)), Promise.resolve(o);
31
+ },
32
+ getInstance: () => s
33
+ };
34
+ } catch (s) {
35
+ if (s.message && s.message.indexOf("is not a constructor") >= 0)
36
+ return {
37
+ name: n,
38
+ invoke: (r) => {
39
+ let a;
40
+ return r === "initialize" && (a = e(t, i)), Promise.resolve(a);
41
+ },
42
+ getInstance: () => e
43
+ };
44
+ throw s;
45
+ }
46
+ };
47
+ function de(n, e) {
48
+ return typeof n > "u" ? e : n;
49
+ }
50
+ let Te = class {
51
+ constructor(e = {}) {
52
+ this.part = e;
53
+ }
54
+ createCommand(e, t, i) {
55
+ let s;
56
+ typeof t == "function" ? s = {
57
+ scope: D.Widget,
58
+ stage: x.Post,
59
+ defaultArgs: void 0,
60
+ handlerResolver: t
61
+ } : s = {
62
+ scope: de(t.scope, D.Widget),
63
+ stage: de(t.stage, x.Post),
64
+ defaultArgs: t.defaultArgs,
65
+ handlerResolver: i
66
+ };
67
+ let r = this.part;
68
+ const a = e.split(".");
69
+ return a.forEach((o, c) => {
70
+ c === a.length - 1 ? r[o] || (r[o] = () => s) : r = this.part[o] = this.part[o] || {};
71
+ }), this;
72
+ }
73
+ get() {
74
+ return this.part;
75
+ }
76
+ };
77
+ const Ae = (n) => {
78
+ const e = new Te({});
79
+ return n(e), e.get();
80
+ };
81
+ Ae((n) => {
82
+ n.createCommand(
83
+ "types.register",
84
+ { scope: D.Implementation, stage: x.Pre },
85
+ (e) => (t, i) => {
86
+ e.container.get("$types")[t] = i;
87
+ }
88
+ ).createCommand(
89
+ "type",
90
+ { stage: x.Pre },
91
+ (e) => (t) => {
92
+ e.container.register("$type", t);
93
+ }
94
+ ).createCommand(
95
+ "settings",
96
+ { stage: x.Pre, defaultArgs: [null] },
97
+ (e) => (t) => {
98
+ e.events.dispatch(
99
+ "settings:change",
100
+ t,
101
+ { bubbles: !0 }
102
+ ), e.container.register("$settings", t);
103
+ }
104
+ ).createCommand(
105
+ "plugin",
106
+ { stage: x.Pre },
107
+ (e) => (t, i, s) => {
108
+ const { container: r } = e;
109
+ let a = null, o = t, c = i;
110
+ typeof t == "string" && (a = t, o = i, c = s);
111
+ const h = (d) => {
112
+ const { transformPluginSettings: g } = e.container.get("$environmentOptions"), u = g ? g(
113
+ c || {},
114
+ a,
115
+ e.container,
116
+ o
117
+ ) : i;
118
+ try {
119
+ const p = Ge(
120
+ a,
121
+ o,
122
+ r,
123
+ u
124
+ );
125
+ r.get("$plugins").push(p), d && p.invoke("initialize", null);
126
+ } catch (p) {
127
+ De(e).warn("Error when initializing plugin", p);
128
+ }
129
+ };
130
+ e.container.get("$instance") ? h(!0) : e.events.subscribeOnce("widget:instance-created", () => h(!1));
131
+ }
132
+ ).createCommand(
133
+ "container.register",
134
+ (e) => (t, i) => {
135
+ e.container.register(t, i);
136
+ }
137
+ ).createCommand(
138
+ "container.registerAsync",
139
+ (e) => (t, i) => {
140
+ e.container.registerAsync(t, i);
141
+ }
142
+ ).createCommand(
143
+ "container.registerFactory",
144
+ (e) => (t, i) => {
145
+ e.container.registerFactory(t, i);
146
+ }
147
+ ).createCommand(
148
+ "container.touch",
149
+ (e) => (t, i) => {
150
+ e.container.touch(t, i);
151
+ }
152
+ ).createCommand(
153
+ "csp",
154
+ {},
155
+ (e) => (t) => {
156
+ e.container.register("csp", t);
157
+ }
158
+ );
159
+ });
160
+ const ze = Ae((n) => {
161
+ n.createCommand(
162
+ "ready",
163
+ { scope: D.Implementation, stage: x.Pre },
164
+ (e) => (t) => {
165
+ const { container: i } = e, s = i.owner;
166
+ i.get("bootstrapping").ready ? t(s) : s.events.subscribeOnce("bootstrap:ready", () => {
167
+ t(s);
168
+ });
169
+ }
170
+ );
171
+ }), Z = /* @__PURE__ */ new WeakMap();
172
+ function R() {
173
+ return (n) => (Z.has(n) || Z.set(n, {}), Z.get(n));
174
+ }
175
+ const J = (n, e, t, ...i) => {
176
+ const s = `[${n.get("$environment").name || "webprovisions"}] ${t}`;
177
+ switch (e) {
178
+ case "info":
179
+ console.info(s, ...i);
180
+ break;
181
+ case "warning":
182
+ console.warn(s, ...i);
183
+ break;
184
+ case "error":
185
+ console.error(s, ...i);
186
+ break;
187
+ }
188
+ }, v = (n) => {
189
+ const e = n.container || n;
190
+ return {
191
+ info: (t, ...i) => J(e, "info", t, ...i),
192
+ warn: (t, ...i) => J(e, "warning", t, ...i),
193
+ error: (t, ...i) => J(e, "error", t, ...i)
194
+ };
195
+ }, m = R(), se = (() => {
196
+ let n = 0;
197
+ return () => ++n;
198
+ })(), re = (n, e, t) => {
199
+ const i = m(n).touchQueue.get(e);
200
+ i && i.forEach((s) => {
201
+ s(t, n);
202
+ });
203
+ };
204
+ class Ue {
205
+ constructor(e, t, i, s) {
206
+ this.key = e, this.factory = t, this.parent = i, this.container = s, this.id = se(), this.resolved = !1, this.constructed = !1, this.async = !0;
207
+ }
208
+ resolve() {
209
+ if (!this.constructed) {
210
+ const e = this.factory(this.parent, this.container);
211
+ return this.constructed = !0, this.value = Promise.resolve(e).then((t) => (this.resolved = !0, re(this.container, this.key, t), t));
212
+ }
213
+ return this.value;
214
+ }
215
+ }
216
+ class Be {
217
+ constructor(e, t, i, s) {
218
+ this.key = e, this.value = t, this.parent = i, this.container = s, this.id = se(), this.async = !1, this.resolved = !1, this.constructed = !0, this.resolve = () => (this.resolved = !0, re(this.container, this.key, this.value), this.value);
219
+ }
220
+ }
221
+ class Fe {
222
+ constructor(e, t, i, s) {
223
+ this.key = e, this.value = t, this.parent = i, this.container = s, this.id = se(), this.async = !1, this.resolved = !1, this.constructed = !1, this.resolve = () => {
224
+ this.resolved = !0, this.constructed = !0;
225
+ const r = this.value(this.parent, this.container);
226
+ return re(this.container, this.key, this.value), r;
227
+ };
228
+ }
229
+ }
230
+ class oe {
231
+ /**
232
+ * Creates a new instance of `Container`.
233
+ * @param owner The object owning this inctance.
234
+ * @param name Optional name for the container.
235
+ * @param parent Parent container this should be a child of.
236
+ */
237
+ constructor(e, t, i) {
238
+ this.owner = e, this.name = t, this.parent = i, m(this).resolvers = /* @__PURE__ */ new Map(), m(this).touchQueue = /* @__PURE__ */ new Map(), m(this).children = [];
239
+ }
240
+ /**
241
+ * Deletes an existing resolver by its unique id.
242
+ * @param id Resolver id.
243
+ */
244
+ delete(e) {
245
+ const t = m(this).resolvers, i = Array.from(t.values()).find((s) => s.id === e);
246
+ return i ? (m(this).touchQueue.delete(i.key), Promise.resolve(t.delete(i.key))) : this.parent ? this.parent.delete(e) : Promise.resolve(!1);
247
+ }
248
+ /**
249
+ * Clears the `Container` and any child containers by deleteing all registered resolvers.
250
+ */
251
+ clear() {
252
+ const e = m(this).resolvers, t = Array.from(e.values());
253
+ return Promise.all(t.map((i) => {
254
+ if (i.constructed)
255
+ return Promise.resolve(i.resolve()).then((s) => {
256
+ if (s !== null && typeof s == "object" && typeof s.dispose == "function")
257
+ return s.dispose.call(s, this, i);
258
+ });
259
+ })).then(() => {
260
+ t.forEach((i) => this.delete(i.id)), m(this).children.forEach((i) => i.clear());
261
+ });
262
+ }
263
+ /**
264
+ * Detaches this `Container` instance from its parent, allowing it to be garbage-collected.
265
+ */
266
+ detach() {
267
+ if (this.parent) {
268
+ const e = m(this.parent).children, t = e.indexOf(this);
269
+ t > -1 && (e.splice(t, 1), delete this.parent);
270
+ }
271
+ }
272
+ /**
273
+ * Provides a way of touching a value in the `Container` without forcing it to be resolved.
274
+ * @param key Key of the resolved value to touch.
275
+ * @param handler Handler function for touching the resolved value.
276
+ */
277
+ touch(e, t) {
278
+ const i = m(this).resolvers.get(e);
279
+ if (i && i.constructed)
280
+ Promise.resolve(i.resolve()).then((s) => {
281
+ t(s, this);
282
+ });
283
+ else {
284
+ const s = m(this).touchQueue;
285
+ let r = s.get(e);
286
+ r || (r = [], s.set(e, r)), r.push(t);
287
+ }
288
+ return this.parent && !i ? this.parent.touch(e, t) : Promise.resolve();
289
+ }
290
+ /**
291
+ * Registers an asynchronous resolver.
292
+ * @param key Key of the resolver.
293
+ * @param factory Value factory.
294
+ */
295
+ registerAsync(e, t) {
296
+ const i = m(this).resolvers.get(e);
297
+ i && !i.async && process.env.NODE_ENV !== "production" && v(this).warn(`Mismatching resolver type. You are registering an async resolver with a key ('${e}') previously used by a non-async resolver.`);
298
+ const s = new Ue(e, t, i, this);
299
+ return m(this).resolvers.set(e, s), s.id;
300
+ }
301
+ /**
302
+ * Registers a factory resolver for constructing the value to be resolved.
303
+ * @param key Key of the resolver.
304
+ * @param factory Value factory.
305
+ */
306
+ registerFactory(e, t) {
307
+ const i = m(this).resolvers.get(e);
308
+ i && i.async && process.env.NODE_ENV !== "production" && v(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${e}') previously used by an async resolver.`);
309
+ const s = new Fe(e, t, i, this);
310
+ return m(this).resolvers.set(e, s), s.id;
311
+ }
312
+ /**
313
+ * Registers an synchronous resolver.
314
+ * @param key Key of the resolver.
315
+ * @param value Value.
316
+ */
317
+ register(e, t) {
318
+ const i = m(this).resolvers.get(e);
319
+ i && i.async && process.env.NODE_ENV !== "production" && v(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${e}') previously used by an async resolver.`);
320
+ const s = new Be(e, t, i, this);
321
+ return m(this).resolvers.set(e, s), s.id;
322
+ }
323
+ /**
324
+ * Gets the value for a synchronous resolver.
325
+ * @param key Key of resolver to get.
326
+ */
327
+ get(e) {
328
+ const t = m(this).resolvers.get(e);
329
+ if (t)
330
+ return t.async && process.env.NODE_ENV !== "production" && v(this).warn(`You are retrieving an async value (with key '${e}') by the non-async function 'container.get(key)'. This will not be supported in future versions. Use 'container.getAsync(key) instead.'`), t.resolve();
331
+ if (this.parent)
332
+ return this.parent.get(e);
333
+ }
334
+ /**
335
+ * Gets the value for a asynchronous resolver.
336
+ * @param key Key of resolver to get.
337
+ */
338
+ getAsync(e) {
339
+ const t = m(this).resolvers.get(e);
340
+ if (t) {
341
+ if (!t.async)
342
+ throw process.env.NODE_ENV !== "production" && v(this).warn(`You are retrieving a non-async value (with key '${e}') by the async function 'container.getAsync(key)'.Use 'container.get(key) instead.'`), "Mismatching resolver type";
343
+ return t.resolve();
344
+ }
345
+ return this.parent ? this.parent.getAsync(e) : Promise.resolve(void 0);
346
+ }
347
+ getMany(...e) {
348
+ const t = {};
349
+ return e.forEach((i) => t[i] = this.get(i)), t;
350
+ }
351
+ getManyAsync(...e) {
352
+ const t = {};
353
+ return Promise.all(e.map((i) => this.getAsync(i).then((s) => t[i] = s))).then(() => t);
354
+ }
355
+ createChild(e, t) {
356
+ const i = new oe(e, t, this);
357
+ return m(this).children.push(i), i;
358
+ }
359
+ }
360
+ class ue {
361
+ /**
362
+ *
363
+ * @param type Type of event.
364
+ * @param target The target of the event, which will handle the default behavour.
365
+ * @param cancelable Whether the event is cancelable by calling preventDefault().
366
+ * @param bubbles Whether the event will bubble up the parent hierarchy.
367
+ */
368
+ constructor(e, t, i = !1, s = !1) {
369
+ this.type = e, this.target = t, this.cancelable = !!i, this.bubbles = !!s, this.defaultPrevented = !1;
370
+ }
371
+ /**
372
+ * Cancels the default behaviour (if the event is cancelable).
373
+ */
374
+ preventDefault() {
375
+ this.cancelable && (this.defaultPrevented = !0);
376
+ }
377
+ }
378
+ const $ = R(), ge = (n, e) => [].concat(
379
+ $(n).listenerLookup.get(e.toLowerCase()) || [],
380
+ $(n).listenerLookup.get("*") || []
381
+ ), pe = (n, e, t, i) => {
382
+ let s, r;
383
+ return e instanceof ue ? (s = e, r = e.type) : (s = new ue(e, n.target, !!t.cancelable, !!t.bubbles), r = e), { event: s, type: r, async: i };
384
+ };
385
+ let We = class Ne {
386
+ /**
387
+ * Creates a new Event Manager instance.
388
+ * @param target The target of events dispatched from this Event Manager instance.
389
+ * @param parent Parent Event Manager instance.
390
+ */
391
+ constructor(e, t) {
392
+ this.target = e, this.parent = t, $(this).listenerLookup = /* @__PURE__ */ new Map(), $(this).children = [];
393
+ }
394
+ /**
395
+ * Clears registered event listeners in this `EventManager` as well as in any children.
396
+ */
397
+ clear() {
398
+ $(this).listenerLookup.clear(), $(this).children.forEach((e) => e.clear());
399
+ }
400
+ /**
401
+ * Detaches this `EventManager` instance from its parent, allowing it to be garbage-collected.
402
+ */
403
+ detach() {
404
+ if (this.parent) {
405
+ const e = $(this.parent).children, t = e.indexOf(this);
406
+ t > -1 && e.splice(t, 1);
407
+ }
408
+ }
409
+ /**
410
+ * Creates an event subscription by registering an listener for an event type.
411
+ * @param type Event type to subscribe to.
412
+ * @param listener Listener for the event.
413
+ */
414
+ subscribe(e, t, i) {
415
+ const s = $(this).listenerLookup, r = e.toLowerCase();
416
+ return s.has(r) || s.set(r, []), s.get(r).push(t), () => this.unsubscribe(e, t);
417
+ }
418
+ /**
419
+ * Similar to `subscribe()` but immediately removes the subscription after the first call.
420
+ * @param type Event type to subscribe to.
421
+ * @param listener Listener for the event.
422
+ */
423
+ subscribeOnce(e, t) {
424
+ const i = this.subscribe(e, (s, r) => (i(), t(s, r)));
425
+ }
426
+ /**
427
+ * Removes a listener for the specified event type.
428
+ * @param type Event type to remove subscription for.
429
+ * @param listener Event listener to remove.
430
+ */
431
+ unsubscribe(e, t) {
432
+ const i = $(this).listenerLookup.get(e.toLowerCase());
433
+ if (i) {
434
+ const s = i.indexOf(t);
435
+ s > -1 && i.splice(s, 1);
436
+ }
437
+ }
438
+ /**
439
+ * Dispatches an asynchonous event to registered event listeners.
440
+ * @param eventOrType Event type or Event object to dispatch.
441
+ * @param data Optional data to be passed to event listeners.
442
+ * @param options Optional event options used if first parameter is an event type.
443
+ */
444
+ dispatchAsync(e, t, i = {}) {
445
+ const { event: s, type: r } = pe(this, e, i, !0), a = ge(this, r);
446
+ let o = 0;
447
+ const c = a.length;
448
+ let h = Promise.resolve();
449
+ for (o = 0; o < c; o++)
450
+ ((d) => {
451
+ h = h.then((g) => g ? Promise.resolve(!0) : Promise.resolve(d(s, t)).then(() => s.defaultPrevented));
452
+ })(a[o]);
453
+ return h.then((d) => !d && s.bubbles && this.parent ? this.parent.dispatchAsync(s, t) : d);
454
+ }
455
+ /**
456
+ * Dispatches an event to registered event listeners.
457
+ * @param eventOrType Event type or Event object to dispatch.
458
+ * @param data Optional data to be passed to event listeners.
459
+ * @param options Optional event options used if first parameter is an event type.
460
+ */
461
+ dispatch(e, t, i = {}) {
462
+ const { event: s, type: r } = pe(this, e, i, !1), a = ge(this, r);
463
+ let o = 0;
464
+ const c = a.length;
465
+ let h = !1;
466
+ for (o = 0; o < c; o++)
467
+ if (a[o](s, t), s.defaultPrevented) {
468
+ h = !0;
469
+ break;
470
+ }
471
+ return !h && s.bubbles && this.parent && (h = this.parent.dispatch(s, t)), h;
472
+ }
473
+ /**
474
+ * Creates a child instance to the current Event manager.
475
+ */
476
+ createChild(e) {
477
+ const t = new Ne(e, this);
478
+ return $(this).children.push(t), t;
479
+ }
480
+ };
481
+ const z = (n, e, t) => {
482
+ const i = n.get("$plugins").map((s) => {
483
+ try {
484
+ return s.invoke(e, t);
485
+ } catch (r) {
486
+ v(n).error("An error occured when invoking a plugin.", s, r);
487
+ }
488
+ });
489
+ return Promise.all(i);
490
+ };
491
+ let He = class {
492
+ constructor(e) {
493
+ this.widget = e.get("$widget"), this.events = this.widget.events, this.container = this.widget.container, this.initialized = null, this.activated = null, this.initialize = this.initialize.bind(this), this.activate = this.activate.bind(this), this.deactivate = this.deactivate.bind(this), this.invoke = this.invoke.bind(this), this.createInstance();
494
+ }
495
+ createInstance() {
496
+ if (!this.widget.container.get("$instance")) {
497
+ const e = this.widget.container.get("$types"), t = this.widget.container.get("$type");
498
+ !t && v(this).error("Unable to create widget. No type is specified.");
499
+ const i = e[t];
500
+ !i && v(this).error(`Unable to create widget. Type '${t}' is not registered.`), this.widget.events.dispatch("widget:create-instance", {}, { bubbles: !0 });
501
+ try {
502
+ this.widget.container.register(
503
+ "$instance",
504
+ new i(this.container)
505
+ );
506
+ } catch (s) {
507
+ v(this).error("Unable to create widget type.", s);
508
+ }
509
+ this.widget.events.dispatch("widget:instance-created", {}, { bubbles: !0 });
510
+ }
511
+ }
512
+ /**
513
+ * The initialization is performed before the widget is activated but after it's configured
514
+ * and thus all required services are available. This hook is a good place to bind events that
515
+ * should trigger activation (e.g. click on "trigger links" or routing events)
516
+ * @param {object} data Custom initialization data passed to the widget.
517
+ */
518
+ initialize(e) {
519
+ return this.initialized = this.initialized || (() => {
520
+ const t = this.container.get("$instance"), i = t.initialize || (() => {
521
+ });
522
+ return this.initialized = Promise.resolve(i.call(t, e)).then(() => z(this.container, "initialize", e)).then(() => {
523
+ });
524
+ })();
525
+ }
526
+ /**
527
+ * The activation is where the widget is actually created and rendered.
528
+ * Activation can be initialized from the outside or from an event originated
529
+ * in the "initialize" hook.
530
+ * @param {object} data Custom activation data passed to the widget.
531
+ */
532
+ activate(e) {
533
+ return (this.initialized || this.initialize()).then(() => {
534
+ this.activated = this.activated || (() => z(this.container, "activate").then(() => {
535
+ const t = this.container.get("$instance");
536
+ return this.activated = t.activate(e);
537
+ }))();
538
+ });
539
+ }
540
+ deactivate() {
541
+ const e = this.container.get("$instance"), t = e.deactivate || (() => {
542
+ });
543
+ return z(this.container, "deactivate").then(() => Promise.resolve(t.call(e))).then(() => {
544
+ this.initialized = null, this.activated = null;
545
+ }).then(() => {
546
+ });
547
+ }
548
+ /**
549
+ * Invokes a command on the widget component.
550
+ * @param command Name of command
551
+ * @param args Command arguments
552
+ */
553
+ invoke(e, ...t) {
554
+ return z(this.container, "invoke", { command: e, args: t }).then(() => {
555
+ const i = this.container.get("$instance");
556
+ if (i[e])
557
+ return i[e].apply(i, t);
558
+ const s = i.invoke;
559
+ if (s)
560
+ return s.call(i, e, ...t);
561
+ });
562
+ }
563
+ };
564
+ const M = (n, e) => {
565
+ if (!e)
566
+ return !0;
567
+ if (typeof e == "string") {
568
+ const t = e.split(",");
569
+ for (let i = 0, s = t.length; i < s; i++) {
570
+ const r = t[i].trim();
571
+ if (r === n || r === "*")
572
+ return !0;
573
+ }
574
+ }
575
+ return e instanceof Array ? e.indexOf(n) > -1 : !1;
576
+ }, Ve = (n, e) => {
577
+ if (typeof e == "function")
578
+ return e(n);
579
+ const t = typeof e == "string" ? Ke(e) : e;
580
+ return !(!M(n.implementation.tenant || "", t.tenant || "") || !M(n.implementation.name, t.implementation || "") || !M(n.name, t.widget || "") || !M(n.container.get("$type"), t.type || ""));
581
+ }, Qe = (n, e) => {
582
+ if (typeof e == "function")
583
+ return e(n);
584
+ const t = typeof e == "string" ? Ze(e) : e;
585
+ return !(!M(n.tenant || "", t.tenant || "") || !M(n.name, t.implementation || ""));
586
+ }, xe = (n) => (e) => Ve(e, n), Ye = (n) => (e) => Qe(e, n), E = (n) => n instanceof Array && n.length === 1 ? n[0] : n, Ke = (n) => {
587
+ const e = {}, t = n.split(":");
588
+ return t.length === 1 ? e.widget = E(t[0].split(",")) : t.length === 2 ? (e.implementation = E(t[0].split(",")), e.widget = E(t[1].split(","))) : (e.tenant = E(t[0].split(",")), e.implementation = E(t[1].split(",")), e.widget = E(t[2].split(","))), e;
589
+ }, Ze = (n) => {
590
+ const e = {}, t = n.split(":");
591
+ return t.length === 1 ? e.implementation = E(t[0].split(",")) : (e.tenant = E(t[0].split(",")), e.implementation = E(t[1].split(","))), e;
592
+ }, W = R(), me = (n, e, t) => n.filter((i) => i.stage === e && xe(i.selector)(t));
593
+ function Je(n) {
594
+ const e = n.container.get("$environment");
595
+ let t = W(e).configurationCache;
596
+ t && (t = t.filter((i) => i[0] !== n), W(e).configurationCache = t);
597
+ }
598
+ var H = /* @__PURE__ */ ((n) => (n.Implementation = "implementation", n.Widget = "widget", n))(H || {}), A = /* @__PURE__ */ ((n) => (n.Pre = "pre", n.Post = "post", n))(A || {});
599
+ const Oe = (n, e, t) => (Object.keys(e).forEach((i) => {
600
+ const s = e[i];
601
+ if (typeof s == "function") {
602
+ const r = s();
603
+ typeof r.defaultArgs < "u" && t(r, ...r.defaultArgs), n[i] = (...a) => {
604
+ const o = Object.assign(
605
+ {},
606
+ r,
607
+ { handlerResolver: r.handlerResolver.bind({}) }
608
+ );
609
+ return t(o, ...a), n;
610
+ };
611
+ } else
612
+ n[i] = Oe(
613
+ {},
614
+ s,
615
+ t
616
+ );
617
+ }), n), Xe = (n, e) => {
618
+ switch (e) {
619
+ case "implementation":
620
+ return n.implementation;
621
+ case "widget":
622
+ return n;
623
+ }
624
+ }, fe = (n, e, t, i) => (i.forEach((s) => {
625
+ Oe(
626
+ n,
627
+ s,
628
+ (r, ...a) => {
629
+ const o = {
630
+ selector: e,
631
+ stage: r.stage,
632
+ handler: (c) => {
633
+ const h = Xe(c, r.scope), d = { container: h.container, events: h.events }, g = r.handlerResolver, u = g(d);
634
+ let p = W(t.environment).configurationCache;
635
+ return p || (p = W(t.environment).configurationCache = []), p.find((b) => b.indexOf(h) > -1 && b.indexOf(g) > -1) ? Promise.resolve() : (p.push([h, g]), Promise.resolve(u(...a)));
636
+ }
637
+ };
638
+ t.instructions.push(o);
639
+ }
640
+ );
641
+ }), n);
642
+ function et(n, e) {
643
+ function t(i) {
644
+ return fe(
645
+ {},
646
+ i,
647
+ n,
648
+ e
649
+ );
650
+ }
651
+ return fe(
652
+ t,
653
+ "*",
654
+ n,
655
+ e
656
+ );
657
+ }
658
+ const tt = (n, e, t, i) => {
659
+ try {
660
+ const s = new e(t, i);
661
+ return {
662
+ name: n,
663
+ invoke: (r, a) => {
664
+ let o;
665
+ return s[r] && (o = s[r].call(s, a)), Promise.resolve(o);
666
+ },
667
+ getInstance: () => s
668
+ };
669
+ } catch (s) {
670
+ if (s.message && s.message.indexOf("is not a constructor") >= 0)
671
+ return {
672
+ name: n,
673
+ invoke: (r) => {
674
+ let a;
675
+ return r === "initialize" && (a = e(t, i)), Promise.resolve(a);
676
+ },
677
+ getInstance: () => e
678
+ };
679
+ throw s;
680
+ }
681
+ };
682
+ function ve(n, e) {
683
+ return typeof n > "u" ? e : n;
684
+ }
685
+ let nt = class {
686
+ constructor(e = {}) {
687
+ this.part = e;
688
+ }
689
+ createCommand(e, t, i) {
690
+ let s;
691
+ typeof t == "function" ? s = {
692
+ scope: H.Widget,
693
+ stage: A.Post,
694
+ defaultArgs: void 0,
695
+ handlerResolver: t
696
+ } : s = {
697
+ scope: ve(t.scope, H.Widget),
698
+ stage: ve(t.stage, A.Post),
699
+ defaultArgs: t.defaultArgs,
700
+ handlerResolver: i
701
+ };
702
+ let r = this.part;
703
+ const a = e.split(".");
704
+ return a.forEach((o, c) => {
705
+ c === a.length - 1 ? r[o] || (r[o] = () => s) : r = this.part[o] = this.part[o] || {};
706
+ }), this;
707
+ }
708
+ get() {
709
+ return this.part;
710
+ }
711
+ };
712
+ const Ie = (n) => {
713
+ const e = new nt({});
714
+ return n(e), e.get();
715
+ }, it = Ie((n) => {
716
+ n.createCommand(
717
+ "types.register",
718
+ { scope: H.Implementation, stage: A.Pre },
719
+ (e) => (t, i) => {
720
+ e.container.get("$types")[t] = i;
721
+ }
722
+ ).createCommand(
723
+ "type",
724
+ { stage: A.Pre },
725
+ (e) => (t) => {
726
+ e.container.register("$type", t);
727
+ }
728
+ ).createCommand(
729
+ "settings",
730
+ { stage: A.Pre, defaultArgs: [null] },
731
+ (e) => (t) => {
732
+ e.events.dispatch(
733
+ "settings:change",
734
+ t,
735
+ { bubbles: !0 }
736
+ ), e.container.register("$settings", t);
737
+ }
738
+ ).createCommand(
739
+ "plugin",
740
+ { stage: A.Pre },
741
+ (e) => (t, i, s) => {
742
+ const { container: r } = e;
743
+ let a = null, o = t, c = i;
744
+ typeof t == "string" && (a = t, o = i, c = s);
745
+ const h = (d) => {
746
+ const { transformPluginSettings: g } = e.container.get("$environmentOptions"), u = g ? g(
747
+ c || {},
748
+ a,
749
+ e.container,
750
+ o
751
+ ) : i;
752
+ try {
753
+ const p = tt(
754
+ a,
755
+ o,
756
+ r,
757
+ u
758
+ );
759
+ r.get("$plugins").push(p), d && p.invoke("initialize", null);
760
+ } catch (p) {
761
+ v(e).warn("Error when initializing plugin", p);
762
+ }
763
+ };
764
+ e.container.get("$instance") ? h(!0) : e.events.subscribeOnce("widget:instance-created", () => h(!1));
765
+ }
766
+ ).createCommand(
767
+ "container.register",
768
+ (e) => (t, i) => {
769
+ e.container.register(t, i);
770
+ }
771
+ ).createCommand(
772
+ "container.registerAsync",
773
+ (e) => (t, i) => {
774
+ e.container.registerAsync(t, i);
775
+ }
776
+ ).createCommand(
777
+ "container.registerFactory",
778
+ (e) => (t, i) => {
779
+ e.container.registerFactory(t, i);
780
+ }
781
+ ).createCommand(
782
+ "container.touch",
783
+ (e) => (t, i) => {
784
+ e.container.touch(t, i);
785
+ }
786
+ ).createCommand(
787
+ "csp",
788
+ {},
789
+ (e) => (t) => {
790
+ e.container.register("csp", t);
791
+ }
792
+ );
793
+ }), st = it;
794
+ function rt(n, e, t = []) {
795
+ const i = [st].concat(t), s = et(
796
+ e,
797
+ i
798
+ );
799
+ n(s, e);
800
+ }
801
+ class ot {
802
+ constructor() {
803
+ this.tasks = [], this.current = Promise.resolve(), this.next = this.next.bind(this);
804
+ }
805
+ add(e, t, i, s) {
806
+ this.tasks.push({ task: e, resolve: t, reject: i, done: s }), this.next();
807
+ }
808
+ next() {
809
+ this.current = this.current.then(() => {
810
+ const e = this.tasks.shift();
811
+ if (e) {
812
+ const t = Promise.resolve(e.task());
813
+ return Promise.resolve(t).then(this.next).then(() => t.then((i) => {
814
+ e.done(), e.resolve(i);
815
+ })).catch((i) => (e.done(), e.reject(i), this.next()));
816
+ }
817
+ return Promise.resolve();
818
+ });
819
+ }
820
+ }
821
+ const U = /* @__PURE__ */ new WeakMap();
822
+ function at(n) {
823
+ return U.has(n) || U.set(n, new ot()), (e) => new Promise((t, i) => {
824
+ const s = U.get(n);
825
+ s.add(e, t, i, () => {
826
+ s.tasks.length || U.delete(n);
827
+ });
828
+ });
829
+ }
830
+ const ye = (n) => typeof n < "u", S = (n, e) => {
831
+ n.events.dispatch("widget:state-change", { state: e }, { bubbles: !0 }), n.state = e, n.events.dispatch("widget:state-changed", {}, { bubbles: !0 });
832
+ }, y = R(), ct = (n) => {
833
+ const { container: e, events: t } = n;
834
+ e.get("$controller") || (e.register("$controller", new He(e)), t.dispatch("widget:controller-created", {}, { bubbles: !0 }));
835
+ };
836
+ let ht = class {
837
+ /**
838
+ * Creates a new `Widget` instance.
839
+ * @param name Name of widget.
840
+ * @param implementation The implementation this instance belongs to.
841
+ * @param configuration Configuration for the widget.
842
+ */
843
+ constructor(e, t, i) {
844
+ this.state = "deactivated", this.name = e, this.implementation = t, this.container = t.container.createChild(this, e), this.events = t.events.createChild(this), y(this).subscriptions = [], i && t.configure((s) => {
845
+ const r = s(e);
846
+ ye(i.type) && r.type(i.type), ye(i.settings) && r.settings(i.settings), i.plugins && Object.keys(i.plugins).forEach((a) => {
847
+ var o;
848
+ const c = (o = i.plugins) == null ? void 0 : o[a];
849
+ r.plugin(a, c);
850
+ });
851
+ }), this.load = this.load.bind(this), this.activate = this.activate.bind(this), this.invoke = this.invoke.bind(this), this.deactivate = this.deactivate.bind(this);
852
+ }
853
+ /**
854
+ * Initializes the widget, if not already initialized, and applies any
855
+ * pending configuration.
856
+ */
857
+ load() {
858
+ return at(this)(() => {
859
+ y(this).deactivatedPromise = null;
860
+ const e = this.state === "deactivated";
861
+ e && (S(
862
+ this,
863
+ "activating"
864
+ /* Activating */
865
+ ), this.container.register("$widget", this), this.container.register("$controller", null), this.container.register("$plugins", []), this.container.register("$type", null), this.container.register("$instance", null)), S(
866
+ this,
867
+ "loading"
868
+ /* Loading */
869
+ );
870
+ const t = this.implementation.instructions, i = me(t, A.Pre, this);
871
+ return Promise.all(i.map((s) => s.handler(this))).then(() => {
872
+ ct(this);
873
+ const s = me(t, A.Post, this);
874
+ return Promise.all(s.map((r) => r.handler(this))).then(() => {
875
+ e && this.container.get("$controller").initialize();
876
+ });
877
+ }).then(() => (S(
878
+ this,
879
+ "activated"
880
+ /* Activated */
881
+ ), this));
882
+ });
883
+ }
884
+ /**
885
+ * Activates the widget and makes it ready for receiving commands.
886
+ * @param data Activation data
887
+ */
888
+ activate(e) {
889
+ y(this).subscriptions.push(
890
+ this.implementation.events.subscribe("implementation:configured", () => {
891
+ [
892
+ "activated",
893
+ "activating",
894
+ "loading"
895
+ /* Loading */
896
+ ].indexOf(this.state) > -1 && this.load();
897
+ })
898
+ );
899
+ const t = y(this).activatedPromise;
900
+ return t ? (process.env.NODE_ENV !== "production" && v(this).warn(`Widget '${this.name}' has already been activated. The passed arguments for this activation will be discarded.`, e), t) : y(this).activatedPromise = this.load().then(() => this.container.get("$controller").activate(e));
901
+ }
902
+ /**
903
+ * Invokes a command on a widget. If the widget isn't activate the invocation
904
+ * will be suspended until activation.
905
+ * @param command Command to invoke.
906
+ * @param args Command arguments.
907
+ */
908
+ invoke(e, ...t) {
909
+ const i = y(this).activatedPromise, s = (r, ...a) => i.then(this.load).then(() => this.container.get("$controller").invoke(r, ...a));
910
+ return i ? s(e, ...t) : (process.env.NODE_ENV !== "production" && v(this).warn("You are invoking a command on a deactivated widget. The invocation will be queued until the widget is activated.", this), new Promise((r) => {
911
+ const a = this.events.subscribe("widget:state-changed", () => {
912
+ this.state === "activated" && (a(), r(s(e, ...t)));
913
+ });
914
+ }));
915
+ }
916
+ /**
917
+ * Deactivates the widget by clearing the `Container` and removing any event subscriptions in the
918
+ * `EventManager`.
919
+ */
920
+ deactivate() {
921
+ return y(this).deactivatedPromise || (this.state === "deactivated" ? Promise.resolve() : (S(
922
+ this,
923
+ "deactivating"
924
+ /* Deactivating */
925
+ ), y(this).deactivatedPromise = this.container.get("$controller").deactivate().then(() => (y(this).activatedPromise = null, y(this).subscriptions.forEach((t) => t()), y(this).subscriptions = [], this.container.clear().then(() => {
926
+ this.events.clear(), Je(this), S(
927
+ this,
928
+ "deactivated"
929
+ /* Deactivated */
930
+ );
931
+ })))));
932
+ }
933
+ };
934
+ const be = R();
935
+ class lt {
936
+ /**
937
+ * Creates a new Implementation instance.
938
+ * @param configuration Configuration for the implementation.
939
+ * @param environment The parent environment.
940
+ * @param configurationApiExtensions Optional configuration API extensions.
941
+ */
942
+ constructor(e, t, i = []) {
943
+ this.instructions = [], this.widgets = /* @__PURE__ */ new Map(), this.name = e.name, this.tenant = e.tenant, this.environment = t, this.container = t.container.createChild(this, this.name), this.events = t.events.createChild(this), this.container.register("$types", {}), be(this).configurationApiExtensions = i;
944
+ }
945
+ /**
946
+ * Loads all widgets in the implementation.
947
+ */
948
+ load() {
949
+ const e = Array.from(this.widgets.values());
950
+ return Promise.all(e.map((t) => t.load())).then(() => e);
951
+ }
952
+ /**
953
+ * Configures the implementation by adding a configuration callback.
954
+ * @param configFn Callback function for configuration.
955
+ */
956
+ configure(e) {
957
+ return rt(e, this, be(this).configurationApiExtensions), this.events.dispatch(
958
+ "implementation:configured",
959
+ { implementation: this },
960
+ { bubbles: !0 }
961
+ ), this;
962
+ }
963
+ /**
964
+ * Creates a widget on the implementation and returns its `WidgetData`.
965
+ * @param name Widget name.
966
+ * @param configuration Widget configuration.
967
+ */
968
+ createWidget(e, t) {
969
+ const i = new ht(e, this, t);
970
+ return this.widgets.set(i.name, i), i;
971
+ }
972
+ }
973
+ function dt(n, e, t) {
974
+ const i = new lt(n, e, t);
975
+ return n.widgets && Object.keys(n.widgets).forEach((s) => {
976
+ var r;
977
+ const a = (r = n.widgets) == null ? void 0 : r[s];
978
+ i.createWidget(s, a);
979
+ }), i;
980
+ }
981
+ let we = class Me {
982
+ constructor(e, t) {
983
+ this.selectorFactory = t, typeof e == "function" ? this.resolver = e : this.resolver = () => e;
984
+ }
985
+ append(e) {
986
+ const t = typeof e == "function" ? e : () => e;
987
+ return new Me(
988
+ () => this.all().concat(t()),
989
+ this.selectorFactory
990
+ );
991
+ }
992
+ all() {
993
+ return this.resolver().concat([]);
994
+ }
995
+ query(e) {
996
+ return this.all().filter(this.selectorFactory(e));
997
+ }
998
+ find(e) {
999
+ const t = this.query(e);
1000
+ if (t.length)
1001
+ return t[0];
1002
+ }
1003
+ };
1004
+ const ae = "#____version____#", X = R(), ut = (n) => n.tenant ? `${n.name}:${n.tenant}` : n.name, Re = class {
1005
+ constructor(e, t = [], i = {}) {
1006
+ this.widgets = new we(
1007
+ () => {
1008
+ let s = [];
1009
+ return this.implementations.all().forEach((r) => {
1010
+ s = s.concat(Array.from(r.widgets.values()));
1011
+ }), s;
1012
+ },
1013
+ xe
1014
+ ), this.implementations = new we([], Ye), this.name = e, this.container = new oe(this, e), this.events = new We(this), this.container.register("$version", ae), this.container.register("$environment", this), this.container.register("$environmentOptions", i), X(this).configurationApiExtensions = t;
1015
+ }
1016
+ /**
1017
+ * Creates an implementation based on the provided configuration.
1018
+ * @param config Implementation configuration.
1019
+ */
1020
+ createImplementation(e) {
1021
+ const t = ut(e);
1022
+ let i = this.implementations.find(t);
1023
+ if (i)
1024
+ return process.env.NODE_ENV !== "production" && v(i).warn(`Implementation "${t}" already exist on current environment.`), i;
1025
+ const s = X(this).configurationApiExtensions;
1026
+ return i = dt(
1027
+ e,
1028
+ this,
1029
+ s
1030
+ ), this.implementations = this.implementations.append([i]), this.events.dispatch("implementation:created", { implementation: i }), i;
1031
+ }
1032
+ /**
1033
+ * Patches the Environment instance configuration.
1034
+ * @param configuration Environment configuration.
1035
+ */
1036
+ patch(e = {}) {
1037
+ const { name: t, configurationApiExtensions: i } = e;
1038
+ typeof t < "u" && t !== null && (this.name = t), i && i.forEach(
1039
+ (s) => {
1040
+ X(this).configurationApiExtensions.push(s);
1041
+ }
1042
+ );
1043
+ }
1044
+ /**
1045
+ * Creates a new Environment instance based on the provided configuration.
1046
+ * @param configuration Environment configuration.
1047
+ */
1048
+ static create(e = {}) {
1049
+ return new Re(
1050
+ e.name || "",
1051
+ e.configurationApiExtensions,
1052
+ e.options
1053
+ );
1054
+ }
1055
+ };
1056
+ let _e = Re;
1057
+ _e.version = ae;
1058
+ const Q = (n, e, ...t) => typeof e == "string" ? n(`[humany] ${e}`, ...t) : n(e, ...t), L = class {
1059
+ constructor() {
1060
+ this.keys = [], this.log = (e, ...t) => this.lookup(e, () => L.log(...t)), this.warn = (e, ...t) => this.lookup(e, () => L.warn(...t)), this.error = (e, ...t) => this.lookup(e, () => L.error(...t)), this.info = (e, ...t) => this.lookup(e, () => L.info(...t));
1061
+ }
1062
+ lookup(e, t) {
1063
+ this.keys.indexOf(e) === -1 && (this.keys.push(e), t());
1064
+ }
1065
+ };
1066
+ let G = L;
1067
+ G.log = (...n) => Q(console.log, ...n);
1068
+ G.warn = (...n) => Q(console.warn, ...n);
1069
+ G.error = (...n) => Q(console.error, ...n);
1070
+ G.info = (...n) => Q(console.info, ...n);
1071
+ const Se = (n) => {
1072
+ let e = {}, t, i;
1073
+ if (typeof n != "object" || n === null)
1074
+ return n;
1075
+ e = Array.isArray(n) ? [] : {};
1076
+ for (i in n)
1077
+ t = n[i], e[i] = typeof t == "object" && t !== null ? Se(t) : t;
1078
+ return e;
1079
+ }, gt = Se;
1080
+ class pt {
1081
+ constructor(e, t) {
1082
+ this.lockWarningTime = e, this.lockErrorTime = t, this.tasks = [], this.current = Promise.resolve(), this.next = this.next.bind(this);
1083
+ }
1084
+ add(e, t, i, s) {
1085
+ this.tasks.push({ task: e, resolve: t, reject: i, done: s }), this.next();
1086
+ }
1087
+ next() {
1088
+ this.current = this.current.then(() => {
1089
+ const e = this.tasks.shift();
1090
+ if (e) {
1091
+ let t;
1092
+ const i = setTimeout(() => {
1093
+ process.env.NODE_ENV !== "production" && G.warn(
1094
+ `A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,
1095
+ e
1096
+ ), t = setTimeout(() => {
1097
+ e.reject("lock timeout exceeded");
1098
+ }, this.lockErrorTime);
1099
+ }, this.lockWarningTime), s = Promise.resolve(e.task()).then((r) => (clearTimeout(i), clearTimeout(t), r));
1100
+ return Promise.resolve(s).then(this.next).then(
1101
+ () => s.then((r) => {
1102
+ e.done(), e.resolve(r);
1103
+ })
1104
+ ).catch((r) => (e.done(), e.reject(r), this.next()));
1105
+ }
1106
+ return Promise.resolve();
1107
+ });
1108
+ }
1109
+ }
1110
+ const B = /* @__PURE__ */ new WeakMap();
1111
+ function mt(n, e = 5e3, t = 1e3) {
1112
+ return B.has(n) || B.set(n, new pt(e, t)), (i) => new Promise((s, r) => {
1113
+ const a = B.get(n);
1114
+ a.add(i, s, r, () => {
1115
+ a.tasks.length || B.delete(n);
1116
+ });
1117
+ });
1118
+ }
1119
+ const ft = (n = {}) => (Object.keys(n).forEach((e) => {
1120
+ (n[e] === null || typeof n[e] > "u") && delete n[e];
1121
+ }), n), vt = ft, F = (n, e) => {
1122
+ let t = !0;
1123
+ return Object.keys(n).length !== Object.keys(e).length || Object.keys(n).some((i) => !Object.keys(e).some((s) => i === s)) ? !1 : (Object.keys(n).forEach((i) => {
1124
+ if (t) {
1125
+ const s = typeof n[i] > "u" ? "" : n[i], r = typeof e[i] > "u" ? "" : e[i];
1126
+ t = s.toString() === r.toString();
1127
+ }
1128
+ }), t);
1129
+ };
1130
+ var yt = Object.defineProperty, ke = Object.getOwnPropertySymbols, bt = Object.prototype.hasOwnProperty, wt = Object.prototype.propertyIsEnumerable, Ce = (n, e, t) => e in n ? yt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, $e = (n, e) => {
1131
+ for (var t in e || (e = {}))
1132
+ bt.call(e, t) && Ce(n, t, e[t]);
1133
+ if (ke)
1134
+ for (var t of ke(e))
1135
+ wt.call(e, t) && Ce(n, t, e[t]);
1136
+ return n;
1137
+ };
1138
+ Ie((n) => {
1139
+ n.createCommand("components", (e) => (t) => {
1140
+ e.events.subscribeOnce("components:platform-created", (i, { platform: s }) => {
1141
+ t.handlers && t.handlers.forEach(([r, a]) => {
1142
+ s.addComponentHandler(r, a);
1143
+ });
1144
+ });
1145
+ });
1146
+ });
1147
+ const kt = "#____version____#", Le = class extends _e {
1148
+ constructor(n, e = []) {
1149
+ super(n, e, {
1150
+ transformPluginSettings: (t, i, s) => {
1151
+ const r = s.get("$settings"), a = r.plugins && i ? r.plugins[i] || {} : {};
1152
+ return $e($e({}, a), t);
1153
+ }
1154
+ });
1155
+ }
1156
+ createImplementation(n) {
1157
+ const e = super.createImplementation(n);
1158
+ return e.bindings = n.bindings, e;
1159
+ }
1160
+ /**
1161
+ * Performs navigation for widgets matching the specified selector by invoking a
1162
+ * 'navigate' command.
1163
+ * @param selector Widget selector matching the widget(s) to perform navigation on.
1164
+ * @param route Route name.
1165
+ * @param params Route params.
1166
+ */
1167
+ navigate(n, e, t) {
1168
+ this.widgets.query(n).forEach((i) => i.invoke("navigate", { route: e, params: t }));
1169
+ }
1170
+ /**
1171
+ * Creates a runtime based on provided configuration.
1172
+ * @param configuration Runtime configuration.
1173
+ */
1174
+ static create(n = {}) {
1175
+ const e = [ze].concat(
1176
+ n.configurationApiExtensions || []
1177
+ );
1178
+ return new Le("humany", e);
1179
+ }
1180
+ /**
1181
+ * Creates a widget runtime based on provided configuration and retains configuration handlers
1182
+ * registered on global context. Use this factory to fully support the default embed script.
1183
+ * Will return any existing widget runtime if available.
1184
+ * @param configuration Runtime configuration.
1185
+ * @param global Object to read configuration handlers from (default: window).
1186
+ */
1187
+ static createFromGlobal(n, e = {}) {
1188
+ if (this.isRuntime(n))
1189
+ return n.patch(e), n;
1190
+ const t = [], i = n && n._c;
1191
+ i && i.forEach((r) => t.push(r));
1192
+ const s = this.create(e);
1193
+ return s.container.register("$runtimecfg", t), s;
1194
+ }
1195
+ /**
1196
+ * Determines whether the specified object is a valid widget runtime.
1197
+ * @param obj Object to compare.
1198
+ */
1199
+ static isRuntime(n) {
1200
+ return !!(n && typeof n == "object" && n.container && typeof n.container.get == "function" && n.container.get("$environment") === n && n.container.owner === n);
1201
+ }
1202
+ };
1203
+ let Ct = Le;
1204
+ Ct.version = `${kt} (${ae})`;
1205
+ var V = /* @__PURE__ */ ((n) => (n.open = "open", n.closed = "closed", n.hidden = "hidden", n))(V || {});
1206
+ const Pe = (n) => import("./index-5c9c2abf.mjs").then(
1207
+ ({ ServiceClient: e, ServiceProxy: t }) => n.get("settings").then((i) => {
1208
+ const { name: s, events: r } = n.get("$widget"), {
1209
+ data: { projection: a = "", site: o = "current", forceHttps: c = !1 }
1210
+ } = i, h = new t(a, {
1211
+ credentials: "same-origin"
1212
+ }), d = new e(
1213
+ h,
1214
+ {
1215
+ funnel: s.replace("_contact-method", "").replace("_contact", ""),
1216
+ site: $t(o, c)
1217
+ },
1218
+ null,
1219
+ n
1220
+ );
1221
+ return r.subscribe("widget:settings-updated", (g, { data: u }) => {
1222
+ u && u.projection !== a && d.proxy.setBaseUrl(u.projection);
1223
+ }), d;
1224
+ })
1225
+ ), $t = (n, e) => () => {
1226
+ const t = (s) => {
1227
+ const r = document.createElement("a");
1228
+ return r.href = s, r;
1229
+ };
1230
+ let i = window.location;
1231
+ return n === "referrer" && document.referrer && (i = t(document.referrer)), [
1232
+ e ? "https:" : "",
1233
+ "//",
1234
+ i.host,
1235
+ i.pathname
1236
+ ].join("");
1237
+ }, O = (n) => {
1238
+ if (n) {
1239
+ const { Type: e, Content: t } = n;
1240
+ if (e && t)
1241
+ return { type: e, content: t };
1242
+ }
1243
+ }, ie = (n) => n.map((e) => {
1244
+ const t = {
1245
+ id: e.Id.toString(),
1246
+ title: e.Name,
1247
+ symbol: O(e.DefaultIcon),
1248
+ activeSymbol: e.ActiveIcon && O(e.ActiveIcon),
1249
+ description: e.Description || e.Attributes && e.Attributes.description || "",
1250
+ matches: e.GuidesCount
1251
+ };
1252
+ return e.Children && e.Children.length && (t.items = ie(e.Children)), t;
1253
+ }), P = (n, e) => n.filter(({ Type: t }) => t === e).map(({ Id: t, Title: i, Body: s }) => ({
1254
+ id: t.toString(),
1255
+ title: i,
1256
+ body: s
1257
+ })), ee = (n) => n.map(({ Id: e, Title: t, DefaultIcon: i, ListNotices: s, Notices: r }) => ({
1258
+ id: e.toString(),
1259
+ title: t,
1260
+ symbol: O(i),
1261
+ defaultHeaderOptions: {
1262
+ visible: !!s.length
1263
+ },
1264
+ notifications: (s || []).concat(r || []).map(({ Id: a, Title: o, Body: c, Type: h, Modified: d }) => ({
1265
+ id: a.toString(),
1266
+ title: o,
1267
+ body: c,
1268
+ modified: d,
1269
+ expandable: h === "listNotice"
1270
+ }))
1271
+ })), te = ({
1272
+ Id: n,
1273
+ Title: e,
1274
+ DefaultIcon: t,
1275
+ Exits: [i],
1276
+ ExitType: s,
1277
+ ConfirmationText: r,
1278
+ Description: a
1279
+ }, o) => {
1280
+ const { Adapter: c } = i || { Adapter: {} }, { ClientName: h = "", Settings: d = {}, CustomClientName: g = "" } = c, u = {
1281
+ id: n.toString(),
1282
+ title: e,
1283
+ description: a,
1284
+ symbol: O(t),
1285
+ clientName: h === "custom.adapter" ? g : h,
1286
+ expanded: !0,
1287
+ inline: !0,
1288
+ body: {}
1289
+ };
1290
+ if (h.indexOf("phone") > -1 || h.indexOf("freetext") > -1) {
1291
+ const { displayTextBeforeClick: p, textBeforeClick: b } = d;
1292
+ p === "true" && (u.expanded = !1, u.title = b), h.indexOf("phone.text") > -1 ? u.body.phoneNumber = d.phoneNumber : u.body.freetext = d.freetext;
1293
+ }
1294
+ return (h.indexOf("chat.popup") > -1 || h.indexOf("link") > -1 || h === "custom.adapter" && s === "custom") && (u.body = d, u.body.confirmationFallback = r), h.indexOf("ace") > -1 && (u.body = d), u;
1295
+ }, j = (n = []) => n.map(
1296
+ ({ Id: e, Title: t, TotalMatches: i, Symbol: s, DefaultIcon: r, ActiveIcon: a }) => ({
1297
+ id: e.toString(),
1298
+ title: t,
1299
+ matches: i,
1300
+ symbol: O(r || s),
1301
+ defaultIcon: O(r),
1302
+ activeIcon: O(a)
1303
+ })
1304
+ ), ne = (n) => n.map(({ Id: e, Title: t, Tags: i, FirstPublishedDate: s, Modified: r }) => ({
1305
+ id: e.toString(),
1306
+ title: t,
1307
+ tags: j(i),
1308
+ published: s,
1309
+ modified: r
1310
+ })), Pt = (n, e) => {
1311
+ switch (n) {
1312
+ case C.MatchByCategory:
1313
+ case C.Match: {
1314
+ const t = {
1315
+ guides: [],
1316
+ matches: 0,
1317
+ topNotifications: [],
1318
+ middleNotifications: [],
1319
+ bottomNotifications: [],
1320
+ notificationLists: [],
1321
+ tags: [],
1322
+ byCategory: []
1323
+ }, {
1324
+ Matches: i,
1325
+ TotalMatches: s,
1326
+ Notices: r,
1327
+ NoticeLists: a,
1328
+ Tags: o,
1329
+ ByCategory: c
1330
+ } = e;
1331
+ return t.guides = ne(i), t.matches = s, t.byCategory = (c || []).map(
1332
+ ({ Id: h, Matches: d, TotalMatches: g }) => ({
1333
+ id: h,
1334
+ guides: ne(d),
1335
+ matches: g
1336
+ })
1337
+ ), t.tags = j(o), t.notificationLists = ee(a || []), t.topNotifications = P(r || [], "noticeRowTop"), t.middleNotifications = P(r || [], "noticeRowMiddle"), t.bottomNotifications = P(r || [], "footerNotice"), t;
1338
+ }
1339
+ case C.Categories: {
1340
+ const { Children: t, GuidesCountTotal: i } = e;
1341
+ return {
1342
+ categories: ie(t || []),
1343
+ matches: i
1344
+ };
1345
+ }
1346
+ case C.Guide: {
1347
+ const {
1348
+ Id: t,
1349
+ Title: i,
1350
+ Body: s,
1351
+ Related: r,
1352
+ Options: a,
1353
+ ConnectionId: o,
1354
+ ContactMethods: c,
1355
+ EnableFeedback: h,
1356
+ HandoverExists: d,
1357
+ FirstPublishedDate: g,
1358
+ Modified: u,
1359
+ ModifiedByDisplayName: p,
1360
+ FirstPublishedByDisplayName: b,
1361
+ Categories: w,
1362
+ Tags: l,
1363
+ SeoMetaDescription: f,
1364
+ SeoAllowIndex: Y,
1365
+ Perspectives: _,
1366
+ PerspectiveKey: ce,
1367
+ Translations: he
1368
+ } = e, je = ce || Object.values(_).find(
1369
+ (N) => N === o
1370
+ ) || _.Default || null, le = {
1371
+ guide: {
1372
+ id: t.toString(),
1373
+ title: i,
1374
+ body: s,
1375
+ modified: u,
1376
+ published: g,
1377
+ modifiedBy: p,
1378
+ publishedBy: b,
1379
+ connection: o,
1380
+ categories: w,
1381
+ hasHandover: d,
1382
+ allowFeedback: h,
1383
+ seoMetaDescription: f,
1384
+ seoAllowIndex: Y,
1385
+ perspectives: _,
1386
+ perspective: je,
1387
+ translations: Object.keys(he || {}).reduce((N, T) => (N[T] = he[T].toString(), N), {})
1388
+ },
1389
+ related: ne(r || []),
1390
+ dialog: [],
1391
+ contactMethods: (c || []).map(
1392
+ (N) => te(N)
1393
+ ),
1394
+ tags: j(l)
1395
+ };
1396
+ return (a || []).forEach(
1397
+ ({ CanAccess: N, Description: T, ConnectionId: qe, Properties: k }) => {
1398
+ if (!N)
1399
+ return;
1400
+ const I = {
1401
+ id: t.toString(),
1402
+ title: T,
1403
+ connection: qe,
1404
+ connectionKey: k.ConnectionKey,
1405
+ type: "default",
1406
+ parent: {
1407
+ id: t.toString(),
1408
+ title: i,
1409
+ tags: j(l)
1410
+ }
1411
+ };
1412
+ if (k.Type === "Guide" || k.Type === "Link")
1413
+ switch (k.Id && (I.id = k.Id.toString()), k.Uri && (I.href = k.Uri), k.Target && (I.target = k.Target), k.Type) {
1414
+ case "Guide":
1415
+ I.type = "guide";
1416
+ break;
1417
+ case "Link":
1418
+ I.type = "link";
1419
+ break;
1420
+ }
1421
+ le.dialog.push(I);
1422
+ }
1423
+ ), le;
1424
+ }
1425
+ case C.Contacts: {
1426
+ const {
1427
+ Children: t,
1428
+ Matches: i,
1429
+ Notices: s,
1430
+ NoticeLists: r
1431
+ } = e;
1432
+ return {
1433
+ contactMethods: (i || []).map(
1434
+ (o) => te(o)
1435
+ ),
1436
+ categories: ie(t || []),
1437
+ topNotifications: P(s || [], "noticeRowTop"),
1438
+ middleNotifications: P(s || [], "noticeRowMiddle"),
1439
+ bottomNotifications: P(s || [], "footerNotice"),
1440
+ notificationLists: ee(r || [])
1441
+ };
1442
+ }
1443
+ case C.ContactMethod: {
1444
+ const { ContactMethod: t } = e;
1445
+ return te(t || {});
1446
+ }
1447
+ case C.Tags:
1448
+ case C.TagsOnGuides:
1449
+ return j(e || []);
1450
+ case C.Notifications: {
1451
+ const { Notices: t, NoticeLists: i } = e;
1452
+ return {
1453
+ topNotifications: P(t || [], "noticeRowTop"),
1454
+ middleNotifications: P(t || [], "noticeRowMiddle"),
1455
+ bottomNotifications: P(t || [], "footerNotice"),
1456
+ notificationLists: ee(i || [])
1457
+ };
1458
+ }
1459
+ default:
1460
+ return {};
1461
+ }
1462
+ };
1463
+ var Et = /* @__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))(Et || {}), C = /* @__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))(C || {}), At = /* @__PURE__ */ ((n) => (n.Positive = "Positive", n.Negative = "Negative", n))(At || {}), Nt = /* @__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))(Nt || {});
1464
+ const Ee = (n) => {
1465
+ switch (n) {
1466
+ case "guides":
1467
+ return "match";
1468
+ case "guides-by-category":
1469
+ return "match-by-category";
1470
+ case "guide":
1471
+ return "guide";
1472
+ case "guide-categories":
1473
+ return "categories";
1474
+ case "contact-method-categories":
1475
+ case "contact-methods":
1476
+ return "contacts";
1477
+ case "contact-method":
1478
+ return "contact-method";
1479
+ case "tags":
1480
+ return "tags";
1481
+ case "tagsonguides":
1482
+ return "tagsonguides";
1483
+ case "notification-lists":
1484
+ case "row-notices":
1485
+ return "notifications";
1486
+ default:
1487
+ throw "error";
1488
+ }
1489
+ }, xt = async (n) => {
1490
+ const { invoke: e } = n.get("$widget");
1491
+ return await e("renderState") === V.hidden;
1492
+ };
1493
+ class q {
1494
+ constructor(e, t) {
1495
+ this.container = e, this.matchingClient = t, this.queries = /* @__PURE__ */ new Map(), this.getUnresolvedQueries = () => {
1496
+ let i = 0;
1497
+ return this.queries.forEach((s, r) => {
1498
+ s.some((o) => !o.resolved) && (i = 1);
1499
+ }), i;
1500
+ }, this.events = e.get("$widget").events, this.events.subscribe(
1501
+ "widget:settings-updated",
1502
+ () => this.queries = /* @__PURE__ */ new Map()
1503
+ ), this.events.subscribe(
1504
+ "widget:render-state-changed",
1505
+ (i, { next: s, previous: r }) => {
1506
+ r === V.hidden && s === V.open && this.fetchAllUnresolvedQueries();
1507
+ }
1508
+ );
1509
+ }
1510
+ static getInstance(e, t = "dataClient") {
1511
+ return mt(this)(() => e.getAsync(t).then(async (i) => {
1512
+ let s = await e.getAsync("matchingClient");
1513
+ s || (s = await Pe(e), e.registerAsync("matchingClient", () => s));
1514
+ let r = i;
1515
+ return r || (r = new q(e, s), e.registerAsync(t, () => r)), r;
1516
+ }));
1517
+ }
1518
+ fetch(e, t, i) {
1519
+ return new Promise((s, r) => {
1520
+ t.take, vt(t);
1521
+ const a = Ee(e);
1522
+ let o = this.queries.get(a) || [], c = o.find((h) => F(h.params, t)) || null;
1523
+ if (c && (i != null && i.noCache)) {
1524
+ const h = o.findIndex(
1525
+ (d) => F(d.params, t)
1526
+ );
1527
+ o = [...o.slice(0, h), ...o.slice(h + 1)], c = null;
1528
+ }
1529
+ if (c) {
1530
+ const h = o.indexOf(c);
1531
+ if (c.resolved ? (this.events.dispatch("data-client:fetched", {
1532
+ params: t,
1533
+ type: a,
1534
+ response: c.data,
1535
+ unresolvedQueries: this.getUnresolvedQueries()
1536
+ }), this.track(c.data, a, c.error), c.data && c.error ? r({ error: c.error }) : s(c.data)) : c.resolvers.push({ resolve: s, reject: r }), o.splice(h, 1), o.push(c), this.queries.set(a, o), !c.loading && !c.resolved)
1537
+ return this.runQuery(a, t);
1538
+ } else
1539
+ return o.push({
1540
+ params: t,
1541
+ resolved: !1,
1542
+ loading: !0,
1543
+ data: {},
1544
+ resolvers: [{ resolve: s, reject: r }]
1545
+ }), this.queries.set(a, o), this.runQuery(a, t);
1546
+ }).then((s) => gt(s));
1547
+ }
1548
+ // query the cached data
1549
+ read(e, t) {
1550
+ const { select: i } = t, s = Ee(e);
1551
+ return (this.queries.get(s) || []).reduce((o, c) => {
1552
+ if (typeof i == "function") {
1553
+ const h = i(c.data);
1554
+ h && o.push(h);
1555
+ } else
1556
+ o.push(c.data);
1557
+ return o;
1558
+ }, []);
1559
+ }
1560
+ feedback(e, t, i) {
1561
+ return this.matchingClient.giveFeedback(e, t, i);
1562
+ }
1563
+ setLoadingStatus(e, t, i) {
1564
+ const s = this.queries.get(e) || [], r = s.find((a) => F(a.params, t));
1565
+ r && (r.loading = i), this.queries.set(e, s);
1566
+ }
1567
+ async runQuery(e, t) {
1568
+ const {
1569
+ searchPhrase: i = "",
1570
+ categories: s = "0",
1571
+ contactMethodCategoryId: r = "0",
1572
+ contactMethodId: a = "0",
1573
+ tagId: o = void 0,
1574
+ take: c = 5,
1575
+ connection: h = "",
1576
+ guideId: d,
1577
+ expandCategories: g = "descendants",
1578
+ currentCategory: u,
1579
+ sorting: p = "popularity-descending",
1580
+ guideIds: b = []
1581
+ } = t, w = i.toString().trim();
1582
+ if (await xt(this.container))
1583
+ return Promise.resolve();
1584
+ switch (e) {
1585
+ case "match": {
1586
+ const l = (f) => {
1587
+ const [Y, _] = f.split("-");
1588
+ return {
1589
+ type: (/* @__PURE__ */ new Map([
1590
+ ["popularity", "popularity"],
1591
+ ["alphabetic", "title"],
1592
+ ["modified", "lastModified"],
1593
+ ["published", "firstPublished"]
1594
+ ])).get(Y),
1595
+ direction: _
1596
+ };
1597
+ };
1598
+ return b.length ? this.matchingClient.customRequest("guides", "POST", {
1599
+ configuration: { ids: b, take: +c }
1600
+ }).then(
1601
+ (f) => f && this.handleResponse(f, e, t)
1602
+ ) : this.matchingClient.match(w, {
1603
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s],
1604
+ take: +c,
1605
+ tags: o,
1606
+ sorting: l(p),
1607
+ ids: b
1608
+ }).then(
1609
+ (f) => f && this.handleResponse(f, e, t)
1610
+ );
1611
+ }
1612
+ case "match-by-category":
1613
+ return this.matchingClient.match(w, {
1614
+ groupByCategory: !0,
1615
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s],
1616
+ take: +c,
1617
+ tags: o
1618
+ }).then(
1619
+ (l) => l && this.handleResponse(l, e, t)
1620
+ );
1621
+ case "guide":
1622
+ return this.matchingClient.getGuide(d, { connectionId: h }).then((l) => {
1623
+ l && this.handleResponse(l, e, t);
1624
+ }).catch((l) => {
1625
+ const f = {
1626
+ message: "Something went wrong.",
1627
+ status: l.status || 400
1628
+ };
1629
+ f.status === 404 && (f.message = "The guide could not be found."), this.handleResponse({}, e, t, f);
1630
+ });
1631
+ case "categories":
1632
+ return this.matchingClient.getCategories({
1633
+ phrase: w,
1634
+ expand: g,
1635
+ tags: o
1636
+ }).then(
1637
+ (l) => l && this.handleResponse(l, e, t)
1638
+ );
1639
+ case "contacts":
1640
+ return d ? this.matchingClient.contactMethods(+d, { phrase: w }).then(
1641
+ (l) => l && this.handleResponse(l, e, t)
1642
+ ) : this.matchingClient.contacts(+r, { phrase: w }).then(
1643
+ (l) => l && this.handleResponse(l, e, t)
1644
+ );
1645
+ case "contact-method":
1646
+ return this.matchingClient.getContactMethod(+a, { guideId: d, currentCategory: u }).then(
1647
+ (l) => l && this.handleResponse(l, e, t)
1648
+ );
1649
+ case "tags":
1650
+ return this.matchingClient.customRequest("tags", "GET", {
1651
+ configuration: {
1652
+ take: 999999,
1653
+ phrase: w,
1654
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s]
1655
+ }
1656
+ }).then(
1657
+ (l) => l && this.handleResponse(l, e, t)
1658
+ );
1659
+ case "tagsonguides":
1660
+ return this.matchingClient.customRequest("tagsonguides", "GET", {
1661
+ configuration: {
1662
+ take: 999999,
1663
+ phrase: w,
1664
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s],
1665
+ tags: o
1666
+ }
1667
+ }).then(
1668
+ (l) => l && this.handleResponse(l, e, t)
1669
+ );
1670
+ case "notifications":
1671
+ return this.matchingClient.customRequest("notices", "GET", {
1672
+ configuration: {
1673
+ phrase: w,
1674
+ categories: s === "0" ? [] : Array.isArray(s) ? s : [+s]
1675
+ }
1676
+ }).then(
1677
+ (l) => l && this.handleResponse(l, e, t)
1678
+ );
1679
+ }
1680
+ }
1681
+ handleResponse(e = {}, t, i, s) {
1682
+ const r = this.queries.get(t) || [], a = r.find((o) => F(o.params, i));
1683
+ if (a) {
1684
+ const o = s || Pt(t, e);
1685
+ this.track(o, t, s), a.resolvers.forEach((h) => {
1686
+ s ? h.reject({ error: o }) : h.resolve(o);
1687
+ });
1688
+ const c = r.indexOf(a);
1689
+ c > -1 && r.splice(c, 1), r.push({
1690
+ ...a,
1691
+ error: s,
1692
+ resolvers: [],
1693
+ data: o,
1694
+ resolved: !0
1695
+ }), this.setLoadingStatus(t, i, !1), this.queries.set(t, r), s || this.events.dispatch("data-client:fetched", {
1696
+ type: t,
1697
+ params: i,
1698
+ response: o,
1699
+ unresolvedQueries: this.getUnresolvedQueries()
1700
+ });
1701
+ }
1702
+ }
1703
+ fetchAllUnresolvedQueries() {
1704
+ for (const [e, t] of this.queries)
1705
+ t.filter((i) => !i.resolved).forEach((i) => {
1706
+ this.runQuery(e, i.params);
1707
+ });
1708
+ }
1709
+ track(e = {}, t, i) {
1710
+ const s = this.container.get("$widget");
1711
+ s && !i ? s.events.dispatch("tracking:service-client-response", {
1712
+ type: t,
1713
+ data: e
1714
+ }) : s && s.events.dispatch("tracking:service-client-error", {
1715
+ type: t,
1716
+ error: i
1717
+ });
1718
+ }
1719
+ static create(e) {
1720
+ return e.getAsync("matchingClient").then(async (t) => {
1721
+ if (t)
1722
+ return new q(e, t);
1723
+ const i = await Pe(e);
1724
+ return e.registerAsync("matchingClient", () => i), new q(e, i);
1725
+ });
1726
+ }
1727
+ getClient() {
1728
+ return this.matchingClient;
1729
+ }
1730
+ }
1731
+ const Lt = async (n) => {
1732
+ n.registerAsync("dataClient", () => q.create(n));
1733
+ };
1734
+ export {
1735
+ q as DataClient,
1736
+ Et as DataType,
1737
+ At as FeedbackType,
1738
+ Lt as KnowledgeDataClientPlugin,
1739
+ C as ServiceClientQueryType,
1740
+ Nt as SortingType,
1741
+ Ee as determineServiceClientQueryType,
1742
+ Pt as formatLegacyData
1743
+ };