@sphereon/ssi-sdk.data-store 0.36.1-feature.vdx24.einvoice.inbox.138 → 0.36.1-feature.vdx24.einvoice.inbox.142

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-feature.vdx24.einvoice.inbox.138+fa0621e6",
3
+ "version": "0.36.1-feature.vdx24.einvoice.inbox.142+ff40ab64",
4
4
  "source": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,12 +28,12 @@
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-feature.vdx24.einvoice.inbox.138+fa0621e6",
32
- "@sphereon/ssi-sdk-ext.identifier-resolution": "0.36.1-feature.vdx24.einvoice.inbox.138+fa0621e6",
33
- "@sphereon/ssi-sdk.agent-config": "0.36.1-feature.vdx24.einvoice.inbox.138+fa0621e6",
34
- "@sphereon/ssi-sdk.core": "0.36.1-feature.vdx24.einvoice.inbox.138+fa0621e6",
35
- "@sphereon/ssi-sdk.data-store-types": "0.36.1-feature.vdx24.einvoice.inbox.138+fa0621e6",
36
- "@sphereon/ssi-types": "0.36.1-feature.vdx24.einvoice.inbox.138+fa0621e6",
31
+ "@sphereon/ssi-sdk-ext.did-utils": "0.36.1-feature.vdx24.einvoice.inbox.142+ff40ab64",
32
+ "@sphereon/ssi-sdk-ext.identifier-resolution": "0.36.1-feature.vdx24.einvoice.inbox.142+ff40ab64",
33
+ "@sphereon/ssi-sdk.agent-config": "0.36.1-feature.vdx24.einvoice.inbox.142+ff40ab64",
34
+ "@sphereon/ssi-sdk.core": "0.36.1-feature.vdx24.einvoice.inbox.142+ff40ab64",
35
+ "@sphereon/ssi-sdk.data-store-types": "0.36.1-feature.vdx24.einvoice.inbox.142+ff40ab64",
36
+ "@sphereon/ssi-types": "0.36.1-feature.vdx24.einvoice.inbox.142+ff40ab64",
37
37
  "@veramo/core": "4.2.0",
38
38
  "@veramo/data-store": "4.2.0",
39
39
  "@veramo/utils": "4.2.0",
@@ -67,5 +67,5 @@
67
67
  "PostgreSQL",
68
68
  "Contact Store"
69
69
  ],
70
- "gitHead": "fa0621e62e4e3e9669e087da06fcde71a3ce1ba1"
70
+ "gitHead": "ff40ab64b07e77c8565ed97a027c74bb4d754f28"
71
71
  }
@@ -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