import { AXIOM_EMPTY_SCHEMA, AXIOM_ID_SCHEMA, AXIOM_NOTIFIER_PROPERTIES_SCHEMA, AXIOM_NOTIFIER_WITH_ID_SCHEMA, } from "@automate.ax/integration-contracts/axiom" import * as z from "zod" import { defineAction } from "../../../automation/actions" import { AXIOM_ACCOUNT, AXIOM_API_TOKEN_ACCOUNT, axiomPath, getAxiomApi, } from "../lib" const NOTIFIER_ID = { notifierId: AXIOM_ID_SCHEMA } const NOTIFIER_FIELDS = { disabledUntil: z.string().nullable().optional(), name: z.string().trim().min(1), properties: AXIOM_NOTIFIER_PROPERTIES_SCHEMA, } export const listAxiomNotifiers = defineAction("List Axiom notifiers") .describe("Lists configured Axiom notification destinations.") .account(AXIOM_ACCOUNT, AXIOM_API_TOKEN_ACCOUNT) .input(z.object({})) .output(AXIOM_NOTIFIER_WITH_ID_SCHEMA.array()) .retry({ replaySafety: "safe" }) .handler(({ account }) => getAxiomApi(account).request("notifiers", { responseSchema: AXIOM_NOTIFIER_WITH_ID_SCHEMA.array(), }), ) export const createAxiomNotifier = defineAction("Create Axiom notifier") .describe("Creates one email, chat, incident, or webhook notifier.") .account(AXIOM_ACCOUNT, AXIOM_API_TOKEN_ACCOUNT) .input(z.object(NOTIFIER_FIELDS)) .output(AXIOM_NOTIFIER_WITH_ID_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(({ account, input }) => getAxiomApi(account).request("notifiers", { body: input, method: "POST", responseSchema: AXIOM_NOTIFIER_WITH_ID_SCHEMA, }), ) export const getAxiomNotifier = defineAction("Get Axiom notifier") .describe("Retrieves one Axiom notifier by ID.") .account(AXIOM_ACCOUNT, AXIOM_API_TOKEN_ACCOUNT) .input(z.object(NOTIFIER_ID)) .output(AXIOM_NOTIFIER_WITH_ID_SCHEMA) .retry({ replaySafety: "safe" }) .handler(({ account, input }) => getAxiomApi(account).request(`notifiers/${axiomPath(input.notifierId)}`, { responseSchema: AXIOM_NOTIFIER_WITH_ID_SCHEMA, }), ) export const updateAxiomNotifier = defineAction("Update Axiom notifier") .describe("Replaces one Axiom notifier's complete configuration.") .account(AXIOM_ACCOUNT, AXIOM_API_TOKEN_ACCOUNT) .input(z.object({ ...NOTIFIER_ID, ...NOTIFIER_FIELDS })) .output(AXIOM_NOTIFIER_WITH_ID_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(({ account, input: { notifierId, ...body } }) => getAxiomApi(account).request(`notifiers/${axiomPath(notifierId)}`, { body, method: "PUT", responseSchema: AXIOM_NOTIFIER_WITH_ID_SCHEMA, }), ) export const deleteAxiomNotifier = defineAction("Delete Axiom notifier") .describe("Deletes one Axiom notifier.") .account(AXIOM_ACCOUNT, AXIOM_API_TOKEN_ACCOUNT) .input(z.object(NOTIFIER_ID)) .output(AXIOM_EMPTY_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(({ account, input }) => getAxiomApi(account).request(`notifiers/${axiomPath(input.notifierId)}`, { method: "DELETE", responseSchema: AXIOM_EMPTY_SCHEMA, }), )