@sphereon/ssi-sdk.data-store 0.30.1-unstable.4 → 0.30.1
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/LICENSE +201 -201
- package/README.md +77 -77
- package/dist/contact/ContactStore.d.ts.map +1 -1
- package/dist/digitalCredential/DigitalCredentialStore.d.ts.map +1 -1
- package/dist/eventLogger/EventLoggerStore.d.ts.map +1 -1
- package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts.map +1 -1
- package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js +33 -33
- package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.js +16 -16
- package/dist/migrations/postgres/1715761125001-CreateContacts.js +33 -33
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js +12 -12
- package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js +32 -32
- package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.js +15 -15
- package/dist/migrations/sqlite/1710438363002-CreateContacts.js +13 -13
- package/dist/migrations/sqlite/1715761125002-CreateContacts.js +32 -32
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js +9 -9
- package/dist/presentationDefinition/PDStore.d.ts.map +1 -1
- package/dist/utils/SortingUtils.d.ts.map +1 -1
- package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
- package/dist/utils/digitalCredential/MappingUtils.d.ts.map +1 -1
- package/dist/utils/digitalCredential/MappingUtils.js +4 -4
- package/dist/utils/digitalCredential/MappingUtils.js.map +1 -1
- package/dist/utils/presentationDefinition/MappingUtils.js +2 -2
- package/dist/utils/presentationDefinition/MappingUtils.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/contact.entities.test.ts +2642 -2642
- package/src/__tests__/contact.store.test.ts +2649 -2649
- package/src/__tests__/digitalCredential.entities.test.ts +274 -274
- package/src/__tests__/digitalCredential.store.test.ts +330 -330
- package/src/__tests__/eventLogger.entities.test.ts +76 -76
- package/src/__tests__/eventLogger.store.test.ts +130 -130
- package/src/__tests__/issuanceBranding.entities.test.ts +846 -846
- package/src/__tests__/issuanceBranding.store.test.ts +1886 -1886
- package/src/__tests__/machineState.entities.test.ts +53 -53
- package/src/__tests__/machineState.store.test.ts +176 -176
- package/src/__tests__/pd-manager.entities.test.ts +73 -73
- package/src/__tests__/pd-manager.store.test.ts +193 -193
- package/src/contact/AbstractContactStore.ts +71 -71
- package/src/contact/ContactStore.ts +768 -768
- package/src/digitalCredential/AbstractDigitalCredentialStore.ts +21 -21
- package/src/digitalCredential/DigitalCredentialStore.ts +189 -189
- package/src/entities/contact/BaseContactEntity.ts +51 -51
- package/src/entities/contact/ConnectionEntity.ts +35 -35
- package/src/entities/contact/ContactMetadataItemEntity.ts +51 -51
- package/src/entities/contact/CorrelationIdentifierEntity.ts +43 -43
- package/src/entities/contact/DidAuthConfigEntity.ts +20 -20
- package/src/entities/contact/ElectronicAddressEntity.ts +70 -70
- package/src/entities/contact/IdentityEntity.ts +107 -107
- package/src/entities/contact/IdentityMetadataItemEntity.ts +48 -48
- package/src/entities/contact/NaturalPersonEntity.ts +44 -44
- package/src/entities/contact/OpenIdConfigEntity.ts +32 -32
- package/src/entities/contact/OrganizationEntity.ts +35 -35
- package/src/entities/contact/PartyEntity.ts +117 -117
- package/src/entities/contact/PartyRelationshipEntity.ts +68 -68
- package/src/entities/contact/PartyTypeEntity.ts +63 -63
- package/src/entities/contact/PhysicalAddressEntity.ts +95 -95
- package/src/entities/digitalCredential/DigitalCredentialEntity.ts +98 -98
- package/src/entities/eventLogger/AuditEventEntity.ts +92 -92
- package/src/entities/issuanceBranding/BackgroundAttributesEntity.ts +42 -42
- package/src/entities/issuanceBranding/BaseLocaleBrandingEntity.ts +87 -87
- package/src/entities/issuanceBranding/CredentialBrandingEntity.ts +79 -79
- package/src/entities/issuanceBranding/CredentialLocaleBrandingEntity.ts +33 -33
- package/src/entities/issuanceBranding/ImageAttributesEntity.ts +57 -57
- package/src/entities/issuanceBranding/ImageDimensionsEntity.ts +22 -22
- package/src/entities/issuanceBranding/IssuerBrandingEntity.ts +73 -73
- package/src/entities/issuanceBranding/IssuerLocaleBrandingEntity.ts +33 -33
- package/src/entities/issuanceBranding/TextAttributesEntity.ts +31 -31
- package/src/entities/machineState/MachineStateInfoEntity.ts +59 -59
- package/src/entities/presentationDefinition/PresentationDefinitionItemEntity.ts +44 -44
- package/src/entities/statusList2021/StatusList2021Entity.ts +96 -96
- package/src/entities/statusList2021/StatusList2021EntryEntity.ts +29 -29
- package/src/eventLogger/AbstractEventLoggerStore.ts +7 -7
- package/src/eventLogger/EventLoggerStore.ts +62 -62
- package/src/index.ts +160 -160
- package/src/issuanceBranding/IssuanceBrandingStore.ts +559 -559
- package/src/machineState/IAbstractMachineStateStore.ts +65 -65
- package/src/machineState/MachineStateStore.ts +149 -149
- package/src/migrations/generic/1-CreateContacts.ts +66 -66
- package/src/migrations/generic/10-CreatePresentationDefinitions.ts +66 -66
- package/src/migrations/generic/2-CreateIssuanceBranding.ts +64 -64
- package/src/migrations/generic/3-CreateContacts.ts +66 -66
- package/src/migrations/generic/4-CreateStatusList.ts +54 -54
- package/src/migrations/generic/5-CreateAuditEvents.ts +66 -66
- package/src/migrations/generic/6-CreateDigitalCredential.ts +66 -66
- package/src/migrations/generic/7-CreateMachineStateStore.ts +66 -66
- package/src/migrations/generic/8-CreateContacts.ts +66 -66
- package/src/migrations/generic/9-CreateContacts.ts +66 -66
- package/src/migrations/generic/index.ts +43 -43
- package/src/migrations/index.ts +10 -10
- package/src/migrations/postgres/1659463079428-CreateContacts.ts +63 -63
- package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +85 -85
- package/src/migrations/postgres/1690925872592-CreateContacts.ts +158 -158
- package/src/migrations/postgres/1693866470001-CreateStatusList.ts +24 -24
- package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +33 -33
- package/src/migrations/postgres/1708525189001-CreateDigitalCredential.ts +61 -61
- package/src/migrations/postgres/1708797018115-CreateMachineStateStore.ts +29 -29
- package/src/migrations/postgres/1710438363001-CreateContacts.ts +63 -63
- package/src/migrations/postgres/1715761125001-CreateContacts.ts +60 -60
- package/src/migrations/postgres/1716475165345-CreatePresentationDefinitions.ts +25 -25
- package/src/migrations/sqlite/1659463069549-CreateContacts.ts +110 -110
- package/src/migrations/sqlite/1685628973231-CreateIssuanceBranding.ts +119 -119
- package/src/migrations/sqlite/1690925872693-CreateContacts.ts +228 -228
- package/src/migrations/sqlite/1693866470000-CreateStatusList.ts +24 -24
- package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +15 -15
- package/src/migrations/sqlite/1708525189002-CreateDigitalCredential.ts +46 -46
- package/src/migrations/sqlite/1708796002272-CreateMachineStateStore.ts +28 -28
- package/src/migrations/sqlite/1710438363002-CreateContacts.ts +83 -83
- package/src/migrations/sqlite/1715761125002-CreateContacts.ts +59 -59
- package/src/migrations/sqlite/1716475165344-CreatePresentationDefinitions.ts +24 -24
- package/src/presentationDefinition/AbstractPDStore.ts +20 -20
- package/src/presentationDefinition/PDStore.ts +185 -185
- package/src/statusList/IStatusListStore.ts +44 -44
- package/src/statusList/StatusListStore.ts +236 -236
- package/src/types/contact/IAbstractContactStore.ts +161 -161
- package/src/types/contact/contact.ts +295 -295
- package/src/types/digitalCredential/IAbstractDigitalCredentialStore.ts +42 -42
- package/src/types/digitalCredential/digitalCredential.ts +102 -102
- package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -12
- package/src/types/eventLogger/eventLogger.ts +3 -3
- package/src/types/index.ts +14 -14
- package/src/types/machineState/IAbstractMachineStateStore.ts +68 -68
- package/src/types/presentationDefinition/IAbstractPDStore.ts +25 -25
- package/src/types/presentationDefinition/presentationDefinition.ts +17 -17
- package/src/utils/SortingUtils.ts +16 -16
- package/src/utils/contact/MappingUtils.ts +506 -506
- package/src/utils/digitalCredential/MappingUtils.ts +160 -160
- package/src/utils/hasher.ts +19 -19
- package/src/utils/presentationDefinition/MappingUtils.ts +52 -52
- package/dist/entities/contact/IMetadataEntity.d.ts +0 -8
- package/dist/entities/contact/IMetadataEntity.d.ts.map +0 -1
- package/dist/entities/contact/IMetadataEntity.js +0 -2
- package/dist/entities/contact/IMetadataEntity.js.map +0 -1
- package/dist/migrations/generic/8-CreatePresentationDefinitions.d.ts +0 -7
- package/dist/migrations/generic/8-CreatePresentationDefinitions.d.ts.map +0 -1
- package/dist/migrations/generic/8-CreatePresentationDefinitions.js +0 -78
- package/dist/migrations/generic/8-CreatePresentationDefinitions.js.map +0 -1
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
-
import { PartyCorrelationType } from '@sphereon/ssi-sdk.core'
|
|
3
|
-
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
|
|
4
|
-
import { DataSource } from 'typeorm'
|
|
5
|
-
import { DataStoreEventLoggerEntities } from '../index'
|
|
6
|
-
import { DataStoreEventLoggerMigrations } from '../migrations/generic'
|
|
7
|
-
import { auditEventEntityFrom, AuditEventEntity } from '../entities/eventLogger/AuditEventEntity'
|
|
8
|
-
import { NonPersistedAuditLoggingEvent } from '../types'
|
|
9
|
-
|
|
10
|
-
describe('Database entities tests', (): void => {
|
|
11
|
-
let dbConnection: DataSource
|
|
12
|
-
|
|
13
|
-
beforeEach(async (): Promise<void> => {
|
|
14
|
-
DataSources.singleInstance().defaultDbType = 'sqlite'
|
|
15
|
-
dbConnection = await new DataSource({
|
|
16
|
-
type: 'sqlite',
|
|
17
|
-
database: ':memory:',
|
|
18
|
-
//logging: 'all',
|
|
19
|
-
migrationsRun: false,
|
|
20
|
-
migrations: DataStoreEventLoggerMigrations,
|
|
21
|
-
synchronize: false,
|
|
22
|
-
entities: [...DataStoreEventLoggerEntities],
|
|
23
|
-
}).initialize()
|
|
24
|
-
await dbConnection.runMigrations()
|
|
25
|
-
expect(await dbConnection.showMigrations()).toBeFalsy()
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
afterEach(async (): Promise<void> => {
|
|
29
|
-
await (await dbConnection).destroy()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should save audit event to database', async (): Promise<void> => {
|
|
33
|
-
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
34
|
-
timestamp: new Date(),
|
|
35
|
-
level: LogLevel.DEBUG,
|
|
36
|
-
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
37
|
-
system: System.GENERAL,
|
|
38
|
-
subSystemType: SubSystem.DID_PROVIDER,
|
|
39
|
-
actionType: ActionType.CREATE,
|
|
40
|
-
actionSubType: 'Key generation',
|
|
41
|
-
initiatorType: InitiatorType.EXTERNAL,
|
|
42
|
-
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
43
|
-
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
44
|
-
systemAlias: 'test_alias',
|
|
45
|
-
partyCorrelationType: PartyCorrelationType.DID,
|
|
46
|
-
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
47
|
-
partyAlias: 'test_alias',
|
|
48
|
-
description: 'test_description',
|
|
49
|
-
data: 'test_data_string',
|
|
50
|
-
diagnosticData: { data: 'test_data_string' },
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const auditEventEntity: AuditEventEntity = auditEventEntityFrom(auditEvent)
|
|
54
|
-
const fromDb: AuditEventEntity = await dbConnection.getRepository(AuditEventEntity).save(auditEventEntity)
|
|
55
|
-
|
|
56
|
-
expect(fromDb).toBeDefined()
|
|
57
|
-
expect(fromDb?.id).not.toBeNull()
|
|
58
|
-
expect(fromDb?.timestamp).toEqual(auditEvent.timestamp)
|
|
59
|
-
expect(fromDb?.level).toEqual(auditEvent.level)
|
|
60
|
-
expect(fromDb?.correlationId).toEqual(auditEvent.correlationId)
|
|
61
|
-
expect(fromDb?.system).toEqual(auditEvent.system)
|
|
62
|
-
expect(fromDb?.subSystemType).toEqual(auditEvent.subSystemType)
|
|
63
|
-
expect(fromDb?.actionType).toEqual(auditEvent.actionType)
|
|
64
|
-
expect(fromDb?.actionSubType).toEqual(auditEvent.actionSubType)
|
|
65
|
-
expect(fromDb?.initiatorType).toEqual(auditEvent.initiatorType)
|
|
66
|
-
expect(fromDb?.systemCorrelationIdType).toEqual(auditEvent.systemCorrelationIdType)
|
|
67
|
-
expect(fromDb?.systemCorrelationId).toEqual(auditEvent.systemCorrelationId)
|
|
68
|
-
expect(fromDb?.systemAlias).toEqual(auditEvent.systemAlias)
|
|
69
|
-
expect(fromDb?.partyCorrelationType).toEqual(auditEvent.partyCorrelationType)
|
|
70
|
-
expect(fromDb?.partyCorrelationId).toEqual(auditEvent.partyCorrelationId)
|
|
71
|
-
expect(fromDb?.partyAlias).toEqual(auditEvent.partyAlias)
|
|
72
|
-
expect(fromDb?.description).toEqual(auditEvent.description)
|
|
73
|
-
expect(fromDb?.data).toEqual(JSON.stringify(auditEvent.data))
|
|
74
|
-
expect(fromDb?.diagnosticData).toEqual(JSON.stringify(auditEvent.diagnosticData))
|
|
75
|
-
})
|
|
76
|
-
})
|
|
1
|
+
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
+
import { PartyCorrelationType } from '@sphereon/ssi-sdk.core'
|
|
3
|
+
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
|
|
4
|
+
import { DataSource } from 'typeorm'
|
|
5
|
+
import { DataStoreEventLoggerEntities } from '../index'
|
|
6
|
+
import { DataStoreEventLoggerMigrations } from '../migrations/generic'
|
|
7
|
+
import { auditEventEntityFrom, AuditEventEntity } from '../entities/eventLogger/AuditEventEntity'
|
|
8
|
+
import { NonPersistedAuditLoggingEvent } from '../types'
|
|
9
|
+
|
|
10
|
+
describe('Database entities tests', (): void => {
|
|
11
|
+
let dbConnection: DataSource
|
|
12
|
+
|
|
13
|
+
beforeEach(async (): Promise<void> => {
|
|
14
|
+
DataSources.singleInstance().defaultDbType = 'sqlite'
|
|
15
|
+
dbConnection = await new DataSource({
|
|
16
|
+
type: 'sqlite',
|
|
17
|
+
database: ':memory:',
|
|
18
|
+
//logging: 'all',
|
|
19
|
+
migrationsRun: false,
|
|
20
|
+
migrations: DataStoreEventLoggerMigrations,
|
|
21
|
+
synchronize: false,
|
|
22
|
+
entities: [...DataStoreEventLoggerEntities],
|
|
23
|
+
}).initialize()
|
|
24
|
+
await dbConnection.runMigrations()
|
|
25
|
+
expect(await dbConnection.showMigrations()).toBeFalsy()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
afterEach(async (): Promise<void> => {
|
|
29
|
+
await (await dbConnection).destroy()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('should save audit event to database', async (): Promise<void> => {
|
|
33
|
+
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
34
|
+
timestamp: new Date(),
|
|
35
|
+
level: LogLevel.DEBUG,
|
|
36
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
37
|
+
system: System.GENERAL,
|
|
38
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
39
|
+
actionType: ActionType.CREATE,
|
|
40
|
+
actionSubType: 'Key generation',
|
|
41
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
42
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
43
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
44
|
+
systemAlias: 'test_alias',
|
|
45
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
46
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
47
|
+
partyAlias: 'test_alias',
|
|
48
|
+
description: 'test_description',
|
|
49
|
+
data: 'test_data_string',
|
|
50
|
+
diagnosticData: { data: 'test_data_string' },
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const auditEventEntity: AuditEventEntity = auditEventEntityFrom(auditEvent)
|
|
54
|
+
const fromDb: AuditEventEntity = await dbConnection.getRepository(AuditEventEntity).save(auditEventEntity)
|
|
55
|
+
|
|
56
|
+
expect(fromDb).toBeDefined()
|
|
57
|
+
expect(fromDb?.id).not.toBeNull()
|
|
58
|
+
expect(fromDb?.timestamp).toEqual(auditEvent.timestamp)
|
|
59
|
+
expect(fromDb?.level).toEqual(auditEvent.level)
|
|
60
|
+
expect(fromDb?.correlationId).toEqual(auditEvent.correlationId)
|
|
61
|
+
expect(fromDb?.system).toEqual(auditEvent.system)
|
|
62
|
+
expect(fromDb?.subSystemType).toEqual(auditEvent.subSystemType)
|
|
63
|
+
expect(fromDb?.actionType).toEqual(auditEvent.actionType)
|
|
64
|
+
expect(fromDb?.actionSubType).toEqual(auditEvent.actionSubType)
|
|
65
|
+
expect(fromDb?.initiatorType).toEqual(auditEvent.initiatorType)
|
|
66
|
+
expect(fromDb?.systemCorrelationIdType).toEqual(auditEvent.systemCorrelationIdType)
|
|
67
|
+
expect(fromDb?.systemCorrelationId).toEqual(auditEvent.systemCorrelationId)
|
|
68
|
+
expect(fromDb?.systemAlias).toEqual(auditEvent.systemAlias)
|
|
69
|
+
expect(fromDb?.partyCorrelationType).toEqual(auditEvent.partyCorrelationType)
|
|
70
|
+
expect(fromDb?.partyCorrelationId).toEqual(auditEvent.partyCorrelationId)
|
|
71
|
+
expect(fromDb?.partyAlias).toEqual(auditEvent.partyAlias)
|
|
72
|
+
expect(fromDb?.description).toEqual(auditEvent.description)
|
|
73
|
+
expect(fromDb?.data).toEqual(JSON.stringify(auditEvent.data))
|
|
74
|
+
expect(fromDb?.diagnosticData).toEqual(JSON.stringify(auditEvent.diagnosticData))
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
-
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
|
|
3
|
-
import { DataSource } from 'typeorm'
|
|
4
|
-
import { DataStoreEventLoggerMigrations } from '../migrations'
|
|
5
|
-
import { DataStoreEventLoggerEntities } from '../index'
|
|
6
|
-
import { AuditLoggingEvent, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
|
|
7
|
-
import { EventLoggerStore } from '../eventLogger/EventLoggerStore'
|
|
8
|
-
import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '../types'
|
|
9
|
-
|
|
10
|
-
describe('Database entities tests', (): void => {
|
|
11
|
-
let dbConnection: DataSource
|
|
12
|
-
let eventLoggerStore: EventLoggerStore
|
|
13
|
-
|
|
14
|
-
beforeEach(async (): Promise<void> => {
|
|
15
|
-
DataSources.singleInstance().defaultDbType = 'sqlite'
|
|
16
|
-
dbConnection = await new DataSource({
|
|
17
|
-
type: 'sqlite',
|
|
18
|
-
database: ':memory:',
|
|
19
|
-
//logging: 'all',
|
|
20
|
-
migrationsRun: false,
|
|
21
|
-
migrations: DataStoreEventLoggerMigrations,
|
|
22
|
-
synchronize: false,
|
|
23
|
-
entities: DataStoreEventLoggerEntities,
|
|
24
|
-
}).initialize()
|
|
25
|
-
await dbConnection.runMigrations()
|
|
26
|
-
expect(await dbConnection.showMigrations()).toBeFalsy()
|
|
27
|
-
eventLoggerStore = new EventLoggerStore(dbConnection)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
afterEach(async (): Promise<void> => {
|
|
31
|
-
await (await dbConnection).destroy()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('should store audit event', async (): Promise<void> => {
|
|
35
|
-
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
36
|
-
timestamp: new Date(),
|
|
37
|
-
level: LogLevel.DEBUG,
|
|
38
|
-
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
39
|
-
system: System.GENERAL,
|
|
40
|
-
subSystemType: SubSystem.DID_PROVIDER,
|
|
41
|
-
actionType: ActionType.CREATE,
|
|
42
|
-
actionSubType: 'Key generation',
|
|
43
|
-
initiatorType: InitiatorType.EXTERNAL,
|
|
44
|
-
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
45
|
-
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
46
|
-
systemAlias: 'test_alias',
|
|
47
|
-
partyCorrelationType: PartyCorrelationType.DID,
|
|
48
|
-
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
49
|
-
partyAlias: 'test_alias',
|
|
50
|
-
description: 'test_description',
|
|
51
|
-
data: 'test_data_string',
|
|
52
|
-
diagnosticData: { data: 'test_data_string' },
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
56
|
-
expect(savedAuditEvent).toBeDefined()
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should get all audit events', async (): Promise<void> => {
|
|
60
|
-
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
61
|
-
timestamp: new Date(),
|
|
62
|
-
level: LogLevel.DEBUG,
|
|
63
|
-
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
64
|
-
system: System.GENERAL,
|
|
65
|
-
subSystemType: SubSystem.DID_PROVIDER,
|
|
66
|
-
actionType: ActionType.CREATE,
|
|
67
|
-
actionSubType: 'Key generation',
|
|
68
|
-
initiatorType: InitiatorType.EXTERNAL,
|
|
69
|
-
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
70
|
-
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
71
|
-
systemAlias: 'test_alias',
|
|
72
|
-
partyCorrelationType: PartyCorrelationType.DID,
|
|
73
|
-
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
74
|
-
partyAlias: 'test_alias',
|
|
75
|
-
description: 'test_description',
|
|
76
|
-
data: 'test_data_string',
|
|
77
|
-
diagnosticData: { data: 'test_data_string' },
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const auditEvent1: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
81
|
-
expect(auditEvent1).toBeDefined()
|
|
82
|
-
|
|
83
|
-
const auditEvent2: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
84
|
-
expect(auditEvent2).toBeDefined()
|
|
85
|
-
|
|
86
|
-
const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents()
|
|
87
|
-
expect(result.length).toEqual(2)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should get audit events by filter', async (): Promise<void> => {
|
|
91
|
-
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
92
|
-
timestamp: new Date(),
|
|
93
|
-
level: LogLevel.DEBUG,
|
|
94
|
-
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
95
|
-
system: System.GENERAL,
|
|
96
|
-
subSystemType: SubSystem.DID_PROVIDER,
|
|
97
|
-
actionType: ActionType.CREATE,
|
|
98
|
-
actionSubType: 'Key generation',
|
|
99
|
-
initiatorType: InitiatorType.EXTERNAL,
|
|
100
|
-
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
101
|
-
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
102
|
-
systemAlias: 'test_alias',
|
|
103
|
-
partyCorrelationType: PartyCorrelationType.DID,
|
|
104
|
-
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
105
|
-
partyAlias: 'test_alias',
|
|
106
|
-
description: 'test_description',
|
|
107
|
-
data: 'test_data_string',
|
|
108
|
-
diagnosticData: { data: 'test_data_string' },
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
112
|
-
expect(savedAuditEvent).toBeDefined()
|
|
113
|
-
|
|
114
|
-
const args: GetAuditEventsArgs = {
|
|
115
|
-
filter: [{ correlationId: auditEvent.correlationId }],
|
|
116
|
-
}
|
|
117
|
-
const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents(args)
|
|
118
|
-
|
|
119
|
-
expect(result.length).toEqual(1)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('should return no audit events if filter does not match', async (): Promise<void> => {
|
|
123
|
-
const args: GetAuditEventsArgs = {
|
|
124
|
-
filter: [{ correlationId: 'unknown_id' }],
|
|
125
|
-
}
|
|
126
|
-
const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents(args)
|
|
127
|
-
|
|
128
|
-
expect(result.length).toEqual(0)
|
|
129
|
-
})
|
|
130
|
-
})
|
|
1
|
+
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
+
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
|
|
3
|
+
import { DataSource } from 'typeorm'
|
|
4
|
+
import { DataStoreEventLoggerMigrations } from '../migrations'
|
|
5
|
+
import { DataStoreEventLoggerEntities } from '../index'
|
|
6
|
+
import { AuditLoggingEvent, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
|
|
7
|
+
import { EventLoggerStore } from '../eventLogger/EventLoggerStore'
|
|
8
|
+
import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '../types'
|
|
9
|
+
|
|
10
|
+
describe('Database entities tests', (): void => {
|
|
11
|
+
let dbConnection: DataSource
|
|
12
|
+
let eventLoggerStore: EventLoggerStore
|
|
13
|
+
|
|
14
|
+
beforeEach(async (): Promise<void> => {
|
|
15
|
+
DataSources.singleInstance().defaultDbType = 'sqlite'
|
|
16
|
+
dbConnection = await new DataSource({
|
|
17
|
+
type: 'sqlite',
|
|
18
|
+
database: ':memory:',
|
|
19
|
+
//logging: 'all',
|
|
20
|
+
migrationsRun: false,
|
|
21
|
+
migrations: DataStoreEventLoggerMigrations,
|
|
22
|
+
synchronize: false,
|
|
23
|
+
entities: DataStoreEventLoggerEntities,
|
|
24
|
+
}).initialize()
|
|
25
|
+
await dbConnection.runMigrations()
|
|
26
|
+
expect(await dbConnection.showMigrations()).toBeFalsy()
|
|
27
|
+
eventLoggerStore = new EventLoggerStore(dbConnection)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
afterEach(async (): Promise<void> => {
|
|
31
|
+
await (await dbConnection).destroy()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('should store audit event', async (): Promise<void> => {
|
|
35
|
+
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
36
|
+
timestamp: new Date(),
|
|
37
|
+
level: LogLevel.DEBUG,
|
|
38
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
39
|
+
system: System.GENERAL,
|
|
40
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
41
|
+
actionType: ActionType.CREATE,
|
|
42
|
+
actionSubType: 'Key generation',
|
|
43
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
44
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
45
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
46
|
+
systemAlias: 'test_alias',
|
|
47
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
48
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
49
|
+
partyAlias: 'test_alias',
|
|
50
|
+
description: 'test_description',
|
|
51
|
+
data: 'test_data_string',
|
|
52
|
+
diagnosticData: { data: 'test_data_string' },
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
56
|
+
expect(savedAuditEvent).toBeDefined()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('should get all audit events', async (): Promise<void> => {
|
|
60
|
+
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
61
|
+
timestamp: new Date(),
|
|
62
|
+
level: LogLevel.DEBUG,
|
|
63
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
64
|
+
system: System.GENERAL,
|
|
65
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
66
|
+
actionType: ActionType.CREATE,
|
|
67
|
+
actionSubType: 'Key generation',
|
|
68
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
69
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
70
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
71
|
+
systemAlias: 'test_alias',
|
|
72
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
73
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
74
|
+
partyAlias: 'test_alias',
|
|
75
|
+
description: 'test_description',
|
|
76
|
+
data: 'test_data_string',
|
|
77
|
+
diagnosticData: { data: 'test_data_string' },
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const auditEvent1: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
81
|
+
expect(auditEvent1).toBeDefined()
|
|
82
|
+
|
|
83
|
+
const auditEvent2: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
84
|
+
expect(auditEvent2).toBeDefined()
|
|
85
|
+
|
|
86
|
+
const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents()
|
|
87
|
+
expect(result.length).toEqual(2)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('should get audit events by filter', async (): Promise<void> => {
|
|
91
|
+
const auditEvent: NonPersistedAuditLoggingEvent = {
|
|
92
|
+
timestamp: new Date(),
|
|
93
|
+
level: LogLevel.DEBUG,
|
|
94
|
+
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
|
|
95
|
+
system: System.GENERAL,
|
|
96
|
+
subSystemType: SubSystem.DID_PROVIDER,
|
|
97
|
+
actionType: ActionType.CREATE,
|
|
98
|
+
actionSubType: 'Key generation',
|
|
99
|
+
initiatorType: InitiatorType.EXTERNAL,
|
|
100
|
+
systemCorrelationIdType: SystemCorrelationIdType.DID,
|
|
101
|
+
systemCorrelationId: 'did:example:123456789abcdefghi',
|
|
102
|
+
systemAlias: 'test_alias',
|
|
103
|
+
partyCorrelationType: PartyCorrelationType.DID,
|
|
104
|
+
partyCorrelationId: '75cfd84a-0f3b-4fb1-97a3-a1506c7ab850',
|
|
105
|
+
partyAlias: 'test_alias',
|
|
106
|
+
description: 'test_description',
|
|
107
|
+
data: 'test_data_string',
|
|
108
|
+
diagnosticData: { data: 'test_data_string' },
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const savedAuditEvent: AuditLoggingEvent = await eventLoggerStore.storeAuditEvent({ event: auditEvent })
|
|
112
|
+
expect(savedAuditEvent).toBeDefined()
|
|
113
|
+
|
|
114
|
+
const args: GetAuditEventsArgs = {
|
|
115
|
+
filter: [{ correlationId: auditEvent.correlationId }],
|
|
116
|
+
}
|
|
117
|
+
const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents(args)
|
|
118
|
+
|
|
119
|
+
expect(result.length).toEqual(1)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('should return no audit events if filter does not match', async (): Promise<void> => {
|
|
123
|
+
const args: GetAuditEventsArgs = {
|
|
124
|
+
filter: [{ correlationId: 'unknown_id' }],
|
|
125
|
+
}
|
|
126
|
+
const result: Array<AuditLoggingEvent> = await eventLoggerStore.getAuditEvents(args)
|
|
127
|
+
|
|
128
|
+
expect(result.length).toEqual(0)
|
|
129
|
+
})
|
|
130
|
+
})
|