@sphereon/ssi-sdk.data-store 0.30.2-unstable.19 → 0.30.2-unstable.21

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 (68) hide show
  1. package/dist/digitalCredential/DigitalCredentialStore.d.ts.map +1 -1
  2. package/dist/digitalCredential/DigitalCredentialStore.js +1 -3
  3. package/dist/digitalCredential/DigitalCredentialStore.js.map +1 -1
  4. package/dist/entities/eventLogger/AuditEventEntity.d.ts +9 -3
  5. package/dist/entities/eventLogger/AuditEventEntity.d.ts.map +1 -1
  6. package/dist/entities/eventLogger/AuditEventEntity.js +52 -1
  7. package/dist/entities/eventLogger/AuditEventEntity.js.map +1 -1
  8. package/dist/eventLogger/AbstractEventLoggerStore.d.ts +4 -2
  9. package/dist/eventLogger/AbstractEventLoggerStore.d.ts.map +1 -1
  10. package/dist/eventLogger/AbstractEventLoggerStore.js.map +1 -1
  11. package/dist/eventLogger/EventLoggerStore.d.ts +4 -3
  12. package/dist/eventLogger/EventLoggerStore.d.ts.map +1 -1
  13. package/dist/eventLogger/EventLoggerStore.js +34 -6
  14. package/dist/eventLogger/EventLoggerStore.js.map +1 -1
  15. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts +0 -4
  16. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -1
  17. package/dist/issuanceBranding/IssuanceBrandingStore.js +13 -42
  18. package/dist/issuanceBranding/IssuanceBrandingStore.js.map +1 -1
  19. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.d.ts.map +1 -1
  20. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js +29 -1
  21. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js.map +1 -1
  22. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.d.ts.map +1 -1
  23. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js +25 -1
  24. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js.map +1 -1
  25. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts +9 -2
  26. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts.map +1 -1
  27. package/dist/types/eventLogger/eventLogger.d.ts +3 -2
  28. package/dist/types/eventLogger/eventLogger.d.ts.map +1 -1
  29. package/dist/utils/FormattingUtils.d.ts +2 -0
  30. package/dist/utils/FormattingUtils.d.ts.map +1 -0
  31. package/dist/utils/FormattingUtils.js +23 -0
  32. package/dist/utils/FormattingUtils.js.map +1 -0
  33. package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
  34. package/dist/utils/contact/MappingUtils.js +25 -12
  35. package/dist/utils/contact/MappingUtils.js.map +1 -1
  36. package/dist/utils/digitalCredential/MappingUtils.d.ts.map +1 -1
  37. package/dist/utils/digitalCredential/MappingUtils.js +3 -1
  38. package/dist/utils/digitalCredential/MappingUtils.js.map +1 -1
  39. package/dist/utils/eventLogger/MappingUtils.d.ts +5 -0
  40. package/dist/utils/eventLogger/MappingUtils.d.ts.map +1 -0
  41. package/dist/utils/eventLogger/MappingUtils.js +16 -0
  42. package/dist/utils/eventLogger/MappingUtils.js.map +1 -0
  43. package/dist/utils/issuanceBranding/MappingUtils.d.ts +8 -0
  44. package/dist/utils/issuanceBranding/MappingUtils.d.ts.map +1 -0
  45. package/dist/utils/issuanceBranding/MappingUtils.js +20 -0
  46. package/dist/utils/issuanceBranding/MappingUtils.js.map +1 -0
  47. package/dist/utils/presentationDefinition/MappingUtils.d.ts.map +1 -1
  48. package/dist/utils/presentationDefinition/MappingUtils.js +3 -1
  49. package/dist/utils/presentationDefinition/MappingUtils.js.map +1 -1
  50. package/package.json +5 -5
  51. package/src/__tests__/digitalCredential.store.test.ts +83 -4
  52. package/src/__tests__/eventLogger.entities.test.ts +59 -5
  53. package/src/__tests__/eventLogger.store.test.ts +183 -3
  54. package/src/digitalCredential/DigitalCredentialStore.ts +1 -3
  55. package/src/entities/eventLogger/AuditEventEntity.ts +50 -3
  56. package/src/eventLogger/AbstractEventLoggerStore.ts +9 -2
  57. package/src/eventLogger/EventLoggerStore.ts +38 -27
  58. package/src/issuanceBranding/IssuanceBrandingStore.ts +14 -62
  59. package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +29 -1
  60. package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +25 -1
  61. package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -2
  62. package/src/types/eventLogger/eventLogger.ts +3 -2
  63. package/src/utils/FormattingUtils.ts +21 -0
  64. package/src/utils/contact/MappingUtils.ts +39 -16
  65. package/src/utils/digitalCredential/MappingUtils.ts +4 -1
  66. package/src/utils/eventLogger/MappingUtils.ts +61 -0
  67. package/src/utils/issuanceBranding/MappingUtils.ts +32 -0
  68. package/src/utils/presentationDefinition/MappingUtils.ts +4 -1
@@ -1,10 +1,11 @@
1
1
  import Debug, { Debugger } from 'debug'
2
2
  import { DataSource } from 'typeorm'
3
- import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
3
+ import { ActivityLoggingEvent, AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
4
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 { activityEventEntityFrom, AuditEventEntity, auditEventEntityFrom } from '../entities/eventLogger/AuditEventEntity'
7
+ import { activityEventFrom, auditEventFrom } from '../utils/eventLogger/MappingUtils'
8
+ import {GetActivityEventsArgs, GetAuditEventsArgs, StoreActivityEventArgs, StoreAuditEventArgs} from '../types'
8
9
 
9
10
  const debug: Debugger = Debug('sphereon:ssi-sdk:event-store')
10
11
 
@@ -19,11 +20,33 @@ export class EventLoggerStore extends AbstractEventLoggerStore {
19
20
  getAuditEvents = async (args?: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>> => {
20
21
  const connection: DataSource = await this.dbConnection // TODO apply everywhere
21
22
  debug('Getting audit events', args)
23
+ const where: any = {}
24
+ if (args?.filter) {
25
+ args.filter.forEach((filterCondition) => {
26
+ Object.assign(where, filterCondition)
27
+ })
28
+ }
22
29
  const result: Array<AuditEventEntity> = await connection.getRepository(AuditEventEntity).find({
23
- ...(args?.filter && { where: args?.filter }),
30
+ where,
24
31
  })
25
32
 
26
- return result.map((event: AuditEventEntity) => this.auditEventFrom(event))
33
+ return result.map((event: AuditEventEntity) => auditEventFrom(event))
34
+ }
35
+
36
+ getActivityEvents = async (args?: GetActivityEventsArgs): Promise<Array<ActivityLoggingEvent>> => {
37
+ const connection: DataSource = await this.dbConnection
38
+ debug('Getting activity events', args)
39
+ const where: any = {}
40
+ if (args?.filter) {
41
+ args.filter.forEach((filterCondition) => {
42
+ Object.assign(where, filterCondition)
43
+ })
44
+ }
45
+ const result: Array<AuditEventEntity> = await connection.getRepository(AuditEventEntity).find({
46
+ where,
47
+ })
48
+
49
+ return result.map((event: AuditEventEntity) => activityEventFrom(event))
27
50
  }
28
51
 
29
52
  storeAuditEvent = async (args: StoreAuditEventArgs): Promise<AuditLoggingEvent> => {
@@ -34,29 +57,17 @@ export class EventLoggerStore extends AbstractEventLoggerStore {
34
57
  debug('Storing audit event', auditEventEntity)
35
58
  const createdResult: AuditEventEntity = await connection.getRepository(AuditEventEntity).save(auditEventEntity)
36
59
 
37
- return this.auditEventFrom(createdResult)
60
+ return auditEventFrom(createdResult)
38
61
  }
39
62
 
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) }),
60
- }
63
+ storeActivityEvent = async (args: StoreActivityEventArgs): Promise<ActivityLoggingEvent> => {
64
+ const { event } = args
65
+
66
+ const activityEventEntity: AuditEventEntity = activityEventEntityFrom(event)
67
+ const connection: DataSource = await this.dbConnection
68
+ debug('Storing activity event', activityEventEntity)
69
+ const createdResult: AuditEventEntity = await connection.getRepository(AuditEventEntity).save(activityEventEntity)
70
+
71
+ return activityEventFrom(createdResult)
61
72
  }
62
73
  }
@@ -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,
@@ -42,6 +42,7 @@ import {
42
42
  ICredentialBrandingFilter,
43
43
  } from '../types'
44
44
 
45
+
45
46
  const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:issuance-branding-store')
46
47
 
47
48
  export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
@@ -71,7 +72,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
71
72
  debug('Adding credential branding', credentialBrandingEntity)
72
73
  const createdResult: CredentialBrandingEntity = await repository.save(credentialBrandingEntity)
73
74
 
74
- return this.credentialBrandingFrom(createdResult)
75
+ return credentialBrandingFrom(createdResult)
75
76
  }
76
77
 
77
78
  public getCredentialBranding = async (args?: IGetCredentialBrandingArgs): Promise<Array<ICredentialBranding>> => {
@@ -89,7 +90,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
89
90
  ...(filter && { where: filter }),
90
91
  })
91
92
 
92
- return result.map((credentialBranding: CredentialBrandingEntity) => this.credentialBrandingFrom(credentialBranding))
93
+ return result.map((credentialBranding: CredentialBrandingEntity) => credentialBrandingFrom(credentialBranding))
93
94
  }
94
95
 
95
96
  public removeCredentialBranding = async (args: IRemoveCredentialBrandingArgs): Promise<void> => {
@@ -133,7 +134,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
133
134
  debug('Updating credential branding', branding)
134
135
  const result: CredentialBrandingEntity = await repository.save(branding, { transaction: true })
135
136
 
136
- return this.credentialBrandingFrom(result)
137
+ return credentialBrandingFrom(result)
137
138
  }
138
139
 
139
140
  public addCredentialLocaleBranding = async (args: IAddCredentialLocaleBrandingArgs): Promise<ICredentialBranding> => {
@@ -188,7 +189,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
188
189
  return Promise.reject(Error('Unable to get updated credential branding'))
189
190
  }
190
191
 
191
- return this.credentialBrandingFrom(result)
192
+ return credentialBrandingFrom(result)
192
193
  }
193
194
 
194
195
  public getCredentialLocaleBranding = async (args?: IGetCredentialLocaleBrandingArgs): Promise<Array<ICredentialLocaleBranding>> => {
@@ -211,7 +212,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
211
212
  return credentialBrandingLocale
212
213
  ? credentialBrandingLocale.map(
213
214
  (credentialLocaleBranding: CredentialLocaleBrandingEntity) =>
214
- this.localeBrandingFrom(credentialLocaleBranding) as ICredentialLocaleBranding,
215
+ localeBrandingFrom(credentialLocaleBranding) as ICredentialLocaleBranding,
215
216
  )
216
217
  : []
217
218
  }
@@ -259,7 +260,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
259
260
  debug('Updating credential locale branding', localeBranding)
260
261
  const updatedResult: CredentialLocaleBrandingEntity = await repository.save(localeBranding, { transaction: true })
261
262
 
262
- return this.localeBrandingFrom(updatedResult) as ICredentialLocaleBranding
263
+ return localeBrandingFrom(updatedResult) as ICredentialLocaleBranding
263
264
  }
264
265
 
265
266
  public addIssuerBranding = async (args: IAddIssuerBrandingArgs): Promise<IIssuerBranding> => {
@@ -281,7 +282,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
281
282
  debug('Adding issuer branding', issuerBrandingEntity)
282
283
  const createdResult: IssuerBrandingEntity = await repository.save(issuerBrandingEntity)
283
284
 
284
- return this.issuerBrandingFrom(createdResult)
285
+ return issuerBrandingFrom(createdResult)
285
286
  }
