11import {
2+ EncryptedObject ,
23 ExecuteFlowOperation ,
34 ExecutePropsOptions ,
45 ExecuteStepOperation ,
@@ -38,8 +39,6 @@ export class EngineConstants {
3839 public static readonly BLOCK_SOURCES =
3940 process . env . OPS_BLOCKS_SOURCE ?? 'FILE' ;
4041
41- private project : Project | null = null ;
42-
4342 public get baseCodeDirectory ( ) : string {
4443 return EngineConstants . BASE_CODE_DIRECTORY ;
4544 }
@@ -67,12 +66,19 @@ export class EngineConstants {
6766 public readonly serverHandlerId : string | null ,
6867 public readonly testRunActionLimits : TestRunLimitSettings ,
6968 public readonly isTestRun : boolean ,
69+ public readonly tablesDatabaseId : number ,
70+ public readonly tablesDatabaseToken : EncryptedObject ,
7071 public readonly resumePayload ?: ResumePayload ,
7172 ) { }
7273
73- public static fromExecuteFlowInput (
74+ public static async fromExecuteFlowInput (
7475 input : ExecuteFlowOperation ,
75- ) : EngineConstants {
76+ ) : Promise < EngineConstants > {
77+ const project = await EngineConstants . fetchProject (
78+ input . internalApiUrl ,
79+ input . engineToken ,
80+ ) ;
81+
7682 return new EngineConstants (
7783 input . executionCorrelationId ,
7884 input . flowVersion . flowId ,
@@ -96,15 +102,22 @@ export class EngineConstants {
96102 input . serverHandlerId ?? null ,
97103 input . flowVersion . testRunActionLimits ,
98104 input . runEnvironment === 'TESTING' ,
105+ project . tablesDatabaseId ,
106+ project . tablesDatabaseToken ,
99107 input . executionType === ExecutionType . RESUME
100108 ? input . resumePayload
101109 : undefined ,
102110 ) ;
103111 }
104112
105- public static fromExecuteStepInput (
113+ public static async fromExecuteStepInput (
106114 input : ExecuteStepOperation ,
107- ) : EngineConstants {
115+ ) : Promise < EngineConstants > {
116+ const project = await EngineConstants . fetchProject (
117+ input . internalApiUrl ,
118+ input . engineToken ,
119+ ) ;
120+
108121 return new EngineConstants (
109122 null ,
110123 input . flowVersion . flowId ,
@@ -128,12 +141,19 @@ export class EngineConstants {
128141 null ,
129142 input . flowVersion . testRunActionLimits ,
130143 true ,
144+ project . tablesDatabaseId ,
145+ project . tablesDatabaseToken ,
131146 ) ;
132147 }
133148
134- public static fromExecutePropertyInput (
149+ public static async fromExecutePropertyInput (
135150 input : ExecutePropsOptions ,
136- ) : EngineConstants {
151+ ) : Promise < EngineConstants > {
152+ const project = await EngineConstants . fetchProject (
153+ input . internalApiUrl ,
154+ input . engineToken ,
155+ ) ;
156+
137157 return new EngineConstants (
138158 null ,
139159 input . flowVersion . flowId ,
@@ -157,12 +177,19 @@ export class EngineConstants {
157177 null ,
158178 input . flowVersion . testRunActionLimits ,
159179 true ,
180+ project . tablesDatabaseId ,
181+ project . tablesDatabaseToken ,
160182 ) ;
161183 }
162184
163- public static fromExecuteTriggerInput (
185+ public static async fromExecuteTriggerInput (
164186 input : ExecuteTriggerOperation < TriggerHookType > ,
165- ) : EngineConstants {
187+ ) : Promise < EngineConstants > {
188+ const project = await EngineConstants . fetchProject (
189+ input . internalApiUrl ,
190+ input . engineToken ,
191+ ) ;
192+
166193 return new EngineConstants (
167194 null ,
168195 input . flowVersion . flowId ,
@@ -186,24 +213,26 @@ export class EngineConstants {
186213 null ,
187214 input . flowVersion . testRunActionLimits ,
188215 input . test ,
216+ project . tablesDatabaseId ,
217+ project . tablesDatabaseToken ,
189218 ) ;
190219 }
191220
192- private async getProject ( ) : Promise < Project > {
193- if ( this . project ) {
194- return this . project ;
195- }
196-
197- const getWorkerProjectEndpoint = `${ this . internalApiUrl } v1/worker/project` ;
221+ private static async fetchProject (
222+ internalApiUrl : string ,
223+ engineToken : string ,
224+ ) : Promise < Project > {
225+ const getWorkerProjectEndpoint = `${ addTrailingSlashIfMissing (
226+ internalApiUrl ,
227+ ) } v1/worker/project`;
198228
199229 const response = await fetch ( getWorkerProjectEndpoint , {
200230 headers : {
201- Authorization : `Bearer ${ this . engineToken } ` ,
231+ Authorization : `Bearer ${ engineToken } ` ,
202232 } ,
203233 } ) ;
204234
205- this . project = ( await response . json ( ) ) as Project ;
206- return this . project ;
235+ return ( await response . json ( ) ) as Project ;
207236 }
208237}
209238
0 commit comments