import {z} from 'zod' export type PatchApiAccountsAccountIdAutomationsAutomationIdArgs = {'X-PhraseApp-OTP'?: string | undefined, account_id: string, id: string, body: {name: string, trigger: 'schedule' | 'upload', project_ids: Array, job_template_id?: string | undefined, status_filters: Array<'unverified' | 'untranslated' | 'ready_for_review'>, tags?: Array | undefined, cron_schedule?: string | undefined, time_zone?: string | undefined, job_owner_id?: string | undefined, include_only_updated_locales?: boolean | undefined}}; export type PatchApiAccountsAccountIdAutomationsAutomationIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const account = z.object({id: z.string().optional(), name: z.string().optional(), slug: z.string().optional(), company: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), company_logo_url: z.string().optional()}); export const automation = z.object({id: z.string().optional(), name: z.string().optional(), status: z.enum(["inactive", "active", "error"]).optional(), trigger: z.enum(["schedule", "upload"]).optional(), status_filters: z.array(z.enum(["unverified", "untranslated", "ready_for_review"])).optional(), project_id: z.string().optional(), project_ids: z.array(z.string()).optional(), job_template_id: z.string().optional(), job_owner_id: z.string().nullable().optional(), include_only_updated_locales: z.boolean().optional(), tags: z.array(z.string()).optional(), cron_schedule: z.string().optional(), time_zone: z.string().optional(), account: account.optional(), created_at: z.string().optional(), updated_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 }; /** * Update an automation * * PATCH /accounts/{account_id}/automations/{automation_id} */ export const patchApiAccountsAccountIdAutomationsAutomationId = async (args: PatchApiAccountsAccountIdAutomationsAutomationIdArgs, options?: PatchApiAccountsAccountIdAutomationsAutomationIdOptions) => { 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(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.account_id))}/automations/${encodeURIComponent(String(args.automation_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(automation, await res.json()) };