@chaibuilder/pages 0.3.6 → 0.4.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/{B4MFY5CR-MVAv6DcU.js → B4MFY5CR-B4tVPs9s.js} +1 -1
- package/dist/{B4MFY5CR-EcyUHg1m.cjs → B4MFY5CR-C_Nr9vlH.cjs} +1 -1
- package/dist/{HO4MOOFI-DI8jMuEu.js → HO4MOOFI-CAKbzM3F.js} +2 -2
- package/dist/{HO4MOOFI-BDxIKIu9.cjs → HO4MOOFI-MA6VFs4z.cjs} +1 -1
- package/dist/{HUY7CZI3-Y4pkyP5k.cjs → HUY7CZI3-D-kSwzvR.cjs} +1 -1
- package/dist/{HUY7CZI3-AC1qETNb.js → HUY7CZI3-m87usavc.js} +2 -2
- package/dist/{index-w504XseG.js → index-CaqQwS02.js} +7270 -6935
- package/dist/index-D-pFPfCY.cjs +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +15 -9
- package/dist/index.js +17 -16
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +58 -32
- package/dist/server.js +167 -133
- package/package.json +1 -1
- package/dist/index-DYH2MB44.cjs +0 -2
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var y=(i,a,e)=>a in i?C(i,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[a]=e;var g=(i,a,e)=>y(i,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("lodash-es"),d={},b=(i,a)=>{d[i]={key:i,...a,hasSlug:!0}},S=(i,a)=>{d[i]={key:i,...a,hasSlug:!1}},m=()=>Object.values(d),h=i=>d[i];let w=async i=>({...i});const T=i=>w=i,f=async i=>{try{return await w(i)}catch(a){return console.error(a),{}}};class A{constructor(a){this.backend=a}async refreshToken(a){const e=await this.backend.handleUsersAction({action:"REFRESH_TOKEN",data:a});return e.error?{error:e.error}:e}async login({email:a,password:e}){return await this.backend.handleUsersAction({action:"LOGIN",data:{email:a,password:e}})}async logout(){await this.backend.handleUsersAction({action:"LOGOUT"})}async isUserActive(a){return(await this.backend.handleUsersAction({action:"CHECK_USER_STATUS"},a)).success}async getUserRoleAndPermissions(a){return await this.backend.handleUsersAction({action:"GET_ROLE_AND_PERMISSIONS"},a)}async getUserInfo(a,e){return await this.backend.handleUsersAction({action:"GET_CHAI_USER",data:e},a)}}const 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"};class L{constructor(a,e){g(this,"fallbackLang","");g(this,"currentLang","");g(this,"draftMode",!1);this.backend=a,this.chaiUsers=e,this._registerDefaultPageTypes(),this.chaiUsers=e??new A(this.backend)}_registerDefaultPageTypes(){b("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>'}),S("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>'})}setFallbackLang(a){if(l.isEmpty(a))throw new Error("Fallback language cannot be empty");this.fallbackLang=a}getFallbackLang(){return this.fallbackLang}setCurrentLang(a){if(l.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,e=""){return await this.backend.handleUpload(a,e)}async handle(a,e){var t,r,o,c,u,E;switch(a.action){case"REFRESH_TOKEN":return(t=this.chaiUsers)==null?void 0:t.refreshToken(a.data);case"LOGIN":return(r=this.chaiUsers)==null?void 0:r.login(a.data);case"LOGOUT":return(o=this.chaiUsers)==null?void 0:o.logout();case"CHECK_USER_STATUS":return(c=this.chaiUsers)==null?void 0:c.isUserActive(e);case"GET_ROLE_AND_PERMISSIONS":return(u=this.chaiUsers)==null?void 0:u.getUserRoleAndPermissions(e);case"GET_CHAI_USER":return(E=this.chaiUsers)==null?void 0:E.getUserInfo(e,a.data)}if(a.action==="GET_BUILDER_PAGE_DATA"){const s=await f({lang:a.data.lang,draft:!0,inBuilder:!0}),k=h(a.data.pageType);return k?{...k.dataProvider?await k.dataProvider({lang:a.data.lang,draft:!0,inBuilder:!0,pageProps:a.data.pageProps??{}}):{},global:s}:{global:s}}if(a.action==="GET_PAGE_TYPES")return Promise.all(m().map(async s=>({key:s.key,helpText:s.helpText??"",icon:s.icon??"",dynamicSegments:s.dynamicSegments??"",dynamicSlug:s.dynamicSlug??"",hasSlug:s.hasSlug??!0,name:typeof s.name=="function"?await s.name():s.name})));if(a.action==="SEARCH_PAGE_TYPE_ITEMS"){const s=h(a.data.pageType);return s?s.search?await s.search(a.data.query):this.backend.handleAction(a,e):{error:"Page type not found"}}const n=await this.backend.handleAction(a,e);return this.emit(a.action,n),n}emit(a,e){var r,o,c;if(!["CREATE_PAGE","UPDATE_PAGE","DELETE_PAGE"].includes(a))return;const n=l.get(e,"page");if(!n)return;const t=h(n.pageType);if(t)switch(a){case"CREATE_PAGE":return(r=t.onCreate)==null?void 0:r.call(t,n);case"UPDATE_PAGE":return(o=t.onUpdate)==null?void 0:o.call(t,n);case"DELETE_PAGE":return(c=t.onDelete)==null?void 0:c.call(t,n)}}setLanguageFromSlug(a){if(!this.getFallbackLang())throw new Error("Please set a fallback language using setFallbackLang(lang: string)");const e=l.first(a||[""]);Object.keys(P).includes(e)?this.setCurrentLang(e):this.setCurrentLang(this.getFallbackLang())}async resolveLink(a,e){const n=h(a);if(!n)return"/not-found";const t=this.isDraftMode(),r=this.getCurrentLang();return n.resolveLink?await n.resolveLink(e,t,r):await this.backend.handleAction({action:"GET_LINK",data:{pageType:a,id:e,draft:t,lang:r}})}async getPageBySlug(a){const e=this.isDraftMode(),n={};return m().forEach(t=>{l.has(t,"dynamicSegments")&&t.dynamicSegments&&(n[t.key]=t.dynamicSegments)}),await this.backend.handleAction({action:"GET_PAGE_META",data:{slug:a,draft:e,dynamicSegments:n}})}async getFullPage(a){const e=this.isDraftMode(),n=this.getCurrentLang(),t=this.getFallbackLang();return await this.backend.handleAction({action:"GET_PAGE",data:{id:a,lang:t===n?void 0:n,draft:e,mergePartials:!0}})}async getSiteSettings(){const a=this.isDraftMode();return await this.backend.handleAction({action:"GET_WEBSITE_SETTINGS",data:{draft:a}})}async getPageData(a,e={}){var u;const n=this.isDraftMode(),t=this.getCurrentLang(),r=h(a),[o,c]=await Promise.all([this.getGlobalData(),((u=r==null?void 0:r.dataProvider)==null?void 0:u.call(r,{lang:t,draft:n,inBuilder:!1,pageProps:e}))||Promise.resolve({})]);return r?{...c,global:o}:{global:o}}async getGlobalData(){const a=this.getCurrentLang();return await f({lang:a,draft:this.isDraftMode(),inBuilder:!1})}async request(a){return await this.backend.handleAction(a)}}class U{constructor(a="",e=p){this.apiKey=a,this.apiUrl=e}async handleUsersAction(a,e){const n=await fetch(`${this.apiUrl}/v1/api/users`,{method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,"x-chai-auth-token":e}}),t=await n.json();return l.has(t,"error")?{...t,status:n.status}:t}async handleAction(a,e){const n=await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,"x-chai-auth-token":e}}),t=await n.json();return l.has(t,"error")?{...t,status:n.status}:t}async handleUpload(a,e){return await(await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:a,headers:{"x-chai-api-key":this.apiKey,"x-chai-upload":"true","x-chai-auth-token":e}})).json()}}const p="https://api.chaibuilder.com";exports.API_URL=p;exports.ChaiBuilderPages=L;exports.ChaiBuilderPagesBackend=U;exports.ChaiBuilderPagesUserManagement=A;exports.LANGUAGES=P;exports.getChaiGlobalData=f;exports.getChaiPageType=h;exports.getChaiPageTypes=m;exports.registerChaiGlobalDataProvider=T;exports.registerChaiPageType=b;exports.registerChaiPartialType=S;
|
package/dist/server.d.ts
CHANGED
|
@@ -13,13 +13,12 @@ export declare type ChaiBuilderPage = {
|
|
|
13
13
|
|
|
14
14
|
export declare class ChaiBuilderPages implements ChaiBuilderPagesInterface {
|
|
15
15
|
protected backend: ChaiBuilderPagesBackendInterface;
|
|
16
|
+
protected chaiUsers?: ChaiBuilderPagesUsersInterface | undefined;
|
|
16
17
|
private fallbackLang;
|
|
17
18
|
private currentLang;
|
|
18
19
|
private draftMode;
|
|
19
|
-
|
|
20
|
-
constructor(backend: ChaiBuilderPagesBackendInterface);
|
|
20
|
+
constructor(backend: ChaiBuilderPagesBackendInterface, chaiUsers?: ChaiBuilderPagesUsersInterface | undefined);
|
|
21
21
|
private _registerDefaultPageTypes;
|
|
22
|
-
setUserManagement(usersMgmt: ChaiBuilderPagesUserManagementInterface): void;
|
|
23
22
|
setFallbackLang(lang: string): void;
|
|
24
23
|
getFallbackLang(): string;
|
|
25
24
|
setCurrentLang(lang: string): void;
|
|
@@ -30,7 +29,7 @@ export declare class ChaiBuilderPages implements ChaiBuilderPagesInterface {
|
|
|
30
29
|
handle(body: {
|
|
31
30
|
action: string;
|
|
32
31
|
data: Record<string, any>;
|
|
33
|
-
},
|
|
32
|
+
}, authToken: string): Promise<any>;
|
|
34
33
|
emit(action: string, data: any): Promise<void> | undefined;
|
|
35
34
|
setLanguageFromSlug(slug: string[]): void;
|
|
36
35
|
resolveLink(pageTypeKey: string, id: string): Promise<any>;
|
|
@@ -48,13 +47,15 @@ export declare class ChaiBuilderPagesBackend implements ChaiBuilderPagesBackendI
|
|
|
48
47
|
private apiKey;
|
|
49
48
|
private apiUrl;
|
|
50
49
|
constructor(apiKey?: string, apiUrl?: string);
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
handleUsersAction(body: any, authToken: string): Promise<any>;
|
|
51
|
+
handleAction(body: any, authToken: string): Promise<any>;
|
|
52
|
+
handleUpload(formData: FormData, authToken: string): Promise<any>;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export declare interface ChaiBuilderPagesBackendInterface {
|
|
56
|
-
handleAction(body: any,
|
|
57
|
-
handleUpload(formData: FormData,
|
|
56
|
+
handleAction(body: any, authToken?: string): Promise<any>;
|
|
57
|
+
handleUpload(formData: FormData, authToken?: string): Promise<any>;
|
|
58
|
+
handleUsersAction(body: any, authToken?: string): Promise<any>;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
export declare interface ChaiBuilderPagesInterface {
|
|
@@ -64,8 +65,7 @@ export declare interface ChaiBuilderPagesInterface {
|
|
|
64
65
|
getCurrentLang(): string;
|
|
65
66
|
setDraftMode(draft: boolean): void;
|
|
66
67
|
isDraftMode(): boolean;
|
|
67
|
-
|
|
68
|
-
handle(body: any): Promise<any>;
|
|
68
|
+
handle(body: any, authToken: string): Promise<any>;
|
|
69
69
|
emit(action: string, data: any): void;
|
|
70
70
|
setLanguageFromSlug(slug: string[]): void;
|
|
71
71
|
resolveLink(pageTypeKey: string, id: string): Promise<string>;
|
|
@@ -76,37 +76,54 @@ export declare interface ChaiBuilderPagesInterface {
|
|
|
76
76
|
getGlobalData(): Promise<any>;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export declare class ChaiBuilderPagesUserManagement implements
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
export declare class ChaiBuilderPagesUserManagement implements ChaiBuilderPagesUsersInterface {
|
|
80
|
+
private backend;
|
|
81
|
+
constructor(backend: ChaiBuilderPagesBackendInterface);
|
|
82
|
+
refreshToken(data: {
|
|
83
|
+
accessToken: string;
|
|
84
|
+
refreshToken: string;
|
|
85
|
+
}): Promise<LoggedInUser | {
|
|
86
|
+
error: string;
|
|
87
|
+
}>;
|
|
88
|
+
login({ email, password, }: {
|
|
83
89
|
email: string;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
password: string;
|
|
91
|
+
}): Promise<LoggedInUser | {
|
|
92
|
+
error: string;
|
|
93
|
+
}>;
|
|
94
|
+
logout(): Promise<void>;
|
|
95
|
+
isUserActive(authToken: string): Promise<boolean>;
|
|
96
|
+
getUserRoleAndPermissions(authToken: string): Promise<{
|
|
87
97
|
role: string;
|
|
88
98
|
permissions: string[] | null;
|
|
89
99
|
}>;
|
|
90
|
-
getUserInfo(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
name: string;
|
|
94
|
-
avatar: string;
|
|
95
|
-
}>;
|
|
100
|
+
getUserInfo(authToken: string, data: {
|
|
101
|
+
userId: string;
|
|
102
|
+
}): Promise<any>;
|
|
96
103
|
}
|
|
97
104
|
|
|
98
|
-
export declare interface
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
export declare interface ChaiBuilderPagesUsersInterface {
|
|
106
|
+
login({ email, password, }: {
|
|
107
|
+
email: string;
|
|
108
|
+
password: string;
|
|
109
|
+
}): Promise<LoggedInUser | {
|
|
110
|
+
error: string;
|
|
111
|
+
}>;
|
|
112
|
+
logout(): Promise<void>;
|
|
113
|
+
isUserActive(authToken: string): Promise<boolean>;
|
|
114
|
+
getUserRoleAndPermissions(authToken: string): Promise<{
|
|
101
115
|
role: string;
|
|
102
116
|
permissions: string[] | null;
|
|
103
117
|
}>;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
getUserInfo(authToken: string, data: {
|
|
119
|
+
userId: string;
|
|
120
|
+
}): Promise<ChaiBuilderUserInfo>;
|
|
121
|
+
refreshToken(data: {
|
|
122
|
+
accessToken: string;
|
|
123
|
+
refreshToken: string;
|
|
124
|
+
}): Promise<LoggedInUser | {
|
|
125
|
+
error: string;
|
|
126
|
+
}>;
|
|
110
127
|
}
|
|
111
128
|
|
|
112
129
|
export declare type ChaiBuilderPageType = {
|
|
@@ -159,6 +176,15 @@ export declare const LANGUAGES: {
|
|
|
159
176
|
[key: string]: string;
|
|
160
177
|
};
|
|
161
178
|
|
|
179
|
+
export declare interface LoggedInUser {
|
|
180
|
+
accessToken: string;
|
|
181
|
+
refreshToken: string;
|
|
182
|
+
id: string;
|
|
183
|
+
email: string;
|
|
184
|
+
name: string;
|
|
185
|
+
avatar?: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
162
188
|
declare const PAGE_TYPES: Record<string, ChaiBuilderPageType>;
|
|
163
189
|
|
|
164
190
|
export declare type PageTypeSearchResult = {
|
package/dist/server.js
CHANGED
|
@@ -1,53 +1,67 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { isEmpty as
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
let
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var A = (i, a, e) => a in i ? b(i, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[a] = e;
|
|
3
|
+
var u = (i, a, e) => A(i, typeof a != "symbol" ? a + "" : a, e);
|
|
4
|
+
import { isEmpty as f, get as p, first as P, has as m } from "lodash-es";
|
|
5
|
+
const g = {}, C = (i, a) => {
|
|
6
|
+
g[i] = { key: i, ...a, hasSlug: !0 };
|
|
7
|
+
}, y = (i, a) => {
|
|
8
|
+
g[i] = { key: i, ...a, hasSlug: !1 };
|
|
9
|
+
}, w = () => Object.values(g), h = (i) => g[i];
|
|
10
|
+
let S = async (i) => ({
|
|
11
11
|
...i
|
|
12
12
|
});
|
|
13
|
-
const
|
|
13
|
+
const _ = (i) => S = i, E = async (i) => {
|
|
14
14
|
try {
|
|
15
|
-
return await
|
|
15
|
+
return await S(i);
|
|
16
16
|
} catch (a) {
|
|
17
17
|
return console.error(a), {};
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
class
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
class L {
|
|
21
|
+
constructor(a) {
|
|
22
|
+
this.backend = a;
|
|
23
|
+
}
|
|
24
|
+
async refreshToken(a) {
|
|
25
|
+
const e = await this.backend.handleUsersAction({
|
|
26
|
+
action: "REFRESH_TOKEN",
|
|
27
|
+
data: a
|
|
28
|
+
});
|
|
29
|
+
return e.error ? { error: e.error } : e;
|
|
30
|
+
}
|
|
31
|
+
async login({
|
|
32
|
+
email: a,
|
|
33
|
+
password: e
|
|
34
|
+
}) {
|
|
35
|
+
return await this.backend.handleUsersAction({
|
|
36
|
+
action: "LOGIN",
|
|
37
|
+
data: { email: a, password: e }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async logout() {
|
|
41
|
+
await this.backend.handleUsersAction({
|
|
42
|
+
action: "LOGOUT"
|
|
43
|
+
});
|
|
28
44
|
}
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
30
45
|
async isUserActive(a) {
|
|
31
|
-
return
|
|
46
|
+
return (await this.backend.handleUsersAction(
|
|
47
|
+
{ action: "CHECK_USER_STATUS" },
|
|
48
|
+
a
|
|
49
|
+
)).success;
|
|
32
50
|
}
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
51
|
async getUserRoleAndPermissions(a) {
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
return await this.backend.handleUsersAction(
|
|
53
|
+
{ action: "GET_ROLE_AND_PERMISSIONS" },
|
|
54
|
+
a
|
|
55
|
+
);
|
|
39
56
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
name: "Mock Chai User",
|
|
46
|
-
avatar: "https://i.pravatar.cc/300"
|
|
47
|
-
};
|
|
57
|
+
async getUserInfo(a, e) {
|
|
58
|
+
return await this.backend.handleUsersAction(
|
|
59
|
+
{ action: "GET_CHAI_USER", data: e },
|
|
60
|
+
a
|
|
61
|
+
);
|
|
48
62
|
}
|
|
49
63
|
}
|
|
50
|
-
const
|
|
64
|
+
const U = {
|
|
51
65
|
ab: "Abkhazian",
|
|
52
66
|
aa: "Afar",
|
|
53
67
|
af: "Afrikaans",
|
|
@@ -236,29 +250,25 @@ const p = {
|
|
|
236
250
|
za: "Zhuang, Chuang",
|
|
237
251
|
zu: "Zulu"
|
|
238
252
|
};
|
|
239
|
-
class
|
|
240
|
-
constructor(a) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
this.backend = a, this._registerDefaultPageTypes();
|
|
253
|
+
class M {
|
|
254
|
+
constructor(a, e) {
|
|
255
|
+
u(this, "fallbackLang", "");
|
|
256
|
+
u(this, "currentLang", "");
|
|
257
|
+
u(this, "draftMode", !1);
|
|
258
|
+
this.backend = a, this.chaiUsers = e, this._registerDefaultPageTypes(), this.chaiUsers = e ?? new L(this.backend);
|
|
246
259
|
}
|
|
247
260
|
_registerDefaultPageTypes() {
|
|
248
|
-
|
|
261
|
+
C("page", {
|
|
249
262
|
name: "Static Page",
|
|
250
263
|
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>'
|
|
251
|
-
}),
|
|
264
|
+
}), y("global", {
|
|
252
265
|
name: "Global Block",
|
|
253
266
|
helpText: "A global block can be reused in multiple pages.",
|
|
254
267
|
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>'
|
|
255
268
|
});
|
|
256
269
|
}
|
|
257
|
-
setUserManagement(a) {
|
|
258
|
-
this.userMgmt = a;
|
|
259
|
-
}
|
|
260
270
|
setFallbackLang(a) {
|
|
261
|
-
if (
|
|
271
|
+
if (f(a))
|
|
262
272
|
throw new Error("Fallback language cannot be empty");
|
|
263
273
|
this.fallbackLang = a;
|
|
264
274
|
}
|
|
@@ -266,7 +276,7 @@ class T {
|
|
|
266
276
|
return this.fallbackLang;
|
|
267
277
|
}
|
|
268
278
|
setCurrentLang(a) {
|
|
269
|
-
if (
|
|
279
|
+
if (f(a))
|
|
270
280
|
throw new Error("Current language cannot be empty");
|
|
271
281
|
this.currentLang = a;
|
|
272
282
|
}
|
|
@@ -279,71 +289,85 @@ class T {
|
|
|
279
289
|
isDraftMode() {
|
|
280
290
|
return this.draftMode;
|
|
281
291
|
}
|
|
282
|
-
async handleUpload(a,
|
|
283
|
-
return await this.backend.handleUpload(a,
|
|
292
|
+
async handleUpload(a, e = "") {
|
|
293
|
+
return await this.backend.handleUpload(a, e);
|
|
284
294
|
}
|
|
285
|
-
async handle(a,
|
|
295
|
+
async handle(a, e) {
|
|
296
|
+
var t, r, o, c, l, k;
|
|
286
297
|
switch (a.action) {
|
|
298
|
+
case "REFRESH_TOKEN":
|
|
299
|
+
return (t = this.chaiUsers) == null ? void 0 : t.refreshToken(
|
|
300
|
+
a.data
|
|
301
|
+
);
|
|
302
|
+
case "LOGIN":
|
|
303
|
+
return (r = this.chaiUsers) == null ? void 0 : r.login(
|
|
304
|
+
a.data
|
|
305
|
+
);
|
|
306
|
+
case "LOGOUT":
|
|
307
|
+
return (o = this.chaiUsers) == null ? void 0 : o.logout();
|
|
287
308
|
case "CHECK_USER_STATUS":
|
|
288
|
-
return this.
|
|
309
|
+
return (c = this.chaiUsers) == null ? void 0 : c.isUserActive(e);
|
|
289
310
|
case "GET_ROLE_AND_PERMISSIONS":
|
|
290
|
-
return this.
|
|
311
|
+
return (l = this.chaiUsers) == null ? void 0 : l.getUserRoleAndPermissions(e);
|
|
291
312
|
case "GET_CHAI_USER":
|
|
292
|
-
return this.
|
|
313
|
+
return (k = this.chaiUsers) == null ? void 0 : k.getUserInfo(
|
|
314
|
+
e,
|
|
315
|
+
a.data
|
|
316
|
+
);
|
|
293
317
|
}
|
|
294
318
|
if (a.action === "GET_BUILDER_PAGE_DATA") {
|
|
295
|
-
const
|
|
319
|
+
const s = await E({
|
|
296
320
|
lang: a.data.lang,
|
|
297
321
|
draft: !0,
|
|
298
322
|
inBuilder: !0
|
|
299
|
-
}),
|
|
323
|
+
}), d = h(
|
|
300
324
|
a.data.pageType
|
|
301
325
|
);
|
|
302
|
-
return
|
|
303
|
-
...
|
|
326
|
+
return d ? {
|
|
327
|
+
...d.dataProvider ? await d.dataProvider({
|
|
304
328
|
lang: a.data.lang,
|
|
305
329
|
draft: !0,
|
|
306
330
|
inBuilder: !0,
|
|
307
331
|
pageProps: a.data.pageProps ?? {}
|
|
308
332
|
}) : {},
|
|
309
|
-
global:
|
|
310
|
-
} : { global:
|
|
333
|
+
global: s
|
|
334
|
+
} : { global: s };
|
|
311
335
|
}
|
|
312
336
|
if (a.action === "GET_PAGE_TYPES")
|
|
313
337
|
return Promise.all(
|
|
314
|
-
|
|
315
|
-
key:
|
|
316
|
-
helpText:
|
|
317
|
-
icon:
|
|
318
|
-
dynamicSegments:
|
|
319
|
-
dynamicSlug:
|
|
320
|
-
hasSlug:
|
|
321
|
-
name: typeof
|
|
338
|
+
w().map(async (s) => ({
|
|
339
|
+
key: s.key,
|
|
340
|
+
helpText: s.helpText ?? "",
|
|
341
|
+
icon: s.icon ?? "",
|
|
342
|
+
dynamicSegments: s.dynamicSegments ?? "",
|
|
343
|
+
dynamicSlug: s.dynamicSlug ?? "",
|
|
344
|
+
hasSlug: s.hasSlug ?? !0,
|
|
345
|
+
name: typeof s.name == "function" ? await s.name() : s.name
|
|
322
346
|
}))
|
|
323
347
|
);
|
|
324
348
|
if (a.action === "SEARCH_PAGE_TYPE_ITEMS") {
|
|
325
|
-
const
|
|
349
|
+
const s = h(
|
|
326
350
|
a.data.pageType
|
|
327
351
|
);
|
|
328
|
-
return
|
|
352
|
+
return s ? s.search ? await s.search(a.data.query) : this.backend.handleAction(a, e) : { error: "Page type not found" };
|
|
329
353
|
}
|
|
330
|
-
const
|
|
331
|
-
return this.emit(a.action,
|
|
354
|
+
const n = await this.backend.handleAction(a, e);
|
|
355
|
+
return this.emit(a.action, n), n;
|
|
332
356
|
}
|
|
333
|
-
emit(a,
|
|
334
|
-
var r,
|
|
357
|
+
emit(a, e) {
|
|
358
|
+
var r, o, c;
|
|
335
359
|
if (!["CREATE_PAGE", "UPDATE_PAGE", "DELETE_PAGE"].includes(a)) return;
|
|
336
|
-
const
|
|
337
|
-
if (!
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
360
|
+
const n = p(e, "page");
|
|
361
|
+
if (!n) return;
|
|
362
|
+
const t = h(n.pageType);
|
|
363
|
+
if (t)
|
|
340
364
|
switch (a) {
|
|
341
365
|
case "CREATE_PAGE":
|
|
342
|
-
return (r =
|
|
366
|
+
return (r = t.onCreate) == null ? void 0 : r.call(t, n);
|
|
343
367
|
case "UPDATE_PAGE":
|
|
344
|
-
return (
|
|
368
|
+
return (o = t.onUpdate) == null ? void 0 : o.call(t, n);
|
|
345
369
|
case "DELETE_PAGE":
|
|
346
|
-
return (c =
|
|
370
|
+
return (c = t.onDelete) == null ? void 0 : c.call(t, n);
|
|
347
371
|
}
|
|
348
372
|
}
|
|
349
373
|
// APIS
|
|
@@ -352,41 +376,41 @@ class T {
|
|
|
352
376
|
throw new Error(
|
|
353
377
|
"Please set a fallback language using setFallbackLang(lang: string)"
|
|
354
378
|
);
|
|
355
|
-
const
|
|
356
|
-
Object.keys(
|
|
379
|
+
const e = P(a || [""]);
|
|
380
|
+
Object.keys(U).includes(e) ? this.setCurrentLang(e) : this.setCurrentLang(this.getFallbackLang());
|
|
357
381
|
}
|
|
358
|
-
async resolveLink(a,
|
|
359
|
-
const
|
|
360
|
-
if (!
|
|
382
|
+
async resolveLink(a, e) {
|
|
383
|
+
const n = h(a);
|
|
384
|
+
if (!n)
|
|
361
385
|
return "/not-found";
|
|
362
|
-
const
|
|
363
|
-
return
|
|
386
|
+
const t = this.isDraftMode(), r = this.getCurrentLang();
|
|
387
|
+
return n.resolveLink ? await n.resolveLink(e, t, r) : await this.backend.handleAction({
|
|
364
388
|
action: "GET_LINK",
|
|
365
389
|
data: {
|
|
366
390
|
pageType: a,
|
|
367
|
-
id:
|
|
368
|
-
draft:
|
|
391
|
+
id: e,
|
|
392
|
+
draft: t,
|
|
369
393
|
lang: r
|
|
370
394
|
}
|
|
371
395
|
});
|
|
372
396
|
}
|
|
373
397
|
async getPageBySlug(a) {
|
|
374
|
-
const
|
|
375
|
-
return
|
|
376
|
-
|
|
398
|
+
const e = this.isDraftMode(), n = {};
|
|
399
|
+
return w().forEach((t) => {
|
|
400
|
+
m(t, "dynamicSegments") && t.dynamicSegments && (n[t.key] = t.dynamicSegments);
|
|
377
401
|
}), await this.backend.handleAction({
|
|
378
402
|
action: "GET_PAGE_META",
|
|
379
|
-
data: { slug: a, draft:
|
|
403
|
+
data: { slug: a, draft: e, dynamicSegments: n }
|
|
380
404
|
});
|
|
381
405
|
}
|
|
382
406
|
async getFullPage(a) {
|
|
383
|
-
const
|
|
407
|
+
const e = this.isDraftMode(), n = this.getCurrentLang(), t = this.getFallbackLang();
|
|
384
408
|
return await this.backend.handleAction({
|
|
385
409
|
action: "GET_PAGE",
|
|
386
410
|
data: {
|
|
387
411
|
id: a,
|
|
388
|
-
lang:
|
|
389
|
-
draft:
|
|
412
|
+
lang: t === n ? void 0 : n,
|
|
413
|
+
draft: e,
|
|
390
414
|
mergePartials: !0
|
|
391
415
|
}
|
|
392
416
|
});
|
|
@@ -398,25 +422,25 @@ class T {
|
|
|
398
422
|
data: { draft: a }
|
|
399
423
|
});
|
|
400
424
|
}
|
|
401
|
-
async getPageData(a,
|
|
402
|
-
var
|
|
403
|
-
const
|
|
425
|
+
async getPageData(a, e = {}) {
|
|
426
|
+
var l;
|
|
427
|
+
const n = this.isDraftMode(), t = this.getCurrentLang(), r = h(a), [o, c] = await Promise.all([
|
|
404
428
|
this.getGlobalData(),
|
|
405
|
-
((
|
|
406
|
-
lang:
|
|
407
|
-
draft:
|
|
429
|
+
((l = r == null ? void 0 : r.dataProvider) == null ? void 0 : l.call(r, {
|
|
430
|
+
lang: t,
|
|
431
|
+
draft: n,
|
|
408
432
|
inBuilder: !1,
|
|
409
|
-
pageProps:
|
|
433
|
+
pageProps: e
|
|
410
434
|
})) || Promise.resolve({})
|
|
411
435
|
]);
|
|
412
436
|
return r ? {
|
|
413
437
|
...c,
|
|
414
|
-
global:
|
|
415
|
-
} : { global:
|
|
438
|
+
global: o
|
|
439
|
+
} : { global: o };
|
|
416
440
|
}
|
|
417
441
|
async getGlobalData() {
|
|
418
442
|
const a = this.getCurrentLang();
|
|
419
|
-
return await
|
|
443
|
+
return await E({
|
|
420
444
|
lang: a,
|
|
421
445
|
draft: this.isDraftMode(),
|
|
422
446
|
inBuilder: !1
|
|
@@ -426,45 +450,55 @@ class T {
|
|
|
426
450
|
return await this.backend.handleAction(a);
|
|
427
451
|
}
|
|
428
452
|
}
|
|
429
|
-
class
|
|
430
|
-
constructor(a = "",
|
|
431
|
-
this.apiKey = a, this.apiUrl =
|
|
453
|
+
class D {
|
|
454
|
+
constructor(a = "", e = v) {
|
|
455
|
+
this.apiKey = a, this.apiUrl = e;
|
|
432
456
|
}
|
|
433
|
-
async
|
|
434
|
-
|
|
435
|
-
cache: "no-store",
|
|
457
|
+
async handleUsersAction(a, e) {
|
|
458
|
+
const n = await fetch(`${this.apiUrl}/v1/api/users`, {
|
|
436
459
|
method: "POST",
|
|
437
460
|
body: JSON.stringify(a),
|
|
438
461
|
headers: {
|
|
439
462
|
"x-chai-api-key": this.apiKey,
|
|
440
|
-
|
|
463
|
+
"x-chai-auth-token": e
|
|
441
464
|
}
|
|
442
|
-
})
|
|
465
|
+
}), t = await n.json();
|
|
466
|
+
return m(t, "error") ? { ...t, status: n.status } : t;
|
|
467
|
+
}
|
|
468
|
+
async handleAction(a, e) {
|
|
469
|
+
const n = await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
470
|
+
method: "POST",
|
|
471
|
+
body: JSON.stringify(a),
|
|
472
|
+
headers: {
|
|
473
|
+
"x-chai-api-key": this.apiKey,
|
|
474
|
+
"x-chai-auth-token": e
|
|
475
|
+
}
|
|
476
|
+
}), t = await n.json();
|
|
477
|
+
return m(t, "error") ? { ...t, status: n.status } : t;
|
|
443
478
|
}
|
|
444
|
-
async handleUpload(a,
|
|
445
|
-
return
|
|
479
|
+
async handleUpload(a, e) {
|
|
480
|
+
return await (await fetch(`${this.apiUrl}/v1/api/chai`, {
|
|
446
481
|
method: "POST",
|
|
447
482
|
body: a,
|
|
448
483
|
headers: {
|
|
449
|
-
// "Content-Type": "multipart/form-data",
|
|
450
484
|
"x-chai-api-key": this.apiKey,
|
|
451
485
|
"x-chai-upload": "true",
|
|
452
|
-
|
|
486
|
+
"x-chai-auth-token": e
|
|
453
487
|
}
|
|
454
488
|
})).json();
|
|
455
489
|
}
|
|
456
490
|
}
|
|
457
|
-
const
|
|
491
|
+
const v = "https://api.chaibuilder.com";
|
|
458
492
|
export {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
493
|
+
v as API_URL,
|
|
494
|
+
M as ChaiBuilderPages,
|
|
495
|
+
D as ChaiBuilderPagesBackend,
|
|
496
|
+
L as ChaiBuilderPagesUserManagement,
|
|
497
|
+
U as LANGUAGES,
|
|
498
|
+
E as getChaiGlobalData,
|
|
499
|
+
h as getChaiPageType,
|
|
500
|
+
w as getChaiPageTypes,
|
|
501
|
+
_ as registerChaiGlobalDataProvider,
|
|
502
|
+
C as registerChaiPageType,
|
|
503
|
+
y as registerChaiPartialType
|
|
470
504
|
};
|