@sphereon/ssi-sdk.data-store 0.15.2-unstable.9 → 0.15.2-unstable.91

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,14 +1,24 @@
1
- import { IContact, IIdentity, IAddIdentityArgs, IGetIdentityArgs, IGetIdentitiesArgs, IGetContactArgs, IRemoveIdentityArgs, IUpdateIdentityArgs, IAddContactArgs, IGetContactsArgs, IRemoveContactArgs, IUpdateContactArgs } from '../types';
1
+ import { Party, Identity, AddIdentityArgs, GetIdentityArgs, GetIdentitiesArgs, GetPartyArgs, RemoveIdentityArgs, UpdateIdentityArgs, AddPartyArgs, GetPartiesArgs, RemovePartyArgs, UpdatePartyArgs, AddRelationshipArgs, PartyRelationship, RemoveRelationshipArgs, AddPartyTypeArgs, PartyType, GetPartyTypeArgs, UpdatePartyTypeArgs, GetPartyTypesArgs, RemovePartyTypeArgs, GetRelationshipsArgs, GetRelationshipArgs, UpdateRelationshipArgs } from '../types';
2
2
  export declare abstract class AbstractContactStore {
3
- abstract getContact(args: IGetContactArgs): Promise<IContact>;
4
- abstract getContacts(args?: IGetContactsArgs): Promise<Array<IContact>>;
5
- abstract addContact(args: IAddContactArgs): Promise<IContact>;
6
- abstract updateContact(args: IUpdateContactArgs): Promise<IContact>;
7
- abstract removeContact(args: IRemoveContactArgs): Promise<void>;
8
- abstract getIdentity(args: IGetIdentityArgs): Promise<IIdentity>;
9
- abstract getIdentities(args: IGetIdentitiesArgs): Promise<Array<IIdentity>>;
10
- abstract addIdentity(args: IAddIdentityArgs): Promise<IIdentity>;
11
- abstract updateIdentity(args: IUpdateIdentityArgs): Promise<IIdentity>;
12
- abstract removeIdentity(args: IRemoveIdentityArgs): Promise<void>;
3
+ abstract getParty(args: GetPartyArgs): Promise<Party>;
4
+ abstract getParties(args?: GetPartiesArgs): Promise<Array<Party>>;
5
+ abstract addParty(args: AddPartyArgs): Promise<Party>;
6
+ abstract updateParty(args: UpdatePartyArgs): Promise<Party>;
7
+ abstract removeParty(args: RemovePartyArgs): Promise<void>;
8
+ abstract getIdentity(args: GetIdentityArgs): Promise<Identity>;
9
+ abstract getIdentities(args?: GetIdentitiesArgs): Promise<Array<Identity>>;
10
+ abstract addIdentity(args: AddIdentityArgs): Promise<Identity>;
11
+ abstract updateIdentity(args: UpdateIdentityArgs): Promise<Identity>;
12
+ abstract removeIdentity(args: RemoveIdentityArgs): Promise<void>;
13
+ abstract getRelationship(args: GetRelationshipArgs): Promise<PartyRelationship>;
14
+ abstract getRelationships(args?: GetRelationshipsArgs): Promise<Array<PartyRelationship>>;
15
+ abstract addRelationship(args: AddRelationshipArgs): Promise<PartyRelationship>;
16
+ abstract updateRelationship(args: UpdateRelationshipArgs): Promise<PartyRelationship>;
17
+ abstract removeRelationship(args: RemoveRelationshipArgs): Promise<void>;
18
+ abstract getPartyType(args: GetPartyTypeArgs): Promise<PartyType>;
19
+ abstract getPartyTypes(args?: GetPartyTypesArgs): Promise<Array<PartyType>>;
20
+ abstract addPartyType(args: AddPartyTypeArgs): Promise<PartyType>;
21
+ abstract updatePartyType(args: UpdatePartyTypeArgs): Promise<PartyType>;
22
+ abstract removePartyType(args: RemovePartyTypeArgs): Promise<void>;
13
23
  }
