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.57 to 1.0.58

42

index.d.ts

@@ -80,2 +80,11 @@ import { Get } from 'type-fest';

};
declare type VideoData = MetafieldVideo;
declare type VideoContent = {
value: VideoData;
attributes: ItemAttributes<'file_reference'>;
};
declare type VideosContent = {
value: VideoData[];
attributes: ItemAttributes<'file_reference'>;
};
declare type BooleanContent = {

@@ -140,2 +149,10 @@ value: boolean;

} | {
type: 'video';
default?: VideoContent;
isList?: false;
} | {
type: 'video';
default?: VideoContent;
isList: true;
} | {
type: 'boolean';

@@ -187,3 +204,3 @@ default?: ProductContent[];

};
declare type ConfigType = 'json' | 'file' | 'product' | 'collection' | 'object' | 'url' | 'boolean';
declare type ConfigType = 'json' | 'file' | 'product' | 'collection' | 'object' | 'url' | 'boolean' | 'video';
declare type GetField<S extends Schema, P extends Paths<S>> = Split<P>[1] extends keyof S[Split<P>[0]]['schema'] ? S[Split<P>[0]]['schema'][Split<P>[1]] : never;

@@ -198,3 +215,3 @@ declare type GetConfigType<S extends Schema, P extends Paths<S>> = Split<P>[1] extends keyof S[Split<P>[0]]['schema'] ? Split<P>[1] extends keyof S[Split<P>[0]]['schema'] ? S[Split<P>[0]]['schema'][Split<P>[1]]['type'] : never : never;

};
declare type GetType2<F extends Field> = F['type'] extends 'text' ? toList2<F, TextContent, TextsContent> : F['type'] extends 'collection' ? toList2<F, CollectionContent, CollectionsContent> : F['type'] extends 'product' ? toList2<F, ProductContent, ProductsContent> : F['type'] extends 'richtext' ? toList2<F, HTMLContent, HTMLsContent> : F['type'] extends 'boolean' ? BooleanContent : F['type'] extends 'url' ? UrlContent : F['type'] extends 'object' ? F extends ObjectField ? F['schema'] extends ModelSchema ? Record<'value', toList2<F, ObjectContent2<F['schema']>>> & {
declare type GetType2<F extends Field> = F['type'] extends 'text' ? toList2<F, TextContent, TextsContent> : F['type'] extends 'collection' ? toList2<F, CollectionContent, CollectionsContent> : F['type'] extends 'product' ? toList2<F, ProductContent, ProductsContent> : F['type'] extends 'richtext' ? toList2<F, HTMLContent, HTMLsContent> : F['type'] extends 'boolean' ? BooleanContent : F['type'] extends 'url' ? UrlContent : F['type'] extends 'video' ? toList2<F, VideoContent, VideosContent> : F['type'] extends 'object' ? F extends ObjectField ? F['schema'] extends ModelSchema ? Record<'value', toList2<F, ObjectContent2<F['schema']>>> & {
attributes: ItemAttributes<'json'>;

@@ -233,2 +250,5 @@ } : never : never : toList2<F, ImageContent, ImagesContent>;

} | {
type: 'file_reference';
video: MetafieldVideo;
} | {
type: 'product_reference';

@@ -256,3 +276,3 @@ product: MetafieldProduct;

edges: {
node: MetafieldImage;
node: MetafieldImage | MetafieldVideo;
}[];

@@ -328,2 +348,15 @@ };

};
declare type MetafieldVideo = {
id: string;
alt: string;
previewImage: {
src: string;
};
sources: {
height: number;
width: number;
src: string;
type: string;
}[];
};
declare type WithEdge<T extends WithEdge<T>> = {

@@ -412,2 +445,3 @@ edges: {

declare const imageFragment: (nested: boolean) => string;
declare const videoFragment: (nested: boolean) => string;
declare const productFragment: (nested: boolean, customMetafields?: CustomMetafields) => string;

@@ -452,2 +486,2 @@ declare const collectionFragment: (nested: boolean, customMetafields?: CustomMetafields) => 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, 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, 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 };
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 };

60

