@icure/api 7.1.34 → 7.1.35

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 (148) hide show
  1. package/icc-api/api/IccAuthApi.d.ts +1 -0
  2. package/icc-api/api/IccAuthApi.js +1 -0
  3. package/icc-api/api/IccAuthApi.js.map +1 -1
  4. package/icc-x-api/index.d.ts +22 -29
  5. package/icc-x-api/index.js +60 -38
  6. package/icc-x-api/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/test/icc-api/api/IccDocumentApi.d.ts +1 -0
  9. package/test/icc-api/api/IccDocumentApi.js +200 -0
  10. package/test/icc-api/api/IccDocumentApi.js.map +1 -0
  11. package/test/icc-api/api/IccGroupApi.d.ts +1 -0
  12. package/test/icc-api/api/IccGroupApi.js +50 -0
  13. package/test/icc-api/api/IccGroupApi.js.map +1 -0
  14. package/test/icc-api/api/IccRoleApi.d.ts +1 -0
  15. package/test/icc-api/api/IccRoleApi.js +34 -0
  16. package/test/icc-api/api/IccRoleApi.js.map +1 -0
  17. package/test/icc-api/api/IccUserApi.d.ts +1 -0
  18. package/test/icc-api/api/IccUserApi.js +80 -0
  19. package/test/icc-api/api/IccUserApi.js.map +1 -0
  20. package/test/icc-api/e2e/IccCalendarItemApi.d.ts +1 -0
  21. package/test/icc-api/e2e/IccCalendarItemApi.js +45 -0
  22. package/test/icc-api/e2e/IccCalendarItemApi.js.map +1 -0
  23. package/test/icc-api/model/modelHelpersTest.d.ts +1 -0
  24. package/test/icc-api/model/modelHelpersTest.js +45 -0
  25. package/test/icc-api/model/modelHelpersTest.js.map +1 -0
  26. package/test/icc-x-api/auth/group-switch-test.d.ts +1 -0
  27. package/test/icc-x-api/auth/group-switch-test.js +81 -0
  28. package/test/icc-x-api/auth/group-switch-test.js.map +1 -0
  29. package/test/icc-x-api/auth/jwt-concurrency-test.d.ts +2 -0
  30. package/test/icc-x-api/auth/jwt-concurrency-test.js +113 -0
  31. package/test/icc-x-api/auth/jwt-concurrency-test.js.map +1 -0
  32. package/test/icc-x-api/auth/smart-auth-provider-test.d.ts +1 -0
  33. package/test/icc-x-api/auth/smart-auth-provider-test.js +222 -0
  34. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -0
  35. package/test/icc-x-api/crypto/KeyManager-test.d.ts +1 -0
  36. package/test/icc-x-api/crypto/KeyManager-test.js +225 -0
  37. package/test/icc-x-api/crypto/KeyManager-test.js.map +1 -0
  38. package/test/icc-x-api/crypto/concurrency.d.ts +1 -0
  39. package/test/icc-x-api/crypto/concurrency.js +35 -0
  40. package/test/icc-x-api/crypto/concurrency.js.map +1 -0
  41. package/test/icc-x-api/crypto/crypto-utils.d.ts +1 -0
  42. package/test/icc-x-api/crypto/crypto-utils.js +80 -0
  43. package/test/icc-x-api/crypto/crypto-utils.js.map +1 -0
  44. package/test/icc-x-api/crypto/cryptoTest.d.ts +2 -0
  45. package/test/icc-x-api/crypto/cryptoTest.js +275 -0
  46. package/test/icc-x-api/crypto/cryptoTest.js.map +1 -0
  47. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.d.ts +1 -0
  48. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js +132 -0
  49. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js.map +1 -0
  50. package/test/icc-x-api/crypto/full-crypto-test.d.ts +1 -0
  51. package/test/icc-x-api/crypto/full-crypto-test.js +458 -0
  52. package/test/icc-x-api/crypto/full-crypto-test.js.map +1 -0
  53. package/test/icc-x-api/crypto/shamir.d.ts +2 -0
  54. package/test/icc-x-api/crypto/shamir.js +156 -0
  55. package/test/icc-x-api/crypto/shamir.js.map +1 -0
  56. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.d.ts +1 -0
  57. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js +75 -0
  58. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +1 -0
  59. package/test/icc-x-api/data-compatibility-test-7to6.d.ts +1 -0
  60. package/test/icc-x-api/data-compatibility-test-7to6.js +343 -0
  61. package/test/icc-x-api/data-compatibility-test-7to6.js.map +1 -0
  62. package/test/icc-x-api/entity-with-attachments-api-test.d.ts +1 -0
  63. package/test/icc-x-api/entity-with-attachments-api-test.js +142 -0
  64. package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -0
  65. package/test/icc-x-api/filters/filters.d.ts +1 -0
  66. package/test/icc-x-api/filters/filters.js +49 -0
  67. package/test/icc-x-api/filters/filters.js.map +1 -0
  68. package/test/icc-x-api/icc-accesslog-x-api.d.ts +1 -0
  69. package/test/icc-x-api/icc-accesslog-x-api.js +121 -0
  70. package/test/icc-x-api/icc-accesslog-x-api.js.map +1 -0
  71. package/test/icc-x-api/icc-auth-api.d.ts +1 -0
  72. package/test/icc-x-api/icc-auth-api.js +46 -0
  73. package/test/icc-x-api/icc-auth-api.js.map +1 -0
  74. package/test/icc-x-api/icc-calendar-item-x-api.d.ts +1 -0
  75. package/test/icc-x-api/icc-calendar-item-x-api.js +146 -0
  76. package/test/icc-x-api/icc-calendar-item-x-api.js.map +1 -0
  77. package/test/icc-x-api/icc-contact-x-api.d.ts +1 -0
  78. package/test/icc-x-api/icc-contact-x-api.js +311 -0
  79. package/test/icc-x-api/icc-contact-x-api.js.map +1 -0
  80. package/test/icc-x-api/icc-form-x-api.d.ts +1 -0
  81. package/test/icc-x-api/icc-form-x-api.js +331 -0
  82. package/test/icc-x-api/icc-form-x-api.js.map +1 -0
  83. package/test/icc-x-api/icc-helement-x-api-test.d.ts +1 -0
  84. package/test/icc-x-api/icc-helement-x-api-test.js +158 -0
  85. package/test/icc-x-api/icc-helement-x-api-test.js.map +1 -0
  86. package/test/icc-x-api/icc-invoice-x-api.d.ts +1 -0
  87. package/test/icc-x-api/icc-invoice-x-api.js +115 -0
  88. package/test/icc-x-api/icc-invoice-x-api.js.map +1 -0
  89. package/test/icc-x-api/icc-maintenance-task-x-api-test.d.ts +1 -0
  90. package/test/icc-x-api/icc-maintenance-task-x-api-test.js +230 -0
  91. package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +1 -0
  92. package/test/icc-x-api/icc-patient-x-api-test.d.ts +1 -0
  93. package/test/icc-x-api/icc-patient-x-api-test.js +169 -0
  94. package/test/icc-x-api/icc-patient-x-api-test.js.map +1 -0
  95. package/test/icc-x-api/icc-time-table-x-api.d.ts +1 -0
  96. package/test/icc-x-api/icc-time-table-x-api.js +110 -0
  97. package/test/icc-x-api/icc-time-table-x-api.js.map +1 -0
  98. package/test/icc-x-api/icc-user-x-api-test.d.ts +1 -0
  99. package/test/icc-x-api/icc-user-x-api-test.js +108 -0
  100. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -0
  101. package/test/icc-x-api/icureapi-group-test.d.ts +1 -0
  102. package/test/icc-x-api/icureapi-group-test.js +130 -0
  103. package/test/icc-x-api/icureapi-group-test.js.map +1 -0
  104. package/test/icc-x-api/patient-user.d.ts +2 -0
  105. package/test/icc-x-api/patient-user.js +117 -0
  106. package/test/icc-x-api/patient-user.js.map +1 -0
  107. package/test/icc-x-api/storage/storage.d.ts +1 -0
  108. package/test/icc-x-api/storage/storage.js +50 -0
  109. package/test/icc-x-api/storage/storage.js.map +1 -0
  110. package/test/icc-x-api/subscription-apis.d.ts +2 -0
  111. package/test/icc-x-api/subscription-apis.js +498 -0
  112. package/test/icc-x-api/subscription-apis.js.map +1 -0
  113. package/test/icc-x-api/test-api-no-parent.d.ts +1 -0
  114. package/test/icc-x-api/test-api-no-parent.js +79 -0
  115. package/test/icc-x-api/test-api-no-parent.js.map +1 -0
  116. package/test/icc-x-api/test-legacy-data-support.d.ts +1 -0
  117. package/test/icc-x-api/test-legacy-data-support.js +231 -0
  118. package/test/icc-x-api/test-legacy-data-support.js.map +1 -0
  119. package/test/icc-x-api/utils/crypto-utils-test.d.ts +1 -0
  120. package/test/icc-x-api/utils/crypto-utils-test.js +586 -0
  121. package/test/icc-x-api/utils/crypto-utils-test.js.map +1 -0
  122. package/test/icc-x-api/utils/graph-test.d.ts +1 -0
  123. package/test/icc-x-api/utils/graph-test.js +54 -0
  124. package/test/icc-x-api/utils/graph-test.js.map +1 -0
  125. package/test/support/CSM-185.d.ts +1 -0
  126. package/test/support/CSM-185.js +120 -0
  127. package/test/support/CSM-185.js.map +1 -0
  128. package/test/support/CSM-87.d.ts +0 -0
  129. package/test/support/CSM-87.js +21 -0
  130. package/test/support/CSM-87.js.map +1 -0
  131. package/test/support/CSM-93.d.ts +1 -0
  132. package/test/support/CSM-93.js +111 -0
  133. package/test/support/CSM-93.js.map +1 -0
  134. package/test/utils/TestApi.d.ts +3 -0
  135. package/test/utils/TestApi.js +27 -0
  136. package/test/utils/TestApi.js.map +1 -0
  137. package/test/utils/TestCollectionUtils.d.ts +1 -0
  138. package/test/utils/TestCollectionUtils.js +109 -0
  139. package/test/utils/TestCollectionUtils.js.map +1 -0
  140. package/test/utils/TestCryptoStrategies.d.ts +37 -0
  141. package/test/utils/TestCryptoStrategies.js +72 -0
  142. package/test/utils/TestCryptoStrategies.js.map +1 -0
  143. package/test/utils/TestStorage.d.ts +31 -0
  144. package/test/utils/TestStorage.js +88 -0
  145. package/test/utils/TestStorage.js.map +1 -0
  146. package/test/utils/test_utils.d.ts +60 -0
  147. package/test/utils/test_utils.js +313 -0
  148. package/test/utils/test_utils.js.map +1 -0
@@ -0,0 +1,311 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const mocha_1 = require("mocha");
13
+ require("isomorphic-fetch");
14
+ const icc_x_api_1 = require("../../icc-x-api");
15
+ const Patient_1 = require("../../icc-api/model/Patient");
16
+ const chai_1 = require("chai");
17
+ const crypto_1 = require("crypto");
18
+ const test_utils_1 = require("../utils/test_utils");
19
+ const Code_1 = require("../../icc-api/model/Code");
20
+ const Contact_1 = require("../../icc-api/model/Contact");
21
+ const Service_1 = require("../../icc-api/model/Service");
22
+ const Content_1 = require("../../icc-api/model/Content");
23
+ const HealthElement_1 = require("../../icc-api/model/HealthElement");
24
+ const SubContact_1 = require("../../icc-api/model/SubContact");
25
+ const ServiceLink_1 = require("../../icc-api/model/ServiceLink");
26
+ const FilterChainService_1 = require("../../icc-api/model/FilterChainService");
27
+ const ServiceByHcPartyHealthElementIdsFilter_1 = require("../../icc-x-api/filters/ServiceByHcPartyHealthElementIdsFilter");
28
+ var initApi = test_utils_1.TestUtils.initApi;
29
+ const types_1 = require("@icure/test-setup/types");
30
+ const TestCryptoStrategies_1 = require("../utils/TestCryptoStrategies");
31
+ const TestStorage_1 = require("../utils/TestStorage");
32
+ const RSA_1 = require("../../icc-x-api/crypto/RSA");
33
+ const icc_api_1 = require("../../icc-api");
34
+ (0, test_utils_1.setLocalStorage)(fetch);
35
+ let env;
36
+ (0, mocha_1.before)(function () {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ this.timeout(600000);
39
+ const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
40
+ env = yield initializer.execute((0, types_1.getEnvVariables)());
41
+ });
42
+ });
43
+ function createPatient(patientApiForHcp, hcpUser) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return patientApiForHcp.createPatientWithUser(hcpUser, yield patientApiForHcp.newInstance(hcpUser, new Patient_1.Patient({
46
+ id: (0, crypto_1.randomUUID)(),
47
+ firstName: 'John',
48
+ lastName: 'Snow',
49
+ note: 'Winter is coming',
50
+ })));
51
+ });
52
+ }
53
+ function createHealthElement(healthElementApi, hcpUser, patient) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ return healthElementApi.createHealthElementWithUser(hcpUser, yield healthElementApi.newInstance(hcpUser, patient, new HealthElement_1.HealthElement({
56
+ id: (0, crypto_1.randomUUID)(),
57
+ note: 'My secret note',
58
+ tags: [
59
+ new Code_1.Code({
60
+ id: 'ICURE|MY-CODE|1',
61
+ code: 'MY-CODE',
62
+ type: 'ICURE',
63
+ version: '1',
64
+ }),
65
+ ],
66
+ }), { confidential: true }));
67
+ });
68
+ }
69
+ function createBasicContact(contactApiForHcp, hcpUser, patient) {
70
+ return contactApiForHcp.newInstance(hcpUser, patient, new Contact_1.Contact({
71
+ id: (0, crypto_1.randomUUID)(),
72
+ services: [
73
+ contactApiForHcp.service().newInstance(hcpUser, new Service_1.Service({
74
+ id: (0, crypto_1.randomUUID)(),
75
+ valueDate: 20220203111034,
76
+ content: { en: new Content_1.Content({ numberValue: 53.5 }) },
77
+ tags: [
78
+ new Code_1.Code({
79
+ id: 'LOINC|29463-7|2',
80
+ code: '29463-7',
81
+ type: 'LOINC',
82
+ version: '2',
83
+ }),
84
+ ],
85
+ })),
86
+ ],
87
+ descr: 'Weight value',
88
+ }), { confidential: true });
89
+ }
90
+ describe('icc-x-contact-api Tests', () => {
91
+ it('CreateContactWithUser Success for HCP', () => __awaiter(void 0, void 0, void 0, function* () {
92
+ // Given
93
+ const { userApi: userApiForHcp, patientApi: patientApiForHcp, contactApi: contactApiForHcp } = yield initApi(env, test_utils_1.hcp1Username);
94
+ const hcpUser = yield userApiForHcp.getCurrentUser();
95
+ const patient = yield createPatient(patientApiForHcp, hcpUser);
96
+ const contactToCreate = yield createBasicContact(contactApiForHcp, hcpUser, patient);
97
+ // When
98
+ const createdContact = (yield contactApiForHcp.createContactWithUser(hcpUser, contactToCreate));
99
+ // Then
100
+ const readContact = yield contactApiForHcp.getContactWithUser(hcpUser, createdContact.id);
101
+ (0, chai_1.expect)(readContact).to.not.be.undefined;
102
+ (0, chai_1.expect)(readContact).to.not.be.null;
103
+ (0, chai_1.expect)(readContact.openingDate).to.not.be.undefined;
104
+ (0, chai_1.expect)(readContact.openingDate).to.not.be.null;
105
+ (0, chai_1.expect)(readContact.groupId).to.not.be.undefined;
106
+ (0, chai_1.expect)(readContact.groupId).to.not.be.null;
107
+ (0, chai_1.expect)(readContact.responsible).to.be.equal(hcpUser.healthcarePartyId);
108
+ (0, chai_1.expect)(readContact.id).to.be.equal(contactToCreate.id);
109
+ (0, chai_1.expect)(readContact.descr).to.be.equal(contactToCreate.descr);
110
+ (0, chai_1.expect)(readContact.delegations[hcpUser.healthcarePartyId].length).to.equals(1);
111
+ (0, chai_1.expect)(readContact.delegations[hcpUser.healthcarePartyId][0].key).to.not.be.undefined;
112
+ (0, chai_1.expect)(readContact.encryptionKeys[hcpUser.healthcarePartyId].length).to.equals(1);
113
+ (0, chai_1.expect)(readContact.encryptionKeys[hcpUser.healthcarePartyId][0].key).to.not.be.undefined;
114
+ (0, chai_1.expect)(readContact.cryptedForeignKeys[hcpUser.healthcarePartyId].length).to.equals(1);
115
+ (0, chai_1.expect)(readContact.cryptedForeignKeys[hcpUser.healthcarePartyId][0].key).to.not.be.undefined;
116
+ (0, chai_1.expect)(readContact.services[0].responsible).to.be.equal(hcpUser.healthcarePartyId);
117
+ (0, chai_1.expect)(readContact.services[0].id).to.be.equal(contactToCreate.services[0].id);
118
+ (0, chai_1.expect)(readContact.services[0].valueDate).to.be.equal(contactToCreate.services[0].valueDate);
119
+ (0, chai_1.expect)(readContact.services[0].tags[0].id).to.be.equal(contactToCreate.services[0].tags[0].id);
120
+ }));
121
+ it('Filter Services By HealthElementId - Success', () => __awaiter(void 0, void 0, void 0, function* () {
122
+ // Given
123
+ const { userApi: userApiForHcp, patientApi: patientApiForHcp, contactApi: contactApiForHcp, healthcareElementApi: hElementApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
124
+ const hcpUser = yield userApiForHcp.getCurrentUser();
125
+ const patient = yield createPatient(patientApiForHcp, hcpUser);
126
+ const healthElement = yield createHealthElement(hElementApiForHcp, hcpUser, patient);
127
+ const contactToCreate = yield createBasicContact(contactApiForHcp, hcpUser, patient).then((contact) => {
128
+ return Object.assign(Object.assign({}, contact), { subContacts: [
129
+ new SubContact_1.SubContact({
130
+ id: (0, crypto_1.randomUUID)(),
131
+ healthElementId: healthElement.id,
132
+ services: [new ServiceLink_1.ServiceLink({ serviceId: contact.services[0].id })],
133
+ }),
134
+ ] });
135
+ });
136
+ const createdContact = (yield contactApiForHcp.createContactWithUser(hcpUser, contactToCreate));
137
+ (0, chai_1.assert)(createdContact != null);
138
+ // When
139
+ const foundServices = yield contactApiForHcp.filterServicesBy(undefined, undefined, new FilterChainService_1.FilterChainService({
140
+ filter: new ServiceByHcPartyHealthElementIdsFilter_1.ServiceByHcPartyHealthElementIdsFilter({
141
+ healthcarePartyId: hcpUser.healthcarePartyId,
142
+ healthElementIds: [healthElement.id],
143
+ }),
144
+ }));
145
+ // Then
146
+ (0, chai_1.assert)(foundServices.rows.length == 1);
147
+ (0, chai_1.assert)(foundServices.rows[0].id == createdContact.services[0].id);
148
+ (0, chai_1.assert)(foundServices.rows[0].healthElementsIds.find((heId) => heId == healthElement.id) != undefined);
149
+ }));
150
+ it('contacts findBy for HCP GET and POSt', () => __awaiter(void 0, void 0, void 0, function* () {
151
+ // Given
152
+ const { userApi: userApiForHcp, dataOwnerApi: dataOwnerApiForHcp, patientApi: patientApiForHcp, contactApi: contactApiForHcp, healthcareElementApi: hElementApiForHcp, cryptoApi: cryptoApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
153
+ const hcpUser = yield userApiForHcp.getCurrentUser();
154
+ const patient = (yield createPatient(patientApiForHcp, hcpUser));
155
+ const healthElement = yield createHealthElement(hElementApiForHcp, hcpUser, patient);
156
+ const contactToCreate = yield createBasicContact(contactApiForHcp, hcpUser, patient).then((contact) => {
157
+ return Object.assign(Object.assign({}, contact), { subContacts: [
158
+ new SubContact_1.SubContact({
159
+ id: (0, crypto_1.randomUUID)(),
160
+ healthElementId: healthElement.id,
161
+ services: [new ServiceLink_1.ServiceLink({ serviceId: contact.services[0].id })],
162
+ }),
163
+ ] });
164
+ });
165
+ const createdContact = (yield contactApiForHcp.createContactWithUser(hcpUser, contactToCreate));
166
+ // When
167
+ const foundContats = yield contactApiForHcp.findBy(hcpUser.healthcarePartyId, patient, false);
168
+ const foundContatsUsingPost = yield contactApiForHcp.findBy(hcpUser.healthcarePartyId, patient, true);
169
+ // Then
170
+ (0, chai_1.assert)(foundContats.length == 1, 'Found items should be 1');
171
+ (0, chai_1.assert)(foundContats[0].id == contactToCreate.id, 'Found item should be the same as the created one');
172
+ (0, chai_1.assert)(foundContatsUsingPost.length == 1, 'Found items using post should be 1');
173
+ (0, chai_1.assert)(foundContatsUsingPost[0].id == createdContact.id, 'Found item using post should be the same as the created one');
174
+ }));
175
+ it('Share with should work as expected', () => __awaiter(void 0, void 0, void 0, function* () {
176
+ const api1 = yield initApi(env, test_utils_1.hcp1Username);
177
+ const user1 = yield api1.userApi.getCurrentUser();
178
+ const api2 = yield initApi(env, test_utils_1.hcp2Username);
179
+ const user2 = yield api2.userApi.getCurrentUser();
180
+ const samplePatient = yield api1.patientApi.createPatientWithUser(user1, yield api1.patientApi.newInstance(user1, { firstName: 'Gigio', lastName: 'Bagigio' }));
181
+ const entity = (yield api1.contactApi.createContactWithUser(user1, yield createBasicContact(api1.contactApi, user1, samplePatient)));
182
+ (0, chai_1.expect)(entity.services[0].encryptedSelf).to.not.be.undefined;
183
+ yield api2.contactApi
184
+ .getContactWithUser(user2, entity.id)
185
+ .then(() => {
186
+ throw new Error('Should not be able to get the entity');
187
+ })
188
+ .catch(() => {
189
+ /* expected */
190
+ });
191
+ yield api1.contactApi.shareWith(user2.healthcarePartyId, entity);
192
+ const retrieved = yield api2.contactApi.getContactWithUser(user2, entity.id);
193
+ (0, chai_1.expect)(retrieved.services[0].content).deep.equals(entity.services[0].content);
194
+ (0, chai_1.expect)((yield api2.contactApi.decryptPatientIdOf(retrieved))[0]).to.equal(samplePatient.id);
195
+ }));
196
+ it('Custom service encryption fields should be applied recursively on compound services', () => __awaiter(void 0, void 0, void 0, function* () {
197
+ var _a, _b, _c, _d;
198
+ const RSA = new RSA_1.RSAUtils(crypto_1.webcrypto);
199
+ const api = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: env.dataOwnerDetails[test_utils_1.hcp1Username].user, password: env.dataOwnerDetails[test_utils_1.hcp1Username].password }, new TestCryptoStrategies_1.TestCryptoStrategies({
200
+ publicKey: yield RSA.importKey('spki', (0, icc_x_api_1.hex2ua)(env.dataOwnerDetails[test_utils_1.hcp1Username].publicKey), ['encrypt']),
201
+ privateKey: yield RSA.importKey('pkcs8', (0, icc_x_api_1.hex2ua)(env.dataOwnerDetails[test_utils_1.hcp1Username].privateKey), ['decrypt']),
202
+ }), crypto_1.webcrypto, fetch, {
203
+ storage: new TestStorage_1.TestStorage(),
204
+ keyStorage: new TestStorage_1.TestKeyStorage(),
205
+ encryptedFieldsConfig: {
206
+ contact: ['descr', 'location'],
207
+ service: ['comment'],
208
+ },
209
+ });
210
+ const contactData = {
211
+ descr: 'secret',
212
+ location: 'secret',
213
+ externalId: 'notSecret',
214
+ services: [
215
+ {
216
+ id: 'flat',
217
+ label: 'notSecret1',
218
+ comment: 'secret2',
219
+ content: { fr: { stringValue: 'Salut' }, nl: { stringValue: 'Halo' } },
220
+ },
221
+ {
222
+ id: 'compound',
223
+ content: {
224
+ fr: {
225
+ compoundValue: [
226
+ {
227
+ id: 'nested1',
228
+ label: 'notSecret3',
229
+ comment: 'secret4',
230
+ content: { fr: { stringValue: 'A' } },
231
+ },
232
+ {
233
+ id: 'nested2',
234
+ label: 'notSecret5',
235
+ comment: 'secret6',
236
+ content: { fr: { stringValue: 'B' } },
237
+ },
238
+ {
239
+ id: 'nested3',
240
+ label: 'notSecret7',
241
+ comment: 'secret8',
242
+ content: {
243
+ fr: {
244
+ compoundValue: [
245
+ {
246
+ id: 'deeplyNested',
247
+ label: 'notSecret9',
248
+ comment: 'secret10',
249
+ content: { fr: { stringValue: 'C' } },
250
+ },
251
+ ],
252
+ },
253
+ },
254
+ },
255
+ ],
256
+ },
257
+ },
258
+ },
259
+ ],
260
+ };
261
+ const user = yield api.userApi.getCurrentUser();
262
+ const patient = yield createPatient(api.patientApi, user);
263
+ const contact = yield api.contactApi.createContactWithUser(user, yield api.contactApi.newInstance(user, patient, contactData));
264
+ const encryptedContact = yield new icc_api_1.IccContactApi(env.iCureUrl, {}, api.authApi.authenticationProvider, fetch).getContact(contact.id);
265
+ (0, chai_1.expect)(encryptedContact.descr).to.be.undefined;
266
+ (0, chai_1.expect)(encryptedContact.location).to.be.undefined;
267
+ (0, chai_1.expect)(encryptedContact.externalId).to.equal(contactData.externalId);
268
+ (0, chai_1.expect)(encryptedContact.encryptedSelf).to.not.be.undefined;
269
+ const flat = encryptedContact.services.find((s) => s.id === 'flat');
270
+ (0, chai_1.expect)(flat.label).to.equal(contactData.services[0].label);
271
+ (0, chai_1.expect)(flat.comment).to.be.undefined;
272
+ (0, chai_1.expect)(Object.keys((_a = flat.content) !== null && _a !== void 0 ? _a : {})).to.have.length(0);
273
+ (0, chai_1.expect)(flat.encryptedSelf).to.not.be.undefined;
274
+ const compound = encryptedContact.services.find((s) => s.id === 'compound');
275
+ (0, chai_1.expect)(compound.label).to.equal(contactData.services[1].label);
276
+ (0, chai_1.expect)(compound.comment).to.be.undefined;
277
+ (0, chai_1.expect)(compound.encryptedSelf).to.not.be.undefined;
278
+ const nested1 = compound.content.fr.compoundValue.find((s) => s.id === 'nested1');
279
+ (0, chai_1.expect)(nested1.label).to.equal(contactData.services[1].content.fr.compoundValue[0].label);
280
+ (0, chai_1.expect)(nested1.comment).to.be.undefined;
281
+ (0, chai_1.expect)(Object.keys((_b = nested1.content) !== null && _b !== void 0 ? _b : {})).to.have.length(0);
282
+ (0, chai_1.expect)(nested1.encryptedSelf).to.not.be.undefined;
283
+ const nested2 = compound.content.fr.compoundValue.find((s) => s.id === 'nested2');
284
+ (0, chai_1.expect)(nested2.label).to.equal(contactData.services[1].content.fr.compoundValue[1].label);
285
+ (0, chai_1.expect)(nested2.comment).to.be.undefined;
286
+ (0, chai_1.expect)(Object.keys((_c = nested2.content) !== null && _c !== void 0 ? _c : {})).to.have.length(0);
287
+ (0, chai_1.expect)(nested2.encryptedSelf).to.not.be.undefined;
288
+ const nested3 = compound.content.fr.compoundValue.find((s) => s.id === 'nested3');
289
+ (0, chai_1.expect)(nested3.label).to.equal(contactData.services[1].content.fr.compoundValue[2].label);
290
+ (0, chai_1.expect)(nested3.comment).to.be.undefined;
291
+ (0, chai_1.expect)(nested3.encryptedSelf).to.not.be.undefined;
292
+ const deeplyNested = nested3.content.fr.compoundValue[0];
293
+ (0, chai_1.expect)(deeplyNested.label).to.equal(contactData.services[1].content.fr.compoundValue[2].content.fr.compoundValue[0].label);
294
+ (0, chai_1.expect)(deeplyNested.comment).to.be.undefined;
295
+ (0, chai_1.expect)(Object.keys((_d = deeplyNested.content) !== null && _d !== void 0 ? _d : {})).to.have.length(0);
296
+ (0, chai_1.expect)(deeplyNested.encryptedSelf).to.not.be.undefined;
297
+ }));
298
+ it('newInstance should honor non-default values unless they are undefined', () => __awaiter(void 0, void 0, void 0, function* () {
299
+ const api = yield initApi(env, test_utils_1.hcp1Username);
300
+ const user = yield api.userApi.getCurrentUser();
301
+ const patient = yield api.patientApi.createPatientWithUser(user, yield api.patientApi.newInstance(user, { firstName: 'Gigio', lastName: 'Bagigio' }));
302
+ const contactUndefinedId = yield api.contactApi.newInstance(user, patient, { id: undefined });
303
+ const customId = 'customId';
304
+ const contactCustomId = yield api.contactApi.newInstance(user, patient, { id: customId });
305
+ const contactWithUndefinedInit = yield api.contactApi.newInstance(user, patient, undefined);
306
+ (0, chai_1.expect)(contactUndefinedId.id).to.not.be.undefined;
307
+ (0, chai_1.expect)(contactWithUndefinedInit.id).to.not.be.undefined;
308
+ (0, chai_1.expect)(contactCustomId.id).to.equal(customId);
309
+ }));
310
+ });
311
+ //# sourceMappingURL=icc-contact-x-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icc-contact-x-api.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-contact-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAA8B;AAE9B,4BAAyB;AAEzB,+CAAmG;AACnG,yDAAqD;AACrD,+BAAqC;AACrC,mCAA8C;AAC9C,oDAAuH;AACvH,mDAA+C;AAC/C,yDAAqD;AACrD,yDAAqD;AACrD,yDAAqD;AAErD,qEAAiE;AACjE,+DAA2D;AAC3D,iEAA6D;AAC7D,+EAA2E;AAC3E,2HAAuH;AACvH,IAAO,OAAO,GAAG,sBAAS,CAAC,OAAO,CAAA;AAClC,mDAAmE;AACnE,wEAAoE;AACpE,sDAAkE;AAClE,oDAAqD;AACrD,2CAA6C;AAE7C,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAyB,CAAA;AAE7B,IAAA,cAAM,EAAC;;QACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACpB,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,GAAE,CAAA;QACrD,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAA,uBAAe,GAAE,CAAC,CAAA;IACpD,CAAC;CAAA,CAAC,CAAA;AAEF,SAAe,aAAa,CAAC,gBAAgC,EAAE,OAAa;;QAC1E,OAAO,gBAAgB,CAAC,qBAAqB,CAC3C,OAAO,EACP,MAAM,gBAAgB,CAAC,WAAW,CAChC,OAAO,EACP,IAAI,iBAAO,CAAC;YACV,EAAE,EAAE,IAAA,mBAAU,GAAE;YAChB,SAAS,EAAE,MAAM;YACjB,QAAQ,EAAE,MAAM;YAChB,IAAI,EAAE,kBAAkB;SACzB,CAAC,CACH,CACF,CAAA;IACH,CAAC;CAAA;AAED,SAAe,mBAAmB,CAAC,gBAAiC,EAAE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C,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;QAC3F,IAAA,aAAM,EAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAA;QACjD,IAAA,aAAM,EAAC,wBAAwB,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAA;QACvD,IAAA,aAAM,EAAC,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAC/C,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { before } from 'mocha'\n\nimport 'isomorphic-fetch'\n\nimport { hex2ua, IccContactXApi, IccHelementXApi, IccPatientXApi, IcureApi } from '../../icc-x-api'\nimport { Patient } from '../../icc-api/model/Patient'\nimport { assert, expect } from 'chai'\nimport { randomUUID, webcrypto } from 'crypto'\nimport { getEnvironmentInitializer, hcp1Username, hcp2Username, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { Code } from '../../icc-api/model/Code'\nimport { Contact } from '../../icc-api/model/Contact'\nimport { Service } from '../../icc-api/model/Service'\nimport { Content } from '../../icc-api/model/Content'\nimport { User } from '../../icc-api/model/User'\nimport { HealthElement } from '../../icc-api/model/HealthElement'\nimport { SubContact } from '../../icc-api/model/SubContact'\nimport { ServiceLink } from '../../icc-api/model/ServiceLink'\nimport { FilterChainService } from '../../icc-api/model/FilterChainService'\nimport { ServiceByHcPartyHealthElementIdsFilter } from '../../icc-x-api/filters/ServiceByHcPartyHealthElementIdsFilter'\nimport initApi = TestUtils.initApi\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { TestCryptoStrategies } from '../utils/TestCryptoStrategies'\nimport { TestKeyStorage, TestStorage } from '../utils/TestStorage'\nimport { RSAUtils } from '../../icc-x-api/crypto/RSA'\nimport { IccContactApi } from '../../icc-api'\n\nsetLocalStorage(fetch)\nlet env: TestVars | undefined\n\nbefore(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n})\n\nasync function createPatient(patientApiForHcp: IccPatientXApi, hcpUser: User) {\n return patientApiForHcp.createPatientWithUser(\n hcpUser,\n await patientApiForHcp.newInstance(\n hcpUser,\n new Patient({\n id: randomUUID(),\n firstName: 'John',\n lastName: 'Snow',\n note: 'Winter is coming',\n })\n )\n )\n}\n\nasync function createHealthElement(healthElementApi: IccHelementXApi, hcpUser: User, patient: Patient) {\n return healthElementApi.createHealthElementWithUser(\n hcpUser,\n await healthElementApi.newInstance(\n hcpUser,\n patient,\n new HealthElement({\n id: randomUUID(),\n note: 'My secret note',\n tags: [\n new Code({\n id: 'ICURE|MY-CODE|1',\n code: 'MY-CODE',\n type: 'ICURE',\n version: '1',\n }),\n ],\n }),\n { confidential: true }\n )\n )\n}\n\nfunction createBasicContact(contactApiForHcp: IccContactXApi, hcpUser: User, patient: Patient) {\n return contactApiForHcp.newInstance(\n hcpUser,\n patient,\n new Contact({\n id: randomUUID(),\n services: [\n contactApiForHcp.service().newInstance(\n hcpUser,\n new Service({\n id: randomUUID(),\n valueDate: 20220203111034,\n content: { en: new Content({ numberValue: 53.5 }) },\n tags: [\n new Code({\n id: 'LOINC|29463-7|2',\n code: '29463-7',\n type: 'LOINC',\n version: '2',\n }),\n ],\n })\n ),\n ],\n descr: 'Weight value',\n }),\n { confidential: true }\n )\n}\n\ndescribe('icc-x-contact-api Tests', () => {\n it('CreateContactWithUser Success for HCP', async () => {\n // Given\n const { userApi: userApiForHcp, patientApi: patientApiForHcp, contactApi: contactApiForHcp } = await initApi(env!, hcp1Username)\n\n const hcpUser = await userApiForHcp.getCurrentUser()\n\n const patient = await createPatient(patientApiForHcp, hcpUser)\n const contactToCreate = await createBasicContact(contactApiForHcp, hcpUser, patient)\n\n // When\n const createdContact = (await contactApiForHcp.createContactWithUser(hcpUser, contactToCreate)) as Contact\n\n // Then\n const readContact = await contactApiForHcp.getContactWithUser(hcpUser, createdContact.id!)\n expect(readContact).to.not.be.undefined\n expect(readContact).to.not.be.null\n expect(readContact.openingDate).to.not.be.undefined\n expect(readContact.openingDate).to.not.be.null\n expect(readContact.groupId).to.not.be.undefined\n expect(readContact.groupId).to.not.be.null\n expect(readContact.responsible).to.be.equal(hcpUser.healthcarePartyId)\n expect(readContact.id).to.be.equal(contactToCreate.id)\n expect(readContact.descr).to.be.equal(contactToCreate.descr)\n expect(readContact.delegations![hcpUser.healthcarePartyId!].length).to.equals(1)\n expect(readContact.delegations![hcpUser.healthcarePartyId!][0].key).to.not.be.undefined\n expect(readContact.encryptionKeys![hcpUser.healthcarePartyId!].length).to.equals(1)\n expect(readContact.encryptionKeys![hcpUser.healthcarePartyId!][0].key).to.not.be.undefined\n expect(readContact.cryptedForeignKeys![hcpUser.healthcarePartyId!].length).to.equals(1)\n expect(readContact.cryptedForeignKeys![hcpUser.healthcarePartyId!][0].key).to.not.be.undefined\n expect(readContact.services![0].responsible).to.be.equal(hcpUser.healthcarePartyId)\n expect(readContact.services![0].id).to.be.equal(contactToCreate.services![0].id)\n expect(readContact.services![0].valueDate).to.be.equal(contactToCreate.services![0].valueDate)\n expect(readContact.services![0].tags![0].id).to.be.equal(contactToCreate.services![0].tags![0].id!)\n })\n\n it('Filter Services By HealthElementId - Success', async () => {\n // Given\n const {\n userApi: userApiForHcp,\n patientApi: patientApiForHcp,\n contactApi: contactApiForHcp,\n healthcareElementApi: hElementApiForHcp,\n } = await initApi(env!, hcp1Username)\n\n const hcpUser = await userApiForHcp.getCurrentUser()\n\n const patient = await createPatient(patientApiForHcp, hcpUser)\n const healthElement = await createHealthElement(hElementApiForHcp, hcpUser, patient)\n const contactToCreate = await createBasicContact(contactApiForHcp, hcpUser, patient).then((contact) => {\n return {\n ...contact,\n subContacts: [\n new SubContact({\n id: randomUUID(),\n healthElementId: healthElement!.id!,\n services: [new ServiceLink({ serviceId: contact.services![0].id })],\n }),\n ],\n }\n })\n\n const createdContact = (await contactApiForHcp.createContactWithUser(hcpUser, contactToCreate)) as Contact\n assert(createdContact != null)\n\n // When\n const foundServices = await contactApiForHcp.filterServicesBy(\n undefined,\n undefined,\n new FilterChainService({\n filter: new ServiceByHcPartyHealthElementIdsFilter({\n healthcarePartyId: hcpUser.healthcarePartyId!,\n healthElementIds: [healthElement!.id!],\n }),\n })\n )\n\n // Then\n assert(foundServices.rows!.length == 1)\n assert(foundServices.rows![0].id == createdContact.services![0].id)\n assert(foundServices.rows![0].healthElementsIds!.find((heId) => heId == healthElement!.id!) != undefined)\n })\n\n it('contacts findBy for HCP GET and POSt', async () => {\n // Given\n const {\n userApi: userApiForHcp,\n dataOwnerApi: dataOwnerApiForHcp,\n patientApi: patientApiForHcp,\n contactApi: contactApiForHcp,\n healthcareElementApi: hElementApiForHcp,\n cryptoApi: cryptoApiForHcp,\n } = await initApi(env!, hcp1Username)\n\n const hcpUser = await userApiForHcp.getCurrentUser()\n\n const patient = (await createPatient(patientApiForHcp, hcpUser)) as Patient\n const healthElement = await createHealthElement(hElementApiForHcp, hcpUser, patient)\n const contactToCreate = await createBasicContact(contactApiForHcp, hcpUser, patient).then((contact) => {\n return {\n ...contact,\n subContacts: [\n new SubContact({\n id: randomUUID(),\n healthElementId: healthElement!.id!,\n services: [new ServiceLink({ serviceId: contact.services![0].id })],\n }),\n ],\n }\n })\n\n const createdContact = (await contactApiForHcp.createContactWithUser(hcpUser, contactToCreate)) as Contact\n\n // When\n const foundContats = await contactApiForHcp.findBy(hcpUser.healthcarePartyId!, patient, false)\n const foundContatsUsingPost = await contactApiForHcp.findBy(hcpUser.healthcarePartyId!, patient, true)\n\n // Then\n assert(foundContats.length == 1, 'Found items should be 1')\n assert(foundContats[0].id == contactToCreate.id, 'Found item should be the same as the created one')\n\n assert(foundContatsUsingPost.length == 1, 'Found items using post should be 1')\n assert(foundContatsUsingPost[0].id == createdContact.id, 'Found item using post should be the same as the created one')\n })\n\n it('Share with should work as expected', async () => {\n const api1 = await initApi(env!, hcp1Username)\n const user1 = await api1.userApi.getCurrentUser()\n const api2 = await initApi(env!, hcp2Username)\n const user2 = await api2.userApi.getCurrentUser()\n const samplePatient = await api1.patientApi.createPatientWithUser(\n user1,\n await api1.patientApi.newInstance(user1, { firstName: 'Gigio', lastName: 'Bagigio' })\n )\n const entity = (await api1.contactApi.createContactWithUser(user1, await createBasicContact(api1.contactApi, user1, samplePatient)))!\n expect(entity.services![0].encryptedSelf).to.not.be.undefined\n await api2.contactApi\n .getContactWithUser(user2, entity.id!)\n .then(() => {\n throw new Error('Should not be able to get the entity')\n })\n .catch(() => {\n /* expected */\n })\n await api1.contactApi.shareWith(user2.healthcarePartyId!, entity)\n const retrieved = await api2.contactApi.getContactWithUser(user2, entity.id!)\n expect(retrieved.services![0].content).deep.equals(entity.services![0].content)\n expect((await api2.contactApi.decryptPatientIdOf(retrieved))[0]).to.equal(samplePatient.id)\n })\n\n it('Custom service encryption fields should be applied recursively on compound services', async () => {\n const RSA = new RSAUtils(webcrypto as any)\n const api = await IcureApi.initialise(\n env!.iCureUrl,\n { username: env!.dataOwnerDetails[hcp1Username].user, password: env!.dataOwnerDetails[hcp1Username].password },\n new TestCryptoStrategies({\n publicKey: await RSA.importKey('spki', hex2ua(env!.dataOwnerDetails[hcp1Username].publicKey), ['encrypt']),\n privateKey: await RSA.importKey('pkcs8', hex2ua(env!.dataOwnerDetails[hcp1Username].privateKey), ['decrypt']),\n }),\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n encryptedFieldsConfig: {\n contact: ['descr', 'location'],\n service: ['comment'],\n },\n }\n )\n const contactData = {\n descr: 'secret',\n location: 'secret',\n externalId: 'notSecret',\n services: [\n {\n id: 'flat',\n label: 'notSecret1',\n comment: 'secret2',\n content: { fr: { stringValue: 'Salut' }, nl: { stringValue: 'Halo' } },\n },\n {\n id: 'compound',\n content: {\n fr: {\n compoundValue: [\n {\n id: 'nested1',\n label: 'notSecret3',\n comment: 'secret4',\n content: { fr: { stringValue: 'A' } },\n },\n {\n id: 'nested2',\n label: 'notSecret5',\n comment: 'secret6',\n content: { fr: { stringValue: 'B' } },\n },\n {\n id: 'nested3',\n label: 'notSecret7',\n comment: 'secret8',\n content: {\n fr: {\n compoundValue: [\n {\n id: 'deeplyNested',\n label: 'notSecret9',\n comment: 'secret10',\n content: { fr: { stringValue: 'C' } },\n },\n ],\n },\n },\n },\n ],\n },\n },\n },\n ],\n }\n const user = await api.userApi.getCurrentUser()\n const patient = await createPatient(api.patientApi, user)\n const contact = await api.contactApi.createContactWithUser(user, await api.contactApi.newInstance(user, patient, contactData))\n const encryptedContact = await new IccContactApi(env!.iCureUrl, {}, api.authApi.authenticationProvider, fetch).getContact(contact!.id!)\n expect(encryptedContact.descr).to.be.undefined\n expect(encryptedContact.location).to.be.undefined\n expect(encryptedContact.externalId).to.equal(contactData.externalId)\n expect(encryptedContact.encryptedSelf).to.not.be.undefined\n const flat = encryptedContact.services!.find((s) => s.id === 'flat')!\n expect(flat.label).to.equal(contactData.services[0].label)\n expect(flat.comment).to.be.undefined\n expect(Object.keys(flat.content ?? {})).to.have.length(0)\n expect(flat.encryptedSelf).to.not.be.undefined\n const compound = encryptedContact.services!.find((s) => s.id === 'compound')!\n expect(compound.label).to.equal(contactData.services[1].label)\n expect(compound.comment).to.be.undefined\n expect(compound.encryptedSelf).to.not.be.undefined\n const nested1 = compound.content!.fr.compoundValue!.find((s) => s.id === 'nested1')!\n expect(nested1.label).to.equal(contactData.services[1].content!.fr.compoundValue![0].label)\n expect(nested1.comment).to.be.undefined\n expect(Object.keys(nested1.content ?? {})).to.have.length(0)\n expect(nested1.encryptedSelf).to.not.be.undefined\n const nested2 = compound.content!.fr.compoundValue!.find((s) => s.id === 'nested2')!\n expect(nested2.label).to.equal(contactData.services[1].content!.fr.compoundValue![1].label)\n expect(nested2.comment).to.be.undefined\n expect(Object.keys(nested2.content ?? {})).to.have.length(0)\n expect(nested2.encryptedSelf).to.not.be.undefined\n const nested3 = compound.content!.fr.compoundValue!.find((s) => s.id === 'nested3')!\n expect(nested3.label).to.equal(contactData.services[1].content!.fr.compoundValue![2].label)\n expect(nested3.comment).to.be.undefined\n expect(nested3.encryptedSelf).to.not.be.undefined\n const deeplyNested = nested3.content!.fr.compoundValue![0]\n expect(deeplyNested.label).to.equal(contactData.services[1].content!.fr.compoundValue![2].content!.fr.compoundValue![0].label)\n expect(deeplyNested.comment).to.be.undefined\n expect(Object.keys(deeplyNested.content ?? {})).to.have.length(0)\n expect(deeplyNested.encryptedSelf).to.not.be.undefined\n })\n\n it('newInstance should honor non-default values unless they are undefined', async () => {\n const api = await initApi(env!, hcp1Username)\n const user = await api.userApi.getCurrentUser()\n const patient = await api.patientApi.createPatientWithUser(\n user,\n await api.patientApi.newInstance(user, { firstName: 'Gigio', lastName: 'Bagigio' })\n )\n const contactUndefinedId = await api.contactApi.newInstance(user, patient, { id: undefined })\n const customId = 'customId'\n const contactCustomId = await api.contactApi.newInstance(user, patient, { id: customId })\n const contactWithUndefinedInit = await api.contactApi.newInstance(user, patient, undefined)\n expect(contactUndefinedId.id).to.not.be.undefined\n expect(contactWithUndefinedInit.id).to.not.be.undefined\n expect(contactCustomId.id).to.equal(customId)\n })\n})\n"]}
@@ -0,0 +1 @@
1
+ import 'isomorphic-fetch';