286
287
 
287
288
  public getIssuerBranding = async (args?: IGetIssuerBrandingArgs): Promise<Array<IIssuerBranding>> => {
@@ -299,7 +300,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
299
300
  ...(filter && { where: filter }),
300
301
  })
301
302
 
302
- return result.map((issuerBranding: IssuerBrandingEntity) => this.issuerBrandingFrom(issuerBranding))
303
+ return result.map((issuerBranding: IssuerBrandingEntity) => issuerBrandingFrom(issuerBranding))
303
304
  }
304
305
 
305
306
  public removeIssuerBranding = async (args: IRemoveIssuerBrandingArgs): Promise<void> => {
@@ -343,7 +344,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
343
344
  debug('Updating issuer branding', branding)
344
345
  const result: IssuerBrandingEntity = await repository.save(branding, { transaction: true })
345
346
 
346
- return this.issuerBrandingFrom(result)
347
+ return issuerBrandingFrom(result)
347
348
  }
348
349
 
349
350
  public addIssuerLocaleBranding = async (args: IAddIssuerLocaleBrandingArgs): Promise<IIssuerBranding> => {
@@ -394,7 +395,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
394
395
  return Promise.reject(Error('Unable to get updated issuer branding'))
395
396
  }
396
397
 
397
- return this.issuerBrandingFrom(result)
398
+ return issuerBrandingFrom(result)
398
399
  }
399
400
 
400
401
  public getIssuerLocaleBranding = async (args?: IGetIssuerLocaleBrandingArgs): Promise<Array<IIssuerLocaleBranding>> => {
@@ -416,7 +417,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
416
417
 
417
418
  return issuerLocaleBranding
418
419
  ? issuerLocaleBranding.map(
419
- (issuerLocaleBranding: IssuerLocaleBrandingEntity) => this.localeBrandingFrom(issuerLocaleBranding) as IIssuerLocaleBranding,
420
+ (issuerLocaleBranding: IssuerLocaleBrandingEntity) => localeBrandingFrom(issuerLocaleBranding) as IIssuerLocaleBranding,
420
421
  )
421
422
  : []
422
423
  }
@@ -462,56 +463,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
462
463
  debug('Updating issuer locale branding', localeBranding)
463
464
  const updatedResult: IssuerLocaleBrandingEntity = await repository.save(localeBranding, { transaction: true })
464
465
 
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
466
+ return localeBrandingFrom(updatedResult) as IIssuerLocaleBranding
515
467
  }
516
468
 
