From 6f0b6f094d9fdeffc5de181c186a81c21bd5a6cb Mon Sep 17 00:00:00 2001 From: ogerly Date: Thu, 27 Apr 2023 11:52:32 +0200 Subject: [PATCH 01/14] refactor auto logout messages autohide time 5000 --- frontend/src/components/SessionLogoutTimeout.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/SessionLogoutTimeout.vue b/frontend/src/components/SessionLogoutTimeout.vue index 7a11d1d83..2b776fbdd 100644 --- a/frontend/src/components/SessionLogoutTimeout.vue +++ b/frontend/src/components/SessionLogoutTimeout.vue @@ -67,7 +67,7 @@ export default { } if (this.tokenExpiresInSeconds === 0) { this.$timer.stop('tokenExpires') - this.toastInfoNoHide(this.$t('session.automaticallyLoggedOut')) + this.toastInfo(this.$t('session.automaticallyLoggedOut')) this.$emit('logout') } }, @@ -85,7 +85,7 @@ export default { }) .catch(() => { this.$timer.stop('tokenExpires') - this.toastInfoNoHide(this.$t('session.automaticallyLoggedOut')) + this.toastInfo(this.$t('session.automaticallyLoggedOut')) this.$emit('logout') }) }, From 3e0db936d63f95f57359ef896ab4a88256195f43 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 18:00:29 +0200 Subject: [PATCH 02/14] update jest-canvas-mock version to resolve window mock problem in tests --- frontend/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/package.json b/frontend/package.json index 8515ca209..f07284da6 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -44,7 +44,7 @@ "graphql": "^15.5.1", "identity-obj-proxy": "^3.0.0", "jest": "^26.6.3", - "jest-canvas-mock": "^2.3.1", + "jest-canvas-mock": "^2.5.0", "jwt-decode": "^3.1.2", "portal-vue": "^2.1.7", "prettier": "^2.2.1", From 12a499ab42f87f67e09d0564bab3c1e88e555eaf Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 2 May 2023 18:04:13 +0200 Subject: [PATCH 03/14] update yarn.lock --- frontend/yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 9e8fdd81d..7cc8e5fe5 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -8657,10 +8657,10 @@ javascript-stringify@^1.6.0: resolved "https://registry.yarnpkg.com/javascript-stringify/-/javascript-stringify-1.6.0.tgz#142d111f3a6e3dae8f4a9afd77d45855b5a9cce3" integrity sha1-FC0RHzpuPa6PSpr9d9RYVbWpzOM= -jest-canvas-mock@^2.3.1: - version "2.3.1" - resolved "https://registry.yarnpkg.com/jest-canvas-mock/-/jest-canvas-mock-2.3.1.tgz#9535d14bc18ccf1493be36ac37dd349928387826" - integrity sha512-5FnSZPrX3Q2ZfsbYNE3wqKR3+XorN8qFzDzB5o0golWgt6EOX1+emBnpOc9IAQ+NXFj8Nzm3h7ZdE/9H0ylBcg== +jest-canvas-mock@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/jest-canvas-mock/-/jest-canvas-mock-2.5.0.tgz#3e60f87f77ddfa273cf8e7e4ea5f86fa827c7117" + integrity sha512-s2bmY2f22WPMzhB2YA93kiyf7CAfWAnV/sFfY9s48IVOrGmwui1eSFluDPesq1M+7tSC1hJAit6mzO0ZNXvVBA== dependencies: cssfontparser "^1.2.1" moo-color "^1.0.2" From 2d56f736641b0692bec00be90b0789affc56e4cc Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:27:07 +0200 Subject: [PATCH 04/14] database migration --- .../0067-private_key_in_community_table.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 database/migrations/0067-private_key_in_community_table.ts diff --git a/database/migrations/0067-private_key_in_community_table.ts b/database/migrations/0067-private_key_in_community_table.ts new file mode 100644 index 000000000..999ef8708 --- /dev/null +++ b/database/migrations/0067-private_key_in_community_table.ts @@ -0,0 +1,16 @@ +/* MIGRATION TO ADD PRIVATE KEY IN COMMUNITY TABLE + * + * This migration adds a field for the private key in the community.table + */ + +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn( + 'ALTER TABLE `communities` ADD COLUMN `private_key` binary(64) DEFAULT NULL AFTER `public_key`;', + ) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('ALTER TABLE `communities` DROP COLUMN `private_key`;') +} From 93a67ac35aa260a298e41b8165ffb686f9eac60f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:28:17 +0200 Subject: [PATCH 05/14] require the new database version --- backend/src/config/index.ts | 2 +- dht-node/src/config/index.ts | 2 +- federation/src/config/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 8d1ed8ae6..70830359f 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,7 +12,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0066-x-community-sendcoins-transactions_table', + DB_VERSION: '0067-private_key_in_community_table', DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 43949201b..255a4def0 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -3,7 +3,7 @@ import dotenv from 'dotenv' dotenv.config() const constants = { - DB_VERSION: '0066-x-community-sendcoins-transactions_table', + DB_VERSION: '0067-private_key_in_community_table', LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info LOG_LEVEL: process.env.LOG_LEVEL || 'info', diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index 66d8a056c..0dade2a6a 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ const constants = { - DB_VERSION: '0066-x-community-sendcoins-transactions_table', + DB_VERSION: '0067-private_key_in_community_table', // DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info From a58e698878d77823309a095bef70e0d293c507af Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:31:34 +0200 Subject: [PATCH 06/14] updated Community entity to include private Key field --- .../Community.ts | 63 +++++++++++++++++++ database/entity/Community.ts | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 database/entity/0067-private_key_in_community_table/Community.ts diff --git a/database/entity/0067-private_key_in_community_table/Community.ts b/database/entity/0067-private_key_in_community_table/Community.ts new file mode 100644 index 000000000..dcb55c875 --- /dev/null +++ b/database/entity/0067-private_key_in_community_table/Community.ts @@ -0,0 +1,63 @@ +import { + BaseEntity, + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + UpdateDateColumn, +} from 'typeorm' + +@Entity('communities') +export class Community extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ name: 'foreign', type: 'bool', nullable: false, default: true }) + foreign: boolean + + @Column({ name: 'url', length: 255, nullable: false }) + url: string + + @Column({ name: 'public_key', type: 'binary', length: 64, nullable: false }) + publicKey: Buffer + + @Column({ name: 'private_key', type: 'binary', length: 64, nullable: true }) + privateKey: Buffer | null + + @Column({ + name: 'community_uuid', + type: 'char', + length: 36, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + communityUuid: string | null + + @Column({ name: 'authenticated_at', type: 'datetime', nullable: true }) + authenticatedAt: Date | null + + @Column({ name: 'name', type: 'varchar', length: 40, nullable: true }) + name: string | null + + @Column({ name: 'description', type: 'varchar', length: 255, nullable: true }) + description: string | null + + @CreateDateColumn({ name: 'creation_date', type: 'datetime', nullable: true }) + creationDate: Date | null + + @CreateDateColumn({ + name: 'created_at', + type: 'datetime', + default: () => 'CURRENT_TIMESTAMP(3)', + nullable: false, + }) + createdAt: Date + + @UpdateDateColumn({ + name: 'updated_at', + type: 'datetime', + onUpdate: 'CURRENT_TIMESTAMP(3)', + nullable: true, + }) + updatedAt: Date | null +} diff --git a/database/entity/Community.ts b/database/entity/Community.ts index ee08323b6..5df0f70fe 100644 --- a/database/entity/Community.ts +++ b/database/entity/Community.ts @@ -1 +1 @@ -export { Community } from './0065-refactor_communities_table/Community' +export { Community } from './0067-private_key_in_community_table/Community' From e4f8cd0f35a70f99ac9238099ac65d8bad107daf Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:35:08 +0200 Subject: [PATCH 07/14] save privatekey for home community --- dht-node/src/dht_node/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dht-node/src/dht_node/index.ts b/dht-node/src/dht_node/index.ts index adef0fc52..639909735 100644 --- a/dht-node/src/dht_node/index.ts +++ b/dht-node/src/dht_node/index.ts @@ -220,6 +220,7 @@ async function writeHomeCommunityEntry(keyPair: KeyPair): Promise { if (homeCom) { // simply update the existing entry, but it MUST keep the ID and UUID because of possible relations homeCom.publicKey = keyPair.publicKey + homeCom.privateKey = keyPair.secretKey homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/' homeCom.name = CONFIG.COMMUNITY_NAME homeCom.description = CONFIG.COMMUNITY_DESCRIPTION @@ -230,6 +231,7 @@ async function writeHomeCommunityEntry(keyPair: KeyPair): Promise { homeCom = new DbCommunity() homeCom.foreign = false homeCom.publicKey = keyPair.publicKey + homeCom.privateKey = keyPair.secretKey homeCom.communityUuid = await newCommunityUuid() homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/' homeCom.name = CONFIG.COMMUNITY_NAME From feedab3cebde52cdc6fc18ba744405fa58cdb13f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 30 May 2023 10:47:20 +0200 Subject: [PATCH 08/14] missing new line --- database/migrations/0067-private_key_in_community_table.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/database/migrations/0067-private_key_in_community_table.ts b/database/migrations/0067-private_key_in_community_table.ts index 999ef8708..f36e68b16 100644 --- a/database/migrations/0067-private_key_in_community_table.ts +++ b/database/migrations/0067-private_key_in_community_table.ts @@ -5,6 +5,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ + export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn( 'ALTER TABLE `communities` ADD COLUMN `private_key` binary(64) DEFAULT NULL AFTER `public_key`;', From ef8c619512116ffdd0f423066eb8e2499c7bfee1 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 31 May 2023 12:50:10 +0200 Subject: [PATCH 09/14] remove changes, hide automatic logout toaster after login --- frontend/src/components/SessionLogoutTimeout.vue | 4 ++-- frontend/src/pages/Login.vue | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/SessionLogoutTimeout.vue b/frontend/src/components/SessionLogoutTimeout.vue index 2b776fbdd..7a11d1d83 100644 --- a/frontend/src/components/SessionLogoutTimeout.vue +++ b/frontend/src/components/SessionLogoutTimeout.vue @@ -67,7 +67,7 @@ export default { } if (this.tokenExpiresInSeconds === 0) { this.$timer.stop('tokenExpires') - this.toastInfo(this.$t('session.automaticallyLoggedOut')) + this.toastInfoNoHide(this.$t('session.automaticallyLoggedOut')) this.$emit('logout') } }, @@ -85,7 +85,7 @@ export default { }) .catch(() => { this.$timer.stop('tokenExpires') - this.toastInfo(this.$t('session.automaticallyLoggedOut')) + this.toastInfoNoHide(this.$t('session.automaticallyLoggedOut')) this.$emit('logout') }) }, diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 6fd435c2d..6e0a50949 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -86,6 +86,7 @@ export default { const loader = this.$loading.show({ container: this.$refs.submitButton, }) + this.$root.$bvToast.hide() this.$apollo .mutate({ mutation: login, From 676cf779c7a68e682ce9980f75d80226d2f95877 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 7 Jun 2023 10:51:45 +0200 Subject: [PATCH 10/14] removed middleware and replace it with a function --- backend/src/graphql/model/KlickTipp.ts | 7 ++--- backend/src/graphql/resolver/UserResolver.ts | 18 +++-------- .../resolver/util/getKlicktippState.ts | 19 ++++++++++++ backend/src/middleware/klicktippMiddleware.ts | 31 ------------------- 4 files changed, 25 insertions(+), 50 deletions(-) create mode 100644 backend/src/graphql/resolver/util/getKlicktippState.ts delete mode 100644 backend/src/middleware/klicktippMiddleware.ts diff --git a/backend/src/graphql/model/KlickTipp.ts b/backend/src/graphql/model/KlickTipp.ts index 059c7874d..356ed391f 100644 --- a/backend/src/graphql/model/KlickTipp.ts +++ b/backend/src/graphql/model/KlickTipp.ts @@ -1,12 +1,9 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { ObjectType, Field } from 'type-graphql' @ObjectType() export class KlickTipp { - constructor(json: any) { - this.newsletterState = json.status === 'Subscribed' + constructor(newsletterState: boolean) { + this.newsletterState = newsletterState } @Field(() => Boolean) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index cbfd9b5c5..194909b89 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -8,17 +8,7 @@ import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' import { User as DbUser } from '@entity/User' import { UserContact as DbUserContact } from '@entity/UserContact' import i18n from 'i18n' -import { - Resolver, - Query, - Args, - Arg, - Authorized, - Ctx, - UseMiddleware, - Mutation, - Int, -} from 'type-graphql' +import { Resolver, Query, Args, Arg, Authorized, Ctx, Mutation, Int } from 'type-graphql' import { v4 as uuidv4 } from 'uuid' import { CreateUserArgs } from '@arg/CreateUserArgs' @@ -60,7 +50,6 @@ import { EVENT_ADMIN_USER_DELETE, EVENT_ADMIN_USER_UNDELETE, } from '@/event/Events' -import { klicktippNewsletterStateMiddleware } from '@/middleware/klicktippMiddleware' import { isValidPassword } from '@/password/EncryptorUtils' import { encryptPassword, verifyPassword } from '@/password/PasswordEncryptor' import { Context, getUser, getClientTimezoneOffset } from '@/server/context' @@ -73,6 +62,7 @@ import { getTimeDurationObject, printTimeDuration } from '@/util/time' import { FULL_CREATION_AVAILABLE } from './const/const' import { getUserCreations } from './util/creations' import { findUserByIdentifier } from './util/findUserByIdentifier' +import { getKlicktippState } from './util/getKlicktippState' import { validateAlias } from './util/validateAlias' // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-commonjs @@ -122,7 +112,6 @@ const newGradidoID = async (): Promise => { export class UserResolver { @Authorized([RIGHTS.VERIFY_LOGIN]) @Query(() => User) - @UseMiddleware(klicktippNewsletterStateMiddleware) async verifyLogin(@Ctx() context: Context): Promise { logger.info('verifyLogin...') // TODO refactor and do not have duplicate code with login(see below) @@ -132,12 +121,12 @@ export class UserResolver { user.hasElopage = await this.hasElopage(context) logger.debug(`verifyLogin... successful: ${user.firstName}.${user.lastName}`) + user.klickTipp = await getKlicktippState(userEntity.emailContact.email) return user } @Authorized([RIGHTS.LOGIN]) @Mutation(() => User) - @UseMiddleware(klicktippNewsletterStateMiddleware) async login( @Args() { email, password, publisherId }: UnsecureLoginArgs, @Ctx() context: Context, @@ -183,6 +172,7 @@ export class UserResolver { dbUser.publisherId = publisherId await DbUser.save(dbUser) } + user.klickTipp = await getKlicktippState(dbUser.emailContact.email) context.setHeaders.push({ key: 'token', diff --git a/backend/src/graphql/resolver/util/getKlicktippState.ts b/backend/src/graphql/resolver/util/getKlicktippState.ts new file mode 100644 index 000000000..728f565ff --- /dev/null +++ b/backend/src/graphql/resolver/util/getKlicktippState.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-unsafe-return */ +import { KlickTipp } from '@model/KlickTipp' + +import { getKlickTippUser } from '@/apis/KlicktippController' +import { klickTippLogger as logger } from '@/server/logger' + +export const getKlicktippState = async (email: string): Promise => { + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const klickTippUser = await getKlickTippUser(email) + if (klickTippUser) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + return new KlickTipp(klickTippUser.status === 'Subscribed') + } + } catch (err) { + logger.error('There is no klicktipp user for email', email, err) + } + return new KlickTipp(false) +} diff --git a/backend/src/middleware/klicktippMiddleware.ts b/backend/src/middleware/klicktippMiddleware.ts deleted file mode 100644 index 038bd3dd3..000000000 --- a/backend/src/middleware/klicktippMiddleware.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unsafe-return */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ -import { MiddlewareFn } from 'type-graphql' - -import { KlickTipp } from '@model/KlickTipp' - -import { getKlickTippUser } from '@/apis/KlicktippController' -import { klickTippLogger as logger } from '@/server/logger' - -export const klicktippNewsletterStateMiddleware: MiddlewareFn = async ( - /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ - { root, args, context, info }, - next, -) => { - // eslint-disable-next-line n/callback-return - const result = await next() - let klickTipp = new KlickTipp({ status: 'Unsubscribed' }) - try { - const klickTippUser = await getKlickTippUser(result.email) - if (klickTippUser) { - klickTipp = new KlickTipp(klickTippUser) - } - } catch (err) { - logger.error(`There is no user for (email='${result.email}') ${err}`) - } - result.klickTipp = klickTipp - return result -} From c8d01263ef03cb5fa1d52cdf95a152e86b621e80 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 9 Jun 2023 14:03:34 +0200 Subject: [PATCH 11/14] enable eslint n --- dht-node/.eslintrc.js | 76 +++++++++++++++++++++---------------------- dht-node/package.json | 3 ++ 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/dht-node/.eslintrc.js b/dht-node/.eslintrc.js index 64f5a9051..27f393f82 100644 --- a/dht-node/.eslintrc.js +++ b/dht-node/.eslintrc.js @@ -101,44 +101,44 @@ module.exports = { // ], // 'import/prefer-default-export': 'off', // n - // 'n/handle-callback-err': 'error', - // 'n/no-callback-literal': 'error', - // 'n/no-exports-assign': 'error', - // 'n/no-extraneous-import': 'error', - // 'n/no-extraneous-require': 'error', - // 'n/no-hide-core-modules': 'error', - // 'n/no-missing-import': 'off', // not compatible with typescript - // 'n/no-missing-require': 'error', - // 'n/no-new-require': 'error', - // 'n/no-path-concat': 'error', - // 'n/no-process-exit': 'error', - // 'n/no-unpublished-bin': 'error', - // 'n/no-unpublished-import': 'off', // TODO need to exclude seeds - // 'n/no-unpublished-require': 'error', - // 'n/no-unsupported-features': ['error', { ignores: ['modules'] }], - // 'n/no-unsupported-features/es-builtins': 'error', - // 'n/no-unsupported-features/es-syntax': 'error', - // 'n/no-unsupported-features/node-builtins': 'error', - // 'n/process-exit-as-throw': 'error', - // 'n/shebang': 'error', - // 'n/callback-return': 'error', - // 'n/exports-style': 'error', - // 'n/file-extension-in-import': 'off', - // 'n/global-require': 'error', - // 'n/no-mixed-requires': 'error', - // 'n/no-process-env': 'error', - // 'n/no-restricted-import': 'error', - // 'n/no-restricted-require': 'error', - // 'n/no-sync': 'error', - // 'n/prefer-global/buffer': 'error', - // 'n/prefer-global/console': 'error', - // 'n/prefer-global/process': 'error', - // 'n/prefer-global/text-decoder': 'error', - // 'n/prefer-global/text-encoder': 'error', - // 'n/prefer-global/url': 'error', - // 'n/prefer-global/url-search-params': 'error', - // 'n/prefer-promises/dns': 'error', - // 'n/prefer-promises/fs': 'error', + 'n/handle-callback-err': 'error', + 'n/no-callback-literal': 'error', + 'n/no-exports-assign': 'error', + 'n/no-extraneous-import': 'error', + 'n/no-extraneous-require': 'error', + 'n/no-hide-core-modules': 'error', + 'n/no-missing-import': 'off', // not compatible with typescript + 'n/no-missing-require': 'error', + 'n/no-new-require': 'error', + 'n/no-path-concat': 'error', + 'n/no-process-exit': 'error', + 'n/no-unpublished-bin': 'error', + 'n/no-unpublished-import': 'off', // TODO need to exclude seeds + 'n/no-unpublished-require': 'error', + 'n/no-unsupported-features': ['error', { ignores: ['modules'] }], + 'n/no-unsupported-features/es-builtins': 'error', + 'n/no-unsupported-features/es-syntax': 'error', + 'n/no-unsupported-features/node-builtins': 'error', + 'n/process-exit-as-throw': 'error', + 'n/shebang': 'error', + 'n/callback-return': 'error', + 'n/exports-style': 'error', + 'n/file-extension-in-import': 'off', + 'n/global-require': 'error', + 'n/no-mixed-requires': 'error', + 'n/no-process-env': 'error', + 'n/no-restricted-import': 'error', + 'n/no-restricted-require': 'error', + 'n/no-sync': 'error', + 'n/prefer-global/buffer': 'error', + 'n/prefer-global/console': 'error', + 'n/prefer-global/process': 'error', + 'n/prefer-global/text-decoder': 'error', + 'n/prefer-global/text-encoder': 'error', + 'n/prefer-global/url': 'error', + 'n/prefer-global/url-search-params': 'error', + 'n/prefer-promises/dns': 'error', + 'n/prefer-promises/fs': 'error', // promise // 'promise/catch-or-return': 'error', // 'promise/no-return-wrap': 'error', diff --git a/dht-node/package.json b/dht-node/package.json index 23238b9e4..049d0373f 100644 --- a/dht-node/package.json +++ b/dht-node/package.json @@ -47,5 +47,8 @@ "prettier": "^2.8.7", "jest": "^27.2.4", "ts-jest": "^27.0.5" + }, + "engines": { + "node": ">=14" } } From 231784ed09c41c9724e2cf7dad6634a4955b9604 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 9 Jun 2023 14:03:43 +0200 Subject: [PATCH 12/14] fix n warnings --- dht-node/jest.config.js | 2 ++ dht-node/src/config/index.ts | 2 +- dht-node/src/index.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dht-node/jest.config.js b/dht-node/jest.config.js index 0b83d8edd..49f048d78 100644 --- a/dht-node/jest.config.js +++ b/dht-node/jest.config.js @@ -16,10 +16,12 @@ module.exports = { '@/(.*)': '/src/$1', '@test/(.*)': '/test/$1', '@entity/(.*)': + // eslint-disable-next-line n/no-process-env process.env.NODE_ENV === 'development' ? '/../database/entity/$1' : '/../database/build/entity/$1', '@dbTools/(.*)': + // eslint-disable-next-line n/no-process-env process.env.NODE_ENV === 'development' ? '/../database/src/$1' : '/../database/build/src/$1', diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 43949201b..b6b0c0a16 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -1,4 +1,4 @@ -// ATTENTION: DO NOT PUT ANY SECRETS IN HERE (or the .env) +/* eslint-disable n/no-process-env */ import dotenv from 'dotenv' dotenv.config() diff --git a/dht-node/src/index.ts b/dht-node/src/index.ts index d5e5f700b..e70b324b5 100644 --- a/dht-node/src/index.ts +++ b/dht-node/src/index.ts @@ -33,5 +33,5 @@ async function main() { main().catch((e) => { // eslint-disable-next-line no-console console.error(e) - process.exit(1) + throw e }) From 360db7424611d70e9d84b5f06c1b6a04bf91c703 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 9 Jun 2023 14:07:46 +0200 Subject: [PATCH 13/14] enable eslint comments --- dht-node/.eslintrc.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dht-node/.eslintrc.js b/dht-node/.eslintrc.js index 64f5a9051..1cb259970 100644 --- a/dht-node/.eslintrc.js +++ b/dht-node/.eslintrc.js @@ -13,7 +13,7 @@ module.exports = { // 'plugin:import/recommended', // 'plugin:import/typescript', // 'plugin:security/recommended', - // 'plugin:@eslint-community/eslint-comments/recommended', + 'plugin:@eslint-community/eslint-comments/recommended', ], settings: { 'import/parsers': { @@ -155,10 +155,10 @@ module.exports = { // 'promise/prefer-await-to-callbacks': 'error', // 'promise/no-multiple-resolved': 'error', // eslint comments - // '@eslint-community/eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }], - // '@eslint-community/eslint-comments/no-restricted-disable': 'error', - // '@eslint-community/eslint-comments/no-use': 'off', - // '@eslint-community/eslint-comments/require-description': 'off', + '@eslint-community/eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }], + '@eslint-community/eslint-comments/no-restricted-disable': 'error', + '@eslint-community/eslint-comments/no-use': 'off', + '@eslint-community/eslint-comments/require-description': 'off', }, overrides: [ // only for ts files From 30b980eb54f847df15157948d1f53a9e35af6992 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 9 Jun 2023 14:08:06 +0200 Subject: [PATCH 14/14] exclude coverage folder from linting --- dht-node/.eslintignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dht-node/.eslintignore b/dht-node/.eslintignore index f6b255e92..1ae86fe5e 100644 --- a/dht-node/.eslintignore +++ b/dht-node/.eslintignore @@ -1,3 +1,4 @@ node_modules **/*.min.js -build \ No newline at end of file +build +coverage \ No newline at end of file