@chaibuilder/pages 0.1.0-beta.86 → 0.1.0-beta.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +3 -5
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var p=(t,a,i)=>a in t?m(t,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[a]=i;var l=(t,a,i)=>p(t,typeof a!="symbol"?a+"":a,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("lodash-es"),S="https://api.chaibuilder.com",y=async(t,a,i,n=S)=>{try{const e=new Headers;e.append("x-chai-api-key",a),e.append("x-chai-user",i);const s={headers:e,method:"POST",body:JSON.stringify(t),cache:"no-store"},r=await fetch(n+"/v1/api/chai",s);if(r.ok)return await r.json();{const o=await r.json();throw new Error((o==null?void 0:o.error)||r.statusText)}}catch(e){return{error:e.message}}},k={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},d={},u=(t,a)=>{d[t]={key:t,...a}},g=()=>Object.values(d),h=t=>d[t],f=async(t,a)=>{const i=h(t);return!i||!i.getSeoFields?{}:await i.getSeoFields(a)},E="https://api.chaibuilder.com";class w{constructor(a,i=E){l(this,"currentLang","");l(this,"draftMode",!1);this.apiKey=a,this.apiUrl=i,u("page",{name:"Static Page",icon:'<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M5 8V20H19V8H5ZM5 6H19V4H5V6ZM20 22H4C3.44772 22 3 21.5523 3 21V3C3 2.44772 3.44772 2 4 2H20C20.5523 2 21 2.44772 21 3V21C21 21.5523 20.5523 22 20 22ZM7 10H11V14H7V10ZM7 16H17V18H7V16ZM13 11H17V13H13V11Z"></path></svg>'}),u("global",{name:"Global Block",helpText:"A global block can be reused in multiple pages.",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-globe w-4 h-4 text-slate-500 stroke-[1]"><circle cx="12" cy="12" r="10"></circle><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"></path><path d="M2 12h20"></path></svg>'})}setCurrentLang(a){this.currentLang=a}getCurrentLang(){return this.currentLang}setDraftMode(a){this.draftMode=a}isDraftMode(){return this.draftMode}setLanguageFromSlug(a){const i=c.first(a||[""]);Object.keys(k).includes(i)?this.setCurrentLang(i):this.setCurrentLang("")}defaultMatchSlug(a,i){return a.match(`^${i}`)}async getPageTypeFromSlug(a){return a==="/"||a===`/${this.getCurrentLang()}`,"page"}async handle(a,i){if(a.action==="GET_SEO_FIELDS"){const e=h(a.data.pageType);return e?typeof e.seoFields=="function"?await e.seoFields()??{}:e.seoFields??{}:{error:"Page type not found"}}if(a.action==="GET_PAGE_TYPES"||a.action==="GET_COLLECTIONS")return Promise.all(g().map(async e=>({key:e.key,helpText:e.helpText||"",icon:e.icon||"",name:typeof e.name=="function"?await e.name():e.name})));if(a.action==="SEARCH_COLLECTION_ITEMS"||a.action==="SEARCH_PAGE_TYPE_ITEMS"){const e=h(a.data.pageType);return e?e.search?await e.search(a.data.query):await(await fetch(`${this.apiUrl}/v1/api/chai`,{cache:"no-store",method:"POST",body:JSON.stringify({action:"SEARCH_PAGES",data:{query:a.data.query,pageType:a.data.pageType}}),headers:{"x-chai-api-key":this.apiKey}})).json():{error:"Page type not found"}}const n=await y(a,this.apiKey,i,this.apiUrl);return this.emit(a.action,n),n}emit(a,i){var s,r,o;if(!["CREATE_PAGE","UPDATE_PAGE","DELETE_PAGE"].includes(a))return;const n=c.get(i,"page");if(!n)return;const e=h(n.pageType);if(e)switch(a){case"CREATE_PAGE":return(s=e.onCreate)==null?void 0:s.call(e,n);case"UPDATE_PAGE":return(r=e.onUpdate)==null?void 0:r.call(e,n);case"DELETE_PAGE":return(o=e.onDelete)==null?void 0:o.call(e,n)}}async resolveLink(a,i){const n=h(a);if(!n)return"/not-found";const e=this.isDraftMode(),s=this.getCurrentLang();if(n.resolveLink)return await n.resolveLink(i,e,s);const o=await(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_LINK",data:{pageType:a,id:i,draft:e,...s?{lang:s}:{}}}),headers:{"x-chai-api-key":this.apiKey}})).json();return c.get(o,"link","/not-found")}async getPageBySlug(a,i){const n={};return g().forEach(s=>{c.has(s,"dynamicSegments")&&s.dynamicSegments&&(n[s.key]=s.dynamicSegments)}),(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE_META",data:{slug:a,draft:i,dynamicSegments:n}}),headers:{"x-chai-api-key":this.apiKey}})).json()}async getFullPage(a,i,n){return(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE",data:{id:a,lang:i,draft:n,mergeGlobal:!0}}),headers:{"x-chai-api-key":this.apiKey}})).json()}async getSiteSettings(a){return(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_WEBSITE_SETTINGS",data:{draft:a}}),headers:{"x-chai-api-key":this.apiKey}})).json()}}exports.ChaiBuilderPages=w;exports.getChaiPageSeoFields=f;exports.getChaiPageType=h;exports.getChaiPageTypes=g;exports.registerChaiPageType=u;
|
package/dist/server.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ declare type ChaiPageTypeSchema = Record<string, any>;
|
|
|
50
50
|
|
|
51
51
|
declare type ChaiPageTypeUiSchema = Record<string, any>;
|
|
52
52
|
|
|
53
|
-
export declare const getChaiPageSeoFields: (params: any) => Promise<Record<string, string>>;
|
|
53
|
+
export declare const getChaiPageSeoFields: (pageType: string, params: any) => Promise<Record<string, string>>;
|
|
54
54
|
|
|
55
55
|
export declare const getChaiPageType: (key: keyof typeof PAGE_TYPES) => ChaiBuilderPageType;
|
|
56
56
|
|
package/dist/server.js
CHANGED
|
@@ -214,9 +214,9 @@ const f = "https://api.chaibuilder.com", y = async (t, a, i, n = f) => {
|
|
|
214
214
|
zu: "Zulu"
|
|
215
215
|
}, l = {}, g = (t, a) => {
|
|
216
216
|
l[t] = { key: t, ...a };
|
|
217
|
-
}, d = () => Object.values(l), h = (t) => l[t], P = async (t) => {
|
|
218
|
-
const
|
|
219
|
-
return !
|
|
217
|
+
}, d = () => Object.values(l), h = (t) => l[t], P = async (t, a) => {
|
|
218
|
+
const i = h(t);
|
|
219
|
+
return !i || !i.getSeoFields ? {} : await i.getSeoFields(a);
|
|
220
220
|
}, E = "https://api.chaibuilder.com";
|
|
221
221
|
class v {
|
|
222
222
|
constructor(a, i = E) {
|
|
@@ -310,7 +310,6 @@ class v {
|
|
|
310
310
|
if (n.resolveLink)
|
|
311
311
|
return await n.resolveLink(i, e, s);
|
|
312
312
|
const o = await (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
313
|
-
cache: "no-store",
|
|
314
313
|
method: "POST",
|
|
315
314
|
body: JSON.stringify({
|
|
316
315
|
action: "GET_LINK",
|
|
@@ -350,7 +349,6 @@ class v {
|
|
|
350
349
|
}
|
|
351
350
|
async getSiteSettings(a) {
|
|
352
351
|
return (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
353
|
-
cache: "no-store",
|
|
354
352
|
method: "POST",
|
|
355
353
|
body: JSON.stringify({
|
|
356
354
|
action: "GET_WEBSITE_SETTINGS",
|