Skip to content

Commit 0f2c812

Browse files
waleedlatif1claude
andcommitted
fix(search): assert the Gmail date-range table as const
The lookup narrows an arbitrary config string through a type guard instead of indexing a widened record. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 1d691a4 commit 0f2c812

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎apps/sim/connectors/gmail/gmail.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,22 @@ function buildSearchQuery(
306306
return parts.join(' ')
307307
}
308308

309-
const DATE_RANGE_DAYS: Record<string, number> = {
309+
const DATE_RANGE_DAYS = {
310310
'7d': 7,
311311
'30d': 30,
312312
'90d': 90,
313313
'6m': 180,
314314
'1y': 365,
315+
} as const
316+
317+
function isBoundedDateRange(value: unknown): value is keyof typeof DATE_RANGE_DAYS {
318+
return typeof value === 'string' && Object.hasOwn(DATE_RANGE_DAYS, value)
315319
}
316320

317321
/** The earliest message date the configured range admits, or undefined for all time. */
318322
function dateRangeStart(sourceConfig: Record<string, unknown>, now: Date): Date | undefined {
319-
const days = DATE_RANGE_DAYS[(sourceConfig.dateRange as string) || 'all']
320-
return days === undefined ? undefined : daysAgo(now, days)
323+
const range = sourceConfig.dateRange
324+
return isBoundedDateRange(range) ? daysAgo(now, DATE_RANGE_DAYS[range]) : undefined
321325
}
322326

323327
function daysAgo(now: Date, days: number): Date {

0 commit comments

Comments
 (0)