Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/n8n-io/n8n into node-844-…
Browse files Browse the repository at this point in the history
…jira-trigger-showing-credential-validation-incorrectly
  • Loading branch information
michael-radency committed Apr 24, 2024
2 parents ce89ddf + 8f5a6be commit 07d6211
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 88 deletions.
14 changes: 14 additions & 0 deletions cypress/e2e/25-stickies.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ describe('Canvas Actions', () => {
expect($el).to.have.css('z-index', '-158');
});
});

it('Empty sticky should not error when activating workflow', () => {
workflowPage.actions.addSticky();

workflowPage.getters.stickies().should('have.length', 1);

workflowPage.getters.stickies().dblclick();

workflowPage.actions.clearSticky();

workflowPage.actions.addNodeToCanvas('Schedule Trigger');

workflowPage.actions.activateWorkflow();
});
});

type Position = {
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/32-node-io-filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ describe('Node IO Filter', () => {

searchInput.filter(':focus').should('exist');
ndv.getters.pagination().find('li').should('have.length', 3);
cy.get('.highlight').should('not.exist');
ndv.getters.outputDataContainer().find('mark').should('not.exist');

searchInput.type('ar');
ndv.getters.pagination().find('li').should('have.length', 2);
cy.get('.highlight').its('length').should('be.gt', 0);
ndv.getters.outputDataContainer().find('mark').its('length').should('be.gt', 0);

searchInput.type('i');
ndv.getters.pagination().should('not.exist');
cy.get('.highlight').its('length').should('be.gt', 0);
ndv.getters.outputDataContainer().find('mark').its('length').should('be.gt', 0);
});

it.only('should filter input/output data separately', () => {
it('should filter input/output data separately', () => {
workflowPage.getters.canvasNodes().eq(1).dblclick();
cy.wait(500);
ndv.getters.outputDataContainer().should('be.visible');
Expand Down
3 changes: 3 additions & 0 deletions cypress/pages/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ export class WorkflowPage extends BasePage {
editSticky: (content: string) => {
this.getters.stickies().dblclick().find('textarea').clear().type(content).type('{esc}');
},
clearSticky: () => {
this.getters.stickies().dblclick().find('textarea').clear().type('{esc}');
},
shouldHaveWorkflowName: (name: string) => {
this.getters.workflowNameInputContainer().invoke('attr', 'title').should('include', name);
},
Expand Down
4 changes: 2 additions & 2 deletions packages/@n8n/nodes-langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@
"@aws-sdk/credential-provider-node": "3.549.0",
"@getzep/zep-js": "0.9.0",
"@google-ai/generativelanguage": "0.2.1",
"@google/generative-ai": "^0.5.0",
"@google/generative-ai": "0.8.0",
"@huggingface/inference": "2.6.4",
"@langchain/anthropic": "^0.1.3",
"@langchain/cohere": "^0.0.5",
"@langchain/community": "0.0.44",
"@langchain/core": "0.1.41",
"@langchain/google-genai": "^0.0.11",
"@langchain/google-genai": "^0.0.12",
"@langchain/mistralai": "0.0.13",
"@langchain/openai": "^0.0.16",
"@langchain/pinecone": "^0.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"ldapts": "4.2.6",
"lodash": "4.17.21",
"luxon": "3.3.0",
"mysql2": "3.9.5",
"mysql2": "3.9.7",
"n8n-core": "workspace:*",
"n8n-editor-ui": "workspace:*",
"n8n-nodes-base": "workspace:*",
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/src/TestWebhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,20 @@ export class TestWebhooks implements IWebhookManager {

for (const webhook of webhooks) {
const key = this.registrations.toKey(webhook);
const isAlreadyRegistered = await this.registrations.get(key);
const registrationByKey = await this.registrations.get(key);

if (runData && webhook.node in runData) {
return false;
}

if (isAlreadyRegistered && !webhook.webhookId) {
// if registration already exists and is not a test webhook created by this user in this workflow throw an error
if (
registrationByKey &&
!webhook.webhookId &&
!registrationByKey.webhook.isTest &&
registrationByKey.webhook.userId !== userId &&
registrationByKey.webhook.workflowId !== workflow.id
) {
throw new WebhookPathTakenError(webhook.node);
}

Expand Down
19 changes: 16 additions & 3 deletions packages/editor-ui/src/components/NodeWebhooks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
>
<div v-if="isWebhookMethodVisible(webhook)" class="webhook-wrapper">
<div class="http-field">
<div class="http-method">
{{ workflowHelpers.getWebhookExpressionValue(webhook, 'httpMethod') }}<br />
</div>
<div class="http-method">{{ getWebhookHttpMethod(webhook) }}<br /></div>
</div>
<div class="url-field">
<div class="webhook-url left-ellipsis clickable" @click="copyWebhookUrl(webhook)">
Expand Down Expand Up @@ -195,12 +193,27 @@ export default defineComponent({
return '';
},
isWebhookMethodVisible(webhook: IWebhookDescription): boolean {
try {
const method = this.workflowHelpers.getWebhookExpressionValue(webhook, 'httpMethod', false);
if (Array.isArray(method) && method.length !== 1) {
return false;
}
} catch (error) {}
if (typeof webhook.ndvHideMethod === 'string') {
return !this.workflowHelpers.getWebhookExpressionValue(webhook, 'ndvHideMethod');
}
return !webhook.ndvHideMethod;
},
getWebhookHttpMethod(webhook: IWebhookDescription): string {
const method = this.workflowHelpers.getWebhookExpressionValue(webhook, 'httpMethod', false);
if (Array.isArray(method)) {
return method[0];
}
return method;
},
},
});
</script>
Expand Down
9 changes: 8 additions & 1 deletion packages/editor-ui/src/components/TriggerPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,17 @@ export default defineComponent({
return undefined;
}
return this.workflowHelpers.getWebhookExpressionValue(
const httpMethod = this.workflowHelpers.getWebhookExpressionValue(
this.nodeType.webhooks[0],
'httpMethod',
false,
);
if (Array.isArray(httpMethod)) {
return httpMethod.join(', ');
}
return httpMethod;
},
webhookTestUrl(): string | undefined {
if (!this.node || !this.nodeType?.webhooks?.length) {
Expand Down
16 changes: 13 additions & 3 deletions packages/editor-ui/src/composables/useWorkflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,12 +738,21 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
return nodeData;
}

function getWebhookExpressionValue(webhookData: IWebhookDescription, key: string): string {
function getWebhookExpressionValue(
webhookData: IWebhookDescription,
key: string,
stringify = true,
): string {
if (webhookData[key] === undefined) {
return 'empty';
}
try {
return resolveExpression(webhookData[key] as string) as string;
return resolveExpression(
webhookData[key] as string,
undefined,
undefined,
stringify,
) as string;
} catch (e) {
return i18n.baseText('nodeWebhooks.invalidExpression');
}
Expand Down Expand Up @@ -785,6 +794,7 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
c?: number;
additionalKeys?: IWorkflowDataProxyAdditionalKeys;
} = {},
stringifyObject = true,
) {
const parameters = {
__xxxxxxx__: expression,
Expand All @@ -796,7 +806,7 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
}

const obj = returnData.__xxxxxxx__;
if (typeof obj === 'object') {
if (typeof obj === 'object' && stringifyObject) {
const proxy = obj as { isProxy: boolean; toJSON?: () => unknown } | null;
if (proxy?.isProxy && proxy.toJSON) return JSON.stringify(proxy.toJSON());
const workflow = getCurrentWorkflow();
Expand Down
24 changes: 22 additions & 2 deletions packages/nodes-base/nodes/Splunk/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
IRequestOptions,
IHttpRequestMethods,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { NodeApiError, NodeOperationError, sleep } from 'n8n-workflow';

import { parseString } from 'xml2js';

Expand Down Expand Up @@ -139,9 +139,29 @@ export async function splunkApiRequest(
delete options.qs;
}

let result;
try {
return await this.helpers.request(options).then(parseXml);
let attempts = 0;

do {
try {
const response = await this.helpers.request(options);
result = await parseXml(response);
return result;
} catch (error) {
if (attempts >= 5) {
throw error;
}
await sleep(1000);
attempts++;
}
} while (true);
} catch (error) {
if (result === undefined) {
throw new NodeOperationError(this.getNode(), 'No response from API call', {
description: "Try to use 'Retry On Fail' option from node's settings",
});
}
if (error?.cause?.code === 'ECONNREFUSED') {
throw new NodeApiError(this.getNode(), { ...(error as JsonObject), code: 401 });
}
Expand Down
51 changes: 33 additions & 18 deletions packages/nodes-base/nodes/Splunk/Splunk.node.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type {
IExecuteFunctions,
ICredentialsDecrypted,
ICredentialTestFunctions,
IDataObject,
ILoadOptionsFunctions,
INodeCredentialTestResult,
INodeExecutionData,
INodeType,
INodeTypeDescription,
IRequestOptions,
import {
type IExecuteFunctions,
type ICredentialsDecrypted,
type ICredentialTestFunctions,
type IDataObject,
type ILoadOptionsFunctions,
type INodeCredentialTestResult,
type INodeExecutionData,
type INodeType,
type INodeTypeDescription,
type IRequestOptions,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';

import {
Expand All @@ -35,6 +37,7 @@ import {
} from './descriptions';

import type { SplunkCredentials, SplunkFeedResponse } from './types';
import set from 'lodash/set';

export class Splunk implements INodeType {
description: INodeTypeDescription = {
Expand Down Expand Up @@ -155,7 +158,7 @@ export class Splunk implements INodeType {

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const returnData: INodeExecutionData[] = [];

const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
Expand Down Expand Up @@ -454,18 +457,30 @@ export class Splunk implements INodeType {
}
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.cause.error });
returnData.push({ json: { error: error.cause.error }, pairedItem: { item: i } });
continue;
}

throw error;
if (error instanceof NodeApiError) {
set(error, 'context.itemIndex', i);
}

if (error instanceof NodeOperationError && error?.context?.itemIndex === undefined) {
set(error, 'context.itemIndex', i);
}

throw new NodeOperationError(this.getNode(), error, { itemIndex: i });
}

Array.isArray(responseData)
? returnData.push(...(responseData as IDataObject[]))
: returnData.push(responseData as IDataObject);
if (Array.isArray(responseData)) {
for (const item of responseData) {
returnData.push({ json: item, pairedItem: { item: i } });
}
} else {
returnData.push({ json: responseData, pairedItem: { item: i } });
}
}

return [this.helpers.returnJsonArray(returnData)];
return [returnData];
}
}
Loading

0 comments on commit 07d6211

Please sign in to comment.