bulltrackers-module 1.0.552 → 1.0.554

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.
@@ -10,9 +10,9 @@ const { processAlertForPI, readComputationResults, readComputationResultsWithSha
10
10
  * Pub/Sub trigger handler for alert generation
11
11
  * Expected message format:
12
12
  * {
13
- * date: "2025-12-27",
14
- * computationName: "PiRiskIncrease",
15
- * documentPath: "unified_insights/2025-12-27/results/popular-investor/computations/PiRiskIncrease"
13
+ * date: "2025-12-27",
14
+ * computationName: "PiRiskIncrease",
15
+ * documentPath: "unified_insights/2025-12-27/results/popular-investor/computations/PiRiskIncrease"
16
16
  * }
17
17
  */
18
18
  async function handleAlertTrigger(message, context, config, dependencies) {
@@ -130,30 +130,40 @@ async function handleAlertTrigger(message, context, config, dependencies) {
130
130
  * Firestore trigger function for alert generation
131
131
  * Triggered when computation results are written to:
132
132
  * unified_insights/{date}/results/{category}/computations/{computationName}
133
- *
134
- * Handles sharded data by checking _shards subcollection if _sharded === true
133
+ * * Handles sharded data by checking _shards subcollection if _sharded === true
135
134
  */
136
135
  async function handleComputationResultWrite(change, context, config, dependencies) {
137
136
  const { db, logger } = dependencies;
138
-
139
- // Extract path parameters from the document path
140
- // Path format: unified_insights/{date}/results/{category}/computations/{computationName}
141
- const resource = context.resource || change.after.ref.path;
142
- const pathParts = resource.split('/');
143
-
144
- // Find indices of key path segments
145
- const dateIndex = pathParts.indexOf('unified_insights') + 1;
146
- const categoryIndex = pathParts.indexOf('results') + 1;
147
- const computationIndex = pathParts.indexOf('computations') + 1;
148
-
149
- if (dateIndex === 0 || categoryIndex === 0 || computationIndex === 0) {
150
- logger.log('WARN', `[AlertTrigger] Invalid document path format: ${resource}`);
151
- return;
137
+
138
+ // --- PATH RESOLUTION LOGIC ---
139
+ // 1. Try to use context.params (Preferred for Gen 2 & Wildcards)
140
+ // The 'contextShim' in your root index.js passes 'event.params' into here.
141
+ let { date, category, computationName } = context.params || {};
142
+
143
+ // 2. Fallback: Parse from resource string (Legacy / Backup)
144
+ if (!date || !computationName) {
145
+ const resource = context.resource || (change.after && change.after.ref.path) || '';
146
+
147
+ // Simple split logic can fail on full resource URIs (e.g. //firestore.googleapis.com/...)
148
+ // so we look for specific keywords to anchor the split.
149
+ const pathParts = resource.split('/');
150
+
151
+ const dateIndex = pathParts.indexOf('unified_insights') + 1;
152
+ const categoryIndex = pathParts.indexOf('results') + 1;
153
+ const computationIndex = pathParts.indexOf('computations') + 1;
154
+
155
+ if (dateIndex > 0 && categoryIndex > 0 && computationIndex > 0) {
156
+ date = pathParts[dateIndex];
157
+ category = pathParts[categoryIndex];
158
+ computationName = pathParts[computationIndex];
159
+ }
160
+ }
161
+
162
+ // 3. Validation
163
+ if (!date || !category || !computationName) {
164
+ logger.log('WARN', `[AlertTrigger] Could not resolve path params. Resource: ${context.resource}`);
165
+ return;
152
166
  }
153
-
154
- const date = pathParts[dateIndex];
155
- const category = pathParts[categoryIndex];
156
- const computationName = pathParts[computationIndex];
157
167
 
158
168
  // Only process if document was created or updated (not deleted)
159
169
  if (!change.after.exists) {
@@ -169,9 +179,9 @@ async function handleComputationResultWrite(change, context, config, dependencie
169
179
  return;
170
180
  }
171
181
 
172
- // Only process popular-investor category computations
173
- if (category !== 'popular-investor') {
174
- logger.log('DEBUG', `[AlertTrigger] Not popular-investor category: ${category}`);
182
+ // [FIX] Allow both 'popular-investor' (for profile metrics) AND 'alerts' (for actual alerts)
183
+ if (category !== 'popular-investor' && category !== 'alerts') {
184
+ logger.log('DEBUG', `[AlertTrigger] Skipping irrelevant category: ${category}`);
175
185
  return;
176
186
  }
177
187
 
@@ -440,5 +450,4 @@ module.exports = {
440
450
  handleAlertTrigger,
441
451
  handleComputationResultWrite,
442
452
  checkAndSendAllClearNotifications
443
- };
444
-
453
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.552",
3
+ "version": "1.0.554",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [