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.58 to 1.0.59

6

index.js

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

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

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

}`;var u=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),ie=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,v=({content:t,namespace:e,key:r,id:n,value:i})=>{let s=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[s]:i})},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,i,s)=>`id:${r(n)}${s.length-1>i?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,i,s)=>`handle:${n}${s.length-1>i?" or ":""}`).join("")}`.trim():void 0},S=(t,e,r=[])=>(console.log({data:t}),(Array.isArray(t)?t:Object.entries(t)).reduce((i,s,o)=>{if(Array.isArray(t))i.push(S(s,e,r.concat(o)));else{let[c,l]=s;Array.isArray(l)?(i[c]=[],l.forEach((a,d)=>i[c].push(S(a,e,r.concat(c).concat(d))))):l&&(l.attributes?i[c]=e(l,r.concat(c)):i[c]=S(l,e,r.concat(c)))}return i},Array.isArray(t)?[]:{}));var D=({acc:t,item:e,locale:r,jsonMetafields:n,nestedContent:i})=>{var l;let s={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},o,c=({id:a,key:d,namespace:f,objectId:m})=>{i&&t&&r&&v({content:t,key:d,id:m,namespace:f.replace(`@${r}`,""),value:i[a]})};switch(e.type){case"collection_reference":{o={attributes:s,value:{...e.collection,products:u(e.collection.products).map(({content:a,...d})=>(a==null||a.forEach(f=>c({...f,objectId:d.id})),{...d,variants:u(d.variants)}))}};break}case"file_reference":{if(!(e!=null&&e.video)&&!e.image)return{attributes:s};"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:s,value:e.image.image}),"video"in e&&(o={attributes:s,value:e.video});break}case"product_reference":{let{product:a}=e;(l=a.content)==null||l.forEach(d=>c({...d,objectId:a.id})),o={attributes:s,value:{...a,variants:u(e.product.variants)}};break}case"list.collection_reference":{o={attributes:s,value:u(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(f=>c({...f,objectId:a.id})),{...a,products:u(a.products).map(f=>{var m;return(m=f.content)==null||m.forEach(p=>c({...p,objectId:f.id})),{...f,variants:u(f.variants)}})}})};break}case"list.file_reference":{o={attributes:s,value:u(e.values).map(a=>a.image)};break}case"list.product_reference":{o={attributes:s,value:u(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(f=>c({...f,objectId:a.id})),{...a,variants:u(a.variants)}})};break}case"json":{let a=K(e.value,n);o={attributes:s,value:a.value||a};break}case"list.multi_line_text_field":case"list.single_line_text_field":{o={attributes:s,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{o={attributes:s,value:e.value||""};break}case"boolean":{o={attributes:s,value:e.value==="true"};break}case"url":{o={attributes:s,value:e.value||""};break}}return o},Q=({client:t,id:e,initalizer:r,content:n,jsonMetafields:i,nestedContent:s})=>{var c,l;let o=r||{};for(let a=0;a<n.length;a++){let d=n[a];if(d){if(!((l=(c=t.config[d.namespace.replace(`@${t.locale}`,"")])==null?void 0:c.schema)==null?void 0:l[d.key]))return o;let m=D({client:t,acc:o,item:d,jsonMetafields:i,nestedContent:s});v({content:o,key:d.key,namespace:d.namespace.replace(`@${t.locale}`,""),value:m})}}return o};var se=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(i=>{I(i)&&e.push(i)}):I(n)&&e.push(n),n)),e},V=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(se(r.value)))}),e},b=(t,e)=>t.reduce((r,n)=>{if(n){let i=D({item:n,client:e});r[n.id]=e.adapter(i)}return r},{}),K=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(i=>I(i)?e[i]:i):I(n)?e[n]:n):JSON.parse(t);var H=t=>{let r={text:"single_line_text_field",richtext:"multi_line_text_field",image:"file_reference",product:"product_reference",collection:"collection_reference",object:"json",boolean:"boolean",url:"url",video:"file_reference"}[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:[]}),k=()=>({id:y(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:$(),products:[h(),h(),h()]}),J=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r},ae=t=>{if(t==="text"||t==="richtext")return"Lorem ipsum";if(t==="image")return $();if(t==="product")return h();if(t==="collection")return k()},G=(t,e=!0)=>Object.entries(t.schema).reduce((r,[n,i])=>(i.isList?i.type==="object"?r[n]=G(i,!1):r[n]=[]:i.type==="object"?r[n]=G(i,!1):r[n]=ae(i.type),r),t.type==="object"&&e?{}:t.isList?[]:{}),W=(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?J(k):k()};case"image":return{value:t.isList?r?J($):[]:r?{id:y(),...$()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?J(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"};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:i}=await n.json();return i}else throw new Error(await n.text())};this.url=e,this.headers=r}},z=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:i},s){this.getMetafieldsByIds=async e=>{var i,s;if(!e.length)return[{},[]];let r=await this.client.request(O(!1,{customProductMetafields:(s=(i=this.params)==null?void 0:i.product)==null?void 0:s.customMetafieldsIdentifiers}),{ids:e});if(!r)return[{},[]];let{metafields:n}=r;return[b(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 i=await this.client.request(j({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(!i)return[{},[],[]];let{products:s,collections:o}=i,c=s?u(s):[],l=o?u(o):[],a=c.map(A=>A.content).flat(),d=l.map(A=>A.content).flat(),f=b(a,this),m=b(d,this);return[{...f,...m},a.concat(d),c.concat(l)]};this.getContentForNamespaces=async e=>{var d,f,m;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(q(!0,{customProductMetafields:(d=e.product)==null?void 0:d.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((f=e.product)==null?void 0:f.namespaces)||[],e.locale),collectionIdentifiers:this.buildIdentifiers(((m=e.collection)==null?void 0:m.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)});console.log({content:r});let[[n,i],[s,o,c]]=await Promise.all([this.getMetafieldsByIds(B(r)),this.getMetafieldsForProductsAndCollection(e)]),[l]=await this.getMetafieldsByIds(V(r.concat(i).concat(o)));console.log({jsonMetafields:l},V(r));let a=Q({client:this,content:r,jsonMetafields:l,nestedContent:{...n,...s}});return c.forEach(({id:p,content:g})=>{Q({client:this,initalizer:a,id:p,content:g,jsonMetafields:l,nestedContent:{...n,...s}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:a}};this.t=(e,r,{productId:n,collectionId:i},s)=>{let[o,c]=e.split("."),{kind:l,schema:a}=this.config[o];n&&l==="product"&&(c=`${c}@${n}`),i&&l==="collection"&&(c=`${c}@${i}`);let d=a[c],f=()=>N(this.config[o],`${c}.default`,()=>{let m=H(d),p={itemID:y(),itemType:m,itemProp:`${o}:${c}`},g=W(d,p);return s?s(g,d):g});return N(r,`${o}.${c}`,f)};this.buildIdentifiers=(e,r)=>e?e.reduce((n,i)=>{let s=this.config[i];return s&&Object.keys(s.schema).forEach(o=>{n.push({namespace:`${i}@${r}`,key:o})}),n},[]):[];this.locale="en",this.adapter=s||(o=>o),this.config=e,this.defaultNameSpaces=i||[],this.client=new C(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var oe=async(t,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:n},i)=>{console.log(i);let s=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:c}}=await s.request(w);return await o.request(_,{value:JSON.stringify(t),key:i,ownerId:c})};0&&(module.exports={GraphqlClient,MetaCms,buildQuery,collectionFragment,config,contentQuery,fieldToMetafieldType,getLoremCollectionData,getLoremImageData,getLoremProductData,getMetaCMSConfigQuery,getOwnerIdQuery,imageFragment,isId,mediaImageFragment,metafieldFragment,metafieldsForNodes,metafieldsQuery,mockValue,normalizeEdges,productFragment,randomId,setInNamespace,setMetaCMSConfigMutation,syncConfig,traverse,videoFragment});
}`;var u=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),ie=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,P=({content:t,namespace:e,key:r,id:n,value:i})=>{let s=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[s]:i})},b=({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,s)=>`id:${r(n)}${s.length-1>i?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,i,s)=>`handle:${n}${s.length-1>i?" or ":""}`).join("")}`.trim():void 0},S=(t,e,r=[])=>(console.log({data:t}),(Array.isArray(t)?t:Object.entries(t)).reduce((i,s,o)=>{if(Array.isArray(t))i.push(S(s,e,r.concat(o)));else{let[c,l]=s;Array.isArray(l)?(i[c]=[],l.forEach((a,d)=>i[c].push(S(a,e,r.concat(c).concat(d))))):l&&(l.attributes?i[c]=e(l,r.concat(c)):i[c]=S(l,e,r.concat(c)))}return i},Array.isArray(t)?[]:{}));var D=({acc:t,item:e,locale:r,jsonMetafields:n,nestedContent:i})=>{var l;let s={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},o,c=({id:a,key:d,namespace:f,objectId:m})=>{i&&t&&r&&P({content:t,key:d,id:m,namespace:f.replace(`@${r}`,""),value:i[a]})};switch(e.type){case"collection_reference":{o={attributes:s,value:{...e.collection,products:u(e.collection.products).map(({content:a,...d})=>(a==null||a.forEach(f=>c({...f,objectId:d.id})),{...d,variants:u(d.variants)}))}};break}case"file_reference":{if(!(e!=null&&e.video)&&!(e!=null&&e.image))return{attributes:s};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:s,value:e.image.image};break}if("video"in e){o={attributes:s,value:e.video};break}}case"product_reference":{let{product:a}=e;(l=a.content)==null||l.forEach(d=>c({...d,objectId:a.id})),o={attributes:s,value:{...a,variants:u(e.product.variants)}};break}case"list.collection_reference":{o={attributes:s,value:u(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(f=>c({...f,objectId:a.id})),{...a,products:u(a.products).map(f=>{var m;return(m=f.content)==null||m.forEach(p=>c({...p,objectId:f.id})),{...f,variants:u(f.variants)}})}})};break}case"list.file_reference":{o={attributes:s,value:u(e.values).map(a=>a.image)};break}case"list.product_reference":{o={attributes:s,value:u(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(f=>c({...f,objectId:a.id})),{...a,variants:u(a.variants)}})};break}case"json":{let a=K(e.value,n);o={attributes:s,value:a.value||a};break}case"list.multi_line_text_field":case"list.single_line_text_field":{o={attributes:s,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{o={attributes:s,value:e.value||""};break}case"boolean":{o={attributes:s,value:e.value==="true"};break}case"url":{o={attributes:s,value:e.value||""};break}}return o},Q=({client:t,id:e,initalizer:r,content:n,jsonMetafields:i,nestedContent:s})=>{var c,l;let o=r||{};for(let a=0;a<n.length;a++){let d=n[a];if(d){if(!((l=(c=t.config[d.namespace.replace(`@${t.locale}`,"")])==null?void 0:c.schema)==null?void 0:l[d.key]))return o;let m=D({client:t,acc:o,item:d,jsonMetafields:i,nestedContent:s});P({content:o,key:d.key,namespace:d.namespace.replace(`@${t.locale}`,""),value:m})}}return o};var se=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(i=>{I(i)&&e.push(i)}):I(n)&&e.push(n),n)),e},V=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(se(r.value)))}),e},v=(t,e)=>t.reduce((r,n)=>{if(n){let i=D({item:n,client:e});r[n.id]=e.adapter(i)}return r},{}),K=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(i=>I(i)?e[i]:i):I(n)?e[n]:n):JSON.parse(t);var H=t=>{let r={text:"single_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:"url"}[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:[]}),k=()=>({id:y(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:$(),products:[h(),h(),h()]}),J=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r},ae=t=>{if(t==="text"||t==="richtext")return"Lorem ipsum";if(t==="image")return $();if(t==="product")return h();if(t==="collection")return k()},G=(t,e=!0)=>Object.entries(t.schema).reduce((r,[n,i])=>(i.isList?i.type==="object"?r[n]=G(i,!1):r[n]=[]:i.type==="object"?r[n]=G(i,!1):r[n]=ae(i.type),r),t.type==="object"&&e?{}:t.isList?[]:{}),W=(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?J(k):k()};case"image":return{value:t.isList?r?J($):[]:r?{id:y(),...$()}:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?J(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"};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:i}=await n.json();return i}else throw new Error(await n.text())};this.url=e,this.headers=r}},z=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:i},s){this.getMetafieldsByIds=async e=>{var i,s;if(!e.length)return[{},[]];let r=await this.client.request(O(!1,{customProductMetafields:(s=(i=this.params)==null?void 0:i.product)==null?void 0:s.customMetafieldsIdentifiers}),{ids:e});if(!r)return[{},[]];let{metafields:n}=r;return[v(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 i=await this.client.request(j({collectionQuery:b({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:b({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(!i)return[{},[],[]];let{products:s,collections:o}=i,c=s?u(s):[],l=o?u(o):[],a=c.map(A=>A.content).flat(),d=l.map(A=>A.content).flat(),f=v(a,this),m=v(d,this);return[{...f,...m},a.concat(d),c.concat(l)]};this.getContentForNamespaces=async e=>{var d,f,m;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(q(!0,{customProductMetafields:(d=e.product)==null?void 0:d.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((f=e.product)==null?void 0:f.namespaces)||[],e.locale),collectionIdentifiers:this.buildIdentifiers(((m=e.collection)==null?void 0:m.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)});console.log({content:r});let[[n,i],[s,o,c]]=await Promise.all([this.getMetafieldsByIds(B(r)),this.getMetafieldsForProductsAndCollection(e)]),[l]=await this.getMetafieldsByIds(V(r.concat(i).concat(o)));console.log({jsonMetafields:l},V(r));let a=Q({client:this,content:r,jsonMetafields:l,nestedContent:{...n,...s}});return c.forEach(({id:p,content:g})=>{Q({client:this,initalizer:a,id:p,content:g,jsonMetafields:l,nestedContent:{...n,...s}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:a}};this.t=(e,r,{productId:n,collectionId:i},s)=>{let[o,c]=e.split("."),{kind:l,schema:a}=this.config[o];n&&l==="product"&&(c=`${c}@${n}`),i&&l==="collection"&&(c=`${c}@${i}`);let d=a[c],f=()=>N(this.config[o],`${c}.default`,()=>{let m=H(d),p={itemID:y(),itemType:m,itemProp:`${o}:${c}`},g=W(d,p);return s?s(g,d):g});return N(r,`${o}.${c}`,f)};this.buildIdentifiers=(e,r)=>e?e.reduce((n,i)=>{let s=this.config[i];return s&&Object.keys(s.schema).forEach(o=>{n.push({namespace:`${i}@${r}`,key:o})}),n},[]):[];this.locale="en",this.adapter=s||(o=>o),this.config=e,this.defaultNameSpaces=i||[],this.client=new C(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var oe=async(t,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:n},i)=>{console.log(i);let s=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:c}}=await s.request(w);return await o.request(_,{value:JSON.stringify(t),key:i,ownerId:c})};0&&(module.exports={GraphqlClient,MetaCms,buildQuery,collectionFragment,config,contentQuery,fieldToMetafieldType,getLoremCollectionData,getLoremImageData,getLoremProductData,getMetaCMSConfigQuery,getOwnerIdQuery,imageFragment,isId,mediaImageFragment,metafieldFragment,metafieldsForNodes,metafieldsQuery,mockValue,normalizeEdges,productFragment,randomId,setInNamespace,setMetaCMSConfigMutation,syncConfig,traverse,videoFragment});
{
"name": "@meta-cms/core",
"version": "1.0.58",
"version": "1.0.59",
"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