bulltrackers-module 1.0.595 → 1.0.597

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -510,23 +510,6 @@ const fetchUserVerificationData = async (firestore, userId) => {
510
510
  const docRef = firestore.collection('SignedInUsers').doc(userId).collection('verification').doc('data');
511
511
  const docSnapshot = await docRef.get();
512
512
  if (!docSnapshot.exists) {
513
- // Attempt migration from old location
514
- const oldCollectionRef = firestore.collection('signedInUsers');
515
- const oldSnapshot = await oldCollectionRef.get();
516
- for (const doc of oldSnapshot.docs) {
517
- const data = doc.data();
518
- if (data.etoroCID && String(data.etoroCID) === String(userId)) {
519
- // Found old data, migrate it
520
- await docRef.set({
521
- ...data,
522
- migratedFromId: doc.id // Store old firestore ID
523
- });
524
- // Delete old document
525
- await oldCollectionRef.doc(doc.id).delete();
526
- return { id: doc.id, ...data, migratedFromId: doc.id };
527
- }
528
- }
529
- // No data found
530
513
  throw new Error(`Verification data for User ID ${userId} not found`);
531
514
  }
532
515
  return { id: docSnapshot.id, ...docSnapshot.data() };
@@ -1517,19 +1500,30 @@ const finalizeVerification = async (db, pubsub, userId, username) => {
1517
1500
  isOptOut
1518
1501
  });
1519
1502
 
1520
- // 2. Create/Update User Doc in SignedInUsers
1521
- // Note: We use the realCID as the document ID, matching the generic-api logic
1522
- await db.collection(signedInUsersCollection).doc(String(realCID)).set({
1523
- username: profileData.username,
1524
- cid: realCID,
1525
- fullName: `${profileData.firstName || ''} ${profileData.lastName || ''}`.trim(),
1526
- avatar: profileData.avatars?.find(a => a.type === 'Original')?.url || null,
1527
- isOptOut,
1503
+ // 2. Create/Update verification data in new format location: /SignedInUsers/{cid}/verification/data
1504
+ const verificationDataRef = db.collection('SignedInUsers').doc(String(realCID)).collection('verification').doc('data');
1505
+ const existingVerificationDoc = await verificationDataRef.get();
1506
+
1507
+ let emails = [];
1508
+ if (existingVerificationDoc.exists()) {
1509
+ const existingData = existingVerificationDoc.data();
1510
+ // Preserve existing email array if present
1511
+ emails = Array.isArray(existingData.email) ? existingData.email : (existingData.email ? [existingData.email] : []);
1512
+ }
1513
+ // Note: Email will be added by frontend completeAccountSetup when Firebase Auth email is available
1514
+
1515
+ await verificationDataRef.set({
1516
+ etoroUsername: profileData.username,
1517
+ etoroCID: realCID,
1518
+ email: emails, // Array - will be populated by frontend
1519
+ displayName: `${profileData.firstName || ''} ${profileData.lastName || ''}`.trim(),
1520
+ photoURL: profileData.avatars?.find(a => a.type === 'Original')?.url || null,
1528
1521
  verifiedAt: FieldValue.serverTimestamp(),
1529
- lastLogin: FieldValue.serverTimestamp()
1522
+ accountSetupComplete: false, // Will be set to true by frontend completeAccountSetup
1523
+ createdAt: FieldValue.serverTimestamp(),
1530
1524
  }, { merge: true });
1531
1525
 
1532
- // 3. Trigger Downstream Systems via Task Engine
1526
+ // 4. Trigger Downstream Systems via Task Engine
1533
1527
  if (pubsub) {
1534
1528
  try {
1535
1529
  // Replicating the 'unifiedTask' payload from generic-api
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.595",
3
+ "version": "1.0.597",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [