export type CdnEnvironmentApiRequestPublication = {labels?: Array | undefined}; export type CreateApiApiV2EnvironmentsEnvironmentKeyPublishArgs = {environmentKey: string, body: CdnEnvironmentApiRequestPublication}; export type CreateApiApiV2EnvironmentsEnvironmentKeyPublishOptions = {baseUrl?: string | undefined, ProjectAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Publish translations to given environment * * POST /api/v2/environments/{environmentKey}/publish */ export const createApiApiV2EnvironmentsEnvironmentKeyPublish = async (args: CreateApiApiV2EnvironmentsEnvironmentKeyPublishArgs, options?: CreateApiApiV2EnvironmentsEnvironmentKeyPublishOptions) => { 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/${encodeURIComponent(String(args.environmentKey))}/publish${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 };