Files
scan-receipts/scripts/generate_apple_keys.mjs
Timo 84b9987c49 Add full application: receipt scanning, auth, billing, and account deletion
Brings the working codebase (Next.js app, auth system, Stripe billing,
Docker/deploy config, tests, docs) into version control on top of the
placeholder initial commit, and adds account self-deletion (Danger Zone
in Settings, password + typed-email confirmation, cascading DB cleanup,
Stripe cancellation) per GDPR right-to-erasure.

Excludes local build caches, node_modules, and internal agent scratch
files; .gitignore hardened to keep those out going forward.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-19 20:59:04 +02:00

44 lines
1.4 KiB
JavaScript

import crypto from 'crypto';
import fs from 'fs';
// Generate EC key pair with curve prime256v1 (P-256) as required by Apple
const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', {
namedCurve: 'prime256v1',
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
});
console.log("=== NEUER PUBLIC KEY (FÜR APPLE SEARCH ADS) ===");
console.log(publicKey);
// Update .env.local with the new private key
const envPath = '.env.local';
let envContent = fs.readFileSync(envPath, 'utf8');
// Replace or set APPLE_SEARCH_ADS_PRIVATE_KEY
const cleanPrivateKey = privateKey.replace(/\r\n/g, '\n');
const formattedPrivateKey = `APPLE_SEARCH_ADS_PRIVATE_KEY="${cleanPrivateKey.replace(/\n/g, '\\n')}"`;
if (envContent.includes('APPLE_SEARCH_ADS_PRIVATE_KEY=')) {
envContent = envContent.replace(/APPLE_SEARCH_ADS_PRIVATE_KEY=.*/g, formattedPrivateKey);
} else {
envContent += `\n${formattedPrivateKey}\n`;
}
// Update public key in .env.local too
const formattedPublicKey = `APPLE_SEARCH_ADS_PUBLIC_KEY="${publicKey.replace(/\r\n/g, '\n').replace(/\n/g, '\\n')}"`;
if (envContent.includes('APPLE_SEARCH_ADS_PUBLIC_KEY=')) {
envContent = envContent.replace(/APPLE_SEARCH_ADS_PUBLIC_KEY=.*/g, formattedPublicKey);
} else {
envContent += `\n${formattedPublicKey}\n`;
}
fs.writeFileSync(envPath, envContent);
console.log("\n-> Private Key wurde automatisch in .env.local gespeichert!");