@forge/bridge

5.15.2-next.0-experimental-5b726e65.16.0-next.1
out/featureFlags/evaluator.js
~out/featureFlags/evaluator.jsModified
+11−2
Index: package/out/featureFlags/evaluator.js
===================================================================
--- package/out/featureFlags/evaluator.js
+++ package/out/featureFlags/evaluator.js
@@ -6,48 +6,57 @@
         this.results = results;
     }
     checkFlag(flagName, defaultValue) {
         if (!this.results || !this.results.feature_flags) {
+            // fallback to default value
             return defaultValue;
         }
         const featureFlags = this.results.feature_flags;
         let hashedValue = '';
         try {
             hashedValue = this.getHashedValue(flagName);
         }
         catch (err) {
+            // eslint-disable-next-line no-console
             console.error('Unexpected error occurred while evaluating flag ', err);
+            // If hashing fails for any reason, do not throw; safely return default
             return defaultValue;
         }
         if (!hashedValue) {
             return defaultValue;
         }
         const evaluatedFlag = featureFlags[hashedValue];
         if (evaluatedFlag) {
+            // if flag being checked is disabled
             if (evaluatedFlag.disabled) {
                 return false;
             }
             return evaluatedFlag.value;
         }
+        // fallback to default value
         return defaultValue;
     }
     shutDown() {
         this.results = undefined;
     }
+    // To be Updated with proper hashing function
     getHashedValue(flagName) {
+        // Defensive: ensure stable, non-throwing behavior for unexpected inputs
         if (typeof flagName !== 'string') {
             return '';
         }
         const input = flagName.trim();
         if (input.length === 0) {
             return '';
         }
+        // djb2 hashing (unsigned 32-bit), matches server-side encoding
         let hash = 5381;
         for (let i = 0; i < input.length; i += 1) {
             const charCode = input.charCodeAt(i);
-            hash = (hash << 5) + hash + charCode;
-            hash |= 0;
+            hash = (hash << 5) + hash + charCode; // hash * 33 + c
+            hash |= 0; // force 32-bit signed int
         }
+        // Convert to unsigned 32-bit and return as a decimal string
         return (hash >>> 0).toString();
     }
 }
 exports.Evaluator = Evaluator;