@sphereon/ssi-sdk.data-store 0.17.6-next.5 → 0.17.6-next.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +5 -0
  2. package/dist/entities/eventLogger/AuditEventEntity.d.ts +27 -0
  3. package/dist/entities/eventLogger/AuditEventEntity.d.ts.map +1 -0
  4. package/dist/entities/eventLogger/AuditEventEntity.js +124 -0
  5. package/dist/entities/eventLogger/AuditEventEntity.js.map +1 -0
  6. package/dist/entities/statusList2021/StatusList2021Entity.d.ts +2 -2
  7. package/dist/entities/statusList2021/StatusList2021Entity.d.ts.map +1 -1
  8. package/dist/entities/statusList2021/StatusList2021Entity.js.map +1 -1
  9. package/dist/eventLogger/AbstractEventLoggerStore.d.ts +7 -0
  10. package/dist/eventLogger/AbstractEventLoggerStore.d.ts.map +1 -0
  11. package/dist/eventLogger/AbstractEventLoggerStore.js +7 -0
  12. package/dist/eventLogger/AbstractEventLoggerStore.js.map +1 -0
  13. package/dist/eventLogger/EventLoggerStore.d.ts +13 -0
  14. package/dist/eventLogger/EventLoggerStore.d.ts.map +1 -0
  15. package/dist/eventLogger/EventLoggerStore.js +44 -0
  16. package/dist/eventLogger/EventLoggerStore.js.map +1 -0
  17. package/dist/index.d.ts +6 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +17 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/migrations/generic/1-CreateContacts.js +2 -2
  22. package/dist/migrations/generic/1-CreateContacts.js.map +1 -1
  23. package/dist/migrations/generic/2-CreateIssuanceBranding.js +2 -2
  24. package/dist/migrations/generic/2-CreateIssuanceBranding.js.map +1 -1
  25. package/dist/migrations/generic/{2-CreateContacts.d.ts → 3-CreateContacts.d.ts} +1 -1
  26. package/dist/migrations/generic/{2-CreateContacts.d.ts.map → 3-CreateContacts.d.ts.map} +1 -1
  27. package/dist/migrations/generic/{2-CreateContacts.js → 3-CreateContacts.js} +3 -3
  28. package/dist/migrations/generic/{2-CreateContacts.js.map → 3-CreateContacts.js.map} +1 -1
  29. package/dist/migrations/generic/{3-CreateStatusList.d.ts → 4-CreateStatusList.d.ts} +1 -1
  30. package/dist/migrations/generic/{3-CreateStatusList.d.ts.map → 4-CreateStatusList.d.ts.map} +1 -1
  31. package/dist/migrations/generic/{3-CreateStatusList.js → 4-CreateStatusList.js} +5 -5
  32. package/dist/migrations/generic/{3-CreateStatusList.js.map → 4-CreateStatusList.js.map} +1 -1
  33. package/dist/migrations/generic/5-CreateAuditEvents.d.ts +7 -0
  34. package/dist/migrations/generic/5-CreateAuditEvents.d.ts.map +1 -0
  35. package/dist/migrations/generic/5-CreateAuditEvents.js +78 -0
  36. package/dist/migrations/generic/5-CreateAuditEvents.js.map +1 -0
  37. package/dist/migrations/generic/index.d.ts +3 -1
  38. package/dist/migrations/generic/index.d.ts.map +1 -1
  39. package/dist/migrations/generic/index.js +13 -6
  40. package/dist/migrations/generic/index.js.map +1 -1
  41. package/dist/migrations/postgres/1659463079428-CreateContacts.js +2 -2
  42. package/dist/migrations/postgres/1659463079428-CreateContacts.js.map +1 -1
  43. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +2 -2
  44. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js.map +1 -1
  45. package/dist/migrations/postgres/1690925872592-CreateContacts.js +2 -2
  46. package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -1
  47. package/dist/migrations/postgres/{CreateStatusList1693866470001-CreateStatusList.d.ts → 1693866470001-CreateStatusList.d.ts} +1 -1
  48. package/dist/migrations/postgres/1693866470001-CreateStatusList.d.ts.map +1 -0
  49. package/dist/migrations/postgres/{CreateStatusList1693866470001-CreateStatusList.js → 1693866470001-CreateStatusList.js} +1 -1
  50. package/dist/migrations/postgres/1693866470001-CreateStatusList.js.map +1 -0
  51. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.d.ts +7 -0
  52. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.d.ts.map +1 -0
  53. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js +43 -0
  54. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js.map +1 -0
  55. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.d.ts +7 -0
  56. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.d.ts.map +1 -0
  57. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js +29 -0
  58. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js.map +1 -0
  59. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts +10 -0
  60. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts.map +1 -0
  61. package/dist/types/eventLogger/IAbstractEventLoggerStore.js +3 -0
  62. package/dist/types/eventLogger/IAbstractEventLoggerStore.js.map +1 -0
  63. package/dist/types/eventLogger/eventLogger.d.ts +3 -0
  64. package/dist/types/eventLogger/eventLogger.d.ts.map +1 -0
  65. package/dist/types/eventLogger/eventLogger.js +3 -0
  66. package/dist/types/eventLogger/eventLogger.js.map +1 -0
  67. package/dist/types/index.d.ts +2 -0
  68. package/dist/types/index.d.ts.map +1 -1
  69. package/dist/types/index.js +2 -0
  70. package/dist/types/index.js.map +1 -1
  71. package/package.json +4 -3
  72. package/src/__tests__/eventLogger.entities.test.ts +82 -0
  73. package/src/__tests__/eventLogger.store.test.ts +137 -0
  74. package/src/entities/eventLogger/AuditEventEntity.ts +106 -0
  75. package/src/entities/statusList2021/StatusList2021Entity.ts +5 -4
  76. package/src/eventLogger/AbstractEventLoggerStore.ts +8 -0
  77. package/src/eventLogger/EventLoggerStore.ts +62 -0
  78. package/src/index.ts +16 -1
  79. package/src/migrations/generic/1-CreateContacts.ts +2 -2
  80. package/src/migrations/generic/2-CreateIssuanceBranding.ts +2 -2
  81. package/src/migrations/generic/{2-CreateContacts.ts → 3-CreateContacts.ts} +2 -2
  82. package/src/migrations/generic/{3-CreateStatusList.ts → 4-CreateStatusList.ts} +3 -3
  83. package/src/migrations/generic/5-CreateAuditEvents.ts +66 -0
  84. package/src/migrations/generic/index.ts +10 -3
  85. package/src/migrations/postgres/1659463079428-CreateContacts.ts +2 -2
  86. package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +2 -2
  87. package/src/migrations/postgres/1690925872592-CreateContacts.ts +2 -2
  88. package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +27 -0
  89. package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +13 -0
  90. package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -0
  91. package/src/types/eventLogger/eventLogger.ts +3 -0
  92. package/src/types/index.ts +2 -1
  93. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts.map +0 -1
  94. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js.map +0 -1
  95. package/dist/migrations/postgres/uuid.d.ts +0 -3
  96. package/dist/migrations/postgres/uuid.d.ts.map +0 -1
  97. package/dist/migrations/postgres/uuid.js +0 -25
  98. package/dist/migrations/postgres/uuid.js.map +0 -1
  99. package/src/migrations/postgres/uuid.ts +0 -12
  100. /package/src/migrations/postgres/{CreateStatusList1693866470001-CreateStatusList.ts → 1693866470001-CreateStatusList.ts} +0 -0
