Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cerbos/core

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cerbos/core - npm Package Compare versions

Comparing version 0.12.0 to 0.13.0

77

lib/client.d.ts
import type { _RPC, _Request, _Response, _Service } from "./rpcs";
import type { AddOrUpdatePoliciesRequest, AddOrUpdateSchemasRequest, CheckResourceRequest, CheckResourcesRequest, CheckResourcesResponse, CheckResourcesResult, DeleteSchemasRequest, DeleteSchemasResponse, DisablePoliciesRequest, DisablePoliciesResponse, EnablePoliciesRequest, EnablePoliciesResponse, GetPoliciesRequest, GetPoliciesResponse, GetSchemasRequest, GetSchemasResponse, IsAllowedRequest, ListPoliciesRequest, ListPoliciesResponse, ListSchemasResponse, PlanResourcesRequest, PlanResourcesResponse, Policy, ReloadStoreRequest, Schema, ServerInfo, ValidationFailedCallback } from "./types/external";
/** @internal */
export 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, metadata?: Record<string, string>) => Promise<_Response<Service, RPC>>;
/** @internal */
export type _Instrumenter = (transport: _Transport) => _Transport;
/** @internal */
export declare const _addInstrumenter: (instrumenter: _Instrumenter) => void;
export declare function _addInstrumenter(instrumenter: _Instrumenter): void;
/** @internal */
export declare const _removeInstrumenter: (instrumenter: _Instrumenter) => void;
export declare function _removeInstrumenter(instrumenter: _Instrumenter): void;
/**

@@ -83,2 +83,4 @@ * Options for creating a new {@link Client}.

* @example
* Create a policy in code:
*
* ```typescript

@@ -99,2 +101,25 @@ * await cerbos.addOrUpdatePolicies({

* ```
*
* @example
* Load a policy from a YAML or JSON file with {@link @cerbos/files#readPolicy}:
*
* ```typescript
* import { readPolicy } from "@cerbos/files";
*
* await cerbos.addOrUpdatePolicies({
* policies: [await readPolicy("path/to/policy.yaml")],
* });
* ```
*
* @example
* Load policies and schemas from a directory with {@link @cerbos/files#readDirectory}:
*
* ```typescript
* import { readDirectory } from "@cerbos/files";
*
* const { policies, schemas } = await readDirectory("path/to/directory");
*
* await cerbos.addOrUpdateSchemas({ schemas });
* await cerbos.addOrUpdatePolicies({ policies });
* ```
*/

@@ -115,13 +140,41 @@ addOrUpdatePolicies(request: AddOrUpdatePoliciesRequest): Promise<void>;

