Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@meta-cms/core

Package Overview
Dependencies
Maintainers
2
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meta-cms/core - npm Package Compare versions

Comparing version 1.0.66 to 1.0.67

36

index.js

@@ -1,2 +0,2 @@

"use strict";var N=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var ne=(t,e)=>{for(var r in e)N(t,r,{get:e[r],enumerable:!0})},se=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of te(e))!re.call(t,s)&&s!==r&&N(t,s,{get:()=>e[s],enumerable:!(n=ee(e,s))||n.enumerable});return t};var ae=t=>se(N({},"__esModule",{value:!0}),t);var me={};ne(me,{GraphqlClient:()=>C,MetaCms:()=>W,buildQuery:()=>P,collectionFragment:()=>L,config:()=>oe,contentQuery:()=>R,fieldToMetafieldType:()=>H,getLoremCollectionData:()=>_,getLoremImageData:()=>$,getLoremProductData:()=>h,getMetaCMSConfigQuery:()=>ie,getOwnerIdQuery:()=>w,imageFragment:()=>M,isId:()=>I,mediaImageFragment:()=>E,metafieldFragment:()=>v,metafieldsForNodes:()=>q,metafieldsQuery:()=>j,mockValue:()=>z,mustaching:()=>Z,normalizeEdges:()=>m,productFragment:()=>b,randomId:()=>y,setInNamespace:()=>S,setMetaCMSConfigMutation:()=>F,syncConfig:()=>de,templating:()=>fe,traverse:()=>T,videoFragment:()=>O});module.exports=ae(me);var x=(t,e,r)=>{if(!t)return r?r():void 0;var n,s;if(Array.isArray(e)&&(n=e.slice(0)),typeof e=="string"&&(n=e.split(".")),typeof e=="symbol"&&(n=[e]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");for(;n.length;)if(s=n.shift(),!t||(t=t[s],t===void 0))return r?r():void 0;return t};var B=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(s=>{e.push(s.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(s=>{e.push(s.id)})}))}),e};var F=`
"use strict";var N=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var ne=(t,e)=>{for(var r in e)N(t,r,{get:e[r],enumerable:!0})},se=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of te(e))!re.call(t,s)&&s!==r&&N(t,s,{get:()=>e[s],enumerable:!(n=ee(e,s))||n.enumerable});return t};var ie=t=>se(N({},"__esModule",{value:!0}),t);var me={};ne(me,{GraphqlClient:()=>C,MetaCms:()=>W,buildQuery:()=>P,collectionFragment:()=>j,config:()=>oe,contentQuery:()=>L,fieldToMetafieldType:()=>H,getLoremCollectionData:()=>_,getLoremImageData:()=>$,getLoremProductData:()=>h,getMetaCMSConfigQuery:()=>ae,getOwnerIdQuery:()=>w,imageFragment:()=>M,isId:()=>I,mediaImageFragment:()=>E,metafieldFragment:()=>b,metafieldsForNodes:()=>q,metafieldsQuery:()=>R,mockValue:()=>z,mustaching:()=>Z,normalizeEdges:()=>m,productFragment:()=>v,randomId:()=>y,setInNamespace:()=>S,setMetaCMSConfigMutation:()=>F,syncConfig:()=>de,templating:()=>fe,traverse:()=>T,videoFragment:()=>O});module.exports=ie(me);var x=(t,e,r)=>{if(!t)return r?r():void 0;var n,s;if(Array.isArray(e)&&(n=e.slice(0)),typeof e=="string"&&(n=e.split(".")),typeof e=="symbol"&&(n=[e]),!Array.isArray(n))throw new Error("props arg must be an array, a string or a symbol");for(;n.length;)if(s=n.shift(),!t||(t=t[s],t===void 0))return r?r():void 0;return t};var B=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(s=>{e.push(s.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(s=>{e.push(s.id)})}))}),e};var F=`
mutation ($ownerId: ID!, $value: String!, $key: String!) {

@@ -9,3 +9,3 @@ metafieldsSet(metafields: [{ key: $key, namespace: "meta-cms", ownerId: $ownerId, value: $value, type: "json" }]) {

}
`,ie=`
`,ae=`
query {

@@ -47,3 +47,3 @@ shop {

}
`,b=(t,e)=>`
`,v=(t,e)=>`
id

@@ -113,3 +113,3 @@ descriptionHtml

}
`,L=(t,e)=>`
`,j=(t,e)=>`
id

@@ -125,3 +125,3 @@ title

node {
${b(t,e)}
${v(t,e)}
}

@@ -137,3 +137,3 @@ }

}
`:"",v=(t,e)=>`
`:"",b=(t,e)=>`
type

@@ -155,6 +155,6 @@ value

... on Collection {
${L(t,e)}
${j(t,e)}
}
... on Product {
${b(t,e)}
${v(t,e)}
}

@@ -179,3 +179,3 @@ ...on Video {

... on Collection {
${L(t,e)}
${j(t,e)}
}

@@ -185,6 +185,6 @@ }

... on Product {
${b(t,e)}
${v(t,e)}
}
}
`,R=(t,e)=>`
`,L=(t,e)=>`
query getContent(

@@ -197,11 +197,11 @@ $identifiers: [HasMetafieldsIdentifier!]!

content: metafields(identifiers: $identifiers) {
${v(t)}
${b(t)}
}
}
}
`,j=(t,e)=>`
`,R=(t,e)=>`
query getMetafields($ids: [ID!]!) {
metafields: nodes(ids: $ids ${e!=null&&e.customProductMetafields?"$customProductMetafields: [HasMetafieldsIdentifier!]! ":""}) {
... on Metafield {
${v(t,e)}
${b(t,e)}
}

@@ -222,3 +222,3 @@ }

content: metafields(identifiers: $productIdentifiers) {
${v(!1,r)}
${b(!1,r)}
}

@@ -234,3 +234,3 @@ }

content: metafields(identifiers: $collectionIdentifiers) {
${v(!1,r)}
${b(!1,r)}
}

@@ -241,3 +241,3 @@ }

}`;var m=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),oe=t=>t,y=()=>{let t="meta-cms-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",e="",r=10;for(;r--;)e+=t[Math.random()*t.length|0];return`meta-cms-${e}`},I=t=>typeof t=="string"?t.startsWith("gid://shopify/Metafield/"):!1,S=({content:t,namespace:e,key:r,id:n,value:s})=>{let c=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[c]:s})},P=({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,s,c)=>`id:${r(n)}${c.length-1>s?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,s,c)=>`handle:${n}${c.length-1>s?" or ":""}`).join("")}`.trim():void 0},T=(t,e,r=[])=>(Array.isArray(t)?t:Object.entries(t)).reduce((s,c,o)=>{if(Array.isArray(t))s.push(T(c,e,r.concat(o)));else{let[a,l]=c;Array.isArray(l)?(s[a]=[],l.forEach((f,i)=>s[a].push(T(f,e,r.concat(a).concat(i))))):l&&(l.attributes?s[a]=e(l,r.concat(a)):typeof l.value=="object"&&(s[a]=T(l,e,r.concat(a))))}return s},Array.isArray(t)?[]:{});var D=({acc:t,item:e,client:r,locale:n,jsonMetafields:s,nestedContent:c})=>{var f;let o={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},a,l=({id:i,key:d,namespace:u,objectId:p})=>{c&&t&&n&&S({content:t,key:d,id:p,namespace:u.replace(`@${n}`,""),value:c[i]})};switch(e.type){case"collection_reference":{a={attributes:o,value:{...e.collection,products:m(e.collection.products).map(({content:i,...d})=>(i==null||i.forEach(u=>l({...u,objectId:d.id})),{...d,variants:m(d.variants)}))}};break}case"file_reference":{if(!(e!=null&&e.video)&&!(e!=null&&e.image))return{attributes:o};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"),a={attributes:o,value:e.image.image};break}if("video"in e){a={attributes:o,value:e.video};break}}case"product_reference":{let{product:i}=e;(f=i.content)==null||f.forEach(d=>l({...d,objectId:i.id})),a={attributes:o,value:{...i,variants:m(e.product.variants)}};break}case"list.collection_reference":{a={attributes:o,value:m(e.values).map(i=>{var d;return(d=i.content)==null||d.forEach(u=>l({...u,objectId:i.id})),{...i,products:m(i.products).map(u=>{var p;return(p=u.content)==null||p.forEach(g=>l({...g,objectId:u.id})),{...u,variants:m(u.variants)}})}})};break}case"list.file_reference":{a={attributes:o,value:m(e.values).map(i=>i.image)};break}case"list.product_reference":{a={attributes:o,value:m(e.values).map(i=>{var d;return(d=i.content)==null||d.forEach(u=>l({...u,objectId:i.id})),{...i,variants:m(i.variants)}})};break}case"json":{let i=JSON.parse(e.value);if(x(r.config,`${e.namespace.split("@")[0]}.schema.${e.key}.type`)==="address")a={attributes:o,value:i};else{let u=K(e.value,s);a={attributes:o,value:u.value||u}}break}case"list.multi_line_text_field":case"list.single_line_text_field":{a={attributes:o,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{a={attributes:o,value:e.value||""};break}case"boolean":{a={attributes:o,value:e.value==="true"};break}case"number_decimal":{a={attributes:o,value:Number(e.value)};break}case"list.number_decimal":{a={attributes:o,value:JSON.parse(e.value,(i,d)=>Number(d))};break}case"url":{a={attributes:o,value:e.value};break}}return a},V=({client:t,id:e,initalizer:r,content:n,jsonMetafields:s,nestedContent:c})=>{var a,l;let o=r||{};for(let f=0;f<n.length;f++){let i=n[f];if(i){if(!((l=(a=t.config[i.namespace.replace(`@${t.locale}`,"")])==null?void 0:a.schema)==null?void 0:l[i.key]))return o;let u=D({client:t,acc:o,item:i,jsonMetafields:s,nestedContent:c});S({content:o,key:i.key,namespace:i.namespace.replace(`@${t.locale}`,""),value:u})}}return o};var ce=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(s=>{I(s)&&e.push(s)}):I(n)&&e.push(n),n)),e},J=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(ce(r.value)))}),e},k=(t,e)=>t.reduce((r,n)=>{if(n){let s=D({item:n,client:e});r[n.id]=e.adapter(s)}return r},{}),K=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(s=>I(s)?e[s]:s):I(n)?e[n]:n):JSON.parse(t);var H=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"}[t.type];return t.isList&&r!=="json"?`list.${r}`:r},$=(t=400,e=300)=>({alt:"image",src:`https://picsum.photos/${t}/${e}`,width:t,height:e}),h=()=>({id:y(),descriptionHtml:"Lorem ipsum",title:"Lorem ipsum",handle:"",featuredImage:$(),compareAtPriceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},priceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},variants:[]}),_=()=>({id:y(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:$(),products:[h(),h(),h()]}),Q=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r},le=t=>{if(t==="text"||t==="richtext")return"Lorem ipsum";if(t==="image")return $();if(t==="product")return h();if(t==="collection")return _()},G=(t,e=!0)=>Object.entries(t.schema).reduce((r,[n,s])=>(s.isList?s.type==="object"?r[n]=G(s,!1):r[n]=[]:s.type==="object"?r[n]=G(s,!1):r[n]=le(s.type),r),t.type==="object"&&e?{}:t.isList?[]:{}),z=(t,e,r=!0)=>{switch(t.type){case"object":return t.isList?{attributes:e,value:[]}:{attributes:e,value:G(t)};case"collection":return{attributes:e,value:t.isList?Q(_):_()};case"image":return{value:t.isList?r?Q($):[]:r?{id:y(),...$()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?Q(h):h()};case"richtext":return{attributes:e,value:t.isList?["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:`<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:!0};case"url":return{attributes:e,value:"https://google.com"};case"list":return{attributes:e,value:t.options[0].value};case"number":return{attributes:e,value:Math.random()};default:case"text":return{attributes:e,value:t.isList?["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:"Lorem ipsum dolor sit amet consectetur adipisicing elit."}}};var C=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:s}=await n.json();return s}else throw new Error(await n.text())};this.url=e,this.headers=r}},W=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:s},c){this.getMetafieldsByIds=async e=>{var s,c;if(!e.length)return[{},[]];let r=await this.client.request(j(!1,{customProductMetafields:(c=(s=this.params)==null?void 0:s.product)==null?void 0:c.customMetafieldsIdentifiers}),{ids:e});if(!r)return[{},[]];let{metafields:n}=r;return[k(n,this),n]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:r,locale:n})=>{var p,g;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 s=await this.client.request(q({collectionQuery:P({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:P({ids:r==null?void 0:r.ids,handles:r==null?void 0:r.handles})},{customProductMetafields:(g=(p=this.params)==null?void 0:p.product)==null?void 0:g.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers((r==null?void 0:r.namespaces)||[],n),collectionIdentifiers:this.buildIdentifiers((e==null?void 0:e.namespaces)||[],n)});if(!s)return[{},[],[]];let{products:c,collections:o}=s,a=c?m(c):[],l=o?m(o):[],f=a.map(A=>A.content).flat(),i=l.map(A=>A.content).flat(),d=k(f,this),u=k(i,this);return[{...d,...u},f.concat(i),a.concat(l)]};this.getContentForNamespaces=async e=>{var i,d,u;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(R(!0,{customProductMetafields:(i=e.product)==null?void 0:i.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((d=e.product)==null?void 0:d.namespaces)||[],e.locale),collectionIdentifiers:this.buildIdentifiers(((u=e.collection)==null?void 0:u.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)});console.log({content:r});let[[n,s],[c,o,a]]=await Promise.all([this.getMetafieldsByIds(B(r)),this.getMetafieldsForProductsAndCollection(e)]),[l]=await this.getMetafieldsByIds(J(r.concat(s).concat(o)));console.log({jsonMetafields:l},J(r));let f=V({client:this,content:r,jsonMetafields:l,nestedContent:{...n,...c}});return a.forEach(({id:p,content:g})=>{V({client:this,initalizer:f,id:p,content:g,jsonMetafields:l,nestedContent:{...n,...c}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:f}};this.t=(e,r,{productId:n,collectionId:s},c)=>{let[o,a]=e.split("."),{kind:l,schema:f}=this.config[o];n&&l==="product"&&(a=`${a}@${n}`),s&&l==="collection"&&(a=`${a}@${s}`);let i=f[a],d=()=>x(this.config[o],`${a}.default`,()=>{let u=H(i),p={itemID:y(),itemType:u,itemProp:`${o}:${a}`},g=z(i,p);return c?c(g,i):g});return x(r,`${o}.${a}`,d)};this.buildIdentifiers=(e,r)=>e?e.reduce((n,s)=>{let c=this.config[s];return c&&Object.keys(c.schema).forEach(o=>{n.push({namespace:`${s}@${r}`,key:o})}),n},[]):[];this.locale="en",this.adapter=c||(o=>o),this.config=e,this.defaultNameSpaces=s||[],this.client=new C(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var de=async(t,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:n},s)=>{console.log(s);let c=new C(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}),o=new C(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":n}),{shop:{id:a}}=await c.request(w);return await o.request(F,{value:JSON.stringify(t),key:s,ownerId:a})};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,ue=(t,e)=>{if(!e)return t;let r=t.matchAll(Y);return Array.from(r).forEach(n=>{let[s]=n,[c,o,a]=s.replace("((","").replace("))","").split(","),l=typeof e[c]=="number"?e[c]>1:!!e[c];a?l===!0?t=t.replace(s,a.trim()):t=t.replace(s,o.trim()):l===!0?(a=o,t=t.replace(s,a.trim())):t=t.replace(Y,"")}),t},fe=(t,e)=>ue(Z(t,e),e);0&&(module.exports={GraphqlClient,MetaCms,buildQuery,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),[]),oe=t=>t,y=()=>{let t="meta-cms-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",e="",r=10;for(;r--;)e+=t[Math.random()*t.length|0];return`meta-cms-${e}`},I=t=>typeof t=="string"?t.startsWith("gid://shopify/Metafield/"):!1,S=({content:t,namespace:e,key:r,id:n,value:s})=>{let c=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[c]:s})},P=({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,s,c)=>`id:${r(n)}${c.length-1>s?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,s,c)=>`handle:${n}${c.length-1>s?" or ":""}`).join("")}`.trim():void 0},T=(t,e,r=[])=>typeof t!="object"?t:(Array.isArray(t)?t:Object.entries(t)).reduce((s,c,o)=>{if(Array.isArray(t))s.push(T(c,e,r.concat(o)));else{let[i,l]=c;Array.isArray(l)?(s[i]=[],l.forEach((f,a)=>s[i].push(T(f,e,r.concat(i).concat(a))))):l&&(l.attributes?s[i]=e(l,r.concat(i)):typeof l.value=="object"&&(s[i]=T(l,e,r.concat(i))))}return s},Array.isArray(t)?[]:{});var D=({acc:t,item:e,client:r,locale:n,jsonMetafields:s,nestedContent:c})=>{var f;let o={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},i,l=({id:a,key:d,namespace:u,objectId:p})=>{c&&t&&n&&S({content:t,key:d,id:p,namespace:u.replace(`@${n}`,""),value:c[a]})};switch(e.type){case"collection_reference":{i={attributes:o,value:{...e.collection,products:m(e.collection.products).map(({content:a,...d})=>(a==null||a.forEach(u=>l({...u,objectId:d.id})),{...d,variants:m(d.variants)}))}};break}case"file_reference":{if(!(e!=null&&e.video)&&!(e!=null&&e.image))return{attributes:o};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"),i={attributes:o,value:e.image.image};break}if("video"in e){i={attributes:o,value:e.video};break}}case"product_reference":{let{product:a}=e;(f=a.content)==null||f.forEach(d=>l({...d,objectId:a.id})),i={attributes:o,value:{...a,variants:m(e.product.variants)}};break}case"list.collection_reference":{i={attributes:o,value:m(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(u=>l({...u,objectId:a.id})),{...a,products:m(a.products).map(u=>{var p;return(p=u.content)==null||p.forEach(g=>l({...g,objectId:u.id})),{...u,variants:m(u.variants)}})}})};break}case"list.file_reference":{i={attributes:o,value:m(e.values).map(a=>a.image)};break}case"list.product_reference":{i={attributes:o,value:m(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(u=>l({...u,objectId:a.id})),{...a,variants:m(a.variants)}})};break}case"json":{let a=JSON.parse(e.value);if(x(r.config,`${e.namespace.split("@")[0]}.schema.${e.key}.type`)==="address")i={attributes:o,value:a};else{let u=K(e.value,s);i={attributes:o,value:u.value||u}}break}case"list.multi_line_text_field":case"list.single_line_text_field":{i={attributes:o,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{i={attributes:o,value:e.value||""};break}case"boolean":{i={attributes:o,value:e.value==="true"};break}case"number_decimal":{i={attributes:o,value:Number(e.value)};break}case"list.number_decimal":{i={attributes:o,value:JSON.parse(e.value,(a,d)=>Number(d))};break}case"url":{i={attributes:o,value:e.value};break}}return i},V=({client:t,id:e,initalizer:r,content:n,jsonMetafields:s,nestedContent:c})=>{var i,l;let o=r||{};for(let f=0;f<n.length;f++){let a=n[f];if(a){if(!((l=(i=t.config[a.namespace.replace(`@${t.locale}`,"")])==null?void 0:i.schema)==null?void 0:l[a.key]))return o;let u=D({client:t,acc:o,item:a,jsonMetafields:s,nestedContent:c});S({content:o,key:a.key,namespace:a.namespace.replace(`@${t.locale}`,""),value:u})}}return o};var ce=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(s=>{I(s)&&e.push(s)}):I(n)&&e.push(n),n)),e},J=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(ce(r.value)))}),e},k=(t,e)=>t.reduce((r,n)=>{if(n){let s=D({item:n,client:e});r[n.id]=e.adapter(s)}return r},{}),K=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(s=>I(s)?e[s]:s):I(n)?e[n]:n):JSON.parse(t);var H=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"}[t.type];return t.isList&&r!=="json"?`list.${r}`:r},$=(t=400,e=300)=>({alt:"image",src:`https://picsum.photos/${t}/${e}`,width:t,height:e}),h=()=>({id:y(),descriptionHtml:"Lorem ipsum",title:"Lorem ipsum",handle:"",featuredImage:$(),compareAtPriceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},priceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},variants:[]}),_=()=>({id:y(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:$(),products:[h(),h(),h()]}),Q=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r},le=t=>{if(t==="text"||t==="richtext")return"Lorem ipsum";if(t==="image")return $();if(t==="product")return h();if(t==="collection")return _()},G=(t,e=!0)=>Object.entries(t.schema).reduce((r,[n,s])=>(s.isList?s.type==="object"?r[n]=G(s,!1):r[n]=[]:s.type==="object"?r[n]=G(s,!1):r[n]=le(s.type),r),t.type==="object"&&e?{}:t.isList?[]:{}),z=(t,e,r=!0)=>{switch(t.type){case"object":return t.isList?{attributes:e,value:[]}:{attributes:e,value:G(t)};case"collection":return{attributes:e,value:t.isList?Q(_):_()};case"image":return{value:t.isList?r?Q($):[]:r?{id:y(),...$()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?Q(h):h()};case"richtext":return{attributes:e,value:t.isList?["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:`<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:!0};case"url":return{attributes:e,value:"https://google.com"};case"list":return{attributes:e,value:t.options[0].value};case"number":return{attributes:e,value:Math.random()};default:case"text":return{attributes:e,value:t.isList?["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:"Lorem ipsum dolor sit amet consectetur adipisicing elit."}}};var C=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:s}=await n.json();return s}else throw new Error(await n.text())};this.url=e,this.headers=r}},W=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:s},c){this.getMetafieldsByIds=async e=>{var s,c;if(!e.length)return[{},[]];let r=await this.client.request(R(!1,{customProductMetafields:(c=(s=this.params)==null?void 0:s.product)==null?void 0:c.customMetafieldsIdentifiers}),{ids:e});if(!r)return[{},[]];let{metafields:n}=r;return[k(n,this),n]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:r,locale:n})=>{var p,g;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 s=await this.client.request(q({collectionQuery:P({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:P({ids:r==null?void 0:r.ids,handles:r==null?void 0:r.handles})},{customProductMetafields:(g=(p=this.params)==null?void 0:p.product)==null?void 0:g.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers((r==null?void 0:r.namespaces)||[],n),collectionIdentifiers:this.buildIdentifiers((e==null?void 0:e.namespaces)||[],n)});if(!s)return[{},[],[]];let{products:c,collections:o}=s,i=c?m(c):[],l=o?m(o):[],f=i.map(A=>A.content).flat(),a=l.map(A=>A.content).flat(),d=k(f,this),u=k(a,this);return[{...d,...u},f.concat(a),i.concat(l)]};this.getContentForNamespaces=async e=>{var a,d,u;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(L(!0,{customProductMetafields:(a=e.product)==null?void 0:a.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((d=e.product)==null?void 0:d.namespaces)||[],e.locale),collectionIdentifiers:this.buildIdentifiers(((u=e.collection)==null?void 0:u.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)});console.log({content:r});let[[n,s],[c,o,i]]=await Promise.all([this.getMetafieldsByIds(B(r)),this.getMetafieldsForProductsAndCollection(e)]),[l]=await this.getMetafieldsByIds(J(r.concat(s).concat(o)));console.log({jsonMetafields:l},J(r));let f=V({client:this,content:r,jsonMetafields:l,nestedContent:{...n,...c}});return i.forEach(({id:p,content:g})=>{V({client:this,initalizer:f,id:p,content:g,jsonMetafields:l,nestedContent:{...n,...c}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:f}};this.t=(e,r,{productId:n,collectionId:s},c)=>{let[o,i]=e.split("."),{kind:l,schema:f}=this.config[o];n&&l==="product"&&(i=`${i}@${n}`),s&&l==="collection"&&(i=`${i}@${s}`);let a=f[i],d=()=>x(this.config[o],`${i}.default`,()=>{let u=H(a),p={itemID:y(),itemType:u,itemProp:`${o}:${i}`},g=z(a,p);return c?c(g,a):g});return x(r,`${o}.${i}`,d)};this.buildIdentifiers=(e,r)=>e?e.reduce((n,s)=>{let c=this.config[s];return c&&Object.keys(c.schema).forEach(o=>{n.push({namespace:`${s}@${r}`,key:o})}),n},[]):[];this.locale="en",this.adapter=c||(o=>o),this.config=e,this.defaultNameSpaces=s||[],this.client=new C(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var de=async(t,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:n},s)=>{console.log(s);let c=new C(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}),o=new C(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":n}),{shop:{id:i}}=await c.request(w);return await o.request(F,{value:JSON.stringify(t),key:s,ownerId:i})};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,ue=(t,e)=>{if(!e)return t;let r=t.matchAll(Y);return Array.from(r).forEach(n=>{let[s]=n,[c,o,i]=s.replace("((","").replace("))","").split(","),l=typeof e[c]=="number"?e[c]>1:!!e[c];i?l===!0?t=t.replace(s,i.trim()):t=t.replace(s,o.trim()):l===!0?(i=o,t=t.replace(s,i.trim())):t=t.replace(Y,"")}),t},fe=(t,e)=>ue(Z(t,e),e);0&&(module.exports={GraphqlClient,MetaCms,buildQuery,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.66",
"version": "1.0.67",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc