import {z} from 'zod' export type GetApiV1SpacesSpaceIdProjectsProjectIdAttachmentsAttachmentIdArgs = {spaceId: number, projectId: number, attachmentId: number, 'X-Org-Id': number}; export type GetApiV1SpacesSpaceIdProjectsProjectIdAttachmentsAttachmentIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const orgRoleDto = z.object({orgRoleId: z.number().int().optional(), roleName: z.string().optional()}); export const userMinimalDto = z.object({userId: z.number().int().optional(), firstName: z.string().optional(), email: z.string().optional(), profilePicURL: z.string().optional(), profilePicColor: z.string().optional(), provider: z.string().optional(), role: orgRoleDto.optional()}); export const attachmentDto = z.object({tenantId: z.number().int().optional(), attachmentId: z.number().int().optional(), attachmentName: z.string().optional(), attachmentUrl: z.string().optional(), attachmentType: z.string().optional(), size: z.number().int().optional(), projectId: z.number().int().optional(), spaceId: z.number().int().optional(), taskId: z.number().int().optional(), parentTaskId: z.number().int().optional(), commentId: z.number().int().optional(), createdBy: userMinimalDto.optional(), createdTime: z.string().optional(), taskName: z.string().optional(), projectName: z.string().optional(), spaceName: z.string().optional(), chatAttachment: z.boolean().optional(), isChatAttachment: z.boolean().optional()}); export const attachmentWithStateDto = z.object({attachment: attachmentDto.optional(), completedBytes: z.number().int().optional(), totalSize: z.number().int().optional(), lastUpdated: z.string().optional()}); export const apiSuccessResponseAttachmentWithStateDto = z.object({success: z.boolean().optional(), message: z.string().optional(), code: z.number().int().optional(), data: attachmentWithStateDto.optional(), timestamp: z.string().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 }; /** * Get one attachment of a project * * GET /v1/spaces/{spaceId}/projects/{projectId}/attachments/{attachmentId} */ export const getApiV1SpacesSpaceIdProjectsProjectIdAttachmentsAttachmentId = async (args: GetApiV1SpacesSpaceIdProjectsProjectIdAttachmentsAttachmentIdArgs, options?: GetApiV1SpacesSpaceIdProjectsProjectIdAttachmentsAttachmentIdOptions) => { const {baseUrl = "https://api.astravue.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Org-Id'] != null) headers.set("X-Org-Id", String(args['X-Org-Id'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/spaces/${encodeURIComponent(String(args.spaceId))}/projects/${encodeURIComponent(String(args.projectId))}/attachments/${encodeURIComponent(String(args.attachmentId))}${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(apiSuccessResponseAttachmentWithStateDto, await res.json()) };