import * as gracely from "gracely" import * as authly from "authly" import { Connection } from "@payfunc/model-base" import { Merchant as ModelMerchant } from "../Merchant" export class Merchant { constructor(readonly connection: Connection) {} async create(request: ModelMerchant): Promise { return await this.connection.post("merchant", request) } async list(): Promise { return this.connection.get("merchant") } async replace(request: ModelMerchant, id: authly.Identifier): Promise { return await this.connection.put("merchant/" + id, request) } async patch(request: Partial, id: authly.Identifier): Promise { return await this.connection.patch("merchant/" + id, request) } async updateRules(request: ModelMerchant.Rules, id: authly.Identifier): Promise { return await this.connection.patch("merchant/" + id + "/rule", request) } async load(id?: authly.Identifier | authly.Identifier[]): Promise { return !id ? await this.connection.get("merchant") : authly.Identifier.is(id) ? await this.connection.get("merchant/" + id) : (await Promise.all(id.map(i => this.connection.get("merchant/" + i)))).filter(ModelMerchant.is) } static open(url: string, token: string): Merchant static open(url: string | undefined, token: string | undefined): Merchant | undefined static open(url: string | undefined, token: string | undefined): Merchant | undefined { const connection = Connection.open(url, token) return connection && new Merchant(connection) } }