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,
|
|
|
|
|
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-05-25 14:48:53 +00:00
|
|
|
},
|
|
|
|
|
core: {
|
|
|
|
|
enabledApps: ['news', 'notes', 'photos', 'expenses'],
|
|
|
|
|
},
|
|
|
|
|
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,
|
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,
|
|
|
|
|
},
|
2025-05-25 14:48:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
console.info('\nConfig loaded from bewcloud.config.ts', JSON.stringify(this.config, null, 2), '\n');
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
static async isSignupAllowed(): Promise<boolean> {
|
|
|
|
|
await this.loadConfig();
|
2024-04-03 13:02:04 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
const areSignupsAllowed = this.config.auth.allowSignups;
|
2024-05-01 08:21:30 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
const areThereAdmins = await UserModel.isThereAnAdmin();
|
2024-05-01 08:21:30 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
if (areSignupsAllowed || !areThereAdmins) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-01-11 07:14:02 +00:00
|
|
|
|
2025-05-25 14:48:53 +00:00
|
|
|
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-05-25 14:48:53 +00:00
|
|
|
static async getFilesRootPath(): Promise<string> {
|
|
|
|
|
await this.loadConfig();
|
|
|
|
|
|
|
|
|
|
const filesRootPath = `${Deno.cwd()}/${this.config.files.rootPath}`;
|
|
|
|
|
|
|
|
|
|
return filesRootPath;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
2024-04-03 13:02:04 +00:00
|
|
|
}
|