import {z} from 'zod' export type CreateApiApiJobsDbschemaArgs = {delete: boolean, emailResultsTo?: Array | undefined, body: BodyInit}; export type CreateApiApiJobsDbschemaOptions = {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 dbSchemaUploadJobPublic = 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()), originalFilename: z.string().optional(), key: z.string().optional(), delete: z.boolean().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:
  • sdzAdmin


loads a dbschema (.dbs) XML file into the secure data zone; if delete is true any dictionaries in the SDZ not specified in the DbSchema file will be dropped * * POST /api/jobs/dbschema */ export const createApiApiJobsDbschema = async (args: CreateApiApiJobsDbschemaArgs, options?: CreateApiApiJobsDbschemaOptions) => { const {baseUrl = "https://api.burstiq.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.delete != null) query.append("delete", String(args.delete)) for (const item of args.emailResultsTo ?? []) query.append("emailResultsTo", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/api/jobs/dbschema${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(dbSchemaUploadJobPublic, await res.json()) };