@chaibuilder/pages 0.1.0-beta.44 → 0.1.0-beta.45
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.js +29 -29
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var S=(t,a,i)=>a in t?p(t,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[a]=i;var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var S=(t,a,i)=>a in t?p(t,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[a]=i;var c=(t,a,i)=>S(t,typeof a!="symbol"?a+"":a,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("lodash-es"),y="https://api.chaibuilder.com",k=async(t,a,i=y)=>{try{const e=new Headers;e.append("x-chai-api-key",a);const n={headers:e,method:"POST",body:JSON.stringify(t)},s=await fetch(i+"/v1/api/chai",n);if(s.ok)return await s.json();{const r=await s.json();throw new Error((r==null?void 0:r.error)||s.statusText)}}catch(e){return{error:e.message}}},g={},d=(t,a)=>{g[t]={key:t,...a}},m=()=>Object.values(g),u=t=>g[t],f={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"},h="https://api.chaibuilder.com";class E{constructor(a,i=h){c(this,"currentLang","");c(this,"draftMode",!1);this.apiKey=a,this.apiUrl=i,d("page",{name:"Page",baseSlug:{FALLBACK:""}})}setCurrentLang(a){this.currentLang=a}getCurrentLang(){return this.currentLang}setDraftMode(a){this.draftMode=a}isDraftMode(){return this.draftMode}setLanguageFromSlug(a){const i=l.first(a||[""]);Object.keys(f).includes(i)?this.setCurrentLang(i):this.setCurrentLang("")}async handle(a){if(a.action==="GET_COLLECTIONS")return Promise.all(m().map(async e=>({key:e.key,name:e.name,slugParam:e.slugParam,baseSlug:typeof e.baseSlug=="function"?await e.baseSlug():e.baseSlug})));if(a.action==="SEARCH_COLLECTION_ITEMS"){const e=u(a.data.collection);return e?e.search?await e.search(a.data.query):await(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"SEARCH_PAGES",data:{query:a.data.query,collection:a.data.collection}}),headers:{"x-chai-api-key":this.apiKey}})).json():{error:"Collection not found"}}const i=await k(a,this.apiKey,this.apiUrl);return this.emit(a.action,i),i}emit(a,i){var s,r,o;if(!["CREATE_PAGE","UPDATE_PAGE","DELETE_PAGE"].includes(a))return;const e=l.get(i,"page");if(!e)return;const n=u(e.collection);if(n)switch(a){case"CREATE_PAGE":return(s=n.onCreate)==null?void 0:s.call(n,e);case"UPDATE_PAGE":return(r=n.onUpdate)==null?void 0:r.call(n,e);case"DELETE_PAGE":return(o=n.onDelete)==null?void 0:o.call(n,e)}}async resolveLink(a,i){const e=u(a);if(!e)return"/not-found";const n=this.isDraftMode(),s=this.getCurrentLang();if(e.resolveLink)return await e.resolveLink(i,n,s);const o=await(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_LINK",data:{collection:a,id:i,draft:n,...s?{lang:s}:{}}}),headers:{"x-chai-api-key":this.apiKey}})).json();return l.get(o,"link","/not-found")}async getPageBySlug(a,i){return(await fetch(`${h}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE_META",data:{slug:a,draft:i}}),headers:{"x-chai-api-key":this.apiKey}})).json()}async getFullPage(a,i,e){return(await fetch(`${h}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE",data:{id:a,lang:i,draft:e,mergeGlobal:!0}}),headers:{"x-chai-api-key":this.apiKey}})).json()}async getSiteSettings(a){return(await fetch(`${h}/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=E;exports.getCollection=u;exports.getCollections=m;exports.registerCollection=d;
|
package/dist/server.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
|
-
var m = (t, a,
|
|
3
|
-
var u = (t, a,
|
|
2
|
+
var m = (t, a, i) => a in t ? d(t, a, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[a] = i;
|
|
3
|
+
var u = (t, a, i) => m(t, typeof a != "symbol" ? a + "" : a, i);
|
|
4
4
|
import { first as p, get as g } from "lodash-es";
|
|
5
|
-
const S = "https://api.chaibuilder.com", k = async (t, a,
|
|
5
|
+
const S = "https://api.chaibuilder.com", k = async (t, a, i = S) => {
|
|
6
6
|
try {
|
|
7
7
|
const e = new Headers();
|
|
8
8
|
e.append("x-chai-api-key", a);
|
|
9
|
-
const
|
|
9
|
+
const n = {
|
|
10
10
|
headers: e,
|
|
11
11
|
method: "POST",
|
|
12
12
|
body: JSON.stringify(t)
|
|
13
13
|
}, s = await fetch(
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
i + "/v1/api/chai",
|
|
15
|
+
n
|
|
16
16
|
);
|
|
17
17
|
if (s.ok)
|
|
18
18
|
return await s.json();
|
|
@@ -213,12 +213,12 @@ const S = "https://api.chaibuilder.com", k = async (t, a, n = S) => {
|
|
|
213
213
|
yo: "Yoruba",
|
|
214
214
|
za: "Zhuang, Chuang",
|
|
215
215
|
zu: "Zulu"
|
|
216
|
-
}, h = "
|
|
216
|
+
}, h = "https://api.chaibuilder.com";
|
|
217
217
|
class w {
|
|
218
|
-
constructor(a,
|
|
218
|
+
constructor(a, i = h) {
|
|
219
219
|
u(this, "currentLang", "");
|
|
220
220
|
u(this, "draftMode", !1);
|
|
221
|
-
this.apiKey = a, this.apiUrl =
|
|
221
|
+
this.apiKey = a, this.apiUrl = i, y("page", {
|
|
222
222
|
name: "Page",
|
|
223
223
|
baseSlug: { FALLBACK: "" }
|
|
224
224
|
});
|
|
@@ -236,8 +236,8 @@ class w {
|
|
|
236
236
|
return this.draftMode;
|
|
237
237
|
}
|
|
238
238
|
setLanguageFromSlug(a) {
|
|
239
|
-
const
|
|
240
|
-
Object.keys(E).includes(
|
|
239
|
+
const i = p(a || [""]);
|
|
240
|
+
Object.keys(E).includes(i) ? this.setCurrentLang(i) : this.setCurrentLang("");
|
|
241
241
|
}
|
|
242
242
|
async handle(a) {
|
|
243
243
|
if (a.action === "GET_COLLECTIONS")
|
|
@@ -262,42 +262,42 @@ class w {
|
|
|
262
262
|
headers: { "x-chai-api-key": this.apiKey }
|
|
263
263
|
})).json() : { error: "Collection not found" };
|
|
264
264
|
}
|
|
265
|
-
const
|
|
266
|
-
return this.emit(a.action,
|
|
265
|
+
const i = await k(a, this.apiKey, this.apiUrl);
|
|
266
|
+
return this.emit(a.action, i), i;
|
|
267
267
|
}
|
|
268
|
-
emit(a,
|
|
268
|
+
emit(a, i) {
|
|
269
269
|
var s, r, o;
|
|
270
270
|
if (!["CREATE_PAGE", "UPDATE_PAGE", "DELETE_PAGE"].includes(a))
|
|
271
271
|
return;
|
|
272
|
-
const e = g(
|
|
272
|
+
const e = g(i, "page");
|
|
273
273
|
if (!e)
|
|
274
274
|
return;
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
275
|
+
const n = c(e.collection);
|
|
276
|
+
if (n)
|
|
277
277
|
switch (a) {
|
|
278
278
|
case "CREATE_PAGE":
|
|
279
|
-
return (s =
|
|
279
|
+
return (s = n.onCreate) == null ? void 0 : s.call(n, e);
|
|
280
280
|
case "UPDATE_PAGE":
|
|
281
|
-
return (r =
|
|
281
|
+
return (r = n.onUpdate) == null ? void 0 : r.call(n, e);
|
|
282
282
|
case "DELETE_PAGE":
|
|
283
|
-
return (o =
|
|
283
|
+
return (o = n.onDelete) == null ? void 0 : o.call(n, e);
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
async resolveLink(a,
|
|
286
|
+
async resolveLink(a, i) {
|
|
287
287
|
const e = c(a);
|
|
288
288
|
if (!e)
|
|
289
289
|
return "/not-found";
|
|
290
|
-
const
|
|
290
|
+
const n = this.isDraftMode(), s = this.getCurrentLang();
|
|
291
291
|
if (e.resolveLink)
|
|
292
|
-
return await e.resolveLink(
|
|
292
|
+
return await e.resolveLink(i, n, s);
|
|
293
293
|
const o = await (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
294
294
|
method: "POST",
|
|
295
295
|
body: JSON.stringify({
|
|
296
296
|
action: "GET_LINK",
|
|
297
297
|
data: {
|
|
298
298
|
collection: a,
|
|
299
|
-
id:
|
|
300
|
-
draft:
|
|
299
|
+
id: i,
|
|
300
|
+
draft: n,
|
|
301
301
|
...s ? { lang: s } : {}
|
|
302
302
|
}
|
|
303
303
|
}),
|
|
@@ -305,22 +305,22 @@ class w {
|
|
|
305
305
|
})).json();
|
|
306
306
|
return g(o, "link", "/not-found");
|
|
307
307
|
}
|
|
308
|
-
async getPageBySlug(a,
|
|
308
|
+
async getPageBySlug(a, i) {
|
|
309
309
|
return (await fetch(`${h}/v1/api/chai`, {
|
|
310
310
|
method: "POST",
|
|
311
311
|
body: JSON.stringify({
|
|
312
312
|
action: "GET_PAGE_META",
|
|
313
|
-
data: { slug: a, draft:
|
|
313
|
+
data: { slug: a, draft: i }
|
|
314
314
|
}),
|
|
315
315
|
headers: { "x-chai-api-key": this.apiKey }
|
|
316
316
|
})).json();
|
|
317
317
|
}
|
|
318
|
-
async getFullPage(a,
|
|
318
|
+
async getFullPage(a, i, e) {
|
|
319
319
|
return (await fetch(`${h}/v1/api/chai`, {
|
|
320
320
|
method: "POST",
|
|
321
321
|
body: JSON.stringify({
|
|
322
322
|
action: "GET_PAGE",
|
|
323
|
-
data: { id: a, lang:
|
|
323
|
+
data: { id: a, lang: i, draft: e, mergeGlobal: !0 }
|
|
324
324
|
}),
|
|
325
325
|
headers: { "x-chai-api-key": this.apiKey }
|
|
326
326
|
})).json();
|