@sphereon/ssi-sdk.data-store 0.30.2-feature.siop.fixes.41 → 0.30.2-fix.138

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/contact/ContactStore.d.ts.map +1 -1
  2. package/dist/digitalCredential/DigitalCredentialStore.d.ts.map +1 -1
  3. package/dist/digitalCredential/DigitalCredentialStore.js +1 -3
  4. package/dist/digitalCredential/DigitalCredentialStore.js.map +1 -1
  5. package/dist/entities/eventLogger/AuditEventEntity.d.ts +10 -3
  6. package/dist/entities/eventLogger/AuditEventEntity.d.ts.map +1 -1
  7. package/dist/entities/eventLogger/AuditEventEntity.js +57 -1
  8. package/dist/entities/eventLogger/AuditEventEntity.js.map +1 -1
  9. package/dist/eventLogger/AbstractEventLoggerStore.d.ts +4 -2
  10. package/dist/eventLogger/AbstractEventLoggerStore.d.ts.map +1 -1
  11. package/dist/eventLogger/AbstractEventLoggerStore.js.map +1 -1
  12. package/dist/eventLogger/EventLoggerStore.d.ts +5 -4
  13. package/dist/eventLogger/EventLoggerStore.d.ts.map +1 -1
  14. package/dist/eventLogger/EventLoggerStore.js +34 -7
  15. package/dist/eventLogger/EventLoggerStore.js.map +1 -1
  16. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts +0 -4
  17. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -1
  18. package/dist/issuanceBranding/IssuanceBrandingStore.js +13 -42
  19. package/dist/issuanceBranding/IssuanceBrandingStore.js.map +1 -1
  20. package/dist/migrations/internal-migrations-ormconfig.d.ts.map +1 -1
  21. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.d.ts.map +1 -1
  22. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js +34 -6
  23. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js.map +1 -1
  24. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.d.ts.map +1 -1
  25. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js +27 -1
  26. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js.map +1 -1
  27. package/dist/presentationDefinition/PDStore.d.ts.map +1 -1
  28. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts +9 -2
  29. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts.map +1 -1
  30. package/dist/types/eventLogger/eventLogger.d.ts +3 -2
  31. package/dist/types/eventLogger/eventLogger.d.ts.map +1 -1
  32. package/dist/utils/FormattingUtils.d.ts +2 -0
  33. package/dist/utils/FormattingUtils.d.ts.map +1 -0
  34. package/dist/utils/FormattingUtils.js +23 -0
  35. package/dist/utils/FormattingUtils.js.map +1 -0
  36. package/dist/utils/SortingUtils.d.ts.map +1 -1
  37. package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
  38. package/dist/utils/contact/MappingUtils.js +27 -14
  39. package/dist/utils/contact/MappingUtils.js.map +1 -1
  40. package/dist/utils/digitalCredential/MappingUtils.d.ts.map +1 -1
  41. package/dist/utils/digitalCredential/MappingUtils.js +7 -5
  42. package/dist/utils/digitalCredential/MappingUtils.js.map +1 -1
  43. package/dist/utils/eventLogger/MappingUtils.d.ts +5 -0
  44. package/dist/utils/eventLogger/MappingUtils.d.ts.map +1 -0
  45. package/dist/utils/eventLogger/MappingUtils.js +16 -0
  46. package/dist/utils/eventLogger/MappingUtils.js.map +1 -0
  47. package/dist/utils/issuanceBranding/MappingUtils.d.ts +8 -0
  48. package/dist/utils/issuanceBranding/MappingUtils.d.ts.map +1 -0
  49. package/dist/utils/issuanceBranding/MappingUtils.js +20 -0
  50. package/dist/utils/issuanceBranding/MappingUtils.js.map +1 -0
  51. package/dist/utils/presentationDefinition/MappingUtils.d.ts.map +1 -1
  52. package/dist/utils/presentationDefinition/MappingUtils.js +5 -3
  53. package/dist/utils/presentationDefinition/MappingUtils.js.map +1 -1
  54. package/package.json +8 -8
  55. package/src/__tests__/digitalCredential.store.test.ts +83 -4
  56. package/src/__tests__/eventLogger.entities.test.ts +60 -5
  57. package/src/__tests__/eventLogger.store.test.ts +480 -3
  58. package/src/digitalCredential/DigitalCredentialStore.ts +1 -3
  59. package/src/entities/eventLogger/AuditEventEntity.ts +54 -3
  60. package/src/eventLogger/AbstractEventLoggerStore.ts +9 -2
  61. package/src/eventLogger/EventLoggerStore.ts +54 -32
  62. package/src/issuanceBranding/IssuanceBrandingStore.ts +13 -63
  63. package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +34 -6
  64. package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +27 -1
  65. package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -2
  66. package/src/types/eventLogger/eventLogger.ts +3 -2
  67. package/src/utils/FormattingUtils.ts +21 -0
  68. package/src/utils/contact/MappingUtils.ts +39 -13
  69. package/src/utils/digitalCredential/MappingUtils.ts +4 -1
  70. package/src/utils/eventLogger/MappingUtils.ts +61 -0
  71. package/src/utils/issuanceBranding/MappingUtils.ts +32 -0
  72. package/src/utils/presentationDefinition/MappingUtils.ts +4 -1
@@ -1,10 +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 { AuditEventEntity, auditEventEntityFrom } from '../entities/eventLogger/AuditEventEntity'
7
- import { GetAuditEventsArgs, StoreAuditEventArgs } from '../types'
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'
8
18
 
9
19
  const debug: Debugger = Debug('sphereon:ssi-sdk:event-store')
10
20
 
@@ -17,46 +27,58 @@ export class EventLoggerStore extends AbstractEventLoggerStore {
17
27
  }
18
28
 
19
29
  getAuditEvents = async (args?: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>> => {
20
- const connection: DataSource = await this.dbConnection // TODO apply everywhere
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
21
38
  debug('Getting audit events', args)
22
- const result: Array<AuditEventEntity> = await connection.getRepository(AuditEventEntity).find({
23
- ...(args?.filter && { where: args?.filter }),
39
+ const result = await connection.getRepository(AuditEventEntity).find({
40
+ where: auditEventsFilter
24
41
  })
25
42
 
26
- return result.map((event: AuditEventEntity) => this.auditEventFrom(event))
43
+ return result.map((event: AuditEventEntity) => auditEventFrom(event))
27
44
  }
28
45
 
29
46
  storeAuditEvent = async (args: StoreAuditEventArgs): Promise<AuditLoggingEvent> => {
30
47
  const { event } = args
31
48
 
32
- const auditEventEntity: AuditEventEntity = auditEventEntityFrom(event)
33
- const connection: DataSource = await this.dbConnection
49
+ const auditEventEntity = auditEventEntityFrom(event)
50
+ const connection = await this.dbConnection
34
51
  debug('Storing audit event', auditEventEntity)
35
- const createdResult: AuditEventEntity = await connection.getRepository(AuditEventEntity).save(auditEventEntity)
52
+ const createdResult = await connection.getRepository(AuditEventEntity).save(auditEventEntity)
36
53
 
37
- return this.auditEventFrom(createdResult)
54
+ return auditEventFrom(createdResult)
38
55
  }
39
56
 
40
- private auditEventFrom = (event: AuditEventEntity): AuditLoggingEvent => {
41
- return {
42
- id: event.id,
43
- description: event.description,
44
- timestamp: event.timestamp,
45
- level: event.level,
46
- correlationId: event.correlationId,
47
- actionType: event.actionType,
48
- actionSubType: event.actionSubType,
49
- initiatorType: event.initiatorType,
50
- partyAlias: event.partyAlias,
51
- partyCorrelationId: event.partyCorrelationId,
52
- partyCorrelationType: event.partyCorrelationType,
53
- subSystemType: event.subSystemType,
54
- system: event.system,
55
- systemAlias: event.systemAlias,
56
- systemCorrelationId: event.systemCorrelationId,
57
- systemCorrelationIdType: event.systemCorrelationIdType,
58
- ...(event.data && { data: JSON.parse(event.data) }),
59
- ...(event.diagnosticData && { diagnosticData: JSON.parse(event.diagnosticData) }),
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 })
60
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)
61
83
  }
62
84
  }
