export type GetApiApiV2AssetsArgs = {path: string, language?: string | undefined, version?: ('working' | 'live') | undefined}; export type GetApiApiV2AssetsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Get raw file-asset content by path * * GET /api/v2/assets */ export const getApiApiV2Assets = async (args: GetApiApiV2AssetsArgs, options: GetApiApiV2AssetsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") if (args.path != null) query.append("path", String(args.path)) if (args.language != null) query.append("language", String(args.language)) if (args.version != null) query.append("version", String(args.version)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/assets${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() };