0.23.4 • Published 18 hours ago

@sphereon/ssi-sdk.event-logger v0.23.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
18 hours ago

Warning: This package still is in very early development. Breaking changes without notice will happen at this point!


A Veramo event logger plugin. This plugin allows for listening to events and to persist them into a database. There are also functions that can be manually called to persist events. Current, only audit events are supported that can be used to create an audit log.

Ideally this plugin should be used in combination with the event logger from our core package. This event logger will also default debug the events. This is mainly as a fallback for when no listener is present within the agent.

Available functions

  • loggerGetAuditEvents
  • loggerStoreAuditEvent

Usage

Adding the plugin to an agent:

import { migrations, Entities } from '@veramo/data-store'
import { EventLogger, IEventLogger } from '@sphereon/ssi-sdk.event-logger'
import {
  EventLoggerStore,
  DataStoreMigrations,
  DataStoreEventLoggerEntities,
  LoggingEventType
} from '@sphereon/ssi-sdk.data-store'

const dbConnection = createConnection({
  type: 'react-native',
  database: 'app.sqlite',
  location: 'default',
  logging: false,
  synchronize: false,
  migrationsRun: true,
  migrations: [...DataStoreMigrations, ...migrations],
  entities: [...DataStoreEventLoggerEntities, ...Entities],
})

const agent = createAgent<IEventLogger>({
  plugins: [
    new EventLogger({
      eventTypes: [LoggingEventType.AUDIT],
      store: new EventLoggerStore(dbConnection),
    }),
  ],
})

Log event using event listener:

import { 
  EventLogger, 
  EventLoggerBuilder, 
  LoggingEventType ,
  LogLevel,
  System,
  SubSystem,
  ActionType,
  InitiatorType,
  SystemCorrelationIdType,
  PartyCorrelationType
} from '@sphereon/ssi-sdk.core';

const agentContext = { agent }
const logger: EventLogger = new EventLoggerBuilder()
    .withContext(agentContext)
    .withNamespace('custom_namespace')
    .build()

await logger.logEvent({
  type: LoggingEventType.AUDIT,
  data: {
    level: LogLevel.DEBUG,
    correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
    system: System.GENERAL,
    subSystemType: SubSystem.DID_PROVIDER,
    actionType: ActionType.CREATE,
    actionSubType: 'Key generation',
    initiatorType: InitiatorType.EXTERNAL,
    systemCorrelationIdType: SystemCorrelationIdType.DID,
    systemCorrelationId: 'did:example:123456789abcdefghi',
    systemAlias: 'test_alias',
    partyCorrelationType: PartyCorrelationType.DID,
    partyCorrelationId: 'did:example:123456789abcdefghi',
    partyAlias: 'test_alias',
    description: 'test_description',
    data: 'test_data_string',
    diagnosticData: { data: 'test_data_string'}
  }
})

Log event manually:

import {
  AuditLoggingEvent,
  LogLevel,
  System,
  SubSystem,
  ActionType,
  InitiatorType,
  SystemCorrelationIdType,
  PartyCorrelationType
} from '@sphereon/ssi-sdk.core'
import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '@sphereon/ssi-sdk.event-logger'

const auditEvent: NonPersistedAuditLoggingEvent = {
  level: LogLevel.DEBUG,
  correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
  system: System.GENERAL,
  subSystemType: SubSystem.DID_PROVIDER,
  actionType: ActionType.CREATE,
  actionSubType: 'Key generation',
  initiatorType: InitiatorType.EXTERNAL,
  systemCorrelationIdType: SystemCorrelationIdType.DID,
  systemCorrelationId: 'did:example:123456789abcdefghi',
  systemAlias: 'test_alias',
  partyCorrelationType: PartyCorrelationType.DID,
  partyCorrelationId: 'did:example:123456789abcdefghi',
  partyAlias: 'test_alias',
  description: 'test_description',
  data: 'test_data_string',
  diagnosticData: { data: 'test_data_string'}
}

