import {z} from 'zod' export type GetApiProjectsProjectIdReportLocalesArgs = {'X-PhraseApp-OTP'?: string | undefined, project_id: string, page?: number | undefined, per_page?: number | undefined, locale_codes?: string | undefined, tag?: string | undefined, branch?: string | undefined}; export type GetApiProjectsProjectIdReportLocalesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const localePreview = z.object({id: z.string().optional(), name: z.string().optional(), code: z.string().optional()}); export const localeReport = z.object({keys_count: z.number().int().optional(), translated_translations_percentage: z.number().optional(), unverified_translations_percentage: z.number().optional(), reviewed_translations_percentage: z.number().optional(), untranslated_keys_percentage: z.number().optional(), completed_translations_count: z.number().int().optional(), untranslated_keys_count: z.number().int().optional(), unverified_translations_count: z.number().int().optional(), reviewed_translations_count: z.number().int().optional(), source_word_count: z.number().int().optional(), word_count: z.number().int().optional(), word_count_unverified: z.number().int().optional(), word_count_missing: z.number().int().optional(), locale: localePreview.optional()}); export const getApiProjectsProjectIdReportLocalesResponse = z.array(localeReport); 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 }; /** * List Locale Reports * * GET /projects/{project_id}/report/locales */ export const getApiProjectsProjectIdReportLocales = async (args: GetApiProjectsProjectIdReportLocalesArgs, options?: GetApiProjectsProjectIdReportLocalesOptions) => { 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.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.locale_codes != null) query.append("locale_codes", String(args.locale_codes)) if (args.tag != null) query.append("tag", String(args.tag)) if (args.branch != null) query.append("branch", String(args.branch)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/report/locales${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(getApiProjectsProjectIdReportLocalesResponse, await res.json()) };