@icure/api 8.0.8 → 8.0.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 (270) hide show
  1. package/icc-api/model/models.d.ts +1 -0
  2. package/icc-api/model/models.js +1 -0
  3. package/icc-api/model/models.js.map +1 -1
  4. package/icc-x-api/crypto/BaseExchangeDataManager.js +1 -1
  5. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
  6. package/icc-x-api/crypto/BaseExchangeKeysManager.js +7 -3
  7. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
  8. package/icc-x-api/crypto/ExchangeDataManager.js +3 -2
  9. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  10. package/icc-x-api/crypto/KeyRecovery.js +6 -5
  11. package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
  12. package/icc-x-api/crypto/RSA.d.ts +4 -1
  13. package/icc-x-api/crypto/RSA.js +6 -1
  14. package/icc-x-api/crypto/RSA.js.map +1 -1
  15. package/icc-x-api/crypto/SecureDelegationsManager.js +2 -1
  16. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
  17. package/icc-x-api/crypto/ShamirKeysManager.js +8 -9
  18. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
  19. package/icc-x-api/crypto/TransferKeysManager.js +4 -3
  20. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
  21. package/icc-x-api/crypto/UserEncryptionKeysManager.js +4 -4
  22. package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -1
  23. package/icc-x-api/crypto/UserSignatureKeysManager.js +9 -5
  24. package/icc-x-api/crypto/UserSignatureKeysManager.js.map +1 -1
  25. package/icc-x-api/crypto/utils.d.ts +13 -4
  26. package/icc-x-api/crypto/utils.js +27 -9
  27. package/icc-x-api/crypto/utils.js.map +1 -1
  28. package/icc-x-api/icc-accesslog-x-api.js +16 -14
  29. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  30. package/icc-x-api/icc-calendar-item-x-api.d.ts +2 -2
  31. package/icc-x-api/icc-calendar-item-x-api.js +17 -17
  32. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  33. package/icc-x-api/icc-classification-x-api.js +12 -11
  34. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  35. package/icc-x-api/icc-contact-x-api.d.ts +2 -2
  36. package/icc-x-api/icc-contact-x-api.js +23 -20
  37. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  38. package/icc-x-api/icc-data-owner-x-api.js +1 -1
  39. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  40. package/icc-x-api/icc-document-x-api.js +17 -16
  41. package/icc-x-api/icc-document-x-api.js.map +1 -1
  42. package/icc-x-api/icc-form-x-api.js +13 -12
  43. package/icc-x-api/icc-form-x-api.js.map +1 -1
  44. package/icc-x-api/icc-helement-x-api.js +18 -16
  45. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  46. package/icc-x-api/icc-icure-maintenance-x-api.js +4 -3
  47. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
  48. package/icc-x-api/icc-invoice-x-api.js +12 -11
  49. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  50. package/icc-x-api/icc-maintenance-task-x-api.js +11 -11
  51. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  52. package/icc-x-api/icc-message-x-api.js +14 -14
  53. package/icc-x-api/icc-message-x-api.js.map +1 -1
  54. package/icc-x-api/icc-patient-x-api.js +28 -27
  55. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  56. package/icc-x-api/icc-receipt-x-api.js +11 -10
  57. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  58. package/icc-x-api/icc-recovery-x-api.js +3 -2
  59. package/icc-x-api/icc-recovery-x-api.js.map +1 -1
  60. package/icc-x-api/icc-time-table-x-api.js +9 -8
  61. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  62. package/icc-x-api/icc-topic-x-api.js +13 -13
  63. package/icc-x-api/icc-topic-x-api.js.map +1 -1
  64. package/icc-x-api/storage/IcureStorageFacade.js +4 -1
  65. package/icc-x-api/storage/IcureStorageFacade.js.map +1 -1
  66. package/icc-x-api/utils/EntityWithDelegationTypeName.d.ts +17 -1
  67. package/icc-x-api/utils/EntityWithDelegationTypeName.js +33 -15
  68. package/icc-x-api/utils/EntityWithDelegationTypeName.js.map +1 -1
  69. package/package.json +1 -1
  70. package/test/icc-api/api/IccAnonymousAccessApi.d.ts +1 -0
  71. package/test/icc-api/api/IccAnonymousAccessApi.js +58 -0
  72. package/test/icc-api/api/IccAnonymousAccessApi.js.map +1 -0
  73. package/test/icc-api/api/IccDocumentApi.d.ts +1 -0
  74. package/test/icc-api/api/IccDocumentApi.js +208 -0
  75. package/test/icc-api/api/IccDocumentApi.js.map +1 -0
  76. package/test/icc-api/api/IccGroupApi.d.ts +1 -0
  77. package/test/icc-api/api/IccGroupApi.js +50 -0
  78. package/test/icc-api/api/IccGroupApi.js.map +1 -0
  79. package/test/icc-api/api/IccRecoveryDataApi.d.ts +1 -0
  80. package/test/icc-api/api/IccRecoveryDataApi.js +95 -0
  81. package/test/icc-api/api/IccRecoveryDataApi.js.map +1 -0
  82. package/test/icc-api/api/IccRoleApi.d.ts +1 -0
  83. package/test/icc-api/api/IccRoleApi.js +34 -0
  84. package/test/icc-api/api/IccRoleApi.js.map +1 -0
  85. package/test/icc-api/api/IccUserApi.d.ts +1 -0
  86. package/test/icc-api/api/IccUserApi.js +96 -0
  87. package/test/icc-api/api/IccUserApi.js.map +1 -0
  88. package/test/icc-api/e2e/IccCalendarItemApi.d.ts +1 -0
  89. package/test/icc-api/e2e/IccCalendarItemApi.js +46 -0
  90. package/test/icc-api/e2e/IccCalendarItemApi.js.map +1 -0
  91. package/test/icc-api/model/modelHelpersTest.d.ts +1 -0
  92. package/test/icc-api/model/modelHelpersTest.js +45 -0
  93. package/test/icc-api/model/modelHelpersTest.js.map +1 -0
  94. package/test/icc-x-api/auth/group-switch-test.d.ts +1 -0
  95. package/test/icc-x-api/auth/group-switch-test.js +81 -0
  96. package/test/icc-x-api/auth/group-switch-test.js.map +1 -0
  97. package/test/icc-x-api/auth/jwt-concurrency-test.d.ts +2 -0
  98. package/test/icc-x-api/auth/jwt-concurrency-test.js +113 -0
  99. package/test/icc-x-api/auth/jwt-concurrency-test.js.map +1 -0
  100. package/test/icc-x-api/auth/smart-auth-provider-test.d.ts +1 -0
  101. package/test/icc-x-api/auth/smart-auth-provider-test.js +224 -0
  102. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -0
  103. package/test/icc-x-api/autofix-anonymity-test.d.ts +1 -0
  104. package/test/icc-x-api/autofix-anonymity-test.js +108 -0
  105. package/test/icc-x-api/autofix-anonymity-test.js.map +1 -0
  106. package/test/icc-x-api/confidential-entities-test.d.ts +1 -0
  107. package/test/icc-x-api/confidential-entities-test.js +110 -0
  108. package/test/icc-x-api/confidential-entities-test.js.map +1 -0
  109. package/test/icc-x-api/crud/comprehensive-crud-test.d.ts +1 -0
  110. package/test/icc-x-api/crud/comprehensive-crud-test.js +276 -0
  111. package/test/icc-x-api/crud/comprehensive-crud-test.js.map +1 -0
  112. package/test/icc-x-api/crud/entities-crud-test-interface.d.ts +16 -0
  113. package/test/icc-x-api/crud/entities-crud-test-interface.js +422 -0
  114. package/test/icc-x-api/crud/entities-crud-test-interface.js.map +1 -0
  115. package/test/icc-x-api/crypto/anonymous-delegations-test.d.ts +1 -0
  116. package/test/icc-x-api/crypto/anonymous-delegations-test.js +588 -0
  117. package/test/icc-x-api/crypto/anonymous-delegations-test.js.map +1 -0
  118. package/test/icc-x-api/crypto/concurrency.d.ts +1 -0
  119. package/test/icc-x-api/crypto/concurrency.js +35 -0
  120. package/test/icc-x-api/crypto/concurrency.js.map +1 -0
  121. package/test/icc-x-api/crypto/crypto-utils.d.ts +1 -0
  122. package/test/icc-x-api/crypto/crypto-utils.js +80 -0
  123. package/test/icc-x-api/crypto/crypto-utils.js.map +1 -0
  124. package/test/icc-x-api/crypto/cryptoTest.d.ts +2 -0
  125. package/test/icc-x-api/crypto/cryptoTest.js +302 -0
  126. package/test/icc-x-api/crypto/cryptoTest.js.map +1 -0
  127. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.d.ts +1 -0
  128. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js +166 -0
  129. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js.map +1 -0
  130. package/test/icc-x-api/crypto/exchange-data-manager-test.d.ts +1 -0
  131. package/test/icc-x-api/crypto/exchange-data-manager-test.js +690 -0
  132. package/test/icc-x-api/crypto/exchange-data-manager-test.js.map +1 -0
  133. package/test/icc-x-api/crypto/full-crypto-test.d.ts +1 -0
  134. package/test/icc-x-api/crypto/full-crypto-test.js +457 -0
  135. package/test/icc-x-api/crypto/full-crypto-test.js.map +1 -0
  136. package/test/icc-x-api/crypto/secure-delegations-manager-test.d.ts +1 -0
  137. package/test/icc-x-api/crypto/secure-delegations-manager-test.js +266 -0
  138. package/test/icc-x-api/crypto/secure-delegations-manager-test.js.map +1 -0
  139. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.d.ts +1 -0
  140. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.js +393 -0
  141. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.js.map +1 -0
  142. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.d.ts +1 -0
  143. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.js +213 -0
  144. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.js.map +1 -0
  145. package/test/icc-x-api/crypto/shamir.d.ts +2 -0
  146. package/test/icc-x-api/crypto/shamir.js +166 -0
  147. package/test/icc-x-api/crypto/shamir.js.map +1 -0
  148. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.d.ts +1 -0
  149. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js +71 -0
  150. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +1 -0
  151. package/test/icc-x-api/crypto/signature-keys-manager-test.d.ts +1 -0
  152. package/test/icc-x-api/crypto/signature-keys-manager-test.js +44 -0
  153. package/test/icc-x-api/crypto/signature-keys-manager-test.js.map +1 -0
  154. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.d.ts +1 -0
  155. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js +246 -0
  156. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js.map +1 -0
  157. package/test/icc-x-api/entity-with-attachments-api-test.d.ts +1 -0
  158. package/test/icc-x-api/entity-with-attachments-api-test.js +142 -0
  159. package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -0
  160. package/test/icc-x-api/filters/filters.d.ts +1 -0
  161. package/test/icc-x-api/filters/filters.js +49 -0
  162. package/test/icc-x-api/filters/filters.js.map +1 -0
  163. package/test/icc-x-api/icc-accesslog-x-api.d.ts +1 -0
  164. package/test/icc-x-api/icc-accesslog-x-api.js +106 -0
  165. package/test/icc-x-api/icc-accesslog-x-api.js.map +1 -0
  166. package/test/icc-x-api/icc-auth-api.d.ts +1 -0
  167. package/test/icc-x-api/icc-auth-api.js +47 -0
  168. package/test/icc-x-api/icc-auth-api.js.map +1 -0
  169. package/test/icc-x-api/icc-calendar-item-x-api.d.ts +1 -0
  170. package/test/icc-x-api/icc-calendar-item-x-api.js +150 -0
  171. package/test/icc-x-api/icc-calendar-item-x-api.js.map +1 -0
  172. package/test/icc-x-api/icc-contact-x-api.d.ts +1 -0
  173. package/test/icc-x-api/icc-contact-x-api.js +279 -0
  174. package/test/icc-x-api/icc-contact-x-api.js.map +1 -0
  175. package/test/icc-x-api/icc-form-x-api.d.ts +1 -0
  176. package/test/icc-x-api/icc-form-x-api.js +98 -0
  177. package/test/icc-x-api/icc-form-x-api.js.map +1 -0
  178. package/test/icc-x-api/icc-helement-x-api-test.d.ts +1 -0
  179. package/test/icc-x-api/icc-helement-x-api-test.js +153 -0
  180. package/test/icc-x-api/icc-helement-x-api-test.js.map +1 -0
  181. package/test/icc-x-api/icc-invoice-x-api.d.ts +1 -0
  182. package/test/icc-x-api/icc-invoice-x-api.js +99 -0
  183. package/test/icc-x-api/icc-invoice-x-api.js.map +1 -0
  184. package/test/icc-x-api/icc-maintenance-task-x-api-test.d.ts +1 -0
  185. package/test/icc-x-api/icc-maintenance-task-x-api-test.js +221 -0
  186. package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +1 -0
  187. package/test/icc-x-api/icc-message-x-api.d.ts +1 -0
  188. package/test/icc-x-api/icc-message-x-api.js +328 -0
  189. package/test/icc-x-api/icc-message-x-api.js.map +1 -0
  190. package/test/icc-x-api/icc-patient-x-api-test.d.ts +1 -0
  191. package/test/icc-x-api/icc-patient-x-api-test.js +158 -0
  192. package/test/icc-x-api/icc-patient-x-api-test.js.map +1 -0
  193. package/test/icc-x-api/icc-recovery-x-api.d.ts +1 -0
  194. package/test/icc-x-api/icc-recovery-x-api.js +170 -0
  195. package/test/icc-x-api/icc-recovery-x-api.js.map +1 -0
  196. package/test/icc-x-api/icc-time-table-x-api.d.ts +1 -0
  197. package/test/icc-x-api/icc-time-table-x-api.js +100 -0
  198. package/test/icc-x-api/icc-time-table-x-api.js.map +1 -0
  199. package/test/icc-x-api/icc-topic-x-api.d.ts +1 -0
  200. package/test/icc-x-api/icc-topic-x-api.js +269 -0
  201. package/test/icc-x-api/icc-topic-x-api.js.map +1 -0
  202. package/test/icc-x-api/icc-user-x-api-test.d.ts +1 -0
  203. package/test/icc-x-api/icc-user-x-api-test.js +99 -0
  204. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -0
  205. package/test/icc-x-api/patient-user.d.ts +2 -0
  206. package/test/icc-x-api/patient-user.js +104 -0
  207. package/test/icc-x-api/patient-user.js.map +1 -0
  208. package/test/icc-x-api/storage/storage.d.ts +1 -0
  209. package/test/icc-x-api/storage/storage.js +48 -0
  210. package/test/icc-x-api/storage/storage.js.map +1 -0
  211. package/test/icc-x-api/test-api-no-parent.d.ts +1 -0
  212. package/test/icc-x-api/test-api-no-parent.js +79 -0
  213. package/test/icc-x-api/test-api-no-parent.js.map +1 -0
  214. package/test/icc-x-api/test-legacy-data-support.d.ts +1 -0
  215. package/test/icc-x-api/test-legacy-data-support.js +376 -0
  216. package/test/icc-x-api/test-legacy-data-support.js.map +1 -0
  217. package/test/icc-x-api/utils/graph-test.d.ts +1 -0
  218. package/test/icc-x-api/utils/graph-test.js +54 -0
  219. package/test/icc-x-api/utils/graph-test.js.map +1 -0
  220. package/test/icc-x-api/utils/lru-temporised-async-cache-test.d.ts +1 -0
  221. package/test/icc-x-api/utils/lru-temporised-async-cache-test.js +364 -0
  222. package/test/icc-x-api/utils/lru-temporised-async-cache-test.js.map +1 -0
  223. package/test/support/CSM-185.d.ts +1 -0
  224. package/test/support/CSM-185.js +124 -0
  225. package/test/support/CSM-185.js.map +1 -0
  226. package/test/support/CSM-243.d.ts +1 -0
  227. package/test/support/CSM-243.js +120 -0
  228. package/test/support/CSM-243.js.map +1 -0
  229. package/test/support/CSM-87.d.ts +0 -0
  230. package/test/support/CSM-87.js +21 -0
  231. package/test/support/CSM-87.js.map +1 -0
  232. package/test/support/CSM-93.d.ts +1 -0
  233. package/test/support/CSM-93.js +112 -0
  234. package/test/support/CSM-93.js.map +1 -0
  235. package/test/utils/FakeDataOwnerApi.d.ts +32 -0
  236. package/test/utils/FakeDataOwnerApi.js +136 -0
  237. package/test/utils/FakeDataOwnerApi.js.map +1 -0
  238. package/test/utils/FakeEncryptionKeysManager.d.ts +35 -0
  239. package/test/utils/FakeEncryptionKeysManager.js +87 -0
  240. package/test/utils/FakeEncryptionKeysManager.js.map +1 -0
  241. package/test/utils/FakeExchangeDataApi.d.ts +30 -0
  242. package/test/utils/FakeExchangeDataApi.js +74 -0
  243. package/test/utils/FakeExchangeDataApi.js.map +1 -0
  244. package/test/utils/FakeExchangeDataManager.d.ts +40 -0
  245. package/test/utils/FakeExchangeDataManager.js +89 -0
  246. package/test/utils/FakeExchangeDataManager.js.map +1 -0
  247. package/test/utils/FakeExchangeDataMapManager.d.ts +12 -0
  248. package/test/utils/FakeExchangeDataMapManager.js +38 -0
  249. package/test/utils/FakeExchangeDataMapManager.js.map +1 -0
  250. package/test/utils/FakeGenericApi.d.ts +16 -0
  251. package/test/utils/FakeGenericApi.js +65 -0
  252. package/test/utils/FakeGenericApi.js.map +1 -0
  253. package/test/utils/FakeSignatureKeysManager.d.ts +16 -0
  254. package/test/utils/FakeSignatureKeysManager.js +54 -0
  255. package/test/utils/FakeSignatureKeysManager.js.map +1 -0
  256. package/test/utils/TestApi.d.ts +3 -0
  257. package/test/utils/TestApi.js +30 -0
  258. package/test/utils/TestApi.js.map +1 -0
  259. package/test/utils/TestCollectionUtils.d.ts +1 -0
  260. package/test/utils/TestCollectionUtils.js +109 -0
  261. package/test/utils/TestCollectionUtils.js.map +1 -0
  262. package/test/utils/TestCryptoStrategies.d.ts +42 -0
  263. package/test/utils/TestCryptoStrategies.js +80 -0
  264. package/test/utils/TestCryptoStrategies.js.map +1 -0
  265. package/test/utils/TestStorage.d.ts +23 -0
  266. package/test/utils/TestStorage.js +61 -0
  267. package/test/utils/TestStorage.js.map +1 -0
  268. package/test/utils/test_utils.d.ts +76 -0
  269. package/test/utils/test_utils.js +419 -0
  270. package/test/utils/test_utils.js.map +1 -0
