@gengage/assistant-fe 0.4.5 → 0.4.6

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 (49) hide show
  1. package/README.md +1 -1
  2. package/dist/api-paths-C4GDpeTf.js +1214 -0
  3. package/dist/chat/index.d.ts +1 -374
  4. package/dist/chat/runtime.d.ts +374 -0
  5. package/dist/chat-BRKK63lt.js +303 -0
  6. package/dist/chat-runtime.js +13 -0
  7. package/dist/chat.iife.js +6 -6
  8. package/dist/chat.js +11 -10
  9. package/dist/common/config-constants.d.ts +1 -0
  10. package/dist/common/config-schema.d.ts +0 -1
  11. package/dist/common/overlay.d.ts +4 -4
  12. package/dist/common-CEN5OW7E.js +491 -0
  13. package/dist/common.js +78 -76
  14. package/dist/{connection-warning-n88bjkqL.js → connection-warning-B6oIU-9s.js} +1 -1
  15. package/dist/context-VIG4SVcS.js +529 -0
  16. package/dist/index.js +70 -67
  17. package/dist/locale-CfqNifrU.js +7 -0
  18. package/dist/native-webview-DudQ7nHe.js +273 -0
  19. package/dist/native.iife.js +28 -91
  20. package/dist/native.js +1 -1
  21. package/dist/overlay-1EO41ZC7.js +212 -0
  22. package/dist/overlay.d.ts +4 -0
  23. package/dist/overlay.js +10 -0
  24. package/dist/pill-launcher-57nrdLRr.js +364 -0
  25. package/dist/qna/index.d.ts +1 -61
  26. package/dist/qna/runtime.d.ts +61 -0
  27. package/dist/qna-BNvttR6s.js +40 -0
  28. package/dist/qna-runtime.js +8 -0
  29. package/dist/qna.iife.js +4 -4
  30. package/dist/qna.js +6 -5
  31. package/dist/{simrel-K2TGFi1r.js → runtime-BdwZZIrO.js} +244 -293
  32. package/dist/{chat-B1lLKIxj.js → runtime-C0qZk0y7.js} +1643 -2297
  33. package/dist/{qna-C5Ok3wd0.js → runtime-DDu8Wk0z.js} +87 -121
  34. package/dist/schemas-CLo8wCjs.js +3207 -0
  35. package/dist/{simbut-Cb5RfaAp.js → simbut-BMWC6x_t.js} +24 -22
  36. package/dist/simbut.js +1 -1
  37. package/dist/simrel/index.d.ts +1 -59
  38. package/dist/simrel/runtime.d.ts +59 -0
  39. package/dist/simrel-ohfkluhp.js +55 -0
  40. package/dist/simrel-runtime.js +8 -0
  41. package/dist/simrel.iife.js +4 -4
  42. package/dist/simrel.js +7 -6
  43. package/dist/widget-base-TgwiA8cD.js +578 -0
  44. package/package.json +17 -1
  45. package/dist/common-C5e2gLuG.js +0 -387
  46. package/dist/locale-MM0U5eeR.js +0 -1109
  47. package/dist/native-webview-niMtkiHX.js +0 -586
  48. package/dist/schemas-JpRGzRQT.js +0 -4419
  49. /package/dist/{price-formatter-CR6VT5z4.js → price-formatter-xI3g9Cd4.js} +0 -0
