@icure/api 8.1.8 → 8.2.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 (107) hide show
  1. package/icc-api/model/RouteOfAdministration.d.ts +0 -1
  2. package/icc-api/model/RouteOfAdministration.js.map +1 -1
  3. package/icc-api/model/Vmp.d.ts +0 -2
  4. package/icc-api/model/Vmp.js.map +1 -1
  5. package/icc-api/model/VmpGroup.d.ts +0 -2
  6. package/icc-api/model/VmpGroup.js.map +1 -1
  7. package/icc-api/model/internal/ExchangeData.d.ts +1 -1
  8. package/icc-api/model/internal/ExchangeData.js +1 -7
  9. package/icc-api/model/internal/ExchangeData.js.map +1 -1
  10. package/icc-x-api/crypto/BaseExchangeDataManager.d.ts +19 -9
  11. package/icc-x-api/crypto/BaseExchangeDataManager.js +27 -6
  12. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
  13. package/icc-x-api/crypto/CryptoStrategies.d.ts +2 -1
  14. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -1
  15. package/icc-x-api/crypto/DelegationsDeAnonymization.js +1 -1
  16. package/icc-x-api/crypto/DelegationsDeAnonymization.js.map +1 -1
  17. package/icc-x-api/crypto/ExchangeDataManager.d.ts +25 -2
  18. package/icc-x-api/crypto/ExchangeDataManager.js +98 -5
  19. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  20. package/icc-x-api/crypto/ExtendedApisUtils.d.ts +3 -1
  21. package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -1
  22. package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +1 -1
  23. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +3 -3
  24. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
  25. package/icc-x-api/crypto/SecureDelegationsManager.d.ts +3 -1
  26. package/icc-x-api/crypto/SecureDelegationsManager.js +10 -6
  27. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
  28. package/icc-x-api/crypto/ShamirKeysManager.js +1 -1
  29. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
  30. package/icc-x-api/crypto/UserEncryptionKeysManager.js +4 -0
  31. package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -1
  32. package/icc-x-api/crypto/utils.js +1 -1
  33. package/icc-x-api/crypto/utils.js.map +1 -1
  34. package/icc-x-api/icc-accesslog-x-api.d.ts +6 -0
  35. package/icc-x-api/icc-accesslog-x-api.js +6 -2
  36. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  37. package/icc-x-api/icc-bekmehr-x-api.js +1 -1
  38. package/icc-x-api/icc-bekmehr-x-api.js.map +1 -1
  39. package/icc-x-api/icc-calendar-item-x-api.d.ts +4 -0
  40. package/icc-x-api/icc-calendar-item-x-api.js +3 -1
  41. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  42. package/icc-x-api/icc-classification-x-api.d.ts +3 -0
  43. package/icc-x-api/icc-classification-x-api.js +3 -1
  44. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  45. package/icc-x-api/icc-contact-x-api.d.ts +3 -0
  46. package/icc-x-api/icc-contact-x-api.js +3 -1
  47. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  48. package/icc-x-api/icc-crypto-x-api.d.ts +29 -0
  49. package/icc-x-api/icc-crypto-x-api.js +36 -0
  50. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  51. package/icc-x-api/icc-document-x-api.d.ts +3 -0
  52. package/icc-x-api/icc-document-x-api.js +3 -1
  53. package/icc-x-api/icc-document-x-api.js.map +1 -1
  54. package/icc-x-api/icc-form-x-api.d.ts +3 -0
  55. package/icc-x-api/icc-form-x-api.js +3 -1
  56. package/icc-x-api/icc-form-x-api.js.map +1 -1
  57. package/icc-x-api/icc-helement-x-api.d.ts +3 -0
  58. package/icc-x-api/icc-helement-x-api.js +3 -1
  59. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  60. package/icc-x-api/icc-invoice-x-api.d.ts +3 -0
  61. package/icc-x-api/icc-invoice-x-api.js +3 -1
  62. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  63. package/icc-x-api/icc-maintenance-task-x-api.d.ts +3 -0
  64. package/icc-x-api/icc-maintenance-task-x-api.js +3 -1
  65. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  66. package/icc-x-api/icc-message-x-api.d.ts +3 -0
  67. package/icc-x-api/icc-message-x-api.js +3 -1
  68. package/icc-x-api/icc-message-x-api.js.map +1 -1
  69. package/icc-x-api/icc-patient-x-api.d.ts +3 -0
  70. package/icc-x-api/icc-patient-x-api.js +6 -2
  71. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  72. package/icc-x-api/icc-receipt-x-api.d.ts +3 -0
  73. package/icc-x-api/icc-receipt-x-api.js +3 -1
  74. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  75. package/icc-x-api/icc-recovery-x-api.js +8 -1
  76. package/icc-x-api/icc-recovery-x-api.js.map +1 -1
  77. package/icc-x-api/icc-time-table-x-api.d.ts +3 -0
  78. package/icc-x-api/icc-time-table-x-api.js +3 -1
  79. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  80. package/icc-x-api/icc-topic-x-api.d.ts +3 -0
  81. package/icc-x-api/icc-topic-x-api.js +3 -1
  82. package/icc-x-api/icc-topic-x-api.js.map +1 -1
  83. package/icc-x-api/index.d.ts +16 -0
  84. package/icc-x-api/index.js +7 -1
  85. package/icc-x-api/index.js.map +1 -1
  86. package/icc-x-api/utils/websocket.d.ts +1 -0
  87. package/package.json +1 -1
  88. package/test/icc-x-api/autofix-anonymity-test.js +18 -4
  89. package/test/icc-x-api/autofix-anonymity-test.js.map +1 -1
  90. package/test/icc-x-api/crypto/exchange-data-manager-test.js +34 -32
  91. package/test/icc-x-api/crypto/exchange-data-manager-test.js.map +1 -1
  92. package/test/icc-x-api/crypto/secure-delegations-manager-test.js +2 -2
  93. package/test/icc-x-api/crypto/secure-delegations-manager-test.js.map +1 -1
  94. package/test/icc-x-api/icc-hcparty-x-api-test.js +2 -14
  95. package/test/icc-x-api/icc-hcparty-x-api-test.js.map +1 -1
  96. package/test/icc-x-api/keyless-api.d.ts +1 -0
  97. package/test/icc-x-api/keyless-api.js +125 -0
  98. package/test/icc-x-api/keyless-api.js.map +1 -0
  99. package/test/utils/FakeExchangeDataManager.d.ts +8 -0
  100. package/test/utils/FakeExchangeDataManager.js +3 -0
  101. package/test/utils/FakeExchangeDataManager.js.map +1 -1
  102. package/test/utils/KeylessCryptoStrategies.d.ts +23 -0
  103. package/test/utils/KeylessCryptoStrategies.js +26 -0
  104. package/test/utils/KeylessCryptoStrategies.js.map +1 -0
  105. package/test/utils/test_utils.d.ts +7 -0
  106. package/test/utils/test_utils.js +30 -1
  107. package/test/utils/test_utils.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gFAA4E;AAE5E,kDAAiD;AACjD,4BAA2B;AAE3B,oDAAmF;AAEnF,0EAAgG;AAChG,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AACzD,4EAAwE;AAKxE,mCAAmJ;AAInJ,4DAAwE;AAGxE,MAAa,sBAAuB,SAAQ,6CAAqB;IAG/D,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAC9B,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,eAAe,CAAC,CAClH,CAAA;IACH,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,UAA0B,EAC1B,YAA8B,EAC9B,OAAoB,EACpB,OAAmB,EACnB,cAAuB,EACxC,gBAA+B,EAAE,EACjC,yBAAiD,IAAI,iDAAwB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EAAE,SAAmB;QAClF,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAC7E,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,eAAe,EAAE,EAC9D,SAAS,CACV,CAAA;IACH,CAAC;CACF;AA/TD,wDA+TC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { DocIdentifier, ListOfIds, MaintenanceTask } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { IccAuthApi } from '../icc-api'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { AbstractFilter } from './filters/filters'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { IccUserXApi } from './icc-user-x-api'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi implements EncryptedEntityXApi<models.MaintenanceTask> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) =>\n this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.MaintenanceTask)\n )\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly hcPartyApi: IccHcpartyXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly userApi: IccUserXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n encryptedKeys: Array<string> = [],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'MaintenanceTask.')\n }\n\n /**\n * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param m initialised data for the maintenance task. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * @return a new instance of maintenance task.\n */\n async newInstance(\n user: models.User,\n m: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const maintenanceTask = {\n ...(m ?? {}),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n id: m?.id ?? this.crypto.primitives.randomUuid(),\n created: m?.created ?? new Date().getTime(),\n modified: m?.modified ?? new Date().getTime(),\n responsible: m?.responsible ?? (this.autofillAuthor ? dataOwnerId : undefined),\n author: m?.author ?? (this.autofillAuthor ? user.id : undefined),\n }\n\n const extraDelegations = {\n ...Object.fromEntries((user.autoDelegations?.all ?? []).map((d) => [d, AccessLevelEnum.WRITE])),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.MaintenanceTask(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n maintenanceTask,\n EntityWithDelegationTypeName.MaintenanceTask,\n undefined,\n undefined,\n true,\n extraDelegations\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<DocIdentifier> | never {\n return super.deleteMaintenanceTask(maintenanceTaskId)\n }\n\n deleteMaintenanceTasks(_maintenanceTaskIds: ListOfIds): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTasksWithUser(user: models.User, maintenanceTaskIds: ListOfIds): Promise<Array<DocIdentifier>> | never {\n return super.deleteMaintenanceTasks(maintenanceTaskIds)\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body ? this.modifyMaintenanceTaskAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n\n private modifyMaintenanceTaskAs(dataOwner: string, body: models.MaintenanceTask): Promise<models.MaintenanceTask> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decryptAs(dataOwner, [mt]))\n .then((mts) => mts[0])\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n return this.encryptAs(dataOwnerId, maintenanceTasks)\n }\n\n private encryptAs(dataOwner: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return this.crypto.xapi.tryEncryptEntities(\n maintenanceTasks,\n EntityWithDelegationTypeName.MaintenanceTask,\n this.encryptedFields,\n true,\n false,\n (x) => new models.MaintenanceTask(x)\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n return this.decryptAs(dataOwnerId, maintenanceTasks)\n }\n\n private async decryptAs(dataOwner: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return (\n await this.crypto.xapi.tryDecryptEntities(maintenanceTasks, EntityWithDelegationTypeName.MaintenanceTask, (x) => new MaintenanceTask(x))\n ).map(({ entity }) => entity)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given maintenance task\n */\n async hasWriteAccess(maintenanceTask: models.MaintenanceTask): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: maintenanceTask, type: EntityWithDelegationTypeName.MaintenanceTask })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the maintenance task.\n * @param maintenanceTask the maintenance task to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n maintenanceTask: models.MaintenanceTask,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.MaintenanceTask> {\n return this.shareWithMany(maintenanceTask, { [delegateId]: options })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity.\n */\n async shareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.MaintenanceTask> {\n return (await this.tryShareWithMany(maintenanceTask, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\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 tryShareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.MaintenanceTask>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(\n maintenanceTask,\n EntityWithDelegationTypeName.MaintenanceTask\n )\n const updatedEntity = entityWithEncryptionKey ? await this.modifyMaintenanceTaskAs(self, entityWithEncryptionKey) : maintenanceTask\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.MaintenanceTask,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: ShareMetadataBehaviour.NEVER,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareMaintenanceTask(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decryptAs(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.MaintenanceTask\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.MaintenanceTask })\n }\n\n getEncryptionKeysOf(entity: models.MaintenanceTask): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.MaintenanceTask }, undefined)\n }\n\n async subscribeToMaintenanceTaskEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<MaintenanceTask>,\n eventFired: (dataSample: MaintenanceTask) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n const currentUser = await this.userApi.getCurrentUser()\n\n return subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.MaintenanceTask,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt(currentUser, [encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: MaintenanceTask, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.MaintenanceTask },\n delegates\n )\n }\n}\n"]}
1
+ {"version":3,"file":"icc-maintenance-task-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-maintenance-task-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gFAA4E;AAE5E,kDAAiD;AACjD,4BAA2B;AAE3B,oDAAmF;AAEnF,0EAAgG;AAChG,wEAAoE;AACpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AACzD,4EAAwE;AAKxE,mCAAmJ;AAInJ,4DAAwE;AAGxE,MAAa,sBAAuB,SAAQ,6CAAqB;IAG/D,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAC9B,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,eAAe,CAAC,CAClH,CAAA;IACH,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,UAA0B,EAC1B,YAA8B,EAC9B,OAAoB,EACpB,OAAmB,EACnB,cAAuB,EACxC,gBAA+B,EAAE,EACjC,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAdtC,WAAM,GAAN,MAAM,CAAe;QACrB,eAAU,GAAV,UAAU,CAAgB;QAC1B,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,YAAO,GAAP,OAAO,CAAa;QACpB,YAAO,GAAP,OAAO,CAAY;QACnB,mBAAc,GAAd,cAAc,CAAS;QAUxC,IAAI,CAAC,e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C,CAAA;IACzI,CAAC;IAED,mBAAmB,CAAC,MAA8B;QAChD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,eAAe,EAAE,EAAE,SAAS,CAAC,CAAA;IACrH,CAAC;IAEK,gCAAgC,CACpC,UAA8C,EAC9C,MAAuC,EACvC,UAA0D,EAC1D,UAA+B,EAAE;;YAEjC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAA;YAEvD,OAAO,IAAA,+BAAuB,EAC5B,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,OAAO,EACZ,oCAA4B,CAAC,eAAe,EAC5C,UAAU,EACV,MAAM,EACN,UAAU,EACV,OAAO,EACP,CAAO,SAAS,EAAE,EAAE,gDAAC,OAAA,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,GAAA,CACvE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;KAAA;IAED,uCAAuC,CAAC,MAAuB,EAAE,SAAmB;QAClF,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAC7E,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,eAAe,EAAE,EAC9D,SAAS,CACV,CAAA;IACH,CAAC;CACF;AAnUD,wDAmUC","sourcesContent":["import { IccMaintenanceTaskApi } from '../icc-api/api/IccMaintenanceTaskApi'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport * as models from '../icc-api/model/models'\nimport * as _ from 'lodash'\nimport { IccHcpartyXApi } from './icc-hcparty-x-api'\nimport { DocIdentifier, ListOfIds, MaintenanceTask } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { IccAuthApi } from '../icc-api'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { AbstractFilter } from './filters/filters'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { IccUserXApi } from './icc-user-x-api'\n\nexport class IccMaintenanceTaskXApi extends IccMaintenanceTaskApi implements EncryptedEntityXApi<models.MaintenanceTask> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) =>\n this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.MaintenanceTask)\n )\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly hcPartyApi: IccHcpartyXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly userApi: IccUserXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n encryptedKeys: Array<string> = [],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'MaintenanceTask.')\n }\n\n /**\n * Creates a new instance of maintenance task with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param m initialised data for the maintenance task. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of maintenance task.\n */\n async newInstance(\n user: models.User,\n m: any,\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n alternateRootDelegation?: string\n } = {}\n ) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n const maintenanceTask = {\n ...(m ?? {}),\n _type: 'org.taktik.icure.entities.MaintenanceTask',\n id: m?.id ?? this.crypto.primitives.randomUuid(),\n created: m?.created ?? new Date().getTime(),\n modified: m?.modified ?? new Date().getTime(),\n responsible: m?.responsible ?? (this.autofillAuthor ? dataOwnerId : undefined),\n author: m?.author ?? (this.autofillAuthor ? user.id : undefined),\n }\n\n const extraDelegations = {\n ...Object.fromEntries((user.autoDelegations?.all ?? []).map((d) => [d, AccessLevelEnum.WRITE])),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.MaintenanceTask(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n maintenanceTask,\n EntityWithDelegationTypeName.MaintenanceTask,\n undefined,\n undefined,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n createMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n createMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((tasks) => super.createMaintenanceTask(tasks[0]))\n .then((mt) => this.decrypt(user, [mt]))\n .then((tasks) => tasks[0])\n : Promise.resolve(null)\n }\n\n filterMaintenanceTasksBy(startDocumentId?: string, limit?: number, body?: models.FilterChainMaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTask(_maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<DocIdentifier> | never {\n return super.deleteMaintenanceTask(maintenanceTaskId)\n }\n\n deleteMaintenanceTasks(_maintenanceTaskIds: ListOfIds): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n deleteMaintenanceTasksWithUser(user: models.User, maintenanceTaskIds: ListOfIds): Promise<Array<DocIdentifier>> | never {\n return super.deleteMaintenanceTasks(maintenanceTaskIds)\n }\n\n filterMaintenanceTasksByWithUser(\n user: models.User,\n startDocumentId?: string,\n limit?: number,\n body?: models.FilterChainMaintenanceTask\n ): Promise<models.PaginatedListMaintenanceTask> {\n return super\n .filterMaintenanceTasksBy(startDocumentId, limit, body)\n .then((pl) => this.decrypt(user, pl.rows!).then((dr) => Object.assign(pl, { rows: dr })))\n }\n\n getMaintenanceTask(maintenanceTaskId: string): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n getMaintenanceTaskWithUser(user: models.User, maintenanceTaskId: string): Promise<models.MaintenanceTask | any> {\n return super\n .getMaintenanceTask(maintenanceTaskId)\n .then((mt) => this.decrypt(user, [mt]))\n .then((mts) => mts[0])\n }\n\n modifyMaintenanceTask(body?: models.MaintenanceTask): never {\n throw new Error('Cannot call a method that returns maintenance tasks without providing a user for de/encryption')\n }\n\n modifyMaintenanceTaskWithUser(user: models.User, body?: models.MaintenanceTask): Promise<models.MaintenanceTask | any> {\n return body ? this.modifyMaintenanceTaskAs(this.dataOwnerApi.getDataOwnerIdOf(user), body) : Promise.resolve(null)\n }\n\n private modifyMaintenanceTaskAs(dataOwner: string, body: models.MaintenanceTask): Promise<models.MaintenanceTask> {\n return this.encryptAs(dataOwner, [_.cloneDeep(body)])\n .then((encTasks) => super.modifyMaintenanceTask(encTasks[0]))\n .then((mt) => this.decryptAs(dataOwner, [mt]))\n .then((mts) => mts[0])\n }\n\n encrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n return this.encryptAs(dataOwnerId, maintenanceTasks)\n }\n\n private encryptAs(dataOwner: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return this.crypto.xapi.tryEncryptEntities(\n maintenanceTasks,\n EntityWithDelegationTypeName.MaintenanceTask,\n this.encryptedFields,\n true,\n false,\n (x) => new models.MaintenanceTask(x)\n )\n }\n\n decrypt(user: models.User, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerIdOf(user)\n return this.decryptAs(dataOwnerId, maintenanceTasks)\n }\n\n private async decryptAs(dataOwner: string, maintenanceTasks: Array<models.MaintenanceTask>): Promise<Array<models.MaintenanceTask>> {\n return (\n await this.crypto.xapi.tryDecryptEntities(maintenanceTasks, EntityWithDelegationTypeName.MaintenanceTask, (x) => new MaintenanceTask(x))\n ).map(({ entity }) => entity)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given maintenance task\n */\n async hasWriteAccess(maintenanceTask: models.MaintenanceTask): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: maintenanceTask, type: EntityWithDelegationTypeName.MaintenanceTask })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the maintenance task.\n * @param maintenanceTask the maintenance task to share.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n maintenanceTask: models.MaintenanceTask,\n options: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.MaintenanceTask> {\n return this.shareWithMany(maintenanceTask, { [delegateId]: options })\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity.\n */\n async shareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.MaintenanceTask> {\n return (await this.tryShareWithMany(maintenanceTask, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing maintenance task with other data owners, allowing them to access the non-encrypted data of the maintenance task and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param maintenanceTask the maintenance task to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * maintenance task does not have encrypted content.\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\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 tryShareWithMany(\n maintenanceTask: models.MaintenanceTask,\n delegates: {\n [delegateId: string]: {\n shareSecretIds?: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.MaintenanceTask>> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(\n maintenanceTask,\n EntityWithDelegationTypeName.MaintenanceTask\n )\n const updatedEntity = entityWithEncryptionKey ? await this.modifyMaintenanceTaskAs(self, entityWithEncryptionKey) : maintenanceTask\n return this.crypto.xapi\n .simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.MaintenanceTask,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: ShareMetadataBehaviour.NEVER,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareMaintenanceTask(x)\n )\n .then((r) => r.mapSuccessAsync((e) => this.decryptAs(self, [e]).then((es) => es[0])))\n }\n\n getDataOwnersWithAccessTo(\n entity: models.MaintenanceTask\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.MaintenanceTask })\n }\n\n getEncryptionKeysOf(entity: models.MaintenanceTask): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.MaintenanceTask }, undefined)\n }\n\n async subscribeToMaintenanceTaskEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<MaintenanceTask>,\n eventFired: (dataSample: MaintenanceTask) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n const currentUser = await this.userApi.getCurrentUser()\n\n return subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.MaintenanceTask,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt(currentUser, [encrypted]))[0]\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: MaintenanceTask, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo(\n { entity, type: EntityWithDelegationTypeName.MaintenanceTask },\n delegates\n )\n }\n}\n"]}
@@ -40,6 +40,8 @@ export declare class IccMessageXApi extends IccMessageApi implements EncryptedEn
40
40
  * auto-delegations, in such case the access level specified here will be used.