14
24
  //# sourceMappingURL=AbstractContactStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractContactStore.d.ts","sourceRoot":"","sources":["../../src/contact/AbstractContactStore.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,UAAU,CAAA;AAEjB,8BAAsB,oBAAoB;IACxC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC7D,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACvE,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC7D,QAAQ,CAAC,aAAa,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,IAAI,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC3E,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IACjE,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC;IACvE,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;CACnE"}
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractContactStore.js","sourceRoot":"","sources":["../../src/contact/AbstractContactStore.ts"],"names":[],"mappings":";;;AAeA,MAAsB,oBAAoB;CAWzC;AAXD,oDAWC"}
1
+ {"version":3,"file":"AbstractContactStore.js","sourceRoot":"","sources":["../../src/contact/AbstractContactStore.ts"],"names":[],"mappings":";;;AA2BA,MAAsB,oBAAoB;CAqBzC;AArBD,oDAqBC"}
@@ -1,29 +1,33 @@
1
1
  import { OrPromise } from '@sphereon/ssi-types';
2
- import { AbstractContactStore } from './AbstractContactStore';
3
- import { IAddIdentityArgs, IGetIdentityArgs, IGetIdentitiesArgs, IGetContactArgs, IRemoveIdentityArgs, IUpdateIdentityArgs, IGetContactsArgs, IAddContactArgs, IUpdateContactArgs, IRemoveContactArgs, IContact, IIdentity } from '../types';
4
2
  import { DataSource } from 'typeorm';
3
+ import { AbstractContactStore } from './AbstractContactStore';
4
+ import { AddIdentityArgs, GetIdentityArgs, GetIdentitiesArgs, GetPartyArgs, RemoveIdentityArgs, UpdateIdentityArgs, GetPartiesArgs, AddPartyArgs, UpdatePartyArgs, RemovePartyArgs, Party, Identity, RemoveRelationshipArgs, PartyRelationship, AddRelationshipArgs, GetRelationshipArgs, AddPartyTypeArgs, PartyType, GetPartyTypeArgs, GetPartyTypesArgs, UpdatePartyTypeArgs, RemovePartyTypeArgs, GetRelationshipsArgs, UpdateRelationshipArgs } from '../types';
5
5
  export declare class ContactStore extends AbstractContactStore {
6
6
  private readonly dbConnection;
7
7
  constructor(dbConnection: OrPromise<DataSource>);
8
- getContact: ({ contactId }: IGetContactArgs) => Promise<IContact>;
9
- getContacts: (args?: IGetContactsArgs) => Promise<Array<IContact>>;
10
- addContact: (args: IAddContactArgs) => Promise<IContact>;
11
- updateContact: ({ contact }: IUpdateContactArgs) => Promise<IContact>;
12
- removeContact: ({ contactId }: IRemoveContactArgs) => Promise<void>;
8
+ getParty: ({ partyId }: GetPartyArgs) => Promise<Party>;
9
+ getParties: (args?: GetPartiesArgs) => Promise<Array<Party>>;
10
+ addParty: (args: AddPartyArgs) => Promise<Party>;
11
+ updateParty: ({ party }: UpdatePartyArgs) => Promise<Party>;
12
+ removeParty: ({ partyId }: RemovePartyArgs) => Promise<void>;
13
+ getIdentity: ({ identityId }: GetIdentityArgs) => Promise<Identity>;
14
+ getIdentities: (args?: GetIdentitiesArgs) => Promise<Array<Identity>>;
15
+ addIdentity: ({ identity, partyId }: AddIdentityArgs) => Promise<Identity>;
16
+ updateIdentity: ({ identity }: UpdateIdentityArgs) => Promise<Identity>;
17
+ removeIdentity: ({ identityId }: RemoveIdentityArgs) => Promise<void>;
18
+ addRelationship: ({ leftId, rightId }: AddRelationshipArgs) => Promise<PartyRelationship>;
19
+ getRelationship: ({ relationshipId }: GetRelationshipArgs) => Promise<PartyRelationship>;
20
+ getRelationships: (args?: GetRelationshipsArgs) => Promise<Array<PartyRelationship>>;
21
+ updateRelationship: ({ relationship }: UpdateRelationshipArgs) => Promise<PartyRelationship>;
22
+ removeRelationship: ({ relationshipId }: RemoveRelationshipArgs) => Promise<void>;
23
+ addPartyType: (args: AddPartyTypeArgs) => Promise<PartyType>;
24
+ getPartyType: ({ partyTypeId }: GetPartyTypeArgs) => Promise<PartyType>;
25
+ getPartyTypes: (args?: GetPartyTypesArgs) => Promise<Array<PartyType>>;
26
+ updatePartyType: ({ partyType }: UpdatePartyTypeArgs) => Promise<PartyType>;
27
+ removePartyType: ({ partyTypeId }: RemovePartyTypeArgs) => Promise<void>;
28
+ private hasCorrectConnectionConfig;
29
+ private hasCorrectPartyType;
13
30
  private deleteIdentities;
14
- getIdentity: ({ identityId }: IGetIdentityArgs) => Promise<IIdentity>;
15
- getIdentities: (args?: IGetIdentitiesArgs) => Promise<Array<IIdentity>>;
16
- addIdentity: ({ identity, contactId }: IAddIdentityArgs) => Promise<IIdentity>;
17
- updateIdentity: ({ identity }: IUpdateIdentityArgs) => Promise<IIdentity>;
18
- removeIdentity: ({ identityId }: IRemoveIdentityArgs) => Promise<void>;
19
- private contactFrom;
20
- private identityFrom;
21
- private correlationIdentifierFrom;
22
- private metadataItemFrom;
23
- private connectionFrom;
24
- private configFrom;
25
- private hasCorrectConfig;
26
- private isOpenIdConfig;
27
- private isDidAuthConfig;
31
+ private assertRelationshipSides;
28
32
  }
