import {z} from 'zod' export type GetApiRestApiV1ProjectsProjectIdNotificationChannelsArgs = {projectId: string, accountId?: string | undefined}; export type GetApiRestApiV1ProjectsProjectIdNotificationChannelsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const channelHealthDTO = z.object({autoDisabled: z.boolean().optional(), consecutiveFailures: z.number().int().optional(), lastError: z.string().optional(), lastFailureAt: z.string().optional(), lastSuccessAt: z.string().optional(), throttled: z.boolean().optional()}); export const notificationRecipientDTO = z.object({displayName: z.string().optional(), enabled: z.boolean().optional(), health: channelHealthDTO.optional(), key: z.string().optional(), verified: z.boolean().optional()}); export const notificationChannelUsageDTO = z.object({featureId: z.string().optional(), featureTypeId: z.number().int().optional(), name: z.string().optional(), recipient: z.string().optional()}); export const notificationChannelDTO = z.object({accountId: z.string().optional(), channelType: z.enum(["TELEGRAM", "WEBHOOK", "SLACK", "MS_TEAMS", "DISCORD"]).optional(), connectMode: z.enum(["OAUTH", "GUIDED_URL", "RECIPIENT", "MANUAL_URL"]).optional(), displayName: z.string().optional(), enabled: z.boolean().optional(), featureId: z.string().optional(), health: channelHealthDTO.optional(), level: z.string().optional(), recipients: z.array(notificationRecipientDTO).optional(), usedBy: z.array(notificationChannelUsageDTO).optional()}); export const getApiRestApiV1ProjectsProjectIdNotificationChannelsResponse = z.array(notificationChannelDTO); 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 the notification channels of a project * * GET /rest/api/v1/projects/{projectId}/notificationChannels */ export const getApiRestApiV1ProjectsProjectIdNotificationChannels = async (args: GetApiRestApiV1ProjectsProjectIdNotificationChannelsArgs, options?: GetApiRestApiV1ProjectsProjectIdNotificationChannelsOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/notificationChannels${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(getApiRestApiV1ProjectsProjectIdNotificationChannelsResponse, await res.json()) };