ff-admin-server/src/type/settingTypes.ts

122 lines
4.2 KiB
TypeScript
Raw Normal View History

2025-04-19 11:26:35 +02:00
import ms from "ms";
export type SettingTopic = "club" | "app" | "session" | "mail" | "backup" | "security";
export type SettingString =
2025-04-24 16:49:16 +02:00
| "club.icon"
| "club.logo"
2025-04-19 11:26:35 +02:00
| "club.name"
| "club.imprint"
| "club.privacy"
| "club.website"
| "app.custom_login_message"
| "app.show_link_to_calendar"
| "session.jwt_expiration"
| "session.refresh_expiration"
| "session.pwa_refresh_expiration"
2025-04-25 12:13:26 +02:00
| "mail.email"
2025-04-19 11:26:35 +02:00
| "mail.username"
| "mail.password"
| "mail.host"
| "mail.port"
| "mail.secure"
| "backup.interval"
| "backup.copies";
2025-04-19 11:26:35 +02:00
2025-04-25 12:13:26 +02:00
export type SettingTypeAtom = "longstring" | "string" | "ms" | "number" | "boolean" | "url" | "email";
2025-04-19 11:26:35 +02:00
export type SettingType = SettingTypeAtom | `${SettingTypeAtom}/crypt` | `${SettingTypeAtom}/rand`;
2025-04-20 15:32:57 +02:00
export type SettingValueMapping = {
2025-04-24 16:49:16 +02:00
"club.icon": string;
"club.logo": string;
2025-04-20 15:32:57 +02:00
"club.name": string;
"club.imprint": string;
"club.privacy": string;
"club.website": string;
"app.custom_login_message": string;
"app.show_link_to_calendar": boolean;
"session.jwt_expiration": ms.StringValue;
"session.refresh_expiration": ms.StringValue;
"session.pwa_refresh_expiration": ms.StringValue;
2025-04-25 12:13:26 +02:00
"mail.email": string;
2025-04-20 15:32:57 +02:00
"mail.username": string;
"mail.password": string;
"mail.host": string;
"mail.port": number;
"mail.secure": boolean;
"backup.interval": number;
"backup.copies": number;
};
// Typsicherer Zugriff auf Settings
export type SettingDefinition<T extends SettingType | SettingTypeAtom[]> = {
type: T;
default?: string | number | boolean | ms.StringValue;
2025-04-20 15:32:57 +02:00
optional?: boolean;
min?: T extends "number" | `number/crypt` | `number/rand` ? number : never;
};
export type SettingsSchema = {
[key in SettingString]: SettingDefinition<SettingType | SettingTypeAtom[]>;
};
export const settingsType: SettingsSchema = {
2025-04-24 16:49:16 +02:00
"club.icon": { type: "string", optional: true },
"club.logo": { type: "string", optional: true },
2025-04-19 11:26:35 +02:00
"club.name": { type: "string", default: "FF Admin" },
"club.imprint": { type: "url", optional: true },
"club.privacy": { type: "url", optional: true },
"club.website": { type: "url", optional: true },
"app.custom_login_message": { type: "string", optional: true },
"app.show_link_to_calendar": { type: "boolean", default: true },
"session.jwt_expiration": { type: "ms", default: "15m" },
"session.refresh_expiration": { type: "ms", default: "1d" },
"session.pwa_refresh_expiration": { type: "ms", default: "5d" },
2025-04-25 12:13:26 +02:00
"mail.email": { type: "email", optional: false },
2025-04-19 11:26:35 +02:00
"mail.username": { type: "string", optional: false },
"mail.password": { type: "string/crypt", optional: false },
"mail.host": { type: "url", optional: false },
"mail.port": { type: "number", default: 587 },
"mail.secure": { type: "boolean", default: false },
"backup.interval": { type: "number", default: 1, min: 1 },
"backup.copies": { type: "number", default: 7, min: 1 },
2025-04-19 11:26:35 +02:00
};
/** ENV Settings */
export type EnvSettingString =
| "database.type"
| "database.host"
| "database.port"
| "database.name"
| "database.username"
| "database.password"
| "application.secret"
| "security.strict_limit"
| "security.strict_limit_window"
| "security.strict_limit_request_count"
| "security.limit"
| "security.limit_window"
| "security.limit_request_count"
| "security.trust_proxy";
2025-04-19 11:26:35 +02:00
export const envSettingsType: {
[key in EnvSettingString]: {
type: SettingType | SettingType[];
default?: string | number | boolean;
2025-04-19 11:26:35 +02:00
};
} = {
"database.type": { type: "string", default: "postgres" },
"database.host": { type: "string" },
"database.port": { type: "string", default: "5432" },
"database.name": { type: "string" },
"database.username": { type: "string" },
"database.password": { type: "string" },
"application.secret": { type: "string" },
"security.strict_limit": { type: "boolean", default: true },
"security.strict_limit_window": { type: "ms", default: "15m" },
"security.strict_limit_request_count": { type: "number", default: 15 },
"security.limit": { type: "boolean", default: true },
"security.limit_window": { type: "ms", default: "1m" },
"security.limit_request_count": { type: "number", default: 500 },
"security.trust_proxy": { type: ["boolean", "number", "string"] },
2025-04-19 11:26:35 +02:00
};