UNPKG

temporibusunde

Version:

Access and interact with Aragon Organizations and their apps.

50 lines (44 loc) 1.43 kB
import { AragonArtifact, ConnectionContext, Metadata } from '../types' import { resolveArtifact } from '../utils/metadata' import Organization from './Organization' import Permission, { PermissionData } from './Permission' export interface RoleData { appAddress: string appId: string artifact?: string | null contentUri?: string | null hash: string manager?: string grantees?: PermissionData[] | null } export default class Role { readonly appAddress!: string readonly appId!: string readonly description?: string readonly hash!: string readonly params?: string[] readonly permissions?: Permission[] | null readonly manager?: string readonly name?: string constructor(data: RoleData, metadata: Metadata, organization: Organization) { const { roles } = metadata[0] as AragonArtifact const role = roles?.find((role) => role.bytes === data.hash) this.appAddress = data.appAddress this.description = role?.name this.hash = data.hash this.manager = data.manager this.name = role?.id this.params = role?.params this.permissions = data.grantees?.map( (grantee) => new Permission(grantee, organization) ) } static async create( data: RoleData, organization: Organization ): Promise<Role> { const artifact = await resolveArtifact(data) const metadata: Metadata = [artifact] return new Role(data, metadata, organization) } }