import {z} from 'zod' export type PatchApiProjectsProjectIdJobsIdArgs = {'X-PhraseApp-OTP'?: string | undefined, project_id: string, id: string, body: {branch?: string | undefined, name?: string | undefined, briefing?: string | undefined, due_date?: (string | null) | undefined, ticket_url?: string | undefined, target_locale_ids?: Array | undefined, autotranslate?: boolean | undefined}}; export type PatchApiProjectsProjectIdJobsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const projectShort = z.object({id: z.string().optional(), name: z.string().optional(), main_format: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const userPreview = z.object({id: z.string().optional(), username: z.string().optional(), name: z.string().optional(), gravatar_uid: z.string().optional()}); export const localePreview = z.object({id: z.string().optional(), name: z.string().optional(), code: z.string().optional()}); export const keyPreview = z.object({id: z.string().optional(), name: z.string().optional(), plural: z.boolean().optional(), use_ordinal_rules: z.boolean().optional()}); export const jobAnnotationShort = z.object({name: z.string(), value: z.string()}); export const jobDetails = z.object({id: z.string().optional(), name: z.string().optional(), briefing: z.string().optional(), due_date: z.string().nullable().optional(), state: z.string().optional(), ticket_url: z.string().optional(), project: projectShort.optional(), branch: z.object({name: z.string().optional()}).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), automation_id: z.string().nullable().optional(), job_template_id: z.string().nullable().optional(), review_due_date: z.string().nullable().optional(), owner: userPreview.optional(), job_tag_name: z.string().optional(), source_translations_updated_at: z.string().optional(), source_locale: localePreview.optional(), locales: z.array(localePreview).optional(), keys: z.array(keyPreview).optional(), annotations: z.array(jobAnnotationShort).optional(), locked: z.boolean().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 }; /** * Update a job * * PATCH /projects/{project_id}/jobs/{id} */ export const patchApiProjectsProjectIdJobsId = async (args: PatchApiProjectsProjectIdJobsIdArgs, options?: PatchApiProjectsProjectIdJobsIdOptions) => { 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.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(jobDetails, await res.json()) };