@meta-cms/core
Advanced tools
Comparing version 1.0.37 to 1.0.38
@@ -332,3 +332,6 @@ import { Get } from 'type-fest'; | ||
constructor(config: S, { storefrontName, storefrontAccessToken, defaultNameSpaces }: MetaCMSConfig<S>); | ||
getContentForNamespaces: <P extends GetContentParams<S, P>>(params: P, locale?: "fra") => Promise<Content<S>>; | ||
getContentForNamespaces: <P extends GetContentParams<S, P>>(params: P, locale?: "fra") => Promise<{ | ||
content: Content<S>; | ||
params: P; | ||
}>; | ||
t: <P extends Paths<S>, Cont extends Content<S>>(p: P, locale: "fr" | undefined, content: Cont) => GetType<S, P, GetConfigType<S, P>>; | ||
@@ -335,0 +338,0 @@ buildIdentifiers: (namespaces: Namespaces<S>[], locale?: "fra") => Identifier[]; |
26
index.js
@@ -1,2 +0,2 @@ | ||
"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=` | ||
"use strict";var m=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var b=(r,e)=>{for(var n in e)m(r,n,{get:e[n],enumerable:!0})},k=(r,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of v(e))!T.call(r,a)&&a!==n&&m(r,a,{get:()=>e[a],enumerable:!(s=M(e,a))||s.enumerable});return r};var w=r=>k(m({},"__esModule",{value:!0}),r);var N={};b(N,{GraphqlClient:()=>p,MetaCms:()=>h,collectionFragment:()=>I,config:()=>_,contentQuery:()=>y,getMetaCMSConfigQuery:()=>O,getOwnerIdQuery:()=>u,imageFragment:()=>P,mediaImageFragment:()=>x,normalizeEdges:()=>f,productFragment:()=>F,setMetaCMSConfigMutation:()=>g,syncConfig:()=>$});module.exports=w(N);function C(r,e,n){if(!r)return n;var s,a;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(a=s.shift(),!r||(r=r[a],r===void 0))return n;return r}var g=` | ||
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=` | ||
`,O=` | ||
query { | ||
@@ -19,3 +19,3 @@ shop { | ||
} | ||
`;var g=` | ||
`;var u=` | ||
query getOwnerId { | ||
@@ -26,3 +26,3 @@ shop { | ||
} | ||
`;var C=` | ||
`;var x=` | ||
fragment MediaImageFields on MediaImage { | ||
@@ -33,3 +33,3 @@ image { | ||
} | ||
`,x=` | ||
`,P=` | ||
fragment ImageFields on Image { | ||
@@ -42,4 +42,4 @@ id | ||
} | ||
`,P=` | ||
${x} | ||
`,F=` | ||
${P} | ||
fragment ProductFields on Product { | ||
@@ -102,4 +102,4 @@ id | ||
} | ||
`,F=` | ||
${P} | ||
`,I=` | ||
${F} | ||
fragment CollectionFields on Collection { | ||
@@ -121,5 +121,5 @@ id | ||
} | ||
`,u=` | ||
${F} | ||
${C} | ||
`,y=` | ||
${I} | ||
${x} | ||
query getContentF($identifiers: [HasMetafieldsIdentifier!]!) { | ||
@@ -167,2 +167,2 @@ shop { | ||
} | ||
`;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}); | ||
`;var p=class{constructor(e,n){this.request=async(e,n)=>(await(await fetch(this.url,{method:"POST",body:JSON.stringify({query:e,variables:n||{}}),headers:{...this.headers||{},"Content-Type":"application/json"}})).json()).data;this.url=e,this.headers=n}},h=class{constructor(e,{storefrontName:n,storefrontAccessToken:s,defaultNameSpaces:a}){this.getContentForNamespaces=async(e,n="fra")=>{if(console.log({params:e}),!e.global)return{content:{},params:e};let{shop:{content:s}}=await this.client.request(y,{identifiers:this.buildIdentifiers(e.global.concat(this.defaultNameSpaces),n)}),a=s.reduce((i,t)=>{if(!t)return i;let o=t.namespace.replace(`_${n}`,"");i[o]||Object.assign(i,{[o]:{}});let c={itemID:t.id,itemType:t.type,itemProp:`${t.namespace}:${t.key}`},l;switch(t.type){case"collection_reference":{l={attributes:c,collection:{...t.collection,products:f(t.collection.products).map(d=>({...d,variants:f(d.variants)}))}};break}case"file_reference":{t.image.image.alt||(t.image.image.alt=""),l={attributes:c,image:t.image.image};break}case"product_reference":{l={attributes:c,product:{...t.product,variants:f(t.product.variants)}};break}case"list.collection_reference":{l={attributes:c,collections:f(t.values).map(d=>({...d,products:f(d.products).map(S=>({...S,variants:f(S.variants)}))}))};break}case"list.file_reference":{l={attributes:c,images:f(t.values).map(d=>d.image)};break}case"list.product_reference":{l={attributes:c,products:f(t.values).map(d=>({...d,variants:f(d.variants)}))};break}case"json":{l={attributes:c,[t.key]:JSON.parse(t.value)};break}case"list.multi_line_text_field":case"list.single_line_text_field":{l={attributes:c,texts:JSON.parse(t.value)};break}case"multi_line_text_field":case"single_line_text_field":{l={attributes:c,text:t.value};break}}return Object.assign(i[o],{[t.key]:l}),i},{});return{params:e,content:a}};this.t=(e,n="fr",s)=>{let[a,i]=e.split("."),t=()=>{var o;return(o=C(this.config[a],i))==null?void 0:o.default};return s?(console.log({content:s}),s[a][i]||t()):t()};this.buildIdentifiers=(e,n="fra")=>e.reduce((a,i)=>{let t=this.config[i];return Object.keys(t.schema).forEach(o=>{a.push({namespace:`${i}_${n}`,key:o})}),a},[]);this.config=e,this.defaultNameSpaces=a||[],this.client=new p(`https://${n}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":s})}},f=r=>r.edges.reduce((e,{node:n})=>(e.push(n),e),[]),_=r=>r;var $=async(r,{storefrontName:e,storefrontAccessToken:n,adminAccessToken:s},a)=>{console.log(a);let i=new p(`https://${e}.myshopify.com/api/2022-10/graphql.json`,{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":n}),t=new p(`https://${e}.myshopify.com/admin/api/2022-10/graphql.json`,{"X-Shopify-Access-Token":s}),{shop:{id:o}}=await i.request(u);return await t.request(g,{value:JSON.stringify(r),key:a,ownerId:o})};0&&(module.exports={GraphqlClient,MetaCms,collectionFragment,config,contentQuery,getMetaCMSConfigQuery,getOwnerIdQuery,imageFragment,mediaImageFragment,normalizeEdges,productFragment,setMetaCMSConfigMutation,syncConfig}); |
{ | ||
"name": "@meta-cms/core", | ||
"version": "1.0.37", | ||
"version": "1.0.38", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
21213
529