@@ -11,6 +11,7 @@ import { IssuerLocaleBrandingEntity, issuerLocaleBrandingEntityFrom } from '../e
11
11
  import { BaseLocaleBrandingEntity } from '../entities/issuanceBranding/BaseLocaleBrandingEntity'
12
12
  import { TextAttributesEntity } from '../entities/issuanceBranding/TextAttributesEntity'
13
13
  import { AbstractIssuanceBrandingStore } from './AbstractIssuanceBrandingStore'
14
+ import { credentialBrandingFrom, issuerBrandingFrom, localeBrandingFrom } from '../utils/issuanceBranding/MappingUtils'
14
15
  import {
15
16
  IAddCredentialBrandingArgs,
16
17
  IAddCredentialLocaleBrandingArgs,
@@ -30,7 +31,6 @@ import {
30
31
  IIssuerBrandingFilter,
31
32
  IIssuerLocaleBranding,
32
33
  IIssuerLocaleBrandingFilter,
33
- ILocaleBranding,
34
34
  IRemoveCredentialBrandingArgs,
35
35
  IRemoveCredentialLocaleBrandingArgs,
36
36
  IRemoveIssuerBrandingArgs,
@@ -71,7 +71,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
71
71
  debug('Adding credential branding', credentialBrandingEntity)
72
72
  const createdResult: CredentialBrandingEntity = await repository.save(credentialBrandingEntity)
73
73
 
74
- return this.credentialBrandingFrom(createdResult)
74
+ return credentialBrandingFrom(createdResult)
75
75
  }
76
76
 
77
77
  public getCredentialBranding = async (args?: IGetCredentialBrandingArgs): Promise<Array<ICredentialBranding>> => {
@@ -89,7 +89,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
89
89
  ...(filter && { where: filter }),
90
90
  })
91
91
 
92
- return result.map((credentialBranding: CredentialBrandingEntity) => this.credentialBrandingFrom(credentialBranding))
92
+ return result.map((credentialBranding: CredentialBrandingEntity) => credentialBrandingFrom(credentialBranding))
93
93
  }
94
94
 
95
95
  public removeCredentialBranding = async (args: IRemoveCredentialBrandingArgs): Promise<void> => {
@@ -133,7 +133,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
133
133
  debug('Updating credential branding', branding)
134
134
  const result: CredentialBrandingEntity = await repository.save(branding, { transaction: true })
135
135
 
136
- return this.credentialBrandingFrom(result)
136
+ return credentialBrandingFrom(result)
137
137
  }
138
138
 
139
139
  public addCredentialLocaleBranding = async (args: IAddCredentialLocaleBrandingArgs): Promise<ICredentialBranding> => {
@@ -188,7 +188,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
188
188
  return Promise.reject(Error('Unable to get updated credential branding'))
189
189
  }
190
190
 
191
- return this.credentialBrandingFrom(result)
191
+ return credentialBrandingFrom(result)
192
192
  }
193
193
 
194
194
  public getCredentialLocaleBranding = async (args?: IGetCredentialLocaleBrandingArgs): Promise<Array<ICredentialLocaleBranding>> => {
@@ -210,8 +210,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
210
210
 
211
211
  return credentialBrandingLocale
212
212
  ? credentialBrandingLocale.map(
213
- (credentialLocaleBranding: CredentialLocaleBrandingEntity) =>
214
- this.localeBrandingFrom(credentialLocaleBranding) as ICredentialLocaleBranding,
213
+ (credentialLocaleBranding: CredentialLocaleBrandingEntity) => localeBrandingFrom(credentialLocaleBranding) as ICredentialLocaleBranding,
215
214
  )
216
215
  : []
217
216
  }
