diff --git a/packages/console/src/pages/JwtClaims/Main.tsx b/packages/console/src/pages/JwtClaims/Main.tsx index 3a1dd543986..62374fdfa23 100644 --- a/packages/console/src/pages/JwtClaims/Main.tsx +++ b/packages/console/src/pages/JwtClaims/Main.tsx @@ -1,7 +1,7 @@ import { - type JwtCustomizerAccessToken, + type AccessTokenJwtCustomizer, LogtoJwtTokenPath, - type JwtCustomizerClientCredentials, + type ClientCredentialsJwtCustomizer, } from '@logto/schemas'; import classNames from 'classnames'; import { useMemo } from 'react'; @@ -21,10 +21,10 @@ import { formatResponseDataToFormData, formatFormDataToRequestData, getApiPath } type Props = { tab: LogtoJwtTokenPath; - accessTokenJwtCustomizer: JwtCustomizerAccessToken | undefined; - clientCredentialsJwtCustomizer: JwtCustomizerClientCredentials | undefined; - mutateAccessTokenJwtCustomizer: KeyedMutator; - mutateClientCredentialsJwtCustomizer: KeyedMutator; + accessTokenJwtCustomizer: AccessTokenJwtCustomizer | undefined; + clientCredentialsJwtCustomizer: ClientCredentialsJwtCustomizer | undefined; + mutateAccessTokenJwtCustomizer: KeyedMutator; + mutateClientCredentialsJwtCustomizer: KeyedMutator; }; function Main({ diff --git a/packages/console/src/pages/JwtClaims/use-jwt-customizer.ts b/packages/console/src/pages/JwtClaims/use-jwt-customizer.ts index c41b7840264..b28c95d5717 100644 --- a/packages/console/src/pages/JwtClaims/use-jwt-customizer.ts +++ b/packages/console/src/pages/JwtClaims/use-jwt-customizer.ts @@ -1,7 +1,7 @@ import { LogtoJwtTokenPath, - type JwtCustomizerAccessToken, - type JwtCustomizerClientCredentials, + type AccessTokenJwtCustomizer, + type ClientCredentialsJwtCustomizer, } from '@logto/schemas'; import { type ResponseError } from '@withtyped/client'; import { useMemo } from 'react'; @@ -15,15 +15,15 @@ import { getApiPath } from './utils'; function useJwtCustomizer() { const fetchApi = useApi({ hideErrorToast: true }); - const accessTokenFetcher = useSwrFetcher(fetchApi); - const clientCredentialsFetcher = useSwrFetcher(fetchApi); + const accessTokenFetcher = useSwrFetcher(fetchApi); + const clientCredentialsFetcher = useSwrFetcher(fetchApi); const { data: accessTokenJwtCustomizer, mutate: mutateAccessTokenJwtCustomizer, isLoading: isAccessTokenJwtDataLoading, error: accessTokenError, - } = useSWR(getApiPath(LogtoJwtTokenPath.AccessToken), { + } = useSWR(getApiPath(LogtoJwtTokenPath.AccessToken), { fetcher: accessTokenFetcher, shouldRetryOnError: shouldRetryOnError({ ignore: [404] }), }); @@ -33,7 +33,7 @@ function useJwtCustomizer() { mutate: mutateClientCredentialsJwtCustomizer, isLoading: isClientCredentialsJwtDataLoading, error: clientCredentialsError, - } = useSWR( + } = useSWR( getApiPath(LogtoJwtTokenPath.ClientCredentials), { fetcher: clientCredentialsFetcher, diff --git a/packages/console/src/pages/JwtClaims/utils.ts b/packages/console/src/pages/JwtClaims/utils.ts index b3f5c58a579..58ef054edea 100644 --- a/packages/console/src/pages/JwtClaims/utils.ts +++ b/packages/console/src/pages/JwtClaims/utils.ts @@ -1,13 +1,13 @@ import { type LogtoJwtTokenPath, - type JwtCustomizerAccessToken, - type JwtCustomizerClientCredentials, + type AccessTokenJwtCustomizer, + type ClientCredentialsJwtCustomizer, } from '@logto/schemas'; import type { JwtClaimsFormType } from './type'; const formatEnvVariablesResponseToFormData = ( - enVariables?: JwtCustomizerAccessToken['envVars'] + enVariables?: AccessTokenJwtCustomizer['envVars'] ) => { if (!enVariables) { return; @@ -16,9 +16,7 @@ const formatEnvVariablesResponseToFormData = ( return Object.entries(enVariables).map(([key, value]) => ({ key, value })); }; -const formatSampleCodeJsonToString = ( - sampleJson?: JwtCustomizerAccessToken['contextSample'] | JwtCustomizerAccessToken['tokenSample'] -) => { +const formatSampleCodeJsonToString = (sampleJson?: AccessTokenJwtCustomizer['contextSample']) => { if (!sampleJson) { return; } @@ -29,8 +27,8 @@ const formatSampleCodeJsonToString = ( export const formatResponseDataToFormData = ( tokenType: T, data?: T extends LogtoJwtTokenPath.AccessToken - ? JwtCustomizerAccessToken - : JwtCustomizerClientCredentials + ? AccessTokenJwtCustomizer + : ClientCredentialsJwtCustomizer ): JwtClaimsFormType => { return { script: data?.script, diff --git a/packages/core/src/routes/logto-config.ts b/packages/core/src/routes/logto-config.ts index 18c53b63589..5543462c841 100644 --- a/packages/core/src/routes/logto-config.ts +++ b/packages/core/src/routes/logto-config.ts @@ -12,8 +12,8 @@ import { type OidcConfigKeysResponse, type OidcConfigKey, LogtoOidcConfigKeyType, - jwtCustomizerAccessTokenGuard, - jwtCustomizerClientCredentialsGuard, + accessTokenJwtCustomizerGuard, + clientCredentialsJwtCustomizerGuard, LogtoJwtTokenKey, LogtoJwtTokenPath, } from '@logto/schemas'; @@ -37,12 +37,12 @@ const getJwtTokenKeyAndBody = (tokenPath: LogtoJwtTokenPath, body: unknown) => { if (tokenPath === LogtoJwtTokenPath.AccessToken) { return { key: LogtoJwtTokenKey.AccessToken, - body: parse('body', jwtCustomizerAccessTokenGuard, body), + body: parse('body', accessTokenJwtCustomizerGuard, body), }; } return { key: LogtoJwtTokenKey.ClientCredentials, - body: parse('body', jwtCustomizerClientCredentialsGuard, body), + body: parse('body', clientCredentialsJwtCustomizerGuard, body), }; }; @@ -219,7 +219,7 @@ export default function logtoConfigRoutes( * Should specify `body` in koaGuard, otherwise the request body is not accessible even via `ctx.request.body`. */ body: z.unknown(), - response: jwtCustomizerAccessTokenGuard.or(jwtCustomizerClientCredentialsGuard), + response: accessTokenJwtCustomizerGuard.or(clientCredentialsJwtCustomizerGuard), status: [200, 201, 400], }), async (ctx, next) => { @@ -248,7 +248,7 @@ export default function logtoConfigRoutes( params: z.object({ tokenTypePath: z.nativeEnum(LogtoJwtTokenPath), }), - response: jwtCustomizerAccessTokenGuard.or(jwtCustomizerClientCredentialsGuard), + response: accessTokenJwtCustomizerGuard.or(clientCredentialsJwtCustomizerGuard), status: [200, 404], }), async (ctx, next) => { diff --git a/packages/integration-tests/src/api/logto-config.ts b/packages/integration-tests/src/api/logto-config.ts index a657c39e6c4..569a5a342ae 100644 --- a/packages/integration-tests/src/api/logto-config.ts +++ b/packages/integration-tests/src/api/logto-config.ts @@ -3,8 +3,8 @@ import { type AdminConsoleData, type OidcConfigKeysResponse, type LogtoOidcConfigKeyType, - type JwtCustomizerAccessToken, - type JwtCustomizerClientCredentials, + type AccessTokenJwtCustomizer, + type ClientCredentialsJwtCustomizer, } from '@logto/schemas'; import { authedAdminApi } from './api.js'; @@ -39,12 +39,12 @@ export const upsertJwtCustomizer = async ( ) => authedAdminApi .put(`configs/jwt-customizer/${keyTypePath}`, { json: value }) - .json(); + .json(); export const getJwtCustomizer = async (keyTypePath: 'access-token' | 'client-credentials') => authedAdminApi .get(`configs/jwt-customizer/${keyTypePath}`) - .json(); + .json(); export const deleteJwtCustomizer = async (keyTypePath: 'access-token' | 'client-credentials') => authedAdminApi.delete(`configs/jwt-customizer/${keyTypePath}`); diff --git a/packages/schemas/src/types/logto-config/index.ts b/packages/schemas/src/types/logto-config/index.ts index a03bf33e43a..b47ad04424a 100644 --- a/packages/schemas/src/types/logto-config/index.ts +++ b/packages/schemas/src/types/logto-config/index.ts @@ -64,30 +64,30 @@ export const jwtCustomizerGuard = z }) .partial(); -export const jwtCustomizerAccessTokenGuard = jwtCustomizerGuard.extend({ +export const accessTokenJwtCustomizerGuard = jwtCustomizerGuard.extend({ // Use partial token guard since users customization may not rely on all fields. tokenSample: accessTokenPayloadGuard.partial().optional(), }); -export type JwtCustomizerAccessToken = z.infer; +export type AccessTokenJwtCustomizer = z.infer; -export const jwtCustomizerClientCredentialsGuard = jwtCustomizerGuard.extend({ +export const clientCredentialsJwtCustomizerGuard = jwtCustomizerGuard.extend({ // Use partial token guard since users customization may not rely on all fields. tokenSample: clientCredentialsPayloadGuard.partial().optional(), }); -export type JwtCustomizerClientCredentials = z.infer; +export type ClientCredentialsJwtCustomizer = z.infer; export type JwtCustomizerType = { - [LogtoJwtTokenKey.AccessToken]: JwtCustomizerAccessToken; - [LogtoJwtTokenKey.ClientCredentials]: JwtCustomizerClientCredentials; + [LogtoJwtTokenKey.AccessToken]: AccessTokenJwtCustomizer; + [LogtoJwtTokenKey.ClientCredentials]: ClientCredentialsJwtCustomizer; }; export const jwtCustomizerConfigGuard: Readonly<{ [key in LogtoJwtTokenKey]: ZodType; }> = Object.freeze({ - [LogtoJwtTokenKey.AccessToken]: jwtCustomizerAccessTokenGuard, - [LogtoJwtTokenKey.ClientCredentials]: jwtCustomizerClientCredentialsGuard, + [LogtoJwtTokenKey.AccessToken]: accessTokenJwtCustomizerGuard, + [LogtoJwtTokenKey.ClientCredentials]: clientCredentialsJwtCustomizerGuard, }); /* --- Logto tenant configs --- */