@chaibuilder/sdk 3.2.13 → 4.0.0-beta.10

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 (193) hide show
  1. package/README.md +88 -61
  2. package/dist/2SSKDMRQ-CfHqXEo6.cjs +1 -0
  3. package/dist/2SSKDMRQ-KxbQMSQF.js +42 -0
  4. package/dist/AP7HFJJL-B3bVbF4b.cjs +1228 -0
  5. package/dist/AP7HFJJL-DJe0zNfP.js +9214 -0
  6. package/dist/IconPicker-7YKi0cvf.cjs +1 -0
  7. package/dist/IconPicker-CaEjFuuU.js +60 -0
  8. package/dist/STRINGS-BExFecZW.js +8 -0
  9. package/dist/STRINGS-FNnfjF5H.cjs +1 -0
  10. package/dist/WDYDFRGG-4MvQxrrE.cjs +1 -0
  11. package/dist/WDYDFRGG-DesO-YVt.js +33 -0
  12. package/dist/_commonjsHelpers-C6fGbg64.js +6 -0
  13. package/dist/_commonjsHelpers-DwGv2jUC.cjs +1 -0
  14. package/dist/actions-registery-BRgseJas.cjs +418 -0
  15. package/dist/actions-registery-DRV8xywr.js +15540 -0
  16. package/dist/actions.cjs +1 -0
  17. package/dist/actions.d.ts +3229 -0
  18. package/dist/actions.js +216 -0
  19. package/dist/active-in-another-tab-BraPCVHD.js +35 -0
  20. package/dist/active-in-another-tab-DmiLcoHl.cjs +1 -0
  21. package/dist/add-new-language-page-BiS0BJFh.cjs +1 -0
  22. package/dist/add-new-language-page-DaNJhujm.js +402 -0
  23. package/dist/add-new-page-BavGPTWz.js +31 -0
  24. package/dist/add-new-page-dbDUyekW.cjs +1 -0
  25. package/dist/ai-panel-content-4Cv-ufXL.js +62 -0
  26. package/dist/ai-panel-content-ClQ5alrF.cjs +1 -0
  27. package/dist/ai-panel-default-lang-BVgCW7Iu.cjs +3 -0
  28. package/dist/ai-panel-default-lang-CByGoNp5.js +341 -0
  29. package/dist/ai-panel-other-lang-BXuiVjMR.cjs +1 -0
  30. package/dist/ai-panel-other-lang-DznZUrL7.js +162 -0
  31. package/dist/ai-prompt-input--MqeAtTu.cjs +1 -0
  32. package/dist/ai-prompt-input-DbNqAJmK.js +656 -0
  33. package/dist/ai-translation-prompt-CqZE5xvG.js +28 -0
  34. package/dist/ai-translation-prompt-yU9T98gu.cjs +1 -0
  35. package/dist/{apply-binding-DLaiD20q.js → apply-binding-CLU6Xp4K.js} +251 -257
  36. package/dist/apply-binding-NvZX_rJe.cjs +1 -0
  37. package/dist/code-display-9Onx6RCq.cjs +1 -0
  38. package/dist/{code-display-DuH-UOhl.js → code-display-oa1j0ri7.js} +1 -1
  39. package/dist/code-editor-DI5chGQy.js +51 -0
  40. package/dist/code-editor-eJ-ha21X.cjs +1 -0
  41. package/dist/continue-editing-in-this-client-BIPyGnqp.cjs +1 -0
  42. package/dist/continue-editing-in-this-client-Bs9Q2ase.js +25 -0
  43. package/dist/core-8lkXy4lC.cjs +1 -0
  44. package/dist/core-BvsZwF26.js +52 -0
  45. package/dist/core.cjs +1 -1
  46. package/dist/core.d.ts +145 -565
  47. package/dist/core.js +24 -103
  48. package/dist/css-import-modal-Cwq__qKK.cjs +13 -0
  49. package/dist/{css-import-modal-CFB2YjDT.js → css-import-modal-D-_jby_w.js} +40 -38
  50. package/dist/{delete-design-token-BjMakV-b.js → delete-design-token-BowiWJOb.js} +3 -3
  51. package/dist/delete-design-token-DjHXH5dg.cjs +1 -0
  52. package/dist/delete-page-Cs0cenoN.js +71 -0
  53. package/dist/delete-page-DqBuzcBW.cjs +1 -0
  54. package/dist/design-token-usage-DDqd3J3T.cjs +1 -0
  55. package/dist/design-token-usage-cjJe9KUU.js +114 -0
  56. package/dist/digital-asset-manager-DjPTwqCP.cjs +1 -0
  57. package/dist/digital-asset-manager-rw_FW-e4.js +877 -0
  58. package/dist/duplicate-page-B19XZEEh.js +134 -0
  59. package/dist/duplicate-page-CpgDT34h.cjs +1 -0
  60. package/dist/dynamic-page-selector-CJXMaEu0.cjs +1 -0
  61. package/dist/dynamic-page-selector-D1pcyyIi.js +86 -0
  62. package/dist/fonts-B-Xt29pe.cjs +1 -0
  63. package/dist/fonts-DRly3Wzd.js +78 -0
  64. package/dist/get-chai-builder-tailwind-config-DNp8Vhme.cjs +1 -0
  65. package/dist/{get-chai-builder-tailwind-config-BqaIvg8p.js → get-chai-builder-tailwind-config-k8l5sdcw.js} +14 -11
  66. package/dist/get-chai-builder-theme-BApShjRz.cjs +1 -0
  67. package/dist/get-chai-builder-theme-DDVRJQ6Z.js +24 -0
  68. package/dist/get-seo-defaults-9zHebckY.js +65 -0
  69. package/dist/get-seo-defaults-Cw7vFt-B.cjs +1 -0
  70. package/dist/image-compression-DZ9WMmyn.cjs +1 -0
  71. package/dist/image-compression-DsZ1oqpb.js +37 -0
  72. package/dist/image-editor-BihtCpkn.cjs +1 -0
  73. package/dist/image-editor-lztBulYI.js +108 -0
  74. package/dist/index-BEldAI1n.cjs +160 -0
  75. package/dist/index-BqlDf5fg.js +18418 -0
  76. package/dist/index-CsChke2B.js +4741 -0
  77. package/dist/index-DTz1hNwi.cjs +5 -0
  78. package/dist/json-diff-viewer-BDbS64LG.cjs +8 -0
  79. package/dist/json-diff-viewer-DI6nPbs8.js +259 -0
  80. package/dist/lang-panel-B51V4-PX.js +216 -0
  81. package/dist/lang-panel-DFttT_MB.cjs +1 -0
  82. package/dist/manage-design-tokens-D8GDkdB2.cjs +1 -0
  83. package/dist/{manage-design-tokens-BHCCrWFS.js → manage-design-tokens-DCPswHMS.js} +24 -24
  84. package/dist/mark-as-template-DBF2r7aW.js +157 -0
  85. package/dist/mark-as-template-rI-cx5-B.cjs +1 -0
  86. package/dist/models-5gOsRC56.cjs +1 -0
  87. package/dist/models-D95ZYr_x.js +70 -0
  88. package/dist/nested-path-selector-content-BQhK20BE.js +88 -0
  89. package/dist/nested-path-selector-content-o7k86m-q.cjs +1 -0
  90. package/dist/no-language-page-content-C2hLFt7A.js +43 -0
  91. package/dist/no-language-page-content-DmgQLhac.cjs +1 -0
  92. package/dist/no-language-page-dialog-BmB5fz92.js +10 -0
  93. package/dist/no-language-page-dialog-D2Ijv2V4.cjs +1 -0
  94. package/dist/page-creator-CGxrkmut.js +796 -0
  95. package/dist/page-creator-jlPEOhfz.cjs +1 -0
  96. package/dist/page-lock-CnOS_qxc.js +30 -0
  97. package/dist/page-lock-CoAmLhTA.cjs +1 -0
  98. package/dist/page-locked-dialog-B2L9yqX1.js +136 -0
  99. package/dist/page-locked-dialog-BNHr0OAi.cjs +1 -0
  100. package/dist/page-manager-new-CkNowPYt.cjs +1 -0
  101. package/dist/page-manager-new-D_TxW1yk.js +395 -0
  102. package/dist/page-manager-search-and-filter-Bme84N1w.js +202 -0
  103. package/dist/page-manager-search-and-filter-CpjNOQqF.cjs +1 -0
  104. package/dist/page-revisions-content-B_EkI6eN.js +456 -0
  105. package/dist/page-revisions-content-DYt-0IJ3.cjs +1 -0
  106. package/dist/pages.cjs +1 -0
  107. package/dist/pages.d.ts +545 -0
  108. package/dist/pages.js +27 -0
  109. package/dist/plugin-BGlQf0iy.cjs +22 -0
  110. package/dist/{plugin-BOcGV_IY.js → plugin-C-ht41UZ.js} +31 -45
  111. package/dist/publish-pages-content-1_-8jO3C.cjs +1 -0
  112. package/dist/publish-pages-content-Ct-rYFXD.js +179 -0
  113. package/dist/register-chai-top-bar-CX_JkRJn.js +237 -0
  114. package/dist/register-chai-top-bar-DWTuRU53.cjs +1 -0
  115. package/dist/register-partial-type-BjtdfKHE.js +36 -0
  116. package/dist/register-partial-type-ig9fUWIJ.cjs +1 -0
  117. package/dist/render.cjs +2 -2
  118. package/dist/render.d.ts +25 -23
  119. package/dist/render.js +108 -103
  120. package/dist/rte-widget-modal-88x3Ag4b.cjs +1 -0
  121. package/dist/rte-widget-modal-BpjTwrAJ.js +39 -0
  122. package/dist/runtime-client.cjs +1 -0
  123. package/dist/runtime-client.d.ts +158 -0
  124. package/dist/runtime-client.js +32 -0
  125. package/dist/runtime.cjs +1 -1
  126. package/dist/runtime.d.ts +322 -7
  127. package/dist/runtime.js +74 -1
  128. package/dist/save-to-lib-B5ggugo6.js +423 -0
  129. package/dist/save-to-lib-BSCJSBw9.cjs +1 -0
  130. package/dist/sdk.css +1 -1
  131. package/dist/selected-block-display-DrMFz5_U.js +320 -0
  132. package/dist/selected-block-display-wHwP16Pz.cjs +16 -0
  133. package/dist/seo-panel-Bktda7aV.cjs +2 -0
  134. package/dist/seo-panel-Dzx-sUAi.js +799 -0
  135. package/dist/shared-json-ld-BMt3lSVf.js +566 -0
  136. package/dist/shared-json-ld-RDvoItXK.cjs +1 -0
  137. package/dist/slug-input-BtbW6w7B.cjs +1 -0
  138. package/dist/slug-input-CyKRaEV_.js +87 -0
  139. package/dist/supabase-actions.cjs +1 -0
  140. package/dist/supabase-actions.d.ts +289 -0
  141. package/dist/supabase-actions.js +524 -0
  142. package/dist/take-over-request-BA_e938L.js +64 -0
  143. package/dist/take-over-request-DsDWVplQ.cjs +1 -0
  144. package/dist/theme-panel-footer-6iHKSeON.cjs +1 -0
  145. package/dist/theme-panel-footer-v8PRUzwR.js +26 -0
  146. package/dist/translation-warning-modal-B1tAPMx7.js +27 -0
  147. package/dist/translation-warning-modal-DA7Vj_9F.cjs +1 -0
  148. package/dist/types.cjs +1 -0
  149. package/dist/types.d.ts +598 -0
  150. package/dist/types.js +1 -0
  151. package/dist/unmark-as-template-Bdg5nLBS.cjs +1 -0
  152. package/dist/unmark-as-template-C6pllRk5.js +40 -0
  153. package/dist/unpublish-page-BOrfamLs.cjs +1 -0
  154. package/dist/unpublish-page-C3Wub7gR.js +28 -0
  155. package/dist/use-page-expand-manager-B6XTvk0E.cjs +1 -0
  156. package/dist/use-page-expand-manager-Cf4MUEJw.js +85 -0
  157. package/dist/utils.cjs +1 -0
  158. package/dist/{tailwind.d.ts → utils.d.ts} +12 -12
  159. package/dist/utils.js +7 -0
  160. package/dist/web-blocks.cjs +1 -1
  161. package/dist/web-blocks.d.ts +0 -6
  162. package/dist/web-blocks.js +240 -239
  163. package/dist/web-preview-869kgvNU.cjs +1 -0
  164. package/dist/web-preview-CVAQ53g_.js +73 -0
  165. package/package.json +152 -76
  166. package/dist/IconPicker-6JSublJp.js +0 -64
  167. package/dist/IconPicker-DpQQDK_Q.cjs +0 -1
  168. package/dist/apply-binding-Bn1KC8uC.cjs +0 -1
  169. package/dist/code-display-Dw1tAwiJ.cjs +0 -1
  170. package/dist/code-editor-CEsA4Nlq.cjs +0 -1
  171. package/dist/code-editor-DPr4HDOV.js +0 -59
  172. package/dist/css-import-modal-bGWZSlqv.cjs +0 -13
  173. package/dist/delete-design-token-Bzxspf8D.cjs +0 -1
  174. package/dist/design-token-usage-DyQcFypc.cjs +0 -1
  175. package/dist/design-token-usage-_FBnvL92.js +0 -120
  176. package/dist/get-chai-builder-tailwind-config-C6MHaUM0.cjs +0 -1
  177. package/dist/get-chai-builder-theme-B1tr_NJB.cjs +0 -1
  178. package/dist/get-chai-builder-theme-BarMkcGH.js +0 -12
  179. package/dist/index-CIez6R-d.js +0 -18327
  180. package/dist/index-zLw6cVaV.cjs +0 -160
  181. package/dist/manage-design-tokens-Cfjg_at9.cjs +0 -1
  182. package/dist/mockServiceWorker.js +0 -349
  183. package/dist/plugin-CSgw-f78.cjs +0 -22
  184. package/dist/rte-widget-modal-CsBCpJSY.js +0 -41
  185. package/dist/rte-widget-modal-Dif3ZoFQ.cjs +0 -1
  186. package/dist/tailwind.cjs +0 -1
  187. package/dist/tailwind.js +0 -8
  188. package/dist/tooltip-Ba1-8jmj.cjs +0 -1
  189. package/dist/tooltip-DUosa-uC.js +0 -1067
  190. package/dist/ui.cjs +0 -1
  191. package/dist/ui.d.ts +0 -415
  192. package/dist/ui.js +0 -129
  193. package/dist/vite.svg +0 -1
@@ -0,0 +1,87 @@
1
+ import { jsxs as i, jsx as o } from "react/jsx-runtime";
2
+ import { z as v } from "./register-chai-top-bar-CX_JkRJn.js";
3
+ import { a8 as d } from "./index-BqlDf5fg.js";
4
+ import { useState as x, useEffect as C } from "react";
5
+ const y = (e) => {
6
+ if (!e) return { base: e, extension: null };
7
+ const n = e.lastIndexOf(".");
8
+ if (n <= 0) return { base: e, extension: null };
9
+ const t = e.substring(n);
10
+ return { base: e.substring(0, n), extension: t };
11
+ }, g = (e) => {
12
+ if (!e) return e;
13
+ const { base: n } = y(e);
14
+ return n;
15
+ };
16
+ function w(e, n) {
17
+ const t = (e || "").split("/").filter(Boolean);
18
+ let s = "", r = !0;
19
+ if (n.slug === "/") {
20
+ const a = t.pop() || "";
21
+ if (d[a])
22
+ r = !0;
23
+ else {
24
+ s = a;
25
+ const l = t.pop() || "";
26
+ r = !!d[l];
27
+ }
28
+ } else if (n.parent)
29
+ t.length && (s = t.pop() || "");
30
+ else if (t.length) {
31
+ s = t.pop() || "";
32
+ const a = t.pop() || "";
33
+ r = !!d[a];
34
+ }
35
+ return { initSlug: s, prefix: r };
36
+ }
37
+ const E = (e) => e && g(e), D = (e, n) => {
38
+ const t = g(e || "");
39
+ return !t || t === "/" ? `/${n}` : `${t}/${n}`;
40
+ };
41
+ function G({
42
+ value: e,
43
+ onChange: n,
44
+ placeholder: t,
45
+ parentSlug: s,
46
+ onValidationChange: r,
47
+ disabled: a = !1,
48
+ fullSlug: l
49
+ }) {
50
+ const [h, u] = x(e), [c, f] = x(null);
51
+ C(() => {
52
+ u(e);
53
+ }, [e]);
54
+ const N = (b) => {
55
+ const p = b.target.value.replace(/\//g, "").replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-_.]/g, "-").replace(/-+/g, "-").replace(/^-+/, "").toLowerCase(), m = (p.match(/\./g) || []).length, S = m <= 1;
56
+ m > 1 ? f("Invalid slug. Only one dot (.) is allowed in the slug") : f(null), r && r(S), u(p), n(p);
57
+ };
58
+ return /* @__PURE__ */ i("div", { children: [
59
+ s && /* @__PURE__ */ o("div", { className: "mb-1 flex items-center", children: /* @__PURE__ */ i("span", { className: "text-xs text-gray-500", children: [
60
+ "Parent: ",
61
+ /* @__PURE__ */ o("span", { className: "font-mono text-gray-900", children: E(s) })
62
+ ] }) }),
63
+ /* @__PURE__ */ i("div", { className: "relative", children: [
64
+ /* @__PURE__ */ o(
65
+ v,
66
+ {
67
+ disabled: a,
68
+ value: h,
69
+ onChange: N,
70
+ placeholder: t,
71
+ className: c ? "border-red-500" : ""
72
+ }
73
+ ),
74
+ c && /* @__PURE__ */ o("div", { className: "mt-1 text-xs text-red-500", children: c })
75
+ ] }),
76
+ l && l !== "undefined" && /* @__PURE__ */ o("div", { className: "mt-1 flex items-center", children: /* @__PURE__ */ i("span", { className: "text-xs text-gray-500", children: [
77
+ "Complete Slug: ",
78
+ /* @__PURE__ */ o("span", { className: "font-mono text-gray-900", children: l })
79
+ ] }) })
80
+ ] });
81
+ }
82
+ export {
83
+ G as S,
84
+ D as c,
85
+ w as p,
86
+ g as r
87
+ };
@@ -0,0 +1 @@
1
+ "use strict";var O=Object.defineProperty;var D=(l,r,e)=>r in l?O(l,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[r]=e;var y=(l,r,e)=>D(l,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./actions-registery-BRgseJas.cjs"),f=require("lodash-es"),b=require("sharp"),c=require("zod");class A{constructor(r,e,t){this.appId=r,this.userId=e,this.supabase=t}appendUpdatedAtToUrl(r,e){if(f.isEmpty(r))return"";const t=new URL(r),o=new Date(e).getTime();return t.searchParams.set("t",o.toString()),`${t.origin}${t.pathname}${t.search}${t.hash}`}getBufferFromBase64(r){try{const e=r.split(",")[1]||r;return Buffer.from(e,"base64")}catch{throw new Error("Invalid base64 string format")}}async uploadImageFile(r,e,t,o){try{const s=this.getBufferFromBase64(r),n=await b(s).metadata(),i=["jpeg","jpg","png","webp","gif","svg","tiff"];if(!n.format||!i.includes(n.format.toLowerCase()))throw new Error(`Invalid image format: ${n.format||"unknown"}`);const u=o?await b(s).webp({quality:100}).resize({width:Math.min(n.width||2e3,2e3)}).toBuffer():await b(s).webp({quality:100}).toBuffer();let a=u;if(o&&u.length>120*1024){const _=Math.floor(90*(122880/u.length));a=await b(s).webp({quality:_}).resize({width:Math.min(n.width||2e3,2e3)}).toBuffer()}const d=await b(a).metadata(),g=await b(s).webp({quality:70}).resize({width:300}).toBuffer(),p=t.split("."),m=p.length>1?p.slice(0,-1).join("."):t,w=`${f.kebabCase(m)}.webp`,z=`${w}_thumbnail.webp`,T=this.appId,I=e?`${T}/${e}`:T,S=h.getChaiAction("UPLOAD_TO_STORAGE");if(!S)throw new Error("UPLOAD_TO_STORAGE action not found");S.setContext({appId:this.appId,userId:this.userId});const U=await S.execute({file:a.toString("base64"),fileName:w,contentType:"image/webp",folder:I});if(U.error)throw new Error(U.error);const E=await S.execute({file:g.toString("base64"),fileName:z,contentType:"image/webp",folder:I});if(E.error)throw new Error(E.error);return{url:U.data.url,thumbnailUrl:E.data.url,size:d.size||a.length,width:d.width||0,height:d.height||0,mimeType:"image/webp"}}catch(s){return console.error("Upload image error:",s),{error:s instanceof Error?s.message:"Unknown error"}}}async uploadSvgFile(r,e,t){try{const o=this.getBufferFromBase64(r);let s,n;try{const w=await b(o).metadata();s=w.width,n=w.height}catch{}const i=t.split("."),u=i.length>1?i.slice(0,-1).join("."):t,a=`${f.kebabCase(u)}.svg`,d=this.appId,g=e?`${d}/${e}`:d,p=h.getChaiAction("UPLOAD_TO_STORAGE");if(!p)throw new Error("UPLOAD_TO_STORAGE action not found");p.setContext({appId:this.appId,userId:this.userId});const m=await p.execute({file:o.toString("base64"),fileName:a,contentType:"image/svg+xml",folder:g});if(m.error)throw new Error(m.error);return{url:m.data.url,thumbnailUrl:m.data.url,size:o.length,width:s,height:n,mimeType:"image/svg+xml"}}catch(o){return console.error("SVG upload error:",o),{error:o instanceof Error?o.message:"Unknown error"}}}async upload({file:r,folderId:e,name:t,optimize:o=!0}){var s;try{const i=t.toLowerCase().endsWith(".svg")||r.includes("data:image/svg+xml")?await this.uploadSvgFile(r,e,t):await this.uploadImageFile(r,e,t,o??!0);if("error"in i)return i;const u={name:t,app:this.appId,url:i.url,thumbnailUrl:i.thumbnailUrl,size:(s=i.size)==null?void 0:s.toString(),width:i.width,height:i.height,format:i.mimeType.split("/")[1],folderId:e,type:i.mimeType.startsWith("image/")?"image":"file",createdBy:this.userId,updatedAt:new Date().toISOString()},{data:a,error:d}=await this.supabase.from("app_assets").insert(u).select("*").single();if(d)throw new Error(`Failed to store asset in database: ${d.message}`);return{id:a.id,name:a.name,type:a.type,url:this.appendUpdatedAtToUrl(a.url,a.updatedAt),size:a.size,thumbnailUrl:this.appendUpdatedAtToUrl(a.thumbnailUrl||"",a.updatedAt),width:a.width,height:a.height,format:a.format,folderId:a.folderId,createdBy:a.createdBy||"",createdAt:a.createdAt,updatedAt:a.updatedAt}}catch(n){return{error:n instanceof Error?n.message:"Unknown error occurred"}}}async getAsset({id:r}){try{const{data:e,error:t}=await this.supabase.from("app_assets").select("*").eq("id",r).eq("app",this.appId).single();if(t)throw new Error(`Failed to fetch asset: ${t.message}`);return f.set(e,"url",this.appendUpdatedAtToUrl(e.url,e.updatedAt)),f.set(e,"thumbnailUrl",this.appendUpdatedAtToUrl(e.thumbnailUrl||"",e.updatedAt)),e}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async getAssets({search:r="",page:e=1,limit:t=20}={}){try{const o=(e-1)*t;let s=this.supabase.from("app_assets").select("*",{count:"exact"}).eq("app",this.appId).order("updatedAt",{ascending:!1});r&&(s=s.or(`name.ilike.%${r}%,description.ilike.%${r}%`));const{data:n,error:i,count:u}=await s.range(o,o+t-1);if(i)throw new Error(i.message);return{assets:n.map(d=>(f.set(d,"url",this.appendUpdatedAtToUrl(d.url,d.updatedAt)),f.set(d,"thsupabaseumbnailUrl",this.appendUpdatedAtToUrl(d.thumbnailUrl||"",d.updatedAt)),d)),total:u||0,page:e,pageSize:t}}catch(o){throw console.error("Error fetching assets:",o),o}}async deleteAsset({id:r}){try{const{data:e,error:t}=await this.supabase.from("app_assets").select("*").eq("id",r).eq("app",this.appId).single();if(t)throw new Error(`Failed to fetch asset: ${t.message}`);if(e.url)try{const n=new URL(e.url).pathname.split("/"),i=n.indexOf("dam-assets");if(i!==-1){const u=n.slice(i+1).join("/"),a=h.getChaiAction("DELETE_FROM_STORAGE");if(a&&(a.setContext({appId:this.appId,userId:this.userId}),await a.execute({key:u})),e.thumbnailUrl&&e.thumbnailUrl!==e.url){const g=new URL(e.thumbnailUrl).pathname.split("/"),p=g.indexOf("dam-assets");if(p!==-1){const m=g.slice(p+1).join("/");a&&await a.execute({key:m})}}}}catch(s){console.warn("Failed to delete from storage, continuing with database deletion:",s)}const{error:o}=await this.supabase.from("app_assets").delete().eq("id",r);if(o)throw new Error(`Failed to delete asset: ${o.message}`);return{success:!0}}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async updateAsset({id:r,file:e,description:t}){var o,s;try{const{data:n,error:i}=await this.supabase.from("app_assets").select("*").eq("id",r).single();if(i)throw new Error(`Failed to fetch asset: ${i.message}`);const u={};if(t!==void 0&&(u.description=t,u.updatedAt=new Date().toISOString()),e){const p=((o=n.format)==null?void 0:o.toLowerCase())==="svg"||e.includes("data:image/svg+xml")?await this.uploadSvgFile(e,n.folderId,n.name):await this.uploadImageFile(e,n.folderId,n.name,!0);if("error"in p)return p;u.url=p.url,u.thumbnailUrl=p.thumbnailUrl,u.size=(s=p.size)==null?void 0:s.toString(),u.width=p.width,u.height=p.height,u.format=p.mimeType.split("/")[1],u.updatedAt=new Date().toISOString()}const{data:a,error:d}=await this.supabase.from("app_assets").update(u).eq("id",r).select().single();if(d)throw new Error(`Failed to update asset: ${d.message}`);return f.set(a,"url",this.appendUpdatedAtToUrl(a.url,a.updatedAt)),f.set(a,"thumbnailUrl",this.appendUpdatedAtToUrl(a.thumbnailUrl||"",a.updatedAt)),a}catch(n){return{error:n instanceof Error?n.message:"Unknown error occurred"}}}}const C=c.z.object({name:c.z.string(),file:c.z.string(),folderId:c.z.string().optional().nullable(),optimize:c.z.boolean().optional()});class F extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return C}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).upload(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPLOAD_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const B=c.z.object({id:c.z.string()});class v extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return B}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).getAsset(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const $=c.z.object({search:c.z.string().optional(),page:c.z.number().optional(),limit:c.z.number().optional()});class q extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return $}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).getAssets(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSETS error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const G=c.z.object({id:c.z.string()});class j extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return G}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).deleteAsset(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("DELETE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const L=c.z.object({id:c.z.string(),file:c.z.string().optional(),description:c.z.string().optional()});class P extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return L}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).updateAsset(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPDATE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const R=c.z.object({userId:c.z.string()});class M extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return R}async execute(r){var e,t,o,s,n,i;try{const{userId:u}=r,{data:a,error:d}=await this.supabase.auth.admin.getUserById(u);return d?{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}:{data:{id:((e=a.user)==null?void 0:e.id)||"unknown",email:((t=a.user)==null?void 0:t.email)||"unknown@chaibuilder.com",name:((s=(o=a.user)==null?void 0:o.user_metadata)==null?void 0:s.name)||"Unknown",avatar:((i=(n=a.user)==null?void 0:n.user_metadata)==null?void 0:i.avatar)||""},status:200}}catch{return{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}}}}const N=c.z.object({key:c.z.string()});class x extends h.ChaiBaseAction{constructor(e){super();y(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return N}async execute(e){try{const{key:t}=e,{error:o}=await this.supabase.storage.from(this.bucketName).remove([t]);return o?{error:`Failed to delete from Supabase Storage: ${o.message}`,status:500}:{data:{success:!0},status:200}}catch(t){return console.error("DELETE_FROM_STORAGE error:",t),{error:t instanceof Error?t.message:"Unknown error",status:500}}}}const V=c.z.object({file:c.z.string(),fileName:c.z.string(),contentType:c.z.string().optional(),folder:c.z.string().optional(),metadata:c.z.record(c.z.string(),c.z.any()).optional()});class k extends h.ChaiBaseAction{constructor(e){super();y(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return V}async execute(e){try{if(!this.context)return{error:"Context not set",status:400};const{appId:t}=this.context,{file:o,fileName:s,contentType:n,folder:i,metadata:u}=e;let a;if(typeof o=="string"){const w=o.split(",")[1]||o;a=Buffer.from(w,"base64")}else a=o;const d=i?`${i}/${s}`:`${t}/${s}`,{data:g,error:p}=await this.supabase.storage.from(this.bucketName).upload(d,a,{contentType:n||"application/octet-stream",upsert:!0,...u&&{metadata:u}});if(p)return{error:`Failed to upload to Supabase Storage: ${p.message}`,status:500};const{data:{publicUrl:m}}=this.supabase.storage.from(this.bucketName).getPublicUrl(d);return{data:{url:m,key:g.path,size:a.length,metadata:u},status:200}}catch(t){return console.error("UPLOAD_TO_STORAGE error:",t),{error:t instanceof Error?t.message:"Unknown error",status:500}}}}const W=l=>({GET_CHAI_USER:new M(l)}),H=l=>({UPLOAD_ASSET:new F(l),GET_ASSET:new v(l),GET_ASSETS:new q(l),DELETE_ASSET:new j(l),UPDATE_ASSET:new P(l),UPLOAD_TO_STORAGE:new k(l),DELETE_FROM_STORAGE:new x(l)});exports.DeleteFromStorageAction=x;exports.SupabaseAuthActions=W;exports.SupabaseStorageActions=H;exports.UploadToStorageAction=k;
@@ -0,0 +1,289 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * ChaiAction Interface
6
+ * Defines the contract for all action handlers
7
+ */
8
+ declare interface ChaiAction<T = any, K = any> {
9
+ validate(data: T): boolean;
10
+ setContext(context: ChaiActionContext): void;
11
+ execute(data: T): Promise<K>;
12
+ }
13
+
14
+ /**
15
+ * Action Context
16
+ * Contains information and repositories needed by actions
17
+ */
18
+ declare interface ChaiActionContext {
19
+ appId: string;
20
+ userId?: string;
21
+ }
22
+
23
+ /**
24
+ * Base Action Class
25
+ * Provides common functionality for all action handlers
26
+ */
27
+ declare abstract class ChaiBaseAction<T = any, K = any> implements ChaiAction<T, K> {
28
+ protected context: ChaiActionContext | null;
29
+ /**
30
+ * Abstract method to get the validation schema for the action data
31
+ * Each action must implement this to define its own validation rules
32
+ */
33
+ protected abstract getValidationSchema(): z.ZodType<T>;
34
+ /**
35
+ * Validate the action data using the schema provided by getValidationSchema
36
+ * @param data The data to validate
37
+ * @returns true if the data is valid, false otherwise
38
+ */
39
+ validate(data: T): boolean;
40
+ /**
41
+ * Get validation errors for the action data
42
+ * This can be useful for debugging or providing more detailed error messages
43
+ * @param data The data to validate
44
+ * @returns An array of validation errors or null if the data is valid
45
+ */
46
+ getValidationErrors(data: T): string | null;
47
+ /**
48
+ * Set the action context
49
+ * @param context The context to set
50
+ */
51
+ setContext(context: ChaiActionContext): void;
52
+ /**
53
+ * Abstract method to execute the action
54
+ * Each action must implement this to define its own business logic
55
+ */
56
+ abstract execute(data: T): Promise<any>;
57
+ /**
58
+ * Verify if the user has access to the app
59
+ * @throws ActionError if the user does not have access
60
+ */
61
+ protected verifyAccess(): Promise<void>;
62
+ /**
63
+ * Helper method to handle common errors in actions
64
+ * @param error The error to handle
65
+ * @throws ActionError with appropriate message and code
66
+ */
67
+ protected handleError(error: unknown): never;
68
+ }
69
+
70
+ declare interface ChaiUser {
71
+ id: string;
72
+ email: string;
73
+ name: string;
74
+ avatar: string;
75
+ }
76
+
77
+ declare class DeleteAssetAction extends ChaiBaseAction<DeleteAssetInput> {
78
+ private supabase;
79
+ constructor(supabase: SupabaseClient);
80
+ protected getValidationSchema(): z.ZodObject<{
81
+ id: z.ZodString;
82
+ }, z.core.$strip>;
83
+ execute(data: DeleteAssetInput): Promise<{
84
+ success: boolean;
85
+ } | {
86
+ error: string;
87
+ status: number;
88
+ }>;
89
+ }
90
+
91
+ declare type DeleteAssetInput = z.infer<typeof DeleteAssetSchema>;
92
+
93
+ declare const DeleteAssetSchema: z.ZodObject<{
94
+ id: z.ZodString;
95
+ }, z.core.$strip>;
96
+
97
+ /**
98
+ * DELETE_FROM_STORAGE Action
99
+ * Generic storage delete action using Supabase Storage
100
+ */
101
+ export declare class DeleteFromStorageAction extends ChaiBaseAction<DeleteFromStorageInput> {
102
+ private supabase;
103
+ private bucketName;
104
+ constructor(supabase: SupabaseClient);
105
+ protected getValidationSchema(): z.ZodObject<{
106
+ key: z.ZodString;
107
+ }, z.core.$strip>;
108
+ execute(data: DeleteFromStorageInput): Promise<{
109
+ error: string;
110
+ status: number;
111
+ data?: undefined;
112
+ } | {
113
+ data: {
114
+ success: boolean;
115
+ };
116
+ status: number;
117
+ error?: undefined;
118
+ }>;
119
+ }
120
+
121
+ declare type DeleteFromStorageInput = z.infer<typeof DeleteFromStorageSchema>;
122
+
123
+ declare const DeleteFromStorageSchema: z.ZodObject<{
124
+ key: z.ZodString;
125
+ }, z.core.$strip>;
126
+
127
+ declare class GetAssetAction extends ChaiBaseAction<GetAssetInput> {
128
+ private supabase;
129
+ constructor(supabase: SupabaseClient);
130
+ protected getValidationSchema(): z.ZodObject<{
131
+ id: z.ZodString;
132
+ }, z.core.$strip>;
133
+ execute(data: GetAssetInput): Promise<any>;
134
+ }
135
+
136
+ declare type GetAssetInput = z.infer<typeof GetAssetSchema>;
137
+
138
+ declare class GetAssetsAction extends ChaiBaseAction<GetAssetsInput> {
139
+ private supabase;
140
+ constructor(supabase: SupabaseClient);
141
+ protected getValidationSchema(): z.ZodObject<{
142
+ search: z.ZodOptional<z.ZodString>;
143
+ page: z.ZodOptional<z.ZodNumber>;
144
+ limit: z.ZodOptional<z.ZodNumber>;
145
+ }, z.core.$strip>;
146
+ execute(data: GetAssetsInput): Promise<{
147
+ assets: Partial<any>[];
148
+ total: number;
149
+ page: number;
150
+ pageSize: number;
151
+ } | {
152
+ error: string;
153
+ status: number;
154
+ }>;
155
+ }
156
+
157
+ declare const GetAssetSchema: z.ZodObject<{
158
+ id: z.ZodString;
159
+ }, z.core.$strip>;
160
+
161
+ declare type GetAssetsInput = z.infer<typeof GetAssetsSchema>;
162
+
163
+ declare const GetAssetsSchema: z.ZodObject<{
164
+ search: z.ZodOptional<z.ZodString>;
165
+ page: z.ZodOptional<z.ZodNumber>;
166
+ limit: z.ZodOptional<z.ZodNumber>;
167
+ }, z.core.$strip>;
168
+
169
+ /**
170
+ * GET_CHAI_USER Action
171
+ * Fetches user information from Supabase Auth
172
+ */
173
+ declare class GetChaiUserAction extends ChaiBaseAction<GetChaiUserInput> {
174
+ private supabase;
175
+ constructor(supabase: SupabaseClient);
176
+ protected getValidationSchema(): z.ZodObject<{
177
+ userId: z.ZodString;
178
+ }, z.core.$strip>;
179
+ execute(data: GetChaiUserInput): Promise<{
180
+ data: ChaiUser;
181
+ status: number;
182
+ } | {
183
+ error: string;
184
+ status: number;
185
+ }>;
186
+ }
187
+
188
+ declare type GetChaiUserInput = z.infer<typeof GetChaiUserSchema>;
189
+
190
+ declare const GetChaiUserSchema: z.ZodObject<{
191
+ userId: z.ZodString;
192
+ }, z.core.$strip>;
193
+
194
+ export declare const SupabaseAuthActions: (supabase: SupabaseClient) => {
195
+ GET_CHAI_USER: GetChaiUserAction;
196
+ };
197
+
198
+ export declare const SupabaseStorageActions: (supabase: SupabaseClient) => {
199
+ UPLOAD_ASSET: UploadAssetAction;
200
+ GET_ASSET: GetAssetAction;
201
+ GET_ASSETS: GetAssetsAction;
202
+ DELETE_ASSET: DeleteAssetAction;
203
+ UPDATE_ASSET: UpdateAssetAction;
204
+ UPLOAD_TO_STORAGE: UploadToStorageAction;
205
+ DELETE_FROM_STORAGE: DeleteFromStorageAction;
206
+ };
207
+
208
+ declare class UpdateAssetAction extends ChaiBaseAction<UpdateAssetInput> {
209
+ private supabase;
210
+ constructor(supabase: SupabaseClient);
211
+ protected getValidationSchema(): z.ZodObject<{
212
+ id: z.ZodString;
213
+ file: z.ZodOptional<z.ZodString>;
214
+ description: z.ZodOptional<z.ZodString>;
215
+ }, z.core.$strip>;
216
+ execute(data: UpdateAssetInput): Promise<any>;
217
+ }
218
+
219
+ declare type UpdateAssetInput = z.infer<typeof UpdateAssetSchema>;
220
+
221
+ declare const UpdateAssetSchema: z.ZodObject<{
222
+ id: z.ZodString;
223
+ file: z.ZodOptional<z.ZodString>;
224
+ description: z.ZodOptional<z.ZodString>;
225
+ }, z.core.$strip>;
226
+
227
+ declare class UploadAssetAction extends ChaiBaseAction<UploadAssetInput> {
228
+ private supabase;
229
+ constructor(supabase: SupabaseClient);
230
+ protected getValidationSchema(): z.ZodObject<{
231
+ name: z.ZodString;
232
+ file: z.ZodString;
233
+ folderId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
234
+ optimize: z.ZodOptional<z.ZodBoolean>;
235
+ }, z.core.$strip>;
236
+ execute(data: UploadAssetInput): Promise<any>;
237
+ }
238
+
239
+ declare type UploadAssetInput = z.infer<typeof UploadAssetSchema>;
240
+
241
+ declare const UploadAssetSchema: z.ZodObject<{
242
+ name: z.ZodString;
243
+ file: z.ZodString;
244
+ folderId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
245
+ optimize: z.ZodOptional<z.ZodBoolean>;
246
+ }, z.core.$strip>;
247
+
248
+ /**
249
+ * UPLOAD_TO_STORAGE Action
250
+ * Generic storage upload action using Supabase Storage
251
+ */
252
+ export declare class UploadToStorageAction extends ChaiBaseAction<UploadToStorageInput> {
253
+ private supabase;
254
+ private bucketName;
255
+ constructor(supabase: SupabaseClient);
256
+ protected getValidationSchema(): z.ZodObject<{
257
+ file: z.ZodString;
258
+ fileName: z.ZodString;
259
+ contentType: z.ZodOptional<z.ZodString>;
260
+ folder: z.ZodOptional<z.ZodString>;
261
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
262
+ }, z.core.$strip>;
263
+ execute(data: UploadToStorageInput): Promise<{
264
+ error: string;
265
+ status: number;
266
+ data?: undefined;
267
+ } | {
268
+ data: {
269
+ url: string;
270
+ key: string;
271
+ size: number;
272
+ metadata: Record<string, any> | undefined;
273
+ };
274
+ status: number;
275
+ error?: undefined;
276
+ }>;
277
+ }
278
+
279
+ declare type UploadToStorageInput = z.infer<typeof UploadToStorageSchema>;
280
+
281
+ declare const UploadToStorageSchema: z.ZodObject<{
282
+ file: z.ZodString;
283
+ fileName: z.ZodString;
284
+ contentType: z.ZodOptional<z.ZodString>;
285
+ folder: z.ZodOptional<z.ZodString>;
286
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
287
+ }, z.core.$strip>;
288
+
289
+ export { }