UNPKG

@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

374 lines 12.7 kB
"use strict"; // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // source: cerbos/request/v1/request.proto Object.defineProperty(exports, "__esModule", { value: true }); exports.ServerInfoRequest = exports.AuxData_JWT = exports.AuxData = exports.CheckResourcesRequest_ResourceEntry = exports.CheckResourcesRequest = exports.CheckResourceBatchRequest_BatchEntry = exports.CheckResourceBatchRequest = exports.AttributesMap_AttrEntry = exports.AttributesMap = exports.ResourceSet_InstancesEntry = exports.ResourceSet = exports.CheckResourceSetRequest = exports.PlanResourcesRequest = exports.protobufPackage = void 0; /* eslint-disable */ const engine_1 = require("../../engine/v1/engine"); exports.protobufPackage = "cerbos.request.v1"; exports.PlanResourcesRequest = { fromJSON(object) { return { requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : "", action: isSet(object.action) ? globalThis.String(object.action) : "", actions: globalThis.Array.isArray(object?.actions) ? object.actions.map((e) => globalThis.String(e)) : [], principal: isSet(object.principal) ? engine_1.Principal.fromJSON(object.principal) : undefined, resource: isSet(object.resource) ? engine_1.PlanResourcesInput_Resource.fromJSON(object.resource) : undefined, auxData: isSet(object.auxData) ? exports.AuxData.fromJSON(object.auxData) : undefined, includeMeta: isSet(object.includeMeta) ? globalThis.Boolean(object.includeMeta) : false, }; }, toJSON(message) { const obj = {}; if (message.requestId !== "") { obj.requestId = message.requestId; } if (message.action !== "") { obj.action = message.action; } if (message.actions?.length) { obj.actions = message.actions; } if (message.principal !== undefined) { obj.principal = engine_1.Principal.toJSON(message.principal); } if (message.resource !== undefined) { obj.resource = engine_1.PlanResourcesInput_Resource.toJSON(message.resource); } if (message.auxData !== undefined) { obj.auxData = exports.AuxData.toJSON(message.auxData); } if (message.includeMeta !== false) { obj.includeMeta = message.includeMeta; } return obj; }, }; exports.CheckResourceSetRequest = { fromJSON(object) { return { requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : "", actions: globalThis.Array.isArray(object?.actions) ? object.actions.map((e) => globalThis.String(e)) : [], principal: isSet(object.principal) ? engine_1.Principal.fromJSON(object.principal) : undefined, resource: isSet(object.resource) ? exports.ResourceSet.fromJSON(object.resource) : undefined, includeMeta: isSet(object.includeMeta) ? globalThis.Boolean(object.includeMeta) : false, auxData: isSet(object.auxData) ? exports.AuxData.fromJSON(object.auxData) : undefined, }; }, toJSON(message) { const obj = {}; if (message.requestId !== "") { obj.requestId = message.requestId; } if (message.actions?.length) { obj.actions = message.actions; } if (message.principal !== undefined) { obj.principal = engine_1.Principal.toJSON(message.principal); } if (message.resource !== undefined) { obj.resource = exports.ResourceSet.toJSON(message.resource); } if (message.includeMeta !== false) { obj.includeMeta = message.includeMeta; } if (message.auxData !== undefined) { obj.auxData = exports.AuxData.toJSON(message.auxData); } return obj; }, }; exports.ResourceSet = { fromJSON(object) { return { kind: isSet(object.kind) ? globalThis.String(object.kind) : "", policyVersion: isSet(object.policyVersion) ? globalThis.String(object.policyVersion) : "", instances: isObject(object.instances) ? Object.entries(object.instances).reduce((acc, [key, value]) => { acc[key] = exports.AttributesMap.fromJSON(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.instances) { const entries = Object.entries(message.instances); if (entries.length > 0) { obj.instances = {}; entries.forEach(([k, v]) => { obj.instances[k] = exports.AttributesMap.toJSON(v); }); } } if (message.scope !== "") { obj.scope = message.scope; } return obj; }, }; exports.ResourceSet_InstancesEntry = { fromJSON(object) { return { key: isSet(object.key) ? globalThis.String(object.key) : "", value: isSet(object.value) ? exports.AttributesMap.fromJSON(object.value) : undefined, }; }, toJSON(message) { const obj = {}; if (message.key !== "") { obj.key = message.key; } if (message.value !== undefined) { obj.value = exports.AttributesMap.toJSON(message.value); } return obj; }, }; exports.AttributesMap = { fromJSON(object) { return { attr: isObject(object.attr) ? Object.entries(object.attr).reduce((acc, [key, value]) => { acc[key] = value; return acc; }, {}) : {}, }; }, toJSON(message) { const obj = {}; if (message.attr) { const entries = Object.entries(message.attr); if (entries.length > 0) { obj.attr = {}; entries.forEach(([k, v]) => { obj.attr[k] = v; }); } } return obj; }, }; exports.AttributesMap_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.CheckResourceBatchRequest = { fromJSON(object) { return { requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : "", principal: isSet(object.principal) ? engine_1.Principal.fromJSON(object.principal) : undefined, resources: globalThis.Array.isArray(object?.resources) ? object.resources.map((e) => exports.CheckResourceBatchRequest_BatchEntry.fromJSON(e)) : [], auxData: isSet(object.auxData) ? exports.AuxData.fromJSON(object.auxData) : undefined, }; }, toJSON(message) { const obj = {}; if (message.requestId !== "") { obj.requestId = message.requestId; } if (message.principal !== undefined) { obj.principal = engine_1.Principal.toJSON(message.principal); } if (message.resources?.length) { obj.resources = message.resources.map((e) => exports.CheckResourceBatchRequest_BatchEntry.toJSON(e)); } if (message.auxData !== undefined) { obj.auxData = exports.AuxData.toJSON(message.auxData); } return obj; }, }; exports.CheckResourceBatchRequest_BatchEntry = { fromJSON(object) { return { actions: globalThis.Array.isArray(object?.actions) ? object.actions.map((e) => globalThis.String(e)) : [], resource: isSet(object.resource) ? engine_1.Resource.fromJSON(object.resource) : undefined, }; }, toJSON(message) { const obj = {}; if (message.actions?.length) { obj.actions = message.actions; } if (message.resource !== undefined) { obj.resource = engine_1.Resource.toJSON(message.resource); } return obj; }, }; exports.CheckResourcesRequest = { fromJSON(object) { return { requestId: isSet(object.requestId) ? globalThis.String(object.requestId) : "", includeMeta: isSet(object.includeMeta) ? globalThis.Boolean(object.includeMeta) : false, principal: isSet(object.principal) ? engine_1.Principal.fromJSON(object.principal) : undefined, resources: globalThis.Array.isArray(object?.resources) ? object.resources.map((e) => exports.CheckResourcesRequest_ResourceEntry.fromJSON(e)) : [], auxData: isSet(object.auxData) ? exports.AuxData.fromJSON(object.auxData) : undefined, }; }, toJSON(message) { const obj = {}; if (message.requestId !== "") { obj.requestId = message.requestId; } if (message.includeMeta !== false) { obj.includeMeta = message.includeMeta; } if (message.principal !== undefined) { obj.principal = engine_1.Principal.toJSON(message.principal); } if (message.resources?.length) { obj.resources = message.resources.map((e) => exports.CheckResourcesRequest_ResourceEntry.toJSON(e)); } if (message.auxData !== undefined) { obj.auxData = exports.AuxData.toJSON(message.auxData); } return obj; }, }; exports.CheckResourcesRequest_ResourceEntry = { fromJSON(object) { return { actions: globalThis.Array.isArray(object?.actions) ? object.actions.map((e) => globalThis.String(e)) : [], resource: isSet(object.resource) ? engine_1.Resource.fromJSON(object.resource) : undefined, }; }, toJSON(message) { const obj = {}; if (message.actions?.length) { obj.actions = message.actions; } if (message.resource !== undefined) { obj.resource = engine_1.Resource.toJSON(message.resource); } return obj; }, }; exports.AuxData = { fromJSON(object) { return { jwt: isSet(object.jwt) ? exports.AuxData_JWT.fromJSON(object.jwt) : undefined, }; }, toJSON(message) { const obj = {}; if (message.jwt !== undefined) { obj.jwt = exports.AuxData_JWT.toJSON(message.jwt); } return obj; }, }; exports.AuxData_JWT = { fromJSON(object) { return { token: isSet(object.token) ? globalThis.String(object.token) : "", keySetId: isSet(object.keySetId) ? globalThis.String(object.keySetId) : "", }; }, toJSON(message) { const obj = {}; if (message.token !== "") { obj.token = message.token; } if (message.keySetId !== "") { obj.keySetId = message.keySetId; } return obj; }, }; exports.ServerInfoRequest = { fromJSON(_) { return {}; }, toJSON(_) { const obj = {}; return obj; }, }; function isObject(value) { return typeof value === "object" && value !== null; } function isSet(value) { return value !== null && value !== undefined; } //# sourceMappingURL=request.js.map