@sphereon/ssi-sdk.data-store 0.15.2-next.6 → 0.15.2-next.77
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 +21 -11
- package/dist/contact/AbstractContactStore.d.ts.map +1 -1
- package/dist/contact/AbstractContactStore.js.map +1 -1
- package/dist/contact/ContactStore.d.ts +25 -21
- package/dist/contact/ContactStore.d.ts.map +1 -1
- package/dist/contact/ContactStore.js +216 -136
- package/dist/contact/ContactStore.js.map +1 -1
- package/dist/entities/contact/BaseConfigEntity.d.ts +2 -0
- package/dist/entities/contact/BaseConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/BaseConfigEntity.js +10 -2
- package/dist/entities/contact/BaseConfigEntity.js.map +1 -1
- package/dist/entities/contact/BaseContactEntity.d.ts +10 -0
- package/dist/entities/contact/BaseContactEntity.d.ts.map +1 -0
- package/dist/entities/contact/BaseContactEntity.js +54 -0
- package/dist/entities/contact/BaseContactEntity.js.map +1 -0
- package/dist/entities/contact/ConnectionEntity.d.ts +1 -2
- package/dist/entities/contact/ConnectionEntity.d.ts.map +1 -1
- package/dist/entities/contact/ConnectionEntity.js +2 -21
- package/dist/entities/contact/ConnectionEntity.js.map +1 -1
- package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +2 -3
- package/dist/entities/contact/CorrelationIdentifierEntity.d.ts.map +1 -1
- package/dist/entities/contact/CorrelationIdentifierEntity.js +8 -11
- package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -1
- package/dist/entities/contact/DidAuthConfigEntity.d.ts +0 -4
- package/dist/entities/contact/DidAuthConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/DidAuthConfigEntity.js +1 -17
- package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -1
- package/dist/entities/contact/ElectronicAddressEntity.d.ts +14 -0
- package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -0
- package/dist/entities/contact/ElectronicAddressEntity.js +92 -0
- package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -0
- package/dist/entities/contact/IdentityEntity.d.ts +5 -6
- package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
- package/dist/entities/contact/IdentityEntity.js +15 -20
- package/dist/entities/contact/IdentityEntity.js.map +1 -1
- package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +1 -3
- package/dist/entities/contact/IdentityMetadataItemEntity.d.ts.map +1 -1
- package/dist/entities/contact/IdentityMetadataItemEntity.js +7 -10
- package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -1
- package/dist/entities/contact/NaturalPersonEntity.d.ts +9 -0
- package/dist/entities/contact/NaturalPersonEntity.d.ts.map +1 -0
- package/dist/entities/contact/NaturalPersonEntity.js +72 -0
- package/dist/entities/contact/NaturalPersonEntity.js.map +1 -0
- package/dist/entities/contact/OpenIdConfigEntity.d.ts +0 -4
- package/dist/entities/contact/OpenIdConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/OpenIdConfigEntity.js +1 -22
- package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -1
- package/dist/entities/contact/OrganizationEntity.d.ts +9 -0
- package/dist/entities/contact/OrganizationEntity.d.ts.map +1 -0
- package/dist/entities/contact/OrganizationEntity.js +67 -0
- package/dist/entities/contact/OrganizationEntity.js.map +1 -0
- package/dist/entities/contact/PartyEntity.d.ts +21 -0
- package/dist/entities/contact/PartyEntity.d.ts.map +1 -0
- package/dist/entities/contact/PartyEntity.js +155 -0
- package/dist/entities/contact/PartyEntity.js.map +1 -0
- package/dist/entities/contact/PartyRelationshipEntity.d.ts +13 -0
- package/dist/entities/contact/PartyRelationshipEntity.d.ts.map +1 -0
- package/dist/entities/contact/PartyRelationshipEntity.js +95 -0
- package/dist/entities/contact/PartyRelationshipEntity.js.map +1 -0
- package/dist/entities/contact/PartyTypeEntity.d.ts +15 -0
- package/dist/entities/contact/PartyTypeEntity.d.ts.map +1 -0
- package/dist/entities/contact/{ContactEntity.js → PartyTypeEntity.js} +35 -36
- package/dist/entities/contact/PartyTypeEntity.js.map +1 -0
- package/dist/entities/statusList2021/StatusList2021Entity.d.ts +19 -0
- package/dist/entities/statusList2021/StatusList2021Entity.d.ts.map +1 -0
- package/dist/entities/statusList2021/StatusList2021Entity.js +115 -0
- package/dist/entities/statusList2021/StatusList2021Entity.js.map +1 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts +11 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts.map +1 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.js +51 -0
- package/dist/entities/statusList2021/StatusList2021EntryEntity.js.map +1 -0
- package/dist/index.d.ts +20 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/dist/migrations/generic/1-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/generic/1-CreateContacts.js +36 -32
- package/dist/migrations/generic/1-CreateContacts.js.map +1 -1
- package/dist/migrations/generic/2-CreateContacts.d.ts +7 -0
- package/dist/migrations/generic/2-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/generic/2-CreateContacts.js +76 -0
- package/dist/migrations/generic/2-CreateContacts.js.map +1 -0
- package/dist/migrations/generic/{1-CreateIssuanceBranding.d.ts → 2-CreateIssuanceBranding.d.ts} +1 -1
- package/dist/migrations/generic/2-CreateIssuanceBranding.d.ts.map +1 -0
- package/dist/migrations/generic/2-CreateIssuanceBranding.js +76 -0
- package/dist/migrations/generic/2-CreateIssuanceBranding.js.map +1 -0
- package/dist/migrations/generic/3-CreateStatusList.d.ts +7 -0
- package/dist/migrations/generic/3-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/generic/{1-CreateIssuanceBranding.js → 3-CreateStatusList.js} +11 -11
- package/dist/migrations/generic/3-CreateStatusList.js.map +1 -0
- package/dist/migrations/generic/index.d.ts +5 -0
- package/dist/migrations/generic/index.d.ts.map +1 -1
- package/dist/migrations/generic/index.js +10 -3
- package/dist/migrations/generic/index.js.map +1 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts +2 -1
- package/dist/migrations/internal-migrations-ormconfig.d.ts.map +1 -1
- package/dist/migrations/internal-migrations-ormconfig.js +0 -2
- package/dist/migrations/internal-migrations-ormconfig.js.map +1 -1
- package/dist/migrations/postgres/1659463079428-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/postgres/1659463079428-CreateContacts.js +4 -2
- package/dist/migrations/postgres/1659463079428-CreateContacts.js.map +1 -1
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.d.ts.map +1 -1
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +2 -0
- package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js.map +1 -1
- package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts +7 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.js +69 -0
- package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts +7 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js +32 -0
- package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js.map +1 -0
- package/dist/migrations/postgres/uuid.d.ts +3 -0
- package/dist/migrations/postgres/uuid.d.ts.map +1 -0
- package/dist/migrations/postgres/uuid.js +25 -0
- package/dist/migrations/postgres/uuid.js.map +1 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts +7 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js +108 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts +7 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts.map +1 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.js +32 -0
- package/dist/migrations/sqlite/1693866470000-CreateStatusList.js.map +1 -0
- package/dist/statusList/IStatusListStore.d.ts +20 -0
- package/dist/statusList/IStatusListStore.d.ts.map +1 -0
- package/dist/statusList/IStatusListStore.js +3 -0
- package/dist/statusList/IStatusListStore.js.map +1 -0
- package/dist/statusList/StatusListStore.d.ts +36 -0
- package/dist/statusList/StatusListStore.d.ts.map +1 -0
- package/dist/statusList/StatusListStore.js +213 -0
- package/dist/statusList/StatusListStore.js.map +1 -0
- package/dist/types/contact/IAbstractContactStore.d.ts +70 -36
- package/dist/types/contact/IAbstractContactStore.d.ts.map +1 -1
- package/dist/types/contact/contact.d.ts +139 -56
- package/dist/types/contact/contact.d.ts.map +1 -1
- package/dist/types/contact/contact.js +6 -1
- package/dist/types/contact/contact.js.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/statusList/IAbstractStatusListStore.d.ts +38 -0
- package/dist/types/statusList/IAbstractStatusListStore.d.ts.map +1 -0
- package/dist/types/statusList/IAbstractStatusListStore.js +3 -0
- package/dist/types/statusList/IAbstractStatusListStore.js.map +1 -0
- package/dist/types/statusList/statusList.d.ts +25 -0
- package/dist/types/statusList/statusList.d.ts.map +1 -0
- package/dist/types/statusList/statusList.js +3 -0
- package/dist/types/statusList/statusList.js.map +1 -0
- package/dist/types/validation/validation.d.ts +4 -0
- package/dist/types/validation/validation.d.ts.map +1 -0
- package/dist/types/validation/validation.js +3 -0
- package/dist/types/validation/validation.js.map +1 -0
- package/dist/utils/ValidatorUtils.d.ts +4 -0
- package/dist/utils/ValidatorUtils.d.ts.map +1 -0
- package/dist/utils/ValidatorUtils.js +13 -0
- package/dist/utils/ValidatorUtils.js.map +1 -0
- package/dist/utils/contact/MappingUtils.d.ts +47 -0
- package/dist/utils/contact/MappingUtils.d.ts.map +1 -0
- package/dist/utils/contact/MappingUtils.js +291 -0
- package/dist/utils/contact/MappingUtils.js.map +1 -0
- package/package.json +5 -4
- package/src/__tests__/contact.entities.test.ts +1457 -195
- package/src/__tests__/contact.store.test.ts +1302 -266
- package/src/contact/AbstractContactStore.ts +44 -22
- package/src/contact/ContactStore.ts +328 -204
- package/src/entities/contact/BaseConfigEntity.ts +10 -2
- package/src/entities/contact/BaseContactEntity.ts +30 -0
- package/src/entities/contact/ConnectionEntity.ts +4 -23
- package/src/entities/contact/CorrelationIdentifierEntity.ts +9 -13
- package/src/entities/contact/DidAuthConfigEntity.ts +1 -18
- package/src/entities/contact/ElectronicAddressEntity.ts +60 -0
- package/src/entities/contact/IdentityEntity.ts +18 -25
- package/src/entities/contact/IdentityMetadataItemEntity.ts +8 -12
- package/src/entities/contact/NaturalPersonEntity.ts +38 -0
- package/src/entities/contact/OpenIdConfigEntity.ts +1 -23
- package/src/entities/contact/OrganizationEntity.ts +34 -0
- package/src/entities/contact/PartyEntity.ts +118 -0
- package/src/entities/contact/PartyRelationshipEntity.ts +61 -0
- package/src/entities/contact/PartyTypeEntity.ts +59 -0
- package/src/entities/statusList2021/StatusList2021Entity.ts +95 -0
- package/src/entities/statusList2021/StatusList2021EntryEntity.ts +29 -0
- package/src/index.ts +36 -17
- package/src/migrations/generic/1-CreateContacts.ts +46 -36
- package/src/migrations/generic/2-CreateContacts.ts +64 -0
- package/src/migrations/generic/2-CreateIssuanceBranding.ts +62 -0
- package/src/migrations/generic/{1-CreateIssuanceBranding.ts → 3-CreateStatusList.ts} +9 -9
- package/src/migrations/generic/index.ts +11 -2
- package/src/migrations/internal-migrations-ormconfig.ts +2 -4
- package/src/migrations/postgres/1659463079428-CreateContacts.ts +4 -2
- package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +2 -0
- package/src/migrations/postgres/1690925872592-CreateContacts.ts +94 -0
- package/src/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.ts +24 -0
- package/src/migrations/postgres/uuid.ts +12 -0
- package/src/migrations/sqlite/1690925872693-CreateContacts.ts +163 -0
- package/src/migrations/sqlite/1693866470000-CreateStatusList.ts +24 -0
- package/src/statusList/IStatusListStore.ts +44 -0
- package/src/statusList/StatusListStore.ts +237 -0
- package/src/types/contact/IAbstractContactStore.ts +84 -27
- package/src/types/contact/contact.ts +144 -50
- package/src/types/index.ts +4 -0
- package/src/types/statusList/IAbstractStatusListStore.ts +47 -0
- package/src/types/statusList/statusList.ts +39 -0
- package/src/types/validation/validation.ts +3 -0
- package/src/utils/ValidatorUtils.ts +10 -0
- package/src/utils/contact/MappingUtils.ts +344 -0
- package/dist/entities/contact/ContactEntity.d.ts +0 -16
- package/dist/entities/contact/ContactEntity.d.ts.map +0 -1
- package/dist/entities/contact/ContactEntity.js.map +0 -1
- package/dist/migrations/generic/1-CreateIssuanceBranding.d.ts.map +0 -1
- package/dist/migrations/generic/1-CreateIssuanceBranding.js.map +0 -1
- package/src/entities/contact/ContactEntity.ts +0 -74
|
@@ -1,40 +1,62 @@
|
|
|
1
|
-
import Debug from 'debug'
|
|
2
1
|
import { OrPromise } from '@sphereon/ssi-types'
|
|
2
|
+
import { DataSource, In, Repository } from 'typeorm'
|
|
3
|
+
import Debug from 'debug'
|
|
3
4
|
import { AbstractContactStore } from './AbstractContactStore'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
IGetIdentityArgs,
|
|
7
|
-
IGetIdentitiesArgs,
|
|
8
|
-
IGetContactArgs,
|
|
9
|
-
IRemoveIdentityArgs,
|
|
10
|
-
IUpdateIdentityArgs,
|
|
11
|
-
IGetContactsArgs,
|
|
12
|
-
IAddContactArgs,
|
|
13
|
-
IUpdateContactArgs,
|
|
14
|
-
IRemoveContactArgs,
|
|
15
|
-
BasicConnectionConfig,
|
|
16
|
-
ConnectionConfig,
|
|
17
|
-
ConnectionTypeEnum,
|
|
18
|
-
CorrelationIdentifierEnum,
|
|
19
|
-
IConnection,
|
|
20
|
-
IContact,
|
|
21
|
-
ICorrelationIdentifier,
|
|
22
|
-
IDidAuthConfig,
|
|
23
|
-
IIdentity,
|
|
24
|
-
IMetadataItem,
|
|
25
|
-
IOpenIdConfig,
|
|
26
|
-
} from '../types'
|
|
27
|
-
import { ContactEntity, contactEntityFrom } from '../entities/contact/ContactEntity'
|
|
28
|
-
import { IdentityEntity, identityEntityFrom } from '../entities/contact/IdentityEntity'
|
|
5
|
+
import { PartyEntity } from '../entities/contact/PartyEntity'
|
|
6
|
+
import { IdentityEntity } from '../entities/contact/IdentityEntity'
|
|
29
7
|
import { IdentityMetadataItemEntity } from '../entities/contact/IdentityMetadataItemEntity'
|
|
30
8
|
import { CorrelationIdentifierEntity } from '../entities/contact/CorrelationIdentifierEntity'
|
|
31
9
|
import { ConnectionEntity } from '../entities/contact/ConnectionEntity'
|
|
32
10
|
import { BaseConfigEntity } from '../entities/contact/BaseConfigEntity'
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
11
|
+
import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity'
|
|
12
|
+
import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity'
|
|
13
|
+
import {
|
|
14
|
+
identityEntityFrom,
|
|
15
|
+
identityFrom,
|
|
16
|
+
isDidAuthConfig,
|
|
17
|
+
isNaturalPerson,
|
|
18
|
+
isOpenIdConfig,
|
|
19
|
+
isOrganization,
|
|
20
|
+
partyEntityFrom,
|
|
21
|
+
partyFrom,
|
|
22
|
+
partyRelationshipEntityFrom,
|
|
23
|
+
partyRelationshipFrom,
|
|
24
|
+
partyTypeEntityFrom,
|
|
25
|
+
partyTypeFrom,
|
|
26
|
+
} from '../utils/contact/MappingUtils'
|
|
27
|
+
import {
|
|
28
|
+
AddIdentityArgs,
|
|
29
|
+
GetIdentityArgs,
|
|
30
|
+
GetIdentitiesArgs,
|
|
31
|
+
GetPartyArgs,
|
|
32
|
+
RemoveIdentityArgs,
|
|
33
|
+
UpdateIdentityArgs,
|
|
34
|
+
GetPartiesArgs,
|
|
35
|
+
AddPartyArgs,
|
|
36
|
+
UpdatePartyArgs,
|
|
37
|
+
RemovePartyArgs,
|
|
38
|
+
NonPersistedConnectionConfig,
|
|
39
|
+
ConnectionTypeEnum,
|
|
40
|
+
CorrelationIdentifierEnum,
|
|
41
|
+
Party,
|
|
42
|
+
Identity,
|
|
43
|
+
RemoveRelationshipArgs,
|
|
44
|
+
PartyRelationship,
|
|
45
|
+
AddRelationshipArgs,
|
|
46
|
+
GetRelationshipArgs,
|
|
47
|
+
AddPartyTypeArgs,
|
|
48
|
+
PartyType,
|
|
49
|
+
GetPartyTypeArgs,
|
|
50
|
+
GetPartyTypesArgs,
|
|
51
|
+
UpdatePartyTypeArgs,
|
|
52
|
+
RemovePartyTypeArgs,
|
|
53
|
+
GetRelationshipsArgs,
|
|
54
|
+
UpdateRelationshipArgs,
|
|
55
|
+
PartyTypeEnum,
|
|
56
|
+
NonPersistedContact,
|
|
57
|
+
} from '../types'
|
|
36
58
|
|
|
37
|
-
const debug = Debug('sphereon:ssi-sdk:contact-store')
|
|
59
|
+
const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:contact-store')
|
|
38
60
|
|
|
39
61
|
export class ContactStore extends AbstractContactStore {
|
|
40
62
|
private readonly dbConnection: OrPromise<DataSource>
|
|
@@ -44,41 +66,40 @@ export class ContactStore extends AbstractContactStore {
|
|
|
44
66
|
this.dbConnection = dbConnection
|
|
45
67
|
}
|
|
46
68
|
|
|
47
|
-
|
|
48
|
-
const result = await (await this.dbConnection).getRepository(
|
|
49
|
-
where: { id:
|
|
69
|
+
getParty = async ({ partyId }: GetPartyArgs): Promise<Party> => {
|
|
70
|
+
const result: PartyEntity | null = await (await this.dbConnection).getRepository(PartyEntity).findOne({
|
|
71
|
+
where: { id: partyId },
|
|
50
72
|
})
|
|
51
73
|
|
|
52
74
|
if (!result) {
|
|
53
|
-
return Promise.reject(Error(`No
|
|
75
|
+
return Promise.reject(Error(`No party found for id: ${partyId}`))
|
|
54
76
|
}
|
|
55
77
|
|
|
56
|
-
return
|
|
78
|
+
return partyFrom(result)
|
|
57
79
|
}
|
|
58
80
|
|
|
59
|
-
|
|
60
|
-
const
|
|
81
|
+
getParties = async (args?: GetPartiesArgs): Promise<Array<Party>> => {
|
|
82
|
+
const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
|
|
83
|
+
const initialResult: Array<PartyEntity> = await partyRepository.find({
|
|
61
84
|
...(args?.filter && { where: args?.filter }),
|
|
62
85
|
})
|
|
63
86
|
|
|
64
|
-
const result = await
|
|
87
|
+
const result: Array<PartyEntity> = await partyRepository.find({
|
|
65
88
|
where: {
|
|
66
|
-
id: In(initialResult.map((
|
|
89
|
+
id: In(initialResult.map((party: PartyEntity) => party.id)),
|
|
67
90
|
},
|
|
68
91
|
})
|
|
69
92
|
|
|
70
|
-
return result.map((
|
|
93
|
+
return result.map((party: PartyEntity) => partyFrom(party))
|
|
71
94
|
}
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
const {
|
|
96
|
+
addParty = async (args: AddPartyArgs): Promise<Party> => {
|
|
97
|
+
const { identities, contact, partyType } = args
|
|
75
98
|
|
|
76
|
-
const
|
|
77
|
-
where: [{ name }, { alias }],
|
|
78
|
-
})
|
|
99
|
+
const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
|
|
79
100
|
|
|
80
|
-
if (
|
|
81
|
-
return Promise.reject(Error(`
|
|
101
|
+
if (!this.hasCorrectPartyType(partyType.type, contact)) {
|
|
102
|
+
return Promise.reject(Error(`Party type ${partyType.type}, does not match for provided contact`))
|
|
82
103
|
}
|
|
83
104
|
|
|
84
105
|
for (const identity of identities ?? []) {
|
|
@@ -87,103 +108,64 @@ export class ContactStore extends AbstractContactStore {
|
|
|
87
108
|
return Promise.reject(Error(`Identity with correlation type ${CorrelationIdentifierEnum.URL} should contain a connection`))
|
|
88
109
|
}
|
|
89
110
|
|
|
90
|
-
if (!this.
|
|
111
|
+
if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
|
|
91
112
|
return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`))
|
|
92
113
|
}
|
|
93
114
|
}
|
|
94
115
|
}
|
|
95
116
|
|
|
96
|
-
const
|
|
97
|
-
debug('Adding
|
|
98
|
-
const createdResult = await
|
|
117
|
+
const partyEntity: PartyEntity = partyEntityFrom(args)
|
|
118
|
+
debug('Adding party', args)
|
|
119
|
+
const createdResult: PartyEntity = await partyRepository.save(partyEntity)
|
|
99
120
|
|
|
100
|
-
return
|
|
121
|
+
return partyFrom(createdResult)
|
|
101
122
|
}
|
|
102
123
|
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
124
|
+
updateParty = async ({ party }: UpdatePartyArgs): Promise<Party> => {
|
|
125
|
+
const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
|
|
126
|
+
const result: PartyEntity | null = await partyRepository.findOne({
|
|
127
|
+
where: { id: party.id },
|
|
106
128
|
})
|
|
107
129
|
|
|
108
130
|
if (!result) {
|
|
109
|
-
return Promise.reject(Error(`No
|
|
131
|
+
return Promise.reject(Error(`No party found for id: ${party.id}`))
|
|
110
132
|
}
|
|
111
133
|
|
|
112
|
-
const
|
|
113
|
-
...
|
|
134
|
+
const updatedParty = {
|
|
135
|
+
...party,
|
|
114
136
|
identities: result.identities,
|
|
137
|
+
type: result.partyType,
|
|
138
|
+
relationships: result.relationships,
|
|
139
|
+
electronicAddresses: result.electronicAddresses,
|
|
115
140
|
}
|
|
116
141
|
|
|
117
|
-
debug('Updating
|
|
118
|
-
const updatedResult = await
|
|
142
|
+
debug('Updating party', party)
|
|
143
|
+
const updatedResult: PartyEntity = await partyRepository.save(updatedParty, { transaction: true })
|
|
119
144
|
|
|
120
|
-
return
|
|
145
|
+
return partyFrom(updatedResult)
|
|
121
146
|
}
|
|
122
147
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
.findOneById(
|
|
128
|
-
.then(async (
|
|
129
|
-
if (!
|
|
130
|
-
await Promise.reject(Error(`Unable to find the
|
|
148
|
+
removeParty = async ({ partyId }: RemovePartyArgs): Promise<void> => {
|
|
149
|
+
const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
|
|
150
|
+
debug('Removing party', partyId)
|
|
151
|
+
partyRepository
|
|
152
|
+
.findOneById(partyId)
|
|
153
|
+
.then(async (party: PartyEntity | null): Promise<void> => {
|
|
154
|
+
if (!party) {
|
|
155
|
+
await Promise.reject(Error(`Unable to find the party with id to remove: ${partyId}`))
|
|
131
156
|
} else {
|
|
132
|
-
await this.deleteIdentities(
|
|
157
|
+
await this.deleteIdentities(party.identities)
|
|
133
158
|
|
|
134
|
-
await
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.getRepository(ContactEntity)
|
|
138
|
-
.delete({ id: contactId })
|
|
139
|
-
.catch((error) => Promise.reject(Error(`Unable to remove contact with id: ${contactId}. ${error}`)))
|
|
159
|
+
await partyRepository
|
|
160
|
+
.delete({ id: partyId })
|
|
161
|
+
.catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)))
|
|
140
162
|
}
|
|
141
163
|
})
|
|
142
|
-
.catch((error) => Promise.reject(Error(`Unable to remove
|
|
164
|
+
.catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)))
|
|
143
165
|
}
|
|
144
166
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
identities.map(async (identity: IdentityEntity) => {
|
|
149
|
-
await (
|
|
150
|
-
await this.dbConnection
|
|
151
|
-
)
|
|
152
|
-
.getRepository(CorrelationIdentifierEntity)
|
|
153
|
-
.delete(identity.identifier.id)
|
|
154
|
-
.catch((error) => Promise.reject(Error(`Unable to remove identity.identifier with id: ${identity.identifier.id}. ${error}`)))
|
|
155
|
-
|
|
156
|
-
if (identity.connection) {
|
|
157
|
-
await (await this.dbConnection).getRepository(BaseConfigEntity).delete(identity.connection.config.id)
|
|
158
|
-
|
|
159
|
-
await (
|
|
160
|
-
await this.dbConnection
|
|
161
|
-
)
|
|
162
|
-
.getRepository(ConnectionEntity)
|
|
163
|
-
.delete(identity.connection.id)
|
|
164
|
-
.catch((error) => Promise.reject(Error(`Unable to remove identity.connection with id. ${error}`)))
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (identity.metadata) {
|
|
168
|
-
identity.metadata.map(async (metadataItem: IdentityMetadataItemEntity) => {
|
|
169
|
-
await (
|
|
170
|
-
await this.dbConnection
|
|
171
|
-
)
|
|
172
|
-
.getRepository(IdentityMetadataItemEntity)
|
|
173
|
-
.delete(metadataItem.id)
|
|
174
|
-
.catch((error) => Promise.reject(Error(`Unable to remove metadataItem.id with id ${metadataItem.id}. ${error}`)))
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
;(await this.dbConnection)
|
|
179
|
-
.getRepository(IdentityEntity)
|
|
180
|
-
.delete(identity.id)
|
|
181
|
-
.catch((error) => Promise.reject(Error(`Unable to remove metadataItem.id with id ${identity.id}. ${error}`)))
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
getIdentity = async ({ identityId }: IGetIdentityArgs): Promise<IIdentity> => {
|
|
186
|
-
const result = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
|
|
167
|
+
getIdentity = async ({ identityId }: GetIdentityArgs): Promise<Identity> => {
|
|
168
|
+
const result: IdentityEntity | null = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
|
|
187
169
|
where: { id: identityId },
|
|
188
170
|
})
|
|
189
171
|
|
|
@@ -191,30 +173,31 @@ export class ContactStore extends AbstractContactStore {
|
|
|
191
173
|
return Promise.reject(Error(`No identity found for id: ${identityId}`))
|
|
192
174
|
}
|
|
193
175
|
|
|
194
|
-
return
|
|
176
|
+
return identityFrom(result)
|
|
195
177
|
}
|
|
196
178
|
|
|
197
|
-
getIdentities = async (args?:
|
|
198
|
-
const
|
|
179
|
+
getIdentities = async (args?: GetIdentitiesArgs): Promise<Array<Identity>> => {
|
|
180
|
+
const identityRepository: Repository<IdentityEntity> = (await this.dbConnection).getRepository(IdentityEntity)
|
|
181
|
+
const initialResult: Array<IdentityEntity> = await identityRepository.find({
|
|
199
182
|
...(args?.filter && { where: args?.filter }),
|
|
200
183
|
})
|
|
201
184
|
|
|
202
|
-
const result = await
|
|
185
|
+
const result: Array<IdentityEntity> = await identityRepository.find({
|
|
203
186
|
where: {
|
|
204
187
|
id: In(initialResult.map((identity: IdentityEntity) => identity.id)),
|
|
205
188
|
},
|
|
206
189
|
})
|
|
207
190
|
|
|
208
|
-
return result.map((identity: IdentityEntity) =>
|
|
191
|
+
return result.map((identity: IdentityEntity) => identityFrom(identity))
|
|
209
192
|
}
|
|
210
193
|
|
|
211
|
-
addIdentity = async ({ identity,
|
|
212
|
-
const
|
|
213
|
-
where: { id:
|
|
194
|
+
addIdentity = async ({ identity, partyId }: AddIdentityArgs): Promise<Identity> => {
|
|
195
|
+
const party: PartyEntity | null = await (await this.dbConnection).getRepository(PartyEntity).findOne({
|
|
196
|
+
where: { id: partyId },
|
|
214
197
|
})
|
|
215
198
|
|
|
216
|
-
if (!
|
|
217
|
-
return Promise.reject(Error(`No
|
|
199
|
+
if (!party) {
|
|
200
|
+
return Promise.reject(Error(`No party found for id: ${partyId}`))
|
|
218
201
|
}
|
|
219
202
|
|
|
220
203
|
if (identity.identifier.type === CorrelationIdentifierEnum.URL) {
|
|
@@ -222,23 +205,24 @@ export class ContactStore extends AbstractContactStore {
|
|
|
222
205
|
return Promise.reject(Error(`Identity with correlation type ${CorrelationIdentifierEnum.URL} should contain a connection`))
|
|
223
206
|
}
|
|
224
207
|
|
|
225
|
-
if (!this.
|
|
208
|
+
if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
|
|
226
209
|
return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`))
|
|
227
210
|
}
|
|
228
211
|
}
|
|
229
212
|
|
|
230
|
-
const identityEntity = identityEntityFrom(identity)
|
|
231
|
-
identityEntity.
|
|
213
|
+
const identityEntity: IdentityEntity = identityEntityFrom(identity)
|
|
214
|
+
identityEntity.party = party
|
|
232
215
|
debug('Adding identity', identity)
|
|
233
|
-
const result = await (await this.dbConnection).getRepository(IdentityEntity).save(identityEntity, {
|
|
216
|
+
const result: IdentityEntity = await (await this.dbConnection).getRepository(IdentityEntity).save(identityEntity, {
|
|
234
217
|
transaction: true,
|
|
235
218
|
})
|
|
236
219
|
|
|
237
|
-
return
|
|
220
|
+
return identityFrom(result)
|
|
238
221
|
}
|
|
239
222
|
|
|
240
|
-
updateIdentity = async ({ identity }:
|
|
241
|
-
const
|
|
223
|
+
updateIdentity = async ({ identity }: UpdateIdentityArgs): Promise<Identity> => {
|
|
224
|
+
const identityRepository: Repository<IdentityEntity> = (await this.dbConnection).getRepository(IdentityEntity)
|
|
225
|
+
const result: IdentityEntity | null = await identityRepository.findOne({
|
|
242
226
|
where: { id: identity.id },
|
|
243
227
|
})
|
|
244
228
|
|
|
@@ -251,19 +235,19 @@ export class ContactStore extends AbstractContactStore {
|
|
|
251
235
|
return Promise.reject(Error(`Identity with correlation type ${CorrelationIdentifierEnum.URL} should contain a connection`))
|
|
252
236
|
}
|
|
253
237
|
|
|
254
|
-
if (!this.
|
|
238
|
+
if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
|
|
255
239
|
return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`))
|
|
256
240
|
}
|
|
257
241
|
}
|
|
258
242
|
|
|
259
243
|
debug('Updating identity', identity)
|
|
260
|
-
const updatedResult = await
|
|
244
|
+
const updatedResult: IdentityEntity = await identityRepository.save(identity, { transaction: true })
|
|
261
245
|
|
|
262
|
-
return
|
|
246
|
+
return identityFrom(updatedResult)
|
|
263
247
|
}
|
|
264
248
|
|
|
265
|
-
removeIdentity = async ({ identityId }:
|
|
266
|
-
const identity = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
|
|
249
|
+
removeIdentity = async ({ identityId }: RemoveIdentityArgs): Promise<void> => {
|
|
250
|
+
const identity: IdentityEntity | null = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
|
|
267
251
|
where: { id: identityId },
|
|
268
252
|
})
|
|
269
253
|
|
|
@@ -276,96 +260,236 @@ export class ContactStore extends AbstractContactStore {
|
|
|
276
260
|
await this.deleteIdentities([identity])
|
|
277
261
|
}
|
|
278
262
|
|
|
279
|
-
|
|
280
|
-
return {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
263
|
+
addRelationship = async ({ leftId, rightId }: AddRelationshipArgs): Promise<PartyRelationship> => {
|
|
264
|
+
return this.assertRelationshipSides(leftId, rightId).then(async (): Promise<PartyRelationship> => {
|
|
265
|
+
const relationship: PartyRelationshipEntity = partyRelationshipEntityFrom({
|
|
266
|
+
leftId,
|
|
267
|
+
rightId,
|
|
268
|
+
})
|
|
269
|
+
debug('Adding party relationship', relationship)
|
|
270
|
+
|
|
271
|
+
const createdResult: PartyRelationshipEntity = await (await this.dbConnection).getRepository(PartyRelationshipEntity).save(relationship)
|
|
272
|
+
|
|
273
|
+
return partyRelationshipFrom(createdResult)
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
getRelationship = async ({ relationshipId }: GetRelationshipArgs): Promise<PartyRelationship> => {
|
|
278
|
+
const result: PartyRelationshipEntity | null = await (await this.dbConnection).getRepository(PartyRelationshipEntity).findOne({
|
|
279
|
+
where: { id: relationshipId },
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
if (!result) {
|
|
283
|
+
return Promise.reject(Error(`No relationship found for id: ${relationshipId}`))
|
|
289
284
|
}
|
|
285
|
+
|
|
286
|
+
return partyRelationshipFrom(result)
|
|
290
287
|
}
|
|
291
288
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
289
|
+
getRelationships = async (args?: GetRelationshipsArgs): Promise<Array<PartyRelationship>> => {
|
|
290
|
+
const partyRelationshipRepository: Repository<PartyRelationshipEntity> = (await this.dbConnection).getRepository(PartyRelationshipEntity)
|
|
291
|
+
const initialResult: Array<PartyRelationshipEntity> = await partyRelationshipRepository.find({
|
|
292
|
+
...(args?.filter && { where: args?.filter }),
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
const result: Array<PartyRelationshipEntity> = await partyRelationshipRepository.find({
|
|
296
|
+
where: {
|
|
297
|
+
id: In(initialResult.map((partyRelationship: PartyRelationshipEntity) => partyRelationship.id)),
|
|
298
|
+
},
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
return result.map((partyRelationship: PartyRelationshipEntity) => partyRelationshipFrom(partyRelationship))
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
updateRelationship = async ({ relationship }: UpdateRelationshipArgs): Promise<PartyRelationship> => {
|
|
305
|
+
const partyRelationshipRepository: Repository<PartyRelationshipEntity> = (await this.dbConnection).getRepository(PartyRelationshipEntity)
|
|
306
|
+
const result: PartyRelationshipEntity | null = await partyRelationshipRepository.findOne({
|
|
307
|
+
where: { id: relationship.id },
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
if (!result) {
|
|
311
|
+
return Promise.reject(Error(`No party relationship found for id: ${relationship.id}`))
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return this.assertRelationshipSides(relationship.leftId, relationship.rightId).then(async (): Promise<PartyRelationship> => {
|
|
315
|
+
debug('Updating party relationship', relationship)
|
|
316
|
+
const updatedResult: PartyRelationshipEntity = await partyRelationshipRepository.save(relationship, { transaction: true })
|
|
317
|
+
|
|
318
|
+
return partyRelationshipFrom(updatedResult)
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
removeRelationship = async ({ relationshipId }: RemoveRelationshipArgs): Promise<void> => {
|
|
323
|
+
const partyRelationshipRepository: Repository<PartyRelationshipEntity> = (await this.dbConnection).getRepository(PartyRelationshipEntity)
|
|
324
|
+
const relationship: PartyRelationshipEntity | null = await partyRelationshipRepository.findOne({
|
|
325
|
+
where: { id: relationshipId },
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
if (!relationship) {
|
|
329
|
+
return Promise.reject(Error(`No relationship found for id: ${relationshipId}`))
|
|
302
330
|
}
|
|
331
|
+
|
|
332
|
+
debug('Removing relationship', relationshipId)
|
|
333
|
+
|
|
334
|
+
await partyRelationshipRepository.delete(relationshipId)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
addPartyType = async (args: AddPartyTypeArgs): Promise<PartyType> => {
|
|
338
|
+
const partyEntity: PartyTypeEntity = partyTypeEntityFrom(args)
|
|
339
|
+
debug('Adding party type', args)
|
|
340
|
+
const createdResult: PartyTypeEntity = await (await this.dbConnection).getRepository(PartyTypeEntity).save(partyEntity)
|
|
341
|
+
|
|
342
|
+
return partyTypeFrom(createdResult)
|
|
303
343
|
}
|
|
304
344
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
id:
|
|
308
|
-
|
|
309
|
-
|
|
345
|
+
getPartyType = async ({ partyTypeId }: GetPartyTypeArgs): Promise<PartyType> => {
|
|
346
|
+
const result: PartyTypeEntity | null = await (await this.dbConnection).getRepository(PartyTypeEntity).findOne({
|
|
347
|
+
where: { id: partyTypeId },
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
if (!result) {
|
|
351
|
+
return Promise.reject(Error(`No party type found for id: ${partyTypeId}`))
|
|
310
352
|
}
|
|
353
|
+
|
|
354
|
+
return partyTypeFrom(result)
|
|
311
355
|
}
|
|
312
356
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
357
|
+
getPartyTypes = async (args?: GetPartyTypesArgs): Promise<Array<PartyType>> => {
|
|
358
|
+
const partyTypeRepository: Repository<PartyTypeEntity> = (await this.dbConnection).getRepository(PartyTypeEntity)
|
|
359
|
+
const initialResult: Array<PartyTypeEntity> = await partyTypeRepository.find({
|
|
360
|
+
...(args?.filter && { where: args?.filter }),
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
const result: Array<PartyTypeEntity> = await partyTypeRepository.find({
|
|
364
|
+
where: {
|
|
365
|
+
id: In(initialResult.map((partyType: PartyTypeEntity) => partyType.id)),
|
|
366
|
+
},
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
return result.map((partyType: PartyTypeEntity) => partyTypeFrom(partyType))
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
updatePartyType = async ({ partyType }: UpdatePartyTypeArgs): Promise<PartyType> => {
|
|
373
|
+
const partyTypeRepository: Repository<PartyTypeEntity> = (await this.dbConnection).getRepository(PartyTypeEntity)
|
|
374
|
+
const result: PartyTypeEntity | null = await partyTypeRepository.findOne({
|
|
375
|
+
where: { id: partyType.id },
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
if (!result) {
|
|
379
|
+
return Promise.reject(Error(`No party type found for id: ${partyType.id}`))
|
|
318
380
|
}
|
|
381
|
+
|
|
382
|
+
debug('Updating party type', partyType)
|
|
383
|
+
const updatedResult: PartyTypeEntity = await partyTypeRepository.save(partyType, { transaction: true })
|
|
384
|
+
|
|
385
|
+
return partyTypeFrom(updatedResult)
|
|
319
386
|
}
|
|
320
387
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
388
|
+
removePartyType = async ({ partyTypeId }: RemovePartyTypeArgs): Promise<void> => {
|
|
389
|
+
const parties: Array<PartyEntity> = await (await this.dbConnection).getRepository(PartyEntity).find({
|
|
390
|
+
where: {
|
|
391
|
+
partyType: {
|
|
392
|
+
id: partyTypeId,
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
if (parties.length > 0) {
|
|
398
|
+
return Promise.reject(Error(`Unable to remove party type with id: ${partyTypeId}. Party type is in use`))
|
|
326
399
|
}
|
|
400
|
+
|
|
401
|
+
const partyTypeRepository: Repository<PartyTypeEntity> = (await this.dbConnection).getRepository(PartyTypeEntity)
|
|
402
|
+
const partyType: PartyTypeEntity | null = await partyTypeRepository.findOne({
|
|
403
|
+
where: { id: partyTypeId },
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
if (!partyType) {
|
|
407
|
+
return Promise.reject(Error(`No party type found for id: ${partyTypeId}`))
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
debug('Removing party type', partyTypeId)
|
|
411
|
+
|
|
412
|
+
await partyTypeRepository.delete(partyTypeId)
|
|
327
413
|
}
|
|
328
414
|
|
|
329
|
-
private
|
|
415
|
+
private hasCorrectConnectionConfig(type: ConnectionTypeEnum, config: NonPersistedConnectionConfig): boolean {
|
|
330
416
|
switch (type) {
|
|
331
417
|
case ConnectionTypeEnum.OPENID_CONNECT:
|
|
332
|
-
return
|
|
333
|
-
id: (config as OpenIdConfigEntity).id,
|
|
334
|
-
clientId: (config as OpenIdConfigEntity).clientId,
|
|
335
|
-
clientSecret: (config as OpenIdConfigEntity).clientSecret,
|
|
336
|
-
scopes: (config as OpenIdConfigEntity).scopes,
|
|
337
|
-
issuer: (config as OpenIdConfigEntity).issuer!, // TODO fixme
|
|
338
|
-
redirectUrl: (config as OpenIdConfigEntity).redirectUrl,
|
|
339
|
-
dangerouslyAllowInsecureHttpRequests: (config as OpenIdConfigEntity).dangerouslyAllowInsecureHttpRequests,
|
|
340
|
-
clientAuthMethod: (config as OpenIdConfigEntity).clientAuthMethod,
|
|
341
|
-
}
|
|
418
|
+
return isOpenIdConfig(config)
|
|
342
419
|
case ConnectionTypeEnum.SIOPv2:
|
|
343
|
-
return
|
|
344
|
-
id: (config as DidAuthConfigEntity).id,
|
|
345
|
-
identifier: { did: (config as DidAuthConfigEntity).identifier, provider: '', keys: [], services: [] },
|
|
346
|
-
stateId: '',
|
|
347
|
-
redirectUrl: (config as DidAuthConfigEntity).redirectUrl,
|
|
348
|
-
sessionId: (config as DidAuthConfigEntity).sessionId,
|
|
349
|
-
}
|
|
420
|
+
return isDidAuthConfig(config)
|
|
350
421
|
default:
|
|
351
422
|
throw new Error('Connection type not supported')
|
|
352
423
|
}
|
|
353
424
|
}
|
|
354
425
|
|
|
355
|
-
private
|
|
426
|
+
private hasCorrectPartyType(type: PartyTypeEnum, contact: NonPersistedContact): boolean {
|
|
356
427
|
switch (type) {
|
|
357
|
-
case
|
|
358
|
-
return
|
|
359
|
-
case
|
|
360
|
-
return
|
|
428
|
+
case PartyTypeEnum.NATURAL_PERSON:
|
|
429
|
+
return isNaturalPerson(contact)
|
|
430
|
+
case PartyTypeEnum.ORGANIZATION:
|
|
431
|
+
return isOrganization(contact)
|
|
361
432
|
default:
|
|
362
|
-
throw new Error('
|
|
433
|
+
throw new Error('Party type not supported')
|
|
363
434
|
}
|
|
364
435
|
}
|
|
365
436
|
|
|
366
|
-
private
|
|
367
|
-
'
|
|
437
|
+
private async deleteIdentities(identities: Array<IdentityEntity>): Promise<void> {
|
|
438
|
+
debug('Removing identities', identities)
|
|
368
439
|
|
|
369
|
-
|
|
370
|
-
|
|
440
|
+
identities.map(async (identity: IdentityEntity): Promise<void> => {
|
|
441
|
+
await (
|
|
442
|
+
await this.dbConnection
|
|
443
|
+
)
|
|
444
|
+
.getRepository(CorrelationIdentifierEntity)
|
|
445
|
+
.delete(identity.identifier.id)
|
|
446
|
+
.catch((error) => Promise.reject(Error(`Unable to remove identity.identifier with id: ${identity.identifier.id}. ${error}`)))
|
|
447
|
+
|
|
448
|
+
if (identity.connection) {
|
|
449
|
+
await (await this.dbConnection).getRepository(BaseConfigEntity).delete(identity.connection.config.id)
|
|
450
|
+
|
|
451
|
+
await (
|
|
452
|
+
await this.dbConnection
|
|
453
|
+
)
|
|
454
|
+
.getRepository(ConnectionEntity)
|
|
455
|
+
.delete(identity.connection.id)
|
|
456
|
+
.catch((error) => Promise.reject(Error(`Unable to remove identity.connection with id. ${error}`)))
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (identity.metadata) {
|
|
460
|
+
identity.metadata.map(async (metadataItem: IdentityMetadataItemEntity): Promise<void> => {
|
|
461
|
+
await (
|
|
462
|
+
await this.dbConnection
|
|
463
|
+
)
|
|
464
|
+
.getRepository(IdentityMetadataItemEntity)
|
|
465
|
+
.delete(metadataItem.id)
|
|
466
|
+
.catch((error) => Promise.reject(Error(`Unable to remove metadataItem.id with id ${metadataItem.id}. ${error}`)))
|
|
467
|
+
})
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
;(await this.dbConnection)
|
|
471
|
+
.getRepository(IdentityEntity)
|
|
472
|
+
.delete(identity.id)
|
|
473
|
+
.catch((error) => Promise.reject(Error(`Unable to remove metadataItem.id with id ${identity.id}. ${error}`)))
|
|
474
|
+
})
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
private async assertRelationshipSides(leftId: string, rightId: string): Promise<void> {
|
|
478
|
+
const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
|
|
479
|
+
const leftParty: PartyEntity | null = await partyRepository.findOne({
|
|
480
|
+
where: { id: leftId },
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
if (!leftParty) {
|
|
484
|
+
return Promise.reject(Error(`No party found for left side of the relationship, party id: ${leftId}`))
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const rightParty: PartyEntity | null = await partyRepository.findOne({
|
|
488
|
+
where: { id: rightId },
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
if (!rightParty) {
|
|
492
|
+
return Promise.reject(Error(`No party found for right side of the relationship, party id: ${rightId}`))
|
|
493
|
+
}
|
|
494
|
+
}
|
|
371
495
|
}
|