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.61 to 1.0.62

21

index.d.ts

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

};
declare type TextField = {
type: 'text';
default?: Text;
isList?: false;
templates?: Readonly<string[]>;
};
declare type ModelKind = 'global' | 'product' | 'collection' | 'page';

@@ -176,8 +182,4 @@ declare type ObjectType = Field['type'];

isList?: true;
} | {
} | TextField | {
type: 'text';
default?: Text;
isList?: false;
} | {
type: 'text';
default?: Text[];

@@ -234,2 +236,3 @@ isList?: true;

key: string;
displayName?: string;
id: string;

@@ -481,2 +484,8 @@ value: string;

export { Adapter, BooleanContent, CollectionContent, CollectionData, CollectionsContent, ConfigType, Content, Field, GetConfigType, GetContentParams, GetField, GetType2, GraphqlClient, HTMLContent, HTMLsContent, IdAccessors, Identifier, ImageContent, ImageData, ImagesContent, ItemAttributes, Last, Locale, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, MetafieldVideo, 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, UrlContent, VariantContent, VideoContent, VideoData, VideosContent, 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, traverse, videoFragment };
declare type variables = {
[key: string]: boolean | string | number;
};
declare const mustaching: (string: string, variables?: variables | undefined) => string;
declare const templating: (value: string, variables?: variables | undefined) => string;
export { Adapter, BooleanContent, CollectionContent, CollectionData, CollectionsContent, ConfigType, Content, Field, GetConfigType, GetContentParams, GetField, GetType2, GraphqlClient, HTMLContent, HTMLsContent, IdAccessors, Identifier, ImageContent, ImageData, ImagesContent, ItemAttributes, Last, Locale, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, MetafieldVideo, 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, TextField, TextsContent, UrlContent, VariantContent, VideoContent, VideoData, VideosContent, WithEdge, buildQuery, collectionFragment, config, contentQuery, fieldToMetafieldType, getLoremCollectionData, getLoremImageData, getLoremProductData, getMetaCMSConfigQuery, getOwnerIdQuery, imageFragment, isId, isList, mediaImageFragment, metafieldFragment, metafieldType, metafieldsForNodes, metafieldsQuery, mockValue, mustaching, normalizeEdges, productFragment, randomId, setInNamespace, setMetaCMSConfigMutation, simpleMetafieldType, syncConfig, templating, toList, toList2, traverse, videoFragment };

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

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

}
`,ne=`
`,ae=`
query {

@@ -28,5 +28,5 @@ shop {

image {
${M(t)}
${x(t)}
}
`,M=t=>`
`,x=t=>`
alt: altText

@@ -65,3 +65,3 @@ height

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

@@ -92,3 +92,3 @@ price {

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

@@ -115,3 +115,3 @@ compareAtPriceRange {

}
`,R=(t,e)=>`
`,O=(t,e)=>`
id

@@ -122,3 +122,3 @@ title

image {
${M(t)}
${x(t)}
}

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

}
`:"",x=(t,e)=>`
`:"",M=(t,e)=>`
type

@@ -157,3 +157,3 @@ value

... on Collection {
${R(t,e)}
${O(t,e)}
}

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

... on Collection {
${R(t,e)}
${O(t,e)}
}

@@ -190,3 +190,3 @@ }

}
`,q=(t,e)=>`
`,R=(t,e)=>`
query getContent(

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

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

@@ -224,3 +224,3 @@ }

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

@@ -236,3 +236,3 @@ }

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

@@ -243,3 +243,3 @@ }

}`;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!=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});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",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"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),[]),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,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,a)=>{if(Array.isArray(t))i.push(S(s,e,r.concat(a)));else{let[c,d]=s;Array.isArray(d)?(i[c]=[],d.forEach((o,l)=>i[c].push(S(o,e,r.concat(c).concat(l))))):d&&(d.attributes?i[c]=e(d,r.concat(c)):i[c]=S(d,e,r.concat(c)))}return i},Array.isArray(t)?[]:{}));var D=({acc:t,item:e,locale:r,jsonMetafields:n,nestedContent:i})=>{var d;let s={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},a,c=({id:o,key:l,namespace:f,objectId:m})=>{i&&t&&r&&P({content:t,key:l,id:m,namespace:f.replace(`@${r}`,""),value:i[o]})};switch(e.type){case"collection_reference":{a={attributes:s,value:{...e.collection,products:u(e.collection.products).map(({content:o,...l})=>(o==null||o.forEach(f=>c({...f,objectId:l.id})),{...l,variants:u(l.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"),a={attributes:s,value:e.image.image};break}if("video"in e){a={attributes:s,value:e.video};break}}case"product_reference":{let{product:o}=e;(d=o.content)==null||d.forEach(l=>c({...l,objectId:o.id})),a={attributes:s,value:{...o,variants:u(e.product.variants)}};break}case"list.collection_reference":{a={attributes:s,value:u(e.values).map(o=>{var l;return(l=o.content)==null||l.forEach(f=>c({...f,objectId:o.id})),{...o,products:u(o.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":{a={attributes:s,value:u(e.values).map(o=>o.image)};break}case"list.product_reference":{a={attributes:s,value:u(e.values).map(o=>{var l;return(l=o.content)==null||l.forEach(f=>c({...f,objectId:o.id})),{...o,variants:u(o.variants)}})};break}case"json":{let o=K(e.value,n);a={attributes:s,value:o.value||o};break}case"list.multi_line_text_field":case"list.single_line_text_field":{a={attributes:s,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{a={attributes:s,value:e.value||""};break}case"boolean":{a={attributes:s,value:e.value==="true"};break}case"url":{a={attributes:s,value:e.value||""};break}}return a},V=({client:t,id:e,initalizer:r,content:n,jsonMetafields:i,nestedContent:s})=>{var c,d;let a=r||{};for(let o=0;o<n.length;o++){let l=n[o];if(l){if(!((d=(c=t.config[l.namespace.replace(`@${t.locale}`,"")])==null?void 0:c.schema)==null?void 0:d[l.key]))return a;let m=D({client:t,acc:a,item:l,jsonMetafields:i,nestedContent:s});P({content:a,key:l.key,namespace:l.namespace.replace(`@${t.locale}`,""),value:m})}}return a};var ce=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},Q=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(ce(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},le=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]=le(i.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?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}},W=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(q(!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:a}=i,c=s?u(s):[],d=a?u(a):[],o=c.map(A=>A.content).flat(),l=d.map(A=>A.content).flat(),f=v(o,this),m=v(l,this);return[{...f,...m},o.concat(l),c.concat(d)]};this.getContentForNamespaces=async e=>{var l,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(R(!0,{customProductMetafields:(l=e.product)==null?void 0:l.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,a,c]]=await Promise.all([this.getMetafieldsByIds(B(r)),this.getMetafieldsForProductsAndCollection(e)]),[d]=await this.getMetafieldsByIds(Q(r.concat(i).concat(a)));console.log({jsonMetafields:d},Q(r));let o=V({client:this,content:r,jsonMetafields:d,nestedContent:{...n,...s}});return c.forEach(({id:p,content:g})=>{V({client:this,initalizer:o,id:p,content:g,jsonMetafields:d,nestedContent:{...n,...s}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:o}};this.t=(e,r,{productId:n,collectionId:i},s)=>{let[a,c]=e.split("."),{kind:d,schema:o}=this.config[a];n&&d==="product"&&(c=`${c}@${n}`),i&&d==="collection"&&(c=`${c}@${i}`);let l=o[c],f=()=>N(this.config[a],`${c}.default`,()=>{let m=H(l),p={itemID:y(),itemType:m,itemProp:`${a}:${c}`},g=z(l,p);return s?s(g,l):g});return N(r,`${a}.${c}`,f)};this.buildIdentifiers=(e,r)=>e?e.reduce((n,i)=>{let s=this.config[i];return s&&Object.keys(s.schema).forEach(a=>{n.push({namespace:`${i}@${r}`,key:a})}),n},[]):[];this.locale="en",this.adapter=s||(a=>a),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 de=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}),a=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 a.request(_,{value:JSON.stringify(t),key:i,ownerId:c})};var X=/{{([\:\/\-\\\,\.a-zA-Z0-9\s])*}}/g,Z=(t,e)=>(e&&Object.keys(e).forEach(r=>{t=t.replace(`{{${r}}}`,String(e[r]))}),t.replace(X,"")),Y=/\(\(([\:\/\-\\\,\s\u0030-\u4351\u4e00-\u9fa5])*\)\)/g,fe=(t,e)=>{if(!e)return t;let r=t.matchAll(Y);return Array.from(r).forEach(n=>{let[i]=n,[s,a,c]=i.replace("((","").replace("))","").split(","),d=typeof e[s]=="number"?e[s]>1:!!e[s];c?d===!0?t=t.replace(i,c.trim()):t=t.replace(i,a.trim()):d===!0?(c=a,t=t.replace(i,c.trim())):t=t.replace(Y,"")}),t},ue=(t,e)=>fe(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.61",
"version": "1.0.62",
"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