From 88a56b85690721476a968da44dfa0f09196ef333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Thu, 29 Apr 2021 09:57:45 +0200 Subject: [PATCH] fix: move AuthenticationRequired to types --- src/lib/authentication-required.js | 10 ------- src/lib/middleware/demo-authentication.js | 2 +- src/lib/middleware/oss-authentication.js | 2 +- src/lib/server-impl.ts | 2 +- src/lib/types/authentication-required.ts | 29 +++++++++++++++++++ .../api/admin/feature.custom-auth.e2e.test.js | 2 +- 6 files changed, 33 insertions(+), 14 deletions(-) delete mode 100644 src/lib/authentication-required.js create mode 100644 src/lib/types/authentication-required.ts diff --git a/src/lib/authentication-required.js b/src/lib/authentication-required.js deleted file mode 100644 index 4f6d97689c..0000000000 --- a/src/lib/authentication-required.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -module.exports = class AuthenticationRequired { - constructor({ type, path, message, options }) { - this.type = type; - this.path = path; - this.message = message; - this.options = options; - } -}; diff --git a/src/lib/middleware/demo-authentication.js b/src/lib/middleware/demo-authentication.js index c2be33eb61..ce2b477c7b 100644 --- a/src/lib/middleware/demo-authentication.js +++ b/src/lib/middleware/demo-authentication.js @@ -1,4 +1,4 @@ -const AuthenticationRequired = require('../authentication-required'); +const AuthenticationRequired = require('../types/authentication-required'); function demoAuthentication(app, basePath = '', { userService }) { app.post(`${basePath}/api/admin/login`, async (req, res) => { diff --git a/src/lib/middleware/oss-authentication.js b/src/lib/middleware/oss-authentication.js index 38481ecc21..2f49700b95 100644 --- a/src/lib/middleware/oss-authentication.js +++ b/src/lib/middleware/oss-authentication.js @@ -1,4 +1,4 @@ -const AuthenticationRequired = require('../authentication-required'); +const AuthenticationRequired = require('../types/authentication-required'); function ossAuthHook(app, config) { const { baseUriPath } = config.server; diff --git a/src/lib/server-impl.ts b/src/lib/server-impl.ts index 4a46bc6475..5ca219cc15 100644 --- a/src/lib/server-impl.ts +++ b/src/lib/server-impl.ts @@ -13,7 +13,7 @@ import { createConfig } from './create-config'; import User from './types/user'; import permissions from './permissions'; -import AuthenticationRequired from './authentication-required'; +import AuthenticationRequired from './types/authentication-required'; import eventType from './event-type'; import { addEventHook } from './event-hook'; diff --git a/src/lib/types/authentication-required.ts b/src/lib/types/authentication-required.ts new file mode 100644 index 0000000000..13ec89d5c4 --- /dev/null +++ b/src/lib/types/authentication-required.ts @@ -0,0 +1,29 @@ +interface IBaseOptions { + type: string; + path: string; + message: string; +} + +interface IOptions extends IBaseOptions { + options: IBaseOptions[]; +} + +class AuthenticationRequired { + private type: string; + + private path: string; + + private message: string; + + private options: IBaseOptions[]; + + constructor({ type, path, message, options }: IOptions) { + this.type = type; + this.path = path; + this.message = message; + this.options = options; + } +} + +export default AuthenticationRequired; +module.exports = AuthenticationRequired; diff --git a/src/test/e2e/api/admin/feature.custom-auth.e2e.test.js b/src/test/e2e/api/admin/feature.custom-auth.e2e.test.js index 81c721611f..f47781c2c3 100644 --- a/src/test/e2e/api/admin/feature.custom-auth.e2e.test.js +++ b/src/test/e2e/api/admin/feature.custom-auth.e2e.test.js @@ -2,7 +2,7 @@ const test = require('ava'); const { setupAppWithCustomAuth } = require('../../helpers/test-helper'); -const AuthenticationRequired = require('../../../../lib/authentication-required'); +const AuthenticationRequired = require('../../../../lib/types/authentication-required'); const dbInit = require('../../helpers/database-init'); const getLogger = require('../../../fixtures/no-logger');