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.51 to 1.0.52

32

index.d.ts

@@ -33,2 +33,6 @@ import { Get } from 'type-fest';

};
declare type UrlContent = {
value: string;
attributes: ItemAttributes<'url'>;
};
declare type TextsContent = {

@@ -77,2 +81,6 @@ value: string[];

};
declare type BooleanContent = {
value: boolean;
attributes: ItemAttributes<'boolean'>;
};
declare type ProductsContent = {

@@ -129,2 +137,10 @@ attributes: ItemAttributes<'list.product_reference'>;

} | {
type: 'url';
default?: UrlContent;
isList?: false;
} | {
type: 'boolean';
default?: ProductContent[];
isList?: false;
} | {
type: 'collection';

@@ -172,3 +188,3 @@ default?: CollectionContent;

};
declare type ConfigType = 'json' | 'file' | 'product' | 'collection' | 'object';
declare type ConfigType = 'json' | 'file' | 'product' | 'collection' | 'object' | 'url' | 'boolean';
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;

@@ -183,3 +199,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 '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 'object' ? F extends ObjectField ? F['schema'] extends ModelSchema ? Record<'value', toList2<F, ObjectContent2<F['schema']>>> & {
attributes: ItemAttributes<'json'>;

@@ -243,2 +259,8 @@ } : never : never : toList2<F, ImageContent, ImagesContent>;

};
} | {
type: 'boolean';
valus: boolean;
} | {
type: 'url';
valus: string;
});

@@ -318,3 +340,5 @@ declare type MetafieldProduct = {

'multi_line_text_field',
'json'
'json',
'boolean',
'url'
][number];

@@ -424,2 +448,2 @@ declare type metafieldType = simpleMetafieldType | `list.${simpleMetafieldType}`;

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 };
export { Adapter, BooleanContent, 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, 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 };

14

index.js

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

