import {z} from 'zod' export type GetApiV1AccountAccountSlugProjectProjectSlugDeliveryChannelsArgs = {accountSlug: string, projectSlug: string}; export type GetApiV1AccountAccountSlugProjectProjectSlugDeliveryChannelsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deliveryChannelPayload = z.object({id: z.string(), label: z.string(), type: z.enum(["email", "slack", "discord", "webhook"]), owner_id: z.string(), project_id: z.string().optional(), reference_id: z.string(), enabled: z.boolean(), created_at: z.string(), information: z.union([z.object({email: z.string().optional(), emails: z.array(z.string()).optional()}), z.object({team_name: z.string().optional(), channel_name: z.string().optional()}), z.object({webhook: z.string().optional()}), z.object({chat_id: z.number().int().optional()})])}); export const projectDeliveryChannelsGetResponse = z.object({delivery_channels: z.array(deliveryChannelPayload).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 Delivery Channels for project * * GET /v1/account/{accountSlug}/project/{projectSlug}/delivery-channels * * Also accepts auth: BearerAuth */ export const getApiV1AccountAccountSlugProjectProjectSlugDeliveryChannels = async (args: GetApiV1AccountAccountSlugProjectProjectSlugDeliveryChannelsArgs, options?: GetApiV1AccountAccountSlugProjectProjectSlugDeliveryChannelsOptions) => { const {baseUrl = "https://api.tenderly.co/api", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-Access-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/account/${encodeURIComponent(String(args.accountSlug))}/project/${encodeURIComponent(String(args.projectSlug))}/delivery-channels${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(projectDeliveryChannelsGetResponse, await res.json()) };