From f30cae7377483ad9246b4aa7adfe6edaeef6b132 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Thu, 27 Jan 2022 19:26:34 +0800 Subject: [PATCH] chore: upgrade eslint-config to v0.6.1 --- packages/core/package.json | 4 +- packages/core/src/app/init.ts | 2 + .../core/src/connectors/aliyun-dm/index.ts | 1 + packages/core/src/connectors/github/index.ts | 4 ++ packages/core/src/connectors/index.ts | 3 + .../core/src/connectors/utilities/aliyun.ts | 5 ++ .../core/src/connectors/utilities/index.ts | 1 + .../core/src/database/insert-into.test.ts | 2 +- packages/core/src/database/insert-into.ts | 1 + packages/core/src/database/update-where.ts | 1 + packages/core/src/i18n/detect-language.ts | 1 + packages/core/src/index.ts | 3 +- packages/core/src/lib/user.test.ts | 1 + packages/core/src/middleware/koa-auth.ts | 2 + .../core/src/middleware/koa-error-handler.ts | 3 + packages/core/src/middleware/koa-i18next.ts | 1 + .../src/middleware/koa-pagination.test.ts | 1 + .../core/src/middleware/koa-pagination.ts | 1 + packages/core/src/middleware/koa-ui-proxy.ts | 1 + packages/core/src/middleware/koa-user-log.ts | 1 + packages/core/src/oidc/init.ts | 6 ++ packages/core/src/queries/application.ts | 1 + packages/core/src/queries/resource.ts | 1 + packages/core/src/queries/scope.ts | 1 + packages/core/src/queries/user.ts | 1 + packages/core/src/routes/application.ts | 4 ++ packages/core/src/routes/resource.ts | 3 + packages/core/src/routes/session.ts | 1 + packages/core/src/routes/status.ts | 1 + packages/core/src/routes/swagger.ts | 1 + packages/core/src/routes/user.ts | 4 ++ packages/core/src/utils/pagination.ts | 1 + packages/phrases/package.json | 4 +- packages/phrases/src/types.ts | 2 + packages/schemas/package.json | 2 +- packages/schemas/src/gen/index.ts | 1 + packages/schemas/src/gen/schema.ts | 1 + packages/schemas/src/gen/utils.ts | 2 + packages/ui/package.json | 8 +-- packages/ui/src/apis/consent.ts | 1 + packages/ui/src/apis/register.ts | 1 + packages/ui/src/apis/sign-in.ts | 1 + packages/ui/src/client.tsx | 2 + packages/ui/src/hooks/use-api.ts | 1 + packages/ui/src/hooks/use-theme.ts | 1 + pnpm-lock.yaml | 61 +++++++++++-------- 46 files changed, 115 insertions(+), 37 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index bdeeb9bbb..9a4009b35 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -48,8 +48,8 @@ }, "devDependencies": { "@shopify/jest-koa-mocks": "^3.0.8", - "@silverhand/eslint-config": "^0.4.0", - "@silverhand/ts-config": "^0.4.0", + "@silverhand/eslint-config": "^0.6.1", + "@silverhand/ts-config": "^0.6.1", "@types/jest": "^27.0.1", "@types/koa": "^2.13.3", "@types/koa-logger": "^3.1.1", diff --git a/packages/core/src/app/init.ts b/packages/core/src/app/init.ts index 85cafa96f..989b9655d 100644 --- a/packages/core/src/app/init.ts +++ b/packages/core/src/app/init.ts @@ -25,6 +25,7 @@ export default async function initApp(app: Koa): Promise { app.use(koaUIProxy()); const { HTTPS_CERT, HTTPS_KEY } = process.env; + if (HTTPS_CERT && HTTPS_KEY) { https .createServer( @@ -34,6 +35,7 @@ export default async function initApp(app: Koa): Promise { .listen(port, () => { console.log(`App is listening on port ${port} with HTTPS`); }); + return; } diff --git a/packages/core/src/connectors/aliyun-dm/index.ts b/packages/core/src/connectors/aliyun-dm/index.ts index b74e16822..54ff0c04a 100644 --- a/packages/core/src/connectors/aliyun-dm/index.ts +++ b/packages/core/src/connectors/aliyun-dm/index.ts @@ -32,6 +32,7 @@ export const validateConfig: ValidateConfig = async (config: unknown) => { } const result = configGuard.safeParse(config); + if (!result.success) { throw new ConnectorConfigError(result.error.message); } diff --git a/packages/core/src/connectors/github/index.ts b/packages/core/src/connectors/github/index.ts index ab67fb50c..6a2973e87 100644 --- a/packages/core/src/connectors/github/index.ts +++ b/packages/core/src/connectors/github/index.ts @@ -41,6 +41,7 @@ export const validateConfig: ValidateConfig = async (config: unknown) => { } const result = githubConfigGuard.safeParse(config); + if (!result.success) { throw new ConnectorConfigError(result.error.message); } @@ -48,6 +49,7 @@ export const validateConfig: ValidateConfig = async (config: unknown) => { export const getAuthorizationUri: GetAuthorizationUri = async (redirectUri, state) => { const config = await getConnectorConfig(metadata.id); + return `${authorizationEndpoint}?${stringify({ client_id: config.clientId, redirect_uri: redirectUri, @@ -75,6 +77,7 @@ export const getAccessToken: GetAccessToken = async (code) => { }, }) .json(); + return accessToken; }; @@ -98,6 +101,7 @@ export const getUserInfo: GetUserInfo = async (accessToken: string) => { }, }) .json(); + return { id: String(id), avatar, diff --git a/packages/core/src/connectors/index.ts b/packages/core/src/connectors/index.ts index 1c2f9d5ec..2fc6bea1e 100644 --- a/packages/core/src/connectors/index.ts +++ b/packages/core/src/connectors/index.ts @@ -11,6 +11,7 @@ export const getConnectorInstances = async (): Promise => { return Promise.all( allConnectors.map(async (element) => { const connector = await findConnectorById(element.metadata.id); + return { connector, ...element }; }) ); @@ -18,6 +19,7 @@ export const getConnectorInstances = async (): Promise => { export const getConnectorInstanceById = async (id: string): Promise => { const found = allConnectors.find((element) => element.metadata.id === id); + if (!found) { throw new RequestError({ code: 'entity.not_found', @@ -27,6 +29,7 @@ export const getConnectorInstanceById = async (id: string): Promise { const value = parameters[key]; + if (typeof value !== 'string') { throw new ConnectorError('Invalid value'); } @@ -36,6 +37,7 @@ export const getSignature = ( .join('&'); const stringToSign = `${method.toUpperCase()}&${escaper('/')}&${escaper(canonicalizedQuery)}`; + return createHmac('sha1', `${secret}&`).update(stringToSign).digest('base64'); }; @@ -72,9 +74,11 @@ export const request = async ( const signature = getSignature(finalParameters, accessKeySecret, 'POST'); const payload = new URLSearchParams(); + for (const key in finalParameters) { if (has(finalParameters, key)) { const value = finalParameters[key]; + if (typeof value !== 'string') { throw new ConnectorError('Invalid value'); } @@ -84,6 +88,7 @@ export const request = async ( } payload.append('Signature', signature); + return got.post({ url, headers: { diff --git a/packages/core/src/connectors/utilities/index.ts b/packages/core/src/connectors/utilities/index.ts index 65d068412..b4f6f77e6 100644 --- a/packages/core/src/connectors/utilities/index.ts +++ b/packages/core/src/connectors/utilities/index.ts @@ -5,6 +5,7 @@ import { findConnectorById, updateConnector } from '@/queries/connector'; export const getConnectorConfig = async (id: string): Promise => { const connector = await findConnectorById(id); + if (!connector) { throw new RequestError({ code: 'entity.not_exists_with_id', diff --git a/packages/core/src/database/insert-into.test.ts b/packages/core/src/database/insert-into.test.ts index 299142c4c..d54d5a213 100644 --- a/packages/core/src/database/insert-into.test.ts +++ b/packages/core/src/database/insert-into.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable sql/no-unsafe-query */ import { CreateUser, Users } from '@logto/schemas'; import decamelize from 'decamelize'; @@ -9,6 +8,7 @@ import { buildInsertInto } from './insert-into'; import { convertToIdentifiers } from './utils'; const buildExpectedInsertIntoSql = (keys: string[]) => [ + // eslint-disable-next-line sql/no-unsafe-query `insert into "users" (${keys.map((key) => `"${decamelize(key)}"`).join(', ')})`, `values (${keys.map((_, index) => `$${index + 1}`).join(', ')})`, ]; diff --git a/packages/core/src/database/insert-into.ts b/packages/core/src/database/insert-into.ts index e30a6456c..c512c90c9 100644 --- a/packages/core/src/database/insert-into.ts +++ b/packages/core/src/database/insert-into.ts @@ -83,6 +83,7 @@ export const buildInsertInto: BuildInsertInto = < `); assertThat(!returning || entry, 'entity.create_failed', { name: rest.tableSingular }); + return entry; }; }; diff --git a/packages/core/src/database/update-where.ts b/packages/core/src/database/update-where.ts index 97bb266d7..e082caf4b 100644 --- a/packages/core/src/database/update-where.ts +++ b/packages/core/src/database/update-where.ts @@ -63,6 +63,7 @@ export const buildUpdateWhere: BuildUpdateWhere = < status: 404, }) ); + return data; }; }; diff --git a/packages/core/src/i18n/detect-language.ts b/packages/core/src/i18n/detect-language.ts index b242780df..a60793291 100644 --- a/packages/core/src/i18n/detect-language.ts +++ b/packages/core/src/i18n/detect-language.ts @@ -19,6 +19,7 @@ const resolveLanguage = (languageString: string): Optional<[string, number]> => for (const item of rest) { const [key, value] = item.split('='); + if (key === 'q' && !Number.isNaN(value)) { return [language, Number(value)]; } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 90b430550..2510f21cb 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable import/first */ import 'module-alias/register.js'; import dotenv from 'dotenv'; @@ -6,10 +5,12 @@ import Koa from 'koa'; dotenv.config(); +/* eslint-disable import/first */ import initApp from './app/init'; import { initConnectors } from './connectors'; import { trustingTlsOffloadingProxies } from './env/consts'; import initI18n from './i18n/init'; +/* eslint-enable import/first */ const app = new Koa({ proxy: trustingTlsOffloadingProxies, diff --git a/packages/core/src/lib/user.test.ts b/packages/core/src/lib/user.test.ts index 5a251f499..3896139dd 100644 --- a/packages/core/src/lib/user.test.ts +++ b/packages/core/src/lib/user.test.ts @@ -32,6 +32,7 @@ describe('generateUserId()', () => { // eslint-disable-next-line @silverhand/fp/no-mutation tried++; + return true; }); diff --git a/packages/core/src/middleware/koa-auth.ts b/packages/core/src/middleware/koa-auth.ts index 0ba396b2b..c163e0893 100644 --- a/packages/core/src/middleware/koa-auth.ts +++ b/packages/core/src/middleware/koa-auth.ts @@ -28,6 +28,7 @@ const extractBearerTokenFromHeaders = ({ authorization }: IncomingHttpHeaders) = { supportedTypes: [bearerTokenIdentifier] } ) ); + return authorization.slice(bearerTokenIdentifier.length + 1); }; @@ -43,6 +44,7 @@ const getUserIdFromRequest = async (request: Request) => { audience: adminResource, }); assertThat(sub, new RequestError({ code: 'auth.jwt_sub_missing', status: 401 })); + return sub; }; diff --git a/packages/core/src/middleware/koa-error-handler.ts b/packages/core/src/middleware/koa-error-handler.ts index 651c76d3e..95dce578b 100644 --- a/packages/core/src/middleware/koa-error-handler.ts +++ b/packages/core/src/middleware/koa-error-handler.ts @@ -19,6 +19,7 @@ export default function koaErrorHandler(): Middleware< if (error instanceof RequestError) { ctx.status = error.status; ctx.body = error.body; + return; } @@ -30,6 +31,7 @@ export default function koaErrorHandler(): Middleware< code: `oidc.${decamelize(error.name)}` as LogtoErrorCode, data: error.error_detail, }; + return; } @@ -37,6 +39,7 @@ export default function koaErrorHandler(): Middleware< const error = new RequestError({ code: 'entity.not_found', status: 404 }); ctx.status = error.status; ctx.body = error.body; + return; } diff --git a/packages/core/src/middleware/koa-i18next.ts b/packages/core/src/middleware/koa-i18next.ts index 96ff75718..cda338eed 100644 --- a/packages/core/src/middleware/koa-i18next.ts +++ b/packages/core/src/middleware/koa-i18next.ts @@ -29,6 +29,7 @@ export default function koaI18next< await i18next.changeLanguage(foundLanguage); ctx.locale = i18next.language; + return next(); }; } diff --git a/packages/core/src/middleware/koa-pagination.test.ts b/packages/core/src/middleware/koa-pagination.test.ts index 7c7c6127f..ab2810db2 100644 --- a/packages/core/src/middleware/koa-pagination.test.ts +++ b/packages/core/src/middleware/koa-pagination.test.ts @@ -26,6 +26,7 @@ const createContext = (query: Record): WithPaginationContext({ const page = Math.floor(offset / limit) + 1; // Start from 1 ctx.append('Link', buildLink(ctx.request, 1, 'first')); ctx.append('Link', buildLink(ctx.request, totalPage, 'last')); + if (page > 1) { ctx.append('Link', buildLink(ctx.request, page - 1, 'prev')); } diff --git a/packages/core/src/middleware/koa-ui-proxy.ts b/packages/core/src/middleware/koa-ui-proxy.ts index fb00336b9..30b8ec3c1 100644 --- a/packages/core/src/middleware/koa-ui-proxy.ts +++ b/packages/core/src/middleware/koa-ui-proxy.ts @@ -35,6 +35,7 @@ export default function koaUIProxy< } const uiDistFiles = await fs.readdir(PATH_TO_UI_DIST); + if (!uiDistFiles.some((file) => ctx.request.path.startsWith(`/${file}`))) { ctx.request.path = '/'; } diff --git a/packages/core/src/middleware/koa-user-log.ts b/packages/core/src/middleware/koa-user-log.ts index dd289d496..d990fbca3 100644 --- a/packages/core/src/middleware/koa-user-log.ts +++ b/packages/core/src/middleware/koa-user-log.ts @@ -47,6 +47,7 @@ export default function koaUserLog(): Middlewar try { await next(); await insertLog(ctx, UserLogResult.Success); + return; } catch (error: unknown) { await insertLog(ctx, UserLogResult.Failed); diff --git a/packages/core/src/oidc/init.ts b/packages/core/src/oidc/init.ts index d0145c8f5..9c616fa0c 100644 --- a/packages/core/src/oidc/init.ts +++ b/packages/core/src/oidc/init.ts @@ -79,6 +79,7 @@ export default async function initOidc(app: Koa): Promise { properties: Object.keys(CustomClientMetadataType), validator: (_ctx, key, value) => { const result = customClientMetadataGuard.pick({ [key]: true }).safeParse({ key: value }); + if (!result.success) { throw new errors.InvalidClientMetadata(key); } @@ -86,6 +87,7 @@ export default async function initOidc(app: Koa): Promise { }, clientBasedCORS: (_, origin) => { console.log('origin', origin); + return origin.startsWith('http://localhost:3000'); }, findAccount: async (ctx, sub) => { @@ -98,6 +100,7 @@ export default async function initOidc(app: Koa): Promise { console.log('scope:', scope); console.log('claims:', claims); console.log('rejected:', rejected); + return { sub }; }, }; @@ -108,14 +111,17 @@ export default async function initOidc(app: Koa): Promise { */ IdToken: (ctx, token, client) => { const { idTokenTtl } = client.metadata(); + return idTokenTtl ?? defaultIdTokenTtl; }, RefreshToken: (ctx, token, client) => { const { refreshTokenTtl } = client.metadata(); + return refreshTokenTtl ?? defaultRefreshTokenTtl; }, }, }); app.use(mount('/oidc', oidc.app)); + return oidc; } diff --git a/packages/core/src/queries/application.ts b/packages/core/src/queries/application.ts index 6cf8596b7..ac825aa8f 100644 --- a/packages/core/src/queries/application.ts +++ b/packages/core/src/queries/application.ts @@ -48,6 +48,7 @@ export const deleteApplicationById = async (id: string) => { delete from ${table} where id=${id} `); + if (rowCount < 1) { throw new DeletionError(); } diff --git a/packages/core/src/queries/resource.ts b/packages/core/src/queries/resource.ts index 8a986f672..3b92e9669 100644 --- a/packages/core/src/queries/resource.ts +++ b/packages/core/src/queries/resource.ts @@ -47,6 +47,7 @@ export const deleteResourceById = async (id: string) => { delete from ${table} where id=${id} `); + if (rowCount < 1) { throw new DeletionError(); } diff --git a/packages/core/src/queries/scope.ts b/packages/core/src/queries/scope.ts index aac44808f..7bf55e629 100644 --- a/packages/core/src/queries/scope.ts +++ b/packages/core/src/queries/scope.ts @@ -28,6 +28,7 @@ export const deleteScopeById = async (id: string) => { delete from ${table} where id=${id} `); + if (rowCount < 1) { throw new DeletionError(); } diff --git a/packages/core/src/queries/user.ts b/packages/core/src/queries/user.ts index 4bfbf446d..64e73282a 100644 --- a/packages/core/src/queries/user.ts +++ b/packages/core/src/queries/user.ts @@ -55,6 +55,7 @@ export const deleteUserById = async (id: string) => { delete from ${table} where id=${id} `); + if (rowCount < 1) { throw new DeletionError(); } diff --git a/packages/core/src/routes/application.ts b/packages/core/src/routes/application.ts index 0f72649e6..351823e49 100644 --- a/packages/core/src/routes/application.ts +++ b/packages/core/src/routes/application.ts @@ -52,6 +52,7 @@ export default function applicationRoutes(router: T) { oidcClientMetadata: buildOidcClientMetadata(oidcClientMetadata), ...rest, }); + return next(); } ); @@ -67,6 +68,7 @@ export default function applicationRoutes(router: T) { } = ctx.guard; ctx.body = await findApplicationById(id); + return next(); } ); @@ -91,6 +93,7 @@ export default function applicationRoutes(router: T) { ...body.oidcClientMetadata, }), }); + return next(); } ); @@ -104,6 +107,7 @@ export default function applicationRoutes(router: T) { await findApplicationById(id); await deleteApplicationById(id); ctx.status = 204; + return next(); } ); diff --git a/packages/core/src/routes/resource.ts b/packages/core/src/routes/resource.ts index e6d9bf9b5..3d6c84d33 100644 --- a/packages/core/src/routes/resource.ts +++ b/packages/core/src/routes/resource.ts @@ -66,6 +66,7 @@ export default function resourceRoutes(router: T) { ]); ctx.body = { ...resource, scopes }; + return next(); } ); @@ -88,6 +89,7 @@ export default function resourceRoutes(router: T) { ]); ctx.body = { ...resource, scopes }; + return next(); } ); @@ -100,6 +102,7 @@ export default function resourceRoutes(router: T) { await findResourceById(id); await deleteResourceById(id); ctx.status = 204; + return next(); } ); diff --git a/packages/core/src/routes/session.ts b/packages/core/src/routes/session.ts index 6d2d92c4d..fe721ecd3 100644 --- a/packages/core/src/routes/session.ts +++ b/packages/core/src/routes/session.ts @@ -162,6 +162,7 @@ export default function sessionRoutes(router: T, prov error, }); ctx.body = { redirectTo }; + return next(); }); } diff --git a/packages/core/src/routes/status.ts b/packages/core/src/routes/status.ts index 5d36a2fe6..c126a7075 100644 --- a/packages/core/src/routes/status.ts +++ b/packages/core/src/routes/status.ts @@ -3,6 +3,7 @@ import { AnonymousRouter } from './types'; export default function statusRoutes(router: T) { router.get('/status', async (ctx, next) => { ctx.status = 204; + return next(); }); } diff --git a/packages/core/src/routes/swagger.ts b/packages/core/src/routes/swagger.ts index 2257a53db..afb8d4c30 100644 --- a/packages/core/src/routes/swagger.ts +++ b/packages/core/src/routes/swagger.ts @@ -13,6 +13,7 @@ export default function swaggerRoutes(router: T) { const guard = stack.find((function_): function_ is WithGuardConfig => isGuardMiddleware(function_) ); + return { path, methods, guard }; }); diff --git a/packages/core/src/routes/user.ts b/packages/core/src/routes/user.ts index 9b48c9439..3a5d1253d 100644 --- a/packages/core/src/routes/user.ts +++ b/packages/core/src/routes/user.ts @@ -12,6 +12,7 @@ export default function userRoutes(router: T) { router.get('/users', async (ctx, next) => { const users = await findAllUsers(); ctx.body = users.map((user) => pick(user, ...userInfoSelectFields)); + return next(); }); @@ -26,6 +27,7 @@ export default function userRoutes(router: T) { } = ctx.guard; const user = await findUserById(userId); ctx.body = pick(user, ...userInfoSelectFields); + return next(); } ); @@ -51,6 +53,7 @@ export default function userRoutes(router: T) { passwordEncrypted, }); ctx.body = pick(user, ...userInfoSelectFields); + return next(); } ); @@ -66,6 +69,7 @@ export default function userRoutes(router: T) { } = ctx.guard; await deleteUserById(userId); ctx.status = 204; + return next(); } ); diff --git a/packages/core/src/utils/pagination.ts b/packages/core/src/utils/pagination.ts index 88bb02481..b69f7dadd 100644 --- a/packages/core/src/utils/pagination.ts +++ b/packages/core/src/utils/pagination.ts @@ -9,5 +9,6 @@ export const buildLink = ( type: LinkRelationType ): string => { const baseUrl = `${request.origin}${request.path}`; + return `<${baseUrl}?${stringify({ ...request.query, page })}>; rel="${type}"`; }; diff --git a/packages/phrases/package.json b/packages/phrases/package.json index 509ef5241..a828881db 100644 --- a/packages/phrases/package.json +++ b/packages/phrases/package.json @@ -28,8 +28,8 @@ "@silverhand/essentials": "^1.1.4" }, "devDependencies": { - "@silverhand/eslint-config": "^0.4.0", - "@silverhand/ts-config": "^0.4.0", + "@silverhand/eslint-config": "^0.6.1", + "@silverhand/ts-config": "^0.6.1", "eslint": "^8.1.0", "lint-staged": "^11.1.1", "prettier": "^2.3.2", diff --git a/packages/phrases/src/types.ts b/packages/phrases/src/types.ts index 347f4f55a..a48e875fc 100644 --- a/packages/phrases/src/types.ts +++ b/packages/phrases/src/types.ts @@ -10,3 +10,5 @@ export interface ResourceLanguage { } export type ResourceKey = string | { [key: string]: any }; + +/* eslint-enable @typescript-eslint/consistent-indexed-object-style */ diff --git a/packages/schemas/package.json b/packages/schemas/package.json index d0a8f520b..207c42b5e 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -21,7 +21,7 @@ "node": ">=14.15.0" }, "devDependencies": { - "@silverhand/eslint-config": "^0.4.0", + "@silverhand/eslint-config": "^0.6.1", "@silverhand/essentials": "^1.1.0", "@silverhand/ts-config": "^0.4.0", "@types/lodash.uniq": "^4.5.6", diff --git a/packages/schemas/src/gen/index.ts b/packages/schemas/src/gen/index.ts index 76564eb98..80a76f67d 100644 --- a/packages/schemas/src/gen/index.ts +++ b/packages/schemas/src/gen/index.ts @@ -87,6 +87,7 @@ const generate = async () => { nullable, }; }); + return { name, fields }; }); const types = statements diff --git a/packages/schemas/src/gen/schema.ts b/packages/schemas/src/gen/schema.ts index 88458e941..dc30f83c4 100644 --- a/packages/schemas/src/gen/schema.ts +++ b/packages/schemas/src/gen/schema.ts @@ -7,6 +7,7 @@ import { TableWithType } from './types'; export const generateSchema = ({ name, fields }: TableWithType) => { const modelName = pluralize(camelcase(name, { pascalCase: true }), 1); const databaseEntryType = `Create${modelName}`; + return [ `export type ${databaseEntryType} = {`, ...fields.map( diff --git a/packages/schemas/src/gen/utils.ts b/packages/schemas/src/gen/utils.ts index 9f2ac8209..a428c0db1 100644 --- a/packages/schemas/src/gen/utils.ts +++ b/packages/schemas/src/gen/utils.ts @@ -22,6 +22,7 @@ export const removeParentheses = (value: string) => Object.values(value).reduce<{ result: string; count: number }>( (previous, current) => { const count = previous.count + getCountDelta(current); + return count === 0 && current !== ')' ? { result: previous.result + current, count } : { result: previous.result, count }; @@ -79,6 +80,7 @@ export const findFirstParentheses = (value: string): Optional const getRawType = (value: string): string => { const bracketIndex = value.indexOf('['); + return bracketIndex === -1 ? value : value.slice(0, bracketIndex); }; diff --git a/packages/ui/package.json b/packages/ui/package.json index 804531fb8..2637705f4 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -34,10 +34,10 @@ "devDependencies": { "@babel/core": "^7.14.6", "@jest/types": "^27.0.6", - "@silverhand/eslint-config": "^0.4.0", - "@silverhand/eslint-config-react": "^0.4.0", - "@silverhand/ts-config": "^0.4.0", - "@silverhand/ts-config-react": "^0.4.0", + "@silverhand/eslint-config": "^0.6.1", + "@silverhand/eslint-config-react": "^0.6.1", + "@silverhand/ts-config": "^0.6.1", + "@silverhand/ts-config-react": "^0.6.1", "@testing-library/react": "^12.0.0", "@types/jest": "^26.0.24", "@types/react": "^17.0.14", diff --git a/packages/ui/src/apis/consent.ts b/packages/ui/src/apis/consent.ts index 7c6b4e51d..18749e32a 100644 --- a/packages/ui/src/apis/consent.ts +++ b/packages/ui/src/apis/consent.ts @@ -4,5 +4,6 @@ export const consent = async () => { type Response = { redirectTo: string; }; + return ky.post('/api/session/consent').json(); }; diff --git a/packages/ui/src/apis/register.ts b/packages/ui/src/apis/register.ts index 7ff86411b..6f9a40e04 100644 --- a/packages/ui/src/apis/register.ts +++ b/packages/ui/src/apis/register.ts @@ -4,6 +4,7 @@ export const register = async (username: string, password: string) => { type Response = { redirectTo: string; }; + return ky .post('/api/session/register', { json: { diff --git a/packages/ui/src/apis/sign-in.ts b/packages/ui/src/apis/sign-in.ts index 4b8cd5f3c..6783604c3 100644 --- a/packages/ui/src/apis/sign-in.ts +++ b/packages/ui/src/apis/sign-in.ts @@ -4,6 +4,7 @@ export const signInBasic = async (username: string, password: string) => { type Response = { redirectTo: string; }; + return ky .post('/api/session', { json: { diff --git a/packages/ui/src/client.tsx b/packages/ui/src/client.tsx index eb9592f3a..1c58b862e 100644 --- a/packages/ui/src/client.tsx +++ b/packages/ui/src/client.tsx @@ -17,3 +17,5 @@ renderFunction( if (module.hot) { module.hot.accept(); } + +/* eslint-enable unicorn/prefer-module */ diff --git a/packages/ui/src/hooks/use-api.ts b/packages/ui/src/hooks/use-api.ts index a131ea9c3..c056590e0 100644 --- a/packages/ui/src/hooks/use-api.ts +++ b/packages/ui/src/hooks/use-api.ts @@ -30,6 +30,7 @@ function useApi( const kyError = await error.response.json(); setError(kyError); setLoading(false); + return; } diff --git a/packages/ui/src/hooks/use-theme.ts b/packages/ui/src/hooks/use-theme.ts index e9c6051db..d7c9f2f38 100644 --- a/packages/ui/src/hooks/use-theme.ts +++ b/packages/ui/src/hooks/use-theme.ts @@ -14,6 +14,7 @@ export default function useTheme() { }; darkThemeWatchMedia.addEventListener('change', changeTheme); + return () => { darkThemeWatchMedia.removeEventListener('change', changeTheme); }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e87d6a054..b0f076ce4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,9 +23,9 @@ importers: '@logto/phrases': ^0.1.0 '@logto/schemas': ^0.1.0 '@shopify/jest-koa-mocks': ^3.0.8 - '@silverhand/eslint-config': ^0.4.0 + '@silverhand/eslint-config': ^0.6.1 '@silverhand/essentials': ^1.1.0 - '@silverhand/ts-config': ^0.4.0 + '@silverhand/ts-config': ^0.6.1 '@types/jest': ^27.0.1 '@types/koa': ^2.13.3 '@types/koa-logger': ^3.1.1 @@ -100,8 +100,8 @@ importers: zod: 3.11.6 devDependencies: '@shopify/jest-koa-mocks': 3.0.8 - '@silverhand/eslint-config': 0.4.0_1462fc7e3c7b4386daba890f6c2395d0 - '@silverhand/ts-config': 0.4.0_typescript@4.5.3 + '@silverhand/eslint-config': 0.6.1_1462fc7e3c7b4386daba890f6c2395d0 + '@silverhand/ts-config': 0.6.1_typescript@4.5.3 '@types/jest': 27.0.3 '@types/koa': 2.13.4 '@types/koa-logger': 3.1.2 @@ -125,9 +125,9 @@ importers: packages/phrases: specifiers: - '@silverhand/eslint-config': ^0.4.0 + '@silverhand/eslint-config': ^0.6.1 '@silverhand/essentials': ^1.1.4 - '@silverhand/ts-config': ^0.4.0 + '@silverhand/ts-config': ^0.6.1 eslint: ^8.1.0 lint-staged: ^11.1.1 prettier: ^2.3.2 @@ -135,8 +135,8 @@ importers: dependencies: '@silverhand/essentials': 1.1.4 devDependencies: - '@silverhand/eslint-config': 0.4.0_1462fc7e3c7b4386daba890f6c2395d0 - '@silverhand/ts-config': 0.4.0_typescript@4.5.3 + '@silverhand/eslint-config': 0.6.1_1462fc7e3c7b4386daba890f6c2395d0 + '@silverhand/ts-config': 0.6.1_typescript@4.5.3 eslint: 8.4.1 lint-staged: 11.2.6 prettier: 2.5.1 @@ -145,7 +145,7 @@ importers: packages/schemas: specifiers: '@logto/phrases': ^0.1.0 - '@silverhand/eslint-config': ^0.4.0 + '@silverhand/eslint-config': ^0.6.1 '@silverhand/essentials': ^1.1.0 '@silverhand/ts-config': ^0.4.0 '@types/lodash.uniq': ^4.5.6 @@ -164,7 +164,7 @@ importers: '@logto/phrases': link:../phrases zod: 3.11.6 devDependencies: - '@silverhand/eslint-config': 0.4.0_1462fc7e3c7b4386daba890f6c2395d0 + '@silverhand/eslint-config': 0.6.1_1462fc7e3c7b4386daba890f6c2395d0 '@silverhand/essentials': 1.1.2 '@silverhand/ts-config': 0.4.0_typescript@4.5.3 '@types/lodash.uniq': 4.5.6 @@ -185,10 +185,10 @@ importers: '@jest/types': ^27.0.6 '@logto/phrases': ^0.1.0 '@logto/schemas': ^0.1.0 - '@silverhand/eslint-config': ^0.4.0 - '@silverhand/eslint-config-react': ^0.4.0 - '@silverhand/ts-config': ^0.4.0 - '@silverhand/ts-config-react': ^0.4.0 + '@silverhand/eslint-config': ^0.6.1 + '@silverhand/eslint-config-react': ^0.6.1 + '@silverhand/ts-config': ^0.6.1 + '@silverhand/ts-config-react': ^0.6.1 '@testing-library/react': ^12.0.0 '@types/jest': ^26.0.24 '@types/react': ^17.0.14 @@ -237,10 +237,10 @@ importers: devDependencies: '@babel/core': 7.16.0 '@jest/types': 27.4.2 - '@silverhand/eslint-config': 0.4.0_1462fc7e3c7b4386daba890f6c2395d0 - '@silverhand/eslint-config-react': 0.4.0_9d4efdeaabe00e4de1f3b58f5988ea20 - '@silverhand/ts-config': 0.4.0_typescript@4.5.3 - '@silverhand/ts-config-react': 0.4.0_typescript@4.5.3 + '@silverhand/eslint-config': 0.6.1_1462fc7e3c7b4386daba890f6c2395d0 + '@silverhand/eslint-config-react': 0.6.1_9d4efdeaabe00e4de1f3b58f5988ea20 + '@silverhand/ts-config': 0.6.1_typescript@4.5.3 + '@silverhand/ts-config-react': 0.6.1_typescript@4.5.3 '@testing-library/react': 12.1.2_react-dom@17.0.2+react@17.0.2 '@types/jest': 26.0.24 '@types/react': 17.0.37 @@ -3076,12 +3076,12 @@ packages: - supports-color dev: true - /@silverhand/eslint-config-react/0.4.0_9d4efdeaabe00e4de1f3b58f5988ea20: - resolution: {integrity: sha512-C0Sf3eajHXzrS/Nc4XJQv+1RGh3XJBJcUDb/W0JI9O4YVmC1zRsGanuzs+Vvd1uDcBzVqWVDjSH5GRw36IOonA==} + /@silverhand/eslint-config-react/0.6.1_9d4efdeaabe00e4de1f3b58f5988ea20: + resolution: {integrity: sha512-QrYy4E6jPPYDHTBiwD6cTQUZ2iC/6GjUrP6bnDDa7ujn93ll0oDlTVsJjcIj9tHaxjF7rJofG+JKCJKLED0Bhw==} peerDependencies: stylelint: ^13.13.1 dependencies: - '@silverhand/eslint-config': 0.4.0_1462fc7e3c7b4386daba890f6c2395d0 + '@silverhand/eslint-config': 0.6.1_1462fc7e3c7b4386daba890f6c2395d0 eslint-config-xo-react: 0.25.0_0d0b684468c8c3b6dac037452254bcd4 eslint-plugin-react: 7.27.1_eslint@8.4.1 eslint-plugin-react-hooks: 4.3.0_eslint@8.4.1 @@ -3094,8 +3094,8 @@ packages: - typescript dev: true - /@silverhand/eslint-config/0.4.0_1462fc7e3c7b4386daba890f6c2395d0: - resolution: {integrity: sha512-ivaUaS1S6w6EZ+K+anZYTJMCDkzP4DxF2aMEo6jndBkAA0/W9CGyQ4fmnLuRamgeE0OzzNpeYRQOaDmLLEEXvA==} + /@silverhand/eslint-config/0.6.1_1462fc7e3c7b4386daba890f6c2395d0: + resolution: {integrity: sha512-XgLn291LvMjhdfPgRfjtL8L2rmZ2Dci40N3jvNoC65jb4i1wmHoaG2ZYL4eVSTXOLiAfIuRJnuuLisunY/aUKQ==} engines: {node: '>=14.15.0'} peerDependencies: eslint: ^8.1.0 @@ -3153,13 +3153,13 @@ packages: lodash.pick: 4.4.0 dev: false - /@silverhand/ts-config-react/0.4.0_typescript@4.5.3: - resolution: {integrity: sha512-8D/VFFFGDrOf4zspfkvasXViOpwC+S/VrJx/rHD7Ztbn8+HPeHQRZeykXI2Tgg/G8cBkmlhW9ufrtCBYElJd+g==} + /@silverhand/ts-config-react/0.6.1_typescript@4.5.3: + resolution: {integrity: sha512-tFuXXeOzWY4p9acWdxL4TyEl+XMHSNj6lpcqQBrYErGklr0Qq9ztYNEQ1MMpNmQMWoUCkUvH/nbl3HEC0DZz5w==} engines: {node: '>=14.15.0'} peerDependencies: typescript: ^4.3.5 dependencies: - '@silverhand/ts-config': 0.4.0_typescript@4.5.3 + '@silverhand/ts-config': 0.6.1_typescript@4.5.3 typescript: 4.5.3 dev: true @@ -3172,6 +3172,15 @@ packages: typescript: 4.5.3 dev: true + /@silverhand/ts-config/0.6.1_typescript@4.5.3: + resolution: {integrity: sha512-Bj6xK0ZUuv57bqryD9LbOJu3j13ud4aM+mrF6ztlQr8WnauvqSn17zCUfwLNxL7EMRH+qIb2BdVqJVIYFE2Dhg==} + engines: {node: '>=14.15.0'} + peerDependencies: + typescript: ^4.3.5 + dependencies: + typescript: 4.5.3 + dev: true + /@sindresorhus/is/4.2.0: resolution: {integrity: sha512-VkE3KLBmJwcCaVARtQpfuKcKv8gcBmUubrfHGF84dXuuW6jgsRYxPtzcIhPyK9WAPpRt2/xY6zkD9MnRaJzSyw==} engines: {node: '>=10'}