@meta-cms/core
Advanced tools
Comparing version 1.0.89 to 1.0.90
162
index.d.ts
import { Get } from 'type-fest'; | ||
declare type Simplify<S extends Model | Schema> = { | ||
type Simplify<S extends Model | Schema> = { | ||
[K in keyof S]: Get<S[K], 'config'> extends Model ? keyof Get<S[K], 'config'> : never; | ||
}; | ||
declare type Namespaces<S extends Schema, T extends ModelKind | undefined = undefined> = { | ||
type Namespaces<S extends Schema, T extends ModelKind | undefined = undefined> = { | ||
[K in keyof S]: T extends undefined ? (K extends string ? K : never) : S[K]['kind'] extends T ? (K extends string ? K : never) : never; | ||
}[keyof S]; | ||
declare type Paths<S extends Schema> = NonNullable<{ | ||
type Paths<S extends Schema> = NonNullable<{ | ||
[K in Namespaces<S>]: keyof S[K]['schema'] extends string ? `${K}.${keyof S[K]['schema']}` : 'never'; | ||
}[Namespaces<S>]>; | ||
declare type Split<S extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}.${infer U}` ? [T, ...Split<U>] : [S]; | ||
declare type Last<S extends string> = S extends `${infer T}.${infer U}` ? U : S extends `${infer T}.${infer U}.${infer V}` ? `${U}.${V}` : never; | ||
declare type ImageContent = { | ||
type Split<S extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}.${infer U}` ? [T, ...Split<U>] : [S]; | ||
type Last<S extends string> = S extends `${infer T}.${infer U}` ? U : S extends `${infer T}.${infer U}.${infer V}` ? `${U}.${V}` : never; | ||
type ImageContent = { | ||
value: { | ||
@@ -24,28 +24,28 @@ id: string; | ||
}; | ||
declare type ImageData = Omit<ImageContent['value'], 'id'>; | ||
declare type ImagesContent = { | ||
type ImageData = Omit<ImageContent['value'], 'id'>; | ||
type ImagesContent = { | ||
attributes: ItemAttributes<'list.file_reference'>; | ||
value: ImageData[]; | ||
}; | ||
declare type TextContent = { | ||
type TextContent = { | ||
value: string; | ||
attributes: ItemAttributes<'single_line_text_field' | 'multi_line_text_field'>; | ||
}; | ||
declare type DateContent = { | ||
type DateContent = { | ||
value: Date; | ||
attributes: ItemAttributes<'date_time'>; | ||
}; | ||
declare type UrlContent = { | ||
type UrlContent = { | ||
value: string; | ||
attributes: ItemAttributes<'url'>; | ||
}; | ||
declare type NumberContent = { | ||
type NumberContent = { | ||
value: number; | ||
attributes: ItemAttributes<'number_decimal'>; | ||
}; | ||
declare type NumbersContent = { | ||
type NumbersContent = { | ||
value: number[]; | ||
attributes: ItemAttributes<'number_decimal'>; | ||
}; | ||
declare type AddressData = { | ||
type AddressData = { | ||
lat: number; | ||
@@ -64,27 +64,27 @@ lng: number; | ||
}; | ||
declare type AddressContent = { | ||
type AddressContent = { | ||
value: AddressData; | ||
attributes: ItemAttributes<'json'>; | ||
}; | ||
declare type AddressesContent = { | ||
type AddressesContent = { | ||
value: AddressData[]; | ||
attributes: ItemAttributes<'json'>; | ||
}; | ||
declare type ListContent<F extends ListField> = { | ||
type ListContent<F extends ListField> = { | ||
value: F['options'][number]['value']; | ||
attributes: ItemAttributes<'single_line_text_field'>; | ||
}; | ||
declare type TextsContent = { | ||
type TextsContent = { | ||
value: string[]; | ||
attributes: ItemAttributes<'list.single_line_text_field'>; | ||
}; | ||
declare type HTMLContent = { | ||
type HTMLContent = { | ||
value: string; | ||
attributes: ItemAttributes<'multi_line_text_field'>; | ||
}; | ||
declare type HTMLsContent = { | ||
type HTMLsContent = { | ||
attributes: ItemAttributes<'list.multi_line_text_field'>; | ||
value: string[]; | ||
}; | ||
declare type VariantContent = { | ||
type VariantContent = { | ||
id: string; | ||
@@ -106,3 +106,3 @@ availableForSale: boolean; | ||
}; | ||
declare type ProductData = { | ||
type ProductData = { | ||
id: string; | ||
@@ -117,32 +117,32 @@ descriptionHtml: string; | ||
}; | ||
declare type ProductContent = { | ||
type ProductContent = { | ||
value: ProductData; | ||
attributes: ItemAttributes<'product_reference'>; | ||
}; | ||
declare type VideoData = MetafieldVideo; | ||
declare type VideoContent = { | ||
type VideoData = MetafieldVideo; | ||
type VideoContent = { | ||
value: VideoData; | ||
attributes: ItemAttributes<'file_reference'>; | ||
}; | ||
declare type VideosContent = { | ||
type VideosContent = { | ||
value: VideoData[]; | ||
attributes: ItemAttributes<'file_reference'>; | ||
}; | ||
declare type BooleanContent = { | ||
type BooleanContent = { | ||
value: boolean; | ||
attributes: ItemAttributes<'boolean'>; | ||
}; | ||
declare type ProductsContent = { | ||
type ProductsContent = { | ||
attributes: ItemAttributes<'list.product_reference'>; | ||
value: ProductData[]; | ||
}; | ||
declare type PriceVariationContent = { | ||
type PriceVariationContent = { | ||
maxVariantPrice: PriceContent; | ||
minVariantPrice: PriceContent; | ||
}; | ||
declare type PriceContent = { | ||
type PriceContent = { | ||
amount: string; | ||
currencyCode: string; | ||
}; | ||
declare type CollectionData = { | ||
type CollectionData = { | ||
id: string; | ||
@@ -155,11 +155,11 @@ title: string; | ||
}; | ||
declare type CollectionContent = { | ||
type CollectionContent = { | ||
value: CollectionData; | ||
attributes: ItemAttributes<'collection_reference'>; | ||
}; | ||
declare type CollectionsContent = { | ||
type CollectionsContent = { | ||
attributes: ItemAttributes<'list.collection_reference'>; | ||
value: CollectionData[]; | ||
}; | ||
declare type ObjectField = { | ||
type ObjectField = { | ||
type: 'object'; | ||
@@ -170,3 +170,3 @@ default?: any; | ||
}; | ||
declare type TextField = { | ||
type TextField = { | ||
type: 'text'; | ||
@@ -177,3 +177,3 @@ default?: string; | ||
}; | ||
declare type DateField = { | ||
type DateField = { | ||
type: 'date'; | ||
@@ -183,3 +183,3 @@ default?: Date; | ||
}; | ||
declare type RichTextField = { | ||
type RichTextField = { | ||
type: 'richtext'; | ||
@@ -190,3 +190,3 @@ default?: string; | ||
}; | ||
declare type UrlField = { | ||
type UrlField = { | ||
type: 'url'; | ||
@@ -196,3 +196,3 @@ default?: UrlContent; | ||
}; | ||
declare type ListField = { | ||
type ListField = { | ||
type: 'list'; | ||
@@ -206,3 +206,3 @@ default?: string; | ||
}; | ||
declare type HumanInfos = { | ||
type HumanInfos = { | ||
order?: number; | ||
@@ -213,11 +213,11 @@ displayName?: string; | ||
}; | ||
declare type ModelKind = 'global' | 'product' | 'collection' | 'page'; | ||
declare type ObjectType = Field['type']; | ||
declare type Schema = Record<string, Model>; | ||
declare type ModelSchema = Record<string, Field>; | ||
declare type Model = HumanInfos & { | ||
type ModelKind = 'global' | 'product' | 'collection' | 'page'; | ||
type ObjectType = Field['type']; | ||
type Schema = Record<string, Model>; | ||
type ModelSchema = Record<string, Field>; | ||
type Model = HumanInfos & { | ||
kind: ModelKind; | ||
schema: ModelSchema; | ||
}; | ||
declare type Field = HumanInfos & (ObjectField | { | ||
type Field = HumanInfos & (ObjectField | { | ||
type: 'product'; | ||
@@ -283,3 +283,3 @@ default?: ProductContent; | ||
}); | ||
declare type Content<S extends Schema> = { | ||
type Content<S extends Schema> = { | ||
[N in Namespaces<S>]: { | ||
@@ -289,3 +289,3 @@ [P in PathForNamespace<S, N, Paths<S>>]: `${N}.${P}` extends Paths<S> ? GetType2<GetField<S, `${N}.${P}`>> : never; | ||
}; | ||
declare type IdAccessors = { | ||
type IdAccessors = { | ||
productId?: string; | ||
@@ -295,21 +295,21 @@ collectionId?: string; | ||
}; | ||
declare type ConfigType = 'json' | 'file' | 'product' | 'collection' | 'object' | 'url' | 'boolean' | 'video' | 'number' | 'address' | '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; | ||
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 isList<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]]['isList'] : never; | ||
declare type toList<S extends Schema, P extends Paths<S>, T, TS = undefined> = isList<S, P> extends true ? (TS extends undefined ? T[] : TS) : T; | ||
declare type toList2<F extends Field, T, TS = undefined> = F['isList'] extends true ? (TS extends undefined ? T[] : TS) : T; | ||
declare type ObjectSchema<S extends Schema, P extends Paths<S>> = Split<P>[0] extends keyof S ? Split<P>[1] extends keyof S[Split<P>[0]]['schema'] ? S[Split<P>[0]]['schema'][Split<P>[1]] : never : never; | ||
declare type ObjectContent2<O extends ModelSchema> = { | ||
type ConfigType = 'json' | 'file' | 'product' | 'collection' | 'object' | 'url' | 'boolean' | 'video' | 'number' | 'address' | 'date'; | ||
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; | ||
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; | ||
type isList<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]]['isList'] : never; | ||
type toList<S extends Schema, P extends Paths<S>, T, TS = undefined> = isList<S, P> extends true ? (TS extends undefined ? T[] : TS) : T; | ||
type toList2<F extends Field, T, TS = undefined> = F['isList'] extends true ? (TS extends undefined ? T[] : TS) : T; | ||
type ObjectSchema<S extends Schema, P extends Paths<S>> = Split<P>[0] extends keyof S ? Split<P>[1] extends keyof S[Split<P>[0]]['schema'] ? S[Split<P>[0]]['schema'][Split<P>[1]] : never : never; | ||
type ObjectContent2<O extends ModelSchema> = { | ||
[K in keyof O]: O[K] extends ObjectField ? ObjectContent2<O[K]['schema']> : O[K] extends Field ? GetType2<O[K]> : 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 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']>>> & { | ||
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'>; | ||
} : never : never : toList2<F, ImageContent, ImagesContent>; | ||
declare type PathForNamespace<S extends Schema, N extends Namespaces<S>, V extends String> = V extends `${infer T}.${infer U}` ? T extends N ? U : V extends `${infer T}.${infer U}.${infer V}` ? `${U}.${V}` : never : never; | ||
declare type Identifier = { | ||
type PathForNamespace<S extends Schema, N extends Namespaces<S>, V extends String> = V extends `${infer T}.${infer U}` ? T extends N ? U : V extends `${infer T}.${infer U}.${infer V}` ? `${U}.${V}` : never : never; | ||
type Identifier = { | ||
namespace: string; | ||
key: string; | ||
}; | ||
declare type MetaCMSConfig<S extends Schema> = { | ||
type MetaCMSConfig<S extends Schema> = { | ||
storefrontName: string; | ||
@@ -319,3 +319,3 @@ storefrontAccessToken: string; | ||
}; | ||
declare type NestedContent = { | ||
type NestedContent = { | ||
id: string; | ||
@@ -325,3 +325,3 @@ namespace: string; | ||
}; | ||
declare type MetafieldContent = { | ||
type MetafieldContent = { | ||
key: string; | ||
@@ -388,3 +388,3 @@ displayName?: string; | ||
}); | ||
declare type MetafieldProduct = { | ||
type MetafieldProduct = { | ||
id: string; | ||
@@ -404,11 +404,11 @@ descriptionHtml: string; | ||
}; | ||
declare type PriceVariation = { | ||
type PriceVariation = { | ||
maxVariantPrice: Price; | ||
minVariantPrice: Price; | ||
}; | ||
declare type Price = { | ||
type Price = { | ||
amount: string; | ||
currencyCode: string; | ||
}; | ||
declare type MetafieldCollection = { | ||
type MetafieldCollection = { | ||
id: string; | ||
@@ -426,3 +426,3 @@ title: string; | ||
}; | ||
declare type MetafieldVariant = { | ||
type MetafieldVariant = { | ||
id: string; | ||
@@ -444,3 +444,3 @@ availableForSale: boolean; | ||
}; | ||
declare type MetafieldImage = { | ||
type MetafieldImage = { | ||
image: { | ||
@@ -453,3 +453,3 @@ alt: string; | ||
}; | ||
declare type MetafieldVideo = { | ||
type MetafieldVideo = { | ||
id: string; | ||
@@ -467,3 +467,3 @@ alt: string; | ||
}; | ||
declare type WithEdge<T extends WithEdge<T>> = { | ||
type WithEdge<T extends WithEdge<T>> = { | ||
edges: { | ||
@@ -473,4 +473,4 @@ node: T['edges'][number]['node']; | ||
}; | ||
declare type Nodes<T extends WithEdge<T>> = T['edges'][number]['node'][]; | ||
declare type simpleMetafieldType = [ | ||
type Nodes<T extends WithEdge<T>> = T['edges'][number]['node'][]; | ||
type simpleMetafieldType = [ | ||
'collection_reference', | ||
@@ -487,4 +487,4 @@ 'file_reference', | ||
][number]; | ||
declare type metafieldType = simpleMetafieldType | `list.${simpleMetafieldType}`; | ||
declare type ItemAttributes<T extends metafieldType = metafieldType> = { | ||
type metafieldType = simpleMetafieldType | `list.${simpleMetafieldType}`; | ||
type ItemAttributes<T extends metafieldType = metafieldType> = { | ||
itemID: string; | ||
@@ -494,6 +494,6 @@ itemType: T; | ||
}; | ||
declare type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = { | ||
type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = { | ||
[Key in KeysType]: Required<Pick<ObjectType, Key>> & Partial<Record<Exclude<KeysType, Key>, never>>; | ||
}[KeysType] & Omit<ObjectType, KeysType>; | ||
declare type ParamsFetcher<S extends Schema, P extends GetContentParams<S, P>, T extends ModelKind> = T extends 'global' ? Namespaces<S, 'global'>[] : { | ||
type ParamsFetcher<S extends Schema, P extends GetContentParams<S, P>, T extends ModelKind> = T extends 'global' ? Namespaces<S, 'global'>[] : { | ||
namespaces: Namespaces<S, T>[]; | ||
@@ -503,3 +503,3 @@ ids?: string[]; | ||
}; | ||
declare type GetContentParams<S extends Schema, P extends GetContentParams<S, P>> = { | ||
type GetContentParams<S extends Schema, P extends GetContentParams<S, P>> = { | ||
global?: ParamsFetcher<S, P, 'global'>; | ||
@@ -513,4 +513,4 @@ product?: ParamsFetcher<S, P, 'product'> & { | ||
}; | ||
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'; | ||
type Adapter = <D extends GetType2<any>>(value: D) => any; | ||
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'; | ||
@@ -553,3 +553,3 @@ declare class GraphqlClient { | ||
declare type CustomMetafields = { | ||
type CustomMetafields = { | ||
customProductMetafields?: Identifier[]; | ||
@@ -599,3 +599,3 @@ } | null; | ||
declare type variables = { | ||
type variables = { | ||
[key: string]: boolean | string | number | undefined; | ||
@@ -602,0 +602,0 @@ }; |
@@ -230,3 +230,3 @@ "use strict";var A=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var re=(t,e)=>{for(var r in e)A(t,r,{get:e[r],enumerable:!0})},ne=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ee(e))!te.call(t,i)&&i!==r&&A(t,i,{get:()=>e[i],enumerable:!(n=Z(e,i))||n.enumerable});return t};var ie=t=>ne(A({},"__esModule",{value:!0}),t);var ue={};re(ue,{GraphqlClient:()=>y,MetaCms:()=>z,buildQuery:()=>T,collectionFragment:()=>L,config:()=>ae,contentQuery:()=>D,fieldToMetafieldType:()=>k,getLoremCollectionData:()=>Q,getLoremImageData:()=>v,getLoremProductData:()=>x,getMetaCMSConfigQuery:()=>se,getOwnerIdQuery:()=>w,imageFragment:()=>I,isId:()=>C,mediaImageFragment:()=>E,metafieldFragment:()=>$,metafieldsForNodes:()=>O,metafieldsQuery:()=>R,mockValue:()=>_,mustaching:()=>Y,normalizeEdges:()=>m,productFragment:()=>M,randomId:()=>g,setInNamespace:()=>S,setMetaCMSConfigMutation:()=>N,syncConfig:()=>ce,templating:()=>de,traverse:()=>b,videoFragment:()=>j});module.exports=ie(ue);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(i=>{e.push(i.id)})}),r.type==="collection_reference"&&r.collection.content&&r.collection.content.map(n=>{e.push(n.id)}),r.type==="list.collection_reference"&&r.values.edges.map(({node:n})=>{n.content&&n.content.map(i=>{e.push(i.id)})}))}),e};var N=` | ||
}`;var m=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),ae=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}`},C=t=>typeof t=="string"?t.startsWith("gid://shopify/Metafield/"):!1,S=({content:t,namespace:e,key:r,id:n,value:i})=>{let s=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[s]:i})},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,i,s)=>`id:${r(n)}${s.length-1>i?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,i,s)=>`handle:${n}${s.length-1>i?" or ":""}`).join("")}`.trim():void 0},b=(t,e,r=i=>i,n=[])=>typeof t!="object"?t:(Array.isArray(t)?t:Object.entries(t)).reduce((s,a,c)=>{if(Array.isArray(t))s.push(b(a,e,r,n.concat(c)));else{let[l,u]=a;Array.isArray(u)?(s[l]=[],u.forEach((o,d)=>s[l].push(b(o,e,r,n.concat(l).concat(d))))):u&&(u.attributes?s[l]=e(u,n.concat(l)):s[l]=r(b(u,e,r,n.concat(l)),n.concat(l)))}return s},Array.isArray(t)?[]:{});var q=({acc:t,item:e,client:r,locale:n,jsonMetafields:i,nestedContent:s})=>{var u;let a={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},c,l=({id:o,key:d,namespace:f,objectId:p})=>{s&&t&&n&&S({content:t,key:d,id:p,namespace:f.replace(`@${n}`,""),value:s[o]})};switch(e.type){case"collection_reference":{c={attributes:a,value:{...e.collection,products:m(e.collection.products).map(({content:o,...d})=>(o==null||o.forEach(f=>l({...f,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"),c={attributes:a,value:e.image.image};break}if("video"in e){c={attributes:a,value:e.video};break}break}case"product_reference":{let{product:o}=e;(u=o.content)==null||u.forEach(d=>l({...d,objectId:o.id})),c={attributes:a,value:{...o,variants:m(e.product.variants)}};break}case"list.collection_reference":{c={attributes:a,value:m(e.values).map(o=>{var d;return(d=o.content)==null||d.forEach(f=>l({...f,objectId:o.id})),{...o,products:m(o.products).map(f=>{var p;return(p=f.content)==null||p.forEach(h=>l({...h,objectId:f.id})),{...f,variants:m(f.variants)}})}})};break}case"list.file_reference":{c={attributes:a,value:m(e.values).map(o=>{if("image"in o)return o.image;if("video"in o)return o})};break}case"list.product_reference":{c={attributes:a,value:m(e.values).map(o=>{var d;return(d=o.content)==null||d.forEach(f=>l({...f,objectId:o.id})),{...o,variants:m(o.variants)}})};break}case"json":{let o=JSON.parse(e.value);if(o.country&&o.address&&o.locality&&o.postal_code)c={attributes:a,value:o};else{let d=U(e.value,i);c={attributes:a,value:d.value||d}}break}case"list.multi_line_text_field":case"list.single_line_text_field":{c={attributes:a,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{c={attributes:a,value:e.value||""};break}case"boolean":{c={attributes:a,value:e.value==="true"};break}case"number_decimal":{c={attributes:a,value:Number(e.value)};break}case"list.number_decimal":{c={attributes:a,value:JSON.parse(e.value,(o,d)=>Number(d))};break}case"url":{c={attributes:a,value:e.value};break}case"date_time":{c={attributes:a,value:(()=>{try{return new Date(e.value)}catch{return new Date}})()};break}}return c},V=({client:t,id:e,initalizer:r,content:n,jsonMetafields:i,nestedContent:s})=>{var c,l;let a=r||{};for(let u=0;u<n.length;u++){let o=n[u];if(o){if(!((l=(c=t.config[o.namespace.replace(`@${t.locale}`,"")])==null?void 0:c.schema)==null?void 0:l[o.key]))return a;let f=q({client:t,acc:a,item:o,jsonMetafields:i,nestedContent:s});S({content:a,key:o.key,namespace:o.namespace.replace(`@${t.locale}`,""),value:f})}}return a};var oe=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(i=>{C(i)&&e.push(i)}):C(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]=q({item:n,client:e})),r),{}),U=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(i=>C(i)?e[i]:i):C(n)?e[n]:n):JSON.parse(t);var k=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},v=(t=400,e=300)=>({alt:"image",src:`https://picsum.photos/${t}/${e}`,width:t,height:e}),x=()=>({id:g(),descriptionHtml:"Lorem ipsum",title:"Lorem ipsum",handle:"",featuredImage:v(),compareAtPriceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},priceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},variants:[]}),Q=()=>({id:g(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:v(),products:[x(),x(),x()]}),J=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r};var H=(t,e=!0,r)=>Object.entries(t.schema).reduce((n,[i,s])=>{if(s.isList)s.type==="object"?n[i]=H(s,!1,r):n[i]=[];else if(s.type==="object")n[i]=H(s,!1,r);else{let a=k(s),c={itemID:g(),itemType:a,itemProp:""};n[i]=_(s.type,c)}return n},t.type==="object"&&e?{}:t.isList?[]:{}),_=(t,e,r=!0,n)=>{var i;switch(t.type){case"object":return t.isList?{attributes:e,value:[]}:{attributes:e,value:H(t,!0,(i=e.itemProp)==null?void 0:i.split(":")[0])};case"collection":return{attributes:e,value:t.isList?J(Q):Q()};case"image":return{value:t.isList?r?J(v):[]:r?{id:g(),...v()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?J(x):x()};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>. | ||
}`;var m=t=>t.edges.reduce((e,{node:r})=>(e.push(r),e),[]),ae=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}`},C=t=>typeof t=="string"?t.startsWith("gid://shopify/Metafield/"):!1,S=({content:t,namespace:e,key:r,id:n,value:i})=>{let s=n?`${r}@${n}`:r;t[e]||Object.assign(t,{[e]:{}}),Object.assign(t[e],{[s]:i})},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,i,s)=>`id:${r(n)}${s.length-1>i?" or ":t!=null&&t.length?" or":""}`).join("")} ${(t||[]).map((n,i,s)=>`handle:${n}${s.length-1>i?" or ":""}`).join("")}`.trim():void 0},b=(t,e,r=i=>i,n=[])=>typeof t!="object"?(console.log({data:t}),t):(Array.isArray(t)?t:Object.entries(t)).reduce((s,a,c)=>{if(Array.isArray(t))s.push(b(a,e,r,n.concat(c)));else{let[l,u]=a;Array.isArray(u)?(s[l]=[],u.forEach((o,d)=>s[l].push(b(o,e,r,n.concat(l).concat(d))))):u&&(u.attributes?s[l]=e(u,n.concat(l)):s[l]=r(b(u,e,r,n.concat(l)),n.concat(l)))}return s},Array.isArray(t)?[]:{});var q=({acc:t,item:e,client:r,locale:n,jsonMetafields:i,nestedContent:s})=>{var u;let a={itemID:e.id,itemType:e.type,itemProp:`${e.namespace}:${e.key}`},c,l=({id:o,key:d,namespace:f,objectId:p})=>{s&&t&&n&&S({content:t,key:d,id:p,namespace:f.replace(`@${n}`,""),value:s[o]})};switch(e.type){case"collection_reference":{c={attributes:a,value:{...e.collection,products:m(e.collection.products).map(({content:o,...d})=>(o==null||o.forEach(f=>l({...f,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"),c={attributes:a,value:e.image.image};break}if("video"in e){c={attributes:a,value:e.video};break}break}case"product_reference":{let{product:o}=e;(u=o.content)==null||u.forEach(d=>l({...d,objectId:o.id})),c={attributes:a,value:{...o,variants:m(e.product.variants)}};break}case"list.collection_reference":{c={attributes:a,value:m(e.values).map(o=>{var d;return(d=o.content)==null||d.forEach(f=>l({...f,objectId:o.id})),{...o,products:m(o.products).map(f=>{var p;return(p=f.content)==null||p.forEach(h=>l({...h,objectId:f.id})),{...f,variants:m(f.variants)}})}})};break}case"list.file_reference":{c={attributes:a,value:m(e.values).map(o=>{if("image"in o)return o.image;if("video"in o)return o})};break}case"list.product_reference":{c={attributes:a,value:m(e.values).map(o=>{var d;return(d=o.content)==null||d.forEach(f=>l({...f,objectId:o.id})),{...o,variants:m(o.variants)}})};break}case"json":{let o=JSON.parse(e.value);if(o.country&&o.address&&o.locality&&o.postal_code)c={attributes:a,value:o};else{let d=U(e.value,i);c={attributes:a,value:d.value||d}}break}case"list.multi_line_text_field":case"list.single_line_text_field":{c={attributes:a,value:JSON.parse(e.value)};break}case"multi_line_text_field":case"single_line_text_field":{c={attributes:a,value:e.value||""};break}case"boolean":{c={attributes:a,value:e.value==="true"};break}case"number_decimal":{c={attributes:a,value:Number(e.value)};break}case"list.number_decimal":{c={attributes:a,value:JSON.parse(e.value,(o,d)=>Number(d))};break}case"url":{c={attributes:a,value:e.value};break}case"date_time":{c={attributes:a,value:(()=>{try{return new Date(e.value)}catch{return new Date}})()};break}}return c},V=({client:t,id:e,initalizer:r,content:n,jsonMetafields:i,nestedContent:s})=>{var c,l;let a=r||{};for(let u=0;u<n.length;u++){let o=n[u];if(o){if(!((l=(c=t.config[o.namespace.replace(`@${t.locale}`,"")])==null?void 0:c.schema)==null?void 0:l[o.key]))return a;let f=q({client:t,acc:a,item:o,jsonMetafields:i,nestedContent:s});S({content:a,key:o.key,namespace:o.namespace.replace(`@${t.locale}`,""),value:f})}}return a};var oe=t=>{let e=[];return t&&JSON.parse(t,(r,n)=>(Array.isArray(n)?n.forEach(i=>{C(i)&&e.push(i)}):C(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]=q({item:n,client:e})),r),{}),U=(t,e)=>e?JSON.parse(t,(r,n)=>Array.isArray(n)?n.map(i=>C(i)?e[i]:i):C(n)?e[n]:n):JSON.parse(t);var k=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},v=(t=400,e=300)=>({alt:"image",src:`https://picsum.photos/${t}/${e}`,width:t,height:e}),x=()=>({id:g(),descriptionHtml:"Lorem ipsum",title:"Lorem ipsum",handle:"",featuredImage:v(),compareAtPriceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},priceRange:{maxVariantPrice:{amount:"0",currencyCode:"EUR"},minVariantPrice:{amount:"0",currencyCode:"EUR"}},variants:[]}),Q=()=>({id:g(),title:"Lorem ipsum",descriptionHtml:"Lorem ipsum",handle:"",image:v(),products:[x(),x(),x()]}),J=(t,e=3)=>{let r=[];for(let n=0;n<4;n++)r.push(t());return r};var H=(t,e=!0,r)=>Object.entries(t.schema).reduce((n,[i,s])=>{if(s.isList)s.type==="object"?n[i]=H(s,!1,r):n[i]=[];else if(s.type==="object")n[i]=H(s,!1,r);else{let a=k(s),c={itemID:g(),itemType:a,itemProp:""};n[i]=_(s,c)}return n},t.type==="object"&&e?{}:t.isList?[]:{}),_=(t,e,r=!0,n)=>{var i;switch(t.type){case"object":return t.isList?{attributes:e,value:[]}:{attributes:e,value:H(t,!0,(i=e.itemProp)==null?void 0:i.split(":")[0])};case"collection":return{attributes:e,value:t.isList?J(Q):Q()};case"image":return{value:t.isList?r?J(v):[]:r?{id:g(),...v()}:void 0,attributes:e};case"video":return{value:void 0,attributes:e};case"product":return{attributes:e,value:t.isList?J(x):x()};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:!1};case"url":return{attributes:e,value:"/"};case"list":return{attributes:e,value:t.options[0].value};case"number":return{attributes:e,value:0};case"date":return{attributes:e,value:new Date};default:case"text":return{attributes:e,value:t.isList?n?[n]:["Lorem ipsum","Lorem ipsum","Lorem ipsum"]:n||"Lorem ipsum dolor sit amet consectetur adipisicing elit."}}};var y=class{constructor(e,r){this.request=async(e,r)=>{let n=await await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:r||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}});if(n.ok){let{data:i}=await n.json();return i}else throw new Error(await n.text())};this.url=e,this.headers=r}},z=class{constructor(e,{storefrontName:r,storefrontAccessToken:n,defaultNameSpaces:i},s){this.getMetafieldsByIds=async e=>{var i,s;if(!e.length)return[{},[]];let r=await this.client.request(R(!1,{customProductMetafields:(s=(i=this.params)==null?void 0:i.product)==null?void 0:s.customMetafieldsIdentifiers}),{ids:e});if(!r)return[{},[]];let{metafields:n}=r;return[P(n,this),n]};this.getMetafieldsForProductsAndCollection=async({collection:e,product:r,locale:n})=>{var p,h;if(!(e!=null&&e.ids)&&!(e!=null&&e.handles)&&!(e!=null&&e.namespaces)&&!(r!=null&&r.ids)&&!(r!=null&&r.handles)&&!(r!=null&&r.namespaces))return[{},[],[]];let i=await this.client.request(O({collectionQuery: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:(h=(p=this.params)==null?void 0:p.product)==null?void 0:h.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers((r==null?void 0:r.namespaces)||[],n),collectionIdentifiers:this.buildIdentifiers((e==null?void 0:e.namespaces)||[],n)});if(!i)return[{},[],[]];let{products:s,collections:a}=i,c=s?m(s):[],l=a?m(a):[],u=c.map(F=>F.content).flat(),o=l.map(F=>F.content).flat(),d=P(u,this),f=P(o,this);return[{...d,...f},u.concat(o),c.concat(l)]};this.getContentForNamespaces=async e=>{var o,d,f;if(this.locale=e.locale||"en",!e.global)return{content:{},params:e};this.params=e;let{shop:{content:r}}=await this.client.request(D(!0,{customProductMetafields:(o=e.product)==null?void 0:o.customMetafieldsIdentifiers}),{productIdentifiers:this.buildIdentifiers(((d=e.product)==null?void 0:d.namespaces)||[],e.locale),collectionIdentifiers:this.buildIdentifiers(((f=e.collection)==null?void 0:f.namespaces)||[],e.locale),identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),e.locale)}),[[n,i],[s,a,c]]=await Promise.all([this.getMetafieldsByIds(W(r)),this.getMetafieldsForProductsAndCollection(e)]),[l]=await this.getMetafieldsByIds(G(r.concat(i).concat(a)));console.log({jsonMetafields:l},G(r));let u=V({client:this,content:r,jsonMetafields:l,nestedContent:{...n,...s}});return c.forEach(({id:p,content:h})=>{V({client:this,initalizer:u,id:p,content:h,jsonMetafields:l,nestedContent:{...n,...s}})}),{params:{...e,global:e.global.concat(this.defaultNameSpaces)},content:u}};this.t=(e,r,{productId:n,collectionId:i})=>{let[s,a]=e.split(".");if(!(s in this.config))throw new Error(`Namespace "${s}" is not defined in the schema`);let{kind:c,schema:l}=this.config[s];if(n&&c==="product"&&(a=`${a}@${n}`),i&&c==="collection"&&(a=`${a}@${i}`),!(a in l))throw new Error(`Path "${a}" is not defined in the "${s}" schema`);let u=l[a],o=()=>{let d=k(u),f={itemID:g(),itemType:d,itemProp:`${s}:${a}`},p=this.config[s].schema[a].default;return _(u,f,!0,p)};return s in r||Object.assign(r,{[s]:{}}),[r[s][a]||o(),u,this.locale]};this.buildIdentifiers=(e,r)=>e?e.reduce((n,i)=>{let s=this.config[i];return s&&Object.keys(s.schema).forEach(a=>{n.push({namespace:`${i}@${r}`,key:a})}),n},[]):[];this.locale="en",this.adapter=s||(a=>a),this.config=e,this.defaultNameSpaces=i||[],this.client=new y(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n})}};var ce=async(t,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:n},i)=>{console.log(i);let s=new y(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}),a=new y(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":n}),{shop:{id:c}}=await s.request(w);return await a.request(N,{value:JSON.stringify(t),key:i,ownerId:c})};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,le=(t,e)=>{if(!e)return t;let r=t.matchAll(X);return Array.from(r).forEach(n=>{let[i]=n,[s,a,c]=i.replace("((","").replace("))","").split(","),l=typeof e[s]=="number"?Number(e[s])>1:!!e[s];c?l===!0?t=t.replace(i,c.trim()):t=t.replace(i,a.trim()):l===!0?(c=a,t=t.replace(i,c.trim())):t=t.replace(X,"")}),t},de=(t,e)=>le(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.89", | ||
"version": "1.0.90", | ||
"description": "", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"type-fest": "^3.0.0", | ||
"typescript": "^4.8.4", | ||
"typescript": "^4.9.3", | ||
"vitest": "^0.24.3" | ||
@@ -23,0 +23,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38079