* @example
* Create a schema in code:
*
* ```typescript
* await cerbos.addOrUpdateSchemas([{
* id: "document.json",
* definition: `{
* "type": "object",
* "properties": {
* "owner": { "type": "string" }
* }
* }`,
* }]);
*
* await cerbos.addOrUpdateSchemas({
* schemas: [{
* id: "document.json",
* definition: {
* type: "object",
* properties: {
* owner: { type: "string" }
* }
* },
* }],
* });
* ```
*
* @example
* Load a schema from a JSON file with {@link @cerbos/files#readSchema}:
*
* ```typescript
* import { readSchema } from "@cerbos/files";
*
* await cerbos.addOrUpdateSchemas({
* schemas: [await readSchema("_schemas/path/to/schema.json")],
* });
* ```
*
* @example
* Load policies and schemas from a directory with {@link @cerbos/files#readDirectory}:
*
* ```typescript
* import { readDirectory } from "@cerbos/files";
*
* const { policies, schemas } = await readDirectory("path/to/directory");
*
* await cerbos.addOrUpdateSchemas({ schemas });
* await cerbos.addOrUpdatePolicies({ policies });
* ```
*/

@@ -128,0 +181,0 @@ addOrUpdateSchemas(request: AddOrUpdateSchemasRequest): Promise<void>;

@@ -9,10 +9,10 @@ "use strict";

/** @internal */
const _addInstrumenter = (instrumenter) => {
function _addInstrumenter(instrumenter) {
instrumenters.add(instrumenter);
};
}
exports._addInstrumenter = _addInstrumenter;
/** @internal */
const _removeInstrumenter = (instrumenter) => {
function _removeInstrumenter(instrumenter) {
instrumenters.delete(instrumenter);
};
}
exports._removeInstrumenter = _removeInstrumenter;

@@ -46,2 +46,4 @@ /**

* @example
* Create a policy in code:
*
* ```typescript

@@ -62,2 +64,25 @@ * await cerbos.addOrUpdatePolicies({

* ```
*
* @example
* Load a policy from a YAML or JSON file with {@link @cerbos/files#readPolicy}:
*
* ```typescript
* import { readPolicy } from "@cerbos/files";
*
* await cerbos.addOrUpdatePolicies({
* policies: [await readPolicy("path/to/policy.yaml")],
* });
* ```
*
* @example
* Load policies and schemas from a directory with {@link @cerbos/files#readDirectory}:
*
* ```typescript
* import { readDirectory } from "@cerbos/files";
*
* const { policies, schemas } = await readDirectory("path/to/directory");
*
* await cerbos.addOrUpdateSchemas({ schemas });
* await cerbos.addOrUpdatePolicies({ policies });
* ```
*/

@@ -80,13 +105,41 @@ async addOrUpdatePolicies(request) {

* @example
* Create a schema in code:
*
* ```typescript
* await cerbos.addOrUpdateSchemas([{
* id: "document.json",
* definition: `{
* "type": "object",
* "properties": {
* "owner": { "type": "string" }
* }
* }`,
* }]);
*
* await cerbos.addOrUpdateSchemas({
* schemas: [{
* id: "document.json",
* definition: {
* type: "object",
* properties: {
* owner: { type: "string" }
* }
* },
* }],
* });
* ```
*
* @example
* Load a schema from a JSON file with {@link @cerbos/files#readSchema}:
*
* ```typescript
* import { readSchema } from "@cerbos/files";
*
* await cerbos.addOrUpdateSchemas({
* schemas: [await readSchema("_schemas/path/to/schema.json")],
* });
* ```
*
* @example
* Load policies and schemas from a directory with {@link @cerbos/files#readDirectory}:
*
* ```typescript
* import { readDirectory } from "@cerbos/files";
*
* const { policies, schemas } = await readDirectory("path/to/directory");
*
* await cerbos.addOrUpdateSchemas({ schemas });
* await cerbos.addOrUpdatePolicies({ policies });
* ```
*/

@@ -93,0 +146,0 @@ async addOrUpdateSchemas(request) {

20

lib/convert/fromProtobuf.d.ts

@@ -7,13 +7,13 @@ import type { Policy as PolicyProtobuf } from "../protobuf/cerbos/policy/v1/policy";

import type { GetSchemasResponse } from "../types/external/GetSchemasResponse";
export declare const checkResourcesResponseFromProtobuf: ({ requestId, results, }: CheckResourcesResponseProtobuf) => CheckResourcesResponse;
export declare const deleteSchemasResponseFromProtobuf: ({ deletedSchemas, }: DeleteSchemaResponse) => DeleteSchemasResponse;
export declare const disablePoliciesResponseFromProtobuf: ({ disabledPolicies, }: DisablePolicyResponse) => DisablePoliciesResponse;
export declare const enablePoliciesResponseFromProtobuf: ({ enabledPolicies, }: EnablePolicyResponse) => EnablePoliciesResponse;
export declare const getPoliciesResponseFromProtobuf: ({ policies, }: GetPolicyResponse) => GetPoliciesResponse;
export declare function checkResourcesResponseFromProtobuf({ requestId, results, }: CheckResourcesResponseProtobuf): CheckResourcesResponse;
export declare function deleteSchemasResponseFromProtobuf({ deletedSchemas, }: DeleteSchemaResponse): DeleteSchemasResponse;
export declare function disablePoliciesResponseFromProtobuf({ disabledPolicies, }: DisablePolicyResponse): DisablePoliciesResponse;
export declare function enablePoliciesResponseFromProtobuf({ enabledPolicies, }: EnablePolicyResponse): EnablePoliciesResponse;
export declare function getPoliciesResponseFromProtobuf({ policies, }: GetPolicyResponse): GetPoliciesResponse;
/** @internal */
export declare const _policyFromProtobuf: ({ apiVersion, description, disabled, metadata, variables, policyType, }: PolicyProtobuf) => Policy;
export declare const getSchemasResponseFromProtobuf: ({ schemas, }: GetSchemaResponse) => GetSchemasResponse;
export declare const listPoliciesResponseFromProtobuf: ({ policyIds, }: ListPoliciesResponseProtobuf) => ListPoliciesResponse;
export declare const listSchemasResponseFromProtobuf: ({ schemaIds, }: ListSchemasResponseProtobuf) => ListSchemasResponse;
export declare const planResourcesResponseFromProtobuf: ({ requestId, filter, validationErrors, meta, }: PlanResourcesResponseProtobuf) => PlanResourcesResponse;
export declare function _policyFromProtobuf({ apiVersion, description, disabled, metadata, variables, policyType, }: PolicyProtobuf): Policy;
export declare function getSchemasResponseFromProtobuf({ schemas, }: GetSchemaResponse): GetSchemasResponse;
export declare function listPoliciesResponseFromProtobuf({ policyIds, }: ListPoliciesResponseProtobuf): ListPoliciesResponse;
export declare function listSchemasResponseFromProtobuf({ schemaIds, }: ListSchemasResponseProtobuf): ListSchemasResponse;
export declare function planResourcesResponseFromProtobuf({ requestId, filter, validationErrors, meta, }: PlanResourcesResponseProtobuf): PlanResourcesResponse;
//# sourceMappingURL=fromProtobuf.d.ts.map

@@ -8,8 +8,10 @@ "use strict";

const external_1 = require("../types/external");
const checkResourcesResponseFromProtobuf = ({ requestId, results, }) => new external_1.CheckResourcesResponse({
requestId,
results: results.map(checkResourcesResultFromProtobuf),
});
function checkResourcesResponseFromProtobuf({ requestId, results, }) {
return new external_1.CheckResourcesResponse({
requestId,
results: results.map(checkResourcesResultFromProtobuf),
});
}
exports.checkResourcesResponseFromProtobuf = checkResourcesResponseFromProtobuf;
const checkResourcesResultFromProtobuf = ({ resource, actions, validationErrors, meta, outputs, }) => {
function checkResourcesResultFromProtobuf({ resource, actions, validationErrors, meta, outputs, }) {
if (!resource) {

@@ -25,14 +27,20 @@ throw new Error("Missing resource on CheckResources result");

});
};
const actionsFromProtobuf = (actions) => Object.fromEntries(Object.entries(actions).map(([action, effect]) => [
action,
effectFromProtobuf(effect),
]));
const effectFromProtobuf = (effect) => effect === effect_1.Effect.EFFECT_ALLOW ? external_1.Effect.ALLOW : external_1.Effect.DENY;
const validationErrorFromProtobuf = ({ path, message, source, }) => ({
path,
message,
source: validationErrorSourceFromProtobuf(source),
});
const validationErrorSourceFromProtobuf = (source) => {
}
function actionsFromProtobuf(actions) {
return Object.fromEntries(Object.entries(actions).map(([action, effect]) => [
action,
effectFromProtobuf(effect),
]));
}
function effectFromProtobuf(effect) {
return effect === effect_1.Effect.EFFECT_ALLOW ? external_1.Effect.ALLOW : external_1.Effect.DENY;
}
function validationErrorFromProtobuf({ path, message, source, }) {
return {
path,
message,
source: validationErrorSourceFromProtobuf(source),
};
}
function validationErrorSourceFromProtobuf(source) {
switch (source) {

@@ -46,41 +54,55 @@ case schema_1.ValidationError_Source.SOURCE_PRINCIPAL:

}
};
const outputResultFromProtobuf = ({ src, val }) => ({
source: src,
value: val,
});
const deleteSchemasResponseFromProtobuf = ({ deletedSchemas, }) => ({
deletedSchemas,
});
}
function outputResultFromProtobuf({ src, val }) {
return {
source: src,
value: val,
};
}
function deleteSchemasResponseFromProtobuf({ deletedSchemas, }) {
return {
deletedSchemas,
};
}
exports.deleteSchemasResponseFromProtobuf = deleteSchemasResponseFromProtobuf;
const disablePoliciesResponseFromProtobuf = ({ disabledPolicies, }) => ({
disabledPolicies,
});
function disablePoliciesResponseFromProtobuf({ disabledPolicies, }) {
return {
disabledPolicies,
};
}
exports.disablePoliciesResponseFromProtobuf = disablePoliciesResponseFromProtobuf;
const enablePoliciesResponseFromProtobuf = ({ enabledPolicies, }) => ({
enabledPolicies,
});
function enablePoliciesResponseFromProtobuf({ enabledPolicies, }) {
return {
enabledPolicies,
};
}
exports.enablePoliciesResponseFromProtobuf = enablePoliciesResponseFromProtobuf;
const getPoliciesResponseFromProtobuf = ({ policies, }) => ({
policies: policies.map(exports._policyFromProtobuf),
});
function getPoliciesResponseFromProtobuf({ policies, }) {
return {
policies: policies.map(_policyFromProtobuf),
};
}
exports.getPoliciesResponseFromProtobuf = getPoliciesResponseFromProtobuf;
/** @internal */
const _policyFromProtobuf = ({ apiVersion, description, disabled, metadata, variables, policyType, }) => ({
apiVersion,
description,
disabled,
metadata: metadata && policyMetadataFromProtobuf(metadata),
variables,
...policyTypeFromProtobuf(policyType),
});
function _policyFromProtobuf({ apiVersion, description, disabled, metadata, variables, policyType, }) {
return {
apiVersion,
description,
disabled,
metadata: metadata && policyMetadataFromProtobuf(metadata),
variables,
...policyTypeFromProtobuf(policyType),
};
}
exports._policyFromProtobuf = _policyFromProtobuf;
const policyMetadataFromProtobuf = ({ annotations, hash, sourceFile, storeIdentifer, storeIdentifier, }) => ({
annotations,
hash,
sourceFile,
storeIdentifer: storeIdentifier || storeIdentifer,
storeIdentifier: storeIdentifier || storeIdentifer,
});
const policyTypeFromProtobuf = (policyType) => {
function policyMetadataFromProtobuf({ annotations, hash, sourceFile, storeIdentifer, storeIdentifier, }) {
return {
annotations,
hash,
sourceFile,
storeIdentifer: storeIdentifier || storeIdentifer,
storeIdentifier: storeIdentifier || storeIdentifer,
};
}
function policyTypeFromProtobuf(policyType) {
if (!policyType) {

@@ -101,16 +123,20 @@ throw new Error("Unknown policy type: undefined");

}
};
const derivedRolesFromProtobuf = ({ name, definitions, variables, }) => ({
derivedRoles: {
}
function derivedRolesFromProtobuf({ name, definitions, variables, }) {
return {
derivedRoles: {
name,
definitions: definitions.map(derivedRoleDefinitionFromProtobuf),
variables: variables && variablesFromProtobuf(variables),
},
};
}
function derivedRoleDefinitionFromProtobuf({ name, parentRoles, condition, }) {
return {
name,
definitions: definitions.map(derivedRoleDefinitionFromProtobuf),
variables: variables && variablesFromProtobuf(variables),
},
});
const derivedRoleDefinitionFromProtobuf = ({ name, parentRoles, condition, }) => ({
name,
parentRoles,
condition: condition && conditionFromProtobuf(condition),
});
const conditionFromProtobuf = ({ condition }) => {
parentRoles,
condition: condition && conditionFromProtobuf(condition),
};
}
function conditionFromProtobuf({ condition }) {
switch (condition?.$case) {

@@ -124,4 +150,4 @@ case "match":

}
};
const matchFromProtobuf = ({ op }) => {
}
function matchFromProtobuf({ op }) {
switch (op?.$case) {

@@ -147,84 +173,114 @@ case "all":

}
};
const matchesFromProtobuf = ({ of }) => ({
of: of.map(matchFromProtobuf),
});
const variablesFromProtobuf = ({ import: imports, local, }) => ({
import: imports,
local,
});
const exportVariablesFromProtobuf = ({ name, definitions, }) => ({
exportVariables: {
}
function matchesFromProtobuf({ of }) {
return {
of: of.map(matchFromProtobuf),
};
}
function variablesFromProtobuf({ import: imports, local, }) {
return {
import: imports,
local,
};
}
function exportVariablesFromProtobuf({ name, definitions, }) {
return {
exportVariables: {
name,
definitions,
},
};
}
function principalPolicyFromProtobuf({ principal, version, rules, scope, variables, }) {
return {
principalPolicy: {
principal,
version,
rules: rules.map(principalRuleFromProtobuf),
scope,
variables: variables && variablesFromProtobuf(variables),
},
};
}
function principalRuleFromProtobuf({ resource, actions, }) {
return {
resource,
actions: actions.map(principalRuleActionFromProtobuf),
};
}
function principalRuleActionFromProtobuf({ action, effect, condition, name, output, }) {
return {
action,
effect: effectFromProtobuf(effect),
condition: condition && conditionFromProtobuf(condition),
name,
definitions,
},
});
const principalPolicyFromProtobuf = ({ principal, version, rules, scope, variables, }) => ({
principalPolicy: {
principal,
version,
rules: rules.map(principalRuleFromProtobuf),
scope,
variables: variables && variablesFromProtobuf(variables),
},
});
const principalRuleFromProtobuf = ({ resource, actions, }) => ({
resource,
actions: actions.map(principalRuleActionFromProtobuf),
});
const principalRuleActionFromProtobuf = ({ action, effect, condition, name, output, }) => ({
action,
effect: effectFromProtobuf(effect),
condition: condition && conditionFromProtobuf(condition),
name,
output: output && outputFromProtobuf(output),
});
const outputFromProtobuf = ({ expr }) => ({ expr });
const resourcePolicyFromProtobuf = ({ resource, version, importDerivedRoles, rules, schemas, scope, variables, }) => ({
resourcePolicy: {
resource,
version,
importDerivedRoles,
rules: rules.map(resourceRuleFromProtobuf),
schemas: schemas && schemaRefsFromProtobuf(schemas),
scope,
variables: variables && variablesFromProtobuf(variables),
},
});
const resourceRuleFromProtobuf = ({ actions, effect, derivedRoles, roles, condition, name, output, }) => ({
actions,
effect: effectFromProtobuf(effect),
derivedRoles,
roles,
condition: condition && conditionFromProtobuf(condition),
name,
output: output && outputFromProtobuf(output),
});
const schemaRefsFromProtobuf = ({ principalSchema, resourceSchema, }) => ({
principalSchema: principalSchema && schemaRefFromProtobuf(principalSchema),
resourceSchema: resourceSchema && schemaRefFromProtobuf(resourceSchema),
});
const schemaRefFromProtobuf = ({ ref, ignoreWhen, }) => ({
ref,
ignoreWhen: ignoreWhen && {
actions: ignoreWhen.actions,
},
});
const getSchemasResponseFromProtobuf = ({ schemas, }) => ({
schemas: schemas.map(schemaFromProtobuf),
});
output: output && outputFromProtobuf(output),
};
}
function outputFromProtobuf({ expr }) {
return { expr };
}
function resourcePolicyFromProtobuf({ resource, version, importDerivedRoles, rules, schemas, scope, variables, }) {
return {
resourcePolicy: {
resource,
version,
importDerivedRoles,
rules: rules.map(resourceRuleFromProtobuf),
schemas: schemas && schemaRefsFromProtobuf(schemas),
scope,
variables: variables && variablesFromProtobuf(variables),
},
};
}
function resourceRuleFromProtobuf({ actions, effect, derivedRoles, roles, condition, name, output, }) {
return {
actions,
effect: effectFromProtobuf(effect),
derivedRoles,
roles,
condition: condition && conditionFromProtobuf(condition),
name,
output: output && outputFromProtobuf(output),
};
}
function schemaRefsFromProtobuf({ principalSchema, resourceSchema, }) {
return {
principalSchema: principalSchema && schemaRefFromProtobuf(principalSchema),
resourceSchema: resourceSchema && schemaRefFromProtobuf(resourceSchema),
};
}
function schemaRefFromProtobuf({ ref, ignoreWhen }) {
return {
ref,
ignoreWhen: ignoreWhen && {
actions: ignoreWhen.actions,
},
};
}
function getSchemasResponseFromProtobuf({ schemas, }) {
return {
schemas: schemas.map(schemaFromProtobuf),
};
}
exports.getSchemasResponseFromProtobuf = getSchemasResponseFromProtobuf;
const schemaFromProtobuf = ({ id, definition }) => ({
id,
definition: new external_1.SchemaDefinition(definition),
});
const listPoliciesResponseFromProtobuf = ({ policyIds, }) => ({
ids: policyIds,
});
function schemaFromProtobuf({ id, definition }) {
return {
id,
definition: new external_1.SchemaDefinition(definition),
};
}
function listPoliciesResponseFromProtobuf({ policyIds, }) {
return {
ids: policyIds,
};
}
exports.listPoliciesResponseFromProtobuf = listPoliciesResponseFromProtobuf;
const listSchemasResponseFromProtobuf = ({ schemaIds, }) => ({
ids: schemaIds,
});
function listSchemasResponseFromProtobuf({ schemaIds, }) {
return {
ids: schemaIds,
};
}
exports.listSchemasResponseFromProtobuf = listSchemasResponseFromProtobuf;
const planResourcesResponseFromProtobuf = ({ requestId, filter, validationErrors, meta, }) => {
function planResourcesResponseFromProtobuf({ requestId, filter, validationErrors, meta, }) {
if (!filter) {

@@ -253,5 +309,5 @@ throw new Error("Missing filter on PlanResources response");

};
};
}
exports.planResourcesResponseFromProtobuf = planResourcesResponseFromProtobuf;
const planKindFromProtobuf = (kind) => {
function planKindFromProtobuf(kind) {
switch (kind) {

@@ -267,4 +323,4 @@ case engine_1.PlanResourcesFilter_Kind.KIND_ALWAYS_ALLOWED:

}
};
const planOperandFromProtobuf = ({ node, }) => {
}
function planOperandFromProtobuf({ node, }) {
if (!node) {

@@ -281,7 +337,9 @@ throw new Error("Missing node on PlanResources expression operand");

}
};
const planResourcesMetadataFromProtobuf = ({ filterDebug, matchedScope, }) => ({
conditionString: filterDebug,
matchedScope,
});
}
function planResourcesMetadataFromProtobuf({ filterDebug, matchedScope, }) {
return {
conditionString: filterDebug,
matchedScope,
};
}
//# sourceMappingURL=fromProtobuf.js.map

@@ -5,12 +5,12 @@ import type { AddOrUpdatePolicyRequest, AddOrUpdateSchemaRequest, CheckResourcesRequest as CheckResourcesRequestProtobuf, DeleteSchemaRequest, DisablePolicyRequest, EnablePolicyRequest, GetPolicyRequest, GetSchemaRequest, ListPoliciesRequest as ListPoliciesRequestProtobuf, PlanResourcesRequest as PlanResourcesRequestProtobuf } from "../protobuf/cerbos/request/v1/request";

import type { GetSchemasRequest } from "../types/external/GetSchemasRequest";
export declare const addOrUpdatePoliciesRequestToProtobuf: ({ policies, }: AddOrUpdatePoliciesRequest) => AddOrUpdatePolicyRequest;
export declare const addOrUpdateSchemasRequestToProtobuf: ({ schemas, }: AddOrUpdateSchemasRequest) => AddOrUpdateSchemaRequest;
export declare const checkResourcesRequestToProtobuf: ({ principal, resources, auxData, includeMetadata, requestId, }: CheckResourcesRequest) => CheckResourcesRequestProtobuf;
export declare const deleteSchemasRequestToProtobuf: ({ ids, }: DeleteSchemasRequest) => DeleteSchemaRequest;
export declare const disablePoliciesRequestToProtobuf: ({ ids, }: DisablePoliciesRequest) => DisablePolicyRequest;
export declare const enablePoliciesRequestToProtobuf: ({ ids, }: EnablePoliciesRequest) => EnablePolicyRequest;
export declare const getPoliciesRequestToProtobuf: ({ ids, }: GetPoliciesRequest) => GetPolicyRequest;
export declare const getSchemasRequestToProtobuf: ({ ids, }: GetSchemasRequest) => GetSchemaRequest;
export declare const listPoliciesRequestToProtobuf: ({ includeDisabled, nameRegexp, scopeRegexp, versionRegexp, }: ListPoliciesRequest) => ListPoliciesRequestProtobuf;
export declare const planResourcesRequestToProtobuf: ({ principal, resource, action, auxData, includeMetadata, requestId, }: PlanResourcesRequest) => PlanResourcesRequestProtobuf;
export declare function addOrUpdatePoliciesRequestToProtobuf({ policies, }: AddOrUpdatePoliciesRequest): AddOrUpdatePolicyRequest;
export declare function addOrUpdateSchemasRequestToProtobuf({ schemas, }: AddOrUpdateSchemasRequest): AddOrUpdateSchemaRequest;
export declare function checkResourcesRequestToProtobuf({ principal, resources, auxData, includeMetadata, requestId, }: CheckResourcesRequest): CheckResourcesRequestProtobuf;
export declare function deleteSchemasRequestToProtobuf({ ids, }: DeleteSchemasRequest): DeleteSchemaRequest;
export declare function disablePoliciesRequestToProtobuf({ ids, }: DisablePoliciesRequest): DisablePolicyRequest;
export declare function enablePoliciesRequestToProtobuf({ ids, }: EnablePoliciesRequest): EnablePolicyRequest;
export declare function getPoliciesRequestToProtobuf({ ids, }: GetPoliciesRequest): GetPolicyRequest;
export declare function getSchemasRequestToProtobuf({ ids, }: GetSchemasRequest): GetSchemaRequest;
export declare function listPoliciesRequestToProtobuf({ includeDisabled, nameRegexp, scopeRegexp, versionRegexp, }: ListPoliciesRequest): ListPoliciesRequestProtobuf;
export declare function planResourcesRequestToProtobuf({ principal, resource, action, auxData, includeMetadata, requestId, }: PlanResourcesRequest): PlanResourcesRequestProtobuf;
//# sourceMappingURL=toProtobuf.d.ts.map

@@ -8,7 +8,9 @@ "use strict";

const encoder = new TextEncoder();
const addOrUpdatePoliciesRequestToProtobuf = ({ policies, }) => ({
policies: policies.map(policyToProtobuf),
});
function addOrUpdatePoliciesRequestToProtobuf({ policies, }) {
return {
policies: policies.map(policyToProtobuf),
};
}
exports.addOrUpdatePoliciesRequestToProtobuf = addOrUpdatePoliciesRequestToProtobuf;
const policyToProtobuf = (policy) => {
function policyToProtobuf(policy) {
const { apiVersion = "api.cerbos.dev/v1", description = "", disabled = false, variables = {}, } = policy;

@@ -24,4 +26,4 @@ return {

};
};
const policyTypeToProtobuf = (policy) => {
}
function policyTypeToProtobuf(policy) {
if ((0, external_1.policyIsDerivedRoles)(policy)) {

@@ -52,20 +54,26 @@ return {

throw new Error(`Unknown policy type: ${JSON.stringify(policy, null, 2)}`);
};
const derivedRolesToProtobuf = ({ derivedRoles: { name, definitions, variables }, }) => ({
name,
definitions: definitions.map(derivedRoleDefinitionToProtobuf),
variables: variables && variablesToProtobuf(variables),
});
const derivedRoleDefinitionToProtobuf = ({ name, parentRoles, condition, }) => ({
name,
parentRoles,
condition: condition && conditionToProtobuf(condition),
});
const conditionToProtobuf = ({ match }) => ({
condition: {
$case: "match",
match: matchToProtobuf(match),
},
});
const matchToProtobuf = (match) => {
}
function derivedRolesToProtobuf({ derivedRoles: { name, definitions, variables }, }) {
return {
name,
definitions: definitions.map(derivedRoleDefinitionToProtobuf),
variables: variables && variablesToProtobuf(variables),
};
}
function derivedRoleDefinitionToProtobuf({ name, parentRoles, condition, }) {
return {
name,
parentRoles,
condition: condition && conditionToProtobuf(condition),
};
}
function conditionToProtobuf({ match }) {
return {
condition: {
$case: "match",
match: matchToProtobuf(match),
},
};
}
function matchToProtobuf(match) {
if ((0, external_1.matchIsMatchAll)(match)) {

@@ -104,71 +112,99 @@ return {

throw new Error(`Unknown match type: ${JSON.stringify(match, null, 2)}`);
};
const matchesToProtobuf = ({ of }) => ({
of: of.map(matchToProtobuf),
});
const variablesToProtobuf = ({ import: imports = [], local = {}, }) => ({
import: imports,
local,
});
const exportVariablesToProtobuf = ({ exportVariables: { name, definitions }, }) => ({
name,
definitions,
});
const principalPolicyToProtobuf = ({ principalPolicy: { principal, version, rules, scope = "", variables }, }) => ({
principal,
version,
rules: rules.map(principalRuleToProtobuf),
scope,
variables: variables && variablesToProtobuf(variables),
});
const principalRuleToProtobuf = ({ resource, actions, }) => ({
resource,
actions: actions.map(principalRuleActionToProtobuf),
});
const principalRuleActionToProtobuf = ({ action, effect, condition, name = "", output, }) => ({
action,
effect: effectToProtobuf(effect),
condition: condition && conditionToProtobuf(condition),
name,
output: output && outputToProtobuf(output),
});
const effectToProtobuf = (effect) => effect === external_1.Effect.ALLOW
? effect_1.Effect.EFFECT_ALLOW
: effect_1.Effect.EFFECT_DENY;
const outputToProtobuf = ({ expr }) => ({ expr });
const resourcePolicyToProtobuf = ({ resourcePolicy: { resource, version, importDerivedRoles = [], rules, scope = "", schemas, variables, }, }) => ({
resource,
version,
importDerivedRoles,
rules: rules.map(resourceRuleToProtobuf),
scope,
schemas: schemas && policySchemasToProtobuf(schemas),
variables: variables && variablesToProtobuf(variables),
});
const resourceRuleToProtobuf = ({ actions, effect, derivedRoles = [], roles = [], condition, name = "", output, }) => ({
actions,
effect: effectToProtobuf(effect),
derivedRoles,
roles,
condition: condition && conditionToProtobuf(condition),
name,
output: output && outputToProtobuf(output),
});
const policySchemasToProtobuf = ({ principalSchema, resourceSchema, }) => ({
principalSchema: principalSchema && policySchemaToProtobuf(principalSchema),
resourceSchema: resourceSchema && policySchemaToProtobuf(resourceSchema),
});
const policySchemaToProtobuf = ({ ref, ignoreWhen, }) => ({
ref,
ignoreWhen,
});
const addOrUpdateSchemasRequestToProtobuf = ({ schemas, }) => ({
schemas: schemas.map(schemaToProtobuf),
});
}
function matchesToProtobuf({ of }) {
return {
of: of.map(matchToProtobuf),
};
}
function variablesToProtobuf({ import: imports = [], local = {}, }) {
return {
import: imports,
local,
};
}
function exportVariablesToProtobuf({ exportVariables: { name, definitions }, }) {
return {
name,
definitions,
};
}
function principalPolicyToProtobuf({ principalPolicy: { principal, version, rules, scope = "", variables }, }) {
return {
principal,
version,
rules: rules.map(principalRuleToProtobuf),
scope,
variables: variables && variablesToProtobuf(variables),
};
}
function principalRuleToProtobuf({ resource, actions, }) {
return {
resource,
actions: actions.map(principalRuleActionToProtobuf),
};
}
function principalRuleActionToProtobuf({ action, effect, condition, name = "", output, }) {
return {
action,
effect: effectToProtobuf(effect),
condition: condition && conditionToProtobuf(condition),
name,
output: output && outputToProtobuf(output),
};
}
function effectToProtobuf(effect) {
return effect === external_1.Effect.ALLOW
? effect_1.Effect.EFFECT_ALLOW
: effect_1.Effect.EFFECT_DENY;
}
function outputToProtobuf({ expr }) {
return { expr };
}
function resourcePolicyToProtobuf({ resourcePolicy: { resource, version, importDerivedRoles = [], rules, scope = "", schemas, variables, }, }) {
return {
resource,
version,
importDerivedRoles,
rules: rules.map(resourceRuleToProtobuf),
scope,
schemas: schemas && policySchemasToProtobuf(schemas),
variables: variables && variablesToProtobuf(variables),
};
}
function resourceRuleToProtobuf({ actions, effect, derivedRoles = [], roles = [], condition, name = "", output, }) {
return {
actions,
effect: effectToProtobuf(effect),
derivedRoles,
roles,
condition: condition && conditionToProtobuf(condition),
name,
output: output && outputToProtobuf(output),
};
}
function policySchemasToProtobuf({ principalSchema, resourceSchema, }) {
return {
principalSchema: principalSchema && policySchemaToProtobuf(principalSchema),
resourceSchema: resourceSchema && policySchemaToProtobuf(resourceSchema),
};
}
function policySchemaToProtobuf({ ref, ignoreWhen, }) {
return {
ref,
ignoreWhen,
};
}
function addOrUpdateSchemasRequestToProtobuf({ schemas, }) {
return {
schemas: schemas.map(schemaToProtobuf),
};
}
exports.addOrUpdateSchemasRequestToProtobuf = addOrUpdateSchemasRequestToProtobuf;
const schemaToProtobuf = ({ id, definition }) => ({
id,
definition: schemaDefinitionToProtobuf(definition),
});
const schemaDefinitionToProtobuf = (definition) => {
function schemaToProtobuf({ id, definition }) {
return {
id,
definition: schemaDefinitionToProtobuf(definition),
};
}
function schemaDefinitionToProtobuf(definition) {
if (definition instanceof Uint8Array) {

@@ -184,78 +220,106 @@ return definition;

return encoder.encode(JSON.stringify(definition));
};
const checkResourcesRequestToProtobuf = ({ principal, resources, auxData, includeMetadata = false, requestId = (0, uuid_1.v4)(), }) => ({
principal: principalToProtobuf(principal),
resources: resources.map(resourceCheckToProtobuf),
auxData: auxData && auxDataToProtobuf(auxData),
includeMeta: includeMetadata,
requestId,
});
}
function checkResourcesRequestToProtobuf({ principal, resources, auxData, includeMetadata = false, requestId = (0, uuid_1.v4)(), }) {
return {
principal: principalToProtobuf(principal),
resources: resources.map(resourceCheckToProtobuf),
auxData: auxData && auxDataToProtobuf(auxData),
includeMeta: includeMetadata,
requestId,
};
}
exports.checkResourcesRequestToProtobuf = checkResourcesRequestToProtobuf;
const principalToProtobuf = ({ id, roles, attributes = {}, policyVersion = "", scope = "", }) => ({
id,
roles,
attr: attributes,
policyVersion,
scope,
});
const resourceCheckToProtobuf = ({ resource, actions, }) => ({
resource: resourceToProtobuf(resource),
actions,
});
const resourceToProtobuf = ({ kind, id, attributes = {}, policyVersion = "", scope = "", }) => ({
kind,
id,
attr: attributes,
policyVersion,
scope,
});
const auxDataToProtobuf = ({ jwt }) => ({
jwt: jwt && jwtToProtobuf(jwt),
});
const jwtToProtobuf = ({ token, keySetId = "" }) => ({
token,
keySetId,
});
const deleteSchemasRequestToProtobuf = ({ ids, }) => ({
id: ids,
});
function principalToProtobuf({ id, roles, attributes = {}, policyVersion = "", scope = "", }) {
return {
id,
roles,
attr: attributes,
policyVersion,
scope,
};
}
function resourceCheckToProtobuf({ resource, actions, }) {
return {
resource: resourceToProtobuf(resource),
actions,
};
}
function resourceToProtobuf({ kind, id, attributes = {}, policyVersion = "", scope = "", }) {
return {
kind,
id,
attr: attributes,
policyVersion,
scope,
};
}
function auxDataToProtobuf({ jwt }) {
return {
jwt: jwt && jwtToProtobuf(jwt),
};
}
function jwtToProtobuf({ token, keySetId = "" }) {
return {
token,
keySetId,
};
}
function deleteSchemasRequestToProtobuf({ ids, }) {
return {
id: ids,
};
}
exports.deleteSchemasRequestToProtobuf = deleteSchemasRequestToProtobuf;
const disablePoliciesRequestToProtobuf = ({ ids, }) => ({
id: ids,
});
function disablePoliciesRequestToProtobuf({ ids, }) {
return {
id: ids,
};
}
exports.disablePoliciesRequestToProtobuf = disablePoliciesRequestToProtobuf;
const enablePoliciesRequestToProtobuf = ({ ids, }) => ({
id: ids,
});
function enablePoliciesRequestToProtobuf({ ids, }) {
return {
id: ids,
};
}
exports.enablePoliciesRequestToProtobuf = enablePoliciesRequestToProtobuf;
const getPoliciesRequestToProtobuf = ({ ids, }) => ({
id: ids,
});
function getPoliciesRequestToProtobuf({ ids, }) {
return {
id: ids,
};
}
exports.getPoliciesRequestToProtobuf = getPoliciesRequestToProtobuf;
const getSchemasRequestToProtobuf = ({ ids, }) => ({
id: ids,
});
function getSchemasRequestToProtobuf({ ids, }) {
return {
id: ids,
};
}
exports.getSchemasRequestToProtobuf = getSchemasRequestToProtobuf;
const listPoliciesRequestToProtobuf = ({ includeDisabled = false, nameRegexp = "", scopeRegexp = "", versionRegexp = "", }) => ({
includeDisabled,
nameRegexp,
scopeRegexp,
versionRegexp,
});
function listPoliciesRequestToProtobuf({ includeDisabled = false, nameRegexp = "", scopeRegexp = "", versionRegexp = "", }) {
return {
includeDisabled,
nameRegexp,
scopeRegexp,
versionRegexp,
};
}
exports.listPoliciesRequestToProtobuf = listPoliciesRequestToProtobuf;
const planResourcesRequestToProtobuf = ({ principal, resource, action, auxData, includeMetadata = false, requestId = (0, uuid_1.v4)(), }) => ({
principal: principalToProtobuf(principal),
resource: resourceQueryToProtobuf(resource),
action,
auxData: auxData && auxDataToProtobuf(auxData),
includeMeta: includeMetadata,
requestId,
});
function planResourcesRequestToProtobuf({ principal, resource, action, auxData, includeMetadata = false, requestId = (0, uuid_1.v4)(), }) {
return {
principal: principalToProtobuf(principal),
resource: resourceQueryToProtobuf(resource),
action,
auxData: auxData && auxDataToProtobuf(auxData),
includeMeta: includeMetadata,
requestId,
};
}
exports.planResourcesRequestToProtobuf = planResourcesRequestToProtobuf;
const resourceQueryToProtobuf = ({ kind, attributes = {}, policyVersion = "", scope = "", }) => ({
kind,
attr: attributes,
policyVersion,
scope,
});
function resourceQueryToProtobuf({ kind, attributes = {}, policyVersion = "", scope = "", }) {
return {
kind,
attr: attributes,
policyVersion,
scope,
};
}
//# sourceMappingURL=toProtobuf.js.map

@@ -83,3 +83,3 @@ "use strict";

exports.NotOK = NotOK;
const code = (error) => {
function code(error) {
if (has(error, "code") &&

@@ -91,4 +91,4 @@ typeof error.code === "number" &&

throw new Error("Error does not include expected code");
};
const details = (error) => {
}
function details(error) {
if (has(error, "message") && typeof error.message === "string") {

@@ -98,4 +98,6 @@ return error.message;

throw new Error("Error does not include expected details");
};
const has = (object, property) => !!object && Object.prototype.hasOwnProperty.call(object, property);
}
function has(object, property) {
return !!object && Object.prototype.hasOwnProperty.call(object, property);
}
/**

@@ -102,0 +104,0 @@ * Error thrown when input fails schema validation, if the {@link @cerbos/core#Client} is configured with {@link @cerbos/core#Options.onValidationError | onValidationError} set to `"throw"`.

@@ -16,3 +16,3 @@ import type { MatchAll } from "./MatchAll";

*/
export declare const matchIsMatchAll: (match: Match) => match is MatchAll;
export declare function matchIsMatchAll(match: Match): match is MatchAll;
/**

@@ -23,3 +23,3 @@ * Type guard to check if a {@link Match} is a {@link MatchAny}.

*/
export declare const matchIsMatchAny: (match: Match) => match is MatchAny;
export declare function matchIsMatchAny(match: Match): match is MatchAny;
/**

@@ -30,3 +30,3 @@ * Type guard to check if a {@link Match} is a {@link MatchNone}.

*/
export declare const matchIsMatchNone: (match: Match) => match is MatchNone;
export declare function matchIsMatchNone(match: Match): match is MatchNone;
/**

@@ -37,3 +37,3 @@ * Type guard to check if a {@link Match} is a {@link MatchExpr}.

*/
export declare const matchIsMatchExpr: (match: Match) => match is MatchExpr;
export declare function matchIsMatchExpr(match: Match): match is MatchExpr;
//# sourceMappingURL=Match.d.ts.map

@@ -9,3 +9,5 @@ "use strict";

*/
const matchIsMatchAll = (match) => "all" in match;
function matchIsMatchAll(match) {
return "all" in match;
}
exports.matchIsMatchAll = matchIsMatchAll;

@@ -17,3 +19,5 @@ /**

*/
const matchIsMatchAny = (match) => "any" in match;
function matchIsMatchAny(match) {
return "any" in match;
}
exports.matchIsMatchAny = matchIsMatchAny;

@@ -25,3 +29,5 @@ /**

*/
const matchIsMatchNone = (match) => "none" in match;
function matchIsMatchNone(match) {
return "none" in match;
}
exports.matchIsMatchNone = matchIsMatchNone;

@@ -33,4 +39,6 @@ /**

*/
const matchIsMatchExpr = (match) => "expr" in match;
function matchIsMatchExpr(match) {
return "expr" in match;
}
exports.matchIsMatchExpr = matchIsMatchExpr;
//# sourceMappingURL=Match.js.map

@@ -16,3 +16,3 @@ import type { DerivedRoles } from "./DerivedRoles";

*/
export declare const policyIsDerivedRoles: (policy: Policy) => policy is DerivedRoles;
export declare function policyIsDerivedRoles(policy: Policy): policy is DerivedRoles;
/**

@@ -23,3 +23,3 @@ * Type guard to check if a {@link Policy} is a set of {@link ExportVariables}.

*/
export declare const policyIsExportVariables: (policy: Policy) => policy is ExportVariables;
export declare function policyIsExportVariables(policy: Policy): policy is ExportVariables;
/**

@@ -30,3 +30,3 @@ * Type guard to check if a {@link Policy} is a {@link PrincipalPolicy}.

*/
export declare const policyIsPrincipalPolicy: (policy: Policy) => policy is PrincipalPolicy;
export declare function policyIsPrincipalPolicy(policy: Policy): policy is PrincipalPolicy;
/**

@@ -37,3 +37,3 @@ * Type guard to check if a {@link Policy} is a {@link ResourcePolicy}.

*/
export declare const policyIsResourcePolicy: (policy: Policy) => policy is ResourcePolicy;
export declare function policyIsResourcePolicy(policy: Policy): policy is ResourcePolicy;
//# sourceMappingURL=Policy.d.ts.map

@@ -9,3 +9,5 @@ "use strict";

*/
const policyIsDerivedRoles = (policy) => "derivedRoles" in policy;
function policyIsDerivedRoles(policy) {
return "derivedRoles" in policy;
}
exports.policyIsDerivedRoles = policyIsDerivedRoles;

@@ -17,3 +19,5 @@ /**

*/
const policyIsExportVariables = (policy) => "exportVariables" in policy;
function policyIsExportVariables(policy) {
return "exportVariables" in policy;
}
exports.policyIsExportVariables = policyIsExportVariables;

@@ -25,3 +29,5 @@ /**

*/
const policyIsPrincipalPolicy = (policy) => "principalPolicy" in policy;
function policyIsPrincipalPolicy(policy) {
return "principalPolicy" in policy;
}
exports.policyIsPrincipalPolicy = policyIsPrincipalPolicy;

@@ -33,4 +39,6 @@ /**

*/
const policyIsResourcePolicy = (policy) => "resourcePolicy" in policy;
function policyIsResourcePolicy(policy) {
return "resourcePolicy" in policy;
}
exports.policyIsResourcePolicy = policyIsResourcePolicy;
//# sourceMappingURL=Policy.js.map
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>;
export declare function isObject(value: unknown): value is Record<string, unknown>;
//# sourceMappingURL=internal.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isObject = void 0;
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
function isObject(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
exports.isObject = isObject;
//# sourceMappingURL=internal.js.map
{
"name": "@cerbos/core",
"version": "0.12.0",
"version": "0.13.0",
"description": "Common types used by the @cerbos/grpc and @cerbos/http client libraries",

@@ -5,0 +5,0 @@ "repository": {

@@ -63,2 +63,3 @@ import {

adminCredentials?: AdminCredentials,
metadata?: Record<string, string>,
) => Promise<_Response<Service, RPC>>;

@@ -72,10 +73,10 @@

/** @internal */
export const _addInstrumenter = (instrumenter: _Instrumenter): void => {
export function _addInstrumenter(instrumenter: _Instrumenter): void {
instrumenters.add(instrumenter);
};
}
/** @internal */
export const _removeInstrumenter = (instrumenter: _Instrumenter): void => {
export function _removeInstrumenter(instrumenter: _Instrumenter): void {
instrumenters.delete(instrumenter);
};
}

@@ -168,2 +169,4 @@ /**

* @example
* Create a policy in code:
*
* ```typescript

@@ -184,2 +187,25 @@ * await cerbos.addOrUpdatePolicies({

* ```
*
* @example
* Load a policy from a YAML or JSON file with {@link @cerbos/files#readPolicy}:
*
* ```typescript
* import { readPolicy } from "@cerbos/files";
*
* await cerbos.addOrUpdatePolicies({
* policies: [await readPolicy("path/to/policy.yaml")],
* });
* ```
*
* @example
* Load policies and schemas from a directory with {@link @cerbos/files#readDirectory}:
*
* ```typescript
* import { readDirectory } from "@cerbos/files";
*
* const { policies, schemas } = await readDirectory("path/to/directory");
*
* await cerbos.addOrUpdateSchemas({ schemas });
* await cerbos.addOrUpdatePolicies({ policies });
* ```
*/

@@ -208,13 +234,41 @@ public async addOrUpdatePolicies(

* @example
* Create a schema in code:
*
* ```typescript
* await cerbos.addOrUpdateSchemas([{
* id: "document.json",
* definition: `{
* "type": "object",
* "properties": {
* "owner": { "type": "string" }
* }
* }`,
* }]);
*
* await cerbos.addOrUpdateSchemas({
* schemas: [{
* id: "document.json",
* definition: {
* type: "object",
* properties: {
* owner: { type: "string" }
* }
* },
* }],
* });
* ```
*
* @example
* Load a schema from a JSON file with {@link @cerbos/files#readSchema}:
*
* ```typescript
* import { readSchema } from "@cerbos/files";
*
* await cerbos.addOrUpdateSchemas({
* schemas: [await readSchema("_schemas/path/to/schema.json")],
* });
* ```
*
* @example
* Load policies and schemas from a directory with {@link @cerbos/files#readDirectory}:
*
* ```typescript
* import { readDirectory } from "@cerbos/files";
*
* const { policies, schemas } = await readDirectory("path/to/directory");
*
* await cerbos.addOrUpdateSchemas({ schemas });
* await cerbos.addOrUpdatePolicies({ policies });
* ```
*/

@@ -221,0 +275,0 @@ public async addOrUpdateSchemas(

@@ -91,12 +91,13 @@ import { Effect as EffectProtobuf } from "../protobuf/cerbos/effect/v1/effect";

export const checkResourcesResponseFromProtobuf = ({
export function checkResourcesResponseFromProtobuf({
requestId,
results,
}: CheckResourcesResponseProtobuf): CheckResourcesResponse =>
new CheckResourcesResponse({
}: CheckResourcesResponseProtobuf): CheckResourcesResponse {
return new CheckResourcesResponse({
requestId,
results: results.map(checkResourcesResultFromProtobuf),
});
}
const checkResourcesResultFromProtobuf = ({
function checkResourcesResultFromProtobuf({
resource,

@@ -107,3 +108,3 @@ actions,

outputs,
}: CheckResourcesResponse_ResultEntry): CheckResourcesResult => {
}: CheckResourcesResponse_ResultEntry): CheckResourcesResult {
if (!resource) {

@@ -120,8 +121,8 @@ throw new Error("Missing resource on CheckResources result");

});
};
}
const actionsFromProtobuf = (
function actionsFromProtobuf(
actions: Record<string, EffectProtobuf>,
): Record<string, Effect | undefined> =>
Object.fromEntries(
): Record<string, Effect | undefined> {
return Object.fromEntries(
Object.entries(actions).map(([action, effect]) => [

@@ -132,19 +133,23 @@ action,

);
}
const effectFromProtobuf = (effect: EffectProtobuf): Effect =>
effect === EffectProtobuf.EFFECT_ALLOW ? Effect.ALLOW : Effect.DENY;
function effectFromProtobuf(effect: EffectProtobuf): Effect {
return effect === EffectProtobuf.EFFECT_ALLOW ? Effect.ALLOW : Effect.DENY;
}
const validationErrorFromProtobuf = ({
function validationErrorFromProtobuf({
path,
message,
source,
}: ValidationErrorProtobuf): ValidationError => ({
path,
message,
source: validationErrorSourceFromProtobuf(source),
});
}: ValidationErrorProtobuf): ValidationError {
return {
path,
message,
source: validationErrorSourceFromProtobuf(source),
};
}
const validationErrorSourceFromProtobuf = (
function validationErrorSourceFromProtobuf(
source: ValidationError_Source,
): ValidationErrorSource => {
): ValidationErrorSource {
switch (source) {

@@ -164,35 +169,45 @@ case ValidationError_Source.SOURCE_PRINCIPAL:

}
};
}
const outputResultFromProtobuf = ({ src, val }: OutputEntry): OutputResult => ({
source: src,
value: val as Value | undefined,
});
function outputResultFromProtobuf({ src, val }: OutputEntry): OutputResult {
return {
source: src,
value: val as Value | undefined,
};
}
export const deleteSchemasResponseFromProtobuf = ({
export function deleteSchemasResponseFromProtobuf({
deletedSchemas,
}: DeleteSchemaResponse): DeleteSchemasResponse => ({
deletedSchemas,
});
}: DeleteSchemaResponse): DeleteSchemasResponse {
return {
deletedSchemas,
};
}
export const disablePoliciesResponseFromProtobuf = ({
export function disablePoliciesResponseFromProtobuf({
disabledPolicies,
}: DisablePolicyResponse): DisablePoliciesResponse => ({
disabledPolicies,
});
}: DisablePolicyResponse): DisablePoliciesResponse {
return {
disabledPolicies,
};
}
export const enablePoliciesResponseFromProtobuf = ({
export function enablePoliciesResponseFromProtobuf({
enabledPolicies,
}: EnablePolicyResponse): EnablePoliciesResponse => ({
enabledPolicies,
});
}: EnablePolicyResponse): EnablePoliciesResponse {
return {
enabledPolicies,
};
}
export const getPoliciesResponseFromProtobuf = ({
export function getPoliciesResponseFromProtobuf({
policies,
}: GetPolicyResponse): GetPoliciesResponse => ({
policies: policies.map(_policyFromProtobuf),
});
}: GetPolicyResponse): GetPoliciesResponse {
return {
policies: policies.map(_policyFromProtobuf),
};
}
/** @internal */
export const _policyFromProtobuf = ({
export function _policyFromProtobuf({
apiVersion,

@@ -204,12 +219,14 @@ description,

policyType,
}: PolicyProtobuf): Policy => ({
apiVersion,
description,
disabled,
metadata: metadata && policyMetadataFromProtobuf(metadata),
variables,
...policyTypeFromProtobuf(policyType),
});
}: PolicyProtobuf): Policy {
return {
apiVersion,
description,
disabled,
metadata: metadata && policyMetadataFromProtobuf(metadata),
variables,
...policyTypeFromProtobuf(policyType),
};
}
const policyMetadataFromProtobuf = ({
function policyMetadataFromProtobuf({
annotations,

@@ -220,15 +237,17 @@ hash,

storeIdentifier,
}: Metadata): PolicyMetadata => ({
annotations,
hash,
sourceFile,
storeIdentifer: storeIdentifier || storeIdentifer,
storeIdentifier: storeIdentifier || storeIdentifer,
});
}: Metadata): PolicyMetadata {
return {
annotations,
hash,
sourceFile,
storeIdentifer: storeIdentifier || storeIdentifer,
storeIdentifier: storeIdentifier || storeIdentifer,
};
}
type OmitPolicyBase<T extends Policy> = OmitFromEach<T, keyof PolicyBase>;
const policyTypeFromProtobuf = (
function policyTypeFromProtobuf(
policyType: PolicyProtobuf["policyType"],
): OmitPolicyBase<Policy> => {
): OmitPolicyBase<Policy> {
if (!policyType) {

@@ -256,27 +275,31 @@ throw new Error("Unknown policy type: undefined");

}
};
}
const derivedRolesFromProtobuf = ({
function derivedRolesFromProtobuf({
name,
definitions,
variables,
}: DerivedRolesProtobuf): OmitPolicyBase<DerivedRoles> => ({
derivedRoles: {
name,
definitions: definitions.map(derivedRoleDefinitionFromProtobuf),
variables: variables && variablesFromProtobuf(variables),
},
});
}: DerivedRolesProtobuf): OmitPolicyBase<DerivedRoles> {
return {
derivedRoles: {
name,
definitions: definitions.map(derivedRoleDefinitionFromProtobuf),
variables: variables && variablesFromProtobuf(variables),
},
};
}
const derivedRoleDefinitionFromProtobuf = ({
function derivedRoleDefinitionFromProtobuf({
name,
parentRoles,
condition,
}: RoleDef): DerivedRoleDefinition => ({
name,
parentRoles,
condition: condition && conditionFromProtobuf(condition),
});
}: RoleDef): DerivedRoleDefinition {
return {
name,
parentRoles,
condition: condition && conditionFromProtobuf(condition),
};
}
const conditionFromProtobuf = ({ condition }: ConditionProtobuf): Condition => {
function conditionFromProtobuf({ condition }: ConditionProtobuf): Condition {
switch (condition?.$case) {

@@ -293,5 +316,5 @@ case "match":

}
};
}
const matchFromProtobuf = ({ op }: MatchProtobuf): Match => {
function matchFromProtobuf({ op }: MatchProtobuf): Match {
switch (op?.$case) {

@@ -321,27 +344,33 @@ case "all":

}
};
}
const matchesFromProtobuf = ({ of }: Match_ExprList): Matches => ({
of: of.map(matchFromProtobuf),
});
function matchesFromProtobuf({ of }: Match_ExprList): Matches {
return {
of: of.map(matchFromProtobuf),
};
}
const variablesFromProtobuf = ({
function variablesFromProtobuf({
import: imports,
local,
}: VariablesProtobuf): Variables => ({
import: imports,
local,
});
}: VariablesProtobuf): Variables {
return {
import: imports,
local,
};
}
const exportVariablesFromProtobuf = ({
function exportVariablesFromProtobuf({
name,
definitions,
}: ExportVariablesProtobuf): OmitPolicyBase<ExportVariables> => ({
exportVariables: {
name,
definitions,
},
});
}: ExportVariablesProtobuf): OmitPolicyBase<ExportVariables> {
return {
exportVariables: {
name,
definitions,
},
};
}
const principalPolicyFromProtobuf = ({
function principalPolicyFromProtobuf({
principal,

@@ -352,21 +381,25 @@ version,

variables,
}: PrincipalPolicyProtobuf): OmitPolicyBase<PrincipalPolicy> => ({
principalPolicy: {
principal,
version,
rules: rules.map(principalRuleFromProtobuf),
scope,
variables: variables && variablesFromProtobuf(variables),
},
});
}: PrincipalPolicyProtobuf): OmitPolicyBase<PrincipalPolicy> {
return {
principalPolicy: {
principal,
version,
rules: rules.map(principalRuleFromProtobuf),
scope,
variables: variables && variablesFromProtobuf(variables),
},
};
}
const principalRuleFromProtobuf = ({
function principalRuleFromProtobuf({
resource,
actions,
}: PrincipalRuleProtobuf): PrincipalRule => ({
resource,
actions: actions.map(principalRuleActionFromProtobuf),
});
}: PrincipalRuleProtobuf): PrincipalRule {
return {
resource,
actions: actions.map(principalRuleActionFromProtobuf),
};
}
const principalRuleActionFromProtobuf = ({
function principalRuleActionFromProtobuf({
action,

@@ -377,13 +410,17 @@ effect,

output,
}: PrincipalRule_Action): PrincipalRuleAction => ({
action,
effect: effectFromProtobuf(effect),
condition: condition && conditionFromProtobuf(condition),
name,
output: output && outputFromProtobuf(output),
});
}: PrincipalRule_Action): PrincipalRuleAction {
return {
action,
effect: effectFromProtobuf(effect),
condition: condition && conditionFromProtobuf(condition),
name,
output: output && outputFromProtobuf(output),
};
}
const outputFromProtobuf = ({ expr }: OutputProtobuf): Output => ({ expr });
function outputFromProtobuf({ expr }: OutputProtobuf): Output {
return { expr };
}
const resourcePolicyFromProtobuf = ({
function resourcePolicyFromProtobuf({
resource,

@@ -396,15 +433,17 @@ version,

variables,
}: ResourcePolicyProtobuf): OmitPolicyBase<ResourcePolicy> => ({
resourcePolicy: {
resource,
version,
importDerivedRoles,
rules: rules.map(resourceRuleFromProtobuf),
schemas: schemas && schemaRefsFromProtobuf(schemas),
scope,
variables: variables && variablesFromProtobuf(variables),
},
});
}: ResourcePolicyProtobuf): OmitPolicyBase<ResourcePolicy> {
return {
resourcePolicy: {
resource,
version,
importDerivedRoles,
rules: rules.map(resourceRuleFromProtobuf),
schemas: schemas && schemaRefsFromProtobuf(schemas),
scope,
variables: variables && variablesFromProtobuf(variables),
},
};
}
const resourceRuleFromProtobuf = ({
function resourceRuleFromProtobuf({
actions,

@@ -417,54 +456,65 @@ effect,

output,
}: ResourceRuleProtobuf): ResourceRule => ({
actions,
effect: effectFromProtobuf(effect),
derivedRoles,
roles,
condition: condition && conditionFromProtobuf(condition),
name,
output: output && outputFromProtobuf(output),
});
}: ResourceRuleProtobuf): ResourceRule {
return {
actions,
effect: effectFromProtobuf(effect),
derivedRoles,
roles,
condition: condition && conditionFromProtobuf(condition),
name,
output: output && outputFromProtobuf(output),
};
}
const schemaRefsFromProtobuf = ({
function schemaRefsFromProtobuf({
principalSchema,
resourceSchema,
}: Schemas): SchemaRefs => ({
principalSchema: principalSchema && schemaRefFromProtobuf(principalSchema),
resourceSchema: resourceSchema && schemaRefFromProtobuf(resourceSchema),
});
}: Schemas): SchemaRefs {
return {
principalSchema: principalSchema && schemaRefFromProtobuf(principalSchema),
resourceSchema: resourceSchema && schemaRefFromProtobuf(resourceSchema),
};
}
const schemaRefFromProtobuf = ({
ref,
ignoreWhen,
}: Schemas_Schema): SchemaRef => ({
ref,
ignoreWhen: ignoreWhen && {
actions: ignoreWhen.actions,
},
});
function schemaRefFromProtobuf({ ref, ignoreWhen }: Schemas_Schema): SchemaRef {
return {
ref,
ignoreWhen: ignoreWhen && {
actions: ignoreWhen.actions,
},
};
}
export const getSchemasResponseFromProtobuf = ({
export function getSchemasResponseFromProtobuf({
schemas,
}: GetSchemaResponse): GetSchemasResponse => ({
schemas: schemas.map(schemaFromProtobuf),
});
}: GetSchemaResponse): GetSchemasResponse {
return {
schemas: schemas.map(schemaFromProtobuf),
};
}
const schemaFromProtobuf = ({ id, definition }: SchemaProtobuf): Schema => ({
id,
definition: new SchemaDefinition(definition),
});
function schemaFromProtobuf({ id, definition }: SchemaProtobuf): Schema {
return {
id,
definition: new SchemaDefinition(definition),
};
}
export const listPoliciesResponseFromProtobuf = ({
export function listPoliciesResponseFromProtobuf({
policyIds,
}: ListPoliciesResponseProtobuf): ListPoliciesResponse => ({
ids: policyIds,
});
}: ListPoliciesResponseProtobuf): ListPoliciesResponse {
return {
ids: policyIds,
};
}
export const listSchemasResponseFromProtobuf = ({
export function listSchemasResponseFromProtobuf({
schemaIds,
}: ListSchemasResponseProtobuf): ListSchemasResponse => ({
ids: schemaIds,
});
}: ListSchemasResponseProtobuf): ListSchemasResponse {
return {
ids: schemaIds,
};
}
export const planResourcesResponseFromProtobuf = ({
export function planResourcesResponseFromProtobuf({
requestId,

@@ -474,3 +524,3 @@ filter,

meta,
}: PlanResourcesResponseProtobuf): PlanResourcesResponse => {
}: PlanResourcesResponseProtobuf): PlanResourcesResponse {
if (!filter) {

@@ -503,5 +553,5 @@ throw new Error("Missing filter on PlanResources response");

};
};
}
const planKindFromProtobuf = (kind: PlanResourcesFilter_Kind): PlanKind => {
function planKindFromProtobuf(kind: PlanResourcesFilter_Kind): PlanKind {
switch (kind) {

@@ -524,7 +574,7 @@ case PlanResourcesFilter_Kind.KIND_ALWAYS_ALLOWED:

}
};
}
const planOperandFromProtobuf = ({
function planOperandFromProtobuf({
node,
}: PlanResourcesFilter_Expression_Operand): PlanExpressionOperand => {
}: PlanResourcesFilter_Expression_Operand): PlanExpressionOperand {
if (!node) {

@@ -547,10 +597,12 @@ throw new Error("Missing node on PlanResources expression operand");

}
};
}
const planResourcesMetadataFromProtobuf = ({
function planResourcesMetadataFromProtobuf({
filterDebug,
matchedScope,
}: PlanResourcesResponse_Meta): PlanResourcesMetadata => ({
conditionString: filterDebug,
matchedScope,
});
}: PlanResourcesResponse_Meta): PlanResourcesMetadata {
return {
conditionString: filterDebug,
matchedScope,
};
}

@@ -94,9 +94,11 @@ import { v4 as uuidv4 } from "uuid";

export const addOrUpdatePoliciesRequestToProtobuf = ({
export function addOrUpdatePoliciesRequestToProtobuf({
policies,
}: AddOrUpdatePoliciesRequest): AddOrUpdatePolicyRequest => ({
policies: policies.map(policyToProtobuf),
});
}: AddOrUpdatePoliciesRequest): AddOrUpdatePolicyRequest {
return {
policies: policies.map(policyToProtobuf),
};
}
const policyToProtobuf = (policy: Policy): PolicyProtobuf => {
function policyToProtobuf(policy: Policy): PolicyProtobuf {
const {

@@ -118,7 +120,7 @@ apiVersion = "api.cerbos.dev/v1",

};
};
}
const policyTypeToProtobuf = (
function policyTypeToProtobuf(
policy: Policy,
): Exclude<PolicyProtobuf["policyType"], undefined> => {
): Exclude<PolicyProtobuf["policyType"], undefined> {
if (policyIsDerivedRoles(policy)) {

@@ -153,30 +155,36 @@ return {

throw new Error(`Unknown policy type: ${JSON.stringify(policy, null, 2)}`);
};
}
const derivedRolesToProtobuf = ({
function derivedRolesToProtobuf({
derivedRoles: { name, definitions, variables },
}: DerivedRoles): DerivedRolesProtobuf => ({
name,
definitions: definitions.map(derivedRoleDefinitionToProtobuf),
variables: variables && variablesToProtobuf(variables),
});
}: DerivedRoles): DerivedRolesProtobuf {
return {
name,
definitions: definitions.map(derivedRoleDefinitionToProtobuf),
variables: variables && variablesToProtobuf(variables),
};
}
const derivedRoleDefinitionToProtobuf = ({
function derivedRoleDefinitionToProtobuf({
name,
parentRoles,
condition,
}: DerivedRoleDefinition): RoleDef => ({
name,
parentRoles,
condition: condition && conditionToProtobuf(condition),
});
}: DerivedRoleDefinition): RoleDef {
return {
name,
parentRoles,
condition: condition && conditionToProtobuf(condition),
};
}
const conditionToProtobuf = ({ match }: Condition): ConditionProtobuf => ({
condition: {
$case: "match",
match: matchToProtobuf(match),
},
});
function conditionToProtobuf({ match }: Condition): ConditionProtobuf {
return {
condition: {
$case: "match",
match: matchToProtobuf(match),
},
};
}
const matchToProtobuf = (match: Match): MatchProtobuf => {
function matchToProtobuf(match: Match): MatchProtobuf {
if (matchIsMatchAll(match)) {

@@ -219,42 +227,52 @@ return {

throw new Error(`Unknown match type: ${JSON.stringify(match, null, 2)}`);
};
}
const matchesToProtobuf = ({ of }: Matches): Match_ExprList => ({
of: of.map(matchToProtobuf),
});
function matchesToProtobuf({ of }: Matches): Match_ExprList {
return {
of: of.map(matchToProtobuf),
};
}
const variablesToProtobuf = ({
function variablesToProtobuf({
import: imports = [],
local = {},
}: Variables): VariablesProtobuf => ({
import: imports,
local,
});
}: Variables): VariablesProtobuf {
return {
import: imports,
local,
};
}
const exportVariablesToProtobuf = ({
function exportVariablesToProtobuf({
exportVariables: { name, definitions },
}: ExportVariables): ExportVariablesProtobuf => ({
name,
definitions,
});
}: ExportVariables): ExportVariablesProtobuf {
return {
name,
definitions,
};
}
const principalPolicyToProtobuf = ({
function principalPolicyToProtobuf({
principalPolicy: { principal, version, rules, scope = "", variables },
}: PrincipalPolicy): PrincipalPolicyProtobuf => ({
principal,
version,
rules: rules.map(principalRuleToProtobuf),
scope,
variables: variables && variablesToProtobuf(variables),
});
}: PrincipalPolicy): PrincipalPolicyProtobuf {
return {
principal,
version,
rules: rules.map(principalRuleToProtobuf),
scope,
variables: variables && variablesToProtobuf(variables),
};
}
const principalRuleToProtobuf = ({
function principalRuleToProtobuf({
resource,
actions,
}: PrincipalRule): PrincipalRuleProtobuf => ({
resource,
actions: actions.map(principalRuleActionToProtobuf),
});
}: PrincipalRule): PrincipalRuleProtobuf {
return {
resource,
actions: actions.map(principalRuleActionToProtobuf),
};
}
const principalRuleActionToProtobuf = ({
function principalRuleActionToProtobuf({
action,

@@ -265,18 +283,23 @@ effect,

output,
}: PrincipalRuleAction): PrincipalRule_Action => ({
action,
effect: effectToProtobuf(effect),
condition: condition && conditionToProtobuf(condition),
name,
output: output && outputToProtobuf(output),
});
}: PrincipalRuleAction): PrincipalRule_Action {
return {
action,
effect: effectToProtobuf(effect),
condition: condition && conditionToProtobuf(condition),
name,
output: output && outputToProtobuf(output),
};
}
const effectToProtobuf = (effect: Effect): EffectProtobuf =>
effect === Effect.ALLOW
function effectToProtobuf(effect: Effect): EffectProtobuf {
return effect === Effect.ALLOW
? EffectProtobuf.EFFECT_ALLOW
: EffectProtobuf.EFFECT_DENY;
}
const outputToProtobuf = ({ expr }: Output): OutputProtobuf => ({ expr });
function outputToProtobuf({ expr }: Output): OutputProtobuf {
return { expr };
}
const resourcePolicyToProtobuf = ({
function resourcePolicyToProtobuf({
resourcePolicy: {

@@ -291,13 +314,15 @@ resource,

},
}: ResourcePolicy): ResourcePolicyProtobuf => ({
resource,
version,
importDerivedRoles,
rules: rules.map(resourceRuleToProtobuf),
scope,
schemas: schemas && policySchemasToProtobuf(schemas),
variables: variables && variablesToProtobuf(variables),
});
}: ResourcePolicy): ResourcePolicyProtobuf {
return {
resource,
version,
importDerivedRoles,
rules: rules.map(resourceRuleToProtobuf),
scope,
schemas: schemas && policySchemasToProtobuf(schemas),
variables: variables && variablesToProtobuf(variables),
};
}
const resourceRuleToProtobuf = ({
function resourceRuleToProtobuf({
actions,

@@ -310,42 +335,52 @@ effect,

output,
}: ResourceRule): ResourceRuleProtobuf => ({
actions,
effect: effectToProtobuf(effect),
derivedRoles,
roles,
condition: condition && conditionToProtobuf(condition),
name,
output: output && outputToProtobuf(output),
});
}: ResourceRule): ResourceRuleProtobuf {
return {
actions,
effect: effectToProtobuf(effect),
derivedRoles,
roles,
condition: condition && conditionToProtobuf(condition),
name,
output: output && outputToProtobuf(output),
};
}
const policySchemasToProtobuf = ({
function policySchemasToProtobuf({
principalSchema,
resourceSchema,
}: SchemaRefs): Schemas => ({
principalSchema: principalSchema && policySchemaToProtobuf(principalSchema),
resourceSchema: resourceSchema && policySchemaToProtobuf(resourceSchema),
});
}: SchemaRefs): Schemas {
return {
principalSchema: principalSchema && policySchemaToProtobuf(principalSchema),
resourceSchema: resourceSchema && policySchemaToProtobuf(resourceSchema),
};
}
const policySchemaToProtobuf = ({
function policySchemaToProtobuf({
ref,
ignoreWhen,
}: SchemaRef): Schemas_Schema => ({
ref,
ignoreWhen,
});
}: SchemaRef): Schemas_Schema {
return {
ref,
ignoreWhen,
};
}
export const addOrUpdateSchemasRequestToProtobuf = ({
export function addOrUpdateSchemasRequestToProtobuf({
schemas,
}: AddOrUpdateSchemasRequest): AddOrUpdateSchemaRequest => ({
schemas: schemas.map(schemaToProtobuf),
});
}: AddOrUpdateSchemasRequest): AddOrUpdateSchemaRequest {
return {
schemas: schemas.map(schemaToProtobuf),
};
}
const schemaToProtobuf = ({ id, definition }: SchemaInput): Schema => ({
id,
definition: schemaDefinitionToProtobuf(definition),
});
function schemaToProtobuf({ id, definition }: SchemaInput): Schema {
return {
id,
definition: schemaDefinitionToProtobuf(definition),
};
}
const schemaDefinitionToProtobuf = (
function schemaDefinitionToProtobuf(
definition: SchemaDefinitionInput,
): Uint8Array => {
): Uint8Array {
if (definition instanceof Uint8Array) {

@@ -364,5 +399,5 @@ return definition;

return encoder.encode(JSON.stringify(definition));
};
}
export const checkResourcesRequestToProtobuf = ({
export function checkResourcesRequestToProtobuf({
principal,

@@ -373,11 +408,13 @@ resources,

requestId = uuidv4(),
}: CheckResourcesRequest): CheckResourcesRequestProtobuf => ({
principal: principalToProtobuf(principal),
resources: resources.map(resourceCheckToProtobuf),
auxData: auxData && auxDataToProtobuf(auxData),
includeMeta: includeMetadata,
requestId,
});
}: CheckResourcesRequest): CheckResourcesRequestProtobuf {
return {
principal: principalToProtobuf(principal),
resources: resources.map(resourceCheckToProtobuf),
auxData: auxData && auxDataToProtobuf(auxData),
includeMeta: includeMetadata,
requestId,
};
}
const principalToProtobuf = ({
function principalToProtobuf({
id,

@@ -388,19 +425,23 @@ roles,

scope = "",
}: Principal): PrincipalProtobuf => ({
id,
roles,
attr: attributes,
policyVersion,
scope,
});
}: Principal): PrincipalProtobuf {
return {
id,
roles,
attr: attributes,
policyVersion,
scope,
};
}
const resourceCheckToProtobuf = ({
function resourceCheckToProtobuf({
resource,
actions,
}: ResourceCheck): CheckResourcesRequest_ResourceEntry => ({
resource: resourceToProtobuf(resource),
actions,
});
}: ResourceCheck): CheckResourcesRequest_ResourceEntry {
return {
resource: resourceToProtobuf(resource),
actions,
};
}
const resourceToProtobuf = ({
function resourceToProtobuf({
kind,

@@ -411,50 +452,66 @@ id,

scope = "",
}: Resource): ResourceProtobuf => ({
kind,
id,
attr: attributes,
policyVersion,
scope,
});
}: Resource): ResourceProtobuf {
return {
kind,
id,
attr: attributes,
policyVersion,
scope,
};
}
const auxDataToProtobuf = ({ jwt }: AuxData): AuxDataProtobuf => ({
jwt: jwt && jwtToProtobuf(jwt),
});
function auxDataToProtobuf({ jwt }: AuxData): AuxDataProtobuf {
return {
jwt: jwt && jwtToProtobuf(jwt),
};
}
const jwtToProtobuf = ({ token, keySetId = "" }: JWT): AuxData_JWT => ({
token,
keySetId,
});
function jwtToProtobuf({ token, keySetId = "" }: JWT): AuxData_JWT {
return {
token,
keySetId,
};
}
export const deleteSchemasRequestToProtobuf = ({
export function deleteSchemasRequestToProtobuf({
ids,
}: DeleteSchemasRequest): DeleteSchemaRequest => ({
id: ids,
});
}: DeleteSchemasRequest): DeleteSchemaRequest {
return {
id: ids,
};
}
export const disablePoliciesRequestToProtobuf = ({
export function disablePoliciesRequestToProtobuf({
ids,
}: DisablePoliciesRequest): DisablePolicyRequest => ({
id: ids,
});
}: DisablePoliciesRequest): DisablePolicyRequest {
return {
id: ids,
};
}
export const enablePoliciesRequestToProtobuf = ({
export function enablePoliciesRequestToProtobuf({
ids,
}: EnablePoliciesRequest): EnablePolicyRequest => ({
id: ids,
});
}: EnablePoliciesRequest): EnablePolicyRequest {
return {
id: ids,
};
}
export const getPoliciesRequestToProtobuf = ({
export function getPoliciesRequestToProtobuf({
ids,
}: GetPoliciesRequest): GetPolicyRequest => ({
id: ids,
});
}: GetPoliciesRequest): GetPolicyRequest {
return {
id: ids,
};
}
export const getSchemasRequestToProtobuf = ({
export function getSchemasRequestToProtobuf({
ids,
}: GetSchemasRequest): GetSchemaRequest => ({
id: ids,
});
}: GetSchemasRequest): GetSchemaRequest {
return {
id: ids,
};
}
export const listPoliciesRequestToProtobuf = ({
export function listPoliciesRequestToProtobuf({
includeDisabled = false,

@@ -464,10 +521,12 @@ nameRegexp = "",

versionRegexp = "",
}: ListPoliciesRequest): ListPoliciesRequestProtobuf => ({
includeDisabled,
nameRegexp,
scopeRegexp,
versionRegexp,
});
}: ListPoliciesRequest): ListPoliciesRequestProtobuf {
return {
includeDisabled,
nameRegexp,
scopeRegexp,
versionRegexp,
};
}
export const planResourcesRequestToProtobuf = ({
export function planResourcesRequestToProtobuf({
principal,

@@ -479,12 +538,14 @@ resource,

requestId = uuidv4(),
}: PlanResourcesRequest): PlanResourcesRequestProtobuf => ({
principal: principalToProtobuf(principal),
resource: resourceQueryToProtobuf(resource),
action,
auxData: auxData && auxDataToProtobuf(auxData),
includeMeta: includeMetadata,
requestId,
});
}: PlanResourcesRequest): PlanResourcesRequestProtobuf {
return {
principal: principalToProtobuf(principal),
resource: resourceQueryToProtobuf(resource),
action,
auxData: auxData && auxDataToProtobuf(auxData),
includeMeta: includeMetadata,
requestId,
};
}
const resourceQueryToProtobuf = ({
function resourceQueryToProtobuf({
kind,

@@ -494,7 +555,9 @@ attributes = {},

scope = "",
}: ResourceQuery): PlanResourcesInput_Resource => ({
kind,
attr: attributes,
policyVersion,
scope,
});
}: ResourceQuery): PlanResourcesInput_Resource {
return {
kind,
attr: attributes,
policyVersion,
scope,
};
}

@@ -90,3 +90,3 @@ import type { ValidationError } from "./types/external";

const code = (error: unknown): Status => {
function code(error: unknown): Status {
if (

@@ -101,5 +101,5 @@ has(error, "code") &&

throw new Error("Error does not include expected code");
};
}
const details = (error: unknown): string => {
function details(error: unknown): string {
if (has(error, "message") && typeof error.message === "string") {

@@ -110,9 +110,10 @@ return error.message;

throw new Error("Error does not include expected details");
};
}
const has = <K extends string>(
function has<K extends string>(
object: unknown,
property: K,
): object is Record<K, unknown> =>
!!object && Object.prototype.hasOwnProperty.call(object, property);
): object is Record<K, unknown> {
return !!object && Object.prototype.hasOwnProperty.call(object, property);
}

@@ -119,0 +120,0 @@ /**

@@ -18,4 +18,5 @@ import type { MatchAll } from "./MatchAll";

*/
export const matchIsMatchAll = (match: Match): match is MatchAll =>
"all" in match;
export function matchIsMatchAll(match: Match): match is MatchAll {
return "all" in match;
}

@@ -27,4 +28,5 @@ /**

*/
export const matchIsMatchAny = (match: Match): match is MatchAny =>
"any" in match;
export function matchIsMatchAny(match: Match): match is MatchAny {
return "any" in match;
}

@@ -36,4 +38,5 @@ /**

*/
export const matchIsMatchNone = (match: Match): match is MatchNone =>
"none" in match;
export function matchIsMatchNone(match: Match): match is MatchNone {
return "none" in match;
}

@@ -45,3 +48,4 @@ /**

*/
export const matchIsMatchExpr = (match: Match): match is MatchExpr =>
"expr" in match;
export function matchIsMatchExpr(match: Match): match is MatchExpr {
return "expr" in match;
}

@@ -22,4 +22,5 @@ import type { DerivedRoles } from "./DerivedRoles";

*/
export const policyIsDerivedRoles = (policy: Policy): policy is DerivedRoles =>
"derivedRoles" in policy;
export function policyIsDerivedRoles(policy: Policy): policy is DerivedRoles {
return "derivedRoles" in policy;
}

@@ -31,5 +32,7 @@ /**

*/
export const policyIsExportVariables = (
export function policyIsExportVariables(
policy: Policy,
): policy is ExportVariables => "exportVariables" in policy;
): policy is ExportVariables {
return "exportVariables" in policy;
}

@@ -41,5 +44,7 @@ /**

*/
export const policyIsPrincipalPolicy = (
export function policyIsPrincipalPolicy(
policy: Policy,
): policy is PrincipalPolicy => "principalPolicy" in policy;
): policy is PrincipalPolicy {
return "principalPolicy" in policy;
}

@@ -51,4 +56,6 @@ /**

*/
export const policyIsResourcePolicy = (
export function policyIsResourcePolicy(
policy: Policy,
): policy is ResourcePolicy => "resourcePolicy" in policy;
): policy is ResourcePolicy {
return "resourcePolicy" in policy;
}

@@ -1,2 +0,2 @@

// https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/60038
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/66392

@@ -3,0 +3,0 @@ import type {

@@ -5,3 +5,4 @@ export type OmitFromEach<T, K extends string> = T extends unknown

export const isObject = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" && value !== null && !Array.isArray(value);
export function isObject(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc