ghost-listmonk-connector/ui/lib/schemas.ts
troneras ff5b39241a first commit
fixed cache

Refactoring from app router to page router

Refactoring from app router to page router

Add authentication with JWT

base ui done

protect the dashboard

added transitions

styling

type trick added

cleanup

Add enable-disable logic

add transactional emails

Improvements on delay and frontend

added description on select

implement auth with magic link

migrate to mariadb

webhook signature working

Adding async processing with queues

Implemented webhook reply functionality

Add son execution logs

update status logic

Add recent activity monitoring to sons

show son performance in dashboard

add readme

implement listmonk connector

listmonk-connector-v1

Create CODE_OF_CONDUCT.md

Create LICENSE
2024-08-21 02:09:24 +02:00

75 lines
No EOL
2.6 KiB
TypeScript

import * as z from 'zod';
// Define the schema for action parameters
const actionParametersSchema = z.object({
subject: z.string().optional(),
lists: z.array(z.number()).optional(),
template_id: z.number().optional(),
tags: z.string().optional(),
}).strict().or(z.record(z.any())); // Allow any other properties for flexibility
// Define the schema for a single action
const actionSchema = z.object({
type: z.enum(['send_transactional_email', 'manage_subscriber', 'create_campaign']),
parameters: actionParametersSchema,
});
// Define the schema for the entire Son object
export const sonSchema = z.object({
id: z.string().optional(), // Optional because it might not be present when creating a new Son
name: z.string().min(1, 'Name is required'),
trigger: z.enum([
'member_created',
'member_deleted',
'member_updated',
'post_published',
'post_scheduled',
]),
delay: z.string().refine((val) => {
const durationRegex = /^(\d+)\s*(s|m|h|d|w)$/;
return durationRegex.test(val);
}, {
message: "Invalid duration format. Use format like '30m', '2h', '1d', or '1w'.",
}).default('0s'),
actions: z.array(actionSchema).min(1, 'At least one action is required'),
enabled: z.boolean().default(true),
created_at: z.date().optional(),
updated_at: z.date().optional(),
});
export const editableSonSchema = z.object({
name: z.string().min(1, 'Name is required'),
trigger: z.enum([
'member_created',
'member_deleted',
'member_updated',
'post_published',
'post_scheduled',
]),
delay: z.string().min(2).default('0s').refine((val) => {
const durationRegex = /^(\d+)\s*(s|m|h|d|w)$/;
return durationRegex.test(val);
}, {
message: "Invalid duration format. Use format like '30m', '2h', '1d', or '1w'.",
}),
actions: z.array(z.object({
type: z.enum(['send_transactional_email', 'manage_subscriber', 'create_campaign']),
parameters: z.record(z.any()),
})),
enabled: z.boolean().default(true),
});
// Define a schema for creating a new Son (without id, createdAt, and updatedAt)
export const createSonSchema = sonSchema.omit({ id: true, created_at: true, updated_at: true });
// Define a schema for updating an existing Son
export const updateSonSchema = sonSchema.partial().extend({
id: z.string(),
});
// Define types for create and update operations
export type CreateSonInput = z.infer<typeof createSonSchema>;
export type UpdateSonInput = z.infer<typeof updateSonSchema>;