@@ -0,0 +1,137 @@
1
+ import { DataSource } from 'typeorm'
2
+ import { DataStoreEventLoggerMigrations } from '../migrations/generic'
3
+ import { DataStoreEventLoggerEntities } from '../index'
4
+ import {
5
+ ActionType,
6
+ AuditLoggingEvent,
7
+ InitiatorType,
8
+ LogLevel,
9
+ PartyCorrelationType,
10
+ SubSystem,
11
+ System,
12
+ SystemCorrelationIdType
13
+ } from '@sphereon/ssi-sdk.core'
14
+ import { EventLoggerStore } from '../eventLogger/EventLoggerStore'
15
+ import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '../types'
16
+
17
+ describe('Database entities tests', (): void => {
18
+ let dbConnection: DataSource
19
+ let eventLoggerStore: EventLoggerStore
20
+
21
+ beforeEach(async (): Promise<void> => {
22
+ dbConnection = await new DataSource({
23
+ type: 'sqlite',
24
+ database: ':memory:',
25
+ //logging: 'all',
26
+ migrationsRun: false,
27
+ migrations: DataStoreEventLoggerMigrations,
28
+ synchronize: false,
29
+ entities: DataStoreEventLoggerEntities,
30
+ }).initialize()
31
+ await dbConnection.runMigrations()
32
+ expect(await dbConnection.showMigrations()).toBeFalsy()
33
+ eventLoggerStore = new EventLoggerStore(dbConnection)
34
+ })
35
+
36
+ afterEach(async (): Promise<void> => {
37
+ await (await dbConnection).destroy()
38
+ })
39
+
40
+ it('should store audit event', async (): Promise<void> => {
41
+ const auditEvent: NonPersistedAuditLoggingEvent = {
42
+ timestamp: new Date(),
43
+ level: LogLevel.DEBUG,
44
+ correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
45
+ system: System.GENERAL,
46
+ subSystemType: SubSystem.DID_PROVIDER,
47
+ actionType: ActionType.CREATE,
48
+ actionSubType: 'Key generation',
49
+ initiatorType: InitiatorType.EXTERNAL,
50
+ systemCorrelationIdType: SystemCorrelationIdType.DID,
51
+ systemCorrelationId: 'did:example:123456789abcdefghi',
52
+ systemAlias: 'test_alias',
53
+ partyCorrelationType: PartyCorrelationType.DID,
54
+ partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
55
+ partyAlias: 'test_alias',
56
+ description: 'test_description',
57
+ data: 'test_data_string',
58
+ diagnosticData: { data: 'test_data_string'}
59
+ }
60
+
61
+ const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent})
62
+ expect(savedAuditEvent).toBeDefined()
63
+ })
64
+
65
+ it('should get all audit events', async (): Promise<void> => {
66
+ const auditEvent: NonPersistedAuditLoggingEvent = {
67
+ timestamp: new Date(),
68
+ level: LogLevel.DEBUG,
69
+ correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
70
+ system: System.GENERAL,
71
+ subSystemType: SubSystem.DID_PROVIDER,
72
+ actionType: ActionType.CREATE,
73
+ actionSubType: 'Key generation',
74
+ initiatorType: InitiatorType.EXTERNAL,
75
+ systemCorrelationIdType: SystemCorrelationIdType.DID,
76
+ systemCorrelationId: 'did:example:123456789abcdefghi',
77
+ systemAlias: 'test_alias',
78
+ partyCorrelationType: PartyCorrelationType.DID,
79
+ partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
80
+ partyAlias: 'test_alias',
81
+ description: 'test_description',
82
+ data: 'test_data_string',
83
+ diagnosticData: { data: 'test_data_string'}
84
+ }
85
+
86
+ const auditEvent1: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent})
87
+ expect(auditEvent1).toBeDefined()
88
+
89
+ const auditEvent2: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent})
90
+ expect(auditEvent2).toBeDefined()
91
+
92
+ const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents()
93
+ expect(result.length).toEqual(2)
94
+ })
95
+
96
+ it('should get audit events by filter', async (): Promise<void> => {
97
+ const auditEvent: NonPersistedAuditLoggingEvent = {
98
+ timestamp: new Date(),
99
+ level: LogLevel.DEBUG,
100
+ correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
101
+ system: System.GENERAL,
102
+ subSystemType: SubSystem.DID_PROVIDER,
103
+ actionType: ActionType.CREATE,
104
+ actionSubType: 'Key generation',
105
+ initiatorType: InitiatorType.EXTERNAL,
106
+ systemCorrelationIdType: SystemCorrelationIdType.DID,
107
+ systemCorrelationId: 'did:example:123456789abcdefghi',
108
+ systemAlias: 'test_alias',
109
+ partyCorrelationType: PartyCorrelationType.DID,
110
+ partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
111
+ partyAlias: 'test_alias',
112
+ description: 'test_description',
113
+ data: 'test_data_string',
114
+ diagnosticData: { data: 'test_data_string'}
115
+ }
116
+
117
+ const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({event: auditEvent})
118
+ expect(savedAuditEvent).toBeDefined()
119
+
120
+ const args: GetAuditEventsArgs = {
121
+ filter: [{ correlationId: auditEvent.correlationId }],
122
+ }
123
+ const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents(args)
124
+
125
+ expect(result.length).toEqual(1)
126
+ })
127
+
128
+ it('should return no audit events if filter does not match', async (): Promise<void> => {
129
+ const args: GetAuditEventsArgs = {
130
+ filter: [{ correlationId: 'unknown_id'}],
131
+ }
132
+ const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents(args)
133
+
134
+ expect(result.length).toEqual(0)
135
+ })
136
+
137
+ })
@@ -0,0 +1,106 @@
1
+ import {
2
+ BaseEntity,
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ PrimaryGeneratedColumn,
7
+ UpdateDateColumn
8
+ } from 'typeorm'
9
+ import {
10
+ ActionType,
11
+ InitiatorType,
12
+ LogLevel,
13
+ PartyCorrelationType,
14
+ SubSystem,
15
+ System,
16
+ SystemCorrelationIdType,
17
+ ActionSubType
18
+ } from '@sphereon/ssi-sdk.core'
19
+ import { NonPersistedAuditLoggingEvent } from '../../types'
20
+
21
+ @Entity('AuditEvents')
22
+ export class AuditEventEntity extends BaseEntity {
23
+ @PrimaryGeneratedColumn('uuid')
24
+ id!: string
25
+
26
+ @Column({ name: 'timestamp', nullable: false, unique: false})
27
+ timestamp!: Date
28
+
29
+ @Column('simple-enum', { name: 'level', enum: LogLevel, nullable: false, unique: false })
30
+ level!: LogLevel
31
+
32
+ @Column({ name: 'correlationId', nullable: false, unique: false})
33
+ correlationId!: string
34
+
35
+ @Column('simple-enum', { name: 'system', enum: System, nullable: false, unique: false })
36
+ system!: System
37
+
38
+ @Column('simple-enum', { name: 'subSystemType', enum: SubSystem, nullable: false, unique: false })
39
+ subSystemType!: SubSystem
40
+
41
+ @Column('simple-enum', { name: 'actionType', enum: ActionType, nullable: false, unique: false })
42
+ actionType!: ActionType
43
+
44
+ @Column({ name: 'actionSubType', nullable: false, unique: false })
45
+ actionSubType!: ActionSubType
46
+
47
+ @Column('simple-enum', { name: 'initiatorType', enum: InitiatorType, nullable: false, unique: false })
48
+ initiatorType!: InitiatorType
49
+
50
+ @Column('simple-enum', { name: 'systemCorrelationIdType', enum: SystemCorrelationIdType, nullable: true, unique: false })
51
+ systemCorrelationIdType?: SystemCorrelationIdType
52
+
53
+ @Column({ name: 'systemCorrelationId', nullable: true, unique: false})
54
+ systemCorrelationId?: string
55
+
56
+ @Column({ name: 'systemAlias', nullable: false, unique: false})
57
+ systemAlias?: string
58
+
59
+ @Column('simple-enum', { name: 'partyCorrelationType', enum: PartyCorrelationType, nullable: true, unique: false })
60
+ partyCorrelationType?: PartyCorrelationType
61
+
62
+ @Column({ name: 'partyCorrelationId', nullable: true, unique: false})
63
+ partyCorrelationId?: string
64
+
65
+ @Column({ name: 'partyAlias', nullable: true, unique: false})
66
+ partyAlias?: string
67
+
68
+ @Column({ name: 'description', nullable: false, unique: false})
69
+ description!: string
70
+
71
+ @Column({ name: 'data', nullable: true, unique: false})
72
+ data?: string
73
+
74
+ @Column({ name: 'diagnosticData', nullable: true, unique: false})
75
+ diagnosticData?: string
76
+
77
+ @CreateDateColumn({ name: 'created_at', nullable: false })
78
+ createdAt!: Date
79
+
80
+ @UpdateDateColumn({ name: 'last_updated_at', nullable: false })
81
+ lastUpdatedAt!: Date
82
+ }
83
+
84
+ export const auditEventEntityFrom = (args: NonPersistedAuditLoggingEvent): AuditEventEntity => {
85
+ const auditEventEntity: AuditEventEntity = new AuditEventEntity()
86
+ auditEventEntity.timestamp = args.timestamp
87
+ auditEventEntity.level = args.level
88
+ auditEventEntity.correlationId = args.correlationId
89
+ auditEventEntity.system = args.system
90
+ auditEventEntity.subSystemType = args.subSystemType
91
+ auditEventEntity.actionType = args.actionType
92
+ auditEventEntity.actionSubType = args.actionSubType
93
+ auditEventEntity.initiatorType = args.initiatorType
94
+ auditEventEntity.systemCorrelationIdType = args.systemCorrelationIdType
95
+ auditEventEntity.systemCorrelationId = args.systemCorrelationId
96
+ auditEventEntity.systemAlias = args.systemAlias
97
+ auditEventEntity.partyCorrelationType = args.partyCorrelationType
98
+ auditEventEntity.partyCorrelationId = args.partyCorrelationId
99
+ auditEventEntity.partyAlias = args.partyAlias
100
+ auditEventEntity.description = args.description
101
+ auditEventEntity.partyCorrelationType = args.partyCorrelationType
102
+ auditEventEntity.data = JSON.stringify(args.data)
103
+ auditEventEntity.diagnosticData = JSON.stringify(args.diagnosticData)
104
+
105
+ return auditEventEntity
106
+ }
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  IIssuer,
3
- OriginalVerifiableCredential,
3
+ JwtDecodedVerifiableCredential,
4
4
  StatusListCredentialIdMode,
