Dependencies upgrade (#510)

This commit is contained in:
Montassar Ghanmy
2024-05-07 17:01:56 +01:00
committed by GitHub
parent 0487ceb7b3
commit 3b20806622
15 changed files with 5080 additions and 5846 deletions
+3273 -4190
View File
File diff suppressed because it is too large Load Diff
+27 -28
View File
@@ -30,7 +30,7 @@
"test:unit:watch": "npm run test:unit -- --watchAll --verbose false | pino-pretty",
"test:merge:json": "npx istanbul report --dir coverage/merged --include 'coverage/**/coverage-final.json' json-summary",
"test:merge:text": "npx istanbul report --dir coverage/merged --include 'coverage/**/coverage-final.json' text > coverage/merged/coverage-report.txt",
"test:all": "jest test --forceExit --coverage --detectOpenHandles --testTimeout=300000 --verbose false --runInBand",
"test:all": "jest test --forceExit --coverage --detectOpenHandles --testTimeout=600000 --verbose false --runInBand",
"kill": "kill $(lsof -t -i:3000) | exit 0"
},
"jest": {
@@ -48,14 +48,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Tdrive/tdrive-backend.git"
"url": "git+https://github.com/linagora/twake-drive.git"
},
"author": "Tdrive",
"license": "ISC",
"bugs": {
"url": "https://github.com/Tdrive/tdrive-backend/issues"
"url": "https://github.com/linagora/twake-drive/issues"
},
"homepage": "https://github.com/Tdrive/tdrive-backend#readme",
"homepage": "https://github.com/linagora/twake-drive#readme",
"bin": {
"tdrive-cli": "bin/tdrive-cli"
},
@@ -98,34 +98,37 @@
"prettier": "^2.1.2",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.2",
"ts-node": "^9.0.0",
"ts-node-dev": "^1.1.8",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"tsc-watch": "^4.2.9",
"tsconfig-paths": "^3.14.1",
"typescript": "^4.9.5"
"tsconfig-paths": "^4.2.0",
"typescript": "^5.4.5"
},
"dependencies": {
"@elastic/elasticsearch": "7",
"@fastify/caching": "^7.0.0",
"@fastify/cookie": "^6.0.0",
"@fastify/formbody": "^6.0.0",
"@fastify/static": "^5.0.1",
"@fastify/caching": "^8.3.0",
"@fastify/cookie": "^9.3.1",
"@fastify/cors": "^9.0.1",
"@fastify/formbody": "^7.4.0",
"@fastify/jwt": "^8.0.0",
"@fastify/multipart": "^8.2.0",
"@fastify/sensible": "^5.6.0",
"@fastify/static": "^7.0.3",
"@fastify/swagger": "^8.14.0",
"@ffprobe-installer/ffprobe": "^1.4.1",
"@opensearch-project/opensearch": "^2.4.0",
"@sentry/node": "^6.19.7",
"@sentry/tracing": "^6.19.7",
"@socket.io/redis-adapter": "^7.2.0",
"@types/http-proxy": "^1.17.11",
"@types/i18n": "^0.13.6",
"@types/pdf-parse": "^1.1.1",
"@types/redis": "^4.0.11",
"@types/http-proxy": "^1.17.14",
"@types/i18n": "^0.13.12",
"@types/pdf-parse": "^1.1.4",
"@types/sharp": "^0.29.5",
"@types/socket.io-parser": "^3.0.0",
"amqp-connection-manager": "^3.7.0",
"amqplib": "^0.8.0",
"analytics-node": "^5.0.0",
"archiver": "^5.3.1",
"axios": "^0.21.3",
"axios": "^1.6.8",
"bcrypt": "^5.0.1",
"cassandra-driver": "^4.6.0",
"class-transformer": "^0.3.1",
@@ -134,29 +137,25 @@
"deep-object-diff": "^1.1.0",
"emoji-name-map": "^1.2.9",
"eta": "^2.2.0",
"fastify": "^3.29.4",
"fastify": "^4.26.2",
"fastify-cors": "^4.1.0",
"fastify-formbody": "^5.0.0",
"fastify-jwt": "^2.2.0",
"fastify-multipart": "5.3.1",
"fastify-plugin": "^2.3.4",
"fastify-plugin": "^4.5.1",
"fastify-sensible": "=3.0.1",
"fastify-socket.io": "^3.0.0",
"fastify-static": "^4.7.0",
"fastify-swagger": "^4.12.6",
"fastify-websocket": "^2.0.11",
"fastify-socket.io": "^5.0.0",
"fastify-websocket": "^4.3.0",
"fluent-ffmpeg": "^2.1.2",
"fold-to-ascii": "^5.0.0",
"free-email-domains": "1.0.26",
"generate-password": "^1.6.0",
"get-website-favicon": "^0.0.7",
"html-metadata-parser": "^2.0.4",
"html-to-text": "^8.2.1",
"i18n": "^0.15.1",
"idtoken-verifier": "^2.2.3",
"jsonwebtoken": "^9.0.0",
"jwks-rsa": "^3.0.1",
"lodash": "^4.17.21",
"loupe": "^3.1.0",
"minio": "^7.1.3",
"moment": "^2.29.4",
"mongodb": "^5.9.2",
@@ -181,7 +180,7 @@
"redis": "3",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.6.3",
"sharp": "^0.33.1",
"sharp": "^0.33.3",
"short-uuid": "^4.2.2",
"socket.io": "^4.6.2",
"socket.io-client": "^3.0.0",
+2 -2
View File
@@ -9,8 +9,8 @@ export interface authenticateDecorator {
declare module "fastify" {
interface FastifyInstance {
authenticate(): void;
authenticateOptional(): void;
authenticate(request: FastifyRequest): void;
authenticateOptional(request: FastifyRequest): void;
io: SocketIO.Server;
}
@@ -9,7 +9,6 @@ export type TdriveLogger = pino.Logger;
export const logger = pino({
name: "TdriveApp",
level: config.get("level", "info") || "info",
prettyPrint: false,
mixin() {
return executionStorage.getStore() ? executionStorage.getStore() : {};
},
@@ -1,5 +1,5 @@
import { FastifyPluginCallback, FastifyRequest } from "fastify";
import fastifyJwt from "fastify-jwt";
import fastifyJwt from "@fastify/jwt";
import cookie from "@fastify/cookie";
import fp from "fastify-plugin";
import config from "../../../../config";
@@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */
import { EntityDefinition } from "../types";
type EntityOption = {
type?: string;
ttl?: number;
@@ -18,11 +16,10 @@ type EntityOption = {
export function Entity(name: string, options: EntityOption): ClassDecorator {
// eslint-disable-next-line @typescript-eslint/ban-types
return function (constructor: Function): void {
const entityDefinition: EntityDefinition = {
constructor.prototype._entity = {
name,
type: options.type || name,
options,
};
constructor.prototype._entity = entityDefinition;
};
}
@@ -115,6 +115,10 @@ export default class StorageService extends TdriveService<StorageAPI> implements
const chunks = options?.totalChunks || 1;
let count = 1;
//check that the file a really exists
await self._read(options?.totalChunks ? `${path}/chunk${count}` : path);
let stream: any;
async function factory(callback: (err?: Error, stream?: Stream) => unknown) {
if (count > chunks) {
@@ -136,6 +140,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
if (decipher) {
stream = stream.pipe(decipher);
}
callback(null, stream);
} catch (err) {
logger.error(err);
callback(err, null);
@@ -163,6 +168,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
stream = stream.pipe(decipher);
} catch (err) {
logger.error("Unable to createDecipheriv: %s", err);
throw err;
}
}
return stream;
@@ -1,19 +1,20 @@
import { logger, TdriveService } from "../../framework";
import { Server, IncomingMessage, ServerResponse } from "http";
import { FastifyInstance, fastify } from "fastify";
import sensible from "fastify-sensible";
import { FastifyInstance, fastify, FastifyRegisterOptions, FastifyServerOptions } from "fastify";
import sensible from "@fastify/sensible";
import multipart from "fastify-multipart";
import formbody from "@fastify/formbody";
import fastifyStatic from "@fastify/static";
import corsPlugin, { FastifyCorsOptions } from "fastify-cors";
import corsPlugin, { FastifyCorsOptions } from "@fastify/cors";
import { serverErrorHandler } from "./error";
import WebServerAPI from "./provider";
import jwtPlugin from "../auth/web/jwt";
import path from "path";
import swaggerPlugin from "fastify-swagger";
import swaggerPlugin, { FastifySwaggerOptions } from "@fastify/swagger";
import { SkipCLI } from "../../framework/decorators/skip";
import fs from "fs";
import { ExecutionContext, executionStorage } from "../../framework/execution-storage";
import { FastifyListenOptions } from "fastify/types/instance";
export default class WebServerService extends TdriveService<WebServerAPI> implements WebServerAPI {
name = "webserver";
@@ -102,9 +103,11 @@ export default class WebServerService extends TdriveService<WebServerAPI> implem
staticCSP: false,
transformStaticCSP: header => header,
exposeRoute: true,
});
} as FastifyRegisterOptions<FastifySwaggerOptions>);
this.server.register(jwtPlugin);
this.server.register(sensible, { errorHandler: false });
this.server.register(sensible, {
errorHandler: false,
} as FastifyRegisterOptions<FastifyServerOptions>);
this.server.register(multipart);
this.server.register(formbody);
this.server.register(corsPlugin, this.configuration.get<FastifyCorsOptions>("cors", {}));
@@ -138,7 +141,10 @@ export default class WebServerService extends TdriveService<WebServerAPI> implem
res.type("text/html").send(stream);
});
await this.server.listen(this.configuration.get<number>("port", 3000), "0.0.0.0");
await this.server.listen({
port: this.configuration.get<number>("port", 3000),
host: "0.0.0.0",
} as FastifyListenOptions);
this.server.ready(err => {
if (err) throw err;
@@ -1,4 +1,4 @@
import { FastifyInstance, FastifyReply, FastifyRequest, HTTPMethods } from "fastify";
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import _ from "lodash";
import { v4 } from "uuid";
import { CrudException } from "../../../../core/platform/framework/api/crud-service";
@@ -155,7 +155,7 @@ export class ApplicationsApiController {
fastify.inject(
{
method: request.method as HTTPMethods,
method: request.method as any,
url: route,
payload: request.body as any,
headers: _.pick(request.headers, "authorization"),
@@ -20,7 +20,7 @@ export class FileController {
if (request.isMultipart()) {
file = await request.file();
}
const q = request.query;
const q: any = request.query;
const options: UploadOptions = {
totalChunks: parseInt(q.resumableTotalChunks || q.total_chunks) || 1,
totalSize: parseInt(q.resumableTotalSize || q.total_size) || 0,
@@ -126,7 +126,7 @@ export class FileController {
file = await request.file();
}
const q = request.query;
const q: any = request.query;
const options: any = {
totalChunks: parseInt(q.resumableTotalChunks || q.total_chunks) || 1,
chunkNumber: parseInt(q.resumableChunkNumber || q.chunk_number) || 1,
@@ -22,7 +22,6 @@ import {
WorkspaceBaseRequest,
WorkspaceInviteDomainBody,
WorkspaceRequest,
WorkspaceUsersBaseRequest,
WorkspaceUsersRequest,
} from "./types";
import { WorkspaceUsersCrudController } from "./controllers/workspace-users";
@@ -52,25 +51,28 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
}
};
const companyCheck = async (request: FastifyRequest<{ Params: WorkspaceBaseRequest }>) => {
await checkUserBelongsToCompany(request.currentUser.id, request.params.company_id);
const companyCheck = async (request: FastifyRequest) => {
await checkUserBelongsToCompany(
request.currentUser.id,
(request.params as WorkspaceBaseRequest).company_id,
);
};
const checkWorkspace = async (request: FastifyRequest<{ Params: WorkspaceUsersBaseRequest }>) => {
const checkWorkspace = async (request: FastifyRequest) => {
const params = request.params as WorkspaceUsersRequest;
const workspace = await gr.services.workspaces.get({
company_id: request.params.company_id,
id: request.params.workspace_id,
company_id: params.company_id,
id: params.workspace_id,
});
if (!workspace) {
throw fastify.httpErrors.notFound(`Workspace ${request.params.workspace_id} not found`);
throw fastify.httpErrors.notFound(`Workspace ${params.workspace_id} not found`);
}
};
const checkUserWorkspace = async (
request: FastifyRequest<{ Params: WorkspaceUsersRequest }>,
): Promise<WorkspaceUser> => {
const companyId = request.params.workspace_id;
const workspaceId = request.params.workspace_id;
const checkUserWorkspace = async (request: FastifyRequest): Promise<WorkspaceUser> => {
const params = request.params as WorkspaceUsersRequest;
const companyId = params.workspace_id;
const workspaceId = params.workspace_id;
const userId = request.currentUser.id;
const workspaceUser = await gr.services.workspaces.getUser({
workspaceId,
@@ -91,14 +93,12 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
return workspaceUser;
};
const checkUserHasCompanyMemberLevel = async (
request: FastifyRequest<{ Params: WorkspaceUsersRequest }>,
) => {
const checkUserHasCompanyMemberLevel = async (request: FastifyRequest) => {
if (!request.currentUser.id) {
throw fastify.httpErrors.forbidden("You must be authenticated");
}
const companyUser = await gr.services.companies.getCompanyUser(
{ id: request.params.company_id },
{ id: (request.params as WorkspaceUsersRequest).company_id },
{ id: request.currentUser.id },
);
@@ -107,15 +107,14 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
}
};
const checkUserIsWorkspaceAdmin = async (
request: FastifyRequest<{ Params: WorkspaceUsersRequest }>,
) => {
const checkUserIsWorkspaceAdmin = async (request: FastifyRequest) => {
if (!request.currentUser.id) {
throw fastify.httpErrors.forbidden("You must be authenticated");
}
const workspaceUser = await checkUserWorkspace(request);
const params = request.params as WorkspaceUsersRequest;
const companyUser = await gr.services.companies.getCompanyUser(
{ id: request.params.company_id },
{ id: params.company_id },
{ id: request.currentUser.id },
);
if (!hasWorkspaceAdminLevel(workspaceUser?.role, companyUser?.role)) {
@@ -123,15 +122,13 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
}
};
const checkUserIsWorkspaceMember = async (
request: FastifyRequest<{ Params: WorkspaceUsersRequest }>,
) => {
const checkUserIsWorkspaceMember = async (request: FastifyRequest) => {
if (!request.currentUser.id) {
throw fastify.httpErrors.forbidden("You must be authenticated");
}
const workspaceUser = await checkUserWorkspace(request);
const companyUser = await gr.services.companies.getCompanyUser(
{ id: request.params.company_id },
{ id: (request.params as WorkspaceUsersRequest).company_id },
{ id: request.currentUser.id },
);
if (!hasWorkspaceMemberLevel(workspaceUser?.role, companyUser?.role)) {
@@ -161,7 +158,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "GET",
url: `${workspacesUrl}`,
preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: getWorkspacesSchema,
handler: workspacesController.list.bind(workspacesController),
});
@@ -170,7 +167,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "GET",
url: `${workspacesUrl}/:id`,
preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: getWorkspaceSchema,
handler: workspacesController.get.bind(workspacesController),
});
@@ -185,7 +182,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST",
url: `${workspacesUrl}`,
preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: createWorkspaceSchema,
handler: workspacesController.save.bind(workspacesController),
});
@@ -194,7 +191,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST",
url: `${workspacesUrl}/:id`,
preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: updateWorkspaceSchema,
handler: workspacesController.save.bind(workspacesController),
});
@@ -203,7 +200,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "DELETE",
url: `${workspacesUrl}/:id`,
preHandler: [accessControl, companyCheck],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
handler: workspacesController.delete.bind(workspacesController),
});
@@ -211,7 +208,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST",
url: `${workspacesUrl}/:id/invite_domain`,
preHandler: [validateDomain, companyCheck],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
handler: workspacesController.setInviteDomain.bind(workspacesController),
});
@@ -219,7 +216,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "GET",
url: `${workspaceUsersUrl}`,
preHandler: [accessControl, companyCheck, checkWorkspace],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: getWorkspaceUsersSchema,
handler: workspaceUsersController.list.bind(workspaceUsersController),
});
@@ -228,7 +225,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "GET",
url: `${workspaceUsersUrl}/:user_id`,
preHandler: [accessControl, companyCheck, checkWorkspace],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: getWorkspaceUserSchema,
handler: workspaceUsersController.get.bind(workspaceUsersController),
});
@@ -237,7 +234,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST",
url: `${workspaceUsersUrl}`,
preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: createWorkspaceUserSchema,
handler: workspaceUsersController.save.bind(workspaceUsersController),
});
@@ -246,7 +243,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST",
url: `${workspaceUsersUrl}/:user_id`,
preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: updateWorkspaceUserSchema,
handler: workspaceUsersController.save.bind(workspaceUsersController),
});
@@ -255,7 +252,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "DELETE",
url: `${workspaceUsersUrl}/:user_id`,
preHandler: [accessControl, companyCheck, checkUserIsWorkspaceAdmin],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: deleteWorkspaceUserSchema,
handler: workspaceUsersController.delete.bind(workspaceUsersController),
});
@@ -269,7 +266,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserHasCompanyMemberLevel,
checkUserIsWorkspaceMember,
],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: inviteWorkspaceUserSchema,
handler: workspaceUsersController.invite.bind(workspaceUsersController),
});
@@ -283,7 +280,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserHasCompanyMemberLevel,
checkUserIsWorkspaceMember,
],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: deleteWorkspacePendingUsersSchema,
handler: workspaceUsersController.deletePending.bind(workspaceUsersController),
});
@@ -297,7 +294,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserHasCompanyMemberLevel,
checkUserIsWorkspaceMember,
],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: getWorkspacePendingUsersSchema,
handler: workspaceUsersController.listPending.bind(workspaceUsersController),
});
@@ -311,7 +308,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserIsWorkspaceMember,
checkUserHasCompanyMemberLevel,
],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: getWorkspaceInviteTokenSchema,
handler: workspaceInviteTokensController.list.bind(workspaceInviteTokensController),
});
@@ -325,7 +322,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserIsWorkspaceMember,
checkUserHasCompanyMemberLevel,
],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: postWorkspaceInviteTokenSchema,
handler: workspaceInviteTokensController.save.bind(workspaceInviteTokensController),
});
@@ -339,7 +336,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
checkUserIsWorkspaceMember,
checkUserHasCompanyMemberLevel,
],
preValidation: [fastify.authenticate],
preValidation: fastify.authenticate,
schema: deleteWorkspaceInviteTokenSchema,
handler: workspaceInviteTokensController.delete.bind(workspaceInviteTokensController),
});
@@ -348,7 +345,7 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, options, next)
method: "POST",
url: "/join",
preHandler: [],
preValidation: [fastify.authenticateOptional],
preValidation: fastify.authenticateOptional,
schema: joinInviteTokenSchema,
handler: workspaceInviteTokensController.join.bind(workspaceInviteTokensController),
});
+1 -1
View File
@@ -1,5 +1,5 @@
import { FastifyReply } from "fastify";
import { HttpErrorCodes } from "fastify-sensible/lib/httpError";
import { HttpErrorCodes } from "@fastify/sensible/lib/httpError";
import { CrudException } from "../core/platform/framework/api/crud-service";
export function handleError(reply: FastifyReply, err: Error): void {
@@ -27,8 +27,8 @@ describe('The PostgresQueryBuilder', () => {
const query = subj.buildSelect(TestDbEntity, filter as { [key: string]: any }, null);
//then
expect(normalizeWhitespace(query[0] as string)).toBe(`SELECT * FROM "test_table" WHERE id = $1 AND company_id = $2 ORDER BY id DESC LIMIT 100 OFFSET 0`);
expect(query[1]).toEqual([filter.id, filter.company_id]);
expect(normalizeWhitespace(query[0] as string)).toBe(`SELECT * FROM "test_table" WHERE company_id = $1 AND id = $2 ORDER BY id DESC LIMIT 100 OFFSET 0`);
expect(query[1]).toEqual([filter.company_id, filter.id]);
});
test('buildSelect query with array in filters', async () => {
+1 -2
View File
@@ -5,7 +5,7 @@
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"target": "ESNext",
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
@@ -13,7 +13,6 @@
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
],
"src/*": ["src/*"]
+1710 -1562
View File
File diff suppressed because it is too large Load Diff