@@ -259,7 +258,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
259
258
  debug('Updating credential locale branding', localeBranding)
260
259
  const updatedResult: CredentialLocaleBrandingEntity = await repository.save(localeBranding, { transaction: true })
261
260
 
262
- return this.localeBrandingFrom(updatedResult) as ICredentialLocaleBranding
261
+ return localeBrandingFrom(updatedResult) as ICredentialLocaleBranding
263
262
  }
264
263
 
265
264
  public addIssuerBranding = async (args: IAddIssuerBrandingArgs): Promise<IIssuerBranding> => {
@@ -281,7 +280,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
281
280
  debug('Adding issuer branding', issuerBrandingEntity)
282
281
  const createdResult: IssuerBrandingEntity = await repository.save(issuerBrandingEntity)
283
282
 
284
- return this.issuerBrandingFrom(createdResult)
283
+ return issuerBrandingFrom(createdResult)
285
284
  }
286
285
 
287
286
  public getIssuerBranding = async (args?: IGetIssuerBrandingArgs): Promise<Array<IIssuerBranding>> => {
@@ -299,7 +298,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
299
298
  ...(filter && { where: filter }),
300
299
  })
301
300
 
302
- return result.map((issuerBranding: IssuerBrandingEntity) => this.issuerBrandingFrom(issuerBranding))
301
+ return result.map((issuerBranding: IssuerBrandingEntity) => issuerBrandingFrom(issuerBranding))
303
302
  }
304
303
 
305
304
  public removeIssuerBranding = async (args: IRemoveIssuerBrandingArgs): Promise<void> => {
@@ -343,7 +342,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
343
342
  debug('Updating issuer branding', branding)
344
343
  const result: IssuerBrandingEntity = await repository.save(branding, { transaction: true })
345
344
 
346
- return this.issuerBrandingFrom(result)
345
+ return issuerBrandingFrom(result)
347
346
  }
348
347
 
349
348
  public addIssuerLocaleBranding = async (args: IAddIssuerLocaleBrandingArgs): Promise<IIssuerBranding> => {
@@ -394,7 +393,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
394
393
  return Promise.reject(Error('Unable to get updated issuer branding'))
395
394
  }
396
395
 
397
- return this.issuerBrandingFrom(result)
396
+ return issuerBrandingFrom(result)
398
397
  }
399
398
 
400
399
  public getIssuerLocaleBranding = async (args?: IGetIssuerLocaleBrandingArgs): Promise<Array<IIssuerLocaleBranding>> => {
@@ -416,7 +415,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
416
415
 
417
416
  return issuerLocaleBranding
418
417
  ? issuerLocaleBranding.map(
419
- (issuerLocaleBranding: IssuerLocaleBrandingEntity) => this.localeBrandingFrom(issuerLocaleBranding) as IIssuerLocaleBranding,
418
+ (issuerLocaleBranding: IssuerLocaleBrandingEntity) => localeBrandingFrom(issuerLocaleBranding) as IIssuerLocaleBranding,
420
419
  )
421
420
  : []
422
421
  }
@@ -462,56 +461,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
462
461
  debug('Updating issuer locale branding', localeBranding)
463
462
  const updatedResult: IssuerLocaleBrandingEntity = await repository.save(localeBranding, { transaction: true })
464
463
 
