Extra per-request options for using the high-level SDK's evaluateBatch method.

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

Type Parameters

  • Res

Hierarchy (view full)

Properties

fallback?: boolean

Fall back to sequential evaluate calls if server doesn't support batch API.

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,
},
);
rejectMixed?: boolean

With rejectMixed set, a batch result that contains any errors causes a Promise rejection.

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.

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.