@chaibuilder/pages 0.1.5 → 0.1.7
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 +33 -27
- package/dist/server.js +74 -82
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var C=Object.defineProperty;var S=(i,a,t)=>a in i?C(i,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[a]=t;var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var S=(i,a,t)=>a in i?C(i,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[a]=t;var l=(i,a,t)=>S(i,typeof a!="symbol"?a+"":a,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("lodash-es"),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"},h={},k=(i,a)=>{h[i]={key:i,...a,hasSlug:!0}},b=(i,a)=>{h[i]={key:i,...a,hasSlug:!1}},g=()=>Object.values(h),s=i=>h[i];let _=async(i,a=!1,t=!1)=>({lang:i,isDraft:a,inBuilder:t});const A=i=>_=i,d=async(i,a,t)=>await _(i,a,t),w=(i,a)=>{({...a})},E="https://api.chaibuilder.com";class f{async verifyTokenAndGetUser(a){return console.log(a),{id:"mock-chai-user",name:"Mock Chai User",email:"mock-chai-user@chaibuilder.com"}}async isUserActive(a){return console.log("isUserActive",a),!0}async getUserPermissions(a){return console.log("getUserPermissions",a),["add_block","delete_block","edit_block","move_block","edit_theme","save_page","edit_styles","import_html","add_page","edit_page","edit_slug","delete_page","publish_page","unpublish_page","add_partial","edit_partial","delete_partial","publish_partial","unpublish_partial","edit_seo","restore_revision","delete_revision","publish_theme","add_library_block","add_library_template","edit_library_block","edit_library_template","delete_library_block","delete_library_template","add_media","edit_media","delete_media"]}async getUserInfo(a){return console.log("getUserInfo",a),{id:"mock-chai-user",email:"mock-chai-user@chaibuilder.com",name:"Mock Chai User",avatar:"https://i.pravatar.cc/300"}}}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()}}class v{constructor(a){l(this,"fallbackLang","");l(this,"currentLang","");l(this,"draftMode",!1);l(this,"userMgmt",new f);this.backend=a,this._registerPageTypes()}_registerPageTypes(){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>'}),b("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){this.fallbackLang=a}getFallbackLang(){return this.fallbackLang}setCurrentLang(a){this.currentLang=a}getCurrentLang(){return this.currentLang}setDraftMode(a){this.draftMode=a}isDraftMode(){return this.draftMode}async handle(a,t){switch(a.action){case"CHECK_USER_STATUS":return this.userMgmt.isUserActive(a.data.authToken);case"GET_PERMISSIONS":return this.userMgmt.getUserPermissions(a.data.authToken);case"GET_CHAI_USER":return this.userMgmt.getUserInfo(a.data.userId)}if(a.action==="GET_BUILDER_PAGE_DATA"){const e=await d(a.data.lang,!0,!0),r=s(a.data.pageType);return r?{...r.dataProvider?await r.dataProvider({},a.data.lang,!0,!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,c;if(!["CREATE_PAGE","UPDATE_PAGE","DELETE_PAGE"].includes(a))return;const n=u.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(c=e.onDelete)==null?void 0:c.call(e,n)}}setLanguageFromSlug(a){const t=u.first(a||[""]);Object.keys(P).includes(t)?this.setCurrentLang(t):this.setCurrentLang("")}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=>{u.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();return await this.backend.handleAction({action:"GET_PAGE",data:{id:a,lang: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,c]=await Promise.all([this.getGlobalData(),((m=r==null?void 0:r.dataProvider)==null?void 0:m.call(r,t,e,n))||Promise.resolve({})]);return r?{...c,global:o}:{global:o}}async getGlobalData(){const a=this.getCurrentLang();return await d(a,this.isDraftMode())}async request(a){return await this.backend.handleAction(a)}}exports.ChaiBuilderPages=v;exports.ChaiBuilderPagesBackend=p;exports.ChaiBuilderPagesUserManagement=f;exports.getChaiGlobalData=d;exports.getChaiPageType=s;exports.getChaiPageTypes=g;exports.registerChaiGlobalDataProvider=A;exports.registerChaiPageType=k;exports.registerChaiPartialType=b;exports.registerChaiTaxonomy=w;
|
package/dist/server.d.ts
CHANGED
|
@@ -12,22 +12,20 @@ export declare class ChaiBuilderPages implements ChaiBuilderPagesInterface {
|
|
|
12
12
|
private fallbackLang;
|
|
13
13
|
private currentLang;
|
|
14
14
|
private draftMode;
|
|
15
|
-
private
|
|
15
|
+
private userMgmt;
|
|
16
16
|
constructor(backend: ChaiBuilderPagesBackendInterface);
|
|
17
17
|
private _registerPageTypes;
|
|
18
|
-
|
|
18
|
+
setUserManagement(usersMgmt: ChaiBuilderPagesUserManagementInterface): void;
|
|
19
19
|
setFallbackLang(lang: string): void;
|
|
20
20
|
getFallbackLang(): string;
|
|
21
21
|
setCurrentLang(lang: string): void;
|
|
22
22
|
getCurrentLang(): string;
|
|
23
23
|
setDraftMode(draft: boolean): void;
|
|
24
24
|
isDraftMode(): boolean;
|
|
25
|
-
verifyToken(): Promise<boolean>;
|
|
26
|
-
getUserInfo(userId: string): Promise<ChaiBuilderUserInfo>;
|
|
27
25
|
handle(body: {
|
|
28
26
|
action: string;
|
|
29
27
|
data: Record<string, any>;
|
|
30
|
-
}): Promise<any>;
|
|
28
|
+
}, userId?: string): Promise<any>;
|
|
31
29
|
emit(action: string, data: any): Promise<void> | undefined;
|
|
32
30
|
setLanguageFromSlug(slug: string[]): void;
|
|
33
31
|
resolveLink(pageTypeKey: string, id: string): Promise<any>;
|
|
@@ -41,13 +39,6 @@ export declare class ChaiBuilderPages implements ChaiBuilderPagesInterface {
|
|
|
41
39
|
request(body: any): Promise<any>;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
declare interface ChaiBuilderPagesAuthInterface {
|
|
45
|
-
isUserActive(chaiUser: string): Promise<boolean>;
|
|
46
|
-
getUserPermissions(chaiUser: string): Promise<string[]>;
|
|
47
|
-
verifyToken(): Promise<boolean>;
|
|
48
|
-
getUserId(): string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
42
|
export declare class ChaiBuilderPagesBackend implements ChaiBuilderPagesBackendInterface {
|
|
52
43
|
private apiKey;
|
|
53
44
|
private apiUrl;
|
|
@@ -59,26 +50,14 @@ export declare interface ChaiBuilderPagesBackendInterface {
|
|
|
59
50
|
handleAction(body: any, chaiUser?: string): Promise<any>;
|
|
60
51
|
}
|
|
61
52
|
|
|
62
|
-
export declare
|
|
63
|
-
protected token: string;
|
|
64
|
-
protected userId: string;
|
|
65
|
-
constructor(token: string);
|
|
66
|
-
verifyToken(): Promise<boolean>;
|
|
67
|
-
isUserActive(): Promise<boolean>;
|
|
68
|
-
getUserPermissions(): Promise<string[]>;
|
|
69
|
-
getUserId(): string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
declare interface ChaiBuilderPagesInterface {
|
|
53
|
+
export declare interface ChaiBuilderPagesInterface {
|
|
73
54
|
setFallbackLang(lang: string): void;
|
|
74
55
|
getFallbackLang(): string;
|
|
75
56
|
setCurrentLang(lang: string): void;
|
|
76
57
|
getCurrentLang(): string;
|
|
77
58
|
setDraftMode(draft: boolean): void;
|
|
78
59
|
isDraftMode(): boolean;
|
|
79
|
-
|
|
80
|
-
verifyToken(): Promise<boolean>;
|
|
81
|
-
getUserInfo(userId: string): Promise<ChaiBuilderUserInfo>;
|
|
60
|
+
setUserManagement(usersMgmt: ChaiBuilderPagesUserManagementInterface): void;
|
|
82
61
|
handle(body: any): Promise<any>;
|
|
83
62
|
emit(action: string, data: any): void;
|
|
84
63
|
setLanguageFromSlug(slug: string[]): void;
|
|
@@ -90,6 +69,33 @@ declare interface ChaiBuilderPagesInterface {
|
|
|
90
69
|
getGlobalData(): Promise<any>;
|
|
91
70
|
}
|
|
92
71
|
|
|
72
|
+
export declare class ChaiBuilderPagesUserManagement implements ChaiBuilderPagesUserManagementInterface {
|
|
73
|
+
verifyTokenAndGetUser(token: string): Promise<{
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
email: string;
|
|
77
|
+
}>;
|
|
78
|
+
isUserActive(userId: string): Promise<boolean>;
|
|
79
|
+
getUserPermissions(userId: string): Promise<string[]>;
|
|
80
|
+
getUserInfo(userId: string): Promise<{
|
|
81
|
+
id: string;
|
|
82
|
+
email: string;
|
|
83
|
+
name: string;
|
|
84
|
+
avatar: string;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export declare interface ChaiBuilderPagesUserManagementInterface {
|
|
89
|
+
isUserActive(chaiUserId: string): Promise<boolean>;
|
|
90
|
+
getUserPermissions(chaiUserId: string): Promise<string[]>;
|
|
91
|
+
verifyTokenAndGetUser(token: string): Promise<{
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
email: string;
|
|
95
|
+
}>;
|
|
96
|
+
getUserInfo(chaiUserId: string): Promise<ChaiBuilderUserInfo>;
|
|
97
|
+
}
|
|
98
|
+
|
|
93
99
|
export declare type ChaiBuilderPageType = {
|
|
94
100
|
key: string;
|
|
95
101
|
helpText?: string;
|
|
@@ -112,7 +118,7 @@ export declare type ChaiBuilderTaxonomyType = {
|
|
|
112
118
|
slug?: string;
|
|
113
119
|
};
|
|
114
120
|
|
|
115
|
-
declare type ChaiBuilderUserInfo = {
|
|
121
|
+
export declare type ChaiBuilderUserInfo = {
|
|
116
122
|
id: string;
|
|
117
123
|
email: string;
|
|
118
124
|
name: string;
|
package/dist/server.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var k = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { get as
|
|
5
|
-
const
|
|
2
|
+
var b = (i, a, t) => a in i ? k(i, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[a] = t;
|
|
3
|
+
var o = (i, a, t) => b(i, typeof a != "symbol" ? a + "" : a, t);
|
|
4
|
+
import { get as _, first as f, has as S } from "lodash-es";
|
|
5
|
+
const A = {
|
|
6
6
|
ab: "Abkhazian",
|
|
7
7
|
aa: "Afar",
|
|
8
8
|
af: "Afrikaans",
|
|
@@ -190,32 +190,32 @@ const w = {
|
|
|
190
190
|
yo: "Yoruba",
|
|
191
191
|
za: "Zhuang, Chuang",
|
|
192
192
|
zu: "Zulu"
|
|
193
|
-
},
|
|
194
|
-
|
|
193
|
+
}, h = {}, w = (i, a) => {
|
|
194
|
+
h[i] = { key: i, ...a, hasSlug: !0 };
|
|
195
195
|
}, E = (i, a) => {
|
|
196
|
-
|
|
197
|
-
}, g = () => Object.values(
|
|
196
|
+
h[i] = { key: i, ...a, hasSlug: !1 };
|
|
197
|
+
}, g = () => Object.values(h), l = (i) => h[i];
|
|
198
198
|
let m = async (i, a = !1, t = !1) => ({
|
|
199
199
|
lang: i,
|
|
200
200
|
isDraft: a,
|
|
201
201
|
inBuilder: t
|
|
202
202
|
});
|
|
203
|
-
const y = (i) => m = i, d = async (i, a, t) => await m(i, a, t),
|
|
203
|
+
const y = (i) => m = i, d = async (i, a, t) => await m(i, a, t), M = (i, a) => {
|
|
204
204
|
({ ...a });
|
|
205
|
-
},
|
|
205
|
+
}, C = "https://api.chaibuilder.com";
|
|
206
206
|
class p {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
207
|
+
async verifyTokenAndGetUser(a) {
|
|
208
|
+
return console.log(a), {
|
|
209
|
+
id: "mock-chai-user",
|
|
210
|
+
name: "Mock Chai User",
|
|
211
|
+
email: "mock-chai-user@chaibuilder.com"
|
|
212
|
+
};
|
|
213
213
|
}
|
|
214
|
-
async isUserActive() {
|
|
215
|
-
return !0;
|
|
214
|
+
async isUserActive(a) {
|
|
215
|
+
return console.log("isUserActive", a), !0;
|
|
216
216
|
}
|
|
217
|
-
async getUserPermissions() {
|
|
218
|
-
return [
|
|
217
|
+
async getUserPermissions(a) {
|
|
218
|
+
return console.log("getUserPermissions", a), [
|
|
219
219
|
"add_block",
|
|
220
220
|
"delete_block",
|
|
221
221
|
"edit_block",
|
|
@@ -250,12 +250,17 @@ class p {
|
|
|
250
250
|
"delete_media"
|
|
251
251
|
];
|
|
252
252
|
}
|
|
253
|
-
|
|
254
|
-
return
|
|
253
|
+
async getUserInfo(a) {
|
|
254
|
+
return console.log("getUserInfo", a), {
|
|
255
|
+
id: "mock-chai-user",
|
|
256
|
+
email: "mock-chai-user@chaibuilder.com",
|
|
257
|
+
name: "Mock Chai User",
|
|
258
|
+
avatar: "https://i.pravatar.cc/300"
|
|
259
|
+
};
|
|
255
260
|
}
|
|
256
261
|
}
|
|
257
|
-
class
|
|
258
|
-
constructor(a = "", t =
|
|
262
|
+
class T {
|
|
263
|
+
constructor(a = "", t = C) {
|
|
259
264
|
this.apiKey = a, this.apiUrl = t;
|
|
260
265
|
}
|
|
261
266
|
async handleAction(a, t = "") {
|
|
@@ -272,16 +277,14 @@ class M {
|
|
|
272
277
|
}
|
|
273
278
|
class G {
|
|
274
279
|
constructor(a) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
"DUMMY_TOKEN"
|
|
280
|
-
));
|
|
280
|
+
o(this, "fallbackLang", "");
|
|
281
|
+
o(this, "currentLang", "");
|
|
282
|
+
o(this, "draftMode", !1);
|
|
283
|
+
o(this, "userMgmt", new p());
|
|
281
284
|
this.backend = a, this._registerPageTypes();
|
|
282
285
|
}
|
|
283
286
|
_registerPageTypes() {
|
|
284
|
-
|
|
287
|
+
w("page", {
|
|
285
288
|
name: "Static Page",
|
|
286
289
|
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>'
|
|
287
290
|
}), E("global", {
|
|
@@ -290,8 +293,8 @@ class G {
|
|
|
290
293
|
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>'
|
|
291
294
|
});
|
|
292
295
|
}
|
|
293
|
-
|
|
294
|
-
this.
|
|
296
|
+
setUserManagement(a) {
|
|
297
|
+
this.userMgmt = a;
|
|
295
298
|
}
|
|
296
299
|
setFallbackLang(a) {
|
|
297
300
|
this.fallbackLang = a;
|
|
@@ -311,32 +314,21 @@ class G {
|
|
|
311
314
|
isDraftMode() {
|
|
312
315
|
return this.draftMode;
|
|
313
316
|
}
|
|
314
|
-
async
|
|
315
|
-
return await this.auth.verifyToken();
|
|
316
|
-
}
|
|
317
|
-
async getUserInfo(a) {
|
|
318
|
-
return {
|
|
319
|
-
id: a,
|
|
320
|
-
email: `${a}@chaibuilder.com`,
|
|
321
|
-
name: "Mock Chai User",
|
|
322
|
-
avatar: "https://i.pravatar.cc/300"
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
async handle(a) {
|
|
317
|
+
async handle(a, t) {
|
|
326
318
|
switch (a.action) {
|
|
327
319
|
case "CHECK_USER_STATUS":
|
|
328
|
-
return this.
|
|
320
|
+
return this.userMgmt.isUserActive(a.data.authToken);
|
|
329
321
|
case "GET_PERMISSIONS":
|
|
330
|
-
return this.
|
|
322
|
+
return this.userMgmt.getUserPermissions(a.data.authToken);
|
|
331
323
|
case "GET_CHAI_USER":
|
|
332
|
-
return this.getUserInfo(a.data.userId);
|
|
324
|
+
return this.userMgmt.getUserInfo(a.data.userId);
|
|
333
325
|
}
|
|
334
326
|
if (a.action === "GET_BUILDER_PAGE_DATA") {
|
|
335
|
-
const e = await d(a.data.lang, !0, !0),
|
|
327
|
+
const e = await d(a.data.lang, !0, !0), r = l(
|
|
336
328
|
a.data.pageType
|
|
337
329
|
);
|
|
338
|
-
return
|
|
339
|
-
...
|
|
330
|
+
return r ? {
|
|
331
|
+
...r.dataProvider ? await r.dataProvider({}, a.data.lang, !0, !0) : {},
|
|
340
332
|
global: e
|
|
341
333
|
} : { global: e };
|
|
342
334
|
}
|
|
@@ -358,59 +350,59 @@ class G {
|
|
|
358
350
|
);
|
|
359
351
|
return e ? e.search ? await e.search(a.data.query) : this.backend.handleAction(a) : { error: "Page type not found" };
|
|
360
352
|
}
|
|
361
|
-
const
|
|
362
|
-
return this.emit(a.action,
|
|
353
|
+
const n = await this.backend.handleAction(a, t);
|
|
354
|
+
return this.emit(a.action, n), n;
|
|
363
355
|
}
|
|
364
356
|
emit(a, t) {
|
|
365
|
-
var r,
|
|
357
|
+
var r, s, c;
|
|
366
358
|
if (!["CREATE_PAGE", "UPDATE_PAGE", "DELETE_PAGE"].includes(a)) return;
|
|
367
|
-
const
|
|
368
|
-
if (!
|
|
369
|
-
const
|
|
370
|
-
if (
|
|
359
|
+
const n = _(t, "page");
|
|
360
|
+
if (!n) return;
|
|
361
|
+
const e = l(n.pageType);
|
|
362
|
+
if (e)
|
|
371
363
|
switch (a) {
|
|
372
364
|
case "CREATE_PAGE":
|
|
373
|
-
return (r =
|
|
365
|
+
return (r = e.onCreate) == null ? void 0 : r.call(e, n);
|
|
374
366
|
case "UPDATE_PAGE":
|
|
375
|
-
return (
|
|
367
|
+
return (s = e.onUpdate) == null ? void 0 : s.call(e, n);
|
|
376
368
|
case "DELETE_PAGE":
|
|
377
|
-
return (
|
|
369
|
+
return (c = e.onDelete) == null ? void 0 : c.call(e, n);
|
|
378
370
|
}
|
|
379
371
|
}
|
|
380
372
|
// APIS
|
|
381
373
|
setLanguageFromSlug(a) {
|
|
382
374
|
const t = f(a || [""]);
|
|
383
|
-
Object.keys(
|
|
375
|
+
Object.keys(A).includes(t) ? this.setCurrentLang(t) : this.setCurrentLang("");
|
|
384
376
|
}
|
|
385
377
|
async resolveLink(a, t) {
|
|
386
|
-
const
|
|
387
|
-
if (!
|
|
378
|
+
const n = l(a);
|
|
379
|
+
if (!n)
|
|
388
380
|
return "/not-found";
|
|
389
|
-
const
|
|
390
|
-
return
|
|
381
|
+
const e = this.isDraftMode(), r = this.getCurrentLang();
|
|
382
|
+
return n.resolveLink ? await n.resolveLink(t, e, r) : await this.backend.handleAction({
|
|
391
383
|
action: "GET_LINK",
|
|
392
384
|
data: {
|
|
393
385
|
pageType: a,
|
|
394
386
|
id: t,
|
|
395
|
-
draft:
|
|
387
|
+
draft: e,
|
|
396
388
|
lang: r
|
|
397
389
|
}
|
|
398
390
|
});
|
|
399
391
|
}
|
|
400
392
|
async getPageBySlug(a) {
|
|
401
|
-
const t = this.isDraftMode(),
|
|
402
|
-
return g().forEach((
|
|
403
|
-
S(
|
|
393
|
+
const t = this.isDraftMode(), n = {};
|
|
394
|
+
return g().forEach((e) => {
|
|
395
|
+
S(e, "dynamicSegments") && e.dynamicSegments && (n[e.key] = e.dynamicSegments);
|
|
404
396
|
}), await this.backend.handleAction({
|
|
405
397
|
action: "GET_PAGE_META",
|
|
406
|
-
data: { slug: a, draft: t, dynamicSegments:
|
|
398
|
+
data: { slug: a, draft: t, dynamicSegments: n }
|
|
407
399
|
});
|
|
408
400
|
}
|
|
409
401
|
async getFullPage(a) {
|
|
410
|
-
const t = this.isDraftMode(),
|
|
402
|
+
const t = this.isDraftMode(), n = this.getCurrentLang();
|
|
411
403
|
return await this.backend.handleAction({
|
|
412
404
|
action: "GET_PAGE",
|
|
413
|
-
data: { id: a, lang:
|
|
405
|
+
data: { id: a, lang: n, draft: t, mergePartials: !0 }
|
|
414
406
|
});
|
|
415
407
|
}
|
|
416
408
|
async getSiteSettings() {
|
|
@@ -422,14 +414,14 @@ class G {
|
|
|
422
414
|
}
|
|
423
415
|
async getPageData(a, t) {
|
|
424
416
|
var u;
|
|
425
|
-
const
|
|
417
|
+
const n = this.isDraftMode(), e = this.getCurrentLang(), r = l(a), [s, c] = await Promise.all([
|
|
426
418
|
this.getGlobalData(),
|
|
427
|
-
((u = r == null ? void 0 : r.dataProvider) == null ? void 0 : u.call(r, t,
|
|
419
|
+
((u = r == null ? void 0 : r.dataProvider) == null ? void 0 : u.call(r, t, e, n)) || Promise.resolve({})
|
|
428
420
|
]);
|
|
429
421
|
return r ? {
|
|
430
|
-
...
|
|
431
|
-
global:
|
|
432
|
-
} : { global:
|
|
422
|
+
...c,
|
|
423
|
+
global: s
|
|
424
|
+
} : { global: s };
|
|
433
425
|
}
|
|
434
426
|
async getGlobalData() {
|
|
435
427
|
const a = this.getCurrentLang();
|
|
@@ -441,13 +433,13 @@ class G {
|
|
|
441
433
|
}
|
|
442
434
|
export {
|
|
443
435
|
G as ChaiBuilderPages,
|
|
444
|
-
|
|
445
|
-
p as
|
|
436
|
+
T as ChaiBuilderPagesBackend,
|
|
437
|
+
p as ChaiBuilderPagesUserManagement,
|
|
446
438
|
d as getChaiGlobalData,
|
|
447
439
|
l as getChaiPageType,
|
|
448
440
|
g as getChaiPageTypes,
|
|
449
441
|
y as registerChaiGlobalDataProvider,
|
|
450
|
-
|
|
442
|
+
w as registerChaiPageType,
|
|
451
443
|
E as registerChaiPartialType,
|
|
452
|
-
|
|
444
|
+
M as registerChaiTaxonomy
|
|
453
445
|
};
|