@chaibuilder/pages 0.4.2 → 0.4.5

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,23 +1,66 @@
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
- ...i
1
+ var _ = Object.defineProperty;
2
+ var C = (s, a, e) => a in s ? _(s, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[a] = e;
3
+ var u = (s, a, e) => C(s, typeof a != "symbol" ? a + "" : a, e);
4
+ import { isEmpty as b, get as L, first as y, has as A } from "lodash-es";
5
+ const g = {}, U = (s, a) => {
6
+ g[s] = { key: s, ...a, hasSlug: !0 };
7
+ }, v = (s, a) => {
8
+ g[s] = { key: s, ...a, hasSlug: !1 };
9
+ }, T = () => Object.values(g), l = (s) => g[s];
10
+ let p = async (s) => ({
11
+ ...s
12
12
  });
13
- const _ = (i) => S = i, E = async (i) => {
13
+ const B = (s) => p = s, P = async (s) => {
14
14
  try {
15
- return await S(i);
15
+ return await p(s);
16
16
  } catch (a) {
17
17
  return console.error(a), {};
18
18
  }
19
19
  };
20
- class L {
20
+ class G {
21
+ constructor(a) {
22
+ this.backend = a;
23
+ }
24
+ async upload({
25
+ file: a,
26
+ folderId: e,
27
+ name: t
28
+ }) {
29
+ return await this.backend.handleAssetsAction({
30
+ action: "UPLOAD_ASSET",
31
+ data: {
32
+ name: t,
33
+ file: a,
34
+ folderId: e
35
+ }
36
+ });
37
+ }
38
+ async getAssets(a) {
39
+ return this.backend.handleAssetsAction({
40
+ action: "GET_ASSETS",
41
+ data: a
42
+ });
43
+ }
44
+ async deleteAsset(a) {
45
+ return this.backend.handleAssetsAction({
46
+ action: "DELETE_ASSET",
47
+ data: { assetId: a }
48
+ });
49
+ }
50
+ async updateAssetMetadata(a) {
51
+ return this.backend.handleAssetsAction({
52
+ action: "UPDATE_ASSET_METADATA",
53
+ data: a
54
+ });
55
+ }
56
+ async updateAssetFile({ id: a, file: e }) {
57
+ return this.backend.handleAssetsAction({
58
+ action: "UPDATE_ASSET_FILE",
59
+ data: { id: a, file: e }
60
+ });
61
+ }
62
+ }
63
+ class D {
21
64
  constructor(a) {
22
65
  this.backend = a;
23
66
  }
@@ -32,10 +75,11 @@ class L {
32
75
  email: a,
33
76
  password: e
34
77
  }) {
35
- return await this.backend.handleUsersAction({
78
+ const t = await this.backend.handleUsersAction({
36
79
  action: "LOGIN",
37
80
  data: { email: a, password: e }
38
81
  });
82
+ return t.error ? { error: t.error } : t;
39
83
  }
40
84
  async logout() {
41
85
  await this.backend.handleUsersAction({
@@ -61,7 +105,7 @@ class L {
61
105
  );
62
106
  }
63
107
  }
64
- const U = {
108
+ const M = {
65
109
  ab: "Abkhazian",
66
110
  aa: "Afar",
67
111
  af: "Afrikaans",
@@ -250,25 +294,25 @@ const U = {
250
294
  za: "Zhuang, Chuang",
251
295
  zu: "Zulu"
252
296
  };
253
- class M {
254
- constructor(a, e) {
297
+ class K {
298
+ constructor(a, e, t) {
255
299
  u(this, "fallbackLang", "");
256
300
  u(this, "currentLang", "");
257
301
  u(this, "draftMode", !1);
258
- this.backend = a, this.chaiUsers = e, this._registerDefaultPageTypes(), this.chaiUsers = e ?? new L(this.backend);
302
+ this.backend = a, this.chaiUsers = e, this.chaiAssets = t, this._registerDefaultPageTypes(), this.chaiUsers = e ?? new D(this.backend), this.chaiAssets = t ?? new G(this.backend);
259
303
  }
260
304
  _registerDefaultPageTypes() {
261
- C("page", {
305
+ U("page", {
262
306
  name: "Static Page",
263
307
  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>'
264
- }), y("global", {
308
+ }), v("global", {
265
309
  name: "Global Block",
266
310
  helpText: "A global block can be reused in multiple pages.",
267
311
  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>'
268
312
  });
269
313
  }
270
314
  setFallbackLang(a) {
271
- if (f(a))
315
+ if (b(a))
272
316
  throw new Error("Fallback language cannot be empty");
273
317
  this.fallbackLang = a;
274
318
  }
@@ -276,7 +320,7 @@ class M {
276
320
  return this.fallbackLang;
277
321
  }
278
322
  setCurrentLang(a) {
279
- if (f(a))
323
+ if (b(a))
280
324
  throw new Error("Current language cannot be empty");
281
325
  this.currentLang = a;
282
326
  }
@@ -289,38 +333,52 @@ class M {
289
333
  isDraftMode() {
290
334
  return this.draftMode;
291
335
  }
292
- async handleUpload(a, e = "") {
293
- return await this.backend.handleUpload(a, e);
294
- }
295
336
  async handle(a, e) {
296
- var t, r, o, c, l, k;
337
+ var n, r, o, c, h, E, k, m, S, f, w;
297
338
  switch (a.action) {
339
+ // Media
340
+ case "UPLOAD_MEDIA":
341
+ return (n = this.chaiAssets) == null ? void 0 : n.upload({
342
+ file: a.data.file,
343
+ name: a.data.name
344
+ });
345
+ case "GET_ASSETS":
346
+ return (r = this.chaiAssets) == null ? void 0 : r.getAssets(a.data);
347
+ case "DELETE_ASSET":
348
+ return (o = this.chaiAssets) == null ? void 0 : o.deleteAsset(a.data.assetId);
349
+ case "UPDATE_ASSET_METADATA":
350
+ return (c = this.chaiAssets) == null ? void 0 : c.updateAssetMetadata(a.data);
351
+ case "UPDATE_ASSET_FILE":
352
+ return (h = this.chaiAssets) == null ? void 0 : h.updateAssetFile(
353
+ a.data
354
+ );
355
+ // Users
298
356
  case "REFRESH_TOKEN":
299
- return (t = this.chaiUsers) == null ? void 0 : t.refreshToken(
357
+ return (E = this.chaiUsers) == null ? void 0 : E.refreshToken(
300
358
  a.data
301
359
  );
302
360
  case "LOGIN":
303
- return (r = this.chaiUsers) == null ? void 0 : r.login(
361
+ return (k = this.chaiUsers) == null ? void 0 : k.login(
304
362
  a.data
305
363
  );
306
364
  case "LOGOUT":
307
- return (o = this.chaiUsers) == null ? void 0 : o.logout();
365
+ return (m = this.chaiUsers) == null ? void 0 : m.logout();
308
366
  case "CHECK_USER_STATUS":
309
- return (c = this.chaiUsers) == null ? void 0 : c.isUserActive(e);
367
+ return (S = this.chaiUsers) == null ? void 0 : S.isUserActive(e);
310
368
  case "GET_ROLE_AND_PERMISSIONS":
311
- return (l = this.chaiUsers) == null ? void 0 : l.getUserRoleAndPermissions(e);
369
+ return (f = this.chaiUsers) == null ? void 0 : f.getUserRoleAndPermissions(e);
312
370
  case "GET_CHAI_USER":
313
- return (k = this.chaiUsers) == null ? void 0 : k.getUserInfo(
371
+ return (w = this.chaiUsers) == null ? void 0 : w.getUserInfo(
314
372
  e,
315
373
  a.data
316
374
  );
317
375
  }
318
376
  if (a.action === "GET_BUILDER_PAGE_DATA") {
319
- const s = await E({
377
+ const i = await P({
320
378
  lang: a.data.lang,
321
379
  draft: !0,
322
380
  inBuilder: !0
323
- }), d = h(
381
+ }), d = l(
324
382
  a.data.pageType
325
383
  );
326
384
  return d ? {
@@ -330,44 +388,44 @@ class M {
330
388
  inBuilder: !0,
331
389
  pageProps: a.data.pageProps ?? {}
332
390
  }) : {},
333
- global: s
334
- } : { global: s };
391
+ global: i
392
+ } : { global: i };
335
393
  }
336
394
  if (a.action === "GET_PAGE_TYPES")
337
395
  return Promise.all(
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
396
+ T().map(async (i) => ({
397
+ key: i.key,
398
+ helpText: i.helpText ?? "",
399
+ icon: i.icon ?? "",
400
+ dynamicSegments: i.dynamicSegments ?? "",
401
+ dynamicSlug: i.dynamicSlug ?? "",
402
+ hasSlug: i.hasSlug ?? !0,
403
+ name: typeof i.name == "function" ? await i.name() : i.name
346
404
  }))
347
405
  );
348
406
  if (a.action === "SEARCH_PAGE_TYPE_ITEMS") {
349
- const s = h(
407
+ const i = l(
350
408
  a.data.pageType
351
409
  );
352
- return s ? s.search ? await s.search(a.data.query) : this.backend.handleAction(a, e) : { error: "Page type not found" };
410
+ return i ? i.search ? await i.search(a.data.query) : this.backend.handleAction(a, e) : { error: "Page type not found" };
353
411
  }
354
- const n = await this.backend.handleAction(a, e);
355
- return this.emit(a.action, n), n;
412
+ const t = await this.backend.handleAction(a, e);
413
+ return this.emit(a.action, t), t;
356
414
  }
357
415
  emit(a, e) {
358
416
  var r, o, c;
359
417
  if (!["CREATE_PAGE", "UPDATE_PAGE", "DELETE_PAGE"].includes(a)) return;
360
- const n = p(e, "page");
361
- if (!n) return;
362
- const t = h(n.pageType);
363
- if (t)
418
+ const t = L(e, "page");
419
+ if (!t) return;
420
+ const n = l(t.pageType);
421
+ if (n)
364
422
  switch (a) {
365
423
  case "CREATE_PAGE":
366
- return (r = t.onCreate) == null ? void 0 : r.call(t, n);
424
+ return (r = n.onCreate) == null ? void 0 : r.call(n, t);
367
425
  case "UPDATE_PAGE":
368
- return (o = t.onUpdate) == null ? void 0 : o.call(t, n);
426
+ return (o = n.onUpdate) == null ? void 0 : o.call(n, t);
369
427
  case "DELETE_PAGE":
370
- return (c = t.onDelete) == null ? void 0 : c.call(t, n);
428
+ return (c = n.onDelete) == null ? void 0 : c.call(n, t);
371
429
  }
372
430
  }
373
431
  // APIS
@@ -376,40 +434,40 @@ class M {
376
434
  throw new Error(
377
435
  "Please set a fallback language using setFallbackLang(lang: string)"
378
436
  );
379
- const e = P(a || [""]);
380
- Object.keys(U).includes(e) ? this.setCurrentLang(e) : this.setCurrentLang(this.getFallbackLang());
437
+ const e = y(a || [""]);
438
+ Object.keys(M).includes(e) ? this.setCurrentLang(e) : this.setCurrentLang(this.getFallbackLang());
381
439
  }
382
440
  async resolveLink(a, e) {
383
- const n = h(a);
384
- if (!n)
441
+ const t = l(a);
442
+ if (!t)
385
443
  return "/not-found";
386
- const t = this.isDraftMode(), r = this.getCurrentLang();
387
- return n.resolveLink ? await n.resolveLink(e, t, r) : await this.backend.handleAction({
444
+ const n = this.isDraftMode(), r = this.getCurrentLang() === this.getFallbackLang() ? "" : this.getCurrentLang();
445
+ return t.resolveLink ? await t.resolveLink(e, n, r) : await this.backend.handleAction({
388
446
  action: "GET_LINK",
389
447
  data: {
390
448
  pageType: a,
391
449
  id: e,
392
- draft: t,
450
+ draft: n,
393
451
  lang: r
394
452
  }
395
453
  });
396
454
  }
397
455
  async getPageBySlug(a) {
398
- const e = this.isDraftMode(), n = {};
399
- return w().forEach((t) => {
400
- m(t, "dynamicSegments") && t.dynamicSegments && (n[t.key] = t.dynamicSegments);
456
+ const e = this.isDraftMode(), t = {};
457
+ return T().forEach((n) => {
458
+ A(n, "dynamicSegments") && n.dynamicSegments && (t[n.key] = n.dynamicSegments);
401
459
  }), await this.backend.handleAction({
402
460
  action: "GET_PAGE_META",
403
- data: { slug: a, draft: e, dynamicSegments: n }
461
+ data: { slug: a, draft: e, dynamicSegments: t }
404
462
  });
405
463
  }
406
464
  async getFullPage(a) {
407
- const e = this.isDraftMode(), n = this.getCurrentLang(), t = this.getFallbackLang();
465
+ const e = this.isDraftMode(), t = this.getCurrentLang(), n = this.getFallbackLang();
408
466
  return await this.backend.handleAction({
409
467
  action: "GET_PAGE",
410
468
  data: {
411
469
  id: a,
412
- lang: t === n ? void 0 : n,
470
+ lang: n === t ? void 0 : t,
413
471
  draft: e,
414
472
  mergePartials: !0
415
473
  }
@@ -423,12 +481,12 @@ class M {
423
481
  });
424
482
  }
425
483
  async getPageData(a, e = {}) {
426
- var l;
427
- const n = this.isDraftMode(), t = this.getCurrentLang(), r = h(a), [o, c] = await Promise.all([
484
+ var h;
485
+ const t = this.isDraftMode(), n = this.getCurrentLang(), r = l(a), [o, c] = await Promise.all([
428
486
  this.getGlobalData(),
429
- ((l = r == null ? void 0 : r.dataProvider) == null ? void 0 : l.call(r, {
430
- lang: t,
431
- draft: n,
487
+ ((h = r == null ? void 0 : r.dataProvider) == null ? void 0 : h.call(r, {
488
+ lang: n,
489
+ draft: t,
432
490
  inBuilder: !1,
433
491
  pageProps: e
434
492
  })) || Promise.resolve({})
@@ -440,7 +498,7 @@ class M {
440
498
  }
441
499
  async getGlobalData() {
442
500
  const a = this.getCurrentLang();
443
- return await E({
501
+ return await P({
444
502
  lang: a,
445
503
  draft: this.isDraftMode(),
446
504
  inBuilder: !1
@@ -450,36 +508,36 @@ class M {
450
508
  return await this.backend.handleAction(a);
451
509
  }
452
510
  }
453
- class D {
454
- constructor(a = "", e = v) {
511
+ class N {
512
+ constructor(a = "", e = I) {
455
513
  this.apiKey = a, this.apiUrl = e;
456
514
  }
457
515
  async handleUsersAction(a, e) {
458
- const n = await fetch(`${this.apiUrl}/v1/api/users`, {
516
+ const t = await fetch(`${this.apiUrl}/v1/api/users`, {
459
517
  method: "POST",
460
518
  body: JSON.stringify(a),
461
519
  headers: {
462
520
  "x-chai-api-key": this.apiKey,
463
521
  "x-chai-auth-token": e
464
522
  }
465
- }), t = await n.json();
466
- return m(t, "error") ? { ...t, status: n.status } : t;
523
+ }), n = await t.json();
524
+ return A(n, "error") ? { ...n, status: t.status } : n;
467
525
  }
468
526
  async handleAction(a, e) {
469
- const n = await fetch(`${this.apiUrl}/v1/api/chai`, {
527
+ const t = await fetch(`${this.apiUrl}/v1/api/chai`, {
470
528
  method: "POST",
471
529
  body: JSON.stringify(a),
472
530
  headers: {
473
531
  "x-chai-api-key": this.apiKey,
474
532
  "x-chai-auth-token": e
475
533
  }
476
- }), t = await n.json();
477
- return m(t, "error") ? { ...t, status: n.status } : t;
534
+ }), n = await t.json();
535
+ return A(n, "error") ? { ...n, status: t.status } : n;
478
536
  }
479
- async handleUpload(a, e) {
480
- return await (await fetch(`${this.apiUrl}/v1/api/chai`, {
537
+ async handleAssetsAction(a, e) {
538
+ return await (await fetch(`${this.apiUrl}/v1/api/assets`, {
481
539
  method: "POST",
482
- body: a,
540
+ body: JSON.stringify(a),
483
541
  headers: {
484
542
  "x-chai-api-key": this.apiKey,
485
543
  "x-chai-upload": "true",
@@ -488,17 +546,17 @@ class D {
488
546
  })).json();
489
547
  }
490
548
  }
491
- const v = "https://api.chaibuilder.com";
549
+ const I = "https://api.chaibuilder.com";
492
550
  export {
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
551
+ I as API_URL,
552
+ K as ChaiBuilderPages,
553
+ N as ChaiBuilderPagesBackend,
554
+ D as ChaiBuilderPagesUserManagement,
555
+ M as LANGUAGES,
556
+ P as getChaiGlobalData,
557
+ l as getChaiPageType,
558
+ T as getChaiPageTypes,
559
+ B as registerChaiGlobalDataProvider,
560
+ U as registerChaiPageType,
561
+ v as registerChaiPartialType
504
562
  };
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.4.2",
6
+ "version": "0.4.5",
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.2.4",
62
+ "@chaibuilder/sdk": "2.2.5",
63
63
  "@chaibuilder/runtime": "2.1.2",
64
64
  "@types/react": "*",
65
65
  "@types/react-dom": "*",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@chaibuilder/runtime": "2.1.2",
82
- "@chaibuilder/sdk": "2.2.4",
82
+ "@chaibuilder/sdk": "2.2.5",
83
83
  "@mhsdesign/jit-browser-tailwindcss": "^0.4.2",
84
84
  "@tailwindcss/aspect-ratio": "^0.4.2",
85
85
  "@tailwindcss/forms": "^0.5.10",
@@ -97,7 +97,7 @@
97
97
  "lucide-react": "^0.474.0",
98
98
  "path": "^0.12.7",
99
99
  "react-dropzone": "^14.3.8",
100
- "react-image-crop": "^11.0.7",
100
+ "react-filerobot-image-editor": "^4.9.1",
101
101
  "sonner": "^2.0.1",
102
102
  "tailwind-merge": "^2.6.0",
103
103
  "tailwindcss-animate": "^1.0.7",
@@ -135,8 +135,8 @@
135
135
  "nodemon": "^3.1.9",
136
136
  "postcss": "^8.5.1",
137
137
  "prettier": "^3.4.2",
138
- "react": "^18.3.1",
139
- "react-dom": "^18.3.1",
138
+ "react": "^19.1.0",
139
+ "react-dom": "^19.1.0",
140
140
  "tailwindcss": "^3.4.13",
141
141
  "ts-node": "^10.9.2",
142
142
  "typescript": "^5.7.3",