import { IHttp, IModify, IPersistence, IRead, } from "@rocket.chat/apps-engine/definition/accessors"; import { IApiEndpointInfo, IApiRequest, } from "@rocket.chat/apps-engine/definition/api"; import { EmptyRequestError } from "../errors/EmptyRequestError"; import { RcSdk } from "../rc-sdk/RcSdk"; import { Store } from "../store/Store"; export class Context { public readonly rc: RcSdk; public readonly store: Store; public readonly request: IApiRequest; public readonly endpoint: IApiEndpointInfo; public readonly read: IRead; public readonly modify: IModify; public readonly http: IHttp; public readonly persis: IPersistence; constructor( request: IApiRequest, endpoint: IApiEndpointInfo, read: IRead, modify: IModify, http: IHttp, persis: IPersistence, ) { this.rc = new RcSdk(http, read); this.store = new Store(read, persis); this.request = request; this.endpoint = endpoint; this.read = read; this.modify = modify; this.http = http; this.persis = persis; } public id(): string { return this.request.params.id; } public content(): any { if ( !this.request.content || Object.keys(this.request.content).length === 0 ) { throw new EmptyRequestError(); } return this.request.content; } }