29
33
  //# sourceMappingURL=ContactStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContactStore.d.ts","sourceRoot":"","sources":["../../src/contact/ContactStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAMlB,QAAQ,EAGR,SAAS,EAGV,MAAM,UAAU,CAAA;AASjB,OAAO,EAAE,UAAU,EAAM,MAAM,SAAS,CAAA;AAIxC,qBAAa,YAAa,SAAQ,oBAAoB;IACpD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuB;gBAExC,YAAY,EAAE,SAAS,CAAC,UAAU,CAAC;IAK/C,UAAU,kBAAyB,eAAe,KAAG,QAAQ,QAAQ,CAAC,CAUrE;IAED,WAAW,UAAiB,gBAAgB,KAAG,QAAQ,MA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AQ,IAAI,CAAC,CAarF;IAED,YAAY,SAAgB,gBAAgB,KAAG,QAAQ,SAAS,CAAC,CAMhE;IAED,YAAY,oBAA2B,gBAAgB,KAAG,QAAQ,SAAS,CAAC,CAU3E;IAED,aAAa,UAAiB,iBAAiB,KAAG,QAAQ,MAAM,SAAS,CAAC,CAAC,CAa1E;IAED,eAAe,kBAAyB,mBAAmB,KAAG,QAAQ,SAAS,CAAC,CAc/E;IAED,eAAe,oBAA2B,mBAAmB,KAAG,QAAQ,IAAI,CAAC,CAyB5E;IAED,OAAO,CAAC,0BAA0B;IAWlC,OAAO,CAAC,mBAAmB;YAWb,gBAAgB;YAwChB,uBAAuB;CAkBtC"}
@@ -13,91 +13,93 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ContactStore = void 0;
16
+ const typeorm_1 = require("typeorm");
16
17
  const debug_1 = __importDefault(require("debug"));
17
18
  const AbstractContactStore_1 = require("./AbstractContactStore");
18
- const types_1 = require("../types");
19
- const ContactEntity_1 = require("../entities/contact/ContactEntity");
19
+ const PartyEntity_1 = require("../entities/contact/PartyEntity");
20
20
  const IdentityEntity_1 = require("../entities/contact/IdentityEntity");
21
21
  const IdentityMetadataItemEntity_1 = require("../entities/contact/IdentityMetadataItemEntity");
22
22
  const CorrelationIdentifierEntity_1 = require("../entities/contact/CorrelationIdentifierEntity");
23
23
  const ConnectionEntity_1 = require("../entities/contact/ConnectionEntity");
24
24
  const BaseConfigEntity_1 = require("../entities/contact/BaseConfigEntity");
25
- const typeorm_1 = require("typeorm");
25
+ const PartyRelationshipEntity_1 = require("../entities/contact/PartyRelationshipEntity");
26
+ const PartyTypeEntity_1 = require("../entities/contact/PartyTypeEntity");
27
+ const MappingUtils_1 = require("../utils/contact/MappingUtils");
28
+ const types_1 = require("../types");
26
29
  const debug = (0, debug_1.default)('sphereon:ssi-sdk:contact-store');
