@sphereon/ssi-sdk.data-store 0.30.2-next.103 → 0.30.2-next.125
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.
- package/dist/digitalCredential/DigitalCredentialStore.d.ts.map +1 -1
- package/dist/digitalCredential/DigitalCredentialStore.js +1 -3
- package/dist/digitalCredential/DigitalCredentialStore.js.map +1 -1
- package/dist/entities/eventLogger/AuditEventEntity.d.ts +10 -3
- package/dist/entities/eventLogger/AuditEventEntity.d.ts.map +1 -1
- package/dist/entities/eventLogger/AuditEventEntity.js +57 -1
- package/dist/entities/eventLogger/AuditEventEntity.js.map +1 -1
- package/dist/eventLogger/AbstractEventLoggerStore.d.ts +4 -2
- package/dist/eventLogger/AbstractEventLoggerStore.d.ts.map +1 -1
- package/dist/eventLogger/AbstractEventLoggerStore.js.map +1 -1
- package/dist/eventLogger/EventLoggerStore.d.ts +5 -3
- package/dist/eventLogger/EventLoggerStore.d.ts.map +1 -1
- package/dist/eventLogger/EventLoggerStore.js +31 -2
- package/dist/eventLogger/EventLoggerStore.js.map +1 -1
- package/dist/migrations/postgres/1701634812183-CreateAuditEvents.d.ts.map +1 -1
- package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js +34 -6
- package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js.map +1 -1
- package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.d.ts.map +1 -1
- package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js +27 -1
- package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js.map +1 -1
- package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts +9 -2
- package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts.map +1 -1
- package/dist/types/eventLogger/eventLogger.d.ts +3 -2
- package/dist/types/eventLogger/eventLogger.d.ts.map +1 -1
- package/dist/utils/eventLogger/MappingUtils.d.ts +2 -1
- package/dist/utils/eventLogger/MappingUtils.d.ts.map +1 -1
- package/dist/utils/eventLogger/MappingUtils.js +8 -2
- package/dist/utils/eventLogger/MappingUtils.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/digitalCredential.store.test.ts +83 -4
- package/src/__tests__/eventLogger.entities.test.ts +60 -5
- package/src/__tests__/eventLogger.store.test.ts +480 -3
- package/src/digitalCredential/DigitalCredentialStore.ts +1 -3
- package/src/entities/eventLogger/AuditEventEntity.ts +54 -3
- package/src/eventLogger/AbstractEventLoggerStore.ts +9 -2
- package/src/eventLogger/EventLoggerStore.ts +55 -11
- package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +34 -6
- package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +27 -1
- package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -2
- package/src/types/eventLogger/eventLogger.ts +3 -2
- package/src/utils/eventLogger/MappingUtils.ts +34 -1
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ActivityLoggingEvent,
|
|
4
|
+
AuditLoggingEvent,
|
|
5
|
+
CredentialType,
|
|
6
|
+
PartyCorrelationType
|
|
7
|
+
} from '@sphereon/ssi-sdk.core'
|
|
8
|
+
import {
|
|
9
|
+
ActionType,
|
|
10
|
+
InitiatorType,
|
|
11
|
+
LoggingEventType,
|
|
12
|
+
LogLevel,
|
|
13
|
+
SubSystem,
|
|
14
|
+
System,
|
|
15
|
+
SystemCorrelationIdType
|
|
16
|
+
} from '@sphereon/ssi-types'
|
|
3
17
|
import { DataSource } from 'typeorm'
|
|
4
18
|
import { DataStoreEventLoggerMigrations } from '../migrations'
|
|
5
19
|
import { DataStoreEventLoggerEntities } from '../index'
|
|
6
|
-
import { AuditLoggingEvent, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
|
|
7
20
|
import { EventLoggerStore } from '../eventLogger/EventLoggerStore'
|
|
8
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
GetActivityEventsArgs,
|
|
23
|
+
GetAuditEventsArgs,
|
|
24
|
+
NonPersistedAuditLoggingEvent,
|
|
25
|
+
NonPersistedActivityLoggingEvent
|
|
26
|
+
} from '../types'
|
|
9
27
|
|
|
10
28
|
describe('Database entities tests', (): void => {
|
|
11
29
|
let dbConnection: DataSource
|
|
@@ -54,6 +72,7 @@ describe('Database entities tests', (): void => {
|
|
|
54
72
|
|
|
55
73
|
const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
56
74
|
expect(savedAuditEvent).toBeDefined()
|
|
75
|
+
expect(savedAuditEvent.type).toEqual(LoggingEventType.AUDIT)
|
|
57
76
|
})
|
|
58
77
|
|
|
59
78
|
it('should get all audit events', async (): Promise<void> => {
|
|
@@ -83,6 +102,32 @@ describe('Database entities tests', (): void => {
|
|
|
83
102
|
const auditEvent2: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
84
103
|
expect(auditEvent2).toBeDefined()
|
|
85
104
|
|
|
105
|
+
const activityEvent: NonPersistedActivityLoggingEvent = {
|
|
106
|
+
timestamp: new Date(),
|
|
107
|
+
level: LogLevel.DEBUG,
|
|
108
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
109
|
+
originalCredential: 'test_credential_string',
|
|
110
|
+
credentialHash: '341a7897df58e472f9bf19b3b9abf7d5',
|
|
111
|
+
credentialType: CredentialType.SD_JWT,
|
|
112
|
+
system: System.GENERAL,
|
|
113
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
114
|
+
actionType: ActionType.EXECUTE,
|
|
115
|
+
actionSubType: 'Share credential',
|
|
116
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
117
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
118
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
119
|
+
systemAlias: 'test_alias',
|
|
120
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
121
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
122
|
+
partyAlias: 'test_alias',
|
|
123
|
+
description: 'test_description',
|
|
124
|
+
data: 'test_data_string',
|
|
125
|
+
diagnosticData: { data: 'test_data_string' },
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const storedActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: activityEvent })
|
|
129
|
+
expect(storedActivityEvent).toBeDefined()
|
|
130
|
+
|
|
86
131
|
const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents()
|
|
87
132
|
expect(result.length).toEqual(2)
|
|
88
133
|
})
|
|
@@ -120,6 +165,29 @@ describe('Database entities tests', (): void => {
|
|
|
120
165
|
})
|
|
121
166
|
|
|
122
167
|
it('should return no audit events if filter does not match', async (): Promise<void> => {
|
|
168
|
+
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
169
|
+
timestamp: new Date(),
|
|
170
|
+
level: LogLevel.DEBUG,
|
|
171
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
172
|
+
system: System.GENERAL,
|
|
173
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
174
|
+
actionType: ActionType.CREATE,
|
|
175
|
+
actionSubType: 'Key generation',
|
|
176
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
177
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
178
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
179
|
+
systemAlias: 'test_alias',
|
|
180
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
181
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
182
|
+
partyAlias: 'test_alias',
|
|
183
|
+
description: 'test_description',
|
|
184
|
+
data: 'test_data_string',
|
|
185
|
+
diagnosticData: { data: 'test_data_string' },
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
189
|
+
expect(savedAuditEvent).toBeDefined()
|
|
190
|
+
|
|
123
191
|
const args: GetAuditEventsArgs = {
|
|
124
192
|
filter: [{ correlationId: 'unknown_id' }],
|
|
125
193
|
}
|
|
@@ -127,4 +195,413 @@ describe('Database entities tests', (): void => {
|
|
|
127
195
|
|
|
128
196
|
expect(result.length).toEqual(0)
|
|
129
197
|
})
|
|
198
|
+
|
|
199
|
+
it('should store activity event', async (): Promise<void> => {
|
|
200
|
+
const activityEvent: NonPersistedActivityLoggingEvent = {
|
|
201
|
+
timestamp: new Date(),
|
|
202
|
+
level: LogLevel.DEBUG,
|
|
203
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
204
|
+
originalCredential: 'test_credential_string',
|
|
205
|
+
credentialHash: '341a7897df58e472f9bf19b3b9abf7d5',
|
|
206
|
+
credentialType: CredentialType.SD_JWT,
|
|
207
|
+
system: System.GENERAL,
|
|
208
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
209
|
+
actionType: ActionType.EXECUTE,
|
|
210
|
+
actionSubType: 'Share credential',
|
|
211
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
212
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
213
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
214
|
+
systemAlias: 'test_alias',
|
|
215
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
216
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
217
|
+
partyAlias: 'test_alias',
|
|
218
|
+
description: 'test_description',
|
|
219
|
+
data: 'test_data_string',
|
|
220
|
+
diagnosticData: { data: 'test_data_string' },
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const savedActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: activityEvent })
|
|
224
|
+
expect(savedActivityEvent).toBeDefined()
|
|
225
|
+
expect(savedActivityEvent.type).toEqual(LoggingEventType.ACTIVITY)
|
|
226
|
+
expect(savedActivityEvent.originalCredential).toEqual(activityEvent.originalCredential)
|
|
227
|
+
expect(savedActivityEvent.credentialHash).toEqual(activityEvent.credentialHash)
|
|
228
|
+
expect(savedActivityEvent.credentialType).toEqual(activityEvent.credentialType)
|
|
229
|
+
expect(savedActivityEvent.data).toEqual(activityEvent.data)
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
it('should get all activity events', async (): Promise<void> => {
|
|
233
|
+
const activityEvent: NonPersistedActivityLoggingEvent = {
|
|
234
|
+
timestamp: new Date(),
|
|
235
|
+
level: LogLevel.DEBUG,
|
|
236
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
237
|
+
originalCredential: 'test_credential_string',
|
|
238
|
+
credentialHash: '341a7897df58e472f9bf19b3b9abf7d5',
|
|
239
|
+
credentialType: CredentialType.SD_JWT,
|
|
240
|
+
system: System.GENERAL,
|
|
241
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
242
|
+
actionType: ActionType.EXECUTE,
|
|
243
|
+
actionSubType: 'Share credential',
|
|
244
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
245
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
246
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
247
|
+
systemAlias: 'test_alias',
|
|
248
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
249
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
250
|
+
partyAlias: 'test_alias',
|
|
251
|
+
description: 'test_description',
|
|
252
|
+
data: 'test_data_string',
|
|
253
|
+
diagnosticData: { data: 'test_data_string' },
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const activityEvent1: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: activityEvent })
|
|
257
|
+
expect(activityEvent1).toBeDefined()
|
|
258
|
+
|
|
259
|
+
const activityEvent2: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: activityEvent })
|
|
260
|
+
expect(activityEvent2).toBeDefined()
|
|
261
|
+
|
|
262
|
+
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
263
|
+
timestamp: new Date(),
|
|
264
|
+
level: LogLevel.DEBUG,
|
|
265
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
266
|
+
system: System.GENERAL,
|
|
267
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
268
|
+
actionType: ActionType.CREATE,
|
|
269
|
+
actionSubType: 'Key generation',
|
|
270
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
271
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
272
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
273
|
+
systemAlias: 'test_alias',
|
|
274
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
275
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
276
|
+
partyAlias: 'test_alias',
|
|
277
|
+
description: 'test_description',
|
|
278
|
+
data: 'test_data_string',
|
|
279
|
+
diagnosticData: { data: 'test_data_string' },
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const storedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
283
|
+
expect(storedAuditEvent).toBeDefined()
|
|
284
|
+
|
|
285
|
+
const result: Array<ActivityLoggingEvent> = await eventLoggerStore.getActivityEvents()
|
|
286
|
+
expect(result.length).toEqual(2)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it('should get activity events by filter', async (): Promise<void> => {
|
|
290
|
+
const activityEvent: NonPersistedActivityLoggingEvent = {
|
|
291
|
+
timestamp: new Date(),
|
|
292
|
+
level: LogLevel.DEBUG,
|
|
293
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
294
|
+
originalCredential: 'test_credential_string',
|
|
295
|
+
credentialHash: '341a7897df58e472f9bf19b3b9abf7d5',
|
|
296
|
+
credentialType: CredentialType.SD_JWT,
|
|
297
|
+
system: System.GENERAL,
|
|
298
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
299
|
+
actionType: ActionType.EXECUTE,
|
|
300
|
+
actionSubType: 'Share credential',
|
|
301
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
302
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
303
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
304
|
+
systemAlias: 'test_alias',
|
|
305
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
306
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
307
|
+
partyAlias: 'test_alias',
|
|
308
|
+
description: 'test_description',
|
|
309
|
+
data: 'test_data_string',
|
|
310
|
+
diagnosticData: { data: 'test_data_string' },
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const savedActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: activityEvent })
|
|
314
|
+
expect(savedActivityEvent).toBeDefined()
|
|
315
|
+
|
|
316
|
+
const args: GetActivityEventsArgs = {
|
|
317
|
+
filter: [{ credentialHash: savedActivityEvent.credentialHash }],
|
|
318
|
+
}
|
|
319
|
+
const result: Array<ActivityLoggingEvent> = await eventLoggerStore.getActivityEvents(args)
|
|
320
|
+
|
|
321
|
+
expect(result.length).toEqual(1)
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
it('should return no audit events if filter does not match', async (): Promise<void> => {
|
|
325
|
+
const activityEvent: NonPersistedActivityLoggingEvent = {
|
|
326
|
+
timestamp: new Date(),
|
|
327
|
+
level: LogLevel.DEBUG,
|
|
328
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
329
|
+
originalCredential: 'test_credential_string',
|
|
330
|
+
credentialHash: '341a7897df58e472f9bf19b3b9abf7d5',
|
|
331
|
+
credentialType: CredentialType.SD_JWT,
|
|
332
|
+
system: System.GENERAL,
|
|
333
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
334
|
+
actionType: ActionType.EXECUTE,
|
|
335
|
+
actionSubType: 'Share credential',
|
|
336
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
337
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
338
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
339
|
+
systemAlias: 'test_alias',
|
|
340
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
341
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
342
|
+
partyAlias: 'test_alias',
|
|
343
|
+
description: 'test_description',
|
|
344
|
+
data: 'test_data_string',
|
|
345
|
+
diagnosticData: { data: 'test_data_string' },
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const savedActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: activityEvent })
|
|
349
|
+
expect(savedActivityEvent).toBeDefined()
|
|
350
|
+
|
|
351
|
+
const args: GetActivityEventsArgs = {
|
|
352
|
+
filter: [{ credentialHash: 'unknown_hash' }],
|
|
353
|
+
}
|
|
354
|
+
const result: Array<ActivityLoggingEvent> = await eventLoggerStore.getActivityEvents(args)
|
|
355
|
+
|
|
356
|
+
expect(result.length).toEqual(0)
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
it('should get all activity events for a parent credential', async (): Promise<void> => {
|
|
360
|
+
const parentCredentialHash = 'df7037831edbde7f0f65f723ef5494d6'
|
|
361
|
+
|
|
362
|
+
const parentActivityEvent: NonPersistedActivityLoggingEvent = {
|
|
363
|
+
timestamp: new Date(),
|
|
364
|
+
level: LogLevel.DEBUG,
|
|
365
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
366
|
+
originalCredential: 'test_credential_string',
|
|
367
|
+
credentialHash: parentCredentialHash,
|
|
368
|
+
credentialType: CredentialType.SD_JWT,
|
|
369
|
+
system: System.GENERAL,
|
|
370
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
371
|
+
actionType: ActionType.EXECUTE,
|
|
372
|
+
actionSubType: 'Share credential',
|
|
373
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
374
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
375
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
376
|
+
systemAlias: 'test_alias',
|
|
377
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
378
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
379
|
+
partyAlias: 'test_alias',
|
|
380
|
+
description: 'test_description',
|
|
381
|
+
data: 'test_data_string',
|
|
382
|
+
diagnosticData: { data: 'test_data_string' },
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const storedParentActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: parentActivityEvent })
|
|
386
|
+
expect(storedParentActivityEvent).toBeDefined()
|
|
387
|
+
|
|
388
|
+
const childActivityEvent: NonPersistedActivityLoggingEvent = {
|
|
389
|
+
timestamp: new Date(),
|
|
390
|
+
level: LogLevel.DEBUG,
|
|
391
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
392
|
+
originalCredential: 'test_credential_string',
|
|
393
|
+
credentialHash: '341a7897df58e472f9bf19b3b9abf7d5',
|
|
394
|
+
parentCredentialHash,
|
|
395
|
+
credentialType: CredentialType.SD_JWT,
|
|
396
|
+
system: System.GENERAL,
|
|
397
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
398
|
+
actionType: ActionType.EXECUTE,
|
|
399
|
+
actionSubType: 'Share credential',
|
|
400
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
401
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
402
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
403
|
+
systemAlias: 'test_alias',
|
|
404
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
405
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
406
|
+
partyAlias: 'test_alias',
|
|
407
|
+
description: 'test_description',
|
|
408
|
+
data: 'test_data_string',
|
|
409
|
+
diagnosticData: { data: 'test_data_string' },
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const storedChildActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: childActivityEvent })
|
|
413
|
+
expect(storedChildActivityEvent).toBeDefined()
|
|
414
|
+
|
|
415
|
+
const otherActivityEvent: NonPersistedActivityLoggingEvent = {
|
|
416
|
+
timestamp: new Date(),
|
|
417
|
+
level: LogLevel.DEBUG,
|
|
418
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
419
|
+
originalCredential: 'test_credential_string',
|
|
420
|
+
credentialHash: 'a8360b0b0b2eed8d185738536ff5b841',
|
|
421
|
+
credentialType: CredentialType.SD_JWT,
|
|
422
|
+
system: System.GENERAL,
|
|
423
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
424
|
+
actionType: ActionType.EXECUTE,
|
|
425
|
+
actionSubType: 'Share credential', // TODO
|
|
426
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
427
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
428
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
429
|
+
systemAlias: 'test_alias',
|
|
430
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
431
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
432
|
+
partyAlias: 'test_alias',
|
|
433
|
+
description: 'test_description',
|
|
434
|
+
data: 'test_data_string',
|
|
435
|
+
diagnosticData: { data: 'test_data_string' },
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const storedOtherActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: otherActivityEvent })
|
|
439
|
+
expect(storedOtherActivityEvent).toBeDefined()
|
|
440
|
+
|
|
441
|
+
const receiveActivityEvent: NonPersistedActivityLoggingEvent = {
|
|
442
|
+
timestamp: new Date(),
|
|
443
|
+
level: LogLevel.DEBUG,
|
|
444
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
445
|
+
originalCredential: 'test_credential_string',
|
|
446
|
+
credentialHash: parentCredentialHash,
|
|
447
|
+
credentialType: CredentialType.SD_JWT,
|
|
448
|
+
system: System.GENERAL,
|
|
449
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
450
|
+
actionType: ActionType.EXECUTE,
|
|
451
|
+
actionSubType: 'Receive credential',
|
|
452
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
453
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
454
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
455
|
+
systemAlias: 'test_alias',
|
|
456
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
457
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
458
|
+
partyAlias: 'test_alias',
|
|
459
|
+
description: 'test_description',
|
|
460
|
+
data: 'test_data_string',
|
|
461
|
+
diagnosticData: { data: 'test_data_string' },
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const storedReceiveActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: receiveActivityEvent })
|
|
465
|
+
expect(storedReceiveActivityEvent).toBeDefined()
|
|
466
|
+
|
|
467
|
+
const args: GetActivityEventsArgs = {
|
|
468
|
+
filter: [
|
|
469
|
+
{
|
|
470
|
+
credentialHash: parentCredentialHash
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
parentCredentialHash
|
|
474
|
+
}
|
|
475
|
+
]
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const result: Array<ActivityLoggingEvent> = await eventLoggerStore.getActivityEvents(args)
|
|
479
|
+
expect(result.length).toEqual(3)
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
it('should get all activity events for a parent credential with a certain action', async (): Promise<void> => {
|
|
483
|
+
const parentCredentialHash = 'df7037831edbde7f0f65f723ef5494d6'
|
|
484
|
+
|
|
485
|
+
const parentActivityEvent: NonPersistedActivityLoggingEvent = {
|
|
486
|
+
timestamp: new Date(),
|
|
487
|
+
level: LogLevel.DEBUG,
|
|
488
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
489
|
+
originalCredential: 'test_credential_string',
|
|
490
|
+
credentialHash: parentCredentialHash,
|
|
491
|
+
credentialType: CredentialType.SD_JWT,
|
|
492
|
+
system: System.GENERAL,
|
|
493
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
494
|
+
actionType: ActionType.EXECUTE,
|
|
495
|
+
actionSubType: 'Share credential',
|
|
496
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
497
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
498
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
499
|
+
systemAlias: 'test_alias',
|
|
500
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
501
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
502
|
+
partyAlias: 'test_alias',
|
|
503
|
+
description: 'test_description',
|
|
504
|
+
data: 'test_data_string',
|
|
505
|
+
diagnosticData: { data: 'test_data_string' },
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const storedParentActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: parentActivityEvent })
|
|
509
|
+
expect(storedParentActivityEvent).toBeDefined()
|
|
510
|
+
|
|
511
|
+
const childActivityEvent: NonPersistedActivityLoggingEvent = {
|
|
512
|
+
timestamp: new Date(),
|
|
513
|
+
level: LogLevel.DEBUG,
|
|
514
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
515
|
+
originalCredential: 'test_credential_string',
|
|
516
|
+
credentialHash: '341a7897df58e472f9bf19b3b9abf7d5',
|
|
517
|
+
parentCredentialHash,
|
|
518
|
+
credentialType: CredentialType.SD_JWT,
|
|
519
|
+
system: System.GENERAL,
|
|
520
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
521
|
+
actionType: ActionType.EXECUTE,
|
|
522
|
+
actionSubType: 'Share credential',
|
|
523
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
524
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
525
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
526
|
+
systemAlias: 'test_alias',
|
|
527
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
528
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
529
|
+
partyAlias: 'test_alias',
|
|
530
|
+
description: 'test_description',
|
|
531
|
+
data: 'test_data_string',
|
|
532
|
+
diagnosticData: { data: 'test_data_string' },
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const storedChildActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: childActivityEvent })
|
|
536
|
+
expect(storedChildActivityEvent).toBeDefined()
|
|
537
|
+
|
|
538
|
+
const otherActivityEvent: NonPersistedActivityLoggingEvent = {
|
|
539
|
+
timestamp: new Date(),
|
|
540
|
+
level: LogLevel.DEBUG,
|
|
541
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
542
|
+
originalCredential: 'test_credential_string',
|
|
543
|
+
credentialHash: 'a8360b0b0b2eed8d185738536ff5b841',
|
|
544
|
+
credentialType: CredentialType.SD_JWT,
|
|
545
|
+
system: System.GENERAL,
|
|
546
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
547
|
+
actionType: ActionType.EXECUTE,
|
|
548
|
+
actionSubType: 'Share credential', // TODO
|
|
549
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
550
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
551
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
552
|
+
systemAlias: 'test_alias',
|
|
553
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
554
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
555
|
+
partyAlias: 'test_alias',
|
|
556
|
+
description: 'test_description',
|
|
557
|
+
data: 'test_data_string',
|
|
558
|
+
diagnosticData: { data: 'test_data_string' },
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const storedOtherActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: otherActivityEvent })
|
|
562
|
+
expect(storedOtherActivityEvent).toBeDefined()
|
|
563
|
+
|
|
564
|
+
const receiveActivityEvent: NonPersistedActivityLoggingEvent = {
|
|
565
|
+
timestamp: new Date(),
|
|
566
|
+
level: LogLevel.DEBUG,
|
|
567
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
568
|
+
originalCredential: 'test_credential_string',
|
|
569
|
+
credentialHash: parentCredentialHash,
|
|
570
|
+
credentialType: CredentialType.SD_JWT,
|
|
571
|
+
system: System.GENERAL,
|
|
572
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
573
|
+
actionType: ActionType.EXECUTE,
|
|
574
|
+
actionSubType: 'Receive credential',
|
|
575
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
576
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
577
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
578
|
+
systemAlias: 'test_alias',
|
|
579
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
580
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
581
|
+
partyAlias: 'test_alias',
|
|
582
|
+
description: 'test_description',
|
|
583
|
+
data: 'test_data_string',
|
|
584
|
+
diagnosticData: { data: 'test_data_string' },
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const storedReceiveActivityEvent: ActivityLoggingEvent = await eventLoggerStore.storeActivityEvent({ event: receiveActivityEvent })
|
|
588
|
+
expect(storedReceiveActivityEvent).toBeDefined()
|
|
589
|
+
|
|
590
|
+
const args: GetActivityEventsArgs = {
|
|
591
|
+
filter: [
|
|
592
|
+
{
|
|
593
|
+
credentialHash: parentCredentialHash,
|
|
594
|
+
actionSubType: 'Share credential'
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
parentCredentialHash,
|
|
598
|
+
actionSubType: 'Share credential'
|
|
599
|
+
}
|
|
600
|
+
]
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
const result: Array<ActivityLoggingEvent> = await eventLoggerStore.getActivityEvents(args)
|
|
604
|
+
expect(result.length).toEqual(2)
|
|
605
|
+
})
|
|
606
|
+
|
|
130
607
|
})
|
|
@@ -106,9 +106,7 @@ export class DigitalCredentialStore extends AbstractDigitalCredentialStore {
|
|
|
106
106
|
let affected: number = 0
|
|
107
107
|
const findResult = await dcRepo.findBy(query)
|
|
108
108
|
for (const dc of findResult) {
|
|
109
|
-
|
|
110
|
-
affected += await this.deleteTree(dcRepo, { id: dc.parentId })
|
|
111
|
-
}
|
|
109
|
+
affected += await this.deleteTree(dcRepo, { parentId: dc.id })
|
|
112
110
|
const result = await dcRepo.delete(dc.id)
|
|
113
111
|
if (result.affected) {
|
|
114
112
|
affected += result.affected
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ActionSubType, ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
|
|
1
|
+
import { ActionSubType, ActionType, InitiatorType, LoggingEventType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
|
|
2
2
|
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
|
|
3
|
-
import { PartyCorrelationType } from '@sphereon/ssi-sdk.core'
|
|
4
|
-
import { NonPersistedAuditLoggingEvent } from '../../types'
|
|
3
|
+
import { CredentialType, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
|
|
5
4
|
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
|
|
5
|
+
import { NonPersistedAuditLoggingEvent, NonPersistedActivityLoggingEvent } from '../../types'
|
|
6
6
|
|
|
7
|
+
//TODO this entity, also contains some optional fields that are related to another event type (Activity) later we might want to refactor and reorganize this.
|
|
8
|
+
// For now I've added a discriminator value called eventType that can be one of the three types of events: 1. General, 2. Audit, and 3. Activity
|
|
7
9
|
@Entity('AuditEvents')
|
|
8
10
|
export class AuditEventEntity extends BaseEntity {
|
|
9
11
|
@PrimaryGeneratedColumn('uuid')
|
|
@@ -12,6 +14,9 @@ export class AuditEventEntity extends BaseEntity {
|
|
|
12
14
|
@Column({ name: 'timestamp', nullable: false, unique: false, type: typeOrmDateTime() })
|
|
13
15
|
timestamp!: Date
|
|
14
16
|
|
|
17
|
+
@Column('simple-enum', { name: 'eventType', enum: LoggingEventType, nullable: false, unique: false })
|
|
18
|
+
type!: LoggingEventType
|
|
19
|
+
|
|
15
20
|
@Column('simple-enum', { name: 'level', enum: LogLevel, nullable: false, unique: false })
|
|
16
21
|
level!: LogLevel
|
|
17
22
|
|
|
@@ -54,6 +59,21 @@ export class AuditEventEntity extends BaseEntity {
|
|
|
54
59
|
@Column('text', { name: 'description', nullable: false, unique: false })
|
|
55
60
|
description!: string
|
|
56
61
|
|
|
62
|
+
@Column('simple-enum', { name: 'credentialType', enum: CredentialType, nullable: true, unique: false })
|
|
63
|
+
credentialType?: CredentialType
|
|
64
|
+
|
|
65
|
+
@Column('text', { name: 'credentialHash', nullable: true, unique: false })
|
|
66
|
+
credentialHash?: string
|
|
67
|
+
|
|
68
|
+
@Column('text', { name: 'parentCredentialHash', nullable: true, unique: false })
|
|
69
|
+
parentCredentialHash?: string
|
|
70
|
+
|
|
71
|
+
@Column('text', { name: 'originalCredential', nullable: true, unique: false })
|
|
72
|
+
originalCredential?: string
|
|
73
|
+
|
|
74
|
+
@Column('text', { name: 'sharePurpose', nullable: true, unique: false })
|
|
75
|
+
sharePurpose?: string
|
|
76
|
+
|
|
57
77
|
@Column('text', { name: 'data', nullable: true, unique: false })
|
|
58
78
|
data?: string
|
|
59
79
|
|
|
@@ -69,6 +89,7 @@ export class AuditEventEntity extends BaseEntity {
|
|
|
69
89
|
|
|
70
90
|
export const auditEventEntityFrom = (args: NonPersistedAuditLoggingEvent): AuditEventEntity => {
|
|
71
91
|
const auditEventEntity: AuditEventEntity = new AuditEventEntity()
|
|
92
|
+
auditEventEntity.type = LoggingEventType.AUDIT
|
|
72
93
|
auditEventEntity.timestamp = args.timestamp
|
|
73
94
|
auditEventEntity.level = args.level
|
|
74
95
|
auditEventEntity.correlationId = args.correlationId
|
|
@@ -90,3 +111,33 @@ export const auditEventEntityFrom = (args: NonPersistedAuditLoggingEvent): Audit
|
|
|
90
111
|
|
|
91
112
|
return auditEventEntity
|
|
92
113
|
}
|
|
114
|
+
|
|
115
|
+
export const activityEventEntityFrom = (args: NonPersistedActivityLoggingEvent): AuditEventEntity => {
|
|
116
|
+
const activityEventEntity: AuditEventEntity = new AuditEventEntity()
|
|
117
|
+
activityEventEntity.type = LoggingEventType.ACTIVITY
|
|
118
|
+
activityEventEntity.timestamp = args.timestamp
|
|
119
|
+
activityEventEntity.level = args.level
|
|
120
|
+
activityEventEntity.correlationId = args.correlationId
|
|
121
|
+
activityEventEntity.system = args.system
|
|
122
|
+
activityEventEntity.subSystemType = args.subSystemType
|
|
123
|
+
activityEventEntity.actionType = args.actionType
|
|
124
|
+
activityEventEntity.actionSubType = args.actionSubType
|
|
125
|
+
activityEventEntity.initiatorType = args.initiatorType
|
|
126
|
+
activityEventEntity.systemCorrelationIdType = args.systemCorrelationIdType
|
|
127
|
+
activityEventEntity.systemCorrelationId = args.systemCorrelationId
|
|
128
|
+
activityEventEntity.systemAlias = args.systemAlias
|
|
129
|
+
activityEventEntity.partyCorrelationType = args.partyCorrelationType
|
|
130
|
+
activityEventEntity.partyCorrelationId = args.partyCorrelationId
|
|
131
|
+
activityEventEntity.partyAlias = args.partyAlias
|
|
132
|
+
activityEventEntity.description = args.description
|
|
133
|
+
activityEventEntity.partyCorrelationType = args.partyCorrelationType
|
|
134
|
+
activityEventEntity.data = JSON.stringify(args.data)
|
|
135
|
+
activityEventEntity.sharePurpose = args.sharePurpose
|
|
136
|
+
activityEventEntity.credentialType = args.credentialType
|
|
137
|
+
activityEventEntity.originalCredential = args.originalCredential
|
|
138
|
+
activityEventEntity.credentialHash = args.credentialHash
|
|
139
|
+
activityEventEntity.parentCredentialHash = args.parentCredentialHash
|
|
140
|
+
activityEventEntity.diagnosticData = JSON.stringify(args.diagnosticData)
|
|
141
|
+
|
|
142
|
+
return activityEventEntity
|
|
143
|
+
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ActivityLoggingEvent, AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
2
|
+
import {
|
|
3
|
+
GetActivityEventsArgs,
|
|
4
|
+
GetAuditEventsArgs,
|
|
5
|
+
StoreActivityEventArgs,
|
|
6
|
+
StoreAuditEventArgs
|
|
7
|
+
} from '../types'
|
|
3
8
|
|
|
4
9
|
export abstract class AbstractEventLoggerStore {
|
|
5
10
|
abstract getAuditEvents(args: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>>
|
|
11
|
+
abstract getActivityEvents(args: GetActivityEventsArgs): Promise<Array<ActivityLoggingEvent>>
|
|
6
12
|
abstract storeAuditEvent(args: StoreAuditEventArgs): Promise<AuditLoggingEvent>
|
|
13
|
+
abstract storeActivityEvent(args: StoreActivityEventArgs): Promise<ActivityLoggingEvent>
|
|
7
14
|
}
|