import {z} from 'zod' export type GetApiFiles202603FoldersUpdateAsyncTasksTaskIdStatusArgs = {taskId: string}; export type GetApiFiles202603FoldersUpdateAsyncTasksTaskIdStatusOptions = {baseUrl?: string | undefined, privateApps?: string | undefined, fetch?: typeof fetch | undefined}; export const errorDetail = z.object({code: z.string().optional(), context: z.record(z.string(), z.array(z.string())).optional(), in: z.string().optional(), message: z.string(), subCategory: z.string().optional()}); export const standardError = z.object({category: z.string(), context: z.record(z.string(), z.array(z.string())), errors: z.array(errorDetail), id: z.string().optional(), links: z.record(z.string(), z.string()), message: z.string(), status: z.string(), subCategory: z.object({}).optional()}); export const filesFolder = z.object({archived: z.boolean(), archivedAt: z.string().optional(), createdAt: z.string(), id: z.string(), name: z.string().optional(), parentFolderId: z.string().optional(), path: z.string().optional(), updatedAt: z.string()}); export const filesFolderActionResponse = z.object({completedAt: z.string(), errors: z.array(standardError).optional(), links: z.record(z.string(), z.string()).optional(), numErrors: z.number().int().optional(), requestedAt: z.string().optional(), result: filesFolder.optional(), startedAt: z.string(), status: z.enum(["CANCELED", "COMPLETE", "PENDING", "PROCESSING"]), taskId: z.string()}); 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 }; /** * Check folder update status * * GET /files/2026-03/folders/update/async/tasks/{taskId}/status * * Also accepts auth: developer_hapikey */ export const getApiFiles202603FoldersUpdateAsyncTasksTaskIdStatus = async (args: GetApiFiles202603FoldersUpdateAsyncTasksTaskIdStatusArgs, options?: GetApiFiles202603FoldersUpdateAsyncTasksTaskIdStatusOptions) => { const {baseUrl = "https://api.hubapi.com", fetch: fetchFn = fetch, privateApps} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (privateApps !== undefined) headers.set('authorization', `Bearer ${privateApps}`) const url = `${baseUrl.replace(/\/+$/, '')}/files/2026-03/folders/update/async/tasks/${encodeURIComponent(String(args.taskId))}/status${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(filesFolderActionResponse, await res.json()) };