@gengage/assistant-fe 0.4.0 → 0.4.2

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.
@@ -1,10 +1,10 @@
1
- import { a as k, c as h, i as D, o as f, r as m, t as A } from "./schemas-JFGRVTVz.js";
1
+ import { a as N, c as h, i as W, o as f, r as m, t as A } from "./schemas-JFGRVTVz.js";
2
2
  import { U as H, h as Q, j, r as M, y as K } from "./locale-MM0U5eeR.js";
3
- import { t as V } from "./chat-ChY1FmRk.js";
3
+ import { t as V } from "./chat-Ci4ZA37X.js";
4
4
  import { t as $ } from "./qna-CQugVOHy.js";
5
5
  import { t as G } from "./simrel-DjzpRZmZ.js";
6
6
  import { t as Y } from "./simbut-Cb5RfaAp.js";
7
- var b = f({ enabled: m().default(!0) }), J = f({
7
+ var w = f({ enabled: m().default(!0) }), J = f({
8
8
  chat: h().optional(),
9
9
  qna: h().optional(),
10
10
  simrel: h().optional(),
@@ -29,8 +29,8 @@ var b = f({ enabled: m().default(!0) }), J = f({
29
29
  fireAndForget: m().default(!0),
30
30
  useBeacon: m().default(!0),
31
31
  keepaliveFetch: m().default(!0),
32
- timeoutMs: k().int().positive().default(4e3),
33
- maxRetries: k().int().min(0).max(5).default(1)
32
+ timeoutMs: N().int().positive().default(4e3),
33
+ maxRetries: N().int().min(0).max(5).default(1)
34
34
  }), R = "__gengageWidgetsInit", te = f({
35
35
  idempotencyKey: h().default(R),
36
36
  requireDomReady: m().default(!0)
@@ -42,15 +42,15 @@ var b = f({ enabled: m().default(!0) }), J = f({
42
42
  unknownActionPolicy: ie.default("log-and-ignore"),
43
43
  allowScriptCall: m().default(!1)
44
44
  }), L = f({
45
- version: D("1", { error: 'version must be "1"' }),
45
+ version: W("1", { error: 'version must be "1"' }),
46
46
  accountId: h({ error: "accountId must be a non-empty string" }).min(1, { error: "accountId must be a non-empty string" }),
47
47
  middlewareUrl: h({ error: 'middlewareUrl must be a valid URL (e.g. "https://your-backend.example.com")' }).url({ error: 'middlewareUrl must be a valid URL (e.g. "https://your-backend.example.com")' }),
48
48
  locale: h().optional(),
49
49
  widgets: f({
50
- chat: b.default({ enabled: !0 }),
51
- qna: b.default({ enabled: !0 }),
52
- simrel: b.default({ enabled: !0 }),
53
- simbut: b.default({ enabled: !1 })
50
+ chat: w.default({ enabled: !0 }),
51
+ qna: w.default({ enabled: !0 }),
52
+ simrel: w.optional(),
53
+ simbut: w.default({ enabled: !1 })
54
54
  }),
55
55
  mounts: J.default({}),
56
56
  transport: X.default({}),
@@ -84,10 +84,10 @@ function se(e) {
84
84
  middlewareUrl: t.middlewareUrl
85
85
  }), t;
86
86
  }
87
- function qe(e) {
87
+ function ke(e) {
88
88
  return L.safeParse(e);
89
89
  }
90
- function Ne(e) {
90
+ function qe(e) {
91
91
  return se({
92
92
  version: "1",
93
93
  accountId: e.accountId,
@@ -96,13 +96,12 @@ function Ne(e) {
96
96
  widgets: {
97
97
  chat: { enabled: !0 },
98
98
  qna: { enabled: !0 },
99
- simrel: { enabled: !0 },
100
99
  simbut: { enabled: !1 }
101
100
  }
102
101
  });
103
102
  }
104
103
  var P = `${R}_overlay_`, oe = "#gengage-qna", ae = "#gengage-simrel", re = "#gengage-simbut";
105
- function S() {
104
+ function I() {
106
105
  const e = window;
107
106
  return e.__gengageOverlayRegistry || (e.__gengageOverlayRegistry = {
108
107
  instances: {},
@@ -121,13 +120,13 @@ function le(e, t) {
121
120
  };
122
121
  return t.pageType !== void 0 && t.pageType !== e.pageType ? (t.pageType !== "pdp" && t.sku === void 0 && delete i.sku, t.pageType !== "plp" && t.skuList === void 0 && delete i.skuList) : (t.sku === void 0 && e.sku !== void 0 && (i.sku = e.sku), t.skuList === void 0 && e.skuList !== void 0 && (i.skuList = e.skuList)), i;
123
122
  }
124
- function I(e) {
123
+ function S(e) {
125
124
  return e instanceof HTMLElement || document.querySelector(e) ? e : null;
126
125
  }
127
126
  function B(e) {
128
127
  return e.idempotencyKey ?? `${P}${e.accountId}`;
129
128
  }
130
- var ue = class {
129
+ var ce = class {
131
130
  constructor(e, t) {
132
131
  this.options = e, this.onDestroy = t, this._chat = null, this._qna = null, this._simrel = null, this._simbut = null, this._analyticsClient = null, this._offQnaWire = null, this._destroyed = !1, this._queue = Promise.resolve(), this._warnedQnaMountMissing = !1, this._warnedSimRelMountMissing = !1, this._warnedSimButMountMissing = !1, this._warnedSimButNoChat = !1, this.idempotencyKey = B(e), this.session = Q(e.session), this._pageContext = de(e);
133
132
  }
@@ -184,7 +183,7 @@ var ue = class {
184
183
  pageContext: this._pageContext,
185
184
  variant: this.options.chat?.variant ?? "floating"
186
185
  };
187
- this.options.theme !== void 0 && (s.theme = this.options.theme), this.options.locale !== void 0 && (s.locale = this.options.locale), this.options.pricing !== void 0 && (s.pricing = this.options.pricing), this.options.chat?.mountTarget !== void 0 && (s.mountTarget = this.options.chat.mountTarget), this.options.chat?.pillLauncher !== void 0 && (s.pillLauncher = this.options.chat.pillLauncher), this.options.chat?.launcherImageUrl !== void 0 ? s.launcherImageUrl = this.options.chat.launcherImageUrl : this.options.chat?.launcherSvg !== void 0 && (s.launcherSvg = this.options.chat.launcherSvg), this.options.chat?.headerTitle !== void 0 && (s.headerTitle = this.options.chat.headerTitle), this.options.chat?.headerAvatarUrl !== void 0 && (s.headerAvatarUrl = this.options.chat.headerAvatarUrl), this.options.chat?.headerBadge !== void 0 && (s.headerBadge = this.options.chat.headerBadge), this.options.chat?.headerCartUrl !== void 0 && (s.headerCartUrl = this.options.chat.headerCartUrl), this.options.chat?.headerFavoritesToggle !== void 0 && (s.headerFavoritesToggle = this.options.chat.headerFavoritesToggle), this.options.chat?.onFavoritesClick !== void 0 && (s.onFavoritesClick = this.options.chat.onFavoritesClick), this.options.chat?.hideMobileLauncher !== void 0 && (s.hideMobileLauncher = this.options.chat.hideMobileLauncher), this.options.chat?.mobileBreakpoint !== void 0 && (s.mobileBreakpoint = this.options.chat.mobileBreakpoint), this.options.chat?.mobileInitialState !== void 0 && (s.mobileInitialState = this.options.chat.mobileInitialState), this.options.chat?.i18n !== void 0 && (s.i18n = this.options.chat.i18n), this.options.chat?.actionHandling !== void 0 && (s.actionHandling = this.options.chat.actionHandling), this.options.chat?.renderer !== void 0 && (s.renderer = this.options.chat.renderer), t !== void 0 && (s.productDetailsExtended = t), i !== void 0 && (s.isDemoWebsite = i), this.options.chat?.productPriceUi !== void 0 && (s.productPriceUi = this.options.chat.productPriceUi), this.options.onScriptCall !== void 0 && (s.onScriptCall = this.options.onScriptCall), this.options.onAddToCart !== void 0 && (s.onAddToCart = this.options.onAddToCart), this.options.chat?.onOpen !== void 0 && (s.onOpen = this.options.chat.onOpen), this.options.chat?.onClose !== void 0 && (s.onClose = this.options.chat.onClose), this._chat = new V(), await this._chat.init(s);
186
+ this.options.theme !== void 0 && (s.theme = this.options.theme), this.options.locale !== void 0 && (s.locale = this.options.locale), this.options.pricing !== void 0 && (s.pricing = this.options.pricing), this.options.chat?.mountTarget !== void 0 && (s.mountTarget = this.options.chat.mountTarget), this.options.chat?.pillLauncher !== void 0 && (s.pillLauncher = this.options.chat.pillLauncher), this.options.chat?.launcherImageUrl !== void 0 ? s.launcherImageUrl = this.options.chat.launcherImageUrl : this.options.chat?.launcherSvg !== void 0 && (s.launcherSvg = this.options.chat.launcherSvg), this.options.chat?.headerTitle !== void 0 && (s.headerTitle = this.options.chat.headerTitle), this.options.chat?.headerAvatarUrl !== void 0 && (s.headerAvatarUrl = this.options.chat.headerAvatarUrl), this.options.chat?.headerBadge !== void 0 && (s.headerBadge = this.options.chat.headerBadge), this.options.chat?.headerCartUrl !== void 0 && (s.headerCartUrl = this.options.chat.headerCartUrl), this.options.chat?.headerFavoritesToggle !== void 0 && (s.headerFavoritesToggle = this.options.chat.headerFavoritesToggle), this.options.chat?.onFavoritesClick !== void 0 && (s.onFavoritesClick = this.options.chat.onFavoritesClick), this.options.chat?.hideMobileLauncher !== void 0 && (s.hideMobileLauncher = this.options.chat.hideMobileLauncher), this.options.chat?.mobileBreakpoint !== void 0 && (s.mobileBreakpoint = this.options.chat.mobileBreakpoint), this.options.chat?.mobileInitialState !== void 0 && (s.mobileInitialState = this.options.chat.mobileInitialState), this.options.chat?.i18n !== void 0 && (s.i18n = this.options.chat.i18n), this.options.chat?.actionHandling !== void 0 && (s.actionHandling = this.options.chat.actionHandling), this.options.chat?.renderer !== void 0 && (s.renderer = this.options.chat.renderer), t !== void 0 && (s.productDetailsExtended = t), i !== void 0 && (s.isDemoWebsite = i), this.options.chat?.productPriceUi !== void 0 && (s.productPriceUi = this.options.chat.productPriceUi), this.options.chat?.hideProductDiscountBadge !== void 0 && (s.hideProductDiscountBadge = this.options.chat.hideProductDiscountBadge), this.options.chat?.hideUserReviews !== void 0 && (s.hideUserReviews = this.options.chat.hideUserReviews), this.options.chat?.hideStockStatus !== void 0 && (s.hideStockStatus = this.options.chat.hideStockStatus), this.options.onScriptCall !== void 0 && (s.onScriptCall = this.options.onScriptCall), this.options.onAddToCart !== void 0 && (s.onAddToCart = this.options.onAddToCart), this.options.chat?.onOpen !== void 0 && (s.onOpen = this.options.chat.onOpen), this.options.chat?.onClose !== void 0 && (s.onClose = this.options.chat.onClose), this._chat = new V(), await this._chat.init(s);
188
187
  }
189
188
  async _syncPdpWidgets() {
190
189
  if (this._destroyed) return;
@@ -195,7 +194,7 @@ var ue = class {
195
194
  }
196
195
  const t = this.options.middlewareUrl;
197
196
  if (this.options.qna?.enabled !== !1) {
198
- const i = this.options.qna?.mountTarget ?? oe, s = I(i);
197
+ const i = this.options.qna?.mountTarget ?? oe, s = S(i);
199
198
  if (s)
200
199
  if (this._warnedQnaMountMissing = !1, this._qna)
201
200
  this._qna.show(), this._qna.update({
@@ -221,8 +220,8 @@ var ue = class {
221
220
  this._qna?.destroy(), this._qna = null, this._warnedQnaMountMissing || (console.warn(`[gengage] QNA mount target not found: ${i}`), this._warnedQnaMountMissing = !0);
222
221
  } else
223
222
  this._qna?.destroy(), this._qna = null;
224
- if (this.options.simrel?.enabled !== !1) {
225
- const i = this.options.simrel?.mountTarget ?? ae, s = I(i);
223
+ if (this.options.simrel !== void 0 && this.options.simrel.enabled !== !1) {
224
+ const i = this.options.simrel?.mountTarget ?? ae, s = S(i);
226
225
  if (s)
227
226
  if (this._warnedSimRelMountMissing = !1, this._simrel)
228
227
  this._simrel.show(), this._simrel.update({
@@ -246,7 +245,7 @@ var ue = class {
246
245
  } else
247
246
  this._simrel?.destroy(), this._simrel = null;
248
247
  if (this.options.simbut && this.options.simbut.enabled !== !1) {
249
- const i = this.options.simbut.mountTarget ?? re, s = I(i), o = this._chat ?? this.options.simbut.onFindSimilar;
248
+ const i = this.options.simbut.mountTarget ?? re, s = S(i), o = this._chat ?? this.options.simbut.onFindSimilar;
250
249
  if (s && o)
251
250
  if (this._warnedSimButMountMissing = !1, this._warnedSimButNoChat = !1, this._simbut)
252
251
  this._simbut.show(), this._simbut.setChat(this._chat), this._simbut.update({
@@ -278,13 +277,13 @@ var ue = class {
278
277
  }), t;
279
278
  }
280
279
  };
281
- async function ce(e) {
282
- const t = B(e), i = S(), s = i.instances[t];
280
+ async function ue(e) {
281
+ const t = B(e), i = I(), s = i.instances[t];
283
282
  if (s) return s;
284
283
  const o = i.pending[t];
285
284
  if (o) return o;
286
- const n = new ue(e, () => {
287
- const l = S();
285
+ const n = new ce(e, () => {
286
+ const l = I();
288
287
  delete l.instances[t], delete l.pending[t];
289
288
  }), d = n.init().then(() => (i.instances[t] = n, delete i.pending[t], n)).catch((l) => {
290
289
  throw delete i.pending[t], j({
@@ -295,9 +294,9 @@ async function ce(e) {
295
294
  return i.pending[t] = d, d;
296
295
  }
297
296
  function ge(e) {
298
- return S().instances[e] ?? null;
297
+ return I().instances[e] ?? null;
299
298
  }
300
- function ke(e) {
299
+ function Ne(e) {
301
300
  ge(e)?.destroy();
302
301
  }
303
302
  function Me(e) {
@@ -361,11 +360,11 @@ function me(e) {
361
360
  }
362
361
  return null;
363
362
  }
364
- function q(e, t) {
363
+ function k(e, t) {
365
364
  return t instanceof HTMLElement ? !0 : typeof t != "string" ? !1 : e.document.querySelector(t) !== null;
366
365
  }
367
366
  function E(e, t, i) {
368
- if (t instanceof HTMLElement || q(e, t) || typeof t != "string") return t;
367
+ if (t instanceof HTMLElement || k(e, t) || typeof t != "string") return t;
369
368
  if (t.startsWith("#")) {
370
369
  const n = t.slice(1);
371
370
  if (n.length > 0) {
@@ -380,17 +379,17 @@ function E(e, t, i) {
380
379
  const o = e.document.createElement("div");
381
380
  return o.id = i, e.document.body.appendChild(o), o;
382
381
  }
383
- function O(e, t) {
382
+ function D(e, t) {
384
383
  const i = e.webkit?.messageHandlers?.[t];
385
384
  return i && typeof i.postMessage == "function" ? i.postMessage.bind(i) : null;
386
385
  }
387
- function w(e, t) {
386
+ function b(e, t) {
388
387
  const i = e[t];
389
388
  return i && typeof i == "object" && typeof i.postMessage == "function" ? i : null;
390
389
  }
391
390
  function ve(e = {}) {
392
391
  const t = e.win ?? window, i = e.iosHandlerName ?? "gengage", s = e.androidInterfaceName ?? "GengageNative", o = e.reactNativeInterfaceName ?? "ReactNativeWebView";
393
- return O(t, i) ? "ios" : w(t, s) ? "android" : w(t, o) ? "react-native" : "browser";
392
+ return D(t, i) ? "ios" : b(t, s) ? "android" : b(t, o) ? "react-native" : "browser";
394
393
  }
395
394
  function ye(e, t = {}) {
396
395
  const i = t.win ?? window;
@@ -417,25 +416,25 @@ function _e(e = {}) {
417
416
  reactNativeInterfaceName: n
418
417
  });
419
418
  let a = t.gengage?.overlay ?? null;
420
- const c = [], v = (u, r) => {
421
- const p = r === void 0 ? { type: u } : {
422
- type: u,
419
+ const u = [], v = (c, r) => {
420
+ const p = r === void 0 ? { type: c } : {
421
+ type: c,
423
422
  payload: r
424
423
  };
425
424
  if (l === "ios") {
426
- O(t, s)?.(p);
425
+ D(t, s)?.(p);
427
426
  return;
428
427
  }
429
428
  if (l === "android") {
430
- w(t, o)?.postMessage(JSON.stringify(p));
429
+ b(t, o)?.postMessage(JSON.stringify(p));
431
430
  return;
432
431
  }
433
432
  if (l === "react-native") {
434
- w(t, n)?.postMessage(JSON.stringify(p));
433
+ b(t, n)?.postMessage(JSON.stringify(p));
435
434
  return;
436
435
  }
437
- }, y = (u) => {
438
- const r = u.detail;
436
+ }, y = (c) => {
437
+ const r = c.detail;
439
438
  !r || typeof r.namespace != "string" || typeof r.type != "string" || v("bridge_message", {
440
439
  namespace: r.namespace,
441
440
  type: r.type,
@@ -443,28 +442,28 @@ function _e(e = {}) {
443
442
  });
444
443
  };
445
444
  t.addEventListener("gengage:bridge:message", y);
446
- const F = d.map((u) => {
445
+ const O = d.map((c) => {
447
446
  const r = (p) => {
448
447
  const g = p.detail;
449
448
  v("widget_event", {
450
- event: u,
449
+ event: c,
451
450
  detail: g
452
451
  });
453
452
  };
454
- return t.addEventListener(u, r), {
455
- event: u,
453
+ return t.addEventListener(c, r), {
454
+ event: c,
456
455
  handler: r
457
456
  };
458
- }), _ = (u) => {
459
- c.length >= pe && c.shift(), c.push(u);
460
- }, W = () => {
461
- if (!a || c.length === 0) return;
462
- const u = c.splice(0, c.length);
463
- for (const r of u) N(r);
464
- }, N = (u) => {
465
- const r = fe(u);
457
+ }), _ = (c) => {
458
+ u.length >= pe && u.shift(), u.push(c);
459
+ }, F = () => {
460
+ if (!a || u.length === 0) return;
461
+ const c = u.splice(0, u.length);
462
+ for (const r of c) q(r);
463
+ }, q = (c) => {
464
+ const r = fe(c);
466
465
  if (!r || typeof r.type != "string") {
467
- console.warn("[gengage:native-bridge] Invalid message:", u);
466
+ console.warn("[gengage:native-bridge] Invalid message:", c);
468
467
  return;
469
468
  }
470
469
  const p = r.type, g = r.payload;
@@ -505,29 +504,29 @@ function _e(e = {}) {
505
504
  }, C = {
506
505
  env: l,
507
506
  sendToNative: v,
508
- receive: N,
509
- setController(u) {
510
- a = u, W();
507
+ receive: q,
508
+ setController(c) {
509
+ a = c, F();
511
510
  },
512
511
  destroy() {
513
512
  t.removeEventListener("gengage:bridge:message", y);
514
- for (const u of F) t.removeEventListener(u.event, u.handler);
515
- c.splice(0, c.length), t.gengageNative === C && delete t.gengageNative;
513
+ for (const c of O) t.removeEventListener(c.event, c.handler);
514
+ u.splice(0, u.length), t.gengageNative === C && delete t.gengageNative;
516
515
  }
517
516
  };
518
517
  return i.gengageNative = C, C;
519
518
  }
520
519
  async function xe(e) {
521
520
  const { nativeBridge: t, emitReadyEvent: i = !0, ...s } = e, o = _e(t), n = { ...s };
522
- n.onAddToCart || (n.onAddToCart = (c) => {
521
+ n.onAddToCart || (n.onAddToCart = (u) => {
523
522
  o.sendToNative("addToCart", {
524
- sku: c.sku,
525
- quantity: c.quantity,
526
- cartCode: c.cartCode
523
+ sku: u.sku,
524
+ quantity: u.quantity,
525
+ cartCode: u.cartCode
527
526
  });
528
- }), n.onProductNavigate || (n.onProductNavigate = (c, v, y) => {
527
+ }), n.onProductNavigate || (n.onProductNavigate = (u, v, y) => {
529
528
  o.sendToNative("productNavigate", {
530
- url: c,
529
+ url: u,
531
530
  sku: v,
532
531
  sessionId: y
533
532
  });
@@ -535,24 +534,24 @@ async function xe(e) {
535
534
  const d = n.qna?.enabled === !0 || n.qna?.mountTarget !== void 0;
536
535
  if (n.qna?.enabled !== !1)
537
536
  if (d) {
538
- const c = E(window, n.qna?.mountTarget ?? x, "gengage-qna");
537
+ const u = E(window, n.qna?.mountTarget ?? x, "gengage-qna");
539
538
  n.qna = {
540
539
  ...n.qna,
541
540
  enabled: !0,
542
- mountTarget: c
541
+ mountTarget: u
543
542
  };
544
- } else q(window, x) || (n.qna = { enabled: !1 });
543
+ } else k(window, x) || (n.qna = { enabled: !1 });
545
544
  const l = n.simrel?.enabled === !0 || n.simrel?.mountTarget !== void 0;
546
545
  if (n.simrel?.enabled !== !1)
547
546
  if (l) {
548
- const c = E(window, n.simrel?.mountTarget ?? U, "gengage-simrel");
547
+ const u = E(window, n.simrel?.mountTarget ?? U, "gengage-simrel");
549
548
  n.simrel = {
550
549
  ...n.simrel,
551
550
  enabled: !0,
552
- mountTarget: c
551
+ mountTarget: u
553
552
  };
554
- } else q(window, U) || (n.simrel = { enabled: !1 });
555
- const a = await ce(n);
553
+ } else k(window, U) || (n.simrel = { enabled: !1 });
554
+ const a = await ue(n);
556
555
  return o.setController(a), i && o.sendToNative("ready", {
557
556
  sessionId: a.session.sessionId,
558
557
  widgets: {
@@ -573,15 +572,15 @@ export {
573
572
  ge as c,
574
573
  z as d,
575
574
  ie as f,
576
- qe as h,
575
+ ke as h,
577
576
  ve as i,
578
- ce as l,
577
+ ue as l,
579
578
  se as m,
580
579
  ye as n,
581
580
  Me as o,
582
- Ne as p,
581
+ qe as p,
583
582
  _e as r,
584
- ke as s,
583
+ Ne as s,
585
584
  he as t,
586
585
  L as u
587
586
  };