@sphereon/ssi-sdk.data-store 0.36.1-feature.vdx24.einvoice.inbox.141 → 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/dist/index.cjs +46 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -2
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/contact/ContactStore.ts +37 -2
package/dist/index.cjs
CHANGED
|
@@ -5114,10 +5114,54 @@ var ContactStore = class extends import_ssi_sdk25.AbstractContactStore {
|
|
|
5114
5114
|
return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
|
|
5115
5115
|
}
|
|
5116
5116
|
}
|
|
5117
|
-
const
|
|
5117
|
+
const identityRepository = (await this.dbConnection).getRepository(IdentityEntity);
|
|
5118
|
+
const correlationIdentifierRepository = (await this.dbConnection).getRepository(CorrelationIdentifierEntity);
|
|
5119
|
+
const existingCorrelationIdentifier = await correlationIdentifierRepository.findOne({
|
|
5120
|
+
where: {
|
|
5121
|
+
correlationId: identity.identifier.correlationId
|
|
5122
|
+
}
|
|
5123
|
+
});
|
|
5124
|
+
if (existingCorrelationIdentifier) {
|
|
5125
|
+
const existingIdentity = await identityRepository.findOne({
|
|
5126
|
+
where: {
|
|
5127
|
+
identifier: {
|
|
5128
|
+
id: existingCorrelationIdentifier.id
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
});
|
|
5132
|
+
if (existingIdentity) {
|
|
5133
|
+
debug("Identity with same correlationId already exists, returning existing identity", identity.identifier.correlationId);
|
|
5134
|
+
return identityFrom(existingIdentity);
|
|
5135
|
+
}
|
|
5136
|
+
}
|
|
5137
|
+
const existingAlias = await identityRepository.findOne({
|
|
5138
|
+
where: {
|
|
5139
|
+
alias: identity.alias
|
|
5140
|
+
}
|
|
5141
|
+
});
|
|
5142
|
+
let uniqueAlias = identity.alias;
|
|
5143
|
+
if (existingAlias) {
|
|
5144
|
+
let counter = 1;
|
|
5145
|
+
while (await identityRepository.findOne({
|
|
5146
|
+
where: {
|
|
5147
|
+
alias: `${identity.alias}_${counter}`
|
|
5148
|
+
}
|
|
5149
|
+
})) {
|
|
5150
|
+
counter++;
|
|
5151
|
+
}
|
|
5152
|
+
uniqueAlias = `${identity.alias}_${counter}`;
|
|
5153
|
+
debug("Alias collision detected, using unique alias", {
|
|
5154
|
+
original: identity.alias,
|
|
5155
|
+
unique: uniqueAlias
|
|
5156
|
+
});
|
|
5157
|
+
}
|
|
5158
|
+
const identityEntity = identityEntityFrom({
|
|
5159
|
+
...identity,
|
|
5160
|
+
alias: uniqueAlias
|
|
5161
|
+
});
|
|
5118
5162
|
identityEntity.party = party;
|
|
5119
5163
|
debug("Adding identity", identity);
|
|
5120
|
-
const result = await
|
|
5164
|
+
const result = await identityRepository.save(identityEntity, {
|
|
5121
5165
|
transaction: true
|
|
5122
5166
|
});
|
|
5123
5167
|
return identityFrom(result);
|