import {z} from 'zod' export type GoogleCloudDatacatalogV1CrossRegionalSource = {taxonomy?: string | undefined}; export type GoogleCloudDatacatalogV1SerializedPolicyTag = {childPolicyTags?: Array | undefined, description?: string | undefined, displayName?: string | undefined, policyTag?: string | undefined}; export type GoogleCloudDatacatalogV1SerializedTaxonomy = {activatedPolicyTypes?: (Array<'POLICY_TYPE_UNSPECIFIED' | 'FINE_GRAINED_ACCESS_CONTROL'>) | undefined, description?: string | undefined, displayName?: string | undefined, policyTags?: Array | undefined}; export type GoogleCloudDatacatalogV1InlineSource = {taxonomies?: Array | undefined}; export type GoogleCloudDatacatalogV1ImportTaxonomiesRequest = {crossRegionalSource?: GoogleCloudDatacatalogV1CrossRegionalSource | undefined, inlineSource?: GoogleCloudDatacatalogV1InlineSource | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesImportArgs = {projectsId: string, locationsId: string, body: GoogleCloudDatacatalogV1ImportTaxonomiesRequest}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesImportOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudDatacatalogV1TaxonomyService = z.object({identity: z.string().optional(), name: z.enum(["MANAGING_SYSTEM_UNSPECIFIED", "MANAGING_SYSTEM_DATAPLEX", "MANAGING_SYSTEM_OTHER"]).optional()}); export const googleCloudDatacatalogV1SystemTimestamps = z.object({createTime: z.string().optional(), expireTime: z.string().optional(), updateTime: z.string().optional()}); export const googleCloudDatacatalogV1Taxonomy = z.object({activatedPolicyTypes: z.array(z.enum(["POLICY_TYPE_UNSPECIFIED", "FINE_GRAINED_ACCESS_CONTROL"])).optional(), description: z.string().optional(), displayName: z.string().optional(), name: z.string().optional(), policyTagCount: z.number().int().optional(), service: googleCloudDatacatalogV1TaxonomyService.optional(), taxonomyTimestamps: googleCloudDatacatalogV1SystemTimestamps.optional()}); export const googleCloudDatacatalogV1ImportTaxonomiesResponse = z.object({taxonomies: z.array(googleCloudDatacatalogV1Taxonomy).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 new taxonomies (including their policy tags) in a given project by importing from inlined or cross-regional sources. For a cross-regional source, new taxonomies are created by copying from a source in another region. For an inlined source, taxonomies and policy tags are created in bulk using nested protocol buffer structures. * * POST /v1/projects/{projectsId}/locations/{locationsId}/taxonomies:import */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesImport = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesImportArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesImportOptions) => { const {baseUrl = "https://datacatalog.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))}/taxonomies:import${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(googleCloudDatacatalogV1ImportTaxonomiesResponse, await res.json()) };