@sphereon/ssi-sdk.data-store 0.17.6-unstable.8 → 0.18.1-next.2

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 (112) hide show
  1. package/README.md +5 -0
  2. package/dist/contact/ContactStore.d.ts.map +1 -1
  3. package/dist/contact/ContactStore.js +5 -0
  4. package/dist/contact/ContactStore.js.map +1 -1
  5. package/dist/entities/eventLogger/AuditEventEntity.d.ts +27 -0
  6. package/dist/entities/eventLogger/AuditEventEntity.d.ts.map +1 -0
  7. package/dist/entities/eventLogger/AuditEventEntity.js +124 -0
  8. package/dist/entities/eventLogger/AuditEventEntity.js.map +1 -0
  9. package/dist/entities/statusList2021/StatusList2021Entity.d.ts +2 -2
  10. package/dist/entities/statusList2021/StatusList2021Entity.d.ts.map +1 -1
  11. package/dist/entities/statusList2021/StatusList2021Entity.js.map +1 -1
  12. package/dist/eventLogger/AbstractEventLoggerStore.d.ts +7 -0
  13. package/dist/eventLogger/AbstractEventLoggerStore.d.ts.map +1 -0
  14. package/dist/eventLogger/AbstractEventLoggerStore.js +7 -0
  15. package/dist/eventLogger/AbstractEventLoggerStore.js.map +1 -0
  16. package/dist/eventLogger/EventLoggerStore.d.ts +13 -0
  17. package/dist/eventLogger/EventLoggerStore.d.ts.map +1 -0
  18. package/dist/eventLogger/EventLoggerStore.js +44 -0
  19. package/dist/eventLogger/EventLoggerStore.js.map +1 -0
  20. package/dist/index.d.ts +7 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +15 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/migrations/generic/1-CreateContacts.js +2 -2
  25. package/dist/migrations/generic/1-CreateContacts.js.map +1 -1
  26. package/dist/migrations/generic/2-CreateIssuanceBranding.js +2 -2
  27. package/dist/migrations/generic/2-CreateIssuanceBranding.js.map +1 -1
  28. package/dist/migrations/generic/{2-CreateContacts.d.ts → 3-CreateContacts.d.ts} +1 -1
  29. package/dist/migrations/generic/{2-CreateContacts.d.ts.map → 3-CreateContacts.d.ts.map} +1 -1
  30. package/dist/migrations/generic/{2-CreateContacts.js → 3-CreateContacts.js} +3 -3
  31. package/dist/migrations/generic/{2-CreateContacts.js.map → 3-CreateContacts.js.map} +1 -1
  32. package/dist/migrations/generic/{3-CreateStatusList.d.ts → 4-CreateStatusList.d.ts} +1 -1
  33. package/dist/migrations/generic/{3-CreateStatusList.d.ts.map → 4-CreateStatusList.d.ts.map} +1 -1
  34. package/dist/migrations/generic/{3-CreateStatusList.js → 4-CreateStatusList.js} +5 -5
  35. package/dist/migrations/generic/{3-CreateStatusList.js.map → 4-CreateStatusList.js.map} +1 -1
  36. package/dist/migrations/generic/5-CreateAuditEvents.d.ts +7 -0
  37. package/dist/migrations/generic/5-CreateAuditEvents.d.ts.map +1 -0
  38. package/dist/migrations/generic/5-CreateAuditEvents.js +78 -0
  39. package/dist/migrations/generic/5-CreateAuditEvents.js.map +1 -0
  40. package/dist/migrations/generic/index.d.ts +3 -1
  41. package/dist/migrations/generic/index.d.ts.map +1 -1
  42. package/dist/migrations/generic/index.js +13 -6
  43. package/dist/migrations/generic/index.js.map +1 -1
  44. package/dist/migrations/index.d.ts +0 -1
  45. package/dist/migrations/index.d.ts.map +1 -1
  46. package/dist/migrations/index.js +1 -3
  47. package/dist/migrations/index.js.map +1 -1
  48. package/dist/migrations/postgres/1659463079428-CreateContacts.js +2 -2
  49. package/dist/migrations/postgres/1659463079428-CreateContacts.js.map +1 -1
  50. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +2 -2
  51. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js.map +1 -1
  52. package/dist/migrations/postgres/1690925872592-CreateContacts.js +2 -2
  53. package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -1
  54. package/dist/migrations/postgres/{CreateStatusList1693866470001-CreateStatusList.d.ts → 1693866470001-CreateStatusList.d.ts} +1 -1
  55. package/dist/migrations/postgres/1693866470001-CreateStatusList.d.ts.map +1 -0
  56. package/dist/migrations/postgres/{CreateStatusList1693866470001-CreateStatusList.js → 1693866470001-CreateStatusList.js} +1 -1
  57. package/dist/migrations/postgres/1693866470001-CreateStatusList.js.map +1 -0
  58. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.d.ts +7 -0
  59. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.d.ts.map +1 -0
  60. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js +43 -0
  61. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js.map +1 -0
  62. package/dist/migrations/sqlite/1690925872693-CreateContacts.js +1 -1
  63. package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -1
  64. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.d.ts +7 -0
  65. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.d.ts.map +1 -0
  66. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js +29 -0
  67. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js.map +1 -0
  68. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts +10 -0
  69. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts.map +1 -0
  70. package/dist/types/eventLogger/IAbstractEventLoggerStore.js +3 -0
  71. package/dist/types/eventLogger/IAbstractEventLoggerStore.js.map +1 -0
  72. package/dist/types/eventLogger/eventLogger.d.ts +3 -0
  73. package/dist/types/eventLogger/eventLogger.d.ts.map +1 -0
  74. package/dist/types/eventLogger/eventLogger.js +3 -0
  75. package/dist/types/eventLogger/eventLogger.js.map +1 -0
  76. package/dist/types/index.d.ts +2 -0
  77. package/dist/types/index.d.ts.map +1 -1
  78. package/dist/types/index.js +2 -0
  79. package/dist/types/index.js.map +1 -1
  80. package/package.json +4 -3
  81. package/src/__tests__/eventLogger.entities.test.ts +73 -0
  82. package/src/__tests__/eventLogger.store.test.ts +136 -0
  83. package/src/contact/ContactStore.ts +6 -0
  84. package/src/entities/eventLogger/AuditEventEntity.ts +99 -0
  85. package/src/entities/statusList2021/StatusList2021Entity.ts +5 -4
  86. package/src/eventLogger/AbstractEventLoggerStore.ts +7 -0
  87. package/src/eventLogger/EventLoggerStore.ts +62 -0
  88. package/src/index.ts +14 -2
  89. package/src/migrations/generic/1-CreateContacts.ts +2 -2
  90. package/src/migrations/generic/2-CreateIssuanceBranding.ts +2 -2
  91. package/src/migrations/generic/{2-CreateContacts.ts → 3-CreateContacts.ts} +2 -2
  92. package/src/migrations/generic/{3-CreateStatusList.ts → 4-CreateStatusList.ts} +3 -3
  93. package/src/migrations/generic/5-CreateAuditEvents.ts +66 -0
  94. package/src/migrations/generic/index.ts +10 -3
  95. package/src/migrations/index.ts +0 -1
  96. package/src/migrations/postgres/1659463079428-CreateContacts.ts +2 -2
  97. package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +2 -2
  98. package/src/migrations/postgres/1690925872592-CreateContacts.ts +2 -2
  99. package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +33 -0
  100. package/src/migrations/sqlite/1690925872693-CreateContacts.ts +1 -1
  101. package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +15 -0
  102. package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -0
  103. package/src/types/eventLogger/eventLogger.ts +3 -0
  104. package/src/types/index.ts +2 -1
  105. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts.map +0 -1
  106. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js.map +0 -1
  107. package/dist/migrations/postgres/uuid.d.ts +0 -3
  108. package/dist/migrations/postgres/uuid.d.ts.map +0 -1
  109. package/dist/migrations/postgres/uuid.js +0 -25
  110. package/dist/migrations/postgres/uuid.js.map +0 -1
  111. package/src/migrations/postgres/uuid.ts +0 -12
  112. /package/src/migrations/postgres/{CreateStatusList1693866470001-CreateStatusList.ts → 1693866470001-CreateStatusList.ts} +0 -0
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IAbstractEventLoggerStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAbstractEventLoggerStore.js","sourceRoot":"","sources":["../../../src/types/eventLogger/IAbstractEventLoggerStore.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core';
2
+ export type NonPersistedAuditLoggingEvent = Omit<AuditLoggingEvent, 'id'>;
3
+ //# sourceMappingURL=eventLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventLogger.d.ts","sourceRoot":"","sources":["../../../src/types/eventLogger/eventLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=eventLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventLogger.js","sourceRoot":"","sources":["../../../src/types/eventLogger/eventLogger.ts"],"names":[],"mappings":""}
@@ -5,4 +5,6 @@ export * from './contact/IAbstractContactStore';
5
5
  export * from './validation/validation';
