diff --git a/packages/nocodb/src/guards/global/global.guard.ts b/packages/nocodb/src/guards/global/global.guard.ts index c0dc6e8ce2..f0ccf8874d 100644 --- a/packages/nocodb/src/guards/global/global.guard.ts +++ b/packages/nocodb/src/guards/global/global.guard.ts @@ -4,6 +4,7 @@ import { lastValueFrom, Observable } from 'rxjs'; import { extractRolesObj } from 'nocodb-sdk'; import type { ExecutionContext } from '@nestjs/common'; import { JwtStrategy } from '~/strategies/jwt.strategy'; +import {Request} from 'express' @Injectable() export class GlobalGuard extends AuthGuard(['jwt']) { @@ -75,7 +76,7 @@ export class GlobalGuard extends AuthGuard(['jwt']) { } private async authenticate( - req: any, + req: Request, user: any = { roles: { guest: true, diff --git a/packages/nocodb/src/helpers/catchError.ts b/packages/nocodb/src/helpers/catchError.ts index 289727f7d9..ce6ab3d288 100644 --- a/packages/nocodb/src/helpers/catchError.ts +++ b/packages/nocodb/src/helpers/catchError.ts @@ -1,4 +1,5 @@ import type { ErrorObject } from 'ajv'; +import {NextFunction,Request,Response} from "express"; export enum DBError { TABLE_EXIST = 'TABLE_EXIST', @@ -384,9 +385,9 @@ export function extractDBError(error): { } export default function ( - requestHandler: (req: any, res: any, next?: any) => any, + requestHandler: (req: Request, res: Response, next?: NextFunction) => any, ) { - return async function (req: any, res: any, next: any) { + return async function (req: Request, res: Response, next?: NextFunction) { try { return await requestHandler(req, res, next); } catch (e) { diff --git a/packages/nocodb/src/interface/config.ts b/packages/nocodb/src/interface/config.ts index 7ec3024000..9fffdcc59e 100644 --- a/packages/nocodb/src/interface/config.ts +++ b/packages/nocodb/src/interface/config.ts @@ -2,6 +2,8 @@ import type { ReqId } from 'pino-http'; import type { Handler } from 'express'; import type * as e from 'express'; import type { Knex } from 'knex'; +import {UserType} from "nocodb-sdk"; +import {User} from "~/models"; export interface Route { path: string; @@ -323,8 +325,9 @@ export interface AppConfig { export interface NcRequest { id?: ReqId; - user?: Record; + user?: UserType | User; ncWorkspaceId?: string; ncProjectId?: string; headers?: Record | IncomingHttpHeaders; + clientIp?: string; } diff --git a/packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts b/packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts index 5b0f70ce57..a9b58627e2 100644 --- a/packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts +++ b/packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts @@ -35,6 +35,7 @@ import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2'; import { BulkDataAliasService } from '~/services/bulk-data-alias.service'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import { sanitizeColumnName } from '~/helpers'; +import {NcRequest} from "~/interface/config"; @Injectable() export class ImportService { @@ -64,7 +65,7 @@ export class ImportService { data: | { models: { model: any; views: any[]; hooks?: any[] }[] } | { model: any; views: any[]; hooks?: any[] }[]; - req: any; + req: NcRequest; externalModels?: Model[]; }) { const hrTime = initTime(); @@ -1051,7 +1052,7 @@ export class ImportService { vw: Partial, views: View[], user: UserType, - req: any, + req: NcRequest, ): Promise { if (vw.is_default) { const view = views.find((a) => a.is_default); @@ -1197,7 +1198,7 @@ export class ImportService { url?: string; file?: any; }; - req: any; + req: NcRequest; }) { const hrTime = initTime(); diff --git a/packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.processor.ts b/packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.processor.ts index a4d09fbaaa..0b236c67b9 100644 --- a/packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.processor.ts +++ b/packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.processor.ts @@ -3,6 +3,7 @@ import { Process, Processor } from '@nestjs/bull'; import { Job } from 'bull'; import { JOBS_QUEUE, JobTypes } from '~/interface/Jobs'; import { MetaDiffsService } from '~/services/meta-diffs.service'; +import {NcRequest} from "~/interface/config"; @Processor(JOBS_QUEUE) export class MetaSyncProcessor { @@ -18,7 +19,7 @@ export class MetaSyncProcessor { baseId: string; sourceId: string; user: any; - req: any; + req: NcRequest; } = job.data; if (info.sourceId === 'all') { diff --git a/packages/nocodb/src/services/api-tokens.service.ts b/packages/nocodb/src/services/api-tokens.service.ts index 8864dffcd7..bcd669e57c 100644 --- a/packages/nocodb/src/services/api-tokens.service.ts +++ b/packages/nocodb/src/services/api-tokens.service.ts @@ -6,6 +6,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { NcError } from '~/helpers/catchError'; import { validatePayload } from '~/helpers'; import { ApiToken } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class ApiTokensService { @@ -17,7 +18,7 @@ export class ApiTokensService { async apiTokenCreate(param: { userId: string; tokenBody: ApiTokenReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ApiTokenReq', @@ -36,7 +37,7 @@ export class ApiTokensService { }); } - async apiTokenDelete(param: { token; user: User; req: any }) { + async apiTokenDelete(param: { token; user: User; req: NcRequest }) { const apiToken = await ApiToken.getByToken(param.token); if ( !extractRolesObj(param.user.roles)[OrgUserRoles.SUPER_ADMIN] && diff --git a/packages/nocodb/src/services/app-hooks/interfaces.ts b/packages/nocodb/src/services/app-hooks/interfaces.ts index 7727d81155..ee2013f535 100644 --- a/packages/nocodb/src/services/app-hooks/interfaces.ts +++ b/packages/nocodb/src/services/app-hooks/interfaces.ts @@ -18,7 +18,7 @@ import type { } from 'nocodb-sdk'; export interface NcBaseEvent extends NcBaseEvent { - req: any; + req: NcRequest; clientId?: string; } diff --git a/packages/nocodb/src/services/attachments.service.ts b/packages/nocodb/src/services/attachments.service.ts index 0da2a8d7ee..7c7e965442 100644 --- a/packages/nocodb/src/services/attachments.service.ts +++ b/packages/nocodb/src/services/attachments.service.ts @@ -10,12 +10,13 @@ import Local from '~/plugins/storage/Local'; import mimetypes, { mimeIcons } from '~/utils/mimeTypes'; import { PresignedUrl } from '~/models'; import { utf8ify } from '~/helpers/stringHelpers'; +import {NcRequest} from "~/interface/config"; @Injectable() export class AttachmentsService { constructor(private readonly appHooksService: AppHooksService) {} - async upload(param: { path?: string; files: FileType[]; req: any }) { + async upload(param: { path?: string; files: FileType[]; req: NcRequest }) { // TODO: add getAjvValidatorMw const filePath = this.sanitizeUrlPath( param.path?.toString()?.split('/') || [''], @@ -92,7 +93,7 @@ export class AttachmentsService { async uploadViaURL(param: { path?: string; urls: AttachmentReqType[]; - req: any; + req: NcRequest; }) { // TODO: add getAjvValidatorMw const filePath = this.sanitizeUrlPath( diff --git a/packages/nocodb/src/services/base-users/base-users.service.ts b/packages/nocodb/src/services/base-users/base-users.service.ts index 50b65a2834..6f466cc1bd 100644 --- a/packages/nocodb/src/services/base-users/base-users.service.ts +++ b/packages/nocodb/src/services/base-users/base-users.service.ts @@ -23,6 +23,7 @@ import { Base, BaseUser, User } from '~/models'; import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals'; import { extractProps } from '~/helpers/extractProps'; import { getProjectRolePower } from '~/utils/roleHelper'; +import {NcRequest} from "~/interface/config"; @Injectable() export class BaseUsersService { @@ -47,7 +48,7 @@ export class BaseUsersService { async userInvite(param: { baseId: string; baseUser: ProjectUserReqType; - req: any; + req: NcRequest; }): Promise { validatePayload( 'swagger.json#/components/schemas/ProjectUserReq', diff --git a/packages/nocodb/src/services/bases.service.ts b/packages/nocodb/src/services/bases.service.ts index 2353d93ddd..8a179bb385 100644 --- a/packages/nocodb/src/services/bases.service.ts +++ b/packages/nocodb/src/services/bases.service.ts @@ -24,6 +24,7 @@ import { getToolDir } from '~/utils/nc-config'; import { MetaService } from '~/meta/meta.service'; import { MetaTable } from '~/utils/globals'; import { TablesService } from '~/services/tables.service'; +import {NcRequest} from "~/interface/config"; const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4); @@ -36,7 +37,7 @@ export class BasesService { ) {} async baseList(param: { - user: { id: string; roles: Record }; + user: { id: string; roles?: string | Record}; query?: any; }) { const bases = extractRolesObj(param.user?.roles)[OrgUserRoles.SUPER_ADMIN] @@ -63,7 +64,7 @@ export class BasesService { baseId: string; base: ProjectUpdateReqType; user: UserType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ProjectUpdateReq', @@ -101,7 +102,7 @@ export class BasesService { } } - async baseSoftDelete(param: { baseId: any; user: UserType; req: any }) { + async baseSoftDelete(param: { baseId: any; user: UserType; req: NcRequest }) { const base = await Base.getWithInfo(param.baseId); if (!base) { @@ -119,7 +120,7 @@ export class BasesService { return true; } - async baseCreate(param: { base: ProjectReqType; user: any; req: any }) { + async baseCreate(param: { base: ProjectReqType; user: any; req: NcRequest }) { validatePayload('swagger.json#/components/schemas/ProjectReq', param.base); const baseId = await this.metaService.genNanoid(MetaTable.PROJECT); @@ -225,7 +226,7 @@ export class BasesService { return base; } - async createDefaultBase(param: { user: UserType; req: any }) { + async createDefaultBase(param: { user: UserType; req: NcRequest }) { const base = await this.baseCreate({ base: { title: 'Getting Started', diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 0a08c0670b..db3126b8d4 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -47,6 +47,7 @@ import Noco from '~/Noco'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import { MetaTable } from '~/utils/globals'; import { MetaService } from '~/meta/meta.service'; +import {NcRequest} from "~/interface/config"; // todo: move export enum Altered { @@ -1030,7 +1031,7 @@ export class ColumnsService { } async columnAdd(param: { - req: any; + req: NcRequest; tableId: string; column: ColumnReqType; user: UserType; @@ -2194,7 +2195,7 @@ export class ColumnsService { column: Partial; }[]; }, - req: any, + req: NcRequest, ) { // TODO validatePayload diff --git a/packages/nocodb/src/services/filters.service.ts b/packages/nocodb/src/services/filters.service.ts index 8c419942a8..23e7e9295b 100644 --- a/packages/nocodb/src/services/filters.service.ts +++ b/packages/nocodb/src/services/filters.service.ts @@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { Filter, Hook, View } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class FiltersService { @@ -14,7 +15,7 @@ export class FiltersService { filter: FilterReqType; hookId: any; user: UserType; - req: any; + req: NcRequest; }) { validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); @@ -41,7 +42,7 @@ export class FiltersService { return Filter.rootFilterListByHook({ hookId: param.hookId }); } - async filterDelete(param: { filterId: string; req: any }) { + async filterDelete(param: { filterId: string; req: NcRequest }) { const filter = await Filter.get(param.filterId); if (!filter) { @@ -62,7 +63,7 @@ export class FiltersService { filter: FilterReqType; viewId: string; user: UserType; - req: any; + req: NcRequest; }) { validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); @@ -86,7 +87,7 @@ export class FiltersService { filter: FilterReqType; filterId: string; user: UserType; - req: any; + req: NcRequest; }) { validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); diff --git a/packages/nocodb/src/services/form-columns.service.ts b/packages/nocodb/src/services/form-columns.service.ts index 6c8b917a2f..cddf40b133 100644 --- a/packages/nocodb/src/services/form-columns.service.ts +++ b/packages/nocodb/src/services/form-columns.service.ts @@ -3,6 +3,7 @@ import { AppEvents } from 'nocodb-sdk'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { FormViewColumn } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class FormColumnsService { @@ -12,7 +13,7 @@ export class FormColumnsService { formViewColumnId: string; // todo: replace with FormColumnReq formViewColumn: FormViewColumn; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/FormColumnReq', diff --git a/packages/nocodb/src/services/forms.service.ts b/packages/nocodb/src/services/forms.service.ts index 612fa76395..be76e6f051 100644 --- a/packages/nocodb/src/services/forms.service.ts +++ b/packages/nocodb/src/services/forms.service.ts @@ -9,6 +9,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { FormView, View } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class FormsService { @@ -23,7 +24,7 @@ export class FormsService { tableId: string; body: ViewCreateReqType; user: UserType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ViewCreateReq', @@ -55,7 +56,7 @@ export class FormsService { async formViewUpdate(param: { formViewId: string; form: FormUpdateReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/FormUpdateReq', diff --git a/packages/nocodb/src/services/galleries.service.ts b/packages/nocodb/src/services/galleries.service.ts index 55b0397032..7f20af63ea 100644 --- a/packages/nocodb/src/services/galleries.service.ts +++ b/packages/nocodb/src/services/galleries.service.ts @@ -9,6 +9,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { GalleryView, View } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class GalleriesService { @@ -23,7 +24,7 @@ export class GalleriesService { gallery: ViewCreateReqType; user: UserType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ViewCreateReq', @@ -48,7 +49,7 @@ export class GalleriesService { async galleryViewUpdate(param: { galleryViewId: string; gallery: GalleryUpdateReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/GalleryUpdateReq', diff --git a/packages/nocodb/src/services/grid-columns.service.ts b/packages/nocodb/src/services/grid-columns.service.ts index 6da1c3b7e4..6cf59a14e0 100644 --- a/packages/nocodb/src/services/grid-columns.service.ts +++ b/packages/nocodb/src/services/grid-columns.service.ts @@ -4,6 +4,7 @@ import type { GridColumnReqType } from 'nocodb-sdk'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { GridViewColumn } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class GridColumnsService { @@ -16,7 +17,7 @@ export class GridColumnsService { async gridColumnUpdate(param: { gridViewColumnId: string; grid: GridColumnReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/GridColumnReq', diff --git a/packages/nocodb/src/services/grids.service.ts b/packages/nocodb/src/services/grids.service.ts index a78438ffdb..31fd69d7b1 100644 --- a/packages/nocodb/src/services/grids.service.ts +++ b/packages/nocodb/src/services/grids.service.ts @@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { GridView, View } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class GridsService { @@ -13,7 +14,7 @@ export class GridsService { async gridViewCreate(param: { tableId: string; grid: ViewCreateReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ViewCreateReq', @@ -39,7 +40,7 @@ export class GridsService { async gridViewUpdate(param: { viewId: string; grid: GridUpdateReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/GridUpdateReq', diff --git a/packages/nocodb/src/services/hooks.service.ts b/packages/nocodb/src/services/hooks.service.ts index ac39261bc2..bdd0625e4f 100644 --- a/packages/nocodb/src/services/hooks.service.ts +++ b/packages/nocodb/src/services/hooks.service.ts @@ -10,6 +10,7 @@ import { } from '~/helpers/populateSamplePayload'; import { invokeWebhook } from '~/helpers/webhookHelpers'; import { Hook, HookLog, Model } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class HooksService { @@ -37,7 +38,7 @@ export class HooksService { return await HookLog.list({ fk_hook_id: param.hookId }, param.query); } - async hookCreate(param: { tableId: string; hook: HookReqType; req: any }) { + async hookCreate(param: { tableId: string; hook: HookReqType; req: NcRequest }) { validatePayload('swagger.json#/components/schemas/HookReq', param.hook); this.validateHookPayload(param.hook.notification); @@ -55,7 +56,7 @@ export class HooksService { return hook; } - async hookDelete(param: { hookId: string; req: any }) { + async hookDelete(param: { hookId: string; req: NcRequest }) { const hook = await Hook.get(param.hookId); if (!hook) { @@ -70,7 +71,7 @@ export class HooksService { return true; } - async hookUpdate(param: { hookId: string; hook: HookReqType; req: any }) { + async hookUpdate(param: { hookId: string; hook: HookReqType; req: NcRequest }) { validatePayload('swagger.json#/components/schemas/HookReq', param.hook); const hook = await Hook.get(param.hookId); @@ -97,7 +98,7 @@ export class HooksService { async hookTest(param: { tableId: string; hookTest: HookTestReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/HookTestReq', diff --git a/packages/nocodb/src/services/kanbans.service.ts b/packages/nocodb/src/services/kanbans.service.ts index 9ffba866df..645cf8bebe 100644 --- a/packages/nocodb/src/services/kanbans.service.ts +++ b/packages/nocodb/src/services/kanbans.service.ts @@ -9,6 +9,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { KanbanView, View } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class KanbansService { @@ -22,7 +23,7 @@ export class KanbansService { tableId: string; kanban: ViewCreateReqType; user: UserType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ViewCreateReq', @@ -50,7 +51,7 @@ export class KanbansService { async kanbanViewUpdate(param: { kanbanViewId: string; kanban: KanbanUpdateReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/KanbanUpdateReq', diff --git a/packages/nocodb/src/services/maps.service.ts b/packages/nocodb/src/services/maps.service.ts index 8feafc1c5c..15d5d775c1 100644 --- a/packages/nocodb/src/services/maps.service.ts +++ b/packages/nocodb/src/services/maps.service.ts @@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { MapView, View } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class MapsService { @@ -18,7 +19,7 @@ export class MapsService { tableId: string; map: ViewCreateReqType; user: UserType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ViewCreateReq', @@ -44,7 +45,7 @@ export class MapsService { async mapViewUpdate(param: { mapViewId: string; map: MapUpdateReqType; - req: any; + req: NcRequest; }) { validatePayload('swagger.json#/components/schemas/MapUpdateReq', param.map); diff --git a/packages/nocodb/src/services/model-visibilities.service.ts b/packages/nocodb/src/services/model-visibilities.service.ts index 63dba190cb..ef316f2417 100644 --- a/packages/nocodb/src/services/model-visibilities.service.ts +++ b/packages/nocodb/src/services/model-visibilities.service.ts @@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { Base, Model, ModelRoleVisibility, View } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class ModelVisibilitiesService { @@ -13,7 +14,7 @@ export class ModelVisibilitiesService { async xcVisibilityMetaSetAll(param: { visibilityRule: VisibilityRuleReqType; baseId: string; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/VisibilityRuleReq', diff --git a/packages/nocodb/src/services/notifications.service.ts b/packages/nocodb/src/services/notifications.service.ts index 97e8791416..f50101dc12 100644 --- a/packages/nocodb/src/services/notifications.service.ts +++ b/packages/nocodb/src/services/notifications.service.ts @@ -10,6 +10,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { NcError } from '~/helpers/catchError'; import { PagedResponseImpl } from '~/helpers/PagedResponse'; import { Notification } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class NotificationsService implements OnModuleInit, OnModuleDestroy { @@ -17,7 +18,7 @@ export class NotificationsService implements OnModuleInit, OnModuleDestroy { protected async insertNotification( insertData: Partial, - req: any, + req: NcRequest, ) { this.appHooks.emit('notification' as any, { ...insertData, req } as any); diff --git a/packages/nocodb/src/services/org-tokens.service.ts b/packages/nocodb/src/services/org-tokens.service.ts index 4cfe2369e9..399a61367b 100644 --- a/packages/nocodb/src/services/org-tokens.service.ts +++ b/packages/nocodb/src/services/org-tokens.service.ts @@ -7,6 +7,7 @@ import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { PagedResponseImpl } from '~/helpers/PagedResponse'; import { ApiToken } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class OrgTokensService { @@ -38,7 +39,7 @@ export class OrgTokensService { async apiTokenCreate(param: { user: User; apiToken: ApiTokenReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ApiTokenReq', @@ -60,7 +61,7 @@ export class OrgTokensService { return apiToken; } - async apiTokenDelete(param: { user: User; token: string; req: any }) { + async apiTokenDelete(param: { user: User; token: string; req: NcRequest }) { const fk_user_id = param.user.id; const apiToken = await ApiToken.getByToken(param.token); if ( diff --git a/packages/nocodb/src/services/org-users.service.ts b/packages/nocodb/src/services/org-users.service.ts index 97eb709664..d5dd80ab53 100644 --- a/packages/nocodb/src/services/org-users.service.ts +++ b/packages/nocodb/src/services/org-users.service.ts @@ -19,6 +19,7 @@ import { BaseUser, Store, SyncSource, User } from '~/models'; import Noco from '~/Noco'; import { MetaTable } from '~/utils/globals'; +import {NcRequest} from "~/interface/config"; @Injectable() export class OrgUsersService { @@ -91,7 +92,7 @@ export class OrgUsersService { async userAdd(param: { user: UserType; // todo: refactor - req: any; + req: NcRequest; }) { validatePayload('swagger.json#/components/schemas/OrgUserReq', param.user); @@ -193,7 +194,7 @@ export class OrgUsersService { NcError.notImplemented(); } - async userInviteResend(param: { userId: string; req: any }): Promise { + async userInviteResend(param: { userId: string; req: NcRequest }): Promise { const user = await User.get(param.userId); if (!user) { diff --git a/packages/nocodb/src/services/plugins.service.ts b/packages/nocodb/src/services/plugins.service.ts index c80f932496..8dd1fac0ea 100644 --- a/packages/nocodb/src/services/plugins.service.ts +++ b/packages/nocodb/src/services/plugins.service.ts @@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2'; import { Plugin } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class PluginsService { @@ -14,7 +15,7 @@ export class PluginsService { return await Plugin.list(); } - async pluginTest(param: { body: PluginTestReqType; req: any }) { + async pluginTest(param: { body: PluginTestReqType; req: NcRequest }) { validatePayload( 'swagger.json#/components/schemas/PluginTestReq', param.body, @@ -33,7 +34,7 @@ export class PluginsService { async pluginUpdate(param: { pluginId: string; plugin: PluginType; - req: any; + req: NcRequest; }) { validatePayload('swagger.json#/components/schemas/PluginReq', param.plugin); diff --git a/packages/nocodb/src/services/shared-bases.service.ts b/packages/nocodb/src/services/shared-bases.service.ts index 33e24d377d..894bb4b2e1 100644 --- a/packages/nocodb/src/services/shared-bases.service.ts +++ b/packages/nocodb/src/services/shared-bases.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { AppEvents } from 'nocodb-sdk'; import { v4 as uuidv4 } from 'uuid'; import { ConfigService } from '@nestjs/config'; -import type { AppConfig } from '~/interface/config'; +import type {AppConfig, NcRequest} from '~/interface/config'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; @@ -26,7 +26,7 @@ export class SharedBasesService { password: string; siteUrl: string; - req: any; + req: NcRequest; }): Promise { validatePayload('swagger.json#/components/schemas/SharedBaseReq', param); @@ -74,7 +74,7 @@ export class SharedBasesService { roles: string; password: string; siteUrl: string; - req: any; + req: NcRequest; }): Promise { validatePayload('swagger.json#/components/schemas/SharedBaseReq', param); @@ -132,7 +132,7 @@ export class SharedBasesService { async disableSharedBaseLink(param: { baseId: string; - req: any; + req: NcRequest; }): Promise { const base = await Base.get(param.baseId); diff --git a/packages/nocodb/src/services/sorts.service.ts b/packages/nocodb/src/services/sorts.service.ts index cdcae1a714..df0bff9dff 100644 --- a/packages/nocodb/src/services/sorts.service.ts +++ b/packages/nocodb/src/services/sorts.service.ts @@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { Sort } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class SortsService { @@ -14,7 +15,7 @@ export class SortsService { return Sort.get(param.sortId); } - async sortDelete(param: { sortId: string; req: any }) { + async sortDelete(param: { sortId: string; req: NcRequest }) { const sort = await Sort.get(param.sortId); if (!sort) { @@ -30,7 +31,7 @@ export class SortsService { return true; } - async sortUpdate(param: { sortId: any; sort: SortReqType; req: any }) { + async sortUpdate(param: { sortId: any; sort: SortReqType; req: NcRequest }) { validatePayload('swagger.json#/components/schemas/SortReq', param.sort); const sort = await Sort.get(param.sortId); @@ -50,7 +51,7 @@ export class SortsService { return res; } - async sortCreate(param: { viewId: any; sort: SortReqType; req: any }) { + async sortCreate(param: { viewId: any; sort: SortReqType; req: NcRequest }) { validatePayload('swagger.json#/components/schemas/SortReq', param.sort); const sort = await Sort.insert({ diff --git a/packages/nocodb/src/services/sources.service.ts b/packages/nocodb/src/services/sources.service.ts index e808e63ffb..387866b7a6 100644 --- a/packages/nocodb/src/services/sources.service.ts +++ b/packages/nocodb/src/services/sources.service.ts @@ -7,6 +7,7 @@ import { populateRollupColumnAndHideLTAR } from '~/helpers/populateMeta'; import { syncBaseMigration } from '~/helpers/syncMigration'; import { Base, Source } from '~/models'; import { NcError } from '~/helpers/catchError'; +import {NcRequest} from "~/interface/config"; @Injectable() export class SourcesService { @@ -24,7 +25,7 @@ export class SourcesService { sourceId: string; source: BaseReqType; baseId: string; - req: any; + req: NcRequest; }) { validatePayload('swagger.json#/components/schemas/BaseReq', param.source); @@ -53,7 +54,7 @@ export class SourcesService { return sources; } - async baseDelete(param: { sourceId: string; req: any }) { + async baseDelete(param: { sourceId: string; req: NcRequest }) { try { const source = await Source.get(param.sourceId, true); await source.delete(); @@ -81,7 +82,7 @@ export class SourcesService { baseId: string; source: BaseReqType; logger?: (message: string) => void; - req: any; + req: NcRequest; }) { validatePayload('swagger.json#/components/schemas/BaseReq', param.source); diff --git a/packages/nocodb/src/services/sync.service.ts b/packages/nocodb/src/services/sync.service.ts index cba066407e..5524216195 100644 --- a/packages/nocodb/src/services/sync.service.ts +++ b/packages/nocodb/src/services/sync.service.ts @@ -4,6 +4,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { NcError } from '~/helpers/catchError'; import { PagedResponseImpl } from '~/helpers/PagedResponse'; import { Base, SyncSource } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class SyncService { @@ -20,7 +21,7 @@ export class SyncService { sourceId?: string; userId: string; syncPayload: Partial; - req: any; + req: NcRequest; }) { const base = await Base.getWithInfo(param.baseId); @@ -39,7 +40,7 @@ export class SyncService { return sync; } - async syncDelete(param: { syncId: string; req: any }) { + async syncDelete(param: { syncId: string; req: NcRequest }) { const syncSource = await SyncSource.get(param.syncId); if (!syncSource) { @@ -58,7 +59,7 @@ export class SyncService { async syncUpdate(param: { syncId: string; syncPayload: Partial; - req: any; + req: NcRequest; }) { const syncSource = await SyncSource.get(param.syncId); diff --git a/packages/nocodb/src/services/tables.service.ts b/packages/nocodb/src/services/tables.service.ts index 2a8f6ec661..8d21d0873c 100644 --- a/packages/nocodb/src/services/tables.service.ts +++ b/packages/nocodb/src/services/tables.service.ts @@ -29,6 +29,7 @@ import { Base, Column, Model, ModelRoleVisibility } from '~/models'; import Noco from '~/Noco'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import { sanitizeColumnName, validatePayload } from '~/helpers'; +import {NcRequest} from "~/interface/config"; @Injectable() export class TablesService { @@ -43,7 +44,7 @@ export class TablesService { table: TableReqType & { base_id?: string }; baseId?: string; user: UserType; - req: any; + req: NcRequest; }) { const model = await Model.get(param.tableId); diff --git a/packages/nocodb/src/services/users/users.service.ts b/packages/nocodb/src/services/users/users.service.ts index e6c782fc7a..4076b5be53 100644 --- a/packages/nocodb/src/services/users/users.service.ts +++ b/packages/nocodb/src/services/users/users.service.ts @@ -26,6 +26,7 @@ import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2'; import { NcError } from '~/helpers/catchError'; import { BasesService } from '~/services/bases.service'; import { extractProps } from '~/helpers/extractProps'; +import {NcRequest} from "~/interface/config"; @Injectable() export class UsersService { @@ -97,7 +98,7 @@ export class UsersService { salt: any; password; email_verification_token; - req: any; + req: NcRequest; }) { this.validateEmailPattern(email); @@ -149,7 +150,7 @@ export class UsersService { async passwordChange(param: { body: PasswordChangeReqType; user: UserType; - req: any; + req: NcRequest; }): Promise { validatePayload( 'swagger.json#/components/schemas/PasswordChangeReq', @@ -202,7 +203,7 @@ export class UsersService { async passwordForgot(param: { body: PasswordForgotReqType; siteUrl: string; - req: any; + req: NcRequest; }): Promise { validatePayload( 'swagger.json#/components/schemas/PasswordForgotReq', @@ -279,7 +280,7 @@ export class UsersService { async passwordReset(param: { body: PasswordResetReqType; token: string; - req: any; + req: NcRequest; }): Promise { validatePayload( 'swagger.json#/components/schemas/PasswordResetReq', @@ -332,7 +333,7 @@ export class UsersService { async emailVerification(param: { token: string; // todo: exclude - req: any; + req: NcRequest; }): Promise { const { token, req } = param; diff --git a/packages/nocodb/src/services/view-columns.service.ts b/packages/nocodb/src/services/view-columns.service.ts index 69fc81421f..09daf25abb 100644 --- a/packages/nocodb/src/services/view-columns.service.ts +++ b/packages/nocodb/src/services/view-columns.service.ts @@ -4,6 +4,7 @@ import type { ViewColumnReqType, ViewColumnUpdateReqType } from 'nocodb-sdk'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { View } from '~/models'; +import {NcRequest} from "~/interface/config"; @Injectable() export class ViewColumnsService { @@ -15,7 +16,7 @@ export class ViewColumnsService { async columnAdd(param: { viewId: string; column: ViewColumnReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ViewColumnReq', @@ -42,7 +43,7 @@ export class ViewColumnsService { viewId: string; columnId: string; column: ViewColumnUpdateReqType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ViewColumnUpdateReq', diff --git a/packages/nocodb/src/services/views.service.ts b/packages/nocodb/src/services/views.service.ts index ba0e5ce5b5..664c5e182d 100644 --- a/packages/nocodb/src/services/views.service.ts +++ b/packages/nocodb/src/services/views.service.ts @@ -9,6 +9,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { Model, ModelRoleVisibility, View } from '~/models'; +import {NcRequest} from "~/interface/config"; // todo: move async function xcVisibilityMetaGet(param: { @@ -69,8 +70,8 @@ export class ViewsService { async viewList(param: { tableId: string; user: { - roles: Record; - base_roles: Record; + roles?: Record | string, + base_roles?: Record; }; }) { const model = await Model.get(param.tableId); @@ -91,7 +92,7 @@ export class ViewsService { return filteredViewList; } - async shareView(param: { viewId: string; user: UserType; req: any }) { + async shareView(param: { viewId: string; user: UserType; req: NcRequest }) { const res = await View.share(param.viewId); const view = await View.get(param.viewId); @@ -113,7 +114,7 @@ export class ViewsService { viewId: string; view: ViewUpdateReqType; user: UserType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/ViewUpdateReq', @@ -140,7 +141,7 @@ export class ViewsService { return result; } - async viewDelete(param: { viewId: string; user: UserType; req: any }) { + async viewDelete(param: { viewId: string; user: UserType; req: NcRequest }) { const view = await View.get(param.viewId); if (!view) { @@ -162,7 +163,7 @@ export class ViewsService { viewId: string; sharedView: SharedViewReqType; user: UserType; - req: any; + req: NcRequest; }) { validatePayload( 'swagger.json#/components/schemas/SharedViewReq', @@ -186,7 +187,7 @@ export class ViewsService { return result; } - async shareViewDelete(param: { viewId: string; user: UserType; req: any }) { + async shareViewDelete(param: { viewId: string; user: UserType; req: NcRequest }) { const view = await View.get(param.viewId); if (!view) { diff --git a/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts b/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts index 6c0446a354..8010f172f0 100644 --- a/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts +++ b/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts @@ -4,11 +4,12 @@ import { extractRolesObj, ProjectRoles } from 'nocodb-sdk'; import { Strategy } from 'passport-custom'; import { ApiToken, BaseUser, User } from '~/models'; import { sanitiseUserObj } from '~/utils'; +import {Request} from 'express' @Injectable() export class AuthTokenStrategy extends PassportStrategy(Strategy, 'authtoken') { // eslint-disable-next-line @typescript-eslint/ban-types - async validate(req: any, callback: Function) { + async validate(req: Request, callback: Function) { try { let user; if (req.headers['xc-token']) { diff --git a/packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts b/packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts index 6f301465b4..4db70ccb27 100644 --- a/packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts +++ b/packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts @@ -3,11 +3,13 @@ import { PassportStrategy } from '@nestjs/passport'; import { Strategy } from 'passport-custom'; import { extractRolesObj } from 'nocodb-sdk'; import { Base } from '~/models'; +import {Request} from 'express' + @Injectable() export class BaseViewStrategy extends PassportStrategy(Strategy, 'base-view') { // eslint-disable-next-line @typescript-eslint/ban-types - async validate(req: any, callback: Function) { + async validate(req: Request, callback: Function) { try { let user; if (req.headers['xc-shared-base-id']) { diff --git a/packages/nocodb/src/strategies/google.strategy/google.strategy.ts b/packages/nocodb/src/strategies/google.strategy/google.strategy.ts index bf8d145d07..6d310d6491 100644 --- a/packages/nocodb/src/strategies/google.strategy/google.strategy.ts +++ b/packages/nocodb/src/strategies/google.strategy/google.strategy.ts @@ -9,6 +9,7 @@ import Noco from '~/Noco'; import { UsersService } from '~/services/users/users.service'; import { BaseUser, Plugin, User } from '~/models'; import { sanitiseUserObj } from '~/utils'; +import {Request} from 'express' @Injectable() export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { @@ -20,7 +21,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { } async validate( - req: any, + req: Request, accessToken: string, refreshToken: string, profile: any, @@ -72,7 +73,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { return params; } - async authenticate(req: any, options?: any): Promise { + async authenticate(req: Request, options?: any): Promise { const googlePlugin = await Plugin.getPluginByTitle('Google'); if (googlePlugin && googlePlugin.input) { diff --git a/packages/nocodb/src/types/express.d.ts b/packages/nocodb/src/types/express.d.ts index 10f041fa6f..c74cd6cca6 100644 --- a/packages/nocodb/src/types/express.d.ts +++ b/packages/nocodb/src/types/express.d.ts @@ -1,5 +1,7 @@ import * as express from 'express'; import { Express } from 'express-serve-static-core'; +import type { UserType } from 'nocodb-sdk'; +import { User } from '~/models'; // declare global { // namespace Express { @@ -20,7 +22,11 @@ declare module 'express-serve-static-core' { interface Request { ncWorkspaceId?: string; ncProjectId?: string; - user: any; + user: UserType & { + base_roles?: Record; + workspace_roles?: Record; + provider?: string; + }; ncSiteUrl: string; clientIp: string; }