5
5
  StatusListDriverType,
6
6
  StatusListIndexingDirection,
7
7
  StatusListType,
8
8
  StatusPurpose2021,
9
+ W3CVerifiableCredential,
9
10
  } from '@sphereon/ssi-types'
10
11
  import { ProofFormat } from '@veramo/core'
11
12
  import { BaseEntity, Column, Entity, OneToMany, PrimaryColumn, Unique } from 'typeorm'
@@ -74,13 +75,13 @@ export class StatusListEntity extends BaseEntity {
74
75
  nullable: true,
75
76
  unique: false,
76
77
  transformer: {
77
- from(value: string): OriginalVerifiableCredential {
78
+ from(value: string): W3CVerifiableCredential | JwtDecodedVerifiableCredential {
78
79
  if (value?.startsWith('ey')) {
79
80
  return value
80
81
  }
81
82
  return JSON.parse(value)
82
83
  },
83
- to(value: OriginalVerifiableCredential): string {
84
+ to(value: W3CVerifiableCredential | JwtDecodedVerifiableCredential): string {
84
85
  if (typeof value === 'string') {
85
86
  return value
86
87
  }
@@ -88,7 +89,7 @@ export class StatusListEntity extends BaseEntity {
88
89
  },
89
90
  },
90
91
  })
91
- statusListCredential?: OriginalVerifiableCredential
92
+ statusListCredential?: W3CVerifiableCredential | JwtDecodedVerifiableCredential
92
93
 
93
94
  @OneToMany((type) => StatusListEntryEntity, (entry) => entry.statusList)
94
95
  statusListEntries!: StatusListEntryEntity[]
@@ -0,0 +1,8 @@
1
+ import { GetAuditEventsArgs, StoreAuditEventArgs } from '../types'
2
+ import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
3
+
4
+ export abstract class AbstractEventLoggerStore {
5
+ abstract getAuditEvents(args: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>>
6
+ abstract storeAuditEvent(args: StoreAuditEventArgs): Promise<AuditLoggingEvent>
7
+ }
8
+
@@ -0,0 +1,62 @@
1
+ import Debug, {Debugger} from 'debug'
2
+ import {DataSource} from 'typeorm'
3
+ import {AuditLoggingEvent} from '@sphereon/ssi-sdk.core'
4
+ import {OrPromise} from '@sphereon/ssi-types'
5
+ import {AbstractEventLoggerStore} from './AbstractEventLoggerStore'
6
+ import {AuditEventEntity, auditEventEntityFrom} from '../entities/eventLogger/AuditEventEntity'
7
+ import {GetAuditEventsArgs, StoreAuditEventArgs} from '../types'
8
+
9
+ const debug: Debugger = Debug('sphereon:ssi-sdk:event-store')
10
+
11
+ export class EventLoggerStore extends AbstractEventLoggerStore {
12
+ private readonly dbConnection: OrPromise<DataSource>
13
+
14
+ constructor(dbConnection: OrPromise<DataSource>) {
15
+ super()
16
+ this.dbConnection = dbConnection
17
+ }
18
+
19
+ getAuditEvents = async (args?: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>> => {
20
+ const connection: DataSource = await this.dbConnection // TODO apply everywhere
21
+ debug('Getting audit events', args)
22
+ const result: Array<AuditEventEntity> = await connection.getRepository(AuditEventEntity).find({
23
+ ...(args?.filter && { where: args?.filter }),
24
+ })
25
+
26
+ return result.map((event: AuditEventEntity) => this.auditEventFrom(event))
27
+ }
28
+
29
+ storeAuditEvent = async (args: StoreAuditEventArgs): Promise<AuditLoggingEvent> => {
30
+ const { event } = args
31
+
32
+ const auditEventEntity: AuditEventEntity = auditEventEntityFrom(event)
33
+ const connection: DataSource = await this.dbConnection
34
+ debug('Storing audit event', auditEventEntity)
35
+ const createdResult: AuditEventEntity = await connection.getRepository(AuditEventEntity).save(auditEventEntity)
36
+
37
+ return this.auditEventFrom(createdResult)
38
+ }
39
+
40
+ private auditEventFrom = (event: AuditEventEntity): AuditLoggingEvent => {
41
+ return {
42
+ id: event.id,
43
+ description: event.description,
44
+ timestamp: event.timestamp,
45
+ level: event.level,
46
+ correlationId: event.correlationId,
47
+ actionType: event.actionType,
48
+ actionSubType: event.actionSubType,
49
+ initiatorType: event.initiatorType,
50
+ partyAlias: event.partyAlias,
51
+ partyCorrelationId: event.partyCorrelationId,
52
+ partyCorrelationType: event.partyCorrelationType,
53
+ subSystemType: event.subSystemType,
54
+ system: event.system,
55
+ systemAlias: event.systemAlias,
56
+ systemCorrelationId: event.systemCorrelationId,
57
+ systemCorrelationIdType: event.systemCorrelationIdType,
58
+ ...(event.data && {data: JSON.parse(event.data)}),
59
+ ...(event.diagnosticData && {diagnosticData: JSON.parse(event.diagnosticData)}),
60
+ }
61
+ }
62
+ }
package/src/index.ts CHANGED
@@ -29,6 +29,9 @@ export { AbstractContactStore } from './contact/AbstractContactStore'
29
29
  export { AbstractIssuanceBrandingStore } from './issuanceBranding/AbstractIssuanceBrandingStore'
30
30
  export { IssuanceBrandingStore } from './issuanceBranding/IssuanceBrandingStore'
31
31
  export { StatusListStore } from './statusList/StatusListStore'
32
+ import { AuditEventEntity, auditEventEntityFrom } from './entities/eventLogger/AuditEventEntity'
33
+ export { AbstractEventLoggerStore } from './eventLogger/AbstractEventLoggerStore'
34
+ export { EventLoggerStore } from './eventLogger/EventLoggerStore'
32
35
  export { DataStoreMigrations } from './migrations'
33
36
  export * from './types'
34
37
  export * from './utils/contact/MappingUtils'
@@ -64,8 +67,18 @@ export const DataStoreIssuanceBrandingEntities = [
64
67
 
65
68
  export const DataStoreStatusListEntities = [StatusListEntity, StatusListEntryEntity]
66
69
 
70
+ export const DataStoreEventLoggerEntities = [
71
+ AuditEventEntity
72
+ ]
73
+
74
+
67
75
  // All entities combined if a party wants to enable them all at once
68
- export const DataStoreEntities = [...DataStoreContactEntities, ...DataStoreIssuanceBrandingEntities, ...DataStoreStatusListEntities]
76
+ export const DataStoreEntities = [
77
+ ...DataStoreContactEntities,
78
+ ...DataStoreIssuanceBrandingEntities,
79
+ ...DataStoreStatusListEntities,
80
+ ...DataStoreEventLoggerEntities
81
+ ]
69
82
 
70
83
  export {
71
84
  BaseConfigEntity,
@@ -98,4 +111,6 @@ export {
98
111
  IStatusListEntryEntity,
99
112
  StatusListEntity,
100
113
  StatusListEntryEntity,
114
+ AuditEventEntity,
115
+ auditEventEntityFrom
101
116
  }
@@ -31,7 +31,7 @@ export class CreateContacts1659463079429 implements MigrationInterface {
31
31
  }
32
32
  default:
33
33
  return Promise.reject(
34
- `Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
34
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
35
35
  )
36
36
  }
37
37
  }
@@ -59,7 +59,7 @@ export class CreateContacts1659463079429 implements MigrationInterface {
59
59
  }
60
60
  default:
61
61
  return Promise.reject(
62
- `Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
62
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
63
63
  )
64
64
  }
65
65
  }
@@ -30,7 +30,7 @@ export class CreateIssuanceBranding1659463079429 implements MigrationInterface {
30
30
  }
31
31
  default:
32
32
  return Promise.reject(
33
- `Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
33
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
34
34
  )
35
35
  }
36
36
  }
@@ -57,7 +57,7 @@ export class CreateIssuanceBranding1659463079429 implements MigrationInterface {
57
57
  }
58
58
  default:
59
59
  return Promise.reject(
60
- `Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
60
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
61
61
  )
62
62
  }
63
63
  }
@@ -31,7 +31,7 @@ export class CreateContacts1690925872318 implements MigrationInterface {
31
31
  }
32
32
  default:
33
33
  return Promise.reject(
34
- `Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
34
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
35
35
  )
36
36
  }
37
37
  }
@@ -59,7 +59,7 @@ export class CreateContacts1690925872318 implements MigrationInterface {
59
59
  }
60
60
  default:
61
61
  return Promise.reject(
62
- `Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
62
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
63
63
  )
64
64
  }
65
65
  }
