@icure/api 8.6.18 → 8.7.0

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 (328) hide show
  1. package/icc-api/api/IccDocumentApi.d.ts +10 -2
  2. package/icc-api/api/IccDocumentApi.js +22 -4
  3. package/icc-api/api/IccDocumentApi.js.map +1 -1
  4. package/icc-api/api/IccReceiptApi.d.ts +17 -0
  5. package/icc-api/api/IccReceiptApi.js +52 -0
  6. package/icc-api/api/IccReceiptApi.js.map +1 -1
  7. package/icc-api/model/DataAttachment.d.ts +22 -0
  8. package/icc-api/model/DataAttachment.js.map +1 -1
  9. package/icc-api/model/Document.d.ts +6 -0
  10. package/icc-api/model/Document.js.map +1 -1
  11. package/icc-api/model/Receipt.d.ts +6 -0
  12. package/icc-api/model/Receipt.js.map +1 -1
  13. package/icc-x-api/crypto/BaseExchangeDataManager.js +2 -2
  14. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
  15. package/icc-x-api/crypto/ExchangeDataManager.js +3 -3
  16. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  17. package/icc-x-api/crypto/ExtendedApisUtils.d.ts +1 -1
  18. package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -1
  19. package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +1 -1
  20. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +8 -2
  21. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
  22. package/icc-x-api/crypto/RecoveryDataEncryption.js.map +1 -1
  23. package/icc-x-api/icc-accesslog-x-api.js +7 -7
  24. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  25. package/icc-x-api/icc-calendar-item-x-api.js +7 -7
  26. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  27. package/icc-x-api/icc-classification-x-api.js +4 -5
  28. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  29. package/icc-x-api/icc-code-x-api.d.ts +2 -2
  30. package/icc-x-api/icc-code-x-api.js +3 -33
  31. package/icc-x-api/icc-code-x-api.js.map +1 -1
  32. package/icc-x-api/icc-contact-x-api.js +20 -33
  33. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  34. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  35. package/icc-x-api/icc-document-x-api.d.ts +8 -7
  36. package/icc-x-api/icc-document-x-api.js +64 -22
  37. package/icc-x-api/icc-document-x-api.js.map +1 -1
  38. package/icc-x-api/icc-form-x-api.js +3 -4
  39. package/icc-x-api/icc-form-x-api.js.map +1 -1
  40. package/icc-x-api/icc-helement-x-api.js +11 -11
  41. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  42. package/icc-x-api/icc-invoice-x-api.js +3 -4
  43. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  44. package/icc-x-api/icc-maintenance-task-x-api.js +3 -3
  45. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  46. package/icc-x-api/icc-patient-x-api.js +29 -29
  47. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  48. package/icc-x-api/icc-receipt-x-api.d.ts +40 -0
  49. package/icc-x-api/icc-receipt-x-api.js +79 -1
  50. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  51. package/icc-x-api/icc-topic-x-api.js.map +1 -1
  52. package/icc-x-api/index.js +1 -1
  53. package/icc-x-api/index.js.map +1 -1
  54. package/icc-x-api/utils/code-util.d.ts +23 -0
  55. package/icc-x-api/utils/code-util.js +39 -2
  56. package/icc-x-api/utils/code-util.js.map +1 -1
  57. package/icc-x-api/utils/collection-utils.d.ts +13 -0
  58. package/icc-x-api/utils/collection-utils.js +69 -0
  59. package/icc-x-api/utils/collection-utils.js.map +1 -1
  60. package/icc-x-api/utils/compression-utils.d.ts +28 -0
  61. package/icc-x-api/utils/compression-utils.js +106 -0
  62. package/icc-x-api/utils/compression-utils.js.map +1 -0
  63. package/icc-x-api/utils/crypto-utils.js +7 -7
  64. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  65. package/icc-x-api/utils/formatting-util.d.ts +1 -3
  66. package/icc-x-api/utils/formatting-util.js +15 -17
  67. package/icc-x-api/utils/formatting-util.js.map +1 -1
  68. package/icc-x-api/utils/hcp-util.js +2 -3
  69. package/icc-x-api/utils/hcp-util.js.map +1 -1
  70. package/icc-x-api/utils/insurability-util.js +10 -8
  71. package/icc-x-api/utils/insurability-util.js.map +1 -1
  72. package/icc-x-api/utils/lzma-wasm.d.ts +6 -0
  73. package/icc-x-api/utils/lzma-wasm.js +81 -0
  74. package/icc-x-api/utils/lzma-wasm.js.map +1 -0
  75. package/icc-x-api/utils/mutex.d.ts +12 -0
  76. package/icc-x-api/utils/mutex.js +26 -0
  77. package/icc-x-api/utils/mutex.js.map +1 -0
  78. package/icc-x-api/utils/websocket.js +7 -7
  79. package/icc-x-api/utils/websocket.js.map +1 -1
  80. package/icc-x-api/wasm/lzma/lzma.js +2 -0
  81. package/icc-x-api/wasm/lzma/lzma.wasm +0 -0
  82. package/package.json +2 -11
  83. package/icc-x-api/utils/uuid-encoder.d.ts +0 -44
  84. package/icc-x-api/utils/uuid-encoder.js +0 -114
  85. package/icc-x-api/utils/uuid-encoder.js.map +0 -1
  86. package/test/icc-api/api/IccAgendaApi.d.ts +0 -1
  87. package/test/icc-api/api/IccAgendaApi.js +0 -64
  88. package/test/icc-api/api/IccAgendaApi.js.map +0 -1
  89. package/test/icc-api/api/IccAnonymousAccessApi.d.ts +0 -1
  90. package/test/icc-api/api/IccAnonymousAccessApi.js +0 -58
  91. package/test/icc-api/api/IccAnonymousAccessApi.js.map +0 -1
  92. package/test/icc-api/api/IccCalendarItemApi.d.ts +0 -1
  93. package/test/icc-api/api/IccCalendarItemApi.js +0 -67
  94. package/test/icc-api/api/IccCalendarItemApi.js.map +0 -1
  95. package/test/icc-api/api/IccCalendarItemTypeApi.d.ts +0 -1
  96. package/test/icc-api/api/IccCalendarItemTypeApi.js +0 -96
  97. package/test/icc-api/api/IccCalendarItemTypeApi.js.map +0 -1
  98. package/test/icc-api/api/IccCodeApi.d.ts +0 -1
  99. package/test/icc-api/api/IccCodeApi.js +0 -38
  100. package/test/icc-api/api/IccCodeApi.js.map +0 -1
  101. package/test/icc-api/api/IccDocumentApi.d.ts +0 -1
  102. package/test/icc-api/api/IccDocumentApi.js +0 -199
  103. package/test/icc-api/api/IccDocumentApi.js.map +0 -1
  104. package/test/icc-api/api/IccGroupApi.d.ts +0 -1
  105. package/test/icc-api/api/IccGroupApi.js +0 -50
  106. package/test/icc-api/api/IccGroupApi.js.map +0 -1
  107. package/test/icc-api/api/IccKeywordApi.d.ts +0 -1
  108. package/test/icc-api/api/IccKeywordApi.js +0 -64
  109. package/test/icc-api/api/IccKeywordApi.js.map +0 -1
  110. package/test/icc-api/api/IccMedicalLocationApi.d.ts +0 -1
  111. package/test/icc-api/api/IccMedicalLocationApi.js +0 -64
  112. package/test/icc-api/api/IccMedicalLocationApi.js.map +0 -1
  113. package/test/icc-api/api/IccPlaceApi.d.ts +0 -1
  114. package/test/icc-api/api/IccPlaceApi.js +0 -64
  115. package/test/icc-api/api/IccPlaceApi.js.map +0 -1
  116. package/test/icc-api/api/IccRecoveryDataApi.d.ts +0 -1
  117. package/test/icc-api/api/IccRecoveryDataApi.js +0 -95
  118. package/test/icc-api/api/IccRecoveryDataApi.js.map +0 -1
  119. package/test/icc-api/api/IccRoleApi.d.ts +0 -1
  120. package/test/icc-api/api/IccRoleApi.js +0 -34
  121. package/test/icc-api/api/IccRoleApi.js.map +0 -1
  122. package/test/icc-api/api/IccUserApi.d.ts +0 -1
  123. package/test/icc-api/api/IccUserApi.js +0 -96
  124. package/test/icc-api/api/IccUserApi.js.map +0 -1
  125. package/test/icc-api/e2e/IccCalendarItemApi.d.ts +0 -1
  126. package/test/icc-api/e2e/IccCalendarItemApi.js +0 -46
  127. package/test/icc-api/e2e/IccCalendarItemApi.js.map +0 -1
  128. package/test/icc-api/model/modelHelpersTest.d.ts +0 -1
  129. package/test/icc-api/model/modelHelpersTest.js +0 -45
  130. package/test/icc-api/model/modelHelpersTest.js.map +0 -1
  131. package/test/icc-x-api/auth/group-switch-test.d.ts +0 -1
  132. package/test/icc-x-api/auth/group-switch-test.js +0 -81
  133. package/test/icc-x-api/auth/group-switch-test.js.map +0 -1
  134. package/test/icc-x-api/auth/jwt-concurrency-test.d.ts +0 -2
  135. package/test/icc-x-api/auth/jwt-concurrency-test.js +0 -112
  136. package/test/icc-x-api/auth/jwt-concurrency-test.js.map +0 -1
  137. package/test/icc-x-api/auth/jwt-provider-test.d.ts +0 -1
  138. package/test/icc-x-api/auth/jwt-provider-test.js +0 -197
  139. package/test/icc-x-api/auth/jwt-provider-test.js.map +0 -1
  140. package/test/icc-x-api/auth/smart-auth-provider-test.d.ts +0 -1
  141. package/test/icc-x-api/auth/smart-auth-provider-test.js +0 -224
  142. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +0 -1
  143. package/test/icc-x-api/autofix-anonymity-test.d.ts +0 -1
  144. package/test/icc-x-api/autofix-anonymity-test.js +0 -122
  145. package/test/icc-x-api/autofix-anonymity-test.js.map +0 -1
  146. package/test/icc-x-api/confidential-entities-test.d.ts +0 -1
  147. package/test/icc-x-api/confidential-entities-test.js +0 -168
  148. package/test/icc-x-api/confidential-entities-test.js.map +0 -1
  149. package/test/icc-x-api/crud/comprehensive-crud-test.d.ts +0 -1
  150. package/test/icc-x-api/crud/comprehensive-crud-test.js +0 -276
  151. package/test/icc-x-api/crud/comprehensive-crud-test.js.map +0 -1
  152. package/test/icc-x-api/crud/entities-crud-test-interface.d.ts +0 -16
  153. package/test/icc-x-api/crud/entities-crud-test-interface.js +0 -408
  154. package/test/icc-x-api/crud/entities-crud-test-interface.js.map +0 -1
  155. package/test/icc-x-api/crypto/anonymous-delegations-test.d.ts +0 -1
  156. package/test/icc-x-api/crypto/anonymous-delegations-test.js +0 -587
  157. package/test/icc-x-api/crypto/anonymous-delegations-test.js.map +0 -1
  158. package/test/icc-x-api/crypto/concurrency.d.ts +0 -1
  159. package/test/icc-x-api/crypto/concurrency.js +0 -35
  160. package/test/icc-x-api/crypto/concurrency.js.map +0 -1
  161. package/test/icc-x-api/crypto/crypto-utils.d.ts +0 -1
  162. package/test/icc-x-api/crypto/crypto-utils.js +0 -79
  163. package/test/icc-x-api/crypto/crypto-utils.js.map +0 -1
  164. package/test/icc-x-api/crypto/cryptoTest.d.ts +0 -2
  165. package/test/icc-x-api/crypto/cryptoTest.js +0 -402
  166. package/test/icc-x-api/crypto/cryptoTest.js.map +0 -1
  167. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.d.ts +0 -1
  168. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js +0 -166
  169. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js.map +0 -1
  170. package/test/icc-x-api/crypto/exchange-data-manager-test.d.ts +0 -1
  171. package/test/icc-x-api/crypto/exchange-data-manager-test.js +0 -674
  172. package/test/icc-x-api/crypto/exchange-data-manager-test.js.map +0 -1
  173. package/test/icc-x-api/crypto/full-crypto-test.d.ts +0 -1
  174. package/test/icc-x-api/crypto/full-crypto-test.js +0 -454
  175. package/test/icc-x-api/crypto/full-crypto-test.js.map +0 -1
  176. package/test/icc-x-api/crypto/legacy-metadata-migration-test.d.ts +0 -1
  177. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js +0 -379
  178. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js.map +0 -1
  179. package/test/icc-x-api/crypto/secure-delegations-manager-test.d.ts +0 -1
  180. package/test/icc-x-api/crypto/secure-delegations-manager-test.js +0 -278
  181. package/test/icc-x-api/crypto/secure-delegations-manager-test.js.map +0 -1
  182. package/test/icc-x-api/crypto/shamir.d.ts +0 -2
  183. package/test/icc-x-api/crypto/shamir.js +0 -167
  184. package/test/icc-x-api/crypto/shamir.js.map +0 -1
  185. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.d.ts +0 -1
  186. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js +0 -71
  187. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +0 -1
  188. package/test/icc-x-api/crypto/soft-deleted-data-owners.d.ts +0 -2
  189. package/test/icc-x-api/crypto/soft-deleted-data-owners.js +0 -113
  190. package/test/icc-x-api/crypto/soft-deleted-data-owners.js.map +0 -1
  191. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.d.ts +0 -1
  192. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js +0 -246
  193. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js.map +0 -1
  194. package/test/icc-x-api/entity-with-attachments-api-test.d.ts +0 -1
  195. package/test/icc-x-api/entity-with-attachments-api-test.js +0 -142
  196. package/test/icc-x-api/entity-with-attachments-api-test.js.map +0 -1
  197. package/test/icc-x-api/filters/filters.d.ts +0 -1
  198. package/test/icc-x-api/filters/filters.js +0 -49
  199. package/test/icc-x-api/filters/filters.js.map +0 -1
  200. package/test/icc-x-api/filters/healthelement.d.ts +0 -1
  201. package/test/icc-x-api/filters/healthelement.js +0 -333
  202. package/test/icc-x-api/filters/healthelement.js.map +0 -1
  203. package/test/icc-x-api/icc-accesslog-x-api.d.ts +0 -1
  204. package/test/icc-x-api/icc-accesslog-x-api.js +0 -106
  205. package/test/icc-x-api/icc-accesslog-x-api.js.map +0 -1
  206. package/test/icc-x-api/icc-application-settings-x-api.d.ts +0 -1
  207. package/test/icc-x-api/icc-application-settings-x-api.js +0 -91
  208. package/test/icc-x-api/icc-application-settings-x-api.js.map +0 -1
  209. package/test/icc-x-api/icc-auth-api.d.ts +0 -1
  210. package/test/icc-x-api/icc-auth-api.js +0 -47
  211. package/test/icc-x-api/icc-auth-api.js.map +0 -1
  212. package/test/icc-x-api/icc-calendar-item-x-api.d.ts +0 -1
  213. package/test/icc-x-api/icc-calendar-item-x-api.js +0 -150
  214. package/test/icc-x-api/icc-calendar-item-x-api.js.map +0 -1
  215. package/test/icc-x-api/icc-contact-x-api.d.ts +0 -1
  216. package/test/icc-x-api/icc-contact-x-api.js +0 -355
  217. package/test/icc-x-api/icc-contact-x-api.js.map +0 -1
  218. package/test/icc-x-api/icc-document-x-api.d.ts +0 -1
  219. package/test/icc-x-api/icc-document-x-api.js +0 -76
  220. package/test/icc-x-api/icc-document-x-api.js.map +0 -1
  221. package/test/icc-x-api/icc-form-x-api.d.ts +0 -1
  222. package/test/icc-x-api/icc-form-x-api.js +0 -413
  223. package/test/icc-x-api/icc-form-x-api.js.map +0 -1
  224. package/test/icc-x-api/icc-hcparty-x-api-test.d.ts +0 -1
  225. package/test/icc-x-api/icc-hcparty-x-api-test.js +0 -43
  226. package/test/icc-x-api/icc-hcparty-x-api-test.js.map +0 -1
  227. package/test/icc-x-api/icc-helement-x-api-test.d.ts +0 -1
  228. package/test/icc-x-api/icc-helement-x-api-test.js +0 -155
  229. package/test/icc-x-api/icc-helement-x-api-test.js.map +0 -1
  230. package/test/icc-x-api/icc-invoice-x-api.d.ts +0 -1
  231. package/test/icc-x-api/icc-invoice-x-api.js +0 -99
  232. package/test/icc-x-api/icc-invoice-x-api.js.map +0 -1
  233. package/test/icc-x-api/icc-maintenance-task-x-api-test.d.ts +0 -1
  234. package/test/icc-x-api/icc-maintenance-task-x-api-test.js +0 -222
  235. package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +0 -1
  236. package/test/icc-x-api/icc-message-x-api.d.ts +0 -1
  237. package/test/icc-x-api/icc-message-x-api.js +0 -54
  238. package/test/icc-x-api/icc-message-x-api.js.map +0 -1
  239. package/test/icc-x-api/icc-patient-x-api-test.d.ts +0 -1
  240. package/test/icc-x-api/icc-patient-x-api-test.js +0 -165
  241. package/test/icc-x-api/icc-patient-x-api-test.js.map +0 -1
  242. package/test/icc-x-api/icc-recovery-x-api.d.ts +0 -1
  243. package/test/icc-x-api/icc-recovery-x-api.js +0 -175
  244. package/test/icc-x-api/icc-recovery-x-api.js.map +0 -1
  245. package/test/icc-x-api/icc-topic-x-api.d.ts +0 -1
  246. package/test/icc-x-api/icc-topic-x-api.js +0 -269
  247. package/test/icc-x-api/icc-topic-x-api.js.map +0 -1
  248. package/test/icc-x-api/icc-user-x-api-test.d.ts +0 -1
  249. package/test/icc-x-api/icc-user-x-api-test.js +0 -99
  250. package/test/icc-x-api/icc-user-x-api-test.js.map +0 -1
  251. package/test/icc-x-api/keyless-api.d.ts +0 -1
  252. package/test/icc-x-api/keyless-api.js +0 -125
  253. package/test/icc-x-api/keyless-api.js.map +0 -1
  254. package/test/icc-x-api/patient-user.d.ts +0 -2
  255. package/test/icc-x-api/patient-user.js +0 -103
  256. package/test/icc-x-api/patient-user.js.map +0 -1
  257. package/test/icc-x-api/storage/storage.d.ts +0 -1
  258. package/test/icc-x-api/storage/storage.js +0 -48
  259. package/test/icc-x-api/storage/storage.js.map +0 -1
  260. package/test/icc-x-api/test-api-no-parent.d.ts +0 -1
  261. package/test/icc-x-api/test-api-no-parent.js +0 -79
  262. package/test/icc-x-api/test-api-no-parent.js.map +0 -1
  263. package/test/icc-x-api/test-legacy-data-support.d.ts +0 -1
  264. package/test/icc-x-api/test-legacy-data-support.js +0 -375
  265. package/test/icc-x-api/test-legacy-data-support.js.map +0 -1
  266. package/test/icc-x-api/utils/graph-test.d.ts +0 -1
  267. package/test/icc-x-api/utils/graph-test.js +0 -54
  268. package/test/icc-x-api/utils/graph-test.js.map +0 -1
  269. package/test/icc-x-api/utils/lru-temporised-async-cache-test.d.ts +0 -1
  270. package/test/icc-x-api/utils/lru-temporised-async-cache-test.js +0 -364
  271. package/test/icc-x-api/utils/lru-temporised-async-cache-test.js.map +0 -1
  272. package/test/support/CSM-185.d.ts +0 -1
  273. package/test/support/CSM-185.js +0 -124
  274. package/test/support/CSM-185.js.map +0 -1
  275. package/test/support/CSM-243.d.ts +0 -1
  276. package/test/support/CSM-243.js +0 -120
  277. package/test/support/CSM-243.js.map +0 -1
  278. package/test/support/CSM-543.d.ts +0 -1
  279. package/test/support/CSM-543.js +0 -164
  280. package/test/support/CSM-543.js.map +0 -1
  281. package/test/support/CSM-729.d.ts +0 -1
  282. package/test/support/CSM-729.js +0 -225
  283. package/test/support/CSM-729.js.map +0 -1
  284. package/test/support/CSM-87.d.ts +0 -0
  285. package/test/support/CSM-87.js +0 -21
  286. package/test/support/CSM-87.js.map +0 -1
  287. package/test/support/CSM-93.d.ts +0 -1
  288. package/test/support/CSM-93.js +0 -112
  289. package/test/support/CSM-93.js.map +0 -1
  290. package/test/utils/FakeDataOwnerApi.d.ts +0 -32
  291. package/test/utils/FakeDataOwnerApi.js +0 -136
  292. package/test/utils/FakeDataOwnerApi.js.map +0 -1
  293. package/test/utils/FakeEncryptionKeysManager.d.ts +0 -36
  294. package/test/utils/FakeEncryptionKeysManager.js +0 -98
  295. package/test/utils/FakeEncryptionKeysManager.js.map +0 -1
  296. package/test/utils/FakeExchangeDataApi.d.ts +0 -32
  297. package/test/utils/FakeExchangeDataApi.js +0 -92
  298. package/test/utils/FakeExchangeDataApi.js.map +0 -1
  299. package/test/utils/FakeExchangeDataManager.d.ts +0 -48
  300. package/test/utils/FakeExchangeDataManager.js +0 -82
  301. package/test/utils/FakeExchangeDataManager.js.map +0 -1
  302. package/test/utils/FakeExchangeDataMapManager.d.ts +0 -12
  303. package/test/utils/FakeExchangeDataMapManager.js +0 -38
  304. package/test/utils/FakeExchangeDataMapManager.js.map +0 -1
  305. package/test/utils/FakeGenericApi.d.ts +0 -16
  306. package/test/utils/FakeGenericApi.js +0 -65
  307. package/test/utils/FakeGenericApi.js.map +0 -1
  308. package/test/utils/KeylessCryptoStrategies.d.ts +0 -23
  309. package/test/utils/KeylessCryptoStrategies.js +0 -26
  310. package/test/utils/KeylessCryptoStrategies.js.map +0 -1
  311. package/test/utils/TestApi.d.ts +0 -3
  312. package/test/utils/TestApi.js +0 -30
  313. package/test/utils/TestApi.js.map +0 -1
  314. package/test/utils/TestCollectionUtils.d.ts +0 -1
  315. package/test/utils/TestCollectionUtils.js +0 -109
  316. package/test/utils/TestCollectionUtils.js.map +0 -1
  317. package/test/utils/TestCryptoStrategies.d.ts +0 -42
  318. package/test/utils/TestCryptoStrategies.js +0 -80
  319. package/test/utils/TestCryptoStrategies.js.map +0 -1
  320. package/test/utils/TestStorage.d.ts +0 -23
  321. package/test/utils/TestStorage.js +0 -61
  322. package/test/utils/TestStorage.js.map +0 -1
  323. package/test/utils/roles.d.ts +0 -14
  324. package/test/utils/roles.js +0 -345
  325. package/test/utils/roles.js.map +0 -1
  326. package/test/utils/test_utils.d.ts +0 -87
  327. package/test/utils/test_utils.js +0 -452
  328. package/test/utils/test_utils.js.map +0 -1
@@ -17,6 +17,7 @@ const ShareMetadataBehaviour_1 = require("./crypto/ShareMetadataBehaviour");
17
17
  const SecureDelegation_1 = require("../icc-api/model/SecureDelegation");
18
18
  var AccessLevelEnum = SecureDelegation_1.SecureDelegation.AccessLevelEnum;
19
19
  const utils_1 = require("./utils");
20
+ const compression_utils_1 = require("./utils/compression-utils");
20
21
  class IccReceiptXApi extends icc_api_1.IccReceiptApi {
21
22
  get headers() {
22
23
  return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, utils_1.EntityWithDelegationTypeName.Receipt));
@@ -126,7 +127,84 @@ class IccReceiptXApi extends icc_api_1.IccReceiptApi {
126
127
  */
127
128
  getAndTryDecryptReceiptAttachment(receipt_1, attachmentId_1) {
128
129
  return __awaiter(this, arguments, void 0, function* (receipt, attachmentId, validator = () => Promise.resolve(true)) {
129
- return yield this.crypto.xapi.tryDecryptDataOf({ entity: receipt, type: utils_1.EntityWithDelegationTypeName.Receipt }, yield this.getReceiptAttachment(receipt.id, attachmentId), (x) => validator(x));
130
+ return yield this.crypto.xapi.tryDecryptDataOf({ entity: receipt, type: utils_1.EntityWithDelegationTypeName.Receipt }, yield this.getReceiptAttachment(receipt.id, attachmentId), (x) => __awaiter(this, void 0, void 0, function* () { return ((yield validator(x)) ? x : undefined); }));
131
+ });
132
+ }
133
+ // --- New data attachment methods (with compression support) ---
134
+ /**
135
+ * Compresses, encrypts, and uploads a receipt attachment using the new data attachment endpoint.
136
+ * Compression is attempted automatically; if the compressed result is not smaller, the original data is used.
137
+ * @param receipt a receipt.
138
+ * @param blobType the type of the attachment.
139
+ * @param attachment the raw attachment data.
140
+ * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated receipt.
141
+ */
142
+ encryptCompressAndSetReceiptDataAttachment(receipt_1, blobType_1, attachment_1) {
143
+ return __awaiter(this, arguments, void 0, function* (receipt, blobType, attachment, deflate = false) {
144
+ var _a;
145
+ const realDataSize = (0, utils_1.ua2ab)(attachment).byteLength;
146
+ const { data: dataToEncrypt, algorithm: compressionAlgorithm } = deflate
147
+ ? yield (0, compression_utils_1.compressData)(attachment)
148
+ : { data: (0, utils_1.ua2ab)(attachment), algorithm: undefined };
149
+ const { encryptedData, updatedEntity } = yield this.crypto.xapi.encryptDataOf(receipt, utils_1.EntityWithDelegationTypeName.Receipt, dataToEncrypt, (r) => this.modifyReceipt(r));
150
+ return yield this.setReceiptDataAttachment(receipt.id, blobType, (_a = updatedEntity === null || updatedEntity === void 0 ? void 0 : updatedEntity.rev) !== null && _a !== void 0 ? _a : receipt.rev, encryptedData, compressionAlgorithm, (0, compression_utils_1.getCompressionVersion)(), realDataSize);
151
+ });
152
+ }
153
+ /**
154
+ * Compresses and uploads an unencrypted receipt attachment using the new data attachment endpoint.
155
+ * Compression is attempted automatically; if the compressed result is not smaller, the original data is used.
156
+ * @param receipt a receipt.
157
+ * @param blobType the type of the attachment.
158
+ * @param attachment the raw attachment data.
159
+ * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated receipt.
160
+ */
161
+ setClearReceiptDataAttachment(receipt_1, blobType_1, attachment_1) {
162
+ return __awaiter(this, arguments, void 0, function* (receipt, blobType, attachment, deflate = false) {
163
+ const realDataSize = (0, utils_1.ua2ab)(attachment).byteLength;
164
+ const { data: dataToUpload, algorithm: compressionAlgorithm } = deflate
165
+ ? yield (0, compression_utils_1.compressData)(attachment)
166
+ : { data: (0, utils_1.ua2ab)(attachment), algorithm: undefined };
167
+ return yield this.setReceiptDataAttachment(receipt.id, blobType, receipt.rev, dataToUpload, compressionAlgorithm, (0, compression_utils_1.getCompressionVersion)(), realDataSize);
168
+ });
169
+ }
170
+ /**
171
+ * Gets a receipt's data attachment by blob type, decrypts it, and decompresses if needed.
172
+ * Throws if decryption fails.
173
+ * @param receipt a receipt.
174
+ * @param blobType the blob type of the attachment to retrieve.
175
+ * @param validator optionally a validator function which checks if the decryption was successful.
176
+ * @return the decrypted (and decompressed) attachment.
177
+ */
178
+ getAndDecryptReceiptDataAttachment(receipt_1, blobType_1) {
179
+ return __awaiter(this, arguments, void 0, function* (receipt, blobType, validator = () => Promise.resolve(true)) {
180
+ const retrieved = yield this.getAndTryDecryptReceiptDataAttachment(receipt, blobType, validator);
181
+ if (!retrieved.wasDecrypted)
182
+ throw new Error(`No valid key found to decrypt data of receipt ${receipt.id}.`);
183
+ return retrieved.data;
184
+ });
185
+ }
186
+ /**
187
+ * Gets a receipt's data attachment by blob type, tries to decrypt it, and decompresses if needed.
188
+ * @param receipt a receipt.
189
+ * @param blobType the blob type of the attachment to retrieve.
190
+ * @param validator optionally a validator function which checks if the decryption was successful.
191
+ * @return an object containing:
192
+ * - data: the decrypted (and decompressed) attachment, or the raw data if decryption failed.
193
+ * - wasDecrypted: if the data was successfully decrypted or not.
194
+ */
195
+ getAndTryDecryptReceiptDataAttachment(receipt_1, blobType_1) {
196
+ return __awaiter(this, arguments, void 0, function* (receipt, blobType, validator = () => Promise.resolve(true)) {
197
+ var _a, _b;
198
+ const compressionAlgorithm = (_b = (_a = receipt.attachmentInfos) === null || _a === void 0 ? void 0 : _a[blobType]) === null || _b === void 0 ? void 0 : _b.compressionAlgorithm;
199
+ return yield this.crypto.xapi.tryDecryptDataOf({ entity: receipt, type: utils_1.EntityWithDelegationTypeName.Receipt }, yield this.getReceiptAttachmentByBlobType(receipt.id, blobType), (decrypted) => __awaiter(this, void 0, void 0, function* () {
200
+ try {
201
+ const data = compressionAlgorithm ? yield (0, compression_utils_1.decompressData)(decrypted, compressionAlgorithm) : decrypted;
202
+ return (yield validator(data)) ? data : undefined;
203
+ }
204
+ catch (_a) {
205
+ return undefined;
206
+ }
207
+ }));
130
208
  });
131
209
  }
132
210
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"icc-receipt-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-receipt-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA0C;AAG1C,kDAAiD;AAEjD,0EAAgG;AAChG,4EAAwE;AAIxE,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAIzD,mCAA6D;AAE7D,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,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;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAVtC,WAAM,GAAN,MAAM,CAAe;QACrB,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,mBA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A0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;IACpJ,CAAC;CACF;AApSD,wCAoSC","sourcesContent":["import { IccReceiptApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { MaintenanceTask } from '../icc-api/model/models'\nimport { EntityWithDelegationTypeName, ua2ab } from './utils'\n\nexport class IccReceiptXApi extends IccReceiptApi implements EncryptedEntityXApi<models.Receipt> {\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Receipt))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\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 this.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of receipt with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param r initialised data for the receipt. 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 * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of receipt.\n */\n async newInstance(\n user: models.User,\n r: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n ignoreAutoDelegations?: boolean\n alternateRootDelegation?: string\n } = {}\n ): Promise<models.Receipt> {\n const receipt = new models.Receipt({\n ...(r ?? {}),\n _type: 'org.taktik.icure.entities.Receipt',\n id: r?.id ?? this.crypto.primitives.randomUuid(),\n created: r?.created ?? new Date().getTime(),\n modified: r?.modified ?? new Date().getTime(),\n responsible: r?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: r?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: r?.codes ?? [],\n tags: r?.tags ?? [],\n })\n\n const extraDelegations = {\n ...(options.ignoreAutoDelegations == true\n ? {}\n : Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n )),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Receipt(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n receipt,\n EntityWithDelegationTypeName.Receipt,\n undefined,\n undefined,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * Creates a new receipt linked to a document and optionally attaches a blob to it.\n * @param user the current user.\n * @param docId the id of the document this receipt refers to.\n * @param refs an array of reference strings to associate with the receipt.\n * @param blobType the type of the blob attachment.\n * @param blob the binary content to attach; if empty (byteLength == 0), no attachment is set.\n * @return the created receipt, with the attachment set if the blob was non-empty.\n */\n logReceipt(user: models.User, docId: string, refs: Array<string>, blobType: string, blob: ArrayBuffer) {\n return this.newInstance(user, { documentId: docId, references: refs })\n .then((rcpt) => this.createReceipt(rcpt))\n .then((rcpt) => (blob.byteLength != 0 ? this.setReceiptAttachmentForBlobType(rcpt.id!, rcpt.rev!, blobType, <any>blob) : Promise.resolve(rcpt)))\n }\n\n /**\n * Adds an attachment to a receipt, encrypting it on client side using the encryption keys of the provided receipt.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment a attachment for the receipt.\n * @return the updated receipt.\n */\n async encryptAndSetReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n const { encryptedData, updatedEntity } = await this.crypto.xapi.encryptDataOf(receipt, EntityWithDelegationTypeName.Receipt, attachment, (r) =>\n this.modifyReceipt(r)\n )\n return await this.setReceiptAttachmentForBlobType(receipt.id!, updatedEntity?.rev ?? receipt.rev!, blobType, encryptedData)\n }\n\n /**\n * Adds an unencrypted attachment to a receipt.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment a attachment for the receipt.\n * @return the updated receipt.\n */\n async setClearReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n return await this.setReceiptAttachmentForBlobType(receipt.id!, receipt.rev!, blobType, ua2ab(attachment))\n }\n\n /**\n * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt.\n * @param receipt a receipt.\n * @param attachmentId id of the attachment of this receipt to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption\n * keys and it is unclear which one should be used this function can help to detect bad decryptions.\n * @return the decrypted attachment, if it could be decrypted, else the encrypted attachment.\n */\n async getAndDecryptReceiptAttachment(\n receipt: models.Receipt,\n attachmentId: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<ArrayBuffer> {\n const retrieved = await this.getAndTryDecryptReceiptAttachment(receipt, attachmentId, (x) => validator(x))\n if (!retrieved.wasDecrypted) throw new Error(`No valid key found to decrypt data of receipt ${receipt.id}.`)\n return retrieved.data\n }\n\n /**\n * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt.\n * @param receipt a receipt.\n * @param attachmentId id of the attachment of this receipt to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption\n * keys and it is unclear which one should be used this function can help to detect bad decryptions.\n * @return an object containing:\n * - data: the decrypted attachment, if it could be decrypted, else the encrypted attachment.\n * - wasDecrypted: if the data was successfully decrypted or not\n */\n async getAndTryDecryptReceiptAttachment(\n receipt: models.Receipt,\n attachmentId: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<{ data: ArrayBuffer; wasDecrypted: boolean }> {\n return await this.crypto.xapi.tryDecryptDataOf(\n { entity: receipt, type: EntityWithDelegationTypeName.Receipt },\n await this.getReceiptAttachment(receipt.id!, attachmentId),\n (x) => validator(x)\n )\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given receipt\n */\n async hasWriteAccess(receipt: models.Receipt): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: receipt, type: EntityWithDelegationTypeName.Receipt })\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt 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 receipt.\n * @param receipt the receipt to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * receipt 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 receipt: models.Receipt,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Receipt> {\n return this.shareWithMany(receipt, { [delegateId]: options })\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param receipt the receipt 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 * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * receipt 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 receipt: models.Receipt,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Receipt> {\n return (await this.tryShareWithMany(receipt, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param receipt the receipt 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 * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * receipt 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 receipt: models.Receipt,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Receipt>> {\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(receipt, EntityWithDelegationTypeName.Receipt)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyReceipt(entityWithEncryptionKey) : receipt\n return this.crypto.xapi.simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Receipt,\n },\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: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareReceipt(x)\n )\n }\n\n /**\n * Retrieves the data owners that have access to the given receipt, along with their access levels.\n * @param entity the receipt.\n * @return an object containing a map of data owner ids to their access levels, and a flag indicating if there are unknown anonymous data owners.\n */\n getDataOwnersWithAccessTo(\n entity: models.Receipt\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Receipt })\n }\n\n /**\n * Retrieves the encryption keys of the given receipt.\n * @param entity the receipt.\n * @return the encryption key ids.\n */\n getEncryptionKeysOf(entity: models.Receipt): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Receipt }, undefined)\n }\n\n /**\n * Creates or updates de-anonymization metadata for the given receipt, allowing the specified delegates to\n * identify the data owners that have access to it.\n * @param entity the receipt.\n * @param delegates the data owner ids for which to create de-anonymization metadata.\n */\n createDelegationDeAnonymizationMetadata(entity: models.Receipt, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Receipt }, delegates)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-receipt-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-receipt-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA0C;AAE1C,kDAAiD;AAEjD,0EAAgG;AAChG,4EAAwE;AAIxE,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAIzD,mCAA6D;AAC7D,iEAA+F;AAE/F,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,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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,CAAC,CAChC,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACH,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;;;;OAIG;IACH,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;;;;;OAKG;IACH,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;AAvZD,wCAuZC","sourcesContent":["import { IccReceiptApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { MaintenanceTask } from '../icc-api/model/models'\nimport { EntityWithDelegationTypeName, ua2ab } from './utils'\nimport { compressData, decompressData, getCompressionVersion } from './utils/compression-utils'\n\nexport class IccReceiptXApi extends IccReceiptApi implements EncryptedEntityXApi<models.Receipt> {\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Receipt))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\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 this.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of receipt with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param r initialised data for the receipt. 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 * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of receipt.\n */\n async newInstance(\n user: models.User,\n r: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n ignoreAutoDelegations?: boolean\n alternateRootDelegation?: string\n } = {}\n ): Promise<models.Receipt> {\n const receipt = new models.Receipt({\n ...(r ?? {}),\n _type: 'org.taktik.icure.entities.Receipt',\n id: r?.id ?? this.crypto.primitives.randomUuid(),\n created: r?.created ?? new Date().getTime(),\n modified: r?.modified ?? new Date().getTime(),\n responsible: r?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: r?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: r?.codes ?? [],\n tags: r?.tags ?? [],\n })\n\n const extraDelegations = {\n ...(options.ignoreAutoDelegations == true\n ? {}\n : Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n )),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Receipt(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n receipt,\n EntityWithDelegationTypeName.Receipt,\n undefined,\n undefined,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * Creates a new receipt linked to a document and optionally attaches a blob to it.\n * @param user the current user.\n * @param docId the id of the document this receipt refers to.\n * @param refs an array of reference strings to associate with the receipt.\n * @param blobType the type of the blob attachment.\n * @param blob the binary content to attach; if empty (byteLength == 0), no attachment is set.\n * @return the created receipt, with the attachment set if the blob was non-empty.\n */\n logReceipt(user: models.User, docId: string, refs: Array<string>, blobType: string, blob: ArrayBuffer) {\n return this.newInstance(user, { documentId: docId, references: refs })\n .then((rcpt) => this.createReceipt(rcpt))\n .then((rcpt) => (blob.byteLength != 0 ? this.setReceiptAttachmentForBlobType(rcpt.id!, rcpt.rev!, blobType, <any>blob) : Promise.resolve(rcpt)))\n }\n\n /**\n * Adds an attachment to a receipt, encrypting it on client side using the encryption keys of the provided receipt.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment a attachment for the receipt.\n * @return the updated receipt.\n */\n async encryptAndSetReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n const { encryptedData, updatedEntity } = await this.crypto.xapi.encryptDataOf(receipt, EntityWithDelegationTypeName.Receipt, attachment, (r) =>\n this.modifyReceipt(r)\n )\n return await this.setReceiptAttachmentForBlobType(receipt.id!, updatedEntity?.rev ?? receipt.rev!, blobType, encryptedData)\n }\n\n /**\n * Adds an unencrypted attachment to a receipt.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment a attachment for the receipt.\n * @return the updated receipt.\n */\n async setClearReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n return await this.setReceiptAttachmentForBlobType(receipt.id!, receipt.rev!, blobType, ua2ab(attachment))\n }\n\n /**\n * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt.\n * @param receipt a receipt.\n * @param attachmentId id of the attachment of this receipt to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption\n * keys and it is unclear which one should be used this function can help to detect bad decryptions.\n * @return the decrypted attachment, if it could be decrypted, else the encrypted attachment.\n */\n async getAndDecryptReceiptAttachment(\n receipt: models.Receipt,\n attachmentId: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<ArrayBuffer> {\n const retrieved = await this.getAndTryDecryptReceiptAttachment(receipt, attachmentId, (x) => validator(x))\n if (!retrieved.wasDecrypted) throw new Error(`No valid key found to decrypt data of receipt ${receipt.id}.`)\n return retrieved.data\n }\n\n /**\n * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt.\n * @param receipt a receipt.\n * @param attachmentId id of the attachment of this receipt to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption\n * keys and it is unclear which one should be used this function can help to detect bad decryptions.\n * @return an object containing:\n * - data: the decrypted attachment, if it could be decrypted, else the encrypted attachment.\n * - wasDecrypted: if the data was successfully decrypted or not\n */\n async getAndTryDecryptReceiptAttachment(\n receipt: models.Receipt,\n attachmentId: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<{ data: ArrayBuffer; wasDecrypted: boolean }> {\n return await this.crypto.xapi.tryDecryptDataOf(\n { entity: receipt, type: EntityWithDelegationTypeName.Receipt },\n await this.getReceiptAttachment(receipt.id!, attachmentId),\n async (x) => ((await validator(x)) ? x : undefined)\n )\n }\n\n // --- New data attachment methods (with compression support) ---\n\n /**\n * Compresses, encrypts, and uploads a receipt attachment using the new data attachment endpoint.\n * Compression is attempted automatically; if the compressed result is not smaller, the original data is used.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment the raw attachment data.\n * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated receipt.\n */\n async encryptCompressAndSetReceiptDataAttachment(\n receipt: models.Receipt,\n blobType: string,\n attachment: ArrayBuffer | Uint8Array,\n deflate: boolean = false\n ): Promise<models.Receipt> {\n const realDataSize = ua2ab(attachment).byteLength\n const { data: dataToEncrypt, algorithm: compressionAlgorithm } = deflate\n ? await compressData(attachment)\n : { data: ua2ab(attachment), algorithm: undefined }\n\n const { encryptedData, updatedEntity } = await this.crypto.xapi.encryptDataOf(\n receipt,\n EntityWithDelegationTypeName.Receipt,\n dataToEncrypt,\n (r) => this.modifyReceipt(r)\n )\n return await this.setReceiptDataAttachment(\n receipt.id!,\n blobType,\n updatedEntity?.rev ?? receipt.rev!,\n encryptedData,\n compressionAlgorithm,\n getCompressionVersion(),\n realDataSize\n )\n }\n\n /**\n * Compresses and uploads an unencrypted receipt attachment using the new data attachment endpoint.\n * Compression is attempted automatically; if the compressed result is not smaller, the original data is used.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment the raw attachment data.\n * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated receipt.\n */\n async setClearReceiptDataAttachment(\n receipt: models.Receipt,\n blobType: string,\n attachment: ArrayBuffer | Uint8Array,\n deflate: boolean = false\n ): Promise<models.Receipt> {\n const realDataSize = ua2ab(attachment).byteLength\n const { data: dataToUpload, algorithm: compressionAlgorithm } = deflate\n ? await compressData(attachment)\n : { data: ua2ab(attachment), algorithm: undefined }\n\n return await this.setReceiptDataAttachment(\n receipt.id!,\n blobType,\n receipt.rev!,\n dataToUpload,\n compressionAlgorithm,\n getCompressionVersion(),\n realDataSize\n )\n }\n\n /**\n * Gets a receipt's data attachment by blob type, decrypts it, and decompresses if needed.\n * Throws if decryption fails.\n * @param receipt a receipt.\n * @param blobType the blob type of the attachment to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful.\n * @return the decrypted (and decompressed) attachment.\n */\n async getAndDecryptReceiptDataAttachment(\n receipt: models.Receipt,\n blobType: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<ArrayBuffer> {\n const retrieved = await this.getAndTryDecryptReceiptDataAttachment(receipt, blobType, validator)\n if (!retrieved.wasDecrypted) throw new Error(`No valid key found to decrypt data of receipt ${receipt.id}.`)\n return retrieved.data\n }\n\n /**\n * Gets a receipt's data attachment by blob type, tries to decrypt it, and decompresses if needed.\n * @param receipt a receipt.\n * @param blobType the blob type of the attachment to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful.\n * @return an object containing:\n * - data: the decrypted (and decompressed) attachment, or the raw data if decryption failed.\n * - wasDecrypted: if the data was successfully decrypted or not.\n */\n async getAndTryDecryptReceiptDataAttachment(\n receipt: models.Receipt,\n blobType: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<{ data: ArrayBuffer; wasDecrypted: boolean }> {\n const compressionAlgorithm = receipt.attachmentInfos?.[blobType]?.compressionAlgorithm\n return await this.crypto.xapi.tryDecryptDataOf(\n { entity: receipt, type: EntityWithDelegationTypeName.Receipt },\n await this.getReceiptAttachmentByBlobType(receipt.id!, blobType),\n async (decrypted) => {\n try {\n const data = compressionAlgorithm ? await decompressData(decrypted, compressionAlgorithm) : decrypted\n return (await validator(data)) ? data : undefined\n } catch {\n return undefined\n }\n }\n )\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given receipt\n */\n async hasWriteAccess(receipt: models.Receipt): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: receipt, type: EntityWithDelegationTypeName.Receipt })\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt 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 receipt.\n * @param receipt the receipt to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * receipt 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 receipt: models.Receipt,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Receipt> {\n return this.shareWithMany(receipt, { [delegateId]: options })\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param receipt the receipt 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 * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * receipt 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 receipt: models.Receipt,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Receipt> {\n return (await this.tryShareWithMany(receipt, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param receipt the receipt 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 * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * receipt 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 receipt: models.Receipt,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Receipt>> {\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(receipt, EntityWithDelegationTypeName.Receipt)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyReceipt(entityWithEncryptionKey) : receipt\n return this.crypto.xapi.simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Receipt,\n },\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: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareReceipt(x)\n )\n }\n\n /**\n * Retrieves the data owners that have access to the given receipt, along with their access levels.\n * @param entity the receipt.\n * @return an object containing a map of data owner ids to their access levels, and a flag indicating if there are unknown anonymous data owners.\n */\n getDataOwnersWithAccessTo(\n entity: models.Receipt\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Receipt })\n }\n\n /**\n * Retrieves the encryption keys of the given receipt.\n * @param entity the receipt.\n * @return the encryption key ids.\n */\n getEncryptionKeysOf(entity: models.Receipt): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Receipt }, undefined)\n }\n\n /**\n * Creates or updates de-anonymization metadata for the given receipt, allowing the specified delegates to\n * identify the data owners that have access to it.\n * @param entity the receipt.\n * @param delegates the data owner ids for which to create de-anonymization metadata.\n */\n createDelegationDeAnonymizationMetadata(entity: models.Receipt, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Receipt }, delegates)\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"icc-topic-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-topic-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAoD;AAIpD,kDAAiD;AAGjD,0EAAgG;AAChG,wEAAoE;AAGpE,qFAAiF;AAKjF,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AACzD,IAAO,uBAAuB,GAAG,uCAAkB,CAAC,uBAAuB,CAAA;AAC3E,mCAAmJ;AAEnJ,4DAAwE;AACxE,kEAA8D;AAE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AEK,sBAAsB;6DAC1B,UAA8C,EAC9C,MAAyC,EACzC,UAA6C,EAC7C,UAA+B,EAAE;YAEjC,OAAO,MAAM,IAAA,+BAAuB,EAClC,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,OAAO,EACZ,oCAA4B,CAAC,KAAK,EAClC,UAAU,EACV,MAAM,EACN,UAAU,EACV,OAAO,EACP,CAAO,SAAS,EAAE,EAAE,gDAAC,OAAA,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,GAAA,CAC1D,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;KAAA;IAED,uCAAuC,CAAC,MAAa,EAAE,SAAmB;QACxE,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAA;IAClJ,CAAC;CACF;AA/WD,oCA+WC","sourcesContent":["import { IccAuthApi, IccTopicApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { ListOfIds, MaintenanceTask, TimingInfo, Topic, TopicRole } 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 { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { FilterChainTopic } from '../icc-api/model/FilterChainTopic'\nimport { PaginatedListTopic } from '../icc-api/model/PaginatedListTopic'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { AbstractFilter } from './filters/filters'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { SecretIdUseOption } from './crypto/SecretIdUseOption'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccTopicXApi extends IccTopicApi implements EncryptedEntityXApi<models.Topic> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n encryptedKeys: Array<string> = ['description'],\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 this.encryptedFields = parseEncryptedFields(encryptedKeys, 'Topic.')\n }\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Topic))\n }\n\n /**\n * Creates a new instance of topic with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this topic refers to.\n * @param c initialised data for the topic. 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 * - sfkOption: specifies which sfk of the owning entity to use.\n * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of topic.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient | null,\n c: Topic = {}, // TODO: Why this isn't Topic?\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n sfkOption?: SecretIdUseOption\n ignoreAutoDelegations?: boolean\n alternateRootDelegation?: string\n } = {}\n ) {\n if (!patient && options.sfkOption) throw new Error('preferredSfk can only be specified if patient is specified.')\n\n const topic = {\n ...(c ?? {}),\n id: c?.id ?? this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.Topic',\n created: c?.created ?? new Date().getTime(),\n modified: c?.modified ?? new Date().getTime(),\n responsible: c?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: c?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: c?.codes ?? [],\n tags: c?.tags ?? [],\n }\n\n const extraDelegations = {\n ...(options.ignoreAutoDelegations == true ? {} : Object.fromEntries((user.autoDelegations?.all ?? []).map((d) => [d, AccessLevelEnum.WRITE]))),\n ...(options?.additionalDelegates ?? {}),\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 = patient\n ? await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n options.sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n : undefined\n\n if (patient && !sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n\n return new models.Topic(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n topic,\n EntityWithDelegationTypeName.Topic,\n patient?.id,\n sfk,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n async decrypt(topics: Array<models.Topic>) {\n return (await this.crypto.xapi.tryDecryptEntities(topics, EntityWithDelegationTypeName.Topic, (x) => new models.Topic(x))).map(\n ({ entity }) => entity\n )\n }\n\n async encrypt(topics: Array<models.Topic>): Promise<Array<models.Topic>> {\n return this.crypto.xapi.tryEncryptEntities(\n topics,\n EntityWithDelegationTypeName.Topic,\n this.encryptedFields,\n true,\n false,\n (x) => new models.Topic(x)\n )\n }\n\n /**\n * Create and share a new topic with other participants.\n * @param body the topic to create.\n * @return the created topic.\n */\n override async createTopic(body: Topic): Promise<Topic> {\n const encryptedTopics = await this.encrypt([body])\n const createdTopic = await super.createTopic(encryptedTopics[0])\n const decryptedTopics = await this.decrypt([createdTopic])\n return decryptedTopics[0]\n }\n\n /**\n * @param topic a topic\n * @return the id of the patient that the topic 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(topic: models.Topic): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: topic, type: EntityWithDelegationTypeName.Topic }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given topic\n */\n async hasWriteAccess(topic: models.Topic): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: topic, type: EntityWithDelegationTypeName.Topic })\n }\n\n /**\n * Share an existing topic with other data owners, allowing them to access the non-encrypted data of the topic 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 topic.\n * @param topic the topic to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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}).\n * - sharePatientId: specifies if the id of the patient that this topic 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 topic: models.Topic,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Topic> {\n return this.shareWithMany(topic, { [delegateId]: options })\n }\n\n /**\n * Share an existing topic with other data owners, allowing them to access the non-encrypted data of the topic and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param topic the topic 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 * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * topic does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this topic 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 topic: models.Topic,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: 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.Topic> {\n return (await this.tryShareWithMany(topic, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing topic with other data owners, allowing them to access the non-encrypted data of the topic and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param topic the topic 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 * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * topic does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this topic 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 topic: models.Topic,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: 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.Topic>> {\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(topic, EntityWithDelegationTypeName.Topic)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyTopic(entityWithEncryptionKey) : topic\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Topic,\n },\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: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareTopics(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt([e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Topic\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Topic })\n }\n\n getEncryptionKeysOf(entity: models.Topic): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Topic }, undefined)\n }\n\n /**\n * Filter and decrypt topics by the given filter.\n * @param body the filter to apply.\n * @param startDocumentId the document id to start from (inclusive).\n * @param limit the maximum number of topics to return in the page.\n * @param collectTiming add timing information to the response\n * @return a paginated list of topics.\n */\n override async filterTopicsBy(body: FilterChainTopic, startDocumentId?: string, limit?: number, collectTiming?: false): Promise<PaginatedListTopic>\n override async filterTopicsBy(body: FilterChainTopic, startDocumentId?: string, limit?: number, collectTiming?: true): Promise<PaginatedListTopic & TimingInfo>\n override async filterTopicsBy(body: FilterChainTopic, startDocumentId?: string, limit?: number, collectTiming: boolean = false): Promise<PaginatedListTopic> {\n const page = await super.filterTopicsBy(body, startDocumentId, limit, collectTiming as any)\n const decryptedTopics = await this.decrypt(page.rows ?? [])\n return {\n ...page,\n rows: decryptedTopics,\n }\n }\n\n /**\n * Obtain the topic with the given id and decrypt it.\n * @param id the id of the topic to retrieve.\n * @return the decrypted topic.\n */\n override async getTopic(id: string): Promise<Topic> {\n const topic = await super.getTopic(id)\n const decryptedTopics = await this.decrypt([topic])\n return decryptedTopics[0]\n }\n\n /**\n * Obtain the topics with the given ids and decrypt them.\n * @param body the ids of the topics to retrieve.\n * @return the decrypted topics.\n */\n override async getTopics(body: ListOfIds): Promise<Array<Topic>> {\n const topics = await super.getTopics(body)\n return await this.decrypt(topics)\n }\n\n /**\n * Update and encrypt the given topic.\n * @param body the topic to update.\n * @return the updated decrypted topic.\n */\n override async modifyTopic(body: Topic): Promise<Topic> {\n const encryptedTopics = await this.encrypt([body])\n const modifiedTopic = await super.modifyTopic(encryptedTopics[0])\n const decryptedTopics = await this.decrypt([modifiedTopic])\n return decryptedTopics[0]\n }\n\n /**\n * @internal this method is for internal use only and may be changed without notice\n * @param body data owner id of the data owner to which the participant should be added and the topic role of the participant.\n * @param topicId Id of the topic to which the participant should be added.\n */\n override async addParticipant(body: { dataOwnerId: string; topicRole: TopicRole }, topicId: string): Promise<Topic> {\n throw new Error('Cannot add participant to topic without sharing it first. You should use addParticipantWithTopic instead.')\n }\n\n /**\n * This method is similar to {@link addParticipant} but it also shares the topic with the data owner before adding the participant.\n * @param body data owner id of the data owner to which the participant should be added and the topic role of the participant.\n * @param topic the topic to share and to which the participant should be added.\n * @return the updated topic.\n */\n async addParticipantWithTopic(body: { dataOwnerId: string; topicRole: TopicRole }, topic: Topic): Promise<Topic> {\n const updatedTopic = await this.shareWith(body.dataOwnerId, topic, {\n requestedPermissions: RequestedPermissionEnum.FULL_WRITE,\n })\n\n return (await this.decrypt([await super.addParticipant(body, updatedTopic.id!)]))[0]\n }\n\n /**\n * Remove the participant with the given data owner id from the topic with the given id.\n * @param body data owner id of the participant to remove.\n * @param topicId Id of the topic from which the participant should be removed.\n * @return the updated decrypted topic.\n */\n async removeParticipant(body: { dataOwnerId: string }, topicId: string): Promise<Topic> {\n const updatedTopic = await super.removeParticipant(body, topicId)\n return (await this.decrypt([updatedTopic]))[0]\n }\n\n async subscribeToTopicEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<Topic> | undefined,\n eventFired: (message: Topic) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return await subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.Topic,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt([encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: Topic, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Topic }, delegates)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-topic-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-topic-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAoD;AAGpD,kDAAiD;AAGjD,0EAAgG;AAChG,wEAAoE;AAGpE,qFAAiF;AAKjF,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AACzD,IAAO,uBAAuB,GAAG,uCAAkB,CAAC,uBAAuB,CAAA;AAC3E,mCAAmJ;AAEnJ,4DAAwE;AACxE,kEAA8D;AAE9D,qCAAqC;AACrC,MAAa,YAAa,SAAQ,qBAAW;IAG3C,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,YAA8B,EAC9B,OAAmB,EACnB,cAAuB,EACxC,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,gBAA+B,CAAC,aAAa,CAAC,EAC9C,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;QAZtC,WAAM,GAAN,MAAM,CAAe;QACrB,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,YAAO,GAAP,OAAO,CAAY;QACnB,mBAAc,GAAd,cAAc,CAAS;QAWxC,IAAI,CAAC,eAAe,GAAG,IAAA,4BAAoB,EAAC,aAAa,EAAE,QAAQ,CAAC,CAAA;IACtE,CAAC;IAED,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CA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'./icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\nimport { ListOfIds, MaintenanceTask, TimingInfo, Topic, TopicRole } 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 { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { FilterChainTopic } from '../icc-api/model/FilterChainTopic'\nimport { PaginatedListTopic } from '../icc-api/model/PaginatedListTopic'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { AbstractFilter } from './filters/filters'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { SecretIdUseOption } from './crypto/SecretIdUseOption'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccTopicXApi extends IccTopicApi implements EncryptedEntityXApi<models.Topic> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n encryptedKeys: Array<string> = ['description'],\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 this.encryptedFields = parseEncryptedFields(encryptedKeys, 'Topic.')\n }\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Topic))\n }\n\n /**\n * Creates a new instance of topic with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this topic refers to.\n * @param c initialised data for the topic. 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 * - sfkOption: specifies which sfk of the owning entity to use.\n * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of topic.\n */\n async newInstance(\n user: models.User,\n patient: models.Patient | null,\n c: Topic = {}, // TODO: Why this isn't Topic?\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n sfkOption?: SecretIdUseOption\n ignoreAutoDelegations?: boolean\n alternateRootDelegation?: string\n } = {}\n ) {\n if (!patient && options.sfkOption) throw new Error('preferredSfk can only be specified if patient is specified.')\n\n const topic = {\n ...(c ?? {}),\n id: c?.id ?? this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.Topic',\n created: c?.created ?? new Date().getTime(),\n modified: c?.modified ?? new Date().getTime(),\n responsible: c?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: c?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: c?.codes ?? [],\n tags: c?.tags ?? [],\n }\n\n const extraDelegations = {\n ...(options.ignoreAutoDelegations == true ? {} : Object.fromEntries((user.autoDelegations?.all ?? []).map((d) => [d, AccessLevelEnum.WRITE]))),\n ...(options?.additionalDelegates ?? {}),\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 = patient\n ? await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n options.sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n : undefined\n\n if (patient && !sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n\n return new models.Topic(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n topic,\n EntityWithDelegationTypeName.Topic,\n patient?.id,\n sfk,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n async decrypt(topics: Array<models.Topic>) {\n return (await this.crypto.xapi.tryDecryptEntities(topics, EntityWithDelegationTypeName.Topic, (x) => new models.Topic(x))).map(\n ({ entity }) => entity\n )\n }\n\n async encrypt(topics: Array<models.Topic>): Promise<Array<models.Topic>> {\n return this.crypto.xapi.tryEncryptEntities(\n topics,\n EntityWithDelegationTypeName.Topic,\n this.encryptedFields,\n true,\n false,\n (x) => new models.Topic(x)\n )\n }\n\n /**\n * Create and share a new topic with other participants.\n * @param body the topic to create.\n * @return the created topic.\n */\n override async createTopic(body: Topic): Promise<Topic> {\n const encryptedTopics = await this.encrypt([body])\n const createdTopic = await super.createTopic(encryptedTopics[0])\n const decryptedTopics = await this.decrypt([createdTopic])\n return decryptedTopics[0]\n }\n\n /**\n * @param topic a topic\n * @return the id of the patient that the topic 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(topic: models.Topic): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: topic, type: EntityWithDelegationTypeName.Topic }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given topic\n */\n async hasWriteAccess(topic: models.Topic): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: topic, type: EntityWithDelegationTypeName.Topic })\n }\n\n /**\n * Share an existing topic with other data owners, allowing them to access the non-encrypted data of the topic 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 topic.\n * @param topic the topic to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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}).\n * - sharePatientId: specifies if the id of the patient that this topic 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 topic: models.Topic,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Topic> {\n return this.shareWithMany(topic, { [delegateId]: options })\n }\n\n /**\n * Share an existing topic with other data owners, allowing them to access the non-encrypted data of the topic and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param topic the topic 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 * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * topic does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this topic 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 topic: models.Topic,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: 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.Topic> {\n return (await this.tryShareWithMany(topic, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing topic with other data owners, allowing them to access the non-encrypted data of the topic and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param topic the topic 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 * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\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 * topic does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this topic 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 topic: models.Topic,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: 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.Topic>> {\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(topic, EntityWithDelegationTypeName.Topic)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyTopic(entityWithEncryptionKey) : topic\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Topic,\n },\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: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareTopics(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decrypt([e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Topic\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Topic })\n }\n\n getEncryptionKeysOf(entity: models.Topic): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Topic }, undefined)\n }\n\n /**\n * Filter and decrypt topics by the given filter.\n * @param body the filter to apply.\n * @param startDocumentId the document id to start from (inclusive).\n * @param limit the maximum number of topics to return in the page.\n * @param collectTiming add timing information to the response\n * @return a paginated list of topics.\n */\n override async filterTopicsBy(body: FilterChainTopic, startDocumentId?: string, limit?: number, collectTiming?: false): Promise<PaginatedListTopic>\n override async filterTopicsBy(body: FilterChainTopic, startDocumentId?: string, limit?: number, collectTiming?: true): Promise<PaginatedListTopic & TimingInfo>\n override async filterTopicsBy(body: FilterChainTopic, startDocumentId?: string, limit?: number, collectTiming: boolean = false): Promise<PaginatedListTopic> {\n const page = await super.filterTopicsBy(body, startDocumentId, limit, collectTiming as any)\n const decryptedTopics = await this.decrypt(page.rows ?? [])\n return {\n ...page,\n rows: decryptedTopics,\n }\n }\n\n /**\n * Obtain the topic with the given id and decrypt it.\n * @param id the id of the topic to retrieve.\n * @return the decrypted topic.\n */\n override async getTopic(id: string): Promise<Topic> {\n const topic = await super.getTopic(id)\n const decryptedTopics = await this.decrypt([topic])\n return decryptedTopics[0]\n }\n\n /**\n * Obtain the topics with the given ids and decrypt them.\n * @param body the ids of the topics to retrieve.\n * @return the decrypted topics.\n */\n override async getTopics(body: ListOfIds): Promise<Array<Topic>> {\n const topics = await super.getTopics(body)\n return await this.decrypt(topics)\n }\n\n /**\n * Update and encrypt the given topic.\n * @param body the topic to update.\n * @return the updated decrypted topic.\n */\n override async modifyTopic(body: Topic): Promise<Topic> {\n const encryptedTopics = await this.encrypt([body])\n const modifiedTopic = await super.modifyTopic(encryptedTopics[0])\n const decryptedTopics = await this.decrypt([modifiedTopic])\n return decryptedTopics[0]\n }\n\n /**\n * @internal this method is for internal use only and may be changed without notice\n * @param body data owner id of the data owner to which the participant should be added and the topic role of the participant.\n * @param topicId Id of the topic to which the participant should be added.\n */\n override async addParticipant(body: { dataOwnerId: string; topicRole: TopicRole }, topicId: string): Promise<Topic> {\n throw new Error('Cannot add participant to topic without sharing it first. You should use addParticipantWithTopic instead.')\n }\n\n /**\n * This method is similar to {@link addParticipant} but it also shares the topic with the data owner before adding the participant.\n * @param body data owner id of the data owner to which the participant should be added and the topic role of the participant.\n * @param topic the topic to share and to which the participant should be added.\n * @return the updated topic.\n */\n async addParticipantWithTopic(body: { dataOwnerId: string; topicRole: TopicRole }, topic: Topic): Promise<Topic> {\n const updatedTopic = await this.shareWith(body.dataOwnerId, topic, {\n requestedPermissions: RequestedPermissionEnum.FULL_WRITE,\n })\n\n return (await this.decrypt([await super.addParticipant(body, updatedTopic.id!)]))[0]\n }\n\n /**\n * Remove the participant with the given data owner id from the topic with the given id.\n * @param body data owner id of the participant to remove.\n * @param topicId Id of the topic from which the participant should be removed.\n * @return the updated decrypted topic.\n */\n async removeParticipant(body: { dataOwnerId: string }, topicId: string): Promise<Topic> {\n const updatedTopic = await super.removeParticipant(body, topicId)\n return (await this.decrypt([updatedTopic]))[0]\n }\n\n async subscribeToTopicEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<Topic> | undefined,\n eventFired: (message: Topic) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return await subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.Topic,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt([encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: Topic, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Topic }, delegates)\n }\n}\n"]}
@@ -177,7 +177,7 @@ var IcureApi;
177
177
  const params = new IcureApiOptions.WithDefaults(options);
178
178
  let authenticationProviderInfo = yield initialiseAuthProviderWithGroupSelector(host, authenticationOptions, params.headers, fetchImpl, params.groupSelector);
179
179
  const cryptoInitInfo = yield initialiseCryptoWithProvider(host, fetchImpl, authenticationProviderInfo.groupSpecificAuthenticationProvider, params, cryptoStrategies, crypto, (_a = options.useLiteCompatibilityMode) !== null && _a !== void 0 ? _a : false);
180
- return new IcureApiImpl(cryptoInitInfo, host, authenticationProviderInfo.groupSpecificAuthenticationProvider, fetch, authenticationProviderInfo.grouplessUserApi, authenticationProviderInfo.matches, authenticationProviderInfo.matches.find((match) => match.groupId === authenticationProviderInfo.chosenGroupId), params, cryptoStrategies, (_b = options.useLiteCompatibilityMode) !== null && _b !== void 0 ? _b : false);
180
+ return new IcureApiImpl(cryptoInitInfo, host, authenticationProviderInfo.groupSpecificAuthenticationProvider, fetchImpl, authenticationProviderInfo.grouplessUserApi, authenticationProviderInfo.matches, authenticationProviderInfo.matches.find((match) => match.groupId === authenticationProviderInfo.chosenGroupId), params, cryptoStrategies, (_b = options.useLiteCompatibilityMode) !== null && _b !== void 0 ? _b : false);
181
181
  });
182
182
  }
183
183
  IcureApi.initialise = initialise;