Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): add devFeature guard for DataHooks #5861

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/middleware/koa-management-api-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
hooks: Libraries['hooks']
): MiddlewareType<StateT, WithHookContext<ContextT>, ResponseT> => {
return async (ctx, next) => {
// TODO: Remove dev feature guard

Check warning on line 30 in packages/core/src/middleware/koa-management-api-hooks.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/middleware/koa-management-api-hooks.ts#L30

[no-warning-comments] Unexpected 'todo' comment: 'TODO: Remove dev feature guard'.
const { isDevFeaturesEnabled } = EnvSet.values;
if (!isDevFeaturesEnabled) {
return;
return next();
}

const {
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/routes/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
Logs,
hook,
hookConfigGuard,
hookEventGuard,
hookEventsGuard,
hookResponseGuard,
interactionHookEventGuard,
type Hook,
type HookResponse,
} from '@logto/schemas';
Expand All @@ -13,6 +15,7 @@
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';
Expand All @@ -22,7 +25,12 @@

import type { ManagementApiRouter, RouterInitArgs } from './types.js';

const nonemptyUniqueHookEventsGuard = hookEventsGuard
const { isDevFeaturesEnabled } = EnvSet.values;
// TODO: remove dev features guard

Check warning on line 29 in packages/core/src/routes/hook.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/routes/hook.ts#L29

[no-warning-comments] Unexpected 'todo' comment: 'TODO: remove dev features guard'.
const webhookEventsGuard = isDevFeaturesEnabled
? hookEventsGuard
: interactionHookEventGuard.array();
const nonemptyUniqueHookEventsGuard = webhookEventsGuard
.nonempty()
.transform((events) => deduplicate(events));

Expand Down Expand Up @@ -159,6 +167,8 @@
koaQuotaGuard({ key: 'hooksLimit', quota }),
koaGuard({
body: Hooks.createGuard.omit({ id: true, signingKey: true }).extend({
// TODO: remove dev features guard

Check warning on line 170 in packages/core/src/routes/hook.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/routes/hook.ts#L170

[no-warning-comments] Unexpected 'todo' comment: 'TODO: remove dev features guard'.
event: (isDevFeaturesEnabled ? hookEventGuard : interactionHookEventGuard).optional(),
events: nonemptyUniqueHookEventsGuard.optional(),
}),
response: Hooks.guard,
Expand Down
2 changes: 2 additions & 0 deletions packages/schemas/src/foundations/jsonb-types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Loading