@@ -15,9 +15,7 @@ import { Freestyle } from "./freestyle";
1515import { Tenancy } from "./tenancies" ;
1616import { upstash } from "./upstash" ;
1717
18- const externalPackages = {
19- '@stackframe/stack' : 'latest' ,
20- } ;
18+ const externalPackages : Record < string , string > = { } ;
2119
2220type WorkflowRegisteredTriggerType = "sign-up" ;
2321
@@ -56,7 +54,9 @@ export async function compileWorkflowSource(source: string): Promise<Result<stri
5654 const bundleResult = await bundleJavaScript ( {
5755 "/source.tsx" : source ,
5856 "/entry.js" : `
59- import { StackServerApp } from '@stackframe/stack';
57+ import { StackServerApp } from 'https://esm.sh/@stackframe/js@2.8.36?target=es2021&standalone';
58+
59+ globalThis.navigator.onLine = true;
6060
6161 export default async () => {
6262 globalThis.stackApp = new StackServerApp({
@@ -125,6 +125,7 @@ export async function compileWorkflowSource(source: string): Promise<Result<stri
125125 } , {
126126 format : 'esm' ,
127127 keepAsImports : Object . keys ( externalPackages ) ,
128+ allowHttpImports : true ,
128129 } ) ;
129130 if ( bundleResult . status === "error" ) {
130131 return Result . error ( bundleResult . error ) ;
@@ -145,7 +146,7 @@ async function compileWorkflow(tenancy: Tenancy, workflowId: string): Promise<Re
145146 return Result . error ( { compileError : `Failed to compile workflow: ${ compiledCodeResult . error } ` } ) ;
146147 }
147148
148- console . log ( `Compiled workflow source for ${ workflowId } , running compilation trigger...` , { compiledCodeResult } ) ;
149+ console . log ( `Compiled workflow source for ${ workflowId } , running compilation trigger...` , { compiledCodeLength : compiledCodeResult . data . length } ) ;
149150
150151 const compileTriggerResult = await triggerWorkflowRaw ( tenancy , compiledCodeResult . data , {
151152 type : "compile" ,
@@ -154,7 +155,7 @@ async function compileWorkflow(tenancy: Tenancy, workflowId: string): Promise<Re
154155 return Result . error ( { compileError : `Failed to initialize workflow: ${ compileTriggerResult . error } ` } ) ;
155156 }
156157
157- console . log ( `Compilation trigger result:` , { compileTriggerResult } ) ;
158+ console . log ( `Compilation trigger completed!` ) ;
158159
159160 const compileTriggerOutputResult = compileTriggerResult . data ;
160161 if ( typeof compileTriggerOutputResult !== "object" || ! compileTriggerOutputResult || ! ( "triggerOutput" in compileTriggerOutputResult ) ) {
@@ -167,7 +168,7 @@ async function compileWorkflow(tenancy: Tenancy, workflowId: string): Promise<Re
167168 return Result . error ( { compileError : `Failed to parse compile trigger output, should be array of strings` } ) ;
168169 }
169170
170- console . log ( `Workflow ${ workflowId } compiled successfully, returning result...` , { registeredTriggers, compiledCodeResult } ) ;
171+ console . log ( `Workflow ${ workflowId } compiled successfully, returning result...` , { registeredTriggers } ) ;
171172
172173 return Result . ok ( {
173174 compiledCode : compiledCodeResult . data ,
@@ -403,16 +404,24 @@ async function triggerWorkflowRaw(tenancy: Tenancy, compiledWorkflowCode: string
403404
404405 try {
405406 const freestyle = new Freestyle ( ) ;
407+ const apiUrl = new URL ( "/" , getEnvVariable ( "NEXT_PUBLIC_STACK_API_URL" ) . replace ( "http://localhost" , "http://host.docker.internal" ) ) ;
406408 const freestyleRes = await freestyle . executeScript ( compiledWorkflowCode , {
407409 envVars : {
408410 STACK_WORKFLOW_TRIGGER_DATA : JSON . stringify ( trigger ) ,
409411 NEXT_PUBLIC_STACK_PROJECT_ID : tenancy . project . id ,
410- NEXT_PUBLIC_STACK_API_URL : getEnvVariable ( "NEXT_PUBLIC_STACK_API_URL" ) . replace ( "http://localhost" , "http://host.docker.internal" ) , // the replace is a hardcoded hack for the Freestyle mock server
412+ NEXT_PUBLIC_STACK_API_URL : apiUrl . toString ( ) ,
411413 NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY : "<placeholder publishable client key; the actual auth happens with the workflow token>" ,
412414 STACK_SECRET_SERVER_KEY : "<placeholder secret server key; the actual auth happens with the workflow token>" ,
413415 STACK_WORKFLOW_TOKEN_SECRET : workflowToken ,
414416 } ,
415417 nodeModules : Object . fromEntries ( Object . entries ( externalPackages ) . map ( ( [ packageName , version ] ) => [ packageName , version ] ) ) ,
418+ networkPermissions : [
419+ {
420+ action : "allow" ,
421+ behavior : "exact" ,
422+ query : apiUrl . host ,
423+ } ,
424+ ] ,
416425 } ) ;
417426 return Result . map ( freestyleRes , ( data ) => data . result ) ;
418427 } finally {
0 commit comments