@@ -16,9 +16,10 @@ const models = require("../icc-api/model/models");
16
16
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
17
17
  const SecureDelegation_1 = require("../icc-api/model/SecureDelegation");
18
18
  var AccessLevelEnum = SecureDelegation_1.SecureDelegation.AccessLevelEnum;
19
+ const utils_1 = require("./utils");
19
20
  class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
20
21
  get headers() {
21
- return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, 'Invoice'));
22
+ return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, utils_1.EntityWithDelegationTypeName.Invoice));
22
23
  }
23
24
  constructor(host, headers, crypto, entityrefApi, dataOwnerApi, autofillAuthor, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
24
25
  ? window.fetch
@@ -52,12 +53,12 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
52
53
  const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
53
54
  if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
54
55
  throw new Error('Can only initialise entities as current data owner.');
55
- const sfk = (_k = options.preferredSfk) !== null && _k !== void 0 ? _k : (yield this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: 'Patient' }));
56
+ const sfk = (_k = options.preferredSfk) !== null && _k !== void 0 ? _k : (yield this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: utils_1.EntityWithDelegationTypeName.Patient }));
56
57
  if (!sfk)
57
58
  throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
58
59
  const extraDelegations = Object.assign(Object.assign({}, Object.fromEntries([...((_m = (_l = user.autoDelegations) === null || _l === void 0 ? void 0 : _l.all) !== null && _m !== void 0 ? _m : []), ...((_p = (_o = user.autoDelegations) === null || _o === void 0 ? void 0 : _o.financialInformation) !== null && _p !== void 0 ? _p : [])].map((d) => [d, AccessLevelEnum.WRITE]))), ((_q = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _q !== void 0 ? _q : {}));
59
60
  return new models.Invoice(yield this.crypto.xapi
60
- .entityWithInitialisedEncryptedMetadata(invoice, 'Invoice', patient.id, sfk, true, false, extraDelegations)
61
+ .entityWithInitialisedEncryptedMetadata(invoice, utils_1.EntityWithDelegationTypeName.Invoice, patient.id, sfk, true, false, extraDelegations)
61
62
  .then((x) => x.updatedEntity));
62
63
  });
63
64
  }
@@ -120,7 +121,7 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
120
121
  */
121
122
  findBy(hcpartyId, patient, usingPost = false) {
122
123
  return __awaiter(this, void 0, void 0, function* () {
123
- const extractedKeys = yield this.crypto.xapi.secretIdsOf({ entity: patient, type: 'Patient' }, hcpartyId);
124
+ const extractedKeys = yield this.crypto.xapi.secretIdsOf({ entity: patient, type: utils_1.EntityWithDelegationTypeName.Patient }, hcpartyId);
124
125
  const topmostParentId = (yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0];
125
126
  let invoices = usingPost
126
127
  ? yield this.findInvoicesByHCPartyPatientForeignKeysUsingPost(hcpartyId, _.uniq(extractedKeys))
@@ -141,7 +142,7 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
141
142
  */
142
143
  decryptPatientIdOf(invoice) {
143
144
  return __awaiter(this, void 0, void 0, function* () {
144
- return this.crypto.xapi.owningEntityIdsOf({ entity: invoice, type: 'Invoice' }, undefined);
145
+ return this.crypto.xapi.owningEntityIdsOf({ entity: invoice, type: utils_1.EntityWithDelegationTypeName.Invoice }, undefined);
145
146
  });
146
147
  }
147
148
  /**
@@ -149,7 +150,7 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
149
150
  */
150
151
  hasWriteAccess(invoice) {
151
152
  return __awaiter(this, void 0, void 0, function* () {
152
- return this.crypto.xapi.hasWriteAccess({ entity: invoice, type: 'Invoice' });
153
+ return this.crypto.xapi.hasWriteAccess({ entity: invoice, type: utils_1.EntityWithDelegationTypeName.Invoice });
153
154
  });
154
155
  }
155
156
  /**
@@ -207,10 +208,10 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
207
208
  return __awaiter(this, void 0, void 0, function* () {
208
209
  const self = yield this.dataOwnerApi.getCurrentDataOwnerId();
209
210
  // All entities should have an encryption key.
210
- const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(invoice, 'Invoice');
211
+ const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(invoice, utils_1.EntityWithDelegationTypeName.Invoice);
211
212
  const updatedEntity = entityWithEncryptionKey ? yield this.modifyInvoice(entityWithEncryptionKey) : invoice;
212
213
  return this.crypto.xapi
213
- .simpleShareOrUpdateEncryptedEntityMetadata({ entity: updatedEntity, type: 'Invoice' }, true, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
214
+ .simpleShareOrUpdateEncryptedEntityMetadata({ entity: updatedEntity, type: utils_1.EntityWithDelegationTypeName.Invoice }, true, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
214
215
  delegateId,
215
216
  {
216
217
  requestedPermissions: options.requestedPermissions,
@@ -223,13 +224,13 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
223
224
  });
224
225
  }
225
226
  getDataOwnersWithAccessTo(entity) {
226
- return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: 'Invoice' });
227
+ return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: utils_1.EntityWithDelegationTypeName.Invoice });
227
228
  }
228
229
  getEncryptionKeysOf(entity) {
229
- return this.crypto.xapi.encryptionKeysOf({ entity, type: 'Invoice' }, undefined);
230
+ return this.crypto.xapi.encryptionKeysOf({ entity, type: utils_1.EntityWithDelegationTypeName.Invoice }, undefined);
230
231
  }
231
232
  createDelegationDeAnonymizationMetadata(entity, delegates) {
232
- return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: 'Invoice' }, delegates);
233
+ return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: utils_1.EntityWithDelegationTypeName.Invoice }, delegates);
233
234
  }
234
235
  }
235
236
  exports.IccInvoiceXApi = IccInvoiceXApi;
@@ -1 +1 @@
1
- {"version":3,"file":"icc-invoice-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-invoice-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA2D;AAG3D,4BAA2B;AAC3B,kDAAiD;AAGjD,0EAAgG;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C,0BAA0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,CAAA;IACzH,CAAC;CACF;AA3RD,wCA2RC","sourcesContent":["import { IccEntityrefApi, IccInvoiceApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { HealthElement, Invoice } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\n\nexport class IccInvoiceXApi extends IccInvoiceApi implements EncryptedEntityXApi<models.Invoice> {\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, 'Invoice'))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly entityrefApi: IccEntityrefApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly autofillAuthor: boolean,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n }\n\n /**\n * Creates a new instance of invoice with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this invoice refers to.\n * @param inv initialised data for the invoice. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the invoice. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * @return a new instance of invoice.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n inv: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n preferredSfk?: string\n } = {}\n ): Promise<models.Invoice> {\n const invoice = new models.Invoice({\n ...(inv ?? {}),\n _type: 'org.taktik.icure.entities.Invoice',\n id: inv?.id ?? this.crypto.primitives.randomUuid(),\n groupId: inv?.groupId ?? this.crypto.primitives.randomUuid(),\n created: inv?.created ?? new Date().getTime(),\n modified: inv?.modified ?? new Date().getTime(),\n responsible: inv?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: inv?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: inv?.codes ?? [],\n tags: inv?.tags ?? [],\n invoicingCodes: inv?.invoicingCodes ?? [],\n })\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk = options.preferredSfk ?? (await this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: 'Patient' }))\n if (!sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = {\n ...Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.financialInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n ),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Invoice(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(invoice, 'Invoice', patient.id, sfk, true, false, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n createInvoice(invoice: Invoice, prefix?: string): Promise<Invoice> {\n if (!prefix) {\n return super.createInvoice(invoice)\n }\n if (!invoice.id) {\n invoice.id = this.crypto.primitives.randomUuid()\n }\n return this.getNextInvoiceReference(prefix, this.entityrefApi)\n .then((reference) => this.createInvoiceReference(reference, invoice.id!, prefix, this.entityrefApi))\n .then((entityReference) => {\n if (!entityReference.id) {\n throw new Error('Cannot create invoice')\n }\n\n if (invoice.internshipNihii) {\n invoice.invoiceReference = entityReference.id.substring(prefix.length).replace('0', '1')\n } else {\n invoice.invoiceReference = entityReference.id.substring(prefix.length)\n }\n return super.createInvoice(invoice)\n })\n }\n\n getNextInvoiceReference(prefix: string, entityrefApi: IccEntityrefApi): Promise<number> {\n return entityrefApi.getLatest(prefix).then((entRef: models.EntityReference) => {\n if (!entRef || !entRef.id || !entRef.id!.startsWith(prefix)) return 1\n const sequenceNumber = entRef.id!.split(':').pop() || 0\n return Number(sequenceNumber) + 1\n })\n }\n\n createInvoiceReference(nextReference: number, docId: string, prefix: string, entityrefApi: IccEntityrefApi): Promise<models.EntityReference> {\n return entityrefApi\n .createEntityReference(\n new models.EntityReference({\n id: prefix + nextReference.toString().padStart(6, '0'),\n docId,\n })\n )\n .catch((err) => {\n console.log(err)\n return this.createInvoiceReference(nextReference + 1, docId, prefix, entityrefApi)\n })\n }\n\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all invoices with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the invoices of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param usingPost\n */\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false): Promise<Array<models.Invoice>> {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: 'Patient' }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n let invoices: Array<Invoice> = usingPost\n ? await this.findInvoicesByHCPartyPatientForeignKeysUsingPost(hcpartyId!, _.uniq(extractedKeys))\n : await this.findInvoicesByHCPartyPatientForeignKeys(hcpartyId!, _.uniq(extractedKeys).join(','))\n return await this.decrypt(hcpartyId, invoices)\n }\n\n encrypt(user: models.User, invoices: Array<models.Invoice>) {\n return Promise.resolve(invoices)\n }\n\n decrypt(hcpartyId: string, invoices: Array<models.Invoice>): Promise<Array<models.Invoice>> {\n return Promise.resolve(invoices)\n }\n\n /**\n * @param invoice a invoice\n * @return the id of the patient that the invoice refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(invoice: models.Invoice): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: invoice, type: 'Invoice' }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given invoice\n */\n async hasWriteAccess(invoice: models.Invoice): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: invoice, type: 'Invoice' })\n }\n\n /**\n * Share an existing invoice with other data owners, allowing them to access the non-encrypted data of the invoice and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the invoice.\n * @param invoice the invoice to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * invoice does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this invoice refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n invoice: models.Invoice,\n options: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Invoice> {\n return this.shareWithMany(invoice, { [delegateId]: options })\n }\n\n /**\n * Share an existing invoice with other data owners, allowing them to access the non-encrypted data of the invoice and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param invoice the invoice to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * invoice does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this invoice refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n invoice: models.Invoice,\n delegates: {\n [delegateId: string]: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Invoice> {\n return (await this.tryShareWithMany(invoice, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing invoice with other data owners, allowing them to access the non-encrypted data of the invoice and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param invoice the invoice to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * invoice does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this invoice refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async tryShareWithMany(\n invoice: models.Invoice,\n delegates: {\n [delegateId: string]: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Invoice>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(invoice, 'Invoice')\n const updatedEntity = entityWithEncryptionKey ? await this.modifyInvoice(entityWithEncryptionKey) : invoice\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n { entity: updatedEntity, type: 'Invoice' },\n true,\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: undefined,\n },\n ])\n ),\n (x) => this.bulkShareInvoices(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Invoice\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: 'Invoice' })\n }\n\n getEncryptionKeysOf(entity: models.Invoice): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: 'Invoice' }, undefined)\n }\n\n createDelegationDeAnonymizationMetadata(entity: models.Invoice, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: 'Invoice' }, delegates)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-invoice-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-invoice-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA2D;AAG3D,4BAA2B;AAC3B,kDAAiD;AAGjD,0EAAgG;AAChG,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAOzD,mCAAsD;AAEtD,MAAa,cAAe,SAAQ,uBAAa;IAC/C,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,OAAO,CAAC,CAAC,CAAA;IAC7I,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,YAA6B,EAC7B,YAA8B,EAC9B,cAAuB,EACxC,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;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EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CACjC;iBACA,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACvF,CAAC;KAAA;IAED,yBAAyB,CACvB,MAAsB;QAEtB,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,OAAO,EAAE,CAAC,CAAA;IACjI,CAAC;IAED,mBAAmB,CAAC,MAAsB;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;IAC7G,CAAC;IAED,uCAAuC,CAAC,MAAsB,EAAE,SAAmB;QACjF,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;IACpJ,CAAC;CACF;AA7RD,wCA6RC","sourcesContent":["import { IccEntityrefApi, IccInvoiceApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { HealthElement, Invoice } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { EntityWithDelegationTypeName } from './utils'\n\nexport class IccInvoiceXApi extends IccInvoiceApi implements EncryptedEntityXApi<models.Invoice> {\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Invoice))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly entityrefApi: IccEntityrefApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly autofillAuthor: boolean,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n }\n\n /**\n * Creates a new instance of invoice with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this invoice refers to.\n * @param inv initialised data for the invoice. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the invoice. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * @return a new instance of invoice.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient,\n inv: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n preferredSfk?: string\n } = {}\n ): Promise<models.Invoice> {\n const invoice = new models.Invoice({\n ...(inv ?? {}),\n _type: 'org.taktik.icure.entities.Invoice',\n id: inv?.id ?? this.crypto.primitives.randomUuid(),\n groupId: inv?.groupId ?? this.crypto.primitives.randomUuid(),\n created: inv?.created ?? new Date().getTime(),\n modified: inv?.modified ?? new Date().getTime(),\n responsible: inv?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: inv?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: inv?.codes ?? [],\n tags: inv?.tags ?? [],\n invoicingCodes: inv?.invoicingCodes ?? [],\n })\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk =\n options.preferredSfk ??\n (await this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: EntityWithDelegationTypeName.Patient }))\n if (!sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = {\n ...Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.financialInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n ),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Invoice(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(invoice, EntityWithDelegationTypeName.Invoice, patient.id, sfk, true, false, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n createInvoice(invoice: Invoice, prefix?: string): Promise<Invoice> {\n if (!prefix) {\n return super.createInvoice(invoice)\n }\n if (!invoice.id) {\n invoice.id = this.crypto.primitives.randomUuid()\n }\n return this.getNextInvoiceReference(prefix, this.entityrefApi)\n .then((reference) => this.createInvoiceReference(reference, invoice.id!, prefix, this.entityrefApi))\n .then((entityReference) => {\n if (!entityReference.id) {\n throw new Error('Cannot create invoice')\n }\n\n if (invoice.internshipNihii) {\n invoice.invoiceReference = entityReference.id.substring(prefix.length).replace('0', '1')\n } else {\n invoice.invoiceReference = entityReference.id.substring(prefix.length)\n }\n return super.createInvoice(invoice)\n })\n }\n\n getNextInvoiceReference(prefix: string, entityrefApi: IccEntityrefApi): Promise<number> {\n return entityrefApi.getLatest(prefix).then((entRef: models.EntityReference) => {\n if (!entRef || !entRef.id || !entRef.id!.startsWith(prefix)) return 1\n const sequenceNumber = entRef.id!.split(':').pop() || 0\n return Number(sequenceNumber) + 1\n })\n }\n\n createInvoiceReference(nextReference: number, docId: string, prefix: string, entityrefApi: IccEntityrefApi): Promise<models.EntityReference> {\n return entityrefApi\n .createEntityReference(\n new models.EntityReference({\n id: prefix + nextReference.toString().padStart(6, '0'),\n docId,\n })\n )\n .catch((err) => {\n console.log(err)\n return this.createInvoiceReference(nextReference + 1, docId, prefix, entityrefApi)\n })\n }\n\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all invoices with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the invoices of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param usingPost\n */\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false): Promise<Array<models.Invoice>> {\n const extractedKeys = await this.crypto.xapi.secretIdsOf({ entity: patient, type: EntityWithDelegationTypeName.Patient }, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n let invoices: Array<Invoice> = usingPost\n ? await this.findInvoicesByHCPartyPatientForeignKeysUsingPost(hcpartyId!, _.uniq(extractedKeys))\n : await this.findInvoicesByHCPartyPatientForeignKeys(hcpartyId!, _.uniq(extractedKeys).join(','))\n return await this.decrypt(hcpartyId, invoices)\n }\n\n encrypt(user: models.User, invoices: Array<models.Invoice>) {\n return Promise.resolve(invoices)\n }\n\n decrypt(hcpartyId: string, invoices: Array<models.Invoice>): Promise<Array<models.Invoice>> {\n return Promise.resolve(invoices)\n }\n\n /**\n * @param invoice a invoice\n * @return the id of the patient that the invoice refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(invoice: models.Invoice): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: invoice, type: EntityWithDelegationTypeName.Invoice }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given invoice\n */\n async hasWriteAccess(invoice: models.Invoice): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: invoice, type: EntityWithDelegationTypeName.Invoice })\n }\n\n /**\n * Share an existing invoice with other data owners, allowing them to access the non-encrypted data of the invoice and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the invoice.\n * @param invoice the invoice to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * invoice does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this invoice refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n invoice: models.Invoice,\n options: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Invoice> {\n return this.shareWithMany(invoice, { [delegateId]: options })\n }\n\n /**\n * Share an existing invoice with other data owners, allowing them to access the non-encrypted data of the invoice and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param invoice the invoice to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * invoice does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this invoice refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n invoice: models.Invoice,\n delegates: {\n [delegateId: string]: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Invoice> {\n return (await this.tryShareWithMany(invoice, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing invoice with other data owners, allowing them to access the non-encrypted data of the invoice and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param invoice the invoice to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * invoice does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this invoice refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async tryShareWithMany(\n invoice: models.Invoice,\n delegates: {\n [delegateId: string]: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Invoice>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(invoice, EntityWithDelegationTypeName.Invoice)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyInvoice(entityWithEncryptionKey) : invoice\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n { entity: updatedEntity, type: EntityWithDelegationTypeName.Invoice },\n true,\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: undefined,\n },\n ])\n ),\n (x) => this.bulkShareInvoices(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Invoice\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Invoice })\n }\n\n getEncryptionKeysOf(entity: models.Invoice): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Invoice }, undefined)\n }\n\n createDelegationDeAnonymizationMetadata(entity: models.Invoice, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Invoice }, delegates)\n }\n}\n"]}
@@ -22,7 +22,7 @@ const utils_1 = require("./utils");
22
22
  const Connection_1 = require("../icc-api/model/Connection");
23
23
  class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskApi {
24
24
  get headers() {
25
- return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, 'MaintenanceTask'));
25
+ return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, utils_1.EntityWithDelegationTypeName.MaintenanceTask));
26
26
  }
27
27
  constructor(host, headers, crypto, hcPartyApi, dataOwnerApi, userApi, authApi, autofillAuthor, encryptedKeys = [], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
28
28
  ? window.fetch
@@ -56,7 +56,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
56
56
  const maintenanceTask = Object.assign(Object.assign({}, (m !== null && m !== void 0 ? m : {})), { _type: 'org.taktik.icure.entities.MaintenanceTask', id: (_a = m === null || m === void 0 ? void 0 : m.id) !== null && _a !== void 0 ? _a : this.crypto.primitives.randomUuid(), created: (_b = m === null || m === void 0 ? void 0 : m.created) !== null && _b !== void 0 ? _b : new Date().getTime(), modified: (_c = m === null || m === void 0 ? void 0 : m.modified) !== null && _c !== void 0 ? _c : new Date().getTime(), responsible: (_d = m === null || m === void 0 ? void 0 : m.responsible) !== null && _d !== void 0 ? _d : (this.autofillAuthor ? dataOwnerId : undefined), author: (_e = m === null || m === void 0 ? void 0 : m.author) !== null && _e !== void 0 ? _e : (this.autofillAuthor ? user.id : undefined) });
57
57
  const extraDelegations = Object.assign(Object.assign({}, Object.fromEntries(((_g = (_f = user.autoDelegations) === null || _f === void 0 ? void 0 : _f.all) !== null && _g !== void 0 ? _g : []).map((d) => [d, AccessLevelEnum.WRITE]))), ((_h = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _h !== void 0 ? _h : {}));
58
58
  return new models.MaintenanceTask(yield this.crypto.xapi
59
- .entityWithInitialisedEncryptedMetadata(maintenanceTask, 'MaintenanceTask', undefined, undefined, true, false, extraDelegations)
59
+ .entityWithInitialisedEncryptedMetadata(maintenanceTask, utils_1.EntityWithDelegationTypeName.MaintenanceTask, undefined, undefined, true, false, extraDelegations)
60
60
  .then((x) => x.updatedEntity));
61
61
  });
62
62
  }
@@ -117,21 +117,21 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
117
117
  return this.encryptAs(dataOwnerId, maintenanceTasks);
118
118
  }
119
119
  encryptAs(dataOwner, maintenanceTasks) {
120
- return Promise.all(maintenanceTasks.map((m) => this.crypto.xapi.tryEncryptEntity(m, 'MaintenanceTask', this.encryptedFields, true, false, (x) => new models.MaintenanceTask(x))));
120
+ return Promise.all(maintenanceTasks.map((m) => this.crypto.xapi.tryEncryptEntity(m, utils_1.EntityWithDelegationTypeName.MaintenanceTask, this.encryptedFields, true, false, (x) => new models.MaintenanceTask(x))));
121
121
  }
122
122
  decrypt(user, maintenanceTasks) {
123
123
  const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user);
124
124
  return this.decryptAs(dataOwnerId, maintenanceTasks);
125
125
  }
126
126
  decryptAs(dataOwner, maintenanceTasks) {
127
- return Promise.all(maintenanceTasks.map((mT) => __awaiter(this, void 0, void 0, function* () { return this.crypto.xapi.decryptEntity(mT, 'MaintenanceTask', (x) => new models_1.MaintenanceTask(x)).then(({ entity }) => entity); })));
127
+ return Promise.all(maintenanceTasks.map((mT) => __awaiter(this, void 0, void 0, function* () { return this.crypto.xapi.decryptEntity(mT, utils_1.EntityWithDelegationTypeName.MaintenanceTask, (x) => new models_1.MaintenanceTask(x)).then(({ entity }) => entity); })));
128
128
  }
129
129
  /**
130
130
  * @return if the logged data owner has write access to the content of the given maintenance task
131
131
  */
132
132
  hasWriteAccess(maintenanceTask) {
133
133
  return __awaiter(this, void 0, void 0, function* () {
134
- return this.crypto.xapi.hasWriteAccess({ entity: maintenanceTask, type: 'MaintenanceTask' });
134
+ return this.crypto.xapi.hasWriteAccess({ entity: maintenanceTask, type: utils_1.EntityWithDelegationTypeName.MaintenanceTask });
135
135
  });
136
136
  }
137
137
  /**
@@ -183,10 +183,10 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
183
183
  return __awaiter(this, void 0, void 0, function* () {
184
184
  const self = yield this.dataOwnerApi.getCurrentDataOwnerId();
185
185
  // All entities should have an encryption key.
186
- const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(maintenanceTask, 'MaintenanceTask');
186
+ const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(maintenanceTask, utils_1.EntityWithDelegationTypeName.MaintenanceTask);
187
187
  const updatedEntity = entityWithEncryptionKey ? yield this.modifyMaintenanceTaskAs(self, entityWithEncryptionKey) : maintenanceTask;
188
188
  return this.crypto.xapi
189
- .simpleShareOrUpdateEncryptedEntityMetadata({ entity: updatedEntity, type: 'MaintenanceTask' }, true, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
189
+ .simpleShareOrUpdateEncryptedEntityMetadata({ entity: updatedEntity, type: utils_1.EntityWithDelegationTypeName.MaintenanceTask }, true, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
190
190
  delegateId,
191
191
  {
192
192
  requestedPermissions: options.requestedPermissions,
@@ -199,19 +199,19 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
199
199
  });
200
200
  }
201
201
  getDataOwnersWithAccessTo(entity) {
202
- return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: 'MaintenanceTask' });
202
+ return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: utils_1.EntityWithDelegationTypeName.MaintenanceTask });
203
203
  }
204
204
  getEncryptionKeysOf(entity) {
205
- return this.crypto.xapi.encryptionKeysOf({ entity, type: 'MaintenanceTask' }, undefined);
205
+ return this.crypto.xapi.encryptionKeysOf({ entity, type: utils_1.EntityWithDelegationTypeName.MaintenanceTask }, undefined);
206
206
  }
207
207
  subscribeToMaintenanceTaskEvents(eventTypes, filter, eventFired, options = {}) {
208
208
  return __awaiter(this, void 0, void 0, function* () {
209
209
  const currentUser = yield this.userApi.getCurrentUser();
210
- return (0, utils_1.subscribeToEntityEvents)(this.host, this.authApi, 'MaintenanceTask', eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt(currentUser, [encrypted]))[0]; })).then((rs) => new Connection_1.ConnectionImpl(rs));
210
+ return (0, utils_1.subscribeToEntityEvents)(this.host, this.authApi, utils_1.EntityWithDelegationTypeName.MaintenanceTask, eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt(currentUser, [encrypted]))[0]; })).then((rs) => new Connection_1.ConnectionImpl(rs));
211
211
  });
212
212
  }
213
213
  createDelegationDeAnonymizationMetadata(entity, delegates) {
214
- return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: 'MaintenanceTask' }, delegates);
214
+ return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: utils_1.EntityWithDelegationTypeName.MaintenanceTask }, delegates);
215
215
  }
216
216
  }
217
217
  exports.IccMaintenanceTaskXApi = IccMaintenanceTaskXApi;
@@ -1 +1 @@
1
- {"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gFAA4E;AAE5E,kDAAiD;AACjD,4BAA2B;AAE3B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AAE,SAAS,CAAC,CAAA;IAC1F,CAAC;IAEK,gCAAgC,CACpC,UAA8C,EAC9C,MAAuC,EACvC,UAA0D,EAC1D,UAA+B,EAAE;;YAEjC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAA;YAEvD,OAAO,IAAA,+BAAuB,EAC5B,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,OAAO,EACZ,iBAAiB,EACjB,UAAU,EACV,MAAM,EACN,UAAU,EACV,OAAO,EACP,CAAO,SAAS,EAAE,EAAE,gDAAC,OAAA,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,GAAA,CACvE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;KAAA;IAED,uCAAuC,CAAC,MAAuB,EAAE,SAAmB;QAClF,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,SAAS,CAAC,CAAA;IACjI,CAAC;CACF;AAvSD,wDAuSC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { DocIdentifier, ListOfIds, MaintenanceTask } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedFieldsManifest, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { IccAuthApi } from '../icc-api'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { AbstractFilter } from './filters/filters'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { IccUserXApi } from './icc-user-x-api'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi implements EncryptedEntityXApi<models.MaintenanceTask> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, 'MaintenanceTask'))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly hcPartyApi: IccHcpartyXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly userApi: IccUserXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n encryptedKeys: Array<string> = [],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'MaintenanceTask.')\n }\n\n /**\n * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param m initialised data for the maintenance task. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * @return a new instance of maintenance task.\n */\n async newInstance(\n user: models.User,\n m: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const maintenanceTask = {\n ...(m ?? {}),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n id: m?.id ?? this.crypto.primitives.randomUuid(),\n created: m?.created ?? new Date().getTime(),\n modified: m?.modified ?? new Date().getTime(),\n responsible: m?.responsible ?? (this.autofillAuthor ? dataOwnerId : undefined),\n author: m?.author ?? (this.autofillAuthor ? user.id : undefined),\n }\n\n const extraDelegations = {\n ...Object.fromEntries((user.autoDelegations?.all ?? []).map((d) => [d, AccessLevelEnum.WRITE])),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.MaintenanceTask(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(maintenanceTask, 'MaintenanceTask', undefined, undefined, true, false, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<DocIdentifier> | never {\n return super.deleteMaintenanceTask(maintenanceTaskId)\n }\n\n deleteMaintenanceTasks(_maintenanceTaskIds: ListOfIds): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTasksWithUser(user: models.User, maintenanceTaskIds: ListOfIds): Promise<Array<DocIdentifier>> | never {\n return super.deleteMaintenanceTasks(maintenanceTaskIds)\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body ? this.modifyMaintenanceTaskAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n\n private modifyMaintenanceTaskAs(dataOwner: string, body: models.MaintenanceTask): Promise<models.MaintenanceTask> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decryptAs(dataOwner, [mt]))\n .then((mts) => mts[0])\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n return this.encryptAs(dataOwnerId, maintenanceTasks)\n }\n\n private encryptAs(dataOwner: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map((m) =>\n this.crypto.xapi.tryEncryptEntity(m, 'MaintenanceTask', this.encryptedFields, true, false, (x) => new models.MaintenanceTask(x))\n )\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n return this.decryptAs(dataOwnerId, maintenanceTasks)\n }\n\n private decryptAs(dataOwner: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map(async (mT) =>\n this.crypto.xapi.decryptEntity(mT, 'MaintenanceTask', (x) => new MaintenanceTask(x)).then(({ entity }) => entity)\n )\n )\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given maintenance task\n */\n async hasWriteAccess(maintenanceTask: models.MaintenanceTask): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: maintenanceTask, type: 'MaintenanceTask' })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the maintenance task.\n * @param maintenanceTask the maintenance task to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n maintenanceTask: models.MaintenanceTask,\n options: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.MaintenanceTask> {\n return this.shareWithMany(maintenanceTask, { [delegateId]: options })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity.\n */\n async shareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.MaintenanceTask> {\n return (await this.tryShareWithMany(maintenanceTask, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async tryShareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.MaintenanceTask>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(maintenanceTask, 'MaintenanceTask')\n const updatedEntity = entityWithEncryptionKey ? await this.modifyMaintenanceTaskAs(self, entityWithEncryptionKey) : maintenanceTask\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n { entity: updatedEntity, type: 'MaintenanceTask' },\n true,\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: ShareMetadataBehaviour.NEVER,\n shareSecretIds: undefined,\n },\n ])\n ),\n (x) => this.bulkShareMaintenanceTask(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decryptAs(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.MaintenanceTask\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: 'MaintenanceTask' })\n }\n\n getEncryptionKeysOf(entity: models.MaintenanceTask): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: 'MaintenanceTask' }, undefined)\n }\n\n async subscribeToMaintenanceTaskEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<MaintenanceTask>,\n eventFired: (dataSample: MaintenanceTask) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n const currentUser = await this.userApi.getCurrentUser()\n\n return subscribeToEntityEvents(\n this.host,\n this.authApi,\n 'MaintenanceTask',\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt(currentUser, [encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: MaintenanceTask, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: 'MaintenanceTask' }, delegates)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gFAA4E;AAE5E,kDAAiD;AACjD,4BAA2B;AAE3B,oDAAmF;AAEnF,0EAAgG;AAChG,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AACzD,4EAAwE;AAKxE,mCAAmJ;AAInJ,4DAAwE;AAGxE,MAAa,sBAAuB,SAAQ,6CAAqB;IAG/D,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAC9B,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,eAAe,CAAC,CAClH,CAAA;IACH,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,UAA0B,EAC1B,YAA8B,EAC9B,OAAoB,EACpB,OAAmB,EACnB,cAAuB,EACxC,gBAA+B,EAAE,EACjC,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAdtC,WAAM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,EAAE,IAAI,EAAE,oCAA4B,CAAC,eAAe,EAAE,EAC9D,SAAS,CACV,CAAA;IACH,CAAC;CACF;AA9TD,wDA8TC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { DocIdentifier, ListOfIds, MaintenanceTask } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { IccAuthApi } from '../icc-api'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { AbstractFilter } from './filters/filters'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { IccUserXApi } from './icc-user-x-api'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi implements EncryptedEntityXApi<models.MaintenanceTask> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) =>\n this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.MaintenanceTask)\n )\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly hcPartyApi: IccHcpartyXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly userApi: IccUserXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n encryptedKeys: Array<string> = [],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'MaintenanceTask.')\n }\n\n /**\n * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param m initialised data for the maintenance task. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * @return a new instance of maintenance task.\n */\n async newInstance(\n user: models.User,\n m: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const maintenanceTask = {\n ...(m ?? {}),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n id: m?.id ?? this.crypto.primitives.randomUuid(),\n created: m?.created ?? new Date().getTime(),\n modified: m?.modified ?? new Date().getTime(),\n responsible: m?.responsible ?? (this.autofillAuthor ? dataOwnerId : undefined),\n author: m?.author ?? (this.autofillAuthor ? user.id : undefined),\n }\n\n const extraDelegations = {\n ...Object.fromEntries((user.autoDelegations?.all ?? []).map((d) => [d, AccessLevelEnum.WRITE])),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.MaintenanceTask(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n maintenanceTask,\n EntityWithDelegationTypeName.MaintenanceTask,\n undefined,\n undefined,\n true,\n false,\n extraDelegations\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<DocIdentifier> | never {\n return super.deleteMaintenanceTask(maintenanceTaskId)\n }\n\n deleteMaintenanceTasks(_maintenanceTaskIds: ListOfIds): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTasksWithUser(user: models.User, maintenanceTaskIds: ListOfIds): Promise<Array<DocIdentifier>> | never {\n return super.deleteMaintenanceTasks(maintenanceTaskIds)\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body ? this.modifyMaintenanceTaskAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n\n private modifyMaintenanceTaskAs(dataOwner: string, body: models.MaintenanceTask): Promise<models.MaintenanceTask> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decryptAs(dataOwner, [mt]))\n .then((mts) => mts[0])\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n return this.encryptAs(dataOwnerId, maintenanceTasks)\n }\n\n private encryptAs(dataOwner: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map((m) =>\n this.crypto.xapi.tryEncryptEntity(\n m,\n EntityWithDelegationTypeName.MaintenanceTask,\n this.encryptedFields,\n true,\n false,\n (x) => new models.MaintenanceTask(x)\n )\n )\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n return this.decryptAs(dataOwnerId, maintenanceTasks)\n }\n\n private decryptAs(dataOwner: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map(async (mT) =>\n this.crypto.xapi.decryptEntity(mT, EntityWithDelegationTypeName.MaintenanceTask, (x) => new MaintenanceTask(x)).then(({ entity }) => entity)\n )\n )\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given maintenance task\n */\n async hasWriteAccess(maintenanceTask: models.MaintenanceTask): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: maintenanceTask, type: EntityWithDelegationTypeName.MaintenanceTask })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the maintenance task.\n * @param maintenanceTask the maintenance task to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n maintenanceTask: models.MaintenanceTask,\n options: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.MaintenanceTask> {\n return this.shareWithMany(maintenanceTask, { [delegateId]: options })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity.\n */\n async shareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.MaintenanceTask> {\n return (await this.tryShareWithMany(maintenanceTask, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async tryShareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.MaintenanceTask>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(\n maintenanceTask,\n EntityWithDelegationTypeName.MaintenanceTask\n )\n const updatedEntity = entityWithEncryptionKey ? await this.modifyMaintenanceTaskAs(self, entityWithEncryptionKey) : maintenanceTask\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n { entity: updatedEntity, type: EntityWithDelegationTypeName.MaintenanceTask },\n true,\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: ShareMetadataBehaviour.NEVER,\n shareSecretIds: undefined,\n },\n ])\n ),\n (x) => this.bulkShareMaintenanceTask(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decryptAs(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.MaintenanceTask\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.MaintenanceTask })\n }\n\n getEncryptionKeysOf(entity: models.MaintenanceTask): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.MaintenanceTask }, undefined)\n }\n\n async subscribeToMaintenanceTaskEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<MaintenanceTask>,\n eventFired: (dataSample: MaintenanceTask) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n const currentUser = await this.userApi.getCurrentUser()\n\n return subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.MaintenanceTask,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt(currentUser, [encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: MaintenanceTask, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.MaintenanceTask },\n delegates\n )\n }\n}\n"]}
@@ -19,7 +19,7 @@ const utils_1 = require("./utils");
19
19
  const Connection_1 = require("../icc-api/model/Connection");
