refactor: replace shouldServeCache with mode parameter for calendar cache control (#26539)

* refactor: replace shouldServeCache with mode parameter for calendar cache control

Replace the boolean shouldServeCache parameter with a new CalendarFetchMode type
that can have values 'slots', 'overlay', and 'booking'. This provides better
control over when to serve cache vs relay on calendar providers.

- 'slots' mode: Check feature flags and use cache when available (for getting
  actual calendar availability)
- 'overlay' mode: Don't use cache (for overlay calendar availability)
- 'booking' mode: Don't use cache (for booking confirmation)
- undefined: Same as 'slots' for backwards compatibility

The cache decision logic is now centralized in getCalendar.ts based on the mode
parameter.

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: update CalendarService.test.ts to use mode parameter

Co-Authored-By: Volnei Munhoz <[email protected]>

* refactor: use shared GetAvailabilityParams type across all calendar services

- Import GetAvailabilityParams and GetAvailabilityWithTimeZonesParams from @calcom/types/Calendar
- Replace inline type definitions with shared types in all calendar service implementations
- Update BaseCalendarService, CalendarCacheWrapper, and CalendarTelemetryWrapper
- Ensures consistent typing and follows DRY principles

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: add missing IntegrationCalendar import and update mock getAvailability signature

- Add IntegrationCalendar back to sendgrid CalendarService imports
- Update bookingScenario mock getAvailability to use typed params object
- Add listCalendars method to mock Calendar object

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: update test files to use typed params object for getAvailability methods

- Update CalendarCacheWrapper.test.ts to call getAvailability/getAvailabilityWithTimeZones with params object
- Update getCalendarsEvents.test.ts toHaveBeenCalledWith assertions to expect params object
- All 32 tests now pass

Co-Authored-By: Volnei Munhoz <[email protected]>

* refactor: consolidate to single GetAvailabilityParams type for both getAvailability methods

- Remove GetAvailabilityWithTimeZonesParams, use GetAvailabilityParams for both methods
- Add mode parameter to getAvailabilityWithTimeZones calls
- Update wrapper classes to pass mode through to underlying calendar
- Update test files to include mode in getAvailabilityWithTimeZones calls and assertions

Co-Authored-By: Volnei Munhoz <[email protected]>

* refactor: use EventBusyDate with optional timeZone for getAvailabilityWithTimeZones

- Add optional timeZone field to EventBusyDate type
- Update getAvailabilityWithTimeZones return type to use EventBusyDate[]
- Update Google Calendar service and wrapper classes to use the new type

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: type errors and remove unused calendar watching methods

- Fix type errors in CalendarCacheWrapper.ts (convert null to undefined for timeZone)
- Fix type errors in getCalendarsEvents.ts (ensure timeZone is always present)
- Remove unused watchCalendar/unwatchCalendar from Calendar interface
- Remove unused startWatchingCalendarsInGoogle/stopWatchingCalendarsInGoogle from GoogleCalendarService
- Remove unused imports (uuid, uniqueBy, GOOGLE_WEBHOOK_URL, ONE_MONTH_IN_MS)

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: remove watchCalendar/unwatchCalendar from CalendarTelemetryWrapper

Co-Authored-By: Volnei Munhoz <[email protected]>

* refactor: remove verbose JSDoc param comments from wrapper classes

Co-Authored-By: Volnei Munhoz <[email protected]>

* refactor: make mode parameter required in getCalendar

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: add required mode parameter to all getCalendar callers

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: provide default mode value in getBusyCalendarTimes

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: add mode parameter to remaining getCalendar callers

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: add mode parameter to vital and wipemycalother reschedule

Co-Authored-By: Volnei Munhoz <[email protected]>

* fix: add mode parameter to credential-sync API endpoint

Co-Authored-By: Volnei Munhoz <[email protected]>

* refactor: add 'none' mode to CalendarFetchMode and use as default

Co-Authored-By: Volnei Munhoz <[email protected]>

* test: add mode parameter to getCalendarsEvents test calls

Co-Authored-By: Volnei Munhoz <[email protected]>

* Update packages/app-store/delegationCredential.ts

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-01-08 09:07:41 -03:00
1 parent 64828abad2
commit a62eb2bdac
37 files changed
+356 -369

No files matched your search

+23 -22
View File
@@ -57,6 +57,7 @@ export type EventBusyDate = {
start: Date | string;
end: Date | string;
source?: string | null;
timeZone?: string;
};
export type EventBusyDetails = EventBusyDate & {
@@ -255,6 +256,26 @@ export interface IntegrationCalendar extends Ensure<Partial<_SelectedCalendar>,
integrationTitle?: string;
}
/**
* Mode for calendar fetch operations to control caching behavior:
* - "slots": For getting actual calendar availability (uses cache when available)
* - "overlay": For getting overlay calendar availability (does not use cache)
* - "booking": For booking confirmation (does not use cache)
* - "none": For operations that don't use getAvailability (e.g., deleteEvent, listCalendars)
*/
export type CalendarFetchMode = "slots" | "overlay" | "booking" | "none";
/**
* Parameters for getAvailability and getAvailabilityWithTimeZones methods
*/
export interface GetAvailabilityParams {
dateFrom: string;
dateTo: string;
selectedCalendars: IntegrationCalendar[];
mode: CalendarFetchMode;
fallbackToPrimary?: boolean;
}
/**
* null is to refer to user-level SelectedCalendar
*/
@@ -280,36 +301,16 @@ export interface Calendar {
deleteEvent(uid: string, event: CalendarEvent, externalCalendarId?: string | null): Promise<unknown>;
getAvailability(
dateFrom: string,
dateTo: string,
selectedCalendars: IntegrationCalendar[],
shouldServeCache?: boolean,
fallbackToPrimary?: boolean
): Promise<EventBusyDate[]>;
getAvailability(params: GetAvailabilityParams): Promise<EventBusyDate[]>;
// for OOO calibration (only google calendar for now)
getAvailabilityWithTimeZones?(
dateFrom: string,
dateTo: string,
selectedCalendars: IntegrationCalendar[],
fallbackToPrimary?: boolean
): Promise<{ start: Date | string; end: Date | string; timeZone: string }[]>;
getAvailabilityWithTimeZones?(params: GetAvailabilityParams): Promise<EventBusyDate[]>;
fetchAvailabilityAndSetCache?(selectedCalendars: IntegrationCalendar[]): Promise<unknown>;
listCalendars(event?: CalendarEvent): Promise<IntegrationCalendar[]>;
testDelegationCredentialSetup?(): Promise<boolean>;
watchCalendar?(options: {
calendarId: string;
eventTypeIds: SelectedCalendarEventTypeIds;
}): Promise<unknown>;
unwatchCalendar?(options: {
calendarId: string;
eventTypeIds: SelectedCalendarEventTypeIds;
}): Promise<void>;
}
/**