export type CreateApiInfraInfraIdCloneArgs = {infra_id: number, name: string}; export type CreateApiInfraInfraIdCloneOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Duplicate an infra * * POST /infra/{infra_id}/clone */ export const createApiInfraInfraIdClone = async (args: CreateApiInfraInfraIdCloneArgs, options?: CreateApiInfraInfraIdCloneOptions) => { const {baseUrl = "https://demo.osrd.fr/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.name != null) query.append("name", String(args.name)) const url = `${baseUrl.replace(/\/+$/, '')}/infra/${encodeURIComponent(String(args.infra_id))}/clone${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };