* adds ExecutionEvents view modal to ExecutionList * fix time rendering and remove wf column * checks for unfinished executions and fails them * prevent re-setting stoppedAt for execution * some cleanup / manually create rundata after crash * quicksave * remove Threads lib, log worker rewrite * cleanup comment * fix sentry destination return value * test for tests... * run tests with single worker * fix tests * remove console log * add endpoint for execution data recovery * lint cleanup and some refactoring * fix accidental recursion * remove cyclic imports * add rundata recovery to Workflowrunner * remove comments * cleanup and refactor * adds a status field to executions * setExecutionStatus on queued worker * fix onWorkflowPostExecute * set waiting from worker * get crashed status into frontend * remove comment * merge fix * cleanup * catch empty rundata in recovery * refactor IExecutionsSummary and inject nodeExecution Errors * reduce default event log size to 10mb from 100mb * add per node execution status * lint fix * merge and lint fix * phrasing change * improve preview rendering and messaging * remove debug * Improve partial rundata recovery * fix labels * fix line through * send manual rundata to ui at crash * some type and msg push fixes * improve recovered item rendering in preview * update workflowStatistics on recover * merge fix * review fixes * merge fix * notify eventbus when ui is back up * add a small timeout to make sure the UI is back up * increase reconnect timeout to 30s * adjust recover timeout and ui connection lost msg * do not stop execution in editor after x reconnects * add executionRecovered push event * fix recovered connection not green * remove reconnect toast and merge existing rundata * merge editor and recovered data for own mode
144 lines
4.1 KiB
TypeScript
144 lines
4.1 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
import { DateTime } from 'luxon';
|
|
import type { EventMessageTypeNames, JsonObject } from 'n8n-workflow';
|
|
import { v4 as uuid } from 'uuid';
|
|
import type { AbstractEventPayload } from './AbstractEventPayload';
|
|
import type { AbstractEventMessageOptions } from './AbstractEventMessageOptions';
|
|
import type { EventNamesTypes } from '.';
|
|
|
|
function modifyUnderscoredKeys(
|
|
input: { [key: string]: any },
|
|
modifier: (secret: string) => string | undefined = () => '*',
|
|
) {
|
|
const result: { [key: string]: any } = {};
|
|
if (!input) return input;
|
|
Object.keys(input).forEach((key) => {
|
|
if (typeof input[key] === 'string') {
|
|
if (key.substring(0, 1) === '_') {
|
|
const modifierResult = modifier(input[key]);
|
|
if (modifierResult !== undefined) {
|
|
result[key] = modifier(input[key]);
|
|
}
|
|
} else {
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
result[key] = input[key];
|
|
}
|
|
} else if (typeof input[key] === 'object') {
|
|
if (Array.isArray(input[key])) {
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
result[key] = input[key].map((item: any) => {
|
|
if (typeof item === 'object' && !Array.isArray(item)) {
|
|
return modifyUnderscoredKeys(item, modifier);
|
|
} else {
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
return item;
|
|
}
|
|
});
|
|
} else {
|
|
result[key] = modifyUnderscoredKeys(input[key], modifier);
|
|
}
|
|
} else {
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
result[key] = input[key];
|
|
}
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
export const isEventMessage = (candidate: unknown): candidate is AbstractEventMessage => {
|
|
const o = candidate as AbstractEventMessage;
|
|
if (!o) return false;
|
|
return (
|
|
o.eventName !== undefined &&
|
|
o.id !== undefined &&
|
|
o.ts !== undefined &&
|
|
o.getEventName !== undefined
|
|
);
|
|
};
|
|
|
|
export const isEventMessageOptions = (
|
|
candidate: unknown,
|
|
): candidate is AbstractEventMessageOptions => {
|
|
const o = candidate as AbstractEventMessageOptions;
|
|
if (!o) return false;
|
|
if (o.eventName !== undefined) {
|
|
if (o.eventName.match(/^[\w\s]+\.[\w\s]+\.[\w\s]+/)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
export const isEventMessageOptionsWithType = (
|
|
candidate: unknown,
|
|
expectedType: string,
|
|
): candidate is AbstractEventMessageOptions => {
|
|
const o = candidate as AbstractEventMessageOptions;
|
|
if (!o) return false;
|
|
return o.eventName !== undefined && o.__type !== undefined && o.__type === expectedType;
|
|
};
|
|
|
|
export abstract class AbstractEventMessage {
|
|
abstract readonly __type: EventMessageTypeNames;
|
|
|
|
id: string;
|
|
|
|
ts: DateTime;
|
|
|
|
eventName: EventNamesTypes;
|
|
|
|
message: string;
|
|
|
|
abstract payload: AbstractEventPayload;
|
|
|
|
/**
|
|
* Creates a new instance of Event Message
|
|
* @param props.eventName The specific events name e.g. "n8n.workflow.workflowStarted"
|
|
* @param props.level The log level, defaults to. "info"
|
|
* @param props.severity The severity of the event e.g. "normal"
|
|
* @returns instance of EventMessage
|
|
*/
|
|
constructor(options: AbstractEventMessageOptions) {
|
|
this.setOptionsOrDefault(options);
|
|
}
|
|
|
|
abstract deserialize(data: JsonObject): this;
|
|
abstract setPayload(payload: AbstractEventPayload): this;
|
|
|
|
anonymize(): AbstractEventPayload {
|
|
const anonymizedPayload = modifyUnderscoredKeys(this.payload);
|
|
return anonymizedPayload;
|
|
}
|
|
|
|
serialize(): AbstractEventMessageOptions {
|
|
return {
|
|
__type: this.__type,
|
|
id: this.id,
|
|
ts: this.ts.toISO(),
|
|
eventName: this.eventName,
|
|
message: this.message,
|
|
payload: this.payload,
|
|
};
|
|
}
|
|
|
|
setOptionsOrDefault(options: AbstractEventMessageOptions) {
|
|
this.id = options.id ?? uuid();
|
|
this.eventName = options.eventName;
|
|
this.message = options.message ?? options.eventName;
|
|
if (typeof options.ts === 'string') {
|
|
this.ts = DateTime.fromISO(options.ts) ?? DateTime.now();
|
|
} else {
|
|
this.ts = options.ts ?? DateTime.now();
|
|
}
|
|
}
|
|
|
|
getEventName(): string {
|
|
return this.eventName;
|
|
}
|
|
|
|
toString() {
|
|
return JSON.stringify(this.serialize());
|
|
}
|
|
}
|