import {z} from 'zod' export type GetApiProjectsProjectIdLocalesLocaleIdDownloadsIdArgs = {'X-PhraseApp-OTP'?: string | undefined, 'If-Modified-Since'?: string | undefined, 'If-None-Match'?: string | undefined, project_id: string, locale_id: string, id: string}; export type GetApiProjectsProjectIdLocalesLocaleIdDownloadsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const localeDownload = z.object({id: z.string().optional(), status: z.enum(["processing", "completed", "error"]).optional(), result: z.object({url: z.string().optional()}).optional(), params: z.object({file_format: z.string().optional(), locale_id: z.string().optional(), tags: z.string().optional(), branch: z.string().optional(), include_empty_translations: z.boolean().optional(), include_translated_keys: z.boolean().optional(), include_unverified_translations: z.boolean().optional()}).optional(), error: z.string().optional(), created_at: z.string().optional(), completed_at: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Show status of an async locale download * * GET /projects/{project_id}/locales/{locale_id}/downloads/{id} */ export const getApiProjectsProjectIdLocalesLocaleIdDownloadsId = async (args: GetApiProjectsProjectIdLocalesLocaleIdDownloadsIdArgs, options?: GetApiProjectsProjectIdLocalesLocaleIdDownloadsIdOptions) => { const {baseUrl = "https://eu.phrase.com/control-hub", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-PhraseApp-OTP'] != null) headers.set("X-PhraseApp-OTP", String(args['X-PhraseApp-OTP'])) if (args['If-Modified-Since'] != null) headers.set("If-Modified-Since", String(args['If-Modified-Since'])) if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/locales/${encodeURIComponent(String(args.locale_id))}/downloads/${encodeURIComponent(String(args.id))}${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 validateResponse(localeDownload, await res.json()) };