6
6
  export * from './statusList/statusList';
7
7
  export * from './statusList/IAbstractStatusListStore';
8
+ export * from './eventLogger/IAbstractEventLoggerStore';
9
+ export * from './eventLogger/eventLogger';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAA;AACnD,cAAc,mDAAmD,CAAA;AACjE,cAAc,mBAAmB,CAAA;AACjC,cAAc,iCAAiC,CAAA;AAE/C,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,uCAAuC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAA;AACnD,cAAc,mDAAmD,CAAA;AACjE,cAAc,mBAAmB,CAAA;AACjC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,uCAAuC,CAAA;AACrD,cAAc,yCAAyC,CAAA;AACvD,cAAc,2BAA2B,CAAA"}
@@ -21,4 +21,6 @@ __exportStar(require("./contact/IAbstractContactStore"), exports);
21
21
  __exportStar(require("./validation/validation"), exports);
22
22
  __exportStar(require("./statusList/statusList"), exports);
23
23
  __exportStar(require("./statusList/IAbstractStatusListStore"), exports);
24
+ __exportStar(require("./eventLogger/IAbstractEventLoggerStore"), exports);
25
+ __exportStar(require("./eventLogger/eventLogger"), exports);
24
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAmD;AACnD,oFAAiE;AACjE,oDAAiC;AACjC,kEAA+C;AAE/C,0DAAuC;AACvC,0DAAuC;AACvC,wEAAqD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAmD;AACnD,oFAAiE;AACjE,oDAAiC;AACjC,kEAA+C;AAC/C,0DAAuC;AACvC,0DAAuC;AACvC,wEAAqD;AACrD,0EAAuD;AACvD,4DAAyC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.data-store",
3
- "version": "0.17.6-unstable.8+d7c1237c",
3
+ "version": "0.18.1-next.2+220d7148",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,7 +13,8 @@
13
13
  "typeorm-postgres:migration:run": "pnpm run typeorm -- migration:run -c migration-postgres"
14
14
  },
15
15
  "dependencies": {
16
- "@sphereon/ssi-types": "0.17.6-unstable.8+d7c1237c",
16
+ "@sphereon/ssi-sdk.core": "0.18.1-next.2+220d7148",
17
+ "@sphereon/ssi-types": "0.18.1-next.2+220d7148",
17
18
  "@veramo/core": "4.2.0",
18
19
  "class-validator": "^0.14.0",
19
20
  "debug": "^4.3.4",
@@ -42,5 +43,5 @@
42
43
  "PostgreSQL",
43
44
  "Contact Store"
44
45
  ],
45
- "gitHead": "d7c1237c3c384fa6fc9d775f8f165abb6a96a40a"
46
+ "gitHead": "220d71483e27b283d6261178d1a6e986cf4029fa"
46
47
  }
@@ -0,0 +1,73 @@
1
+ import { DataSource } from 'typeorm'
2
+ import { DataStoreEventLoggerEntities } from '../index'
3
+ import { DataStoreEventLoggerMigrations } from '../migrations/generic'
4
+ import { ActionType, InitiatorType, LogLevel, PartyCorrelationType, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-sdk.core'
5
+ import { auditEventEntityFrom, AuditEventEntity } from '../entities/eventLogger/AuditEventEntity'
6
+ import { NonPersistedAuditLoggingEvent } from '../types'
7
+
8
+ describe('Database entities tests', (): void => {
9
+ let dbConnection: DataSource
10
+
11
+ beforeEach(async (): Promise<void> => {
12
+ dbConnection = await new DataSource({
13
+ type: 'sqlite',
14
+ database: ':memory:',
15
+ //logging: 'all',
16
+ migrationsRun: false,
17
+ migrations: DataStoreEventLoggerMigrations,
18
+ synchronize: false,
19
+ entities: [...DataStoreEventLoggerEntities],
20
+ }).initialize()
21
+ await dbConnection.runMigrations()
22
+ expect(await dbConnection.showMigrations()).toBeFalsy()
23
+ })
24
+
25
+ afterEach(async (): Promise<void> => {
26
+ await (await dbConnection).destroy()
27
+ })
28
+
29
+ it('should save audit event to database', async (): Promise<void> => {
30
+ const auditEvent: NonPersistedAuditLoggingEvent = {
31
+ timestamp: new Date(),
32
+ level: LogLevel.DEBUG,
33
+ correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
34
+ system: System.GENERAL,
35
+ subSystemType: SubSystem.DID_PROVIDER,
36
+ actionType: ActionType.CREATE,
37
+ actionSubType: 'Key generation',
38
+ initiatorType: InitiatorType.EXTERNAL,
39
+ systemCorrelationIdType: SystemCorrelationIdType.DID,
40
+ systemCorrelationId: 'did:example:123456789abcdefghi',
41
+ systemAlias: 'test_alias',
42
+ partyCorrelationType: PartyCorrelationType.DID,
43
+ partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
44
+ partyAlias: 'test_alias',
45
+ description: 'test_description',
46
+ data: 'test_data_string',
47
+ diagnosticData: { data: 'test_data_string' },
48
+ }
49
+
50
+ const auditEventEntity: AuditEventEntity = auditEventEntityFrom(auditEvent)
51
+ const fromDb: AuditEventEntity = await dbConnection.getRepository(AuditEventEntity).save(auditEventEntity)
52
+
53
+ expect(fromDb).toBeDefined()
54
+ expect(fromDb?.id).not.toBeNull()
55
+ expect(fromDb?.timestamp).toEqual(auditEvent.timestamp)
56
+ expect(fromDb?.level).toEqual(auditEvent.level)
57
+ expect(fromDb?.correlationId).toEqual(auditEvent.correlationId)
58
+ expect(fromDb?.system).toEqual(auditEvent.system)
59
+ expect(fromDb?.subSystemType).toEqual(auditEvent.subSystemType)
60
+ expect(fromDb?.actionType).toEqual(auditEvent.actionType)
61
+ expect(fromDb?.actionSubType).toEqual(auditEvent.actionSubType)
62
+ expect(fromDb?.initiatorType).toEqual(auditEvent.initiatorType)
63
+ expect(fromDb?.systemCorrelationIdType).toEqual(auditEvent.systemCorrelationIdType)
64
+ expect(fromDb?.systemCorrelationId).toEqual(auditEvent.systemCorrelationId)
65
+ expect(fromDb?.systemAlias).toEqual(auditEvent.systemAlias)
66
+ expect(fromDb?.partyCorrelationType).toEqual(auditEvent.partyCorrelationType)
67
+ expect(fromDb?.partyCorrelationId).toEqual(auditEvent.partyCorrelationId)
68
+ expect(fromDb?.partyAlias).toEqual(auditEvent.partyAlias)
69
+ expect(fromDb?.description).toEqual(auditEvent.description)
70
+ expect(fromDb?.data).toEqual(JSON.stringify(auditEvent.data))
71
+ expect(fromDb?.diagnosticData).toEqual(JSON.stringify(auditEvent.diagnosticData))
72
+ })
73
+ })
@@ -0,0 +1,136 @@
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
+ })
@@ -10,6 +10,7 @@ import { ConnectionEntity } from '../entities/contact/ConnectionEntity'
10
10
  import { BaseConfigEntity } from '../entities/contact/BaseConfigEntity'
