From 42d695db9703f029993af6531c1614c38ba76799 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:06:25 +0100 Subject: [PATCH] fix(jobs): sync_type validation (#3325) ## Changes - Fix sync_type validation for very old scripts --- packages/jobs/lib/routes/tasks/putTask.ts | 2 +- packages/jobs/lib/runner/render.ts | 6 +++--- packages/types/lib/nangoYaml/index.ts | 2 +- packages/webapp/src/pages/Connection/components/SyncRow.tsx | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/jobs/lib/routes/tasks/putTask.ts b/packages/jobs/lib/routes/tasks/putTask.ts index 9937f20fd96..90ea80b6fcf 100644 --- a/packages/jobs/lib/routes/tasks/putTask.ts +++ b/packages/jobs/lib/routes/tasks/putTask.ts @@ -68,7 +68,7 @@ const nangoPropsSchema = z pre_built: z.boolean(), is_public: z.boolean(), input: z.string().nullable(), - sync_type: z.enum(['full', 'incremental']).nullable(), + sync_type: z.enum(['full', 'incremental', 'FULL', 'INCREMENTAL']).nullable(), metadata: z.record(z.string(), z.any()) }) .passthrough(), diff --git a/packages/jobs/lib/runner/render.ts b/packages/jobs/lib/runner/render.ts index 7b1b5c016f2..25246f037b4 100644 --- a/packages/jobs/lib/runner/render.ts +++ b/packages/jobs/lib/runner/render.ts @@ -6,7 +6,7 @@ import { envs } from '../env.js'; import { getPersistAPIUrl, getProvidersUrl, getRedisUrl } from '@nangohq/shared'; import type { AxiosResponse } from 'axios'; import { isAxiosError } from 'axios'; -import type { RateLimiterAbstract } from 'rate-limiter-flexible'; +import type { IRateLimiterRedisOptions, RateLimiterAbstract } from 'rate-limiter-flexible'; import { RateLimiterRedis, RateLimiterMemory } from 'rate-limiter-flexible'; import { createClient } from 'redis'; @@ -172,13 +172,13 @@ class CombinedThrottler { } const serviceCreationThrottler = await (async () => { - const minuteThrottlerOpts = { + const minuteThrottlerOpts: Omit = { keyPrefix: 'minute', points: envs.RENDER_SERVICE_CREATION_MAX_PER_MINUTE || 50, duration: 60, blockDuration: 0 }; - const hourThrottlerOpts = { + const hourThrottlerOpts: Omit = { keyPrefix: 'hour', points: envs.RENDER_SERVICE_CREATION_MAX_PER_HOUR || 700, duration: 3600, diff --git a/packages/types/lib/nangoYaml/index.ts b/packages/types/lib/nangoYaml/index.ts index dcbc989cdf2..2ec39c32b55 100644 --- a/packages/types/lib/nangoYaml/index.ts +++ b/packages/types/lib/nangoYaml/index.ts @@ -1,7 +1,7 @@ import type { OnEventType } from '../scripts/on-events/api'; export type HTTP_METHOD = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE'; -export type SyncTypeLiteral = 'incremental' | 'full'; +export type SyncTypeLiteral = 'incremental' | 'full' | 'FULL' | 'INCREMENTAL'; // TODO: There has been some mixed type in the DB, fix casing export type ScriptFileType = 'actions' | 'syncs' | 'on-events' | 'post-connection-scripts'; // post-connection-scripts is deprecated export type ScriptTypeLiteral = 'action' | 'sync' | 'on-event'; diff --git a/packages/webapp/src/pages/Connection/components/SyncRow.tsx b/packages/webapp/src/pages/Connection/components/SyncRow.tsx index 016e66d9691..a7a826860bd 100644 --- a/packages/webapp/src/pages/Connection/components/SyncRow.tsx +++ b/packages/webapp/src/pages/Connection/components/SyncRow.tsx @@ -30,7 +30,7 @@ export const SyncRow: React.FC<{ sync: SyncResponse; connection: ApiConnectionFu const [showPauseStartLoader, setShowPauseStartLoader] = useState(false); const [showInterruptLoader, setShowInterruptLoader] = useState(false); - const [triggerMode, setTriggerMode] = useState<'incremental' | 'full'>(sync.sync_type === 'full' ? 'full' : 'incremental'); + const [triggerMode, setTriggerMode] = useState<'incremental' | 'full'>(sync.sync_type.toLocaleLowerCase() === 'full' ? 'full' : 'incremental'); const [deleteRecords, setDeleteRecords] = useState(false); const [modalSpinner, setModalShowSpinner] = useState(false); const [openConfirm, setOpenConfirm] = useState(false);