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.77 to 1.0.78

26

index.d.ts

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

};
declare type DateContent = {
value: Date;
attributes: ItemAttributes<'date_time'>;
};
declare type UrlContent = {

@@ -170,3 +174,3 @@ value: string;

type: 'date';
default?: string;
default?: Date;
isList?: false;

@@ -216,3 +220,3 @@ };

isList?: true;
} | UrlField | ListField | {
} | UrlField | ListField | DateField | {
type: 'video';

@@ -280,3 +284,3 @@ default?: VideoContent;

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

@@ -291,3 +295,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 'list' ? F extends ListField ? ListContent<F> : never : F['type'] extends 'video' ? toList2<F, VideoContent, VideosContent> : F['type'] extends 'address' ? toList2<F, AddressContent, AddressesContent> : F['type'] extends 'number' ? toList2<F, NumberContent, NumbersContent> : 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 extends DateField ? DateContent : F extends ListField ? ListContent<F> : F['type'] extends 'video' ? toList2<F, VideoContent, VideosContent> : F['type'] extends 'address' ? toList2<F, AddressContent, AddressesContent> : F['type'] extends 'number' ? toList2<F, NumberContent, NumbersContent> : F['type'] extends 'object' ? F extends ObjectField ? F['schema'] extends ModelSchema ? Record<'value', toList2<F, ObjectContent2<F['schema']>>> & {
attributes: ItemAttributes<'json'>;

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

value: string;
} | {
type: 'date_time';
value: string;
});

@@ -459,3 +466,4 @@ declare type MetafieldProduct = {

'url',
'number_decimal'
'number_decimal',
'date_time'
][number];

@@ -499,3 +507,3 @@ declare type metafieldType = simpleMetafieldType | `list.${simpleMetafieldType}`;

adapter: Adapter;
locale?: string;
locale: Locale;
params?: GetContentParams<any, any>;

@@ -516,3 +524,3 @@ constructor(config: S, { storefrontName, storefrontAccessToken, defaultNameSpaces }: MetaCMSConfig<S>, adapter?: Adapter);

}>;
t: <P extends Paths<S>, C extends Content<S>, T>(p: P, content: C, { productId, collectionId }: IdAccessors, transform?: ((data: any, field: Field) => any) | undefined) => T;
t: <P extends Paths<S>, C extends Content<S>, F extends GetField<S, P> = GetField<S, P>>(p: P, content: C, { productId, collectionId }: IdAccessors) => [GetType2<F>, F, Locale];
buildIdentifiers: (namespaces: Namespaces<S>[], locale: Locale) => Identifier[];

@@ -572,3 +580,3 @@ }

declare type variables = {
[key: string]: boolean | string | number;
[key: string]: boolean | string | number | undefined;
};

@@ -578,2 +586,2 @@ declare const mustaching: (string: string, variables?: variables | undefined) => string;

export { Adapter, AddressContent, AddressData, AddressesContent, BooleanContent, CollectionContent, CollectionData, CollectionsContent, ConfigType, Content, DateField, Field, GetConfigType, GetContentParams, GetField, GetType2, GraphqlClient, HTMLContent, HTMLsContent, HumanInfos, IdAccessors, Identifier, ImageContent, ImageData, ImagesContent, ItemAttributes, Last, ListContent, ListField, Locale, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, MetafieldVideo, Model, ModelKind, ModelSchema, Namespaces, NestedContent, Nodes, NumberContent, NumbersContent, ObjectContent2, ObjectField, ObjectSchema, ObjectType, ParamsFetcher, PathForNamespace, Paths, Price, PriceContent, PriceVariation, PriceVariationContent, ProductContent, ProductData, ProductsContent, RequireExactlyOne, RichTextField, Schema, Simplify, Split, TextContent, TextField, TextsContent, UrlContent, UrlField, 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 };
export { Adapter, AddressContent, AddressData, AddressesContent, BooleanContent, CollectionContent, CollectionData, CollectionsContent, ConfigType, Content, DateContent, DateField, Field, GetConfigType, GetContentParams, GetField, GetType2, GraphqlClient, HTMLContent, HTMLsContent, HumanInfos, IdAccessors, Identifier, ImageContent, ImageData, ImagesContent, ItemAttributes, Last, ListContent, ListField, Locale, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, MetafieldVideo, Model, ModelKind, ModelSchema, Namespaces, NestedContent, Nodes, NumberContent, NumbersContent, ObjectContent2, ObjectField, ObjectSchema, ObjectType, ParamsFetcher, PathForNamespace, Paths, Price, PriceContent, PriceVariation, PriceVariationContent, ProductContent, ProductData, ProductsContent, RequireExactlyOne, RichTextField, Schema, Simplify, Split, TextContent, TextField, TextsContent, UrlContent, UrlField, 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, variables, videoFragment };

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

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

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

}
`,ae=`
`,se=`
query {

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

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

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

}
`;var O=t=>`
`;var w=t=>`
id

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

