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.50 to 1.0.51

8

index.d.ts

@@ -411,2 +411,8 @@ import { Get } from 'type-fest';

export { Adapter, CollectionContent, CollectionData, CollectionsContent, ConfigType, Content, Field, GetConfigType, GetContentParams, GetField, GetType2, GraphqlClient, HTMLContent, HTMLsContent, IdAccessors, Identifier, ImageContent, ImageData, ImagesContent, ItemAttributes, Last, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, Model, ModelKind, ModelSchema, Namespaces, NestedContent, Nodes, ObjectContent2, ObjectField, ObjectSchema, ObjectType, ParamsFetcher, PathForNamespace, Paths, Price, PriceContent, PriceVariation, PriceVariationContent, ProductContent, ProductData, ProductsContent, RequireExactlyOne, Schema, Simplify, Split, TextContent, TextsContent, VariantContent, WithEdge, buildQuery, collectionFragment, config, contentQuery, getMetaCMSConfigQuery, getOwnerIdQuery, imageFragment, isId, isList, mediaImageFragment, metafieldFragment, metafieldType, metafieldsForNodes, metafieldsQuery, normalizeEdges, productFragment, randomId, setInNamespace, setMetaCMSConfigMutation, simpleMetafieldType, syncConfig, toList, toList2 };
declare const fieldToMetafieldType: (field: Field) => metafieldType;
declare const getLoremImageData: (width?: number, height?: number) => ImageData;
declare const getLoremProductData: () => ProductData;
declare const getLoremCollectionData: () => CollectionData;
declare const mockValue: <F extends Field, T = GetType2<F>>(field: F, attributes: Partial<ItemAttributes>, fill?: Boolean) => T;
export { Adapter, CollectionContent, CollectionData, CollectionsContent, ConfigType, Content, Field, GetConfigType, GetContentParams, GetField, GetType2, GraphqlClient, HTMLContent, HTMLsContent, IdAccessors, Identifier, ImageContent, ImageData, ImagesContent, ItemAttributes, Last, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, Model, ModelKind, ModelSchema, Namespaces, NestedContent, Nodes, ObjectContent2, ObjectField, ObjectSchema, ObjectType, ParamsFetcher, PathForNamespace, Paths, Price, PriceContent, PriceVariation, PriceVariationContent, ProductContent, ProductData, ProductsContent, RequireExactlyOne, Schema, Simplify, Split, TextContent, TextsContent, VariantContent, WithEdge, buildQuery, collectionFragment, config, contentQuery, fieldToMetafieldType, getLoremCollectionData, getLoremImageData, getLoremProductData, getMetaCMSConfigQuery, getOwnerIdQuery, imageFragment, isId, isList, mediaImageFragment, metafieldFragment, metafieldType, metafieldsForNodes, metafieldsQuery, mockValue, normalizeEdges, productFragment, randomId, setInNamespace, setMetaCMSConfigMutation, simpleMetafieldType, syncConfig, toList, toList2 };

68

index.js

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

