studiocms 0.2.0 → 0.4.0

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 (293) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/dist/cli/add/index.d.ts +2 -2
  3. package/dist/cli/add/index.js +4 -3
  4. package/dist/cli/add/npm-utils.d.ts +6 -6
  5. package/dist/cli/add/tryToInstallPlugins.d.ts +1 -1
  6. package/dist/cli/add/tryToInstallPlugins.js +6 -5
  7. package/dist/cli/add/updateStudioCMSConfig.d.ts +1 -1
  8. package/dist/cli/add/updateStudioCMSConfig.js +3 -4
  9. package/dist/cli/add/validatePlugins.d.ts +1 -2
  10. package/dist/cli/add/validatePlugins.js +15 -9
  11. package/dist/cli/crypto/genJWT/index.d.ts +1 -1
  12. package/dist/cli/crypto/genJWT/index.js +8 -9
  13. package/dist/cli/crypto/index.d.ts +1 -1
  14. package/dist/cli/init/steps/env.js +14 -4
  15. package/dist/cli/init/steps/next.d.ts +1 -1
  16. package/dist/cli/init/steps/next.js +6 -5
  17. package/dist/cli/migrator/index.d.ts +1 -1
  18. package/dist/cli/migrator/index.js +2 -2
  19. package/dist/cli/users/index.d.ts +1 -1
  20. package/dist/cli/users/shared.js +2 -2
  21. package/dist/cli/users/steps/createUsers.js +7 -7
  22. package/dist/cli/users/steps/modifyUsers.js +2 -2
  23. package/dist/cli/users/steps/next.d.ts +1 -1
  24. package/dist/cli/utils/checkRequiredEnvVars.js +2 -2
  25. package/dist/cli/utils/context.d.ts +2 -4
  26. package/dist/cli/utils/context.js +1 -3
  27. package/dist/cli/utils/getCliDbClient.d.ts +1 -1
  28. package/dist/cli/utils/intro.d.ts +1 -1
  29. package/dist/cli/utils/loadConfig.d.ts +54 -49
  30. package/dist/cli/utils/loadConfig.js +5 -8
  31. package/dist/cli/utils/logger.js +3 -3
  32. package/dist/cli/utils/user-utils.d.ts +1 -1
  33. package/dist/cli/utils/user-utils.js +4 -3
  34. package/dist/client/apiClient.d.ts +4923 -0
  35. package/dist/client/apiClient.js +72 -0
  36. package/dist/config.d.ts +1734 -1
  37. package/dist/consts.d.ts +5 -5
  38. package/dist/consts.js +3 -2
  39. package/dist/db/plugins.d.ts +1 -1
  40. package/dist/db/plugins.js +5 -8
  41. package/dist/handlers/frontend/routes.d.ts +4 -18
  42. package/dist/handlers/frontend/routes.js +13 -152
  43. package/dist/handlers/frontend/types.d.ts +1 -1
  44. package/dist/handlers/frontend/utils.js +0 -18
  45. package/dist/handlers/pluginHandler.d.ts +34 -257
  46. package/dist/handlers/pluginHandler.js +92 -46
  47. package/dist/handlers/routeHandler.js +32 -11
  48. package/dist/handlers/setupDbStudio.d.ts +3 -1
  49. package/dist/handlers/setupDbStudio.js +19 -10
  50. package/dist/handlers/storage-manager/core/effectify-astro-context.d.ts +25 -0
  51. package/dist/handlers/storage-manager/core/effectify-astro-context.js +78 -0
  52. package/dist/handlers/storage-manager/no-op.d.ts +2 -2
  53. package/dist/handlers/storage-manager/no-op.js +2 -3
  54. package/dist/index.d.ts +0 -1
  55. package/dist/index.js +10 -20
  56. package/dist/integrations/robots/index.d.ts +2 -2
  57. package/dist/integrations/robots/index.js +1 -3
  58. package/dist/integrations/robots/schema.d.ts +102 -273
  59. package/dist/integrations/robots/schema.js +220 -209
  60. package/dist/plugins/analytics/assets/schemas.d.ts +14 -9
  61. package/dist/plugins/analytics/assets/schemas.js +25 -17
  62. package/dist/plugins/analytics/db-client.d.ts +1 -1
  63. package/dist/plugins/analytics/index.d.ts +823 -3
  64. package/dist/plugins/analytics/index.js +4 -5
  65. package/dist/plugins/analytics/schemas.d.ts +54 -62
  66. package/dist/plugins/analytics/schemas.js +64 -13
  67. package/dist/plugins/analytics/table.d.ts +1 -1
  68. package/dist/plugins.d.ts +0 -1
  69. package/dist/schemas/config/api.d.ts +17 -0
  70. package/dist/schemas/config/api.js +14 -0
  71. package/dist/schemas/config/auth.d.ts +55 -59
  72. package/dist/schemas/config/auth.js +34 -11
  73. package/dist/schemas/config/dashboard.d.ts +43 -79
  74. package/dist/schemas/config/dashboard.js +43 -12
  75. package/dist/schemas/config/db.d.ts +15 -17
  76. package/dist/schemas/config/db.js +13 -5
  77. package/dist/schemas/config/developer.d.ts +33 -45
  78. package/dist/schemas/config/developer.js +22 -5
  79. package/dist/schemas/config/index.d.ts +398 -521
  80. package/dist/schemas/config/index.js +115 -57
  81. package/dist/schemas/config/sdk.d.ts +50 -196
  82. package/dist/schemas/config/sdk.js +61 -73
  83. package/dist/schemas/custom.d.ts +40 -0
  84. package/dist/schemas/custom.js +41 -0
  85. package/dist/schemas/external-schemas.d.ts +171 -0
  86. package/dist/schemas/external-schemas.js +179 -0
  87. package/dist/schemas/index.d.ts +2 -0
  88. package/dist/schemas/index.js +2 -0
  89. package/dist/schemas/plugins/i18n.d.ts +59 -39
  90. package/dist/schemas/plugins/i18n.js +42 -5
  91. package/dist/schemas/plugins/index.d.ts +7126 -10296
  92. package/dist/schemas/plugins/index.js +260 -276
  93. package/dist/schemas/plugins/shared.d.ts +1293 -3718
  94. package/dist/schemas/plugins/shared.js +320 -329
  95. package/dist/test-utils.d.ts +15 -4
  96. package/dist/test-utils.js +27 -11
  97. package/dist/toolbar/db-viewer/db-shared-types.d.ts +6 -6
  98. package/dist/toolbar/db-viewer/studio/connection.d.ts +8 -4
  99. package/dist/toolbar/db-viewer/studio/connection.js +2 -28
  100. package/dist/toolbar/db-viewer/studio/env/libsql.d.ts +7 -0
  101. package/dist/toolbar/db-viewer/studio/env/libsql.js +17 -0
  102. package/dist/toolbar/db-viewer/studio/env/mysql.d.ts +7 -0
  103. package/dist/toolbar/db-viewer/studio/env/mysql.js +23 -0
  104. package/dist/toolbar/db-viewer/studio/env/postgres.d.ts +7 -0
  105. package/dist/toolbar/db-viewer/studio/env/postgres.js +23 -0
  106. package/dist/toolbar/db-viewer/studio/index.js +20 -56
  107. package/dist/toolbar/db-viewer/studio/type.d.ts +1 -2
  108. package/dist/toolbar/db-viewer/studio/virtual-connection/libsql.d.ts +3 -0
  109. package/dist/toolbar/db-viewer/studio/virtual-connection/libsql.js +24 -0
  110. package/dist/toolbar/db-viewer/studio/virtual-connection/mysql.d.ts +3 -0
  111. package/dist/toolbar/db-viewer/studio/virtual-connection/mysql.js +9 -0
  112. package/dist/toolbar/db-viewer/studio/virtual-connection/postgres.d.ts +3 -0
  113. package/dist/toolbar/db-viewer/studio/virtual-connection/postgres.js +9 -0
  114. package/dist/toolbar/db-viewer/viewer.js +20 -21
  115. package/dist/types.d.ts +30 -0
  116. package/dist/utils/effects/smtp.d.ts +1 -1
  117. package/dist/utils/lang-helper.d.ts +10 -2
  118. package/dist/virtual.d.ts +35 -28
  119. package/dist/virtuals/auth/core.d.ts +5 -5
  120. package/dist/virtuals/auth/verify-email.d.ts +6 -6
  121. package/dist/virtuals/components/Generator.astro +2 -2
  122. package/dist/virtuals/components/Renderer.astro +9 -1
  123. package/dist/virtuals/components/renderFn.d.ts +3 -1
  124. package/dist/virtuals/components/renderFn.js +18 -0
  125. package/dist/virtuals/lib/headDefaults.d.ts +4 -2
  126. package/dist/virtuals/lib/headDefaults.js +0 -2
  127. package/dist/virtuals/lib/routeMap.d.ts +0 -12
  128. package/dist/virtuals/lib/routeMap.js +2 -14
  129. package/dist/virtuals/mailer/index.d.ts +3 -3
  130. package/dist/virtuals/notifier/index.d.ts +5 -5
  131. package/dist/virtuals/plugins/dashboard-pages.d.ts +2 -64
  132. package/dist/virtuals/scripts/StorageFileBrowser.d.ts +1 -172
  133. package/dist/virtuals/scripts/StorageFileBrowser.js +216 -119
  134. package/dist/virtuals/template-engine/index.d.ts +4 -4
  135. package/frontend/components/dashboard/configuration/ConfigForm.astro +218 -110
  136. package/frontend/components/dashboard/content-mgmt/ContentSearch.astro +21 -22
  137. package/frontend/components/dashboard/content-mgmt/CreateFolder.astro +66 -54
  138. package/frontend/components/dashboard/content-mgmt/CreatePage.astro +58 -104
  139. package/frontend/components/dashboard/content-mgmt/EditFolder.astro +65 -67
  140. package/frontend/components/dashboard/content-mgmt/EditPage.astro +86 -134
  141. package/frontend/components/dashboard/content-mgmt/InnerSidebarElement.astro +0 -1
  142. package/frontend/components/dashboard/content-mgmt/PageHeader.astro +33 -52
  143. package/frontend/components/dashboard/content-mgmt/PageTypeHandler.astro +2 -2
  144. package/frontend/components/dashboard/profile/APITokens.astro +219 -158
  145. package/frontend/components/dashboard/profile/BasicInfo.astro +165 -106
  146. package/frontend/components/dashboard/profile/Notifications.astro +27 -18
  147. package/frontend/components/dashboard/profile/UpdatePassword.astro +134 -94
  148. package/frontend/components/dashboard/sidebar/VersionCheck.astro +31 -16
  149. package/frontend/components/dashboard/sidebar/VersionCheckChangelog.astro +18 -11
  150. package/frontend/components/dashboard/sidebar-modals/VersionModal.astro +2 -2
  151. package/frontend/components/dashboard/smtp-config/TemplateEditor.astro +14 -14
  152. package/frontend/components/dashboard/taxonomy/InnerSidebarElement.astro +0 -1
  153. package/frontend/components/dashboard/taxonomy/MetaContainer.astro +0 -2
  154. package/frontend/components/dashboard/taxonomy/PageHeader.astro +16 -24
  155. package/frontend/components/dashboard/taxonomy/TaxonomySearch.astro +23 -27
  156. package/frontend/components/dashboard/user-mgmt/InnerSidebarElement.astro +111 -104
  157. package/frontend/components/dashboard/user-mgmt/UserListItem.astro +9 -22
  158. package/frontend/components/dashboard/user-mgmt/UserListItems.astro +18 -0
  159. package/frontend/components/first-time-setup/snippets/{opt2-studiocms.config.diff → studiocms.config.diff} +1 -0
  160. package/frontend/components/shared/Code.astro +1 -4
  161. package/frontend/components/shared/DynamicSettingsRenderer.astro +1 -1
  162. package/frontend/components/shared/SSRUser.astro +2 -4
  163. package/frontend/components/shared/foldertree/FolderTreeNode.astro +0 -6
  164. package/frontend/components/shared/storage-manager/StorageCopyOutput.astro +0 -1
  165. package/frontend/components/shared/taxonomy/TaxonomyTreeNode.astro +0 -6
  166. package/frontend/layouts/DashboardLayout.astro +1 -10
  167. package/frontend/layouts/TaxonomyLayout.astro +0 -1
  168. package/frontend/middleware/index.ts +102 -61
  169. package/frontend/pages/404.astro +5 -9
  170. package/frontend/pages/[dashboard]/[...pluginPage].astro +10 -1
  171. package/frontend/pages/[dashboard]/configuration.astro +10 -1
  172. package/frontend/pages/[dashboard]/content-management/createfolder.astro +10 -1
  173. package/frontend/pages/[dashboard]/content-management/createpage.astro +10 -1
  174. package/frontend/pages/[dashboard]/content-management/diff.astro +39 -14
  175. package/frontend/pages/[dashboard]/content-management/editfolder.astro +10 -1
  176. package/frontend/pages/[dashboard]/content-management/editpage.astro +10 -1
  177. package/frontend/pages/[dashboard]/content-management/index.astro +10 -1
  178. package/frontend/pages/[dashboard]/index.astro +10 -1
  179. package/frontend/pages/[dashboard]/login.astro +86 -25
  180. package/frontend/pages/[dashboard]/password-reset.astro +22 -16
  181. package/frontend/pages/[dashboard]/plugins/[plugin].astro +10 -1
  182. package/frontend/pages/[dashboard]/profile.astro +10 -1
  183. package/frontend/pages/[dashboard]/signup.astro +153 -52
  184. package/frontend/pages/[dashboard]/smtp-configuration.astro +77 -75
  185. package/frontend/pages/[dashboard]/system-management.astro +10 -1
  186. package/frontend/pages/[dashboard]/taxonomy/categories.astro +30 -41
  187. package/frontend/pages/[dashboard]/taxonomy/index.astro +10 -0
  188. package/frontend/pages/[dashboard]/taxonomy/tags.astro +33 -43
  189. package/frontend/pages/[dashboard]/unverified-email.astro +29 -21
  190. package/frontend/pages/[dashboard]/user-management/edit.astro +170 -90
  191. package/frontend/pages/[dashboard]/user-management/index.astro +10 -1
  192. package/frontend/pages/studiocms_api/[...all].ts +106 -0
  193. package/frontend/pages/studiocms_api/_handlers/_utils/auth.ts +26 -0
  194. package/frontend/pages/studiocms_api/_handlers/_utils/changelog.ts +147 -0
  195. package/frontend/pages/studiocms_api/_handlers/_utils/db-studio-driver.ts +46 -0
  196. package/frontend/pages/studiocms_api/_handlers/_utils/parseLogLevel.ts +27 -0
  197. package/frontend/pages/studiocms_api/_handlers/auth/auth.ts +459 -0
  198. package/frontend/pages/studiocms_api/_handlers/auth/index.ts +17 -0
  199. package/frontend/pages/studiocms_api/_handlers/auth/oauth.ts +91 -0
  200. package/frontend/pages/studiocms_api/_handlers/dashboard/_shared.ts +57 -0
  201. package/frontend/pages/studiocms_api/_handlers/dashboard/apiTokens.ts +134 -0
  202. package/frontend/pages/studiocms_api/_handlers/dashboard/config.ts +64 -0
  203. package/frontend/pages/studiocms_api/_handlers/dashboard/content.ts +741 -0
  204. package/frontend/pages/studiocms_api/_handlers/dashboard/create.ts +480 -0
  205. package/frontend/pages/studiocms_api/_handlers/dashboard/emailNotifications.ts +49 -0
  206. package/frontend/pages/studiocms_api/_handlers/dashboard/index.ts +45 -0
  207. package/frontend/pages/studiocms_api/_handlers/dashboard/mailer.ts +136 -0
  208. package/frontend/pages/studiocms_api/_handlers/dashboard/plugins.ts +80 -0
  209. package/frontend/pages/studiocms_api/_handlers/dashboard/profile.ts +275 -0
  210. package/frontend/pages/studiocms_api/_handlers/dashboard/resetPassword.ts +140 -0
  211. package/frontend/pages/studiocms_api/_handlers/dashboard/search.ts +63 -0
  212. package/frontend/pages/studiocms_api/_handlers/dashboard/taxonomy.ts +285 -0
  213. package/frontend/pages/studiocms_api/_handlers/dashboard/templates.ts +75 -0
  214. package/frontend/pages/studiocms_api/_handlers/dashboard/users.ts +312 -0
  215. package/frontend/pages/studiocms_api/_handlers/dashboard/verifyEndpoints.ts +307 -0
  216. package/frontend/pages/studiocms_api/_handlers/integration/dbStudio.ts +98 -0
  217. package/frontend/pages/studiocms_api/_handlers/integration/index.ts +17 -0
  218. package/frontend/pages/studiocms_api/_handlers/integration/storageManager.ts +107 -0
  219. package/frontend/pages/studiocms_api/_handlers/rest-api/index.ts +8 -0
  220. package/frontend/pages/studiocms_api/_handlers/rest-api/v1/_shared.ts +41 -0
  221. package/frontend/pages/studiocms_api/_handlers/rest-api/v1/index.ts +17 -0
  222. package/frontend/pages/studiocms_api/_handlers/rest-api/v1/public.ts +195 -0
  223. package/frontend/pages/studiocms_api/_handlers/rest-api/v1/secure.ts +1726 -0
  224. package/frontend/pages/studiocms_api/_handlers/sdk.ts +129 -0
  225. package/frontend/pages/studiocms_api/_middleware/astroLocals.ts +36 -0
  226. package/frontend/pages/studiocms_api/_middleware/restApi.ts +56 -0
  227. package/frontend/pages/studiocms_api/integrations/[...all].ts +8 -0
  228. package/frontend/scripts/formdata.ts +219 -0
  229. package/frontend/setup-pages/3-done.astro +4 -20
  230. package/frontend/setup-pages/studiocms_api/dashboard/step-2.ts +3 -6
  231. package/frontend/styles/dashboard-base.css +0 -1
  232. package/frontend/web-vitals/endpoint.ts +2 -1
  233. package/package.json +35 -31
  234. package/dist/global.d.ts +0 -9
  235. package/frontend/components/dashboard/LoginChecker.astro +0 -68
  236. package/frontend/components/dashboard/user-mgmt/RankCheck.astro +0 -57
  237. package/frontend/components/first-time-setup/snippets/opt1-astro.config.diff +0 -14
  238. package/frontend/components/first-time-setup/snippets/opt2-astro.config.diff +0 -9
  239. package/frontend/middleware/_authmap.ts +0 -63
  240. package/frontend/pages/studiocms_api/auth/[path].ts +0 -390
  241. package/frontend/pages/studiocms_api/auth/[provider]/[...id].ts +0 -64
  242. package/frontend/pages/studiocms_api/auth/[provider]/_effects/index.ts +0 -101
  243. package/frontend/pages/studiocms_api/auth/_shared.ts +0 -52
  244. package/frontend/pages/studiocms_api/dashboard/api-tokens.ts +0 -115
  245. package/frontend/pages/studiocms_api/dashboard/config.ts +0 -74
  246. package/frontend/pages/studiocms_api/dashboard/content/diff.ts +0 -73
  247. package/frontend/pages/studiocms_api/dashboard/content/folder.ts +0 -220
  248. package/frontend/pages/studiocms_api/dashboard/content/page.ts +0 -359
  249. package/frontend/pages/studiocms_api/dashboard/create-reset-link.ts +0 -77
  250. package/frontend/pages/studiocms_api/dashboard/create-user-invite.ts +0 -231
  251. package/frontend/pages/studiocms_api/dashboard/create-user.ts +0 -186
  252. package/frontend/pages/studiocms_api/dashboard/email-notification-settings-site.ts +0 -74
  253. package/frontend/pages/studiocms_api/dashboard/mailer/check-email.ts +0 -75
  254. package/frontend/pages/studiocms_api/dashboard/mailer/config.ts +0 -136
  255. package/frontend/pages/studiocms_api/dashboard/plugins/[plugin].ts +0 -80
  256. package/frontend/pages/studiocms_api/dashboard/profile.ts +0 -245
  257. package/frontend/pages/studiocms_api/dashboard/resend-verify-email.ts +0 -77
  258. package/frontend/pages/studiocms_api/dashboard/reset-password.ts +0 -124
  259. package/frontend/pages/studiocms_api/dashboard/search-list.ts +0 -59
  260. package/frontend/pages/studiocms_api/dashboard/taxonomy-search.ts +0 -47
  261. package/frontend/pages/studiocms_api/dashboard/taxonomy.ts +0 -230
  262. package/frontend/pages/studiocms_api/dashboard/templates.ts +0 -74
  263. package/frontend/pages/studiocms_api/dashboard/update-user-notifications.ts +0 -86
  264. package/frontend/pages/studiocms_api/dashboard/users.ts +0 -236
  265. package/frontend/pages/studiocms_api/dashboard/verify-email.ts +0 -83
  266. package/frontend/pages/studiocms_api/dashboard/verify-session.ts +0 -187
  267. package/frontend/pages/studiocms_api/integrations/[type]/[...id].ts +0 -15
  268. package/frontend/pages/studiocms_api/integrations/[type]/_routes/db-studio.ts +0 -173
  269. package/frontend/pages/studiocms_api/integrations/[type]/_routes/storage.ts +0 -88
  270. package/frontend/pages/studiocms_api/partials/editor.astro +0 -74
  271. package/frontend/pages/studiocms_api/partials/render.astro +0 -39
  272. package/frontend/pages/studiocms_api/partials/user-list-items.astro +0 -43
  273. package/frontend/pages/studiocms_api/rest/utils/auth-token.ts +0 -59
  274. package/frontend/pages/studiocms_api/rest/v1/[type]/[...id].ts +0 -23
  275. package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/categories.ts +0 -267
  276. package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/folders.ts +0 -283
  277. package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/pages.ts +0 -505
  278. package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/settings.ts +0 -100
  279. package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/tags.ts +0 -229
  280. package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/users.ts +0 -553
  281. package/frontend/pages/studiocms_api/rest/v1/public/[type]/[...id].ts +0 -19
  282. package/frontend/pages/studiocms_api/rest/v1/public/[type]/_routes/categories.ts +0 -74
  283. package/frontend/pages/studiocms_api/rest/v1/public/[type]/_routes/folders.ts +0 -85
  284. package/frontend/pages/studiocms_api/rest/v1/public/[type]/_routes/pages.ts +0 -103
  285. package/frontend/pages/studiocms_api/rest/v1/public/[type]/_routes/tags.ts +0 -67
  286. package/frontend/pages/studiocms_api/sdk/[...path].ts +0 -97
  287. package/frontend/pages/studiocms_api/sdk/utils/changelog.ts +0 -119
  288. package/frontend/scripts/auth/formListener.ts +0 -81
  289. package/frontend/scripts/formdata-utils.ts +0 -116
  290. package/frontend/utils/build-partial-schema.ts +0 -46
  291. package/frontend/utils/errors.ts +0 -6
  292. package/frontend/utils/param-extractor.ts +0 -83
  293. package/frontend/utils/rest-router.ts +0 -444
