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.3 to 1.0.4

4

client.ts

@@ -101,3 +101,3 @@ import {

t = <P extends Paths<C>>(p: P, locale: "fr" = "fr", params: TParams, content: Content<C>) => {
t = <P extends Paths<C>, Cont extends Content<C>>(p: P, locale: "fr" = "fr", params: TParams, content: Cont) => {
console.log({ params, locale });

@@ -110,3 +110,3 @@ const [ns, ...path] = p.split(".");

// @ts-ignore
return (content[ns as keyof Content][path.join(".")] || defaultValue()) as GetType<P>;
return (content[ns as keyof Cont][path.join(".")] || defaultValue()) as GetType<C, P>;
};

@@ -113,0 +113,0 @@

@@ -126,3 +126,3 @@ import { Get } from 'type-fest';

declare type ConfigType = "json" | "file" | "product" | "collection" | "object";
declare type GetConfigType<C extends Config, P extends Paths<C>> = Split<P>[2] extends undefined ? Split<P>[1] extends keyof C[Split<P>[0]] ? C[Split<P>[0]]["type"] : never : Split<P>[1] extends keyof C[Split<P>[0]] ? C[Split<P>[0]][Split<P>[1]] extends ObjectConfig ? Split<P>[2] extends keyof C[Split<P>[0]][Split<P>[1]]["config"] ? C[Split<P>[0]][Split<P>[1]]["config"][Split<P>[2]]["type"] : never : never : never;
declare type GetConfigType<C extends Config, P extends Paths<C>> = Split<P>[2] extends undefined ? Split<P>[1] extends keyof C[Split<P>[0]] ? C[Split<P>[0]][Split<P>[1]]["type"] : never : Split<P>[1] extends keyof C[Split<P>[0]] ? C[Split<P>[0]][Split<P>[1]] extends ObjectConfig ? Split<P>[2] extends keyof C[Split<P>[0]][Split<P>[1]]["config"] ? C[Split<P>[0]][Split<P>[1]]["config"][Split<P>[2]]["type"] : never : never : never;
declare type isList<C extends Config, P extends Paths<C>> = Split<P>[2] extends undefined ? C[Split<P>[0]][Split<P>[1]]["isList"] : Get<Get<Get<C[Split<P>[0]][Split<P>[1]], "config">, [Split<P>[2]]>, "isList">;

@@ -226,10 +226,11 @@ declare type toList<C extends Config, P extends Paths<C>, T> = isList<C, P> extends true ? T[] : T;

declare class MetaCms {
config: Config;
declare class MetaCms<C extends Config> {
config: C;
client: GraphQLClient;
constructor(config: Config, { storefrontName, storefrontAcessToken }: MetaCMSConfig);
getContentForNamespaces: (namespaces: Namespaces<typeof this$1.config>[], locale?: "fra") => Promise<Content<Config>>;
t: <P extends `${string}.${string}`>(p: P, locale: "fr" | undefined, params: TParams, content: Content<typeof this$1.config>) => any;
constructor(config: C, { storefrontName, storefrontAcessToken }: MetaCMSConfig);
getContentForNamespaces: (namespaces: Namespaces<C>[], locale?: "fra") => Promise<Content<C>>;
t: <P extends Paths<C>, Cont extends Content<C>>(p: P, locale: "fr" | undefined, params: TParams, content: Cont) => GetType<C, P>;
buildIdentifiers: (namespaces: Namespaces<C>[], locale?: "fra") => Identifier[];
}
export { ArrayKeys, CollectionContent, Config, ConfigElement, ConfigType, Content, GetConfigType, GetType, Identifier, ImageContent, Last, MetaCMSConfig, MetaCms, MetafieldCollection, MetafieldContent, MetafieldImage, MetafieldProduct, MetafieldVariant, Namespaces, Nodes, PathForNamespace, Paths, Price, PriceContent, PriceVariation, PriceVariationContent, ProductContent, Split, TParams, TextContent, VariantContent, WithEdge, isList, toList };

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

"use strict";var T=Object.create;var m=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var $=(n,t)=>{for(var i in t)m(n,i,{get:t[i],enumerable:!0})},P=(n,t,i,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of M(t))!I.call(n,s)&&s!==i&&m(n,s,{get:()=>t[s],enumerable:!(a=b(t,s))||a.enumerable});return n};var k=(n,t,i)=>(i=n!=null?T(v(n)):{},P(t||!n||!n.__esModule?m(i,"default",{value:n,enumerable:!0}):i,n)),F=n=>P(m({},"__esModule",{value:!0}),n);var _={};$(_,{MetaCms:()=>u});module.exports=F(_);var h=require("graphql-request");var x=`
"use strict";var F=Object.create;var C=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var O=(i,n)=>{for(var s in n)C(i,s,{get:n[s],enumerable:!0})},h=(i,n,s,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of T(n))!b.call(i,t)&&t!==s&&C(i,t,{get:()=>n[t],enumerable:!(r=I(n,t))||r.enumerable});return i};var j=(i,n,s)=>(s=i!=null?F(_(i)):{},h(n||!i||!i.__esModule?C(s,"default",{value:i,enumerable:!0}):s,i)),x=i=>h(C({},"__esModule",{value:!0}),i);var v={};O(v,{MetaCms:()=>m});module.exports=x(v);var P=require("graphql-request");var y=`
query getContentF($identifiers: [HasMetafieldsIdentifier!]!) {

@@ -133,2 +133,2 @@ shop {

}
`;var S=k(require("just-safe-get")),u=class{constructor(t,{storefrontName:i,storefrontAcessToken:a}){this.getContentForNamespaces=(t,i="fra")=>N(this.config,this.client,t,i);this.t=(t,i="fr",a,s)=>{console.log({params:a,locale:i});let[o,...e]=t.split("."),r=()=>(0,S.default)(this.config[o],e).default;return s&&s[o][e.join(".")]||r()};this.config=t,this.client=new h.GraphQLClient(`https://${i}.myshopify.com/api/2022-10/graphql.json`,{headers:{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":a}})}},N=async(n,t,i,a="fra")=>{let{shop:{content:s}}=await t.request(x,{identifiers:V(n,i,a)});return s.reduce((o,e)=>{var d,p,g,C;if(!e)return o;let r=e.namespace.replace(`_${a}`,"");if(o[r]||Object.assign(o,{[r]:{}}),(d=e.image)!=null&&d.image)Object.assign(o[r],{[e.key]:e.image.image});else if((p=e.product)!=null&&p.descriptionHtml)Object.assign(o[r],{[e.key]:{...e.product,variants:f(e.product.variants)}});else if((g=e.collection)!=null&&g.products)Object.assign(o[r],{[e.key]:{...e.collection,products:f(e.collection.products)}});else if((C=e.values)!=null&&C.edges.length){let c=f(e.values),[y]=c;y.__typename==="Collection"?Object.assign(o[r],{[e.key]:c.map(l=>({...l,products:f(l.products)}))}):y.__typename==="MediaImage"?Object.assign(o[r],{[e.key]:c.map(l=>l.image)}):Object.assign(o[r],{[e.key]:c.map(l=>({...l,variants:f(l.variants)}))})}else if(e.type==="list.single_line_text_field"){let c=JSON.parse(e.value).map((y,l)=>({id:`${e.id}#${l}`,dangerouslySetInnerHTML:{__html:y}}));Object.assign(o[r],{[e.key]:c})}else{let c={id:e.id,dangerouslySetInnerHTML:{__html:e.value}};Object.assign(o[r],{[e.key]:c})}return o},{})},f=n=>n.edges.reduce((t,{node:i})=>(t.push(i),t),[]),V=(n,t,i="fra")=>t.reduce((s,o)=>{let e=n[o];return Object.entries(e).reduce((d,[p,g])=>(g.config?Object.keys(g.config).forEach(C=>{d.push(`${p}.${C}`)}):d.push(p),d),[]).forEach(d=>{s.push({namespace:`${o}_${i}`,key:d})}),s},[]);0&&(module.exports={MetaCms});
`;var M=j(require("just-safe-get")),m=class{constructor(n,{storefrontName:s,storefrontAcessToken:r}){this.getContentForNamespaces=async(n,s="fra")=>{let{shop:{content:r}}=await this.client.request(y,{identifiers:this.buildIdentifiers(n,s)});return r.reduce((t,e)=>{var c,l,f,g;if(!e)return t;let a=e.namespace.replace(`_${s}`,"");if(t[a]||Object.assign(t,{[a]:{}}),(c=e.image)!=null&&c.image)Object.assign(t[a],{[e.key]:e.image.image});else if((l=e.product)!=null&&l.descriptionHtml)Object.assign(t[a],{[e.key]:{...e.product,variants:p(e.product.variants)}});else if((f=e.collection)!=null&&f.products)Object.assign(t[a],{[e.key]:{...e.collection,products:p(e.collection.products)}});else if((g=e.values)!=null&&g.edges.length){let o=p(e.values),[u]=o;u.__typename==="Collection"?Object.assign(t[a],{[e.key]:o.map(d=>({...d,products:p(d.products)}))}):u.__typename==="MediaImage"?Object.assign(t[a],{[e.key]:o.map(d=>d.image)}):Object.assign(t[a],{[e.key]:o.map(d=>({...d,variants:p(d.variants)}))})}else if(e.type==="list.single_line_text_field"){let o=JSON.parse(e.value).map((u,d)=>({id:`${e.id}#${d}`,dangerouslySetInnerHTML:{__html:u}}));Object.assign(t[a],{[e.key]:o})}else{let o={id:e.id,dangerouslySetInnerHTML:{__html:e.value}};Object.assign(t[a],{[e.key]:o})}return t},{})};this.t=(n,s="fr",r,t)=>{console.log({params:r,locale:s});let[e,...a]=n.split("."),c=()=>(0,M.default)(this.config[e],a).default;return t&&t[e][a.join(".")]||c()};this.buildIdentifiers=(n,s="fra")=>n.reduce((t,e)=>{let a=this.config[e];return Object.entries(a).reduce((l,[f,g])=>(g.config?Object.keys(g.config).forEach(o=>{l.push(`${f}.${o}`)}):l.push(f),l),[]).forEach(l=>{t.push({namespace:`${e}_${s}`,key:l})}),t},[]);this.config=n,this.client=new P.GraphQLClient(`https://${s}.myshopify.com/api/2022-10/graphql.json`,{headers:{"X-SHOPIFY-STOREFRONT-ACCESS-TOKEN":r}})}},p=i=>i.edges.reduce((n,{node:s})=>(n.push(s),n),[]);0&&(module.exports={MetaCms});
{
"name": "@meta-cms/core",
"version": "1.0.3",
"version": "1.0.4",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -174,3 +174,3 @@ import { Get } from "type-fest";

? Split<P>[1] extends keyof C[Split<P>[0]]
? C[Split<P>[0]]["type"]
? C[Split<P>[0]][Split<P>[1]]["type"]
: never

@@ -211,17 +211,2 @@ : Split<P>[1] extends keyof C[Split<P>[0]]

const config = <const>{
header: <const>{
title: <const>{
type: "string"
},
object: <const>{
type: "object",
config: <const>{
image: {
type: "image"
}
}
}
}
};
export type Identifier = { namespace: string; key: string };

@@ -313,2 +298,18 @@ export type MetaCMSConfig = {

// const config = {
// header: {
// title: {
// type: "string"
// },
// object: {
// type: "object",
// config: {
// ze: {
// type: "image"
// }
// }
// }
// }
// } as const;
// type CONFIG = typeof config;

@@ -319,4 +320,4 @@ // type simple = Simplify<CONFIG>;

// type paths = Paths<CONFIG>;
// type typ = GetConfigType<CONFIG, "header.object.image">;
// type typp = GetType<CONFIG, "header.object.image">;
// type typ = GetConfigType<CONFIG, "header.title">;
// type typp = GetType<CONFIG, "header.object.ze">;

@@ -323,0 +324,0 @@ export type TParams = {

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