@molin.ai/shop-ai 0.8.34 → 0.8.35

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.
@@ -384,7 +384,7 @@ var au=Object.defineProperty;var Ks=t=>{throw TypeError(t)};var lu=(t,e,r)=>e in
384
384
  <span>Molin AI</span>
385
385
  </a>
386
386
  </p>
387
- `)}};customElements.get("mw-powered-by")||customElements.define("mw-powered-by",os);function ga(t,e="http"){return t.startsWith("http://")||t.startsWith("https://")?t:`${e}://${t}`}function as(t){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$","i").test(t)}function ya(t,e){let r=t instanceof URL?t:new URL(t);if(e)for(let[n,i]of e)r.searchParams.set(n,i);return r}var ie=t=>t??E;var st,mr,ot,bn=class extends _(S){constructor(){super();d(this,st,!1);d(this,mr,!1);d(this,ot,!1);this.src=""}render(){return(this.src?.startsWith("https://cdn.shopify.com")||!1)&&m(this,st,!0),this.src?h`
387
+ `)}};customElements.get("mw-powered-by")||customElements.define("mw-powered-by",os);function ga(t,e="http"){return t.startsWith("http://")||t.startsWith("https://")?t:`${e}://${t}`}function as(t){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+!*'();@&=,$]*)*(\\?[-a-z\\d%_.~+!*'();@&=,$]*)?(\\#[-a-z\\d%_.~+!*'();@&=,$]*)?$","i").test(t)}function ya(t,e){let r=t instanceof URL?t:new URL(t);if(e)for(let[n,i]of e)r.searchParams.set(n,i);return r}var ie=t=>t??E;var st,mr,ot,bn=class extends _(S){constructor(){super();d(this,st,!1);d(this,mr,!1);d(this,ot,!1);this.src=""}render(){return(this.src?.startsWith("https://cdn.shopify.com")||!1)&&m(this,st,!0),this.src?h`
388
388
  <div class="relative h-full w-full overflow-hidden rounded-lg">
389
389
  <!-- use the same icon as for missing image url as the background behind the image so there is no flicker while it's loading -->
390
390
  <div class="absolute inset-0 flex items-center justify-center bg-gray-100">
@@ -979,7 +979,7 @@ var au=Object.defineProperty;var Ks=t=>{throw TypeError(t)};var lu=(t,e,r)=>e in
979
979
  `})}
980
980
  </div>
981
981
  </div>
982
- `}};g(ii,"properties",{orderDetails:{type:Object,attribute:"order-details"},streaming:{type:Boolean},linksNewTab:{type:Boolean,attribute:"links-new-tab"}});customElements.get("mw-product-order-status-card")||customElements.define("mw-product-order-status-card",ii);var qe,$e,Fs,Ur,Hs=class{constructor(e=window.localStorage){d(this,$e);d(this,qe);m(this,qe,e)}setex(e,r,n){return l(this,qe).setItem(e,y(this,$e,Ur).call(this,{value:y(this,$e,Ur).call(this,r),expiresAt:Date.now()+n*1e3})||"")}set(e,r){return l(this,qe).setItem(e,y(this,$e,Ur).call(this,{value:y(this,$e,Ur).call(this,r)})||"")}get(e){let r=l(this,qe).getItem(e);if(!r)return;let n=y(this,$e,Fs).call(this,r);if(n){if(n.expiresAt&&n.expiresAt<Date.now()){l(this,qe).removeItem(e);return}return y(this,$e,Fs).call(this,n.value)}}get molin_shop_assistant_distinct_id(){return localStorage.getItem("molin_shop_assistant_distinct_id")}set molin_shop_assistant_distinct_id(e){e===null?localStorage.removeItem("molin_shop_assistant_distinct_id"):localStorage.setItem("molin_shop_assistant_distinct_id",e)}get molin_widget_open_state(){return pe.get("molin-shop-ai-widget-open")??null}set molin_widget_open_state(e){pe.set("molin-shop-ai-widget-open",e)}resetWidgetData(){pe.molin_shop_assistant_distinct_id=null,pe.molin_widget_open_state=null}};qe=new WeakMap,$e=new WeakSet,Fs=function(e){if(!(typeof e!="string"||e===""))try{return JSON.parse(e)}catch{return}},Ur=function(e){if(e!==void 0)try{return JSON.stringify(e)}catch{return}};var pe=new Hs;var re,Te,oi,Nr,Wt,Bs=class{constructor(){d(this,re,[]);d(this,Te);d(this,oi,10);d(this,Nr,5e3);d(this,Wt,!1)}async add(e,r){if(l(this,re).push({event:e,properties:Object.assign({},r,Wl()),distinct_id:zl(r.distinct_id),timestamp:new Date().toISOString()}),l(this,re).length>=l(this,oi))return this.flush();l(this,Te)||m(this,Te,setTimeout(()=>{this.flush().catch(console.error)},l(this,Nr)))}async flush(){if(l(this,Wt)||l(this,re).length===0)return;let e=[...l(this,re)];try{m(this,Wt,!0),clearTimeout(l(this,Te)),m(this,Te,void 0),m(this,re,[]);let r=new AbortController,n=setTimeout(()=>r.abort(),5e3),i=new FormData;i.append("events",JSON.stringify(e));let s=await fetch(new URL("/widgets/data/collect",qs()).href,{method:"POST",body:i,signal:r.signal});if(clearTimeout(n),!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s}catch(r){if(r.name==="AbortError")console.error("Request timed out, retrying events"),m(this,re,[...e,...l(this,re)]);else{console.error("Failed to send events to backend:",r);let n=e.filter(i=>i.event.includes("error"));m(this,re,[...n,...l(this,re)])}}finally{m(this,Wt,!1),l(this,re).length>0&&!l(this,Te)&&m(this,Te,setTimeout(()=>{this.flush().catch(console.error)},l(this,Nr)))}}async flushBeforeUnload(){if(l(this,re).length>0)try{let e=new FormData;e.append("events",JSON.stringify(l(this,re))),navigator.sendBeacon(new URL("/widgets/data/collect",qs()).href,e)}catch(e){console.error("Failed to send final events:",e)}}};re=new WeakMap,Te=new WeakMap,oi=new WeakMap,Nr=new WeakMap,Wt=new WeakMap;var ql=new Bs;window.addEventListener("beforeunload",()=>{ql.flushBeforeUnload().catch(console.error)});async function H(t,e){try{if(e.immediate){let r=new FormData;r.append("events",JSON.stringify([{event:t,properties:Object.assign({},e,Wl()),distinct_id:zl(e.distinct_id),timestamp:new Date().toISOString()}]));let n=await fetch(new URL("/widgets/data/collect",qs()).href,{method:"POST",body:r});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}return ql.add(t,e)}catch(r){console.error("Failed to send event:",r)}}function zl(t=crypto.randomUUID()){try{let e=pe.molin_shop_assistant_distinct_id;return e||(e=t,pe.molin_shop_assistant_distinct_id=e),e}catch(e){console.error("Failed to handle distinct ID:",e);try{pe.molin_shop_assistant_distinct_id=t}catch(r){console.error("Failed to store new distinct ID:",r)}return t}}function Wl(){return{referrer:document.referrer,userAgent:navigator.userAgent,language:navigator.language,screenWidth:window.innerWidth,screenHeight:window.innerHeight,timestamp:new Date().toISOString(),timezoneOffset:new Date().getTimezoneOffset(),doNotTrack:navigator.doNotTrack}}var si;function qs(){if(si)return si;let t=new URL(import.meta.url).hostname;return si=new Map([["localhost","http://localhost:8787"],["widget.molin.foo","https://molin.foo"],["widget.molin.ai","https://molin.ai"],["molin.foo","https://molin.foo"]]).get(t)||"https://molin.ai",si}var dt,Vr,ze,mt,li,Gl,ai=class{constructor(e,r,n){d(this,li);d(this,dt);d(this,Vr);d(this,ze);d(this,mt);g(this,"isLoading",!1);g(this,"data");m(this,dt,e),m(this,Vr,r),m(this,ze,n),e.addController(this)}fetch(){if(this.isLoading)return;l(this,mt)?.abort();let e=new AbortController;m(this,mt,e),this.isLoading=!0,this.data=void 0,l(this,dt).requestUpdate(),(async()=>{let r=y(this,li,Gl).call(this);return r.signal?.addEventListener("abort",()=>e.abort(),{signal:e.signal}),fetch(r,{signal:e.signal})})().then(async r=>{if(!r.ok)throw new Error(`${r.statusText}: ${await r.text()}`);this.isLoading=!1,this.data=typeof l(this,ze)?.transform=="function"?await l(this,ze).transform(r):r,l(this,dt).requestUpdate()}).catch(r=>{l(this,ze)?.onError?.(r),this.isLoading=!1,this.data=void 0,l(this,dt).requestUpdate()}).finally(()=>{e.abort()})}hostConnected(){this.isLoading||l(this,ze)?.fetchWhenConnected&&this.fetch()}hostDisconnected(){l(this,mt)?.abort(),m(this,mt,void 0)}};dt=new WeakMap,Vr=new WeakMap,ze=new WeakMap,mt=new WeakMap,li=new WeakSet,Gl=function(){let e=l(this,Vr);if(typeof e=="function"&&(e=e()),!e)throw new Error("missing request");return new Request(e)};var Se,Hr,Zt,Gt,We=class{constructor(e,r){d(this,Se);d(this,Hr);d(this,Zt);d(this,Gt);m(this,Se,e),m(this,Hr,r),e.addController(this)}get data(){return l(this,Gt)||l(this,Zt)?.data}hostConnected(){if(l(this,Zt)||l(this,Gt))return;let e=Jl();e&&e.widgetId===l(this,Se).widgetId?m(this,Gt,e.config):m(this,Zt,new ai(l(this,Se),()=>{if(l(this,Se).cdn&&l(this,Se).widgetId)return`${l(this,Se).cdn}/config?w=${l(this,Se).widgetId}`;throw new Error("missing cdn or widgetId")},{fetchWhenConnected:!0,transform:r=>r.json(),onError:l(this,Hr)?.onError}))}};Se=new WeakMap,Hr=new WeakMap,Zt=new WeakMap,Gt=new WeakMap;function Ze(){return window.molinSettings&&typeof window.molinSettings=="object"?window.molinSettings:null}var ui,qr,ci,je,Xl,Fr,Br=class Br extends _(S){constructor(){super();d(this,je);d(this,ui,new We(this,{onError:console.error}));d(this,qr);d(this,ci,{onError:r=>{alert(r.error),console.error(r.widgetId,r.error),H("ShopAssistant: error",{...r,immediate:!0})},onNewMessageStartedStreaming:r=>{H("ShopAssistant: user received bot message (streaming started)",r)},onMessageEndedStreaming:r=>{H("ShopAssistant: user received bot message (streaming ended)",r)},onUserCanceledStreaming:r=>{H("ShopAssistant: user canceled streaming",r)},onUserClickedLink:r=>{H("ShopAssistant: user clicked link",r)},onUserSentInput:r=>{H("ShopAssistant: user sent input",r)}});this.cdn="https://widget.molin.ai",this.widgetId="",this.showClose=!1,this.xUserData=Ze()?.userData,this.xCustomInstructions=Ze()?.customInstructions}get config(){return l(this,qr)||l(this,ui).data}render(){return this.config?h`
982
+ `}};g(ii,"properties",{orderDetails:{type:Object,attribute:"order-details"},streaming:{type:Boolean},linksNewTab:{type:Boolean,attribute:"links-new-tab"}});customElements.get("mw-product-order-status-card")||customElements.define("mw-product-order-status-card",ii);var qe,$e,Fs,Ur,Hs=class{constructor(e=window.localStorage){d(this,$e);d(this,qe);m(this,qe,e)}setex(e,r,n){return l(this,qe).setItem(e,y(this,$e,Ur).call(this,{value:y(this,$e,Ur).call(this,r),expiresAt:Date.now()+n*1e3})||"")}set(e,r){return l(this,qe).setItem(e,y(this,$e,Ur).call(this,{value:y(this,$e,Ur).call(this,r)})||"")}get(e){let r=l(this,qe).getItem(e);if(!r)return;let n=y(this,$e,Fs).call(this,r);if(n){if(n.expiresAt&&n.expiresAt<Date.now()){l(this,qe).removeItem(e);return}return y(this,$e,Fs).call(this,n.value)}}get molin_shop_assistant_distinct_id(){return localStorage.getItem("molin_shop_assistant_distinct_id")}set molin_shop_assistant_distinct_id(e){e===null?localStorage.removeItem("molin_shop_assistant_distinct_id"):localStorage.setItem("molin_shop_assistant_distinct_id",e)}get molin_widget_open_state(){return pe.get("molin-shop-ai-widget-open")??null}set molin_widget_open_state(e){pe.set("molin-shop-ai-widget-open",e)}resetWidgetData(){pe.molin_shop_assistant_distinct_id=null,pe.molin_widget_open_state=null}};qe=new WeakMap,$e=new WeakSet,Fs=function(e){if(!(typeof e!="string"||e===""))try{return JSON.parse(e)}catch{return}},Ur=function(e){if(e!==void 0)try{return JSON.stringify(e)}catch{return}};var pe=new Hs;var re,Te,oi,Nr,Wt,Bs=class{constructor(){d(this,re,[]);d(this,Te);d(this,oi,10);d(this,Nr,5e3);d(this,Wt,!1)}async add(e,r){if(l(this,re).push({event:e,properties:Object.assign({},r,Wl()),distinct_id:zl(r.distinct_id),timestamp:new Date().toISOString()}),l(this,re).length>=l(this,oi))return this.flush();l(this,Te)||m(this,Te,setTimeout(()=>{this.flush().catch(console.error)},l(this,Nr)))}async flush(){if(l(this,Wt)||l(this,re).length===0)return;let e=[...l(this,re)];try{m(this,Wt,!0),clearTimeout(l(this,Te)),m(this,Te,void 0),m(this,re,[]);let r=new AbortController,n=setTimeout(()=>r.abort(),5e3),i=new FormData;i.append("events",JSON.stringify(e));let s=await fetch(new URL("/widgets/data/collect",qs()).href,{method:"POST",body:i,signal:r.signal});if(clearTimeout(n),!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s}catch(r){if(r.name==="AbortError")console.error("Request timed out, retrying events"),m(this,re,[...e,...l(this,re)]);else{console.error("Failed to send events to backend:",r);let n=e.filter(i=>i.event.includes("error"));m(this,re,[...n,...l(this,re)])}}finally{m(this,Wt,!1),l(this,re).length>0&&!l(this,Te)&&m(this,Te,setTimeout(()=>{this.flush().catch(console.error)},l(this,Nr)))}}async flushBeforeUnload(){if(l(this,re).length>0)try{let e=new FormData;e.append("events",JSON.stringify(l(this,re))),navigator.sendBeacon(new URL("/widgets/data/collect",qs()).href,e)}catch(e){console.error("Failed to send final events:",e)}}};re=new WeakMap,Te=new WeakMap,oi=new WeakMap,Nr=new WeakMap,Wt=new WeakMap;var ql=new Bs;window.addEventListener("beforeunload",()=>{ql.flushBeforeUnload().catch(console.error)});async function H(t,e){try{if(e.immediate){let r=new FormData;r.append("events",JSON.stringify([{event:t,properties:Object.assign({},e,Wl()),distinct_id:zl(e.distinct_id),timestamp:new Date().toISOString()}]));let n=await fetch(new URL("/widgets/data/collect",qs()).href,{method:"POST",body:r});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}return ql.add(t,e)}catch(r){console.error("Failed to send event:",r)}}function zl(t=crypto.randomUUID()){try{let e=pe.molin_shop_assistant_distinct_id;return e||(e=t,pe.molin_shop_assistant_distinct_id=e),e}catch(e){console.error("Failed to handle distinct ID:",e);try{pe.molin_shop_assistant_distinct_id=t}catch(r){console.error("Failed to store new distinct ID:",r)}return t}}function Wl(){return{referrer:document.referrer,userAgent:navigator.userAgent,language:navigator.language,screenWidth:window.innerWidth,screenHeight:window.innerHeight,timestamp:new Date().toISOString(),timezoneOffset:new Date().getTimezoneOffset(),doNotTrack:navigator.doNotTrack}}var si;function qs(){if(si)return si;let t=new URL(import.meta.url).hostname;return si={localhost:"http://localhost:8787","molin.localhost":"http://molin.localhost:8787","widget.molin.foo":"https://molin.foo","widget.molin.ai":"https://molin.ai","molin.ai":"https://molin.ai","molin.foo":"https://molin.foo"}[t]||"https://molin.ai",si}var dt,Vr,ze,mt,li,Gl,ai=class{constructor(e,r,n){d(this,li);d(this,dt);d(this,Vr);d(this,ze);d(this,mt);g(this,"isLoading",!1);g(this,"data");m(this,dt,e),m(this,Vr,r),m(this,ze,n),e.addController(this)}fetch(){if(this.isLoading)return;l(this,mt)?.abort();let e=new AbortController;m(this,mt,e),this.isLoading=!0,this.data=void 0,l(this,dt).requestUpdate(),(async()=>{let r=y(this,li,Gl).call(this);return r.signal?.addEventListener("abort",()=>e.abort(),{signal:e.signal}),fetch(r,{signal:e.signal})})().then(async r=>{if(!r.ok)throw new Error(`${r.statusText}: ${await r.text()}`);this.isLoading=!1,this.data=typeof l(this,ze)?.transform=="function"?await l(this,ze).transform(r):r,l(this,dt).requestUpdate()}).catch(r=>{l(this,ze)?.onError?.(r),this.isLoading=!1,this.data=void 0,l(this,dt).requestUpdate()}).finally(()=>{e.abort()})}hostConnected(){this.isLoading||l(this,ze)?.fetchWhenConnected&&this.fetch()}hostDisconnected(){l(this,mt)?.abort(),m(this,mt,void 0)}};dt=new WeakMap,Vr=new WeakMap,ze=new WeakMap,mt=new WeakMap,li=new WeakSet,Gl=function(){let e=l(this,Vr);if(typeof e=="function"&&(e=e()),!e)throw new Error("missing request");return new Request(e)};var Se,Hr,Zt,Gt,We=class{constructor(e,r){d(this,Se);d(this,Hr);d(this,Zt);d(this,Gt);m(this,Se,e),m(this,Hr,r),e.addController(this)}get data(){return l(this,Gt)||l(this,Zt)?.data}hostConnected(){if(l(this,Zt)||l(this,Gt))return;let e=Jl();e&&e.widgetId===l(this,Se).widgetId?m(this,Gt,e.config):m(this,Zt,new ai(l(this,Se),()=>{if(l(this,Se).cdn&&l(this,Se).widgetId)return`${l(this,Se).cdn}/config?w=${l(this,Se).widgetId}`;throw new Error("missing cdn or widgetId")},{fetchWhenConnected:!0,transform:r=>r.json(),onError:l(this,Hr)?.onError}))}};Se=new WeakMap,Hr=new WeakMap,Zt=new WeakMap,Gt=new WeakMap;function Ze(){return window.molinSettings&&typeof window.molinSettings=="object"?window.molinSettings:null}var ui,qr,ci,je,Xl,Fr,Br=class Br extends _(S){constructor(){super();d(this,je);d(this,ui,new We(this,{onError:console.error}));d(this,qr);d(this,ci,{onError:r=>{alert(r.error),console.error(r.widgetId,r.error),H("ShopAssistant: error",{...r,immediate:!0})},onNewMessageStartedStreaming:r=>{H("ShopAssistant: user received bot message (streaming started)",r)},onMessageEndedStreaming:r=>{H("ShopAssistant: user received bot message (streaming ended)",r)},onUserCanceledStreaming:r=>{H("ShopAssistant: user canceled streaming",r)},onUserClickedLink:r=>{H("ShopAssistant: user clicked link",r)},onUserSentInput:r=>{H("ShopAssistant: user sent input",r)}});this.cdn="https://widget.molin.ai",this.widgetId="",this.showClose=!1,this.xUserData=Ze()?.userData,this.xCustomInstructions=Ze()?.customInstructions}get config(){return l(this,qr)||l(this,ui).data}render(){return this.config?h`
983
983
  <!-- embed our chat component forwarding props -->
984
984
  <mw-chat
985
985
  widget="${this.widgetId}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molin.ai/shop-ai",
3
- "version": "0.8.34",
3
+ "version": "0.8.35",
4
4
  "description": "Molin Shop AI",
5
5
  "keywords": [
6
6
  "molin",