@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,20 @@
|
|
|
1
|
+
import { ActivityLoggingEvent, AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
2
|
+
import { LoggingEventType, OrPromise } from '@sphereon/ssi-types'
|
|
1
3
|
import Debug, { Debugger } from 'debug'
|
|
2
4
|
import { DataSource } from 'typeorm'
|
|
3
|
-
import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
4
|
-
import { OrPromise } from '@sphereon/ssi-types'
|
|
5
5
|
import { AbstractEventLoggerStore } from './AbstractEventLoggerStore'
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import {
|
|
7
|
+
activityEventEntityFrom,
|
|
8
|
+
AuditEventEntity,
|
|
9
|
+
auditEventEntityFrom
|
|
10
|
+
} from '../entities/eventLogger/AuditEventEntity'
|
|
11
|
+
import { activityEventFrom, auditEventFrom } from '../utils/eventLogger/MappingUtils'
|
|
12
|
+
import {
|
|
13
|
+
GetActivityEventsArgs,
|
|
14
|
+
GetAuditEventsArgs,
|
|
15
|
+
StoreActivityEventArgs,
|
|
16
|
+
StoreAuditEventArgs
|
|
17
|
+
} from '../types'
|
|
9
18
|
|
|
10
19
|
const debug: Debugger = Debug('sphereon:ssi-sdk:event-store')
|
|
11
20
|
|
|
@@ -18,10 +27,17 @@ export class EventLoggerStore extends AbstractEventLoggerStore {
|
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
getAuditEvents = async (args?: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>> => {
|
|
21
|
-
const
|
|
30
|
+
const { filter = [] } = args ?? {}
|
|
31
|
+
|
|
32
|
+
const auditEventsFilter = filter.map((item) => ({ ...item, type: LoggingEventType.AUDIT }))
|
|
33
|
+
if (auditEventsFilter.length === 0) {
|
|
34
|
+
auditEventsFilter.push({ type: LoggingEventType.AUDIT })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const connection = await this.dbConnection
|
|
22
38
|
debug('Getting audit events', args)
|
|
23
|
-
const result
|
|
24
|
-
|
|
39
|
+
const result = await connection.getRepository(AuditEventEntity).find({
|
|
40
|
+
where: auditEventsFilter
|
|
25
41
|
})
|
|
26
42
|
|
|
27
43
|
return result.map((event: AuditEventEntity) => auditEventFrom(event))
|
|
@@ -30,11 +46,39 @@ export class EventLoggerStore extends AbstractEventLoggerStore {
|
|
|
30
46
|
storeAuditEvent = async (args: StoreAuditEventArgs): Promise<AuditLoggingEvent> => {
|
|
31
47
|
const { event } = args
|
|
32
48
|
|
|
33
|
-
const auditEventEntity
|
|
34
|
-
const connection
|
|
49
|
+
const auditEventEntity = auditEventEntityFrom(event)
|
|
50
|
+
const connection = await this.dbConnection
|
|
35
51
|
debug('Storing audit event', auditEventEntity)
|
|
36
|
-
const createdResult
|
|
52
|
+
const createdResult = await connection.getRepository(AuditEventEntity).save(auditEventEntity)
|
|
37
53
|
|
|
38
54
|
return auditEventFrom(createdResult)
|
|
39
55
|
}
|
|
56
|
+
|
|
57
|
+
getActivityEvents = async (args?: GetActivityEventsArgs): Promise<Array<ActivityLoggingEvent>> => {
|
|
58
|
+
const { filter = [] } = args ?? {}
|
|
59
|
+
|
|
60
|
+
const activityEventsFilter = filter.map((item) => ({ ...item, type: LoggingEventType.ACTIVITY }))
|
|
61
|
+
if (activityEventsFilter.length === 0) {
|
|
62
|
+
activityEventsFilter.push({ type: LoggingEventType.ACTIVITY })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const connection = await this.dbConnection
|
|
66
|
+
debug('Getting activity events', args)
|
|
67
|
+
const result = await connection.getRepository(AuditEventEntity).find({
|
|
68
|
+
where: activityEventsFilter
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return result.map((event: AuditEventEntity) => activityEventFrom(event))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
storeActivityEvent = async (args: StoreActivityEventArgs): Promise<ActivityLoggingEvent> => {
|
|
75
|
+
const { event } = args
|
|
76
|
+
|
|
77
|
+
const activityEventEntity = activityEventEntityFrom(event)
|
|
78
|
+
const connection = await this.dbConnection
|
|
79
|
+
debug('Storing activity event', activityEventEntity)
|
|
80
|
+
const createdResult = await connection.getRepository(AuditEventEntity).save(activityEventEntity)
|
|
81
|
+
|
|
82
|
+
return activityEventFrom(createdResult)
|
|
83
|
+
}
|
|
40
84
|
}
|
|
@@ -4,19 +4,47 @@ export class CreateAuditEvents1701634812183 implements MigrationInterface {
|
|
|
4
4
|
name = 'CreateAuditEvents1701634812183'
|
|
5
5
|
|
|
6
6
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
-
await queryRunner.query(`CREATE TYPE "public"."Level_enum" AS ENUM('0', '1', '2', '3')`)
|
|
7
|
+
await queryRunner.query(`CREATE TYPE "public"."Level_enum" AS ENUM('0', '1', '2', '3', '4')`)
|
|
8
8
|
await queryRunner.query(
|
|
9
|
-
`CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'credentials', 'web3', 'profile', 'contact')`,
|
|
9
|
+
`CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'oid4vp', 'siopv2', 'PE', 'credentials', 'web3', 'profile', 'contact')`,
|
|
10
10
|
)
|
|
11
11
|
await queryRunner.query(
|
|
12
|
-
`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')`,
|
|
12
|
+
`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', 'api')`,
|
|
13
13
|
)
|
|
14
14
|
await queryRunner.query(`CREATE TYPE "public"."Action_type_enum" AS ENUM('create', 'read', 'update', 'delete', 'execute')`)
|
|
15
15
|
await queryRunner.query(`CREATE TYPE "public"."Initiator_type_enum" AS ENUM('user', 'system', 'external')`)
|
|
16
|
-
await queryRunner.query(`CREATE TYPE "public"."System_correlation_id_type_enum" AS ENUM('did', 'email', 'hostname', 'phone', 'user')`)
|
|
17
|
-
await queryRunner.query(`CREATE TYPE "public"."Party_correlation_type_enum" AS ENUM('did', 'email', 'hostname', 'phone')`)
|
|
16
|
+
await queryRunner.query(`CREATE TYPE "public"."System_correlation_id_type_enum" AS ENUM('did', 'url', 'email', 'hostname', 'phone', 'user')`)
|
|
17
|
+
await queryRunner.query(`CREATE TYPE "public"."Party_correlation_type_enum" AS ENUM('did', 'url', 'email', 'hostname', 'phone')`)
|
|
18
|
+
await queryRunner.query(`CREATE TYPE "public"."Event_type_enum" AS ENUM('audit', 'activity', 'general')`)
|
|
19
|
+
await queryRunner.query(`CREATE TYPE "public"."Event_credential_type_enum" AS ENUM('JSON_LD', 'JWT', 'SD_JWT', 'MSO_MDOC')`)
|
|
18
20
|
await queryRunner.query(
|
|
19
|
-
`CREATE TABLE "AuditEvents" (
|
|
21
|
+
`CREATE TABLE "AuditEvents" (
|
|
22
|
+
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
|
|
23
|
+
"eventType" "public"."Event_type_enum" NOT NULL,
|
|
24
|
+
"timestamp" TIMESTAMP NOT NULL,
|
|
25
|
+
"level" "public"."Level_enum" NOT NULL,
|
|
26
|
+
"correlationId" TEXT NOT NULL,
|
|
27
|
+
"system" "public"."System_enum" NOT NULL,
|
|
28
|
+
"subSystemType" "public"."Subsystem_type_enum" NOT NULL,
|
|
29
|
+
"actionType" "public"."Action_type_enum" NOT NULL,
|
|
30
|
+
"actionSubType" TEXT NOT NULL,
|
|
31
|
+
"initiatorType" "public"."Initiator_type_enum" NOT NULL,
|
|
32
|
+
"systemCorrelationIdType" "public"."System_correlation_id_type_enum",
|
|
33
|
+
"systemCorrelationId" TEXT,
|
|
34
|
+
"systemAlias" TEXT,
|
|
35
|
+
"partyCorrelationType" "public"."Party_correlation_type_enum",
|
|
36
|
+
"partyCorrelationId" TEXT,
|
|
37
|
+
"partyAlias" TEXT,
|
|
38
|
+
"credentialType" "public"."Event_credential_type_enum",
|
|
39
|
+
"credentialHash" TEXT,
|
|
40
|
+
"originalCredential" TEXT,
|
|
41
|
+
"sharePurpose" TEXT,
|
|
42
|
+
"description" TEXT NOT NULL,
|
|
43
|
+
"data" TEXT,
|
|
44
|
+
"diagnosticData" TEXT,
|
|
45
|
+
"created_at" TIMESTAMP NOT NULL DEFAULT now(),
|
|
46
|
+
"last_updated_at" TIMESTAMP NOT NULL DEFAULT now(),
|
|
47
|
+
CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))`,
|
|
20
48
|
)
|
|
21
49
|
}
|
|
22
50
|
|
|
@@ -5,7 +5,33 @@ export class CreateAuditEvents1701634819487 implements MigrationInterface {
|
|
|
5
5
|
|
|
6
6
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
7
|
await queryRunner.query(
|
|
8
|
-
`CREATE TABLE "AuditEvents" (
|
|
8
|
+
`CREATE TABLE "AuditEvents" (
|
|
9
|
+
"id" varchar PRIMARY KEY NOT NULL,
|
|
10
|
+
"eventType" varchar CHECK( "eventType" IN ('audit','activity','general') ) NOT NULL,
|
|
11
|
+
"timestamp" datetime NOT NULL,
|
|
12
|
+
"level" varchar CHECK( "level" IN ('0','1','2','3','4') ) NOT NULL,
|
|
13
|
+
"correlationId" varchar NOT NULL,
|
|
14
|
+
"system" varchar CHECK( "system" IN ('general','kms','identity','oid4vci','oid4vp','siopv2','PE','credentials','web3','profile','contact') ) NOT NULL,
|
|
15
|
+
"subSystemType" varchar CHECK( "subSystemType" IN ('key','did_provider','did_resolver','oid4vp_op','oid4vci_client','siopv2_op','contact_manager','vc_issuer','vc_verifier','vc_persistence','transport','profile','api') ) NOT NULL,
|
|
16
|
+
"actionType" varchar CHECK( "actionType" IN ('create','read','update','delete','execute') ) NOT NULL,
|
|
17
|
+
"actionSubType" varchar NOT NULL,
|
|
18
|
+
"initiatorType" varchar CHECK( "initiatorType" IN ('user','system','external') ) NOT NULL,
|
|
19
|
+
"systemCorrelationIdType" varchar CHECK( "systemCorrelationIdType" IN ('did','url','email','hostname','phone','user') ),
|
|
20
|
+
"systemCorrelationId" varchar,
|
|
21
|
+
"systemAlias" varchar,
|
|
22
|
+
"partyCorrelationType" varchar CHECK( "partyCorrelationType" IN ('did','url','email','hostname','phone') ),
|
|
23
|
+
"partyCorrelationId" varchar,
|
|
24
|
+
"partyAlias" varchar,
|
|
25
|
+
"credentialType" varchar CHECK( "credentialType" IN ('JSON_LD','JWT','SD_JWT','MSO_MDOC') ),
|
|
26
|
+
"credentialHash" varchar,
|
|
27
|
+
"parentCredentialHash" varchar,
|
|
28
|
+
"originalCredential" varchar,
|
|
29
|
+
"sharePurpose" varchar,
|
|
30
|
+
"description" varchar NOT NULL,
|
|
31
|
+
"data" varchar,
|
|
32
|
+
"diagnosticData" varchar,
|
|
33
|
+
"created_at" datetime NOT NULL DEFAULT (datetime('now')),
|
|
34
|
+
"last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`,
|
|
9
35
|
)
|
|
10
36
|
}
|
|
11
37
|
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import { PartialAuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
2
|
-
import { NonPersistedAuditLoggingEvent } from './eventLogger'
|
|
1
|
+
import { PartialActivityLoggingEvent, PartialAuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
2
|
+
import { NonPersistedActivityLoggingEvent, NonPersistedAuditLoggingEvent } from './eventLogger'
|
|
3
3
|
|
|
4
4
|
export type FindAuditLoggingEventArgs = Array<PartialAuditLoggingEvent>
|
|
5
5
|
|
|
6
|
+
export type FindActivityLoggingEventArgs = Array<PartialActivityLoggingEvent>
|
|
7
|
+
|
|
6
8
|
export type StoreAuditEventArgs = {
|
|
7
9
|
event: NonPersistedAuditLoggingEvent
|
|
8
10
|
}
|
|
9
11
|
|
|
12
|
+
export type StoreActivityEventArgs = {
|
|
13
|
+
event: NonPersistedActivityLoggingEvent
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
export type GetAuditEventsArgs = {
|
|
11
17
|
filter?: FindAuditLoggingEventArgs
|
|
12
18
|
}
|
|
19
|
+
|
|
20
|
+
export type GetActivityEventsArgs = {
|
|
21
|
+
filter?: FindActivityLoggingEventArgs
|
|
22
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
1
|
+
import { ActivityLoggingEvent, AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
2
2
|
|
|
3
|
-
export type NonPersistedAuditLoggingEvent = Omit<AuditLoggingEvent, 'id'>
|
|
3
|
+
export type NonPersistedAuditLoggingEvent = Omit<AuditLoggingEvent, 'id' | 'type'>
|
|
4
|
+
export type NonPersistedActivityLoggingEvent = Omit<ActivityLoggingEvent, 'id' | 'type'>
|
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
import { AuditEventEntity } from '../../entities/eventLogger/AuditEventEntity'
|
|
2
|
-
import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
2
|
+
import { ActivityLoggingEvent, AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
|
|
3
|
+
import { LoggingEventType } from '@sphereon/ssi-types'
|
|
3
4
|
import { replaceNullWithUndefined } from '../FormattingUtils'
|
|
4
5
|
|
|
5
6
|
export const auditEventFrom = (event: AuditEventEntity): AuditLoggingEvent => {
|
|
6
7
|
const result: AuditLoggingEvent = {
|
|
7
8
|
id: event.id,
|
|
9
|
+
type: LoggingEventType.AUDIT,
|
|
10
|
+
description: event.description,
|
|
11
|
+
timestamp: event.timestamp,
|
|
12
|
+
level: event.level,
|
|
13
|
+
correlationId: event.correlationId,
|
|
14
|
+
actionType: event.actionType,
|
|
15
|
+
actionSubType: event.actionSubType,
|
|
16
|
+
initiatorType: event.initiatorType,
|
|
17
|
+
partyAlias: event.partyAlias,
|
|
18
|
+
partyCorrelationId: event.partyCorrelationId,
|
|
19
|
+
partyCorrelationType: event.partyCorrelationType,
|
|
20
|
+
subSystemType: event.subSystemType,
|
|
21
|
+
system: event.system,
|
|
22
|
+
systemAlias: event.systemAlias,
|
|
23
|
+
systemCorrelationId: event.systemCorrelationId,
|
|
24
|
+
systemCorrelationIdType: event.systemCorrelationIdType,
|
|
25
|
+
...(event.data && { data: JSON.parse(event.data) }),
|
|
26
|
+
...(event.diagnosticData && { diagnosticData: JSON.parse(event.diagnosticData) }),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return replaceNullWithUndefined(result)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const activityEventFrom = (event: AuditEventEntity): ActivityLoggingEvent => {
|
|
33
|
+
|
|
34
|
+
const result: ActivityLoggingEvent = {
|
|
35
|
+
id: event.id,
|
|
36
|
+
type: LoggingEventType.ACTIVITY,
|
|
37
|
+
credentialType: event.credentialType!,
|
|
38
|
+
originalCredential: event.originalCredential,
|
|
39
|
+
credentialHash: event.credentialHash,
|
|
40
|
+
sharePurpose: event.sharePurpose,
|
|
8
41
|
description: event.description,
|
|
9
42
|
timestamp: event.timestamp,
|
|
10
43
|
level: event.level,
|