@@ -14,11 +14,12 @@ import type { EvaluationContext, JsonValue, PrimitiveValue } from '../types';
1414
1515// TODO(FFL-2837): Replace this legacy UFC v1 alias with
1616// `NonNullable<FlagsConfiguration['rules']>['response']` after a flagging-core
17- // release contains DataDog/openfeature-js-client#344 through `03cde21` and
18- // restores 32-byte SHA digest validation. Keep the `FlagsConfiguration` type
17+ // release contains DataDog/openfeature-js-client#344 through `5a5511e`.
18+ // Keep the `FlagsConfiguration` type
1919// import on the flagging-core package root. PR #344 preserves protobuf integers
2020// as `bigint`, does not call global `BigInt` during safe conversion, and reports
21- // unsafe conversions as deterministic per-flag `PARSE_ERROR` results.
21+ // unsafe conversions and malformed SHA digests as deterministic per-flag
22+ // `PARSE_ERROR` results.
2223type RulesConfigurationResponse = UniversalFlagConfigurationV1 ;
2324
2425export type RulesValueType = 'boolean' | 'string' | 'number' | 'object' ;
@@ -119,18 +120,27 @@ export const toRulesEvaluationContext = (
119120 attributes . set ( key , value ) ;
120121 }
121122
122- return {
123- ...Object . fromEntries ( attributes ) ,
124- targetingKey : context . targetingKey
125- } ;
123+ // TODO(FFL-2837): Delete the inherited-name shadows after a flagging-core
124+ // release contains DataDog/openfeature-js-client#344 through `aa93230` and
125+ // this adapter uses its generated protobuf evaluator. That evaluator uses
126+ // own-property lookup for condition and shard context attributes.
127+ const rulesContext = Object . create ( null ) as RulesEvaluationContext ;
128+ for ( const key of Object . getOwnPropertyNames ( Object . prototype ) ) {
129+ rulesContext [ key ] = undefined ;
130+ }
131+ for ( const [ key , value ] of attributes ) {
132+ rulesContext [ key ] = value ;
133+ }
134+ rulesContext . targetingKey = context . targetingKey ;
135+
136+ return rulesContext ;
126137} ;
127138
128139const hasOwn = ( value : object , key : PropertyKey ) : boolean =>
129140 Object . prototype . hasOwnProperty . call ( value , key ) ;
130141
131142// TODO(FFL-2837): Delete this compatibility error store after a flagging-core
132- // release contains DataDog/openfeature-js-client#344 through `03cde21` and the
133- // required SHA digest validation follow-up.
143+ // release contains DataDog/openfeature-js-client#344 through `5a5511e`.
134144// The generated protobuf evaluator validates the requested flag and the data
135145// that evaluation reaches. It does not build this error map during parsing.
136146// It returns deterministic `PARSE_ERROR` results, including for an integer that
@@ -209,7 +219,7 @@ const validateCondition = (value: unknown): string | undefined => {
209219 try {
210220 // TODO(FFL-2837): Define a bounded regular expression policy before
211221 // dynamic offline rules leave draft state. Upstream PR #344 through
212- // `03cde21 ` compiles protobuf regular expressions lazily and caches
222+ // `5a5511e ` compiles protobuf regular expressions lazily and caches
213223 // them by configuration and index, but it does not limit patterns.
214224 RegExp ( value . value ) ; // dd-iac-scan ignore-line
215225 } catch {
@@ -464,8 +474,7 @@ export const prepareRulesConfiguration = (
464474 const clone = cloneValue ( value ) ;
465475
466476 // TODO(FFL-2837): Delete this legacy JSON clone and validator after a
467- // flagging-core release contains upstream PR #344 through `03cde21` and the
468- // required SHA digest validation follow-up. That
477+ // flagging-core release contains upstream PR #344 through `5a5511e`. That
469478 // implementation preserves protobuf integers as `bigint` and validates only
470479 // the requested flag data that evaluation reaches. It does not call global
471480 // `BigInt` when it returns a deterministic per-flag error for an unsafe number.
@@ -520,7 +529,7 @@ const normalizeVariationType = (
520529
521530// TODO(FFL-2837): Delete this legacy UFC v1 metadata fallback after the
522531// flagging-core dependency contains DataDog/openfeature-js-client#344 through
523- // `03cde21 `. The protobuf evaluator maps only safely represented integer
532+ // `5a5511e `. The protobuf evaluator maps only safely represented integer
524533// variations, and all numeric variations, to the OpenFeature type `number`.
525534const recoverVariationType = (
526535 configuration : RulesConfigurationResponse ,
@@ -547,7 +556,7 @@ export const flaggingCoreRulesEngine: RulesEngine = {
547556
548557 // TODO(FFL-2837): Delete this local compatibility guard after the
549558 // flagging-core dependency contains DataDog/openfeature-js-client#344
550- // through `03cde21 `. Keep the reserved-name contract tests.
559+ // through `5a5511e `. Keep the reserved-name contract tests.
551560 if ( ! hasOwn ( flags , request . flagKey ) ) {
552561 return {
553562 value : request . defaultValue ,
@@ -558,7 +567,7 @@ export const flaggingCoreRulesEngine: RulesEngine = {
558567 }
559568
560569 // TODO(FFL-2837): Delete this compatibility check with the local error
561- // store after the published PR #344 evaluator through `03cde21 ` validates
570+ // store after the published PR #344 evaluator through `5a5511e ` validates
562571 // reached flag data and reports deterministic flag-scoped errors, including
563572 // unsupported feature levels and unsafe integer conversions with and
564573 // without global `BigInt` when supported.
0 commit comments