@chaibuilder/pages 0.1.0-beta.55 → 0.1.0-beta.57
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 +6 -4
- package/dist/server.js +63 -49
- package/package.json +3 -3
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var S=Object.defineProperty;var p=(s,a,n)=>a in s?S(s,a,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[a]=n;var c=(s,a,n)=>p(s,typeof a!="symbol"?a+"":a,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("lodash-es"),y="https://api.chaibuilder.com",f=async(s,a,n=y)=>{try{const e=new Headers;e.append("x-chai-api-key",a);const i={headers:e,method:"POST",body:JSON.stringify(s)},t=await fetch(n+"/v1/api/chai",i);if(t.ok)return await t.json();{const r=await t.json();throw new Error((r==null?void 0:r.error)||t.statusText)}}catch(e){return{error:e.message}}},d={},m=(s,a)=>{d[s]={key:s,...a}},g=()=>Object.values(d),u=s=>d[s],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"},h="https://api.chaibuilder.com";class b{constructor(a,n=h){c(this,"currentLang","");c(this,"draftMode",!1);this.apiKey=a,this.apiUrl=n,m("page",{name:"Page",baseSlug:{DEFAULT:""}})}setCurrentLang(a){this.currentLang=a}getCurrentLang(){return this.currentLang}setDraftMode(a){this.draftMode=a}isDraftMode(){return this.draftMode}setLanguageFromSlug(a){const n=l.first(a||[""]);Object.keys(k).includes(n)?this.setCurrentLang(n):this.setCurrentLang("")}defaultMatchSlug(a,n){return Object.keys(n).some(e=>a.match(`^${n[e]}`))}async getCollectionFromSlug(a){var e;const n=await g();for(const i of n){if(i.key==="page")continue;const t=typeof i.baseSlug=="function"?await i.baseSlug():i.baseSlug;if((e=i.matchSlug)!=null&&e.call(i,a,t)||this.defaultMatchSlug(a,t))return i.key}return"page"}async handle(a){if(a.action==="GET_COLLECTIONS")return Promise.all(g().map(async e=>({key:e.key,name:typeof e.name=="function"?await e.name():e.name,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 n=await f(a,this.apiKey,this.apiUrl);return this.emit(a.action,n),n}emit(a,n){var t,r,o;if(!["CREATE_PAGE","UPDATE_PAGE","DELETE_PAGE"].includes(a))return;const e=l.get(n,"page");if(!e)return;const i=u(e.collection);if(i)switch(a){case"CREATE_PAGE":return(t=i.onCreate)==null?void 0:t.call(i,e);case"UPDATE_PAGE":return(r=i.onUpdate)==null?void 0:r.call(i,e);case"DELETE_PAGE":return(o=i.onDelete)==null?void 0:o.call(i,e)}}async resolveLink(a,n){const e=u(a);if(!e)return"/not-found";const i=this.isDraftMode(),t=this.getCurrentLang();if(e.resolveLink)return await e.resolveLink(n,i,t);const o=await(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_LINK",data:{collection:a,id:n,draft:i,...t?{lang:t}:{}}}),headers:{"x-chai-api-key":this.apiKey}})).json();return l.get(o,"link","/not-found")}async getPageBySlug(a,n,e){return(await fetch(`${h}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE_META",data:{slug:a,draft:n,collection:e}}),headers:{"x-chai-api-key":this.apiKey}})).json()}async getFullPage(a,n,e){return(await fetch(`${h}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE",data:{id:a,lang:n,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=b;exports.getCollection=u;exports.getCollections=g;exports.registerCollection=m;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export declare type ChaiBuilderCollection = {
|
|
2
2
|
key: string;
|
|
3
|
-
name: string;
|
|
4
|
-
slugParam?: string;
|
|
3
|
+
name: string | (() => Promise<string>);
|
|
5
4
|
baseSlug: Record<LanguageCode, string> | (() => Promise<Record<LanguageCode, string>>);
|
|
6
5
|
search?: (query: string) => Promise<CollectionSearchResult[] | Error>;
|
|
7
6
|
resolveLink?: (id: string, draft?: boolean, lang?: string) => Promise<string>;
|
|
@@ -10,6 +9,7 @@ export declare type ChaiBuilderCollection = {
|
|
|
10
9
|
onDelete?: (data: Pick<ChaiBuilderPage, "id">) => Promise<void>;
|
|
11
10
|
schema?: ChaiCollectionSchema;
|
|
12
11
|
uiSchema?: ChaiCollectionUiSchema;
|
|
12
|
+
matchSlug?: (slug: string, baseSlug: Record<LanguageCode, string>) => Promise<boolean>;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export declare type ChaiBuilderPage = {
|
|
@@ -32,10 +32,12 @@ export declare class ChaiBuilderPages {
|
|
|
32
32
|
setDraftMode(draft: boolean): void;
|
|
33
33
|
isDraftMode(): boolean;
|
|
34
34
|
setLanguageFromSlug(slug: string[]): void;
|
|
35
|
+
defaultMatchSlug(slug: string, baseSlug: Record<string, string>): boolean;
|
|
36
|
+
getCollectionFromSlug(slug: string): Promise<string>;
|
|
35
37
|
handle(body: any): Promise<any>;
|
|
36
38
|
emit(action: string, data: any): Promise<void> | undefined;
|
|
37
39
|
resolveLink(collectionKey: string, id: string): Promise<any>;
|
|
38
|
-
getPageBySlug(slug: string, draft: boolean): Promise<any>;
|
|
40
|
+
getPageBySlug(slug: string, draft: boolean, collection?: string): Promise<any>;
|
|
39
41
|
getFullPage(id: string, lang: string, draft: boolean): Promise<any>;
|
|
40
42
|
getSiteSettings(draft: boolean): Promise<any>;
|
|
41
43
|
}
|
|
@@ -56,7 +58,7 @@ export declare const getCollection: (key: keyof typeof COLLECTIONS) => ChaiBuild
|
|
|
56
58
|
|
|
57
59
|
export declare const getCollections: () => ChaiBuilderCollection[];
|
|
58
60
|
|
|
59
|
-
declare type LanguageCode = "
|
|
61
|
+
declare type LanguageCode = "DEFAULT" | string;
|
|
60
62
|
|
|
61
63
|
export declare const registerCollection: (key: string, collection: Omit<ChaiBuilderCollection, "key">) => void;
|
|
62
64
|
|
package/dist/server.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var u = (
|
|
4
|
-
import { first as
|
|
5
|
-
const
|
|
1
|
+
var m = Object.defineProperty;
|
|
2
|
+
var p = (s, a, n) => a in s ? m(s, a, { enumerable: !0, configurable: !0, writable: !0, value: n }) : s[a] = n;
|
|
3
|
+
var u = (s, a, n) => p(s, typeof a != "symbol" ? a + "" : a, n);
|
|
4
|
+
import { first as S, get as g } from "lodash-es";
|
|
5
|
+
const f = "https://api.chaibuilder.com", y = async (s, a, n = f) => {
|
|
6
6
|
try {
|
|
7
7
|
const e = new Headers();
|
|
8
8
|
e.append("x-chai-api-key", a);
|
|
9
|
-
const
|
|
9
|
+
const i = {
|
|
10
10
|
headers: e,
|
|
11
11
|
method: "POST",
|
|
12
|
-
body: JSON.stringify(
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
body: JSON.stringify(s)
|
|
13
|
+
}, t = await fetch(
|
|
14
|
+
n + "/v1/api/chai",
|
|
15
|
+
i
|
|
16
16
|
);
|
|
17
|
-
if (
|
|
18
|
-
return await
|
|
17
|
+
if (t.ok)
|
|
18
|
+
return await t.json();
|
|
19
19
|
{
|
|
20
|
-
const r = await
|
|
21
|
-
throw new Error((r == null ? void 0 : r.error) ||
|
|
20
|
+
const r = await t.json();
|
|
21
|
+
throw new Error((r == null ? void 0 : r.error) || t.statusText);
|
|
22
22
|
}
|
|
23
23
|
} catch (e) {
|
|
24
24
|
return { error: e.message };
|
|
25
25
|
}
|
|
26
|
-
}, l = {},
|
|
27
|
-
l[
|
|
28
|
-
},
|
|
26
|
+
}, l = {}, k = (s, a) => {
|
|
27
|
+
l[s] = { key: s, ...a };
|
|
28
|
+
}, d = () => Object.values(l), c = (s) => l[s], b = {
|
|
29
29
|
ab: "Abkhazian",
|
|
30
30
|
aa: "Afar",
|
|
31
31
|
af: "Afrikaans",
|
|
@@ -214,13 +214,13 @@ const S = "https://api.chaibuilder.com", k = async (t, a, i = S) => {
|
|
|
214
214
|
za: "Zhuang, Chuang",
|
|
215
215
|
zu: "Zulu"
|
|
216
216
|
}, h = "https://api.chaibuilder.com";
|
|
217
|
-
class
|
|
218
|
-
constructor(a,
|
|
217
|
+
class T {
|
|
218
|
+
constructor(a, n = h) {
|
|
219
219
|
u(this, "currentLang", "");
|
|
220
220
|
u(this, "draftMode", !1);
|
|
221
|
-
this.apiKey = a, this.apiUrl =
|
|
221
|
+
this.apiKey = a, this.apiUrl = n, k("page", {
|
|
222
222
|
name: "Page",
|
|
223
|
-
baseSlug: {
|
|
223
|
+
baseSlug: { DEFAULT: "" }
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
setCurrentLang(a) {
|
|
@@ -236,16 +236,30 @@ class w {
|
|
|
236
236
|
return this.draftMode;
|
|
237
237
|
}
|
|
238
238
|
setLanguageFromSlug(a) {
|
|
239
|
-
const
|
|
240
|
-
Object.keys(
|
|
239
|
+
const n = S(a || [""]);
|
|
240
|
+
Object.keys(b).includes(n) ? this.setCurrentLang(n) : this.setCurrentLang("");
|
|
241
|
+
}
|
|
242
|
+
defaultMatchSlug(a, n) {
|
|
243
|
+
return Object.keys(n).some((e) => a.match(`^${n[e]}`));
|
|
244
|
+
}
|
|
245
|
+
async getCollectionFromSlug(a) {
|
|
246
|
+
var e;
|
|
247
|
+
const n = await d();
|
|
248
|
+
for (const i of n) {
|
|
249
|
+
if (i.key === "page")
|
|
250
|
+
continue;
|
|
251
|
+
const t = typeof i.baseSlug == "function" ? await i.baseSlug() : i.baseSlug;
|
|
252
|
+
if ((e = i.matchSlug) != null && e.call(i, a, t) || this.defaultMatchSlug(a, t))
|
|
253
|
+
return i.key;
|
|
254
|
+
}
|
|
255
|
+
return "page";
|
|
241
256
|
}
|
|
242
257
|
async handle(a) {
|
|
243
258
|
if (a.action === "GET_COLLECTIONS")
|
|
244
259
|
return Promise.all(
|
|
245
|
-
|
|
260
|
+
d().map(async (e) => ({
|
|
246
261
|
key: e.key,
|
|
247
|
-
name: e.name,
|
|
248
|
-
slugParam: e.slugParam,
|
|
262
|
+
name: typeof e.name == "function" ? await e.name() : e.name,
|
|
249
263
|
baseSlug: typeof e.baseSlug == "function" ? await e.baseSlug() : e.baseSlug
|
|
250
264
|
}))
|
|
251
265
|
);
|
|
@@ -262,65 +276,65 @@ class w {
|
|
|
262
276
|
headers: { "x-chai-api-key": this.apiKey }
|
|
263
277
|
})).json() : { error: "Collection not found" };
|
|
264
278
|
}
|
|
265
|
-
const
|
|
266
|
-
return this.emit(a.action,
|
|
279
|
+
const n = await y(a, this.apiKey, this.apiUrl);
|
|
280
|
+
return this.emit(a.action, n), n;
|
|
267
281
|
}
|
|
268
|
-
emit(a,
|
|
269
|
-
var
|
|
282
|
+
emit(a, n) {
|
|
283
|
+
var t, r, o;
|
|
270
284
|
if (!["CREATE_PAGE", "UPDATE_PAGE", "DELETE_PAGE"].includes(a))
|
|
271
285
|
return;
|
|
272
|
-
const e = g(
|
|
286
|
+
const e = g(n, "page");
|
|
273
287
|
if (!e)
|
|
274
288
|
return;
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
289
|
+
const i = c(e.collection);
|
|
290
|
+
if (i)
|
|
277
291
|
switch (a) {
|
|
278
292
|
case "CREATE_PAGE":
|
|
279
|
-
return (
|
|
293
|
+
return (t = i.onCreate) == null ? void 0 : t.call(i, e);
|
|
280
294
|
case "UPDATE_PAGE":
|
|
281
|
-
return (r =
|
|
295
|
+
return (r = i.onUpdate) == null ? void 0 : r.call(i, e);
|
|
282
296
|
case "DELETE_PAGE":
|
|
283
|
-
return (o =
|
|
297
|
+
return (o = i.onDelete) == null ? void 0 : o.call(i, e);
|
|
284
298
|
}
|
|
285
299
|
}
|
|
286
|
-
async resolveLink(a,
|
|
300
|
+
async resolveLink(a, n) {
|
|
287
301
|
const e = c(a);
|
|
288
302
|
if (!e)
|
|
289
303
|
return "/not-found";
|
|
290
|
-
const
|
|
304
|
+
const i = this.isDraftMode(), t = this.getCurrentLang();
|
|
291
305
|
if (e.resolveLink)
|
|
292
|
-
return await e.resolveLink(
|
|
306
|
+
return await e.resolveLink(n, i, t);
|
|
293
307
|
const o = await (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
294
308
|
method: "POST",
|
|
295
309
|
body: JSON.stringify({
|
|
296
310
|
action: "GET_LINK",
|
|
297
311
|
data: {
|
|
298
312
|
collection: a,
|
|
299
|
-
id:
|
|
300
|
-
draft:
|
|
301
|
-
...
|
|
313
|
+
id: n,
|
|
314
|
+
draft: i,
|
|
315
|
+
...t ? { lang: t } : {}
|
|
302
316
|
}
|
|
303
317
|
}),
|
|
304
318
|
headers: { "x-chai-api-key": this.apiKey }
|
|
305
319
|
})).json();
|
|
306
320
|
return g(o, "link", "/not-found");
|
|
307
321
|
}
|
|
308
|
-
async getPageBySlug(a,
|
|
322
|
+
async getPageBySlug(a, n, e) {
|
|
309
323
|
return (await fetch(`${h}/v1/api/chai`, {
|
|
310
324
|
method: "POST",
|
|
311
325
|
body: JSON.stringify({
|
|
312
326
|
action: "GET_PAGE_META",
|
|
313
|
-
data: { slug: a, draft:
|
|
327
|
+
data: { slug: a, draft: n, collection: e }
|
|
314
328
|
}),
|
|
315
329
|
headers: { "x-chai-api-key": this.apiKey }
|
|
316
330
|
})).json();
|
|
317
331
|
}
|
|
318
|
-
async getFullPage(a,
|
|
332
|
+
async getFullPage(a, n, e) {
|
|
319
333
|
return (await fetch(`${h}/v1/api/chai`, {
|
|
320
334
|
method: "POST",
|
|
321
335
|
body: JSON.stringify({
|
|
322
336
|
action: "GET_PAGE",
|
|
323
|
-
data: { id: a, lang:
|
|
337
|
+
data: { id: a, lang: n, draft: e, mergeGlobal: !0 }
|
|
324
338
|
}),
|
|
325
339
|
headers: { "x-chai-api-key": this.apiKey }
|
|
326
340
|
})).json();
|
|
@@ -337,8 +351,8 @@ class w {
|
|
|
337
351
|
}
|
|
338
352
|
}
|
|
339
353
|
export {
|
|
340
|
-
|
|
354
|
+
T as ChaiBuilderPages,
|
|
341
355
|
c as getCollection,
|
|
342
|
-
|
|
343
|
-
|
|
356
|
+
d as getCollections,
|
|
357
|
+
k as registerCollection
|
|
344
358
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Suraj Air",
|
|
4
4
|
"license": "Private",
|
|
5
5
|
"homepage": "https://chaibuilder.com",
|
|
6
|
-
"version": "0.1.0-beta.
|
|
6
|
+
"version": "0.1.0-beta.57",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"preview": "vite preview"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@chaibuilder/runtime": "2.0.0-beta.
|
|
62
|
-
"@chaibuilder/sdk": "^2.0.0-beta.
|
|
61
|
+
"@chaibuilder/runtime": "2.0.0-beta.12",
|
|
62
|
+
"@chaibuilder/sdk": "^2.0.0-beta.26",
|
|
63
63
|
"@mhsdesign/jit-browser-tailwindcss": "^0.4.1",
|
|
64
64
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
65
65
|
"@tailwindcss/forms": "^0.5.9",
|