Open Policy Agent TypeScript Packages
    Preparing search index...

    Interface RequestOptions<Res>

    Extra per-request options for using the high-level SDK's evaluation methods (evaluate, evaluateDefault).

    interface RequestOptions<Res> {
        fetchOptions?: Omit<RequestInit, "method" | "body">;
        fromResult?: (res?: Result) => Res;
        retries?: RetryConfig;
        retryCodes?: string[];
        serverURL?: string | URL;
        timeoutMs?: number;
    }

    Type Parameters

    • Res

    Hierarchy (View Summary)

    Index

    Properties

    fetchOptions?: Omit<RequestInit, "method" | "body">

    Sets various request options on the fetch call made by an SDK method.

    fromResult?: (res?: Result) => Res

    fromResult allows you to provide a function to convert the generic Result type into another type

    Assuming that your policy evaluates to an object like {"allowed": true}, this fromResult function would let you convert it to a boolean:

    const res = await new OPAClient(serverURL).evaluate<any, boolean>(
    "policy/result",
    { action: "read" },
    {
    fromResult: (r?: Result) => (r as Record<string, any>)["allowed"] ?? false,
    },
    );
    retries?: RetryConfig

    Set or override a retry policy on HTTP calls.

    retryCodes?: string[]

    Specifies the status codes which should be retried using the given retry policy.

    serverURL?: string | URL

    Overrides the base server URL that will be used by an operation.

    timeoutMs?: number

    Sets a timeout, in milliseconds, on HTTP requests made by an SDK method. If fetchOptions.signal is set then it will take precedence over this option.