Fix strict TypeScript checks for server
This commit is contained in:
@@ -35,7 +35,7 @@ function normalizeOptionalString(value: unknown): string | undefined {
|
||||
}
|
||||
|
||||
function isValidPort(value: unknown): value is number {
|
||||
return Number.isInteger(value) && value >= 1 && value <= 65535;
|
||||
return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 65535;
|
||||
}
|
||||
|
||||
function isValidWsUrl(value: string): boolean {
|
||||
@@ -67,18 +67,18 @@ export function validateYonexusServerConfig(raw: unknown): YonexusServerConfig {
|
||||
issues.push("followerIdentifiers must not contain duplicates");
|
||||
}
|
||||
|
||||
const notifyBotToken = source.notifyBotToken;
|
||||
if (!isNonEmptyString(notifyBotToken)) {
|
||||
const rawNotifyBotToken = source.notifyBotToken;
|
||||
if (!isNonEmptyString(rawNotifyBotToken)) {
|
||||
issues.push("notifyBotToken is required");
|
||||
}
|
||||
|
||||
const adminUserId = source.adminUserId;
|
||||
if (!isNonEmptyString(adminUserId)) {
|
||||
const rawAdminUserId = source.adminUserId;
|
||||
if (!isNonEmptyString(rawAdminUserId)) {
|
||||
issues.push("adminUserId is required");
|
||||
}
|
||||
|
||||
const listenPort = source.listenPort;
|
||||
if (!isValidPort(listenPort)) {
|
||||
const rawListenPort = source.listenPort;
|
||||
if (!isValidPort(rawListenPort)) {
|
||||
issues.push("listenPort must be an integer between 1 and 65535");
|
||||
}
|
||||
|
||||
@@ -93,6 +93,10 @@ export function validateYonexusServerConfig(raw: unknown): YonexusServerConfig {
|
||||
throw new YonexusServerConfigError(issues);
|
||||
}
|
||||
|
||||
const notifyBotToken = rawNotifyBotToken as string;
|
||||
const adminUserId = rawAdminUserId as string;
|
||||
const listenPort = rawListenPort as number;
|
||||
|
||||
return {
|
||||
followerIdentifiers,
|
||||
notifyBotToken: notifyBotToken.trim(),
|
||||
|
||||
@@ -79,6 +79,9 @@ export interface ClientRecord {
|
||||
/** Last successful authentication timestamp (UTC unix seconds) */
|
||||
lastAuthenticatedAt?: number;
|
||||
|
||||
/** Last successful pairing timestamp (UTC unix seconds) */
|
||||
pairedAt?: number;
|
||||
|
||||
/**
|
||||
* Recent nonces used in authentication attempts.
|
||||
* This is a rolling window that may be cleared on restart.
|
||||
@@ -151,6 +154,7 @@ export interface SerializedClientRecord {
|
||||
status: ClientLivenessStatus;
|
||||
lastHeartbeatAt?: number;
|
||||
lastAuthenticatedAt?: number;
|
||||
pairedAt?: number;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
// Note: recentNonces and recentHandshakeAttempts are intentionally
|
||||
@@ -203,6 +207,7 @@ export function serializeClientRecord(record: ClientRecord): SerializedClientRec
|
||||
status: record.status,
|
||||
lastHeartbeatAt: record.lastHeartbeatAt,
|
||||
lastAuthenticatedAt: record.lastAuthenticatedAt,
|
||||
pairedAt: record.pairedAt,
|
||||
createdAt: record.createdAt,
|
||||
updatedAt: record.updatedAt
|
||||
};
|
||||
|
||||
@@ -52,6 +52,7 @@ export interface YonexusServerRuntimeOptions {
|
||||
config: YonexusServerConfig;
|
||||
store: YonexusServerStore;
|
||||
transport: ServerTransport;
|
||||
notificationService?: DiscordNotificationService;
|
||||
now?: () => number;
|
||||
sweepIntervalMs?: number;
|
||||
}
|
||||
@@ -80,10 +81,12 @@ export class YonexusServerRuntime {
|
||||
};
|
||||
this.sweepIntervalMs = options.sweepIntervalMs ?? 30_000;
|
||||
this.pairingService = createPairingService({ now: this.now });
|
||||
this.notificationService = createDiscordNotificationService({
|
||||
botToken: options.config.notifyBotToken,
|
||||
adminUserId: options.config.adminUserId
|
||||
});
|
||||
this.notificationService =
|
||||
options.notificationService ??
|
||||
createDiscordNotificationService({
|
||||
botToken: options.config.notifyBotToken,
|
||||
adminUserId: options.config.adminUserId
|
||||
});
|
||||
}
|
||||
|
||||
get state(): ServerLifecycleState {
|
||||
|
||||
Reference in New Issue
Block a user