Compare commits

...

21 Commits

Author SHA1 Message Date
Philip Okugbe 72f64e7b10 revert sentry (#808)
* revert sentry
* remove sentry env
2025-02-27 15:58:32 +00:00
Philipinho 3cfb17bb62 fix sentry 2025-02-27 14:44:28 +00:00
Philipinho fe5066c7b5 v0.8.4 2025-02-27 14:34:38 +00:00
Philipinho e13be904cd cleanup 2025-02-27 14:18:25 +00:00
Philip Okugbe fda5c7d60f push files left (#360) (#804) 2025-02-26 18:33:50 +00:00
Peter Shcherbakov 7fc1a782a7 feat: add copy invite link to invitation action menu (#360)
* +copy invite link to clipboard from invite action menu

* -remove log to console for copy link action

* Refactor copy invite link feature

---------

Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
2025-02-26 18:28:44 +00:00
Philipinho 54d27af76a * Add SENTRY_DNS env variable
* Commit lock file
2025-02-26 17:38:25 +00:00
Philip Okugbe 0065f29634 feat: sentry (#802) 2025-02-26 15:42:19 +00:00
Philipinho 7d034e8a8b enable trustProxy 2025-02-26 13:16:11 +00:00
Philipinho 81b6c7ef69 Merge remote-tracking branch 'refs/remotes/origin/main' 2025-02-26 13:14:45 +00:00
Philip Okugbe 89f6b0a8c2 feat: add stats to standalone collab server (#798)
* Log APP_URL on startup

* add stats endpoint to standalone collab server
2025-02-26 13:00:01 +00:00
Philipinho ad1571b902 Log APP_URL on startup 2025-02-26 11:49:58 +00:00
Philip Okugbe 4b9ab4f63c feat: standalone collab server (#767)
* feat: standalone collab server

* * custom collab server port env
* fix collab start script command

* * API prefix
* Log startup PORT

* Tweak collab debounce
2025-02-25 13:15:51 +00:00
Philipinho 08829ea721 v0.8.3 2025-02-22 12:25:49 +00:00
Philip Okugbe 6c502b4749 pin react-email version (#779) 2025-02-22 12:16:02 +00:00
Philipinho 6b41538b60 v0.8.2 2025-02-21 13:16:16 +00:00
Philipinho 496f5d7384 pin s3 package to 3.701.0 2025-02-21 13:15:19 +00:00
Alexander 32c7a16d06 fix: accept invitation password hashing (#773) 2025-02-21 12:48:25 +00:00
Philip Okugbe 64ecef09bc upgrade to NestJS 11 (#766)
* upgrade to nest 11

* update dependencies
2025-02-20 21:17:03 +00:00
Philipinho 3e5cb92621 v0.8.1 2025-02-18 16:59:27 +00:00
Philipinho fd5ad2f576 fix signup email 2025-02-18 16:26:16 +00:00
25 changed files with 5222 additions and 5797 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "client", "name": "client",
"private": true, "private": true,
"version": "0.8.0", "version": "0.8.4",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc && vite build", "build": "tsc && vite build",
@@ -148,6 +148,7 @@
"Select role to assign to all invited members": "Select role to assign to all invited members", "Select role to assign to all invited members": "Select role to assign to all invited members",
"Select theme": "Select theme", "Select theme": "Select theme",
"Send invitation": "Send invitation", "Send invitation": "Send invitation",
"Invitation sent": "Invitation sent",
"Settings": "Settings", "Settings": "Settings",
"Setup workspace": "Setup workspace", "Setup workspace": "Setup workspace",
"Sign In": "Sign In", "Sign In": "Sign In",
@@ -1,12 +1,16 @@
import { Menu, ActionIcon, Text } from "@mantine/core"; import { Menu, ActionIcon, Text } from "@mantine/core";
import React from "react"; import React from "react";
import { IconDots, IconTrash } from "@tabler/icons-react"; import { IconCopy, IconDots, IconSend, IconTrash } from "@tabler/icons-react";
import { modals } from "@mantine/modals"; import { modals } from "@mantine/modals";
import { import {
useResendInvitationMutation, useResendInvitationMutation,
useRevokeInvitationMutation, useRevokeInvitationMutation,
} from "@/features/workspace/queries/workspace-query.ts"; } from "@/features/workspace/queries/workspace-query.ts";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { notifications } from "@mantine/notifications";
import { useClipboard } from "@mantine/hooks";
import { getInviteLink } from "@/features/workspace/services/workspace-service.ts";
import useUserRole from "@/hooks/use-user-role.tsx";
interface Props { interface Props {
invitationId: string; invitationId: string;
@@ -15,6 +19,21 @@ export default function InviteActionMenu({ invitationId }: Props) {
const { t } = useTranslation(); const { t } = useTranslation();
const resendInvitationMutation = useResendInvitationMutation(); const resendInvitationMutation = useResendInvitationMutation();
const revokeInvitationMutation = useRevokeInvitationMutation(); const revokeInvitationMutation = useRevokeInvitationMutation();
const { isAdmin } = useUserRole();
const clipboard = useClipboard();
const handleCopyLink = async (invitationId: string) => {
try {
const link = await getInviteLink({ invitationId });
clipboard.copy(link.inviteLink);
notifications.show({ message: t("Link copied") });
} catch (err) {
notifications.show({
message: err["response"]?.data?.message,
color: "red",
});
}
};
const onResend = async () => { const onResend = async () => {
await resendInvitationMutation.mutateAsync({ invitationId }); await resendInvitationMutation.mutateAsync({ invitationId });
@@ -57,12 +76,26 @@ export default function InviteActionMenu({ invitationId }: Props) {
</Menu.Target> </Menu.Target>
<Menu.Dropdown> <Menu.Dropdown>
<Menu.Item onClick={onResend}>{t("Resend invitation")}</Menu.Item> <Menu.Item
onClick={() => handleCopyLink(invitationId)}
leftSection={<IconCopy size={16} />}
disabled={!isAdmin}
>
{t("Copy link")}
</Menu.Item>
<Menu.Item
onClick={onResend}
leftSection={<IconSend size={16} />}
disabled={!isAdmin}
>
{t("Resend invitation")}
</Menu.Item>
<Menu.Divider /> <Menu.Divider />
<Menu.Item <Menu.Item
c="red" c="red"
onClick={openRevokeModal} onClick={openRevokeModal}
leftSection={<IconTrash size={16} stroke={2} />} leftSection={<IconTrash size={16} />}
disabled={!isAdmin}
> >
{t("Revoke invitation")} {t("Revoke invitation")}
</Menu.Item> </Menu.Item>
@@ -24,6 +24,7 @@ import {
IWorkspace, IWorkspace,
} from "@/features/workspace/types/workspace.types.ts"; } from "@/features/workspace/types/workspace.types.ts";
import { IUser } from "@/features/user/types/user.types.ts"; import { IUser } from "@/features/user/types/user.types.ts";
import { useTranslation } from "react-i18next";
export function useWorkspaceQuery(): UseQueryResult<IWorkspace, Error> { export function useWorkspaceQuery(): UseQueryResult<IWorkspace, Error> {
return useQuery({ return useQuery({
@@ -81,12 +82,13 @@ export function useWorkspaceInvitationsQuery(
} }
export function useCreateInvitationMutation() { export function useCreateInvitationMutation() {
const { t } = useTranslation();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation<void, Error, ICreateInvite>({ return useMutation<void, Error, ICreateInvite>({
mutationFn: (data) => createInvitation(data), mutationFn: (data) => createInvitation(data),
onSuccess: (data, variables) => { onSuccess: (data, variables) => {
notifications.show({ message: "Invitation sent" }); notifications.show({ message: t("Invitation sent") });
queryClient.refetchQueries({ queryClient.refetchQueries({
queryKey: ["invitations"], queryKey: ["invitations"],
}); });
@@ -5,6 +5,7 @@ import {
IInvitation, IInvitation,
IWorkspace, IWorkspace,
IAcceptInvite, IAcceptInvite,
IInvitationLink,
} from "../types/workspace.types"; } from "../types/workspace.types";
import { IPagination, QueryParams } from "@/lib/types.ts"; import { IPagination, QueryParams } from "@/lib/types.ts";
@@ -53,6 +54,13 @@ export async function acceptInvitation(data: IAcceptInvite): Promise<void> {
await api.post<void>("/workspace/invites/accept", data); await api.post<void>("/workspace/invites/accept", data);
} }
export async function getInviteLink(data: {
invitationId: string;
}): Promise<IInvitationLink> {
const req = await api.post("/workspace/invites/link", data);
return req.data;
}
export async function resendInvitation(data: { export async function resendInvitation(data: {
invitationId: string; invitationId: string;
}): Promise<void> { }): Promise<void> {
@@ -28,6 +28,10 @@ export interface IInvitation {
createdAt: Date; createdAt: Date;
} }
export interface IInvitationLink {
inviteLink: string;
}
export interface IAcceptInvite { export interface IAcceptInvite {
invitationId: string; invitationId: string;
name: string; name: string;
+6 -8
View File
@@ -19,15 +19,13 @@ export function getBackendUrl(): string {
} }
export function getCollaborationUrl(): string { export function getCollaborationUrl(): string {
const COLLAB_PATH = "/collab"; const baseUrl =
getConfigValue("COLLAB_URL") ||
(import.meta.env.DEV ? process.env.APP_URL : getAppUrl());
let url = getAppUrl(); const collabUrl = new URL("/collab", baseUrl);
if (import.meta.env.DEV) { collabUrl.protocol = collabUrl.protocol === "https:" ? "wss:" : "ws:";
url = process.env.APP_URL; return collabUrl.toString();
}
const wsProtocol = url.startsWith("https") ? "wss" : "ws";
return `${wsProtocol}://${url.split("://")[1]}${COLLAB_PATH}`;
} }
export function getAvatarUrl(avatarUrl: string) { export function getAvatarUrl(avatarUrl: string) {
+8 -3
View File
@@ -5,16 +5,21 @@ import * as path from "path";
export const envPath = path.resolve(process.cwd(), "..", ".."); export const envPath = path.resolve(process.cwd(), "..", "..");
export default defineConfig(({ mode }) => { export default defineConfig(({ mode }) => {
const { APP_URL, FILE_UPLOAD_SIZE_LIMIT, DRAWIO_URL } = loadEnv(mode, envPath, ""); const { APP_URL, FILE_UPLOAD_SIZE_LIMIT, DRAWIO_URL, COLLAB_URL } = loadEnv(
mode,
envPath,
"",
);
return { return {
define: { define: {
"process.env": { "process.env": {
APP_URL, APP_URL,
FILE_UPLOAD_SIZE_LIMIT, FILE_UPLOAD_SIZE_LIMIT,
DRAWIO_URL DRAWIO_URL,
COLLAB_URL,
}, },
'APP_VERSION': JSON.stringify(process.env.npm_package_version), APP_VERSION: JSON.stringify(process.env.npm_package_version),
}, },
plugins: [react()], plugins: [react()],
resolve: { resolve: {
+43 -43
View File
@@ -1,6 +1,6 @@
{ {
"name": "server", "name": "server",
"version": "0.8.0", "version": "0.8.4",
"description": "", "description": "",
"author": "", "author": "",
"private": true, "private": true,
@@ -12,6 +12,7 @@
"start:dev": "cross-env NODE_ENV=development nest start --watch", "start:dev": "cross-env NODE_ENV=development nest start --watch",
"start:debug": "cross-env NODE_ENV=development nest start --debug --watch", "start:debug": "cross-env NODE_ENV=development nest start --debug --watch",
"start:prod": "cross-env NODE_ENV=production node dist/main", "start:prod": "cross-env NODE_ENV=production node dist/main",
"collab:prod": "cross-env NODE_ENV=production node dist/collaboration/server/collab-main",
"email:dev": "email dev -p 5019 -d ./src/integrations/transactional/emails", "email:dev": "email dev -p 5019 -d ./src/integrations/transactional/emails",
"migration:create": "tsx src/database/migrate.ts create", "migration:create": "tsx src/database/migrate.ts create",
"migration:up": "tsx src/database/migrate.ts up", "migration:up": "tsx src/database/migrate.ts up",
@@ -28,47 +29,46 @@
"test:e2e": "jest --config test/jest-e2e.json" "test:e2e": "jest --config test/jest-e2e.json"
}, },
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.701.0", "@aws-sdk/client-s3": "3.701.0",
"@aws-sdk/s3-request-presigner": "^3.701.0", "@aws-sdk/s3-request-presigner": "3.701.0",
"@casl/ability": "^6.7.2", "@casl/ability": "^6.7.3",
"@fastify/cookie": "^9.4.0", "@fastify/cookie": "^11.0.2",
"@fastify/multipart": "^8.3.0", "@fastify/multipart": "^9.0.3",
"@fastify/static": "^7.0.4", "@fastify/static": "^8.1.1",
"@nestjs/bullmq": "^10.2.2", "@nestjs/bullmq": "^11.0.2",
"@nestjs/common": "^10.4.9", "@nestjs/common": "^11.0.10",
"@nestjs/config": "^3.3.0", "@nestjs/config": "^4.0.0",
"@nestjs/core": "^10.4.9", "@nestjs/core": "^11.0.10",
"@nestjs/event-emitter": "^2.1.1", "@nestjs/event-emitter": "^3.0.0",
"@nestjs/jwt": "^10.2.0", "@nestjs/jwt": "^11.0.0",
"@nestjs/mapped-types": "^2.0.6", "@nestjs/mapped-types": "^2.1.0",
"@nestjs/passport": "^10.0.3", "@nestjs/passport": "^11.0.5",
"@nestjs/platform-fastify": "^10.4.9", "@nestjs/platform-fastify": "^11.0.10",
"@nestjs/platform-socket.io": "^10.4.9", "@nestjs/platform-socket.io": "^11.0.10",
"@nestjs/terminus": "^10.2.3", "@nestjs/terminus": "^11.0.0",
"@nestjs/websockets": "^10.4.9", "@nestjs/websockets": "^11.0.10",
"@react-email/components": "0.0.28", "@react-email/components": "0.0.28",
"@react-email/render": "^1.0.2", "@react-email/render": "1.0.2",
"@socket.io/redis-adapter": "^8.3.0", "@socket.io/redis-adapter": "^8.3.0",
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",
"bullmq": "^5.29.1", "bullmq": "^5.41.3",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.1", "class-validator": "^0.14.1",
"cookie": "^1.0.2", "cookie": "^1.0.2",
"fix-esm": "^1.0.1", "fix-esm": "^1.0.1",
"fs-extra": "^11.2.0", "fs-extra": "^11.3.0",
"happy-dom": "^15.11.6", "happy-dom": "^15.11.6",
"kysely": "^0.27.4", "kysely": "^0.27.5",
"kysely-migration-cli": "^0.4.2", "kysely-migration-cli": "^0.4.2",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"nanoid": "^5.0.9", "nanoid": "^5.1.0",
"nestjs-kysely": "^1.0.0", "nestjs-kysely": "^1.1.0",
"nodemailer": "^6.9.16", "nodemailer": "^6.10.0",
"passport-jwt": "^4.0.1", "passport-jwt": "^4.0.1",
"pg": "^8.13.1", "pg": "^8.13.3",
"pg-tsquery": "^8.4.2", "pg-tsquery": "^8.4.2",
"postmark": "^4.0.5", "postmark": "^4.0.5",
"react": "^18.3.1", "react": "^18.3.1",
"redis": "^4.7.0",
"reflect-metadata": "^0.2.2", "reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"sanitize-filename-ts": "^1.0.2", "sanitize-filename-ts": "^1.0.2",
@@ -76,36 +76,36 @@
"ws": "^8.18.0" "ws": "^8.18.0"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.16.0", "@eslint/js": "^9.20.0",
"@nestjs/cli": "^10.4.8", "@nestjs/cli": "^11.0.4",
"@nestjs/schematics": "^10.2.3", "@nestjs/schematics": "^11.0.1",
"@nestjs/testing": "^10.4.9", "@nestjs/testing": "^11.0.10",
"@types/bcrypt": "^5.0.2", "@types/bcrypt": "^5.0.2",
"@types/debounce": "^1.2.4", "@types/debounce": "^1.2.4",
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",
"@types/mime-types": "^2.1.4", "@types/mime-types": "^2.1.4",
"@types/node": "^22.10.0", "@types/node": "^22.13.4",
"@types/nodemailer": "^6.4.17", "@types/nodemailer": "^6.4.17",
"@types/passport-jwt": "^4.0.1", "@types/passport-jwt": "^4.0.1",
"@types/pg": "^8.11.10", "@types/pg": "^8.11.11",
"@types/supertest": "^6.0.2", "@types/supertest": "^6.0.2",
"@types/ws": "^8.5.13", "@types/ws": "^8.5.14",
"eslint": "^9.15.0", "eslint": "^9.20.1",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^10.0.1",
"globals": "^15.13.0", "globals": "^15.15.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"kysely-codegen": "^0.17.0", "kysely-codegen": "^0.17.0",
"prettier": "^3.4.1", "prettier": "^3.5.1",
"react-email": "^3.0.2", "react-email": "3.0.2",
"source-map-support": "^0.5.21", "source-map-support": "^0.5.21",
"supertest": "^7.0.0", "supertest": "^7.0.0",
"ts-jest": "^29.2.5", "ts-jest": "^29.2.5",
"ts-loader": "^9.5.1", "ts-loader": "^9.5.2",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0", "tsconfig-paths": "^4.2.0",
"typescript": "^5.7.2", "typescript": "^5.7.3",
"typescript-eslint": "^8.17.0" "typescript-eslint": "^8.24.1"
}, },
"jest": { "jest": {
"moduleFileExtensions": [ "moduleFileExtensions": [
@@ -25,12 +25,15 @@ export class CollaborationGateway {
this.redisConfig = parseRedisUrl(this.environmentService.getRedisUrl()); this.redisConfig = parseRedisUrl(this.environmentService.getRedisUrl());
this.hocuspocus = HocuspocusServer.configure({ this.hocuspocus = HocuspocusServer.configure({
debounce: 5000, debounce: 10000,
maxDebounce: 10000, maxDebounce: 20000,
unloadImmediately: false, unloadImmediately: false,
extensions: [ extensions: [
this.authenticationExtension, this.authenticationExtension,
this.persistenceExtension, this.persistenceExtension,
...(this.environmentService.isCollabDisableRedis()
? []
: [
new Redis({ new Redis({
host: this.redisConfig.host, host: this.redisConfig.host,
port: this.redisConfig.port, port: this.redisConfig.port,
@@ -40,6 +43,7 @@ export class CollaborationGateway {
retryStrategy: createRetryStrategy(), retryStrategy: createRetryStrategy(),
}, },
}), }),
]),
], ],
}); });
} }
@@ -48,6 +52,14 @@ export class CollaborationGateway {
this.hocuspocus.handleConnection(client, request); this.hocuspocus.handleConnection(client, request);
} }
getConnectionCount() {
return this.hocuspocus.getConnectionsCount();
}
getDocumentCount() {
return this.hocuspocus.getDocumentsCount();
}
async destroy(): Promise<void> { async destroy(): Promise<void> {
await this.hocuspocus.destroy(); await this.hocuspocus.destroy();
} }
@@ -16,6 +16,7 @@ import { HistoryListener } from './listeners/history.listener';
PersistenceExtension, PersistenceExtension,
HistoryListener, HistoryListener,
], ],
exports: [CollaborationGateway],
imports: [TokenModule], imports: [TokenModule],
}) })
export class CollaborationModule implements OnModuleInit, OnModuleDestroy { export class CollaborationModule implements OnModuleInit, OnModuleDestroy {
@@ -0,0 +1,29 @@
import { Module } from '@nestjs/common';
import { AppController } from '../../app.controller';
import { AppService } from '../../app.service';
import { EnvironmentModule } from '../../integrations/environment/environment.module';
import { CollaborationModule } from '../collaboration.module';
import { DatabaseModule } from '@docmost/db/database.module';
import { QueueModule } from '../../integrations/queue/queue.module';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { HealthModule } from '../../integrations/health/health.module';
import { CollaborationController } from './collaboration.controller';
@Module({
imports: [
DatabaseModule,
EnvironmentModule,
CollaborationModule,
QueueModule,
HealthModule,
EventEmitterModule.forRoot(),
],
controllers: [
AppController,
...(process.env.COLLAB_SHOW_STATS.toLowerCase() === 'true'
? [CollaborationController]
: []),
],
providers: [AppService],
})
export class CollabAppModule {}
@@ -0,0 +1,39 @@
import { NestFactory } from '@nestjs/core';
import { CollabAppModule } from './collab-app.module';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { TransformHttpResponseInterceptor } from '../../common/interceptors/http-response.interceptor';
import { InternalLogFilter } from '../../common/logger/internal-log-filter';
import { Logger } from '@nestjs/common';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
CollabAppModule,
new FastifyAdapter({
ignoreTrailingSlash: true,
ignoreDuplicateSlashes: true,
maxParamLength: 500,
}),
{
logger: new InternalLogFilter(),
},
);
app.setGlobalPrefix('api', { exclude: ['/'] });
app.enableCors();
app.useGlobalInterceptors(new TransformHttpResponseInterceptor());
app.enableShutdownHooks();
const logger = new Logger('CollabServer');
const port = process.env.COLLAB_PORT || 3001;
await app.listen(port, '0.0.0.0', () => {
logger.log(`Listening on http://127.0.0.1:${port}`);
});
}
bootstrap();
@@ -0,0 +1,15 @@
import { Controller, Get } from '@nestjs/common';
import { CollaborationGateway } from '../collaboration.gateway';
@Controller('collab')
export class CollaborationController {
constructor(private readonly collaborationGateway: CollaborationGateway) {}
@Get('stats')
async getStats() {
return {
connections: this.collaborationGateway.getConnectionCount(),
documents: this.collaborationGateway.getDocumentCount(),
};
}
}
@@ -79,7 +79,7 @@ export class SignupService {
const user = await this.userRepo.insertUser( const user = await this.userRepo.insertUser(
{ {
name: createAdminUserDto.name, name: createAdminUserDto.name,
email: createAdminUserDto.name, email: createAdminUserDto.email,
password: createAdminUserDto.password, password: createAdminUserDto.password,
role: UserRole.OWNER, role: UserRole.OWNER,
emailVerifiedAt: new Date(), emailVerifiedAt: new Date(),
@@ -237,4 +237,30 @@ export class WorkspaceController {
secure: this.environmentService.isHttps(), secure: this.environmentService.isHttps(),
}); });
} }
@HttpCode(HttpStatus.OK)
@Post('invites/link')
async getInviteLink(
@Body() inviteDto: InvitationIdDto,
@AuthUser() user: User,
@AuthWorkspace() workspace: Workspace,
) {
if (this.environmentService.isCloud()) {
throw new ForbiddenException();
}
const ability = this.workspaceAbility.createForUser(user, workspace);
if (
ability.cannot(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Member)
) {
throw new ForbiddenException();
}
const inviteLink =
await this.workspaceInvitationService.getInvitationLinkById(
inviteDto.invitationId,
workspace.id,
);
return { inviteLink };
}
} }
@@ -16,7 +16,6 @@ import {
} from '@docmost/db/types/entity.types'; } from '@docmost/db/types/entity.types';
import { MailService } from '../../../integrations/mail/mail.service'; import { MailService } from '../../../integrations/mail/mail.service';
import InvitationEmail from '@docmost/transactional/emails/invitation-email'; import InvitationEmail from '@docmost/transactional/emails/invitation-email';
import { hashPassword } from '../../../common/helpers';
import { GroupUserRepo } from '@docmost/db/repos/group/group-user.repo'; import { GroupUserRepo } from '@docmost/db/repos/group/group-user.repo';
import InvitationAcceptedEmail from '@docmost/transactional/emails/invitation-accepted-email'; import InvitationAcceptedEmail from '@docmost/transactional/emails/invitation-accepted-email';
import { EnvironmentService } from '../../../integrations/environment/environment.service'; import { EnvironmentService } from '../../../integrations/environment/environment.service';
@@ -72,6 +71,21 @@ export class WorkspaceInvitationService {
return invitation; return invitation;
} }
async getInvitationTokenById(invitationId: string, workspaceId: string) {
const invitation = await this.db
.selectFrom('workspaceInvitations')
.select(['token'])
.where('id', '=', invitationId)
.where('workspaceId', '=', workspaceId)
.executeTakeFirst();
if (!invitation) {
throw new NotFoundException('Invitation not found');
}
return invitation;
}
async createInvitation( async createInvitation(
inviteUserDto: InviteUserDto, inviteUserDto: InviteUserDto,
workspaceId: string, workspaceId: string,
@@ -163,7 +177,6 @@ export class WorkspaceInvitationService {
throw new BadRequestException('Invalid invitation token'); throw new BadRequestException('Invalid invitation token');
} }
const password = await hashPassword(dto.password);
let newUser: User; let newUser: User;
try { try {
@@ -173,7 +186,7 @@ export class WorkspaceInvitationService {
name: dto.name, name: dto.name,
email: invitation.email, email: invitation.email,
emailVerifiedAt: new Date(), emailVerifiedAt: new Date(),
password: password, password: dto.password,
role: invitation.role, role: invitation.role,
invitedById: invitation.invitedById, invitedById: invitation.invitedById,
workspaceId: workspaceId, workspaceId: workspaceId,
@@ -258,7 +271,6 @@ export class WorkspaceInvitationService {
invitationId: string, invitationId: string,
workspaceId: string, workspaceId: string,
): Promise<void> { ): Promise<void> {
//
const invitation = await this.db const invitation = await this.db
.selectFrom('workspaceInvitations') .selectFrom('workspaceInvitations')
.selectAll() .selectAll()
@@ -294,13 +306,28 @@ export class WorkspaceInvitationService {
.execute(); .execute();
} }
async getInvitationLinkById(
invitationId: string,
workspaceId: string,
): Promise<string> {
const token = await this.getInvitationTokenById(invitationId, workspaceId);
return this.buildInviteLink(invitationId, token.token);
}
async buildInviteLink(
invitationId: string,
inviteToken: string,
): Promise<string> {
return `${this.environmentService.getAppUrl()}/invites/${invitationId}?token=${inviteToken}`;
}
async sendInvitationMail( async sendInvitationMail(
invitationId: string, invitationId: string,
inviteeEmail: string, inviteeEmail: string,
inviteToken: string, inviteToken: string,
invitedByName: string, invitedByName: string,
): Promise<void> { ): Promise<void> {
const inviteLink = `${this.environmentService.getAppUrl()}/invites/${invitationId}?token=${inviteToken}`; const inviteLink = await this.buildInviteLink(invitationId, inviteToken);
const emailTemplate = InvitationEmail({ const emailTemplate = InvitationEmail({
inviteLink, inviteLink,
@@ -145,4 +145,15 @@ export class EnvironmentService {
isSelfHosted(): boolean { isSelfHosted(): boolean {
return !this.isCloud(); return !this.isCloud();
} }
getCollabUrl(): string {
return this.configService.get<string>('COLLAB_URL');
}
isCollabDisableRedis(): boolean {
const isStandalone = this.configService
.get<string>('COLLAB_DISABLE_REDIS', 'false')
.toLowerCase();
return isStandalone === 'true';
}
} }
@@ -5,6 +5,7 @@ import {
IsOptional, IsOptional,
IsUrl, IsUrl,
MinLength, MinLength,
ValidateIf,
validateSync, validateSync,
} from 'class-validator'; } from 'class-validator';
import { plainToInstance } from 'class-transformer'; import { plainToInstance } from 'class-transformer';
@@ -48,6 +49,11 @@ export class EnvironmentVariables {
@IsOptional() @IsOptional()
@IsIn(['local', 's3']) @IsIn(['local', 's3'])
STORAGE_DRIVER: string; STORAGE_DRIVER: string;
@IsOptional()
@ValidateIf((obj) => obj.COLLAB_URL != '' && obj.COLLAB_URL != null)
@IsUrl({ protocols: ['http', 'https'], require_tld: false })
COLLAB_URL: string;
} }
export function validate(config: Record<string, any>) { export function validate(config: Record<string, any>) {
@@ -1,31 +1,30 @@
import { InjectKysely } from 'nestjs-kysely'; import { InjectKysely } from 'nestjs-kysely';
import { import {
HealthCheckError,
HealthIndicator,
HealthIndicatorResult, HealthIndicatorResult,
HealthIndicatorService,
} from '@nestjs/terminus'; } from '@nestjs/terminus';
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { sql } from 'kysely'; import { sql } from 'kysely';
import { KyselyDB } from '@docmost/db/types/kysely.types'; import { KyselyDB } from '@docmost/db/types/kysely.types';
@Injectable() @Injectable()
export class PostgresHealthIndicator extends HealthIndicator { export class PostgresHealthIndicator {
private readonly logger = new Logger(PostgresHealthIndicator.name); private readonly logger = new Logger(PostgresHealthIndicator.name);
constructor(@InjectKysely() private readonly db: KyselyDB) { constructor(
super(); private readonly healthIndicatorService: HealthIndicatorService,
} @InjectKysely() private readonly db: KyselyDB,
) {}
async pingCheck(key: string): Promise<HealthIndicatorResult> { async pingCheck(key: string): Promise<HealthIndicatorResult> {
const indicator = this.healthIndicatorService.check(key);
try { try {
await sql`SELECT 1=1`.execute(this.db); await sql`SELECT 1=1`.execute(this.db);
return this.getStatus(key, true); return indicator.up();
} catch (e) { } catch (e) {
this.logger.error(JSON.stringify(e)); this.logger.error(JSON.stringify(e));
throw new HealthCheckError( return indicator.down(`${key} is not available`);
`${key} is not available`,
this.getStatus(key, false),
);
} }
} }
} }
@@ -1,21 +1,23 @@
import { import {
HealthCheckError,
HealthIndicator,
HealthIndicatorResult, HealthIndicatorResult,
HealthIndicatorService,
} from '@nestjs/terminus'; } from '@nestjs/terminus';
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { EnvironmentService } from '../environment/environment.service'; import { EnvironmentService } from '../environment/environment.service';
import { Redis } from 'ioredis'; import { Redis } from 'ioredis';
@Injectable() @Injectable()
export class RedisHealthIndicator extends HealthIndicator { export class RedisHealthIndicator {
private readonly logger = new Logger(RedisHealthIndicator.name); private readonly logger = new Logger(RedisHealthIndicator.name);
constructor(private environmentService: EnvironmentService) { constructor(
super(); private readonly healthIndicatorService: HealthIndicatorService,
} private environmentService: EnvironmentService,
) {}
async pingCheck(key: string): Promise<HealthIndicatorResult> { async pingCheck(key: string): Promise<HealthIndicatorResult> {
const indicator = this.healthIndicatorService.check(key);
try { try {
const redis = new Redis(this.environmentService.getRedisUrl(), { const redis = new Redis(this.environmentService.getRedisUrl(), {
maxRetriesPerRequest: 15, maxRetriesPerRequest: 15,
@@ -23,13 +25,10 @@ export class RedisHealthIndicator extends HealthIndicator {
await redis.ping(); await redis.ping();
redis.disconnect(); redis.disconnect();
return this.getStatus(key, true); return indicator.up();
} catch (e) { } catch (e) {
this.logger.error(e); this.logger.error(e);
throw new HealthCheckError( return indicator.down(`${key} is not available`);
`${key} is not available`,
this.getStatus(key, false),
);
} }
} }
} }
@@ -38,6 +38,7 @@ export class StaticModule implements OnModuleInit {
FILE_UPLOAD_SIZE_LIMIT: FILE_UPLOAD_SIZE_LIMIT:
this.environmentService.getFileUploadSizeLimit(), this.environmentService.getFileUploadSizeLimit(),
DRAWIO_URL: this.environmentService.getDrawioUrl(), DRAWIO_URL: this.environmentService.getDrawioUrl(),
COLLAB_URL: this.environmentService.getCollabUrl(),
}; };
const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`; const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`;
+10 -2
View File
@@ -4,7 +4,7 @@ import {
FastifyAdapter, FastifyAdapter,
NestFastifyApplication, NestFastifyApplication,
} from '@nestjs/platform-fastify'; } from '@nestjs/platform-fastify';
import { NotFoundException, ValidationPipe } from '@nestjs/common'; import { Logger, NotFoundException, ValidationPipe } from '@nestjs/common';
import { TransformHttpResponseInterceptor } from './common/interceptors/http-response.interceptor'; import { TransformHttpResponseInterceptor } from './common/interceptors/http-response.interceptor';
import fastifyMultipart from '@fastify/multipart'; import fastifyMultipart from '@fastify/multipart';
import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter'; import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter';
@@ -18,6 +18,7 @@ async function bootstrap() {
ignoreTrailingSlash: true, ignoreTrailingSlash: true,
ignoreDuplicateSlashes: true, ignoreDuplicateSlashes: true,
maxParamLength: 500, maxParamLength: 500,
trustProxy: true,
}), }),
{ {
logger: new InternalLogFilter(), logger: new InternalLogFilter(),
@@ -65,7 +66,14 @@ async function bootstrap() {
app.useGlobalInterceptors(new TransformHttpResponseInterceptor()); app.useGlobalInterceptors(new TransformHttpResponseInterceptor());
app.enableShutdownHooks(); app.enableShutdownHooks();
await app.listen(process.env.PORT || 3000, '0.0.0.0'); const logger = new Logger('NestApplication');
const port = process.env.PORT || 3000;
await app.listen(port, '0.0.0.0', () => {
logger.log(
`Listening on http://127.0.0.1:${port} / ${process.env.APP_URL}`,
);
});
} }
bootstrap(); bootstrap();
+9 -8
View File
@@ -1,11 +1,12 @@
{ {
"name": "docmost", "name": "docmost",
"homepage": "https://docmost.com", "homepage": "https://docmost.com",
"version": "0.8.0", "version": "0.8.4",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "nx run-many -t build", "build": "nx run-many -t build",
"start": "pnpm --filter ./apps/server run start:prod", "start": "pnpm --filter ./apps/server run start:prod",
"collab": "pnpm --filter ./apps/server run collab:prod",
"server:build": "nx run server:build", "server:build": "nx run server:build",
"client:build": "nx run client:build", "client:build": "nx run client:build",
"editor-ext:build": "nx run @docmost/editor-ext:build", "editor-ext:build": "nx run @docmost/editor-ext:build",
@@ -61,23 +62,23 @@
"bytes": "^3.1.2", "bytes": "^3.1.2",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"dompurify": "^3.2.1", "dompurify": "^3.2.4",
"fractional-indexing-jittered": "^1.0.0", "fractional-indexing-jittered": "^1.0.0",
"ioredis": "^5.4.1", "ioredis": "^5.4.1",
"jszip": "^3.10.1", "jszip": "^3.10.1",
"linkifyjs": "^4.2.0", "linkifyjs": "^4.2.0",
"marked": "^13.0.3", "marked": "^13.0.3",
"uuid": "^11.0.3", "uuid": "^11.1.0",
"y-indexeddb": "^9.0.12", "y-indexeddb": "^9.0.12",
"yjs": "^13.6.20" "yjs": "^13.6.20"
}, },
"devDependencies": { "devDependencies": {
"@nx/js": "20.1.3", "@nx/js": "20.4.5",
"@types/bytes": "^3.1.4", "@types/bytes": "^3.1.5",
"@types/uuid": "^10.0.0", "@types/uuid": "^10.0.0",
"concurrently": "^9.1.0", "concurrently": "^9.1.2",
"nx": "20.1.3", "nx": "20.4.5",
"tsx": "^4.19.2" "tsx": "^4.19.3"
}, },
"workspaces": { "workspaces": {
"packages": [ "packages": [
+4889 -5689
View File
File diff suppressed because it is too large Load Diff