oso-cloud
Version:
Oso Cloud Node.js Client SDK
203 lines • 5.74 kB
TypeScript
import http from "http";
import https from "https";
import { ClientOptions, LoggingFn } from ".";
import { ParityHandle } from "./parity-handle";
export type ApiResult = {
message: string;
};
export type ApiError = {
message: string;
};
export type Policy = {
filename: string | null;
src: string;
};
export type GetPolicyResult = {
policy: Policy | null;
};
export type Fact = {
predicate: string;
args: Value[];
};
export type ConcreteFact = {
predicate: string;
args: TypedId[];
};
export type Value = {
type: string | null;
id: string | null;
};
export type Bulk = {
delete: Fact[];
tell: Fact[];
};
export type AuthorizeResult = {
allowed: boolean;
};
export type AuthorizeQuery = {
actor_type: string;
actor_id: string;
action: string;
resource_type: string;
resource_id: string;
context_facts: Fact[];
};
export type ListResult = {
results: string[];
};
export type ListQuery = {
actor_type: string;
actor_id: string;
action: string;
resource_type: string;
context_facts: Fact[];
};
export type ActionsResult = {
results: string[];
};
export type ActionsQuery = {
actor_type: string;
actor_id: string;
resource_type: string;
resource_id: string;
context_facts: Fact[];
};
export type StatsResult = {
policy: {
versions: string[];
};
facts: {
total: number;
predicates: {
[predicate: string]: number;
};
};
};
export type ExpectedResult = {
request_id: string;
expected: boolean;
};
export type BatchInserts = {
inserts: Fact[];
};
export type BatchDeletes = {
deletes: Fact[];
};
export type FactChangeset = BatchInserts | BatchDeletes;
export type TypedId = {
type: string;
id: string;
};
export type QueryCall = [string, string[]];
export type QueryConstraint = {
type: string;
ids: string[] | null;
};
export type Query = {
predicate: QueryCall;
calls: QueryCall[];
constraints: {
[key: string]: QueryConstraint;
};
context_facts: ConcreteFact[];
};
export type QueryResult = {
results: {
[key: string]: string | null;
}[];
};
type LocalQueryMode = {
mode: "select";
query_vars_to_output_column_names: Record<string, string>;
} | {
mode: "filter";
query_var: string;
output_column_name: string;
};
export type LocalQueryResult = {
sql: string;
};
export type PolicyMetadata = {
resources: {
[resource: string]: {
roles: string[];
permissions: string[];
relations: {
[relation: string]: {
relatedResource: string;
};
};
};
};
};
export type GetPolicyMetadataResult = {
metadata: PolicyMetadata;
};
export declare class Api {
url: string;
token: string;
agent: http.Agent | https.Agent;
fallbackUrl?: string;
fallbackAgent?: http.Agent | https.Agent;
userAgent: string;
lastOffset: string | null;
debug?: {
print?: boolean;
file?: string;
logger?: LoggingFn;
};
dataBindings?: Promise<string>;
fetchTimeoutMillis?: number;
fetchBuilder?: (fetch: (input: any, init?: any) => Promise<any>) => (input: any, init?: any) => Promise<any>;
clientId: string;
constructor(url: string, apiKey: string, options: ClientOptions);
fallbackEligible(method: string, path: string): boolean | "" | undefined;
fallbackEligibleStatusCode(statusCode: number): boolean;
printDebugLogs(msg: string, metadata?: Record<string, any>): Promise<void>;
private printRequestTimingInfo;
_req<B, R>(path: string, method: string, params: Record<string, string>, body: B, isMutation: boolean): Promise<{
result: R;
requestId: string | null;
}>;
_get<B, R>(path: string, params: Record<string, string>, _body: B): Promise<{
result: R;
requestId: string | null;
}>;
_post<B, R>(path: string, params: Record<string, string>, body: B, isMutation: boolean): Promise<{
result: R;
requestId: string | null;
}>;
_delete<B, R>(path: string, params: Record<string, string>, body: B): Promise<{
result: R;
requestId: string | null;
}>;
_headers(request_id?: string): {
"X-Request-ID": string;
Accept: string;
"X-Oso-Instance-Id": string;
OsoOffset?: string | undefined;
"Content-Type": string;
Authorization: string;
"User-Agent": string;
"X-OsoApiVersion": string;
};
getPolicy(): Promise<GetPolicyResult>;
getPolicyMetadata(version?: string): Promise<GetPolicyMetadataResult>;
postPolicy(data: Policy): Promise<ApiResult>;
postBatch(data: FactChangeset[]): Promise<ApiResult>;
postAuthorize(data: AuthorizeQuery, parityHandle?: ParityHandle): Promise<AuthorizeResult>;
postList(data: ListQuery): Promise<ListResult>;
postActions(data: ActionsQuery): Promise<ActionsResult>;
postQuery(data: Query): Promise<QueryResult>;
getStats(): Promise<StatsResult>;
readDataBindings(): Promise<string>;
postActionsQuery(query: ActionsQuery): Promise<LocalQueryResult>;
postAuthorizeQuery(query: AuthorizeQuery, parityHandle?: ParityHandle): Promise<LocalQueryResult>;
postListQuery(query: ListQuery, column: string): Promise<LocalQueryResult>;
postQueryLocal(query: Query, mode: LocalQueryMode): Promise<LocalQueryResult>;
clearData(): Promise<ApiResult>;
getFacts(predicate: string, args: Value[]): Promise<Fact[]>;
postExpectedResult(expectedResult: ExpectedResult): Promise<ApiResult>;
}
export {};
//# sourceMappingURL=api.d.ts.map