export type GetApiPipelineMetricUsageArgs = {from: string, to: string, bucket: number, include_deleted?: boolean | undefined, pipeline_id?: string | undefined, traffic?: ('ingress' | 'egress') | undefined}; export type GetApiPipelineMetricUsageOptions = {baseUrl?: string | undefined, PipelineServiceKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Fetch account usage metics * * GET /pipeline/metric/usage */ export const getApiPipelineMetricUsage = async (args: GetApiPipelineMetricUsageArgs, options?: GetApiPipelineMetricUsageOptions) => { const {baseUrl = "https://api.mezmo.com/v3", fetch: fetchFn = fetch, PipelineServiceKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.bucket != null) query.append("bucket", String(args.bucket)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.pipeline_id != null) query.append("pipeline_id", String(args.pipeline_id)) if (args.traffic != null) query.append("traffic", String(args.traffic)) if (PipelineServiceKey !== undefined) headers.set("Authorization", PipelineServiceKey) const url = `${baseUrl.replace(/\/+$/, '')}/pipeline/metric/usage${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 undefined };