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.
- package/CHANGELOG.md +122 -0
- package/dist/cli/add/index.d.ts +2 -2
- package/dist/cli/add/index.js +4 -3
- package/dist/cli/add/npm-utils.d.ts +6 -6
- package/dist/cli/add/tryToInstallPlugins.d.ts +1 -1
- package/dist/cli/add/tryToInstallPlugins.js +6 -5
- package/dist/cli/add/updateStudioCMSConfig.d.ts +1 -1
- package/dist/cli/add/updateStudioCMSConfig.js +3 -4
- package/dist/cli/add/validatePlugins.d.ts +1 -2
- package/dist/cli/add/validatePlugins.js +15 -9
- package/dist/cli/crypto/genJWT/index.d.ts +1 -1
- package/dist/cli/crypto/genJWT/index.js +8 -9
- package/dist/cli/crypto/index.d.ts +1 -1
- package/dist/cli/init/steps/env.js +14 -4
- package/dist/cli/init/steps/next.d.ts +1 -1
- package/dist/cli/init/steps/next.js +6 -5
- package/dist/cli/migrator/index.d.ts +1 -1
- package/dist/cli/migrator/index.js +2 -2
- package/dist/cli/users/index.d.ts +1 -1
- package/dist/cli/users/shared.js +2 -2
- package/dist/cli/users/steps/createUsers.js +7 -7
- package/dist/cli/users/steps/modifyUsers.js +2 -2
- package/dist/cli/users/steps/next.d.ts +1 -1
- package/dist/cli/utils/checkRequiredEnvVars.js +2 -2
- package/dist/cli/utils/context.d.ts +2 -4
- package/dist/cli/utils/context.js +1 -3
- package/dist/cli/utils/getCliDbClient.d.ts +1 -1
- package/dist/cli/utils/intro.d.ts +1 -1
- package/dist/cli/utils/loadConfig.d.ts +54 -49
- package/dist/cli/utils/loadConfig.js +5 -8
- package/dist/cli/utils/logger.js +3 -3
- package/dist/cli/utils/user-utils.d.ts +1 -1
- package/dist/cli/utils/user-utils.js +4 -3
- package/dist/client/apiClient.d.ts +4923 -0
- package/dist/client/apiClient.js +72 -0
- package/dist/config.d.ts +1734 -1
- package/dist/consts.d.ts +5 -5
- package/dist/consts.js +3 -2
- package/dist/db/plugins.d.ts +1 -1
- package/dist/db/plugins.js +5 -8
- package/dist/handlers/frontend/routes.d.ts +4 -18
- package/dist/handlers/frontend/routes.js +13 -152
- package/dist/handlers/frontend/types.d.ts +1 -1
- package/dist/handlers/frontend/utils.js +0 -18
- package/dist/handlers/pluginHandler.d.ts +34 -257
- package/dist/handlers/pluginHandler.js +92 -46
- package/dist/handlers/routeHandler.js +32 -11
- package/dist/handlers/setupDbStudio.d.ts +3 -1
- package/dist/handlers/setupDbStudio.js +19 -10
- package/dist/handlers/storage-manager/core/effectify-astro-context.d.ts +25 -0
- package/dist/handlers/storage-manager/core/effectify-astro-context.js +78 -0
- package/dist/handlers/storage-manager/no-op.d.ts +2 -2
- package/dist/handlers/storage-manager/no-op.js +2 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +10 -20
- package/dist/integrations/robots/index.d.ts +2 -2
- package/dist/integrations/robots/index.js +1 -3
- package/dist/integrations/robots/schema.d.ts +102 -273
- package/dist/integrations/robots/schema.js +220 -209
- package/dist/plugins/analytics/assets/schemas.d.ts +14 -9
- package/dist/plugins/analytics/assets/schemas.js +25 -17
- package/dist/plugins/analytics/db-client.d.ts +1 -1
- package/dist/plugins/analytics/index.d.ts +823 -3
- package/dist/plugins/analytics/index.js +4 -5
- package/dist/plugins/analytics/schemas.d.ts +54 -62
- package/dist/plugins/analytics/schemas.js +64 -13
- package/dist/plugins/analytics/table.d.ts +1 -1
- package/dist/plugins.d.ts +0 -1
- package/dist/schemas/config/api.d.ts +17 -0
- package/dist/schemas/config/api.js +14 -0
- package/dist/schemas/config/auth.d.ts +55 -59
- package/dist/schemas/config/auth.js +34 -11
- package/dist/schemas/config/dashboard.d.ts +43 -79
- package/dist/schemas/config/dashboard.js +43 -12
- package/dist/schemas/config/db.d.ts +15 -17
- package/dist/schemas/config/db.js +13 -5
- package/dist/schemas/config/developer.d.ts +33 -45
- package/dist/schemas/config/developer.js +22 -5
- package/dist/schemas/config/index.d.ts +398 -521
- package/dist/schemas/config/index.js +115 -57
- package/dist/schemas/config/sdk.d.ts +50 -196
- package/dist/schemas/config/sdk.js +61 -73
- package/dist/schemas/custom.d.ts +40 -0
- package/dist/schemas/custom.js +41 -0
- package/dist/schemas/external-schemas.d.ts +171 -0
- package/dist/schemas/external-schemas.js +179 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.js +2 -0
- package/dist/schemas/plugins/i18n.d.ts +59 -39
- package/dist/schemas/plugins/i18n.js +42 -5
- package/dist/schemas/plugins/index.d.ts +7126 -10296
- package/dist/schemas/plugins/index.js +260 -276
- package/dist/schemas/plugins/shared.d.ts +1293 -3718
- package/dist/schemas/plugins/shared.js +320 -329
- package/dist/test-utils.d.ts +15 -4
- package/dist/test-utils.js +27 -11
- package/dist/toolbar/db-viewer/db-shared-types.d.ts +6 -6
- package/dist/toolbar/db-viewer/studio/connection.d.ts +8 -4
- package/dist/toolbar/db-viewer/studio/connection.js +2 -28
- package/dist/toolbar/db-viewer/studio/env/libsql.d.ts +7 -0
- package/dist/toolbar/db-viewer/studio/env/libsql.js +17 -0
- package/dist/toolbar/db-viewer/studio/env/mysql.d.ts +7 -0
- package/dist/toolbar/db-viewer/studio/env/mysql.js +23 -0
- package/dist/toolbar/db-viewer/studio/env/postgres.d.ts +7 -0
- package/dist/toolbar/db-viewer/studio/env/postgres.js +23 -0
- package/dist/toolbar/db-viewer/studio/index.js +20 -56
- package/dist/toolbar/db-viewer/studio/type.d.ts +1 -2
- package/dist/toolbar/db-viewer/studio/virtual-connection/libsql.d.ts +3 -0
- package/dist/toolbar/db-viewer/studio/virtual-connection/libsql.js +24 -0
- package/dist/toolbar/db-viewer/studio/virtual-connection/mysql.d.ts +3 -0
- package/dist/toolbar/db-viewer/studio/virtual-connection/mysql.js +9 -0
- package/dist/toolbar/db-viewer/studio/virtual-connection/postgres.d.ts +3 -0
- package/dist/toolbar/db-viewer/studio/virtual-connection/postgres.js +9 -0
- package/dist/toolbar/db-viewer/viewer.js +20 -21
- package/dist/types.d.ts +30 -0
- package/dist/utils/effects/smtp.d.ts +1 -1
- package/dist/utils/lang-helper.d.ts +10 -2
- package/dist/virtual.d.ts +35 -28
- package/dist/virtuals/auth/core.d.ts +5 -5
- package/dist/virtuals/auth/verify-email.d.ts +6 -6
- package/dist/virtuals/components/Generator.astro +2 -2
- package/dist/virtuals/components/Renderer.astro +9 -1
- package/dist/virtuals/components/renderFn.d.ts +3 -1
- package/dist/virtuals/components/renderFn.js +18 -0
- package/dist/virtuals/lib/headDefaults.d.ts +4 -2
- package/dist/virtuals/lib/headDefaults.js +0 -2
- package/dist/virtuals/lib/routeMap.d.ts +0 -12
- package/dist/virtuals/lib/routeMap.js +2 -14
- package/dist/virtuals/mailer/index.d.ts +3 -3
- package/dist/virtuals/notifier/index.d.ts +5 -5
- package/dist/virtuals/plugins/dashboard-pages.d.ts +2 -64
- package/dist/virtuals/scripts/StorageFileBrowser.d.ts +1 -172
- package/dist/virtuals/scripts/StorageFileBrowser.js +216 -119
- package/dist/virtuals/template-engine/index.d.ts +4 -4
- package/frontend/components/dashboard/configuration/ConfigForm.astro +218 -110
- package/frontend/components/dashboard/content-mgmt/ContentSearch.astro +21 -22
- package/frontend/components/dashboard/content-mgmt/CreateFolder.astro +66 -54
- package/frontend/components/dashboard/content-mgmt/CreatePage.astro +58 -104
- package/frontend/components/dashboard/content-mgmt/EditFolder.astro +65 -67
- package/frontend/components/dashboard/content-mgmt/EditPage.astro +86 -134
- package/frontend/components/dashboard/content-mgmt/InnerSidebarElement.astro +0 -1
- package/frontend/components/dashboard/content-mgmt/PageHeader.astro +33 -52
- package/frontend/components/dashboard/content-mgmt/PageTypeHandler.astro +2 -2
- package/frontend/components/dashboard/profile/APITokens.astro +219 -158
- package/frontend/components/dashboard/profile/BasicInfo.astro +165 -106
- package/frontend/components/dashboard/profile/Notifications.astro +27 -18
- package/frontend/components/dashboard/profile/UpdatePassword.astro +134 -94
- package/frontend/components/dashboard/sidebar/VersionCheck.astro +31 -16
- package/frontend/components/dashboard/sidebar/VersionCheckChangelog.astro +18 -11
- package/frontend/components/dashboard/sidebar-modals/VersionModal.astro +2 -2
- package/frontend/components/dashboard/smtp-config/TemplateEditor.astro +14 -14
- package/frontend/components/dashboard/taxonomy/InnerSidebarElement.astro +0 -1
- package/frontend/components/dashboard/taxonomy/MetaContainer.astro +0 -2
- package/frontend/components/dashboard/taxonomy/PageHeader.astro +16 -24
- package/frontend/components/dashboard/taxonomy/TaxonomySearch.astro +23 -27
- package/frontend/components/dashboard/user-mgmt/InnerSidebarElement.astro +111 -104
- package/frontend/components/dashboard/user-mgmt/UserListItem.astro +9 -22
- package/frontend/components/dashboard/user-mgmt/UserListItems.astro +18 -0
- package/frontend/components/first-time-setup/snippets/{opt2-studiocms.config.diff → studiocms.config.diff} +1 -0
- package/frontend/components/shared/Code.astro +1 -4
- package/frontend/components/shared/DynamicSettingsRenderer.astro +1 -1
- package/frontend/components/shared/SSRUser.astro +2 -4
- package/frontend/components/shared/foldertree/FolderTreeNode.astro +0 -6
- package/frontend/components/shared/storage-manager/StorageCopyOutput.astro +0 -1
- package/frontend/components/shared/taxonomy/TaxonomyTreeNode.astro +0 -6
- package/frontend/layouts/DashboardLayout.astro +1 -10
- package/frontend/layouts/TaxonomyLayout.astro +0 -1
- package/frontend/middleware/index.ts +102 -61
- package/frontend/pages/404.astro +5 -9
- package/frontend/pages/[dashboard]/[...pluginPage].astro +10 -1
- package/frontend/pages/[dashboard]/configuration.astro +10 -1
- package/frontend/pages/[dashboard]/content-management/createfolder.astro +10 -1
- package/frontend/pages/[dashboard]/content-management/createpage.astro +10 -1
- package/frontend/pages/[dashboard]/content-management/diff.astro +39 -14
- package/frontend/pages/[dashboard]/content-management/editfolder.astro +10 -1
- package/frontend/pages/[dashboard]/content-management/editpage.astro +10 -1
- package/frontend/pages/[dashboard]/content-management/index.astro +10 -1
- package/frontend/pages/[dashboard]/index.astro +10 -1
- package/frontend/pages/[dashboard]/login.astro +86 -25
- package/frontend/pages/[dashboard]/password-reset.astro +22 -16
- package/frontend/pages/[dashboard]/plugins/[plugin].astro +10 -1
- package/frontend/pages/[dashboard]/profile.astro +10 -1
- package/frontend/pages/[dashboard]/signup.astro +153 -52
- package/frontend/pages/[dashboard]/smtp-configuration.astro +77 -75
- package/frontend/pages/[dashboard]/system-management.astro +10 -1
- package/frontend/pages/[dashboard]/taxonomy/categories.astro +30 -41
- package/frontend/pages/[dashboard]/taxonomy/index.astro +10 -0
- package/frontend/pages/[dashboard]/taxonomy/tags.astro +33 -43
- package/frontend/pages/[dashboard]/unverified-email.astro +29 -21
- package/frontend/pages/[dashboard]/user-management/edit.astro +170 -90
- package/frontend/pages/[dashboard]/user-management/index.astro +10 -1
- package/frontend/pages/studiocms_api/[...all].ts +106 -0
- package/frontend/pages/studiocms_api/_handlers/_utils/auth.ts +26 -0
- package/frontend/pages/studiocms_api/_handlers/_utils/changelog.ts +147 -0
- package/frontend/pages/studiocms_api/_handlers/_utils/db-studio-driver.ts +46 -0
- package/frontend/pages/studiocms_api/_handlers/_utils/parseLogLevel.ts +27 -0
- package/frontend/pages/studiocms_api/_handlers/auth/auth.ts +459 -0
- package/frontend/pages/studiocms_api/_handlers/auth/index.ts +17 -0
- package/frontend/pages/studiocms_api/_handlers/auth/oauth.ts +91 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/_shared.ts +57 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/apiTokens.ts +134 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/config.ts +64 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/content.ts +741 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/create.ts +480 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/emailNotifications.ts +49 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/index.ts +45 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/mailer.ts +136 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/plugins.ts +80 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/profile.ts +275 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/resetPassword.ts +140 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/search.ts +63 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/taxonomy.ts +285 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/templates.ts +75 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/users.ts +312 -0
- package/frontend/pages/studiocms_api/_handlers/dashboard/verifyEndpoints.ts +307 -0
- package/frontend/pages/studiocms_api/_handlers/integration/dbStudio.ts +98 -0
- package/frontend/pages/studiocms_api/_handlers/integration/index.ts +17 -0
- package/frontend/pages/studiocms_api/_handlers/integration/storageManager.ts +107 -0
- package/frontend/pages/studiocms_api/_handlers/rest-api/index.ts +8 -0
- package/frontend/pages/studiocms_api/_handlers/rest-api/v1/_shared.ts +41 -0
- package/frontend/pages/studiocms_api/_handlers/rest-api/v1/index.ts +17 -0
- package/frontend/pages/studiocms_api/_handlers/rest-api/v1/public.ts +195 -0
- package/frontend/pages/studiocms_api/_handlers/rest-api/v1/secure.ts +1726 -0
- package/frontend/pages/studiocms_api/_handlers/sdk.ts +129 -0
- package/frontend/pages/studiocms_api/_middleware/astroLocals.ts +36 -0
- package/frontend/pages/studiocms_api/_middleware/restApi.ts +56 -0
- package/frontend/pages/studiocms_api/integrations/[...all].ts +8 -0
- package/frontend/scripts/formdata.ts +219 -0
- package/frontend/setup-pages/3-done.astro +4 -20
- package/frontend/setup-pages/studiocms_api/dashboard/step-2.ts +3 -6
- package/frontend/styles/dashboard-base.css +0 -1
- package/frontend/web-vitals/endpoint.ts +2 -1
- package/package.json +35 -31
- package/dist/global.d.ts +0 -9
- package/frontend/components/dashboard/LoginChecker.astro +0 -68
- package/frontend/components/dashboard/user-mgmt/RankCheck.astro +0 -57
- package/frontend/components/first-time-setup/snippets/opt1-astro.config.diff +0 -14
- package/frontend/components/first-time-setup/snippets/opt2-astro.config.diff +0 -9
- package/frontend/middleware/_authmap.ts +0 -63
- package/frontend/pages/studiocms_api/auth/[path].ts +0 -390
- package/frontend/pages/studiocms_api/auth/[provider]/[...id].ts +0 -64
- package/frontend/pages/studiocms_api/auth/[provider]/_effects/index.ts +0 -101
- package/frontend/pages/studiocms_api/auth/_shared.ts +0 -52
- package/frontend/pages/studiocms_api/dashboard/api-tokens.ts +0 -115
- package/frontend/pages/studiocms_api/dashboard/config.ts +0 -74
- package/frontend/pages/studiocms_api/dashboard/content/diff.ts +0 -73
- package/frontend/pages/studiocms_api/dashboard/content/folder.ts +0 -220
- package/frontend/pages/studiocms_api/dashboard/content/page.ts +0 -359
- package/frontend/pages/studiocms_api/dashboard/create-reset-link.ts +0 -77
- package/frontend/pages/studiocms_api/dashboard/create-user-invite.ts +0 -231
- package/frontend/pages/studiocms_api/dashboard/create-user.ts +0 -186
- package/frontend/pages/studiocms_api/dashboard/email-notification-settings-site.ts +0 -74
- package/frontend/pages/studiocms_api/dashboard/mailer/check-email.ts +0 -75
- package/frontend/pages/studiocms_api/dashboard/mailer/config.ts +0 -136
- package/frontend/pages/studiocms_api/dashboard/plugins/[plugin].ts +0 -80
- package/frontend/pages/studiocms_api/dashboard/profile.ts +0 -245
- package/frontend/pages/studiocms_api/dashboard/resend-verify-email.ts +0 -77
- package/frontend/pages/studiocms_api/dashboard/reset-password.ts +0 -124
- package/frontend/pages/studiocms_api/dashboard/search-list.ts +0 -59
- package/frontend/pages/studiocms_api/dashboard/taxonomy-search.ts +0 -47
- package/frontend/pages/studiocms_api/dashboard/taxonomy.ts +0 -230
- package/frontend/pages/studiocms_api/dashboard/templates.ts +0 -74
- package/frontend/pages/studiocms_api/dashboard/update-user-notifications.ts +0 -86
- package/frontend/pages/studiocms_api/dashboard/users.ts +0 -236
- package/frontend/pages/studiocms_api/dashboard/verify-email.ts +0 -83
- package/frontend/pages/studiocms_api/dashboard/verify-session.ts +0 -187
- package/frontend/pages/studiocms_api/integrations/[type]/[...id].ts +0 -15
- package/frontend/pages/studiocms_api/integrations/[type]/_routes/db-studio.ts +0 -173
- package/frontend/pages/studiocms_api/integrations/[type]/_routes/storage.ts +0 -88
- package/frontend/pages/studiocms_api/partials/editor.astro +0 -74
- package/frontend/pages/studiocms_api/partials/render.astro +0 -39
- package/frontend/pages/studiocms_api/partials/user-list-items.astro +0 -43
- package/frontend/pages/studiocms_api/rest/utils/auth-token.ts +0 -59
- package/frontend/pages/studiocms_api/rest/v1/[type]/[...id].ts +0 -23
- package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/categories.ts +0 -267
- package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/folders.ts +0 -283
- package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/pages.ts +0 -505
- package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/settings.ts +0 -100
- package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/tags.ts +0 -229
- package/frontend/pages/studiocms_api/rest/v1/[type]/_routes/users.ts +0 -553
- package/frontend/pages/studiocms_api/rest/v1/public/[type]/[...id].ts +0 -19
- package/frontend/pages/studiocms_api/rest/v1/public/[type]/_routes/categories.ts +0 -74
- package/frontend/pages/studiocms_api/rest/v1/public/[type]/_routes/folders.ts +0 -85
- package/frontend/pages/studiocms_api/rest/v1/public/[type]/_routes/pages.ts +0 -103
- package/frontend/pages/studiocms_api/rest/v1/public/[type]/_routes/tags.ts +0 -67
- package/frontend/pages/studiocms_api/sdk/[...path].ts +0 -97
- package/frontend/pages/studiocms_api/sdk/utils/changelog.ts +0 -119
- package/frontend/scripts/auth/formListener.ts +0 -81
- package/frontend/scripts/formdata-utils.ts +0 -116
- package/frontend/utils/build-partial-schema.ts +0 -46
- package/frontend/utils/errors.ts +0 -6
- package/frontend/utils/param-extractor.ts +0 -83
- package/frontend/utils/rest-router.ts +0 -444
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DashboardAPIError } from '@withstudiocms/api-spec/dashboard';
|
|
2
|
+
import { Schema } from 'effect';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shared database error handlers for the Dashboard API. These handlers convert common database-related errors into consistent DashboardAPIError responses, allowing for cleaner and more maintainable error handling across all endpoints that interact with the database.
|
|
6
|
+
*/
|
|
7
|
+
export const sharedDBErrors = {
|
|
8
|
+
DBCallbackFailure: () => new DashboardAPIError({ error: 'Database callback failed' }),
|
|
9
|
+
DBClientInitializationError: () =>
|
|
10
|
+
new DashboardAPIError({ error: 'Database client initialization failed' }),
|
|
11
|
+
NotFoundError: () => new DashboardAPIError({ error: 'Resource not found' }),
|
|
12
|
+
QueryError: () => new DashboardAPIError({ error: 'Database query failed' }),
|
|
13
|
+
QueryParseError: () => new DashboardAPIError({ error: 'Database query parsing failed' }),
|
|
14
|
+
SDKInitializationError: () => new DashboardAPIError({ error: 'SDK initialization failed' }),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Shared notification error handlers for the Dashboard API. These handlers convert common notification-related errors into consistent DashboardAPIError responses, allowing for cleaner and more maintainable error handling across all endpoints that involve sending notifications.
|
|
19
|
+
*/
|
|
20
|
+
export const sharedNotifierErrors = {
|
|
21
|
+
ConfigError: () =>
|
|
22
|
+
new DashboardAPIError({ error: 'Configuration error during notification sending' }),
|
|
23
|
+
SMTPError: () => new DashboardAPIError({ error: 'SMTP error during notification sending' }),
|
|
24
|
+
UnknownException: () =>
|
|
25
|
+
new DashboardAPIError({ error: 'An unknown error occurred during notification sending' }),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Shared page collection error handlers for the Dashboard API. These handlers convert common errors that can occur during the collection of pages for operations like category deletion into consistent DashboardAPIError responses, allowing for cleaner and more maintainable error handling in endpoints that involve complex data collection and manipulation.
|
|
30
|
+
*/
|
|
31
|
+
export const sharedPageCollectionErrors = {
|
|
32
|
+
ParseError: () => new DashboardAPIError({ error: 'Failed to parse data during page collection' }),
|
|
33
|
+
FolderTreeError: () =>
|
|
34
|
+
new DashboardAPIError({
|
|
35
|
+
error: 'Failed to retrieve folder tree during page collection',
|
|
36
|
+
}),
|
|
37
|
+
CollectorError: () =>
|
|
38
|
+
new DashboardAPIError({
|
|
39
|
+
error: 'Failed to collect necessary data during page collection',
|
|
40
|
+
}),
|
|
41
|
+
PaginateError: () =>
|
|
42
|
+
new DashboardAPIError({ error: 'Failed to paginate data during page collection' }),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Utility schema for encoding Arrays of Strings
|
|
47
|
+
*/
|
|
48
|
+
export const StringArrayCodec = Schema.transform(Schema.String, Schema.Array(Schema.String), {
|
|
49
|
+
strict: true,
|
|
50
|
+
decode: (data) => JSON.parse(data),
|
|
51
|
+
encode: (data) => JSON.stringify(data),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Function that uses the String Array Schema to create a JSON.stringify like function for string arrays
|
|
56
|
+
*/
|
|
57
|
+
export const encodeStringArray = Schema.encode(StringArrayCodec);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { developerConfig } from 'studiocms:config';
|
|
2
|
+
import { SDKCore } from 'studiocms:sdk';
|
|
3
|
+
import routeConfig from 'virtual:studiocms/route-config';
|
|
4
|
+
import { HttpApiBuilder } from '@effect/platform';
|
|
5
|
+
import { StudioCMSDashboardApiSpec } from '@withstudiocms/api-spec';
|
|
6
|
+
import { CurrentUser } from '@withstudiocms/api-spec/astro-context';
|
|
7
|
+
import { DashboardAPIError } from '@withstudiocms/api-spec/dashboard';
|
|
8
|
+
import { availablePermissionRanks } from '@withstudiocms/auth-kit/types';
|
|
9
|
+
import { Effect } from 'effect';
|
|
10
|
+
import { sharedDBErrors } from './_shared.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if the Dashboard API is enabled in the route configuration.
|
|
14
|
+
*/
|
|
15
|
+
const dashboardAPIEnabled = routeConfig.dashboardAPIEnabled;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Dashboard API Handlers - API Tokens group
|
|
19
|
+
*/
|
|
20
|
+
export const ApiTokensHandler = HttpApiBuilder.group(
|
|
21
|
+
StudioCMSDashboardApiSpec,
|
|
22
|
+
'apiTokens',
|
|
23
|
+
(handlers) =>
|
|
24
|
+
handlers
|
|
25
|
+
.handle(
|
|
26
|
+
'createApiToken',
|
|
27
|
+
Effect.fn(
|
|
28
|
+
function* ({ payload: { description } }) {
|
|
29
|
+
if (!dashboardAPIEnabled) {
|
|
30
|
+
return yield* new DashboardAPIError({ error: 'Dashboard API is disabled' });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (developerConfig.demoMode !== false) {
|
|
34
|
+
return yield* new DashboardAPIError({
|
|
35
|
+
error: 'Demo mode is enabled, this action is not allowed.',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const [sdk, userData] = yield* Effect.all([SDKCore, CurrentUser]);
|
|
40
|
+
|
|
41
|
+
const isAuthorized = userData.userPermissionLevel.isEditor;
|
|
42
|
+
|
|
43
|
+
if (!userData.isLoggedIn || !userData.user || !isAuthorized) {
|
|
44
|
+
return yield* new DashboardAPIError({ error: 'Unauthorized' });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const newToken = yield* sdk.REST_API.tokens.new(userData.user.id, description);
|
|
48
|
+
|
|
49
|
+
return { token: newToken.key };
|
|
50
|
+
},
|
|
51
|
+
Effect.catchTags({
|
|
52
|
+
...sharedDBErrors,
|
|
53
|
+
GeneratorError: () => new DashboardAPIError({ error: 'Internal Server Error' }),
|
|
54
|
+
})
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
.handle(
|
|
58
|
+
'revokeApiToken',
|
|
59
|
+
Effect.fn(function* ({ payload: { tokenID } }) {
|
|
60
|
+
if (!dashboardAPIEnabled) {
|
|
61
|
+
return yield* new DashboardAPIError({ error: 'Dashboard API is disabled' });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (developerConfig.demoMode !== false) {
|
|
65
|
+
return yield* new DashboardAPIError({
|
|
66
|
+
error: 'Demo mode is enabled, this action is not allowed.',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const [sdk, userData] = yield* Effect.all([SDKCore, CurrentUser]);
|
|
71
|
+
|
|
72
|
+
const isAuthorized = userData.userPermissionLevel.isEditor;
|
|
73
|
+
|
|
74
|
+
if (!userData.isLoggedIn || !userData.user || !isAuthorized) {
|
|
75
|
+
return yield* new DashboardAPIError({ error: 'Unauthorized' });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const tokenData = yield* sdk.REST_API.tokens.verify(tokenID);
|
|
79
|
+
|
|
80
|
+
if (!tokenData || tokenData.userId !== userData.user.id) {
|
|
81
|
+
return yield* new DashboardAPIError({ error: 'Unauthorized' });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
yield* sdk.REST_API.tokens.delete({ tokenId: tokenID, userId: userData.user.id });
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
message: 'Token deleted',
|
|
88
|
+
};
|
|
89
|
+
}, Effect.catchTags(sharedDBErrors))
|
|
90
|
+
)
|
|
91
|
+
.handle(
|
|
92
|
+
'adminRevokeUserApiToken',
|
|
93
|
+
Effect.fn(function* ({ payload: { tokenID, userID } }) {
|
|
94
|
+
if (!dashboardAPIEnabled) {
|
|
95
|
+
return yield* new DashboardAPIError({ error: 'Dashboard API is disabled' });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (developerConfig.demoMode !== false) {
|
|
99
|
+
return yield* new DashboardAPIError({
|
|
100
|
+
error: 'Demo mode is enabled, this action is not allowed.',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const [sdk, userData] = yield* Effect.all([SDKCore, CurrentUser]);
|
|
105
|
+
|
|
106
|
+
const isAuthorized = userData.userPermissionLevel.isAdmin;
|
|
107
|
+
|
|
108
|
+
if (!userData.isLoggedIn || !isAuthorized) {
|
|
109
|
+
return yield* new DashboardAPIError({ error: 'Unauthorized' });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const tokenData = yield* sdk.REST_API.tokens.verify(tokenID);
|
|
113
|
+
|
|
114
|
+
if (!tokenData) {
|
|
115
|
+
return yield* new DashboardAPIError({ error: 'Token not found' });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const targetPerms = availablePermissionRanks.indexOf(tokenData.rank);
|
|
119
|
+
const userPerms = availablePermissionRanks.indexOf(userData.permissionLevel);
|
|
120
|
+
|
|
121
|
+
if (targetPerms >= userPerms) {
|
|
122
|
+
return yield* new DashboardAPIError({
|
|
123
|
+
error: 'Unauthorized - insufficient permissions to revoke this token',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
yield* sdk.REST_API.tokens.delete({ tokenId: tokenID, userId: userID });
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
message: 'Token deleted',
|
|
131
|
+
};
|
|
132
|
+
}, Effect.catchTags(sharedDBErrors))
|
|
133
|
+
)
|
|
134
|
+
);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { developerConfig } from 'studiocms:config';
|
|
2
|
+
import { SDKCore } from 'studiocms:sdk';
|
|
3
|
+
import routeConfig from 'virtual:studiocms/route-config';
|
|
4
|
+
import { HttpApiBuilder } from '@effect/platform';
|
|
5
|
+
import { StudioCMSDashboardApiSpec } from '@withstudiocms/api-spec';
|
|
6
|
+
import { CurrentUser } from '@withstudiocms/api-spec/astro-context';
|
|
7
|
+
import { DashboardAPIError } from '@withstudiocms/api-spec/dashboard';
|
|
8
|
+
import { Effect } from 'effect';
|
|
9
|
+
import { sharedDBErrors } from './_shared.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Check if the Dashboard API is enabled in the route configuration.
|
|
13
|
+
*/
|
|
14
|
+
const dashboardAPIEnabled = routeConfig.dashboardAPIEnabled;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Handlers for the Dashboard API configuration endpoints.
|
|
18
|
+
*/
|
|
19
|
+
export const ConfigHandlers = HttpApiBuilder.group(
|
|
20
|
+
StudioCMSDashboardApiSpec,
|
|
21
|
+
'config',
|
|
22
|
+
(handlers) =>
|
|
23
|
+
handlers.handle(
|
|
24
|
+
'updateSiteConfig',
|
|
25
|
+
Effect.fn(function* ({ payload }) {
|
|
26
|
+
if (!dashboardAPIEnabled) {
|
|
27
|
+
return yield* new DashboardAPIError({ error: 'Dashboard API is disabled' });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (developerConfig.demoMode !== false) {
|
|
31
|
+
return yield* new DashboardAPIError({
|
|
32
|
+
error: 'Demo mode is enabled, this action is not allowed.',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const [sdk, userData] = yield* Effect.all([SDKCore, CurrentUser]);
|
|
37
|
+
|
|
38
|
+
const isAuthorized = userData.userPermissionLevel.isOwner;
|
|
39
|
+
|
|
40
|
+
if (!userData.isLoggedIn || !isAuthorized) {
|
|
41
|
+
return yield* new DashboardAPIError({ error: 'Unauthorized' });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!payload.loginPageBackground) {
|
|
45
|
+
return yield* new DashboardAPIError({
|
|
46
|
+
error: 'Invalid input: loginPageBackground is required',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (payload.loginPageBackground === 'custom' && !payload.loginPageCustomImage) {
|
|
51
|
+
return yield* new DashboardAPIError({
|
|
52
|
+
error:
|
|
53
|
+
'Invalid input: loginPageCustomImage is required when loginPageBackground is set to custom',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
yield* sdk.UPDATE.siteConfig(payload);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
message: 'Site configuration updated successfully',
|
|
61
|
+
};
|
|
62
|
+
}, Effect.catchTags(sharedDBErrors))
|
|
63
|
+
)
|
|
64
|
+
);
|