import {z} from 'zod' export type GetApiProjectsProjectIdQaChecksArgs = {projectId: number, limit?: number | undefined, offset?: number | undefined, category?: ('empty' | 'variables' | 'tags' | 'punctuation' | 'symbol_register' | 'spaces' | 'size' | 'special_symbols' | 'wrong_translation' | 'spellcheck' | 'icu' | 'numbers' | 'ai' | 'outdated') | undefined, validation?: ('empty_string_check' | 'empty_suggestion_check' | 'max_length_check' | 'tags_check' | 'mismatch_ids_check' | 'cdata_check' | 'specials_symbols_check' | 'leading_newlines_check' | 'trailing_newlines_check' | 'leading_spaces_check' | 'trailing_spaces_check' | 'multiple_spaces_check' | 'custom_blocked_variables_check' | 'highest_priority_custom_variables_check' | 'highest_priority_variables_check' | 'c_variables_check' | 'python_variables_check' | 'rails_variables_check' | 'java_variables_check' | 'dot_net_variables_check' | 'twig_variables_check' | 'php_variables_check' | 'freemarker_variables_check' | 'lowest_priority_variable_check' | 'lowest_priority_custom_variables_check' | 'punctuation_check' | 'spaces_before_punctuation_check' | 'spaces_after_punctuation_check' | 'non_breaking_spaces_check' | 'capitalize_check' | 'multiple_uppercase_check' | 'parentheses_check' | 'entities_check' | 'escaped_quotes_check' | 'wrong_translation_issue_check' | 'spellcheck' | 'icu_check' | 'numbers_check' | 'ai_check' | 'outdated_translation_check') | undefined, languageIds?: string | undefined, taskId?: number | undefined, fileId?: number | undefined}; export type GetApiProjectsProjectIdQaChecksOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const qaCheck = z.object({stringId: z.number().int().optional(), languageId: z.string().optional(), category: z.string().optional(), categoryDescription: z.string().optional(), validation: z.string().optional(), validationDescription: z.string().optional(), pluralId: z.number().int().optional(), text: z.string().optional()}); export const qaCheckResource = z.object({data: qaCheck}); export const pagination = z.object({offset: z.number().int().optional(), limit: z.number().int().optional()}); export const qaCheckCollectionResource = z.object({data: z.array(qaCheckResource), pagination: pagination.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 }; /** * List QA Check Issues * * GET /projects/{projectId}/qa-checks */ export const getApiProjectsProjectIdQaChecks = async (args: GetApiProjectsProjectIdQaChecksArgs, options?: GetApiProjectsProjectIdQaChecksOptions) => { const {baseUrl = "https://api.crowdin.com/api/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.category != null) query.append("category", String(args.category)) if (args.validation != null) query.append("validation", String(args.validation)) if (args.languageIds != null) query.append("languageIds", String(args.languageIds)) if (args.taskId != null) query.append("taskId", String(args.taskId)) if (args.fileId != null) query.append("fileId", String(args.fileId)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/qa-checks${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(qaCheckCollectionResource, await res.json()) };