feat : notify new update income

This commit is contained in:
2026-09-26 23:34:42 +07:00 Unverified
parent e99a5b76b1
commit 4ef1968b04
14 changed files with 499 additions and 33 deletions
+42
View File
@@ -0,0 +1,42 @@
export const DEPLOYMENT_STATUSES = ["deploying", "ready", "failed"] as const;
export type DeploymentStatus = (typeof DEPLOYMENT_STATUSES)[number];
export interface DeploymentStatusEvent {
deploymentId: string;
status: DeploymentStatus;
updatedAt: string;
}
const DEPLOYMENT_ID_PATTERN = /^[a-f0-9]{40}$/u;
export function isDeploymentId(value: unknown): value is string {
return typeof value === "string" && DEPLOYMENT_ID_PATTERN.test(value);
}
export function isDeploymentStatus(value: unknown): value is DeploymentStatus {
return DEPLOYMENT_STATUSES.some((status) => status === value);
}
export function parseDeploymentStatusEvent(
value: string,
): DeploymentStatusEvent | null {
try {
const parsed = JSON.parse(value) as Record<string, unknown>;
if (
!isDeploymentId(parsed.deploymentId) ||
!isDeploymentStatus(parsed.status) ||
typeof parsed.updatedAt !== "string" ||
!Number.isFinite(Date.parse(parsed.updatedAt))
) {
return null;
}
return {
deploymentId: parsed.deploymentId,
status: parsed.status,
updatedAt: parsed.updatedAt,
};
} catch {
return null;
}
}