import {z} from 'zod' export type GoogleCloudApihubV1EnablePluginRequest = Record; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdEnableArgs = {projectsId: string, locationsId: string, pluginsId: string, body: GoogleCloudApihubV1EnablePluginRequest}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdEnableOptions = {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 }; /** * Enables a plugin. The `state` of the plugin after enabling is `ENABLED` * * POST /v1/projects/{projectsId}/locations/{locationsId}/plugins/{pluginsId}:enable * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdEnable = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdEnableArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdEnableOptions) => { 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 (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/${encodeURIComponent(String(args.pluginsId))}:enable${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()) };