import {z} from 'zod' export type TopicDetailsReqBody = {entity_id?: (Array | string | null) | undefined, destination_ids?: (Array | string | null) | undefined, snapshot?: (Array | string | null) | undefined, value_format?: (string | null) | undefined, has_errors?: (boolean | null) | undefined, orphaned?: (boolean | null) | undefined, partition_skew?: (boolean | null) | undefined, tag_ids?: (Array | string | null) | undefined, tag_filter_operation?: ('and' | 'or' | null) | undefined} | {[key: string]: unknown}; export type GetApiTopicsDetailsArgs = {entity_type?: (string | null) | undefined, topic_id?: (string | null) | undefined, partial_name?: (string | null) | undefined, page?: number | undefined, page_size?: number | undefined, entity_id?: (string | null) | undefined, destination_ids?: (string | null) | undefined, include_dlq?: boolean | undefined, include_internal?: boolean | undefined, snapshot?: (string | null) | undefined, eta?: (string | null) | undefined, timestamp_from?: (string | null) | undefined, timestamp_to?: (string | null) | undefined, time_type?: ('timeseries' | 'timesummary' | 'latest' | null) | undefined, value_format?: (string | null) | undefined, has_errors?: (boolean | null) | undefined, orphaned?: (boolean | null) | undefined, partition_skew?: (boolean | null) | undefined, sort?: (string | null) | undefined, sort_dir?: ('asc' | 'desc') | undefined, tag_ids?: (string | null) | undefined, tag_filter_operation?: ('and' | 'or' | null) | undefined, body: TopicDetailsReqBody | null}; export type GetApiTopicsDetailsOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const topicDetailsEntityTypeEnum = z.enum(["sources", "destinations", "transforms", "pipelines", "manual", "agents"]); export const sourceConnectorEnum = z.enum(["alloydb", "elasticsearch", "mongodbhosted", "mongodb", "sqlserveraws", "mariadb", "mysql", "postgresql", "oracle", "documentdb", "oracleaws", "kafkadirect", "redis", "s3", "webhook", "zendesk_webhook", "salesforce_webhook", "shopify_webhook", "stripe_webhook", "db2", "dynamodb", "vitess", "planetscale", "supabase", "informix", "hubspot", "salesforce", "netsuite", "stripe", "google_analytics", "facebook_ads", "google_ads", "zendesk", "pipedrive", "freshdesk", "shopify"]); export const destinationConnectorEnum = z.enum(["azblob", "clickhouse", "databricks", "mysql", "postgresql", "redshift", "s3", "r2", "gcs", "motherduck", "weaviate", "pinecone", "httpsink", "sqlserver", "bigquery", "cockroachdb", "db2", "oracle", "redis", "snowflake", "starburst", "kafka", "kafkadirect", "iceberg"]); export const transformsLibraryEnum = z.enum(["fan_out", "sql_join", "enrich", "enrich_async", "map_filter", "toast_handling", "un_nesting", "rollup", "topic_router"]); export const topicDetailsEntity = z.object({entity_type: topicDetailsEntityTypeEnum, entity_id: z.string(), name: z.string(), connector: z.union([sourceConnectorEnum, destinationConnectorEnum, transformsLibraryEnum, z.string()]), topic_ids: z.array(z.string()), topic_db_ids: z.array(z.string()), display_name: z.string(), filtered_snapshot_language: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())); export const serializationFormatEnum = z.enum(["avro", "json", "json_schema", "protobuf", "string", "bytearray", "unknown"]); export const topicSerialization = z.object({key_format: serializationFormatEnum.optional(), value_format: serializationFormatEnum.optional(), key_converter: z.string().nullable().optional(), value_converter: z.string().nullable().optional(), schema_registry_enabled: z.boolean().optional()}).and(z.record(z.string(), z.unknown())); export const topicDetailsRes = z.object({id: z.string(), name: z.string(), entity: topicDetailsEntity, prefix: z.string().nullable().optional(), serialization: topicSerialization.nullable().optional(), tags: z.array(z.string()).nullable().optional(), broker_only: z.boolean().optional()}).and(z.record(z.string(), z.unknown())); export const topicsDetailsRes = z.object({page: z.number().int().optional(), page_size: z.number().int().optional(), total: z.number().int().nullable().optional(), has_next: z.boolean().nullable().optional(), result: z.array(topicDetailsRes)}).and(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 }; /** * List all topics * * GET /topics/details */ export const getApiTopicsDetails = async (args: GetApiTopicsDetailsArgs, options?: GetApiTopicsDetailsOptions) => { 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.entity_type != null) query.append("entity_type", String(args.entity_type)) if (args.topic_id != null) query.append("topic_id", String(args.topic_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.entity_id != null) query.append("entity_id", String(args.entity_id)) if (args.destination_ids != null) query.append("destination_ids", String(args.destination_ids)) if (args.include_dlq != null) query.append("include_dlq", String(args.include_dlq)) if (args.include_internal != null) query.append("include_internal", String(args.include_internal)) if (args.snapshot != null) query.append("snapshot", String(args.snapshot)) if (args.eta != null) query.append("eta", String(args.eta)) if (args.timestamp_from != null) query.append("timestamp_from", String(args.timestamp_from)) if (args.timestamp_to != null) query.append("timestamp_to", String(args.timestamp_to)) if (args.time_type != null) query.append("time_type", String(args.time_type)) if (args.value_format != null) query.append("value_format", String(args.value_format)) if (args.has_errors != null) query.append("has_errors", String(args.has_errors)) if (args.orphaned != null) query.append("orphaned", String(args.orphaned)) if (args.partition_skew != null) query.append("partition_skew", String(args.partition_skew)) 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.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(/\/+$/, '')}/topics/details${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(topicsDetailsRes, await res.json()) };