UNPKG

@cerbos/http

Version:

Client library for interacting with the Cerbos policy decision point service over HTTP from browser-based applications

708 lines 24 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.ReloadStoreRequest = exports.DeleteSchemaRequest = exports.GetSchemaRequest = exports.ListSchemasRequest = exports.AddOrUpdateSchemaRequest = exports.InspectPoliciesRequest = exports.EnablePolicyRequest = exports.DisablePolicyRequest = exports.GetPolicyRequest = exports.ListPoliciesRequest = exports.ServerInfoRequest = exports.ListAuditLogEntriesRequest_TimeRange = exports.ListAuditLogEntriesRequest = exports.AddOrUpdatePolicyRequest = 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.ListAuditLogEntriesRequest_Kind = exports.protobufPackage = void 0; exports.listAuditLogEntriesRequest_KindFromJSON = listAuditLogEntriesRequest_KindFromJSON; exports.listAuditLogEntriesRequest_KindToJSON = listAuditLogEntriesRequest_KindToJSON; /* eslint-disable */ const duration_1 = require("../../../google/protobuf/duration"); const timestamp_1 = require("../../../google/protobuf/timestamp"); const engine_1 = require("../../engine/v1/engine"); const policy_1 = require("../../policy/v1/policy"); const schema_1 = require("../../schema/v1/schema"); exports.protobufPackage = "cerbos.request.v1"; var ListAuditLogEntriesRequest_Kind; (function (ListAuditLogEntriesRequest_Kind) { ListAuditLogEntriesRequest_Kind[ListAuditLogEntriesRequest_Kind["KIND_UNSPECIFIED"] = 0] = "KIND_UNSPECIFIED"; ListAuditLogEntriesRequest_Kind[ListAuditLogEntriesRequest_Kind["KIND_ACCESS"] = 1] = "KIND_ACCESS"; ListAuditLogEntriesRequest_Kind[ListAuditLogEntriesRequest_Kind["KIND_DECISION"] = 2] = "KIND_DECISION"; })(ListAuditLogEntriesRequest_Kind || (exports.ListAuditLogEntriesRequest_Kind = ListAuditLogEntriesRequest_Kind = {})); function listAuditLogEntriesRequest_KindFromJSON(object) { switch (object) { case 0: case "KIND_UNSPECIFIED": return ListAuditLogEntriesRequest_Kind.KIND_UNSPECIFIED; case 1: case "KIND_ACCESS": return ListAuditLogEntriesRequest_Kind.KIND_ACCESS; case 2: case "KIND_DECISION": return ListAuditLogEntriesRequest_Kind.KIND_DECISION; default: throw new globalThis.Error("Unrecognized enum value " + object + " for enum ListAuditLogEntriesRequest_Kind"); } } function listAuditLogEntriesRequest_KindToJSON(object) { switch (object) { case ListAuditLogEntriesRequest_Kind.KIND_UNSPECIFIED: return "KIND_UNSPECIFIED"; case ListAuditLogEntriesRequest_Kind.KIND_ACCESS: return "KIND_ACCESS"; case ListAuditLogEntriesRequest_Kind.KIND_DECISION: return "KIND_DECISION"; default: throw new globalThis.Error("Unrecognized enum value " + object + " for enum ListAuditLogEntriesRequest_Kind"); } } 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.AddOrUpdatePolicyRequest = { fromJSON(object) { return { policies: globalThis.Array.isArray(object?.policies) ? object.policies.map((e) => policy_1.Policy.fromJSON(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.policies?.length) { obj.policies = message.policies.map((e) => policy_1.Policy.toJSON(e)); } return obj; }, }; exports.ListAuditLogEntriesRequest = { fromJSON(object) { return { kind: isSet(object.kind) ? listAuditLogEntriesRequest_KindFromJSON(object.kind) : 0, filter: isSet(object.tail) ? { $case: "tail", tail: globalThis.Number(object.tail) } : isSet(object.between) ? { $case: "between", between: exports.ListAuditLogEntriesRequest_TimeRange.fromJSON(object.between), } : isSet(object.since) ? { $case: "since", since: duration_1.Duration.fromJSON(object.since) } : isSet(object.lookup) ? { $case: "lookup", lookup: globalThis.String(object.lookup) } : undefined, }; }, toJSON(message) { const obj = {}; if (message.kind !== 0) { obj.kind = listAuditLogEntriesRequest_KindToJSON(message.kind); } if (message.filter?.$case === "tail") { obj.tail = Math.round(message.filter.tail); } else if (message.filter?.$case === "between") { obj.between = exports.ListAuditLogEntriesRequest_TimeRange.toJSON(message.filter.between); } else if (message.filter?.$case === "since") { obj.since = duration_1.Duration.toJSON(message.filter.since); } else if (message.filter?.$case === "lookup") { obj.lookup = message.filter.lookup; } return obj; }, }; exports.ListAuditLogEntriesRequest_TimeRange = { fromJSON(object) { return { start: isSet(object.start) ? fromJsonTimestamp(object.start) : undefined, end: isSet(object.end) ? fromJsonTimestamp(object.end) : undefined, }; }, toJSON(message) { const obj = {}; if (message.start !== undefined) { obj.start = message.start.toISOString(); } if (message.end !== undefined) { obj.end = message.end.toISOString(); } return obj; }, }; exports.ServerInfoRequest = { fromJSON(_) { return {}; }, toJSON(_) { const obj = {}; return obj; }, }; exports.ListPoliciesRequest = { fromJSON(object) { return { includeDisabled: isSet(object.includeDisabled) ? globalThis.Boolean(object.includeDisabled) : false, nameRegexp: isSet(object.nameRegexp) ? globalThis.String(object.nameRegexp) : "", scopeRegexp: isSet(object.scopeRegexp) ? globalThis.String(object.scopeRegexp) : "", versionRegexp: isSet(object.versionRegexp) ? globalThis.String(object.versionRegexp) : "", policyId: globalThis.Array.isArray(object?.policyId) ? object.policyId.map((e) => globalThis.String(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.includeDisabled !== false) { obj.includeDisabled = message.includeDisabled; } if (message.nameRegexp !== "") { obj.nameRegexp = message.nameRegexp; } if (message.scopeRegexp !== "") { obj.scopeRegexp = message.scopeRegexp; } if (message.versionRegexp !== "") { obj.versionRegexp = message.versionRegexp; } if (message.policyId?.length) { obj.policyId = message.policyId; } return obj; }, }; exports.GetPolicyRequest = { fromJSON(object) { return { id: globalThis.Array.isArray(object?.id) ? object.id.map((e) => globalThis.String(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.id?.length) { obj.id = message.id; } return obj; }, }; exports.DisablePolicyRequest = { fromJSON(object) { return { id: globalThis.Array.isArray(object?.id) ? object.id.map((e) => globalThis.String(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.id?.length) { obj.id = message.id; } return obj; }, }; exports.EnablePolicyRequest = { fromJSON(object) { return { id: globalThis.Array.isArray(object?.id) ? object.id.map((e) => globalThis.String(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.id?.length) { obj.id = message.id; } return obj; }, }; exports.InspectPoliciesRequest = { fromJSON(object) { return { includeDisabled: isSet(object.includeDisabled) ? globalThis.Boolean(object.includeDisabled) : false, nameRegexp: isSet(object.nameRegexp) ? globalThis.String(object.nameRegexp) : "", scopeRegexp: isSet(object.scopeRegexp) ? globalThis.String(object.scopeRegexp) : "", versionRegexp: isSet(object.versionRegexp) ? globalThis.String(object.versionRegexp) : "", policyId: globalThis.Array.isArray(object?.policyId) ? object.policyId.map((e) => globalThis.String(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.includeDisabled !== false) { obj.includeDisabled = message.includeDisabled; } if (message.nameRegexp !== "") { obj.nameRegexp = message.nameRegexp; } if (message.scopeRegexp !== "") { obj.scopeRegexp = message.scopeRegexp; } if (message.versionRegexp !== "") { obj.versionRegexp = message.versionRegexp; } if (message.policyId?.length) { obj.policyId = message.policyId; } return obj; }, }; exports.AddOrUpdateSchemaRequest = { fromJSON(object) { return { schemas: globalThis.Array.isArray(object?.schemas) ? object.schemas.map((e) => schema_1.Schema.fromJSON(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.schemas?.length) { obj.schemas = message.schemas.map((e) => schema_1.Schema.toJSON(e)); } return obj; }, }; exports.ListSchemasRequest = { fromJSON(_) { return {}; }, toJSON(_) { const obj = {}; return obj; }, }; exports.GetSchemaRequest = { fromJSON(object) { return { id: globalThis.Array.isArray(object?.id) ? object.id.map((e) => globalThis.String(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.id?.length) { obj.id = message.id; } return obj; }, }; exports.DeleteSchemaRequest = { fromJSON(object) { return { id: globalThis.Array.isArray(object?.id) ? object.id.map((e) => globalThis.String(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.id?.length) { obj.id = message.id; } return obj; }, }; exports.ReloadStoreRequest = { fromJSON(object) { return { wait: isSet(object.wait) ? globalThis.Boolean(object.wait) : false, }; }, toJSON(message) { const obj = {}; if (message.wait !== false) { obj.wait = message.wait; } return obj; }, }; function fromTimestamp(t) { let millis = (globalThis.Number(t.seconds) || 0) * 1_000; millis += (t.nanos || 0) / 1_000_000; return new globalThis.Date(millis); } function fromJsonTimestamp(o) { if (o instanceof globalThis.Date) { return o; } else if (typeof o === "string") { return new globalThis.Date(o); } else { return fromTimestamp(timestamp_1.Timestamp.fromJSON(o)); } } function isObject(value) { return typeof value === "object" && value !== null; } function isSet(value) { return value !== null && value !== undefined; } //# sourceMappingURL=request.js.map