import {z} from 'zod' export type GetApiCatalogV1DataProductStatusesArgs = {after?: string | undefined, size?: number | undefined, search?: string | undefined, name?: string | undefined, sort?: Array | undefined, extraProperties?: Array | undefined}; export type GetApiCatalogV1DataProductStatusesOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const paginationMetadata = z.object({next: z.string().optional(), total: z.number().int().optional()}); export const dataProductStatusUrn = z.string(); export const urn = z.string(); export const dynamicPropertyValue = z.union([z.string(), z.number(), z.boolean(), urn, z.array(z.string()), z.array(z.number()), z.array(z.boolean()), z.array(urn)]).nullable(); export const extraProperties = z.record(z.string(), dynamicPropertyValue); export const dataProductStatus = z.object({urn: dataProductStatusUrn, name: z.string(), extraProperties: extraProperties.optional()}); export const getApiCatalogV1DataProductStatusesResponse = z.object({meta: paginationMetadata.optional(), data: z.array(dataProductStatus).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 }; /** * List data product statuses * * GET /catalog/v1/data-product-statuses */ export const getApiCatalogV1DataProductStatuses = async (args: GetApiCatalogV1DataProductStatusesArgs, options?: GetApiCatalogV1DataProductStatusesOptions) => { const {baseUrl = "https://your-environment.ataccama.one/api", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.after != null) query.append("after", String(args.after)) if (args.size != null) query.append("size", String(args.size)) if (args.search != null) query.append("search", String(args.search)) if (args.name != null) query.append("name", String(args.name)) if (args.sort != null) query.append("sort", args.sort.join(',')) if (args.extraProperties != null) query.append("extraProperties", args.extraProperties.join(',')) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/catalog/v1/data-product-statuses${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiCatalogV1DataProductStatusesResponse, await res.json()) };