11import {
2- EncryptedDatabaseToken ,
2+ EncryptedObject ,
33 ExecuteFlowOperation ,
44 ExecutePropsOptions ,
55 ExecuteStepOperation ,
@@ -39,8 +39,6 @@ export class EngineConstants {
3939 public static readonly BLOCK_SOURCES =
4040 process . env . OPS_BLOCKS_SOURCE ?? 'FILE' ;
4141
42- private project : Project | null = null ;
43-
4442 public get baseCodeDirectory ( ) : string {
4543 return EngineConstants . BASE_CODE_DIRECTORY ;
4644 }
@@ -69,13 +67,18 @@ export class EngineConstants {
6967 public readonly testRunActionLimits : TestRunLimitSettings ,
7068 public readonly isTestRun : boolean ,
7169 public readonly tablesDatabaseId : number ,
72- public readonly tablesDatabaseToken : EncryptedDatabaseToken ,
70+ public readonly tablesDatabaseToken : EncryptedObject ,
7371 public readonly resumePayload ?: ResumePayload ,
7472 ) { }
7573
76- public static fromExecuteFlowInput (
74+ public static async fromExecuteFlowInput (
7775 input : ExecuteFlowOperation ,
78- ) : EngineConstants {
76+ ) : Promise < EngineConstants > {
77+ const project = await EngineConstants . fetchProject (
78+ input . internalApiUrl ,
79+ input . engineToken ,
80+ ) ;
81+
7982 return new EngineConstants (
8083 input . executionCorrelationId ,
8184 input . flowVersion . flowId ,
@@ -99,17 +102,22 @@ export class EngineConstants {
99102 input . serverHandlerId ?? null ,
100103 input . flowVersion . testRunActionLimits ,
101104 input . runEnvironment === 'TESTING' ,
102- input . tablesDatabaseId ,
103- input . tablesDatabaseToken ,
105+ project . tablesDatabaseId ,
106+ project . tablesDatabaseToken ,
104107 input . executionType === ExecutionType . RESUME
105108 ? input . resumePayload
106109 : undefined ,
107110 ) ;
108111 }
109112
110- public static fromExecuteStepInput (
113+ public static async fromExecuteStepInput (
111114 input : ExecuteStepOperation ,
112- ) : EngineConstants {
115+ ) : Promise < EngineConstants > {
116+ const project = await EngineConstants . fetchProject (
117+ input . internalApiUrl ,
118+ input . engineToken ,
119+ ) ;
120+
113121 return new EngineConstants (
114122 null ,
115123 input . flowVersion . flowId ,
@@ -133,14 +141,19 @@ export class EngineConstants {
133141 null ,
134142 input . flowVersion . testRunActionLimits ,
135143 true ,
136- input . tablesDatabaseId ,
137- input . tablesDatabaseToken ,
144+ project . tablesDatabaseId ,
145+ project . tablesDatabaseToken ,
138146 ) ;
139147 }
140148
141- public static fromExecutePropertyInput (
149+ public static async fromExecutePropertyInput (
142150 input : ExecutePropsOptions ,
143- ) : EngineConstants {
151+ ) : Promise < EngineConstants > {
152+ const project = await EngineConstants . fetchProject (
153+ input . internalApiUrl ,
154+ input . engineToken ,
155+ ) ;
156+
144157 return new EngineConstants (
145158 null ,
146159 input . flowVersion . flowId ,
@@ -164,14 +177,19 @@ export class EngineConstants {
164177 null ,
165178 input . flowVersion . testRunActionLimits ,
166179 true ,
167- input . tablesDatabaseId ,
168- input . tablesDatabaseToken ,
180+ project . tablesDatabaseId ,
181+ project . tablesDatabaseToken ,
169182 ) ;
170183 }
171184
172- public static fromExecuteTriggerInput (
185+ public static async fromExecuteTriggerInput (
173186 input : ExecuteTriggerOperation < TriggerHookType > ,
174- ) : EngineConstants {
187+ ) : Promise < EngineConstants > {
188+ const project = await EngineConstants . fetchProject (
189+ input . internalApiUrl ,
190+ input . engineToken ,
191+ ) ;
192+
175193 return new EngineConstants (
176194 null ,
177195 input . flowVersion . flowId ,
@@ -195,26 +213,26 @@ export class EngineConstants {
195213 null ,
196214 input . flowVersion . testRunActionLimits ,
197215 input . test ,
198- input . tablesDatabaseId ,
199- input . tablesDatabaseToken ,
216+ project . tablesDatabaseId ,
217+ project . tablesDatabaseToken ,
200218 ) ;
201219 }
202220
203- private async getProject ( ) : Promise < Project > {
204- if ( this . project ) {
205- return this . project ;
206- }
207-
208- 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`;
209228
210229 const response = await fetch ( getWorkerProjectEndpoint , {
211230 headers : {
212- Authorization : `Bearer ${ this . engineToken } ` ,
231+ Authorization : `Bearer ${ engineToken } ` ,
213232 } ,
214233 } ) ;
215234
216- this . project = ( await response . json ( ) ) as Project ;
217- return this . project ;
235+ return ( await response . json ( ) ) as Project ;
218236 }
219237}
220238
0 commit comments