diff --git a/backend/.eslintrc.js b/backend/.eslintrc.js index 78ac9e41e..0007fd125 100644 --- a/backend/.eslintrc.js +++ b/backend/.eslintrc.js @@ -58,7 +58,7 @@ module.exports = { 'import/no-dynamic-require': 'error', 'import/no-internal-modules': 'off', 'import/no-relative-packages': 'error', - 'import/no-relative-parent-imports': ['error', { ignore: ['@/*'] }], + 'import/no-relative-parent-imports': ['error', { ignore: ['@/*', 'random-bigint'] }], 'import/no-self-import': 'error', 'import/no-unresolved': 'error', 'import/no-useless-path-segments': 'error', diff --git a/backend/@types/random-bigint/index.d.ts b/backend/@types/random-bigint/index.d.ts new file mode 100644 index 000000000..0f685e722 --- /dev/null +++ b/backend/@types/random-bigint/index.d.ts @@ -0,0 +1,5 @@ +/* eslint-disable @typescript-eslint/ban-types */ +declare module 'random-bigint' { + function random(bits: number, cb?: (err: Error, num: BigInt) => void): BigInt + export = random +} diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index cbfd9b5c5..9934c93de 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -70,13 +70,13 @@ import { communityDbUser } from '@/util/communityUser' import { hasElopageBuys } from '@/util/hasElopageBuys' import { getTimeDurationObject, printTimeDuration } from '@/util/time' +import random from 'random-bigint' + import { FULL_CREATION_AVAILABLE } from './const/const' import { getUserCreations } from './util/creations' import { findUserByIdentifier } from './util/findUserByIdentifier' import { validateAlias } from './util/validateAlias' -// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-commonjs -const random = require('random-bigint') // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-commonjs const sodium = require('sodium-native') diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 2c237d22c..b4c7b4325 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -68,7 +68,7 @@ FEDERATION_COMMUNITY_API_PORT=5000 FEDERATION_CONFIG_VERSION=v1.2023-01-09 # comma separated list of api-versions, which cause starting several federation modules -FEDERATION_COMMUNITY_APIS=1_0,1_1,2_0 +FEDERATION_COMMUNITY_APIS=1_0,1_1 # database DATABASE_CONFIG_VERSION=v1.2022-03-18 diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts index 18d2a7599..83c024c9f 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts @@ -3,12 +3,15 @@ import { createTestClient } from 'apollo-server-testing' import createServer from '@/server/createServer' import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' +import CONFIG from '@/config' let query: any // to do: We need a setup for the tests that closes the connection let con: any +CONFIG.FEDERATION_API = '1_0' + beforeAll(async () => { const server = await createServer() con = server.con diff --git a/federation/src/graphql/api/1_0/resolver/TestResolver.test.ts b/federation/src/graphql/api/1_0/resolver/TestResolver.test.ts deleted file mode 100644 index e236ee5d8..000000000 --- a/federation/src/graphql/api/1_0/resolver/TestResolver.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { createTestClient } from 'apollo-server-testing' -import createServer from '@/server/createServer' - -let query: any - -// to do: We need a setup for the tests that closes the connection -let con: any - -beforeAll(async () => { - const server = await createServer() - con = server.con - query = createTestClient(server.apollo).query -}) - -afterAll(async () => { - await con.close() -}) - -describe('TestResolver', () => { - const getTestQuery = ` - query { - test { - api - } - } - ` - - describe('getTestApi', () => { - it('returns 1_0', async () => { - await expect(query({ query: getTestQuery })).resolves.toMatchObject({ - data: { - test: { - api: '1_0', - }, - }, - }) - }) - }) -}) diff --git a/federation/src/graphql/api/1_0/resolver/TestResolver.ts b/federation/src/graphql/api/1_0/resolver/TestResolver.ts deleted file mode 100644 index 9fb2fc797..000000000 --- a/federation/src/graphql/api/1_0/resolver/TestResolver.ts +++ /dev/null @@ -1,14 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Query, Resolver } from 'type-graphql' -import { federationLogger as logger } from '@/server/logger' -import { GetTestApiResult } from '../../GetTestApiResult' - -@Resolver() -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export class TestResolver { - @Query(() => GetTestApiResult) - async test(): Promise { - logger.info(`test api 1_0`) - return new GetTestApiResult('1_0') - } -} diff --git a/federation/src/graphql/api/1_1/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_1/resolver/PublicKeyResolver.test.ts new file mode 100644 index 000000000..d41b53263 --- /dev/null +++ b/federation/src/graphql/api/1_1/resolver/PublicKeyResolver.test.ts @@ -0,0 +1,56 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { createTestClient } from 'apollo-server-testing' +import createServer from '@/server/createServer' +import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' +import CONFIG from '@/config' + +let query: any + +// to do: We need a setup for the tests that closes the connection +let con: any + +CONFIG.FEDERATION_API = '1_1' + +beforeAll(async () => { + const server = await createServer() + con = server.con + query = createTestClient(server.apollo).query + DbFederatedCommunity.clear() +}) + +afterAll(async () => { + await con.close() +}) + +describe('PublicKeyResolver', () => { + const getPublicKeyQuery = ` + query { + getPublicKey + { + publicKey + } + } + ` + + describe('getPublicKey', () => { + beforeEach(async () => { + const homeCom = new DbFederatedCommunity() + homeCom.foreign = false + homeCom.apiVersion = '1_0' + homeCom.endPoint = 'endpoint-url' + homeCom.publicKey = Buffer.from('homeCommunity-publicKey') + await DbFederatedCommunity.insert(homeCom) + }) + + it('returns homeCommunity-publicKey', async () => { + await expect(query({ query: getPublicKeyQuery })).resolves.toMatchObject({ + data: { + getPublicKey: { + publicKey: expect.stringMatching('homeCommunity-publicKey'), + }, + }, + }) + }) + }) +}) diff --git a/federation/src/graphql/api/1_1/resolver/PublicKeyResolver.ts b/federation/src/graphql/api/1_1/resolver/PublicKeyResolver.ts new file mode 100644 index 000000000..e03b36075 --- /dev/null +++ b/federation/src/graphql/api/1_1/resolver/PublicKeyResolver.ts @@ -0,0 +1,8 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { Resolver } from 'type-graphql' +// eslint-disable-next-line camelcase +import { PublicKeyResolver as PublicKeyResolver_1_0 } from '../../1_0/resolver/PublicKeyResolver' + +@Resolver() +// eslint-disable-next-line camelcase, @typescript-eslint/no-unused-vars +export class PublicKeyResolver extends PublicKeyResolver_1_0 {} diff --git a/federation/src/graphql/api/1_1/resolver/TestResolver.test.ts b/federation/src/graphql/api/1_1/resolver/TestResolver.test.ts deleted file mode 100644 index ad08345a7..000000000 --- a/federation/src/graphql/api/1_1/resolver/TestResolver.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { createTestClient } from 'apollo-server-testing' -import createServer from '@/server/createServer' -import CONFIG from '@/config' - -CONFIG.FEDERATION_API = '1_1' - -let query: any - -// to do: We need a setup for the tests that closes the connection -let con: any - -beforeAll(async () => { - const server = await createServer() - con = server.con - query = createTestClient(server.apollo).query -}) - -afterAll(async () => { - await con.close() -}) - -describe('TestResolver', () => { - const getTestQuery = ` - query { - test { - api - } - } - ` - - describe('getTestApi', () => { - it('returns 1_1', async () => { - await expect(query({ query: getTestQuery })).resolves.toMatchObject({ - data: { - test: { - api: '1_1', - }, - }, - }) - }) - }) -}) diff --git a/federation/src/graphql/api/1_1/resolver/TestResolver.ts b/federation/src/graphql/api/1_1/resolver/TestResolver.ts deleted file mode 100644 index 74e02b74a..000000000 --- a/federation/src/graphql/api/1_1/resolver/TestResolver.ts +++ /dev/null @@ -1,14 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Query, Resolver } from 'type-graphql' -import { federationLogger as logger } from '@/server/logger' -import { GetTestApiResult } from '../../GetTestApiResult' - -@Resolver() -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export class TestResolver { - @Query(() => GetTestApiResult) - async test(): Promise { - logger.info(`test api 1_1`) - return new GetTestApiResult('1_1') - } -} diff --git a/federation/src/graphql/api/2_0/resolver/TestResolver.test.ts b/federation/src/graphql/api/2_0/resolver/TestResolver.test.ts deleted file mode 100644 index 02fd8c358..000000000 --- a/federation/src/graphql/api/2_0/resolver/TestResolver.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { createTestClient } from 'apollo-server-testing' -import createServer from '@/server/createServer' -import CONFIG from '@/config' - -CONFIG.FEDERATION_API = '2_0' - -let query: any - -// to do: We need a setup for the tests that closes the connection -let con: any - -beforeAll(async () => { - const server = await createServer() - con = server.con - query = createTestClient(server.apollo).query -}) - -afterAll(async () => { - await con.close() -}) - -describe('TestResolver', () => { - const getTestQuery = ` - query { - test { - api - } - } - ` - - describe('getTestApi', () => { - it('returns 2_0', async () => { - await expect(query({ query: getTestQuery })).resolves.toMatchObject({ - data: { - test: { - api: '2_0', - }, - }, - }) - }) - }) -}) diff --git a/federation/src/graphql/api/2_0/resolver/TestResolver.ts b/federation/src/graphql/api/2_0/resolver/TestResolver.ts deleted file mode 100644 index 4202bbbfe..000000000 --- a/federation/src/graphql/api/2_0/resolver/TestResolver.ts +++ /dev/null @@ -1,14 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Query, Resolver } from 'type-graphql' -import { federationLogger as logger } from '@/server/logger' -import { GetTestApiResult } from '../../GetTestApiResult' - -@Resolver() -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export class TestResolver { - @Query(() => GetTestApiResult) - async test(): Promise { - logger.info(`test api 2_0`) - return new GetTestApiResult('2_0') - } -} diff --git a/federation/src/graphql/api/GetTestApiResult.ts b/federation/src/graphql/api/GetTestApiResult.ts deleted file mode 100644 index 942ff7b6c..000000000 --- a/federation/src/graphql/api/GetTestApiResult.ts +++ /dev/null @@ -1,13 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Field, ObjectType } from 'type-graphql' - -@ObjectType() -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export class GetTestApiResult { - constructor(apiVersion: string) { - this.api = apiVersion - } - - @Field(() => String) - api: string -} diff --git a/federation/src/graphql/scalar/Decimal.ts b/federation/src/graphql/scalar/Decimal.ts.unused similarity index 100% rename from federation/src/graphql/scalar/Decimal.ts rename to federation/src/graphql/scalar/Decimal.ts.unused diff --git a/federation/src/graphql/schema.ts b/federation/src/graphql/schema.ts index 92977882b..015ea124f 100644 --- a/federation/src/graphql/schema.ts +++ b/federation/src/graphql/schema.ts @@ -2,15 +2,15 @@ import { GraphQLSchema } from 'graphql' import { buildSchema } from 'type-graphql' // import isAuthorized from './directive/isAuthorized' -import DecimalScalar from './scalar/Decimal' -import Decimal from 'decimal.js-light' +// import DecimalScalar from './scalar/Decimal' +// import Decimal from 'decimal.js-light' import { getApiResolvers } from './api/schema' const schema = async (): Promise => { return await buildSchema({ resolvers: [getApiResolvers()], // authChecker: isAuthorized, - scalarsMap: [{ type: Decimal, scalar: DecimalScalar }], + // scalarsMap: [{ type: Decimal, scalar: DecimalScalar }], }) }