Skip to content

Commit 39ac1e8

Browse files
committed
Add tablesDatabaseId and tablesDatabaseToken to block context to be later used in openops-tables
1 parent 940f221 commit 39ac1e8

12 files changed

Lines changed: 76 additions & 2 deletions

File tree

packages/blocks/framework/src/lib/context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ export type ServerContext = {
125125
apiUrl: string;
126126
publicUrl: string;
127127
token: string;
128+
tablesDatabaseId: number;
129+
tablesDatabaseToken: {
130+
iv: string;
131+
data: string;
132+
};
128133
};
129134
export type BaseActionContext<
130135
ET extends ExecutionType,

packages/engine/src/lib/handler/block-executor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ const executeAction: ActionHandler<BlockAction> = async ({
189189
token: constants.engineToken,
190190
apiUrl: constants.internalApiUrl,
191191
publicUrl: constants.publicUrl,
192+
tablesDatabaseId: constants.tablesDatabaseId,
193+
tablesDatabaseToken: constants.tablesDatabaseToken,
192194
},
193195
propsValue: processedInput,
194196
tags: createTagsManager(hookResponse),

packages/engine/src/lib/handler/context/engine-constants.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
EncryptedDatabaseToken,
23
ExecuteFlowOperation,
34
ExecutePropsOptions,
45
ExecuteStepOperation,
@@ -67,6 +68,8 @@ export class EngineConstants {
6768
public readonly serverHandlerId: string | null,
6869
public readonly testRunActionLimits: TestRunLimitSettings,
6970
public readonly isTestRun: boolean,
71+
public readonly tablesDatabaseId: number,
72+
public readonly tablesDatabaseToken: EncryptedDatabaseToken,
7073
public readonly resumePayload?: ResumePayload,
7174
) {}
7275

@@ -96,6 +99,8 @@ export class EngineConstants {
9699
input.serverHandlerId ?? null,
97100
input.flowVersion.testRunActionLimits,
98101
input.runEnvironment === 'TESTING',
102+
input.tablesDatabaseId,
103+
input.tablesDatabaseToken,
99104
input.executionType === ExecutionType.RESUME
100105
? input.resumePayload
101106
: undefined,
@@ -128,6 +133,8 @@ export class EngineConstants {
128133
null,
129134
input.flowVersion.testRunActionLimits,
130135
true,
136+
input.tablesDatabaseId,
137+
input.tablesDatabaseToken,
131138
);
132139
}
133140

@@ -157,6 +164,8 @@ export class EngineConstants {
157164
null,
158165
input.flowVersion.testRunActionLimits,
159166
true,
167+
input.tablesDatabaseId,
168+
input.tablesDatabaseToken,
160169
);
161170
}
162171

@@ -186,6 +195,8 @@ export class EngineConstants {
186195
null,
187196
input.flowVersion.testRunActionLimits,
188197
input.test,
198+
input.tablesDatabaseId,
199+
input.tablesDatabaseToken,
189200
);
190201
}
191202

packages/engine/src/lib/helper/block-helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export const blockHelper = {
124124
token: params.engineToken,
125125
apiUrl: constants.internalApiUrl,
126126
publicUrl: params.publicUrl,
127+
tablesDatabaseId: constants.tablesDatabaseId,
128+
tablesDatabaseToken: constants.tablesDatabaseToken,
127129
},
128130
project: {
129131
id: params.projectId,

packages/engine/src/lib/resolve-variable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export async function resolveVariable(
1717
flowVersion: input.flowVersion,
1818
stepName: input.stepName,
1919
stepTestOutputs: input.stepTestOutputs,
20+
tablesDatabaseId: input.tablesDatabaseId,
21+
tablesDatabaseToken: input.tablesDatabaseToken,
2022
});
2123

