@icure/api 7.1.16 → 8.0.0-RC.2

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 (363) hide show
  1. package/icc-api/api/IccAccesslogApi.d.ts +12 -1
  2. package/icc-api/api/IccAccesslogApi.js +142 -98
  3. package/icc-api/api/IccAccesslogApi.js.map +1 -1
  4. package/icc-api/api/IccBemikronoApi.d.ts +81 -0
  5. package/icc-api/api/IccBemikronoApi.js +163 -0
  6. package/icc-api/api/IccBemikronoApi.js.map +1 -0
  7. package/icc-api/api/IccCalendarItemApi.d.ts +21 -1
  8. package/icc-api/api/IccCalendarItemApi.js +183 -117
  9. package/icc-api/api/IccCalendarItemApi.js.map +1 -1
  10. package/icc-api/api/IccClassificationApi.d.ts +21 -1
  11. package/icc-api/api/IccClassificationApi.js +119 -63
  12. package/icc-api/api/IccClassificationApi.js.map +1 -1
  13. package/icc-api/api/IccContactApi.d.ts +21 -1
  14. package/icc-api/api/IccContactApi.js +385 -294
  15. package/icc-api/api/IccContactApi.js.map +1 -1
  16. package/icc-api/api/IccDocumentApi.d.ts +38 -25
  17. package/icc-api/api/IccDocumentApi.js +279 -212
  18. package/icc-api/api/IccDocumentApi.js.map +1 -1
  19. package/icc-api/api/IccExchangeDataApi.d.ts +19 -0
  20. package/icc-api/api/IccExchangeDataApi.js +85 -0
  21. package/icc-api/api/IccExchangeDataApi.js.map +1 -0
  22. package/icc-api/api/IccExchangeDataMapApi.d.ts +18 -0
  23. package/icc-api/api/IccExchangeDataMapApi.js +65 -0
  24. package/icc-api/api/IccExchangeDataMapApi.js.map +1 -0
  25. package/icc-api/api/IccFormApi.d.ts +21 -1
  26. package/icc-api/api/IccFormApi.js +321 -229
  27. package/icc-api/api/IccFormApi.js.map +1 -1
  28. package/icc-api/api/IccHelementApi.d.ts +21 -1
  29. package/icc-api/api/IccHelementApi.js +207 -137
  30. package/icc-api/api/IccHelementApi.js.map +1 -1
  31. package/icc-api/api/IccInvoiceApi.d.ts +21 -1
  32. package/icc-api/api/IccInvoiceApi.js +404 -298
  33. package/icc-api/api/IccInvoiceApi.js.map +1 -1
  34. package/icc-api/api/IccMaintenanceTaskApi.d.ts +12 -1
  35. package/icc-api/api/IccMaintenanceTaskApi.js +79 -43
  36. package/icc-api/api/IccMaintenanceTaskApi.js.map +1 -1
  37. package/icc-api/api/IccMessageApi.d.ts +28 -1
  38. package/icc-api/api/IccMessageApi.js +294 -191
  39. package/icc-api/api/IccMessageApi.js.map +1 -1
  40. package/icc-api/api/IccPatientApi.d.ts +12 -1
  41. package/icc-api/api/IccPatientApi.js +447 -351
  42. package/icc-api/api/IccPatientApi.js.map +1 -1
  43. package/icc-api/api/IccReceiptApi.d.ts +22 -8
  44. package/icc-api/api/IccReceiptApi.js +121 -64
  45. package/icc-api/api/IccReceiptApi.js.map +1 -1
  46. package/icc-api/api/IccRestApiPath.js +1 -1
  47. package/icc-api/api/IccRestApiPath.js.map +1 -1
  48. package/icc-api/api/IccSecureDelegationKeyMapApi.d.ts +26 -0
  49. package/icc-api/api/IccSecureDelegationKeyMapApi.js +71 -0
  50. package/icc-api/api/IccSecureDelegationKeyMapApi.js.map +1 -0
  51. package/icc-api/api/IccTimeTableApi.d.ts +12 -1
  52. package/icc-api/api/IccTimeTableApi.js +86 -48
  53. package/icc-api/api/IccTimeTableApi.js.map +1 -1
  54. package/icc-api/api/IccTopicApi.d.ts +90 -0
  55. package/icc-api/api/IccTopicApi.js +193 -0
  56. package/icc-api/api/IccTopicApi.js.map +1 -0
  57. package/icc-api/index.d.ts +2 -0
  58. package/icc-api/index.js +2 -0
  59. package/icc-api/index.js.map +1 -1
  60. package/icc-api/model/AbstractFilterMessage.d.ts +15 -0
  61. package/icc-api/model/AbstractFilterMessage.js +21 -0
  62. package/icc-api/model/AbstractFilterMessage.js.map +1 -0
  63. package/icc-api/model/AbstractFilterTopic.d.ts +15 -0
  64. package/icc-api/model/AbstractFilterTopic.js +21 -0
  65. package/icc-api/model/AbstractFilterTopic.js.map +1 -0
  66. package/icc-api/model/AccessLog.d.ts +2 -0
  67. package/icc-api/model/AccessLog.js.map +1 -1
  68. package/icc-api/model/Article.d.ts +2 -0
  69. package/icc-api/model/Article.js.map +1 -1
  70. package/icc-api/model/CalendarItem.d.ts +2 -0
  71. package/icc-api/model/CalendarItem.js.map +1 -1
  72. package/icc-api/model/Classification.d.ts +2 -0
  73. package/icc-api/model/Classification.js.map +1 -1
  74. package/icc-api/model/ClassificationTemplate.d.ts +2 -0
  75. package/icc-api/model/ClassificationTemplate.js.map +1 -1
  76. package/icc-api/model/Connection.d.ts +1 -1
  77. package/icc-api/model/Connection.js.map +1 -1
  78. package/icc-api/model/Contact.d.ts +2 -0
  79. package/icc-api/model/Contact.js.map +1 -1
  80. package/icc-api/model/Device.d.ts +4 -4
  81. package/icc-api/model/Device.js.map +1 -1
  82. package/icc-api/model/Document.d.ts +2 -0
  83. package/icc-api/model/Document.js.map +1 -1
  84. package/icc-api/model/ExchangeDataMapCreationBatch.d.ts +13 -0
  85. package/icc-api/model/ExchangeDataMapCreationBatch.js +10 -0
  86. package/icc-api/model/ExchangeDataMapCreationBatch.js.map +1 -0
  87. package/icc-api/model/FilterChainMessage.d.ts +19 -0
  88. package/icc-api/model/FilterChainMessage.js +11 -0
  89. package/icc-api/model/FilterChainMessage.js.map +1 -0
  90. package/icc-api/model/FilterChainTopic.d.ts +19 -0
  91. package/icc-api/model/FilterChainTopic.js +11 -0
  92. package/icc-api/model/FilterChainTopic.js.map +1 -0
  93. package/icc-api/model/Form.d.ts +2 -0
  94. package/icc-api/model/Form.js.map +1 -1
  95. package/icc-api/model/HealthElement.d.ts +2 -0
  96. package/icc-api/model/HealthElement.js.map +1 -1
  97. package/icc-api/model/HealthcareParty.d.ts +2 -2
  98. package/icc-api/model/HealthcareParty.js +13 -1
  99. package/icc-api/model/HealthcareParty.js.map +1 -1
  100. package/icc-api/model/IcureStub.d.ts +2 -0
  101. package/icc-api/model/IcureStub.js.map +1 -1
  102. package/icc-api/model/Invoice.d.ts +2 -0
  103. package/icc-api/model/Invoice.js.map +1 -1
  104. package/icc-api/model/MaintenanceTask.d.ts +13 -10
  105. package/icc-api/model/MaintenanceTask.js +13 -11
  106. package/icc-api/model/MaintenanceTask.js.map +1 -1
  107. package/icc-api/model/Message.d.ts +2 -0
  108. package/icc-api/model/Message.js.map +1 -1
  109. package/icc-api/model/PaginatedListExchangeData.d.ts +9 -0
  110. package/icc-api/model/PaginatedListExchangeData.js +10 -0
  111. package/icc-api/model/PaginatedListExchangeData.js.map +1 -0
  112. package/icc-api/model/PaginatedListTopic.d.ts +20 -0
  113. package/icc-api/model/PaginatedListTopic.js +10 -0
  114. package/icc-api/model/PaginatedListTopic.js.map +1 -0
  115. package/icc-api/model/Patient.d.ts +4 -2
  116. package/icc-api/model/Patient.js.map +1 -1
  117. package/icc-api/model/PatientByHcPartyGenderEducationProfession.d.ts +31 -0
  118. package/icc-api/model/PatientByHcPartyGenderEducationProfession.js +32 -0
  119. package/icc-api/model/PatientByHcPartyGenderEducationProfession.js.map +1 -0
  120. package/icc-api/model/Receipt.d.ts +2 -0
  121. package/icc-api/model/Receipt.js.map +1 -1
  122. package/icc-api/model/SecureDelegation.d.ts +52 -0
  123. package/icc-api/model/SecureDelegation.js +16 -0
  124. package/icc-api/model/SecureDelegation.js.map +1 -0
  125. package/icc-api/model/SecurityMetadata.d.ts +33 -0
  126. package/icc-api/model/SecurityMetadata.js +13 -0
  127. package/icc-api/model/SecurityMetadata.js.map +1 -0
  128. package/icc-api/model/Service.d.ts +2 -0
  129. package/icc-api/model/Service.js.map +1 -1
  130. package/icc-api/model/TimeTable.d.ts +2 -0
  131. package/icc-api/model/TimeTable.js.map +1 -1
  132. package/icc-api/model/Topic.d.ts +95 -0
  133. package/icc-api/model/Topic.js +16 -0
  134. package/icc-api/model/Topic.js.map +1 -0
  135. package/icc-api/model/internal/ExchangeData.d.ts +64 -0
  136. package/icc-api/model/internal/ExchangeData.js +15 -0
  137. package/icc-api/model/internal/ExchangeData.js.map +1 -0
  138. package/icc-api/model/internal/ExchangeDataMap.d.ts +24 -0
  139. package/icc-api/model/internal/ExchangeDataMap.js +13 -0
  140. package/icc-api/model/internal/ExchangeDataMap.js.map +1 -0
  141. package/icc-api/model/internal/SecureDelegationKeyMap.d.ts +14 -0
  142. package/icc-api/model/internal/SecureDelegationKeyMap.js +13 -0
  143. package/icc-api/model/internal/SecureDelegationKeyMap.js.map +1 -0
  144. package/icc-api/model/models.d.ts +26 -40
  145. package/icc-api/model/models.js +19 -37
  146. package/icc-api/model/models.js.map +1 -1
  147. package/icc-api/model/requests/EntityBulkShareResult.d.ts +28 -0
  148. package/icc-api/model/requests/EntityBulkShareResult.js +16 -0
  149. package/icc-api/model/requests/EntityBulkShareResult.js.map +1 -0
  150. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.d.ts +10 -0
  151. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.js +17 -0
  152. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.js.map +1 -0
  153. package/icc-api/model/requests/EntityShareRequest.d.ts +110 -0
  154. package/icc-api/model/requests/EntityShareRequest.js +63 -0
  155. package/icc-api/model/requests/EntityShareRequest.js.map +1 -0
  156. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.d.ts +54 -0
  157. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.js +24 -0
  158. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.js.map +1 -0
  159. package/icc-api/model/requests/MinimalEntityBulkShareResult.d.ts +23 -0
  160. package/icc-api/model/requests/MinimalEntityBulkShareResult.js +13 -0
  161. package/icc-api/model/requests/MinimalEntityBulkShareResult.js.map +1 -0
  162. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.d.ts +21 -0
  163. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.js +14 -0
  164. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.js.map +1 -0
  165. package/icc-x-api/basexapi/EncryptedEntityXApi.d.ts +55 -6
  166. package/icc-x-api/basexapi/EncryptedEntityXApi.js.map +1 -1
  167. package/icc-x-api/crypto/AES.js +1 -1
  168. package/icc-x-api/crypto/AES.js.map +1 -1
  169. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.d.ts +18 -0
  170. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.js +50 -0
  171. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.js.map +1 -0
  172. package/icc-x-api/crypto/AccessControlSecretUtils.d.ts +43 -0
  173. package/icc-x-api/crypto/AccessControlSecretUtils.js +97 -0
  174. package/icc-x-api/crypto/AccessControlSecretUtils.js.map +1 -0
  175. package/icc-x-api/crypto/BaseExchangeDataManager.d.ts +146 -0
  176. package/icc-x-api/crypto/BaseExchangeDataManager.js +342 -0
  177. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -0
  178. package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +0 -18
  179. package/icc-x-api/crypto/BaseExchangeKeysManager.js +11 -85
  180. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
  181. package/icc-x-api/crypto/ConfidentialEntities.d.ts +26 -16
  182. package/icc-x-api/crypto/ConfidentialEntities.js +30 -17
  183. package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -1
  184. package/icc-x-api/crypto/CryptoStrategies.d.ts +8 -1
  185. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -1
  186. package/icc-x-api/crypto/DelegationsDeAnonymization.d.ts +44 -0
  187. package/icc-x-api/crypto/DelegationsDeAnonymization.js +235 -0
  188. package/icc-x-api/crypto/DelegationsDeAnonymization.js.map +1 -0
  189. package/icc-x-api/crypto/ExchangeDataManager.d.ts +97 -0
  190. package/icc-x-api/crypto/ExchangeDataManager.js +501 -0
  191. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -0
  192. package/icc-x-api/crypto/ExchangeDataMapManager.d.ts +32 -0
  193. package/icc-x-api/crypto/ExchangeDataMapManager.js +70 -0
  194. package/icc-x-api/crypto/ExchangeDataMapManager.js.map +1 -0
  195. package/icc-x-api/crypto/ExchangeKeysManager.d.ts +4 -16
  196. package/icc-x-api/crypto/ExchangeKeysManager.js +4 -62
  197. package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -1
  198. package/icc-x-api/crypto/ExtendedApisUtils.d.ts +326 -0
  199. package/icc-x-api/crypto/ExtendedApisUtils.js +3 -0
  200. package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -0
  201. package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +174 -0
  202. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +559 -0
  203. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -0
  204. package/icc-x-api/crypto/KeyRecovery.d.ts +5 -2
  205. package/icc-x-api/crypto/KeyRecovery.js +59 -29
  206. package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
  207. package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +7 -2
  208. package/icc-x-api/crypto/LegacyCryptoStrategies.js +8 -1
  209. package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -1
  210. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.d.ts +33 -0
  211. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js +141 -0
  212. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js.map +1 -0
  213. package/icc-x-api/crypto/RSA.d.ts +34 -8
  214. package/icc-x-api/crypto/RSA.js +80 -13
  215. package/icc-x-api/crypto/RSA.js.map +1 -1
  216. package/icc-x-api/crypto/SecureDelegationsEncryption.d.ts +54 -0
  217. package/icc-x-api/crypto/SecureDelegationsEncryption.js +178 -0
  218. package/icc-x-api/crypto/SecureDelegationsEncryption.js.map +1 -0
  219. package/icc-x-api/crypto/SecureDelegationsManager.d.ts +66 -0
  220. package/icc-x-api/crypto/SecureDelegationsManager.js +261 -0
  221. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -0
  222. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.d.ts +46 -0
  223. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js +312 -0
  224. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js.map +1 -0
  225. package/icc-x-api/crypto/SecurityMetadataDecryptor.d.ts +97 -0
  226. package/icc-x-api/crypto/SecurityMetadataDecryptor.js +79 -0
  227. package/icc-x-api/crypto/SecurityMetadataDecryptor.js.map +1 -0
  228. package/icc-x-api/crypto/ShamirKeysManager.d.ts +5 -5
  229. package/icc-x-api/crypto/ShamirKeysManager.js +6 -9
  230. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
  231. package/icc-x-api/crypto/TransferKeysManager.d.ts +8 -6
  232. package/icc-x-api/crypto/TransferKeysManager.js +75 -52
  233. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
  234. package/icc-x-api/crypto/{KeyManager.d.ts → UserEncryptionKeysManager.d.ts} +4 -6
  235. package/icc-x-api/crypto/{KeyManager.js → UserEncryptionKeysManager.js} +43 -23
  236. package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -0
  237. package/icc-x-api/crypto/UserSignatureKeysManager.d.ts +26 -0
  238. package/icc-x-api/crypto/UserSignatureKeysManager.js +74 -0
  239. package/icc-x-api/crypto/UserSignatureKeysManager.js.map +1 -0
  240. package/icc-x-api/crypto/utils.d.ts +61 -11
  241. package/icc-x-api/crypto/utils.js +113 -44
  242. package/icc-x-api/crypto/utils.js.map +1 -1
  243. package/icc-x-api/filters/LatestMessageByHcPartyTransportGuidFilter.d.ts +8 -0
  244. package/icc-x-api/filters/LatestMessageByHcPartyTransportGuidFilter.js +13 -0
  245. package/icc-x-api/filters/LatestMessageByHcPartyTransportGuidFilter.js.map +1 -0
  246. package/icc-x-api/filters/MessageByHcPartyFilter.d.ts +7 -0
  247. package/icc-x-api/filters/MessageByHcPartyFilter.js +13 -0
  248. package/icc-x-api/filters/MessageByHcPartyFilter.js.map +1 -0
  249. package/icc-x-api/filters/MessageByHcPartyTransportGuidFilter.d.ts +8 -0
  250. package/icc-x-api/filters/MessageByHcPartyTransportGuidFilter.js +13 -0
  251. package/icc-x-api/filters/MessageByHcPartyTransportGuidFilter.js.map +1 -0
  252. package/icc-x-api/filters/TopicByHcPartyFilter.d.ts +7 -0
  253. package/icc-x-api/filters/TopicByHcPartyFilter.js +13 -0
  254. package/icc-x-api/filters/TopicByHcPartyFilter.js.map +1 -0
  255. package/icc-x-api/filters/TopicByParticipantFilter.d.ts +7 -0
  256. package/icc-x-api/filters/TopicByParticipantFilter.js +13 -0
  257. package/icc-x-api/filters/TopicByParticipantFilter.js.map +1 -0
  258. package/icc-x-api/filters/filters.d.ts +5 -0
  259. package/icc-x-api/filters/filters.js +5 -0
  260. package/icc-x-api/filters/filters.js.map +1 -1
  261. package/icc-x-api/icc-accesslog-x-api.d.ts +49 -12
  262. package/icc-x-api/icc-accesslog-x-api.js +81 -44
  263. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  264. package/icc-x-api/icc-calendar-item-x-api.d.ts +53 -15
  265. package/icc-x-api/icc-calendar-item-x-api.js +105 -51
  266. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  267. package/icc-x-api/icc-classification-x-api.d.ts +47 -10
  268. package/icc-x-api/icc-classification-x-api.js +62 -33
  269. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  270. package/icc-x-api/icc-contact-x-api.d.ts +59 -33
  271. package/icc-x-api/icc-contact-x-api.js +101 -66
  272. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  273. package/icc-x-api/icc-crypto-x-api.d.ts +33 -333
  274. package/icc-x-api/icc-crypto-x-api.js +47 -764
  275. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  276. package/icc-x-api/icc-data-owner-x-api.d.ts +20 -8
  277. package/icc-x-api/icc-data-owner-x-api.js +31 -10
  278. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  279. package/icc-x-api/icc-document-x-api.d.ts +51 -12
  280. package/icc-x-api/icc-document-x-api.js +117 -66
  281. package/icc-x-api/icc-document-x-api.js.map +1 -1
  282. package/icc-x-api/icc-form-x-api.d.ts +48 -11
  283. package/icc-x-api/icc-form-x-api.js +71 -37
  284. package/icc-x-api/icc-form-x-api.js.map +1 -1
  285. package/icc-x-api/icc-hcparty-x-api.d.ts +2 -2
  286. package/icc-x-api/icc-hcparty-x-api.js +3 -3
  287. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  288. package/icc-x-api/icc-helement-x-api.d.ts +59 -20
  289. package/icc-x-api/icc-helement-x-api.js +78 -43
  290. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  291. package/icc-x-api/icc-icure-maintenance-x-api.d.ts +7 -2
  292. package/icc-x-api/icc-icure-maintenance-x-api.js +38 -27
  293. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
  294. package/icc-x-api/icc-invoice-x-api.d.ts +53 -16
  295. package/icc-x-api/icc-invoice-x-api.js +69 -35
  296. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  297. package/icc-x-api/icc-maintenance-task-x-api.d.ts +56 -22
  298. package/icc-x-api/icc-maintenance-task-x-api.js +77 -36
  299. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  300. package/icc-x-api/icc-message-x-api.d.ts +75 -19
  301. package/icc-x-api/icc-message-x-api.js +126 -37
  302. package/icc-x-api/icc-message-x-api.js.map +1 -1
  303. package/icc-x-api/icc-patient-x-api.d.ts +86 -29
  304. package/icc-x-api/icc-patient-x-api.js +318 -379
  305. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  306. package/icc-x-api/icc-receipt-x-api.d.ts +47 -13
  307. package/icc-x-api/icc-receipt-x-api.js +72 -36
  308. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  309. package/icc-x-api/icc-time-table-x-api.d.ts +46 -13
  310. package/icc-x-api/icc-time-table-x-api.js +61 -27
  311. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  312. package/icc-x-api/icc-topic-x-api.d.ts +191 -0
  313. package/icc-x-api/icc-topic-x-api.js +307 -0
  314. package/icc-x-api/icc-topic-x-api.js.map +1 -0
  315. package/icc-x-api/icc-user-x-api.d.ts +2 -2
  316. package/icc-x-api/icc-user-x-api.js +3 -3
  317. package/icc-x-api/icc-user-x-api.js.map +1 -1
  318. package/icc-x-api/index.d.ts +18 -2
  319. package/icc-x-api/index.js +203 -156
  320. package/icc-x-api/index.js.map +1 -1
  321. package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +1 -1
  322. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +2 -0
  323. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +9 -2
  324. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -1
  325. package/icc-x-api/storage/IcureStorageFacade.d.ts +23 -2
  326. package/icc-x-api/storage/IcureStorageFacade.js +36 -2
  327. package/icc-x-api/storage/IcureStorageFacade.js.map +1 -1
  328. package/icc-x-api/storage/KeyStorageFacade.d.ts +12 -0
  329. package/icc-x-api/storage/KeyStorageFacade.js.map +1 -1
  330. package/icc-x-api/storage/KeyStorageImpl.d.ts +2 -0
  331. package/icc-x-api/storage/KeyStorageImpl.js +10 -0
  332. package/icc-x-api/storage/KeyStorageImpl.js.map +1 -1
  333. package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +14 -1
  334. package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -1
  335. package/icc-x-api/utils/EntityWithDelegationTypeName.d.ts +32 -0
  336. package/icc-x-api/utils/EntityWithDelegationTypeName.js +75 -0
  337. package/icc-x-api/utils/EntityWithDelegationTypeName.js.map +1 -0
  338. package/icc-x-api/utils/ShareResult.d.ts +74 -0
  339. package/icc-x-api/utils/ShareResult.js +61 -0
  340. package/icc-x-api/utils/ShareResult.js.map +1 -0
  341. package/icc-x-api/utils/binary-utils.d.ts +1 -0
  342. package/icc-x-api/utils/binary-utils.js +8 -1
  343. package/icc-x-api/utils/binary-utils.js.map +1 -1
  344. package/icc-x-api/utils/collection-utils.d.ts +5 -0
  345. package/icc-x-api/utils/collection-utils.js +26 -1
  346. package/icc-x-api/utils/collection-utils.js.map +1 -1
  347. package/icc-x-api/utils/crypto-utils.d.ts +4 -3
  348. package/icc-x-api/utils/crypto-utils.js +5 -4
  349. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  350. package/icc-x-api/utils/lru-temporised-async-cache.d.ts +26 -3
  351. package/icc-x-api/utils/lru-temporised-async-cache.js +75 -15
  352. package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -1
  353. package/icc-x-api/utils/websocket.d.ts +14 -10
  354. package/icc-x-api/utils/websocket.js +26 -9
  355. package/icc-x-api/utils/websocket.js.map +1 -1
  356. package/index.d.ts +1 -1
  357. package/index.js +3 -1
  358. package/index.js.map +1 -1
  359. package/package.json +2 -3
  360. package/icc-x-api/crypto/EntitiesEncryption.d.ts +0 -275
  361. package/icc-x-api/crypto/EntitiesEncryption.js +0 -734
  362. package/icc-x-api/crypto/EntitiesEncryption.js.map +0 -1
  363. package/icc-x-api/crypto/KeyManager.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-utils.js","sourceRoot":"","sources":["../../../icc-x-api/utils/crypto-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAA4B;AAG5B,wDAA4G;AAC5G,+CAAoC;AACpC,+CAAyC;AAGzC,SAAgB,aAAa,CAAI,cAAmD,EAAE,GAAW,EAAE,IAA0B;IAC3H,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,MAAM,GAAG,CAAC,GAAS,EAAE;YACzB,IAAI;gBACF,OAAO,MAAM,IAAI,EAAE,CAAA;aACpB;oBAAS;gBACR,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;aAC3B;QACH,CAAC,CAAA,CAA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AAG,CAAC,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;iBAClD;aACF;iBAAM;gBACL,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;aAClB;SACF;QACD,IAAI,GAAG,CAAC,aAAa,EAAE;YACrB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,IAAA,wBAAS,EAAC,IAAA,kBAAG,EAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;YACpE,uCAAY,IAAI,GAAK,SAAS,EAAE;SACjC;;YAAM,OAAO,IAAI,CAAA;IACpB,CAAC;CAAA;AA1BD,sCA0BC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,aAAyB;IAChE,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAA;IAClI,OAAO;QACL,UAAU,EAAE,aAAa;QACzB,SAAS,EAAE,SAAS,CAAC,IAAA,qBAAM,EAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;KACtD,CAAA;AACH,CAAC;AAND,4DAMC","sourcesContent":["import * as mm from 'moment'\nimport { Moment } from 'moment'\nimport * as _ from 'lodash'\nimport { a2b, b2a, b64Url2ua, hex2ua, string2ua, ua2b64Url, ua2hex, ua2string } from '../utils/binary-utils'\nimport { pack } from './asn1-packer'\nimport { parseAsn1 } from './asn1-parser'\nimport { KeyPair } from '../crypto/RSA'\n\nexport function notConcurrent<T>(concurrencyMap: { [key: string]: PromiseLike<any> }, key: string, proc: () => PromiseLike<T>): PromiseLike<T> {\n const inFlight = concurrencyMap[key]\n if (!inFlight) {\n const newJob = (async () => {\n try {\n return await proc()\n } finally {\n delete concurrencyMap[key]\n }\n })()\n concurrencyMap[key] = newJob\n return newJob\n } else {\n return concurrencyMap[key].then(() => notConcurrent(concurrencyMap, key, proc))\n }\n}\n\nexport function jwk2pkcs8(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret\n [\n 0x04,\n [\n [\n 0x30,\n [\n [0x02, '00'],\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n [0x02, ua2hex(b64Url2ua(jwk.d))],\n [0x02, ua2hex(b64Url2ua(jwk.p))],\n [0x02, ua2hex(b64Url2ua(jwk.q))],\n [0x02, ua2hex(b64Url2ua(jwk.dp))],\n [0x02, ua2hex(b64Url2ua(jwk.dq))],\n [0x02, ua2hex(b64Url2ua(jwk.qi))],\n ],\n ],\n ],\n ],\n ],\n ])\n}\n\nexport function jwk2spki(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret\n [\n 0x03,\n [\n [\n 0x30,\n [\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n ],\n ],\n ],\n ],\n ],\n ])\n}\n\nexport function spkiToJwk(buf: Uint8Array): { kty: string; alg: string; n: string; e: string; ext: boolean } {\n const asn1 = parseAsn1(new Uint8Array(buf))\n\n var modulus: Uint8Array | undefined = undefined\n var exponent: Uint8Array | undefined = undefined\n if (\n asn1.type === 0x30 &&\n asn1.children?.[0]?.type === 0x30 &&\n asn1.children?.[0]?.children?.[0]?.type === 0x06 &&\n ua2hex(asn1.children?.[0]?.children?.[0]?.value ?? new Uint8Array(0)) === '2a864886f70d010101' // pragma: allowlist secret\n ) {\n modulus = asn1.children?.[1]?.children?.[0]?.children?.[0]?.value\n exponent = asn1.children?.[1]?.children?.[0]?.children?.[1]?.value\n } else if (asn1.type === 0x30 && asn1.children?.[0]?.type === 0x02 && asn1.children?.[1]?.type === 0x02) {\n modulus = asn1.children?.[0]?.value\n exponent = asn1.children?.[1]?.value\n }\n\n if (!modulus || !exponent) {\n throw new Error('Invalid spki format')\n }\n return {\n kty: 'RSA',\n alg: 'RSA-OAEP',\n ext: true,\n n: ua2b64Url(minimalRep(modulus)),\n e: ua2b64Url(minimalRep(exponent)),\n }\n}\n\nexport function pkcs8ToJwk(buf: Uint8Array | ArrayBuffer) {\n const parsed = parseAsn1(new Uint8Array(buf))\n const seq =\n parsed.children?.length === 3 && parsed.children[2].type === 0x04 && parsed.children[2].children?.length === 1\n ? parsed.children[2].children[0]\n : parsed\n return {\n kty: 'RSA',\n n: ua2b64Url(minimalRep(seq.children![1].value as Uint8Array)),\n e: ua2b64Url(minimalRep(seq.children![2].value as Uint8Array)),\n d: ua2b64Url(minimalRep(seq.children![3].value as Uint8Array)),\n p: ua2b64Url(minimalRep(seq.children![4].value as Uint8Array)),\n q: ua2b64Url(minimalRep(seq.children![5].value as Uint8Array)),\n dp: ua2b64Url(minimalRep(seq.children![6].value as Uint8Array)),\n dq: ua2b64Url(minimalRep(seq.children![7].value as Uint8Array)),\n qi: ua2b64Url(minimalRep(seq.children![8].value as Uint8Array)),\n }\n}\n\nfunction minimalRep(b: Uint8Array) {\n let i = 0\n while (b[i] === 0) {\n i++\n }\n return b.slice(i)\n}\n\n/**\n * Provide a view over the given Uint8Array where any trailing null bytes at\n * the end are truncated.\n *\n * This can be used to ignore null bytes at the end of a padded UTF-8 string\n * without needing to copy that string, assuming code point U+0000 is encoded\n * in one null byte according to standards rather than in a multi-byte\n * overlong form.\n */\nexport function truncateTrailingNulls(a: Uint8Array) {\n let end = a.byteLength - 1\n while (a[end] === 0 && end >= 0) {\n end--\n }\n // end is now either the last non-null position in a or -1; in the latter\n // case the returned array will have length 0.\n return a.subarray(0, end + 1)\n}\n\n/**\n *\n * @param buffer1 {Uint8Array}\n * @param buffer2{ Uint8Array}\n * @returns {ArrayBuffer}\n */\nexport function appendBuffer(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBuffer {\n const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)\n tmp.set(new Uint8Array(buffer1), 0)\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength)\n return tmp.buffer as ArrayBuffer\n}\n\n//Convenience methods for dates management\nexport function after(d1: number | null | undefined, d2: number | null | undefined): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || moment(d1)!.isAfter(moment(d2)!)\n}\n\nexport function before(d1: number | null | undefined, d2: number | null | undefined): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || moment(d1)!.isBefore(moment(d2)!)\n}\n\nfunction moment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return mm('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return mm('' + epochOrLongCalendar, 'YYYYMMDDHHmmss')\n } else {\n return mm(epochOrLongCalendar)\n }\n}\n\n/**\n * Configuration for the encryption of an object.\n * @param topLevelFields the fields of the object to encrypt. All the fields will be encrypted in a single encryptedSelf field which is added to the\n * object.\n * @param nestedObjectsKeys the name of fields which are expected to contain a nested object (or undefined). Allows to specify\n */\nexport type EncryptedFieldsManifest = {\n topLevelFields: { fieldName: string; fieldPath: string }[]\n nestedObjectsKeys: {\n [objectFieldName: string]: EncryptedFieldsManifest\n }\n mapsValuesKeys: {\n [mapFieldName: string]: EncryptedFieldsManifest\n }\n arraysValuesKeys: {\n [arrayFieldName: string]: EncryptedFieldsManifest\n }\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n *\n * Parse the encrypted fields configuration for a specific entity type.\n *\n * ## Grammar\n *\n * The grammar for each encrypted field is the following:\n * ```\n * fieldName :=\n * regex([a-zA-Z_][a-zA-Z0-9_]+)\n * encryptedField :=\n * fieldName\n * | fieldName + (\".\" | \".*.\" | \"[].\") + encryptedField\n * ```\n *\n * This grammar allows you to specify the fields to encrypt for the object and recursively for nested objects.\n * - A string containing only a single `fieldName` will encrypt the field with the given name.\n * - A string starting with `fieldName.` allows to specify the encrypted fields of a nested object. The encrypted values of the\n * fields in the nested object will be saved in the nested object.\n * - A string starting with `fieldName.*.` treats `fieldName` as a map/dictionary data structure and allows to specify the encrypted fields of the\n * values of the map. Note that the values of the map must be objects as well. The encrypted content of each map value is stored in that value.\n * - A string starting with `fieldName[].` treats `fieldName` as an array and allows to specify the encrypted fields of the values of the array.\n * Note that the values of the array must be objects as well. The encrypted content of each array element is stored in that element.\n *\n * ## Example\n *\n * Consider the following object and encryption keys:\n * ```javascript\n * const obj = {\n * a: { x: 0, y: 1 },\n * b: \"hello\",\n * c: [ { public: \"a\", secret: \"b\" }, { public: \"c\", secret: \"d\" } ],\n * d: \"ok\",\n * e: {\n * info: \"something\",\n * private: \"secret\",\n * dataMap: {\n * \"en\": {\n * a: 1,\n * b: 2\n * },\n * \"fr\": {\n * a: 3,\n * b: 4\n * }\n * }\n * }\n * }\n * const encryptedFields = [\n * \"a\",\n * \"c[].secret\",\n * \"d\",\n * \"e.private\",\n * \"e.datamap.*.a\"\n * ]\n * ```\n * If you use them with the crypt method you will get the following result:\n * ```json\n * {\n * b: \"hello\",\n * c: [\n * { public: \"a\", encryptedSelf: \"...encrypted data of c[0]\" },\n * { public: \"c\", encryptedSelf: \"...encrypted data of c[1]\" }\n * ],\n * e: {\n * info: \"something\",\n * dataMap: {\n * \"en\": { b: 2, encryptedSelf: \"...encrypted data of e.dataMap['en']\" },\n * \"fr\": { b: 4, encryptedSelf: \"...encrypted data of e.dataMap['fr']\" }\n * },\n * encryptedSelf: \"...encrypted data of e\"\n * },\n * encryptedSelf: \"...encrypted data of obj\"\n * }\n * ```\n *\n * ## Shortened representation\n *\n * You can also group encrypted fields having the same prefix by concatenating to the prefix the JSON representation of an array of all the postfixes.\n * For example the following encrypted fields:\n * ```javascript\n * const encryptedFields = [\"a.b.c.d.e.f1\", \"a.b.c.d.e.f2\", \"a.b.c.d.e.f3\", \"a.b.c.d.e.f4\"]\n * ```\n * can be shortened to\n * ```javascript\n * const encryptedFields = ['a.b.c.d.e.[\"f1\",\"f2\",\"f3\",\"f4\"]'] // Note the use of single quotes to avoid escaping the double quotes\n * ```\n * If you use the shortened representation you may need to escape nested json representations. In that case the use of `JSON.stringify` is\n * recommended.\n *\n * @param encryptedFields\n * @param path\n */\nexport function parseEncryptedFields(encryptedFields: string[], path: string): EncryptedFieldsManifest {\n const groupedData = {\n topLevelFields: new Set<string>(),\n nestedObjectsKeys: {} as { [objectFieldName: string]: string[] },\n mapsValuesKeys: {} as { [mapFieldName: string]: string[] },\n arraysValuesKeys: {} as { [arrayFieldName: string]: string[] },\n }\n const encryptedFieldRegex = /^([_a-zA-Z][_a-zA-Z0-9]*)(?:(\\.\\*\\.|\\[]\\.|\\.)(?:[_a-zA-Z].*|\\[.*]))?$/\n const addSubkeyToGroupedData = (\n currFieldName: string,\n currFieldSeparator: string,\n currEncryptedField: string,\n groupedDataKey: 'nestedObjectsKeys' | 'mapsValuesKeys' | 'arraysValuesKeys'\n ) => {\n const existingOrNew = groupedData[groupedDataKey][currFieldName] ?? (groupedData[groupedDataKey][currFieldName] = [])\n const subKey = currEncryptedField.slice(currFieldName.length + currFieldSeparator.length)\n if (subKey.startsWith('[')) {\n let parsedJson: any[]\n try {\n parsedJson = JSON.parse(subKey)\n } catch {\n throw new Error(`Invalid encrypted field ${path}${currEncryptedField} (not a valid JSON subkey)`)\n }\n if (Array.isArray(parsedJson) && parsedJson.every((x) => typeof x == 'string')) {\n parsedJson.forEach((x) => existingOrNew.push(x))\n } else throw new Error(`Invalid encrypted field ${path}${currEncryptedField} (not an array of strings)`)\n } else {\n existingOrNew.push(subKey)\n }\n }\n for (const currEncryptedField of encryptedFields) {\n const currFieldMatch = currEncryptedField.match(encryptedFieldRegex)\n if (!!currFieldMatch) {\n const currFieldName = currFieldMatch[1]\n const currFieldSeparator = currFieldMatch[2]\n if (!currFieldSeparator) {\n if (groupedData.topLevelFields.has(currFieldName)) throw new Error(`Duplicate encrypted field ${path}${currFieldName}`)\n if (\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.mapsValuesKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n groupedData.topLevelFields.add(currFieldName)\n } else if (currFieldSeparator == '.') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.mapsValuesKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'nestedObjectsKeys')\n } else if (currFieldSeparator == '.*.') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'mapsValuesKeys')\n } else if (currFieldSeparator == '[].') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.mapsValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'arraysValuesKeys')\n } else throw new Error(`Internal error: unknown separator ${currFieldSeparator} passed regex validation in ${path}${currEncryptedField}`)\n } else throw new Error(`Invalid encrypted field ${path}${currEncryptedField}`)\n }\n return {\n topLevelFields: Array.from(groupedData.topLevelFields).map((fieldName) => ({ fieldName, fieldPath: path + fieldName })),\n nestedObjectsKeys: Object.fromEntries(\n Object.entries(groupedData.nestedObjectsKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '.'),\n ])\n ),\n mapsValuesKeys: Object.fromEntries(\n Object.entries(groupedData.mapsValuesKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '.*.'),\n ])\n ),\n arraysValuesKeys: Object.fromEntries(\n Object.entries(groupedData.arraysValuesKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '[].'),\n ])\n ),\n }\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n * Encrypt the object graph recursively. Generally return an updated SHALLOW copy, although some fields may be deep copied if they also needed to be\n * recursively encrypted.\n * @param obj the object to encrypt\n * @param cryptor takes in input an object consisting only of the fields to encrypt of obj, and returns the encrypted object.\n * @param keys the keys to encrypt for the\n * @param path path of the current object, used for error messages.\n * @return a shallow copy of the object with a new encryptedSelfField and without the encrypted fields.\n */\nexport async function encryptObject(\n obj: { [key: string]: any },\n cryptor: (obj: { [key: string]: any }) => Promise<ArrayBuffer>,\n keys: EncryptedFieldsManifest,\n path: string = 'obj'\n): Promise<{ [key: string]: any }> {\n const shallowClone = { ...obj }\n const currEncryptedFields: { [key: string]: any } = {}\n for (const { fieldName } of keys.topLevelFields) {\n const fieldValue = shallowClone[fieldName]\n if (fieldValue !== undefined) {\n // we keep null values\n currEncryptedFields[fieldName] = fieldValue\n delete shallowClone[fieldName]\n }\n }\n shallowClone['encryptedSelf'] = b2a(ua2string(await cryptor(currEncryptedFields)))\n for (const [fieldName, subKeys] of Object.entries(keys.nestedObjectsKeys)) {\n const fieldValue = shallowClone[fieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!isPojo(fieldValue)) throw new Error(`Expected field ${path}.${fieldName} to be a non-array object`)\n shallowClone[fieldName] = await encryptObject(fieldValue, cryptor, subKeys, path + '.' + fieldName)\n }\n }\n for (const [mapFieldName, subKeys] of Object.entries(keys.mapsValuesKeys)) {\n const fieldValue = shallowClone[mapFieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!isPojo(fieldValue)) throw new Error(`Expected field ${path}.${mapFieldName} to be a non-array object`)\n const newMap: { [key: string]: any } = {}\n for (const [key, value] of Object.entries(fieldValue as object)) {\n if (value === null || value === undefined) {\n newMap[key] = value\n } else {\n if (!isPojo(value)) throw new Error(`Expected field ${path}.${mapFieldName}.${key} to be a non-array object`)\n newMap[key] = await encryptObject(value, cryptor, subKeys, path + '.' + mapFieldName + '.' + key)\n }\n }\n shallowClone[mapFieldName] = newMap\n }\n }\n for (const [arrayFieldName, subKeys] of Object.entries(keys.arraysValuesKeys)) {\n const fieldValue = shallowClone[arrayFieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!Array.isArray(fieldValue)) throw new Error(`Expected field ${path}.${arrayFieldName} to be an array`)\n const newArray: any[] = Array(fieldValue.length)\n for (let i = 0; i < fieldValue.length; i++) {\n const value = fieldValue[i]\n if (value === null || value === undefined) {\n newArray[i] = value\n } else {\n if (!isPojo(value)) throw new Error(`Expected field ${path}.${arrayFieldName}[${i}] to be a non-array object`)\n newArray[i] = await encryptObject(value, cryptor, subKeys, path + '.' + arrayFieldName + '[' + i + ']')\n }\n }\n shallowClone[arrayFieldName] = newArray\n }\n }\n return shallowClone\n}\n\n/**\n * Check if value is a non-null object that is not an array.\n */\nfunction isPojo(value: any): boolean {\n // This break if for some reason we have object versions of String/Number/Boolean\n return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof ArrayBuffer) && !ArrayBuffer.isView(value)\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n * Decrypt object graph recursively.\n *\n * @param obj the object to decrypt\n * @param decryptor the decryptor function (returns a promise)\n * @return a deep copy of the object with the decrypted fields and removed encryptedSelf field\n */\nexport async function decryptObject(\n obj: { [key: string]: any },\n decryptor: (obj: Uint8Array) => Promise<{ [key: string]: any }>\n): Promise<{ [key: string]: any }> {\n const copy: { [key: string]: any } = {}\n for (const [key, value] of Object.entries(obj)) {\n if (key === 'encryptedSelf') {\n copy[key] = value\n } else if (typeof value === 'object' && value !== null) {\n if (Array.isArray(value)) {\n // Note: nested arrays (and primitives) are returned as is and not they are not recursively decrypted. This is because we currently do not\n // support encryption of elements from arrays in arrays (we only support arrays in objects in arrays). In future this may change.\n copy[key] = await Promise.all(value.map((v) => (isPojo(v) ? decryptObject(v, decryptor) : v)))\n } else if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {\n copy[key] = value // No direct decryption of array buffer data. Array buffer should be converted to b64 string and encrypted as json data.\n } else {\n copy[key] = await decryptObject(value, decryptor)\n }\n } else {\n copy[key] = value\n }\n }\n if (obj.encryptedSelf) {\n const decrypted = await decryptor(string2ua(a2b(obj.encryptedSelf)))\n return { ...copy, ...decrypted }\n } else return copy\n}\n\n/**\n * Extracts the full jwk key pair from the jwk representation of the private key.\n * @param privateKeyJwk private key in jwk representation\n * @throws if the key is missing the public modulus or public exponent.\n */\nexport function keyPairFromPrivateKeyJwk(privateKeyJwk: JsonWebKey): KeyPair<JsonWebKey> {\n if (!privateKeyJwk.n || !privateKeyJwk.e) throw new Error('Incomplete private JsonWebKey: missing public modulus and/or exponent')\n return {\n privateKey: privateKeyJwk,\n publicKey: spkiToJwk(hex2ua(jwk2spki(privateKeyJwk))),\n }\n}\n"]}
1
+ {"version":3,"file":"crypto-utils.js","sourceRoot":"","sources":["../../../icc-x-api/utils/crypto-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAA4B;AAG5B,wDAA4G;AAC5G,+CAAoC;AACpC,+CAAyC;AAGzC,SAAgB,aAAa,CAAI,cAAmD,EAAE,GAAW,EAAE,IAA0B;IAC3H,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,MAAM,GAAG,CAAC,GAAS,EAAE;YACzB,IAAI;gBACF,OAAO,MAAM,IAAI,EAAE,CAAA;aACpB;oBAAS;gBACR,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;aAC3B;QACH,CAAC,CAAA,CAAC,EAAE,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,GAAG,KAAK,CAAA,CAAC,wHAAwH;iBAC3I;qBAAM;oBACL,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;iBAClD;aACF;iBAAM;gBACL,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;aAClB;SACF;QACD,IAAI,GAAG,CAAC,aAAa,EAAE;YACrB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,IAAA,wBAAS,EAAC,IAAA,kBAAG,EAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;YACpE,uCAAY,IAAI,GAAK,SAAS,EAAE;SACjC;;YAAM,OAAO,IAAI,CAAA;IACpB,CAAC;CAAA;AA1BD,sCA0BC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,aAAyB,EAAE,UAAsB;IACxF,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAA;IAClI,OAAO;QACL,UAAU,EAAE,aAAa;QACzB,SAAS,EAAE,SAAS,CAAC,IAAA,qBAAM,EAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,EAAE,UAAU,CAAC;KAClE,CAAA;AACH,CAAC;AAND,4DAMC","sourcesContent":["import * as mm from 'moment'\nimport { Moment } from 'moment'\nimport * as _ from 'lodash'\nimport { a2b, b2a, b64Url2ua, hex2ua, string2ua, ua2b64Url, ua2hex, ua2string } from '../utils/binary-utils'\nimport { pack } from './asn1-packer'\nimport { parseAsn1 } from './asn1-parser'\nimport { KeyPair, ShaVersion } from '../crypto/RSA'\n\nexport function notConcurrent<T>(concurrencyMap: { [key: string]: PromiseLike<any> }, key: string, proc: () => PromiseLike<T>): PromiseLike<T> {\n const inFlight = concurrencyMap[key]\n if (!inFlight) {\n const newJob = (async () => {\n try {\n return await proc()\n } finally {\n delete concurrencyMap[key]\n }\n })()\n concurrencyMap[key] = newJob\n return newJob\n } else {\n return concurrencyMap[key].then(() => notConcurrent(concurrencyMap, key, proc))\n }\n}\n\nexport function jwk2pkcs8(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret\n [\n 0x04,\n [\n [\n 0x30,\n [\n [0x02, '00'],\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n [0x02, ua2hex(b64Url2ua(jwk.d))],\n [0x02, ua2hex(b64Url2ua(jwk.p))],\n [0x02, ua2hex(b64Url2ua(jwk.q))],\n [0x02, ua2hex(b64Url2ua(jwk.dp))],\n [0x02, ua2hex(b64Url2ua(jwk.dq))],\n [0x02, ua2hex(b64Url2ua(jwk.qi))],\n ],\n ],\n ],\n ],\n ],\n ])\n}\n\nexport function jwk2spki(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret\n [\n 0x03,\n [\n [\n 0x30,\n [\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n ],\n ],\n ],\n ],\n ],\n ])\n}\n\nexport function spkiToJwk(buf: Uint8Array, shaVersion: ShaVersion): { kty: string; alg: string; n: string; e: string; ext: boolean } {\n const asn1 = parseAsn1(new Uint8Array(buf))\n\n var modulus: Uint8Array | undefined = undefined\n var exponent: Uint8Array | undefined = undefined\n if (\n asn1.type === 0x30 &&\n asn1.children?.[0]?.type === 0x30 &&\n asn1.children?.[0]?.children?.[0]?.type === 0x06 &&\n ua2hex(asn1.children?.[0]?.children?.[0]?.value ?? new Uint8Array(0)) === '2a864886f70d010101' // pragma: allowlist secret\n ) {\n modulus = asn1.children?.[1]?.children?.[0]?.children?.[0]?.value\n exponent = asn1.children?.[1]?.children?.[0]?.children?.[1]?.value\n } else if (asn1.type === 0x30 && asn1.children?.[0]?.type === 0x02 && asn1.children?.[1]?.type === 0x02) {\n modulus = asn1.children?.[0]?.value\n exponent = asn1.children?.[1]?.value\n }\n\n if (!modulus || !exponent) {\n throw new Error('Invalid spki format')\n }\n return {\n kty: 'RSA',\n alg: shaVersion === 'sha-256' ? 'RSA-OAEP-256' : 'RSA-OAEP',\n ext: true,\n n: ua2b64Url(minimalRep(modulus)),\n e: ua2b64Url(minimalRep(exponent)),\n }\n}\n\nexport function pkcs8ToJwk(buf: Uint8Array | ArrayBuffer) {\n const parsed = parseAsn1(new Uint8Array(buf))\n const seq =\n parsed.children?.length === 3 && parsed.children[2].type === 0x04 && parsed.children[2].children?.length === 1\n ? parsed.children[2].children[0]\n : parsed\n return {\n kty: 'RSA',\n n: ua2b64Url(minimalRep(seq.children![1].value as Uint8Array)),\n e: ua2b64Url(minimalRep(seq.children![2].value as Uint8Array)),\n d: ua2b64Url(minimalRep(seq.children![3].value as Uint8Array)),\n p: ua2b64Url(minimalRep(seq.children![4].value as Uint8Array)),\n q: ua2b64Url(minimalRep(seq.children![5].value as Uint8Array)),\n dp: ua2b64Url(minimalRep(seq.children![6].value as Uint8Array)),\n dq: ua2b64Url(minimalRep(seq.children![7].value as Uint8Array)),\n qi: ua2b64Url(minimalRep(seq.children![8].value as Uint8Array)),\n }\n}\n\nfunction minimalRep(b: Uint8Array) {\n let i = 0\n while (b[i] === 0) {\n i++\n }\n return b.slice(i)\n}\n\n/**\n * Provide a view over the given Uint8Array where any trailing null bytes at\n * the end are truncated.\n *\n * This can be used to ignore null bytes at the end of a padded UTF-8 string\n * without needing to copy that string, assuming code point U+0000 is encoded\n * in one null byte according to standards rather than in a multi-byte\n * overlong form.\n */\nexport function truncateTrailingNulls(a: Uint8Array) {\n let end = a.byteLength - 1\n while (a[end] === 0 && end >= 0) {\n end--\n }\n // end is now either the last non-null position in a or -1; in the latter\n // case the returned array will have length 0.\n return a.subarray(0, end + 1)\n}\n\n/**\n *\n * @param buffer1 {Uint8Array}\n * @param buffer2{ Uint8Array}\n * @returns {ArrayBuffer}\n */\nexport function appendBuffer(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBuffer {\n const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)\n tmp.set(new Uint8Array(buffer1), 0)\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength)\n return tmp.buffer as ArrayBuffer\n}\n\n//Convenience methods for dates management\nexport function after(d1: number | null | undefined, d2: number | null | undefined): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || moment(d1)!.isAfter(moment(d2)!)\n}\n\nexport function before(d1: number | null | undefined, d2: number | null | undefined): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || moment(d1)!.isBefore(moment(d2)!)\n}\n\nfunction moment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return mm('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return mm('' + epochOrLongCalendar, 'YYYYMMDDHHmmss')\n } else {\n return mm(epochOrLongCalendar)\n }\n}\n\n/**\n * Configuration for the encryption of an object.\n * @param topLevelFields the fields of the object to encrypt. All the fields will be encrypted in a single encryptedSelf field which is added to the\n * object.\n * @param nestedObjectsKeys the name of fields which are expected to contain a nested object (or undefined). Allows to specify\n */\nexport type EncryptedFieldsManifest = {\n topLevelFields: { fieldName: string; fieldPath: string }[]\n nestedObjectsKeys: {\n [objectFieldName: string]: EncryptedFieldsManifest\n }\n mapsValuesKeys: {\n [mapFieldName: string]: EncryptedFieldsManifest\n }\n arraysValuesKeys: {\n [arrayFieldName: string]: EncryptedFieldsManifest\n }\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n *\n * Parse the encrypted fields configuration for a specific entity type.\n *\n * ## Grammar\n *\n * The grammar for each encrypted field is the following:\n * ```\n * fieldName :=\n * regex([a-zA-Z_][a-zA-Z0-9_]+)\n * encryptedField :=\n * fieldName\n * | fieldName + (\".\" | \".*.\" | \"[].\") + encryptedField\n * ```\n *\n * This grammar allows you to specify the fields to encrypt for the object and recursively for nested objects.\n * - A string containing only a single `fieldName` will encrypt the field with the given name.\n * - A string starting with `fieldName.` allows to specify the encrypted fields of a nested object. The encrypted values of the\n * fields in the nested object will be saved in the nested object.\n * - A string starting with `fieldName.*.` treats `fieldName` as a map/dictionary data structure and allows to specify the encrypted fields of the\n * values of the map. Note that the values of the map must be objects as well. The encrypted content of each map value is stored in that value.\n * - A string starting with `fieldName[].` treats `fieldName` as an array and allows to specify the encrypted fields of the values of the array.\n * Note that the values of the array must be objects as well. The encrypted content of each array element is stored in that element.\n *\n * ## Example\n *\n * Consider the following object and encryption keys:\n * ```javascript\n * const obj = {\n * a: { x: 0, y: 1 },\n * b: \"hello\",\n * c: [ { public: \"a\", secret: \"b\" }, { public: \"c\", secret: \"d\" } ],\n * d: \"ok\",\n * e: {\n * info: \"something\",\n * private: \"secret\",\n * dataMap: {\n * \"en\": {\n * a: 1,\n * b: 2\n * },\n * \"fr\": {\n * a: 3,\n * b: 4\n * }\n * }\n * }\n * }\n * const encryptedFields = [\n * \"a\",\n * \"c[].secret\",\n * \"d\",\n * \"e.private\",\n * \"e.datamap.*.a\"\n * ]\n * ```\n * If you use them with the crypt method you will get the following result:\n * ```json\n * {\n * b: \"hello\",\n * c: [\n * { public: \"a\", encryptedSelf: \"...encrypted data of c[0]\" },\n * { public: \"c\", encryptedSelf: \"...encrypted data of c[1]\" }\n * ],\n * e: {\n * info: \"something\",\n * dataMap: {\n * \"en\": { b: 2, encryptedSelf: \"...encrypted data of e.dataMap['en']\" },\n * \"fr\": { b: 4, encryptedSelf: \"...encrypted data of e.dataMap['fr']\" }\n * },\n * encryptedSelf: \"...encrypted data of e\"\n * },\n * encryptedSelf: \"...encrypted data of obj\"\n * }\n * ```\n *\n * ## Shortened representation\n *\n * You can also group encrypted fields having the same prefix by concatenating to the prefix the JSON representation of an array of all the postfixes.\n * For example the following encrypted fields:\n * ```javascript\n * const encryptedFields = [\"a.b.c.d.e.f1\", \"a.b.c.d.e.f2\", \"a.b.c.d.e.f3\", \"a.b.c.d.e.f4\"]\n * ```\n * can be shortened to\n * ```javascript\n * const encryptedFields = ['a.b.c.d.e.[\"f1\",\"f2\",\"f3\",\"f4\"]'] // Note the use of single quotes to avoid escaping the double quotes\n * ```\n * If you use the shortened representation you may need to escape nested json representations. In that case the use of `JSON.stringify` is\n * recommended.\n *\n * @param encryptedFields\n * @param path\n */\nexport function parseEncryptedFields(encryptedFields: string[], path: string): EncryptedFieldsManifest {\n const groupedData = {\n topLevelFields: new Set<string>(),\n nestedObjectsKeys: {} as { [objectFieldName: string]: string[] },\n mapsValuesKeys: {} as { [mapFieldName: string]: string[] },\n arraysValuesKeys: {} as { [arrayFieldName: string]: string[] },\n }\n const encryptedFieldRegex = /^([_a-zA-Z][_a-zA-Z0-9]*)(?:(\\.\\*\\.|\\[]\\.|\\.)(?:[_a-zA-Z].*|\\[.*]))?$/\n const addSubkeyToGroupedData = (\n currFieldName: string,\n currFieldSeparator: string,\n currEncryptedField: string,\n groupedDataKey: 'nestedObjectsKeys' | 'mapsValuesKeys' | 'arraysValuesKeys'\n ) => {\n const existingOrNew = groupedData[groupedDataKey][currFieldName] ?? (groupedData[groupedDataKey][currFieldName] = [])\n const subKey = currEncryptedField.slice(currFieldName.length + currFieldSeparator.length)\n if (subKey.startsWith('[')) {\n let parsedJson: any[]\n try {\n parsedJson = JSON.parse(subKey)\n } catch {\n throw new Error(`Invalid encrypted field ${path}${currEncryptedField} (not a valid JSON subkey)`)\n }\n if (Array.isArray(parsedJson) && parsedJson.every((x) => typeof x == 'string')) {\n parsedJson.forEach((x) => existingOrNew.push(x))\n } else throw new Error(`Invalid encrypted field ${path}${currEncryptedField} (not an array of strings)`)\n } else {\n existingOrNew.push(subKey)\n }\n }\n for (const currEncryptedField of encryptedFields) {\n const currFieldMatch = currEncryptedField.match(encryptedFieldRegex)\n if (!!currFieldMatch) {\n const currFieldName = currFieldMatch[1]\n const currFieldSeparator = currFieldMatch[2]\n if (!currFieldSeparator) {\n if (groupedData.topLevelFields.has(currFieldName)) throw new Error(`Duplicate encrypted field ${path}${currFieldName}`)\n if (\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.mapsValuesKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n groupedData.topLevelFields.add(currFieldName)\n } else if (currFieldSeparator == '.') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.mapsValuesKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'nestedObjectsKeys')\n } else if (currFieldSeparator == '.*.') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'mapsValuesKeys')\n } else if (currFieldSeparator == '[].') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.mapsValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'arraysValuesKeys')\n } else throw new Error(`Internal error: unknown separator ${currFieldSeparator} passed regex validation in ${path}${currEncryptedField}`)\n } else throw new Error(`Invalid encrypted field ${path}${currEncryptedField}`)\n }\n return {\n topLevelFields: Array.from(groupedData.topLevelFields).map((fieldName) => ({ fieldName, fieldPath: path + fieldName })),\n nestedObjectsKeys: Object.fromEntries(\n Object.entries(groupedData.nestedObjectsKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '.'),\n ])\n ),\n mapsValuesKeys: Object.fromEntries(\n Object.entries(groupedData.mapsValuesKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '.*.'),\n ])\n ),\n arraysValuesKeys: Object.fromEntries(\n Object.entries(groupedData.arraysValuesKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '[].'),\n ])\n ),\n }\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n * Encrypt the object graph recursively. Generally return an updated SHALLOW copy, although some fields may be deep copied if they also needed to be\n * recursively encrypted.\n * @param obj the object to encrypt\n * @param cryptor takes in input an object consisting only of the fields to encrypt of obj, and returns the encrypted object.\n * @param keys the keys to encrypt for the\n * @param path path of the current object, used for error messages.\n * @return a shallow copy of the object with a new encryptedSelfField and without the encrypted fields.\n */\nexport async function encryptObject(\n obj: { [key: string]: any },\n cryptor: (obj: { [key: string]: any }) => Promise<ArrayBuffer>,\n keys: EncryptedFieldsManifest,\n path: string = 'obj'\n): Promise<{ [key: string]: any }> {\n const shallowClone = { ...obj }\n const currEncryptedFields: { [key: string]: any } = {}\n for (const { fieldName } of keys.topLevelFields) {\n const fieldValue = shallowClone[fieldName]\n if (fieldValue !== undefined) {\n // we keep null values\n currEncryptedFields[fieldName] = fieldValue\n delete shallowClone[fieldName]\n }\n }\n shallowClone['encryptedSelf'] = b2a(ua2string(await cryptor(currEncryptedFields)))\n for (const [fieldName, subKeys] of Object.entries(keys.nestedObjectsKeys)) {\n const fieldValue = shallowClone[fieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!isPojo(fieldValue)) throw new Error(`Expected field ${path}.${fieldName} to be a non-array object`)\n shallowClone[fieldName] = await encryptObject(fieldValue, cryptor, subKeys, path + '.' + fieldName)\n }\n }\n for (const [mapFieldName, subKeys] of Object.entries(keys.mapsValuesKeys)) {\n const fieldValue = shallowClone[mapFieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!isPojo(fieldValue)) throw new Error(`Expected field ${path}.${mapFieldName} to be a non-array object`)\n const newMap: { [key: string]: any } = {}\n for (const [key, value] of Object.entries(fieldValue as object)) {\n if (value === null || value === undefined) {\n newMap[key] = value\n } else {\n if (!isPojo(value)) throw new Error(`Expected field ${path}.${mapFieldName}.${key} to be a non-array object`)\n newMap[key] = await encryptObject(value, cryptor, subKeys, path + '.' + mapFieldName + '.' + key)\n }\n }\n shallowClone[mapFieldName] = newMap\n }\n }\n for (const [arrayFieldName, subKeys] of Object.entries(keys.arraysValuesKeys)) {\n const fieldValue = shallowClone[arrayFieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!Array.isArray(fieldValue)) throw new Error(`Expected field ${path}.${arrayFieldName} to be an array`)\n const newArray: any[] = Array(fieldValue.length)\n for (let i = 0; i < fieldValue.length; i++) {\n const value = fieldValue[i]\n if (value === null || value === undefined) {\n newArray[i] = value\n } else {\n if (!isPojo(value)) throw new Error(`Expected field ${path}.${arrayFieldName}[${i}] to be a non-array object`)\n newArray[i] = await encryptObject(value, cryptor, subKeys, path + '.' + arrayFieldName + '[' + i + ']')\n }\n }\n shallowClone[arrayFieldName] = newArray\n }\n }\n return shallowClone\n}\n\n/**\n * Check if value is a non-null object that is not an array.\n */\nfunction isPojo(value: any): boolean {\n // This break if for some reason we have object versions of String/Number/Boolean\n return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof ArrayBuffer) && !ArrayBuffer.isView(value)\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n * Decrypt object graph recursively.\n *\n * @param obj the object to decrypt\n * @param decryptor the decryptor function (returns a promise)\n * @return a deep copy of the object with the decrypted fields and removed encryptedSelf field\n */\nexport async function decryptObject(\n obj: { [key: string]: any },\n decryptor: (obj: Uint8Array) => Promise<{ [key: string]: any }>\n): Promise<{ [key: string]: any }> {\n const copy: { [key: string]: any } = {}\n for (const [key, value] of Object.entries(obj)) {\n if (key === 'encryptedSelf') {\n copy[key] = value\n } else if (typeof value === 'object' && value !== null) {\n if (Array.isArray(value)) {\n // Note: nested arrays (and primitives) are returned as is and not they are not recursively decrypted. This is because we currently do not\n // support encryption of elements from arrays in arrays (we only support arrays in objects in arrays). In future this may change.\n copy[key] = await Promise.all(value.map((v) => (isPojo(v) ? decryptObject(v, decryptor) : v)))\n } else if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {\n copy[key] = value // No direct decryption of array buffer data. Array buffer should be converted to b64 string and encrypted as json data.\n } else {\n copy[key] = await decryptObject(value, decryptor)\n }\n } else {\n copy[key] = value\n }\n }\n if (obj.encryptedSelf) {\n const decrypted = await decryptor(string2ua(a2b(obj.encryptedSelf)))\n return { ...copy, ...decrypted }\n } else return copy\n}\n\n/**\n * Extracts the full jwk key pair from the jwk representation of the private key.\n * @param privateKeyJwk private key in jwk representation\n * @param shaVersion the SHA algorithm version\n * @throws if the key is missing the public modulus or public exponent.\n */\nexport function keyPairFromPrivateKeyJwk(privateKeyJwk: JsonWebKey, shaVersion: ShaVersion): KeyPair<JsonWebKey> {\n if (!privateKeyJwk.n || !privateKeyJwk.e) throw new Error('Incomplete private JsonWebKey: missing public modulus and/or exponent')\n return {\n privateKey: privateKeyJwk,\n publicKey: spkiToJwk(hex2ua(jwk2spki(privateKeyJwk)), shaVersion),\n }\n}\n"]}
@@ -4,11 +4,25 @@ export declare class LruTemporisedAsyncCache<K, V> {
4
4
  private readonly nodesMap;
5
5
  private firstNode;
6
6
  private lastNode;
7
+ private sequentialJobId;
7
8
  /**
8
9
  * @param maxCacheSize Maximum size of the cache. Any value <= 0 is considered as no limit.
9
- * @param lifetimeForValue Get the maximum lifetime for an entry given its value.
10
+ * @param lifetimeForValue Get the maximum lifetime for an entry given its value, in milliseconds.
10
11
  */
11
12
  constructor(maxCacheSize: number, lifetimeForValue: (value: V) => number);
13
+ /**
14
+ * Get a value if there is an already cached value or job for the provided key.
15
+ * - If the job is in progress this will return the job promise.
16
+ * - If there is already a cached value returns the value, regardless of whether his lifetime is expired or not.
17
+ * - If there is no job nor cached value this will return undefined.
18
+ * @param key key of the entry
19
+ * @return if there is a cached value or job in progress for the entry returns the item and if its lifetime has expired, otherwise returns
20
+ * undefined.
21
+ */
22
+ getIfCachedJob(key: K): Promise<{
23
+ item: V;
24
+ expired: boolean;
25
+ } | undefined>;
12
26
  /**
13
27
  * Gets a cached value or retrieves it and caches it if the value is not available or if it is available but expired. A value will never be expired
14
28
  * if it was not yet retrieved, even if the retrieved value would be expired according to the {@link additionalExpirationCondition}
@@ -18,10 +32,19 @@ export declare class LruTemporisedAsyncCache<K, V> {
18
32
  * always false by default, meaning the value is not expired if its lifetime didn't already surpass the maximum lifetime.
19
33
  * @return the cached value if present and not expired, else the retrieved value.
20
34
  */
21
- get(key: K, retrieve: (previousValue: V | undefined) => Promise<V>, additionalExpirationCondition?: (value: V) => boolean): Promise<V>;
22
- clear(): void;
35
+ get(key: K, retrieve: (previousValue: V | undefined) => Promise<{
36
+ item: V;
37
+ onEviction?: (isReplacement: boolean) => void;
38
+ }>, additionalExpirationCondition?: (value: V) => boolean): Promise<V>;
39
+ /**
40
+ * Fully empties this cache.
41
+ * @param doOnEvictionOfCleared if true the onEviction triggers for the retrieved and cached data will be executed, otherwise not. onEviction
42
+ * triggers of data for which the retrieval jobs were not completed will automatically be called when the job completes.
43
+ */
44
+ clear(doOnEvictionOfCleared?: boolean): void;
23
45
  private addToTail;
24
46
  private evict;
25
47
  private markUsed;
26
48
  private registerJob;
49
+ private nextJobId;
27
50
  }
@@ -4,15 +4,38 @@ exports.LruTemporisedAsyncCache = void 0;
4
4
  class LruTemporisedAsyncCache {
5
5
  /**
6
6
  * @param maxCacheSize Maximum size of the cache. Any value <= 0 is considered as no limit.
7
- * @param lifetimeForValue Get the maximum lifetime for an entry given its value.
7
+ * @param lifetimeForValue Get the maximum lifetime for an entry given its value, in milliseconds.
8
8
  */
9
9
  constructor(maxCacheSize, lifetimeForValue) {
10
10
  this.nodesMap = new Map();
11
11
  this.firstNode = null;
12
12
  this.lastNode = null;
13
+ this.sequentialJobId = 0;
13
14
  this.maxCacheSize = maxCacheSize;
14
15
  this.lifetimeForValue = lifetimeForValue;
15
16
  }
17
+ /**
18
+ * Get a value if there is an already cached value or job for the provided key.
19
+ * - If the job is in progress this will return the job promise.
20
+ * - If there is already a cached value returns the value, regardless of whether his lifetime is expired or not.
21
+ * - If there is no job nor cached value this will return undefined.
22
+ * @param key key of the entry
23
+ * @return if there is a cached value or job in progress for the entry returns the item and if its lifetime has expired, otherwise returns
24
+ * undefined.
25
+ */
26
+ getIfCachedJob(key) {
27
+ const retrieved = this.nodesMap.get(key);
28
+ if (retrieved !== undefined) {
29
+ if (retrieved.expired((x) => this.lifetimeForValue(x))) {
30
+ return retrieved.valuePromise().then((x) => ({ item: x, expired: true }));
31
+ }
32
+ else {
33
+ this.markUsed(retrieved);
34
+ return retrieved.valuePromise().then((x) => ({ item: x, expired: false }));
35
+ }
36
+ }
37
+ return Promise.resolve(undefined);
38
+ }
16
39
  /**
17
40
  * Gets a cached value or retrieves it and caches it if the value is not available or if it is available but expired. A value will never be expired
18
41
  * if it was not yet retrieved, even if the retrieved value would be expired according to the {@link additionalExpirationCondition}
@@ -28,21 +51,35 @@ class LruTemporisedAsyncCache {
28
51
  this.markUsed(retrieved);
29
52
  const cachedValue = retrieved.cachedValue;
30
53
  if (retrieved.expired((x) => this.lifetimeForValue(x)) || (cachedValue !== undefined && additionalExpirationCondition(cachedValue))) {
31
- retrieved.value = this.registerJob(key, () => retrieve(cachedValue));
54
+ const newId = this.nextJobId();
55
+ retrieved.onEviction(true);
56
+ retrieved.jobId = newId;
57
+ retrieved.value = this.registerJob(key, newId, () => retrieve(cachedValue));
32
58
  }
33
59
  return retrieved.valuePromise();
34
60
  }
35
61
  else {
36
- const newNode = new CacheNode(key, this.lastNode, null, this.registerJob(key, () => retrieve(undefined)));
62
+ const jobId = this.nextJobId();
63
+ const newNode = new CacheNode(key, jobId, this.lastNode, null, this.registerJob(key, jobId, () => retrieve(undefined)));
37
64
  this.addToTail(key, newNode);
38
65
  if (this.maxCacheSize > 0 && this.nodesMap.size > this.maxCacheSize)
39
- this.evict(this.firstNode.key, this.firstNode);
66
+ this.evict(this.firstNode.key, this.firstNode, true);
40
67
  return newNode.valuePromise();
41
68
  }
42
69
  }
43
- clear() {
70
+ /**
71
+ * Fully empties this cache.
72
+ * @param doOnEvictionOfCleared if true the onEviction triggers for the retrieved and cached data will be executed, otherwise not. onEviction
73
+ * triggers of data for which the retrieval jobs were not completed will automatically be called when the job completes.
74
+ */
75
+ clear(doOnEvictionOfCleared = true) {
44
76
  this.firstNode = null;
45
77
  this.lastNode = null;
78
+ if (doOnEvictionOfCleared) {
79
+ for (const node of this.nodesMap.values()) {
80
+ node.onEviction(false);
81
+ }
82
+ }
46
83
  this.nodesMap.clear();
47
84
  }
48
85
  addToTail(key, node) {
@@ -56,7 +93,7 @@ class LruTemporisedAsyncCache {
56
93
  if (key != null)
57
94
  this.nodesMap.set(key, node);
58
95
  }
59
- evict(key, node) {
96
+ evict(key, node, doEvictionTriggers) {
60
97
  if (node.previous)
61
98
  node.previous.next = node.next;
62
99
  if (node.next)
@@ -65,39 +102,57 @@ class LruTemporisedAsyncCache {
65
102
  this.firstNode = node.next;
66
103
  if (this.lastNode === node)
67
104
  this.lastNode = node.previous;
68
- if (key !== null)
105
+ if (key !== null) {
69
106
  this.nodesMap.delete(key);
107
+ }
108
+ if (doEvictionTriggers) {
109
+ node.onEviction(false);
110
+ }
70
111
  }
71
112
  markUsed(node) {
72
113
  if (node !== this.lastNode) {
73
114
  // No need to modify the nodes map
74
- this.evict(null, node);
115
+ this.evict(null, node, false);
75
116
  this.addToTail(null, node);
76
117
  }
77
118
  }
78
- registerJob(key, retrieve) {
119
+ registerJob(key, jobId, retrieve) {
79
120
  // The node may have already been evicted by the time the promise completed if the cached surpassed the maximum size.
80
121
  return retrieve()
81
- .then((v) => {
122
+ .then(({ item: v, onEviction }) => {
82
123
  const node = this.nodesMap.get(key);
83
- if (node) {
84
- node.value = { cached: v, timestamp: Date.now() };
124
+ if (node && node.jobId == jobId) {
125
+ node.value = { cached: v, timestamp: Date.now(), onEviction: (r) => onEviction === null || onEviction === void 0 ? void 0 : onEviction(r) };
126
+ }
127
+ else {
128
+ onEviction === null || onEviction === void 0 ? void 0 : onEviction(!!node);
85
129
  }
86
130
  return v;
87
131
  })
88
132
  .catch((e) => {
89
133
  const node = this.nodesMap.get(key);
90
- if (node) {
91
- this.evict(key, node);
134
+ if (node && node.jobId == jobId) {
135
+ this.evict(key, node, true);
92
136
  }
93
137
  throw e;
94
138
  });
95
139
  }
140
+ nextJobId() {
141
+ const res = this.sequentialJobId;
142
+ if (this.sequentialJobId < Number.MAX_SAFE_INTEGER) {
143
+ this.sequentialJobId = res + 1;
144
+ }
145
+ else {
146
+ this.sequentialJobId = 0;
147
+ }
148
+ return res;
149
+ }
96
150
  }
97
151
  exports.LruTemporisedAsyncCache = LruTemporisedAsyncCache;
98
152
  class CacheNode {
99
- constructor(key, previous, next, value) {
153
+ constructor(key, jobId, previous, next, value) {
100
154
  this.key = key;
155
+ this.jobId = jobId;
101
156
  this.previous = previous;
102
157
  this.next = next;
103
158
  this.value = value;
@@ -113,6 +168,11 @@ class CacheNode {
113
168
  valuePromise() {
114
169
  return 'timestamp' in this.value ? Promise.resolve(this.value.cached) : this.value;
115
170
  }
171
+ onEviction(isReplacement) {
172
+ if ('timestamp' in this.value) {
173
+ this.value.onEviction(isReplacement);
174
+ }
175
+ }
116
176
  get cachedValue() {
117
177
  return 'timestamp' in this.value ? this.value.cached : undefined;
118
178
  }
@@ -1 +1 @@
1
- {"version":3,"file":"lru-temporised-async-cache.js","sourceRoot":"","sources":["../../../icc-x-api/utils/lru-temporised-async-cache.ts"],"names":[],"mappings":";;;A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AG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,OAAO,CAAC,gBAAsC;QAC5C,IAAI,WAAW,IAAI,IAAI,CAAC,KAAK,EAAE;YAC7B,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YACvD,OAAO,WAAW,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,WAAW,CAAA;SAC1E;;YAAM,OAAO,KAAK,CAAA;IACrB,CAAC;IAED,YAAY;QACV,OAAO,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAA;IACpF,CAAC;IAED,IAAI,WAAW;QACb,OAAO,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IAClE,CAAC;CACF","sourcesContent":["export class LruTemporisedAsyncCache<K, V> {\n private readonly maxCacheSize: number\n private readonly lifetimeForValue: (value: V) => number\n\n private readonly nodesMap: Map<K, CacheNode<K, V>> = new Map()\n private firstNode: CacheNode<K, V> | null = null\n private lastNode: CacheNode<K, V> | null = null\n\n /**\n * @param maxCacheSize Maximum size of the cache. Any value <= 0 is considered as no limit.\n * @param lifetimeForValue Get the maximum lifetime for an entry given its value.\n */\n constructor(maxCacheSize: number, lifetimeForValue: (value: V) => number) {\n this.maxCacheSize = maxCacheSize\n this.lifetimeForValue = lifetimeForValue\n }\n\n /**\n * Gets a cached value or retrieves it and caches it if the value is not available or if it is available but expired. A value will never be expired\n * if it was not yet retrieved, even if the retrieved value would be expired according to the {@link additionalExpirationCondition}\n * @param key key of the entry\n * @param retrieve given the previous value (if available, expired but not yet removed) of the entry retrieves an updated value.\n * @param additionalExpirationCondition an expiration condition for already cached values to consider in addition to time-based expiration. Returns\n * always false by default, meaning the value is not expired if its lifetime didn't already surpass the maximum lifetime.\n * @return the cached value if present and not expired, else the retrieved value.\n */\n get(\n key: K,\n retrieve: (previousValue: V | undefined) => Promise<V>,\n additionalExpirationCondition: (value: V) => boolean = () => false\n ): Promise<V> {\n const retrieved = this.nodesMap.get(key)\n if (retrieved !== undefined) {\n this.markUsed(retrieved)\n const cachedValue = retrieved.cachedValue\n if (retrieved.expired((x) => this.lifetimeForValue(x)) || (cachedValue !== undefined && additionalExpirationCondition(cachedValue))) {\n retrieved.value = this.registerJob(key, () => retrieve(cachedValue))\n }\n return retrieved.valuePromise()\n } else {\n const newNode = new CacheNode(\n key,\n this.lastNode,\n null,\n this.registerJob(key, () => retrieve(undefined))\n )\n this.addToTail(key, newNode)\n if (this.maxCacheSize > 0 && this.nodesMap.size > this.maxCacheSize) this.evict(this.firstNode!.key, this.firstNode!)\n return newNode.valuePromise()\n }\n }\n\n clear() {\n this.firstNode = null\n this.lastNode = null\n this.nodesMap.clear()\n }\n\n private addToTail(key: K | null, node: CacheNode<K, V>) {\n node.previous = this.lastNode\n node.next = null\n if (this.lastNode) this.lastNode.next = node\n this.lastNode = node\n if (this.firstNode === null) this.firstNode = node\n if (key != null) this.nodesMap.set(key, node)\n }\n\n private evict(key: K | null, node: CacheNode<K, V>) {\n if (node.previous) node.previous.next = node.next\n if (node.next) node.next.previous = node.previous\n if (this.firstNode === node) this.firstNode = node.next\n if (this.lastNode === node) this.lastNode = node.previous\n if (key !== null) this.nodesMap.delete(key)\n }\n\n private markUsed(node: CacheNode<K, V>) {\n if (node !== this.lastNode) {\n // No need to modify the nodes map\n this.evict(null, node)\n this.addToTail(null, node)\n }\n }\n\n private registerJob(key: K, retrieve: () => Promise<V>): Promise<V> {\n // The node may have already been evicted by the time the promise completed if the cached surpassed the maximum size.\n return retrieve()\n .then((v) => {\n const node = this.nodesMap.get(key)\n if (node) {\n node.value = { cached: v, timestamp: Date.now() }\n }\n return v\n })\n .catch((e) => {\n const node = this.nodesMap.get(key)\n if (node) {\n this.evict(key, node)\n }\n throw e\n })\n }\n}\n\ntype Cached<V> = { cached: V; timestamp: number }\n\nclass CacheNode<K, V> {\n readonly key: K\n previous: CacheNode<K, V> | null\n next: CacheNode<K, V> | null\n value: Promise<V> | Cached<V>\n\n constructor(key: K, previous: CacheNode<K, V> | null, next: CacheNode<K, V> | null, value: Promise<V>) {\n this.key = key\n this.previous = previous\n this.next = next\n this.value = value\n }\n\n expired(lifetimeForValue: (value: V) => number): boolean {\n if ('timestamp' in this.value) {\n const maxLifetime = lifetimeForValue(this.value.cached)\n return maxLifetime > 0 && Date.now() - this.value.timestamp > maxLifetime\n } else return false\n }\n\n valuePromise(): Promise<V> {\n return 'timestamp' in this.value ? Promise.resolve(this.value.cached) : this.value\n }\n\n get cachedValue(): V | undefined {\n return 'timestamp' in this.value ? this.value.cached : undefined\n }\n}\n"]}
1
+ {"version":3,"file":"lru-temporised-async-cache.js","sourceRoot":"","sources":["../../../icc-x-api/utils/lru-temporised-async-cache.ts"],"names":[],"mappings":";;;AAAA,MAAa,uBAAuB;IAUlC;;;OAGG;IACH,YAAY,YAAoB,EAAE,gBAAsC;QAVvD,aAAQ,GAA4B,IAAI,GAAG,EAAE,CAAA;QACtD,cAAS,GAA2B,IAAI,CAAA;QACxC,aAAQ,GAA2B,IAAI,CAAA;QAEvC,oBAAe,GAAG,CAAC,CAAA;QAOzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC1C,CAAC;IAED;;;;;;;;OAQG;IACH,cAAc,CAAC,GAAM;QACnB,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACxC,IAAI,SAAS,KAAK,SAAS,EAAE;YAC3B,IAAI,SAAS,CAAC,OAAO,CAAC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ACF;AA7JD,0DA6JC;AAID,MAAM,SAAS;IAOb,YAAY,GAAM,EAAE,KAAa,EAAE,QAAgC,EAAE,IAA4B,EAAE,KAAiB;QAClH,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,OAAO,CAAC,gBAAsC;QAC5C,IAAI,WAAW,IAAI,IAAI,CAAC,KAAK,EAAE;YAC7B,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YACvD,OAAO,WAAW,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,WAAW,CAAA;SAC1E;;YAAM,OAAO,KAAK,CAAA;IACrB,CAAC;IAED,YAAY;QACV,OAAO,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAA;IACpF,CAAC;IAED,UAAU,CAAC,aAAsB;QAC/B,IAAI,WAAW,IAAI,IAAI,CAAC,KAAK,EAAE;YAC7B,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;SACrC;IACH,CAAC;IAED,IAAI,WAAW;QACb,OAAO,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IAClE,CAAC;CACF","sourcesContent":["export class LruTemporisedAsyncCache<K, V> {\n private readonly maxCacheSize: number\n private readonly lifetimeForValue: (value: V) => number\n\n private readonly nodesMap: Map<K, CacheNode<K, V>> = new Map()\n private firstNode: CacheNode<K, V> | null = null\n private lastNode: CacheNode<K, V> | null = null\n\n private sequentialJobId = 0\n\n /**\n * @param maxCacheSize Maximum size of the cache. Any value <= 0 is considered as no limit.\n * @param lifetimeForValue Get the maximum lifetime for an entry given its value, in milliseconds.\n */\n constructor(maxCacheSize: number, lifetimeForValue: (value: V) => number) {\n this.maxCacheSize = maxCacheSize\n this.lifetimeForValue = lifetimeForValue\n }\n\n /**\n * Get a value if there is an already cached value or job for the provided key.\n * - If the job is in progress this will return the job promise.\n * - If there is already a cached value returns the value, regardless of whether his lifetime is expired or not.\n * - If there is no job nor cached value this will return undefined.\n * @param key key of the entry\n * @return if there is a cached value or job in progress for the entry returns the item and if its lifetime has expired, otherwise returns\n * undefined.\n */\n getIfCachedJob(key: K): Promise<{ item: V; expired: boolean } | undefined> {\n const retrieved = this.nodesMap.get(key)\n if (retrieved !== undefined) {\n if (retrieved.expired((x) => this.lifetimeForValue(x))) {\n return retrieved.valuePromise().then((x) => ({ item: x, expired: true }))\n } else {\n this.markUsed(retrieved)\n return retrieved.valuePromise().then((x) => ({ item: x, expired: false }))\n }\n }\n return Promise.resolve(undefined)\n }\n\n /**\n * Gets a cached value or retrieves it and caches it if the value is not available or if it is available but expired. A value will never be expired\n * if it was not yet retrieved, even if the retrieved value would be expired according to the {@link additionalExpirationCondition}\n * @param key key of the entry\n * @param retrieve given the previous value (if available, expired but not yet removed) of the entry retrieves an updated value.\n * @param additionalExpirationCondition an expiration condition for already cached values to consider in addition to time-based expiration. Returns\n * always false by default, meaning the value is not expired if its lifetime didn't already surpass the maximum lifetime.\n * @return the cached value if present and not expired, else the retrieved value.\n */\n get(\n key: K,\n retrieve: (previousValue: V | undefined) => Promise<{ item: V; onEviction?: (isReplacement: boolean) => void }>,\n additionalExpirationCondition: (value: V) => boolean = () => false\n ): Promise<V> {\n const retrieved = this.nodesMap.get(key)\n if (retrieved !== undefined) {\n this.markUsed(retrieved)\n const cachedValue = retrieved.cachedValue\n if (retrieved.expired((x) => this.lifetimeForValue(x)) || (cachedValue !== undefined && additionalExpirationCondition(cachedValue))) {\n const newId = this.nextJobId()\n retrieved.onEviction(true)\n retrieved.jobId = newId\n retrieved.value = this.registerJob(key, newId, () => retrieve(cachedValue))\n }\n return retrieved.valuePromise()\n } else {\n const jobId = this.nextJobId()\n const newNode = new CacheNode(\n key,\n jobId,\n this.lastNode,\n null,\n this.registerJob(key, jobId, () => retrieve(undefined))\n )\n this.addToTail(key, newNode)\n if (this.maxCacheSize > 0 && this.nodesMap.size > this.maxCacheSize) this.evict(this.firstNode!.key, this.firstNode!, true)\n return newNode.valuePromise()\n }\n }\n\n /**\n * Fully empties this cache.\n * @param doOnEvictionOfCleared if true the onEviction triggers for the retrieved and cached data will be executed, otherwise not. onEviction\n * triggers of data for which the retrieval jobs were not completed will automatically be called when the job completes.\n */\n clear(doOnEvictionOfCleared: boolean = true) {\n this.firstNode = null\n this.lastNode = null\n if (doOnEvictionOfCleared) {\n for (const node of this.nodesMap.values()) {\n node.onEviction(false)\n }\n }\n this.nodesMap.clear()\n }\n\n private addToTail(key: K | null, node: CacheNode<K, V>) {\n node.previous = this.lastNode\n node.next = null\n if (this.lastNode) this.lastNode.next = node\n this.lastNode = node\n if (this.firstNode === null) this.firstNode = node\n if (key != null) this.nodesMap.set(key, node)\n }\n\n private evict(key: K | null, node: CacheNode<K, V>, doEvictionTriggers: boolean) {\n if (node.previous) node.previous.next = node.next\n if (node.next) node.next.previous = node.previous\n if (this.firstNode === node) this.firstNode = node.next\n if (this.lastNode === node) this.lastNode = node.previous\n if (key !== null) {\n this.nodesMap.delete(key)\n }\n if (doEvictionTriggers) {\n node.onEviction(false)\n }\n }\n\n private markUsed(node: CacheNode<K, V>) {\n if (node !== this.lastNode) {\n // No need to modify the nodes map\n this.evict(null, node, false)\n this.addToTail(null, node)\n }\n }\n\n private registerJob(key: K, jobId: number, retrieve: () => Promise<{ item: V; onEviction?: (isReplacement: boolean) => void }>): Promise<V> {\n // The node may have already been evicted by the time the promise completed if the cached surpassed the maximum size.\n return retrieve()\n .then(({ item: v, onEviction }) => {\n const node = this.nodesMap.get(key)\n if (node && node.jobId == jobId) {\n node.value = { cached: v, timestamp: Date.now(), onEviction: (r) => onEviction?.(r) }\n } else {\n onEviction?.(!!node)\n }\n return v\n })\n .catch((e) => {\n const node = this.nodesMap.get(key)\n if (node && node.jobId == jobId) {\n this.evict(key, node, true)\n }\n throw e\n })\n }\n\n private nextJobId(): number {\n const res = this.sequentialJobId\n if (this.sequentialJobId < Number.MAX_SAFE_INTEGER) {\n this.sequentialJobId = res + 1\n } else {\n this.sequentialJobId = 0\n }\n return res\n }\n}\n\ntype Cached<V> = { cached: V; timestamp: number; onEviction: (isReplacement: boolean) => void }\n\nclass CacheNode<K, V> {\n readonly key: K\n previous: CacheNode<K, V> | null\n next: CacheNode<K, V> | null\n value: Promise<V> | Cached<V>\n jobId: number\n\n constructor(key: K, jobId: number, previous: CacheNode<K, V> | null, next: CacheNode<K, V> | null, value: Promise<V>) {\n this.key = key\n this.jobId = jobId\n this.previous = previous\n this.next = next\n this.value = value\n }\n\n expired(lifetimeForValue: (value: V) => number): boolean {\n if ('timestamp' in this.value) {\n const maxLifetime = lifetimeForValue(this.value.cached)\n return maxLifetime > 0 && Date.now() - this.value.timestamp > maxLifetime\n } else return false\n }\n\n valuePromise(): Promise<V> {\n return 'timestamp' in this.value ? Promise.resolve(this.value.cached) : this.value\n }\n\n onEviction(isReplacement: boolean): void {\n if ('timestamp' in this.value) {\n this.value.onEviction(isReplacement)\n }\n }\n\n get cachedValue(): V | undefined {\n return 'timestamp' in this.value ? this.value.cached : undefined\n }\n}\n"]}
@@ -1,14 +1,16 @@
1
1
  /// <reference types="node" />
2
- import { Patient } from "../../icc-api/model/Patient";
3
- import { AbstractFilter } from "../filters/filters";
4
- import { User } from "../../icc-api/model/User";
5
- import { IccAuthApi } from "../../icc-api";
6
- import { Service } from "../../icc-api/model/Service";
7
- import { HealthElement } from "../../icc-api/model/HealthElement";
8
- import { MaintenanceTask } from "../../icc-api/model/MaintenanceTask";
9
- import { HealthcareParty } from "../../icc-api/model/HealthcareParty";
10
- import { Device } from "../../icc-api/model/Device";
11
- import { Contact } from "../../icc-api/model/Contact";
2
+ import { Patient } from '../../icc-api/model/Patient';
3
+ import { AbstractFilter } from '../filters/filters';
4
+ import { User } from '../../icc-api/model/User';
5
+ import { IccAuthApi } from '../../icc-api';
6
+ import { Service } from '../../icc-api/model/Service';
7
+ import { HealthElement } from '../../icc-api/model/HealthElement';
8
+ import { MaintenanceTask } from '../../icc-api/model/MaintenanceTask';
9
+ import { HealthcareParty } from '../../icc-api/model/HealthcareParty';
10
+ import { Device } from '../../icc-api/model/Device';
11
+ import { Contact } from '../../icc-api/model/Contact';
12
+ import { Message } from '../../icc-api/model/Message';
13
+ import { Topic } from '../../icc-api/model/Topic';
12
14
  export type EventTypes = 'CREATE' | 'UPDATE' | 'DELETE';
13
15
  export type SubscriptionOptions = {
14
16
  connectionMaxRetry?: number;
@@ -19,6 +21,8 @@ export declare function subscribeToEntityEvents(basePath: string, authApi: IccAu
19
21
  export declare function subscribeToEntityEvents(basePath: string, authApi: IccAuthApi, entityClass: 'Service', eventTypes: EventTypes[], filter: AbstractFilter<Service> | undefined, eventFired: (entity: Service) => Promise<void>, options: SubscriptionOptions, decryptor: (encrypted: Service) => Promise<Service>): Promise<WebSocketWrapper>;
20
22
  export declare function subscribeToEntityEvents(basePath: string, authApi: IccAuthApi, entityClass: 'Contact', eventTypes: EventTypes[], filter: AbstractFilter<Contact> | undefined, eventFired: (entity: Contact) => Promise<void>, options: SubscriptionOptions, decryptor: (encrypted: Contact) => Promise<Contact>): Promise<WebSocketWrapper>;
21
23
  export declare function subscribeToEntityEvents(basePath: string, authApi: IccAuthApi, entityClass: 'HealthElement', eventTypes: EventTypes[], filter: AbstractFilter<HealthElement> | undefined, eventFired: (entity: HealthElement) => Promise<void>, options: SubscriptionOptions, decryptor: (encrypted: HealthElement) => Promise<HealthElement>): Promise<WebSocketWrapper>;
24
+ export declare function subscribeToEntityEvents(basePath: string, authApi: IccAuthApi, entityClass: 'Message', eventTypes: EventTypes[], filter: AbstractFilter<Message> | undefined, eventFired: (entity: Message) => Promise<void>, options: SubscriptionOptions, decryptor: (encrypted: Message) => Promise<Message>): Promise<WebSocketWrapper>;
25
+ export declare function subscribeToEntityEvents(basePath: string, authApi: IccAuthApi, entityClass: 'Topic', eventTypes: EventTypes[], filter: AbstractFilter<Topic> | undefined, eventFired: (entity: Topic) => Promise<void>, options: SubscriptionOptions, decryptor: (encrypted: Topic) => Promise<Topic>): Promise<WebSocketWrapper>;
22
26
  export declare function subscribeToEntityEvents(basePath: string, authApi: IccAuthApi, entityClass: 'User', eventTypes: EventTypes[], filter: AbstractFilter<User> | undefined, eventFired: (entity: User) => Promise<void>, options: SubscriptionOptions): Promise<WebSocketWrapper>;
23
27
  export declare function subscribeToEntityEvents(basePath: string, authApi: IccAuthApi, entityClass: 'MaintenanceTask', eventTypes: EventTypes[], filter: AbstractFilter<MaintenanceTask> | undefined, eventFired: (entity: MaintenanceTask) => Promise<void>, options: SubscriptionOptions, decryptor: (encrypted: MaintenanceTask) => Promise<MaintenanceTask>): Promise<WebSocketWrapper>;
24
28
  export declare function subscribeToEntityEvents(basePath: string, authApi: IccAuthApi, entityClass: 'HealthcareParty', eventTypes: EventTypes[], filter: AbstractFilter<HealthcareParty> | undefined, eventFired: (entity: HealthcareParty) => Promise<void>, options: SubscriptionOptions): Promise<WebSocketWrapper>;
@@ -34,6 +34,14 @@ function subscribeToEntityEvents(basePath, authApi, entityClass, eventTypes, fil
34
34
  qualifiedName: 'org.taktik.icure.entities.HealthElement',
35
35
  decryptor: (data) => decryptor(data),
36
36
  },
37
+ Message: {
38
+ qualifiedName: 'org.taktik.icure.entities.Message',
39
+ decryptor: (data) => decryptor(data),
40
+ },
41
+ Topic: {
42
+ qualifiedName: 'org.taktik.icure.entities.Topic',
43
+ decryptor: (data) => decryptor(data),
44
+ },
37
45
  MaintenanceTask: {
38
46
  qualifiedName: 'org.taktik.icure.entities.MaintenanceTask',
39
47
  decryptor: (data) => decryptor(data),
@@ -57,7 +65,7 @@ function subscribeToEntityEvents(basePath, authApi, entityClass, eventTypes, fil
57
65
  const subscription = {
58
66
  eventTypes,
59
67
  entityClass: config[entityClass].qualifiedName,
60
- filter: { filter }
68
+ filter: { filter },
61
69
  };
62
70
  ws.send(JSON.stringify(subscription));
63
71
  }),
@@ -127,11 +135,12 @@ class WebSocketWrapper {
127
135
  throw new Error('WebSocket connection failed after ' + this.maxRetries + ' retries');
128
136
  }
129
137
  const bearerToken = yield this.authProvider.getBearerToken();
130
- const socket = browser_or_node_1.isNode && !!bearerToken ? new WebSocketNode(this.url, {
131
- headers: {
132
- Authorization: bearerToken,
133
- },
134
- })
138
+ const socket = browser_or_node_1.isNode && !!bearerToken
139
+ ? new WebSocketNode(this.url, {
140
+ headers: {
141
+ Authorization: bearerToken,
142
+ },
143
+ })
135
144
  : yield this.authProvider.getIcureOtt(this.methodPath).then((icureOttToken) => {
136
145
  const address = `${this.url};tokenid=${icureOttToken}`;
137
146
  return browser_or_node_1.isNode ? new WebSocketNode(address) : new WebSocket(address);
@@ -284,18 +293,20 @@ class WebsocketAdapter {
284
293
  onMessage(callback) {
285
294
  if (this.websocket) {
286
295
  if (browser_or_node_1.isNode) {
296
+ ;
287
297
  this.websocket.on('message', (x) => callback(x.toString('utf8')));
288
298
  }
289
299
  else {
300
+ ;
290
301
  this.websocket.addEventListener('message', (event) => __awaiter(this, void 0, void 0, function* () {
291
302
  let dataAsString;
292
303
  if (event.type === 'message') {
293
304
  dataAsString = event.data;
294
305
  }
295
306
  else
296
- console.error("Unexpected event type: " + event.type);
307
+ console.error('Unexpected event type: ' + event.type);
297
308
  if (!dataAsString) {
298
- console.error("Failed to parse WebSocket message");
309
+ console.error('Failed to parse WebSocket message');
299
310
  return;
300
311
  }
301
312
  callback(dataAsString);
@@ -303,16 +314,18 @@ class WebsocketAdapter {
303
314
  }
304
315
  }
305
316
  else {
306
- console.error("Websocket is not defined");
317
+ console.error('Websocket is not defined');
307
318
  throw new Error('Websocket is not defined');
308
319
  }
309
320
  }
310
321
  onOpen(callback) {
311
322
  if (this.websocket) {
312
323
  if (browser_or_node_1.isNode) {
324
+ ;
313
325
  this.websocket.on('open', callback);
314
326
  }
315
327
  else {
328
+ ;
316
329
  this.websocket.addEventListener('open', callback);
317
330
  }
318
331
  }
@@ -320,9 +333,11 @@ class WebsocketAdapter {
320
333
  onClose(callback) {
321
334
  if (this.websocket) {
322
335
  if (browser_or_node_1.isNode) {
336
+ ;
323
337
  this.websocket.on('close', callback);
324
338
  }
325
339
  else {
340
+ ;
326
341
  this.websocket.addEventListener('close', callback);
327
342
  }
328
343
  }
@@ -330,9 +345,11 @@ class WebsocketAdapter {
330
345
  onError(callback) {
331
346
  if (this.websocket) {
332
347
  if (browser_or_node_1.isNode) {
348
+ ;
333
349
  this.websocket.on('error', callback);
334
350
  }
335
351
  else {
352
+ ;
336
353
  this.websocket.addEventListener('error', callback);
337
354
  }
338
355
  }