Skip to content

Commit

Permalink
Merge branch 'master' into ADO-2220-agent-assistant-poc
Browse files Browse the repository at this point in the history
* master:
  ci: Delete unused code in some backend tests (no-changelog) (#9456)
  fix(core): Setup webhook stopping endpoint after the CORS middleware (no-changelog) (#9454)
  fix(editor): Fix i18n translation addition (#9451)
  refactor(editor): Fix type errors in `NodeDetailsView.vue` (no-changelog) (#9431)
  refactor(editor): Convert `workflowActivate`  mixin into a composable  (no-changelog) (#9423)
  • Loading branch information
MiloradFilipovic committed May 19, 2024
2 parents ce91133 + bf2ee51 commit 5ca2bf5
Show file tree
Hide file tree
Showing 16 changed files with 844 additions and 1,408 deletions.
17 changes: 10 additions & 7 deletions packages/cli/src/AbstractServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,6 @@ export abstract class AbstractServer {
// Register a handler
this.app.all(`/${this.endpointFormTest}/:path(*)`, webhookRequestHandler(testWebhooks));
this.app.all(`/${this.endpointWebhookTest}/:path(*)`, webhookRequestHandler(testWebhooks));

// Removes a test webhook
// TODO UM: check if this needs validation with user management.
this.app.delete(
`/${this.restEndpoint}/test-webhook/:id`,
send(async (req) => await testWebhooks.cancelWebhook(req.params.id)),
);
}

// Block bots from scanning the application
Expand All @@ -230,6 +223,16 @@ export abstract class AbstractServer {
this.setupDevMiddlewares();
}

if (this.testWebhooksEnabled) {
const testWebhooks = Container.get(TestWebhooks);
// Removes a test webhook
// TODO UM: check if this needs validation with user management.
this.app.delete(
`/${this.restEndpoint}/test-webhook/:id`,
send(async (req) => await testWebhooks.cancelWebhook(req.params.id)),
);
}

// Setup body parsing middleware after the webhook handlers are setup
this.app.use(bodyParser);

Expand Down
96 changes: 12 additions & 84 deletions packages/core/test/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ import { readdirSync, readFileSync } from 'fs';
const BASE_DIR = path.resolve(__dirname, '../../..');

import type {
ICredentialDataDecryptedObject,
IDataObject,
IDeferredPromise,
IExecuteWorkflowInfo,
IHttpRequestHelper,
IHttpRequestOptions,
INode,
INodeCredentialsDetails,
INodeType,
INodeTypes,
IRun,
Expand All @@ -24,66 +18,13 @@ import type {
INodeTypeData,
} from 'n8n-workflow';

import { ApplicationError, ICredentialsHelper, NodeHelpers, WorkflowHooks } from 'n8n-workflow';
import { Credentials } from '@/Credentials';
import { ApplicationError, NodeHelpers, WorkflowHooks } from 'n8n-workflow';

import { predefinedNodesTypes } from './constants';

export class CredentialsHelper extends ICredentialsHelper {
async authenticate(
credentials: ICredentialDataDecryptedObject,
typeName: string,
requestParams: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
return requestParams;
}

async preAuthentication(
helpers: IHttpRequestHelper,
credentials: ICredentialDataDecryptedObject,
typeName: string,
node: INode,
credentialsExpired: boolean,
): Promise<ICredentialDataDecryptedObject | undefined> {
return undefined;
}

getParentTypes(name: string): string[] {
return [];
}

async getDecrypted(
additionalData: IWorkflowExecuteAdditionalData,
nodeCredentials: INodeCredentialsDetails,
type: string,
): Promise<ICredentialDataDecryptedObject> {
return {};
}

async getCredentials(
nodeCredentials: INodeCredentialsDetails,
type: string,
): Promise<Credentials> {
return new Credentials({ id: null, name: '' }, '', [], '');
}

async updateCredentials(
nodeCredentials: INodeCredentialsDetails,
type: string,
data: ICredentialDataDecryptedObject,
): Promise<void> {}
}
import { mock } from 'jest-mock-extended';

class NodeTypesClass implements INodeTypes {
nodeTypes: INodeTypeData;

constructor(nodeTypes?: INodeTypeData) {
if (nodeTypes) {
this.nodeTypes = nodeTypes;
} else {
this.nodeTypes = predefinedNodesTypes;
}
}
constructor(private nodeTypes: INodeTypeData = predefinedNodesTypes) {}

getByName(nodeType: string): INodeType | IVersionedNodeType {
return this.nodeTypes[nodeType].type;
Expand All @@ -92,11 +33,15 @@ class NodeTypesClass implements INodeTypes {
getByNameAndVersion(nodeType: string, version?: number): INodeType {
return NodeHelpers.getVersionedNodeType(this.nodeTypes[nodeType].type, version);
}

getKnownTypes(): IDataObject {
throw new Error('Method not implemented.');
}
}

let nodeTypesInstance: NodeTypesClass | undefined;

export function NodeTypes(nodeTypes?: INodeTypeData): NodeTypesClass {
export function NodeTypes(nodeTypes?: INodeTypeData): INodeTypes {
if (nodeTypesInstance === undefined || nodeTypes !== undefined) {
nodeTypesInstance = new NodeTypesClass(nodeTypes);
}
Expand All @@ -110,7 +55,7 @@ export function WorkflowExecuteAdditionalData(
): IWorkflowExecuteAdditionalData {
const hookFunctions = {
nodeExecuteAfter: [
async (nodeName: string, data: ITaskData): Promise<void> => {
async (nodeName: string, _data: ITaskData): Promise<void> => {
nodeExecutionOrder.push(nodeName);
},
],
Expand All @@ -121,26 +66,9 @@ export function WorkflowExecuteAdditionalData(
],
};

const workflowData: IWorkflowBase = {
name: '',
createdAt: new Date(),
updatedAt: new Date(),
active: true,
nodes: [],
connections: {},
};

return {
credentialsHelper: new CredentialsHelper(),
hooks: new WorkflowHooks(hookFunctions, 'trigger', '1', workflowData),
executeWorkflow: async (workflowInfo: IExecuteWorkflowInfo) => {},
sendDataToUI: (message: string) => {},
restApiUrl: '',
webhookBaseUrl: 'webhook',
webhookWaitingBaseUrl: 'webhook-waiting',
webhookTestBaseUrl: 'webhook-test',
userId: '123',
};
return mock<IWorkflowExecuteAdditionalData>({
hooks: new WorkflowHooks(hookFunctions, 'trigger', '1', mock()),
});
}

const preparePinData = (pinData: IDataObject) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export default defineComponent({
},
parentTypes: {
type: Array as PropType<string[]>,
default: () => [],
},
credentialData: {},
credentialId: {
Expand Down Expand Up @@ -274,21 +275,21 @@ export default defineComponent({
return '';
}
const appName = getAppNameFromCredType((this.credentialType as ICredentialType).displayName);
const appName = getAppNameFromCredType(this.credentialType.displayName);
return (
appName ||
this.$locale.baseText('credentialEdit.credentialConfig.theServiceYouReConnectingTo')
);
},
credentialTypeName(): string {
return (this.credentialType as ICredentialType)?.name;
return this.credentialType?.name;
},
credentialOwnerName(): string {
return this.credentialsStore.getCredentialOwnerNameById(`${this.credentialId}`);
},
documentationUrl(): string {
const type = this.credentialType as ICredentialType;
const type = this.credentialType;
const activeNode = this.ndvStore.activeNode;
const isCommunityNode = activeNode ? isCommunityPackageName(activeNode.type) : false;
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/NDVDraggablePanels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default defineComponent({
type: Number,
},
nodeType: {
type: Object as PropType<INodeTypeDescription>,
type: Object as PropType<INodeTypeDescription | null>,
default: () => ({}),
},
},
Expand Down
Loading

0 comments on commit 5ca2bf5

Please sign in to comment.