@@ -1,586 +0,0 @@
1
- import { a as N, c as h, i as W, o as f, r as m, t as A } from "./schemas-JpRGzRQT.js";
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-B1lLKIxj.js";
4
- import { t as $ } from "./qna-C5Ok3wd0.js";
5
- import { t as G } from "./simrel-K2TGFi1r.js";
6
- import { t as Y } from "./simbut-Cb5RfaAp.js";
7
- var w = f({ enabled: m().default(!0) }), J = f({
8
- chat: h().optional(),
9
- qna: h().optional(),
10
- simrel: h().optional(),
11
- simbut: h().optional()
12
- }), X = f({}), z = A([
13
- "none",
14
- "x-api-key-header",
15
- "bearer-header",
16
- "body-api-key"
17
- ]), Z = f({
18
- mode: z.default("none"),
19
- key: h().optional(),
20
- headerName: h().optional(),
21
- bodyField: h().default("api_key")
22
- }), ee = f({
23
- enabled: m().default(!0),
24
- endpoint: h().default("/analytics"),
25
- auth: Z.default({
26
- mode: "none",
27
- bodyField: "api_key"
28
- }),
29
- fireAndForget: m().default(!0),
30
- useBeacon: m().default(!0),
31
- keepaliveFetch: m().default(!0),
32
- timeoutMs: N().int().positive().default(4e3),
33
- maxRetries: N().int().min(0).max(5).default(1)
34
- }), R = "__gengageWidgetsInit", te = f({
35
- idempotencyKey: h().default(R),
36
- requireDomReady: m().default(!0)
37
- }), ie = A([
38
- "log-and-ignore",
39
- "throw",
40
- "delegate"
41
- ]), ne = f({
42
- unknownActionPolicy: ie.default("log-and-ignore"),
43
- allowScriptCall: m().default(!1)
44
- }), L = f({
45
- version: W("1", { error: 'version must be "1"' }),
46
- accountId: h({ error: "accountId must be a non-empty string" }).min(1, { error: "accountId must be a non-empty string" }),
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
- locale: h().optional(),
49
- widgets: f({
50
- chat: w.default({ enabled: !0 }),
51
- qna: w.default({ enabled: !0 }),
52
- simrel: w.optional(),
53
- simbut: w.default({ enabled: !1 })
54
- }),
55
- mounts: J.default({}),
56
- transport: X.default({}),
57
- analytics: ee.default({
58
- enabled: !0,
59
- endpoint: "/analytics",
60
- auth: {
61
- mode: "none",
62
- bodyField: "api_key"
63
- },
64
- fireAndForget: !0,
65
- useBeacon: !0,
66
- keepaliveFetch: !0,
67
- timeoutMs: 4e3,
68
- maxRetries: 1
69
- }),
70
- gtm: te.default({
71
- idempotencyKey: "__gengageWidgetsInit",
72
- requireDomReady: !0
73
- }),
74
- actionHandling: ne.default({
75
- unknownActionPolicy: "log-and-ignore",
76
- allowScriptCall: !1
77
- })
78
- });
79
- function se(e) {
80
- M("config", "parsing account runtime config", e);
81
- const t = L.parse(e);
82
- return M("config", "config resolved", {
83
- accountId: t.accountId,
84
- middlewareUrl: t.middlewareUrl
85
- }), t;
86
- }
87
- function ke(e) {
88
- return L.safeParse(e);
89
- }
90
- function qe(e) {
91
- return se({
92
- version: "1",
93
- accountId: e.accountId,
94
- middlewareUrl: e.middlewareUrl,
95
- locale: e.locale,
96
- widgets: {
97
- chat: { enabled: !0 },
98
- qna: { enabled: !0 },
99
- simbut: { enabled: !1 }
100
- }
101
- });
102
- }
103
- var P = `${R}_overlay_`, oe = "#gengage-qna", ae = "#gengage-simrel", re = "#gengage-simbut";
104
- function I() {
105
- const e = window;
106
- return e.__gengageOverlayRegistry || (e.__gengageOverlayRegistry = {
107
- instances: {},
108
- pending: {}
109
- }), e.__gengageOverlayRegistry;
110
- }
111
- function de(e) {
112
- const t = { pageType: e.pageContext?.pageType ?? (e.sku !== void 0 ? "pdp" : "other") }, i = e.pageContext;
113
- return i?.sku !== void 0 && (t.sku = i.sku), i?.skuList !== void 0 && (t.skuList = i.skuList), i?.price !== void 0 && (t.price = i.price), i?.categoryTree !== void 0 && (t.categoryTree = i.categoryTree), i?.url !== void 0 && (t.url = i.url), i?.extra !== void 0 && (t.extra = i.extra), e.sku !== void 0 && (t.sku = e.sku), t;
114
- }
115
- function le(e, t) {
116
- const i = {
117
- ...e,
118
- ...t,
119
- pageType: t.pageType ?? e.pageType
120
- };
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;
122
- }
123
- function S(e) {
124
- return e instanceof HTMLElement || document.querySelector(e) ? e : null;
125
- }
126
- function B(e) {
127
- return e.idempotencyKey ?? `${P}${e.accountId}`;
128
- }
129
- var ce = class {
130
- constructor(e, t) {
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);
132
- }
133
- get chat() {
134
- return this._chat;
135
- }
136
- get qna() {
137
- return this._qna;
138
- }
139
- get simrel() {
140
- return this._simrel;
141
- }
142
- get simbut() {
143
- return this._simbut;
144
- }
145
- get analyticsClient() {
146
- return this._analyticsClient;
147
- }
148
- async init() {
149
- window.gengage || (window.gengage = {}), window.gengage.sessionId = this.session.sessionId, window.gengage.pageContext = this._pageContext, await this._initChat(), this.options.wireQnaToChat !== !1 && (this._offQnaWire = K()), await this._syncPdpWidgets(), window.gengage.overlay = this;
150
- }
151
- openChat(e) {
152
- this._chat?.open(e);
153
- }
154
- closeChat() {
155
- this._chat?.close();
156
- }
157
- async updateContext(e) {
158
- this._destroyed || await this._enqueue(async () => {
159
- this._pageContext = le(this._pageContext, e), window.gengage || (window.gengage = {}), window.gengage.pageContext = this._pageContext, this._chat?.update(this._pageContext), this._qna?.update(this._pageContext), this._simrel?.update(this._pageContext), this._simbut?.update(this._pageContext), await this._syncPdpWidgets();
160
- });
161
- }
162
- async updateSku(e, t = "pdp") {
163
- await this.updateContext({
164
- sku: e,
165
- pageType: t
166
- });
167
- }
168
- async updatePageContext(e) {
169
- await this.updateContext(e);
170
- }
171
- async setPageContext(e) {
172
- await this.updateContext(e);
173
- }
174
- destroy() {
175
- this._destroyed || (this._destroyed = !0, this._offQnaWire?.(), this._offQnaWire = null, this._chat?.destroy(), this._qna?.destroy(), this._simrel?.destroy(), this._simbut?.destroy(), this._chat = null, this._qna = null, this._simrel = null, this._simbut = null, window.gengage?.overlay === this && delete window.gengage.overlay, this.onDestroy());
176
- }
177
- async _initChat() {
178
- if (this.options.chat?.enabled === !1) return;
179
- const e = this.options.middlewareUrl, t = this.options.chat?.productDetailsExtended ?? this.options.productDetailsExtended, i = this.options.chat?.isDemoWebsite ?? this.options.isDemoWebsite, s = {
180
- accountId: this.options.accountId,
181
- middlewareUrl: e,
182
- session: this.session,
183
- pageContext: this._pageContext,
184
- variant: this.options.chat?.variant ?? "floating"
185
- };
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);
187
- }
188
- async _syncPdpWidgets() {
189
- if (this._destroyed) return;
190
- const e = this._pageContext.sku;
191
- if (!(this._pageContext.pageType === "pdp" && e !== void 0 && e.length > 0)) {
192
- this._qna?.hide(), this._simrel?.hide(), this._simbut?.hide();
193
- return;
194
- }
195
- const t = this.options.middlewareUrl;
196
- if (this.options.qna?.enabled !== !1) {
197
- const i = this.options.qna?.mountTarget ?? oe, s = S(i);
198
- if (s)
199
- if (this._warnedQnaMountMissing = !1, this._qna)
200
- this._qna.show(), this._qna.update({
201
- pageType: "pdp",
202
- sku: e
203
- });
204
- else {
205
- const o = new $(), n = {
206
- accountId: this.options.accountId,
207
- middlewareUrl: t,
208
- session: this.session,
209
- pageContext: {
210
- pageType: "pdp",
211
- sku: e
212
- },
213
- mountTarget: s
214
- };
215
- this.options.theme !== void 0 && (n.theme = this.options.theme), this.options.qna?.ctaText !== void 0 && (n.ctaText = this.options.qna.ctaText), this.options.qna?.hideButtonRowCta !== void 0 && (n.hideButtonRowCta = this.options.qna.hideButtonRowCta), this.options.qna?.inputPlaceholder !== void 0 && (n.inputPlaceholder = this.options.qna.inputPlaceholder), this.options.qna?.i18n !== void 0 && (n.i18n = this.options.qna.i18n), this.options.qna?.renderer !== void 0 && (n.renderer = this.options.qna.renderer);
216
- const d = this.options.qna?.headerTitle ?? this.options.qna?.headingTitle;
217
- d !== void 0 && (n.headerTitle = d), await o.init(n), this._qna = o;
218
- }
219
- else
220
- this._qna?.destroy(), this._qna = null, this._warnedQnaMountMissing || (console.warn(`[gengage] QNA mount target not found: ${i}`), this._warnedQnaMountMissing = !0);
221
- } else
222
- this._qna?.destroy(), this._qna = null;
223
- if (this.options.simrel !== void 0 && this.options.simrel.enabled !== !1) {
224
- const i = this.options.simrel?.mountTarget ?? ae, s = S(i);
225
- if (s)
226
- if (this._warnedSimRelMountMissing = !1, this._simrel)
227
- this._simrel.show(), this._simrel.update({
228
- pageType: "pdp",
229
- sku: e
230
- });
231
- else {
232
- const o = new G(), n = {
233
- accountId: this.options.accountId,
234
- middlewareUrl: t,
235
- session: this.session,
236
- sku: e,
237
- mountTarget: s
238
- };
239
- this.options.theme !== void 0 && (n.theme = this.options.theme), this.options.pricing !== void 0 && (n.pricing = this.options.pricing), this.options.simrel?.discountType !== void 0 && (n.discountType = this.options.simrel.discountType), this.options.simrel?.renderCardElement !== void 0 && (n.renderCardElement = this.options.simrel.renderCardElement), this.options.simrel?.renderer !== void 0 && (n.renderer = this.options.simrel.renderer), this.options.onAddToCart !== void 0 && (n.onAddToCart = this.options.onAddToCart), this.options.onProductNavigate !== void 0 ? n.onProductNavigate = this.options.onProductNavigate : n.onProductNavigate = (d, l, a) => {
240
- H(d) && (this._chat?.saveSession(a ?? this.session.sessionId, l), window.location.href = d);
241
- }, await o.init(n), this._simrel = o;
242
- }
243
- else
244
- this._simrel?.destroy(), this._simrel = null, this._warnedSimRelMountMissing || (console.warn(`[gengage] SimRel mount target not found: ${i}`), this._warnedSimRelMountMissing = !0);
245
- } else
246
- this._simrel?.destroy(), this._simrel = null;
247
- if (this.options.simbut && this.options.simbut.enabled !== !1) {
248
- const i = this.options.simbut.mountTarget ?? re, s = S(i), o = this._chat ?? this.options.simbut.onFindSimilar;
249
- if (s && o)
250
- if (this._warnedSimButMountMissing = !1, this._warnedSimButNoChat = !1, this._simbut)
251
- this._simbut.show(), this._simbut.setChat(this._chat), this._simbut.update({
252
- pageType: "pdp",
253
- sku: e
254
- });
255
- else {
256
- const n = new Y(), d = {
257
- accountId: this.options.accountId,
258
- middlewareUrl: t,
259
- session: this.session,
260
- pageContext: {
261
- pageType: "pdp",
262
- sku: e
263
- },
264
- mountTarget: s,
265
- chat: this._chat
266
- };
267
- this.options.theme !== void 0 && (d.theme = this.options.theme), this.options.locale !== void 0 && (d.locale = this.options.locale), this.options.simbut.imageUrl !== void 0 && (d.imageUrl = this.options.simbut.imageUrl), this.options.simbut.i18n !== void 0 && (d.i18n = this.options.simbut.i18n), this.options.simbut.onFindSimilar !== void 0 && (d.onFindSimilar = this.options.simbut.onFindSimilar), await n.init(d), this._simbut = n;
268
- }
269
- else
270
- this._simbut?.destroy(), this._simbut = null, !s && !this._warnedSimButMountMissing ? (console.warn(`[gengage] SimBut mount target not found: ${i}`), this._warnedSimButMountMissing = !0) : !o && !this._warnedSimButNoChat && (console.warn("[gengage] SimBut requires chat to be enabled or simbut.onFindSimilar"), this._warnedSimButNoChat = !0);
271
- } else
272
- this._simbut?.destroy(), this._simbut = null;
273
- }
274
- _enqueue(e) {
275
- const t = this._queue.then(e);
276
- return this._queue = t.catch((i) => {
277
- }), t;
278
- }
279
- };
280
- async function ue(e) {
281
- const t = B(e), i = I(), s = i.instances[t];
282
- if (s) return s;
283
- const o = i.pending[t];
284
- if (o) return o;
285
- const n = new ce(e, () => {
286
- const l = I();
287
- delete l.instances[t], delete l.pending[t];
288
- }), d = n.init().then(() => (i.instances[t] = n, delete i.pending[t], n)).catch((l) => {
289
- throw delete i.pending[t], j({
290
- reason: "overlay_init_failed",
291
- message: l instanceof Error ? l.message : String(l)
292
- }), l;
293
- });
294
- return i.pending[t] = d, d;
295
- }
296
- function ge(e) {
297
- return I().instances[e] ?? null;
298
- }
299
- function Ne(e) {
300
- ge(e)?.destroy();
301
- }
302
- function Me(e) {
303
- return `${P}${e}`;
304
- }
305
- var he = [
306
- "gengage:chat:open",
307
- "gengage:chat:close",
308
- "gengage:chat:ready",
309
- "gengage:chat:add-to-cart",
310
- "gengage:qna:action",
311
- "gengage:qna:open-chat",
312
- "gengage:similar:product-click",
313
- "gengage:similar:grouping-click",
314
- "gengage:similar:products-impression",
315
- "gengage:similar:add-to-cart",
316
- "gengage:global:error",
317
- "gengage:context:update"
318
- ], pe = 32, x = "#gengage-qna", U = "#gengage-simrel";
319
- function fe(e) {
320
- let t = e;
321
- if (typeof e == "string") {
322
- const n = e.trim();
323
- if (n.length === 0) return null;
324
- if (!n.startsWith("{") && !n.startsWith("[")) return { type: n };
325
- try {
326
- t = JSON.parse(n);
327
- } catch {
328
- return null;
329
- }
330
- }
331
- if (!t || typeof t != "object") return null;
332
- const i = t, s = [
333
- i.type,
334
- i.command,
335
- i.action,
336
- i.event
337
- ].find((n) => typeof n == "string" && n.length > 0);
338
- if (!s) return null;
339
- let o = i.payload;
340
- if (o === void 0 && "data" in i && (o = i.data), s === "setSession" && o === void 0) {
341
- const n = {};
342
- typeof i.sessionId == "string" && (n.sessionId = i.sessionId), typeof i.userId == "string" && (n.userId = i.userId), (n.sessionId !== void 0 || n.userId !== void 0) && (o = n);
343
- }
344
- return o === void 0 ? { type: s } : {
345
- type: s,
346
- payload: o
347
- };
348
- }
349
- function me(e) {
350
- if (typeof e == "string" && e.length > 0) return { sku: e };
351
- if (e && typeof e == "object" && "sku" in e) {
352
- const t = e.sku;
353
- if (typeof t == "string" && t.length > 0) {
354
- const i = e.pageType;
355
- return i !== void 0 ? {
356
- sku: t,
357
- pageType: i
358
- } : { sku: t };
359
- }
360
- }
361
- return null;
362
- }
363
- function k(e, t) {
364
- return t instanceof HTMLElement ? !0 : typeof t != "string" ? !1 : e.document.querySelector(t) !== null;
365
- }
366
- function E(e, t, i) {
367
- if (t instanceof HTMLElement || k(e, t) || typeof t != "string") return t;
368
- if (t.startsWith("#")) {
369
- const n = t.slice(1);
370
- if (n.length > 0) {
371
- const d = e.document.getElementById(n);
372
- if (d) return d;
373
- const l = e.document.createElement("div");
374
- return l.id = n, e.document.body.appendChild(l), l;
375
- }
376
- }
377
- const s = e.document.getElementById(i);
378
- if (s) return s;
379
- const o = e.document.createElement("div");
380
- return o.id = i, e.document.body.appendChild(o), o;
381
- }
382
- function D(e, t) {
383
- const i = e.webkit?.messageHandlers?.[t];
384
- return i && typeof i.postMessage == "function" ? i.postMessage.bind(i) : null;
385
- }
386
- function b(e, t) {
387
- const i = e[t];
388
- return i && typeof i == "object" && typeof i.postMessage == "function" ? i : null;
389
- }
390
- function ve(e = {}) {
391
- const t = e.win ?? window, i = e.iosHandlerName ?? "gengage", s = e.androidInterfaceName ?? "GengageNative", o = e.reactNativeInterfaceName ?? "ReactNativeWebView";
392
- return D(t, i) ? "ios" : b(t, s) ? "android" : b(t, o) ? "react-native" : "browser";
393
- }
394
- function ye(e, t = {}) {
395
- const i = t.win ?? window;
396
- if (e.sessionId !== void 0) {
397
- i.__gengageSessionId = e.sessionId, i.gengage || (i.gengage = {}), i.gengage.sessionId = e.sessionId;
398
- try {
399
- i.sessionStorage.setItem("gengage_session_id", e.sessionId);
400
- } catch {
401
- }
402
- }
403
- if (e.userId !== void 0) {
404
- i.gengage || (i.gengage = {});
405
- const s = i.gengage, o = s.session ?? {};
406
- o.userId = e.userId, s.session = o;
407
- }
408
- }
409
- function _e(e = {}) {
410
- const t = e.win ?? window, i = t;
411
- if (i.gengageNative) return i.gengageNative;
412
- const s = e.iosHandlerName ?? "gengage", o = e.androidInterfaceName ?? "GengageNative", n = e.reactNativeInterfaceName ?? "ReactNativeWebView", d = e.trackedEvents ?? [...he], l = ve({
413
- win: t,
414
- iosHandlerName: s,
415
- androidInterfaceName: o,
416
- reactNativeInterfaceName: n
417
- });
418
- let a = t.gengage?.overlay ?? null;
419
- const u = [], v = (c, r) => {
420
- const p = r === void 0 ? { type: c } : {
421
- type: c,
422
- payload: r
423
- };
424
- if (l === "ios") {
425
- D(t, s)?.(p);
426
- return;
427
- }
428
- if (l === "android") {
429
- b(t, o)?.postMessage(JSON.stringify(p));
430
- return;
431
- }
432
- if (l === "react-native") {
433
- b(t, n)?.postMessage(JSON.stringify(p));
434
- return;
435
- }
436
- }, y = (c) => {
437
- const r = c.detail;
438
- !r || typeof r.namespace != "string" || typeof r.type != "string" || v("bridge_message", {
439
- namespace: r.namespace,
440
- type: r.type,
441
- payload: r.payload
442
- });
443
- };
444
- t.addEventListener("gengage:bridge:message", y);
445
- const O = d.map((c) => {
446
- const r = (p) => {
447
- const g = p.detail;
448
- v("widget_event", {
449
- event: c,
450
- detail: g
451
- });
452
- };
453
- return t.addEventListener(c, r), {
454
- event: c,
455
- handler: r
456
- };
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);
465
- if (!r || typeof r.type != "string") {
466
- console.warn("[gengage:native-bridge] Invalid message:", c);
467
- return;
468
- }
469
- const p = r.type, g = r.payload;
470
- switch (p) {
471
- case "openChat":
472
- a ? a.openChat(g && typeof g == "object" ? g : g === "half" || g === "full" ? { state: g } : void 0) : _(r);
473
- return;
474
- case "closeChat":
475
- a ? a.closeChat() : _(r);
476
- return;
477
- case "updateContext":
478
- case "updatePageContext":
479
- case "setPageContext":
480
- a && g && typeof g == "object" ? a.updateContext(g) : a ? console.warn(`[gengage:native-bridge] ${p}: missing payload`) : _(r);
481
- return;
482
- case "updateSku": {
483
- const T = me(g);
484
- if (a && T) {
485
- a.updateSku(T.sku, T.pageType);
486
- return;
487
- }
488
- a ? console.warn("[gengage:native-bridge] updateSku: missing sku") : _(r);
489
- return;
490
- }
491
- case "setSession":
492
- g && typeof g == "object" && ye(g, { win: t });
493
- return;
494
- case "destroy":
495
- a?.destroy();
496
- return;
497
- default:
498
- t.postMessage({
499
- gengage: "native",
500
- type: p,
501
- payload: g
502
- }, t.location.origin), e.logUnhandled && console.warn("[gengage:native-bridge] Unhandled inbound type forwarded:", p);
503
- }
504
- }, C = {
505
- env: l,
506
- sendToNative: v,
507
- receive: q,
508
- setController(c) {
509
- a = c, F();
510
- },
511
- destroy() {
512
- t.removeEventListener("gengage:bridge:message", y);
513
- for (const c of O) t.removeEventListener(c.event, c.handler);
514
- u.splice(0, u.length), t.gengageNative === C && delete t.gengageNative;
515
- }
516
- };
517
- return i.gengageNative = C, C;
518
- }
519
- async function xe(e) {
520
- const { nativeBridge: t, emitReadyEvent: i = !0, ...s } = e, o = _e(t), n = { ...s };
521
- n.onAddToCart || (n.onAddToCart = (u) => {
522
- o.sendToNative("addToCart", {
523
- sku: u.sku,
524
- quantity: u.quantity,
525
- cartCode: u.cartCode
526
- });
527
- }), n.onProductNavigate || (n.onProductNavigate = (u, v, y) => {
528
- o.sendToNative("productNavigate", {
529
- url: u,
530
- sku: v,
531
- sessionId: y
532
- });
533
- });
534
- const d = n.qna?.enabled === !0 || n.qna?.mountTarget !== void 0;
535
- if (n.qna?.enabled !== !1)
536
- if (d) {
537
- const u = E(window, n.qna?.mountTarget ?? x, "gengage-qna");
538
- n.qna = {
539
- ...n.qna,
540
- enabled: !0,
541
- mountTarget: u
542
- };
543
- } else k(window, x) || (n.qna = { enabled: !1 });
544
- const l = n.simrel?.enabled === !0 || n.simrel?.mountTarget !== void 0;
545
- if (n.simrel?.enabled !== !1)
546
- if (l) {
547
- const u = E(window, n.simrel?.mountTarget ?? U, "gengage-simrel");
548
- n.simrel = {
549
- ...n.simrel,
550
- enabled: !0,
551
- mountTarget: u
552
- };
553
- } else k(window, U) || (n.simrel = { enabled: !1 });
554
- const a = await ue(n);
555
- return o.setController(a), i && o.sendToNative("ready", {
556
- sessionId: a.session.sessionId,
557
- widgets: {
558
- chat: a.chat !== null,
559
- qna: a.qna !== null,
560
- simrel: a.simrel !== null
561
- }
562
- }), {
563
- controller: a,
564
- bridge: o,
565
- destroy() {
566
- a.destroy(), o.destroy();
567
- }
568
- };
569
- }
570
- export {
571
- xe as a,
572
- ge as c,
573
- z as d,
574
- ie as f,
575
- ke as h,
576
- ve as i,
577
- ue as l,
578
- se as m,
579
- ye as n,
580
- Me as o,
581
- qe as p,
582
- _e as r,
583
- Ne as s,
584
- he as t,
585
- L as u
586
- };