UNPKG

@atproto/oauth-scopes

Version:

A library for manipulating and validating ATproto OAuth scopes in TypeScript.

62 lines • 2.18 kB
import { ScopeMissingError } from './scope-missing-error.js'; import { AccountPermission, } from './scopes/account-permission.js'; import { BlobPermission, } from './scopes/blob-permission.js'; import { IdentityPermission, } from './scopes/identity-permission.js'; import { RepoPermission, } from './scopes/repo-permission.js'; import { RpcPermission, } from './scopes/rpc-permission.js'; import { ScopesSet } from './scopes-set.js'; export class ScopePermissions { constructor(scope) { this.scopes = new ScopesSet(!scope // "" | null | undefined ? undefined : typeof scope === 'string' ? scope.split(' ') : scope); } allowsAccount(options) { return this.scopes.matches('account', options); } assertAccount(options) { if (!this.allowsAccount(options)) { const scope = AccountPermission.scopeNeededFor(options); throw new ScopeMissingError(scope); } } allowsIdentity(options) { return this.scopes.matches('identity', options); } assertIdentity(options) { if (!this.allowsIdentity(options)) { const scope = IdentityPermission.scopeNeededFor(options); throw new ScopeMissingError(scope); } } allowsBlob(options) { return this.scopes.matches('blob', options); } assertBlob(options) { if (!this.allowsBlob(options)) { const scope = BlobPermission.scopeNeededFor(options); throw new ScopeMissingError(scope); } } allowsRepo(options) { return this.scopes.matches('repo', options); } assertRepo(options) { if (!this.allowsRepo(options)) { const scope = RepoPermission.scopeNeededFor(options); throw new ScopeMissingError(scope); } } allowsRpc(options) { return this.scopes.matches('rpc', options); } assertRpc(options) { if (!this.allowsRpc(options)) { const scope = RpcPermission.scopeNeededFor(options); throw new ScopeMissingError(scope); } } } //# sourceMappingURL=scope-permissions.js.map