const result: AuditLoggingEvent = await agent.loggerLogAuditEvent({event: auditEvent})

Retrieve audit events:

import {
  AuditLoggingEvent,
  LogLevel,
  System,
  SubSystem,
  ActionType,
  InitiatorType,
  SystemCorrelationIdType,
  PartyCorrelationType
} from '@sphereon/ssi-sdk.core'
import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '@sphereon/ssi-sdk.event-logger'

const auditEvent: NonPersistedAuditLoggingEvent = {
  level: LogLevel.DEBUG,
  correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
  system: System.GENERAL,
  subSystemType: SubSystem.DID_PROVIDER,
  actionType: ActionType.CREATE,
  actionSubType: 'Key generation',
  initiatorType: InitiatorType.EXTERNAL,
  systemCorrelationIdType: SystemCorrelationIdType.DID,
  systemCorrelationId: 'did:example:123456789abcdefghi',
  systemAlias: 'test_alias',
  partyCorrelationType: PartyCorrelationType.DID,
  partyCorrelationId: 'did:example:123456789abcdefghi',
  partyAlias: 'test_alias',
  description: 'test_description',
  data: 'test_data_string',
  diagnosticData: { data: 'test_data_string'}
}

await agent.loggerLogAuditEvent({event: auditEvent})
const getAuditEventArgs: GetAuditEventsArgs = {
  filter: [{ correlationId: auditEvent.correlationId }],
}
const result: Array<AuditLoggingEvent> = await agent.loggerGetAuditEvents(getAuditEventArgs)

Installation

yarn add @sphereon/ssi-sdk.event-logger

Build

yarn build
0.23.5-unstable.17

18 hours ago

0.23.5-next.12

6 days ago

0.23.5-next.11

7 days ago

0.23.5-next.10

8 days ago

0.23.3-next.3

13 days ago

0.23.4

13 days ago

0.23.2-next.4

13 days ago

0.23.1-next.7

14 days ago

0.23.0

14 days ago

0.21.2-next.25

14 days ago

0.23.1-next.2

14 days ago

0.21.2-next.23

27 days ago

0.21.2-next.17

28 days ago

0.21.2-next.8

28 days ago

0.21.2-next.7

29 days ago

0.21.2-next.6

29 days ago

0.21.1

1 month ago

0.21.1-next.8

1 month ago

0.21.1-next.4

1 month ago

0.22.0

1 month ago

0.21.1-unstable.5

2 months ago

0.19.1-next.125

2 months ago

0.19.1-next.126

2 months ago

0.21.0

2 months ago

0.21.1-next.2

2 months ago

0.19.1-next.119

2 months ago

0.19.1-next.135

2 months ago

0.19.1-next.117

2 months ago

0.19.1-next.113

2 months ago

0.19.1-next.114

2 months ago

0.19.1-next.115

2 months ago

0.19.1-next.116

2 months ago

0.19.1-next.111

2 months ago

0.19.1-next.112

2 months ago

0.19.1-next.105

2 months ago

0.19.1-next.110

2 months ago

0.19.1-next.106

2 months ago

0.19.1-next.108

2 months ago

0.19.1-next.109

2 months ago

0.19.1-next.102

2 months ago

0.19.1-next.100

2 months ago

0.19.1-next.101

2 months ago

0.19.1-next.98

2 months ago

0.19.1-next.99

2 months ago

0.19.1-unstable.88

2 months ago

0.19.1-unstable.89

2 months ago

0.19.1-unstable.86

2 months ago

0.19.1-unstable.87

2 months ago

0.19.1-next.96

2 months ago

0.19.1-unstable.93

2 months ago

0.19.1-unstable.94

2 months ago

0.19.1-unstable.91

2 months ago

0.19.1-unstable.92

2 months ago

0.19.1-unstable.90

2 months ago

0.19.1-unstable.84

2 months ago

0.19.1-unstable.85

2 months ago

