import {z} from 'zod' export type ExportFileRequestPublic = {title?: string | undefined, description?: string | undefined, filePassword?: string | undefined, sftpUrl?: string | undefined, sftpUsername?: string | undefined, sftpPassword?: string | undefined, emailResultsTo?: Array | undefined, limit?: number | undefined, skip?: number | undefined}; export type CreateApiApiJobsChainExportArgs = {chain: string, body: ExportFileRequestPublic}; export type CreateApiApiJobsChainExportOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const jsonNodePublic = z.unknown(); export const jobResultsPublic = z.object({results: z.object({}).optional(), error: jsonNodePublic.optional(), errorString: z.string().optional(), errorStrings: z.array(z.string()).optional()}); export const exportDownloadJobPublic = z.object({jobId: z.string(), name: z.string().min(1), status: z.enum(["NEW", "QUEUED", "RUNNING", "CANCELLED", "COMPLETED_ERROR", "COMPLETED_SUCCESS", "INCOMPLETE_ERROR"]), jobCreated: z.string(), jobQueued: z.string().optional(), jobStarted: z.string().optional(), jobCompleted: z.string().optional(), emailRecipients: z.array(z.string()).optional(), timeout: z.number().int().optional(), timeoutUnit: z.enum(["NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS", "DAYS"]), results: jobResultsPublic.optional(), customerName: z.string().min(1), sdzName: z.string().min(1), effectiveId: z.string(), loggedInId: z.string(), mdc: z.record(z.string(), z.string()), fileType: z.enum(["CSV", "PIPE", "TAB", "XLS", "XLSX", "XLSM", "EDI", "JSON", "XML", "PARQUET", "SPSS"]).optional(), title: z.string().optional(), description: z.string().optional(), password: z.string().optional(), sftpUrl: z.string().optional(), sftpUsername: z.string().optional(), sftpPassword: z.string().optional(), key: z.string().optional(), tql: z.string().optional(), dictName: 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 }; /** * Allowed user roles:
  • sdzReadOnly
  • sdzUser


Exports data from a single chain and produces a JSON file, caller can request skip/limit of data for pagination of results always ordered by SDO ID; can be SFTP'ed or downloaded as an async job. * * POST /api/jobs/{chain}/export */ export const createApiApiJobsChainExport = async (args: CreateApiApiJobsChainExportArgs, options?: CreateApiApiJobsChainExportOptions) => { const {baseUrl = "https://api.burstiq.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/jobs/${encodeURIComponent(String(args.chain))}/export${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(exportDownloadJobPublic, await res.json()) };