Fix strict TypeScript checks for client
This commit is contained in:
@@ -32,25 +32,25 @@ export function validateYonexusClientConfig(raw: unknown): YonexusClientConfig {
|
||||
const source = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const issues: string[] = [];
|
||||
|
||||
const mainHost = source.mainHost;
|
||||
if (!isNonEmptyString(mainHost)) {
|
||||
const rawMainHost = source.mainHost;
|
||||
if (!isNonEmptyString(rawMainHost)) {
|
||||
issues.push("mainHost is required");
|
||||
} else if (!isValidWsUrl(mainHost.trim())) {
|
||||
} else if (!isValidWsUrl(rawMainHost.trim())) {
|
||||
issues.push("mainHost must be a valid ws:// or wss:// URL");
|
||||
}
|
||||
|
||||
const identifier = source.identifier;
|
||||
if (!isNonEmptyString(identifier)) {
|
||||
const rawIdentifier = source.identifier;
|
||||
if (!isNonEmptyString(rawIdentifier)) {
|
||||
issues.push("identifier is required");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -58,10 +58,15 @@ export function validateYonexusClientConfig(raw: unknown): YonexusClientConfig {
|
||||
throw new YonexusClientConfigError(issues);
|
||||
}
|
||||
|
||||
const mainHost = (rawMainHost as string).trim();
|
||||
const identifier = (rawIdentifier as string).trim();
|
||||
const notifyBotToken = (rawNotifyBotToken as string).trim();
|
||||
const adminUserId = (rawAdminUserId as string).trim();
|
||||
|
||||
return {
|
||||
mainHost: mainHost.trim(),
|
||||
identifier: identifier.trim(),
|
||||
notifyBotToken: notifyBotToken.trim(),
|
||||
adminUserId: adminUserId.trim()
|
||||
mainHost,
|
||||
identifier,
|
||||
notifyBotToken,
|
||||
adminUserId
|
||||
};
|
||||
}
|
||||
|
||||
@@ -181,7 +181,8 @@ function assertClientStateShape(
|
||||
);
|
||||
}
|
||||
|
||||
if (!Number.isInteger(candidate.updatedAt) || candidate.updatedAt < 0) {
|
||||
const updatedAt = candidate.updatedAt;
|
||||
if (typeof updatedAt !== "number" || !Number.isInteger(updatedAt) || updatedAt < 0) {
|
||||
throw new YonexusClientStateCorruptionError(
|
||||
`Client state file has invalid updatedAt value: ${filePath}`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user