Skip to content

Commit 50ede55

Browse files
saltcodivasilov
andauthored
Chore/webhook json (supabase#30797)
* Enforce json payloads with webhook jobs * EFs need json as well * Handle case where the body can be null/undefined. * Fix url in the child id. * Fix a redirect for cron. --------- Co-authored-by: Ivan Vasilov <[email protected]>
1 parent 283e274 commit 50ede55

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,19 @@ const edgeFunctionSchema = z.object({
6363
edgeFunctionName: z.string().trim().min(1, 'Please select one of the listed Edge Functions'),
6464
timeoutMs: z.coerce.number().int().gte(1000).lte(5000).default(1000),
6565
httpHeaders: z.array(z.object({ name: z.string(), value: z.string() })),
66-
httpBody: z.string().trim(),
66+
httpBody: z
67+
.string()
68+
.trim()
69+
.optional()
70+
.refine((value) => {
71+
if (!value) return true
72+
try {
73+
JSON.parse(value)
74+
return true
75+
} catch {
76+
return false
77+
}
78+
}, 'Input must be valid JSON'),
6779
})
6880

6981
const httpRequestSchema = z.object({
@@ -77,7 +89,19 @@ const httpRequestSchema = z.object({
7789
.refine((value) => value.startsWith('http'), 'Please include HTTP/HTTPs to your URL'),
7890
timeoutMs: z.coerce.number().int().gte(1000).lte(5000).default(1000),
7991
httpHeaders: z.array(z.object({ name: z.string(), value: z.string() })),
80-
httpBody: z.string().trim(),
92+
httpBody: z
93+
.string()
94+
.trim()
95+
.optional()
96+
.refine((value) => {
97+
if (!value) return true
98+
try {
99+
JSON.parse(value)
100+
return true
101+
} catch {
102+
return false
103+
}
104+
}, 'Input must be valid JSON'),
81105
})
82106

83107
const sqlFunctionSchema = z.object({

apps/studio/components/interfaces/Integrations/CronJobs/CronJobCard.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ export const CronJobCard = ({ job, onEditCronJob, onDeleteCronJob }: CronJobCard
6969
onCheckedChange={() => showToggleConfirmationModal(true)}
7070
/>
7171
<Button type="default" icon={<History />}>
72-
<Link href={`/project/${ref}/integrations/cron/cron-jobs/${job.jobname}`}>
73-
History
74-
</Link>
72+
<Link href={`/project/${ref}/integrations/cron/jobs/${job.jobname}`}>History</Link>
7573
</Button>
7674
<DropdownMenu>
7775
<DropdownMenuTrigger asChild>

apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const buildHttpRequestCommand = (
99
method: 'GET' | 'POST',
1010
url: string,
1111
headers: HTTPHeader[],
12-
body: string,
12+
body: string | undefined,
1313
timeout: number
1414
) => {
1515
return `$$
@@ -20,7 +20,7 @@ export const buildHttpRequestCommand = (
2020
.filter((v) => v.name && v.value)
2121
.map((v) => `'${v.name}', '${v.value}'`)
2222
.join(', ')}),
23-
${method === 'POST' ? `body:='${body}',` : ''}
23+
${method === 'POST' && body ? `body:='${body}',` : ''}
2424
timeout_milliseconds:=${timeout}
2525
);
2626
$$`

apps/studio/components/interfaces/Integrations/CronJobs/HttpBodyFieldSection.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ export const HttpBodyFieldSection = ({ form }: HttpBodyFieldSectionProps) => {
3232
onChange={field.onChange}
3333
/>
3434
</FormControl_Shadcn_>
35-
<FormDescription_Shadcn_ className="text-foreground-lighter">
36-
The content should match the content-type header.
37-
</FormDescription_Shadcn_>
3835
<FormMessage_Shadcn_ />
3936
</FormItem_Shadcn_>
4037
)}

apps/studio/components/layouts/Integrations/tabs.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ export const IntegrationTabs = ({ scroll, isSticky }: IntegrationTabsProps) => {
9696
>
9797
<NavMenuItem active={true} className="flex items-center gap-2">
9898
{tab.childIcon}
99-
<Link href={`/project/${project?.ref}/integrations/${tab.route}`}>
100-
{childId}
101-
</Link>
99+
<Link href={`${tabUrl}/${childId}`}>{childId}</Link>
102100
</NavMenuItem>
103101
</motion.div>
104102
</>

apps/studio/next.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ const nextConfig = {
411411
},
412412
{
413413
permanent: true,
414-
source: '/project/:ref/.....',
415-
destination: '/project/:ref/integrations/cron-jobs',
414+
source: '/project/:ref/database/cron-jobs',
415+
destination: '/project/:ref/integrations/cron',
416416
},
417417
{
418418
permanent: true,

0 commit comments

Comments
 (0)