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,195 +0,0 @@
1
- /**
2
- * @fileoverview User Status Helpers
3
- * Functions to check user status (PI, signed-in, etc.)
4
- */
5
-
6
- const { findLatestRankingsDate } = require('./data_lookup_helpers');
7
-
8
- /**
9
- * Get Popular Investor master list from Firestore
10
- * @param {Firestore} db - Firestore instance
11
- * @param {object} collectionRegistry - Collection registry (optional)
12
- * @param {object} logger - Logger instance (optional)
13
- * @returns {Promise<object>} - Master list investors map { cid: { cid, username, firstSeenAt, lastSeenAt } }
14
- */
15
- async function getPIMasterList(db, collectionRegistry = null, logger = null) {
16
- try {
17
- let masterListPath = 'system_state/popular_investor_master_list';
18
-
19
- if (collectionRegistry && collectionRegistry.getCollectionPath) {
20
- try {
21
- masterListPath = collectionRegistry.getCollectionPath('system', 'popularInvestorMasterList', {});
22
- } catch (err) {
23
- if (logger) {
24
- logger.log('WARN', `[getPIMasterList] Failed to get master list path from registry, using default: ${err.message}`);
25
- }
26
- }
27
- }
28
-
29
- const masterListRef = db.doc(masterListPath);
30
- const masterListDoc = await masterListRef.get();
31
-
32
- if (!masterListDoc.exists) {
33
- return {};
34
- }
35
-
36
- const masterListData = masterListDoc.data();
37
- return masterListData.investors || {};
38
- } catch (error) {
39
- if (logger) {
40
- logger.log('ERROR', `[getPIMasterList] Error loading master list: ${error.message}`);
41
- }
42
- return {};
43
- }
44
- }
45
-
46
- /**
47
- * Get PI username from CID using master list
48
- * @param {Firestore} db - Firestore instance
49
- * @param {string|number} piCid - Popular Investor CID
50
- * @param {object} collectionRegistry - Collection registry (optional)
51
- * @param {object} logger - Logger instance (optional)
52
- * @returns {Promise<string|null>} - Username or null if not found
53
- */
54
- async function getPIUsernameFromMasterList(db, piCid, collectionRegistry = null, logger = null) {
55
- try {
56
- const investors = await getPIMasterList(db, collectionRegistry, logger);
57
- const cidStr = String(piCid);
58
- const investor = investors[cidStr];
59
-
60
- if (investor && investor.username) {
61
- return investor.username;
62
- }
63
-
64
- return null;
65
- } catch (error) {
66
- if (logger) {
67
- logger.log('ERROR', `[getPIUsernameFromMasterList] Error getting username for PI ${piCid}: ${error.message}`);
68
- }
69
- return null;
70
- }
71
- }
72
-
73
- /**
74
- * Get PI CID from username using master list
75
- * @param {Firestore} db - Firestore instance
76
- * @param {string} username - Popular Investor username
77
- * @param {object} collectionRegistry - Collection registry (optional)
78
- * @param {object} logger - Logger instance (optional)
79
- * @returns {Promise<string|null>} - CID or null if not found
80
- */
81
- async function getPICidFromMasterList(db, username, collectionRegistry = null, logger = null) {
82
- try {
83
- const investors = await getPIMasterList(db, collectionRegistry, logger);
84
- const searchUsername = username.toLowerCase().trim();
85
-
86
- for (const [cid, investor] of Object.entries(investors)) {
87
- if (investor.username && investor.username.toLowerCase().trim() === searchUsername) {
88
- return cid;
89
- }
90
- }
91
-
92
- return null;
93
- } catch (error) {
94
- if (logger) {
95
- logger.log('ERROR', `[getPICidFromMasterList] Error getting CID for username ${username}: ${error.message}`);
96
- }
97
- return null;
98
- }
99
- }
100
-
101
- /**
102
- * Check if a CID is a Popular Investor using master list
103
- * @param {Firestore} db - Firestore instance
104
- * @param {string|number} cid - User CID
105
- * @param {object} collectionRegistry - Collection registry (optional)
106
- * @param {object} logger - Logger instance (optional)
107
- * @returns {Promise<boolean>} - True if PI, false otherwise
108
- */
109
- async function isPopularInvestor(db, cid, collectionRegistry = null, logger = null) {
110
- try {
111
- const investors = await getPIMasterList(db, collectionRegistry, logger);
112
- const cidStr = String(cid);
113
- return investors.hasOwnProperty(cidStr);
114
- } catch (error) {
115
- if (logger) {
116
- logger.log('ERROR', `[isPopularInvestor] Error checking if ${cid} is PI: ${error.message}`);
117
- }
118
- return false;
119
- }
120
- }
121
-
122
- /**
123
- * Check if a signed-in user is also a Popular Investor
124
- * Returns ranking entry if found, null otherwise
125
- * Checks dev overrides first for pretendToBePI flag
126
- * @param {Firestore} db - Firestore instance
127
- * @param {string|number} userCid - User CID
128
- * @param {object} config - Configuration object
129
- * @param {object} logger - Logger instance (optional)
130
- * @returns {Promise<object|null>} - Ranking entry or null
131
- */
132
- async function checkIfUserIsPI(db, userCid, config, logger = null) {
133
- try {
134
- // Check dev override first (for developer accounts)
135
- const { getDevOverride } = require('../dev/dev_helpers');
136
- const devOverride = await getDevOverride(db, userCid, config, logger);
137
-
138
- if (devOverride && devOverride.enabled && devOverride.pretendToBePI) {
139
- // Generate fake ranking entry for dev testing
140
- const fakeRankEntry = {
141
- CustomerId: Number(userCid),
142
- UserName: 'Dev Test PI',
143
- AUMValue: 500000 + Math.floor(Math.random() * 1000000), // Random AUM between 500k-1.5M
144
- Copiers: 150 + Math.floor(Math.random() * 200), // Random copiers between 150-350
145
- RiskScore: 3 + Math.floor(Math.random() * 3), // Random risk score 3-5
146
- Gain: 25 + Math.floor(Math.random() * 50), // Random gain 25-75%
147
- WinRatio: 50 + Math.floor(Math.random() * 20), // Random win ratio 50-70%
148
- Trades: 500 + Math.floor(Math.random() * 1000) // Random trades 500-1500
149
- };
150
-
151
- if (logger && logger.log) {
152
- logger.log('INFO', `[checkIfUserIsPI] DEV OVERRIDE: User ${userCid} pretending to be PI with fake ranking data`);
153
- } else {
154
- console.log(`[checkIfUserIsPI] DEV OVERRIDE: User ${userCid} pretending to be PI with fake ranking data`);
155
- }
156
-
157
- return fakeRankEntry;
158
- }
159
-
160
- // Otherwise, check master list (single source of truth)
161
- const collectionRegistry = config.collectionRegistry || null;
162
- const isPI = await isPopularInvestor(db, userCid, collectionRegistry, logger);
163
-
164
- if (!isPI) {
165
- return null;
166
- }
167
-
168
- // Get username from master list
169
- const username = await getPIUsernameFromMasterList(db, userCid, collectionRegistry, logger);
170
-
171
- if (!username) {
172
- return null;
173
- }
174
-
175
- // Return a ranking-like entry for compatibility (minimal data)
176
- // Note: Full ranking data (AUM, copiers, etc.) is not in master list
177
- // If full ranking data is needed, it should be fetched from rankings collection separately
178
- return {
179
- CustomerId: Number(userCid),
180
- UserName: username
181
- };
182
- } catch (error) {
183
- console.error('[checkIfUserIsPI] Error checking if user is PI:', error);
184
- return null;
185
- }
186
- }
187
-
188
- module.exports = {
189
- checkIfUserIsPI,
190
- getPIMasterList,
191
- getPIUsernameFromMasterList,
192
- getPICidFromMasterList,
193
- isPopularInvestor
194
- };
195
-