index.js

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

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

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

}
`,re=`
`,ne=`
query {

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

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

@@ -26,3 +26,3 @@ shop {

}
`;var L=t=>`
`;var E=t=>`
id

@@ -37,3 +37,15 @@ image {

src: url(transform:{maxWidth:4000})
`,S=(t,e)=>`
`,L=t=>`
id
alt
previewImage{
src: url
}
sources{
height
width
src:url
type: mimeType
}
`,T=(t,e)=>`
id

@@ -78,3 +90,3 @@ descriptionHtml

}`:""}
${B(t,"product")}
${U(t,"product")}

@@ -104,3 +116,3 @@ featuredImage {

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

@@ -116,8 +128,8 @@ title

node {
${S(t,e)}
${T(t,e)}
}
}
}
${B(t,"collection")}
`,B=(t,e)=>t?`
${U(t,"collection")}
`,U=(t,e)=>t?`
content: metafields(identifiers: ${e==="product"?"$productIdentifiers":"$collectionIdentifiers"}) {

@@ -142,10 +154,13 @@ id

... on MediaImage {
${L(t)}
${E(t)}
}
... on Collection {
${w(t,e)}
${R(t,e)}
}
... on Product {
${S(t,e)}
${T(t,e)}
}
...on Video {
${L(t)}
}
}

@@ -156,2 +171,7 @@ }

... on MediaImage {
${E(t)}
}
}
video: reference {
...on Video {
${L(t)}

@@ -162,3 +182,3 @@ }

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

@@ -168,6 +188,6 @@ }

... on Product {
${S(t,e)}
${T(t,e)}
}
}
`,R=(t,e)=>`
`,q=(t,e)=>`
query getContent(

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

}
`,q=(t,e)=>`
`,O=(t,e)=>`
query getMetafields($ids: [ID!]!) {

@@ -193,3 +213,3 @@ metafields: nodes(ids: $ids ${e!=null&&e.customProductMetafields?"$customProductMetafields: [HasMetafieldsIdentifier!]! ":""}) {

}
`;var O=({collectionQuery:t,productQuery:e},r)=>`
`;var j=({collectionQuery:t,productQuery:e},r)=>`
query getNodeContent(

@@ -223,3 +243,3 @@ ${e?"$productIdentifiers: [HasMetafieldsIdentifier!]! $productQuery:String":""}

}`;var m=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),ne=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},T=(t,e,r=[])=>(console.log({data:t}),(Array.isArray(t)?t:Object.entries(t)).reduce((i,s,o)=>{if(Array.isArray(t))i.push(T(s,e,r.concat(o)));else{let[c,l]=s;Array.isArray(l)?(i[c]=[],l.forEach((a,d)=>i[c].push(T(a,e,r.concat(c).concat(d))))):l&&(l.attributes?i[c]=e(l,r.concat(c)):i[c]=T(l,e,r.concat(c)))}return i},Array.isArray(t)?[]:{}));var j=({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:u})=>{i&&t&&r&&P({content:t,key:d,id:u,namespace:f.replace(`@${r}`,""),value:i[a]})};switch(e.type){case"collection_reference":{o={attributes:s,value:{...e.collection,products:m(e.collection.products).map(({content:a,...d})=>(a==null||a.forEach(f=>c({...f,objectId:d.id})),{...d,variants:m(d.variants)}))}};break}case"file_reference":{(!e.image.image.alt||!e.image.image.alt.length)&&(e.image.image.alt="image"),o={attributes:s,value:e.image.image};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:m(e.product.variants)}};break}case"list.collection_reference":{o={attributes:s,value:m(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(f=>c({...f,objectId:a.id})),{...a,products:m(a.products).map(f=>{var u;return(u=f.content)==null||u.forEach(p=>c({...p,objectId:f.id})),{...f,variants:m(f.variants)}})}})};break}case"list.file_reference":{o={attributes:s,value:m(e.values).map(a=>a.image)};break}case"list.product_reference":{o={attributes:s,value:m(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(f=>c({...f,objectId:a.id})),{...a,variants:m(a.variants)}})};break}case"json":{let a=U(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},D=({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 u=j({client:t,acc:o,item:d,jsonMetafields:i,nestedContent:s});P({content:o,key:d.key,namespace:d.namespace.replace(`@${t.locale}`,""),value:t.adapter(u)})}}return o};var ie=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(ie(r.value)))}),e},v=(t,e)=>t.reduce((r,n)=>{if(n){let i=j({item:n,client:e});r[n.id]=e.adapter(i)}return r},{}),U=(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"}[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:[]}),A=()=>({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},se=t=>{if(t==="text"||t==="richtext")return"Lorem ipsum";if(t==="image")return $();if(t==="product")return h();if(t==="collection")return A()},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]=se(i.type),r),t.type==="object"&&e?{}:t.isList?[]:{}),V=(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(A):A()};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{data:n}=await(await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:r||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}})).json();return n};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(O({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?m(s):[],l=o?m(o):[],a=c.map(k=>k.content).flat(),d=l.map(k=>k.content).flat(),f=v(a,this),u=v(d,this);return[{...f,...u},a.concat(d),c.concat(l)]};this.getContentForNamespaces=async e=>{var d,f,u;if(this.locale=e.locale||"en",console.log("this.locale",this.locale),!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(R(!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(((u=e.collection)==null?void 0:u.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)}),[[n,i],[s,o,c]]=await Promise.all([this.getMetafieldsByIds(z(r)),this.getMetafieldsForProductsAndCollection(e)]),[l]=await this.getMetafieldsByIds(Q(r.concat(i).concat(o)));console.log({jsonMetafields:l},Q(r));let a=D({client:this,content:r,jsonMetafields:l,nestedContent:{...n,...s}});return c.forEach(({id:p,content:g})=>{D({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 u=H(d),p={itemID:y(),itemType:u,itemProp:`${o}:${c}`},g=V(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 ae=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(E);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});
}`;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});
{
"name": "@meta-cms/core",
"version": "1.0.57",
"version": "1.0.58",
"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