refactor(core): Update auth related typings (no-changelog) (#8686)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-02-23 15:08:18 +01:00 committed by GitHub
parent 9b0d98403a
commit 35fb7102cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 33 deletions

View file

@ -17,6 +17,7 @@ import { InternalHooks } from '@/InternalHooks';
import { License } from '@/License'; import { License } from '@/License';
import { UserRepository } from '@db/repositories/user.repository'; import { UserRepository } from '@db/repositories/user.repository';
import { UrlService } from '@/services/url.service'; import { UrlService } from '@/services/url.service';
import type { AuthenticatedRequest } from '@/requests';
async function createApiRouter( async function createApiRouter(
version: string, version: string,
@ -51,7 +52,7 @@ async function createApiRouter(
); );
} }
apiController.get(`/${publicApiEndpoint}/${version}/openapi.yml`, (req, res) => { apiController.get(`/${publicApiEndpoint}/${version}/openapi.yml`, (_, res) => {
res.sendFile(openApiSpecPath); res.sendFile(openApiSpecPath);
}); });
@ -91,7 +92,7 @@ async function createApiRouter(
validateSecurity: { validateSecurity: {
handlers: { handlers: {
ApiKeyAuth: async ( ApiKeyAuth: async (
req: express.Request, req: AuthenticatedRequest,
_scopes: unknown, _scopes: unknown,
schema: OpenAPIV3.ApiKeySecurityScheme, schema: OpenAPIV3.ApiKeySecurityScheme,
): Promise<boolean> => { ): Promise<boolean> => {

View file

@ -1,32 +1,8 @@
import type express from 'express';
import type { IDataObject, ExecutionStatus } from 'n8n-workflow'; import type { IDataObject, ExecutionStatus } from 'n8n-workflow';
import type { User } from '@db/entities/User';
import type { WorkflowEntity } from '@db/entities/WorkflowEntity'; import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import type { TagEntity } from '@db/entities/TagEntity'; import type { TagEntity } from '@db/entities/TagEntity';
import type { UserManagementMailer } from '@/UserManagement/email';
import type { Risk } from '@/security-audit/types'; import type { Risk } from '@/security-audit/types';
import type { AuthlessRequest, AuthenticatedRequest } from '@/requests';
export type AuthlessRequest<
RouteParams = {},
ResponseBody = {},
RequestBody = {},
RequestQuery = {},
> = express.Request<RouteParams, ResponseBody, RequestBody, RequestQuery>;
export type AuthenticatedRequest<
RouteParams = {},
ResponseBody = {},
RequestBody = {},
RequestQuery = {},
> = express.Request<RouteParams, ResponseBody, RequestBody, RequestQuery> & {
user: User;
mailer?: UserManagementMailer;
};
export type PaginatedRequest = AuthenticatedRequest< export type PaginatedRequest = AuthenticatedRequest<
{}, {},

View file

@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/no-invalid-void-type */ /* eslint-disable @typescript-eslint/no-invalid-void-type */
import type express from 'express'; import type express from 'express';
import { Container } from 'typedi'; import { Container } from 'typedi';
import type { AuthenticatedRequest, PaginatedRequest } from '../../../types';
import { decodeCursor } from '../services/pagination.service';
import { License } from '@/License'; import { License } from '@/License';
import type { GlobalRole } from '@db/entities/User'; import type { GlobalRole } from '@db/entities/User';
import type { AuthenticatedRequest } from '@/requests';
import type { PaginatedRequest } from '../../../types';
import { decodeCursor } from '../services/pagination.service';
const UNLIMITED_USERS_QUOTA = -1; const UNLIMITED_USERS_QUOTA = -1;
@ -51,7 +52,7 @@ export const validCursor = (
}; };
export const validLicenseWithUserQuota = ( export const validLicenseWithUserQuota = (
req: express.Request, _: express.Request,
res: express.Response, res: express.Response,
next: express.NextFunction, next: express.NextFunction,
): express.Response | void => { ): express.Response | void => {

View file

@ -15,7 +15,6 @@ import { IsBoolean, IsEmail, IsIn, IsOptional, IsString, Length } from 'class-va
import { NoXss } from '@db/utils/customValidators'; import { NoXss } from '@db/utils/customValidators';
import type { PublicUser, SecretsProvider, SecretsProviderState } from '@/Interfaces'; import type { PublicUser, SecretsProvider, SecretsProviderState } from '@/Interfaces';
import { AssignableRole, type User } from '@db/entities/User'; import { AssignableRole, type User } from '@db/entities/User';
import type { UserManagementMailer } from '@/UserManagement/email';
import type { Variables } from '@db/entities/Variables'; import type { Variables } from '@db/entities/Variables';
import type { WorkflowEntity } from '@db/entities/WorkflowEntity'; import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import type { CredentialsEntity } from '@db/entities/CredentialsEntity'; import type { CredentialsEntity } from '@db/entities/CredentialsEntity';
@ -65,7 +64,6 @@ export type AuthenticatedRequest<
RequestQuery = {}, RequestQuery = {},
> = Omit<express.Request<RouteParams, ResponseBody, RequestBody, RequestQuery>, 'user'> & { > = Omit<express.Request<RouteParams, ResponseBody, RequestBody, RequestQuery>, 'user'> & {
user: User; user: User;
mailer?: UserManagementMailer;
}; };
// ---------------------------------- // ----------------------------------