20
20
  class IccMessageXApi extends icc_api_1.IccMessageApi {
21
21
  get headers() {
22
- return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, 'Message'));
22
+ return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, utils_1.EntityWithDelegationTypeName.Message));
23
23
  }
24
24
  constructor(host, headers, crypto, dataOwnerApi, authApi, autofillAuthor, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), encryptedKeys = [], fetchImpl = typeof window !== 'undefined'
25
25
  ? window.fetch
@@ -61,21 +61,21 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
61
61
  if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
62
62
  throw new Error('Can only initialise entities as current data owner.');
63
63
  const sfk = patient
64
- ? (_h = options.preferredSfk) !== null && _h !== void 0 ? _h : (yield this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: 'Patient' }))
64
+ ? (_h = options.preferredSfk) !== null && _h !== void 0 ? _h : (yield this.crypto.confidential.getAnySecretIdSharedWithParents({ entity: patient, type: utils_1.EntityWithDelegationTypeName.Patient }))
65
65
  : undefined;
66
66
  if (patient && !sfk)
67
67
  throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
68
68
  const extraDelegations = Object.assign(Object.assign({}, Object.fromEntries([...((_k = (_j = user.autoDelegations) === null || _j === void 0 ? void 0 : _j.all) !== null && _k !== void 0 ? _k : []), ...((_m = (_l = user.autoDelegations) === null || _l === void 0 ? void 0 : _l.medicalInformation) !== null && _m !== void 0 ? _m : [])].map((d) => [d, AccessLevelEnum.WRITE]))), ((_o = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _o !== void 0 ? _o : {}));
69
69
  return new models.Message(yield this.crypto.xapi
70
- .entityWithInitialisedEncryptedMetadata(message, 'Message', patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, true, extraDelegations)
70
+ .entityWithInitialisedEncryptedMetadata(message, utils_1.EntityWithDelegationTypeName.Message, patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, true, extraDelegations)
71
71
  .then((x) => x.updatedEntity));
72
72
  });
