@sphereon/ssi-sdk.data-store 0.18.1 → 0.18.2-unstable.10

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 (180) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +77 -77
  3. package/dist/contact/AbstractContactStore.d.ts +23 -23
  4. package/dist/contact/AbstractContactStore.js +6 -6
  5. package/dist/contact/ContactStore.d.ts +32 -32
  6. package/dist/contact/ContactStore.js +365 -365
  7. package/dist/entities/contact/BaseConfigEntity.d.ts +6 -6
  8. package/dist/entities/contact/BaseConfigEntity.js +33 -33
  9. package/dist/entities/contact/BaseContactEntity.d.ts +9 -9
  10. package/dist/entities/contact/BaseContactEntity.js +53 -53
  11. package/dist/entities/contact/ConnectionEntity.d.ts +10 -10
  12. package/dist/entities/contact/ConnectionEntity.js +46 -46
  13. package/dist/entities/contact/ContactEntity.d.ts +16 -0
  14. package/dist/entities/contact/ContactEntity.d.ts.map +1 -0
  15. package/dist/entities/contact/ContactEntity.js +164 -0
  16. package/dist/entities/contact/ContactEntity.js.map +1 -0
  17. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +10 -10
  18. package/dist/entities/contact/CorrelationIdentifierEntity.js +71 -71
  19. package/dist/entities/contact/DidAuthConfigEntity.d.ts +6 -6
  20. package/dist/entities/contact/DidAuthConfigEntity.js +32 -32
  21. package/dist/entities/contact/ElectronicAddressEntity.d.ts +13 -13
  22. package/dist/entities/contact/ElectronicAddressEntity.js +91 -91
  23. package/dist/entities/contact/IdentityEntity.d.ts +20 -20
  24. package/dist/entities/contact/IdentityEntity.js +128 -128
  25. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +9 -9
  26. package/dist/entities/contact/IdentityMetadataItemEntity.js +68 -68
  27. package/dist/entities/contact/NaturalPersonEntity.d.ts +8 -8
  28. package/dist/entities/contact/NaturalPersonEntity.js +71 -71
  29. package/dist/entities/contact/OpenIdConfigEntity.d.ts +10 -10
  30. package/dist/entities/contact/OpenIdConfigEntity.js +48 -48
  31. package/dist/entities/contact/OrganizationEntity.d.ts +8 -8
  32. package/dist/entities/contact/OrganizationEntity.js +66 -66
  33. package/dist/entities/contact/PartyEntity.d.ts +19 -19
  34. package/dist/entities/contact/PartyEntity.js +131 -131
  35. package/dist/entities/contact/PartyRelationshipEntity.d.ts +12 -12
  36. package/dist/entities/contact/PartyRelationshipEntity.js +94 -94
  37. package/dist/entities/contact/PartyTypeEntity.d.ts +14 -14
  38. package/dist/entities/contact/PartyTypeEntity.js +103 -103
  39. package/dist/entities/eventLogger/AuditEventEntity.d.ts +26 -26
  40. package/dist/entities/eventLogger/AuditEventEntity.js +123 -123
  41. package/dist/entities/issuanceBranding/BackgroundAttributesEntity.d.ts +10 -10
  42. package/dist/entities/issuanceBranding/BackgroundAttributesEntity.js +73 -73
  43. package/dist/entities/issuanceBranding/BaseLocaleBrandingEntity.d.ts +17 -17
  44. package/dist/entities/issuanceBranding/BaseLocaleBrandingEntity.js +119 -119
  45. package/dist/entities/issuanceBranding/CredentialBrandingEntity.d.ts +14 -14
  46. package/dist/entities/issuanceBranding/CredentialBrandingEntity.js +101 -101
  47. package/dist/entities/issuanceBranding/CredentialLocaleBrandingEntity.d.ts +8 -8
  48. package/dist/entities/issuanceBranding/CredentialLocaleBrandingEntity.js +48 -48
  49. package/dist/entities/issuanceBranding/ImageAttributesEntity.d.ts +13 -13
  50. package/dist/entities/issuanceBranding/ImageAttributesEntity.js +91 -91
  51. package/dist/entities/issuanceBranding/ImageDimensionsEntity.d.ts +8 -8
  52. package/dist/entities/issuanceBranding/ImageDimensionsEntity.js +38 -38
  53. package/dist/entities/issuanceBranding/IssuerBrandingEntity.d.ts +13 -13
  54. package/dist/entities/issuanceBranding/IssuerBrandingEntity.js +94 -94
  55. package/dist/entities/issuanceBranding/IssuerLocaleBrandingEntity.d.ts +8 -8
  56. package/dist/entities/issuanceBranding/IssuerLocaleBrandingEntity.js +48 -48
  57. package/dist/entities/issuanceBranding/TextAttributesEntity.d.ts +8 -8
  58. package/dist/entities/issuanceBranding/TextAttributesEntity.js +61 -61
  59. package/dist/entities/statusList2021/StatusList2021Entity.d.ts +18 -18
  60. package/dist/entities/statusList2021/StatusList2021Entity.js +114 -114
  61. package/dist/entities/statusList2021/StatusList2021EntryEntity.d.ts +10 -10
  62. package/dist/entities/statusList2021/StatusList2021EntryEntity.js +50 -50
  63. package/dist/entities/validators/index.d.ts +6 -6
  64. package/dist/entities/validators/index.js +26 -26
  65. package/dist/eventLogger/AbstractEventLoggerStore.d.ts +6 -6
  66. package/dist/eventLogger/AbstractEventLoggerStore.js +6 -6
  67. package/dist/eventLogger/EventLoggerStore.d.ts +12 -12
  68. package/dist/eventLogger/EventLoggerStore.js +43 -43
  69. package/dist/index.d.ts +41 -41
  70. package/dist/index.js +127 -127
  71. package/dist/issuanceBranding/AbstractIssuanceBrandingStore.d.ts +19 -19
  72. package/dist/issuanceBranding/AbstractIssuanceBrandingStore.js +6 -6
  73. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts +30 -30
  74. package/dist/issuanceBranding/IssuanceBrandingStore.js +374 -374
  75. package/dist/migrations/generic/1-CreateContacts.d.ts +6 -6
  76. package/dist/migrations/generic/1-CreateContacts.js +77 -77
  77. package/dist/migrations/generic/1-CreateIssuanceBranding.d.ts +7 -0
  78. package/dist/migrations/generic/1-CreateIssuanceBranding.d.ts.map +1 -0
  79. package/dist/migrations/generic/1-CreateIssuanceBranding.js +96 -0
  80. package/dist/migrations/generic/1-CreateIssuanceBranding.js.map +1 -0
  81. package/dist/migrations/generic/2-CreateContacts.d.ts +7 -0
  82. package/dist/migrations/generic/2-CreateContacts.d.ts.map +1 -0
  83. package/dist/migrations/generic/2-CreateContacts.js +78 -0
  84. package/dist/migrations/generic/2-CreateContacts.js.map +1 -0
  85. package/dist/migrations/generic/2-CreateIssuanceBranding.d.ts +6 -6
  86. package/dist/migrations/generic/2-CreateIssuanceBranding.js +77 -77
  87. package/dist/migrations/generic/3-CreateContacts.d.ts +6 -6
  88. package/dist/migrations/generic/3-CreateContacts.js +77 -77
  89. package/dist/migrations/generic/3-CreateStatusList.d.ts +7 -0
  90. package/dist/migrations/generic/3-CreateStatusList.d.ts.map +1 -0
  91. package/dist/migrations/generic/3-CreateStatusList.js +72 -0
  92. package/dist/migrations/generic/3-CreateStatusList.js.map +1 -0
  93. package/dist/migrations/generic/4-CreateStatusList.d.ts +6 -6
  94. package/dist/migrations/generic/4-CreateStatusList.js +71 -71
  95. package/dist/migrations/generic/5-CreateAuditEvents.d.ts +6 -6
  96. package/dist/migrations/generic/5-CreateAuditEvents.js +77 -77
  97. package/dist/migrations/generic/index.d.ts +16 -16
  98. package/dist/migrations/generic/index.js +27 -27
  99. package/dist/migrations/index.d.ts +1 -1
  100. package/dist/migrations/index.js +5 -5
  101. package/dist/migrations/internal-migrations-ormconfig.d.ts +6 -6
  102. package/dist/migrations/internal-migrations-ormconfig.js +26 -26
  103. package/dist/migrations/postgres/1659463079428-CreateContacts.d.ts +6 -6
  104. package/dist/migrations/postgres/1659463079428-CreateContacts.js +56 -56
  105. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.d.ts +6 -6
  106. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +68 -68
  107. package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts +6 -6
  108. package/dist/migrations/postgres/1690925872592-CreateContacts.js +68 -68
  109. package/dist/migrations/postgres/1693866470001-CreateStatusList.d.ts +6 -6
  110. package/dist/migrations/postgres/1693866470001-CreateStatusList.js +31 -31
  111. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.d.ts +6 -6
  112. package/dist/migrations/postgres/1701634812183-CreateAuditEvents.js +42 -42
  113. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts +7 -0
  114. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.d.ts.map +1 -0
  115. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js +32 -0
  116. package/dist/migrations/postgres/CreateStatusList1693866470001-CreateStatusList.js.map +1 -0
  117. package/dist/migrations/postgres/uuid.d.ts +3 -0
  118. package/dist/migrations/postgres/uuid.d.ts.map +1 -0
  119. package/dist/migrations/postgres/uuid.js +25 -0
  120. package/dist/migrations/postgres/uuid.js.map +1 -0
  121. package/dist/migrations/sqlite/1659463069549-CreateContacts.d.ts +6 -6
  122. package/dist/migrations/sqlite/1659463069549-CreateContacts.js +78 -78
  123. package/dist/migrations/sqlite/1685628973231-CreateIssuanceBranding.d.ts +6 -6
  124. package/dist/migrations/sqlite/1685628973231-CreateIssuanceBranding.js +88 -88
  125. package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts +6 -6
  126. package/dist/migrations/sqlite/1690925872693-CreateContacts.js +107 -107
  127. package/dist/migrations/sqlite/1693866470000-CreateStatusList.d.ts +6 -6
  128. package/dist/migrations/sqlite/1693866470000-CreateStatusList.js +31 -31
  129. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.d.ts +6 -6
  130. package/dist/migrations/sqlite/1701634819487-CreateAuditEvents.js +28 -28
  131. package/dist/statusList/IStatusListStore.d.ts +19 -19
  132. package/dist/statusList/IStatusListStore.js +2 -2
  133. package/dist/statusList/StatusListStore.d.ts +35 -35
  134. package/dist/statusList/StatusListStore.js +212 -212
  135. package/dist/types/contact/IAbstractContactStore.d.ts +74 -74
  136. package/dist/types/contact/IAbstractContactStore.js +2 -2
  137. package/dist/types/contact/contact.d.ts +173 -173
  138. package/dist/types/contact/contact.js +25 -25
  139. package/dist/types/eventLogger/IAbstractEventLoggerStore.d.ts +9 -9
  140. package/dist/types/eventLogger/IAbstractEventLoggerStore.js +2 -2
  141. package/dist/types/eventLogger/eventLogger.d.ts +2 -2
  142. package/dist/types/eventLogger/eventLogger.js +2 -2
  143. package/dist/types/index.d.ts +9 -9
  144. package/dist/types/index.js +25 -25
  145. package/dist/types/issuanceBranding/IAbstractIssuanceBrandingStore.d.ts +58 -58
  146. package/dist/types/issuanceBranding/IAbstractIssuanceBrandingStore.js +2 -2
  147. package/dist/types/issuanceBranding/issuanceBranding.d.ts +114 -114
  148. package/dist/types/issuanceBranding/issuanceBranding.js +2 -2
  149. package/dist/types/statusList/IAbstractStatusListStore.d.ts +37 -37
  150. package/dist/types/statusList/IAbstractStatusListStore.js +2 -2
  151. package/dist/types/statusList/statusList.d.ts +24 -24
  152. package/dist/types/statusList/statusList.js +2 -2
  153. package/dist/types/validation/validation.d.ts +3 -3
  154. package/dist/types/validation/validation.js +2 -2
  155. package/dist/utils/ValidatorUtils.d.ts +3 -3
  156. package/dist/utils/ValidatorUtils.js +12 -12
  157. package/dist/utils/contact/MappingUtils.d.ts +46 -46
  158. package/dist/utils/contact/MappingUtils.js +290 -290
  159. package/package.json +4 -4
  160. package/src/__tests__/eventLogger.entities.test.ts +73 -73
  161. package/src/__tests__/eventLogger.store.test.ts +136 -136
  162. package/src/contact/ContactStore.ts +501 -501
  163. package/src/entities/eventLogger/AuditEventEntity.ts +99 -99
  164. package/src/entities/statusList2021/StatusList2021Entity.ts +96 -96
  165. package/src/eventLogger/AbstractEventLoggerStore.ts +7 -7
  166. package/src/eventLogger/EventLoggerStore.ts +62 -62
  167. package/src/index.ts +113 -113
  168. package/src/migrations/generic/1-CreateContacts.ts +66 -66
  169. package/src/migrations/generic/2-CreateIssuanceBranding.ts +64 -64
  170. package/src/migrations/generic/3-CreateContacts.ts +66 -66
  171. package/src/migrations/generic/4-CreateStatusList.ts +54 -54
  172. package/src/migrations/generic/5-CreateAuditEvents.ts +66 -66
  173. package/src/migrations/generic/index.ts +27 -27
  174. package/src/migrations/postgres/1693866470001-CreateStatusList.ts +24 -24
  175. package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +33 -33
  176. package/src/migrations/sqlite/1690925872693-CreateContacts.ts +163 -163
  177. package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +15 -15
  178. package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -12
  179. package/src/types/eventLogger/eventLogger.ts +3 -3
  180. package/src/types/index.ts +9 -9
