@cerbos/embedded
Version:
Client library for interacting with embedded Cerbos policy decision points generated by Cerbos Hub from server-side Node.js and browser-based applications
442 lines • 15.4 kB
JavaScript
;
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// source: cerbos/engine/v1/engine.proto
Object.defineProperty(exports, "__esModule", { value: true });
exports.Principal_AttrEntry = exports.Principal = exports.Resource_AttrEntry = exports.Resource = exports.OutputEntry = exports.CheckOutput_ActionsEntry = exports.CheckOutput_ActionEffect = exports.CheckOutput = exports.PlanResourcesFilter_Expression_Operand = exports.PlanResourcesFilter_Expression = exports.PlanResourcesFilter = exports.PlanResourcesInput_Resource_AttrEntry = exports.PlanResourcesInput_Resource = exports.PlanResourcesInput = exports.PlanResourcesFilter_Kind = exports.protobufPackage = void 0;
exports.planResourcesFilter_KindFromJSON = planResourcesFilter_KindFromJSON;
exports.planResourcesFilter_KindToJSON = planResourcesFilter_KindToJSON;
/* eslint-disable */
const effect_1 = require("../../effect/v1/effect");
const schema_1 = require("../../schema/v1/schema");
exports.protobufPackage = "cerbos.engine.v1";
var PlanResourcesFilter_Kind;
(function (PlanResourcesFilter_Kind) {
PlanResourcesFilter_Kind[PlanResourcesFilter_Kind["KIND_UNSPECIFIED"] = 0] = "KIND_UNSPECIFIED";
PlanResourcesFilter_Kind[PlanResourcesFilter_Kind["KIND_ALWAYS_ALLOWED"] = 1] = "KIND_ALWAYS_ALLOWED";
PlanResourcesFilter_Kind[PlanResourcesFilter_Kind["KIND_ALWAYS_DENIED"] = 2] = "KIND_ALWAYS_DENIED";
PlanResourcesFilter_Kind[PlanResourcesFilter_Kind["KIND_CONDITIONAL"] = 3] = "KIND_CONDITIONAL";
})(PlanResourcesFilter_Kind || (exports.PlanResourcesFilter_Kind = PlanResourcesFilter_Kind = {}));
function planResourcesFilter_KindFromJSON(object) {
switch (object) {
case 0:
case "KIND_UNSPECIFIED":
return PlanResourcesFilter_Kind.KIND_UNSPECIFIED;
case 1:
case "KIND_ALWAYS_ALLOWED":
return PlanResourcesFilter_Kind.KIND_ALWAYS_ALLOWED;
case 2:
case "KIND_ALWAYS_DENIED":
return PlanResourcesFilter_Kind.KIND_ALWAYS_DENIED;
case 3:
case "KIND_CONDITIONAL":
return PlanResourcesFilter_Kind.KIND_CONDITIONAL;
default:
throw new globalThis.Error("Unrecognized enum value " +
object +
" for enum PlanResourcesFilter_Kind");
}
}
function planResourcesFilter_KindToJSON(object) {
switch (object) {
case PlanResourcesFilter_Kind.KIND_UNSPECIFIED:
return "KIND_UNSPECIFIED";
case PlanResourcesFilter_Kind.KIND_ALWAYS_ALLOWED:
return "KIND_ALWAYS_ALLOWED";
case PlanResourcesFilter_Kind.KIND_ALWAYS_DENIED:
return "KIND_ALWAYS_DENIED";
case PlanResourcesFilter_Kind.KIND_CONDITIONAL:
return "KIND_CONDITIONAL";
default:
throw new globalThis.Error("Unrecognized enum value " +
object +
" for enum PlanResourcesFilter_Kind");
}
}
exports.PlanResourcesInput = {
fromJSON(_) {
return {};
},
toJSON(_) {
const obj = {};
return obj;
},
};
exports.PlanResourcesInput_Resource = {
fromJSON(object) {
return {
kind: isSet(object.kind) ? globalThis.String(object.kind) : "",
attr: isObject(object.attr)
? Object.entries(object.attr).reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {})
: {},
policyVersion: isSet(object.policyVersion)
? globalThis.String(object.policyVersion)
: "",
scope: isSet(object.scope) ? globalThis.String(object.scope) : "",
};
},
toJSON(message) {
const obj = {};
if (message.kind !== "") {
obj.kind = message.kind;
}
if (message.attr) {
const entries = Object.entries(message.attr);
if (entries.length > 0) {
obj.attr = {};
entries.forEach(([k, v]) => {
obj.attr[k] = v;
});
}
}
if (message.policyVersion !== "") {
obj.policyVersion = message.policyVersion;
}
if (message.scope !== "") {
obj.scope = message.scope;
}
return obj;
},
};
exports.PlanResourcesInput_Resource_AttrEntry = {
fromJSON(object) {
return {
key: isSet(object.key) ? globalThis.String(object.key) : "",
value: isSet(object?.value) ? object.value : undefined,
};
},
toJSON(message) {
const obj = {};
if (message.key !== "") {
obj.key = message.key;
}
if (message.value !== undefined) {
obj.value = message.value;
}
return obj;
},
};
exports.PlanResourcesFilter = {
fromJSON(object) {
return {
kind: isSet(object.kind)
? planResourcesFilter_KindFromJSON(object.kind)
: 0,
condition: isSet(object.condition)
? exports.PlanResourcesFilter_Expression_Operand.fromJSON(object.condition)
: undefined,
};
},
toJSON(message) {
const obj = {};
if (message.kind !== 0) {
obj.kind = planResourcesFilter_KindToJSON(message.kind);
}
if (message.condition !== undefined) {
obj.condition = exports.PlanResourcesFilter_Expression_Operand.toJSON(message.condition);
}
return obj;
},
};
exports.PlanResourcesFilter_Expression = {
fromJSON(object) {
return {
operator: isSet(object.operator)
? globalThis.String(object.operator)
: "",
operands: globalThis.Array.isArray(object?.operands)
? object.operands.map((e) => exports.PlanResourcesFilter_Expression_Operand.fromJSON(e))
: [],
};
},
toJSON(message) {
const obj = {};
if (message.operator !== "") {
obj.operator = message.operator;
}
if (message.operands?.length) {
obj.operands = message.operands.map((e) => exports.PlanResourcesFilter_Expression_Operand.toJSON(e));
}
return obj;
},
};
exports.PlanResourcesFilter_Expression_Operand = {
fromJSON(object) {
return {
node: isSet(object.value)
? { $case: "value", value: object.value }
: isSet(object.expression)
? {
$case: "expression",
expression: exports.PlanResourcesFilter_Expression.fromJSON(object.expression),
}
: isSet(object.variable)
? {
$case: "variable",
variable: globalThis.String(object.variable),
}
: undefined,
};
},
toJSON(message) {
const obj = {};
if (message.node?.$case === "value") {
obj.value = message.node.value;
}
else if (message.node?.$case === "expression") {
obj.expression = exports.PlanResourcesFilter_Expression.toJSON(message.node.expression);
}
else if (message.node?.$case === "variable") {
obj.variable = message.node.variable;
}
return obj;
},
};
exports.CheckOutput = {
fromJSON(object) {
return {
requestId: isSet(object.requestId)
? globalThis.String(object.requestId)
: "",
resourceId: isSet(object.resourceId)
? globalThis.String(object.resourceId)
: "",
actions: isObject(object.actions)
? Object.entries(object.actions).reduce((acc, [key, value]) => {
acc[key] = exports.CheckOutput_ActionEffect.fromJSON(value);
return acc;
}, {})
: {},
effectiveDerivedRoles: globalThis.Array.isArray(object?.effectiveDerivedRoles)
? object.effectiveDerivedRoles.map((e) => globalThis.String(e))
: [],
validationErrors: globalThis.Array.isArray(object?.validationErrors)
? object.validationErrors.map((e) => schema_1.ValidationError.fromJSON(e))
: [],
outputs: globalThis.Array.isArray(object?.outputs)
? object.outputs.map((e) => exports.OutputEntry.fromJSON(e))
: [],
};
},
toJSON(message) {
const obj = {};
if (message.requestId !== "") {
obj.requestId = message.requestId;
}
if (message.resourceId !== "") {
obj.resourceId = message.resourceId;
}
if (message.actions) {
const entries = Object.entries(message.actions);
if (entries.length > 0) {
obj.actions = {};
entries.forEach(([k, v]) => {
obj.actions[k] = exports.CheckOutput_ActionEffect.toJSON(v);
});
}
}
if (message.effectiveDerivedRoles?.length) {
obj.effectiveDerivedRoles = message.effectiveDerivedRoles;
}
if (message.validationErrors?.length) {
obj.validationErrors = message.validationErrors.map((e) => schema_1.ValidationError.toJSON(e));
}
if (message.outputs?.length) {
obj.outputs = message.outputs.map((e) => exports.OutputEntry.toJSON(e));
}
return obj;
},
};
exports.CheckOutput_ActionEffect = {
fromJSON(object) {
return {
effect: isSet(object.effect) ? (0, effect_1.effectFromJSON)(object.effect) : 0,
policy: isSet(object.policy) ? globalThis.String(object.policy) : "",
scope: isSet(object.scope) ? globalThis.String(object.scope) : "",
};
},
toJSON(message) {
const obj = {};
if (message.effect !== 0) {
obj.effect = (0, effect_1.effectToJSON)(message.effect);
}
if (message.policy !== "") {
obj.policy = message.policy;
}
if (message.scope !== "") {
obj.scope = message.scope;
}
return obj;
},
};
exports.CheckOutput_ActionsEntry = {
fromJSON(object) {
return {
key: isSet(object.key) ? globalThis.String(object.key) : "",
value: isSet(object.value)
? exports.CheckOutput_ActionEffect.fromJSON(object.value)
: undefined,
};
},
toJSON(message) {
const obj = {};
if (message.key !== "") {
obj.key = message.key;
}
if (message.value !== undefined) {
obj.value = exports.CheckOutput_ActionEffect.toJSON(message.value);
}
return obj;
},
};
exports.OutputEntry = {
fromJSON(object) {
return {
src: isSet(object.src) ? globalThis.String(object.src) : "",
val: isSet(object?.val) ? object.val : undefined,
};
},
toJSON(message) {
const obj = {};
if (message.src !== "") {
obj.src = message.src;
}
if (message.val !== undefined) {
obj.val = message.val;
}
return obj;
},
};
exports.Resource = {
fromJSON(object) {
return {
kind: isSet(object.kind) ? globalThis.String(object.kind) : "",
policyVersion: isSet(object.policyVersion)
? globalThis.String(object.policyVersion)
: "",
id: isSet(object.id) ? globalThis.String(object.id) : "",
attr: isObject(object.attr)
? Object.entries(object.attr).reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {})
: {},
scope: isSet(object.scope) ? globalThis.String(object.scope) : "",
};
},
toJSON(message) {
const obj = {};
if (message.kind !== "") {
obj.kind = message.kind;
}
if (message.policyVersion !== "") {
obj.policyVersion = message.policyVersion;
}
if (message.id !== "") {
obj.id = message.id;
}
if (message.attr) {
const entries = Object.entries(message.attr);
if (entries.length > 0) {
obj.attr = {};
entries.forEach(([k, v]) => {
obj.attr[k] = v;
});
}
}
if (message.scope !== "") {
obj.scope = message.scope;
}
return obj;
},
};
exports.Resource_AttrEntry = {
fromJSON(object) {
return {
key: isSet(object.key) ? globalThis.String(object.key) : "",
value: isSet(object?.value) ? object.value : undefined,
};
},
toJSON(message) {
const obj = {};
if (message.key !== "") {
obj.key = message.key;
}
if (message.value !== undefined) {
obj.value = message.value;
}
return obj;
},
};
exports.Principal = {
fromJSON(object) {
return {
id: isSet(object.id) ? globalThis.String(object.id) : "",
policyVersion: isSet(object.policyVersion)
? globalThis.String(object.policyVersion)
: "",
roles: globalThis.Array.isArray(object?.roles)
? object.roles.map((e) => globalThis.String(e))
: [],
attr: isObject(object.attr)
? Object.entries(object.attr).reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {})
: {},
scope: isSet(object.scope) ? globalThis.String(object.scope) : "",
};
},
toJSON(message) {
const obj = {};
if (message.id !== "") {
obj.id = message.id;
}
if (message.policyVersion !== "") {
obj.policyVersion = message.policyVersion;
}
if (message.roles?.length) {
obj.roles = message.roles;
}
if (message.attr) {
const entries = Object.entries(message.attr);
if (entries.length > 0) {
obj.attr = {};
entries.forEach(([k, v]) => {
obj.attr[k] = v;
});
}
}
if (message.scope !== "") {
obj.scope = message.scope;
}
return obj;
},
};
exports.Principal_AttrEntry = {
fromJSON(object) {
return {
key: isSet(object.key) ? globalThis.String(object.key) : "",
value: isSet(object?.value) ? object.value : undefined,
};
},
toJSON(message) {
const obj = {};
if (message.key !== "") {
obj.key = message.key;
}
if (message.value !== undefined) {
obj.value = message.value;
}
return obj;
},
};
function isObject(value) {
return typeof value === "object" && value !== null;
}
function isSet(value) {
return value !== null && value !== undefined;
}
//# sourceMappingURL=engine.js.map