"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 _=`
"use strict";var F=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(r,e)=>{for(var t in e)F(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&&F(r,i,{get:()=>e[i],enumerable:!(n=U(e,i))||n.enumerable});return r};var ee=r=>Z(F({},"__esModule",{value:!0}),r);var ae={};Y(ae,{GraphqlClient:()=>C,MetaCms:()=>H,buildQuery:()=>b,collectionFragment:()=>w,config:()=>re,contentQuery:()=>R,fieldToMetafieldType:()=>J,getLoremCollectionData:()=>k,getLoremImageData:()=>$,getLoremProductData:()=>h,getMetaCMSConfigQuery:()=>te,getOwnerIdQuery:()=>A,imageFragment:()=>x,isId:()=>I,mediaImageFragment:()=>E,metafieldFragment:()=>S,metafieldsForNodes:()=>L,metafieldsQuery:()=>q,mockValue:()=>G,normalizeEdges:()=>u,productFragment:()=>T,randomId:()=>y,setInNamespace:()=>P,setMetaCMSConfigMutation:()=>_,syncConfig:()=>se});module.exports=ee(ae);var N=(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 V=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!) {

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

width
src: url
src: url(transform:{maxWidth:4000})
`,T=(r,e)=>`

@@ -75,3 +75,3 @@ id

}`:""}
${z(r,"product")}
${W(r,"product")}

@@ -116,4 +116,4 @@ featuredImage {

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

@@ -213,3 +213,3 @@ id

}`;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});
}`;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 d=n?`${t}@${n}`:t;r[e]||Object.assign(r,{[e]:{}}),Object.assign(r[e],{[d]: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,d)=>`id:${t(n)}${d.length-1>i?" or ":r!=null&&r.length?" or":""}`).join("")} ${(r||[]).map((n,i,d)=>`handle:${n}${d.length-1>i?" or ":""}`).join("")}`.trim():void 0};var O=({field:r,acc:e,item:t,locale:n,jsonMetafields:i,nestedContent:d})=>{var m;let a={itemID:t.id,itemType:t.type,itemProp:`${t.namespace}:${t.key}`},o,f=({id:s,key:c,namespace:l,objectId:p})=>{d&&e&&n&&P({content:e,key:c,id:p,namespace:l.replace(`@${n}`,""),value:d[s]})};switch(t.type){case"collection_reference":{o={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"),o={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})),o={attributes:a,value:{...s,variants:u(t.product.variants)}};break}case"list.collection_reference":{o={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":{o={attributes:a,value:u(t.values).map(s=>s.image)};break}case"list.product_reference":{o={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=z(t.value,i);o={attributes:a,value:s.value||s};break}case"list.multi_line_text_field":case"list.single_line_text_field":{o={attributes:a,value:JSON.parse(t.value)};break}case"multi_line_text_field":case"single_line_text_field":{o={attributes:a,value:t.value};break}case"boolean":{o={attributes:a,value:t.value==="true"};break}case"url":{o={attributes:a,value:t.value};break}}return o},j=({client:r,id:e,initalizer:t,content:n,jsonMetafields:i,nestedContent:d})=>{var o,f;let a=t||{};for(let m=0;m<n.length;m++){let s=n[m];if(s){let c=(f=(o=r.config[s.namespace.replace(`@${r.locale}`,"")])==null?void 0:o.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:d});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},B=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,d;if(n){let a=(d=(i=e.config[n.namespace.replace(`@${e.locale}`,"")])==null?void 0:i.schema)==null?void 0:d[n.key];if(!a)return t;let o=O({field:a,item:n,client:e});t[n.id]=e.adapter(o)}return t},{}),z=(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 J=r=>{let t={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"}[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:[]}),k=()=>({id:y(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:$(),products:[h(),h(),h()]}),D=(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 k()},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?[]:{}),G=(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?D(k):k()};case"image":return{value:r.isList?t?D($):[]:t?{id:y(),...$()}:void 0,attributes:e};case"product":return{attributes:e,value:r.isList?D(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!`};case"boolean":return{attributes:e,value:!0};case"url":return{attributes:e,value:"https://google.com"};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}},H=class{constructor(e,{storefrontName:t,storefrontAccessToken:n,defaultNameSpaces:i},d){this.getMetafieldsByIds=async e=>{var i,d;if(!e.length)return[{},[]];let t=await this.client.request(q(!1,{customProductMetafields:(d=(i=this.params)==null?void 0:i.product)==null?void 0:d.customMetafieldsIdentifiers}),{ids:e});if(!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(!i)return[{},[],[]];let{products:d,collections:a}=i,o=d?u(d):[],f=a?u(a):[],m=o.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),o.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,d],[a,o,f]]=await Promise.all([this.getMetafieldsByIds(V(n)),this.getMetafieldsForProductsAndCollection(e)]),[m]=await this.getMetafieldsByIds(B(n.concat(d).concat(o))),s=j({client:this,content:n,jsonMetafields:m,nestedContent:{...i,...a}});return 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},d)=>{let[a,o]=e.split("."),{kind:f,schema:m}=this.config[a];n&&f==="product"&&(o=`${o}@${n}`),i&&f==="collection"&&(o=`${o}@${i}`);let s=m[o],c=()=>N(this.config[a],`${o}.default`,()=>{let l=J(s),p={itemID:y(),itemType:l,itemProp:`${a}:${o}`},g=G(s,p);return d?d(g,s):g});return N(t,`${a}.${o}`,c)};this.buildIdentifiers=(e,t="fra")=>e?e.reduce((n,i)=>{let d=this.config[i];return d&&Object.keys(d.schema).forEach(a=>{n.push({namespace:`${i}@${t}`,key:a})}),n},[]):[];this.locale="en",this.adapter=d||(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 d=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:o}}=await d.request(A);return await a.request(_,{value:JSON.stringify(r),key:i,ownerId:o})};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.51",
"version": "1.0.52",
"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