@gengage/assistant-fe 0.3.23 → 0.3.25
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.
- package/dist/chat/catalog.d.ts +2 -4
- package/dist/chat/components/ChatDrawer.d.ts +1 -2
- package/dist/chat/components/PhotoAnalysisCard.d.ts +1 -2
- package/dist/chat/types.d.ts +1 -2
- package/dist/{chat-DBJ8ZWch.js → chat-B1bVP6dh.js} +295 -297
- package/dist/chat.iife.js +4 -4
- package/dist/chat.js +1 -1
- package/dist/{common-BJZB1LIH.js → common-B-CaKFN9.js} +1 -1
- package/dist/common.js +3 -3
- package/dist/index.js +3 -3
- package/dist/{native-webview-111Or6o1.js → native-webview-Dx5logj9.js} +1 -1
- package/dist/native.iife.js +2 -2
- package/dist/native.js +1 -1
- package/package.json +8 -16
- package/dist/chat-BOkLnT1i.cjs +0 -93
- package/dist/chat.cjs +0 -1
- package/dist/common-0GWnpStO.cjs +0 -1
- package/dist/common.cjs +0 -1
- package/dist/connection-warning-YQiIRXrz.cjs +0 -1
- package/dist/ga-datalayer-BVppFxqk.cjs +0 -47
- package/dist/index.cjs +0 -1
- package/dist/native-webview-BePZBK3U.cjs +0 -1
- package/dist/native.cjs +0 -1
- package/dist/product-utils-DLXQQJbh.cjs +0 -1
- package/dist/qna-DwG8AJJf.cjs +0 -1
- package/dist/qna.cjs +0 -1
- package/dist/schemas-B7jnyzQI.cjs +0 -40
- package/dist/simbut-D_ycY_MQ.cjs +0 -1
- package/dist/simbut.cjs +0 -1
- package/dist/simrel-DdP4lur9.cjs +0 -1
- package/dist/simrel.cjs +0 -1
package/dist/chat.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chat-BOkLnT1i.cjs");exports.CHAT_SCROLL_ELEMENT_ID=e.CHAT_SCROLL_ELEMENT_ID;exports.ChatPresentationState=e.ChatPresentationState;exports.GengageChat=e.GengageChat;exports.chatCatalog=e.chatCatalog;exports.createChatWidget=e.createChatWidget;exports.createDefaultChatUISpecRegistry=e.createDefaultChatUISpecRegistry;exports.defaultChatUnknownUISpecRenderer=e.defaultChatUnknownUISpecRenderer;exports.getChatScrollElement=e.getChatScrollElement;exports.invalidateChatScrollCache=e.invalidateChatScrollCache;exports.renderUISpec=e.renderUISpec;
|
package/dist/common-0GWnpStO.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const y=require("./schemas-B7jnyzQI.cjs"),l=require("./native-webview-BePZBK3U.cjs");var p={enabled:!0,endpoint:"/analytics",fireAndForget:!0,useBeacon:!0,keepaliveFetch:!0,timeoutMs:4e3,maxRetries:0,batchSize:10,flushIntervalMs:250},b={mode:"none",key:"",headerName:"X-API-Key",bodyField:"api_key"},f=class{constructor(e){this.queue=[],this.flushTimer=null,this.config={...p,...e,auth:{...b,...e.auth??{}}},this.onPageHideBound=()=>{this.queue.length!==0&&this.flushAllSync()},typeof window<"u"&&window.addEventListener("pagehide",this.onPageHideBound)}track(e){if(!this.config.enabled)return;const t=w(e);if(this.queue.push(t),this.queue.length>=this.config.batchSize){this.scheduleImmediateFlush();return}this.scheduleFlush()}flush(){if(!this.config.enabled||this.queue.length===0)return;const e=this.queue.splice(0,this.config.batchSize),t=this.buildTransportBody(e),r=c(this.config.endpoint,this.config.middlewareUrl);this.send(r,t)}flushAll(){for(;this.queue.length>0;)this.flush()}destroy(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.queue.length>0&&this.flushAllSync(),typeof window<"u"&&window.removeEventListener("pagehide",this.onPageHideBound)}scheduleFlush(){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.flush()},this.config.flushIntervalMs))}scheduleImmediateFlush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.flush()}buildTransportBody(e){const t={events:e};return this.config.auth.mode==="body-api-key"&&this.config.auth.key&&(t[this.config.auth.bodyField]=this.config.auth.key),t}send(e,t){try{const r=JSON.stringify(t);if(this.config.useBeacon&&this.config.auth.mode!=="x-api-key-header"&&this.config.auth.mode!=="bearer-header"&&d()){const o=new Blob([r],{type:"application/json"});navigator.sendBeacon(e,o);return}if(typeof fetch>"u")return;const n={"Content-Type":"application/json"};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,{method:"POST",headers:n,body:r,keepalive:!0}).catch(()=>{})}catch{}}flushAllSync(){if(!this.config.enabled)return;const e=c(this.config.endpoint,this.config.middlewareUrl);for(;this.queue.length>0;){const t=this.queue.splice(0,this.config.batchSize),r=this.buildTransportBody(t);try{const n=JSON.stringify(r);if(d()){const o=new Blob([n],{type:"application/json"});navigator.sendBeacon(e,o)}}catch{}}}};function v(e){return new f(e)}function w(e){const t={event_name:e.event_name,event_version:e.event_version??"1",timestamp_ms:e.timestamp_ms??Date.now(),account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:e.payload};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}function c(e,t){return/^https?:\/\//i.test(e)?e:`${y.normalizeMiddlewareUrl(t)}${e.startsWith("/")?e:`/${e}`}`}function d(){return typeof navigator<"u"&&typeof navigator.sendBeacon=="function"}var T="tr";function C(e){return{ACCOUNT_ID:e.accountId,MIDDLEWARE_URL:e.middlewareUrl,LOCALE:e.locale??"tr"}}function P(e,t={}){const r={accountId:e.accountId,middlewareUrl:e.middlewareUrl,session:{sessionId:e.sessionId},variant:"floating",locale:e.locale??"tr",...t};return e.theme!==void 0&&(r.theme=e.theme),r}function _(e,t={}){const r={accountId:e.accountId,middlewareUrl:e.middlewareUrl,session:{sessionId:e.sessionId},pageContext:{pageType:"pdp",sku:e.sku},mountTarget:e.mountTarget,...t};return e.theme!==void 0&&(r.theme=e.theme),r}function k(e,t={}){const r={accountId:e.accountId,middlewareUrl:e.middlewareUrl,session:{sessionId:e.sessionId},sku:e.sku,mountTarget:e.mountTarget,...t};return e.theme!==void 0&&(r.theme=e.theme),r}function I(e,t={}){return{enabled:!0,middlewareUrl:e,endpoint:"/analytics",fireAndForget:!0,useBeacon:!0,...t}}function S(e){try{return document.querySelector(e),!0}catch{return!1}}function h(e,t){const r=[],n=e.mounts,o=[["qna",n.qna],["simrel",n.simrel],["simbut",n.simbut],["chat",n.chat]];for(const[i,s]of o)if(s!==void 0){if(!S(s)){r.push({code:"INVALID_SELECTOR",message:`[gengage preflight] ${i} mount selector is invalid CSS: "${s}"`,severity:"error"});continue}document.querySelector(s)||r.push({code:"MOUNT_NOT_FOUND",message:`[gengage preflight] ${i} mount target not found: "${s}" — widget will skip or wait for DOM`,severity:"warn"})}if(e.widgets.simbut.enabled&&n.simbut===void 0){const i="#gengage-simbut";document.querySelector(i)||r.push({code:"SIMBUT_MOUNT_REQUIRED",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 "${i}" was not found in the DOM.`,severity:"error"})}const a=e.gtm.idempotencyKey;if(window[a]!==void 0&&r.push({code:"DUPLICATE_IDEMPOTENCY",message:`[gengage preflight] window["${a}"] already exists — widgets may have already initialized`,severity:"warn"}),!t?.skipCspCheck){let i=!1;const s=u=>{u.blockedURI&&e.middlewareUrl.startsWith(u.blockedURI)&&(i=!0)};document.addEventListener("securitypolicyviolation",s);try{fetch(e.middlewareUrl,{method:"HEAD",mode:"no-cors"}).catch(()=>{})}catch{i=!0}document.removeEventListener("securitypolicyviolation",s),i&&r.push({code:"CSP_BLOCKED",message:`[gengage preflight] middleware URL may be blocked by Content-Security-Policy: "${e.middlewareUrl}". Add it to connect-src.`,severity:"warn"})}for(const i of r)i.severity==="error"?console.error(i.message):console.warn(i.message);return{ok:r.every(i=>i.severity!=="error"),warnings:r}}function U(e){const t=l.safeParseAccountRuntimeConfig(e);if(!t.success){const r=t.error.issues.map(n=>`${n.path.join(".")}: ${n.message}`).join("; ");throw new Error(`[gengage] Invalid runtime config: ${r}`)}return t.data}function O(e,t,r){const n={accountId:e.accountId,middlewareUrl:e.middlewareUrl,idempotencyKey:e.gtm.idempotencyKey};return e.locale!==void 0&&(n.locale=e.locale),r!==void 0&&(n.pageContext=r,r.sku!==void 0&&(n.sku=r.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),n.simrel={enabled:e.widgets.simrel.enabled},e.mounts.simrel!==void 0&&(n.simrel.mountTarget=e.mounts.simrel),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}async function A(e){const t=U(e.runtimeConfig);if(e.preflight!==!1){const o=h(t);if(!o.ok){const a=o.warnings.filter(i=>i.severity==="error");throw new Error(`[gengage] Preflight failed: ${a.map(i=>i.message).join("; ")}`)}}const r=e.contextResolver?.(),n=await l.initOverlayWidgets(O(t,e.hostActions,r));if(e.contextResolver!==void 0){const o=e.contextResolver,a=()=>{const s=o();n.updateContext(s)};window.addEventListener("gengage:context:update",a);const i=n.destroy.bind(n);n.destroy=()=>{window.removeEventListener("gengage:context:update",a),i()}}return n}var E=[{pageType:"home",urlPatterns:["^/$","^/index\\.html?$","^/anasayfa$"]},{pageType:"search",urlPatterns:["/arama","/search","/ara\\?"],queryParam:"q"},{pageType:"cart",urlPatterns:["/sepet","/cart","/basket","/sepetim"]},{pageType:"plp",urlPatterns:["/kategori/","/category/","/c/","/koleksiyon/","/collection/"]},{pageType:"pdp",urlPatterns:["/urun/","/product/","/p/","/-p-","/-pm-"]}];function m(e,t){const r=t??(typeof window<"u"?new URL(window.location.href):null);if(!r)return"other";const n=e??E,o=r.pathname;for(const a of n)if(!(a.urlPatterns&&!a.urlPatterns.some(i=>{try{return new RegExp(i,"i").test(o)}catch{return!1}}))&&!(a.queryParam&&!r.searchParams.has(a.queryParam))&&!(a.selector&&typeof document<"u"&&!document.querySelector(a.selector)))return a.pageType;return"other"}function g(e){const t=e??(typeof window<"u"?new URL(window.location.href):null);if(!t)return;const r=t.pathname,n=r.match(/\/(?:p|urun|product)\/([^/?#]+)/i);if(n?.[1])return n[1];const o=r.match(/-p-(\d+)/i);if(o?.[1])return o[1]}function q(e){const t=m(e),r={pageType:t};if(t==="pdp"){const n=g();n&&(r.sku=n)}return typeof window<"u"&&(r.url=window.location.href),r}Object.defineProperty(exports,"AnalyticsClient",{enumerable:!0,get:function(){return f}});Object.defineProperty(exports,"DEFAULT_CUSTOMIZATION_LOCALE",{enumerable:!0,get:function(){return T}});Object.defineProperty(exports,"autoDetectPageContext",{enumerable:!0,get:function(){return q}});Object.defineProperty(exports,"createAccountIdentity",{enumerable:!0,get:function(){return C}});Object.defineProperty(exports,"createAnalyticsClient",{enumerable:!0,get:function(){return v}});Object.defineProperty(exports,"createDefaultAnalyticsConfig",{enumerable:!0,get:function(){return I}});Object.defineProperty(exports,"createFloatingChatConfig",{enumerable:!0,get:function(){return P}});Object.defineProperty(exports,"createPdpQnaConfig",{enumerable:!0,get:function(){return _}});Object.defineProperty(exports,"createPdpSimRelConfig",{enumerable:!0,get:function(){return k}});Object.defineProperty(exports,"detectPageType",{enumerable:!0,get:function(){return m}});Object.defineProperty(exports,"extractSkuFromUrl",{enumerable:!0,get:function(){return g}});Object.defineProperty(exports,"initGengageClient",{enumerable:!0,get:function(){return A}});Object.defineProperty(exports,"preflightDiagnostics",{enumerable:!0,get:function(){return h}});
|
package/dist/common.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./schemas-B7jnyzQI.cjs"),e=require("./ga-datalayer-BVppFxqk.cjs"),i=require("./chat-BOkLnT1i.cjs"),a=require("./connection-warning-YQiIRXrz.cjs"),t=require("./native-webview-BePZBK3U.cjs"),r=require("./common-0GWnpStO.cjs");exports.AccountRuntimeConfigSchema=t.AccountRuntimeConfigSchema;exports.AnalyticsAuthModeSchema=t.AnalyticsAuthModeSchema;exports.AnalyticsClient=r.AnalyticsClient;exports.BASE_WIDGET_THEME=e.BASE_WIDGET_THEME;exports.BaseWidget=e.BaseWidget;exports.DEFAULT_CUSTOMIZATION_LOCALE=r.DEFAULT_CUSTOMIZATION_LOCALE;exports.DEFAULT_WIDGET_THEME_TOKENS=e.DEFAULT_WIDGET_THEME_TOKENS;exports.UnknownActionPolicySchema=t.UnknownActionPolicySchema;exports.VoiceInput=i.VoiceInput;exports.adaptBackendEvent=n.adaptBackendEvent;exports.applyNativeSession=t.applyNativeSession;exports.autoDetectPageContext=r.autoDetectPageContext;exports.basketAddEvent=e.basketAddEvent;exports.bootstrapSession=e.bootstrapSession;exports.buildChatEndpointUrl=n.buildChatEndpointUrl;exports.buildOverlayIdempotencyKey=t.buildOverlayIdempotencyKey;exports.chatHistorySnapshotEvent=e.chatHistorySnapshotEvent;exports.checkoutCompleteEvent=e.checkoutCompleteEvent;exports.checkoutStartEvent=e.checkoutStartEvent;exports.configureConnectionWarning=a.configureConnectionWarning;exports.consumeStream=n.consumeStream;exports.createAccountIdentity=r.createAccountIdentity;exports.createAnalyticsClient=r.createAnalyticsClient;exports.createDefaultAccountRuntimeConfig=t.createDefaultAccountRuntimeConfig;exports.createDefaultAnalyticsConfig=r.createDefaultAnalyticsConfig;exports.createFloatingChatConfig=r.createFloatingChatConfig;exports.createNativeWebViewBridge=t.createNativeWebViewBridge;exports.createPdpQnaConfig=r.createPdpQnaConfig;exports.createPdpSimRelConfig=r.createPdpSimRelConfig;exports.defaultUnknownUISpecRenderer=n.defaultUnknownUISpecRenderer;exports.destroyOverlayWidgets=t.destroyOverlayWidgets;exports.detectNativeEnvironment=t.detectNativeEnvironment;exports.detectPageType=r.detectPageType;exports.dismissGlobalErrorToast=e.dismissGlobalErrorToast;exports.dispatch=e.dispatch;exports.extractSkuFromUrl=r.extractSkuFromUrl;exports.getGlobalErrorMessage=e.getGlobalErrorMessage;exports.getOverlayWidgets=t.getOverlayWidgets;exports.getSuggestedSearchKeywords=n.getSuggestedSearchKeywords;exports.getSuggestedSearchKeywordsText=n.getSuggestedSearchKeywordsText;exports.getWindowPageContext=e.getWindowPageContext;exports.initGengageClient=r.initGengageClient;exports.initNativeOverlayWidgets=t.initNativeOverlayWidgets;exports.initOverlayWidgets=t.initOverlayWidgets;exports.isVoiceInputSupported=i.isVoiceInputSupported;exports.listen=e.listen;exports.llmUsageEvent=e.llmUsageEvent;exports.makePillLauncher=i.makePillLauncher;exports.mergeUISpecRegistry=n.mergeUISpecRegistry;exports.meteringIncrementEvent=e.meteringIncrementEvent;exports.meteringSummaryEvent=e.meteringSummaryEvent;exports.normalizeMiddlewareUrl=n.normalizeMiddlewareUrl;exports.normalizeProductGroupingsResponse=n.normalizeProductGroupingsResponse;exports.normalizeSimilarProductsResponse=n.normalizeSimilarProductsResponse;exports.parseAccountRuntimeConfig=t.parseAccountRuntimeConfig;exports.preflightDiagnostics=r.preflightDiagnostics;exports.productToNormalized=n.productToNormalized;exports.registerGlobalErrorToastListener=e.registerGlobalErrorToastListener;exports.renderUISpecWithRegistry=n.renderUISpecWithRegistry;exports.resolveSession=e.resolveSession;exports.routeStreamAction=i.routeStreamAction;exports.safeParseAccountRuntimeConfig=t.safeParseAccountRuntimeConfig;exports.sanitizeHtml=e.sanitizeHtml;exports.showGlobalErrorToast=e.showGlobalErrorToast;exports.streamChunkEvent=e.streamChunkEvent;exports.streamDoneEvent=e.streamDoneEvent;exports.streamErrorEvent=e.streamErrorEvent;exports.streamPost=n.streamPost;exports.streamStartEvent=e.streamStartEvent;exports.streamUiSpecEvent=e.streamUiSpecEvent;exports.trackConnectionWarningRequest=a.trackConnectionWarningRequest;exports.updatePageContext=e.updatePageContext;exports.widgetHistorySnapshotEvent=e.widgetHistorySnapshotEvent;exports.wireGADataLayer=e.wireGADataLayer;exports.wireQNAToChat=e.wireQNAToChat;exports.wireSimilarToChat=e.wireSimilarToChat;exports.withBaseTheme=e.withBaseTheme;exports.withDefaultWidgetTheme=e.withDefaultWidgetTheme;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const l=require("./ga-datalayer-BVppFxqk.cjs");var w=8e3,h=5e3,g="https://www.google.com/favicon.ico";function m(e){e.probeUrl&&(g=e.probeUrl)}var n=new Map,f=!1,i=null,a=null,r=!1;function b(e){return typeof e=="string"&&e.toLowerCase().startsWith("tr")}function y(e){return b(e)?"İnternet bağlantısında sorun var gibi görünüyor. İstek sürerken yeniden deneyeceğiz.":"Your internet connection looks unstable. We'll keep retrying while this request is active."}function v(){let e;for(const t of n.values())e=t;return e}function u(){i&&(clearTimeout(i),i=null)}function C(){a&&(clearInterval(a),a=null)}async function d(){try{if(typeof navigator<"u"&&navigator.onLine===!1)return!1;if(typeof window<"u"){const o=window.location.hostname;if(o==="localhost"||o==="127.0.0.1")return navigator.onLine}const e=new AbortController,t=setTimeout(()=>e.abort(),3e3);try{return await fetch(g,{method:"HEAD",mode:"no-cors",cache:"no-cache",signal:e.signal}),!0}catch{return navigator.onLine}finally{clearTimeout(t)}}catch{return typeof navigator>"u"?!0:navigator.onLine}}function s(){r=!1,C(),l.dismissGlobalErrorToast()}function c(){i||r||n.size===0||(i=setTimeout(async()=>{i=null,!(r||n.size===0)&&!await d()&&n.size>0&&(r=!0,l.showGlobalErrorToast({source:"sdk",message:y(v()),sticky:!0}),a||(a=setInterval(async()=>{if(n.size===0){s();return}await d()&&(s(),c())},h)))},w))}function T(){f||typeof window>"u"||(f=!0,window.addEventListener("online",()=>{s(),c()}),window.addEventListener("offline",()=>{n.size===0||r||(r=!0,u(),l.showGlobalErrorToast({source:"sdk",message:y(v()),sticky:!0}))}))}function k(e){T();const t=Symbol(e.source);n.set(t,e.locale),c();let o=!1;return()=>{if(!o){if(o=!0,n.delete(t),n.size===0){u(),s();return}r||(u(),c())}}}Object.defineProperty(exports,"configureConnectionWarning",{enumerable:!0,get:function(){return m}});Object.defineProperty(exports,"trackConnectionWarningRequest",{enumerable:!0,get:function(){return k}});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
function Z(e,t){const n={event_name:"stream.start",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{endpoint:t.endpoint,request_id:t.request_id}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),t.widget!==void 0&&(n.widget=t.widget),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function ee(e,t){const n={request_id:t.request_id,chunk_index:t.chunk_index};t.latency_ms!==void 0&&(n.latency_ms=t.latency_ms);const r={event_name:"stream.chunk",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:n};return e.view_id!==void 0&&(r.view_id=e.view_id),e.user_id!==void 0&&(r.user_id=e.user_id),t.widget!==void 0&&(r.widget=t.widget),e.page_type!==void 0&&(r.page_type=e.page_type),e.sku!==void 0&&(r.sku=e.sku),r}function te(e,t){const n={event_name:"stream.ui_spec",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{request_id:t.request_id,chunk_index:t.chunk_index,component_type:t.component_type}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),t.widget!==void 0&&(n.widget=t.widget),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function ne(e,t){const n={event_name:"stream.done",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{request_id:t.request_id,latency_ms:t.latency_ms,chunk_count:t.chunk_count}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),t.widget!==void 0&&(n.widget=t.widget),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function re(e,t){const n={event_name:"stream.error",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{request_id:t.request_id,error_code:t.error_code,error_message:t.error_message}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),t.widget!==void 0&&(n.widget=t.widget),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function ie(e,t){const n={model:t.model,prompt_tokens:t.prompt_tokens,completion_tokens:t.completion_tokens,total_tokens:t.total_tokens};t.provider!==void 0&&(n.provider=t.provider);const r={event_name:"llm.usage",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:n};return e.view_id!==void 0&&(r.view_id=e.view_id),e.user_id!==void 0&&(r.user_id=e.user_id),e.page_type!==void 0&&(r.page_type=e.page_type),e.sku!==void 0&&(r.sku=e.sku),r}function oe(e,t){const n={event_name:"metering.increment",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{meter_key:t.meter_key,quantity:t.quantity,unit:t.unit}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function M(e,t){const n={event_name:"metering.summary",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{meter_key:t.meter_key,quantity:t.quantity,unit:t.unit}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function se(e,t){const n={event_name:"chat.history.snapshot",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{message_count:t.message_count,history_ref:t.history_ref,redaction_level:t.redaction_level}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function ae(e,t){const n={event_name:"widget.history.snapshot",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,widget:t.widget,payload:{message_count:t.message_count,history_ref:t.history_ref,redaction_level:t.redaction_level}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function ue(e,t){const n={event_name:"basket.add",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,widget:t.attribution_source,payload:{attribution_source:t.attribution_source,attribution_action_id:t.attribution_action_id,cart_value:t.cart_value,currency:t.currency,line_items:t.line_items,sku:t.sku}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function D(e,t){const n={event_name:"checkout.start",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,widget:t.attribution_source,payload:{attribution_source:t.attribution_source,attribution_action_id:t.attribution_action_id,cart_value:t.cart_value,currency:t.currency,line_items:t.line_items}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function q(e,t){const n={event_name:"checkout.complete",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,widget:t.attribution_source,payload:{attribution_source:t.attribution_source,attribution_action_id:t.attribution_action_id,cart_value:t.cart_value,currency:t.currency,line_items:t.line_items}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}var de=new Set(["p","br","a","strong","b","em","i","u","ul","ol","li","h1","h2","h3","h4","h5","h6","span","div","table","thead","tbody","tr","th","td","hr","code","pre","blockquote","img","sup","sub"]),ge=new Set(["script","iframe","object","embed","form","input","textarea","select","button","style","link","meta","template","noscript"]),A={"*":new Set(["class"]),a:new Set(["href","target","rel"]),img:new Set(["src","alt","width","height"]),div:new Set(["style"]),span:new Set(["style"]),p:new Set(["style"])};function ce(e){return/^\s*javascript\s*:/i.test(e)}var fe=new Set(["color","background-color","font-size","font-weight","font-style","font-family","text-align","text-decoration","line-height","letter-spacing","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","border","border-top","border-right","border-bottom","border-left","border-radius","border-color","border-width","border-style","width","max-width","min-width","height","max-height","min-height","display","vertical-align","white-space","word-break","overflow","opacity","visibility","list-style","list-style-type","text-transform","text-indent","text-overflow","box-sizing","flex","flex-direction","flex-wrap","justify-content","align-items","gap"]),le=/url\s*\(|expression\s*\(|javascript\s*:|\bimport\b|-moz-binding|behavior\s*:/i;function pe(e){const t=[];for(const n of e.split(";")){const r=n.trim();if(!r)continue;const i=r.indexOf(":");if(i===-1)continue;const u=r.slice(0,i).trim().toLowerCase(),l=r.slice(i+1).trim();fe.has(u)&&(le.test(l)||t.push(r))}return t.join("; ")}function k(e,t){if(e.nodeType===Node.TEXT_NODE)return;if(e.nodeType!==Node.ELEMENT_NODE){e.parentNode?.removeChild(e);return}const n=e,r=n.tagName.toLowerCase();if(ge.has(r)){n.parentNode?.removeChild(n);return}if(!de.has(r)){const o=Array.from(n.childNodes);for(const d of o)t.insertBefore(d,n);t.removeChild(n);for(const d of o)k(d,t);return}const i=A["*"]??new Set,u=A[r]??new Set,l=Array.from(n.attributes);for(const o of l){const d=o.name.toLowerCase();if(!i.has(d)&&!u.has(d)){n.removeAttribute(o.name);continue}if(ce(o.value)){n.removeAttribute(o.name);continue}if(d==="style"){const h=pe(o.value);h?n.setAttribute("style",h):n.removeAttribute("style");continue}}if(r==="a"){const o=n.getAttribute("href");if(o!==null){const d=o.trim().toLowerCase();!d.startsWith("http://")&&!d.startsWith("https://")&&!d.startsWith("mailto:")&&n.removeAttribute("href")}n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer")}if(r==="img"){const o=n.getAttribute("src");o!==null&&(o.trim().toLowerCase().startsWith("https://")||n.removeAttribute("src"))}const m=Array.from(n.childNodes);for(const o of m)k(o,n)}var N=["http:","https:"];function _e(e){try{return N.includes(new URL(e).protocol)}catch{return!1}}function T(e){if(e.startsWith("/")&&!e.startsWith("//"))return!0;try{const t=new URL(e);return N.includes(t.protocol)}catch{return!1}}function me(e,t,n){(t==="href"||t==="src")&&!T(n)||e.setAttribute(t,n)}function he(e){if(!e)return"";const t=new DOMParser().parseFromString(e,"text/html").body,n=Array.from(t.childNodes);for(const r of n)k(r,t);return t.innerHTML}function be(e,t){window.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!1}))}function _(e,t){const n=r=>{t(r.detail)};return window.addEventListener(e,n),()=>window.removeEventListener(e,n)}function ve(e){if(e.type!=="user_message"&&e.type!=="inputText")return null;if(typeof e.payload=="string"&&e.payload.trim().length>0)return e.payload.trim();if(typeof e.payload=="object"&&e.payload!==null){const t=e.payload;if(typeof t.text=="string"){const n=t.text.trim();if(n.length>0)return n}}return typeof e.title=="string"&&e.title.trim().length>0?e.title.trim():null}function ye(e){if(e.type!=="inputText"&&e.type!=="user_message")return e;const t=typeof e.payload=="string"?{text:e.payload.trim()}:e.payload!=null&&typeof e.payload=="object"&&!Array.isArray(e.payload)?{...e.payload}:{};if(typeof t.text!="string"||!t.text.trim()){const n=e.title?.trim();n&&(t.text=n)}return"is_launcher"in t||(t.is_launcher=1),"is_suggested_text"in t||(t.is_suggested_text=1),{...e,payload:t}}function we(e){let t=!1;const n=[];let r=0,i=null,u=0;const l=100,m=5e3;function o(){return window.gengage?.chat??null}function d(){t||(console.warn("[gengage] QNA tried to open chat, but chat widget is not initialized. Ensure GengageChat is initialized before calling wireQNAToChat()."),t=!0),e?.onChatUnavailable?.()}function h(a,c){if(a.openWithAction){const X=c.type==="inputText"||c.type==="user_message"?ye(c):c;a.openWithAction(X);return}const y=ve(c);if(y&&a.sendMessage){a.open?.(),a.sendMessage(y);return}}function w(){i!==null&&(window.clearInterval(i),i=null)}function Y(){const a=o();if(!a)return!1;if(r>0&&(a.open?.(),r=0),n.length>0){const c=n.splice(0,n.length);for(const y of c)h(a,y)}return w(),!0}function P(){i===null&&(u=Date.now(),i=window.setInterval(()=>{Y()||Date.now()-u>=m&&(n.length=0,r=0,w())},l))}const J=_("gengage:qna:action",a=>{const c=o();if(c){h(c,a);return}d(),n.length>=20&&n.shift(),n.push(a),P()}),K=_("gengage:qna:open-chat",()=>{const a=o();if(a){a.open?.();return}d(),r+=1,P()});return()=>{J(),K(),n.length=0,r=0,w()}}function ke(){return _("gengage:similar:product-click",({sku:e,url:t,sessionId:n})=>{n&&window.gengage?.chat?.saveSession(n,e),T(t)&&(window.location.href=t)})}function R(){const e=window.__gengageSessionId??sessionStorage.getItem("gengage_session_id")??null??crypto.randomUUID();return window.__gengageSessionId=e,sessionStorage.setItem("gengage_session_id",e),window.gengage||(window.gengage={}),window.gengage.sessionId=e,e}function Ee(){return window.gengage?.pageContext??null}function Se(e){window.gengage||(window.gengage={}),window.gengage.pageContext={pageType:"other",...window.gengage.pageContext,...e},window.dispatchEvent(new CustomEvent("gengage:context:update",{detail:e}))}function U(e){return{sessionId:e?.sessionId??R(),...e}}var E={"--gengage-chat-offset":"20px","--gengage-chat-launcher-size":"56px","--gengage-chat-width":"400px","--gengage-chat-shell-radius":"1rem","--gengage-chat-header-height":"72px","--gengage-chat-conversation-width":"396px","--gengage-chat-panel-min-width":"320px","--gengage-chat-panel-max-width":"1200px","--gengage-chat-input-height":"48px","--gengage-qna-pill-radius":"999px","--gengage-qna-input-radius":"12px","--gengage-simrel-card-radius":"0.75rem","--radius-control":"12px","--radius-card":"16px","--radius-panel":"24px","--radius-pill":"999px","--surface-card-muted":"#f8fafc","--text-secondary":"#4b5563","--text-muted":"#6b7280","--border-default":"rgba(17, 24, 39, 0.10)"};function W(e){return e?{...E,...e}:{...E}}var g={primaryColor:"#b7102a",primaryForeground:"#ffffff",backgroundColor:"#ffffff",foregroundColor:"#111827",borderRadius:"0.75rem",fontFamily:'"Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",zIndex:"1000","--glov-chatbot-width":"420px","--glov-left-spacing":"260px","--chatbot-padding":"16px","--root-wrapper-background-color":"#f8f9fa","--root-wrapper-border-color":"#edeeef","--gengage-chat-width":"400px","--gengage-chat-shell-radius":"1rem","--gengage-chat-header-height":"72px","--gengage-chat-conversation-width":"396px","--gengage-chat-panel-min-width":"320px","--gengage-chat-panel-max-width":"1200px","--gengage-chat-input-height":"48px","--gengage-qna-pill-radius":"999px","--gengage-qna-input-radius":"0.75rem","--gengage-simrel-card-radius":"0.75rem","--client-primary":"#b7102a","--client-primary-hover":"color-mix(in srgb, #b7102a 88%, black 12%)","--client-primary-active":"color-mix(in srgb, #b7102a 78%, black 22%)","--client-primary-subtle":"color-mix(in srgb, #b7102a 12%, white)","--client-primary-soft":"color-mix(in srgb, #b7102a 20%, white)","--client-on-primary":"#ffffff","--client-focus-ring":"color-mix(in srgb, #b7102a 32%, transparent)","--surface-page":"#f6f7fb","--surface-shell":"#10131a","--surface-card":"#ffffff","--surface-card-muted":"#f8fafc","--surface-card-soft":"#f8fafc","--surface-elevated":"#ffffff","--surface-input":"#ffffff","--surface-overlay":"rgba(16, 19, 26, 0.52)","--text-primary":"#111827","--text-secondary":"#4b5563","--text-muted":"#6b7280","--text-inverse":"#f9fafb","--border-subtle":"rgba(17, 24, 39, 0.06)","--border-default":"rgba(17, 24, 39, 0.10)","--border-strong":"rgba(17, 24, 39, 0.18)","--shadow-1":"0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06)","--shadow-2":"0 4px 12px rgba(16, 24, 40, 0.08)","--shadow-3":"0 10px 24px rgba(16, 24, 40, 0.12)","--radius-control":"12px","--radius-card":"16px","--radius-panel":"24px","--radius-pill":"999px","--success":"#16a34a","--warning":"#d97706","--error":"#dc2626","--info":"#2563eb","--rating":"#f5b301","--ai-accent-start":"#0b24d6","--ai-accent-end":"#f768f2","--ai-accent-soft":"linear-gradient(135deg, rgba(11, 36, 214, 0.08), rgba(247, 104, 242, 0.08))"};function Ce(e){return{...g,...e}}var f="gengage-global-toast-root",j="gengage-global-toast-style",O="gengage-global-toast-root--visible",Te=4200,Oe=1500,Pe=15e3,Ae=["--gengage-font-family","--surface-card","--text-primary","--text-muted","--border-default","--radius-card","--shadow-3","--error","--ds-toast-error-bg","--ds-toast-error-border","--ds-toast-error-accent","--ds-toast-error-fg","--ds-toast-error-shadow"],I=!1,p=null,je=[/failed to fetch/i,/networkerror/i,/network request failed/i,/load failed/i,/err_network/i,/fetch failed/i,/network error/i];function L(e){return typeof e=="string"&&e.toLowerCase().startsWith("tr")}function $(e){if(typeof navigator<"u"&&navigator.onLine===!1)return!0;const t=e instanceof Error?e.message.trim():"";return t?je.some(n=>n.test(t)):!1}function Ie(e,t){return $(t)?L(e)?"Bağlantı sorunu oluştu. Lütfen tekrar deneyin.":"Connection issue. Please try again.":L(e)?"Bir hata oluştu. Lütfen tekrar deneyin.":"Something went wrong. Please try again."}function G(){I||typeof window>"u"||typeof document>"u"||(I=!0,_("gengage:global:error",e=>{H(e)}))}function H(e){if(typeof document>"u")return;const t=e.message.trim();if(!t)return;Ne();const n=Me();De(n),n.innerHTML="";const r=document.createElement("section");r.className="gengage-global-toast gengage-global-toast--error",r.setAttribute("role","status"),r.setAttribute("aria-live","polite");const i=document.createElement("div");i.className="gengage-global-toast-title",i.textContent=Le(e.source);const u=document.createElement("div");u.className="gengage-global-toast-message",u.textContent=t,r.appendChild(i),r.appendChild(u),n.appendChild(r),n.classList.add(O),p&&(clearTimeout(p),p=null),e.sticky!==!0&&(p=setTimeout(()=>{z()},qe(e.durationMs)))}function z(){if(typeof document>"u")return;const e=document.getElementById(f);e&&(e.classList.remove(O),e.innerHTML="",p&&(clearTimeout(p),p=null))}function Le(e){switch(e){case"chat":return"Chat warning";case"qna":return"QnA warning";case"simrel":return"Widget warning";default:return"Connection warning"}}function Me(){const e=document.getElementById(f);if(e instanceof HTMLElement)return e;const t=document.createElement("div");return t.id=f,t.className="gengage-global-toast-root",document.body.appendChild(t),t}function De(e){if(typeof document>"u"||typeof window>"u")return;const t=document.querySelector(".gengage-chat-root, .gengage-qna-container, .gengage-simrel-container, .gengage-simbut-root");if(!t)return;const n=window.getComputedStyle(t);for(const r of Ae){const i=n.getPropertyValue(r).trim();i?e.style.setProperty(r,i):e.style.removeProperty(r)}}function qe(e){return typeof e!="number"||!Number.isFinite(e)?Te:Math.min(Pe,Math.max(Oe,Math.round(e)))}function Ne(){if(document.getElementById(j))return;const e=document.createElement("style");e.id=j;const t=g["--surface-card"]??g.backgroundColor??"#ffffff",n=g["--text-primary"]??g.foregroundColor??"#111827",r=g["--border-default"]??"rgba(17, 24, 39, 0.10)",i=g["--error"]??"#dc2626",u=g["--shadow-3"]??"0 10px 24px rgba(16, 24, 40, 0.12)",l=g["--radius-card"]??"16px",m=g["--text-muted"]??"#6b7280";e.textContent=`
|
|
2
|
-
#${f} {
|
|
3
|
-
position: fixed;
|
|
4
|
-
top: 16px;
|
|
5
|
-
right: 16px;
|
|
6
|
-
z-index: 2147483646;
|
|
7
|
-
pointer-events: none;
|
|
8
|
-
}
|
|
9
|
-
#${f}.${O} {
|
|
10
|
-
pointer-events: auto;
|
|
11
|
-
}
|
|
12
|
-
#${f} .gengage-global-toast {
|
|
13
|
-
min-width: 260px;
|
|
14
|
-
max-width: min(92vw, 420px);
|
|
15
|
-
border-radius: var(--radius-card, ${l});
|
|
16
|
-
border: 1px solid var(--ds-toast-error-border, color-mix(in srgb, var(--error, ${i}) 18%, var(--border-default, ${r})));
|
|
17
|
-
border-left: 4px solid var(--ds-toast-error-accent, var(--error, ${i}));
|
|
18
|
-
background: var(--ds-toast-error-bg, color-mix(in srgb, var(--error, ${i}) 5%, var(--surface-card, ${t})));
|
|
19
|
-
color: var(--ds-toast-error-fg, color-mix(in srgb, var(--error, ${i}) 22%, var(--text-primary, ${n})));
|
|
20
|
-
box-shadow: var(--ds-toast-error-shadow, var(--shadow-3, ${u}));
|
|
21
|
-
padding: 10px 12px;
|
|
22
|
-
font-family: var(--gengage-font-family, ${JSON.stringify(g.fontFamily??'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif')});
|
|
23
|
-
font-size: 13px;
|
|
24
|
-
line-height: 1.4;
|
|
25
|
-
animation: gengage-global-toast-in 180ms ease-out forwards;
|
|
26
|
-
}
|
|
27
|
-
#${f} .gengage-global-toast-title {
|
|
28
|
-
margin: 0 0 4px;
|
|
29
|
-
font-size: 12px;
|
|
30
|
-
font-weight: 700;
|
|
31
|
-
color: var(--text-muted, ${m});
|
|
32
|
-
}
|
|
33
|
-
#${f} .gengage-global-toast-message {
|
|
34
|
-
margin: 0;
|
|
35
|
-
font-weight: 500;
|
|
36
|
-
}
|
|
37
|
-
@keyframes gengage-global-toast-in {
|
|
38
|
-
from {
|
|
39
|
-
opacity: 0;
|
|
40
|
-
transform: translateY(-8px);
|
|
41
|
-
}
|
|
42
|
-
to {
|
|
43
|
-
opacity: 1;
|
|
44
|
-
transform: translateY(0);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
`,document.head.appendChild(e)}var b=null;function Re(){if(b!==null)return b;try{b=localStorage.getItem("gengage:debug")==="1"}catch{b=!1}return b}function S(e,t,n){if(!Re())return;const r=[`[gengage:${e}]`,t];n!==void 0&&r.push(n),console.debug(...r)}var Ue=class{constructor(){this.isVisible=!1,this.isInitialised=!1,this._handlers=new Map,this._cleanups=[],this._ownsRoot=!1,this._destroying=!1}async init(e){if(this.isInitialised){console.warn("[gengage] Widget already initialised. Call update() instead.");return}const t=W(e.theme);this.config={...e,theme:t,session:U(e.session)},this.root=this._resolveMount(e.mountTarget),this._applyTheme(t),G();const n=_("gengage:context:update",r=>this.update(r));this._cleanups.push(n),S("lifecycle",`${this.constructor.name}.init`,{accountId:e.accountId,sku:e.pageContext?.sku});try{await this.onInit(this.config)}catch(r){throw this.destroy(),r}this._destroying||(this.isInitialised=!0,S("lifecycle",`${this.constructor.name} ready`),this.emit("ready"))}update(e){this.isInitialised&&(this.config.pageContext?this.config={...this.config,pageContext:{...this.config.pageContext,...e}}:e.pageType!==void 0&&(this.config={...this.config,pageContext:e}),this.onUpdate(e),this.emit("context-update",this.config.pageContext))}show(){this.isVisible||(this.isVisible=!0,this.root.style.display="",this.onShow(),this.emit("show"))}hide(){this.isVisible&&(this.isVisible=!1,this.root.style.display="none",this.onHide(),this.emit("hide"))}destroy(){this._destroying||(this._destroying=!0,this.emit("destroy"),this._cleanups.forEach(e=>e()),this._cleanups.length=0,this._handlers.clear(),this.onDestroy(),this.config.analyticsClient?.destroy(),this._cleanupRoot(),this.isInitialised=!1)}_cleanupRoot(){this._ownsRoot?this.root.remove():this.root.innerHTML=""}on(e,t){return this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t),()=>this._handlers.get(e)?.delete(t)}trackCheckout(e,t){const n=e==="start"?D:q;this.track(n(this.analyticsContext(),t))}flushMeteringSummary(e){this.track(M(this.analyticsContext(),e))}emit(e,...t){this._handlers.get(e)?.forEach(n=>n(...t))}addCleanup(e){this._cleanups.push(e)}track(e){this.config.analyticsClient?.track(e)}analyticsContext(){const e={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??""};return this.config.session?.viewId!==void 0&&(e.view_id=this.config.session.viewId),this.config.session?.userId!==void 0&&(e.user_id=this.config.session.userId),this.config.pageContext?.pageType!==void 0&&(e.page_type=this.config.pageContext.pageType),this.config.pageContext?.sku!==void 0&&(e.sku=this.config.pageContext.sku),this.config.session?.abTestVariant!==void 0&&(e.ab_test_variant=this.config.session.abTestVariant),this.config.session?.abTestExperimentId!==void 0&&(e.ab_test_experiment_id=this.config.session.abTestExperimentId),e}_resolveMount(e){if(e instanceof HTMLElement)return e;if(typeof e=="string"){const n=document.querySelector(e);if(!n)throw new Error(`[gengage] Mount target not found: "${e}"`);return n}const t=document.createElement("div");return t.dataset.gengageWidget=this.constructor.name.toLowerCase(),document.body.insertBefore(t,document.body.firstChild),this._ownsRoot=!0,t}_applyTheme(e){if(e){for(const[t,n]of Object.entries(e))if(n!==void 0){const r=t.startsWith("--")?t:`--gengage-${We(t)}`;this.root.style.setProperty(r,n)}}}};function We(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}function $e(){return typeof window<"u"&&Array.isArray(window.dataLayer)}function s(e,t){const n={event:e,...t};$e()&&window.dataLayer.push(n)}function B(e){s("gengage-on-init",{gengage_widget:e})}function C(e){s("gengage-show",{gengage_widget:e})}function Ge(e){s("gengage-hide",{gengage_widget:e})}function F(e,t){s("gengage-suggested-question",{gengage_question_title:e,gengage_action_type:t})}function He(e){s("gengage-find-similars",{gengage_sku:e})}function ze(e){s("gengage-compare-preselection",{gengage_sku:e})}function Be(e){s("gengage-compare-selected",{gengage_skus:e,gengage_product_count:e.length})}function Fe(){s("gengage-compare-clear")}function xe(e){s("gengage-compare-received",{gengage_product_count:e})}function Ve(e){s("gengage-like-product",{gengage_sku:e})}function Qe(){s("gengage-like-list")}function Ye(e,t){s("gengage-search",{gengage_search_query:e,gengage_result_count:t})}function x(e,t){s("gengage-product-detail",{gengage_sku:e,gengage_product_name:t})}function V(e,t){s("gengage-cart-add",{gengage_sku:e,gengage_quantity:t})}function Je(){s("gengage-message-sent")}function Ke(){s("gengage-message-received")}function Xe(){s("gengage-conversation-start")}function Q(){s("gengage-voice-input")}function Ze(e,t){s("gengage-error",{gengage_widget:e,gengage_error:t})}var v=null;function et(){if(typeof window>"u")return()=>{};if(v)return v;const e=[];function t(n,r){const i=u=>r(u.detail);window.addEventListener(n,i),e.push(()=>window.removeEventListener(n,i))}return t("gengage:chat:open",()=>C("chat")),t("gengage:chat:close",()=>Ge("chat")),t("gengage:chat:ready",()=>B("chat")),t("gengage:similar:add-to-cart",({sku:n,quantity:r})=>{V(n,r)}),t("gengage:similar:product-click",({sku:n})=>{x(n)}),t("gengage:qna:action",({title:n,type:r})=>{F(n,r)}),t("gengage:chat:voice",()=>Q()),t("gengage:qna:open-chat",()=>C("chat")),t("gengage:global:error",({source:n,message:r})=>{Ze(n,r)}),v=()=>{for(const n of e)n();e.length=0,v=null},v}Object.defineProperty(exports,"BASE_WIDGET_THEME",{enumerable:!0,get:function(){return g}});Object.defineProperty(exports,"BaseWidget",{enumerable:!0,get:function(){return Ue}});Object.defineProperty(exports,"DEFAULT_WIDGET_THEME_TOKENS",{enumerable:!0,get:function(){return E}});Object.defineProperty(exports,"basketAddEvent",{enumerable:!0,get:function(){return ue}});Object.defineProperty(exports,"bootstrapSession",{enumerable:!0,get:function(){return R}});Object.defineProperty(exports,"chatHistorySnapshotEvent",{enumerable:!0,get:function(){return se}});Object.defineProperty(exports,"checkoutCompleteEvent",{enumerable:!0,get:function(){return q}});Object.defineProperty(exports,"checkoutStartEvent",{enumerable:!0,get:function(){return D}});Object.defineProperty(exports,"debugLog",{enumerable:!0,get:function(){return S}});Object.defineProperty(exports,"dismissGlobalErrorToast",{enumerable:!0,get:function(){return z}});Object.defineProperty(exports,"dispatch",{enumerable:!0,get:function(){return be}});Object.defineProperty(exports,"getGlobalErrorMessage",{enumerable:!0,get:function(){return Ie}});Object.defineProperty(exports,"getWindowPageContext",{enumerable:!0,get:function(){return Ee}});Object.defineProperty(exports,"isLikelyConnectivityIssue",{enumerable:!0,get:function(){return $}});Object.defineProperty(exports,"isSafeImageUrl",{enumerable:!0,get:function(){return _e}});Object.defineProperty(exports,"isSafeUrl",{enumerable:!0,get:function(){return T}});Object.defineProperty(exports,"listen",{enumerable:!0,get:function(){return _}});Object.defineProperty(exports,"llmUsageEvent",{enumerable:!0,get:function(){return ie}});Object.defineProperty(exports,"meteringIncrementEvent",{enumerable:!0,get:function(){return oe}});Object.defineProperty(exports,"meteringSummaryEvent",{enumerable:!0,get:function(){return M}});Object.defineProperty(exports,"registerGlobalErrorToastListener",{enumerable:!0,get:function(){return G}});Object.defineProperty(exports,"resolveSession",{enumerable:!0,get:function(){return U}});Object.defineProperty(exports,"safeSetAttribute",{enumerable:!0,get:function(){return me}});Object.defineProperty(exports,"sanitizeHtml",{enumerable:!0,get:function(){return he}});Object.defineProperty(exports,"showGlobalErrorToast",{enumerable:!0,get:function(){return H}});Object.defineProperty(exports,"streamChunkEvent",{enumerable:!0,get:function(){return ee}});Object.defineProperty(exports,"streamDoneEvent",{enumerable:!0,get:function(){return ne}});Object.defineProperty(exports,"streamErrorEvent",{enumerable:!0,get:function(){return re}});Object.defineProperty(exports,"streamStartEvent",{enumerable:!0,get:function(){return Z}});Object.defineProperty(exports,"streamUiSpecEvent",{enumerable:!0,get:function(){return te}});Object.defineProperty(exports,"trackCartAdd",{enumerable:!0,get:function(){return V}});Object.defineProperty(exports,"trackCompareClear",{enumerable:!0,get:function(){return Fe}});Object.defineProperty(exports,"trackComparePreselection",{enumerable:!0,get:function(){return ze}});Object.defineProperty(exports,"trackCompareReceived",{enumerable:!0,get:function(){return xe}});Object.defineProperty(exports,"trackCompareSelected",{enumerable:!0,get:function(){return Be}});Object.defineProperty(exports,"trackConversationStart",{enumerable:!0,get:function(){return Xe}});Object.defineProperty(exports,"trackFindSimilars",{enumerable:!0,get:function(){return He}});Object.defineProperty(exports,"trackInit",{enumerable:!0,get:function(){return B}});Object.defineProperty(exports,"trackLikeList",{enumerable:!0,get:function(){return Qe}});Object.defineProperty(exports,"trackLikeProduct",{enumerable:!0,get:function(){return Ve}});Object.defineProperty(exports,"trackMessageReceived",{enumerable:!0,get:function(){return Ke}});Object.defineProperty(exports,"trackMessageSent",{enumerable:!0,get:function(){return Je}});Object.defineProperty(exports,"trackProductDetail",{enumerable:!0,get:function(){return x}});Object.defineProperty(exports,"trackSearch",{enumerable:!0,get:function(){return Ye}});Object.defineProperty(exports,"trackShow",{enumerable:!0,get:function(){return C}});Object.defineProperty(exports,"trackSuggestedQuestion",{enumerable:!0,get:function(){return F}});Object.defineProperty(exports,"trackVoiceInput",{enumerable:!0,get:function(){return Q}});Object.defineProperty(exports,"updatePageContext",{enumerable:!0,get:function(){return Se}});Object.defineProperty(exports,"widgetHistorySnapshotEvent",{enumerable:!0,get:function(){return ae}});Object.defineProperty(exports,"wireGADataLayer",{enumerable:!0,get:function(){return et}});Object.defineProperty(exports,"wireQNAToChat",{enumerable:!0,get:function(){return we}});Object.defineProperty(exports,"wireSimilarToChat",{enumerable:!0,get:function(){return ke}});Object.defineProperty(exports,"withBaseTheme",{enumerable:!0,get:function(){return Ce}});Object.defineProperty(exports,"withDefaultWidgetTheme",{enumerable:!0,get:function(){return W}});
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./schemas-B7jnyzQI.cjs"),i=require("./ga-datalayer-BVppFxqk.cjs"),n=require("./chat-BOkLnT1i.cjs"),u=require("./connection-warning-YQiIRXrz.cjs"),r=require("./qna-DwG8AJJf.cjs"),c=require("./simrel-DdP4lur9.cjs"),o=require("./simbut-D_ycY_MQ.cjs"),e=require("./native-webview-BePZBK3U.cjs"),t=require("./common-0GWnpStO.cjs");exports.AccountRuntimeConfigSchema=e.AccountRuntimeConfigSchema;exports.AnalyticsAuthModeSchema=e.AnalyticsAuthModeSchema;exports.BASE_WIDGET_THEME=i.BASE_WIDGET_THEME;exports.DEFAULT_CUSTOMIZATION_LOCALE=t.DEFAULT_CUSTOMIZATION_LOCALE;exports.DEFAULT_WIDGET_THEME_TOKENS=i.DEFAULT_WIDGET_THEME_TOKENS;exports.GengageChat=n.GengageChat;exports.GengageQNA=r.GengageQNA;exports.GengageSimBut=o.GengageSimBut;exports.GengageSimRel=c.GengageSimRel;exports.UnknownActionPolicySchema=e.UnknownActionPolicySchema;exports.VoiceInput=n.VoiceInput;exports.applyNativeSession=e.applyNativeSession;exports.autoDetectPageContext=t.autoDetectPageContext;exports.bootstrapSession=i.bootstrapSession;exports.buildChatEndpointUrl=a.buildChatEndpointUrl;exports.buildOverlayIdempotencyKey=e.buildOverlayIdempotencyKey;exports.configureConnectionWarning=u.configureConnectionWarning;exports.consumeStream=a.consumeStream;exports.createAccountIdentity=t.createAccountIdentity;exports.createAnalyticsClient=t.createAnalyticsClient;exports.createChatWidget=n.createChatWidget;exports.createDefaultAccountRuntimeConfig=e.createDefaultAccountRuntimeConfig;exports.createDefaultAnalyticsConfig=t.createDefaultAnalyticsConfig;exports.createDefaultChatUISpecRegistry=n.createDefaultChatUISpecRegistry;exports.createDefaultQnaUISpecRegistry=r.createDefaultQnaUISpecRegistry;exports.createDefaultSimRelUISpecRegistry=c.createDefaultSimRelUISpecRegistry;exports.createFloatingChatConfig=t.createFloatingChatConfig;exports.createNativeWebViewBridge=e.createNativeWebViewBridge;exports.createPdpQnaConfig=t.createPdpQnaConfig;exports.createPdpSimRelConfig=t.createPdpSimRelConfig;exports.createQNAWidget=r.createQNAWidget;exports.createSimButWidget=o.createSimButWidget;exports.createSimRelWidget=c.createSimRelWidget;exports.defaultChatUnknownUISpecRenderer=n.defaultChatUnknownUISpecRenderer;exports.defaultQnaUnknownUISpecRenderer=r.defaultQnaUnknownUISpecRenderer;exports.defaultSimRelUnknownUISpecRenderer=c.defaultSimRelUnknownUISpecRenderer;exports.defaultUnknownUISpecRenderer=a.defaultUnknownUISpecRenderer;exports.destroyOverlayWidgets=e.destroyOverlayWidgets;exports.detectNativeEnvironment=e.detectNativeEnvironment;exports.detectPageType=t.detectPageType;exports.dispatch=i.dispatch;exports.extractSkuFromUrl=t.extractSkuFromUrl;exports.getOverlayWidgets=e.getOverlayWidgets;exports.initGengageClient=t.initGengageClient;exports.initNativeOverlayWidgets=e.initNativeOverlayWidgets;exports.initOverlayWidgets=e.initOverlayWidgets;exports.isVoiceInputSupported=n.isVoiceInputSupported;exports.listen=i.listen;exports.makePillLauncher=n.makePillLauncher;exports.normalizeMiddlewareUrl=a.normalizeMiddlewareUrl;exports.parseAccountRuntimeConfig=e.parseAccountRuntimeConfig;exports.preflightDiagnostics=t.preflightDiagnostics;exports.renderChatUISpec=n.renderUISpec;exports.renderQnaUISpec=r.renderQnaUISpec;exports.renderSimRelUISpec=c.renderSimRelUISpec;exports.renderUISpecWithRegistry=a.renderUISpecWithRegistry;exports.routeStreamAction=n.routeStreamAction;exports.safeParseAccountRuntimeConfig=e.safeParseAccountRuntimeConfig;exports.streamPost=a.streamPost;exports.updatePageContext=i.updatePageContext;exports.wireGADataLayer=i.wireGADataLayer;exports.wireQNAToChat=i.wireQNAToChat;exports.wireSimilarToChat=i.wireSimilarToChat;exports.withBaseTheme=i.withBaseTheme;exports.withDefaultWidgetTheme=i.withDefaultWidgetTheme;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const a=require("./schemas-B7jnyzQI.cjs"),m=require("./ga-datalayer-BVppFxqk.cjs"),K=require("./chat-BOkLnT1i.cjs"),$=require("./qna-DwG8AJJf.cjs"),G=require("./simrel-DdP4lur9.cjs"),Y=require("./simbut-D_ycY_MQ.cjs");var b=a.object({enabled:a.boolean().default(!0)}),J=a.object({chat:a.string().optional(),qna:a.string().optional(),simrel:a.string().optional(),simbut:a.string().optional()}),X=a.object({}),k=a._enum(["none","x-api-key-header","bearer-header","body-api-key"]),z=a.object({mode:k.default("none"),key:a.string().optional(),headerName:a.string().optional(),bodyField:a.string().default("api_key")}),Z=a.object({enabled:a.boolean().default(!0),endpoint:a.string().default("/analytics"),auth:z.default({mode:"none",bodyField:"api_key"}),fireAndForget:a.boolean().default(!0),useBeacon:a.boolean().default(!0),keepaliveFetch:a.boolean().default(!0),timeoutMs:a.number().int().positive().default(4e3),maxRetries:a.number().int().min(0).max(5).default(1)}),U="__gengageWidgetsInit",ee=a.object({idempotencyKey:a.string().default(U),requireDomReady:a.boolean().default(!0)}),O=a._enum(["log-and-ignore","throw","delegate"]),te=a.object({unknownActionPolicy:O.default("log-and-ignore"),allowScriptCall:a.boolean().default(!1)}),N=a.object({version:a.literal("1",{error:'version must be "1"'}),accountId:a.string({error:"accountId must be a non-empty string"}).min(1,{error:"accountId must be a non-empty string"}),middlewareUrl:a.string({error:'middlewareUrl must be a valid URL (e.g. "https://your-backend.example.com")'}).url({error:'middlewareUrl must be a valid URL (e.g. "https://your-backend.example.com")'}),locale:a.string().optional(),widgets:a.object({chat:b.default({enabled:!0}),qna:b.default({enabled:!0}),simrel:b.default({enabled:!0}),simbut:b.default({enabled:!1})}),mounts:J.default({}),transport:X.default({}),analytics:Z.default({enabled:!0,endpoint:"/analytics",auth:{mode:"none",bodyField:"api_key"},fireAndForget:!0,useBeacon:!0,keepaliveFetch:!0,timeoutMs:4e3,maxRetries:1}),gtm:ee.default({idempotencyKey:"__gengageWidgetsInit",requireDomReady:!0}),actionHandling:te.default({unknownActionPolicy:"log-and-ignore",allowScriptCall:!1})});function P(e){m.debugLog("config","parsing account runtime config",e);const t=N.parse(e);return m.debugLog("config","config resolved",{accountId:t.accountId,middlewareUrl:t.middlewareUrl}),t}function ie(e){return N.safeParse(e)}function ne(e){return P({version:"1",accountId:e.accountId,middlewareUrl:e.middlewareUrl,locale:e.locale,widgets:{chat:{enabled:!0},qna:{enabled:!0},simrel:{enabled:!0},simbut:{enabled:!1}}})}var x=`${U}_overlay_`,se="#gengage-qna",oe="#gengage-simrel",ae="#gengage-simbut";function q(){const e=window;return e.__gengageOverlayRegistry||(e.__gengageOverlayRegistry={instances:{},pending:{}}),e.__gengageOverlayRegistry}function re(e){const t={pageType:e.pageContext?.pageType??(e.sku!==void 0?"pdp":"other")},i=e.pageContext;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}function de(e,t){const i={...e,...t,pageType:t.pageType??e.pageType};return t.sku===void 0&&e.sku!==void 0&&(i.sku=e.sku),i}function T(e){return e instanceof HTMLElement||document.querySelector(e)?e:null}function R(e){return e.idempotencyKey??`${x}${e.accountId}`}var ue=class{constructor(e,t){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=R(e),this.session=m.resolveSession(e.session),this._pageContext=re(e)}get chat(){return this._chat}get qna(){return this._qna}get simrel(){return this._simrel}get simbut(){return this._simbut}get analyticsClient(){return this._analyticsClient}async init(){window.gengage||(window.gengage={}),window.gengage.sessionId=this.session.sessionId,window.gengage.pageContext=this._pageContext,await this._initChat(),this.options.wireQnaToChat!==!1&&(this._offQnaWire=m.wireQNAToChat()),await this._syncPdpWidgets(),window.gengage.overlay=this}openChat(e){this._chat?.open(e)}closeChat(){this._chat?.close()}async updateContext(e){this._destroyed||await this._enqueue(async()=>{this._pageContext=de(this._pageContext,e),window.gengage||(window.gengage={}),window.gengage.pageContext=this._pageContext,this._chat?.update(e),this._qna?.update(e),this._simrel?.update(e),this._simbut?.update(e),await this._syncPdpWidgets()})}async updateSku(e,t="pdp"){await this.updateContext({sku:e,pageType:t})}destroy(){this._destroyed||(this._destroyed=!0,this._offQnaWire?.(),this._offQnaWire=null,this._chat?.destroy(),this._qna?.destroy(),this._simrel?.destroy(),this._simbut?.destroy(),this._chat=null,this._qna=null,this._simrel=null,this._simbut=null,window.gengage?.overlay===this&&delete window.gengage.overlay,this.onDestroy())}async _initChat(){if(this.options.chat?.enabled===!1)return;const e=this.options.middlewareUrl,t=this.options.chat?.productDetailsExtended??this.options.productDetailsExtended,i=this.options.chat?.isDemoWebsite??this.options.isDemoWebsite,s={accountId:this.options.accountId,middlewareUrl:e,session:this.session,pageContext:this._pageContext,variant:this.options.chat?.variant??"floating"};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.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 K.GengageChat,await this._chat.init(s)}async _syncPdpWidgets(){if(this._destroyed)return;const e=this._pageContext.sku;if(!(this._pageContext.pageType==="pdp"&&e!==void 0&&e.length>0)){this._qna?.hide(),this._simrel?.hide(),this._simbut?.hide();return}const t=this.options.middlewareUrl;if(this.options.qna?.enabled!==!1){const i=this.options.qna?.mountTarget??se,s=T(i);if(s)if(this._warnedQnaMountMissing=!1,this._qna)this._qna.show(),this._qna.update({pageType:"pdp",sku:e});else{const o=new $.GengageQNA,n={accountId:this.options.accountId,middlewareUrl:t,session:this.session,pageContext:{pageType:"pdp",sku:e},mountTarget:s};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);const u=this.options.qna?.headerTitle??this.options.qna?.headingTitle;u!==void 0&&(n.headerTitle=u),await o.init(n),this._qna=o}else this._qna?.destroy(),this._qna=null,this._warnedQnaMountMissing||(console.warn(`[gengage] QNA mount target not found: ${i}`),this._warnedQnaMountMissing=!0)}else this._qna?.destroy(),this._qna=null;if(this.options.simrel?.enabled!==!1){const i=this.options.simrel?.mountTarget??oe,s=T(i);if(s)if(this._warnedSimRelMountMissing=!1,this._simrel)this._simrel.show(),this._simrel.update({pageType:"pdp",sku:e});else{const o=new G.GengageSimRel,n={accountId:this.options.accountId,middlewareUrl:t,session:this.session,sku:e,mountTarget:s};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=(u,g,r)=>{m.isSafeUrl(u)&&(this._chat?.saveSession(r??this.session.sessionId,g),window.location.href=u)},await o.init(n),this._simrel=o}else this._simrel?.destroy(),this._simrel=null,this._warnedSimRelMountMissing||(console.warn(`[gengage] SimRel mount target not found: ${i}`),this._warnedSimRelMountMissing=!0)}else this._simrel?.destroy(),this._simrel=null;if(this.options.simbut&&this.options.simbut.enabled!==!1){const i=this.options.simbut.mountTarget??ae,s=T(i),o=this._chat??this.options.simbut.onFindSimilar;if(s&&o)if(this._warnedSimButMountMissing=!1,this._warnedSimButNoChat=!1,this._simbut)this._simbut.show(),this._simbut.setChat(this._chat),this._simbut.update({pageType:"pdp",sku:e});else{const n=new Y.GengageSimBut,u={accountId:this.options.accountId,middlewareUrl:t,session:this.session,pageContext:{pageType:"pdp",sku:e},mountTarget:s,chat:this._chat};this.options.theme!==void 0&&(u.theme=this.options.theme),this.options.locale!==void 0&&(u.locale=this.options.locale),this.options.simbut.imageUrl!==void 0&&(u.imageUrl=this.options.simbut.imageUrl),this.options.simbut.i18n!==void 0&&(u.i18n=this.options.simbut.i18n),this.options.simbut.onFindSimilar!==void 0&&(u.onFindSimilar=this.options.simbut.onFindSimilar),await n.init(u),this._simbut=n}else 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)}else this._simbut?.destroy(),this._simbut=null}_enqueue(e){const t=this._queue.then(e);return this._queue=t.catch(i=>{}),t}};async function B(e){const t=R(e),i=q(),s=i.instances[t];if(s)return s;const o=i.pending[t];if(o)return o;const n=new ue(e,()=>{const g=q();delete g.instances[t],delete g.pending[t]}),u=n.init().then(()=>(i.instances[t]=n,delete i.pending[t],n)).catch(g=>{throw delete i.pending[t],g});return i.pending[t]=u,u}function W(e){return q().instances[e]??null}function le(e){W(e)?.destroy()}function ce(e){return`${x}${e}`}var j=["gengage:chat:open","gengage:chat:close","gengage:chat:ready","gengage:chat:add-to-cart","gengage:qna:action","gengage:qna:open-chat","gengage:similar:product-click","gengage:similar:add-to-cart","gengage:global:error","gengage:context:update"],ge=32,M="#gengage-qna",A="#gengage-simrel";function he(e){let t=e;if(typeof e=="string"){const n=e.trim();if(n.length===0)return null;if(!n.startsWith("{")&&!n.startsWith("["))return{type:n};try{t=JSON.parse(n)}catch{return null}}if(!t||typeof t!="object")return null;const i=t,s=[i.type,i.command,i.action,i.event].find(n=>typeof n=="string"&&n.length>0);if(!s)return null;let o=i.payload;if(o===void 0&&"data"in i&&(o=i.data),s==="setSession"&&o===void 0){const n={};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)}return o===void 0?{type:s}:{type:s,payload:o}}function fe(e){if(typeof e=="string"&&e.length>0)return{sku:e};if(e&&typeof e=="object"&&"sku"in e){const t=e.sku;if(typeof t=="string"&&t.length>0){const i=e.pageType;return i!==void 0?{sku:t,pageType:i}:{sku:t}}}return null}function I(e,t){return t instanceof HTMLElement?!0:typeof t!="string"?!1:e.document.querySelector(t)!==null}function E(e,t,i){if(t instanceof HTMLElement||I(e,t)||typeof t!="string")return t;if(t.startsWith("#")){const n=t.slice(1);if(n.length>0){const u=e.document.getElementById(n);if(u)return u;const g=e.document.createElement("div");return g.id=n,e.document.body.appendChild(g),g}}const s=e.document.getElementById(i);if(s)return s;const o=e.document.createElement("div");return o.id=i,e.document.body.appendChild(o),o}function L(e,t){const i=e.webkit?.messageHandlers?.[t];return i&&typeof i.postMessage=="function"?i.postMessage.bind(i):null}function _(e,t){const i=e[t];return i&&typeof i=="object"&&typeof i.postMessage=="function"?i:null}function D(e={}){const t=e.win??window,i=e.iosHandlerName??"gengage",s=e.androidInterfaceName??"GengageNative",o=e.reactNativeInterfaceName??"ReactNativeWebView";return L(t,i)?"ios":_(t,s)?"android":_(t,o)?"react-native":"browser"}function F(e,t={}){const i=t.win??window;if(e.sessionId!==void 0){i.__gengageSessionId=e.sessionId,i.gengage||(i.gengage={}),i.gengage.sessionId=e.sessionId;try{i.sessionStorage.setItem("gengage_session_id",e.sessionId)}catch{}}if(e.userId!==void 0){i.gengage||(i.gengage={});const s=i.gengage,o=s.session??{};o.userId=e.userId,s.session=o}}function H(e={}){const t=e.win??window,i=t;if(i.gengageNative)return i.gengageNative;const s=e.iosHandlerName??"gengage",o=e.androidInterfaceName??"GengageNative",n=e.reactNativeInterfaceName??"ReactNativeWebView",u=e.trackedEvents??[...j],g=D({win:t,iosHandlerName:s,androidInterfaceName:o,reactNativeInterfaceName:n});let r=t.gengage?.overlay??null;const c=[],p=(l,d)=>{const f=d===void 0?{type:l}:{type:l,payload:d};if(g==="ios"){L(t,s)?.(f);return}if(g==="android"){_(t,o)?.postMessage(JSON.stringify(f));return}if(g==="react-native"){_(t,n)?.postMessage(JSON.stringify(f));return}},v=l=>{const d=l.detail;!d||typeof d.namespace!="string"||typeof d.type!="string"||p("bridge_message",{namespace:d.namespace,type:d.type,payload:d.payload})};t.addEventListener("gengage:bridge:message",v);const Q=u.map(l=>{const d=f=>{const h=f.detail;p("widget_event",{event:l,detail:h})};return t.addEventListener(l,d),{event:l,handler:d}}),y=l=>{c.length>=ge&&c.shift(),c.push(l)},V=()=>{if(!r||c.length===0)return;const l=c.splice(0,c.length);for(const d of l)S(d)},S=l=>{const d=he(l);if(!d||typeof d.type!="string"){console.warn("[gengage:native-bridge] Invalid message:",l);return}const f=d.type,h=d.payload;switch(f){case"openChat":r?r.openChat(h&&typeof h=="object"?h:h==="half"||h==="full"?{state:h}:void 0):y(d);return;case"closeChat":r?r.closeChat():y(d);return;case"updateContext":r&&h&&typeof h=="object"?r.updateContext(h):r?console.warn("[gengage:native-bridge] updateContext: missing payload"):y(d);return;case"updateSku":{const C=fe(h);if(r&&C){r.updateSku(C.sku,C.pageType);return}r?console.warn("[gengage:native-bridge] updateSku: missing sku"):y(d);return}case"setSession":h&&typeof h=="object"&&F(h,{win:t});return;case"destroy":r?.destroy();return;default:t.postMessage({gengage:"native",type:f,payload:h},t.location.origin),e.logUnhandled&&console.warn("[gengage:native-bridge] Unhandled inbound type forwarded:",f)}},w={env:g,sendToNative:p,receive:S,setController(l){r=l,V()},destroy(){t.removeEventListener("gengage:bridge:message",v);for(const l of Q)t.removeEventListener(l.event,l.handler);c.splice(0,c.length),t.gengageNative===w&&delete t.gengageNative}};return i.gengageNative=w,w}async function pe(e){const{nativeBridge:t,emitReadyEvent:i=!0,...s}=e,o=H(t),n={...s};n.onAddToCart||(n.onAddToCart=c=>{o.sendToNative("addToCart",{sku:c.sku,quantity:c.quantity,cartCode:c.cartCode})}),n.onProductNavigate||(n.onProductNavigate=(c,p,v)=>{o.sendToNative("productNavigate",{url:c,sku:p,sessionId:v})});const u=n.qna?.enabled===!0||n.qna?.mountTarget!==void 0;if(n.qna?.enabled!==!1)if(u){const c=E(window,n.qna?.mountTarget??M,"gengage-qna");n.qna={...n.qna,enabled:!0,mountTarget:c}}else I(window,M)||(n.qna={enabled:!1});const g=n.simrel?.enabled===!0||n.simrel?.mountTarget!==void 0;if(n.simrel?.enabled!==!1)if(g){const c=E(window,n.simrel?.mountTarget??A,"gengage-simrel");n.simrel={...n.simrel,enabled:!0,mountTarget:c}}else I(window,A)||(n.simrel={enabled:!1});const r=await B(n);return o.setController(r),i&&o.sendToNative("ready",{sessionId:r.session.sessionId,widgets:{chat:r.chat!==null,qna:r.qna!==null,simrel:r.simrel!==null}}),{controller:r,bridge:o,destroy(){r.destroy(),o.destroy()}}}Object.defineProperty(exports,"AccountRuntimeConfigSchema",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"AnalyticsAuthModeSchema",{enumerable:!0,get:function(){return k}});Object.defineProperty(exports,"DEFAULT_NATIVE_TRACKED_EVENTS",{enumerable:!0,get:function(){return j}});Object.defineProperty(exports,"UnknownActionPolicySchema",{enumerable:!0,get:function(){return O}});Object.defineProperty(exports,"applyNativeSession",{enumerable:!0,get:function(){return F}});Object.defineProperty(exports,"buildOverlayIdempotencyKey",{enumerable:!0,get:function(){return ce}});Object.defineProperty(exports,"createDefaultAccountRuntimeConfig",{enumerable:!0,get:function(){return ne}});Object.defineProperty(exports,"createNativeWebViewBridge",{enumerable:!0,get:function(){return H}});Object.defineProperty(exports,"destroyOverlayWidgets",{enumerable:!0,get:function(){return le}});Object.defineProperty(exports,"detectNativeEnvironment",{enumerable:!0,get:function(){return D}});Object.defineProperty(exports,"getOverlayWidgets",{enumerable:!0,get:function(){return W}});Object.defineProperty(exports,"initNativeOverlayWidgets",{enumerable:!0,get:function(){return pe}});Object.defineProperty(exports,"initOverlayWidgets",{enumerable:!0,get:function(){return B}});Object.defineProperty(exports,"parseAccountRuntimeConfig",{enumerable:!0,get:function(){return P}});Object.defineProperty(exports,"safeParseAccountRuntimeConfig",{enumerable:!0,get:function(){return ie}});
|
package/dist/native.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./native-webview-BePZBK3U.cjs");exports.DEFAULT_NATIVE_TRACKED_EVENTS=e.DEFAULT_NATIVE_TRACKED_EVENTS;exports.applyNativeSession=e.applyNativeSession;exports.createNativeWebViewBridge=e.createNativeWebViewBridge;exports.detectNativeEnvironment=e.detectNativeEnvironment;exports.initNativeOverlayWidgets=e.initNativeOverlayWidgets;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var m={currencyCode:"TRY",currencySymbol:"TL",currencyPosition:"suffix",thousandsSeparator:".",decimalSeparator:",",alwaysShowDecimals:!1};function f(e,o){const r=Number(e);if(!Number.isFinite(r)||r<0)return e;const n={...m,...o},i=Math.abs(r%1)<Number.EPSILON,t=n.alwaysShowDecimals||!i?r.toFixed(2):r.toFixed(0),a=t.indexOf("."),u=a===-1?t:t.slice(0,a),s=a===-1?void 0:t.slice(a+1),l=u.replace(/\B(?=(\d{3})+(?!\d))/g,n.thousandsSeparator);let c;return s!==void 0?c=`${l}${n.decimalSeparator}${s}`:c=l,n.currencySymbol?n.currencyPosition==="prefix"?`${n.currencySymbol}${c}`:`${c} ${n.currencySymbol}`:c}function d(e){return Number.isFinite(e)?Math.max(0,Math.min(5,e)):0}function p(e){return Number.isFinite(e)?Math.max(0,Math.min(100,Math.round(e))):0}function b(e){const o=d(e),r=Math.floor(o),n=o-r>=.5,i=5-r-(n?1:0),t=document.createElement("span");if(t.className="gengage-star-rating",t.setAttribute("role","img"),t.setAttribute("aria-label",`${o.toFixed(1)} out of 5 stars`),r>0&&t.appendChild(document.createTextNode("★".repeat(r))),n){const a=document.createElement("span");a.className="gengage-star-half",a.textContent="☆";const u=document.createElement("span");u.textContent="★",a.appendChild(u),t.appendChild(a)}return i>0&&t.appendChild(document.createTextNode("☆".repeat(i))),t}function y(e){e.addEventListener("error",()=>{e.style.display="none"},{once:!0})}Object.defineProperty(exports,"addImageErrorHandler",{enumerable:!0,get:function(){return y}});Object.defineProperty(exports,"clampDiscount",{enumerable:!0,get:function(){return p}});Object.defineProperty(exports,"clampRating",{enumerable:!0,get:function(){return d}});Object.defineProperty(exports,"createStarRatingElement",{enumerable:!0,get:function(){return b}});Object.defineProperty(exports,"formatPrice",{enumerable:!0,get:function(){return f}});
|
package/dist/qna-DwG8AJJf.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const u=require("./schemas-B7jnyzQI.cjs"),y=require("./ga-datalayer-BVppFxqk.cjs"),O=require("./connection-warning-YQiIRXrz.cjs");async function H(t,n,e){const o=u.buildChatEndpointUrl("launcher_action",n),i={uiSpecs:[],actions:[]},a={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)};e!==void 0&&(a.signal=e);const r=await fetch(o,a);if(!r.ok)throw new Error(`HTTP ${r.status}: ${r.statusText}`);const s={onEvent:c=>{const l=u.adaptBackendEvent(c);if(l&&(l.type==="ui_spec"&&i.uiSpecs.push(l.spec),l.type==="ui_spec"&&l.spec.elements)){for(const d of Object.values(l.spec.elements))if(d.type==="ActionButton"&&d.props?.action){const _=d.props.action;i.actions.push(_)}}}};return e!==void 0&&(s.signal=e),await u.consumeStream(r,s),i}function C(t){const n=document.createElement("div");n.className="gengage-qna-buttons gds-toolbar",n.dataset.gengagePart="qna-button-row",n.setAttribute("role","group"),n.setAttribute("aria-label",t.quickQuestionsAriaLabel??"Quick questions"),t.orientation==="vertical"&&(n.style.flexDirection="column");for(const e of t.actions){const o=document.createElement("button");o.className="gengage-qna-button gds-chip",o.dataset.gengagePart="qna-quick-question",o.textContent=e.title,o.type="button",o.addEventListener("click",()=>{const i={title:e.title,type:e.type};e.payload!==void 0&&(i.payload=e.payload),t.onAction(i)}),n.appendChild(o)}if(t.ctaText||t.onOpenChat){const e=document.createElement("button");e.className="gengage-qna-cta gds-btn gds-btn-secondary",e.dataset.gengagePart="qna-cta",e.textContent=t.ctaText??t.defaultCtaText??"Ask something else",e.type="button",e.addEventListener("click",()=>{t.onOpenChat?.()}),n.appendChild(e)}return n}function U(t){const n=document.createElement("div");n.className="gengage-qna-input-wrapper",n.dataset.gengagePart="qna-input-wrapper";const e=document.createElement("div");e.className="gengage-qna-input-combo",e.dataset.gengagePart="qna-input-combo";const o=document.createElement("input");o.type="text",o.className="gengage-qna-input",o.dataset.gengagePart="qna-input",o.setAttribute("aria-label",t.askQuestionAriaLabel??"Ask a question");const i=Array.isArray(t.placeholders)?t.placeholders:t.placeholders?[t.placeholders]:[t.defaultInputPlaceholder??"Ask a question..."];let a=0,r=i[0]??"";o.placeholder=r;let s=null,c=null,l=!1;const d=()=>{s&&clearInterval(s),s=null,c&&clearTimeout(c),c=null,o.classList.remove("gengage-qna-input--fade")},_=()=>i.length>1&&!l&&o.value.trim().length===0,b=()=>{d(),_()&&(s=setInterval(()=>{_()&&(o.classList.add("gengage-qna-input--fade"),c=setTimeout(()=>{a=(a+1)%i.length,r=i[a]??"",o.placeholder=r,o.classList.remove("gengage-qna-input--fade")},180))},3e3))},f=document.createElement("div");f.className="gengage-qna-input-actions",f.dataset.gengagePart="qna-input-actions";const g=document.createElement("button");g.className="gengage-qna-icon-btn gengage-qna-clear gengage-qna-icon-btn--hidden",g.type="button",g.dataset.gengagePart="qna-clear",g.setAttribute("aria-label","Clear question"),g.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6L6 18" /><path d="M6 6L18 18" /></svg>';const h=document.createElement("button");h.className="gengage-qna-icon-btn gengage-qna-send gengage-qna-icon-btn--hidden",h.type="button",h.dataset.gengagePart="qna-send",h.setAttribute("aria-label",t.sendQuestionAriaLabel??"Send question"),h.disabled=!0,h.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M22 2L11 13" /><path d="M22 2L15 22L11 13L2 9L22 2Z" /></svg><span class="gengage-qna-sr-only">${t.ctaLabel??t.sendButtonText??"Ask"}</span>`;const v=()=>{const p=o.value.trim().length>0;g.classList.toggle("gengage-qna-icon-btn--hidden",!p),h.classList.toggle("gengage-qna-icon-btn--hidden",!p),h.classList.toggle("gengage-qna-send--active",p),h.disabled=!p},q=()=>{const p=o.value.trim();p&&(t.onSubmit({title:p,type:"user_message",payload:p}),o.value="",v(),b())};return g.addEventListener("click",()=>{o.value="",v(),o.focus({preventScroll:!0})}),h.addEventListener("click",q),o.addEventListener("focus",()=>{l=!0,d(),o.placeholder=""}),o.addEventListener("blur",()=>{l=!1,o.value.trim().length===0&&(o.placeholder=r),b()}),o.addEventListener("input",()=>{if(v(),o.value.trim().length>0){d();return}o.placeholder=l?"":r,b()}),o.addEventListener("keydown",p=>{p.key==="Enter"&&(p.preventDefault(),q()),p.key==="Escape"&&o.value.length>0&&(o.value="",v(),b())}),f.appendChild(g),f.appendChild(h),e.appendChild(o),e.appendChild(f),n.appendChild(e),v(),b(),n._cleanup=()=>{d()},n}function T(t,n){if(!t||typeof t!="object")return null;const e=t,o=e.type;if(typeof o!="string"||o.length===0)return null;const i=e.title,a=e.payload,r=typeof i=="string"&&i.length>0?i:n;if(!r)return null;const s={title:r,type:o};return a!==void 0&&(s.payload=a),s}function S(t){const n={title:t.title,type:t.type};return t.payload!==void 0&&(n.payload=t.payload),n}function k(t,n){const e=[],o=t.props?.actions;if(Array.isArray(o))for(const r of o){const s=T(r);s&&e.push(s)}const i=t.props?.buttons;if(Array.isArray(i))for(const r of i){if(!r||typeof r!="object")continue;const s=r,c=typeof s.label=="string"?s.label:void 0,l=T(s.action,c);l&&e.push(l)}if(t.children)for(const r of t.children){const s=n.elements[r];if(!s||s.type!=="ActionButton")continue;const c=typeof s.props?.label=="string"?s.props.label:void 0,l=T(s.props?.action,c);l&&e.push(l)}const a=new Set;return e.filter(r=>a.has(r.title)?!1:(a.add(r.title),!0))}var L={ButtonRow:({element:t,spec:n,context:e})=>{const o=k(t,n).map(S),i=t.props?.orientation,a={actions:o,onAction:e.onAction,defaultCtaText:e.i18n.defaultCtaText,quickQuestionsAriaLabel:e.i18n.quickQuestionsAriaLabel};return e.onOpenChat!==void 0&&(a.onOpenChat=e.onOpenChat),e.ctaText!==void 0&&(a.ctaText=e.ctaText),(i==="horizontal"||i==="vertical")&&(a.orientation=i),C(a)},ActionButtons:({element:t,spec:n,context:e})=>{const o={actions:k(t,n).map(S),onAction:e.onAction,defaultCtaText:e.i18n.defaultCtaText,quickQuestionsAriaLabel:e.i18n.quickQuestionsAriaLabel};return e.onOpenChat!==void 0&&(o.onOpenChat=e.onOpenChat),e.ctaText!==void 0&&(o.ctaText=e.ctaText),C(o)},ActionButton:({element:t,context:n})=>{const e=document.createElement("button");e.className="gengage-qna-button gds-chip",e.type="button",e.dataset.gengagePart="qna-action-button";const o=t.props?.label;typeof o=="string"?e.textContent=o:e.textContent=n.i18n.defaultCtaText;const i=T(t.props?.action,typeof o=="string"?o:void 0);return i&&e.addEventListener("click",()=>n.onAction(i)),e},TextInput:({element:t,context:n})=>{const e=t.props?.placeholder,o=typeof e=="string"||Array.isArray(e)?e:n.inputPlaceholder,i=typeof t.props?.ctaLabel=="string"?t.props.ctaLabel:void 0,a={onSubmit:n.onAction,askQuestionAriaLabel:n.i18n.askQuestionAriaLabel,defaultInputPlaceholder:n.i18n.defaultInputPlaceholder,sendButtonText:n.i18n.sendButton,sendQuestionAriaLabel:n.i18n.sendQuestionAriaLabel};return o!==void 0&&(a.placeholders=o),i!==void 0&&(a.ctaLabel=i),U(a)},QuestionHeading:({element:t,context:n})=>{const e=document.createElement("h3");e.className="gengage-qna-heading",e.dataset.gengagePart="qna-heading";const o=t.props?.text,i=n.headingTitleOverride;return e.textContent=typeof i=="string"&&i.trim().length>0?i:typeof o=="string"?o:"",e},ProductCard:()=>null},E=({element:t,renderElement:n})=>{if(!t.children||t.children.length===0)return null;const e=document.createElement("div");for(const o of t.children){const i=n(o);i&&e.appendChild(i)}return e};function P(){return{...L}}function Q(t,n,e=L,o=E){return u.renderUISpecWithRegistry({spec:t,context:n,registry:e,containerClassName:"gengage-qna-uispec",unknownRenderer:o})}function j(t){if(!t)return;const n=t.extra;if(n&&typeof n=="object"&&!Array.isArray(n)){const o=n.visible_skus??n.visibleSkus;if(Array.isArray(o)){const i=o.filter(a=>typeof a=="string"&&a.trim().length>0).map(a=>a.trim()).slice(0,200);if(i.length>0)return i}}const e=typeof t.sku=="string"&&t.sku.trim()?t.sku.trim():void 0;return e?[e]:void 0}function B(t,n){if(!t)return null;const e=t.action;if(!e||typeof e!="object")return null;const o=e,i=o.type;if(typeof i!="string"||i.length===0)return null;const a=o.title,r=typeof a=="string"&&a.length>0?a:typeof n=="string"&&n.length>0?n:"";if(!r)return null;const s=o.payload,c={title:r,type:i};return s!==void 0&&(c.payload=s),c}function M(t,n){const e=t.elements[t.root];if(!e)return!1;const o=i=>{if(i.type!=="ActionButton")return!1;const a=i.props;if(!a||typeof a!="object")return!1;const r=typeof a.label=="string"?a.label:void 0;return r===n?!0:B(a,r)?.title===n};if(e.type==="ActionButton")return o(e);if(e.children)for(const i of e.children){const a=t.elements[i];if(a&&o(a))return!0}if(e.type==="ActionButtons"&&Array.isArray(e.props?.buttons)){for(const i of e.props.buttons)if(i?.label===n||i?.action?.title===n)return!0}return!1}var I=0;function x(){return I+=1,`gengage-merge-${I}`}function D(t,n){const e=t.elements[t.root];if(!e||e.type!=="ButtonRow")return;const o=x();t.elements[o]={type:"ActionButton",props:{label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}}},e.children=e.children?[o,...e.children]:[o]}function F(t,n){const e=t.elements[t.root];if(!e||e.type!=="ActionButtons")return;const o=x();t.elements[o]={type:"ActionButton",props:{label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}}},e.children=e.children?[o,...e.children]:[o];const i=e.props?.buttons??[],a={label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}};e.props={...e.props,buttons:[a,...i]}}function W(t){const n={},e=[];for(let o=0;o<t.length;o++){const i=t[o],a=`action-${o}`;e.push(a),n[a]={type:"ActionButton",props:{label:i.title,action:{title:i.title,type:i.type,...i.payload!==void 0?{payload:i.payload}:{}}}}}return n.root={type:"ButtonRow",children:e},{root:"root",elements:n}}function z(t){return t.find(n=>{const e=n.elements[n.root];return e?.type==="ActionButtons"||e?.type==="ButtonRow"})}function w(t,n){const e=t.productContextQuickPillLabel,o={text:e};return n&&n.length>0&&(o.sku_list=n),{title:e,type:"user_message",payload:o}}function $(t,n,e){const o=e?.skuList,i=[],a=[];for(const c of t){const l=c.elements[c.root];if(l?.type==="ActionButton"){const d=l.props;if(B(d,typeof d?.label=="string"?d.label:void 0)?.type==="findSimilar"){i.push(w(n,o));continue}}a.push(c)}if(i.length===0)return t;const r=w(n,o),s=z(a);if(!s)return[...a,W([r])];if(!M(s,r.title)){const c=s.elements[s.root];c?.type==="ActionButtons"?F(s,r):c?.type==="ButtonRow"&&D(s,r)}return a}var R={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor",redirectingToChat:"Sohbete yönlendiriliyor...",productContextQuickPillLabel:"Bu ürün hakkında ne bilmeliyim?"},G={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else",redirectingToChat:"Redirecting to chat...",productContextQuickPillLabel:"What should I know about this product?"};function J(t){return t?t.toLowerCase().split("-")[0]??"tr":"tr"}function V(t){return J(t)==="en"?G:R}var Y=u.object({title:u.string(),type:u.string(),payload:u.unknown().optional()}),Z=u.object({label:u.string(),action:Y,variant:u._enum(["primary","outline","ghost"]).optional()}),K=u.object({orientation:u._enum(["horizontal","vertical"]).optional(),wrap:u.boolean().optional()}),X=u.object({placeholder:u.union([u.string(),u.array(u.string())]).optional(),ctaLabel:u.string().optional()}),tt=u.object({text:u.string()}),et={components:{ActionButton:{schema:Z,description:"A single clickable QNA action button."},ButtonRow:{schema:K,description:"Container for a group of QNA action buttons."},TextInput:{schema:X,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:tt,description:"A heading displayed above the QNA button group."}}},N=class extends y.BaseWidget{constructor(...t){super(...t),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=R,this._actionHandler=this._handleAction.bind(this),this._openChatHandler=this._handleOpenChat.bind(this)}async onInit(t){this._i18n=this._resolveI18n(t),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-qna-container",this._contentEl.dataset.gengagePart="qna-container",this.root.appendChild(this._contentEl);const n=t.pageContext?.sku;n&&(this._lastSku=n,await this._fetchAndRender(n)),y.trackInit("qna")}onUpdate(t){const n=t.sku;!n||n===this._lastSku||(this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=null,this._lastSku=n,this._fetchAndRender(n)},50))}onShow(){this._contentEl&&(this._contentEl.style.opacity="0",this._contentEl.style.transition="opacity 0.2s ease-in",requestAnimationFrame(()=>{this._contentEl&&(this._contentEl.style.opacity="1")}))}onHide(){}onDestroy(){this._abort(),this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=null),this._contentEl&&(this._cleanupTextInputTimers(),this._contentEl.remove(),this._contentEl=null)}_abort(){this._abortController?.abort(),this._abortController=null}_resolvedQnaHeaderTitle(){const t=this.config.headerTitle??this.config.headingTitle;if(typeof t!="string")return;const n=t.trim();return n.length>0?n:void 0}_cleanupTextInputTimers(){if(!this._contentEl)return;const t=this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");for(const n of t)n._cleanup?.()}async _fetchAndRender(t){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const n=this._createLoadingIndicator();this._contentEl.appendChild(n);const e={middlewareUrl:this.config.middlewareUrl},o=crypto.randomUUID(),i=Date.now(),a=O.trackConnectionWarningRequest({source:"qna",locale:this.config.locale});this.track(y.streamStartEvent(this.analyticsContext(),{endpoint:"launcher_action",request_id:o,widget:"qna"}));try{const r={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:t,locale:this.config.locale??"tr"},s=this.config.pageContext?.pageType;s!==void 0&&(r.page_type=s);const c=await H(r,e,this._abortController.signal);if(this.track(y.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-i,chunk_count:c.actions.length,widget:"qna"})),this.track(y.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:c.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;this._contentEl.innerHTML="";const l=document.createElement("div");l.className="gengage-qna-panel gds-panel",l.dataset.gengagePart="qna-panel",this._contentEl.appendChild(l);const d=this._specIncludesType(c.uiSpecs,"QuestionHeading"),_=this._resolvedQnaHeaderTitle()??(this.config.showStaticQuestion&&this.config.staticQuestionText?this.config.staticQuestionText:void 0);if(!d&&_){const m=document.createElement("h3");m.className="gengage-qna-heading",m.textContent=_,l.appendChild(m)}const b=this.config.inputPlaceholder;let f;if(b!==!0)f=b??this._i18n.defaultInputPlaceholder;else if(c.actions.length>0){const m=c.actions.filter(A=>A.type==="user_message"||A.title.includes("?")).map(A=>A.title);f=m.length>0?m:this._i18n.defaultInputPlaceholder}else f=this._i18n.defaultInputPlaceholder;const g={onAction:this._actionHandler,i18n:this._i18n},h=this._resolvedQnaHeaderTitle();h!==void 0&&(g.headingTitleOverride=h),this.config.hideButtonRowCta||(g.onOpenChat=this._openChatHandler,this.config.ctaText!==void 0&&(g.ctaText=this.config.ctaText)),f!==void 0&&(g.inputPlaceholder=f);const v=this._buildFallbackActionsSpec(c.actions),q=j(this.config.pageContext),p=(c.uiSpecs.length>0?$(c.uiSpecs,this._i18n,{skuList:q}):[v]).filter(m=>Object.keys(m.elements).length>0);for(const m of p){const A=this._renderUISpec(m,g);l.appendChild(A)}p.length>0&&y.trackShow("qna"),this._specIncludesType(p,"TextInput")||this._insertStandaloneInputBeforePills(l,g,f)}catch(r){if(r instanceof DOMException&&r.name==="AbortError")return;if(y.dispatch("gengage:global:error",{source:"qna",code:"FETCH_ERROR",message:y.getGlobalErrorMessage(this.config.locale,r)}),this.track(y.streamErrorEvent(this.analyticsContext(),{request_id:o,error_code:"FETCH_ERROR",error_message:r instanceof Error?r.message:String(r),widget:"qna"})),this._contentEl){this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const s=document.createElement("div");s.className="gengage-qna-panel",this._contentEl.appendChild(s);const c=this.config.inputPlaceholder===!0?this._i18n.defaultInputPlaceholder:this.config.inputPlaceholder??this._i18n.defaultInputPlaceholder,l={onAction:this._actionHandler,i18n:this._i18n,onOpenChat:this._openChatHandler},d=this._resolvedQnaHeaderTitle();d!==void 0&&(l.headingTitleOverride=d),this.config.ctaText!==void 0&&(l.ctaText=this.config.ctaText),this._appendStandaloneInput(l,c,s)}}finally{a()}}_createLoadingIndicator(){const t=document.createElement("div");t.className="gengage-qna-loading";for(let n=0;n<3;n++){const e=document.createElement("div");e.className="gengage-qna-loading-dot",t.appendChild(e)}return t}_resolveI18n(t){return{...V(t.locale),...t.i18n}}_resolveUISpecRegistry(){return u.mergeUISpecRegistry(P(),this.config.renderer?.registry)}_renderUISpec(t,n){const e=this._resolveUISpecRegistry(),o=this.config.renderer?.unknownRenderer??E,i=(r,s)=>Q(r,s,e,o),a=this.config.renderer?.renderUISpec;return a?a(t,n,{registry:e,unknownRenderer:o,defaultRender:i}):i(t,n)}_specIncludesType(t,n){for(const e of t)for(const o of Object.values(e.elements))if(o.type===n)return!0;return!1}_buildFallbackActionsSpec(t){if(t.length===0)return{root:"root",elements:{}};const n={},e=[];for(let o=0;o<t.length;o++){const i=t[o],a=`action-${o}`;e.push(a),n[a]={type:"ActionButton",props:{label:i.title,action:{title:i.title,type:i.type,payload:i.payload}}}}return n.root={type:"ButtonRow",children:e},{root:"root",elements:n}}_insertStandaloneInputBeforePills(t,n,e){const o={root:"root",elements:{root:{type:"TextInput",props:{placeholder:e}}}},i=this._renderUISpec(o,n),a=i.querySelector(".gengage-qna-input-wrapper");if(!a)return;const r=t.querySelector(".gengage-qna-uispec"),s=r?.querySelector(":scope > .gengage-qna-buttons");if(r&&s)r.insertBefore(a,s);else if(r){const c=r.querySelector(":scope > .gengage-qna-heading");c?c.insertAdjacentElement("afterend",a):r.prepend(a)}else{t.appendChild(i);return}i.remove()}_appendStandaloneInput(t,n,e){if(!this._contentEl)return;const o={root:"root",elements:{root:{type:"TextInput",props:{placeholder:n}}}},i=this._renderUISpec(o,t);(e??this._contentEl).appendChild(i)}_handleAction(t){this._showTransitionIndicator(),y.trackSuggestedQuestion(t.title,t.type),this.config.onActionSelected?.(t),setTimeout(()=>y.dispatch("gengage:qna:action",t),350)}_handleOpenChat(){this._showTransitionIndicator(),this.config.onOpenChat?.(),setTimeout(()=>y.dispatch("gengage:qna:open-chat",{}),350)}_showTransitionIndicator(){if(!this._contentEl)return;this._contentEl.querySelector(".gengage-qna-transition-indicator")?.remove(),this._contentEl.classList.add("gengage-qna--transitioning");const t=this._i18n.redirectingToChat??"Redirecting to chat...",n=document.createElement("div");n.className="gengage-qna-transition-indicator",n.textContent=t,(this._contentEl.querySelector(".gengage-qna-panel")??this._contentEl).appendChild(n),setTimeout(()=>{this._contentEl?.classList.remove("gengage-qna--transitioning"),n.remove()},600)}};function nt(){return new N}Object.defineProperty(exports,"GengageQNA",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"createDefaultQnaUISpecRegistry",{enumerable:!0,get:function(){return P}});Object.defineProperty(exports,"createQNAWidget",{enumerable:!0,get:function(){return nt}});Object.defineProperty(exports,"defaultQnaUnknownUISpecRenderer",{enumerable:!0,get:function(){return E}});Object.defineProperty(exports,"qnaCatalog",{enumerable:!0,get:function(){return et}});Object.defineProperty(exports,"renderQnaUISpec",{enumerable:!0,get:function(){return Q}});
|
package/dist/qna.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./qna-DwG8AJJf.cjs");exports.GengageQNA=e.GengageQNA;exports.createDefaultQnaUISpecRegistry=e.createDefaultQnaUISpecRegistry;exports.createQNAWidget=e.createQNAWidget;exports.defaultQnaUnknownUISpecRenderer=e.defaultQnaUnknownUISpecRenderer;exports.qnaCatalog=e.qnaCatalog;exports.renderQnaUISpec=e.renderQnaUISpec;
|