src: url(transform:{maxWidth:4000})
`,L=t=>`
`,E=t=>`
id

@@ -90,3 +90,3 @@ alt

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

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

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

@@ -132,4 +132,4 @@ title

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

@@ -154,6 +154,6 @@ id

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

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

...on Video {
${L(t)}
${E(t)}
}

@@ -172,3 +172,3 @@ }

... on MediaImage {
${O(t)}
${w(t)}
}

@@ -178,3 +178,3 @@ }

...on Video {
${L(t)}
${E(t)}
}

@@ -184,3 +184,3 @@ }

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

@@ -193,3 +193,3 @@ }

}
`,j=(t,e)=>`
`,L=(t,e)=>`
query getContent(

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

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

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

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

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

}`;var m=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,T=({content:t,namespace:e,key:r,id:n,value:s})=>{let c=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[c]:s})},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,s,c)=>`id:${r(n)}${c.length-1>s?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,s,c)=>`handle:${n}${c.length-1>s?" or ":""}`).join("")}`.trim():void 0},S=(t,e,r=[])=>typeof t!="object"?t:(Array.isArray(t)?t:Object.entries(t)).reduce((s,c,o)=>{if(Array.isArray(t))s.push(S(c,e,r.concat(o)));else{let[i,l]=c;Array.isArray(l)?(s[i]=[],l.forEach((f,a)=>s[i].push(S(f,e,r.concat(i).concat(a))))):l&&(l.attributes?s[i]=e(l,r.concat(i)):s[i]=S(l,e,r.concat(i)))}return s},Array.isArray(t)?[]:{});var J=({acc:t,item:e,client:r,locale:n,jsonMetafields:s,nestedContent:c})=>{var f;let o={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},i,l=({id:a,key:d,namespace:u,objectId:p})=>{c&&t&&n&&T({content:t,key:d,id:p,namespace:u.replace(`@${n}`,""),value:c[a]})};switch(e.type){case"collection_reference":{i={attributes:o,value:{...e.collection,products:m(e.collection.products).map(({content:a,...d})=>(a==null||a.forEach(u=>l({...u,objectId:d.id})),{...d,variants:m(d.variants)}))}};break}case"file_reference":{if(!(e!=null&&e.video)&&!(e!=null&&e.image))return{attributes:o};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"),i={attributes:o,value:e.image.image};break}if("video"in e){i={attributes:o,value:e.video};break}}case"product_reference":{let{product:a}=e;(f=a.content)==null||f.forEach(d=>l({...d,objectId:a.id})),i={attributes:o,value:{...a,variants:m(e.product.variants)}};break}case"list.collection_reference":{i={attributes:o,value:m(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(u=>l({...u,objectId:a.id})),{...a,products:m(a.products).map(u=>{var p;return(p=u.content)==null||p.forEach(g=>l({...g,objectId:u.id})),{...u,variants:m(u.variants)}})}})};break}case"list.file_reference":{i={attributes:o,value:m(e.values).map(a=>a.image)};break}case"list.product_reference":{i={attributes:o,value:m(e.values).map(a=>{var d;return(d=a.content)==null||d.forEach(u=>l({...u,objectId:a.id})),{...a,variants:m(a.variants)}})};break}case"json":{let a=JSON.parse(e.value);if(b(r.config,`${e.namespace.split("@")[0]}.schema.${e.key}.type`)==="address")i={attributes:o,value:a};else{let u=K(e.value,s);i={attributes:o,value:u.value||u}}break}case"list.multi_line_text_field":case"list.single_line_text_field":{i={attributes:o,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{i={attributes:o,value:e.value||""};break}case"boolean":{i={attributes:o,value:e.value==="true"};break}case"number_decimal":{i={attributes:o,value:Number(e.value)};break}case"list.number_decimal":{i={attributes:o,value:JSON.parse(e.value,(a,d)=>Number(d))};break}case"url":{i={attributes:o,value:e.value};break}}return i},Q=({client:t,id:e,initalizer:r,content:n,jsonMetafields:s,nestedContent:c})=>{var i,l;let o=r||{};for(let f=0;f<n.length;f++){let a=n[f];if(a){if(!((l=(i=t.config[a.namespace.replace(`@${t.locale}`,"")])==null?void 0:i.schema)==null?void 0:l[a.key]))return o;let u=J({client:t,acc:o,item:a,jsonMetafields:s,nestedContent:c});T({content:o,key:a.key,namespace:a.namespace.replace(`@${t.locale}`,""),value:u})}}return o};var ce=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(s=>{I(s)&&e.push(s)}):I(n)&&e.push(n),n)),e},G=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(ce(r.value)))}),e},k=(t,e)=>t.reduce((r,n)=>{if(n){let s=J({item:n,client:e});r[n.id]=e.adapter(s)}return r},{}),K=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(s=>I(s)?e[s]:s):I(n)?e[n]:n):JSON.parse(t);var z=t=>{let r={text:"multi_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:"single_line_text_field",list:"single_line_text_field",number:"number_decimal",address:"json"}[t.type];return t.isList&&r!=="json"?`list.${r}`:r},x=(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:x(),compareAtPriceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},priceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},variants:[]}),_=()=>({id:y(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:x(),products:[h(),h(),h()]}),H=(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 x();if(t==="product")return h();if(t==="collection")return _()},V=(t,e=!0)=>Object.entries(t.schema).reduce((r,[n,s])=>(s.isList?s.type==="object"?r[n]=V(s,!1):r[n]=[]:s.type==="object"?r[n]=V(s,!1):r[n]=le(s.type),r),t.type==="object"&&e?{}:t.isList?[]:{}),A=(t,e,r=!0,n)=>{switch(t.type){case"object":return t.isList?{attributes:e,value:[]}:{attributes:e,value:V(t)};case"collection":return{attributes:e,value:t.isList?H(_):_()};case"image":return{value:t.isList?r?H(x):[]:r?{id:y(),...x()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?H(h):h()};case"richtext":return{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||`<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"};case"list":return{attributes:e,value:t.options[0].value};case"number":return{attributes:e,value:Math.random()};default:case"text":return console.log({defaultValue:n}),{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||"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:s}=await n.json();return s}else throw new Error(await n.text())};this.url=e,this.headers=r}},W=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:s},c){this.getMetafieldsByIds=async e=>{var s,c;if(!e.length)return[{},[]];let r=await this.client.request(q(!1,{customProductMetafields:(c=(s=this.params)==null?void 0:s.product)==null?void 0:c.customMetafieldsIdentifiers}),{ids:e});if(!r)return[{},[]];let{metafields:n}=r;return[k(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 s=await this.client.request(D({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(!s)return[{},[],[]];let{products:c,collections:o}=s,i=c?m(c):[],l=o?m(o):[],f=i.map(N=>N.content).flat(),a=l.map(N=>N.content).flat(),d=k(f,this),u=k(a,this);return[{...d,...u},f.concat(a),i.concat(l)]};this.getContentForNamespaces=async e=>{var a,d,u;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(j(!0,{customProductMetafields:(a=e.product)==null?void 0:a.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((d=e.product)==null?void 0:d.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)});console.log({content:r});let[[n,s],[c,o,i]]=await Promise.all([this.getMetafieldsByIds(B(r)),this.getMetafieldsForProductsAndCollection(e)]),[l]=await this.getMetafieldsByIds(G(r.concat(s).concat(o)));console.log({jsonMetafields:l},G(r));let f=Q({client:this,content:r,jsonMetafields:l,nestedContent:{...n,...c}});return i.forEach(({id:p,content:g})=>{Q({client:this,initalizer:f,id:p,content:g,jsonMetafields:l,nestedContent:{...n,...c}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:f}};this.t=(e,r,{productId:n,collectionId:s},c)=>{let[o,i]=e.split("."),{kind:l,schema:f}=this.config[o];n&&l==="product"&&(i=`${i}@${n}`),s&&l==="collection"&&(i=`${i}@${s}`);let a=f[i],d=()=>{let u=z(a),p={itemID:y(),itemType:u,itemProp:`${o}:${i}`},g=this.config[o].schema[i].default;return c?c(A(a,p,!0,g),a):A(a,p,!0,g)};return b(r,`${o}.${i}`,d)};this.buildIdentifiers=(e,r)=>e?e.reduce((n,s)=>{let c=this.config[s];return c&&Object.keys(c.schema).forEach(o=>{n.push({namespace:`${s}@${r}`,key:o})}),n},[]):[];this.locale="en",this.adapter=c||(o=>o),this.config=e,this.defaultNameSpaces=s||[],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},s)=>{console.log(s);let c=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:i}}=await c.request(E);return await o.request(w,{value:JSON.stringify(t),key:s,ownerId:i})};var X=/{{([\:\/\-\\\,\.a-zA-Z0-9\s])*}}/g,Z=(t,e)=>(e&&Object.keys(e).forEach(r=>{t=t.replace(new RegExp(`{{${r}}}`,"g"),String(e[r]))}),t.replace(X,"")),Y=/\(\(([\:\/\-\\\,\s\u0030-\u4351\u4e00-\u9fa5])*\)\)/g,ue=(t,e)=>{if(!e)return t;let r=t.matchAll(Y);return Array.from(r).forEach(n=>{let[s]=n,[c,o,i]=s.replace("((","").replace("))","").split(","),l=typeof e[c]=="number"?e[c]>1:!!e[c];i?l===!0?t=t.replace(s,i.trim()):t=t.replace(s,o.trim()):l===!0?(i=o,t=t.replace(s,i.trim())):t=t.replace(Y,"")}),t},fe=(t,e)=>ue(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});
}`;var m=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),ie=t=>t,g=()=>{let t="meta-cms-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",e="",r=10;for(;r--;)e+=t[Math.random()*t.length|0];return`meta-cms-${e}`},x=t=>typeof t=="string"?t.startsWith("gid://shopify/Metafield/"):!1,S=({content:t,namespace:e,key:r,id:n,value:a})=>{let c=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[c]:a})},T=({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,a,c)=>`id:${r(n)}${c.length-1>a?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,a,c)=>`handle:${n}${c.length-1>a?" or ":""}`).join("")}`.trim():void 0},b=(t,e,r=[])=>typeof t!="object"?t:(Array.isArray(t)?t:Object.entries(t)).reduce((a,c,i)=>{if(Array.isArray(t))a.push(b(c,e,r.concat(i)));else{let[o,l]=c;Array.isArray(l)?(a[o]=[],l.forEach((f,s)=>a[o].push(b(f,e,r.concat(o).concat(s))))):l&&(l.attributes?a[o]=e(l,r.concat(o)):a[o]=b(l,e,r.concat(o)))}return a},Array.isArray(t)?[]:{});var D=({acc:t,item:e,client:r,locale:n,jsonMetafields:a,nestedContent:c})=>{var f;let i={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},o,l=({id:s,key:d,namespace:u,objectId:p})=>{c&&t&&n&&S({content:t,key:d,id:p,namespace:u.replace(`@${n}`,""),value:c[s]})};switch(e.type){case"collection_reference":{o={attributes:i,value:{...e.collection,products:m(e.collection.products).map(({content:s,...d})=>(s==null||s.forEach(u=>l({...u,objectId:d.id})),{...d,variants:m(d.variants)}))}};break}case"file_reference":{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:i,value:e.image.image};break}if("video"in e){o={attributes:i,value:e.video};break}break}case"product_reference":{let{product:s}=e;(f=s.content)==null||f.forEach(d=>l({...d,objectId:s.id})),o={attributes:i,value:{...s,variants:m(e.product.variants)}};break}case"list.collection_reference":{o={attributes:i,value:m(e.values).map(s=>{var d;return(d=s.content)==null||d.forEach(u=>l({...u,objectId:s.id})),{...s,products:m(s.products).map(u=>{var p;return(p=u.content)==null||p.forEach(C=>l({...C,objectId:u.id})),{...u,variants:m(u.variants)}})}})};break}case"list.file_reference":{o={attributes:i,value:m(e.values).map(s=>{if("image"in s)return s.image;if("video"in s)return s})};break}case"list.product_reference":{o={attributes:i,value:m(e.values).map(s=>{var d;return(d=s.content)==null||d.forEach(u=>l({...u,objectId:s.id})),{...s,variants:m(s.variants)}})};break}case"json":{let s=JSON.parse(e.value);if(s.country&&s.address&&s.locality&&s.postal_code)o={attributes:i,value:s};else{let d=U(e.value,a);o={attributes:i,value:d.value||d}}break}case"list.multi_line_text_field":case"list.single_line_text_field":{o={attributes:i,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{o={attributes:i,value:e.value||""};break}case"boolean":{o={attributes:i,value:e.value==="true"};break}case"number_decimal":{o={attributes:i,value:Number(e.value)};break}case"list.number_decimal":{o={attributes:i,value:JSON.parse(e.value,(s,d)=>Number(d))};break}case"url":{o={attributes:i,value:e.value};break}case"date_time":{o={attributes:i,value:(()=>{try{return new Date(e.value)}catch{return new Date}})()};break}}return o},q=({client:t,id:e,initalizer:r,content:n,jsonMetafields:a,nestedContent:c})=>{var o,l;let i=r||{};for(let f=0;f<n.length;f++){let s=n[f];if(s){if(!((l=(o=t.config[s.namespace.replace(`@${t.locale}`,"")])==null?void 0:o.schema)==null?void 0:l[s.key]))return i;let u=D({client:t,acc:i,item:s,jsonMetafields:a,nestedContent:c});S({content:i,key:s.key,namespace:s.namespace.replace(`@${t.locale}`,""),value:u})}}return i};var oe=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(a=>{x(a)&&e.push(a)}):x(n)&&e.push(n),n)),e},G=t=>{let e=[];return t.forEach(r=>{!r||r.type==="json"&&(e=e.concat(oe(r.value)))}),e},P=(t,e)=>t.reduce((r,n)=>(n&&(r[n.id]=D({item:n,client:e})),r),{}),U=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(a=>x(a)?e[a]:a):x(n)?e[n]:n):JSON.parse(t);var Q=t=>{let r={text:"multi_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:"single_line_text_field",list:"single_line_text_field",number:"number_decimal",address:"json",date:"date_time"}[t.type];return t.isList&&r!=="json"?`list.${r}`:r},I=(t=400,e=300)=>({alt:"image",src:`https://picsum.photos/${t}/${e}`,width:t,height:e}),y=()=>({id:g(),descriptionHtml:"Lorem ipsum",title:"Lorem ipsum",handle:"",featuredImage:I(),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:g(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:I(),products:[y(),y(),y()]}),V=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r},ce=t=>{if(t==="text"||t==="richtext")return"Lorem ipsum";if(t==="image")return I();if(t==="product")return y();if(t==="collection")return k()},J=(t,e=!0)=>Object.entries(t.schema).reduce((r,[n,a])=>(a.isList?a.type==="object"?r[n]=J(a,!1):r[n]=[]:a.type==="object"?r[n]=J(a,!1):r[n]=ce(a.type),r),t.type==="object"&&e?{}:t.isList?[]:{}),H=(t,e,r=!0,n)=>{switch(t.type){case"object":return t.isList?{attributes:e,value:[]}:{attributes:e,value:J(t)};case"collection":return{attributes:e,value:t.isList?V(k):k()};case"image":return{value:t.isList?r?V(I):[]:r?{id:g(),...I()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?V(y):y()};case"richtext":return{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||`<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"};case"list":return{attributes:e,value:t.options[0].value};case"number":return{attributes:e,value:Math.random()};case"date":return{attributes:e,value:new Date};default:case"text":return console.log({defaultValue:n}),{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||"Lorem ipsum dolor sit amet consectetur adipisicing elit."}}};var h=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:a}=await n.json();return a}else throw new Error(await n.text())};this.url=e,this.headers=r}},z=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:a},c){this.getMetafieldsByIds=async e=>{var a,c;if(!e.length)return[{},[]];let r=await this.client.request(O(!1,{customProductMetafields:(c=(a=this.params)==null?void 0:a.product)==null?void 0:c.customMetafieldsIdentifiers}),{ids:e});if(!r)return[{},[]];let{metafields:n}=r;return[P(n,this),n]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:r,locale:n})=>{var p,C;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 a=await this.client.request(R({collectionQuery:T({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:T({ids:r==null?void 0:r.ids,handles:r==null?void 0:r.handles})},{customProductMetafields:(C=(p=this.params)==null?void 0:p.product)==null?void 0:C.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers((r==null?void 0:r.namespaces)||[],n),collectionIdentifiers:this.buildIdentifiers((e==null?void 0:e.namespaces)||[],n)});if(!a)return[{},[],[]];let{products:c,collections:i}=a,o=c?m(c):[],l=i?m(i):[],f=o.map(_=>_.content).flat(),s=l.map(_=>_.content).flat(),d=P(f,this),u=P(s,this);return[{...d,...u},f.concat(s),o.concat(l)]};this.getContentForNamespaces=async e=>{var s,d,u;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(L(!0,{customProductMetafields:(s=e.product)==null?void 0:s.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((d=e.product)==null?void 0:d.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)});console.log({content:r});let[[n,a],[c,i,o]]=await Promise.all([this.getMetafieldsByIds(W(r)),this.getMetafieldsForProductsAndCollection(e)]),[l]=await this.getMetafieldsByIds(G(r.concat(a).concat(i)));console.log({jsonMetafields:l},G(r));let f=q({client:this,content:r,jsonMetafields:l,nestedContent:{...n,...c}});return o.forEach(({id:p,content:C})=>{q({client:this,initalizer:f,id:p,content:C,jsonMetafields:l,nestedContent:{...n,...c}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:f}};this.t=(e,r,{productId:n,collectionId:a})=>{let[c,i]=e.split("."),{kind:o,schema:l}=this.config[c];n&&o==="product"&&(i=`${i}@${n}`),a&&o==="collection"&&(i=`${i}@${a}`);let f=l[i],s=()=>{let d=Q(f),u={itemID:g(),itemType:d,itemProp:`${c}:${i}`},p=this.config[c].schema[i].default;return H(f,u,!0,p)};if(!(c in r))throw new Error(`Namespace "${c}" not found in content. Make sure you have added it to namespaces of the page you are trying to load.`);return[r[c][i]||s(),f,this.locale]};this.buildIdentifiers=(e,r)=>e?e.reduce((n,a)=>{let c=this.config[a];return c&&Object.keys(c.schema).forEach(i=>{n.push({namespace:`${a}@${r}`,key:i})}),n},[]):[];this.locale="en",this.adapter=c||(i=>i),this.config=e,this.defaultNameSpaces=a||[],this.client=new h(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var le=async(t,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:n},a)=>{console.log(a);let c=new h(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}),i=new h(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":n}),{shop:{id:o}}=await c.request(N);return await i.request(A,{value:JSON.stringify(t),key:a,ownerId:o})};var K=/{{([\:\/\-\\\,\.a-zA-Z0-9\s])*}}/g,Y=(t,e)=>(e&&Object.keys(e).forEach(r=>{t=t.replace(new RegExp(`{{${r}}}`,"g"),String(e[r]))}),t.replace(K,"")),X=/\(\(([\:\/\-\\\,\s\u0030-\u4351\u4e00-\u9fa5])*\)\)/g,de=(t,e)=>{if(!e)return t;let r=t.matchAll(X);return Array.from(r).forEach(n=>{let[a]=n,[c,i,o]=a.replace("((","").replace("))","").split(","),l=typeof e[c]=="number"?Number(e[c])>1:!!e[c];o?l===!0?t=t.replace(a,o.trim()):t=t.replace(a,i.trim()):l===!0?(o=i,t=t.replace(a,o.trim())):t=t.replace(X,"")}),t},ue=(t,e)=>de(Y(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.77",
"version": "1.0.78",
"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