2224
const executionState = await testExecutionContext.stateFromFlowVersion({

packages/engine/test/handler/test-helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const generateMockEngineConstants = (params?: Partial<EngineConstants>):
3030
params?.serverHandlerId ?? null,
3131
params?.testRunActionLimits ?? { isEnabled: false, limits: [] },
3232
params?.isTestRun ?? false,
33+
params?.tablesDatabaseId ?? 1,
34+
params?.tablesDatabaseToken ?? { iv: 'test-iv', data: 'test-data' },
3335
params?.resumePayload,
3436
)
3537
}

packages/engine/test/resolve-variable.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ describe('resolveVariable', () => {
1616
engineToken: 'test-engine-token',
1717
internalApiUrl: 'https://test-api.com',
1818
publicUrl: 'https://test-public.com',
19+
tablesDatabaseId: 1,
20+
tablesDatabaseToken: { iv: 'test-iv', data: 'test-data' },
1921
flowVersion: {
2022
id: 'flow-version-id',
2123
flowId: 'flow-id',
@@ -146,6 +148,8 @@ describe('resolveVariable', () => {
146148
flowVersion: mockInput.flowVersion,
147149
stepName: mockInput.stepName,
148150
stepTestOutputs: mockInput.stepTestOutputs,
151+
tablesDatabaseId: mockInput.tablesDatabaseId,
152+
tablesDatabaseToken: mockInput.tablesDatabaseToken,
149153
});
150154

151155
expect(mockTestExecutionContext.stateFromFlowVersion).toHaveBeenCalledWith({
@@ -186,6 +190,8 @@ describe('resolveVariable', () => {
186190
flowVersion: mockInput.flowVersion,
187191
stepName: mockInput.stepName,
188192
stepTestOutputs: undefined,
193+
tablesDatabaseId: mockInput.tablesDatabaseId,
194+
tablesDatabaseToken: mockInput.tablesDatabaseToken,
189195
});
190196
});
191197
});

packages/server/worker/src/lib/api/server-api.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
GetBlockRequestQuery,
2020
GetFlowVersionForWorkerRequest,
2121
PopulatedFlow,
22+
Project,
2223
RemoveStableJobEngineRequest,
2324
UpdateRunProgressRequest,
2425
WorkerMachineHealthcheckRequest,
@@ -86,6 +87,9 @@ export const engineApiService = (engineToken: string) => {
8687
responseType: 'arraybuffer',
8788
});
8889
},
90+
async getProject(): Promise<Project> {
91+
return client.get<Project>('/v1/worker/project', {});
92+
},
8993
async updateJobStatus(request: UpdateJobRequest): Promise<void> {
9094
await client.post('/v1/engine/update-job', request);
9195
},

packages/server/worker/src/lib/engine/engine-runner.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ import {
2727
} from '@openops/shared';
2828
import chalk from 'chalk';
2929

30-
type EngineConstants = 'publicUrl' | 'internalApiUrl' | 'engineToken';
30+
type EngineConstants =
31+
| 'publicUrl'
32+
| 'internalApiUrl'
33+
| 'engineToken'
34+
| 'tablesDatabaseId'
35+
| 'tablesDatabaseToken';
3136

