mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
refactor(core,schemas,ui): fix non-consistent type definitions (#1742)
This commit is contained in:
parent
f0347a7a6f
commit
6327eb6c57
6 changed files with 45 additions and 61 deletions
|
@ -14,12 +14,10 @@ import {
|
||||||
} from '@/queries/user';
|
} from '@/queries/user';
|
||||||
import assertThat from '@/utils/assert-that';
|
import assertThat from '@/utils/assert-that';
|
||||||
|
|
||||||
// FIXME: @Darcy
|
export type SocialUserInfoSession = {
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
||||||
export interface SocialUserInfoSession {
|
|
||||||
connectorId: string;
|
connectorId: string;
|
||||||
userInfo: SocialUserInfo;
|
userInfo: SocialUserInfo;
|
||||||
}
|
};
|
||||||
|
|
||||||
const getConnector = async (connectorId: string) => {
|
const getConnector = async (connectorId: string) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// FIXME: @sijie
|
|
||||||
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
|
||||||
import { MiddlewareType } from 'koa';
|
import { MiddlewareType } from 'koa';
|
||||||
import { IMiddleware } from 'koa-router';
|
import { IMiddleware } from 'koa-router';
|
||||||
import { number } from 'zod';
|
import { number } from 'zod';
|
||||||
|
@ -7,20 +5,20 @@ import { number } from 'zod';
|
||||||
import RequestError from '@/errors/RequestError';
|
import RequestError from '@/errors/RequestError';
|
||||||
import { buildLink } from '@/utils/pagination';
|
import { buildLink } from '@/utils/pagination';
|
||||||
|
|
||||||
export interface Pagination {
|
export type Pagination = {
|
||||||
offset: number;
|
offset: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
totalCount?: number;
|
totalCount?: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type WithPaginationContext<ContextT> = ContextT & {
|
export type WithPaginationContext<ContextT> = ContextT & {
|
||||||
pagination: Pagination;
|
pagination: Pagination;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface PaginationConfig {
|
export type PaginationConfig = {
|
||||||
defaultPageSize?: number;
|
defaultPageSize?: number;
|
||||||
maxPageSize?: number;
|
maxPageSize?: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const isPaginationMiddleware = <Type extends IMiddleware>(
|
export const isPaginationMiddleware = <Type extends IMiddleware>(
|
||||||
function_: Type
|
function_: Type
|
||||||
|
@ -84,4 +82,3 @@ export default function koaPagination<StateT, ContextT, ResponseBodyT>({
|
||||||
|
|
||||||
return paginationMiddleware;
|
return paginationMiddleware;
|
||||||
}
|
}
|
||||||
/* eslint-enable @typescript-eslint/consistent-type-definitions */
|
|
||||||
|
|
|
@ -10,13 +10,11 @@ const { table, fields } = convertToIdentifiers(Logs);
|
||||||
|
|
||||||
export const insertLog = buildInsertInto<CreateLog>(Logs);
|
export const insertLog = buildInsertInto<CreateLog>(Logs);
|
||||||
|
|
||||||
// FIXME: @IceHe
|
export type LogCondition = {
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
||||||
export interface LogCondition {
|
|
||||||
logType?: string;
|
logType?: string;
|
||||||
applicationId?: string;
|
applicationId?: string;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
const buildLogConditionSql = (logCondition: LogCondition) =>
|
const buildLogConditionSql = (logCondition: LogCondition) =>
|
||||||
conditionalSql(logCondition, ({ logType, applicationId, userId }) => {
|
conditionalSql(logCondition, ({ logType, applicationId, userId }) => {
|
||||||
|
|
|
@ -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
|
* - https://github.com/panva/node-oidc-provider/blob/564b1095ee869c89381d63dfdb5875c99f870f5f/lib/actions/grants/refresh_token.js#L225
|
||||||
* - ……
|
* - ……
|
||||||
*/
|
*/
|
||||||
// FIXME: @IceHe
|
type GrantBody = {
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
||||||
interface GrantBody {
|
|
||||||
access_token?: string;
|
access_token?: string;
|
||||||
refresh_token?: string;
|
refresh_token?: string;
|
||||||
id_token?: string;
|
id_token?: string;
|
||||||
scope?: string; // AccessToken.scope
|
scope?: string; // AccessToken.scope
|
||||||
}
|
};
|
||||||
|
|
||||||
const getLogType = (grantType: unknown) => {
|
const getLogType = (grantType: unknown) => {
|
||||||
const allowedGrantType = new Set<unknown>([GrantType.AuthorizationCode, GrantType.RefreshToken]);
|
const allowedGrantType = new Set<unknown>([GrantType.AuthorizationCode, GrantType.RefreshToken]);
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// FIXME: @IceHe
|
|
||||||
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
|
||||||
import { Log } from '../db-entries';
|
import { Log } from '../db-entries';
|
||||||
|
|
||||||
export enum LogResult {
|
export enum LogResult {
|
||||||
|
@ -7,96 +5,96 @@ export enum LogResult {
|
||||||
Error = 'Error',
|
Error = 'Error',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BaseLogPayload {
|
export type BaseLogPayload = {
|
||||||
result?: LogResult;
|
result?: LogResult;
|
||||||
error?: Record<string, unknown>;
|
error?: Record<string, unknown>;
|
||||||
ip?: string;
|
ip?: string;
|
||||||
userAgent?: string;
|
userAgent?: string;
|
||||||
applicationId?: string;
|
applicationId?: string;
|
||||||
sessionId?: string;
|
sessionId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
type ArbitraryLogPayload = Record<string, unknown>;
|
type ArbitraryLogPayload = Record<string, unknown>;
|
||||||
|
|
||||||
interface RegisterUsernamePasswordLogPayload extends ArbitraryLogPayload {
|
type RegisterUsernamePasswordLogPayload = ArbitraryLogPayload & {
|
||||||
userId?: string;
|
userId?: string;
|
||||||
username?: string;
|
username?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface RegisterEmailSendPasscodeLogPayload extends ArbitraryLogPayload {
|
type RegisterEmailSendPasscodeLogPayload = ArbitraryLogPayload & {
|
||||||
email?: string;
|
email?: string;
|
||||||
connectorId?: string;
|
connectorId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface RegisterEmailLogPayload extends ArbitraryLogPayload {
|
type RegisterEmailLogPayload = ArbitraryLogPayload & {
|
||||||
email?: string;
|
email?: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface RegisterSmsSendPasscodeLogPayload extends ArbitraryLogPayload {
|
type RegisterSmsSendPasscodeLogPayload = {
|
||||||
phone?: string;
|
phone?: string;
|
||||||
connectorId?: string;
|
connectorId?: string;
|
||||||
}
|
} & ArbitraryLogPayload;
|
||||||
|
|
||||||
interface RegisterSmsLogPayload extends ArbitraryLogPayload {
|
type RegisterSmsLogPayload = ArbitraryLogPayload & {
|
||||||
phone?: string;
|
phone?: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface RegisterSocialBindLogPayload extends ArbitraryLogPayload {
|
type RegisterSocialBindLogPayload = ArbitraryLogPayload & {
|
||||||
connectorId?: string;
|
connectorId?: string;
|
||||||
userInfo?: object;
|
userInfo?: object;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface RegisterSocialLogPayload extends RegisterSocialBindLogPayload {
|
type RegisterSocialLogPayload = RegisterSocialBindLogPayload & {
|
||||||
code?: string;
|
code?: string;
|
||||||
state?: string;
|
state?: string;
|
||||||
redirectUri?: string;
|
redirectUri?: string;
|
||||||
redirectTo?: string;
|
redirectTo?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface SignInUsernamePasswordLogPayload extends ArbitraryLogPayload {
|
type SignInUsernamePasswordLogPayload = ArbitraryLogPayload & {
|
||||||
userId?: string;
|
userId?: string;
|
||||||
username?: string;
|
username?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface SignInEmailSendPasscodeLogPayload extends ArbitraryLogPayload {
|
type SignInEmailSendPasscodeLogPayload = ArbitraryLogPayload & {
|
||||||
email?: string;
|
email?: string;
|
||||||
connectorId?: string;
|
connectorId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface SignInEmailLogPayload extends ArbitraryLogPayload {
|
type SignInEmailLogPayload = ArbitraryLogPayload & {
|
||||||
email?: string;
|
email?: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface SignInSmsSendPasscodeLogPayload extends ArbitraryLogPayload {
|
type SignInSmsSendPasscodeLogPayload = ArbitraryLogPayload & {
|
||||||
phone?: string;
|
phone?: string;
|
||||||
connectorId?: string;
|
connectorId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface SignInSmsLogPayload extends ArbitraryLogPayload {
|
type SignInSmsLogPayload = ArbitraryLogPayload & {
|
||||||
phone?: string;
|
phone?: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface SignInSocialBindLogPayload extends ArbitraryLogPayload {
|
type SignInSocialBindLogPayload = ArbitraryLogPayload & {
|
||||||
connectorId?: string;
|
connectorId?: string;
|
||||||
userInfo?: object;
|
userInfo?: object;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface SignInSocialLogPayload extends SignInSocialBindLogPayload {
|
type SignInSocialLogPayload = SignInSocialBindLogPayload & {
|
||||||
code?: string;
|
code?: string;
|
||||||
state?: string;
|
state?: string;
|
||||||
redirectUri?: string;
|
redirectUri?: string;
|
||||||
redirectTo?: string;
|
redirectTo?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export enum TokenType {
|
export enum TokenType {
|
||||||
AccessToken = 'AccessToken',
|
AccessToken = 'AccessToken',
|
||||||
|
@ -104,19 +102,19 @@ export enum TokenType {
|
||||||
IdToken = 'IdToken',
|
IdToken = 'IdToken',
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ExchangeTokenLogPayload extends ArbitraryLogPayload {
|
type ExchangeTokenLogPayload = ArbitraryLogPayload & {
|
||||||
userId?: string;
|
userId?: string;
|
||||||
params?: Record<string, unknown>;
|
params?: Record<string, unknown>;
|
||||||
issued?: TokenType[];
|
issued?: TokenType[];
|
||||||
scope?: string;
|
scope?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface RevokeTokenLogPayload extends ArbitraryLogPayload {
|
type RevokeTokenLogPayload = ArbitraryLogPayload & {
|
||||||
userId?: string;
|
userId?: string;
|
||||||
params?: Record<string, unknown>;
|
params?: Record<string, unknown>;
|
||||||
grantId?: string;
|
grantId?: string;
|
||||||
tokenType?: TokenType;
|
tokenType?: TokenType;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type LogPayloads = {
|
export type LogPayloads = {
|
||||||
RegisterUsernamePassword: RegisterUsernamePasswordLogPayload;
|
RegisterUsernamePassword: RegisterUsernamePasswordLogPayload;
|
||||||
|
@ -151,4 +149,3 @@ export type LogDto = Omit<Log, 'payload'> & {
|
||||||
ip?: string;
|
ip?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
/* eslint-enable @typescript-eslint/consistent-type-definitions */
|
|
||||||
|
|
|
@ -15,11 +15,7 @@ export type Platform = 'web' | 'mobile';
|
||||||
|
|
||||||
export type Theme = 'dark' | 'light';
|
export type Theme = 'dark' | 'light';
|
||||||
|
|
||||||
// FIXME: @Darcy
|
export type ConnectorData = ConnectorMetadata & { id: string };
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
||||||
export interface ConnectorData extends ConnectorMetadata {
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SignInExperienceSettingsResponse = SignInExperience & {
|
export type SignInExperienceSettingsResponse = SignInExperience & {
|
||||||
socialConnectors: ConnectorData[];
|
socialConnectors: ConnectorData[];
|
||||||
|
|
Loading…
Add table
Reference in a new issue