bulltrackers-module 1.0.752 → 1.0.753

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.
@@ -16,6 +16,9 @@ const QUEUE_NAME = process.env.ORCHESTRATOR_QUEUE || 'task-engine-queue';
16
16
  const LOCATION = process.env.GCP_REGION || 'europe-west1';
17
17
  const PROJECT = process.env.GCP_PROJECT_ID;
18
18
 
19
+ // --- FEATURE FLAG: Disable Normal/Speculator Users ---
20
+ const ENABLE_LEGACY_USERS = process.env.ENABLE_LEGACY_USERS === 'true';
21
+
19
22
  /**
20
23
  * ENTRY POINT: HTTP Handler for Workflow Interaction
21
24
  */
@@ -33,6 +36,14 @@ async function handleOrchestratorHttp(req, res, dependencies, config) {
33
36
  throw new Error("Missing userType or date for PLAN action");
34
37
  }
35
38
 
39
+ // --- NEW: Block Legacy Users if Disabled ---
40
+ if ((userType === 'normal' || userType === 'speculator') && !ENABLE_LEGACY_USERS) {
41
+ const msg = `[Orchestrator] SKIPPING PLAN for '${userType}': ENABLE_LEGACY_USERS is false.`;
42
+ logger.log('WARN', msg);
43
+ // Return 200 to prevent retry loops in workflows
44
+ return res.status(200).send({ status: 'skipped', message: msg });
45
+ }
46
+
36
47
  // Determine self-URL for callback (Cloud Task needs to call this function back)
37
48
  // We use the env var passed by GCF (FUNCTION_URI) or construct it manually
38
49
  const orchestratorUrl = orchestratorUrlOverride ||
@@ -47,6 +58,14 @@ async function handleOrchestratorHttp(req, res, dependencies, config) {
47
58
  if (!planId || !windowId) {
48
59
  throw new Error("Missing planId or windowId for EXECUTE_WINDOW action");
49
60
  }
61
+
62
+ // --- NEW: Block Legacy Users if Disabled (Double Check) ---
63
+ if ((userType === 'normal' || userType === 'speculator') && !ENABLE_LEGACY_USERS) {
64
+ const msg = `[Orchestrator] SKIPPING EXECUTE_WINDOW for '${userType}': ENABLE_LEGACY_USERS is false.`;
65
+ logger.log('WARN', msg);
66
+ return res.status(200).send({ status: 'skipped', message: msg });
67
+ }
68
+
50
69
  const result = await executeUpdateWindow(planId, windowId, userType, config, dependencies);
51
70
  res.status(200).send(result);
52
71
 
@@ -227,8 +246,13 @@ async function runDiscoveryOrchestrator(config, deps) {
227
246
  const { logger, firestoreUtils } = deps;
228
247
  logger.log('INFO', '🚀 Discovery Orchestrator triggered...');
229
248
  await firestoreUtils.resetProxyLocks(deps, config);
230
- if (isUserTypeEnabled('normal', config.enabledUserTypes)) await runDiscovery('normal', config.discoveryConfig.normal, config, deps);
231
- if (isUserTypeEnabled('speculator', config.enabledUserTypes)) await runDiscovery('speculator', config.discoveryConfig.speculator, config, deps);
249
+
250
+ if (ENABLE_LEGACY_USERS) {
251
+ if (isUserTypeEnabled('normal', config.enabledUserTypes)) await runDiscovery('normal', config.discoveryConfig.normal, config, deps);
252
+ if (isUserTypeEnabled('speculator', config.enabledUserTypes)) await runDiscovery('speculator', config.discoveryConfig.speculator, config, deps);
253
+ } else {
254
+ logger.log('INFO', 'Discovery skipped for legacy users (normal/speculator) because ENABLE_LEGACY_USERS is false.');
255
+ }
232
256
  }
233
257
 
234
258
  async function runUpdateOrchestrator(config, deps) {
@@ -237,8 +261,13 @@ async function runUpdateOrchestrator(config, deps) {
237
261
  await firestoreUtils.resetProxyLocks(deps, config);
238
262
  const enabledTypes = config.enabledUserTypes || [];
239
263
 
240
- if (isUserTypeEnabled('normal', enabledTypes)) await runUpdates('normal', config.updateConfig, config, deps);
241
- if (isUserTypeEnabled('speculator', enabledTypes)) await runUpdates('speculator', config.updateConfig, config, deps);
264
+ if (ENABLE_LEGACY_USERS) {
265
+ if (isUserTypeEnabled('normal', enabledTypes)) await runUpdates('normal', config.updateConfig, config, deps);
266
+ if (isUserTypeEnabled('speculator', enabledTypes)) await runUpdates('speculator', config.updateConfig, config, deps);
267
+ } else {
268
+ logger.log('INFO', 'Updates skipped for legacy users (normal/speculator) because ENABLE_LEGACY_USERS is false.');
269
+ }
270
+
242
271
  if (isUserTypeEnabled('popular_investor', enabledTypes)) {
243
272
  const piConfig = { ...config.updateConfig, popularInvestorRankingsCollection: config.updateConfig.popularInvestorRankingsCollection || 'popular_investor_rankings' };
244
273
  await runUpdates('popular_investor', piConfig, config, deps);
@@ -0,0 +1,73 @@
1
+ #!/bin/bash
2
+
3
+ # ==============================================================================
4
+ # BULLTRACKERS TASK ENGINE END-TO-END TESTER
5
+ # This script triggers the Orchestrator to plan an immediate execution window.
6
+ # ==============================================================================
7
+
8
+ # --- CONFIGURATION ---
9
+ FUNCTION_NAME="orchestrator-http"
10
+ REGION="europe-west1"
11
+ DATE=$(date +%Y-%m-%d) # Defaults to today
12
+ USER_TYPE="normal" # Options: normal, speculator, popular_investor
13
+ WINDOWS=1 # 1 window = immediate execution (0s delay)
14
+
15
+ # --- 1. FETCH URL DYNAMICALLY ---
16
+ echo "🔍 Fetching URL for function: $FUNCTION_NAME ($REGION)..."
17
+
18
+ # Try Gen 2 (Cloud Run) URL first
19
+ URL=$(gcloud functions describe $FUNCTION_NAME --region=$REGION --format='value(serviceConfig.uri)' 2>/dev/null)
20
+
21
+ # Fallback to Gen 1 if empty
22
+ if [ -z "$URL" ]; then
23
+ URL=$(gcloud functions describe $FUNCTION_NAME --region=$REGION --format='value(httpsTrigger.url)' 2>/dev/null)
24
+ fi
25
+
26
+ if [ -z "$URL" ]; then
27
+ echo "❌ Error: Could not find URL for function '$FUNCTION_NAME'. Check if it is deployed."
28
+ exit 1
29
+ fi
30
+
31
+ echo "✅ Target URL: $URL"
32
+
33
+ # --- 2. GET AUTH TOKEN ---
34
+ echo "🔑 Generating Identity Token..."
35
+ TOKEN=$(gcloud auth print-identity-token)
36
+
37
+ if [ -z "$TOKEN" ]; then
38
+ echo "❌ Error: Could not generate token. Run 'gcloud auth login' first."
39
+ exit 1
40
+ fi
41
+
42
+ # --- 3. SEND REQUEST ---
43
+ echo "🚀 Triggering Plan for $USER_TYPE on $DATE ($WINDOWS window)..."
44
+
45
+ RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$URL" \
46
+ -H "Authorization: Bearer $TOKEN" \
47
+ -H "Content-Type: application/json" \
48
+ -d "{
49
+ \"action\": \"PLAN\",
50
+ \"userType\": \"$USER_TYPE\",
51
+ \"date\": \"$DATE\",
52
+ \"windows\": $WINDOWS
53
+ }")
54
+
55
+ # --- 4. PARSE RESPONSE ---
56
+ HTTP_BODY=$(echo "$RESPONSE" | head -n -1)
57
+ HTTP_CODE=$(echo "$RESPONSE" | tail -n 1)
58
+
59
+ if [ "$HTTP_CODE" -eq 200 ]; then
60
+ echo ""
61
+ echo "✅ SUCCESS (HTTP 200)"
62
+ echo "---------------------------------------------------"
63
+ echo "$HTTP_BODY" | python3 -m json.tool 2>/dev/null || echo "$HTTP_BODY"
64
+ echo "---------------------------------------------------"
65
+ echo "👉 Monitor 'task-engine-queue' in Cloud Tasks Console."
66
+ echo "👉 Check Logs Explorer for 'Orchestrator' and 'Dispatcher'."
67
+ else
68
+ echo ""
69
+ echo "❌ FAILED (HTTP $HTTP_CODE)"
70
+ echo "---------------------------------------------------"
71
+ echo "$HTTP_BODY"
72
+ echo "---------------------------------------------------"
73
+ fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.752",
3
+ "version": "1.0.753",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [