import { IccAuthApi, IccDocumentApi } from '../icc-api'; import { IccCryptoXApi } from './icc-crypto-x-api'; import { XHR } from '../icc-api/api/XHR'; import * as models from '../icc-api/model/models'; import { IccDataOwnerXApi } from './icc-data-owner-x-api'; import { AuthenticationProvider } from './auth/AuthenticationProvider'; import { SecureDelegation } from '../icc-api/model/SecureDelegation'; import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'; import { ShareResult } from './utils/ShareResult'; import { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'; import { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'; import AccessLevelEnum = SecureDelegation.AccessLevelEnum; import RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum; import { SecretIdUseOption } from './crypto/SecretIdUseOption'; import { ListOfIds, PaginatedListDocument } from '../icc-api/model/models'; export declare class IccDocumentXApi extends IccDocumentApi implements EncryptedEntityXApi { private crypto; private authApi; private readonly autofillAuthor; fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise; /** maps invalid UTI values to corresponding MIME type for backward-compatibility (pre-v1.0.117) */ compatUtiRevDefs: { [key: string]: string; }; utiRevDefs: { [key: string]: string; }; utiExts: { [key: string]: string; }; utiDefs: { [key: string]: string; }; dataOwnerApi: IccDataOwnerXApi; authenticationProvider: AuthenticationProvider; private readonly encryptedFields; constructor(host: string, headers: { [key: string]: string; }, crypto: IccCryptoXApi, authApi: IccAuthApi, dataOwnerApi: IccDataOwnerXApi, autofillAuthor: boolean, authenticationProvider?: AuthenticationProvider, encryptedKeys?: Array, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise); get headers(): Promise>; /** * Creates a new instance of document with initialised encryption metadata (not in the database). * @param user the current user. * @param message the message this document refers to. * @param c initialised data for the document. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata. * @param options optional parameters: * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the * 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 * auto-delegations, in such case the access level specified here will be used. * - sfkOption: specifies which sfk of the owning entity to use. * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible, * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation. * @return a new instance of document. */ newInstance(user: models.User, message?: models.Message, c?: any, options?: { additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum; }; sfkOption?: SecretIdUseOption; ignoreAutoDelegations?: boolean; alternateRootDelegation?: string; }): Promise; /** * Same as {@link findByMessage} but it will only return the ids of the documents. It can also filter the documents where Document.created is between * startDate and endDate in ascending or descending order by that field. (default: ascending). */ findIdsByMessage(hcpartyId: string, message: models.Message, startDate?: number, endDate?: number, descending?: boolean): Promise; /** * Decrypts an array of documents. * @param documents the documents to decrypt. * @return an array of objects containing the document and a flag indicating if it was successfully decrypted. */ decrypt(documents: Array): Promise<{ entity: models.Document; decrypted: boolean; }[]>; /** * Encrypts an array of documents. * @param documents the documents to encrypt. * @return the encrypted documents. */ encrypt(documents: Array): Promise>; getAttachmentAs(documentId: string, attachmentId: string, returnType: "application/octet-stream", enckeys?: string, fileName?: string): Promise; getAttachmentAs(documentId: string, attachmentId: string, returnType: "text/plain", enckeys?: string, fileName?: string): Promise; getAttachmentAs(documentId: string, attachmentId: string, returnType: "application/json", enckeys?: string, fileName?: string): Promise; getMainAttachmentAs(documentId: string, returnType: "application/octet-stream"): Promise; getMainAttachmentAs(documentId: string, returnType: "text/plain"): Promise; getMainAttachmentAs(documentId: string, returnType: "application/json", tryHardToParseJson?: boolean): Promise; getMainAttachmentAs(documentId: string, returnType: 'application/octet-stream' | 'text/plain' | 'application/json', tryHardToParseJson?: boolean): Promise; getAndTryDecryptMainAttachmentAs(document: models.Document, returnType: "application/octet-stream"): Promise; getAndTryDecryptMainAttachmentAs(document: models.Document, returnType: "text/plain"): Promise; getAndTryDecryptMainAttachmentAs(document: models.Document, returnType: "application/json"): Promise; getAndTryDecryptMainAttachmentAs(document: models.Document, returnType: 'application/octet-stream' | 'text/plain' | 'application/json'): Promise; private parserFor; /** * Converts a MIME type and file extension to a UTI (Uniform Type Identifier). * @param mimeType the MIME type. * @param extension the file extension. * @return the corresponding UTI. */ uti(mimeType: string, extension: string): string; /** * Converts a UTI (Uniform Type Identifier) to a MIME type. * @param uti the UTI. * @return the corresponding MIME type. */ mimeType(uti: string): string; /** * Adds an attachment to a document, encrypting it on client side using the encryption keys of the provided document. * @param document a document. * @param attachment a new main attachment for the document. * @param utis an array of UTIs for the attachment. The first element will be considered as the main UTI for the document. If provided and non-empty * overrides existing values. * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated document. */ encryptAndSetDocumentAttachment(document: models.Document, attachment: ArrayBuffer | Uint8Array, utis?: string[], deflate?: boolean): Promise; /** * Adds an unencrypted attachment to a document. * @param document a document. * @param attachment a new main attachment for the document. * @param utis an array of UTIs for the attachment. The first element will be considered as the main UTI for the document. If provided and non-empty * overrides existing values. * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated document. */ setClearDocumentAttachment(document: models.Document, attachment: ArrayBuffer | Uint8Array, utis?: string[], deflate?: boolean): Promise; /** * Adds a secondary attachment to a document, encrypting it on client side using the encryption keys of the provided document. * @param document a document. * @param secondaryAttachmentKey key for the secondary attachment. * @param attachment a new secondary attachment for the document. * @param utis an array of UTIs for the attachment. The first element will be considered as the main UTI for the document. If provided and non-empty * overrides existing values. * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated document. */ encryptAndSetSecondaryDocumentAttachment(document: models.Document, secondaryAttachmentKey: string, attachment: ArrayBuffer | Uint8Array, utis?: string[], deflate?: boolean): Promise; /** * Adds an unencrypted secondary attachment to a document. * @param document a document. * @param secondaryAttachmentKey key for the secondary attachment. * @param attachment a new secondary attachment for the document. * @param utis an array of UTIs for the attachment. The first element will be considered as the main UTI for the document. If provided and non-empty * overrides existing values. * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated document. */ setClearSecondaryDocumentAttachment(document: models.Document, secondaryAttachmentKey: string, attachment: ArrayBuffer | Uint8Array, utis?: string[], deflate?: boolean): Promise; /** * Gets the main attachment of a document and tries to decrypt it using the encryption keys of the document, throwing an error if the operation fails. * @param document a document. * @param validator optionally a validator function which checks if the decryption was successful. In cases where the document has many encryption * keys and it is unclear which one should be used this function can help to detect bad decryptions. * @return the decrypted attachment, if it could be decrypted, else the encrypted attachment. */ getAndDecryptDocumentAttachment(document: models.Document, validator?: (decrypted: ArrayBuffer) => Promise): Promise; /** * Gets the main attachment of a document and tries to decrypt it using the encryption keys of the document. * @param document a document. * @param validator optionally a validator function which checks if the decryption was successful. In cases where the document has many encryption * keys and it is unclear which one should be used this function can help to detect bad decryptions. * @return an object containing: * - data: the decrypted attachment, if it could be decrypted, else the encrypted attachment. * - wasDecrypted: if the data was successfully decrypted or not */ getAndTryDecryptDocumentAttachment(document: models.Document, validator?: (decrypted: ArrayBuffer) => Promise): Promise<{ data: ArrayBuffer; wasDecrypted: boolean; }>; /** * Gets the secondary attachment of a document and tries to decrypt it using the encryption keys of the document, throwing an error if the operation fails. * @param document a document. * @param secondaryAttachmentKey key of the secondary attachment. * @param validator optionally a validator function which checks if the decryption was successful. In cases where the document has many encryption * keys and it is unclear which one should be used this function can help to detect bad decryptions. * @return the decrypted attachment. */ getAndDecryptSecondaryDocumentAttachment(document: models.Document, secondaryAttachmentKey: string, validator?: (decrypted: ArrayBuffer) => Promise): Promise; /** * Gets the secondary attachment of a document and tries to decrypt it using the encryption keys of the document. * @param document a document. * @param secondaryAttachmentKey key of the secondary attachment. * @param validator optionally a validator function which checks if the decryption was successful. In cases where the document has many encryption * keys and it is unclear which one should be used this function can help to detect bad decryptions. * @return an object containing: * - data: the decrypted attachment, if it could be decrypted, else the encrypted attachment. * - wasDecrypted: if the data was successfully decrypted or not */ getAndTryDecryptSecondaryDocumentAttachment(document: models.Document, secondaryAttachmentKey: string, validator?: (decrypted: ArrayBuffer) => Promise): Promise<{ data: ArrayBuffer; wasDecrypted: boolean; }>; /** * @param document a document * @return the id of the message that the document refers to, retrieved from the encrypted metadata. Normally there should only be one element * in the returned array, but in case of entity merges there could be multiple values. */ decryptMessageIdOf(document: models.Document): Promise; /** * @return if the logged data owner has write access to the content of the given document */ hasWriteAccess(document: models.Document): Promise; /** * Share an existing document with other data owners, allowing them to access the non-encrypted data of the document and optionally also * the encrypted content, with read-only or read-write permissions. * @param delegateId the id of the data owner which will be granted access to the document. * @param document the document to share. * @param options optional parameters to customize the sharing behaviour: * - 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 * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - shareMessageId: specifies if the id of the message that this document refers to should be shared with the delegate (defaults to * {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @return the updated entity */ shareWith(delegateId: string, document: models.Document, options?: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; shareMessageId?: ShareMetadataBehaviour; }): Promise; /** * Share an existing document with other data owners, allowing them to access the non-encrypted data of the document and optionally also * the encrypted content, with read-only or read-write permissions. * @param document the document to share. * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options: * - 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 * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - shareMessageId: specifies if the id of the message that this document refers to should be shared with the delegate (defaults to * {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @return the updated entity. */ shareWithMany(document: models.Document, delegates: { [delegateId: string]: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; shareMessageId?: ShareMetadataBehaviour; }; }): Promise; /** * Share an existing document with other data owners, allowing them to access the non-encrypted data of the document and optionally also * the encrypted content, with read-only or read-write permissions. * @param document the document to share. * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options: * - 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 * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - shareMessageId: specifies if the id of the message that this document refers to should be shared with the delegate (defaults to * {@link ShareMetadataBehaviour.IF_AVAILABLE}). * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @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 * the operation failed. */ tryShareWithMany(document: models.Document, delegates: { [delegateId: string]: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; shareMessageId?: ShareMetadataBehaviour; }; }): Promise>; /** * Gets the data owners that have access to a document. * @param entity the document. * @return an object containing the permissions by data owner id and a flag indicating if there are unknown anonymous data owners. */ getDataOwnersWithAccessTo(entity: models.Document): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum; }; hasUnknownAnonymousDataOwners: boolean; }>; /** * Gets the encryption keys of a document. * @param entity the document. * @return an array of encryption keys. */ getEncryptionKeysOf(entity: models.Document): Promise; /** * Creates delegation de-anonymization metadata for a document. * @param entity the document. * @param delegates the data owner ids of the delegates. */ createDelegationDeAnonymizationMetadata(entity: models.Document, delegates: string[]): Promise; private decryptPage; /** * Creates a new document. * @param user the user (not used). * @param body the document to create. * @return the created document. */ createDocumentWithUser(user: models.User | undefined, body: models.Document): Promise; /** * Deletes the main attachment of a document. * @param user the user (not used). * @param documentId the id of the document. * @param documentRev the revision of the document. * @return the updated document. */ deleteAttachmentWithUser(user: models.User | undefined, documentId: string, documentRev: string): Promise; /** * @deprecated */ findByTypeHCPartyMessageSecretFKeysWithUser(user: models.User | undefined, documentTypeCode: string, hcPartyId: string, secretFKeys: string[]): Promise>; /** * @deprecated */ findDocumentsByHCPartyPatientForeignKeysWithUser(user: models.User | undefined, hcPartyId: string, secretFKeys: string[]): Promise>; /** * @deprecated */ findDocumentsByHCPartyPatientForeignKeyWithUser(user: models.User | undefined, hcPartyId: string, secretFKey: string, startKey?: string, startDocumentId?: string, limit?: number): Promise; findWithoutDelegationWithUser(user: models.User | undefined, limit?: number): Promise>; /** * Gets a document by id. * @param user the user (not used). * @param documentId the id of the document. * @return the document. */ getDocumentWithUser(user: models.User | undefined, documentId: string): Promise; /** * Gets a document by external UUID. * @param user the user (not used). * @param externalUuid the external UUID of the document. * @return the document. */ getDocumentByExternalUuidWithUser(user: models.User | undefined, externalUuid: string): Promise; /** * Gets multiple documents by their ids. * @param user the user (not used). * @param body a list of document ids. * @return the documents. */ getDocumentsWithUser(user: models.User | undefined, body?: ListOfIds): Promise>; /** * Gets all documents with a specific external UUID. * @param user the user (not used). * @param externalUuid the external UUID. * @return the documents. */ getDocumentsByExternalUuidWithUser(user: models.User | undefined, externalUuid: string): Promise>; /** * Updates a document. * @param user the user (not used). * @param body the document to update. * @return the updated document. */ modifyDocumentWithUser(user: models.User | undefined, body: models.Document): Promise; /** * Updates multiple documents. * @param user the user (not used). * @param body the documents to update. * @return the updated documents. */ modifyDocumentsWithUser(user: models.User | undefined, body: Array): Promise>; /** * Sets the main attachment of a document. * @param user the user (not used). * @param documentId the id of the document. * @param documentRev the revision of the document. * @param body the attachment data. * @param utis an array of UTIs for the attachment. * @param dataIsEncrypted whether the data is already encrypted. * @return the updated document. */ setMainDocumentAttachmentWithUser(user: models.User | undefined, documentId: string, documentRev: string, body: Object, utis?: Array, dataIsEncrypted?: boolean): Promise; /** * Sets a secondary attachment on a document. * @param user the user (not used). * @param documentId the id of the document. * @param key the key for the secondary attachment. * @param rev the revision of the document. * @param attachment the attachment data. * @param utis an array of UTIs for the attachment. * @param dataIsEncrypted whether the data is already encrypted. * @return the updated document. */ setSecondaryAttachmentWithUser(user: models.User | undefined, documentId: string, key: string, rev: string, attachment: Object, utis?: Array, dataIsEncrypted?: boolean): Promise; /** * Deletes a secondary attachment from a document. * @param user the user (not used). * @param documentId the id of the document. * @param key the key of the secondary attachment. * @param rev the revision of the document. * @return the updated document. */ deleteSecondaryAttachmentWithUser(user: models.User | undefined, documentId: string, key: string, rev: string): Promise; createDocument(body?: models.Document): never; deleteAttachment(documentId: string): never; findByTypeHCPartyMessageSecretFKeys(documentTypeCode: string, hcPartyId: string, secretFKeys: string[]): never; findDocumentsByHCPartyPatientForeignKeys(hcPartyId: string, secretFKeys: string[]): never; findDocumentsByHCPartyPatientForeignKey(hcPartyId: string, secretFKey: string, startKey?: string, startDocumentId?: string, limit?: number): never; findWithoutDelegation(limit?: number): never; getDocument(documentId: string): never; getDocumentByExternalUuid(externalUuid: string): never; getDocuments(body?: ListOfIds): never; getDocumentsByExternalUuid(externalUuid: string): never; modifyDocument(body?: models.Document): never; modifyDocuments(body?: Array): never; setMainDocumentAttachment(documentId: string, documentRev: string, body: Object, utis?: Array, dataIsEncrypted?: boolean): never; setDocumentAttachmentBody(documentId: string, documentRev: string, enckeys?: null, body?: Object, utis?: string[]): never; setDocumentAttachment(documentId: string, documentRev: string, enckeys?: null, body?: Object, utis?: string[]): never; setDocumentAttachmentMulti(attachment: ArrayBuffer, documentRev: string, documentId: string, enckeys?: null): never; setSecondaryAttachment(documentId: string, key: string, rev: string, attachment: Object, utis?: Array, dataIsEncrypted?: boolean): never; deleteSecondaryAttachment(documentId: string, key: string, rev: string): never; /** * Like {@link getConflictsForEntity} but additionally decrypts the conflicting revisions. * @param user the current user (unused for documents, kept for API consistency). * @param entityId the id of the document to retrieve the conflicts for. * @return the decrypted conflicting revisions of the document. */ getConflictsForEntityWithUser(user: models.User, entityId: string): Promise>; /** * Like {@link declareConflictWinner} but encrypts the winning revision before sending it and decrypts the saved * winner returned by the backend. * @param user the current user (unused for documents, kept for API consistency). * @param request the {@link models.ConflictResolutionRequest} carrying the (decrypted) winning revision and the conflicts to purge. * @return the {@link models.ConflictResolutionResult} with the decrypted saved winner and the conflicts that are still unresolved. */ declareConflictWinnerWithUser(user: models.User, request: models.ConflictResolutionRequest): Promise>; /** * Like {@link getConflictsForEntityWithUser} but targets the entity of the group with the given id. * @param user the current user (unused for documents, kept for API consistency). * @param groupId the id of the group the document belongs to. * @param entityId the id of the document to retrieve the conflicts for. * @return the decrypted conflicting revisions of the document. */ getConflictsForEntityInGroupWithUser(user: models.User, groupId: string, entityId: string): Promise>; /** * Like {@link declareConflictWinnerWithUser} but targets the entity of the group with the given id. * @param user the current user (unused for documents, kept for API consistency). * @param groupId the id of the group the document belongs to. * @param request the {@link models.ConflictResolutionRequest} carrying the (decrypted) winning revision and the conflicts to purge. * @return the {@link models.ConflictResolutionResult} with the decrypted saved winner and the conflicts that are still unresolved. */ declareConflictWinnerInGroupWithUser(user: models.User, groupId: string, request: models.ConflictResolutionRequest): Promise>; }