2020-06-30 01:10:18 +02:00
|
|
|
import {ArrayField, Field, RawJsonField} from "sparkson"
|
2022-07-14 20:06:05 +02:00
|
|
|
import {ClientConfig, to} from "./shared";
|
2020-06-30 01:10:18 +02:00
|
|
|
|
|
|
|
// TODO: Replace string types by more specific types like URL, Password, etc.
|
|
|
|
|
2022-07-14 20:06:05 +02:00
|
|
|
export type Username = {
|
|
|
|
value: string;
|
|
|
|
readonly __tag: unique symbol
|
|
|
|
};
|
|
|
|
export type CleartextPassword = {
|
|
|
|
value: string;
|
|
|
|
readonly __tag: unique symbol
|
|
|
|
};
|
|
|
|
export type PasswordHash = {
|
|
|
|
value: string;
|
|
|
|
readonly __tag: unique symbol
|
|
|
|
};
|
2022-07-07 13:10:57 +02:00
|
|
|
|
|
|
|
export class UsersConfig {
|
2022-07-14 20:06:05 +02:00
|
|
|
public username: Username;
|
|
|
|
public passwordHash: PasswordHash;
|
|
|
|
|
2022-07-07 13:10:57 +02:00
|
|
|
constructor(
|
2022-07-14 20:06:05 +02:00
|
|
|
@Field("user") username: string,
|
|
|
|
@Field("passwordHash") passwordHash: string,
|
|
|
|
) {
|
|
|
|
this.username = to(username);
|
|
|
|
this.passwordHash = to(passwordHash);
|
|
|
|
}
|
2022-07-07 13:10:57 +02:00
|
|
|
}
|
|
|
|
|
2020-06-30 01:10:18 +02:00
|
|
|
export class LoggingConfig {
|
|
|
|
constructor(
|
2021-08-23 21:05:17 +02:00
|
|
|
@Field("enabled") public enabled: boolean,
|
2020-06-30 01:10:18 +02:00
|
|
|
@Field("debug") public debug: boolean,
|
|
|
|
@Field("profile") public profile: boolean,
|
|
|
|
) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class InternalConfig {
|
|
|
|
constructor(
|
|
|
|
@Field("active") public active: boolean,
|
2022-07-07 13:10:57 +02:00
|
|
|
@ArrayField("users", UsersConfig) public users: UsersConfig[],
|
2020-06-30 01:10:18 +02:00
|
|
|
) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class EmailConfig {
|
|
|
|
constructor(
|
|
|
|
@Field("from") public from: string,
|
|
|
|
|
|
|
|
// For details see: https://nodemailer.com/2-0-0-beta/setup-smtp/
|
|
|
|
@RawJsonField("smtp") public smtp: any, // TODO: Better types!
|
|
|
|
) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ServerMapConfig {
|
|
|
|
constructor(
|
|
|
|
@ArrayField("nodesJsonUrl", String) public nodesJsonUrl: string[],
|
|
|
|
) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ServerConfig {
|
|
|
|
constructor(
|
|
|
|
@Field("baseUrl") public baseUrl: string,
|
|
|
|
@Field("port") public port: number,
|
|
|
|
|
|
|
|
@Field("databaseFile") public databaseFile: string,
|
|
|
|
@Field("peersPath") public peersPath: string,
|
|
|
|
|
|
|
|
@Field("logging") public logging: LoggingConfig,
|
|
|
|
@Field("internal") public internal: InternalConfig,
|
|
|
|
@Field("email") public email: EmailConfig,
|
|
|
|
@Field("map") public map: ServerMapConfig,
|
|
|
|
|
|
|
|
@Field("rootPath", true, undefined, "/") public rootPath: string,
|
|
|
|
) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Config {
|
|
|
|
constructor(
|
|
|
|
@Field("server") public server: ServerConfig,
|
2022-05-19 13:33:48 +02:00
|
|
|
@Field("client") public client: ClientConfig,
|
2020-06-30 01:10:18 +02:00
|
|
|
) {}
|
|
|
|
}
|