import {z} from 'zod' export type CreateApiProjectsProjectIdJobsJobIdLocalesIdCompleteArgs = {'X-PhraseApp-OTP'?: string | undefined, project_id: string, job_id: string, id: string, body: {branch?: string | undefined}}; export type CreateApiProjectsProjectIdJobsJobIdLocalesIdCompleteOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const jobPreview = z.object({id: z.string().optional(), name: z.string().optional(), state: z.string().optional()}); export const localePreview = z.object({id: z.string().optional(), name: z.string().optional(), code: z.string().optional()}); export const localeUserPreview = z.object({id: z.string().optional(), username: z.string().optional(), name: z.string().optional(), role: z.string().optional()}); export const localeTeamPreview = z.object({id: z.string().optional(), name: z.string().optional(), role: z.string().optional()}); export const jobAnnotationShort = z.object({name: z.string(), value: z.string()}); export const jobLocale = z.object({id: z.string().optional(), job: jobPreview.optional(), locale: localePreview.optional(), users: z.array(localeUserPreview).optional(), teams: z.array(localeTeamPreview).optional(), completed: z.boolean().optional(), translation_completed_at: z.string().optional(), review_completed_at: z.string().optional(), annotations: z.array(jobAnnotationShort).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 }; /** * Complete a job locale * * POST /projects/{project_id}/jobs/{job_id}/locales/{id}/complete */ export const createApiProjectsProjectIdJobsJobIdLocalesIdComplete = async (args: CreateApiProjectsProjectIdJobsJobIdLocalesIdCompleteArgs, options?: CreateApiProjectsProjectIdJobsJobIdLocalesIdCompleteOptions) => { const {baseUrl = "https://eu.phrase.com/control-hub", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-PhraseApp-OTP'] != null) headers.set("X-PhraseApp-OTP", String(args['X-PhraseApp-OTP'])) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/jobs/${encodeURIComponent(String(args.job_id))}/locales/${encodeURIComponent(String(args.id))}/complete${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 validateResponse(jobLocale, await res.json()) };