import { SDKOptions } from "./lib/config.js"; import { RequestOptions as FetchOptions } from "./lib/sdks.js"; import { CompileQueryWithPartialEvaluationAcceptEnum } from "./sdk/index.js"; import { CompileOptions, type Input, type Result, type ServerErrorWithStatusCode, type SuccessfulPolicyResponse } from "./sdk/models/components/index.js"; export type { Input, Result }; /** * Implement `ToInput` to declare how your provided input is to be converted * into the API request payload's "input". */ export interface ToInput { toInput(): Input; } /** Extra options for using the high-level SDK. */ export type Options = { headers?: Record; sdk?: SDKOptions; }; /** Extra per-request options for using the high-level SDK's * evaluation methods ({@link OPAClient.evaluate | evaluate}, * {@link OPAClient.evaluateDefault | evaluateDefault}). */ export interface RequestOptions extends FetchOptions { /** fromResult allows you to provide a function to convert the generic `Result` type into another type * * @example Convert a response to boolean * Assuming that your policy evaluates to an object like `{"allowed": true}`, * this `fromResult` function would let you convert it to a boolean: * * ```ts * const res = await new OPAClient(serverURL).evaluate( * "policy/result", * { action: "read" }, * { * fromResult: (r?: Result) => (r as Record)["allowed"] ?? false, * }, * ); * ``` */ fromResult?: (res?: Result) => Res; } /** Extra per-request options for using the high-level SDK's * filter method ({@link OPAClient.getFilters | getFilters }. */ export interface FiltersRequestOptions extends FiltersOptions { /** * The compilation target for translating a policy into queries. Optional if TargetOptions are provided. */ target?: Target; tableMappings?: Record>; } /** * Per-target options for translating a policy into Prisma query conditions and an adapted mask function. */ export interface PrismaOptions { /** * The primary table of the Prisma query, used for translation and masking. */ primary: PrismaPrimary; } type PrismaPrimary = string; /** Per-request options for using the high-level SDK's * filter method {@link OPAClient.getMultipleFilters | getMultipleFilters }. */ export interface MultipleFiltersRequestOptions extends FiltersOptions { /** * The compilation targets for translating a policy into queries. */ targets: Exclude[]; tableMappings?: Partial, Record>>>; } /** Common extra per-request options for using the high-level SDK's * filter methods ({@link OPAClient.getFilters | getFilters } and * {@link OPAClient.getMultipleFilters | getMultipleFilters }. */ export interface FiltersOptions extends FetchOptions { /** * Low-level compilation options. */ compileOptions?: CompileOptions; /** * The unknowns for partial evaluation of the policy in the translation process. * Optional if provided via policy metadata. * * @example ["input.users", "input.fruits"] */ unknowns?: string[]; } export type Filters = { query?: string | Record | undefined; masks?: { [k: string]: any; } | undefined; }; export type PrismaMask = { mask>(obj: T): T; }; export type MultipleFilters = { targets?: Record, Filters>; }; /** * Target represents the known targets of translation. */ export type Target = keyof typeof CompileTargets; /** * SingleTarget is a convenience type, representing all known targets of translation, except "multi". */ export type SingleTarget = Exclude; /** * TargetOptions encodes extra translation options for each target. */ export type TargetOptions = Record<"ucastPrisma", PrismaOptions>; declare const CompileTargets: { readonly multi: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraMultitargetPlusJson; readonly mysql: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraSqlMysqlPlusJson; readonly postgresql: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraSqlPostgresqlPlusJson; readonly sqlserver: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraSqlSqlserverPlusJson; readonly sqlite: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraSqlSqlitePlusJson; readonly ucastALL: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraUcastAllPlusJson; readonly ucastLinq: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraUcastLinqPlusJson; readonly ucastMinimal: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraUcastMinimalPlusJson; readonly ucastPrisma: CompileQueryWithPartialEvaluationAcceptEnum.applicationVndStyraUcastPrismaPlusJson; }; /** Extra per-request options for using the high-level SDK's * evaluateBatch method. */ export interface BatchRequestOptions extends RequestOptions { /** With `rejectMixed` set, a batch result that contains _any errors_ causes a `Promise` rejection. */ rejectMixed?: boolean; /** Fall back to sequential evaluate calls if server doesn't support batch API. */ fallback?: boolean; } /** OPAClient is the starting point for using the high-level API. * * Use {@link OpaApiClient} if you need some low-level customization. */ export declare class OPAClient { private opa; private opaFallback; /** Create a new `OPA` instance. * @param serverURL - The OPA URL, e.g. `https://opa.internal.corp:8443/`. * @param opts - Extra options, including low-level `SDKOptions`. */ constructor(serverURL: string, opts?: Options); /** `evaluate` is used to evaluate the policy at the specified path with optional input. * * @param path - The path to the policy, without `/v1/data`: use `authz/allow` to evaluate policy `data.authz.allow`. * @param input - The input to the policy, if needed. * @param opts - Per-request options to control how the policy evaluation result is to be transformed * into `Res` (via `fromResult`), and low-level fetch options. */ evaluate(path: string, input?: In, opts?: RequestOptions): Promise; /** `evaluateDefault` is used to evaluate the server's default policy with optional input. * * @param input - The input to the default policy, defaults to `{}`. * @param opts - Per-request options to control how the policy evaluation result is to be transformed * into `Res` (via `fromResult`), and low-level fetch options. */ evaluateDefault(input?: In, opts?: RequestOptions): Promise; /** `evaluateBatch` is used to evaluate the policy at the specified path, for a batch of many inputs. * * @param path - The path to the policy, without `/v1/batch/data`: use `authz/allow` to evaluate policy `data.authz.allow`. * @param inputs - The inputs to the policy. * @param opts - Per-request options to control how the policy evaluation result is to be transformed * into `Res` (via `fromResult`), if any failures in the batch result should reject the promose (via * `rejectMixed`), and low-level fetch options. */ evaluateBatch(path: string, inputs: { [k: string]: In; }, opts?: BatchRequestOptions): Promise<{ [k: string]: Res | ServerErrorWithStatusCode; }>; fallbackBatch(path: string, inputs: { [k: string]: Input; }, opts?: BatchRequestOptions): Promise<{ [k: string]: ServerErrorWithStatusCode | SuccessfulPolicyResponse; }>; /** `getFilters` is used to translate the policy at the specified path into query filters of * the desired target type, with optional input. * Returns a promise that resolves to an object containing the query filters (key `query`) and optional masks (key `masks`). * * @param path - The path to the policy, without `/v1/compile`: use `filters/include` to translate the policy `data.filters.include`. * @param input - The input to the policy, if needed. * @param opts - Per-request options to control how the policy is translated into query filters, and low-level fetch options. */ getFilters(path: string, input?: In, opts?: (FiltersRequestOptions & Partial) | PrismaPrimary): Promise; /** `getMultipleFilters` is used to translate the policy at the specified path into query filters of * the multiple target types in one request, with optional input. * Returns a promise that resolves to an object containing the query filters (key `query`) and optional masks (key `masks`) _for each requested target_. * * @param path - The path to the policy, without `/v1/compile`: use `filters/include` to translate the policy `data.filters.include`. * @param input - The input to the policy, if needed. * @param opts - Per-request options to control how the policy is translated into query filters, and low-level fetch options. */ getMultipleFilters(path: string, input?: In, opts?: MultipleFiltersRequestOptions): Promise; } //# sourceMappingURL=opaclient.d.ts.map