bulltrackers-module 1.0.591 → 1.0.592

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.
Files changed (68) hide show
  1. package/functions/alert-system/helpers/alert_helpers.js +6 -6
  2. package/functions/alert-system/index.js +1 -1
  3. package/functions/api-v2/helpers/data-fetchers/firestore.js +2218 -0
  4. package/functions/api-v2/helpers/task_engine_helper.js +51 -0
  5. package/functions/api-v2/index.js +36 -0
  6. package/functions/api-v2/middleware/identity_middleware.js +48 -0
  7. package/functions/api-v2/package.json +6 -0
  8. package/functions/api-v2/routes/alerts.js +168 -0
  9. package/functions/api-v2/routes/index.js +35 -0
  10. package/functions/api-v2/routes/notifications.js +38 -0
  11. package/functions/api-v2/routes/popular_investors.js +204 -0
  12. package/functions/api-v2/routes/profile.js +212 -0
  13. package/functions/api-v2/routes/reviews.js +72 -0
  14. package/functions/api-v2/routes/settings.js +71 -0
  15. package/functions/api-v2/routes/sync.js +132 -0
  16. package/functions/api-v2/routes/verification.js +47 -0
  17. package/functions/api-v2/routes/watchlists.js +148 -0
  18. package/functions/computation-system/helpers/computation_worker.js +1 -1
  19. package/functions/task-engine/helpers/popular_investor_helpers.js +2 -2
  20. package/index.js +6 -2
  21. package/package.json +2 -1
  22. package/functions/generic-api/admin-api/index.js +0 -895
  23. package/functions/generic-api/helpers/api_helpers.js +0 -457
  24. package/functions/generic-api/index.js +0 -204
  25. package/functions/generic-api/user-api/ADDING_LEGACY_ROUTES_GUIDE.md +0 -345
  26. package/functions/generic-api/user-api/CODE_REORGANIZATION_PLAN.md +0 -320
  27. package/functions/generic-api/user-api/COMPLETE_REFACTORING_PLAN.md +0 -116
  28. package/functions/generic-api/user-api/FIRESTORE_PATHS_INVENTORY.md +0 -171
  29. package/functions/generic-api/user-api/FIRESTORE_PATH_MIGRATION_REFERENCE.md +0 -710
  30. package/functions/generic-api/user-api/FIRESTORE_PATH_VALIDATION.md +0 -109
  31. package/functions/generic-api/user-api/MIGRATION_PLAN.md +0 -499
  32. package/functions/generic-api/user-api/README_MIGRATION.md +0 -152
  33. package/functions/generic-api/user-api/REFACTORING_COMPLETE.md +0 -106
  34. package/functions/generic-api/user-api/REFACTORING_STATUS.md +0 -85
  35. package/functions/generic-api/user-api/VERIFICATION_MIGRATION_NOTES.md +0 -206
  36. package/functions/generic-api/user-api/helpers/ORGANIZATION_COMPLETE.md +0 -126
  37. package/functions/generic-api/user-api/helpers/alerts/alert_helpers.js +0 -355
  38. package/functions/generic-api/user-api/helpers/alerts/subscription_helpers.js +0 -327
  39. package/functions/generic-api/user-api/helpers/alerts/test_alert_helpers.js +0 -212
  40. package/functions/generic-api/user-api/helpers/collection_helpers.js +0 -193
  41. package/functions/generic-api/user-api/helpers/core/compression_helpers.js +0 -68
  42. package/functions/generic-api/user-api/helpers/core/data_lookup_helpers.js +0 -256
  43. package/functions/generic-api/user-api/helpers/core/path_resolution_helpers.js +0 -640
  44. package/functions/generic-api/user-api/helpers/core/user_status_helpers.js +0 -195
  45. package/functions/generic-api/user-api/helpers/data/computation_helpers.js +0 -503
  46. package/functions/generic-api/user-api/helpers/data/instrument_helpers.js +0 -55
  47. package/functions/generic-api/user-api/helpers/data/portfolio_helpers.js +0 -245
  48. package/functions/generic-api/user-api/helpers/data/social_helpers.js +0 -174
  49. package/functions/generic-api/user-api/helpers/data_helpers.js +0 -87
  50. package/functions/generic-api/user-api/helpers/dev/dev_helpers.js +0 -336
  51. package/functions/generic-api/user-api/helpers/fetch/on_demand_fetch_helpers.js +0 -615
  52. package/functions/generic-api/user-api/helpers/metrics/personalized_metrics_helpers.js +0 -231
  53. package/functions/generic-api/user-api/helpers/notifications/notification_helpers.js +0 -641
  54. package/functions/generic-api/user-api/helpers/profile/pi_profile_helpers.js +0 -182
  55. package/functions/generic-api/user-api/helpers/profile/profile_view_helpers.js +0 -137
  56. package/functions/generic-api/user-api/helpers/profile/user_profile_helpers.js +0 -190
  57. package/functions/generic-api/user-api/helpers/recommendations/recommendation_helpers.js +0 -66
  58. package/functions/generic-api/user-api/helpers/reviews/review_helpers.js +0 -550
  59. package/functions/generic-api/user-api/helpers/rootdata/rootdata_aggregation_helpers.js +0 -378
  60. package/functions/generic-api/user-api/helpers/search/pi_request_helpers.js +0 -295
  61. package/functions/generic-api/user-api/helpers/search/pi_search_helpers.js +0 -162
  62. package/functions/generic-api/user-api/helpers/sync/user_sync_helpers.js +0 -677
  63. package/functions/generic-api/user-api/helpers/verification/verification_helpers.js +0 -323
  64. package/functions/generic-api/user-api/helpers/watchlist/watchlist_analytics_helpers.js +0 -96
  65. package/functions/generic-api/user-api/helpers/watchlist/watchlist_data_helpers.js +0 -141
  66. package/functions/generic-api/user-api/helpers/watchlist/watchlist_generation_helpers.js +0 -310
  67. package/functions/generic-api/user-api/helpers/watchlist/watchlist_management_helpers.js +0 -829
  68. package/functions/generic-api/user-api/index.js +0 -109
