@swell/apps-sdk 1.0.104 → 1.0.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +3 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -945,6 +945,6 @@ Shopify.routes = Shopify.routes || {};
|
|
|
945
945
|
Shopify.routes.root = "/";
|
|
946
946
|
${o.join(`
|
|
947
947
|
`)}</script>`}getMenuData(e){return Ne(this,e)}getFontData(e){return Ie(this,e)}getFormData(e){return He(this,e)}getFontFromShopifySetting(e){return C2(e)}getThemeConfig(e){return u2(e)}getPresetsConfig(e){return m2(e)}getEditorConfig(e){let{locale:t}=this.swell.getStorefrontLocalization();return c2(e,t)}getSectionConfigSchema(e){let{locale:t}=this.swell.getStorefrontLocalization();return p2(e,t)}async getLocaleConfig(e,t="en",i=".json"){let r=await e.getThemeConfigsByPath("theme/locales/",i),o=r.get(`theme/locales/${t}${i}`)??null;if(!o){let a=t.split("-")[0];if(o=r.get(`theme/locales/${a}${i}`)??null,!o){let s=`.default${i}`;for(let l of r.values())if(l?.file_path?.endsWith(s)){o=l;break}}}if(o){o=await e.getThemeConfig(o.file_path);try{return JSON.parse(o?.file_data||"")}catch{}}return{}}async getEditorLocaleConfig(e,t){if(this.editorLocaleConfig?.[t])return this.editorLocaleConfig[t];let i=await this.getLocaleConfig(e,t,".schema.json");return this.editorLocaleConfig={[t]:i},i}async renderSchemaTranslations(e,t,i="en"){if(!C6(t))return t;let r=await this.getEditorLocaleConfig(e,i);return this.renderSchemaTranslationValue(e,t,i,r)}async renderSchemaTranslationValue(e,t,i,r){switch(typeof t){case"string":{if(t.startsWith("t:")){let o=t.slice(2),a=o?.split("."),s=a.pop()||"",l=a.join(".");return p6(r,l)?.[s]??o}break}case"object":{if(Array.isArray(t)){let o=[];for(let a of t)o.push(await this.renderSchemaTranslationValue(e,a,i,r));return o}if(t!==null){let o={...t};for(let[a,s]of Object.entries(t))o[a]=await this.renderSchemaTranslationValue(e,s,i,r);return o}break}default:break}return t}getPageType(e){return this.shopifyCompatibilityConfig?.page_types?.[e]||e}getPageRouteUrl(e){return this.theme.props.pages?.find(t=>t.id===e)?.url||e}getPageRoutes(){let e={account_addresses_url:this.getPageRouteUrl("account/addresses"),account_login_url:this.getPageRouteUrl("account/login"),account_logout_url:this.getPageRouteUrl("account/logout"),account_recover_url:this.getPageRouteUrl("account/recover"),account_register_url:this.getPageRouteUrl("account/signup"),account_url:this.getPageRouteUrl("account/index"),all_products_collection_url:this.getPageRouteUrl("products/index"),cart_add_url:this.getPageRouteUrl("cart/add"),cart_change_url:this.getPageRouteUrl("cart/change"),cart_clear_url:this.getPageRouteUrl("cart/clear"),cart_update_url:this.getPageRouteUrl("cart/update"),cart_url:this.getPageRouteUrl("cart/index"),collections_url:this.getPageRouteUrl("categories/index"),predictive_search_url:this.getPageRouteUrl("search/suggest"),product_recommendations_url:this.getPageRouteUrl("products/index"),root_url:this.getPageRouteUrl("index"),search_url:this.getPageRouteUrl("search")};if(this.shopifyCompatibilityConfig?.page_routes)for(let[t,i]of Object.entries(this.shopifyCompatibilityConfig.page_routes))i&&typeof i=="object"&&i.page_id?e[t]=this.getPageRouteUrl(i.page_id):typeof i=="string"&&(e[t]=i);return e}getLocalizationObject(e,t){return M3(this,e,t)}getAdaptedPageUrl(e){if(!e)return;let t,i,r={},[o,a]=e.split("?"),s=o.split("."),l=s[1]?s.pop():null,[,h,u,d]=s.join(".").split("/");switch(l==="js"&&(i="json"),h){case"account":switch(u){case"order":t="account/order",r.id=d;break;case"register":t="account/login";break;default:break}break;case"blog":u&&(t="blogs/category",r.category=u),d&&(t="blogs/blog",r.slug=d);break;case"collections":u?u==="all"?t="products/index":(t="categories/category",r.slug=u):t="categories/index";break;case"gift_card":u&&(t="gift-card",r.code=u);break}if(t){let m=this.getPageRouteUrl(t);if(m)return m.replace(/:(\w+)/g,(g,C)=>r[C])+(l?`.${l}`:"")+(a?`?${a}`:"")}else if(i)return o.replace(new RegExp(`.${l}$`),`.${i}`)+(a?`?${a}`:"")}getThemeFilePath(e,t){switch(e){case"assets":return`assets/${t}`;case"components":return`snippets/${t}`;case"config":return`config/${t}`;case"layouts":return`layout/${t}`;case"templates":return`templates/${this.getPageType(t)}`;case"sections":return`sections/${t}`;default:throw new Error(`Theme file type not supported: ${e}`)}}getPageResourceMap(){return this.shopifyCompatibilityConfig?.page_resources?this.shopifyCompatibilityConfig.page_resources.reduce((e,t)=>e.set(t.page,{page:t.page,resources:t.resources.map(({from:i,to:r,object:o})=>{let a=r4[o];if(!a)throw new Error(`ShopifyObject for '${o}' not found.`);return{from:i,to:r,object:a}})}),new Map):new Map}getObjectResourceMap(){return this.shopifyCompatibilityConfig?.object_resources?this.shopifyCompatibilityConfig.object_resources.reduce((e,t)=>{let i=r4[t.object];if(!i)throw new Error(`ShopifyObject for '${t.object}' not found.`);return e.set(t.from,{from:t.from,object:i})},new Map):new Map}getFormResourceMap(){return this.shopifyCompatibilityConfig?.forms?this.shopifyCompatibilityConfig.forms.map(e=>({shopifyType:e.shopify_type,type:e.id})):[]}getQueryParamsMap(){return[{from:"sort_by",to:"sort"},{from(e){return e.startsWith("filter.v.")},to(e,t){let i=e.split("filter.v.")[1],r=t;return{[i]:r}}}]}getAllCountryOptionTags(e){return e?e.countries?.map(t=>{if(!t)return"";let i=(e.states||[]).filter(o=>o.country===t.id).map(o=>[o.id,o.name]),r=JSON.stringify(i).replace(/"/g,""");return`<option value="${t.id}" data-provinces="${r}">${t.name}</option>`}).filter(Boolean).join(`
|
|
948
|
-
`):""}isScriptFormActionUrl(e){if(!e)return!1;let t=this.shopifyCompatibilityConfig?.editor_configs?.script_actions_routes||{};for(let i of Object.values(t))if(e===i)return!0;return!1}isScriptUrl(e){if(!e)return!1;let t=this.shopifyCompatibilityConfig?.editor_configs?.script_routes||{};for(let i of Object.values(t))if(e.startsWith(i))return!0;return!1}needRedirectToPageStart(e){return e?(this.shopifyCompatibilityConfig?.editor_configs?.redirect_to_page_start_forms||[]).includes(e):!1}isCheckoutForm(e){return e?this.shopifyCompatibilityConfig?.editor_configs?.checkout_form===e:!1}};var y=class n{props;stringProp;linkProps;constructor(e,t,i){return this.props=e,this.stringProp=t,this.linkProps=i,new Proxy(e,{get(r,o){let a=r;switch(o){case"toJSON":return e;case"clone":return()=>new n(Ge(e),Ge(t),Ge(i));case"toString":{if(t)return()=>e[t];break}default:break}return a[o]instanceof i3?a[o].resolve().then(s=>(a[o]=s,s),s=>(console.log(s),a[o]=null,null)):a[o]},getPrototypeOf(){return n.prototype}})}valueOf(){return this.stringProp?this.props[this.stringProp]:this}clone(){return new n({})}},i3=class{handler;result;constructor(e){this.result=void 0,this.handler=e}async resolve(){return this.result===void 0&&(this.result=Promise.resolve().then(()=>{let e=this.handler();return this.handler=g6,e}).then(e=>(e=e!==void 0?e:null,this.result=e,e))),this.result}};function w(n){return new i3(n)}function f6(n){return v(n)&&(P(n)||typeof n._resolve=="function")}function S2(n){return v(n)&&typeof n._resolve=="function"}async function w6(n){return Array.isArray(n)?Promise.all(n.map(e=>S2(e)?e._resolve():e)):S2(n)?n._resolve():n}async function k2(n,e){return w6(n).then(t=>Array.isArray(n)&&Array.isArray(t)?e(...t.map(i=>i||{})):f6(t)?k2(t,e):e(t||{})).catch(t=>(console.log(t),null))}function c(n,e){return new i3(()=>k2(n,e))}function f4(n,e,t,i,r){return c(e,o=>o[t]?._cloneWithCompatibilityResult(a=>({results:a?.results?.map(s=>{let l=i(n,s);return r&&r(l,s),l})}))||[])}function l3(n){var e="0123456789abcdef";function t(L){var k,T="";for(k=0;k<=3;k++)T+=e.charAt(L>>k*8+4&15)+e.charAt(L>>k*8&15);return T}function i(L,k){var T=(L&65535)+(k&65535),M=(L>>16)+(k>>16)+(T>>16);return M<<16|T&65535}function r(L,k){return L<<k|L>>>32-k}function o(L,k,T,M,I,H){return i(r(i(i(k,L),i(M,H)),I),T)}function a(L,k,T,M,I,H,W){return o(k&T|~k&M,L,k,I,H,W)}function s(L,k,T,M,I,H,W){return o(k&M|T&~M,L,k,I,H,W)}function l(L,k,T,M,I,H,W){return o(k^T^M,L,k,I,H,W)}function h(L,k,T,M,I,H,W){return o(T^(k|~M),L,k,I,H,W)}function u(L){var k,T=(L.length+8>>6)+1,M=new Array(T*16);for(k=0;k<T*16;k++)M[k]=0;for(k=0;k<L.length;k++)M[k>>2]|=L.charCodeAt(k)<<k%4*8;return M[k>>2]|=128<<k%4*8,M[T*16-2]=L.length*8,M}var d,m=u(""+n),p=1732584193,g=-271733879,C=-1732584194,f=271733878,x,n3,j3,Ke;for(d=0;d<m.length;d+=16)x=p,n3=g,j3=C,Ke=f,p=a(p,g,C,f,m[d+0],7,-680876936),f=a(f,p,g,C,m[d+1],12,-389564586),C=a(C,f,p,g,m[d+2],17,606105819),g=a(g,C,f,p,m[d+3],22,-1044525330),p=a(p,g,C,f,m[d+4],7,-176418897),f=a(f,p,g,C,m[d+5],12,1200080426),C=a(C,f,p,g,m[d+6],17,-1473231341),g=a(g,C,f,p,m[d+7],22,-45705983),p=a(p,g,C,f,m[d+8],7,1770035416),f=a(f,p,g,C,m[d+9],12,-1958414417),C=a(C,f,p,g,m[d+10],17,-42063),g=a(g,C,f,p,m[d+11],22,-1990404162),p=a(p,g,C,f,m[d+12],7,1804603682),f=a(f,p,g,C,m[d+13],12,-40341101),C=a(C,f,p,g,m[d+14],17,-1502002290),g=a(g,C,f,p,m[d+15],22,1236535329),p=s(p,g,C,f,m[d+1],5,-165796510),f=s(f,p,g,C,m[d+6],9,-1069501632),C=s(C,f,p,g,m[d+11],14,643717713),g=s(g,C,f,p,m[d+0],20,-373897302),p=s(p,g,C,f,m[d+5],5,-701558691),f=s(f,p,g,C,m[d+10],9,38016083),C=s(C,f,p,g,m[d+15],14,-660478335),g=s(g,C,f,p,m[d+4],20,-405537848),p=s(p,g,C,f,m[d+9],5,568446438),f=s(f,p,g,C,m[d+14],9,-1019803690),C=s(C,f,p,g,m[d+3],14,-187363961),g=s(g,C,f,p,m[d+8],20,1163531501),p=s(p,g,C,f,m[d+13],5,-1444681467),f=s(f,p,g,C,m[d+2],9,-51403784),C=s(C,f,p,g,m[d+7],14,1735328473),g=s(g,C,f,p,m[d+12],20,-1926607734),p=l(p,g,C,f,m[d+5],4,-378558),f=l(f,p,g,C,m[d+8],11,-2022574463),C=l(C,f,p,g,m[d+11],16,1839030562),g=l(g,C,f,p,m[d+14],23,-35309556),p=l(p,g,C,f,m[d+1],4,-1530992060),f=l(f,p,g,C,m[d+4],11,1272893353),C=l(C,f,p,g,m[d+7],16,-155497632),g=l(g,C,f,p,m[d+10],23,-1094730640),p=l(p,g,C,f,m[d+13],4,681279174),f=l(f,p,g,C,m[d+0],11,-358537222),C=l(C,f,p,g,m[d+3],16,-722521979),g=l(g,C,f,p,m[d+6],23,76029189),p=l(p,g,C,f,m[d+9],4,-640364487),f=l(f,p,g,C,m[d+12],11,-421815835),C=l(C,f,p,g,m[d+15],16,530742520),g=l(g,C,f,p,m[d+2],23,-995338651),p=h(p,g,C,f,m[d+0],6,-198630844),f=h(f,p,g,C,m[d+7],10,1126891415),C=h(C,f,p,g,m[d+14],15,-1416354905),g=h(g,C,f,p,m[d+5],21,-57434055),p=h(p,g,C,f,m[d+12],6,1700485571),f=h(f,p,g,C,m[d+3],10,-1894986606),C=h(C,f,p,g,m[d+10],15,-1051523),g=h(g,C,f,p,m[d+1],21,-2054922799),p=h(p,g,C,f,m[d+8],6,1873313359),f=h(f,p,g,C,m[d+15],10,-30611744),C=h(C,f,p,g,m[d+6],15,-1560198380),g=h(g,C,f,p,m[d+13],21,1309151649),p=h(p,g,C,f,m[d+4],6,-145523070),f=h(f,p,g,C,m[d+11],10,-1120210379),C=h(C,f,p,g,m[d+2],15,718787259),g=h(g,C,f,p,m[d+9],21,-343485551),p=i(p,x),g=i(g,n3),C=i(C,j3),f=i(f,Ke);return t(p)+t(g)+t(C)+t(f)}function L6(n,e){if(!n.file_path.startsWith("theme/sections/"))return!1;if(n.file_path.endsWith(".liquid")){if(!e.get(n.file_path.replace(/\.liquid$/,".json")))return!0}else if(n.file_path.endsWith(".json"))return!0;return!1}async function s2(n,e){let t=[];for(let i of n.values())if(L6(i,n)){let r=await e(i);r&&t.push({...r,id:String(i.name||"").split(".").pop()??"",...r&&{presets:b6(r)}})}return t}function b6(n){return Array.isArray(n?.presets)?n.presets.map(e=>({label:e.label,settings:{...n.fields?.reduce((t,i)=>(i.id&&i.default!==void 0&&(t[i.id]=i.default),t),{}),...e.settings||void 0},blocks:e.blocks?.map(t=>{let i=n.blocks?.find(r=>r.type===t.type);return i?{...t,settings:{...i.fields.reduce((r,o)=>(o.id&&o.default!==void 0&&(r[o.id]=o.default),r),{}),...t.settings||void 0}}:t})})):[]}async function l2(n,e){let t=Array.from(n.values()),i=t.filter(a=>a.file_path.endsWith(".json")&&!n.has(a.file_path.replace(/\.json$/,".liquid"))),r=async a=>{let s=t.find(h=>{if(!h.file_path.endsWith(`/${a}.json`)&&!h.file_path.endsWith(`/${a}.liquid`))return!1;if(h.file_path.endsWith(".liquid")){if(!n.get(h.file_path.replace(/\.liquid$/,".json")))return!0}else if(h.file_path.endsWith(".json"))return!0;return!1});return s?{...await e(s),id:String(s.name||"").split(".").pop()}:void 0},o=[];for(let a of i){let s;try{s=JSON.parse(a.file_data),s?.name&&(s.label=s.name,delete s.name)}catch{}if(s?.type){let l=await Me(s,r);o.push({...s,id:String(a.name||"").split(".").pop(),sectionConfigs:l})}}return o}async function Me(n,e){let t=Array.isArray(n?.order)?n.order:Object.keys(n?.sections||{}),i=[];for(let r of t){let o=n.sections[r];if(!o)continue;let a=await e(o.type)||{id:o.type,label:o.type,tag:"div",class:"",fields:[],blocks:[]},s=n.id?`page__${n.id}__${r}`:a.id,h=(Array.isArray(o.block_order)?o.block_order:Object.keys(o.blocks||{})).map(d=>o.blocks?.[d]).filter(Boolean),u={section:{id:s,...o,blocks:h}};i.push({id:s,section:{id:s,...o},schema:a,settings:u,tag:a.tag||"div",class:a.class})}return i}function hd(n){return String(n)==="[object Array]"}function K(n){let e=typeof n;return n!==null&&(e==="object"||e==="function")}function b2(n){let e=new TextEncoder().encode(n),t="";for(let i=0;i<e.length;i+=3){let r=Array.from(e.slice(i,i+3));t+=btoa(String.fromCharCode(...r))}return t}function n2(n,e="id"){return k6(n,(t,i)=>(t[String(i[e])]=i,t),{})}function cd(n){let e=n.toUpperCase().split(/-|_/),t=e.shift(),i=e.pop(),r="";return i&&(r=i),i||(r=l5[t.toLowerCase()]||""),r.toLowerCase()}function A2(n,e){if(!(typeof n!="object"||n===null))for(let[t,i]of Object.entries(n))e(t,n)!==!1&&typeof i=="object"&&i!==null&&A2(i,e)}function ud(n){let e=new Set;return A2(n,(t,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return!1;e.add(i)}return!0}),Array.from(e)}function md(n){if(!n)return n;let e=new WeakSet;return JSON.parse(JSON.stringify(n,(t,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return JSON.parse(JSON.stringify(i));e.add(i)}return i}))}function A6(n){if(!(typeof n!="object"||n===null))for(let[e,t]of Object.entries(n))e==="_swell"&&"_swell"in n?n[e]=void 0:A6(t)}function L2(n){if(n!==void 0)return n instanceof b?"SwellStorefrontCollection":n instanceof A?"SwellStorefrontRecord":n instanceof y?"ShopifyResource":n instanceof _?"StorefrontResource":"promise"}async function B(n,e=!0,t=!1){let i=n,r=e;try{if(P(n)&&(r=!1,i=await n),n instanceof _&&(r=!1,i=await B(n.resolve(),e,t)),Array.isArray(i)){let o=await Promise.all(i.map(a=>B(a,e,t)));if(i=o,!o.some(a=>a!==void 0))return e?[]:void 0}else if(typeof i=="object"&&i!==null&&(!("_swell"in i)||!i._swell)){let o={};for(let[a,s]of Object.entries(i)){if(!e&&(P(s)||s instanceof _||s instanceof y)){o[a]={_type:L2(s),...t?{value:await B(s,r,t)}:void 0};continue}if(s instanceof _&&t){o[a]={_type:L2(s),value:await B(s,r,t)};continue}o[a]=await B(s,r,t)}return!e&&Object.keys(o).length===0?void 0:o}}catch(o){return console.error(o),n}return i}function O(n){return y6.stringify({...n,sections:void 0,section_id:void 0},{encodeValuesOnly:!0,arrayFormat:"repeat"})}function d2(n,e){return n=Array.isArray(n)?n.join(" "):n,n.split("}").map(r=>{let[o,a]=r.split("{");return!o||!a?"":`${o.split(",").map(l=>`#${e} ${l.trim()}`).join(", ")} {${a}}`}).join(" ")}function L3(n,e){return Object.entries(n).reduce((t,[i,r])=>(r?.value!==null&&r?.value!==void 0&&(t[i]=r?.value),t),S6(e))}var X3="ContentSections";function m3(n){return`SectionGroup_${n}`}var _6="THEME",M6=Object.freeze({ttl:1e3*60*60*24}),_2="__NULL__",V=class{client;constructor(e){e=e||{},e.stores=e.stores||E6(e.kvStore),this.client=T6({...M6,...e})}async fetch(e,t){return this.client.wrap(e,t)}async fetchSWR(e,t){let i=await this.client.get(e),r=Promise.resolve().then(()=>t()).then(async a=>{let s=a==null,l=await B(a);return await this.client.set(e,s?_2:l),a});return i!==null?i===_2?null:i:await r}async get(e){return this.client.get(e)}async set(e,t,i){return this.client.set(e,t,i)}async flush(e){await this.client.del(e)}async flushAll(){await this.client.clear()}};function E6(n){let e=[];return n?e.push(new T2({namespace:_6,store:new Z3(n)})):e.push(new T2),e}var P6=24*60*60*1e3,v6=30*1e3,v3=class extends V{constructor(e){super({ttl:e?.kvStore?P6:v6,...e})}};import{Keyv as R6}from"keyv";var D6=5*1e3,R3=class extends V{constructor(e){super({stores:x6(),ttl:D6,...e})}};function x6(){return[new R6({serialize:void 0,deserialize:void 0})]}var j6=90*24*60*60*1e3,S3=class extends V{constructor(e){super({ttl:j6,...e})}};var M2="https://api.schema.io",E2=new Map,P2=new Map,v2=class n{url;headers;swellHeaders;queryParams;workerEnv;config;shopifyCompatibilityConfig;backend;storefront;storefrontContext;instanceId="";isPreview=!1;isEditor=!1;sentResponse=!1;storefront_url;constructor(e){let{url:t,config:i,shopifyCompatibilityConfig:r,headers:o,swellHeaders:a,serverHeaders:s,queryParams:l,workerEnv:h,...u}=e;if(this.url=t instanceof URL?t:new URL(t||""),this.config=i,this.shopifyCompatibilityConfig=r,this.queryParams=n.formatQueryParams(l||this.url.searchParams),this.workerEnv=h,console.log(`KV cache: ${this.workerEnv?.THEME?"enabled":"disabled"}`),s){let{headers:d,swellHeaders:m}=n.formatHeaders(s);this.headers=d,this.swellHeaders=m,this.backend=new Ve({storeId:m["store-id"],accessToken:m["access-token"],apiHost:m["api-host"]}),this.storefront=this.getStorefrontInstance({...e,headers:d,swellHeaders:m}),this.instanceId=["store-id","environment-id","deployment-mode","theme-id","theme-branch-id"].map(p=>m[p]||"0").join(":"),this.isEditor=u.isEditor??m["deployment-mode"]==="editor",this.isPreview=this.isEditor||m["deployment-mode"]==="preview"}else if(o&&a)Object.assign(this,u),this.headers=o,this.swellHeaders=a,this.storefront=this.getStorefrontInstance(e);else throw new Error("Swell client requires `serverHeaders` when initialized on the server-side, or `headers` and `swellHeaders` when initialized on the client-side.");this.storefrontContext=this.initStorefrontContext()}static formatHeaders(e){let t={},i={};e instanceof Headers?e.forEach((r,o)=>{t[o]=r}):e&&(t=e);for(let[r,o]of Object.entries(t))r.startsWith("swell-")&&o&&(i[r.replace("swell-","")]=o);return{headers:t,swellHeaders:i}}static formatQueryParams(e){let t={};return e instanceof URLSearchParams?t=F6.parse(e.toString()):e&&(t=e),t}async getCachedResource(e,t,i){let r=this.swellHeaders["request-id"],o=R2(e,[r,t]);return this.getResourceCache().fetch(o,i)}async getAppSettings(){return await this.get("/:storefronts/{id}/configs/settings/values",{id:this.swellHeaders["storefront-id"]})||{}}async getStorefrontSettings(e=!1){try{let{settings:t,menus:i,payments:r,subscriptions:o,session:a}=await this.storefront.request("get","/settings/all",void 0,void 0,{force:e}),s=this.storefront.settings;s.localizedState={},s.set({value:t}),s.set({model:"menus",value:i}),s.set({model:"payments",value:r}),s.set({model:"subscriptions",value:o}),s.set({model:"session",value:a})}catch(t){t instanceof Error&&(t.message=`Swell: unable to load settings (${t.message})`),console.error(t)}return this.storefront.settings.get()}getStorefrontMenus(){let e=this.storefront.settings.getState("/settings/menus","menuState");return!e||P(e)?[]:e}getStorefrontLocalization(){let e=this.storefront.locale.selected(),t=this.storefront.currency.selected();return!e||P(e)?{locale:"en-US",currency:"USD"}:{locale:e,currency:t}}async get(...e){return this.backend?.get(...e)}async put(...e){return this.backend?.put(...e)}async post(...e){return this.backend?.post(...e)}async delete(...e){return this.backend?.delete(...e)}getStorefrontInstance(e){let{swellHeaders:t,getCookie:i,setCookie:r,storefrontSettingStates:o}=e;if(!t)throw new Error("Swell headers are required");let a=t["store-id"],s=t["public-key"];if(!a||!s)throw new Error('Missing required headers: "swell-store-id" and "swell-public-key"');let l=Z6.create(a,s,{url:t["admin-url"],vaultUrl:t["vault-url"],getCookie:i,setCookie:r&&((h,u,d)=>r(h,u,d,this)),headers:{"Swell-Store-id":a,"Swell-Storefront-Id":t["storefront-id"]}});return o&&Object.assign(l.settings,o),l.request=this.getCacheableStorefrontRequestHandler(l),l}initStorefrontContext(){let e={};if(this.swellHeaders?.["storefront-context"])try{e=JSON.parse(this.swellHeaders["storefront-context"])}catch{console.error("Failed to parse swell-storefront-context. Ignoring...")}return e}isStorefrontRequestCacheable(e,t,i){if(i?.force)return!1;if(e==="get")switch(t.split("/")[1]){case"products":case"categories":case"content":case"settings":return!0;default:return!1}return!1}getCacheableStorefrontRequestHandler(e){let t=e.request;return(i,r,o,a,s)=>{if(this.isStorefrontRequestCacheable(i,r,s))return this.getRequestCache().fetchSWR(R2("request",[i,r,o,a,s]),()=>t(i,r,o,a,s));switch(i){case"delete":case"post":case"put":{let l=r.split("/")[1];delete this.storefrontContext[l];break}default:}return t(i,r,o,a,s)}}getResourceCache(){let e=E2.get(this.instanceId);return e||(e=new R3({kvStore:this.workerEnv?.THEME}),E2.set(this.instanceId,e)),e}getRequestCache(){let e=P2.get(this.instanceId);return e||(e=new v3({kvStore:this.workerEnv?.THEME}),P2.set(this.instanceId,e)),e}};function R2(n,e){let t=n;return Array.isArray(e)&&e.length>0&&(t+=`_${JSON.stringify(e)}`),t.length>512&&(t=`${t.slice(0,480)}${l3(t)}`),t}var Ve=class{apiHost=M2;apiAuth="";constructor({storeId:e,accessToken:t,apiHost:i}){this.apiHost=i||M2,this.apiAuth=b2(`${e}:${t}`)}async makeRequest(e,t,i){let r={method:e,headers:{Authorization:`Basic ${this.apiAuth}`,"User-Agent":"swell-functions/1.0","Content-Type":"application/json"}},o="";if(i)try{e==="GET"?o=`?${this.stringifyQuery(i)}`:(r.body=JSON.stringify(i),r.headers["Content-Length"]=String(r.body.length))}catch{throw new Error(`Error serializing data: ${i}`)}let a=String(t).startsWith("/")?t.substring(1):t,s=`${this.apiHost}/${a}${o}`,l=await fetch(s,r),h=await l.text(),u;try{u=JSON.parse(h)}catch{u=String(h||"").trim()}if(l.status>299)throw new o4(u,{status:l.status,method:e,endpointUrl:a});if(e!=="GET"&&u?.errors)throw new o4(u.errors,{status:400,method:e,endpointUrl:a});return u}stringifyQuery(e,t){let i=[];for(let[r,o]of Object.entries(e)){let a=t?`${t}[${r}]`:r,l=o!==null&&typeof o=="object"?this.stringifyQuery(o,a):`${encodeURIComponent(a)}=${o===null?"":encodeURIComponent(o)}`;i.push(l)}return i.join("&")}async get(e,t){return this.makeRequest("GET",e,t)}async put(e,t){return this.makeRequest("PUT",e,t)}async post(e,t){return this.makeRequest("POST",e,t)}async delete(e,t){return this.makeRequest("DELETE",e,t)}},o4=class extends Error{status=200;constructor(e,t={}){let i;typeof e=="string"?i=e:i=JSON.stringify(e,null,2),t.method&&t.endpointUrl&&(i=`${t.method} /${t.endpointUrl}
|
|
948
|
+
`):""}isScriptFormActionUrl(e){if(!e)return!1;let t=this.shopifyCompatibilityConfig?.editor_configs?.script_actions_routes||{};for(let i of Object.values(t))if(e===i)return!0;return!1}isScriptUrl(e){if(!e)return!1;let t=this.shopifyCompatibilityConfig?.editor_configs?.script_routes||{};for(let i of Object.values(t))if(e.startsWith(i))return!0;return!1}needRedirectToPageStart(e){return e?(this.shopifyCompatibilityConfig?.editor_configs?.redirect_to_page_start_forms||[]).includes(e):!1}isCheckoutForm(e){return e?this.shopifyCompatibilityConfig?.editor_configs?.checkout_form===e:!1}};var y=class n{props;stringProp;linkProps;constructor(e,t,i){return this.props=e,this.stringProp=t,this.linkProps=i,new Proxy(e,{get(r,o){let a=r;switch(o){case"toJSON":return e;case"clone":return()=>new n(Ge(e),Ge(t),Ge(i));case"toString":{if(t)return()=>e[t];break}default:break}return a[o]instanceof i3?a[o].resolve().then(s=>(a[o]=s,s),s=>(console.log(s),a[o]=null,null)):a[o]},getPrototypeOf(){return n.prototype}})}valueOf(){return this.stringProp?this.props[this.stringProp]:this}clone(){return new n({})}},i3=class{handler;result;constructor(e){this.result=void 0,this.handler=e}async resolve(){return this.result===void 0&&(this.result=Promise.resolve().then(()=>{let e=this.handler();return this.handler=g6,e}).then(e=>(e=e!==void 0?e:null,this.result=e,e))),this.result}};function w(n){return new i3(n)}function f6(n){return v(n)&&(P(n)||typeof n._resolve=="function")}function S2(n){return v(n)&&typeof n._resolve=="function"}async function w6(n){return Array.isArray(n)?Promise.all(n.map(e=>S2(e)?e._resolve():e)):S2(n)?n._resolve():n}async function k2(n,e){return w6(n).then(t=>Array.isArray(n)&&Array.isArray(t)?e(...t.map(i=>i||{})):f6(t)?k2(t,e):e(t||{})).catch(t=>(console.log(t),null))}function c(n,e){return new i3(()=>k2(n,e))}function f4(n,e,t,i,r){return c(e,o=>o[t]?._cloneWithCompatibilityResult(a=>({results:a?.results?.map(s=>{let l=i(n,s);return r&&r(l,s),l})}))||[])}function l3(n){var e="0123456789abcdef";function t(L){var k,T="";for(k=0;k<=3;k++)T+=e.charAt(L>>k*8+4&15)+e.charAt(L>>k*8&15);return T}function i(L,k){var T=(L&65535)+(k&65535),M=(L>>16)+(k>>16)+(T>>16);return M<<16|T&65535}function r(L,k){return L<<k|L>>>32-k}function o(L,k,T,M,I,H){return i(r(i(i(k,L),i(M,H)),I),T)}function a(L,k,T,M,I,H,W){return o(k&T|~k&M,L,k,I,H,W)}function s(L,k,T,M,I,H,W){return o(k&M|T&~M,L,k,I,H,W)}function l(L,k,T,M,I,H,W){return o(k^T^M,L,k,I,H,W)}function h(L,k,T,M,I,H,W){return o(T^(k|~M),L,k,I,H,W)}function u(L){var k,T=(L.length+8>>6)+1,M=new Array(T*16);for(k=0;k<T*16;k++)M[k]=0;for(k=0;k<L.length;k++)M[k>>2]|=L.charCodeAt(k)<<k%4*8;return M[k>>2]|=128<<k%4*8,M[T*16-2]=L.length*8,M}var d,m=u(""+n),p=1732584193,g=-271733879,C=-1732584194,f=271733878,x,n3,j3,Ke;for(d=0;d<m.length;d+=16)x=p,n3=g,j3=C,Ke=f,p=a(p,g,C,f,m[d+0],7,-680876936),f=a(f,p,g,C,m[d+1],12,-389564586),C=a(C,f,p,g,m[d+2],17,606105819),g=a(g,C,f,p,m[d+3],22,-1044525330),p=a(p,g,C,f,m[d+4],7,-176418897),f=a(f,p,g,C,m[d+5],12,1200080426),C=a(C,f,p,g,m[d+6],17,-1473231341),g=a(g,C,f,p,m[d+7],22,-45705983),p=a(p,g,C,f,m[d+8],7,1770035416),f=a(f,p,g,C,m[d+9],12,-1958414417),C=a(C,f,p,g,m[d+10],17,-42063),g=a(g,C,f,p,m[d+11],22,-1990404162),p=a(p,g,C,f,m[d+12],7,1804603682),f=a(f,p,g,C,m[d+13],12,-40341101),C=a(C,f,p,g,m[d+14],17,-1502002290),g=a(g,C,f,p,m[d+15],22,1236535329),p=s(p,g,C,f,m[d+1],5,-165796510),f=s(f,p,g,C,m[d+6],9,-1069501632),C=s(C,f,p,g,m[d+11],14,643717713),g=s(g,C,f,p,m[d+0],20,-373897302),p=s(p,g,C,f,m[d+5],5,-701558691),f=s(f,p,g,C,m[d+10],9,38016083),C=s(C,f,p,g,m[d+15],14,-660478335),g=s(g,C,f,p,m[d+4],20,-405537848),p=s(p,g,C,f,m[d+9],5,568446438),f=s(f,p,g,C,m[d+14],9,-1019803690),C=s(C,f,p,g,m[d+3],14,-187363961),g=s(g,C,f,p,m[d+8],20,1163531501),p=s(p,g,C,f,m[d+13],5,-1444681467),f=s(f,p,g,C,m[d+2],9,-51403784),C=s(C,f,p,g,m[d+7],14,1735328473),g=s(g,C,f,p,m[d+12],20,-1926607734),p=l(p,g,C,f,m[d+5],4,-378558),f=l(f,p,g,C,m[d+8],11,-2022574463),C=l(C,f,p,g,m[d+11],16,1839030562),g=l(g,C,f,p,m[d+14],23,-35309556),p=l(p,g,C,f,m[d+1],4,-1530992060),f=l(f,p,g,C,m[d+4],11,1272893353),C=l(C,f,p,g,m[d+7],16,-155497632),g=l(g,C,f,p,m[d+10],23,-1094730640),p=l(p,g,C,f,m[d+13],4,681279174),f=l(f,p,g,C,m[d+0],11,-358537222),C=l(C,f,p,g,m[d+3],16,-722521979),g=l(g,C,f,p,m[d+6],23,76029189),p=l(p,g,C,f,m[d+9],4,-640364487),f=l(f,p,g,C,m[d+12],11,-421815835),C=l(C,f,p,g,m[d+15],16,530742520),g=l(g,C,f,p,m[d+2],23,-995338651),p=h(p,g,C,f,m[d+0],6,-198630844),f=h(f,p,g,C,m[d+7],10,1126891415),C=h(C,f,p,g,m[d+14],15,-1416354905),g=h(g,C,f,p,m[d+5],21,-57434055),p=h(p,g,C,f,m[d+12],6,1700485571),f=h(f,p,g,C,m[d+3],10,-1894986606),C=h(C,f,p,g,m[d+10],15,-1051523),g=h(g,C,f,p,m[d+1],21,-2054922799),p=h(p,g,C,f,m[d+8],6,1873313359),f=h(f,p,g,C,m[d+15],10,-30611744),C=h(C,f,p,g,m[d+6],15,-1560198380),g=h(g,C,f,p,m[d+13],21,1309151649),p=h(p,g,C,f,m[d+4],6,-145523070),f=h(f,p,g,C,m[d+11],10,-1120210379),C=h(C,f,p,g,m[d+2],15,718787259),g=h(g,C,f,p,m[d+9],21,-343485551),p=i(p,x),g=i(g,n3),C=i(C,j3),f=i(f,Ke);return t(p)+t(g)+t(C)+t(f)}function L6(n,e){if(!n.file_path.startsWith("theme/sections/"))return!1;if(n.file_path.endsWith(".liquid")){if(!e.get(n.file_path.replace(/\.liquid$/,".json")))return!0}else if(n.file_path.endsWith(".json"))return!0;return!1}async function s2(n,e){let t=[];for(let i of n.values())if(L6(i,n)){let r=await e(i);r&&t.push({...r,id:String(i.name||"").split(".").pop()??"",...r&&{presets:b6(r)}})}return t}function b6(n){return Array.isArray(n?.presets)?n.presets.map(e=>({label:e.label,settings:{...n.fields?.reduce((t,i)=>(i.id&&i.default!==void 0&&(t[i.id]=i.default),t),{}),...e.settings||void 0},blocks:e.blocks?.map(t=>{let i=n.blocks?.find(r=>r.type===t.type);return i?{...t,settings:{...i.fields.reduce((r,o)=>(o.id&&o.default!==void 0&&(r[o.id]=o.default),r),{}),...t.settings||void 0}}:t})})):[]}async function l2(n,e){let t=Array.from(n.values()),i=t.filter(a=>a.file_path.endsWith(".json")&&!n.has(a.file_path.replace(/\.json$/,".liquid"))),r=async a=>{let s=t.find(h=>{if(!h.file_path.endsWith(`/${a}.json`)&&!h.file_path.endsWith(`/${a}.liquid`))return!1;if(h.file_path.endsWith(".liquid")){if(!n.get(h.file_path.replace(/\.liquid$/,".json")))return!0}else if(h.file_path.endsWith(".json"))return!0;return!1});return s?{...await e(s),id:String(s.name||"").split(".").pop()}:void 0},o=[];for(let a of i){let s;try{s=JSON.parse(a.file_data),s?.name&&(s.label=s.name,delete s.name)}catch{}if(s?.type){let l=await Me(s,r);o.push({...s,id:String(a.name||"").split(".").pop(),sectionConfigs:l})}}return o}async function Me(n,e){let t=Array.isArray(n?.order)?n.order:Object.keys(n?.sections||{}),i=[];for(let r of t){let o=n.sections[r];if(!o)continue;let a=await e(o.type)||{id:o.type,label:o.type,tag:"div",class:"",fields:[],blocks:[]},s=n.id?`page__${n.id}__${r}`:a.id,h=(Array.isArray(o.block_order)?o.block_order:Object.keys(o.blocks||{})).map(d=>o.blocks?.[d]).filter(Boolean),u={section:{id:s,...o,blocks:h}};i.push({id:s,section:{id:s,...o},schema:a,settings:u,tag:a.tag||"div",class:a.class})}return i}function hd(n){return String(n)==="[object Array]"}function K(n){let e=typeof n;return n!==null&&(e==="object"||e==="function")}function b2(n){let e=new TextEncoder().encode(n),t="";for(let i=0;i<e.length;i+=3){let r=Array.from(e.slice(i,i+3));t+=btoa(String.fromCharCode(...r))}return t}function n2(n,e="id"){return k6(n,(t,i)=>(t[String(i[e])]=i,t),{})}function cd(n){let e=n.toUpperCase().split(/-|_/),t=e.shift(),i=e.pop(),r="";return i&&(r=i),i||(r=l5[t.toLowerCase()]||""),r.toLowerCase()}function A2(n,e){if(!(typeof n!="object"||n===null))for(let[t,i]of Object.entries(n))e(t,n)!==!1&&typeof i=="object"&&i!==null&&A2(i,e)}function ud(n){let e=new Set;return A2(n,(t,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return!1;e.add(i)}return!0}),Array.from(e)}function md(n){if(!n)return n;let e=new WeakSet;return JSON.parse(JSON.stringify(n,(t,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return JSON.parse(JSON.stringify(i));e.add(i)}return i}))}function A6(n){if(!(typeof n!="object"||n===null))for(let[e,t]of Object.entries(n))e==="_swell"&&"_swell"in n?n[e]=void 0:A6(t)}function L2(n){if(n!==void 0)return n instanceof b?"SwellStorefrontCollection":n instanceof A?"SwellStorefrontRecord":n instanceof y?"ShopifyResource":n instanceof _?"StorefrontResource":"promise"}async function B(n,e=!0,t=!1){let i=n,r=e;try{if(P(n)&&(r=!1,i=await n),n instanceof _&&(r=!1,i=await B(n.resolve(),e,t)),Array.isArray(i)){let o=await Promise.all(i.map(a=>B(a,e,t)));if(i=o,!o.some(a=>a!==void 0))return e?[]:void 0}else if(typeof i=="object"&&i!==null&&(!("_swell"in i)||!i._swell)){let o={};for(let[a,s]of Object.entries(i)){if(!e&&(P(s)||s instanceof _||s instanceof y)){o[a]={_type:L2(s),...t?{value:await B(s,r,t)}:void 0};continue}if(s instanceof _&&t){o[a]={_type:L2(s),value:await B(s,r,t)};continue}o[a]=await B(s,r,t)}return!e&&Object.keys(o).length===0?void 0:o}}catch(o){return console.error(o),n}return i}function O(n){return y6.stringify({...n,sections:void 0,section_id:void 0},{encodeValuesOnly:!0,arrayFormat:"repeat"})}function d2(n,e){return n=Array.isArray(n)?n.join(" "):n,n.split("}").map(r=>{let[o,a]=r.split("{");return!o||!a?"":`${o.split(",").map(l=>`#${e} ${l.trim()}`).join(", ")} {${a}}`}).join(" ")}function L3(n,e){return Object.entries(n).reduce((t,[i,r])=>(r?.value!==null&&r?.value!==void 0&&(t[i]=r?.value),t),S6(e))}var X3="ContentSections";function m3(n){return`SectionGroup_${n}`}var _6="THEME",M6=Object.freeze({ttl:1e3*60*60*24}),_2="__NULL__",V=class{client;constructor(e){e=e||{},e.stores=e.stores||E6(e.kvStore),this.client=T6({...M6,...e})}async fetch(e,t){return this.client.wrap(e,t)}async fetchSWR(e,t){let i=await this.client.get(e),r=Promise.resolve().then(()=>t()).then(async a=>{let s=a==null,l=await B(a);return await this.client.set(e,s?_2:l),a});return i!==null?i===_2?null:i:await r}async get(e){return this.client.get(e)}async set(e,t,i){return this.client.set(e,t,i)}async flush(e){await this.client.del(e)}async flushAll(){await this.client.clear()}};function E6(n){let e=[];return n?e.push(new T2({namespace:_6,store:new Z3(n)})):e.push(new T2),e}var P6=24*60*60*1e3,v6=30*1e3,v3=class extends V{constructor(e){super({ttl:e?.kvStore?P6:v6,...e})}};import{Keyv as R6}from"keyv";var D6=5*1e3,R3=class extends V{constructor(e){super({stores:x6(),ttl:D6,...e})}};function x6(){return[new R6({serialize:void 0,deserialize:void 0})]}var j6=90*24*60*60*1e3,S3=class extends V{constructor(e){super({ttl:j6,...e})}};var M2="https://api.schema.io",E2=new Map,P2=new Map,v2=class n{url;headers;swellHeaders;queryParams;workerEnv;config;shopifyCompatibilityConfig;backend;storefront;storefrontContext;instanceId="";isPreview=!1;isEditor=!1;sentResponse=!1;storefront_url;constructor(e){let{url:t,config:i,shopifyCompatibilityConfig:r,headers:o,swellHeaders:a,serverHeaders:s,queryParams:l,workerEnv:h,...u}=e;if(this.url=t instanceof URL?t:new URL(t||""),this.config=i,this.shopifyCompatibilityConfig=r,this.queryParams=n.formatQueryParams(l||this.url.searchParams),this.workerEnv=h,console.log(`KV cache: ${this.workerEnv?.THEME?"enabled":"disabled"}`),s){let{headers:d,swellHeaders:m}=n.formatHeaders(s);this.headers=d,this.swellHeaders=m,this.backend=new Ve({storeId:m["store-id"],accessToken:m["access-token"],apiHost:m["api-host"]}),this.storefront=this.getStorefrontInstance({...e,headers:d,swellHeaders:m}),this.instanceId=["store-id","environment-id","deployment-mode","theme-id","theme-branch-id"].map(p=>m[p]||"0").join(":"),this.isEditor=u.isEditor??m["deployment-mode"]==="editor",this.isPreview=this.isEditor||m["deployment-mode"]==="preview"}else if(o&&a)Object.assign(this,u),this.headers=o,this.swellHeaders=a,this.storefront=this.getStorefrontInstance(e);else throw new Error("Swell client requires `serverHeaders` when initialized on the server-side, or `headers` and `swellHeaders` when initialized on the client-side.");this.storefrontContext=this.initStorefrontContext()}static formatHeaders(e){let t={},i={};e instanceof Headers?e.forEach((r,o)=>{t[o]=r}):e&&(t=e);for(let[r,o]of Object.entries(t))r.startsWith("swell-")&&o&&(i[r.replace("swell-","")]=o);return{headers:t,swellHeaders:i}}static formatQueryParams(e){let t={};return e instanceof URLSearchParams?t=F6.parse(e.toString()):e&&(t=e),t}async getCachedResource(e,t,i){let r=R2(e,[this.instanceId,t]);return this.getResourceCache().fetch(r,i)}async getAppSettings(){return await this.get("/:storefronts/{id}/configs/settings/values",{id:this.swellHeaders["storefront-id"]})||{}}async getStorefrontSettings(e=!1){try{let{settings:t,menus:i,payments:r,subscriptions:o,session:a}=await this.storefront.request("get","/settings/all",void 0,void 0,{force:e}),s=this.storefront.settings;s.localizedState={},s.set({value:t}),s.set({model:"menus",value:i}),s.set({model:"payments",value:r}),s.set({model:"subscriptions",value:o}),s.set({model:"session",value:a})}catch(t){t instanceof Error&&(t.message=`Swell: unable to load settings (${t.message})`),console.error(t)}return this.storefront.settings.get()}getStorefrontMenus(){let e=this.storefront.settings.getState("/settings/menus","menuState");return!e||P(e)?[]:e}getStorefrontLocalization(){let e=this.storefront.locale.selected(),t=this.storefront.currency.selected();return!e||P(e)?{locale:"en-US",currency:"USD"}:{locale:e,currency:t}}async get(...e){return this.backend?.get(...e)}async put(...e){return this.backend?.put(...e)}async post(...e){return this.backend?.post(...e)}async delete(...e){return this.backend?.delete(...e)}getStorefrontInstance(e){let{swellHeaders:t,getCookie:i,setCookie:r,storefrontSettingStates:o}=e;if(!t)throw new Error("Swell headers are required");let a=t["store-id"],s=t["public-key"];if(!a||!s)throw new Error('Missing required headers: "swell-store-id" and "swell-public-key"');let l=Z6.create(a,s,{url:t["admin-url"],vaultUrl:t["vault-url"],getCookie:i,setCookie:r&&((h,u,d)=>r(h,u,d,this)),headers:{"Swell-Store-id":a,"Swell-Storefront-Id":t["storefront-id"]}});return o&&Object.assign(l.settings,o),l.request=this.getCacheableStorefrontRequestHandler(l),l}initStorefrontContext(){let e={};if(this.swellHeaders?.["storefront-context"])try{e=JSON.parse(decodeURIComponent(this.swellHeaders["storefront-context"]))}catch{console.error("Failed to parse swell-storefront-context. Ignoring...")}return e}isStorefrontRequestCacheable(e,t,i){if(i?.force)return!1;if(e==="get")switch(t.split("/")[1]){case"products":case"categories":case"content":case"settings":return!0;default:return!1}return!1}getCacheableStorefrontRequestHandler(e){let t=e.request;return(i,r,o,a,s)=>{if(this.isStorefrontRequestCacheable(i,r,s))return this.getRequestCache().fetchSWR(R2("request",[this.instanceId,i,r,o,a,s]),()=>t(i,r,o,a,s));switch(i){case"delete":case"post":case"put":{let l=r.split("/")[1];delete this.storefrontContext[l];break}default:}return t(i,r,o,a,s)}}getResourceCache(){let e=E2.get(this.instanceId);return e||(e=new R3({kvStore:this.workerEnv?.THEME}),E2.set(this.instanceId,e)),e}getRequestCache(){let e=P2.get(this.instanceId);return e||(e=new v3({kvStore:this.workerEnv?.THEME}),P2.set(this.instanceId,e)),e}};function R2(n,e){let t=n;return Array.isArray(e)&&e.length>0&&(t+=`_${JSON.stringify(e)}`),t.length>512&&(t=`${t.slice(0,480)}${l3(t)}`),t}var Ve=class{apiHost=M2;apiAuth="";constructor({storeId:e,accessToken:t,apiHost:i}){this.apiHost=i||M2,this.apiAuth=b2(`${e}:${t}`)}async makeRequest(e,t,i){let r={method:e,headers:{Authorization:`Basic ${this.apiAuth}`,"User-Agent":"swell-functions/1.0","Content-Type":"application/json"}},o="";if(i)try{e==="GET"?o=`?${this.stringifyQuery(i)}`:(r.body=JSON.stringify(i),r.headers["Content-Length"]=String(r.body.length))}catch{throw new Error(`Error serializing data: ${i}`)}let a=String(t).startsWith("/")?t.substring(1):t,s=`${this.apiHost}/${a}${o}`,l=await fetch(s,r),h=await l.text(),u;try{u=JSON.parse(h)}catch{u=String(h||"").trim()}if(l.status>299)throw new o4(u,{status:l.status,method:e,endpointUrl:a});if(e!=="GET"&&u?.errors)throw new o4(u.errors,{status:400,method:e,endpointUrl:a});return u}stringifyQuery(e,t){let i=[];for(let[r,o]of Object.entries(e)){let a=t?`${t}[${r}]`:r,l=o!==null&&typeof o=="object"?this.stringifyQuery(o,a):`${encodeURIComponent(a)}=${o===null?"":encodeURIComponent(o)}`;i.push(l)}return i.join("&")}async get(e,t){return this.makeRequest("GET",e,t)}async put(e,t){return this.makeRequest("PUT",e,t)}async post(e,t){return this.makeRequest("POST",e,t)}async delete(e,t){return this.makeRequest("DELETE",e,t)}},o4=class extends Error{status=200;constructor(e,t={}){let i;typeof e=="string"?i=e:i=JSON.stringify(e,null,2),t.method&&t.endpointUrl&&(i=`${t.method} /${t.endpointUrl}
|
|
949
949
|
${i}`),super(i),this.name="SwellError",this.status=t.status||500}};function D2(n,e){return new b(n,"products",e)}function Od(n,e,t){return new A(n,"products",e,t)}function $d(n,{search:e,filter:t,sort:i}){return new b(n,"products",{search:e,filter:t,sort:i})}function Jd(n,e){return new b(n,"categories",e)}function N6(n,e,t){return new A(n,"categories",e,t)}async function Yd(n,e,t){let i=N6(n,e,t),r=await i.id;return i.products=D2(n,{category:r}),i}function th(n,e){return n.getCachedResource(`content-model-${e}`,[],()=>n.get("/:content/{name}",{name:e,public:!0,"storefront.enabled":!0}))}async function I6(n,e,t){return new b(n,`content/${e}`,t)}async function x2(n,e,t,i){return new A(n,`content/${e}`,t,i)}async function ih(n,e,t){return x2(n,"pages",e,t)}async function nh(n,e){return I6(n,"blogs",e)}async function rh(n,e,t){return x2(n,"blogs",e,t)}import{reduce as z}from"lodash-es";async function j2(n,e){let t=[];for(let i of e)if(B6(i,e)){let r=await $e(n,i);r&&t.push({...r,id:String(i.name||"").split(".").pop()})}return t}async function Oe(n,e,t=H6){let i=Array.isArray(e.order)?e.order:Object.keys(e.sections||{}),r=[];for(let o of i){let a=e.sections[o],s=await t(n,a.type);if(!s)continue;let l={...s,id:o},h=e.id?`page__${e.id}__${o}`:l.id,d=(Array.isArray(a.block_order)?a.block_order:Object.keys(a.blocks||{})).map(p=>a.blocks?.[p]).filter(Boolean),m={section:{id:h,...a,blocks:d}};r.push({id:h,settings:m,section:{id:h,...a},tag:l.tag||"div",class:l.class,schema:l})}return r}async function Z2(n,e){let t=e.filter(o=>q6(o,e)),i=async(o,a)=>{let s=e.find(h=>G6(h,e,a)),l=await $e(o,s);if(l)return{...l,id:String(s?.name||"").split(".").pop()}},r=[];for(let o of t){let a;try{a=JSON.parse(o.file_data),a?.name&&(a.label=a.name,delete a.name)}catch{}if(a?.type){let s=await Oe(n,a,i);r.push({...a,id:String(o.name||"").split(".").pop(),sectionConfigs:s})}}return r}async function H6(n,e){let t=await n.getThemeTemplateConfigByType("sections",e);return $e(n,t)}async function $e(n,e){let t;if(e?.file_path?.endsWith(".liquid")){if(n.shopifyCompatibility){n.liquidSwell.lastSchema=void 0,await n.renderTemplate(e);let i=n.liquidSwell.lastSchema;i&&(t=n.shopifyCompatibility.getSectionConfigSchema(i))}}else if(e?.file_data)try{t=JSON.parse(e?.file_data)||void 0}catch{}return t}function B6(n,e){return n.file_path.startsWith("theme/sections/")?F2(n,e):!1}function q6(n,e){if(!n.file_path.startsWith("theme/sections/")||!n.file_path.endsWith(".json"))return!1;let t=n.file_path.replace(/\.json$/,".liquid");return!e.some(i=>i.file_path===t)}function G6(n,e,t){return!n.file_path.endsWith(`/${t}.json`)&&!n.file_path.endsWith(`/${t}.liquid`)?!1:F2(n,e)}function F2(n,e){if(n.file_path.endsWith(".liquid")){let t=n.file_path.replace(/\.liquid$/,".json");if(!e.find(r=>r.file_path===t))return!0}else if(n.file_path.endsWith(".json"))return!0;return!1}function D3(n){let e={description:n.description,defaultValue:n.default,isLabelHidden:!0,layout:"column",params:n},t;switch(n?.type){case"text":case"short_text":t={type:"swell_short_text"};break;case"paragraph":t={type:"swell_paragraph"};break;case"textarea":case"long_text":case"liquid":t={type:"swell_long_text"};break;case"basic_html":case"rich_text":case"rich_html":case"markdown":t={type:"swell_editor"};break;case"number":t={type:"swell_number"};break;case"select":t={type:"swell_select"};break;case"radio":t={type:"swell_radio"};break;case"checkbox":t={type:"swell_boolean"};break;case"color":t={type:"swell_color"};break;case"color_scheme":t={type:"swell_color_scheme"};break;case"color_scheme_group":t={type:"swell_color_scheme_group"};break;case"font":t={type:"swell_font"};break;case"header":t={type:"swell_header"};break;case"icon":t={type:"swell_menu"};break;case"menu":t={type:"swell_menu"};break;case"url":t={type:"swell_url"};break;case"lookup":case"generic_lookup":case"product_lookup":case"category_lookup":case"customer_lookup":t={type:"swell_lookup"};break;case"image":t={type:"swell_image",defaultValue:""};break;case"asset":case"document":case"video":t={type:"swell_file"};break;default:t={type:"swell_short_text"};break}return{...e,...t}}function N(n,e,t){if(t===void 0)return null;switch(n?.find(r=>r.id===e)?.type){default:return t}}function V6(n,e){return e?.reduce((t,i)=>{for(let r of i.fields||[])r?.id&&(t[r.id]=n[r.id]);return t},{})}function O6(n,e){if(e)return{settings:e.fields.reduce((t,i)=>(i?.id&&(t[i.id]=n[i.id]),t),{$locale:n.$locale}),id:e.id,blocks:n.Blocks?.filter(t=>!!t.props.compiled?._component).map(t=>{let i=t.props.compiled.props,r=t.props.compiled._component.split("__")[2],o=e.blocks?.find(a=>a.type===r);return{type:r,settings:o?.fields?.reduce((a,s)=>(s?.id&&(a[s.id]=i[s.id]),a),{$locale:i.$locale})||{}}})}}var a4=!0;async function hh(n,e,t){let i=await $6(n,t),r=await j2(n,e),o=await Oe(n,i),a=await Z2(n,e);return{pageTemplate:i,allSections:r,pageSections:o,layoutSectionGroups:a}}async function $6(n,e){let t=null;if(t=await n.getThemeTemplateConfigByType("templates",e),t)return t.file_path.endsWith(".liquid")?t.file_data:JSON.parse(t.file_data)}function U6(n,e){return n.reduce((t,i)=>(i.enabled_on?s4(i.enabled_on,"groups",e)&&t.push(String(i.id)):i.disabled_on?s4(i.disabled_on,"groups",e)||t.push(String(i.id)):i.id===e&&t.push(String(i.id)),t),[])}function K6(n,e){return e.map(t=>({prop:m3(t.id),type:"component-collection",label:t.label,required:!0,noInline:a4,accepts:U6(n,t.type)}))}function s4(n,e,t){return!!(n.templates==="*"||n[e]?.includes(t))}function z6(n,e,t){return n.reduce((i,r)=>(r.enabled_on?s4(r.enabled_on,"templates",t)&&i.push(String(r.id)):r.disabled_on?s4(r.disabled_on,"templates",t)||i.push(String(r.id)):e.some(({type:o})=>o===r.id)||i.push(String(r.id)),i),[])}function W6(n){return(n?.configs?.editor?.settings??[]).reduce((e,t)=>{for(let i of t.fields||[])e.push({prop:i.id,label:i.label,optional:!0,group:t.label,...D3(i)});return e},[])}function J6(n){let e=[];for(let t of n){let i=Array.isArray(t.blocks)&&t.blocks.length>0;e.push({id:t.id,label:t.label,schema:[...(t.fields||[]).reduce((r,o)=>(o.id&&o.type&&r.push({prop:o.id,label:o.label,optional:!0,...D3(o)}),r),[]),...i?[{prop:"Blocks",type:"component-collection",required:!0,noInline:a4,accepts:(t.blocks||[]).map(r=>`Block__${t.id}__${r.type}`),defaultValue:t.presets?.reduce((r,o,a)=>o.blocks?o.blocks.reduce((s,l)=>{let h=t.blocks?.find(({type:u})=>u===l.type);return h&&s.push({_id:`Block__${t.id}__${l.type}__preset_${a}`,_component:`Block__${t.id}__${l.type}`,...z(h.fields,(u,d)=>(d.id&&(u[d.id]=N(h.fields,d.id,d.default)),u),{})}),s},r):r,[]),placeholderAppearance:{height:50,label:"Add block",aspectRatio:1}}]:[],{prop:"custom_css",type:"swell_css",label:"Custom CSS",description:"Add custom CSS for this section",layout:"column",isLabelHidden:!0,params:{rows:5,placeholder:"Enter custom CSS..."}},{prop:"$locale",type:"swell_locale",isLabelHidden:!0}],styles:()=>({styled:{Root:{}}})}),i&&e.push(...(t.blocks||[]).map(r=>({id:`Block__${t.id}__${r.type}`,label:r.label,schema:(r.fields||[]).reduce((o,a)=>(a.id&&a.type&&o.push({prop:a.id,label:a.label,optional:!0,...D3(a)}),o),[{prop:"$locale",type:"swell_locale",isLabelHidden:!0}]),styles:()=>({styled:{Root:{}}})})))}return e}function Y6(n){return n?.configs?.editor?.settings?.reduce((e,t)=>{for(let i of t.fields||[])i?.id&&(e[i.id]=N(t.fields,i.id,n?.configs?.theme?.[i.id]));return e},{})}function Q6(n){return n.reduce((e,t)=>(e[m3(t.id)]=t.sectionConfigs.map(({section:i,settings:r,schema:o})=>({_id:`SectionGroup__${i.type}_${N2()}`,_component:`${i.type}`,...z(r?.section.settings,(a,s,l)=>(a[l]=N(o?.fields,l,s),a),{}),custom_css:r?.section.custom_css||"",...r?.section.blocks?{Blocks:r.section.blocks.map(a=>({_id:`Block__${i.type}__${a.type}_${N2()}`,_component:`Block__${i.type}__${a.type}`,...z(a.settings,(s,l,h)=>(s[h]=N(o?.blocks?.find(({type:u})=>u===a.type)?.fields,h,l),s),{})}))}:void 0})),e),{})}function X6(n){return(n||"").replaceAll("/","_")}function ei(n){let e=[];for(let t of n)t.presets&&e.push(...t.presets.map((i,r)=>({id:`${t.id}__preset_${r}`,entry:{_id:`${t.id}__preset_${r}`,_component:t.id,custom_css:i.settings?.custom_css||"",...z(t.fields,(o,a)=>(a.id&&(o[a.id]=N(t.fields,a.id,i.settings?.[a.id])),o),{}),Blocks:i.blocks?.reduce((o,a)=>{let s=t.blocks?.find(({type:l})=>l===a.type);return s&&o.push({_id:`Block__${t.id}__${a.type}__preset_${r}`,_component:`Block__${t.id}__${a.type}`,...z(s.fields,(l,h)=>(h.id&&(l[h.id]=N(s.fields,h.id,a.settings?.[h.id])),l),{})}),o},[])}}))),t.blocks&&e.push(...t.blocks.map(i=>({id:`Block__${t.id}__${i.type}`,entry:{_id:`Block__${t.id}__${i.type}`,_component:`Block__${t.id}__${i.type}`,...z(i.fields,(r,o)=>(o.id&&o.default!==void 0&&(r[o.id]=N(i.fields,o.id,o.default)),r),{})}})));return e.filter(t=>Object.keys(t.entry).some(i=>i!=="_id"&&i!=="_component"))}function ch(n,e,t,i,r){let o={id:"swell_global",label:"Theme settings",schema:[{prop:"swell_page",type:"component",required:!0,accepts:["swell_page"],isNonChangable:!0,noInline:a4},{prop:"$locale",type:"swell_locale",isLabelHidden:!0},...W6(n)],groups:(n?.configs?.editor?.settings??[]).map(u=>({key:u.label,label:u.label,collapsable:!0,collapsed:!0})),styles:()=>({styled:{Root:{}}})},a={id:"swell_page",label:"Page settings",schema:[{prop:X3,type:"component-collection",required:!0,noInline:a4,accepts:z6(e,i,r),placeholderAppearance:{height:250,label:"Add section",aspectRatio:1}},...K6(e,i)],allowSave:!0,styles:()=>({styled:{Root:{}}})},s=[o,a,...J6(e)],l=o.schema.find(u=>u.prop==="color_schemes");if(l){let u=l.params,{fields:d=[]}=u;s.push({id:"swell_color_scheme_group",label:"Swell color scheme",schema:d.map(m=>({prop:m.id,label:m.label,optional:!0,...D3({...m,type:m.id==="background_gradient"?"text":m.type})})),styles(){return{styled:{Root:{}}}}})}let h=[{id:"swell_global",entry:{_id:"swell_global",_component:"swell_global",...Y6(n),$locale:n?.configs?.theme?.$locale,swell_page:[{_id:"swell_page",_component:"swell_page",ContentSections:t.map(({section:u,settings:d,schema:m})=>({_id:X6(u.id),_component:`${u.type}`,custom_css:d?.section?.custom_css||"",disabled:d?.section?.disabled||!1,$locale:d?.section?.settings?.$locale,...z(m?.fields,(p,g)=>(g?.id&&(p[g.id]=N(m?.fields,g.id,d?.section?.settings?.[g.id])),p),{}),...u?.blocks?{Blocks:Object.entries(u.blocks).map(([p,g])=>({_id:`Block__${p}__${g.type}_${Math.random()}`,_component:`Block__${u.type}__${g.type}`,disabled:g.disabled||!1,...z(g.settings,(C,f,x)=>(C[x]=N(m?.blocks?.find(({type:n3})=>n3===g.type)?.fields,x,f),C),{})}))}:void 0})),...Q6(i)}]}},{id:"swell_page",entry:{_id:"swell_page",_component:"swell_page"}},...ei(e)];return{easyblocksConfig:{components:s,templates:h,backend:ti(),hideCloseButton:!0,allowSave:!0,readOnly:!1,locales:[{code:"en-US",isDefault:!0}],types:{swell_css:{type:"inline",widget:{id:"SwellCSS"}},swell_locale:{type:"inline",widget:{id:"SwellLocale"}},swell_boolean:{type:"inline",widget:{id:"SwellBoolean"}},swell_color:{type:"inline",widget:{id:"SwellColor"}},swell_color_scheme:{type:"inline",widget:{id:"SwellColorScheme"}},swell_color_scheme_group:{type:"inline",widget:{id:"SwellColorSchemeGroup"}},swell_font:{type:"inline",widget:{id:"SwellFont"}},swell_header:{type:"inline",widget:{id:"SwellHeader"}},swell_icon:{type:"inline",widget:{id:"SwellIcon"}},swell_lookup:{type:"inline",widget:{id:"SwellLookup"}},swell_menu:{type:"inline",widget:{id:"SwellMenu"}},swell_url:{type:"inline",widget:{id:"SwellUrl"}},swell_number:{type:"inline",widget:{id:"SwellNumber"}},swell_select:{type:"inline",widget:{id:"SwellSelect"}},swell_radio:{type:"inline",widget:{id:"SwellRadio"}},swell_short_text:{type:"inline",widget:{id:"SwellText"}},swell_long_text:{type:"inline",widget:{id:"SwellTextarea"}},swell_paragraph:{type:"inline",widget:{id:"SwellParagraph"}},swell_editor:{type:"inline",widget:{id:"SwellEditor"}},swell_file:{type:"inline",widget:{id:"SwellFile"}},swell_image:{type:"inline",widget:{id:"SwellImage"}}},tokens:{colors:[],fonts:[]}}}}function uh(n,e,t){let i=n.reduce((a,s)=>(a[`${s.id}`]=t("pageSection",s),a),{}),r=e.reduce((a,s)=>(a[m3(s.id)]=t("layoutSectionGroup",s),a),{}),o=n.reduce((a,s)=>{if(s.blocks)for(let l of s.blocks){let h=`Block__${s.id}__${l.type}`;a[h]=t("block",{section:s,block:l})}return a},{});return{...i,...r,...o,swell_page:t("root"),swell_global:t("global")}}function ti(){return{documents:{get({id:e}){console.log("Easyblocks backend documents.get()",e);let t={id:e,version:1,entry:{_id:"page",_component:"swell_page"}};return Promise.resolve(t)},create(e){return console.log("Easyblocks backend documents.create()",e),Promise.resolve({})},update(e){return console.log("Easyblocks backend documents.update()",e),Promise.resolve({})}},templates:{get(e){return console.log("Easyblocks backend templates.get()",e),Promise.resolve({})},getAll(){return console.log("Easyblocks backend get templates.getAll()"),Promise.resolve([])},create(e){return console.log("Easyblocks backend get templates.create()",e),Promise.resolve({})},update(e){return console.log("Easyblocks backend get templates.update()",e),Promise.resolve({})},delete(e){return console.log("Easyblocks backend get templates.delete()",e),Promise.resolve()}}}}function N2(){return(Math.random()+1).toString(36).substring(7)}function l4(n,e){let i=n?.storefront?.options?.getCookie;return typeof i=="function"&&i(e)||""}var I2=class extends A{constructor(e,t,i={}){super(e,"",t,i,async function(){let r=await B2(e,this._resourceName,t,i);return x3(this._resourceName,r,e,"",t,i)})}},H2=class extends Y{constructor(e,t,i={}){super(e,"",async function(){let r=await B2(e,this._resourceName,t,i);return x3(this._resourceName,r,e,"",t,i)})}};async function B2(n,e,t,i){let r=new URLSearchParams({...t&&{slug:t},...i&&{query:JSON.stringify(i)}}),o=r.size>0?`?${r}`:"",a=l4(n,"swell-session"),s=l4(n,"swell-data")||{};return(await fetch(`${n.storefront_url}/resources/${e}.json/${o}`,{headers:{"X-Session":a,"Swell-Data":JSON.stringify(s)}})).json()}function x3(n,e,t,i="",r,o){let a={};for(let[s,l]of Object.entries(e)){let h=i+`${i===""?"":"/"}${s}`,u;switch(l?._type){case"SwellStorefrontCollection":u=ri;break;case"SwellStorefrontRecord":u=ni;break;case"createStorefrontResource":u=ii;break;default:break}a[s]=u?u(n,t,h,r,o):l}return a}function ii(n,e,t,i,r){return new _(async function(){let o=await Ue(e,n,t,i,r);return x3(n,o,e,t,i,r)})}function ni(n,e,t,i,r){let o=q2(i,r);return new A(e,n,t,o,async function(){let a=await Ue(e,n,t,i,r);return x3(n,a,e,t,i,r)})}function ri(n,e,t,i,r){let o=q2(i,r);return new b(e,n,o,async function(){let a=await Ue(e,n,t,i,r);return x3(n,a,e,t,i,r)})}async function Ue(n,e,t,i,r){let o=new URLSearchParams({path:t,...i&&{slug:i},...r&&{query:JSON.stringify(r)}}),a=o.size>0?`?${o}`:"",s=l4(n,"swell-session"),l=l4(n,"swell-data")||{};return(await fetch(`${n.storefront_url}/resources/${e}.json${a}`,{headers:{"X-Session":s,"Swell-Data":JSON.stringify(l)}})).json()}function q2(n,e){return{...n&&{slug:n},...e}}export{e5 as DEFAULT_QUERY_PAGE_LIMIT,i3 as DeferredShopifyResource,w4 as FILE_DATA_INCLUDE_QUERY,s5 as GEO_DATA,l5 as LANG_TO_COUNTRY_CODES,K3 as LiquidSwell,Xe as MAX_QUERY_PAGE_LIMIT,I2 as MockRecordResource,H2 as MockRecordSingleton,J3 as PageError,Y3 as PageNotFound,X3 as SECTION_GROUP_CONTENT,b3 as ShopifyArticle,Ee as ShopifyBlog,g3 as ShopifyCart,G as ShopifyCollection,ve as ShopifyCollections,k3 as ShopifyCompatibility,e3 as ShopifyCustomer,T3 as ShopifyFont,n4 as ShopifyForm,_3 as ShopifyLink,M3 as ShopifyLocalization,h3 as ShopifyOrder,Ze as ShopifyPage,f3 as ShopifyPaginate,xe as ShopifyPredictiveSearch,E as ShopifyProduct,je as ShopifyRecommendations,y as ShopifyResource,Fe as ShopifySearch,U as ShopifyVariant,_ as StorefrontResource,v2 as Swell,Ve as SwellBackendAPI,o4 as SwellError,b as SwellStorefrontCollection,N3 as SwellStorefrontPagination,A as SwellStorefrontRecord,C3 as SwellStorefrontResource,Y as SwellStorefrontSingleton,r2 as SwellTheme,S as ThemeColor,R as ThemeFont,Q as ThemeForm,m4 as ThemeFormErrors,Ie as adaptShopifyFontData,He as adaptShopifyFormData,Ne as adaptShopifyMenuData,n2 as arrayToObject,c3 as deferMenuItemUrlAndResource,A6 as dehydrateSwellRefsInStorefrontResources,L3 as extractSettingsFromForm,ud as findCircularReferences,a2 as findEditorSetting,o2 as findThemeSettingsByType,u4 as fontMap,A2 as forEachKeyDeep,s2 as getAllSections,rh as getBlog,nh as getBlogs,Jd as getCategories,N6 as getCategory,Yd as getCategoryWithProducts,x2 as getContentEntry,I6 as getContentList,th as getContentModel,cd as getCountryCodeFromLocale,ti as getEasyblocksBackend,uh as getEasyblocksComponentDefinitions,ch as getEasyblocksPagePropsWithConfigs,$6 as getEasyblocksPageTemplate,hh as getEasyblocksPropsFromThemeConfigs,l2 as getLayoutSectionGroups,u3 as getMenuItemStorefrontUrl,G1 as getMenuItemUrlAndResource,q1 as getMenuItemValueId,ih as getPage,Me as getPageSections,Od as getProduct,D2 as getProducts,$d as getProductsFiltered,m3 as getSectionGroupProp,O6 as getSectionSettingsFromProps,V6 as getThemeSettingsFromProps,hd as isArray,K as isObject,l3 as md5,md as removeCircularReferences,B as resolveAsyncResources,W1 as resolveLookupCollection,H1 as resolveMenuItemUrlAndResource,t2 as resolveMenuItems,e2 as resolveMenuSettings,Te as resolveSectionSettings,Q3 as resolveThemeSettings,d2 as scopeCustomCSS,O as stringifyQueryParams,Ci as systemFonts,b2 as toBase64};
|
|
950
950
|
//# sourceMappingURL=index.mjs.map
|