@gengage/assistant-fe 0.3.21 → 0.3.23
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/README.md +18 -6
- package/dist/chat/catalog.d.ts +11 -1
- package/dist/chat/components/ChatDrawer.d.ts +5 -0
- package/dist/chat/components/PhotoAnalysisCard.d.ts +14 -7
- package/dist/chat/types.d.ts +14 -1
- package/dist/chat-BOkLnT1i.cjs +93 -0
- package/dist/{chat-yAf9OADM.js → chat-DBJ8ZWch.js} +1807 -1737
- package/dist/chat.cjs +1 -1
- package/dist/chat.iife.js +26 -26
- package/dist/chat.js +1 -1
- package/dist/common/client.d.ts +4 -0
- package/dist/common/config-schema.d.ts +4 -0
- package/dist/common/overlay.d.ts +4 -0
- package/dist/common/widget-base.d.ts +6 -0
- package/dist/common-0GWnpStO.cjs +1 -0
- package/dist/{common-C8NRcP7O.js → common-BJZB1LIH.js} +35 -26
- package/dist/common.cjs +1 -1
- package/dist/common.js +6 -6
- package/dist/{connection-warning-CVZzlGJt.js → connection-warning-CHHi3BAf.js} +1 -1
- package/dist/{connection-warning-CL1CReZo.cjs → connection-warning-YQiIRXrz.cjs} +1 -1
- package/dist/{ga-datalayer-DkfsAHf9.cjs → ga-datalayer-BVppFxqk.cjs} +1 -1
- package/dist/{ga-datalayer-CgI6Kb_i.js → ga-datalayer-BwxWX-cr.js} +35 -32
- package/dist/index.cjs +1 -1
- package/dist/index.js +9 -9
- package/dist/{native-webview-B8vOoxns.js → native-webview-111Or6o1.js} +72 -69
- package/dist/native-webview-BePZBK3U.cjs +1 -0
- package/dist/native.cjs +1 -1
- package/dist/native.iife.js +11 -11
- package/dist/native.js +1 -1
- package/dist/{qna-YSaIDxjs.js → qna-DXCQtwLq.js} +3 -3
- package/dist/{qna-KizG_W1J.cjs → qna-DwG8AJJf.cjs} +1 -1
- package/dist/qna.cjs +1 -1
- package/dist/qna.iife.js +1 -1
- package/dist/qna.js +1 -1
- package/dist/{schemas-B6RjqKrg.cjs → schemas-B7jnyzQI.cjs} +1 -1
- package/dist/{schemas-PkedCk_-.js → schemas-CTbgsvNJ.js} +1 -1
- package/dist/simbut/index.d.ts +3 -0
- package/dist/{simbut-BI054QK0.js → simbut-BBXTlzOg.js} +28 -20
- package/dist/simbut-D_ycY_MQ.cjs +1 -0
- package/dist/simbut.cjs +1 -1
- package/dist/simbut.iife.js +8 -8
- package/dist/simbut.js +1 -1
- package/dist/{simrel-C-DKpfVB.js → simrel-DP2EMyua.js} +3 -3
- package/dist/{simrel-vL0woDkE.cjs → simrel-DdP4lur9.cjs} +1 -1
- package/dist/simrel.cjs +1 -1
- package/dist/simrel.iife.js +1 -1
- package/dist/simrel.js +1 -1
- package/package.json +1 -1
- package/dist/chat-CuPO9t-Z.cjs +0 -93
- package/dist/common-BzegEdJs.cjs +0 -1
- package/dist/native-webview-D2lDXTh3.cjs +0 -1
- package/dist/simbut-B2jXtckF.cjs +0 -1
package/dist/common-BzegEdJs.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const y=require("./schemas-B6RjqKrg.cjs"),l=require("./native-webview-D2lDXTh3.cjs");var p={enabled:!0,endpoint:"/analytics",fireAndForget:!0,useBeacon:!0,keepaliveFetch:!0,timeoutMs:4e3,maxRetries:0,batchSize:10,flushIntervalMs:250},v={mode:"none",key:"",headerName:"X-API-Key",bodyField:"api_key"},f=class{constructor(e){this.queue=[],this.flushTimer=null,this.config={...p,...e,auth:{...v,...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=b(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),n=u(this.config.endpoint,this.config.middlewareUrl);this.send(n,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 n=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([n],{type:"application/json"});navigator.sendBeacon(e,o);return}if(typeof fetch>"u")return;const r={"Content-Type":"application/json"};this.config.auth.mode==="x-api-key-header"&&this.config.auth.key&&(r[this.config.auth.headerName]=this.config.auth.key),this.config.auth.mode==="bearer-header"&&this.config.auth.key&&(r.Authorization=`Bearer ${this.config.auth.key}`),fetch(e,{method:"POST",headers:r,body:n,keepalive:!0}).catch(()=>{})}catch{}}flushAllSync(){if(!this.config.enabled)return;const e=u(this.config.endpoint,this.config.middlewareUrl);for(;this.queue.length>0;){const t=this.queue.splice(0,this.config.batchSize),n=this.buildTransportBody(t);try{const r=JSON.stringify(n);if(d()){const o=new Blob([r],{type:"application/json"});navigator.sendBeacon(e,o)}}catch{}}}};function w(e){return new f(e)}function b(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 u(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 n={accountId:e.accountId,middlewareUrl:e.middlewareUrl,session:{sessionId:e.sessionId},variant:"floating",locale:e.locale??"tr",...t};return e.theme!==void 0&&(n.theme=e.theme),n}function k(e,t={}){const n={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&&(n.theme=e.theme),n}function _(e,t={}){const n={accountId:e.accountId,middlewareUrl:e.middlewareUrl,session:{sessionId:e.sessionId},sku:e.sku,mountTarget:e.mountTarget,...t};return e.theme!==void 0&&(n.theme=e.theme),n}function I(e,t={}){return{enabled:!0,middlewareUrl:e,endpoint:"/analytics",fireAndForget:!0,useBeacon:!0,...t}}function A(e){try{return document.querySelector(e),!0}catch{return!1}}function h(e,t){const n=[],r=e.mounts,o=[["qna",r.qna],["simrel",r.simrel],["chat",r.chat]];for(const[i,s]of o)if(s!==void 0){if(!A(s)){n.push({code:"INVALID_SELECTOR",message:`[gengage preflight] ${i} mount selector is invalid CSS: "${s}"`,severity:"error"});continue}document.querySelector(s)||n.push({code:"MOUNT_NOT_FOUND",message:`[gengage preflight] ${i} mount target not found: "${s}" — widget will skip or wait for DOM`,severity:"warn"})}const a=e.gtm.idempotencyKey;if(window[a]!==void 0&&n.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=c=>{c.blockedURI&&e.middlewareUrl.startsWith(c.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&&n.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 n)i.severity==="error"?console.error(i.message):console.warn(i.message);return{ok:n.every(i=>i.severity!=="error"),warnings:n}}function U(e){const t=l.safeParseAccountRuntimeConfig(e);if(!t.success){const n=t.error.issues.map(r=>`${r.path.join(".")}: ${r.message}`).join("; ");throw new Error(`[gengage] Invalid runtime config: ${n}`)}return t.data}function O(e,t,n){const r={accountId:e.accountId,middlewareUrl:e.middlewareUrl,idempotencyKey:e.gtm.idempotencyKey};return e.locale!==void 0&&(r.locale=e.locale),n!==void 0&&(r.pageContext=n,n.sku!==void 0&&(r.sku=n.sku)),r.chat={enabled:e.widgets.chat.enabled},e.mounts.chat!==void 0&&(r.chat.mountTarget=e.mounts.chat),r.qna={enabled:e.widgets.qna.enabled},e.mounts.qna!==void 0&&(r.qna.mountTarget=e.mounts.qna),r.simrel={enabled:e.widgets.simrel.enabled},e.mounts.simrel!==void 0&&(r.simrel.mountTarget=e.mounts.simrel),t?.onAddToCart!==void 0&&(r.onAddToCart=t.onAddToCart),t?.onProductNavigate!==void 0&&(r.onProductNavigate=t.onProductNavigate),t?.onScriptCall!==void 0&&(r.onScriptCall=t.onScriptCall),r}async function S(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 n=e.contextResolver?.(),r=await l.initOverlayWidgets(O(t,e.hostActions,n));if(e.contextResolver!==void 0){const o=e.contextResolver,a=()=>{const s=o();r.updateContext(s)};window.addEventListener("gengage:context:update",a);const i=r.destroy.bind(r);r.destroy=()=>{window.removeEventListener("gengage:context:update",a),i()}}return r}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 n=t??(typeof window<"u"?new URL(window.location.href):null);if(!n)return"other";const r=e??E,o=n.pathname;for(const a of r)if(!(a.urlPatterns&&!a.urlPatterns.some(i=>{try{return new RegExp(i,"i").test(o)}catch{return!1}}))&&!(a.queryParam&&!n.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 n=t.pathname,r=n.match(/\/(?:p|urun|product)\/([^/?#]+)/i);if(r?.[1])return r[1];const o=n.match(/-p-(\d+)/i);if(o?.[1])return o[1]}function L(e){const t=m(e),n={pageType:t};if(t==="pdp"){const r=g();r&&(n.sku=r)}return typeof window<"u"&&(n.url=window.location.href),n}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 L}});Object.defineProperty(exports,"createAccountIdentity",{enumerable:!0,get:function(){return C}});Object.defineProperty(exports,"createAnalyticsClient",{enumerable:!0,get:function(){return w}});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 k}});Object.defineProperty(exports,"createPdpSimRelConfig",{enumerable:!0,get:function(){return _}});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 S}});Object.defineProperty(exports,"preflightDiagnostics",{enumerable:!0,get:function(){return h}});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const o=require("./schemas-B6RjqKrg.cjs"),m=require("./ga-datalayer-DkfsAHf9.cjs"),K=require("./chat-CuPO9t-Z.cjs"),$=require("./qna-KizG_W1J.cjs"),G=require("./simrel-vL0woDkE.cjs"),Y=require("./simbut-B2jXtckF.cjs");var C=o.object({enabled:o.boolean().default(!0)}),J=o.object({chat:o.string().optional(),qna:o.string().optional(),simrel:o.string().optional()}),X=o.object({}),k=o._enum(["none","x-api-key-header","bearer-header","body-api-key"]),z=o.object({mode:k.default("none"),key:o.string().optional(),headerName:o.string().optional(),bodyField:o.string().default("api_key")}),Z=o.object({enabled:o.boolean().default(!0),endpoint:o.string().default("/analytics"),auth:z.default({mode:"none",bodyField:"api_key"}),fireAndForget:o.boolean().default(!0),useBeacon:o.boolean().default(!0),keepaliveFetch:o.boolean().default(!0),timeoutMs:o.number().int().positive().default(4e3),maxRetries:o.number().int().min(0).max(5).default(1)}),U="__gengageWidgetsInit",ee=o.object({idempotencyKey:o.string().default(U),requireDomReady:o.boolean().default(!0)}),O=o._enum(["log-and-ignore","throw","delegate"]),te=o.object({unknownActionPolicy:O.default("log-and-ignore"),allowScriptCall:o.boolean().default(!1)}),N=o.object({version:o.literal("1",{error:'version must be "1"'}),accountId:o.string({error:"accountId must be a non-empty string"}).min(1,{error:"accountId must be a non-empty string"}),middlewareUrl:o.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:o.string().optional(),widgets:o.object({chat:C.default({enabled:!0}),qna:C.default({enabled:!0}),simrel:C.default({enabled:!0})}),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}}})}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={accountId:this.options.accountId,middlewareUrl:e,session:this.session,pageContext:this._pageContext,variant:this.options.chat?.variant??"floating"};this.options.theme!==void 0&&(t.theme=this.options.theme),this.options.locale!==void 0&&(t.locale=this.options.locale),this.options.pricing!==void 0&&(t.pricing=this.options.pricing),this.options.chat?.mountTarget!==void 0&&(t.mountTarget=this.options.chat.mountTarget),this.options.chat?.pillLauncher!==void 0&&(t.pillLauncher=this.options.chat.pillLauncher),this.options.chat?.launcherImageUrl!==void 0?t.launcherImageUrl=this.options.chat.launcherImageUrl:this.options.chat?.launcherSvg!==void 0&&(t.launcherSvg=this.options.chat.launcherSvg),this.options.chat?.headerTitle!==void 0&&(t.headerTitle=this.options.chat.headerTitle),this.options.chat?.headerAvatarUrl!==void 0&&(t.headerAvatarUrl=this.options.chat.headerAvatarUrl),this.options.chat?.headerBadge!==void 0&&(t.headerBadge=this.options.chat.headerBadge),this.options.chat?.headerCartUrl!==void 0&&(t.headerCartUrl=this.options.chat.headerCartUrl),this.options.chat?.headerFavoritesToggle!==void 0&&(t.headerFavoritesToggle=this.options.chat.headerFavoritesToggle),this.options.chat?.onFavoritesClick!==void 0&&(t.onFavoritesClick=this.options.chat.onFavoritesClick),this.options.chat?.hideMobileLauncher!==void 0&&(t.hideMobileLauncher=this.options.chat.hideMobileLauncher),this.options.chat?.mobileBreakpoint!==void 0&&(t.mobileBreakpoint=this.options.chat.mobileBreakpoint),this.options.chat?.mobileInitialState!==void 0&&(t.mobileInitialState=this.options.chat.mobileInitialState),this.options.chat?.i18n!==void 0&&(t.i18n=this.options.chat.i18n),this.options.chat?.actionHandling!==void 0&&(t.actionHandling=this.options.chat.actionHandling),this.options.chat?.renderer!==void 0&&(t.renderer=this.options.chat.renderer),this.options.chat?.productDetailsExtended!==void 0&&(t.productDetailsExtended=this.options.chat.productDetailsExtended),this.options.chat?.isDemoWebsite!==void 0&&(t.isDemoWebsite=this.options.chat.isDemoWebsite),this.options.chat?.productPriceUi!==void 0&&(t.productPriceUi=this.options.chat.productPriceUi),this.options.onScriptCall!==void 0&&(t.onScriptCall=this.options.onScriptCall),this.options.onAddToCart!==void 0&&(t.onAddToCart=this.options.onAddToCart),this.options.chat?.onOpen!==void 0&&(t.onOpen=this.options.chat.onOpen),this.options.chat?.onClose!==void 0&&(t.onClose=this.options.chat.onClose),this._chat=new K.GengageChat,await this._chat.init(t)}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,a=T(i);if(a)if(this._warnedQnaMountMissing=!1,this._qna)this._qna.show(),this._qna.update({pageType:"pdp",sku:e});else{const s=new $.GengageQNA,n={accountId:this.options.accountId,middlewareUrl:t,session:this.session,pageContext:{pageType:"pdp",sku:e},mountTarget:a};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 s.init(n),this._qna=s}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,a=T(i);if(a)if(this._warnedSimRelMountMissing=!1,this._simrel)this._simrel.show(),this._simrel.update({pageType:"pdp",sku:e});else{const s=new G.GengageSimRel,n={accountId:this.options.accountId,middlewareUrl:t,session:this.session,sku:e,mountTarget:a};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 s.init(n),this._simrel=s}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,a=T(i),s=this._chat??this.options.simbut.onFindSimilar;if(a&&s)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:a,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,!a&&!this._warnedSimButMountMissing?(console.warn(`[gengage] SimBut mount target not found: ${i}`),this._warnedSimButMountMissing=!0):!s&&!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(),a=i.instances[t];if(a)return a;const s=i.pending[t];if(s)return s;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 j(e){return q().instances[e]??null}function ce(e){j(e)?.destroy()}function le(e){return`${x}${e}`}var W=["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,a=[i.type,i.command,i.action,i.event].find(n=>typeof n=="string"&&n.length>0);if(!a)return null;let s=i.payload;if(s===void 0&&"data"in i&&(s=i.data),a==="setSession"&&s===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)&&(s=n)}return s===void 0?{type:a}:{type:a,payload:s}}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 a=e.document.getElementById(i);if(a)return a;const s=e.document.createElement("div");return s.id=i,e.document.body.appendChild(s),s}function L(e,t){const i=e.webkit?.messageHandlers?.[t];return i&&typeof i.postMessage=="function"?i.postMessage.bind(i):null}function b(e,t){const i=e[t];return i&&typeof i=="object"&&typeof i.postMessage=="function"?i:null}function F(e={}){const t=e.win??window,i=e.iosHandlerName??"gengage",a=e.androidInterfaceName??"GengageNative",s=e.reactNativeInterfaceName??"ReactNativeWebView";return L(t,i)?"ios":b(t,a)?"android":b(t,s)?"react-native":"browser"}function D(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 a=i.gengage,s=a.session??{};s.userId=e.userId,a.session=s}}function H(e={}){const t=e.win??window,i=t;if(i.gengageNative)return i.gengageNative;const a=e.iosHandlerName??"gengage",s=e.androidInterfaceName??"GengageNative",n=e.reactNativeInterfaceName??"ReactNativeWebView",u=e.trackedEvents??[...W],g=F({win:t,iosHandlerName:a,androidInterfaceName:s,reactNativeInterfaceName:n});let r=t.gengage?.overlay??null;const l=[],p=(c,d)=>{const f=d===void 0?{type:c}:{type:c,payload:d};if(g==="ios"){L(t,a)?.(f);return}if(g==="android"){b(t,s)?.postMessage(JSON.stringify(f));return}if(g==="react-native"){b(t,n)?.postMessage(JSON.stringify(f));return}},v=c=>{const d=c.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(c=>{const d=f=>{const h=f.detail;p("widget_event",{event:c,detail:h})};return t.addEventListener(c,d),{event:c,handler:d}}),y=c=>{l.length>=ge&&l.shift(),l.push(c)},V=()=>{if(!r||l.length===0)return;const c=l.splice(0,l.length);for(const d of c)S(d)},S=c=>{const d=he(c);if(!d||typeof d.type!="string"){console.warn("[gengage:native-bridge] Invalid message:",c);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 w=fe(h);if(r&&w){r.updateSku(w.sku,w.pageType);return}r?console.warn("[gengage:native-bridge] updateSku: missing sku"):y(d);return}case"setSession":h&&typeof h=="object"&&D(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)}},_={env:g,sendToNative:p,receive:S,setController(c){r=c,V()},destroy(){t.removeEventListener("gengage:bridge:message",v);for(const c of Q)t.removeEventListener(c.event,c.handler);l.splice(0,l.length),t.gengageNative===_&&delete t.gengageNative}};return i.gengageNative=_,_}async function pe(e){const{nativeBridge:t,emitReadyEvent:i=!0,...a}=e,s=H(t),n={...a};n.onAddToCart||(n.onAddToCart=l=>{s.sendToNative("addToCart",{sku:l.sku,quantity:l.quantity,cartCode:l.cartCode})}),n.onProductNavigate||(n.onProductNavigate=(l,p,v)=>{s.sendToNative("productNavigate",{url:l,sku:p,sessionId:v})});const u=n.qna?.enabled===!0||n.qna?.mountTarget!==void 0;if(n.qna?.enabled!==!1)if(u){const l=E(window,n.qna?.mountTarget??M,"gengage-qna");n.qna={...n.qna,enabled:!0,mountTarget:l}}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 l=E(window,n.simrel?.mountTarget??A,"gengage-simrel");n.simrel={...n.simrel,enabled:!0,mountTarget:l}}else I(window,A)||(n.simrel={enabled:!1});const r=await B(n);return s.setController(r),i&&s.sendToNative("ready",{sessionId:r.session.sessionId,widgets:{chat:r.chat!==null,qna:r.qna!==null,simrel:r.simrel!==null}}),{controller:r,bridge:s,destroy(){r.destroy(),s.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 W}});Object.defineProperty(exports,"UnknownActionPolicySchema",{enumerable:!0,get:function(){return O}});Object.defineProperty(exports,"applyNativeSession",{enumerable:!0,get:function(){return D}});Object.defineProperty(exports,"buildOverlayIdempotencyKey",{enumerable:!0,get:function(){return le}});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 ce}});Object.defineProperty(exports,"detectNativeEnvironment",{enumerable:!0,get:function(){return F}});Object.defineProperty(exports,"getOverlayWidgets",{enumerable:!0,get:function(){return j}});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/simbut-B2jXtckF.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const n=require("./ga-datalayer-DkfsAHf9.cjs");var c={findSimilarLabel:"Benzerlerini Bul"},f={findSimilarLabel:"Find Similar"};function g(t,i){return i?.findSimilarLabel?i.findSimilarLabel:(t??"tr").toLowerCase().startsWith("en")?f.findSimilarLabel:c.findSimilarLabel}function r(t){const i=typeof t.sku=="string"&&t.sku.length>0?t.sku:void 0,a=typeof t.pageContext?.sku=="string"&&t.pageContext.sku.length>0?t.pageContext.sku:void 0;return i??a}var u=class extends n.BaseWidget{constructor(...t){super(...t),this._button=null,this._label=c.findSimilarLabel}async onInit(t){this._label=g(t.locale,t.i18n),this.root.classList.add("gengage-simbut-root"),window.getComputedStyle(this.root).position==="static"&&(this.root.style.position="relative");const i=document.createElement("button");i.type="button",i.className="gengage-chat-find-similar-pill",i.textContent=this._label,this._button=i;const a=()=>{i.disabled=!(r(this.config)&&(this.config.onFindSimilar||this.config.chat))};i.addEventListener("click",d=>{d.stopPropagation();const e=r(this.config);if(!e)return;const s=this.config.imageUrl,o=typeof s=="string"&&n.isSafeUrl(s)?s:void 0;if(n.trackSuggestedQuestion(this._label,"findSimilar"),n.trackFindSimilars(e),this.config.onFindSimilar){this.config.onFindSimilar(o?{sku:e,imageUrl:o}:{sku:e});return}const l=this.config.chat;if(!l)return;const h={title:this._label,type:"findSimilar",payload:o?{sku:e,image_url:o}:{sku:e}};l.openWithAction(h,{sku:e})}),this.root.appendChild(i),a(),n.trackInit("simbut")}onUpdate(t){if(!this._button)return;const i=!!r(this.config)&&(!!this.config.onFindSimilar||!!this.config.chat);this._button.disabled=!i}onShow(){}onHide(){}onDestroy(){this._button?.remove(),this._button=null}setChat(t){if(this.config.chat=t,this._button){const i=!!r(this.config)&&(!!this.config.onFindSimilar||!!this.config.chat);this._button.disabled=!i}}};function m(){return new u}Object.defineProperty(exports,"GengageSimBut",{enumerable:!0,get:function(){return u}});Object.defineProperty(exports,"createSimButWidget",{enumerable:!0,get:function(){return m}});
|