export type CdnEnvironmentCreateApiRequest = {key: string, name: string, color: string}; export type CreateApiApiV2EnvironmentsArgs = {body: CdnEnvironmentCreateApiRequest}; export type CreateApiApiV2EnvironmentsOptions = {baseUrl?: string | undefined, ProjectAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new environment * * POST /api/v2/environments */ export const createApiApiV2Environments = async (args: CreateApiApiV2EnvironmentsArgs, options?: CreateApiApiV2EnvironmentsOptions) => { const {baseUrl = "https://api.simplelocalize.io", fetch: fetchFn = fetch, ProjectAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ProjectAPIKey !== undefined) headers.set("X-SimpleLocalize-Token", ProjectAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/environments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };