bulltrackers-module 1.0.591 → 1.0.593
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.
- package/functions/alert-system/helpers/alert_helpers.js +6 -6
- package/functions/alert-system/index.js +1 -1
- package/functions/api-v2/helpers/data-fetchers/firestore.js +2218 -0
- package/functions/api-v2/helpers/task_engine_helper.js +51 -0
- package/functions/api-v2/index.js +36 -0
- package/functions/api-v2/middleware/identity_middleware.js +48 -0
- package/functions/api-v2/package.json +6 -0
- package/functions/api-v2/routes/alerts.js +168 -0
- package/functions/api-v2/routes/index.js +35 -0
- package/functions/api-v2/routes/notifications.js +38 -0
- package/functions/api-v2/routes/popular_investors.js +204 -0
- package/functions/api-v2/routes/profile.js +212 -0
- package/functions/api-v2/routes/reviews.js +72 -0
- package/functions/api-v2/routes/settings.js +71 -0
- package/functions/api-v2/routes/sync.js +132 -0
- package/functions/api-v2/routes/verification.js +47 -0
- package/functions/api-v2/routes/watchlists.js +148 -0
- package/functions/computation-system/helpers/computation_worker.js +1 -1
- package/functions/task-engine/helpers/popular_investor_helpers.js +2 -2
- package/index.js +6 -2
- package/package.json +3 -2
- package/functions/generic-api/user-api/ADDING_LEGACY_ROUTES_GUIDE.md +0 -345
- package/functions/generic-api/user-api/CODE_REORGANIZATION_PLAN.md +0 -320
- package/functions/generic-api/user-api/COMPLETE_REFACTORING_PLAN.md +0 -116
- package/functions/generic-api/user-api/FIRESTORE_PATHS_INVENTORY.md +0 -171
- package/functions/generic-api/user-api/FIRESTORE_PATH_MIGRATION_REFERENCE.md +0 -710
- package/functions/generic-api/user-api/FIRESTORE_PATH_VALIDATION.md +0 -109
- package/functions/generic-api/user-api/MIGRATION_PLAN.md +0 -499
- package/functions/generic-api/user-api/README_MIGRATION.md +0 -152
- package/functions/generic-api/user-api/REFACTORING_COMPLETE.md +0 -106
- package/functions/generic-api/user-api/REFACTORING_STATUS.md +0 -85
- package/functions/generic-api/user-api/VERIFICATION_MIGRATION_NOTES.md +0 -206
- package/functions/generic-api/user-api/helpers/ORGANIZATION_COMPLETE.md +0 -126
- /package/functions/{generic-api → old-generic-api}/admin-api/index.js +0 -0
- /package/functions/{generic-api → old-generic-api}/helpers/api_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/index.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/alerts/alert_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/alerts/subscription_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/alerts/test_alert_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/collection_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/core/compression_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/core/data_lookup_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/core/path_resolution_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/core/user_status_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/data/computation_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/data/instrument_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/data/portfolio_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/data/social_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/data_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/dev/dev_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/fetch/on_demand_fetch_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/metrics/personalized_metrics_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/notifications/notification_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/profile/pi_profile_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/profile/profile_view_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/profile/user_profile_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/recommendations/recommendation_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/reviews/review_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/rootdata/rootdata_aggregation_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/search/pi_request_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/search/pi_search_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/sync/user_sync_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/verification/verification_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/watchlist/watchlist_analytics_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/watchlist/watchlist_data_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/watchlist/watchlist_generation_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/helpers/watchlist/watchlist_management_helpers.js +0 -0
- /package/functions/{generic-api → old-generic-api}/user-api/index.js +0 -0
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# User API Migration & Reorganization Summary
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
This directory contains plans for:
|
|
6
|
-
1. **Firestore Migration**: Restructuring user-centric data to use CID-based paths under `SignedInUsers/{cid}/...`
|
|
7
|
-
2. **Code Reorganization**: Breaking down the 2573-line `data_helpers.js` into modular, maintainable files
|
|
8
|
-
|
|
9
|
-
## Documents
|
|
10
|
-
|
|
11
|
-
### 1. MIGRATION_PLAN.md
|
|
12
|
-
**Purpose:** Complete migration strategy for Firestore paths
|
|
13
|
-
**Key Points:**
|
|
14
|
-
- Always use CID (not Firebase UID) for user data paths
|
|
15
|
-
- Root data format: `{collection}/{date}/{cid}/{cid}` (document ID is CID)
|
|
16
|
-
- Auto-migration on read: Try new format first, fallback to legacy, auto-migrate if found
|
|
17
|
-
- 9 user-centric data types to migrate
|
|
18
|
-
|
|
19
|
-
### 2. FIRESTORE_PATHS_INVENTORY.md
|
|
20
|
-
**Purpose:** Quick reference of all Firestore paths
|
|
21
|
-
**Key Points:**
|
|
22
|
-
- Complete list of legacy and new paths
|
|
23
|
-
- Organized by migration priority
|
|
24
|
-
- Files that need updates
|
|
25
|
-
- Migration checklist
|
|
26
|
-
|
|
27
|
-
### 3. CODE_REORGANIZATION_PLAN.md
|
|
28
|
-
**Purpose:** Plan to reorganize messy code structure
|
|
29
|
-
**Key Points:**
|
|
30
|
-
- Break down 2573-line `data_helpers.js` (29 functions) into 18 focused files
|
|
31
|
-
- Create core utilities for shared functionality
|
|
32
|
-
- Organize by feature domain (data, profile, watchlist, etc.)
|
|
33
|
-
- Maintain backward compatibility during migration
|
|
34
|
-
|
|
35
|
-
## Key Decisions
|
|
36
|
-
|
|
37
|
-
### Firestore Paths
|
|
38
|
-
✅ **Always use CID** - All user data paths use `{cid}`, not `{firebaseUid}`
|
|
39
|
-
✅ **Root data format** - Task engine writes to `{collection}/{date}/{cid}/{cid}` (document ID is CID)
|
|
40
|
-
✅ **Auto-migration** - Migrate on read, no batch migration needed initially
|
|
41
|
-
✅ **Firebase UID mapping** - `signedInUsers/{firebaseUid}` is ONLY for UID→CID lookup
|
|
42
|
-
|
|
43
|
-
### Code Organization
|
|
44
|
-
✅ **Modular structure** - Split large files into focused, single-responsibility modules
|
|
45
|
-
✅ **Core utilities** - Shared functionality in `helpers/core/`
|
|
46
|
-
✅ **Feature domains** - Organize by feature (data, profile, watchlist, etc.)
|
|
47
|
-
✅ **Backward compatibility** - Re-export from new locations to avoid breaking changes
|
|
48
|
-
|
|
49
|
-
## Migration Priority
|
|
50
|
-
|
|
51
|
-
### High Priority (User Actions/Creations)
|
|
52
|
-
1. Notifications → `SignedInUsers/{cid}/notifications`
|
|
53
|
-
2. Alerts → `SignedInUsers/{cid}/alerts`
|
|
54
|
-
3. Watchlists → `SignedInUsers/{cid}/watchlists`
|
|
55
|
-
4. Subscriptions → `SignedInUsers/{cid}/subscriptions`
|
|
56
|
-
5. Verification → `SignedInUsers/{cid}/verification/data` (4 segments)
|
|
57
|
-
6. Sync Requests → `SignedInUsers/{cid}/syncRequests`
|
|
58
|
-
|
|
59
|
-
### Medium Priority (User Data Snapshots)
|
|
60
|
-
7. Portfolio (latest) → `SignedInUsers/{cid}/portfolio/latest`
|
|
61
|
-
8. Trade History (latest) → `SignedInUsers/{cid}/tradeHistory/latest`
|
|
62
|
-
9. Social Posts (latest) → `SignedInUsers/{cid}/posts`
|
|
63
|
-
|
|
64
|
-
## Implementation Order
|
|
65
|
-
|
|
66
|
-
### Phase 1: Core Infrastructure
|
|
67
|
-
1. Create `helpers/core/path_resolution_helpers.js` with migration support
|
|
68
|
-
2. Create `helpers/core/data_lookup_helpers.js` with CID-based lookups
|
|
69
|
-
3. Create `helpers/core/compression_helpers.js` for decompression
|
|
70
|
-
4. Create `helpers/core/user_status_helpers.js` for user checks
|
|
71
|
-
|
|
72
|
-
### Phase 2: Data Helpers
|
|
73
|
-
1. Create `helpers/data/portfolio_helpers.js`
|
|
74
|
-
2. Create `helpers/data/social_helpers.js`
|
|
75
|
-
3. Create `helpers/data/computation_helpers.js`
|
|
76
|
-
4. Create `helpers/data/instrument_helpers.js`
|
|
77
|
-
|
|
78
|
-
### Phase 3: Profile & Feature Helpers
|
|
79
|
-
1. Create `helpers/profile/` directory with PI and user profile helpers
|
|
80
|
-
2. Create `helpers/watchlist/` directory with watchlist-specific helpers
|
|
81
|
-
3. Create `helpers/search/` directory with PI search helpers
|
|
82
|
-
4. Create `helpers/metrics/` directory with personalized metrics helpers
|
|
83
|
-
|
|
84
|
-
### Phase 4: Update Existing Helpers
|
|
85
|
-
1. Update `notification_helpers.js` to use CID-based paths
|
|
86
|
-
2. Update `alert_helpers.js` to use CID-based paths
|
|
87
|
-
3. Update `watchlist_helpers.js` to use CID-based paths
|
|
88
|
-
4. Update `subscription_helpers.js` to use CID-based paths
|
|
89
|
-
5. Update `verification_helpers.js` to use CID-based paths
|
|
90
|
-
6. Update `user_sync_helpers.js` to use CID-based paths
|
|
91
|
-
|
|
92
|
-
### Phase 5: Migration & Testing
|
|
93
|
-
1. Implement auto-migration on read
|
|
94
|
-
2. Test all endpoints with both legacy and new formats
|
|
95
|
-
3. Monitor migration progress
|
|
96
|
-
4. Remove legacy read fallback after all users migrated
|
|
97
|
-
|
|
98
|
-
## Root Data Format Reference
|
|
99
|
-
|
|
100
|
-
The task engine writes to these formats (DO NOT CHANGE):
|
|
101
|
-
|
|
102
|
-
- **Portfolio:** `SignedInUserPortfolioData/{date}/{cid}/{cid}` (document ID is CID)
|
|
103
|
-
- **Trade History:** `SignedInUserTradeHistoryData/{date}/{cid}/{cid}` (document ID is CID)
|
|
104
|
-
- **Social Posts:** `SignedInUserSocialPostData/{date}/{cid}/{cid}` (document ID is CID)
|
|
105
|
-
|
|
106
|
-
The API should read from these exact formats when querying root data.
|
|
107
|
-
|
|
108
|
-
## Helper Functions
|
|
109
|
-
|
|
110
|
-
### CID Resolution
|
|
111
|
-
```javascript
|
|
112
|
-
const { getCidFromFirebaseUid } = require('./helpers/collection_helpers');
|
|
113
|
-
const cid = await getCidFromFirebaseUid(db, firebaseUid);
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Path Resolution with Migration
|
|
117
|
-
```javascript
|
|
118
|
-
const { readWithMigration } = require('./helpers/core/path_resolution_helpers');
|
|
119
|
-
const data = await readWithMigration(db, newPath, legacyPath, { isCollection: false });
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Collection Path from Registry
|
|
123
|
-
```javascript
|
|
124
|
-
const { getCollectionPath } = require('../../config/collection_registry');
|
|
125
|
-
const path = getCollectionPath('signedInUsers', 'notifications', { cid: '12345678' });
|
|
126
|
-
// Returns: 'SignedInUsers/12345678/notifications'
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Testing Strategy
|
|
130
|
-
|
|
131
|
-
1. **Unit Tests**: Test path resolution and migration logic
|
|
132
|
-
2. **Integration Tests**: Test dual read/write with both formats
|
|
133
|
-
3. **Migration Tests**: Test auto-migration on read
|
|
134
|
-
4. **Rollback Tests**: Ensure legacy paths still work during transition
|
|
135
|
-
|
|
136
|
-
## Next Steps
|
|
137
|
-
|
|
138
|
-
1. ✅ Review migration plan (done)
|
|
139
|
-
2. ⏳ Review code reorganization plan (done)
|
|
140
|
-
3. ⏳ Start implementing core helpers
|
|
141
|
-
4. ⏳ Begin migrating helper files one by one
|
|
142
|
-
5. ⏳ Test each migration incrementally
|
|
143
|
-
6. ⏳ Deploy with feature flags
|
|
144
|
-
7. ⏳ Monitor and iterate
|
|
145
|
-
|
|
146
|
-
## Questions?
|
|
147
|
-
|
|
148
|
-
Refer to:
|
|
149
|
-
- `MIGRATION_PLAN.md` for detailed migration strategy
|
|
150
|
-
- `FIRESTORE_PATHS_INVENTORY.md` for path reference
|
|
151
|
-
- `CODE_REORGANIZATION_PLAN.md` for code structure details
|
|
152
|
-
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# Refactoring Complete ✅
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
The `data_helpers.js` file (2550 lines) has been completely refactored into organized, modular helper files with full migration support.
|
|
6
|
-
|
|
7
|
-
## File Size Reduction
|
|
8
|
-
|
|
9
|
-
- **Before**: `data_helpers.js` = 2550 lines
|
|
10
|
-
- **After**: `data_helpers.js` = 90 lines (re-exports only)
|
|
11
|
-
- **Reduction**: 96% smaller, now just a re-export hub
|
|
12
|
-
|
|
13
|
-
## New File Structure
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
helpers/
|
|
17
|
-
├── core/
|
|
18
|
-
│ ├── compression_helpers.js (compression utilities)
|
|
19
|
-
│ ├── data_lookup_helpers.js (find latest dates)
|
|
20
|
-
│ ├── user_status_helpers.js (PI status checks)
|
|
21
|
-
│ └── path_resolution_helpers.js (path resolution with migration)
|
|
22
|
-
├── data/
|
|
23
|
-
│ ├── portfolio_helpers.js (portfolio endpoints)
|
|
24
|
-
│ ├── social_helpers.js (social posts)
|
|
25
|
-
│ ├── computation_helpers.js (computation results)
|
|
26
|
-
│ └── instrument_helpers.js (instrument mappings)
|
|
27
|
-
├── profile/
|
|
28
|
-
│ ├── pi_profile_helpers.js (PI profile & analytics)
|
|
29
|
-
│ ├── user_profile_helpers.js (user verification & PI check)
|
|
30
|
-
│ └── profile_view_helpers.js (profile view tracking)
|
|
31
|
-
├── watchlist/
|
|
32
|
-
│ ├── watchlist_data_helpers.js (legacy watchlist endpoints)
|
|
33
|
-
│ ├── watchlist_generation_helpers.js (auto-generate)
|
|
34
|
-
│ └── watchlist_analytics_helpers.js (trigger counts)
|
|
35
|
-
├── search/
|
|
36
|
-
│ ├── pi_search_helpers.js (PI search)
|
|
37
|
-
│ └── pi_request_helpers.js (PI requests & rankings check)
|
|
38
|
-
├── recommendations/
|
|
39
|
-
│ └── recommendation_helpers.js (user recommendations)
|
|
40
|
-
└── metrics/
|
|
41
|
-
└── personalized_metrics_helpers.js (personalized metrics)
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Migration Support
|
|
45
|
-
|
|
46
|
-
All helper files now use the migration system:
|
|
47
|
-
|
|
48
|
-
- **`readWithMigration()`** - Tries new path, falls back to legacy, auto-migrates on read
|
|
49
|
-
- **`writeWithMigration()`** - Dual-write to both paths during transition
|
|
50
|
-
- **Registry-based paths** - All paths resolved through `collection_registry.js`
|
|
51
|
-
- **Legacy path mappings** - All legacy paths mapped in `path_resolution_helpers.js`
|
|
52
|
-
|
|
53
|
-
## Legacy Path Mappings
|
|
54
|
-
|
|
55
|
-
All legacy paths are now mapped and support auto-migration:
|
|
56
|
-
|
|
57
|
-
### Signed-In User Data
|
|
58
|
-
- `user_notifications/{firebaseUid}/notifications` → `SignedInUsers/{cid}/notifications`
|
|
59
|
-
- `user_watchlists/{cid}/lists` → `SignedInUsers/{cid}/watchlists`
|
|
60
|
-
- `user_verifications/{username}` → `SignedInUsers/{cid}/verification/data`
|
|
61
|
-
- `user_sync_requests/{cid}/requests` → `SignedInUsers/{cid}/syncRequests`
|
|
62
|
-
- `user_sync_requests/{cid}/global/latest` → `SignedInUsers/{cid}/syncStatus/latest`
|
|
63
|
-
- `signed_in_users_social/{cid}/posts` → `SignedInUsers/{cid}/posts`
|
|
64
|
-
|
|
65
|
-
### Popular Investor Data
|
|
66
|
-
- `pi_fetch_requests/{piCid}/requests/{requestId}` → `PopularInvestors/{piCid}/fetchRequests/{requestId}`
|
|
67
|
-
- `pi_fetch_requests/{piCid}/global/latest` → `PopularInvestors/{piCid}/fetchStatus/latest`
|
|
68
|
-
- `pi_fetch_requests/{piCid}/user_requests/{userCid}` → `PopularInvestors/{piCid}/userFetchRequests/{userCid}`
|
|
69
|
-
- `pi_reviews/{piCid}_{userCid}` → `PopularInvestors/{piCid}/reviews/{reviewId}`
|
|
70
|
-
- `pi_social_posts/{piCid}/posts/{postId}` → `PopularInvestors/{piCid}/posts/{postId}`
|
|
71
|
-
- `profile_views/{piCid}_{date}` → `PopularInvestors/{piCid}/profileViews/{date}`
|
|
72
|
-
- `profile_views/individual_views/views/{piCid}_{viewerCid}_{timestamp}` → `PopularInvestors/{piCid}/views/{viewId}`
|
|
73
|
-
|
|
74
|
-
## Backward Compatibility
|
|
75
|
-
|
|
76
|
-
✅ **Zero Breaking Changes** - All existing imports continue to work:
|
|
77
|
-
- `data_helpers.js` re-exports all functions from organized modules
|
|
78
|
-
- All function signatures remain identical
|
|
79
|
-
- All endpoints behave the same way
|
|
80
|
-
|
|
81
|
-
## Benefits
|
|
82
|
-
|
|
83
|
-
1. **Modularity** - Each file has a clear, single responsibility
|
|
84
|
-
2. **Maintainability** - Easy to find and update specific functionality
|
|
85
|
-
3. **DRY Compliance** - Shared utilities extracted to core helpers
|
|
86
|
-
4. **Migration Support** - Auto-migration on read, dual-write on write
|
|
87
|
-
5. **Registry-Based** - All paths use collection registry
|
|
88
|
-
6. **Testability** - Smaller files are easier to test
|
|
89
|
-
7. **Readability** - Clear organization makes code easier to understand
|
|
90
|
-
|
|
91
|
-
## Next Steps
|
|
92
|
-
|
|
93
|
-
1. ✅ All functions migrated to organized modules
|
|
94
|
-
2. ✅ All functions use migration system
|
|
95
|
-
3. ✅ Legacy paths mapped
|
|
96
|
-
4. ✅ `data_helpers.js` cleaned up
|
|
97
|
-
5. ⏳ Test all endpoints to ensure zero breaking changes
|
|
98
|
-
6. ⏳ Update any external documentation
|
|
99
|
-
|
|
100
|
-
## Notes
|
|
101
|
-
|
|
102
|
-
- Root data collections remain unchanged (populated by task engines)
|
|
103
|
-
- Public watchlists remain in `public_watchlists` (not user-centric)
|
|
104
|
-
- System collections like `user_gcid_mappings` remain unchanged
|
|
105
|
-
- Firebase UID → CID mapping stays in `signedInUsers/{firebaseUid}` main document
|
|
106
|
-
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# Refactoring Status
|
|
2
|
-
|
|
3
|
-
## ✅ Completed
|
|
4
|
-
|
|
5
|
-
### Core Infrastructure
|
|
6
|
-
- ✅ Created `core/compression_helpers.js` - Decompression utilities
|
|
7
|
-
- ✅ Created `core/data_lookup_helpers.js` - Data date lookup functions
|
|
8
|
-
- ✅ Created `core/user_status_helpers.js` - User status checks
|
|
9
|
-
- ✅ Created `core/path_resolution_helpers.js` - Path resolution with migration support
|
|
10
|
-
- ✅ Updated `collection_helpers.js` - Re-exports from core for backward compatibility
|
|
11
|
-
- ✅ Updated `collection_registry.js` - Added all new paths and legacy mappings
|
|
12
|
-
|
|
13
|
-
### Data Helpers
|
|
14
|
-
- ✅ Created `data/portfolio_helpers.js` - Portfolio endpoints
|
|
15
|
-
- ✅ Created `data/social_helpers.js` - Social posts endpoints
|
|
16
|
-
- ✅ Created `data/computation_helpers.js` - Computation endpoints
|
|
17
|
-
- ✅ Created `data/instrument_helpers.js` - Instrument mappings
|
|
18
|
-
|
|
19
|
-
### Profile Helpers
|
|
20
|
-
- ✅ Created `profile/pi_profile_helpers.js` - PI profile and analytics
|
|
21
|
-
- ✅ Created `profile/profile_view_helpers.js` - Profile view tracking with migration
|
|
22
|
-
|
|
23
|
-
### Migration Support
|
|
24
|
-
- ✅ Updated `path_resolution_helpers.js` with ALL legacy path mappings
|
|
25
|
-
- ✅ Implemented `readWithMigration()` - Auto-migrates on read
|
|
26
|
-
- ✅ Implemented `writeWithMigration()` - Dual-write during transition
|
|
27
|
-
|
|
28
|
-
## 🔄 In Progress / Remaining
|
|
29
|
-
|
|
30
|
-
### Profile Helpers
|
|
31
|
-
- ⏳ `profile/user_profile_helpers.js`
|
|
32
|
-
- `getUserVerification` - Needs migration to use `SignedInUsers/{cid}/verification`
|
|
33
|
-
- `checkIfUserIsPopularInvestor` - Can use existing helpers
|
|
34
|
-
|
|
35
|
-
### Watchlist Helpers
|
|
36
|
-
- ⏳ `watchlist/watchlist_data_helpers.js` (Legacy)
|
|
37
|
-
- `getWatchlist` - Legacy endpoint, needs migration support
|
|
38
|
-
- `updateWatchlist` - Legacy endpoint, needs migration support
|
|
39
|
-
- ⏳ `watchlist/watchlist_generation_helpers.js`
|
|
40
|
-
- `autoGenerateWatchlist` - Auto-generate from copied PIs
|
|
41
|
-
- ⏳ `watchlist/watchlist_analytics_helpers.js`
|
|
42
|
-
- `getWatchlistTriggerCounts` - Watchlist analytics
|
|
43
|
-
|
|
44
|
-
### Search & Recommendations
|
|
45
|
-
- ⏳ `search/pi_search_helpers.js`
|
|
46
|
-
- `searchPopularInvestors` - PI search
|
|
47
|
-
- ⏳ `search/pi_request_helpers.js`
|
|
48
|
-
- `requestPiAddition` - Request PI addition
|
|
49
|
-
- `checkPisInRankings` - Check PIs in rankings
|
|
50
|
-
- ⏳ `recommendations/recommendation_helpers.js`
|
|
51
|
-
- `getUserRecommendations` - User recommendations
|
|
52
|
-
|
|
53
|
-
### Metrics
|
|
54
|
-
- ⏳ `metrics/personalized_metrics_helpers.js`
|
|
55
|
-
- `getSignedInUserPIPersonalizedMetrics` - Personalized metrics
|
|
56
|
-
- `generateSamplePIPersonalizedMetrics` - Sample data generator
|
|
57
|
-
|
|
58
|
-
### Cleanup
|
|
59
|
-
- ⏳ Remove all legacy function implementations from `data_helpers.js`
|
|
60
|
-
- ⏳ Update `data_helpers.js` to only re-export from organized modules
|
|
61
|
-
- ⏳ Update all helper files to use `readWithMigration` and `writeWithMigration`
|
|
62
|
-
|
|
63
|
-
## Legacy Path Mappings Status
|
|
64
|
-
|
|
65
|
-
All legacy paths are now mapped in `path_resolution_helpers.js`:
|
|
66
|
-
- ✅ Signed-in user notifications, alerts, watchlists, subscriptions
|
|
67
|
-
- ✅ User verification, sync requests, sync status
|
|
68
|
-
- ✅ Portfolio, trade history, social posts
|
|
69
|
-
- ✅ PI fetch requests, fetch status, user fetch requests
|
|
70
|
-
- ✅ PI reviews, social posts, profile views, individual views
|
|
71
|
-
|
|
72
|
-
## Next Steps
|
|
73
|
-
|
|
74
|
-
1. Complete remaining helper file creation
|
|
75
|
-
2. Update all functions to use migration system
|
|
76
|
-
3. Remove legacy implementations from `data_helpers.js`
|
|
77
|
-
4. Test all endpoints to ensure zero breaking changes
|
|
78
|
-
5. Update documentation
|
|
79
|
-
|
|
80
|
-
## File Size Reduction
|
|
81
|
-
|
|
82
|
-
- **Before**: `data_helpers.js` = 2550 lines
|
|
83
|
-
- **After (target)**: `data_helpers.js` = ~100 lines (re-exports only)
|
|
84
|
-
- **Organized modules**: Each file 100-400 lines, clear responsibility
|
|
85
|
-
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
# Verification Data Migration Notes
|
|
2
|
-
|
|
3
|
-
## Current Implementation
|
|
4
|
-
|
|
5
|
-
### Initiate Verification
|
|
6
|
-
- **Path**: `{verificationsCollection}/{username}` (e.g., `verifications/marau2021`)
|
|
7
|
-
- **Data**: `{ username, otp, status: 'PENDING', createdAt, expiresAt }`
|
|
8
|
-
- **Purpose**: Store pending OTP before CID is known
|
|
9
|
-
|
|
10
|
-
### Finalize Verification
|
|
11
|
-
- **API Call**: `GET https://www.etoro.com/api/logininfo/v1.1/users/{username}`
|
|
12
|
-
- **Response Contains**: `{ realCID, username, firstName, lastName, optOut, ... }`
|
|
13
|
-
- **Current Action**: Updates verification doc with `{ status: 'VERIFIED', cid: realCID, verifiedAt, isOptOut }`
|
|
14
|
-
- **Current Path**: Still at `{verificationsCollection}/{username}` (not migrated)
|
|
15
|
-
|
|
16
|
-
## New Implementation
|
|
17
|
-
|
|
18
|
-
### Initiate Verification (Unchanged)
|
|
19
|
-
- **Path**: `{verificationsCollection}/{username}` (legacy, before CID known)
|
|
20
|
-
- **Data**: `{ username, otp, status: 'PENDING', createdAt, expiresAt }`
|
|
21
|
-
|
|
22
|
-
### Finalize Verification (Updated)
|
|
23
|
-
- **After Bio Check API**:
|
|
24
|
-
1. Get `realCID` from `profileData.realCID`
|
|
25
|
-
2. Migrate verification data to: `SignedInUsers/{cid}/verification`
|
|
26
|
-
3. Store full profile data for reference
|
|
27
|
-
4. Delete or mark legacy verification as migrated
|
|
28
|
-
|
|
29
|
-
- **New Path**: `SignedInUsers/{cid}/verification/data` (4 segments: collection/document/collection/document)
|
|
30
|
-
- Single document in subcollection to comply with Firestore even-segment rule
|
|
31
|
-
- **New Data Structure**:
|
|
32
|
-
```javascript
|
|
33
|
-
{
|
|
34
|
-
username: 'Marau2021',
|
|
35
|
-
cid: 29312236, // from profileData.realCID
|
|
36
|
-
firebaseUid: null, // set later when Firebase account created
|
|
37
|
-
otp: 'I84Z9P',
|
|
38
|
-
status: 'VERIFIED',
|
|
39
|
-
createdAt: Timestamp,
|
|
40
|
-
expiresAt: Timestamp,
|
|
41
|
-
verifiedAt: Timestamp,
|
|
42
|
-
isOptOut: false,
|
|
43
|
-
profileData: {
|
|
44
|
-
realCID: 29312236,
|
|
45
|
-
gcid: 29595736,
|
|
46
|
-
demoCID: 30809243,
|
|
47
|
-
username: 'Marau2021',
|
|
48
|
-
firstName: 'Aiden',
|
|
49
|
-
lastName: 'Hawkins',
|
|
50
|
-
optOut: false,
|
|
51
|
-
isPi: false,
|
|
52
|
-
avatars: [...],
|
|
53
|
-
// ... other profile fields
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Account Creation (New Step)
|
|
59
|
-
- **When Firebase account is created**:
|
|
60
|
-
1. Get Firebase UID from auth system
|
|
61
|
-
2. Update verification document: `SignedInUsers/{cid}/verification`
|
|
62
|
-
3. Add: `{ firebaseUid: 'firebase-uid-here' }`
|
|
63
|
-
4. Also update: `signedInUsers/{firebaseUid}` with `{ etoroCID: cid }` (UID→CID mapping)
|
|
64
|
-
|
|
65
|
-
## Migration Strategy
|
|
66
|
-
|
|
67
|
-
### Option 1: Immediate Migration (Recommended)
|
|
68
|
-
During `finalizeVerification`:
|
|
69
|
-
1. Read from legacy path: `{verificationsCollection}/{username}`
|
|
70
|
-
2. Get `realCID` from bio check API response
|
|
71
|
-
3. Write to new path: `SignedInUsers/{cid}/verification`
|
|
72
|
-
4. Delete legacy document (or mark as migrated)
|
|
73
|
-
|
|
74
|
-
### Option 2: Dual Write (During Transition)
|
|
75
|
-
During `finalizeVerification`:
|
|
76
|
-
1. Write to both paths:
|
|
77
|
-
- Legacy: `{verificationsCollection}/{username}` (for backward compatibility)
|
|
78
|
-
- New: `SignedInUsers/{cid}/verification`
|
|
79
|
-
2. Read from new path first, fallback to legacy
|
|
80
|
-
3. Eventually remove legacy writes
|
|
81
|
-
|
|
82
|
-
### Option 3: Auto-Migration on Read
|
|
83
|
-
1. Keep legacy path for now
|
|
84
|
-
2. When reading verification, check new path first
|
|
85
|
-
3. If not found, read from legacy and migrate
|
|
86
|
-
4. Eventually all verifications migrated
|
|
87
|
-
|
|
88
|
-
## Implementation Changes Needed
|
|
89
|
-
|
|
90
|
-
### verification_helpers.js
|
|
91
|
-
|
|
92
|
-
#### initiateVerification
|
|
93
|
-
- **No changes needed** - still uses legacy path (CID not known yet)
|
|
94
|
-
|
|
95
|
-
#### finalizeVerification
|
|
96
|
-
- **After getting `realCID` from API**:
|
|
97
|
-
```javascript
|
|
98
|
-
const realCID = profileData.realCID;
|
|
99
|
-
|
|
100
|
-
// 1. Read existing verification data
|
|
101
|
-
const legacyVerificationRef = db.collection(verificationsCollection).doc(username.toLowerCase());
|
|
102
|
-
const legacyVerificationDoc = await legacyVerificationRef.get();
|
|
103
|
-
const legacyData = legacyVerificationDoc.data();
|
|
104
|
-
|
|
105
|
-
// 2. Create new verification document under CID
|
|
106
|
-
const newVerificationRef = db.collection('SignedInUsers')
|
|
107
|
-
.doc(String(realCID))
|
|
108
|
-
.collection('verification')
|
|
109
|
-
.doc('data'); // Single document named "data" to comply with Firestore even-segment rule (4 segments)
|
|
110
|
-
|
|
111
|
-
await newVerificationRef.set({
|
|
112
|
-
username: legacyData.username,
|
|
113
|
-
cid: realCID,
|
|
114
|
-
firebaseUid: null, // Will be set when Firebase account created
|
|
115
|
-
otp: legacyData.otp,
|
|
116
|
-
status: 'VERIFIED',
|
|
117
|
-
createdAt: legacyData.createdAt,
|
|
118
|
-
expiresAt: legacyData.expiresAt,
|
|
119
|
-
verifiedAt: FieldValue.serverTimestamp(),
|
|
120
|
-
isOptOut: isOptOut,
|
|
121
|
-
profileData: profileData // Store full profile for reference
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// 3. Delete legacy verification (or mark as migrated)
|
|
125
|
-
await legacyVerificationRef.delete();
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
#### Account Creation Hook (New)
|
|
129
|
-
- **When Firebase account is created** (in auth system or separate endpoint):
|
|
130
|
-
```javascript
|
|
131
|
-
async function linkFirebaseAccountToVerification(db, firebaseUid, cid) {
|
|
132
|
-
// Update verification document with Firebase UID
|
|
133
|
-
const verificationRef = db.collection('SignedInUsers')
|
|
134
|
-
.doc(String(cid))
|
|
135
|
-
.collection('verification')
|
|
136
|
-
.doc('data'); // 4 segments: collection/document/collection/document
|
|
137
|
-
|
|
138
|
-
await verificationRef.update({
|
|
139
|
-
firebaseUid: firebaseUid,
|
|
140
|
-
accountLinkedAt: FieldValue.serverTimestamp()
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Also update UID→CID mapping
|
|
144
|
-
await db.collection('signedInUsers').doc(firebaseUid).set({
|
|
145
|
-
etoroCID: cid,
|
|
146
|
-
linkedAt: FieldValue.serverTimestamp()
|
|
147
|
-
}, { merge: true });
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## Reading Verification Data
|
|
152
|
-
|
|
153
|
-
### By CID (New)
|
|
154
|
-
```javascript
|
|
155
|
-
const verificationRef = db.collection('SignedInUsers')
|
|
156
|
-
.doc(String(cid))
|
|
157
|
-
.collection('verification')
|
|
158
|
-
.doc('data'); // 4 segments: collection/document/collection/document
|
|
159
|
-
|
|
160
|
-
const verificationDoc = await verificationRef.get();
|
|
161
|
-
if (verificationDoc.exists) {
|
|
162
|
-
return verificationDoc.data();
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### By Username (Legacy - During Migration)
|
|
167
|
-
```javascript
|
|
168
|
-
// Try new path first (if CID is known)
|
|
169
|
-
// Fallback to legacy path if needed
|
|
170
|
-
const legacyRef = db.collection(verificationsCollection).doc(username.toLowerCase());
|
|
171
|
-
const legacyDoc = await legacyRef.get();
|
|
172
|
-
if (legacyDoc.exists) {
|
|
173
|
-
// Auto-migrate if CID is available
|
|
174
|
-
const data = legacyDoc.data();
|
|
175
|
-
if (data.cid) {
|
|
176
|
-
// Migrate to new path
|
|
177
|
-
await migrateVerificationToCidPath(db, data.cid, data);
|
|
178
|
-
}
|
|
179
|
-
return data;
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## Benefits
|
|
184
|
-
|
|
185
|
-
1. **Consistent Structure**: All user data under `SignedInUsers/{cid}/...`
|
|
186
|
-
2. **Single Source of Truth**: One verification document per user (by CID)
|
|
187
|
-
3. **Complete Profile Data**: Store full API response for reference
|
|
188
|
-
4. **Firebase UID Linkage**: Connect Firebase account to eToro CID
|
|
189
|
-
5. **Easier Queries**: Can query by CID instead of username
|
|
190
|
-
|
|
191
|
-
## Registry Update
|
|
192
|
-
|
|
193
|
-
Update `collection_registry.js`:
|
|
194
|
-
```javascript
|
|
195
|
-
verification: {
|
|
196
|
-
path: 'SignedInUsers/{cid}/verification/data', // 4 segments: collection/document/collection/document
|
|
197
|
-
description: 'User verification status and OTP data (single document in subcollection)',
|
|
198
|
-
schema: '{ username, cid, firebaseUid, otp, status, createdAt, expiresAt, verifiedAt, isOptOut, profileData }',
|
|
199
|
-
dynamicSegments: ['{cid}'],
|
|
200
|
-
status: 'active',
|
|
201
|
-
legacyPaths: [
|
|
202
|
-
'{verificationsCollection}/{username}' // Legacy path before CID known (2 segments)
|
|
203
|
-
]
|
|
204
|
-
}
|
|
205
|
-
```
|
|
206
|
-
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
# Helper Files Organization - Complete
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
All helper files have been reorganized into logical subfolders for better maintainability and clarity.
|
|
5
|
-
|
|
6
|
-
## New Directory Structure
|
|
7
|
-
|
|
8
|
-
```
|
|
9
|
-
helpers/
|
|
10
|
-
├── alerts/ # Alert-related functionality
|
|
11
|
-
│ ├── alert_helpers.js # Alert management (get, mark read, delete)
|
|
12
|
-
│ ├── test_alert_helpers.js # Test alert functionality for developers
|
|
13
|
-
│ └── subscription_helpers.js # Alert subscriptions for watchlists
|
|
14
|
-
│
|
|
15
|
-
├── verification/ # User verification
|
|
16
|
-
│ └── verification_helpers.js # OTP bio check and account verification
|
|
17
|
-
│
|
|
18
|
-
├── sync/ # User sync requests
|
|
19
|
-
│ └── user_sync_helpers.js # On-demand sync for user profiles
|
|
20
|
-
│
|
|
21
|
-
├── fetch/ # On-demand data fetching
|
|
22
|
-
│ └── on_demand_fetch_helpers.js # PI data fetch requests with rate limiting
|
|
23
|
-
│
|
|
24
|
-
├── watchlist/ # Watchlist management
|
|
25
|
-
│ ├── watchlist_data_helpers.js # Legacy single watchlist endpoints
|
|
26
|
-
│ ├── watchlist_generation_helpers.js # Auto-generation from copied PIs
|
|
27
|
-
│ ├── watchlist_analytics_helpers.js # Watchlist analytics and triggers
|
|
28
|
-
│ └── watchlist_management_helpers.js # Multi-watchlist CRUD operations
|
|
29
|
-
│
|
|
30
|
-
├── dev/ # Developer tools
|
|
31
|
-
│ └── dev_helpers.js # Developer overrides and impersonation
|
|
32
|
-
│
|
|
33
|
-
├── reviews/ # Review system
|
|
34
|
-
│ └── review_helpers.js # PI review submission and retrieval
|
|
35
|
-
│
|
|
36
|
-
├── notifications/ # Notification system
|
|
37
|
-
│ └── notification_helpers.js # On-demand request notifications
|
|
38
|
-
│
|
|
39
|
-
├── core/ # Core utilities
|
|
40
|
-
│ ├── compression_helpers.js # Data decompression
|
|
41
|
-
│ ├── data_lookup_helpers.js # Date lookup functions
|
|
42
|
-
│ ├── path_resolution_helpers.js # Path resolution with migration
|
|
43
|
-
│ └── user_status_helpers.js # User status checks
|
|
44
|
-
│
|
|
45
|
-
├── data/ # Data endpoints
|
|
46
|
-
│ ├── portfolio_helpers.js # Portfolio data
|
|
47
|
-
│ ├── social_helpers.js # Social posts
|
|
48
|
-
│ ├── computation_helpers.js # Computation results
|
|
49
|
-
│ └── instrument_helpers.js # Instrument mappings
|
|
50
|
-
│
|
|
51
|
-
├── profile/ # Profile endpoints
|
|
52
|
-
│ ├── pi_profile_helpers.js # PI profile and analytics
|
|
53
|
-
│ ├── user_profile_helpers.js # User profile and verification
|
|
54
|
-
│ └── profile_view_helpers.js # Profile view tracking
|
|
55
|
-
│
|
|
56
|
-
├── search/ # Search functionality
|
|
57
|
-
│ ├── pi_search_helpers.js # PI search
|
|
58
|
-
│ └── pi_request_helpers.js # PI addition requests
|
|
59
|
-
│
|
|
60
|
-
├── recommendations/ # Recommendations
|
|
61
|
-
│ └── recommendation_helpers.js # User recommendations
|
|
62
|
-
│
|
|
63
|
-
├── metrics/ # Metrics
|
|
64
|
-
│ └── personalized_metrics_helpers.js # Personalized metrics
|
|
65
|
-
│
|
|
66
|
-
├── collection_helpers.js # Re-exports from core (backward compat)
|
|
67
|
-
└── data_helpers.js # Re-export hub (backward compat)
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## File Organization by Purpose
|
|
71
|
-
|
|
72
|
-
### Alerts (`alerts/`)
|
|
73
|
-
- **alert_helpers.js**: Core alert management (get, mark read, delete, count)
|
|
74
|
-
- **test_alert_helpers.js**: Developer tool for sending test alerts
|
|
75
|
-
- **subscription_helpers.js**: Alert subscriptions for watchlist PIs
|
|
76
|
-
|
|
77
|
-
### Verification (`verification/`)
|
|
78
|
-
- **verification_helpers.js**: User account verification via OTP bio check
|
|
79
|
-
|
|
80
|
-
### Sync (`sync/`)
|
|
81
|
-
- **user_sync_helpers.js**: On-demand sync requests for user profiles (rate limited)
|
|
82
|
-
|
|
83
|
-
### Fetch (`fetch/`)
|
|
84
|
-
- **on_demand_fetch_helpers.js**: On-demand PI data fetching with rate limiting
|
|
85
|
-
|
|
86
|
-
### Watchlist (`watchlist/`)
|
|
87
|
-
- **watchlist_management_helpers.js**: Multi-watchlist CRUD operations (new system)
|
|
88
|
-
- **watchlist_data_helpers.js**: Legacy single watchlist endpoints
|
|
89
|
-
- **watchlist_generation_helpers.js**: Auto-generation from copied PIs
|
|
90
|
-
- **watchlist_analytics_helpers.js**: Analytics and trigger counts
|
|
91
|
-
|
|
92
|
-
### Dev (`dev/`)
|
|
93
|
-
- **dev_helpers.js**: Developer overrides, impersonation, and testing tools
|
|
94
|
-
|
|
95
|
-
### Reviews (`reviews/`)
|
|
96
|
-
- **review_helpers.js**: PI review submission, retrieval, and eligibility checks
|
|
97
|
-
|
|
98
|
-
### Notifications (`notifications/`)
|
|
99
|
-
- **notification_helpers.js**: On-demand request completion notifications
|
|
100
|
-
|
|
101
|
-
## Import Path Updates
|
|
102
|
-
|
|
103
|
-
All imports have been updated to reflect the new structure:
|
|
104
|
-
- `./dev_helpers` → `../dev/dev_helpers`
|
|
105
|
-
- `./data_helpers` → `../data_helpers` (or appropriate relative path)
|
|
106
|
-
- `./alert_helpers` → `../alerts/alert_helpers`
|
|
107
|
-
- etc.
|
|
108
|
-
|
|
109
|
-
## Backward Compatibility
|
|
110
|
-
|
|
111
|
-
- `data_helpers.js` remains as a re-export hub for backward compatibility
|
|
112
|
-
- `collection_helpers.js` re-exports from `core/path_resolution_helpers.js`
|
|
113
|
-
- All existing imports continue to work
|
|
114
|
-
|
|
115
|
-
## Benefits
|
|
116
|
-
|
|
117
|
-
1. **Clear Organization**: Files are grouped by functionality
|
|
118
|
-
2. **Easier Navigation**: Related files are in the same directory
|
|
119
|
-
3. **Better Maintainability**: Smaller, focused files are easier to understand
|
|
120
|
-
4. **Scalability**: Easy to add new files to appropriate folders
|
|
121
|
-
5. **Zero Breaking Changes**: All existing imports still work
|
|
122
|
-
|
|
123
|
-
## Next Steps
|
|
124
|
-
|
|
125
|
-
The frontend can now be reviewed and updated to use the new import paths if desired, though backward compatibility is maintained.
|
|
126
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/functions/{generic-api → old-generic-api}/user-api/helpers/alerts/subscription_helpers.js
RENAMED
|
File without changes
|