export type GetApiCasHashArgs = {hash: string, 'max-size': string}; export type GetApiCasHashOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /cas/{hash} */ export const getApiCasHash = async (args: GetApiCasHashArgs, options?: GetApiCasHashOptions) => { const {baseUrl = "https://virtserver.swaggerhub.com/sidetree/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") if (args['max-size'] != null) query.append("max-size", String(args['max-size'])) const url = `${baseUrl.replace(/\/+$/, '')}/cas/${encodeURIComponent(String(args.hash))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };