@gengage/assistant-fe 0.4.21 → 0.5.1

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 (34) hide show
  1. package/README.md +1 -1
  2. package/dist/{api-paths-Bg6iwO5w.js → api-paths-XNsAaP_N.js} +1 -1
  3. package/dist/chat-runtime.js +1 -1
  4. package/dist/chat.iife.js +43 -43
  5. package/dist/chat.js +1 -1
  6. package/dist/common-Cb5WKXue.js +324 -0
  7. package/dist/common.js +64 -81
  8. package/dist/{connection-warning-BeD-B0Ec.js → connection-warning-BjfQKyV7.js} +1 -1
  9. package/dist/{fastIntent-BeeDIwd2.js → fastIntent-DxSSvrgK.js} +2 -2
  10. package/dist/index.js +49 -52
  11. package/dist/{native-webview-Bbcvvi_5.js → native-webview-BQPhKMli.js} +1 -1
  12. package/dist/native.iife.js +23 -23
  13. package/dist/native.js +1 -1
  14. package/dist/{overlay-O4nlUrzw.js → overlay-C0NSAZoL.js} +3 -6
  15. package/dist/overlay.js +2 -2
  16. package/dist/qna-runtime.js +1 -1
  17. package/dist/qna.iife.js +36 -36
  18. package/dist/qna.js +1 -1
  19. package/dist/{runtime-C8ZBidd2.js → runtime-B8Y5j1Xu.js} +176 -196
  20. package/dist/runtime-Bso-rbzX.js +654 -0
  21. package/dist/{runtime-Ct1qOl8V.js → runtime-CatBpqEd.js} +2194 -2225
  22. package/dist/{simbut-BrAeZ6SH.js → simbut-D2WpS0Y8.js} +7 -7
  23. package/dist/simbut.iife.js +12 -12
  24. package/dist/simbut.js +1 -1
  25. package/dist/{simrel-Cha5de6P.js → simrel-CNfVfah6.js} +2 -2
  26. package/dist/simrel-runtime.js +1 -1
  27. package/dist/simrel.iife.js +35 -35
  28. package/dist/simrel.js +2 -2
  29. package/dist/widget-base-CcNNPfdn.js +362 -0
  30. package/package.json +1 -2
  31. package/dist/common-DDJSeQhg.js +0 -491
  32. package/dist/runtime-CRSFPLku.js +0 -688
  33. package/dist/widget-base-BtBl_PCR.js +0 -589
  34. /package/dist/{context-DGz5F81j.js → context-BBuSsXZ9.js} +0 -0
@@ -1,491 +0,0 @@
1
- import { n as w } from "./api-paths-Bg6iwO5w.js";
2
- import { i as f } from "./widget-base-BtBl_PCR.js";
3
- import { a as h, c as s, i as b, o as d, r as u, t as p } from "./schemas-CLo8wCjs.js";
4
- import { a as T, i as k } from "./overlay-O4nlUrzw.js";
5
- var c = d({ enabled: u().default(!0) }), S = d({
6
- chat: s().optional(),
7
- qna: s().optional(),
8
- simrel: s().optional(),
9
- simbut: s().optional()
10
- }), I = d({}), U = p([
11
- "none",
12
- "x-api-key-header",
13
- "bearer-header",
14
- "body-api-key"
15
- ]), _ = d({
16
- mode: U.default("none"),
17
- key: s().optional(),
18
- headerName: s().optional(),
19
- bodyField: s().default("api_key")
20
- }), A = d({
21
- enabled: u().default(!0),
22
- endpoint: s().default("/analytics"),
23
- auth: _.default({
24
- mode: "none",
25
- bodyField: "api_key"
26
- }),
27
- fireAndForget: u().default(!0),
28
- useBeacon: u().default(!0),
29
- keepaliveFetch: u().default(!0),
30
- timeoutMs: h().int().positive().default(4e3),
31
- maxRetries: h().int().min(0).max(5).default(1)
32
- }), C = d({
33
- idempotencyKey: s().default(T),
34
- requireDomReady: u().default(!0)
35
- }), E = p([
36
- "log-and-ignore",
37
- "throw",
38
- "delegate"
39
- ]), P = d({
40
- unknownActionPolicy: E.default("log-and-ignore"),
41
- allowScriptCall: u().default(!1)
42
- }), v = d({
43
- version: b("1", { error: 'version must be "1"' }),
44
- accountId: s({ error: "accountId must be a non-empty string" }).min(1, { error: "accountId must be a non-empty string" }),
45
- middlewareUrl: s({ 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")' }),
46
- locale: s().optional(),
47
- widgets: d({
48
- chat: c.default({ enabled: !0 }),
49
- qna: c.default({ enabled: !0 }),
50
- simrel: c.optional(),
51
- simbut: c.default({ enabled: !1 })
52
- }),
53
- mounts: S.default({}),
54
- transport: I.default({}),
55
- analytics: A.default({
56
- enabled: !0,
57
- endpoint: "/analytics",
58
- auth: {
59
- mode: "none",
60
- bodyField: "api_key"
61
- },
62
- fireAndForget: !0,
63
- useBeacon: !0,
64
- keepaliveFetch: !0,
65
- timeoutMs: 4e3,
66
- maxRetries: 1
67
- }),
68
- gtm: C.default({
69
- idempotencyKey: "__gengageWidgetsInit",
70
- requireDomReady: !0
71
- }),
72
- actionHandling: P.default({
73
- unknownActionPolicy: "log-and-ignore",
74
- allowScriptCall: !1
75
- })
76
- });
77
- function R(e) {
78
- f("config", "parsing account runtime config", e);
79
- const t = v.parse(e);
80
- return f("config", "config resolved", {
81
- accountId: t.accountId,
82
- middlewareUrl: t.middlewareUrl
83
- }), t;
84
- }
85
- function L(e) {
86
- return v.safeParse(e);
87
- }
88
- function Y(e) {
89
- return R({
90
- version: "1",
91
- accountId: e.accountId,
92
- middlewareUrl: e.middlewareUrl,
93
- locale: e.locale,
94
- widgets: {
95
- chat: { enabled: !0 },
96
- qna: { enabled: !0 },
97
- simbut: { enabled: !1 }
98
- }
99
- });
100
- }
101
- var q = {
102
- enabled: !0,
103
- endpoint: "/analytics",
104
- fireAndForget: !0,
105
- useBeacon: !0,
106
- keepaliveFetch: !0,
107
- timeoutMs: 4e3,
108
- maxRetries: 0,
109
- batchSize: 10,
110
- flushIntervalMs: 250
111
- }, F = {
112
- mode: "none",
113
- key: "",
114
- headerName: "X-API-Key",
115
- bodyField: "api_key"
116
- }, D = class {
117
- constructor(e) {
118
- this.queue = [], this.flushTimer = null, this.config = {
119
- ...q,
120
- ...e,
121
- auth: {
122
- ...F,
123
- ...e.auth ?? {}
124
- }
125
- }, this.onPageHideBound = () => {
126
- this.queue.length !== 0 && this.flushAllSync();
127
- }, typeof window < "u" && window.addEventListener("pagehide", this.onPageHideBound);
128
- }
129
- track(e) {
130
- if (!this.config.enabled) return;
131
- const t = O(e);
132
- if (this.queue.push(t), this.queue.length >= this.config.batchSize) {
133
- this.scheduleImmediateFlush();
134
- return;
135
- }
136
- this.scheduleFlush();
137
- }
138
- flush() {
139
- if (!this.config.enabled || this.queue.length === 0) return;
140
- const e = this.queue.splice(0, this.config.batchSize), t = this.buildTransportBody(e), n = g(this.config.endpoint, this.config.middlewareUrl);
141
- this.send(n, t);
142
- }
143
- flushAll() {
144
- for (; this.queue.length > 0; ) this.flush();
145
- }
146
- destroy() {
147
- this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.queue.length > 0 && this.flushAllSync(), typeof window < "u" && window.removeEventListener("pagehide", this.onPageHideBound);
148
- }
149
- scheduleFlush() {
150
- this.flushTimer || (this.flushTimer = setTimeout(() => {
151
- this.flushTimer = null, this.flush();
152
- }, this.config.flushIntervalMs));
153
- }
154
- scheduleImmediateFlush() {
155
- this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.flush();
156
- }
157
- buildTransportBody(e) {
158
- const t = { events: e };
159
- return this.config.auth.mode === "body-api-key" && this.config.auth.key && (t[this.config.auth.bodyField] = this.config.auth.key), t;
160
- }
161
- send(e, t) {
162
- try {
163
- const n = JSON.stringify(t);
164
- if (this.config.useBeacon && this.config.auth.mode !== "x-api-key-header" && this.config.auth.mode !== "bearer-header" && y()) {
165
- const o = new Blob([n], { type: "application/json" });
166
- navigator.sendBeacon(e, o);
167
- return;
168
- }
169
- if (typeof fetch > "u") return;
170
- const i = { "Content-Type": "application/json" };
171
- 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(e, {
172
- method: "POST",
173
- headers: i,
174
- body: n,
175
- keepalive: !0
176
- }).catch(() => {
177
- });
178
- } catch {
179
- }
180
- }
181
- flushAllSync() {
182
- if (!this.config.enabled) return;
183
- const e = g(this.config.endpoint, this.config.middlewareUrl);
184
- for (; this.queue.length > 0; ) {
185
- const t = this.queue.splice(0, this.config.batchSize), n = this.buildTransportBody(t);
186
- try {
187
- const i = JSON.stringify(n);
188
- if (y()) {
189
- const o = new Blob([i], { type: "application/json" });
190
- navigator.sendBeacon(e, o);
191
- }
192
- } catch {
193
- }
194
- }
195
- }
196
- };
197
- function J(e) {
198
- return new D(e);
199
- }
200
- function O(e) {
201
- const t = {
202
- event_name: e.event_name,
203
- event_version: e.event_version ?? "1",
204
- timestamp_ms: e.timestamp_ms ?? Date.now(),
205
- account_id: e.account_id,
206
- session_id: e.session_id,
207
- correlation_id: e.correlation_id,
208
- payload: e.payload
209
- };
210
- 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;
211
- }
212
- function g(e, t) {
213
- return /^https?:\/\//i.test(e) ? e : `${w(t)}${e.startsWith("/") ? e : `/${e}`}`;
214
- }
215
- function y() {
216
- return typeof navigator < "u" && typeof navigator.sendBeacon == "function";
217
- }
218
- var Q = "tr";
219
- function V(e) {
220
- return {
221
- ACCOUNT_ID: e.accountId,
222
- MIDDLEWARE_URL: e.middlewareUrl,
223
- LOCALE: e.locale ?? "tr"
224
- };
225
- }
226
- function X(e, t = {}) {
227
- const n = {
228
- accountId: e.accountId,
229
- middlewareUrl: e.middlewareUrl,
230
- session: { sessionId: e.sessionId },
231
- variant: "floating",
232
- locale: e.locale ?? "tr",
233
- ...t
234
- };
235
- return e.theme !== void 0 && (n.theme = e.theme), n;
236
- }
237
- function Z(e, t = {}) {
238
- const n = {
239
- accountId: e.accountId,
240
- middlewareUrl: e.middlewareUrl,
241
- session: { sessionId: e.sessionId },
242
- pageContext: {
243
- pageType: "pdp",
244
- sku: e.sku
245
- },
246
- mountTarget: e.mountTarget,
247
- ...t
248
- };
249
- return e.theme !== void 0 && (n.theme = e.theme), n;
250
- }
251
- function ee(e, t = {}) {
252
- const n = {
253
- accountId: e.accountId,
254
- middlewareUrl: e.middlewareUrl,
255
- session: { sessionId: e.sessionId },
256
- sku: e.sku,
257
- mountTarget: e.mountTarget,
258
- ...t
259
- };
260
- return e.theme !== void 0 && (n.theme = e.theme), n;
261
- }
262
- function te(e, t = {}) {
263
- return {
264
- enabled: !0,
265
- middlewareUrl: e,
266
- endpoint: "/analytics",
267
- fireAndForget: !0,
268
- useBeacon: !0,
269
- ...t
270
- };
271
- }
272
- function x(e) {
273
- try {
274
- return document.querySelector(e), !0;
275
- } catch {
276
- return !1;
277
- }
278
- }
279
- function B(e, t) {
280
- const n = [], i = e.mounts, o = [
281
- ["qna", i.qna],
282
- ["simrel", i.simrel],
283
- ["simbut", i.simbut],
284
- ["chat", i.chat]
285
- ];
286
- for (const [a, l] of o)
287
- if (l !== void 0) {
288
- if (a === "simrel" && e.widgets.simrel === void 0) {
289
- n.push({
290
- code: "SIMREL_MOUNT_IGNORED",
291
- 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.",
292
- severity: "warn"
293
- });
294
- continue;
295
- }
296
- if (!x(l)) {
297
- n.push({
298
- code: "INVALID_SELECTOR",
299
- message: `[gengage preflight] ${a} mount selector is invalid CSS: "${l}"`,
300
- severity: "error"
301
- });
302
- continue;
303
- }
304
- document.querySelector(l) || n.push({
305
- code: "MOUNT_NOT_FOUND",
306
- message: `[gengage preflight] ${a} mount target not found: "${l}" — widget will skip or wait for DOM`,
307
- severity: "warn"
308
- });
309
- }
310
- if (e.widgets.simbut.enabled && i.simbut === void 0) {
311
- const a = "#gengage-simbut";
312
- document.querySelector(a) || n.push({
313
- code: "SIMBUT_MOUNT_REQUIRED",
314
- 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 "${a}" was not found in the DOM.`,
315
- severity: "error"
316
- });
317
- }
318
- const r = e.gtm.idempotencyKey;
319
- if (window[r] !== void 0 && n.push({
320
- code: "DUPLICATE_IDEMPOTENCY",
321
- message: `[gengage preflight] window["${r}"] already exists — widgets may have already initialized`,
322
- severity: "warn"
323
- }), !t?.skipCspCheck) {
324
- let a = !1;
325
- const l = (m) => {
326
- m.blockedURI && e.middlewareUrl.startsWith(m.blockedURI) && (a = !0);
327
- };
328
- document.addEventListener("securitypolicyviolation", l);
329
- try {
330
- fetch(e.middlewareUrl, {
331
- method: "HEAD",
332
- mode: "no-cors"
333
- }).catch(() => {
334
- });
335
- } catch {
336
- a = !0;
337
- }
338
- document.removeEventListener("securitypolicyviolation", l), a && n.push({
339
- code: "CSP_BLOCKED",
340
- message: `[gengage preflight] middleware URL may be blocked by Content-Security-Policy: "${e.middlewareUrl}". Add it to connect-src.`,
341
- severity: "warn"
342
- });
343
- }
344
- for (const a of n) a.severity === "error" ? console.error(a.message) : console.warn(a.message);
345
- return {
346
- ok: n.every((a) => a.severity !== "error"),
347
- warnings: n
348
- };
349
- }
350
- function M(e) {
351
- const t = L(e);
352
- if (!t.success) {
353
- const n = t.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
354
- throw new Error(`[gengage] Invalid runtime config: ${n}`);
355
- }
356
- return t.data;
357
- }
358
- function N(e, t, n) {
359
- const i = {
360
- accountId: e.accountId,
361
- middlewareUrl: e.middlewareUrl,
362
- idempotencyKey: e.gtm.idempotencyKey
363
- };
364
- return e.locale !== void 0 && (i.locale = e.locale), n !== void 0 && (i.pageContext = n, n.sku !== void 0 && (i.sku = n.sku)), i.chat = { enabled: e.widgets.chat.enabled }, e.mounts.chat !== void 0 && (i.chat.mountTarget = e.mounts.chat), i.qna = { enabled: e.widgets.qna.enabled }, e.mounts.qna !== void 0 && (i.qna.mountTarget = e.mounts.qna), e.widgets.simrel !== void 0 && (i.simrel = {
365
- enabled: e.widgets.simrel.enabled,
366
- ...e.mounts.simrel !== void 0 ? { mountTarget: e.mounts.simrel } : {}
367
- }), i.simbut = { enabled: e.widgets.simbut.enabled }, e.mounts.simbut !== void 0 && (i.simbut.mountTarget = e.mounts.simbut), t?.onAddToCart !== void 0 && (i.onAddToCart = t.onAddToCart), t?.onProductNavigate !== void 0 && (i.onProductNavigate = t.onProductNavigate), t?.onFindSimilar !== void 0 && (i.simbut.onFindSimilar = t.onFindSimilar), t?.onScriptCall !== void 0 && (i.onScriptCall = t.onScriptCall), i;
368
- }
369
- async function ne(e) {
370
- const t = M(e.runtimeConfig);
371
- if (e.preflight !== !1) {
372
- const o = B(t);
373
- if (!o.ok) {
374
- const r = o.warnings.filter((a) => a.severity === "error");
375
- throw new Error(`[gengage] Preflight failed: ${r.map((a) => a.message).join("; ")}`);
376
- }
377
- }
378
- const n = e.contextResolver?.(), i = await k(N(t, e.hostActions, n));
379
- if (e.contextResolver !== void 0) {
380
- const o = e.contextResolver, r = () => {
381
- const l = o();
382
- i.updateContext(l);
383
- };
384
- window.addEventListener("gengage:context:update", r);
385
- const a = i.destroy.bind(i);
386
- i.destroy = () => {
387
- window.removeEventListener("gengage:context:update", r), a();
388
- };
389
- }
390
- return i;
391
- }
392
- var $ = [
393
- {
394
- pageType: "home",
395
- urlPatterns: [
396
- "^/$",
397
- "^/index\\.html?$",
398
- "^/anasayfa$"
399
- ]
400
- },
401
- {
402
- pageType: "search",
403
- urlPatterns: [
404
- "/arama",
405
- "/search",
406
- "/ara\\?"
407
- ],
408
- queryParam: "q"
409
- },
410
- {
411
- pageType: "cart",
412
- urlPatterns: [
413
- "/sepet",
414
- "/cart",
415
- "/basket",
416
- "/sepetim"
417
- ]
418
- },
419
- {
420
- pageType: "plp",
421
- urlPatterns: [
422
- "/kategori/",
423
- "/category/",
424
- "/c/",
425
- "/koleksiyon/",
426
- "/collection/"
427
- ]
428
- },
429
- {
430
- pageType: "pdp",
431
- urlPatterns: [
432
- "/urun/",
433
- "/product/",
434
- "/p/",
435
- "/-p-",
436
- "/-pm-"
437
- ]
438
- }
439
- ];
440
- function z(e, t) {
441
- const n = t ?? (typeof window < "u" ? new URL(window.location.href) : null);
442
- if (!n) return "other";
443
- const i = e ?? $, o = n.pathname;
444
- for (const r of i)
445
- if (!(r.urlPatterns && !r.urlPatterns.some((a) => {
446
- try {
447
- return new RegExp(a, "i").test(o);
448
- } catch {
449
- return !1;
450
- }
451
- })) && !(r.queryParam && !n.searchParams.has(r.queryParam)) && !(r.selector && typeof document < "u" && !document.querySelector(r.selector)))
452
- return r.pageType;
453
- return "other";
454
- }
455
- function K(e) {
456
- const t = e ?? (typeof window < "u" ? new URL(window.location.href) : null);
457
- if (!t) return;
458
- const n = t.pathname, i = n.match(/\/(?:p|urun|product)\/([^/?#]+)/i);
459
- if (i?.[1]) return i[1];
460
- const o = n.match(/-p-(\d+)/i);
461
- if (o?.[1]) return o[1];
462
- }
463
- function ie(e) {
464
- const t = z(e), n = { pageType: t };
465
- if (t === "pdp") {
466
- const i = K();
467
- i && (n.sku = i);
468
- }
469
- return typeof window < "u" && (n.url = window.location.href), n;
470
- }
471
- export {
472
- Y as _,
473
- B as a,
474
- te as c,
475
- ee as d,
476
- D as f,
477
- E as g,
478
- U as h,
479
- ne as i,
480
- X as l,
481
- v as m,
482
- z as n,
483
- Q as o,
484
- J as p,
485
- K as r,
486
- V as s,
487
- ie as t,
488
- Z as u,
489
- R as v,
490
- L as y
491
- };