@chaibuilder/sdk 0.1.3 → 0.1.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.
Files changed (81) hide show
  1. package/dist/{AddBlocks-c195f577.js → AddBlocks-5d928d58.js} +20 -19
  2. package/dist/AddBlocks-df0ea47a.cjs +3 -0
  3. package/dist/BrandingOptions-b76762a4.cjs +1 -0
  4. package/dist/{BrandingOptions-766c19c6.js → BrandingOptions-bf7e6a38.js} +11 -9
  5. package/dist/{CanvasArea-25800a3e.js → CanvasArea-688987d1.js} +226 -224
  6. package/dist/{CanvasArea-e855c4a2.cjs → CanvasArea-9287e1bd.cjs} +2 -2
  7. package/dist/{Class-e34b2337.js → Class-1fb4c0c4.js} +110 -169
  8. package/dist/Class-6c695ccb.cjs +1 -0
  9. package/dist/Layers-11b26a20.cjs +1 -0
  10. package/dist/{Layers-f7e792f6.js → Layers-c053dfb8.js} +12 -10
  11. package/dist/MODIFIERS-70fef873.cjs +1 -0
  12. package/dist/MODIFIERS-c2e02614.js +67 -0
  13. package/dist/{MarkAsGlobalBlock-6bac1842.js → MarkAsGlobalBlock-111d739d.js} +10 -8
  14. package/dist/MarkAsGlobalBlock-4c85ba27.cjs +1 -0
  15. package/dist/{PagesPanel-0827c264.js → PagesPanel-48d0f29b.js} +12 -10
  16. package/dist/PagesPanel-97dbe8c3.cjs +1 -0
  17. package/dist/ProjectPanel-24543eac.cjs +1 -0
  18. package/dist/{ProjectPanel-e577029a.js → ProjectPanel-e19b9778.js} +10 -11
  19. package/dist/Settings-0358ce2f.cjs +1 -0
  20. package/dist/{Settings-b214f859.js → Settings-f4118350.js} +7 -5
  21. package/dist/{SidePanels-03fa10e8.js → SidePanels-73e79a7d.js} +8 -6
  22. package/dist/SidePanels-e48c2ba6.cjs +1 -0
  23. package/dist/Topbar-26d18e9d.cjs +1 -0
  24. package/dist/{Topbar-9bc8c9cf.js → Topbar-5574394f.js} +7 -5
  25. package/dist/add-page-modal-61d5bad7.js +93 -0
  26. package/dist/add-page-modal-6a60b790.cjs +1 -0
  27. package/dist/core.cjs +1 -1
  28. package/dist/core.d.ts +13 -11
  29. package/dist/core.js +63 -61
  30. package/dist/{delete-page-modal-def9012d.js → delete-page-modal-62641e4c.js} +10 -9
  31. package/dist/delete-page-modal-ecdd890a.cjs +1 -0
  32. package/dist/html-to-json-01cc5fe0.cjs +1 -0
  33. package/dist/{html-to-json-9304dbda.js → html-to-json-d20aafdd.js} +2 -2
  34. package/dist/index-89fce4e7.cjs +2 -0
  35. package/dist/index-de0f72ce.js +4911 -0
  36. package/dist/lib.cjs +1 -1
  37. package/dist/lib.js +4 -4
  38. package/dist/{page-viewer-41cbb548.js → page-viewer-14a69dba.js} +21 -18
  39. package/dist/page-viewer-e8469cfa.cjs +1 -0
  40. package/dist/{project-general-setting-2c8bed74.cjs → project-general-setting-decde8d1.cjs} +1 -1
  41. package/dist/{project-general-setting-0262fe62.js → project-general-setting-f7cfce70.js} +7 -5
  42. package/dist/render.cjs +2 -2
  43. package/dist/render.d.ts +9 -3
  44. package/dist/render.js +154 -134
  45. package/dist/server.cjs +1 -0
  46. package/dist/server.d.ts +142 -0
  47. package/dist/server.js +126 -0
  48. package/dist/{single-page-detail-924d57fc.js → single-page-detail-16682af2.js} +45 -43
  49. package/dist/single-page-detail-60edc711.cjs +1 -0
  50. package/dist/style.css +1 -1
  51. package/dist/useChangePage-5a62d7fc.cjs +1 -0
  52. package/dist/useChangePage-6b957e49.js +12 -0
  53. package/dist/usePageActions-32ea32a5.cjs +1 -0
  54. package/dist/usePageActions-37599b0c.js +38 -0
  55. package/package.json +7 -1
  56. package/dist/AddBlocks-0916e841.cjs +0 -3
  57. package/dist/BrandingOptions-742992b6.cjs +0 -1
  58. package/dist/CONTROLS-031e1de3.cjs +0 -1
  59. package/dist/CONTROLS-442caee5.js +0 -6
  60. package/dist/Class-7d6aadbc.cjs +0 -1
  61. package/dist/Layers-a2169d0b.cjs +0 -1
  62. package/dist/MarkAsGlobalBlock-6187e6fd.cjs +0 -1
  63. package/dist/PagesPanel-5698953d.cjs +0 -1
  64. package/dist/ProjectPanel-a3cb7396.cjs +0 -1
  65. package/dist/Settings-bee21026.cjs +0 -1
  66. package/dist/SidePanels-934159a4.cjs +0 -1
  67. package/dist/Topbar-c083cc2a.cjs +0 -1
  68. package/dist/add-page-modal-63858244.js +0 -92
  69. package/dist/add-page-modal-cb367c9d.cjs +0 -1
  70. package/dist/delete-page-modal-1e3914e3.cjs +0 -1
  71. package/dist/html-to-json-9c9961da.cjs +0 -1
  72. package/dist/index-207f2cbf.cjs +0 -2
  73. package/dist/index-390f7bef.js +0 -4749
  74. package/dist/index-824a7bd0.js +0 -188
  75. package/dist/index-ebd86d7f.cjs +0 -2
  76. package/dist/page-viewer-83ce2c70.cjs +0 -1
  77. package/dist/single-page-detail-cfeae896.cjs +0 -1
  78. package/dist/usePageActions-3bed2330.cjs +0 -1
  79. package/dist/usePageActions-f86f6f65.js +0 -36
  80. package/dist/useProjectActions-1de05f63.js +0 -17
  81. package/dist/useProjectActions-5092ed79.cjs +0 -1
