@gengage/assistant-fe 0.1.0

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 (200) hide show
  1. package/LICENSE +61 -0
  2. package/README.md +232 -0
  3. package/dist/assistant-fe.css +1 -0
  4. package/dist/chat/api.d.ts +87 -0
  5. package/dist/chat/api.d.ts.map +1 -0
  6. package/dist/chat/attachment-utils.d.ts +10 -0
  7. package/dist/chat/attachment-utils.d.ts.map +1 -0
  8. package/dist/chat/catalog.d.ts +1114 -0
  9. package/dist/chat/catalog.d.ts.map +1 -0
  10. package/dist/chat/components/AIGroupingCards.d.ts +4 -0
  11. package/dist/chat/components/AIGroupingCards.d.ts.map +1 -0
  12. package/dist/chat/components/AISuggestedSearchCards.d.ts +4 -0
  13. package/dist/chat/components/AISuggestedSearchCards.d.ts.map +1 -0
  14. package/dist/chat/components/AITopPicks.d.ts +4 -0
  15. package/dist/chat/components/AITopPicks.d.ts.map +1 -0
  16. package/dist/chat/components/CategoriesContainer.d.ts +4 -0
  17. package/dist/chat/components/CategoriesContainer.d.ts.map +1 -0
  18. package/dist/chat/components/ChatDrawer.d.ts +140 -0
  19. package/dist/chat/components/ChatDrawer.d.ts.map +1 -0
  20. package/dist/chat/components/ChoicePrompter.d.ts +16 -0
  21. package/dist/chat/components/ChoicePrompter.d.ts.map +1 -0
  22. package/dist/chat/components/ComparisonTable.d.ts +47 -0
  23. package/dist/chat/components/ComparisonTable.d.ts.map +1 -0
  24. package/dist/chat/components/FloatingComparisonButton.d.ts +11 -0
  25. package/dist/chat/components/FloatingComparisonButton.d.ts.map +1 -0
  26. package/dist/chat/components/GroundingReviewCard.d.ts +4 -0
  27. package/dist/chat/components/GroundingReviewCard.d.ts.map +1 -0
  28. package/dist/chat/components/KvkkBanner.d.ts +6 -0
  29. package/dist/chat/components/KvkkBanner.d.ts.map +1 -0
  30. package/dist/chat/components/Launcher.d.ts +25 -0
  31. package/dist/chat/components/Launcher.d.ts.map +1 -0
  32. package/dist/chat/components/PanelTopBar.d.ts +20 -0
  33. package/dist/chat/components/PanelTopBar.d.ts.map +1 -0
  34. package/dist/chat/components/ProactivePopup.d.ts +11 -0
  35. package/dist/chat/components/ProactivePopup.d.ts.map +1 -0
  36. package/dist/chat/components/ProsAndCons.d.ts +9 -0
  37. package/dist/chat/components/ProsAndCons.d.ts.map +1 -0
  38. package/dist/chat/components/ReviewHighlights.d.ts +3 -0
  39. package/dist/chat/components/ReviewHighlights.d.ts.map +1 -0
  40. package/dist/chat/components/ThumbnailsColumn.d.ts +23 -0
  41. package/dist/chat/components/ThumbnailsColumn.d.ts.map +1 -0
  42. package/dist/chat/components/actionClassifier.d.ts +13 -0
  43. package/dist/chat/components/actionClassifier.d.ts.map +1 -0
  44. package/dist/chat/components/productMentionLinker.d.ts +26 -0
  45. package/dist/chat/components/productMentionLinker.d.ts.map +1 -0
  46. package/dist/chat/components/renderUISpec.d.ts +15 -0
  47. package/dist/chat/components/renderUISpec.d.ts.map +1 -0
  48. package/dist/chat/components/typewriter.d.ts +25 -0
  49. package/dist/chat/components/typewriter.d.ts.map +1 -0
  50. package/dist/chat/extendedModeManager.d.ts +33 -0
  51. package/dist/chat/extendedModeManager.d.ts.map +1 -0
  52. package/dist/chat/index.d.ts +192 -0
  53. package/dist/chat/index.d.ts.map +1 -0
  54. package/dist/chat/locales/en.d.ts +3 -0
  55. package/dist/chat/locales/en.d.ts.map +1 -0
  56. package/dist/chat/locales/index.d.ts +6 -0
  57. package/dist/chat/locales/index.d.ts.map +1 -0
  58. package/dist/chat/locales/tr.d.ts +3 -0
  59. package/dist/chat/locales/tr.d.ts.map +1 -0
  60. package/dist/chat/types.d.ts +212 -0
  61. package/dist/chat/types.d.ts.map +1 -0
  62. package/dist/chat.cjs +2 -0
  63. package/dist/chat.cjs.map +1 -0
  64. package/dist/chat.iife.js +59 -0
  65. package/dist/chat.iife.js.map +1 -0
  66. package/dist/chat.js +11 -0
  67. package/dist/chat.js.map +1 -0
  68. package/dist/common/action-router.d.ts +30 -0
  69. package/dist/common/action-router.d.ts.map +1 -0
  70. package/dist/common/activity-tracker.d.ts +38 -0
  71. package/dist/common/activity-tracker.d.ts.map +1 -0
  72. package/dist/common/analytics-events.d.ts +90 -0
  73. package/dist/common/analytics-events.d.ts.map +1 -0
  74. package/dist/common/analytics.d.ts +58 -0
  75. package/dist/common/analytics.d.ts.map +1 -0
  76. package/dist/common/api-paths.d.ts +14 -0
  77. package/dist/common/api-paths.d.ts.map +1 -0
  78. package/dist/common/client.d.ts +20 -0
  79. package/dist/common/client.d.ts.map +1 -0
  80. package/dist/common/communication-bridge.d.ts +51 -0
  81. package/dist/common/communication-bridge.d.ts.map +1 -0
  82. package/dist/common/config-schema.d.ts +241 -0
  83. package/dist/common/config-schema.d.ts.map +1 -0
  84. package/dist/common/context.d.ts +28 -0
  85. package/dist/common/context.d.ts.map +1 -0
  86. package/dist/common/customization-factories.d.ts +63 -0
  87. package/dist/common/customization-factories.d.ts.map +1 -0
  88. package/dist/common/events.d.ts +47 -0
  89. package/dist/common/events.d.ts.map +1 -0
  90. package/dist/common/global-error-toast.d.ts +6 -0
  91. package/dist/common/global-error-toast.d.ts.map +1 -0
  92. package/dist/common/index.d.ts +36 -0
  93. package/dist/common/index.d.ts.map +1 -0
  94. package/dist/common/indexed-db.d.ts +74 -0
  95. package/dist/common/indexed-db.d.ts.map +1 -0
  96. package/dist/common/overlay.d.ts +64 -0
  97. package/dist/common/overlay.d.ts.map +1 -0
  98. package/dist/common/preflight.d.ts +12 -0
  99. package/dist/common/preflight.d.ts.map +1 -0
  100. package/dist/common/renderer/dom.d.ts +4 -0
  101. package/dist/common/renderer/dom.d.ts.map +1 -0
  102. package/dist/common/renderer/index.d.ts +5 -0
  103. package/dist/common/renderer/index.d.ts.map +1 -0
  104. package/dist/common/renderer/overrides.d.ts +24 -0
  105. package/dist/common/renderer/overrides.d.ts.map +1 -0
  106. package/dist/common/renderer/registry.d.ts +3 -0
  107. package/dist/common/renderer/registry.d.ts.map +1 -0
  108. package/dist/common/renderer/types.d.ts +20 -0
  109. package/dist/common/renderer/types.d.ts.map +1 -0
  110. package/dist/common/safe-html.d.ts +19 -0
  111. package/dist/common/safe-html.d.ts.map +1 -0
  112. package/dist/common/streaming.d.ts +32 -0
  113. package/dist/common/streaming.d.ts.map +1 -0
  114. package/dist/common/theme-utils.d.ts +16 -0
  115. package/dist/common/theme-utils.d.ts.map +1 -0
  116. package/dist/common/types.d.ts +298 -0
  117. package/dist/common/types.d.ts.map +1 -0
  118. package/dist/common/ui-theme.d.ts +10 -0
  119. package/dist/common/ui-theme.d.ts.map +1 -0
  120. package/dist/common/uuidv7.d.ts +8 -0
  121. package/dist/common/uuidv7.d.ts.map +1 -0
  122. package/dist/common/v1-protocol-adapter.d.ts +66 -0
  123. package/dist/common/v1-protocol-adapter.d.ts.map +1 -0
  124. package/dist/common/widget-base.d.ts +75 -0
  125. package/dist/common/widget-base.d.ts.map +1 -0
  126. package/dist/common.cjs +2 -0
  127. package/dist/common.cjs.map +1 -0
  128. package/dist/common.js +584 -0
  129. package/dist/common.js.map +1 -0
  130. package/dist/index-CFA70IGF.js +3626 -0
  131. package/dist/index-CFA70IGF.js.map +1 -0
  132. package/dist/index-Dfl89zpe.cjs +13 -0
  133. package/dist/index-Dfl89zpe.cjs.map +1 -0
  134. package/dist/index.cjs +2 -0
  135. package/dist/index.cjs.map +1 -0
  136. package/dist/index.d.ts +24 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +59 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/qna/api.d.ts +22 -0
  141. package/dist/qna/api.d.ts.map +1 -0
  142. package/dist/qna/catalog.d.ts +140 -0
  143. package/dist/qna/catalog.d.ts.map +1 -0
  144. package/dist/qna/components/ButtonRow.d.ts +16 -0
  145. package/dist/qna/components/ButtonRow.d.ts.map +1 -0
  146. package/dist/qna/components/TextInput.d.ts +12 -0
  147. package/dist/qna/components/TextInput.d.ts.map +1 -0
  148. package/dist/qna/components/renderUISpec.d.ts +8 -0
  149. package/dist/qna/components/renderUISpec.d.ts.map +1 -0
  150. package/dist/qna/index.d.ts +34 -0
  151. package/dist/qna/index.d.ts.map +1 -0
  152. package/dist/qna/locales/en.d.ts +3 -0
  153. package/dist/qna/locales/en.d.ts.map +1 -0
  154. package/dist/qna/locales/index.d.ts +6 -0
  155. package/dist/qna/locales/index.d.ts.map +1 -0
  156. package/dist/qna/locales/tr.d.ts +3 -0
  157. package/dist/qna/locales/tr.d.ts.map +1 -0
  158. package/dist/qna/types.d.ts +62 -0
  159. package/dist/qna/types.d.ts.map +1 -0
  160. package/dist/qna.cjs +2 -0
  161. package/dist/qna.cjs.map +1 -0
  162. package/dist/qna.css +1 -0
  163. package/dist/qna.iife.js +48 -0
  164. package/dist/qna.iife.js.map +1 -0
  165. package/dist/qna.js +435 -0
  166. package/dist/qna.js.map +1 -0
  167. package/dist/simrel/api.d.ts +26 -0
  168. package/dist/simrel/api.d.ts.map +1 -0
  169. package/dist/simrel/catalog.d.ts +319 -0
  170. package/dist/simrel/catalog.d.ts.map +1 -0
  171. package/dist/simrel/components/GroupTabs.d.ts +17 -0
  172. package/dist/simrel/components/GroupTabs.d.ts.map +1 -0
  173. package/dist/simrel/components/ProductCard.d.ts +17 -0
  174. package/dist/simrel/components/ProductCard.d.ts.map +1 -0
  175. package/dist/simrel/components/ProductGrid.d.ts +17 -0
  176. package/dist/simrel/components/ProductGrid.d.ts.map +1 -0
  177. package/dist/simrel/components/renderUISpec.d.ts +8 -0
  178. package/dist/simrel/components/renderUISpec.d.ts.map +1 -0
  179. package/dist/simrel/index.d.ts +36 -0
  180. package/dist/simrel/index.d.ts.map +1 -0
  181. package/dist/simrel/locales/en.d.ts +3 -0
  182. package/dist/simrel/locales/en.d.ts.map +1 -0
  183. package/dist/simrel/locales/index.d.ts +6 -0
  184. package/dist/simrel/locales/index.d.ts.map +1 -0
  185. package/dist/simrel/locales/tr.d.ts +3 -0
  186. package/dist/simrel/locales/tr.d.ts.map +1 -0
  187. package/dist/simrel/types.d.ts +111 -0
  188. package/dist/simrel/types.d.ts.map +1 -0
  189. package/dist/simrel.cjs +2 -0
  190. package/dist/simrel.cjs.map +1 -0
  191. package/dist/simrel.css +1 -0
  192. package/dist/simrel.iife.js +48 -0
  193. package/dist/simrel.iife.js.map +1 -0
  194. package/dist/simrel.js +620 -0
  195. package/dist/simrel.js.map +1 -0
  196. package/dist/types-CeON7iBO.cjs +48 -0
  197. package/dist/types-CeON7iBO.cjs.map +1 -0
  198. package/dist/types-yxW8WA7u.js +4132 -0
  199. package/dist/types-yxW8WA7u.js.map +1 -0
  200. package/package.json +100 -0