3237
export type CodeArtifact = {
3338
name: string;

packages/server/worker/src/lib/engine/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@ import {
1414
ResolveVariableOperation,
1515
TriggerHookType,
1616
} from '@openops/shared';
17+
import { engineApiService } from '../api/server-api.service';
1718
import { webhookUtils } from '../utils/webhook-utils';
1819
import { callEngineLambda } from './call-engine';
1920
import { EngineRunner } from './engine-runner';
2021
import { blockEngineUtil } from './flow-enginer-util';
2122

2223
export const engineRunner: EngineRunner = {
2324
async executeFlow(engineToken, operation) {
25+
const project = await engineApiService(engineToken).getProject();
26+
2427
const input: ExecuteFlowOperation = {
2528
...operation,
2629
engineToken,
2730
publicUrl: await networkUtls.getPublicUrl(),
2831
internalApiUrl: networkUtls.getInternalApiUrl(),
32+
tablesDatabaseId: project.tablesDatabaseId,
33+
tablesDatabaseToken: project.tablesDatabaseToken,
2934
};
3035

3136
return callEngineLambda(EngineOperationType.EXECUTE_FLOW, input);
@@ -44,6 +49,7 @@ export const engineRunner: EngineRunner = {
4449
'[EngineHelper#executeTrigger]',
4550
);
4651

52+
const project = await engineApiService(engineToken).getProject();
4753
const triggerBlock = await blockEngineUtil.getTriggerBlock(
4854
engineToken,
4955
operation.flowVersion,
@@ -68,34 +74,45 @@ export const engineRunner: EngineRunner = {
6874
internalApiUrl: networkUtls.getInternalApiUrl(),
6975
webhookSecret: await webhookSecretsUtils.getWebhookSecret(lockedVersion),
7076
engineToken,
77+
tablesDatabaseId: project.tablesDatabaseId,
78+
tablesDatabaseToken: project.tablesDatabaseToken,
7179
};
7280

7381
return callEngineLambda(EngineOperationType.EXECUTE_TRIGGER_HOOK, input);
7482
},
7583

7684
async executeProp(engineToken, operation) {
85+
const project = await engineApiService(engineToken).getProject();
86+
7787
const input: ExecutePropsOptions = {
7888
...operation,
7989
publicUrl: await networkUtls.getPublicUrl(),
8090
internalApiUrl: networkUtls.getInternalApiUrl(),
8191
engineToken,
92+
tablesDatabaseId: project.tablesDatabaseId,
93+
tablesDatabaseToken: project.tablesDatabaseToken,
8294
};
8395

8496
return callEngineLambda(EngineOperationType.EXECUTE_PROPERTY, input);
8597
},
8698

8799
async executeValidateAuth(engineToken, operation) {
100+
const project = await engineApiService(engineToken).getProject();
101+
88102
const input: ExecuteValidateAuthOperation = {
89103
...operation,
90104
publicUrl: await networkUtls.getPublicUrl(),
91105
internalApiUrl: networkUtls.getInternalApiUrl(),
92106
engineToken,
107+
tablesDatabaseId: project.tablesDatabaseId,
108+
tablesDatabaseToken: project.tablesDatabaseToken,
93109
};
94110

95111
return callEngineLambda(EngineOperationType.EXECUTE_VALIDATE_AUTH, input);
96112
},
97113

98114
async executeAction(engineToken, operation) {
115+
const project = await engineApiService(engineToken).getProject();
99116
const lockedFlowVersion = await blockEngineUtil.lockBlockInFlowVersion({
100117
engineToken,
101118
flowVersion: operation.flowVersion,
@@ -110,17 +127,23 @@ export const engineRunner: EngineRunner = {
110127
internalApiUrl: networkUtls.getInternalApiUrl(),
111128
engineToken,
112129
stepTestOutputs: operation.stepTestOutputs,
130+
tablesDatabaseId: project.tablesDatabaseId,
131+
tablesDatabaseToken: project.tablesDatabaseToken,
113132
};
114133

115134
return callEngineLambda(EngineOperationType.EXECUTE_STEP, input);
116135
},
117136

118137
async executeVariable(engineToken, operation) {
138+
const project = await engineApiService(engineToken).getProject();
139+
119140
const input: ResolveVariableOperation = {
120141
...operation,
121142
publicUrl: await networkUtls.getPublicUrl(),
122143
internalApiUrl: networkUtls.getInternalApiUrl(),
123144
engineToken,
145+
tablesDatabaseId: project.tablesDatabaseId,
146+
tablesDatabaseToken: project.tablesDatabaseToken,
124147
};
125148

126149
return callEngineLambda(EngineOperationType.RESOLVE_VARIABLE, input);

0 commit comments

Comments
 (0)