517
469
  private hasDuplicateLocales = async (localeBranding: Array<IBasicCredentialLocaleBranding | IBasicIssuerLocaleBranding>): Promise<boolean> => {
@@ -15,8 +15,36 @@ export class CreateAuditEvents1701634812183 implements MigrationInterface {
15
15
  await queryRunner.query(`CREATE TYPE "public"."Initiator_type_enum" AS ENUM('user', 'system', 'external')`)
16
16
  await queryRunner.query(`CREATE TYPE "public"."System_correlation_id_type_enum" AS ENUM('did', 'email', 'hostname', 'phone', 'user')`)
17
17
  await queryRunner.query(`CREATE TYPE "public"."Party_correlation_type_enum" AS ENUM('did', '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,31 @@ 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') ) NOT NULL,
13
+ "correlationId" varchar NOT NULL,
14
+ "system" varchar CHECK( "system" IN ('general','kms','identity','oid4vci','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') ) NOT NULL,
16
+ "actionType" varchar CHECK( "actionType" IN ('create','read','update','delete','execute') ) NOT NULL,
17
+ "actionSubType" varchar NOT NULL, "initiatorType" varchar CHECK( "initiatorType" IN ('user','system','external') ) NOT NULL,
18
+ "systemCorrelationIdType" varchar CHECK( "systemCorrelationIdType" IN ('did','email','hostname','phone','user') ),
19
+ "systemCorrelationId" varchar,
20
+ "systemAlias" varchar,
21
+ "partyCorrelationType" varchar CHECK( "partyCorrelationType" IN ('did','email','hostname','phone') ),
22
+ "partyCorrelationId" varchar,
23
+ "partyAlias" varchar,
24
+ "credentialType" varchar CHECK( "credentialType" IN ('JSON_LD', 'JWT', 'SD_JWT', 'MSO_MDOC') ),
25
+ "credentialHash" varchar,
26
+ "originalCredential" varchar,
27
+ "sharePurpose" varchar,
28
+ "description" varchar NOT NULL,
29
+ "data" varchar,
30
+ "diagnosticData" varchar,
31
+ "created_at" datetime NOT NULL DEFAULT (datetime('now')),
32
+ "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`,
9
33
  )
10
34
  }
11
35
 
@@ -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,7 +68,7 @@ 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
74
  roles: [...new Set(party.identities?.flatMap((identity: IdentityEntity) => identity.roles))] ?? [],
@@ -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,12 +281,11 @@ 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
- const metadataItemEntityFrom = <T extends MetadataTypes, U extends { new (): any }>(
276
- item: NonPersistedMetadataItem<T>,
277
- EntityClass: U,
278
- ): InstanceType<U> | undefined => {
288
+ const metadataItemEntityFrom = <T extends MetadataTypes, U extends { new (): any }>(item: NonPersistedMetadataItem<T>, EntityClass: U): InstanceType<U> | undefined => {
279
289
  const { label, value } = item
280
290
 
281
291
  if (value === null || value === undefined) {
@@ -359,7 +369,7 @@ export const naturalPersonEntityFrom = (naturalPerson: NonPersistedNaturalPerson
359
369
  }
360
370
 
361
371
  export const naturalPersonFrom = (naturalPerson: NaturalPersonEntity): NaturalPerson => {
362
- return {
372
+ const result: NaturalPerson = {
363
373
  id: naturalPerson.id,
364
374
  firstName: naturalPerson.firstName,
365
375
  middleName: naturalPerson.middleName,
@@ -371,6 +381,8 @@ export const naturalPersonFrom = (naturalPerson: NaturalPersonEntity): NaturalPe
371
381
  createdAt: naturalPerson.createdAt,
372
382
  lastUpdatedAt: naturalPerson.lastUpdatedAt,
373
383
  }
384
+
385
+ return replaceNullWithUndefined(result)
374
386
  }
375
387
 
376
388
  export const openIdConfigEntityFrom = (config: NonPersistedOpenIdConfig): OpenIdConfigEntity => {
@@ -402,7 +414,7 @@ export const organizationEntityFrom = (organization: NonPersistedOrganization):
402
414
  }
403
415
 
404
416
  export const organizationFrom = (organization: OrganizationEntity): Organization => {
405
- return {
417
+ const result: Organization = {
406
418
  id: organization.id,
407
419
  legalName: organization.legalName,
408
420
  displayName: organization.displayName,
@@ -412,6 +424,8 @@ export const organizationFrom = (organization: OrganizationEntity): Organization
412
424
  createdAt: organization.createdAt,
413
425
  lastUpdatedAt: organization.lastUpdatedAt,
414
426
  }
427
+
428
+ return replaceNullWithUndefined(result)
415
429
  }
416
430
 
417
431
  export const partyRelationshipEntityFrom = (relationship: NonPersistedPartyRelationship): PartyRelationshipEntity => {
@@ -420,11 +434,12 @@ export const partyRelationshipEntityFrom = (relationship: NonPersistedPartyRelat
420
434
  partyRelationshipEntity.rightId = relationship.rightId
421
435
  partyRelationshipEntity.ownerId = relationship.ownerId
422
436
  partyRelationshipEntity.tenantId = relationship.tenantId
437
+
423
438
  return partyRelationshipEntity
424
439
  }
425
440
 
426
441
  export const partyRelationshipFrom = (relationship: PartyRelationshipEntity): PartyRelationship => {
427
- return {
442
+ const result: PartyRelationship = {
428
443
  id: relationship.id,
429
444
  leftId: relationship.leftId,
430
445
  rightId: relationship.rightId,
@@ -433,6 +448,8 @@ export const partyRelationshipFrom = (relationship: PartyRelationshipEntity): Pa
433
448
  createdAt: relationship.createdAt,
434
449
  lastUpdatedAt: relationship.lastUpdatedAt,
435
450
  }
451
+
452
+ return replaceNullWithUndefined(result)
436
453
  }
437
454
 
438
455
  export const partyTypeEntityFrom = (args: NonPersistedPartyType): PartyTypeEntity => {
@@ -450,7 +467,7 @@ export const partyTypeEntityFrom = (args: NonPersistedPartyType): PartyTypeEntit
450
467
  }
451
468
 
452
469
  export const partyTypeFrom = (partyType: PartyTypeEntity): PartyType => {
453
- return {
470
+ const result: PartyType = {
454
471
  id: partyType.id,
455
472
  type: partyType.type,
456
473
  origin: partyType.origin,
@@ -460,6 +477,8 @@ export const partyTypeFrom = (partyType: PartyTypeEntity): PartyType => {
460
477
  createdAt: partyType.createdAt,
461
478
  lastUpdatedAt: partyType.lastUpdatedAt,
462
479
  }
480
+
481
+ return replaceNullWithUndefined(result)
463
482
  }
464
483
 
465
484
  export const configFrom = (config: BaseConfigEntity): ConnectionConfig => {
@@ -473,7 +492,7 @@ export const configFrom = (config: BaseConfigEntity): ConnectionConfig => {
473
492
  }
474
493
 
475
494
  export const openIdConfigFrom = (config: OpenIdConfigEntity): OpenIdConfig => {
476
- return {
495
+ const result: OpenIdConfig = {
477
496
  id: config.id,
478
497
  clientId: config.clientId,
479
498
  clientSecret: config.clientSecret,
@@ -485,10 +504,12 @@ export const openIdConfigFrom = (config: OpenIdConfigEntity): OpenIdConfig => {
485
504
  ownerId: config.ownerId,
486
505
  tenantId: config.tenantId,
487
506
  }
507
+
508
+ return replaceNullWithUndefined(result)
488
509
  }
489
510
 
490
511
  export const didAuthConfigFrom = (config: DidAuthConfigEntity): DidAuthConfig => {
491
- return {
512
+ const result: DidAuthConfig = {
492
513
  id: config.id,
493
514
  idOpts: { identifier: config.identifier },
494
515
  stateId: '', // FIXME
@@ -497,6 +518,8 @@ export const didAuthConfigFrom = (config: DidAuthConfigEntity): DidAuthConfig =>
497
518
  ownerId: config.ownerId,
498
519
  tenantId: config.tenantId,
499
520
  }
521
+
522
+ return replaceNullWithUndefined(result)
500
523
  }
501
524
 
502
525
  export const isOpenIdConfig = (config: NonPersistedConnectionConfig | BaseConfigEntity): config is OpenIdConfig | OpenIdConfigEntity =>
@@ -18,6 +18,7 @@ import {
18
18
  NonPersistedDigitalCredential,
19
19
  RegulationType,
20
20
  } from '../../types'
21
+ import { replaceNullWithUndefined } from '../FormattingUtils'
21
22
 
22
23
  function determineDocumentType(raw: string): DocumentType {
23
24
  const rawDocument = parseRawDocument(raw)
@@ -150,9 +151,11 @@ export const nonPersistedDigitalCredentialEntityFromAddArgs = (addCredentialArgs
150
151
  }
151
152
 
152
153
  export const digitalCredentialFrom = (credentialEntity: DigitalCredentialEntity): DigitalCredential => {
153
- return {
154
+ const result: DigitalCredential = {
154
155
  ...credentialEntity,
155
156
  }
157
+
158
+ return replaceNullWithUndefined(result)
156
159
  }
157
160
 
158
161
  export const digitalCredentialsFrom = (credentialEntities: Array<DigitalCredentialEntity>): DigitalCredential[] => {