update typing to node v24 from v20
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.6.0",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ interface RunningProcess {
|
|||||||
graceSec: number;
|
graceSec: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ChildProcessWithEvents = ChildProcess & {
|
||||||
|
on(event: "error", listener: (err: Error) => void): ChildProcess;
|
||||||
|
on(
|
||||||
|
event: "close",
|
||||||
|
listener: (code: number | null, signal: NodeJS.Signals | null) => void,
|
||||||
|
): ChildProcess;
|
||||||
|
};
|
||||||
|
|
||||||
export const runningProcesses = new Map<string, RunningProcess>();
|
export const runningProcesses = new Map<string, RunningProcess>();
|
||||||
export const MAX_CAPTURE_BYTES = 4 * 1024 * 1024;
|
export const MAX_CAPTURE_BYTES = 4 * 1024 * 1024;
|
||||||
export const MAX_EXCERPT_BYTES = 32 * 1024;
|
export const MAX_EXCERPT_BYTES = 32 * 1024;
|
||||||
@@ -217,7 +225,7 @@ export async function runChildProcess(
|
|||||||
env: mergedEnv,
|
env: mergedEnv,
|
||||||
shell: false,
|
shell: false,
|
||||||
stdio: [opts.stdin != null ? "pipe" : "ignore", "pipe", "pipe"],
|
stdio: [opts.stdin != null ? "pipe" : "ignore", "pipe", "pipe"],
|
||||||
});
|
}) as ChildProcessWithEvents;
|
||||||
|
|
||||||
if (opts.stdin != null && child.stdin) {
|
if (opts.stdin != null && child.stdin) {
|
||||||
child.stdin.write(opts.stdin);
|
child.stdin.write(opts.stdin);
|
||||||
@@ -244,7 +252,7 @@ export async function runChildProcess(
|
|||||||
}, opts.timeoutSec * 1000)
|
}, opts.timeoutSec * 1000)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
child.stdout?.on("data", (chunk) => {
|
child.stdout?.on("data", (chunk: unknown) => {
|
||||||
const text = String(chunk);
|
const text = String(chunk);
|
||||||
stdout = appendWithCap(stdout, text);
|
stdout = appendWithCap(stdout, text);
|
||||||
logChain = logChain
|
logChain = logChain
|
||||||
@@ -252,7 +260,7 @@ export async function runChildProcess(
|
|||||||
.catch((err) => onLogError(err, runId, "failed to append stdout log chunk"));
|
.catch((err) => onLogError(err, runId, "failed to append stdout log chunk"));
|
||||||
});
|
});
|
||||||
|
|
||||||
child.stderr?.on("data", (chunk) => {
|
child.stderr?.on("data", (chunk: unknown) => {
|
||||||
const text = String(chunk);
|
const text = String(chunk);
|
||||||
stderr = appendWithCap(stderr, text);
|
stderr = appendWithCap(stderr, text);
|
||||||
logChain = logChain
|
logChain = logChain
|
||||||
@@ -260,7 +268,7 @@ export async function runChildProcess(
|
|||||||
.catch((err) => onLogError(err, runId, "failed to append stderr log chunk"));
|
.catch((err) => onLogError(err, runId, "failed to append stderr log chunk"));
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on("error", (err) => {
|
child.on("error", (err: Error) => {
|
||||||
if (timeout) clearTimeout(timeout);
|
if (timeout) clearTimeout(timeout);
|
||||||
runningProcesses.delete(runId);
|
runningProcesses.delete(runId);
|
||||||
const errno = (err as NodeJS.ErrnoException).code;
|
const errno = (err as NodeJS.ErrnoException).code;
|
||||||
@@ -272,7 +280,7 @@ export async function runChildProcess(
|
|||||||
reject(new Error(msg));
|
reject(new Error(msg));
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on("close", (code, signal) => {
|
child.on("close", (code: number | null, signal: NodeJS.Signals | null) => {
|
||||||
if (timeout) clearTimeout(timeout);
|
if (timeout) clearTimeout(timeout);
|
||||||
runningProcesses.delete(runId);
|
runningProcesses.delete(runId);
|
||||||
void logChain.finally(() => {
|
void logChain.finally(() => {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
"picocolors": "^1.1.1"
|
"picocolors": "^1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.6.0",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
"picocolors": "^1.1.1"
|
"picocolors": "^1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.6.0",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
"picocolors": "^1.1.1"
|
"picocolors": "^1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.6.0",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
"postgres": "^3.4.5"
|
"postgres": "^3.4.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.6.0",
|
||||||
"drizzle-kit": "^0.31.9",
|
"drizzle-kit": "^0.31.9",
|
||||||
"tsx": "^4.19.2",
|
"tsx": "^4.19.2",
|
||||||
"typescript": "^5.7.3",
|
"typescript": "^5.7.3",
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
"@types/express-serve-static-core": "^5.0.0",
|
"@types/express-serve-static-core": "^5.0.0",
|
||||||
"@types/multer": "^2.0.0",
|
"@types/multer": "^2.0.0",
|
||||||
"@types/supertest": "^6.0.2",
|
"@types/supertest": "^6.0.2",
|
||||||
|
"@types/ws": "^8.18.1",
|
||||||
"supertest": "^7.0.0",
|
"supertest": "^7.0.0",
|
||||||
"tsx": "^4.19.2",
|
"tsx": "^4.19.2",
|
||||||
"typescript": "^5.7.3",
|
"typescript": "^5.7.3",
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ const app = await createApp(db as any, {
|
|||||||
betterAuthHandler,
|
betterAuthHandler,
|
||||||
resolveSession,
|
resolveSession,
|
||||||
});
|
});
|
||||||
const server = createServer(app);
|
const server = createServer(app as unknown as Parameters<typeof createServer>[0]);
|
||||||
const listenPort = await detectPort(config.port);
|
const listenPort = await detectPort(config.port);
|
||||||
|
|
||||||
if (listenPort !== config.port) {
|
if (listenPort !== config.port) {
|
||||||
|
|||||||
@@ -1,15 +1,45 @@
|
|||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
import type { IncomingMessage, Server as HttpServer } from "node:http";
|
import type { IncomingMessage, Server as HttpServer } from "node:http";
|
||||||
|
import { createRequire } from "node:module";
|
||||||
import type { Duplex } from "node:stream";
|
import type { Duplex } from "node:stream";
|
||||||
import { and, eq, isNull } from "drizzle-orm";
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
import type { Db } from "@paperclipai/db";
|
import type { Db } from "@paperclipai/db";
|
||||||
import { agentApiKeys, companyMemberships, instanceUserRoles } from "@paperclipai/db";
|
import { agentApiKeys, companyMemberships, instanceUserRoles } from "@paperclipai/db";
|
||||||
import type { DeploymentMode } from "@paperclipai/shared";
|
import type { DeploymentMode } from "@paperclipai/shared";
|
||||||
import { WebSocket, WebSocketServer } from "ws";
|
|
||||||
import type { BetterAuthSessionResult } from "../auth/better-auth.js";
|
import type { BetterAuthSessionResult } from "../auth/better-auth.js";
|
||||||
import { logger } from "../middleware/logger.js";
|
import { logger } from "../middleware/logger.js";
|
||||||
import { subscribeCompanyLiveEvents } from "../services/live-events.js";
|
import { subscribeCompanyLiveEvents } from "../services/live-events.js";
|
||||||
|
|
||||||
|
interface WsSocket {
|
||||||
|
readyState: number;
|
||||||
|
ping(): void;
|
||||||
|
send(data: string): void;
|
||||||
|
terminate(): void;
|
||||||
|
close(code?: number, reason?: string): void;
|
||||||
|
on(event: "pong", listener: () => void): void;
|
||||||
|
on(event: "close", listener: () => void): void;
|
||||||
|
on(event: "error", listener: (err: Error) => void): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WsServer {
|
||||||
|
clients: Set<WsSocket>;
|
||||||
|
on(event: "connection", listener: (socket: WsSocket, req: IncomingMessage) => void): void;
|
||||||
|
on(event: "close", listener: () => void): void;
|
||||||
|
handleUpgrade(
|
||||||
|
req: IncomingMessage,
|
||||||
|
socket: Duplex,
|
||||||
|
head: Buffer,
|
||||||
|
callback: (ws: WsSocket) => void,
|
||||||
|
): void;
|
||||||
|
emit(event: "connection", ws: WsSocket, req: IncomingMessage): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
const { WebSocket, WebSocketServer } = require("ws") as {
|
||||||
|
WebSocket: { OPEN: number };
|
||||||
|
WebSocketServer: new (opts: { noServer: boolean }) => WsServer;
|
||||||
|
};
|
||||||
|
|
||||||
interface UpgradeContext {
|
interface UpgradeContext {
|
||||||
companyId: string;
|
companyId: string;
|
||||||
actorType: "board" | "agent";
|
actorType: "board" | "agent";
|
||||||
@@ -154,8 +184,8 @@ export function setupLiveEventsWebSocketServer(
|
|||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const wss = new WebSocketServer({ noServer: true });
|
const wss = new WebSocketServer({ noServer: true });
|
||||||
const cleanupByClient = new Map<WebSocket, () => void>();
|
const cleanupByClient = new Map<WsSocket, () => void>();
|
||||||
const aliveByClient = new Map<WebSocket, boolean>();
|
const aliveByClient = new Map<WsSocket, boolean>();
|
||||||
|
|
||||||
const pingInterval = setInterval(() => {
|
const pingInterval = setInterval(() => {
|
||||||
for (const socket of wss.clients) {
|
for (const socket of wss.clients) {
|
||||||
@@ -168,7 +198,7 @@ export function setupLiveEventsWebSocketServer(
|
|||||||
}
|
}
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
wss.on("connection", (socket, req) => {
|
wss.on("connection", (socket: WsSocket, req: IncomingMessage) => {
|
||||||
const context = (req as IncomingMessageWithContext).paperclipUpgradeContext;
|
const context = (req as IncomingMessageWithContext).paperclipUpgradeContext;
|
||||||
if (!context) {
|
if (!context) {
|
||||||
socket.close(1008, "missing context");
|
socket.close(1008, "missing context");
|
||||||
@@ -194,7 +224,7 @@ export function setupLiveEventsWebSocketServer(
|
|||||||
aliveByClient.delete(socket);
|
aliveByClient.delete(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("error", (err) => {
|
socket.on("error", (err: Error) => {
|
||||||
logger.warn({ err, companyId: context.companyId }, "live websocket client error");
|
logger.warn({ err, companyId: context.companyId }, "live websocket client error");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -229,7 +259,7 @@ export function setupLiveEventsWebSocketServer(
|
|||||||
const reqWithContext = req as IncomingMessageWithContext;
|
const reqWithContext = req as IncomingMessageWithContext;
|
||||||
reqWithContext.paperclipUpgradeContext = context;
|
reqWithContext.paperclipUpgradeContext = context;
|
||||||
|
|
||||||
wss.handleUpgrade(req, socket, head, (ws) => {
|
wss.handleUpgrade(req, socket, head, (ws: WsSocket) => {
|
||||||
wss.emit("connection", ws, reqWithContext);
|
wss.emit("connection", ws, reqWithContext);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user