@@ -1,6 +1,6 @@
1
1
  import Debug from 'debug'
2
2
  import { MigrationInterface, QueryRunner } from 'typeorm'
3
- import { CreateStatusList1693866470001 } from '../postgres/CreateStatusList1693866470001-CreateStatusList'
3
+ import { CreateStatusList1693866470001 } from '../postgres/1693866470001-CreateStatusList'
4
4
  import { CreateStatusList1693866470002 } from '../sqlite/1693866470000-CreateStatusList'
5
5
 
6
6
  const debug = Debug('sphereon:ssi-sdk:migrations')
@@ -25,7 +25,7 @@ export class CreateStatusList1693866470000 implements MigrationInterface {
25
25
  return up
26
26
  } else {
27
27
  return Promise.reject(
28
- `Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
28
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
29
29
  )
30
30
  }
31
31
  }
@@ -47,7 +47,7 @@ export class CreateStatusList1693866470000 implements MigrationInterface {
47
47
  return down
48
48
  } else {
49
49
  return Promise.reject(
50
- `Migrations are currently only supported for sqlite, react-native, expor and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
50
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
51
51
  )
52
52
  }
53
53
  }
@@ -0,0 +1,66 @@
1
+ import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
2
+ import Debug, { Debugger } from 'debug'
3
+ import { CreateAuditEvents1701634819487 } from '../sqlite/1701634819487-CreateAuditEvents'
4
+ import { CreateAuditEvents1701634812183 } from '../postgres/1701634812183-CreateAuditEvents'
5
+
6
+ const debug: Debugger = Debug('sphereon:ssi-sdk:migrations')
7
+
8
+ export class CreateAuditEvents1701635835330 implements MigrationInterface {
9
+ name: string = 'CreateAuditEvents1701635835330'
10
+
11
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
+ debug('migration: creating audit events tables')
13
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
14
+
15
+ switch (dbType) {
16
+ case 'postgres': {
17
+ debug('using postgres migration file')
18
+ const mig: CreateAuditEvents1701634812183 = new CreateAuditEvents1701634812183()
19
+ await mig.up(queryRunner)
20
+ debug('Migration statements executed')
21
+ return
22
+ }
23
+ case 'sqlite':
24
+ case 'expo':
25
+ case 'react-native': {
26
+ debug('using sqlite/react-native migration file')
27
+ const mig: CreateAuditEvents1701634819487 = new CreateAuditEvents1701634819487()
28
+ await mig.up(queryRunner)
29
+ debug('Migration statements executed')
30
+ return
31
+ }
32
+ default:
33
+ return Promise.reject(
34
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
35
+ )
36
+ }
37
+ }
38
+
39
+ public async down(queryRunner: QueryRunner): Promise<void> {
40
+ debug('migration: reverting audit events tables')
41
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
42
+
43
+ switch (dbType) {
44
+ case 'postgres': {
45
+ debug('using postgres migration file')
46
+ const mig: CreateAuditEvents1701634812183 = new CreateAuditEvents1701634812183()
47
+ await mig.down(queryRunner)
48
+ debug('Migration statements executed')
49
+ return
50
+ }
51
+ case 'sqlite':
52
+ case 'expo':
53
+ case 'react-native': {
54
+ debug('using sqlite/react-native migration file')
55
+ const mig: CreateAuditEvents1701634819487 = new CreateAuditEvents1701634819487()
56
+ await mig.down(queryRunner)
57
+ debug('Migration statements executed')
58
+ return
59
+ }
60
+ default:
61
+ return Promise.reject(
62
+ `Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
63
+ )
64
+ }
65
+ }
66
+ }
@@ -1,7 +1,8 @@
1
1
  import { CreateContacts1659463079429 } from './1-CreateContacts'
2
- import { CreateContacts1690925872318 } from './2-CreateContacts'
3
2
  import { CreateIssuanceBranding1659463079429 } from './2-CreateIssuanceBranding'
4
- import { CreateStatusList1693866470000 } from './3-CreateStatusList'
3
+ import { CreateContacts1690925872318 } from './3-CreateContacts'
4
+ import { CreateStatusList1693866470000 } from './4-CreateStatusList'
5
+ import { CreateAuditEvents1701635835330 } from './5-CreateAuditEvents'
5
6
 
6
7
  /**
7
8
  * The migrations array that SHOULD be used when initializing a TypeORM database connection.
@@ -15,6 +16,12 @@ import { CreateStatusList1693866470000 } from './3-CreateStatusList'
15
16
  export const DataStoreContactMigrations = [CreateContacts1659463079429, CreateContacts1690925872318]
16
17
  export const DataStoreIssuanceBrandingMigrations = [CreateIssuanceBranding1659463079429]
17
18
  export const DataStoreStatusListMigrations = [CreateStatusList1693866470000]
19
+ export const DataStoreEventLoggerMigrations= [CreateAuditEvents1701635835330]
18
20
 
19
21
  // All migrations together
20
- export const DataStoreMigrations = [...DataStoreContactMigrations, ...DataStoreIssuanceBrandingMigrations, ...DataStoreStatusListMigrations]
22
+ export const DataStoreMigrations = [
23
+ ...DataStoreContactMigrations,
24
+ ...DataStoreIssuanceBrandingMigrations,
25
+ ...DataStoreStatusListMigrations,
26
+ ...DataStoreEventLoggerMigrations
27
+ ]
@@ -1,11 +1,11 @@
1
1
  import { MigrationInterface, QueryRunner } from 'typeorm'
2
- import { enableUuidv4 } from './uuid'
2
+ import { enablePostgresUuidExtension } from '@sphereon/ssi-sdk.core'
3
3
 
4
4
  export class CreateContacts1659463079428 implements MigrationInterface {
5
5
  name = 'CreateContacts1659463079428'
6
6
 
7
7
  public async up(queryRunner: QueryRunner): Promise<void> {
8
- await enableUuidv4(queryRunner)
8
+ await enablePostgresUuidExtension(queryRunner)
9
9
  await queryRunner.query(
10
10
  `CREATE TABLE "BaseConfigEntity" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "client_id" character varying(255), "client_secret" character varying(255), "scopes" text, "issuer" character varying(255), "redirect_url" text, "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "identifier" character varying(255), "session_id" character varying(255), "type" character varying NOT NULL, "connectionId" uuid, CONSTRAINT "REL_BaseConfig_connectionId" UNIQUE ("connectionId"), CONSTRAINT "PK_BaseConfigEntity_id" PRIMARY KEY ("id"))`
11
11
  )
@@ -1,11 +1,11 @@
1
1
  import { MigrationInterface, QueryRunner } from 'typeorm'
2
- import { enableUuidv4 } from './uuid'
2
+ import { enablePostgresUuidExtension } from '@sphereon/ssi-sdk.core'
3
3
 
4
4
  export class CreateIssuanceBranding1685628974232 implements MigrationInterface {
5
5
  name = 'CreateIssuanceBranding1685628974232'
6
6
 
7
7
  public async up(queryRunner: QueryRunner): Promise<void> {
8
- await enableUuidv4(queryRunner)
8
+ await enablePostgresUuidExtension(queryRunner)
9
9
  await queryRunner.query(
10
10
  `CREATE TABLE "ImageDimensions" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "width" integer NOT NULL, "height" integer NOT NULL, CONSTRAINT "PK_ImageDimensions_id" PRIMARY KEY ("id"))`
11
11
  )
@@ -1,11 +1,11 @@
1
1
  import { MigrationInterface, QueryRunner } from 'typeorm'
2
- import { enableUuidv4 } from './uuid'
2
+ import { enablePostgresUuidExtension } from '@sphereon/ssi-sdk.core'
3
3
 
4
4
  export class CreateContacts1690925872592 implements MigrationInterface {
5
5
  name = 'CreateContacts1690925872592'
6
6
 
7
7
  public async up(queryRunner: QueryRunner): Promise<void> {
8
- await enableUuidv4(queryRunner)
8
+ await enablePostgresUuidExtension(queryRunner)
9
9
  await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP CONSTRAINT "FK_CorrelationIdentifier_identityId"`)
10
10
  await queryRunner.query(`ALTER TABLE "IdentityMetadata" DROP CONSTRAINT "FK_IdentityMetadata_identityId"`)
11
11
  await queryRunner.query(`ALTER TABLE "Identity" DROP CONSTRAINT "FK_Identity_contactId"`)
@@ -0,0 +1,27 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm'
2
+
3
+ export class CreateAuditEvents1701634812183 implements MigrationInterface {
4
+ name = 'CreateAuditEvents1701634812183'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`CREATE TYPE "public"."Level_enum" AS ENUM('0', '1', '2', '3')`)
8
+ await queryRunner.query(`CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'credentials', 'web3', 'profile', 'contact')`)
9
+ await queryRunner.query(`CREATE TYPE "public"."Subsystem_type_enum" AS ENUM('key', 'did_provider', 'did_resolver', 'oid4vp_op', 'oid4vci_client', 'siopv2_op', 'contact_manager', 'vc_issuer', 'vc_verifier', 'vc_persistence', 'transport', 'profile')`)
10
+ await queryRunner.query(`CREATE TYPE "public"."Action_type_enum" AS ENUM('create', 'read', 'update', 'delete', 'execute')`)
11
+ await queryRunner.query(`CREATE TYPE "public"."Initiator_type_enum" AS ENUM('user', 'system', 'external')`)
12
+ await queryRunner.query(`CREATE TYPE "public"."System_correlation_id_type_enum" AS ENUM('did', 'email', 'hostname', 'phone', 'user')`)
13
+ await queryRunner.query(`CREATE TYPE "public"."Party_correlation_type_enum" AS ENUM('did', 'email', 'hostname', 'phone')`)
14
+ await queryRunner.query(`CREATE TABLE "AuditEvents" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "timestamp" TIMESTAMP NOT NULL, "level" "public"."Level_enum" NOT NULL, "correlationId" TEXT NOT NULL, "system" "public"."System_enum" NOT NULL, "subSystemType" "public"."Subsystem_type_enum" NOT NULL, "actionType" "public"."Action_type_enum" NOT NULL, "actionSubType" TEXT NOT NULL, "initiatorType" "public"."Initiator_type_enum" NOT NULL, "systemCorrelationIdType" "public"."System_correlation_id_type_enum", "systemCorrelationId" TEXT, "systemAlias" TEXT NOT NULL, "partyCorrelationType" "public"."Party_correlation_type_enum", "partyCorrelationId" TEXT, "partyAlias" TEXT, "description" TEXT NOT NULL, "data" TEXT, "diagnosticData" TEXT, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))`)
15
+ }
16
+
17
+ public async down(queryRunner: QueryRunner): Promise<void> {
18
+ await queryRunner.query(`DROP TABLE "AuditEvents"`)
19
+ await queryRunner.query(`DROP TYPE "public"."Party_correlation_type_enum`)
20
+ await queryRunner.query(`DROP TYPE "public"."System_correlation_id_type_enum`)
21
+ await queryRunner.query(`DROP TYPE "public"."Initiator_type_enum`)
22
+ await queryRunner.query(`DROP TYPE "public"."Action_type_enum`)
23
+ await queryRunner.query(`DROP TYPE "public"."Subsystem_type_enum`)
24
+ await queryRunner.query(`DROP TYPE "public"."System_enum`)
25
+ await queryRunner.query(`DROP TYPE "public"."Level_enum`)
26
+ }
27
+ }