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.36 to 1.0.37

95

index.d.ts

@@ -6,9 +6,7 @@ import { Get } from 'type-fest';

};
declare type ArrayToUnion<Base> = NonNullable<{
[Key in keyof Base]: Base[Key] extends never ? Key : Key extends string ? Base[Key] extends string ? `${Key}.${Base[Key]}` : never : never;
}[keyof Base]>;
declare type ArrayKeys<Base> = ArrayToUnion<Base> extends string ? ArrayToUnion<Base> : never;
declare type Namespaces<S extends Schema> = ArrayKeys<Simplify<S>>;
declare 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<{
[K in Namespaces<S>]: `${K}.${ArrayKeys<Simplify<S[K]>>}`;
[K in Namespaces<S>]: keyof S[K]["schema"] extends string ? `${K}.${keyof S[K]["schema"]}` : "never";
}[Namespaces<S>]>;

@@ -18,2 +16,3 @@ declare type Split<S extends string> = string extends S ? string[] : S extends "" ? [] : S extends `${infer T}.${infer U}` ? [T, ...Split<U>] : [S];

declare type ImageContent = {
id: string;
alt: string;

@@ -25,5 +24,6 @@ src: string;

};
declare type ImageData = Omit<ImageContent, "attributes" | "id">;
declare type ImagesContent = {
attributes: ItemAttributes<"list.file_reference">;
images: Omit<ImageContent, "attributes">[];
images: ImageData[];
};

@@ -55,3 +55,3 @@ declare type TextContent = {

}[];
image: ImageContent;
image: ImageData;
price: PriceContent;

@@ -65,6 +65,7 @@ compareAtPrice: PriceContent;

