@gengage/assistant-fe 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/assistant-fe.css +2 -1
  2. package/dist/chat-C1_48HTk.js +4867 -0
  3. package/dist/chat-C1_48HTk.js.map +1 -0
  4. package/dist/chat-DJpVCmRT.cjs +13 -0
  5. package/dist/chat-DJpVCmRT.cjs.map +1 -0
  6. package/dist/chat.cjs +1 -2
  7. package/dist/chat.iife.js +31 -31
  8. package/dist/chat.iife.js.map +1 -1
  9. package/dist/chat.js +2 -15
  10. package/dist/common--5smIEwc.js +390 -0
  11. package/dist/common--5smIEwc.js.map +1 -0
  12. package/dist/common-DTY__1sq.cjs +2 -0
  13. package/dist/common-DTY__1sq.cjs.map +1 -0
  14. package/dist/common.cjs +1 -2
  15. package/dist/common.js +5 -448
  16. package/dist/index.cjs +1 -2
  17. package/dist/index.js +7 -70
  18. package/dist/native-webview-D1v6n8kJ.cjs +2 -0
  19. package/dist/native-webview-D1v6n8kJ.cjs.map +1 -0
  20. package/dist/native-webview-DlY9mxqG.js +521 -0
  21. package/dist/native-webview-DlY9mxqG.js.map +1 -0
  22. package/dist/native.cjs +1 -2
  23. package/dist/native.iife.js +31 -31
  24. package/dist/native.iife.js.map +1 -1
  25. package/dist/native.js +2 -9
  26. package/dist/qna-C-ZboudC.cjs +2 -0
  27. package/dist/qna-C-ZboudC.cjs.map +1 -0
  28. package/dist/qna-CDfFy61x.js +442 -0
  29. package/dist/qna-CDfFy61x.js.map +1 -0
  30. package/dist/qna.cjs +1 -2
  31. package/dist/qna.css +1 -1
  32. package/dist/qna.iife.js +29 -29
  33. package/dist/qna.iife.js.map +1 -1
  34. package/dist/qna.js +2 -463
  35. package/dist/quantity-stepper-BuwCXbPt.cjs +2 -0
  36. package/dist/quantity-stepper-BuwCXbPt.cjs.map +1 -0
  37. package/dist/quantity-stepper-CTEOqVS6.js +74 -0
  38. package/dist/quantity-stepper-CTEOqVS6.js.map +1 -0
  39. package/dist/schemas-BNc2hTff.cjs +86 -0
  40. package/dist/schemas-BNc2hTff.cjs.map +1 -0
  41. package/dist/schemas-ClU0oPbf.js +4625 -0
  42. package/dist/schemas-ClU0oPbf.js.map +1 -0
  43. package/dist/simrel-B2UMdZ9p.cjs +2 -0
  44. package/dist/simrel-B2UMdZ9p.cjs.map +1 -0
  45. package/dist/simrel-BjL12luk.js +657 -0
  46. package/dist/simrel-BjL12luk.js.map +1 -0
  47. package/dist/simrel.cjs +1 -2
  48. package/dist/simrel.css +1 -1
  49. package/dist/simrel.iife.js +29 -29
  50. package/dist/simrel.iife.js.map +1 -1
  51. package/dist/simrel.js +2 -689
  52. package/package.json +13 -13
  53. package/dist/chat.cjs.map +0 -1
  54. package/dist/chat.js.map +0 -1
  55. package/dist/common.cjs.map +0 -1
  56. package/dist/common.js.map +0 -1
  57. package/dist/index-BAQXPosE.cjs +0 -2
  58. package/dist/index-BAQXPosE.cjs.map +0 -1
  59. package/dist/index-CUBMZpGs.js +0 -5111
  60. package/dist/index-CUBMZpGs.js.map +0 -1
  61. package/dist/index-Dco2Aw73.cjs +0 -13
  62. package/dist/index-Dco2Aw73.cjs.map +0 -1
  63. package/dist/index-DvSU2I9u.js +0 -506
  64. package/dist/index-DvSU2I9u.js.map +0 -1
  65. package/dist/index.cjs.map +0 -1
  66. package/dist/index.js.map +0 -1
  67. package/dist/native.cjs.map +0 -1
  68. package/dist/native.js.map +0 -1
  69. package/dist/qna.cjs.map +0 -1
  70. package/dist/qna.js.map +0 -1
  71. package/dist/quantity-stepper-CQWgexMO.cjs +0 -2
  72. package/dist/quantity-stepper-CQWgexMO.cjs.map +0 -1
  73. package/dist/quantity-stepper-CjY_cpgJ.js +0 -80
  74. package/dist/quantity-stepper-CjY_cpgJ.js.map +0 -1
  75. package/dist/schemas-5lXjLjwW.js +0 -4944
  76. package/dist/schemas-5lXjLjwW.js.map +0 -1
  77. package/dist/schemas-DqUVzVDf.cjs +0 -86
  78. package/dist/schemas-DqUVzVDf.cjs.map +0 -1
  79. package/dist/simrel.cjs.map +0 -1
  80. package/dist/simrel.js.map +0 -1
