Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"cron-parser": "^4.9.0",
"currency-codes": "^2.2.0",
"date-fns": "^4.1.0",
"decimal.js": "^10.6.0",
Expand Down
23 changes: 23 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/components/functions/ConfigForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ export const ConfigForm = ({ middlewares, data }: ConfigFormProps) => {
<InputField fieldName={'options.eventName'} label={'Event Name'} />
)}
{form.watch('functionType') === 'cron' && (
<InputField fieldName={'options.cronString'} label={'Cron String'} />
<InputField
fieldName={'options.cronString'}
label={'Cron schedule'}
placeholder={'*/5 * * * *'}
description={'minute hour day month weekday (UTC)'}
/>
)}
{(form.watch('functionType') === 'webhook' ||
form.watch('functionType') === 'request') && (
Expand Down
1 change: 1 addition & 0 deletions src/components/functions/CreateFunctionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const CreateFunctionForm = ({
functionType: data.functionType,
timeout: data.timeout,
inputs: {
cronPattern: options.cronString,
event: options.cronString,
},
})
Expand Down
6 changes: 5 additions & 1 deletion src/components/functions/EditFunctionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export const EditFunctionForm = ({
? {
options: {
functionType: functionData.functionType,
cronString: functionData.inputs?.event!,
cronString:
functionData.inputs?.cronPattern ??
functionData.inputs?.event ??
'',
},
}
: {}),
Expand Down Expand Up @@ -186,6 +189,7 @@ export const EditFunctionForm = ({
functionType: data.functionType,
timeout: data.timeout,
inputs: {
cronPattern: options.cronString,
event: options.cronString,
},
})
Expand Down
18 changes: 17 additions & 1 deletion src/components/functions/zod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { z } from 'zod';
import { parseExpression } from 'cron-parser';

function validateCronString(value: string): boolean {
try {
parseExpression(value.trim(), { tz: 'UTC' });
return true;
} catch {
return false;
}
}

export enum ParamsEnum {
String = 'string',
Expand Down Expand Up @@ -126,7 +136,13 @@ export const EventOptions = z.object({
});
export const CronOptions = z.object({
functionType: z.literal('cron'),
cronString: z.string(),
cronString: z
.string()
.min(1, 'Cron schedule is required')
.refine(validateCronString, {
message:
'Invalid cron pattern. Use 5 fields: minute hour day month weekday (UTC). Example: */5 * * * *',
}),
});
export const SocketOptions = z.object({
functionType: z.literal('socket'),
Expand Down
1 change: 1 addition & 0 deletions src/lib/models/functions/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface IWebInputsInterface {
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
event?: string;
cronPattern?: string;
bodyParams?: { [key: string]: any }[];
urlParams?: { [key: string]: any }[];
queryParams?: { [key: string]: any }[];
Expand Down
Loading