@icure/api 8.3.5 → 8.4.0

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 (44) hide show
  1. package/icc-api/api/IccAuthApi.d.ts +10 -1
  2. package/icc-api/api/IccAuthApi.js +20 -3
  3. package/icc-api/api/IccAuthApi.js.map +1 -1
  4. package/icc-api/api/IccClassificationApi.d.ts +1 -0
  5. package/icc-api/api/IccClassificationApi.js +12 -0
  6. package/icc-api/api/IccClassificationApi.js.map +1 -1
  7. package/icc-api/api/IccMessageApi.d.ts +0 -6
  8. package/icc-api/api/IccMessageApi.js +0 -15
  9. package/icc-api/api/IccMessageApi.js.map +1 -1
  10. package/icc-x-api/auth/SmartAuthProvider.d.ts +37 -13
  11. package/icc-x-api/auth/SmartAuthProvider.js +105 -29
  12. package/icc-x-api/auth/SmartAuthProvider.js.map +1 -1
  13. package/icc-x-api/icc-bekmehr-x-api.js +2 -1
  14. package/icc-x-api/icc-bekmehr-x-api.js.map +1 -1
  15. package/icc-x-api/icc-document-x-api.d.ts +51 -6
  16. package/icc-x-api/icc-document-x-api.js +231 -69
  17. package/icc-x-api/icc-document-x-api.js.map +1 -1
  18. package/icc-x-api/icc-message-x-api.d.ts +45 -6
  19. package/icc-x-api/icc-message-x-api.js +202 -30
  20. package/icc-x-api/icc-message-x-api.js.map +1 -1
  21. package/icc-x-api/icc-patient-x-api.d.ts +9 -1
  22. package/icc-x-api/icc-patient-x-api.js +92 -100
  23. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  24. package/icc-x-api/index.d.ts +14 -14
  25. package/icc-x-api/index.js +5 -4
  26. package/icc-x-api/index.js.map +1 -1
  27. package/package.json +1 -1
  28. package/test/icc-api/api/IccDocumentApi.js +27 -35
  29. package/test/icc-api/api/IccDocumentApi.js.map +1 -1
  30. package/test/icc-x-api/auth/group-switch-test.js +5 -5
  31. package/test/icc-x-api/auth/group-switch-test.js.map +1 -1
  32. package/test/icc-x-api/auth/jwt-provider-test.js +1 -1
  33. package/test/icc-x-api/auth/jwt-provider-test.js.map +1 -1
  34. package/test/icc-x-api/auth/smart-auth-provider-test.js +5 -5
  35. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -1
  36. package/test/icc-x-api/icc-document-x-api.js +28 -4
  37. package/test/icc-x-api/icc-document-x-api.js.map +1 -1
  38. package/test/icc-x-api/icc-message-x-api.js +19 -293
  39. package/test/icc-x-api/icc-message-x-api.js.map +1 -1
  40. package/test/icc-x-api/icc-user-x-api-test.js +1 -1
  41. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -1
  42. package/test/utils/test_utils.d.ts +4 -2
  43. package/test/utils/test_utils.js +4 -3
  44. package/test/utils/test_utils.js.map +1 -1
