Files
evig/scripts/setup-all-admins.ts
GandClaude Opus 5 a21d8906af chore: add a formatter, and close a CSS comment that was never closed (#419)
* chore: add a formatter, matching the style this repo already writes

singleQuote=true was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier, and close a comment that was never closed

The formatter refused this repo outright, which turned out to be a real defect
rather than a tooling complaint. kivitendo-intake.css opens a header comment,
and line 17 contains an inner /* ⚠ PRÜFEN */ — CSS comments do not nest, so
that inner terminator CLOSES the header. Everything after it is parsed as CSS
until the stray */ on line 20. A browser mis-parses it the same way.

The file exists in two places (public/presentations/ and deliverables/), both
carrying the same defect; fixing one still failed the gate, which is how the
duplicate surfaced at all.

Mechanical otherwise. This SHA is listed in .git-blame-ignore-revs.

* chore: teach git blame to skip the reformat

* fix: undo a 3-way merge duplication in AdminSidebar.tsx

Merging main with -X theirs duplicated a 30-line block: main's currency-sweep
commit and this branch's prettier reformat both touched overlapping lines in
the single-destination-group render path, and the -X theirs strategy inserted
rather than replaced, leaving two near-identical copies and a dangling closing
brace — SyntaxError: ',' expected at line 298.

The branch has no legitimate change to this file's logic, only formatting, so
main's content is correct outright. Took it wholesale rather than hand-editing
the merge result.

* fix(lint): reattach 5 directives the reformat detached

Four eslint-disable-next-line sites for react-hooks/set-state-in-effect and one
@ts-expect-error, all the same defect: the directive sat above useEffect( (or
above a JSX element), while the statement that actually errors is 1-2 lines
further down inside the block. eslint/tsc report at the real statement; the
directive, still bound to its original line number, protects nothing there.

TimecardReviewDrawer.tsx (x2), DataEntryTabs.tsx, AppointmentBookingForm.tsx,
CreatePoolModal.tsx. Same root cause documented for hirnli, fleetcrown and
ivy-portal earlier today — a positional directive is a hidden dependency on
formatting, and this is the fourth distinct shape it's taken.

* fix(i18n): restore a same-line audit-exemption marker

Fifth shape of today's positional-directive defect, this time the repo's own
i18n-hardcoded-audit convention rather than eslint or tsc: a // i18n-ok comment
exempts a hardcoded string only when it trails the SAME line. prettier wrapped
this one if-statement's long condition onto its own line, leaving the marker
on the return statement below — the exact sibling one line down
('fortgeschrittene bis experten') stayed on one line because it was short
enough not to wrap, and it alone kept passing.

Restored the one-line form and added // prettier-ignore so a future reformat
cannot re-split it. Verified against the real audit script locally: 0 new
violations.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 13:35:50 +00:00

139 lines
3.8 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import { Client } from 'pg';
import bcrypt from 'bcryptjs';
function loadEnvFile(filePath: string) {
if (!fs.existsSync(filePath)) return;
const lines = fs.readFileSync(filePath, 'utf8').split(/\r?\n/);
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const match = trimmed.match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/);
if (!match) continue;
const [, key, rawValue] = match;
if (process.env[key] !== undefined) continue;
process.env[key] = rawValue.replace(/^['"]|['"]$/g, '');
}
}
loadEnvFile(path.join(process.cwd(), '.env.local'));
loadEnvFile(path.join(process.cwd(), '.env'));
function getDbConfig(): {
connectionString?: string;
host?: string;
port?: number;
database?: string;
user?: string;
password?: string;
ssl?: false | { rejectUnauthorized: boolean };
} {
if (process.env.DATABASE_URL) {
return { connectionString: process.env.DATABASE_URL };
}
return {
host: process.env.DB_HOST || 'localhost',
port: Number(process.env.DB_PORT || 5433),
database: process.env.DB_NAME || 'revampit_cms',
user: process.env.DB_USER || 'postgres',
password: process.env.DB_PASSWORD || 'postgres',
ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : false,
};
}
function getAdminPassword() {
const password = process.env.ADMIN_PASSWORD || process.env.SETUP_ADMIN_PASSWORD;
if (password) return password;
if (process.env.NODE_ENV === 'production') {
throw new Error(
'Set ADMIN_PASSWORD or SETUP_ADMIN_PASSWORD when bootstrapping production admins.',
);
}
return 'Admin123!';
}
async function setupAllAdmins() {
const client = new Client(getDbConfig());
const email = process.env.ADMIN_EMAIL || 'admin@revampit.ch';
const password = getAdminPassword();
const passwordHash = await bcrypt.hash(password, 12);
await client.connect();
try {
await client.query('BEGIN');
const result = await client.query<{ id: string }>(
`
INSERT INTO users (
email,
name,
password_hash,
role,
"emailVerified",
is_staff,
staff_permissions,
is_super_admin,
dashboard_mode,
"createdAt",
"updatedAt"
)
VALUES (
$1,
$2,
$3,
'revampit_admin',
NOW(),
true,
ARRAY['*']::text[],
true,
'lead',
NOW(),
NOW()
)
ON CONFLICT (email) DO UPDATE SET
name = COALESCE(users.name, EXCLUDED.name),
password_hash = EXCLUDED.password_hash,
role = EXCLUDED.role,
"emailVerified" = COALESCE(users."emailVerified", NOW()),
is_staff = true,
staff_permissions = ARRAY['*']::text[],
is_super_admin = true,
dashboard_mode = COALESCE(users.dashboard_mode, 'lead'),
"updatedAt" = NOW()
RETURNING id
`,
[email, 'Admin RevampIT', passwordHash],
);
await client.query(
`
INSERT INTO user_profiles (user_id, display_name, preferred_language, created_at, updated_at)
VALUES ($1, 'Admin RevampIT', 'de', NOW(), NOW())
ON CONFLICT (user_id) DO NOTHING
`,
[result.rows[0].id],
);
await client.query('COMMIT');
console.log('Admin user ready.');
console.log(`Email: ${email}`);
console.log(
process.env.ADMIN_PASSWORD || process.env.SETUP_ADMIN_PASSWORD
? 'Password: from ADMIN_PASSWORD/SETUP_ADMIN_PASSWORD'
: 'Password: Admin123! (development default)',
);
} catch (error) {
await client.query('ROLLBACK');
throw error;
} finally {
await client.end();
}
}
setupAllAdmins().catch((error) => {
console.error('Failed to setup admin user:', error);
process.exit(1);
});