studiocms 0.1.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 (582) hide show
  1. package/CHANGELOG.md +501 -0
  2. package/LICENSE +21 -0
  3. package/README.md +59 -0
  4. package/custom-renderers/index.ts +4 -0
  5. package/custom-renderers/markdocRenderers/markdocReact-components/MarkDocReactRenderer.tsx +8 -0
  6. package/custom-renderers/markdocRenderers/markdocReact-components/MarkDocReactWrapper.astro +13 -0
  7. package/custom-renderers/markdocRenderers/markdocReact.ts +56 -0
  8. package/dist/auth.d.js +0 -0
  9. package/dist/auth.d.ts +397 -0
  10. package/dist/cli/cmds/get-turso.d.ts +1 -0
  11. package/dist/cli/cmds/get-turso.js +10 -0
  12. package/dist/cli/cmds/init/index.d.ts +4 -0
  13. package/dist/cli/cmds/init/index.js +52 -0
  14. package/dist/cli/cmds/init/steps/data/studiocmsEnv.d.ts +3 -0
  15. package/dist/cli/cmds/init/steps/data/studiocmsEnv.js +71 -0
  16. package/dist/cli/cmds/init/steps/envBuilder.d.ts +21 -0
  17. package/dist/cli/cmds/init/steps/envBuilder.js +368 -0
  18. package/dist/cli/cmds/init/steps/nextSteps.d.ts +2 -0
  19. package/dist/cli/cmds/init/steps/nextSteps.js +38 -0
  20. package/dist/cli/cmds/init.d.ts +1 -0
  21. package/dist/cli/cmds/init.js +4 -0
  22. package/dist/cli/index.d.ts +1 -0
  23. package/dist/cli/index.js +9 -0
  24. package/dist/cli/lib/commander.d.ts +39 -0
  25. package/dist/cli/lib/commander.js +87 -0
  26. package/dist/cli/lib/context.d.ts +28 -0
  27. package/dist/cli/lib/context.js +55 -0
  28. package/dist/cli/lib/pathUtil.d.ts +5 -0
  29. package/dist/cli/lib/pathUtil.js +14 -0
  30. package/dist/cli/lib/runExternal.d.ts +20 -0
  31. package/dist/cli/lib/runExternal.js +40 -0
  32. package/dist/cli/lib/seasonal.d.ts +5 -0
  33. package/dist/cli/lib/seasonal.js +88 -0
  34. package/dist/cli/lib/utils.d.ts +55 -0
  35. package/dist/cli/lib/utils.js +310 -0
  36. package/dist/cli/shared/intro.d.ts +2 -0
  37. package/dist/cli/shared/intro.js +24 -0
  38. package/dist/components/DefaultEditor.astro +138 -0
  39. package/dist/components/FormattedDate.astro +12 -0
  40. package/dist/components/Generator.astro +7 -0
  41. package/dist/components/Renderer.astro +13 -0
  42. package/dist/components/auth/OAuthButton.astro +21 -0
  43. package/dist/components/auth/OAuthButtonStack.astro +36 -0
  44. package/dist/components/auth/StaticAuthCheck.astro +20 -0
  45. package/dist/components/auth/StudioCMSLogoSVG.astro +13 -0
  46. package/dist/components/auth/oAuthButtonProviders.d.ts +8 -0
  47. package/dist/components/auth/oAuthButtonProviders.js +35 -0
  48. package/dist/components/dashboard/AstroCodeDiffsScript.astro +25 -0
  49. package/dist/components/dashboard/BaseHead.astro +41 -0
  50. package/dist/components/dashboard/Code.astro +23 -0
  51. package/dist/components/dashboard/DashboardPageHeader.astro +77 -0
  52. package/dist/components/dashboard/DoubleSidebar.astro +26 -0
  53. package/dist/components/dashboard/Footer.astro +16 -0
  54. package/dist/components/dashboard/MainSidebarContent.astro +317 -0
  55. package/dist/components/dashboard/PageHeader.astro +52 -0
  56. package/dist/components/dashboard/SidebarLink.astro +61 -0
  57. package/dist/components/dashboard/SidebarModals.astro +6 -0
  58. package/dist/components/dashboard/SidebarPluginLink.astro +45 -0
  59. package/dist/components/dashboard/SingleSidebar.astro +23 -0
  60. package/dist/components/dashboard/StudioCMSLogo.astro +12 -0
  61. package/dist/components/dashboard/ThemeManager.astro +53 -0
  62. package/dist/components/dashboard/component-scripts/TinyMDE.astro +6 -0
  63. package/dist/components/dashboard/component-scripts/dateTimeListener.d.ts +1 -0
  64. package/dist/components/dashboard/component-scripts/dateTimeListener.js +14 -0
  65. package/dist/components/dashboard/component-scripts/dateWithTimeAndZone.d.ts +1 -0
  66. package/dist/components/dashboard/component-scripts/dateWithTimeAndZone.js +12 -0
  67. package/dist/components/dashboard/component-scripts/makeClientRoutable.d.ts +1 -0
  68. package/dist/components/dashboard/component-scripts/makeClientRoutable.js +9 -0
  69. package/dist/components/dashboard/component-scripts/timeAgo.d.ts +1 -0
  70. package/dist/components/dashboard/component-scripts/timeAgo.js +21 -0
  71. package/dist/components/dashboard/islands/LoginChecker.astro +52 -0
  72. package/dist/components/dashboard/islands/configuration/ConfigForm.astro +317 -0
  73. package/dist/components/dashboard/islands/configuration/LightVsDark.astro +67 -0
  74. package/dist/components/dashboard/islands/content-mgmt/CreateFolder.astro +118 -0
  75. package/dist/components/dashboard/islands/content-mgmt/CreatePage.astro +380 -0
  76. package/dist/components/dashboard/islands/content-mgmt/EditFolder.astro +138 -0
  77. package/dist/components/dashboard/islands/content-mgmt/EditPage.astro +432 -0
  78. package/dist/components/dashboard/islands/content-mgmt/InnerSidebarElement.astro +299 -0
  79. package/dist/components/dashboard/islands/content-mgmt/PageHeader.astro +455 -0
  80. package/dist/components/dashboard/islands/content-mgmt/PageList.astro +49 -0
  81. package/dist/components/dashboard/islands/content-mgmt/PluginFields.astro +29 -0
  82. package/dist/components/dashboard/islands/content-mgmt/TreeRenderer.astro +75 -0
  83. package/dist/components/dashboard/islands/content-mgmt/TreeSidebarFolder.astro +53 -0
  84. package/dist/components/dashboard/islands/content-mgmt/TreeSidebarLink.astro +51 -0
  85. package/dist/components/dashboard/islands/content-mgmt/runtime.d.ts +10 -0
  86. package/dist/components/dashboard/islands/content-mgmt/runtime.js +33 -0
  87. package/dist/components/dashboard/islands/content-mgmt/shared.d.ts +27 -0
  88. package/dist/components/dashboard/islands/content-mgmt/shared.js +31 -0
  89. package/dist/components/dashboard/islands/dashboard/DashboardGrid.astro +39 -0
  90. package/dist/components/dashboard/islands/dashboard/DashboardGridItem.astro +34 -0
  91. package/dist/components/dashboard/islands/dashboard/Test.astro +5 -0
  92. package/dist/components/dashboard/islands/dashboard/UserName.astro +6 -0
  93. package/dist/components/dashboard/islands/dashboard/shared.d.ts +2 -0
  94. package/dist/components/dashboard/islands/dashboard/shared.js +0 -0
  95. package/dist/components/dashboard/islands/plugins/SettingsRenderer.astro +29 -0
  96. package/dist/components/dashboard/islands/profile/APITokens.astro +306 -0
  97. package/dist/components/dashboard/islands/profile/BasicInfo.astro +140 -0
  98. package/dist/components/dashboard/islands/profile/BasicInfoFallback.astro +43 -0
  99. package/dist/components/dashboard/islands/profile/SocialSignin.astro +181 -0
  100. package/dist/components/dashboard/islands/profile/SocialSigninFallback.astro +83 -0
  101. package/dist/components/dashboard/islands/profile/UpdatePassword.astro +166 -0
  102. package/dist/components/dashboard/islands/profile/UpdatePasswordFallback.astro +47 -0
  103. package/dist/components/dashboard/islands/profile/oAuthButtonProviders.d.ts +8 -0
  104. package/dist/components/dashboard/islands/profile/oAuthButtonProviders.js +35 -0
  105. package/dist/components/dashboard/islands/sidebar/UserAccount.astro +23 -0
  106. package/dist/components/dashboard/islands/sidebar/VersionCheck.astro +127 -0
  107. package/dist/components/dashboard/islands/sidebar/VersionCheckChangelog.astro +107 -0
  108. package/dist/components/dashboard/islands/user-mgmt/InnerSidebarElement.astro +348 -0
  109. package/dist/components/dashboard/islands/user-mgmt/RankCheck.astro +49 -0
  110. package/dist/components/dashboard/islands/user-mgmt/SocialSignin.astro +109 -0
  111. package/dist/components/dashboard/islands/user-mgmt/UserListItem.astro +60 -0
  112. package/dist/components/dashboard/sidebar-modals/UserManagementModals.astro +103 -0
  113. package/dist/components/dashboard/sidebar-modals/VersionModal.astro +267 -0
  114. package/dist/components/dashboard/sidebarConfig.d.ts +32 -0
  115. package/dist/components/dashboard/sidebarConfig.js +88 -0
  116. package/dist/components/default-grid-items/Recently-created-pages.astro +91 -0
  117. package/dist/components/default-grid-items/Recently-signed-up.astro +71 -0
  118. package/dist/components/default-grid-items/Recently-updated-pages.astro +96 -0
  119. package/dist/components/default-grid-items/Totals.astro +107 -0
  120. package/dist/components/default-grid-items/utils.d.ts +17 -0
  121. package/dist/components/default-grid-items/utils.js +26 -0
  122. package/dist/components/image/CustomImage.astro +90 -0
  123. package/dist/components/user-quick-tools.d.ts +42 -0
  124. package/dist/components/user-quick-tools.js +312 -0
  125. package/dist/config.d.ts +3 -0
  126. package/dist/config.js +4 -0
  127. package/dist/consts.d.ts +61 -0
  128. package/dist/consts.js +39 -0
  129. package/dist/core.d.js +0 -0
  130. package/dist/core.d.ts +226 -0
  131. package/dist/db/config.d.ts +4 -0
  132. package/dist/db/config.js +6 -0
  133. package/dist/db/tables.js +168 -0
  134. package/dist/errors.d.ts +19 -0
  135. package/dist/errors.js +11 -0
  136. package/dist/index.d.ts +152 -0
  137. package/dist/index.js +1179 -0
  138. package/dist/layouts/auth/AuthLayout.astro +74 -0
  139. package/dist/layouts/auth/FallbackCanvas.astro +123 -0
  140. package/dist/layouts/auth/ThemeManager.astro +53 -0
  141. package/dist/layouts/auth/ThreeCanvasLoader.astro +18 -0
  142. package/dist/layouts/dashboard/Layout.astro +64 -0
  143. package/dist/lib/auth/encryption.d.ts +30 -0
  144. package/dist/lib/auth/encryption.js +39 -0
  145. package/dist/lib/auth/password.d.ts +27 -0
  146. package/dist/lib/auth/password.js +42 -0
  147. package/dist/lib/auth/rate-limit.d.ts +136 -0
  148. package/dist/lib/auth/rate-limit.js +214 -0
  149. package/dist/lib/auth/session.d.ts +85 -0
  150. package/dist/lib/auth/session.js +93 -0
  151. package/dist/lib/auth/types.d.ts +83 -0
  152. package/dist/lib/auth/types.js +0 -0
  153. package/dist/lib/auth/user.d.ts +148 -0
  154. package/dist/lib/auth/user.js +133 -0
  155. package/dist/lib/dashboardGrid.d.ts +119 -0
  156. package/dist/lib/dashboardGrid.js +0 -0
  157. package/dist/lib/dynamic-sitemap/index.d.ts +42 -0
  158. package/dist/lib/dynamic-sitemap/index.js +45 -0
  159. package/dist/lib/dynamic-sitemap/sitemap-index.xml.d.ts +8 -0
  160. package/dist/lib/dynamic-sitemap/sitemap-index.xml.js +20 -0
  161. package/dist/lib/dynamic-sitemap/sitemap-index.xml.ts +45 -0
  162. package/dist/lib/head.d.ts +9 -0
  163. package/dist/lib/head.js +65 -0
  164. package/dist/lib/headDefaults.d.ts +18 -0
  165. package/dist/lib/headDefaults.js +75 -0
  166. package/dist/lib/i18n/LanguageSelector.astro +114 -0
  167. package/dist/lib/i18n/client.d.ts +591 -0
  168. package/dist/lib/i18n/client.js +83 -0
  169. package/dist/lib/i18n/config.d.ts +16 -0
  170. package/dist/lib/i18n/config.js +8 -0
  171. package/dist/lib/i18n/index.d.ts +578 -0
  172. package/dist/lib/i18n/index.js +63 -0
  173. package/dist/lib/i18n/translations/de.json +64 -0
  174. package/dist/lib/i18n/translations/en-us.json +238 -0
  175. package/dist/lib/i18n/translations/es.json +64 -0
  176. package/dist/lib/i18n/translations/fr.json +64 -0
  177. package/dist/lib/index.d.ts +7 -0
  178. package/dist/lib/index.js +7 -0
  179. package/dist/lib/jsonUtils.d.ts +2 -0
  180. package/dist/lib/jsonUtils.js +11 -0
  181. package/dist/lib/makeAPIRoute.d.ts +45 -0
  182. package/dist/lib/makeAPIRoute.js +16 -0
  183. package/dist/lib/makePublicRoute.d.ts +7 -0
  184. package/dist/lib/makePublicRoute.js +6 -0
  185. package/dist/lib/pathGenerators.d.ts +20 -0
  186. package/dist/lib/pathGenerators.js +66 -0
  187. package/dist/lib/plugins/dashboard-pages.d.ts +71 -0
  188. package/dist/lib/plugins/dashboard-pages.js +11 -0
  189. package/dist/lib/plugins/frontend-navigation.d.ts +18 -0
  190. package/dist/lib/plugins/frontend-navigation.js +39 -0
  191. package/dist/lib/plugins/index.d.ts +2 -0
  192. package/dist/lib/plugins/index.js +2 -0
  193. package/dist/lib/removeLeadingTrailingSlashes.d.ts +7 -0
  194. package/dist/lib/removeLeadingTrailingSlashes.js +13 -0
  195. package/dist/lib/renderer/astro-remark.d.ts +13 -0
  196. package/dist/lib/renderer/astro-remark.js +11 -0
  197. package/dist/lib/renderer/contentRenderer.d.ts +13 -0
  198. package/dist/lib/renderer/contentRenderer.js +31 -0
  199. package/dist/lib/renderer/errors.d.ts +5 -0
  200. package/dist/lib/renderer/errors.js +25 -0
  201. package/dist/lib/renderer/markdoc-renderers/markdocHTML.d.ts +3 -0
  202. package/dist/lib/renderer/markdoc-renderers/markdocHTML.js +14 -0
  203. package/dist/lib/renderer/markdoc-renderers/markdocReactStatic.d.ts +3 -0
  204. package/dist/lib/renderer/markdoc-renderers/markdocReactStatic.js +14 -0
  205. package/dist/lib/renderer/markdoc.d.ts +11 -0
  206. package/dist/lib/renderer/markdoc.js +28 -0
  207. package/dist/lib/renderer/mdx.d.ts +10 -0
  208. package/dist/lib/renderer/mdx.js +37 -0
  209. package/dist/lib/renderer/runtime.d.ts +8 -0
  210. package/dist/lib/renderer/runtime.js +30 -0
  211. package/dist/lib/renderer/shared.d.ts +15 -0
  212. package/dist/lib/renderer/shared.js +13 -0
  213. package/dist/lib/renderer/studiocms.d.ts +11 -0
  214. package/dist/lib/renderer/studiocms.js +22 -0
  215. package/dist/lib/renderer/types.d.ts +12 -0
  216. package/dist/lib/renderer/types.js +0 -0
  217. package/dist/lib/robots/core.d.ts +24 -0
  218. package/dist/lib/robots/core.js +187 -0
  219. package/dist/lib/robots/index.d.ts +11 -0
  220. package/dist/lib/robots/index.js +47 -0
  221. package/dist/lib/robots/types.d.ts +185 -0
  222. package/dist/lib/robots/types.js +0 -0
  223. package/dist/lib/robots/utils.d.ts +22 -0
  224. package/dist/lib/robots/utils.js +22 -0
  225. package/dist/lib/routeMap.d.ts +257 -0
  226. package/dist/lib/routeMap.js +249 -0
  227. package/dist/lib/urlGen.d.ts +11 -0
  228. package/dist/lib/urlGen.js +26 -0
  229. package/dist/lib/webVitals/checkForWebVitalsPlugin.d.ts +18 -0
  230. package/dist/lib/webVitals/checkForWebVitalsPlugin.js +82 -0
  231. package/dist/lib/webVitals/consts.d.ts +240 -0
  232. package/dist/lib/webVitals/consts.js +40 -0
  233. package/dist/lib/webVitals/dashboard-grid-items/CoreVitals.astro +66 -0
  234. package/dist/lib/webVitals/dashboard-grid-items/MetricCard.astro +24 -0
  235. package/dist/lib/webVitals/dashboard-grid-items/SummaryCard.astro +56 -0
  236. package/dist/lib/webVitals/dashboard-grid-items/metric.css +103 -0
  237. package/dist/lib/webVitals/dashboard-grid-items/shared.d.ts +29 -0
  238. package/dist/lib/webVitals/dashboard-grid-items/shared.js +35 -0
  239. package/dist/lib/webVitals/pages/analytics/body.astro +186 -0
  240. package/dist/lib/webVitals/pages/analytics/header.astro +42 -0
  241. package/dist/lib/webVitals/schemas.d.ts +78 -0
  242. package/dist/lib/webVitals/schemas.js +37 -0
  243. package/dist/lib/webVitals/types.d.ts +156 -0
  244. package/dist/lib/webVitals/types.js +0 -0
  245. package/dist/lib/webVitals/utils/buildDataObject.d.ts +8 -0
  246. package/dist/lib/webVitals/utils/buildDataObject.js +28 -0
  247. package/dist/lib/webVitals/utils/buildPageRouteDataObject.d.ts +15 -0
  248. package/dist/lib/webVitals/utils/buildPageRouteDataObject.js +70 -0
  249. package/dist/lib/webVitals/utils/buildPerPageDataObject.d.ts +23 -0
  250. package/dist/lib/webVitals/utils/buildPerPageDataObject.js +209 -0
  251. package/dist/lib/webVitals/utils/checkDate.d.ts +5 -0
  252. package/dist/lib/webVitals/utils/checkDate.js +19 -0
  253. package/dist/lib/webVitals/utils/webVitalsUtils.d.ts +24 -0
  254. package/dist/lib/webVitals/utils/webVitalsUtils.js +234 -0
  255. package/dist/lib/webVitals/webVital.d.ts +20 -0
  256. package/dist/lib/webVitals/webVital.js +40 -0
  257. package/dist/lib/webVitals/webVitalsRouteSummary.d.ts +19 -0
  258. package/dist/lib/webVitals/webVitalsRouteSummary.js +59 -0
  259. package/dist/lib/webVitals/webVitalsSummary.d.ts +19 -0
  260. package/dist/lib/webVitals/webVitalsSummary.js +49 -0
  261. package/dist/plugins.d.ts +2 -0
  262. package/dist/plugins.js +6 -0
  263. package/dist/renderer.d.js +0 -0
  264. package/dist/renderer.d.ts +23 -0
  265. package/dist/routes/api/render.astro +25 -0
  266. package/dist/routes/auth/api/auth0/callback.d.ts +4 -0
  267. package/dist/routes/auth/api/auth0/callback.js +117 -0
  268. package/dist/routes/auth/api/auth0/index.d.ts +4 -0
  269. package/dist/routes/auth/api/auth0/index.js +36 -0
  270. package/dist/routes/auth/api/auth0/shared.d.ts +13 -0
  271. package/dist/routes/auth/api/auth0/shared.js +24 -0
  272. package/dist/routes/auth/api/discord/callback.d.ts +4 -0
  273. package/dist/routes/auth/api/discord/callback.js +112 -0
  274. package/dist/routes/auth/api/discord/index.d.ts +4 -0
  275. package/dist/routes/auth/api/discord/index.js +36 -0
  276. package/dist/routes/auth/api/discord/shared.d.ts +12 -0
  277. package/dist/routes/auth/api/discord/shared.js +17 -0
  278. package/dist/routes/auth/api/github/callback.d.ts +4 -0
  279. package/dist/routes/auth/api/github/callback.js +112 -0
  280. package/dist/routes/auth/api/github/index.d.ts +4 -0
  281. package/dist/routes/auth/api/github/index.js +36 -0
  282. package/dist/routes/auth/api/github/shared.d.ts +13 -0
  283. package/dist/routes/auth/api/github/shared.js +14 -0
  284. package/dist/routes/auth/api/google/callback.d.ts +4 -0
  285. package/dist/routes/auth/api/google/callback.js +115 -0
  286. package/dist/routes/auth/api/google/index.d.ts +4 -0
  287. package/dist/routes/auth/api/google/index.js +38 -0
  288. package/dist/routes/auth/api/google/shared.d.ts +12 -0
  289. package/dist/routes/auth/api/google/shared.js +19 -0
  290. package/dist/routes/auth/api/login.d.ts +4 -0
  291. package/dist/routes/auth/api/login.js +46 -0
  292. package/dist/routes/auth/api/logout.d.ts +5 -0
  293. package/dist/routes/auth/api/logout.js +55 -0
  294. package/dist/routes/auth/api/register.d.ts +4 -0
  295. package/dist/routes/auth/api/register.js +64 -0
  296. package/dist/routes/auth/api/shared.d.ts +2 -0
  297. package/dist/routes/auth/api/shared.js +21 -0
  298. package/dist/routes/auth/login.astro +118 -0
  299. package/dist/routes/auth/logout.astro +28 -0
  300. package/dist/routes/auth/signup.astro +124 -0
  301. package/dist/routes/dashboard/[...pluginPage].astro +88 -0
  302. package/dist/routes/dashboard/configuration.astro +61 -0
  303. package/dist/routes/dashboard/content-management/createfolder.astro +83 -0
  304. package/dist/routes/dashboard/content-management/createpage.astro +86 -0
  305. package/dist/routes/dashboard/content-management/diff.astro +135 -0
  306. package/dist/routes/dashboard/content-management/editfolder.astro +67 -0
  307. package/dist/routes/dashboard/content-management/editpage.astro +71 -0
  308. package/dist/routes/dashboard/content-management/index.astro +91 -0
  309. package/dist/routes/dashboard/index.astro +56 -0
  310. package/dist/routes/dashboard/password-reset.astro +206 -0
  311. package/dist/routes/dashboard/plugins/[plugin].astro +104 -0
  312. package/dist/routes/dashboard/profile.astro +87 -0
  313. package/dist/routes/dashboard/studiocms_api/dashboard/api-tokens.d.ts +5 -0
  314. package/dist/routes/dashboard/studiocms_api/dashboard/api-tokens.js +90 -0
  315. package/dist/routes/dashboard/studiocms_api/dashboard/config.d.ts +4 -0
  316. package/dist/routes/dashboard/studiocms_api/dashboard/config.js +63 -0
  317. package/dist/routes/dashboard/studiocms_api/dashboard/content/folder.d.ts +6 -0
  318. package/dist/routes/dashboard/studiocms_api/dashboard/content/folder.js +121 -0
  319. package/dist/routes/dashboard/studiocms_api/dashboard/content/page.d.ts +6 -0
  320. package/dist/routes/dashboard/studiocms_api/dashboard/content/page.js +258 -0
  321. package/dist/routes/dashboard/studiocms_api/dashboard/create-reset-link.d.ts +4 -0
  322. package/dist/routes/dashboard/studiocms_api/dashboard/create-reset-link.js +59 -0
  323. package/dist/routes/dashboard/studiocms_api/dashboard/create-user-invite.d.ts +4 -0
  324. package/dist/routes/dashboard/studiocms_api/dashboard/create-user-invite.js +105 -0
  325. package/dist/routes/dashboard/studiocms_api/dashboard/create-user.d.ts +4 -0
  326. package/dist/routes/dashboard/studiocms_api/dashboard/create-user.js +100 -0
  327. package/dist/routes/dashboard/studiocms_api/dashboard/partials/Editor.astro +61 -0
  328. package/dist/routes/dashboard/studiocms_api/dashboard/partials/LiveRender.astro +30 -0
  329. package/dist/routes/dashboard/studiocms_api/dashboard/partials/UserListItems.astro +39 -0
  330. package/dist/routes/dashboard/studiocms_api/dashboard/plugins/[plugin].d.ts +2 -0
  331. package/dist/routes/dashboard/studiocms_api/dashboard/plugins/[plugin].js +32 -0
  332. package/dist/routes/dashboard/studiocms_api/dashboard/profile.d.ts +4 -0
  333. package/dist/routes/dashboard/studiocms_api/dashboard/profile.js +130 -0
  334. package/dist/routes/dashboard/studiocms_api/dashboard/reset-password.d.ts +4 -0
  335. package/dist/routes/dashboard/studiocms_api/dashboard/reset-password.js +105 -0
  336. package/dist/routes/dashboard/studiocms_api/dashboard/search-list.d.ts +4 -0
  337. package/dist/routes/dashboard/studiocms_api/dashboard/search-list.js +55 -0
  338. package/dist/routes/dashboard/studiocms_api/dashboard/users.d.ts +5 -0
  339. package/dist/routes/dashboard/studiocms_api/dashboard/users.js +92 -0
  340. package/dist/routes/dashboard/studiocms_api/dashboard/verify-session.d.ts +2 -0
  341. package/dist/routes/dashboard/studiocms_api/dashboard/verify-session.js +72 -0
  342. package/dist/routes/dashboard/user-management/edit.astro +631 -0
  343. package/dist/routes/dashboard/user-management/index.astro +103 -0
  344. package/dist/routes/error-pages/404.astro +66 -0
  345. package/dist/routes/firstTimeSetupRoutes/1-start.astro +253 -0
  346. package/dist/routes/firstTimeSetupRoutes/2-next.astro +208 -0
  347. package/dist/routes/firstTimeSetupRoutes/3-done.astro +95 -0
  348. package/dist/routes/firstTimeSetupRoutes/api/step-1.d.ts +2 -0
  349. package/dist/routes/firstTimeSetupRoutes/api/step-1.js +126 -0
  350. package/dist/routes/firstTimeSetupRoutes/api/step-2.d.ts +2 -0
  351. package/dist/routes/firstTimeSetupRoutes/api/step-2.js +110 -0
  352. package/dist/routes/firstTimeSetupRoutes/components/Layout.astro +41 -0
  353. package/dist/routes/firstTimeSetupRoutes/components/PageHeader.astro +60 -0
  354. package/dist/routes/firstTimeSetupRoutes/components/TabItem.astro +44 -0
  355. package/dist/routes/firstTimeSetupRoutes/components/Tabs.astro +170 -0
  356. package/dist/routes/firstTimeSetupRoutes/snippets/opt1-astro.config.diff +14 -0
  357. package/dist/routes/firstTimeSetupRoutes/snippets/opt2-astro.config.diff +9 -0
  358. package/dist/routes/firstTimeSetupRoutes/snippets/opt2-studiocms.config.diff +5 -0
  359. package/dist/routes/rest/utils/auth-token.d.ts +17 -0
  360. package/dist/routes/rest/utils/auth-token.js +31 -0
  361. package/dist/routes/rest/v1/folders/[id].d.ts +6 -0
  362. package/dist/routes/rest/v1/folders/[id].js +106 -0
  363. package/dist/routes/rest/v1/folders/index.d.ts +5 -0
  364. package/dist/routes/rest/v1/folders/index.js +88 -0
  365. package/dist/routes/rest/v1/pages/[id]/history/[diffid].d.ts +4 -0
  366. package/dist/routes/rest/v1/pages/[id]/history/[diffid].js +55 -0
  367. package/dist/routes/rest/v1/pages/[id]/history/index.d.ts +4 -0
  368. package/dist/routes/rest/v1/pages/[id]/history/index.js +61 -0
  369. package/dist/routes/rest/v1/pages/[id]/index.d.ts +6 -0
  370. package/dist/routes/rest/v1/pages/[id]/index.js +165 -0
  371. package/dist/routes/rest/v1/pages/index.d.ts +5 -0
  372. package/dist/routes/rest/v1/pages/index.js +113 -0
  373. package/dist/routes/rest/v1/public/folders/[id].d.ts +4 -0
  374. package/dist/routes/rest/v1/public/folders/[id].js +43 -0
  375. package/dist/routes/rest/v1/public/folders/index.d.ts +4 -0
  376. package/dist/routes/rest/v1/public/folders/index.js +49 -0
  377. package/dist/routes/rest/v1/public/pages/[id].d.ts +4 -0
  378. package/dist/routes/rest/v1/public/pages/[id].js +46 -0
  379. package/dist/routes/rest/v1/public/pages/index.d.ts +4 -0
  380. package/dist/routes/rest/v1/public/pages/index.js +61 -0
  381. package/dist/routes/rest/v1/settings/index.d.ts +5 -0
  382. package/dist/routes/rest/v1/settings/index.js +75 -0
  383. package/dist/routes/rest/v1/users/[id].d.ts +6 -0
  384. package/dist/routes/rest/v1/users/[id].js +212 -0
  385. package/dist/routes/rest/v1/users/index.d.ts +5 -0
  386. package/dist/routes/rest/v1/users/index.js +138 -0
  387. package/dist/routes/sdk/fallback-list-pages.json.d.ts +2 -0
  388. package/dist/routes/sdk/fallback-list-pages.json.js +19 -0
  389. package/dist/routes/sdk/fallback-list-pages.json.ts +22 -0
  390. package/dist/routes/sdk/full-changelog.json.d.ts +16 -0
  391. package/dist/routes/sdk/full-changelog.json.js +170 -0
  392. package/dist/routes/sdk/full-changelog.json.ts +224 -0
  393. package/dist/routes/sdk/list-pages.d.ts +4 -0
  394. package/dist/routes/sdk/list-pages.js +34 -0
  395. package/dist/routes/sdk/update-latest-version-cache.d.ts +4 -0
  396. package/dist/routes/sdk/update-latest-version-cache.js +41 -0
  397. package/dist/runtime/AstroComponentProxy.d.ts +29 -0
  398. package/dist/runtime/AstroComponentProxy.js +47 -0
  399. package/dist/runtime/decoder/decode-codepoint.d.ts +18 -0
  400. package/dist/runtime/decoder/decode-codepoint.js +58 -0
  401. package/dist/runtime/decoder/decode-data-html.d.ts +1 -0
  402. package/dist/runtime/decoder/decode-data-html.js +7 -0
  403. package/dist/runtime/decoder/decode-data-xml.d.ts +1 -0
  404. package/dist/runtime/decoder/decode-data-xml.js +7 -0
  405. package/dist/runtime/decoder/index.d.ts +34 -0
  406. package/dist/runtime/decoder/index.js +18 -0
  407. package/dist/runtime/decoder/util.d.ts +208 -0
  408. package/dist/runtime/decoder/util.js +415 -0
  409. package/dist/schemas/config/auth.d.ts +175 -0
  410. package/dist/schemas/config/auth.js +65 -0
  411. package/dist/schemas/config/componentoverrides.d.ts +17 -0
  412. package/dist/schemas/config/componentoverrides.js +14 -0
  413. package/dist/schemas/config/dashboard.d.ts +154 -0
  414. package/dist/schemas/config/dashboard.js +59 -0
  415. package/dist/schemas/config/defaultFrontend.d.ts +125 -0
  416. package/dist/schemas/config/defaultFrontend.js +57 -0
  417. package/dist/schemas/config/developer.d.ts +15 -0
  418. package/dist/schemas/config/developer.js +14 -0
  419. package/dist/schemas/config/imageService.d.ts +13 -0
  420. package/dist/schemas/config/imageService.js +12 -0
  421. package/dist/schemas/config/index.d.ts +1153 -0
  422. package/dist/schemas/config/index.js +95 -0
  423. package/dist/schemas/config/integrations.d.ts +14 -0
  424. package/dist/schemas/config/integrations.js +12 -0
  425. package/dist/schemas/config/markdoc.d.ts +172 -0
  426. package/dist/schemas/config/markdoc.js +68 -0
  427. package/dist/schemas/config/mdx.d.ts +455 -0
  428. package/dist/schemas/config/mdx.js +71 -0
  429. package/dist/schemas/config/rendererConfig.d.ts +659 -0
  430. package/dist/schemas/config/rendererConfig.js +51 -0
  431. package/dist/schemas/config/sdk.d.ts +167 -0
  432. package/dist/schemas/config/sdk.js +85 -0
  433. package/dist/schemas/config/studiocms-markdown-remark.d.ts +292 -0
  434. package/dist/schemas/config/studiocms-markdown-remark.js +63 -0
  435. package/dist/schemas/index.d.ts +2 -0
  436. package/dist/schemas/index.js +2 -0
  437. package/dist/schemas/plugins/index.d.ts +7373 -0
  438. package/dist/schemas/plugins/index.js +192 -0
  439. package/dist/schemas/plugins/shared.d.ts +1752 -0
  440. package/dist/schemas/plugins/shared.js +221 -0
  441. package/dist/scripts/formListener.d.ts +16 -0
  442. package/dist/scripts/formListener.js +46 -0
  443. package/dist/scripts/three.d.ts +1 -0
  444. package/dist/scripts/three.js +278 -0
  445. package/dist/scripts/utils/fitModelToViewport.d.ts +8 -0
  446. package/dist/scripts/utils/fitModelToViewport.js +19 -0
  447. package/dist/sdk/StudioCMSVirtualCache.d.ts +283 -0
  448. package/dist/sdk/StudioCMSVirtualCache.js +685 -0
  449. package/dist/sdk/cache.d.ts +11 -0
  450. package/dist/sdk/cache.js +12 -0
  451. package/dist/sdk/core.d.ts +865 -0
  452. package/dist/sdk/core.js +1966 -0
  453. package/dist/sdk/errors.d.ts +21 -0
  454. package/dist/sdk/errors.js +11 -0
  455. package/dist/sdk/index.d.ts +371 -0
  456. package/dist/sdk/index.js +8 -0
  457. package/dist/sdk/lib/foldertree.d.ts +50 -0
  458. package/dist/sdk/lib/foldertree.js +123 -0
  459. package/dist/sdk/lib/generators.d.ts +30 -0
  460. package/dist/sdk/lib/generators.js +25 -0
  461. package/dist/sdk/lib/packages.d.ts +8 -0
  462. package/dist/sdk/lib/packages.js +14 -0
  463. package/dist/sdk/lib/parsers.d.ts +14 -0
  464. package/dist/sdk/lib/parsers.js +10 -0
  465. package/dist/sdk/lib/users.d.ts +19 -0
  466. package/dist/sdk/lib/users.js +26 -0
  467. package/dist/sdk/tables.d.ts +1198 -0
  468. package/dist/sdk/tables.js +55 -0
  469. package/dist/sdk/types/index.d.ts +175 -0
  470. package/dist/sdk/types/index.js +0 -0
  471. package/dist/sdk/types/tableDefs.d.ts +75 -0
  472. package/dist/sdk/types/tableDefs.js +0 -0
  473. package/dist/sdk/types/tsAlias.d.ts +155 -0
  474. package/dist/sdk/types/tsAlias.js +0 -0
  475. package/dist/sdk/utils/db.d.ts +5 -0
  476. package/dist/sdk/utils/db.js +15 -0
  477. package/dist/stubs/auth-lib.d.ts +2 -0
  478. package/dist/stubs/auth-lib.js +519 -0
  479. package/dist/stubs/auth-scripts.d.ts +2 -0
  480. package/dist/stubs/auth-scripts.js +29 -0
  481. package/dist/stubs/auth-utils.d.ts +2 -0
  482. package/dist/stubs/auth-utils.js +36 -0
  483. package/dist/stubs/changelog.d.ts +2 -0
  484. package/dist/stubs/changelog.js +16 -0
  485. package/dist/stubs/components.d.ts +2 -0
  486. package/dist/stubs/components.js +67 -0
  487. package/dist/stubs/core.d.ts +2 -0
  488. package/dist/stubs/core.js +49 -0
  489. package/dist/stubs/i18n-dts.d.ts +2 -0
  490. package/dist/stubs/i18n-dts.js +117 -0
  491. package/dist/stubs/images.d.ts +1 -0
  492. package/dist/stubs/images.js +30 -0
  493. package/dist/stubs/index.d.ts +1 -0
  494. package/dist/stubs/index.js +40 -0
  495. package/dist/stubs/lib.d.ts +2 -0
  496. package/dist/stubs/lib.js +123 -0
  497. package/dist/stubs/plugins.d.ts +2 -0
  498. package/dist/stubs/plugins.js +60 -0
  499. package/dist/stubs/proxy.d.ts +2 -0
  500. package/dist/stubs/proxy.js +40 -0
  501. package/dist/stubs/renderer-config.d.ts +2 -0
  502. package/dist/stubs/renderer-config.js +18 -0
  503. package/dist/stubs/renderer-markdownConfig.d.ts +2 -0
  504. package/dist/stubs/renderer-markdownConfig.js +17 -0
  505. package/dist/stubs/renderer.d.ts +2 -0
  506. package/dist/stubs/renderer.js +44 -0
  507. package/dist/stubs/sdk.d.ts +2 -0
  508. package/dist/stubs/sdk.js +202 -0
  509. package/dist/stubs/webVitals.d.ts +2 -0
  510. package/dist/stubs/webVitals.js +40 -0
  511. package/dist/styles/404.css +47 -0
  512. package/dist/styles/SyntaxFont.woff2 +0 -0
  513. package/dist/styles/authlayout.css +138 -0
  514. package/dist/styles/dashboard-base.css +493 -0
  515. package/dist/styles/dashboard-code.css +33 -0
  516. package/dist/styles/dashboard-diff.css +389 -0
  517. package/dist/styles/dashboard-tiny-mde.css +224 -0
  518. package/dist/styles/md-remark-callouts/github.css +56 -0
  519. package/dist/styles/md-remark-callouts/obsidian.css +66 -0
  520. package/dist/styles/md-remark-callouts/vitepress.css +58 -0
  521. package/dist/styles/md-remark-headings.css +48 -0
  522. package/dist/types.d.ts +43 -0
  523. package/dist/types.js +0 -0
  524. package/dist/utils/addAPIRoutes.d.ts +9 -0
  525. package/dist/utils/addAPIRoutes.js +33 -0
  526. package/dist/utils/addIntegrationArray.d.ts +24 -0
  527. package/dist/utils/addIntegrationArray.js +11 -0
  528. package/dist/utils/addIntegrationArrayWithCheck.d.ts +11 -0
  529. package/dist/utils/addIntegrationArrayWithCheck.js +24 -0
  530. package/dist/utils/astroConfigCheck.d.ts +8 -0
  531. package/dist/utils/astroConfigCheck.js +31 -0
  532. package/dist/utils/astroEnvConfig.d.ts +45 -0
  533. package/dist/utils/astroEnvConfig.js +9 -0
  534. package/dist/utils/authEnvCheck.d.ts +38 -0
  535. package/dist/utils/authEnvCheck.js +82 -0
  536. package/dist/utils/changelog.d.ts +1 -0
  537. package/dist/utils/changelog.js +53 -0
  538. package/dist/utils/changelogLoader.d.ts +15 -0
  539. package/dist/utils/changelogLoader.js +104 -0
  540. package/dist/utils/checkENV.d.ts +27 -0
  541. package/dist/utils/checkENV.js +115 -0
  542. package/dist/utils/configManager.d.ts +22 -0
  543. package/dist/utils/configManager.js +98 -0
  544. package/dist/utils/configResolver.d.ts +283 -0
  545. package/dist/utils/configResolver.js +105 -0
  546. package/dist/utils/defineStudioCMSConfig.d.ts +165 -0
  547. package/dist/utils/defineStudioCMSConfig.js +6 -0
  548. package/dist/utils/getLabelForPermissionLevel.d.ts +2 -0
  549. package/dist/utils/getLabelForPermissionLevel.js +17 -0
  550. package/dist/utils/injectRouteArray.d.ts +19 -0
  551. package/dist/utils/injectRouteArray.js +75 -0
  552. package/dist/utils/integrationLogger.d.ts +7 -0
  553. package/dist/utils/integrationLogger.js +18 -0
  554. package/dist/utils/integrations.d.ts +4 -0
  555. package/dist/utils/integrations.js +32 -0
  556. package/dist/utils/isDashboardRoute.d.ts +7 -0
  557. package/dist/utils/isDashboardRoute.js +10 -0
  558. package/dist/utils/loginBackgrounds/studiocms-blobs-dark.png +0 -0
  559. package/dist/utils/loginBackgrounds/studiocms-blobs-light.png +0 -0
  560. package/dist/utils/loginBackgrounds/studiocms-blocks-dark.png +0 -0
  561. package/dist/utils/loginBackgrounds/studiocms-blocks-light.png +0 -0
  562. package/dist/utils/loginBackgrounds/studiocms-curves-dark.png +0 -0
  563. package/dist/utils/loginBackgrounds/studiocms-curves-light.png +0 -0
  564. package/dist/utils/makePageTitle.d.ts +3 -0
  565. package/dist/utils/makePageTitle.js +7 -0
  566. package/dist/utils/pageListPackageLabel.d.ts +4 -0
  567. package/dist/utils/pageListPackageLabel.js +12 -0
  568. package/dist/utils/readJson.d.ts +1 -0
  569. package/dist/utils/readJson.js +7 -0
  570. package/dist/utils/routeBuilder.d.ts +18 -0
  571. package/dist/utils/routeBuilder.js +96 -0
  572. package/dist/utils/safeString.d.ts +1 -0
  573. package/dist/utils/safeString.js +6 -0
  574. package/dist/utils/simpleResponse.d.ts +1 -0
  575. package/dist/utils/simpleResponse.js +29 -0
  576. package/dist/utils/validImages.d.ts +13 -0
  577. package/dist/utils/validImages.js +39 -0
  578. package/dist/virtual.d.js +0 -0
  579. package/dist/virtual.d.ts +9 -0
  580. package/package.json +219 -0
  581. package/studiocms-cli.mjs +13 -0
  582. package/ui.d.ts +291 -0