41
41
  * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the message. The default value will be a
42
42
  * secret id of patient known by the topmost parent in the current data owner hierarchy.
43
+ * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,
44
+ * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.
43
45
  * @return a new instance of message.
44
46
  */
45
47
  newInstanceWithPatient(user: User, patient: Patient | null, m?: any, options?: {
@@ -47,6 +49,7 @@ export declare class IccMessageXApi extends IccMessageApi implements EncryptedEn
47
49
  [dataOwnerId: string]: AccessLevelEnum;
48
50
  };
49
51
  sfkOption?: SecretIdUseOption;
52
+ alternateRootDelegation?: string;
50
53
  }): Promise<models.Message>;
51
54
  decrypt(messages: Array<models.Message>): Promise<{
52
55
  entity: models.Message;
@@ -50,6 +50,8 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
50
50
  * auto-delegations, in such case the access level specified here will be used.
51
51
  * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the message. The default value will be a
52
52
  * secret id of patient known by the topmost parent in the current data owner hierarchy.
53
+ * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,
54
+ * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.
53
55
  * @return a new instance of message.
54
56
  */
55
57
  newInstanceWithPatient(user, patient, m = {}, options = {}) {
@@ -66,7 +68,7 @@ class IccMessageXApi extends icc_api_1.IccMessageApi {
66
68
  throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`);
67
69
  const extraDelegations = Object.assign(Object.assign({}, Object.fromEntries([...((_k = (_j = user.autoDelegations) === null || _j === void 0 ? void 0 : _j.all) !== null && _k !== void 0 ? _k : []), ...((_m = (_l = user.autoDelegations) === null || _l === void 0 ? void 0 : _l.medicalInformation) !== null && _m !== void 0 ? _m : [])].map((d) => [d, AccessLevelEnum.WRITE]))), ((_o = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _o !== void 0 ? _o : {}));
68
70
  return new models.Message(yield this.crypto.xapi
69
- .entityWithInitialisedEncryptedMetadata(message, utils_1.EntityWithDelegationTypeName.Message, patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, extraDelegations)
71
+ .entityWithInitialisedEncryptedMetadata(message, utils_1.EntityWithDelegationTypeName.Message, patient === null || patient === void 0 ? void 0 : patient.id, sfk, true, extraDelegations, options.alternateRootDelegation)
70
72
  .then((x) => x.updatedEntity));
71
73
  });
72
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"icc-message-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-message-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAsD;AAGtD,kDAAiD;AAGjD,0EAAgG;AAChG,wEAAoE;AAOpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAGzD,mCAAmJ;AACnJ,4DAAwE;AACxE,kEAA8D;AAE9D,MAAa,cAAe,SAAQ,uBAAa;IAG/C,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,OAAO,CAAC,CAAC,CAAA;IAC7I,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,YAA8B,EAC9B,OAAmB,EACnB,cAAuB,EACxC,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,gBAA+B,EAAE,EACjC,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAZtC,WAAM,GAAN,MAAM,CAAe;QACrB,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,YAAO,GAAP,OAAO,CAAY;QACnB,mBAAc,GAAd,cAAc,CAAS;QAUxC,IAAI,CAAC,eAAe,GAAG,IAAA,4BAAoB,EAAC,aAAa,EAAE,UAAU,CA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AuC,CAAC,MAAe,EAAE,SAAmB;QAC1E,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;IACpJ,CAAC;CACF;AAtSD,wCAsSC","sourcesContent":["import { IccAuthApi, IccMessageApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\nimport { Message, MessagesReadStatusUpdate, PaginatedListMessage, Patient, User } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { FilterChainMessage } from '../icc-api/model/FilterChainMessage'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { AbstractFilter } from './filters/filters'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { SecretIdUseOption } from './crypto/SecretIdUseOption'\n\nexport class IccMessageXApi extends IccMessageApi implements EncryptedEntityXApi<models.Message> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Message))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n encryptedKeys: Array<string> = [],\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'Message.')\n }\n\n // noinspection JSUnusedGlobalSymbols\n newInstance(user: User, m: any) {\n return this.newInstanceWithPatient(user, null, m)\n }\n\n /**\n * Creates a new instance of message with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this message refers to.\n * @param m initialised data for the message. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the message. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * @return a new instance of message.\n */\n async newInstanceWithPatient(\n user: User,\n patient: Patient | null,\n m: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n sfkOption?: SecretIdUseOption\n } = {}\n ) {\n const message = {\n ...(m ?? {}),\n _type: 'org.taktik.icure.entities.Message',\n id: m?.id ?? this.crypto.primitives.randomUuid(),\n created: m?.created ?? new Date().getTime(),\n modified: m?.modified ?? new Date().getTime(),\n responsible: m?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: m?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: m?.codes ?? [],\n tags: m?.tags ?? [],\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\n ? await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n options.sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n : undefined\n if (patient && !sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = {\n ...Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n ),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Message(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(message, EntityWithDelegationTypeName.Message, patient?.id, sfk, true, extraDelegations)\n .then((x) => x.updatedEntity)\n )\n }\n\n async decrypt(messages: Array<models.Message>) {\n return await this.crypto.xapi.tryDecryptEntities(messages, EntityWithDelegationTypeName.Message, (x) => new models.Message(x))\n }\n\n encrypt(messages: Array<models.Message>): Promise<Array<models.Message>> {\n return this.crypto.xapi.tryEncryptEntities(\n messages,\n EntityWithDelegationTypeName.Message,\n this.encryptedFields,\n true,\n false,\n (x) => new models.Message(x)\n )\n }\n\n /**\n * @param message a message\n * @return the id of the patient that the message refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(message: models.Message): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: message, type: EntityWithDelegationTypeName.Message }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given message\n */\n async hasWriteAccess(message: models.Message): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: message, type: EntityWithDelegationTypeName.Message })\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the message.\n * @param message the message to share.\n * @param shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n message: models.Message,\n shareSecretIds: string[],\n options: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Message> {\n return this.shareWithMany(message, { [delegateId]: { ...options, shareSecretIds } })\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param message the message to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id. Mandatory.\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n message: models.Message,\n delegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Message> {\n return (await this.tryShareWithMany(message, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param message the message to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id. Mandatory.\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\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 tryShareWithMany(\n message: models.Message,\n delegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Message>> {\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(message, EntityWithDelegationTypeName.Message)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyMessage(entityWithEncryptionKey) : message\n return this.crypto.xapi.simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Message,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareMessages(x)\n )\n }\n\n /**\n * @param message a message\n * @return the secret ids of the message, retrieved from the encrypted metadata. The result may be used to find entities where the message is\n * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.\n */\n decryptSecretIdsOf(message: models.Message): Promise<string[]> {\n return this.crypto.xapi.secretIdsOf({ entity: message, type: EntityWithDelegationTypeName.Message }, undefined)\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Message\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Message })\n }\n\n getEncryptionKeysOf(entity: models.Message): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Message }, undefined)\n }\n\n override async filterMessagesBy(body: FilterChainMessage, startDocumentId?: string, limit?: number): Promise<PaginatedListMessage> {\n const page = await super.filterMessagesBy(body, startDocumentId, limit)\n const decryptedMessages = await this.decrypt(page.rows ?? [])\n if (decryptedMessages.some((m) => !m.decrypted)) throw new Error('Some messages could not be decrypted')\n return {\n ...page,\n rows: decryptedMessages.map((m) => m.entity),\n }\n }\n\n async encryptAndCreateMessageInTopic(body: Message): Promise<Message> {\n const encryptedMessage = await this.encrypt([body])\n const createdMessage = await super.createMessageInTopic(encryptedMessage[0])\n return (await this.decrypt([createdMessage]))[0].entity\n }\n\n async setMessagesReadStatus(body?: MessagesReadStatusUpdate): Promise<Array<Message>> {\n return (await this.decrypt(await super.setMessagesReadStatus(body))).map((m) => m.entity)\n }\n\n async getAndDecryptMessage(messageId: string): Promise<Message> {\n const encryptedMessage = await super.getMessage(messageId)\n const decryptedMessage = await this.decrypt([encryptedMessage])\n if (!decryptedMessage[0].decrypted) throw new Error('Message could not be decrypted')\n return decryptedMessage[0].entity\n }\n\n async subscribeToMessageEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<Message> | undefined,\n eventFired: (message: Message) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return await subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.Message,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt([encrypted]))[0].entity\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: Message, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Message }, delegates)\n }\n}\n"]}
1
+ {"version":3,"file":"icc-message-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-message-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAsD;AAGtD,kDAAiD;AAGjD,0EAAgG;AAChG,wEAAoE;AAOpE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAGzD,mCAAmJ;AACnJ,4DAAwE;AACxE,kEAA8D;AAE9D,MAAa,cAAe,SAAQ,uBAAa;IAG/C,IAAI,OAAO;QACT,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,EAAE,oCAA4B,CAAC,OAAO,CAAC,CAAC,CAAA;IAC7I,CAAC;IAED,YACE,IAAY,EACZ,OAAkC,EACjB,MAAqB,EACrB,YAA8B,EAC9B,OAAmB,EACn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,MAAM,CAAA;QACnC,CAAC;KAAA;IAEK,wBAAwB,CAC5B,UAA8C,EAC9C,MAA2C,EAC3C,UAA+C,EAC/C,UAA+B,EAAE;;YAEjC,OAAO,MAAM,IAAA,+BAAuB,EAClC,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,OAAO,EACZ,oCAA4B,CAAC,OAAO,EACpC,UAAU,EACV,MAAM,EACN,UAAU,EACV,OAAO,EACP,CAAO,SAAS,EAAE,EAAE,gDAAC,OAAA,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA,GAAA,CACjE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;KAAA;IAED,uCAAuC,CAAC,MAAe,EAAE,SAAmB;QAC1E,OAAO,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,iCAAiC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,oCAA4B,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAA;IACpJ,CAAC;CACF;AAjTD,wCAiTC","sourcesContent":["import { IccAuthApi, IccMessageApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\nimport { Message, MessagesReadStatusUpdate, PaginatedListMessage, Patient, User } from '../icc-api/model/models'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { SecureDelegation } from '../icc-api/model/SecureDelegation'\nimport { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'\nimport { ShareResult } from './utils/ShareResult'\nimport { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'\nimport { XHR } from '../icc-api/api/XHR'\nimport { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'\nimport { FilterChainMessage } from '../icc-api/model/FilterChainMessage'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { AbstractFilter } from './filters/filters'\nimport { EncryptedFieldsManifest, EntityWithDelegationTypeName, parseEncryptedFields, subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { SecretIdUseOption } from './crypto/SecretIdUseOption'\n\nexport class IccMessageXApi extends IccMessageApi implements EncryptedEntityXApi<models.Message> {\n private readonly encryptedFields: EncryptedFieldsManifest\n\n get headers(): Promise<Array<XHR.Header>> {\n return super.headers.then((h) => this.crypto.accessControlKeysHeaders.addAccessControlKeysHeaders(h, EntityWithDelegationTypeName.Message))\n }\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n private readonly crypto: IccCryptoXApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly authApi: IccAuthApi,\n private readonly autofillAuthor: boolean,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n encryptedKeys: Array<string> = [],\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.encryptedFields = parseEncryptedFields(encryptedKeys, 'Message.')\n }\n\n // noinspection JSUnusedGlobalSymbols\n newInstance(user: User, m: any) {\n return this.newInstanceWithPatient(user, null, m)\n }\n\n /**\n * Creates a new instance of message with initialised encryption metadata (not in the database).\n * @param user the current user.\n * @param patient the patient this message refers to.\n * @param m initialised data for the message. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify\n * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata.\n * @param options optional parameters:\n * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the\n * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with\n * auto-delegations, in such case the access level specified here will be used.\n * - preferredSfk: secret id of the patient to use as the secret foreign key to use for the message. The default value will be a\n * secret id of patient known by the topmost parent in the current data owner hierarchy.\n * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @return a new instance of message.\n */\n async newInstanceWithPatient(\n user: User,\n patient: Patient | null,\n m: any = {},\n options: {\n additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum }\n sfkOption?: SecretIdUseOption\n alternateRootDelegation?: string\n } = {}\n ) {\n const message = {\n ...(m ?? {}),\n _type: 'org.taktik.icure.entities.Message',\n id: m?.id ?? this.crypto.primitives.randomUuid(),\n created: m?.created ?? new Date().getTime(),\n modified: m?.modified ?? new Date().getTime(),\n responsible: m?.responsible ?? (this.autofillAuthor ? this.dataOwnerApi.getDataOwnerIdOf(user) : undefined),\n author: m?.author ?? (this.autofillAuthor ? user.id : undefined),\n codes: m?.codes ?? [],\n tags: m?.tags ?? [],\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\n ? await this.crypto.xapi.resolveSecretIdUseOptions(\n { entity: patient, type: EntityWithDelegationTypeName.Patient },\n options.sfkOption ?? SecretIdUseOption.UseAnySharedWithParent\n )\n : undefined\n if (patient && !sfk) throw new Error(`Couldn't find any sfk of parent patient ${patient.id}`)\n const extraDelegations = {\n ...Object.fromEntries(\n [...(user.autoDelegations?.all ?? []), ...(user.autoDelegations?.medicalInformation ?? [])].map((d) => [d, AccessLevelEnum.WRITE])\n ),\n ...(options?.additionalDelegates ?? {}),\n }\n return new models.Message(\n await this.crypto.xapi\n .entityWithInitialisedEncryptedMetadata(\n message,\n EntityWithDelegationTypeName.Message,\n patient?.id,\n sfk,\n true,\n extraDelegations,\n options.alternateRootDelegation\n )\n .then((x) => x.updatedEntity)\n )\n }\n\n async decrypt(messages: Array<models.Message>) {\n return await this.crypto.xapi.tryDecryptEntities(messages, EntityWithDelegationTypeName.Message, (x) => new models.Message(x))\n }\n\n encrypt(messages: Array<models.Message>): Promise<Array<models.Message>> {\n return this.crypto.xapi.tryEncryptEntities(\n messages,\n EntityWithDelegationTypeName.Message,\n this.encryptedFields,\n true,\n false,\n (x) => new models.Message(x)\n )\n }\n\n /**\n * @param message a message\n * @return the id of the patient that the message refers to, retrieved from the encrypted metadata. Normally there should only be one element\n * in the returned array, but in case of entity merges there could be multiple values.\n */\n async decryptPatientIdOf(message: models.Message): Promise<string[]> {\n return this.crypto.xapi.owningEntityIdsOf({ entity: message, type: EntityWithDelegationTypeName.Message }, undefined)\n }\n\n /**\n * @return if the logged data owner has write access to the content of the given message\n */\n async hasWriteAccess(message: models.Message): Promise<boolean> {\n return this.crypto.xapi.hasWriteAccess({ entity: message, type: EntityWithDelegationTypeName.Message })\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param delegateId the id of the data owner which will be granted access to the message.\n * @param message the message to share.\n * @param shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id.\n * @param options optional parameters to customize the sharing behaviour:\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWith(\n delegateId: string,\n message: models.Message,\n shareSecretIds: string[],\n options: {\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n } = {}\n ): Promise<models.Message> {\n return this.shareWithMany(message, { [delegateId]: { ...options, shareSecretIds } })\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param message the message to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id. Mandatory.\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @return the updated entity\n */\n async shareWithMany(\n message: models.Message,\n delegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<models.Message> {\n return (await this.tryShareWithMany(message, delegates)).updatedEntityOrThrow\n }\n\n /**\n * Share an existing message with other data owners, allowing them to access the non-encrypted data of the message and optionally also\n * the encrypted content, with read-only or read-write permissions.\n * @param message the message to share.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareSecretIds the secret ids of the Message that the delegate will be given access to. Allows the delegate to search for data where the\n * shared Message is the owning entity id. Mandatory.\n * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted\n * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a\n * message does not have encrypted content.\n * - sharePatientId: specifies if the id of the patient that this message refers to should be shared with the delegate (defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}).\n * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\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 tryShareWithMany(\n message: models.Message,\n delegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n requestedPermissions?: RequestedPermissionEnum\n shareEncryptionKey?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n sharePatientId?: ShareMetadataBehaviour // Defaults to ShareMetadataBehaviour.IF_AVAILABLE\n }\n }\n ): Promise<ShareResult<models.Message>> {\n // All entities should have an encryption key.\n const entityWithEncryptionKey = await this.crypto.xapi.ensureEncryptionKeysInitialised(message, EntityWithDelegationTypeName.Message)\n const updatedEntity = entityWithEncryptionKey ? await this.modifyMessage(entityWithEncryptionKey) : message\n return this.crypto.xapi.simpleShareOrUpdateEncryptedEntityMetadata(\n {\n entity: updatedEntity,\n type: EntityWithDelegationTypeName.Message,\n },\n Object.fromEntries(\n Object.entries(delegates).map(([delegateId, options]) => [\n delegateId,\n {\n requestedPermissions: options.requestedPermissions,\n shareEncryptionKeys: options.shareEncryptionKey,\n shareOwningEntityIds: options.sharePatientId,\n shareSecretIds: options.shareSecretIds,\n },\n ])\n ),\n (x) => this.bulkShareMessages(x)\n )\n }\n\n /**\n * @param message a message\n * @return the secret ids of the message, retrieved from the encrypted metadata. The result may be used to find entities where the message is\n * the 'owning entity', or in the {@link shareWith} method in order to share it with other data owners.\n */\n decryptSecretIdsOf(message: models.Message): Promise<string[]> {\n return this.crypto.xapi.secretIdsOf({ entity: message, type: EntityWithDelegationTypeName.Message }, undefined)\n }\n\n getDataOwnersWithAccessTo(\n entity: models.Message\n ): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum }; hasUnknownAnonymousDataOwners: boolean }> {\n return this.crypto.delegationsDeAnonymization.getDataOwnersWithAccessTo({ entity, type: EntityWithDelegationTypeName.Message })\n }\n\n getEncryptionKeysOf(entity: models.Message): Promise<string[]> {\n return this.crypto.xapi.encryptionKeysOf({ entity, type: EntityWithDelegationTypeName.Message }, undefined)\n }\n\n override async filterMessagesBy(body: FilterChainMessage, startDocumentId?: string, limit?: number): Promise<PaginatedListMessage> {\n const page = await super.filterMessagesBy(body, startDocumentId, limit)\n const decryptedMessages = await this.decrypt(page.rows ?? [])\n if (decryptedMessages.some((m) => !m.decrypted)) throw new Error('Some messages could not be decrypted')\n return {\n ...page,\n rows: decryptedMessages.map((m) => m.entity),\n }\n }\n\n async encryptAndCreateMessageInTopic(body: Message): Promise<Message> {\n const encryptedMessage = await this.encrypt([body])\n const createdMessage = await super.createMessageInTopic(encryptedMessage[0])\n return (await this.decrypt([createdMessage]))[0].entity\n }\n\n async setMessagesReadStatus(body?: MessagesReadStatusUpdate): Promise<Array<Message>> {\n return (await this.decrypt(await super.setMessagesReadStatus(body))).map((m) => m.entity)\n }\n\n async getAndDecryptMessage(messageId: string): Promise<Message> {\n const encryptedMessage = await super.getMessage(messageId)\n const decryptedMessage = await this.decrypt([encryptedMessage])\n if (!decryptedMessage[0].decrypted) throw new Error('Message could not be decrypted')\n return decryptedMessage[0].entity\n }\n\n async subscribeToMessageEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<Message> | undefined,\n eventFired: (message: Message) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return await subscribeToEntityEvents(\n this.host,\n this.authApi,\n EntityWithDelegationTypeName.Message,\n eventTypes,\n filter,\n eventFired,\n options,\n async (encrypted) => (await this.decrypt([encrypted]))[0].entity\n ).then((rs) => new ConnectionImpl(rs))\n }\n\n createDelegationDeAnonymizationMetadata(entity: Message, delegates: string[]): Promise<void> {\n return this.crypto.delegationsDeAnonymization.createOrUpdateDeAnonymizationInfo({ entity, type: EntityWithDelegationTypeName.Message }, delegates)\n }\n}\n"]}
@@ -53,12 +53,15 @@ export declare class IccPatientXApi extends IccPatientApi implements EncryptedEn
53
53
  * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
54
54
  * 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
55
55
  * auto-delegations, in such case the access level specified here will be used.
56
+ * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,
57
+ * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.
56
58
  * @return a new instance of patient.
57
59
  */
58
60
  newInstance(user: models.User, p?: any, options?: {
59
61
  additionalDelegates?: {
60
62
  [dataOwnerId: string]: AccessLevelEnum;
61
63
  };
64
+ alternateRootDelegation?: string;
62
65
  }): Promise<models.Patient>;
63
66
  completeNames(patient: models.Patient): models.Patient;
64
67
  /**
@@ -60,6 +60,8 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
60
60
  * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the
61
61
  * 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
62
62
  * auto-delegations, in such case the access level specified here will be used.
63
+ * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,
64
+ * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.
63
65
  * @return a new instance of patient.
64
66
  */
65
67
  newInstance(user, p = {}, options = {}) {
@@ -70,7 +72,7 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
70
72
  if (ownerId !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
71
73
  throw new Error('Can only initialise entities as current data owner.');
72
74
  const extraDelegations = Object.assign(Object.assign({}, Object.fromEntries([...((_j = (_h = user.autoDelegations) === null || _h === void 0 ? void 0 : _h.all) !== null && _j !== void 0 ? _j : []), ...((_l = (_k = user.autoDelegations) === null || _k === void 0 ? void 0 : _k.medicalInformation) !== null && _l !== void 0 ? _l : [])].map((d) => [d, AccessLevelEnum.WRITE]))), ((_m = options === null || options === void 0 ? void 0 : options.additionalDelegates) !== null && _m !== void 0 ? _m : {}));
73
- const initialisationInfo = yield this.crypto.xapi.entityWithInitialisedEncryptedMetadata(patient, EntityWithDelegationTypeName_1.EntityWithDelegationTypeName.Patient, undefined, undefined, true, extraDelegations);
75
+ const initialisationInfo = yield this.crypto.xapi.entityWithInitialisedEncryptedMetadata(patient, EntityWithDelegationTypeName_1.EntityWithDelegationTypeName.Patient, undefined, undefined, true, extraDelegations, options.alternateRootDelegation);
74
76
  return new models.Patient(initialisationInfo.updatedEntity);
75
77
  });
76
78
  }
@@ -881,7 +883,9 @@ class IccPatientXApi extends icc_api_1.IccPatientApi {
881
883
  const patient = yield _super.getPatient.call(this, patientId);
882
884
  if (this.dataOwnerApi.getHexPublicKeysOf(patient).size)
883
885
  return false;
884
- yield this.crypto.exchangeData.getOrCreateEncryptionDataTo(patientId, true);
886
+ yield this.crypto.exchangeData.getOrCreateEncryptionDataTo(patientId, {
887
+ allowCreationWithoutDelegateKey: true,
888
+ });
885
889
  return true;
886
890
  });
887
891
  }