0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(core): apply no-unused-modules (#4009)

This commit is contained in:
Gao Sun 2023-06-09 21:55:15 +08:00 committed by GitHub
parent a4cae18151
commit 2338cb692e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 30 additions and 115 deletions

View file

@ -116,8 +116,22 @@
"eslintConfig": { "eslintConfig": {
"extends": "@silverhand", "extends": "@silverhand",
"rules": { "rules": {
"no-console": "error" "no-console": "error",
} "import/no-unused-modules": [
"error",
{ "unusedExports": true }
]
},
"overrides": [
{
"files": [
"*.d.ts"
],
"rules": {
"import/no-unused-modules": "off"
}
}
]
}, },
"prettier": "@silverhand/eslint-config/.prettierrc" "prettier": "@silverhand/eslint-config/.prettierrc"
} }

View file

@ -1,4 +1,3 @@
import en from '@logto/phrases-ui/lib/locales/en/index.js';
import { type CustomPhrase } from '@logto/schemas'; import { type CustomPhrase } from '@logto/schemas';
import { mockId } from '#src/test-utils/nanoid.js'; import { mockId } from '#src/test-utils/nanoid.js';
@ -23,31 +22,6 @@ export const mockEnCustomPhrase = {
}, },
} satisfies CustomPhrase; } satisfies CustomPhrase;
export const mockEnPhrase = {
tenantId: 'fake_tenant',
id: mockId,
languageTag: enTag,
translation: {
...en.translation,
...mockEnCustomPhrase.translation,
},
} satisfies CustomPhrase;
export const mockTrTrCustomPhrase = {
tenantId: 'fake_tenant',
id: mockId,
languageTag: trTrTag,
translation: {
input: {
username: 'Kullanıcı Adı 1',
password: 'Şifre 2',
email: 'E-posta Adresi 3',
phone_number: 'Telefon Numarası 4',
confirm_password: 'Şifreyi Doğrula 5',
},
},
} satisfies CustomPhrase;
export const mockZhCnCustomPhrase = { export const mockZhCnCustomPhrase = {
tenantId: 'fake_tenant', tenantId: 'fake_tenant',
id: mockId, id: mockId,

View file

@ -1,26 +0,0 @@
export const interactionMocks = [
{
username: 'username',
password: 'password',
},
{
email: 'email',
password: 'password',
},
{
phone: 'phone',
password: 'password',
},
{
email: 'email@logto.io',
passcode: 'passcode',
},
{
phone: '123456',
passcode: 'passcode',
},
{
connectorId: 'connectorId',
connectorData: { code: 'code' },
},
];

View file

@ -14,7 +14,7 @@ type WellKnownMap = {
'custom-phrases-tags': string[]; 'custom-phrases-tags': string[];
}; };
export type WellKnownCacheType = keyof WellKnownMap; type WellKnownCacheType = keyof WellKnownMap;
/** /**
* The array tuple to determine how cache will be built. * The array tuple to determine how cache will be built.

View file

@ -1,2 +0,0 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function
export const checkAlterationState = async () => {};

View file

@ -30,7 +30,7 @@ export const getTenantEndpoint = (
return tenantUrl; return tenantUrl;
}; };
export const getTenantLocalhost = ( const getTenantLocalhost = (
id: string, id: string,
{ urlSet, adminUrlSet, isDomainBasedMultiTenancy, isPathBasedMultiTenancy }: GlobalValues { urlSet, adminUrlSet, isDomainBasedMultiTenancy, isPathBasedMultiTenancy }: GlobalValues
): Optional<URL> => { ): Optional<URL> => {

View file

@ -1,23 +0,0 @@
import { generateKeyPairSync } from 'node:crypto';
import type { LogtoOidcConfigType } from '@logto/schemas';
import { LogtoOidcConfigKey } from '@logto/schemas';
const { privateKey } = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
},
});
const getOidcConfigs = async (): Promise<LogtoOidcConfigType> => ({
[LogtoOidcConfigKey.PrivateKeys]: [privateKey],
[LogtoOidcConfigKey.CookieKeys]: ['LOGTOSEKRIT1'],
});
export const createLogtoConfigLibrary = () => ({ getOidcConfigs });

View file

@ -2,8 +2,6 @@ import type { Scope } from '@logto/schemas';
import type Queries from '#src/tenants/Queries.js'; import type Queries from '#src/tenants/Queries.js';
export type ApplicationLibrary = ReturnType<typeof createApplicationLibrary>;
export const createApplicationLibrary = (queries: Queries) => { export const createApplicationLibrary = (queries: Queries) => {
const { const {
applicationsRoles: { findApplicationsRolesByApplicationId }, applicationsRoles: { findApplicationsRolesByApplicationId },

View file

@ -2,12 +2,12 @@ import { connectorMetadataGuard, type ConnectorMetadata } from '@logto/connector
import { type SignInExperience, SignInExperiences } from '@logto/schemas'; import { type SignInExperience, SignInExperiences } from '@logto/schemas';
import { z } from 'zod'; import { z } from 'zod';
export type ForgotPassword = { type ForgotPassword = {
phone: boolean; phone: boolean;
email: boolean; email: boolean;
}; };
export type ConnectorMetadataWithId = ConnectorMetadata & { id: string }; type ConnectorMetadataWithId = ConnectorMetadata & { id: string };
export type FullSignInExperience = SignInExperience & { export type FullSignInExperience = SignInExperience & {
socialConnectors: ConnectorMetadataWithId[]; socialConnectors: ConnectorMetadataWithId[];

View file

@ -12,11 +12,6 @@ import type Queries from '#src/tenants/Queries.js';
import assertThat from '#src/utils/assert-that.js'; import assertThat from '#src/utils/assert-that.js';
import type { LogtoConnector } from '#src/utils/connectors/types.js'; import type { LogtoConnector } from '#src/utils/connectors/types.js';
export type SocialUserInfoSession = {
connectorId: string;
userInfo: SocialUserInfo;
};
const getUserInfoFromInteractionResult = async ( const getUserInfoFromInteractionResult = async (
connectorId: string, connectorId: string,
interactionResult: InteractionResults interactionResult: InteractionResults
@ -40,8 +35,6 @@ const getUserInfoFromInteractionResult = async (
return result.socialUserInfo.userInfo; return result.socialUserInfo.userInfo;
}; };
export type SocialLibrary = ReturnType<typeof createSocialLibrary>;
export const createSocialLibrary = (queries: Queries, connectorLibrary: ConnectorLibrary) => { export const createSocialLibrary = (queries: Queries, connectorLibrary: ConnectorLibrary) => {
const { findUserByEmail, findUserByPhone } = queries.users; const { findUserByEmail, findUserByPhone } = queries.users;
const { getLogtoConnectorById } = connectorLibrary; const { getLogtoConnectorById } = connectorLibrary;

View file

@ -5,8 +5,6 @@ import { verificationTimeout } from '#src/routes/consts.js';
import type Queries from '#src/tenants/Queries.js'; import type Queries from '#src/tenants/Queries.js';
import assertThat from '#src/utils/assert-that.js'; import assertThat from '#src/utils/assert-that.js';
export type VerificationStatusLibrary = ReturnType<typeof createVerificationStatusLibrary>;
export const createVerificationStatusLibrary = (queries: Queries) => { export const createVerificationStatusLibrary = (queries: Queries) => {
const { const {
findVerificationStatusByUserId, findVerificationStatusByUserId,

View file

@ -5,7 +5,7 @@ import { number } from 'zod';
import RequestError from '#src/errors/RequestError/index.js'; import RequestError from '#src/errors/RequestError/index.js';
import { buildLink } from '#src/utils/pagination.js'; import { buildLink } from '#src/utils/pagination.js';
export type Pagination = { type Pagination = {
offset: number; offset: number;
limit: number; limit: number;
totalCount?: number; totalCount?: number;
@ -16,7 +16,7 @@ export type WithPaginationContext<ContextT> = ContextT & {
pagination: Pagination; pagination: Pagination;
}; };
export type PaginationConfig = { type PaginationConfig = {
defaultPageSize?: number; defaultPageSize?: number;
maxPageSize?: number; maxPageSize?: number;
isOptional?: boolean; isOptional?: boolean;

View file

@ -4,7 +4,7 @@ import type { User } from '@logto/schemas';
import type { Nullable } from '@silverhand/essentials'; import type { Nullable } from '@silverhand/essentials';
import type { ClaimsParameterMember } from 'oidc-provider'; import type { ClaimsParameterMember } from 'oidc-provider';
export const claimToUserKey: Readonly< const claimToUserKey: Readonly<
Record<Exclude<UserClaim, 'email_verified' | 'phone_number_verified'>, keyof User> Record<Exclude<UserClaim, 'email_verified' | 'phone_number_verified'>, keyof User>
> = Object.freeze({ > = Object.freeze({
name: 'name', name: 'name',

View file

@ -10,7 +10,7 @@ import { buildInsertIntoWithPool } from '#src/database/insert-into.js';
const { table, fields } = convertToIdentifiers(Logs); const { table, fields } = convertToIdentifiers(Logs);
export type LogCondition = { type LogCondition = {
logKey?: string; logKey?: string;
applicationId?: string; applicationId?: string;
userId?: string; userId?: string;

View file

@ -20,7 +20,6 @@ import type {
verifiedRegisterInteractionResultGuard, verifiedRegisterInteractionResultGuard,
verifiedSignInteractionResultGuard, verifiedSignInteractionResultGuard,
verifiedForgotPasswordInteractionResultGuard, verifiedForgotPasswordInteractionResultGuard,
forgotPasswordProfileGuard,
} from './guard.js'; } from './guard.js';
/* Payload Types */ /* Payload Types */
@ -45,9 +44,6 @@ export type SocialIdentifier = z.infer<typeof socialIdentifierGuard>;
export type Identifier = z.infer<typeof identifierGuard>; export type Identifier = z.infer<typeof identifierGuard>;
// Profile
export type ForgotPasswordProfile = z.infer<typeof forgotPasswordProfileGuard>;
// Interaction // Interaction
export type AnonymousInteractionResult = z.infer<typeof anonymousInteractionResultGuard>; export type AnonymousInteractionResult = z.infer<typeof anonymousInteractionResultGuard>;

View file

@ -13,7 +13,6 @@ import { anonymousInteractionResultGuard } from '../types/guard.js';
import type { import type {
Identifier, Identifier,
AnonymousInteractionResult, AnonymousInteractionResult,
AccountVerifiedInteractionResult,
VerifiedForgotPasswordInteractionResult, VerifiedForgotPasswordInteractionResult,
VerifiedInteractionResult, VerifiedInteractionResult,
} from '../types/index.js'; } from '../types/index.js';
@ -82,10 +81,6 @@ export const categorizeIdentifiers = (
}; };
}; };
export const isAccountVerifiedInteractionResult = (
interaction: AnonymousInteractionResult
): interaction is AccountVerifiedInteractionResult => Boolean(interaction.accountId);
export const isForgotPasswordInteractionResult = ( export const isForgotPasswordInteractionResult = (
interaction: VerifiedInteractionResult interaction: VerifiedInteractionResult
): interaction is VerifiedForgotPasswordInteractionResult => ): interaction is VerifiedForgotPasswordInteractionResult =>

