Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/SPRIND-77 #254

Merged
merged 9 commits into from
Nov 4, 2024
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ test/*.js
/packages/xstate-persistence/plugin.schema.json
/packages/credential-store/plugin.schema.json
/packages/pd-manager/plugin.schema.json
/packages/event-logger/plugin.schema.json
/packages/credential-validation/plugin.schema.json

**/.env.energyshr
**/.env.local
/packages/web3-provider-headless/__tests__/config.json
/packages/event-logger/plugin.schema.json

/packages/public-key-hosting/__tests__/database/test.sqlite
/__tests__/database/test.sqlite

.nx/cache
.nx/workspace-data
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { DataSource } from 'typeorm'
import { CredentialRole, DataStoreDigitalCredentialEntities } from '../index'
import { DataStoreDigitalCredentialMigrations } from '../migrations'
import { DigitalCredentialEntity } from '../entities/digitalCredential/DigitalCredentialEntity'
import { computeEntryHash } from '@veramo/utils'
import { nonPersistedDigitalCredentialEntityFromAddArgs } from '../utils/digitalCredential/MappingUtils'
import { createHash } from 'crypto'
import {
AddCredentialArgs,
CredentialCorrelationType,
CredentialDocumentFormat,
DocumentType,
NonPersistedDigitalCredential,
} from '../types/digitalCredential/digitalCredential'
import { computeEntryHash } from '@veramo/utils'
import { AddCredentialArgs } from '../types/digitalCredential/IAbstractDigitalCredentialStore'
import { nonPersistedDigitalCredentialEntityFromAddArgs } from '../utils/digitalCredential/MappingUtils'
import { createHash } from 'crypto'
} from '../types'

