@icure/api 6.4.0 → 7.0.0-beta.1

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 (154) hide show
  1. package/icc-api/api/IccDeviceApi.d.ts +1 -1
  2. package/icc-api/api/IccDeviceApi.js.map +1 -1
  3. package/icc-api/api/IccDoctemplateApi.js.map +1 -1
  4. package/icc-api/api/IccDocumentTemplateApi.js.map +1 -1
  5. package/icc-api/api/IccHcpartyApi.d.ts +1 -1
  6. package/icc-api/api/IccHcpartyApi.js.map +1 -1
  7. package/icc-api/api/IccPatientApi.d.ts +1 -1
  8. package/icc-api/api/IccPatientApi.js.map +1 -1
  9. package/icc-api/model/MaintenanceTask.d.ts +6 -5
  10. package/icc-api/model/MaintenanceTask.js +5 -0
  11. package/icc-api/model/MaintenanceTask.js.map +1 -1
  12. package/icc-api/model/User.d.ts +23 -1
  13. package/icc-api/model/User.js +21 -0
  14. package/icc-api/model/User.js.map +1 -1
  15. package/icc-api/model/models.d.ts +14 -0
  16. package/icc-api/model/models.js.map +1 -1
  17. package/icc-x-api/crypto/AES.d.ts +2 -0
  18. package/icc-x-api/crypto/AES.js +12 -0
  19. package/icc-x-api/crypto/AES.js.map +1 -1
  20. package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +122 -0
  21. package/icc-x-api/crypto/BaseExchangeKeysManager.js +356 -0
  22. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -0
  23. package/icc-x-api/crypto/ConfidentialEntities.d.ts +58 -0
  24. package/icc-x-api/crypto/ConfidentialEntities.js +99 -0
  25. package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -0
  26. package/icc-x-api/crypto/CryptoPrimitives.d.ts +31 -0
  27. package/icc-x-api/crypto/CryptoPrimitives.js +55 -0
  28. package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -0
  29. package/icc-x-api/crypto/CryptoStrategies.d.ts +82 -0
  30. package/icc-x-api/crypto/CryptoStrategies.js +3 -0
  31. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -0
  32. package/icc-x-api/crypto/EntitiesEncryption.d.ts +254 -0
  33. package/icc-x-api/crypto/EntitiesEncryption.js +700 -0
  34. package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -0
  35. package/icc-x-api/crypto/ExchangeKeysManager.d.ts +56 -0
  36. package/icc-x-api/crypto/ExchangeKeysManager.js +147 -0
  37. package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -0
  38. package/icc-x-api/crypto/KeyManager.d.ts +103 -0
  39. package/icc-x-api/crypto/KeyManager.js +288 -0
  40. package/icc-x-api/crypto/KeyManager.js.map +1 -0
  41. package/icc-x-api/crypto/KeyRecovery.d.ts +34 -0
  42. package/icc-x-api/crypto/KeyRecovery.js +253 -0
  43. package/icc-x-api/crypto/KeyRecovery.js.map +1 -0
  44. package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +28 -0
  45. package/icc-x-api/crypto/LegacyCryptoStrategies.js +22 -0
  46. package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -0
  47. package/icc-x-api/crypto/RSA.d.ts +19 -20
  48. package/icc-x-api/crypto/RSA.js +30 -1
  49. package/icc-x-api/crypto/RSA.js.map +1 -1
  50. package/icc-x-api/crypto/ShamirKeysManager.d.ts +43 -0
  51. package/icc-x-api/crypto/ShamirKeysManager.js +150 -0
  52. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -0
  53. package/icc-x-api/crypto/ShareMetadataBehaviour.d.ts +19 -0
  54. package/icc-x-api/crypto/ShareMetadataBehaviour.js +24 -0
  55. package/icc-x-api/crypto/ShareMetadataBehaviour.js.map +1 -0
  56. package/icc-x-api/crypto/TransferKeysManager.d.ts +29 -0
  57. package/icc-x-api/crypto/TransferKeysManager.js +121 -0
  58. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -0
  59. package/icc-x-api/crypto/utils.d.ts +46 -0
  60. package/icc-x-api/crypto/utils.js +128 -0
  61. package/icc-x-api/crypto/utils.js.map +1 -1
  62. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.d.ts +11 -0
  63. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js +11 -0
  64. package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js.map +1 -1
  65. package/icc-x-api/filters/DeviceByHcPartyFilter.d.ts +11 -0
  66. package/icc-x-api/filters/DeviceByHcPartyFilter.js +11 -0
  67. package/icc-x-api/filters/DeviceByHcPartyFilter.js.map +1 -1
  68. package/icc-x-api/filters/DeviceByIdsFilter.d.ts +11 -0
  69. package/icc-x-api/filters/DeviceByIdsFilter.js +11 -0
  70. package/icc-x-api/filters/DeviceByIdsFilter.js.map +1 -1
  71. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.d.ts +11 -0
  72. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js +11 -0
  73. package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js.map +1 -1
  74. package/icc-x-api/icc-accesslog-x-api.d.ts +49 -4
  75. package/icc-x-api/icc-accesslog-x-api.js +112 -102
  76. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  77. package/icc-x-api/icc-calendar-item-x-api.d.ts +53 -5
  78. package/icc-x-api/icc-calendar-item-x-api.js +112 -100
  79. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  80. package/icc-x-api/icc-classification-x-api.d.ts +45 -2
  81. package/icc-x-api/icc-classification-x-api.js +89 -41
  82. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  83. package/icc-x-api/icc-contact-x-api.d.ts +57 -19
  84. package/icc-x-api/icc-contact-x-api.js +149 -154
  85. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  86. package/icc-x-api/icc-crypto-x-api.d.ts +266 -366
  87. package/icc-x-api/icc-crypto-x-api.js +416 -1327
  88. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  89. package/icc-x-api/icc-data-owner-x-api.d.ts +110 -11
  90. package/icc-x-api/icc-data-owner-x-api.js +188 -14
  91. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  92. package/icc-x-api/icc-doctemplate-x-api.js +3 -3
  93. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  94. package/icc-x-api/icc-document-x-api.d.ts +76 -5
  95. package/icc-x-api/icc-document-x-api.js +137 -59
  96. package/icc-x-api/icc-document-x-api.js.map +1 -1
  97. package/icc-x-api/icc-form-x-api.d.ts +47 -7
  98. package/icc-x-api/icc-form-x-api.js +85 -86
  99. package/icc-x-api/icc-form-x-api.js.map +1 -1
  100. package/icc-x-api/icc-hcparty-x-api.d.ts +1 -1
  101. package/icc-x-api/icc-hcparty-x-api.js +1 -1
  102. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  103. package/icc-x-api/icc-helement-x-api.d.ts +50 -3
  104. package/icc-x-api/icc-helement-x-api.js +101 -118
  105. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  106. package/icc-x-api/icc-icure-maintenance-x-api.d.ts +31 -0
  107. package/icc-x-api/icc-icure-maintenance-x-api.js +124 -0
  108. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -0
  109. package/icc-x-api/icc-invoice-x-api.d.ts +45 -5
  110. package/icc-x-api/icc-invoice-x-api.js +89 -64
  111. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  112. package/icc-x-api/icc-maintenance-task-x-api.d.ts +38 -6
  113. package/icc-x-api/icc-maintenance-task-x-api.js +73 -102
  114. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  115. package/icc-x-api/icc-message-x-api.d.ts +55 -2
  116. package/icc-x-api/icc-message-x-api.js +92 -33
  117. package/icc-x-api/icc-message-x-api.js.map +1 -1
  118. package/icc-x-api/icc-patient-x-api.d.ts +67 -7
  119. package/icc-x-api/icc-patient-x-api.js +409 -473
  120. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  121. package/icc-x-api/icc-receipt-x-api.d.ts +49 -5
  122. package/icc-x-api/icc-receipt-x-api.js +85 -47
  123. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  124. package/icc-x-api/icc-time-table-x-api.d.ts +34 -10
  125. package/icc-x-api/icc-time-table-x-api.js +61 -18
  126. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  127. package/icc-x-api/index.d.ts +30 -1
  128. package/icc-x-api/index.js +112 -49
  129. package/icc-x-api/index.js.map +1 -1
  130. package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +35 -0
  131. package/icc-x-api/maintenance/KeyPairUpdateRequest.js +54 -0
  132. package/icc-x-api/maintenance/KeyPairUpdateRequest.js.map +1 -0
  133. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +9 -0
  134. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +23 -0
  135. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -0
  136. package/icc-x-api/storage/IcureStorageFacade.d.ts +55 -0
  137. package/icc-x-api/storage/IcureStorageFacade.js +95 -0
  138. package/icc-x-api/storage/IcureStorageFacade.js.map +1 -0
  139. package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +31 -0
  140. package/icc-x-api/storage/StorageEntryKeysFactory.js +3 -0
  141. package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -0
  142. package/icc-x-api/utils/collection-utils.d.ts +8 -0
  143. package/icc-x-api/utils/collection-utils.js +26 -0
  144. package/icc-x-api/utils/collection-utils.js.map +1 -0
  145. package/icc-x-api/utils/crypto-utils.d.ts +8 -1
  146. package/icc-x-api/utils/crypto-utils.js +19 -3
  147. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  148. package/icc-x-api/utils/graph-utils.d.ts +45 -0
  149. package/icc-x-api/utils/graph-utils.js +203 -0
  150. package/icc-x-api/utils/graph-utils.js.map +1 -0
  151. package/icc-x-api/utils/lru-temporised-async-cache.d.ts +27 -0
  152. package/icc-x-api/utils/lru-temporised-async-cache.js +120 -0
  153. package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -0
  154. package/package.json +1 -1
@@ -1,11 +1,21 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.IccMaintenanceTaskXApi = void 0;
4
13
  const IccMaintenanceTaskApi_1 = require("../icc-api/api/IccMaintenanceTaskApi");
14
+ const models = require("../icc-api/model/models");
15
+ const models_1 = require("../icc-api/model/models");
5
16
  const _ = require("lodash");
6
- const ModelHelper_1 = require("../icc-api/model/ModelHelper");
7
- const utils_1 = require("./utils");
8
17
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
18
+ const ShareMetadataBehaviour_1 = require("./crypto/ShareMetadataBehaviour");
9
19
  class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskApi {
10
20
  constructor(host, headers, crypto, hcPartyApi, dataOwnerApi, encryptedKeys = [], authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
11
21
  ? window.fetch
@@ -18,51 +28,34 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
18
28
  this.dataOwnerApi = dataOwnerApi;
19
29
  this.encryptedKeys = encryptedKeys;
20
30
  }
21
- newInstance(user, m, delegates = []) {
22
- const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
23
- const maintenanceTask = _.assign({
24
- id: this.crypto.randomUuid(),
25
- _type: 'org.taktik.icure.entities.MaintenanceTask',
26
- created: new Date().getTime(),
27
- modified: new Date().getTime(),
28
- responsible: dataOwnerId,
29
- author: user.id,
30
- }, m || {});
31
- return this.initDelegations(user, maintenanceTask, delegates).then((task) => this.initEncryptionKeys(user, task, delegates));
32
- }
33
- initDelegations(user, maintenanceTask, delegates = []) {
34
- const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
35
- return this.crypto.initObjectDelegations(maintenanceTask, null, dataOwnerId, null).then((initData) => {
36
- _.extend(maintenanceTask, { delegations: initData.delegations });
37
- let promise = Promise.resolve(maintenanceTask);
38
- _.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach((delegateId) => (promise = promise
39
- .then((patient) => this.crypto.extendedDelegationsAndCryptedForeignKeys(patient, null, dataOwnerId, delegateId, initData.secretId))
40
- .then((extraData) => _.extend(maintenanceTask, { delegations: extraData.delegations }))
41
- .catch((e) => {
42
- console.log(e);
43
- return maintenanceTask;
44
- })));
45
- return promise;
46
- });
47
- }
48
- initEncryptionKeys(user, maintenanceTask, delegates = []) {
49
- const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
50
- return this.crypto.initEncryptionKeys(maintenanceTask, dataOwnerId).then((eks) => {
51
- let promise = Promise.resolve(_.extend(maintenanceTask, {
52
- encryptionKeys: eks.encryptionKeys,
53
- }));
54
- _.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach((delegateId) => (promise = promise.then((patient) => this.crypto
55
- .appendEncryptionKeys(patient, dataOwnerId, delegateId, eks.secretId)
56
- .then((extraEks) => {
57
- return _.extend(extraEks.modifiedObject, {
58
- encryptionKeys: extraEks.encryptionKeys,
59
- });
60
- })
61
- .catch((e) => {
62
- console.log(e.message);
63
- return patient;
64
- }))));
65
- return promise;
31
+ /**
32
+ * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).
33
+ * @param user the current user.
34
+ * @param m initialised data for the maintenance task. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
35
+ * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
36
+ * @param options optional parameters:
37
+ * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
38
+ * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with
39
+ * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
40
+ * access will be possible.
41
+ * @return a new instance of maintenance task.
42
+ */
43
+ newInstance(user, m, options = {}) {
44
+ var _a, _b, _c;
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user);
47
+ const maintenanceTask = _.assign({
48
+ id: this.crypto.primitives.randomUuid(),
49
+ _type: 'org.taktik.icure.entities.MaintenanceTask',
50
+ created: new Date().getTime(),
51
+ modified: new Date().getTime(),
52
+ responsible: dataOwnerId,
53
+ author: user.id,
54
+ }, m || {});
55
+ const extraDelegations = [...Object.keys((_a = options.additionalDelegates) !== null && _a !== void 0 ? _a : {}), ...((_c = (_b = user.autoDelegations) === null || _b === void 0 ? void 0 : _b.all) !== null && _c !== void 0 ? _c : [])];
56
+ return new models.MaintenanceTask(yield this.crypto.entities
57
+ .entityWithInitialisedEncryptedMetadata(maintenanceTask, undefined, undefined, true, extraDelegations)
58
+ .then((x) => x.updatedEntity));
66
59
  });
67
60
  }
68
61
  createMaintenanceTask(body) {
@@ -83,15 +76,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
83
76
  throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
84
77
  }
85
78
  deleteMaintenanceTaskWithUser(user, maintenanceTaskId) {
86
- return super.getMaintenanceTask(maintenanceTaskId).then((mt) => {
87
- var _a;
88
- return this.dataOwnerApi.hasAccessTo(user, (_a = mt.delegations) !== null && _a !== void 0 ? _a : {}).then((hasAccess) => {
89
- if (hasAccess)
90
- return super.deleteMaintenanceTask(maintenanceTaskId);
91
- else
92
- throw new Error('User does not have a delegation for this maintenanceTask');
93
- });
94
- });
79
+ return super.deleteMaintenanceTask(maintenanceTaskId);
95
80
  }
96
81
  filterMaintenanceTasksByWithUser(user, startDocumentId, limit, body) {
97
82
  return super
@@ -111,56 +96,42 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
111
96
  throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
112
97
  }
113
98
  modifyMaintenanceTaskWithUser(user, body) {
114
- return body
115
- ? this.encrypt(user, [_.cloneDeep(body)])
116
- .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))
117
- .then((mt) => this.decrypt(user, [mt]))
118
- .then((mts) => mts[0])
119
- : Promise.resolve(null);
99
+ return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null);
100
+ }
101
+ modifyAs(dataOwner, body) {
102
+ return this.encryptAs(dataOwner, [_.cloneDeep(body)])
103
+ .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))
104
+ .then((mt) => this.decryptAs(dataOwner, [mt]))
105
+ .then((mts) => mts[0]);
120
106
  }
121
107
  encrypt(user, maintenanceTasks) {
122
- const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
123
- return Promise.all(maintenanceTasks.map((m) => (m.encryptionKeys && Object.keys(m.encryptionKeys).some((k) => !!m.encryptionKeys[k].length)
124
- ? Promise.resolve(m)
125
- : this.initEncryptionKeys(user, m))
126
- .then((m) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, m.id, m.encryptionKeys))
127
- .then((sfks) => this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks.extractedKeys[0].replace(/-/g, ''))))
128
- .then((key) => (0, utils_1.crypt)(m, (obj) => this.crypto.AES.encrypt(key, (0, utils_1.utf8_2ua)(JSON.stringify(obj, (k, v) => {
129
- return v instanceof ArrayBuffer || v instanceof Uint8Array
130
- ? (0, ModelHelper_1.b2a)(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))
131
- : v;
132
- }))), this.encryptedKeys))));
108
+ return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks);
109
+ }
110
+ encryptAs(dataOwnerId, maintenanceTasks) {
111
+ return Promise.all(maintenanceTasks.map((m) => this.crypto.entities.tryEncryptEntity(m, dataOwnerId, this.encryptedKeys, true, true, (x) => new models.MaintenanceTask(x))));
133
112
  }
134
113
  decrypt(user, maintenanceTasks) {
135
- const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
136
- return Promise.all(maintenanceTasks.map((mT) => {
137
- var _a;
138
- return this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id, (_a = mT.encryptionKeys) !== null && _a !== void 0 ? _a : {}).then(({ extractedKeys: sfks }) => {
139
- if (!sfks || !sfks.length) {
140
- console.log('Cannot decrypt maintenanceTask', mT.id);
141
- return Promise.resolve(mT);
142
- }
143
- if (mT.encryptedSelf) {
144
- return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks[0].replace(/-/g, ''))).then((key) => new Promise((resolve) => this.crypto.AES.decrypt(key, (0, ModelHelper_1.string2ua)((0, ModelHelper_1.a2b)(mT.encryptedSelf))).then((dec) => {
145
- let jsonContent;
146
- try {
147
- jsonContent = dec && (0, utils_1.ua2utf8)(dec);
148
- jsonContent && _.assign(mT, JSON.parse(jsonContent));
149
- }
150
- catch (e) {
151
- console.log('Cannot parse mTask', mT.id, jsonContent || '<- Invalid encoding');
152
- }
153
- resolve(mT);
154
- }, () => {
155
- console.log('Cannot decrypt mTask', mT.id);
156
- resolve(mT);
157
- })));
158
- }
159
- else {
160
- return Promise.resolve(mT);
161
- }
162
- });
163
- }));
114
+ return this.decryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks);
115
+ }
116
+ decryptAs(dataOwnerId, maintenanceTasks) {
117
+ return Promise.all(maintenanceTasks.map((mT) => __awaiter(this, void 0, void 0, function* () { return this.crypto.entities.decryptEntity(mT, dataOwnerId, (x) => new models_1.MaintenanceTask(x)).then(({ entity }) => entity); })));
118
+ }
119
+ /**
120
+ * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also
121
+ * the encrypted content.
122
+ * @param delegateId the id of the data owner which will be granted access to the maintenance task.
123
+ * @param maintenanceTask the maintenance task to share.
124
+ * @param options optional parameters to customize the sharing behaviour:
125
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
126
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
127
+ * maintenance task does not have encrypted content.
128
+ * @return a promise which will contain the updated maintenance task
129
+ */
130
+ shareWith(delegateId, maintenanceTask, options = {}) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ const self = yield this.dataOwnerApi.getCurrentDataOwnerId();
133
+ return yield this.modifyAs(self, yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(maintenanceTask, delegateId, undefined, options.shareEncryptionKey, ShareMetadataBehaviour_1.ShareMetadataBehaviour.IF_AVAILABLE));
134
+ });
164
135
  }
