import {z} from 'zod' export type ProjectSystemPlaceholderMassOperation = {op: 'replace' | 'test', path: '/wrappedAmpersand/isEnabled' | '/appleStringsdictPlural/isEnabled' | '/dollarInsideBraces/isEnabled' | '/dollarOutsideBraces/isEnabled' | '/wrappedColon/isEnabled' | '/wrappedDollar/isEnabled' | '/dollarParentheses/isEnabled' | '/i18nextNesting/isEnabled' | '/i18nextLegacy/isEnabled' | '/rubyInterpolation/isEnabled' | '/mailchimpMergeTag/isEnabled' | '/swiftInterpolation/isEnabled' | '/bracesTriple/isEnabled' | '/bracesDouble/isEnabled' | '/bracesSingle/isEnabled' | '/bracesDoubleFormatted/isEnabled' | '/dateTimePattern/isEnabled' | '/appleStringCatalogNamed/isEnabled' | '/printfSpecifier/isEnabled' | '/pythonPercentFormat/isEnabled' | '/railsI18n/isEnabled' | '/javaMessageFormat/isEnabled' | '/dotNetCompositeFormat/isEnabled' | '/twig/isEnabled' | '/phpInterpolation/isEnabled' | '/freemarkerDirective/isEnabled' | '/wrappedPercent/isEnabled' | '/dateTimeSpecifier/isEnabled', value: boolean}; export type ProjectSystemPlaceholderMassPatch = Array; export type PatchApiProjectsProjectIdSystemPlaceholdersArgs = {projectId: number, body: ProjectSystemPlaceholderMassPatch}; export type PatchApiProjectsProjectIdSystemPlaceholdersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const projectSystemPlaceholderResponse = z.object({id: z.enum(["wrappedAmpersand", "appleStringsdictPlural", "dollarInsideBraces", "dollarOutsideBraces", "wrappedColon", "wrappedDollar", "dollarParentheses", "i18nextNesting", "i18nextLegacy", "rubyInterpolation", "mailchimpMergeTag", "swiftInterpolation", "bracesTriple", "bracesDouble", "bracesSingle", "bracesDoubleFormatted", "dateTimePattern", "appleStringCatalogNamed", "printfSpecifier", "pythonPercentFormat", "railsI18n", "javaMessageFormat", "dotNetCompositeFormat", "twig", "phpInterpolation", "freemarkerDirective", "wrappedPercent", "dateTimeSpecifier"]), isEnabled: z.boolean(), label: z.string(), examples: z.array(z.string()), description: z.string()}); export const projectSystemPlaceholderResource = z.object({data: projectSystemPlaceholderResponse}); export const projectSystemPlaceholderUpdatedCollectionResource = z.object({data: z.array(projectSystemPlaceholderResource)}); 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 }; /** * Project System Placeholder Batch Operations * * PATCH /projects/{projectId}/system-placeholders */ export const patchApiProjectsProjectIdSystemPlaceholders = async (args: PatchApiProjectsProjectIdSystemPlaceholdersArgs, options?: PatchApiProjectsProjectIdSystemPlaceholdersOptions) => { const {baseUrl = "https://api.crowdin.com/api/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/system-placeholders${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(projectSystemPlaceholderUpdatedCollectionResource, await res.json()) };