Skip to content

Conversation

Zaimwa9
Copy link

@Zaimwa9 Zaimwa9 commented Sep 18, 2025

Closes #198

In this PR, we:

  • Add EvaluationResult getEvaluationResult(EvaluationContext context) and remove all of the old engine APIs.
  • Add support for JSONPath-enabled context values.
  • Add evaluationContext/mappers for engine-API data interop
  • Add script generate-engine-types to generate from flagsmith/sdk/evaluation-*-schema -> in pre-commit

Couple of questions concerning:

  • hide_disabled_flags deprecation => ready to remove the commented code
  • offlineHandler: It is wrapped between a wider getEnvironment that also includes getEnvironmentFromApi. I'm not seeing a huge value to migrate it but maybe I am missing something ? this would getEnvironmentFlagsFromDocument/getIdentityFlagsFromDocument -> getEnvironment -> this.offlineHandler.getEnvironment -> getEvaluationContext (using environment)
    Happy to change if misunderstood
    /**
     * Returns the current environment, fetching it from the API if needed.
     *
     * Calling this method concurrently while the environment is being fetched will not cause additional requests.
     */
    async getEnvironment(): Promise<EnvironmentModel> {
        if (this.offlineHandler) {
            return this.offlineHandler.getEnvironment();
        }
        if (this.environment) {
            return this.environment;
        }
        if (!this.environmentPromise) {
            this.environmentPromise = this.fetchEnvironment();
        }
        return this.environmentPromise;
    }

@Zaimwa9 Zaimwa9 requested a review from a team as a code owner September 18, 2025 15:50
@Zaimwa9 Zaimwa9 requested review from khvn26 and removed request for a team September 18, 2025 15:50
@Zaimwa9 Zaimwa9 changed the title feat: implement context values [DRAFT] feat: implement context values Sep 18, 2025
@Zaimwa9 Zaimwa9 changed the title [DRAFT] feat: implement context values feat: implement context values Sep 19, 2025
Segments
} from './evaluationContext.types.ts';

export type EnvironmentKey = EnvironmentContext['key'];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this manually to avoid relying on auto-generated redundant name keys:

export type Key1 = string;
/**
 * Key used for % split segmentation.
 */
export type Key2 = string;
/**

const { segments, segmentOverrides } = evaluateSegments(context);
const flags = evaluateFeatures(context, segmentOverrides);

// Not sure if we need this - Keeping till confirmed hidedisabledflags is remote evaluation only
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question here about hidedisabled-flags. can remove

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup — I believe this is cleared up now; we don't use the setting for local evaluation mode.

Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the PR looks solid to me — just a handful of comments to address.

/**
* A context object containing the necessary information to evaluate Flagsmith feature flags.
*/
export interface EvaluationContext {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to avoid the type duplication here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I created a joint model type at the root of evaluation folder. The idea being that:

  • All types used in the code must come from this evaluation/models.ts
  • If a type is needed from one generated file, it must be imported and re-exported from this entrypoint

const { segments, segmentOverrides } = evaluateSegments(context);
const flags = evaluateFeatures(context, segmentOverrides);

// Not sure if we need this - Keeping till confirmed hidedisabledflags is remote evaluation only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup — I believe this is cleared up now; we don't use the setting for local evaluation mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Context Values
2 participants