@meta-cms/core
Advanced tools
Comparing version 1.0.104 to 1.0.105
@@ -1,2 +0,2 @@ | ||
"use strict";var F=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var ie=(t,e)=>{for(var r in e)F(t,r,{get:e[r],enumerable:!0})},se=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of re(e))!ne.call(t,i)&&i!==r&&F(t,i,{get:()=>e[i],enumerable:!(n=te(e,i))||n.enumerable});return t};var ae=t=>se(F({},"__esModule",{value:!0}),t);var pe={};ie(pe,{GraphqlClient:()=>h,MetaCms:()=>W,buildQuery:()=>S,chunk:()=>q,collectionFragment:()=>j,config:()=>ce,contentQuery:()=>D,fieldToMetafieldType:()=>_,getLoremCollectionData:()=>Q,getLoremImageData:()=>v,getLoremProductData:()=>x,getMetaCMSConfigQuery:()=>oe,getOwnerIdQuery:()=>N,imageFragment:()=>$,isId:()=>C,mediaImageFragment:()=>E,metafieldFragment:()=>b,metafieldsForNodes:()=>R,metafieldsQuery:()=>O,mockValue:()=>w,mustaching:()=>Z,normalizeEdges:()=>m,productFragment:()=>M,randomId:()=>g,setInNamespace:()=>P,setMetaCMSConfigMutation:()=>A,syncConfig:()=>ue,templating:()=>me,traverse:()=>T,videoFragment:()=>L});module.exports=ae(pe);var z=t=>{let e=[];return t.forEach(r=>{!r||(r.type==="product_reference"&&r.product.content&&r.product.content.map(n=>{e.push(n.id)}),r.type==="list.product_reference"&&r.values.edges.map(({node:n})=>{n.content&&n.content.map(i=>{e.push(i.id)})}),r.type==="collection_reference"&&r.collection.content&&r.collection.content.map(n=>{e.push(n.id)}),r.type==="list.collection_reference"&&r.values.edges.map(({node:n})=>{n.content&&n.content.map(i=>{e.push(i.id)})}))}),e};var A=` | ||
"use strict";var F=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var se=(t,e)=>{for(var r in e)F(t,r,{get:e[r],enumerable:!0})},ae=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ne(e))!ie.call(t,i)&&i!==r&&F(t,i,{get:()=>e[i],enumerable:!(n=re(e,i))||n.enumerable});return t};var oe=t=>ae(F({},"__esModule",{value:!0}),t);var pe={};se(pe,{GraphqlClient:()=>h,MetaCms:()=>W,buildQuery:()=>S,chunk:()=>q,collectionFragment:()=>j,config:()=>le,contentQuery:()=>D,fieldToMetafieldType:()=>_,getLoremCollectionData:()=>Q,getLoremImageData:()=>v,getLoremProductData:()=>x,getMetaCMSConfigQuery:()=>ce,getOwnerIdQuery:()=>N,imageFragment:()=>$,isId:()=>C,mediaImageFragment:()=>E,metafieldFragment:()=>b,metafieldsForNodes:()=>R,metafieldsQuery:()=>O,mockValue:()=>w,mustaching:()=>ee,normalizeEdges:()=>m,productFragment:()=>M,randomId:()=>g,setInNamespace:()=>P,setMetaCMSConfigMutation:()=>A,syncConfig:()=>ue,templating:()=>me,traverse:()=>T,videoFragment:()=>L});module.exports=oe(pe);var z=t=>{let e=[];return t.forEach(r=>{!r||(r.type==="product_reference"&&r.product.content&&r.product.content.map(n=>{e.push(n.id)}),r.type==="list.product_reference"&&r.values.edges.map(({node:n})=>{n.content&&n.content.map(i=>{e.push(i.id)})}),r.type==="collection_reference"&&r.collection.content&&r.collection.content.map(n=>{e.push(n.id)}),r.type==="list.collection_reference"&&r.values.edges.map(({node:n})=>{n.content&&n.content.map(i=>{e.push(i.id)})}))}),e};var A=` | ||
mutation ($ownerId: ID!, $value: String!, $key: String!) { | ||
@@ -9,3 +9,3 @@ metafieldsSet(metafields: [{ key: $key, namespace: "meta-cms", ownerId: $ownerId, value: $value, type: "json" }]) { | ||
} | ||
`,oe=` | ||
`,ce=` | ||
query { | ||
@@ -231,3 +231,3 @@ shop { | ||
}`;var m=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),ce=t=>t,g=()=>{let t="meta-cms-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",e="",r=10;for(;r--;)e+=t[Math.random()*t.length|0];return`meta-cms-${e}`},C=t=>typeof t=="string"?t.startsWith("gid://shopify/Metafield/"):!1,P=({content:t,namespace:e,key:r,id:n,value:i})=>{let a=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[a]:i})},S=({handles:t,ids:e})=>{let r=n=>n.replace("gid://shopify/Product/","");return(t==null?void 0:t.length)||(e==null?void 0:e.length)?`${(e||[]).map((n,i,a)=>`id:${r(n)}${a.length-1>i?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,i,a)=>`handle:${n}${a.length-1>i?" or ":""}`).join("")}`.trim():void 0},T=(t,e,r=i=>i,n=[])=>typeof t!="object"?t:(Array.isArray(t)?t:Object.entries(t)).reduce((a,s,c)=>{if(Array.isArray(t))a.push(T(s,e,r,n.concat(c)));else{let[l,u]=s;Array.isArray(u)?(a[l]=[],u.forEach((o,d)=>a[l].push(T(o,e,r,n.concat(l).concat(d))))):u&&(u.attributes?a[l]=e(u,n.concat(l)):a[l]=r(T(u,e,r,n.concat(l)),n.concat(l)))}return a},Array.isArray(t)?[]:{}),q=(t,e)=>{let r=[],n=0;for(;n<t.length;)r.push(t.slice(n,e+n)),n+=e;return r};var V=({acc:t,item:e,client:r,locale:n,jsonMetafields:i,nestedContent:a})=>{var u;let s={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},c,l=({id:o,key:d,namespace:f,objectId:p})=>{a&&t&&n&&P({content:t,key:d,id:p,namespace:f.replace(`@${n}`,""),value:a[o]})};switch(e.type){case"collection_reference":{c={attributes:s,value:{...e.collection,products:m(e.collection.products).map(({content:o,...d})=>(o==null||o.forEach(f=>l({...f,objectId:d.id})),{...d,variants:m(d.variants)}))}};break}case"file_reference":{if("image"in e&&"image"in(e==null?void 0:e.image)){(!e.image.image.alt||!e.image.image.alt.length)&&(e.image.image.alt="image"),c={attributes:s,value:{...e.image.image,id:e.image.id}};break}if("video"in e){c={attributes:s,value:e.video};break}break}case"product_reference":{let{product:o}=e;(u=o.content)==null||u.forEach(d=>l({...d,objectId:o.id})),c={attributes:s,value:{...o,variants:m(e.product.variants)}};break}case"list.collection_reference":{c={attributes:s,value:m(e.values).map(o=>{var d;return(d=o.content)==null||d.forEach(f=>l({...f,objectId:o.id})),{...o,products:m(o.products).map(f=>{var p;return(p=f.content)==null||p.forEach(y=>l({...y,objectId:f.id})),{...f,variants:m(f.variants)}})}})};break}case"list.file_reference":{c={attributes:s,value:m(e.values).map(o=>{if("image"in o)return{...o.image,id:o.id};if("video"in o)return o})};break}case"list.product_reference":{c={attributes:s,value:m(e.values).map(o=>{var d;return(d=o.content)==null||d.forEach(f=>l({...f,objectId:o.id})),{...o,variants:m(o.variants)}})};break}case"json":{let o=JSON.parse(e.value);if(o.country&&o.address&&o.locality&&o.postal_code)c={attributes:s,value:o};else{let d=U(e.value,i);c={attributes:s,value:d.value||d}}break}case"list.multi_line_text_field":case"list.single_line_text_field":{c={attributes:s,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{c={attributes:s,value:e.value||""};break}case"boolean":{c={attributes:s,value:e.value==="true"};break}case"number_decimal":{c={attributes:s,value:Number(e.value)};break}case"list.number_decimal":{c={attributes:s,value:JSON.parse(e.value,(o,d)=>Number(d))};break}case"url":{c={attributes:s,value:e.value};break}case"date_time":{c={attributes:s,value:(()=>{try{return new Date(e.value)}catch{return new Date}})()};break}}return c},G=({client:t,id:e,initalizer:r,content:n,jsonMetafields:i,nestedContent:a})=>{var c,l;let s=r||{};for(let u=0;u<n.length;u++){let o=n[u];if(o){if(!((l=(c=t.config[o.namespace.replace(`@${t.locale}`,"")])==null?void 0:c.schema)==null?void 0:l[o.key]))return s;let f=V({client:t,acc:s,item:o,jsonMetafields:i,nestedContent:a});P({content:s,key:o.key,namespace:o.namespace.replace(`@${t.locale}`,""),value:f})}}return s};var le=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(i=>{C(i)&&e.push(i)}):C(n)&&e.push(n),n)),e},K=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(le(r.value)))}),e},k=(t,e)=>t.reduce((r,n)=>(n&&(r[n.id]=V({item:n,client:e})),r),{}),U=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(i=>C(i)?e[i]:i):C(n)?e[n]:n):JSON.parse(t);var _=t=>{let r={text:"multi_line_text_field",richtext:"multi_line_text_field",image:"file_reference",product:"product_reference",collection:"collection_reference",object:"json",boolean:"boolean",video:"file_reference",url:"single_line_text_field",list:"single_line_text_field",number:"number_decimal",address:"json",date:"date_time"}[t.type];return t.isList&&r!=="json"?`list.${r}`:r},v=(t=400,e=300)=>({alt:"image",src:`https://picsum.photos/${t}/${e}`,width:t,height:e}),x=()=>({id:g(),descriptionHtml:"Lorem ipsum",title:"Lorem ipsum",handle:"",featuredImage:v(),compareAtPriceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},priceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},variants:[]}),Q=()=>({id:g(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:v(),products:[x(),x(),x()]}),J=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r};var H=(t,e=!0,r)=>Object.entries(t.schema).reduce((n,[i,a])=>{if(a.isList)a.type==="object"?n[i]=H(a,!1,r):n[i]=[];else if(a.type==="object")n[i]=H(a,!1,r);else{let s=_(a),c={itemID:g(),itemType:s,itemProp:""};n[i]=w(a,c)}return n},t.type==="object"&&e?{}:t.isList?[]:{}),w=(t,e,r=!0,n)=>{var i;switch(t.type){case"object":return t.isList?{attributes:e,value:[]}:{attributes:e,value:H(t,!0,(i=e.itemProp)==null?void 0:i.split(":")[0])};case"collection":return{attributes:e,value:t.isList?J(Q):Q()};case"image":return{value:t.isList?r?J(v):[]:r?{id:g(),...v()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?J(x):x()};case"richtext":return{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||`<i>Lorem ipsum dolor sit amet consectetur adipisicing elit</i>. | ||
Officia quisquam, vero eius nam, reiciendis fugiat dolore, sit aspernatur numquam a vitae quae laborum? Rem quidem, neque dignissimos delectus vel quasi!`};case"boolean":return{attributes:e,value:!1};case"url":return{attributes:e,value:"/"};case"list":return{attributes:e,value:t.options[0].value};case"number":return{attributes:e,value:0};case"date":return{attributes:e,value:new Date};default:case"text":return{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||"Lorem ipsum dolor sit amet consectetur adipisicing elit."}}};var de=()=>new Promise(t=>{setTimeout(t,5e3)}),h=class{constructor(e,r){this.request=async(e,r)=>{let n=await await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:r||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}});if(n.ok){let{data:i}=await n.json();return i}else throw new Error(await n.text())};this.url=e,this.headers=r}},W=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:i},a){this.getMetafieldsByIds=async e=>{if(!e.length)return[{},[]];let r=q(e,250),i=(await Promise.all(r.map(a=>{var s,c;return this.client.request(O(!1,{customProductMetafields:(c=(s=this.params)==null?void 0:s.product)==null?void 0:c.customMetafieldsIdentifiers}),{ids:a}).then(({metafields:l=[]})=>l)}))).flat();return i.length?[k(i,this),i]:[{},[]]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:r,locale:n})=>{var p,y;if(!(e!=null&&e.ids)&&!(e!=null&&e.handles)&&!(e!=null&&e.namespaces)&&!(r!=null&&r.ids)&&!(r!=null&&r.handles)&&!(r!=null&&r.namespaces))return[{},[],[]];let i=await this.client.request(R({collectionQuery:S({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:S({ids:r==null?void 0:r.ids,handles:r==null?void 0:r.handles})},{customProductMetafields:(y=(p=this.params)==null?void 0:p.product)==null?void 0:y.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers((r==null?void 0:r.namespaces)||[],n),collectionIdentifiers:this.buildIdentifiers((e==null?void 0:e.namespaces)||[],n)});if(!i)return[{},[],[]];let{products:a,collections:s}=i,c=a?m(a):[],l=s?m(s):[],u=c.map(I=>I.content).flat(),o=l.map(I=>I.content).flat(),d=k(u,this),f=k(o,this);return[{...d,...f},u.concat(o),c.concat(l)]};this.translate=async(e,r)=>{let n=Object.keys(this.config)};this.getContentForNamespaces=async e=>{var f,p,y;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let r;for(;!(r!=null&&r.shop);)r=await this.client.request(D(!0,{customProductMetafields:(f=e.product)==null?void 0:f.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((p=e.product)==null?void 0:p.namespaces)||[],e.locale),collectionIdentifiers:this.buildIdentifiers(((y=e.collection)==null?void 0:y.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)}),r!=null&&r.shop||await de();let{shop:{content:n}}=r,[[i,a],[s,c,l]]=await Promise.all([this.getMetafieldsByIds(z(n)),this.getMetafieldsForProductsAndCollection(e)]),[u,o]=await this.getMetafieldsByIds(K(n.concat(a).concat(c))),d=G({client:this,content:n,jsonMetafields:u,nestedContent:{...i,...s}});return l.forEach(({id:I,content:ee})=>{G({client:this,initalizer:d,id:I,content:ee,jsonMetafields:u,nestedContent:{...i,...s}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:d}};this.t=(e,r,{productId:n,collectionId:i})=>{let[a,s]=e.split(".");if(!(a in this.config))throw new Error(`Namespace "${a}" is not defined in the schema`);let{kind:c,schema:l}=this.config[a];if(n&&c==="product"&&(s=`${s}@${n}`),i&&c==="collection"&&(s=`${s}@${i}`),!(s in l))throw new Error(`Path "${s}" is not defined in the "${a}" schema`);let u=l[s],o=()=>{let d=_(u),f={itemID:g(),itemType:d,itemProp:`${a}:${s}`},p=this.config[a].schema[s].default;return w(u,f,!0,p)};return a in r||Object.assign(r,{[a]:{}}),[r[a][s]||o(),u,this.locale]};this.buildIdentifiers=(e,r)=>e?e.reduce((n,i)=>{let a=this.config[i];return a&&Object.keys(a.schema).forEach(s=>{n.push({namespace:`${i}@${r}`,key:s})}),n},[]):[];this.locale="en",this.adapter=a||(s=>s),this.config=e,this.defaultNameSpaces=i||[],this.client=new h(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var ue=async(t,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:n},i)=>{let a=new h(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}),s=new h(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":n}),{shop:{id:c}}=await a.request(N);return await s.request(A,{value:JSON.stringify(t),key:i,ownerId:c})};var X=/{{([\:\/\-\\\,\.a-zA-Z0-9\s])*}}/g,Z=(t,e)=>(e&&Object.keys(e).forEach(r=>{t=t.replace(new RegExp(`{{${r}}}`,"g"),String(e[r]))}),t.replace(X,"")),Y=/\(\(([\:\/\-\\\,\s\u0030-\u4351\u4e00-\u9fa5])*\)\)/g,fe=(t,e)=>{if(!e)return t;let r=t.matchAll(Y);return Array.from(r).forEach(n=>{let[i]=n,[a,s,c]=i.replace("((","").replace("))","").split(","),l=typeof e[a]=="number"?Number(e[a])>1:!!e[a];c?l===!0?t=t.replace(i,c.trim()):t=t.replace(i,s.trim()):l===!0?(c=s,t=t.replace(i,c.trim())):t=t.replace(Y,"")}),t},me=(t,e)=>fe(Z(t,e),e);0&&(module.exports={GraphqlClient,MetaCms,buildQuery,chunk,collectionFragment,config,contentQuery,fieldToMetafieldType,getLoremCollectionData,getLoremImageData,getLoremProductData,getMetaCMSConfigQuery,getOwnerIdQuery,imageFragment,isId,mediaImageFragment,metafieldFragment,metafieldsForNodes,metafieldsQuery,mockValue,mustaching,normalizeEdges,productFragment,randomId,setInNamespace,setMetaCMSConfigMutation,syncConfig,templating,traverse,videoFragment}); | ||
}`;var m=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),le=t=>t,g=()=>{let t="meta-cms-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",e="",r=10;for(;r--;)e+=t[Math.random()*t.length|0];return`meta-cms-${e}`},C=t=>typeof t=="string"?t.startsWith("gid://shopify/Metafield/"):!1,P=({content:t,namespace:e,key:r,id:n,value:i})=>{let a=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[a]:i})},S=({handles:t,ids:e})=>{let r=n=>n.replace("gid://shopify/Product/","");return(t==null?void 0:t.length)||(e==null?void 0:e.length)?`${(e||[]).map((n,i,a)=>`id:${r(n)}${a.length-1>i?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,i,a)=>`handle:${n}${a.length-1>i?" or ":""}`).join("")}`.trim():void 0},T=(t,e,r=i=>i,n=[])=>typeof t!="object"?t:(Array.isArray(t)?t:Object.entries(t)).reduce((a,s,c)=>{if(Array.isArray(t))a.push(T(s,e,r,n.concat(c)));else{let[l,u]=s;Array.isArray(u)?(a[l]=[],u.forEach((o,d)=>a[l].push(T(o,e,r,n.concat(l).concat(d))))):u&&(u.attributes?a[l]=e(u,n.concat(l)):a[l]=r(T(u,e,r,n.concat(l)),n.concat(l)))}return a},Array.isArray(t)?[]:{}),q=(t,e)=>{let r=[],n=0;for(;n<t.length;)r.push(t.slice(n,e+n)),n+=e;return r};var V=({acc:t,item:e,client:r,locale:n,jsonMetafields:i,nestedContent:a})=>{var u;let s={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},c,l=({id:o,key:d,namespace:f,objectId:p})=>{a&&t&&n&&P({content:t,key:d,id:p,namespace:f.replace(`@${n}`,""),value:a[o]})};switch(e.type){case"collection_reference":{c={attributes:s,value:{...e.collection,products:m(e.collection.products).map(({content:o,...d})=>(o==null||o.forEach(f=>l({...f,objectId:d.id})),{...d,variants:m(d.variants)}))}};break}case"file_reference":{if("image"in e&&"image"in(e==null?void 0:e.image)){(!e.image.image.alt||!e.image.image.alt.length)&&(e.image.image.alt="image"),c={attributes:s,value:{...e.image.image,id:e.image.id}};break}if("video"in e){c={attributes:s,value:e.video};break}break}case"product_reference":{let{product:o}=e;(u=o.content)==null||u.forEach(d=>l({...d,objectId:o.id})),c={attributes:s,value:{...o,variants:m(e.product.variants)}};break}case"list.collection_reference":{c={attributes:s,value:m(e.values).map(o=>{var d;return(d=o.content)==null||d.forEach(f=>l({...f,objectId:o.id})),{...o,products:m(o.products).map(f=>{var p;return(p=f.content)==null||p.forEach(y=>l({...y,objectId:f.id})),{...f,variants:m(f.variants)}})}})};break}case"list.file_reference":{c={attributes:s,value:m(e.values).map(o=>{if("image"in o)return{...o.image,id:o.id};if("video"in o)return o})};break}case"list.product_reference":{c={attributes:s,value:m(e.values).map(o=>{var d;return(d=o.content)==null||d.forEach(f=>l({...f,objectId:o.id})),{...o,variants:m(o.variants)}})};break}case"json":{let o=JSON.parse(e.value);if(o.country&&o.address&&o.locality&&o.postal_code)c={attributes:s,value:o};else{let d=U(e.value,i);c={attributes:s,value:d.value||d}}break}case"list.multi_line_text_field":case"list.single_line_text_field":{c={attributes:s,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{c={attributes:s,value:e.value||""};break}case"boolean":{c={attributes:s,value:e.value==="true"};break}case"number_decimal":{c={attributes:s,value:Number(e.value)};break}case"list.number_decimal":{c={attributes:s,value:JSON.parse(e.value,(o,d)=>Number(d))};break}case"url":{c={attributes:s,value:e.value};break}case"date_time":{c={attributes:s,value:(()=>{try{return new Date(e.value)}catch{return new Date}})()};break}}return c},G=({client:t,id:e,initalizer:r,content:n,jsonMetafields:i,nestedContent:a})=>{var c,l;let s=r||{};for(let u=0;u<n.length;u++){let o=n[u];if(o){if(!((l=(c=t.config[o.namespace.replace(`@${t.locale}`,"")])==null?void 0:c.schema)==null?void 0:l[o.key]))return s;let f=V({client:t,acc:s,item:o,jsonMetafields:i,nestedContent:a});P({content:s,key:o.key,namespace:o.namespace.replace(`@${t.locale}`,""),value:f})}}return s};var de=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(i=>{C(i)&&e.push(i)}):C(n)&&e.push(n),n)),e},K=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(de(r.value)))}),e},k=(t,e)=>t.reduce((r,n)=>(n&&(r[n.id]=V({item:n,client:e})),r),{}),U=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(i=>C(i)?e[i]:i):C(n)?e[n]:n):JSON.parse(t);var _=t=>{let r={text:"multi_line_text_field",richtext:"multi_line_text_field",image:"file_reference",product:"product_reference",collection:"collection_reference",object:"json",boolean:"boolean",video:"file_reference",url:"single_line_text_field",list:"single_line_text_field",number:"number_decimal",address:"json",date:"date_time"}[t.type];return t.isList&&r!=="json"?`list.${r}`:r},v=(t=400,e=300)=>({alt:"image",src:`https://picsum.photos/${t}/${e}`,width:t,height:e}),x=()=>({id:g(),descriptionHtml:"Lorem ipsum",title:"Lorem ipsum",handle:"",featuredImage:v(),compareAtPriceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},priceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},variants:[]}),Q=()=>({id:g(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:v(),products:[x(),x(),x()]}),J=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r};var H=(t,e=!0,r)=>Object.entries(t.schema).reduce((n,[i,a])=>{if(a.isList)a.type==="object"?n[i]=H(a,!1,r):n[i]=[];else if(a.type==="object")n[i]=H(a,!1,r);else{let s=_(a),c={itemID:g(),itemType:s,itemProp:""};n[i]=w(a,c)}return n},t.type==="object"&&e?{}:t.isList?[]:{}),w=(t,e,r=!0,n)=>{var i;switch(t.type){case"object":return t.isList?{attributes:e,value:[]}:{attributes:e,value:H(t,!0,(i=e.itemProp)==null?void 0:i.split(":")[0])};case"collection":return{attributes:e,value:t.isList?J(Q):Q()};case"image":return{value:t.isList?r?J(v):[]:r?{id:g(),...v()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?J(x):x()};case"richtext":return{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||`<i>Lorem ipsum dolor sit amet consectetur adipisicing elit</i>. | ||
Officia quisquam, vero eius nam, reiciendis fugiat dolore, sit aspernatur numquam a vitae quae laborum? Rem quidem, neque dignissimos delectus vel quasi!`};case"boolean":return{attributes:e,value:!1};case"url":return{attributes:e,value:"/"};case"list":return{attributes:e,value:t.options[0].value};case"number":return{attributes:e,value:0};case"date":return{attributes:e,value:new Date};default:case"text":return{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||"Lorem ipsum dolor sit amet consectetur adipisicing elit."}}};var X=(t=5e3)=>new Promise(e=>{setTimeout(e,t)}),h=class{constructor(e,r){this.request=async(e,r)=>{let n=await await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:r||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}});if(n.ok){let{data:i}=await n.json();return i}else throw new Error(await n.text())};this.url=e,this.headers=r}},W=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:i},a){this.getMetafieldsByIds=async e=>{if(!e.length)return[{},[]];let r=q(e,250),i=(await Promise.all(r.map(async a=>{var s,c;return await X(1),this.client.request(O(!1,{customProductMetafields:(c=(s=this.params)==null?void 0:s.product)==null?void 0:c.customMetafieldsIdentifiers}),{ids:a}).then(({metafields:l=[]})=>l)}))).flat();return i.length?[k(i,this),i]:[{},[]]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:r,locale:n})=>{var p,y;if(!(e!=null&&e.ids)&&!(e!=null&&e.handles)&&!(e!=null&&e.namespaces)&&!(r!=null&&r.ids)&&!(r!=null&&r.handles)&&!(r!=null&&r.namespaces))return[{},[],[]];let i=await this.client.request(R({collectionQuery:S({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:S({ids:r==null?void 0:r.ids,handles:r==null?void 0:r.handles})},{customProductMetafields:(y=(p=this.params)==null?void 0:p.product)==null?void 0:y.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers((r==null?void 0:r.namespaces)||[],n),collectionIdentifiers:this.buildIdentifiers((e==null?void 0:e.namespaces)||[],n)});if(!i)return[{},[],[]];let{products:a,collections:s}=i,c=a?m(a):[],l=s?m(s):[],u=c.map(I=>I.content).flat(),o=l.map(I=>I.content).flat(),d=k(u,this),f=k(o,this);return[{...d,...f},u.concat(o),c.concat(l)]};this.translate=async(e,r)=>{let n=Object.keys(this.config)};this.getContentForNamespaces=async e=>{var f,p,y;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let r;for(;!(r!=null&&r.shop);)r=await this.client.request(D(!0,{customProductMetafields:(f=e.product)==null?void 0:f.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((p=e.product)==null?void 0:p.namespaces)||[],e.locale),collectionIdentifiers:this.buildIdentifiers(((y=e.collection)==null?void 0:y.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)}),r!=null&&r.shop||await X();let{shop:{content:n}}=r,[[i,a],[s,c,l]]=await Promise.all([this.getMetafieldsByIds(z(n)),this.getMetafieldsForProductsAndCollection(e)]),[u,o]=await this.getMetafieldsByIds(K(n.concat(a).concat(c))),d=G({client:this,content:n,jsonMetafields:u,nestedContent:{...i,...s}});return l.forEach(({id:I,content:te})=>{G({client:this,initalizer:d,id:I,content:te,jsonMetafields:u,nestedContent:{...i,...s}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:d}};this.t=(e,r,{productId:n,collectionId:i})=>{let[a,s]=e.split(".");if(!(a in this.config))throw new Error(`Namespace "${a}" is not defined in the schema`);let{kind:c,schema:l}=this.config[a];if(n&&c==="product"&&(s=`${s}@${n}`),i&&c==="collection"&&(s=`${s}@${i}`),!(s in l))throw new Error(`Path "${s}" is not defined in the "${a}" schema`);let u=l[s],o=()=>{let d=_(u),f={itemID:g(),itemType:d,itemProp:`${a}:${s}`},p=this.config[a].schema[s].default;return w(u,f,!0,p)};return a in r||Object.assign(r,{[a]:{}}),[r[a][s]||o(),u,this.locale]};this.buildIdentifiers=(e,r)=>e?e.reduce((n,i)=>{let a=this.config[i];return a&&Object.keys(a.schema).forEach(s=>{n.push({namespace:`${i}@${r}`,key:s})}),n},[]):[];this.locale="en",this.adapter=a||(s=>s),this.config=e,this.defaultNameSpaces=i||[],this.client=new h(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var ue=async(t,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:n},i)=>{let a=new h(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}),s=new h(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":n}),{shop:{id:c}}=await a.request(N);return await s.request(A,{value:JSON.stringify(t),key:i,ownerId:c})};var Y=/{{([\:\/\-\\\,\.a-zA-Z0-9\s])*}}/g,ee=(t,e)=>(e&&Object.keys(e).forEach(r=>{t=t.replace(new RegExp(`{{${r}}}`,"g"),String(e[r]))}),t.replace(Y,"")),Z=/\(\(([\:\/\-\\\,\s\u0030-\u4351\u4e00-\u9fa5])*\)\)/g,fe=(t,e)=>{if(!e)return t;let r=t.matchAll(Z);return Array.from(r).forEach(n=>{let[i]=n,[a,s,c]=i.replace("((","").replace("))","").split(","),l=typeof e[a]=="number"?Number(e[a])>1:!!e[a];c?l===!0?t=t.replace(i,c.trim()):t=t.replace(i,s.trim()):l===!0?(c=s,t=t.replace(i,c.trim())):t=t.replace(Z,"")}),t},me=(t,e)=>fe(ee(t,e),e);0&&(module.exports={GraphqlClient,MetaCms,buildQuery,chunk,collectionFragment,config,contentQuery,fieldToMetafieldType,getLoremCollectionData,getLoremImageData,getLoremProductData,getMetaCMSConfigQuery,getOwnerIdQuery,imageFragment,isId,mediaImageFragment,metafieldFragment,metafieldsForNodes,metafieldsQuery,mockValue,mustaching,normalizeEdges,productFragment,randomId,setInNamespace,setMetaCMSConfigMutation,syncConfig,templating,traverse,videoFragment}); |
{ | ||
"name": "@meta-cms/core", | ||
"version": "1.0.104", | ||
"version": "1.0.105", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38626