describe('Database entities tests', (): void => {
let dbConnection: DataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
DocumentType,
DigitalCredential,
GetCredentialsArgs,
GetCredentialsResponse,
GetCredentialsResponse
} from '../types'

describe('Database entities tests', (): void => {
Expand Down
48 changes: 24 additions & 24 deletions packages/data-store/src/__tests__/eventLogger.entities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { ActionType, InitiatorType, LoggingEventType, LogLevel, SubSystem, Syste
import { DataSource } from 'typeorm'
import { DataStoreEventLoggerEntities } from '../index'
import { DataStoreEventLoggerMigrations } from '../migrations'
import {
activityEventEntityFrom,
auditEventEntityFrom,
AuditEventEntity
} from '../entities/eventLogger/AuditEventEntity'
import { AuditEventEntity } from '../entities/eventLogger/AuditEventEntity'
import { NonPersistedAuditLoggingEvent, NonPersistedActivityLoggingEvent } from '../types'
import { activityEventEntityFrom, auditEventEntityFrom } from '../utils/eventLogger/MappingUtils'

describe('Database entities tests', (): void => {
let dbConnection: DataSource
Expand Down Expand Up @@ -80,7 +77,7 @@ describe('Database entities tests', (): void => {
})

it('should save activity event to database', async (): Promise<void> => {
const auditEvent: NonPersistedActivityLoggingEvent = {
const activityEvent: NonPersistedActivityLoggingEvent = {
timestamp: new Date(),
level: LogLevel.DEBUG,
originalCredential: 'test_credential_string',
Expand All @@ -104,28 +101,31 @@ describe('Database entities tests', (): void => {
diagnosticData: { data: 'test_data_string' },
}

const activityEventEntity: AuditEventEntity = activityEventEntityFrom(auditEvent)
const activityEventEntity: AuditEventEntity = activityEventEntityFrom(activityEvent)
const fromDb: AuditEventEntity = await dbConnection.getRepository(AuditEventEntity).save(activityEventEntity)

expect(fromDb).toBeDefined()
expect(fromDb?.id).not.toBeNull()
expect(fromDb?.type).toEqual(LoggingEventType.ACTIVITY)
expect(fromDb?.timestamp).toEqual(auditEvent.timestamp)
expect(fromDb?.level).toEqual(auditEvent.level)
expect(fromDb?.correlationId).toEqual(auditEvent.correlationId)
expect(fromDb?.system).toEqual(auditEvent.system)
expect(fromDb?.subSystemType).toEqual(auditEvent.subSystemType)
expect(fromDb?.actionType).toEqual(auditEvent.actionType)
expect(fromDb?.actionSubType).toEqual(auditEvent.actionSubType)
expect(fromDb?.initiatorType).toEqual(auditEvent.initiatorType)
expect(fromDb?.systemCorrelationIdType).toEqual(auditEvent.systemCorrelationIdType)
expect(fromDb?.systemCorrelationId).toEqual(auditEvent.systemCorrelationId)
expect(fromDb?.systemAlias).toEqual(auditEvent.systemAlias)
expect(fromDb?.partyCorrelationType).toEqual(auditEvent.partyCorrelationType)
expect(fromDb?.partyCorrelationId).toEqual(auditEvent.partyCorrelationId)
expect(fromDb?.partyAlias).toEqual(auditEvent.partyAlias)
expect(fromDb?.description).toEqual(auditEvent.description)
expect(fromDb?.data).toEqual(JSON.stringify(auditEvent.data))
expect(fromDb?.diagnosticData).toEqual(JSON.stringify(auditEvent.diagnosticData))
expect(fromDb?.timestamp).toEqual(activityEvent.timestamp)
expect(fromDb?.level).toEqual(activityEvent.level)
expect(fromDb?.correlationId).toEqual(activityEvent.correlationId)
expect(fromDb?.system).toEqual(activityEvent.system)
expect(fromDb?.subSystemType).toEqual(activityEvent.subSystemType)
expect(fromDb?.actionType).toEqual(activityEvent.actionType)
expect(fromDb?.actionSubType).toEqual(activityEvent.actionSubType)
expect(fromDb?.initiatorType).toEqual(activityEvent.initiatorType)
expect(fromDb?.systemCorrelationIdType).toEqual(activityEvent.systemCorrelationIdType)
expect(fromDb?.systemCorrelationId).toEqual(activityEvent.systemCorrelationId)
expect(fromDb?.systemAlias).toEqual(activityEvent.systemAlias)
expect(fromDb?.partyCorrelationType).toEqual(activityEvent.partyCorrelationType)
expect(fromDb?.partyCorrelationId).toEqual(activityEvent.partyCorrelationId)
expect(fromDb?.partyAlias).toEqual(activityEvent.partyAlias)
expect(fromDb?.description).toEqual(activityEvent.description)
expect(fromDb?.data).toEqual(JSON.stringify(activityEvent.data))
expect(fromDb?.diagnosticData).toEqual(JSON.stringify(activityEvent.diagnosticData))
expect(fromDb?.credentialHash).toEqual(activityEvent.credentialHash)
expect(fromDb?.parentCredentialHash).toEqual(activityEvent.parentCredentialHash)
expect(fromDb?.credentialType).toEqual(activityEvent.credentialType)
})
})

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { typeormDate, typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
import {
CredentialCorrelationType,
Expand All @@ -8,7 +9,6 @@ import {
DocumentType,
RegulationType,
} from '../../types'
import { typeormDate, typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'

@Entity('DigitalCredential')
export class DigitalCredentialEntity extends BaseEntity implements DigitalCredential {
Expand Down
58 changes: 1 addition & 57 deletions packages/data-store/src/entities/eventLogger/AuditEventEntity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ActionSubType, ActionType, InitiatorType, LoggingEventType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
import { CredentialType, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { NonPersistedAuditLoggingEvent, NonPersistedActivityLoggingEvent } from '../../types'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'

//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.
// 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
Expand Down Expand Up @@ -86,58 +85,3 @@ export class AuditEventEntity extends BaseEntity {
@UpdateDateColumn({ name: 'last_updated_at', nullable: false, type: typeOrmDateTime() })
lastUpdatedAt!: Date
}

export const auditEventEntityFrom = (args: NonPersistedAuditLoggingEvent): AuditEventEntity => {
const auditEventEntity: AuditEventEntity = new AuditEventEntity()
auditEventEntity.type = LoggingEventType.AUDIT
auditEventEntity.timestamp = args.timestamp
auditEventEntity.level = args.level
auditEventEntity.correlationId = args.correlationId
auditEventEntity.system = args.system
auditEventEntity.subSystemType = args.subSystemType
auditEventEntity.actionType = args.actionType
auditEventEntity.actionSubType = args.actionSubType
auditEventEntity.initiatorType = args.initiatorType
auditEventEntity.systemCorrelationIdType = args.systemCorrelationIdType
auditEventEntity.systemCorrelationId = args.systemCorrelationId
auditEventEntity.systemAlias = args.systemAlias
auditEventEntity.partyCorrelationType = args.partyCorrelationType
auditEventEntity.partyCorrelationId = args.partyCorrelationId
auditEventEntity.partyAlias = args.partyAlias
auditEventEntity.description = args.description
auditEventEntity.partyCorrelationType = args.partyCorrelationType
auditEventEntity.data = JSON.stringify(args.data)
auditEventEntity.diagnosticData = JSON.stringify(args.diagnosticData)

return auditEventEntity
}

export const activityEventEntityFrom = (args: NonPersistedActivityLoggingEvent): AuditEventEntity => {
const activityEventEntity: AuditEventEntity = new AuditEventEntity()
activityEventEntity.type = LoggingEventType.ACTIVITY
activityEventEntity.timestamp = args.timestamp
activityEventEntity.level = args.level
activityEventEntity.correlationId = args.correlationId
activityEventEntity.system = args.system
activityEventEntity.subSystemType = args.subSystemType
activityEventEntity.actionType = args.actionType
activityEventEntity.actionSubType = args.actionSubType
activityEventEntity.initiatorType = args.initiatorType
activityEventEntity.systemCorrelationIdType = args.systemCorrelationIdType
activityEventEntity.systemCorrelationId = args.systemCorrelationId
activityEventEntity.systemAlias = args.systemAlias
activityEventEntity.partyCorrelationType = args.partyCorrelationType
activityEventEntity.partyCorrelationId = args.partyCorrelationId
activityEventEntity.partyAlias = args.partyAlias
activityEventEntity.description = args.description
activityEventEntity.partyCorrelationType = args.partyCorrelationType
activityEventEntity.data = JSON.stringify(args.data)
activityEventEntity.sharePurpose = args.sharePurpose
activityEventEntity.credentialType = args.credentialType
activityEventEntity.originalCredential = args.originalCredential
activityEventEntity.credentialHash = args.credentialHash
activityEventEntity.parentCredentialHash = args.parentCredentialHash
activityEventEntity.diagnosticData = JSON.stringify(args.diagnosticData)

return activityEventEntity
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BaseEntity, BeforeInsert, BeforeUpdate, Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm'
import { IBasicBackgroundAttributes } from '../../types'
import { ImageAttributesEntity, imageAttributesEntityFrom } from './ImageAttributesEntity'
import { ImageAttributesEntity } from './ImageAttributesEntity'
import { validate, Validate, ValidationError } from 'class-validator'
import { isEmptyString, IsNonEmptyStringConstraint } from '../validators'
import { IsNonEmptyStringConstraint } from '../validators'

@Entity('BackgroundAttributes')
export class BackgroundAttributesEntity extends BaseEntity {
Expand Down Expand Up @@ -32,11 +31,3 @@ export class BackgroundAttributesEntity extends BaseEntity {
return
}
}

export const backgroundAttributesEntityFrom = (args: IBasicBackgroundAttributes): BackgroundAttributesEntity => {
const backgroundAttributesEntity: BackgroundAttributesEntity = new BackgroundAttributesEntity()
backgroundAttributesEntity.color = isEmptyString(args.color) ? undefined : args.color
backgroundAttributesEntity.image = args.image ? imageAttributesEntityFrom(args.image) : undefined

return backgroundAttributesEntity
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
} from 'typeorm'
import { ArrayMinSize, IsNotEmpty, validate, ValidationError } from 'class-validator'
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { CredentialLocaleBrandingEntity, credentialLocaleBrandingEntityFrom } from './CredentialLocaleBrandingEntity'
import { IBasicCredentialBranding, IBasicCredentialLocaleBranding } from '../../types'
import { CredentialLocaleBrandingEntity } from './CredentialLocaleBrandingEntity'

@Entity('CredentialBranding')
@Index('IDX_CredentialBrandingEntity_vcHash', ['vcHash'])
Expand Down Expand Up @@ -66,14 +65,3 @@ export class CredentialBrandingEntity extends BaseEntity {
return
}
}

export const credentialBrandingEntityFrom = (args: IBasicCredentialBranding): CredentialBrandingEntity => {
const credentialBrandingEntity: CredentialBrandingEntity = new CredentialBrandingEntity()
credentialBrandingEntity.issuerCorrelationId = args.issuerCorrelationId
credentialBrandingEntity.vcHash = args.vcHash
credentialBrandingEntity.localeBranding = args.localeBranding.map((localeBranding: IBasicCredentialLocaleBranding) =>
credentialLocaleBrandingEntityFrom(localeBranding),
)

return credentialBrandingEntity
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { ChildEntity, Column, JoinColumn, ManyToOne, Index } from 'typeorm'
import { IBasicCredentialLocaleBranding } from '../../types'
import { backgroundAttributesEntityFrom } from './BackgroundAttributesEntity'
import { CredentialBrandingEntity } from './CredentialBrandingEntity'
import { imageAttributesEntityFrom } from './ImageAttributesEntity'
import { BaseLocaleBrandingEntity } from './BaseLocaleBrandingEntity'
import { textAttributesEntityFrom } from './TextAttributesEntity'
import { isEmptyString } from '../validators'

@ChildEntity('CredentialLocaleBranding')
@Index('IDX_CredentialLocaleBrandingEntity_credentialBranding_locale', ['credentialBranding', 'locale'], { unique: true })
Expand All @@ -19,15 +14,3 @@ export class CredentialLocaleBrandingEntity extends BaseLocaleBrandingEntity {
@Column('text', { name: 'credentialBrandingId', nullable: false })
credentialBrandingId!: string
}

export const credentialLocaleBrandingEntityFrom = (args: IBasicCredentialLocaleBranding): CredentialLocaleBrandingEntity => {
const credentialLocaleBrandingEntity: CredentialLocaleBrandingEntity = new CredentialLocaleBrandingEntity()
credentialLocaleBrandingEntity.alias = isEmptyString(args.alias) ? undefined : args.alias
credentialLocaleBrandingEntity.locale = args.locale ? args.locale : ''
credentialLocaleBrandingEntity.logo = args.logo ? imageAttributesEntityFrom(args.logo) : undefined
credentialLocaleBrandingEntity.description = isEmptyString(args.description) ? undefined : args.description
credentialLocaleBrandingEntity.background = args.background ? backgroundAttributesEntityFrom(args.background) : undefined
credentialLocaleBrandingEntity.text = args.text ? textAttributesEntityFrom(args.text) : undefined

return credentialLocaleBrandingEntity
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BaseEntity, BeforeInsert, BeforeUpdate, Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm'
import { IBasicImageAttributes } from '../../types'
import { ImageDimensionsEntity, imageDimensionsEntityFrom } from './ImageDimensionsEntity'
import { ImageDimensionsEntity } from './ImageDimensionsEntity'
import { validate, Validate, ValidationError } from 'class-validator'
import { isEmptyString, IsNonEmptyStringConstraint } from '../validators'
import { IsNonEmptyStringConstraint } from '../validators'

@Entity('ImageAttributes')
export class ImageAttributesEntity extends BaseEntity {
Expand Down Expand Up @@ -44,14 +43,3 @@ export class ImageAttributesEntity extends BaseEntity {
return
}
}

export const imageAttributesEntityFrom = (args: IBasicImageAttributes): ImageAttributesEntity => {
const imageAttributesEntity: ImageAttributesEntity = new ImageAttributesEntity()
imageAttributesEntity.uri = isEmptyString(args.uri) ? undefined : args.uri
imageAttributesEntity.dataUri = isEmptyString(args.dataUri) ? undefined : args.dataUri
imageAttributesEntity.mediaType = isEmptyString(args.mediaType) ? undefined : args.mediaType
imageAttributesEntity.alt = isEmptyString(args.alt) ? undefined : args.alt
imageAttributesEntity.dimensions = args.dimensions ? imageDimensionsEntityFrom(args.dimensions) : undefined

return imageAttributesEntity
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm'
import { IBasicImageDimensions } from '../../types'

@Entity('ImageDimensions')
export class ImageDimensionsEntity extends BaseEntity {
Expand All @@ -12,11 +11,3 @@ export class ImageDimensionsEntity extends BaseEntity {
@Column('integer', { name: 'height', nullable: false, unique: false })
height!: number
}

export const imageDimensionsEntityFrom = (args: IBasicImageDimensions): ImageDimensionsEntity => {
const imageDimensionsEntity: ImageDimensionsEntity = new ImageDimensionsEntity()
imageDimensionsEntity.width = args.width
imageDimensionsEntity.height = args.height

return imageDimensionsEntity
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
} from 'typeorm'
import { ArrayMinSize, IsNotEmpty, validate, ValidationError } from 'class-validator'
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { IssuerLocaleBrandingEntity, issuerLocaleBrandingEntityFrom } from './IssuerLocaleBrandingEntity'
import { IBasicIssuerBranding, IBasicIssuerLocaleBranding } from '../../types'
import { IssuerLocaleBrandingEntity } from './IssuerLocaleBrandingEntity'

@Entity('IssuerBranding')
@Index('IDX_IssuerBrandingEntity_issuerCorrelationId', ['issuerCorrelationId'])
Expand Down Expand Up @@ -61,13 +60,3 @@ export class IssuerBrandingEntity extends BaseEntity {
return
}
}

export const issuerBrandingEntityFrom = (args: IBasicIssuerBranding): IssuerBrandingEntity => {
const issuerBrandingEntity: IssuerBrandingEntity = new IssuerBrandingEntity()
issuerBrandingEntity.issuerCorrelationId = args.issuerCorrelationId
issuerBrandingEntity.localeBranding = args.localeBranding.map((localeBranding: IBasicIssuerLocaleBranding) =>
issuerLocaleBrandingEntityFrom(localeBranding),
)

return issuerBrandingEntity
}
Loading