View file

@ -10,7 +10,7 @@ import type { AnonymousRouter } from '#src/routes/types.js';
const { default: swaggerRoutes, paginationParameters } = await import('./swagger.js'); const { default: swaggerRoutes, paginationParameters } = await import('./swagger.js');
export const createSwaggerRequest = ( const createSwaggerRequest = (
allRouters: Router[], allRouters: Router[],
swaggerRouter: AnonymousRouter = new Router() swaggerRouter: AnonymousRouter = new Router()
) => { ) => {

View file

@ -13,5 +13,5 @@ export type AuthedRouter = Router<
WithAuthContext & WithLogContext & WithI18nContext & ExtendableContext WithAuthContext & WithLogContext & WithI18nContext & ExtendableContext
>; >;
export type RouterInit<T> = (router: T, tenant: TenantContext) => void; type RouterInit<T> = (router: T, tenant: TenantContext) => void;
export type RouterInitArgs<T> = Parameters<RouterInit<T>>; export type RouterInitArgs<T> = Parameters<RouterInit<T>>;

View file

@ -3,7 +3,7 @@ import { assert } from '@silverhand/essentials';
import RequestError from '#src/errors/RequestError/index.js'; import RequestError from '#src/errors/RequestError/index.js';
export type AssertThatFunction = <E extends Error>( type AssertThatFunction = <E extends Error>(
value: unknown, value: unknown,
error: E | LogtoErrorCode error: E | LogtoErrorCode
) => asserts value; ) => asserts value;

View file

@ -1,11 +1,9 @@
import type { AllConnector, VerificationCodeType } from '@logto/connector-kit'; import type { AllConnector } from '@logto/connector-kit';
import { type Connector, Connectors } from '@logto/schemas'; import { type Connector, Connectors } from '@logto/schemas';
import { type z } from 'zod'; import { type z } from 'zod';
export { ConnectorType } from '@logto/schemas'; export { ConnectorType } from '@logto/schemas';
export type TemplateType = VerificationCodeType;
/** /**
* The connector type with full context. * The connector type with full context.
*/ */

View file

@ -10,7 +10,7 @@ import { isEnum } from './type.js';
const searchJointModes = Object.values(SearchJointMode); const searchJointModes = Object.values(SearchJointMode);
const searchMatchModes = Object.values(SearchMatchMode); const searchMatchModes = Object.values(SearchMatchMode);
export type SearchItem = { type SearchItem = {
mode: SearchMatchMode; mode: SearchMatchMode;
field?: string; field?: string;
values: string[]; values: string[];

View file

@ -1,4 +1,4 @@
export type UploadFileOptions = { type UploadFileOptions = {
contentType?: string; contentType?: string;
publicUrl?: string; publicUrl?: string;
}; };