@chaibuilder/pages 0.4.3 → 0.4.6

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