All files / lib/esm/Service ShareService.js

0% Statements 0/20
0% Branches 0/3
0% Functions 0/6
0% Lines 0/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                               
import Credential from "../Model/Credential";
import { SharingACL } from "../Model/SharingACL";
export class ShareService {
    static async getCredentialsSharedWithUs(vault, server, getCachedIfPossible = false) {
        let sharedItemsResponse = await server.getJson('/sharing/vault/' + vault.guid + '/get', (response) => {
            server.logger.onError(response.message);
        }, getCachedIfPossible);
        const credentials = [];
        if (sharedItemsResponse) {
            for (const sharedItem of sharedItemsResponse) {
                try {
                    const sharedCredential = Credential.fromData(sharedItem.credential_data, vault, server);
                    sharedCredential.encryptedSharedCredentialEncryptionKey = sharedItem.shared_key;
                    // transfer acl data from sharedItem into the new Credential object
                    delete sharedItem.credential_data;
                    const permissionsSharingAcl = new SharingACL(sharedItem.permissions);
                    const newAcl = sharedItem;
                    newAcl.permissions = permissionsSharingAcl;
                    sharedCredential.acl = newAcl;
                    credentials.push(sharedCredential);
                }
                catch (e) {
                    server.logger.anyError(e);
                    server.logger.onError('Failed to decrypt shared credential: ' + sharedItem.credential_data.label);
                }
            }
        }
        return credentials;
    }
    /**
     * Response array entries of ICredentialShareRequest does not contain the credential_data field.
     *
     * @param vault
     * @param server
     */
    static getACLsForCredentialsSharedWithUs(vault, server) {
        return server.getJson('/sharing/vault/' + vault.guid + '/acl', (response) => {
            server.logger.onError(response.message);
        });
    }
    static updateSharedKeyForCredentialSharedWithUsByGuid(encryptedSharedKey, credentialGUID, server) {
        return server.postJson('/sharing/credential/' + credentialGUID + '/acl/shared_key', {
            shared_key: encryptedSharedKey
        }, () => {
        }, 'PATCH');
    }
}