bulltrackers-module 1.0.559 → 1.0.560

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.
@@ -98,18 +98,60 @@ async function getSignedInUserPIPersonalizedMetrics(req, res, dependencies, conf
98
98
  try {
99
99
  const devOverride = await getDevOverride(db, userCid, config, logger);
100
100
 
101
+ // Also read raw Firestore data to check pretendToBePI value directly (in case of normalization issues)
102
+ let rawPretendToBePI = null;
103
+ if (devOverride && devOverride.enabled) {
104
+ try {
105
+ const devOverridesCollection = config.devOverridesCollection || 'dev_overrides';
106
+ const overrideDoc = await db.collection(devOverridesCollection).doc(String(userCid)).get();
107
+ if (overrideDoc.exists) {
108
+ const rawData = overrideDoc.data();
109
+ rawPretendToBePI = rawData.pretendToBePI; // Get raw value (could be false, true, undefined, etc.)
110
+ }
111
+ } catch (err) {
112
+ logger.log('WARN', `[getSignedInUserPIPersonalizedMetrics] Error reading raw dev override: ${err.message}`);
113
+ }
114
+ }
115
+
101
116
  // For PI-related checks, respect pretendToBePI flag
102
- // If pretendToBePI is false, use actual userCid even if impersonateCid is set
117
+ // If pretendToBePI is false (either normalized or raw), use actual userCid even if impersonateCid is set
103
118
  let effectiveCid;
104
- if (devOverride && devOverride.enabled && devOverride.pretendToBePI === false) {
105
- // User explicitly doesn't want to pretend to be a PI, use actual CID
119
+ let shouldCheckPI = true;
120
+
121
+ // Check if user explicitly doesn't want to pretend to be a PI
122
+ // Check both normalized value and raw value to be safe
123
+ const pretendToBePIValue = rawPretendToBePI !== undefined ? rawPretendToBePI : (devOverride ? devOverride.pretendToBePI : false);
124
+ const explicitlyNotPretending = pretendToBePIValue === false;
125
+
126
+ if (devOverride && devOverride.enabled && explicitlyNotPretending) {
127
+ // User explicitly doesn't want to pretend to be a PI
128
+ // Use actual CID and don't check PI status (user doesn't want to be treated as PI)
106
129
  effectiveCid = Number(userCid);
130
+ shouldCheckPI = false; // Skip PI check since user doesn't want to pretend to be PI
131
+
132
+ logger.log('INFO', `[getSignedInUserPIPersonalizedMetrics] DEV OVERRIDE: User ${userCid} has pretendToBePI=false (raw: ${rawPretendToBePI}, normalized: ${devOverride.pretendToBePI}), skipping PI check and returning 404`);
107
133
  } else {
108
134
  // Use normal effective CID logic (may use impersonateCid if set)
109
135
  effectiveCid = await getEffectiveCid(db, userCid, config, logger);
110
136
  }
111
137
 
112
- const isImpersonating = devOverride && devOverride.enabled && devOverride.impersonateCid && effectiveCid !== Number(userCid);
138
+ // Calculate isImpersonating based on whether we're actually using impersonation
139
+ // If pretendToBePI is false, we're not impersonating for PI purposes
140
+ // Only consider it impersonating if pretendToBePI is not explicitly false AND effectiveCid differs from userCid
141
+ const isImpersonating = shouldCheckPI &&
142
+ devOverride && devOverride.enabled && devOverride.impersonateCid &&
143
+ !explicitlyNotPretending && effectiveCid !== Number(userCid);
144
+
145
+ // If user explicitly doesn't want to pretend to be a PI, return 404 immediately
146
+ if (!shouldCheckPI) {
147
+ return res.status(404).json({
148
+ error: "Not a Popular Investor",
149
+ message: "This endpoint is only available for users who are Popular Investors",
150
+ effectiveCid: effectiveCid,
151
+ isImpersonating: false, // Not impersonating if pretendToBePI is false
152
+ actualCid: Number(userCid)
153
+ });
154
+ }
113
155
 
114
156
  // Check if user is a PI
115
157
  const rankEntry = await checkIfUserIsPI(db, effectiveCid, config, logger);
@@ -118,7 +160,8 @@ async function getSignedInUserPIPersonalizedMetrics(req, res, dependencies, conf
118
160
  error: "Not a Popular Investor",
119
161
  message: "This endpoint is only available for users who are Popular Investors",
120
162
  effectiveCid: effectiveCid,
121
- isImpersonating: isImpersonating || false
163
+ isImpersonating: isImpersonating || false,
164
+ actualCid: Number(userCid)
122
165
  });
123
166
  }
124
167
 
@@ -355,7 +398,8 @@ async function getSignedInUserPIPersonalizedMetrics(req, res, dependencies, conf
355
398
  isFallback: foundDate !== today,
356
399
  daysBackFromLatest: checkedDates.indexOf(foundDate),
357
400
  isImpersonating: isImpersonating || false,
358
- actualCid: Number(userCid)
401
+ actualCid: Number(userCid),
402
+ pretendToBePI: devOverride && devOverride.enabled ? (devOverride.pretendToBePI || false) : false
359
403
  });
360
404
 
361
405
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.559",
3
+ "version": "1.0.560",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [