From 61e6e79497d8eb8bd8c507c5b663e72e22dfe790 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Thu, 8 Oct 2020 22:21:37 +0800 Subject: [PATCH] shared: types: move API types to api folder --- client/src/javascript/actions/AuthActions.ts | 4 +-- .../src/javascript/actions/TorrentActions.ts | 2 +- .../move-torrents-modal/MoveTorrentsModal.tsx | 2 +- .../src/javascript/constants/ServerActions.ts | 3 ++- client/src/javascript/stores/AuthStore.ts | 3 ++- server/routes/api/auth.ts | 3 ++- server/routes/api/torrents.ts | 2 +- server/services/clientGatewayService.ts | 2 +- shared/types/Auth.ts | 26 ------------------ shared/types/api/auth.ts | 27 +++++++++++++++++++ shared/types/{Action.ts => api/torrents.ts} | 2 +- 11 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 shared/types/api/auth.ts rename shared/types/{Action.ts => api/torrents.ts} (98%) diff --git a/client/src/javascript/actions/AuthActions.ts b/client/src/javascript/actions/AuthActions.ts index 0bf1cba6..d323dbb4 100644 --- a/client/src/javascript/actions/AuthActions.ts +++ b/client/src/javascript/actions/AuthActions.ts @@ -5,8 +5,8 @@ import type { AuthRegisterOptions, AuthUpdateUserOptions, AuthVerificationResponse, - Credentials, -} from '@shared/types/Auth'; +} from '@shared/types/api/auth'; +import type {Credentials} from '@shared/types/Auth'; import AppDispatcher from '../dispatcher/AppDispatcher'; import ClientActions from './ClientActions'; diff --git a/client/src/javascript/actions/TorrentActions.ts b/client/src/javascript/actions/TorrentActions.ts index 665d057a..16f9a34e 100644 --- a/client/src/javascript/actions/TorrentActions.ts +++ b/client/src/javascript/actions/TorrentActions.ts @@ -11,7 +11,7 @@ import type { SetTorrentsTagsOptions, StartTorrentsOptions, StopTorrentsOptions, -} from '@shared/types/Action'; +} from '@shared/types/api/torrents'; import type {TorrentProperties} from '@shared/types/Torrent'; import AppDispatcher from '../dispatcher/AppDispatcher'; diff --git a/client/src/javascript/components/modals/move-torrents-modal/MoveTorrentsModal.tsx b/client/src/javascript/components/modals/move-torrents-modal/MoveTorrentsModal.tsx index f67cae30..be103231 100644 --- a/client/src/javascript/components/modals/move-torrents-modal/MoveTorrentsModal.tsx +++ b/client/src/javascript/components/modals/move-torrents-modal/MoveTorrentsModal.tsx @@ -1,7 +1,7 @@ import {injectIntl, WrappedComponentProps} from 'react-intl'; import React from 'react'; -import type {MoveTorrentsOptions} from '@shared/types/Action'; +import type {MoveTorrentsOptions} from '@shared/types/api/torrents'; import {Form} from '../../../ui'; import Modal from '../Modal'; diff --git a/client/src/javascript/constants/ServerActions.ts b/client/src/javascript/constants/ServerActions.ts index e5d327ce..ded8c734 100644 --- a/client/src/javascript/constants/ServerActions.ts +++ b/client/src/javascript/constants/ServerActions.ts @@ -1,4 +1,5 @@ -import type {AuthAuthenticationResponse, AuthVerificationResponse, Credentials} from '@shared/types/Auth'; +import type {AuthAuthenticationResponse, AuthVerificationResponse} from '@shared/types/api/auth'; +import type {Credentials} from '@shared/types/Auth'; import type {ClientSettings} from '@shared/constants/clientSettingsMap'; import type {NotificationFetchOptions, NotificationState} from '@shared/types/Notification'; import type {ServerEvents} from '@shared/types/ServerEvents'; diff --git a/client/src/javascript/stores/AuthStore.ts b/client/src/javascript/stores/AuthStore.ts index e5edc51a..4971f1b9 100644 --- a/client/src/javascript/stores/AuthStore.ts +++ b/client/src/javascript/stores/AuthStore.ts @@ -1,4 +1,5 @@ -import type {AuthAuthenticationResponse, AuthVerificationResponse, Credentials} from '@shared/types/Auth'; +import type {AuthAuthenticationResponse, AuthVerificationResponse} from '@shared/types/api/auth'; +import type {Credentials} from '@shared/types/Auth'; import AppDispatcher from '../dispatcher/AppDispatcher'; import BaseStore from './BaseStore'; diff --git a/server/routes/api/auth.ts b/server/routes/api/auth.ts index 8564eb26..9934b00a 100644 --- a/server/routes/api/auth.ts +++ b/server/routes/api/auth.ts @@ -4,7 +4,8 @@ import jwt from 'jsonwebtoken'; import passport from 'passport'; import type {Response} from 'express'; -import type {AuthRegisterOptions, AuthUpdateUserOptions, Credentials} from '@shared/types/Auth'; +import type {AuthRegisterOptions, AuthUpdateUserOptions} from '@shared/types/api/auth'; +import type {Credentials} from '@shared/types/Auth'; import ajaxUtil from '../../util/ajaxUtil'; import config from '../../../config'; diff --git a/server/routes/api/torrents.ts b/server/routes/api/torrents.ts index 88617fd0..5d07cc0e 100644 --- a/server/routes/api/torrents.ts +++ b/server/routes/api/torrents.ts @@ -11,7 +11,7 @@ import { SetTorrentsTagsOptions, StartTorrentsOptions, StopTorrentsOptions, -} from '@shared/types/Action'; +} from '@shared/types/api/torrents'; import ajaxUtil from '../../util/ajaxUtil'; import client from '../../models/client'; diff --git a/server/services/clientGatewayService.ts b/server/services/clientGatewayService.ts index 27366171..67aaacb4 100644 --- a/server/services/clientGatewayService.ts +++ b/server/services/clientGatewayService.ts @@ -16,7 +16,7 @@ import type { SetTorrentsTagsOptions, StartTorrentsOptions, StopTorrentsOptions, -} from '@shared/types/Action'; +} from '@shared/types/api/torrents'; import {accessDeniedError, createDirectory, isAllowedPath, sanitizePath} from '../util/fileUtil'; import BaseService from './BaseService'; diff --git a/shared/types/Auth.ts b/shared/types/Auth.ts index 478959ab..102c76a3 100644 --- a/shared/types/Auth.ts +++ b/shared/types/Auth.ts @@ -15,29 +15,3 @@ export interface Credentials { } export type UserInDatabase = Required & {_id: string}; - -// POST /api/auth/authenticate -export type AuthAuthenticationOptions = Required>; - -// POST /api/auth/authenticate - success response -export interface AuthAuthenticationResponse { - success: boolean; - token: string; - username: string; - isAdmin: boolean; -} - -// POST /api/auth/register -export type AuthRegisterOptions = Required< - Pick ->; - -// PATCH /api/auth/users/{username} -export type AuthUpdateUserOptions = Partial; - -// GET /api/auth/verify - success response -export interface AuthVerificationResponse extends Pick { - initialUser: boolean; - username: string; - isAdmin: boolean; -} diff --git a/shared/types/api/auth.ts b/shared/types/api/auth.ts new file mode 100644 index 00000000..837ce078 --- /dev/null +++ b/shared/types/api/auth.ts @@ -0,0 +1,27 @@ +import type {Credentials} from '../Auth'; + +// POST /api/auth/authenticate +export type AuthAuthenticationOptions = Required>; + +// POST /api/auth/authenticate - success response +export interface AuthAuthenticationResponse { + success: boolean; + token: string; + username: string; + isAdmin: boolean; +} + +// POST /api/auth/register +export type AuthRegisterOptions = Required< + Pick +>; + +// PATCH /api/auth/users/{username} +export type AuthUpdateUserOptions = Partial; + +// GET /api/auth/verify - success response +export interface AuthVerificationResponse extends Pick { + initialUser: boolean; + username: string; + isAdmin: boolean; +} diff --git a/shared/types/Action.ts b/shared/types/api/torrents.ts similarity index 98% rename from shared/types/Action.ts rename to shared/types/api/torrents.ts index 5b0e6304..a137a6db 100644 --- a/shared/types/Action.ts +++ b/shared/types/api/torrents.ts @@ -1,4 +1,4 @@ -import {TorrentProperties} from './Torrent'; +import {TorrentProperties} from '../Torrent'; // POST /api/torrents/add-urls export interface AddTorrentByURLOptions {