Closes #12303 ### What’s Changed - Replace auto‐save with explicit Save / Cancel Webhook forms now use manual “Save” and “Cancel” buttons instead of the old debounced auto‐save/update. - Separate “New” and “Detail” routes Two dedicated paths `/settings/webhooks/new` for creation and /`settings/webhooks/:webhookId` for editing, making the UX clearer. - URL hint & normalization If a user omits the http(s):// scheme, we display a “Will be saved as https://…” hint and automatically default to HTTPS. - Centralized validation with Zod Introduced a `webhookFormSchema` for client‐side URL, operations, and secret validation. - Storybook coverage Added stories for both “New Webhook” and “Webhook Detail” - Unit tests Added tests for the new `useWebhookForm` hook
30 lines
914 B
TypeScript
30 lines
914 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
|
|
import {
|
|
GraphqlQueryRunnerException,
|
|
GraphqlQueryRunnerExceptionCode,
|
|
} from 'src/engine/api/graphql/graphql-query-runner/errors/graphql-query-runner.exception';
|
|
|
|
@Injectable()
|
|
export class WebhookUrlValidationService {
|
|
validateWebhookUrl(targetUrl: string): void {
|
|
let parsedUrl: URL;
|
|
|
|
try {
|
|
parsedUrl = new URL(targetUrl);
|
|
} catch {
|
|
throw new GraphqlQueryRunnerException(
|
|
`Invalid URL: missing scheme. URLs must include http:// or https://. Received: ${targetUrl}`,
|
|
GraphqlQueryRunnerExceptionCode.INVALID_QUERY_INPUT,
|
|
);
|
|
}
|
|
|
|
if (!['http:', 'https:'].includes(parsedUrl.protocol)) {
|
|
throw new GraphqlQueryRunnerException(
|
|
`Invalid URL scheme. Only HTTP and HTTPS are allowed. Received: ${parsedUrl.protocol}`,
|
|
GraphqlQueryRunnerExceptionCode.INVALID_QUERY_INPUT,
|
|
);
|
|
}
|
|
}
|
|
}
|