@@ -0,0 +1,1966 @@
1
+ import { createTwoFilesPatch } from "diff";
2
+ import { html } from "diff2html";
3
+ import { and, asc, desc, eq } from "drizzle-orm";
4
+ import { CMSSiteConfigId, GhostUserDefaults } from "../consts.js";
5
+ import { StudioCMS_SDK_Error } from "./errors.js";
6
+ import {
7
+ addPageToFolderTree,
8
+ findNodeById,
9
+ findNodeByPath,
10
+ findNodesAlongPath,
11
+ findNodesAlongPathToId,
12
+ generateFolderTree,
13
+ getFullPath
14
+ } from "./lib/foldertree.js";
15
+ import {
16
+ generateRandomIDNumber,
17
+ generateRandomPassword,
18
+ generateToken,
19
+ testToken
20
+ } from "./lib/generators.js";
21
+ import { parseIdNumberArray, parseIdStringArray } from "./lib/parsers.js";
22
+ import { combineRanks, verifyRank } from "./lib/users.js";
23
+ import {
24
+ tsAPIKeys,
25
+ tsDiffTracking,
26
+ tsOAuthAccounts,
27
+ tsPageContent,
28
+ tsPageData,
29
+ tsPageDataCategories,
30
+ tsPageDataTags,
31
+ tsPageFolderStructure,
32
+ tsPermissions,
33
+ tsSessionTable,
34
+ tsSiteConfig,
35
+ tsUserResetTokens,
36
+ tsUsers
37
+ } from "./tables.js";
38
+ import { useDB } from "./utils/db.js";
39
+ const db = useDB();
40
+ function studiocmsSDKCore() {
41
+ async function buildFolderTree() {
42
+ const currentFolders = await db.select().from(tsPageFolderStructure);
43
+ return generateFolderTree(currentFolders);
44
+ }
45
+ async function getAvailableFolders() {
46
+ const folders = [];
47
+ const currentFolders = await db.select().from(tsPageFolderStructure);
48
+ for (const current of currentFolders) {
49
+ folders.push(current);
50
+ }
51
+ return folders;
52
+ }
53
+ async function clearUserReferences(userId) {
54
+ try {
55
+ await db.batch([
56
+ db.delete(tsUserResetTokens).where(eq(tsUserResetTokens.userId, userId)),
57
+ db.delete(tsPermissions).where(eq(tsPermissions.user, userId)),
58
+ db.delete(tsOAuthAccounts).where(eq(tsOAuthAccounts.userId, userId)),
59
+ db.delete(tsSessionTable).where(eq(tsSessionTable.userId, userId)),
60
+ db.update(tsDiffTracking).set({ userId: GhostUserDefaults.id }).where(eq(tsDiffTracking.userId, userId)),
61
+ db.update(tsPageData).set({ authorId: GhostUserDefaults.id }).where(eq(tsPageData.authorId, userId))
62
+ ]);
63
+ return true;
64
+ } catch (error) {
65
+ if (error instanceof Error) {
66
+ throw new StudioCMS_SDK_Error(
67
+ `Error clearing user references: ${error.message}`,
68
+ error.stack
69
+ );
70
+ }
71
+ throw new StudioCMS_SDK_Error("Error clearing user references: An unknown error occurred.");
72
+ }
73
+ }
74
+ async function collectCategories(categoryIds) {
75
+ try {
76
+ const categories = [];
77
+ if (categoryIds.length > 0) {
78
+ const [categoryHead, ...categoryTail] = categoryIds.map(
79
+ (id) => db.select().from(tsPageDataCategories).where(eq(tsPageDataCategories.id, id))
80
+ );
81
+ if (categoryHead) {
82
+ const categoryResults = await db.batch([categoryHead, ...categoryTail]);
83
+ categories.push(...categoryResults.flat().filter((result) => result !== void 0));
84
+ }
85
+ }
86
+ return categories;
87
+ } catch (error) {
88
+ if (error instanceof Error) {
89
+ throw new StudioCMS_SDK_Error(`Error getting categories: ${error.message}`, error.stack);
90
+ }
91
+ throw new StudioCMS_SDK_Error("Error getting categories: An unknown error occurred.");
92
+ }
93
+ }
94
+ async function collectTags(tagIds) {
95
+ try {
96
+ const tags = [];
97
+ const [tagHead, ...tagTail] = tagIds.map(
98
+ (id) => db.select().from(tsPageDataTags).where(eq(tsPageDataTags.id, id))
99
+ );
100
+ if (tagHead) {
101
+ const tagResults = await db.batch([tagHead, ...tagTail]);
102
+ tags.push(...tagResults.flat().filter((result) => result !== void 0));
103
+ }
104
+ return tags;
105
+ } catch (error) {
106
+ if (error instanceof Error) {
107
+ throw new StudioCMS_SDK_Error(`Error getting tags: ${error.message}`, error.stack);
108
+ }
109
+ throw new StudioCMS_SDK_Error("Error getting tags: An unknown error occurred.");
110
+ }
111
+ }
112
+ async function collectPageData(page, tree) {
113
+ try {
114
+ const categoryIds = parseIdNumberArray(page.categories || []);
115
+ const categories = await collectCategories(categoryIds);
116
+ const tagIds = parseIdNumberArray(page.tags || []);
117
+ const tags = await collectTags(tagIds);
118
+ const contributorIds = parseIdStringArray(page.contributorIds || []);
119
+ const multiLanguageContentData = await db.select().from(tsPageContent).where(eq(tsPageContent.contentId, page.id));
120
+ const defaultLanguageContentData = multiLanguageContentData.find(
121
+ (content) => content.contentLang === page.contentLang
122
+ );
123
+ const safeSlug = page.slug === "index" ? "/" : `/${page.slug}`;
124
+ let urlRoute = safeSlug;
125
+ if (page.parentFolder) {
126
+ const urlParts = findNodesAlongPathToId(tree, page.parentFolder);
127
+ urlRoute = urlParts.map((part) => part.name).join("/") + safeSlug;
128
+ }
129
+ return {
130
+ ...page,
131
+ urlRoute,
132
+ categories,
133
+ tags,
134
+ contributorIds,
135
+ multiLangContent: multiLanguageContentData,
136
+ defaultContent: defaultLanguageContentData
137
+ };
138
+ } catch (error) {
139
+ if (error instanceof Error) {
140
+ throw new StudioCMS_SDK_Error(`Error collecting page data: ${error.message}`, error.stack);
141
+ }
142
+ throw new StudioCMS_SDK_Error("Error collecting page data: An unknown error occurred.");
143
+ }
144
+ }
145
+ async function collectUserData(user) {
146
+ try {
147
+ const [oAuthData, permissionData] = await db.batch([
148
+ db.select().from(tsOAuthAccounts).where(eq(tsOAuthAccounts.userId, user.id)),
149
+ db.select().from(tsPermissions).where(eq(tsPermissions.user, user.id))
150
+ ]);
151
+ return {
152
+ ...user,
153
+ oAuthData,
154
+ permissionsData: permissionData[0]
155
+ };
156
+ } catch (error) {
157
+ if (error instanceof Error) {
158
+ throw new StudioCMS_SDK_Error(`Error collecting user data: ${error.message}`, error.stack);
159
+ }
160
+ throw new StudioCMS_SDK_Error("Error collecting user data: An unknown error occurred.");
161
+ }
162
+ }
163
+ const resetTokenBucket = {
164
+ new: async (userId) => {
165
+ const token = generateToken(userId);
166
+ return await db.insert(tsUserResetTokens).values({ id: crypto.randomUUID(), userId, token }).returning().get();
167
+ },
168
+ delete: async (userId) => {
169
+ await db.delete(tsUserResetTokens).where(eq(tsUserResetTokens.userId, userId));
170
+ },
171
+ check: async (token) => {
172
+ const _token = testToken(token);
173
+ const resetToken = await db.select().from(tsUserResetTokens).where(eq(tsUserResetTokens.userId, _token.userId)).get();
174
+ if (!resetToken) {
175
+ return false;
176
+ }
177
+ return resetToken.token === token;
178
+ }
179
+ };
180
+ async function checkDiffsLengthAndRemoveOldestIfToLong(pageId, length) {
181
+ const diffs = await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.pageId, pageId)).orderBy(asc(tsDiffTracking.timestamp));
182
+ if (diffs.length > length) {
183
+ const oldestDiff = diffs[0];
184
+ await db.delete(tsDiffTracking).where(eq(tsDiffTracking.id, oldestDiff.id));
185
+ }
186
+ }
187
+ const REST_API = {
188
+ tokens: {
189
+ get: async (userId) => {
190
+ return await db.select().from(tsAPIKeys).where(eq(tsAPIKeys.userId, userId));
191
+ },
192
+ new: async (userId, description) => {
193
+ const key = generateToken(userId);
194
+ return await db.insert(tsAPIKeys).values({
195
+ id: crypto.randomUUID(),
196
+ creationDate: /* @__PURE__ */ new Date(),
197
+ userId,
198
+ key,
199
+ description
200
+ }).returning().get();
201
+ },
202
+ delete: async (userId, tokenId) => {
203
+ await db.delete(tsAPIKeys).where(and(eq(tsAPIKeys.userId, userId), eq(tsAPIKeys.id, tokenId)));
204
+ },
205
+ verify: async (key) => {
206
+ const apiKey = await db.select().from(tsAPIKeys).where(eq(tsAPIKeys.key, key)).get();
207
+ if (!apiKey) {
208
+ return false;
209
+ }
210
+ const keyRank = await db.select().from(tsPermissions).where(eq(tsPermissions.user, apiKey.userId)).get();
211
+ if (!keyRank) {
212
+ return false;
213
+ }
214
+ return {
215
+ userId: apiKey.userId,
216
+ key: apiKey.key,
217
+ rank: keyRank.rank
218
+ };
219
+ }
220
+ }
221
+ };
222
+ const diffTracking = {
223
+ insert: async (userId, pageId, data, diffLength) => {
224
+ const diff = createTwoFilesPatch("Content", "Content", data.content.start, data.content.end);
225
+ await checkDiffsLengthAndRemoveOldestIfToLong(pageId, diffLength);
226
+ return await db.insert(tsDiffTracking).values({
227
+ id: crypto.randomUUID(),
228
+ userId,
229
+ pageId,
230
+ diff,
231
+ timestamp: /* @__PURE__ */ new Date(),
232
+ pageContentStart: data.content.start,
233
+ pageMetaData: JSON.stringify(data.metaData)
234
+ }).returning().get();
235
+ },
236
+ clear: async (pageId) => {
237
+ await db.delete(tsDiffTracking).where(eq(tsDiffTracking.pageId, pageId));
238
+ },
239
+ get: {
240
+ byPageId: {
241
+ all: async (pageId) => {
242
+ return await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.pageId, pageId)).orderBy(desc(tsDiffTracking.timestamp));
243
+ },
244
+ latest: async (pageId, count) => {
245
+ const diffs = await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.pageId, pageId)).orderBy(desc(tsDiffTracking.timestamp));
246
+ return diffs.slice(0, count);
247
+ }
248
+ },
249
+ byUserId: {
250
+ all: async (userId) => {
251
+ return await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.userId, userId)).orderBy(desc(tsDiffTracking.timestamp));
252
+ },
253
+ latest: async (userId, count) => {
254
+ const diffs = await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.userId, userId)).orderBy(desc(tsDiffTracking.timestamp));
255
+ return diffs.slice(0, count);
256
+ }
257
+ },
258
+ single: async (id) => {
259
+ return await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.id, id)).get();
260
+ },
261
+ withHtml: async (id, options) => {
262
+ const diffEntry = await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.id, id)).get();
263
+ if (!diffEntry) {
264
+ throw new StudioCMS_SDK_Error("Diff not found");
265
+ }
266
+ if (!diffEntry.diff) {
267
+ throw new StudioCMS_SDK_Error("Diff not found");
268
+ }
269
+ const contentDiffHtml = html(diffEntry.diff, {
270
+ diffStyle: "word",
271
+ matching: "lines",
272
+ drawFileList: false,
273
+ outputFormat: "side-by-side",
274
+ ...options
275
+ });
276
+ const diff = createTwoFilesPatch(
277
+ "Metadata",
278
+ "Metadata",
279
+ JSON.stringify(JSON.parse(diffEntry.pageMetaData).start, null, 2),
280
+ JSON.stringify(JSON.parse(diffEntry.pageMetaData).end, null, 2)
281
+ );
282
+ const metadataDiffHtml = html(diff, {
283
+ diffStyle: "word",
284
+ matching: "lines",
285
+ drawFileList: false,
286
+ outputFormat: "side-by-side",
287
+ ...options
288
+ });
289
+ return {
290
+ ...diffEntry,
291
+ metadataDiffHtml,
292
+ contentDiffHtml
293
+ };
294
+ }
295
+ },
296
+ revertToDiff: async (id, type) => {
297
+ const diffEntry = await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.id, id)).get();
298
+ if (!diffEntry) {
299
+ throw new StudioCMS_SDK_Error("Diff not found");
300
+ }
301
+ const shouldRevertData = type === "data" || type === "both";
302
+ const shouldRevertContent = type === "content" || type === "both";
303
+ if (shouldRevertData) {
304
+ const pageData = JSON.parse(diffEntry.pageMetaData);
305
+ await db.update(tsPageData).set(pageData.start).where(eq(tsPageData.id, pageData.end.id));
306
+ }
307
+ if (shouldRevertContent) {
308
+ await db.update(tsPageContent).set({ content: diffEntry.pageContentStart }).where(eq(tsPageContent.contentId, diffEntry.pageId));
309
+ }
310
+ const allDiffs = await db.select().from(tsDiffTracking).where(eq(tsDiffTracking.pageId, diffEntry.pageId)).orderBy(desc(tsDiffTracking.timestamp));
311
+ const diffIndex = allDiffs.findIndex((diff) => diff.id === id);
312
+ const diffsToPurge = allDiffs.slice(diffIndex + 1);
313
+ for (const diff of diffsToPurge) {
314
+ await db.delete(tsDiffTracking).where(eq(tsDiffTracking.id, diff.id));
315
+ }
316
+ return diffEntry;
317
+ }
318
+ };
319
+ const AUTH = {
320
+ /**
321
+ * Provides various methods to create, delete, and search for OAuth accounts in the StudioCMS database.
322
+ */
323
+ oAuth: {
324
+ /**
325
+ * Creates a new OAuth account in the database.
326
+ *
327
+ * @param data - The data to insert into the OAuth account table.
328
+ * @returns A promise that resolves to the inserted OAuth account.
329
+ * @throws {StudioCMS_SDK_Error} If an error occurs while creating the OAuth account.
330
+ */
331
+ create: async (data) => {
332
+ try {
333
+ return await db.insert(tsOAuthAccounts).values(data).returning().get();
334
+ } catch (error) {
335
+ if (error instanceof Error) {
336
+ throw new StudioCMS_SDK_Error(
337
+ `Error creating OAuth account: ${error.message}`,
338
+ error.stack
339
+ );
340
+ }
341
+ throw new StudioCMS_SDK_Error("Error creating OAuth account: An unknown error occurred.");
342
+ }
343
+ },
344
+ /**
345
+ * Deletes an OAuth account from the database.
346
+ *
347
+ * @param userId - The ID of the user associated with the OAuth account.
348
+ * @param provider - The provider of the OAuth account.
349
+ * @returns A promise that resolves to a deletion response.
350
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the OAuth account.
351
+ */
352
+ delete: async (userId, provider) => {
353
+ try {
354
+ return await db.delete(tsOAuthAccounts).where(and(eq(tsOAuthAccounts.userId, userId), eq(tsOAuthAccounts.provider, provider))).then(() => {
355
+ return {
356
+ status: "success",
357
+ message: "OAuth account deleted"
358
+ };
359
+ });
360
+ } catch (error) {
361
+ if (error instanceof Error) {
362
+ throw new StudioCMS_SDK_Error(
363
+ `Error deleting OAuth account: ${error.message}`,
364
+ error.stack
365
+ );
366
+ }
367
+ throw new StudioCMS_SDK_Error("Error deleting OAuth account: An unknown error occurred.");
368
+ }
369
+ },
370
+ /**
371
+ * Searches for OAuth accounts based on the provider ID and user ID.
372
+ *
373
+ * @param providerId - The provider ID to search for.
374
+ * @param userId - The user ID to search for.
375
+ * @returns A promise that resolves to the OAuth account data if found, otherwise undefined.
376
+ * @throws {StudioCMS_SDK_Error} If an error occurs while searching for the OAuth account.
377
+ */
378
+ searchProvidersForId: async (providerId, userId) => {
379
+ try {
380
+ return await db.select().from(tsOAuthAccounts).where(
381
+ and(
382
+ eq(tsOAuthAccounts.providerUserId, providerId),
383
+ eq(tsOAuthAccounts.userId, userId)
384
+ )
385
+ ).get();
386
+ } catch (error) {
387
+ if (error instanceof Error) {
388
+ throw new StudioCMS_SDK_Error(
389
+ `Error searching for OAuth account: ${error.message}`,
390
+ error.stack
391
+ );
392
+ }
393
+ throw new StudioCMS_SDK_Error(
394
+ "Error searching for OAuth account: An unknown error occurred."
395
+ );
396
+ }
397
+ }
398
+ },
399
+ /**
400
+ * Provides various methods to get and update permissions for users in the StudioCMS database.
401
+ */
402
+ permission: {
403
+ /**
404
+ * Checks the current status of a user's permissions.
405
+ */
406
+ currentStatus: async (userId) => {
407
+ try {
408
+ return await db.select().from(tsPermissions).where(eq(tsPermissions.user, userId)).get();
409
+ } catch (error) {
410
+ if (error instanceof Error) {
411
+ throw new StudioCMS_SDK_Error(
412
+ `Error getting user permissions: ${error.message}`,
413
+ error.stack
414
+ );
415
+ }
416
+ throw new StudioCMS_SDK_Error(
417
+ "Error getting user permissions: An unknown error occurred."
418
+ );
419
+ }
420
+ }
421
+ },
422
+ /**
423
+ * Provides various methods to create, delete, and update sessions in the StudioCMS database.
424
+ */
425
+ session: {
426
+ /**
427
+ * Creates a new session in the database.
428
+ *
429
+ * @param data - The data to insert into the session table.
430
+ * @returns A promise that resolves to the inserted session.
431
+ * @throws {StudioCMS_SDK_Error} If an error occurs while creating the session.
432
+ */
433
+ create: async (data) => {
434
+ try {
435
+ return await db.insert(tsSessionTable).values(data).returning({
436
+ id: tsSessionTable.id,
437
+ userId: tsSessionTable.userId,
438
+ expiresAt: tsSessionTable.expiresAt
439
+ }).get();
440
+ } catch (error) {
441
+ if (error instanceof Error) {
442
+ throw new StudioCMS_SDK_Error(`Error creating session: ${error.message}`, error.stack);
443
+ }
444
+ throw new StudioCMS_SDK_Error("Error creating session: An unknown error occurred.");
445
+ }
446
+ },
447
+ /**
448
+ * Gets a session with the associated user.
449
+ *
450
+ * @param sessionId - The ID of the session to search for.
451
+ * @returns A promise that resolves to the session with the associated user.
452
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the session with the user.
453
+ */
454
+ sessionWithUser: async (sessionId) => {
455
+ try {
456
+ return await db.select({ user: tsUsers, session: tsSessionTable }).from(tsSessionTable).innerJoin(tsUsers, eq(tsSessionTable.userId, tsUsers.id)).where(eq(tsSessionTable.id, sessionId));
457
+ } catch (error) {
458
+ if (error instanceof Error) {
459
+ throw new StudioCMS_SDK_Error(
460
+ `Error getting session with user: ${error.message}`,
461
+ error.stack
462
+ );
463
+ }
464
+ throw new StudioCMS_SDK_Error(
465
+ "Error getting session with user: An unknown error occurred."
466
+ );
467
+ }
468
+ },
469
+ /**
470
+ * Deletes a session from the database.
471
+ *
472
+ * @param sessionId - The ID of the session to delete.
473
+ * @returns A promise that resolves to a deletion response.
474
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the session.
475
+ */
476
+ delete: async (sessionId) => {
477
+ try {
478
+ await db.delete(tsSessionTable).where(eq(tsSessionTable.id, sessionId));
479
+ return {
480
+ status: "success",
481
+ message: "Session deleted"
482
+ };
483
+ } catch (error) {
484
+ if (error instanceof Error) {
485
+ throw new StudioCMS_SDK_Error(`Error deleting session: ${error.message}`, error.stack);
486
+ }
487
+ throw new StudioCMS_SDK_Error("Error deleting session: An unknown error occurred.");
488
+ }
489
+ },
490
+ /**
491
+ * Updates the expiration date of a session.
492
+ *
493
+ * @param sessionId - The ID of the session to update.
494
+ * @param newDate - The new expiration date for the session.
495
+ * @returns A promise that resolves to the updated session.
496
+ * @throws {StudioCMS_SDK_Error} If an error occurs while updating the session.
497
+ */
498
+ update: async (sessionId, newDate) => {
499
+ try {
500
+ return await db.update(tsSessionTable).set({ expiresAt: newDate }).where(eq(tsSessionTable.id, sessionId)).returning();
501
+ } catch (error) {
502
+ if (error instanceof Error) {
503
+ throw new StudioCMS_SDK_Error(`Error updating session: ${error.message}`, error.stack);
504
+ }
505
+ throw new StudioCMS_SDK_Error("Error updating session: An unknown error occurred.");
506
+ }
507
+ }
508
+ },
509
+ /**
510
+ * Provides various methods to create, update, and search for users in the StudioCMS database.
511
+ */
512
+ user: {
513
+ /**
514
+ * Creates a new user in the database.
515
+ *
516
+ * @param newUserData - The data to insert into the users table.
517
+ * @returns A promise that resolves to the inserted user.
518
+ * @throws {StudioCMS_SDK_Error} If an error occurs while creating the user.
519
+ */
520
+ create: async (newUserData, rank) => {
521
+ try {
522
+ const newUser = await db.insert(tsUsers).values(newUserData).returning().get();
523
+ await db.insert(tsPermissions).values({ user: newUser.id, rank: rank || "visitor" });
524
+ return newUser;
525
+ } catch (error) {
526
+ if (error instanceof Error) {
527
+ throw new StudioCMS_SDK_Error(`Error creating user: ${error.message}`, error.stack);
528
+ }
529
+ throw new StudioCMS_SDK_Error("Error creating user: An unknown error occurred.");
530
+ }
531
+ },
532
+ /**
533
+ * Updates a user in the database.
534
+ *
535
+ * @param userId - The ID of the user to update.
536
+ * @param userData - The data to update the user with.
537
+ * @returns A promise that resolves to the updated user.
538
+ * @throws {StudioCMS_SDK_Error} If an error occurs while updating the user.
539
+ */
540
+ update: async (userId, userData) => {
541
+ try {
542
+ return await db.update(tsUsers).set(userData).where(eq(tsUsers.id, userId)).returning().get();
543
+ } catch (error) {
544
+ if (error instanceof Error) {
545
+ throw new StudioCMS_SDK_Error(`Error updating user: ${error.message}`, error.stack);
546
+ }
547
+ throw new StudioCMS_SDK_Error("Error updating user: An unknown error occurred.");
548
+ }
549
+ },
550
+ /**
551
+ * Searches for users based on the provided username or email.
552
+ *
553
+ * @param username - The username to search for.
554
+ * @param email - The email to search for.
555
+ * @returns A promise that resolves to an object containing the search results for the username and email.
556
+ * @throws {StudioCMS_SDK_Error} If an error occurs while searching for the username or email.
557
+ */
558
+ searchUsersForUsernameOrEmail: async (username, email) => {
559
+ try {
560
+ const [usernameSearch, emailSearch] = await db.batch([
561
+ db.select().from(tsUsers).where(eq(tsUsers.username, username)),
562
+ db.select().from(tsUsers).where(eq(tsUsers.email, email))
563
+ ]);
564
+ return { usernameSearch, emailSearch };
565
+ } catch (error) {
566
+ if (error instanceof Error) {
567
+ throw new StudioCMS_SDK_Error(
568
+ `Error searching for username or email: ${error.message}`,
569
+ error.stack
570
+ );
571
+ }
572
+ throw new StudioCMS_SDK_Error(
573
+ "Error searching for username or email: An unknown error occurred."
574
+ );
575
+ }
576
+ },
577
+ /**
578
+ * Ghost user utilities.
579
+ */
580
+ ghost: {
581
+ /**
582
+ * Verifies if the ghost user exists in the database.
583
+ *
584
+ * @returns A promise that resolves to a boolean indicating if the ghost user exists.
585
+ * @throws {StudioCMS_SDK_Error} If an error occurs while verifying the ghost user.
586
+ */
587
+ verifyExists: async () => {
588
+ try {
589
+ const ghostUser = await db.select().from(tsUsers).where(eq(tsUsers.id, GhostUserDefaults.id)).get();
590
+ if (!ghostUser) {
591
+ return false;
592
+ }
593
+ return true;
594
+ } catch (error) {
595
+ if (error instanceof Error) {
596
+ throw new StudioCMS_SDK_Error(
597
+ `Error verifying ghost user exists: ${error.message}`,
598
+ error.stack
599
+ );
600
+ }
601
+ throw new StudioCMS_SDK_Error(
602
+ "Error verifying ghost user exists: An unknown error occurred."
603
+ );
604
+ }
605
+ },
606
+ /**
607
+ * Creates the ghost user in the database.
608
+ *
609
+ * @returns A promise that resolves to the inserted ghost user.
610
+ * @throws {StudioCMS_SDK_Error} If an error occurs while creating the ghost user.
611
+ */
612
+ create: async () => {
613
+ try {
614
+ return await db.insert(tsUsers).values(GhostUserDefaults).returning().get();
615
+ } catch (error) {
616
+ if (error instanceof Error) {
617
+ throw new StudioCMS_SDK_Error(
618
+ `Error creating ghost user: ${error.message}`,
619
+ error.stack
620
+ );
621
+ }
622
+ throw new StudioCMS_SDK_Error("Error creating ghost user: An unknown error occurred.");
623
+ }
624
+ },
625
+ /**
626
+ * Gets the ghost user from the database.
627
+ *
628
+ * @returns A promise that resolves to the ghost user.
629
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the ghost user.
630
+ */
631
+ get: async () => {
632
+ try {
633
+ return await db.select().from(tsUsers).where(eq(tsUsers.id, GhostUserDefaults.id)).get();
634
+ } catch (error) {
635
+ if (error instanceof Error) {
636
+ throw new StudioCMS_SDK_Error(
637
+ `Error getting ghost user: ${error.message}`,
638
+ error.stack
639
+ );
640
+ }
641
+ throw new StudioCMS_SDK_Error("Error getting ghost user: An unknown error occurred.");
642
+ }
643
+ }
644
+ }
645
+ }
646
+ };
647
+ const INIT = {
648
+ /**
649
+ * Initializes the StudioCMS SiteConfig table with the provided configuration.
650
+ *
651
+ * @param config - The configuration to insert into the SiteConfig table.
652
+ * @returns A promise that resolves to the inserted site configuration.
653
+ * @throws {StudioCMS_SDK_Error} If an error occurs while creating the site configuration.
654
+ */
655
+ siteConfig: async (config) => {
656
+ try {
657
+ return await db.insert(tsSiteConfig).values({ ...config, id: CMSSiteConfigId }).returning().get();
658
+ } catch (error) {
659
+ if (error instanceof Error) {
660
+ throw new StudioCMS_SDK_Error(
661
+ `Error creating site configuration: ${error.message}`,
662
+ error.stack
663
+ );
664
+ }
665
+ throw new StudioCMS_SDK_Error(
666
+ "Error creating site configuration: An unknown error occurred."
667
+ );
668
+ }
669
+ },
670
+ /**
671
+ * Initializes the StudioCMS Ghost User.
672
+ *
673
+ * The ghost user is a default user that is used to perform actions on behalf of the system as well as to replace deleted users.
674
+ *
675
+ * @returns A promise that resolves to the ghost user record.
676
+ * @throws {StudioCMS_SDK_Error} If an error occurs while creating the ghost user.
677
+ */
678
+ ghostUser: async () => {
679
+ try {
680
+ const ghostUser = await AUTH.user.ghost.verifyExists();
681
+ if (!ghostUser) {
682
+ return await AUTH.user.ghost.create();
683
+ }
684
+ const ghostUserRecord = await AUTH.user.ghost.get();
685
+ if (!ghostUserRecord) {
686
+ throw new StudioCMS_SDK_Error(
687
+ "Error getting ghost user from database: The ghost user may not exist yet."
688
+ );
689
+ }
690
+ return ghostUserRecord;
691
+ } catch (error) {
692
+ if (error instanceof Error) {
693
+ throw new StudioCMS_SDK_Error(`Error creating ghost user: ${error.message}`, error.stack);
694
+ }
695
+ throw new StudioCMS_SDK_Error("Error creating ghost user: An unknown error occurred.");
696
+ }
697
+ }
698
+ };
699
+ const GET = {
700
+ /**
701
+ * Retrieves data from the database
702
+ */
703
+ database: {
704
+ /**
705
+ * Retrieves all users from the database.
706
+ *
707
+ * @returns A promise that resolves to an array of combined user data.
708
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the users.
709
+ */
710
+ users: async () => {
711
+ try {
712
+ const combinedUserData = [];
713
+ const users = await db.select().from(tsUsers);
714
+ for (const user of users) {
715
+ const UserData = await collectUserData(user);
716
+ combinedUserData.push(UserData);
717
+ }
718
+ return combinedUserData;
719
+ } catch (error) {
720
+ if (error instanceof Error) {
721
+ throw new StudioCMS_SDK_Error(`Error getting users: ${error.message}`, error.stack);
722
+ }
723
+ throw new StudioCMS_SDK_Error("Error getting users: An unknown error occurred.");
724
+ }
725
+ },
726
+ /**
727
+ * Retrieves all pages from the database.
728
+ *
729
+ * @returns A promise that resolves to an array of combined page data.
730
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the pages.
731
+ */
732
+ pages: async (includeDrafts = false, tree) => {
733
+ try {
734
+ const pages = [];
735
+ let pagesRaw = await db.select().from(tsPageData);
736
+ if (!includeDrafts) {
737
+ pagesRaw = pagesRaw.filter(({ draft }) => draft === false || draft === null);
738
+ }
739
+ const folders = tree || await buildFolderTree();
740
+ for (const page of pagesRaw) {
741
+ const PageData = await collectPageData(page, folders);
742
+ pages.push(PageData);
743
+ }
744
+ return pages;
745
+ } catch (error) {
746
+ if (error instanceof Error) {
747
+ throw new StudioCMS_SDK_Error(`Error getting pages: ${error.message}`, error.stack);
748
+ }
749
+ throw new StudioCMS_SDK_Error("Error getting pages: An unknown error occurred.");
750
+ }
751
+ },
752
+ /**
753
+ * Retrieves the site configuration from the database.
754
+ *
755
+ * @returns A promise that resolves to the site configuration.
756
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the site configuration.
757
+ */
758
+ config: async () => {
759
+ try {
760
+ return await db.select().from(tsSiteConfig).where(eq(tsSiteConfig.id, CMSSiteConfigId)).get();
761
+ } catch (error) {
762
+ if (error instanceof Error) {
763
+ throw new StudioCMS_SDK_Error(
764
+ `Error getting site configuration: ${error.message}`,
765
+ error.stack
766
+ );
767
+ }
768
+ throw new StudioCMS_SDK_Error(
769
+ "Error getting site configuration: An unknown error occurred."
770
+ );
771
+ }
772
+ },
773
+ folders: async () => {
774
+ try {
775
+ return await db.select().from(tsPageFolderStructure);
776
+ } catch (error) {
777
+ if (error instanceof Error) {
778
+ throw new StudioCMS_SDK_Error(`Error getting folders: ${error.message}`, error.stack);
779
+ }
780
+ throw new StudioCMS_SDK_Error("Error getting folders: An unknown error occurred.");
781
+ }
782
+ }
783
+ },
784
+ /**
785
+ * Retrieves data from the database by ID.
786
+ */
787
+ databaseEntry: {
788
+ /**
789
+ * Retrieves a user from the database
790
+ */
791
+ users: {
792
+ /**
793
+ * Retrieves a user by ID.
794
+ *
795
+ * @param id - The ID of the user to retrieve.
796
+ * @returns A promise that resolves to the user data.
797
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the user.
798
+ */
799
+ byId: async (id) => {
800
+ try {
801
+ const user = await db.select().from(tsUsers).where(eq(tsUsers.id, id)).get();
802
+ if (!user) return void 0;
803
+ return await collectUserData(user);
804
+ } catch (error) {
805
+ if (error instanceof Error) {
806
+ throw new StudioCMS_SDK_Error(
807
+ `Error getting user by ID: ${error.message}`,
808
+ error.stack
809
+ );
810
+ }
811
+ throw new StudioCMS_SDK_Error("Error getting user by ID: An unknown error occurred.");
812
+ }
813
+ },
814
+ /**
815
+ * Retrieves a user by username.
816
+ *
817
+ * @param username - The username of the user to retrieve.
818
+ * @returns A promise that resolves to the user data.
819
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the user.
820
+ */
821
+ byUsername: async (username) => {
822
+ try {
823
+ const user = await db.select().from(tsUsers).where(eq(tsUsers.username, username)).get();
824
+ if (!user) return void 0;
825
+ return await collectUserData(user);
826
+ } catch (error) {
827
+ if (error instanceof Error) {
828
+ throw new StudioCMS_SDK_Error(
829
+ `Error getting user by username: ${error.message}`,
830
+ error.stack
831
+ );
832
+ }
833
+ throw new StudioCMS_SDK_Error(
834
+ "Error getting user by username: An unknown error occurred."
835
+ );
836
+ }
837
+ },
838
+ /**
839
+ * Retrieves a user by email.
840
+ *
841
+ * @param email - The email of the user to retrieve.
842
+ * @returns A promise that resolves to the user data.
843
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the user.
844
+ */
845
+ byEmail: async (email) => {
846
+ try {
847
+ const user = await db.select().from(tsUsers).where(eq(tsUsers.email, email)).get();
848
+ if (!user) return void 0;
849
+ return await collectUserData(user);
850
+ } catch (error) {
851
+ if (error instanceof Error) {
852
+ throw new StudioCMS_SDK_Error(
853
+ `Error getting user by email: ${error.message}`,
854
+ error.stack
855
+ );
856
+ }
857
+ throw new StudioCMS_SDK_Error(
858
+ "Error getting user by email: An unknown error occurred."
859
+ );
860
+ }
861
+ }
862
+ },
863
+ /**
864
+ * Retrieves a page from the database
865
+ */
866
+ pages: {
867
+ /**
868
+ * Retrieves a page by ID.
869
+ *
870
+ * @param id - The ID of the page to retrieve.
871
+ * @returns A promise that resolves to the page data.
872
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the page.
873
+ */
874
+ byId: async (id, tree) => {
875
+ try {
876
+ const page = await db.select().from(tsPageData).where(eq(tsPageData.id, id)).get();
877
+ if (!page) return void 0;
878
+ const folders = tree || await buildFolderTree();
879
+ return await collectPageData(page, folders);
880
+ } catch (error) {
881
+ if (error instanceof Error) {
882
+ throw new StudioCMS_SDK_Error(
883
+ `Error getting page by ID: ${error.message}`,
884
+ error.stack
885
+ );
886
+ }
887
+ throw new StudioCMS_SDK_Error("Error getting page by ID: An unknown error occurred.");
888
+ }
889
+ },
890
+ /**
891
+ * Retrieves a page by slug.
892
+ *
893
+ * @param slug - The slug of the page to retrieve.
894
+ * @returns A promise that resolves to the page data.
895
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the page.
896
+ */
897
+ bySlug: async (slug, tree) => {
898
+ try {
899
+ const page = await db.select().from(tsPageData).where(eq(tsPageData.slug, slug)).get();
900
+ if (!page) return void 0;
901
+ const folders = tree || await buildFolderTree();
902
+ return await collectPageData(page, folders);
903
+ } catch (error) {
904
+ if (error instanceof Error) {
905
+ throw new StudioCMS_SDK_Error(
906
+ `Error getting page by slug: ${error.message}`,
907
+ error.stack
908
+ );
909
+ }
910
+ throw new StudioCMS_SDK_Error("Error getting page by slug: An unknown error occurred.");
911
+ }
912
+ }
913
+ },
914
+ folder: async (id) => {
915
+ try {
916
+ return await db.select().from(tsPageFolderStructure).where(eq(tsPageFolderStructure.id, id)).get();
917
+ } catch (error) {
918
+ if (error instanceof Error) {
919
+ throw new StudioCMS_SDK_Error(`Error getting folders: ${error.message}`, error.stack);
920
+ }
921
+ throw new StudioCMS_SDK_Error("Error getting folders: An unknown error occurred.");
922
+ }
923
+ }
924
+ },
925
+ /**
926
+ * Retrieves data from the database tables without any additional processing.
927
+ */
928
+ databaseTable: {
929
+ /**
930
+ * Retrieves all data from the users table.
931
+ *
932
+ * @returns A promise that resolves to an array of user data.
933
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the users.
934
+ */
935
+ users: async () => await db.select().from(tsUsers),
936
+ /**
937
+ * Retrieves all data from the OAuth accounts table.
938
+ *
939
+ * @returns A promise that resolves to an array of OAuth account data.
940
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the OAuth accounts.
941
+ */
942
+ oAuthAccounts: async () => await db.select().from(tsOAuthAccounts),
943
+ /**
944
+ * Retrieves all data from the session table.
945
+ *
946
+ * @returns A promise that resolves to an array of session data.
947
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the sessions.
948
+ */
949
+ sessionTable: async () => await db.select().from(tsSessionTable),
950
+ /**
951
+ * Retrieves all data from the permissions table.
952
+ *
953
+ * @returns A promise that resolves to an array of permission data.
954
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the permissions.
955
+ */
956
+ permissions: async () => await db.select().from(tsPermissions),
957
+ /**
958
+ * Retrieves all data from the page data table.
959
+ *
960
+ * @returns A promise that resolves to an array of page data.
961
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the pages.
962
+ */
963
+ pageData: async () => await db.select().from(tsPageData),
964
+ /**
965
+ * Retrieves all data from the page data tags table.
966
+ *
967
+ * @returns A promise that resolves to an array of page data tags.
968
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the page data tags.
969
+ */
970
+ pageDataTags: async () => await db.select().from(tsPageDataTags),
971
+ /**
972
+ * Retrieves all data from the page data categories table.
973
+ *
974
+ * @returns A promise that resolves to an array of page data categories.
975
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the page data categories.
976
+ */
977
+ pageDataCategories: async () => await db.select().from(tsPageDataCategories),
978
+ /**
979
+ * Retrieves all data from the page content table.
980
+ *
981
+ * @returns A promise that resolves to an array of page content.
982
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the page content.
983
+ */
984
+ pageContent: async () => await db.select().from(tsPageContent),
985
+ /**
986
+ * Retrieves all data from the site config table.
987
+ *
988
+ * @returns A promise that resolves to an array of site configuration data.
989
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the site configuration.
990
+ */
991
+ siteConfig: async () => await db.select().from(tsSiteConfig).where(eq(tsSiteConfig.id, CMSSiteConfigId)).get(),
992
+ /**
993
+ * Retrieves all data from the diff tracking table.
994
+ *
995
+ * @returns A promise that resolves to an array of diff tracking data.
996
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the diff tracking data.
997
+ */
998
+ diffTracking: async () => await db.select().from(tsDiffTracking),
999
+ /**
1000
+ * Retrieves all data from the page folder structure table.
1001
+ *
1002
+ * @returns A promise that resolves to an array of page folder structure data.
1003
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the page folder structure data.
1004
+ */
1005
+ pageFolderStructure: async () => await db.select().from(tsPageFolderStructure)
1006
+ },
1007
+ /**
1008
+ * Retrieve Permission Lists
1009
+ */
1010
+ permissionsLists: {
1011
+ /**
1012
+ * Retrieves all permissions for users in the database.
1013
+ *
1014
+ * @returns A promise that resolves to an array of combined rank data.
1015
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the permissions.
1016
+ */
1017
+ all: async () => {
1018
+ try {
1019
+ const [currentPermittedUsers, existingUsers] = await db.batch([
1020
+ db.select().from(tsPermissions),
1021
+ db.select().from(tsUsers)
1022
+ ]);
1023
+ const owners = verifyRank(existingUsers, currentPermittedUsers, "owner");
1024
+ const admins = verifyRank(existingUsers, currentPermittedUsers, "admin");
1025
+ const editors = verifyRank(existingUsers, currentPermittedUsers, "editor");
1026
+ const visitors = verifyRank(existingUsers, currentPermittedUsers, "visitor");
1027
+ return [
1028
+ ...combineRanks("owner", owners),
1029
+ ...combineRanks("admin", admins),
1030
+ ...combineRanks("editor", editors),
1031
+ ...combineRanks("visitor", visitors)
1032
+ ];
1033
+ } catch (error) {
1034
+ if (error instanceof Error) {
1035
+ throw new StudioCMS_SDK_Error(`Error getting users: ${error.message}`, error.stack);
1036
+ }
1037
+ throw new StudioCMS_SDK_Error("Error getting users: An unknown error occurred.");
1038
+ }
1039
+ },
1040
+ /**
1041
+ * Retrieves all owners in the database.
1042
+ *
1043
+ * @returns A promise that resolves to an array of combined rank data.
1044
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the owners.
1045
+ */
1046
+ owners: async () => {
1047
+ try {
1048
+ const [currentPermittedUsers, existingUsers] = await db.batch([
1049
+ db.select().from(tsPermissions),
1050
+ db.select().from(tsUsers)
1051
+ ]);
1052
+ return verifyRank(existingUsers, currentPermittedUsers, "owner");
1053
+ } catch (error) {
1054
+ if (error instanceof Error) {
1055
+ throw new StudioCMS_SDK_Error(`Error getting users: ${error.message}`, error.stack);
1056
+ }
1057
+ throw new StudioCMS_SDK_Error("Error getting users: An unknown error occurred.");
1058
+ }
1059
+ },
1060
+ /**
1061
+ * Retrieves all admins in the database.
1062
+ *
1063
+ * @returns A promise that resolves to an array of combined rank data.
1064
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the admins.
1065
+ */
1066
+ admins: async () => {
1067
+ try {
1068
+ const [currentPermittedUsers, existingUsers] = await db.batch([
1069
+ db.select().from(tsPermissions),
1070
+ db.select().from(tsUsers)
1071
+ ]);
1072
+ return verifyRank(existingUsers, currentPermittedUsers, "admin");
1073
+ } catch (error) {
1074
+ if (error instanceof Error) {
1075
+ throw new StudioCMS_SDK_Error(`Error getting users: ${error.message}`, error.stack);
1076
+ }
1077
+ throw new StudioCMS_SDK_Error("Error getting users: An unknown error occurred.");
1078
+ }
1079
+ },
1080
+ /**
1081
+ * Retrieves all editors in the database.
1082
+ *
1083
+ * @returns A promise that resolves to an array of combined rank data.
1084
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the editors.
1085
+ */
1086
+ editors: async () => {
1087
+ try {
1088
+ const [currentPermittedUsers, existingUsers] = await db.batch([
1089
+ db.select().from(tsPermissions),
1090
+ db.select().from(tsUsers)
1091
+ ]);
1092
+ return verifyRank(existingUsers, currentPermittedUsers, "editor");
1093
+ } catch (error) {
1094
+ if (error instanceof Error) {
1095
+ throw new StudioCMS_SDK_Error(`Error getting users: ${error.message}`, error.stack);
1096
+ }
1097
+ throw new StudioCMS_SDK_Error("Error getting users: An unknown error occurred.");
1098
+ }
1099
+ },
1100
+ /**
1101
+ * Retrieves all visitors in the database.
1102
+ *
1103
+ * @returns A promise that resolves to an array of combined rank data.
1104
+ * @throws {StudioCMS_SDK_Error} If an error occurs while getting the visitors.
1105
+ */
1106
+ visitors: async () => {
1107
+ try {
1108
+ const [currentPermittedUsers, existingUsers] = await db.batch([
1109
+ db.select().from(tsPermissions),
1110
+ db.select().from(tsUsers)
1111
+ ]);
1112
+ return verifyRank(existingUsers, currentPermittedUsers, "visitor");
1113
+ } catch (error) {
1114
+ if (error instanceof Error) {
1115
+ throw new StudioCMS_SDK_Error(`Error getting users: ${error.message}`, error.stack);
1116
+ }
1117
+ throw new StudioCMS_SDK_Error("Error getting users: An unknown error occurred.");
1118
+ }
1119
+ }
1120
+ },
1121
+ /**
1122
+ * Retrieves data from the database by package.
1123
+ */
1124
+ packagePages: async (packageName, tree) => {
1125
+ try {
1126
+ const pages = [];
1127
+ const pagesRaw = await db.select().from(tsPageData).where(eq(tsPageData.package, packageName));
1128
+ const folders = tree || await buildFolderTree();
1129
+ for (const page of pagesRaw) {
1130
+ const PageData = await collectPageData(page, folders);
1131
+ pages.push(PageData);
1132
+ }
1133
+ return pages;
1134
+ } catch (error) {
1135
+ if (error instanceof Error) {
1136
+ throw new StudioCMS_SDK_Error(`Error getting pages: ${error.message}`, error.stack);
1137
+ }
1138
+ throw new StudioCMS_SDK_Error("Error getting pages: An unknown error occurred.");
1139
+ }
1140
+ }
1141
+ };
1142
+ const POST = {
1143
+ /**
1144
+ * Inserts data into the database by Entry
1145
+ */
1146
+ databaseEntry: {
1147
+ /**
1148
+ * Insert a new page into the database.
1149
+ *
1150
+ * @param pageData - The data to insert into the page data table.
1151
+ * @param pageContent - The data to insert into the page content table.
1152
+ * @returns A promise that resolves to the inserted page data and page content.
1153
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the page.
1154
+ */
1155
+ pages: async (pageData, pageContent) => {
1156
+ try {
1157
+ const newContentID = pageData.id || crypto.randomUUID().toString();
1158
+ const {
1159
+ id = newContentID,
1160
+ title,
1161
+ slug,
1162
+ description,
1163
+ authorId = null,
1164
+ package: packageName = "studiocms",
1165
+ contentLang = "default",
1166
+ heroImage = "",
1167
+ showOnNav = false,
1168
+ showAuthor = false,
1169
+ showContributors = false,
1170
+ categories = [],
1171
+ tags = [],
1172
+ contributorIds = [],
1173
+ draft = false,
1174
+ parentFolder = null
1175
+ } = pageData;
1176
+ const stringified = {
1177
+ categories: categories || [],
1178
+ tags: tags || [],
1179
+ contributorIds: contributorIds || []
1180
+ };
1181
+ const contentData = {
1182
+ id: crypto.randomUUID().toString(),
1183
+ contentId: newContentID,
1184
+ contentLang,
1185
+ content: pageContent.content || ""
1186
+ };
1187
+ const NOW = /* @__PURE__ */ new Date();
1188
+ const [newPageData, newPageContent] = await db.batch([
1189
+ db.insert(tsPageData).values({
1190
+ id,
1191
+ title,
1192
+ slug,
1193
+ description,
1194
+ authorId,
1195
+ contentLang,
1196
+ heroImage,
1197
+ showAuthor,
1198
+ showContributors,
1199
+ showOnNav,
1200
+ draft,
1201
+ parentFolder,
1202
+ package: packageName,
1203
+ publishedAt: NOW,
1204
+ updatedAt: NOW,
1205
+ ...stringified
1206
+ }).returning({ id: tsPageData.id }),
1207
+ db.insert(tsPageContent).values(contentData).returning({ id: tsPageContent.id })
1208
+ ]);
1209
+ return {
1210
+ pageData: newPageData,
1211
+ pageContent: newPageContent
1212
+ };
1213
+ } catch (error) {
1214
+ if (error instanceof Error) {
1215
+ throw new StudioCMS_SDK_Error(`Error inserting page: ${error.message}`, error.stack);
1216
+ }
1217
+ throw new StudioCMS_SDK_Error("Error inserting page: An unknown error occurred.");
1218
+ }
1219
+ },
1220
+ /**
1221
+ * Inserts new page content into the database.
1222
+ *
1223
+ * @param pageContent - The data to insert into the page content table.
1224
+ * @returns A promise that resolves to the inserted page content.
1225
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the page content.
1226
+ */
1227
+ pageContent: async (pageContent) => {
1228
+ try {
1229
+ return await db.insert(tsPageContent).values({
1230
+ id: pageContent.id || crypto.randomUUID().toString(),
1231
+ contentId: pageContent.contentId,
1232
+ contentLang: pageContent.contentLang || "default",
1233
+ content: pageContent.content || ""
1234
+ }).returning({ id: tsPageContent.id });
1235
+ } catch (error) {
1236
+ if (error instanceof Error) {
1237
+ throw new StudioCMS_SDK_Error(
1238
+ `Error inserting page content: ${error.message}`,
1239
+ error.stack
1240
+ );
1241
+ }
1242
+ throw new StudioCMS_SDK_Error("Error inserting page content: An unknown error occurred.");
1243
+ }
1244
+ },
1245
+ /**
1246
+ * Inserts a new tag into the database.
1247
+ *
1248
+ * @param tag - The data to insert into the page data tags table.
1249
+ * @returns A promise that resolves to the inserted tag.
1250
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the tag.
1251
+ */
1252
+ tags: async (tag) => {
1253
+ try {
1254
+ return await db.insert(tsPageDataTags).values({
1255
+ name: tag.name,
1256
+ description: tag.description,
1257
+ slug: tag.slug,
1258
+ meta: JSON.stringify(tag.meta),
1259
+ id: tag.id || generateRandomIDNumber(9)
1260
+ }).returning({ id: tsPageDataTags.id });
1261
+ } catch (error) {
1262
+ if (error instanceof Error) {
1263
+ throw new StudioCMS_SDK_Error(`Error inserting tag: ${error.message}`, error.stack);
1264
+ }
1265
+ throw new StudioCMS_SDK_Error("Error inserting tag: An unknown error occurred.");
1266
+ }
1267
+ },
1268
+ /**
1269
+ * Inserts a new category into the database.
1270
+ *
1271
+ * @param category - The data to insert into the page data categories table.
1272
+ * @returns A promise that resolves to the inserted category.
1273
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the category.
1274
+ */
1275
+ categories: async (category) => {
1276
+ try {
1277
+ return await db.insert(tsPageDataCategories).values({
1278
+ name: category.name,
1279
+ description: category.description,
1280
+ slug: category.slug,
1281
+ meta: JSON.stringify(category.meta),
1282
+ id: category.id || generateRandomIDNumber(9)
1283
+ }).returning({ id: tsPageDataCategories.id });
1284
+ } catch (error) {
1285
+ if (error instanceof Error) {
1286
+ throw new StudioCMS_SDK_Error(
1287
+ `Error inserting category: ${error.message}`,
1288
+ error.stack
1289
+ );
1290
+ }
1291
+ throw new StudioCMS_SDK_Error("Error inserting category: An unknown error occurred.");
1292
+ }
1293
+ },
1294
+ /**
1295
+ * Inserts a new permission into the database.
1296
+ *
1297
+ * @param userId - The ID of the user to assign the rank to.
1298
+ * @param rank - The rank to assign to the user.
1299
+ * @returns A promise that resolves to the inserted permission.
1300
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the permission.
1301
+ */
1302
+ permissions: async (userId, rank) => {
1303
+ try {
1304
+ const userAlreadyExists = await db.select().from(tsPermissions).where(eq(tsPermissions.user, userId)).get();
1305
+ if (userAlreadyExists) {
1306
+ throw new StudioCMS_SDK_Error(
1307
+ "User already is already assigned a rank, please update the existing rank instead."
1308
+ );
1309
+ }
1310
+ return await db.insert(tsPermissions).values({
1311
+ user: userId,
1312
+ rank
1313
+ }).returning({ user: tsPermissions.user, rank: tsPermissions.rank });
1314
+ } catch (error) {
1315
+ if (error instanceof Error) {
1316
+ throw new StudioCMS_SDK_Error(
1317
+ `Error inserting permissions: ${error.message}`,
1318
+ error.stack
1319
+ );
1320
+ }
1321
+ throw new StudioCMS_SDK_Error("Error inserting permissions: An unknown error occurred.");
1322
+ }
1323
+ },
1324
+ /**
1325
+ * Inserts a new diff tracking entry into the database.
1326
+ *
1327
+ * @param diff - The data to insert into the diff tracking table.
1328
+ * @returns A promise that resolves to the inserted diff tracking entry.
1329
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the diff tracking entry.
1330
+ */
1331
+ diffTracking: async (diff) => {
1332
+ try {
1333
+ return await db.insert(tsDiffTracking).values({
1334
+ id: diff.id || crypto.randomUUID().toString(),
1335
+ userId: diff.userId,
1336
+ pageId: diff.pageId,
1337
+ diff: diff.diff || "",
1338
+ timestamp: diff.timestamp || /* @__PURE__ */ new Date(),
1339
+ pageContentStart: diff.pageContentStart,
1340
+ pageMetaData: JSON.stringify(diff.pageMetaData || {})
1341
+ }).returning();
1342
+ } catch (error) {
1343
+ if (error instanceof Error) {
1344
+ throw new StudioCMS_SDK_Error(
1345
+ `Error inserting diff tracking: ${error.message}`,
1346
+ error.stack
1347
+ );
1348
+ }
1349
+ throw new StudioCMS_SDK_Error(
1350
+ "Error inserting diff tracking: An unknown error occurred."
1351
+ );
1352
+ }
1353
+ },
1354
+ /**
1355
+ * Inserts a new folder into the database.
1356
+ *
1357
+ * @param folder - The data to insert into the page folder structure table.
1358
+ * @returns A promise that resolves to the inserted folder.
1359
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the folder.
1360
+ */
1361
+ folder: async (folder) => {
1362
+ try {
1363
+ return await db.insert(tsPageFolderStructure).values({
1364
+ id: folder.id || crypto.randomUUID().toString(),
1365
+ name: folder.name,
1366
+ parent: folder.parent || null
1367
+ }).returning();
1368
+ } catch (error) {
1369
+ if (error instanceof Error) {
1370
+ throw new StudioCMS_SDK_Error(`Error inserting folder: ${error.message}`, error.stack);
1371
+ }
1372
+ throw new StudioCMS_SDK_Error("Error inserting folder: An unknown error occurred.");
1373
+ }
1374
+ }
1375
+ },
1376
+ /**
1377
+ * Inserts data into the database by Array of Entries
1378
+ */
1379
+ databaseEntries: {
1380
+ /**
1381
+ * Inserts multiple tags into the database.
1382
+ *
1383
+ * @param data - The data to insert into the page data tags table.
1384
+ * @returns A promise that resolves to the inserted tags.
1385
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the tags.
1386
+ */
1387
+ tags: async (data) => {
1388
+ try {
1389
+ return await db.insert(tsPageDataTags).values(
1390
+ data.map((tag) => {
1391
+ return {
1392
+ id: tag.id || generateRandomIDNumber(9),
1393
+ name: tag.name,
1394
+ slug: tag.slug,
1395
+ description: tag.description,
1396
+ meta: JSON.stringify(tag.meta)
1397
+ };
1398
+ })
1399
+ ).returning({ id: tsPageDataTags.id });
1400
+ } catch (error) {
1401
+ if (error instanceof Error) {
1402
+ throw new StudioCMS_SDK_Error(`Error inserting tags: ${error.message}`, error.stack);
1403
+ }
1404
+ throw new StudioCMS_SDK_Error("Error inserting tags: An unknown error occurred.");
1405
+ }
1406
+ },
1407
+ /**
1408
+ * Inserts multiple categories into the database.
1409
+ *
1410
+ * @param data - The data to insert into the page data categories table.
1411
+ * @returns A promise that resolves to the inserted categories.
1412
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the categories.
1413
+ */
1414
+ categories: async (data) => {
1415
+ try {
1416
+ return await db.insert(tsPageDataCategories).values(
1417
+ data.map((category) => {
1418
+ return {
1419
+ id: category.id || generateRandomIDNumber(9),
1420
+ name: category.name,
1421
+ slug: category.slug,
1422
+ description: category.description,
1423
+ meta: JSON.stringify(category.meta)
1424
+ };
1425
+ })
1426
+ ).returning({ id: tsPageDataCategories.id });
1427
+ } catch (error) {
1428
+ if (error instanceof Error) {
1429
+ throw new StudioCMS_SDK_Error(
1430
+ `Error inserting categories: ${error.message}`,
1431
+ error.stack
1432
+ );
1433
+ }
1434
+ throw new StudioCMS_SDK_Error("Error inserting categories: An unknown error occurred.");
1435
+ }
1436
+ },
1437
+ /**
1438
+ * Inserts multiple permissions into the database.
1439
+ *
1440
+ * @param data - The data to insert into the permissions table.
1441
+ * @returns A promise that resolves to the inserted permissions.
1442
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the permissions.
1443
+ */
1444
+ permissions: async (data) => {
1445
+ try {
1446
+ const currentPermittedUsers = await db.select().from(tsPermissions);
1447
+ for (const permission of data) {
1448
+ const userAlreadyExists = currentPermittedUsers.find(
1449
+ (user) => user.user === permission.user
1450
+ );
1451
+ if (userAlreadyExists) {
1452
+ throw new Error(
1453
+ `User with ID ${permission.user} already has a rank assigned. Please update the existing rank instead.`
1454
+ );
1455
+ }
1456
+ }
1457
+ return await db.insert(tsPermissions).values(
1458
+ data.map((permission) => {
1459
+ return {
1460
+ user: permission.user,
1461
+ rank: permission.rank
1462
+ };
1463
+ })
1464
+ ).returning({ user: tsPermissions.user, rank: tsPermissions.rank });
1465
+ } catch (error) {
1466
+ if (error instanceof Error) {
1467
+ throw new StudioCMS_SDK_Error(
1468
+ `Error inserting permissions: ${error.message}`,
1469
+ error.stack
1470
+ );
1471
+ }
1472
+ throw new StudioCMS_SDK_Error("Error inserting permissions: An unknown error occurred.");
1473
+ }
1474
+ },
1475
+ /**
1476
+ * Inserts multiple pages into the database.
1477
+ *
1478
+ * @param pages - The data to insert into the page data and page content tables.
1479
+ * @returns A promise that resolves to the inserted pages.
1480
+ * @throws {StudioCMS_SDK_Error} If an error occurs while inserting the pages.
1481
+ */
1482
+ pages: async (pages) => {
1483
+ try {
1484
+ const queries = [];
1485
+ for (const { pageData, pageContent } of pages) {
1486
+ const newContentID = pageData.id || crypto.randomUUID().toString();
1487
+ const {
1488
+ title,
1489
+ slug,
1490
+ description,
1491
+ authorId = null,
1492
+ package: packageName = "studiocms",
1493
+ contentLang = "default",
1494
+ heroImage = "",
1495
+ showOnNav = false,
1496
+ showAuthor = false,
1497
+ showContributors = false,
1498
+ categories = [],
1499
+ tags = [],
1500
+ contributorIds = [],
1501
+ draft = false,
1502
+ parentFolder = null,
1503
+ id = newContentID
1504
+ } = pageData;
1505
+ const stringified = {
1506
+ categories: categories || [],
1507
+ tags: tags || [],
1508
+ contributorIds: contributorIds || []
1509
+ };
1510
+ const contentData = {
1511
+ id: crypto.randomUUID().toString(),
1512
+ contentId: newContentID,
1513
+ contentLang: pageContent.contentLang || "default",
1514
+ content: pageContent.content || ""
1515
+ };
1516
+ const NOW = /* @__PURE__ */ new Date();
1517
+ queries.push(
1518
+ db.insert(tsPageData).values({
1519
+ id,
1520
+ title,
1521
+ slug,
1522
+ description,
1523
+ authorId,
1524
+ contentLang,
1525
+ heroImage,
1526
+ showAuthor,
1527
+ showContributors,
1528
+ showOnNav,
1529
+ draft,
1530
+ parentFolder,
1531
+ package: packageName,
1532
+ publishedAt: NOW,
1533
+ updatedAt: NOW,
1534
+ ...stringified
1535
+ }).returning(),
1536
+ db.insert(tsPageContent).values(contentData).returning()
1537
+ );
1538
+ }
1539
+ const [head, ...tail] = queries;
1540
+ if (head) {
1541
+ await db.batch([head, ...tail]);
1542
+ }
1543
+ } catch (error) {
1544
+ if (error instanceof Error) {
1545
+ throw new StudioCMS_SDK_Error(`Error inserting pages: ${error.message}`, error.stack);
1546
+ }
1547
+ throw new StudioCMS_SDK_Error("Error inserting pages: An unknown error occurred.");
1548
+ }
1549
+ }
1550
+ }
1551
+ };
1552
+ const UPDATE = {
1553
+ /**
1554
+ * Updates a page in the database.
1555
+ *
1556
+ * @param data - The data to update in the page data table.
1557
+ * @returns A promise that resolves to the updated page data.
1558
+ * @throws {StudioCMS_SDK_Error} If an error occurs while updating the page.
1559
+ */
1560
+ page: async (data) => {
1561
+ try {
1562
+ return await db.update(tsPageData).set(data).where(eq(tsPageData.id, data.id)).returning().get();
1563
+ } catch (error) {
1564
+ if (error instanceof Error) {
1565
+ throw new StudioCMS_SDK_Error(`Error updating page: ${error.message}`, error.stack);
1566
+ }
1567
+ throw new StudioCMS_SDK_Error("Error updating page: An unknown error occurred.");
1568
+ }
1569
+ },
1570
+ /**
1571
+ * Updates a page content in the database.
1572
+ *
1573
+ * @param data - The data to update in the page content table.
1574
+ * @returns A promise that resolves to the updated page content.
1575
+ * @throws {StudioCMS_SDK_Error} If an error occurs while updating the page content.
1576
+ */
1577
+ pageContent: async (data) => {
1578
+ try {
1579
+ return await db.update(tsPageContent).set(data).where(eq(tsPageContent.id, data.id)).returning().get();
1580
+ } catch (error) {
1581
+ if (error instanceof Error) {
1582
+ throw new StudioCMS_SDK_Error(
1583
+ `Error updating page content: ${error.message}`,
1584
+ error.stack
1585
+ );
1586
+ }
1587
+ throw new StudioCMS_SDK_Error("Error updating page content: An unknown error occurred.");
1588
+ }
1589
+ },
1590
+ /**
1591
+ * Updates a tag in the database.
1592
+ *
1593
+ * @param data - The data to update in the page data tags table.
1594
+ * @returns A promise that resolves to the updated tag.
1595
+ * @throws {StudioCMS_SDK_Error} If an error occurs while updating the tag.
1596
+ */
1597
+ tags: async (data) => {
1598
+ try {
1599
+ return await db.update(tsPageDataTags).set(data).where(eq(tsPageDataTags.id, data.id)).returning().get();
1600
+ } catch (error) {
1601
+ if (error instanceof Error) {
1602
+ throw new StudioCMS_SDK_Error(`Error updating tags: ${error.message}`, error.stack);
1603
+ }
1604
+ throw new StudioCMS_SDK_Error("Error updating tags: An unknown error occurred.");
1605
+ }
1606
+ },
1607
+ /**
1608
+ * Updates a category in the database.
1609
+ *
1610
+ * @param data - The data to update in the page data categories table.
1611
+ * @returns A promise that resolves to the updated category.
1612
+ * @throws {StudioCMS_SDK_Error} If an error occurs while updating the category.
1613
+ */
1614
+ categories: async (data) => {
1615
+ try {
1616
+ return await db.update(tsPageDataCategories).set(data).where(eq(tsPageDataCategories.id, data.id)).returning().get();
1617
+ } catch (error) {
1618
+ if (error instanceof Error) {
1619
+ throw new StudioCMS_SDK_Error(`Error updating categories: ${error.message}`, error.stack);
1620
+ }
1621
+ throw new StudioCMS_SDK_Error("Error updating categories: An unknown error occurred.");
1622
+ }
1623
+ },
1624
+ /**
1625
+ * Updates a permission in the database.
1626
+ *
1627
+ * @param data - The data to update in the permissions table.
1628
+ * @returns A promise that resolves to the updated permission.
1629
+ * @throws {StudioCMS_SDK_Error} If an error occurs while updating the permission.
1630
+ */
1631
+ permissions: async (data) => {
1632
+ try {
1633
+ return await db.update(tsPermissions).set(data).where(eq(tsPermissions.user, data.user)).returning().get();
1634
+ } catch (error) {
1635
+ if (error instanceof Error) {
1636
+ throw new StudioCMS_SDK_Error(
1637
+ `Error updating permissions: ${error.message}`,
1638
+ error.stack
1639
+ );
1640
+ }
1641
+ throw new StudioCMS_SDK_Error("Error updating permissions: An unknown error occurred.");
1642
+ }
1643
+ },
1644
+ /**
1645
+ * Updates a site configuration in the database.
1646
+ *
1647
+ * @param data - The data to update in the site config table.
1648
+ * @returns A promise that resolves to the updated site configuration.
1649
+ * @throws {StudioCMS_SDK_Error} If an error occurs while updating the site configuration.
1650
+ */
1651
+ siteConfig: async (data) => {
1652
+ try {
1653
+ return await db.update(tsSiteConfig).set(data).where(eq(tsSiteConfig.id, data.id)).returning().get();
1654
+ } catch (error) {
1655
+ if (error instanceof Error) {
1656
+ throw new StudioCMS_SDK_Error(
1657
+ `Error updating site config: ${error.message}`,
1658
+ error.stack
1659
+ );
1660
+ }
1661
+ throw new StudioCMS_SDK_Error("Error updating site config: An unknown error occurred.");
1662
+ }
1663
+ },
1664
+ folder: async (data) => {
1665
+ try {
1666
+ return await db.update(tsPageFolderStructure).set(data).where(eq(tsPageFolderStructure.id, data.id)).returning().get();
1667
+ } catch (error) {
1668
+ if (error instanceof Error) {
1669
+ throw new StudioCMS_SDK_Error(`Error updating folder: ${error.message}`, error.stack);
1670
+ }
1671
+ throw new StudioCMS_SDK_Error("Error updating folder: An unknown error occurred.");
1672
+ }
1673
+ }
1674
+ };
1675
+ const DELETE = {
1676
+ /**
1677
+ * Deletes a page from the database.
1678
+ *
1679
+ * @param id - The ID of the page to delete.
1680
+ * @returns A promise that resolves to a deletion response.
1681
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the page.
1682
+ */
1683
+ page: async (id) => {
1684
+ try {
1685
+ return await db.batch([
1686
+ db.delete(tsDiffTracking).where(eq(tsDiffTracking.pageId, id)),
1687
+ db.delete(tsPageContent).where(eq(tsPageContent.contentId, id)),
1688
+ db.delete(tsPageData).where(eq(tsPageData.id, id))
1689
+ ]).then(() => {
1690
+ return {
1691
+ status: "success",
1692
+ message: `Page with ID ${id} has been deleted successfully`
1693
+ };
1694
+ });
1695
+ } catch (error) {
1696
+ if (error instanceof Error) {
1697
+ throw new StudioCMS_SDK_Error(
1698
+ `Error deleting page with ID ${id}: ${error.message}`,
1699
+ error.stack
1700
+ );
1701
+ }
1702
+ throw new StudioCMS_SDK_Error(
1703
+ `Error deleting page with ID ${id}: An unknown error occurred.`
1704
+ );
1705
+ }
1706
+ },
1707
+ /**
1708
+ * Deletes a page content from the database.
1709
+ *
1710
+ * @param id - The ID of the page content to delete.
1711
+ * @returns A promise that resolves to a deletion response.
1712
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the page content.
1713
+ */
1714
+ pageContent: async (id) => {
1715
+ try {
1716
+ return await db.delete(tsPageContent).where(eq(tsPageContent.contentId, id)).then(() => {
1717
+ return {
1718
+ status: "success",
1719
+ message: `Page content with ID ${id} has been deleted successfully`
1720
+ };
1721
+ });
1722
+ } catch (error) {
1723
+ if (error instanceof Error) {
1724
+ throw new StudioCMS_SDK_Error(
1725
+ `Error deleting page content with ID ${id}: ${error.message}`,
1726
+ error.stack
1727
+ );
1728
+ }
1729
+ throw new StudioCMS_SDK_Error(
1730
+ `Error deleting page content with ID ${id}: An unknown error occurred.`
1731
+ );
1732
+ }
1733
+ },
1734
+ /**
1735
+ * Deletes a page content lang from the database.
1736
+ *
1737
+ * @param id - The ID of the page content to delete.
1738
+ * @param lang - The lang of the page content to delete.
1739
+ * @returns A promise that resolves to a deletion response.
1740
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the page content lang.
1741
+ */
1742
+ pageContentLang: async (id, lang) => {
1743
+ try {
1744
+ return await db.delete(tsPageContent).where(and(eq(tsPageContent.contentId, id), eq(tsPageContent.contentLang, lang))).then(() => {
1745
+ return {
1746
+ status: "success",
1747
+ message: `Page content with ID ${id} and lang ${lang} has been deleted successfully`
1748
+ };
1749
+ });
1750
+ } catch (error) {
1751
+ if (error instanceof Error) {
1752
+ throw new StudioCMS_SDK_Error(
1753
+ `Error deleting page content with ID ${id} and lang ${lang}: ${error.message}`,
1754
+ error.stack
1755
+ );
1756
+ }
1757
+ throw new StudioCMS_SDK_Error(
1758
+ `Error deleting page content with ID ${id} and lang ${lang}: An unknown error occurred.`
1759
+ );
1760
+ }
1761
+ },
1762
+ /**
1763
+ * Deletes a tag from the database.
1764
+ *
1765
+ * @param id - The ID of the tag to delete.
1766
+ * @returns A promise that resolves to a deletion response.
1767
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the tag.
1768
+ */
1769
+ tags: async (id) => {
1770
+ try {
1771
+ return await db.delete(tsPageDataTags).where(eq(tsPageDataTags.id, id)).then(() => {
1772
+ return {
1773
+ status: "success",
1774
+ message: `Tag with ID ${id} has been deleted successfully`
1775
+ };
1776
+ });
1777
+ } catch (error) {
1778
+ if (error instanceof Error) {
1779
+ throw new StudioCMS_SDK_Error(
1780
+ `Error deleting tag with ID ${id}: ${error.message}`,
1781
+ error.stack
1782
+ );
1783
+ }
1784
+ throw new StudioCMS_SDK_Error(
1785
+ `Error deleting tag with ID ${id}: An unknown error occurred.`
1786
+ );
1787
+ }
1788
+ },
1789
+ /**
1790
+ * Deletes a category from the database.
1791
+ *
1792
+ * @param id - The ID of the category to delete.
1793
+ * @returns A promise that resolves to a deletion response.
1794
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the category.
1795
+ */
1796
+ categories: async (id) => {
1797
+ try {
1798
+ return await db.delete(tsPageDataCategories).where(eq(tsPageDataCategories.id, id)).then(() => {
1799
+ return {
1800
+ status: "success",
1801
+ message: `Category with ID ${id} has been deleted successfully`
1802
+ };
1803
+ });
1804
+ } catch (error) {
1805
+ if (error instanceof Error) {
1806
+ throw new StudioCMS_SDK_Error(
1807
+ `Error deleting category with ID ${id}: ${error.message}`,
1808
+ error.stack
1809
+ );
1810
+ }
1811
+ throw new StudioCMS_SDK_Error(
1812
+ `Error deleting category with ID ${id}: An unknown error occurred.`
1813
+ );
1814
+ }
1815
+ },
1816
+ /**
1817
+ * Deletes a permission from the database.
1818
+ *
1819
+ * @param userId - The ID of the user to delete the permission for.
1820
+ * @returns A promise that resolves to a deletion response.
1821
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the permission.
1822
+ */
1823
+ permissions: async (userId) => {
1824
+ try {
1825
+ return await db.delete(tsPermissions).where(eq(tsPermissions.user, userId)).then(() => {
1826
+ return {
1827
+ status: "success",
1828
+ message: `Permissions for user with ID ${userId} have been deleted successfully`
1829
+ };
1830
+ });
1831
+ } catch (error) {
1832
+ if (error instanceof Error) {
1833
+ throw new StudioCMS_SDK_Error(
1834
+ `Error deleting permissions for user with ID ${userId}: ${error.message}`,
1835
+ error.stack
1836
+ );
1837
+ }
1838
+ throw new StudioCMS_SDK_Error(
1839
+ `Error deleting permissions for user with ID ${userId}: An unknown error occurred.`
1840
+ );
1841
+ }
1842
+ },
1843
+ /**
1844
+ * Deletes a site configuration from the database.
1845
+ *
1846
+ * @param id - The ID of the site configuration to delete.
1847
+ * @returns A promise that resolves to a deletion response.
1848
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the site configuration.
1849
+ */
1850
+ diffTracking: async (id) => {
1851
+ try {
1852
+ return await db.delete(tsDiffTracking).where(eq(tsDiffTracking.id, id)).then(() => {
1853
+ return {
1854
+ status: "success",
1855
+ message: `Diff tracking with ID ${id} has been deleted successfully`
1856
+ };
1857
+ });
1858
+ } catch (error) {
1859
+ if (error instanceof Error) {
1860
+ throw new StudioCMS_SDK_Error(
1861
+ `Error deleting diff tracking with ID ${id}: ${error.message}`,
1862
+ error.stack
1863
+ );
1864
+ }
1865
+ throw new StudioCMS_SDK_Error(
1866
+ `Error deleting diff tracking with ID ${id}: An unknown error occurred.`
1867
+ );
1868
+ }
1869
+ },
1870
+ /**
1871
+ * Deletes a folder from the database.
1872
+ *
1873
+ * @param id - The ID of the folder to delete.
1874
+ * @returns A promise that resolves to a deletion response.
1875
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the folder.
1876
+ */
1877
+ folder: async (id) => {
1878
+ try {
1879
+ return await db.delete(tsPageFolderStructure).where(eq(tsPageFolderStructure.id, id)).then(() => {
1880
+ return {
1881
+ status: "success",
1882
+ message: `Folder with ID ${id} has been deleted successfully`
1883
+ };
1884
+ });
1885
+ } catch (error) {
1886
+ if (error instanceof Error) {
1887
+ throw new StudioCMS_SDK_Error(
1888
+ `Error deleting folder with ID ${id}: ${error.message}`,
1889
+ error.stack
1890
+ );
1891
+ }
1892
+ throw new StudioCMS_SDK_Error(
1893
+ `Error deleting folder with ID ${id}: An unknown error occurred.`
1894
+ );
1895
+ }
1896
+ },
1897
+ /**
1898
+ * Deletes a user from the database.
1899
+ *
1900
+ * @param id - The ID of the user to delete.
1901
+ * @returns A promise that resolves to a deletion response.
1902
+ * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the user.
1903
+ */
1904
+ user: async (id) => {
1905
+ try {
1906
+ const verifyNoReference = await clearUserReferences(id);
1907
+ if (verifyNoReference) {
1908
+ return await db.delete(tsUsers).where(eq(tsUsers.id, id)).then(() => {
1909
+ return {
1910
+ status: "success",
1911
+ message: `User with ID ${id} has been deleted successfully`
1912
+ };
1913
+ });
1914
+ }
1915
+ throw new StudioCMS_SDK_Error(
1916
+ `There was an issue deleting User with ID ${id}. Please manually remove all references before deleting the user. Or try again.`
1917
+ );
1918
+ } catch (error) {
1919
+ if (error instanceof Error) {
1920
+ throw new StudioCMS_SDK_Error(
1921
+ `Error deleting user with ID ${id}: ${error.message}`,
1922
+ error.stack
1923
+ );
1924
+ }
1925
+ throw new StudioCMS_SDK_Error(
1926
+ `Error deleting user with ID ${id}: An unknown error occurred.`
1927
+ );
1928
+ }
1929
+ }
1930
+ };
1931
+ return {
1932
+ addPageToFolderTree,
1933
+ findNodeById,
1934
+ findNodeByPath,
1935
+ findNodesAlongPath,
1936
+ getFullPath,
1937
+ parseIdNumberArray,
1938
+ parseIdStringArray,
1939
+ generateRandomIDNumber,
1940
+ generateToken,
1941
+ testToken,
1942
+ combineRanks,
1943
+ verifyRank,
1944
+ buildFolderTree,
1945
+ getAvailableFolders,
1946
+ clearUserReferences,
1947
+ collectCategories,
1948
+ collectTags,
1949
+ collectPageData,
1950
+ collectUserData,
1951
+ generateRandomPassword,
1952
+ resetTokenBucket,
1953
+ diffTracking,
1954
+ AUTH,
1955
+ INIT,
1956
+ GET,
1957
+ POST,
1958
+ UPDATE,
1959
+ DELETE,
1960
+ db,
1961
+ REST_API
1962
+ };
1963
+ }
1964
+ export {
1965
+ studiocmsSDKCore
1966
+ };