73
73
  }
74
74
  decrypt(messages) {
75
- return Promise.all(messages.map((message) => this.crypto.xapi.decryptEntity(message, 'Message', (x) => new models.Message(x))));
75
+ return Promise.all(messages.map((message) => this.crypto.xapi.decryptEntity(message, utils_1.EntityWithDelegationTypeName.Message, (x) => new models.Message(x))));
76
76
  }
77
77
  encrypt(messages) {
78
- return Promise.all(messages.map((p) => this.crypto.xapi.tryEncryptEntity(p, 'Message', this.encryptedFields, true, false, (x) => new models.Message(x))));
78
+ return Promise.all(messages.map((p) => this.crypto.xapi.tryEncryptEntity(p, utils_1.EntityWithDelegationTypeName.Message, this.encryptedFields, true, false, (x) => new models.Message(x))));
79
79
  }
80
80
  /**
81
81
  * @param message a message
@@ -84,7 +84,7 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
84
84
  */
85
85
  decryptPatientIdOf(message) {
86
86
  return __awaiter(this, void 0, void 0, function* () {
87
- return this.crypto.xapi.owningEntityIdsOf({ entity: message, type: 'Message' }, undefined);
87
+ return this.crypto.xapi.owningEntityIdsOf({ entity: message, type: utils_1.EntityWithDelegationTypeName.Message }, undefined);
88
88
  });
89
89
  }
