import {z} from 'zod' export type FilterOperator = 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'in' | 'nin' | 'contains' | 'starts_with' | 'ends_with' | 'regex' | 'exists' | 'is_null' | 'text' | 'phrase' | 'words' | 'geo_radius' | 'geo_bounding_box' | 'geo_polygon'; export type DynamicValue = {type?: 'dynamic' | undefined, field: string}; export type FilterCondition = {field: string, operator?: FilterOperator | undefined, value: DynamicValue | unknown}; export type LogicalOperatorInput = {AND?: (Array | null) | undefined, OR?: (Array | null) | undefined, NOT?: (Array | null) | undefined, case_sensitive?: (boolean | null) | undefined} | {[key: string]: unknown}; export type SortDirection = 'asc' | 'desc'; export type SortOption = {field: string, direction?: SortDirection | undefined}; export type ListUploadsRequest = {filters?: (LogicalOperatorInput | null) | undefined, sort?: (SortOption | null) | undefined, search?: (string | null) | undefined, return_presigned_urls?: boolean | undefined, limit?: number | undefined, offset?: number | undefined}; export type CreateApiV1BucketsBucketIdentifierUploadsListArgs = {bucket_identifier: string, limit?: (number | null) | undefined, page_size?: (number | null) | undefined, offset?: (number | null) | undefined, page?: (number | null) | undefined, cursor?: (string | null) | undefined, next_cursor?: (string | null) | undefined, after?: (string | null) | undefined, include_total?: boolean | undefined, body: ListUploadsRequest}; export type CreateApiV1BucketsBucketIdentifierUploadsListOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, NamespaceHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const taskStatusEnum = z.enum(["PENDING", "QUEUED", "IN_PROGRESS", "PROCESSING", "COMPLETED", "COMPLETED_WITH_ERRORS", "FAILED", "CANCELED", "INTERRUPTED", "UNKNOWN", "SKIPPED", "DRAFT", "ACTIVE", "ARCHIVED", "SUSPENDED", "DEACTIVATED"]); export const uploadResponse = z.object({upload_id: z.string(), bucket_id: z.string(), filename: z.string(), content_type: z.string(), file_size_bytes: z.number().int().nullable().optional(), presigned_url: z.string().min(1).max(2083).nullable().optional(), presigned_url_expiration: z.number().int(), s3_key: z.string(), status: taskStatusEnum, metadata: z.record(z.string(), z.unknown()).optional(), create_object_on_confirm: z.boolean(), object_metadata: z.record(z.string(), z.unknown()).nullable().optional(), blob_property: z.string().nullable().optional(), blob_type: z.string().nullable().optional(), file_hash: z.string().nullable().optional(), skip_duplicates: z.boolean().optional(), is_duplicate: z.boolean().optional(), duplicate_of_upload_id: z.string().nullable().optional(), skipped_unique_key: z.boolean().optional(), existing_object_id: z.string().nullable().optional(), message: z.string().nullable().optional(), created_at: z.string(), expires_at: z.string(), completed_at: z.string().nullable().optional(), verified_at: z.string().nullable().optional(), etag: z.string().nullable().optional(), object_id: z.string().nullable().optional(), task_id: z.string().nullable().optional()}); export const paginationResponse = z.object({total: z.number().int().nullable().optional(), page: z.number().int().nullable().optional(), page_size: z.number().int().nullable().optional(), total_pages: z.number().int().nullable().optional(), next_page: z.string().nullable().optional(), previous_page: z.string().nullable().optional(), next_cursor: z.string().nullable().optional()}); export const uploadListStats = z.object({total_uploads: z.number().int(), total_size_bytes: z.number().int(), uploads_by_status: z.record(z.string(), z.number().int()), avg_file_size_bytes: z.number(), unique_buckets: z.number().int()}); export const listUploadsResponse = z.object({results: z.array(uploadResponse), pagination: paginationResponse, stats: uploadListStats}); 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 Uploads * * POST /v1/buckets/{bucket_identifier}/uploads/list */ export const createApiV1BucketsBucketIdentifierUploadsList = async (args: CreateApiV1BucketsBucketIdentifierUploadsListArgs, options?: CreateApiV1BucketsBucketIdentifierUploadsListOptions) => { const {baseUrl = "https://api.mixpeek.com", fetch: fetchFn = fetch, BearerAuth, NamespaceHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.page != null) query.append("page", String(args.page)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.next_cursor != null) query.append("next_cursor", String(args.next_cursor)) if (args.after != null) query.append("after", String(args.after)) if (args.include_total != null) query.append("include_total", String(args.include_total)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) if (NamespaceHeader !== undefined) headers.set("X-Namespace", NamespaceHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/buckets/${encodeURIComponent(String(args.bucket_identifier))}/uploads/list${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(listUploadsResponse, await res.json()) };