import {z} from 'zod' export type GetApiProjectsProjectIdScreenshotsArgs = {projectId: number, search?: string | undefined, orderBy?: ('id' | 'name' | 'tagsCount' | 'createdAt' | 'updatedAt') | undefined, stringId?: number | undefined, stringIds?: string | undefined, labelIds?: string | undefined, excludeLabelIds?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiProjectsProjectIdScreenshotsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const screenshotTagPosition = z.object({x: z.number().int().optional(), y: z.number().int().optional(), width: z.number().int().optional(), height: z.number().int().optional()}); export const screenshotTag = z.object({id: z.number().int().optional(), screenshotId: z.number().int().optional(), stringId: z.number().int().optional(), position: screenshotTagPosition.optional(), createdAt: z.string().optional()}); export const screenshot = z.object({id: z.number().int().optional(), userId: z.number().int().optional(), url: z.string().optional(), webUrl: z.string().optional(), name: z.string().optional(), size: z.object({width: z.number().int().optional(), height: z.number().int().optional()}).optional(), tagsCount: z.number().int().optional(), tags: z.array(screenshotTag).optional(), labels: z.array(z.number().int()).optional(), labelIds: z.array(z.number().int()).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const screenshotResource = z.object({data: screenshot}); export const pagination = z.object({offset: z.number().int().optional(), limit: z.number().int().optional()}); export const screenshotCollectionResource = z.object({data: z.array(screenshotResource), 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 Screenshots * * GET /projects/{projectId}/screenshots */ export const getApiProjectsProjectIdScreenshots = async (args: GetApiProjectsProjectIdScreenshotsArgs, options?: GetApiProjectsProjectIdScreenshotsOptions) => { 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.search != null) query.append("search", String(args.search)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.stringId != null) query.append("stringId", String(args.stringId)) if (args.stringIds != null) query.append("stringIds", String(args.stringIds)) if (args.labelIds != null) query.append("labelIds", String(args.labelIds)) if (args.excludeLabelIds != null) query.append("excludeLabelIds", String(args.excludeLabelIds)) 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))}/screenshots${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(screenshotCollectionResource, await res.json()) };