@swell/apps-sdk 1.0.48 → 1.0.49

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 CHANGED
@@ -39,5 +39,5 @@ ${a}`),super(a),this.name="SwellError",this.status=e.status||500}};function F2(i
39
39
  `.trim(),n},{})}async renderSection(t,e){e&&this.setGlobals(e);let[a,l]=t?.split(/\_\_/).reverse(),n=await this.getThemeTemplateConfigByType(l?"templates":"sections",l||a);if(n){let c=await this.renderThemeTemplate(n.file_path,e);if(l&&c?.sections){let r={id:n.name,sections:{[a]:c?.sections?.[a]}},[s]=await this.renderPageSections(r,e);return s.output||""}return c}return""}async renderLayout(t){return this.liquidSwell.layoutName?this.renderLayoutTemplate(this.liquidSwell.layoutName,t):t?.content_for_layout||""}getContentForHeader(){let t=`
40
40
  `;return t+=this.renderFontHeaderLinks(),this.shopifyCompatibility&&(t+=`
41
41
  ${this.shopifyCompatibility.getContentForHeader()}`),t}renderFontHeaderLinks(){let t=this.globals.settings,e=this.globals.configs?.editor?.settings||[];if(t&&e){let a=t5("font",t,e),l=[];for(let n=0;n<a.length;n++){let c=a[n].value?.id||a[n].value;if(this.shopifyCompatibility){let r=this.shopifyCompatibility.getFontFromShopifySetting(c);l.includes(r||c)||l.push(r||c)}else l.includes(c)||l.push(c)}if(a.length>0)return`<link href="${A.combinedGoogleFontUrl(l)}" rel="stylesheet">`}return""}async getTemplateSchema(t){let e,a=await this.getThemeConfig(t.file_path);if(a){if(a.file_path.endsWith(".liquid")){if(this.shopifyCompatibility){this.liquidSwell.lastSchema=void 0,await this.renderTemplate(a);let l=this.liquidSwell.lastSchema||{};if(l){let n=this.shopifyCompatibility.getSectionConfigSchema(l);e=await this.shopifyCompatibility.renderSchemaTranslations(this,n,this.globals.request?.locale)}}}else if(a.file_data)try{e=JSON.parse(a?.file_data)||void 0}catch{}return e}}async resolveSectionDefaultSettings(t,e){let a={},l=e||t?.default||{};return t?.fields&&t.fields.forEach(n=>{n.default!==void 0&&(a[n.id]=n.default)}),Object.assign(a,l.settings,{blocks:l.blocks}),a.blocks instanceof Array&&(a.blocks=a.blocks.map(n=>{let c={},r=t?.blocks?.find(s=>s.type===n.type);return r?.fields&&r.fields.forEach(s=>{s.default!==void 0&&(c[s.id]=s.default)}),{...n,settings:{...c,...n.settings||void 0}}})),a}async getAllSections(){let t=await this.getAllThemeConfigs();return Z2(t,this.getTemplateSchema.bind(this))}async getPageSections(t,e=!0){let a=await J1(t,l=>this.getSectionSchema(l));if(e)for(let l of a){let{schema:n}=l;n?.fields&&this.globals&&l.settings&&(l.settings=S2(this,l))}return a}async getPageSectionGroups(t){let e=await this.getThemeTemplateConfigByType("templates",t);if(e===null)return[];let l=Q3(e).layout||"theme",n=await this.getThemeTemplateConfigByType("layouts",`${l}.liquid`);if(n===null)return[];let c=await this.getThemeConfig("theme/locales/en.default.schema.json"),r=Q3(c),m=n.file_data.matchAll(/\bsections \'(\w.*?)\'|(\bcontent_for_layout\b)/gm),u=[];for(let o of m)if(o[1]){let f=o[1],p=await this.getThemeTemplateConfigByType("sections",`${f}.json`),g=Q3(p).name;typeof g=="string"&&g.startsWith("t:")&&(g=(0,_.get)(r,g.slice(2))),u.push({prop:t1(f),label:g||f})}else o[2]&&u.push({prop:D1,label:"Template"});return u}async getLayoutSectionGroups(t=!0){let e=await this.getAllThemeConfigs(),a=await E2(e,this.getTemplateSchema.bind(this));if(t)for(let l of a)for(let n of l.sectionConfigs){let{schema:c}=n;c?.fields&&this.globals&&n.settings&&(n.settings=S2(this,n))}return a}async renderPageSections(t,e){let a=await this.getPageSections(t,!0);return this.renderSectionConfigs(a,e)}async renderSectionConfigs(t,e){return await Promise.all(t.map((a,l)=>{let{section:n,schema:c}=a,{settings:r}=a;return c?.fields&&this.globals&&(r=S2(this,a)),new Promise(async s=>{let m=await this.getThemeTemplateConfigByType("sections",`${n.type}.liquid`),u="";m&&(u=await this.renderTemplate(m,{...e,...r,index:l,template:m}),r?.section.settings.custom_css&&(u+=`<style>${I2(r?.section.settings.custom_css,r.section.id)}</style>`)),s({...a,output:u})})}))}async renderTemplateSections(t,e){return(await this.renderPageSections(t,e)).map(l=>`<${l.tag} ${l.class?`class="${l.class}"`:""}>${l.output}</${l.tag}>`).join(`
42
- `)}async renderTranslation(t,e,a){let l=this.globals.translations,n=this.globals.request?.locale;return this.renderTranslationValue(n,l,t,e,a)}async renderTranslationValue(t,e,a,l,n){if(a===void 0)return n||"";let c=a?.split(".")||[],r=c.pop()||"",s=c.join("."),m=(0,_.get)(e,s),u=(0,_.get)(m?.[t],r)||(0,_.get)(m?.[t.split("-")[0]],r)||m?.[r];return l?.count!==void 0&&u?.one&&(u=l.count===1?u.one:u.other),typeof u!="string"||u===""?n||"":await this.renderTemplateString(u,l)||n||""}renderCurrency(t,e){let a=this.swell.storefront.settings,l=this.swell.storefront.currency,n=a.state,c=l.code=n?.store?.currency||"USD";return l.locale=n?.store?.locale||"en-US",l.state=n?.store?.locales?.find(r=>r.code===c)||{code:c},l.format(t,e)}},F1=class{title;status=500;message;description;constructor(t="Something went wrong",e=500,a){this.title=String(t),this.status=e,this.message=this.title+(a?`: ${a}`:""),this.description=a}toString(){return this.message}},V1=class extends F1{constructor(t="Page not found",e=404,a){super(t,e,a)}};function S2(i,t){let{settings:e,schema:a}=t;if(!a||!e?.section?.settings)return e;let l=[{label:a.label,fields:a.fields}];return{...e,section:{...e.section,id:a.id,settings:q1(i,e.section.settings,l),blocks:e.section.blocks?.map(n=>({...n,settings:q1(i,n.settings,a.blocks?.filter(c=>c.type===n.type))}))}}}function q1(i,t,e){let a=(0,_.cloneDeep)(t);return(0,_.each)(a,(l,n)=>{let c=(e&&e5(e,n))??null;if(A1(l)&&!(l instanceof C)){switch(c?.type){case"color_scheme_group":{(0,_.each)(l,(r,s)=>{(0,_.each)(l[s].settings,(m,u)=>{(0,_.find)(c.fields,{id:u})?.type==="color"&&m&&(l[s].id=s,l[s].settings[u]=new S(m))})});return}default:break}a[n]=q1(i,l,e)}else switch(c?.type){case"lookup":case"product_lookup":case"category_lookup":case"customer_lookup":a[n]=i.resolveLookupSetting(c,l);break;case"color":l&&(a[n]=new S(l));break;case"font":a[n]=i.resolveFontSetting(l);break;case"menu":a[n]=i.resolveMenuSetting(l);break;case"url":a[n]=i.resolveUrlSetting(l);break}}),a}function t5(i,t,e){let a=[];return(0,_.each)(t,(l,n)=>{if(A1(l)&&!(l instanceof A)&&!(l instanceof C))a.push(...t5(i,l,e));else{let c=e5(e,n);c?.type===i&&a.push({setting:c,value:l})}}),a}function it(i){if(i.collection)return i.collection;switch(i.type){case"product_lookup":return"products";case"category_lookup":return"categories";case"customer_lookup":return"accounts";default:break}}function e5(i,t){for(let e of i||[])for(let a of e.fields)if(a.id===t)return a;return null}function Q3(i){try{return JSON.parse(i?.file_data||"{}")}catch{return{}}}function z2(i,t){let a=i?.storefront?.options?.getCookie;return typeof a=="function"&&a(t)||""}var a5=class extends M{constructor(t,e,a={}){super(t,"",e,a,async function(){let l=await lt(t,this._resourceName,e,a);return G1(this._resourceName,l,t,"",e,a)})}},i5=class extends G{constructor(t,e,a={}){super(t,"",async function(){let l=await lt(t,this._resourceName,e,a);return G1(this._resourceName,l,t,"",e,a)})}};async function lt(i,t,e,a){let l=new URLSearchParams({...e&&{slug:e},...a&&{query:JSON.stringify(a)}}),n=z2(i,"swell-session"),c=z2(i,"swell-data");return(await fetch(`${i.storefront_url}/resources/${t}.json/?${l.toString()}`,{headers:{"X-Session":n,"Swell-Data":JSON.stringify(c)}})).json()}function G1(i,t,e,a="",l,n){let c={};for(let r in t){let s=t[r],m=a+`${a===""?"":"/"}${r}`,u;switch(s?._type){case"SwellStorefrontCollection":u=Fe;break;case"SwellStorefrontRecord":u=Ie;break;case"createStorefrontResource":u=He;break;default:break}c[r]=u?u(i,e,m,l,n):s}return c}function He(i,t,e,a,l){return new C(async function(){let n=await l5(t,i,e,a,l);return G1(i,n,t,e,a,l)})}function Ie(i,t,e,a,l){return new M(t,i,e,{},async function(){let n=await l5(t,i,e,a,l);return G1(i,n,t,e,a,l)})}function Fe(i,t,e,a,l){return new T(t,i,{},async function(){let n=await l5(t,i,e,a,l);return G1(i,n,t,e,a,l)})}async function l5(i,t,e,a,l){let n=new URLSearchParams({path:e,...a&&{slug:a},...l&&{query:JSON.stringify(l)}}),c=z2(i,"swell-session"),r=z2(i,"swell-data");return(await fetch(`${i.storefront_url}/resources/${t}.json?${n}`,{headers:{"X-Session":c,"Swell-Data":JSON.stringify(r)}})).json()}0&&(module.exports={DEFAULT_QUERY_PAGE_LIMIT,DeferredShopifyResource,FILE_DATA_INCLUDE_QUERY,GEO_DATA,LANG_TO_COUNTRY_CODES,LiquidSwell,MAX_QUERY_PAGE_LIMIT,MockRecordResource,MockRecordSingleton,PageError,PageNotFound,SECTION_GROUP_CONTENT,ShopifyArticle,ShopifyBlog,ShopifyCart,ShopifyCollection,ShopifyCollections,ShopifyCompatibility,ShopifyCustomer,ShopifyFont,ShopifyForm,ShopifyLink,ShopifyLocalization,ShopifyOrder,ShopifyPage,ShopifyPaginate,ShopifyPredictiveSearch,ShopifyProduct,ShopifyResource,ShopifySearch,ShopifyVariant,StorefrontResource,Swell,SwellBackendAPI,SwellError,SwellStorefrontCollection,SwellStorefrontPagination,SwellStorefrontRecord,SwellStorefrontResource,SwellStorefrontSingleton,SwellTheme,ThemeColor,ThemeFont,ThemeForm,ThemeFormErrors,adaptShopifyFontData,adaptShopifyFormData,adaptShopifyMenuData,arrayToObject,brightness,deferMenuItemUrlAndResource,dehydrateSwellRefsInStorefrontResources,diff,extractSettingsFromForm,findCircularReferences,findEditorSetting,findThemeSettingsByType,fontMap,forEachKeyDeep,getAllSections,getBlog,getBlogs,getCategories,getCategory,getCategoryWithProducts,getContentEntry,getContentList,getContentModel,getCountryCodeFromLocale,getEasyblocksBackend,getEasyblocksComponentDefinitions,getEasyblocksPagePropsWithConfigs,getEasyblocksPageTemplate,getEasyblocksPropsFromThemeConfigs,getLayoutSectionGroups,getMenuItemStorefrontUrl,getMenuItemUrlAndResource,getMenuItemValueId,getPage,getPageSections,getProduct,getProducts,getProductsFiltered,getSectionGroupProp,getSectionSettingsFromProps,getThemeSettingsFromProps,isArray,isObject,md5,mix,removeCircularReferences,resolveAsyncResources,resolveLookupCollection,resolveMenuItemUrlAndResource,resolveMenuItems,resolveMenuSettings,resolveSectionSettings,resolveThemeSettings,scopeCustomCSS,stringifyQueryParams,systemFonts,themeConfigQuery,toBase64});
42
+ `)}async renderTranslation(t,e,a){let l=this.globals.translations,n=this.globals.request?.locale;return this.renderTranslationValue(n,l,t,e,a)}async renderTranslationValue(t,e,a,l,n){if(a===void 0)return n||"";let c=a?.split(".")||[],r=c.pop()||"",s=c.join("."),m=(0,_.get)(e,s),u=(0,_.get)(m?.[t],r)||(0,_.get)(m?.[t.split("-")[0]],r)||m?.[r];return l?.count!==void 0&&u?.one&&(u=l.count===1?u.one:u.other),typeof u!="string"||u===""?n||"":await this.renderTemplateString(u,l)||n||""}renderCurrency(t,e){let a=this.swell.storefront.settings,l=this.swell.storefront.currency,n=a.state,c=l.code=n?.store?.currency||"USD";return l.locale=n?.store?.locale||"en-US",l.state=n?.store?.locales?.find(r=>r.code===c)||{code:c},l.format(t,e)}},F1=class{title;status=500;message;description;constructor(t="Something went wrong",e=500,a){this.title=String(t),this.status=e,this.message=this.title+(a?`: ${a}`:""),this.description=a}toString(){return this.message}},V1=class extends F1{constructor(t="Page not found",e=404,a){super(t,e,a)}};function S2(i,t){let{settings:e,schema:a}=t;if(!a||!e?.section?.settings)return e;let l=[{label:a.label,fields:a.fields}];return{...e,section:{...e.section,id:a.id,settings:q1(i,e.section.settings,l),blocks:e.section.blocks?.map(n=>({...n,settings:q1(i,n.settings,a.blocks?.filter(c=>c.type===n.type))}))}}}function q1(i,t,e){let a=(0,_.cloneDeep)(t);return(0,_.each)(a,(l,n)=>{let c=(e&&e5(e,n))??null;if(A1(l)&&!(l instanceof C)){switch(c?.type){case"color_scheme_group":{(0,_.each)(l,(r,s)=>{(0,_.each)(l[s].settings,(m,u)=>{(0,_.find)(c.fields,{id:u})?.type==="color"&&m&&(l[s].id=s,l[s].settings[u]=new S(m))})});return}default:break}a[n]=q1(i,l,e)}else switch(c?.type){case"lookup":case"product_lookup":case"category_lookup":case"customer_lookup":a[n]=i.resolveLookupSetting(c,l);break;case"color":l&&(a[n]=new S(l));break;case"font":a[n]=i.resolveFontSetting(l);break;case"menu":a[n]=i.resolveMenuSetting(l);break;case"url":a[n]=i.resolveUrlSetting(l);break}}),a}function t5(i,t,e){let a=[];return(0,_.each)(t,(l,n)=>{if(A1(l)&&!(l instanceof A)&&!(l instanceof C))a.push(...t5(i,l,e));else{let c=e5(e,n);c?.type===i&&a.push({setting:c,value:l})}}),a}function it(i){if(i.collection)return i.collection;switch(i.type){case"product_lookup":return"products";case"category_lookup":return"categories";case"customer_lookup":return"accounts";default:break}}function e5(i,t){for(let e of i||[])for(let a of e.fields)if(a.id===t)return a;return null}function Q3(i){try{return JSON.parse(i?.file_data||"{}")}catch{return{}}}function z2(i,t){let a=i?.storefront?.options?.getCookie;return typeof a=="function"&&a(t)||""}var a5=class extends M{constructor(t,e,a={}){super(t,"",e,a,async function(){let l=await lt(t,this._resourceName,e,a);return G1(this._resourceName,l,t,"",e,a)})}},i5=class extends G{constructor(t,e,a={}){super(t,"",async function(){let l=await lt(t,this._resourceName,e,a);return G1(this._resourceName,l,t,"",e,a)})}};async function lt(i,t,e,a){let l=new URLSearchParams({...e&&{slug:e},...a&&{query:JSON.stringify(a)}}),n=z2(i,"swell-session"),c=z2(i,"swell-data")||{};return(await fetch(`${i.storefront_url}/resources/${t}.json/?${l.toString()}`,{headers:{"X-Session":n,"Swell-Data":JSON.stringify(c)}})).json()}function G1(i,t,e,a="",l,n){let c={};for(let r in t){let s=t[r],m=a+`${a===""?"":"/"}${r}`,u;switch(s?._type){case"SwellStorefrontCollection":u=Fe;break;case"SwellStorefrontRecord":u=Ie;break;case"createStorefrontResource":u=He;break;default:break}c[r]=u?u(i,e,m,l,n):s}return c}function He(i,t,e,a,l){return new C(async function(){let n=await l5(t,i,e,a,l);return G1(i,n,t,e,a,l)})}function Ie(i,t,e,a,l){return new M(t,i,e,{},async function(){let n=await l5(t,i,e,a,l);return G1(i,n,t,e,a,l)})}function Fe(i,t,e,a,l){return new T(t,i,{},async function(){let n=await l5(t,i,e,a,l);return G1(i,n,t,e,a,l)})}async function l5(i,t,e,a,l){let n=new URLSearchParams({path:e,...a&&{slug:a},...l&&{query:JSON.stringify(l)}}),c=z2(i,"swell-session"),r=z2(i,"swell-data")||{};return(await fetch(`${i.storefront_url}/resources/${t}.json?${n}`,{headers:{"X-Session":c,"Swell-Data":JSON.stringify(r)}})).json()}0&&(module.exports={DEFAULT_QUERY_PAGE_LIMIT,DeferredShopifyResource,FILE_DATA_INCLUDE_QUERY,GEO_DATA,LANG_TO_COUNTRY_CODES,LiquidSwell,MAX_QUERY_PAGE_LIMIT,MockRecordResource,MockRecordSingleton,PageError,PageNotFound,SECTION_GROUP_CONTENT,ShopifyArticle,ShopifyBlog,ShopifyCart,ShopifyCollection,ShopifyCollections,ShopifyCompatibility,ShopifyCustomer,ShopifyFont,ShopifyForm,ShopifyLink,ShopifyLocalization,ShopifyOrder,ShopifyPage,ShopifyPaginate,ShopifyPredictiveSearch,ShopifyProduct,ShopifyResource,ShopifySearch,ShopifyVariant,StorefrontResource,Swell,SwellBackendAPI,SwellError,SwellStorefrontCollection,SwellStorefrontPagination,SwellStorefrontRecord,SwellStorefrontResource,SwellStorefrontSingleton,SwellTheme,ThemeColor,ThemeFont,ThemeForm,ThemeFormErrors,adaptShopifyFontData,adaptShopifyFormData,adaptShopifyMenuData,arrayToObject,brightness,deferMenuItemUrlAndResource,dehydrateSwellRefsInStorefrontResources,diff,extractSettingsFromForm,findCircularReferences,findEditorSetting,findThemeSettingsByType,fontMap,forEachKeyDeep,getAllSections,getBlog,getBlogs,getCategories,getCategory,getCategoryWithProducts,getContentEntry,getContentList,getContentModel,getCountryCodeFromLocale,getEasyblocksBackend,getEasyblocksComponentDefinitions,getEasyblocksPagePropsWithConfigs,getEasyblocksPageTemplate,getEasyblocksPropsFromThemeConfigs,getLayoutSectionGroups,getMenuItemStorefrontUrl,getMenuItemUrlAndResource,getMenuItemValueId,getPage,getPageSections,getProduct,getProducts,getProductsFiltered,getSectionGroupProp,getSectionSettingsFromProps,getThemeSettingsFromProps,isArray,isObject,md5,mix,removeCircularReferences,resolveAsyncResources,resolveLookupCollection,resolveMenuItemUrlAndResource,resolveMenuItems,resolveMenuSettings,resolveSectionSettings,resolveThemeSettings,scopeCustomCSS,stringifyQueryParams,systemFonts,themeConfigQuery,toBase64});
43
43
  //# sourceMappingURL=index.cjs.map