33 detectOutputFormat ,
44 defineCommand ,
55 ExitCode ,
6- sandboxEndpoint ,
6+ sandboxApiPath ,
77 SANDBOX_PATHS ,
88 sandboxTemplateBuildStatusPath ,
99 sandboxTemplatePath ,
@@ -21,7 +21,7 @@ import {
2121 POLL_INTERVAL_FLAG ,
2222 readRequestBody ,
2323 redactRequestSecrets ,
24- resolveWorkspaceId ,
24+ resolveSandboxEndpoint ,
2525 SANDBOX_NOTES ,
2626 setDefined ,
2727 validateIntegerRange ,
@@ -312,7 +312,7 @@ function validatePollInterval(flags: { pollInterval?: number }): string | undefi
312312
313313async function emitTemplateMutationResult ( options : {
314314 response : TemplateInfo ;
315- workspaceId : string ;
315+ endpoint : string ;
316316 client : Client ;
317317 settings : Settings ;
318318 async : boolean ;
@@ -333,10 +333,13 @@ async function emitTemplateMutationResult(options: {
333333 }
334334 return ;
335335 }
336- const buildEndpoint = sandboxEndpoint (
337- options . workspaceId ,
338- sandboxTemplateBuildStatusPath ( options . response . templateID , options . response . buildID ) ,
339- ) ;
336+ // Poll the same origin that accepted the build, including custom gateways.
337+ const buildEndpoint = new URL (
338+ sandboxApiPath (
339+ sandboxTemplateBuildStatusPath ( options . response . templateID , options . response . buildID ) ,
340+ ) ,
341+ options . endpoint ,
342+ ) . toString ( ) ;
340343 const build = await waitForTemplateBuild (
341344 options . client ,
342345 options . settings ,
@@ -372,8 +375,7 @@ export const sandboxTemplateCreate = defineCommand({
372375 validate : validatePollInterval ,
373376 async run ( ctx ) {
374377 const format = detectOutputFormat ( ctx . settings . output ) ;
375- const workspaceId = resolveWorkspaceId ( ctx ) ;
376- const endpoint = sandboxEndpoint ( workspaceId , SANDBOX_PATHS . templateCreate ) ;
378+ const endpoint = resolveSandboxEndpoint ( ctx , SANDBOX_PATHS . templateCreate ) ;
377379 const body = await buildTemplateCreateBody ( ctx . flags ) ;
378380 if ( ctx . settings . dryRun ) {
379381 emitResult ( { method : "POST" , endpoint, request : redactRequestSecrets ( body ) } , format ) ;
@@ -386,7 +388,7 @@ export const sandboxTemplateCreate = defineCommand({
386388 } ) ;
387389 await emitTemplateMutationResult ( {
388390 response,
389- workspaceId ,
391+ endpoint ,
390392 client : ctx . client ,
391393 settings : ctx . settings ,
392394 async : ctx . flags . async ,
@@ -419,8 +421,7 @@ export const sandboxTemplateList = defineCommand({
419421 return undefined ;
420422 } ,
421423 async run ( ctx ) {
422- const workspaceId = resolveWorkspaceId ( ctx ) ;
423- const url = new URL ( sandboxEndpoint ( workspaceId , SANDBOX_PATHS . templateList ) ) ;
424+ const url = new URL ( resolveSandboxEndpoint ( ctx , SANDBOX_PATHS . templateList ) ) ;
424425 if ( ctx . flags . limit !== undefined ) url . searchParams . set ( "limit" , String ( ctx . flags . limit ) ) ;
425426 if ( ctx . flags . cursor ) url . searchParams . set ( "cursor" , ctx . flags . cursor ) ;
426427 const response = await ctx . client . requestJson < TemplateInfo [ ] > ( {
@@ -466,8 +467,7 @@ export const sandboxTemplateGet = defineCommand({
466467 exampleArgs : [ "--template-id tpl-xxx" , "--template-id tpl-xxx --output json" ] ,
467468 notes : SANDBOX_NOTES ,
468469 async run ( ctx ) {
469- const workspaceId = resolveWorkspaceId ( ctx ) ;
470- const endpoint = sandboxEndpoint ( workspaceId , sandboxTemplatePath ( ctx . flags . templateId ) ) ;
470+ const endpoint = resolveSandboxEndpoint ( ctx , sandboxTemplatePath ( ctx . flags . templateId ) ) ;
471471 const response = await ctx . client . requestJson < TemplateInfo > ( { path : endpoint , method : "GET" } ) ;
472472 if ( ctx . settings . quiet ) emitBare ( displayValue ( response . templateID ) ) ;
473473 else emitResult ( response , detectOutputFormat ( ctx . settings . output ) ) ;
@@ -499,8 +499,7 @@ export const sandboxTemplateUpdate = defineCommand({
499499 validate : validatePollInterval ,
500500 async run ( ctx ) {
501501 const format = detectOutputFormat ( ctx . settings . output ) ;
502- const workspaceId = resolveWorkspaceId ( ctx ) ;
503- const endpoint = sandboxEndpoint ( workspaceId , sandboxTemplatePath ( ctx . flags . templateId ) ) ;
502+ const endpoint = resolveSandboxEndpoint ( ctx , sandboxTemplatePath ( ctx . flags . templateId ) ) ;
504503 const body = await buildTemplateUpdateBody ( ctx . flags ) ;
505504 if ( ctx . settings . dryRun ) {
506505 emitResult ( { method : "PUT" , endpoint, request : redactRequestSecrets ( body ) } , format ) ;
@@ -513,7 +512,7 @@ export const sandboxTemplateUpdate = defineCommand({
513512 } ) ;
514513 await emitTemplateMutationResult ( {
515514 response,
516- workspaceId ,
515+ endpoint ,
517516 client : ctx . client ,
518517 settings : ctx . settings ,
519518 async : ctx . flags . async ,
@@ -536,9 +535,8 @@ export const sandboxTemplateBuildStatus = defineCommand({
536535 ] ,
537536 notes : SANDBOX_NOTES ,
538537 async run ( ctx ) {
539- const workspaceId = resolveWorkspaceId ( ctx ) ;
540- const endpoint = sandboxEndpoint (
541- workspaceId ,
538+ const endpoint = resolveSandboxEndpoint (
539+ ctx ,
542540 sandboxTemplateBuildStatusPath ( ctx . flags . templateId , ctx . flags . buildId ) ,
543541 ) ;
544542 const response = await ctx . client . requestJson < TemplateBuildStatus > ( {
@@ -573,8 +571,7 @@ export const sandboxTemplateDelete = defineCommand({
573571 ] ,
574572 async run ( ctx ) {
575573 const format = detectOutputFormat ( ctx . settings . output ) ;
576- const workspaceId = resolveWorkspaceId ( ctx ) ;
577- const endpoint = sandboxEndpoint ( workspaceId , sandboxTemplatePath ( ctx . flags . templateId ) ) ;
574+ const endpoint = resolveSandboxEndpoint ( ctx , sandboxTemplatePath ( ctx . flags . templateId ) ) ;
578575 if ( ctx . settings . dryRun ) {
579576 emitResult ( { method : "DELETE" , endpoint, request : null } , format ) ;
580577 return ;
0 commit comments