465
- return this.localeBrandingFrom(updatedResult) as IIssuerLocaleBranding
466
- }
467
-
468
- private credentialBrandingFrom = (credentialBranding: CredentialBrandingEntity): ICredentialBranding => {
469
- const result: ICredentialBranding = {
470
- ...credentialBranding,
471
- localeBranding: credentialBranding.localeBranding.map((localeBranding: BaseLocaleBrandingEntity) => this.localeBrandingFrom(localeBranding)),
472
- }
473
-
474
- return this.replaceNullWithUndefined(result)
475
- }
476
-
477
- private issuerBrandingFrom = (issuerBranding: IssuerBrandingEntity): IIssuerBranding => {
478
- const result: IIssuerBranding = {
479
- ...issuerBranding,
480
- localeBranding: issuerBranding.localeBranding.map((localeBranding: BaseLocaleBrandingEntity) => this.localeBrandingFrom(localeBranding)),
481
- }
482
-
483
- return this.replaceNullWithUndefined(result)
484
- }
485
-
486
- private localeBrandingFrom = (localeBranding: BaseLocaleBrandingEntity): ILocaleBranding => {
487
- const result: ILocaleBranding = {
488
- ...localeBranding,
489
- locale: localeBranding.locale === '' ? undefined : localeBranding.locale,
490
- }
491
-
492
- return this.replaceNullWithUndefined(result)
493
- }
494
-
495
- private replaceNullWithUndefined(obj: any): any {
496
- if (obj === null) {
497
- return undefined
498
- }
499
-
500
- if (typeof obj !== 'object' || obj instanceof Date) {
501
- return obj
502
- }
503
-
504
- if (Array.isArray(obj)) {
505
- return obj.map((value: any) => this.replaceNullWithUndefined(value))
506
- }
507
-
508
- const result: any = {}
509
- for (const key in obj) {
510
- if (obj.hasOwnProperty(key)) {
511
- result[key] = this.replaceNullWithUndefined(obj[key])
512
- }
513
- }
514
- return result
464
+ return localeBrandingFrom(updatedResult) as IIssuerLocaleBranding
515
465
  }
516
466
 
