UNPKG

@sphereon/ssi-sdk.event-logger

Version:

785 lines (781 loc) • 25.1 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // plugin.schema.json var require_plugin_schema = __commonJS({ "plugin.schema.json"(exports, module2) { module2.exports = { IEventLogger: { components: { schemas: { GetActivityEventsArgs: { type: "object", properties: { filter: { $ref: "#/components/schemas/FindActivityLoggingEventArgs" } }, additionalProperties: false }, FindActivityLoggingEventArgs: { type: "array", items: { $ref: "#/components/schemas/PartialActivityLoggingEvent" } }, PartialActivityLoggingEvent: { $ref: "#/components/schemas/Partial<ActivityLoggingEvent>" }, "Partial<ActivityLoggingEvent>": { type: "object", properties: { level: { $ref: "#/components/schemas/LogLevel" }, correlationId: { type: "string" }, timestamp: { type: "string", format: "date-time" }, diagnosticData: {}, id: { type: "string" }, type: { $ref: "#/components/schemas/LoggingEventType.ACTIVITY" }, originalCredential: { type: "string" }, credentialHash: { type: "string" }, parentCredentialHash: { type: "string" }, credentialType: { $ref: "#/components/schemas/CredentialType" }, sharePurpose: { type: "string" }, system: { $ref: "#/components/schemas/System" }, subSystemType: { $ref: "#/components/schemas/SubSystem" }, actionType: { $ref: "#/components/schemas/ActionType" }, actionSubType: { $ref: "#/components/schemas/ActionSubType" }, initiatorType: { $ref: "#/components/schemas/InitiatorType" }, systemCorrelationIdType: { $ref: "#/components/schemas/SystemCorrelationIdType" }, systemCorrelationId: { type: "string" }, systemAlias: { type: "string" }, partyCorrelationType: { $ref: "#/components/schemas/PartyCorrelationType" }, partyCorrelationId: { type: "string" }, partyAlias: { type: "string" }, description: { type: "string" }, data: {} }, additionalProperties: false }, LogLevel: { type: "number", enum: [0, 1, 2, 3, 4] }, "LoggingEventType.ACTIVITY": { type: "string", const: "activity" }, CredentialType: { type: "string", enum: ["JSON_LD", "JWT", "SD_JWT", "MSO_MDOC"] }, System: { type: "string", enum: ["general", "kms", "identity", "oid4vci", "oid4vp", "siopv2", "PE", "credentials", "web3", "profile", "contact"] }, SubSystem: { type: "string", enum: [ "key", "did_provider", "did_resolver", "oid4vp_op", "oid4vci_client", "siopv2_op", "contact_manager", "vc_issuer", "vc_verifier", "vc_persistence", "transport", "profile", "api" ] }, ActionType: { type: "string", enum: ["create", "read", "update", "delete", "execute"] }, ActionSubType: { anyOf: [ { $ref: "#/components/schemas/DefaultActionSubType" }, { type: "string" } ] }, DefaultActionSubType: { type: "string", enum: [ "Key generation", "Key import", "Key persistence", "Key removal", "DID creation", "DID resolution", "DID service update", "VC issue", "VC verify", "VC share", "VC delete", "VC issue decline", "VC share decline" ] }, InitiatorType: { type: "string", enum: ["user", "system", "external"] }, SystemCorrelationIdType: { type: "string", enum: ["did", "url", "email", "hostname", "phone", "user"] }, PartyCorrelationType: { type: "string", enum: ["did", "url", "email", "hostname", "phone"] }, ActivityLoggingEvent: { type: "object", additionalProperties: false, properties: { id: { type: "string" }, type: { $ref: "#/components/schemas/LoggingEventType.ACTIVITY" }, originalCredential: { type: "string" }, credentialHash: { type: "string" }, parentCredentialHash: { type: "string" }, credentialType: { $ref: "#/components/schemas/CredentialType" }, sharePurpose: { type: "string" }, correlationId: { type: "string" }, system: { $ref: "#/components/schemas/System" }, subSystemType: { $ref: "#/components/schemas/SubSystem" }, actionType: { $ref: "#/components/schemas/ActionType" }, actionSubType: { $ref: "#/components/schemas/ActionSubType" }, initiatorType: { $ref: "#/components/schemas/InitiatorType" }, systemCorrelationIdType: { $ref: "#/components/schemas/SystemCorrelationIdType" }, systemCorrelationId: { type: "string" }, systemAlias: { type: "string" }, partyCorrelationType: { $ref: "#/components/schemas/PartyCorrelationType" }, partyCorrelationId: { type: "string" }, partyAlias: { type: "string" }, description: { type: "string" }, data: {}, level: { $ref: "#/components/schemas/LogLevel" }, timestamp: { type: "string", format: "date-time" }, diagnosticData: {} }, required: [ "actionSubType", "actionType", "correlationId", "description", "id", "initiatorType", "level", "subSystemType", "system", "timestamp", "type" ] }, GetAuditEventsArgs: { type: "object", properties: { filter: { $ref: "#/components/schemas/FindAuditLoggingEventArgs" } }, additionalProperties: false }, FindAuditLoggingEventArgs: { type: "array", items: { $ref: "#/components/schemas/PartialAuditLoggingEvent" } }, PartialAuditLoggingEvent: { $ref: "#/components/schemas/Partial<AuditLoggingEvent>" }, "Partial<AuditLoggingEvent>": { type: "object", properties: { level: { $ref: "#/components/schemas/LogLevel" }, correlationId: { type: "string" }, timestamp: { type: "string", format: "date-time" }, diagnosticData: {}, id: { type: "string" }, type: { $ref: "#/components/schemas/LoggingEventType.AUDIT" }, system: { $ref: "#/components/schemas/System" }, subSystemType: { $ref: "#/components/schemas/SubSystem" }, actionType: { $ref: "#/components/schemas/ActionType" }, actionSubType: { $ref: "#/components/schemas/ActionSubType" }, initiatorType: { $ref: "#/components/schemas/InitiatorType" }, systemCorrelationIdType: { $ref: "#/components/schemas/SystemCorrelationIdType" }, systemCorrelationId: { type: "string" }, systemAlias: { type: "string" }, partyCorrelationType: { $ref: "#/components/schemas/PartyCorrelationType" }, partyCorrelationId: { type: "string" }, partyAlias: { type: "string" }, description: { type: "string" }, data: {} }, additionalProperties: false }, "LoggingEventType.AUDIT": { type: "string", const: "audit" }, AuditLoggingEvent: { type: "object", additionalProperties: false, properties: { id: { type: "string" }, type: { $ref: "#/components/schemas/LoggingEventType.AUDIT" }, correlationId: { type: "string" }, system: { $ref: "#/components/schemas/System" }, subSystemType: { $ref: "#/components/schemas/SubSystem" }, actionType: { $ref: "#/components/schemas/ActionType" }, actionSubType: { $ref: "#/components/schemas/ActionSubType" }, initiatorType: { $ref: "#/components/schemas/InitiatorType" }, systemCorrelationIdType: { $ref: "#/components/schemas/SystemCorrelationIdType" }, systemCorrelationId: { type: "string" }, systemAlias: { type: "string" }, partyCorrelationType: { $ref: "#/components/schemas/PartyCorrelationType" }, partyCorrelationId: { type: "string" }, partyAlias: { type: "string" }, description: { type: "string" }, data: {}, level: { $ref: "#/components/schemas/LogLevel" }, timestamp: { type: "string", format: "date-time" }, diagnosticData: {} }, required: [ "actionSubType", "actionType", "correlationId", "description", "id", "initiatorType", "level", "subSystemType", "system", "timestamp", "type" ] }, LogEventArgs: { type: "object", properties: { event: { $ref: "#/components/schemas/LogEventType" } }, required: ["event"], additionalProperties: false }, LogEventType: { anyOf: [ { $ref: "#/components/schemas/NonPersistedAuditLoggingEvent" }, { $ref: "#/components/schemas/NonPersistedActivityLoggingEvent" } ] }, NonPersistedAuditLoggingEvent: { type: "object", additionalProperties: false, properties: { system: { $ref: "#/components/schemas/System" }, subSystemType: { $ref: "#/components/schemas/SubSystem" }, initiatorType: { $ref: "#/components/schemas/InitiatorType" }, diagnosticData: {}, actionType: { $ref: "#/components/schemas/ActionType" }, actionSubType: { $ref: "#/components/schemas/ActionSubType" }, systemCorrelationIdType: { $ref: "#/components/schemas/SystemCorrelationIdType" }, systemCorrelationId: { type: "string" }, systemAlias: { type: "string" }, partyCorrelationType: { $ref: "#/components/schemas/PartyCorrelationType" }, partyCorrelationId: { type: "string" }, partyAlias: { type: "string" }, description: { type: "string" }, data: {}, level: { $ref: "#/components/schemas/LogLevel" }, correlationId: { type: "string" } }, required: ["actionSubType", "actionType", "description", "initiatorType", "subSystemType", "system"] }, NonPersistedActivityLoggingEvent: { type: "object", additionalProperties: false, properties: { system: { $ref: "#/components/schemas/System" }, subSystemType: { $ref: "#/components/schemas/SubSystem" }, initiatorType: { $ref: "#/components/schemas/InitiatorType" }, originalCredential: { type: "string" }, credentialHash: { type: "string" }, parentCredentialHash: { type: "string" }, credentialType: { $ref: "#/components/schemas/CredentialType" }, sharePurpose: { type: "string" }, data: {}, diagnosticData: {}, actionType: { $ref: "#/components/schemas/ActionType" }, actionSubType: { $ref: "#/components/schemas/ActionSubType" }, systemCorrelationIdType: { $ref: "#/components/schemas/SystemCorrelationIdType" }, systemCorrelationId: { type: "string" }, systemAlias: { type: "string" }, partyCorrelationType: { $ref: "#/components/schemas/PartyCorrelationType" }, partyCorrelationId: { type: "string" }, partyAlias: { type: "string" }, description: { type: "string" }, level: { $ref: "#/components/schemas/LogLevel" }, correlationId: { type: "string" } }, required: ["actionSubType", "actionType", "description", "initiatorType", "subSystemType", "system"] } }, methods: { loggerGetActivityEvents: { description: "", arguments: { $ref: "#/components/schemas/GetActivityEventsArgs" }, returnType: { type: "array", items: { $ref: "#/components/schemas/ActivityLoggingEvent" } } }, loggerGetAuditEvents: { description: "", arguments: { $ref: "#/components/schemas/GetAuditEventsArgs" }, returnType: { type: "array", items: { $ref: "#/components/schemas/AuditLoggingEvent" } } }, loggerLogActivityEvent: { description: "", arguments: { $ref: "#/components/schemas/LogEventArgs" }, returnType: { $ref: "#/components/schemas/ActivityLoggingEvent" } }, loggerLogAuditEvent: { description: "", arguments: { $ref: "#/components/schemas/LogEventArgs" }, returnType: { $ref: "#/components/schemas/AuditLoggingEvent" } }, loggerLogGeneralEvent: { description: "", arguments: { $ref: "#/components/schemas/LogEventArgs" }, returnType: { $ref: "#/components/schemas/LogEventType" } } } } } }; } }); // src/index.ts var index_exports = {}; __export(index_exports, { EventLogger: () => EventLogger, eventLoggerAuditMethods: () => eventLoggerAuditMethods, eventLoggerMethods: () => eventLoggerMethods, schema: () => schema }); module.exports = __toCommonJS(index_exports); // src/agent/EventLogger.ts var import_ssi_types = require("@sphereon/ssi-types"); var import_uuid = require("uuid"); var eventLoggerAuditMethods = [ "loggerGetAuditEvents", "loggerLogAuditEvent", "loggerLogGeneralEvent", "loggerLogActivityEvent", "loggerGetActivityEvents" ]; var eventLoggerMethods = [ ...eventLoggerAuditMethods ]; var EventLogger = class { static { __name(this, "EventLogger"); } schema = schema.IEventLogger; eventTypes = []; store; simpleLoggers; methods = { loggerGetAuditEvents: this.loggerGetAuditEvents.bind(this), loggerLogAuditEvent: this.loggerLogAuditEvent.bind(this), loggerLogGeneralEvent: this.loggerLogGeneralEvent.bind(this), loggerLogActivityEvent: this.loggerLogActivityEvent.bind(this), loggerGetActivityEvents: this.loggerGetActivityEvents.bind(this) }; constructor(options) { const { store, eventTypes } = options; const generalOpts = options.general ?? { debugPkg: true }; this.store = store; this.eventTypes = eventTypes; const methods = []; if (generalOpts.debugPkg) { methods.push(import_ssi_types.LogMethod.DEBUG_PKG); } if (generalOpts.console) { methods.push(import_ssi_types.LogMethod.CONSOLE); } if (generalOpts.events) { methods.push(import_ssi_types.LogMethod.EVENT); } this.simpleLoggers = new import_ssi_types.Loggers({ methods, eventName: generalOpts.eventName, defaultLogLevel: generalOpts.defaultLogLevel }); } async onEvent(event, context) { switch (event.type) { case import_ssi_types.LoggingEventType.AUDIT: await context.agent.loggerLogAuditEvent({ event: event.data }); break; case import_ssi_types.LoggingEventType.GENERAL: await context.agent.loggerLogGeneralEvent({ event: event.data }); break; case import_ssi_types.LoggingEventType.ACTIVITY: await context.agent.loggerLogActivityEvent({ event: event.data }); break; default: return Promise.reject(Error(`Event type ${event.type} not supported`)); } } async loggerGetAuditEvents(args) { const { filter } = args ?? {}; if (!this.store) { return Promise.reject(Error("No store available in options")); } return this.store.getAuditEvents({ filter }); } async loggerGetActivityEvents(args) { const { filter } = args ?? {}; if (!this.store) { return Promise.reject(Error("No store available in options")); } return this.store.getActivityEvents({ filter }); } async loggerLogGeneralEvent(args) { const { event } = args; this.simpleLoggers.get(event.data.system).logl(event.data.level ?? import_ssi_types.LogLevel.INFO, event.data.data, event.data); return args.event; } async loggerLogAuditEvent(args) { const { event } = args; if (!this.store) { return Promise.reject(Error("No store available in options")); } return this.store.storeAuditEvent({ event: { ...event, system: event.system, subSystemType: event.subSystemType, initiatorType: event.initiatorType, level: event.level ?? import_ssi_types.LogLevel.INFO, correlationId: event.correlationId ?? (0, import_uuid.v4)(), timestamp: /* @__PURE__ */ new Date() } }); } async loggerLogActivityEvent(args) { const { event } = args; if (!this.store) { return Promise.reject(Error("No store available in options")); } return this.store.storeActivityEvent({ event: { ...event, system: event.system, subSystemType: event.subSystemType, initiatorType: event.initiatorType, level: event.level ?? import_ssi_types.LogLevel.INFO, correlationId: event.correlationId ?? (0, import_uuid.v4)(), timestamp: /* @__PURE__ */ new Date() } }); } }; // src/index.ts var schema = require_plugin_schema(); //# sourceMappingURL=index.cjs.map