From 6327eb6c577cdf36c8f44b55bac8195f7d6a6335 Mon Sep 17 00:00:00 2001 From: "IceHe.Life" Date: Fri, 5 Aug 2022 23:42:16 +0800 Subject: [PATCH] refactor(core,schemas,ui): fix non-consistent type definitions (#1742) --- packages/core/src/lib/social.ts | 6 +- .../core/src/middleware/koa-pagination.ts | 11 ++- packages/core/src/queries/log.ts | 6 +- .../src/utils/oidc-provider-event-listener.ts | 6 +- packages/schemas/src/types/log.ts | 71 +++++++++---------- packages/ui/src/types/index.ts | 6 +- 6 files changed, 45 insertions(+), 61 deletions(-) diff --git a/packages/core/src/lib/social.ts b/packages/core/src/lib/social.ts index a725c3172..fc0cc1f21 100644 --- a/packages/core/src/lib/social.ts +++ b/packages/core/src/lib/social.ts @@ -14,12 +14,10 @@ import { } from '@/queries/user'; import assertThat from '@/utils/assert-that'; -// FIXME: @Darcy -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export interface SocialUserInfoSession { +export type SocialUserInfoSession = { connectorId: string; userInfo: SocialUserInfo; -} +}; const getConnector = async (connectorId: string) => { try { diff --git a/packages/core/src/middleware/koa-pagination.ts b/packages/core/src/middleware/koa-pagination.ts index 684ff085c..ed093e136 100644 --- a/packages/core/src/middleware/koa-pagination.ts +++ b/packages/core/src/middleware/koa-pagination.ts @@ -1,5 +1,3 @@ -// FIXME: @sijie -/* eslint-disable @typescript-eslint/consistent-type-definitions */ import { MiddlewareType } from 'koa'; import { IMiddleware } from 'koa-router'; import { number } from 'zod'; @@ -7,20 +5,20 @@ import { number } from 'zod'; import RequestError from '@/errors/RequestError'; import { buildLink } from '@/utils/pagination'; -export interface Pagination { +export type Pagination = { offset: number; limit: number; totalCount?: number; -} +}; export type WithPaginationContext = ContextT & { pagination: Pagination; }; -export interface PaginationConfig { +export type PaginationConfig = { defaultPageSize?: number; maxPageSize?: number; -} +}; export const isPaginationMiddleware = ( function_: Type @@ -84,4 +82,3 @@ export default function koaPagination({ return paginationMiddleware; } -/* eslint-enable @typescript-eslint/consistent-type-definitions */ diff --git a/packages/core/src/queries/log.ts b/packages/core/src/queries/log.ts index 62c33aff8..ee3445594 100644 --- a/packages/core/src/queries/log.ts +++ b/packages/core/src/queries/log.ts @@ -10,13 +10,11 @@ const { table, fields } = convertToIdentifiers(Logs); export const insertLog = buildInsertInto(Logs); -// FIXME: @IceHe -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export interface LogCondition { +export type LogCondition = { logType?: string; applicationId?: string; userId?: string; -} +}; const buildLogConditionSql = (logCondition: LogCondition) => conditionalSql(logCondition, ({ logType, applicationId, userId }) => { diff --git a/packages/core/src/utils/oidc-provider-event-listener.ts b/packages/core/src/utils/oidc-provider-event-listener.ts index e21a188fa..812380245 100644 --- a/packages/core/src/utils/oidc-provider-event-listener.ts +++ b/packages/core/src/utils/oidc-provider-event-listener.ts @@ -21,14 +21,12 @@ export const addOidcEventListeners = (provider: Provider) => { * - https://github.com/panva/node-oidc-provider/blob/564b1095ee869c89381d63dfdb5875c99f870f5f/lib/actions/grants/refresh_token.js#L225 * - …… */ -// FIXME: @IceHe -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -interface GrantBody { +type GrantBody = { access_token?: string; refresh_token?: string; id_token?: string; scope?: string; // AccessToken.scope -} +}; const getLogType = (grantType: unknown) => { const allowedGrantType = new Set([GrantType.AuthorizationCode, GrantType.RefreshToken]); diff --git a/packages/schemas/src/types/log.ts b/packages/schemas/src/types/log.ts index 989ba04f0..c65cc07a7 100644 --- a/packages/schemas/src/types/log.ts +++ b/packages/schemas/src/types/log.ts @@ -1,5 +1,3 @@ -// FIXME: @IceHe -/* eslint-disable @typescript-eslint/consistent-type-definitions */ import { Log } from '../db-entries'; export enum LogResult { @@ -7,96 +5,96 @@ export enum LogResult { Error = 'Error', } -export interface BaseLogPayload { +export type BaseLogPayload = { result?: LogResult; error?: Record; ip?: string; userAgent?: string; applicationId?: string; sessionId?: string; -} +}; type ArbitraryLogPayload = Record; -interface RegisterUsernamePasswordLogPayload extends ArbitraryLogPayload { +type RegisterUsernamePasswordLogPayload = ArbitraryLogPayload & { userId?: string; username?: string; -} +}; -interface RegisterEmailSendPasscodeLogPayload extends ArbitraryLogPayload { +type RegisterEmailSendPasscodeLogPayload = ArbitraryLogPayload & { email?: string; connectorId?: string; -} +}; -interface RegisterEmailLogPayload extends ArbitraryLogPayload { +type RegisterEmailLogPayload = ArbitraryLogPayload & { email?: string; code?: string; userId?: string; -} +}; -interface RegisterSmsSendPasscodeLogPayload extends ArbitraryLogPayload { +type RegisterSmsSendPasscodeLogPayload = { phone?: string; connectorId?: string; -} +} & ArbitraryLogPayload; -interface RegisterSmsLogPayload extends ArbitraryLogPayload { +type RegisterSmsLogPayload = ArbitraryLogPayload & { phone?: string; code?: string; userId?: string; -} +}; -interface RegisterSocialBindLogPayload extends ArbitraryLogPayload { +type RegisterSocialBindLogPayload = ArbitraryLogPayload & { connectorId?: string; userInfo?: object; userId?: string; -} +}; -interface RegisterSocialLogPayload extends RegisterSocialBindLogPayload { +type RegisterSocialLogPayload = RegisterSocialBindLogPayload & { code?: string; state?: string; redirectUri?: string; redirectTo?: string; -} +}; -interface SignInUsernamePasswordLogPayload extends ArbitraryLogPayload { +type SignInUsernamePasswordLogPayload = ArbitraryLogPayload & { userId?: string; username?: string; -} +}; -interface SignInEmailSendPasscodeLogPayload extends ArbitraryLogPayload { +type SignInEmailSendPasscodeLogPayload = ArbitraryLogPayload & { email?: string; connectorId?: string; -} +}; -interface SignInEmailLogPayload extends ArbitraryLogPayload { +type SignInEmailLogPayload = ArbitraryLogPayload & { email?: string; code?: string; userId?: string; -} +}; -interface SignInSmsSendPasscodeLogPayload extends ArbitraryLogPayload { +type SignInSmsSendPasscodeLogPayload = ArbitraryLogPayload & { phone?: string; connectorId?: string; -} +}; -interface SignInSmsLogPayload extends ArbitraryLogPayload { +type SignInSmsLogPayload = ArbitraryLogPayload & { phone?: string; code?: string; userId?: string; -} +}; -interface SignInSocialBindLogPayload extends ArbitraryLogPayload { +type SignInSocialBindLogPayload = ArbitraryLogPayload & { connectorId?: string; userInfo?: object; userId?: string; -} +}; -interface SignInSocialLogPayload extends SignInSocialBindLogPayload { +type SignInSocialLogPayload = SignInSocialBindLogPayload & { code?: string; state?: string; redirectUri?: string; redirectTo?: string; -} +}; export enum TokenType { AccessToken = 'AccessToken', @@ -104,19 +102,19 @@ export enum TokenType { IdToken = 'IdToken', } -interface ExchangeTokenLogPayload extends ArbitraryLogPayload { +type ExchangeTokenLogPayload = ArbitraryLogPayload & { userId?: string; params?: Record; issued?: TokenType[]; scope?: string; -} +}; -interface RevokeTokenLogPayload extends ArbitraryLogPayload { +type RevokeTokenLogPayload = ArbitraryLogPayload & { userId?: string; params?: Record; grantId?: string; tokenType?: TokenType; -} +}; export type LogPayloads = { RegisterUsernamePassword: RegisterUsernamePasswordLogPayload; @@ -151,4 +149,3 @@ export type LogDto = Omit & { ip?: string; }; }; -/* eslint-enable @typescript-eslint/consistent-type-definitions */ diff --git a/packages/ui/src/types/index.ts b/packages/ui/src/types/index.ts index d527c594f..6bef60d3f 100644 --- a/packages/ui/src/types/index.ts +++ b/packages/ui/src/types/index.ts @@ -15,11 +15,7 @@ export type Platform = 'web' | 'mobile'; export type Theme = 'dark' | 'light'; -// FIXME: @Darcy -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export interface ConnectorData extends ConnectorMetadata { - id: string; -} +export type ConnectorData = ConnectorMetadata & { id: string }; export type SignInExperienceSettingsResponse = SignInExperience & { socialConnectors: ConnectorData[];