OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
// The event/filter vocabulary comes from the report module, which owns it.
import { z } from 'zod';
import { zChartEvent } from '../report/report.constants';
export const zNotificationRuleEventConfig = z.object({
type: z.literal('events'),
events: z.array(zChartEvent),
});
export type INotificationRuleEventConfig = z.infer<
typeof zNotificationRuleEventConfig
>;
export const zNotificationRuleFunnelConfig = z.object({
type: z.literal('funnel'),
events: z.array(zChartEvent).min(1),
});
export type INotificationRuleFunnelConfig = z.infer<
typeof zNotificationRuleFunnelConfig
>;
export const zNotificationRuleConfig = z.discriminatedUnion('type', [
zNotificationRuleEventConfig,
zNotificationRuleFunnelConfig,
]);
export type INotificationRuleConfig = z.infer<typeof zNotificationRuleConfig>;
export const zCreateNotificationRule = z.object({
id: z.string().optional(),
name: z.string().min(1),
template: z.string().optional(),
config: zNotificationRuleConfig,
integrations: z.array(z.string()),
sendToApp: z.boolean(),
sendToEmail: z.boolean(),
projectId: z.string(),
});
export type ICreateNotificationRule = z.infer<typeof zCreateNotificationRule>;