From 2338cb692ea6c6742e7006335e7d216c103accf8 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Fri, 9 Jun 2023 21:55:15 +0800 Subject: [PATCH] refactor(core): apply no-unused-modules (#4009) --- packages/core/package.json | 18 +++++++++++-- packages/core/src/__mocks__/custom-phrase.ts | 26 ------------------- packages/core/src/__mocks__/interactions.ts | 26 ------------------- packages/core/src/caches/well-known.ts | 2 +- .../__mocks__/check-alteration-state.ts | 2 -- packages/core/src/env-set/utils.ts | 2 +- .../src/libraries/__mocks__/logto-config.ts | 23 ---------------- packages/core/src/libraries/application.ts | 2 -- .../src/libraries/sign-in-experience/types.ts | 4 +-- packages/core/src/libraries/social.ts | 7 ----- .../core/src/libraries/verification-status.ts | 2 -- .../core/src/middleware/koa-pagination.ts | 4 +-- packages/core/src/oidc/scope.ts | 2 +- packages/core/src/queries/log.ts | 2 +- .../src/routes/interaction/types/index.ts | 4 --- .../routes/interaction/utils/interaction.ts | 5 ---- packages/core/src/routes/swagger.test.ts | 2 +- packages/core/src/routes/types.ts | 2 +- packages/core/src/utils/assert-that.ts | 2 +- packages/core/src/utils/connectors/types.ts | 4 +-- packages/core/src/utils/search.ts | 2 +- packages/core/src/utils/storage/types.ts | 2 +- 22 files changed, 30 insertions(+), 115 deletions(-) delete mode 100644 packages/core/src/__mocks__/interactions.ts delete mode 100644 packages/core/src/env-set/__mocks__/check-alteration-state.ts delete mode 100644 packages/core/src/libraries/__mocks__/logto-config.ts diff --git a/packages/core/package.json b/packages/core/package.json index a49ada687..63537508e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -116,8 +116,22 @@ "eslintConfig": { "extends": "@silverhand", "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" } diff --git a/packages/core/src/__mocks__/custom-phrase.ts b/packages/core/src/__mocks__/custom-phrase.ts index 042812d9b..f82ece29e 100644 --- a/packages/core/src/__mocks__/custom-phrase.ts +++ b/packages/core/src/__mocks__/custom-phrase.ts @@ -1,4 +1,3 @@ -import en from '@logto/phrases-ui/lib/locales/en/index.js'; import { type CustomPhrase } from '@logto/schemas'; import { mockId } from '#src/test-utils/nanoid.js'; @@ -23,31 +22,6 @@ export const mockEnCustomPhrase = { }, } 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 = { tenantId: 'fake_tenant', id: mockId, diff --git a/packages/core/src/__mocks__/interactions.ts b/packages/core/src/__mocks__/interactions.ts deleted file mode 100644 index bfb3196dd..000000000 --- a/packages/core/src/__mocks__/interactions.ts +++ /dev/null @@ -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' }, - }, -]; diff --git a/packages/core/src/caches/well-known.ts b/packages/core/src/caches/well-known.ts index 2bde434c0..4148ee637 100644 --- a/packages/core/src/caches/well-known.ts +++ b/packages/core/src/caches/well-known.ts @@ -14,7 +14,7 @@ type WellKnownMap = { 'custom-phrases-tags': string[]; }; -export type WellKnownCacheType = keyof WellKnownMap; +type WellKnownCacheType = keyof WellKnownMap; /** * The array tuple to determine how cache will be built. diff --git a/packages/core/src/env-set/__mocks__/check-alteration-state.ts b/packages/core/src/env-set/__mocks__/check-alteration-state.ts deleted file mode 100644 index a6b386678..000000000 --- a/packages/core/src/env-set/__mocks__/check-alteration-state.ts +++ /dev/null @@ -1,2 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-empty-function -export const checkAlterationState = async () => {}; diff --git a/packages/core/src/env-set/utils.ts b/packages/core/src/env-set/utils.ts index 20f5c00d6..c6226f779 100644 --- a/packages/core/src/env-set/utils.ts +++ b/packages/core/src/env-set/utils.ts @@ -30,7 +30,7 @@ export const getTenantEndpoint = ( return tenantUrl; }; -export const getTenantLocalhost = ( +const getTenantLocalhost = ( id: string, { urlSet, adminUrlSet, isDomainBasedMultiTenancy, isPathBasedMultiTenancy }: GlobalValues ): Optional => { diff --git a/packages/core/src/libraries/__mocks__/logto-config.ts b/packages/core/src/libraries/__mocks__/logto-config.ts deleted file mode 100644 index c6f0bb202..000000000 --- a/packages/core/src/libraries/__mocks__/logto-config.ts +++ /dev/null @@ -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 => ({ - [LogtoOidcConfigKey.PrivateKeys]: [privateKey], - [LogtoOidcConfigKey.CookieKeys]: ['LOGTOSEKRIT1'], -}); - -export const createLogtoConfigLibrary = () => ({ getOidcConfigs }); diff --git a/packages/core/src/libraries/application.ts b/packages/core/src/libraries/application.ts index 8e7ab033f..1ec4cc5b5 100644 --- a/packages/core/src/libraries/application.ts +++ b/packages/core/src/libraries/application.ts @@ -2,8 +2,6 @@ import type { Scope } from '@logto/schemas'; import type Queries from '#src/tenants/Queries.js'; -export type ApplicationLibrary = ReturnType; - export const createApplicationLibrary = (queries: Queries) => { const { applicationsRoles: { findApplicationsRolesByApplicationId }, diff --git a/packages/core/src/libraries/sign-in-experience/types.ts b/packages/core/src/libraries/sign-in-experience/types.ts index 720ac92a2..48c9a4b50 100644 --- a/packages/core/src/libraries/sign-in-experience/types.ts +++ b/packages/core/src/libraries/sign-in-experience/types.ts @@ -2,12 +2,12 @@ import { connectorMetadataGuard, type ConnectorMetadata } from '@logto/connector import { type SignInExperience, SignInExperiences } from '@logto/schemas'; import { z } from 'zod'; -export type ForgotPassword = { +type ForgotPassword = { phone: boolean; email: boolean; }; -export type ConnectorMetadataWithId = ConnectorMetadata & { id: string }; +type ConnectorMetadataWithId = ConnectorMetadata & { id: string }; export type FullSignInExperience = SignInExperience & { socialConnectors: ConnectorMetadataWithId[]; diff --git a/packages/core/src/libraries/social.ts b/packages/core/src/libraries/social.ts index 462135926..149c3814d 100644 --- a/packages/core/src/libraries/social.ts +++ b/packages/core/src/libraries/social.ts @@ -12,11 +12,6 @@ import type Queries from '#src/tenants/Queries.js'; import assertThat from '#src/utils/assert-that.js'; import type { LogtoConnector } from '#src/utils/connectors/types.js'; -export type SocialUserInfoSession = { - connectorId: string; - userInfo: SocialUserInfo; -}; - const getUserInfoFromInteractionResult = async ( connectorId: string, interactionResult: InteractionResults @@ -40,8 +35,6 @@ const getUserInfoFromInteractionResult = async ( return result.socialUserInfo.userInfo; }; -export type SocialLibrary = ReturnType; - export const createSocialLibrary = (queries: Queries, connectorLibrary: ConnectorLibrary) => { const { findUserByEmail, findUserByPhone } = queries.users; const { getLogtoConnectorById } = connectorLibrary; diff --git a/packages/core/src/libraries/verification-status.ts b/packages/core/src/libraries/verification-status.ts index 2dc31e613..d51979b28 100644 --- a/packages/core/src/libraries/verification-status.ts +++ b/packages/core/src/libraries/verification-status.ts @@ -5,8 +5,6 @@ import { verificationTimeout } from '#src/routes/consts.js'; import type Queries from '#src/tenants/Queries.js'; import assertThat from '#src/utils/assert-that.js'; -export type VerificationStatusLibrary = ReturnType; - export const createVerificationStatusLibrary = (queries: Queries) => { const { findVerificationStatusByUserId, diff --git a/packages/core/src/middleware/koa-pagination.ts b/packages/core/src/middleware/koa-pagination.ts index 8036acaa1..940f8e1dc 100644 --- a/packages/core/src/middleware/koa-pagination.ts +++ b/packages/core/src/middleware/koa-pagination.ts @@ -5,7 +5,7 @@ import { number } from 'zod'; import RequestError from '#src/errors/RequestError/index.js'; import { buildLink } from '#src/utils/pagination.js'; -export type Pagination = { +type Pagination = { offset: number; limit: number; totalCount?: number; @@ -16,7 +16,7 @@ export type WithPaginationContext = ContextT & { pagination: Pagination; }; -export type PaginationConfig = { +type PaginationConfig = { defaultPageSize?: number; maxPageSize?: number; isOptional?: boolean; diff --git a/packages/core/src/oidc/scope.ts b/packages/core/src/oidc/scope.ts index 57f3d1995..7df564969 100644 --- a/packages/core/src/oidc/scope.ts +++ b/packages/core/src/oidc/scope.ts @@ -4,7 +4,7 @@ import type { User } from '@logto/schemas'; import type { Nullable } from '@silverhand/essentials'; import type { ClaimsParameterMember } from 'oidc-provider'; -export const claimToUserKey: Readonly< +const claimToUserKey: Readonly< Record, keyof User> > = Object.freeze({ name: 'name', diff --git a/packages/core/src/queries/log.ts b/packages/core/src/queries/log.ts index 485c05a38..6bffbda7c 100644 --- a/packages/core/src/queries/log.ts +++ b/packages/core/src/queries/log.ts @@ -10,7 +10,7 @@ import { buildInsertIntoWithPool } from '#src/database/insert-into.js'; const { table, fields } = convertToIdentifiers(Logs); -export type LogCondition = { +type LogCondition = { logKey?: string; applicationId?: string; userId?: string; diff --git a/packages/core/src/routes/interaction/types/index.ts b/packages/core/src/routes/interaction/types/index.ts index 9983ba4c0..be87c3202 100644 --- a/packages/core/src/routes/interaction/types/index.ts +++ b/packages/core/src/routes/interaction/types/index.ts @@ -20,7 +20,6 @@ import type { verifiedRegisterInteractionResultGuard, verifiedSignInteractionResultGuard, verifiedForgotPasswordInteractionResultGuard, - forgotPasswordProfileGuard, } from './guard.js'; /* Payload Types */ @@ -45,9 +44,6 @@ export type SocialIdentifier = z.infer; export type Identifier = z.infer; -// Profile -export type ForgotPasswordProfile = z.infer; - // Interaction export type AnonymousInteractionResult = z.infer; diff --git a/packages/core/src/routes/interaction/utils/interaction.ts b/packages/core/src/routes/interaction/utils/interaction.ts index 67c8ce3fd..741304ff9 100644 --- a/packages/core/src/routes/interaction/utils/interaction.ts +++ b/packages/core/src/routes/interaction/utils/interaction.ts @@ -13,7 +13,6 @@ import { anonymousInteractionResultGuard } from '../types/guard.js'; import type { Identifier, AnonymousInteractionResult, - AccountVerifiedInteractionResult, VerifiedForgotPasswordInteractionResult, VerifiedInteractionResult, } 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 = ( interaction: VerifiedInteractionResult ): interaction is VerifiedForgotPasswordInteractionResult => diff --git a/packages/core/src/routes/swagger.test.ts b/packages/core/src/routes/swagger.test.ts index d68fa3409..c973c7cc6 100644 --- a/packages/core/src/routes/swagger.test.ts +++ b/packages/core/src/routes/swagger.test.ts @@ -10,7 +10,7 @@ import type { AnonymousRouter } from '#src/routes/types.js'; const { default: swaggerRoutes, paginationParameters } = await import('./swagger.js'); -export const createSwaggerRequest = ( +const createSwaggerRequest = ( allRouters: Router[], swaggerRouter: AnonymousRouter = new Router() ) => { diff --git a/packages/core/src/routes/types.ts b/packages/core/src/routes/types.ts index 52e40e852..3beb572b6 100644 --- a/packages/core/src/routes/types.ts +++ b/packages/core/src/routes/types.ts @@ -13,5 +13,5 @@ export type AuthedRouter = Router< WithAuthContext & WithLogContext & WithI18nContext & ExtendableContext >; -export type RouterInit = (router: T, tenant: TenantContext) => void; +type RouterInit = (router: T, tenant: TenantContext) => void; export type RouterInitArgs = Parameters>; diff --git a/packages/core/src/utils/assert-that.ts b/packages/core/src/utils/assert-that.ts index 3d819bac3..fed961124 100644 --- a/packages/core/src/utils/assert-that.ts +++ b/packages/core/src/utils/assert-that.ts @@ -3,7 +3,7 @@ import { assert } from '@silverhand/essentials'; import RequestError from '#src/errors/RequestError/index.js'; -export type AssertThatFunction = ( +type AssertThatFunction = ( value: unknown, error: E | LogtoErrorCode ) => asserts value; diff --git a/packages/core/src/utils/connectors/types.ts b/packages/core/src/utils/connectors/types.ts index f304af022..4d479dc54 100644 --- a/packages/core/src/utils/connectors/types.ts +++ b/packages/core/src/utils/connectors/types.ts @@ -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 z } from 'zod'; export { ConnectorType } from '@logto/schemas'; -export type TemplateType = VerificationCodeType; - /** * The connector type with full context. */ diff --git a/packages/core/src/utils/search.ts b/packages/core/src/utils/search.ts index d24884336..947724f84 100644 --- a/packages/core/src/utils/search.ts +++ b/packages/core/src/utils/search.ts @@ -10,7 +10,7 @@ import { isEnum } from './type.js'; const searchJointModes = Object.values(SearchJointMode); const searchMatchModes = Object.values(SearchMatchMode); -export type SearchItem = { +type SearchItem = { mode: SearchMatchMode; field?: string; values: string[]; diff --git a/packages/core/src/utils/storage/types.ts b/packages/core/src/utils/storage/types.ts index 4bb7f06be..fd13e258c 100644 --- a/packages/core/src/utils/storage/types.ts +++ b/packages/core/src/utils/storage/types.ts @@ -1,4 +1,4 @@ -export type UploadFileOptions = { +type UploadFileOptions = { contentType?: string; publicUrl?: string; };