import {z} from 'zod' export type GetApiEnvIdFlowIdTenantJobsArgs = {env_id: string, flow_id: string, tenant: string, count?: number | undefined, scheduled?: boolean | undefined, job_type?: ('read' | 'write') | undefined, page?: number | undefined, from?: string | undefined, to?: string | undefined, include_state?: boolean | undefined, include_export_details?: boolean | undefined, ignore_empty_jobs?: boolean | undefined, sync_type?: ('incremental_sync' | 'auto_sync' | 'full_sync' | 'real_time_sync') | undefined}; export type GetApiEnvIdFlowIdTenantJobsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiEnvIdFlowIdTenantJobsResponse = z.array(z.object({job_id: z.string().optional(), env_id: z.string().optional(), job_name: z.string().optional(), tenant: z.string().optional(), started_by: z.string().optional(), flow: z.string().optional(), s3_root: z.string().optional(), start_time: z.string().optional(), state: z.object({}).optional(), tap: z.string().optional(), status: z.enum(["JOB_CREATED", "PROVISION_FAILED", "DISCOVER_STARTED", "DISCOVER_SUCCESS", "DISCOVER_FAILED", "SYNC_STARTED", "SYNC_FAILED", "SYNC_SUCCESS", "ETL_STARTED", "ETL_FAILED", "ETL_SUCCESS", "EXPORT_STARTED", "EXPORT_FAILED", "JOB_COMPLETED"]).optional(), message: z.string().optional(), last_updated: 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 }; /** * Fetch jobs * * GET /{env_id}/{flow_id}/{tenant}/jobs */ export const getApiEnvIdFlowIdTenantJobs = async (args: GetApiEnvIdFlowIdTenantJobsArgs, options?: GetApiEnvIdFlowIdTenantJobsOptions) => { 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.scheduled != null) query.append("scheduled", String(args.scheduled)) if (args.job_type != null) query.append("job_type", String(args.job_type)) if (args.page != null) query.append("page", String(args.page)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.include_state != null) query.append("include_state", String(args.include_state)) if (args.include_export_details != null) query.append("include_export_details", String(args.include_export_details)) if (args.ignore_empty_jobs != null) query.append("ignore_empty_jobs", String(args.ignore_empty_jobs)) if (args.sync_type != null) query.append("sync_type", String(args.sync_type)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.env_id))}/${encodeURIComponent(String(args.flow_id))}/${encodeURIComponent(String(args.tenant))}/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(getApiEnvIdFlowIdTenantJobsResponse, await res.json()) };