@gengage/assistant-fe 0.4.4 → 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 (50) 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/types.d.ts +1 -1
  6. package/dist/chat-BRKK63lt.js +303 -0
  7. package/dist/chat-runtime.js +13 -0
  8. package/dist/chat.iife.js +7 -7
  9. package/dist/chat.js +11 -10
  10. package/dist/common/config-constants.d.ts +1 -0
  11. package/dist/common/config-schema.d.ts +0 -1
  12. package/dist/common/overlay.d.ts +4 -4
  13. package/dist/common-CEN5OW7E.js +491 -0
  14. package/dist/common.js +78 -76
  15. package/dist/{connection-warning-n88bjkqL.js → connection-warning-B6oIU-9s.js} +1 -1
  16. package/dist/context-VIG4SVcS.js +529 -0
  17. package/dist/index.js +70 -67
  18. package/dist/locale-CfqNifrU.js +7 -0
  19. package/dist/native-webview-DudQ7nHe.js +273 -0
  20. package/dist/native.iife.js +28 -91
  21. package/dist/native.js +1 -1
  22. package/dist/overlay-1EO41ZC7.js +212 -0
  23. package/dist/overlay.d.ts +4 -0
  24. package/dist/overlay.js +10 -0
  25. package/dist/pill-launcher-57nrdLRr.js +364 -0
  26. package/dist/qna/index.d.ts +1 -61
  27. package/dist/qna/runtime.d.ts +61 -0
  28. package/dist/qna-BNvttR6s.js +40 -0
  29. package/dist/qna-runtime.js +8 -0
  30. package/dist/qna.iife.js +4 -4
  31. package/dist/qna.js +6 -5
  32. package/dist/{simrel-K2TGFi1r.js → runtime-BdwZZIrO.js} +244 -293
  33. package/dist/{chat-DI7Vm0gh.js → runtime-C0qZk0y7.js} +1644 -2298
  34. package/dist/{qna-C5Ok3wd0.js → runtime-DDu8Wk0z.js} +87 -121
  35. package/dist/schemas-CLo8wCjs.js +3207 -0
  36. package/dist/{simbut-Cb5RfaAp.js → simbut-BMWC6x_t.js} +24 -22
  37. package/dist/simbut.js +1 -1
  38. package/dist/simrel/index.d.ts +1 -59
  39. package/dist/simrel/runtime.d.ts +59 -0
  40. package/dist/simrel-ohfkluhp.js +55 -0
  41. package/dist/simrel-runtime.js +8 -0
  42. package/dist/simrel.iife.js +4 -4
  43. package/dist/simrel.js +7 -6
  44. package/dist/widget-base-TgwiA8cD.js +578 -0
  45. package/package.json +17 -1
  46. package/dist/common-BxSi3UWt.js +0 -387
  47. package/dist/locale-MM0U5eeR.js +0 -1109
  48. package/dist/native-webview-DFqnyus6.js +0 -586
  49. package/dist/schemas-JpRGzRQT.js +0 -4419
  50. /package/dist/{price-formatter-CR6VT5z4.js → price-formatter-xI3g9Cd4.js} +0 -0