@@ -1,710 +0,0 @@
1
- # Firestore Path Migration Reference
2
-
3
- ## Complete Legacy → New Path Mapping
4
-
5
- This document provides a comprehensive reference for all Firestore path migrations from legacy formats to the new user-centric structure. All paths include example values for dynamic segments.
6
-
7
- ---
8
-
9
- ## 1. User Notifications
10
-
11
- ### Legacy Paths
12
- ```
13
- user_notifications/{userCid}/notifications/{notificationId}
14
- user_notifications/{userCid}/counters/{date}
15
- user_notifications/{firebaseUid}/notifications/{notificationId} (test alerts)
16
- ```
17
-
18
- **Example Legacy Paths:**
19
- - `user_notifications/29312236/notifications/test_alert_1767063681211_29312236_1_xx0ey9x`
20
- - `user_notifications/29312236/counters/2025-12-28`
21
- - `user_notifications/GYXUIoWNnNSxJf3o5CeZm1fljlp1/notifications/test_alert_1767063681211_GYXUIoWNnNSxJf3o5CeZm1fljlp1_1_xx0ey9x`
22
-
23
- ### New Paths
24
- ```
25
- SignedInUsers/{cid}/notifications/{notificationId}
26
- SignedInUsers/{cid}/notifications/counters/{date} (if needed)
27
- ```
28
-
29
- **Example New Paths:**
30
- - `SignedInUsers/29312236/notifications/test_alert_1767063681211_29312236_1_xx0ey9x`
31
- - `SignedInUsers/29312236/notifications/counters/2025-12-28`
32
-
33
- **Notes:**
34
- - Always use CID, not Firebase UID
35
- - Use `getCidFromFirebaseUid()` helper when converting from Firebase UID
36
- - Migration: Auto-migrate on read
37
-
38
- ---
39
-
40
- ## 2. User Alerts
41
-
42
- ### Legacy Paths
43
- ```
44
- user_alerts/{userCid}/alerts/{alertId}
45
- user_alerts/{userCid}/counters/{date}
46
- ```
47
-
48
- **Example Legacy Paths:**
49
- - `user_alerts/29312236/alerts/alert_1767063681211_31075566`
50
- - `user_alerts/29312236/counters/2025-12-28`
51
-
52
- ### New Paths
53
- ```
54
- SignedInUsers/{cid}/alerts/{alertId}
55
- SignedInUsers/{cid}/alerts/counters/{date} (if needed)
56
- ```
57
-
58
- **Example New Paths:**
59
- - `SignedInUsers/29312236/alerts/alert_1767063681211_31075566`
60
- - `SignedInUsers/29312236/alerts/counters/2025-12-28`
61
-
62
- **Notes:**
63
- - Alert counters track unread/total counts per day
64
- - Migration: Auto-migrate on read
65
-
66
- ---
67
-
68
- ## 3. Watchlists (Private)
69
-
70
- ### Legacy Paths
71
- ```
72
- watchlists/{userCid}/lists/{watchlistId}
73
- user_watchlists/{userCid}/lists/{watchlistId}
74
- ```
75
-
76
- **Example Legacy Paths:**
77
- - `watchlists/29312236/lists/watchlist_1766797382685_091cca66`
78
- - `user_watchlists/29312236/lists/watchlist_1766797382685_091cca66`
79
-
80
- ### New Paths
81
- ```
82
- SignedInUsers/{cid}/watchlists/{watchlistId}
83
- ```
84
-
85
- **Example New Paths:**
86
- - `SignedInUsers/29312236/watchlists/watchlist_1766797382685_091cca66`
87
-
88
- **Notes:**
89
- - Private watchlists only
90
- - Public watchlists remain in `public_watchlists` collection (no migration needed)
91
- - Migration: Auto-migrate on read
92
-
93
- ---
94
-
95
- ## 4. Watchlist Subscriptions
96
-
97
- ### Legacy Paths
98
- ```
99
- watchlist_subscriptions/{userCid}/alerts/{piCid}
100
- ```
101
-
102
- **Example Legacy Paths:**
103
- - `watchlist_subscriptions/29312236/alerts/31075566`
104
-
105
- ### New Paths
106
- ```
107
- SignedInUsers/{cid}/watchlists/{watchlistId}/subscriptions/{piCid} (per-watchlist)
108
- SignedInUsers/{cid}/subscriptions/{piCid} (global subscriptions)
109
- ```
110
-
111
- **Example New Paths:**
112
- - `SignedInUsers/29312236/watchlists/watchlist_1766797382685_091cca66/subscriptions/31075566`
113
- - `SignedInUsers/29312236/subscriptions/31075566`
114
-
115
- **Notes:**
116
- - Per-watchlist subscriptions: tied to a specific watchlist
117
- - Global subscriptions: not tied to a watchlist
118
- - Migration: Auto-migrate on read
119
-
120
- ---
121
-
122
- ## 5. User Verification
123
-
124
- ### Legacy Paths
125
- ```
126
- user_verifications/{username}
127
- ```
128
-
129
- **Example Legacy Paths:**
130
- - `user_verifications/daniel81991`
131
- - `user_verifications/marau2021`
132
-
133
- ### New Paths
134
- ```
135
- SignedInUsers/{cid}/verification/data
136
- ```
137
-
138
- **Example New Paths:**
139
- - `SignedInUsers/12336860/verification/data`
140
- - `SignedInUsers/29312236/verification/data`
141
-
142
- **Notes:**
143
- - Legacy path uses username (before CID is known)
144
- - New path uses CID (after verification completes)
145
- - Migration: After `finalizeVerification` gets `realCID` from bio check API, migrate to CID-based path
146
- - Firebase UID: Store `firebaseUid` in verification document once Firebase account is created
147
- - Using subcollection with single document named "data" to comply with Firestore even-segment rule (4 segments)
148
-
149
- **Schema Example:**
150
- ```javascript
151
- {
152
- username: "daniel81991",
153
- cid: 12336860,
154
- firebaseUid: "1C2VKLjEqcZKi3NFAFfPsx5Dins1", // Added after account creation
155
- otp: "38K0E1",
156
- status: "VERIFIED",
157
- createdAt: Timestamp,
158
- expiresAt: Timestamp,
159
- verifiedAt: Timestamp,
160
- isOptOut: false
161
- }
162
- ```
163
-
164
- ---
165
-
166
- ## 6. User Sync Requests
167
-
168
- ### Legacy Paths
169
- ```
170
- user_sync_requests/{userCid}/requests/{requestId}
171
- user_sync_requests/{userCid}/global/latest
172
- ```
173
-
174
- **Example Legacy Paths:**
175
- - `user_sync_requests/29312236/requests/sync_1766941189840_801ad9f3`
176
- - `user_sync_requests/29312236/global/latest`
177
-
178
- ### New Paths
179
- ```
180
- SignedInUsers/{cid}/syncRequests/{requestId}
181
- SignedInUsers/{cid}/syncStatus/latest
182
- ```
183
-
184
- **Example New Paths:**
185
- - `SignedInUsers/29312236/syncRequests/sync_1766941189840_801ad9f3`
186
- - `SignedInUsers/29312236/syncStatus/latest`
187
-
188
- **Notes:**
189
- - Sync requests track on-demand data sync history
190
- - Global status tracks latest request metadata
191
- - Migration: Auto-migrate on read
192
-
193
- **Schema Example (Request):**
194
- ```javascript
195
- {
196
- requestId: "sync_1766941189840_801ad9f3",
197
- targetUserCid: 29312236,
198
- requestedBy: 29312236,
199
- effectiveRequestedBy: 29312236,
200
- username: "Marau2021",
201
- userType: "SIGNED_IN_USER",
202
- status: "completed",
203
- createdAt: Timestamp,
204
- dispatchedAt: Timestamp,
205
- completedAt: Timestamp,
206
- updatedAt: Timestamp
207
- }
208
- ```
209
-
210
- ---
211
-
212
- ## 7. Portfolio Data (Latest Snapshot)
213
-
214
- ### Legacy Paths
215
- ```
216
- {signedInUsersCollection}/{blockId}/snapshots/{date}/parts/part_{N}
217
- signed_in_users/{blockId}/snapshots/{date}/parts/part_{N}
218
- ```
219
-
220
- **Example Legacy Paths:**
221
- - `signed_in_users/19M/snapshots/2025-12-26/parts/part_0`
222
- - `signed_in_users/19M/snapshots/2025-12-26/parts/part_1`
223
-
224
- ### Root Data Paths (Task Engine Format - No Migration)
225
- ```
226
- SignedInUserPortfolioData/{date}/{cid}/{cid}
227
- ```
228
-
229
- **Example Root Data Paths:**
230
- - `SignedInUserPortfolioData/2025-12-26/29312236/29312236`
231
-
232
- ### New Paths (Latest Snapshot - Fallback)
233
- ```
234
- SignedInUsers/{cid}/portfolio/latest
235
- ```
236
-
237
- **Example New Paths:**
238
- - `SignedInUsers/29312236/portfolio/latest`
239
-
240
- **Notes:**
241
- - Root data format: `{collection}/{date}/{cid}/{cid}` (document ID is CID)
242
- - Latest snapshot is stored per-user for fallback when computation doesn't exist
243
- - Task engine writes to root data format
244
- - Migration: Auto-migrate on read
245
-
246
- **Schema Example (Latest Snapshot):**
247
- ```javascript
248
- {
249
- AggregatedPositions: [...],
250
- AggregatedMirrors: [...],
251
- fetchedAt: Timestamp,
252
- date: "2025-12-26",
253
- cid: 29312236
254
- }
255
- ```
256
-
257
- ---
258
-
259
- ## 8. Trade History (Latest Snapshot)
260
-
261
- ### Legacy Paths
262
- ```
263
- {signedInHistoryCollection}/{blockId}/snapshots/{date}/parts/part_{N}
264
- ```
265
-
266
- **Example Legacy Paths:**
267
- - `signed_in_user_history/19M/snapshots/2025-12-26/parts/part_0`
268
-
269
- ### Root Data Paths (Task Engine Format - No Migration)
270
- ```
271
- SignedInUserTradeHistoryData/{date}/{cid}/{cid}
272
- ```
273
-
274
- **Example Root Data Paths:**
275
- - `SignedInUserTradeHistoryData/2025-12-26/29312236/29312236`
276
-
277
- ### New Paths (Latest Snapshot - Fallback)
278
- ```
279
- SignedInUsers/{cid}/tradeHistory/latest
280
- ```
281
-
282
- **Example New Paths:**
283
- - `SignedInUsers/29312236/tradeHistory/latest`
284
-
285
- **Notes:**
286
- - Same structure as portfolio data
287
- - Migration: Auto-migrate on read
288
-
289
- ---
290
-
291
- ## 9. Social Posts (Latest Snapshot)
292
-
293
- ### Legacy Paths
294
- ```
295
- signed_in_users_social/{cid}/posts/{postId}
296
- ```
297
-
298
- **Example Legacy Paths:**
299
- - `signed_in_users_social/29312236/posts/00c0f500-f199-11ee-8080-80000769abad`
300
-
301
- ### Root Data Paths (Task Engine Format - No Migration)
302
- ```
303
- SignedInUserSocialPostData/{date}/{cid}/{cid}
304
- ```
305
-
306
- **Example Root Data Paths:**
307
- - `SignedInUserSocialPostData/2025-12-26/29312236/29312236`
308
-
309
- ### New Paths (Latest Snapshot - Fallback)
310
- ```
311
- SignedInUsers/{cid}/posts/{postId}
312
- ```
313
-
314
- **Example New Paths:**
315
- - `SignedInUsers/29312236/posts/00c0f500-f199-11ee-8080-80000769abad`
316
-
317
- **Notes:**
318
- - Task engine can write all posts here as well as root data location
319
- - Migration: Auto-migrate on read
320
-
321
- ---
322
-
323
- ## 10. Popular Investor Fetch Requests
324
-
325
- ### Legacy Paths
326
- ```
327
- pi_fetch_requests/{piCid}/requests/{requestId}
328
- pi_fetch_requests/{piCid}/user_requests/{userCid}
329
- pi_fetch_requests/{piCid}/global/latest
330
- ```
331
-
332
- **Example Legacy Paths:**
333
- - `pi_fetch_requests/31075566/requests/req_1766890969236_4c887876`
334
- - `pi_fetch_requests/31075566/user_requests/647267`
335
- - `pi_fetch_requests/31075566/global/latest`
336
-
337
- ### New Paths
338
- ```
339
- PopularInvestors/{piCid}/fetchRequests/{requestId}
340
- PopularInvestors/{piCid}/userFetchRequests/{userCid}
341
- PopularInvestors/{piCid}/fetchStatus/latest
342
- ```
343
-
344
- **Example New Paths:**
345
- - `PopularInvestors/31075566/fetchRequests/req_1766890969236_4c887876`
346
- - `PopularInvestors/31075566/userFetchRequests/647267`
347
- - `PopularInvestors/31075566/fetchStatus/latest`
348
-
349
- **Notes:**
350
- - PI-centric data (not user-centric)
351
- - Rate limiting tracked per user, per PI
352
- - Migration: Auto-migrate on read
353
-
354
- **Schema Example (Request):**
355
- ```javascript
356
- {
357
- requestId: "req_1766890969236_4c887876",
358
- actualUserCid: 29312236,
359
- createdAt: Timestamp,
360
- isImpersonating: true,
361
- piCid: 31075566,
362
- piUsername: "Gr33nTrader",
363
- status: "queued",
364
- taskMessageId: "17612318165520680",
365
- updatedAt: Timestamp,
366
- userCid: 647267
367
- }
368
- ```
369
-
370
- ---
371
-
372
- ## 11. Popular Investor Reviews
373
-
374
- ### Legacy Paths
375
- ```
376
- pi_reviews/{piCid}_{userCid}
377
- ```
378
-
379
- **Example Legacy Paths:**
380
- - `pi_reviews/29312236_647267`
381
-
382
- ### New Paths
383
- ```
384
- PopularInvestors/{piCid}/reviews/{reviewId}
385
- ```
386
-
387
- **Example New Paths:**
388
- - `PopularInvestors/647267/reviews/29312236_647267`
389
-
390
- **Notes:**
391
- - Review ID format: `{userCid}_{piCid}`
392
- - Migration: Auto-migrate on read
393
-
394
- **Schema Example:**
395
- ```javascript
396
- {
397
- comment: "Test Review",
398
- createdAt: Timestamp,
399
- isAnonymous: false,
400
- piCid: 647267,
401
- rating: 5,
402
- reviewerUsername: "Marau2021",
403
- updatedAt: Timestamp,
404
- userCid: 29312236
405
- }
406
- ```
407
-
408
- ---
409
-
410
- ## 12. Popular Investor Social Posts
411
-
412
- ### Legacy Paths
413
- ```
414
- pi_social_posts/{piCid}/posts/{postId}
415
- ```
416
-
417
- **Example Legacy Paths:**
418
- - `pi_social_posts/10050875/posts/00c0f500-f199-11ee-8080-80000769abad`
419
-
420
- ### New Paths
421
- ```
422
- PopularInvestors/{piCid}/posts/{postId}
423
- ```
424
-
425
- **Example New Paths:**
426
- - `PopularInvestors/10050875/posts/00c0f500-f199-11ee-8080-80000769abad`
427
-
428
- **Notes:**
429
- - PI-centric data
430
- - Migration: Auto-migrate on read
431
-
432
- ---
433
-
434
- ## 13. Profile Views
435
-
436
- ### Legacy Paths
437
- ```
438
- profile_views/{piCid}_{date}
439
- profile_views/individual_views/views/{piCid}_{viewerCid}_{timestamp}
440
- ```
441
-
442
- **Example Legacy Paths:**
443
- - `profile_views/31075566_2025-12-27`
444
- - `profile_views/individual_views/views/31075566_29312236_1766868534621`
445
-
446
- ### New Paths
447
- ```
448
- PopularInvestors/{piCid}/profileViews/{date}
449
- PopularInvestors/{piCid}/views/{viewId}
450
- ```
451
-
452
- **Example New Paths:**
453
- - `PopularInvestors/31075566/profileViews/2025-12-27`
454
- - `PopularInvestors/31075566/views/31075566_29312236_1766868534621`
455
-
456
- **Notes:**
457
- - Profile views tracked by date (aggregated)
458
- - Individual views tracked per view event
459
- - Migration: Auto-migrate on read
460
-
461
- **Schema Example (Aggregated):**
462
- ```javascript
463
- {
464
- date: "2025-12-27",
465
- lastUpdated: Timestamp,
466
- piCid: 31075566,
467
- totalViews: 2,
468
- uniqueViewers: ["29312236"]
469
- }
470
- ```
471
-
472
- **Schema Example (Individual):**
473
- ```javascript
474
- {
475
- date: "2025-12-27",
476
- piCid: 31075566,
477
- viewedAt: Timestamp,
478
- viewerCid: 29312236,
479
- viewerType: "signed_in"
480
- }
481
- ```
482
-
483
- ---
484
-
485
- ## 14. Public Watchlists (No Migration - Already Correct)
486
-
487
- ### Current Paths (Unchanged)
488
- ```
489
- public_watchlists/{watchlistId}
490
- public_watchlists/{watchlistId}/versions/{version}
491
- ```
492
-
493
- **Example Paths:**
494
- - `public_watchlists/watchlist_1766966023323_17e982f0`
495
- - `public_watchlists/watchlist_1766966023323_17e982f0/versions/1`
496
-
497
- **Notes:**
498
- - Public watchlists are system-wide, not user-centric
499
- - No migration needed
500
-
501
- **Schema Example (Version):**
502
- ```javascript
503
- {
504
- copyCount: 0,
505
- createdAt: Timestamp,
506
- createdBy: 29312236,
507
- description: "",
508
- dynamicConfig: {
509
- alertConfig: {...},
510
- computationName: "RiskScoreIncrease",
511
- parameters: {...}
512
- },
513
- isImmutable: true,
514
- name: "testing",
515
- snapshotAt: Timestamp,
516
- type: "dynamic",
517
- version: 1,
518
- watchlistId: "watchlist_1766966023323_17e982f0"
519
- }
520
- ```
521
-
522
- ---
523
-
524
- ## 15. System Collections (No Migration Needed)
525
-
526
- ### Firebase Auth Mapping
527
- ```
528
- signedInUsers/{firebaseUid}
529
- ```
530
-
531
- **Example Paths:**
532
- - `signedInUsers/1C2VKLjEqcZKi3NFAFfPsx5Dins1`
533
-
534
- **Notes:**
535
- - **ONLY for Firebase Auth UID → eToro CID mapping**
536
- - All user data should use CID-based paths
537
- - No migration needed
538
-
539
- **Schema Example:**
540
- ```javascript
541
- {
542
- accountSetupComplete: true,
543
- createdAt: Timestamp,
544
- displayName: "Daniel Allison",
545
- email: "daniel.allison@y7mail.com",
546
- etoroCID: 12336860,
547
- etoroUsername: "daniel81991",
548
- photoURL: "https://...",
549
- setupCompletedAt: Timestamp,
550
- verifiedAt: Timestamp
551
- }
552
- ```
553
-
554
- ### User GCID Mappings
555
- ```
556
- user_gcid_mappings/{cid}
557
- ```
558
-
559
- **Example Paths:**
560
- - `user_gcid_mappings/10050875`
561
-
562
- **Notes:**
563
- - Maps eToro CID to GCID (social ID)
564
- - Used for social post context where eToro uses GCID instead of CID
565
- - No migration needed
566
-
567
- **Schema Example:**
568
- ```javascript
569
- {
570
- gcid: 10337657,
571
- updatedAt: Timestamp,
572
- username: "Rafnus"
573
- }
574
- ```
575
-
576
- ---
577
-
578
- ## 16. Root Data Collections (No Migration - Task Engine Format)
579
-
580
- ### Signed-In User Root Data
581
- ```
582
- SignedInUserPortfolioData/{date}/{cid}/{cid}
583
- SignedInUserTradeHistoryData/{date}/{cid}/{cid}
584
- SignedInUserSocialPostData/{date}/{cid}/{cid}
585
- ```
586
-
587
- **Example Paths:**
588
- - `SignedInUserPortfolioData/2025-12-26/29312236/29312236`
589
- - `SignedInUserTradeHistoryData/2025-12-26/29312236/29312236`
590
- - `SignedInUserSocialPostData/2025-12-26/29312236/29312236`
591
-
592
- **Notes:**
593
- - Document ID is the CID (task engine format)
594
- - Populated by task engine, price fetcher, insights fetcher
595
- - No migration needed - this is the correct format
596
-
597
- ### Popular Investor Root Data
598
- ```
599
- PopularInvestorPortfolioData/{date}/{cid}
600
- PopularInvestorTradeHistoryData/{date}/{cid}
601
- PopularInvestorSocialPostData/{date}/{cid}
602
- ```
603
-
604
- **Example Paths:**
605
- - `PopularInvestorPortfolioData/2025-12-26/10050875`
606
- - `PopularInvestorTradeHistoryData/2025-12-26/10050875`
607
- - `PopularInvestorSocialPostData/2025-12-26/10050875`
608
-
609
- **Notes:**
610
- - Document ID is the CID
611
- - Populated by task engine
612
- - No migration needed
613
-
614
- ### Instrument Social Data
615
- ```
616
- InstrumentFeedSocialPostData/{date}
617
- ```
618
-
619
- **Example Paths:**
620
- - `InstrumentFeedSocialPostData/2025-12-26`
621
-
622
- **Notes:**
623
- - Instrument-specific social posts
624
- - No migration needed
625
-
626
- ---
627
-
628
- ## 17. Computation Results (No Migration Needed)
629
-
630
- ### Computation Results
631
- ```
632
- unified_insights/{date}/results/{category}/computations/{computationName}
633
- unified_insights/{date}/results/{category}/computations/{computationName}/_shards/{shardId}
634
- ```
635
-
636
- **Example Paths:**
637
- - `unified_insights/2025-12-26/results/popular-investor/computations/PopularInvestorProfileMetrics`
638
- - `unified_insights/2025-12-26/results/popular-investor/computations/PopularInvestorProfileMetrics/_shards/shard_0`
639
-
640
- **Notes:**
641
- - May be sharded for large datasets
642
- - No migration needed
643
-
644
- ---
645
-
646
- ## 18. Rankings (No Migration Needed)
647
-
648
- ### Popular Investor Rankings
649
- ```
650
- popular_investor_rankings/{date}
651
- ```
652
-
653
- **Example Paths:**
654
- - `popular_investor_rankings/2025-12-26`
655
-
656
- **Notes:**
657
- - Daily rankings from eToro API
658
- - No migration needed
659
-
660
- ---
661
-
662
- ## Migration Strategy Summary
663
-
664
- ### Auto-Migration on Read
665
- 1. **Try new path first** - Attempt to read from new CID-based path
666
- 2. **Fallback to legacy** - If not found, try legacy path
667
- 3. **Auto-migrate** - If found in legacy path, automatically migrate to new path
668
- 4. **Return data** - Return data from new path (or legacy if migration failed)
669
-
670
- ### Dual-Write (During Transition)
671
- - Write to both new and legacy paths during transition period
672
- - Ensures consistency and facilitates migration
673
-
674
- ### Path Resolution
675
- - Use `readWithMigration()` helper from `core/path_resolution_helpers.js`
676
- - Use `writeWithMigration()` helper for dual-write during transition
677
- - All paths defined in `collection_registry.js` with legacy mappings
678
-
679
- ---
680
-
681
- ## Key Principles
682
-
683
- 1. **Always use CID** - All user-centric data uses `{cid}`, not `{firebaseUid}`
684
- 2. **Root data format** - Task engine writes to `{collection}/{date}/{cid}/{cid}` (document ID is CID)
685
- 3. **Firebase UID mapping** - `signedInUsers/{firebaseUid}` is ONLY for UID→CID lookup
686
- 4. **Even segments** - All paths must have even number of segments (collection/document/collection/document)
687
- 5. **Auto-migration** - Migrate on read, no batch migration needed initially
688
-
689
- ---
690
-
691
- ## Path Segment Validation
692
-
693
- All user-centric paths follow this structure:
694
- - **Collection** (1)
695
- - **Document** (2) - User CID
696
- - **Collection** (3) - Data type (notifications, alerts, watchlists, etc.)
697
- - **Document** (4) - Specific item ID
698
-
699
- Example: `SignedInUsers/29312236/notifications/notification_123` (4 segments ✅)
700
-
701
- ---
702
-
703
- ## Notes
704
-
705
- - **Legacy paths** are still supported during migration period
706
- - **New paths** are the target format for all new data
707
- - **Root data** collections remain in task engine format (no migration)
708
- - **Public collections** (watchlists, rankings) remain unchanged
709
- - **System collections** (mappings, configs) remain unchanged
710
-