fix: allow cron delivery clears

This commit is contained in:
Peter Steinberger
2026-05-31 22:04:19 -04:00
parent d2c5ad2b36
commit d86b6da012
10 changed files with 450 additions and 41 deletions

View File

@@ -99,6 +99,39 @@ describe("cron protocol validators", () => {
).toBe(true);
});
it("accepts nullable delivery clears on update params", () => {
expect(
validateCronUpdateParams({
id: "job-1",
patch: {
delivery: {
channel: null,
to: null,
threadId: null,
accountId: null,
failureDestination: null,
},
},
}),
).toBe(true);
expect(
validateCronUpdateParams({
id: "job-1",
patch: {
delivery: {
failureDestination: {
channel: null,
to: null,
accountId: null,
mode: null,
},
},
},
}),
).toBe(true);
});
it("accepts remove params for id and jobId selectors", () => {
expect(validateCronRemoveParams({ id: "job-1" })).toBe(true);
expect(validateCronRemoveParams({ jobId: "job-2" })).toBe(true);

View File

@@ -235,6 +235,18 @@ export const CronFailureDestinationSchema = Type.Object(
{ additionalProperties: false },
);
const CronFailureDestinationPatchSchema = Type.Object(
{
channel: Type.Optional(Type.Union([Type.Literal("last"), NonEmptyString, Type.Null()])),
to: Type.Optional(Type.Union([Type.String(), Type.Null()])),
accountId: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
mode: Type.Optional(
Type.Union([Type.Literal("announce"), Type.Literal("webhook"), Type.Null()]),
),
},
{ additionalProperties: false },
);
export const CronCompletionDestinationSchema = Type.Object(
{
mode: Type.Literal("webhook"),
@@ -251,6 +263,14 @@ const CronDeliverySharedProperties = {
failureDestination: Type.Optional(CronFailureDestinationSchema),
};
const CronDeliveryPatchSharedProperties = {
channel: Type.Optional(Type.Union([Type.Literal("last"), NonEmptyString, Type.Null()])),
threadId: Type.Optional(Type.Union([Type.String(), Type.Number(), Type.Null()])),
accountId: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
bestEffort: Type.Optional(Type.Boolean()),
failureDestination: Type.Optional(Type.Union([CronFailureDestinationPatchSchema, Type.Null()])),
};
const CronDeliveryNoopSchema = Type.Object(
{
mode: Type.Literal("none"),
@@ -290,11 +310,11 @@ export const CronDeliveryPatchSchema = Type.Object(
mode: Type.Optional(
Type.Union([Type.Literal("none"), Type.Literal("announce"), Type.Literal("webhook")]),
),
...CronDeliverySharedProperties,
...CronDeliveryPatchSharedProperties,
completionDestination: Type.Optional(
Type.Union([CronCompletionDestinationSchema, Type.Null()]),
),
to: Type.Optional(Type.String()),
to: Type.Optional(Type.Union([Type.String(), Type.Null()])),
},
{ additionalProperties: false },
);