bulltrackers-module 1.0.592 → 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/old-generic-api/admin-api/index.js +895 -0
- package/functions/old-generic-api/helpers/api_helpers.js +457 -0
- package/functions/old-generic-api/index.js +204 -0
- package/functions/old-generic-api/user-api/helpers/alerts/alert_helpers.js +355 -0
- package/functions/old-generic-api/user-api/helpers/alerts/subscription_helpers.js +327 -0
- package/functions/old-generic-api/user-api/helpers/alerts/test_alert_helpers.js +212 -0
- package/functions/old-generic-api/user-api/helpers/collection_helpers.js +193 -0
- package/functions/old-generic-api/user-api/helpers/core/compression_helpers.js +68 -0
- package/functions/old-generic-api/user-api/helpers/core/data_lookup_helpers.js +256 -0
- package/functions/old-generic-api/user-api/helpers/core/path_resolution_helpers.js +640 -0
- package/functions/old-generic-api/user-api/helpers/core/user_status_helpers.js +195 -0
- package/functions/old-generic-api/user-api/helpers/data/computation_helpers.js +503 -0
- package/functions/old-generic-api/user-api/helpers/data/instrument_helpers.js +55 -0
- package/functions/old-generic-api/user-api/helpers/data/portfolio_helpers.js +245 -0
- package/functions/old-generic-api/user-api/helpers/data/social_helpers.js +174 -0
- package/functions/old-generic-api/user-api/helpers/data_helpers.js +87 -0
- package/functions/old-generic-api/user-api/helpers/dev/dev_helpers.js +336 -0
- package/functions/old-generic-api/user-api/helpers/fetch/on_demand_fetch_helpers.js +615 -0
- package/functions/old-generic-api/user-api/helpers/metrics/personalized_metrics_helpers.js +231 -0
- package/functions/old-generic-api/user-api/helpers/notifications/notification_helpers.js +641 -0
- package/functions/old-generic-api/user-api/helpers/profile/pi_profile_helpers.js +182 -0
- package/functions/old-generic-api/user-api/helpers/profile/profile_view_helpers.js +137 -0
- package/functions/old-generic-api/user-api/helpers/profile/user_profile_helpers.js +190 -0
- package/functions/old-generic-api/user-api/helpers/recommendations/recommendation_helpers.js +66 -0
- package/functions/old-generic-api/user-api/helpers/reviews/review_helpers.js +550 -0
- package/functions/old-generic-api/user-api/helpers/rootdata/rootdata_aggregation_helpers.js +378 -0
- package/functions/old-generic-api/user-api/helpers/search/pi_request_helpers.js +295 -0
- package/functions/old-generic-api/user-api/helpers/search/pi_search_helpers.js +162 -0
- package/functions/old-generic-api/user-api/helpers/sync/user_sync_helpers.js +677 -0
- package/functions/old-generic-api/user-api/helpers/verification/verification_helpers.js +323 -0
- package/functions/old-generic-api/user-api/helpers/watchlist/watchlist_analytics_helpers.js +96 -0
- package/functions/old-generic-api/user-api/helpers/watchlist/watchlist_data_helpers.js +141 -0
- package/functions/old-generic-api/user-api/helpers/watchlist/watchlist_generation_helpers.js +310 -0
- package/functions/old-generic-api/user-api/helpers/watchlist/watchlist_management_helpers.js +829 -0
- package/functions/old-generic-api/user-api/index.js +109 -0
- package/package.json +2 -2
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Data Lookup Utilities
|
|
3
|
+
* Functions to find latest available data dates for various collections
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Find the latest available date for signed-in user portfolio data
|
|
8
|
+
* Searches backwards from today up to maxDaysBack days
|
|
9
|
+
* Checks both new root data path and legacy path for compatibility
|
|
10
|
+
* @param {Firestore} db - Firestore instance
|
|
11
|
+
* @param {string} signedInUsersCollection - Collection name (legacy)
|
|
12
|
+
* @param {string|number} userCid - User CID
|
|
13
|
+
* @param {number} maxDaysBack - Maximum days to search backwards (default: 30)
|
|
14
|
+
* @returns {Promise<string|null>} - Date string (YYYY-MM-DD) or null if not found
|
|
15
|
+
*/
|
|
16
|
+
async function findLatestPortfolioDate(db, signedInUsersCollection, userCid, maxDaysBack = 30) {
|
|
17
|
+
const today = new Date();
|
|
18
|
+
const userCidStr = String(userCid);
|
|
19
|
+
|
|
20
|
+
// First, check the user-centric latest snapshot (fastest check)
|
|
21
|
+
try {
|
|
22
|
+
const latestRef = db.collection('SignedInUsers')
|
|
23
|
+
.doc(userCidStr)
|
|
24
|
+
.collection('portfolio')
|
|
25
|
+
.doc('latest');
|
|
26
|
+
|
|
27
|
+
const latestDoc = await latestRef.get();
|
|
28
|
+
if (latestDoc.exists) {
|
|
29
|
+
const data = latestDoc.data();
|
|
30
|
+
if (data && data.date) {
|
|
31
|
+
return data.date; // Found in latest snapshot
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
// Continue to other checks if this fails
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Second, check the new root data path: SignedInUserPortfolioData/{date}/{cid}/{cid}
|
|
39
|
+
for (let i = 0; i < maxDaysBack; i++) {
|
|
40
|
+
const checkDate = new Date(today);
|
|
41
|
+
checkDate.setDate(checkDate.getDate() - i);
|
|
42
|
+
const dateStr = checkDate.toISOString().split('T')[0];
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const rootDataRef = db.collection('SignedInUserPortfolioData')
|
|
46
|
+
.doc(dateStr)
|
|
47
|
+
.collection(userCidStr)
|
|
48
|
+
.doc(userCidStr);
|
|
49
|
+
|
|
50
|
+
const rootDataDoc = await rootDataRef.get();
|
|
51
|
+
if (rootDataDoc.exists) {
|
|
52
|
+
return dateStr; // Found data in root data collection
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
// Continue to next date if error
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Third, check legacy path for backward compatibility: {signedInUsersCollection}/19M/snapshots/{date}/parts
|
|
61
|
+
const CANARY_BLOCK_ID = '19M';
|
|
62
|
+
for (let i = 0; i < maxDaysBack; i++) {
|
|
63
|
+
const checkDate = new Date(today);
|
|
64
|
+
checkDate.setDate(checkDate.getDate() - i);
|
|
65
|
+
const dateStr = checkDate.toISOString().split('T')[0];
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const partsRef = db.collection(signedInUsersCollection)
|
|
69
|
+
.doc(CANARY_BLOCK_ID)
|
|
70
|
+
.collection('snapshots')
|
|
71
|
+
.doc(dateStr)
|
|
72
|
+
.collection('parts');
|
|
73
|
+
|
|
74
|
+
const partsSnapshot = await partsRef.get();
|
|
75
|
+
|
|
76
|
+
// Check if user's CID exists in any part document
|
|
77
|
+
for (const partDoc of partsSnapshot.docs) {
|
|
78
|
+
const partData = partDoc.data();
|
|
79
|
+
if (partData && partData[userCidStr]) {
|
|
80
|
+
return dateStr; // Found data for this date in legacy path
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
// Continue to next date if error
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return null; // No data found in the last maxDaysBack days
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Find the latest available date for computation results
|
|
94
|
+
* Searches backwards from today up to maxDaysBack days
|
|
95
|
+
* @param {Firestore} db - Firestore instance
|
|
96
|
+
* @param {string} insightsCollection - Insights collection name
|
|
97
|
+
* @param {string} resultsSub - Results subcollection name
|
|
98
|
+
* @param {string} compsSub - Computations subcollection name
|
|
99
|
+
* @param {string} category - Category name
|
|
100
|
+
* @param {string} computationName - Computation name
|
|
101
|
+
* @param {string|number} userCid - User CID (for logging)
|
|
102
|
+
* @param {number} maxDaysBack - Maximum days to search backwards (default: 30)
|
|
103
|
+
* @returns {Promise<string|null>} - Date string (YYYY-MM-DD) or null if not found
|
|
104
|
+
*/
|
|
105
|
+
async function findLatestComputationDate(db, insightsCollection, resultsSub, compsSub, category, computationName, userCid, maxDaysBack = 30) {
|
|
106
|
+
const today = new Date();
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < maxDaysBack; i++) {
|
|
109
|
+
const checkDate = new Date(today);
|
|
110
|
+
checkDate.setDate(checkDate.getDate() - i);
|
|
111
|
+
const dateStr = checkDate.toISOString().split('T')[0];
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const computationRef = db.collection(insightsCollection)
|
|
115
|
+
.doc(dateStr)
|
|
116
|
+
.collection(resultsSub)
|
|
117
|
+
.doc(category)
|
|
118
|
+
.collection(compsSub)
|
|
119
|
+
.doc(computationName);
|
|
120
|
+
|
|
121
|
+
const computationDoc = await computationRef.get();
|
|
122
|
+
|
|
123
|
+
// Just check if document exists - don't check for CID here
|
|
124
|
+
// We'll check for CID in the calling function after decompression
|
|
125
|
+
if (computationDoc.exists) {
|
|
126
|
+
return dateStr; // Found document for this date
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
// Continue to next date if error
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return null; // No document found in the last maxDaysBack days
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Find the latest available date for Popular Investor rankings
|
|
139
|
+
* Searches backwards from today up to maxDaysBack days
|
|
140
|
+
* @param {Firestore} db - Firestore instance
|
|
141
|
+
* @param {string} rankingsCollection - Rankings collection name
|
|
142
|
+
* @param {number} maxDaysBack - Maximum days to search backwards (default: 30)
|
|
143
|
+
* @returns {Promise<string|null>} - Date string (YYYY-MM-DD) or null if not found
|
|
144
|
+
*/
|
|
145
|
+
async function findLatestRankingsDate(db, rankingsCollection, maxDaysBack = 30) {
|
|
146
|
+
const today = new Date();
|
|
147
|
+
|
|
148
|
+
for (let i = 0; i < maxDaysBack; i++) {
|
|
149
|
+
const checkDate = new Date(today);
|
|
150
|
+
checkDate.setDate(checkDate.getDate() - i);
|
|
151
|
+
const dateStr = checkDate.toISOString().split('T')[0];
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const rankingsRef = db.collection(rankingsCollection).doc(dateStr);
|
|
155
|
+
const rankingsDoc = await rankingsRef.get();
|
|
156
|
+
|
|
157
|
+
if (rankingsDoc.exists) {
|
|
158
|
+
return dateStr; // Found rankings for this date
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
// Continue to next date if error
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return null; // No rankings found in the last maxDaysBack days
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Find the latest available date for Popular Investor portfolio data
|
|
171
|
+
* Searches backwards from today up to maxDaysBack days
|
|
172
|
+
* @param {Firestore} db - Firestore instance
|
|
173
|
+
* @param {string} piPortfoliosCollection - PI portfolios collection name
|
|
174
|
+
* @param {string|number} userCid - User CID
|
|
175
|
+
* @param {number} maxDaysBack - Maximum days to search backwards (default: 30)
|
|
176
|
+
* @returns {Promise<string|null>} - Date string (YYYY-MM-DD) or null if not found
|
|
177
|
+
*/
|
|
178
|
+
async function findLatestPiPortfolioDate(db, piPortfoliosCollection, userCid, maxDaysBack = 30) {
|
|
179
|
+
const CANARY_BLOCK_ID = '19M';
|
|
180
|
+
const today = new Date();
|
|
181
|
+
|
|
182
|
+
for (let i = 0; i < maxDaysBack; i++) {
|
|
183
|
+
const checkDate = new Date(today);
|
|
184
|
+
checkDate.setDate(checkDate.getDate() - i);
|
|
185
|
+
const dateStr = checkDate.toISOString().split('T')[0];
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
const partsRef = db.collection(piPortfoliosCollection)
|
|
189
|
+
.doc(CANARY_BLOCK_ID)
|
|
190
|
+
.collection('snapshots')
|
|
191
|
+
.doc(dateStr)
|
|
192
|
+
.collection('parts');
|
|
193
|
+
|
|
194
|
+
const partsSnapshot = await partsRef.get();
|
|
195
|
+
|
|
196
|
+
// Check if user's CID exists in any part document
|
|
197
|
+
for (const partDoc of partsSnapshot.docs) {
|
|
198
|
+
const partData = partDoc.data();
|
|
199
|
+
if (partData && partData[String(userCid)]) {
|
|
200
|
+
return dateStr; // Found data for this date
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
// Continue to next date if error
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return null; // No data found in the last maxDaysBack days
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Find the latest available date for Popular Investor history data
|
|
214
|
+
* Searches backwards from today up to maxDaysBack days
|
|
215
|
+
* @param {Firestore} db - Firestore instance
|
|
216
|
+
* @param {string} piHistoryCollection - PI history collection name
|
|
217
|
+
* @param {string|number} userCid - User CID
|
|
218
|
+
* @param {number} maxDaysBack - Maximum days to search backwards (default: 30)
|
|
219
|
+
* @returns {Promise<string|null>} - Date string (YYYY-MM-DD) or null if not found
|
|
220
|
+
*/
|
|
221
|
+
async function findLatestPiHistoryDate(db, piHistoryCollection, userCid, maxDaysBack = 30) {
|
|
222
|
+
const today = new Date();
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < maxDaysBack; i++) {
|
|
225
|
+
const checkDate = new Date(today);
|
|
226
|
+
checkDate.setDate(checkDate.getDate() - i);
|
|
227
|
+
const dateStr = checkDate.toISOString().split('T')[0];
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
const historyRef = db.collection(piHistoryCollection)
|
|
231
|
+
.doc(String(userCid))
|
|
232
|
+
.collection('history')
|
|
233
|
+
.doc(dateStr);
|
|
234
|
+
|
|
235
|
+
const historyDoc = await historyRef.get();
|
|
236
|
+
|
|
237
|
+
if (historyDoc.exists) {
|
|
238
|
+
return dateStr; // Found history for this date
|
|
239
|
+
}
|
|
240
|
+
} catch (error) {
|
|
241
|
+
// Continue to next date if error
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return null; // No data found in the last maxDaysBack days
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
module.exports = {
|
|
250
|
+
findLatestPortfolioDate,
|
|
251
|
+
findLatestComputationDate,
|
|
252
|
+
findLatestRankingsDate,
|
|
253
|
+
findLatestPiPortfolioDate,
|
|
254
|
+
findLatestPiHistoryDate
|
|
255
|
+
};
|
|
256
|
+
|