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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | 57x 57x | import { sdk, table } from "../index.client";
import { StorageReader } from "./StorageReader";
/**
* 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.
*/
export class StorageSyncReader implements sdk.StorageSyncReader {
constructor(public auth: sdk.AuthId, public storage: StorageReader) {
}
isAvailable(): boolean {
return this.storage.isAvailable()
}
async makeAvailable(): Promise<table.Settings> {
await this.storage.makeAvailable()
Iif (this.auth.userId === undefined) {
const user = await this.storage.findUserByIdentityKey(this.auth.identityKey)
Iif (!user)
throw new sdk.WERR_UNAUTHORIZED()
this.auth.userId = user.userId
}
return this.getSettings()
}
destroy(): Promise<void> {
return this.storage.destroy()
}
getSettings(): table.Settings {
return this.storage.getSettings()
}
async getSyncChunk(args: sdk.RequestSyncChunkArgs): Promise<sdk.SyncChunk> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.identityKey !== this.auth.identityKey)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.getSyncChunk(args)
}
async findUserByIdentityKey(key: string): Promise<table.User | undefined> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (key !== this.auth.identityKey)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findUserByIdentityKey(key)
}
async findSyncStates(args: sdk.FindSyncStatesArgs): Promise<table.SyncState[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findSyncStates(args)
}
async findCertificateFields(args: sdk.FindCertificateFieldsArgs): Promise<table.CertificateField[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findCertificateFields(args)
}
async findCertificates(args: sdk.FindCertificatesArgs): Promise<table.Certificate[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findCertificates(args)
}
async findCommissions(args: sdk.FindCommissionsArgs): Promise<table.Commission[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findCommissions(args)
}
async findOutputBaskets(args: sdk.FindOutputBasketsArgs): Promise<table.OutputBasket[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findOutputBaskets(args)
}
async findOutputs(args: sdk.FindOutputsArgs): Promise<table.Output[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findOutputs(args)
}
async findOutputTags(args: sdk.FindOutputTagsArgs): Promise<table.OutputTag[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findOutputTags(args)
}
async findTransactions(args: sdk.FindTransactionsArgs): Promise<table.Transaction[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findTransactions(args)
}
async findTxLabels(args: sdk.FindTxLabelsArgs): Promise<table.TxLabel[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.partial.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.findTxLabels(args)
}
async getProvenTxsForUser(args: sdk.FindForUserSincePagedArgs): Promise<table.ProvenTx[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.getProvenTxsForUser(args)
}
async getProvenTxReqsForUser(args: sdk.FindForUserSincePagedArgs): Promise<table.ProvenTxReq[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.getProvenTxReqsForUser(args)
}
async getTxLabelMapsForUser(args: sdk.FindForUserSincePagedArgs): Promise<table.TxLabelMap[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.getTxLabelMapsForUser(args)
}
async getOutputTagMapsForUser(args: sdk.FindForUserSincePagedArgs): Promise<table.OutputTagMap[]> {
Iif (!this.auth.userId) await this.makeAvailable()
Iif (args.userId !== this.auth.userId)
throw new sdk.WERR_UNAUTHORIZED()
return await this.storage.getOutputTagMapsForUser(args)
}
} |