import {z} from 'zod' export type GoogleCloudApihubV1PluginActionConfig = {description?: string | undefined, displayName?: string | undefined, id?: string | undefined, triggerMode?: ('TRIGGER_MODE_UNSPECIFIED' | 'API_HUB_ON_DEMAND_TRIGGER' | 'API_HUB_SCHEDULE_TRIGGER' | 'NON_API_HUB_MANAGED') | undefined}; export type GoogleCloudApihubV1ConfigValueOption = {description?: string | undefined, displayName?: string | undefined, id?: string | undefined}; export type GoogleCloudApihubV1ConfigVariableTemplate = {description?: string | undefined, enumOptions?: Array | undefined, id?: string | undefined, multiSelectOptions?: Array | undefined, required?: boolean | undefined, validationRegex?: string | undefined, valueType?: ('VALUE_TYPE_UNSPECIFIED' | 'STRING' | 'INT' | 'BOOL' | 'SECRET' | 'ENUM' | 'MULTI_SELECT' | 'MULTI_STRING' | 'MULTI_INT') | undefined}; export type GoogleCloudApihubV1GoogleServiceAccountConfig = {serviceAccount?: string | undefined}; export type GoogleCloudApihubV1AuthConfigTemplate = {serviceAccount?: GoogleCloudApihubV1GoogleServiceAccountConfig | undefined, supportedAuthTypes?: (Array<'AUTH_TYPE_UNSPECIFIED' | 'NO_AUTH' | 'GOOGLE_SERVICE_ACCOUNT' | 'USER_PASSWORD' | 'API_KEY' | 'OAUTH2_CLIENT_CREDENTIALS'>) | undefined}; export type GoogleCloudApihubV1ConfigTemplate = {additionalConfigTemplate?: Array | undefined, authConfigTemplate?: GoogleCloudApihubV1AuthConfigTemplate | undefined}; export type GoogleCloudApihubV1Documentation = {externalUri?: string | undefined}; export type GoogleCloudApihubV1HostingService = {serviceUri?: string | undefined}; export type GoogleCloudApihubV1AllowedValue = {description?: string | undefined, displayName?: string | undefined, id?: string | undefined, immutable?: boolean | undefined}; export type GoogleCloudApihubV1EnumAttributeValues = {values?: Array | undefined}; export type GoogleCloudApihubV1StringAttributeValues = {values?: Array | undefined}; export type GoogleCloudApihubV1AttributeValues = {attribute?: string | undefined, enumValues?: GoogleCloudApihubV1EnumAttributeValues | undefined, jsonValues?: GoogleCloudApihubV1StringAttributeValues | undefined, stringValues?: GoogleCloudApihubV1StringAttributeValues | undefined, uriValues?: GoogleCloudApihubV1StringAttributeValues | undefined}; export type GoogleCloudApihubV1Plugin = {actionsConfig?: Array | undefined, configTemplate?: GoogleCloudApihubV1ConfigTemplate | undefined, createTime?: unknown | undefined, description?: string | undefined, displayName?: string | undefined, documentation?: GoogleCloudApihubV1Documentation | undefined, gatewayType?: ('GATEWAY_TYPE_UNSPECIFIED' | 'APIGEE_X_AND_HYBRID' | 'APIGEE_EDGE_PUBLIC_CLOUD' | 'APIGEE_EDGE_PRIVATE_CLOUD' | 'CLOUD_API_GATEWAY' | 'CLOUD_ENDPOINTS' | 'API_DISCOVERY' | 'OTHERS' | 'AWS_API_GATEWAY' | 'AZURE_API_MANAGEMENT') | undefined, hostingService?: GoogleCloudApihubV1HostingService | undefined, name?: string | undefined, ownershipType?: ('OWNERSHIP_TYPE_UNSPECIFIED' | 'SYSTEM_OWNED' | 'USER_OWNED') | undefined, pluginCategory?: ('PLUGIN_CATEGORY_UNSPECIFIED' | 'API_GATEWAY' | 'API_PRODUCER') | undefined, state?: ('STATE_UNSPECIFIED' | 'ENABLED' | 'DISABLED') | undefined, type?: GoogleCloudApihubV1AttributeValues | undefined, updateTime?: unknown | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsArgs = {projectsId: string, locationsId: string, pluginId?: string | undefined, body: GoogleCloudApihubV1Plugin}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudApihubV1PluginActionConfig = z.object({description: z.string().optional(), displayName: z.string().optional(), id: z.string().optional(), triggerMode: z.enum(["TRIGGER_MODE_UNSPECIFIED", "API_HUB_ON_DEMAND_TRIGGER", "API_HUB_SCHEDULE_TRIGGER", "NON_API_HUB_MANAGED"]).optional()}); export const googleCloudApihubV1ConfigValueOption = z.object({description: z.string().optional(), displayName: z.string().optional(), id: z.string().optional()}); export const googleCloudApihubV1ConfigVariableTemplate = z.object({description: z.string().optional(), enumOptions: z.array(googleCloudApihubV1ConfigValueOption).optional(), id: z.string().optional(), multiSelectOptions: z.array(googleCloudApihubV1ConfigValueOption).optional(), required: z.boolean().optional(), validationRegex: z.string().optional(), valueType: z.enum(["VALUE_TYPE_UNSPECIFIED", "STRING", "INT", "BOOL", "SECRET", "ENUM", "MULTI_SELECT", "MULTI_STRING", "MULTI_INT"]).optional()}); export const googleCloudApihubV1GoogleServiceAccountConfig = z.object({serviceAccount: z.string().optional()}); export const googleCloudApihubV1AuthConfigTemplate = z.object({serviceAccount: googleCloudApihubV1GoogleServiceAccountConfig.optional(), supportedAuthTypes: z.array(z.enum(["AUTH_TYPE_UNSPECIFIED", "NO_AUTH", "GOOGLE_SERVICE_ACCOUNT", "USER_PASSWORD", "API_KEY", "OAUTH2_CLIENT_CREDENTIALS"])).optional()}); export const googleCloudApihubV1ConfigTemplate = z.object({additionalConfigTemplate: z.array(googleCloudApihubV1ConfigVariableTemplate).optional(), authConfigTemplate: googleCloudApihubV1AuthConfigTemplate.optional()}); export const googleCloudApihubV1Documentation = z.object({externalUri: z.string().optional()}); export const googleCloudApihubV1HostingService = z.object({serviceUri: z.string().optional()}); export const googleCloudApihubV1AllowedValue = z.object({description: z.string().optional(), displayName: z.string().optional(), id: z.string().optional(), immutable: z.boolean().optional()}); export const googleCloudApihubV1EnumAttributeValues = z.object({values: z.array(googleCloudApihubV1AllowedValue).optional()}); export const googleCloudApihubV1StringAttributeValues = z.object({values: z.array(z.string()).optional()}); export const googleCloudApihubV1AttributeValues = z.object({attribute: z.string().optional(), enumValues: googleCloudApihubV1EnumAttributeValues.optional(), jsonValues: googleCloudApihubV1StringAttributeValues.optional(), stringValues: googleCloudApihubV1StringAttributeValues.optional(), uriValues: googleCloudApihubV1StringAttributeValues.optional()}); export const googleCloudApihubV1Plugin = z.object({actionsConfig: z.array(googleCloudApihubV1PluginActionConfig).optional(), configTemplate: googleCloudApihubV1ConfigTemplate.optional(), createTime: z.string().optional(), description: z.string().optional(), displayName: z.string().optional(), documentation: googleCloudApihubV1Documentation.optional(), gatewayType: z.enum(["GATEWAY_TYPE_UNSPECIFIED", "APIGEE_X_AND_HYBRID", "APIGEE_EDGE_PUBLIC_CLOUD", "APIGEE_EDGE_PRIVATE_CLOUD", "CLOUD_API_GATEWAY", "CLOUD_ENDPOINTS", "API_DISCOVERY", "OTHERS", "AWS_API_GATEWAY", "AZURE_API_MANAGEMENT"]).optional(), hostingService: googleCloudApihubV1HostingService.optional(), name: z.string().optional(), ownershipType: z.enum(["OWNERSHIP_TYPE_UNSPECIFIED", "SYSTEM_OWNED", "USER_OWNED"]).optional(), pluginCategory: z.enum(["PLUGIN_CATEGORY_UNSPECIFIED", "API_GATEWAY", "API_PRODUCER"]).optional(), state: z.enum(["STATE_UNSPECIFIED", "ENABLED", "DISABLED"]).optional(), type: googleCloudApihubV1AttributeValues.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 }; /** * Create an API Hub plugin resource in the API hub. Once a plugin is created, it can be used to create plugin instances. * * POST /v1/projects/{projectsId}/locations/{locationsId}/plugins * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdPlugins = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsOptions) => { const {baseUrl = "https://apihub.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.pluginId != null) query.append("pluginId", String(args.pluginId)) 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))}/plugins${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(googleCloudApihubV1Plugin, await res.json()) };