@@ -1,387 +0,0 @@
1
- import { f as u } from "./schemas-JpRGzRQT.js";
2
- import { h, l as f } from "./native-webview-DFqnyus6.js";
3
- var m = {
4
- enabled: !0,
5
- endpoint: "/analytics",
6
- fireAndForget: !0,
7
- useBeacon: !0,
8
- keepaliveFetch: !0,
9
- timeoutMs: 4e3,
10
- maxRetries: 0,
11
- batchSize: 10,
12
- flushIntervalMs: 250
13
- }, g = {
14
- mode: "none",
15
- key: "",
16
- headerName: "X-API-Key",
17
- bodyField: "api_key"
18
- }, y = class {
19
- constructor(e) {
20
- this.queue = [], this.flushTimer = null, this.config = {
21
- ...m,
22
- ...e,
23
- auth: {
24
- ...g,
25
- ...e.auth ?? {}
26
- }
27
- }, this.onPageHideBound = () => {
28
- this.queue.length !== 0 && this.flushAllSync();
29
- }, typeof window < "u" && window.addEventListener("pagehide", this.onPageHideBound);
30
- }
31
- track(e) {
32
- if (!this.config.enabled) return;
33
- const t = p(e);
34
- if (this.queue.push(t), this.queue.length >= this.config.batchSize) {
35
- this.scheduleImmediateFlush();
36
- return;
37
- }
38
- this.scheduleFlush();
39
- }
40
- flush() {
41
- if (!this.config.enabled || this.queue.length === 0) return;
42
- const e = this.queue.splice(0, this.config.batchSize), t = this.buildTransportBody(e), i = l(this.config.endpoint, this.config.middlewareUrl);
43
- this.send(i, t);
44
- }
45
- flushAll() {
46
- for (; this.queue.length > 0; ) this.flush();
47
- }
48
- destroy() {
49
- this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.queue.length > 0 && this.flushAllSync(), typeof window < "u" && window.removeEventListener("pagehide", this.onPageHideBound);
50
- }
51
- scheduleFlush() {
52
- this.flushTimer || (this.flushTimer = setTimeout(() => {
53
- this.flushTimer = null, this.flush();
54
- }, this.config.flushIntervalMs));
55
- }
56
- scheduleImmediateFlush() {
57
- this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.flush();
58
- }
59
- buildTransportBody(e) {
60
- const t = { events: e };
61
- return this.config.auth.mode === "body-api-key" && this.config.auth.key && (t[this.config.auth.bodyField] = this.config.auth.key), t;
62
- }
63
- send(e, t) {
64
- try {
65
- const i = JSON.stringify(t);
66
- if (this.config.useBeacon && this.config.auth.mode !== "x-api-key-header" && this.config.auth.mode !== "bearer-header" && c()) {
67
- const o = new Blob([i], { type: "application/json" });
68
- navigator.sendBeacon(e, o);
69
- return;
70
- }
71
- if (typeof fetch > "u") return;
72
- const n = { "Content-Type": "application/json" };
73
- this.config.auth.mode === "x-api-key-header" && this.config.auth.key && (n[this.config.auth.headerName] = this.config.auth.key), this.config.auth.mode === "bearer-header" && this.config.auth.key && (n.Authorization = `Bearer ${this.config.auth.key}`), fetch(e, {
74
- method: "POST",
75
- headers: n,
76
- body: i,
77
- keepalive: !0
78
- }).catch(() => {
79
- });
80
- } catch {
81
- }
82
- }
83
- flushAllSync() {
84
- if (!this.config.enabled) return;
85
- const e = l(this.config.endpoint, this.config.middlewareUrl);
86
- for (; this.queue.length > 0; ) {
87
- const t = this.queue.splice(0, this.config.batchSize), i = this.buildTransportBody(t);
88
- try {
89
- const n = JSON.stringify(i);
90
- if (c()) {
91
- const o = new Blob([n], { type: "application/json" });
92
- navigator.sendBeacon(e, o);
93
- }
94
- } catch {
95
- }
96
- }
97
- }
98
- };
99
- function U(e) {
100
- return new y(e);
101
- }
102
- function p(e) {
103
- const t = {
104
- event_name: e.event_name,
105
- event_version: e.event_version ?? "1",
106
- timestamp_ms: e.timestamp_ms ?? Date.now(),
107
- account_id: e.account_id,
108
- session_id: e.session_id,
109
- correlation_id: e.correlation_id,
110
- payload: e.payload
111
- };
112
- 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;
113
- }
114
- function l(e, t) {
115
- return /^https?:\/\//i.test(e) ? e : `${u(t)}${e.startsWith("/") ? e : `/${e}`}`;
116
- }
117
- function c() {
118
- return typeof navigator < "u" && typeof navigator.sendBeacon == "function";
119
- }
120
- var E = "tr";
121
- function A(e) {
122
- return {
123
- ACCOUNT_ID: e.accountId,
124
- MIDDLEWARE_URL: e.middlewareUrl,
125
- LOCALE: e.locale ?? "tr"
126
- };
127
- }
128
- function P(e, t = {}) {
129
- const i = {
130
- accountId: e.accountId,
131
- middlewareUrl: e.middlewareUrl,
132
- session: { sessionId: e.sessionId },
133
- variant: "floating",
134
- locale: e.locale ?? "tr",
135
- ...t
136
- };
137
- return e.theme !== void 0 && (i.theme = e.theme), i;
138
- }
139
- function L(e, t = {}) {
140
- const i = {
141
- accountId: e.accountId,
142
- middlewareUrl: e.middlewareUrl,
143
- session: { sessionId: e.sessionId },
144
- pageContext: {
145
- pageType: "pdp",
146
- sku: e.sku
147
- },
148
- mountTarget: e.mountTarget,
149
- ...t
150
- };
151
- return e.theme !== void 0 && (i.theme = e.theme), i;
152
- }
153
- function q(e, t = {}) {
154
- const i = {
155
- accountId: e.accountId,
156
- middlewareUrl: e.middlewareUrl,
157
- session: { sessionId: e.sessionId },
158
- sku: e.sku,
159
- mountTarget: e.mountTarget,
160
- ...t
161
- };
162
- return e.theme !== void 0 && (i.theme = e.theme), i;
163
- }
164
- function O(e, t = {}) {
165
- return {
166
- enabled: !0,
167
- middlewareUrl: e,
168
- endpoint: "/analytics",
169
- fireAndForget: !0,
170
- useBeacon: !0,
171
- ...t
172
- };
173
- }
174
- function w(e) {
175
- try {
176
- return document.querySelector(e), !0;
177
- } catch {
178
- return !1;
179
- }
180
- }
181
- function v(e, t) {
182
- const i = [], n = e.mounts, o = [
183
- ["qna", n.qna],
184
- ["simrel", n.simrel],
185
- ["simbut", n.simbut],
186
- ["chat", n.chat]
187
- ];
188
- for (const [s, a] of o)
189
- if (a !== void 0) {
190
- if (s === "simrel" && e.widgets.simrel === void 0) {
191
- i.push({
192
- code: "SIMREL_MOUNT_IGNORED",
193
- message: "[gengage preflight] mounts.simrel is set but widgets.simrel is not declared — SimRel will not initialize. Add widgets.simrel: { enabled: true } to enable it.",
194
- severity: "warn"
195
- });
196
- continue;
197
- }
198
- if (!w(a)) {
199
- i.push({
200
- code: "INVALID_SELECTOR",
201
- message: `[gengage preflight] ${s} mount selector is invalid CSS: "${a}"`,
202
- severity: "error"
203
- });
204
- continue;
205
- }
206
- document.querySelector(a) || i.push({
207
- code: "MOUNT_NOT_FOUND",
208
- message: `[gengage preflight] ${s} mount target not found: "${a}" — widget will skip or wait for DOM`,
209
- severity: "warn"
210
- });
211
- }
212
- if (e.widgets.simbut.enabled && n.simbut === void 0) {
213
- const s = "#gengage-simbut";
214
- document.querySelector(s) || i.push({
215
- code: "SIMBUT_MOUNT_REQUIRED",
216
- message: `[gengage preflight] SimBut is enabled but no mount target is configured. Set mounts.simbut to your product image wrapper selector (e.g. "#product-gallery"). The default "${s}" was not found in the DOM.`,
217
- severity: "error"
218
- });
219
- }
220
- const r = e.gtm.idempotencyKey;
221
- if (window[r] !== void 0 && i.push({
222
- code: "DUPLICATE_IDEMPOTENCY",
223
- message: `[gengage preflight] window["${r}"] already exists — widgets may have already initialized`,
224
- severity: "warn"
225
- }), !t?.skipCspCheck) {
226
- let s = !1;
227
- const a = (d) => {
228
- d.blockedURI && e.middlewareUrl.startsWith(d.blockedURI) && (s = !0);
229
- };
230
- document.addEventListener("securitypolicyviolation", a);
231
- try {
232
- fetch(e.middlewareUrl, {
233
- method: "HEAD",
234
- mode: "no-cors"
235
- }).catch(() => {
236
- });
237
- } catch {
238
- s = !0;
239
- }
240
- document.removeEventListener("securitypolicyviolation", a), s && i.push({
241
- code: "CSP_BLOCKED",
242
- message: `[gengage preflight] middleware URL may be blocked by Content-Security-Policy: "${e.middlewareUrl}". Add it to connect-src.`,
243
- severity: "warn"
244
- });
245
- }
246
- for (const s of i) s.severity === "error" ? console.error(s.message) : console.warn(s.message);
247
- return {
248
- ok: i.every((s) => s.severity !== "error"),
249
- warnings: i
250
- };
251
- }
252
- function b(e) {
253
- const t = h(e);
254
- if (!t.success) {
255
- const i = t.error.issues.map((n) => `${n.path.join(".")}: ${n.message}`).join("; ");
256
- throw new Error(`[gengage] Invalid runtime config: ${i}`);
257
- }
258
- return t.data;
259
- }
260
- function T(e, t, i) {
261
- const n = {
262
- accountId: e.accountId,
263
- middlewareUrl: e.middlewareUrl,
264
- idempotencyKey: e.gtm.idempotencyKey
265
- };
266
- 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 = { enabled: e.widgets.chat.enabled }, e.mounts.chat !== void 0 && (n.chat.mountTarget = e.mounts.chat), n.qna = { enabled: e.widgets.qna.enabled }, e.mounts.qna !== void 0 && (n.qna.mountTarget = e.mounts.qna), e.widgets.simrel !== void 0 && (n.simrel = {
267
- enabled: e.widgets.simrel.enabled,
268
- ...e.mounts.simrel !== void 0 ? { mountTarget: e.mounts.simrel } : {}
269
- }), n.simbut = { enabled: e.widgets.simbut.enabled }, e.mounts.simbut !== void 0 && (n.simbut.mountTarget = e.mounts.simbut), t?.onAddToCart !== void 0 && (n.onAddToCart = t.onAddToCart), t?.onProductNavigate !== void 0 && (n.onProductNavigate = t.onProductNavigate), t?.onFindSimilar !== void 0 && (n.simbut.onFindSimilar = t.onFindSimilar), t?.onScriptCall !== void 0 && (n.onScriptCall = t.onScriptCall), n;
270
- }
271
- async function R(e) {
272
- const t = b(e.runtimeConfig);
273
- if (e.preflight !== !1) {
274
- const o = v(t);
275
- if (!o.ok) {
276
- const r = o.warnings.filter((s) => s.severity === "error");
277
- throw new Error(`[gengage] Preflight failed: ${r.map((s) => s.message).join("; ")}`);
278
- }
279
- }
280
- const i = e.contextResolver?.(), n = await f(T(t, e.hostActions, i));
281
- if (e.contextResolver !== void 0) {
282
- const o = e.contextResolver, r = () => {
283
- const a = o();
284
- n.updateContext(a);
285
- };
286
- window.addEventListener("gengage:context:update", r);
287
- const s = n.destroy.bind(n);
288
- n.destroy = () => {
289
- window.removeEventListener("gengage:context:update", r), s();
290
- };
291
- }
292
- return n;
293
- }
294
- var k = [
295
- {
296
- pageType: "home",
297
- urlPatterns: [
298
- "^/$",
299
- "^/index\\.html?$",
300
- "^/anasayfa$"
301
- ]
302
- },
303
- {
304
- pageType: "search",
305
- urlPatterns: [
306
- "/arama",
307
- "/search",
308
- "/ara\\?"
309
- ],
310
- queryParam: "q"
311
- },
312
- {
313
- pageType: "cart",
314
- urlPatterns: [
315
- "/sepet",
316
- "/cart",
317
- "/basket",
318
- "/sepetim"
319
- ]
320
- },
321
- {
322
- pageType: "plp",
323
- urlPatterns: [
324
- "/kategori/",
325
- "/category/",
326
- "/c/",
327
- "/koleksiyon/",
328
- "/collection/"
329
- ]
330
- },
331
- {
332
- pageType: "pdp",
333
- urlPatterns: [
334
- "/urun/",
335
- "/product/",
336
- "/p/",
337
- "/-p-",
338
- "/-pm-"
339
- ]
340
- }
341
- ];
342
- function I(e, t) {
343
- const i = t ?? (typeof window < "u" ? new URL(window.location.href) : null);
344
- if (!i) return "other";
345
- const n = e ?? k, o = i.pathname;
346
- for (const r of n)
347
- if (!(r.urlPatterns && !r.urlPatterns.some((s) => {
348
- try {
349
- return new RegExp(s, "i").test(o);
350
- } catch {
351
- return !1;
352
- }
353
- })) && !(r.queryParam && !i.searchParams.has(r.queryParam)) && !(r.selector && typeof document < "u" && !document.querySelector(r.selector)))
354
- return r.pageType;
355
- return "other";
356
- }
357
- function S(e) {
358
- const t = e ?? (typeof window < "u" ? new URL(window.location.href) : null);
359
- if (!t) return;
360
- const i = t.pathname, n = i.match(/\/(?:p|urun|product)\/([^/?#]+)/i);
361
- if (n?.[1]) return n[1];
362
- const o = i.match(/-p-(\d+)/i);
363
- if (o?.[1]) return o[1];
364
- }
365
- function D(e) {
366
- const t = I(e), i = { pageType: t };
367
- if (t === "pdp") {
368
- const n = S();
369
- n && (i.sku = n);
370
- }
371
- return typeof window < "u" && (i.url = window.location.href), i;
372
- }
373
- export {
374
- v as a,
375
- O as c,
376
- q as d,
377
- y as f,
378
- R as i,
379
- P as l,
380
- I as n,
381
- E as o,
382
- U as p,
383
- S as r,
384
- A as s,
385
- D as t,
386
- L as u
387
- };