package/dist/render.js CHANGED
@@ -1,108 +1,35 @@
1
- import { j as s } from "./jsx-runtime-944c88e2.js";
2
- import u from "react";
3
- import { memoize as S, filter as f, isEmpty as w, omit as E, isString as z, get as i, replace as C, set as F } from "lodash";
4
- import { twMerge as v } from "tailwind-merge";
5
- import { S as D, a as k } from "./CONTROLS-442caee5.js";
6
- import { getBlockComponent as A } from "@chaibuilder/blocks";
7
- import { Provider as L } from "react-wrap-balancer";
8
- import { createTailwindcss as $ } from "@mhsdesign/jit-browser-tailwindcss";
9
- import { tailwindcssPaletteGenerator as j } from "@bobthered/tailwindcss-palette-generator";
10
- import { g as U } from "./_commonjsHelpers-d4512b9c.js";
11
- import O from "@tailwindcss/forms";
12
- import R from "@tailwindcss/typography";
13
- import B from "@tailwindcss/aspect-ratio";
14
- import H from "@tailwindcss/line-clamp";
15
- const M = (e) => {
16
- const t = {};
17
- return Object.keys(e).forEach((r) => {
18
- z(e[r]) && e[r].startsWith(k) && (t[r] = e[r].replace(k, "").split(","));
19
- }), t;
20
- }, P = S((e) => {
21
- const t = e.replace(D, "").split(",");
22
- return v(t[0], t[1]);
23
- });
24
- function W(e, t) {
25
- return i(e, `${t}_attrs`, {});
26
- }
27
- function I(e) {
28
- const t = {};
29
- return Object.keys(e).forEach((r) => {
30
- if (z(e[r]) && e[r].startsWith(D)) {
31
- const n = P(e[r]);
32
- t[r] = {
33
- className: n,
34
- ...W(e, r)
35
- };
36
- }
37
- }), t;
38
- }
39
- function y({ blocks: e, parent: t }) {
40
- const r = e, n = (o) => I(o), a = t ? f(e, { _parent: t }) : f(e, (o) => w(o._parent));
41
- return /* @__PURE__ */ s.jsx(s.Fragment, { children: u.Children.toArray(
42
- a.map((o, d) => {
43
- const p = M(o), m = {};
44
- w(p) || Object.keys(p).forEach((l) => {
45
- m[l] = u.Children.toArray(
46
- p[l].map((x) => /* @__PURE__ */ s.jsx(y, { blocks: r, parent: x }))
47
- );
48
- });
49
- const c = f(r, { _parent: o._id });
50
- m.children = c.length > 0 ? /* @__PURE__ */ s.jsx(y, { parent: o._id, blocks: r }) : null;
51
- const g = A(o._type);
52
- if (g !== null) {
53
- let l = o;
54
- const x = g.component;
55
- return l = { ...g.defaults, ...o }, u.createElement(
56
- x,
57
- E(
58
- {
59
- blockProps: {},
60
- ...l,
61
- index: d,
62
- ...n(l),
63
- ...m,
64
- inBuilder: !1
65
- },
66
- ["_parent"]
67
- )
68
- );
69
- }
70
- return /* @__PURE__ */ s.jsxs("noscript", { children: [
71
- o._type,
72
- " not found"
73
- ] });
74
- })
75
- ) });
76
- }
77
- const N = (e) => {
78
- const t = i(e, "_bodyTextLightColor", "#64748b"), r = i(e, "_bodyTextDarkColor", "#94a3b8"), n = i(e, "_bodyBgLightColor", "#FFFFFF"), a = i(e, "_bodyBgDarkColor", "#0f172a");
79
- return `font-body antialiased text-[${t}] bg-[${n}] dark:text-[${r}] dark:bg-[${a}]`;
80
- }, me = ({ snapshot: e, before: t = null, after: r = null, classPrefix: n = "c-" }) => {
81
- const a = i(e.projectData, "brandingOptions", {});
82
- return /* @__PURE__ */ s.jsxs(s.Fragment, { children: [
83
- t,
84
- /* @__PURE__ */ s.jsx("div", { className: n.replace("-", "") + " " + N(a) + " min-h-screen", children: /* @__PURE__ */ s.jsx(L, { children: /* @__PURE__ */ s.jsx(y, { blocks: e.pageData.blocks || [] }) }) }),
85
- r
86
- ] });
87
- };
88
- var T = {}, _ = {};
1
+ import { j as m } from "./jsx-runtime-944c88e2.js";
2
+ import f from "react";
3
+ import { get as i, includes as b, last as _, replace as v, set as z, startsWith as L, memoize as $, filter as h, isEmpty as T, omit as j, isString as k } from "lodash";
4
+ import { twMerge as U } from "tailwind-merge";
5
+ import { S as g, a as D, B } from "./MODIFIERS-c2e02614.js";
6
+ import { getBlockComponent as O } from "@chaibuilder/blocks";
7
+ import { createTailwindcss as R } from "@mhsdesign/jit-browser-tailwindcss";
8
+ import { tailwindcssPaletteGenerator as H } from "@bobthered/tailwindcss-palette-generator";
9
+ import { g as M } from "./_commonjsHelpers-d4512b9c.js";
10
+ import P from "@tailwindcss/forms";
11
+ import I from "@tailwindcss/typography";
12
+ import W from "@tailwindcss/aspect-ratio";
13
+ import N from "@tailwindcss/line-clamp";
14
+ import { Provider as q } from "react-wrap-balancer";
15
+ var S = {}, E = {};
89
16
  (function(e) {
90
17
  Object.defineProperty(e, "__esModule", {
91
18
  value: !0
92
19
  }), Object.defineProperty(e, "cloneDeep", {
93
20
  enumerable: !0,
94
21
  get: function() {
95
- return t;
22
+ return r;
96
23
  }
97
24
  });
98
- function t(r) {
99
- return Array.isArray(r) ? r.map((n) => t(n)) : typeof r == "object" && r !== null ? Object.fromEntries(Object.entries(r).map(([n, a]) => [
25
+ function r(t) {
26
+ return Array.isArray(t) ? t.map((n) => r(n)) : typeof t == "object" && t !== null ? Object.fromEntries(Object.entries(t).map(([n, o]) => [
100
27
  n,
101
- t(a)
102
- ])) : r;
28
+ r(o)
29
+ ])) : t;
103
30
  }
104
- })(_);
105
- var q = {
31
+ })(E);
32
+ var G = {
106
33
  content: [],
107
34
  presets: [],
108
35
  darkMode: "media",
@@ -730,7 +657,7 @@ var q = {
730
657
  max: "max-content",
731
658
  fit: "fit-content"
732
659
  }),