11
11
  import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity'
12
12
  import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity'
13
+ import { BaseContactEntity } from '../entities/contact/BaseContactEntity'
13
14
  import {
14
15
  identityEntityFrom,
15
16
  identityFrom,
@@ -159,6 +160,11 @@ export class ContactStore extends AbstractContactStore {
159
160
  await partyRepository
160
161
  .delete({ id: partyId })
161
162
  .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)))
163
+
164
+ const partyContactRepository: Repository<BaseContactEntity> = (await this.dbConnection).getRepository(BaseContactEntity)
165
+ await partyContactRepository
166
+ .delete({ id: party.contact.id })
167
+ .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)))
162
168
  }
163
169
  })
164
170
  .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)))
@@ -0,0 +1,99 @@
1
+ import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
2
+ import {
3
+ ActionType,
4
+ InitiatorType,
5
+ LogLevel,
6
+ PartyCorrelationType,
7
+ SubSystem,
8
+ System,
9
+ SystemCorrelationIdType,
10
+ ActionSubType,
11
+ } from '@sphereon/ssi-sdk.core'
12
+ import { NonPersistedAuditLoggingEvent } from '../../types'
13
+
14
+ @Entity('AuditEvents')
15
+ export class AuditEventEntity extends BaseEntity {
16
+ @PrimaryGeneratedColumn('uuid')
17
+ id!: string
18
+
19
+ @Column({ name: 'timestamp', nullable: false, unique: false })
20
+ timestamp!: Date
21
+
22
+ @Column('simple-enum', { name: 'level', enum: LogLevel, nullable: false, unique: false })
23
+ level!: LogLevel
24
+
25
+ @Column({ name: 'correlationId', nullable: false, unique: false })
26
+ correlationId!: string
27
+
28
+ @Column('simple-enum', { name: 'system', enum: System, nullable: false, unique: false })
29
+ system!: System
30
+
31
+ @Column('simple-enum', { name: 'subSystemType', enum: SubSystem, nullable: false, unique: false })
32
+ subSystemType!: SubSystem
33
+
34
+ @Column('simple-enum', { name: 'actionType', enum: ActionType, nullable: false, unique: false })
35
+ actionType!: ActionType
36
+
37
+ @Column({ name: 'actionSubType', nullable: false, unique: false })
38
+ actionSubType!: ActionSubType
39
+
40
+ @Column('simple-enum', { name: 'initiatorType', enum: InitiatorType, nullable: false, unique: false })
41
+ initiatorType!: InitiatorType
42
+
43
+ @Column('simple-enum', { name: 'systemCorrelationIdType', enum: SystemCorrelationIdType, nullable: true, unique: false })
44
+ systemCorrelationIdType?: SystemCorrelationIdType
45
+
46
+ @Column({ name: 'systemCorrelationId', nullable: true, unique: false })
47
+ systemCorrelationId?: string
48
+
49
+ @Column({ name: 'systemAlias', nullable: false, unique: false })
50
+ systemAlias?: string
51
+
52
+ @Column('simple-enum', { name: 'partyCorrelationType', enum: PartyCorrelationType, nullable: true, unique: false })
53
+ partyCorrelationType?: PartyCorrelationType
54
+
55
+ @Column({ name: 'partyCorrelationId', nullable: true, unique: false })
56
+ partyCorrelationId?: string
57
+
58
+ @Column({ name: 'partyAlias', nullable: true, unique: false })
59
+ partyAlias?: string
60
+
61
+ @Column({ name: 'description', nullable: false, unique: false })
62
+ description!: string
63
+
64
+ @Column({ name: 'data', nullable: true, unique: false })
65
+ data?: string
66
+
67
+ @Column({ name: 'diagnosticData', nullable: true, unique: false })
68
+ diagnosticData?: string
69
+
70
+ @CreateDateColumn({ name: 'created_at', nullable: false })
71
+ createdAt!: Date
72
+
73
+ @UpdateDateColumn({ name: 'last_updated_at', nullable: false })
74
+ lastUpdatedAt!: Date
75
+ }
76
+
77
+ export const auditEventEntityFrom = (args: NonPersistedAuditLoggingEvent): AuditEventEntity => {
78
+ const auditEventEntity: AuditEventEntity = new AuditEventEntity()
79
+ auditEventEntity.timestamp = args.timestamp
80
+ auditEventEntity.level = args.level
81
+ auditEventEntity.correlationId = args.correlationId
82
+ auditEventEntity.system = args.system
83
+ auditEventEntity.subSystemType = args.subSystemType
84
+ auditEventEntity.actionType = args.actionType
85
+ auditEventEntity.actionSubType = args.actionSubType
86
+ auditEventEntity.initiatorType = args.initiatorType
87
+ auditEventEntity.systemCorrelationIdType = args.systemCorrelationIdType
88
+ auditEventEntity.systemCorrelationId = args.systemCorrelationId
89
+ auditEventEntity.systemAlias = args.systemAlias
90
+ auditEventEntity.partyCorrelationType = args.partyCorrelationType
91
+ auditEventEntity.partyCorrelationId = args.partyCorrelationId
92
+ auditEventEntity.partyAlias = args.partyAlias
93
+ auditEventEntity.description = args.description
94
+ auditEventEntity.partyCorrelationType = args.partyCorrelationType
95
+ auditEventEntity.data = JSON.stringify(args.data)
96
+ auditEventEntity.diagnosticData = JSON.stringify(args.diagnosticData)
97
+
98
+ return auditEventEntity
99
+ }
@@ -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,7 @@
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
+ }
@@ -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,7 +29,10 @@ 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
- export { DataStoreMigrations, enableUuidv4 } from './migrations'
32
+ import { AuditEventEntity, auditEventEntityFrom } from './entities/eventLogger/AuditEventEntity'
33
+ export { AbstractEventLoggerStore } from './eventLogger/AbstractEventLoggerStore'
34
+ export { EventLoggerStore } from './eventLogger/EventLoggerStore'
35
+ export { DataStoreMigrations } from './migrations'
33
36
  export * from './types'
34
37
  export * from './utils/contact/MappingUtils'
35
38
 
@@ -64,8 +67,15 @@ export const DataStoreIssuanceBrandingEntities = [
64
67
 
65
68
  export const DataStoreStatusListEntities = [StatusListEntity, StatusListEntryEntity]
66
69
 
70
+ export const DataStoreEventLoggerEntities = [AuditEventEntity]
71
+
67
72
  // All entities combined if a party wants to enable them all at once
68
- export const DataStoreEntities = [...DataStoreContactEntities, ...DataStoreIssuanceBrandingEntities, ...DataStoreStatusListEntities]
73
+ export const DataStoreEntities = [
74
+ ...DataStoreContactEntities,
75
+ ...DataStoreIssuanceBrandingEntities,
76
+ ...DataStoreStatusListEntities,
77
+ ...DataStoreEventLoggerEntities,
78
+ ]
69
79
 
70
80
  export {
71
81
  BaseConfigEntity,
@@ -98,4 +108,6 @@ export {
98
108
  IStatusListEntryEntity,
99
109
  StatusListEntity,
100
110
  StatusListEntryEntity,
111
+ AuditEventEntity,
112
+ auditEventEntityFrom,
101
113
  }
@@ -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
  }