mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 02:51:14 +00:00
🎨 Set up linting and formatting (#2120)
* ⬆️ Upgrade TS to 4.3.5 * 👕 Add ESLint configs * 🎨 Add Prettier config * 📦 Add deps and commands * ⚡ Adjust global .editorconfig to new ruleset * 🔥 Remove unneeded local .editorconfig * 📦 Update deps in editor-ui * 🔨 Limit Prettier to only TS files * ⚡ Add recommended VSCode extensions * 👕 Fix build * 🔥 Remove Vue setting from global config * ⚡ Disable prefer-default-export per feedback * ✏️ Add forgotten divider * 👕 Disable no-plusplus * 👕 Disable class-methods-use-this * ✏️ Alphabetize overrides * 👕 Add one-var consecutive override * ⏪ Revert one-var consecutive override This reverts commit b9252cf935659ba6d76727ad484a1d3c00008fcc. * 🎨 👕 Lint and format workflow package (#2121) * 🎨 Format /workflow package * 👕 Lint /workflow package * 🎨 Re-format /workflow package * 👕 Re-lint /workflow package * ✏️ Fix typo * ⚡ Consolidate if-checks * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 🎨 👕 Lint and format node-dev package (#2122) * 🎨 Format /node-dev package * ⚡ Exclude templates from ESLint config This keeps the templates consistent with the codebase while preventing lint exceptions from being made part of the templates. * 👕 Lint /node-dev package * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🎨 👕 Lint and format core package (#2123) * 🎨 Format /core package * 👕 Lint /core package * 🎨 Re-format /core package * 👕 Re-lint /core package * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 🎨 👕 Lint and format cli package (#2124) * 🎨 Format /cli package * 👕 Exclude migrations from linting * 👕 Lint /cli package * 🎨 Re-format /cli package * 👕 Re-lint /cli package * 👕 Fix build * 🔥 Remove prefer-default-export exceptions * ⚡ Update exceptions in ActiveExecutions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 👕 fix lint issues * 🔧 use package specific linter, remove tslint command * 🔨 resolve build issue, sync dependencies * 🔧 change lint command Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com>
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
import { INode, IStatusCodeMessages, JsonObject} from '.';
|
||||
/* eslint-disable @typescript-eslint/no-shadow */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable no-param-reassign */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
// eslint-disable-next-line max-classes-per-file
|
||||
import { parseString } from 'xml2js';
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import { INode, IStatusCodeMessages, JsonObject } from '.';
|
||||
|
||||
/**
|
||||
* Top-level properties where an error message can be found in an API response.
|
||||
@@ -33,7 +41,14 @@ const ERROR_MESSAGE_PROPERTIES = [
|
||||
/**
|
||||
* Top-level properties where an HTTP error code can be found in an API response.
|
||||
*/
|
||||
const ERROR_STATUS_PROPERTIES = ['statusCode', 'status', 'code', 'status_code', 'errorCode', 'error_code'];
|
||||
const ERROR_STATUS_PROPERTIES = [
|
||||
'statusCode',
|
||||
'status',
|
||||
'code',
|
||||
'status_code',
|
||||
'errorCode',
|
||||
'error_code',
|
||||
];
|
||||
|
||||
/**
|
||||
* Properties where a nested object can be found in an API response.
|
||||
@@ -46,8 +61,11 @@ const ERROR_NESTING_PROPERTIES = ['error', 'err', 'response', 'body', 'data'];
|
||||
*/
|
||||
abstract class NodeError extends Error {
|
||||
description: string | null | undefined;
|
||||
|
||||
cause: Error | JsonObject;
|
||||
|
||||
node: INode;
|
||||
|
||||
timestamp: number;
|
||||
|
||||
constructor(node: INode, error: Error | JsonObject) {
|
||||
@@ -95,13 +113,17 @@ abstract class NodeError extends Error {
|
||||
potentialKeys: string[],
|
||||
traversalKeys: string[] = [],
|
||||
): string | null {
|
||||
for(const key of potentialKeys) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const key of potentialKeys) {
|
||||
if (error[key]) {
|
||||
if (typeof error[key] === 'string') return error[key] as string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
if (typeof error[key] === 'number') return error[key]!.toString();
|
||||
if (Array.isArray(error[key])) {
|
||||
// @ts-ignore
|
||||
const resolvedErrors: string[] = error[key].map((error) => {
|
||||
const resolvedErrors: string[] = error[key]
|
||||
// @ts-ignore
|
||||
.map((error) => {
|
||||
if (typeof error === 'string') return error;
|
||||
if (typeof error === 'number') return error.toString();
|
||||
if (this.isTraversableObject(error)) {
|
||||
@@ -125,6 +147,7 @@ abstract class NodeError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const key of traversalKeys) {
|
||||
if (this.isTraversableObject(error[key])) {
|
||||
const property = this.findProperty(error[key] as JsonObject, potentialKeys, traversalKeys);
|
||||
@@ -140,18 +163,24 @@ abstract class NodeError extends Error {
|
||||
/**
|
||||
* Check if a value is an object with at least one key, i.e. it can be traversed.
|
||||
*/
|
||||
protected isTraversableObject(value: any): value is JsonObject { // tslint:disable-line:no-any
|
||||
return value && typeof value === 'object' && !Array.isArray(value) && !!Object.keys(value).length;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
protected isTraversableObject(value: any): value is JsonObject {
|
||||
return (
|
||||
value && typeof value === 'object' && !Array.isArray(value) && !!Object.keys(value).length
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove circular references from objects.
|
||||
*/
|
||||
protected removeCircularRefs(obj: JsonObject, seen = new Set()) {
|
||||
protected removeCircularRefs(obj: JsonObject, seen = new Set()) {
|
||||
seen.add(obj);
|
||||
Object.entries(obj).forEach(([key, value]) => {
|
||||
if (this.isTraversableObject(value)) {
|
||||
seen.has(value) ? obj[key] = { circularReference: true } : this.removeCircularRefs(value, seen);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
seen.has(value)
|
||||
? (obj[key] = { circularReference: true })
|
||||
: this.removeCircularRefs(value, seen);
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
@@ -173,7 +202,6 @@ abstract class NodeError extends Error {
|
||||
* Class for instantiating an operational error, e.g. an invalid credentials error.
|
||||
*/
|
||||
export class NodeOperationError extends NodeError {
|
||||
|
||||
constructor(node: INode, error: Error | string) {
|
||||
if (typeof error === 'string') {
|
||||
error = new Error(error);
|
||||
@@ -211,10 +239,16 @@ export class NodeApiError extends NodeError {
|
||||
constructor(
|
||||
node: INode,
|
||||
error: JsonObject,
|
||||
{ message, description, httpCode, parseXml }: { message?: string, description?: string, httpCode?: string, parseXml?: boolean } = {},
|
||||
{
|
||||
message,
|
||||
description,
|
||||
httpCode,
|
||||
parseXml,
|
||||
}: { message?: string; description?: string; httpCode?: string; parseXml?: boolean } = {},
|
||||
) {
|
||||
super(node, error);
|
||||
if (error.error) { // only for request library error
|
||||
if (error.error) {
|
||||
// only for request library error
|
||||
this.removeCircularRefs(error.error as JsonObject);
|
||||
}
|
||||
if (message) {
|
||||
@@ -236,11 +270,17 @@ export class NodeApiError extends NodeError {
|
||||
}
|
||||
|
||||
private setDescriptionFromXml(xml: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
parseString(xml, { explicitArray: false }, (_, result) => {
|
||||
if (!result) return;
|
||||
|
||||
const topLevelKey = Object.keys(result)[0];
|
||||
this.description = this.findProperty(result[topLevelKey], ERROR_MESSAGE_PROPERTIES, ['Error'].concat(ERROR_NESTING_PROPERTIES));
|
||||
this.description = this.findProperty(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
result[topLevelKey],
|
||||
ERROR_MESSAGE_PROPERTIES,
|
||||
['Error'].concat(ERROR_NESTING_PROPERTIES),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user