@chaibuilder/pages 0.2.6 → 0.3.1
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 +28 -13
- package/dist/server.js +177 -142
- package/package.json +4 -4
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var P=Object.defineProperty;var A=(i,a,t)=>a in i?P(i,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[a]=t;var l=(i,a,t)=>A(i,typeof a!="symbol"?a+"":a,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("lodash-es"),u={},k=(i,a)=>{u[i]={key:i,...a,hasSlug:!0}},f=(i,a)=>{u[i]={key:i,...a,hasSlug:!1}},g=()=>Object.values(u),s=i=>u[i];let b=async i=>({...i});const C=i=>b=i,d=async i=>{try{return await b(i)}catch(a){return console.error(a),{}}};class w{async verifyTokenAndGetUser(a){return{id:"mock-chai-user",name:"Mock Chai User",email:"mock-chai-user@chaibuilder.com"}}async isUserActive(a){return!0}async getUserRoleAndPermissions(a){return{role:"admin",permissions:null}}async getUserInfo(a){return{id:"mock-chai-users",email:"mock-chai-user@chaibuilder.com",name:"Mock Chai User",avatar:"https://i.pravatar.cc/300"}}}const S={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"};class y{constructor(a){l(this,"fallbackLang","");l(this,"currentLang","");l(this,"draftMode",!1);l(this,"userMgmt",new w);this.backend=a,this._registerDefaultPageTypes()}_registerDefaultPageTypes(){k("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>'}),f("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>'})}setUserManagement(a){this.userMgmt=a}setFallbackLang(a){if(c.isEmpty(a))throw new Error("Fallback language cannot be empty");this.fallbackLang=a}getFallbackLang(){return this.fallbackLang}setCurrentLang(a){if(c.isEmpty(a))throw new Error("Current language cannot be empty");this.currentLang=a}getCurrentLang(){return this.currentLang}setDraftMode(a){this.draftMode=a}isDraftMode(){return this.draftMode}async handleUpload(a,t=""){return await this.backend.handleUpload(a,t)}async handle(a,t){switch(a.action){case"CHECK_USER_STATUS":return this.userMgmt.isUserActive(t);case"GET_ROLE_AND_PERMISSIONS":return this.userMgmt.getUserRoleAndPermissions(t);case"GET_CHAI_USER":return this.userMgmt.getUserInfo(t)}if(a.action==="GET_BUILDER_PAGE_DATA"){const e=await d({lang:a.data.lang,draft:!0,inBuilder:!0}),r=s(a.data.pageType);return r?{...r.dataProvider?await r.dataProvider({lang:a.data.lang,draft:!0,inBuilder:!0}):{},global:e}:{global:e}}if(a.action==="GET_PAGE_TYPES")return Promise.all(g().map(async e=>({key:e.key,helpText:e.helpText??"",icon:e.icon??"",dynamicSegments:e.dynamicSegments??"",dynamicSlug:e.dynamicSlug??"",hasSlug:e.hasSlug??!0,name:typeof e.name=="function"?await e.name():e.name})));if(a.action==="SEARCH_PAGE_TYPE_ITEMS"){const e=s(a.data.pageType);return e?e.search?await e.search(a.data.query):this.backend.handleAction(a):{error:"Page type not found"}}const n=await this.backend.handleAction(a,t);return this.emit(a.action,n),n}emit(a,t){var r,o,h;if(!["CREATE_PAGE","UPDATE_PAGE","DELETE_PAGE"].includes(a))return;const n=c.get(t,"page");if(!n)return;const e=s(n.pageType);if(e)switch(a){case"CREATE_PAGE":return(r=e.onCreate)==null?void 0:r.call(e,n);case"UPDATE_PAGE":return(o=e.onUpdate)==null?void 0:o.call(e,n);case"DELETE_PAGE":return(h=e.onDelete)==null?void 0:h.call(e,n)}}setLanguageFromSlug(a){if(!this.getFallbackLang())throw new Error("Please set a fallback language using setFallbackLang(lang: string)");const t=c.first(a||[""]);Object.keys(S).includes(t)?this.setCurrentLang(t):this.setCurrentLang(this.getFallbackLang())}async resolveLink(a,t){const n=s(a);if(!n)return"/not-found";const e=this.isDraftMode(),r=this.getCurrentLang();return n.resolveLink?await n.resolveLink(t,e,r):await this.backend.handleAction({action:"GET_LINK",data:{pageType:a,id:t,draft:e,lang:r}})}async getPageBySlug(a){const t=this.isDraftMode(),n={};return g().forEach(e=>{c.has(e,"dynamicSegments")&&e.dynamicSegments&&(n[e.key]=e.dynamicSegments)}),await this.backend.handleAction({action:"GET_PAGE_META",data:{slug:a,draft:t,dynamicSegments:n}})}async getFullPage(a){const t=this.isDraftMode(),n=this.getCurrentLang(),e=this.getFallbackLang();return await this.backend.handleAction({action:"GET_PAGE",data:{id:a,lang:e===n?void 0:n,draft:t,mergePartials:!0}})}async getSiteSettings(){const a=this.isDraftMode();return await this.backend.handleAction({action:"GET_WEBSITE_SETTINGS",data:{draft:a}})}async getPageData(a,t={}){var m;const n=this.isDraftMode(),e=this.getCurrentLang(),r=s(a),[o,h]=await Promise.all([this.getGlobalData(),((m=r==null?void 0:r.dataProvider)==null?void 0:m.call(r,{lang:e,draft:n,inBuilder:!1,...t}))||Promise.resolve({})]);return r?{...h,global:o}:{global:o}}async getGlobalData(){const a=this.getCurrentLang();return await d({lang:a,draft:this.isDraftMode(),inBuilder:!1})}async request(a){return await this.backend.handleAction(a)}}class p{constructor(a="",t=E){this.apiKey=a,this.apiUrl=t}async handleAction(a,t=""){return await(await fetch(`${this.apiUrl}/v1/api/chai`,{cache:"no-store",method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,...t?{"x-chai-user":t}:{}}})).json()}async handleUpload(a,t=""){return console.log("handleUpload",typeof a.get("file")),await(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:a,headers:{"x-chai-api-key":this.apiKey,"x-chai-upload":"true",...t?{"x-chai-user":t}:{}}})).json()}}const E="https://api.chaibuilder.com";exports.API_URL=E;exports.ChaiBuilderPages=y;exports.ChaiBuilderPagesBackend=p;exports.ChaiBuilderPagesUserManagement=w;exports.LANGUAGES=S;exports.getChaiGlobalData=d;exports.getChaiPageType=s;exports.getChaiPageTypes=g;exports.registerChaiGlobalDataProvider=C;exports.registerChaiPageType=k;exports.registerChaiPartialType=f;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const API_URL = "https://api.chaibuilder.com";
|
|
2
|
+
|
|
1
3
|
export declare type ChaiBuilderPage = {
|
|
2
4
|
id: string;
|
|
3
5
|
slug: string;
|
|
@@ -14,7 +16,7 @@ export declare class ChaiBuilderPages implements ChaiBuilderPagesInterface {
|
|
|
14
16
|
private draftMode;
|
|
15
17
|
private userMgmt;
|
|
16
18
|
constructor(backend: ChaiBuilderPagesBackendInterface);
|
|
17
|
-
private
|
|
19
|
+
private _registerDefaultPageTypes;
|
|
18
20
|
setUserManagement(usersMgmt: ChaiBuilderPagesUserManagementInterface): void;
|
|
19
21
|
setFallbackLang(lang: string): void;
|
|
20
22
|
getFallbackLang(): string;
|
|
@@ -33,7 +35,7 @@ export declare class ChaiBuilderPages implements ChaiBuilderPagesInterface {
|
|
|
33
35
|
getPageBySlug(slug: string): Promise<any>;
|
|
34
36
|
getFullPage(id: string): Promise<any>;
|
|
35
37
|
getSiteSettings(): Promise<any>;
|
|
36
|
-
getPageData(pageType: string, props
|
|
38
|
+
getPageData(pageType: string, props?: Record<string, any>): Promise<{
|
|
37
39
|
global: any;
|
|
38
40
|
}>;
|
|
39
41
|
getGlobalData(): Promise<any>;
|
|
@@ -118,13 +120,12 @@ export declare type ChaiBuilderPageType = {
|
|
|
118
120
|
onCreate?: (data: Omit<ChaiBuilderPage, "seo">) => Promise<void>;
|
|
119
121
|
onUpdate?: (data: ChaiBuilderPage) => Promise<void>;
|
|
120
122
|
onDelete?: (data: Pick<ChaiBuilderPage, "id">) => Promise<void>;
|
|
121
|
-
dataProvider?: (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
slug?: string;
|
|
123
|
+
dataProvider?: (args: {
|
|
124
|
+
lang: string;
|
|
125
|
+
draft: boolean;
|
|
126
|
+
inBuilder: boolean;
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
}) => Promise<Record<string, any>>;
|
|
128
129
|
};
|
|
129
130
|
|
|
130
131
|
export declare type ChaiBuilderUserInfo = {
|
|
@@ -140,12 +141,20 @@ export declare type ChaiWebsiteSetting = {
|
|
|
140
141
|
theme: Record<"fontFamily" | "borderRadius" | "colors", any>;
|
|
141
142
|
};
|
|
142
143
|
|
|
143
|
-
export declare const getChaiGlobalData: (
|
|
144
|
+
export declare const getChaiGlobalData: (args: {
|
|
145
|
+
lang: string;
|
|
146
|
+
draft: boolean;
|
|
147
|
+
inBuilder: boolean;
|
|
148
|
+
}) => Promise<any>;
|
|
144
149
|
|
|
145
150
|
export declare const getChaiPageType: (key: keyof typeof PAGE_TYPES) => ChaiBuilderPageType;
|
|
146
151
|
|
|
147
152
|
export declare const getChaiPageTypes: () => ChaiBuilderPageType[];
|
|
148
153
|
|
|
154
|
+
export declare const LANGUAGES: {
|
|
155
|
+
[key: string]: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
149
158
|
declare const PAGE_TYPES: Record<string, ChaiBuilderPageType>;
|
|
150
159
|
|
|
151
160
|
export declare type PageTypeSearchResult = {
|
|
@@ -154,12 +163,18 @@ export declare type PageTypeSearchResult = {
|
|
|
154
163
|
slug?: string;
|
|
155
164
|
};
|
|
156
165
|
|
|
157
|
-
export declare const registerChaiGlobalDataProvider: <T>(globalDataProvider: (
|
|
166
|
+
export declare const registerChaiGlobalDataProvider: <T>(globalDataProvider: (args: {
|
|
167
|
+
lang: string;
|
|
168
|
+
draft: boolean;
|
|
169
|
+
inBuilder: boolean;
|
|
170
|
+
}) => Promise<T>) => (args: {
|
|
171
|
+
lang: string;
|
|
172
|
+
draft: boolean;
|
|
173
|
+
inBuilder: boolean;
|
|
174
|
+
}) => Promise<T>;
|
|
158
175
|
|
|
159
176
|
export declare const registerChaiPageType: (key: string, pageTypeOptions: Omit<ChaiBuilderPageType, "key">) => void;
|
|
160
177
|
|
|
161
178
|
export declare const registerChaiPartialType: (key: string, pageTypeOptions: Omit<ChaiBuilderPageType, "key">) => void;
|
|
162
179
|
|
|
163
|
-
export declare const registerChaiTaxonomy: (key: string, taxonomyOptions: Omit<ChaiBuilderTaxonomyType, "key">) => void;
|
|
164
|
-
|
|
165
180
|
export { }
|
package/dist/server.js
CHANGED
|
@@ -1,20 +1,53 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (
|
|
4
|
-
import { get as
|
|
5
|
-
const h = {}, A = (
|
|
6
|
-
h[
|
|
7
|
-
},
|
|
8
|
-
h[
|
|
9
|
-
},
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
isDraft: a,
|
|
13
|
-
inBuilder: e
|
|
1
|
+
var f = Object.defineProperty;
|
|
2
|
+
var b = (i, a, n) => a in i ? f(i, a, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[a] = n;
|
|
3
|
+
var o = (i, a, n) => b(i, typeof a != "symbol" ? a + "" : a, n);
|
|
4
|
+
import { isEmpty as g, get as w, first as S, has as E } from "lodash-es";
|
|
5
|
+
const h = {}, A = (i, a) => {
|
|
6
|
+
h[i] = { key: i, ...a, hasSlug: !0 };
|
|
7
|
+
}, C = (i, a) => {
|
|
8
|
+
h[i] = { key: i, ...a, hasSlug: !1 };
|
|
9
|
+
}, d = () => Object.values(h), l = (i) => h[i];
|
|
10
|
+
let k = async (i) => ({
|
|
11
|
+
...i
|
|
14
12
|
});
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const L = (i) => k = i, m = async (i) => {
|
|
14
|
+
try {
|
|
15
|
+
return await k(i);
|
|
16
|
+
} catch (a) {
|
|
17
|
+
return console.error(a), {};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
class P {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
|
+
async verifyTokenAndGetUser(a) {
|
|
23
|
+
return {
|
|
24
|
+
id: "mock-chai-user",
|
|
25
|
+
name: "Mock Chai User",
|
|
26
|
+
email: "mock-chai-user@chaibuilder.com"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
30
|
+
async isUserActive(a) {
|
|
31
|
+
return !0;
|
|
32
|
+
}
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
+
async getUserRoleAndPermissions(a) {
|
|
35
|
+
return {
|
|
36
|
+
role: "admin",
|
|
37
|
+
permissions: null
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
+
async getUserInfo(a) {
|
|
42
|
+
return {
|
|
43
|
+
id: "mock-chai-users",
|
|
44
|
+
email: "mock-chai-user@chaibuilder.com",
|
|
45
|
+
name: "Mock Chai User",
|
|
46
|
+
avatar: "https://i.pravatar.cc/300"
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const y = {
|
|
18
51
|
ab: "Abkhazian",
|
|
19
52
|
aa: "Afar",
|
|
20
53
|
af: "Afrikaans",
|
|
@@ -202,78 +235,20 @@ const M = (t) => m = t, d = async (t, a, e) => await m(t, a, e), T = (t, a) => {
|
|
|
202
235
|
yo: "Yoruba",
|
|
203
236
|
za: "Zhuang, Chuang",
|
|
204
237
|
zu: "Zulu"
|
|
205
|
-
}
|
|
206
|
-
class
|
|
207
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
208
|
-
async verifyTokenAndGetUser(a) {
|
|
209
|
-
return {
|
|
210
|
-
id: "mock-chai-user",
|
|
211
|
-
name: "Mock Chai User",
|
|
212
|
-
email: "mock-chai-user@chaibuilder.com"
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
216
|
-
async isUserActive(a) {
|
|
217
|
-
return !0;
|
|
218
|
-
}
|
|
219
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
220
|
-
async getUserRoleAndPermissions(a) {
|
|
221
|
-
return {
|
|
222
|
-
role: "admin",
|
|
223
|
-
permissions: null
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
227
|
-
async getUserInfo(a) {
|
|
228
|
-
return {
|
|
229
|
-
id: "mock-chai-users",
|
|
230
|
-
email: "mock-chai-user@chaibuilder.com",
|
|
231
|
-
name: "Mock Chai User",
|
|
232
|
-
avatar: "https://i.pravatar.cc/300"
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
class G {
|
|
237
|
-
constructor(a = "", e = P) {
|
|
238
|
-
this.apiKey = a, this.apiUrl = e;
|
|
239
|
-
}
|
|
240
|
-
async handleAction(a, e = "") {
|
|
241
|
-
return await (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
242
|
-
cache: "no-store",
|
|
243
|
-
method: "POST",
|
|
244
|
-
body: JSON.stringify(a),
|
|
245
|
-
headers: {
|
|
246
|
-
"x-chai-api-key": this.apiKey,
|
|
247
|
-
...e ? { "x-chai-user": e } : {}
|
|
248
|
-
}
|
|
249
|
-
})).json();
|
|
250
|
-
}
|
|
251
|
-
async handleUpload(a, e = "") {
|
|
252
|
-
return console.log("handleUpload", typeof a.get("file")), await (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
253
|
-
method: "POST",
|
|
254
|
-
body: a,
|
|
255
|
-
headers: {
|
|
256
|
-
// "Content-Type": "multipart/form-data",
|
|
257
|
-
"x-chai-api-key": this.apiKey,
|
|
258
|
-
"x-chai-upload": "true",
|
|
259
|
-
...e ? { "x-chai-user": e } : {}
|
|
260
|
-
}
|
|
261
|
-
})).json();
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
class L {
|
|
238
|
+
};
|
|
239
|
+
class T {
|
|
265
240
|
constructor(a) {
|
|
266
241
|
o(this, "fallbackLang", "");
|
|
267
242
|
o(this, "currentLang", "");
|
|
268
243
|
o(this, "draftMode", !1);
|
|
269
|
-
o(this, "userMgmt", new
|
|
270
|
-
this.backend = a, this.
|
|
244
|
+
o(this, "userMgmt", new P());
|
|
245
|
+
this.backend = a, this._registerDefaultPageTypes();
|
|
271
246
|
}
|
|
272
|
-
|
|
247
|
+
_registerDefaultPageTypes() {
|
|
273
248
|
A("page", {
|
|
274
249
|
name: "Static Page",
|
|
275
250
|
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>'
|
|
276
|
-
}),
|
|
251
|
+
}), C("global", {
|
|
277
252
|
name: "Global Block",
|
|
278
253
|
helpText: "A global block can be reused in multiple pages.",
|
|
279
254
|
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>'
|
|
@@ -283,12 +258,16 @@ class L {
|
|
|
283
258
|
this.userMgmt = a;
|
|
284
259
|
}
|
|
285
260
|
setFallbackLang(a) {
|
|
261
|
+
if (g(a))
|
|
262
|
+
throw new Error("Fallback language cannot be empty");
|
|
286
263
|
this.fallbackLang = a;
|
|
287
264
|
}
|
|
288
265
|
getFallbackLang() {
|
|
289
266
|
return this.fallbackLang;
|
|
290
267
|
}
|
|
291
268
|
setCurrentLang(a) {
|
|
269
|
+
if (g(a))
|
|
270
|
+
throw new Error("Current language cannot be empty");
|
|
292
271
|
this.currentLang = a;
|
|
293
272
|
}
|
|
294
273
|
getCurrentLang() {
|
|
@@ -300,98 +279,115 @@ class L {
|
|
|
300
279
|
isDraftMode() {
|
|
301
280
|
return this.draftMode;
|
|
302
281
|
}
|
|
303
|
-
async handleUpload(a,
|
|
304
|
-
return await this.backend.handleUpload(a,
|
|
282
|
+
async handleUpload(a, n = "") {
|
|
283
|
+
return await this.backend.handleUpload(a, n);
|
|
305
284
|
}
|
|
306
|
-
async handle(a,
|
|
285
|
+
async handle(a, n) {
|
|
307
286
|
switch (a.action) {
|
|
308
287
|
case "CHECK_USER_STATUS":
|
|
309
|
-
return this.userMgmt.isUserActive(
|
|
288
|
+
return this.userMgmt.isUserActive(n);
|
|
310
289
|
case "GET_ROLE_AND_PERMISSIONS":
|
|
311
|
-
return this.userMgmt.getUserRoleAndPermissions(
|
|
290
|
+
return this.userMgmt.getUserRoleAndPermissions(n);
|
|
312
291
|
case "GET_CHAI_USER":
|
|
313
|
-
return this.userMgmt.getUserInfo(
|
|
292
|
+
return this.userMgmt.getUserInfo(n);
|
|
314
293
|
}
|
|
315
294
|
if (a.action === "GET_BUILDER_PAGE_DATA") {
|
|
316
|
-
const
|
|
295
|
+
const e = await m({
|
|
296
|
+
lang: a.data.lang,
|
|
297
|
+
draft: !0,
|
|
298
|
+
inBuilder: !0
|
|
299
|
+
}), r = l(
|
|
317
300
|
a.data.pageType
|
|
318
301
|
);
|
|
319
|
-
return
|
|
320
|
-
...
|
|
321
|
-
|
|
322
|
-
|
|
302
|
+
return r ? {
|
|
303
|
+
...r.dataProvider ? await r.dataProvider({
|
|
304
|
+
lang: a.data.lang,
|
|
305
|
+
draft: !0,
|
|
306
|
+
inBuilder: !0
|
|
307
|
+
}) : {},
|
|
308
|
+
global: e
|
|
309
|
+
} : { global: e };
|
|
323
310
|
}
|
|
324
311
|
if (a.action === "GET_PAGE_TYPES")
|
|
325
312
|
return Promise.all(
|
|
326
|
-
|
|
327
|
-
key:
|
|
328
|
-
helpText:
|
|
329
|
-
icon:
|
|
330
|
-
dynamicSegments:
|
|
331
|
-
dynamicSlug:
|
|
332
|
-
hasSlug:
|
|
333
|
-
name: typeof
|
|
313
|
+
d().map(async (e) => ({
|
|
314
|
+
key: e.key,
|
|
315
|
+
helpText: e.helpText ?? "",
|
|
316
|
+
icon: e.icon ?? "",
|
|
317
|
+
dynamicSegments: e.dynamicSegments ?? "",
|
|
318
|
+
dynamicSlug: e.dynamicSlug ?? "",
|
|
319
|
+
hasSlug: e.hasSlug ?? !0,
|
|
320
|
+
name: typeof e.name == "function" ? await e.name() : e.name
|
|
334
321
|
}))
|
|
335
322
|
);
|
|
336
323
|
if (a.action === "SEARCH_PAGE_TYPE_ITEMS") {
|
|
337
|
-
const
|
|
324
|
+
const e = l(
|
|
338
325
|
a.data.pageType
|
|
339
326
|
);
|
|
340
|
-
return
|
|
327
|
+
return e ? e.search ? await e.search(a.data.query) : this.backend.handleAction(a) : { error: "Page type not found" };
|
|
341
328
|
}
|
|
342
|
-
const
|
|
343
|
-
return this.emit(a.action,
|
|
329
|
+
const t = await this.backend.handleAction(a, n);
|
|
330
|
+
return this.emit(a.action, t), t;
|
|
344
331
|
}
|
|
345
|
-
emit(a,
|
|
346
|
-
var
|
|
332
|
+
emit(a, n) {
|
|
333
|
+
var r, s, c;
|
|
347
334
|
if (!["CREATE_PAGE", "UPDATE_PAGE", "DELETE_PAGE"].includes(a)) return;
|
|
348
|
-
const
|
|
349
|
-
if (!
|
|
350
|
-
const
|
|
351
|
-
if (
|
|
335
|
+
const t = w(n, "page");
|
|
336
|
+
if (!t) return;
|
|
337
|
+
const e = l(t.pageType);
|
|
338
|
+
if (e)
|
|
352
339
|
switch (a) {
|
|
353
340
|
case "CREATE_PAGE":
|
|
354
|
-
return (
|
|
341
|
+
return (r = e.onCreate) == null ? void 0 : r.call(e, t);
|
|
355
342
|
case "UPDATE_PAGE":
|
|
356
|
-
return (
|
|
343
|
+
return (s = e.onUpdate) == null ? void 0 : s.call(e, t);
|
|
357
344
|
case "DELETE_PAGE":
|
|
358
|
-
return (c =
|
|
345
|
+
return (c = e.onDelete) == null ? void 0 : c.call(e, t);
|
|
359
346
|
}
|
|
360
347
|
}
|
|
361
348
|
// APIS
|
|
362
349
|
setLanguageFromSlug(a) {
|
|
363
|
-
|
|
364
|
-
|
|
350
|
+
if (!this.getFallbackLang())
|
|
351
|
+
throw new Error(
|
|
352
|
+
"Please set a fallback language using setFallbackLang(lang: string)"
|
|
353
|
+
);
|
|
354
|
+
const n = S(a || [""]);
|
|
355
|
+
Object.keys(y).includes(n) ? this.setCurrentLang(n) : this.setCurrentLang(this.getFallbackLang());
|
|
365
356
|
}
|
|
366
|
-
async resolveLink(a,
|
|
367
|
-
const
|
|
368
|
-
if (!
|
|
357
|
+
async resolveLink(a, n) {
|
|
358
|
+
const t = l(a);
|
|
359
|
+
if (!t)
|
|
369
360
|
return "/not-found";
|
|
370
|
-
const
|
|
371
|
-
return
|
|
361
|
+
const e = this.isDraftMode(), r = this.getCurrentLang();
|
|
362
|
+
return t.resolveLink ? await t.resolveLink(n, e, r) : await this.backend.handleAction({
|
|
372
363
|
action: "GET_LINK",
|
|
373
364
|
data: {
|
|
374
365
|
pageType: a,
|
|
375
|
-
id:
|
|
376
|
-
draft:
|
|
377
|
-
lang:
|
|
366
|
+
id: n,
|
|
367
|
+
draft: e,
|
|
368
|
+
lang: r
|
|
378
369
|
}
|
|
379
370
|
});
|
|
380
371
|
}
|
|
381
372
|
async getPageBySlug(a) {
|
|
382
|
-
const
|
|
383
|
-
return
|
|
384
|
-
|
|
373
|
+
const n = this.isDraftMode(), t = {};
|
|
374
|
+
return d().forEach((e) => {
|
|
375
|
+
E(e, "dynamicSegments") && e.dynamicSegments && (t[e.key] = e.dynamicSegments);
|
|
385
376
|
}), await this.backend.handleAction({
|
|
386
377
|
action: "GET_PAGE_META",
|
|
387
|
-
data: { slug: a, draft:
|
|
378
|
+
data: { slug: a, draft: n, dynamicSegments: t }
|
|
388
379
|
});
|
|
389
380
|
}
|
|
390
381
|
async getFullPage(a) {
|
|
391
|
-
const
|
|
382
|
+
const n = this.isDraftMode(), t = this.getCurrentLang(), e = this.getFallbackLang();
|
|
392
383
|
return await this.backend.handleAction({
|
|
393
384
|
action: "GET_PAGE",
|
|
394
|
-
data: {
|
|
385
|
+
data: {
|
|
386
|
+
id: a,
|
|
387
|
+
lang: e === t ? void 0 : t,
|
|
388
|
+
draft: n,
|
|
389
|
+
mergePartials: !0
|
|
390
|
+
}
|
|
395
391
|
});
|
|
396
392
|
}
|
|
397
393
|
async getSiteSettings() {
|
|
@@ -401,34 +397,73 @@ class L {
|
|
|
401
397
|
data: { draft: a }
|
|
402
398
|
});
|
|
403
399
|
}
|
|
404
|
-
async getPageData(a,
|
|
400
|
+
async getPageData(a, n = {}) {
|
|
405
401
|
var u;
|
|
406
|
-
const
|
|
402
|
+
const t = this.isDraftMode(), e = this.getCurrentLang(), r = l(a), [s, c] = await Promise.all([
|
|
407
403
|
this.getGlobalData(),
|
|
408
|
-
((u =
|
|
404
|
+
((u = r == null ? void 0 : r.dataProvider) == null ? void 0 : u.call(r, {
|
|
405
|
+
lang: e,
|
|
406
|
+
draft: t,
|
|
407
|
+
inBuilder: !1,
|
|
408
|
+
...n
|
|
409
|
+
})) || Promise.resolve({})
|
|
409
410
|
]);
|
|
410
|
-
return
|
|
411
|
+
return r ? {
|
|
411
412
|
...c,
|
|
412
|
-
global:
|
|
413
|
-
} : { global:
|
|
413
|
+
global: s
|
|
414
|
+
} : { global: s };
|
|
414
415
|
}
|
|
415
416
|
async getGlobalData() {
|
|
416
417
|
const a = this.getCurrentLang();
|
|
417
|
-
return await
|
|
418
|
+
return await m({
|
|
419
|
+
lang: a,
|
|
420
|
+
draft: this.isDraftMode(),
|
|
421
|
+
inBuilder: !1
|
|
422
|
+
});
|
|
418
423
|
}
|
|
419
424
|
async request(a) {
|
|
420
425
|
return await this.backend.handleAction(a);
|
|
421
426
|
}
|
|
422
427
|
}
|
|
428
|
+
class G {
|
|
429
|
+
constructor(a = "", n = v) {
|
|
430
|
+
this.apiKey = a, this.apiUrl = n;
|
|
431
|
+
}
|
|
432
|
+
async handleAction(a, n = "") {
|
|
433
|
+
return await (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
434
|
+
cache: "no-store",
|
|
435
|
+
method: "POST",
|
|
436
|
+
body: JSON.stringify(a),
|
|
437
|
+
headers: {
|
|
438
|
+
"x-chai-api-key": this.apiKey,
|
|
439
|
+
...n ? { "x-chai-user": n } : {}
|
|
440
|
+
}
|
|
441
|
+
})).json();
|
|
442
|
+
}
|
|
443
|
+
async handleUpload(a, n = "") {
|
|
444
|
+
return console.log("handleUpload", typeof a.get("file")), await (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
445
|
+
method: "POST",
|
|
446
|
+
body: a,
|
|
447
|
+
headers: {
|
|
448
|
+
// "Content-Type": "multipart/form-data",
|
|
449
|
+
"x-chai-api-key": this.apiKey,
|
|
450
|
+
"x-chai-upload": "true",
|
|
451
|
+
...n ? { "x-chai-user": n } : {}
|
|
452
|
+
}
|
|
453
|
+
})).json();
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const v = "https://api.chaibuilder.com";
|
|
423
457
|
export {
|
|
424
|
-
|
|
458
|
+
v as API_URL,
|
|
459
|
+
T as ChaiBuilderPages,
|
|
425
460
|
G as ChaiBuilderPagesBackend,
|
|
426
|
-
|
|
427
|
-
|
|
461
|
+
P as ChaiBuilderPagesUserManagement,
|
|
462
|
+
y as LANGUAGES,
|
|
463
|
+
m as getChaiGlobalData,
|
|
428
464
|
l as getChaiPageType,
|
|
429
|
-
|
|
430
|
-
|
|
465
|
+
d as getChaiPageTypes,
|
|
466
|
+
L as registerChaiGlobalDataProvider,
|
|
431
467
|
A as registerChaiPageType,
|
|
432
|
-
|
|
433
|
-
T as registerChaiTaxonomy
|
|
468
|
+
C as registerChaiPartialType
|
|
434
469
|
};
|
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.
|
|
6
|
+
"version": "0.3.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"test": "vitest"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@chaibuilder/sdk": "2.
|
|
62
|
+
"@chaibuilder/sdk": "2.2.0",
|
|
63
63
|
"@types/react": "*",
|
|
64
64
|
"@types/react-dom": "*",
|
|
65
65
|
"react": "^18.0 || ^19.0",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@chaibuilder/runtime": "2.0.
|
|
81
|
-
"@chaibuilder/sdk": "2.
|
|
80
|
+
"@chaibuilder/runtime": "2.0.8",
|
|
81
|
+
"@chaibuilder/sdk": "2.2.0",
|
|
82
82
|
"@mhsdesign/jit-browser-tailwindcss": "^0.4.2",
|
|
83
83
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
84
84
|
"@tailwindcss/forms": "^0.5.10",
|