"use strict";var F=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(n,e)=>{for(var t in e)F(n,t,{get:e[t],enumerable:!0})},Z=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of K(e))!X.call(n,i)&&i!==t&&F(n,i,{get:()=>e[i],enumerable:!(r=B(e,i))||r.enumerable});return n};var ee=n=>Z(F({},"__esModule",{value:!0}),n);var ae={};Y(ae,{GraphqlClient:()=>h,MetaCms:()=>G,buildQuery:()=>b,collectionFragment:()=>E,config:()=>ne,contentQuery:()=>w,getMetaCMSConfigQuery:()=>te,getOwnerIdQuery:()=>_,imageFragment:()=>M,isId:()=>C,mediaImageFragment:()=>A,metafieldFragment:()=>x,metafieldsForNodes:()=>q,metafieldsQuery:()=>R,normalizeEdges:()=>m,productFragment:()=>T,randomId:()=>y,setInNamespace:()=>P,setMetaCMSConfigMutation:()=>N,syncConfig:()=>se});module.exports=ee(ae);var k=(n,e,t)=>{if(!n)return t?t():void 0;var r,i;if(Array.isArray(e)&&(r=e.slice(0)),typeof e=="string"&&(r=e.split(".")),typeof e=="symbol"&&(r=[e]),!Array.isArray(r))throw new Error("props arg must be an array, a string or a symbol");for(;r.length;)if(i=r.shift(),!n||(n=n[i],n===void 0))return t?t():void 0;return n};var H=n=>{let e=[];return n.forEach(t=>{!t||(t.type==="product_reference"&&t.product.content&&t.product.content.map(r=>{e.push(r.id)}),t.type==="list.product_reference"&&t.values.edges.map(({node:r})=>{r.content&&r.content.map(i=>{e.push(i.id)})}),t.type==="collection_reference"&&t.collection.content&&t.collection.content.map(r=>{e.push(r.id)}),t.type==="list.collection_reference"&&t.values.edges.map(({node:r})=>{r.content&&r.content.map(i=>{e.push(i.id)})}))}),e};var N=`
"use strict";var N=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(r,e)=>{for(var t in e)N(r,t,{get:e[t],enumerable:!0})},Z=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of K(e))!X.call(r,i)&&i!==t&&N(r,i,{get:()=>e[i],enumerable:!(n=U(e,i))||n.enumerable});return r};var ee=r=>Z(N({},"__esModule",{value:!0}),r);var ae={};Y(ae,{GraphqlClient:()=>C,MetaCms:()=>V,buildQuery:()=>b,collectionFragment:()=>w,config:()=>re,contentQuery:()=>R,fieldToMetafieldType:()=>G,getLoremCollectionData:()=>F,getLoremImageData:()=>$,getLoremProductData:()=>h,getMetaCMSConfigQuery:()=>te,getOwnerIdQuery:()=>A,imageFragment:()=>x,isId:()=>I,mediaImageFragment:()=>E,metafieldFragment:()=>S,metafieldsForNodes:()=>L,metafieldsQuery:()=>q,mockValue:()=>H,normalizeEdges:()=>u,productFragment:()=>T,randomId:()=>y,setInNamespace:()=>P,setMetaCMSConfigMutation:()=>_,syncConfig:()=>se});module.exports=ee(ae);var k=(r,e,t)=>{if(!r)return t?t():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(),!r||(r=r[i],r===void 0))return t?t():void 0;return r};var W=r=>{let e=[];return r.forEach(t=>{!t||(t.type==="product_reference"&&t.product.content&&t.product.content.map(n=>{e.push(n.id)}),t.type==="list.product_reference"&&t.values.edges.map(({node:n})=>{n.content&&n.content.map(i=>{e.push(i.id)})}),t.type==="collection_reference"&&t.collection.content&&t.collection.content.map(n=>{e.push(n.id)}),t.type==="list.collection_reference"&&t.values.edges.map(({node:n})=>{n.content&&n.content.map(i=>{e.push(i.id)})}))}),e};var _=`
mutation ($ownerId: ID!, $value: String!, $key: String!) {

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

}
`;var _=`
`;var A=`
query getOwnerId {

@@ -25,8 +25,8 @@ shop {

}
`;var A=n=>`
`;var E=r=>`
id
image {
${M(n)}
${x(r)}
}
`,M=n=>`
id
`,x=r=>`
alt: altText

@@ -36,3 +36,3 @@ height

src: url
`,T=(n,e)=>`
`,T=(r,e)=>`
id

@@ -54,3 +54,3 @@ descriptionHtml

image {
${M(!1)}
${x(!1)}
}

@@ -78,6 +78,6 @@ price {

}`:""}
${V(n,"product")}
${z(r,"product")}
featuredImage {
${M(!1)}
${x(!1)}
}

@@ -104,3 +104,3 @@ compareAtPriceRange {

}
`,E=(n,e)=>`
`,w=(r,e)=>`
id

@@ -111,3 +111,3 @@ title

image {
${M(n)}
${x(r)}
}

@@ -117,8 +117,8 @@ products(first: 20) {

node {
${T(n,e)}
${T(r,e)}
}
}
}
${V(n,"collection")}
`,V=(n,e)=>n?`
${z(r,"collection")}
`,z=(r,e)=>r?`
content: metafields(identifiers: ${e==="product"?"$productIdentifiers":"$collectionIdentifiers"}) {

@@ -129,3 +129,3 @@ id

}
`:"",x=(n,e)=>`
`:"",S=(r,e)=>`
type

@@ -144,9 +144,9 @@ value

... on MediaImage {
${A(n)}
${E(r)}
}
... on Collection {
${E(n,e)}
${w(r,e)}
}
... on Product {
${T(n,e)}
${T(r,e)}
}

@@ -158,3 +158,3 @@ }

... on MediaImage {
${A(n)}
${E(r)}
}

@@ -164,3 +164,3 @@ }

... on Collection {
${E(n,e)}
${w(r,e)}
}

@@ -170,9 +170,9 @@ }

... on Product {
${T(n,e)}
${T(r,e)}
}
}
`,w=(n,e)=>`
`,R=(r,e)=>`
query getContent(
$identifiers: [HasMetafieldsIdentifier!]!
${n?`$productIdentifiers: [HasMetafieldsIdentifier!]!
${r?`$productIdentifiers: [HasMetafieldsIdentifier!]!
$collectionIdentifiers: [HasMetafieldsIdentifier!]!`:""}

@@ -182,18 +182,18 @@ ) {

content: metafields(identifiers: $identifiers) {
${x(n)}
${S(r)}
}
}
}
`,R=(n,e)=>`
`,q=(r,e)=>`
query getMetafields($ids: [ID!]!) {
metafields: nodes(ids: $ids ${e!=null&&e.customProductMetafields?"$customProductMetafields: [HasMetafieldsIdentifier!]! ":""}) {
... on Metafield {
${x(n,e)}
${S(r,e)}
}
}
}
`;var q=({collectionQuery:n,productQuery:e},t)=>`
`;var L=({collectionQuery:r,productQuery:e},t)=>`
query getNodeContent(
${e?"$productIdentifiers: [HasMetafieldsIdentifier!]! $productQuery:String":""}
${n?"$collectionIdentifiers: [HasMetafieldsIdentifier!]! $collectionQuery:String":""}
${r?"$collectionIdentifiers: [HasMetafieldsIdentifier!]! $collectionQuery:String":""}
${t!=null&&t.customProductMetafields?"$customProductMetafields: [HasMetafieldsIdentifier!]! ":""}

@@ -207,3 +207,3 @@ ){

content: metafields(identifiers: $productIdentifiers) {
${x(!1,t)}
${S(!1,t)}
}

@@ -214,3 +214,3 @@ }