@@ -12,6 +12,7 @@ import { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi';
12
12
  import AccessLevelEnum = SecureDelegation.AccessLevelEnum;
13
13
  import RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum;
14
14
  import { SecretIdUseOption } from './crypto/SecretIdUseOption';
15
+ import { ListOfIds, PaginatedListDocument } from '../icc-api/model/models';
15
16
  export declare class IccDocumentXApi extends IccDocumentApi implements EncryptedEntityXApi<models.Document> {
16
17
  private crypto;
17
18
  private authApi;
@@ -32,9 +33,10 @@ export declare class IccDocumentXApi extends IccDocumentApi implements Encrypted
32
33
  };
33
34
  dataOwnerApi: IccDataOwnerXApi;
34
35
  authenticationProvider: AuthenticationProvider;
36
+ private readonly encryptedFields;
35
37
  constructor(host: string, headers: {
36
38
  [key: string]: string;
37
- }, crypto: IccCryptoXApi, authApi: IccAuthApi, dataOwnerApi: IccDataOwnerXApi, autofillAuthor: boolean, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
39
+ }, crypto: IccCryptoXApi, authApi: IccAuthApi, dataOwnerApi: IccDataOwnerXApi, autofillAuthor: boolean, authenticationProvider?: AuthenticationProvider, encryptedKeys?: Array<string>, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
38
40
  get headers(): Promise<Array<XHR.Header>>;
39
41
  /**
40
42
  * Creates a new instance of document with initialised encryption metadata (not in the database).
@@ -60,16 +62,16 @@ export declare class IccDocumentXApi extends IccDocumentApi implements Encrypted
60
62
  ignoreAutoDelegations?: boolean;
61
63
  alternateRootDelegation?: string;
62
64
  }): Promise<models.Document>;
63
- /**
64
- * @deprecated use {@link findIdsByMessage} instead.
65
- */
66
- findByMessage(hcpartyId: string, message: models.Message): Promise<models.Document[]>;
67
65
  /**
68
66
  * Same as {@link findByMessage} but it will only return the ids of the contacts. It can also filter the documents where Document.created is between
69
67
  * startDate and endDate in ascending or descending order by that field. (default: ascending).
70
68
  */
71
69
  findIdsByMessage(hcpartyId: string, message: models.Message, startDate?: number, endDate?: number, descending?: boolean): Promise<string[]>;
72
- decrypt(hcpartyId: string, documents: Array<models.Document>): Promise<Array<models.Document>>;
70
+ decrypt(documents: Array<models.Document>): Promise<{
71
+ entity: models.Document;
72
+ decrypted: boolean;
73
+ }[]>;
74
+ encrypt(documents: Array<models.Document>): Promise<Array<models.Document>>;
73
75
  getAttachmentAs(documentId: string, attachmentId: string, returnType: "application/octet-stream", enckeys?: string, fileName?: string): Promise<ArrayBuffer>;
74
76
  getAttachmentAs(documentId: string, attachmentId: string, returnType: "text/plain", enckeys?: string, fileName?: string): Promise<string>;
75
77
  getAttachmentAs(documentId: string, attachmentId: string, returnType: "application/json", enckeys?: string, fileName?: string): Promise<any>;
@@ -247,4 +249,47 @@ export declare class IccDocumentXApi extends IccDocumentApi implements Encrypted
247
249
  }>;
248
250
  getEncryptionKeysOf(entity: models.Document): Promise<string[]>;
249
251
  createDelegationDeAnonymizationMetadata(entity: models.Document, delegates: string[]): Promise<void>;
