New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.79 to 1.0.80

52

index.js

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

"use strict";var F=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var re=(t,e)=>{for(var r in e)F(t,r,{get:e[r],enumerable:!0})},ne=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ee(e))!te.call(t,s)&&s!==r&&F(t,s,{get:()=>e[s],enumerable:!(n=Z(e,s))||n.enumerable});return t};var se=t=>ne(F({},"__esModule",{value:!0}),t);var fe={};re(fe,{GraphqlClient:()=>h,MetaCms:()=>z,buildQuery:()=>T,collectionFragment:()=>E,config:()=>ie,contentQuery:()=>L,fieldToMetafieldType:()=>Q,getLoremCollectionData:()=>k,getLoremImageData:()=>I,getLoremProductData:()=>y,getMetaCMSConfigQuery:()=>ae,getOwnerIdQuery:()=>N,imageFragment:()=>$,isId:()=>x,mediaImageFragment:()=>w,metafieldFragment:()=>b,metafieldsForNodes:()=>R,metafieldsQuery:()=>O,mockValue:()=>H,mustaching:()=>Y,normalizeEdges:()=>m,productFragment:()=>M,randomId:()=>g,setInNamespace:()=>S,setMetaCMSConfigMutation:()=>A,syncConfig:()=>le,templating:()=>ue,traverse:()=>v,videoFragment:()=>j});module.exports=se(fe);var W=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 A=`
"use strict";var A=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var re=(t,e)=>{for(var r in e)A(t,r,{get:e[r],enumerable:!0})},ne=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ee(e))!te.call(t,s)&&s!==r&&A(t,s,{get:()=>e[s],enumerable:!(n=Z(e,s))||n.enumerable});return t};var se=t=>ne(A({},"__esModule",{value:!0}),t);var ue={};re(ue,{GraphqlClient:()=>y,MetaCms:()=>z,buildQuery:()=>T,collectionFragment:()=>L,config:()=>ae,contentQuery:()=>O,fieldToMetafieldType:()=>k,getLoremCollectionData:()=>Q,getLoremImageData:()=>b,getLoremProductData:()=>x,getMetaCMSConfigQuery:()=>ie,getOwnerIdQuery:()=>w,imageFragment:()=>I,isId:()=>C,mediaImageFragment:()=>j,metafieldFragment:()=>$,metafieldsForNodes:()=>R,metafieldsQuery:()=>D,mockValue:()=>_,mustaching:()=>Y,normalizeEdges:()=>m,productFragment:()=>M,randomId:()=>g,setInNamespace:()=>S,setMetaCMSConfigMutation:()=>N,syncConfig:()=>ce,templating:()=>de,traverse:()=>v,videoFragment:()=>E});module.exports=se(ue);var W=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 N=`
mutation ($ownerId: ID!, $value: String!, $key: String!) {

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

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

@@ -19,3 +19,3 @@ shop {

}
`;var N=`
`;var w=`
query getOwnerId {

@@ -26,8 +26,8 @@ shop {

}
`;var w=t=>`
`;var j=t=>`
id
image {
${$(t)}
${I(t)}
}
`,$=t=>`
`,I=t=>`
alt: altText

@@ -37,3 +37,3 @@ height

src: url(transform:{maxWidth:4000})
`,j=t=>`
`,E=t=>`
id

@@ -67,3 +67,3 @@ alt

image {
${$(!1)}
${I(!1)}
}

@@ -94,3 +94,3 @@ price {

featuredImage {
${$(!1)}
${I(!1)}
}

@@ -117,3 +117,3 @@ compareAtPriceRange {

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

@@ -124,3 +124,3 @@ title

image {
${$(t)}
${I(t)}
}

@@ -141,3 +141,3 @@ products(first: 20) {

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

@@ -156,6 +156,6 @@ value

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

@@ -166,3 +166,3 @@ ... on Product {

...on Video {
${j(t)}
${E(t)}
}

@@ -174,3 +174,3 @@ }

... on MediaImage {
${w(t)}
${j(t)}
}

@@ -180,3 +180,3 @@ }

...on Video {
${j(t)}
${E(t)}
}

@@ -186,3 +186,3 @@ }

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

@@ -195,3 +195,3 @@ }

}
`,L=(t,e)=>`
`,O=(t,e)=>`
query getContent(

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

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

@@ -229,3 +229,3 @@ }

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

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

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

@@ -248,3 +248,3 @@ }

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