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 GoogleCloudApihubV1DependencyEntityReference = {displayName?: string | undefined, externalApiResourceName?: string | undefined, operationResourceName?: string | undefined}; export type GoogleCloudApihubV1DependencyErrorDetail = {error?: ('ERROR_UNSPECIFIED' | 'SUPPLIER_NOT_FOUND' | 'SUPPLIER_RECREATED') | undefined, errorTime?: unknown | undefined}; export type GoogleCloudApihubV1Dependency = {attributes?: {[key: string]: GoogleCloudApihubV1AttributeValues} | undefined, consumer?: GoogleCloudApihubV1DependencyEntityReference | undefined, createTime?: unknown | undefined, description?: string | undefined, discoveryMode?: ('DISCOVERY_MODE_UNSPECIFIED' | 'MANUAL') | undefined, errorDetail?: GoogleCloudApihubV1DependencyErrorDetail | undefined, name?: string | undefined, state?: ('STATE_UNSPECIFIED' | 'PROPOSED' | 'VALIDATED') | undefined, supplier?: GoogleCloudApihubV1DependencyEntityReference | undefined, updateTime?: unknown | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDependenciesArgs = {projectsId: string, locationsId: string, dependencyId?: string | undefined, body: GoogleCloudApihubV1Dependency}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDependenciesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; 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 googleCloudApihubV1DependencyEntityReference = z.object({displayName: z.string().optional(), externalApiResourceName: z.string().optional(), operationResourceName: z.string().optional()}); export const googleCloudApihubV1DependencyErrorDetail = z.object({error: z.enum(["ERROR_UNSPECIFIED", "SUPPLIER_NOT_FOUND", "SUPPLIER_RECREATED"]).optional(), errorTime: z.string().optional()}); export const googleCloudApihubV1Dependency = z.object({attributes: z.record(z.string(), googleCloudApihubV1AttributeValues).optional(), consumer: googleCloudApihubV1DependencyEntityReference.optional(), createTime: z.string().optional(), description: z.string().optional(), discoveryMode: z.enum(["DISCOVERY_MODE_UNSPECIFIED", "MANUAL"]).optional(), errorDetail: googleCloudApihubV1DependencyErrorDetail.optional(), name: z.string().optional(), state: z.enum(["STATE_UNSPECIFIED", "PROPOSED", "VALIDATED"]).optional(), supplier: googleCloudApihubV1DependencyEntityReference.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 a dependency between two entities in the API hub. * * POST /v1/projects/{projectsId}/locations/{locationsId}/dependencies * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdDependencies = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDependenciesArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDependenciesOptions) => { 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.dependencyId != null) query.append("dependencyId", String(args.dependencyId)) 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))}/dependencies${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(googleCloudApihubV1Dependency, await res.json()) };