2025-12-03 14:56:40 +00:00
|
|
|
import { isAbsolute, join } from '@std/path';
|
2025-05-24 07:24:10 +00:00
|
|
|
import { UserModel } from './models/user.ts';
|
2025-05-25 14:48:53 +00:00
|
|
|
import { Config, OptionalApp } from './types.ts';
|
|
|
|
|
|
|
|
|
|
export class AppConfig {
|
|
|
|
|
private static config: Config;
|
|
|
|
|
|
|
|
|
|
private static getDefaultConfig(): Config {
|
|
|
|
|
return {
|
|
|
|
|
auth: {
|
|
|
|
|
baseUrl: 'http://localhost:8000',
|
|
|
|
|
allowSignups: false,
|
|
|
|
|
enableEmailVerification: false,
|
|
|
|
|
enableForeverSignup: true,
|
2025-05-29 16:30:28 +00:00
|
|
|
enableMultiFactor: false,
|
2025-05-25 14:48:53 +00:00
|
|
|
allowedCookieDomains: [],
|
|
|
|
|
skipCookieDomainSecurity: false,
|
2025-06-05 17:10:40 +00:00
|
|
|
enableSingleSignOn: false,
|
2026-02-26 13:31:19 +00:00
|
|
|
allowSignupsViaSingleSignOn: false,
|
2025-06-05 17:10:40 +00:00
|
|
|
singleSignOnUrl: '',
|
|
|
|
|
singleSignOnEmailAttribute: 'email',
|
|
|
|
|
singleSignOnScopes: ['openid', 'email'],
|
2025-05-25 14:48:53 +00:00
|
|
|
},
|
|
|
|
|
files: {
|
|
|
|
|
rootPath: 'data-files',
|
2025-06-20 11:04:16 +00:00
|
|
|
allowPublicSharing: false,
|
2025-10-08 13:38:31 +00:00
|
|
|
allowDirectoryDownloads: false,
|
2026-03-02 19:52:00 +00:00
|
|
|
maxUploadSizeInMegabytes: 100,
|
2025-05-25 14:48:53 +00:00
|
|
|
},
|
|
|
|
|
core: {
|
2025-12-01 12:25:21 +00:00
|
|
|
enabledApps: ['dashboard', 'files', 'news', 'notes', 'photos', 'expenses', 'contacts', 'calendar'],
|
2026-03-02 19:52:00 +00:00
|
|
|
maxRequestSizeInMegabytes: 12,
|
2025-05-25 14:48:53 +00:00
|
|
|
},
|
|
|
|
|
visuals: {
|
|
|
|
|
title: '',
|
|
|
|
|
description: '',
|
|
|
|
|
helpEmail: 'help@bewcloud.com',
|
|
|
|
|
},
|
Migrate email provider (from Brevo to generic SMTP) (#67)
This means we now need to have the text and HTML content set in the code, which is arguably better.
In order to avoid allowing legacy Brevo API Key support, this will also introduce breaking changes and will be released as v2.0.0.
I took the opportunity to remove a few deprecated things (like legacy ENV-based config), upgrade PostgreSQL, and pin a specific version in `docker-compose.yml`, since I don't plan to do breaking releases anytime soon, and upgrading PostgreSQL should be fine from now on if the version is pinned.
If you were using Brevo with an API Key, they support SMTP as well, just update your config.
If you were using ENV-based config, check `bewcloud.config.sample.ts`to create your `bewcloud.config.ts`.
If you need help upgrading you PostgreSQL container, I've written a simple guide [step-by-step guide](https://news.onbrn.com/step-by-step-guide-upgrading-postgresql-docker-containers/).
2025-06-10 09:28:13 +00:00
|
|
|
email: {
|
|
|
|
|
from: 'help@bewcloud.com',
|
|
|
|
|
host: 'localhost',
|
|
|
|
|
port: 465,
|
Remove fresh
This implements a huge change, where Fresh is removed as a framework and serving files, allowing more control over importing, bundling, and serving files and components.
The biggest challenge was to continue making sure that there weren't too many places to look into for import versions, and `PasswordlessPasskeyLogin.tsx` became a prototype in migrating a component to fully SSR, no need for frontend parsing (via Babel) or bundling (via a custom-script, downloading frontend dependencies from esm.sh). Still, there are too many components to migrate like that, and it's all working, so I likely won't even attempt it unless there's some bug, new feature, or security vulnerability to address that warrants a rewrite of those.
This also updates all dependencies (except `@libs/xml` because that still causes some breaking in DAV endpoints), including Deno!
All other advantages can be seen in the related issues, and the breaking change this (v4.0.0) introduces is related simply to `config.email.tlsMode` (which had a deprecation warning throughout v3), and because, while I tested many things exhaustively, it's not impossible something broke that I didn't see.
Closes #141
Closes #132
2026-02-20 10:54:31 +00:00
|
|
|
tlsMode: 'auto',
|
2025-12-20 11:50:15 +00:00
|
|
|
tlsVerify: true,
|
2025-05-25 14:48:53 +00:00
|
|
|
},
|
2025-07-20 09:35:32 +00:00
|
|
|
contacts: {
|
|
|
|
|
enableCardDavServer: true,
|
2025-08-27 15:44:01 +00:00
|
|
|
cardDavUrl: 'http://radicale:5232',
|
2025-07-20 09:35:32 +00:00
|
|
|
},
|
|
|
|
|
calendar: {
|
|
|
|
|
enableCalDavServer: true,
|
2025-08-27 15:44:01 +00:00
|
|
|
calDavUrl: 'http://radicale:5232',
|
2025-07-20 09:35:32 +00:00
|
|
|
},
|
2025-05-25 14:48:53 +00:00
|
|
|
};
|
|
|
|
|
}
|
2024-03-16 08:40:24 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
private static async loadConfig(): Promise<void> {
|
|
|
|
|
if (this.config) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
Migrate email provider (from Brevo to generic SMTP) (#67)
This means we now need to have the text and HTML content set in the code, which is arguably better.
In order to avoid allowing legacy Brevo API Key support, this will also introduce breaking changes and will be released as v2.0.0.
I took the opportunity to remove a few deprecated things (like legacy ENV-based config), upgrade PostgreSQL, and pin a specific version in `docker-compose.yml`, since I don't plan to do breaking releases anytime soon, and upgrading PostgreSQL should be fine from now on if the version is pinned.
If you were using Brevo with an API Key, they support SMTP as well, just update your config.
If you were using ENV-based config, check `bewcloud.config.sample.ts`to create your `bewcloud.config.ts`.
If you need help upgrading you PostgreSQL container, I've written a simple guide [step-by-step guide](https://news.onbrn.com/step-by-step-guide-upgrading-postgresql-docker-containers/).
2025-06-10 09:28:13 +00:00
|
|
|
const initialConfig = this.getDefaultConfig();
|
2025-05-25 14:48:53 +00:00
|
|
|
|
|
|
|
|
const config: Config = {
|
|
|
|
|
...initialConfig,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const configFromFile: Config = (await import(`${Deno.cwd()}/bewcloud.config.ts`)).default;
|
|
|
|
|
|
|
|
|
|
this.config = {
|
|
|
|
|
...config,
|
|
|
|
|
auth: {
|
|
|
|
|
...config.auth,
|
|
|
|
|
...configFromFile.auth,
|
|
|
|
|
},
|
|
|
|
|
files: {
|
|
|
|
|
...config.files,
|
|
|
|
|
...configFromFile.files,
|
|
|
|
|
},
|
|
|
|
|
core: {
|
|
|
|
|
...config.core,
|
|
|
|
|
...configFromFile.core,
|
|
|
|
|
},
|
|
|
|
|
visuals: {
|
|
|
|
|
...config.visuals,
|
|
|
|
|
...configFromFile.visuals,
|
|
|
|
|
},
|
Migrate email provider (from Brevo to generic SMTP) (#67)
This means we now need to have the text and HTML content set in the code, which is arguably better.
In order to avoid allowing legacy Brevo API Key support, this will also introduce breaking changes and will be released as v2.0.0.
I took the opportunity to remove a few deprecated things (like legacy ENV-based config), upgrade PostgreSQL, and pin a specific version in `docker-compose.yml`, since I don't plan to do breaking releases anytime soon, and upgrading PostgreSQL should be fine from now on if the version is pinned.
If you were using Brevo with an API Key, they support SMTP as well, just update your config.
If you were using ENV-based config, check `bewcloud.config.sample.ts`to create your `bewcloud.config.ts`.
If you need help upgrading you PostgreSQL container, I've written a simple guide [step-by-step guide](https://news.onbrn.com/step-by-step-guide-upgrading-postgresql-docker-containers/).
2025-06-10 09:28:13 +00:00
|
|
|
email: {
|
|
|
|
|
...config.email,
|
|
|
|
|
...configFromFile.email,
|
|
|
|
|
},
|
Basic CardDav UI (Contacts)
This implements a basic CardDav UI, titled "Contacts". It allows creating new contacts with a first name + last name, and editing their first and last names, main email, main phone, and notes.
You can also import and export VCF (VCARD) files.
It also allows editing the VCARD directly, for power users.
Additionally, you can choose, create, or delete address books, and if there's no address book created yet in your CardDav server (first-time setup), it'll automatically create one, titled "Contacts".
Finally, there are some dependency updates and a fix for the config not allowing disabling the `cardDav` or the `calDav` server.
Related to #56
2025-08-10 06:48:16 +00:00
|
|
|
contacts: {
|
|
|
|
|
...config.contacts,
|
|
|
|
|
...configFromFile.contacts,
|
|
|
|
|
},
|
|
|
|
|
calendar: {
|
|
|
|
|
...config.calendar,
|
|
|
|
|
...configFromFile.calendar,
|
|
|
|
|
},
|
2025-05-25 14:48:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
console.info('\nConfig loaded from bewcloud.config.ts', JSON.stringify(this.config, null, 2), '\n');
|
|
|
|
|
|
2025-12-01 12:25:21 +00:00
|
|
|
if (this.config.core.enabledApps.length === 0) {
|
|
|
|
|
throw new Error('At least one app must be enabled. Please check the config.core.enabledApps array.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
return;
|
|
|
|
|
} catch (error) {
|
Migrate email provider (from Brevo to generic SMTP) (#67)
This means we now need to have the text and HTML content set in the code, which is arguably better.
In order to avoid allowing legacy Brevo API Key support, this will also introduce breaking changes and will be released as v2.0.0.
I took the opportunity to remove a few deprecated things (like legacy ENV-based config), upgrade PostgreSQL, and pin a specific version in `docker-compose.yml`, since I don't plan to do breaking releases anytime soon, and upgrading PostgreSQL should be fine from now on if the version is pinned.
If you were using Brevo with an API Key, they support SMTP as well, just update your config.
If you were using ENV-based config, check `bewcloud.config.sample.ts`to create your `bewcloud.config.ts`.
If you need help upgrading you PostgreSQL container, I've written a simple guide [step-by-step guide](https://news.onbrn.com/step-by-step-guide-upgrading-postgresql-docker-containers/).
2025-06-10 09:28:13 +00:00
|
|
|
console.error('Error loading config from bewcloud.config.ts. Using default config instead.', error);
|
2025-05-25 14:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.config = config;
|
|
|
|
|
}
|
2024-03-16 08:40:24 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
static async getConfig(): Promise<Config> {
|
|
|
|
|
await this.loadConfig();
|
2024-03-16 08:40:24 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
return this.config;
|
2024-03-16 08:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 13:31:19 +00:00
|
|
|
static async isSignupAllowed({ viaSingleSignOn = false }: { viaSingleSignOn?: boolean } = {}): Promise<boolean> {
|
2025-05-25 14:48:53 +00:00
|
|
|
await this.loadConfig();
|
2024-04-03 13:02:04 +00:00
|
|
|
|
2026-02-26 13:35:33 +00:00
|
|
|
const areSignupsAllowed = viaSingleSignOn && !this.config.auth.allowSignups
|
|
|
|
|
? this.config.auth.allowSignupsViaSingleSignOn
|
|
|
|
|
: this.config.auth.allowSignups;
|
2025-05-25 14:48:53 +00:00
|
|
|
const areThereAdmins = await UserModel.isThereAnAdmin();
|
2024-05-01 08:21:30 +00:00
|
|
|
|
2026-02-26 13:35:33 +00:00
|
|
|
if (areSignupsAllowed || !areThereAdmins) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2025-01-11 07:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
static async isAppEnabled(app: OptionalApp): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
2025-01-11 07:09:11 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
const enabledApps = this.config.core.enabledApps;
|
2025-03-02 07:24:28 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
return enabledApps.includes(app);
|
|
|
|
|
}
|
2025-03-02 07:24:28 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
static async isCookieDomainAllowed(domain: string): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
2024-04-08 19:53:28 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
const allowedDomains = this.config.auth.allowedCookieDomains;
|
2024-04-08 19:53:28 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
if (allowedDomains.length === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-04-08 19:53:28 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
return allowedDomains.includes(domain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async isCookieDomainSecurityDisabled(): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
return this.config.auth.skipCookieDomainSecurity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async isEmailVerificationEnabled(): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
2024-04-08 19:53:28 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
return this.config.auth.enableEmailVerification;
|
|
|
|
|
}
|
2024-04-03 13:02:04 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
static async isForeverSignupEnabled(): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
2024-04-03 13:02:04 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
return this.config.auth.enableForeverSignup;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-29 16:30:28 +00:00
|
|
|
static async isMultiFactorAuthEnabled(): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
return this.config.auth.enableMultiFactor;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-05 17:10:40 +00:00
|
|
|
static async isSingleSignOnEnabled(): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
return this.config.auth.enableSingleSignOn;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 11:04:16 +00:00
|
|
|
static async isPublicFileSharingAllowed(): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
return this.config.files.allowPublicSharing;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-08 13:32:45 +00:00
|
|
|
static async areDirectoryDownloadsAllowed(): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
return this.config.files.allowDirectoryDownloads;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
static async getFilesRootPath(): Promise<string> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
2025-12-03 05:47:53 +00:00
|
|
|
if (isAbsolute(this.config.files.rootPath)) {
|
|
|
|
|
return this.config.files.rootPath;
|
|
|
|
|
} else {
|
|
|
|
|
return join(Deno.cwd(), this.config.files.rootPath);
|
|
|
|
|
}
|
2025-05-25 14:48:53 +00:00
|
|
|
}
|
Migrate email provider (from Brevo to generic SMTP) (#67)
This means we now need to have the text and HTML content set in the code, which is arguably better.
In order to avoid allowing legacy Brevo API Key support, this will also introduce breaking changes and will be released as v2.0.0.
I took the opportunity to remove a few deprecated things (like legacy ENV-based config), upgrade PostgreSQL, and pin a specific version in `docker-compose.yml`, since I don't plan to do breaking releases anytime soon, and upgrading PostgreSQL should be fine from now on if the version is pinned.
If you were using Brevo with an API Key, they support SMTP as well, just update your config.
If you were using ENV-based config, check `bewcloud.config.sample.ts`to create your `bewcloud.config.ts`.
If you need help upgrading you PostgreSQL container, I've written a simple guide [step-by-step guide](https://news.onbrn.com/step-by-step-guide-upgrading-postgresql-docker-containers/).
2025-06-10 09:28:13 +00:00
|
|
|
|
|
|
|
|
static async getEmailConfig(): Promise<Config['email']> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
return this.config.email;
|
|
|
|
|
}
|
2025-07-20 09:35:32 +00:00
|
|
|
|
|
|
|
|
static async getContactsConfig(): Promise<Config['contacts']> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
return this.config.contacts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async getCalendarConfig(): Promise<Config['calendar']> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
return this.config.calendar;
|
|
|
|
|
}
|
2024-04-03 13:02:04 +00:00
|
|
|
}
|