Skip to content

Commit

Permalink
refactor(core): Update auth related typings (no-changelog) (#8686)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored Feb 23, 2024
1 parent 9b0d984 commit 35fb710
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
5 changes: 3 additions & 2 deletions packages/cli/src/PublicApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { InternalHooks } from '@/InternalHooks';
import { License } from '@/License';
import { UserRepository } from '@db/repositories/user.repository';
import { UrlService } from '@/services/url.service';
import type { AuthenticatedRequest } from '@/requests';

async function createApiRouter(
version: string,
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -91,7 +92,7 @@ async function createApiRouter(
validateSecurity: {
handlers: {
ApiKeyAuth: async (
req: express.Request,
req: AuthenticatedRequest,
_scopes: unknown,
schema: OpenAPIV3.ApiKeySecurityScheme,
): Promise<boolean> => {
Expand Down
26 changes: 1 addition & 25 deletions packages/cli/src/PublicApi/types.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
import type express from 'express';
import type { IDataObject, ExecutionStatus } from 'n8n-workflow';

import type { User } from '@db/entities/User';

import type { WorkflowEntity } from '@db/entities/WorkflowEntity';

import type { TagEntity } from '@db/entities/TagEntity';

import type { UserManagementMailer } from '@/UserManagement/email';

import type { Risk } from '@/security-audit/types';

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;
};
import type { AuthlessRequest, AuthenticatedRequest } from '@/requests';

export type PaginatedRequest = AuthenticatedRequest<
{},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/no-invalid-void-type */

import type express from 'express';
import { Container } from 'typedi';

import type { AuthenticatedRequest, PaginatedRequest } from '../../../types';
import { decodeCursor } from '../services/pagination.service';
import { License } from '@/License';
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;

Expand Down Expand Up @@ -51,7 +52,7 @@ export const validCursor = (
};

export const validLicenseWithUserQuota = (
req: express.Request,
_: express.Request,
res: express.Response,
next: express.NextFunction,
): express.Response | void => {
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { IsBoolean, IsEmail, IsIn, IsOptional, IsString, Length } from 'class-va
import { NoXss } from '@db/utils/customValidators';
import type { PublicUser, SecretsProvider, SecretsProviderState } from '@/Interfaces';
import { AssignableRole, type User } from '@db/entities/User';
import type { UserManagementMailer } from '@/UserManagement/email';
import type { Variables } from '@db/entities/Variables';
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import type { CredentialsEntity } from '@db/entities/CredentialsEntity';
Expand Down Expand Up @@ -65,7 +64,6 @@ export type AuthenticatedRequest<
RequestQuery = {},
> = Omit<express.Request<RouteParams, ResponseBody, RequestBody, RequestQuery>, 'user'> & {
user: User;
mailer?: UserManagementMailer;
};

// ----------------------------------
Expand Down

0 comments on commit 35fb710

Please sign in to comment.