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": {
"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"
}

View file

@ -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,

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[];
};
export type WellKnownCacheType = keyof WellKnownMap;
type WellKnownCacheType = keyof WellKnownMap;
/**
* 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;
};
export const getTenantLocalhost = (
const getTenantLocalhost = (
id: string,
{ urlSet, adminUrlSet, isDomainBasedMultiTenancy, isPathBasedMultiTenancy }: GlobalValues
): 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';
export type ApplicationLibrary = ReturnType<typeof createApplicationLibrary>;
export const createApplicationLibrary = (queries: Queries) => {
const {
applicationsRoles: { findApplicationsRolesByApplicationId },

View file

@ -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[];

View file

@ -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<typeof createSocialLibrary>;
export const createSocialLibrary = (queries: Queries, connectorLibrary: ConnectorLibrary) => {
const { findUserByEmail, findUserByPhone } = queries.users;
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 assertThat from '#src/utils/assert-that.js';
export type VerificationStatusLibrary = ReturnType<typeof createVerificationStatusLibrary>;
export const createVerificationStatusLibrary = (queries: Queries) => {
const {
findVerificationStatusByUserId,

View file

@ -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> = ContextT & {
pagination: Pagination;
};
export type PaginationConfig = {
type PaginationConfig = {
defaultPageSize?: number;
maxPageSize?: number;
isOptional?: boolean;

View file

@ -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<Exclude<UserClaim, 'email_verified' | 'phone_number_verified'>, keyof User>
> = Object.freeze({
name: 'name',

View file

@ -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;

View file

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

View file

@ -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 =>

View file

@ -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()
) => {

View file

@ -13,5 +13,5 @@ export type AuthedRouter = Router<
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>>;

View file

@ -3,7 +3,7 @@ import { assert } from '@silverhand/essentials';
import RequestError from '#src/errors/RequestError/index.js';
export type AssertThatFunction = <E extends Error>(
type AssertThatFunction = <E extends Error>(
value: unknown,
error: E | LogtoErrorCode
) => 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 z } from 'zod';
export { ConnectorType } from '@logto/schemas';
export type TemplateType = VerificationCodeType;
/**
* The connector type with full context.
*/

View file

@ -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[];

View file

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