@sphereon/ssi-sdk.data-store 0.36.1-next.129 → 0.36.1-next.150

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.data-store",
3
- "version": "0.36.1-next.129+2a4f4386",
3
+ "version": "0.36.1-next.150+f7fd1f3f",
4
4
  "source": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,13 +28,14 @@
28
28
  "dependencies": {
29
29
  "@sphereon/kmp-mdoc-core": "0.2.0-SNAPSHOT.26",
30
30
  "@sphereon/pex": "5.0.0-unstable.28",
31
- "@sphereon/ssi-sdk-ext.did-utils": "0.36.1-next.129+2a4f4386",
32
- "@sphereon/ssi-sdk-ext.identifier-resolution": "0.36.1-next.129+2a4f4386",
33
- "@sphereon/ssi-sdk.agent-config": "0.36.1-next.129+2a4f4386",
34
- "@sphereon/ssi-sdk.core": "0.36.1-next.129+2a4f4386",
35
- "@sphereon/ssi-sdk.data-store-types": "0.36.1-next.129+2a4f4386",
36
- "@sphereon/ssi-types": "0.36.1-next.129+2a4f4386",
31
+ "@sphereon/ssi-sdk-ext.did-utils": "0.36.1-next.150+f7fd1f3f",
32
+ "@sphereon/ssi-sdk-ext.identifier-resolution": "0.36.1-next.150+f7fd1f3f",
33
+ "@sphereon/ssi-sdk.agent-config": "0.36.1-next.150+f7fd1f3f",
34
+ "@sphereon/ssi-sdk.core": "0.36.1-next.150+f7fd1f3f",
35
+ "@sphereon/ssi-sdk.data-store-types": "0.36.1-next.150+f7fd1f3f",
36
+ "@sphereon/ssi-types": "0.36.1-next.150+f7fd1f3f",
37
37
  "@veramo/core": "4.2.0",
38
+ "@veramo/data-store": "4.2.0",
38
39
  "@veramo/utils": "4.2.0",
39
40
  "blakejs": "^1.2.1",
40
41
  "class-validator": "0.14.1",
@@ -66,5 +67,5 @@
66
67
  "PostgreSQL",
67
68
  "Contact Store"
68
69
  ],
69
- "gitHead": "2a4f43863a1544f53c63485daee40bcb2abbfa81"
70
+ "gitHead": "f7fd1f3f7e42d569b2695b54aa2587fa4926310d"
70
71
  }
@@ -18,7 +18,7 @@ import { PartyEntity } from '../entities/contact/PartyEntity'
18
18
  import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity'
19
19
  import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity'
20
20
  import { PhysicalAddressEntity } from '../entities/contact/PhysicalAddressEntity'