0.19.1-unstable.82

2 months ago

0.19.1-unstable.80

2 months ago

0.19.1-unstable.81

2 months ago

0.19.1-unstable.78

2 months ago

0.19.1-unstable.77

2 months ago

0.19.1-unstable.75

2 months ago

0.19.1-next.75

2 months ago

0.19.1-unstable.73

2 months ago

0.19.1-unstable.74

2 months ago

0.19.1-unstable.69

2 months ago

0.19.1-unstable.67

2 months ago

0.19.1-unstable.65

2 months ago

0.19.1-unstable.63

2 months ago

0.18.2-unstable.98

2 months ago

0.19.1-next.24

2 months ago

0.19.1-next.2

2 months ago

0.19.0

2 months ago

0.18.2-next.96

2 months ago

0.18.2-unstable.97

2 months ago

0.18.2-unstable.57

2 months ago

0.18.2-next.95

2 months ago

0.18.2-next.94

2 months ago

0.18.2-next.92

2 months ago

0.18.2-unstable.96

2 months ago

0.18.2-unstable.95

2 months ago

0.18.2-unstable.55

2 months ago

0.18.2-unstable.90

2 months ago

0.18.2-unstable.89

2 months ago

0.18.2-unstable.88

2 months ago

0.18.2-unstable.87

2 months ago

0.18.2-unstable.85

2 months ago

0.18.2-unstable.12

3 months ago

0.18.2-next.77

3 months ago

0.18.2-unstable.61

3 months ago

0.18.2-next.58

3 months ago

0.18.2-next.62

3 months ago

0.18.2-unstable.56

3 months ago

0.18.2-unstable.53

3 months ago

0.18.2-unstable.67

3 months ago

0.18.2-unstable.64

3 months ago

0.18.2-next.57

3 months ago

0.18.2-unstable.59

3 months ago

0.18.2-unstable.60

3 months ago

0.18.2-unstable.54

3 months ago

0.18.2-unstable.51

3 months ago

0.18.2-unstable.50

3 months ago

0.18.2-next.47

3 months ago

0.18.2-next.15

3 months ago

0.18.2-next.17

3 months ago

0.18.2-next.14

3 months ago

0.18.2-next.12

3 months ago

0.18.2-unstable.22

3 months ago

0.18.2-unstable.46

3 months ago

0.18.2-unstable.14

3 months ago

0.18.2-unstable.13

3 months ago

0.18.2-next.9

3 months ago

0.18.2-unstable.44

3 months ago

0.18.2-unstable.34

3 months ago

0.18.2-unstable.36

3 months ago

0.18.2-unstable.35

3 months ago

0.18.2-unstable.33

3 months ago

0.18.2-unstable.32

3 months ago

0.18.2-unstable.30

3 months ago

0.18.2-unstable.5

3 months ago

0.18.2-unstable.10

3 months ago

0.18.2-unstable.6

3 months ago

0.18.2-unstable.7

3 months ago

0.18.2-unstable.8

3 months ago

0.17.6-unstable.79

3 months ago

0.18.2-next.3

4 months ago

0.18.2-unstable.25

4 months ago

0.18.2-unstable.24

4 months ago

0.18.1-next.3

4 months ago

0.18.1-next.2

4 months ago

0.18.1-next.4

4 months ago

0.18.1

4 months ago

0.18.1-next.8

4 months ago

0.17.6-next.61

4 months ago

0.18.0

4 months ago

0.17.6-next.58

4 months ago

0.17.6-unstable.74

4 months ago

0.17.6-unstable.72

4 months ago

0.17.6-unstable.73

4 months ago

0.17.6-unstable.71

4 months ago

0.17.6-next.57

4 months ago

0.17.6-next.56

5 months ago

0.17.6-unstable.69

5 months ago

0.17.6-next.52

5 months ago

0.17.6-unstable.54

5 months ago

0.17.6-unstable.55

5 months ago

0.17.6-unstable.23

5 months ago