${n?`collections(first:50, query:$collectionQuery){
${r?`collections(first:50, query:$collectionQuery){
edges{

@@ -220,3 +220,3 @@ node{

content: metafields(identifiers: $collectionIdentifiers) {
${x(!1,t)}
${S(!1,t)}
}

@@ -227,3 +227,3 @@ }

}`;var m=n=>n.edges.reduce((e,{node:t})=>(e.push(t),e),[]),ne=n=>n,y=()=>{let n="meta-cms-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",e="",t=10;for(;t--;)e+=n[Math.random()*n.length|0];return`meta-cms-${e}`},C=n=>typeof n=="string"?n.startsWith("gid://shopify/Metafield/"):!1,P=({content:n,namespace:e,key:t,id:r,value:i})=>{let a=r?`${t}@${r}`:t;n[e]||Object.assign(n,{[e]:{}}),Object.assign(n[e],{[a]:i})},b=({handles:n,ids:e})=>{let t=r=>r.replace("gid://shopify/Product/","");return(n==null?void 0:n.length)||(e==null?void 0:e.length)?`${(e||[]).map((r,i,a)=>`id:${t(r)}${a.length-1>i?" or ":n!=null&&n.length?" or":""}`).join("")} ${(n||[]).map((r,i,a)=>`handle:${r}${a.length-1>i?" or ":""}`).join("")}`.trim():void 0};var L=({field:n,acc:e,item:t,locale:r,jsonMetafields:i,nestedContent:a})=>{var u;let o={itemID:t.id,itemType:t.type,itemProp:`${t.namespace}:${t.key}`},d,c=({id:s,key:l,namespace:f,objectId:p})=>{a&&e&&r&&P({content:e,key:l,id:p,namespace:f.replace(`@${r}`,""),value:a[s]})};switch(t.type){case"collection_reference":{d={attributes:o,value:{...t.collection,products:m(t.collection.products).map(({content:s,...l})=>(s==null||s.forEach(f=>c({...f,objectId:l.id})),{...l,variants:m(l.variants)}))}};break}case"file_reference":{(!t.image.image.alt||!t.image.image.alt.length)&&(t.image.image.alt="image"),d={attributes:o,value:t.image.image};break}case"product_reference":{let{product:s}=t;(u=s.content)==null||u.forEach(l=>c({...l,objectId:s.id})),d={attributes:o,value:{...s,variants:m(t.product.variants)}};break}case"list.collection_reference":{d={attributes:o,value:m(t.values).map(s=>{var l;return(l=s.content)==null||l.forEach(f=>c({...f,objectId:s.id})),{...s,products:m(s.products).map(f=>{var p;return(p=f.content)==null||p.forEach(g=>c({...g,objectId:f.id})),{...f,variants:m(f.variants)}})}})};break}case"list.file_reference":{d={attributes:o,value:m(t.values).map(s=>s.image)};break}case"list.product_reference":{d={attributes:o,value:m(t.values).map(s=>{var l;return(l=s.content)==null||l.forEach(f=>c({...f,objectId:s.id})),{...s,variants:m(s.variants)}})};break}case"json":{let s=W(t.value,i);d={attributes:o,value:s.value||s};break}case"list.multi_line_text_field":case"list.single_line_text_field":{d={attributes:o,value:JSON.parse(t.value)};break}case"multi_line_text_field":case"single_line_text_field":{d={attributes:o,value:t.value};break}}return d},O=({client:n,id:e,initalizer:t,content:r,jsonMetafields:i,nestedContent:a})=>{let o=t||{};for(let d=0;d<r.length;d++){let c=r[d];if(c){let u=n.config[c.namespace.replace(`@${n.locale}`,"")].schema[c.key],s=L({client:n,field:u,acc:o,item:c,jsonMetafields:i,nestedContent:a});P({content:o,key:c.key,namespace:c.namespace.replace(`@${n.locale}`,""),value:n.adapter(s)})}}return o};var re=n=>{let e=[];return n&&JSON.parse(n,(t,r)=>(Array.isArray(r)?r.forEach(i=>{C(i)&&e.push(i)}):C(r)&&e.push(r),r)),e},j=n=>{let e=[];return n.forEach(t=>{!t||t.type==="json"&&(e=e.concat(re(t.value)))}),e},v=(n,e)=>n.reduce((t,r)=>{if(r){console.log(r.namespace,e.locale,r.key,e.config[r.namespace.replace(`_${e.locale}`,"")]);let i=e.config[r.namespace.replace(`_${e.locale}`,"")].schema[r.key],a=L({field:i,item:r,client:e});t[r.id]=e.adapter(a)}return t},{}),W=(n,e)=>e?JSON.parse(n,(t,r)=>Array.isArray(r)?r.map(i=>C(i)?e[i]:i):C(r)?e[r]:r):JSON.parse(n);var z=n=>{let t={text:"single_line_text_field",richtext:"multi_line_text_field",image:"file_reference",product:"product_reference",collection:"collection_reference",object:"json"}[n.type];return n.isList?`list.${t}`:t},S=(n=400,e=300)=>({alt:"image",src:`https://picsum.photos/${n}/${e}`,width:n,height:e}),I=()=>({id:y(),descriptionHtml:"Lorem ipsum",title:"Lorem ipsum",handle:"",featuredImage:S(),compareAtPriceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},priceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},variants:[]}),J=()=>({id:y(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:S(),products:[I(),I(),I()]}),D=(n,e=3)=>{let t=[];for(let r=0;r<4;r++)t.push(n());return t},ie=n=>{if(n==="text"||n==="richtext")return"Lorem ipsum";if(n==="image")return S();if(n==="product")return I();if(n==="collection")return J()},Q=(n,e=!0)=>Object.entries(n.schema).reduce((t,[r,i])=>(i.isList?i.type==="object"?t[r]=Q(i,!1):t[r]=[]:i.type==="object"?t[r]=Q(i,!1):t[r]=ie(i.type),t),n.type==="object"&&e?{}:n.isList?[]:{}),U=(n,e)=>{switch(n.type){case"object":return n.isList?{attributes:e,value:[]}:{attributes:e,value:Q(n)};case"collection":return{attributes:e,value:n.isList?D(J):J()};case"image":return{value:n.isList?D(S):{id:y(),...S()},attributes:e};case"product":return{attributes:e,value:n.isList?D(I):I()};case"richtext":return{attributes:e,value:n.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!`};default:case"text":return{attributes:e,value:n.isList?["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:"Lorem ipsum dolor sit amet consectetur adipisicing elit."}}};var h=class{constructor(e,t){this.request=async(e,t)=>{let{data:r}=await(await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:t||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}})).json();return r};this.url=e,this.headers=t}},G=class{constructor(e,{storefrontName:t,storefrontAccessToken:r,defaultNameSpaces:i},a){this.getMetafieldsByIds=async e=>{var i,a;if(!e.length)return[{},[]];let t=await this.client.request(R(!1,{customProductMetafields:(a=(i=this.params)==null?void 0:i.product)==null?void 0:a.customMetafieldsIdentifiers}),{ids:e});if(console.log({res:t}),!t)return[{},[]];let{metafields:r}=t;return[v(r,this),r]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:t},r="fra")=>{var p,g;if(!(e!=null&&e.ids)&&!(e!=null&&e.handles)&&!(e!=null&&e.namespaces)&&!(t!=null&&t.ids)&&!(t!=null&&t.handles)&&!(t!=null&&t.namespaces))return[{},[],[]];let i=await this.client.request(q({collectionQuery:b({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:b({ids:t==null?void 0:t.ids,handles:t==null?void 0:t.handles})},{customProductMetafields:(g=(p=this.params)==null?void 0:p.product)==null?void 0:g.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers((t==null?void 0:t.namespaces)||[],r),collectionIdentifiers:this.buildIdentifiers((e==null?void 0:e.namespaces)||[],r)});if(console.log({res:i}),!i)return[{},[],[]];let{products:a,collections:o}=i,d=a?m(a):[],c=o?m(o):[],u=d.map($=>$.content).flat(),s=c.map($=>$.content).flat(),l=v(u,this),f=v(s,this);return[{...l,...f},u.concat(s),d.concat(c)]};this.getContentForNamespaces=async(e,t="fra")=>{var l,f,p;if(this.locale=t,!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(w(!0,{customProductMetafields:(l=e.product)==null?void 0:l.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((f=e.product)==null?void 0:f.namespaces)||[],t),collectionIdentifiers:this.buildIdentifiers(((p=e.collection)==null?void 0:p.namespaces)||[],t),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),t)}),[[i,a],[o,d,c]]=await Promise.all([this.getMetafieldsByIds(H(r)),this.getMetafieldsForProductsAndCollection(e)]),[u]=await this.getMetafieldsByIds(j(r.concat(a).concat(d))),s=O({client:this,content:r,jsonMetafields:u,nestedContent:{...i,...o}});return console.log("content",r,"jsonMetafields",u,"getJsonNstedIds",j(r)),c.forEach(({id:g,content:$})=>{O({client:this,initalizer:s,id:g,content:$,jsonMetafields:u,nestedContent:{...i,...o}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:s}};this.t=(e,t,{productId:r,collectionId:i},a)=>{let[o,d]=e.split("."),{kind:c,schema:u}=this.config[o];r&&c==="product"&&(d=`${d}@${r}`),i&&c==="collection"&&(d=`${d}@${i}`);let s=u[d],l=()=>k(this.config[o],`${d}.default`,()=>{let f=z(s),p={itemID:y(),itemType:f,itemProp:`${o}:${d}`},g=U(s,p);return a?a(g,s):g});return k(t,`${o}.${d}`,l)};this.buildIdentifiers=(e,t="fra")=>e?e.reduce((r,i)=>{let a=this.config[i];return a&&Object.keys(a.schema).forEach(o=>{r.push({namespace:`${i}@${t}`,key:o})}),r},[]):[];this.locale="en",this.adapter=a||(o=>o),this.config=e,this.defaultNameSpaces=i||[],this.client=new h(`https://${t}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r})}};var se=async(n,{storefrontName:e,storefrontAccessToken:t,adminAccessToken:r},i)=>{console.log(i);let a=new h(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":t}),o=new h(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":r}),{shop:{id:d}}=await a.request(_);return await o.request(N,{value:JSON.stringify(n),key:i,ownerId:d})};0&&(module.exports={GraphqlClient,MetaCms,buildQuery,collectionFragment,config,contentQuery,getMetaCMSConfigQuery,getOwnerIdQuery,imageFragment,isId,mediaImageFragment,metafieldFragment,metafieldsForNodes,metafieldsQuery,normalizeEdges,productFragment,randomId,setInNamespace,setMetaCMSConfigMutation,syncConfig});
}`;var u=r=>r.edges.reduce((e,{node:t})=>(e.push(t),e),[]),re=r=>r,y=()=>{let r="meta-cms-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",e="",t=10;for(;t--;)e+=r[Math.random()*r.length|0];return`meta-cms-${e}`},I=r=>typeof r=="string"?r.startsWith("gid://shopify/Metafield/"):!1,P=({content:r,namespace:e,key:t,id:n,value:i})=>{let o=n?`${t}@${n}`:t;r[e]||Object.assign(r,{[e]:{}}),Object.assign(r[e],{[o]:i})},b=({handles:r,ids:e})=>{let t=n=>n.replace("gid://shopify/Product/","");return(r==null?void 0:r.length)||(e==null?void 0:e.length)?`${(e||[]).map((n,i,o)=>`id:${t(n)}${o.length-1>i?" or ":r!=null&&r.length?" or":""}`).join("")} ${(r||[]).map((n,i,o)=>`handle:${n}${o.length-1>i?" or ":""}`).join("")}`.trim():void 0};var O=({field:r,acc:e,item:t,locale:n,jsonMetafields:i,nestedContent:o})=>{var m;let a={itemID:t.id,itemType:t.type,itemProp:`${t.namespace}:${t.key}`},d,f=({id:s,key:c,namespace:l,objectId:p})=>{o&&e&&n&&P({content:e,key:c,id:p,namespace:l.replace(`@${n}`,""),value:o[s]})};switch(t.type){case"collection_reference":{d={attributes:a,value:{...t.collection,products:u(t.collection.products).map(({content:s,...c})=>(s==null||s.forEach(l=>f({...l,objectId:c.id})),{...c,variants:u(c.variants)}))}};break}case"file_reference":{(!t.image.image.alt||!t.image.image.alt.length)&&(t.image.image.alt="image"),d={attributes:a,value:t.image.image};break}case"product_reference":{let{product:s}=t;(m=s.content)==null||m.forEach(c=>f({...c,objectId:s.id})),d={attributes:a,value:{...s,variants:u(t.product.variants)}};break}case"list.collection_reference":{d={attributes:a,value:u(t.values).map(s=>{var c;return(c=s.content)==null||c.forEach(l=>f({...l,objectId:s.id})),{...s,products:u(s.products).map(l=>{var p;return(p=l.content)==null||p.forEach(g=>f({...g,objectId:l.id})),{...l,variants:u(l.variants)}})}})};break}case"list.file_reference":{d={attributes:a,value:u(t.values).map(s=>s.image)};break}case"list.product_reference":{d={attributes:a,value:u(t.values).map(s=>{var c;return(c=s.content)==null||c.forEach(l=>f({...l,objectId:s.id})),{...s,variants:u(s.variants)}})};break}case"json":{let s=B(t.value,i);d={attributes:a,value:s.value||s};break}case"list.multi_line_text_field":case"list.single_line_text_field":{d={attributes:a,value:JSON.parse(t.value)};break}case"multi_line_text_field":case"single_line_text_field":{d={attributes:a,value:t.value};break}}return d},j=({client:r,id:e,initalizer:t,content:n,jsonMetafields:i,nestedContent:o})=>{var d,f;let a=t||{};for(let m=0;m<n.length;m++){let s=n[m];if(s){let c=(f=(d=r.config[s.namespace.replace(`@${r.locale}`,"")])==null?void 0:d.schema)==null?void 0:f[s.key];if(!c)return a;let l=O({client:r,field:c,acc:a,item:s,jsonMetafields:i,nestedContent:o});P({content:a,key:s.key,namespace:s.namespace.replace(`@${r.locale}`,""),value:r.adapter(l)})}}return a};var ne=r=>{let e=[];return r&&JSON.parse(r,(t,n)=>(Array.isArray(n)?n.forEach(i=>{I(i)&&e.push(i)}):I(n)&&e.push(n),n)),e},D=r=>{let e=[];return r.forEach(t=>{!t||t.type==="json"&&(e=e.concat(ne(t.value)))}),e},v=(r,e)=>r.reduce((t,n)=>{var i,o;if(n){let a=(o=(i=e.config[n.namespace.replace(`@${e.locale}`,"")])==null?void 0:i.schema)==null?void 0:o[n.key];if(!a)return t;let d=O({field:a,item:n,client:e});t[n.id]=e.adapter(d)}return t},{}),B=(r,e)=>e?JSON.parse(r,(t,n)=>Array.isArray(n)?n.map(i=>I(i)?e[i]:i):I(n)?e[n]:n):JSON.parse(r);var G=r=>{let t={text:"single_line_text_field",richtext:"multi_line_text_field",image:"file_reference",product:"product_reference",collection:"collection_reference",object:"json"}[r.type];return r.isList?`list.${t}`:t},$=(r=400,e=300)=>({alt:"image",src:`https://picsum.photos/${r}/${e}`,width:r,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:[]}),F=()=>({id:y(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:$(),products:[h(),h(),h()]}),J=(r,e=3)=>{let t=[];for(let n=0;n<4;n++)t.push(r());return t},ie=r=>{if(r==="text"||r==="richtext")return"Lorem ipsum";if(r==="image")return $();if(r==="product")return h();if(r==="collection")return F()},Q=(r,e=!0)=>Object.entries(r.schema).reduce((t,[n,i])=>(i.isList?i.type==="object"?t[n]=Q(i,!1):t[n]=[]:i.type==="object"?t[n]=Q(i,!1):t[n]=ie(i.type),t),r.type==="object"&&e?{}:r.isList?[]:{}),H=(r,e,t=!0)=>{switch(r.type){case"object":return r.isList?{attributes:e,value:[]}:{attributes:e,value:Q(r)};case"collection":return{attributes:e,value:r.isList?J(F):F()};case"image":return{value:r.isList?t?J($):[]:t?{id:y(),...$()}:void 0,attributes:e};case"product":return{attributes:e,value:r.isList?J(h):h()};case"richtext":return{attributes:e,value:r.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!`};default:case"text":return{attributes:e,value:r.isList?["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:"Lorem ipsum dolor sit amet consectetur adipisicing elit."}}};var C=class{constructor(e,t){this.request=async(e,t)=>{let{data:n}=await(await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:t||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}})).json();return n};this.url=e,this.headers=t}},V=class{constructor(e,{storefrontName:t,storefrontAccessToken:n,defaultNameSpaces:i},o){this.getMetafieldsByIds=async e=>{var i,o;if(!e.length)return[{},[]];let t=await this.client.request(q(!1,{customProductMetafields:(o=(i=this.params)==null?void 0:i.product)==null?void 0:o.customMetafieldsIdentifiers}),{ids:e});if(console.log({res:t}),!t)return[{},[]];let{metafields:n}=t;return[v(n,this),n]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:t},n="fra")=>{var p,g;if(!(e!=null&&e.ids)&&!(e!=null&&e.handles)&&!(e!=null&&e.namespaces)&&!(t!=null&&t.ids)&&!(t!=null&&t.handles)&&!(t!=null&&t.namespaces))return[{},[],[]];let i=await this.client.request(L({collectionQuery:b({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:b({ids:t==null?void 0:t.ids,handles:t==null?void 0:t.handles})},{customProductMetafields:(g=(p=this.params)==null?void 0:p.product)==null?void 0:g.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers((t==null?void 0:t.namespaces)||[],n),collectionIdentifiers:this.buildIdentifiers((e==null?void 0:e.namespaces)||[],n)});if(console.log({res:i}),!i)return[{},[],[]];let{products:o,collections:a}=i,d=o?u(o):[],f=a?u(a):[],m=d.map(M=>M.content).flat(),s=f.map(M=>M.content).flat(),c=v(m,this),l=v(s,this);return[{...c,...l},m.concat(s),d.concat(f)]};this.getContentForNamespaces=async(e,t="fra")=>{var c,l,p;if(this.locale=t,!e.global)return{content:{},params:e};this.params=e;let{shop:{content:n}}=await this.client.request(R(!0,{customProductMetafields:(c=e.product)==null?void 0:c.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((l=e.product)==null?void 0:l.namespaces)||[],t),collectionIdentifiers:this.buildIdentifiers(((p=e.collection)==null?void 0:p.namespaces)||[],t),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),t)}),[[i,o],[a,d,f]]=await Promise.all([this.getMetafieldsByIds(W(n)),this.getMetafieldsForProductsAndCollection(e)]),[m]=await this.getMetafieldsByIds(D(n.concat(o).concat(d))),s=j({client:this,content:n,jsonMetafields:m,nestedContent:{...i,...a}});return console.log("content",n,"jsonMetafields",m,"getJsonNstedIds",D(n)),f.forEach(({id:g,content:M})=>{j({client:this,initalizer:s,id:g,content:M,jsonMetafields:m,nestedContent:{...i,...a}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:s}};this.t=(e,t,{productId:n,collectionId:i},o)=>{let[a,d]=e.split("."),{kind:f,schema:m}=this.config[a];n&&f==="product"&&(d=`${d}@${n}`),i&&f==="collection"&&(d=`${d}@${i}`);let s=m[d],c=()=>k(this.config[a],`${d}.default`,()=>{let l=G(s),p={itemID:y(),itemType:l,itemProp:`${a}:${d}`},g=H(s,p);return o?o(g,s):g});return k(t,`${a}.${d}`,c)};this.buildIdentifiers=(e,t="fra")=>e?e.reduce((n,i)=>{let o=this.config[i];return o&&Object.keys(o.schema).forEach(a=>{n.push({namespace:`${i}@${t}`,key:a})}),n},[]):[];this.locale="en",this.adapter=o||(a=>a),this.config=e,this.defaultNameSpaces=i||[],this.client=new C(`https://${t}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var se=async(r,{storefrontName:e,storefrontAccessToken:t,adminAccessToken:n},i)=>{console.log(i);let o=new C(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":t}),a=new C(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":n}),{shop:{id:d}}=await o.request(A);return await a.request(_,{value:JSON.stringify(r),key:i,ownerId:d})};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});
{
"name": "@meta-cms/core",
"version": "1.0.50",
"version": "1.0.51",
"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