import {z} from 'zod' export type GetApiAudienceAudienceIdJobsArgs = {audienceId: string, page?: number | undefined, page_size?: number | undefined, sort?: (Array<'name' | '-name' | 'created_at' | '-created_at' | 'status' | '-status'>) | undefined, job_id?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, name?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, definition_id?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, status?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, created_at?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, logic?: ('and' | 'or') | undefined}; export type GetApiAudienceAudienceIdJobsOptions = {baseUrl?: string | undefined, OpenIdConnect?: string | undefined, fetch?: typeof fetch | undefined}; export const audienceJobState = z.enum(["Submitted", "Running", "Completed", "Failed", "ManualApproval", "Queued", "Paused", "StaleResults", "SpendLimited", "Blocked"]); export const queryAudienceJobsEndpointOutput = z.object({jobId: z.string(), name: z.string(), definitionId: z.string(), audienceId: z.string(), revisionNumber: z.number().int(), pipelineId: z.string(), state: audienceJobState, createdAt: z.string()}); export const queryAudienceJobsEndpointPagedResultOfOutput = z.object({total: z.number().int(), page: z.number().int(), pageSize: z.number().int(), items: z.array(queryAudienceJobsEndpointOutput), totalPages: z.number().int().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 }; /** * Queries jobs for the specified audience. * * GET /audience/{audienceId}/jobs * * Also accepts auth: OpenIdConnect */ export const getApiAudienceAudienceIdJobs = async (args: GetApiAudienceAudienceIdJobsArgs, options?: GetApiAudienceAudienceIdJobsOptions) => { const {baseUrl = "https://api.rapidata.ai", fetch: fetchFn = fetch, OpenIdConnect} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) for (const item of args.sort ?? []) query.append("sort", String(item)) if (args.job_id != null) query.append("job_id", JSON.stringify(args.job_id)) if (args.name != null) query.append("name", JSON.stringify(args.name)) if (args.definition_id != null) query.append("definition_id", JSON.stringify(args.definition_id)) if (args.status != null) query.append("status", JSON.stringify(args.status)) if (args.created_at != null) query.append("created_at", JSON.stringify(args.created_at)) if (args.logic != null) query.append("logic", String(args.logic)) if (OpenIdConnect !== undefined) headers.set('authorization', `Bearer ${OpenIdConnect}`) const url = `${baseUrl.replace(/\/+$/, '')}/audience/${encodeURIComponent(String(args.audienceId))}/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(queryAudienceJobsEndpointPagedResultOfOutput, await res.json()) };