mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
feat: Add support for $env in the js task runner (no-changelog) (#11177)
This commit is contained in:
@@ -30,6 +30,8 @@ import {
|
||||
import * as NodeHelpers from './NodeHelpers';
|
||||
import { deepCopy } from './utils';
|
||||
import type { Workflow } from './Workflow';
|
||||
import type { EnvProviderState } from './WorkflowDataProxyEnvProvider';
|
||||
import { createEnvProvider, createEnvProviderState } from './WorkflowDataProxyEnvProvider';
|
||||
import { getPinDataIfManualExecution } from './WorkflowDataProxyHelpers';
|
||||
|
||||
export function isResourceLocatorValue(value: unknown): value is INodeParameterResourceLocator {
|
||||
@@ -66,6 +68,7 @@ export class WorkflowDataProxy {
|
||||
private defaultReturnRunIndex = -1,
|
||||
private selfData: IDataObject = {},
|
||||
private contextNodeName: string = activeNodeName,
|
||||
private envProviderState?: EnvProviderState,
|
||||
) {
|
||||
this.runExecutionData = isScriptingNode(this.contextNodeName, workflow)
|
||||
? runExecutionData !== null
|
||||
@@ -487,40 +490,6 @@ export class WorkflowDataProxy {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a proxy to query data from the environment
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private envGetter() {
|
||||
const that = this;
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
has: () => true,
|
||||
get(_, name) {
|
||||
if (name === 'isProxy') return true;
|
||||
|
||||
if (typeof process === 'undefined') {
|
||||
throw new ExpressionError('not accessible via UI, please run node', {
|
||||
runIndex: that.runIndex,
|
||||
itemIndex: that.itemIndex,
|
||||
});
|
||||
}
|
||||
if (process.env.N8N_BLOCK_ENV_ACCESS_IN_NODE === 'true') {
|
||||
throw new ExpressionError('access to env vars denied', {
|
||||
causeDetailed:
|
||||
'If you need access please contact the administrator to remove the environment variable ‘N8N_BLOCK_ENV_ACCESS_IN_NODE‘',
|
||||
runIndex: that.runIndex,
|
||||
itemIndex: that.itemIndex,
|
||||
});
|
||||
}
|
||||
return process.env[name.toString()];
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
private prevNodeGetter() {
|
||||
const allowedValues = ['name', 'outputIndex', 'runIndex'];
|
||||
const that = this;
|
||||
@@ -1303,7 +1272,11 @@ export class WorkflowDataProxy {
|
||||
|
||||
$binary: {}, // Placeholder
|
||||
$data: {}, // Placeholder
|
||||
$env: this.envGetter(),
|
||||
$env: createEnvProvider(
|
||||
that.runIndex,
|
||||
that.itemIndex,
|
||||
that.envProviderState ?? createEnvProviderState(),
|
||||
),
|
||||
$evaluateExpression: (expression: string, itemIndex?: number) => {
|
||||
itemIndex = itemIndex || that.itemIndex;
|
||||
return that.workflow.expression.getParameterValue(
|
||||
|
||||
Reference in New Issue
Block a user