@@ -1,359 +1,350 @@
1
- import { z } from "astro/zod";
1
+ import { ParseResult } from "effect";
2
+ import * as Schema from "effect/Schema";
2
3
  import { availableTranslationFileKeys } from "../../virtuals/i18n/v-files.js";
3
- const astroIntegrationSchema = z.object({
4
- name: z.string(),
5
- hooks: z.object({}).passthrough().default({})
6
- });
7
- const StudioCMSColorway = z.enum([
4
+ import {
5
+ AstroComponentSchema,
6
+ SanitizeOptionsSchema,
7
+ UIIconListSchema
8
+ } from "../external-schemas.js";
9
+ const I18nLabelSchema = Schema.transformOrFail(
10
+ Schema.Record({
11
+ key: Schema.String,
12
+ value: Schema.String
13
+ }),
14
+ Schema.Record({
15
+ key: Schema.String,
16
+ value: Schema.String
17
+ }),
18
+ {
19
+ strict: true,
20
+ decode: (input, _options, ast) => {
21
+ if (typeof input !== "object" || input === null) {
22
+ return ParseResult.fail(new ParseResult.Type(ast, input, "Expected an object"));
23
+ }
24
+ const result = {};
25
+ for (const key in input) {
26
+ if (typeof input[key] !== "string") {
27
+ return ParseResult.fail(
28
+ new ParseResult.Type(ast, input[key], `Expected value for key '${key}' to be a string`)
29
+ );
30
+ }
31
+ result[key] = input[key];
32
+ }
33
+ const unknown = Object.keys(result).filter((k) => !availableTranslationFileKeys.includes(k));
34
+ if (unknown.length > 0) {
35
+ return ParseResult.fail(
36
+ new ParseResult.Type(
37
+ ast,
38
+ input,
39
+ `Unknown/Unsupported translation keys: ${unknown.join(", ")}
40
+
41
+ Supported keys are: ${availableTranslationFileKeys.join(", ")}`
42
+ )
43
+ );
44
+ }
45
+ return ParseResult.succeed(result);
46
+ },
47
+ encode: (input) => ParseResult.succeed(input)
48
+ }
49
+ );
50
+ const StudioCMSColorwaySchema = Schema.Literal(
8
51
  "primary",
9
52
  "success",
10
53
  "warning",
11
54
  "danger",
12
55
  "info",
13
56
  "mono"
14
- ]);
15
- const BaseFieldSchema = z.object({
16
- /**
17
- * The name of the field used in the form submission data
18
- */
19
- name: z.string(),
20
- /**
21
- * The label of the field displayed in the form
22
- */
23
- label: z.string(),
24
- /**
25
- * Is the field required
26
- */
27
- required: z.boolean().optional(),
28
- /**
29
- * Is the field read only (disabled)
30
- */
31
- readOnly: z.boolean().optional()
32
- });
33
- const SupportsColorSchema = BaseFieldSchema.extend({
34
- color: StudioCMSColorway.optional()
35
- });
36
- const SupportsPlaceHolderSchema = BaseFieldSchema.extend({
37
- placeholder: z.string().optional()
38
- });
39
- const CheckboxFieldSchema = SupportsColorSchema.extend({
40
- input: z.literal("checkbox"),
41
- defaultChecked: z.boolean().optional(),
42
- size: z.enum(["sm", "md", "lg"]).optional()
43
- });
44
- const TextInputFieldSchema = SupportsPlaceHolderSchema.extend({
45
- input: z.literal("input"),
46
- type: z.enum(["text", "password", "email", "number", "tel", "url", "search"]).optional(),
47
- defaultValue: z.string().optional()
48
- });
49
- const TextAreaFieldSchema = SupportsPlaceHolderSchema.extend({
50
- input: z.literal("textarea"),
51
- defaultValue: z.string().optional()
57
+ );
58
+ const StudioCMSSizeSchema = Schema.Literal("sm", "md", "lg");
59
+ const SharedOptionsSchemaItem = Schema.Struct({
60
+ label: Schema.String,
61
+ value: Schema.String,
62
+ disabled: Schema.optional(Schema.Boolean)
52
63
  });
53
- const SharedOptionsSchema = z.array(
54
- z.object({
55
- label: z.string(),
56
- value: z.string(),
57
- disabled: z.boolean().optional()
58
- })
64
+ const SharedOptionsSchema = Schema.mutable(Schema.Array(SharedOptionsSchemaItem));
65
+ const StudioCMSPermissionsSchema = Schema.Literal(
66
+ "owner",
67
+ "admin",
68
+ "editor",
69
+ "visitor",
70
+ "none"
59
71
  );
60
- const RadioGroupFieldSchema = SupportsColorSchema.extend({
61
- input: z.literal("radio"),
62
- direction: z.enum(["horizontal", "vertical"]).optional(),
63
- defaultValue: z.string().optional(),
72
+ class BaseFieldSchema extends Schema.Class("BaseFieldSchema")({
73
+ name: Schema.String,
74
+ label: Schema.String,
75
+ required: Schema.optional(Schema.Boolean),
76
+ readOnly: Schema.optional(Schema.Boolean)
77
+ }) {
78
+ }
79
+ class SupportsColorwaySchema extends BaseFieldSchema.extend(
80
+ "SupportsColorwaySchema"
81
+ )({
82
+ color: Schema.optional(StudioCMSColorwaySchema)
83
+ }) {
84
+ }
85
+ class SupportsPlaceHolderSchema extends BaseFieldSchema.extend(
86
+ "SupportsPlaceHolderSchema"
87
+ )({
88
+ placeholder: Schema.optional(Schema.String)
89
+ }) {
90
+ }
91
+ class CheckboxFieldSchema extends SupportsColorwaySchema.extend(
92
+ "CheckboxFieldSchema"
93
+ )({
94
+ input: Schema.Literal("checkbox"),
95
+ defaultChecked: Schema.optional(Schema.Boolean),
96
+ size: Schema.optional(StudioCMSSizeSchema)
97
+ }) {
98
+ }
99
+ class TextInputFieldSchema extends SupportsPlaceHolderSchema.extend(
100
+ "TextInputFieldSchema"
101
+ )({
102
+ input: Schema.Literal("input"),
103
+ type: Schema.optional(
104
+ Schema.Literal("text", "password", "email", "number", "tel", "url", "search")
105
+ ),
106
+ defaultValue: Schema.optional(Schema.String)
107
+ }) {
108
+ }
109
+ class TextAreaFieldSchema extends SupportsPlaceHolderSchema.extend(
110
+ "TextAreaFieldSchema"
111
+ )({
112
+ input: Schema.Literal("textarea"),
113
+ defaultValue: Schema.optional(Schema.String)
114
+ }) {
115
+ }
116
+ class RadioGroupFieldSchema extends SupportsColorwaySchema.extend(
117
+ "RadioGroupFieldSchema"
118
+ )({
119
+ input: Schema.Literal("radio"),
120
+ direction: Schema.optional(Schema.Literal("horizontal", "vertical")),
121
+ defaultValue: Schema.optional(Schema.String),
64
122
  options: SharedOptionsSchema
65
- });
66
- const SelectFieldSchema = SupportsPlaceHolderSchema.extend({
67
- input: z.literal("select"),
68
- type: z.enum(["basic", "search"]).optional(),
69
- defaultValue: z.string().optional(),
123
+ }) {
124
+ }
125
+ class SelectFieldSchema extends SupportsColorwaySchema.extend(
126
+ "SelectFieldSchema"
127
+ )({
128
+ input: Schema.Literal("select"),
129
+ type: Schema.optional(Schema.Literal("basic", "search")),
130
+ defaultValue: Schema.optional(Schema.String),
70
131
  options: SharedOptionsSchema
71
- });
72
- const FieldSchema = z.union([
132
+ }) {
133
+ }
134
+ const FieldSchema = Schema.Union(
73
135
  CheckboxFieldSchema,
74
136
  TextInputFieldSchema,
75
137
  TextAreaFieldSchema,
76
138
  RadioGroupFieldSchema,
77
139
  SelectFieldSchema
78
- ]);
79
- const RowFieldSchema = BaseFieldSchema.extend({
80
- input: z.literal("row"),
81
- alignCenter: z.boolean().optional(),
82
- gapSize: z.enum(["sm", "md", "lg"]).optional(),
83
- fields: z.lazy(() => FieldSchema.array())
84
- // Recursive definition
85
- });
86
- const SettingsFieldSchema = z.union([FieldSchema, RowFieldSchema]);
87
- const i18nLabelSchema = z.record(z.string().min(1)).superRefine((val, ctx) => {
88
- const unknown = Object.keys(val).filter((k) => !availableTranslationFileKeys.includes(k));
89
- if (unknown.length) {
90
- ctx.addIssue({
91
- code: z.ZodIssueCode.custom,
92
- message: `Unsupported locale keys: ${unknown.join(", ")}. Allowed: ${availableTranslationFileKeys.join(", ")}.`
93
- });
140
+ );
141
+ class RowFieldSchema extends BaseFieldSchema.extend("RowFieldSchema")({
142
+ input: Schema.Literal("row"),
143
+ alignCenter: Schema.optional(Schema.Boolean),
144
+ gapSize: Schema.optional(StudioCMSSizeSchema),
145
+ fields: Schema.Array(FieldSchema)
146
+ }) {
147
+ }
148
+ const SettingsFieldSchema = Schema.Union(FieldSchema, RowFieldSchema);
149
+ class BaseDashboardPagePropsSchema extends Schema.Class(
150
+ "BaseDashboardPagePropsSchema"
151
+ )({
152
+ title: I18nLabelSchema,
153
+ description: Schema.String,
154
+ route: Schema.String,
155
+ icon: Schema.optionalWith(UIIconListSchema, {
156
+ default: () => "heroicons:cube-transparent"
157
+ }),
158
+ requiredPermissions: Schema.optionalWith(StudioCMSPermissionsSchema, {
159
+ default: () => "none"
160
+ }),
161
+ pageActionsComponent: Schema.optional(Schema.String),
162
+ pageBodyComponent: Schema.String
163
+ }) {
164
+ }
165
+ class AvailableBaseSchema extends BaseDashboardPagePropsSchema.extend(
166
+ "AvailableBaseSchema"
167
+ )({
168
+ slug: Schema.String
169
+ }) {
170
+ }
171
+ class FinalBaseSchema extends AvailableBaseSchema.extend("FinalBaseSchema")(
172
+ {
173
+ components: Schema.Struct({
174
+ PageActionsComponent: Schema.optional(AstroComponentSchema),
175
+ PageBodyComponent: AstroComponentSchema,
176
+ InnerSidebarComponent: Schema.optional(AstroComponentSchema)
177
+ })
94
178
  }
95
- });
96
- const BaseDashboardPagePropsSchema = z.object({
97
- /**
98
- * The title of the dashboard page
99
- */
100
- title: i18nLabelSchema,
101
- /**
102
- * The description of the dashboard page
103
- */
104
- description: z.string(),
105
- /**
106
- * The desired route of the dashboard page
107
- */
108
- route: z.string(),
109
- /**
110
- * The icon to display in the sidebar
111
- *
112
- * @default 'cube-transparent'
113
- * @optional
114
- */
115
- icon: z.string().default("heroicons:cube-transparent").optional(),
116
- /**
117
- * The required permissions to access the page
118
- */
119
- requiredPermissions: z.union([
120
- z.literal("owner"),
121
- z.literal("admin"),
122
- z.literal("editor"),
123
- z.literal("visitor"),
124
- z.literal("none")
125
- ]).default("none").optional(),
126
- /**
127
- * The component to render in the page header to display action buttons
128
- */
129
- pageActionsComponent: z.string().optional(),
130
- /**
131
- * The component to render in the page body
132
- */
133
- pageBodyComponent: z.string()
134
- });
135
- const AvailableBaseSchema = BaseDashboardPagePropsSchema.extend({
136
- /**
137
- * The slug of the dashboard page
138
- */
139
- slug: z.string()
140
- });
141
- const AstroComponentSchema = z.custom();
142
- const FinalBaseSchema = AvailableBaseSchema.extend({
143
- components: z.object({
144
- PageActionsComponent: AstroComponentSchema.optional(),
145
- PageBodyComponent: AstroComponentSchema,
146
- InnerSidebarComponent: AstroComponentSchema.optional()
147
- })
148
- });
149
- const SingleSidebarSchema = BaseDashboardPagePropsSchema.extend({
150
- /**
151
- * The sidebar layout
152
- */
153
- sidebar: z.literal("single")
154
- });
155
- const AvailableSingleSchema = AvailableBaseSchema.extend({
156
- /**
157
- * The sidebar layout
158
- */
159
- sidebar: z.literal("single")
160
- });
161
- const FinalSingleSchema = FinalBaseSchema.extend({
162
- /**
163
- * The sidebar layout
164
- */
165
- sidebar: z.literal("single")
166
- });
167
- const DoubleSidebarSchema = BaseDashboardPagePropsSchema.extend({
168
- /**
169
- * The sidebar layout
170
- */
171
- sidebar: z.literal("double"),
172
- /**
173
- * The component to render in the inner sidebar
174
- */
175
- innerSidebarComponent: z.string()
176
- });
177
- const AvailableDoubleSchema = AvailableBaseSchema.extend({
178
- /**
179
- * The sidebar layout
180
- */
181
- sidebar: z.literal("double"),
182
- /**
183
- * The component to render in the inner sidebar
184
- */
185
- innerSidebarComponent: z.string()
186
- });
187
- const FinalDoubleSchema = FinalBaseSchema.extend({
188
- /**
189
- * The sidebar layout
190
- */
191
- sidebar: z.literal("double"),
192
- /**
193
- * The component to render in the inner sidebar
194
- */
195
- innerSidebarComponent: z.string()
196
- });
197
- const DashboardPageSchema = z.union([SingleSidebarSchema, DoubleSidebarSchema]);
198
- const AvailableDashboardBaseSchema = z.union([AvailableSingleSchema, AvailableDoubleSchema]);
199
- const FinalDashboardBaseSchema = z.union([FinalSingleSchema, FinalDoubleSchema]);
200
- const AvailableDashboardPagesSchema = z.object({
201
- /**
202
- * Available dashboard pages for users
203
- */
204
- user: z.array(AvailableDashboardBaseSchema).optional(),
205
- /**
206
- * Available dashboard pages for admins
207
- */
208
- admin: z.array(AvailableDashboardBaseSchema).optional()
209
- });
210
- const SettingsPageSchema = z.object({
211
- /**
212
- * Fields according to specification
213
- */
214
- fields: z.array(SettingsFieldSchema),
215
- /**
216
- * The endpoint for the settings
217
- *
218
- * Should export a APIRoute named `onSave` that runs when the settings page is saved
219
- */
220
- endpoint: z.string()
221
- }).optional();
222
- const FrontendNavigationLinksSchema = z.array(
223
- z.object({
224
- /**
225
- * Display label for the link
226
- */
227
- label: z.string(),
228
- /**
229
- * URL to link to
230
- */
231
- href: z.string()
179
+ ) {
180
+ }
181
+ class SingleSidebarSchema extends BaseDashboardPagePropsSchema.extend(
182
+ "SingleSidebarSchema"
183
+ )({
184
+ sidebar: Schema.Literal("single")
185
+ }) {
186
+ }
187
+ class AvailableSingleSchema extends AvailableBaseSchema.extend(
188
+ "AvailableSingleSchema"
189
+ )({
190
+ sidebar: Schema.Literal("single")
191
+ }) {
192
+ }
193
+ class FinalSingleSchema extends FinalBaseSchema.extend(
194
+ "FinalSingleSchema"
195
+ )({
196
+ sidebar: Schema.Literal("single")
197
+ }) {
198
+ }
199
+ class DoubleSidebarSchema extends BaseDashboardPagePropsSchema.extend(
200
+ "DoubleSidebarSchema"
201
+ )({
202
+ sidebar: Schema.Literal("double"),
203
+ innerSidebarComponent: Schema.String
204
+ }) {
205
+ }
206
+ class AvailableDoubleSchema extends AvailableBaseSchema.extend(
207
+ "AvailableDoubleSchema"
208
+ )({
209
+ sidebar: Schema.Literal("double"),
210
+ innerSidebarComponent: Schema.String
211
+ }) {
212
+ }
213
+ class FinalDoubleSchema extends FinalBaseSchema.extend(
214
+ "FinalDoubleSchema"
215
+ )({
216
+ sidebar: Schema.Literal("double"),
217
+ innerSidebarComponent: Schema.String
218
+ }) {
219
+ }
220
+ const DashboardPageSchema = Schema.Union(SingleSidebarSchema, DoubleSidebarSchema);
221
+ const AvailableDashboardBaseSchema = Schema.Union(
222
+ AvailableSingleSchema,
223
+ AvailableDoubleSchema
224
+ );
225
+ const FinalDashboardBaseSchema = Schema.Union(FinalSingleSchema, FinalDoubleSchema);
226
+ const AvailableDashboardPagesSchema = Schema.mutable(
227
+ Schema.Struct({
228
+ user: Schema.optional(Schema.mutable(Schema.Array(AvailableDashboardBaseSchema))),
229
+ admin: Schema.optional(Schema.mutable(Schema.Array(AvailableDashboardBaseSchema)))
232
230
  })
233
- ).optional();
234
- const PageTypesSchema = z.array(
235
- z.object({
236
- /**
237
- * Label that is shown in the select input
238
- */
239
- label: z.string(),
240
- /**
241
- * Identifier that is saved in the database
242
- * @example
243
- * // Single page type per plugin
244
- * 'studiocms'
245
- * '@studiocms/blog'
246
- * // Multiple page types per plugin (Use unique identifiers for each type to avoid conflicts)
247
- * '@mystudiocms/plugin:pageType1'
248
- * '@mystudiocms/plugin:pageType2'
249
- * '@mystudiocms/plugin:pageType3'
250
- * '@mystudiocms/plugin:pageType4'
251
- */
252
- identifier: z.string(),
253
- /**
254
- * Description that is shown below the "Page Content" header if this type is selected
255
- */
256
- description: z.string().optional(),
257
- /**
258
- * The path to the actual component that is displayed for the page content
259
- *
260
- * Component should have a `content` prop that is a string to be able to display current content.
261
- *
262
- * **NOTE:** If you storing a single string in the database, you can use the form name `page-content` for the content output. and it will be stored in the normal `content` field in the database.
263
- * You can also use the apiEndpoints to create custom endpoints for the page type.
264
- *
265
- * @example
266
- * ```ts
267
- * import { createResolver } from 'astro-integration-kit';
268
- * const { resolve } = createResolver(import.meta.url)
269
- *
270
- * {
271
- * pageContentComponent: resolve('./components/MyContentEditor.astro'),
272
- * }
273
- * ```
274
- */
275
- pageContentComponent: z.string().optional(),
276
- /**
277
- * The path to the file that contains the default exported object with the `PluginRenderer` interface.
278
- *
279
- * This is used to render the content on the frontend.
280
- *
281
- * ```ts
282
- * import { createResolver } from 'astro-integration-kit';
283
- * const { resolve } = createResolver(import.meta.url);
284
- *
285
- * {
286
- * rendererComponent: resolve('./renderers/MyRenderer.ts'),
287
- * }
288
- * ```
289
- *
290
- * with the following export in `MyRenderer.ts`:
291
- * ```ts
292
- * import type { PluginRenderer } from 'studiocms/types';
293
- *
294
- * const MyRenderer: PluginRenderer = {
295
- * name: 'my-renderer',
296
- * sanitizeOpts: {
297
- * // ultrahtml sanitize options
298
- * },
299
- * renderer: async (content) => {
300
- * // Custom rendering logic here
301
- * return `<div class="my-rendered-content">${content}</div>`;
302
- * },
303
- * };
304
- *
305
- * export default MyRenderer;
306
- * ```
307
- */
308
- rendererComponent: z.string().optional(),
309
- /**
310
- * Fields that are shown in the page metadata tab when creating or editing a page of this type
311
- */
312
- fields: z.array(SettingsFieldSchema).optional(),
313
- /**
314
- * API Endpoint file for the page type
315
- *
316
- * API endpoints are used to create, edit, and delete pages of this type,
317
- * endpoints will be provided the full Astro APIContext from the Astro APIRoute.
318
- *
319
- * File should export at least one of the following:
320
- * - `onCreate`
321
- * - `onEdit`
322
- * - `onDelete`
323
- *
324
- * @example
325
- * ```ts
326
- * // my-plugin.ts
327
- * import { createResolver } from 'astro-integration-kit';
328
- * const { resolve } = createResolver(import.meta.url)
329
- *
330
- * {
331
- * apiEndpoint: resolve('./api/pageTypeApi.ts'),
332
- * }
333
- *
334
- * // api/pageTypeApi.ts
335
- * import { PluginAPIRoute } from 'studiocms/plugins';
336
- *
337
- * export const onCreate: PluginAPIRoute<'onCreate'> = async ({ AstroCtx, pageData }) => {
338
- * // Custom logic here
339
- * return new Response();
340
- * }
341
- * ```
342
- */
343
- apiEndpoint: z.string().optional()
231
+ );
232
+ const SettingsPageSchema = Schema.optional(
233
+ Schema.Struct({
234
+ fields: Schema.Array(SettingsFieldSchema),
235
+ endpoint: Schema.String
344
236
  })
345
- ).optional();
237
+ );
238
+ const FrontendNavigationLinksSchema = Schema.optional(
239
+ Schema.Array(
240
+ Schema.Struct({
241
+ label: Schema.String,
242
+ href: Schema.String
243
+ })
244
+ )
245
+ );
246
+ const PageTypesSchema = Schema.optional(
247
+ Schema.Array(
248
+ Schema.Struct({
249
+ label: Schema.String,
250
+ identifier: Schema.String,
251
+ description: Schema.optional(Schema.String),
252
+ pageContentComponent: Schema.optional(Schema.String),
253
+ rendererComponent: Schema.optional(Schema.String),
254
+ fields: Schema.optional(Schema.Array(SettingsFieldSchema)),
255
+ apiEndpoint: Schema.optional(Schema.String)
256
+ })
257
+ )
258
+ );
259
+ class GridItemInputBaseSchema extends Schema.Class(
260
+ "GridItemInputBaseSchema"
261
+ )({
262
+ name: Schema.String,
263
+ span: Schema.Literal(1, 2, 3),
264
+ variant: Schema.Literal("default", "filled"),
265
+ requiresPermission: Schema.optional(Schema.Literal("owner", "admin", "editor", "visitor")),
266
+ header: Schema.optional(
267
+ Schema.Struct({
268
+ title: Schema.String,
269
+ icon: Schema.optional(UIIconListSchema)
270
+ })
271
+ )
272
+ }) {
273
+ }
274
+ class GridItemInputSchema extends GridItemInputBaseSchema.extend(
275
+ "GridItemInputSchema"
276
+ )({
277
+ body: Schema.optional(
278
+ Schema.Struct({
279
+ html: Schema.String,
280
+ components: Schema.optional(
281
+ Schema.Record({
282
+ key: Schema.String,
283
+ value: Schema.String
284
+ })
285
+ ),
286
+ sanitizeOpts: Schema.optional(SanitizeOptionsSchema)
287
+ })
288
+ )
289
+ }) {
290
+ }
291
+ class GridItemUsableSchema extends GridItemInputBaseSchema.extend(
292
+ "GridItemUsableSchema"
293
+ )({
294
+ body: Schema.optional(
295
+ Schema.Struct({
296
+ html: Schema.String,
297
+ components: Schema.optional(
298
+ Schema.Record({
299
+ key: Schema.String,
300
+ value: Schema.Any
301
+ })
302
+ ),
303
+ sanitizeOpts: Schema.optional(SanitizeOptionsSchema)
304
+ })
305
+ )
306
+ }) {
307
+ }
308
+ class GridItemSchema extends GridItemUsableSchema.extend("GridItemSchema")({
309
+ enabled: Schema.Boolean
310
+ }) {
311
+ }
346
312
  export {
313
+ AvailableBaseSchema,
347
314
  AvailableDashboardBaseSchema,
348
315
  AvailableDashboardPagesSchema,
316
+ AvailableDoubleSchema,
317
+ AvailableSingleSchema,
318
+ BaseDashboardPagePropsSchema,
319
+ BaseFieldSchema,
320
+ CheckboxFieldSchema,
349
321
  DashboardPageSchema,
322
+ DoubleSidebarSchema,
350
323
  FieldSchema,
324
+ FinalBaseSchema,
351
325
  FinalDashboardBaseSchema,
326
+ FinalDoubleSchema,
327
+ FinalSingleSchema,
352
328
  FrontendNavigationLinksSchema,
329
+ GridItemInputBaseSchema,
330
+ GridItemInputSchema,
331
+ GridItemSchema,
332
+ GridItemUsableSchema,
333
+ I18nLabelSchema,
353
334
  PageTypesSchema,
335
+ RadioGroupFieldSchema,
336
+ RowFieldSchema,
337
+ SelectFieldSchema,
354
338
  SettingsFieldSchema,
355
339
  SettingsPageSchema,
356
- StudioCMSColorway,
357
- astroIntegrationSchema,
358
- i18nLabelSchema
340
+ SharedOptionsSchema,
341
+ SharedOptionsSchemaItem,
342
+ SingleSidebarSchema,
343
+ StudioCMSColorwaySchema,
344
+ StudioCMSPermissionsSchema,
345
+ StudioCMSSizeSchema,
346
+ SupportsColorwaySchema,
347
+ SupportsPlaceHolderSchema,
348
+ TextAreaFieldSchema,
349
+ TextInputFieldSchema
359
350
  };