@cerbos/core
Advanced tools
Comparing version 0.8.0 to 0.8.1
import type { _RPC, _Request, _Response, _Service } from "./rpcs"; | ||
import type { AddOrUpdatePoliciesRequest, AddOrUpdateSchemasRequest, CheckResourceRequest, CheckResourcesRequest, CheckResourcesResponse, CheckResourcesResult, DeleteSchemasRequest, GetPoliciesRequest, GetPoliciesResponse, GetSchemasRequest, GetSchemasResponse, IsAllowedRequest, ListPoliciesResponse, ListSchemasResponse, PlanResourcesRequest, PlanResourcesResponse, Policy, ReloadStoreRequest, Schema, ServerInfo, ValidationFailedCallback } from "./types/external"; | ||
/** @internal */ | ||
export declare type _Transport = <Service extends _Service, RPC extends _RPC<Service>>(service: Service, rpc: RPC, request: _Request<Service, RPC>, adminCredentials?: AdminCredentials) => Promise<_Response<Service, RPC>>; | ||
export type _Transport = <Service extends _Service, RPC extends _RPC<Service>>(service: Service, rpc: RPC, request: _Request<Service, RPC>, adminCredentials?: AdminCredentials) => Promise<_Response<Service, RPC>>; | ||
/** | ||
@@ -126,4 +126,12 @@ * Options for creating a new {@link Client}. | ||
* const decision = await cerbos.checkResource({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* resource: { kind: "document", id: "1" }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["view", "edit"], | ||
@@ -142,10 +150,22 @@ * }); | ||
* const decision = await cerbos.checkResources({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resources: [ | ||
* { | ||
* resource: { kind: "document", id: "1" }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["view", "edit"], | ||
* }, | ||
* { | ||
* resource: { kind: "image", id: "1" }, | ||
* resource: { | ||
* kind: "image", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["delete"], | ||
@@ -275,4 +295,12 @@ * }, | ||
* await cerbos.isAllowed({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* resource: { kind: "document", id: "1" }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* action: "view", | ||
@@ -321,3 +349,7 @@ * }); // => true | ||
* const plan = await cerbos.planResources({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { kind: "document" }, | ||
@@ -324,0 +356,0 @@ * }); |
@@ -84,4 +84,12 @@ "use strict"; | ||
* const decision = await cerbos.checkResource({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* resource: { kind: "document", id: "1" }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["view", "edit"], | ||
@@ -111,10 +119,22 @@ * }); | ||
* const decision = await cerbos.checkResources({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resources: [ | ||
* { | ||
* resource: { kind: "document", id: "1" }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["view", "edit"], | ||
* }, | ||
* { | ||
* resource: { kind: "image", id: "1" }, | ||
* resource: { | ||
* kind: "image", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["delete"], | ||
@@ -262,4 +282,12 @@ * }, | ||
* await cerbos.isAllowed({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* resource: { kind: "document", id: "1" }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* action: "view", | ||
@@ -320,3 +348,7 @@ * }); // => true | ||
* const plan = await cerbos.planResources({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { kind: "document" }, | ||
@@ -323,0 +355,0 @@ * }); |
@@ -54,2 +54,14 @@ "use strict"; | ||
class NotOK extends Error { | ||
/** | ||
* Parse a JSON-serialized unsuccessful response. | ||
*/ | ||
static fromJSON(text) { | ||
try { | ||
const error = JSON.parse(text); | ||
return new NotOK(code(error), details(error)); | ||
} | ||
catch (_) { | ||
return new NotOK(Status.UNKNOWN, text); | ||
} | ||
} | ||
constructor( | ||
@@ -64,3 +76,3 @@ /** | ||
details) { | ||
super(`gRPC error ${code} (${Status[code] ?? "unrecognized"}): ${details}`); | ||
super(`gRPC error ${code} (${Status[code]}): ${details}`); | ||
this.code = code; | ||
@@ -71,14 +83,2 @@ this.details = details; | ||
} | ||
/** | ||
* Parse a JSON-serialized unsuccessful response. | ||
*/ | ||
static fromJSON(text) { | ||
try { | ||
const error = JSON.parse(text); | ||
return new NotOK(code(error), details(error)); | ||
} | ||
catch (_) { | ||
return new NotOK(Status.UNKNOWN, text); | ||
} | ||
} | ||
} | ||
@@ -85,0 +85,0 @@ exports.NotOK = NotOK; |
@@ -285,3 +285,3 @@ import type { Empty } from "../../../protobuf/empty"; | ||
* Whether the function is to be used in a method call-style `x.f(...)` | ||
* of a function call-style `f(x, ...)`. | ||
* or a function call-style `f(x, ...)`. | ||
* | ||
@@ -288,0 +288,0 @@ * For methods, the first parameter declaration, `params[0]` is the |
@@ -24,3 +24,3 @@ export declare const protobufPackage = "grpc.gateway.protoc_gen_openapiv2.options"; | ||
* version: "1.0"; | ||
* description: "; | ||
* description: ""; | ||
* contact: { | ||
@@ -301,3 +301,3 @@ * name: "gRPC-Gateway project"; | ||
* version: "1.0"; | ||
* description: "; | ||
* description: ""; | ||
* contact: { | ||
@@ -542,2 +542,7 @@ * name: "gRPC-Gateway project"; | ||
enum: string[]; | ||
/** Additional field level properties used when generating the OpenAPI v2 file. */ | ||
fieldConfiguration: JSONSchema_FieldConfiguration | undefined; | ||
extensions: { | ||
[key: string]: any | undefined; | ||
}; | ||
} | ||
@@ -555,2 +560,19 @@ export declare enum JSONSchema_JSONSchemaSimpleTypes { | ||
/** | ||
* 'FieldConfiguration' provides additional field level properties used when generating the OpenAPI v2 file. | ||
* These properties are not defined by OpenAPIv2, but they are used to control the generation. | ||
*/ | ||
export interface JSONSchema_FieldConfiguration { | ||
/** | ||
* Alternative parameter name when used as path parameter. If set, this will | ||
* be used as the complete parameter name when this field is used as a path | ||
* parameter. Use this to avoid having auto generated path parameter names | ||
* for overlapping paths. | ||
*/ | ||
pathParamName: string; | ||
} | ||
export interface JSONSchema_ExtensionsEntry { | ||
key: string; | ||
value: any | undefined; | ||
} | ||
/** | ||
* `Tag` is a representation of OpenAPI v2 specification's Tag object. | ||
@@ -557,0 +579,0 @@ * |
@@ -22,9 +22,9 @@ import type { AddOrUpdatePolicyRequest, AddOrUpdateSchemaRequest, CheckResourcesRequest, DeleteSchemaRequest, GetPolicyRequest, GetSchemaRequest, ListPoliciesRequest, ListSchemasRequest, PlanResourcesRequest, ReloadStoreRequest, ServerInfoRequest } from "./protobuf/cerbos/request/v1/request"; | ||
/** @internal */ | ||
export declare type _Service = keyof _Services; | ||
export type _Service = keyof _Services; | ||
/** @internal */ | ||
export declare type _RPC<Service> = Service extends _Service ? keyof _Services[Service] : never; | ||
export type _RPC<Service> = Service extends _Service ? keyof _Services[Service] : never; | ||
/** @internal */ | ||
export declare type _Request<Service extends _Service, RPC extends _RPC<Service>> = _Services[Service][RPC] extends unknown[] ? _Services[Service][RPC][0] : never; | ||
export type _Request<Service extends _Service, RPC extends _RPC<Service>> = _Services[Service][RPC] extends unknown[] ? _Services[Service][RPC][0] : never; | ||
/** @internal */ | ||
export declare type _Response<Service extends _Service, RPC extends _RPC<Service>> = _Services[Service][RPC] extends unknown[] ? _Services[Service][RPC][1] : never; | ||
export type _Response<Service extends _Service, RPC extends _RPC<Service>> = _Services[Service][RPC] extends unknown[] ? _Services[Service][RPC][1] : never; | ||
//# sourceMappingURL=rpcs.d.ts.map |
@@ -8,3 +8,3 @@ import type { CheckResourcesRequest } from "./CheckResourcesRequest"; | ||
*/ | ||
export declare type CheckResourceRequest = Omit<CheckResourcesRequest, "resources"> & ResourceCheck; | ||
export type CheckResourceRequest = Omit<CheckResourcesRequest, "resources"> & ResourceCheck; | ||
//# sourceMappingURL=CheckResourceRequest.d.ts.map |
@@ -7,5 +7,5 @@ import type { CheckResourceRequest } from "./CheckResourceRequest"; | ||
*/ | ||
export declare type IsAllowedRequest = Omit<CheckResourceRequest, "actions"> & { | ||
export type IsAllowedRequest = Omit<CheckResourceRequest, "actions"> & { | ||
action: string; | ||
}; | ||
//# sourceMappingURL=IsAllowedRequest.d.ts.map |
@@ -10,3 +10,3 @@ import type { MatchAll } from "./MatchAll"; | ||
*/ | ||
export declare type Match = MatchAll | MatchAny | MatchNone | MatchExpr; | ||
export type Match = MatchAll | MatchAny | MatchNone | MatchExpr; | ||
/** | ||
@@ -13,0 +13,0 @@ * Type guard to check if a {@link Match} is a {@link MatchAll}. |
@@ -9,3 +9,3 @@ import type { PlanExpression } from "./PlanExpression"; | ||
*/ | ||
export declare type PlanExpressionOperand = PlanExpression | PlanExpressionValue | PlanExpressionVariable; | ||
export type PlanExpressionOperand = PlanExpression | PlanExpressionValue | PlanExpressionVariable; | ||
//# sourceMappingURL=PlanExpressionOperand.d.ts.map |
@@ -8,3 +8,3 @@ import type { PlanResourcesConditionalResponse } from "./PlanResourcesConditionalResponse"; | ||
*/ | ||
export declare type PlanResourcesResponse = PlanResourcesConditionalResponse | PlanResourcesUnconditionalResponse; | ||
export type PlanResourcesResponse = PlanResourcesConditionalResponse | PlanResourcesUnconditionalResponse; | ||
//# sourceMappingURL=PlanResourcesResponse.d.ts.map |
@@ -9,3 +9,3 @@ import type { DerivedRoles } from "./DerivedRoles"; | ||
*/ | ||
export declare type Policy = DerivedRoles | PrincipalPolicy | ResourcePolicy; | ||
export type Policy = DerivedRoles | PrincipalPolicy | ResourcePolicy; | ||
/** | ||
@@ -12,0 +12,0 @@ * Type guard to check if a {@link Policy} is a set of {@link DerivedRoles}. |
@@ -7,3 +7,3 @@ import type { Resource } from "./Resource"; | ||
*/ | ||
export declare type ResourceQuery = Omit<Resource, "id">; | ||
export type ResourceQuery = Omit<Resource, "id">; | ||
//# sourceMappingURL=ResourceQuery.d.ts.map |
@@ -10,3 +10,3 @@ import type { Resource } from "./Resource"; | ||
*/ | ||
export declare type ResourceSearch = Omit<Resource, "attributes">; | ||
export type ResourceSearch = Omit<Resource, "attributes">; | ||
//# sourceMappingURL=ResourceSearch.d.ts.map |
@@ -7,3 +7,3 @@ import type { SchemaDefinition } from "./SchemaDefinition"; | ||
*/ | ||
export declare type SchemaDefinitionInput = string | Uint8Array | Record<string, unknown> | SchemaDefinition; | ||
export type SchemaDefinitionInput = string | Uint8Array | Record<string, unknown> | SchemaDefinition; | ||
//# sourceMappingURL=SchemaDefinitionInput.d.ts.map |
@@ -7,3 +7,3 @@ import type { ValidationError } from "./ValidationError"; | ||
*/ | ||
export declare type ValidationFailedCallback = (validationErrors: ValidationError[]) => void; | ||
export type ValidationFailedCallback = (validationErrors: ValidationError[]) => void; | ||
//# sourceMappingURL=ValidationFailedCallback.d.ts.map |
@@ -6,5 +6,5 @@ /** | ||
*/ | ||
export declare type Value = string | number | boolean | null | { | ||
export type Value = string | number | boolean | null | { | ||
[key: string]: Value; | ||
} | Value[]; | ||
//# sourceMappingURL=Value.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export declare type OmitFromEach<T, K extends string> = T extends unknown ? Omit<T, K> : never; | ||
export type OmitFromEach<T, K extends string> = T extends unknown ? Omit<T, K> : never; | ||
export declare const isObject: (value: unknown) => value is Record<string, unknown>; | ||
//# sourceMappingURL=internal.d.ts.map |
{ | ||
"name": "@cerbos/core", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Common types used by the @cerbos/grpc and @cerbos/http client libraries", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -197,4 +197,12 @@ import { | ||
* const decision = await cerbos.checkResource({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* resource: { kind: "document", id: "1" }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["view", "edit"], | ||
@@ -230,10 +238,22 @@ * }); | ||
* const decision = await cerbos.checkResources({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resources: [ | ||
* { | ||
* resource: { kind: "document", id: "1" }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["view", "edit"], | ||
* }, | ||
* { | ||
* resource: { kind: "image", id: "1" }, | ||
* resource: { | ||
* kind: "image", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* actions: ["delete"], | ||
@@ -411,4 +431,12 @@ * }, | ||
* await cerbos.isAllowed({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* resource: { kind: "document", id: "1" }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { | ||
* kind: "document", | ||
* id: "1", | ||
* attributes: { owner: "user@example.com" }, | ||
* }, | ||
* action: "view", | ||
@@ -476,3 +504,7 @@ * }); // => true | ||
* const plan = await cerbos.planResources({ | ||
* principal: { id: "user@example.com", roles: ["USER"] }, | ||
* principal: { | ||
* id: "user@example.com", | ||
* roles: ["USER"], | ||
* attributes: { tier: "PREMIUM" }, | ||
* }, | ||
* resource: { kind: "document" }, | ||
@@ -479,0 +511,0 @@ * }); |
@@ -136,3 +136,3 @@ import { Effect as EffectProtobuf } from "../protobuf/cerbos/effect/v1/effect"; | ||
`Unexpected validation error source ${source} (${ | ||
ValidationError_Source[source] ?? "unrecognized" | ||
ValidationError_Source[source as number] ?? "unrecognized" | ||
})` | ||
@@ -414,3 +414,3 @@ ); | ||
`Unexpected PlanResources filter kind ${kind} (${ | ||
PlanResourcesFilter_Kind[kind] ?? "unrecognized" | ||
PlanResourcesFilter_Kind[kind as number] ?? "unrecognized" | ||
})` | ||
@@ -417,0 +417,0 @@ ); |
@@ -84,3 +84,3 @@ import type { ValidationError } from "./types/external"; | ||
) { | ||
super(`gRPC error ${code} (${Status[code] ?? "unrecognized"}): ${details}`); | ||
super(`gRPC error ${code} (${Status[code]}): ${details}`); | ||
this.name = this.constructor.name; | ||
@@ -87,0 +87,0 @@ Error.captureStackTrace(this, this.constructor); |
@@ -277,3 +277,3 @@ /* eslint-disable */ | ||
* Whether the function is to be used in a method call-style `x.f(...)` | ||
* of a function call-style `f(x, ...)`. | ||
* or a function call-style `f(x, ...)`. | ||
* | ||
@@ -280,0 +280,0 @@ * For methods, the first parameter declaration, `params[0]` is the |
@@ -28,3 +28,3 @@ /* eslint-disable */ | ||
* version: "1.0"; | ||
* description: "; | ||
* description: ""; | ||
* contact: { | ||
@@ -310,3 +310,3 @@ * name: "gRPC-Gateway project"; | ||
* version: "1.0"; | ||
* description: "; | ||
* description: ""; | ||
* contact: { | ||
@@ -563,2 +563,5 @@ * name: "gRPC-Gateway project"; | ||
enum: string[]; | ||
/** Additional field level properties used when generating the OpenAPI v2 file. */ | ||
fieldConfiguration: JSONSchema_FieldConfiguration | undefined; | ||
extensions: { [key: string]: any | undefined }; | ||
} | ||
@@ -578,2 +581,21 @@ | ||
/** | ||
* 'FieldConfiguration' provides additional field level properties used when generating the OpenAPI v2 file. | ||
* These properties are not defined by OpenAPIv2, but they are used to control the generation. | ||
*/ | ||
export interface JSONSchema_FieldConfiguration { | ||
/** | ||
* Alternative parameter name when used as path parameter. If set, this will | ||
* be used as the complete parameter name when this field is used as a path | ||
* parameter. Use this to avoid having auto generated path parameter names | ||
* for overlapping paths. | ||
*/ | ||
pathParamName: string; | ||
} | ||
export interface JSONSchema_ExtensionsEntry { | ||
key: string; | ||
value: any | undefined; | ||
} | ||
/** | ||
* `Tag` is a representation of OpenAPI v2 specification's Tag object. | ||
@@ -580,0 +602,0 @@ * |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
689349
16354