UNPKG

@cerbos/http

Version:

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

345 lines 12.2 kB
"use strict"; // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // source: cerbos/audit/v1/audit.proto Object.defineProperty(exports, "__esModule", { value: true }); exports.AuditTrail_EffectivePoliciesEntry = exports.AuditTrail = exports.Peer = exports.MetaValues = exports.DecisionLogEntry_MetadataEntry = exports.DecisionLogEntry_PlanResources = exports.DecisionLogEntry_CheckResources = exports.DecisionLogEntry = exports.AccessLogEntry_MetadataEntry = exports.AccessLogEntry = exports.protobufPackage = void 0; /* eslint-disable */ const timestamp_1 = require("../../../google/protobuf/timestamp"); const engine_1 = require("../../engine/v1/engine"); const policy_1 = require("../../policy/v1/policy"); exports.protobufPackage = "cerbos.audit.v1"; exports.AccessLogEntry = { fromJSON(object) { return { callId: isSet(object.callId) ? globalThis.String(object.callId) : "", timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, peer: isSet(object.peer) ? exports.Peer.fromJSON(object.peer) : undefined, metadata: isObject(object.metadata) ? Object.entries(object.metadata).reduce((acc, [key, value]) => { acc[key] = exports.MetaValues.fromJSON(value); return acc; }, {}) : {}, method: isSet(object.method) ? globalThis.String(object.method) : "", statusCode: isSet(object.statusCode) ? globalThis.Number(object.statusCode) : 0, }; }, toJSON(message) { const obj = {}; if (message.callId !== "") { obj.callId = message.callId; } if (message.timestamp !== undefined) { obj.timestamp = message.timestamp.toISOString(); } if (message.peer !== undefined) { obj.peer = exports.Peer.toJSON(message.peer); } if (message.metadata) { const entries = Object.entries(message.metadata); if (entries.length > 0) { obj.metadata = {}; entries.forEach(([k, v]) => { obj.metadata[k] = exports.MetaValues.toJSON(v); }); } } if (message.method !== "") { obj.method = message.method; } if (message.statusCode !== 0) { obj.statusCode = Math.round(message.statusCode); } return obj; }, }; exports.AccessLogEntry_MetadataEntry = { fromJSON(object) { return { key: isSet(object.key) ? globalThis.String(object.key) : "", value: isSet(object.value) ? exports.MetaValues.fromJSON(object.value) : undefined, }; }, toJSON(message) { const obj = {}; if (message.key !== "") { obj.key = message.key; } if (message.value !== undefined) { obj.value = exports.MetaValues.toJSON(message.value); } return obj; }, }; exports.DecisionLogEntry = { fromJSON(object) { return { callId: isSet(object.callId) ? globalThis.String(object.callId) : "", timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, peer: isSet(object.peer) ? exports.Peer.fromJSON(object.peer) : undefined, inputs: globalThis.Array.isArray(object?.inputs) ? object.inputs.map((e) => engine_1.CheckInput.fromJSON(e)) : [], outputs: globalThis.Array.isArray(object?.outputs) ? object.outputs.map((e) => engine_1.CheckOutput.fromJSON(e)) : [], error: isSet(object.error) ? globalThis.String(object.error) : "", method: isSet(object.checkResources) ? { $case: "checkResources", checkResources: exports.DecisionLogEntry_CheckResources.fromJSON(object.checkResources), } : isSet(object.planResources) ? { $case: "planResources", planResources: exports.DecisionLogEntry_PlanResources.fromJSON(object.planResources), } : undefined, metadata: isObject(object.metadata) ? Object.entries(object.metadata).reduce((acc, [key, value]) => { acc[key] = exports.MetaValues.fromJSON(value); return acc; }, {}) : {}, auditTrail: isSet(object.auditTrail) ? exports.AuditTrail.fromJSON(object.auditTrail) : undefined, }; }, toJSON(message) { const obj = {}; if (message.callId !== "") { obj.callId = message.callId; } if (message.timestamp !== undefined) { obj.timestamp = message.timestamp.toISOString(); } if (message.peer !== undefined) { obj.peer = exports.Peer.toJSON(message.peer); } if (message.inputs?.length) { obj.inputs = message.inputs.map((e) => engine_1.CheckInput.toJSON(e)); } if (message.outputs?.length) { obj.outputs = message.outputs.map((e) => engine_1.CheckOutput.toJSON(e)); } if (message.error !== "") { obj.error = message.error; } if (message.method?.$case === "checkResources") { obj.checkResources = exports.DecisionLogEntry_CheckResources.toJSON(message.method.checkResources); } else if (message.method?.$case === "planResources") { obj.planResources = exports.DecisionLogEntry_PlanResources.toJSON(message.method.planResources); } if (message.metadata) { const entries = Object.entries(message.metadata); if (entries.length > 0) { obj.metadata = {}; entries.forEach(([k, v]) => { obj.metadata[k] = exports.MetaValues.toJSON(v); }); } } if (message.auditTrail !== undefined) { obj.auditTrail = exports.AuditTrail.toJSON(message.auditTrail); } return obj; }, }; exports.DecisionLogEntry_CheckResources = { fromJSON(object) { return { inputs: globalThis.Array.isArray(object?.inputs) ? object.inputs.map((e) => engine_1.CheckInput.fromJSON(e)) : [], outputs: globalThis.Array.isArray(object?.outputs) ? object.outputs.map((e) => engine_1.CheckOutput.fromJSON(e)) : [], error: isSet(object.error) ? globalThis.String(object.error) : "", }; }, toJSON(message) { const obj = {}; if (message.inputs?.length) { obj.inputs = message.inputs.map((e) => engine_1.CheckInput.toJSON(e)); } if (message.outputs?.length) { obj.outputs = message.outputs.map((e) => engine_1.CheckOutput.toJSON(e)); } if (message.error !== "") { obj.error = message.error; } return obj; }, }; exports.DecisionLogEntry_PlanResources = { fromJSON(object) { return { input: isSet(object.input) ? engine_1.PlanResourcesInput.fromJSON(object.input) : undefined, output: isSet(object.output) ? engine_1.PlanResourcesOutput.fromJSON(object.output) : undefined, error: isSet(object.error) ? globalThis.String(object.error) : "", }; }, toJSON(message) { const obj = {}; if (message.input !== undefined) { obj.input = engine_1.PlanResourcesInput.toJSON(message.input); } if (message.output !== undefined) { obj.output = engine_1.PlanResourcesOutput.toJSON(message.output); } if (message.error !== "") { obj.error = message.error; } return obj; }, }; exports.DecisionLogEntry_MetadataEntry = { fromJSON(object) { return { key: isSet(object.key) ? globalThis.String(object.key) : "", value: isSet(object.value) ? exports.MetaValues.fromJSON(object.value) : undefined, }; }, toJSON(message) { const obj = {}; if (message.key !== "") { obj.key = message.key; } if (message.value !== undefined) { obj.value = exports.MetaValues.toJSON(message.value); } return obj; }, }; exports.MetaValues = { fromJSON(object) { return { values: globalThis.Array.isArray(object?.values) ? object.values.map((e) => globalThis.String(e)) : [], }; }, toJSON(message) { const obj = {}; if (message.values?.length) { obj.values = message.values; } return obj; }, }; exports.Peer = { fromJSON(object) { return { address: isSet(object.address) ? globalThis.String(object.address) : "", authInfo: isSet(object.authInfo) ? globalThis.String(object.authInfo) : "", userAgent: isSet(object.userAgent) ? globalThis.String(object.userAgent) : "", forwardedFor: isSet(object.forwardedFor) ? globalThis.String(object.forwardedFor) : "", }; }, toJSON(message) { const obj = {}; if (message.address !== "") { obj.address = message.address; } if (message.authInfo !== "") { obj.authInfo = message.authInfo; } if (message.userAgent !== "") { obj.userAgent = message.userAgent; } if (message.forwardedFor !== "") { obj.forwardedFor = message.forwardedFor; } return obj; }, }; exports.AuditTrail = { fromJSON(object) { return { effectivePolicies: isObject(object.effectivePolicies) ? Object.entries(object.effectivePolicies).reduce((acc, [key, value]) => { acc[key] = policy_1.SourceAttributes.fromJSON(value); return acc; }, {}) : {}, }; }, toJSON(message) { const obj = {}; if (message.effectivePolicies) { const entries = Object.entries(message.effectivePolicies); if (entries.length > 0) { obj.effectivePolicies = {}; entries.forEach(([k, v]) => { obj.effectivePolicies[k] = policy_1.SourceAttributes.toJSON(v); }); } } return obj; }, }; exports.AuditTrail_EffectivePoliciesEntry = { fromJSON(object) { return { key: isSet(object.key) ? globalThis.String(object.key) : "", value: isSet(object.value) ? policy_1.SourceAttributes.fromJSON(object.value) : undefined, }; }, toJSON(message) { const obj = {}; if (message.key !== "") { obj.key = message.key; } if (message.value !== undefined) { obj.value = policy_1.SourceAttributes.toJSON(message.value); } 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=audit.js.map