interface TransactionContextPropagator {
    getTransactionContext(): EvaluationContext;
    setTransactionContext<TArgs, R>(transactionContext: EvaluationContext, callback: ((...args: TArgs) => R), ...args: TArgs): void;
}

Hierarchy (view full)

Implemented by

Methods

  • Sets the transaction context using the registered transaction context propagator. Runs the callback function, in which the transactionContext will be available by calling this#getTransactionContext.

    The TransactionContextPropagator must persist the transactionContext and make it available to callback via this#getTransactionContext.

    The precedence of merging context can be seen in the specification.

    Example:

    app.use((req: Request, res: Response, next: NextFunction) => {
    const ip = res.headers.get("X-Forwarded-For")
    OpenFeature.setTransactionContext({ targetingKey: req.user.id, ipAddress: ip }, () => {
    // The transaction context is used in any flag evaluation throughout the whole call chain of next
    next();
    });
    })

    Type Parameters

    • TArgs extends unknown[]

      The optional args passed to the callback function

    • R

      The return value of the callback

    Parameters

    • transactionContext: EvaluationContext

      The transaction specific context

    • callback: ((...args: TArgs) => R)

      Callback function to run

        • (...args): R
        • Parameters

          Returns R

    • Rest...args: TArgs

      Optional arguments that are passed to the callback function

    Returns void