refactor: replace custom API fetch logic with requestJson utility across multiple pages

Updated the API fetching mechanism in various components to utilize the new requestJson function for improved consistency and error handling. This change affects the alerts, dashboard, data collection, filters, gre, network map, probes, recursive routes, route optimizer, servers, settings, traffic, and uptime pages.
This commit is contained in:
Denozordec
2026-05-07 13:35:41 +07:00
parent 5f31bb47fb
commit 6d8379501c
42 changed files with 1336 additions and 631 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"name": "@mmapp/contracts",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsc -p tsconfig.json"
},
"exports": {
".": "./dist/index.js",
"./servers": "./dist/servers.js",
"./alerts": "./dist/alerts.js"
},
"dependencies": {
"zod": "^4.4.1"
}
}
+204
View File
@@ -0,0 +1,204 @@
import { z } from "zod";
export declare const alertTypeSchema: z.ZodEnum<{
"gre-tunnel": "gre-tunnel";
"bgp-peer": "bgp-peer";
"bgp-prefix": "bgp-prefix";
"gre-client": "gre-client";
server: "server";
rtt: "rtt";
loss: "loss";
traffic: "traffic";
}>;
export declare const alertSeveritySchema: z.ZodEnum<{
critical: "critical";
warning: "warning";
info: "info";
}>;
export declare const alertCooldownSchema: z.ZodEnum<{
"1\u043C": "1м";
"5\u043C": "5м";
"15\u043C": "15м";
"1\u0447": "1ч";
"4\u0447": "4ч";
"24\u0447": "24ч";
}>;
export declare const recoveryModeSchema: z.ZodEnum<{
never: "never";
always: "always";
conditional: "conditional";
}>;
export declare const combineModeSchema: z.ZodEnum<{
any: "any";
all: "all";
}>;
export declare const alertGroupSchema: z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
combineMode: z.ZodEnum<{
any: "any";
all: "all";
}>;
enabled: z.ZodBoolean;
cooldownOverride: z.ZodUnion<readonly [z.ZodEnum<{
"1\u043C": "1м";
"5\u043C": "5м";
"15\u043C": "15м";
"1\u0447": "1ч";
"4\u0447": "4ч";
"24\u0447": "24ч";
}>, z.ZodNull]>;
}, z.core.$strip>;
export declare const alertRuleSchema: z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
type: z.ZodEnum<{
"gre-tunnel": "gre-tunnel";
"bgp-peer": "bgp-peer";
"bgp-prefix": "bgp-prefix";
"gre-client": "gre-client";
server: "server";
rtt: "rtt";
loss: "loss";
traffic: "traffic";
}>;
target: z.ZodOptional<z.ZodString>;
targets: z.ZodOptional<z.ZodArray<z.ZodString>>;
groupId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
condition: z.ZodOptional<z.ZodString>;
conditions: z.ZodOptional<z.ZodArray<z.ZodString>>;
severity: z.ZodEnum<{
critical: "critical";
warning: "warning";
info: "info";
}>;
enabled: z.ZodBoolean;
cooldown: z.ZodEnum<{
"1\u043C": "1м";
"5\u043C": "5м";
"15\u043C": "15м";
"1\u0447": "1ч";
"4\u0447": "4ч";
"24\u0447": "24ч";
}>;
confirmStabilitySec: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
recoveryMode: z.ZodOptional<z.ZodEnum<{
never: "never";
always: "always";
conditional: "conditional";
}>>;
recoveryStabilitySec: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
chatId: z.ZodString;
}, z.core.$strip>;
export declare const putRulesSchema: z.ZodObject<{
rules: z.ZodArray<z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
type: z.ZodEnum<{
"gre-tunnel": "gre-tunnel";
"bgp-peer": "bgp-peer";
"bgp-prefix": "bgp-prefix";
"gre-client": "gre-client";
server: "server";
rtt: "rtt";
loss: "loss";
traffic: "traffic";
}>;
target: z.ZodOptional<z.ZodString>;
targets: z.ZodOptional<z.ZodArray<z.ZodString>>;
groupId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
condition: z.ZodOptional<z.ZodString>;
conditions: z.ZodOptional<z.ZodArray<z.ZodString>>;
severity: z.ZodEnum<{
critical: "critical";
warning: "warning";
info: "info";
}>;
enabled: z.ZodBoolean;
cooldown: z.ZodEnum<{
"1\u043C": "1м";
"5\u043C": "5м";
"15\u043C": "15м";
"1\u0447": "1ч";
"4\u0447": "4ч";
"24\u0447": "24ч";
}>;
confirmStabilitySec: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
recoveryMode: z.ZodOptional<z.ZodEnum<{
never: "never";
always: "always";
conditional: "conditional";
}>>;
recoveryStabilitySec: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
chatId: z.ZodString;
}, z.core.$strip>>;
groups: z.ZodOptional<z.ZodArray<z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
combineMode: z.ZodEnum<{
any: "any";
all: "all";
}>;
enabled: z.ZodBoolean;
cooldownOverride: z.ZodUnion<readonly [z.ZodEnum<{
"1\u043C": "1м";
"5\u043C": "5м";
"15\u043C": "15м";
"1\u0447": "1ч";
"4\u0447": "4ч";
"24\u0447": "24ч";
}>, z.ZodNull]>;
}, z.core.$strip>>>;
}, z.core.$strip>;
export declare const putTelegramSchema: z.ZodObject<{
token: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
chatId: z.ZodOptional<z.ZodString>;
messageThreadId: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
}, z.core.$strip>;
export declare const rulePreviewTelegramSchema: z.ZodObject<{
name: z.ZodString;
targets: z.ZodArray<z.ZodString>;
conditionLine: z.ZodString;
severity: z.ZodEnum<{
critical: "critical";
warning: "warning";
info: "info";
}>;
cooldown: z.ZodEnum<{
"1\u043C": "1м";
"5\u043C": "5м";
"15\u043C": "15м";
"1\u0447": "1ч";
"4\u0447": "4ч";
"24\u0447": "24ч";
}>;
}, z.core.$strip>;
export declare const testTelegramSchema: z.ZodObject<{
token: z.ZodOptional<z.ZodString>;
chatId: z.ZodOptional<z.ZodString>;
messageThreadId: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
rulePreview: z.ZodOptional<z.ZodObject<{
name: z.ZodString;
targets: z.ZodArray<z.ZodString>;
conditionLine: z.ZodString;
severity: z.ZodEnum<{
critical: "critical";
warning: "warning";
info: "info";
}>;
cooldown: z.ZodEnum<{
"1\u043C": "1м";
"5\u043C": "5м";
"15\u043C": "15м";
"1\u0447": "1ч";
"4\u0447": "4ч";
"24\u0447": "24ч";
}>;
}, z.core.$strip>>;
}, z.core.$strip>;
export type AlertGroup = z.infer<typeof alertGroupSchema>;
export type AlertRule = z.infer<typeof alertRuleSchema>;
export type PutRulesBody = z.infer<typeof putRulesSchema>;
export type PutTelegramBody = z.infer<typeof putTelegramSchema>;
export type RulePreviewTelegram = z.infer<typeof rulePreviewTelegramSchema>;
export type TestTelegramBody = z.infer<typeof testTelegramSchema>;
//# sourceMappingURL=alerts.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"alerts.d.ts","sourceRoot":"","sources":["alerts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,eAAe;;;;;;;;;EAS1B,CAAA;AACF,eAAO,MAAM,mBAAmB;;;;EAA0C,CAAA;AAC1E,eAAO,MAAM,mBAAmB;;;;;;;EAAiD,CAAA;AACjF,eAAO,MAAM,kBAAkB;;;;EAA6C,CAAA;AAC5E,eAAO,MAAM,iBAAiB;;;EAAyB,CAAA;AAEvD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;iBAM3B,CAAA;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyBxB,CAAA;AAEJ,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAGzB,CAAA;AAEF,eAAO,MAAM,iBAAiB;;;;iBAI5B,CAAA;AAEF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;iBAMpC,CAAA;AAEF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;iBAK7B,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AACzD,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AACvD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA;AACzD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAC/D,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAA;AAC3E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA"}
+71
View File
@@ -0,0 +1,71 @@
import { z } from "zod";
export const alertTypeSchema = z.enum([
"gre-tunnel",
"bgp-peer",
"bgp-prefix",
"gre-client",
"server",
"rtt",
"loss",
"traffic",
]);
export const alertSeveritySchema = z.enum(["critical", "warning", "info"]);
export const alertCooldownSchema = z.enum(["1м", "5м", "15м", "1ч", "4ч", "24ч"]);
export const recoveryModeSchema = z.enum(["always", "never", "conditional"]);
export const combineModeSchema = z.enum(["any", "all"]);
export const alertGroupSchema = z.object({
id: z.string().min(1),
name: z.string().min(1),
combineMode: combineModeSchema,
enabled: z.boolean(),
cooldownOverride: z.union([alertCooldownSchema, z.null()]),
});
export const alertRuleSchema = z
.object({
id: z.string().min(1),
name: z.string().min(1),
type: alertTypeSchema,
target: z.string().optional(),
targets: z.array(z.string().min(1)).optional(),
groupId: z.string().nullable().optional(),
condition: z.string().optional(),
conditions: z.array(z.string().min(1)).optional(),
severity: alertSeveritySchema,
enabled: z.boolean(),
cooldown: alertCooldownSchema,
confirmStabilitySec: z.union([z.number().int().min(0).max(86400), z.null()]).optional(),
recoveryMode: recoveryModeSchema.optional(),
recoveryStabilitySec: z.union([z.number().int().min(0).max(86400), z.null()]).optional(),
chatId: z.string(),
})
.refine((r) => (r.targets != null && r.targets.length > 0) || Boolean(r.target?.trim()), {
message: "Нужен хотя бы один объект: targets или target",
path: ["targets"],
})
.refine((r) => (r.conditions != null && r.conditions.length > 0) || Boolean(r.condition?.trim()), {
message: "Нужно хотя бы одно условие: conditions или condition",
path: ["conditions"],
});
export const putRulesSchema = z.object({
rules: z.array(alertRuleSchema),
groups: z.array(alertGroupSchema).optional(),
});
export const putTelegramSchema = z.object({
token: z.union([z.string(), z.null()]).optional(),
chatId: z.string().optional(),
messageThreadId: z.union([z.number().int().positive(), z.null()]).optional(),
});
export const rulePreviewTelegramSchema = z.object({
name: z.string().min(1),
targets: z.array(z.string().min(1)).min(1),
conditionLine: z.string().min(1),
severity: alertSeveritySchema,
cooldown: alertCooldownSchema,
});
export const testTelegramSchema = z.object({
token: z.string().optional(),
chatId: z.string().optional(),
messageThreadId: z.coerce.number().int().positive().optional(),
rulePreview: rulePreviewTelegramSchema.optional(),
});
//# sourceMappingURL=alerts.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"alerts.js","sourceRoot":"","sources":["alerts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC;IACpC,YAAY;IACZ,UAAU;IACV,YAAY;IACZ,YAAY;IACZ,QAAQ;IACR,KAAK;IACL,MAAM;IACN,SAAS;CACV,CAAC,CAAA;AACF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAA;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;AACjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,C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;IAC7B,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC9D,WAAW,EAAE,yBAAyB,CAAC,QAAQ,EAAE;CAClD,CAAC,CAAA"}
+84
View File
@@ -0,0 +1,84 @@
import { z } from "zod"
export const alertTypeSchema = z.enum([
"gre-tunnel",
"bgp-peer",
"bgp-prefix",
"gre-client",
"server",
"rtt",
"loss",
"traffic",
])
export const alertSeveritySchema = z.enum(["critical", "warning", "info"])
export const alertCooldownSchema = z.enum(["1м", "5м", "15м", "1ч", "4ч", "24ч"])
export const recoveryModeSchema = z.enum(["always", "never", "conditional"])
export const combineModeSchema = z.enum(["any", "all"])
export const alertGroupSchema = z.object({
id: z.string().min(1),
name: z.string().min(1),
combineMode: combineModeSchema,
enabled: z.boolean(),
cooldownOverride: z.union([alertCooldownSchema, z.null()]),
})
export const alertRuleSchema = z
.object({
id: z.string().min(1),
name: z.string().min(1),
type: alertTypeSchema,
target: z.string().optional(),
targets: z.array(z.string().min(1)).optional(),
groupId: z.string().nullable().optional(),
condition: z.string().optional(),
conditions: z.array(z.string().min(1)).optional(),
severity: alertSeveritySchema,
enabled: z.boolean(),
cooldown: alertCooldownSchema,
confirmStabilitySec: z.union([z.number().int().min(0).max(86400), z.null()]).optional(),
recoveryMode: recoveryModeSchema.optional(),
recoveryStabilitySec: z.union([z.number().int().min(0).max(86400), z.null()]).optional(),
chatId: z.string(),
})
.refine((r) => (r.targets != null && r.targets.length > 0) || Boolean(r.target?.trim()), {
message: "Нужен хотя бы один объект: targets или target",
path: ["targets"],
})
.refine((r) => (r.conditions != null && r.conditions.length > 0) || Boolean(r.condition?.trim()), {
message: "Нужно хотя бы одно условие: conditions или condition",
path: ["conditions"],
})
export const putRulesSchema = z.object({
rules: z.array(alertRuleSchema),
groups: z.array(alertGroupSchema).optional(),
})
export const putTelegramSchema = z.object({
token: z.union([z.string(), z.null()]).optional(),
chatId: z.string().optional(),
messageThreadId: z.union([z.number().int().positive(), z.null()]).optional(),
})
export const rulePreviewTelegramSchema = z.object({
name: z.string().min(1),
targets: z.array(z.string().min(1)).min(1),
conditionLine: z.string().min(1),
severity: alertSeveritySchema,
cooldown: alertCooldownSchema,
})
export const testTelegramSchema = z.object({
token: z.string().optional(),
chatId: z.string().optional(),
messageThreadId: z.coerce.number().int().positive().optional(),
rulePreview: rulePreviewTelegramSchema.optional(),
})
export type AlertGroup = z.infer<typeof alertGroupSchema>
export type AlertRule = z.infer<typeof alertRuleSchema>
export type PutRulesBody = z.infer<typeof putRulesSchema>
export type PutTelegramBody = z.infer<typeof putTelegramSchema>
export type RulePreviewTelegram = z.infer<typeof rulePreviewTelegramSchema>
export type TestTelegramBody = z.infer<typeof testTelegramSchema>
+2
View File
@@ -0,0 +1,2 @@
export * from "./servers.js"
export * from "./alerts.js"
+228
View File
@@ -0,0 +1,228 @@
import { z } from "zod";
export declare const serverTypeSchema: z.ZodEnum<{
"jump-host": "jump-host";
"exit-node": "exit-node";
"home-router": "home-router";
}>;
export declare const serverStatusSchema: z.ZodEnum<{
online: "online";
offline: "offline";
}>;
export declare const wanUplinkSchema: z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
isp: z.ZodString;
iface: z.ZodString;
ip: z.ZodString;
maxDl: z.ZodNumber;
maxUl: z.ZodNumber;
}, z.core.$strip>;
export declare const serverCreateSchema: z.ZodObject<{
host: z.ZodString;
port: z.ZodDefault<z.ZodNumber>;
username: z.ZodDefault<z.ZodString>;
password: z.ZodDefault<z.ZodString>;
useSsl: z.ZodDefault<z.ZodBoolean>;
verifySsl: z.ZodDefault<z.ZodBoolean>;
name: z.ZodDefault<z.ZodString>;
type: z.ZodDefault<z.ZodEnum<{
"jump-host": "jump-host";
"exit-node": "exit-node";
"home-router": "home-router";
}>>;
site: z.ZodDefault<z.ZodString>;
country: z.ZodDefault<z.ZodString>;
asn: z.ZodDefault<z.ZodString>;
comment: z.ZodDefault<z.ZodString>;
enabled: z.ZodDefault<z.ZodBoolean>;
lanSubnet: z.ZodDefault<z.ZodString>;
wanUplinks: z.ZodDefault<z.ZodArray<z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
isp: z.ZodString;
iface: z.ZodString;
ip: z.ZodString;
maxDl: z.ZodNumber;
maxUl: z.ZodNumber;
}, z.core.$strip>>>;
}, z.core.$strip>;
export declare const serverUpdateSchema: z.ZodObject<{
type: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
"jump-host": "jump-host";
"exit-node": "exit-node";
"home-router": "home-router";
}>>>;
name: z.ZodOptional<z.ZodDefault<z.ZodString>>;
port: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
username: z.ZodOptional<z.ZodDefault<z.ZodString>>;
password: z.ZodOptional<z.ZodDefault<z.ZodString>>;
useSsl: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
verifySsl: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
site: z.ZodOptional<z.ZodDefault<z.ZodString>>;
country: z.ZodOptional<z.ZodDefault<z.ZodString>>;
asn: z.ZodOptional<z.ZodDefault<z.ZodString>>;
comment: z.ZodOptional<z.ZodDefault<z.ZodString>>;
enabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
lanSubnet: z.ZodOptional<z.ZodDefault<z.ZodString>>;
wanUplinks: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
isp: z.ZodString;
iface: z.ZodString;
ip: z.ZodString;
maxDl: z.ZodNumber;
maxUl: z.ZodNumber;
}, z.core.$strip>>>>;
host: z.ZodOptional<z.ZodString>;
}, z.core.$strip>;
export declare const serverIdParamSchema: z.ZodObject<{
id: z.ZodCoercedNumber<unknown>;
}, z.core.$strip>;
export declare const snapshotsQuerySchema: z.ZodObject<{
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
}, z.core.$strip>;
export declare const testConnectionSchema: z.ZodObject<{
host: z.ZodString;
port: z.ZodDefault<z.ZodNumber>;
useSsl: z.ZodDefault<z.ZodBoolean>;
verifySsl: z.ZodDefault<z.ZodBoolean>;
apiPath: z.ZodDefault<z.ZodString>;
username: z.ZodDefault<z.ZodString>;
password: z.ZodDefault<z.ZodString>;
}, z.core.$strip>;
export declare const serverReadSchema: z.ZodObject<{
id: z.ZodNumber;
name: z.ZodString;
host: z.ZodString;
port: z.ZodNumber;
useSsl: z.ZodBoolean;
verifySsl: z.ZodBoolean;
username: z.ZodString;
password: z.ZodString;
type: z.ZodEnum<{
"jump-host": "jump-host";
"exit-node": "exit-node";
"home-router": "home-router";
}>;
site: z.ZodString;
country: z.ZodString;
asn: z.ZodString;
comment: z.ZodString;
enabled: z.ZodBoolean;
lanSubnet: z.ZodString;
wanUplinks: z.ZodArray<z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
isp: z.ZodString;
iface: z.ZodString;
ip: z.ZodString;
maxDl: z.ZodNumber;
maxUl: z.ZodNumber;
}, z.core.$strip>>;
createdAt: z.ZodString;
updatedAt: z.ZodString;
status: z.ZodUnion<readonly [z.ZodEnum<{
online: "online";
offline: "offline";
}>, z.ZodNull]>;
latency: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
os: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
model: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
uptime: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
cpuLoad: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
freeMemory: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
totalMemory: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
identityName: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
sessions: z.ZodNumber;
polledAt: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
}, z.core.$strip>;
export declare const snapshotReadSchema: z.ZodObject<{
id: z.ZodNumber;
serverId: z.ZodNumber;
polledAt: z.ZodString;
status: z.ZodEnum<{
online: "online";
offline: "offline";
}>;
latencyMs: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
rosVersion: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
boardName: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
uptime: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
cpuLoad: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
freeMemory: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
totalMemory: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
identityName: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
}, z.core.$strip>;
export declare const serverListSchema: z.ZodArray<z.ZodObject<{
id: z.ZodNumber;
name: z.ZodString;
host: z.ZodString;
port: z.ZodNumber;
useSsl: z.ZodBoolean;
verifySsl: z.ZodBoolean;
username: z.ZodString;
password: z.ZodString;
type: z.ZodEnum<{
"jump-host": "jump-host";
"exit-node": "exit-node";
"home-router": "home-router";
}>;
site: z.ZodString;
country: z.ZodString;
asn: z.ZodString;
comment: z.ZodString;
enabled: z.ZodBoolean;
lanSubnet: z.ZodString;
wanUplinks: z.ZodArray<z.ZodObject<{
id: z.ZodString;
name: z.ZodString;
isp: z.ZodString;
iface: z.ZodString;
ip: z.ZodString;
maxDl: z.ZodNumber;
maxUl: z.ZodNumber;
}, z.core.$strip>>;
createdAt: z.ZodString;
updatedAt: z.ZodString;
status: z.ZodUnion<readonly [z.ZodEnum<{
online: "online";
offline: "offline";
}>, z.ZodNull]>;
latency: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
os: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
model: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
uptime: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
cpuLoad: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
freeMemory: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
totalMemory: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
identityName: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
sessions: z.ZodNumber;
polledAt: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
}, z.core.$strip>>;
export declare const snapshotListSchema: z.ZodArray<z.ZodObject<{
id: z.ZodNumber;
serverId: z.ZodNumber;
polledAt: z.ZodString;
status: z.ZodEnum<{
online: "online";
offline: "offline";
}>;
latencyMs: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
rosVersion: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
boardName: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
uptime: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
cpuLoad: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
freeMemory: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
totalMemory: z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>;
identityName: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
}, z.core.$strip>>;
export type ServerType = z.infer<typeof serverTypeSchema>;
export type WanUplink = z.infer<typeof wanUplinkSchema>;
export type ServerCreate = z.infer<typeof serverCreateSchema>;
export type ServerUpdate = z.infer<typeof serverUpdateSchema>;
export type ServerRead = z.infer<typeof serverReadSchema>;
export type SnapshotRead = z.infer<typeof snapshotReadSchema>;
export type ServerIdParam = z.infer<typeof serverIdParamSchema>;
export type SnapshotsQuery = z.infer<typeof snapshotsQuerySchema>;
export type TestConnectionRequest = z.infer<typeof testConnectionSchema>;
//# sourceMappingURL=servers.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"servers.d.ts","sourceRoot":"","sources":["servers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,gBAAgB;;;;EAAoD,CAAA;AACjF,eAAO,MAAM,kBAAkB;;;EAAgC,CAAA;AAE/D,eAAO,MAAM,eAAe;;;;;;;;iBAQ1B,CAAA;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CAAA;AACjE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
+95
View File
@@ -0,0 +1,95 @@
import { z } from "zod";
export const serverTypeSchema = z.enum(["jump-host", "exit-node", "home-router"]);
export const serverStatusSchema = z.enum(["online", "offline"]);
export const wanUplinkSchema = z.object({
id: z.string(),
name: z.string(),
isp: z.string(),
iface: z.string(),
ip: z.string(),
maxDl: z.number(),
maxUl: z.number(),
});
export const serverCreateSchema = z.object({
host: z.string().min(1, "Host is required"),
port: z.number().int().positive().default(443),
username: z.string().default("admin"),
password: z.string().default(""),
useSsl: z.boolean().default(true),
verifySsl: z.boolean().default(false),
name: z.string().default(""),
type: serverTypeSchema.default("home-router"),
site: z.string().default(""),
country: z.string().default(""),
asn: z.string().default(""),
comment: z.string().default(""),
enabled: z.boolean().default(true),
lanSubnet: z.string().default(""),
wanUplinks: z.array(wanUplinkSchema).default([]),
});
export const serverUpdateSchema = serverCreateSchema.partial().omit({ host: true }).extend({
host: z.string().min(1).optional(),
});
export const serverIdParamSchema = z.object({
id: z.coerce.number().int().positive(),
});
export const snapshotsQuerySchema = z.object({
limit: z.coerce.number().int().positive().max(500).default(50),
});
export const testConnectionSchema = z.object({
host: z.string().min(1),
port: z.number().int().positive().default(443),
useSsl: z.boolean().default(true),
verifySsl: z.boolean().default(false),
apiPath: z.string().default("/rest"),
username: z.string().default("admin"),
password: z.string().default(""),
});
export const serverReadSchema = z.object({
id: z.number().int(),
name: z.string(),
host: z.string(),
port: z.number().int(),
useSsl: z.boolean(),
verifySsl: z.boolean(),
username: z.string(),
password: z.string(),
type: serverTypeSchema,
site: z.string(),
country: z.string(),
asn: z.string(),
comment: z.string(),
enabled: z.boolean(),
lanSubnet: z.string(),
wanUplinks: z.array(wanUplinkSchema),
createdAt: z.string(),
updatedAt: z.string(),
status: z.union([serverStatusSchema, z.null()]),
latency: z.union([z.number(), z.null()]),
os: z.union([z.string(), z.null()]),
model: z.union([z.string(), z.null()]),
uptime: z.union([z.string(), z.null()]),
cpuLoad: z.union([z.number(), z.null()]),
freeMemory: z.union([z.number(), z.null()]),
totalMemory: z.union([z.number(), z.null()]),
identityName: z.union([z.string(), z.null()]),
sessions: z.number().int(),
polledAt: z.union([z.string(), z.null()]),
});
export const snapshotReadSchema = z.object({
id: z.number().int(),
serverId: z.number().int(),
polledAt: z.string(),
status: serverStatusSchema,
latencyMs: z.union([z.number(), z.null()]),
rosVersion: z.union([z.string(), z.null()]),
boardName: z.union([z.string(), z.null()]),
uptime: z.union([z.string(), z.null()]),
cpuLoad: z.union([z.number().int(), z.null()]),
freeMemory: z.union([z.number().int(), z.null()]),
totalMemory: z.union([z.number().int(), z.null()]),
identityName: z.union([z.string(), z.null()]),
});
export const serverListSchema = z.array(serverReadSchema);
export const snapshotListSchema = z.array(snapshotReadSchema);
//# sourceMappingURL=servers.js.map
File diff suppressed because one or more lines are too long
+114
View File
@@ -0,0 +1,114 @@
import { z } from "zod"
export const serverTypeSchema = z.enum(["jump-host", "exit-node", "home-router"])
export const serverStatusSchema = z.enum(["online", "offline"])
export const wanUplinkSchema = z.object({
id: z.string(),
name: z.string(),
isp: z.string(),
iface: z.string(),
ip: z.string(),
maxDl: z.number(),
maxUl: z.number(),
})
export const serverCreateSchema = z.object({
host: z.string().min(1, "Host is required"),
port: z.number().int().positive().default(443),
username: z.string().default("admin"),
password: z.string().default(""),
useSsl: z.boolean().default(true),
verifySsl: z.boolean().default(false),
name: z.string().default(""),
type: serverTypeSchema.default("home-router"),
site: z.string().default(""),
country: z.string().default(""),
asn: z.string().default(""),
comment: z.string().default(""),
enabled: z.boolean().default(true),
lanSubnet: z.string().default(""),
wanUplinks: z.array(wanUplinkSchema).default([]),
})
export const serverUpdateSchema = serverCreateSchema.partial().omit({ host: true }).extend({
host: z.string().min(1).optional(),
})
export const serverIdParamSchema = z.object({
id: z.coerce.number().int().positive(),
})
export const snapshotsQuerySchema = z.object({
limit: z.coerce.number().int().positive().max(500).default(50),
})
export const testConnectionSchema = z.object({
host: z.string().min(1),
port: z.number().int().positive().default(443),
useSsl: z.boolean().default(true),
verifySsl: z.boolean().default(false),
apiPath: z.string().default("/rest"),
username: z.string().default("admin"),
password: z.string().default(""),
})
export const serverReadSchema = z.object({
id: z.number().int(),
name: z.string(),
host: z.string(),
port: z.number().int(),
useSsl: z.boolean(),
verifySsl: z.boolean(),
username: z.string(),
password: z.string(),
type: serverTypeSchema,
site: z.string(),
country: z.string(),
asn: z.string(),
comment: z.string(),
enabled: z.boolean(),
lanSubnet: z.string(),
wanUplinks: z.array(wanUplinkSchema),
createdAt: z.string(),
updatedAt: z.string(),
status: z.union([serverStatusSchema, z.null()]),
latency: z.union([z.number(), z.null()]),
os: z.union([z.string(), z.null()]),
model: z.union([z.string(), z.null()]),
uptime: z.union([z.string(), z.null()]),
cpuLoad: z.union([z.number(), z.null()]),
freeMemory: z.union([z.number(), z.null()]),
totalMemory: z.union([z.number(), z.null()]),
identityName: z.union([z.string(), z.null()]),
sessions: z.number().int(),
polledAt: z.union([z.string(), z.null()]),
})
export const snapshotReadSchema = z.object({
id: z.number().int(),
serverId: z.number().int(),
polledAt: z.string(),
status: serverStatusSchema,
latencyMs: z.union([z.number(), z.null()]),
rosVersion: z.union([z.string(), z.null()]),
boardName: z.union([z.string(), z.null()]),
uptime: z.union([z.string(), z.null()]),
cpuLoad: z.union([z.number().int(), z.null()]),
freeMemory: z.union([z.number().int(), z.null()]),
totalMemory: z.union([z.number().int(), z.null()]),
identityName: z.union([z.string(), z.null()]),
})
export const serverListSchema = z.array(serverReadSchema)
export const snapshotListSchema = z.array(snapshotReadSchema)
export type ServerType = z.infer<typeof serverTypeSchema>
export type WanUplink = z.infer<typeof wanUplinkSchema>
export type ServerCreate = z.infer<typeof serverCreateSchema>
export type ServerUpdate = z.infer<typeof serverUpdateSchema>
export type ServerRead = z.infer<typeof serverReadSchema>
export type SnapshotRead = z.infer<typeof snapshotReadSchema>
export type ServerIdParam = z.infer<typeof serverIdParamSchema>
export type SnapshotsQuery = z.infer<typeof snapshotsQuerySchema>
export type TestConnectionRequest = z.infer<typeof testConnectionSchema>
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "dist",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}