UNPKG

@crosspost/scheduler-sdk

Version:

TypeScript SDK client for the Scheduler service

58 lines (57 loc) 1.76 kB
import { z } from "zod"; /** * Job schedule types */ export var ScheduleType; (function (ScheduleType) { ScheduleType["CRON"] = "cron"; ScheduleType["SPECIFIC_TIME"] = "specific_time"; ScheduleType["RECURRING"] = "recurring"; })(ScheduleType || (ScheduleType = {})); /** * Job types */ export var JobType; (function (JobType) { JobType["HTTP"] = "http"; })(JobType || (JobType = {})); /** * Interval types for recurring jobs */ export var IntervalType; (function (IntervalType) { IntervalType["MINUTE"] = "minute"; IntervalType["HOUR"] = "hour"; IntervalType["DAY"] = "day"; IntervalType["WEEK"] = "week"; IntervalType["MONTH"] = "month"; IntervalType["YEAR"] = "year"; })(IntervalType || (IntervalType = {})); /** * Job status types */ export var JobStatus; (function (JobStatus) { JobStatus["ACTIVE"] = "active"; JobStatus["INACTIVE"] = "inactive"; JobStatus["FAILED"] = "failed"; })(JobStatus || (JobStatus = {})); export const JobSchema = z.object({ name: z.string().min(1, "Name is required"), description: z.string().optional(), type: z.nativeEnum(JobType), target: z.string().url("Target must be a valid URL"), payload: z.record(z.any()).optional(), schedule_type: z.nativeEnum(ScheduleType), cron_expression: z .string() .optional() .refine((val) => !val || val.trim() !== "" || val.split(" ").length === 5 || val.split(" ").length === 6, { message: "Invalid cron expression format" }), specific_time: z.string().datetime().optional(), interval: z.nativeEnum(IntervalType).optional(), interval_value: z.number().int().positive().optional(), status: z.nativeEnum(JobStatus).default(JobStatus.ACTIVE), });