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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/icc-api/api/IccPatientApi.d.ts +4 -0
  2. package/icc-api/api/IccPatientApi.js +17 -0
  3. package/icc-api/api/IccPatientApi.js.map +1 -1
  4. package/icc-x-api/basexapi/EncryptedEntityXApi.d.ts +48 -0
  5. package/icc-x-api/basexapi/EncryptedEntityXApi.js +3 -0
  6. package/icc-x-api/basexapi/EncryptedEntityXApi.js.map +1 -0
  7. package/icc-x-api/crypto/EntitiesEncryption.d.ts +23 -4
  8. package/icc-x-api/crypto/EntitiesEncryption.js +46 -22
  9. package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -1
  10. package/icc-x-api/icc-accesslog-x-api.d.ts +27 -1
  11. package/icc-x-api/icc-accesslog-x-api.js +34 -1
  12. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  13. package/icc-x-api/icc-calendar-item-x-api.d.ts +36 -1
  14. package/icc-x-api/icc-calendar-item-x-api.js +58 -1
  15. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  16. package/icc-x-api/icc-classification-x-api.d.ts +27 -1
  17. package/icc-x-api/icc-classification-x-api.js +34 -1
  18. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  19. package/icc-x-api/icc-contact-x-api.d.ts +27 -1
  20. package/icc-x-api/icc-contact-x-api.js +34 -1
  21. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  22. package/icc-x-api/icc-document-x-api.d.ts +71 -4
  23. package/icc-x-api/icc-document-x-api.js +96 -6
  24. package/icc-x-api/icc-document-x-api.js.map +1 -1
  25. package/icc-x-api/icc-form-x-api.d.ts +27 -1
  26. package/icc-x-api/icc-form-x-api.js +34 -1
  27. package/icc-x-api/icc-form-x-api.js.map +1 -1
  28. package/icc-x-api/icc-helement-x-api.d.ts +27 -1
  29. package/icc-x-api/icc-helement-x-api.js +34 -1
  30. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  31. package/icc-x-api/icc-invoice-x-api.d.ts +27 -1
  32. package/icc-x-api/icc-invoice-x-api.js +34 -1
  33. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  34. package/icc-x-api/icc-maintenance-task-x-api.d.ts +25 -2
  35. package/icc-x-api/icc-maintenance-task-x-api.js +26 -2
  36. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  37. package/icc-x-api/icc-message-x-api.d.ts +30 -1
  38. package/icc-x-api/icc-message-x-api.js +37 -1
  39. package/icc-x-api/icc-message-x-api.js.map +1 -1
  40. package/icc-x-api/icc-patient-x-api.d.ts +67 -1
  41. package/icc-x-api/icc-patient-x-api.js +80 -6
  42. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  43. package/icc-x-api/icc-receipt-x-api.d.ts +47 -2
  44. package/icc-x-api/icc-receipt-x-api.js +58 -4
  45. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  46. package/icc-x-api/icc-time-table-x-api.d.ts +25 -1
  47. package/icc-x-api/icc-time-table-x-api.js +27 -2
  48. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  49. package/package.json +1 -1
@@ -14,7 +14,6 @@ const icc_api_1 = require("../icc-api");
14
14
  const _ = require("lodash");
15
15
  const models = require("../icc-api/model/models");
16
16
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
17
- const ShareMetadataBehaviour_1 = require("./crypto/ShareMetadataBehaviour");
18
17
  class IccReceiptXApi extends icc_api_1.IccReceiptApi {
19
18
  constructor(host, headers, crypto, dataOwnerApi, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
20
19
  ? window.fetch
@@ -79,7 +78,19 @@ class IccReceiptXApi extends icc_api_1.IccReceiptApi {
79
78
  });
80
79
  }
81
80
  /**
82
- * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt.
81
+ * Adds an unencrypted attachment to a receipt.
82
+ * @param receipt a receipt.
83
+ * @param blobType the type of the attachment.
84
+ * @param attachment a attachment for the receipt.
85
+ * @return the updated receipt.
86
+ */
87
+ setClearReceiptAttachment(receipt, blobType, attachment) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ return yield this.setReceiptAttachment(receipt.id, blobType, undefined, attachment);
90
+ });
91
+ }
92
+ /**
93
+ * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt, throwing an error if the operation fails.
83
94
  * @param receipt a receipt.
84
95
  * @param attachmentId id of the attachment of this receipt to retrieve.
85
96
  * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption
@@ -88,7 +99,25 @@ class IccReceiptXApi extends icc_api_1.IccReceiptApi {
88
99
  */
89
100
  getAndDecryptReceiptAttachment(receipt, attachmentId, validator = () => Promise.resolve(true)) {
90
101
  return __awaiter(this, void 0, void 0, function* () {
91
- return yield this.crypto.entities.decryptDataOf(receipt, yield this.getReceiptAttachment(receipt.id, attachmentId, ''), (x) => validator(x));
102
+ const { data, wasDecrypted } = yield this.crypto.entities.tryDecryptDataOf(receipt, yield this.getReceiptAttachment(receipt.id, attachmentId, ''), (x) => validator(x));
103
+ if (!wasDecrypted)
104
+ throw new Error(`No valid key found to decrypt data of receipt ${receipt.id}.`);
105
+ return data;
106
+ });
107
+ }
108
+ /**
109
+ * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt.
110
+ * @param receipt a receipt.
111
+ * @param attachmentId id of the attachment of this receipt to retrieve.
112
+ * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption
113
+ * keys and it is unclear which one should be used this function can help to detect bad decryptions.
114
+ * @return an object containing:
115
+ * - data: the decrypted attachment, if it could be decrypted, else the encrypted attachment.
116
+ * - wasDecrypted: if the data was successfully decrypted or not
117
+ */
118
+ getAndTryDecryptReceiptAttachment(receipt, attachmentId, validator = () => Promise.resolve(true)) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ return yield this.crypto.entities.tryDecryptDataOf(receipt, yield this.getReceiptAttachment(receipt.id, attachmentId, ''), (x) => validator(x));
92
121
  });
93
122
  }
94
123
  /**
@@ -104,7 +133,32 @@ class IccReceiptXApi extends icc_api_1.IccReceiptApi {
104
133
  */
105
134
  shareWith(delegateId, receipt, options = {}) {
106
135
  return __awaiter(this, void 0, void 0, function* () {
107
- return yield this.modifyReceipt(yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(receipt, delegateId, undefined, options.shareEncryptionKey, ShareMetadataBehaviour_1.ShareMetadataBehaviour.IF_AVAILABLE));
136
+ return this.shareWithMany(receipt, { [delegateId]: options });
137
+ });
138
+ }
139
+ /**
140
+ * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also
141
+ * the encrypted content.
142
+ * @param receipt the receipt to share.
143
+ * @param delegates sharing options for each delegate which will gain access to the entity:
144
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
145
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
146
+ * receipt does not have encrypted content.
147
+ * @return a promise which will contain the updated receipt.
148
+ */
149
+ shareWithMany(receipt, delegates) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ return yield this.modifyReceipt(yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(receipt, true, delegates));
152
+ });
153
+ }
154
+ getDataOwnersWithAccessTo(entity) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ return yield this.crypto.entities.getDataOwnersWithAccessTo(entity);
157
+ });
158
+ }
159
+ getEncryptionKeysOf(entity) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ return yield this.crypto.entities.encryptionKeysOf(entity);
108
162
  });
109
163
  }
110
164
  }
@@ -1 +1 @@
1
- {"version":3,"file":"icc-receipt-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-receipt-x-api.ts"],"names":[],"mappings":";;;;;;;;;;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,CAAC,CAAA;QACzF,CAAC;KAAA;IAED;;;;;;;OAOG;IACG,8BAA8B,CAClC,OAAuB,EACvB,YAAoB,EACpB,YAA0D,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;;YAErF,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAG,EAAE,YAAY,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;QAC/I,CAAC;KAAA;IAED;;;;;;;;;;OAUG;IACG,SAAS,CACb,UAAkB,EAClB,OAAuB,EACvB,UAEI,EAAE;;YAEN,OAAO,MAAM,IAAI,CAAC,aAAa,CAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAChE,OAAO,EACP,UAAU,EACV,SAAS,EACT,OAAO,CAAC,kBAAkB,EAC1B,+CAAsB,CAAC,YAAY,CACpC,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAhID,wCAgIC","sourcesContent":["import { IccReceiptApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\n\nexport class IccReceiptXApi extends IccReceiptApi {\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of receipt with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param r initialised data for the receipt. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * @return a new instance of receipt.\n */\n async newInstance(\n user: models.User,\n r: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n } = {}\n ): Promise<models.Receipt> {\n const receipt = new models.Receipt(\n _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Receipt',\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 r || {}\n )\n )\n\n const extraDelegations = [\n ...Object.keys(options.additionalDelegates ?? {}),\n ...(user.autoDelegations?.all ?? []),\n ...(user.autoDelegations?.medicalInformation ?? []),\n ]\n return new models.Receipt(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(receipt, undefined, undefined, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n logReceipt(user: models.User, docId: string, refs: Array<string>, blobType: string, blob: ArrayBuffer) {\n return this.newInstance(user, { documentId: docId, references: refs })\n .then((rcpt) => this.createReceipt(rcpt))\n .then((rcpt) => (blob.byteLength != 0 ? this.setReceiptAttachment(rcpt.id!, blobType, '', <any>blob) : Promise.resolve(rcpt)))\n }\n\n /**\n * Adds an attachment to a receipt, encrypting it on client side using the encryption keys of the provided receipt.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment a attachment for the receipt.\n * @return the updated receipt.\n */\n async encryptAndSetReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n const encryptedData = await this.crypto.entities.encryptDataOf(receipt, attachment)\n return await this.setReceiptAttachment(receipt.id!, blobType, undefined, encryptedData)\n }\n\n /**\n * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt.\n * @param receipt a receipt.\n * @param attachmentId id of the attachment of this receipt to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption\n * keys and it is unclear which one should be used this function can help to detect bad decryptions.\n * @return the decrypted attachment, if it could be decrypted, else the encrypted attachment.\n */\n async getAndDecryptReceiptAttachment(\n receipt: models.Receipt,\n attachmentId: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<ArrayBuffer> {\n return await this.crypto.entities.decryptDataOf(receipt, await this.getReceiptAttachment(receipt.id!, attachmentId, ''), (x) => validator(x))\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the receipt.\n * @param receipt the receipt to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * receipt does not have encrypted content.\n * @return a promise which will contain the updated receipt.\n */\n async shareWith(\n delegateId: string,\n receipt: models.Receipt,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Receipt> {\n return await this.modifyReceipt(\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n receipt,\n delegateId,\n undefined,\n options.shareEncryptionKey,\n ShareMetadataBehaviour.IF_AVAILABLE\n )\n )\n }\n}\n"]}
1
+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AA;IAED;;;;;;;;;;OAUG;IACG,SAAS,CACb,UAAkB,EAClB,OAAuB,EACvB,UAEI,EAAE;;YAEN,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;QAC/D,CAAC;KAAA;IAED;;;;;;;;;OASG;IACG,aAAa,CACjB,OAAuB,EACvB,SAIC;;YAED,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;QAC/H,CAAC;KAAA;IAEK,yBAAyB,CAAC,MAAsB;;YAIpD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAA;QACrE,CAAC;KAAA;IAEK,mBAAmB,CAAC,MAAsB;;YAC9C,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC5D,CAAC;KAAA;CACF;AA3LD,wCA2LC","sourcesContent":["import { IccReceiptApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\n\nexport class IccReceiptXApi extends IccReceiptApi implements EncryptedEntityXApi<models.Receipt> {\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of receipt with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param r initialised data for the receipt. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * @return a new instance of receipt.\n */\n async newInstance(\n user: models.User,\n r: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n } = {}\n ): Promise<models.Receipt> {\n const receipt = new models.Receipt(\n _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.Receipt',\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 r || {}\n )\n )\n\n const extraDelegations = [\n ...Object.keys(options.additionalDelegates ?? {}),\n ...(user.autoDelegations?.all ?? []),\n ...(user.autoDelegations?.medicalInformation ?? []),\n ]\n return new models.Receipt(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(receipt, undefined, undefined, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n logReceipt(user: models.User, docId: string, refs: Array<string>, blobType: string, blob: ArrayBuffer) {\n return this.newInstance(user, { documentId: docId, references: refs })\n .then((rcpt) => this.createReceipt(rcpt))\n .then((rcpt) => (blob.byteLength != 0 ? this.setReceiptAttachment(rcpt.id!, blobType, '', <any>blob) : Promise.resolve(rcpt)))\n }\n\n /**\n * Adds an attachment to a receipt, encrypting it on client side using the encryption keys of the provided receipt.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment a attachment for the receipt.\n * @return the updated receipt.\n */\n async encryptAndSetReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n const encryptedData = await this.crypto.entities.encryptDataOf(receipt, attachment)\n return await this.setReceiptAttachment(receipt.id!, blobType, undefined, encryptedData)\n }\n\n /**\n * Adds an unencrypted attachment to a receipt.\n * @param receipt a receipt.\n * @param blobType the type of the attachment.\n * @param attachment a attachment for the receipt.\n * @return the updated receipt.\n */\n async setClearReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n return await this.setReceiptAttachment(receipt.id!, blobType, undefined, attachment)\n }\n\n /**\n * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt, throwing an error if the operation fails.\n * @param receipt a receipt.\n * @param attachmentId id of the attachment of this receipt to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption\n * keys and it is unclear which one should be used this function can help to detect bad decryptions.\n * @return the decrypted attachment, if it could be decrypted, else the encrypted attachment.\n */\n async getAndDecryptReceiptAttachment(\n receipt: models.Receipt,\n attachmentId: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<ArrayBuffer> {\n const { data, wasDecrypted } = await this.crypto.entities.tryDecryptDataOf(\n receipt,\n await this.getReceiptAttachment(receipt.id!, attachmentId, ''),\n (x) => validator(x)\n )\n if (!wasDecrypted) throw new Error(`No valid key found to decrypt data of receipt ${receipt.id}.`)\n return data\n }\n\n /**\n * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt.\n * @param receipt a receipt.\n * @param attachmentId id of the attachment of this receipt to retrieve.\n * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption\n * keys and it is unclear which one should be used this function can help to detect bad decryptions.\n * @return an object containing:\n * - data: the decrypted attachment, if it could be decrypted, else the encrypted attachment.\n * - wasDecrypted: if the data was successfully decrypted or not\n */\n async getAndTryDecryptReceiptAttachment(\n receipt: models.Receipt,\n attachmentId: string,\n validator: (decrypted: ArrayBuffer) => Promise<boolean> = () => Promise.resolve(true)\n ): Promise<{ data: ArrayBuffer; wasDecrypted: boolean }> {\n return await this.crypto.entities.tryDecryptDataOf(receipt, await this.getReceiptAttachment(receipt.id!, attachmentId, ''), (x) => validator(x))\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also\n * the encrypted content.\n * @param delegateId the id of the data owner which will be granted access to the receipt.\n * @param receipt the receipt to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * receipt does not have encrypted content.\n * @return a promise which will contain the updated receipt.\n */\n async shareWith(\n delegateId: string,\n receipt: models.Receipt,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Receipt> {\n return this.shareWithMany(receipt, { [delegateId]: options })\n }\n\n /**\n * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also\n * the encrypted content.\n * @param receipt the receipt to share.\n * @param delegates sharing options for each delegate which will gain access to the entity:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * receipt does not have encrypted content.\n * @return a promise which will contain the updated receipt.\n */\n async shareWithMany(\n receipt: models.Receipt,\n delegates: {\n [delegateId: string]: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Receipt> {\n return await this.modifyReceipt(await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(receipt, true, delegates))\n }\n\n async getDataOwnersWithAccessTo(entity: models.Receipt): Promise<{\n permissionsByDataOwnerId: { [dataOwnerId: string]: 'WRITE' }\n hasUnknownAnonymousDataOwners: boolean\n }> {\n return await this.crypto.entities.getDataOwnersWithAccessTo(entity)\n }\n\n async getEncryptionKeysOf(entity: models.Receipt): Promise<string[]> {\n return await this.crypto.entities.encryptionKeysOf(entity)\n }\n}\n"]}
@@ -6,7 +6,8 @@ import { IccDataOwnerXApi } from './icc-data-owner-x-api';
6
6
  import * as models from '../icc-api/model/models';
7
7
  import { AuthenticationProvider } from './auth/AuthenticationProvider';
8
8
  import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour';
9
- export declare class IccTimeTableXApi extends IccTimeTableApi {
9
+ import { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi';
10
+ export declare class IccTimeTableXApi extends IccTimeTableApi implements EncryptedEntityXApi<TimeTable> {
10
11
  i18n: any;
11
12
  crypto: IccCryptoXApi;
12
13
  dataOwnerApi: IccDataOwnerXApi;
@@ -45,4 +46,27 @@ export declare class IccTimeTableXApi extends IccTimeTableApi {
45
46
  shareWith(delegateId: string, timeTable: models.TimeTable, options?: {
46
47
  shareEncryptionKey?: ShareMetadataBehaviour;
47
48
  }): Promise<models.TimeTable>;
49
+ /**
50
+ * Share an existing time table with other data owners, allowing them to access the non-encrypted data of the time table and optionally also
51
+ * the encrypted content, with read-only or read-write permissions.
52
+ * @param timeTable the time table to share.
53
+ * @param delegates sharing options for each delegate.
54
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
55
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
56
+ * time table does not have encrypted content.
57
+ * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if
58
+ * the operation failed.
59
+ */
60
+ shareWithMany(timeTable: models.TimeTable, delegates: {
61
+ [delegateId: string]: {
62
+ shareEncryptionKey?: ShareMetadataBehaviour;
63
+ };
64
+ }): Promise<models.TimeTable>;
65
+ getDataOwnersWithAccessTo(entity: models.TimeTable): Promise<{
66
+ permissionsByDataOwnerId: {
67
+ [p: string]: 'WRITE';
68
+ };
69
+ hasUnknownAnonymousDataOwners: boolean;
70
+ }>;
71
+ getEncryptionKeysOf(entity: models.TimeTable): Promise<string[]>;
48
72
  }
@@ -15,7 +15,6 @@ const _ = require("lodash");
15
15
  const icc_api_1 = require("../icc-api");
16
16
  const models = require("../icc-api/model/models");
17
17
  const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
18
- const ShareMetadataBehaviour_1 = require("./crypto/ShareMetadataBehaviour");
19
18
  class IccTimeTableXApi extends icc_api_1.IccTimeTableApi {
20
19
  constructor(host, headers, crypto, dataOwnerApi, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
21
20
  ? window.fetch
@@ -76,7 +75,33 @@ class IccTimeTableXApi extends icc_api_1.IccTimeTableApi {
76
75
  */
77
76
  shareWith(delegateId, timeTable, options = {}) {
78
77
  return __awaiter(this, void 0, void 0, function* () {
79
- return yield this.modifyTimeTable(yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(timeTable, delegateId, undefined, options.shareEncryptionKey, ShareMetadataBehaviour_1.ShareMetadataBehaviour.IF_AVAILABLE));
78
+ return this.shareWithMany(timeTable, { [delegateId]: options });
79
+ });
80
+ }
81
+ /**
82
+ * Share an existing time table with other data owners, allowing them to access the non-encrypted data of the time table and optionally also
83
+ * the encrypted content, with read-only or read-write permissions.
84
+ * @param timeTable the time table to share.
85
+ * @param delegates sharing options for each delegate.
86
+ * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted
87
+ * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a
88
+ * time table does not have encrypted content.
89
+ * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if
90
+ * the operation failed.
91
+ */
92
+ shareWithMany(timeTable, delegates) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ return yield this.modifyTimeTable(yield this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(timeTable, true, delegates));
95
+ });
96
+ }
97
+ getDataOwnersWithAccessTo(entity) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return yield this.crypto.entities.getDataOwnersWithAccessTo(entity);
100
+ });
101
+ }
102
+ getEncryptionKeysOf(entity) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ return yield this.crypto.entities.encryptionKeysOf(entity);
80
105
  });
81
106
  }
82
107
  }
@@ -1 +1 @@
1
- {"version":3,"file":"icc-time-table-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-time-table-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAC3B,wCAA4C;AAK5C,kDAAiD;AACjD,0EAAgG;AAChG,4EAAwE;AAExE,MAAa,gBAAiB,SAAQ,yBAAe;IAKnD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAhBzD,SAAI,GAAQ,IAAI,CAAA;QAiBd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED;;;;;;;;;;;OAWG;IACG,WAAW,CACf,IAAU,EACV,EAAa,EACb,UAEI,EAAE;;;YAEN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AsB,CAAC,YAAY,CACpC,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAhGD,4CAgGC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport { IccTimeTableApi } from '../icc-api'\nimport { User } from '../icc-api/model/User'\nimport { TimeTable } from '../icc-api/model/TimeTable'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport * as models from '../icc-api/model/models'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\n\nexport class IccTimeTableXApi extends IccTimeTableApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of timetable with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param tt initialised data for the timetable. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * @return a new instance of timetable.\n */\n async newInstance(\n user: User,\n tt: TimeTable,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n } = {}\n ) {\n const timeTable = _.extend(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.TimeTable',\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 tt || {}\n )\n\n const extraDelegations = [\n ...Object.keys(options.additionalDelegates ?? {}),\n ...(user.autoDelegations?.all ?? []),\n ...(user.autoDelegations?.administrativeData ?? []),\n ]\n return new models.TimeTable(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(timeTable, undefined, undefined, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * Share an existing time table with other data owners, allowing them to access the non-encrypted data of the time table and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the time table.\n * @param timeTable the time table 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 * time table does not have encrypted content.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async shareWith(\n delegateId: string,\n timeTable: models.TimeTable,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.TimeTable> {\n return await this.modifyTimeTable(\n await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(\n timeTable,\n delegateId,\n undefined,\n options.shareEncryptionKey,\n ShareMetadataBehaviour.IF_AVAILABLE\n )\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-time-table-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-time-table-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAC3B,wCAA4C;AAK5C,kDAAiD;AACjD,0EAAgG;AAIhG,MAAa,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,MAAA,MAAA,IAAI,CAAC,eAAe,0CAAE,kBAAkB,mCAAI,EAAE,CAAC;aACpD,CAAA;YACD,OAAO,IAAI,MAAM,CAAC,SAAS,CACzB,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ;iBACvB,sCAAsC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,gBAAgB,CAAC;iBAC/F,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAChC,CAAA;;KACF;IAED;;;;;;;;;;;OAWG;IACG,SAAS,CACb,UAAkB,EAClB,SAA2B,EAC3B,UAEI,EAAE;;YAEN,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;QACjE,CAAC;KAAA;IAED;;;;;;;;;;OAUG;IACG,aAAa,CACjB,SAA2B,EAC3B,SAIC;;YAED,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,uCAAuC,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;QACnI,CAAC;KAAA;IAEK,yBAAyB,CAC7B,MAAwB;;YAExB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAA;QACrE,CAAC;KAAA;IAEK,mBAAmB,CAAC,MAAwB;;YAChD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC5D,CAAC;KAAA;CACF;AAxHD,4CAwHC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport { IccTimeTableApi } from '../icc-api'\nimport { User } from '../icc-api/model/User'\nimport { TimeTable } from '../icc-api/model/TimeTable'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport * as models from '../icc-api/model/models'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\n\nexport class IccTimeTableXApi extends IccTimeTableApi implements EncryptedEntityXApi<TimeTable> {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n /**\n * Creates a new instance of timetable with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param tt initialised data for the timetable. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used. Currently only WRITE access is supported, but in future also read\n * access will be possible.\n * @return a new instance of timetable.\n */\n async newInstance(\n user: User,\n tt: TimeTable,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: 'WRITE' }\n } = {}\n ) {\n const timeTable = _.extend(\n {\n id: this.crypto.primitives.randomUuid(),\n _type: 'org.taktik.icure.entities.TimeTable',\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 tt || {}\n )\n\n const extraDelegations = [\n ...Object.keys(options.additionalDelegates ?? {}),\n ...(user.autoDelegations?.all ?? []),\n ...(user.autoDelegations?.administrativeData ?? []),\n ]\n return new models.TimeTable(\n await this.crypto.entities\n .entityWithInitialisedEncryptedMetadata(timeTable, undefined, undefined, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n /**\n * Share an existing time table with other data owners, allowing them to access the non-encrypted data of the time table and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the time table.\n * @param timeTable the time table 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 * time table does not have encrypted content.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async shareWith(\n delegateId: string,\n timeTable: models.TimeTable,\n options: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.TimeTable> {\n return this.shareWithMany(timeTable, { [delegateId]: options })\n }\n\n /**\n * Share an existing time table with other data owners, allowing them to access the non-encrypted data of the time table and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param timeTable the time table 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 * time table does not have encrypted content.\n * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if\n * the operation failed.\n */\n async shareWithMany(\n timeTable: models.TimeTable,\n delegates: {\n [delegateId: string]: {\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.TimeTable> {\n return await this.modifyTimeTable(await this.crypto.entities.entityWithAutoExtendedEncryptedMetadata(timeTable, true, delegates))\n }\n\n async getDataOwnersWithAccessTo(\n entity: models.TimeTable\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: 'WRITE' }; hasUnknownAnonymousDataOwners: boolean }> {\n return await this.crypto.entities.getDataOwnersWithAccessTo(entity)\n }\n\n async getEncryptionKeysOf(entity: models.TimeTable): Promise<string[]> {\n return await this.crypto.entities.encryptionKeysOf(entity)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icure/api",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.0-beta.2",
4
4
  "description": "Typescript version of iCure standalone API client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",