Files
clawdbot/src/cron/payload-migration.ts
2026-01-13 08:40:39 +00:00

39 lines
975 B
TypeScript

type UnknownRecord = Record<string, unknown>;
function readString(value: unknown): string | undefined {
if (typeof value !== "string") return undefined;
return value;
}
function normalizeChannel(value: string): string {
return value.trim().toLowerCase();
}
export function migrateLegacyCronPayload(payload: UnknownRecord): boolean {
let mutated = false;
const channelValue = readString(payload.channel);
const providerValue = readString(payload.provider);
const nextChannel =
typeof channelValue === "string" && channelValue.trim().length > 0
? normalizeChannel(channelValue)
: typeof providerValue === "string" && providerValue.trim().length > 0
? normalizeChannel(providerValue)
: "";
if (nextChannel) {
if (channelValue !== nextChannel) {
payload.channel = nextChannel;
mutated = true;
}
}
if ("provider" in payload) {
delete payload.provider;
mutated = true;
}
return mutated;
}