165
136
  }
166
137
  exports.IccMaintenanceTaskXApi = IccMaintenanceTaskXApi;
@@ -1 +1 @@
1
- {"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;AAAA,gFAA4E;AAG5E,4BAA2B;AAC3B,8DAAkE;AAClE,mCAA0D;AAI1D,0EAAgG;AAEhG,MAAa,sBAAuB,SAAQ,6CAAqB;IAO/D,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,UAA0B,EAC1B,YAA8B,EAC9B,gBAA+B,EAAE,EACjC,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KA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MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,IAAA,uBAAS,EAAC,IAAA,iBAAG,EAAC,EAAE,CAAC,aAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAClE,CAAC,GAAG,EAAE,EAAE;wBACN,IAAI,WAAW,CAAA;wBACf,IAAI;4BACF,WAAW,GAAG,GAAG,IAAI,IAAA,eAAO,EAAC,GAAG,CAAC,CAAA;4BACjC,WAAW,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;yBACrD;wBAAC,OAAO,CAAC,EAAE;4BACV,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,IAAI,qBAAqB,CAAC,CAAA;yBAC/E;wBACD,OAAO,CAAC,EAAE,CAAC,CAAA;oBACb,CAAC,EACD,GAAG,EAAE;wBACH,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;wBAC1C,OAAO,CAAC,EAAE,CAAC,CAAA;oBACb,CAAC,CACF,CACF,CACJ,CAAA;iBACF;qBAAM;oBACL,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;iBAC3B;YACH,CAAC,CAAC,CAAA;SAAA,CACH,CACF,CAAA;IACH,CAAC;CACF;AAvOD,wDAuOC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { a2b, b2a, string2ua } from '../icc-api/model/ModelHelper'\nimport { hex2ua, ua2utf8, utf8_2ua, crypt } from './utils'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { DocIdentifier } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi {\n crypto: IccCryptoXApi\n hcPartyApi: IccHcpartyXApi\n dataOwnerApi: IccDataOwnerXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n hcPartyApi: IccHcpartyXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = [],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.hcPartyApi = hcPartyApi\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: models.User, m: any, delegates: string[] = []) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n const maintenanceTask = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n },\n m || {}\n )\n\n return this.initDelegations(user, maintenanceTask, delegates).then((task) => this.initEncryptionKeys(user, task, delegates))\n }\n\n initDelegations(user: models.User, maintenanceTask: models.MaintenanceTask, delegates: string[] = []): Promise<models.MaintenanceTask> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initObjectDelegations(maintenanceTask, null, dataOwnerId!, null).then((initData) => {\n _.extend(maintenanceTask, { delegations: initData.delegations })\n\n let promise = Promise.resolve(maintenanceTask)\n _.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach(\n (delegateId) =>\n (promise = promise\n .then((patient) => this.crypto.extendedDelegationsAndCryptedForeignKeys(patient, null, dataOwnerId!, delegateId, initData.secretId))\n .then((extraData) => _.extend(maintenanceTask, { delegations: extraData.delegations }))\n .catch((e) => {\n console.log(e)\n return maintenanceTask\n }))\n )\n return promise\n })\n }\n\n initEncryptionKeys(user: models.User, maintenanceTask: models.MaintenanceTask, delegates: string[] = []): Promise<models.MaintenanceTask> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(maintenanceTask, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(maintenanceTask, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n _.uniq(delegates.concat(user.autoDelegations ? user.autoDelegations.all || [] : [])).forEach(\n (delegateId) =>\n (promise = promise.then((patient) =>\n this.crypto\n .appendEncryptionKeys(patient, dataOwnerId!, delegateId, eks.secretId)\n .then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n .catch((e) => {\n console.log(e.message)\n return patient\n })\n ))\n )\n return promise\n })\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskIds: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<Array<DocIdentifier>> | never {\n return super.getMaintenanceTask(maintenanceTaskId).then((mt) => {\n return this.dataOwnerApi.hasAccessTo(user, mt.delegations ?? {}).then((hasAccess) => {\n if (hasAccess) return super.deleteMaintenanceTask(maintenanceTaskId)\n else throw new Error('User does not have a delegation for this maintenanceTask')\n })\n })\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask | any> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n : Promise.resolve(null)\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return Promise.all(\n maintenanceTasks.map((m) =>\n (m.encryptionKeys && Object.keys(m.encryptionKeys).some((k) => !!m.encryptionKeys![k].length)\n ? Promise.resolve(m)\n : this.initEncryptionKeys(user, m)\n )\n .then((m: models.MaintenanceTask) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId!, m.id!, m.encryptionKeys!))\n .then((sfks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(sfks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n crypt(\n m,\n (obj: { [key: string]: string }) =>\n this.crypto.AES.encrypt(\n key,\n utf8_2ua(\n JSON.stringify(obj, (k, v) => {\n return v instanceof ArrayBuffer || v instanceof Uint8Array\n ? b2a(new Uint8Array(v).reduce((d, b) => d + String.fromCharCode(b), ''))\n : v\n })\n )\n ),\n this.encryptedKeys\n )\n )\n )\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return Promise.all(\n maintenanceTasks.map((mT) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id!, mT.encryptionKeys ?? {}).then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n console.log('Cannot decrypt maintenanceTask', mT.id)\n return Promise.resolve(mT)\n }\n if (mT.encryptedSelf) {\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then(\n (key) =>\n new Promise((resolve: (value: any) => any) =>\n this.crypto.AES.decrypt(key, string2ua(a2b(mT.encryptedSelf!))).then(\n (dec) => {\n let jsonContent\n try {\n jsonContent = dec && ua2utf8(dec)\n jsonContent && _.assign(mT, JSON.parse(jsonContent))\n } catch (e) {\n console.log('Cannot parse mTask', mT.id, jsonContent || '<- Invalid encoding')\n }\n resolve(mT)\n },\n () => {\n console.log('Cannot decrypt mTask', mT.id)\n resolve(mT)\n }\n )\n )\n )\n } else {\n return Promise.resolve(mT)\n }\n })\n )\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gFAA4E;AAE5E,kDAAiD;AACjD,oDAAwE;AACxE,4BAA2B;AAG3B,0EAA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AC,CAAO,EAAE,EAAE,EAAE,gDAChC,OAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,wBAAe,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAA,GAAA,CAChH,CACF,CAAA;IACH,CAAC;IAED;;;;;;;;;;OAUG;IACG,SAAS,CACb,UAAkB,EAClB,eAAuC,EACvC,UAEI,EAAE;;YAEN,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAA;YAC5D,OAAO,MAAM,IAAI,CAAC,QAAQ,CACxB,IAAI,EACJ,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAChE,eAAe,EACf,UAAU,EACV,SAAS,EACT,OAAO,CAAC,kBAAkB,EAC1B,+CAAsB,CAAC,YAAY,CACpC,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAvLD,wDAuLC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport { DocIdentifier, MaintenanceTask } from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi {\n crypto: IccCryptoXApi\n hcPartyApi: IccHcpartyXApi\n dataOwnerApi: IccDataOwnerXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n hcPartyApi: IccHcpartyXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = [],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.hcPartyApi = hcPartyApi\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n /**\n * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param m initialised data for the maintenance task. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * @return a new instance of maintenance task.\n */\n async newInstance(\n user: models.User,\n m: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const maintenanceTask = _.assign(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n },\n m || {}\n )\n\n const extraDelegations = [...Object.keys(options.additionalDelegates ?? {}), ...(user.autoDelegations?.all ?? [])]\n return new models.MaintenanceTask(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(maintenanceTask, undefined, undefined, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskIds: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<Array<DocIdentifier>> | never {\n return super.deleteMaintenanceTask(maintenanceTaskId)\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n\n private modifyAs(dataOwner: string, body: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decryptAs(dataOwner, [mt]))\n .then((mts) => mts[0])\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks)\n }\n\n private encryptAs(dataOwnerId: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map((m) =>\n this.crypto.entities.tryEncryptEntity(m, dataOwnerId, this.encryptedKeys, true, true, (x) => new models.MaintenanceTask(x))\n )\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return this.decryptAs(this.dataOwnerApi.getDataOwnerIdOf(user), maintenanceTasks)\n }\n private decryptAs(dataOwnerId: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return Promise.all(\n maintenanceTasks.map(async (mT) =>\n this.crypto.entities.decryptEntity(mT, dataOwnerId, (x) => new MaintenanceTask(x)).then(({ entity }) => entity)\n )\n )\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the maintenance task.\n * @param maintenanceTask the maintenance task to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * @return a promise which will contain the updated maintenance task\n */\n async shareWith(\n delegateId: string,\n maintenanceTask: models.MaintenanceTask,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.MaintenanceTask> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n return await this.modifyAs(\n self,\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n maintenanceTask,\n delegateId,\n undefined,\n options.shareEncryptionKey,\n ShareMetadataBehaviour.IF_AVAILABLE\n )\n )\n }\n}\n"]}
@@ -3,12 +3,65 @@ import { IccCryptoXApi } from './icc-crypto-x-api';
3
3
  import { Patient, User } from '../icc-api/model/models';
4
4
  import { IccDataOwnerXApi } from './icc-data-owner-x-api';
5
5
  import { AuthenticationProvider } from './auth/AuthenticationProvider';
6
+ import * as models from '../icc-api/model/models';
7
+ import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour';
6
8
  export declare class IccMessageXApi extends IccMessageApi {
7
9
  private crypto;
8
10
  dataOwnerApi: IccDataOwnerXApi;
9
11
  constructor(host: string, headers: {
10
12
  [key: string]: string;
11
13
  }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
12
- newInstance(user: User, m: any): Promise<any>;
13
- newInstanceWithPatient(user: User, patient: Patient | null, m?: any, delegates?: string[]): Promise<any>;
14
+ newInstance(user: User, m: any): Promise<models.Message>;
15
+ /**
16
+ * Creates a new instance of message with initialised encryption metadata (not in the database).
17
+ * @param user the current user.
18
+ * @param patient the patient this message refers to.
19
+ * @param m initialised data for the message. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
20
+ * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
21
+ * @param options optional parameters:
22
+ * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
23
+ * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with
24
+ * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
25
+ * access will be possible.
26
+ * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
27
+ * secret id of patient known by the topmost parent in the current data owner hierarchy.
28
+ * @return a new instance of message.
29
+ */
30
+ newInstanceWithPatient(user: User, patient: Patient | null, m?: any, options?: {
31
+ additionalDelegates?: {
32
+ [dataOwnerId: string]: 'WRITE';
33
+ };
34
+ preferredSfk?: string;
35
+ }): Promise<models.Message>;
36
+ /**
37
+ * @param message a message
38
+ * @return the id of the patient that the message refers to, retrieved from the encrypted metadata. Normally there should only be one element
39
+ * in the returned array, but in case of entity merges there could be multiple values.
40
+ */
41
+ decryptPatientIdOf(message: models.Message): Promise<string[]>;
42
+ /**
43
+ * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also
44
+ * the encrypted content.
45
+ * @param delegateId the id of the data owner which will be granted access to the message.
46
+ * @param message the message to share.
47
+ * @param shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the
48
+ * shared Message is the owning entity id.
49
+ * @param options optional parameters to customize the sharing behaviour:
50
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
51
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
52
+ * message does not have encrypted content.
53
+ * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to
54
+ * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
55
+ * @return a promise which will contain the updated message
56
+ */
57
+ shareWith(delegateId: string, message: models.Message, shareSecretIds: string[], options?: {
58
+ shareEncryptionKey?: ShareMetadataBehaviour;
59
+ sharePatientId?: ShareMetadataBehaviour;
60
+ }): Promise<models.Message>;
61
+ /**
62
+ * @param message a message
63
+ * @return the secret ids of the message, retrieved from the encrypted metadata. The result may be used to find entities where the message is
64
+ * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.
65
+ */
66
+ decryptSecretIdsOf(message: models.Message): Promise<string[]>;
14
67
  }
@@ -1,9 +1,19 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.IccMessageXApi = void 0;
4
13
  const icc_api_1 = require("../icc-api");
5
14
  const _ = require("lodash");
6
15
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
16
+ const models = require("../icc-api/model/models");
7
17
  class IccMessageXApi extends icc_api_1.IccMessageApi {
8
18
  constructor(host, headers, crypto, dataOwnerApi, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
9
19
  ? window.fetch
@@ -19,41 +29,90 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
19
29
  newInstance(user, m) {
20
30
  return this.newInstanceWithPatient(user, null, m);
21
31
  }
22
- newInstanceWithPatient(user, patient, m = {}, delegates = []) {
23
- const message = _.extend({
24
- id: this.crypto.randomUuid(),
25
- _type: 'org.taktik.icure.entities.Message',
26
- created: new Date().getTime(),
27
- modified: new Date().getTime(),
28
- responsible: this.dataOwnerApi.getDataOwnerOf(user),
29
- author: user.id,
30
- codes: [],
31
- tags: [],
32
- }, m || {});
33
- const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
34
- return this.crypto
35
- .extractDelegationsSFKs(patient, dataOwnerId)
36
- .then((secretForeignKeys) => this.crypto.initObjectDelegations(message, patient, dataOwnerId, secretForeignKeys.extractedKeys[0]))
37
- .then((initData) => {
38
- _.extend(message, {
39
- delegations: initData.delegations,
40
- cryptedForeignKeys: initData.cryptedForeignKeys,
41
- secretForeignKeys: initData.secretForeignKeys,
42
- });
43
- let promise = Promise.resolve(message);
44
- _.uniq(delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])).forEach((delegateId) => (promise = promise.then((helement) => this.crypto
45
- .extendedDelegationsAndCryptedForeignKeys(helement, patient, dataOwnerId, delegateId, initData.secretId)
46
- .then((extraData) => _.extend(helement, {
47
- delegations: extraData.delegations,
48
- cryptedForeignKeys: extraData.cryptedForeignKeys,
49
- }))
50
- .catch((e) => {
51
- console.log(e);
52
- return helement;
53
- }))));
54
- return promise;
32
+ /**
33
+ * Creates a new instance of message with initialised encryption metadata (not in the database).
34
+ * @param user the current user.
35
+ * @param patient the patient this message refers to.
36
+ * @param m initialised data for the message. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify
37
+ * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.
38
+ * @param options optional parameters:
39
+ * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
40
+ * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with
41
+ * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read
42
+ * access will be possible.
43
+ * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a
44
+ * secret id of patient known by the topmost parent in the current data owner hierarchy.
45
+ * @return a new instance of message.
46
+ */
47
+ newInstanceWithPatient(user, patient, m = {}, options = {}) {
48
+ var _a, _b, _c, _d, _e, _f;
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ if (!patient && options.preferredSfk)
51
+ throw new Error('You need to specify parent patient in order to use secret foreign keys.');
52
+ const message = _.extend({
53
+ id: this.crypto.primitives.randomUuid(),
54
+ _type: 'org.taktik.icure.entities.Message',
55
+ created: new Date().getTime(),
56
+ modified: new Date().getTime(),
57
+ responsible: this.dataOwnerApi.getDataOwnerIdOf(user),
58
+ author: user.id,
59
+ codes: [],
60
+ tags: [],
61
+ }, m || {});
62
+ const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user);
63
+ if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
64
+ throw new Error('Can only initialise entities as current data owner.');
65
+ const sfk = patient ? (_a = options === null || options === void 0 ? void 0 : options.preferredSfk) !== null && _a !== void 0 ? _a : (yield this.crypto.confidential.getAnySecretIdSharedWithParents(patient)) : undefined;
66
+ if (patient && !sfk)
67
+ throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
68
+ const extraDelegations = [
69
+ ...Object.keys((_b = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _b !== void 0 ? _b : {}),
70
+ ...((_d = (_c = user.autoDelegations) === null || _c === void 0 ? void 0 : _c.all) !== null && _d !== void 0 ? _d : []),
71
+ ...((_f = (_e = user.autoDelegations) === null || _e === void 0 ? void 0 : _e.medicalInformation) !== null && _f !== void 0 ? _f : []),
72
+ ];
73
+ return new models.Message(yield this.crypto.entities
74
+ .entityWithInitialisedEncryptedMetadata(message, patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, extraDelegations)
75
+ .then((x) => x.updatedEntity));
55
76
  });
56
77
  }
78
+ /**
79
+ * @param message a message
80
+ * @return the id of the patient that the message refers to, retrieved from the encrypted metadata. Normally there should only be one element
81
+ * in the returned array, but in case of entity merges there could be multiple values.
82
+ */
83
+ decryptPatientIdOf(message) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ return this.crypto.entities.owningEntityIdsOf(message, undefined);
86
+ });
87
+ }
88
+ /**
89
+ * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also
90
+ * the encrypted content.
91
+ * @param delegateId the id of the data owner which will be granted access to the message.
92
+ * @param message the message to share.
93
+ * @param shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the
94
+ * shared Message is the owning entity id.
95
+ * @param options optional parameters to customize the sharing behaviour:
96
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
97
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
98
+ * message does not have encrypted content.
99
+ * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to
100
+ * {@link ShareMetadataBehaviour.IF_AVAILABLE}).
101
+ * @return a promise which will contain the updated message
102
+ */
103
+ shareWith(delegateId, message, shareSecretIds, options = {}) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ return yield this.modifyMessage(yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(message, delegateId, shareSecretIds, options.shareEncryptionKey, options.sharePatientId));
106
+ });
107
+ }
108
+ /**
109
+ * @param message a message
110
+ * @return the secret ids of the message, retrieved from the encrypted metadata. The result may be used to find entities where the message is
111
+ * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.
112
+ */
113
+ decryptSecretIdsOf(message) {
114
+ return this.crypto.entities.secretIdsOf(message, undefined);
115
+ }
57
116
  }
58
117
  exports.IccMessageXApi = IccMessageXApi;
59
118
  //# sourceMappingURL=icc-message-x-api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"icc-message-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-message-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAA0C;AAG1C,4BAA2B;AAI3B,0EAAgG;AAEhG,MAAa,cAAe,SAAQ,uBAAa;IAG/C,YACE,IAAY,EACZ,OAAkC,EAC1B,MAAqB,EAC7B,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAT/C,WAAM,GAAN,MAAM,CAA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AC,kBAAkB;gBAC/C,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;aAC9C,CAAC,CAAA;YAEF,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YACtC,CAAC,CAAC,IAAI,CACJ,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CACrI,CAAC,OAAO,CACP,CAAC,UAAU,EAAE,EAAE,CACb,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CACnC,IAAI,CAAC,MAAM;iBACR,wCAAwC,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAY,EAAE,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC;iBACxG,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAClB,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;gBACjB,WAAW,EAAE,SAAS,CAAC,WAAW;gBAClC,kBAAkB,EAAE,SAAS,CAAC,kBAAkB;aACjD,CAAC,CACH;iBACA,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBACd,OAAO,QAAQ,CAAA;YACjB,CAAC,CAAC,CACL,CAAC,CACL,CAAA;YACD,OAAO,OAAO,CAAA;QAChB,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AA3ED,wCA2EC","sourcesContent":["import { IccMessageApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\n\nimport { Patient, User } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccMessageXApi extends IccMessageApi {\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n // noinspection JSUnusedGlobalSymbols\n newInstance(user: User, m: any) {\n return this.newInstanceWithPatient(user, null, m)\n }\n\n newInstanceWithPatient(user: User, patient: Patient | null, m: any = {}, delegates: string[] = []) {\n const message = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Message',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n m || {}\n )\n\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId)\n .then((secretForeignKeys) => this.crypto.initObjectDelegations(message, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]))\n .then((initData) => {\n _.extend(message, {\n delegations: initData.delegations,\n cryptedForeignKeys: initData.cryptedForeignKeys,\n secretForeignKeys: initData.secretForeignKeys,\n })\n\n let promise = Promise.resolve(message)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((helement) =>\n this.crypto\n .extendedDelegationsAndCryptedForeignKeys(helement, patient, dataOwnerId!, delegateId, initData.secretId)\n .then((extraData) =>\n _.extend(helement, {\n delegations: extraData.delegations,\n cryptedForeignKeys: extraData.cryptedForeignKeys,\n })\n )\n .catch((e) => {\n console.log(e)\n return helement\n })\n ))\n )\n return promise\n })\n }\n}\n"]}
1
+ {"version":3,"file":"icc-message-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-message-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA0C;AAG1C,4BAA2B;AAI3B,0EAAgG;AAChG,kDAAiD;AAGjD,MAAa,cAAe,SAAQ,uBAAa;IAG/C,YACE,IAAY,EACZ,OAAkC,EAC1B,MAAqB,EAC7B,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAT/C,WAAM,GAAN,MAAM,CAAe;QAU7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,qCAAqC;IACrC,WAAW,CAAC,IAAU,EAAE,CAAM;QAC5B,OAAO,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACnD,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACG,sBAAsB,CAC1B,IAAU,EACV,OAAuB,EACvB,IAAS,EAAE,EACX,UAGI,EAAE;;;YAEN,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,YAAY;gBAAE,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAA;YAChI,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CACtB;gBACE,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE;gBACvC,KAAK,EAAE,mCAAmC;gBAC1C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;iBACvB,sCAAsC,CAAC,OAAO,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,gBAAgB,CAAC;iBACzF,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAChC,CAAA;;KACF;IAED;;;;OAIG;IACG,kBAAkB,CAAC,OAAuB;;YAC9C,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QACnE,CAAC;KAAA;IAED;;;;;;;;;;;;;;OAcG;IACG,SAAS,CACb,UAAkB,EAClB,OAAuB,EACvB,cAAwB,EACxB,UAGI,EAAE;;YAEN,OAAO,MAAM,IAAI,CAAC,aAAa,CAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAChE,OAAO,EACP,UAAU,EACV,cAAc,EACd,OAAO,CAAC,kBAAkB,EAC1B,OAAO,CAAC,cAAc,CACvB,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACH,kBAAkB,CAAC,OAAuB;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAC7D,CAAC;CACF;AApID,wCAoIC","sourcesContent":["import { IccMessageApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\n\nimport { Patient, User } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport * as models from '../icc-api/model/models'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\n\nexport class IccMessageXApi extends IccMessageApi {\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n // noinspection JSUnusedGlobalSymbols\n newInstance(user: User, m: any) {\n return this.newInstanceWithPatient(user, null, m)\n }\n\n /**\n * Creates a new instance of message with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this message refers to.\n * @param m initialised data for the message. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the classification. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * @return a new instance of message.\n */\n async newInstanceWithPatient(\n user: User,\n patient: Patient | null,\n m: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ) {\n if (!patient && options.preferredSfk) throw new Error('You need to specify parent patient in order to use secret foreign keys.')\n const message = _.extend(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.Message',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerIdOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n m || {}\n )\n\n const ownerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n if (ownerId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) throw new Error('Can only initialise entities as current data owner.')\n const sfk = patient ? options?.preferredSfk ?? (await this.crypto.confidential.getAnySecretIdSharedWithParents(patient)) : undefined\n if (patient && !sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = [\n ...Object.keys(options?.additionalDelegates ?? {}),\n ...(user.autoDelegations?.all ?? []),\n ...(user.autoDelegations?.medicalInformation ?? []),\n ]\n return new models.Message(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(message, patient?.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * @param message a message\n * @return the id of the patient that the message refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(message: models.Message): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(message, undefined)\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the message.\n * @param message the message to share.\n * @param shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated message\n */\n async shareWith(\n delegateId: string,\n message: models.Message,\n shareSecretIds: string[],\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Message> {\n return await this.modifyMessage(\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n message,\n delegateId,\n shareSecretIds,\n options.shareEncryptionKey,\n options.sharePatientId\n )\n )\n }\n\n /**\n * @param message a message\n * @return the secret ids of the message, retrieved from the encrypted metadata. The result may be used to find entities where the message is\n * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.\n */\n decryptSecretIdsOf(message: models.Message): Promise<string[]> {\n return this.crypto.entities.secretIdsOf(message, undefined)\n }\n}\n"]}