@chaibuilder/pages 0.1.19 → 0.2.0

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.js CHANGED
@@ -1,20 +1,20 @@
1
1
  var k = Object.defineProperty;
2
- var _ = (i, a, e) => a in i ? k(i, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[a] = e;
3
- var o = (i, a, e) => _(i, typeof a != "symbol" ? a + "" : a, e);
4
- import { get as b, first as f, has as p } from "lodash-es";
5
- const h = {}, S = (i, a) => {
6
- h[i] = { key: i, ...a, hasSlug: !0 };
7
- }, w = (i, a) => {
8
- h[i] = { key: i, ...a, hasSlug: !1 };
9
- }, d = () => Object.values(h), l = (i) => h[i];
10
- let m = async (i, a = !1, e = !1) => ({
11
- lang: i,
2
+ var f = (t, a, e) => a in t ? k(t, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[a] = e;
3
+ var o = (t, a, e) => f(t, typeof a != "symbol" ? a + "" : a, e);
4
+ import { get as S, first as b, has as w } from "lodash-es";
5
+ const h = {}, A = (t, a) => {
6
+ h[t] = { key: t, ...a, hasSlug: !0 };
7
+ }, E = (t, a) => {
8
+ h[t] = { key: t, ...a, hasSlug: !1 };
9
+ }, g = () => Object.values(h), l = (t) => h[t];
10
+ let m = async (t, a = !1, e = !1) => ({
11
+ lang: t,
12
12
  isDraft: a,
13
13
  inBuilder: e
14
14
  });
15
- const P = (i) => m = i, g = async (i, a, e) => await m(i, a, e), M = (i, a) => {
15
+ const M = (t) => m = t, d = async (t, a, e) => await m(t, a, e), T = (t, a) => {
16
16
  ({ ...a });
17
- }, A = {
17
+ }, C = {
18
18
  ab: "Abkhazian",
19
19
  aa: "Afar",
20
20
  af: "Afrikaans",
@@ -202,8 +202,8 @@ const P = (i) => m = i, g = async (i, a, e) => await m(i, a, e), M = (i, a) => {
202
202
  yo: "Yoruba",
203
203
  za: "Zhuang, Chuang",
204
204
  zu: "Zulu"
205
- }, y = "https://api.chaibuilder.com";
206
- class E {
205
+ }, P = "https://api.chaibuilder.com";
206
+ class y {
207
207
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
208
208
  async verifyTokenAndGetUser(a) {
209
209
  return {
@@ -220,55 +220,21 @@ class E {
220
220
  async getUserRoleAndPermissions(a) {
221
221
  return {
222
222
  role: "admin",
223
- permissions: [
224
- "add_block",
225
- "delete_block",
226
- "save_as_template",
227
- "edit_block",
228
- "move_block",
229
- "edit_theme",
230
- "save_page",
231
- "edit_styles",
232
- "import_html",
233
- "add_page",
234
- "edit_page",
235
- "edit_slug",
236
- "delete_page",
237
- "publish_page",
238
- "unpublish_page",
239
- "add_partial",
240
- "edit_partial",
241
- "delete_partial",
242
- "publish_partial",
243
- "unpublish_partial",
244
- "edit_seo",
245
- "restore_revision",
246
- "delete_revision",
247
- "publish_theme",
248
- "add_library_block",
249
- "add_library_template",
250
- "edit_library_block",
251
- "edit_library_template",
252
- "delete_library_block",
253
- "delete_library_template",
254
- "add_media",
255
- "edit_media",
256
- "delete_media"
257
- ]
223
+ permissions: null
258
224
  };
259
225
  }
260
226
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
261
227
  async getUserInfo(a) {
262
228
  return {
263
- id: "mock-chai-user",
229
+ id: "mock-chai-users",
264
230
  email: "mock-chai-user@chaibuilder.com",
265
231
  name: "Mock Chai User",
266
232
  avatar: "https://i.pravatar.cc/300"
267
233
  };
268
234
  }
269
235
  }
270
- class T {
271
- constructor(a = "", e = y) {
236
+ class G {
237
+ constructor(a = "", e = P) {
272
238
  this.apiKey = a, this.apiUrl = e;
273
239
  }
274
240
  async handleAction(a, e = "") {
@@ -295,19 +261,19 @@ class T {
295
261
  })).json();
296
262
  }
297
263
  }
298
- class G {
264
+ class L {
299
265
  constructor(a) {
300
266
  o(this, "fallbackLang", "");
301
267
  o(this, "currentLang", "");
302
268
  o(this, "draftMode", !1);
303
- o(this, "userMgmt", new E());
269
+ o(this, "userMgmt", new y());
304
270
  this.backend = a, this._registerPageTypes();
305
271
  }
306
272
  _registerPageTypes() {
307
- S("page", {
273
+ A("page", {
308
274
  name: "Static Page",
309
275
  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>'
310
- }), w("global", {
276
+ }), E("global", {
311
277
  name: "Global Block",
312
278
  helpText: "A global block can be reused in multiple pages.",
313
279
  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>'
@@ -347,85 +313,85 @@ class G {
347
313
  return this.userMgmt.getUserInfo(e);
348
314
  }
349
315
  if (a.action === "GET_BUILDER_PAGE_DATA") {
350
- const t = await g(a.data.lang, !0, !0), r = l(
316
+ const n = await d(a.data.lang, !0, !0), s = l(
351
317
  a.data.pageType
352
318
  );
353
- return r ? {
354
- ...r.dataProvider ? await r.dataProvider({}, a.data.lang, !0, !0) : {},
355
- global: t
356
- } : { global: t };
319
+ return s ? {
320
+ ...s.dataProvider ? await s.dataProvider({}, a.data.lang, !0, !0) : {},
321
+ global: n
322
+ } : { global: n };
357
323
  }
358
324
  if (a.action === "GET_PAGE_TYPES")
359
325
  return Promise.all(
360
- d().map(async (t) => ({
361
- key: t.key,
362
- helpText: t.helpText ?? "",
363
- icon: t.icon ?? "",
364
- dynamicSegments: t.dynamicSegments ?? "",
365
- dynamicSlug: t.dynamicSlug ?? "",
366
- hasSlug: t.hasSlug ?? !0,
367
- name: typeof t.name == "function" ? await t.name() : t.name
326
+ g().map(async (n) => ({
327
+ key: n.key,
328
+ helpText: n.helpText ?? "",
329
+ icon: n.icon ?? "",
330
+ dynamicSegments: n.dynamicSegments ?? "",
331
+ dynamicSlug: n.dynamicSlug ?? "",
332
+ hasSlug: n.hasSlug ?? !0,
333
+ name: typeof n.name == "function" ? await n.name() : n.name
368
334
  }))
369
335
  );
370
336
  if (a.action === "SEARCH_PAGE_TYPE_ITEMS") {
371
- const t = l(
337
+ const n = l(
372
338
  a.data.pageType
373
339
  );
374
- return t ? t.search ? await t.search(a.data.query) : this.backend.handleAction(a) : { error: "Page type not found" };
340
+ return n ? n.search ? await n.search(a.data.query) : this.backend.handleAction(a) : { error: "Page type not found" };
375
341
  }
376
- const n = await this.backend.handleAction(a, e);
377
- return this.emit(a.action, n), n;
342
+ const i = await this.backend.handleAction(a, e);
343
+ return this.emit(a.action, i), i;
378
344
  }
379
345
  emit(a, e) {
380
- var r, s, c;
346
+ var s, r, c;
381
347
  if (!["CREATE_PAGE", "UPDATE_PAGE", "DELETE_PAGE"].includes(a)) return;
382
- const n = b(e, "page");
383
- if (!n) return;
384
- const t = l(n.pageType);
385
- if (t)
348
+ const i = S(e, "page");
349
+ if (!i) return;
350
+ const n = l(i.pageType);
351
+ if (n)
386
352
  switch (a) {
387
353
  case "CREATE_PAGE":
388
- return (r = t.onCreate) == null ? void 0 : r.call(t, n);
354
+ return (s = n.onCreate) == null ? void 0 : s.call(n, i);
389
355
  case "UPDATE_PAGE":
390
- return (s = t.onUpdate) == null ? void 0 : s.call(t, n);
356
+ return (r = n.onUpdate) == null ? void 0 : r.call(n, i);
391
357
  case "DELETE_PAGE":
392
- return (c = t.onDelete) == null ? void 0 : c.call(t, n);
358
+ return (c = n.onDelete) == null ? void 0 : c.call(n, i);
393
359
  }
394
360
  }
395
361
  // APIS
396
362
  setLanguageFromSlug(a) {
397
- const e = f(a || [""]);
398
- Object.keys(A).includes(e) ? this.setCurrentLang(e) : this.setCurrentLang("");
363
+ const e = b(a || [""]);
364
+ Object.keys(C).includes(e) ? this.setCurrentLang(e) : this.setCurrentLang("");
399
365
  }
400
366
  async resolveLink(a, e) {
401
- const n = l(a);
402
- if (!n)
367
+ const i = l(a);
368
+ if (!i)
403
369
  return "/not-found";
404
- const t = this.isDraftMode(), r = this.getCurrentLang();
405
- return n.resolveLink ? await n.resolveLink(e, t, r) : await this.backend.handleAction({
370
+ const n = this.isDraftMode(), s = this.getCurrentLang();
371
+ return i.resolveLink ? await i.resolveLink(e, n, s) : await this.backend.handleAction({
406
372
  action: "GET_LINK",
407
373
  data: {
408
374
  pageType: a,
409
375
  id: e,
410
- draft: t,
411
- lang: r
376
+ draft: n,
377
+ lang: s
412
378
  }
413
379
  });
414
380
  }
415
381
  async getPageBySlug(a) {
416
- const e = this.isDraftMode(), n = {};
417
- return d().forEach((t) => {
418
- p(t, "dynamicSegments") && t.dynamicSegments && (n[t.key] = t.dynamicSegments);
382
+ const e = this.isDraftMode(), i = {};
383
+ return g().forEach((n) => {
384
+ w(n, "dynamicSegments") && n.dynamicSegments && (i[n.key] = n.dynamicSegments);
419
385
  }), await this.backend.handleAction({
420
386
  action: "GET_PAGE_META",
421
- data: { slug: a, draft: e, dynamicSegments: n }
387
+ data: { slug: a, draft: e, dynamicSegments: i }
422
388
  });
423
389
  }
424
390
  async getFullPage(a) {
425
- const e = this.isDraftMode(), n = this.getCurrentLang();
391
+ const e = this.isDraftMode(), i = this.getCurrentLang();
426
392
  return await this.backend.handleAction({
427
393
  action: "GET_PAGE",
428
- data: { id: a, lang: n, draft: e, mergePartials: !0 }
394
+ data: { id: a, lang: i, draft: e, mergePartials: !0 }
429
395
  });
430
396
  }
431
397
  async getSiteSettings() {
@@ -437,32 +403,32 @@ class G {
437
403
  }
438
404
  async getPageData(a, e) {
439
405
  var u;
440
- const n = this.isDraftMode(), t = this.getCurrentLang(), r = l(a), [s, c] = await Promise.all([
406
+ const i = this.isDraftMode(), n = this.getCurrentLang(), s = l(a), [r, c] = await Promise.all([
441
407
  this.getGlobalData(),
442
- ((u = r == null ? void 0 : r.dataProvider) == null ? void 0 : u.call(r, e, t, n)) || Promise.resolve({})
408
+ ((u = s == null ? void 0 : s.dataProvider) == null ? void 0 : u.call(s, e, n, i)) || Promise.resolve({})
443
409
  ]);
444
- return r ? {
410
+ return s ? {
445
411
  ...c,
446
- global: s
447
- } : { global: s };
412
+ global: r
413
+ } : { global: r };
448
414
  }
449
415
  async getGlobalData() {
450
416
  const a = this.getCurrentLang();
451
- return await g(a, this.isDraftMode());
417
+ return await d(a, this.isDraftMode());
452
418
  }
453
419
  async request(a) {
454
420
  return await this.backend.handleAction(a);
455
421
  }
456
422
  }
457
423
  export {
458
- G as ChaiBuilderPages,
459
- T as ChaiBuilderPagesBackend,
460
- E as ChaiBuilderPagesUserManagement,
461
- g as getChaiGlobalData,
424
+ L as ChaiBuilderPages,
425
+ G as ChaiBuilderPagesBackend,
426
+ y as ChaiBuilderPagesUserManagement,
427
+ d as getChaiGlobalData,
462
428
  l as getChaiPageType,
463
- d as getChaiPageTypes,
464
- P as registerChaiGlobalDataProvider,
465
- S as registerChaiPageType,
466
- w as registerChaiPartialType,
467
- M as registerChaiTaxonomy
429
+ g as getChaiPageTypes,
430
+ M as registerChaiGlobalDataProvider,
431
+ A as registerChaiPageType,
432
+ E as registerChaiPartialType,
433
+ T as registerChaiTaxonomy
468
434
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Suraj Air",
4
4
  "license": "Private",
5
5
  "homepage": "https://chaibuilder.com",
6
- "version": "0.1.19",
6
+ "version": "0.2.0",
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.0.12",
62
+ "@chaibuilder/sdk": "2.1.3",
63
63
  "@types/react": "*",
64
64
  "@types/react-dom": "*",
65
65
  "react": "^18.0 || ^19.0",
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "@chaibuilder/runtime": "2.0.6",
81
- "@chaibuilder/sdk": "2.0.12",
81
+ "@chaibuilder/sdk": "2.1.3",
82
82
  "@mhsdesign/jit-browser-tailwindcss": "^0.4.2",
83
83
  "@tailwindcss/aspect-ratio": "^0.4.2",
84
84
  "@tailwindcss/forms": "^0.5.10",