Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: server overrides #221

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

greghuels
Copy link
Contributor

@greghuels greghuels commented Feb 19, 2025

Fixes: FF-3995

Motivation and Context

Allows users to override server-side flags by providing new parseOverrides and withOverrides functions to the EppoClient.

  • parseOverrides - Allows users to parse the x-eppo-overrides header sent by web requests. Eppo's Chrome extension will intercept and append this header to all https endpoints for the target site.
  • withOverrides - Creates an EppoClient instance that has overrides applied so that it doesn't affect the behavior of the original EppoClient singleton on a shared Node web server.

Typical usage will be something like this:

export const eppoOverridesStorage = new AsyncLocalStorage<Record<FlagKey, Variation>>();

@Injectable()
export class EppoOverridesMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    getInstance()
      .parseOverrides(req.headers['X-EPPO-OVERRIDES'] as string | undefined)
      .then((overrides) => eppoOverridesStorage.run(overrides, next))
      .catch(next);
  }
}

export const getEppoInstance = () => {
  const overrides = eppoOverridesStorage.getStore();
  return EppoSDK.getInstance().withOverrides(overrides);
};

How has this been tested?

  • Manual QA
  • TODO: Additional unit testing

@greghuels greghuels added the enhancement New feature or request label Feb 19, 2025
Base automatically changed from yf-overrides to main February 19, 2025 18:25
@greghuels greghuels force-pushed the greg/FF-3995/server-overrides branch from 9ec6076 to b181bd4 Compare February 19, 2025 18:52
Comment on lines +59 to +68
private async sendValidationRequest(overrideApiKey: string) {
const response = await fetch(EPPO_API_URL, {
headers: {
'X-Eppo-Token': overrideApiKey,
'Content-Type': 'application/json',
},
});
if (response.status !== 200) {
throw new Error(`Unable to authorize API token: ${response.statusText}`);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The final version of this will hit a new endpoint that validates the "browser extension" key

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

Successfully merging this pull request may close these issues.

1 participant