mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-27 03:02:30 +00:00
Fix type imports
This commit is contained in:
@@ -11,7 +11,6 @@
|
|||||||
* This file is not licensed under the AGPLv3.
|
* This file is not licensed under the AGPLv3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./types";
|
|
||||||
export * from "./processAlerts";
|
export * from "./processAlerts";
|
||||||
export * from "./sendAlertWebhook";
|
export * from "./sendAlertWebhook";
|
||||||
export * from "./sendAlertEmail";
|
export * from "./sendAlertEmail";
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ import {
|
|||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import { decrypt } from "@server/lib/crypto";
|
import { decrypt } from "@server/lib/crypto";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { AlertContext, WebhookAlertConfig } from "./types";
|
|
||||||
import { sendAlertWebhook } from "./sendAlertWebhook";
|
import { sendAlertWebhook } from "./sendAlertWebhook";
|
||||||
import { sendAlertEmail } from "./sendAlertEmail";
|
import { sendAlertEmail } from "./sendAlertEmail";
|
||||||
|
import { AlertContext, WebhookAlertConfig } from "@server/routers/alertRule/types";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core alert processing pipeline.
|
* Core alert processing pipeline.
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { sendEmail } from "@server/emails";
|
|||||||
import AlertNotification from "@server/emails/templates/AlertNotification";
|
import AlertNotification from "@server/emails/templates/AlertNotification";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { AlertContext } from "./types";
|
import { AlertContext } from "@server/routers/alertRule/types";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an alert notification email to every address in `recipients`.
|
* Sends an alert notification email to every address in `recipients`.
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { AlertContext, WebhookAlertConfig } from "./types";
|
import { AlertContext, WebhookAlertConfig } from "@server/routers/alertRule/types";
|
||||||
|
|
||||||
const REQUEST_TIMEOUT_MS = 15_000;
|
const REQUEST_TIMEOUT_MS = 15_000;
|
||||||
|
|
||||||
@@ -137,4 +137,4 @@ function buildHeaders(webhookConfig: WebhookAlertConfig): Record<string, string>
|
|||||||
}
|
}
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of a proprietary work.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025-2026 Fossorial, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This file is licensed under the Fossorial Commercial License.
|
|
||||||
* You may not use this file except in compliance with the License.
|
|
||||||
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
|
||||||
*
|
|
||||||
* This file is not licensed under the AGPLv3.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Alert event types
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export type AlertEventType =
|
|
||||||
| "site_online"
|
|
||||||
| "site_offline"
|
|
||||||
| "site_toggle"
|
|
||||||
| "health_check_healthy"
|
|
||||||
| "health_check_unhealthy"
|
|
||||||
| "health_check_toggle"
|
|
||||||
| "resource_healthy"
|
|
||||||
| "resource_unhealthy"
|
|
||||||
| "resource_toggle";
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Webhook authentication config (stored as encrypted JSON in the DB)
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export type WebhookAuthType = "none" | "bearer" | "basic" | "custom";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stored as an encrypted JSON blob in `alertWebhookActions.config`.
|
|
||||||
*/
|
|
||||||
export interface WebhookAlertConfig {
|
|
||||||
/** Authentication strategy for the webhook endpoint */
|
|
||||||
authType: WebhookAuthType;
|
|
||||||
/** Bearer token – used when authType === "bearer" */
|
|
||||||
bearerToken?: string;
|
|
||||||
/** Basic credentials – "username:password" – used when authType === "basic" */
|
|
||||||
basicCredentials?: string;
|
|
||||||
/** Custom header name – used when authType === "custom" */
|
|
||||||
customHeaderName?: string;
|
|
||||||
/** Custom header value – used when authType === "custom" */
|
|
||||||
customHeaderValue?: string;
|
|
||||||
/** Extra headers to send with every webhook request */
|
|
||||||
headers?: Array<{ key: string; value: string }>;
|
|
||||||
/** HTTP method (default POST) */
|
|
||||||
method?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Internal alert event passed through the processing pipeline
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export interface AlertContext {
|
|
||||||
eventType: AlertEventType;
|
|
||||||
orgId: string;
|
|
||||||
/** Set for site_online / site_offline events */
|
|
||||||
siteId?: number;
|
|
||||||
/** Set for health_check_* events */
|
|
||||||
healthCheckId?: number;
|
|
||||||
/** Set for resource_* events */
|
|
||||||
resourceId?: number;
|
|
||||||
/** Human-readable context data included in emails and webhook payloads */
|
|
||||||
data: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
@@ -31,6 +31,7 @@ import { fromError } from "zod-validation-error";
|
|||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
import { encrypt } from "@server/lib/crypto";
|
import { encrypt } from "@server/lib/crypto";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
|
import { CreateAlertRuleResponse } from "@server/routers/alertRule/types";
|
||||||
|
|
||||||
export const SITE_EVENT_TYPES = ["site_online", "site_offline", "site_toggle"] as const;
|
export const SITE_EVENT_TYPES = ["site_online", "site_offline", "site_toggle"] as const;
|
||||||
export const HC_EVENT_TYPES = [
|
export const HC_EVENT_TYPES = [
|
||||||
@@ -169,10 +170,6 @@ const bodySchema = z
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export type CreateAlertRuleResponse = {
|
|
||||||
alertRuleId: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
registry.registerPath({
|
registry.registerPath({
|
||||||
method: "put",
|
method: "put",
|
||||||
path: "/org/{orgId}/alert-rule",
|
path: "/org/{orgId}/alert-rule",
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import { OpenAPITags, registry } from "@server/openApi";
|
|||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import { decrypt } from "@server/lib/crypto";
|
import { decrypt } from "@server/lib/crypto";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import { WebhookAlertConfig } from "#private/lib/alerts/types";
|
import { GetAlertRuleResponse, WebhookAlertConfig } from "@server/routers/alertRule/types";
|
||||||
|
|
||||||
const paramsSchema = z
|
const paramsSchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -41,43 +41,6 @@ const paramsSchema = z
|
|||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
export type GetAlertRuleResponse = {
|
|
||||||
alertRuleId: number;
|
|
||||||
orgId: string;
|
|
||||||
name: string;
|
|
||||||
eventType:
|
|
||||||
| "site_online"
|
|
||||||
| "site_offline"
|
|
||||||
| "site_toggle"
|
|
||||||
| "health_check_healthy"
|
|
||||||
| "health_check_unhealthy"
|
|
||||||
| "health_check_toggle"
|
|
||||||
| "resource_healthy"
|
|
||||||
| "resource_unhealthy"
|
|
||||||
| "resource_toggle";
|
|
||||||
enabled: boolean;
|
|
||||||
cooldownSeconds: number;
|
|
||||||
lastTriggeredAt: number | null;
|
|
||||||
createdAt: number;
|
|
||||||
updatedAt: number;
|
|
||||||
siteIds: number[];
|
|
||||||
healthCheckIds: number[];
|
|
||||||
resourceIds: number[];
|
|
||||||
recipients: {
|
|
||||||
recipientId: number;
|
|
||||||
userId: string | null;
|
|
||||||
roleId: number | null;
|
|
||||||
email: string | null;
|
|
||||||
}[];
|
|
||||||
webhookActions: {
|
|
||||||
webhookActionId: number;
|
|
||||||
webhookUrl: string;
|
|
||||||
enabled: boolean;
|
|
||||||
lastSentAt: number | null;
|
|
||||||
config: WebhookAlertConfig | null;
|
|
||||||
}[];
|
|
||||||
};
|
|
||||||
|
|
||||||
registry.registerPath({
|
registry.registerPath({
|
||||||
method: "get",
|
method: "get",
|
||||||
path: "/org/{orgId}/alert-rule/{alertRuleId}",
|
path: "/org/{orgId}/alert-rule/{alertRuleId}",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import logger from "@server/logger";
|
|||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
import { and, asc, desc, eq, inArray, like, or, sql } from "drizzle-orm";
|
import { and, asc, desc, eq, inArray, like, or, sql } from "drizzle-orm";
|
||||||
|
import { ListAlertRulesResponse } from "@server/routers/alertRule/types";
|
||||||
|
|
||||||
const paramsSchema = z.strictObject({
|
const paramsSchema = z.strictObject({
|
||||||
orgId: z.string().nonempty()
|
orgId: z.string().nonempty()
|
||||||
|
|||||||
@@ -19,3 +19,102 @@ export type ListAlertRulesResponse = {
|
|||||||
offset: number;
|
offset: number;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CreateAlertRuleResponse = {
|
||||||
|
alertRuleId: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type GetAlertRuleResponse = {
|
||||||
|
alertRuleId: number;
|
||||||
|
orgId: string;
|
||||||
|
name: string;
|
||||||
|
eventType:
|
||||||
|
| "site_online"
|
||||||
|
| "site_offline"
|
||||||
|
| "site_toggle"
|
||||||
|
| "health_check_healthy"
|
||||||
|
| "health_check_unhealthy"
|
||||||
|
| "health_check_toggle"
|
||||||
|
| "resource_healthy"
|
||||||
|
| "resource_unhealthy"
|
||||||
|
| "resource_toggle";
|
||||||
|
enabled: boolean;
|
||||||
|
cooldownSeconds: number;
|
||||||
|
lastTriggeredAt: number | null;
|
||||||
|
createdAt: number;
|
||||||
|
updatedAt: number;
|
||||||
|
siteIds: number[];
|
||||||
|
healthCheckIds: number[];
|
||||||
|
resourceIds: number[];
|
||||||
|
recipients: {
|
||||||
|
recipientId: number;
|
||||||
|
userId: string | null;
|
||||||
|
roleId: number | null;
|
||||||
|
email: string | null;
|
||||||
|
}[];
|
||||||
|
webhookActions: {
|
||||||
|
webhookActionId: number;
|
||||||
|
webhookUrl: string;
|
||||||
|
enabled: boolean;
|
||||||
|
lastSentAt: number | null;
|
||||||
|
config: WebhookAlertConfig | null;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stored as an encrypted JSON blob in `alertWebhookActions.config`.
|
||||||
|
*/
|
||||||
|
export interface WebhookAlertConfig {
|
||||||
|
/** Authentication strategy for the webhook endpoint */
|
||||||
|
authType: WebhookAuthType;
|
||||||
|
/** Bearer token – used when authType === "bearer" */
|
||||||
|
bearerToken?: string;
|
||||||
|
/** Basic credentials – "username:password" – used when authType === "basic" */
|
||||||
|
basicCredentials?: string;
|
||||||
|
/** Custom header name – used when authType === "custom" */
|
||||||
|
customHeaderName?: string;
|
||||||
|
/** Custom header value – used when authType === "custom" */
|
||||||
|
customHeaderValue?: string;
|
||||||
|
/** Extra headers to send with every webhook request */
|
||||||
|
headers?: Array<{ key: string; value: string }>;
|
||||||
|
/** HTTP method (default POST) */
|
||||||
|
method?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Alert event types
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export type AlertEventType =
|
||||||
|
| "site_online"
|
||||||
|
| "site_offline"
|
||||||
|
| "site_toggle"
|
||||||
|
| "health_check_healthy"
|
||||||
|
| "health_check_unhealthy"
|
||||||
|
| "health_check_toggle"
|
||||||
|
| "resource_healthy"
|
||||||
|
| "resource_unhealthy"
|
||||||
|
| "resource_toggle";
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Webhook authentication config (stored as encrypted JSON in the DB)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export type WebhookAuthType = "none" | "bearer" | "basic" | "custom";
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Internal alert event passed through the processing pipeline
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export interface AlertContext {
|
||||||
|
eventType: AlertEventType;
|
||||||
|
orgId: string;
|
||||||
|
/** Set for site_online / site_offline events */
|
||||||
|
siteId?: number;
|
||||||
|
/** Set for health_check_* events */
|
||||||
|
healthCheckId?: number;
|
||||||
|
/** Set for resource_* events */
|
||||||
|
resourceId?: number;
|
||||||
|
/** Human-readable context data included in emails and webhook payloads */
|
||||||
|
data: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { useParams, useRouter } from "next/navigation";
|
|||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import type { AxiosResponse } from "axios";
|
import type { AxiosResponse } from "axios";
|
||||||
import type { GetAlertRuleResponse } from "@server/private/routers/alertRule";
|
import type { GetAlertRuleResponse } from "@server/routers/alertRule/types";
|
||||||
import type { AlertRuleFormValues } from "@app/lib/alertRuleForm";
|
import type { AlertRuleFormValues } from "@app/lib/alertRuleForm";
|
||||||
|
|
||||||
export default function EditAlertRulePage() {
|
export default function EditAlertRulePage() {
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export function LayoutSidebar({
|
|||||||
const showTrial =
|
const showTrial =
|
||||||
build === "saas" &&
|
build === "saas" &&
|
||||||
Boolean(orgId) &&
|
Boolean(orgId) &&
|
||||||
subscriptionContext?.isTrial
|
subscriptionContext?.isTrial;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import {
|
|||||||
} from "@app/lib/alertRuleForm";
|
} from "@app/lib/alertRuleForm";
|
||||||
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
import type { CreateAlertRuleResponse } from "@server/private/routers/alertRule";
|
import type { CreateAlertRuleResponse } from "@server/routers/alertRule/types";
|
||||||
import type { AxiosResponse } from "axios";
|
import type { AxiosResponse } from "axios";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { ChevronLeft, Cog, Flag, Zap } from "lucide-react";
|
import { ChevronLeft, Cog, Flag, Zap } from "lucide-react";
|
||||||
|
|||||||
Reference in New Issue
Block a user