Browse Source

refactor: proper custom request type in service and other files

pull/6914/head
Pranav C 1 year ago
parent
commit
d61424c3e6
  1. 3
      packages/nocodb/src/guards/global/global.guard.ts
  2. 5
      packages/nocodb/src/helpers/catchError.ts
  3. 5
      packages/nocodb/src/interface/config.ts
  4. 7
      packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts
  5. 3
      packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.processor.ts
  6. 5
      packages/nocodb/src/services/api-tokens.service.ts
  7. 2
      packages/nocodb/src/services/app-hooks/interfaces.ts
  8. 5
      packages/nocodb/src/services/attachments.service.ts
  9. 3
      packages/nocodb/src/services/base-users/base-users.service.ts
  10. 11
      packages/nocodb/src/services/bases.service.ts
  11. 5
      packages/nocodb/src/services/columns.service.ts
  12. 9
      packages/nocodb/src/services/filters.service.ts
  13. 3
      packages/nocodb/src/services/form-columns.service.ts
  14. 5
      packages/nocodb/src/services/forms.service.ts
  15. 5
      packages/nocodb/src/services/galleries.service.ts
  16. 3
      packages/nocodb/src/services/grid-columns.service.ts
  17. 5
      packages/nocodb/src/services/grids.service.ts
  18. 9
      packages/nocodb/src/services/hooks.service.ts
  19. 5
      packages/nocodb/src/services/kanbans.service.ts
  20. 5
      packages/nocodb/src/services/maps.service.ts
  21. 3
      packages/nocodb/src/services/model-visibilities.service.ts
  22. 3
      packages/nocodb/src/services/notifications.service.ts
  23. 5
      packages/nocodb/src/services/org-tokens.service.ts
  24. 5
      packages/nocodb/src/services/org-users.service.ts
  25. 5
      packages/nocodb/src/services/plugins.service.ts
  26. 8
      packages/nocodb/src/services/shared-bases.service.ts
  27. 7
      packages/nocodb/src/services/sorts.service.ts
  28. 7
      packages/nocodb/src/services/sources.service.ts
  29. 7
      packages/nocodb/src/services/sync.service.ts
  30. 3
      packages/nocodb/src/services/tables.service.ts
  31. 11
      packages/nocodb/src/services/users/users.service.ts
  32. 5
      packages/nocodb/src/services/view-columns.service.ts
  33. 15
      packages/nocodb/src/services/views.service.ts
  34. 3
      packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts
  35. 4
      packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts
  36. 5
      packages/nocodb/src/strategies/google.strategy/google.strategy.ts
  37. 8
      packages/nocodb/src/types/express.d.ts

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

5
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) {

5
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<string, any>;
user?: UserType | User;
ncWorkspaceId?: string;
ncProjectId?: string;
headers?: Record<string, string | undefined> | IncomingHttpHeaders;
clientIp?: string;
}

7
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<View>,
views: View[],
user: UserType,
req: any,
req: NcRequest,
): Promise<View> {
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();

3
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') {

5
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] &&

2
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;
}

5
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(

3
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<any> {
validatePayload(
'swagger.json#/components/schemas/ProjectUserReq',

11
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<string, boolean> };
user: { id: string; roles?: string | Record<string, boolean>};
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',

5
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<Column>;
}[];
},
req: any,
req: NcRequest,
) {
// TODO validatePayload

9
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);

3
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',

5
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',

5
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',

3
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',

5
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',

9
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',

5
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',

5
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);

3
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',

3
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<Notification>,
req: any,
req: NcRequest,
) {
this.appHooks.emit('notification' as any, { ...insertData, req } as any);

5
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 (

5
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<any> {
async userInviteResend(param: { userId: string; req: NcRequest }): Promise<any> {
const user = await User.get(param.userId);
if (!user) {

5
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);

8
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<any> {
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<any> {
validatePayload('swagger.json#/components/schemas/SharedBaseReq', param);
@ -132,7 +132,7 @@ export class SharedBasesService {
async disableSharedBaseLink(param: {
baseId: string;
req: any;
req: NcRequest;
}): Promise<any> {
const base = await Base.get(param.baseId);

7
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({

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

7
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<SyncSource>;
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<SyncSource>;
req: any;
req: NcRequest;
}) {
const syncSource = await SyncSource.get(param.syncId);

3
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);

11
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<any> {
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<any> {
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<any> {
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<any> {
const { token, req } = param;

5
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',

15
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<string, boolean>;
base_roles: Record<string, boolean>;
roles?: Record<string, boolean> | string,
base_roles?: Record<string, boolean>;
};
}) {
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) {

3
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']) {

4
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']) {

5
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<void> {
async authenticate(req: Request, options?: any): Promise<void> {
const googlePlugin = await Plugin.getPluginByTitle('Google');
if (googlePlugin && googlePlugin.input) {

8
packages/nocodb/src/types/express.d.ts vendored

@ -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<string, boolean>;
workspace_roles?: Record<string, boolean>;
provider?: string;
};
ncSiteUrl: string;
clientIp: string;
}

Loading…
Cancel
Save