bulltrackers-module 1.0.23 → 1.0.24

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.
@@ -398,7 +398,7 @@ async function getSpeculatorsToUpdate(dateThreshold, gracePeriodThreshold, specu
398
398
  }
399
399
 
400
400
  module.exports = {
401
- getLatestNormalUserPortfolios, // Export new function
401
+ getLatestNormalUserPortfolios,
402
402
  resetProxyLocks,
403
403
  getBlockCapacities,
404
404
  getExclusionIds,
@@ -4,14 +4,12 @@
4
4
 
5
5
  const firestoreUtils = require('./firestore_utils');
6
6
  const pubsubUtils = require('./pubsub_utils');
7
- const loggingWrapper = require('./logging_wrapper');
8
- const { IntelligentHeaderManager } = require('./intelligent_header_manager'); // <-- ADD
9
- const { IntelligentProxyManager } = require('./intelligent_proxy_manager'); // <-- ADD
7
+ const { IntelligentHeaderManager } = require('./intelligent_header_manager');
8
+ const { IntelligentProxyManager } = require('./intelligent_proxy_manager');
10
9
 
11
10
  module.exports = {
12
11
  firestore: firestoreUtils,
13
12
  pubsub: pubsubUtils,
14
- logging: loggingWrapper,
15
- IntelligentHeaderManager, // <-- ADD
16
- IntelligentProxyManager, // <-- ADD
13
+ IntelligentHeaderManager,
14
+ IntelligentProxyManager,
17
15
  };
@@ -61,7 +61,7 @@ class IntelligentHeaderManager {
61
61
 
62
62
  this.headers = snapshot.docs.map(doc => ({
63
63
  id: doc.id,
64
- data: doc.data().header, // Assuming header object is stored in 'header' field
64
+ data: doc.data().header,
65
65
  performance: {
66
66
  total: doc.data().totalRequests || 0,
67
67
  success: doc.data().successfulRequests || 0
@@ -62,7 +62,7 @@ class IntelligentProxyManager {
62
62
 
63
63
  // 1. Initialize all known proxies from config
64
64
  for (const url of this.proxyUrls) {
65
- const owner = new URL(url).hostname; // Or derive a unique ID differently
65
+ const owner = new URL(url).hostname;
66
66
  tempProxyStatus[owner] = { owner, url, status: 'unlocked' }; // Default to unlocked
67
67
  }
68
68
 
@@ -47,7 +47,7 @@ exports.fetchAndStorePrices = async (firestore, logger, headerManager, proxyMana
47
47
  // Apply specific headers required by this endpoint
48
48
  const apiHeaders = {
49
49
  "accept": "application/json, text/plain, */*",
50
- "accept-encoding": "gzip, deflate, br, zstd", // Proxy might handle this, but include for safety
50
+ "accept-encoding": "gzip, deflate, br, zstd", // To shrink the response size
51
51
  "accept-language": "en-US,en;q=0.9",
52
52
  "origin": "https://www.etoro.com",
53
53
  "referer": "https://www.etoro.com/",
@@ -110,7 +110,7 @@ exports.fetchAndStorePrices = async (firestore, logger, headerManager, proxyMana
110
110
  batchCount = 0;
111
111
 
112
112
  // Optional: Add a small delay between large batch commits if needed
113
- // await new Promise(resolve => setTimeout(resolve, 50));
113
+ await new Promise(resolve => setTimeout(resolve, 50));
114
114
  }
115
115
  }
116
116
  }
@@ -36,7 +36,6 @@ async function handleDiscover(task, taskId, clients, config) {
36
36
  const publicUsers = await response.json();
37
37
  if (!Array.isArray(publicUsers)) return;
38
38
 
39
- // --- REFACTORED FILTERING & CHAINING ---
40
39
  const oneMonthAgo = new Date();
41
40
  oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1);
42
41
 
@@ -111,8 +110,7 @@ async function handleDiscover(task, taskId, clients, config) {
111
110
  logger.log('INFO', `[DISCOVER] Verification message published was : ${JSON.stringify(verificationTask)} `);
112
111
  logger.log('INFO', `[DISCOVER] Chaining to 'verify' task for ${finalActiveUsers.length} active users.`);
113
112
  }
114
- // --- END REFACTORED LOGIC ---
115
-
113
+
116
114
  } finally {
117
115
  if (selectedHeader) clients.headerManager.updatePerformance(selectedHeader.id, wasSuccess);
118
116
  }
@@ -55,14 +55,8 @@ async function handleUpdate(task, taskId, clients, config) {
55
55
  const today = new Date().toISOString().slice(0, 10);
56
56
  const blockId = `${Math.floor(parseInt(userId) / 1000000)}M`;
57
57
 
58
- // Use the batch manager to add portfolio data
58
+ // Use the batch manager to add portfolio data and update timestamp
59
59
  await clients.batchManager.addToPortfolioBatch(userId, blockId, today, portfolioData, userType, instrumentId);
60
-
61
- // --- DEPRECATED LOGIC ---
62
- // The PreCompute system is deprecated. All related logic is removed.
63
- // --- END DEPRECATED LOGIC ---
64
-
65
- // Use the batch manager to update the timestamp
66
60
  await clients.batchManager.updateUserTimestamp(userId, userType, instrumentId);
67
61
 
68
62
  } finally {
@@ -208,7 +208,6 @@ class FirestoreBatchManager {
208
208
  promises.push(...deletePromises);
209
209
  }
210
210
  }
211
- // --- End new logic ---
212
211
 
213
212
  if (batchOperationCount > 0) {
214
213
  promises.push(firestoreBatch.commit());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -1,56 +0,0 @@
1
- /**
2
- * @fileoverview Wrappers for Cloud Functions and logic stages for consistent logging and error handling.
3
- */
4
-
5
- // Placeholder for a potential shared logger instance if needed
6
- // const { logger } = require('shared-logger-package'); // Example
7
-
8
- /**
9
- * Wraps an entire HTTP Cloud Function for standardized logging and response handling.
10
- * @async
11
- * @param {string} functionName - The name of the Cloud Function.
12
- * @param {Function} logicCallback - The async function containing the core logic.
13
- * @returns {Function} An Express middleware function.
14
- */
15
- function handleCloudFunction(functionName, logicCallback) {
16
- return async (req, res) => {
17
- console.log(`[${functionName}] Function triggered.`); // Replace with actual logger
18
- try {
19
- await logicCallback(req, res); // Pass req and res if needed by the logic
20
- if (!res.headersSent) {
21
- console.log(`[${functionName}] Function completed successfully.`);
22
- res.status(200).send(`${functionName} completed.`);
23
- }
24
- } catch (error) {
25
- console.error(`[${functionName}] FATAL Error: ${error.message}`, error.stack); // Replace with actual logger
26
- if (!res.headersSent) {
27
- res.status(500).send(`Internal Server Error in ${functionName}.`);
28
- }
29
- }
30
- };
31
- }
32
-
33
- /**
34
- * Wraps a specific stage within a Cloud Function's logic for logging start/end and errors.
35
- * @async
36
- * @param {string} stageName - A descriptive name for the stage.
37
- * @param {Function} logicCallback - The async function containing the stage's logic.
38
- * @returns {Promise<any>} The result of the logicCallback.
39
- * @throws Will re-throw any errors caught during the stage execution.
40
- */
41
- async function handleLogicStage(stageName, logicCallback) {
42
- console.log(`[Stage: ${stageName}] Starting...`); // Replace with actual logger
43
- try {
44
- const result = await logicCallback();
45
- console.log(`[Stage: ${stageName}] Completed successfully.`); // Replace with actual logger
46
- return result;
47
- } catch (error) {
48
- console.error(`[Stage: ${stageName}] Error: ${error.message}`, error.stack); // Replace with actual logger
49
- throw error; // Re-throw to allow the main handler to catch it
50
- }
51
- }
52
-
53
- module.exports = {
54
- handleCloudFunction,
55
- handleLogicStage,
56
- };