@icure/api 7.0.0-beta.2 → 7.0.0-beta.3

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 (59) hide show
  1. package/icc-api/api/IccDataownerApi.d.ts +13 -2
  2. package/icc-api/api/IccDataownerApi.js +30 -4
  3. package/icc-api/api/IccDataownerApi.js.map +1 -1
  4. package/icc-api/model/CryptoActorStub.d.ts +55 -0
  5. package/icc-api/model/CryptoActorStub.js +35 -0
  6. package/icc-api/model/CryptoActorStub.js.map +1 -0
  7. package/icc-api/model/DataOwnerTypeEnum.d.ts +8 -0
  8. package/icc-api/model/DataOwnerTypeEnum.js +13 -0
  9. package/icc-api/model/DataOwnerTypeEnum.js.map +1 -0
  10. package/icc-api/model/DataOwnerWithType.d.ts +16 -3
  11. package/icc-api/model/DataOwnerWithType.js +22 -7
  12. package/icc-api/model/DataOwnerWithType.js.map +1 -1
  13. package/icc-api/model/Device.d.ts +4 -0
  14. package/icc-api/model/Device.js.map +1 -1
  15. package/icc-api/model/HealthcareParty.d.ts +4 -0
  16. package/icc-api/model/HealthcareParty.js.map +1 -1
  17. package/icc-api/model/Patient.d.ts +4 -0
  18. package/icc-api/model/Patient.js.map +1 -1
  19. package/icc-x-api/crypto/AES.js +9 -1
  20. package/icc-x-api/crypto/AES.js.map +1 -1
  21. package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +4 -2
  22. package/icc-x-api/crypto/BaseExchangeKeysManager.js +32 -31
  23. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
  24. package/icc-x-api/crypto/CryptoStrategies.d.ts +5 -4
  25. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -1
  26. package/icc-x-api/crypto/EntitiesEncryption.js +2 -2
  27. package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -1
  28. package/icc-x-api/crypto/ExchangeKeysManager.d.ts +3 -2
  29. package/icc-x-api/crypto/ExchangeKeysManager.js +3 -3
  30. package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -1
  31. package/icc-x-api/crypto/KeyManager.js +4 -4
  32. package/icc-x-api/crypto/KeyManager.js.map +1 -1
  33. package/icc-x-api/crypto/KeyRecovery.d.ts +2 -1
  34. package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
  35. package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +5 -4
  36. package/icc-x-api/crypto/LegacyCryptoStrategies.js +1 -1
  37. package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -1
  38. package/icc-x-api/crypto/ShamirKeysManager.d.ts +4 -3
  39. package/icc-x-api/crypto/ShamirKeysManager.js +8 -7
  40. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
  41. package/icc-x-api/crypto/TransferKeysManager.d.ts +3 -2
  42. package/icc-x-api/crypto/TransferKeysManager.js +6 -6
  43. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
  44. package/icc-x-api/crypto/utils.d.ts +7 -6
  45. package/icc-x-api/crypto/utils.js +4 -7
  46. package/icc-x-api/crypto/utils.js.map +1 -1
  47. package/icc-x-api/icc-calendar-item-x-api.js +3 -0
  48. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  49. package/icc-x-api/icc-crypto-x-api.d.ts +6 -6
  50. package/icc-x-api/icc-crypto-x-api.js +4 -4
  51. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  52. package/icc-x-api/icc-data-owner-x-api.d.ts +21 -52
  53. package/icc-x-api/icc-data-owner-x-api.js +36 -68
  54. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  55. package/icc-x-api/icc-icure-maintenance-x-api.js +4 -4
  56. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
  57. package/icc-x-api/index.js +4 -3
  58. package/icc-x-api/index.js.map +1 -1
  59. package/package.json +1 -1
@@ -1,15 +1,16 @@
1
1
  import { StronglyConnectedGraph } from '../utils/graph-utils';
2
- import { DataOwner, DataOwnerWithType, IccDataOwnerXApi } from '../icc-data-owner-x-api';
2
+ import { DataOwnerOrStub, IccDataOwnerXApi } from '../icc-data-owner-x-api';
3
3
  import { RSAUtils } from './RSA';
4
4
  import { EntitiesEncryption } from './EntitiesEncryption';
5
5
  import { CryptoPrimitives } from './CryptoPrimitives';
6
- import { EncryptedEntityStub } from '../../icc-api/model/models';
6
+ import { DataOwnerWithType, EncryptedEntityStub } from '../../icc-api/model/models';
7
+ import { IccPatientApi } from '../../icc-api';
7
8
  /**
8
9
  * @internal this function is meant only for internal use and may be changed without notice.
9
10
  * Get the public keys of a data owner, same as {@link dataOwnerApi.getHexPublicKeysOf}.
10
11
  * @param dataOwner
11
12
  */
12
- export declare function hexPublicKeysOf(dataOwner: DataOwner): Set<string>;
13
+ export declare function hexPublicKeysOf(dataOwner: DataOwnerOrStub): Set<string>;
13
14
  /**
14
15
  * @internal this function is meant only for internal use and may be changed without notice.
15
16
  * Get the transfer key graph for a data owner. Node names are the public key fingerprints of the data owner's keys, and an edge represents a key
@@ -17,14 +18,14 @@ export declare function hexPublicKeysOf(dataOwner: DataOwner): Set<string>;
17
18
  * @param dataOwner a data owner.
18
19
  * @return a graph representing the possible key recovery paths using transfer keys for hte provided data owner.
19
20
  */
20
- export declare function transferKeysFpGraphOf(dataOwner: DataOwner): StronglyConnectedGraph;
21
+ export declare function transferKeysFpGraphOf(dataOwner: DataOwnerOrStub): StronglyConnectedGraph;
21
22
  /**
22
23
  * @internal this function is meant only for internal use and may be changed without notice.
23
24
  * Get a map for converting public keys fingerprint to full public keys for the provided data owner.
24
25
  * @param dataOwner a data owner.
25
26
  * @return a map to convert fingerprints of the data owner into full public keys.
26
27
  */
27
- export declare function fingerprintToPublicKeysMapOf(dataOwner: DataOwner): {
28
+ export declare function fingerprintToPublicKeysMapOf(dataOwner: DataOwnerOrStub): {
28
29
  [fp: string]: string;
29
30
  };
30
31
  /**
@@ -42,5 +43,5 @@ export declare function loadPublicKeys(rsa: RSAUtils, publicKeysSpkiHex: string[
42
43
  * Creates a delegation for the current data owner if the data owner is an encrypted entity and there is no delegation to himself.
43
44
  * @return the updated self.
44
45
  */
45
- export declare function ensureDelegationForSelf(dataOwnerApi: IccDataOwnerXApi, entitiesEncryption: EntitiesEncryption, cryptoPrimitives: CryptoPrimitives): Promise<DataOwnerWithType>;
46
+ export declare function ensureDelegationForSelf(dataOwnerApi: IccDataOwnerXApi, entitiesEncryption: EntitiesEncryption, cryptoPrimitives: CryptoPrimitives, basePatientApi: IccPatientApi): Promise<DataOwnerWithType>;
46
47
  export declare function encryptedStubEquals(a: EncryptedEntityStub, b: EncryptedEntityStub): boolean;
@@ -12,9 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.encryptedStubEquals = exports.ensureDelegationForSelf = exports.loadPublicKeys = exports.fingerprintToPublicKeysMapOf = exports.transferKeysFpGraphOf = exports.hexPublicKeysOf = void 0;
13
13
  // Uses fp as node names
14
14
  const graph_utils_1 = require("../utils/graph-utils");
15
- const icc_data_owner_x_api_1 = require("../icc-data-owner-x-api");
16
15
  const utils_1 = require("../utils");
17
16
  const collection_utils_1 = require("../utils/collection-utils");
17
+ const DataOwnerTypeEnum_1 = require("../../icc-api/model/DataOwnerTypeEnum");
18
18
  /**
19
19
  * @internal this function is meant only for internal use and may be changed without notice.
20
20
  * Get the public keys of a data owner, same as {@link dataOwnerApi.getHexPublicKeysOf}.
@@ -77,11 +77,11 @@ exports.loadPublicKeys = loadPublicKeys;
77
77
  * Creates a delegation for the current data owner if the data owner is an encrypted entity and there is no delegation to himself.
78
78
  * @return the updated self.
79
79
  */
80
- function ensureDelegationForSelf(dataOwnerApi, entitiesEncryption, cryptoPrimitives) {
80
+ function ensureDelegationForSelf(dataOwnerApi, entitiesEncryption, cryptoPrimitives, basePatientApi) {
81
81
  var _a, _b;
82
82
  return __awaiter(this, void 0, void 0, function* () {
83
83
  const self = yield dataOwnerApi.getCurrentDataOwner();
84
- if (self.type === icc_data_owner_x_api_1.DataOwnerTypeEnum.Patient) {
84
+ if (self.type === DataOwnerTypeEnum_1.DataOwnerTypeEnum.Patient) {
85
85
  const patient = self.dataOwner;
86
86
  const availableSecretIds = yield entitiesEncryption.secretIdsOf(patient);
87
87
  if (availableSecretIds.length) {
@@ -93,10 +93,7 @@ function ensureDelegationForSelf(dataOwnerApi, entitiesEncryption, cryptoPrimiti
93
93
  // If there is already something initialise only a new delegation to self
94
94
  patient, patient.id, [cryptoPrimitives.randomUuid()], [], []) // else initialise also encryption keys
95
95
  : yield entitiesEncryption.entityWithInitialisedEncryptedMetadata(patient, undefined, undefined, true).then((x) => x.updatedEntity);
96
- return yield dataOwnerApi.updateDataOwner({
97
- dataOwner: updatedPatient,
98
- type: icc_data_owner_x_api_1.DataOwnerTypeEnum.Patient,
99
- });
96
+ return yield basePatientApi.modifyPatient(updatedPatient).then((x) => ({ dataOwner: x, type: DataOwnerTypeEnum_1.DataOwnerTypeEnum.Patient }));
100
97
  }
101
98
  }
102
99
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wBAAwB;AACxB,sDAAsF;AACtF,kEAA2G;AAE3G,oCAAiC;AAOjC,gEAAqD;AAErD;;;;GAIG;AACH,SAAgB,eAAe,CAAC,SAAoB;;IAClD,OAAO,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAA,SAAS,CAAC,eAAe,mCAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAa,CAAC,CAAA;AACjI,CAAC;AAFD,0CAEC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,SAAoB;;IACxD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAA;IACzD,MAAM,KAAK,GAAuB,EAAE,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AAD,CAAC,cAAD,CAAC,GAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QACjC,IACE,CAAC,YAAY,CAAC,KAAK,CACjB,CAAC,EAAE,EAAE,EAAE,CACL,CAAC,CAAC,YAAY,CAAC,IAAI,CACjB,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,WAAW,KAAK,EAAE,CAAC,WAAW,IAAI,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,KAAK,IAAI,IAAA,4BAAS,EAAC,IAAI,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CACzI,CACJ;YAED,OAAO,KAAK,CAAA;KACf;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["// Uses fp as node names\nimport { acyclic, graphFromEdges, StronglyConnectedGraph } from '../utils/graph-utils'\nimport { DataOwner, DataOwnerTypeEnum, DataOwnerWithType, IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { RSAUtils } from './RSA'\nimport { hex2ua } from '../utils'\nimport { HealthcareParty } from '../../icc-api/model/HealthcareParty'\nimport { Patient } from '../../icc-api/model/Patient'\nimport { Device } from '../../icc-api/model/Device'\nimport { EntitiesEncryption } from './EntitiesEncryption'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { Delegation, EncryptedEntityStub } from '../../icc-api/model/models'\nimport { setEquals } from '../utils/collection-utils'\n\n/**\n * @internal this function is meant only for internal use and may be changed without notice.\n * Get the public keys of a data owner, same as {@link dataOwnerApi.getHexPublicKeysOf}.\n * @param dataOwner\n */\nexport function hexPublicKeysOf(dataOwner: DataOwner) {\n return new Set([dataOwner.publicKey, ...Object.keys(dataOwner.aesExchangeKeys ?? {})].filter((pubKey) => !!pubKey) as string[])\n}\n\n/**\n * @internal this function is meant only for internal use and may be changed without notice.\n * Get the transfer key graph for a data owner. Node names are the public key fingerprints of the data owner's keys, and an edge represents a key\n * which can be retrieved from another key using the transfer keys.\n * @param dataOwner a data owner.\n * @return a graph representing the possible key recovery paths using transfer keys for hte provided data owner.\n */\nexport function transferKeysFpGraphOf(dataOwner: DataOwner): StronglyConnectedGraph {\n const publicKeys = Array.from(hexPublicKeysOf(dataOwner))\n const edges: [string, string][] = []\n Object.entries(dataOwner.transferKeys ?? {}).forEach(([from, tos]) => {\n Object.keys(tos).forEach((to) => {\n edges.push([from.slice(-32), to.slice(-32)])\n })\n })\n return acyclic(\n graphFromEdges(\n edges,\n publicKeys.map((x) => x.slice(-32))\n )\n )\n}\n\n/**\n * @internal this function is meant only for internal use and may be changed without notice.\n * Get a map for converting public keys fingerprint to full public keys for the provided data owner.\n * @param dataOwner a data owner.\n * @return a map to convert fingerprints of the data owner into full public keys.\n */\nexport function fingerprintToPublicKeysMapOf(dataOwner: DataOwner): { [fp: string]: string } {\n const publicKeys = Array.from(hexPublicKeysOf(dataOwner))\n const res: { [fp: string]: string } = {}\n publicKeys.forEach((pk) => {\n res[pk.slice(-32)] = pk\n })\n return res\n}\n\n/**\n * @internal this function is meant only for internal use and may be changed without notice.\n * Load many public keys in spki format.\n * @param rsa the rsa service\n * @param publicKeysSpkiHex public keys in spki format, hex encoded.\n * @return public keys as crypto keys by their fingerprint.\n */\nexport async function loadPublicKeys(rsa: RSAUtils, publicKeysSpkiHex: string[]): Promise<{ [publicKeyFingerprint: string]: CryptoKey }> {\n return Object.fromEntries(\n await Promise.all(publicKeysSpkiHex.map(async (x) => [x.slice(-32), await rsa.importKey('spki', hex2ua(x), ['encrypt'])]))\n )\n}\n\n/**\n * @internal This method is intended only for internal use and may be changed without notice.\n * Creates a delegation for the current data owner if the data owner is an encrypted entity and there is no delegation to himself.\n * @return the updated self.\n */\nexport async function ensureDelegationForSelf(\n dataOwnerApi: IccDataOwnerXApi,\n entitiesEncryption: EntitiesEncryption,\n cryptoPrimitives: CryptoPrimitives\n): Promise<DataOwnerWithType> {\n const self = await dataOwnerApi.getCurrentDataOwner()\n if (self.type === DataOwnerTypeEnum.Patient) {\n const patient: Patient & DataOwner = self.dataOwner\n const availableSecretIds = await entitiesEncryption.secretIdsOf(patient)\n if (availableSecretIds.length) {\n return self\n } else {\n const updatedPatient =\n Object.entries(patient.encryptionKeys ?? {}).length || Object.entries(patient.delegations ?? {}).length\n ? await entitiesEncryption.entityWithExtendedEncryptedMetadata(\n // If there is already something initialise only a new delegation to self\n patient,\n patient.id!,\n [cryptoPrimitives.randomUuid()],\n [],\n []\n ) // else initialise also encryption keys\n : await entitiesEncryption.entityWithInitialisedEncryptedMetadata(patient, undefined, undefined, true).then((x) => x.updatedEntity)\n return await dataOwnerApi.updateDataOwner({\n dataOwner: updatedPatient,\n type: DataOwnerTypeEnum.Patient,\n })\n }\n } else {\n return self\n }\n}\n\nexport function encryptedStubEquals(a: EncryptedEntityStub, b: EncryptedEntityStub): boolean {\n if (!delegationLikeEquality(a.delegations, b.delegations)) return false\n if (!delegationLikeEquality(a.encryptionKeys, b.encryptionKeys)) return false\n if (!delegationLikeEquality(a.cryptedForeignKeys, b.cryptedForeignKeys)) return false\n if (!setEquals(new Set(a.secretForeignKeys), new Set(b.secretForeignKeys))) return false\n return a.encryptedSelf === b.encryptedSelf\n}\n\nfunction delegationLikeEquality(a: { [s: string]: Delegation[] } | undefined, b: { [s: string]: Delegation[] } | undefined): boolean {\n if (!setEquals(new Set(Object.keys(a ?? {})), new Set(Object.keys(b ?? {})))) return false\n for (const [k, aDelegations] of Object.entries(a ?? {})) {\n const bDelegations = (b ?? {})[k]\n if (\n !aDelegations.every(\n (da) =>\n !!bDelegations.find(\n (db) => da.key === db.key && da.delegatedTo === db.delegatedTo && da.owner === db.owner && setEquals(new Set(da.tags), new Set(db.tags))\n )\n )\n )\n return false\n }\n return true\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,w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wnerOrStub, IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { RSAUtils } from './RSA'\nimport { hex2ua } from '../utils'\nimport { HealthcareParty } from '../../icc-api/model/HealthcareParty'\nimport { Patient } from '../../icc-api/model/Patient'\nimport { Device } from '../../icc-api/model/Device'\nimport { EntitiesEncryption } from './EntitiesEncryption'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { DataOwnerWithType, Delegation, EncryptedEntityStub } from '../../icc-api/model/models'\nimport { setEquals } from '../utils/collection-utils'\nimport { DataOwnerTypeEnum } from '../../icc-api/model/DataOwnerTypeEnum'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { IccPatientApi } from '../../icc-api'\n\n/**\n * @internal this function is meant only for internal use and may be changed without notice.\n * Get the public keys of a data owner, same as {@link dataOwnerApi.getHexPublicKeysOf}.\n * @param dataOwner\n */\nexport function hexPublicKeysOf(dataOwner: DataOwnerOrStub) {\n return new Set([dataOwner.publicKey, ...Object.keys(dataOwner.aesExchangeKeys ?? {})].filter((pubKey) => !!pubKey) as string[])\n}\n\n/**\n * @internal this function is meant only for internal use and may be changed without notice.\n * Get the transfer key graph for a data owner. Node names are the public key fingerprints of the data owner's keys, and an edge represents a key\n * which can be retrieved from another key using the transfer keys.\n * @param dataOwner a data owner.\n * @return a graph representing the possible key recovery paths using transfer keys for hte provided data owner.\n */\nexport function transferKeysFpGraphOf(dataOwner: DataOwnerOrStub): StronglyConnectedGraph {\n const publicKeys = Array.from(hexPublicKeysOf(dataOwner))\n const edges: [string, string][] = []\n Object.entries(dataOwner.transferKeys ?? {}).forEach(([from, tos]) => {\n Object.keys(tos).forEach((to) => {\n edges.push([from.slice(-32), to.slice(-32)])\n })\n })\n return acyclic(\n graphFromEdges(\n edges,\n publicKeys.map((x) => x.slice(-32))\n )\n )\n}\n\n/**\n * @internal this function is meant only for internal use and may be changed without notice.\n * Get a map for converting public keys fingerprint to full public keys for the provided data owner.\n * @param dataOwner a data owner.\n * @return a map to convert fingerprints of the data owner into full public keys.\n */\nexport function fingerprintToPublicKeysMapOf(dataOwner: DataOwnerOrStub): { [fp: string]: string } {\n const publicKeys = Array.from(hexPublicKeysOf(dataOwner))\n const res: { [fp: string]: string } = {}\n publicKeys.forEach((pk) => {\n res[pk.slice(-32)] = pk\n })\n return res\n}\n\n/**\n * @internal this function is meant only for internal use and may be changed without notice.\n * Load many public keys in spki format.\n * @param rsa the rsa service\n * @param publicKeysSpkiHex public keys in spki format, hex encoded.\n * @return public keys as crypto keys by their fingerprint.\n */\nexport async function loadPublicKeys(rsa: RSAUtils, publicKeysSpkiHex: string[]): Promise<{ [publicKeyFingerprint: string]: CryptoKey }> {\n return Object.fromEntries(\n await Promise.all(publicKeysSpkiHex.map(async (x) => [x.slice(-32), await rsa.importKey('spki', hex2ua(x), ['encrypt'])]))\n )\n}\n\n/**\n * @internal This method is intended only for internal use and may be changed without notice.\n * Creates a delegation for the current data owner if the data owner is an encrypted entity and there is no delegation to himself.\n * @return the updated self.\n */\nexport async function ensureDelegationForSelf(\n dataOwnerApi: IccDataOwnerXApi,\n entitiesEncryption: EntitiesEncryption,\n cryptoPrimitives: CryptoPrimitives,\n basePatientApi: IccPatientApi\n): Promise<DataOwnerWithType> {\n const self = await dataOwnerApi.getCurrentDataOwner()\n if (self.type === DataOwnerTypeEnum.Patient) {\n const patient: Patient = self.dataOwner\n const availableSecretIds = await entitiesEncryption.secretIdsOf(patient)\n if (availableSecretIds.length) {\n return self\n } else {\n const updatedPatient =\n Object.entries(patient.encryptionKeys ?? {}).length || Object.entries(patient.delegations ?? {}).length\n ? await entitiesEncryption.entityWithExtendedEncryptedMetadata(\n // If there is already something initialise only a new delegation to self\n patient,\n patient.id!,\n [cryptoPrimitives.randomUuid()],\n [],\n []\n ) // else initialise also encryption keys\n : await entitiesEncryption.entityWithInitialisedEncryptedMetadata(patient, undefined, undefined, true).then((x) => x.updatedEntity)\n return await basePatientApi.modifyPatient(updatedPatient).then((x) => ({ dataOwner: x, type: DataOwnerTypeEnum.Patient }))\n }\n } else {\n return self\n }\n}\n\nexport function encryptedStubEquals(a: EncryptedEntityStub, b: EncryptedEntityStub): boolean {\n if (!delegationLikeEquality(a.delegations, b.delegations)) return false\n if (!delegationLikeEquality(a.encryptionKeys, b.encryptionKeys)) return false\n if (!delegationLikeEquality(a.cryptedForeignKeys, b.cryptedForeignKeys)) return false\n if (!setEquals(new Set(a.secretForeignKeys), new Set(b.secretForeignKeys))) return false\n return a.encryptedSelf === b.encryptedSelf\n}\n\nfunction delegationLikeEquality(a: { [s: string]: Delegation[] } | undefined, b: { [s: string]: Delegation[] } | undefined): boolean {\n if (!setEquals(new Set(Object.keys(a ?? {})), new Set(Object.keys(b ?? {})))) return false\n for (const [k, aDelegations] of Object.entries(a ?? {})) {\n const bDelegations = (b ?? {})[k]\n if (\n !aDelegations.every(\n (da) =>\n !!bDelegations.find(\n (db) => da.key === db.key && da.delegatedTo === db.delegatedTo && da.owner === db.owner && setEquals(new Set(da.tags), new Set(db.tags))\n )\n )\n )\n return false\n }\n return true\n}\n"]}
@@ -275,7 +275,10 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
275
275
  * @return the updated calendar item
276
276
  */
277
277
  linkToPatient(calendarItem, patient, shareLinkWithDelegates) {
278
+ var _a;
278
279
  return __awaiter(this, void 0, void 0, function* () {
280
+ if (!!((_a = calendarItem.secretForeignKeys) === null || _a === void 0 ? void 0 : _a.length))
281
+ throw new Error(`Calendar item ${calendarItem.id} is already linked to a patient`);
279
282
  const delegates = [...new Set([yield this.dataOwnerApi.getCurrentDataOwnerId(), ...shareLinkWithDelegates])];
280
283
  const sfk = yield this.crypto.confidential.getAnySecretIdSharedWithParents(patient);
281
284
  if (!sfk) {
@@ -1 +1 @@
1
- {"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE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OAAO,mCACN,YAAY,KACf,iBAAiB,EAAE,CAAC,GAAG,CAAC,GACzB,CAAA;YACD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;gBAChC,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,mCAAmC,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAG,CAAC,CAAC,CAAA;aACnH;YACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAA;YAC5D,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;YAChD,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC/C,CAAC;KAAA;CACF;AA3UD,kDA2UC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi implements EncryptedEntityXApi<models.CalendarItem> {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n encryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\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 this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: User, ci: CalendarItem, options: { additionalDelegates?: { [dataOwnerId: string]: 'WRITE' } } = {}) {\n return this.newInstancePatient(user, null, ci, options)\n }\n\n /**\n * Creates a new instance of calendar item with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this calendar item refers to.\n * @param ci initialised data for the calendar item. 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 access log. 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 calendar item.\n */\n async newInstancePatient(\n user: models.User,\n patient: models.Patient | null,\n ci: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ): Promise<models.CalendarItem> {\n if (!patient && options.preferredSfk) throw new Error('You need to specify parent patient in order to use secret foreign keys.')\n const calendarItem = _.extend(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.CalendarItem',\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 ci || {}\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 CalendarItem(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(calendarItem, patient?.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n const extractedKeys = await this.crypto.entities.secretIdsOf(patient, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? usingPost\n ? await this.findByHCPartyPatientSecretFKeysArray(topmostParentId, _.uniq(extractedKeys))\n : await this.findByHCPartyPatientSecretFKeys(topmostParentId, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n\n async findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem>> {\n const calendarItems = await super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys)\n return await this.decrypt(hcPartyId, calendarItems)\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any> {\n return super\n .findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, _.cloneDeep(body)) : null\n }\n\n private modifyAs(dataOwner: string, body: models.CalendarItem): Promise<models.CalendarItem> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((als) => super.modifyCalendarItem(als[0]))\n .then((body) => this.decrypt(dataOwner, [body]))\n .then((als) => als[0])\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems)\n }\n\n private encryptAs(dataOwnerId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((x) =>\n this.crypto.entities.tryEncryptEntity(x, dataOwnerId, this.encryptedKeys, false, true, (json) => new CalendarItem(json))\n )\n )\n }\n\n decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((x) => this.crypto.entities.decryptEntity(x, hcpId, (json) => new CalendarItem(json)).then(({ entity }) => entity))\n )\n }\n\n /**\n * @param calendarItem a calendar item\n * @return the id of the patient that the calendar item 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(calendarItem: models.CalendarItem): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(calendarItem, undefined)\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the calendar item.\n * @param calendarItem item the calendar item 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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated entity.\n */\n async shareWith(\n delegateId: string,\n calendarItem: models.CalendarItem,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.CalendarItem> {\n return this.shareWithMany(calendarItem, { [delegateId]: options })\n }\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content.\n * @param calendarItem item the calendar item to share.\n * @param delegates sharing options for each delegate.\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated entity.\n */\n async shareWithMany(\n calendarItem: models.CalendarItem,\n delegates: {\n [delegateId: string]: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.CalendarItem> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n return await this.modifyAs(\n self,\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n calendarItem,\n true,\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n shareEncryptionKey: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n },\n ])\n )\n )\n )\n }\n\n async getDataOwnersWithAccessTo(\n entity: CalendarItem\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: 'WRITE' }; hasUnknownAnonymousDataOwners: boolean }> {\n return await this.crypto.entities.getDataOwnersWithAccessTo(entity)\n }\n\n async getEncryptionKeysOf(entity: CalendarItem): Promise<string[]> {\n return await this.crypto.entities.encryptionKeysOf(entity)\n }\n\n /**\n * Links a calendar item with a patient. Note that this operation is not reversible: it is not possible to change the patient linked to a calendar\n * item.\n * @param calendarItem a calendar item\n * @param patient the patient which will be linked to the calendar item\n * @param shareLinkWithDelegates data owners other than the current data owner which will also be able to decrypt the id of the newly linked patient\n * @return the updated calendar item\n */\n async linkToPatient(calendarItem: models.CalendarItem, patient: models.Patient, shareLinkWithDelegates: string[]): Promise<models.CalendarItem> {\n const delegates = [...new Set([await this.dataOwnerApi.getCurrentDataOwnerId(), ...shareLinkWithDelegates])]\n const sfk = await this.crypto.confidential.getAnySecretIdSharedWithParents(patient)\n if (!sfk) {\n throw new Error(`Could not find any secret id for patient ${patient.id} which is shared with the topmost ancestor of the current data owner`)\n }\n let updated = {\n ...calendarItem,\n secretForeignKeys: [sfk],\n }\n for (const delegate of delegates) {\n updated = await this.crypto.entities.entityWithExtendedEncryptedMetadata(updated, delegate, [], [], [patient.id!])\n }\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const saved = await this.modifyAs(self, updated)\n return (await this.decrypt(self, [saved]))[0]\n }\n}\n"]}
1
+ {"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAE3B,oDAA4D;AAE5D,wCAA+C;AAE/C,0EAAgG;AAIhG,MAAa,mBAAoB,SAAQ,4BAAkB;IAMzD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,gBAA+B,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,EAChE,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;QAlBzD,SAAI,GAAQ,IAAI,CAAA;QAGhB,kBAAa,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QAgB/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAED,WAAW,CAAC,IAAU,EAAE,EAAgB,EAAE,UAAwE,EAAE;QAClH,OAAO,IAAI,CAAC,kBAAkB,CAAC,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User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi implements EncryptedEntityXApi<models.CalendarItem> {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n encryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\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 this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: User, ci: CalendarItem, options: { additionalDelegates?: { [dataOwnerId: string]: 'WRITE' } } = {}) {\n return this.newInstancePatient(user, null, ci, options)\n }\n\n /**\n * Creates a new instance of calendar item with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this calendar item refers to.\n * @param ci initialised data for the calendar item. 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 access log. 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 calendar item.\n */\n async newInstancePatient(\n user: models.User,\n patient: models.Patient | null,\n ci: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n preferredSfk?: string\n } = {}\n ): Promise<models.CalendarItem> {\n if (!patient && options.preferredSfk) throw new Error('You need to specify parent patient in order to use secret foreign keys.')\n const calendarItem = _.extend(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.CalendarItem',\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 ci || {}\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 CalendarItem(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(calendarItem, patient?.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n async findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n const extractedKeys = await this.crypto.entities.secretIdsOf(patient, hcpartyId)\n const topmostParentId = (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0]\n return extractedKeys && extractedKeys.length > 0\n ? usingPost\n ? await this.findByHCPartyPatientSecretFKeysArray(topmostParentId, _.uniq(extractedKeys))\n : await this.findByHCPartyPatientSecretFKeys(topmostParentId, _.uniq(extractedKeys).join(','))\n : Promise.resolve([])\n }\n\n async findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem>> {\n const calendarItems = await super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys)\n return await this.decrypt(hcPartyId, calendarItems)\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any> {\n return super\n .findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body ? this.modifyAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, _.cloneDeep(body)) : null\n }\n\n private modifyAs(dataOwner: string, body: models.CalendarItem): Promise<models.CalendarItem> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((als) => super.modifyCalendarItem(als[0]))\n .then((body) => this.decrypt(dataOwner, [body]))\n .then((als) => als[0])\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return this.encryptAs(this.dataOwnerApi.getDataOwnerIdOf(user)!, calendarItems)\n }\n\n private encryptAs(dataOwnerId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((x) =>\n this.crypto.entities.tryEncryptEntity(x, dataOwnerId, this.encryptedKeys, false, true, (json) => new CalendarItem(json))\n )\n )\n }\n\n decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((x) => this.crypto.entities.decryptEntity(x, hcpId, (json) => new CalendarItem(json)).then(({ entity }) => entity))\n )\n }\n\n /**\n * @param calendarItem a calendar item\n * @return the id of the patient that the calendar item 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(calendarItem: models.CalendarItem): Promise<string[]> {\n return this.crypto.entities.owningEntityIdsOf(calendarItem, undefined)\n }\n\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the calendar item.\n * @param calendarItem item the calendar item 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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated entity.\n */\n async shareWith(\n delegateId: string,\n calendarItem: models.CalendarItem,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.CalendarItem> {\n return this.shareWithMany(calendarItem, { [delegateId]: options })\n }\n /**\n * Share an existing calendar item with other data owners, allowing them to access the non-encrypted data of the calendar item and optionally also\n * the encrypted content.\n * @param calendarItem item the calendar item to share.\n * @param delegates sharing options for each delegate.\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 * calendar item does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this calendar item refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * @return a promise which will contain the updated entity.\n */\n async shareWithMany(\n calendarItem: models.CalendarItem,\n delegates: {\n [delegateId: string]: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.CalendarItem> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n return await this.modifyAs(\n self,\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n calendarItem,\n true,\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n shareEncryptionKey: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n },\n ])\n )\n )\n )\n }\n\n async getDataOwnersWithAccessTo(\n entity: CalendarItem\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: 'WRITE' }; hasUnknownAnonymousDataOwners: boolean }> {\n return await this.crypto.entities.getDataOwnersWithAccessTo(entity)\n }\n\n async getEncryptionKeysOf(entity: CalendarItem): Promise<string[]> {\n return await this.crypto.entities.encryptionKeysOf(entity)\n }\n\n /**\n * Links a calendar item with a patient. Note that this operation is not reversible: it is not possible to change the patient linked to a calendar\n * item.\n * @param calendarItem a calendar item\n * @param patient the patient which will be linked to the calendar item\n * @param shareLinkWithDelegates data owners other than the current data owner which will also be able to decrypt the id of the newly linked patient\n * @return the updated calendar item\n */\n async linkToPatient(calendarItem: models.CalendarItem, patient: models.Patient, shareLinkWithDelegates: string[]): Promise<models.CalendarItem> {\n if (!!calendarItem.secretForeignKeys?.length) throw new Error(`Calendar item ${calendarItem.id} is already linked to a patient`)\n const delegates = [...new Set([await this.dataOwnerApi.getCurrentDataOwnerId(), ...shareLinkWithDelegates])]\n const sfk = await this.crypto.confidential.getAnySecretIdSharedWithParents(patient)\n if (!sfk) {\n throw new Error(`Could not find any secret id for patient ${patient.id} which is shared with the topmost ancestor of the current data owner`)\n }\n let updated = {\n ...calendarItem,\n secretForeignKeys: [sfk],\n }\n for (const delegate of delegates) {\n updated = await this.crypto.entities.entityWithExtendedEncryptedMetadata(updated, delegate, [], [], [patient.id!])\n }\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const saved = await this.modifyAs(self, updated)\n return (await this.decrypt(self, [saved]))[0]\n }\n}\n"]}
@@ -1,13 +1,13 @@
1
1
  import { AESUtils } from './crypto/AES';
2
2
  import { KeyPair, RSAUtils } from './crypto/RSA';
3
3
  import { ShamirClass } from './crypto/shamir';
4
- import { Delegation, Device, Document, EncryptedEntity, EncryptedParentEntity, HealthcareParty, Patient, User } from '../icc-api/model/models';
4
+ import { Delegation, Document, EncryptedEntity, EncryptedParentEntity, HealthcareParty, User } from '../icc-api/model/models';
5
5
  import { StorageFacade } from './storage/StorageFacade';
6
6
  import { KeyStorageFacade } from './storage/KeyStorageFacade';
7
7
  import { ExchangeKeysManager } from './crypto/ExchangeKeysManager';
8
8
  import { CryptoPrimitives } from './crypto/CryptoPrimitives';
9
9
  import { KeyManager } from './crypto/KeyManager';
10
- import { DataOwner, DataOwnerWithType, IccDataOwnerXApi } from './icc-data-owner-x-api';
10
+ import { DataOwner, IccDataOwnerXApi } from './icc-data-owner-x-api';
11
11
  import { EntitiesEncryption } from './crypto/EntitiesEncryption';
12
12
  import { IcureStorageFacade } from './storage/IcureStorageFacade';
13
13
  import { ShamirKeysManager } from './crypto/ShamirKeysManager';
@@ -210,7 +210,7 @@ export declare class IccCryptoXApi {
210
210
  * entity-specific extended api.
211
211
  * Note that currently this method does not cache results anymore (but the updated methods do).
212
212
  */
213
- getEncryptedAesExchangeKeys(owner: HealthcareParty | Patient | Device, delegateId: string): Promise<{
213
+ getEncryptedAesExchangeKeys(owner: DataOwner, delegateId: string): Promise<{
214
214
  [pubKeyIdentifier: string]: {
215
215
  [pubKeyFingerprint: string]: string;
216
216
  };
@@ -358,7 +358,7 @@ export declare class IccCryptoXApi {
358
358
  /**
359
359
  * @deprecated use {@link IccIcureMaintenanceXApi.applyKeyPairUpdate} instead.
360
360
  */
361
- giveAccessBackTo(delegateUser: User, ownerId: string, ownerNewPublicKey: string): Promise<DataOwnerWithType>;
361
+ giveAccessBackTo(delegateUser: User, ownerId: string, ownerNewPublicKey: string): Promise<DataOwner>;
362
362
  /**
363
363
  * @deprecated You don't need to manually generate exchange keys as they will be automatically created by the api when needed.
364
364
  * Note that this method has some changes compared to previous version:
@@ -369,13 +369,13 @@ export declare class IccCryptoXApi {
369
369
  /**
370
370
  * @deprecated replace with {@link IccDataOwnerXApi.getDataOwner}. Note that data owners are not cached anymore.
371
371
  */
372
- getDataOwner(ownerId: string, loadIfMissingFromCache?: boolean): Promise<DataOwnerWithType>;
372
+ getDataOwner(ownerId: string, loadIfMissingFromCache?: boolean): Promise<import("../icc-api/model/DataOwnerWithType").DataOwnerWithType>;
373
373
  /**
374
374
  * @deprecated the crypto api will automatically verify on startup the validity of private keys, but in some cases you may want to verify the
375
375
  * validity of keys recovered in your implementation of {@link CryptoStrategies}: in this case the method has been replaced with
376
376
  * {@link RSA.checkKeyPairValidity}
377
377
  */
378
- checkPrivateKeyValidity(dataOwner: HealthcareParty | Patient | Device): Promise<boolean>;
378
+ checkPrivateKeyValidity(dataOwner: DataOwner): Promise<boolean>;
379
379
  /**
380
380
  * @deprecated (See {@link extractEncryptionsSKs} for a detailed explanation).
381
381
  */
@@ -222,7 +222,8 @@ class IccCryptoXApi {
222
222
  const legacyKeyFp = (_a = hcp.publicKey) === null || _a === void 0 ? void 0 : _a.slice(-32);
223
223
  if (!legacyKeyFp)
224
224
  throw new Error(`No legacy/default key for hcp ${hcp.id}`);
225
- return (yield this.shamirKeysManager.updateSelfSplits({ [legacyKeyFp]: { notariesIds: notaries.map((x) => x.id), minShares: threshold !== null && threshold !== void 0 ? threshold : notaries.length } }, [])).dataOwner;
225
+ yield this.shamirKeysManager.updateSelfSplits({ [legacyKeyFp]: { notariesIds: notaries.map((x) => x.id), minShares: threshold !== null && threshold !== void 0 ? threshold : notaries.length } }, []);
226
+ return (yield this.dataOwnerApi.getDataOwner(hcp.id)).dataOwner;
226
227
  });
227
228
  }
228
229
  /**
@@ -727,7 +728,7 @@ class IccCryptoXApi {
727
728
  giveAccessBackTo(delegateUser, ownerId, ownerNewPublicKey) {
728
729
  return __awaiter(this, void 0, void 0, function* () {
729
730
  yield this.exchangeKeys.base.giveAccessBackTo(ownerId, ownerNewPublicKey, this.userKeysManager.getDecryptionKeys());
730
- return this.dataOwnerApi.getDataOwner(ownerId);
731
+ return this.dataOwnerApi.getDataOwner(ownerId).then((x) => x.dataOwner);
731
732
  });
732
733
  }
733
734
  /**
@@ -737,12 +738,11 @@ class IccCryptoXApi {
737
738
  * - The method will throw an exception if the provided ownerId does not match the current data owner
738
739
  */
739
740
  generateKeyForDelegate(ownerId, delegateId) {
740
- var _a, _b;
741
741
  return __awaiter(this, void 0, void 0, function* () {
742
742
  if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId())) {
743
743
  throw new Error('You can only create delegation where the delegator is the current data owner');
744
744
  }
745
- return ((_b = (_a = (yield this.exchangeKeysManager.getOrCreateEncryptionExchangeKeysTo(delegateId)).updatedDelegator) === null || _a === void 0 ? void 0 : _a.dataOwner) !== null && _b !== void 0 ? _b : (yield this.dataOwnerApi.getDataOwner(ownerId)).dataOwner);
745
+ return (yield this.dataOwnerApi.getDataOwner(ownerId)).dataOwner;
746
746
  });
747
747
  }
748
748
  /**