LifeMate — Personal, Family & Learning Companion

docs/offline-data-rescue-options
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
js 43 lines 3.62 KB
Raw
1 // Three synthetic accounts for local Android/PWA acceptance. Not a live seed.
2 import argon2 from 'argon2';
3 import pg from 'pg';
4 if (process.env.ALLOW_SYNTHETIC_SEED !== 'yes') throw new Error('ALLOW_SYNTHETIC_SEED=yes required');
5 const password = process.env.SYNTHETIC_PASSWORD;
6 if (typeof password !== 'string' || password.length < 10) throw new Error('Provide a random synthetic password of at least 10 characters');
7 const members = [
8 { id: 'a0000000-0000-4000-8000-000000000001', email: 'stage0-child@lifeguide.test', name: 'فرزند آزمایشی', role: 'teen_minor', theme: 'boy_blue', category: 'boy_minor' },
9 { id: 'a0000000-0000-4000-8000-000000000002', email: 'stage0-mother@lifeguide.test', name: 'مادر آزمایشی', role: 'parent_guardian', theme: 'adult_blue', category: 'adult' },
10 { id: 'a0000000-0000-4000-8000-000000000003', email: 'stage0-father@lifeguide.test', name: 'پدر آزمایشی', role: 'parent_guardian', theme: 'adult_blue', category: 'adult' },
11 ];
12 const familyId = 'a1000000-0000-4000-8000-000000000001';
13 const pool = new pg.Pool();
14 const client = await pool.connect();
15 try {
16 await client.query('begin');
17 const hash = await argon2.hash(password, { type: argon2.argon2id });
18 for (const member of members) {
19 const subject = `stage0-synthetic-family:${member.id}`;
20 const existing = await client.query('select id,identity_subject from app_user where id=$1 or email_normalized=$2 for update', [member.id, member.email]);
21 if (existing.rowCount && (existing.rowCount !== 1 || existing.rows[0].id !== member.id || existing.rows[0].identity_subject !== subject)) throw new Error('Refusing to modify a non-fixture account');
22 await client.query('insert into app_user(id,identity_subject,email_normalized,email_verified_at) values($1,$2,$3,now()) on conflict(id) do nothing', [member.id, subject, member.email]);
23 await client.query('insert into profile(user_id,display_name,theme_preference,profile_category) values($1,$2,$3,$4) on conflict(user_id) do update set display_name=excluded.display_name,theme_preference=excluded.theme_preference,profile_category=excluded.profile_category', [member.id, member.name, member.theme, member.category]);
24 await client.query('insert into auth_credential(user_id,password_hash) values($1,$2) on conflict(user_id) do update set password_hash=excluded.password_hash', [member.id, hash]);
25 }
26 const family = await client.query('select created_by from family_workspace where id=$1 for update', [familyId]);
27 if (family.rowCount && family.rows[0].created_by !== members[1].id) throw new Error('Refusing to modify a non-fixture family');
28 await client.query("insert into family_workspace(id,name,created_by) values($1,'LifeGuide Synthetic Stage0 Family',$2) on conflict(id) do nothing", [familyId, members[1].id]);
29 for (const member of members) {
30 await client.query('insert into family_membership(family_id,user_id,role,is_admin) values($1,$2,$3,$4) on conflict(family_id,user_id) do update set role=excluded.role,ended_at=null,is_admin=excluded.is_admin', [familyId, member.id, member.role, member.role === 'parent_guardian']);
31 }
32 for (const parent of members.slice(1)) {
33 await client.query('insert into guardian_relationship(family_id,guardian_user_id,minor_user_id) values($1,$2,$3) on conflict(family_id,guardian_user_id,minor_user_id) do update set active=true', [familyId, parent.id, members[0].id]);
34 }
35 await client.query('commit');
36 console.log('Synthetic Stage0 child/mother/father accounts and permitted guardian relationships ready. Password not logged.');
37 } catch (error) {
38 await client.query('rollback');
39 throw error;
40 } finally {
41 client.release();
42 await pool.end();
43 }