import {z} from 'zod' 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 GoogleCloudApihubV1Documentation = {externalUri?: string | undefined}; export type GoogleCloudApihubV1Owner = {displayName?: string | undefined, email?: string | undefined}; export type GoogleCloudApihubV1PluginInstanceActionSource = {actionId?: string | undefined, pluginInstance?: string | undefined}; export type GoogleCloudApihubV1SourceMetadata = {originalResourceCreateTime?: unknown | undefined, originalResourceId?: string | undefined, originalResourceUpdateTime?: unknown | undefined, pluginInstanceActionSource?: GoogleCloudApihubV1PluginInstanceActionSource | undefined, sourceType?: ('SOURCE_TYPE_UNSPECIFIED' | 'PLUGIN') | undefined}; export type GoogleCloudApihubV1Api = {apiFunctionalRequirements?: GoogleCloudApihubV1AttributeValues | undefined, apiRequirements?: GoogleCloudApihubV1AttributeValues | undefined, apiStyle?: GoogleCloudApihubV1AttributeValues | undefined, apiTechnicalRequirements?: GoogleCloudApihubV1AttributeValues | undefined, attributes?: {[key: string]: GoogleCloudApihubV1AttributeValues} | undefined, businessUnit?: GoogleCloudApihubV1AttributeValues | undefined, createTime?: unknown | undefined, description?: string | undefined, displayName?: string | undefined, documentation?: GoogleCloudApihubV1Documentation | undefined, fingerprint?: string | undefined, maturityLevel?: GoogleCloudApihubV1AttributeValues | undefined, name?: string | undefined, owner?: GoogleCloudApihubV1Owner | undefined, selectedVersion?: string | undefined, serviceType?: GoogleCloudApihubV1AttributeValues | undefined, sourceMetadata?: Array | undefined, targetUser?: GoogleCloudApihubV1AttributeValues | undefined, team?: GoogleCloudApihubV1AttributeValues | undefined, updateTime?: unknown | undefined, versions?: Array | undefined}; export type GoogleCloudApihubV1Deployment = {apiOperations?: Array | undefined, apiVersions?: Array | undefined, attributes?: {[key: string]: GoogleCloudApihubV1AttributeValues} | undefined, createTime?: unknown | undefined, deploymentType?: GoogleCloudApihubV1AttributeValues | undefined, description?: string | undefined, displayName?: string | undefined, documentation?: GoogleCloudApihubV1Documentation | undefined, endpoints?: Array | undefined, environment?: GoogleCloudApihubV1AttributeValues | undefined, managementUrl?: GoogleCloudApihubV1AttributeValues | undefined, name?: string | undefined, resourceUri?: string | undefined, slo?: GoogleCloudApihubV1AttributeValues | undefined, sourceEnvironment?: string | undefined, sourceMetadata?: Array | undefined, sourceProject?: string | undefined, sourceRevision?: string | undefined, sourceUri?: GoogleCloudApihubV1AttributeValues | undefined, specs?: Array | undefined, updateTime?: unknown | undefined}; export type GoogleCloudApihubV1DeploymentMetadata = {deployment?: GoogleCloudApihubV1Deployment | undefined, originalCreateTime?: unknown | undefined, originalId?: string | undefined, originalUpdateTime?: unknown | undefined}; export type GoogleCloudApihubV1SpecContents = {contents?: string | undefined, mimeType?: string | undefined}; export type GoogleCloudApihubV1AdditionalSpecContent = {createTime?: unknown | undefined, labels?: {[key: string]: string} | undefined, specContentType?: ('SPEC_CONTENT_TYPE_UNSPECIFIED' | 'BOOSTED_SPEC_CONTENT' | 'GATEWAY_OPEN_API_SPEC') | undefined, specContents?: GoogleCloudApihubV1SpecContents | undefined, updateTime?: unknown | undefined}; export type GoogleCloudApihubV1OpenApiSpecDetails = {format?: ('FORMAT_UNSPECIFIED' | 'OPEN_API_SPEC_2_0' | 'OPEN_API_SPEC_3_0' | 'OPEN_API_SPEC_3_1') | undefined, owner?: GoogleCloudApihubV1Owner | undefined, version?: string | undefined}; export type GoogleCloudApihubV1SpecDetails = {description?: string | undefined, openApiSpecDetails?: GoogleCloudApihubV1OpenApiSpecDetails | undefined}; export type GoogleCloudApihubV1Point = {character?: number | undefined, line?: number | undefined}; export type GoogleCloudApihubV1Range = {end?: GoogleCloudApihubV1Point | undefined, start?: GoogleCloudApihubV1Point | undefined}; export type GoogleCloudApihubV1Issue = {code?: string | undefined, message?: string | undefined, path?: Array | undefined, range?: GoogleCloudApihubV1Range | undefined, severity?: ('SEVERITY_UNSPECIFIED' | 'SEVERITY_ERROR' | 'SEVERITY_WARNING' | 'SEVERITY_INFO' | 'SEVERITY_HINT') | undefined}; export type GoogleCloudApihubV1SummaryEntry = {count?: number | undefined, severity?: ('SEVERITY_UNSPECIFIED' | 'SEVERITY_ERROR' | 'SEVERITY_WARNING' | 'SEVERITY_INFO' | 'SEVERITY_HINT') | undefined}; export type GoogleCloudApihubV1LintResponse = {createTime?: unknown | undefined, issues?: Array | undefined, linter?: ('LINTER_UNSPECIFIED' | 'SPECTRAL' | 'OTHER') | undefined, source?: string | undefined, state?: ('LINT_STATE_UNSPECIFIED' | 'LINT_STATE_SUCCESS' | 'LINT_STATE_ERROR') | undefined, summary?: Array | undefined}; export type GoogleCloudApihubV1Spec = {additionalSpecContents?: Array | undefined, attributes?: {[key: string]: GoogleCloudApihubV1AttributeValues} | undefined, contents?: GoogleCloudApihubV1SpecContents | undefined, createTime?: unknown | undefined, deployments?: Array | undefined, details?: GoogleCloudApihubV1SpecDetails | undefined, displayName?: string | undefined, documentation?: GoogleCloudApihubV1Documentation | undefined, lintResponse?: GoogleCloudApihubV1LintResponse | undefined, name?: string | undefined, parsingMode?: ('PARSING_MODE_UNSPECIFIED' | 'RELAXED' | 'STRICT') | undefined, sourceMetadata?: Array | undefined, sourceUri?: string | undefined, specType?: GoogleCloudApihubV1AttributeValues | undefined, updateTime?: unknown | undefined}; export type GoogleCloudApihubV1SpecMetadata = {deploymentResourceUris?: Array | undefined, originalCreateTime?: unknown | undefined, originalId?: string | undefined, originalUpdateTime?: unknown | undefined, spec?: GoogleCloudApihubV1Spec | undefined}; export type GoogleCloudApihubV1Version = {accreditation?: GoogleCloudApihubV1AttributeValues | undefined, apiOperations?: Array | undefined, attributes?: {[key: string]: GoogleCloudApihubV1AttributeValues} | undefined, compliance?: GoogleCloudApihubV1AttributeValues | undefined, createTime?: unknown | undefined, definitions?: Array | undefined, deployments?: Array | undefined, description?: string | undefined, displayName?: string | undefined, documentation?: GoogleCloudApihubV1Documentation | undefined, lifecycle?: GoogleCloudApihubV1AttributeValues | undefined, name?: string | undefined, selectedDeployment?: string | undefined, sourceMetadata?: Array | undefined, specs?: Array | undefined, updateTime?: unknown | undefined}; export type GoogleCloudApihubV1VersionMetadata = {deployments?: Array | undefined, originalCreateTime?: unknown | undefined, originalId?: string | undefined, originalUpdateTime?: unknown | undefined, specs?: Array | undefined, version?: GoogleCloudApihubV1Version | undefined}; export type GoogleCloudApihubV1APIMetadata = {api?: GoogleCloudApihubV1Api | undefined, originalCreateTime?: unknown | undefined, originalId?: string | undefined, originalUpdateTime?: unknown | undefined, versions?: Array | undefined}; export type GoogleCloudApihubV1ApiMetadataList = {apiMetadata?: Array | undefined}; export type GoogleCloudApihubV1ApiData = {apiMetadataList?: GoogleCloudApihubV1ApiMetadataList | undefined}; export type GoogleCloudApihubV1CollectApiDataRequest = {actionId?: string | undefined, apiData?: GoogleCloudApihubV1ApiData | undefined, collectionType?: ('COLLECTION_TYPE_UNSPECIFIED' | 'COLLECTION_TYPE_UPSERT' | 'COLLECTION_TYPE_DELETE') | undefined, pluginInstance?: string | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdCollectApiDataArgs = {projectsId: string, locationsId: string, body: GoogleCloudApihubV1CollectApiDataRequest}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdCollectApiDataOptions = {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 }; /** * Collect API data from a source and push it to Hub's collect layer. * * POST /v1/projects/{projectsId}/locations/{locationsId}:collectApiData * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdCollectApiData = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdCollectApiDataArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdCollectApiDataOptions) => { 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))}:collectApiData${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()) };