package/dist/common.js CHANGED
@@ -1,448 +1,5 @@
1
- import { a0 as h } from "./schemas-5lXjLjwW.js";
2
- import { B as z, a1 as W, a as G, C as H, a2 as K, b as j, R as V, a3 as J, a4 as Q, c as X, a5 as Y, a6 as Z, j as ee, k as te, a7 as ae, a8 as ne, a9 as oe, aa as ie, T as se, m as re, Q as ce, ab as de, q as le, p as ue, ac as he, ad as fe, r as ge, Z as me, v as pe, ae as ye, X as ve, h as we, l as Te, af as be, g as Ee, U as Se, ag as ke, w as Ce, ah as Ie, $ as Ue, ai as Ae, aj as _e } from "./schemas-5lXjLjwW.js";
3
- import { i as f, s as g } from "./index-DvSU2I9u.js";
4
- import { A as Pe, a as Le, U as Re, b as qe, c as De, d as Be, e as Oe, f as Ne, g as Fe, h as Me, j as $e, p as ze } from "./index-DvSU2I9u.js";
5
- import { V as Ge, i as He, r as Ke } from "./index-CUBMZpGs.js";
6
- import "./qna.js";
7
- import "./simrel.js";
8
- const m = {
9
- enabled: !0,
10
- endpoint: "/analytics",
11
- fireAndForget: !0,
12
- useBeacon: !0,
13
- keepaliveFetch: !0,
14
- timeoutMs: 4e3,
15
- maxRetries: 0,
16
- batchSize: 10,
17
- flushIntervalMs: 250
18
- }, p = {
19
- mode: "none",
20
- key: "",
21
- headerName: "X-API-Key",
22
- bodyField: "api_key"
23
- };
24
- class y {
25
- constructor(t) {
26
- this.queue = [], this.flushTimer = null, this.config = {
27
- ...m,
28
- ...t,
29
- auth: {
30
- ...p,
31
- ...t.auth ?? {}
32
- }
33
- }, this.onPageHideBound = () => {
34
- this.queue.length !== 0 && this.flushAllSync();
35
- }, typeof window < "u" && window.addEventListener("pagehide", this.onPageHideBound);
36
- }
37
- track(t) {
38
- if (!this.config.enabled) return;
39
- const a = v(t);
40
- if (this.queue.push(a), this.queue.length >= this.config.batchSize) {
41
- this.scheduleImmediateFlush();
42
- return;
43
- }
44
- this.scheduleFlush();
45
- }
46
- flush() {
47
- if (!this.config.enabled || this.queue.length === 0) return;
48
- const t = this.queue.splice(0, this.config.batchSize), a = this.buildTransportBody(t), n = d(this.config.endpoint, this.config.middlewareUrl);
49
- this.send(n, a);
50
- }
51
- /** Drain the entire queue synchronously (used on page hide). */
52
- flushAll() {
53
- for (; this.queue.length > 0; )
54
- this.flush();
55
- }
56
- destroy() {
57
- this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.queue.length > 0 && this.flushAllSync(), typeof window < "u" && window.removeEventListener("pagehide", this.onPageHideBound);
58
- }
59
- scheduleFlush() {
60
- this.flushTimer || (this.flushTimer = setTimeout(() => {
61
- this.flushTimer = null, this.flush();
62
- }, this.config.flushIntervalMs));
63
- }
64
- scheduleImmediateFlush() {
65
- this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.flush();
66
- }
67
- buildTransportBody(t) {
68
- const a = { events: t };
69
- return this.config.auth.mode === "body-api-key" && this.config.auth.key && (a[this.config.auth.bodyField] = this.config.auth.key), a;
70
- }
71
- /** Best-effort send — all errors silently suppressed. */
72
- send(t, a) {
73
- try {
74
- const n = JSON.stringify(a);
75
- if (this.config.useBeacon && this.config.auth.mode !== "x-api-key-header" && this.config.auth.mode !== "bearer-header" && l()) {
76
- const o = new Blob([n], { type: "application/json" });
77
- navigator.sendBeacon(t, o);
78
- return;
79
- }
80
- if (typeof fetch > "u") return;
81
- const i = { "Content-Type": "application/json" };
82
- this.config.auth.mode === "x-api-key-header" && this.config.auth.key && (i[this.config.auth.headerName] = this.config.auth.key), this.config.auth.mode === "bearer-header" && this.config.auth.key && (i.Authorization = `Bearer ${this.config.auth.key}`), fetch(t, {
83
- method: "POST",
84
- headers: i,
85
- body: n,
86
- keepalive: !0
87
- }).catch(() => {
88
- });
89
- } catch {
90
- }
91
- }
92
- /** Synchronous flush using sendBeacon only (for page unload). */
93
- flushAllSync() {
94
- if (!this.config.enabled) return;
95
- const t = d(this.config.endpoint, this.config.middlewareUrl);
96
- for (; this.queue.length > 0; ) {
97
- const a = this.queue.splice(0, this.config.batchSize), n = this.buildTransportBody(a);
98
- try {
99
- const i = JSON.stringify(n);
100
- if (l()) {
101
- const o = new Blob([i], { type: "application/json" });
102
- navigator.sendBeacon(t, o);
103
- }
104
- } catch {
105
- }
106
- }
107
- }
108
- }
109
- function P(e) {
110
- return new y(e);
111
- }
112
- function v(e) {
113
- const t = {
114
- event_name: e.event_name,
115
- event_version: e.event_version ?? "1",
116
- timestamp_ms: e.timestamp_ms ?? Date.now(),
117
- account_id: e.account_id,
118
- session_id: e.session_id,
119
- correlation_id: e.correlation_id,
120
- payload: e.payload
121
- };
122
- return e.view_id !== void 0 && (t.view_id = e.view_id), e.user_id !== void 0 && (t.user_id = e.user_id), e.widget !== void 0 && (t.widget = e.widget), e.page_type !== void 0 && (t.page_type = e.page_type), e.sku !== void 0 && (t.sku = e.sku), t;
123
- }
124
- function d(e, t) {
125
- if (/^https?:\/\//i.test(e)) return e;
126
- const a = h(t), n = e.startsWith("/") ? e : `/${e}`;
127
- return `${a}${n}`;
128
- }
129
- function l() {
130
- return typeof navigator < "u" && typeof navigator.sendBeacon == "function";
131
- }
132
- const w = {
133
- /* ── Editorial Commerce Framework ────────────────────────────────────── */
134
- /* Primary: signature red; never use pure black for text — use on_surface */
135
- primaryColor: "#b7102a",
136
- primaryForeground: "#ffffff",
137
- backgroundColor: "#f8f9fa",
138
- foregroundColor: "#191c1d",
139
- borderRadius: "0.75rem",
140
- fontFamily: '"Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
141
- fontSize: "14px",
142
- zIndex: "1000",
143
- "--glov-chatbot-width": "420px",
144
- "--glov-left-spacing": "260px",
145
- "--chatbot-padding": "16px",
146
- "--root-wrapper-background-color": "#f8f9fa",
147
- "--root-wrapper-border-color": "#edeeef",
148
- "--gengage-chat-width": "400px",
149
- "--gengage-chat-shell-radius": "1rem",
150
- "--gengage-chat-header-height": "60px",
151
- "--gengage-chat-conversation-width": "396px",
152
- "--gengage-chat-panel-min-width": "320px",
153
- "--gengage-chat-panel-max-width": "860px",
154
- "--gengage-chat-input-height": "48px",
155
- "--gengage-qna-pill-radius": "999px",
156
- "--gengage-qna-input-radius": "0.75rem",
157
- "--gengage-simrel-card-radius": "0.75rem"
158
- };
159
- function L(e) {
160
- return { ...w, ...e };
161
- }
162
- const u = "tr";
163
- function R(e) {
164
- return {
165
- ACCOUNT_ID: e.accountId,
166
- MIDDLEWARE_URL: e.middlewareUrl,
167
- LOCALE: e.locale ?? u
168
- };
169
- }
170
- function q(e, t = {}) {
171
- const a = {
172
- accountId: e.accountId,
173
- middlewareUrl: e.middlewareUrl,
174
- session: { sessionId: e.sessionId },
175
- variant: "floating",
176
- locale: e.locale ?? u,
177
- ...t
178
- };
179
- return e.theme !== void 0 && (a.theme = e.theme), a;
180
- }
181
- function D(e, t = {}) {
182
- const a = {
183
- accountId: e.accountId,
184
- middlewareUrl: e.middlewareUrl,
185
- session: { sessionId: e.sessionId },
186
- pageContext: { pageType: "pdp", sku: e.sku },
187
- mountTarget: e.mountTarget,
188
- ...t
189
- };
190
- return e.theme !== void 0 && (a.theme = e.theme), a;
191
- }
192
- function B(e, t = {}) {
193
- const a = {
194
- accountId: e.accountId,
195
- middlewareUrl: e.middlewareUrl,
196
- session: { sessionId: e.sessionId },
197
- sku: e.sku,
198
- mountTarget: e.mountTarget,
199
- ...t
200
- };
201
- return e.theme !== void 0 && (a.theme = e.theme), a;
202
- }
203
- function O(e, t = {}) {
204
- return {
205
- enabled: !0,
206
- middlewareUrl: e,
207
- endpoint: "/analytics",
208
- fireAndForget: !0,
209
- useBeacon: !0,
210
- ...t
211
- };
212
- }
213
- function T(e) {
214
- try {
215
- return document.querySelector(e), !0;
216
- } catch {
217
- return !1;
218
- }
219
- }
220
- function b(e, t) {
221
- const a = [], n = e.mounts, i = [
222
- ["qna", n.qna],
223
- ["simrel", n.simrel],
224
- ["chat", n.chat]
225
- ];
226
- for (const [s, r] of i)
227
- if (r !== void 0) {
228
- if (!T(r)) {
229
- a.push({
230
- code: "INVALID_SELECTOR",
231
- message: `[gengage preflight] ${s} mount selector is invalid CSS: "${r}"`,
232
- severity: "error"
233
- });
234
- continue;
235
- }
236
- document.querySelector(r) || a.push({
237
- code: "MOUNT_NOT_FOUND",
238
- message: `[gengage preflight] ${s} mount target not found: "${r}" — widget will skip or wait for DOM`,
239
- severity: "warn"
240
- });
241
- }
242
- const o = e.gtm.idempotencyKey;
243
- if (window[o] !== void 0 && a.push({
244
- code: "DUPLICATE_IDEMPOTENCY",
245
- message: `[gengage preflight] window["${o}"] already exists — widgets may have already initialized`,
246
- severity: "warn"
247
- }), !t?.skipCspCheck) {
248
- let s = !1;
249
- const r = (c) => {
250
- c.blockedURI && e.middlewareUrl.startsWith(c.blockedURI) && (s = !0);
251
- };
252
- document.addEventListener("securitypolicyviolation", r);
253
- try {
254
- fetch(e.middlewareUrl, { method: "HEAD", mode: "no-cors" }).catch(() => {
255
- });
256
- } catch {
257
- s = !0;
258
- }
259
- document.removeEventListener("securitypolicyviolation", r), s && a.push({
260
- code: "CSP_BLOCKED",
261
- message: `[gengage preflight] middleware URL may be blocked by Content-Security-Policy: "${e.middlewareUrl}". Add it to connect-src.`,
262
- severity: "warn"
263
- });
264
- }
265
- for (const s of a)
266
- s.severity === "error" ? console.error(s.message) : console.warn(s.message);
267
- return {
268
- ok: a.every((s) => s.severity !== "error"),
269
- warnings: a
270
- };
271
- }
272
- function E(e) {
273
- const t = g(e);
274
- if (!t.success) {
275
- const a = t.error.issues.map((n) => `${n.path.join(".")}: ${n.message}`).join("; ");
276
- throw new Error(`[gengage] Invalid runtime config: ${a}`);
277
- }
278
- return t.data;
279
- }
280
- function S(e, t, a) {
281
- const n = {
282
- accountId: e.accountId,
283
- middlewareUrl: e.middlewareUrl,
284
- idempotencyKey: e.gtm.idempotencyKey
285
- };
286
- return e.locale !== void 0 && (n.locale = e.locale), a !== void 0 && (n.pageContext = a, a.sku !== void 0 && (n.sku = a.sku)), n.chat = {
287
- enabled: e.widgets.chat.enabled
288
- }, e.mounts.chat !== void 0 && (n.chat.mountTarget = e.mounts.chat), n.qna = {
289
- enabled: e.widgets.qna.enabled
290
- }, e.mounts.qna !== void 0 && (n.qna.mountTarget = e.mounts.qna), n.simrel = {
291
- enabled: e.widgets.simrel.enabled
292
- }, e.mounts.simrel !== void 0 && (n.simrel.mountTarget = e.mounts.simrel), t?.onAddToCart !== void 0 && (n.onAddToCart = t.onAddToCart), t?.onProductNavigate !== void 0 && (n.onProductNavigate = t.onProductNavigate), t?.onScriptCall !== void 0 && (n.onScriptCall = t.onScriptCall), n;
293
- }
294
- async function N(e) {
295
- const t = E(e.runtimeConfig);
296
- if (e.preflight !== !1) {
297
- const o = b(t);
298
- if (!o.ok) {
299
- const s = o.warnings.filter((r) => r.severity === "error");
300
- throw new Error(`[gengage] Preflight failed: ${s.map((r) => r.message).join("; ")}`);
301
- }
302
- }
303
- const a = e.contextResolver?.(), n = S(t, e.hostActions, a), i = await f(n);
304
- if (e.contextResolver !== void 0) {
305
- const o = e.contextResolver, s = () => {
306
- const c = o();
307
- i.updateContext(c);
308
- };
309
- window.addEventListener("gengage:context:update", s);
310
- const r = i.destroy.bind(i);
311
- i.destroy = () => {
312
- window.removeEventListener("gengage:context:update", s), r();
313
- };
314
- }
315
- return i;
316
- }
317
- const k = [
318
- {
319
- pageType: "home",
320
- urlPatterns: ["^/$", "^/index\\.html?$", "^/anasayfa$"]
321
- },
322
- {
323
- pageType: "search",
324
- urlPatterns: ["/arama", "/search", "/ara\\?"],
325
- queryParam: "q"
326
- },
327
- {
328
- pageType: "cart",
329
- urlPatterns: ["/sepet", "/cart", "/basket", "/sepetim"]
330
- },
331
- {
332
- pageType: "plp",
333
- urlPatterns: ["/kategori/", "/category/", "/c/", "/koleksiyon/", "/collection/"]
334
- },
335
- {
336
- pageType: "pdp",
337
- urlPatterns: ["/urun/", "/product/", "/p/", "/-p-", "/-pm-"]
338
- }
339
- ];
340
- function C(e, t) {
341
- const a = t ?? (typeof window < "u" ? new URL(window.location.href) : null);
342
- if (!a) return "other";
343
- const n = e ?? k, i = a.pathname;
344
- for (const o of n)
345
- if (!(o.urlPatterns && !o.urlPatterns.some((r) => {
346
- try {
347
- return new RegExp(r, "i").test(i);
348
- } catch {
349
- return !1;
350
- }
351
- })) && !(o.queryParam && !a.searchParams.has(o.queryParam)) && !(o.selector && typeof document < "u" && !document.querySelector(o.selector)))
352
- return o.pageType;
353
- return "other";
354
- }
355
- function I(e) {
356
- const t = e ?? (typeof window < "u" ? new URL(window.location.href) : null);
357
- if (!t) return;
358
- const a = t.pathname, n = a.match(/\/(?:p|urun|product)\/([^/?#]+)/i);
359
- if (n?.[1]) return n[1];
360
- const i = a.match(/-p-(\d+)/i);
361
- if (i?.[1]) return i[1];
362
- }
363
- function F(e) {
364
- const t = C(e), a = { pageType: t };
365
- if (t === "pdp") {
366
- const n = I();
367
- n && (a.sku = n);
368
- }
369
- return typeof window < "u" && (a.url = window.location.href), a;
370
- }
371
- export {
372
- Pe as AccountRuntimeConfigSchema,
373
- Le as AnalyticsAuthModeSchema,
374
- y as AnalyticsClient,
375
- w as BASE_WIDGET_THEME,
376
- z as BaseWidget,
377
- u as DEFAULT_CUSTOMIZATION_LOCALE,
378
- W as DEFAULT_WIDGET_THEME_TOKENS,
379
- Re as UnknownActionPolicySchema,
380
- Ge as VoiceInput,
381
- G as adaptBackendEvent,
382
- qe as applyNativeSession,
383
- F as autoDetectPageContext,
384
- H as basketAddEvent,
385
- K as bootstrapSession,
386
- j as buildChatEndpointUrl,
387
- De as buildOverlayIdempotencyKey,
388
- V as chatHistorySnapshotEvent,
389
- J as checkoutCompleteEvent,
390
- Q as checkoutStartEvent,
391
- X as consumeStream,
392
- R as createAccountIdentity,
393
- P as createAnalyticsClient,
394
- Be as createDefaultAccountRuntimeConfig,
395
- O as createDefaultAnalyticsConfig,
396
- q as createFloatingChatConfig,
397
- Oe as createNativeWebViewBridge,
398
- D as createPdpQnaConfig,
399
- B as createPdpSimRelConfig,
400
- Y as defaultUnknownUISpecRenderer,
401
- Ne as destroyOverlayWidgets,
402
- Fe as detectNativeEnvironment,
403
- C as detectPageType,
404
- Z as dismissGlobalErrorToast,
405
- ee as dispatch,
406
- I as extractSkuFromUrl,
407
- te as getGlobalErrorMessage,
408
- Me as getOverlayWidgets,
409
- ae as getSuggestedSearchKeywords,
410
- ne as getSuggestedSearchKeywordsText,
411
- oe as getWindowPageContext,
412
- N as initGengageClient,
413
- $e as initNativeOverlayWidgets,
414
- f as initOverlayWidgets,
415
- He as isVoiceInputSupported,
416
- ie as listen,
417
- se as llmUsageEvent,
418
- re as mergeUISpecRegistry,
419
- ce as meteringIncrementEvent,
420
- de as meteringSummaryEvent,
421
- h as normalizeMiddlewareUrl,
422
- le as normalizeProductGroupingsResponse,
423
- ue as normalizeSimilarProductsResponse,
424
- ze as parseAccountRuntimeConfig,
425
- b as preflightDiagnostics,
426
- he as productToNormalized,
427
- fe as registerGlobalErrorToastListener,
428
- ge as renderUISpecWithRegistry,
429
- me as resolveSession,
430
- Ke as routeStreamAction,
431
- g as safeParseAccountRuntimeConfig,
432
- pe as sanitizeHtml,
433
- ye as showGlobalErrorToast,
434
- ve as streamChunkEvent,
435
- we as streamDoneEvent,
436
- Te as streamErrorEvent,
437
- be as streamPost,
438
- Ee as streamStartEvent,
439
- Se as streamUiSpecEvent,
440
- ke as updatePageContext,
441
- Ce as widgetHistorySnapshotEvent,
442
- Ie as wireGADataLayer,
443
- Ue as wireQNAToChat,
444
- Ae as wireSimilarToChat,
445
- L as withBaseTheme,
446
- _e as withDefaultWidgetTheme
447
- };
448
- //# sourceMappingURL=common.js.map
1
+ import { $ as e, A as t, F as n, G as r, H as i, I as a, J as o, K as s, L as c, M as l, N as u, O as d, P as f, Q as p, R as m, U as h, V as g, W as _, X as v, Y as y, Z as b, _t as x, at as S, bt as C, ct as w, dt as T, et as E, ft as D, gt as O, ht as k, it as A, j, k as M, lt as N, mt as P, ot as F, pt as I, q as L, st as R, ut as z, vt as B, yt as V, z as H } from "./schemas-ClU0oPbf.js";
2
+ import { c as U, l as W, p as G } from "./chat-C1_48HTk.js";
3
+ import { a as K, c as q, d as J, f as Y, h as X, i as Z, l as Q, m as $, n as ee, o as te, p as ne, r as re, s as ie, u as ae } from "./native-webview-DlY9mxqG.js";
4
+ import { a as oe, c as se, d as ce, f as le, h as ue, i as de, l as fe, m as pe, n as me, o as he, p as ge, r as _e, s as ve, t as ye, u as be } from "./common--5smIEwc.js";
5
+ export { ae as AccountRuntimeConfigSchema, J as AnalyticsAuthModeSchema, pe as AnalyticsClient, le as BASE_WIDGET_THEME, H as BaseWidget, he as DEFAULT_CUSTOMIZATION_LOCALE, r as DEFAULT_WIDGET_THEME_TOKENS, Y as UnknownActionPolicySchema, U as VoiceInput, j as adaptBackendEvent, ee as applyNativeSession, ye as autoDetectPageContext, S as basketAddEvent, L as bootstrapSession, M as buildChatEndpointUrl, te as buildOverlayIdempotencyKey, F as chatHistorySnapshotEvent, R as checkoutCompleteEvent, w as checkoutStartEvent, c as consumeStream, ve as createAccountIdentity, ue as createAnalyticsClient, ne as createDefaultAccountRuntimeConfig, se as createDefaultAnalyticsConfig, fe as createFloatingChatConfig, re as createNativeWebViewBridge, be as createPdpQnaConfig, ce as createPdpSimRelConfig, V as defaultUnknownUISpecRenderer, ie as destroyOverlayWidgets, Z as detectNativeEnvironment, me as detectPageType, g as dismissGlobalErrorToast, b as dispatch, _e as extractSkuFromUrl, i as getGlobalErrorMessage, q as getOverlayWidgets, n as getSuggestedSearchKeywords, a as getSuggestedSearchKeywordsText, o as getWindowPageContext, de as initGengageClient, K as initNativeOverlayWidgets, Q as initOverlayWidgets, W as isVoiceInputSupported, p as listen, N as llmUsageEvent, B as mergeUISpecRegistry, z as meteringIncrementEvent, T as meteringSummaryEvent, t as normalizeMiddlewareUrl, l as normalizeProductGroupingsResponse, u as normalizeSimilarProductsResponse, $ as parseAccountRuntimeConfig, oe as preflightDiagnostics, f as productToNormalized, h as registerGlobalErrorToastListener, C as renderUISpecWithRegistry, y as resolveSession, G as routeStreamAction, X as safeParseAccountRuntimeConfig, A as sanitizeHtml, _ as showGlobalErrorToast, D as streamChunkEvent, I as streamDoneEvent, P as streamErrorEvent, m as streamPost, k as streamStartEvent, O as streamUiSpecEvent, v as updatePageContext, x as widgetHistorySnapshotEvent, d as wireGADataLayer, e as wireQNAToChat, E as wireSimilarToChat, ge as withBaseTheme, s as withDefaultWidgetTheme };
package/dist/index.cjs CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index-Dco2Aw73.cjs"),n=require("./qna.cjs"),r=require("./simrel.cjs"),e=require("./schemas-DqUVzVDf.cjs"),t=require("./index-BAQXPosE.cjs"),a=require("./common.cjs");exports.GengageChat=i.GengageChat;exports.VoiceInput=i.VoiceInput;exports.createChatWidget=i.createChatWidget;exports.createDefaultChatUISpecRegistry=i.createDefaultChatUISpecRegistry;exports.defaultChatUnknownUISpecRenderer=i.defaultChatUnknownUISpecRenderer;exports.isVoiceInputSupported=i.isVoiceInputSupported;exports.renderChatUISpec=i.renderUISpec;exports.routeStreamAction=i.routeStreamAction;exports.GengageQNA=n.GengageQNA;exports.createDefaultQnaUISpecRegistry=n.createDefaultQnaUISpecRegistry;exports.createQNAWidget=n.createQNAWidget;exports.defaultQnaUnknownUISpecRenderer=n.defaultQnaUnknownUISpecRenderer;exports.renderQnaUISpec=n.renderQnaUISpec;exports.GengageSimRel=r.GengageSimRel;exports.createDefaultSimRelUISpecRegistry=r.createDefaultSimRelUISpecRegistry;exports.createSimRelWidget=r.createSimRelWidget;exports.defaultSimRelUnknownUISpecRenderer=r.defaultSimRelUnknownUISpecRenderer;exports.renderSimRelUISpec=r.renderSimRelUISpec;exports.DEFAULT_WIDGET_THEME_TOKENS=e.DEFAULT_WIDGET_THEME_TOKENS;exports.bootstrapSession=e.bootstrapSession;exports.buildChatEndpointUrl=e.buildChatEndpointUrl;exports.consumeStream=e.consumeStream;exports.defaultUnknownUISpecRenderer=e.defaultUnknownUISpecRenderer;exports.dispatch=e.dispatch;exports.listen=e.listen;exports.normalizeMiddlewareUrl=e.normalizeMiddlewareUrl;exports.renderUISpecWithRegistry=e.renderUISpecWithRegistry;exports.streamPost=e.streamPost;exports.updatePageContext=e.updatePageContext;exports.wireGADataLayer=e.wireGADataLayer;exports.wireQNAToChat=e.wireQNAToChat;exports.wireSimilarToChat=e.wireSimilarToChat;exports.withDefaultWidgetTheme=e.withDefaultWidgetTheme;exports.AccountRuntimeConfigSchema=t.AccountRuntimeConfigSchema;exports.AnalyticsAuthModeSchema=t.AnalyticsAuthModeSchema;exports.UnknownActionPolicySchema=t.UnknownActionPolicySchema;exports.applyNativeSession=t.applyNativeSession;exports.buildOverlayIdempotencyKey=t.buildOverlayIdempotencyKey;exports.createDefaultAccountRuntimeConfig=t.createDefaultAccountRuntimeConfig;exports.createNativeWebViewBridge=t.createNativeWebViewBridge;exports.destroyOverlayWidgets=t.destroyOverlayWidgets;exports.detectNativeEnvironment=t.detectNativeEnvironment;exports.getOverlayWidgets=t.getOverlayWidgets;exports.initNativeOverlayWidgets=t.initNativeOverlayWidgets;exports.initOverlayWidgets=t.initOverlayWidgets;exports.parseAccountRuntimeConfig=t.parseAccountRuntimeConfig;exports.safeParseAccountRuntimeConfig=t.safeParseAccountRuntimeConfig;exports.BASE_WIDGET_THEME=a.BASE_WIDGET_THEME;exports.DEFAULT_CUSTOMIZATION_LOCALE=a.DEFAULT_CUSTOMIZATION_LOCALE;exports.autoDetectPageContext=a.autoDetectPageContext;exports.createAccountIdentity=a.createAccountIdentity;exports.createAnalyticsClient=a.createAnalyticsClient;exports.createDefaultAnalyticsConfig=a.createDefaultAnalyticsConfig;exports.createFloatingChatConfig=a.createFloatingChatConfig;exports.createPdpQnaConfig=a.createPdpQnaConfig;exports.createPdpSimRelConfig=a.createPdpSimRelConfig;exports.detectPageType=a.detectPageType;exports.extractSkuFromUrl=a.extractSkuFromUrl;exports.initGengageClient=a.initGengageClient;exports.preflightDiagnostics=a.preflightDiagnostics;exports.withBaseTheme=a.withBaseTheme;
2
- //# sourceMappingURL=index.cjs.map
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./schemas-BNc2hTff.cjs`),t=require(`./chat-DJpVCmRT.cjs`),n=require(`./qna-C-ZboudC.cjs`),r=require(`./simrel-B2UMdZ9p.cjs`),i=require(`./native-webview-D1v6n8kJ.cjs`),a=require(`./common-DTY__1sq.cjs`);exports.AccountRuntimeConfigSchema=i.u,exports.AnalyticsAuthModeSchema=i.d,exports.BASE_WIDGET_THEME=a.f,exports.DEFAULT_CUSTOMIZATION_LOCALE=a.o,exports.DEFAULT_WIDGET_THEME_TOKENS=e.G,exports.GengageChat=t.t,exports.GengageQNA=n.t,exports.GengageSimRel=r.t,exports.UnknownActionPolicySchema=i.f,exports.VoiceInput=t.c,exports.applyNativeSession=i.n,exports.autoDetectPageContext=a.t,exports.bootstrapSession=e.q,exports.buildChatEndpointUrl=e.k,exports.buildOverlayIdempotencyKey=i.o,exports.consumeStream=e.L,exports.createAccountIdentity=a.s,exports.createAnalyticsClient=a.h,exports.createChatWidget=t.n,exports.createDefaultAccountRuntimeConfig=i.p,exports.createDefaultAnalyticsConfig=a.c,exports.createDefaultChatUISpecRegistry=t.a,exports.createDefaultQnaUISpecRegistry=n.i,exports.createDefaultSimRelUISpecRegistry=r.i,exports.createFloatingChatConfig=a.l,exports.createNativeWebViewBridge=i.r,exports.createPdpQnaConfig=a.u,exports.createPdpSimRelConfig=a.d,exports.createQNAWidget=n.n,exports.createSimRelWidget=r.n,exports.defaultChatUnknownUISpecRenderer=t.o,exports.defaultQnaUnknownUISpecRenderer=n.a,exports.defaultSimRelUnknownUISpecRenderer=r.a,exports.defaultUnknownUISpecRenderer=e.yt,exports.destroyOverlayWidgets=i.s,exports.detectNativeEnvironment=i.i,exports.detectPageType=a.n,exports.dispatch=e.Z,exports.extractSkuFromUrl=a.r,exports.getOverlayWidgets=i.c,exports.initGengageClient=a.i,exports.initNativeOverlayWidgets=i.a,exports.initOverlayWidgets=i.l,exports.isVoiceInputSupported=t.l,exports.listen=e.Q,exports.normalizeMiddlewareUrl=e.A,exports.parseAccountRuntimeConfig=i.m,exports.preflightDiagnostics=a.a,exports.renderChatUISpec=t.s,exports.renderQnaUISpec=n.o,exports.renderSimRelUISpec=r.o,exports.renderUISpecWithRegistry=e.bt,exports.routeStreamAction=t.p,exports.safeParseAccountRuntimeConfig=i.h,exports.streamPost=e.R,exports.updatePageContext=e.X,exports.wireGADataLayer=e.O,exports.wireQNAToChat=e.$,exports.wireSimilarToChat=e.et,exports.withBaseTheme=a.p,exports.withDefaultWidgetTheme=e.K;
package/dist/index.js CHANGED
@@ -1,70 +1,7 @@
1
- import { G as t, V as i, c as r, a as n, d as s, i as c, b as o, r as d } from "./index-CUBMZpGs.js";
2
- import { GengageQNA as g, createDefaultQnaUISpecRegistry as p, createQNAWidget as m, defaultQnaUnknownUISpecRenderer as u, renderQnaUISpec as S } from "./qna.js";
3
- import { GengageSimRel as C, createDefaultSimRelUISpecRegistry as U, createSimRelWidget as h, defaultSimRelUnknownUISpecRenderer as A, renderSimRelUISpec as y } from "./simrel.js";
4
- import { a1 as R, a2 as T, b as D, c as E, a5 as w, j as W, aa as v, a0 as x, r as N, af as O, ag as G, ah as P, $ as b, ai as Q, aj as _ } from "./schemas-5lXjLjwW.js";
5
- import { A as L, a as M, U as F, b as V, c as j, d as B, e as H, f as K, g as z, h as Z, j as $, i as q, p as J, s as X } from "./index-DvSU2I9u.js";
6
- import { BASE_WIDGET_THEME as ee, DEFAULT_CUSTOMIZATION_LOCALE as ae, autoDetectPageContext as te, createAccountIdentity as ie, createAnalyticsClient as re, createDefaultAnalyticsConfig as ne, createFloatingChatConfig as se, createPdpQnaConfig as ce, createPdpSimRelConfig as oe, detectPageType as de, extractSkuFromUrl as le, initGengageClient as ge, preflightDiagnostics as pe, withBaseTheme as me } from "./common.js";
7
- export {
8
- L as AccountRuntimeConfigSchema,
9
- M as AnalyticsAuthModeSchema,
10
- ee as BASE_WIDGET_THEME,
11
- ae as DEFAULT_CUSTOMIZATION_LOCALE,
12
- R as DEFAULT_WIDGET_THEME_TOKENS,
13
- t as GengageChat,
14
- g as GengageQNA,
15
- C as GengageSimRel,
16
- F as UnknownActionPolicySchema,
17
- i as VoiceInput,
18
- V as applyNativeSession,
19
- te as autoDetectPageContext,
20
- T as bootstrapSession,
21
- D as buildChatEndpointUrl,
22
- j as buildOverlayIdempotencyKey,
23
- E as consumeStream,
24
- ie as createAccountIdentity,
25
- re as createAnalyticsClient,
26
- r as createChatWidget,
27
- B as createDefaultAccountRuntimeConfig,
28
- ne as createDefaultAnalyticsConfig,
29
- n as createDefaultChatUISpecRegistry,
30
- p as createDefaultQnaUISpecRegistry,
31
- U as createDefaultSimRelUISpecRegistry,
32
- se as createFloatingChatConfig,
33
- H as createNativeWebViewBridge,
34
- ce as createPdpQnaConfig,
35
- oe as createPdpSimRelConfig,
36
- m as createQNAWidget,
37
- h as createSimRelWidget,
38
- s as defaultChatUnknownUISpecRenderer,
39
- u as defaultQnaUnknownUISpecRenderer,
40
- A as defaultSimRelUnknownUISpecRenderer,
41
- w as defaultUnknownUISpecRenderer,
42
- K as destroyOverlayWidgets,
43
- z as detectNativeEnvironment,
44
- de as detectPageType,
45
- W as dispatch,
46
- le as extractSkuFromUrl,
47
- Z as getOverlayWidgets,
48
- ge as initGengageClient,
49
- $ as initNativeOverlayWidgets,
50
- q as initOverlayWidgets,
51
- c as isVoiceInputSupported,
52
- v as listen,
53
- x as normalizeMiddlewareUrl,
54
- J as parseAccountRuntimeConfig,
55
- pe as preflightDiagnostics,
56
- o as renderChatUISpec,
57
- S as renderQnaUISpec,
58
- y as renderSimRelUISpec,
59
- N as renderUISpecWithRegistry,
60
- d as routeStreamAction,
61
- X as safeParseAccountRuntimeConfig,
62
- O as streamPost,
63
- G as updatePageContext,
64
- P as wireGADataLayer,
65
- b as wireQNAToChat,
66
- Q as wireSimilarToChat,
67
- me as withBaseTheme,
68
- _ as withDefaultWidgetTheme
69
- };
70
- //# sourceMappingURL=index.js.map
1
+ import { $ as e, A as t, G as n, K as r, L as i, O as a, Q as o, R as s, X as c, Z as l, bt as u, et as d, k as f, q as p, yt as m } from "./schemas-ClU0oPbf.js";
2
+ import { a as h, c as g, l as _, n as v, o as y, p as b, s as x, t as S } from "./chat-C1_48HTk.js";
3
+ import { a as C, i as w, n as T, o as E, t as D } from "./qna-CDfFy61x.js";
4
+ import { a as O, i as k, n as A, o as j, t as M } from "./simrel-BjL12luk.js";
5
+ import { a as N, c as P, d as F, f as I, h as L, i as R, l as z, m as B, n as V, o as H, p as U, r as W, s as G, u as K } from "./native-webview-DlY9mxqG.js";
6
+ import { a as q, c as J, d as Y, f as X, h as Z, i as Q, l as $, n as ee, o as te, p as ne, r as re, s as ie, t as ae, u as oe } from "./common--5smIEwc.js";
7
+ export { K as AccountRuntimeConfigSchema, F as AnalyticsAuthModeSchema, X as BASE_WIDGET_THEME, te as DEFAULT_CUSTOMIZATION_LOCALE, n as DEFAULT_WIDGET_THEME_TOKENS, S as GengageChat, D as GengageQNA, M as GengageSimRel, I as UnknownActionPolicySchema, g as VoiceInput, V as applyNativeSession, ae as autoDetectPageContext, p as bootstrapSession, f as buildChatEndpointUrl, H as buildOverlayIdempotencyKey, i as consumeStream, ie as createAccountIdentity, Z as createAnalyticsClient, v as createChatWidget, U as createDefaultAccountRuntimeConfig, J as createDefaultAnalyticsConfig, h as createDefaultChatUISpecRegistry, w as createDefaultQnaUISpecRegistry, k as createDefaultSimRelUISpecRegistry, $ as createFloatingChatConfig, W as createNativeWebViewBridge, oe as createPdpQnaConfig, Y as createPdpSimRelConfig, T as createQNAWidget, A as createSimRelWidget, y as defaultChatUnknownUISpecRenderer, C as defaultQnaUnknownUISpecRenderer, O as defaultSimRelUnknownUISpecRenderer, m as defaultUnknownUISpecRenderer, G as destroyOverlayWidgets, R as detectNativeEnvironment, ee as detectPageType, l as dispatch, re as extractSkuFromUrl, P as getOverlayWidgets, Q as initGengageClient, N as initNativeOverlayWidgets, z as initOverlayWidgets, _ as isVoiceInputSupported, o as listen, t as normalizeMiddlewareUrl, B as parseAccountRuntimeConfig, q as preflightDiagnostics, x as renderChatUISpec, E as renderQnaUISpec, j as renderSimRelUISpec, u as renderUISpecWithRegistry, b as routeStreamAction, L as safeParseAccountRuntimeConfig, s as streamPost, c as updatePageContext, a as wireGADataLayer, e as wireQNAToChat, d as wireSimilarToChat, ne as withBaseTheme, r as withDefaultWidgetTheme };
@@ -0,0 +1,2 @@
1
+ const e=require(`./schemas-BNc2hTff.cjs`),t=require(`./chat-DJpVCmRT.cjs`),n=require(`./qna-C-ZboudC.cjs`),r=require(`./simrel-B2UMdZ9p.cjs`);var i=e.o({enabled:e.r().default(!0)}),a=e.o({chat:e.c().optional(),qna:e.c().optional(),simrel:e.c().optional()}),o=e.o({}),s=e.t([`none`,`x-api-key-header`,`bearer-header`,`body-api-key`]),c=e.o({mode:s.default(`none`),key:e.c().optional(),headerName:e.c().optional(),bodyField:e.c().default(`api_key`)}),l=e.o({enabled:e.r().default(!0),endpoint:e.c().default(`/analytics`),auth:c.default({mode:`none`,bodyField:`api_key`}),fireAndForget:e.r().default(!0),useBeacon:e.r().default(!0),keepaliveFetch:e.r().default(!0),timeoutMs:e.a().int().positive().default(4e3),maxRetries:e.a().int().min(0).max(5).default(1)}),u=`__gengageWidgetsInit`,d=e.o({idempotencyKey:e.c().default(u),requireDomReady:e.r().default(!0)}),f=e.t([`log-and-ignore`,`throw`,`delegate`]),p=e.o({unknownActionPolicy:f.default(`log-and-ignore`),allowScriptCall:e.r().default(!1)}),m=e.o({version:e.i(`1`,{error:`version must be "1"`}),accountId:e.c({error:`accountId must be a non-empty string`}).min(1,{error:`accountId must be a non-empty string`}),middlewareUrl:e.c({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")`}),locale:e.c().optional(),widgets:e.o({chat:i.default({enabled:!0}),qna:i.default({enabled:!0}),simrel:i.default({enabled:!0})}),mounts:a.default({}),transport:o.default({}),analytics:l.default({enabled:!0,endpoint:`/analytics`,auth:{mode:`none`,bodyField:`api_key`},fireAndForget:!0,useBeacon:!0,keepaliveFetch:!0,timeoutMs:4e3,maxRetries:1}),gtm:d.default({idempotencyKey:`__gengageWidgetsInit`,requireDomReady:!0}),actionHandling:p.default({unknownActionPolicy:`log-and-ignore`,allowScriptCall:!1})});function h(t){e.B(`config`,`parsing account runtime config`,t);let n=m.parse(t);return e.B(`config`,`config resolved`,{accountId:n.accountId,middlewareUrl:n.middlewareUrl}),n}function g(e){return m.safeParse(e)}function _(e){return h({version:`1`,accountId:e.accountId,middlewareUrl:e.middlewareUrl,locale:e.locale,widgets:{chat:{enabled:!0},qna:{enabled:!0},simrel:{enabled:!0}}})}var v=`${u}_overlay_`,y=`#gengage-qna`,b=`#gengage-simrel`;function x(){let e=window;return e.__gengageOverlayRegistry||={instances:{},pending:{}},e.__gengageOverlayRegistry}function S(e){let t={pageType:e.pageContext?.pageType??(e.sku===void 0?`other`:`pdp`)},n=e.pageContext;return n?.sku!==void 0&&(t.sku=n.sku),n?.price!==void 0&&(t.price=n.price),n?.categoryTree!==void 0&&(t.categoryTree=n.categoryTree),n?.url!==void 0&&(t.url=n.url),n?.extra!==void 0&&(t.extra=n.extra),e.sku!==void 0&&(t.sku=e.sku),t}function C(e,t){let n={...e,...t,pageType:t.pageType??e.pageType};return t.sku===void 0&&e.sku!==void 0&&(n.sku=e.sku),n}function w(e){return e instanceof HTMLElement||document.querySelector(e)?e:null}function T(e){return e.idempotencyKey??`${v}${e.accountId}`}var E=class{constructor(t,n){this.options=t,this.onDestroy=n,this._chat=null,this._qna=null,this._simrel=null,this._analyticsClient=null,this._offQnaWire=null,this._destroyed=!1,this._queue=Promise.resolve(),this._warnedQnaMountMissing=!1,this._warnedSimRelMountMissing=!1,this.idempotencyKey=T(t),this.session=e.Y(t.session),this._pageContext=S(t)}get chat(){return this._chat}get qna(){return this._qna}get simrel(){return this._simrel}get analyticsClient(){return this._analyticsClient}async init(){window.gengage||(window.gengage={}),window.gengage.sessionId=this.session.sessionId,window.gengage.pageContext=this._pageContext,await this._initChat(),this.options.wireQnaToChat!==!1&&(this._offQnaWire=e.$()),await this._syncPdpWidgets(),window.gengage.overlay=this}openChat(e){this._chat?.open(e)}closeChat(){this._chat?.close()}async updateContext(e){this._destroyed||await this._enqueue(async()=>{this._pageContext=C(this._pageContext,e),window.gengage||(window.gengage={}),window.gengage.pageContext=this._pageContext,this._chat?.update(e),this._qna?.update(e),this._simrel?.update(e),await this._syncPdpWidgets()})}async updateSku(e,t=`pdp`){await this.updateContext({sku:e,pageType:t})}destroy(){this._destroyed||(this._destroyed=!0,this._offQnaWire?.(),this._offQnaWire=null,this._chat?.destroy(),this._qna?.destroy(),this._simrel?.destroy(),this._chat=null,this._qna=null,this._simrel=null,window.gengage?.overlay===this&&delete window.gengage.overlay,this.onDestroy())}async _initChat(){if(this.options.chat?.enabled===!1)return;let e=this.options.middlewareUrl,n={accountId:this.options.accountId,middlewareUrl:e,session:this.session,pageContext:this._pageContext,variant:this.options.chat?.variant??`floating`};this.options.theme!==void 0&&(n.theme=this.options.theme),this.options.locale!==void 0&&(n.locale=this.options.locale),this.options.pricing!==void 0&&(n.pricing=this.options.pricing),this.options.chat?.mountTarget!==void 0&&(n.mountTarget=this.options.chat.mountTarget),this.options.chat?.launcherImageUrl===void 0?this.options.chat?.launcherSvg!==void 0&&(n.launcherSvg=this.options.chat.launcherSvg):n.launcherImageUrl=this.options.chat.launcherImageUrl,this.options.chat?.headerTitle!==void 0&&(n.headerTitle=this.options.chat.headerTitle),this.options.chat?.headerAvatarUrl!==void 0&&(n.headerAvatarUrl=this.options.chat.headerAvatarUrl),this.options.chat?.headerBadge!==void 0&&(n.headerBadge=this.options.chat.headerBadge),this.options.chat?.headerCartUrl!==void 0&&(n.headerCartUrl=this.options.chat.headerCartUrl),this.options.chat?.headerFavoritesToggle!==void 0&&(n.headerFavoritesToggle=this.options.chat.headerFavoritesToggle),this.options.chat?.hideMobileLauncher!==void 0&&(n.hideMobileLauncher=this.options.chat.hideMobileLauncher),this.options.chat?.mobileBreakpoint!==void 0&&(n.mobileBreakpoint=this.options.chat.mobileBreakpoint),this.options.chat?.mobileInitialState!==void 0&&(n.mobileInitialState=this.options.chat.mobileInitialState),this.options.chat?.i18n!==void 0&&(n.i18n=this.options.chat.i18n),this.options.chat?.actionHandling!==void 0&&(n.actionHandling=this.options.chat.actionHandling),this.options.chat?.renderer!==void 0&&(n.renderer=this.options.chat.renderer),this.options.onScriptCall!==void 0&&(n.onScriptCall=this.options.onScriptCall),this._chat=new t.t,await this._chat.init(n)}async _syncPdpWidgets(){if(this._destroyed)return;let t=this._pageContext.sku;if(!(this._pageContext.pageType===`pdp`&&t!==void 0&&t.length>0)){this._destroyPdpWidgets();return}let i=this.options.middlewareUrl;if(this.options.qna?.enabled!==!1){let e=this.options.qna?.mountTarget??y,r=w(e);if(r)if(this._warnedQnaMountMissing=!1,this._qna)this._qna.show(),this._qna.update({pageType:`pdp`,sku:t});else{let e=new n.t,a={accountId:this.options.accountId,middlewareUrl:i,session:this.session,pageContext:{pageType:`pdp`,sku:t},mountTarget:r};this.options.theme!==void 0&&(a.theme=this.options.theme),this.options.qna?.ctaText!==void 0&&(a.ctaText=this.options.qna.ctaText),this.options.qna?.hideButtonRowCta!==void 0&&(a.hideButtonRowCta=this.options.qna.hideButtonRowCta),this.options.qna?.inputPlaceholder!==void 0&&(a.inputPlaceholder=this.options.qna.inputPlaceholder),this.options.qna?.i18n!==void 0&&(a.i18n=this.options.qna.i18n),this.options.qna?.renderer!==void 0&&(a.renderer=this.options.qna.renderer),await e.init(a),this._qna=e}else this._qna?.destroy(),this._qna=null,this._warnedQnaMountMissing||=(console.warn(`[gengage] QNA mount target not found: ${e}`),!0)}else this._qna?.destroy(),this._qna=null;if(this.options.simrel?.enabled!==!1){let n=this.options.simrel?.mountTarget??b,a=w(n);if(a)if(this._warnedSimRelMountMissing=!1,this._simrel)this._simrel.show(),this._simrel.update({pageType:`pdp`,sku:t});else{let n=new r.t,o={accountId:this.options.accountId,middlewareUrl:i,session:this.session,sku:t,mountTarget:a};this.options.theme!==void 0&&(o.theme=this.options.theme),this.options.pricing!==void 0&&(o.pricing=this.options.pricing),this.options.simrel?.discountType!==void 0&&(o.discountType=this.options.simrel.discountType),this.options.simrel?.renderCardElement!==void 0&&(o.renderCardElement=this.options.simrel.renderCardElement),this.options.simrel?.renderer!==void 0&&(o.renderer=this.options.simrel.renderer),this.options.onAddToCart!==void 0&&(o.onAddToCart=this.options.onAddToCart),this.options.onProductNavigate===void 0?o.onProductNavigate=(t,n,r)=>{e.nt(t)&&(this._chat?.saveSession(r??this.session.sessionId,n),window.location.href=t)}:o.onProductNavigate=this.options.onProductNavigate,await n.init(o),this._simrel=n}else this._simrel?.destroy(),this._simrel=null,this._warnedSimRelMountMissing||=(console.warn(`[gengage] SimRel mount target not found: ${n}`),!0)}else this._simrel?.destroy(),this._simrel=null}_destroyPdpWidgets(){this._qna?.destroy(),this._simrel?.destroy(),this._qna=null,this._simrel=null}_enqueue(e){let t=this._queue.then(e);return this._queue=t.catch(e=>{}),t}};async function D(e){let t=T(e),n=x(),r=n.instances[t];if(r)return r;let i=n.pending[t];if(i)return i;let a=new E(e,()=>{let e=x();delete e.instances[t],delete e.pending[t]}),o=a.init().then(()=>(n.instances[t]=a,delete n.pending[t],a)).catch(e=>{throw delete n.pending[t],e});return n.pending[t]=o,o}function O(e){return x().instances[e]??null}function k(e){O(e)?.destroy()}function A(e){return`${v}${e}`}var j=[`gengage:chat:open`,`gengage:chat:close`,`gengage:chat:ready`,`gengage:chat:add-to-cart`,`gengage:qna:action`,`gengage:qna:open-chat`,`gengage:similar:product-click`,`gengage:similar:add-to-cart`,`gengage:global:error`,`gengage:context:update`],M=32,N=`#gengage-qna`,P=`#gengage-simrel`;function F(e){return e}function I(e){let t=e;if(typeof e==`string`){let n=e.trim();if(n.length===0)return null;if(!n.startsWith(`{`)&&!n.startsWith(`[`))return{type:n};try{t=JSON.parse(n)}catch{return null}}if(!t||typeof t!=`object`)return null;let n=t,r=[n.type,n.command,n.action,n.event].find(e=>typeof e==`string`&&e.length>0);if(!r)return null;let i=n.payload;if(i===void 0&&`data`in n&&(i=n.data),r===`setSession`&&i===void 0){let e={};typeof n.sessionId==`string`&&(e.sessionId=n.sessionId),typeof n.userId==`string`&&(e.userId=n.userId),(e.sessionId!==void 0||e.userId!==void 0)&&(i=e)}return i===void 0?{type:r}:{type:r,payload:i}}function L(e){if(typeof e==`string`&&e.length>0)return{sku:e};if(e&&typeof e==`object`&&`sku`in e){let t=e.sku;if(typeof t==`string`&&t.length>0){let n=e.pageType;return n===void 0?{sku:t}:{sku:t,pageType:n}}}return null}function R(e,t){return t instanceof HTMLElement?!0:typeof t==`string`?e.document.querySelector(t)!==null:!1}function z(e,t,n){if(t instanceof HTMLElement||R(e,t)||typeof t!=`string`)return t;if(t.startsWith(`#`)){let n=t.slice(1);if(n.length>0){let t=e.document.getElementById(n);if(t)return t;let r=e.document.createElement(`div`);return r.id=n,e.document.body.appendChild(r),r}}let r=e.document.getElementById(n);if(r)return r;let i=e.document.createElement(`div`);return i.id=n,e.document.body.appendChild(i),i}function B(e,t){let n=F(e).webkit?.messageHandlers?.[t];return n&&typeof n.postMessage==`function`?n.postMessage.bind(n):null}function V(e,t){let n=e[t];return n&&typeof n==`object`&&typeof n.postMessage==`function`?n:null}function H(e={}){let t=e.win??window,n=e.iosHandlerName??`gengage`,r=e.androidInterfaceName??`GengageNative`,i=e.reactNativeInterfaceName??`ReactNativeWebView`;return B(t,n)?`ios`:V(t,r)?`android`:V(t,i)?`react-native`:`browser`}function U(e,t={}){let n=t.win??window;if(e.sessionId!==void 0){n.__gengageSessionId=e.sessionId,n.gengage||={},n.gengage.sessionId=e.sessionId;try{n.sessionStorage.setItem(`gengage_session_id`,e.sessionId)}catch{}}if(e.userId!==void 0){n.gengage||={};let t=n.gengage,r=t.session??{};r.userId=e.userId,t.session=r}}function W(e={}){let t=e.win??window,n=F(t);if(n.gengageNative)return n.gengageNative;let r=e.iosHandlerName??`gengage`,i=e.androidInterfaceName??`GengageNative`,a=e.reactNativeInterfaceName??`ReactNativeWebView`,o=e.trackedEvents??[...j],s=H({win:t,iosHandlerName:r,androidInterfaceName:i,reactNativeInterfaceName:a}),c=t.gengage?.overlay??null,l=[],u=(e,n)=>{let o=n===void 0?{type:e}:{type:e,payload:n};if(s===`ios`){B(t,r)?.(o);return}if(s===`android`){V(t,i)?.postMessage(JSON.stringify(o));return}if(s===`react-native`){V(t,a)?.postMessage(JSON.stringify(o));return}},d=e=>{let t=e.detail;!t||typeof t.namespace!=`string`||typeof t.type!=`string`||u(`bridge_message`,{namespace:t.namespace,type:t.type,payload:t.payload})};t.addEventListener(`gengage:bridge:message`,d);let f=o.map(e=>{let n=t=>{let n=t.detail;u(`widget_event`,{event:e,detail:n})};return t.addEventListener(e,n),{event:e,handler:n}}),p=e=>{l.length>=M&&l.shift(),l.push(e)},m=()=>{if(!c||l.length===0)return;let e=l.splice(0,l.length);for(let t of e)h(t)},h=n=>{let r=I(n);if(!r||typeof r.type!=`string`){console.warn(`[gengage:native-bridge] Invalid message:`,n);return}let i=r.type,a=r.payload;switch(i){case`openChat`:c?c.openChat(a&&typeof a==`object`?a:a===`half`||a===`full`?{state:a}:void 0):p(r);return;case`closeChat`:c?c.closeChat():p(r);return;case`updateContext`:c&&a&&typeof a==`object`?c.updateContext(a):c?console.warn(`[gengage:native-bridge] updateContext: missing payload`):p(r);return;case`updateSku`:{let e=L(a);if(c&&e){c.updateSku(e.sku,e.pageType);return}c?console.warn(`[gengage:native-bridge] updateSku: missing sku`):p(r);return}case`setSession`:a&&typeof a==`object`&&U(a,{win:t});return;case`destroy`:c?.destroy();return;default:t.postMessage({gengage:`native`,type:i,payload:a},t.location.origin),e.logUnhandled&&console.warn(`[gengage:native-bridge] Unhandled inbound type forwarded:`,i)}},g={env:s,sendToNative:u,receive:h,setController(e){c=e,m()},destroy(){t.removeEventListener(`gengage:bridge:message`,d);for(let e of f)t.removeEventListener(e.event,e.handler);l.splice(0,l.length),F(t).gengageNative===g&&delete F(t).gengageNative}};return n.gengageNative=g,g}async function G(e){let{nativeBridge:t,emitReadyEvent:n=!0,...r}=e,i=W(t),a={...r};a.onAddToCart||=e=>{i.sendToNative(`addToCart`,{sku:e.sku,quantity:e.quantity,cartCode:e.cartCode})},a.onProductNavigate||=(e,t,n)=>{i.sendToNative(`productNavigate`,{url:e,sku:t,sessionId:n})};let o=a.qna?.enabled===!0||a.qna?.mountTarget!==void 0;if(a.qna?.enabled!==!1)if(o){let e=z(window,a.qna?.mountTarget??N,`gengage-qna`);a.qna={...a.qna,enabled:!0,mountTarget:e}}else R(window,N)||(a.qna={enabled:!1});let s=a.simrel?.enabled===!0||a.simrel?.mountTarget!==void 0;if(a.simrel?.enabled!==!1)if(s){let e=z(window,a.simrel?.mountTarget??P,`gengage-simrel`);a.simrel={...a.simrel,enabled:!0,mountTarget:e}}else R(window,P)||(a.simrel={enabled:!1});let c=await D(a);return i.setController(c),n&&i.sendToNative(`ready`,{sessionId:c.session.sessionId,widgets:{chat:c.chat!==null,qna:c.qna!==null,simrel:c.simrel!==null}}),{controller:c,bridge:i,destroy(){c.destroy(),i.destroy()}}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return m}});
2
+ //# sourceMappingURL=native-webview-D1v6n8kJ.cjs.map