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,116 +0,0 @@
1
- # Complete Refactoring Plan
2
-
3
- ## Overview
4
- This document outlines the complete refactoring of `data_helpers.js` (2550 lines) into organized, modular helper files with full migration support.
5
-
6
- ## Function Mapping
7
-
8
- ### ✅ Already Migrated
9
- - `getUserPortfolio` → `data/portfolio_helpers.js`
10
- - `getUserDataStatus` → `data/portfolio_helpers.js`
11
- - `getUserSocialPosts` → `data/social_helpers.js`
12
- - `getUserComputations` → `data/computation_helpers.js`
13
- - `checkPiInComputationDate` → `data/computation_helpers.js`
14
- - `getInstrumentMappings` → `data/instrument_helpers.js`
15
- - Core utilities → `core/` directory
16
-
17
- ### 🔄 To Be Migrated
18
-
19
- #### Profile Helpers (`profile/`)
20
- 1. **`profile/pi_profile_helpers.js`**
21
- - `getPiProfile` - PI profile endpoint
22
- - `getPiAnalytics` - PI analytics endpoint
23
-
24
- 2. **`profile/user_profile_helpers.js`**
25
- - `getUserVerification` - User verification endpoint (needs migration to use `SignedInUsers/{cid}/verification`)
26
- - `checkIfUserIsPopularInvestor` - Check if user is PI
27
-
28
- 3. **`profile/profile_view_helpers.js`**
29
- - `trackProfileView` - Profile view tracking (needs migration to use `PopularInvestors/{piCid}/profileViews` and `PopularInvestors/{piCid}/views`)
30
-
31
- #### Watchlist Helpers (`watchlist/`)
32
- 4. **`watchlist/watchlist_data_helpers.js`** (Legacy)
33
- - `getWatchlist` - Legacy single watchlist endpoint
34
- - `updateWatchlist` - Legacy single watchlist endpoint
35
-
36
- 5. **`watchlist/watchlist_generation_helpers.js`**
37
- - `autoGenerateWatchlist` - Auto-generate watchlist from copied PIs
38
-
39
- 6. **`watchlist/watchlist_analytics_helpers.js`**
40
- - `getWatchlistTriggerCounts` - Watchlist analytics
41
-
42
- #### Search & Recommendations (`search/`, `recommendations/`)
43
- 7. **`search/pi_search_helpers.js`**
44
- - `searchPopularInvestors` - PI search endpoint
45
-
46
- 8. **`search/pi_request_helpers.js`**
47
- - `requestPiAddition` - Request PI addition
48
- - `checkPisInRankings` - Check PIs in rankings
49
-
50
- 9. **`recommendations/recommendation_helpers.js`**
51
- - `getUserRecommendations` - User recommendations (hedges/similar)
52
-
53
- #### Metrics (`metrics/`)
54
- 10. **`metrics/personalized_metrics_helpers.js`**
55
- - `getSignedInUserPIPersonalizedMetrics` - Personalized metrics endpoint
56
- - `generateSamplePIPersonalizedMetrics` - Sample data generator (internal)
57
-
58
- ## Legacy Path Mappings
59
-
60
- ### Signed-In User Data
61
- | New Path | Legacy Path | Migration Type |
62
- |----------|------------|----------------|
63
- | `SignedInUsers/{cid}/notifications` | `user_notifications/{firebaseUid}/notifications` | Auto-migrate on read |
64
- | `SignedInUsers/{cid}/watchlists` | `user_watchlists/{cid}/lists` | Auto-migrate on read |
65
- | `SignedInUsers/{cid}/verification/data` | `user_verifications/{username}` | Auto-migrate on read |
66
- | `SignedInUsers/{cid}/syncRequests` | `user_sync_requests/{cid}/requests` | Auto-migrate on read |
67
- | `SignedInUsers/{cid}/syncStatus/latest` | `user_sync_requests/{cid}/global/latest` | Auto-migrate on read |
68
- | `SignedInUsers/{cid}/portfolio/latest` | `{signedInUsersCollection}/19M/snapshots/{date}/parts` | Read from root data, write to user-centric |
69
- | `SignedInUsers/{cid}/posts` | `signed_in_users_social/{cid}/posts` | Auto-migrate on read |
70
-
71
- ### Popular Investor Data
72
- | New Path | Legacy Path | Migration Type |
73
- |----------|------------|----------------|
74
- | `PopularInvestors/{piCid}/fetchRequests/{requestId}` | `pi_fetch_requests/{piCid}/requests/{requestId}` | Auto-migrate on read |
75
- | `PopularInvestors/{piCid}/fetchStatus/latest` | `pi_fetch_requests/{piCid}/global/latest` | Auto-migrate on read |
76
- | `PopularInvestors/{piCid}/userFetchRequests/{userCid}` | `pi_fetch_requests/{piCid}/user_requests/{userCid}` | Auto-migrate on read |
77
- | `PopularInvestors/{piCid}/reviews/{reviewId}` | `pi_reviews/{piCid}_{userCid}` | Auto-migrate on read |
78
- | `PopularInvestors/{piCid}/posts/{postId}` | `pi_social_posts/{piCid}/posts/{postId}` | Auto-migrate on read |
79
- | `PopularInvestors/{piCid}/profileViews/{date}` | `profile_views/{piCid}_{date}` | Auto-migrate on read |
80
- | `PopularInvestors/{piCid}/views/{viewId}` | `profile_views/individual_views/views/{piCid}_{viewerCid}_{timestamp}` | Auto-migrate on read |
81
-
82
- ### Root Data (No Migration - Task Engine Writes Here)
83
- - `SignedInUserPortfolioData/{date}/{cid}`
84
- - `SignedInUserTradeHistoryData/{date}/{cid}`
85
- - `SignedInUserSocialPostData/{date}/{cid}`
86
- - `PopularInvestorPortfolioData/{date}/{cid}`
87
- - `PopularInvestorTradeHistoryData/{date}/{cid}`
88
- - `PopularInvestorSocialPostData/{date}/{cid}`
89
-
90
- ## Implementation Steps
91
-
92
- 1. ✅ Update `path_resolution_helpers.js` with all legacy path mappings
93
- 2. ✅ Update `collection_registry.js` with correct new paths
94
- 3. ⏳ Create profile helper files
95
- 4. ⏳ Create watchlist helper files
96
- 5. ⏳ Create search/recommendations helper files
97
- 6. ⏳ Create metrics helper files
98
- 7. ⏳ Update all functions to use `readWithMigration` and `writeWithMigration`
99
- 8. ⏳ Update `data_helpers.js` to only re-export
100
- 9. ⏳ Test all endpoints
101
-
102
- ## Migration Strategy
103
-
104
- All functions should:
105
- 1. Use `readWithMigration()` to read data (tries new path, falls back to legacy, auto-migrates)
106
- 2. Use `writeWithMigration()` to write data (writes to both paths during transition)
107
- 3. Use `getNewPath()` from registry for new paths
108
- 4. Use `getLegacyPath()` for legacy path resolution
109
-
110
- ## Notes
111
-
112
- - Root data collections remain unchanged (populated by task engines)
113
- - Public watchlists remain in `public_watchlists` (not user-centric)
114
- - System collections like `user_gcid_mappings` remain unchanged
115
- - Firebase UID → CID mapping stays in `signedInUsers/{firebaseUid}` main document
116
-
@@ -1,171 +0,0 @@
1
- # Firestore Paths Inventory - User API
2
-
3
- ## Complete List of All Firestore Paths Used in User-API
4
-
5
- ### User-Centric Data (To Be Migrated)
6
-
7
- #### 1. Notifications
8
- - **Legacy:** `user_notifications/{userCid}/notifications/{notificationId}`
9
- - **Legacy:** `user_notifications/{userCid}/counters/{date}`
10
- - **Legacy:** `user_notifications/{firebaseUid}/notifications/{notificationId}` (test_alert_helpers - needs CID conversion)
11
- - **New (CID-only):** `SignedInUsers/{cid}/notifications/{notificationId}`
12
- - **New (CID-only):** `SignedInUsers/{cid}/notifications/counters/{date}` (if needed)
13
-
14
- #### 2. Alerts
15
- - **Legacy:** `user_alerts/{userCid}/alerts/{alertId}`
16
- - **Legacy:** `user_alerts/{userCid}/counters/{date}`
17
- - **New:** `SignedInUsers/{cid}/alerts/{alertId}`
18
- - **New:** `SignedInUsers/{cid}/alerts/counters/{date}` (if needed)
19
-
20
- #### 3. Watchlists (Private)
21
- - **Legacy:** `watchlists/{userCid}/lists/{watchlistId}`
22
- - **New:** `SignedInUsers/{cid}/watchlists/{watchlistId}`
23
-
24
- #### 4. Watchlist Subscriptions
25
- - **Legacy:** `watchlist_subscriptions/{userCid}/alerts/{piCid}`
26
- - **New (per-watchlist):** `SignedInUsers/{cid}/watchlists/{watchlistId}/subscriptions/{piCid}`
27
- - **New (global):** `SignedInUsers/{cid}/subscriptions/{piCid}`
28
-
29
- #### 5. Verification
30
- - **Legacy (pending):** `{verificationsCollection}/{username}` (before CID is known, 2 segments)
31
- - **New (CID-based):** `SignedInUsers/{cid}/verification/data` (4 segments: collection/document/collection/document)
32
- - **Migration:** After `finalizeVerification` gets `realCID` from bio check API, migrate to CID-based path
33
- - **Firebase UID:** Store `firebaseUid` in verification document once Firebase account is created
34
- - **Note:** Using subcollection with single document named "data" to comply with Firestore even-segment rule
35
-
36
- #### 6. User Sync Requests
37
- - **Legacy:** `user_sync_requests/{userCid}/requests/{requestId}`
38
- - **Legacy:** `user_sync_requests/{userCid}/global/latest`
39
- - **New:** `SignedInUsers/{cid}/syncRequests/{requestId}`
40
- - **New:** `SignedInUsers/{cid}/syncStatus/latest`
41
-
42
- #### 7. Portfolio Data (Latest Snapshot)
43
- - **Legacy:** `{signedInUsersCollection}/{blockId}/snapshots/{date}/parts/part_{N}`
44
- - **Root Data:** `SignedInUserPortfolioData/{date}/{cid}/{cid}` (4 segments - task engine format, document ID is CID)
45
- - **New (CID-only):** `SignedInUsers/{cid}/portfolio/latest` (4 segments: collection/document/collection/document)
46
-
47
- #### 8. Trade History (Latest Snapshot)
48
- - **Legacy:** `{signedInHistoryCollection}/{blockId}/snapshots/{date}/parts/part_{N}`
49
- - **Root Data:** `SignedInUserTradeHistoryData/{date}/{cid}/{cid}` (4 segments - task engine format, document ID is CID)
50
- - **New (CID-only):** `SignedInUsers/{cid}/tradeHistory/latest` (4 segments: collection/document/collection/document)
51
-
52
- #### 9. Social Posts (Latest Snapshot)
53
- - **Legacy:** `signed_in_users_social/{cid}/posts/{postId}` (4 segments)
54
- - **Root Data:** `SignedInUserSocialPostData/{date}/{cid}/{cid}` (4 segments - task engine format, document ID is CID)
55
- - **New (CID-only):** `SignedInUsers/{cid}/posts/{postId}` (4 segments: collection/document/collection/document)
56
-
57
- #### 10. Signed-In User Main Document
58
- - **Firebase Auth Mapping:** `signedInUsers/{firebaseUid}` (unchanged - ONLY for UID→CID lookup)
59
- - **Legacy:** `{signedInUsersCollection}/{cid}`
60
- - **Legacy:** `signed_in_users/{cid}`
61
-
62
- **Note:** `signedInUsers/{firebaseUid}` is ONLY for Firebase Auth UID → eToro CID mapping. All user data should use CID-based paths.
63
-
64
- ### Public/System Collections (No Migration Needed)
65
-
66
- #### 11. Public Watchlists
67
- - `public_watchlists/{watchlistId}` (unchanged)
68
- - `public_watchlists/{watchlistId}/versions/{version}` (unchanged)
69
-
70
- #### 12. PI Fetch Requests (PI-Centric, Not User-Centric)
71
- - `pi_fetch_requests/{piCid}/requests/{requestId}` (unchanged - PI-specific)
72
- - `pi_fetch_requests/{piCid}/user_requests/{userCid}` (unchanged - rate limiting)
73
- - `pi_fetch_requests/{piCid}/global/latest` (unchanged - PI-specific)
74
-
75
- #### 13. Reviews (PI-Centric, Not User-Centric)
76
- - `{reviewsCollection}/{reviewId}` (unchanged - reviews of PIs)
77
- - Should be: `popularInvestors/{piCid}/reviews/{reviewId}` (per registry)
78
-
79
- #### 14. Dev Overrides (System Configuration)
80
- - `dev_overrides/{etoroCid}` (unchanged - system-level)
81
-
82
- #### 15. Computation Results (Read-Only, Date-Based)
83
- - `unified_insights/{date}/results/{category}/computations/{computationName}`
84
- - `unified_insights/{date}/results/{category}/computations/{computationName}/_shards/{shardId}`
85
-
86
- #### 16. Rankings Data (Read-Only, Date-Based)
87
- - `popular_investor_rankings/{date}`
88
-
89
- ## Summary by Migration Priority
90
-
91
- ### High Priority (User Actions/Creations)
92
- 1. ✅ Notifications - User receives notifications
93
- 2. ✅ Alerts - User receives alerts
94
- 3. ✅ Watchlists - User creates watchlists
95
- 4. ✅ Subscriptions - User subscribes to alerts
96
- 5. ✅ Verification - User verification data
97
- 6. ✅ Sync Requests - User requests syncs
98
-
99
- ### Medium Priority (User Data Snapshots)
100
- 7. ✅ Portfolio (latest) - Fallback data for profile pages
101
- 8. ✅ Trade History (latest) - Fallback data for profile pages
102
- 9. ✅ Social Posts (latest) - Fallback data for profile pages
103
-
104
- ### Low Priority (System/Public Data)
105
- 10. ⚠️ Public Watchlists - Public data, not user-centric
106
- 11. ⚠️ PI Fetch Requests - PI-centric, not user-centric
107
- 12. ⚠️ Reviews - PI-centric, not user-centric
108
- 13. ⚠️ Dev Overrides - System configuration
109
- 14. ⚠️ Computation Results - Date-based, not user-centric
110
- 15. ⚠️ Rankings - Date-based, not user-centric
111
-
112
- ## Files That Need Updates
113
-
114
- ### High Priority Files
115
- 1. `helpers/notification_helpers.js` - Notifications
116
- 2. `helpers/alert_helpers.js` - Alerts
117
- 3. `helpers/watchlist_helpers.js` - Watchlists
118
- 4. `helpers/subscription_helpers.js` - Subscriptions
119
- 5. `helpers/verification_helpers.js` - Verification
120
- 6. `helpers/user_sync_helpers.js` - Sync Requests
121
- 7. `helpers/data_helpers.js` - Portfolio, History, Social Posts
122
-
123
- ### Medium Priority Files
124
- 8. `helpers/collection_helpers.js` - Path resolution helpers
125
- 9. `helpers/test_alert_helpers.js` - Test notifications
126
-
127
- ### Low Priority Files (No Changes Needed)
128
- 10. `helpers/on_demand_fetch_helpers.js` - PI fetch (PI-centric)
129
- 11. `helpers/review_helpers.js` - Reviews (PI-centric)
130
- 12. `helpers/dev_helpers.js` - Dev overrides (system-level)
131
-
132
- ## Path Resolution Notes
133
-
134
- ### CID vs Firebase UID
135
- - **Always use CID** for user data paths (`SignedInUsers/{cid}/...`)
136
- - **Firebase UID** is ONLY used in `signedInUsers/{firebaseUid}` for UID→CID mapping
137
- - **Helper function:** `getCidFromFirebaseUid()` - already exists in `collection_helpers.js`
138
- - **Migration requirement:** Convert Firebase UID to CID before accessing user data
139
-
140
- ### Collection Name Variations
141
- - `signedInUsers` vs `SignedInUsers` - case sensitivity matters
142
- - `signed_in_users` vs `signedInUsers` - legacy variations
143
- - Config collections: `{signedInUsersCollection}`, `{verificationsCollection}`, etc.
144
-
145
- ### Block ID Pattern (Legacy)
146
- - Legacy portfolio/history uses: `{collection}/{blockId}/snapshots/{date}/parts/part_{N}`
147
- - Block ID is typically `'19M'` (CANARY_BLOCK_ID)
148
- - New format eliminates block ID structure
149
-
150
- ## Migration Checklist
151
-
152
- - [ ] Create `helpers/path_mapping.js` with path resolution logic
153
- - [ ] Create `helpers/migration_helpers.js` with auto-migration functions
154
- - [ ] Update `collection_registry.js` with migration metadata
155
- - [ ] Update `helpers/notification_helpers.js`
156
- - [ ] Update `helpers/alert_helpers.js`
157
- - [ ] Update `helpers/watchlist_helpers.js`
158
- - [ ] Update `helpers/subscription_helpers.js`
159
- - [ ] Update `helpers/verification_helpers.js`
160
- - [ ] Update `helpers/user_sync_helpers.js`
161
- - [ ] Update `helpers/data_helpers.js` (portfolio, history, social)
162
- - [ ] Update `helpers/collection_helpers.js` (enhance existing helpers)
163
- - [ ] Update `helpers/test_alert_helpers.js`
164
- - [ ] Test dual read/write functionality
165
- - [ ] Test auto-migration on read
166
- - [ ] Test legacy fallback
167
- - [ ] Deploy with feature flag
168
- - [ ] Monitor migration progress
169
- - [ ] Remove legacy read fallback (after all users migrated)
170
- - [ ] Stop dual writes (after verification period)
171
-