import {z} from 'zod' export type TransformDetailsReqBody = {status?: (Array | string | null) | undefined, tag_ids?: (Array | string | null) | undefined, tag_filter_operation?: ('and' | 'or' | null) | undefined} | {[key: string]: unknown}; export type GetApiTransformsArgs = {id?: (string | null) | undefined, partial_name?: (string | null) | undefined, page?: number | undefined, page_size?: number | undefined, sort?: (string | null) | undefined, sort_dir?: ('asc' | 'desc') | undefined, status?: (string | null) | undefined, latency?: (string | null) | undefined, duration?: (string | null) | undefined, unwind_topics?: boolean | undefined, tag_ids?: (string | null) | undefined, tag_filter_operation?: ('and' | 'or' | null) | undefined, body: TransformDetailsReqBody | null}; export type GetApiTransformsOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const fullTransformsRes = z.record(z.string(), z.unknown()); 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 }; /** * Get Full Transforms * * GET /transforms */ export const getApiTransforms = async (args: GetApiTransformsArgs, options?: GetApiTransformsOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args.partial_name != null) query.append("partial_name", String(args.partial_name)) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.sort_dir != null) query.append("sort_dir", String(args.sort_dir)) if (args.status != null) query.append("status", String(args.status)) if (args.latency != null) query.append("latency", String(args.latency)) if (args.duration != null) query.append("duration", String(args.duration)) if (args.unwind_topics != null) query.append("unwind_topics", String(args.unwind_topics)) if (args.tag_ids != null) query.append("tag_ids", String(args.tag_ids)) if (args.tag_filter_operation != null) query.append("tag_filter_operation", String(args.tag_filter_operation)) if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/transforms${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", 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(fullTransformsRes, await res.json()) };