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.53 to 1.0.54

10

index.d.ts

@@ -359,4 +359,6 @@ import { Get } from 'type-fest';

collection?: ParamsFetcher<S, P, 'collection'>;
locale: Locale;
};
declare type Adapter = <D extends GetType2<any>>(value: D) => any;
declare type Locale = 'bg' | 'cs' | 'da' | 'de' | 'el' | 'en' | 'en-gb' | 'en-us' | 'es' | 'et' | 'fi' | 'fr' | 'hu' | 'id' | 'it' | 'ja' | 'lt' | 'lv' | 'nl' | 'pl' | 'pt' | 'pt-br' | 'pt-pt' | 'ro' | 'ru' | 'sk' | 'sl' | 'sv' | 'tr' | 'uk' | 'zh';

@@ -378,3 +380,3 @@ declare class GraphqlClient {

getMetafieldsByIds: (ids: string[]) => Promise<[Record<string, MetafieldContent>, MetafieldContent[]]>;
getMetafieldsForProductsAndCollection: <P extends GetContentParams<S, P>>({ collection, product }: P, locale?: 'fra') => Promise<[
getMetafieldsForProductsAndCollection: <P extends GetContentParams<S, P>>({ collection, product, locale }: P) => Promise<[
Record<string, MetafieldContent>,

@@ -387,3 +389,3 @@ MetafieldContent[],

]>;
getContentForNamespaces: <P extends GetContentParams<S, P>>(params: P, locale?: 'fra') => Promise<{
getContentForNamespaces: <P extends GetContentParams<S, P>>(params: P) => Promise<{
content: Content<S>;

@@ -393,3 +395,3 @@ params: P;

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;
buildIdentifiers: (namespaces: Namespaces<S>[], locale?: 'fra') => Identifier[];
buildIdentifiers: (namespaces: Namespaces<S>[], locale: Locale) => Identifier[];
}

@@ -445,2 +447,2 @@

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 };
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 };

46

index.js

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

"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 _=`
"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:()=>P,collectionFragment:()=>L,config:()=>re,contentQuery:()=>w,fieldToMetafieldType:()=>J,getLoremCollectionData:()=>v,getLoremImageData:()=>$,getLoremProductData:()=>h,getMetaCMSConfigQuery:()=>te,getOwnerIdQuery:()=>A,imageFragment:()=>M,isId:()=>I,mediaImageFragment:()=>E,metafieldFragment:()=>x,metafieldsForNodes:()=>q,metafieldsQuery:()=>R,mockValue:()=>G,normalizeEdges:()=>u,productFragment:()=>S,randomId:()=>y,setInNamespace:()=>T,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!) {

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

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

@@ -35,3 +35,3 @@ height

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

@@ -53,3 +53,3 @@ descriptionHtml

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

@@ -80,3 +80,3 @@ price {

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

@@ -103,3 +103,3 @@ compareAtPriceRange {

}
`,w=(r,e)=>`
`,L=(r,e)=>`
id

@@ -110,3 +110,3 @@ title

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

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

node {
${T(r,e)}
${S(r,e)}
}

@@ -128,3 +128,3 @@ }

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

@@ -146,6 +146,6 @@ value

... on Collection {
${w(r,e)}
${L(r,e)}
}
... on Product {
${T(r,e)}
${S(r,e)}
}

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

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

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

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

@@ -180,15 +180,15 @@ $identifiers: [HasMetafieldsIdentifier!]!

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

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

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

@@ -217,3 +217,3 @@ }

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

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

}`;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});
}`;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,T=({content:r,namespace:e,key:t,id:n,value:i})=>{let c=n?`${t}@${n}`:t;r[e]||Object.assign(r,{[e]:{}}),Object.assign(r[e],{[c]:i})},P=({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,c)=>`id:${t(n)}${c.length-1>i?" or ":r!=null&&r.length?" or":""}`).join("")} ${(r||[]).map((n,i,c)=>`handle:${n}${c.length-1>i?" or ":""}`).join("")}`.trim():void 0};var O=({field:r,acc:e,item:t,locale:n,jsonMetafields:i,nestedContent:c})=>{var m;let a={itemID:t.id,itemType:t.type,itemProp:`${t.namespace}:${t.key}`},o,f=({id:s,key:d,namespace:l,objectId:p})=>{c&&e&&n&&T({content:e,key:d,id:p,namespace:l.replace(`@${n}`,""),value:c[s]})};switch(t.type){case"collection_reference":{o={attributes:a,value:{...t.collection,products:u(t.collection.products).map(({content:s,...d})=>(s==null||s.forEach(l=>f({...l,objectId:d.id})),{...d,variants:u(d.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(d=>f({...d,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 d;return(d=s.content)==null||d.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 d;return(d=s.content)==null||d.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:c})=>{var o,f;let a=t||{};for(let m=0;m<n.length;m++){let s=n[m];if(s){let d=(f=(o=r.config[s.namespace.replace(`@${r.locale}`,"")])==null?void 0:o.schema)==null?void 0:f[s.key];if(!d)return a;let l=O({client:r,field:d,acc:a,item:s,jsonMetafields:i,nestedContent:c});T({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},b=(r,e)=>r.reduce((t,n)=>{var i,c;if(n){let a=(c=(i=e.config[n.namespace.replace(`@${e.locale}`,"")])==null?void 0:i.schema)==null?void 0:c[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:[]}),v=()=>({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 v()},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(v):v()};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},c){this.getMetafieldsByIds=async e=>{var i,c;if(!e.length)return[{},[]];let t=await this.client.request(R(!1,{customProductMetafields:(c=(i=this.params)==null?void 0:i.product)==null?void 0:c.customMetafieldsIdentifiers}),{ids:e});if(!t)return[{},[]];let{metafields:n}=t;return[b(n,this),n]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:t,locale:n})=>{var p,g;if(!(e!=null&&e.ids)&&!(e!=null&&e.handles)&&!(e!=null&&e.namespaces)&&!(t!=null&&t.ids)&&!(t!=null&&t.handles)&&!(t!=null&&t.namespaces))return[{},[],[]];let i=await this.client.request(q({collectionQuery:P({ids:e==null?void 0:e.ids,handles:e==null?void 0:e.handles}),productQuery:P({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:c,collections:a}=i,o=c?u(c):[],f=a?u(a):[],m=o.map(k=>k.content).flat(),s=f.map(k=>k.content).flat(),d=b(m,this),l=b(s,this);return[{...d,...l},m.concat(s),o.concat(f)]};this.getContentForNamespaces=async e=>{var s,d,l;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let{shop:{content:t}}=await this.client.request(w(!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(((l=e.collection)==null?void 0:l.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)}),[[n,i],[c,a,o]]=await Promise.all([this.getMetafieldsByIds(V(t)),this.getMetafieldsForProductsAndCollection(e)]),[f]=await this.getMetafieldsByIds(B(t.concat(i).concat(a))),m=j({client:this,content:t,jsonMetafields:f,nestedContent:{...n,...c}});return o.forEach(({id:p,content:g})=>{j({client:this,initalizer:m,id:p,content:g,jsonMetafields:f,nestedContent:{...n,...c}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:m}};this.t=(e,t,{productId:n,collectionId:i},c)=>{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],d=()=>N(this.config[a],`${o}.default`,()=>{let l=J(s),p={itemID:y(),itemType:l,itemProp:`${a}:${o}`},g=G(s,p);return c?c(g,s):g});return N(t,`${a}.${o}`,d)};this.buildIdentifiers=(e,t)=>e?e.reduce((n,i)=>{let c=this.config[i];return c&&Object.keys(c.schema).forEach(a=>{n.push({namespace:`${i}@${t}`,key:a})}),n},[]):[];this.locale="en",this.adapter=c||(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 c=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 c.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.53",
"version": "1.0.54",
"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