733
- maxWidth: ({ theme: e, breakpoints: t }) => ({
660
+ maxWidth: ({ theme: e, breakpoints: r }) => ({
734
661
  none: "none",
735
662
  0: "0rem",
736
663
  xs: "20rem",
@@ -749,7 +676,7 @@ var q = {
749
676
  max: "max-content",
750
677
  fit: "fit-content",
751
678
  prose: "65ch",
752
- ...t(e("screens"))
679
+ ...r(e("screens"))
753
680
  }),
754
681
  minHeight: {
755
682
  0: "0px",
@@ -1099,73 +1026,166 @@ var q = {
1099
1026
  }), Object.defineProperty(e, "default", {
1100
1027
  enumerable: !0,
1101
1028
  get: function() {
1102
- return a;
1029
+ return o;
1103
1030
  }
1104
1031
  });
1105
- const t = _, r = /* @__PURE__ */ n(q);
1106
- function n(o) {
1107
- return o && o.__esModule ? o : {
1108
- default: o
1032
+ const r = E, t = /* @__PURE__ */ n(G);
1033
+ function n(s) {
1034
+ return s && s.__esModule ? s : {
1035
+ default: s
1109
1036
  };
1110
1037
  }
1111
- const a = (0, t.cloneDeep)(r.default.theme);
1112
- })(T);
1113
- let b = T;
1114
- var G = (b.__esModule ? b : { default: b }).default;
1115
- const h = /* @__PURE__ */ U(G), Y = (e, t = "c-") => {
1116
- const r = i(e, "_bodyTextLightColor", "#64748b"), n = i(e, "_bodyTextDarkColor", "#94a3b8"), a = i(e, "_bodyBgLightColor", "#FFFFFF"), o = i(e, "_bodyBgDarkColor", "#0f172a");
1117
- return `${t}font-body ${t}antialiased ${t}text-[${r}] ${t}bg-[${a}] dark:${t}text-[${n}] dark:${t}bg-[${o}]`;
1118
- }, pe = (e, t, r, n = "c-") => {
1119
- const a = Y(r, n);
1120
- return J(
1038
+ const o = (0, r.cloneDeep)(t.default.theme);
1039
+ })(S);
1040
+ let y = S;
1041
+ var Y = (y.__esModule ? y : { default: y }).default;
1042
+ const w = /* @__PURE__ */ M(Y), K = (e, r = "c-") => {
1043
+ const t = i(e, "bodyTextLightColor", "#64748b"), n = i(e, "bodyTextDarkColor", "#94a3b8"), o = i(e, "bodyBgLightColor", "#FFFFFF"), s = i(e, "bodyBgDarkColor", "#0f172a");
1044
+ return `${r}font-body ${r}antialiased ${r}text-[${t}] ${r}bg-[${o}] dark:${r}text-[${n}] dark:${r}bg-[${s}]`;
1045
+ }, A = (e, r = "c-") => {
1046
+ const n = e.replace(g, "").split(",").map((o) => o.split(" ").map((l) => {
1047
+ if (l === "")
1048
+ return "";
1049
+ if (b(l, "hs-") || b(l, "[--") || b(l, "paddle"))
1050
+ return l;
1051
+ if (l.includes(":")) {
1052
+ const p = l.split(":");
1053
+ return p[p.length - 1] = r + _(p), p.join(":");
1054
+ }
1055
+ return `${r}${l}`;
1056
+ }).join(" "));
1057
+ return `${g}${n.join(" , ")}`;
1058
+ }, J = (e, r) => e.map((t) => (Object.keys(t).forEach((n) => {
1059
+ L(t[n], g) && (t[n] = A(t[n], r));
1060
+ }), t)), fe = (e, r, t = "c-") => {
1061
+ const n = K(r, t);
1062
+ return Q(
1121
1063
  r,
1122
- [C(JSON.stringify(e), /#styles:/g, ""), C(JSON.stringify(t), /#styles:/g, "")],
1123
- a.split(" ").concat(`${n}inline-block`, `${n}w-full`, `${n}h-full`)
1064
+ [v(JSON.stringify(J(e, t)), /#styles:/g, "")],
1065
+ n.split(" ").concat(`${t}inline-block`, `${t}w-full`, `${t}h-full`)
1124
1066
  );
1125
1067
  };
1126
- async function J(e, t, r = [], n = "c-") {
1127
- const a = i(e, "_primaryColor", "#000"), o = i(e, "_secondaryColor", "#ccc"), d = i(e, "_headingFont", "Inter"), p = i(e, "_bodyFont", "Inter"), m = i(e, "_roundedCorners", "0"), c = j({
1128
- colors: [a, o],
1068
+ async function Q(e, r, t = [], n = "c-") {
1069
+ const o = i(e, "primaryColor", "#000"), s = i(e, "secondaryColor", "#ccc"), a = i(e, "headingFont", "Inter"), l = i(e, "bodyFont", "Inter"), p = i(e, "roundedCorners", "0"), c = H({
1070
+ colors: [o, s],
1129
1071
  names: ["primary", "secondary"]
1130
1072
  });
1131
- return F(c, "primary.DEFAULT", a), F(c, "secondary.DEFAULT", o), `${await $({
1073
+ return z(c, "primary.DEFAULT", o), z(c, "secondary.DEFAULT", s), `${await R({
1132
1074
  tailwindConfig: {
1133
1075
  prefix: n,
1134
1076
  darkMode: "class",
1135
- safelist: r,
1077
+ safelist: t,
1136
1078
  theme: {
1137
1079
  fontFamily: {
1138
- heading: [d, ...h.fontFamily.sans],
1139
- body: [p, ...h.fontFamily.sans]
1080
+ heading: [a, ...w.fontFamily.sans],
1081
+ body: [l, ...w.fontFamily.sans]
1140
1082
  },
1141
1083
  extend: {
1142
1084
  borderRadius: {
1143
- global: `${m || "0"}px`
1085
+ global: `${p || "0"}px`
1144
1086
  },
1145
1087
  colors: c
1146
1088
  }
1147
1089
  },
1148
- plugins: [O, R, B, H],
1090
+ plugins: [P, I, W, N],
1149
1091
  corePlugins: { preflight: !1 }
1150
1092
  }
1151
1093
  }).generateStylesFromContent(
1152
1094
  ` @tailwind components;
1153
1095
  @tailwind utilities;`,
1154
- t
1155
- )} .${n}bg-clip-text{background-clip: text;-webkit-background-clip: text;} h1,h2,h3,h4,h5,h6{font-family: "${d}",${h.fontFamily.sans.join(
1096
+ r
1097
+ )} .${n}bg-clip-text{background-clip: text;-webkit-background-clip: text;} h1,h2,h3,h4,h5,h6{font-family: "${a}",${w.fontFamily.sans.join(
1156
1098
  ", "
1157
1099
  )};}`;
1158
1100
  }
1159
- function ce(e = 6, t = "abcdefghijklmnopqrstuvwxyzABCD") {
1160
- let r = "";
1101
+ function be(e = 6, r = "abcdefghijklmnopqrstuvwxyzABCD") {
1102
+ let t = "";
1161
1103
  for (let n = e; n > 0; --n)
1162
- r += t[Math.floor(Math.random() * t.length)];
1163
- return r;
1104
+ t += r[Math.floor(Math.random() * r.length)];
1105
+ return t;
1106
+ }
1107
+ const V = (e) => {
1108
+ const r = {};
1109
+ return Object.keys(e).forEach((t) => {
1110
+ k(e[t]) && e[t].startsWith(D) && (r[t] = e[t].replace(D, "").split(","));
1111
+ }), r;
1112
+ }, X = $((e, r) => {
1113
+ const t = e.replace(g, "").split(","), n = U(t[0], t[1]);
1114
+ return A(n, r).replace(g, "").trim();
1115
+ });
1116
+ function Z(e, r) {
1117
+ return i(e, `${r}_attrs`, {});
1164
1118
  }
1119
+ function ee(e, r) {
1120
+ const t = {};
1121
+ return Object.keys(e).forEach((n) => {
1122
+ if (k(e[n]) && e[n].startsWith(g)) {
1123
+ const o = X(e[n], r);
1124
+ t[n] = {
1125
+ className: o,
1126
+ ...Z(e, n)
1127
+ };
1128
+ }
1129
+ }), t;
1130
+ }
1131
+ function C({
1132
+ blocks: e,
1133
+ parent: r,
1134
+ classPrefix: t = "c-"
1135
+ }) {
1136
+ const n = e, o = (a) => ee(a, t), s = r ? h(e, { _parent: r }) : h(e, (a) => T(a._parent));
1137
+ return /* @__PURE__ */ m.jsx(m.Fragment, { children: f.Children.toArray(
1138
+ s.map((a, l) => {
1139
+ const p = V(a), c = {};
1140
+ T(p) || Object.keys(p).forEach((d) => {
1141
+ c[d] = f.Children.toArray(
1142
+ p[d].map((x) => /* @__PURE__ */ m.jsx(C, { classPrefix: t, blocks: n, parent: x }))
1143
+ );
1144
+ });
1145
+ const F = h(n, { _parent: a._id });
1146
+ c.children = F.length > 0 ? /* @__PURE__ */ m.jsx(C, { classPrefix: t, parent: a._id, blocks: n }) : null;
1147
+ const u = O(a._type);
1148
+ if (u !== null) {
1149
+ let d = a;
1150
+ const x = u.component;
1151
+ return d = { ...u.defaults, ...a }, f.createElement(
1152
+ x,
1153
+ j(
1154
+ {
1155
+ blockProps: {},
1156
+ ...d,
1157
+ index: l,
1158
+ ...o(d),
1159
+ ...c,
1160
+ inBuilder: !1
1161
+ },
1162
+ ["_parent"]
1163
+ )
1164
+ );
1165
+ }
1166
+ return /* @__PURE__ */ m.jsxs("noscript", { children: [
1167
+ a._type,
1168
+ " not found"
1169
+ ] });
1170
+ })
1171
+ ) });
1172
+ }
1173
+ const te = (e) => {
1174
+ const r = i(e, "_bodyTextLightColor", "#64748b"), t = i(e, "_bodyTextDarkColor", "#94a3b8"), n = i(e, "_bodyBgLightColor", "#FFFFFF"), o = i(e, "_bodyBgDarkColor", "#0f172a");
1175
+ return `font-body antialiased text-[${r}] bg-[${n}] dark:text-[${t}] dark:bg-[${o}]`;
1176
+ }, he = ({ snapshot: e, before: r = null, after: t = null, classPrefix: n = "c-" }) => {
1177
+ const o = i(e.projectData, "brandingOptions", B);
1178
+ return /* @__PURE__ */ m.jsxs(m.Fragment, { children: [
1179
+ r,
1180
+ /* @__PURE__ */ m.jsx("div", { className: n.replace("-", "") + " " + te(o) + " min-h-screen", children: /* @__PURE__ */ m.jsx(q, { children: /* @__PURE__ */ m.jsx(C, { blocks: e.pageData.blocks || [], classPrefix: n }) }) }),
1181
+ t
1182
+ ] });
1183
+ };
1165
1184
  export {
1166
- y as RenderChaiBlocks,
1167
- me as RenderChaiPage,
1168
- ce as generateUUID,
1169
- pe as getBlocksTailwindCSS,
1170
- Y as getBrandingClasses
1185
+ C as RenderChaiBlocks,
1186
+ he as RenderChaiPage,
1187
+ A as addPrefixToClasses,
1188
+ be as generateUUID,
1189
+ fe as getBlocksTailwindCSS,
1190
+ K as getBrandingClasses
1171
1191
  };
@@ -0,0 +1 @@
1
+ "use strict";var d=Object.defineProperty;var u=(o,t,e)=>t in o?d(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var c=(o,t,e)=>(u(o,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("lodash"),i="https://api.chaibuilder.com";class g{constructor(t,e){c(this,"authToken");c(this,"projectKey");if(!t)throw"Please provide valid auth token.";if(!e)throw"Please provide valid project key.";this.authToken=t,this.projectKey=e}async getPage(t){if(!t)return Promise.reject({data:null,error:{message:"Invalid page uuid"},result:"error"});const e=this.getHeaders(),s=this.getURL("page",{uuid:t}),n={method:"GET",headers:e};return this.fetchAPI(s,n)}async getPages(){const t=this.getHeaders(),e=this.getURL("pages"),r={method:"GET",headers:t};return this.fetchAPI(e,r)}async addPage(t){h.set(t,"project",this.projectKey);const e=JSON.stringify(t),s=this.getHeaders(),r=this.getURL("page"),a={method:"POST",headers:s,body:e};return this.fetchAPI(r,a)}async deletePage(t){if(!t)return Promise.reject({data:null,error:{message:"Invalid page uuid"},result:"error"});const e=this.getHeaders(),s=this.getURL("page",{uuid:t}),n={method:"DELETE",headers:e};return this.fetchAPI(s,n)}async updatePage(t){const e=JSON.stringify(t),s=this.getHeaders(),r=this.getURL("page"),a={method:"PUT",headers:s,body:e};return this.fetchAPI(r,a)}async getProject(){const t=this.getHeaders(),e=this.getURL("project"),r={method:"GET",headers:t};return this.fetchAPI(e,r)}async updateProject(t){t.uuid=this.projectKey,h.set(t,"uuid",this.projectKey);const e=JSON.stringify(t),s=this.getHeaders(),r=this.getURL("project"),a={method:"PUT",headers:s,body:e};return this.fetchAPI(r,a)}getURL(t,e){const s=new URLSearchParams(e).toString();return h.isEmpty(e)?`${i}/v1/${t}`:`${i}/v1/${t}?${s}`}getHeaders(){const t=new Headers;return t.append("x-chai-app-key",this.projectKey),t.append("x-chai-auth-token",this.authToken),t.append("Content-Type","application/json"),t}async fetchAPI(t,e){try{const s=await fetch(t,e).then(r=>r.json());if((s==null?void 0:s.result)==="success")return{data:s==null?void 0:s.data,error:null,result:"success"};throw s==null?void 0:s.error}catch(s){return{data:null,error:s,result:"error"}}}}exports.ChaibuilderBackend=g;
@@ -0,0 +1,142 @@
1
+ import type { ChaiBlock } from '@chaibuilder/sdk';
2
+
3
+ export declare class ChaibuilderBackend implements ChaibuilderBackendInterface {
4
+ private authToken;
5
+ private readonly projectKey;
6
+ constructor(authToken: string, projectKey: string);
7
+ /**
8
+ *
9
+ * @param uuid
10
+ * @returns Detail Single Page Information
11
+ */
12
+ getPage(uuid: string): Promise<{
13
+ data: ChaiPage & {
14
+ subPages: ChaiSubPage[];
15
+ };
16
+ error: null;
17
+ result: string;
18
+ }>;
19
+ /**
20
+ *
21
+ * @returns List of all pages
22
+ */
23
+ getPages(): Promise<{
24
+ data: ChaiPage & {
25
+ subPages: ChaiSubPage[];
26
+ }[];
27
+ error: null;
28
+ result: string;
29
+ }>;
30
+ /**
31
+ *
32
+ * @param page
33
+ * @returns Detail of new page
34
+ */
35
+ addPage(page: Pick<ChaiPage, "name" | "slug">): Promise<{
36
+ data: ChaiPage;
37
+ error: null;
38
+ result: string;
39
+ }>;
40
+ /**
41
+ *
42
+ * @param uuid
43
+ * @returns Success | Error Message
44
+ */
45
+ deletePage(uuid: string): Promise<{
46
+ data: null;
47
+ error: null;
48
+ result: string;
49
+ }>;
50
+ /**
51
+ *
52
+ * @param page
53
+ * @returns Update page information or Error response
54
+ */
55
+ updatePage(page: ChaiPage): Promise<{
56
+ data: ChaiPage;
57
+ error: null;
58
+ result: string;
59
+ }>;
60
+ /**
61
+ *
62
+ * @returns Project detail
63
+ */
64
+ getProject(): Promise<{
65
+ data: ChaiProject;
66
+ error: null;
67
+ result: string;
68
+ }>;
69
+ /**
70
+ *
71
+ * @param project
72
+ * @returns Updated project detail
73
+ */
74
+ updateProject(project: Partial<ChaiProject>): Promise<{
75
+ data: ChaiProject;
76
+ error: null;
77
+ result: string;
78
+ }>;
79
+ /**
80
+ *
81
+ * @param endpoint
82
+ * @param queryParam
83
+ * @returns api endpoint with query param
84
+ */
85
+ private getURL;
86
+ /**
87
+ *
88
+ * @returns headers for api
89
+ */
90
+ private getHeaders;
91
+ /**
92
+ *
93
+ * @returns Fetch API
94
+ */
95
+ private fetchAPI;
96
+ }
97
+
98
+ export declare interface ChaibuilderBackendInterface {
99
+ getPage(uuid: string): TChaiResponse<ChaiPage & {
100
+ subPages: ChaiSubPage[];
101
+ }>;
102
+ getPages(): TChaiResponse<ChaiPage>;
103
+ addPage(page: Pick<ChaiPage, "name" | "slug">): TChaiResponse<ChaiPage>;
104
+ deletePage(uuid: string): TChaiResponse<null>;
105
+ updatePage(page: ChaiPage): TChaiResponse<ChaiPage>;
106
+ getProject(): TChaiResponse<ChaiProject>;
107
+ updateProject(project: Partial<ChaiProject>): TChaiResponse<ChaiProject>;
108
+ }
109
+
110
+ declare type ChaiPage = {
111
+ uuid: string;
112
+ name: string;
113
+ slug: string;
114
+ blocks: ChaiBlock[];
115
+ seoData: object;
116
+ type: "STATIC" | "DYNAMIC" | "SUBPAGE";
117
+ project: string;
118
+ };
119
+
120
+ declare type ChaiProject = {
121
+ uuid: string;
122
+ brandingOptions: Record<string, string | number>;
123
+ favicon: string;
124
+ homepage: string;
125
+ name: string;
126
+ description?: string;
127
+ seoData: object;
128
+ primaryLanguage?: string;
129
+ password?: string;
130
+ languages?: Array<string>;
131
+ user?: string;
132
+ };
133
+
134
+ declare type ChaiSubPage = Pick<ChaiPage, "uuid" | "name" | "blocks" | "type" | "project">;
135
+
136
+ declare type TChaiResponse<T> = Promise<{
137
+ data: T;
138
+ error: null;
139
+ result: string;
140
+ }>;
141
+
142
+ export { }
package/dist/server.js ADDED
@@ -0,0 +1,126 @@
1
+ var d = Object.defineProperty;
2
+ var u = (o, t, e) => t in o ? d(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
+ var a = (o, t, e) => (u(o, typeof t != "symbol" ? t + "" : t, e), e);
4
+ import { set as h, isEmpty as g } from "lodash";
5
+ const i = "https://api.chaibuilder.com";
6
+ class y {
7
+ constructor(t, e) {
8
+ a(this, "authToken");
9
+ a(this, "projectKey");
10
+ if (!t)
11
+ throw "Please provide valid auth token.";
12
+ if (!e)
13
+ throw "Please provide valid project key.";
14
+ this.authToken = t, this.projectKey = e;
15
+ }
16
+ /**
17
+ *
18
+ * @param uuid
19
+ * @returns Detail Single Page Information
20
+ */
21
+ async getPage(t) {
22
+ if (!t)
23
+ return Promise.reject({
24
+ data: null,
25
+ error: { message: "Invalid page uuid" },
26
+ result: "error"
27
+ });
28
+ const e = this.getHeaders(), s = this.getURL("page", { uuid: t }), n = { method: "GET", headers: e };
29
+ return this.fetchAPI(s, n);
30
+ }
31
+ /**
32
+ *
33
+ * @returns List of all pages
34
+ */
35
+ async getPages() {
36
+ const t = this.getHeaders(), e = this.getURL("pages"), r = { method: "GET", headers: t };
37
+ return this.fetchAPI(e, r);
38
+ }
39
+ /**
40
+ *
41
+ * @param page
42
+ * @returns Detail of new page
43
+ */
44
+ async addPage(t) {
45
+ h(t, "project", this.projectKey);
46
+ const e = JSON.stringify(t), s = this.getHeaders(), r = this.getURL("page"), c = { method: "POST", headers: s, body: e };
47
+ return this.fetchAPI(r, c);
48
+ }
49
+ /**
50
+ *
51
+ * @param uuid
52
+ * @returns Success | Error Message
53
+ */
54
+ async deletePage(t) {
55
+ if (!t)
56
+ return Promise.reject({
57
+ data: null,
58
+ error: { message: "Invalid page uuid" },
59
+ result: "error"
60
+ });
61
+ const e = this.getHeaders(), s = this.getURL("page", { uuid: t }), n = { method: "DELETE", headers: e };
62
+ return this.fetchAPI(s, n);
63
+ }
64
+ /**
65
+ *
66
+ * @param page
67
+ * @returns Update page information or Error response
68
+ */
69
+ async updatePage(t) {
70
+ const e = JSON.stringify(t), s = this.getHeaders(), r = this.getURL("page"), c = { method: "PUT", headers: s, body: e };
71
+ return this.fetchAPI(r, c);
72
+ }
73
+ /**
74
+ *
75
+ * @returns Project detail
76
+ */
77
+ async getProject() {
78
+ const t = this.getHeaders(), e = this.getURL("project"), r = { method: "GET", headers: t };
79
+ return this.fetchAPI(e, r);
80
+ }
81
+ /**
82
+ *
83
+ * @param project
84
+ * @returns Updated project detail
85
+ */
86
+ async updateProject(t) {
87
+ t.uuid = this.projectKey, h(t, "uuid", this.projectKey);
88
+ const e = JSON.stringify(t), s = this.getHeaders(), r = this.getURL("project"), c = { method: "PUT", headers: s, body: e };
89
+ return this.fetchAPI(r, c);
90
+ }
91
+ /**
92
+ *
93
+ * @param endpoint
94
+ * @param queryParam
95
+ * @returns api endpoint with query param
96
+ */
97
+ getURL(t, e) {
98
+ const s = new URLSearchParams(e).toString();
99
+ return g(e) ? `${i}/v1/${t}` : `${i}/v1/${t}?${s}`;
100
+ }
101
+ /**
102
+ *
103
+ * @returns headers for api
104
+ */
105
+ getHeaders() {
106
+ const t = new Headers();
107
+ return t.append("x-chai-app-key", this.projectKey), t.append("x-chai-auth-token", this.authToken), t.append("Content-Type", "application/json"), t;
108
+ }
109
+ /**
110
+ *
111
+ * @returns Fetch API
112
+ */
113
+ async fetchAPI(t, e) {
114
+ try {
115
+ const s = await fetch(t, e).then((r) => r.json());
116
+ if ((s == null ? void 0 : s.result) === "success")
117
+ return { data: s == null ? void 0 : s.data, error: null, result: "success" };
118
+ throw s == null ? void 0 : s.error;
119
+ } catch (s) {
120
+ return { data: null, error: s, result: "error" };
121
+ }
122
+ }
123
+ }
124
+ export {
125
+ y as ChaibuilderBackend
126
+ };