The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix cron panel if unable to parse command (#37562)
Joshen Lim2fad79f825d6
diff --git a/apps/studio/components/interfaces/Account/Preferences/AnalyticsSettings.tsx b/apps/studio/components/interfaces/Account/Preferences/AnalyticsSettings.tsxindex 73d736d80a8..694d94dd4ee 100644--- a/apps/studio/components/interfaces/Account/Preferences/AnalyticsSettings.tsx+++ b/apps/studio/components/interfaces/Account/Preferences/AnalyticsSettings.tsx@@ -1,21 +1,21 @@-import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, Badge, Toggle } from 'ui'import { ButtonTooltip } from 'components/ui/ButtonTooltip'import { X } from 'lucide-react'import { toast } from 'sonner'+import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, Badge, Toggle } from 'ui'import { useConsentState } from 'common'+import { LOCAL_STORAGE_KEYS } from 'common/constants/local-storage'import Panel from 'components/ui/Panel'import { useSendResetMutation } from 'data/telemetry/send-reset-mutation'import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'-import { LOCAL_STORAGE_KEYS } from 'common/constants/local-storage'export const TermsUpdateBanner = () => {- const [termsUpdateAcknowledged, setTermsUpdateAcknowledged] = useLocalStorageQuery(+ const [termsUpdateAcknowledged, setTermsUpdateAcknowledged, { isSuccess }] = useLocalStorageQuery(LOCAL_STORAGE_KEYS.TERMS_OF_SERVICE_ACKNOWLEDGED,false)- if (termsUpdateAcknowledged) return null+ if (!isSuccess || termsUpdateAcknowledged) return nullreturn (<Alert_Shadcn_ className="mb-4 relative">diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsx b/apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsxindex c821de8ccfa..8044d0c2dc2 100644--- a/apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsx+++ b/apps/studio/components/interfaces/Integrations/CronJobs/CreateCronJobSheet.tsx@@ -16,7 +16,7 @@ import { CronJob, useCronJobsQuery } from 'data/database-cron-jobs/database-cronimport { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'import { useSendEventMutation } from 'data/telemetry/send-event-mutation'import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'-import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'+import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'import {Button,Form_Shadcn_,@@ -199,7 +199,7 @@ export const CreateCronJobSheet = ({onClose,}: CreateCronJobSheetProps) => {const { project } = useProjectContext()- const org = useSelectedOrganization()+ const { data: org } = useSelectedOrganizationQuery()const isEditing = !!selectedCronJob?.jobnameconst [showEnableExtensionModal, setShowEnableExtensionModal] = useState(false)@@ -209,6 +209,13 @@ export const CreateCronJobSheet = ({connectionString: project?.connectionString,})+ const { data } = useDatabaseExtensionsQuery({+ projectRef: project?.ref,+ connectionString: project?.connectionString,+ })+ const pgNetExtension = (data ?? []).find((ext) => ext.name === 'pg_net')+ const pgNetExtensionInstalled = pgNetExtension?.installed_version != undefined+const { mutate: sendEvent } = useSendEventMutation()const { mutate: upsertCronJob, isLoading } = useDatabaseCronJobCreateMutation()@@ -230,11 +237,8 @@ export const CreateCronJobSheet = ({})const isEdited = form.formState.isDirty-// if the form hasn't been touched and the user clicked esc or the backdrop, close the sheet- if (!isEdited && isClosing) {- onClose()- }+ if (!isEdited && isClosing) onClose()const onClosePanel = () => {if (isEdited) {@@ -286,6 +290,7 @@ export const CreateCronJobSheet = ({if (command) {form.setValue('values.snippet', command)}+ // eslint-disable-next-line react-hooks/exhaustive-deps}, [edgeFunctionName,endpoint,@@ -362,14 +367,6 @@ export const CreateCronJobSheet = ({)}- const { data } = useDatabaseExtensionsQuery({- projectRef: project?.ref,- connectionString: project?.connectionString,- })-- const pgNetExtension = (data ?? []).find((ext) => ext.name === 'pg_net')- const pgNetExtensionInstalled = pgNetExtension?.installed_version != undefined-return (<><div className="flex flex-col h-full" tabIndex={-1}>diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.tsindex fc7c9ffc289..08827113b60 100644--- a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts+++ b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts@@ -30,12 +30,20 @@ describe('parseCronJobCommand', () => {})})- it('should return a sql function command when the command is SELECT public.test_fn(1, 2)', () => {- const command = 'SELECT public.test_fn(1, 2)'+ it('should return a sql function command when the command is SELECT auth.jwt () and ends with ;', () => {+ const command = 'SELECT auth.jwt ();'expect(parseCronJobCommand(command, 'random_project_ref')).toStrictEqual({type: 'sql_function',- schema: 'public',- functionName: 'test_fn',+ schema: 'auth',+ functionName: 'jwt',+ snippet: command,+ })+ })++ it('should return a sql snippet command when the command is SELECT public.test_fn(1, 2)', () => {+ const command = 'SELECT public.test_fn(1, 2)'+ expect(parseCronJobCommand(command, 'random_project_ref')).toStrictEqual({+ type: 'sql_snippet',snippet: command,})})@@ -194,6 +202,14 @@ describe('parseCronJobCommand', () => {})})+ it('should return SQL snippet type if the command is a HTTP request that cannot be parsed properly due to positional notationa', () => {+ const command = `SELECT net.http_post( 'https://webhook.site/dacc2028-a588-462c-9597-c8968e61d0fa', '{"message":"Hello from Supabase"}'::jsonb, '{}'::jsonb, '{"Content-Type":"application/json"}'::jsonb );`+ expect(parseCronJobCommand(command, 'random_project_ref')).toStrictEqual({+ type: 'sql_snippet',+ snippet: command,+ })+ })+// Array of test cases for secondsPatternconst secondsPatternTests = [{ description: '10 seconds', command: '10 seconds' },diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.ts b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.tsindex 08bca3ff2de..1dbae3bfb44 100644--- a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.ts+++ b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.ts@@ -73,7 +73,7 @@ export const parseCronJobCommand = (originalCommand: string, projectRef: string)}} else {const headersStringMatch = command.match(/headers:='([^']*)'/i)- const headersString = headersStringMatch?.[1] || ''+ const headersString = headersStringMatch?.[1] || '{}'try {const parsedHeaders = JSON.parse(headersString)headersObjs = Object.entries(parsedHeaders).map(([name, value]) => ({@@ -112,22 +112,25 @@ export const parseCronJobCommand = (originalCommand: string, projectRef: string)}}- return {- type: 'http_request',- method: method === 'http_get' ? 'GET' : 'POST',- endpoint: url,- httpHeaders: headersObjs,- httpBody: body,- timeoutMs: Number(timeout ?? 1000),- snippet: originalCommand,+ if (url !== '') {+ return {+ type: 'http_request',+ method: method === 'http_get' ? 'GET' : 'POST',+ endpoint: url,+ httpHeaders: headersObjs,+ httpBody: body,+ timeoutMs: Number(timeout ?? 1000),+ snippet: originalCommand,+ }}}- const regexDBFunction = /select\s+[a-zA-Z-_]*\.?[a-zA-Z-_]*\s*\(.+/g+ const regexDBFunction = /select\s+[a-zA-Z-_]*\.?[a-zA-Z-_]*\s*\(\)/gif (command.toLocaleLowerCase().match(regexDBFunction)) {const [schemaName, functionName] = command.replace('SELECT ', '')- .replace(/\(.*\)/, '')+ .replace(/\(.*\);*/, '')+.trim().split('.')