constants.ts
Raw
1import path from "node:path";
2import config from "./config.ts";
3
4// Auth / identity
5export const WEBAUTHN_RP_NAME = `${config.OWNER_DISPLAY_NAME}'s Hearthforge`;
6export const ADMIN_USERNAME = "admin";
7export const VALID_USERNAME_RE = /^[a-zA-Z0-9_-]+$/;
8export const VALID_REPO_NAME_RE = /^[a-zA-Z0-9._-]+$/;
9export const ALLOWED_REACTIONS = new Set([
10 "👍",
11 "👎",
12 "❤️",
13 "🎉",
14 "😕",
15 "👀",
16 "🚀",
17]);
18export const VALID_KEY_TYPES = new Set([
19 "ssh-rsa",
20 "ssh-ed25519",
21 "ecdsa-sha2-nistp256",
22 "ecdsa-sha2-nistp384",
23 "ecdsa-sha2-nistp521",
24 "sk-ssh-ed25519@openssh.com",
25 "sk-ecdsa-sha2-nistp256@openssh.com",
26]);
27export const CHALLENGE_TTL_MS = 5 * 60 * 1000;
28
29// Rate limiting
30export const LOGIN_MAX_ATTEMPTS = 10;
31export const LOGIN_RATE_WINDOW_MS = 60_000;
32export const REGISTRATION_MAX_ATTEMPTS = 3;
33export const REGISTRATION_RATE_WINDOW_MS = 60 * 60_000;
34
35// Session
36export const SESSION_ID_BYTES = 32;
37export const SESSION_DURATION_MS = 30 * 24 * 60 * 60 * 1000;
38export const SESSION_DURATION_SECONDS = 30 * 24 * 60 * 60;
39export const MIN_PASSWORD_LENGTH = 8;
40
41// Cookie lifetimes
42export const YEAR_SECONDS = 365 * 24 * 60 * 60;
43
44// File handling
45export const BINARY_DETECT_BYTES = 8000;
46
47// Git ref limits
48export const MAX_REF_LIST = 1000;
49
50// Text preview
51export const PREVIEW_MAX_LENGTH = 180;
52export const PREVIEW_TRUNCATION_THRESHOLD = 0.6;
53
54// String length limits
55export const MAX_BRANCH_NAME_LENGTH = 255;
56export const MAX_TAG_NAME_LENGTH = 255;
57export const MAX_TAG_MESSAGE_LENGTH = 500;
58export const MAX_LABEL_NAME_LENGTH = 50;
59export const MAX_FILE_PATH_LENGTH = 1000;
60
61// Pagination
62export const REPOS_PER_PAGE = 20;
63export const COMMITS_PER_PAGE = 20;
64export const ISSUES_PER_PAGE = 20;
65export const PATCHES_PER_PAGE = 20;
66export const RELEASES_PER_PAGE = 20;
67export const CI_RUNS_PER_PAGE = 20;
68export const BRANCHES_PER_PAGE = 30;
69export const TAGS_PER_PAGE = 30;
70
71// Cache sizes
72export const MAX_MD_CACHE = 50;
73export const MAX_FILE_CACHE = 500;
74export const MAX_DIFF_CACHE = 500;
75export const MAX_PATCH_CACHE = 100;
76export const PATCH_CACHE_TTL_MS = 60 * 60 * 1000;
77export const MAX_BRANCH_CACHE = 200;
78export const MAX_TAG_CACHE = 200;
79export const REF_CACHE_TTL_MS = 30_000;
80
81// Paths — derived from config.DATA_DIR via getters so they reflect overrides.
82export const paths = {
83 get DB_PATH() {
84 return path.join(config.DATA_DIR, "hearthforge.db");
85 },
86 get REPOS_DIR() {
87 return path.join(config.DATA_DIR, "repos");
88 },
89 get AVATARS_DIR() {
90 return path.join(config.DATA_DIR, "avatars");
91 },
92 get RELEASES_DIR() {
93 return path.join(config.DATA_DIR, "releases");
94 },
95 get SSH_HOST_KEY_PATH() {
96 return (
97 process.env.SSH_HOST_KEY_PATH ??
98 path.join(config.DATA_DIR, "ssh_host_key")
99 );
100 },
101 get ALLOWED_SIGNERS_PATH() {
102 return path.join(config.DATA_DIR, "allowed_signers");
103 },
104 get CI_ARTIFACTS_DIR() {
105 return path.join(config.DATA_DIR, "ci", "artifacts");
106 },
107};
108