import {z} from 'zod' export type GetApiV1b3ProjectsProjectIdLocationsLocationTemplatesGetArgs = {projectId: string, location: string, gcsPath?: string | undefined, view?: 'METADATA_ONLY' | undefined}; export type GetApiV1b3ProjectsProjectIdLocationsLocationTemplatesGetOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const parameterMetadataEnumOption = z.object({description: z.string().optional(), label: z.string().optional(), value: z.string().optional()}); export const parameterMetadata = z.object({customMetadata: z.record(z.string(), z.string()).optional(), defaultValue: z.string().optional(), enumOptions: z.array(parameterMetadataEnumOption).optional(), groupName: z.string().optional(), helpText: z.string().optional(), hiddenUi: z.boolean().optional(), isOptional: z.boolean().optional(), label: z.string().optional(), name: z.string().optional(), paramType: z.enum(["DEFAULT", "TEXT", "GCS_READ_BUCKET", "GCS_WRITE_BUCKET", "GCS_READ_FILE", "GCS_WRITE_FILE", "GCS_READ_FOLDER", "GCS_WRITE_FOLDER", "PUBSUB_TOPIC", "PUBSUB_SUBSCRIPTION", "BIGQUERY_TABLE", "JAVASCRIPT_UDF_FILE", "SERVICE_ACCOUNT", "MACHINE_TYPE", "KMS_KEY_NAME", "WORKER_REGION", "WORKER_ZONE", "BOOLEAN", "ENUM", "NUMBER", "KAFKA_TOPIC", "KAFKA_READ_TOPIC", "KAFKA_WRITE_TOPIC"]).optional(), parentName: z.string().optional(), parentTriggerValues: z.array(z.string()).optional(), regexes: z.array(z.string()).optional()}); export const templateMetadata = z.object({defaultStreamingMode: z.string().optional(), description: z.string().optional(), name: z.string().optional(), parameters: z.array(parameterMetadata).optional(), streaming: z.boolean().optional(), supportsAtLeastOnce: z.boolean().optional(), supportsExactlyOnce: z.boolean().optional(), yamlDefinition: z.string().optional()}); export const sDKInfo = z.object({language: z.enum(["UNKNOWN", "JAVA", "PYTHON", "GO", "YAML"]).optional(), version: z.string().optional()}); export const runtimeMetadata = z.object({parameters: z.array(parameterMetadata).optional(), sdkInfo: sDKInfo.optional()}); export const status = z.object({code: z.number().int().optional(), details: z.array(z.record(z.string(), z.unknown())).optional(), message: z.string().optional()}); export const getTemplateResponse = z.object({metadata: templateMetadata.optional(), runtimeMetadata: runtimeMetadata.optional(), status: status.optional(), templateType: z.enum(["UNKNOWN", "LEGACY", "FLEX"]).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 }; /** * Get the template associated with a template. To get the template, we recommend using `projects.locations.templates.get` with a [regional endpoint] (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). Using `projects.templates.get` is not recommended, because only templates that are running in `us-central1` are retrieved. # IAM Permissions Requires the `resourcemanager.projects.get` permission on the project. * * GET /v1b3/projects/{projectId}/locations/{location}/templates:get * * Also accepts auth: Oauth2 + Oauth2c */ export const getApiV1b3ProjectsProjectIdLocationsLocationTemplatesGet = async (args: GetApiV1b3ProjectsProjectIdLocationsLocationTemplatesGetArgs, options?: GetApiV1b3ProjectsProjectIdLocationsLocationTemplatesGetOptions) => { 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.gcsPath != null) query.append("gcsPath", String(args.gcsPath)) if (args.view != null) query.append("view", String(args.view)) 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))}/locations/${encodeURIComponent(String(args.location))}/templates:get${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(getTemplateResponse, await res.json()) };