90
90
  /**
@@ -92,7 +92,7 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
92
92
  */
93
93
  hasWriteAccess(message) {
94
94
  return __awaiter(this, void 0, void 0, function* () {
95
- return this.crypto.xapi.hasWriteAccess({ entity: message, type: 'Message' });
95
+ return this.crypto.xapi.hasWriteAccess({ entity: message, type: utils_1.EntityWithDelegationTypeName.Message });
96
96
  });
97
97
  }
98
98
  /**
@@ -155,9 +155,9 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
155
155
  tryShareWithMany(message, delegates) {
156
156
  return __awaiter(this, void 0, void 0, function* () {
157
157
  // All entities should have an encryption key.
158
- const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(message, 'Message');
158
+ const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(message, utils_1.EntityWithDelegationTypeName.Message);
159
159
  const updatedEntity = entityWithEncryptionKey ? yield this.modifyMessage(entityWithEncryptionKey) : message;
160
- return this.crypto.xapi.simpleShareOrUpdateEncryptedEntityMetadata({ entity: updatedEntity, type: 'Message' }, false, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
160
+ return this.crypto.xapi.simpleShareOrUpdateEncryptedEntityMetadata({ entity: updatedEntity, type: utils_1.EntityWithDelegationTypeName.Message }, false, Object.fromEntries(Object.entries(delegates).map(([delegateId, options]) => [
161
161
  delegateId,
162
162
  {
163
163
  requestedPermissions: options.requestedPermissions,
@@ -174,13 +174,13 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
174
174
  * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.
175
175
  */
