@@ -68,22 +68,19 @@ export class EngineConstants {
6868 public readonly serverHandlerId : string | null ,
6969 public readonly testRunActionLimits : TestRunLimitSettings ,
7070 public readonly isTestRun : boolean ,
71+ public readonly tablesDatabaseId : number ,
72+ public readonly tablesDatabaseToken : EncryptedObject ,
7173 public readonly resumePayload ?: ResumePayload ,
7274 ) { }
7375
74- public async getTablesDatabaseId ( ) : Promise < number > {
75- const project = await this . getProject ( ) ;
76- return project . tablesDatabaseId ;
77- }
78-
79- public async getTablesDatabaseToken ( ) : Promise < EncryptedObject > {
80- const project = await this . getProject ( ) ;
81- return project . tablesDatabaseToken ;
82- }
83-
84- public static fromExecuteFlowInput (
76+ public static async fromExecuteFlowInput (
8577 input : ExecuteFlowOperation ,
86- ) : EngineConstants {
78+ ) : Promise < EngineConstants > {
79+ const project = await EngineConstants . fetchProject (
80+ input . internalApiUrl ,
81+ input . engineToken ,
82+ ) ;
83+
8784 return new EngineConstants (
8885 input . executionCorrelationId ,
8986 input . flowVersion . flowId ,
@@ -107,15 +104,22 @@ export class EngineConstants {
107104 input . serverHandlerId ?? null ,
108105 input . flowVersion . testRunActionLimits ,
109106 input . runEnvironment === 'TESTING' ,
107+ project . tablesDatabaseId ,
108+ project . tablesDatabaseToken ,
110109 input . executionType === ExecutionType . RESUME
111110 ? input . resumePayload
112111 : undefined ,
113112 ) ;
114113 }
115114
116- public static fromExecuteStepInput (
115+ public static async fromExecuteStepInput (
117116 input : ExecuteStepOperation ,
118- ) : EngineConstants {
117+ ) : Promise < EngineConstants > {
118+ const project = await EngineConstants . fetchProject (
119+ input . internalApiUrl ,
120+ input . engineToken ,
121+ ) ;
122+
119123 return new EngineConstants (
120124 null ,
121125 input . flowVersion . flowId ,
@@ -139,12 +143,19 @@ export class EngineConstants {
139143 null ,
140144 input . flowVersion . testRunActionLimits ,
141145 true ,
146+ project . tablesDatabaseId ,
147+ project . tablesDatabaseToken ,
142148 ) ;
143149 }
144150
145- public static fromExecutePropertyInput (
151+ public static async fromExecutePropertyInput (
146152 input : ExecutePropsOptions ,
147- ) : EngineConstants {
153+ ) : Promise < EngineConstants > {
154+ const project = await EngineConstants . fetchProject (
155+ input . internalApiUrl ,
156+ input . engineToken ,
157+ ) ;
158+
148159 return new EngineConstants (
149160 null ,
150161 input . flowVersion . flowId ,
@@ -168,12 +179,19 @@ export class EngineConstants {
168179 null ,
169180 input . flowVersion . testRunActionLimits ,
170181 true ,
182+ project . tablesDatabaseId ,
183+ project . tablesDatabaseToken ,
171184 ) ;
172185 }
173186
174- public static fromExecuteTriggerInput (
187+ public static async fromExecuteTriggerInput (
175188 input : ExecuteTriggerOperation < TriggerHookType > ,
176- ) : EngineConstants {
189+ ) : Promise < EngineConstants > {
190+ const project = await EngineConstants . fetchProject (
191+ input . internalApiUrl ,
192+ input . engineToken ,
193+ ) ;
194+
177195 return new EngineConstants (
178196 null ,
179197 input . flowVersion . flowId ,
@@ -197,24 +215,26 @@ export class EngineConstants {
197215 null ,
198216 input . flowVersion . testRunActionLimits ,
199217 input . test ,
218+ project . tablesDatabaseId ,
219+ project . tablesDatabaseToken ,
200220 ) ;
201221 }
202222
203- private async getProject ( ) : Promise < Project > {
204- if ( this . project ) {
205- return this . project ;
206- }
207-
208- const getWorkerProjectEndpoint = `${ this . internalApiUrl } v1/worker/project` ;
223+ private static async fetchProject (
224+ internalApiUrl : string ,
225+ engineToken : string ,
226+ ) : Promise < Project > {
227+ const getWorkerProjectEndpoint = `${ addTrailingSlashIfMissing (
228+ internalApiUrl ,
229+ ) } v1/worker/project`;
209230
210231 const response = await fetch ( getWorkerProjectEndpoint , {
211232 headers : {
212- Authorization : `Bearer ${ this . engineToken } ` ,
233+ Authorization : `Bearer ${ engineToken } ` ,
213234 } ,
214235 } ) ;
215236
216- this . project = ( await response . json ( ) ) as Project ;
217- return this . project ;
237+ return ( await response . json ( ) ) as Project ;
218238 }
219239}
220240
0 commit comments