package/dist/common.js ADDED
@@ -0,0 +1,584 @@
1
+ import { o as l, s as d, D as k, f as v, e as c, q as p, E as I, F as x, G as E } from "./types-yxW8WA7u.js";
2
+ import { B as be, H as Ce, a as ke, t as Ie, I as xe, b as Ee, y as Se, J as Ae, K as qe, c as Ue, L as Me, M as Re, j as Pe, k as Fe, N as Oe, O as Ne, z as De, m as Le, x as Be, P as We, p as $e, n as He, Q as ze, R as Ge, r as Ke, S as Qe, C as je, i as Ye, l as Ve, T as Je, h as Xe, A as Ze, U as et, w as tt, V as it, W as nt } from "./types-yxW8WA7u.js";
3
+ import { G as S } from "./index-CFA70IGF.js";
4
+ import { r as ot, s as at } from "./index-CFA70IGF.js";
5
+ import { GengageQNA as A } from "./qna.js";
6
+ import { GengageSimRel as q } from "./simrel.js";
7
+ const g = l({
8
+ enabled: c().default(!0)
9
+ }), U = l({
10
+ chat: d().optional(),
11
+ qna: d().optional(),
12
+ simrel: d().optional()
13
+ }), M = l({}), R = v(["none", "x-api-key-header", "bearer-header", "body-api-key"]), P = l({
14
+ mode: R.default("none"),
15
+ key: d().optional(),
16
+ headerName: d().optional(),
17
+ bodyField: d().default("api_key")
18
+ }), F = l({
19
+ enabled: c().default(!0),
20
+ endpoint: d().default("/analytics"),
21
+ auth: P.default({ mode: "none", bodyField: "api_key" }),
22
+ fireAndForget: c().default(!0),
23
+ useBeacon: c().default(!0),
24
+ keepaliveFetch: c().default(!0),
25
+ timeoutMs: p().int().positive().default(4e3),
26
+ maxRetries: p().int().min(0).max(5).default(1)
27
+ }), w = "__gengageWidgetsInit", O = l({
28
+ idempotencyKey: d().default(w),
29
+ requireDomReady: c().default(!0)
30
+ }), N = v(["log-and-ignore", "throw", "delegate"]), D = l({
31
+ unknownActionPolicy: N.default("log-and-ignore"),
32
+ allowScriptCall: c().default(!0)
33
+ }), _ = l({
34
+ version: k("1"),
35
+ accountId: d().min(1),
36
+ middlewareUrl: d().url(),
37
+ locale: d().optional(),
38
+ widgets: l({
39
+ chat: g.default({ enabled: !0 }),
40
+ qna: g.default({ enabled: !0 }),
41
+ simrel: g.default({ enabled: !0 })
42
+ }),
43
+ mounts: U.default({}),
44
+ transport: M.default({}),
45
+ analytics: F.default({
46
+ enabled: !0,
47
+ endpoint: "/analytics",
48
+ auth: { mode: "none", bodyField: "api_key" },
49
+ fireAndForget: !0,
50
+ useBeacon: !0,
51
+ keepaliveFetch: !0,
52
+ timeoutMs: 4e3,
53
+ maxRetries: 1
54
+ }),
55
+ gtm: O.default({
56
+ idempotencyKey: "__gengageWidgetsInit",
57
+ requireDomReady: !0
58
+ }),
59
+ actionHandling: D.default({
60
+ unknownActionPolicy: "log-and-ignore",
61
+ allowScriptCall: !0
62
+ })
63
+ });
64
+ function L(e) {
65
+ return _.parse(e);
66
+ }
67
+ function B(e) {
68
+ return _.safeParse(e);
69
+ }
70
+ function le(e) {
71
+ return L({
72
+ version: "1",
73
+ accountId: e.accountId,
74
+ middlewareUrl: e.middlewareUrl,
75
+ locale: e.locale,
76
+ widgets: {
77
+ chat: { enabled: !0 },
78
+ qna: { enabled: !0 },
79
+ simrel: { enabled: !0 }
80
+ }
81
+ });
82
+ }
83
+ const T = `${w}_overlay_`, W = "#gengage-qna", $ = "#gengage-simrel";
84
+ function f() {
85
+ const e = window;
86
+ return e.__gengageOverlayRegistry || (e.__gengageOverlayRegistry = {
87
+ instances: {},
88
+ pending: {}
89
+ }), e.__gengageOverlayRegistry;
90
+ }
91
+ function H(e) {
92
+ const t = {
93
+ pageType: e.pageContext?.pageType ?? (e.sku !== void 0 ? "pdp" : "other")
94
+ }, i = e.pageContext;
95
+ return i?.sku !== void 0 && (t.sku = i.sku), 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;
96
+ }
97
+ function z(e, t) {
98
+ const i = {
99
+ ...e,
100
+ ...t,
101
+ pageType: t.pageType ?? e.pageType
102
+ };
103
+ return t.sku === void 0 && e.sku !== void 0 && (i.sku = e.sku), i;
104
+ }
105
+ function y(e) {
106
+ return e instanceof HTMLElement || document.querySelector(e) ? e : null;
107
+ }
108
+ function b(e) {
109
+ return e.idempotencyKey ?? `${T}${e.accountId}`;
110
+ }
111
+ class G {
112
+ constructor(t, i) {
113
+ this.options = t, this.onDestroy = i, this._chat = null, this._qna = null, this._simrel = null, this._destroyed = !1, this._queue = Promise.resolve(), this._warnedQnaMountMissing = !1, this._warnedSimRelMountMissing = !1, this.idempotencyKey = b(t), this.session = I(t.session), this._pageContext = H(t);
114
+ }
115
+ get chat() {
116
+ return this._chat;
117
+ }
118
+ get qna() {
119
+ return this._qna;
120
+ }
121
+ get simrel() {
122
+ return this._simrel;
123
+ }
124
+ async init() {
125
+ window.gengage || (window.gengage = {}), window.gengage.sessionId = this.session.sessionId, window.gengage.pageContext = this._pageContext, await this._initChat(), await this._syncPdpWidgets(), this.options.wireQnaToChat !== !1 && x(), window.gengage.overlay = this;
126
+ }
127
+ openChat(t) {
128
+ this._chat?.open(t);
129
+ }
130
+ closeChat() {
131
+ this._chat?.close();
132
+ }
133
+ async updateContext(t) {
134
+ this._destroyed || await this._enqueue(async () => {
135
+ this._pageContext = z(this._pageContext, t), window.gengage || (window.gengage = {}), window.gengage.pageContext = this._pageContext, this._chat?.update(t), this._qna?.update(t), this._simrel?.update(t), await this._syncPdpWidgets();
136
+ });
137
+ }
138
+ async updateSku(t, i = "pdp") {
139
+ await this.updateContext({ sku: t, pageType: i });
140
+ }
141
+ destroy() {
142
+ this._destroyed || (this._destroyed = !0, 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());
143
+ }
144
+ async _initChat() {
145
+ if (this.options.chat?.enabled === !1) return;
146
+ const t = this.options.middlewareUrl, i = {
147
+ accountId: this.options.accountId,
148
+ middlewareUrl: t,
149
+ session: this.session,
150
+ pageContext: this._pageContext,
151
+ variant: this.options.chat?.variant ?? "floating"
152
+ };
153
+ this.options.theme !== void 0 && (i.theme = this.options.theme), this.options.locale !== void 0 && (i.locale = this.options.locale), this.options.chat?.mountTarget !== void 0 && (i.mountTarget = this.options.chat.mountTarget), this.options.chat?.launcherSvg !== void 0 && (i.launcherSvg = this.options.chat.launcherSvg), this.options.chat?.hideMobileLauncher !== void 0 && (i.hideMobileLauncher = this.options.chat.hideMobileLauncher), this.options.chat?.mobileBreakpoint !== void 0 && (i.mobileBreakpoint = this.options.chat.mobileBreakpoint), this.options.chat?.mobileInitialState !== void 0 && (i.mobileInitialState = this.options.chat.mobileInitialState), this.options.chat?.i18n !== void 0 && (i.i18n = this.options.chat.i18n), this.options.chat?.actionHandling !== void 0 && (i.actionHandling = this.options.chat.actionHandling), this._chat = new S(), await this._chat.init(i);
154
+ }
155
+ async _syncPdpWidgets() {
156
+ if (this._destroyed) return;
157
+ const t = this._pageContext.sku;
158
+ if (!(this._pageContext.pageType === "pdp" && t !== void 0 && t.length > 0)) {
159
+ this._destroyPdpWidgets();
160
+ return;
161
+ }
162
+ const n = this.options.middlewareUrl;
163
+ if (this.options.qna?.enabled !== !1) {
164
+ const a = this.options.qna?.mountTarget ?? W, s = y(a);
165
+ if (s)
166
+ if (this._warnedQnaMountMissing = !1, this._qna)
167
+ this._qna.show(), this._qna.update({ pageType: "pdp", sku: t });
168
+ else {
169
+ const r = new A(), o = {
170
+ accountId: this.options.accountId,
171
+ middlewareUrl: n,
172
+ session: this.session,
173
+ pageContext: {
174
+ pageType: "pdp",
175
+ sku: t
176
+ },
177
+ mountTarget: s
178
+ };
179
+ this.options.theme !== void 0 && (o.theme = this.options.theme), this.options.qna?.ctaText !== void 0 && (o.ctaText = this.options.qna.ctaText), this.options.qna?.inputPlaceholder !== void 0 && (o.inputPlaceholder = this.options.qna.inputPlaceholder), await r.init(o), this._qna = r;
180
+ }
181
+ else
182
+ this._qna?.destroy(), this._qna = null, this._warnedQnaMountMissing || (console.warn(`[gengage] QNA mount target not found: ${a}`), this._warnedQnaMountMissing = !0);
183
+ } else
184
+ this._qna?.destroy(), this._qna = null;
185
+ if (this.options.simrel?.enabled !== !1) {
186
+ const a = this.options.simrel?.mountTarget ?? $, s = y(a);
187
+ if (s)
188
+ if (this._warnedSimRelMountMissing = !1, this._simrel)
189
+ this._simrel.show(), this._simrel.update({ pageType: "pdp", sku: t });
190
+ else {
191
+ const r = new q(), o = {
192
+ accountId: this.options.accountId,
193
+ middlewareUrl: n,
194
+ session: this.session,
195
+ sku: t,
196
+ mountTarget: s
197
+ };
198
+ this.options.theme !== void 0 && (o.theme = this.options.theme), this.options.simrel?.discountType !== void 0 && (o.discountType = this.options.simrel.discountType), this.options.onAddToCart !== void 0 && (o.onAddToCart = this.options.onAddToCart), this.options.onProductNavigate !== void 0 ? o.onProductNavigate = this.options.onProductNavigate : o.onProductNavigate = (h, u, m) => {
199
+ this._chat?.saveSession(m ?? this.session.sessionId, u), window.location.href = h;
200
+ }, await r.init(o), this._simrel = r;
201
+ }
202
+ else
203
+ this._simrel?.destroy(), this._simrel = null, this._warnedSimRelMountMissing || (console.warn(`[gengage] SimRel mount target not found: ${a}`), this._warnedSimRelMountMissing = !0);
204
+ } else
205
+ this._simrel?.destroy(), this._simrel = null;
206
+ }
207
+ _destroyPdpWidgets() {
208
+ this._qna?.destroy(), this._simrel?.destroy(), this._qna = null, this._simrel = null;
209
+ }
210
+ _enqueue(t) {
211
+ const i = this._queue.then(t);
212
+ return this._queue = i.catch(() => {
213
+ }), i;
214
+ }
215
+ }
216
+ async function K(e) {
217
+ const t = b(e), i = f(), n = i.instances[t];
218
+ if (n) return n;
219
+ const a = i.pending[t];
220
+ if (a) return a;
221
+ const s = new G(e, () => {
222
+ const o = f();
223
+ delete o.instances[t], delete o.pending[t];
224
+ }), r = s.init().then(() => (i.instances[t] = s, delete i.pending[t], s)).catch((o) => {
225
+ throw delete i.pending[t], o;
226
+ });
227
+ return i.pending[t] = r, r;
228
+ }
229
+ function Q(e) {
230
+ return f().instances[e] ?? null;
231
+ }
232
+ function ce(e) {
233
+ Q(e)?.destroy();
234
+ }
235
+ function ue(e) {
236
+ return `${T}${e}`;
237
+ }
238
+ const j = {
239
+ enabled: !0,
240
+ endpoint: "/analytics",
241
+ fireAndForget: !0,
242
+ useBeacon: !0,
243
+ keepaliveFetch: !0,
244
+ timeoutMs: 4e3,
245
+ maxRetries: 1,
246
+ batchSize: 10,
247
+ flushIntervalMs: 250
248
+ }, Y = {
249
+ mode: "none",
250
+ key: "",
251
+ headerName: "X-API-Key",
252
+ bodyField: "api_key"
253
+ };
254
+ class V {
255
+ constructor(t) {
256
+ this.queue = [], this.flushTimer = null, this.config = {
257
+ ...j,
258
+ ...t,
259
+ auth: {
260
+ ...Y,
261
+ ...t.auth ?? {}
262
+ }
263
+ }, this.onPageHideBound = () => {
264
+ this.queue.length !== 0 && this.flushAll({ preferBeacon: !0 });
265
+ }, typeof window < "u" && window.addEventListener("pagehide", this.onPageHideBound);
266
+ }
267
+ track(t) {
268
+ if (!this.config.enabled) return;
269
+ const i = J(t);
270
+ if (this.queue.push(i), this.queue.length >= this.config.batchSize) {
271
+ this.scheduleImmediateFlush();
272
+ return;
273
+ }
274
+ this.scheduleFlush();
275
+ }
276
+ async flush(t = {}) {
277
+ if (!this.config.enabled || this.queue.length === 0) return;
278
+ const i = this.queue.splice(0, this.config.batchSize), n = this.buildTransportBody(i), a = X(this.config.endpoint, this.config.middlewareUrl), s = t.preferBeacon ?? this.config.useBeacon;
279
+ await this.sendWithRetry(a, n, s);
280
+ }
281
+ /** Drain the entire queue, flushing in batch-sized chunks. */
282
+ async flushAll(t = {}) {
283
+ for (; this.queue.length > 0; )
284
+ await this.flush(t);
285
+ }
286
+ destroy() {
287
+ this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), typeof window < "u" && window.removeEventListener("pagehide", this.onPageHideBound);
288
+ }
289
+ scheduleFlush() {
290
+ this.flushTimer || (this.flushTimer = setTimeout(() => {
291
+ this.flushTimer = null, this.flush();
292
+ }, this.config.flushIntervalMs));
293
+ }
294
+ scheduleImmediateFlush() {
295
+ this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.flush();
296
+ }
297
+ buildTransportBody(t) {
298
+ const i = { events: t };
299
+ return this.config.auth.mode === "body-api-key" && this.config.auth.key && (i[this.config.auth.bodyField] = this.config.auth.key), i;
300
+ }
301
+ async sendWithRetry(t, i, n) {
302
+ let a = 0;
303
+ for (; a <= this.config.maxRetries; ) {
304
+ a += 1;
305
+ try {
306
+ if (await this.send(t, i, n)) return;
307
+ } catch {
308
+ }
309
+ }
310
+ }
311
+ async send(t, i, n) {
312
+ const a = JSON.stringify(i);
313
+ if (n && this.config.useBeacon && this.config.auth.mode !== "x-api-key-header" && this.config.auth.mode !== "bearer-header" && Z() && navigator.sendBeacon(t, a))
314
+ return !0;
315
+ if (typeof fetch > "u") return !1;
316
+ const r = {
317
+ "Content-Type": "application/json"
318
+ };
319
+ this.config.auth.mode === "x-api-key-header" && this.config.auth.key && (r[this.config.auth.headerName] = this.config.auth.key), this.config.auth.mode === "bearer-header" && this.config.auth.key && (r.Authorization = `Bearer ${this.config.auth.key}`);
320
+ const o = typeof AbortController < "u" ? new AbortController() : null, h = o ? setTimeout(() => o.abort(), this.config.timeoutMs) : null;
321
+ try {
322
+ const u = {
323
+ method: "POST",
324
+ headers: r,
325
+ body: a,
326
+ keepalive: this.config.keepaliveFetch && this.config.fireAndForget
327
+ };
328
+ return o && (u.signal = o.signal), (await fetch(t, u)).ok;
329
+ } finally {
330
+ h && clearTimeout(h);
331
+ }
332
+ }
333
+ }
334
+ function he(e) {
335
+ return new V(e);
336
+ }
337
+ function J(e) {
338
+ const t = {
339
+ event_name: e.event_name,
340
+ event_version: e.event_version ?? "1",
341
+ timestamp_ms: e.timestamp_ms ?? Date.now(),
342
+ account_id: e.account_id,
343
+ session_id: e.session_id,
344
+ correlation_id: e.correlation_id,
345
+ payload: e.payload
346
+ };
347
+ 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;
348
+ }
349
+ function X(e, t) {
350
+ if (/^https?:\/\//i.test(e)) return e;
351
+ const i = E(t), n = e.startsWith("/") ? e : `/${e}`;
352
+ return `${i}${n}`;
353
+ }
354
+ function Z() {
355
+ return typeof navigator < "u" && typeof navigator.sendBeacon == "function";
356
+ }
357
+ const ee = {
358
+ primaryColor: "#000000",
359
+ primaryForeground: "#ffffff",
360
+ backgroundColor: "#ffffff",
361
+ foregroundColor: "#222222",
362
+ borderRadius: "8px",
363
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
364
+ fontSize: "14px",
365
+ zIndex: "1000",
366
+ "--glov-chatbot-width": "420px",
367
+ "--glov-left-spacing": "260px",
368
+ "--chatbot-padding": "16px",
369
+ "--root-wrapper-background-color": "#F2F2F2",
370
+ "--root-wrapper-border-color": "#E5E5E5",
371
+ "--gengage-chat-width": "400px",
372
+ "--gengage-chat-shell-radius": "12px",
373
+ "--gengage-chat-header-height": "60px",
374
+ "--gengage-chat-conversation-width": "396px",
375
+ "--gengage-chat-panel-min-width": "320px",
376
+ "--gengage-chat-panel-max-width": "860px",
377
+ "--gengage-chat-input-height": "48px",
378
+ "--gengage-qna-pill-radius": "999px",
379
+ "--gengage-qna-input-radius": "14px",
380
+ "--gengage-simrel-card-radius": "14px"
381
+ };
382
+ function ge(e) {
383
+ return { ...ee, ...e };
384
+ }
385
+ const C = "tr";
386
+ function fe(e) {
387
+ return {
388
+ ACCOUNT_ID: e.accountId,
389
+ MIDDLEWARE_URL: e.middlewareUrl,
390
+ LOCALE: e.locale ?? C
391
+ };
392
+ }
393
+ function me(e, t = {}) {
394
+ const i = {
395
+ accountId: e.accountId,
396
+ middlewareUrl: e.middlewareUrl,
397
+ session: { sessionId: e.sessionId },
398
+ variant: "floating",
399
+ locale: e.locale ?? C,
400
+ ...t
401
+ };
402
+ return e.theme !== void 0 && (i.theme = e.theme), i;
403
+ }
404
+ function pe(e, t = {}) {
405
+ const i = {
406
+ accountId: e.accountId,
407
+ middlewareUrl: e.middlewareUrl,
408
+ session: { sessionId: e.sessionId },
409
+ pageContext: { pageType: "pdp", sku: e.sku },
410
+ mountTarget: e.mountTarget,
411
+ ...t
412
+ };
413
+ return e.theme !== void 0 && (i.theme = e.theme), i;
414
+ }
415
+ function ye(e, t = {}) {
416
+ const i = {
417
+ accountId: e.accountId,
418
+ middlewareUrl: e.middlewareUrl,
419
+ session: { sessionId: e.sessionId },
420
+ sku: e.sku,
421
+ mountTarget: e.mountTarget,
422
+ ...t
423
+ };
424
+ return e.theme !== void 0 && (i.theme = e.theme), i;
425
+ }
426
+ function ve(e, t = {}) {
427
+ return {
428
+ enabled: !0,
429
+ middlewareUrl: e,
430
+ endpoint: "/analytics",
431
+ fireAndForget: !0,
432
+ useBeacon: !0,
433
+ ...t
434
+ };
435
+ }
436
+ function te(e) {
437
+ try {
438
+ return document.querySelector(e), !0;
439
+ } catch {
440
+ return !1;
441
+ }
442
+ }
443
+ function ie(e) {
444
+ const t = [], i = e.mounts, n = [
445
+ ["qna", i.qna],
446
+ ["simrel", i.simrel],
447
+ ["chat", i.chat]
448
+ ];
449
+ for (const [s, r] of n)
450
+ if (r !== void 0) {
451
+ if (!te(r)) {
452
+ t.push({
453
+ code: "INVALID_SELECTOR",
454
+ message: `[gengage preflight] ${s} mount selector is invalid CSS: "${r}"`,
455
+ severity: "error"
456
+ });
457
+ continue;
458
+ }
459
+ document.querySelector(r) || t.push({
460
+ code: "MOUNT_NOT_FOUND",
461
+ message: `[gengage preflight] ${s} mount target not found: "${r}" — widget will skip or wait for DOM`,
462
+ severity: "warn"
463
+ });
464
+ }
465
+ const a = e.gtm.idempotencyKey;
466
+ window[a] !== void 0 && t.push({
467
+ code: "DUPLICATE_IDEMPOTENCY",
468
+ message: `[gengage preflight] window["${a}"] already exists — widgets may have already initialized`,
469
+ severity: "warn"
470
+ });
471
+ for (const s of t)
472
+ s.severity === "error" ? console.error(s.message) : console.warn(s.message);
473
+ return {
474
+ ok: t.every((s) => s.severity !== "error"),
475
+ warnings: t
476
+ };
477
+ }
478
+ function ne(e) {
479
+ const t = B(e);
480
+ if (!t.success) {
481
+ const i = t.error.issues.map((n) => `${n.path.join(".")}: ${n.message}`).join("; ");
482
+ throw new Error(`[gengage] Invalid runtime config: ${i}`);
483
+ }
484
+ return t.data;
485
+ }
486
+ function se(e, t, i) {
487
+ const n = {
488
+ accountId: e.accountId,
489
+ middlewareUrl: e.middlewareUrl,
490
+ idempotencyKey: e.gtm.idempotencyKey
491
+ };
492
+ return e.locale !== void 0 && (n.locale = e.locale), i !== void 0 && (n.pageContext = i, i.sku !== void 0 && (n.sku = i.sku)), n.chat = {
493
+ enabled: e.widgets.chat.enabled
494
+ }, e.mounts.chat !== void 0 && (n.chat.mountTarget = e.mounts.chat), n.qna = {
495
+ enabled: e.widgets.qna.enabled
496
+ }, e.mounts.qna !== void 0 && (n.qna.mountTarget = e.mounts.qna), n.simrel = {
497
+ enabled: e.widgets.simrel.enabled
498
+ }, 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), n;
499
+ }
500
+ async function we(e) {
501
+ const t = ne(e.runtimeConfig);
502
+ if (e.preflight !== !1) {
503
+ const s = ie(t);
504
+ if (!s.ok) {
505
+ const r = s.warnings.filter((o) => o.severity === "error");
506
+ throw new Error(`[gengage] Preflight failed: ${r.map((o) => o.message).join("; ")}`);
507
+ }
508
+ }
509
+ const i = e.contextResolver?.(), n = se(t, e.hostActions, i), a = await K(n);
510
+ if (e.contextResolver !== void 0) {
511
+ const s = e.contextResolver;
512
+ window.addEventListener("gengage:context:update", () => {
513
+ const r = s();
514
+ a.updateContext(r);
515
+ });
516
+ }
517
+ return a;
518
+ }
519
+ export {
520
+ _ as AccountRuntimeConfigSchema,
521
+ R as AnalyticsAuthModeSchema,
522
+ V as AnalyticsClient,
523
+ ee as BASE_WIDGET_THEME,
524
+ be as BaseWidget,
525
+ C as DEFAULT_CUSTOMIZATION_LOCALE,
526
+ Ce as DEFAULT_WIDGET_THEME_TOKENS,
527
+ N as UnknownActionPolicySchema,
528
+ ke as adaptV1Event,
529
+ Ie as basketAddEvent,
530
+ xe as bootstrapSession,
531
+ Ee as buildChatEndpointUrl,
532
+ ue as buildOverlayIdempotencyKey,
533
+ Se as chatHistorySnapshotEvent,
534
+ Ae as checkoutCompleteEvent,
535
+ qe as checkoutStartEvent,
536
+ Ue as consumeStream,
537
+ fe as createAccountIdentity,
538
+ he as createAnalyticsClient,
539
+ le as createDefaultAccountRuntimeConfig,
540
+ ve as createDefaultAnalyticsConfig,
541
+ me as createFloatingChatConfig,
542
+ pe as createPdpQnaConfig,
543
+ ye as createPdpSimRelConfig,
544
+ Me as defaultUnknownUISpecRenderer,
545
+ ce as destroyOverlayWidgets,
546
+ Re as dismissGlobalErrorToast,
547
+ Pe as dispatch,
548
+ Fe as getGlobalErrorMessage,
549
+ Q as getOverlayWidgets,
550
+ Oe as getWindowPageContext,
551
+ we as initGengageClient,
552
+ K as initOverlayWidgets,
553
+ Ne as listen,
554
+ De as llmUsageEvent,
555
+ Le as mergeUISpecRegistry,
556
+ Be as meteringIncrementEvent,
557
+ We as meteringSummaryEvent,
558
+ E as normalizeMiddlewareUrl,
559
+ $e as normalizeProductGroupingsResponse,
560
+ He as normalizeSimilarProductsResponse,
561
+ L as parseAccountRuntimeConfig,
562
+ ie as preflightDiagnostics,
563
+ ze as productToNormalized,
564
+ Ge as registerGlobalErrorToastListener,
565
+ Ke as renderUISpecWithRegistry,
566
+ I as resolveSession,
567
+ ot as routeStreamAction,
568
+ B as safeParseAccountRuntimeConfig,
569
+ at as sanitizeHtml,
570
+ Qe as showGlobalErrorToast,
571
+ je as streamChunkEvent,
572
+ Ye as streamDoneEvent,
573
+ Ve as streamErrorEvent,
574
+ Je as streamPost,
575
+ Xe as streamStartEvent,
576
+ Ze as streamUiSpecEvent,
577
+ et as updatePageContext,
578
+ tt as widgetHistorySnapshotEvent,
579
+ x as wireQNAToChat,
580
+ it as wireSimilarToChat,
581
+ ge as withBaseTheme,
582
+ nt as withDefaultWidgetTheme
583
+ };
584
+ //# sourceMappingURL=common.js.map