replace inline objects with defined constants

This commit is contained in:
Alex Holliday committed 2026-05-01 11:31:52 -07:00
1 parent a57da284d7
commit 34feb6d3fa
5 files changed
+195 -128

No files matched your search

+87 -71
View File
@@ -81,58 +81,72 @@
"$ref": "#/components/schemas/User" "$ref": "#/components/schemas/User"
}, },
"token": { "token": {
"type": "string", "type": "string"
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
} }
}, },
"required": ["user"] "required": ["user"],
"example": {
"user": {
"_id": "65f1c2a4d8b9e0123456789a",
"firstName": "Ada",
"lastName": "Lovelace",
"email": "ada@example.com",
"role": ["admin"],
"teamId": "65f1c2a4d8b9e01234567890",
"createdAt": "2026-04-01T10:00:00.000Z",
"updatedAt": "2026-04-15T14:30:00.000Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}, },
"User": { "User": {
"type": "object", "type": "object",
"properties": { "properties": {
"_id": { "_id": {
"type": "string", "type": "string"
"example": "65f1c2a4d8b9e0123456789a"
}, },
"firstName": { "firstName": {
"type": "string", "type": "string"
"example": "Ada"
}, },
"lastName": { "lastName": {
"type": "string", "type": "string"
"example": "Lovelace"
}, },
"email": { "email": {
"type": "string", "type": "string"
"example": "ada@example.com"
}, },
"role": { "role": {
"type": "array", "type": "array",
"items": { "items": {
"type": "string" "type": "string"
}, }
"example": ["admin"]
}, },
"teamId": { "teamId": {
"type": "string", "type": "string"
"example": "65f1c2a4d8b9e01234567890"
}, },
"profileImage": { "profileImage": {
"type": "string", "type": "string",
"nullable": true "nullable": true
}, },
"createdAt": { "createdAt": {
"type": "string", "type": "string"
"example": "2026-04-01T10:00:00.000Z"
}, },
"updatedAt": { "updatedAt": {
"type": "string", "type": "string"
"example": "2026-04-15T14:30:00.000Z"
} }
}, },
"required": ["_id", "firstName", "lastName", "email", "role", "createdAt", "updatedAt"], "required": ["_id", "firstName", "lastName", "email", "role", "createdAt", "updatedAt"],
"additionalProperties": { "additionalProperties": {
"nullable": true "nullable": true
},
"example": {
"_id": "65f1c2a4d8b9e0123456789a",
"firstName": "Ada",
"lastName": "Lovelace",
"email": "ada@example.com",
"role": ["admin"],
"teamId": "65f1c2a4d8b9e01234567890",
"createdAt": "2026-04-01T10:00:00.000Z",
"updatedAt": "2026-04-15T14:30:00.000Z"
} }
}, },
"Incident": { "Incident": {
@@ -322,58 +336,45 @@
"type": "object", "type": "object",
"properties": { "properties": {
"_id": { "_id": {
"type": "string", "type": "string"
"example": "65f1c2a4d8b9e0123456789a"
}, },
"name": { "name": {
"type": "string", "type": "string"
"example": "Marketing site"
}, },
"description": { "description": {
"type": "string", "type": "string"
"example": "Production marketing site monitored from the EU region"
}, },
"type": { "type": {
"type": "string", "type": "string",
"enum": ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc", "websocket", "unknown"], "enum": ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc", "websocket", "unknown"]
"example": "http"
}, },
"url": { "url": {
"type": "string", "type": "string"
"example": "https://www.example.com"
}, },
"port": { "port": {
"type": "number", "type": "number"
"example": 443
}, },
"isActive": { "isActive": {
"type": "boolean", "type": "boolean"
"example": true
}, },
"interval": { "interval": {
"type": "number", "type": "number"
"example": 60000
}, },
"status": { "status": {
"type": "string", "type": "string",
"enum": ["up", "down", "paused", "initializing", "maintenance", "breached"], "enum": ["up", "down", "paused", "initializing", "maintenance", "breached"]
"example": "up"
}, },
"statusWindowSize": { "statusWindowSize": {
"type": "number", "type": "number"
"example": 5
}, },
"statusWindowThreshold": { "statusWindowThreshold": {
"type": "number", "type": "number"
"example": 3
}, },
"ignoreTlsErrors": { "ignoreTlsErrors": {
"type": "boolean", "type": "boolean"
"example": false
}, },
"useAdvancedMatching": { "useAdvancedMatching": {
"type": "boolean", "type": "boolean"
"example": false
}, },
"jsonPath": { "jsonPath": {
"type": "string" "type": "string"
@@ -389,34 +390,28 @@
"type": "array", "type": "array",
"items": { "items": {
"type": "string" "type": "string"
}, }
"example": ["65f1c2a4d8b9e0123456789b"]
}, },
"secret": { "secret": {
"type": "string" "type": "string"
}, },
"cpuAlertThreshold": { "cpuAlertThreshold": {
"type": "number", "type": "number"
"example": 90
}, },
"memoryAlertThreshold": { "memoryAlertThreshold": {
"type": "number", "type": "number"
"example": 90
}, },
"diskAlertThreshold": { "diskAlertThreshold": {
"type": "number", "type": "number"
"example": 90
}, },
"tempAlertThreshold": { "tempAlertThreshold": {
"type": "number", "type": "number"
"example": 80
}, },
"selectedDisks": { "selectedDisks": {
"type": "array", "type": "array",
"items": { "items": {
"type": "string" "type": "string"
}, }
"example": []
}, },
"gameId": { "gameId": {
"type": "string" "type": "string"
@@ -429,36 +424,29 @@
"nullable": true "nullable": true
}, },
"geoCheckEnabled": { "geoCheckEnabled": {
"type": "boolean", "type": "boolean"
"example": false
}, },
"geoCheckLocations": { "geoCheckLocations": {
"type": "array", "type": "array",
"items": { "items": {
"type": "string", "type": "string",
"enum": ["EU", "NA", "AS", "SA", "AF", "OC"] "enum": ["EU", "NA", "AS", "SA", "AF", "OC"]
}, }
"example": []
}, },
"geoCheckInterval": { "geoCheckInterval": {
"type": "number", "type": "number"
"example": 300000
}, },
"teamId": { "teamId": {
"type": "string", "type": "string"
"example": "65f1c2a4d8b9e01234567890"
}, },
"userId": { "userId": {
"type": "string", "type": "string"
"example": "65f1c2a4d8b9e01234567891"
}, },
"createdAt": { "createdAt": {
"type": "string", "type": "string"
"example": "2026-04-01T10:00:00.000Z"
}, },
"updatedAt": { "updatedAt": {
"type": "string", "type": "string"
"example": "2026-04-15T14:30:00.000Z"
} }
}, },
"required": [ "required": [
@@ -489,6 +477,34 @@
], ],
"additionalProperties": { "additionalProperties": {
"nullable": true "nullable": true
},
"example": {
"_id": "65f1c2a4d8b9e0123456789a",
"name": "Marketing site",
"description": "Production marketing site monitored from the EU region",
"type": "http",
"url": "https://www.example.com",
"port": 443,
"isActive": true,
"interval": 60000,
"status": "up",
"statusWindowSize": 5,
"statusWindowThreshold": 3,
"ignoreTlsErrors": false,
"useAdvancedMatching": false,
"notifications": ["65f1c2a4d8b9e0123456789b"],
"cpuAlertThreshold": 90,
"memoryAlertThreshold": 90,
"diskAlertThreshold": 90,
"tempAlertThreshold": 80,
"selectedDisks": [],
"geoCheckEnabled": false,
"geoCheckLocations": [],
"geoCheckInterval": 300000,
"teamId": "65f1c2a4d8b9e01234567890",
"userId": "65f1c2a4d8b9e01234567891",
"createdAt": "2026-04-01T10:00:00.000Z",
"updatedAt": "2026-04-15T14:30:00.000Z"
} }
}, },
"NotificationChannelBody": { "NotificationChannelBody": {
+20 -16
View File
@@ -15,31 +15,35 @@ import {
editUserPasswordByIdBodyValidation, editUserPasswordByIdBodyValidation,
createUserBodyValidation, createUserBodyValidation,
editUserBodyValidation, editUserBodyValidation,
userResponseSchema,
} from "@/validation/userValidation.js"; } from "@/validation/userValidation.js";
const tags = ["auth"]; const tags = ["auth"];
const userObject = z const userExample = {
.object({ _id: "65f1c2a4d8b9e0123456789a",
_id: z.string().openapi({ example: "65f1c2a4d8b9e0123456789a" }), firstName: "Ada",
firstName: z.string().openapi({ example: "Ada" }), lastName: "Lovelace",
lastName: z.string().openapi({ example: "Lovelace" }), email: "ada@example.com",
email: z.string().openapi({ example: "ada@example.com" }), role: ["admin"],
role: z.array(z.string()).openapi({ example: ["admin"] }), teamId: "65f1c2a4d8b9e01234567890",
teamId: z.string().optional().openapi({ example: "65f1c2a4d8b9e01234567890" }), createdAt: "2026-04-01T10:00:00.000Z",
profileImage: z.string().nullable().optional(), updatedAt: "2026-04-15T14:30:00.000Z",
createdAt: z.string().openapi({ example: "2026-04-01T10:00:00.000Z" }), };
updatedAt: z.string().openapi({ example: "2026-04-15T14:30:00.000Z" }),
}) const userObject = userResponseSchema.openapi("User", { example: userExample });
.passthrough()
.openapi("User");
const authPayload = z const authPayload = z
.object({ .object({
user: userObject, user: userObject,
token: z.string().optional().openapi({ example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }), token: z.string().optional(),
}) })
.openapi("AuthPayload"); .openapi("AuthPayload", {
example: {
user: userExample,
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
},
});
registry.registerPath({ registry.registerPath({
method: "post", method: "post",
+31 -40
View File
@@ -1,8 +1,6 @@
import { z } from "zod"; import { z } from "zod";
import { registry } from "../registry.js"; import { registry } from "../registry.js";
import { bearer, json, okJson, okJsonNoData, okUnknown, standardErrors } from "../helpers.js"; import { bearer, json, okJson, okJsonNoData, okUnknown, standardErrors } from "../helpers.js";
import { GeoContinents } from "@/types/geoCheck.js";
import { MonitorMatchMethods, MonitorTypes } from "@/types/monitor.js";
import { import {
getMonitorByIdParamValidation, getMonitorByIdParamValidation,
getMonitorByIdQueryValidation, getMonitorByIdQueryValidation,
@@ -17,49 +15,42 @@ import {
importMonitorsBodyValidation, importMonitorsBodyValidation,
getHardwareDetailsByIdParamValidation, getHardwareDetailsByIdParamValidation,
getHardwareDetailsByIdQueryValidation, getHardwareDetailsByIdQueryValidation,
monitorResponseSchema,
} from "@/validation/monitorValidation.js"; } from "@/validation/monitorValidation.js";
import { updateNotificationsValidation } from "@/validation/notificationValidation.js"; import { updateNotificationsValidation } from "@/validation/notificationValidation.js";
const tags = ["monitors"]; const tags = ["monitors"];
const monitorObject = z const monitorObject = monitorResponseSchema.openapi("Monitor", {
.object({ example: {
_id: z.string().openapi({ example: "65f1c2a4d8b9e0123456789a" }), _id: "65f1c2a4d8b9e0123456789a",
name: z.string().openapi({ example: "Marketing site" }), name: "Marketing site",
description: z.string().optional().openapi({ example: "Production marketing site monitored from the EU region" }), description: "Production marketing site monitored from the EU region",
type: z.enum(MonitorTypes).openapi({ example: "http" }), type: "http",
url: z.string().openapi({ example: "https://www.example.com" }), url: "https://www.example.com",
port: z.number().optional().openapi({ example: 443 }), port: 443,
isActive: z.boolean().openapi({ example: true }), isActive: true,
interval: z.number().openapi({ example: 60000 }), interval: 60000,
status: z.enum(["up", "down", "paused", "initializing", "maintenance", "breached"]).openapi({ example: "up" }), status: "up",
statusWindowSize: z.number().openapi({ example: 5 }), statusWindowSize: 5,
statusWindowThreshold: z.number().openapi({ example: 3 }), statusWindowThreshold: 3,
ignoreTlsErrors: z.boolean().openapi({ example: false }), ignoreTlsErrors: false,
useAdvancedMatching: z.boolean().openapi({ example: false }), useAdvancedMatching: false,
jsonPath: z.string().optional(), notifications: ["65f1c2a4d8b9e0123456789b"],
expectedValue: z.string().optional(), cpuAlertThreshold: 90,
matchMethod: z.enum(MonitorMatchMethods).optional(), memoryAlertThreshold: 90,
notifications: z.array(z.string()).openapi({ example: ["65f1c2a4d8b9e0123456789b"] }), diskAlertThreshold: 90,
secret: z.string().optional(), tempAlertThreshold: 80,
cpuAlertThreshold: z.number().openapi({ example: 90 }), selectedDisks: [],
memoryAlertThreshold: z.number().openapi({ example: 90 }), geoCheckEnabled: false,
diskAlertThreshold: z.number().openapi({ example: 90 }), geoCheckLocations: [],
tempAlertThreshold: z.number().openapi({ example: 80 }), geoCheckInterval: 300000,
selectedDisks: z.array(z.string()).openapi({ example: [] }), teamId: "65f1c2a4d8b9e01234567890",
gameId: z.string().optional(), userId: "65f1c2a4d8b9e01234567891",
grpcServiceName: z.string().optional(), createdAt: "2026-04-01T10:00:00.000Z",
group: z.string().nullable().optional(), updatedAt: "2026-04-15T14:30:00.000Z",
geoCheckEnabled: z.boolean().openapi({ example: false }), },
geoCheckLocations: z.array(z.enum(GeoContinents)).openapi({ example: [] }), });
geoCheckInterval: z.number().openapi({ example: 300000 }),
teamId: z.string().openapi({ example: "65f1c2a4d8b9e01234567890" }),
userId: z.string().openapi({ example: "65f1c2a4d8b9e01234567891" }),
createdAt: z.string().openapi({ example: "2026-04-01T10:00:00.000Z" }),
updatedAt: z.string().openapi({ example: "2026-04-15T14:30:00.000Z" }),
})
.passthrough()
.openapi("Monitor");
registry.registerPath({ registry.registerPath({
method: "get", method: "get",
+41 -1
View File
@@ -1,7 +1,7 @@
import { z } from "zod"; import { z } from "zod";
import { booleanCoercion } from "./shared.js"; import { booleanCoercion } from "./shared.js";
import { GeoContinents } from "@/types/geoCheck.js"; import { GeoContinents } from "@/types/geoCheck.js";
import { MonitorMatchMethods, MonitorTypes } from "@/types/monitor.js"; import { MonitorMatchMethods, MonitorStatuses, MonitorTypes } from "@/types/monitor.js";
export const getMonitorByIdParamValidation = z.object({ export const getMonitorByIdParamValidation = z.object({
monitorId: z.string().min(1, "Monitor ID is required"), monitorId: z.string().min(1, "Monitor ID is required"),
@@ -177,3 +177,43 @@ export const getHardwareDetailsByIdParamValidation = z.object({
export const getHardwareDetailsByIdQueryValidation = z.object({ export const getHardwareDetailsByIdQueryValidation = z.object({
dateRange: z.enum(["recent", "hour", "day", "week", "month", "all"]).optional(), dateRange: z.enum(["recent", "hour", "day", "week", "month", "all"]).optional(),
}); });
// Canonical monitor shape returned by /monitors endpoints. Keep aligned with
// what the controllers actually serialize.
export const monitorResponseSchema = z
.object({
_id: z.string(),
name: z.string(),
description: z.string().optional(),
type: z.enum(MonitorTypes),
url: z.string(),
port: z.number().optional(),
isActive: z.boolean(),
interval: z.number(),
status: z.enum(MonitorStatuses),
statusWindowSize: z.number(),
statusWindowThreshold: z.number(),
ignoreTlsErrors: z.boolean(),
useAdvancedMatching: z.boolean(),
jsonPath: z.string().optional(),
expectedValue: z.string().optional(),
matchMethod: z.enum(MonitorMatchMethods).optional(),
notifications: z.array(z.string()),
secret: z.string().optional(),
cpuAlertThreshold: z.number(),
memoryAlertThreshold: z.number(),
diskAlertThreshold: z.number(),
tempAlertThreshold: z.number(),
selectedDisks: z.array(z.string()),
gameId: z.string().optional(),
grpcServiceName: z.string().optional(),
group: z.string().nullable().optional(),
geoCheckEnabled: z.boolean(),
geoCheckLocations: z.array(z.enum(GeoContinents)),
geoCheckInterval: z.number(),
teamId: z.string(),
userId: z.string(),
createdAt: z.string(),
updatedAt: z.string(),
})
.passthrough();
+16
View File
@@ -50,3 +50,19 @@ export const editUserBodyValidation = z.object({
email: lowercaseEmailValidation.optional(), email: lowercaseEmailValidation.optional(),
profilePicture: z.string().optional(), profilePicture: z.string().optional(),
}); });
// Canonical user shape returned by auth/user endpoints. Keep aligned with what
// the controllers actually serialize (password is intentionally omitted).
export const userResponseSchema = z
.object({
_id: z.string(),
firstName: z.string(),
lastName: z.string(),
email: z.string(),
role: z.array(z.string()),
teamId: z.string().optional(),
profileImage: z.string().nullable().optional(),
createdAt: z.string(),
updatedAt: z.string(),
})
.passthrough();