import {z} from 'zod' export type GetApiEnvIdJobsArgs = {env_id: string, count?: number | undefined, page?: number | undefined, status?: ('JOB_CREATED' | 'DISCOVER_STARTED' | 'DISCOVER_FAILED' | 'SYNC_STARTED' | 'SYNC_FAILED' | 'SYNC_SUCCESS' | 'ETL_STARTED' | 'ETL_FAILED' | 'ETL_SUCCESS' | 'EXPORT_STARTED' | 'EXPORT_FAILED' | 'JOB_COMPLETED') | undefined, taps?: string | undefined, targets?: string | undefined, from?: string | undefined, to?: string | undefined, tenant?: string | undefined, include_export_details?: boolean | undefined, sync_type?: ('incremental_sync' | 'auto_sync' | 'full_sync' | 'real_time_sync') | undefined, ignore_empty_jobs?: boolean | undefined}; export type GetApiEnvIdJobsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiEnvIdJobsResponse = z.object({}); 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 }; /** * Advanced Job Query * * GET /{env_id}/jobs */ export const getApiEnvIdJobs = async (args: GetApiEnvIdJobsArgs, options?: GetApiEnvIdJobsOptions) => { const {baseUrl = "https://api.hotglue.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.count != null) query.append("count", String(args.count)) if (args.page != null) query.append("page", String(args.page)) if (args.status != null) query.append("status", String(args.status)) if (args.taps != null) query.append("taps", String(args.taps)) if (args.targets != null) query.append("targets", String(args.targets)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.tenant != null) query.append("tenant", String(args.tenant)) if (args.include_export_details != null) query.append("include_export_details", String(args.include_export_details)) if (args.sync_type != null) query.append("sync_type", String(args.sync_type)) if (args.ignore_empty_jobs != null) query.append("ignore_empty_jobs", String(args.ignore_empty_jobs)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.env_id))}/jobs${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(getApiEnvIdJobsResponse, await res.json()) };