mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(core): add devFeature guard for DataHooks (#5861)
fix(core): add devFeature guard add devFeature guard
This commit is contained in:
parent
062d21764c
commit
f020c5984c
3 changed files with 14 additions and 2 deletions
|
@ -30,7 +30,7 @@ export const koaManagementApiHooks = <StateT, ContextT extends IRouterParamConte
|
|||
// TODO: Remove dev feature guard
|
||||
const { isDevFeaturesEnabled } = EnvSet.values;
|
||||
if (!isDevFeaturesEnabled) {
|
||||
return;
|
||||
return next();
|
||||
}
|
||||
|
||||
const {
|
||||
|
|
|
@ -3,8 +3,10 @@ import {
|
|||
Logs,
|
||||
hook,
|
||||
hookConfigGuard,
|
||||
hookEventGuard,
|
||||
hookEventsGuard,
|
||||
hookResponseGuard,
|
||||
interactionHookEventGuard,
|
||||
type Hook,
|
||||
type HookResponse,
|
||||
} from '@logto/schemas';
|
||||
|
@ -13,6 +15,7 @@ import { conditional, deduplicate, yes } from '@silverhand/essentials';
|
|||
import { subDays } from 'date-fns';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { EnvSet } from '#src/env-set/index.js';
|
||||
import RequestError from '#src/errors/RequestError/index.js';
|
||||
import koaGuard from '#src/middleware/koa-guard.js';
|
||||
import koaPagination from '#src/middleware/koa-pagination.js';
|
||||
|
@ -22,7 +25,12 @@ import assertThat from '#src/utils/assert-that.js';
|
|||
|
||||
import type { ManagementApiRouter, RouterInitArgs } from './types.js';
|
||||
|
||||
const nonemptyUniqueHookEventsGuard = hookEventsGuard
|
||||
const { isDevFeaturesEnabled } = EnvSet.values;
|
||||
// TODO: remove dev features guard
|
||||
const webhookEventsGuard = isDevFeaturesEnabled
|
||||
? hookEventsGuard
|
||||
: interactionHookEventGuard.array();
|
||||
const nonemptyUniqueHookEventsGuard = webhookEventsGuard
|
||||
.nonempty()
|
||||
.transform((events) => deduplicate(events));
|
||||
|
||||
|
@ -159,6 +167,8 @@ export default function hookRoutes<T extends ManagementApiRouter>(
|
|||
koaQuotaGuard({ key: 'hooksLimit', quota }),
|
||||
koaGuard({
|
||||
body: Hooks.createGuard.omit({ id: true, signingKey: true }).extend({
|
||||
// TODO: remove dev features guard
|
||||
event: (isDevFeaturesEnabled ? hookEventGuard : interactionHookEventGuard).optional(),
|
||||
events: nonemptyUniqueHookEventsGuard.optional(),
|
||||
}),
|
||||
response: Hooks.guard,
|
||||
|
|
|
@ -82,6 +82,8 @@ export const hookEventsGuard = hookEventGuard.array();
|
|||
|
||||
export type HookEvents = z.infer<typeof hookEventsGuard>;
|
||||
|
||||
export const interactionHookEventGuard = z.nativeEnum(InteractionHookEvent);
|
||||
|
||||
/**
|
||||
* Hook configuration for web hook.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue