@sphereon/ssi-sdk.data-store 0.18.2-next.9 → 0.18.2-next.92
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/contact/AbstractContactStore.d.ts +11 -1
- package/dist/contact/AbstractContactStore.d.ts.map +1 -1
- package/dist/contact/AbstractContactStore.js.map +1 -1
- package/dist/contact/ContactStore.d.ts +27 -15
- package/dist/contact/ContactStore.d.ts.map +1 -1
- package/dist/contact/ContactStore.js +201 -32
- package/dist/contact/ContactStore.js.map +1 -1
- package/dist/entities/contact/ElectronicAddressEntity.d.ts +1 -0
- package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -1
- package/dist/entities/contact/ElectronicAddressEntity.js +4 -0
- package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -1
- package/dist/entities/contact/IdentityEntity.d.ts +1 -1
- package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
- package/dist/entities/contact/PartyEntity.d.ts +2 -0
- package/dist/entities/contact/PartyEntity.d.ts.map +1 -1
- package/dist/entities/contact/PartyEntity.js +12 -1
- package/dist/entities/contact/PartyEntity.js.map +1 -1
- package/dist/entities/contact/PhysicalAddressEntity.d.ts +21 -0
- package/dist/entities/contact/PhysicalAddressEntity.d.ts.map +1 -0
- package/dist/entities/contact/PhysicalAddressEntity.js +126 -0
- package/dist/entities/contact/PhysicalAddressEntity.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -1
- package/dist/issuanceBranding/IssuanceBrandingStore.js +76 -60
- package/dist/issuanceBranding/IssuanceBrandingStore.js.map +1 -1
- package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js +3 -6
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -1
- package/dist/types/contact/IAbstractContactStore.d.ts +36 -1
- package/dist/types/contact/IAbstractContactStore.d.ts.map +1 -1
- package/dist/types/contact/contact.d.ts +27 -4
- package/dist/types/contact/contact.d.ts.map +1 -1
- package/dist/types/contact/contact.js.map +1 -1
- package/dist/utils/contact/MappingUtils.d.ts +4 -1
- package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
- package/dist/utils/contact/MappingUtils.js +37 -1
- package/dist/utils/contact/MappingUtils.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/contact.entities.test.ts +340 -23
- package/src/__tests__/contact.store.test.ts +629 -10
- package/src/contact/AbstractContactStore.ts +38 -16
- package/src/contact/ContactStore.ts +278 -58
- package/src/entities/contact/ElectronicAddressEntity.ts +3 -0
- package/src/entities/contact/IdentityEntity.ts +1 -1
- package/src/entities/contact/PartyEntity.ts +11 -1
- package/src/entities/contact/PhysicalAddressEntity.ts +87 -0
- package/src/index.ts +3 -0
- package/src/issuanceBranding/IssuanceBrandingStore.ts +83 -69
- package/src/migrations/sqlite/1690925872693-CreateContacts.ts +3 -8
- package/src/types/contact/IAbstractContactStore.ts +58 -8
- package/src/types/contact/contact.ts +40 -4
- package/src/utils/contact/MappingUtils.ts +39 -0
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
Identity,
|
|
2
|
+
AddElectronicAddressArgs,
|
|
4
3
|
AddIdentityArgs,
|
|
5
|
-
|
|
4
|
+
AddPartyArgs,
|
|
5
|
+
AddPartyTypeArgs,
|
|
6
|
+
AddPhysicalAddressArgs,
|
|
7
|
+
AddRelationshipArgs,
|
|
8
|
+
ElectronicAddress,
|
|
9
|
+
GetElectronicAddressArgs,
|
|
10
|
+
GetElectronicAddressesArgs,
|
|
6
11
|
GetIdentitiesArgs,
|
|
12
|
+
GetIdentityArgs,
|
|
13
|
+
GetPartiesArgs,
|
|
7
14
|
GetPartyArgs,
|
|
15
|
+
GetPartyTypeArgs,
|
|
16
|
+
GetPartyTypesArgs,
|
|
17
|
+
GetPhysicalAddressArgs,
|
|
18
|
+
GetPhysicalAddressesArgs,
|
|
19
|
+
GetRelationshipArgs,
|
|
20
|
+
GetRelationshipsArgs,
|
|
21
|
+
Identity,
|
|
22
|
+
Party,
|
|
23
|
+
PartyRelationship,
|
|
24
|
+
PartyType,
|
|
25
|
+
PhysicalAddress,
|
|
26
|
+
RemoveElectronicAddressArgs,
|
|
8
27
|
RemoveIdentityArgs,
|
|
9
|
-
UpdateIdentityArgs,
|
|
10
|
-
AddPartyArgs,
|
|
11
|
-
GetPartiesArgs,
|
|
12
28
|
RemovePartyArgs,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
PartyRelationship,
|
|
29
|
+
RemovePartyTypeArgs,
|
|
30
|
+
RemovePhysicalAddressArgs,
|
|
16
31
|
RemoveRelationshipArgs,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
UpdateElectronicAddressArgs,
|
|
33
|
+
UpdateIdentityArgs,
|
|
34
|
+
UpdatePartyArgs,
|
|
20
35
|
UpdatePartyTypeArgs,
|
|
21
|
-
|
|
22
|
-
RemovePartyTypeArgs,
|
|
23
|
-
GetRelationshipsArgs,
|
|
24
|
-
GetRelationshipArgs,
|
|
36
|
+
UpdatePhysicalAddressArgs,
|
|
25
37
|
UpdateRelationshipArgs,
|
|
26
38
|
} from '../types'
|
|
27
39
|
|
|
@@ -46,4 +58,14 @@ export abstract class AbstractContactStore {
|
|
|
46
58
|
abstract addPartyType(args: AddPartyTypeArgs): Promise<PartyType>
|
|
47
59
|
abstract updatePartyType(args: UpdatePartyTypeArgs): Promise<PartyType>
|
|
48
60
|
abstract removePartyType(args: RemovePartyTypeArgs): Promise<void>
|
|
61
|
+
abstract getElectronicAddress(args: GetElectronicAddressArgs): Promise<ElectronicAddress>
|
|
62
|
+
abstract getElectronicAddresses(args?: GetElectronicAddressesArgs): Promise<Array<ElectronicAddress>>
|
|
63
|
+
abstract addElectronicAddress(args: AddElectronicAddressArgs): Promise<ElectronicAddress>
|
|
64
|
+
abstract updateElectronicAddress(args: UpdateElectronicAddressArgs): Promise<ElectronicAddress>
|
|
65
|
+
abstract removeElectronicAddress(args: RemoveElectronicAddressArgs): Promise<void>
|
|
66
|
+
abstract getPhysicalAddress(args: GetPhysicalAddressArgs): Promise<PhysicalAddress>
|
|
67
|
+
abstract getPhysicalAddresses(args?: GetPhysicalAddressesArgs): Promise<Array<PhysicalAddress>>
|
|
68
|
+
abstract addPhysicalAddress(args: AddPhysicalAddressArgs): Promise<PhysicalAddress>
|
|
69
|
+
abstract updatePhysicalAddress(args: UpdatePhysicalAddressArgs): Promise<PhysicalAddress>
|
|
70
|
+
abstract removePhysicalAddress(args: RemovePhysicalAddressArgs): Promise<void>
|
|
49
71
|
}
|
|
@@ -11,7 +11,11 @@ import { BaseConfigEntity } from '../entities/contact/BaseConfigEntity'
|
|
|
11
11
|
import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity'
|
|
12
12
|
import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity'
|
|
13
13
|
import { BaseContactEntity } from '../entities/contact/BaseContactEntity'
|
|
14
|
+
import { ElectronicAddressEntity } from '../entities/contact/ElectronicAddressEntity'
|
|
15
|
+
import { PhysicalAddressEntity } from '../entities/contact/PhysicalAddressEntity'
|
|
14
16
|
import {
|
|
17
|
+
electronicAddressEntityFrom,
|
|
18
|
+
electronicAddressFrom,
|
|
15
19
|
identityEntityFrom,
|
|
16
20
|
identityFrom,
|
|
17
21
|
isDidAuthConfig,
|
|
@@ -24,37 +28,51 @@ import {
|
|
|
24
28
|
partyRelationshipFrom,
|
|
25
29
|
partyTypeEntityFrom,
|
|
26
30
|
partyTypeFrom,
|
|
31
|
+
physicalAddressEntityFrom,
|
|
32
|
+
physicalAddressFrom,
|
|
27
33
|
} from '../utils/contact/MappingUtils'
|
|
28
34
|
import {
|
|
35
|
+
AddElectronicAddressArgs,
|
|
29
36
|
AddIdentityArgs,
|
|
30
|
-
GetIdentityArgs,
|
|
31
|
-
GetIdentitiesArgs,
|
|
32
|
-
GetPartyArgs,
|
|
33
|
-
RemoveIdentityArgs,
|
|
34
|
-
UpdateIdentityArgs,
|
|
35
|
-
GetPartiesArgs,
|
|
36
37
|
AddPartyArgs,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
AddPartyTypeArgs,
|
|
39
|
+
AddPhysicalAddressArgs,
|
|
40
|
+
AddRelationshipArgs,
|
|
40
41
|
ConnectionTypeEnum,
|
|
41
42
|
CorrelationIdentifierEnum,
|
|
42
|
-
|
|
43
|
+
ElectronicAddress,
|
|
44
|
+
GetElectronicAddressArgs,
|
|
45
|
+
GetElectronicAddressesArgs,
|
|
46
|
+
GetIdentitiesArgs,
|
|
47
|
+
GetIdentityArgs,
|
|
48
|
+
GetPartiesArgs,
|
|
49
|
+
GetPartyArgs,
|
|
50
|
+
GetPartyTypeArgs,
|
|
51
|
+
GetPartyTypesArgs,
|
|
52
|
+
GetPhysicalAddressArgs,
|
|
53
|
+
GetPhysicalAddressesArgs,
|
|
54
|
+
GetRelationshipArgs,
|
|
55
|
+
GetRelationshipsArgs,
|
|
43
56
|
Identity,
|
|
44
|
-
|
|
57
|
+
NonPersistedConnectionConfig,
|
|
58
|
+
NonPersistedContact,
|
|
59
|
+
Party,
|
|
45
60
|
PartyRelationship,
|
|
46
|
-
AddRelationshipArgs,
|
|
47
|
-
GetRelationshipArgs,
|
|
48
|
-
AddPartyTypeArgs,
|
|
49
61
|
PartyType,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
PartyTypeEnum,
|
|
63
|
+
PhysicalAddress,
|
|
64
|
+
RemoveElectronicAddressArgs,
|
|
65
|
+
RemoveIdentityArgs,
|
|
66
|
+
RemovePartyArgs,
|
|
53
67
|
RemovePartyTypeArgs,
|
|
54
|
-
|
|
68
|
+
RemovePhysicalAddressArgs,
|
|
69
|
+
RemoveRelationshipArgs,
|
|
70
|
+
UpdateElectronicAddressArgs,
|
|
71
|
+
UpdateIdentityArgs,
|
|
72
|
+
UpdatePartyArgs,
|
|
73
|
+
UpdatePartyTypeArgs,
|
|
74
|
+
UpdatePhysicalAddressArgs,
|
|
55
75
|
UpdateRelationshipArgs,
|
|
56
|
-
PartyTypeEnum,
|
|
57
|
-
NonPersistedContact,
|
|
58
76
|
} from '../types'
|
|
59
77
|
|
|
60
78
|
const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:contact-store')
|
|
@@ -67,7 +85,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
67
85
|
this.dbConnection = dbConnection
|
|
68
86
|
}
|
|
69
87
|
|
|
70
|
-
getParty = async (
|
|
88
|
+
getParty = async (args: GetPartyArgs): Promise<Party> => {
|
|
89
|
+
const { partyId } = args
|
|
71
90
|
const result: PartyEntity | null = await (await this.dbConnection).getRepository(PartyEntity).findOne({
|
|
72
91
|
where: { id: partyId },
|
|
73
92
|
})
|
|
@@ -80,9 +99,10 @@ export class ContactStore extends AbstractContactStore {
|
|
|
80
99
|
}
|
|
81
100
|
|
|
82
101
|
getParties = async (args?: GetPartiesArgs): Promise<Array<Party>> => {
|
|
102
|
+
const { filter } = args ?? {}
|
|
83
103
|
const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
|
|
84
104
|
const initialResult: Array<PartyEntity> = await partyRepository.find({
|
|
85
|
-
...(
|
|
105
|
+
...(filter && { where: filter }),
|
|
86
106
|
})
|
|
87
107
|
|
|
88
108
|
const result: Array<PartyEntity> = await partyRepository.find({
|
|
@@ -122,7 +142,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
122
142
|
return partyFrom(createdResult)
|
|
123
143
|
}
|
|
124
144
|
|
|
125
|
-
updateParty = async (
|
|
145
|
+
updateParty = async (args: UpdatePartyArgs): Promise<Party> => {
|
|
146
|
+
const { party } = args
|
|
126
147
|
const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
|
|
127
148
|
const result: PartyEntity | null = await partyRepository.findOne({
|
|
128
149
|
where: { id: party.id },
|
|
@@ -146,7 +167,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
146
167
|
return partyFrom(updatedResult)
|
|
147
168
|
}
|
|
148
169
|
|
|
149
|
-
removeParty = async (
|
|
170
|
+
removeParty = async (args: RemovePartyArgs): Promise<void> => {
|
|
171
|
+
const { partyId } = args
|
|
150
172
|
const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
|
|
151
173
|
debug('Removing party', partyId)
|
|
152
174
|
partyRepository
|
|
@@ -156,6 +178,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
156
178
|
await Promise.reject(Error(`Unable to find the party with id to remove: ${partyId}`))
|
|
157
179
|
} else {
|
|
158
180
|
await this.deleteIdentities(party.identities)
|
|
181
|
+
await this.deleteElectronicAddresses(party.electronicAddresses)
|
|
182
|
+
await this.deletePhysicalAddresses(party.physicalAddresses)
|
|
159
183
|
|
|
160
184
|
await partyRepository
|
|
161
185
|
.delete({ id: partyId })
|
|
@@ -170,7 +194,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
170
194
|
.catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)))
|
|
171
195
|
}
|
|
172
196
|
|
|
173
|
-
getIdentity = async (
|
|
197
|
+
getIdentity = async (args: GetIdentityArgs): Promise<Identity> => {
|
|
198
|
+
const { identityId } = args
|
|
174
199
|
const result: IdentityEntity | null = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
|
|
175
200
|
where: { id: identityId },
|
|
176
201
|
})
|
|
@@ -183,9 +208,10 @@ export class ContactStore extends AbstractContactStore {
|
|
|
183
208
|
}
|
|
184
209
|
|
|
185
210
|
getIdentities = async (args?: GetIdentitiesArgs): Promise<Array<Identity>> => {
|
|
211
|
+
const { filter } = args ?? {}
|
|
186
212
|
const identityRepository: Repository<IdentityEntity> = (await this.dbConnection).getRepository(IdentityEntity)
|
|
187
213
|
const initialResult: Array<IdentityEntity> = await identityRepository.find({
|
|
188
|
-
...(
|
|
214
|
+
...(filter && { where: filter }),
|
|
189
215
|
})
|
|
190
216
|
|
|
191
217
|
const result: Array<IdentityEntity> = await identityRepository.find({
|
|
@@ -197,7 +223,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
197
223
|
return result.map((identity: IdentityEntity) => identityFrom(identity))
|
|
198
224
|
}
|
|
199
225
|
|
|
200
|
-
addIdentity = async (
|
|
226
|
+
addIdentity = async (args: AddIdentityArgs): Promise<Identity> => {
|
|
227
|
+
const { identity, partyId } = args
|
|
201
228
|
const party: PartyEntity | null = await (await this.dbConnection).getRepository(PartyEntity).findOne({
|
|
202
229
|
where: { id: partyId },
|
|
203
230
|
})
|
|
@@ -226,7 +253,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
226
253
|
return identityFrom(result)
|
|
227
254
|
}
|
|
228
255
|
|
|
229
|
-
updateIdentity = async (
|
|
256
|
+
updateIdentity = async (args: UpdateIdentityArgs): Promise<Identity> => {
|
|
257
|
+
const { identity } = args
|
|
230
258
|
const identityRepository: Repository<IdentityEntity> = (await this.dbConnection).getRepository(IdentityEntity)
|
|
231
259
|
const result: IdentityEntity | null = await identityRepository.findOne({
|
|
232
260
|
where: { id: identity.id },
|
|
@@ -252,7 +280,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
252
280
|
return identityFrom(updatedResult)
|
|
253
281
|
}
|
|
254
282
|
|
|
255
|
-
removeIdentity = async (
|
|
283
|
+
removeIdentity = async (args: RemoveIdentityArgs): Promise<void> => {
|
|
284
|
+
const { identityId } = args
|
|
256
285
|
const identity: IdentityEntity | null = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
|
|
257
286
|
where: { id: identityId },
|
|
258
287
|
})
|
|
@@ -266,7 +295,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
266
295
|
await this.deleteIdentities([identity])
|
|
267
296
|
}
|
|
268
297
|
|
|
269
|
-
addRelationship = async (
|
|
298
|
+
addRelationship = async (args: AddRelationshipArgs): Promise<PartyRelationship> => {
|
|
299
|
+
const { leftId, rightId } = args
|
|
270
300
|
return this.assertRelationshipSides(leftId, rightId).then(async (): Promise<PartyRelationship> => {
|
|
271
301
|
const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({
|
|
272
302
|
leftId,
|
|
@@ -280,7 +310,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
280
310
|
})
|
|
281
311
|
}
|
|
282
312
|
|
|
283
|
-
getRelationship = async (
|
|
313
|
+
getRelationship = async (args: GetRelationshipArgs): Promise<PartyRelationship> => {
|
|
314
|
+
const { relationshipId } = args
|
|
284
315
|
const result: PartyRelationshipEntity | null = await (await this.dbConnection).getRepository(PartyRelationshipEntity).findOne({
|
|
285
316
|
where: { id: relationshipId },
|
|
286
317
|
})
|
|
@@ -293,9 +324,10 @@ export class ContactStore extends AbstractContactStore {
|
|
|
293
324
|
}
|
|
294
325
|
|
|
295
326
|
getRelationships = async (args?: GetRelationshipsArgs): Promise<Array<PartyRelationship>> => {
|
|
327
|
+
const { filter } = args ?? {}
|
|
296
328
|
const partyRelationshipRepository: Repository<PartyRelationshipEntity> = (await this.dbConnection).getRepository(PartyRelationshipEntity)
|
|
297
329
|
const initialResult: Array<PartyRelationshipEntity> = await partyRelationshipRepository.find({
|
|
298
|
-
...(
|
|
330
|
+
...(filter && { where: filter }),
|
|
299
331
|
})
|
|
300
332
|
|
|
301
333
|
const result: Array<PartyRelationshipEntity> = await partyRelationshipRepository.find({
|
|
@@ -307,7 +339,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
307
339
|
return result.map((partyRelationship: PartyRelationshipEntity) => partyRelationshipFrom(partyRelationship))
|
|
308
340
|
}
|
|
309
341
|
|
|
310
|
-
updateRelationship = async (
|
|
342
|
+
updateRelationship = async (args: UpdateRelationshipArgs): Promise<PartyRelationship> => {
|
|
343
|
+
const { relationship } = args
|
|
311
344
|
const partyRelationshipRepository: Repository<PartyRelationshipEntity> = (await this.dbConnection).getRepository(PartyRelationshipEntity)
|
|
312
345
|
const result: PartyRelationshipEntity | null = await partyRelationshipRepository.findOne({
|
|
313
346
|
where: { id: relationship.id },
|
|
@@ -325,7 +358,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
325
358
|
})
|
|
326
359
|
}
|
|
327
360
|
|
|
328
|
-
removeRelationship = async (
|
|
361
|
+
removeRelationship = async (args: RemoveRelationshipArgs): Promise<void> => {
|
|
362
|
+
const { relationshipId } = args
|
|
329
363
|
const partyRelationshipRepository: Repository<PartyRelationshipEntity> = (await this.dbConnection).getRepository(PartyRelationshipEntity)
|
|
330
364
|
const relationship: PartyRelationshipEntity | null = await partyRelationshipRepository.findOne({
|
|
331
365
|
where: { id: relationshipId },
|
|
@@ -348,7 +382,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
348
382
|
return partyTypeFrom(createdResult)
|
|
349
383
|
}
|
|
350
384
|
|
|
351
|
-
getPartyType = async (
|
|
385
|
+
getPartyType = async (args: GetPartyTypeArgs): Promise<PartyType> => {
|
|
386
|
+
const { partyTypeId } = args
|
|
352
387
|
const result: PartyTypeEntity | null = await (await this.dbConnection).getRepository(PartyTypeEntity).findOne({
|
|
353
388
|
where: { id: partyTypeId },
|
|
354
389
|
})
|
|
@@ -361,9 +396,10 @@ export class ContactStore extends AbstractContactStore {
|
|
|
361
396
|
}
|
|
362
397
|
|
|
363
398
|
getPartyTypes = async (args?: GetPartyTypesArgs): Promise<Array<PartyType>> => {
|
|
399
|
+
const { filter } = args ?? {}
|
|
364
400
|
const partyTypeRepository: Repository<PartyTypeEntity> = (await this.dbConnection).getRepository(PartyTypeEntity)
|
|
365
401
|
const initialResult: Array<PartyTypeEntity> = await partyTypeRepository.find({
|
|
366
|
-
...(
|
|
402
|
+
...(filter && { where: filter }),
|
|
367
403
|
})
|
|
368
404
|
|
|
369
405
|
const result: Array<PartyTypeEntity> = await partyTypeRepository.find({
|
|
@@ -375,7 +411,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
375
411
|
return result.map((partyType: PartyTypeEntity) => partyTypeFrom(partyType))
|
|
376
412
|
}
|
|
377
413
|
|
|
378
|
-
updatePartyType = async (
|
|
414
|
+
updatePartyType = async (args: UpdatePartyTypeArgs): Promise<PartyType> => {
|
|
415
|
+
const { partyType } = args
|
|
379
416
|
const partyTypeRepository: Repository<PartyTypeEntity> = (await this.dbConnection).getRepository(PartyTypeEntity)
|
|
380
417
|
const result: PartyTypeEntity | null = await partyTypeRepository.findOne({
|
|
381
418
|
where: { id: partyType.id },
|
|
@@ -391,7 +428,8 @@ export class ContactStore extends AbstractContactStore {
|
|
|
391
428
|
return partyTypeFrom(updatedResult)
|
|
392
429
|
}
|
|
393
430
|
|
|
394
|
-
removePartyType = async (
|
|
431
|
+
removePartyType = async (args: RemovePartyTypeArgs): Promise<void> => {
|
|
432
|
+
const { partyTypeId } = args
|
|
395
433
|
const parties: Array<PartyEntity> = await (await this.dbConnection).getRepository(PartyEntity).find({
|
|
396
434
|
where: {
|
|
397
435
|
partyType: {
|
|
@@ -418,6 +456,170 @@ export class ContactStore extends AbstractContactStore {
|
|
|
418
456
|
await partyTypeRepository.delete(partyTypeId)
|
|
419
457
|
}
|
|
420
458
|
|
|
459
|
+
getElectronicAddress = async (args: GetElectronicAddressArgs): Promise<ElectronicAddress> => {
|
|
460
|
+
const { electronicAddressId } = args
|
|
461
|
+
const result: ElectronicAddressEntity | null = await (await this.dbConnection).getRepository(ElectronicAddressEntity).findOne({
|
|
462
|
+
where: { id: electronicAddressId },
|
|
463
|
+
})
|
|
464
|
+
|
|
465
|
+
if (!result) {
|
|
466
|
+
return Promise.reject(Error(`No electronic address found for id: ${electronicAddressId}`))
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return electronicAddressFrom(result)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
getElectronicAddresses = async (args?: GetElectronicAddressesArgs): Promise<Array<ElectronicAddress>> => {
|
|
473
|
+
const { filter } = args ?? {}
|
|
474
|
+
const electronicAddressRepository: Repository<ElectronicAddressEntity> = (await this.dbConnection).getRepository(ElectronicAddressEntity)
|
|
475
|
+
const initialResult: Array<ElectronicAddressEntity> = await electronicAddressRepository.find({
|
|
476
|
+
...(filter && { where: filter }),
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
const result: Array<ElectronicAddressEntity> = await electronicAddressRepository.find({
|
|
480
|
+
where: {
|
|
481
|
+
id: In(initialResult.map((electronicAddress: ElectronicAddressEntity) => electronicAddress.id)),
|
|
482
|
+
},
|
|
483
|
+
})
|
|
484
|
+
|
|
485
|
+
return result.map((electronicAddress: ElectronicAddressEntity) => electronicAddressFrom(electronicAddress))
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
addElectronicAddress = async (args: AddElectronicAddressArgs): Promise<ElectronicAddress> => {
|
|
489
|
+
const { electronicAddress, partyId } = args
|
|
490
|
+
const party: PartyEntity | null = await (await this.dbConnection).getRepository(PartyEntity).findOne({
|
|
491
|
+
where: { id: partyId },
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
if (!party) {
|
|
495
|
+
return Promise.reject(Error(`No party found for id: ${partyId}`))
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const electronicAddressEntity: ElectronicAddressEntity = electronicAddressEntityFrom(electronicAddress)
|
|
499
|
+
electronicAddressEntity.party = party
|
|
500
|
+
debug('Adding electronic address', electronicAddress)
|
|
501
|
+
const result: ElectronicAddressEntity = await (await this.dbConnection).getRepository(ElectronicAddressEntity).save(electronicAddressEntity, {
|
|
502
|
+
transaction: true,
|
|
503
|
+
})
|
|
504
|
+
|
|
505
|
+
return electronicAddressFrom(result)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
updateElectronicAddress = async (args: UpdateElectronicAddressArgs): Promise<ElectronicAddress> => {
|
|
509
|
+
const { electronicAddress } = args
|
|
510
|
+
const electronicAddressRepository: Repository<ElectronicAddressEntity> = (await this.dbConnection).getRepository(ElectronicAddressEntity)
|
|
511
|
+
const result: ElectronicAddressEntity | null = await electronicAddressRepository.findOne({
|
|
512
|
+
where: { id: electronicAddress.id },
|
|
513
|
+
})
|
|
514
|
+
|
|
515
|
+
if (!result) {
|
|
516
|
+
return Promise.reject(Error(`No electronic address found for id: ${electronicAddress.id}`))
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
debug('Updating electronic address', electronicAddress)
|
|
520
|
+
const updatedResult: ElectronicAddressEntity = await electronicAddressRepository.save(electronicAddress, { transaction: true })
|
|
521
|
+
|
|
522
|
+
return electronicAddressFrom(updatedResult)
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
removeElectronicAddress = async (args: RemoveElectronicAddressArgs): Promise<void> => {
|
|
526
|
+
const { electronicAddressId } = args
|
|
527
|
+
const electronicAddressRepository: Repository<ElectronicAddressEntity> = (await this.dbConnection).getRepository(ElectronicAddressEntity)
|
|
528
|
+
const electronicAddress: ElectronicAddressEntity | null = await electronicAddressRepository.findOne({
|
|
529
|
+
where: { id: electronicAddressId },
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
if (!electronicAddress) {
|
|
533
|
+
return Promise.reject(Error(`No electronic address found for id: ${electronicAddressId}`))
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
debug('Removing electronic address', electronicAddressId)
|
|
537
|
+
|
|
538
|
+
await electronicAddressRepository.delete(electronicAddressId)
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
getPhysicalAddress = async (args: GetPhysicalAddressArgs): Promise<PhysicalAddress> => {
|
|
542
|
+
const { physicalAddressId } = args
|
|
543
|
+
const result: PhysicalAddressEntity | null = await (await this.dbConnection).getRepository(PhysicalAddressEntity).findOne({
|
|
544
|
+
where: { id: physicalAddressId },
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
if (!result) {
|
|
548
|
+
return Promise.reject(Error(`No physical address found for id: ${physicalAddressId}`))
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
return physicalAddressFrom(result)
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
getPhysicalAddresses = async (args?: GetPhysicalAddressesArgs): Promise<Array<PhysicalAddress>> => {
|
|
555
|
+
const { filter } = args ?? {}
|
|
556
|
+
const physicalAddressRepository: Repository<PhysicalAddressEntity> = (await this.dbConnection).getRepository(PhysicalAddressEntity)
|
|
557
|
+
const initialResult: Array<PhysicalAddressEntity> = await physicalAddressRepository.find({
|
|
558
|
+
...(filter && { where: filter }),
|
|
559
|
+
})
|
|
560
|
+
|
|
561
|
+
const result: Array<PhysicalAddressEntity> = await physicalAddressRepository.find({
|
|
562
|
+
where: {
|
|
563
|
+
id: In(initialResult.map((physicalAddress: PhysicalAddressEntity) => physicalAddress.id)),
|
|
564
|
+
},
|
|
565
|
+
})
|
|
566
|
+
|
|
567
|
+
return result.map((physicalAddress: PhysicalAddressEntity) => physicalAddressFrom(physicalAddress))
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
addPhysicalAddress = async (args: AddPhysicalAddressArgs): Promise<PhysicalAddress> => {
|
|
571
|
+
const { physicalAddress, partyId } = args
|
|
572
|
+
const party: PartyEntity | null = await (await this.dbConnection).getRepository(PartyEntity).findOne({
|
|
573
|
+
where: { id: partyId },
|
|
574
|
+
})
|
|
575
|
+
|
|
576
|
+
if (!party) {
|
|
577
|
+
return Promise.reject(Error(`No party found for id: ${partyId}`))
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const physicalAddressEntity: PhysicalAddressEntity = physicalAddressEntityFrom(physicalAddress)
|
|
581
|
+
physicalAddressEntity.party = party
|
|
582
|
+
debug('Adding physical address', physicalAddress)
|
|
583
|
+
const result: PhysicalAddressEntity = await (await this.dbConnection).getRepository(PhysicalAddressEntity).save(physicalAddressEntity, {
|
|
584
|
+
transaction: true,
|
|
585
|
+
})
|
|
586
|
+
|
|
587
|
+
return physicalAddressFrom(result)
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
updatePhysicalAddress = async (args: UpdatePhysicalAddressArgs): Promise<PhysicalAddress> => {
|
|
591
|
+
const { physicalAddress } = args
|
|
592
|
+
const physicalAddressRepository: Repository<PhysicalAddressEntity> = (await this.dbConnection).getRepository(PhysicalAddressEntity)
|
|
593
|
+
const result: PhysicalAddressEntity | null = await physicalAddressRepository.findOne({
|
|
594
|
+
where: { id: physicalAddress.id },
|
|
595
|
+
})
|
|
596
|
+
|
|
597
|
+
if (!result) {
|
|
598
|
+
return Promise.reject(Error(`No physical address found for id: ${physicalAddress.id}`))
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
debug('Updating physical address', physicalAddress)
|
|
602
|
+
const updatedResult: PhysicalAddressEntity = await physicalAddressRepository.save(physicalAddress, { transaction: true })
|
|
603
|
+
|
|
604
|
+
return physicalAddressFrom(updatedResult)
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
removePhysicalAddress = async (args: RemovePhysicalAddressArgs): Promise<void> => {
|
|
608
|
+
const { physicalAddressId } = args
|
|
609
|
+
const physicalAddressRepository: Repository<PhysicalAddressEntity> = (await this.dbConnection).getRepository(PhysicalAddressEntity)
|
|
610
|
+
const physicalAddress: PhysicalAddressEntity | null = await physicalAddressRepository.findOne({
|
|
611
|
+
where: { id: physicalAddressId },
|
|
612
|
+
})
|
|
613
|
+
|
|
614
|
+
if (!physicalAddress) {
|
|
615
|
+
return Promise.reject(Error(`No physical address found for id: ${physicalAddressId}`))
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
debug('Removing physical address', physicalAddressId)
|
|
619
|
+
|
|
620
|
+
await physicalAddressRepository.delete(physicalAddressId)
|
|
621
|
+
}
|
|
622
|
+
|
|
421
623
|
private hasCorrectConnectionConfig(type: ConnectionTypeEnum, config: NonPersistedConnectionConfig): boolean {
|
|
422
624
|
switch (type) {
|
|
423
625
|
case ConnectionTypeEnum.OPENID_CONNECT:
|
|
@@ -443,40 +645,58 @@ export class ContactStore extends AbstractContactStore {
|
|
|
443
645
|
private async deleteIdentities(identities: Array<IdentityEntity>): Promise<void> {
|
|
444
646
|
debug('Removing identities', identities)
|
|
445
647
|
|
|
648
|
+
const connection: DataSource = await this.dbConnection
|
|
649
|
+
const correlationIdentifierRepository: Repository<CorrelationIdentifierEntity> = connection.getRepository(CorrelationIdentifierEntity)
|
|
650
|
+
const baseConfigRepository: Repository<BaseConfigEntity> = connection.getRepository(BaseConfigEntity)
|
|
651
|
+
const connectionRepository: Repository<ConnectionEntity> = connection.getRepository(ConnectionEntity)
|
|
652
|
+
const identityMetadataItemRepository: Repository<IdentityMetadataItemEntity> = connection.getRepository(IdentityMetadataItemEntity)
|
|
653
|
+
const identityRepository: Repository<IdentityEntity> = connection.getRepository(IdentityEntity)
|
|
654
|
+
|
|
446
655
|
identities.map(async (identity: IdentityEntity): Promise<void> => {
|
|
447
|
-
await
|
|
448
|
-
await this.dbConnection
|
|
449
|
-
)
|
|
450
|
-
.getRepository(CorrelationIdentifierEntity)
|
|
656
|
+
await correlationIdentifierRepository
|
|
451
657
|
.delete(identity.identifier.id)
|
|
452
|
-
.catch((error) => Promise.reject(Error(`Unable to remove identity.identifier with id
|
|
658
|
+
.catch((error) => Promise.reject(Error(`Unable to remove identity.identifier with id ${identity.identifier.id}. ${error}`)))
|
|
453
659
|
|
|
454
660
|
if (identity.connection) {
|
|
455
|
-
await
|
|
456
|
-
|
|
457
|
-
await (
|
|
458
|
-
await this.dbConnection
|
|
459
|
-
)
|
|
460
|
-
.getRepository(ConnectionEntity)
|
|
661
|
+
await baseConfigRepository.delete(identity.connection.config.id)
|
|
662
|
+
await connectionRepository
|
|
461
663
|
.delete(identity.connection.id)
|
|
462
|
-
.catch((error) => Promise.reject(Error(`Unable to remove identity.connection with id. ${error}`)))
|
|
664
|
+
.catch((error) => Promise.reject(Error(`Unable to remove identity.connection with id ${identity.connection?.id}. ${error}`)))
|
|
463
665
|
}
|
|
464
666
|
|
|
465
667
|
if (identity.metadata) {
|
|
466
668
|
identity.metadata.map(async (metadataItem: IdentityMetadataItemEntity): Promise<void> => {
|
|
467
|
-
await
|
|
468
|
-
await this.dbConnection
|
|
469
|
-
)
|
|
470
|
-
.getRepository(IdentityMetadataItemEntity)
|
|
669
|
+
await identityMetadataItemRepository
|
|
471
670
|
.delete(metadataItem.id)
|
|
472
|
-
.catch((error) => Promise.reject(Error(`Unable to remove metadataItem
|
|
671
|
+
.catch((error) => Promise.reject(Error(`Unable to remove identity.metadataItem with id ${metadataItem.id}. ${error}`)))
|
|
473
672
|
})
|
|
474
673
|
}
|
|
475
674
|
|
|
476
|
-
|
|
477
|
-
.getRepository(IdentityEntity)
|
|
675
|
+
await identityRepository
|
|
478
676
|
.delete(identity.id)
|
|
479
|
-
.catch((error) => Promise.reject(Error(`Unable to remove
|
|
677
|
+
.catch((error) => Promise.reject(Error(`Unable to remove identity with id ${identity.id}. ${error}`)))
|
|
678
|
+
})
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
private async deleteElectronicAddresses(electronicAddresses: Array<ElectronicAddressEntity>): Promise<void> {
|
|
682
|
+
debug('Removing electronic addresses', electronicAddresses)
|
|
683
|
+
|
|
684
|
+
const electronicAddressRepository: Repository<ElectronicAddressEntity> = (await this.dbConnection).getRepository(ElectronicAddressEntity)
|
|
685
|
+
electronicAddresses.map(async (electronicAddress: ElectronicAddressEntity): Promise<void> => {
|
|
686
|
+
await electronicAddressRepository
|
|
687
|
+
.delete(electronicAddress.id)
|
|
688
|
+
.catch((error) => Promise.reject(Error(`Unable to remove electronic address with id ${electronicAddress.id}. ${error}`)))
|
|
689
|
+
})
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
private async deletePhysicalAddresses(physicalAddresses: Array<PhysicalAddressEntity>): Promise<void> {
|
|
693
|
+
debug('Removing physical addresses', physicalAddresses)
|
|
694
|
+
|
|
695
|
+
const physicalAddressRepository: Repository<PhysicalAddressEntity> = (await this.dbConnection).getRepository(PhysicalAddressEntity)
|
|
696
|
+
physicalAddresses.map(async (physicalAddress: PhysicalAddressEntity): Promise<void> => {
|
|
697
|
+
await physicalAddressRepository
|
|
698
|
+
.delete(physicalAddress.id)
|
|
699
|
+
.catch((error) => Promise.reject(Error(`Unable to remove physical address with id ${physicalAddress.id}. ${error}`)))
|
|
480
700
|
})
|
|
481
701
|
}
|
|
482
702
|
|
|
@@ -73,7 +73,7 @@ export class IdentityEntity extends BaseEntity {
|
|
|
73
73
|
party!: PartyEntity
|
|
74
74
|
|
|
75
75
|
@Column({ name: 'partyId', nullable: true })
|
|
76
|
-
partyId
|
|
76
|
+
partyId?: string
|
|
77
77
|
|
|
78
78
|
// By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
|
|
79
79
|
@BeforeInsert()
|
|
@@ -20,13 +20,14 @@ import { BaseContactEntity } from './BaseContactEntity'
|
|
|
20
20
|
import { PartyRelationshipEntity } from './PartyRelationshipEntity'
|
|
21
21
|
import { getConstraint } from '../../utils/ValidatorUtils'
|
|
22
22
|
import { ElectronicAddressEntity } from './ElectronicAddressEntity'
|
|
23
|
+
import { PhysicalAddressEntity } from './PhysicalAddressEntity'
|
|
23
24
|
|
|
24
25
|
@Entity('Party')
|
|
25
26
|
export class PartyEntity extends BaseEntity {
|
|
26
27
|
@PrimaryGeneratedColumn('uuid')
|
|
27
28
|
id!: string
|
|
28
29
|
|
|
29
|
-
@Column({ name: 'uri', length: 255 })
|
|
30
|
+
@Column({ name: 'uri', length: 255, nullable: true })
|
|
30
31
|
uri?: string
|
|
31
32
|
|
|
32
33
|
@OneToMany(() => IdentityEntity, (identity: IdentityEntity) => identity.party, {
|
|
@@ -47,6 +48,15 @@ export class PartyEntity extends BaseEntity {
|
|
|
47
48
|
@JoinColumn({ name: 'electronic_address_id' })
|
|
48
49
|
electronicAddresses!: Array<ElectronicAddressEntity>
|
|
49
50
|
|
|
51
|
+
@OneToMany(() => PhysicalAddressEntity, (physicalAddress: PhysicalAddressEntity) => physicalAddress.party, {
|
|
52
|
+
cascade: true,
|
|
53
|
+
onDelete: 'CASCADE',
|
|
54
|
+
eager: true,
|
|
55
|
+
nullable: false,
|
|
56
|
+
})
|
|
57
|
+
@JoinColumn({ name: 'physical_address_id' })
|
|
58
|
+
physicalAddresses!: Array<PhysicalAddressEntity>
|
|
59
|
+
|
|
50
60
|
@ManyToOne(() => PartyTypeEntity, (contactType: PartyTypeEntity) => contactType.parties, {
|
|
51
61
|
cascade: true,
|
|
52
62
|
nullable: false,
|