import {z} from 'zod' export type GetApiV1b3ProjectsProjectIdJobsJobIdMessagesArgs = {projectId: string, jobId: string, endTime?: unknown | undefined, location?: string | undefined, minimumImportance?: ('JOB_MESSAGE_IMPORTANCE_UNKNOWN' | 'JOB_MESSAGE_DEBUG' | 'JOB_MESSAGE_DETAILED' | 'JOB_MESSAGE_BASIC' | 'JOB_MESSAGE_WARNING' | 'JOB_MESSAGE_ERROR') | undefined, pageSize?: number | undefined, pageToken?: string | undefined, startTime?: unknown | undefined}; export type GetApiV1b3ProjectsProjectIdJobsJobIdMessagesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const parameter = z.object({key: z.string().optional(), value: z.unknown()}); export const structuredMessage = z.object({messageKey: z.string().optional(), messageText: z.string().optional(), parameters: z.array(parameter).optional()}); export const autoscalingEvent = z.object({currentNumWorkers: z.string().optional(), description: structuredMessage.optional(), eventType: z.enum(["TYPE_UNKNOWN", "TARGET_NUM_WORKERS_CHANGED", "CURRENT_NUM_WORKERS_CHANGED", "ACTUATION_FAILURE", "NO_CHANGE"]).optional(), targetNumWorkers: z.string().optional(), time: z.string().optional(), workerPool: z.string().optional()}); export const jobMessage = z.object({id: z.string().optional(), messageImportance: z.enum(["JOB_MESSAGE_IMPORTANCE_UNKNOWN", "JOB_MESSAGE_DEBUG", "JOB_MESSAGE_DETAILED", "JOB_MESSAGE_BASIC", "JOB_MESSAGE_WARNING", "JOB_MESSAGE_ERROR"]).optional(), messageText: z.string().optional(), time: z.string().optional()}); export const listJobMessagesResponse = z.object({autoscalingEvents: z.array(autoscalingEvent).optional(), jobMessages: z.array(jobMessage).optional(), nextPageToken: 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 }; /** * Request the job status. To request the status of a job, we recommend using `projects.locations.jobs.messages.list` with a [regional endpoint] (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). Using `projects.jobs.messages.list` is not recommended, as you can only request the status of jobs that are running in `us-central1`. # IAM Permissions Requires the `dataflow.messages.list` permission on the job. * * GET /v1b3/projects/{projectId}/jobs/{jobId}/messages * * Also accepts auth: Oauth2 + Oauth2c */ export const getApiV1b3ProjectsProjectIdJobsJobIdMessages = async (args: GetApiV1b3ProjectsProjectIdJobsJobIdMessagesArgs, options?: GetApiV1b3ProjectsProjectIdJobsJobIdMessagesOptions) => { const {baseUrl = "https://dataflow.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.endTime != null) query.append("endTime", String(args.endTime)) if (args.location != null) query.append("location", String(args.location)) if (args.minimumImportance != null) query.append("minimumImportance", String(args.minimumImportance)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.startTime != null) query.append("startTime", String(args.startTime)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1b3/projects/${encodeURIComponent(String(args.projectId))}/jobs/${encodeURIComponent(String(args.jobId))}/messages${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(listJobMessagesResponse, await res.json()) };