import {z} from 'zod' export type GetApiCatalogV1DocumentationFlowConfigurationsArgs = {after?: string | undefined, size?: number | undefined, search?: string | undefined, name?: string | undefined}; export type GetApiCatalogV1DocumentationFlowConfigurationsOptions = {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 documentationFlowConfigurationUrn = z.string(); export const documentationFlowConfiguration = z.object({urn: documentationFlowConfigurationUrn, name: z.string().optional(), description: z.string().optional(), configuration: z.string()}); export const getApiCatalogV1DocumentationFlowConfigurationsResponse = z.object({meta: paginationMetadata.optional(), data: z.array(documentationFlowConfiguration).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 documentation flow configurations * * GET /catalog/v1/documentation-flow/configurations */ export const getApiCatalogV1DocumentationFlowConfigurations = async (args: GetApiCatalogV1DocumentationFlowConfigurationsArgs, options?: GetApiCatalogV1DocumentationFlowConfigurationsOptions) => { 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 (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/catalog/v1/documentation-flow/configurations${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(getApiCatalogV1DocumentationFlowConfigurationsResponse, await res.json()) };