import {z} from 'zod' export type PatchApiProjectsProjectIdKeysIdArgs = {'X-PhraseApp-OTP'?: string | undefined, project_id: string, id: string, body: {branch?: string | undefined, name?: string | undefined, description?: string | undefined, plural?: boolean | undefined, use_ordinal_rules?: boolean | undefined, name_plural?: string | undefined, data_type?: string | undefined, tags?: string | undefined, max_characters_allowed?: number | undefined, screenshot?: string | undefined, remove_screenshot?: boolean | undefined, unformatted?: boolean | undefined, xml_space_preserve?: boolean | undefined, original_file?: string | undefined, localized_format_string?: string | undefined, localized_format_key?: string | undefined, custom_metadata?: Record | undefined, excluded_in_locales?: Array | undefined, format_value_type?: string | undefined}}; export type PatchApiProjectsProjectIdKeysIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const userPreview = z.object({id: z.string().optional(), username: z.string().optional(), name: z.string().optional(), gravatar_uid: z.string().optional()}); export const translationKeyDetails = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), name_hash: z.string().optional(), plural: z.boolean().optional(), use_ordinal_rules: z.boolean().optional(), tags: z.array(z.string()).optional(), data_type: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), name_plural: z.string().optional(), comments_count: z.number().int().optional(), max_characters_allowed: z.number().int().optional(), screenshot_url: z.string().optional(), unformatted: z.boolean().optional(), xml_space_preserve: z.boolean().optional(), original_file: z.string().optional(), format_value_type: z.string().optional(), creator: userPreview.optional(), custom_metadata: z.record(z.string(), 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 a key * * PATCH /projects/{project_id}/keys/{id} */ export const patchApiProjectsProjectIdKeysId = async (args: PatchApiProjectsProjectIdKeysIdArgs, options?: PatchApiProjectsProjectIdKeysIdOptions) => { 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))}/keys/${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(translationKeyDetails, await res.json()) };