import { inject, injectable } from "@codemation/core"; import { HmacRequestSigner } from "./HmacRequestSigner"; @injectable() export class PairedFetch { constructor(@inject(HmacRequestSigner) private readonly signer: HmacRequestSigner) {} async get(url: string): Promise { const headers = this.signer.sign("GET", url, ""); return fetch(url, { method: "GET", headers: { ...headers } }); } async post(url: string, body: unknown): Promise { const bodyString = JSON.stringify(body); const headers = this.signer.sign("POST", url, bodyString); return fetch(url, { method: "POST", headers: { ...headers, "Content-Type": "application/json" }, body: bodyString, }); } async delete(url: string): Promise { const headers = this.signer.sign("DELETE", url, ""); return fetch(url, { method: "DELETE", headers: { ...headers } }); } }