| 
4 | 4 |  * See License.AGPL.txt in the project root for license information.  | 
5 | 5 |  */  | 
6 | 6 | 
 
  | 
7 |  | -import { parse as parseDuration } from "@arcjet/duration";  | 
 | 7 | +import parse from "parse-duration";  | 
8 | 8 | import {  | 
9 | 9 |     User,  | 
10 | 10 |     WorkspaceInfo,  | 
@@ -359,17 +359,27 @@ export namespace WorkspaceTimeoutDuration {  | 
359 | 359 |         duration = duration.toLowerCase();  | 
360 | 360 | 
 
  | 
361 | 361 |         try {  | 
362 |  | -            // Use @arcjet/duration library which is a TypeScript port of Go's ParseDuration  | 
363 |  | -            // This ensures exact compatibility with Go's duration parsing  | 
364 |  | -            const seconds = parseDuration(duration);  | 
 | 362 | +            // Ensure the duration contains proper units (h, m, s, ms, us, ns)  | 
 | 363 | +            // This prevents bare numbers like "1" from being accepted  | 
 | 364 | +            if (!/[a-z]/.test(duration)) {  | 
 | 365 | +                throw new Error("Invalid duration format");  | 
 | 366 | +            }  | 
 | 367 | + | 
 | 368 | +            // Use parse-duration library which supports Go duration format perfectly  | 
 | 369 | +            // This handles mixed-unit durations like "1h30m", "2h15m", etc.  | 
 | 370 | +            const milliseconds = parse(duration);  | 
 | 371 | + | 
 | 372 | +            if (milliseconds === undefined || milliseconds === null) {  | 
 | 373 | +                throw new Error("Invalid duration format");  | 
 | 374 | +            }  | 
365 | 375 | 
 
  | 
366 | 376 |             // Validate the parsed duration is within limits  | 
367 |  | -            const maxSeconds = WORKSPACE_MAXIMUM_TIMEOUT_HOURS * 60 * 60;  | 
368 |  | -            if (seconds > maxSeconds) {  | 
 | 377 | +            const maxMs = WORKSPACE_MAXIMUM_TIMEOUT_HOURS * 60 * 60 * 1000;  | 
 | 378 | +            if (milliseconds > maxMs) {  | 
369 | 379 |                 throw new Error("Workspace inactivity timeout cannot exceed 24h");  | 
370 | 380 |             }  | 
371 | 381 | 
 
  | 
372 |  | -            if (seconds <= 0) {  | 
 | 382 | +            if (milliseconds <= 0) {  | 
373 | 383 |                 throw new Error(`Invalid timeout value: ${duration}. Timeout must be greater than 0`);  | 
374 | 384 |             }  | 
375 | 385 | 
 
  | 
 | 
0 commit comments