@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.
Files changed (213) hide show
  1. package/dist/contact/AbstractContactStore.d.ts +21 -11
  2. package/dist/contact/AbstractContactStore.d.ts.map +1 -1
  3. package/dist/contact/AbstractContactStore.js.map +1 -1
  4. package/dist/contact/ContactStore.d.ts +25 -21
  5. package/dist/contact/ContactStore.d.ts.map +1 -1
  6. package/dist/contact/ContactStore.js +216 -136
  7. package/dist/contact/ContactStore.js.map +1 -1
  8. package/dist/entities/contact/BaseConfigEntity.d.ts +2 -0
  9. package/dist/entities/contact/BaseConfigEntity.d.ts.map +1 -1
  10. package/dist/entities/contact/BaseConfigEntity.js +10 -2
  11. package/dist/entities/contact/BaseConfigEntity.js.map +1 -1
  12. package/dist/entities/contact/BaseContactEntity.d.ts +10 -0
  13. package/dist/entities/contact/BaseContactEntity.d.ts.map +1 -0
  14. package/dist/entities/contact/BaseContactEntity.js +54 -0
  15. package/dist/entities/contact/BaseContactEntity.js.map +1 -0
  16. package/dist/entities/contact/ConnectionEntity.d.ts +1 -2
  17. package/dist/entities/contact/ConnectionEntity.d.ts.map +1 -1
  18. package/dist/entities/contact/ConnectionEntity.js +2 -21
  19. package/dist/entities/contact/ConnectionEntity.js.map +1 -1
  20. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +2 -3
  21. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts.map +1 -1
  22. package/dist/entities/contact/CorrelationIdentifierEntity.js +8 -11
  23. package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -1
  24. package/dist/entities/contact/DidAuthConfigEntity.d.ts +0 -4
  25. package/dist/entities/contact/DidAuthConfigEntity.d.ts.map +1 -1
  26. package/dist/entities/contact/DidAuthConfigEntity.js +1 -17
  27. package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -1
  28. package/dist/entities/contact/ElectronicAddressEntity.d.ts +14 -0
  29. package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -0
  30. package/dist/entities/contact/ElectronicAddressEntity.js +92 -0
  31. package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -0
  32. package/dist/entities/contact/IdentityEntity.d.ts +5 -6
  33. package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
  34. package/dist/entities/contact/IdentityEntity.js +15 -20
  35. package/dist/entities/contact/IdentityEntity.js.map +1 -1
  36. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +1 -3
  37. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts.map +1 -1
  38. package/dist/entities/contact/IdentityMetadataItemEntity.js +7 -10
  39. package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -1
  40. package/dist/entities/contact/NaturalPersonEntity.d.ts +9 -0
  41. package/dist/entities/contact/NaturalPersonEntity.d.ts.map +1 -0
  42. package/dist/entities/contact/NaturalPersonEntity.js +72 -0
  43. package/dist/entities/contact/NaturalPersonEntity.js.map +1 -0
  44. package/dist/entities/contact/OpenIdConfigEntity.d.ts +0 -4
  45. package/dist/entities/contact/OpenIdConfigEntity.d.ts.map +1 -1
  46. package/dist/entities/contact/OpenIdConfigEntity.js +1 -22
  47. package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -1
  48. package/dist/entities/contact/OrganizationEntity.d.ts +9 -0
  49. package/dist/entities/contact/OrganizationEntity.d.ts.map +1 -0
  50. package/dist/entities/contact/OrganizationEntity.js +67 -0
  51. package/dist/entities/contact/OrganizationEntity.js.map +1 -0
  52. package/dist/entities/contact/PartyEntity.d.ts +21 -0
  53. package/dist/entities/contact/PartyEntity.d.ts.map +1 -0
  54. package/dist/entities/contact/PartyEntity.js +155 -0
  55. package/dist/entities/contact/PartyEntity.js.map +1 -0
  56. package/dist/entities/contact/PartyRelationshipEntity.d.ts +13 -0
  57. package/dist/entities/contact/PartyRelationshipEntity.d.ts.map +1 -0
  58. package/dist/entities/contact/PartyRelationshipEntity.js +95 -0
  59. package/dist/entities/contact/PartyRelationshipEntity.js.map +1 -0
  60. package/dist/entities/contact/PartyTypeEntity.d.ts +15 -0
  61. package/dist/entities/contact/PartyTypeEntity.d.ts.map +1 -0
  62. package/dist/entities/contact/{ContactEntity.js → PartyTypeEntity.js} +35 -36
  63. package/dist/entities/contact/PartyTypeEntity.js.map +1 -0
  64. package/dist/entities/statusList2021/StatusList2021Entity.d.ts +19 -0
  65. package/dist/entities/statusList2021/StatusList2021Entity.d.ts.map +1 -0
  66. package/dist/entities/statusList2021/StatusList2021Entity.js +115 -0
  67. package/dist/entities/statusList2021/StatusList2021Entity.js.map +1 -0
  68. package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts +11 -0
  69. package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts.map +1 -0
  70. package/dist/entities/statusList2021/StatusList2021EntryEntity.js +51 -0
  71. package/dist/entities/statusList2021/StatusList2021EntryEntity.js.map +1 -0
  72. package/dist/index.d.ts +20 -9
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +27 -11
  75. package/dist/index.js.map +1 -1
  76. package/dist/migrations/generic/1-CreateContacts.d.ts.map +1 -1
  77. package/dist/migrations/generic/1-CreateContacts.js +36 -32
  78. package/dist/migrations/generic/1-CreateContacts.js.map +1 -1
  79. package/dist/migrations/generic/2-CreateContacts.d.ts +7 -0
  80. package/dist/migrations/generic/2-CreateContacts.d.ts.map +1 -0
  81. package/dist/migrations/generic/2-CreateContacts.js +76 -0
  82. package/dist/migrations/generic/2-CreateContacts.js.map +1 -0
  83. package/dist/migrations/generic/{1-CreateIssuanceBranding.d.ts → 2-CreateIssuanceBranding.d.ts} +1 -1
  84. package/dist/migrations/generic/2-CreateIssuanceBranding.d.ts.map +1 -0
  85. package/dist/migrations/generic/2-CreateIssuanceBranding.js +76 -0
  86. package/dist/migrations/generic/2-CreateIssuanceBranding.js.map +1 -0
  87. package/dist/migrations/generic/3-CreateStatusList.d.ts +7 -0
  88. package/dist/migrations/generic/3-CreateStatusList.d.ts.map +1 -0
  89. package/dist/migrations/generic/{1-CreateIssuanceBranding.js → 3-CreateStatusList.js} +11 -11
  90. package/dist/migrations/generic/3-CreateStatusList.js.map +1 -0
  91. package/dist/migrations/generic/index.d.ts +5 -0
  92. package/dist/migrations/generic/index.d.ts.map +1 -1
  93. package/dist/migrations/generic/index.js +10 -3
  94. package/dist/migrations/generic/index.js.map +1 -1
  95. package/dist/migrations/internal-migrations-ormconfig.d.ts +2 -1
  96. package/dist/migrations/internal-migrations-ormconfig.d.ts.map +1 -1
  97. package/dist/migrations/internal-migrations-ormconfig.js +0 -2
  98. package/dist/migrations/internal-migrations-ormconfig.js.map +1 -1
  99. package/dist/migrations/postgres/1659463079428-CreateContacts.d.ts.map +1 -1
  100. package/dist/migrations/postgres/1659463079428-CreateContacts.js +4 -2
  101. package/dist/migrations/postgres/1659463079428-CreateContacts.js.map +1 -1
  102. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.d.ts.map +1 -1
  103. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +2 -0
  104. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js.map +1 -1
  105. package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts +7 -0
  106. package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts.map +1 -0
  107. package/dist/migrations/postgres/1690925872592-CreateContacts.js +69 -0
  108. package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -0
  109. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts +7 -0
  110. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts.map +1 -0
  111. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js +32 -0
  112. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js.map +1 -0
  113. package/dist/migrations/postgres/uuid.d.ts +3 -0
  114. package/dist/migrations/postgres/uuid.d.ts.map +1 -0
  115. package/dist/migrations/postgres/uuid.js +25 -0
  116. package/dist/migrations/postgres/uuid.js.map +1 -0
  117. package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts +7 -0
  118. package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -0
  119. package/dist/migrations/sqlite/1690925872693-CreateContacts.js +108 -0
  120. package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -0
  121. package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts +7 -0
  122. package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts.map +1 -0
  123. package/dist/migrations/sqlite/1693866470000-CreateStatusList.js +32 -0
  124. package/dist/migrations/sqlite/1693866470000-CreateStatusList.js.map +1 -0
  125. package/dist/statusList/IStatusListStore.d.ts +20 -0
  126. package/dist/statusList/IStatusListStore.d.ts.map +1 -0
  127. package/dist/statusList/IStatusListStore.js +3 -0
  128. package/dist/statusList/IStatusListStore.js.map +1 -0
  129. package/dist/statusList/StatusListStore.d.ts +36 -0
  130. package/dist/statusList/StatusListStore.d.ts.map +1 -0
  131. package/dist/statusList/StatusListStore.js +213 -0
  132. package/dist/statusList/StatusListStore.js.map +1 -0
  133. package/dist/types/contact/IAbstractContactStore.d.ts +70 -36
  134. package/dist/types/contact/IAbstractContactStore.d.ts.map +1 -1
  135. package/dist/types/contact/contact.d.ts +139 -56
  136. package/dist/types/contact/contact.d.ts.map +1 -1
  137. package/dist/types/contact/contact.js +6 -1
  138. package/dist/types/contact/contact.js.map +1 -1
  139. package/dist/types/index.d.ts +3 -0
  140. package/dist/types/index.d.ts.map +1 -1
  141. package/dist/types/index.js +3 -0
  142. package/dist/types/index.js.map +1 -1
  143. package/dist/types/statusList/IAbstractStatusListStore.d.ts +38 -0
  144. package/dist/types/statusList/IAbstractStatusListStore.d.ts.map +1 -0
  145. package/dist/types/statusList/IAbstractStatusListStore.js +3 -0
  146. package/dist/types/statusList/IAbstractStatusListStore.js.map +1 -0
  147. package/dist/types/statusList/statusList.d.ts +25 -0
  148. package/dist/types/statusList/statusList.d.ts.map +1 -0
  149. package/dist/types/statusList/statusList.js +3 -0
  150. package/dist/types/statusList/statusList.js.map +1 -0
  151. package/dist/types/validation/validation.d.ts +4 -0
  152. package/dist/types/validation/validation.d.ts.map +1 -0
  153. package/dist/types/validation/validation.js +3 -0
  154. package/dist/types/validation/validation.js.map +1 -0
  155. package/dist/utils/ValidatorUtils.d.ts +4 -0
  156. package/dist/utils/ValidatorUtils.d.ts.map +1 -0
  157. package/dist/utils/ValidatorUtils.js +13 -0
  158. package/dist/utils/ValidatorUtils.js.map +1 -0
  159. package/dist/utils/contact/MappingUtils.d.ts +47 -0
  160. package/dist/utils/contact/MappingUtils.d.ts.map +1 -0
  161. package/dist/utils/contact/MappingUtils.js +291 -0
  162. package/dist/utils/contact/MappingUtils.js.map +1 -0
  163. package/package.json +5 -4
  164. package/src/__tests__/contact.entities.test.ts +1457 -195
  165. package/src/__tests__/contact.store.test.ts +1302 -266
  166. package/src/contact/AbstractContactStore.ts +44 -22
  167. package/src/contact/ContactStore.ts +328 -204
  168. package/src/entities/contact/BaseConfigEntity.ts +10 -2
  169. package/src/entities/contact/BaseContactEntity.ts +30 -0
  170. package/src/entities/contact/ConnectionEntity.ts +4 -23
  171. package/src/entities/contact/CorrelationIdentifierEntity.ts +9 -13
  172. package/src/entities/contact/DidAuthConfigEntity.ts +1 -18
  173. package/src/entities/contact/ElectronicAddressEntity.ts +60 -0
  174. package/src/entities/contact/IdentityEntity.ts +18 -25
  175. package/src/entities/contact/IdentityMetadataItemEntity.ts +8 -12
  176. package/src/entities/contact/NaturalPersonEntity.ts +38 -0
  177. package/src/entities/contact/OpenIdConfigEntity.ts +1 -23
  178. package/src/entities/contact/OrganizationEntity.ts +34 -0
  179. package/src/entities/contact/PartyEntity.ts +118 -0
  180. package/src/entities/contact/PartyRelationshipEntity.ts +61 -0
  181. package/src/entities/contact/PartyTypeEntity.ts +59 -0
  182. package/src/entities/statusList2021/StatusList2021Entity.ts +95 -0
  183. package/src/entities/statusList2021/StatusList2021EntryEntity.ts +29 -0
  184. package/src/index.ts +36 -17
  185. package/src/migrations/generic/1-CreateContacts.ts +46 -36
  186. package/src/migrations/generic/2-CreateContacts.ts +64 -0
  187. package/src/migrations/generic/2-CreateIssuanceBranding.ts +62 -0
  188. package/src/migrations/generic/{1-CreateIssuanceBranding.ts → 3-CreateStatusList.ts} +9 -9
  189. package/src/migrations/generic/index.ts +11 -2
  190. package/src/migrations/internal-migrations-ormconfig.ts +2 -4
  191. package/src/migrations/postgres/1659463079428-CreateContacts.ts +4 -2
  192. package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +2 -0
  193. package/src/migrations/postgres/1690925872592-CreateContacts.ts +94 -0
  194. package/src/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.ts +24 -0
  195. package/src/migrations/postgres/uuid.ts +12 -0
  196. package/src/migrations/sqlite/1690925872693-CreateContacts.ts +163 -0
  197. package/src/migrations/sqlite/1693866470000-CreateStatusList.ts +24 -0
  198. package/src/statusList/IStatusListStore.ts +44 -0
  199. package/src/statusList/StatusListStore.ts +237 -0
  200. package/src/types/contact/IAbstractContactStore.ts +84 -27
  201. package/src/types/contact/contact.ts +144 -50
  202. package/src/types/index.ts +4 -0
  203. package/src/types/statusList/IAbstractStatusListStore.ts +47 -0
  204. package/src/types/statusList/statusList.ts +39 -0
  205. package/src/types/validation/validation.ts +3 -0
  206. package/src/utils/ValidatorUtils.ts +10 -0
  207. package/src/utils/contact/MappingUtils.ts +344 -0
  208. package/dist/entities/contact/ContactEntity.d.ts +0 -16
  209. package/dist/entities/contact/ContactEntity.d.ts.map +0 -1
  210. package/dist/entities/contact/ContactEntity.js.map +0 -1
  211. package/dist/migrations/generic/1-CreateIssuanceBranding.d.ts.map +0 -1
  212. package/dist/migrations/generic/1-CreateIssuanceBranding.js.map +0 -1
  213. 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
