mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor: patch type issues
This commit is contained in:
parent
e3109af026
commit
f96277b410
3 changed files with 17 additions and 6 deletions
|
@ -55,12 +55,19 @@ export const buildOidcClientMetadata = (metadata?: OidcClientMetadata): OidcClie
|
|||
...metadata,
|
||||
});
|
||||
|
||||
export const validateCustomClientMetadata = (key: string, value: unknown) => {
|
||||
const result = customClientMetadataGuard.pick({ [key]: true }).safeParse({ [key]: value });
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
const isKeyOf = <T extends object>(object: T, key: string | number | symbol): key is keyof T =>
|
||||
key in object;
|
||||
|
||||
if (!result.success) {
|
||||
throw new errors.InvalidClientMetadata(key);
|
||||
export const validateCustomClientMetadata = (key: string, value: unknown) => {
|
||||
if (isKeyOf(customClientMetadataGuard.shape, key)) {
|
||||
const result = customClientMetadataGuard.shape[key].safeParse(value);
|
||||
if (result.success) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new errors.InvalidClientMetadata(key);
|
||||
};
|
||||
|
||||
export const isOriginAllowed = (
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
jwtCustomizerConfigsGuard,
|
||||
jwtCustomizerTestRequestBodyGuard,
|
||||
} from '@logto/schemas';
|
||||
import { removeUndefinedKeys } from '@silverhand/essentials';
|
||||
import { ResponseError } from '@withtyped/client';
|
||||
import { ZodError, z } from 'zod';
|
||||
|
||||
|
@ -236,7 +237,7 @@ export default function logtoConfigJwtCustomizerRoutes<T extends ManagementApiRo
|
|||
search: { isTest: 'true' },
|
||||
});
|
||||
} else {
|
||||
ctx.body = await JwtCustomizerLibrary.runScriptInLocalVm(body);
|
||||
ctx.body = removeUndefinedKeys(await JwtCustomizerLibrary.runScriptInLocalVm(body));
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
/**
|
||||
|
|
|
@ -286,7 +286,9 @@ export default class SchemaRouter<
|
|||
this.delete(
|
||||
`/:id/${pathname}/:${camelCaseSchemaId(relationSchema)}`,
|
||||
koaGuard({
|
||||
params: z.object({ id: z.string().min(1), [relationSchemaId]: z.string().min(1) }),
|
||||
params: z
|
||||
.object({ id: z.string().min(1) })
|
||||
.extend({ [relationSchemaId]: z.string().min(1) }),
|
||||
status: [204, 422],
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
|
@ -337,6 +339,7 @@ export default class SchemaRouter<
|
|||
this.post(
|
||||
'/',
|
||||
koaGuard({
|
||||
// @ts-expect-error -- `.omit()` doesn't play well with generics
|
||||
body: schema.createGuard.omit({ id: true }),
|
||||
response: entityGuard ?? schema.guard,
|
||||
status: [201], // TODO: 409/422 for conflict?
|
||||
|
|
Loading…
Reference in a new issue