import {z} from 'zod' export type GetApiV1ProjectsProjectsIdLocationsLocationsIdAddonsAddonsIdArgs = {projectsId: string, locationsId: string, addonsId: string}; export type GetApiV1ProjectsProjectsIdLocationsLocationsIdAddonsAddonsIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudApihubV1AllDataAddonConfig = z.object({enabled: z.boolean().optional()}); export const googleCloudApihubV1EnvironmentFilter = z.object({allEnvironments: z.boolean().optional(), environments: z.array(z.string()).optional()}); export const googleCloudApihubV1ApigeeEdgeConfig = z.object({environmentFilter: googleCloudApihubV1EnvironmentFilter.optional()}); export const googleCloudApihubV1ApigeeOPDKConfig = z.object({environmentFilter: googleCloudApihubV1EnvironmentFilter.optional()}); export const googleCloudApihubV1ApigeeXHybridConfig = z.object({environmentFilter: googleCloudApihubV1EnvironmentFilter.optional()}); export const googleCloudApihubV1GatewayPluginConfig = z.object({apigeeEdgeConfig: googleCloudApihubV1ApigeeEdgeConfig.optional(), apigeeOpdkConfig: googleCloudApihubV1ApigeeOPDKConfig.optional(), apigeeXHybridConfig: googleCloudApihubV1ApigeeXHybridConfig.optional(), pluginInstance: z.string().optional()}); export const googleCloudApihubV1GatewayPluginAddonConfig = z.object({gatewayPluginConfigs: z.array(googleCloudApihubV1GatewayPluginConfig).optional()}); export const googleCloudApihubV1AddonConfig = z.object({allDataAddonConfig: googleCloudApihubV1AllDataAddonConfig.optional(), gatewayPluginAddonConfig: googleCloudApihubV1GatewayPluginAddonConfig.optional()}); export const googleCloudApihubV1Addon = z.object({boostSpecGeminiRegionId: z.string().optional(), config: googleCloudApihubV1AddonConfig.optional(), createTime: z.string().optional(), dataSource: z.enum(["DATA_SOURCE_UNSPECIFIED", "PLUGIN_INSTANCE", "ALL_DATA"]).optional(), description: z.string().optional(), displayName: z.string().optional(), name: z.string().optional(), state: z.enum(["ADDON_STATE_UNSPECIFIED", "ACTIVE", "UPDATING", "ERROR", "INACTIVE"]).optional(), updateTime: 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 }; /** * Get an addon. * * GET /v1/projects/{projectsId}/locations/{locationsId}/addons/{addonsId} * * Also accepts auth: Oauth2 + Oauth2c, Oauth2 + Oauth2c */ export const getApiV1ProjectsProjectsIdLocationsLocationsIdAddonsAddonsId = async (args: GetApiV1ProjectsProjectsIdLocationsLocationsIdAddonsAddonsIdArgs, options?: GetApiV1ProjectsProjectsIdLocationsLocationsIdAddonsAddonsIdOptions) => { const {baseUrl = "https://apihub.googleapis.com", 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(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/addons/${encodeURIComponent(String(args.addonsId))}${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(googleCloudApihubV1Addon, await res.json()) };