176
176
  decryptSecretIdsOf(message) {
177
- return this.crypto.xapi.secretIdsOf({ entity: message, type: 'Message' }, undefined);
177
+ return this.crypto.xapi.secretIdsOf({ entity: message, type: utils_1.EntityWithDelegationTypeName.Message }, undefined);
178
178
  }
179
179
  getDataOwnersWithAccessTo(entity) {
180
- return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: 'Message' });
180
+ return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: utils_1.EntityWithDelegationTypeName.Message });
181
181
  }
182
182
  getEncryptionKeysOf(entity) {
183
- return this.crypto.xapi.encryptionKeysOf({ entity, type: 'Message' }, undefined);
183
+ return this.crypto.xapi.encryptionKeysOf({ entity, type: utils_1.EntityWithDelegationTypeName.Message }, undefined);
184
184
  }
185
185
  filterMessagesBy(body, startDocumentId, limit) {
186
186
  const _super = Object.create(null, {
@@ -227,11 +227,11 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
227
227
  }
228
228
  subscribeToMessageEvents(eventTypes, filter, eventFired, options = {}) {
229
229
  return __awaiter(this, void 0, void 0, function* () {
230
- return yield (0, utils_1.subscribeToEntityEvents)(this.host, this.authApi, 'Message', eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt([encrypted]))[0].entity; })).then((rs) => new Connection_1.ConnectionImpl(rs));
230
+ return yield (0, utils_1.subscribeToEntityEvents)(this.host, this.authApi, utils_1.EntityWithDelegationTypeName.Message, eventTypes, filter, eventFired, options, (encrypted) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt([encrypted]))[0].entity; })).then((rs) => new Connection_1.ConnectionImpl(rs));
231
231
  });
232
232
  }
233
233
  createDelegationDeAnonymizationMetadata(entity, delegates) {
234
- return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: 'Message' }, delegates);
234
+ return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: utils_1.EntityWithDelegationTypeName.Message }, delegates);
235
235
  }
236
236
  }
237
237
  exports.IccMessageXApi = IccMessageXApi;