mirror of
https://github.com/bitbaum/evig.git
synced 2026-12-05 00:27:53 +01:00
* 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>
193 lines
5.7 KiB
JavaScript
193 lines
5.7 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* PCI DSS Data Cleanup Script
|
|
* Removes or anonymizes sensitive payment data after retention periods
|
|
* Runs periodically to maintain PCI compliance
|
|
*/
|
|
|
|
const { Client } = require('pg');
|
|
const {
|
|
cleanupExpiredData,
|
|
PCI_COMPLIANCE,
|
|
maskSensitiveData,
|
|
} = require('../src/lib/payments/security');
|
|
|
|
// Database configuration
|
|
const dbConfig = {
|
|
host: process.env.DB_HOST || 'localhost',
|
|
port: process.env.DB_PORT || 5433,
|
|
database: process.env.DB_NAME || 'revampit_cms',
|
|
user: process.env.DB_USER || 'postgres',
|
|
password: process.env.DB_PASSWORD || 'postgres',
|
|
};
|
|
|
|
async function cleanupPCIData() {
|
|
const client = new Client(dbConfig);
|
|
|
|
try {
|
|
await client.connect();
|
|
console.log('Connected to database for PCI cleanup');
|
|
|
|
const cutoffDate = new Date();
|
|
cutoffDate.setDate(cutoffDate.getDate() - PCI_COMPLIANCE.DATA_RETENTION.CARD_DATA_MAX_DAYS);
|
|
|
|
console.log(`Cleaning up payment data older than ${cutoffDate.toISOString()}`);
|
|
|
|
// 1. Anonymize old payment transaction metadata
|
|
console.log('Step 1: Anonymizing old transaction metadata...');
|
|
|
|
const anonymizeResult = await client.query(
|
|
`
|
|
UPDATE payment_transactions
|
|
SET metadata = jsonb_build_object(
|
|
'anonymized', true,
|
|
'anonymized_at', $2,
|
|
'original_amount', (metadata->>'subtotalCents')::int / 100.0,
|
|
'original_currency', currency
|
|
)
|
|
WHERE created_at < $1
|
|
AND (metadata->>'anonymized') IS NULL
|
|
AND type = 'payment'
|
|
`,
|
|
[cutoffDate, new Date().toISOString()],
|
|
);
|
|
|
|
console.log(`✓ Anonymized ${anonymizeResult.rowCount} transaction records`);
|
|
|
|
// 2. Clean up old webhook logs (keep only essential info)
|
|
console.log('Step 2: Cleaning webhook response data...');
|
|
|
|
const webhookCleanupResult = await client.query(
|
|
`
|
|
UPDATE payment_transactions
|
|
SET provider_response = jsonb_build_object(
|
|
'event_type', provider_response->'type',
|
|
'processed_at', provider_response->'created',
|
|
'status', provider_response->'status',
|
|
'anonymized', true
|
|
)
|
|
WHERE created_at < $1
|
|
AND jsonb_typeof(provider_response) = 'object'
|
|
AND (provider_response->>'anonymized') IS NULL
|
|
`,
|
|
[cutoffDate],
|
|
);
|
|
|
|
console.log(`✓ Cleaned ${webhookCleanupResult.rowCount} webhook records`);
|
|
|
|
// 3. Archive old refund data (move to archive table)
|
|
console.log('Step 3: Archiving old refund data...');
|
|
|
|
// Create archive table if it doesn't exist
|
|
await client.query(`
|
|
CREATE TABLE IF NOT EXISTS archived_refunds (
|
|
LIKE refunds INCLUDING ALL,
|
|
archived_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`);
|
|
|
|
const archiveResult = await client.query(
|
|
`
|
|
WITH moved_rows AS (
|
|
DELETE FROM refunds
|
|
WHERE created_at < $1
|
|
AND status IN ('completed', 'rejected')
|
|
RETURNING *
|
|
)
|
|
INSERT INTO archived_refunds
|
|
SELECT *, CURRENT_TIMESTAMP FROM moved_rows
|
|
`,
|
|
[cutoffDate],
|
|
);
|
|
|
|
console.log(`✓ Archived ${archiveResult.rowCount} old refund records`);
|
|
|
|
// 4. Clean up old payment analytics (keep summary data only)
|
|
console.log('Step 4: Cleaning payment analytics...');
|
|
|
|
const analyticsCutoff = new Date();
|
|
analyticsCutoff.setMonth(analyticsCutoff.getMonth() - 6); // Keep 6 months of detailed analytics
|
|
|
|
const analyticsCleanupResult = await client.query(
|
|
`
|
|
UPDATE payment_analytics
|
|
SET type_breakdown = jsonb_build_object(
|
|
'total_processed', (type_breakdown->>'payment')::int + (type_breakdown->>'refund')::int,
|
|
'anonymized', true
|
|
)
|
|
WHERE date < $1
|
|
AND (type_breakdown->>'anonymized') IS NULL
|
|
`,
|
|
[analyticsCutoff],
|
|
);
|
|
|
|
console.log(`✓ Cleaned ${analyticsCleanupResult.rowCount} analytics records`);
|
|
|
|
// 5. Remove old temporary data (in-memory cleanup simulation)
|
|
console.log('Step 5: Simulating in-memory cleanup...');
|
|
|
|
const memoryCleanup = await cleanupExpiredData();
|
|
console.log(`✓ Memory cleanup completed:`, memoryCleanup);
|
|
|
|
// 6. Generate compliance report
|
|
console.log('Step 6: Generating compliance report...');
|
|
|
|
const complianceReport = await client.query(`
|
|
SELECT
|
|
'transactions_anonymized' as metric,
|
|
COUNT(*) as value
|
|
FROM payment_transactions
|
|
WHERE metadata->>'anonymized' = 'true'
|
|
UNION ALL
|
|
SELECT
|
|
'active_escrow_accounts' as metric,
|
|
COUNT(*) as value
|
|
FROM escrow_accounts
|
|
WHERE status = 'active'
|
|
UNION ALL
|
|
SELECT
|
|
'pending_refunds' as metric,
|
|
COUNT(*) as value
|
|
FROM refunds
|
|
WHERE status IN ('requested', 'approved')
|
|
UNION ALL
|
|
SELECT
|
|
'total_payment_volume_30d' as metric,
|
|
COALESCE(SUM(amount_cents), 0) / 100 as value
|
|
FROM payment_transactions
|
|
WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
|
|
AND status = 'succeeded'
|
|
AND type = 'payment'
|
|
`);
|
|
|
|
console.log('📊 PCI Compliance Report:');
|
|
complianceReport.rows.forEach((row) => {
|
|
console.log(` ${row.metric}: ${row.value}`);
|
|
});
|
|
|
|
console.log('\n✅ PCI DSS data cleanup completed successfully');
|
|
} catch (error) {
|
|
console.error('PCI cleanup script error:', error);
|
|
process.exit(1);
|
|
} finally {
|
|
await client.end();
|
|
console.log('Database connection closed');
|
|
}
|
|
}
|
|
|
|
// Run the script
|
|
if (require.main === module) {
|
|
cleanupPCIData()
|
|
.then(() => {
|
|
console.log('PCI data cleanup script completed successfully');
|
|
process.exit(0);
|
|
})
|
|
.catch((error) => {
|
|
console.error('PCI data cleanup script failed:', error);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
module.exports = { cleanupPCIData };
|