import {z} from 'zod' export type DeleteApiTopicsTopicIdDestinationsDestinationIdArgs = {topic_id: string, destination_id: string}; export type DeleteApiTopicsTopicIdDestinationsDestinationIdOptions = {baseUrl?: string | undefined, FronteggHTTPAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const topicDestinationLink = z.object({binding_id: z.string(), source_id: z.string(), destination_id: z.string(), destination_name: z.string(), destination_connector: z.string(), topic_ids: z.array(z.string()), managed: z.boolean().optional()}).and(z.record(z.string(), z.unknown())); export const deleteApiTopicsTopicIdDestinationsDestinationIdResponse = z.union([topicDestinationLink, 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 }; /** * Stop sending a topic to a destination (emptied binding is removed) * * DELETE /topics/{topic_id}/destinations/{destination_id} */ export const deleteApiTopicsTopicIdDestinationsDestinationId = async (args: DeleteApiTopicsTopicIdDestinationsDestinationIdArgs, options?: DeleteApiTopicsTopicIdDestinationsDestinationIdOptions) => { const {baseUrl = "https://api.streamkap.com", fetch: fetchFn = fetch, FronteggHTTPAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (FronteggHTTPAuthentication !== undefined) headers.set('authorization', `Bearer ${FronteggHTTPAuthentication}`) const url = `${baseUrl.replace(/\/+$/, '')}/topics/${encodeURIComponent(String(args.topic_id))}/destinations/${encodeURIComponent(String(args.destination_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deleteApiTopicsTopicIdDestinationsDestinationIdResponse, await res.json()) };