@icure/api 5.0.14 → 5.0.17

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 (60) hide show
  1. package/icc-api/api/IccCodeApi.d.ts +14 -1
  2. package/icc-api/api/IccCodeApi.js +33 -1
  3. package/icc-api/api/IccCodeApi.js.map +1 -1
  4. package/icc-api/model/UserGroup.d.ts +3 -0
  5. package/icc-api/model/UserGroup.js.map +1 -1
  6. package/icc-x-api/crypto/utils.d.ts +0 -0
  7. package/icc-x-api/crypto/utils.js +2 -0
  8. package/icc-x-api/crypto/utils.js.map +1 -0
  9. package/icc-x-api/icc-accesslog-x-api.d.ts +3 -3
  10. package/icc-x-api/icc-accesslog-x-api.js +11 -11
  11. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  12. package/icc-x-api/icc-calendar-item-x-api.d.ts +3 -3
  13. package/icc-x-api/icc-calendar-item-x-api.js +13 -13
  14. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  15. package/icc-x-api/icc-classification-x-api.d.ts +3 -3
  16. package/icc-x-api/icc-classification-x-api.js +4 -4
  17. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  18. package/icc-x-api/icc-contact-x-api.d.ts +3 -3
  19. package/icc-x-api/icc-contact-x-api.js +16 -16
  20. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  21. package/icc-x-api/icc-crypto-x-api.d.ts +10 -3
  22. package/icc-x-api/icc-crypto-x-api.js +29 -17
  23. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  24. package/icc-x-api/icc-data-owner-x-api.d.ts +14 -0
  25. package/icc-x-api/icc-data-owner-x-api.js +44 -0
  26. package/icc-x-api/icc-data-owner-x-api.js.map +1 -0
  27. package/icc-x-api/icc-document-x-api.d.ts +3 -3
  28. package/icc-x-api/icc-document-x-api.js +5 -5
  29. package/icc-x-api/icc-document-x-api.js.map +1 -1
  30. package/icc-x-api/icc-form-x-api.d.ts +3 -3
  31. package/icc-x-api/icc-form-x-api.js +5 -5
  32. package/icc-x-api/icc-form-x-api.js.map +1 -1
  33. package/icc-x-api/icc-helement-x-api.d.ts +3 -3
  34. package/icc-x-api/icc-helement-x-api.js +10 -10
  35. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  36. package/icc-x-api/icc-invoice-x-api.d.ts +3 -3
  37. package/icc-x-api/icc-invoice-x-api.js +5 -5
  38. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  39. package/icc-x-api/icc-maintenance-task-x-api.d.ts +6 -3
  40. package/icc-x-api/icc-maintenance-task-x-api.js +21 -7
  41. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  42. package/icc-x-api/icc-message-x-api.d.ts +3 -3
  43. package/icc-x-api/icc-message-x-api.js +4 -4
  44. package/icc-x-api/icc-message-x-api.js.map +1 -1
  45. package/icc-x-api/icc-patient-x-api.d.ts +3 -3
  46. package/icc-x-api/icc-patient-x-api.js +9 -9
  47. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  48. package/icc-x-api/icc-receipt-x-api.d.ts +3 -3
  49. package/icc-x-api/icc-receipt-x-api.js +5 -5
  50. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  51. package/icc-x-api/icc-time-table-x-api.d.ts +3 -3
  52. package/icc-x-api/icc-time-table-x-api.js +5 -5
  53. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  54. package/icc-x-api/icc-user-x-api.d.ts +0 -2
  55. package/icc-x-api/icc-user-x-api.js +0 -8
  56. package/icc-x-api/icc-user-x-api.js.map +1 -1
  57. package/icc-x-api/index.d.ts +2 -0
  58. package/icc-x-api/index.js +24 -19
  59. package/icc-x-api/index.js.map +1 -1
  60. package/package.json +1 -1
@@ -17,18 +17,18 @@ const moment = require("moment");
17
17
  const binary_utils_1 = require("./utils/binary-utils");
18
18
  const utils_1 = require("./utils");
19
19
  class IccHelementXApi extends icc_api_1.IccHelementApi {
20
- constructor(host, headers, crypto, userApi, encryptedKeys = ['descr', 'note'], fetchImpl = typeof window !== 'undefined'
20
+ constructor(host, headers, crypto, dataOwnerApi, encryptedKeys = ['descr', 'note'], fetchImpl = typeof window !== 'undefined'
21
21
  ? window.fetch
22
22
  : typeof self !== 'undefined'
23
23
  ? self.fetch
24
24
  : fetch) {
25
25
  super(host, headers, fetchImpl);
26
26
  this.crypto = crypto;
27
- this.userApi = userApi;
27
+ this.dataOwnerApi = dataOwnerApi;
28
28
  this.encryptedKeys = encryptedKeys;
29
29
  }
30
30
  newInstance(user, patient, h, confidential = false, delegates = []) {
31
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
31
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
32
32
  const helement = _.assign({
33
33
  id: this.crypto.randomUuid(),
34
34
  _type: 'org.taktik.icure.entities.HealthElement',
@@ -44,7 +44,7 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
44
44
  return this.initDelegationsAndEncryptionKeys(helement, patient, user, confidential, delegates);
45
45
  }
46
46
  initDelegationsAndEncryptionKeys(healthElement, patient, user, confidential, delegates = []) {
47
- let dataOwnerId = this.userApi.getDataOwnerOf(user);
47
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
48
48
  return this.crypto.extractPreferredSfk(patient, dataOwnerId, confidential).then((key) => __awaiter(this, void 0, void 0, function* () {
49
49
  if (!key) {
50
50
  console.error(`SFK cannot be found for Health element ${key}. The healthElement will not be reachable from the patient side`);
@@ -87,7 +87,7 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
87
87
  return bodies
88
88
  ? this.encrypt(user, bodies.map((c) => _.cloneDeep(c)))
89
89
  .then((hes) => super.createHealthElements(hes))
90
- .then((hes) => this.decrypt(this.userApi.getDataOwnerOf(user), hes))
90
+ .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))
91
91
  : Promise.resolve(null);
92
92
  }
93
93
  getHealthElement(healthElementId) {
@@ -103,7 +103,7 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
103
103
  throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption');
104
104
  }
105
105
  getHealthElementsWithUser(user, body) {
106
- return super.getHealthElements(body).then((hes) => this.decrypt(this.userApi.getDataOwnerOf(user), hes));
106
+ return super.getHealthElements(body).then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes));
107
107
  }
108
108
  newHealthElementDelegations(healthElementId, body) {
109
109
  throw new Error('Cannot call a method that returns health element without providing a user for de/encryption');
@@ -148,7 +148,7 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
148
148
  return bodies
149
149
  ? this.encrypt(user, bodies.map((c) => _.cloneDeep(c)))
150
150
  .then((hes) => super.modifyHealthElements(hes))
151
- .then((hes) => this.decrypt(this.userApi.getDataOwnerOf(user), hes))
151
+ .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))
152
152
  : Promise.resolve(null);
153
153
  }
154
154
  // noinspection JSUnusedGlobalSymbols
@@ -206,7 +206,7 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
206
206
  return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((helements) => this.decrypt(hcPartyId, helements));
207
207
  }
208
208
  encrypt(user, healthElements) {
209
- let dataOwnerId = this.userApi.getDataOwnerOf(user);
209
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
210
210
  return Promise.all(healthElements.map((he) => (he.encryptionKeys && Object.keys(he.encryptionKeys).some((k) => !!he.encryptionKeys[k].length)
211
211
  ? Promise.resolve(he)
212
212
  : this.initEncryptionKeys(user, he))
@@ -219,7 +219,7 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
219
219
  }))), this.encryptedKeys))));
220
220
  }
221
221
  initEncryptionKeys(user, he) {
222
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
222
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
223
223
  return this.crypto.initEncryptionKeys(he, dataOwnerId).then((eks) => {
224
224
  let promise = Promise.resolve(_.extend(he, {
225
225
  encryptionKeys: eks.encryptionKeys,
@@ -239,7 +239,7 @@ class IccHelementXApi extends icc_api_1.IccHelementApi {
239
239
  });
240
240
  }
241
241
  decryptWithUser(user, hes) {
242
- return this.decrypt(this.userApi.getDataOwnerOf(user), hes);
242
+ return this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes);
243
243
  }
244
244
  decrypt(dataOwnerId, hes) {
245
245
  return Promise.all(hes.map((he) => this.crypto
@@ -1 +1 @@
1
- {"version":3,"file":"icc-helement-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-helement-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA2C;AAG3C,kDAAiD;AAEjD,4BAA2B;AAC3B,iCAAgC;AAChC,uDAAqF;AAGrF,mCAA+B;AAE/B,MAAa,eAAgB,SAAQ,wBAAc;IAMjD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,OAAoB,EACpB,gBAA+B,CAAC,OAAO,EAAE,MAAM,CAAC,EAChD,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,SAAS,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED,WAAW,CAAC,IAAiB,EAAE,OAAuB,EAAE,CAAM,EAAE,YAAY,GAAG,KAAK,EAAE,YAAsB,EAAE;QAC5G,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QACrD,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAC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AC,EAAE,EAAE,EAAE;YACb,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,0DAA0D;IAC1D,YAAY,CAAC,IAAY;QACvB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC;YACrB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACV,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACV,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YACb,EAAE,EAAE,IAAI;SACT,CAAC,CAAA;IACJ,CAAC;CACF;AA1YD,0CA0YC","sourcesContent":["import { IccHelementApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport * as moment from 'moment'\nimport { a2b, b2a, hex2ua, string2ua, ua2utf8, utf8_2ua } from './utils/binary-utils'\nimport { HealthElement } from '../icc-api/model/models'\nimport { IccUserXApi } from './icc-user-x-api'\nimport { crypt } from './utils'\n\nexport class IccHelementXApi extends IccHelementApi {\n crypto: IccCryptoXApi\n userApi: IccUserXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n userApi: IccUserXApi,\n encryptedKeys: Array<string> = ['descr', 'note'],\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, fetchImpl)\n this.crypto = crypto\n this.userApi = userApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: models.User, patient: models.Patient, h: any, confidential = false, delegates: string[] = []) {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n const helement = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.HealthElement',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n healthElementId: this.crypto.randomUuid(),\n openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),\n },\n h || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(helement, patient, user, confidential, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n healthElement: models.HealthElement,\n patient: models.Patient,\n user: models.User,\n confidential: boolean,\n delegates: string[] = []\n ): Promise<models.HealthElement> {\n let dataOwnerId = this.userApi.getDataOwnerOf(user)\n\n return this.crypto.extractPreferredSfk(patient, dataOwnerId!, confidential).then(async (key) => {\n if (!key) {\n console.error(`SFK cannot be found for Health element ${key}. The healthElement will not be reachable from the patient side`)\n }\n const dels = await this.crypto.initObjectDelegations(healthElement, patient, dataOwnerId!, key ?? null)\n const eks = await this.crypto.initEncryptionKeys(healthElement, dataOwnerId!)\n _.extend(healthElement, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(healthElement)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, healthElement, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return healthElement\n })\n ))\n )\n ;(user.autoDelegations && user.autoDelegations.anonymousMedicalInformation ? user.autoDelegations.anonymousMedicalInformation : []).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, healthElement, dataOwnerId!, delegateId, null, eks.secretId).catch((e) => {\n console.log(e)\n return healthElement\n })\n ))\n )\n return promise\n })\n }\n\n createHealthElement(body?: models.HealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementWithUser(user: models.User, body?: models.HealthElement): Promise<models.HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.createHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n createHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementsWithUser(user: models.User, bodies?: models.HealthElement[]): Promise<models.HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.createHealthElements(hes))\n .then((hes) => this.decrypt(this.userApi.getDataOwnerOf(user), hes))\n : Promise.resolve(null)\n }\n\n getHealthElement(healthElementId: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n getHealthElementWithUser(user: models.User, healthElementId: string): Promise<models.HealthElement> {\n return super\n .getHealthElement(healthElementId)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n }\n\n getHealthElements(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n getHealthElementsWithUser(user: models.User, body?: models.ListOfIds): Promise<models.HealthElement[]> {\n return super.getHealthElements(body).then((hes) => this.decrypt(this.userApi.getDataOwnerOf(user), hes))\n }\n\n newHealthElementDelegations(healthElementId: string, body?: Array<models.Delegation>): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n newHealthElementDelegationsWithUser(user: models.User, healthElementId: string, body?: Array<models.Delegation>): Promise<models.HealthElement> {\n return super\n .newHealthElementDelegations(healthElementId, body)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((he) => he[0])\n }\n\n findHealthElementsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n findHealthElementsByHCPartyPatientForeignKeysWithUser(user: models.User, hcPartyId: string, secretFKeys: string): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n findHealthElementsByHCPartyAndPatientWithUser(user: models.User, hcPartyId: string, patient: models.Patient): Promise<models.HealthElement[]> {\n return this.crypto.extractSFKsHierarchyFromDelegations(patient, hcPartyId).then((keysAndHcPartyId) => {\n const keys = keysAndHcPartyId.find((secretForeignKeys) => secretForeignKeys.hcpartyId == hcPartyId)?.extractedKeys\n\n if (keys == undefined) {\n throw Error('No delegation for user')\n }\n\n return this.findHealthElementsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, keys.join(','))\n })\n }\n\n modifyHealthElement(body?: HealthElement): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise<HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.modifyHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n modifyHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n modifyHealthElementsWithUser(user: models.User, bodies?: HealthElement[]): Promise<HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.modifyHealthElements(hes))\n .then((hes) => this.decrypt(this.userApi.getDataOwnerOf(user), hes))\n : Promise.resolve(null)\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n */\n\n findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions = false) {\n return this.crypto\n .extractSFKsHierarchyFromDelegations(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.length > 0\n ? Promise.all(\n secretForeignKeys\n .reduce((acc, level) => {\n return acc.concat([\n {\n hcpartyId: level.hcpartyId,\n extractedKeys: level.extractedKeys.filter((key) => !acc.some((previousLevel) => previousLevel.extractedKeys.includes(key))),\n },\n ])\n }, [] as Array<{ hcpartyId: string; extractedKeys: Array<string> }>)\n .filter((l) => l.extractedKeys.length > 0)\n .map(({ hcpartyId, extractedKeys }) => this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(',')))\n ).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))\n : Promise.resolve([])\n )\n .then((decryptedHelements: Array<models.HealthElement>) => {\n const byIds: { [key: string]: models.HealthElement } = {}\n\n if (keepObsoleteVersions) {\n return decryptedHelements\n } else {\n decryptedHelements.forEach((he) => {\n if (he.healthElementId) {\n const phe = byIds[he.healthElementId]\n if (!phe || !phe.modified || (he.modified && phe.modified < he.modified)) {\n byIds[he.healthElementId] = he\n }\n }\n })\n return _.values(byIds).filter((s: any) => !s.endOfLife)\n }\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.Contact> | any> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n encrypt(user: models.User, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n let dataOwnerId = this.userApi.getDataOwnerOf(user)\n return Promise.all(\n healthElements.map((he) =>\n (he.encryptionKeys && Object.keys(he.encryptionKeys).some((k) => !!he.encryptionKeys![k].length)\n ? Promise.resolve(he)\n : this.initEncryptionKeys(user, he)\n )\n .then((healthElement: HealthElement) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, healthElement.id!, healthElement.encryptionKeys!)\n )\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 he,\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 initEncryptionKeys(user: models.User, he: models.HealthElement): Promise<models.HealthElement> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(he, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(he, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto\n .appendEncryptionKeys(healthElement, dataOwnerId!, delegateId, eks.secretId)\n .then((extraEks) => {\n return _.extend(healthElement, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n .catch((e) => {\n console.log(e.message)\n return healthElement\n })\n ))\n )\n return promise\n })\n }\n\n decryptWithUser(user: models.User, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.decrypt(this.userApi.getDataOwnerOf(user), hes)\n }\n\n decrypt(dataOwnerId: string, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return Promise.all(\n hes.map((he) =>\n this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, he.id!, _.size(he.encryptionKeys) ? he.encryptionKeys! : he.delegations!)\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n console.log('Cannot decrypt helement', he.id)\n return Promise.resolve(he)\n }\n if (he.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(he.encryptedSelf!))).then(\n (dec) => {\n let jsonContent\n try {\n jsonContent = dec && ua2utf8(dec)\n jsonContent && _.assign(he, JSON.parse(jsonContent))\n } catch (e) {\n console.log('Cannot parse he', he.id, jsonContent || '<- Invalid encoding')\n }\n resolve(he)\n },\n () => {\n console.log('Cannot decrypt health element', he.id)\n resolve(he)\n }\n )\n )\n )\n } else {\n return Promise.resolve(he)\n }\n })\n )\n )\n }\n\n // noinspection JSUnusedGlobalSymbols\n serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string) {\n return this.newInstance(user, patient, {\n idService: heSvc.id,\n author: heSvc.author,\n responsible: heSvc.responsible,\n openingDate: heSvc.valueDate || heSvc.openingDate,\n descr: descr,\n idOpeningContact: heSvc.contactId,\n modified: heSvc.modified,\n created: heSvc.created,\n codes: heSvc.codes,\n tags: heSvc.tags,\n }).then((he) => {\n return this.createHealthElement(he)\n })\n }\n\n // noinspection JSUnusedGlobalSymbols, JSMethodCanBeStatic\n stringToCode(code: string) {\n const c = code.split('|')\n return new models.Code({\n type: c[0],\n code: c[1],\n version: c[2],\n id: code,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"icc-helement-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-helement-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA2C;AAG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IACJ,CAAC;CACF;AA1YD,0CA0YC","sourcesContent":["import { IccHelementApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport * as moment from 'moment'\nimport { a2b, b2a, hex2ua, string2ua, ua2utf8, utf8_2ua } from './utils/binary-utils'\nimport { HealthElement } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { crypt } from './utils'\n\nexport class IccHelementXApi extends IccHelementApi {\n crypto: IccCryptoXApi\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 dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['descr', 'note'],\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, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: models.User, patient: models.Patient, h: any, confidential = false, delegates: string[] = []) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n const helement = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.HealthElement',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n healthElementId: this.crypto.randomUuid(),\n openingDate: parseInt(moment().format('YYYYMMDDHHmmss')),\n },\n h || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(helement, patient, user, confidential, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n healthElement: models.HealthElement,\n patient: models.Patient,\n user: models.User,\n confidential: boolean,\n delegates: string[] = []\n ): Promise<models.HealthElement> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.extractPreferredSfk(patient, dataOwnerId!, confidential).then(async (key) => {\n if (!key) {\n console.error(`SFK cannot be found for Health element ${key}. The healthElement will not be reachable from the patient side`)\n }\n const dels = await this.crypto.initObjectDelegations(healthElement, patient, dataOwnerId!, key ?? null)\n const eks = await this.crypto.initEncryptionKeys(healthElement, dataOwnerId!)\n _.extend(healthElement, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(healthElement)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, healthElement, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return healthElement\n })\n ))\n )\n ;(user.autoDelegations && user.autoDelegations.anonymousMedicalInformation ? user.autoDelegations.anonymousMedicalInformation : []).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, healthElement, dataOwnerId!, delegateId, null, eks.secretId).catch((e) => {\n console.log(e)\n return healthElement\n })\n ))\n )\n return promise\n })\n }\n\n createHealthElement(body?: models.HealthElement): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementWithUser(user: models.User, body?: models.HealthElement): Promise<models.HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.createHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n createHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n createHealthElementsWithUser(user: models.User, bodies?: models.HealthElement[]): Promise<models.HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.createHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n : Promise.resolve(null)\n }\n\n getHealthElement(healthElementId: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n getHealthElementWithUser(user: models.User, healthElementId: string): Promise<models.HealthElement> {\n return super\n .getHealthElement(healthElementId)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n }\n\n getHealthElements(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n getHealthElementsWithUser(user: models.User, body?: models.ListOfIds): Promise<models.HealthElement[]> {\n return super.getHealthElements(body).then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n }\n\n newHealthElementDelegations(healthElementId: string, body?: Array<models.Delegation>): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n newHealthElementDelegationsWithUser(user: models.User, healthElementId: string, body?: Array<models.Delegation>): Promise<models.HealthElement> {\n return super\n .newHealthElementDelegations(healthElementId, body)\n .then((he) => this.decryptWithUser(user, [he]))\n .then((he) => he[0])\n }\n\n findHealthElementsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n findHealthElementsByHCPartyPatientForeignKeysWithUser(user: models.User, hcPartyId: string, secretFKeys: string): Promise<HealthElement[]> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((hes) => this.decryptWithUser(user, hes))\n }\n\n findHealthElementsByHCPartyAndPatientWithUser(user: models.User, hcPartyId: string, patient: models.Patient): Promise<models.HealthElement[]> {\n return this.crypto.extractSFKsHierarchyFromDelegations(patient, hcPartyId).then((keysAndHcPartyId) => {\n const keys = keysAndHcPartyId.find((secretForeignKeys) => secretForeignKeys.hcpartyId == hcPartyId)?.extractedKeys\n\n if (keys == undefined) {\n throw Error('No delegation for user')\n }\n\n return this.findHealthElementsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, keys.join(','))\n })\n }\n\n modifyHealthElement(body?: HealthElement): never {\n throw new Error('Cannot call a method that returns health element without providing a user for de/encryption')\n }\n\n modifyHealthElementWithUser(user: models.User, body?: HealthElement): Promise<HealthElement | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((hes) => super.modifyHealthElement(hes[0]))\n .then((he) => this.decryptWithUser(user, [he]))\n .then((hes) => hes[0])\n : Promise.resolve(null)\n }\n\n modifyHealthElements(body?: Array<HealthElement>): never {\n throw new Error('Cannot call a method that returns health elements without providing a user for de/encryption')\n }\n\n modifyHealthElementsWithUser(user: models.User, bodies?: HealthElement[]): Promise<HealthElement[] | any> {\n return bodies\n ? this.encrypt(\n user,\n bodies.map((c) => _.cloneDeep(c))\n )\n .then((hes) => super.modifyHealthElements(hes))\n .then((hes) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes))\n : Promise.resolve(null)\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n */\n\n findBy(hcpartyId: string, patient: models.Patient, keepObsoleteVersions = false) {\n return this.crypto\n .extractSFKsHierarchyFromDelegations(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.length > 0\n ? Promise.all(\n secretForeignKeys\n .reduce((acc, level) => {\n return acc.concat([\n {\n hcpartyId: level.hcpartyId,\n extractedKeys: level.extractedKeys.filter((key) => !acc.some((previousLevel) => previousLevel.extractedKeys.includes(key))),\n },\n ])\n }, [] as Array<{ hcpartyId: string; extractedKeys: Array<string> }>)\n .filter((l) => l.extractedKeys.length > 0)\n .map(({ hcpartyId, extractedKeys }) => this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(',')))\n ).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))\n : Promise.resolve([])\n )\n .then((decryptedHelements: Array<models.HealthElement>) => {\n const byIds: { [key: string]: models.HealthElement } = {}\n\n if (keepObsoleteVersions) {\n return decryptedHelements\n } else {\n decryptedHelements.forEach((he) => {\n if (he.healthElementId) {\n const phe = byIds[he.healthElementId]\n if (!phe || !phe.modified || (he.modified && phe.modified < he.modified)) {\n byIds[he.healthElementId] = he\n }\n }\n })\n return _.values(byIds).filter((s: any) => !s.endOfLife)\n }\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.Contact> | any> {\n return super.findHealthElementsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((helements) => this.decrypt(hcPartyId, helements))\n }\n\n encrypt(user: models.User, healthElements: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return Promise.all(\n healthElements.map((he) =>\n (he.encryptionKeys && Object.keys(he.encryptionKeys).some((k) => !!he.encryptionKeys![k].length)\n ? Promise.resolve(he)\n : this.initEncryptionKeys(user, he)\n )\n .then((healthElement: HealthElement) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, healthElement.id!, healthElement.encryptionKeys!)\n )\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 he,\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 initEncryptionKeys(user: models.User, he: models.HealthElement): Promise<models.HealthElement> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(he, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(he, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((healthElement) =>\n this.crypto\n .appendEncryptionKeys(healthElement, dataOwnerId!, delegateId, eks.secretId)\n .then((extraEks) => {\n return _.extend(healthElement, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n .catch((e) => {\n console.log(e.message)\n return healthElement\n })\n ))\n )\n return promise\n })\n }\n\n decryptWithUser(user: models.User, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), hes)\n }\n\n decrypt(dataOwnerId: string, hes: Array<models.HealthElement>): Promise<Array<models.HealthElement>> {\n return Promise.all(\n hes.map((he) =>\n this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, he.id!, _.size(he.encryptionKeys) ? he.encryptionKeys! : he.delegations!)\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n console.log('Cannot decrypt helement', he.id)\n return Promise.resolve(he)\n }\n if (he.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(he.encryptedSelf!))).then(\n (dec) => {\n let jsonContent\n try {\n jsonContent = dec && ua2utf8(dec)\n jsonContent && _.assign(he, JSON.parse(jsonContent))\n } catch (e) {\n console.log('Cannot parse he', he.id, jsonContent || '<- Invalid encoding')\n }\n resolve(he)\n },\n () => {\n console.log('Cannot decrypt health element', he.id)\n resolve(he)\n }\n )\n )\n )\n } else {\n return Promise.resolve(he)\n }\n })\n )\n )\n }\n\n // noinspection JSUnusedGlobalSymbols\n serviceToHealthElement(user: models.User, patient: models.Patient, heSvc: models.Service, descr: string) {\n return this.newInstance(user, patient, {\n idService: heSvc.id,\n author: heSvc.author,\n responsible: heSvc.responsible,\n openingDate: heSvc.valueDate || heSvc.openingDate,\n descr: descr,\n idOpeningContact: heSvc.contactId,\n modified: heSvc.modified,\n created: heSvc.created,\n codes: heSvc.codes,\n tags: heSvc.tags,\n }).then((he) => {\n return this.createHealthElement(he)\n })\n }\n\n // noinspection JSUnusedGlobalSymbols, JSMethodCanBeStatic\n stringToCode(code: string) {\n const c = code.split('|')\n return new models.Code({\n type: c[0],\n code: c[1],\n version: c[2],\n id: code,\n })\n }\n}\n"]}
@@ -2,14 +2,14 @@ import { IccEntityrefApi, IccInvoiceApi } from '../icc-api';
2
2
  import { IccCryptoXApi } from './icc-crypto-x-api';
3
3
  import * as models from '../icc-api/model/models';
4
4
  import { Invoice } from '../icc-api/model/models';
5
- import { IccUserXApi } from './icc-user-x-api';
5
+ import { IccDataOwnerXApi } from './icc-data-owner-x-api';
6
6
  export declare class IccInvoiceXApi extends IccInvoiceApi {
7
7
  crypto: IccCryptoXApi;
8
8
  entityrefApi: IccEntityrefApi;
9
- userApi: IccUserXApi;
9
+ dataOwnerApi: IccDataOwnerXApi;
10
10
  constructor(host: string, headers: {
11
11
  [key: string]: string;
12
- }, crypto: IccCryptoXApi, entityrefApi: IccEntityrefApi, userApi: IccUserXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
12
+ }, crypto: IccCryptoXApi, entityrefApi: IccEntityrefApi, dataOwnerApi: IccDataOwnerXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
13
13
  newInstance(user: models.User, patient: models.Patient, inv?: any, delegates?: string[]): Promise<models.Invoice>;
14
14
  initEncryptionKeys(user: models.User, invoice: models.Invoice): Promise<models.Invoice & {
15
15
  encryptionKeys: any;
@@ -5,7 +5,7 @@ const icc_api_1 = require("../icc-api");
5
5
  const _ = require("lodash");
6
6
  const models = require("../icc-api/model/models");
7
7
  class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
8
- constructor(host, headers, crypto, entityrefApi, userApi, fetchImpl = typeof window !== 'undefined'
8
+ constructor(host, headers, crypto, entityrefApi, dataOwnerApi, fetchImpl = typeof window !== 'undefined'
9
9
  ? window.fetch
10
10
  : typeof self !== 'undefined'
11
11
  ? self.fetch
@@ -13,7 +13,7 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
13
13
  super(host, headers, fetchImpl);
14
14
  this.crypto = crypto;
15
15
  this.entityrefApi = entityrefApi;
16
- this.userApi = userApi;
16
+ this.dataOwnerApi = dataOwnerApi;
17
17
  }
18
18
  newInstance(user, patient, inv = {}, delegates = []) {
19
19
  const invoice = new models.Invoice(_.extend({
@@ -22,7 +22,7 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
22
22
  _type: 'org.taktik.icure.entities.Invoice',
23
23
  created: new Date().getTime(),
24
24
  modified: new Date().getTime(),
25
- responsible: this.userApi.getDataOwnerOf(user),
25
+ responsible: this.dataOwnerApi.getDataOwnerOf(user),
26
26
  author: user.id,
27
27
  codes: [],
28
28
  tags: [],
@@ -31,7 +31,7 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
31
31
  return this.initDelegationsAndEncryptionKeys(user, patient, invoice, delegates);
32
32
  }
33
33
  initEncryptionKeys(user, invoice) {
34
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
34
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
35
35
  return this.crypto.initEncryptionKeys(invoice, dataOwnerId).then((eks) => {
36
36
  let promise = Promise.resolve(_.extend(invoice, {
37
37
  encryptionKeys: eks.encryptionKeys,
@@ -45,7 +45,7 @@ class IccInvoiceXApi extends icc_api_1.IccInvoiceApi {
45
45
  });
46
46
  }
47
47
  initDelegationsAndEncryptionKeys(user, patient, invoice, delegates = []) {
48
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
48
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
49
49
  return this.crypto
50
50
  .extractDelegationsSFKs(patient, dataOwnerId)
51
51
  .then((secretForeignKeys) => Promise.all([
@@ -1 +1 @@
1
- {"version":3,"file":"icc-invoice-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-invoice-x-api.ts"],"names":[],"mappings":";;;AAAA,wCAA2D;AAG3D,4BAA2B;AAC3B,kDAAiD;AAIjD,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA6B,EAC7B,OAAoB,EACpB,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,SAAS,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,WAAW,CAAC,IAAiB,EAAE,OAAuB,EAAE,MAAW,EAAE,EAAE,YAAsB,EAAE;QAC7F,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,OAA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\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { Invoice } from '../icc-api/model/models'\nimport { IccUserXApi } from './icc-user-x-api'\n\nexport class IccInvoiceXApi extends IccInvoiceApi {\n crypto: IccCryptoXApi\n entityrefApi: IccEntityrefApi\n userApi: IccUserXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n entityrefApi: IccEntityrefApi,\n userApi: IccUserXApi,\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, fetchImpl)\n this.crypto = crypto\n this.entityrefApi = entityrefApi\n this.userApi = userApi\n }\n\n newInstance(user: models.User, patient: models.Patient, inv: any = {}, delegates: string[] = []): Promise<models.Invoice> {\n const invoice = new models.Invoice(\n _.extend(\n {\n id: this.crypto.randomUuid(),\n groupId: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Invoice',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.userApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n invoicingCodes: [],\n },\n inv || {}\n )\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, invoice, delegates)\n }\n\n initEncryptionKeys(user: models.User, invoice: models.Invoice) {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(invoice, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(invoice, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.financialInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((invoice) =>\n this.crypto.appendEncryptionKeys(invoice, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(invoice, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n private initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n invoice: models.Invoice,\n delegates: string[] = []\n ): Promise<models.Invoice> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(invoice, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(invoice, dataOwnerId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\n _.extend(invoice, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(invoice)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.financialInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((invoice) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, invoice, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return invoice\n })\n ))\n )\n return promise\n })\n }\n\n createInvoice(invoice: Invoice, prefix?: string): Promise<Invoice> {\n if (!prefix) {\n return super.createInvoice(invoice)\n }\n if (!invoice.id) {\n invoice.id = this.crypto.randomUuid()\n }\n return this.getNextInvoiceReference(prefix, this.entityrefApi)\n .then((reference) => this.createInvoiceReference(reference, invoice.id!, prefix, this.entityrefApi))\n .then((entityReference) => {\n if (!entityReference.id) {\n throw new Error('Cannot create invoice')\n }\n\n if (invoice.internshipNihii) {\n const ref = entityReference.id.substr(prefix.length).replace('0', '1')\n invoice.invoiceReference = ref\n } else {\n invoice.invoiceReference = entityReference.id.substr(prefix.length)\n }\n return super.createInvoice(invoice)\n })\n }\n\n getNextInvoiceReference(prefix: string, entityrefApi: IccEntityrefApi): Promise<number> {\n return entityrefApi.getLatest(prefix).then((entRef: models.EntityReference) => {\n if (!entRef || !entRef.id || !entRef.id!.startsWith(prefix)) return 1\n const sequenceNumber = entRef.id!.split(':').pop() || 0\n return Number(sequenceNumber) + 1\n })\n }\n\n createInvoiceReference(nextReference: number, docId: string, prefix: string, entityrefApi: IccEntityrefApi): Promise<models.EntityReference> {\n return entityrefApi\n .createEntityReference(\n new models.EntityReference({\n id: prefix + nextReference.toString().padStart(6, '0'),\n docId,\n })\n )\n .catch((err) => {\n console.log(err)\n return this.createInvoiceReference(nextReference + 1, docId, prefix, entityrefApi)\n })\n }\n\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all invoices with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the invoices of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n */\n findBy(hcpartyId: string, patient: models.Patient): Promise<Array<models.Invoice>> {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n this.findInvoicesByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n )\n .then((invoices) => this.decrypt(hcpartyId, invoices))\n .then(function (decryptedInvoices) {\n return decryptedInvoices\n })\n }\n\n encrypt(user: models.User, invoices: Array<models.Invoice>) {\n return Promise.resolve(invoices)\n }\n\n decrypt(hcpartyId: string, invoices: Array<models.Invoice>): Promise<Array<models.Invoice>> {\n return Promise.resolve(invoices)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-invoice-x-api.js","sourceRoot":"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I,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAC1B,IAAI,CAAC,uCAAuC,CAAC,iBAAiB,CAAC,SAAU,EAAE,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAC9H;aACA,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;aACrD,IAAI,CAAC,UAAU,iBAAiB;YAC/B,OAAO,iBAAiB,CAAA;QAC1B,CAAC,CAAC,CAAA;IACN,CAAC;IAED,OAAO,CAAC,IAAiB,EAAE,QAA+B;QACxD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,CAAC,SAAiB,EAAE,QAA+B;QACxD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;CACF;AA5LD,wCA4LC","sourcesContent":["import { IccEntityrefApi, IccInvoiceApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { Invoice } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\n\nexport class IccInvoiceXApi extends IccInvoiceApi {\n crypto: IccCryptoXApi\n entityrefApi: IccEntityrefApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n entityrefApi: IccEntityrefApi,\n dataOwnerApi: IccDataOwnerXApi,\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, fetchImpl)\n this.crypto = crypto\n this.entityrefApi = entityrefApi\n this.dataOwnerApi = dataOwnerApi\n }\n\n newInstance(user: models.User, patient: models.Patient, inv: any = {}, delegates: string[] = []): Promise<models.Invoice> {\n const invoice = new models.Invoice(\n _.extend(\n {\n id: this.crypto.randomUuid(),\n groupId: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Invoice',\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 invoicingCodes: [],\n },\n inv || {}\n )\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, invoice, delegates)\n }\n\n initEncryptionKeys(user: models.User, invoice: models.Invoice) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto.initEncryptionKeys(invoice, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(invoice, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.financialInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((invoice) =>\n this.crypto.appendEncryptionKeys(invoice, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(invoice, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n private initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient,\n invoice: models.Invoice,\n delegates: string[] = []\n ): Promise<models.Invoice> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(invoice, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(invoice, dataOwnerId!),\n ])\n )\n .then((initData) => {\n const dels = initData[0]\n const eks = initData[1]\n _.extend(invoice, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(invoice)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.financialInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((invoice) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, invoice, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return invoice\n })\n ))\n )\n return promise\n })\n }\n\n createInvoice(invoice: Invoice, prefix?: string): Promise<Invoice> {\n if (!prefix) {\n return super.createInvoice(invoice)\n }\n if (!invoice.id) {\n invoice.id = this.crypto.randomUuid()\n }\n return this.getNextInvoiceReference(prefix, this.entityrefApi)\n .then((reference) => this.createInvoiceReference(reference, invoice.id!, prefix, this.entityrefApi))\n .then((entityReference) => {\n if (!entityReference.id) {\n throw new Error('Cannot create invoice')\n }\n\n if (invoice.internshipNihii) {\n const ref = entityReference.id.substr(prefix.length).replace('0', '1')\n invoice.invoiceReference = ref\n } else {\n invoice.invoiceReference = entityReference.id.substr(prefix.length)\n }\n return super.createInvoice(invoice)\n })\n }\n\n getNextInvoiceReference(prefix: string, entityrefApi: IccEntityrefApi): Promise<number> {\n return entityrefApi.getLatest(prefix).then((entRef: models.EntityReference) => {\n if (!entRef || !entRef.id || !entRef.id!.startsWith(prefix)) return 1\n const sequenceNumber = entRef.id!.split(':').pop() || 0\n return Number(sequenceNumber) + 1\n })\n }\n\n createInvoiceReference(nextReference: number, docId: string, prefix: string, entityrefApi: IccEntityrefApi): Promise<models.EntityReference> {\n return entityrefApi\n .createEntityReference(\n new models.EntityReference({\n id: prefix + nextReference.toString().padStart(6, '0'),\n docId,\n })\n )\n .catch((err) => {\n console.log(err)\n return this.createInvoiceReference(nextReference + 1, docId, prefix, entityrefApi)\n })\n }\n\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all invoices with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the invoices of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n */\n findBy(hcpartyId: string, patient: models.Patient): Promise<Array<models.Invoice>> {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n this.findInvoicesByHCPartyPatientForeignKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n )\n .then((invoices) => this.decrypt(hcpartyId, invoices))\n .then(function (decryptedInvoices) {\n return decryptedInvoices\n })\n }\n\n encrypt(user: models.User, invoices: Array<models.Invoice>) {\n return Promise.resolve(invoices)\n }\n\n decrypt(hcpartyId: string, invoices: Array<models.Invoice>): Promise<Array<models.Invoice>> {\n return Promise.resolve(invoices)\n }\n}\n"]}
@@ -1,22 +1,25 @@
1
1
  import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi';
2
2
  import { IccCryptoXApi } from './icc-crypto-x-api';
3
- import { IccUserXApi } from './icc-user-x-api';
4
3
  import * as models from '../icc-api/model/models';
5
4
  import { IccHcpartyXApi } from './icc-hcparty-x-api';
5
+ import { DocIdentifier } from '../icc-api/model/models';
6
+ import { IccDataOwnerXApi } from './icc-data-owner-x-api';
6
7
  export declare class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi {
7
8
  crypto: IccCryptoXApi;
8
- userApi: IccUserXApi;
9
9
  hcPartyApi: IccHcpartyXApi;
10
+ dataOwnerApi: IccDataOwnerXApi;
10
11
  private readonly encryptedKeys;
11
12
  constructor(host: string, headers: {
12
13
  [key: string]: string;
13
- }, crypto: IccCryptoXApi, userApi: IccUserXApi, hcPartyApi: IccHcpartyXApi, encryptedKeys?: Array<string>, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
14
+ }, crypto: IccCryptoXApi, hcPartyApi: IccHcpartyXApi, dataOwnerApi: IccDataOwnerXApi, encryptedKeys?: Array<string>, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
14
15
  newInstance(user: models.User, m: any, delegates?: string[]): Promise<models.MaintenanceTask>;
15
16
  initDelegations(user: models.User, maintenanceTask: models.MaintenanceTask, delegates?: string[]): Promise<models.MaintenanceTask>;
16
17
  initEncryptionKeys(user: models.User, maintenanceTask: models.MaintenanceTask, delegates?: string[]): Promise<models.MaintenanceTask>;
17
18
  createMaintenanceTask(body?: models.MaintenanceTask): never;
18
19
  createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any>;
19
20
  filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never;
21
+ deleteMaintenanceTask(_maintenanceTaskIds: string): never;
22
+ deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<Array<DocIdentifier>> | never;
20
23
  filterMaintenanceTasksByWithUser(user: models.User, startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): Promise<models.PaginatedListMaintenanceTask | any>;
21
24
  getMaintenanceTask(maintenanceTaskId: string): never;
22
25
  getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any>;
@@ -6,19 +6,19 @@ const _ = require("lodash");
6
6
  const ModelHelper_1 = require("../icc-api/model/ModelHelper");
7
7
  const utils_1 = require("./utils");
8
8
  class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskApi {
9
- constructor(host, headers, crypto, userApi, hcPartyApi, encryptedKeys = [], fetchImpl = typeof window !== 'undefined'
9
+ constructor(host, headers, crypto, hcPartyApi, dataOwnerApi, encryptedKeys = [], fetchImpl = typeof window !== 'undefined'
10
10
  ? window.fetch
11
11
  : typeof self !== 'undefined'
12
12
  ? self.fetch
13
13
  : fetch) {
14
14
  super(host, headers, fetchImpl);
15
15
  this.crypto = crypto;
16
- this.userApi = userApi;
17
16
  this.hcPartyApi = hcPartyApi;
17
+ this.dataOwnerApi = dataOwnerApi;
18
18
  this.encryptedKeys = encryptedKeys;
19
19
  }
20
20
  newInstance(user, m, delegates = []) {
21
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
21
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
22
22
  const maintenanceTask = _.assign({
23
23
  id: this.crypto.randomUuid(),
24
24
  _type: 'org.taktik.icure.entities.MaintenanceTask',
@@ -30,7 +30,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
30
30
  return this.initDelegations(user, maintenanceTask, delegates).then((task) => this.initEncryptionKeys(user, task, delegates));
31
31
  }
32
32
  initDelegations(user, maintenanceTask, delegates = []) {
33
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
33
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
34
34
  return this.crypto.initObjectDelegations(maintenanceTask, null, dataOwnerId, null).then((initData) => {
35
35
  _.extend(maintenanceTask, { delegations: initData.delegations });
36
36
  let promise = Promise.resolve(maintenanceTask);
@@ -45,7 +45,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
45
45
  });
46
46
  }
47
47
  initEncryptionKeys(user, maintenanceTask, delegates = []) {
48
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
48
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
49
49
  return this.crypto.initEncryptionKeys(maintenanceTask, dataOwnerId).then((eks) => {
50
50
  let promise = Promise.resolve(_.extend(maintenanceTask, {
51
51
  encryptionKeys: eks.encryptionKeys,
@@ -78,6 +78,20 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
78
78
  filterMaintenanceTasksBy(startDocumentId, limit, body) {
79
79
  throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
80
80
  }
81
+ deleteMaintenanceTask(_maintenanceTaskIds) {
82
+ throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption');
83
+ }
84
+ deleteMaintenanceTaskWithUser(user, maintenanceTaskId) {
85
+ return super.getMaintenanceTask(maintenanceTaskId).then((mt) => {
86
+ var _a;
87
+ return this.dataOwnerApi.hasAccessTo(user, (_a = mt.delegations) !== null && _a !== void 0 ? _a : {}).then((hasAccess) => {
88
+ if (hasAccess)
89
+ return super.deleteMaintenanceTask(maintenanceTaskId);
90
+ else
91
+ throw new Error('User does not have a delegation for this maintenanceTask');
92
+ });
93
+ });
94
+ }
81
95
  filterMaintenanceTasksByWithUser(user, startDocumentId, limit, body) {
82
96
  return super
83
97
  .filterMaintenanceTasksBy(startDocumentId, limit, body)
@@ -104,7 +118,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
104
118
  : Promise.resolve(null);
105
119
  }
106
120
  encrypt(user, maintenanceTasks) {
107
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
121
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
108
122
  return Promise.all(maintenanceTasks.map((m) => (m.encryptionKeys && Object.keys(m.encryptionKeys).some((k) => !!m.encryptionKeys[k].length)
109
123
  ? Promise.resolve(m)
110
124
  : this.initEncryptionKeys(user, m))
@@ -117,7 +131,7 @@ class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi_1.IccMaintenanceTaskA
117
131
  }))), this.encryptedKeys))));
118
132
  }
119
133
  decrypt(user, maintenanceTasks) {
120
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
134
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
121
135
  return Promise.all(maintenanceTasks.map((mT) => {
122
136
  var _a;
123
137
  return this.crypto.extractKeysFromDelegationsForHcpHierarchy(dataOwnerId, mT.id, (_a = mT.encryptionKeys) !== null && _a !== void 0 ? _a : {}).then(({ extractedKeys: sfks }) => {
@@ -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;AAI5E,4BAA2B;AAC3B,8DAAkE;AAClE,mCAA0D;AAG1D,MAAa,sBAAuB,SAAQ,6CAAqB;IAO/D,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,OAAoB,EACpB,UAA0B,EAC1B,gBAA+B,EAAE,EACjC,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,SAAS,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED,WAAW,CAAC,IAAiB,EAAE,CAAM,EAAE,YAAsB,EAAE;QAC7D,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QACrD,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAC9B;YACE,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YAC5B,KAAK,EAAE,2CAA2C;YAClD,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC7B,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC9B,WAAW,EAAE,WAAW;YACxB,MAAM,EAA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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;AAzND,wDAyNC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccUserXApi } from './icc-user-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'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi {\n crypto: IccCryptoXApi\n userApi: IccUserXApi\n hcPartyApi: IccHcpartyXApi\n\n private readonly encryptedKeys: Array<string>\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n userApi: IccUserXApi,\n hcPartyApi: IccHcpartyXApi,\n encryptedKeys: Array<string> = [],\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, fetchImpl)\n this.crypto = crypto\n this.userApi = userApi\n this.hcPartyApi = hcPartyApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: models.User, m: any, delegates: string[] = []) {\n const dataOwnerId = this.userApi.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.userApi.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.userApi.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(patient, {\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 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.userApi.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.userApi.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;AAG5E,4BAA2B;AAC3B,8DAAkE;AAClE,mCAA0D;AAK1D,MAAa,sBAAuB,SAAQ,6CAAqB;IAO/D,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,UAA0B,EAC1B,YAA8B,EAC9B,gBAA+B,EAAE,EACjC,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,SAAS,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED,WAAW,CAAC,IAAiB,EAAE,CAAM,EAAE,YAAsB,EAAE;QAC7D,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,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AE,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;AAtOD,wDAsOC","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'\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 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, 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(patient, {\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,13 +1,13 @@
1
1
  import { IccMessageApi } from '../icc-api';
2
2
  import { IccCryptoXApi } from './icc-crypto-x-api';
3
3
  import { Patient, User } from '../icc-api/model/models';
4
- import { IccUserXApi } from './icc-user-x-api';
4
+ import { IccDataOwnerXApi } from './icc-data-owner-x-api';
5
5
  export declare class IccMessageXApi extends IccMessageApi {
6
6
  private crypto;
7
- userApi: IccUserXApi;
7
+ dataOwnerApi: IccDataOwnerXApi;
8
8
  constructor(host: string, headers: {
9
9
  [key: string]: string;
10
- }, crypto: IccCryptoXApi, userApi: IccUserXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
10
+ }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
11
11
  newInstance(user: User, m: any): Promise<any>;
12
12
  newInstanceWithPatient(user: User, patient: Patient | null, m?: any, delegates?: string[]): Promise<any>;
13
13
  }
@@ -4,7 +4,7 @@ exports.IccMessageXApi = void 0;
4
4
  const icc_api_1 = require("../icc-api");
5
5
  const _ = require("lodash");
6
6
  class IccMessageXApi extends icc_api_1.IccMessageApi {
7
- constructor(host, headers, crypto, userApi, fetchImpl = typeof window !== 'undefined'
7
+ constructor(host, headers, crypto, dataOwnerApi, fetchImpl = typeof window !== 'undefined'
8
8
  ? window.fetch
9
9
  : typeof self !== 'undefined'
10
10
  ? self.fetch
@@ -12,7 +12,7 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
12
12
  super(host, headers, fetchImpl);
13
13
  this.crypto = crypto;
14
14
  this.crypto = crypto;
15
- this.userApi = userApi;
15
+ this.dataOwnerApi = dataOwnerApi;
16
16
  }
17
17
  // noinspection JSUnusedGlobalSymbols
18
18
  newInstance(user, m) {
@@ -24,12 +24,12 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
24
24
  _type: 'org.taktik.icure.entities.Message',
25
25
  created: new Date().getTime(),
26
26
  modified: new Date().getTime(),
27
- responsible: this.userApi.getDataOwnerOf(user),
27
+ responsible: this.dataOwnerApi.getDataOwnerOf(user),
28
28
  author: user.id,
29
29
  codes: [],
30
30
  tags: [],
31
31
  }, m || {});
32
- const dataOwnerId = this.userApi.getDataOwnerOf(user);
32
+ const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
33
33
  return this.crypto
34
34
  .extractDelegationsSFKs(patient, dataOwnerId)
35
35
  .then((secretForeignKeys) => this.crypto.initObjectDelegations(message, patient, dataOwnerId, secretForeignKeys.extractedKeys[0]))