declare type ProductData = {
id: string;
descriptionHtml: string;
title: string;
handle: string;
featuredImage: ImageContent;
featuredImage: ImageData;
compareAtPriceRange: PriceVariationContent;

@@ -91,6 +92,7 @@ priceRange: PriceVariationContent;

declare type CollectionData = {
id: string;
title: string;
descriptionHtml: string;
handle: string;
image: ImageContent;
image: ImageData;
products: ProductData[];

@@ -108,12 +110,15 @@ };

type: "object";
kind?: "global" | "product" | "collection" | "variant";
default?: ProductContent;
isList?: boolean;
schema: Model;
schema: ModelSchema;
};
declare type ModelKind = "global" | "product" | "collection" | "page";
declare type Schema = Record<string, Model>;
declare type Model = Record<string, Field>;
declare type ModelSchema = Record<string, Field>;
declare type Model = {
kind: ModelKind;
schema: ModelSchema;
};
declare type Field = ObjectField | {
type: "product";
kind?: "global" | "product" | "collection" | "variant";
default?: ProductContent;

@@ -123,3 +128,2 @@ isList?: false;

type: "product";
kind?: "global" | "product" | "collection" | "variant";
default?: ProductContent[];

@@ -129,3 +133,2 @@ isList?: true;

type: "collection";
kind?: "global" | "product" | "collection" | "variant";
default?: CollectionContent;

@@ -135,3 +138,2 @@ isList?: false;

type: "collection";
kind?: "global" | "product" | "collection" | "variant";
default?: CollectionContent[];

@@ -141,3 +143,2 @@ isList?: true;

type: "image";
kind?: "global" | "product" | "collection" | "variant";
default?: ImageContent;

@@ -147,3 +148,2 @@ isList?: false;

type: "image";
kind?: "global" | "product" | "collection" | "variant";
default?: ImageContent[];

@@ -153,3 +153,2 @@ isList?: true;

type: "text";
kind?: "global" | "product" | "collection" | "variant";
default?: Text;

@@ -159,3 +158,2 @@ isList?: false;

type: "text";
kind?: "global" | "product" | "collection" | "variant";
default?: Text[];

@@ -165,3 +163,2 @@ isList?: true;

type: "richtext";
kind?: "global" | "product" | "collection" | "variant";
default?: Text;

@@ -171,3 +168,2 @@ isList?: false;

type: "richtext";
kind?: "global" | "product" | "collection" | "variant";
default?: Text[];

@@ -182,13 +178,13 @@ isList?: true;

declare type ConfigType = "json" | "file" | "product" | "collection" | "object";
declare type GetConfigType<S extends Schema, P extends Paths<S>> = Split<P>[2] extends undefined ? Split<P>[1] extends keyof S[Split<P>[0]] ? S[Split<P>[0]][Split<P>[1]]["type"] : never : Split<P>[1] extends keyof S[Split<P>[0]] ? S[Split<P>[0]][Split<P>[1]] extends ObjectField ? Split<P>[2] extends keyof S[Split<P>[0]][Split<P>[1]]["schema"] ? S[Split<P>[0]][Split<P>[1]]["schema"][Split<P>[2]]["type"] : never : never : never;
declare type isList<S extends Schema, P extends Paths<S>> = Split<P>[2] extends undefined ? S[Split<P>[0]][Split<P>[1]]["isList"] : Get<Get<Get<S[Split<P>[0]][Split<P>[1]], "schema">, [Split<P>[2]]>, "isList">;
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 ObjectSchema<S extends Schema, P extends Paths<S>> = Split<P>[0] extends keyof S ? Split<P>[1] extends keyof S[Split<P>[0]] ? S[Split<P>[0]][Split<P>[1]] : never : never;
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 getNestedType<T> = T extends "text" ? string : T extends "richtext" ? string : T extends "image" ? ImageData : T extends "product" ? ProductData : CollectionData;
declare type ObjectContent<O extends Model> = {
[K in keyof O]: "schema" extends keyof O[K] ? O[K]["schema"] extends Model ? O[K]["isList"] extends true ? ObjectContent<O[K]["schema"]>[] : ObjectContent<O[K]["schema"]> : never : getNestedType<O[K]["type"]>;
declare type ObjectContent<O extends ModelSchema> = {
[K in keyof O]: "schema" extends keyof O[K] ? O[K]["schema"] extends ModelSchema ? O[K]["isList"] extends true ? ObjectContent<O[K]["schema"]>[] : ObjectContent<O[K]["schema"]> : never : O[K]["isList"] extends true ? getNestedType<O[K]["type"]>[] : getNestedType<O[K]["type"]>;
};
declare type GetType<S extends Schema, P extends Paths<S>> = GetConfigType<S, P> extends "text" ? toList<S, P, TextContent, TextsContent> : GetConfigType<S, P> extends "collection" ? toList<S, P, CollectionContent, CollectionsContent> : GetConfigType<S, P> extends "product" ? toList<S, P, ProductContent, ProductsContent> : GetConfigType<S, P> extends "richtext" ? toList<S, P, HTMLContent, HTMLsContent> : GetConfigType<S, P> extends "object" ? ObjectSchema<S, P> extends ObjectField ? ObjectSchema<S, P>["schema"] extends Model ? Record<Split<P>[1], toList<S, P, ObjectContent<ObjectSchema<S, P>["schema"]>>> & {
attributes: ItemAttributes;
} : never : never : toList<S, P, ImageContent, ImagesContent>;
declare type GetType<S extends Schema, P extends Paths<S>, C = GetConfigType<S, P>> = C extends "text" ? toList<S, P, TextContent, TextsContent> : C extends "collection" ? toList<S, P, CollectionContent, CollectionsContent> : C extends "product" ? toList<S, P, ProductContent, ProductsContent> : C extends "richtext" ? toList<S, P, HTMLContent, HTMLsContent> : C extends "object" ? ObjectSchema<S, P> extends ObjectField ? ObjectSchema<S, P>["schema"] extends ModelSchema ? Split<P>[1] extends string ? Record<Split<P>[1], toList<S, P, ObjectContent<ObjectSchema<S, P>["schema"]>>> & {
attributes: ItemAttributes<"json">;
} : never : never : never : toList<S, P, 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;

@@ -202,3 +198,3 @@ declare type Identifier = {

storefrontAccessToken: string;
defaultNameSpaces?: Namespaces<S>[];
defaultNameSpaces?: Namespaces<S, "global">[];
};

@@ -248,3 +244,3 @@ declare type MetafieldContent = {

declare type MetafieldProduct = {
__typename: "Product";
id: string;
descriptionHtml: string;

@@ -271,3 +267,3 @@ title: string;

declare type MetafieldCollection = {
__typename: "Collection";
id: string;
title: string;

@@ -328,2 +324,18 @@ descriptionHtml: string;

};
declare 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">[] : P["global"] extends undefined ? {
namespaces: Namespaces<S, T>[];
ids: string[];
handles: string[];
} : {
namespaces: Namespaces<S, T>[];
};
declare type GetContentParams<S extends Schema, P extends GetContentParams<S, P>> = {
global?: ParamsFetcher<S, P, "global">;
product?: ParamsFetcher<S, P, "product">;
page?: ParamsFetcher<S, P, "page">;
collection?: ParamsFetcher<S, P, "collection">;
};

@@ -339,8 +351,9 @@ declare class GraphqlClient {

client: GraphqlClient;
defaultNameSpaces: Namespaces<S>[];
defaultNameSpaces: Namespaces<S, "global">[];
constructor(config: S, { storefrontName, storefrontAccessToken, defaultNameSpaces }: MetaCMSConfig<S>);
getContentForNamespaces: (namespaces: Namespaces<S>[], locale?: "fra") => Promise<Content<S>>;
t: <P extends Paths<S>, Cont extends Content<S>>(p: P, locale: "fr" | undefined, content: Cont) => GetType<S, P>;
getContentForNamespaces: <P extends GetContentParams<S, P>>(params: P, locale?: "fra") => Promise<Content<S>>;
t: <P extends Paths<S>, Cont extends Content<S>>(p: P, locale: "fr" | undefined, content: Cont) => GetType<S, P, GetConfigType<S, P>>;
buildIdentifiers: (namespaces: Namespaces<S>[], locale?: "fra") => Identifier[];
}
declare const normalizeEdges: <T extends WithEdge<T>>(item: T) => Nodes<T>;
declare const config: <C extends Model>(c: C) => C;

@@ -353,3 +366,7 @@

declare const contentQuery = "\n query getContentF($identifiers: [HasMetafieldsIdentifier!]!) {\n shop {\n content: metafields(identifiers: $identifiers) {\n type\n value\n key\n id\n namespace\n value\n values: references(first: 10) {\n edges {\n node {\n ... on MediaImage {\n ...MediaImageFields\n }\n ... on Collection {\n ...CollectionFields\n }\n ... on Product {\n ...ProductFields\n }\n }\n }\n }\n image: reference {\n ... on MediaImage {\n ...MediaImageFields\n }\n }\n collection: reference {\n ... on Collection {\n ...CollectionFields\n }\n }\n product: reference {\n ... on Product {\n ...ProductFields\n }\n }\n }\n }\n }\n\n fragment MediaImageFields on MediaImage {\n __typename\n image {\n ...ImageFields\n }\n }\n\n fragment ImageFields on Image {\n alt: altText\n height\n width\n src: url\n }\n\n fragment MoneyV2Fields on MoneyV2 {\n amount\n currencyCode\n }\n\n fragment CollectionFields on Collection {\n __typename\n title\n descriptionHtml\n handle\n image {\n ...ImageFields\n }\n products(first: 10) {\n edges {\n node {\n ...ProductFields\n }\n }\n }\n }\n\n fragment ProductFields on Product {\n __typename\n descriptionHtml\n title\n handle\n variants(first: 20) {\n edges {\n node {\n id\n availableForSale\n quantityAvailable\n selectedOptions {\n name\n value\n }\n title\n image {\n ...ImageFields\n }\n price {\n ...MoneyV2Fields\n }\n compareAtPrice {\n ...MoneyV2Fields\n }\n product {\n handle\n id\n }\n }\n }\n }\n featuredImage {\n ...ImageFields\n }\n compareAtPriceRange {\n maxVariantPrice {\n ...MoneyV2Fields\n }\n minVariantPrice {\n ...MoneyV2Fields\n }\n }\n priceRange {\n maxVariantPrice {\n ...MoneyV2Fields\n }\n minVariantPrice {\n ...MoneyV2Fields\n }\n }\n }\n";
declare const mediaImageFragment = "\n fragment MediaImageFields on MediaImage {\n image {\n ...ImageFields\n }\n }\n";
declare const imageFragment = "\n fragment ImageFields on Image {\n id\n alt: altText\n height\n width\n src: url\n }\n";
declare const productFragment: string;
declare const collectionFragment: string;
declare const contentQuery: string;

@@ -362,2 +379,2 @@ declare const syncConfig: (schema: Schema, { storefrontName, storefrontAccessToken, adminAccessToken }: {

export { ArrayKeys, ArrayToUnion, CollectionContent, CollectionData, CollectionsContent, ConfigType, Content, Field, GetConfigType, GetType, GraphqlClient, HTMLContent, HTMLsContent, Identifier, ImageContent, ImagesContent, ItemAttributes, Last, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, Model, Namespaces, Nodes, PathForNamespace, Paths, Price, PriceContent, PriceVariation, PriceVariationContent, ProductContent, ProductData, ProductsContent, Schema, Simplify, Split, TextContent, TextsContent, VariantContent, WithEdge, config, contentQuery, getMetaCMSConfigQuery, getOwnerIdQuery, isList, metafieldType, setMetaCMSConfigMutation, syncConfig, toList };
export { CollectionContent, CollectionData, CollectionsContent, ConfigType, Content, Field, GetConfigType, GetContentParams, GetType, GraphqlClient, HTMLContent, HTMLsContent, Identifier, ImageContent, ImageData, ImagesContent, ItemAttributes, Last, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, Model, ModelKind, ModelSchema, Namespaces, Nodes, ObjectContent, ObjectSchema, ParamsFetcher, PathForNamespace, Paths, Price, PriceContent, PriceVariation, PriceVariationContent, ProductContent, ProductData, ProductsContent, RequireExactlyOne, Schema, Simplify, Split, TextContent, TextsContent, VariantContent, WithEdge, collectionFragment, config, contentQuery, getMetaCMSConfigQuery, getOwnerIdQuery, imageFragment, isList, mediaImageFragment, metafieldType, normalizeEdges, productFragment, setMetaCMSConfigMutation, syncConfig, toList };

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

"use strict";var p=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var F=(s,e)=>{for(var r in e)p(s,r,{get:e[r],enumerable:!0})},P=(s,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of x(e))!M.call(s,n)&&n!==r&&p(s,n,{get:()=>e[n],enumerable:!(i=I(e,n))||i.enumerable});return s};var T=s=>P(p({},"__esModule",{value:!0}),s);var O={};F(O,{GraphqlClient:()=>f,MetaCms:()=>y,config:()=>k,contentQuery:()=>g,getMetaCMSConfigQuery:()=>_,getOwnerIdQuery:()=>u,setMetaCMSConfigMutation:()=>m,syncConfig:()=>v});module.exports=T(O);var m=`
"use strict";var p=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var T=(a,e)=>{for(var r in e)p(a,r,{get:e[r],enumerable:!0})},b=(a,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of M(e))!v.call(a,n)&&n!==r&&p(a,n,{get:()=>e[n],enumerable:!(s=I(e,n))||s.enumerable});return a};var k=a=>b(p({},"__esModule",{value:!0}),a);var $={};T($,{GraphqlClient:()=>f,MetaCms:()=>y,collectionFragment:()=>F,config:()=>O,contentQuery:()=>u,getMetaCMSConfigQuery:()=>w,getOwnerIdQuery:()=>g,imageFragment:()=>x,mediaImageFragment:()=>C,normalizeEdges:()=>d,productFragment:()=>P,setMetaCMSConfigMutation:()=>m,syncConfig:()=>_});module.exports=k($);function S(a,e,r){if(!a)return r;var s,n;if(Array.isArray(e)&&(s=e.slice(0)),typeof e=="string"&&(s=e.split(".")),typeof e=="symbol"&&(s=[e]),!Array.isArray(s))throw new Error("props arg must be an array, a string or a symbol");for(;s.length;)if(n=s.shift(),!a||(a=a[n],a===void 0))return r;return a}var m=`
mutation ($ownerId: ID!, $value: String!, $key: String!) {

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

}
`,_=`
`,w=`
query {

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

}
`;var u=`
`;var g=`
query getOwnerId {

@@ -26,48 +26,4 @@ shop {

}
`;var g=`
query getContentF($identifiers: [HasMetafieldsIdentifier!]!) {
shop {
content: metafields(identifiers: $identifiers) {
type
value
key
id
namespace
value
values: references(first: 10) {
edges {
node {
... on MediaImage {
...MediaImageFields
}
... on Collection {
...CollectionFields
}
... on Product {
...ProductFields
}
}
}
}
image: reference {
... on MediaImage {
...MediaImageFields
}
}
collection: reference {
... on Collection {
...CollectionFields
}
}
product: reference {
... on Product {
...ProductFields
}
}
}
}
}
`;var C=`
fragment MediaImageFields on MediaImage {
__typename
image {

@@ -77,4 +33,5 @@ ...ImageFields

}
`,x=`
fragment ImageFields on Image {
id
alt: altText

@@ -85,27 +42,6 @@ height

}
fragment MoneyV2Fields on MoneyV2 {
amount
currencyCode
}
fragment CollectionFields on Collection {
__typename
title
descriptionHtml
handle
image {
...ImageFields
}
products(first: 10) {
edges {
node {
...ProductFields
}
}
}
}
`,P=`
${x}
fragment ProductFields on Product {
__typename
id
descriptionHtml

@@ -161,2 +97,70 @@ title

}
`;function S(s,e,r){if(!s)return r;var i,n;if(Array.isArray(e)&&(i=e.slice(0)),typeof e=="string"&&(i=e.split(".")),typeof e=="symbol"&&(i=[e]),!Array.isArray(i))throw new Error("props arg must be an array, a string or a symbol");for(;i.length;)if(n=i.shift(),!s||(s=s[n],s===void 0))return r;return s}var f=class{constructor(e,r){this.request=async(e,r)=>(await(await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:r||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}})).json()).data;this.url=e,this.headers=r}},y=class{constructor(e,{storefrontName:r,storefrontAccessToken:i,defaultNameSpaces:n}){this.getContentForNamespaces=async(e,r="fra")=>{let{shop:{content:i}}=await this.client.request(g,{identifiers:this.buildIdentifiers(e.concat(this.defaultNameSpaces),r)});return console.log({content:i}),i.reduce((n,t)=>{if(!t)return n;let c=t.namespace.replace(`_${r}`,"");n[c]||Object.assign(n,{[c]:{}});let o={itemID:t.id,itemType:t.type,itemProp:`${t.namespace}:${t.key}`},a;switch(t.type){case"collection_reference":{a={attributes:o,collection:{...t.collection,products:l(t.collection.products)}};break}case"file_reference":{t.image.image.alt||(t.image.image.alt=""),a={attributes:o,image:t.image.image};break}case"product_reference":{a={attributes:o,product:{...t.product,variants:l(t.product.variants)}};break}case"list.collection_reference":{a={attributes:o,collections:l(t.values).map(d=>({...d,products:l(d.products)}))};break}case"list.file_reference":{a={attributes:o,images:l(t.values).map(d=>d.image)};break}case"list.product_reference":{a={attributes:o,products:l(t.values).map(d=>({...d,variants:l(d.variants)}))};break}case"json":{a={attributes:o,[t.key]:JSON.parse(t.value)};break}case"list.multi_line_text_field":case"list.single_line_text_field":{a={attributes:o,texts:JSON.parse(t.value)};break}case"multi_line_text_field":case"single_line_text_field":{a={attributes:o,text:t.value};break}}return Object.assign(n[c],{[t.key]:a}),n},{})};this.t=(e,r="fr",i)=>{let[n,...t]=e.split("."),c=()=>S(this.config[n],t).default;return i&&i[n][t.join(".")]||c()};this.buildIdentifiers=(e,r="fra")=>e.reduce((n,t)=>{let c=this.config[t];return Object.entries(c).reduce((a,[d,h])=>(h.config?Object.keys(h.config).forEach(C=>{a.push(`${d}.${C}`)}):a.push(d),a),[]).forEach(a=>{n.push({namespace:`${t}_${r}`,key:a})}),n},[]);this.config=e,this.defaultNameSpaces=n||[],this.client=new f(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":i})}},l=s=>s.edges.reduce((e,{node:r})=>(e.push(r),e),[]),k=s=>s;var v=async(s,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:i},n)=>{console.log(n);let t=new f(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}),c=new f(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":i}),{shop:{id:o}}=await t.request(u);return await c.request(m,{value:JSON.stringify(s),key:n,ownerId:o})};0&&(module.exports={GraphqlClient,MetaCms,config,contentQuery,getMetaCMSConfigQuery,getOwnerIdQuery,setMetaCMSConfigMutation,syncConfig});
fragment MoneyV2Fields on MoneyV2 {
amount
currencyCode
}
`,F=`
${P}
fragment CollectionFields on Collection {
id
title
descriptionHtml
handle
image {
...ImageFields
}
products(first: 10) {
edges {
node {
...ProductFields
}
}
}
}
`,u=`
${F}
${C}
query getContentF($identifiers: [HasMetafieldsIdentifier!]!) {
shop {
content: metafields(identifiers: $identifiers) {
type
value
key
id
namespace
value
values: references(first: 10) {
edges {
node {
... on MediaImage {
...MediaImageFields
}
... on Collection {
...CollectionFields
}
... on Product {
...ProductFields
}
}
}
}
image: reference {
... on MediaImage {
...MediaImageFields
}
}
collection: reference {
... on Collection {
...CollectionFields
}
}
product: reference {
... on Product {
...ProductFields
}
}
}
}
}
`;var f=class{constructor(e,r){this.request=async(e,r)=>(await(await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:r||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}})).json()).data;this.url=e,this.headers=r}},y=class{constructor(e,{storefrontName:r,storefrontAccessToken:s,defaultNameSpaces:n}){this.getContentForNamespaces=async(e,r="fra")=>{if(console.log({params:e}),!e.global)return{};let{shop:{content:s}}=await this.client.request(u,{identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),r)});return s.reduce((n,t)=>{if(!t)return n;let c=t.namespace.replace(`_${r}`,"");n[c]||Object.assign(n,{[c]:{}});let i={itemID:t.id,itemType:t.type,itemProp:`${t.namespace}:${t.key}`},o;switch(t.type){case"collection_reference":{o={attributes:i,collection:{...t.collection,products:d(t.collection.products).map(l=>({...l,variants:d(l.variants)}))}};break}case"file_reference":{t.image.image.alt||(t.image.image.alt=""),o={attributes:i,image:t.image.image};break}case"product_reference":{o={attributes:i,product:{...t.product,variants:d(t.product.variants)}};break}case"list.collection_reference":{o={attributes:i,collections:d(t.values).map(l=>({...l,products:d(l.products).map(h=>({...h,variants:d(h.variants)}))}))};break}case"list.file_reference":{o={attributes:i,images:d(t.values).map(l=>l.image)};break}case"list.product_reference":{o={attributes:i,products:d(t.values).map(l=>({...l,variants:d(l.variants)}))};break}case"json":{o={attributes:i,[t.key]:JSON.parse(t.value)};break}case"list.multi_line_text_field":case"list.single_line_text_field":{o={attributes:i,texts:JSON.parse(t.value)};break}case"multi_line_text_field":case"single_line_text_field":{o={attributes:i,text:t.value};break}}return Object.assign(n[c],{[t.key]:o}),n},{})};this.t=(e,r="fr",s)=>{let[n,t]=e.split("."),c=()=>{var i;return(i=S(this.config[n],t))==null?void 0:i.default};return s?(console.log({content:s}),s[n][t]||c()):c()};this.buildIdentifiers=(e,r="fra")=>e.reduce((n,t)=>{let c=this.config[t];return Object.keys(c.schema).forEach(i=>{n.push({namespace:`${t}_${r}`,key:i})}),n},[]);this.config=e,this.defaultNameSpaces=n||[],this.client=new f(`https://${r}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":s})}},d=a=>a.edges.reduce((e,{node:r})=>(e.push(r),e),[]),O=a=>a;var _=async(a,{storefrontName:e,storefrontAccessToken:r,adminAccessToken:s},n)=>{console.log(n);let t=new f(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}),c=new f(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":s}),{shop:{id:i}}=await t.request(g);return await c.request(m,{value:JSON.stringify(a),key:n,ownerId:i})};0&&(module.exports={GraphqlClient,MetaCms,collectionFragment,config,contentQuery,getMetaCMSConfigQuery,getOwnerIdQuery,imageFragment,mediaImageFragment,normalizeEdges,productFragment,setMetaCMSConfigMutation,syncConfig});
{
"name": "@meta-cms/core",
"version": "1.0.36",
"version": "1.0.37",
"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