- IAddIdentityArgs,
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 { OpenIdConfigEntity } from '../entities/contact/OpenIdConfigEntity'
34
- import { DidAuthConfigEntity } from '../entities/contact/DidAuthConfigEntity'
35
- import { DataSource, In } from 'typeorm'
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
- getContact = async ({ contactId }: IGetContactArgs): Promise<IContact> => {
48
- const result = await (await this.dbConnection).getRepository(ContactEntity).findOne({
49
- where: { id: contactId },
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 contact found for id: ${contactId}`))
75
+ return Promise.reject(Error(`No party found for id: ${partyId}`))
54
76
  }
55
77
 
56
- return this.contactFrom(result)
78
+ return partyFrom(result)
57
79
  }
58
80
 
59
- getContacts = async (args?: IGetContactsArgs): Promise<Array<IContact>> => {
60
- const initialResult = await (await this.dbConnection).getRepository(ContactEntity).find({
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 (await this.dbConnection).getRepository(ContactEntity).find({
87
+ const result: Array<PartyEntity> = await partyRepository.find({
65
88
  where: {
66
- id: In(initialResult.map((contact: ContactEntity) => contact.id)),
89
+ id: In(initialResult.map((party: PartyEntity) => party.id)),
67
90
  },
68
91
  })
69
92
 
70
- return result.map((contact: ContactEntity) => this.contactFrom(contact))
93
+ return result.map((party: PartyEntity) => partyFrom(party))
71
94
  }
72
95
 
73
- addContact = async (args: IAddContactArgs): Promise<IContact> => {
74
- const { name, alias, uri, identities } = args
96
+ addParty = async (args: AddPartyArgs): Promise<Party> => {
97
+ const { identities, contact, partyType } = args
75
98
 
76
- const result = await (await this.dbConnection).getRepository(ContactEntity).findOne({
77
- where: [{ name }, { alias }],
78
- })
99
+ const partyRepository: Repository<PartyEntity> = (await this.dbConnection).getRepository(PartyEntity)
79
100
 
80
- if (result) {
81
- return Promise.reject(Error(`Duplicate names or aliases are not allowed. Name: ${name}, Alias: ${alias}`))
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.hasCorrectConfig(identity.connection.type, identity.connection.config)) {
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 contactEntity = contactEntityFrom({ name, alias, uri, identities })
97
- debug('Adding contact', name)
98
- const createdResult = await (await this.dbConnection).getRepository(ContactEntity).save(contactEntity)
117
+ const partyEntity: PartyEntity = partyEntityFrom(args)
118
+ debug('Adding party', args)
119
+ const createdResult: PartyEntity = await partyRepository.save(partyEntity)
99
120
 
100
- return this.contactFrom(createdResult)
121
+ return partyFrom(createdResult)
101
122
  }
102
123
 
103
- updateContact = async ({ contact }: IUpdateContactArgs): Promise<IContact> => {
104
- const result = await (await this.dbConnection).getRepository(ContactEntity).findOne({
105
- where: { id: contact.id },
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 contact found for id: ${contact.id}`))
131
+ return Promise.reject(Error(`No party found for id: ${party.id}`))
110
132
  }