252
+ private decryptPage;
253
+ createDocumentWithUser(user: models.User | undefined, body: models.Document): Promise<models.Document>;
254
+ deleteAttachmentWithUser(user: models.User | undefined, documentId: string): Promise<models.Document>;
255
+ /**
256
+ * @deprecated
257
+ */
258
+ findByTypeHCPartyMessageSecretFKeysWithUser(user: models.User | undefined, documentTypeCode: string, hcPartyId: string, secretFKeys: string[]): Promise<Array<models.Document>>;
259
+ /**
260
+ * @deprecated
261
+ */
262
+ findDocumentsByHCPartyPatientForeignKeysWithUser(user: models.User | undefined, hcPartyId: string, secretFKeys: string[]): Promise<Array<models.Document>>;
263
+ /**
264
+ * @deprecated
265
+ */
266
+ findDocumentsByHCPartyPatientForeignKeyWithUser(user: models.User | undefined, hcPartyId: string, secretFKey: string, startKey?: string, startDocumentId?: string, limit?: number): Promise<PaginatedListDocument>;
267
+ findWithoutDelegationWithUser(user: models.User | undefined, limit?: number): Promise<Array<models.Document>>;
268
+ getDocumentWithUser(user: models.User | undefined, documentId: string): Promise<models.Document>;
269
+ getDocumentByExternalUuidWithUser(user: models.User | undefined, externalUuid: string): Promise<models.Document>;
270
+ getDocumentsWithUser(user: models.User | undefined, body?: ListOfIds): Promise<Array<models.Document>>;
271
+ getDocumentsByExternalUuidWithUser(user: models.User | undefined, externalUuid: string): Promise<Array<models.Document>>;
272
+ modifyDocumentWithUser(user: models.User | undefined, body: models.Document): Promise<models.Document>;
273
+ modifyDocumentsWithUser(user: models.User | undefined, body: Array<models.Document>): Promise<Array<models.Document>>;
274
+ setMainDocumentAttachmentWithUser(user: models.User | undefined, documentId: string, documentRev: string, body: Object, utis?: Array<string>, dataIsEncrypted?: boolean): Promise<models.Document>;
275
+ setSecondaryAttachmentWithUser(user: models.User | undefined, documentId: string, key: string, rev: string, attachment: Object, utis?: Array<string>, dataIsEncrypted?: boolean): Promise<models.Document>;
276
+ deleteSecondaryAttachmentWithUser(user: models.User | undefined, documentId: string, key: string, rev: string): Promise<models.Document>;
277
+ createDocument(body?: models.Document): never;
278
+ deleteAttachment(documentId: string): never;
279
+ findByTypeHCPartyMessageSecretFKeys(documentTypeCode: string, hcPartyId: string, secretFKeys: string[]): never;
280
+ findDocumentsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string[]): never;
281
+ findDocumentsByHCPartyPatientForeignKey(hcPartyId: string, secretFKey: string, startKey?: string, startDocumentId?: string, limit?: number): never;
282
+ findWithoutDelegation(limit?: number): never;
283
+ getDocument(documentId: string): never;
284
+ getDocumentByExternalUuid(externalUuid: string): never;
285
+ getDocuments(body?: ListOfIds): never;
286
+ getDocumentsByExternalUuid(externalUuid: string): never;
287
+ modifyDocument(body?: models.Document): never;
288
+ modifyDocuments(body?: Array<models.Document>): never;
289
+ setMainDocumentAttachment(documentId: string, documentRev: string, body: Object, utis?: Array<string>, dataIsEncrypted?: boolean): never;
290
+ setDocumentAttachmentBody(documentId: string, documentRev: string, enckeys?: null, body?: Object, utis?: string[]): never;
291
+ setDocumentAttachment(documentId: string, documentRev: string, enckeys?: null, body?: Object, utis?: string[]): never;
292
+ setDocumentAttachmentMulti(attachment: ArrayBuffer, documentRev: string, documentId: string, enckeys?: null): never;
293
+ setSecondaryAttachment(documentId: string, key: string, rev: string, attachment: Object, utis?: Array<string>, dataIsEncrypted?: boolean): never;
294
+ deleteSecondaryAttachment(documentId: string, key: string, rev: string): never;
250
295
  }
@@ -22,7 +22,7 @@ var AccessLevelEnum = SecureDelegation_1.SecureDelegation.AccessLevelEnum;
22
22
  const SecretIdUseOption_1 = require("./crypto/SecretIdUseOption");
23
23
  // noinspection JSUnusedGlobalSymbols
24
24
  class IccDocumentXApi extends icc_api_1.IccDocumentApi {
25
- constructor(host, headers, crypto, authApi, dataOwnerApi, autofillAuthor, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), fetchImpl = typeof window !== 'undefined'
25
+ constructor(host, headers, crypto, authApi, dataOwnerApi, autofillAuthor, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), encryptedKeys = [], fetchImpl = typeof window !== 'undefined'
26
26
  ? window.fetch
27
27
  : typeof self !== 'undefined'
28
28
  ? self.fetch
@@ -423,6 +423,7 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
423
423
  this.fetchImpl = fetchImpl;
424
424
  this.authenticationProvider = authenticationProvider;
425
425
  this.dataOwnerApi = dataOwnerApi;
426
+ this.encryptedFields = (0, utils_1.parseEncryptedFields)(encryptedKeys, 'Document.');
426
427
  }
427
428
  get headers() {
428
429
  return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, utils_1.EntityWithDelegationTypeName.Document));
@@ -462,17 +463,6 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
462
463
  });
463
464
  }
464
465
  // noinspection JSUnusedGlobalSymbols
465
- /**
466
- * @deprecated use {@link findIdsByMessage} instead.
467
- */
468
- findByMessage(hcpartyId, message) {
469
- return __awaiter(this, void 0, void 0, function* () {
470
- const extractedKeys = yield this.crypto.xapi.secretIdsOf({ entity: message, type: utils_1.EntityWithDelegationTypeName.Message }, hcpartyId);
471
- const topmostParentId = (yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds())[0];
472
- let documents = yield this.findDocumentsByHCPartyPatientForeignKeys(topmostParentId, _.uniq(extractedKeys));
473
- return yield this.decrypt(hcpartyId, documents);
474
- });
475
- }
476
466
  /**
477
467
  * Same as {@link findByMessage} but it will only return the ids of the contacts. It can also filter the documents where Document.created is between
478
468
  * startDate and endDate in ascending or descending order by that field. (default: ascending).
@@ -484,55 +474,14 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
484
474
  return this.findDocumentIdsByDataOwnerSecretForeignKey(topmostParentId, _.uniq(extractedKeys), startDate, endDate, descending);
485
475
  });
486
476
  }
487
- // Note: this is only for dealing with legacy documents: new document are not encrypted, only their attachments are
488
- decrypt(hcpartyId, documents) {
477
+ decrypt(documents) {
489
478
  return __awaiter(this, void 0, void 0, function* () {
490
- const res = [];
491
- for (const document of documents) {
492
- const keys = yield this.crypto.xapi.encryptionKeysOf({ entity: document, type: utils_1.EntityWithDelegationTypeName.Document }, undefined);
493
- if (!keys.length) {
494
- console.log('Cannot decrypt document', document.id);
495
- res.push(document);
496
- }
497
- else if (keys.length && (document.encryptedSelf || document.encryptedAttachment)) {
498
- const key = yield this.crypto.primitives.AES.importKey('raw', (0, binary_utils_1.hex2ua)(keys[0]));
499
- res.push(yield Promise.all([
500
- document.encryptedSelf
501
- ? new Promise((resolve) => {
502
- this.crypto.primitives.AES.decrypt(key, (0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(document.encryptedSelf))).then(resolve, () => {
503
- console.log('Cannot decrypt document', document.id);
504
- resolve(null);
505
- });
506
- })
507
- : Promise.resolve(null),
508
- document.encryptedAttachment
509
- ? new Promise((resolve) => {
510
- this.crypto.primitives.AES.decrypt(key, document.encryptedAttachment).then(resolve, () => {
511
- console.log('Cannot decrypt document', document.id);
512
- resolve(null);
513
- });
514
- })
515
- : Promise.resolve(null),
516
- ]).then((decrypted) => {
517
- let updatedDocument = Object.assign({}, document);
518
- if (decrypted) {
519
- if (decrypted[0]) {
520
- updatedDocument = _.extend(document, JSON.parse((0, binary_utils_1.ua2string)(decrypted[0])));
521
- }
522
- if (decrypted[1]) {
523
- updatedDocument.decryptedAttachment = decrypted[1];
524
- }
525
- }
526
- return updatedDocument;
527
- }));
528
- }
529
- else {
530
- res.push(document);
531
- }
532
- }
533
- return res;
479
+ return yield this.crypto.xapi.tryDecryptEntities(documents, utils_1.EntityWithDelegationTypeName.Document, (x) => new models.Document(x));
534
480
  });
535
481
  }
482
+ encrypt(documents) {
483
+ return this.crypto.xapi.tryEncryptEntities(documents, utils_1.EntityWithDelegationTypeName.Document, this.encryptedFields, true, false, (x) => new models.Document(x));
484
+ }
536
485
  /**
537
486
  * @deprecated use getMainAttachmentAs instead
538
487
  */
@@ -610,12 +559,15 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
610
559
  * @return the updated document.
611
560
  */
612
561
  encryptAndSetDocumentAttachment(document, attachment, utis) {
562
+ const _super = Object.create(null, {
563
+ setMainDocumentAttachment: { get: () => super.setMainDocumentAttachment }
564
+ });
613
565
  return __awaiter(this, void 0, void 0, function* () {
614
566
  var _a;
615
567
  if (!document.rev)
616
568
  throw new Error('Cannot set attachment on document without rev');
617
- const { encryptedData, updatedEntity } = yield this.crypto.xapi.encryptDataOf(document, utils_1.EntityWithDelegationTypeName.Document, attachment, (d) => this.modifyDocument(d));
618
- return yield this.setMainDocumentAttachment(document.id, (_a = updatedEntity === null || updatedEntity === void 0 ? void 0 : updatedEntity.rev) !== null && _a !== void 0 ? _a : document.rev, encryptedData, utis, true);
569
+ const { encryptedData, updatedEntity } = yield this.crypto.xapi.encryptDataOf(document, utils_1.EntityWithDelegationTypeName.Document, attachment, (d) => this.modifyDocumentWithUser(undefined, d));
570
+ return (yield this.decrypt([yield _super.setMainDocumentAttachment.call(this, document.id, (_a = updatedEntity === null || updatedEntity === void 0 ? void 0 : updatedEntity.rev) !== null && _a !== void 0 ? _a : document.rev, encryptedData, utis, true)]))[0].entity;
619
571
  });
620
572
  }
621
573
  /**
@@ -627,10 +579,13 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
627
579
  * @return the updated document.
628
580
  */
629
581
  setClearDocumentAttachment(document, attachment, utis) {
582
+ const _super = Object.create(null, {
583
+ setMainDocumentAttachment: { get: () => super.setMainDocumentAttachment }
584
+ });
630
585
  return __awaiter(this, void 0, void 0, function* () {
631
586
  if (!document.rev)
632
587
  throw new Error('Cannot set attachment on document without rev');
633
- return yield this.setMainDocumentAttachment(document.id, document.rev, attachment, utis, false);
588
+ return (yield this.decrypt([yield _super.setMainDocumentAttachment.call(this, document.id, document.rev, attachment, utis, false)]))[0].entity;
634
589
  });
635
590
  }
636
591
  /**
@@ -643,12 +598,17 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
643
598
  * @return the updated document.
644
599
  */
645
600
  encryptAndSetSecondaryDocumentAttachment(document, secondaryAttachmentKey, attachment, utis) {
601
+ const _super = Object.create(null, {
602
+ setSecondaryAttachment: { get: () => super.setSecondaryAttachment }
603
+ });
646
604
  return __awaiter(this, void 0, void 0, function* () {
647
605
  var _a;
648
606
  if (!document.rev)
649
607
  throw new Error('Cannot set attachment on document without rev');
650
- const { encryptedData, updatedEntity } = yield this.crypto.xapi.encryptDataOf(document, utils_1.EntityWithDelegationTypeName.Document, attachment, (d) => this.modifyDocument());
651
- return yield this.setSecondaryAttachment(document.id, secondaryAttachmentKey, (_a = updatedEntity === null || updatedEntity === void 0 ? void 0 : updatedEntity.rev) !== null && _a !== void 0 ? _a : document.rev, encryptedData, utis, true);
608
+ const { encryptedData, updatedEntity } = yield this.crypto.xapi.encryptDataOf(document, utils_1.EntityWithDelegationTypeName.Document, attachment, (d) => this.modifyDocumentWithUser(undefined, d));
609
+ return (yield this.decrypt([
610
+ yield _super.setSecondaryAttachment.call(this, document.id, secondaryAttachmentKey, (_a = updatedEntity === null || updatedEntity === void 0 ? void 0 : updatedEntity.rev) !== null && _a !== void 0 ? _a : document.rev, encryptedData, utis, true),
611
+ ]))[0].entity;
652
612
  });
653
613
  }
654
614
  /**
@@ -661,8 +621,12 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
661
621
  * @return the updated document.
662
622
  */
663
623
  setClearSecondaryDocumentAttachment(document, secondaryAttachmentKey, attachment, utis) {
624
+ const _super = Object.create(null, {
625
+ setSecondaryAttachment: { get: () => super.setSecondaryAttachment }
626
+ });
664
627
  return __awaiter(this, void 0, void 0, function* () {
665
- return yield this.setSecondaryAttachment(document.id, secondaryAttachmentKey, document.rev, attachment, utis, false);
628
+ return (yield this.decrypt([yield _super.setSecondaryAttachment.call(this, document.id, secondaryAttachmentKey, document.rev, attachment, utis, false)]))[0]
629
+ .entity;
666
630
  });
667
631
  }
668
632
  /**
@@ -690,8 +654,11 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
690
654
  * - wasDecrypted: if the data was successfully decrypted or not
691
655
  */
692
656
  getAndTryDecryptDocumentAttachment(document_1) {
657
+ const _super = Object.create(null, {
658
+ getRawMainDocumentAttachment: { get: () => super.getRawMainDocumentAttachment }
659
+ });
693
660
  return __awaiter(this, arguments, void 0, function* (document, validator = () => Promise.resolve(true)) {
694
- return yield this.crypto.xapi.tryDecryptDataOf({ entity: document, type: utils_1.EntityWithDelegationTypeName.Document }, yield this.getRawMainDocumentAttachment(document.id), (x) => validator(x));
661
+ return yield this.crypto.xapi.tryDecryptDataOf({ entity: document, type: utils_1.EntityWithDelegationTypeName.Document }, yield _super.getRawMainDocumentAttachment.call(this, document.id), (x) => validator(x));
695
662
  });
696
663
  }
697
664
  /**
@@ -721,8 +688,11 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
721
688
  * - wasDecrypted: if the data was successfully decrypted or not
722
689
  */
723
690
  getAndTryDecryptSecondaryDocumentAttachment(document_1, secondaryAttachmentKey_1) {
691
+ const _super = Object.create(null, {
692
+ getSecondaryAttachment: { get: () => super.getSecondaryAttachment }
693
+ });
724
694
  return __awaiter(this, arguments, void 0, function* (document, secondaryAttachmentKey, validator = () => Promise.resolve(true)) {
725
- return yield this.crypto.xapi.tryDecryptDataOf({ entity: document, type: utils_1.EntityWithDelegationTypeName.Document }, yield this.getSecondaryAttachment(document.id, secondaryAttachmentKey), (x) => validator(x));
695
+ return yield this.crypto.xapi.tryDecryptDataOf({ entity: document, type: utils_1.EntityWithDelegationTypeName.Document }, yield _super.getSecondaryAttachment.call(this, document.id, secondaryAttachmentKey), (x) => validator(x));
726
696
  });
727
697
  }
728
698
  /**
@@ -795,11 +765,14 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
795
765
  * the operation failed.
796
766
  */
797
767
  tryShareWithMany(document, delegates) {
768
+ const _super = Object.create(null, {
769
+ bulkShareDocument: { get: () => super.bulkShareDocument }
770
+ });
798
771
  return __awaiter(this, void 0, void 0, function* () {
799
772
  const self = yield this.dataOwnerApi.getCurrentDataOwnerId();
800
773
  // All entities should have an encryption key.
801
774
  const entityWithEncryptionKey = yield this.crypto.xapi.ensureEncryptionKeysInitialised(document, utils_1.EntityWithDelegationTypeName.Document);
802
- const updatedEntity = entityWithEncryptionKey ? yield this.modifyDocument(entityWithEncryptionKey) : document;
775
+ const updatedEntity = entityWithEncryptionKey ? yield this.modifyDocumentWithUser(undefined, entityWithEncryptionKey) : document;
803
776
  return this.crypto.xapi
804
777
  .simpleShareOrUpdateEncryptedEntityMetadata({
805
778
  entity: updatedEntity,
@@ -812,8 +785,8 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
812
785
  shareOwningEntityIds: options.shareMessageId,
813
786
  shareSecretIds: options.shareSecretIds,
814
787
  },
815
- ])), (x) => this.bulkShareDocument(x))
816
- .then((r) => r);
788
+ ])), (x) => _super.bulkShareDocument.call(this, x))
789
+ .then((r) => r.mapSuccessAsync((m) => __awaiter(this, void 0, void 0, function* () { return (yield this.decrypt([m]))[0].entity; })));
817
790
  });
818
791
  }
819
792
  getDataOwnersWithAccessTo(entity) {
@@ -825,6 +798,195 @@ class IccDocumentXApi extends icc_api_1.IccDocumentApi {
825
798
  createDelegationDeAnonymizationMetadata(entity, delegates) {
826
799
  return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: utils_1.EntityWithDelegationTypeName.Document }, delegates);
827
800
  }