27
30
  class ContactStore extends AbstractContactStore_1.AbstractContactStore {
28
31
  constructor(dbConnection) {
29
32
  super();
30
- this.getContact = ({ contactId }) => __awaiter(this, void 0, void 0, function* () {
31
- const result = yield (yield this.dbConnection).getRepository(ContactEntity_1.ContactEntity).findOne({
32
- where: { id: contactId },
33
+ this.getParty = ({ partyId }) => __awaiter(this, void 0, void 0, function* () {
34
+ const result = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
35
+ where: { id: partyId },
33
36
  });
34
37
  if (!result) {
35
- return Promise.reject(Error(`No contact found for id: ${contactId}`));
38
+ return Promise.reject(Error(`No party found for id: ${partyId}`));
36
39
  }
37
- return this.contactFrom(result);
40
+ return (0, MappingUtils_1.partyFrom)(result);
38
41
  });
39
- this.getContacts = (args) => __awaiter(this, void 0, void 0, function* () {
40
- const initialResult = yield (yield this.dbConnection).getRepository(ContactEntity_1.ContactEntity).find(Object.assign({}, ((args === null || args === void 0 ? void 0 : args.filter) && { where: args === null || args === void 0 ? void 0 : args.filter })));
41
- const result = yield (yield this.dbConnection).getRepository(ContactEntity_1.ContactEntity).find({
42
+ this.getParties = (args) => __awaiter(this, void 0, void 0, function* () {
43
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
44
+ const initialResult = yield partyRepository.find(Object.assign({}, ((args === null || args === void 0 ? void 0 : args.filter) && { where: args === null || args === void 0 ? void 0 : args.filter })));
45
+ const result = yield partyRepository.find({
42
46
  where: {
43
- id: (0, typeorm_1.In)(initialResult.map((contact) => contact.id)),
47
+ id: (0, typeorm_1.In)(initialResult.map((party) => party.id)),
44
48
  },
45
49
  });
46
- return result.map((contact) => this.contactFrom(contact));
50
+ return result.map((party) => (0, MappingUtils_1.partyFrom)(party));
47
51
  });
48
- this.addContact = (args) => __awaiter(this, void 0, void 0, function* () {
49
- const { name, alias, uri, identities } = args;
50
- const result = yield (yield this.dbConnection).getRepository(ContactEntity_1.ContactEntity).findOne({
51
- where: [{ name }, { alias }],
52
- });
53
- if (result) {
54
- return Promise.reject(Error(`Duplicate names or aliases are not allowed. Name: ${name}, Alias: ${alias}`));
52
+ this.addParty = (args) => __awaiter(this, void 0, void 0, function* () {
53
+ const { identities, contact, partyType } = args;
54
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
55
+ if (!this.hasCorrectPartyType(partyType.type, contact)) {
56
+ return Promise.reject(Error(`Party type ${partyType.type}, does not match for provided contact`));
55
57
  }
56
58
  for (const identity of identities !== null && identities !== void 0 ? identities : []) {
57
59
  if (identity.identifier.type === types_1.CorrelationIdentifierEnum.URL) {
58
60
  if (!identity.connection) {
59
61
  return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
60
62
  }
61
- if (!this.hasCorrectConfig(identity.connection.type, identity.connection.config)) {
63
+ if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
62
64
  return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
63
65
  }
64
66
  }
65
67
  }
66
- const contactEntity = (0, ContactEntity_1.contactEntityFrom)({ name, alias, uri, identities });
67
- debug('Adding contact', name);
68
- const createdResult = yield (yield this.dbConnection).getRepository(ContactEntity_1.ContactEntity).save(contactEntity);
69
- return this.contactFrom(createdResult);
68
+ const partyEntity = (0, MappingUtils_1.partyEntityFrom)(args);
69
+ debug('Adding party', args);
70
+ const createdResult = yield partyRepository.save(partyEntity);
71
+ return (0, MappingUtils_1.partyFrom)(createdResult);
70
72
  });
71
- this.updateContact = ({ contact }) => __awaiter(this, void 0, void 0, function* () {
72
- const result = yield (yield this.dbConnection).getRepository(ContactEntity_1.ContactEntity).findOne({
73
- where: { id: contact.id },
73
+ this.updateParty = ({ party }) => __awaiter(this, void 0, void 0, function* () {
74
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
75
+ const result = yield partyRepository.findOne({
76
+ where: { id: party.id },
74
77
  });
75
78
  if (!result) {
76
- return Promise.reject(Error(`No contact found for id: ${contact.id}`));
79
+ return Promise.reject(Error(`No party found for id: ${party.id}`));
77
80
  }
78
- const updatedContact = Object.assign(Object.assign({}, contact), { identities: result.identities });
79
- debug('Updating contact', contact);
80
- const updatedResult = yield (yield this.dbConnection).getRepository(ContactEntity_1.ContactEntity).save(updatedContact, { transaction: true });
81
- return this.contactFrom(updatedResult);
81
+ const updatedParty = Object.assign(Object.assign({}, party), { identities: result.identities, type: result.partyType, relationships: result.relationships, electronicAddresses: result.electronicAddresses });
82
+ debug('Updating party', party);
83
+ const updatedResult = yield partyRepository.save(updatedParty, { transaction: true });
84
+ return (0, MappingUtils_1.partyFrom)(updatedResult);
82
85
  });
83
- this.removeContact = ({ contactId }) => __awaiter(this, void 0, void 0, function* () {
84
- debug('Removing contact', contactId);
85
- (yield this.dbConnection)
86
- .getRepository(ContactEntity_1.ContactEntity)
87
- .findOneById(contactId)
88
- .then((contact) => __awaiter(this, void 0, void 0, function* () {
89
- if (!contact) {
90
- yield Promise.reject(Error(`Unable to find the contact with id to remove: ${contactId}`));
86
+ this.removeParty = ({ partyId }) => __awaiter(this, void 0, void 0, function* () {
87
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
88
+ debug('Removing party', partyId);
89
+ partyRepository
90
+ .findOneById(partyId)
91
+ .then((party) => __awaiter(this, void 0, void 0, function* () {
92
+ if (!party) {
93
+ yield Promise.reject(Error(`Unable to find the party with id to remove: ${partyId}`));
91
94
  }
92
95
  else {
93
- yield this.deleteIdentities(contact.identities);
94
- yield (yield this.dbConnection)
95
- .getRepository(ContactEntity_1.ContactEntity)
96
- .delete({ id: contactId })
97
- .catch((error) => Promise.reject(Error(`Unable to remove contact with id: ${contactId}. ${error}`)));
96
+ yield this.deleteIdentities(party.identities);
97
+ yield partyRepository
98
+ .delete({ id: partyId })
99
+ .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
98
100
  }
99
101
  }))
100
- .catch((error) => Promise.reject(Error(`Unable to remove contact with id: ${contactId}. ${error}`)));
102
+ .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
101
103
  });
102
104
  this.getIdentity = ({ identityId }) => __awaiter(this, void 0, void 0, function* () {
103
105
  const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
@@ -106,42 +108,44 @@ class ContactStore extends AbstractContactStore_1.AbstractContactStore {
106
108
  if (!result) {
107
109
  return Promise.reject(Error(`No identity found for id: ${identityId}`));
108
110
  }
109
- return this.identityFrom(result);
111
+ return (0, MappingUtils_1.identityFrom)(result);
110
112
  });
111
113
  this.getIdentities = (args) => __awaiter(this, void 0, void 0, function* () {
112
- const initialResult = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).find(Object.assign({}, ((args === null || args === void 0 ? void 0 : args.filter) && { where: args === null || args === void 0 ? void 0 : args.filter })));
113
- const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).find({
114
+ const identityRepository = (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity);
115
+ const initialResult = yield identityRepository.find(Object.assign({}, ((args === null || args === void 0 ? void 0 : args.filter) && { where: args === null || args === void 0 ? void 0 : args.filter })));
116
+ const result = yield identityRepository.find({
114
117
  where: {
115
118
  id: (0, typeorm_1.In)(initialResult.map((identity) => identity.id)),
116
119
  },
117
120
  });
118
- return result.map((identity) => this.identityFrom(identity));
121
+ return result.map((identity) => (0, MappingUtils_1.identityFrom)(identity));
119
122
  });
120
- this.addIdentity = ({ identity, contactId }) => __awaiter(this, void 0, void 0, function* () {
121
- const contact = yield (yield this.dbConnection).getRepository(ContactEntity_1.ContactEntity).findOne({
122
- where: { id: contactId },
123
+ this.addIdentity = ({ identity, partyId }) => __awaiter(this, void 0, void 0, function* () {
124
+ const party = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
125
+ where: { id: partyId },
123
126
  });
124
- if (!contact) {
125
- return Promise.reject(Error(`No contact found for id: ${contactId}`));
127
+ if (!party) {
128
+ return Promise.reject(Error(`No party found for id: ${partyId}`));
126
129
  }
127
130
  if (identity.identifier.type === types_1.CorrelationIdentifierEnum.URL) {
128
131
  if (!identity.connection) {
129
132
  return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
130
133
  }
131
- if (!this.hasCorrectConfig(identity.connection.type, identity.connection.config)) {
134
+ if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
132
135
  return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
133
136
  }
134
137
  }
135
- const identityEntity = (0, IdentityEntity_1.identityEntityFrom)(identity);
136
- identityEntity.contact = contact;
138
+ const identityEntity = (0, MappingUtils_1.identityEntityFrom)(identity);
139
+ identityEntity.party = party;
137
140
  debug('Adding identity', identity);
138
141
  const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).save(identityEntity, {
139
142
  transaction: true,
140
143
  });
141
- return this.identityFrom(result);
144
+ return (0, MappingUtils_1.identityFrom)(result);
142
145
  });
143
146
  this.updateIdentity = ({ identity }) => __awaiter(this, void 0, void 0, function* () {
144
- const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
147
+ const identityRepository = (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity);
148
+ const result = yield identityRepository.findOne({
145
149
  where: { id: identity.id },
146
150
  });
147
151
  if (!result) {
@@ -151,13 +155,13 @@ class ContactStore extends AbstractContactStore_1.AbstractContactStore {
151
155
  if (!identity.connection) {
152
156
  return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
153
157
  }
154
- if (!this.hasCorrectConfig(identity.connection.type, identity.connection.config)) {
158
+ if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
155
159
  return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
156
160
  }
157
161
  }
158
162
  debug('Updating identity', identity);
159
- const updatedResult = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).save(identity, { transaction: true });
160
- return this.identityFrom(updatedResult);
163
+ const updatedResult = yield identityRepository.save(identity, { transaction: true });
164
+ return (0, MappingUtils_1.identityFrom)(updatedResult);
161
165
  });
162
166
  this.removeIdentity = ({ identityId }) => __awaiter(this, void 0, void 0, function* () {
163
167
  const identity = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
@@ -169,72 +173,141 @@ class ContactStore extends AbstractContactStore_1.AbstractContactStore {
169
173
  debug('Removing identity', identityId);
170
174
  yield this.deleteIdentities([identity]);
171
175
  });
172
- this.contactFrom = (contact) => {
173
- var _a, _b;
174
- return {
175
- id: contact.id,
176
- name: contact.name,
177
- alias: contact.alias,
178
- uri: contact.uri,
179
- roles: (_b = [...new Set((_a = contact.identities) === null || _a === void 0 ? void 0 : _a.flatMap((identity) => identity.roles))]) !== null && _b !== void 0 ? _b : [],
180
- identities: contact.identities ? contact.identities.map((identity) => this.identityFrom(identity)) : [],
181
- createdAt: contact.createdAt,
182
- lastUpdatedAt: contact.lastUpdatedAt,
183
- };
184
- };
185
- this.identityFrom = (identity) => {
186
- return Object.assign(Object.assign({ id: identity.id, alias: identity.alias, roles: identity.roles, identifier: this.correlationIdentifierFrom(identity.identifier) }, (identity.connection && { connection: this.connectionFrom(identity.connection) })), { metadata: identity.metadata ? identity.metadata.map((item) => this.metadataItemFrom(item)) : [], createdAt: identity.createdAt, lastUpdatedAt: identity.createdAt });
187
- };
188
- this.correlationIdentifierFrom = (identifier) => {
189
- return {
190
- id: identifier.id,
191
- type: identifier.type,
192
- correlationId: identifier.correlationId,
193
- };
194
- };
195
- this.metadataItemFrom = (item) => {
196
- return {
197
- id: item.id,
198
- label: item.label,
199
- value: item.value,
200
- };
201
- };
202
- this.connectionFrom = (connection) => {
203
- return {
204
- id: connection.id,
205
- type: connection.type,
206
- config: this.configFrom(connection.type, connection.config),
207
- };
208
- };
209
- this.configFrom = (type, config) => {
210
- switch (type) {
211
- case types_1.ConnectionTypeEnum.OPENID_CONNECT:
212
- return {
213
- id: config.id,
214
- clientId: config.clientId,
215
- clientSecret: config.clientSecret,
216
- scopes: config.scopes,
217
- issuer: config.issuer,
218
- redirectUrl: config.redirectUrl,
219
- dangerouslyAllowInsecureHttpRequests: config.dangerouslyAllowInsecureHttpRequests,
220
- clientAuthMethod: config.clientAuthMethod,
221
- };
222
- case types_1.ConnectionTypeEnum.SIOPv2:
223
- return {
224
- id: config.id,
225
- identifier: { did: config.identifier, provider: '', keys: [], services: [] },
226
- stateId: '',
227
- redirectUrl: config.redirectUrl,
228
- sessionId: config.sessionId,
229
- };
230
- default:
231
- throw new Error('Connection type not supported');
176
+ this.addRelationship = ({ leftId, rightId }) => __awaiter(this, void 0, void 0, function* () {
177
+ return this.assertRelationshipSides(leftId, rightId).then(() => __awaiter(this, void 0, void 0, function* () {
178
+ const relationship = (0, MappingUtils_1.partyRelationshipEntityFrom)({
179
+ leftId,
180
+ rightId,
181
+ });
182
+ debug('Adding party relationship', relationship);
183
+ const createdResult = yield (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity).save(relationship);
184
+ return (0, MappingUtils_1.partyRelationshipFrom)(createdResult);
185
+ }));
186
+ });
187
+ this.getRelationship = ({ relationshipId }) => __awaiter(this, void 0, void 0, function* () {
188
+ const result = yield (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity).findOne({
189
+ where: { id: relationshipId },
190
+ });
191
+ if (!result) {
192
+ return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
193
+ }
194
+ return (0, MappingUtils_1.partyRelationshipFrom)(result);
195
+ });
196
+ this.getRelationships = (args) => __awaiter(this, void 0, void 0, function* () {
197
+ const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
198
+ const initialResult = yield partyRelationshipRepository.find(Object.assign({}, ((args === null || args === void 0 ? void 0 : args.filter) && { where: args === null || args === void 0 ? void 0 : args.filter })));
199
+ const result = yield partyRelationshipRepository.find({
200
+ where: {
201
+ id: (0, typeorm_1.In)(initialResult.map((partyRelationship) => partyRelationship.id)),
202
+ },
203
+ });
204
+ return result.map((partyRelationship) => (0, MappingUtils_1.partyRelationshipFrom)(partyRelationship));
205
+ });
206
+ this.updateRelationship = ({ relationship }) => __awaiter(this, void 0, void 0, function* () {
207
+ const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
208
+ const result = yield partyRelationshipRepository.findOne({
209
+ where: { id: relationship.id },
210
+ });
211
+ if (!result) {
212
+ return Promise.reject(Error(`No party relationship found for id: ${relationship.id}`));
232
213
  }
233
- };
234
- this.isOpenIdConfig = (config) => 'clientSecret' in config && 'issuer' in config && 'redirectUrl' in config;
235
- this.isDidAuthConfig = (config) => 'identifier' in config && 'redirectUrl' in config && 'sessionId' in config;
214
+ return this.assertRelationshipSides(relationship.leftId, relationship.rightId).then(() => __awaiter(this, void 0, void 0, function* () {
215
+ debug('Updating party relationship', relationship);
216
+ const updatedResult = yield partyRelationshipRepository.save(relationship, { transaction: true });
217
+ return (0, MappingUtils_1.partyRelationshipFrom)(updatedResult);
218
+ }));
219
+ });
220
+ this.removeRelationship = ({ relationshipId }) => __awaiter(this, void 0, void 0, function* () {
221
+ const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
222
+ const relationship = yield partyRelationshipRepository.findOne({
223
+ where: { id: relationshipId },
224
+ });
225
+ if (!relationship) {
226
+ return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
227
+ }
228
+ debug('Removing relationship', relationshipId);
229
+ yield partyRelationshipRepository.delete(relationshipId);
230
+ });
231
+ this.addPartyType = (args) => __awaiter(this, void 0, void 0, function* () {
232
+ const partyEntity = (0, MappingUtils_1.partyTypeEntityFrom)(args);
233
+ debug('Adding party type', args);
234
+ const createdResult = yield (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity).save(partyEntity);
235
+ return (0, MappingUtils_1.partyTypeFrom)(createdResult);
236
+ });
237
+ this.getPartyType = ({ partyTypeId }) => __awaiter(this, void 0, void 0, function* () {
238
+ const result = yield (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity).findOne({
239
+ where: { id: partyTypeId },
240
+ });
241
+ if (!result) {
242
+ return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
243
+ }
244
+ return (0, MappingUtils_1.partyTypeFrom)(result);
245
+ });
246
+ this.getPartyTypes = (args) => __awaiter(this, void 0, void 0, function* () {
247
+ const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
248
+ const initialResult = yield partyTypeRepository.find(Object.assign({}, ((args === null || args === void 0 ? void 0 : args.filter) && { where: args === null || args === void 0 ? void 0 : args.filter })));
249
+ const result = yield partyTypeRepository.find({
250
+ where: {
251
+ id: (0, typeorm_1.In)(initialResult.map((partyType) => partyType.id)),
252
+ },
253
+ });
254
+ return result.map((partyType) => (0, MappingUtils_1.partyTypeFrom)(partyType));
255
+ });
256
+ this.updatePartyType = ({ partyType }) => __awaiter(this, void 0, void 0, function* () {
257
+ const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
258
+ const result = yield partyTypeRepository.findOne({
259
+ where: { id: partyType.id },
260
+ });
261
+ if (!result) {
262
+ return Promise.reject(Error(`No party type found for id: ${partyType.id}`));
263
+ }
264
+ debug('Updating party type', partyType);
265
+ const updatedResult = yield partyTypeRepository.save(partyType, { transaction: true });
266
+ return (0, MappingUtils_1.partyTypeFrom)(updatedResult);
267
+ });
268
+ this.removePartyType = ({ partyTypeId }) => __awaiter(this, void 0, void 0, function* () {
269
+ const parties = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).find({
270
+ where: {
271
+ partyType: {
272
+ id: partyTypeId,
273
+ },
274
+ },
275
+ });
276
+ if (parties.length > 0) {
277
+ return Promise.reject(Error(`Unable to remove party type with id: ${partyTypeId}. Party type is in use`));
278
+ }
279
+ const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
280
+ const partyType = yield partyTypeRepository.findOne({
281
+ where: { id: partyTypeId },
282
+ });
283
+ if (!partyType) {
284
+ return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
285
+ }
286
+ debug('Removing party type', partyTypeId);
287
+ yield partyTypeRepository.delete(partyTypeId);
288
+ });
236
289
  this.dbConnection = dbConnection;
237
290
  }
291
+ hasCorrectConnectionConfig(type, config) {
292
+ switch (type) {
293
+ case types_1.ConnectionTypeEnum.OPENID_CONNECT:
294
+ return (0, MappingUtils_1.isOpenIdConfig)(config);
295
+ case types_1.ConnectionTypeEnum.SIOPv2:
296
+ return (0, MappingUtils_1.isDidAuthConfig)(config);
297
+ default:
298
+ throw new Error('Connection type not supported');
299
+ }
300
+ }
301
+ hasCorrectPartyType(type, contact) {
302
+ switch (type) {
303
+ case types_1.PartyTypeEnum.NATURAL_PERSON:
304
+ return (0, MappingUtils_1.isNaturalPerson)(contact);
305
+ case types_1.PartyTypeEnum.ORGANIZATION:
306
+ return (0, MappingUtils_1.isOrganization)(contact);
307
+ default:
308
+ throw new Error('Party type not supported');
309
+ }
310
+ }
238
311
  deleteIdentities(identities) {
239
312
  return __awaiter(this, void 0, void 0, function* () {
240
313
  debug('Removing identities', identities);
@@ -266,15 +339,22 @@ class ContactStore extends AbstractContactStore_1.AbstractContactStore {
266
339
  }));
267
340
  });
268
341
  }
269
- hasCorrectConfig(type, config) {
270
- switch (type) {
271
- case types_1.ConnectionTypeEnum.OPENID_CONNECT:
272
- return this.isOpenIdConfig(config);
273
- case types_1.ConnectionTypeEnum.SIOPv2:
274
- return this.isDidAuthConfig(config);
275
- default:
276
- throw new Error('Connection type not supported');
277
- }
342
+ assertRelationshipSides(leftId, rightId) {
343
+ return __awaiter(this, void 0, void 0, function* () {
344
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
345
+ const leftParty = yield partyRepository.findOne({
346
+ where: { id: leftId },
347
+ });
348
+ if (!leftParty) {
349
+ return Promise.reject(Error(`No party found for left side of the relationship, party id: ${leftId}`));
350
+ }
351
+ const rightParty = yield partyRepository.findOne({
352
+ where: { id: rightId },
353
+ });
354
+ if (!rightParty) {
355
+ return Promise.reject(Error(`No party found for right side of the relationship, party id: ${rightId}`));
356
+ }
357
+ });
278
358
  }
279
359
  }
280
360
  exports.ContactStore = ContactStore;