From 936a8733cf877db136b5c42c3a75aca3c9f8460d Mon Sep 17 00:00:00 2001 From: wangsijie Date: Tue, 6 Feb 2024 11:32:31 +0800 Subject: [PATCH] chore(core): remove dev features flag from core (#5371) chore(console): remove dev features flag from core --- .../src/routes/applications/application.ts | 15 +++---- .../core/src/routes/applications/types.ts | 39 +------------------ packages/core/src/routes/init.ts | 5 +-- packages/core/src/routes/role.application.ts | 4 +- packages/core/src/routes/system.ts | 28 ++++++------- 5 files changed, 23 insertions(+), 68 deletions(-) diff --git a/packages/core/src/routes/applications/application.ts b/packages/core/src/routes/applications/application.ts index c66732539..f8ddda6cc 100644 --- a/packages/core/src/routes/applications/application.ts +++ b/packages/core/src/routes/applications/application.ts @@ -4,6 +4,7 @@ import { buildDemoAppDataForTenant, InternalRole, ApplicationType, + Applications, } from '@logto/schemas'; import { generateStandardId, generateStandardSecret } from '@logto/shared'; import { conditional } from '@silverhand/essentials'; @@ -18,11 +19,7 @@ import { parseSearchParamsForSearch } from '#src/utils/search.js'; import type { AuthedRouter, RouterInitArgs } from '../types.js'; -import { - applicationResponseGuard, - applicationCreateGuard, - applicationPatchGuard, -} from './types.js'; +import { applicationCreateGuard, applicationPatchGuard } from './types.js'; const includesInternalAdminRole = (roles: Readonly>) => roles.some(({ role: { name } }) => name === InternalRole.Admin); @@ -81,7 +78,7 @@ export default function applicationRoutes( excludeRoleId: string().optional(), isThirdParty: z.union([z.literal('true'), z.literal('false')]).optional(), }), - response: z.array(applicationResponseGuard), + response: z.array(Applications.guard), status: 200, }), async (ctx, next) => { @@ -131,7 +128,7 @@ export default function applicationRoutes( '/applications', koaGuard({ body: applicationCreateGuard, - response: applicationResponseGuard, + response: Applications.guard, status: [200, 400, 422], }), async (ctx, next) => { @@ -194,7 +191,7 @@ export default function applicationRoutes( '/applications/:id', koaGuard({ params: object({ id: string().min(1) }), - response: applicationResponseGuard.merge(z.object({ isAdmin: z.boolean() })), + response: Applications.guard.merge(z.object({ isAdmin: z.boolean() })), status: [200, 404], }), async (ctx, next) => { @@ -230,7 +227,7 @@ export default function applicationRoutes( isAdmin: boolean().optional(), }) ), - response: applicationResponseGuard, + response: Applications.guard, status: [200, 404, 422, 500], }), async (ctx, next) => { diff --git a/packages/core/src/routes/applications/types.ts b/packages/core/src/routes/applications/types.ts index 42ae4cf68..135e64b64 100644 --- a/packages/core/src/routes/applications/types.ts +++ b/packages/core/src/routes/applications/types.ts @@ -1,29 +1,10 @@ import { - Applications, applicationCreateGuard as originalApplicationCreateGuard, applicationPatchGuard as originalApplicationPatchGuard, } from '@logto/schemas'; import { z } from 'zod'; -import { EnvSet } from '#src/env-set/index.js'; - -enum OriginalApplicationType { - Native = 'Native', - SPA = 'SPA', - Traditional = 'Traditional', - MachineToMachine = 'MachineToMachine', -} - -// FIXME: @wangsijie Remove this guard once protected app is ready -// @ts-expect-error -- hide the dev feature field from the guard type, but always return the full type to make the api logic simpler -export const applicationResponseGuard: typeof Applications.guard = EnvSet.values - .isDevFeaturesEnabled - ? Applications.guard - : Applications.guard - .omit({ type: true, protectedAppMetadata: true }) - .extend({ type: z.nativeEnum(OriginalApplicationType) }); - -const applicationCreateGuardWithProtectedAppMetadata = originalApplicationCreateGuard +export const applicationCreateGuard = originalApplicationCreateGuard .omit({ protectedAppMetadata: true, }) @@ -36,7 +17,7 @@ const applicationCreateGuardWithProtectedAppMetadata = originalApplicationCreate .optional(), }); -const applicationPatchGuardWithProtectedAppMetadata = originalApplicationPatchGuard +export const applicationPatchGuard = originalApplicationPatchGuard .deepPartial() .omit({ protectedAppMetadata: true, @@ -57,19 +38,3 @@ const applicationPatchGuardWithProtectedAppMetadata = originalApplicationPatchGu }) .optional(), }); - -// FIXME: @wangsijie Remove this guard once protected app is ready -// @ts-expect-error -- hide the dev feature field from the guard type, but always return the full type to make the api logic simpler -export const applicationCreateGuard: typeof applicationCreateGuardWithProtectedAppMetadata = EnvSet - .values.isDevFeaturesEnabled - ? applicationCreateGuardWithProtectedAppMetadata - : applicationCreateGuardWithProtectedAppMetadata - .omit({ type: true, protectedAppMetadata: true }) - .extend({ type: z.nativeEnum(OriginalApplicationType) }); - -// FIXME: @wangsijie Remove this guard once protected app is ready -// @ts-expect-error -- hide the dev feature field from the guard type, but always return the full type to make the api logic simpler -export const applicationPatchGuard: typeof applicationPatchGuardWithProtectedAppMetadata = EnvSet - .values.isDevFeaturesEnabled - ? applicationPatchGuardWithProtectedAppMetadata - : applicationPatchGuardWithProtectedAppMetadata.omit({ protectedAppMetadata: true }); diff --git a/packages/core/src/routes/init.ts b/packages/core/src/routes/init.ts index fed92f6c9..99f134c22 100644 --- a/packages/core/src/routes/init.ts +++ b/packages/core/src/routes/init.ts @@ -56,10 +56,7 @@ const createRouters = (tenant: TenantContext) => { applicationSignInExperienceRoutes(managementRouter, tenant); applicationUserConsentOrganizationRoutes(managementRouter, tenant); - // FIXME: @wangsijie: remove this after the feature is enabled by default - if (!EnvSet.values.isCloud) { - applicationProtectedAppMetadataRoutes(managementRouter, tenant); - } + applicationProtectedAppMetadataRoutes(managementRouter, tenant); logtoConfigRoutes(managementRouter, tenant); connectorRoutes(managementRouter, tenant); diff --git a/packages/core/src/routes/role.application.ts b/packages/core/src/routes/role.application.ts index c65bd2b44..7e78b08d7 100644 --- a/packages/core/src/routes/role.application.ts +++ b/packages/core/src/routes/role.application.ts @@ -1,3 +1,4 @@ +import { Applications } from '@logto/schemas'; import { generateStandardId } from '@logto/shared'; import { tryThat } from '@silverhand/essentials'; import { object, string } from 'zod'; @@ -7,7 +8,6 @@ import koaGuard from '#src/middleware/koa-guard.js'; import koaPagination from '#src/middleware/koa-pagination.js'; import { parseSearchParamsForSearch } from '#src/utils/search.js'; -import { applicationResponseGuard } from './applications/types.js'; import type { AuthedRouter, RouterInitArgs } from './types.js'; export default function roleApplicationRoutes( @@ -29,7 +29,7 @@ export default function roleApplicationRoutes( koaPagination(), koaGuard({ params: object({ id: string().min(1) }), - response: applicationResponseGuard.array(), + response: Applications.guard.array(), status: [200, 204, 400, 404], }), async (ctx, next) => { diff --git a/packages/core/src/routes/system.ts b/packages/core/src/routes/system.ts index cf432c725..250c279c1 100644 --- a/packages/core/src/routes/system.ts +++ b/packages/core/src/routes/system.ts @@ -1,6 +1,5 @@ import { object, string } from 'zod'; -import { EnvSet } from '#src/env-set/index.js'; import koaGuard from '#src/middleware/koa-guard.js'; import type { AuthedRouter, RouterInitArgs } from './types.js'; @@ -13,21 +12,18 @@ export default function systemRoutes( }, ]: RouterInitArgs ) { - // FIXME: @wangsijie - if (EnvSet.values.isDevFeaturesEnabled) { - router.get( - '/systems/application', - koaGuard({ - response: object({ protectedApps: object({ defaultDomain: string() }) }), - status: [200, 501], - }), - async (ctx, next) => { - const defaultDomain = await protectedApps.getDefaultDomain(); + router.get( + '/systems/application', + koaGuard({ + response: object({ protectedApps: object({ defaultDomain: string() }) }), + status: [200, 501], + }), + async (ctx, next) => { + const defaultDomain = await protectedApps.getDefaultDomain(); - ctx.body = { protectedApps: { defaultDomain } }; + ctx.body = { protectedApps: { defaultDomain } }; - return next(); - } - ); - } + return next(); + } + ); }