21
- import { contactMetadataItemEntityFrom, DataStoreContactEntities, DataStoreMigrations, identityMetadataItemEntityFrom, partyTypeFrom } from '../index'
21
+ import { contactMetadataItemEntityFrom, DataStoreEntitiesWithVeramo, DataStoreMigrationsWithVeramo, identityMetadataItemEntityFrom, partyTypeFrom } from '../index'
22
22
  import {
23
23
  IdentityOrigin,
24
24
  MetadataTypes,
@@ -64,9 +64,9 @@ describe('Database entities tests', (): void => {
64
64
  database: ':memory:',
65
65
  logging: ['info'],
66
66
  migrationsRun: false,
67
- migrations: DataStoreMigrations,
67
+ migrations: DataStoreMigrationsWithVeramo,
68
68
  synchronize: false,
69
- entities: DataStoreContactEntities,
69
+ entities: DataStoreEntitiesWithVeramo,
70
70
  }).initialize()
71
71
  await dbConnection.runMigrations()
72
72
  expect(await dbConnection.showMigrations()).toBeFalsy()
@@ -31,7 +31,7 @@ import { CredentialRole } from '@sphereon/ssi-types'
31
31
  import { DataSource } from 'typeorm'
32
32
  import { afterEach, beforeEach, describe, expect, it } from 'vitest'
33
33
  import { ContactStore } from '../contact/ContactStore'
34
- import { DataStoreContactEntities, DataStoreMigrations } from '../index'
34
+ import { DataStoreEntitiesWithVeramo, DataStoreMigrationsWithVeramo } from '../index'
35
35
 
36
36
  describe('Contact store tests', (): void => {
37
37
  let dbConnection: DataSource
@@ -44,9 +44,9 @@ describe('Contact store tests', (): void => {
44
44
  database: ':memory:',
45
45
  logging: ['info'],
46
46
  migrationsRun: false,
47
- migrations: DataStoreMigrations,
47
+ migrations: DataStoreMigrationsWithVeramo,
48
48
  synchronize: false,
49
- entities: DataStoreContactEntities,
49
+ entities: DataStoreEntitiesWithVeramo,
50
50
  }).initialize()
51
51
  await dbConnection.runMigrations()
52
52
  expect(await dbConnection.showMigrations()).toBeFalsy()
@@ -6,7 +6,7 @@ import {
6
6
  credentialBrandingEntityFrom,
7
7
  CredentialLocaleBrandingEntity,
8
8
  credentialLocaleBrandingEntityFrom,
9
- DataStoreIssuanceBrandingEntities,
9
+ DataStoreIssuanceBrandingEntities, DataStoreEntitiesWithVeramo,
10
10
  IBasicCredentialBranding,
11
11
  IBasicCredentialLocaleBranding,
12
12
  IBasicIssuerBranding,
@@ -16,7 +16,7 @@ import {
16
16
  IssuerLocaleBrandingEntity,
17
17
  issuerLocaleBrandingEntityFrom,
18
18
  } from '../index'
19
- import { DataStoreMigrations } from '../migrations'
19
+ import { DataStoreMigrationsWithVeramo } from '../migrations'
20
20
 
21
21
  describe('Database entities tests', (): void => {
22
22
  let dbConnection: DataSource
@@ -28,9 +28,9 @@ describe('Database entities tests', (): void => {
28
28
  database: ':memory:',
29
29
  //logging: ['info'],
30
30
  migrationsRun: false,
31
- migrations: DataStoreMigrations,
31
+ migrations: DataStoreMigrationsWithVeramo,
32
32
  synchronize: false,
33
- entities: DataStoreIssuanceBrandingEntities,
33
+ entities: DataStoreEntitiesWithVeramo,
34
34
  }).initialize()
35
35
  await dbConnection.runMigrations()
36
36
  expect(await dbConnection.showMigrations()).toBeFalsy()
@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'
4
4
  import {
5
5
  BackgroundAttributesEntity,
6
6
  CredentialLocaleBrandingEntity,
7
- DataStoreIssuanceBrandingEntities,
7
+ DataStoreIssuanceBrandingEntities, DataStoreEntitiesWithVeramo,
8
8
  IAddCredentialLocaleBrandingArgs,
9
9
  IAddIssuerLocaleBrandingArgs,
10
10
  IBasicCredentialBranding,
@@ -26,7 +26,7 @@ import {
26
26
  TextAttributesEntity,
27
27
  } from '../index'
28
28
  import { IssuanceBrandingStore } from '../issuanceBranding/IssuanceBrandingStore'
29
- import { DataStoreMigrations } from '../migrations'
29
+ import { DataStoreMigrationsWithVeramo } from '../migrations'
30
30
 
31
31
  describe('Issuance branding store tests', (): void => {
32
32
  let dbConnection: DataSource
@@ -39,9 +39,9 @@ describe('Issuance branding store tests', (): void => {
39
39
  database: ':memory:',
40
40
  //logging: ['info'],
41
41
  migrationsRun: false,
42
- migrations: DataStoreMigrations,
42
+ migrations: DataStoreMigrationsWithVeramo,
43
43
  synchronize: false,
44
- entities: DataStoreIssuanceBrandingEntities,
44
+ entities: DataStoreEntitiesWithVeramo,
45
45
  }).initialize()
46
46
  await dbConnection.runMigrations()
47
47
  expect(await dbConnection.showMigrations()).toBeFalsy()
@@ -249,10 +249,45 @@ export class ContactStore extends AbstractContactStore {
249
249
  }
250
250
  }
251
251
 
252
- const identityEntity: IdentityEntity = identityEntityFrom(identity)
252
+ const identityRepository = (await this.dbConnection).getRepository(IdentityEntity)
253
+ const correlationIdentifierRepository = (await this.dbConnection).getRepository(CorrelationIdentifierEntity)
254
+
255
+ // First check if an identity with the same correlationId already exists
256
+ const existingCorrelationIdentifier = await correlationIdentifierRepository.findOne({
257
+ where: { correlationId: identity.identifier.correlationId },
258
+ })
259
+
260
+ if (existingCorrelationIdentifier) {
261
+ // The same identifier already exists, return the existing identity
262
+ const existingIdentity = await identityRepository.findOne({
263
+ where: { identifier: { id: existingCorrelationIdentifier.id } },
264
+ })
265
+ if (existingIdentity) {
266
+ debug('Identity with same correlationId already exists, returning existing identity', identity.identifier.correlationId)
267
+ return identityFrom(existingIdentity)
268
+ }
269
+ }
270
+
271
+ // Check if an identity with the same alias exists (but different correlationId)
272
+ const existingAlias = await identityRepository.findOne({
273
+ where: { alias: identity.alias },
274
+ })
275
+
276
+ let uniqueAlias = identity.alias
277
+ if (existingAlias) {
278
+ // Generate a unique alias by appending a counter
279
+ let counter = 1
280
+ while (await identityRepository.findOne({ where: { alias: `${identity.alias}_${counter}` } })) {
281
+ counter++
282
+ }
283
+ uniqueAlias = `${identity.alias}_${counter}`
284
+ debug('Alias collision detected, using unique alias', { original: identity.alias, unique: uniqueAlias })
285
+ }
286
+
287
+ const identityEntity: IdentityEntity = identityEntityFrom({ ...identity, alias: uniqueAlias })
253
288
  identityEntity.party = party
254
289
  debug('Adding identity', identity)
255
- const result: IdentityEntity = await (await this.dbConnection).getRepository(IdentityEntity).save(identityEntity, {
290
+ const result: IdentityEntity = await identityRepository.save(identityEntity, {
256
291
  transaction: true,
257
292
  })
258
293
 
@@ -6,8 +6,8 @@ export class OpenIdConfigEntity extends BaseConfigEntity {
6
6
  @Column('varchar', { name: 'client_id', length: 255, nullable: false })
7
7
  clientId!: string
8
8
 
9
- @Column('varchar', { name: 'client_secret', length: 255, nullable: false })
10
- clientSecret!: string
9
+ @Column('varchar', { name: 'client_secret', length: 255, nullable: true })
10
+ clientSecret?: string
11
11
 
12
12
  @Column('simple-array', { name: 'scopes', nullable: false })
13
13
  scopes!: Array<string>
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Entities as VeramoDataStoreEntities } from '@veramo/data-store'
1
2
  import { BaseConfigEntity } from './entities/contact/BaseConfigEntity'
2
3
  import { BaseContactEntity } from './entities/contact/BaseContactEntity'
3
4
  import { ConnectionEntity } from './entities/contact/ConnectionEntity'
@@ -53,6 +54,10 @@ export {
53
54
  DataStoreStatusListMigrations,
54
55
  DataStoreMachineStateMigrations,
55
56
  DataStorePresentationDefinitionMigrations,
57
+ DataStoreServiceMigrations,
58
+ DataStoreMigrationsWithVeramo,
59
+ VeramoDataStoreMigrations,
60
+ VeramoDataStoreEntities,
56
61
  } from './migrations'
57
62
  export * from './types'
58
63
  export * from './utils/contact/MappingUtils'
@@ -123,6 +128,13 @@ export const DataStoreEntities = [
123
128
  // ...DataStoreOid4vcStateEntities,
124
129
  ]
125
130
 
131
+ // All entities combined with Veramo entities if a party wants to enable them all at once
132
+ export const DataStoreEntitiesWithVeramo = [
133
+ ...VeramoDataStoreEntities,
134
+ ...DataStoreEntities,
135
+ ]
136
+
137
+
126
138
  export {
127
139
  BaseConfigEntity,
128
140
  ConnectionEntity,
@@ -0,0 +1,66 @@
1
+ import Debug, { Debugger } from 'debug'
2
+ import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
3
+ import { AddServiceMetadata1764000000001 } from '../postgres/1764000000001-AddServiceMetadata'
4
+ import { AddServiceMetadata1764000000002 } from '../sqlite/1764000000002-AddServiceMetadata'
5
+
6
+ const debug: Debugger = Debug('sphereon:ssi-sdk:migrations')
7
+
8
+ export class AddServiceMetadata1764000000000 implements MigrationInterface {
9
+ name: string = 'AddServiceMetadata1764000000000'
10
+
11
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
+ debug('migration: adding metadata column to service table')
13
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
14
+
15
+ switch (dbType) {
16
+ case 'postgres': {
17
+ debug('using postgres migration file for AddServiceMetadata')
18
+ const mig: AddServiceMetadata1764000000001 = new AddServiceMetadata1764000000001()
19
+ await mig.up(queryRunner)
20
+ debug('Postgres migration statements for AddServiceMetadata executed')
21
+ return
22
+ }
23
+ case 'sqlite':
24
+ case 'expo':
25
+ case 'react-native': {
26
+ debug('using sqlite/react-native migration file for AddServiceMetadata')
27
+ const mig: AddServiceMetadata1764000000002 = new AddServiceMetadata1764000000002()
28
+ await mig.up(queryRunner)
29
+ debug('SQLite migration statements for AddServiceMetadata executed')
30
+ return
31
+ }
32
+ default:
33
+ return Promise.reject(
34
+ `Migrations are currently only supported for sqlite, react-native, expo, and postgres for AddServiceMetadata. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
35
+ )
36
+ }
37
+ }
38
+
39
+ public async down(queryRunner: QueryRunner): Promise<void> {
40
+ debug('migration: reverting metadata column from service table')
41
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
42
+
43
+ switch (dbType) {
44
+ case 'postgres': {
45
+ debug('using postgres migration file for AddServiceMetadata')
46
+ const mig: AddServiceMetadata1764000000001 = new AddServiceMetadata1764000000001()
47
+ await mig.down(queryRunner)
48
+ debug('Postgres migration statements for AddServiceMetadata reverted')
49
+ return
50
+ }
51
+ case 'sqlite':
52
+ case 'expo':
53
+ case 'react-native': {
54
+ debug('using sqlite/react-native migration file for AddServiceMetadata')
55
+ const mig: AddServiceMetadata1764000000002 = new AddServiceMetadata1764000000002()
56
+ await mig.down(queryRunner)
57
+ debug('SQLite migration statements for AddServiceMetadata reverted')
58
+ return
59
+ }
60
+ default:
61
+ return Promise.reject(
62
+ `Migrations are currently only supported for sqlite, react-native, expo, and postgres for AddServiceMetadata. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
63
+ )
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,62 @@
1
+ import Debug, { Debugger } from 'debug'
2
+ import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
3
+ import { MakeOpenIdClientSecretNullable1767000000001 } from '../postgres/1767000000001-MakeOpenIdClientSecretNullable'
4
+ import { MakeOpenIdClientSecretNullable1767000000002 } from '../sqlite/1767000000002-MakeOpenIdClientSecretNullable'
5
+
6
+ const debug: Debugger = Debug('sphereon:ssi-sdk:migrations')
7
+
8
+ export class MakeOpenIdClientSecretNullable1767000000000 implements MigrationInterface {
9
+ name: string = 'MakeOpenIdClientSecretNullable1767000000000'
10
+
11
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
+ debug('migration: making client_secret nullable in BaseConfig table')
13
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
14
+
15
+ switch (dbType) {
16
+ case 'postgres': {
17
+ debug('using postgres migration file for MakeOpenIdClientSecretNullable')
18
+ const mig = new MakeOpenIdClientSecretNullable1767000000001()
19
+ await mig.up(queryRunner)
20
+ debug('Postgres migration statements for MakeOpenIdClientSecretNullable executed')
21
+ return
22
+ }
23
+ case 'sqlite':
24
+ case 'expo':
25
+ case 'react-native': {
26
+ debug('using sqlite/react-native migration file for MakeOpenIdClientSecretNullable')
27
+ const mig = new MakeOpenIdClientSecretNullable1767000000002()
28
+ await mig.up(queryRunner)
29
+ debug('SQLite migration statements for MakeOpenIdClientSecretNullable executed')
30
+ return
31
+ }
32
+ default:
33
+ return Promise.reject(
34
+ `Migrations are currently only supported for sqlite, react-native, expo, and postgres for MakeOpenIdClientSecretNullable. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
35
+ )
36
+ }
37
+ }
38
+
39
+ public async down(queryRunner: QueryRunner): Promise<void> {
40
+ debug('migration: reverting client_secret nullable in BaseConfig table')
41
+ const dbType: DatabaseType = queryRunner.connection.driver.options.type
42
+
43
+ switch (dbType) {
44
+ case 'postgres': {
45
+ const mig = new MakeOpenIdClientSecretNullable1767000000001()
46
+ await mig.down(queryRunner)
47
+ return
48
+ }
49
+ case 'sqlite':
50
+ case 'expo':
51
+ case 'react-native': {
52
+ const mig = new MakeOpenIdClientSecretNullable1767000000002()
53
+ await mig.down(queryRunner)
54
+ return
55
+ }
56
+ default:
57
+ return Promise.reject(
58
+ `Migrations are currently only supported for sqlite, react-native, expo, and postgres for MakeOpenIdClientSecretNullable. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
59
+ )
60
+ }
61
+ }
62
+ }
@@ -1,3 +1,4 @@
1
+ import { migrations as VeramoDataStoreMigrations, Entities as VeramoDataStoreEntities } from '@veramo/data-store'
1
2
  import { CreateContacts1659463079429 } from './1-CreateContacts'
2
3
  import { CreatePresentationDefinitions1716533767523 } from './10-CreatePresentationDefinitions'
3
4
  import { FixCredentialClaimsReferencesUuid1741895822987 } from './11-FixCredentialClaimsReferenceUuid'
@@ -5,6 +6,8 @@ import { AddBitstringStatusListEnum1741895823000, CreateBitstringStatusList17418
5
6
  import { CreateDcqlQueryItem1726617600000 } from './13-CreateDcqlQueryItem'
6
7
  import { AddLinkedVpFields1763387280000 } from './14-AddLinkedVpFields'
7
8
  import { AddBrandingState1766000000000 } from './15-AddBrandingState'
9
+ import { AddServiceMetadata1764000000000 } from './15-AddServiceMetadata'
10
+ import { MakeOpenIdClientSecretNullable1767000000000 } from './16-MakeOpenIdClientSecretNullable'
8
11
  import { CreateIssuanceBranding1659463079429 } from './2-CreateIssuanceBranding'
9
12
  import { CreateContacts1690925872318 } from './3-CreateContacts'
10
13
  import { CreateStatusList1693866470000 } from './4-CreateStatusList'
@@ -28,6 +31,7 @@ export const DataStoreContactMigrations = [
28
31
  CreateContacts1690925872318,
29
32
  CreateContacts1708525189000,
30
33
  CreateContacts1715761125000,
34
+ MakeOpenIdClientSecretNullable1767000000000,
31
35
  ]
32
36
  export const DataStoreIssuanceBrandingMigrations = [
33
37
  CreateIssuanceBranding1659463079429,
@@ -43,6 +47,7 @@ export const DataStoreEventLoggerMigrations = [CreateAuditEvents1701635835330]
43
47
  export const DataStoreDigitalCredentialMigrations = [CreateDigitalCredential1708525189000, AddLinkedVpFields1763387280000]
44
48
  export const DataStoreMachineStateMigrations = [CreateMachineStateStore1708098041262]
45
49
  export const DataStorePresentationDefinitionMigrations = [CreatePresentationDefinitions1716533767523, CreateDcqlQueryItem1726617600000]
50
+ export const DataStoreServiceMigrations = [AddServiceMetadata1764000000000]
46
51
 
47
52
  // All migrations together
48
53
  export const DataStoreMigrations = [
@@ -53,4 +58,16 @@ export const DataStoreMigrations = [
53
58
  ...DataStoreDigitalCredentialMigrations,
54
59
  ...DataStoreMachineStateMigrations,
55
60
  ...DataStorePresentationDefinitionMigrations,
61
+ ...DataStoreServiceMigrations,
56
62
  ]
63
+
64
+
65
+
66
+ // All migrations combined with Veramo migrations first - use this when you need both
67
+ export const DataStoreMigrationsWithVeramo = [
68
+ ...VeramoDataStoreMigrations,
69
+ ...DataStoreMigrations,
70
+ ]
71
+
72
+ // Re-export Veramo migrations and entities for convenience
73
+ export { VeramoDataStoreMigrations, VeramoDataStoreEntities }
@@ -1,5 +1,6 @@
1
1
  export {
2
2
  DataStoreMigrations,
3
+ DataStoreMigrationsWithVeramo,
3
4
  DataStoreEventLoggerMigrations,
4
5
  DataStoreContactMigrations,
5
6
  DataStoreIssuanceBrandingMigrations,
@@ -7,4 +8,7 @@ export {
7
8
  DataStoreDigitalCredentialMigrations,
8
9
  DataStoreMachineStateMigrations,
9
10
  DataStorePresentationDefinitionMigrations,
11
+ DataStoreServiceMigrations,
12
+ VeramoDataStoreMigrations,
13
+ VeramoDataStoreEntities,
10
14
  } from './generic'
@@ -0,0 +1,44 @@
1
+ import Debug, { Debugger } from 'debug'
2
+ import { MigrationInterface, QueryRunner } from 'typeorm'
3
+
4
+ const debug: Debugger = Debug('sphereon:ssi-sdk:migrations')
5
+
6
+ export class AddServiceMetadata1764000000001 implements MigrationInterface {
7
+ name = 'AddServiceMetadata1764000000001'
8
+
9
+ public async up(queryRunner: QueryRunner): Promise<void> {
10
+ // Check if the service table exists (created by Veramo migrations)
11
+ const table = await queryRunner.getTable('service')
12
+ if (!table) {
13
+ // Service table doesn't exist - Veramo DID Manager is not in use
14
+ // Skip this migration as there's no service table to modify
15
+ debug(
16
+ 'AddServiceMetadata: Skipping migration - service table does not exist. ' +
17
+ 'This is expected if Veramo DID Manager is not being used. ' +
18
+ 'If you need service metadata support, ensure Veramo migrations run before SSI-SDK migrations.'
19
+ )
20
+ console.warn(
21
+ '[SSI-SDK Migration] AddServiceMetadata: Skipping - service table does not exist (Veramo DID Manager not in use)'
22
+ )
23
+ return
24
+ }
25
+
26
+ await queryRunner.query(`
27
+ ALTER TABLE "service"
28
+ ADD COLUMN IF NOT EXISTS "metadata" jsonb
29
+ `)
30
+ debug('AddServiceMetadata: Added metadata column to service table')
31
+ }
32
+
33
+ public async down(queryRunner: QueryRunner): Promise<void> {
34
+ const table = await queryRunner.getTable('service')
35
+ if (!table) {
36
+ return
37
+ }
38
+
39
+ await queryRunner.query(`
40
+ ALTER TABLE "service"
41
+ DROP COLUMN IF EXISTS "metadata"
42
+ `)
43
+ }
44
+ }
@@ -0,0 +1,32 @@
1
+ import Debug, { Debugger } from 'debug'
2
+ import { MigrationInterface, QueryRunner } from 'typeorm'
3
+
4
+ const debug: Debugger = Debug('sphereon:ssi-sdk:migrations')
5
+
6
+ export class MakeOpenIdClientSecretNullable1767000000001 implements MigrationInterface {
7
+ name = 'MakeOpenIdClientSecretNullable1767000000001'
8
+
9
+ public async up(queryRunner: QueryRunner): Promise<void> {
10
+ const table = await queryRunner.getTable('BaseConfig')
11
+ if (!table) {
12
+ debug('MakeOpenIdClientSecretNullable: Skipping migration - BaseConfig table does not exist')
13
+ return
14
+ }
15
+
16
+ const column = table.columns.find((col) => col.name === 'client_secret')
17
+ if (column && !column.isNullable) {
18
+ await queryRunner.query(`ALTER TABLE "BaseConfig" ALTER COLUMN "client_secret" DROP NOT NULL`)
19
+ debug('MakeOpenIdClientSecretNullable: Made client_secret nullable')
20
+ }
21
+ }
22
+
23
+ public async down(queryRunner: QueryRunner): Promise<void> {
24
+ const table = await queryRunner.getTable('BaseConfig')
25
+ if (!table) {
26
+ return
27
+ }
28
+
29
+ await queryRunner.query(`UPDATE "BaseConfig" SET "client_secret" = '' WHERE "client_secret" IS NULL`)
30
+ await queryRunner.query(`ALTER TABLE "BaseConfig" ALTER COLUMN "client_secret" SET NOT NULL`)
31
+ }
32
+ }
@@ -0,0 +1,41 @@
1
+ import Debug, { Debugger } from 'debug'
2
+ import { MigrationInterface, QueryRunner } from 'typeorm'
3
+
4
+ const debug: Debugger = Debug('sphereon:ssi-sdk:migrations')
5
+
6
+ export class AddServiceMetadata1764000000002 implements MigrationInterface {
7
+ name = 'AddServiceMetadata1764000000002'
8
+
9
+ public async up(queryRunner: QueryRunner): Promise<void> {
10
+ // Check if the service table exists (created by Veramo migrations)
11
+ const table = await queryRunner.getTable('service')
12
+ if (!table) {
13
+ // Service table doesn't exist - Veramo DID Manager is not in use
14
+ // Skip this migration as there's no service table to modify
15
+ debug(
16
+ 'AddServiceMetadata: Skipping migration - service table does not exist. ' +
17
+ 'This is expected if Veramo DID Manager is not being used. ' +
18
+ 'If you need service metadata support, ensure Veramo migrations run before SSI-SDK migrations.'
19
+ )
20
+ console.warn(
21
+ '[SSI-SDK Migration] AddServiceMetadata: Skipping - service table does not exist (Veramo DID Manager not in use)'
22
+ )
23
+ return
24
+ }
25
+
26
+ // Check if metadata column already exists
27
+ const hasMetadataColumn = table.columns.some((col) => col.name === 'metadata')
28
+ if (!hasMetadataColumn) {
29
+ await queryRunner.query(`
30
+ ALTER TABLE "service"
31
+ ADD COLUMN "metadata" text
32
+ `)
33
+ debug('AddServiceMetadata: Added metadata column to service table')
34
+ }
35
+ }
36
+
37
+ public async down(queryRunner: QueryRunner): Promise<void> {
38
+ // SQLite doesn't support DROP COLUMN directly
39
+ // Also, if the service table doesn't exist, nothing to do
40
+ }
41
+ }
@@ -0,0 +1,22 @@
1
+ import Debug, { Debugger } from 'debug'
2
+ import { MigrationInterface, QueryRunner } from 'typeorm'
3
+
4
+ const debug: Debugger = Debug('sphereon:ssi-sdk:migrations')
5
+
6
+ export class MakeOpenIdClientSecretNullable1767000000002 implements MigrationInterface {
7
+ name = 'MakeOpenIdClientSecretNullable1767000000002'
8
+
9
+ public async up(queryRunner: QueryRunner): Promise<void> {
10
+ // SQLite columns added via ALTER TABLE are already nullable by default,
11
+ // and SQLite does not enforce NOT NULL changes via ALTER COLUMN.
12
+ // Since client_secret was originally created as NOT NULL, we need to recreate.
13
+ // However, SQLite in practice allows NULL values in NOT NULL columns when
14
+ // inserted via raw queries, and TypeORM's synchronize handles this.
15
+ // For safety, we simply ensure existing rows have an empty string if null.
16
+ debug('MakeOpenIdClientSecretNullable: SQLite does not support ALTER COLUMN, no action needed for nullable change')
17
+ }
18
+
19
+ public async down(queryRunner: QueryRunner): Promise<void> {
20
+ // No action needed
21
+ }
22
+ }
@@ -1,10 +1,13 @@
1
1
  import type { IPresentationDefinition } from '@sphereon/pex'
2
2
  import type { DcqlQueryItem, NonPersistedDcqlQueryItem, PartialDcqlQueryItem } from '@sphereon/ssi-sdk.data-store-types'
3
- import * as blakepkg from 'blakejs'
3
+ import * as blakejs from 'blakejs'
4
4
  import { DcqlQuery } from 'dcql'
5
5
  import { DcqlQueryItemEntity } from '../../entities/presentationDefinition/DcqlQueryItemEntity'
6
6
  import { replaceNullWithUndefined } from '../FormattingUtils'
7
7
 
8
+ // Handle CommonJS/ESM interop - blakejs may be wrapped in a default export
9
+ const blake = (blakejs as any).default ?? blakejs
10
+
8
11
  export const dcqlQueryItemFrom = (entity: DcqlQueryItemEntity): DcqlQueryItem => {
9
12
  const result: DcqlQueryItem = {
10
13
  id: entity.id,
@@ -41,7 +44,7 @@ export const dcqlQueryEntityItemFrom = (item: NonPersistedDcqlQueryItem): DcqlQu
41
44
  }
42
45
 
43
46
  function hashPayload(payload: IPresentationDefinition | DcqlQuery): string {
44
- return blakepkg.blake2bHex(JSON.stringify(payload))
47
+ return blake.blake2bHex(JSON.stringify(payload))
45
48
  }
46
49
 
47
50
  export function isPresentationDefinitionEqual(base: PartialDcqlQueryItem, compare: PartialDcqlQueryItem): boolean {