import {z} from 'zod' export type GetApiProjectsProjectGlobalPublicDelegatedPrefixesPublicDelegatedPrefixArgs = {project: string, publicDelegatedPrefix: string}; export type GetApiProjectsProjectGlobalPublicDelegatedPrefixesPublicDelegatedPrefixOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const publicDelegatedPrefixPublicDelegatedSubPrefix = z.object({allocatablePrefixLength: z.number().int().optional(), delegateeProject: z.string().optional(), description: z.string().optional(), enableEnhancedIpv4Allocation: z.boolean().optional(), ipCidrRange: z.string().optional(), ipv6AccessType: z.enum(["EXTERNAL", "INTERNAL"]).optional(), isAddress: z.boolean().optional(), mode: z.enum(["DELEGATION", "EXTERNAL_IPV6_FORWARDING_RULE_CREATION", "EXTERNAL_IPV6_SUBNETWORK_CREATION", "INTERNAL_IPV6_SUBNETWORK_CREATION"]).optional(), name: z.string().optional(), region: z.string().optional(), status: z.enum(["ACTIVE", "INACTIVE"]).optional()}); export const publicDelegatedPrefix = z.object({allocatablePrefixLength: z.number().int().optional(), byoipApiVersion: z.enum(["V1", "V2"]).optional(), creationTimestamp: z.string().optional(), description: z.string().optional(), enableEnhancedIpv4Allocation: z.boolean().optional(), fingerprint: z.string().optional(), id: z.string().optional(), ipCidrRange: z.string().optional(), ipv6AccessType: z.enum(["EXTERNAL", "INTERNAL"]).optional(), isLiveMigration: z.boolean().optional(), kind: z.string().optional(), mode: z.enum(["DELEGATION", "EXTERNAL_IPV6_FORWARDING_RULE_CREATION", "EXTERNAL_IPV6_SUBNETWORK_CREATION", "INTERNAL_IPV6_SUBNETWORK_CREATION"]).optional(), name: z.string().optional(), parentPrefix: z.string().optional(), publicDelegatedSubPrefixs: z.array(publicDelegatedPrefixPublicDelegatedSubPrefix).optional(), region: z.string().optional(), selfLink: z.string().optional(), status: z.enum(["ACTIVE", "ANNOUNCED", "ANNOUNCED_TO_GOOGLE", "ANNOUNCED_TO_INTERNET", "DELETING", "INITIALIZING", "READY_TO_ANNOUNCE"]).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 }; /** * Returns the specified global PublicDelegatedPrefix resource. * * GET /projects/{project}/global/publicDelegatedPrefixes/{publicDelegatedPrefix} * * Also accepts auth: Oauth2 + Oauth2c, Oauth2 + Oauth2c */ export const getApiProjectsProjectGlobalPublicDelegatedPrefixesPublicDelegatedPrefix = async (args: GetApiProjectsProjectGlobalPublicDelegatedPrefixesPublicDelegatedPrefixArgs, options?: GetApiProjectsProjectGlobalPublicDelegatedPrefixesPublicDelegatedPrefixOptions) => { const {baseUrl = "https://compute.googleapis.com/compute/v1", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project))}/global/publicDelegatedPrefixes/${encodeURIComponent(String(args.publicDelegatedPrefix))}${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(publicDelegatedPrefix, await res.json()) };