801
+ decryptPage(page) {
802
+ return __awaiter(this, void 0, void 0, function* () {
803
+ var _a;
804
+ return Object.assign(Object.assign({}, page), { rows: (yield this.decrypt((_a = page.rows) !== null && _a !== void 0 ? _a : [])).map((x) => x.entity) });
805
+ });
806
+ }
807
+ createDocumentWithUser(user, body) {
808
+ const _super = Object.create(null, {
809
+ createDocument: { get: () => super.createDocument }
810
+ });
811
+ return __awaiter(this, void 0, void 0, function* () {
812
+ return (yield this.decrypt([yield _super.createDocument.call(this, (yield this.encrypt([body]))[0])]))[0].entity;
813
+ });
814
+ }
815
+ deleteAttachmentWithUser(user, documentId) {
816
+ const _super = Object.create(null, {
817
+ deleteAttachment: { get: () => super.deleteAttachment }
818
+ });
819
+ return __awaiter(this, void 0, void 0, function* () {
820
+ return (yield this.decrypt([yield _super.deleteAttachment.call(this, documentId)]))[0].entity;
821
+ });
822
+ }
823
+ /**
824
+ * @deprecated
825
+ */
826
+ findByTypeHCPartyMessageSecretFKeysWithUser(user, documentTypeCode, hcPartyId, secretFKeys) {
827
+ const _super = Object.create(null, {
828
+ findByTypeHCPartyMessageSecretFKeys: { get: () => super.findByTypeHCPartyMessageSecretFKeys }
829
+ });
830
+ return __awaiter(this, void 0, void 0, function* () {
831
+ return (yield this.decrypt(yield _super.findByTypeHCPartyMessageSecretFKeys.call(this, documentTypeCode, hcPartyId, secretFKeys))).map((x) => x.entity);
832
+ });
833
+ }
834
+ /**
835
+ * @deprecated
836
+ */
837
+ findDocumentsByHCPartyPatientForeignKeysWithUser(user, hcPartyId, secretFKeys) {
838
+ const _super = Object.create(null, {
839
+ findDocumentsByHCPartyPatientForeignKeys: { get: () => super.findDocumentsByHCPartyPatientForeignKeys }
840
+ });
841
+ return __awaiter(this, void 0, void 0, function* () {
842
+ return (yield this.decrypt(yield _super.findDocumentsByHCPartyPatientForeignKeys.call(this, hcPartyId, secretFKeys))).map((x) => x.entity);
843
+ });
844
+ }
845
+ /**
846
+ * @deprecated
847
+ */
848
+ findDocumentsByHCPartyPatientForeignKeyWithUser(user, hcPartyId, secretFKey, startKey, startDocumentId, limit) {
849
+ const _super = Object.create(null, {
850
+ findDocumentsByHCPartyPatientForeignKey: { get: () => super.findDocumentsByHCPartyPatientForeignKey }
851
+ });
852
+ return __awaiter(this, void 0, void 0, function* () {
853
+ return yield this.decryptPage(yield _super.findDocumentsByHCPartyPatientForeignKey.call(this, hcPartyId, secretFKey, startKey, startDocumentId, limit));
854
+ });
855
+ }
856
+ findWithoutDelegationWithUser(user, limit) {
857
+ const _super = Object.create(null, {
858
+ findWithoutDelegation: { get: () => super.findWithoutDelegation }
859
+ });
860
+ return __awaiter(this, void 0, void 0, function* () {
861
+ return (yield this.decrypt(yield _super.findWithoutDelegation.call(this, limit))).map((x) => x.entity);
862
+ });
863
+ }
864
+ getDocumentWithUser(user, documentId) {
865
+ const _super = Object.create(null, {
866
+ getDocument: { get: () => super.getDocument }
867
+ });
868
+ return __awaiter(this, void 0, void 0, function* () {
869
+ return (yield this.decrypt([yield _super.getDocument.call(this, documentId)]))[0].entity;
870
+ });
871
+ }
872
+ getDocumentByExternalUuidWithUser(user, externalUuid) {
873
+ const _super = Object.create(null, {
874
+ getDocumentByExternalUuid: { get: () => super.getDocumentByExternalUuid }
875
+ });
876
+ return __awaiter(this, void 0, void 0, function* () {
877
+ return (yield this.decrypt([yield _super.getDocumentByExternalUuid.call(this, externalUuid)]))[0].entity;
878
+ });
879
+ }
880
+ getDocumentsWithUser(user, body) {
881
+ const _super = Object.create(null, {
882
+ getDocuments: { get: () => super.getDocuments }
883
+ });
884
+ return __awaiter(this, void 0, void 0, function* () {
885
+ return (yield this.decrypt(yield _super.getDocuments.call(this, body))).map((x) => x.entity);
886
+ });
887
+ }
888
+ getDocumentsByExternalUuidWithUser(user, externalUuid) {
889
+ const _super = Object.create(null, {
890
+ getDocumentsByExternalUuid: { get: () => super.getDocumentsByExternalUuid }
891
+ });
892
+ return __awaiter(this, void 0, void 0, function* () {
893
+ return (yield this.decrypt(yield _super.getDocumentsByExternalUuid.call(this, externalUuid))).map((x) => x.entity);
894
+ });
895
+ }
896
+ modifyDocumentWithUser(user, body) {
897
+ const _super = Object.create(null, {
898
+ modifyDocument: { get: () => super.modifyDocument }
899
+ });
900
+ return __awaiter(this, void 0, void 0, function* () {
901
+ return (yield this.decrypt([yield _super.modifyDocument.call(this, (yield this.encrypt([body]))[0])]))[0].entity;
902
+ });
903
+ }
904
+ modifyDocumentsWithUser(user, body) {
905
+ const _super = Object.create(null, {
906
+ modifyDocuments: { get: () => super.modifyDocuments }
907
+ });
908
+ return __awaiter(this, void 0, void 0, function* () {
909
+ return (yield this.decrypt(yield _super.modifyDocuments.call(this, yield this.encrypt(body)))).map((x) => x.entity);
910
+ });
911
+ }
912
+ setMainDocumentAttachmentWithUser(user, documentId, documentRev, body, utis, dataIsEncrypted) {
913
+ const _super = Object.create(null, {
914
+ setMainDocumentAttachment: { get: () => super.setMainDocumentAttachment }
915
+ });
916
+ return __awaiter(this, void 0, void 0, function* () {
917
+ return (yield this.decrypt([yield _super.setMainDocumentAttachment.call(this, documentId, documentRev, body, utis, dataIsEncrypted)]))[0].entity;
918
+ });
919
+ }
920
+ setSecondaryAttachmentWithUser(user, documentId, key, rev, attachment, utis, dataIsEncrypted) {
921
+ const _super = Object.create(null, {
922
+ setSecondaryAttachment: { get: () => super.setSecondaryAttachment }
923
+ });
924
+ return __awaiter(this, void 0, void 0, function* () {
925
+ return (yield this.decrypt([yield _super.setSecondaryAttachment.call(this, documentId, key, rev, attachment, utis, dataIsEncrypted)]))[0].entity;
926
+ });
927
+ }
928
+ deleteSecondaryAttachmentWithUser(user, documentId, key, rev) {
929
+ const _super = Object.create(null, {
930
+ deleteSecondaryAttachment: { get: () => super.deleteSecondaryAttachment }
931
+ });
932
+ return __awaiter(this, void 0, void 0, function* () {
933
+ return (yield this.decrypt([yield _super.deleteSecondaryAttachment.call(this, documentId, key, rev)]))[0].entity;
934
+ });
935
+ }
936
+ createDocument(body) {
937
+ throw new Error('Use withUser method');
938
+ }
939
+ deleteAttachment(documentId) {
940
+ throw new Error('Use withUser method');
941
+ }
942
+ findByTypeHCPartyMessageSecretFKeys(documentTypeCode, hcPartyId, secretFKeys) {
943
+ throw new Error('Use withUser method');
944
+ }
945
+ findDocumentsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys) {
946
+ throw new Error('Use withUser method');
947
+ }
948
+ findDocumentsByHCPartyPatientForeignKey(hcPartyId, secretFKey, startKey, startDocumentId, limit) {
949
+ throw new Error('Use withUser method');
950
+ }
951
+ findWithoutDelegation(limit) {
952
+ throw new Error('Use withUser method');
953
+ }
954
+ getDocument(documentId) {
955
+ throw new Error('Use withUser method');
956
+ }
957
+ getDocumentByExternalUuid(externalUuid) {
958
+ throw new Error('Use withUser method');
959
+ }
960
+ getDocuments(body) {
961
+ throw new Error('Use withUser method');
962
+ }
963
+ getDocumentsByExternalUuid(externalUuid) {
964
+ throw new Error('Use withUser method');
965
+ }
966
+ modifyDocument(body) {
967
+ throw new Error('Use withUser method');
968
+ }
969
+ modifyDocuments(body) {
970
+ throw new Error('Use withUser method');
971
+ }
972
+ setMainDocumentAttachment(documentId, documentRev, body, utis, dataIsEncrypted) {
973
+ throw new Error('Use withUser method');
974
+ }
975
+ setDocumentAttachmentBody(documentId, documentRev, enckeys, body, utis) {
976
+ throw new Error('Use withUser method');
977
+ }
978
+ setDocumentAttachment(documentId, documentRev, enckeys, body, utis) {
979
+ throw new Error('Use withUser method');
980
+ }
981
+ setDocumentAttachmentMulti(attachment, documentRev, documentId, enckeys) {
982
+ throw new Error('Use withUser method');
983
+ }
984
+ setSecondaryAttachment(documentId, key, rev, attachment, utis, dataIsEncrypted) {
985
+ throw new Error('Use withUser method');
986
+ }
987
+ deleteSecondaryAttachment(documentId, key, rev) {
988
+ throw new Error('Use withUser method');
989
+ }
828
990
  }
829
991
  exports.IccDocumentXApi = IccDocumentXApi;
830
992
  //# sourceMappingURL=icc-document-x-api.js.map