517
467
  private hasDuplicateLocales = async (localeBranding: Array<IBasicCredentialLocaleBranding | IBasicIssuerLocaleBranding>): Promise<boolean> => {
@@ -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" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "timestamp" TIMESTAMP NOT NULL, "level" "public"."Level_enum" NOT NULL, "correlationId" TEXT NOT NULL, "system" "public"."System_enum" NOT NULL, "subSystemType" "public"."Subsystem_type_enum" NOT NULL, "actionType" "public"."Action_type_enum" NOT NULL, "actionSubType" TEXT NOT NULL, "initiatorType" "public"."Initiator_type_enum" NOT NULL, "systemCorrelationIdType" "public"."System_correlation_id_type_enum", "systemCorrelationId" TEXT, "systemAlias" TEXT, "partyCorrelationType" "public"."Party_correlation_type_enum", "partyCorrelationId" TEXT, "partyAlias" TEXT, "description" TEXT NOT NULL, "data" TEXT, "diagnosticData" TEXT, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))`,
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" ("id" varchar PRIMARY KEY NOT NULL, "timestamp" datetime NOT NULL, "level" varchar CHECK( "level" IN ('0','1','2','3') ) NOT NULL, "correlationId" varchar NOT NULL, "system" varchar CHECK( "system" IN ('general','kms','identity','oid4vci','credentials','web3','profile','contact') ) NOT NULL, "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') ) NOT NULL, "actionType" varchar CHECK( "actionType" IN ('create','read','update','delete','execute') ) NOT NULL, "actionSubType" varchar NOT NULL, "initiatorType" varchar CHECK( "initiatorType" IN ('user','system','external') ) NOT NULL, "systemCorrelationIdType" varchar CHECK( "systemCorrelationIdType" IN ('did','email','hostname','phone','user') ), "systemCorrelationId" varchar, "systemAlias" varchar, "partyCorrelationType" varchar CHECK( "partyCorrelationType" IN ('did','email','hostname','phone') ), "partyCorrelationId" varchar, "partyAlias" varchar, "description" varchar NOT NULL, "data" varchar, "diagnosticData" varchar, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`,
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'>
@@ -0,0 +1,21 @@
1
+ export const replaceNullWithUndefined = (obj: any): any => {
2
+ if (obj === null) {
3
+ return undefined
4
+ }
5
+
6
+ if (typeof obj !== 'object' || obj instanceof Date) {
7
+ return obj
8
+ }
9
+
10
+ if (Array.isArray(obj)) {
11
+ return obj.map((value: any) => replaceNullWithUndefined(value))
12
+ }
13
+
14
+ const result: any = {}
15
+ for (const key in obj) {
16
+ if (obj.hasOwnProperty(key)) {
17
+ result[key] = replaceNullWithUndefined(obj[key])
18
+ }
19
+ }
20
+ return result
21
+ }
@@ -47,6 +47,7 @@ import { OpenIdConfigEntity } from '../../entities/contact/OpenIdConfigEntity'
47
47
  import { PartyTypeEntity } from '../../entities/contact/PartyTypeEntity'
48
48
  import { PhysicalAddressEntity } from '../../entities/contact/PhysicalAddressEntity'
49
49
  import { ContactMetadataItemEntity } from '../../entities/contact/ContactMetadataItemEntity'
50
+ import { replaceNullWithUndefined } from '../FormattingUtils'
50
51
 
51
52
  export const partyEntityFrom = (party: NonPersistedParty): PartyEntity => {
52
53
  const partyEntity: PartyEntity = new PartyEntity()
@@ -67,10 +68,10 @@ export const partyEntityFrom = (party: NonPersistedParty): PartyEntity => {
67
68
  }
68
69
 
69
70
  export const partyFrom = (party: PartyEntity): Party => {
70
- return {
71
+ const result: Party = {
71
72
  id: party.id,
72
73
  uri: party.uri,
73
- roles: [...new Set(party.identities?.flatMap((identity: IdentityEntity) => identity.roles))] ?? [],
74
+ roles: [...new Set(party.identities?.flatMap((identity: IdentityEntity) => identity.roles))],
74
75
  identities: party.identities ? party.identities.map((identity: IdentityEntity) => identityFrom(identity)) : [],
75
76
  electronicAddresses: party.electronicAddresses
76
77
  ? party.electronicAddresses.map((electronicAddress: ElectronicAddressEntity) => electronicAddressFrom(electronicAddress))
@@ -86,6 +87,8 @@ export const partyFrom = (party: PartyEntity): Party => {
86
87
  createdAt: party.createdAt,
87
88
  lastUpdatedAt: party.lastUpdatedAt,
88
89
  }
90
+
91
+ return replaceNullWithUndefined(result)
89
92
  }
90
93
 
91
94
  export const contactEntityFrom = (contact: NonPersistedContact): BaseContactEntity => {
@@ -125,13 +128,15 @@ export const connectionEntityFrom = (connection: NonPersistedConnection): Connec
125
128
  }
126
129
 
127
130
  export const connectionFrom = (connection: ConnectionEntity): Connection => {
128
- return {
131
+ const result: Connection = {
129
132
  id: connection.id,
130
133
  type: connection.type,
131
134
  ownerId: connection.ownerId,
132
135
  tenantId: connection.tenantId,
133
136
  config: configFrom(connection.config),
134
137
  }
138
+
139
+ return replaceNullWithUndefined(result)
135
140
  }
136
141
 
137
142
  const configEntityFrom = (config: NonPersistedConnectionConfig): BaseConfigEntity => {
@@ -155,13 +160,15 @@ export const correlationIdentifierEntityFrom = (identifier: NonPersistedCorrelat
155
160
  }
156
161
 
157
162
  export const correlationIdentifierFrom = (identifier: CorrelationIdentifierEntity): CorrelationIdentifier => {
158
- return {
163
+ const result: CorrelationIdentifier = {
159
164
  id: identifier.id,
160
165
  type: identifier.type,
161
166
  correlationId: identifier.correlationId,
162
167
  ownerId: identifier.ownerId,
163
168
  tenantId: identifier.tenantId,
164
169
  }
170
+
171
+ return replaceNullWithUndefined(result)
165
172
  }
166
173
 
167
174
  export const didAuthConfigEntityFrom = (config: NonPersistedDidAuthConfig): DidAuthConfigEntity => {
@@ -196,7 +203,7 @@ export const electronicAddressEntityFrom = (electronicAddress: NonPersistedElect
196
203
  }
197
204
 
198
205
  export const electronicAddressFrom = (electronicAddress: ElectronicAddressEntity): ElectronicAddress => {
199
- return {
206
+ const result: ElectronicAddress = {
200
207
  id: electronicAddress.id,
201
208
  type: electronicAddress.type,
202
209
  electronicAddress: electronicAddress.electronicAddress,
@@ -205,6 +212,8 @@ export const electronicAddressFrom = (electronicAddress: ElectronicAddressEntity
205
212
  createdAt: electronicAddress.createdAt,
206
213
  lastUpdatedAt: electronicAddress.lastUpdatedAt,
207
214
  }
215
+
216
+ return replaceNullWithUndefined(result)
208
217
  }
209
218
 
210
219
  export const physicalAddressEntityFrom = (physicalAddress: NonPersistedPhysicalAddress): PhysicalAddressEntity => {
@@ -224,7 +233,7 @@ export const physicalAddressEntityFrom = (physicalAddress: NonPersistedPhysicalA
224
233
  }
225
234
 
226
235
  export const physicalAddressFrom = (physicalAddress: PhysicalAddressEntity): PhysicalAddress => {
227
- return {
236
+ const result: PhysicalAddress = {
228
237
  id: physicalAddress.id,
229
238
  type: physicalAddress.type,
230
239
  streetName: physicalAddress.streetName,
@@ -239,6 +248,8 @@ export const physicalAddressFrom = (physicalAddress: PhysicalAddressEntity): Phy
239
248
  createdAt: physicalAddress.createdAt,
240
249
  lastUpdatedAt: physicalAddress.lastUpdatedAt,
241
250
  }
251
+
252
+ return replaceNullWithUndefined(result)
242
253
  }
243
254
 
244
255
  export const identityEntityFrom = (entity: NonPersistedIdentity): IdentityEntity => {
@@ -257,7 +268,7 @@ export const identityEntityFrom = (entity: NonPersistedIdentity): IdentityEntity
257
268
  }
258
269
 
259
270
  export const identityFrom = (identity: IdentityEntity): Identity => {
260
- return {
271
+ const result: Identity = {
261
272
  id: identity.id,
262
273
  alias: identity.alias,
263
274
  origin: identity.origin,
@@ -270,6 +281,8 @@ export const identityFrom = (identity: IdentityEntity): Identity => {
270
281
  createdAt: identity.createdAt,
271
282
  lastUpdatedAt: identity.createdAt,
272
283
  }
284
+
285
+ return replaceNullWithUndefined(result)
273
286
  }
274
287
 
275
288
  const metadataItemEntityFrom = <T extends MetadataTypes, U extends { new (): any }>(
@@ -359,7 +372,7 @@ export const naturalPersonEntityFrom = (naturalPerson: NonPersistedNaturalPerson
359
372
  }
360
373
 
361
374
  export const naturalPersonFrom = (naturalPerson: NaturalPersonEntity): NaturalPerson => {
362
- return {
375
+ const result: NaturalPerson = {
363
376
  id: naturalPerson.id,
364
377
  firstName: naturalPerson.firstName,
365
378
  middleName: naturalPerson.middleName,
@@ -371,6 +384,8 @@ export const naturalPersonFrom = (naturalPerson: NaturalPersonEntity): NaturalPe
371
384
  createdAt: naturalPerson.createdAt,
372
385
  lastUpdatedAt: naturalPerson.lastUpdatedAt,
373
386
  }
387
+
388
+ return replaceNullWithUndefined(result)
374
389
  }
375
390
 
376
391
  export const openIdConfigEntityFrom = (config: NonPersistedOpenIdConfig): OpenIdConfigEntity => {
@@ -402,7 +417,7 @@ export const organizationEntityFrom = (organization: NonPersistedOrganization):
402
417
  }
403
418
 
404
419
  export const organizationFrom = (organization: OrganizationEntity): Organization => {
405
- return {
420
+ const result: Organization = {
406
421
  id: organization.id,
407
422
  legalName: organization.legalName,
408
423
  displayName: organization.displayName,
@@ -412,6 +427,8 @@ export const organizationFrom = (organization: OrganizationEntity): Organization
412
427
  createdAt: organization.createdAt,
413
428
  lastUpdatedAt: organization.lastUpdatedAt,
414
429
  }
430
+
431
+ return replaceNullWithUndefined(result)
415
432
  }
416
433
 
417
434
  export const partyRelationshipEntityFrom = (relationship: NonPersistedPartyRelationship): PartyRelationshipEntity => {
@@ -420,11 +437,12 @@ export const partyRelationshipEntityFrom = (relationship: NonPersistedPartyRelat
420
437
  partyRelationshipEntity.rightId = relationship.rightId
421
438
  partyRelationshipEntity.ownerId = relationship.ownerId
422
439
  partyRelationshipEntity.tenantId = relationship.tenantId
440
+
423
441
  return partyRelationshipEntity
424
442
  }
425
443
 
426
444
  export const partyRelationshipFrom = (relationship: PartyRelationshipEntity): PartyRelationship => {
427
- return {
445
+ const result: PartyRelationship = {
428
446
  id: relationship.id,
429
447
  leftId: relationship.leftId,
430
448
  rightId: relationship.rightId,
@@ -433,6 +451,8 @@ export const partyRelationshipFrom = (relationship: PartyRelationshipEntity): Pa
433
451
  createdAt: relationship.createdAt,
434
452
  lastUpdatedAt: relationship.lastUpdatedAt,
435
453
  }
454
+
455
+ return replaceNullWithUndefined(result)
436
456
  }
437
457
 
438
458
  export const partyTypeEntityFrom = (args: NonPersistedPartyType): PartyTypeEntity => {
@@ -450,7 +470,7 @@ export const partyTypeEntityFrom = (args: NonPersistedPartyType): PartyTypeEntit
450
470
  }
451
471
 
452
472
  export const partyTypeFrom = (partyType: PartyTypeEntity): PartyType => {
453
- return {
473
+ const result: PartyType = {
454
474
  id: partyType.id,
455
475
  type: partyType.type,
456
476
  origin: partyType.origin,
@@ -460,6 +480,8 @@ export const partyTypeFrom = (partyType: PartyTypeEntity): PartyType => {
460
480
  createdAt: partyType.createdAt,
461
481
  lastUpdatedAt: partyType.lastUpdatedAt,
462
482
  }
483
+
484
+ return replaceNullWithUndefined(result)
463
485
  }
464
486
 
465
487
  export const configFrom = (config: BaseConfigEntity): ConnectionConfig => {
@@ -473,7 +495,7 @@ export const configFrom = (config: BaseConfigEntity): ConnectionConfig => {
473
495
  }
474
496
 
475
497
  export const openIdConfigFrom = (config: OpenIdConfigEntity): OpenIdConfig => {
476
- return {
498
+ const result: OpenIdConfig = {
477
499
  id: config.id,
478
500
  clientId: config.clientId,
479
501
  clientSecret: config.clientSecret,
@@ -485,10 +507,12 @@ export const openIdConfigFrom = (config: OpenIdConfigEntity): OpenIdConfig => {
485
507
  ownerId: config.ownerId,
486
508
  tenantId: config.tenantId,
487
509
  }
510
+
511
+ return replaceNullWithUndefined(result)
488
512
  }
489
513
 
490
514
  export const didAuthConfigFrom = (config: DidAuthConfigEntity): DidAuthConfig => {
491
- return {
515
+ const result: DidAuthConfig = {
492
516
  id: config.id,
493
517
  idOpts: { identifier: config.identifier },
494
518
  stateId: '', // FIXME
@@ -497,6 +521,8 @@ export const didAuthConfigFrom = (config: DidAuthConfigEntity): DidAuthConfig =>
497
521
  ownerId: config.ownerId,
498
522
  tenantId: config.tenantId,
499
523
  }
524
+
525
+ return replaceNullWithUndefined(result)
500
526
  }
501
527
 
502
528
  export const isOpenIdConfig = (config: NonPersistedConnectionConfig | BaseConfigEntity): config is OpenIdConfig | OpenIdConfigEntity =>