@chaibuilder/pages 0.1.0-beta.14 → 0.1.0-beta.16
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 +2 -2
- package/dist/server.js +28 -28
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var m=(i,e,a)=>e in i?d(i,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[e]=a;var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var m=(i,e,a)=>e in i?d(i,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[e]=a;var h=(i,e,a)=>m(i,typeof e!="symbol"?e+"":e,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("lodash-es"),k="https://api.chaibuilder.com",y=async(i,e)=>{try{const a=new Headers;a.append("x-chai-api-key",e);const s={headers:a,method:"POST",body:JSON.stringify(i)},n=await fetch(k+"/v1/api/chai",s);if(n.ok)return await n.json();throw new Error("Failed to handle request: "+n.status+" : "+n.statusText)}catch(a){return{error:a.message}}},o={},l=(i,e)=>{o[i]={key:i,...e}},c=()=>Object.values(o),r=i=>o[i],p={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"},t="https://api.chaibuilder.com";class S{constructor(e){h(this,"currentLang","");this.apiKey=e,l("pages",{name:"Pages",search:async a=>(await fetch(`${t}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"SEARCH_PAGES",data:{query:a}}),headers:{"x-chai-api-key":this.apiKey}})).json(),resolveLink:async(a,s)=>{const g=await(await fetch(`${t}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_LINK",data:{id:a,lang:s}}),headers:{"x-chai-api-key":this.apiKey}})).json();return u.get(g,"slug","")}})}setCurrentLang(e){this.currentLang=e}getCurrentLang(){return this.currentLang}setLanguageFromSlug(e){const a=u.first(e||[""]),s=Object.keys(p);s.includes(a)||s.some(n=>a.startsWith(n))?this.setCurrentLang(a):this.setCurrentLang("")}async handle(e){if(e.action==="GET_COLLECTIONS")return c().map(a=>({key:a.key,name:a.name,urlIdentifier:a.urlIdentifier}));if(e.action==="SEARCH_COLLECTION_ITEMS"){const a=r(e.data.collection);return a?await(a==null?void 0:a.search(e.data.query)):{error:"Collection not found"}}return await y(e,this.apiKey)}async resolveLink(e,a,s=""){const n=r(e);return n?await(n==null?void 0:n.resolveLink(a,s??this.currentLang)):""}async getPageMeta(e,a=!0){return(await fetch(`${t}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE_META",data:{slug:e,published:a}}),headers:{"x-chai-api-key":this.apiKey}})).json()}async getPage(e,a=!0){return(await fetch(`${t}/v1/api/chai`,{method:"POST",body:JSON.stringify({action:"GET_PAGE",data:{id:e,published:a,mergeGlobal:!0}}),headers:{"x-chai-api-key":this.apiKey}})).json()}}exports.ChaiBuilderPages=S;exports.getCollection=r;exports.getCollections=c;exports.registerCollection=l;
|
package/dist/server.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare class ChaiBuilderPages {
|
|
|
7
7
|
setLanguageFromSlug(slug: string[]): void;
|
|
8
8
|
handle(body: any): Promise<any>;
|
|
9
9
|
resolveLink(collectionKey: string, id: string, lang?: string): Promise<string>;
|
|
10
|
-
getPageMeta(slug: string): Promise<any>;
|
|
11
|
-
getPage(id: string): Promise<any>;
|
|
10
|
+
getPageMeta(slug: string, published?: boolean): Promise<any>;
|
|
11
|
+
getPage(id: string, published?: boolean): Promise<any>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export declare type Collection = {
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var c = Object.defineProperty;
|
|
2
2
|
var l = (n, e, a) => e in n ? c(n, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : n[e] = a;
|
|
3
|
-
var
|
|
3
|
+
var o = (n, e, a) => l(n, typeof e != "symbol" ? e + "" : e, a);
|
|
4
4
|
import { get as g, first as d } from "lodash-es";
|
|
5
5
|
const m = "https://api.chaibuilder.com", k = async (n, e) => {
|
|
6
6
|
try {
|
|
@@ -14,17 +14,17 @@ const m = "https://api.chaibuilder.com", k = async (n, e) => {
|
|
|
14
14
|
m + "/v1/api/chai",
|
|
15
15
|
s
|
|
16
16
|
);
|
|
17
|
-
if (i.ok)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (i.ok)
|
|
18
|
+
return await i.json();
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Failed to handle request: " + i.status + " : " + i.statusText
|
|
21
|
+
);
|
|
22
22
|
} catch (a) {
|
|
23
|
-
return { error: a };
|
|
23
|
+
return { error: a.message };
|
|
24
24
|
}
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
},
|
|
25
|
+
}, t = {}, y = (n, e) => {
|
|
26
|
+
t[n] = { key: n, ...e };
|
|
27
|
+
}, p = () => Object.values(t), h = (n) => t[n], S = {
|
|
28
28
|
ab: "Abkhazian",
|
|
29
29
|
aa: "Afar",
|
|
30
30
|
af: "Afrikaans",
|
|
@@ -212,24 +212,24 @@ const m = "https://api.chaibuilder.com", k = async (n, e) => {
|
|
|
212
212
|
yo: "Yoruba",
|
|
213
213
|
za: "Zhuang, Chuang",
|
|
214
214
|
zu: "Zulu"
|
|
215
|
-
},
|
|
215
|
+
}, r = "https://api.chaibuilder.com";
|
|
216
216
|
class C {
|
|
217
217
|
constructor(e) {
|
|
218
|
-
|
|
219
|
-
this.apiKey = e,
|
|
218
|
+
o(this, "currentLang", "");
|
|
219
|
+
this.apiKey = e, y("pages", {
|
|
220
220
|
name: "Pages",
|
|
221
|
-
search: async (a) => (await fetch(`${
|
|
221
|
+
search: async (a) => (await fetch(`${r}/v1/api/chai`, {
|
|
222
222
|
method: "POST",
|
|
223
223
|
body: JSON.stringify({ action: "SEARCH_PAGES", data: { query: a } }),
|
|
224
224
|
headers: { "x-chai-api-key": this.apiKey }
|
|
225
225
|
})).json(),
|
|
226
226
|
resolveLink: async (a, s) => {
|
|
227
|
-
const
|
|
227
|
+
const u = await (await fetch(`${r}/v1/api/chai`, {
|
|
228
228
|
method: "POST",
|
|
229
229
|
body: JSON.stringify({ action: "GET_LINK", data: { id: a, lang: s } }),
|
|
230
230
|
headers: { "x-chai-api-key": this.apiKey }
|
|
231
231
|
})).json();
|
|
232
|
-
return g(
|
|
232
|
+
return g(u, "slug", "");
|
|
233
233
|
}
|
|
234
234
|
});
|
|
235
235
|
}
|
|
@@ -245,37 +245,37 @@ class C {
|
|
|
245
245
|
}
|
|
246
246
|
async handle(e) {
|
|
247
247
|
if (e.action === "GET_COLLECTIONS")
|
|
248
|
-
return
|
|
248
|
+
return p().map((a) => ({
|
|
249
249
|
key: a.key,
|
|
250
250
|
name: a.name,
|
|
251
251
|
urlIdentifier: a.urlIdentifier
|
|
252
252
|
}));
|
|
253
253
|
if (e.action === "SEARCH_COLLECTION_ITEMS") {
|
|
254
|
-
const a =
|
|
254
|
+
const a = h(e.data.collection);
|
|
255
255
|
return a ? await (a == null ? void 0 : a.search(e.data.query)) : { error: "Collection not found" };
|
|
256
256
|
}
|
|
257
257
|
return await k(e, this.apiKey);
|
|
258
258
|
}
|
|
259
259
|
async resolveLink(e, a, s = "") {
|
|
260
|
-
const i =
|
|
260
|
+
const i = h(e);
|
|
261
261
|
return i ? await (i == null ? void 0 : i.resolveLink(a, s ?? this.currentLang)) : "";
|
|
262
262
|
}
|
|
263
|
-
async getPageMeta(e) {
|
|
264
|
-
return (await fetch(`${
|
|
263
|
+
async getPageMeta(e, a = !0) {
|
|
264
|
+
return (await fetch(`${r}/v1/api/chai`, {
|
|
265
265
|
method: "POST",
|
|
266
266
|
body: JSON.stringify({
|
|
267
267
|
action: "GET_PAGE_META",
|
|
268
|
-
data: { slug: e, published:
|
|
268
|
+
data: { slug: e, published: a }
|
|
269
269
|
}),
|
|
270
270
|
headers: { "x-chai-api-key": this.apiKey }
|
|
271
271
|
})).json();
|
|
272
272
|
}
|
|
273
|
-
async getPage(e) {
|
|
274
|
-
return (await fetch(`${
|
|
273
|
+
async getPage(e, a = !0) {
|
|
274
|
+
return (await fetch(`${r}/v1/api/chai`, {
|
|
275
275
|
method: "POST",
|
|
276
276
|
body: JSON.stringify({
|
|
277
277
|
action: "GET_PAGE",
|
|
278
|
-
data: { id: e, published:
|
|
278
|
+
data: { id: e, published: a, mergeGlobal: !0 }
|
|
279
279
|
}),
|
|
280
280
|
headers: { "x-chai-api-key": this.apiKey }
|
|
281
281
|
})).json();
|
|
@@ -283,7 +283,7 @@ class C {
|
|
|
283
283
|
}
|
|
284
284
|
export {
|
|
285
285
|
C as ChaiBuilderPages,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
h as getCollection,
|
|
287
|
+
p as getCollections,
|
|
288
|
+
y as registerCollection
|
|
289
289
|
};
|