LifeMate — Personal, Family & Learning Companion
test/android-reminder-acceptance
chore/phase1-repository-cleanup
deploy/stable-web-apk
deployment-static
design/mobile-accessibility-v2
design/mobile-navigation-review
docs/child-education-access-decision
docs/offline-data-rescue-options
docs/owner-guide-and-delivery-plan
docs/phase1-policy-options
docs/public-review-live-2026-10-15
feat/aparat-learning-library
feat/child-device-safety
feat/child-identity-schema
feat/flutter-mobile-navigation
feat/learning-content-operations
feat/local-signing-preflight
feat/online-family-stage0
feat/personal-encrypted-recovery
feat/private-planner-series-api
feat/public-review-page
feat/standalone-weekly-planner
feat/weekly-planner-android
final-feature-1/iran-family-school
fix/auth-abuse-expiry-safety
fix/auth-expiry-after-lock
fix/backend-request-safety
fix/lifeguide-bootstrap-naming-ci
fix/lifeguide-pages-qa-base-preflight
fix/lifeguide-qa-pages-env-deployment
fix/local-task-persistence
fix/managed-child-session-boundary
fix/personal-jalali-dates
fix/personal-notification-controls
fix/personal-upgrade-delivery-guard
fix/sms-approval-gates
fix/study-duration-display
infra/cloudflare-neon-migration
infra/lifeguide-cloudflare-qa
infra/lifeguide-github-pages-qa
infra/lifeguide-supabase-qa
main
phase-1/foundation-completion
phase-2/product-foundation-identity
phase-3/planner-school-family-core
phase-4/ai-learning-wellbeing
phase-5/hardening-observability-release
test/android-reminder-acceptance
test/personal-notification-settings
test/personal-recovery-acceptance
test/role-entry-apk
| 1 | // Offline local-file preparation only. Preserves existing secrets/settings. |
| 2 | import crypto from 'node:crypto'; |
| 3 | import fs from 'node:fs/promises'; |
| 4 | const envFile = new URL('../.env',import.meta.url); |
| 5 | if (process.argv[2] !== '--write' || process.argv.length !== 3) throw new Error('Use --write to append missing private local role settings'); |
| 6 | let contents = await fs.readFile(envFile,'utf8'); |
| 7 | const original = contents; |
| 8 | const additions=[]; |
| 9 | for(const [prefix,user] of [['API','lifeguide_api'],['MIGRATOR','lifeguide_migrator'],['BACKUP','lifeguide_backup']]) { |
| 10 | const userPattern = new RegExp(`^${prefix}_DB_USER=(.*)$`,'m'); |
| 11 | const existingUser=contents.match(userPattern)?.[1]; |
| 12 | if(existingUser && existingUser!==user) throw new Error('Configured application roles must use their canonical distinct names'); |
| 13 | if(!existingUser) { |
| 14 | if(userPattern.test(contents)) contents=contents.replace(userPattern,`${prefix}_DB_USER=${user}`); |
| 15 | else additions.push(`${prefix}_DB_USER=${user}`); |
| 16 | } |
| 17 | const passwordPattern = new RegExp(`^${prefix}_DB_PASSWORD=(.*)$`,'m'); |
| 18 | const existingPassword = contents.match(passwordPattern)?.[1]; |
| 19 | if(!existingPassword || existingPassword.startsWith('CHANGE_ME')) { |
| 20 | const value=`${prefix}_DB_PASSWORD=${crypto.randomBytes(32).toString('hex')}`; |
| 21 | if(passwordPattern.test(contents)) contents=contents.replace(passwordPattern,value); |
| 22 | else additions.push(value); |
| 23 | } |
| 24 | } |
| 25 | if(additions.length) { |
| 26 | contents=contents.replace(/\s*$/,'')+'\n# Independent local application DB credentials\n'+additions.join('\n')+'\n'; |
| 27 | } |
| 28 | if(contents!==original) { |
| 29 | const temporary = new URL(`../.env.roles-${crypto.randomBytes(8).toString('hex')}.tmp`,import.meta.url); |
| 30 | try { |
| 31 | const file=await fs.open(temporary,'wx',0o600); |
| 32 | try { await file.writeFile(contents); await file.sync(); } finally { await file.close(); } |
| 33 | await fs.rename(temporary,envFile); |
| 34 | } finally { await fs.rm(temporary,{force:true}); } |
| 35 | console.log('Appended missing private role settings; existing values preserved. No database/server operation ran.'); |
| 36 | } else console.log('Private role settings already present; preserved unchanged.'); |