import {z} from 'zod' export type GetApiProjectsProjectIdSystemPlaceholdersArgs = {limit?: number | undefined, offset?: number | undefined, projectId: number}; export type GetApiProjectsProjectIdSystemPlaceholdersOptions = {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 pagination = z.object({offset: z.number().int().optional(), limit: z.number().int().optional()}); export const projectSystemPlaceholderCollectionResource = z.object({data: z.array(projectSystemPlaceholderResource), 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 Project System Placeholders * * GET /projects/{projectId}/system-placeholders */ export const getApiProjectsProjectIdSystemPlaceholders = async (args: GetApiProjectsProjectIdSystemPlaceholdersArgs, options?: GetApiProjectsProjectIdSystemPlaceholdersOptions) => { 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)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/system-placeholders${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(projectSystemPlaceholderCollectionResource, await res.json()) };