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
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { apiResponseLogger } from 'studiocms:logger';
|
|
2
|
-
import { SDKCore } from 'studiocms:sdk';
|
|
3
|
-
import {
|
|
4
|
-
AllResponse,
|
|
5
|
-
createEffectAPIRoutes,
|
|
6
|
-
createJsonResponse,
|
|
7
|
-
Effect,
|
|
8
|
-
genLogger,
|
|
9
|
-
OptionsResponse,
|
|
10
|
-
} from '@withstudiocms/effect';
|
|
11
|
-
import type { EndpointRoute } from '../../../../../../../utils/rest-router.js';
|
|
12
|
-
|
|
13
|
-
export const foldersRouter: EndpointRoute = {
|
|
14
|
-
__idType: 'string',
|
|
15
|
-
__index: createEffectAPIRoutes(
|
|
16
|
-
{
|
|
17
|
-
GET: (ctx) =>
|
|
18
|
-
genLogger('studioCMS:rest:v1:public:folders:GET')(function* () {
|
|
19
|
-
const sdk = yield* SDKCore;
|
|
20
|
-
|
|
21
|
-
const folders = yield* sdk.GET.folderList();
|
|
22
|
-
|
|
23
|
-
const searchParams = ctx.url.searchParams;
|
|
24
|
-
|
|
25
|
-
const folderNameFilter = searchParams.get('name');
|
|
26
|
-
const folderParentFilter = searchParams.get('parent');
|
|
27
|
-
|
|
28
|
-
let filteredFolders = folders;
|
|
29
|
-
|
|
30
|
-
if (folderNameFilter) {
|
|
31
|
-
filteredFolders = filteredFolders.filter((folder) =>
|
|
32
|
-
folder.name.includes(folderNameFilter)
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (folderParentFilter) {
|
|
37
|
-
filteredFolders = filteredFolders.filter(
|
|
38
|
-
(folder) => folder.parent === folderParentFilter
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return createJsonResponse(filteredFolders);
|
|
43
|
-
}),
|
|
44
|
-
OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ['GET'] })),
|
|
45
|
-
ALL: () => Effect.try(() => AllResponse()),
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
cors: { methods: ['GET', 'OPTIONS'] },
|
|
49
|
-
onError: (error) => {
|
|
50
|
-
console.error('API Error:', error);
|
|
51
|
-
return createJsonResponse({ error: 'Something went wrong' }, { status: 500 });
|
|
52
|
-
},
|
|
53
|
-
}
|
|
54
|
-
),
|
|
55
|
-
id: (id: string) =>
|
|
56
|
-
createEffectAPIRoutes(
|
|
57
|
-
{
|
|
58
|
-
GET: () =>
|
|
59
|
-
genLogger('studioCMS:rest:v1:public:folders:[id]:GET')(function* () {
|
|
60
|
-
const sdk = yield* SDKCore;
|
|
61
|
-
|
|
62
|
-
if (!id) {
|
|
63
|
-
return apiResponseLogger(400, 'Invalid folder ID');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const folder = yield* sdk.GET.folder(id);
|
|
67
|
-
|
|
68
|
-
if (!folder) {
|
|
69
|
-
return apiResponseLogger(404, 'Folder not found');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return createJsonResponse(folder);
|
|
73
|
-
}),
|
|
74
|
-
OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ['GET'] })),
|
|
75
|
-
ALL: () => Effect.try(() => AllResponse()),
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
cors: { methods: ['GET', 'OPTIONS'] },
|
|
79
|
-
onError: (error) => {
|
|
80
|
-
console.error('API Error:', error);
|
|
81
|
-
return createJsonResponse({ error: 'Something went wrong' }, { status: 500 });
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
),
|
|
85
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { apiResponseLogger } from 'studiocms:logger';
|
|
2
|
-
import { SDKCore } from 'studiocms:sdk';
|
|
3
|
-
import {
|
|
4
|
-
AllResponse,
|
|
5
|
-
createEffectAPIRoutes,
|
|
6
|
-
createJsonResponse,
|
|
7
|
-
Effect,
|
|
8
|
-
genLogger,
|
|
9
|
-
OptionsResponse,
|
|
10
|
-
} from '@withstudiocms/effect';
|
|
11
|
-
import type { EndpointRoute } from '../../../../../../../utils/rest-router.js';
|
|
12
|
-
|
|
13
|
-
export const pagesRouter: EndpointRoute = {
|
|
14
|
-
__idType: 'string',
|
|
15
|
-
__index: createEffectAPIRoutes(
|
|
16
|
-
{
|
|
17
|
-
GET: (ctx) =>
|
|
18
|
-
genLogger('studioCMS:rest:v1:public:pages:GET')(function* () {
|
|
19
|
-
const sdk = yield* SDKCore;
|
|
20
|
-
|
|
21
|
-
const pages = yield* sdk.GET.pages();
|
|
22
|
-
|
|
23
|
-
const searchParams = ctx.url.searchParams;
|
|
24
|
-
|
|
25
|
-
const titleFilter = searchParams.get('title');
|
|
26
|
-
const slugFilter = searchParams.get('slug');
|
|
27
|
-
const authorFilter = searchParams.get('author');
|
|
28
|
-
const parentFolderFilter = searchParams.get('parentFolder');
|
|
29
|
-
|
|
30
|
-
let filteredPages = pages;
|
|
31
|
-
|
|
32
|
-
if (titleFilter) {
|
|
33
|
-
filteredPages = filteredPages.filter((page) => page.title.includes(titleFilter));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (slugFilter) {
|
|
37
|
-
filteredPages = filteredPages.filter((page) => page.slug.includes(slugFilter));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (authorFilter) {
|
|
41
|
-
filteredPages = filteredPages.filter((page) => page.authorId === authorFilter);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (parentFolderFilter) {
|
|
45
|
-
filteredPages = filteredPages.filter(
|
|
46
|
-
(page) => page.parentFolder === parentFolderFilter
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return createJsonResponse(filteredPages);
|
|
51
|
-
}),
|
|
52
|
-
OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ['GET'] })),
|
|
53
|
-
ALL: () => Effect.try(() => AllResponse()),
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
cors: { methods: ['GET', 'OPTIONS'] },
|
|
57
|
-
onError: (error) => {
|
|
58
|
-
console.error('API Error:', error);
|
|
59
|
-
return createJsonResponse(
|
|
60
|
-
{ error: 'Internal Server Error' },
|
|
61
|
-
{ status: 500, statusText: 'Internal Server Error' }
|
|
62
|
-
);
|
|
63
|
-
},
|
|
64
|
-
}
|
|
65
|
-
),
|
|
66
|
-
id: (id: string) =>
|
|
67
|
-
createEffectAPIRoutes(
|
|
68
|
-
{
|
|
69
|
-
GET: () =>
|
|
70
|
-
genLogger('studioCMS:rest:v1:public:pages:[id]:GET')(function* () {
|
|
71
|
-
const sdk = yield* SDKCore;
|
|
72
|
-
|
|
73
|
-
if (!id) {
|
|
74
|
-
return apiResponseLogger(400, 'Invalid page ID');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const page = yield* sdk.GET.page.byId(id);
|
|
78
|
-
|
|
79
|
-
if (!page) {
|
|
80
|
-
return apiResponseLogger(404, 'Page not found');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (page.draft) {
|
|
84
|
-
return apiResponseLogger(404, 'Page not found');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return createJsonResponse(page);
|
|
88
|
-
}),
|
|
89
|
-
OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ['GET'] })),
|
|
90
|
-
ALL: () => Effect.try(() => AllResponse()),
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
cors: { methods: ['GET', 'OPTIONS'] },
|
|
94
|
-
onError: (error) => {
|
|
95
|
-
console.error('API Error:', error);
|
|
96
|
-
return createJsonResponse(
|
|
97
|
-
{ error: 'Internal Server Error' },
|
|
98
|
-
{ status: 500, statusText: 'Internal Server Error' }
|
|
99
|
-
);
|
|
100
|
-
},
|
|
101
|
-
}
|
|
102
|
-
),
|
|
103
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { SDKCore } from 'studiocms:sdk';
|
|
2
|
-
import {
|
|
3
|
-
AllResponse,
|
|
4
|
-
createEffectAPIRoutes,
|
|
5
|
-
createJsonResponse,
|
|
6
|
-
Effect,
|
|
7
|
-
genLogger,
|
|
8
|
-
OptionsResponse,
|
|
9
|
-
} from '@withstudiocms/effect';
|
|
10
|
-
import type { EndpointRoute } from '../../../../../../../utils/rest-router.js';
|
|
11
|
-
|
|
12
|
-
export const tagsRouter: EndpointRoute = {
|
|
13
|
-
__idType: 'number',
|
|
14
|
-
__index: createEffectAPIRoutes(
|
|
15
|
-
{
|
|
16
|
-
GET: (ctx) =>
|
|
17
|
-
genLogger('studiocms:rest:v1:public:tags:GET')(function* () {
|
|
18
|
-
const sdk = yield* SDKCore;
|
|
19
|
-
|
|
20
|
-
const searchParams = ctx.url.searchParams;
|
|
21
|
-
const folderNameFilter = searchParams.get('name');
|
|
22
|
-
|
|
23
|
-
let tags = yield* sdk.GET.tags.getAll();
|
|
24
|
-
|
|
25
|
-
if (folderNameFilter) {
|
|
26
|
-
tags = tags.filter((tag) => tag.name.includes(folderNameFilter));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return createJsonResponse(tags);
|
|
30
|
-
}),
|
|
31
|
-
OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ['GET'] })),
|
|
32
|
-
ALL: () => Effect.try(() => AllResponse()),
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
cors: { methods: ['GET', 'OPTIONS'] },
|
|
36
|
-
onError: (error) => {
|
|
37
|
-
console.error('API Error:', error);
|
|
38
|
-
return createJsonResponse({ error: 'Something went wrong' }, { status: 500 });
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
),
|
|
42
|
-
id: (id: number) =>
|
|
43
|
-
createEffectAPIRoutes(
|
|
44
|
-
{
|
|
45
|
-
GET: () =>
|
|
46
|
-
genLogger(`studiocms:rest:v1:public:tags:${id}:GET`)(function* () {
|
|
47
|
-
const sdk = yield* SDKCore;
|
|
48
|
-
const tag = yield* sdk.GET.tags.byId(id);
|
|
49
|
-
|
|
50
|
-
if (!tag) {
|
|
51
|
-
return createJsonResponse({ error: 'Tag not found' }, { status: 404 });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return createJsonResponse(tag);
|
|
55
|
-
}),
|
|
56
|
-
OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ['GET'] })),
|
|
57
|
-
ALL: () => Effect.try(() => AllResponse()),
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
cors: { methods: ['GET', 'OPTIONS'] },
|
|
61
|
-
onError: (error) => {
|
|
62
|
-
console.error('API Error:', error);
|
|
63
|
-
return createJsonResponse({ error: 'Something went wrong' }, { status: 500 });
|
|
64
|
-
},
|
|
65
|
-
}
|
|
66
|
-
),
|
|
67
|
-
};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import logger from 'studiocms:logger';
|
|
2
|
-
import { SDKCore } from 'studiocms:sdk';
|
|
3
|
-
import {
|
|
4
|
-
AllResponse,
|
|
5
|
-
createEffectAPIRoutes,
|
|
6
|
-
createJsonResponse,
|
|
7
|
-
Effect,
|
|
8
|
-
type HTTPMethod,
|
|
9
|
-
OptionsResponse,
|
|
10
|
-
} from '@withstudiocms/effect';
|
|
11
|
-
import { createSimplePathRouter } from '#frontend/utils/rest-router.js';
|
|
12
|
-
import { ProcessChangelog } from './utils/changelog.js';
|
|
13
|
-
|
|
14
|
-
const optionsFn = (allowedMethods: string[]) => () =>
|
|
15
|
-
Effect.try(() => OptionsResponse({ allowedMethods }));
|
|
16
|
-
|
|
17
|
-
const allFn = () => Effect.try(() => AllResponse());
|
|
18
|
-
|
|
19
|
-
const cors = (method: string) => ({ methods: [method, 'OPTIONS'] }) as { methods: HTTPMethod[] };
|
|
20
|
-
|
|
21
|
-
const isError = (error: unknown): error is Error => {
|
|
22
|
-
return (
|
|
23
|
-
error instanceof Error || (typeof error === 'object' && error !== null && 'message' in error)
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const onError = (error: unknown) => {
|
|
28
|
-
const message = isError(error) ? error.message : String(error);
|
|
29
|
-
logger.error(`API Error: ${message}`);
|
|
30
|
-
return createJsonResponse(
|
|
31
|
-
{ error: 'Something went wrong' },
|
|
32
|
-
{
|
|
33
|
-
status: 500,
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const router = {
|
|
39
|
-
'full-changelog.json': createEffectAPIRoutes(
|
|
40
|
-
{
|
|
41
|
-
POST: (ctx) =>
|
|
42
|
-
ProcessChangelog.pipe(
|
|
43
|
-
Effect.flatMap(({ generateChangelog, getRawChangelog, renderChangelog }) =>
|
|
44
|
-
getRawChangelog().pipe(
|
|
45
|
-
Effect.flatMap(generateChangelog),
|
|
46
|
-
Effect.flatMap((changelogData) => renderChangelog(changelogData, ctx))
|
|
47
|
-
)
|
|
48
|
-
),
|
|
49
|
-
Effect.map((renderedChangelog) => ({ success: true, changelog: renderedChangelog })),
|
|
50
|
-
Effect.map(createJsonResponse),
|
|
51
|
-
ProcessChangelog.Provide
|
|
52
|
-
),
|
|
53
|
-
OPTIONS: optionsFn(['POST']),
|
|
54
|
-
ALL: allFn,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
cors: cors('POST'),
|
|
58
|
-
onError,
|
|
59
|
-
}
|
|
60
|
-
),
|
|
61
|
-
'list-pages': createEffectAPIRoutes(
|
|
62
|
-
{
|
|
63
|
-
GET: () =>
|
|
64
|
-
SDKCore.pipe(
|
|
65
|
-
Effect.flatMap((sdk) => sdk.GET.pages()),
|
|
66
|
-
Effect.map((pages) => {
|
|
67
|
-
const lastUpdated = new Date().toISOString();
|
|
68
|
-
return { lastUpdated, pages };
|
|
69
|
-
}),
|
|
70
|
-
Effect.map((data) => createJsonResponse(data))
|
|
71
|
-
),
|
|
72
|
-
OPTIONS: optionsFn(['GET']),
|
|
73
|
-
ALL: allFn,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
cors: cors('GET'),
|
|
77
|
-
onError,
|
|
78
|
-
}
|
|
79
|
-
),
|
|
80
|
-
'update-latest-version-cache': createEffectAPIRoutes(
|
|
81
|
-
{
|
|
82
|
-
GET: () =>
|
|
83
|
-
SDKCore.pipe(
|
|
84
|
-
Effect.flatMap((sdk) => sdk.UPDATE.latestVersion()),
|
|
85
|
-
Effect.map((latestVersion) => createJsonResponse({ success: true, latestVersion }))
|
|
86
|
-
),
|
|
87
|
-
OPTIONS: optionsFn(['GET']),
|
|
88
|
-
ALL: allFn,
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
cors: cors('GET'),
|
|
92
|
-
onError,
|
|
93
|
-
}
|
|
94
|
-
),
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const ALL = createSimplePathRouter('studiocms:sdk', router);
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { Effect, genLogger, HTTPClient, Platform, readAPIContextJson } from '@withstudiocms/effect';
|
|
2
|
-
import { loadChangelog, semverCategories } from '@withstudiocms/internal_helpers/utils';
|
|
3
|
-
import type { APIContext } from 'astro';
|
|
4
|
-
import { Data } from 'effect';
|
|
5
|
-
import type { List, Root } from 'mdast';
|
|
6
|
-
import { toMarkdown } from 'mdast-util-to-markdown';
|
|
7
|
-
|
|
8
|
-
export class ChangelogError extends Data.TaggedError('ChangelogError')<{ message: string }> {}
|
|
9
|
-
|
|
10
|
-
export class ProcessChangelog extends Effect.Service<ProcessChangelog>()('ProcessChangelog', {
|
|
11
|
-
effect: genLogger('routes/sdk/utils/changelog/ProcessChangelog/effect')(function* () {
|
|
12
|
-
const httpClient = yield* HTTPClient;
|
|
13
|
-
|
|
14
|
-
const getRawChangelog = () =>
|
|
15
|
-
genLogger('routes/sdk/utils/changelog/ProcessChangelog/effect.getRawChangelog')(function* () {
|
|
16
|
-
const data = yield* httpClient.get(
|
|
17
|
-
'https://raw.githubusercontent.com/withstudiocms/studiocms/refs/heads/main/packages/studiocms/CHANGELOG.md'
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
if (data.status !== 200) {
|
|
21
|
-
return yield* new ChangelogError({
|
|
22
|
-
message: `Failed to fetch CHANGELOG.md: ${data.status} ${data.toString()}`,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return yield* data.text;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const generateChangelog = (raw: string) =>
|
|
30
|
-
genLogger('routes/sdk/utils/changelog/ProcessChangelog/effect.generateChangelog')(
|
|
31
|
-
function* () {
|
|
32
|
-
const ToProcess = yield* Effect.try(() => loadChangelog({ raw }));
|
|
33
|
-
|
|
34
|
-
const output: string[] = [];
|
|
35
|
-
|
|
36
|
-
const astEnd: Root = {
|
|
37
|
-
type: 'root',
|
|
38
|
-
children: [],
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
for (const version of ToProcess.versions) {
|
|
42
|
-
const versionChanges: List = { type: 'list', children: [] };
|
|
43
|
-
|
|
44
|
-
for (const semverCategory of semverCategories) {
|
|
45
|
-
for (const listItem of version.changes[semverCategory].children) {
|
|
46
|
-
versionChanges.children.push(listItem);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (version.includes.size) {
|
|
51
|
-
versionChanges.children.push({
|
|
52
|
-
type: 'listItem',
|
|
53
|
-
children: [
|
|
54
|
-
{
|
|
55
|
-
type: 'paragraph',
|
|
56
|
-
children: [
|
|
57
|
-
{ type: 'text', value: `Includes: ${[...version.includes].join(', ')} ` },
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!versionChanges.children.length) continue;
|
|
65
|
-
|
|
66
|
-
astEnd.children.push({
|
|
67
|
-
type: 'heading',
|
|
68
|
-
depth: 2,
|
|
69
|
-
children: [{ type: 'text', value: version.version }],
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
astEnd.children.push(versionChanges);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const outputData = yield* Effect.try(() => toMarkdown(astEnd, { bullet: '-' }));
|
|
76
|
-
|
|
77
|
-
output.push(outputData);
|
|
78
|
-
|
|
79
|
-
const markdownString = output.join('\n');
|
|
80
|
-
|
|
81
|
-
return markdownString;
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const renderChangelog = (content: string, context: APIContext) =>
|
|
86
|
-
genLogger('routes/sdk/utils/changelog/ProcessChangelog/effect.renderChangelog')(function* () {
|
|
87
|
-
const currentRequestJson = yield* readAPIContextJson<{
|
|
88
|
-
currentURLOrigin: string;
|
|
89
|
-
}>(context);
|
|
90
|
-
|
|
91
|
-
const currentURLOrigin = currentRequestJson.currentURLOrigin;
|
|
92
|
-
|
|
93
|
-
const partialUrl = new URL(
|
|
94
|
-
context.locals.StudioCMS?.routeMap.endpointLinks.partials.render,
|
|
95
|
-
currentURLOrigin
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return yield* Platform.HttpClientRequest.post(partialUrl).pipe(
|
|
99
|
-
Platform.HttpClientRequest.setHeaders({
|
|
100
|
-
'Content-Type': 'application/json',
|
|
101
|
-
}),
|
|
102
|
-
Platform.HttpClientRequest.bodyJson({
|
|
103
|
-
content,
|
|
104
|
-
}),
|
|
105
|
-
Effect.flatMap(httpClient.execute),
|
|
106
|
-
Effect.flatMap((response) => response.text)
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
getRawChangelog,
|
|
112
|
-
generateChangelog,
|
|
113
|
-
renderChangelog,
|
|
114
|
-
};
|
|
115
|
-
}),
|
|
116
|
-
dependencies: [HTTPClient.Default],
|
|
117
|
-
}) {
|
|
118
|
-
static Provide = Effect.provide(this.Default);
|
|
119
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This tool is used by Auth Login pages
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { toast as uiToast } from 'studiocms:ui/components/toaster/client';
|
|
6
|
-
import type { ToastProps } from '@studiocms/ui/types';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Handles form submission events for login and registration forms.
|
|
10
|
-
*
|
|
11
|
-
* @param event - The submit event triggered by the form submission.
|
|
12
|
-
* @param form - The HTML form element being submitted.
|
|
13
|
-
* @param type - The type of form being submitted, either 'login' or 'register'.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* - Prevents the default form submission behavior.
|
|
17
|
-
* - For registration forms, checks if the password and confirm password fields match.
|
|
18
|
-
* - Displays a toast notification if the passwords do not match.
|
|
19
|
-
* - Submits the form data using the fetch API.
|
|
20
|
-
* - Displays a success toast notification and reloads the page if the submission is successful.
|
|
21
|
-
* - Displays an error toast notification if the submission fails.
|
|
22
|
-
*/
|
|
23
|
-
export async function formListener(
|
|
24
|
-
event: SubmitEvent,
|
|
25
|
-
form: HTMLFormElement,
|
|
26
|
-
type: 'login' | 'register',
|
|
27
|
-
toast: (props: ToastProps) => void = uiToast,
|
|
28
|
-
/* v8 ignore start */
|
|
29
|
-
reload: () => void = () => {
|
|
30
|
-
if (typeof window !== 'undefined') {
|
|
31
|
-
window.location.reload();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/* v8 ignore stop */
|
|
35
|
-
) {
|
|
36
|
-
event.preventDefault();
|
|
37
|
-
|
|
38
|
-
/* v8 ignore start */
|
|
39
|
-
if (type === 'register') {
|
|
40
|
-
const password = form.querySelector('input[name="password"]') as HTMLInputElement;
|
|
41
|
-
const confirmPassword = form.querySelector(
|
|
42
|
-
'input[name="confirm-password"]'
|
|
43
|
-
) as HTMLInputElement;
|
|
44
|
-
|
|
45
|
-
if (password.value !== confirmPassword.value) {
|
|
46
|
-
toast({
|
|
47
|
-
title: 'Passwords do not match!',
|
|
48
|
-
type: 'danger',
|
|
49
|
-
description: 'Please make sure your passwords match.',
|
|
50
|
-
closeButton: true,
|
|
51
|
-
persistent: true,
|
|
52
|
-
});
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/* v8 ignore stop */
|
|
57
|
-
|
|
58
|
-
const response = await fetch(form.action, {
|
|
59
|
-
method: form.method,
|
|
60
|
-
body: new FormData(form),
|
|
61
|
-
});
|
|
62
|
-
if (response.ok) {
|
|
63
|
-
toast({
|
|
64
|
-
title: `${type === 'login' ? 'Login' : 'Registration'} successful!`,
|
|
65
|
-
type: 'success',
|
|
66
|
-
description: 'Redirecting...',
|
|
67
|
-
});
|
|
68
|
-
reload();
|
|
69
|
-
} else {
|
|
70
|
-
const {
|
|
71
|
-
error: { title, description },
|
|
72
|
-
} = await response.json();
|
|
73
|
-
toast({
|
|
74
|
-
title,
|
|
75
|
-
type: 'danger',
|
|
76
|
-
description,
|
|
77
|
-
closeButton: true,
|
|
78
|
-
persistent: true,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { z } from 'astro/zod';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Ensures the input value is returned as an array of strings.
|
|
5
|
-
*
|
|
6
|
-
* - If the input is `undefined`, `null`, or an empty string, returns an empty array.
|
|
7
|
-
* - If the input is already an array of strings, returns it as-is.
|
|
8
|
-
* - If the input is a JSON string representing an array, parses and returns the array.
|
|
9
|
-
* - For any other input, returns an empty array.
|
|
10
|
-
*
|
|
11
|
-
* @param val - The value to convert to a string array. Can be a string, an array of strings, or undefined.
|
|
12
|
-
* @returns An array of strings derived from the input value.
|
|
13
|
-
*/
|
|
14
|
-
function ensureStringArray(val: string | string[] | undefined): string[] {
|
|
15
|
-
if (!val) return [];
|
|
16
|
-
if (typeof val === 'string' && val.trim() === '') return [];
|
|
17
|
-
if (Array.isArray(val)) return val;
|
|
18
|
-
try {
|
|
19
|
-
const parsed = JSON.parse(val);
|
|
20
|
-
if (Array.isArray(parsed)) return parsed;
|
|
21
|
-
return [];
|
|
22
|
-
} catch {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Zod schema for validating and transforming data when creating a new StudioCMS page.
|
|
29
|
-
*
|
|
30
|
-
* Fields:
|
|
31
|
-
* - `title`: Required string. The title of the page. Must not be empty.
|
|
32
|
-
* - `slug`: Required string. Must be lowercase, only contain letters, numbers, and hyphens (no leading/trailing hyphens).
|
|
33
|
-
* - `description`: Optional string. A description of the page.
|
|
34
|
-
* - `package`: Required string. The package associated with the page.
|
|
35
|
-
* - `showOnNav`: Optional boolean (default: false). Whether to show the page in navigation.
|
|
36
|
-
* - `heroImage`: Optional string. URL or path to the hero image.
|
|
37
|
-
* - `parentFolder`: Optional string or null (default: null). The parent folder for the page.
|
|
38
|
-
* - `draft`: Optional boolean (default: false). Whether the page is a draft.
|
|
39
|
-
* - `showAuthor`: Optional boolean (default: false). Whether to display the author.
|
|
40
|
-
* - `showContributors`: Optional boolean (default: false). Whether to display contributors.
|
|
41
|
-
* - `categories`: Optional string or array of strings (default: []). Transformed to an array of strings.
|
|
42
|
-
* - `tags`: Optional string or array of strings (default: []). Transformed to an array of strings.
|
|
43
|
-
*
|
|
44
|
-
* Uses custom transformations to ensure `categories` and `tags` are always arrays of strings.
|
|
45
|
-
*/
|
|
46
|
-
export const studioCMSCreatePageDataSchema = z.object({
|
|
47
|
-
title: z.string().min(1, { message: 'Title is required' }),
|
|
48
|
-
slug: z.string().refine((val) => /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(val), {
|
|
49
|
-
message:
|
|
50
|
-
'Slug must be lowercase and can only contain letters, numbers, and hyphens (no leading/trailing hyphens)',
|
|
51
|
-
}),
|
|
52
|
-
description: z.string().optional(),
|
|
53
|
-
package: z.string(),
|
|
54
|
-
showOnNav: z.string().optional().transform(transformStringToBoolean),
|
|
55
|
-
heroImage: z.string().optional(),
|
|
56
|
-
parentFolder: z
|
|
57
|
-
.union([z.string(), z.null()])
|
|
58
|
-
.transform((value) => (value === 'null' || value === null ? null : value))
|
|
59
|
-
.optional()
|
|
60
|
-
.default(null),
|
|
61
|
-
draft: z.string().optional().transform(transformStringToBoolean),
|
|
62
|
-
showAuthor: z.string().optional().transform(transformStringToBoolean),
|
|
63
|
-
showContributors: z.string().optional().transform(transformStringToBoolean),
|
|
64
|
-
categories: z
|
|
65
|
-
.string()
|
|
66
|
-
.or(z.array(z.string()))
|
|
67
|
-
.optional()
|
|
68
|
-
.transform(ensureStringArray)
|
|
69
|
-
.default([]),
|
|
70
|
-
tags: z.string().or(z.array(z.string())).optional().transform(ensureStringArray).default([]),
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Schema for editing page data and content in StudioCMS.
|
|
75
|
-
*
|
|
76
|
-
* Extends the `studioCMSCreatePageDataSchema` with additional fields required for editing:
|
|
77
|
-
* - `id`: The unique identifier for the page.
|
|
78
|
-
* - `content`: The main content of the page as a string.
|
|
79
|
-
* - `contentId`: The unique identifier for the content.
|
|
80
|
-
* - `pluginFields`: An optional record of plugin-specific fields, where each value is a `FormDataEntryValue` or null.
|
|
81
|
-
*/
|
|
82
|
-
export const studioCMSEditPageDataAndContentSchema = studioCMSCreatePageDataSchema.extend({
|
|
83
|
-
id: z.string(),
|
|
84
|
-
content: z.string(),
|
|
85
|
-
contentId: z.string(),
|
|
86
|
-
pluginFields: z.record(z.custom<FormDataEntryValue>().nullable()).optional().default({}),
|
|
87
|
-
augments: z.array(z.string()).optional(),
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Converts a FormData object into a plain record object, optionally remapping keys.
|
|
92
|
-
*
|
|
93
|
-
* @param formData - The FormData instance to convert.
|
|
94
|
-
* @param keyRemapping - An optional mapping of original keys to new keys.
|
|
95
|
-
* @returns A record object where each key is either the original or remapped key, and each value is the corresponding FormData entry value.
|
|
96
|
-
*/
|
|
97
|
-
export function formDataToRecord(formData: FormData, keyRemapping?: Record<string, string>) {
|
|
98
|
-
const record: Record<string, FormDataEntryValue> = {};
|
|
99
|
-
for (const [key, value] of formData.entries()) {
|
|
100
|
-
const mappedKey = keyRemapping?.[key] || key;
|
|
101
|
-
record[mappedKey] = value;
|
|
102
|
-
}
|
|
103
|
-
return record;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Transform a string true/false value to boolean.
|
|
108
|
-
*
|
|
109
|
-
* - If the input value is undefined, return false.
|
|
110
|
-
*
|
|
111
|
-
* @param value - The value to transform, can be undefined, 'true' or 'false'.
|
|
112
|
-
* @returns Transformed value in boolean.
|
|
113
|
-
*/
|
|
114
|
-
export function transformStringToBoolean(value: string | undefined): boolean {
|
|
115
|
-
return !!value && value.toLowerCase() === 'true';
|
|
116
|
-
}
|