import {z} from 'zod' export type GoogleCloudApihubV1CustomCuration = {curation?: string | undefined}; export type GoogleCloudApihubV1CurationConfig = {curationType?: ('CURATION_TYPE_UNSPECIFIED' | 'DEFAULT_CURATION_FOR_API_METADATA' | 'CUSTOM_CURATION_FOR_API_METADATA') | undefined, customCuration?: GoogleCloudApihubV1CustomCuration | undefined}; export type GoogleCloudApihubV1LastExecution = {endTime?: unknown | undefined, errorMessage?: string | undefined, result?: ('RESULT_UNSPECIFIED' | 'SUCCEEDED' | 'FAILED') | undefined, resultMetadata?: string | undefined, startTime?: unknown | undefined}; export type GoogleCloudApihubV1ExecutionStatus = {currentExecutionState?: ('CURRENT_EXECUTION_STATE_UNSPECIFIED' | 'RUNNING' | 'NOT_RUNNING') | undefined, lastExecution?: GoogleCloudApihubV1LastExecution | undefined}; export type GoogleCloudApihubV1ResourceConfig = {actionType?: ('ACTION_TYPE_UNSPECIFIED' | 'SYNC_METADATA' | 'SYNC_RUNTIME_DATA') | undefined, pubsubTopic?: string | undefined}; export type GoogleCloudApihubV1PluginInstanceAction = {actionId?: string | undefined, curationConfig?: GoogleCloudApihubV1CurationConfig | undefined, hubInstanceAction?: GoogleCloudApihubV1ExecutionStatus | undefined, resourceConfig?: GoogleCloudApihubV1ResourceConfig | undefined, scheduleCronExpression?: string | undefined, scheduleTimeZone?: string | undefined, serviceAccount?: string | undefined, state?: ('STATE_UNSPECIFIED' | 'ENABLED' | 'DISABLED' | 'ENABLING' | 'DISABLING' | 'ERROR') | undefined}; export type GoogleCloudApihubV1ConfigValueOption = {description?: string | undefined, displayName?: string | undefined, id?: string | undefined}; export type GoogleCloudApihubV1MultiIntValues = {values?: Array | undefined}; export type GoogleCloudApihubV1MultiSelectValues = {values?: Array | undefined}; export type GoogleCloudApihubV1MultiStringValues = {values?: Array | undefined}; export type GoogleCloudApihubV1Secret = {secretVersion?: string | undefined}; export type GoogleCloudApihubV1ConfigVariable = {boolValue?: boolean | undefined, enumValue?: GoogleCloudApihubV1ConfigValueOption | undefined, intValue?: unknown | undefined, key?: string | undefined, multiIntValues?: GoogleCloudApihubV1MultiIntValues | undefined, multiSelectValues?: GoogleCloudApihubV1MultiSelectValues | undefined, multiStringValues?: GoogleCloudApihubV1MultiStringValues | undefined, secretValue?: GoogleCloudApihubV1Secret | undefined, stringValue?: string | undefined}; export type GoogleCloudApihubV1ApiKeyConfig = {apiKey?: GoogleCloudApihubV1Secret | undefined, httpElementLocation?: ('HTTP_ELEMENT_LOCATION_UNSPECIFIED' | 'QUERY' | 'HEADER' | 'PATH' | 'BODY' | 'COOKIE') | undefined, name?: string | undefined}; export type GoogleCloudApihubV1GoogleServiceAccountConfig = {serviceAccount?: string | undefined}; export type GoogleCloudApihubV1Oauth2ClientCredentialsConfig = {clientId?: string | undefined, clientSecret?: GoogleCloudApihubV1Secret | undefined}; export type GoogleCloudApihubV1UserPasswordConfig = {password?: GoogleCloudApihubV1Secret | undefined, username?: string | undefined}; export type GoogleCloudApihubV1AuthConfig = {apiKeyConfig?: GoogleCloudApihubV1ApiKeyConfig | undefined, authType?: ('AUTH_TYPE_UNSPECIFIED' | 'NO_AUTH' | 'GOOGLE_SERVICE_ACCOUNT' | 'USER_PASSWORD' | 'API_KEY' | 'OAUTH2_CLIENT_CREDENTIALS') | undefined, googleServiceAccountConfig?: GoogleCloudApihubV1GoogleServiceAccountConfig | undefined, oauth2ClientCredentialsConfig?: GoogleCloudApihubV1Oauth2ClientCredentialsConfig | undefined, userPasswordConfig?: GoogleCloudApihubV1UserPasswordConfig | undefined}; export type GoogleCloudApihubV1SourceEnvironment = {createTime?: unknown | undefined, sourceEnvironment?: string | undefined, sourceEnvironmentUri?: string | undefined, updateTime?: unknown | undefined}; export type GoogleCloudApihubV1PluginInstance = {actions?: Array | undefined, additionalConfig?: {[key: string]: GoogleCloudApihubV1ConfigVariable} | undefined, authConfig?: GoogleCloudApihubV1AuthConfig | undefined, createTime?: unknown | undefined, displayName?: string | undefined, errorMessage?: string | undefined, name?: string | undefined, sourceEnvironmentsConfig?: {[key: string]: GoogleCloudApihubV1SourceEnvironment} | undefined, sourceProjectId?: string | undefined, state?: ('STATE_UNSPECIFIED' | 'CREATING' | 'ACTIVE' | 'APPLYING_CONFIG' | 'ERROR' | 'FAILED' | 'DELETING') | undefined, updateTime?: unknown | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdInstancesArgs = {projectsId: string, locationsId: string, pluginsId: string, pluginInstanceId?: string | undefined, body: GoogleCloudApihubV1PluginInstance}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdInstancesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleRpcStatus = z.object({code: z.number().int().optional(), details: z.array(z.record(z.string(), z.unknown())).optional(), message: z.string().optional()}); export const googleLongrunningOperation = z.object({done: z.boolean().optional(), error: googleRpcStatus.optional(), metadata: z.record(z.string(), z.unknown()).optional(), name: z.string().optional(), response: z.record(z.string(), z.unknown()).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 }; /** * Creates a Plugin instance in the API hub. * * POST /v1/projects/{projectsId}/locations/{locationsId}/plugins/{pluginsId}/instances * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdInstances = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdInstancesArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdPluginsPluginsIdInstancesOptions) => { 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.pluginInstanceId != null) query.append("pluginInstanceId", String(args.pluginInstanceId)) 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))}/instances${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(googleLongrunningOperation, await res.json()) };