@blotoutio/providers-shop-gpt-sdk 0.69.0 → 0.70.0
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/index.cjs.js +80 -42
- package/index.js +80 -42
- package/index.mjs +80 -42
- package/package.json +1 -1
- package/stores/shopify/index.cjs.js +7 -0
- package/stores/shopify/index.js +7 -0
- package/stores/shopify/index.mjs +7 -0
package/index.cjs.js
CHANGED
@@ -34,6 +34,12 @@ new Set([
|
|
34
34
|
...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
|
35
35
|
]);
|
36
36
|
|
37
|
+
const formatMoney = (n, currency, options) => n.toLocaleString('en-US', {
|
38
|
+
style: 'currency',
|
39
|
+
currency: currency || 'USD',
|
40
|
+
...options,
|
41
|
+
});
|
42
|
+
|
37
43
|
const packageName = 'shopGPT';
|
38
44
|
|
39
45
|
var _a$1;
|
@@ -63,11 +69,11 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
63
69
|
const url = new URL(`/providers/shopGPT${path}`, baseURL);
|
64
70
|
return url;
|
65
71
|
};
|
66
|
-
const processQuery = async (query) => {
|
72
|
+
const processQuery = async (query, productHandle) => {
|
67
73
|
const response = await fetchImpl(getURL('/query'), {
|
68
74
|
method: 'POST',
|
69
75
|
headers: getHeaders(),
|
70
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
76
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
71
77
|
credentials: 'include',
|
72
78
|
});
|
73
79
|
if (!response.ok) {
|
@@ -216,20 +222,20 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
216
222
|
* Copyright 2019 Google LLC
|
217
223
|
* SPDX-License-Identifier: BSD-3-Clause
|
218
224
|
*/
|
219
|
-
const t$
|
225
|
+
const t$3=globalThis,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$3=new WeakMap;let n$3 = class n{constructor(t,e,o){if(this._$cssResult$=!0,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$6&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$5=t=>new n$3("string"==typeof t?t:t+"",void 0,s$2),i$3=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[o+1]),t[0]);return new n$3(o,t,s$2)},S$1=(s,o)=>{if(e$6)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$3.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$5(e)})(t):t;
|
220
226
|
|
221
227
|
/**
|
222
228
|
* @license
|
223
229
|
* Copyright 2017 Google LLC
|
224
230
|
* SPDX-License-Identifier: BSD-3-Clause
|
225
|
-
*/const{is:i$
|
231
|
+
*/const{is:i$2,defineProperty:e$5,getOwnPropertyDescriptor:r$4,getOwnPropertyNames:h$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$2}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$2(t,s),y$1={attribute:!0,type:String,converter:u$1,reflect:!1,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let b$1 = class b extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=y$1){if(s.state&&(s.attribute=!1),this._$Ei(),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(t,i,s);void 0!==r&&e$5(this.prototype,t,r);}}static getPropertyDescriptor(t,s,i){const{get:e,set:h}=r$4(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get(){return e?.call(this)},set(s){const r=e?.call(this);h.call(this,s),this.requestUpdate(t,r,i);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??y$1}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$2(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...h$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return !1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$EC(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&!0===i.reflect){const r=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==r?this.removeAttribute(e):this.setAttribute(e,r),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e,this[e]=r.fromAttribute(s,t.type),this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){if(i??=this.constructor.getPropertyOptions(t),!(i.hasChanged??f$1)(this[t],s))return;this.P(t,s,i);}!1===this.isUpdatePending&&(this._$ES=this._$ET());}P(t,s,i){this._$AL.has(t)||this._$AL.set(t,s),!0===i.reflect&&this._$Em!==t&&(this._$Ej??=new Set).add(t);}async _$ET(){this.isUpdatePending=!0;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t)!0!==i.wrapped||this._$AL.has(s)||void 0===this[s]||this.P(s,this[s],i);}let t=!1;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EU();}catch(s){throw t=!1,this._$EU(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$EU(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return !0}update(t){this._$Ej&&=this._$Ej.forEach((t=>this._$EC(t,this[t]))),this._$EU();}updated(t){}firstUpdated(t){}};b$1.elementStyles=[],b$1.shadowRootOptions={mode:"open"},b$1[d$1("elementProperties")]=new Map,b$1[d$1("finalized")]=new Map,p$1?.({ReactiveElement:b$1}),(a$1.reactiveElementVersions??=[]).push("2.0.4");
|
226
232
|
|
227
233
|
/**
|
228
234
|
* @license
|
229
235
|
* Copyright 2017 Google LLC
|
230
236
|
* SPDX-License-Identifier: BSD-3-Clause
|
231
237
|
*/
|
232
|
-
const t$
|
238
|
+
const t$2=globalThis,i$1=t$2.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$4="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$1="?"+h,n$1=`<${o$1}>`,r$3=document,l=()=>r$3.createComment(""),c=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a=Array.isArray,u=t=>a(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,_=/>/g,m=RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),p=/'/g,g=/"/g,$=/^(?:script|style|textarea|title)$/i,y=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x=y(1),b=y(2),w=Symbol.for("lit-noChange"),T=Symbol.for("lit-nothing"),A=new WeakMap,E=r$3.createTreeWalker(r$3,129);function C(t,i){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s$1?s$1.createHTML(i):i}const P=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"<svg>":"",c=f;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,y=0;for(;y<s.length&&(c.lastIndex=y,u=c.exec(s),null!==u);)y=c.lastIndex,c===f?"!--"===u[1]?c=v:void 0!==u[1]?c=_:void 0!==u[2]?($.test(u[2])&&(r=RegExp("</"+u[2],"g")),c=m):void 0!==u[3]&&(c=m):c===m?">"===u[0]?(c=r??f,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?m:'"'===u[3]?g:p):c===g||c===p?c=m:c===v||c===_?c=f:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f?s+n$1:d>=0?(o.push(a),s.slice(0,d)+e$4+s.slice(d)+h+x):s+h+(-2===d?i:x);}return [C(t,l+(t[s]||"<?>")+(2===i?"</svg>":"")),o]};class V{constructor({strings:t,_$litType$:s},n){let r;this.parts=[];let c=0,a=0;const u=t.length-1,d=this.parts,[f,v]=P(t,s);if(this.el=V.createElement(f,n),E.currentNode=this.el.content,2===s){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=E.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(e$4)){const i=v[a++],s=r.getAttribute(t).split(h),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:c,name:e[2],strings:s,ctor:"."===e[1]?k:"?"===e[1]?H:"@"===e[1]?I:R}),r.removeAttribute(t);}else t.startsWith(h)&&(d.push({type:6,index:c}),r.removeAttribute(t));if($.test(r.tagName)){const t=r.textContent.split(h),s=t.length-1;if(s>0){r.textContent=i$1?i$1.emptyScript:"";for(let i=0;i<s;i++)r.append(t[i],l()),E.nextNode(),d.push({type:2,index:++c});r.append(t[s],l());}}}else if(8===r.nodeType)if(r.data===o$1)d.push({type:2,index:c});else {let t=-1;for(;-1!==(t=r.data.indexOf(h,t+1));)d.push({type:7,index:c}),t+=h.length-1;}c++;}}static createElement(t,i){const s=r$3.createElement("template");return s.innerHTML=t,s}}function N(t,i,s=t,e){if(i===w)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=c(i)?void 0:i._$litDirective$;return h?.constructor!==o&&(h?._$AO?.(!1),void 0===o?h=void 0:(h=new o(t),h._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=h:s._$Cl=h),void 0!==h&&(i=N(t,h._$AS(t,i.values),h,e)),i}class S{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??r$3).importNode(i,!0);E.currentNode=e;let h=E.nextNode(),o=0,n=0,l=s[0];for(;void 0!==l;){if(o===l.index){let i;2===l.type?i=new M(h,h.nextSibling,this,t):1===l.type?i=new l.ctor(h,l.name,l.strings,this,t):6===l.type&&(i=new L(h,this,t)),this._$AV.push(i),l=s[++n];}o!==l?.index&&(h=E.nextNode(),o++);}return E.currentNode=r$3,e}p(t){let i=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class M{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=T,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??!0;}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=N(this,t,i),c(t)?t===T||null==t||""===t?(this._$AH!==T&&this._$AR(),this._$AH=T):t!==this._$AH&&t!==w&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):u(t)?this.k(t):this._(t);}S(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.S(t));}_(t){this._$AH!==T&&c(this._$AH)?this._$AA.nextSibling.data=t:this.T(r$3.createTextNode(t)),this._$AH=t;}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=V.createElement(C(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new S(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=A.get(t.strings);return void 0===i&&A.set(t.strings,i=new V(t)),i}k(t){a(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const h of t)e===i.length?i.push(s=new M(this.S(l()),this.S(l()),this,this.options)):s=i[e],s._$AI(h),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e);}_$AR(t=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i;}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t));}}class R{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,h){this.type=1,this._$AH=T,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=h,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=T;}_$AI(t,i=this,s,e){const h=this.strings;let o=!1;if(void 0===h)t=N(this,t,i,0),o=!c(t)||t!==this._$AH&&t!==w,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n<h.length-1;n++)r=N(this,e[s+n],i,n),r===w&&(r=this._$AH[n]),o||=!c(r)||r!==this._$AH[n],r===T?t=T:t!==T&&(t+=(r??"")+h[n+1]),this._$AH[n]=r;}o&&!e&&this.j(t);}j(t){t===T?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}}class k extends R{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===T?void 0:t;}}class H extends R{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==T);}}class I extends R{constructor(t,i,s,e,h){super(t,i,s,e,h),this.type=5;}_$AI(t,i=this){if((t=N(this,t,i,0)??T)===w)return;const s=this._$AH,e=t===T&&s!==T||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,h=t!==T&&(s===T||e);e&&this.element.removeEventListener(this.name,this,s),h&&this.element.addEventListener(this.name,this,t),this._$AH=t;}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t);}}class L{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s;}get _$AU(){return this._$AM._$AU}_$AI(t){N(this,t);}}const Z=t$2.litHtmlPolyfillSupport;Z?.(V,M),(t$2.litHtmlVersions??=[]).push("3.1.3");const j=(t,i,s)=>{const e=s?.renderBefore??i;let h=e._$litPart$;if(void 0===h){const t=s?.renderBefore??null;e._$litPart$=h=new M(i.insertBefore(l(),t),t,void 0,s??{});}return h._$AI(t),h};
|
233
239
|
|
234
240
|
/**
|
235
241
|
* @license
|
@@ -237,6 +243,19 @@ const t$1=globalThis,i=t$1.trustedTypes,s$1=i?i.createPolicy("lit-html",{createH
|
|
237
243
|
* SPDX-License-Identifier: BSD-3-Clause
|
238
244
|
*/class s extends b$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=j(i,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1);}render(){return w}}s._$litElement$=!0,s[("finalized")]=!0,globalThis.litElementHydrateSupport?.({LitElement:s});const r$2=globalThis.litElementPolyfillSupport;r$2?.({LitElement:s});(globalThis.litElementVersions??=[]).push("4.0.5");
|
239
245
|
|
246
|
+
/**
|
247
|
+
* @license
|
248
|
+
* Copyright 2017 Google LLC
|
249
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
250
|
+
*/
|
251
|
+
const t$1={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e$3=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
|
252
|
+
|
253
|
+
/**
|
254
|
+
* @license
|
255
|
+
* Copyright 2018 Google LLC
|
256
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
257
|
+
*/const e$2=e$3(class extends i{constructor(t){if(super(t),t.type!==t$1.ATTRIBUTE||"class"!==t.name||t.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return w}});
|
258
|
+
|
240
259
|
/**
|
241
260
|
* @license
|
242
261
|
* Copyright 2017 Google LLC
|
@@ -301,7 +320,7 @@ const logger = {
|
|
301
320
|
},
|
302
321
|
};
|
303
322
|
|
304
|
-
const shopGPTStyles = () => i$
|
323
|
+
const shopGPTStyles = () => i$3 `
|
305
324
|
:host {
|
306
325
|
position: fixed;
|
307
326
|
top: 0;
|
@@ -849,6 +868,7 @@ const shopGPTStyles = () => i$2 `
|
|
849
868
|
.chat-input {
|
850
869
|
display: flex;
|
851
870
|
align-items: center;
|
871
|
+
margin: 0;
|
852
872
|
|
853
873
|
input {
|
854
874
|
flex: 1;
|
@@ -929,6 +949,9 @@ const botIcon = () => b `
|
|
929
949
|
|
930
950
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
931
951
|
const getImageProperties = (src) => {
|
952
|
+
if (!src) {
|
953
|
+
return;
|
954
|
+
}
|
932
955
|
const image = new URL(src);
|
933
956
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
934
957
|
image.searchParams.set('width', width.toString());
|
@@ -977,6 +1000,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
977
1000
|
return;
|
978
1001
|
}
|
979
1002
|
await this.loadHistory();
|
1003
|
+
await this.loadInitialQuery();
|
980
1004
|
});
|
981
1005
|
}
|
982
1006
|
async loadHistory() {
|
@@ -1009,6 +1033,31 @@ let ShopGPT = class ShopGPT extends s {
|
|
1009
1033
|
this.isLoadingHistory = false;
|
1010
1034
|
}
|
1011
1035
|
}
|
1036
|
+
async loadInitialQuery() {
|
1037
|
+
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1038
|
+
if (this.chatbotMessages.length) {
|
1039
|
+
return;
|
1040
|
+
}
|
1041
|
+
try {
|
1042
|
+
this.isTyping = true;
|
1043
|
+
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1044
|
+
this.chatbotMessages = [
|
1045
|
+
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1046
|
+
...this.chatbotMessages,
|
1047
|
+
];
|
1048
|
+
this.recommendedProduct = reply.products[0];
|
1049
|
+
this.moreRecommendations = reply.products.slice(1, 4);
|
1050
|
+
this.setChatWindowHeight();
|
1051
|
+
}
|
1052
|
+
catch (error) {
|
1053
|
+
logger.error(error);
|
1054
|
+
this.resetProductRecommendations();
|
1055
|
+
this.isFailed = true;
|
1056
|
+
}
|
1057
|
+
finally {
|
1058
|
+
this.isTyping = false;
|
1059
|
+
}
|
1060
|
+
}
|
1012
1061
|
redirect(url) {
|
1013
1062
|
var _a;
|
1014
1063
|
if (!url) {
|
@@ -1064,9 +1113,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1064
1113
|
this.isTyping = false;
|
1065
1114
|
}
|
1066
1115
|
}
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1116
|
+
getLocalPrice(price) {
|
1117
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1118
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1119
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1070
1120
|
}
|
1071
1121
|
handleShowMore(value) {
|
1072
1122
|
if (!this.chatWindowElement) {
|
@@ -1111,9 +1161,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1111
1161
|
var _a;
|
1112
1162
|
return x `
|
1113
1163
|
<div
|
1114
|
-
class
|
1115
|
-
|
1116
|
-
:
|
1164
|
+
class=${e$2({
|
1165
|
+
'products-section': true,
|
1166
|
+
'no-recommended-product': !this.recommendedProduct,
|
1167
|
+
})}
|
1117
1168
|
>
|
1118
1169
|
<div class="product-section recommended-product">
|
1119
1170
|
<h2>Recommended product</h2>
|
@@ -1149,13 +1200,12 @@ let ShopGPT = class ShopGPT extends s {
|
|
1149
1200
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1150
1201
|
this.recommendedProduct.variants[0].price
|
1151
1202
|
? x `<p class="compared-at-price">
|
1152
|
-
${this.
|
1153
|
-
.
|
1203
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1204
|
+
.comparedAtPrice)}
|
1154
1205
|
</p>`
|
1155
1206
|
: T}
|
1156
1207
|
<p class="price">
|
1157
|
-
${this.
|
1158
|
-
.variants[0].price}
|
1208
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1159
1209
|
</p>
|
1160
1210
|
</div>
|
1161
1211
|
<button
|
@@ -1170,9 +1220,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1170
1220
|
</div>
|
1171
1221
|
|
1172
1222
|
<div
|
1173
|
-
class
|
1174
|
-
|
1175
|
-
:
|
1223
|
+
class=${e$2({
|
1224
|
+
'product-section': true,
|
1225
|
+
'more-recommendations': true,
|
1226
|
+
'show-more-sml': this.showMore,
|
1227
|
+
})}
|
1176
1228
|
>
|
1177
1229
|
<h2>More Recommendations</h2>
|
1178
1230
|
${this.moreRecommendations.length === 0
|
@@ -1184,12 +1236,13 @@ let ShopGPT = class ShopGPT extends s {
|
|
1184
1236
|
`
|
1185
1237
|
: x `<div class="products">
|
1186
1238
|
${this.moreRecommendations.map((product) => {
|
1187
|
-
|
1239
|
+
var _a, _b, _c;
|
1240
|
+
const imageProperties = getImageProperties((_a = product === null || product === void 0 ? void 0 : product.image) === null || _a === void 0 ? void 0 : _a.url);
|
1188
1241
|
return x `
|
1189
1242
|
<div class="product">
|
1190
1243
|
<img
|
1191
|
-
srcset=${imageProperties.srcset}
|
1192
|
-
sizes=${imageProperties.sizes}
|
1244
|
+
srcset=${(_b = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.srcset) !== null && _b !== void 0 ? _b : T}
|
1245
|
+
sizes=${(_c = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.sizes) !== null && _c !== void 0 ? _c : T}
|
1193
1246
|
src=${product.image.url}
|
1194
1247
|
alt=${product.image.alt}
|
1195
1248
|
@click=${() => this.redirect(product.url)}
|
@@ -1206,13 +1259,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1206
1259
|
product.variants[0].comparedAtPrice !==
|
1207
1260
|
product.variants[0].price
|
1208
1261
|
? x `<p class="compared-at-price">
|
1209
|
-
${this.
|
1210
|
-
.comparedAtPrice}
|
1262
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1211
1263
|
</p>`
|
1212
1264
|
: T}
|
1213
1265
|
<p class="price">
|
1214
|
-
${this.
|
1215
|
-
.price}
|
1266
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1216
1267
|
</p>
|
1217
1268
|
</div>
|
1218
1269
|
</div>
|
@@ -1239,17 +1290,6 @@ let ShopGPT = class ShopGPT extends s {
|
|
1239
1290
|
if (this.isLoadingHistory) {
|
1240
1291
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1241
1292
|
}
|
1242
|
-
if (this.chatbotMessages.length === 0) {
|
1243
|
-
return x `
|
1244
|
-
<div class="chat-header">
|
1245
|
-
<div class="chat-header-title">ShopGPT</div>
|
1246
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1247
|
-
<div class="chat-header-description">
|
1248
|
-
Hi, type a message to get started!
|
1249
|
-
</div>
|
1250
|
-
</div>
|
1251
|
-
`;
|
1252
|
-
}
|
1253
1293
|
return x `
|
1254
1294
|
<div class="chat-window">
|
1255
1295
|
${this.isTyping
|
@@ -1272,7 +1312,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1272
1312
|
<div class="bot-message-container">
|
1273
1313
|
${botIcon()}
|
1274
1314
|
<div class="message bot">
|
1275
|
-
|
1315
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1276
1316
|
${message.product
|
1277
1317
|
? x `<div class="product">
|
1278
1318
|
<img
|
@@ -1293,13 +1333,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1293
1333
|
message.product.variants[0].comparedAtPrice !==
|
1294
1334
|
message.product.variants[0].comparedAtPrice
|
1295
1335
|
? x `<p class="compared-at-price">
|
1296
|
-
${this.
|
1297
|
-
.variants[0].comparedAtPrice}
|
1336
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1298
1337
|
</p>`
|
1299
1338
|
: T}
|
1300
1339
|
<p class="price">
|
1301
|
-
${this.
|
1302
|
-
.variants[0].price}
|
1340
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1303
1341
|
</p>
|
1304
1342
|
</div>
|
1305
1343
|
</div>
|
package/index.js
CHANGED
@@ -35,6 +35,12 @@ var ProvidersShopGptSdk = (function () {
|
|
35
35
|
...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
|
36
36
|
]);
|
37
37
|
|
38
|
+
const formatMoney = (n, currency, options) => n.toLocaleString('en-US', {
|
39
|
+
style: 'currency',
|
40
|
+
currency: currency || 'USD',
|
41
|
+
...options,
|
42
|
+
});
|
43
|
+
|
38
44
|
const packageName = 'shopGPT';
|
39
45
|
|
40
46
|
var _a$1;
|
@@ -64,11 +70,11 @@ var ProvidersShopGptSdk = (function () {
|
|
64
70
|
const url = new URL(`/providers/shopGPT${path}`, baseURL);
|
65
71
|
return url;
|
66
72
|
};
|
67
|
-
const processQuery = async (query) => {
|
73
|
+
const processQuery = async (query, productHandle) => {
|
68
74
|
const response = await fetchImpl(getURL('/query'), {
|
69
75
|
method: 'POST',
|
70
76
|
headers: getHeaders(),
|
71
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
77
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
72
78
|
credentials: 'include',
|
73
79
|
});
|
74
80
|
if (!response.ok) {
|
@@ -217,20 +223,20 @@ var ProvidersShopGptSdk = (function () {
|
|
217
223
|
* Copyright 2019 Google LLC
|
218
224
|
* SPDX-License-Identifier: BSD-3-Clause
|
219
225
|
*/
|
220
|
-
const t$
|
226
|
+
const t$3=globalThis,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$3=new WeakMap;let n$3 = class n{constructor(t,e,o){if(this._$cssResult$=!0,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$6&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$5=t=>new n$3("string"==typeof t?t:t+"",void 0,s$2),i$3=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[o+1]),t[0]);return new n$3(o,t,s$2)},S$1=(s,o)=>{if(e$6)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$3.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$5(e)})(t):t;
|
221
227
|
|
222
228
|
/**
|
223
229
|
* @license
|
224
230
|
* Copyright 2017 Google LLC
|
225
231
|
* SPDX-License-Identifier: BSD-3-Clause
|
226
|
-
*/const{is:i$
|
232
|
+
*/const{is:i$2,defineProperty:e$5,getOwnPropertyDescriptor:r$4,getOwnPropertyNames:h$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$2}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$2(t,s),y$1={attribute:!0,type:String,converter:u$1,reflect:!1,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let b$1 = class b extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=y$1){if(s.state&&(s.attribute=!1),this._$Ei(),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(t,i,s);void 0!==r&&e$5(this.prototype,t,r);}}static getPropertyDescriptor(t,s,i){const{get:e,set:h}=r$4(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get(){return e?.call(this)},set(s){const r=e?.call(this);h.call(this,s),this.requestUpdate(t,r,i);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??y$1}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$2(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...h$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return !1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$EC(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&!0===i.reflect){const r=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==r?this.removeAttribute(e):this.setAttribute(e,r),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e,this[e]=r.fromAttribute(s,t.type),this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){if(i??=this.constructor.getPropertyOptions(t),!(i.hasChanged??f$1)(this[t],s))return;this.P(t,s,i);}!1===this.isUpdatePending&&(this._$ES=this._$ET());}P(t,s,i){this._$AL.has(t)||this._$AL.set(t,s),!0===i.reflect&&this._$Em!==t&&(this._$Ej??=new Set).add(t);}async _$ET(){this.isUpdatePending=!0;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t)!0!==i.wrapped||this._$AL.has(s)||void 0===this[s]||this.P(s,this[s],i);}let t=!1;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EU();}catch(s){throw t=!1,this._$EU(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$EU(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return !0}update(t){this._$Ej&&=this._$Ej.forEach((t=>this._$EC(t,this[t]))),this._$EU();}updated(t){}firstUpdated(t){}};b$1.elementStyles=[],b$1.shadowRootOptions={mode:"open"},b$1[d$1("elementProperties")]=new Map,b$1[d$1("finalized")]=new Map,p$1?.({ReactiveElement:b$1}),(a$1.reactiveElementVersions??=[]).push("2.0.4");
|
227
233
|
|
228
234
|
/**
|
229
235
|
* @license
|
230
236
|
* Copyright 2017 Google LLC
|
231
237
|
* SPDX-License-Identifier: BSD-3-Clause
|
232
238
|
*/
|
233
|
-
const t$
|
239
|
+
const t$2=globalThis,i$1=t$2.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$4="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$1="?"+h,n$1=`<${o$1}>`,r$3=document,l=()=>r$3.createComment(""),c=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a=Array.isArray,u=t=>a(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,_=/>/g,m=RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),p=/'/g,g=/"/g,$=/^(?:script|style|textarea|title)$/i,y=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x=y(1),b=y(2),w=Symbol.for("lit-noChange"),T=Symbol.for("lit-nothing"),A=new WeakMap,E=r$3.createTreeWalker(r$3,129);function C(t,i){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s$1?s$1.createHTML(i):i}const P=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"<svg>":"",c=f;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,y=0;for(;y<s.length&&(c.lastIndex=y,u=c.exec(s),null!==u);)y=c.lastIndex,c===f?"!--"===u[1]?c=v:void 0!==u[1]?c=_:void 0!==u[2]?($.test(u[2])&&(r=RegExp("</"+u[2],"g")),c=m):void 0!==u[3]&&(c=m):c===m?">"===u[0]?(c=r??f,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?m:'"'===u[3]?g:p):c===g||c===p?c=m:c===v||c===_?c=f:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f?s+n$1:d>=0?(o.push(a),s.slice(0,d)+e$4+s.slice(d)+h+x):s+h+(-2===d?i:x);}return [C(t,l+(t[s]||"<?>")+(2===i?"</svg>":"")),o]};class V{constructor({strings:t,_$litType$:s},n){let r;this.parts=[];let c=0,a=0;const u=t.length-1,d=this.parts,[f,v]=P(t,s);if(this.el=V.createElement(f,n),E.currentNode=this.el.content,2===s){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=E.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(e$4)){const i=v[a++],s=r.getAttribute(t).split(h),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:c,name:e[2],strings:s,ctor:"."===e[1]?k:"?"===e[1]?H:"@"===e[1]?I:R}),r.removeAttribute(t);}else t.startsWith(h)&&(d.push({type:6,index:c}),r.removeAttribute(t));if($.test(r.tagName)){const t=r.textContent.split(h),s=t.length-1;if(s>0){r.textContent=i$1?i$1.emptyScript:"";for(let i=0;i<s;i++)r.append(t[i],l()),E.nextNode(),d.push({type:2,index:++c});r.append(t[s],l());}}}else if(8===r.nodeType)if(r.data===o$1)d.push({type:2,index:c});else {let t=-1;for(;-1!==(t=r.data.indexOf(h,t+1));)d.push({type:7,index:c}),t+=h.length-1;}c++;}}static createElement(t,i){const s=r$3.createElement("template");return s.innerHTML=t,s}}function N(t,i,s=t,e){if(i===w)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=c(i)?void 0:i._$litDirective$;return h?.constructor!==o&&(h?._$AO?.(!1),void 0===o?h=void 0:(h=new o(t),h._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=h:s._$Cl=h),void 0!==h&&(i=N(t,h._$AS(t,i.values),h,e)),i}class S{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??r$3).importNode(i,!0);E.currentNode=e;let h=E.nextNode(),o=0,n=0,l=s[0];for(;void 0!==l;){if(o===l.index){let i;2===l.type?i=new M(h,h.nextSibling,this,t):1===l.type?i=new l.ctor(h,l.name,l.strings,this,t):6===l.type&&(i=new L(h,this,t)),this._$AV.push(i),l=s[++n];}o!==l?.index&&(h=E.nextNode(),o++);}return E.currentNode=r$3,e}p(t){let i=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class M{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=T,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??!0;}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=N(this,t,i),c(t)?t===T||null==t||""===t?(this._$AH!==T&&this._$AR(),this._$AH=T):t!==this._$AH&&t!==w&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):u(t)?this.k(t):this._(t);}S(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.S(t));}_(t){this._$AH!==T&&c(this._$AH)?this._$AA.nextSibling.data=t:this.T(r$3.createTextNode(t)),this._$AH=t;}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=V.createElement(C(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new S(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=A.get(t.strings);return void 0===i&&A.set(t.strings,i=new V(t)),i}k(t){a(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const h of t)e===i.length?i.push(s=new M(this.S(l()),this.S(l()),this,this.options)):s=i[e],s._$AI(h),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e);}_$AR(t=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i;}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t));}}class R{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,h){this.type=1,this._$AH=T,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=h,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=T;}_$AI(t,i=this,s,e){const h=this.strings;let o=!1;if(void 0===h)t=N(this,t,i,0),o=!c(t)||t!==this._$AH&&t!==w,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n<h.length-1;n++)r=N(this,e[s+n],i,n),r===w&&(r=this._$AH[n]),o||=!c(r)||r!==this._$AH[n],r===T?t=T:t!==T&&(t+=(r??"")+h[n+1]),this._$AH[n]=r;}o&&!e&&this.j(t);}j(t){t===T?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}}class k extends R{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===T?void 0:t;}}class H extends R{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==T);}}class I extends R{constructor(t,i,s,e,h){super(t,i,s,e,h),this.type=5;}_$AI(t,i=this){if((t=N(this,t,i,0)??T)===w)return;const s=this._$AH,e=t===T&&s!==T||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,h=t!==T&&(s===T||e);e&&this.element.removeEventListener(this.name,this,s),h&&this.element.addEventListener(this.name,this,t),this._$AH=t;}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t);}}class L{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s;}get _$AU(){return this._$AM._$AU}_$AI(t){N(this,t);}}const Z=t$2.litHtmlPolyfillSupport;Z?.(V,M),(t$2.litHtmlVersions??=[]).push("3.1.3");const j=(t,i,s)=>{const e=s?.renderBefore??i;let h=e._$litPart$;if(void 0===h){const t=s?.renderBefore??null;e._$litPart$=h=new M(i.insertBefore(l(),t),t,void 0,s??{});}return h._$AI(t),h};
|
234
240
|
|
235
241
|
/**
|
236
242
|
* @license
|
@@ -238,6 +244,19 @@ var ProvidersShopGptSdk = (function () {
|
|
238
244
|
* SPDX-License-Identifier: BSD-3-Clause
|
239
245
|
*/class s extends b$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=j(i,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1);}render(){return w}}s._$litElement$=!0,s[("finalized")]=!0,globalThis.litElementHydrateSupport?.({LitElement:s});const r$2=globalThis.litElementPolyfillSupport;r$2?.({LitElement:s});(globalThis.litElementVersions??=[]).push("4.0.5");
|
240
246
|
|
247
|
+
/**
|
248
|
+
* @license
|
249
|
+
* Copyright 2017 Google LLC
|
250
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
251
|
+
*/
|
252
|
+
const t$1={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e$3=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
|
253
|
+
|
254
|
+
/**
|
255
|
+
* @license
|
256
|
+
* Copyright 2018 Google LLC
|
257
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
258
|
+
*/const e$2=e$3(class extends i{constructor(t){if(super(t),t.type!==t$1.ATTRIBUTE||"class"!==t.name||t.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return w}});
|
259
|
+
|
241
260
|
/**
|
242
261
|
* @license
|
243
262
|
* Copyright 2017 Google LLC
|
@@ -302,7 +321,7 @@ var ProvidersShopGptSdk = (function () {
|
|
302
321
|
},
|
303
322
|
};
|
304
323
|
|
305
|
-
const shopGPTStyles = () => i$
|
324
|
+
const shopGPTStyles = () => i$3 `
|
306
325
|
:host {
|
307
326
|
position: fixed;
|
308
327
|
top: 0;
|
@@ -850,6 +869,7 @@ var ProvidersShopGptSdk = (function () {
|
|
850
869
|
.chat-input {
|
851
870
|
display: flex;
|
852
871
|
align-items: center;
|
872
|
+
margin: 0;
|
853
873
|
|
854
874
|
input {
|
855
875
|
flex: 1;
|
@@ -930,6 +950,9 @@ var ProvidersShopGptSdk = (function () {
|
|
930
950
|
|
931
951
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
932
952
|
const getImageProperties = (src) => {
|
953
|
+
if (!src) {
|
954
|
+
return;
|
955
|
+
}
|
933
956
|
const image = new URL(src);
|
934
957
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
935
958
|
image.searchParams.set('width', width.toString());
|
@@ -978,6 +1001,7 @@ var ProvidersShopGptSdk = (function () {
|
|
978
1001
|
return;
|
979
1002
|
}
|
980
1003
|
await this.loadHistory();
|
1004
|
+
await this.loadInitialQuery();
|
981
1005
|
});
|
982
1006
|
}
|
983
1007
|
async loadHistory() {
|
@@ -1010,6 +1034,31 @@ var ProvidersShopGptSdk = (function () {
|
|
1010
1034
|
this.isLoadingHistory = false;
|
1011
1035
|
}
|
1012
1036
|
}
|
1037
|
+
async loadInitialQuery() {
|
1038
|
+
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1039
|
+
if (this.chatbotMessages.length) {
|
1040
|
+
return;
|
1041
|
+
}
|
1042
|
+
try {
|
1043
|
+
this.isTyping = true;
|
1044
|
+
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1045
|
+
this.chatbotMessages = [
|
1046
|
+
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1047
|
+
...this.chatbotMessages,
|
1048
|
+
];
|
1049
|
+
this.recommendedProduct = reply.products[0];
|
1050
|
+
this.moreRecommendations = reply.products.slice(1, 4);
|
1051
|
+
this.setChatWindowHeight();
|
1052
|
+
}
|
1053
|
+
catch (error) {
|
1054
|
+
logger.error(error);
|
1055
|
+
this.resetProductRecommendations();
|
1056
|
+
this.isFailed = true;
|
1057
|
+
}
|
1058
|
+
finally {
|
1059
|
+
this.isTyping = false;
|
1060
|
+
}
|
1061
|
+
}
|
1013
1062
|
redirect(url) {
|
1014
1063
|
var _a;
|
1015
1064
|
if (!url) {
|
@@ -1065,9 +1114,10 @@ var ProvidersShopGptSdk = (function () {
|
|
1065
1114
|
this.isTyping = false;
|
1066
1115
|
}
|
1067
1116
|
}
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1117
|
+
getLocalPrice(price) {
|
1118
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1119
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1120
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1071
1121
|
}
|
1072
1122
|
handleShowMore(value) {
|
1073
1123
|
if (!this.chatWindowElement) {
|
@@ -1112,9 +1162,10 @@ var ProvidersShopGptSdk = (function () {
|
|
1112
1162
|
var _a;
|
1113
1163
|
return x `
|
1114
1164
|
<div
|
1115
|
-
class
|
1116
|
-
|
1117
|
-
:
|
1165
|
+
class=${e$2({
|
1166
|
+
'products-section': true,
|
1167
|
+
'no-recommended-product': !this.recommendedProduct,
|
1168
|
+
})}
|
1118
1169
|
>
|
1119
1170
|
<div class="product-section recommended-product">
|
1120
1171
|
<h2>Recommended product</h2>
|
@@ -1150,13 +1201,12 @@ var ProvidersShopGptSdk = (function () {
|
|
1150
1201
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1151
1202
|
this.recommendedProduct.variants[0].price
|
1152
1203
|
? x `<p class="compared-at-price">
|
1153
|
-
${this.
|
1154
|
-
.
|
1204
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1205
|
+
.comparedAtPrice)}
|
1155
1206
|
</p>`
|
1156
1207
|
: T}
|
1157
1208
|
<p class="price">
|
1158
|
-
${this.
|
1159
|
-
.variants[0].price}
|
1209
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1160
1210
|
</p>
|
1161
1211
|
</div>
|
1162
1212
|
<button
|
@@ -1171,9 +1221,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1171
1221
|
</div>
|
1172
1222
|
|
1173
1223
|
<div
|
1174
|
-
class
|
1175
|
-
|
1176
|
-
:
|
1224
|
+
class=${e$2({
|
1225
|
+
'product-section': true,
|
1226
|
+
'more-recommendations': true,
|
1227
|
+
'show-more-sml': this.showMore,
|
1228
|
+
})}
|
1177
1229
|
>
|
1178
1230
|
<h2>More Recommendations</h2>
|
1179
1231
|
${this.moreRecommendations.length === 0
|
@@ -1185,12 +1237,13 @@ var ProvidersShopGptSdk = (function () {
|
|
1185
1237
|
`
|
1186
1238
|
: x `<div class="products">
|
1187
1239
|
${this.moreRecommendations.map((product) => {
|
1188
|
-
|
1240
|
+
var _a, _b, _c;
|
1241
|
+
const imageProperties = getImageProperties((_a = product === null || product === void 0 ? void 0 : product.image) === null || _a === void 0 ? void 0 : _a.url);
|
1189
1242
|
return x `
|
1190
1243
|
<div class="product">
|
1191
1244
|
<img
|
1192
|
-
srcset=${imageProperties.srcset}
|
1193
|
-
sizes=${imageProperties.sizes}
|
1245
|
+
srcset=${(_b = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.srcset) !== null && _b !== void 0 ? _b : T}
|
1246
|
+
sizes=${(_c = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.sizes) !== null && _c !== void 0 ? _c : T}
|
1194
1247
|
src=${product.image.url}
|
1195
1248
|
alt=${product.image.alt}
|
1196
1249
|
@click=${() => this.redirect(product.url)}
|
@@ -1207,13 +1260,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1207
1260
|
product.variants[0].comparedAtPrice !==
|
1208
1261
|
product.variants[0].price
|
1209
1262
|
? x `<p class="compared-at-price">
|
1210
|
-
${this.
|
1211
|
-
.comparedAtPrice}
|
1263
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1212
1264
|
</p>`
|
1213
1265
|
: T}
|
1214
1266
|
<p class="price">
|
1215
|
-
${this.
|
1216
|
-
.price}
|
1267
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1217
1268
|
</p>
|
1218
1269
|
</div>
|
1219
1270
|
</div>
|
@@ -1240,17 +1291,6 @@ var ProvidersShopGptSdk = (function () {
|
|
1240
1291
|
if (this.isLoadingHistory) {
|
1241
1292
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1242
1293
|
}
|
1243
|
-
if (this.chatbotMessages.length === 0) {
|
1244
|
-
return x `
|
1245
|
-
<div class="chat-header">
|
1246
|
-
<div class="chat-header-title">ShopGPT</div>
|
1247
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1248
|
-
<div class="chat-header-description">
|
1249
|
-
Hi, type a message to get started!
|
1250
|
-
</div>
|
1251
|
-
</div>
|
1252
|
-
`;
|
1253
|
-
}
|
1254
1294
|
return x `
|
1255
1295
|
<div class="chat-window">
|
1256
1296
|
${this.isTyping
|
@@ -1273,7 +1313,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1273
1313
|
<div class="bot-message-container">
|
1274
1314
|
${botIcon()}
|
1275
1315
|
<div class="message bot">
|
1276
|
-
|
1316
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1277
1317
|
${message.product
|
1278
1318
|
? x `<div class="product">
|
1279
1319
|
<img
|
@@ -1294,13 +1334,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1294
1334
|
message.product.variants[0].comparedAtPrice !==
|
1295
1335
|
message.product.variants[0].comparedAtPrice
|
1296
1336
|
? x `<p class="compared-at-price">
|
1297
|
-
${this.
|
1298
|
-
.variants[0].comparedAtPrice}
|
1337
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1299
1338
|
</p>`
|
1300
1339
|
: T}
|
1301
1340
|
<p class="price">
|
1302
|
-
${this.
|
1303
|
-
.variants[0].price}
|
1341
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1304
1342
|
</p>
|
1305
1343
|
</div>
|
1306
1344
|
</div>
|
package/index.mjs
CHANGED
@@ -32,6 +32,12 @@ new Set([
|
|
32
32
|
...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
|
33
33
|
]);
|
34
34
|
|
35
|
+
const formatMoney = (n, currency, options) => n.toLocaleString('en-US', {
|
36
|
+
style: 'currency',
|
37
|
+
currency: currency || 'USD',
|
38
|
+
...options,
|
39
|
+
});
|
40
|
+
|
35
41
|
const packageName = 'shopGPT';
|
36
42
|
|
37
43
|
var _a$1;
|
@@ -61,11 +67,11 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
61
67
|
const url = new URL(`/providers/shopGPT${path}`, baseURL);
|
62
68
|
return url;
|
63
69
|
};
|
64
|
-
const processQuery = async (query) => {
|
70
|
+
const processQuery = async (query, productHandle) => {
|
65
71
|
const response = await fetchImpl(getURL('/query'), {
|
66
72
|
method: 'POST',
|
67
73
|
headers: getHeaders(),
|
68
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
74
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
69
75
|
credentials: 'include',
|
70
76
|
});
|
71
77
|
if (!response.ok) {
|
@@ -214,20 +220,20 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
214
220
|
* Copyright 2019 Google LLC
|
215
221
|
* SPDX-License-Identifier: BSD-3-Clause
|
216
222
|
*/
|
217
|
-
const t$
|
223
|
+
const t$3=globalThis,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$3=new WeakMap;let n$3 = class n{constructor(t,e,o){if(this._$cssResult$=!0,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$6&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$5=t=>new n$3("string"==typeof t?t:t+"",void 0,s$2),i$3=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[o+1]),t[0]);return new n$3(o,t,s$2)},S$1=(s,o)=>{if(e$6)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$3.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$5(e)})(t):t;
|
218
224
|
|
219
225
|
/**
|
220
226
|
* @license
|
221
227
|
* Copyright 2017 Google LLC
|
222
228
|
* SPDX-License-Identifier: BSD-3-Clause
|
223
|
-
*/const{is:i$
|
229
|
+
*/const{is:i$2,defineProperty:e$5,getOwnPropertyDescriptor:r$4,getOwnPropertyNames:h$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$2}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$2(t,s),y$1={attribute:!0,type:String,converter:u$1,reflect:!1,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let b$1 = class b extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=y$1){if(s.state&&(s.attribute=!1),this._$Ei(),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(t,i,s);void 0!==r&&e$5(this.prototype,t,r);}}static getPropertyDescriptor(t,s,i){const{get:e,set:h}=r$4(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get(){return e?.call(this)},set(s){const r=e?.call(this);h.call(this,s),this.requestUpdate(t,r,i);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??y$1}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$2(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...h$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return !1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$EC(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&!0===i.reflect){const r=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==r?this.removeAttribute(e):this.setAttribute(e,r),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e,this[e]=r.fromAttribute(s,t.type),this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){if(i??=this.constructor.getPropertyOptions(t),!(i.hasChanged??f$1)(this[t],s))return;this.P(t,s,i);}!1===this.isUpdatePending&&(this._$ES=this._$ET());}P(t,s,i){this._$AL.has(t)||this._$AL.set(t,s),!0===i.reflect&&this._$Em!==t&&(this._$Ej??=new Set).add(t);}async _$ET(){this.isUpdatePending=!0;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t)!0!==i.wrapped||this._$AL.has(s)||void 0===this[s]||this.P(s,this[s],i);}let t=!1;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EU();}catch(s){throw t=!1,this._$EU(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$EU(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return !0}update(t){this._$Ej&&=this._$Ej.forEach((t=>this._$EC(t,this[t]))),this._$EU();}updated(t){}firstUpdated(t){}};b$1.elementStyles=[],b$1.shadowRootOptions={mode:"open"},b$1[d$1("elementProperties")]=new Map,b$1[d$1("finalized")]=new Map,p$1?.({ReactiveElement:b$1}),(a$1.reactiveElementVersions??=[]).push("2.0.4");
|
224
230
|
|
225
231
|
/**
|
226
232
|
* @license
|
227
233
|
* Copyright 2017 Google LLC
|
228
234
|
* SPDX-License-Identifier: BSD-3-Clause
|
229
235
|
*/
|
230
|
-
const t$
|
236
|
+
const t$2=globalThis,i$1=t$2.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$4="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$1="?"+h,n$1=`<${o$1}>`,r$3=document,l=()=>r$3.createComment(""),c=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a=Array.isArray,u=t=>a(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,_=/>/g,m=RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),p=/'/g,g=/"/g,$=/^(?:script|style|textarea|title)$/i,y=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x=y(1),b=y(2),w=Symbol.for("lit-noChange"),T=Symbol.for("lit-nothing"),A=new WeakMap,E=r$3.createTreeWalker(r$3,129);function C(t,i){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s$1?s$1.createHTML(i):i}const P=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"<svg>":"",c=f;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,y=0;for(;y<s.length&&(c.lastIndex=y,u=c.exec(s),null!==u);)y=c.lastIndex,c===f?"!--"===u[1]?c=v:void 0!==u[1]?c=_:void 0!==u[2]?($.test(u[2])&&(r=RegExp("</"+u[2],"g")),c=m):void 0!==u[3]&&(c=m):c===m?">"===u[0]?(c=r??f,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?m:'"'===u[3]?g:p):c===g||c===p?c=m:c===v||c===_?c=f:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f?s+n$1:d>=0?(o.push(a),s.slice(0,d)+e$4+s.slice(d)+h+x):s+h+(-2===d?i:x);}return [C(t,l+(t[s]||"<?>")+(2===i?"</svg>":"")),o]};class V{constructor({strings:t,_$litType$:s},n){let r;this.parts=[];let c=0,a=0;const u=t.length-1,d=this.parts,[f,v]=P(t,s);if(this.el=V.createElement(f,n),E.currentNode=this.el.content,2===s){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=E.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(e$4)){const i=v[a++],s=r.getAttribute(t).split(h),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:c,name:e[2],strings:s,ctor:"."===e[1]?k:"?"===e[1]?H:"@"===e[1]?I:R}),r.removeAttribute(t);}else t.startsWith(h)&&(d.push({type:6,index:c}),r.removeAttribute(t));if($.test(r.tagName)){const t=r.textContent.split(h),s=t.length-1;if(s>0){r.textContent=i$1?i$1.emptyScript:"";for(let i=0;i<s;i++)r.append(t[i],l()),E.nextNode(),d.push({type:2,index:++c});r.append(t[s],l());}}}else if(8===r.nodeType)if(r.data===o$1)d.push({type:2,index:c});else {let t=-1;for(;-1!==(t=r.data.indexOf(h,t+1));)d.push({type:7,index:c}),t+=h.length-1;}c++;}}static createElement(t,i){const s=r$3.createElement("template");return s.innerHTML=t,s}}function N(t,i,s=t,e){if(i===w)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=c(i)?void 0:i._$litDirective$;return h?.constructor!==o&&(h?._$AO?.(!1),void 0===o?h=void 0:(h=new o(t),h._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=h:s._$Cl=h),void 0!==h&&(i=N(t,h._$AS(t,i.values),h,e)),i}class S{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??r$3).importNode(i,!0);E.currentNode=e;let h=E.nextNode(),o=0,n=0,l=s[0];for(;void 0!==l;){if(o===l.index){let i;2===l.type?i=new M(h,h.nextSibling,this,t):1===l.type?i=new l.ctor(h,l.name,l.strings,this,t):6===l.type&&(i=new L(h,this,t)),this._$AV.push(i),l=s[++n];}o!==l?.index&&(h=E.nextNode(),o++);}return E.currentNode=r$3,e}p(t){let i=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class M{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=T,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??!0;}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=N(this,t,i),c(t)?t===T||null==t||""===t?(this._$AH!==T&&this._$AR(),this._$AH=T):t!==this._$AH&&t!==w&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):u(t)?this.k(t):this._(t);}S(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.S(t));}_(t){this._$AH!==T&&c(this._$AH)?this._$AA.nextSibling.data=t:this.T(r$3.createTextNode(t)),this._$AH=t;}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=V.createElement(C(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new S(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=A.get(t.strings);return void 0===i&&A.set(t.strings,i=new V(t)),i}k(t){a(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const h of t)e===i.length?i.push(s=new M(this.S(l()),this.S(l()),this,this.options)):s=i[e],s._$AI(h),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e);}_$AR(t=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i;}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t));}}class R{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,h){this.type=1,this._$AH=T,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=h,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=T;}_$AI(t,i=this,s,e){const h=this.strings;let o=!1;if(void 0===h)t=N(this,t,i,0),o=!c(t)||t!==this._$AH&&t!==w,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n<h.length-1;n++)r=N(this,e[s+n],i,n),r===w&&(r=this._$AH[n]),o||=!c(r)||r!==this._$AH[n],r===T?t=T:t!==T&&(t+=(r??"")+h[n+1]),this._$AH[n]=r;}o&&!e&&this.j(t);}j(t){t===T?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}}class k extends R{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===T?void 0:t;}}class H extends R{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==T);}}class I extends R{constructor(t,i,s,e,h){super(t,i,s,e,h),this.type=5;}_$AI(t,i=this){if((t=N(this,t,i,0)??T)===w)return;const s=this._$AH,e=t===T&&s!==T||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,h=t!==T&&(s===T||e);e&&this.element.removeEventListener(this.name,this,s),h&&this.element.addEventListener(this.name,this,t),this._$AH=t;}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t);}}class L{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s;}get _$AU(){return this._$AM._$AU}_$AI(t){N(this,t);}}const Z=t$2.litHtmlPolyfillSupport;Z?.(V,M),(t$2.litHtmlVersions??=[]).push("3.1.3");const j=(t,i,s)=>{const e=s?.renderBefore??i;let h=e._$litPart$;if(void 0===h){const t=s?.renderBefore??null;e._$litPart$=h=new M(i.insertBefore(l(),t),t,void 0,s??{});}return h._$AI(t),h};
|
231
237
|
|
232
238
|
/**
|
233
239
|
* @license
|
@@ -235,6 +241,19 @@ const t$1=globalThis,i=t$1.trustedTypes,s$1=i?i.createPolicy("lit-html",{createH
|
|
235
241
|
* SPDX-License-Identifier: BSD-3-Clause
|
236
242
|
*/class s extends b$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=j(i,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1);}render(){return w}}s._$litElement$=!0,s[("finalized")]=!0,globalThis.litElementHydrateSupport?.({LitElement:s});const r$2=globalThis.litElementPolyfillSupport;r$2?.({LitElement:s});(globalThis.litElementVersions??=[]).push("4.0.5");
|
237
243
|
|
244
|
+
/**
|
245
|
+
* @license
|
246
|
+
* Copyright 2017 Google LLC
|
247
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
248
|
+
*/
|
249
|
+
const t$1={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e$3=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* @license
|
253
|
+
* Copyright 2018 Google LLC
|
254
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
255
|
+
*/const e$2=e$3(class extends i{constructor(t){if(super(t),t.type!==t$1.ATTRIBUTE||"class"!==t.name||t.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return w}});
|
256
|
+
|
238
257
|
/**
|
239
258
|
* @license
|
240
259
|
* Copyright 2017 Google LLC
|
@@ -299,7 +318,7 @@ const logger = {
|
|
299
318
|
},
|
300
319
|
};
|
301
320
|
|
302
|
-
const shopGPTStyles = () => i$
|
321
|
+
const shopGPTStyles = () => i$3 `
|
303
322
|
:host {
|
304
323
|
position: fixed;
|
305
324
|
top: 0;
|
@@ -847,6 +866,7 @@ const shopGPTStyles = () => i$2 `
|
|
847
866
|
.chat-input {
|
848
867
|
display: flex;
|
849
868
|
align-items: center;
|
869
|
+
margin: 0;
|
850
870
|
|
851
871
|
input {
|
852
872
|
flex: 1;
|
@@ -927,6 +947,9 @@ const botIcon = () => b `
|
|
927
947
|
|
928
948
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
929
949
|
const getImageProperties = (src) => {
|
950
|
+
if (!src) {
|
951
|
+
return;
|
952
|
+
}
|
930
953
|
const image = new URL(src);
|
931
954
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
932
955
|
image.searchParams.set('width', width.toString());
|
@@ -975,6 +998,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
975
998
|
return;
|
976
999
|
}
|
977
1000
|
await this.loadHistory();
|
1001
|
+
await this.loadInitialQuery();
|
978
1002
|
});
|
979
1003
|
}
|
980
1004
|
async loadHistory() {
|
@@ -1007,6 +1031,31 @@ let ShopGPT = class ShopGPT extends s {
|
|
1007
1031
|
this.isLoadingHistory = false;
|
1008
1032
|
}
|
1009
1033
|
}
|
1034
|
+
async loadInitialQuery() {
|
1035
|
+
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1036
|
+
if (this.chatbotMessages.length) {
|
1037
|
+
return;
|
1038
|
+
}
|
1039
|
+
try {
|
1040
|
+
this.isTyping = true;
|
1041
|
+
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1042
|
+
this.chatbotMessages = [
|
1043
|
+
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1044
|
+
...this.chatbotMessages,
|
1045
|
+
];
|
1046
|
+
this.recommendedProduct = reply.products[0];
|
1047
|
+
this.moreRecommendations = reply.products.slice(1, 4);
|
1048
|
+
this.setChatWindowHeight();
|
1049
|
+
}
|
1050
|
+
catch (error) {
|
1051
|
+
logger.error(error);
|
1052
|
+
this.resetProductRecommendations();
|
1053
|
+
this.isFailed = true;
|
1054
|
+
}
|
1055
|
+
finally {
|
1056
|
+
this.isTyping = false;
|
1057
|
+
}
|
1058
|
+
}
|
1010
1059
|
redirect(url) {
|
1011
1060
|
var _a;
|
1012
1061
|
if (!url) {
|
@@ -1062,9 +1111,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1062
1111
|
this.isTyping = false;
|
1063
1112
|
}
|
1064
1113
|
}
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1114
|
+
getLocalPrice(price) {
|
1115
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1116
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1117
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1068
1118
|
}
|
1069
1119
|
handleShowMore(value) {
|
1070
1120
|
if (!this.chatWindowElement) {
|
@@ -1109,9 +1159,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1109
1159
|
var _a;
|
1110
1160
|
return x `
|
1111
1161
|
<div
|
1112
|
-
class
|
1113
|
-
|
1114
|
-
:
|
1162
|
+
class=${e$2({
|
1163
|
+
'products-section': true,
|
1164
|
+
'no-recommended-product': !this.recommendedProduct,
|
1165
|
+
})}
|
1115
1166
|
>
|
1116
1167
|
<div class="product-section recommended-product">
|
1117
1168
|
<h2>Recommended product</h2>
|
@@ -1147,13 +1198,12 @@ let ShopGPT = class ShopGPT extends s {
|
|
1147
1198
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1148
1199
|
this.recommendedProduct.variants[0].price
|
1149
1200
|
? x `<p class="compared-at-price">
|
1150
|
-
${this.
|
1151
|
-
.
|
1201
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1202
|
+
.comparedAtPrice)}
|
1152
1203
|
</p>`
|
1153
1204
|
: T}
|
1154
1205
|
<p class="price">
|
1155
|
-
${this.
|
1156
|
-
.variants[0].price}
|
1206
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1157
1207
|
</p>
|
1158
1208
|
</div>
|
1159
1209
|
<button
|
@@ -1168,9 +1218,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1168
1218
|
</div>
|
1169
1219
|
|
1170
1220
|
<div
|
1171
|
-
class
|
1172
|
-
|
1173
|
-
:
|
1221
|
+
class=${e$2({
|
1222
|
+
'product-section': true,
|
1223
|
+
'more-recommendations': true,
|
1224
|
+
'show-more-sml': this.showMore,
|
1225
|
+
})}
|
1174
1226
|
>
|
1175
1227
|
<h2>More Recommendations</h2>
|
1176
1228
|
${this.moreRecommendations.length === 0
|
@@ -1182,12 +1234,13 @@ let ShopGPT = class ShopGPT extends s {
|
|
1182
1234
|
`
|
1183
1235
|
: x `<div class="products">
|
1184
1236
|
${this.moreRecommendations.map((product) => {
|
1185
|
-
|
1237
|
+
var _a, _b, _c;
|
1238
|
+
const imageProperties = getImageProperties((_a = product === null || product === void 0 ? void 0 : product.image) === null || _a === void 0 ? void 0 : _a.url);
|
1186
1239
|
return x `
|
1187
1240
|
<div class="product">
|
1188
1241
|
<img
|
1189
|
-
srcset=${imageProperties.srcset}
|
1190
|
-
sizes=${imageProperties.sizes}
|
1242
|
+
srcset=${(_b = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.srcset) !== null && _b !== void 0 ? _b : T}
|
1243
|
+
sizes=${(_c = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.sizes) !== null && _c !== void 0 ? _c : T}
|
1191
1244
|
src=${product.image.url}
|
1192
1245
|
alt=${product.image.alt}
|
1193
1246
|
@click=${() => this.redirect(product.url)}
|
@@ -1204,13 +1257,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1204
1257
|
product.variants[0].comparedAtPrice !==
|
1205
1258
|
product.variants[0].price
|
1206
1259
|
? x `<p class="compared-at-price">
|
1207
|
-
${this.
|
1208
|
-
.comparedAtPrice}
|
1260
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1209
1261
|
</p>`
|
1210
1262
|
: T}
|
1211
1263
|
<p class="price">
|
1212
|
-
${this.
|
1213
|
-
.price}
|
1264
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1214
1265
|
</p>
|
1215
1266
|
</div>
|
1216
1267
|
</div>
|
@@ -1237,17 +1288,6 @@ let ShopGPT = class ShopGPT extends s {
|
|
1237
1288
|
if (this.isLoadingHistory) {
|
1238
1289
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1239
1290
|
}
|
1240
|
-
if (this.chatbotMessages.length === 0) {
|
1241
|
-
return x `
|
1242
|
-
<div class="chat-header">
|
1243
|
-
<div class="chat-header-title">ShopGPT</div>
|
1244
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1245
|
-
<div class="chat-header-description">
|
1246
|
-
Hi, type a message to get started!
|
1247
|
-
</div>
|
1248
|
-
</div>
|
1249
|
-
`;
|
1250
|
-
}
|
1251
1291
|
return x `
|
1252
1292
|
<div class="chat-window">
|
1253
1293
|
${this.isTyping
|
@@ -1270,7 +1310,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1270
1310
|
<div class="bot-message-container">
|
1271
1311
|
${botIcon()}
|
1272
1312
|
<div class="message bot">
|
1273
|
-
|
1313
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1274
1314
|
${message.product
|
1275
1315
|
? x `<div class="product">
|
1276
1316
|
<img
|
@@ -1291,13 +1331,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1291
1331
|
message.product.variants[0].comparedAtPrice !==
|
1292
1332
|
message.product.variants[0].comparedAtPrice
|
1293
1333
|
? x `<p class="compared-at-price">
|
1294
|
-
${this.
|
1295
|
-
.variants[0].comparedAtPrice}
|
1334
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1296
1335
|
</p>`
|
1297
1336
|
: T}
|
1298
1337
|
<p class="price">
|
1299
|
-
${this.
|
1300
|
-
.variants[0].price}
|
1338
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1301
1339
|
</p>
|
1302
1340
|
</div>
|
1303
1341
|
</div>
|
package/package.json
CHANGED
@@ -25,6 +25,13 @@ const createShopApi = (fetchOverride = window.fetch) => ({
|
|
25
25
|
throw new Error(`Could not add items`, { cause: await response.text() });
|
26
26
|
}
|
27
27
|
},
|
28
|
+
getSiteCurrency() {
|
29
|
+
var _a, _b, _c, _d;
|
30
|
+
return {
|
31
|
+
currency: ((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.currency) === null || _b === void 0 ? void 0 : _b.active) || 'USD',
|
32
|
+
rate: parseFloat(((_d = (_c = window.Shopify) === null || _c === void 0 ? void 0 : _c.currency) === null || _d === void 0 ? void 0 : _d.rate) || '1'),
|
33
|
+
};
|
34
|
+
},
|
28
35
|
getCurrentProductHandle() {
|
29
36
|
const pathname = window.location.pathname;
|
30
37
|
return pathname.split('/').at(-1);
|
package/stores/shopify/index.js
CHANGED
@@ -26,6 +26,13 @@
|
|
26
26
|
throw new Error(`Could not add items`, { cause: await response.text() });
|
27
27
|
}
|
28
28
|
},
|
29
|
+
getSiteCurrency() {
|
30
|
+
var _a, _b, _c, _d;
|
31
|
+
return {
|
32
|
+
currency: ((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.currency) === null || _b === void 0 ? void 0 : _b.active) || 'USD',
|
33
|
+
rate: parseFloat(((_d = (_c = window.Shopify) === null || _c === void 0 ? void 0 : _c.currency) === null || _d === void 0 ? void 0 : _d.rate) || '1'),
|
34
|
+
};
|
35
|
+
},
|
29
36
|
getCurrentProductHandle() {
|
30
37
|
const pathname = window.location.pathname;
|
31
38
|
return pathname.split('/').at(-1);
|
package/stores/shopify/index.mjs
CHANGED
@@ -23,6 +23,13 @@ const createShopApi = (fetchOverride = window.fetch) => ({
|
|
23
23
|
throw new Error(`Could not add items`, { cause: await response.text() });
|
24
24
|
}
|
25
25
|
},
|
26
|
+
getSiteCurrency() {
|
27
|
+
var _a, _b, _c, _d;
|
28
|
+
return {
|
29
|
+
currency: ((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.currency) === null || _b === void 0 ? void 0 : _b.active) || 'USD',
|
30
|
+
rate: parseFloat(((_d = (_c = window.Shopify) === null || _c === void 0 ? void 0 : _c.currency) === null || _d === void 0 ? void 0 : _d.rate) || '1'),
|
31
|
+
};
|
32
|
+
},
|
26
33
|
getCurrentProductHandle() {
|
27
34
|
const pathname = window.location.pathname;
|
28
35
|
return pathname.split('/').at(-1);
|