UNPKG

wallet-storage-client

Version:
142 lines 5.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StorageSyncReader = void 0; const index_client_1 = require("../index.client"); /** * The `StorageSyncReader` non-abstract class must be used when authentication checking access to the methods of a `StorageBaseReader` is required. * * Constructed from an `auth` object that must minimally include the authenticated user's identityKey, * and the `StorageBaseReader` to be protected. */ class StorageSyncReader { constructor(auth, storage) { this.auth = auth; this.storage = storage; } isAvailable() { return this.storage.isAvailable(); } async makeAvailable() { await this.storage.makeAvailable(); if (this.auth.userId === undefined) { const user = await this.storage.findUserByIdentityKey(this.auth.identityKey); if (!user) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); this.auth.userId = user.userId; } return this.getSettings(); } destroy() { return this.storage.destroy(); } getSettings() { return this.storage.getSettings(); } async getSyncChunk(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.identityKey !== this.auth.identityKey) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.getSyncChunk(args); } async findUserByIdentityKey(key) { if (!this.auth.userId) await this.makeAvailable(); if (key !== this.auth.identityKey) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findUserByIdentityKey(key); } async findSyncStates(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findSyncStates(args); } async findCertificateFields(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findCertificateFields(args); } async findCertificates(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findCertificates(args); } async findCommissions(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findCommissions(args); } async findOutputBaskets(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findOutputBaskets(args); } async findOutputs(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findOutputs(args); } async findOutputTags(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findOutputTags(args); } async findTransactions(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findTransactions(args); } async findTxLabels(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.partial.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.findTxLabels(args); } async getProvenTxsForUser(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.getProvenTxsForUser(args); } async getProvenTxReqsForUser(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.getProvenTxReqsForUser(args); } async getTxLabelMapsForUser(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.getTxLabelMapsForUser(args); } async getOutputTagMapsForUser(args) { if (!this.auth.userId) await this.makeAvailable(); if (args.userId !== this.auth.userId) throw new index_client_1.sdk.WERR_UNAUTHORIZED(); return await this.storage.getOutputTagMapsForUser(args); } } exports.StorageSyncReader = StorageSyncReader; //# sourceMappingURL=StorageSyncReader.js.map