diff --git a/packages/server/src/sdk/app/datasources/datasources.ts b/packages/server/src/sdk/app/datasources/datasources.ts index ffd379c30d..c6a036ef20 100644 --- a/packages/server/src/sdk/app/datasources/datasources.ts +++ b/packages/server/src/sdk/app/datasources/datasources.ts @@ -1,13 +1,18 @@ import { environmentVariables } from "@budibase/pro" -import { context } from "@budibase/backend-core" -import { processObject } from "@budibase/string-templates" -import { Datasource } from "@budibase/types" +import { context, db as dbCore } from "@budibase/backend-core" +import { processObjectSync } from "@budibase/string-templates" +import { AppEnvironment, Datasource } from "@budibase/types" import { cloneDeep } from "lodash/fp" export async function enrichDatasourceWithValues(datasource: Datasource) { + const appId = context.getAppId() + const appEnv = dbCore.isDevAppID(appId) + ? AppEnvironment.DEVELOPMENT + : AppEnvironment.PRODUCTION const cloned = cloneDeep(datasource) - const envVars = await environmentVariables.fetchValues() - return (await processObject(cloned, envVars)) as Datasource + const envVars = await environmentVariables.fetchValues(appEnv) + const processed = processObjectSync(cloned, { env: envVars }) + return processed as Datasource } export async function get( diff --git a/packages/server/src/threads/query.ts b/packages/server/src/threads/query.ts index 5eb027883f..9ab96c078f 100644 --- a/packages/server/src/threads/query.ts +++ b/packages/server/src/threads/query.ts @@ -10,10 +10,7 @@ import sdk from "../sdk" import { cloneDeep } from "lodash/fp" import { isSQL } from "../integrations/utils" -import { - enrichQueryFields, - interpolateSQL, -} from "../integrations/queries/sql" +import { enrichQueryFields, interpolateSQL } from "../integrations/queries/sql" class QueryRunner { datasource: any diff --git a/packages/types/src/sdk/environmentVariables.ts b/packages/types/src/sdk/environmentVariables.ts new file mode 100644 index 0000000000..0fe01de1bb --- /dev/null +++ b/packages/types/src/sdk/environmentVariables.ts @@ -0,0 +1,4 @@ +export enum AppEnvironment { + PRODUCTION = "production", + DEVELOPMENT = "development", +} diff --git a/packages/types/src/sdk/index.ts b/packages/types/src/sdk/index.ts index e5512b062b..f8f9d9cb97 100644 --- a/packages/types/src/sdk/index.ts +++ b/packages/types/src/sdk/index.ts @@ -11,3 +11,4 @@ export * from "./locks" export * from "./db" export * from "./middleware" export * from "./featureFlag" +export * from "./environmentVariables"