feature(dashboard): add integrations and notifications
This commit is contained in:
@@ -148,3 +148,119 @@ export const zOnboardingProject = z
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const zSlackAuthResponse = z.object({
|
||||
ok: z.literal(true),
|
||||
app_id: z.string(),
|
||||
authed_user: z.object({
|
||||
id: z.string(),
|
||||
}),
|
||||
scope: z.string(),
|
||||
token_type: z.literal('bot'),
|
||||
access_token: z.string(),
|
||||
bot_user_id: z.string(),
|
||||
team: z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
}),
|
||||
incoming_webhook: z.object({
|
||||
channel: z.string(),
|
||||
channel_id: z.string(),
|
||||
configuration_url: z.string().url(),
|
||||
url: z.string().url(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const zSlackConfig = z
|
||||
.object({
|
||||
type: z.literal('slack'),
|
||||
})
|
||||
.merge(zSlackAuthResponse);
|
||||
|
||||
export type ISlackConfig = z.infer<typeof zSlackConfig>;
|
||||
|
||||
export const zWebhookConfig = z.object({
|
||||
type: z.literal('webhook'),
|
||||
url: z.string().url(),
|
||||
headers: z.record(z.string()),
|
||||
payload: z.record(z.string(), z.unknown()),
|
||||
});
|
||||
export type IWebhookConfig = z.infer<typeof zWebhookConfig>;
|
||||
|
||||
export const zDiscordConfig = z.object({
|
||||
type: z.literal('discord'),
|
||||
url: z.string().url(),
|
||||
});
|
||||
export type IDiscordConfig = z.infer<typeof zDiscordConfig>;
|
||||
|
||||
export const zAppConfig = z.object({
|
||||
type: z.literal('app'),
|
||||
});
|
||||
export type IAppConfig = z.infer<typeof zAppConfig>;
|
||||
|
||||
export const zEmailConfig = z.object({
|
||||
type: z.literal('email'),
|
||||
});
|
||||
export type IEmailConfig = z.infer<typeof zEmailConfig>;
|
||||
|
||||
export type IIntegrationConfig =
|
||||
| ISlackConfig
|
||||
| IDiscordConfig
|
||||
| IWebhookConfig
|
||||
| IAppConfig
|
||||
| IEmailConfig;
|
||||
|
||||
const zCreateIntegration = z.object({
|
||||
id: z.string().optional(),
|
||||
name: z.string().min(1),
|
||||
organizationId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const zCreateSlackIntegration = zCreateIntegration;
|
||||
|
||||
export const zCreateWebhookIntegration = zCreateIntegration.merge(
|
||||
z.object({
|
||||
config: zWebhookConfig,
|
||||
}),
|
||||
);
|
||||
|
||||
export const zCreateDiscordIntegration = zCreateIntegration.merge(
|
||||
z.object({
|
||||
config: zDiscordConfig,
|
||||
}),
|
||||
);
|
||||
|
||||
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),
|
||||
config: zNotificationRuleConfig,
|
||||
integrations: z.array(z.string()),
|
||||
sendToApp: z.boolean(),
|
||||
sendToEmail: z.boolean(),
|
||||
projectId: z.string(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user