@@ -1,366 +1,366 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ContactStore = void 0;
16
- const typeorm_1 = require("typeorm");
17
- const debug_1 = __importDefault(require("debug"));
18
- const AbstractContactStore_1 = require("./AbstractContactStore");
19
- const PartyEntity_1 = require("../entities/contact/PartyEntity");
20
- const IdentityEntity_1 = require("../entities/contact/IdentityEntity");
21
- const IdentityMetadataItemEntity_1 = require("../entities/contact/IdentityMetadataItemEntity");
22
- const CorrelationIdentifierEntity_1 = require("../entities/contact/CorrelationIdentifierEntity");
23
- const ConnectionEntity_1 = require("../entities/contact/ConnectionEntity");
24
- const BaseConfigEntity_1 = require("../entities/contact/BaseConfigEntity");
25
- const PartyRelationshipEntity_1 = require("../entities/contact/PartyRelationshipEntity");
26
- const PartyTypeEntity_1 = require("../entities/contact/PartyTypeEntity");
27
- const BaseContactEntity_1 = require("../entities/contact/BaseContactEntity");
28
- const MappingUtils_1 = require("../utils/contact/MappingUtils");
29
- const types_1 = require("../types");
30
- const debug = (0, debug_1.default)('sphereon:ssi-sdk:contact-store');
31
- class ContactStore extends AbstractContactStore_1.AbstractContactStore {
32
- constructor(dbConnection) {
33
- super();
34
- this.getParty = ({ partyId }) => __awaiter(this, void 0, void 0, function* () {
35
- const result = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
36
- where: { id: partyId },
37
- });
38
- if (!result) {
39
- return Promise.reject(Error(`No party found for id: ${partyId}`));
40
- }
41
- return (0, MappingUtils_1.partyFrom)(result);
42
- });
43
- this.getParties = (args) => __awaiter(this, void 0, void 0, function* () {
44
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
45
- 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 })));
46
- const result = yield partyRepository.find({
47
- where: {
48
- id: (0, typeorm_1.In)(initialResult.map((party) => party.id)),
49
- },
50
- });
51
- return result.map((party) => (0, MappingUtils_1.partyFrom)(party));
52
- });
53
- this.addParty = (args) => __awaiter(this, void 0, void 0, function* () {
54
- const { identities, contact, partyType } = args;
55
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
56
- if (!this.hasCorrectPartyType(partyType.type, contact)) {
57
- return Promise.reject(Error(`Party type ${partyType.type}, does not match for provided contact`));
58
- }
59
- for (const identity of identities !== null && identities !== void 0 ? identities : []) {
60
- if (identity.identifier.type === types_1.CorrelationIdentifierEnum.URL) {
61
- if (!identity.connection) {
62
- return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
63
- }
64
- if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
65
- return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
66
- }
67
- }
68
- }
69
- const partyEntity = (0, MappingUtils_1.partyEntityFrom)(args);
70
- debug('Adding party', args);
71
- const createdResult = yield partyRepository.save(partyEntity);
72
- return (0, MappingUtils_1.partyFrom)(createdResult);
73
- });
74
- this.updateParty = ({ party }) => __awaiter(this, void 0, void 0, function* () {
75
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
76
- const result = yield partyRepository.findOne({
77
- where: { id: party.id },
78
- });
79
- if (!result) {
80
- return Promise.reject(Error(`No party found for id: ${party.id}`));
81
- }
82
- const updatedParty = Object.assign(Object.assign({}, party), { identities: result.identities, type: result.partyType, relationships: result.relationships, electronicAddresses: result.electronicAddresses });
83
- debug('Updating party', party);
84
- const updatedResult = yield partyRepository.save(updatedParty, { transaction: true });
85
- return (0, MappingUtils_1.partyFrom)(updatedResult);
86
- });
87
- this.removeParty = ({ partyId }) => __awaiter(this, void 0, void 0, function* () {
88
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
89
- debug('Removing party', partyId);
90
- partyRepository
91
- .findOneById(partyId)
92
- .then((party) => __awaiter(this, void 0, void 0, function* () {
93
- if (!party) {
94
- yield Promise.reject(Error(`Unable to find the party with id to remove: ${partyId}`));
95
- }
96
- else {
97
- yield this.deleteIdentities(party.identities);
98
- yield partyRepository
99
- .delete({ id: partyId })
100
- .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
101
- const partyContactRepository = (yield this.dbConnection).getRepository(BaseContactEntity_1.BaseContactEntity);
102
- yield partyContactRepository
103
- .delete({ id: party.contact.id })
104
- .catch((error) => Promise.reject(Error(`Unable to remove party contact with id: ${party.contact.id}. ${error}`)));
105
- }
106
- }))
107
- .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
108
- });
109
- this.getIdentity = ({ identityId }) => __awaiter(this, void 0, void 0, function* () {
110
- const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
111
- where: { id: identityId },
112
- });
113
- if (!result) {
114
- return Promise.reject(Error(`No identity found for id: ${identityId}`));
115
- }
116
- return (0, MappingUtils_1.identityFrom)(result);
117
- });
118
- this.getIdentities = (args) => __awaiter(this, void 0, void 0, function* () {
119
- const identityRepository = (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity);
120
- 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 })));
121
- const result = yield identityRepository.find({
122
- where: {
123
- id: (0, typeorm_1.In)(initialResult.map((identity) => identity.id)),
124
- },
125
- });
126
- return result.map((identity) => (0, MappingUtils_1.identityFrom)(identity));
127
- });
128
- this.addIdentity = ({ identity, partyId }) => __awaiter(this, void 0, void 0, function* () {
129
- const party = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
130
- where: { id: partyId },
131
- });
132
- if (!party) {
133
- return Promise.reject(Error(`No party found for id: ${partyId}`));
134
- }
135
- if (identity.identifier.type === types_1.CorrelationIdentifierEnum.URL) {
136
- if (!identity.connection) {
137
- return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
138
- }
139
- if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
140
- return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
141
- }
142
- }
143
- const identityEntity = (0, MappingUtils_1.identityEntityFrom)(identity);
144
- identityEntity.party = party;
145
- debug('Adding identity', identity);
146
- const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).save(identityEntity, {
147
- transaction: true,
148
- });
149
- return (0, MappingUtils_1.identityFrom)(result);
150
- });
151
- this.updateIdentity = ({ identity }) => __awaiter(this, void 0, void 0, function* () {
152
- const identityRepository = (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity);
153
- const result = yield identityRepository.findOne({
154
- where: { id: identity.id },
155
- });
156
- if (!result) {
157
- return Promise.reject(Error(`No identity found for id: ${identity.id}`));
158
- }
159
- if (identity.identifier.type === types_1.CorrelationIdentifierEnum.URL) {
160
- if (!identity.connection) {
161
- return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
162
- }
163
- if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
164
- return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
165
- }
166
- }
167
- debug('Updating identity', identity);
168
- const updatedResult = yield identityRepository.save(identity, { transaction: true });
169
- return (0, MappingUtils_1.identityFrom)(updatedResult);
170
- });
171
- this.removeIdentity = ({ identityId }) => __awaiter(this, void 0, void 0, function* () {
172
- const identity = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
173
- where: { id: identityId },
174
- });
175
- if (!identity) {
176
- return Promise.reject(Error(`No identity found for id: ${identityId}`));
177
- }
178
- debug('Removing identity', identityId);
179
- yield this.deleteIdentities([identity]);
180
- });
181
- this.addRelationship = ({ leftId, rightId }) => __awaiter(this, void 0, void 0, function* () {
182
- return this.assertRelationshipSides(leftId, rightId).then(() => __awaiter(this, void 0, void 0, function* () {
183
- const relationship = (0, MappingUtils_1.partyRelationshipEntityFrom)({
184
- leftId,
185
- rightId,
186
- });
187
- debug('Adding party relationship', relationship);
188
- const createdResult = yield (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity).save(relationship);
189
- return (0, MappingUtils_1.partyRelationshipFrom)(createdResult);
190
- }));
191
- });
192
- this.getRelationship = ({ relationshipId }) => __awaiter(this, void 0, void 0, function* () {
193
- const result = yield (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity).findOne({
194
- where: { id: relationshipId },
195
- });
196
- if (!result) {
197
- return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
198
- }
199
- return (0, MappingUtils_1.partyRelationshipFrom)(result);
200
- });
201
- this.getRelationships = (args) => __awaiter(this, void 0, void 0, function* () {
202
- const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
203
- 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 })));
204
- const result = yield partyRelationshipRepository.find({
205
- where: {
206
- id: (0, typeorm_1.In)(initialResult.map((partyRelationship) => partyRelationship.id)),
207
- },
208
- });
209
- return result.map((partyRelationship) => (0, MappingUtils_1.partyRelationshipFrom)(partyRelationship));
210
- });
211
- this.updateRelationship = ({ relationship }) => __awaiter(this, void 0, void 0, function* () {
212
- const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
213
- const result = yield partyRelationshipRepository.findOne({
214
- where: { id: relationship.id },
215
- });
216
- if (!result) {
217
- return Promise.reject(Error(`No party relationship found for id: ${relationship.id}`));
218
- }
219
- return this.assertRelationshipSides(relationship.leftId, relationship.rightId).then(() => __awaiter(this, void 0, void 0, function* () {
220
- debug('Updating party relationship', relationship);
221
- const updatedResult = yield partyRelationshipRepository.save(relationship, { transaction: true });
222
- return (0, MappingUtils_1.partyRelationshipFrom)(updatedResult);
223
- }));
224
- });
225
- this.removeRelationship = ({ relationshipId }) => __awaiter(this, void 0, void 0, function* () {
226
- const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
227
- const relationship = yield partyRelationshipRepository.findOne({
228
- where: { id: relationshipId },
229
- });
230
- if (!relationship) {
231
- return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
232
- }
233
- debug('Removing relationship', relationshipId);
234
- yield partyRelationshipRepository.delete(relationshipId);
235
- });
236
- this.addPartyType = (args) => __awaiter(this, void 0, void 0, function* () {
237
- const partyEntity = (0, MappingUtils_1.partyTypeEntityFrom)(args);
238
- debug('Adding party type', args);
239
- const createdResult = yield (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity).save(partyEntity);
240
- return (0, MappingUtils_1.partyTypeFrom)(createdResult);
241
- });
242
- this.getPartyType = ({ partyTypeId }) => __awaiter(this, void 0, void 0, function* () {
243
- const result = yield (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity).findOne({
244
- where: { id: partyTypeId },
245
- });
246
- if (!result) {
247
- return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
248
- }
249
- return (0, MappingUtils_1.partyTypeFrom)(result);
250
- });
251
- this.getPartyTypes = (args) => __awaiter(this, void 0, void 0, function* () {
252
- const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
253
- 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 })));
254
- const result = yield partyTypeRepository.find({
255
- where: {
256
- id: (0, typeorm_1.In)(initialResult.map((partyType) => partyType.id)),
257
- },
258
- });
259
- return result.map((partyType) => (0, MappingUtils_1.partyTypeFrom)(partyType));
260
- });
261
- this.updatePartyType = ({ partyType }) => __awaiter(this, void 0, void 0, function* () {
262
- const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
263
- const result = yield partyTypeRepository.findOne({
264
- where: { id: partyType.id },
265
- });
266
- if (!result) {
267
- return Promise.reject(Error(`No party type found for id: ${partyType.id}`));
268
- }
269
- debug('Updating party type', partyType);
270
- const updatedResult = yield partyTypeRepository.save(partyType, { transaction: true });
271
- return (0, MappingUtils_1.partyTypeFrom)(updatedResult);
272
- });
273
- this.removePartyType = ({ partyTypeId }) => __awaiter(this, void 0, void 0, function* () {
274
- const parties = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).find({
275
- where: {
276
- partyType: {
277
- id: partyTypeId,
278
- },
279
- },
280
- });
281
- if (parties.length > 0) {
282
- return Promise.reject(Error(`Unable to remove party type with id: ${partyTypeId}. Party type is in use`));
283
- }
284
- const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
285
- const partyType = yield partyTypeRepository.findOne({
286
- where: { id: partyTypeId },
287
- });
288
- if (!partyType) {
289
- return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
290
- }
291
- debug('Removing party type', partyTypeId);
292
- yield partyTypeRepository.delete(partyTypeId);
293
- });
294
- this.dbConnection = dbConnection;
295
- }
296
- hasCorrectConnectionConfig(type, config) {
297
- switch (type) {
298
- case types_1.ConnectionTypeEnum.OPENID_CONNECT:
299
- return (0, MappingUtils_1.isOpenIdConfig)(config);
300
- case types_1.ConnectionTypeEnum.SIOPv2:
301
- return (0, MappingUtils_1.isDidAuthConfig)(config);
302
- default:
303
- throw new Error('Connection type not supported');
304
- }
305
- }
306
- hasCorrectPartyType(type, contact) {
307
- switch (type) {
308
- case types_1.PartyTypeEnum.NATURAL_PERSON:
309
- return (0, MappingUtils_1.isNaturalPerson)(contact);
310
- case types_1.PartyTypeEnum.ORGANIZATION:
311
- return (0, MappingUtils_1.isOrganization)(contact);
312
- default:
313
- throw new Error('Party type not supported');
314
- }
315
- }
316
- deleteIdentities(identities) {
317
- return __awaiter(this, void 0, void 0, function* () {
318
- debug('Removing identities', identities);
319
- identities.map((identity) => __awaiter(this, void 0, void 0, function* () {
320
- yield (yield this.dbConnection)
321
- .getRepository(CorrelationIdentifierEntity_1.CorrelationIdentifierEntity)
322
- .delete(identity.identifier.id)
323
- .catch((error) => Promise.reject(Error(`Unable to remove identity.identifier with id: ${identity.identifier.id}. ${error}`)));
324
- if (identity.connection) {
325
- yield (yield this.dbConnection).getRepository(BaseConfigEntity_1.BaseConfigEntity).delete(identity.connection.config.id);
326
- yield (yield this.dbConnection)
327
- .getRepository(ConnectionEntity_1.ConnectionEntity)
328
- .delete(identity.connection.id)
329
- .catch((error) => Promise.reject(Error(`Unable to remove identity.connection with id. ${error}`)));
330
- }
331
- if (identity.metadata) {
332
- identity.metadata.map((metadataItem) => __awaiter(this, void 0, void 0, function* () {
333
- yield (yield this.dbConnection)
334
- .getRepository(IdentityMetadataItemEntity_1.IdentityMetadataItemEntity)
335
- .delete(metadataItem.id)
336
- .catch((error) => Promise.reject(Error(`Unable to remove metadataItem.id with id ${metadataItem.id}. ${error}`)));
337
- }));
338
- }
339
- ;
340
- (yield this.dbConnection)
341
- .getRepository(IdentityEntity_1.IdentityEntity)
342
- .delete(identity.id)
343
- .catch((error) => Promise.reject(Error(`Unable to remove metadataItem.id with id ${identity.id}. ${error}`)));
344
- }));
345
- });
346
- }
347
- assertRelationshipSides(leftId, rightId) {
348
- return __awaiter(this, void 0, void 0, function* () {
349
- const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
350
- const leftParty = yield partyRepository.findOne({
351
- where: { id: leftId },
352
- });
353
- if (!leftParty) {
354
- return Promise.reject(Error(`No party found for left side of the relationship, party id: ${leftId}`));
355
- }
356
- const rightParty = yield partyRepository.findOne({
357
- where: { id: rightId },
358
- });
359
- if (!rightParty) {
360
- return Promise.reject(Error(`No party found for right side of the relationship, party id: ${rightId}`));
361
- }
362
- });
363
- }
364
- }
365
- exports.ContactStore = ContactStore;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ContactStore = void 0;
16
+ const typeorm_1 = require("typeorm");
17
+ const debug_1 = __importDefault(require("debug"));
18
+ const AbstractContactStore_1 = require("./AbstractContactStore");
19
+ const PartyEntity_1 = require("../entities/contact/PartyEntity");
20
+ const IdentityEntity_1 = require("../entities/contact/IdentityEntity");
21
+ const IdentityMetadataItemEntity_1 = require("../entities/contact/IdentityMetadataItemEntity");
22
+ const CorrelationIdentifierEntity_1 = require("../entities/contact/CorrelationIdentifierEntity");
23
+ const ConnectionEntity_1 = require("../entities/contact/ConnectionEntity");
24
+ const BaseConfigEntity_1 = require("../entities/contact/BaseConfigEntity");
25
+ const PartyRelationshipEntity_1 = require("../entities/contact/PartyRelationshipEntity");
26
+ const PartyTypeEntity_1 = require("../entities/contact/PartyTypeEntity");
27
+ const BaseContactEntity_1 = require("../entities/contact/BaseContactEntity");
28
+ const MappingUtils_1 = require("../utils/contact/MappingUtils");
29
+ const types_1 = require("../types");
30
+ const debug = (0, debug_1.default)('sphereon:ssi-sdk:contact-store');
31
+ class ContactStore extends AbstractContactStore_1.AbstractContactStore {
32
+ constructor(dbConnection) {
33
+ super();
34
+ this.getParty = ({ partyId }) => __awaiter(this, void 0, void 0, function* () {
35
+ const result = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
36
+ where: { id: partyId },
37
+ });
38
+ if (!result) {
39
+ return Promise.reject(Error(`No party found for id: ${partyId}`));
40
+ }
41
+ return (0, MappingUtils_1.partyFrom)(result);
42
+ });
43
+ this.getParties = (args) => __awaiter(this, void 0, void 0, function* () {
44
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
45
+ 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 })));
46
+ const result = yield partyRepository.find({
47
+ where: {
48
+ id: (0, typeorm_1.In)(initialResult.map((party) => party.id)),
49
+ },
50
+ });
51
+ return result.map((party) => (0, MappingUtils_1.partyFrom)(party));
52
+ });
53
+ this.addParty = (args) => __awaiter(this, void 0, void 0, function* () {
54
+ const { identities, contact, partyType } = args;
55
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
56
+ if (!this.hasCorrectPartyType(partyType.type, contact)) {
57
+ return Promise.reject(Error(`Party type ${partyType.type}, does not match for provided contact`));
58
+ }
59
+ for (const identity of identities !== null && identities !== void 0 ? identities : []) {
60
+ if (identity.identifier.type === types_1.CorrelationIdentifierEnum.URL) {
61
+ if (!identity.connection) {
62
+ return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
63
+ }
64
+ if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
65
+ return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
66
+ }
67
+ }
68
+ }
69
+ const partyEntity = (0, MappingUtils_1.partyEntityFrom)(args);
70
+ debug('Adding party', args);
71
+ const createdResult = yield partyRepository.save(partyEntity);
72
+ return (0, MappingUtils_1.partyFrom)(createdResult);
73
+ });
74
+ this.updateParty = ({ party }) => __awaiter(this, void 0, void 0, function* () {
75
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
76
+ const result = yield partyRepository.findOne({
77
+ where: { id: party.id },
78
+ });
79
+ if (!result) {
80
+ return Promise.reject(Error(`No party found for id: ${party.id}`));
81
+ }
82
+ const updatedParty = Object.assign(Object.assign({}, party), { identities: result.identities, type: result.partyType, relationships: result.relationships, electronicAddresses: result.electronicAddresses });
83
+ debug('Updating party', party);
84
+ const updatedResult = yield partyRepository.save(updatedParty, { transaction: true });
85
+ return (0, MappingUtils_1.partyFrom)(updatedResult);
86
+ });
87
+ this.removeParty = ({ partyId }) => __awaiter(this, void 0, void 0, function* () {
88
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
89
+ debug('Removing party', partyId);
90
+ partyRepository
91
+ .findOneById(partyId)
92
+ .then((party) => __awaiter(this, void 0, void 0, function* () {
93
+ if (!party) {
94
+ yield Promise.reject(Error(`Unable to find the party with id to remove: ${partyId}`));
95
+ }
96
+ else {
97
+ yield this.deleteIdentities(party.identities);
98
+ yield partyRepository
99
+ .delete({ id: partyId })
100
+ .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
101
+ const partyContactRepository = (yield this.dbConnection).getRepository(BaseContactEntity_1.BaseContactEntity);
102
+ yield partyContactRepository
103
+ .delete({ id: party.contact.id })
104
+ .catch((error) => Promise.reject(Error(`Unable to remove party contact with id: ${party.contact.id}. ${error}`)));
105
+ }
106
+ }))
107
+ .catch((error) => Promise.reject(Error(`Unable to remove party with id: ${partyId}. ${error}`)));
108
+ });
109
+ this.getIdentity = ({ identityId }) => __awaiter(this, void 0, void 0, function* () {
110
+ const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
111
+ where: { id: identityId },
112
+ });
113
+ if (!result) {
114
+ return Promise.reject(Error(`No identity found for id: ${identityId}`));
115
+ }
116
+ return (0, MappingUtils_1.identityFrom)(result);
117
+ });
118
+ this.getIdentities = (args) => __awaiter(this, void 0, void 0, function* () {
119
+ const identityRepository = (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity);
120
+ 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 })));
121
+ const result = yield identityRepository.find({
122
+ where: {
123
+ id: (0, typeorm_1.In)(initialResult.map((identity) => identity.id)),
124
+ },
125
+ });
126
+ return result.map((identity) => (0, MappingUtils_1.identityFrom)(identity));
127
+ });
128
+ this.addIdentity = ({ identity, partyId }) => __awaiter(this, void 0, void 0, function* () {
129
+ const party = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).findOne({
130
+ where: { id: partyId },
131
+ });
132
+ if (!party) {
133
+ return Promise.reject(Error(`No party found for id: ${partyId}`));
134
+ }
135
+ if (identity.identifier.type === types_1.CorrelationIdentifierEnum.URL) {
136
+ if (!identity.connection) {
137
+ return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
138
+ }
139
+ if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
140
+ return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
141
+ }
142
+ }
143
+ const identityEntity = (0, MappingUtils_1.identityEntityFrom)(identity);
144
+ identityEntity.party = party;
145
+ debug('Adding identity', identity);
146
+ const result = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).save(identityEntity, {
147
+ transaction: true,
148
+ });
149
+ return (0, MappingUtils_1.identityFrom)(result);
150
+ });
151
+ this.updateIdentity = ({ identity }) => __awaiter(this, void 0, void 0, function* () {
152
+ const identityRepository = (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity);
153
+ const result = yield identityRepository.findOne({
154
+ where: { id: identity.id },
155
+ });
156
+ if (!result) {
157
+ return Promise.reject(Error(`No identity found for id: ${identity.id}`));
158
+ }
159
+ if (identity.identifier.type === types_1.CorrelationIdentifierEnum.URL) {
160
+ if (!identity.connection) {
161
+ return Promise.reject(Error(`Identity with correlation type ${types_1.CorrelationIdentifierEnum.URL} should contain a connection`));
162
+ }
163
+ if (!this.hasCorrectConnectionConfig(identity.connection.type, identity.connection.config)) {
164
+ return Promise.reject(Error(`Connection type ${identity.connection.type}, does not match for provided config`));
165
+ }
166
+ }
167
+ debug('Updating identity', identity);
168
+ const updatedResult = yield identityRepository.save(identity, { transaction: true });
169
+ return (0, MappingUtils_1.identityFrom)(updatedResult);
170
+ });
171
+ this.removeIdentity = ({ identityId }) => __awaiter(this, void 0, void 0, function* () {
172
+ const identity = yield (yield this.dbConnection).getRepository(IdentityEntity_1.IdentityEntity).findOne({
173
+ where: { id: identityId },
174
+ });
175
+ if (!identity) {
176
+ return Promise.reject(Error(`No identity found for id: ${identityId}`));
177
+ }
178
+ debug('Removing identity', identityId);
179
+ yield this.deleteIdentities([identity]);
180
+ });
181
+ this.addRelationship = ({ leftId, rightId }) => __awaiter(this, void 0, void 0, function* () {
182
+ return this.assertRelationshipSides(leftId, rightId).then(() => __awaiter(this, void 0, void 0, function* () {
183
+ const relationship = (0, MappingUtils_1.partyRelationshipEntityFrom)({
184
+ leftId,
185
+ rightId,
186
+ });
187
+ debug('Adding party relationship', relationship);
188
+ const createdResult = yield (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity).save(relationship);
189
+ return (0, MappingUtils_1.partyRelationshipFrom)(createdResult);
190
+ }));
191
+ });
192
+ this.getRelationship = ({ relationshipId }) => __awaiter(this, void 0, void 0, function* () {
193
+ const result = yield (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity).findOne({
194
+ where: { id: relationshipId },
195
+ });
196
+ if (!result) {
197
+ return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
198
+ }
199
+ return (0, MappingUtils_1.partyRelationshipFrom)(result);
200
+ });
201
+ this.getRelationships = (args) => __awaiter(this, void 0, void 0, function* () {
202
+ const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
203
+ 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 })));
204
+ const result = yield partyRelationshipRepository.find({
205
+ where: {
206
+ id: (0, typeorm_1.In)(initialResult.map((partyRelationship) => partyRelationship.id)),
207
+ },
208
+ });
209
+ return result.map((partyRelationship) => (0, MappingUtils_1.partyRelationshipFrom)(partyRelationship));
210
+ });
211
+ this.updateRelationship = ({ relationship }) => __awaiter(this, void 0, void 0, function* () {
212
+ const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
213
+ const result = yield partyRelationshipRepository.findOne({
214
+ where: { id: relationship.id },
215
+ });
216
+ if (!result) {
217
+ return Promise.reject(Error(`No party relationship found for id: ${relationship.id}`));
218
+ }
219
+ return this.assertRelationshipSides(relationship.leftId, relationship.rightId).then(() => __awaiter(this, void 0, void 0, function* () {
220
+ debug('Updating party relationship', relationship);
221
+ const updatedResult = yield partyRelationshipRepository.save(relationship, { transaction: true });
222
+ return (0, MappingUtils_1.partyRelationshipFrom)(updatedResult);
223
+ }));
224
+ });
225
+ this.removeRelationship = ({ relationshipId }) => __awaiter(this, void 0, void 0, function* () {
226
+ const partyRelationshipRepository = (yield this.dbConnection).getRepository(PartyRelationshipEntity_1.PartyRelationshipEntity);
227
+ const relationship = yield partyRelationshipRepository.findOne({
228
+ where: { id: relationshipId },
229
+ });
230
+ if (!relationship) {
231
+ return Promise.reject(Error(`No relationship found for id: ${relationshipId}`));
232
+ }
233
+ debug('Removing relationship', relationshipId);
234
+ yield partyRelationshipRepository.delete(relationshipId);
235
+ });
236
+ this.addPartyType = (args) => __awaiter(this, void 0, void 0, function* () {
237
+ const partyEntity = (0, MappingUtils_1.partyTypeEntityFrom)(args);
238
+ debug('Adding party type', args);
239
+ const createdResult = yield (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity).save(partyEntity);
240
+ return (0, MappingUtils_1.partyTypeFrom)(createdResult);
241
+ });
242
+ this.getPartyType = ({ partyTypeId }) => __awaiter(this, void 0, void 0, function* () {
243
+ const result = yield (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity).findOne({
244
+ where: { id: partyTypeId },
245
+ });
246
+ if (!result) {
247
+ return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
248
+ }
249
+ return (0, MappingUtils_1.partyTypeFrom)(result);
250
+ });
251
+ this.getPartyTypes = (args) => __awaiter(this, void 0, void 0, function* () {
252
+ const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
253
+ 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 })));
254
+ const result = yield partyTypeRepository.find({
255
+ where: {
256
+ id: (0, typeorm_1.In)(initialResult.map((partyType) => partyType.id)),
257
+ },
258
+ });
259
+ return result.map((partyType) => (0, MappingUtils_1.partyTypeFrom)(partyType));
260
+ });
261
+ this.updatePartyType = ({ partyType }) => __awaiter(this, void 0, void 0, function* () {
262
+ const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
263
+ const result = yield partyTypeRepository.findOne({
264
+ where: { id: partyType.id },
265
+ });
266
+ if (!result) {
267
+ return Promise.reject(Error(`No party type found for id: ${partyType.id}`));
268
+ }
269
+ debug('Updating party type', partyType);
270
+ const updatedResult = yield partyTypeRepository.save(partyType, { transaction: true });
271
+ return (0, MappingUtils_1.partyTypeFrom)(updatedResult);
272
+ });
273
+ this.removePartyType = ({ partyTypeId }) => __awaiter(this, void 0, void 0, function* () {
274
+ const parties = yield (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity).find({
275
+ where: {
276
+ partyType: {
277
+ id: partyTypeId,
278
+ },
279
+ },
280
+ });
281
+ if (parties.length > 0) {
282
+ return Promise.reject(Error(`Unable to remove party type with id: ${partyTypeId}. Party type is in use`));
283
+ }
284
+ const partyTypeRepository = (yield this.dbConnection).getRepository(PartyTypeEntity_1.PartyTypeEntity);
285
+ const partyType = yield partyTypeRepository.findOne({
286
+ where: { id: partyTypeId },
287
+ });
288
+ if (!partyType) {
289
+ return Promise.reject(Error(`No party type found for id: ${partyTypeId}`));
290
+ }
291
+ debug('Removing party type', partyTypeId);
292
+ yield partyTypeRepository.delete(partyTypeId);
293
+ });
294
+ this.dbConnection = dbConnection;
295
+ }
296
+ hasCorrectConnectionConfig(type, config) {
297
+ switch (type) {
298
+ case types_1.ConnectionTypeEnum.OPENID_CONNECT:
299
+ return (0, MappingUtils_1.isOpenIdConfig)(config);
300
+ case types_1.ConnectionTypeEnum.SIOPv2:
301
+ return (0, MappingUtils_1.isDidAuthConfig)(config);
302
+ default:
303
+ throw new Error('Connection type not supported');
304
+ }
305
+ }
306
+ hasCorrectPartyType(type, contact) {
307
+ switch (type) {
308
+ case types_1.PartyTypeEnum.NATURAL_PERSON:
309
+ return (0, MappingUtils_1.isNaturalPerson)(contact);
310
+ case types_1.PartyTypeEnum.ORGANIZATION:
311
+ return (0, MappingUtils_1.isOrganization)(contact);
312
+ default:
313
+ throw new Error('Party type not supported');
314
+ }
315
+ }
316
+ deleteIdentities(identities) {
317
+ return __awaiter(this, void 0, void 0, function* () {
318
+ debug('Removing identities', identities);
319
+ identities.map((identity) => __awaiter(this, void 0, void 0, function* () {
320
+ yield (yield this.dbConnection)
321
+ .getRepository(CorrelationIdentifierEntity_1.CorrelationIdentifierEntity)
322
+ .delete(identity.identifier.id)
323
+ .catch((error) => Promise.reject(Error(`Unable to remove identity.identifier with id: ${identity.identifier.id}. ${error}`)));
324
+ if (identity.connection) {
325
+ yield (yield this.dbConnection).getRepository(BaseConfigEntity_1.BaseConfigEntity).delete(identity.connection.config.id);
326
+ yield (yield this.dbConnection)
327
+ .getRepository(ConnectionEntity_1.ConnectionEntity)
328
+ .delete(identity.connection.id)
329
+ .catch((error) => Promise.reject(Error(`Unable to remove identity.connection with id. ${error}`)));
330
+ }
331
+ if (identity.metadata) {
332
+ identity.metadata.map((metadataItem) => __awaiter(this, void 0, void 0, function* () {
333
+ yield (yield this.dbConnection)
334
+ .getRepository(IdentityMetadataItemEntity_1.IdentityMetadataItemEntity)
335
+ .delete(metadataItem.id)
336
+ .catch((error) => Promise.reject(Error(`Unable to remove metadataItem.id with id ${metadataItem.id}. ${error}`)));
337
+ }));
338
+ }
339
+ ;
340
+ (yield this.dbConnection)
341
+ .getRepository(IdentityEntity_1.IdentityEntity)
342
+ .delete(identity.id)
343
+ .catch((error) => Promise.reject(Error(`Unable to remove metadataItem.id with id ${identity.id}. ${error}`)));
344
+ }));
345
+ });
346
+ }
347
+ assertRelationshipSides(leftId, rightId) {
348
+ return __awaiter(this, void 0, void 0, function* () {
349
+ const partyRepository = (yield this.dbConnection).getRepository(PartyEntity_1.PartyEntity);
350
+ const leftParty = yield partyRepository.findOne({
351
+ where: { id: leftId },
352
+ });
353
+ if (!leftParty) {
354
+ return Promise.reject(Error(`No party found for left side of the relationship, party id: ${leftId}`));
355
+ }
356
+ const rightParty = yield partyRepository.findOne({
357
+ where: { id: rightId },
358
+ });
359
+ if (!rightParty) {
360
+ return Promise.reject(Error(`No party found for right side of the relationship, party id: ${rightId}`));
361
+ }
362
+ });
363
+ }
364
+ }
365
+ exports.ContactStore = ContactStore;
366
366
  //# sourceMappingURL=ContactStore.js.map