@@ -8,46 +8,25 @@ import { AUTH_RATE_LIMIT_SCOPE_WORKER_TRANSFER, type AuthRateLimiter } from "../
88import { classifyNodeWorkspaceTransferPath } from "../gateway-http-route-contracts.js" ;
99import { sendJson , watchClientDisconnect } from "../http-common.js" ;
1010import { withSerializedRateLimitAttempt } from "../rate-limit-attempt-serialization.js" ;
11+ import type {
12+ NodeWorkspaceTransferHttpCallback ,
13+ NodeWorkspaceTransferHttpRoute ,
14+ } from "./node-workspace-transfer-http-contract.js" ;
1115import {
1216 isNodeWorkspaceTransferLimitError ,
1317 type NodeWorkspaceTransferService ,
1418} from "./node-workspace-transfer-service.js" ;
1519
20+ export type {
21+ NodeWorkspaceTransferHttpCallback ,
22+ NodeWorkspaceTransferHttpRoute ,
23+ } from "./node-workspace-transfer-http-contract.js" ;
24+
1625const SHA256_PATTERN = / ^ [ a - f 0 - 9 ] { 64 } $ / u;
1726const TRANSFER_TIMEOUT_MS = 10 * 60_000 ;
1827const MAX_ENVIRONMENT_ID_LENGTH = 256 ;
1928const OPAQUE_NOT_FOUND = { error : "not_found" } as const ;
2029
21- export type NodeWorkspaceTransferHttpRoute =
22- | {
23- kind : "manifest" | "pack" ;
24- direction : "download" ;
25- environmentId : string ;
26- manifestRef : string ;
27- }
28- | { kind : "blob" ; direction : "download" ; environmentId : string ; sha256 : string }
29- | {
30- kind : "reconcile" ;
31- direction : "upload" ;
32- environmentId : string ;
33- baseManifestRef : string ;
34- } ;
35-
36- type NodeWorkspaceTransferHttpCallbackResult =
37- | { kind : "unauthorized" }
38- | { kind : "authorized" ; handle : ( ) => Promise < void > | void } ;
39-
40- /**
41- * Authenticates one parsed transfer route without consuming its body. Long-running
42- * streaming belongs in the returned handle so per-IP auth serialization stays brief.
43- */
44- export type NodeWorkspaceTransferHttpCallback = ( params : {
45- req : IncomingMessage ;
46- res : ServerResponse ;
47- route : NodeWorkspaceTransferHttpRoute ;
48- bearer : string ;
49- } ) => Promise < NodeWorkspaceTransferHttpCallbackResult > ;
50-
5130function decodeEnvironmentId ( segment : string ) : string | undefined {
5231 let value : string ;
5332 try {
@@ -145,7 +124,7 @@ function sendTransferRateLimited(res: ServerResponse, retryAfterMs: number): voi
145124type TransferAdmission =
146125 | { kind : "rate-limited" ; retryAfterMs : number }
147126 | { kind : "unauthorized" }
148- | Extract < NodeWorkspaceTransferHttpCallbackResult , { kind : "authorized" } > ;
127+ | Extract < Awaited < ReturnType < NodeWorkspaceTransferHttpCallback > > , { kind : "authorized" } > ;
149128
150129/** Reserve and authenticate the node workspace transfer namespace before normal HTTP routing. */
151130export async function handleNodeWorkspaceTransferHttpRequest ( params : {
0 commit comments