import {z} from 'zod' export type GetApiV1ChannelConnectionsIdentifierArgs = {identifier: string, 'idempotency-key'?: string | undefined}; export type GetApiV1ChannelConnectionsIdentifierOptions = {baseUrl?: string | undefined, secretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const workspaceDto = z.object({id: z.string(), name: z.string().optional(), botUserId: z.string().optional()}); export const authDto = z.object({accessToken: z.string(), refreshToken: z.string().optional(), expiresAt: z.string().optional(), refreshTokenExpiresAt: z.string().optional()}); export const getChannelConnectionResponseDto = z.object({identifier: z.string(), channel: z.enum(["in_app", "email", "sms", "chat", "push", "tool"]).nullable(), providerId: z.enum(["anypost", "emailjs", "mailgun", "mailjet", "mandrill", "nodemailer", "postmark", "sendgrid", "sendinblue", "ses", "netcore", "infobip-email", "resend", "plunk", "mailersend", "mailtrap", "clickatell", "outlook365", "novu-email", "sparkpost", "email-webhook", "braze", "novu-email-agent", "agent-email-inbox", "nexmo", "plivo", "sms77", "sms-central", "sns", "telnyx", "twilio", "gupshup", "firetext", "infobip-sms", "burst-sms", "bulk-sms", "isend-sms", "forty-six-elks", "kannel", "maqsam", "termii", "africas-talking", "novu-sms", "sendchamp", "generic-sms", "clicksend", "bandwidth", "messagebird", "simpletexting", "azure-sms", "ring-central", "brevo-sms", "eazy-sms", "mobishastra", "afro-message", "unifonic", "smsmode", "imedia", "sinch", "isendpro-sms", "cm-telecom", "ruach-sms", "fcm", "apns", "expo", "one-signal", "pushpad", "push-webhook", "pusher-beams", "appio", "novu", "slack", "discord", "google-chat", "msteams", "webex-messaging", "mattermost", "ryver", "zulip", "grafana-on-call", "getstream", "rocket-chat", "whatsapp-business", "line", "chat-webhook", "novu-slack", "telegram", "sendblue", "photon-imessage", "novu-web-chat", "anthropic", "novu-anthropic", "anthropic-aws", "pagerduty", "opsgenie", "grafana", "tool-webhook"]).nullable(), integrationIdentifier: z.string().nullable(), subscriberId: z.string().nullable(), contextKeys: z.array(z.string()), workspace: workspaceDto, auth: authDto, createdAt: z.string(), updatedAt: z.string()}); 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 }; /** * Retrieve a channel connection * * GET /v1/channel-connections/{identifier} */ export const getApiV1ChannelConnectionsIdentifier = async (args: GetApiV1ChannelConnectionsIdentifierArgs, options?: GetApiV1ChannelConnectionsIdentifierOptions) => { const {baseUrl = "https://api.novu.co", fetch: fetchFn = fetch, secretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['idempotency-key'] != null) headers.set("idempotency-key", String(args['idempotency-key'])) if (secretKey !== undefined) headers.set("Authorization", secretKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/channel-connections/${encodeURIComponent(String(args.identifier))}${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(getChannelConnectionResponseDto, await res.json()) };