111
133
 
112
- const updatedContact = {
113
- ...contact,
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 contact', contact)
118
- const updatedResult = await (await this.dbConnection).getRepository(ContactEntity).save(updatedContact, { transaction: true })
142
+ debug('Updating party', party)
143
+ const updatedResult: PartyEntity = await partyRepository.save(updatedParty, { transaction: true })
119
144
 
120
- return this.contactFrom(updatedResult)
145
+ return partyFrom(updatedResult)
121
146
  }
122
147
 
123
- removeContact = async ({ contactId }: IRemoveContactArgs): Promise<void> => {
124
- debug('Removing contact', contactId)
125
- ;(await this.dbConnection)
126
- .getRepository(ContactEntity)
127
- .findOneById(contactId)
128
- .then(async (contact: ContactEntity | null) => {
129
- if (!contact) {
130
- await Promise.reject(Error(`Unable to find the contact with id to remove: ${contactId}`))
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(contact.identities)
157
+ await this.deleteIdentities(party.identities)
133
158
 
134
- await (
135
- await this.dbConnection
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 contact with id: ${contactId}. ${error}`)))
164
+ .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)))
143
165
  }
144
166
 
145
- private async deleteIdentities(identities: Array<IdentityEntity>): Promise<void> {
146
- debug('Removing identities', identities)
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 this.identityFrom(result)
176
+ return identityFrom(result)
195
177
  }
196
178
 
197
- getIdentities = async (args?: IGetIdentitiesArgs): Promise<Array<IIdentity>> => {
198
- const initialResult = await (await this.dbConnection).getRepository(IdentityEntity).find({
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 (await this.dbConnection).getRepository(IdentityEntity).find({
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) => this.identityFrom(identity))
191
+ return result.map((identity: IdentityEntity) => identityFrom(identity))
209
192
  }
210
193
 
211
- addIdentity = async ({ identity, contactId }: IAddIdentityArgs): Promise<IIdentity> => {
212
- const contact = await (await this.dbConnection).getRepository(ContactEntity).findOne({
213
- where: { id: contactId },
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 (!contact) {
217
- return Promise.reject(Error(`No contact found for id: ${contactId}`))
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.hasCorrectConfig(identity.connection.type, identity.connection.config)) {
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.contact = contact
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 this.identityFrom(result)
220
+ return identityFrom(result)
238
221
  }
239
222
 
240
- updateIdentity = async ({ identity }: IUpdateIdentityArgs): Promise<IIdentity> => {
241
- const result = await (await this.dbConnection).getRepository(IdentityEntity).findOne({
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.hasCorrectConfig(identity.connection.type, identity.connection.config)) {
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 (await this.dbConnection).getRepository(IdentityEntity).save(identity, { transaction: true })
244
+ const updatedResult: IdentityEntity = await identityRepository.save(identity, { transaction: true })
261
245
 
262
- return this.identityFrom(updatedResult)
246
+ return identityFrom(updatedResult)
263
247
  }
264
248
 
265
- removeIdentity = async ({ identityId }: IRemoveIdentityArgs): Promise<void> => {
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
- private contactFrom = (contact: ContactEntity): IContact => {
280
- return {
281
- id: contact.id,
282
- name: contact.name,
283
- alias: contact.alias,
284
- uri: contact.uri,
285
- roles: [...new Set(contact.identities?.flatMap((identity) => identity.roles))] ?? [],
286
- identities: contact.identities ? contact.identities.map((identity: IdentityEntity) => this.identityFrom(identity)) : [],
287
- createdAt: contact.createdAt,
288
- lastUpdatedAt: contact.lastUpdatedAt,
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
- private identityFrom = (identity: IdentityEntity): IIdentity => {
293
- return {
294
- id: identity.id,
295
- alias: identity.alias,
296
- roles: identity.roles,
297
- identifier: this.correlationIdentifierFrom(identity.identifier),
298
- ...(identity.connection && { connection: this.connectionFrom(identity.connection) }),
299
- metadata: identity.metadata ? identity.metadata.map((item: IdentityMetadataItemEntity) => this.metadataItemFrom(item)) : [],
300
- createdAt: identity.createdAt,
301
- lastUpdatedAt: identity.createdAt,
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
- private correlationIdentifierFrom = (identifier: CorrelationIdentifierEntity): ICorrelationIdentifier => {
306
- return {
307
- id: identifier.id,
308
- type: identifier.type,
309
- correlationId: identifier.correlationId,
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
- private metadataItemFrom = (item: IdentityMetadataItemEntity): IMetadataItem => {
314
- return {
315
- id: item.id,
316
- label: item.label,
317
- value: item.value,
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
- private connectionFrom = (connection: ConnectionEntity): IConnection => {
322
- return {
323
- id: connection.id,
324
- type: connection.type,
325
- config: this.configFrom(connection.type, connection.config),
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 configFrom = (type: ConnectionTypeEnum, config: BaseConfigEntity): ConnectionConfig => {
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 hasCorrectConfig(type: ConnectionTypeEnum, config: BasicConnectionConfig): boolean {
426
+ private hasCorrectPartyType(type: PartyTypeEnum, contact: NonPersistedContact): boolean {
356
427
  switch (type) {
357
- case ConnectionTypeEnum.OPENID_CONNECT:
358
- return this.isOpenIdConfig(config)
359
- case ConnectionTypeEnum.SIOPv2:
360
- return this.isDidAuthConfig(config)
428
+ case PartyTypeEnum.NATURAL_PERSON:
429
+ return isNaturalPerson(contact)
430
+ case PartyTypeEnum.ORGANIZATION:
431
+ return isOrganization(contact)
361
432
  default:
362
- throw new Error('Connection type not supported')
433
+ throw new Error('Party type not supported')
363
434
  }
364
435
  }
365
436
 
366
- private isOpenIdConfig = (config: BasicConnectionConfig): config is IOpenIdConfig =>
367
- 'clientSecret' in config && 'issuer' in config && 'redirectUrl' in config
437
+ private async deleteIdentities(identities: Array<IdentityEntity>): Promise<void> {
438
+ debug('Removing identities', identities)
368
439
 
369
- private isDidAuthConfig = (config: BasicConnectionConfig): config is IDidAuthConfig =>
370
- 'identifier' in config && 'redirectUrl' in config && 'sessionId' in config
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
  }