Skip to content

Comments

refactor: move a constant to a dedicated file in App store package#23671

Merged
hbjORbj merged 3 commits intomainfrom
refactor/better-imports-location
Sep 8, 2025
Merged

refactor: move a constant to a dedicated file in App store package#23671
hbjORbj merged 3 commits intomainfrom
refactor/better-imports-location

Conversation

@hbjORbj
Copy link
Contributor

@hbjORbj hbjORbj commented Sep 8, 2025

What does this PR do?

  • Change: import { DailyLocationType } from "@calcom/app-store/locations"; -> import { DailyLocationType } from "@calcom/app-store/constants";
  • Impact: locations.ts loads zod, appStoreMetadata, logger and more. As a result, we don't do that where there aren't needed.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A - I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

@hbjORbj hbjORbj requested a review from a team as a code owner September 8, 2025 07:21
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 8, 2025

Walkthrough

The change centralizes the DailyLocationType constant by adding it to packages/app-store/constants.ts and updating packages/app-store/locations.ts to re-export it from this source. All references across the codebase switch imports from @calcom/app-store/locations to @calcom/app-store/constants, including in bookings handlers, scheduleNoShowTriggers (and its integration test), defaultEvents, getDefaultLocations, videoClient, and TRPC viewer schemas/handlers. No logic, control flow, or API signatures are modified; only import paths and the constant’s source are updated.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/better-imports-location

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@graphite-app graphite-app bot requested a review from a team September 8, 2025 07:21
@keithwillcode keithwillcode added core area: core, team members only foundation labels Sep 8, 2025
@hbjORbj hbjORbj changed the title refactor: better imports location refactor: move a constant to a dedicated file in App store package Sep 8, 2025
@dosubot dosubot bot added the 💻 refactor label Sep 8, 2025
@hbjORbj hbjORbj enabled auto-merge (squash) September 8, 2025 07:23
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/app-store/locations.ts (2)

459-467: Bug: assignment typo prevents message update for cancelled/rejected bookings

locationToDisplay == t("web_conference") compares instead of assigns, so the string never updates.

Apply:

-    if (bookingStatus === BookingStatus.CANCELLED || bookingStatus === BookingStatus.REJECTED) {
-      locationToDisplay == t("web_conference");
+    if (bookingStatus === BookingStatus.CANCELLED || bookingStatus === BookingStatus.REJECTED) {
+      locationToDisplay = t("web_conference");

488-495: Fix return/variable type to always be an array

The current type DefaultEventLocationType["type"] | EventLocationTypeFromApp["type"][] reads as “string OR array of strings,” but this function always returns an array.

Apply:

-export const getOrganizerInputLocationTypes = () => {
-  const result: DefaultEventLocationType["type"] | EventLocationTypeFromApp["type"][] = [];
+export const getOrganizerInputLocationTypes = (): (
+  DefaultEventLocationType["type"] | EventLocationTypeFromApp["type"]
+)[] => {
+  const result: (
+    DefaultEventLocationType["type"] | EventLocationTypeFromApp["type"]
+  )[] = [];
🧹 Nitpick comments (5)
packages/app-store/constants.ts (1)

1-5: Consider a typed LocationTypes map for stronger typing

Defining a single const map and a union type can reduce stringly-typed usage across the codebase.

Non-breaking addition:

+export const LocationTypes = {
+  Meet: "integrations:google:meet",
+  MSTeams: "integrations:office365_video",
+  Daily: "integrations:daily",
+} as const;
+export type LocationType = typeof LocationTypes[keyof typeof LocationTypes];
packages/lib/defaultEvents.ts (1)

214-214: Prefer named export over default export

Helps tree-shaking and consistency across the monorepo. Can be a follow-up PR.

-export default defaultEvents;
+export { defaultEvents };
packages/app-store/locations.ts (2)

429-433: Nit: clearer error message when defaultValueVariable is missing

Interpolating an undefined variable produces a confusing log.

Apply:

-  if (!defaultValueVariable) {
-    console.error(`${defaultValueVariable} not set for ${bookingLocation.type}`);
+  if (!defaultValueVariable) {
+    console.error(`defaultValueVariable not set for ${bookingLocation.type}`);
     return "";
   }

497-504: Return boolean for isAttendeeInputRequired

The name implies boolean but it returns a possibly string value. Returning a boolean avoids truthiness pitfalls.

Apply:

-export const isAttendeeInputRequired = (locationType: string) => {
+export const isAttendeeInputRequired = (locationType: string): boolean => {
   const location = locations.find((l) => l.type === locationType);
   if (!location) {
     // Consider throwing an error here. This shouldn't happen normally.
-    return false;
+    return false;
   }
-  return location.attendeeInputType;
+  return Boolean(location.attendeeInputType);
 };
packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts (1)

36-39: Trim once and compare against normalized value

Slight readability/robustness improvement: normalize once to handle incidental whitespace.

Apply:

-  const isCalVideoLocation = booking.location === DailyLocationType || booking.location?.trim() === "";
+  const locationTrimmed = booking.location?.trim() ?? null;
+  const isCalVideoLocation = locationTrimmed === DailyLocationType || locationTrimmed === "";
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 411a14d and 7bb50e5.

📒 Files selected for processing (11)
  • packages/app-store/constants.ts (1 hunks)
  • packages/app-store/locations.ts (1 hunks)
  • packages/features/bookings/lib/handleCancelBooking.ts (1 hunks)
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.integration-test.ts (1 hunks)
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts (1 hunks)
  • packages/lib/defaultEvents.ts (1 hunks)
  • packages/lib/server/getDefaultLocations.ts (1 hunks)
  • packages/lib/videoClient.ts (1 hunks)
  • packages/trpc/server/routers/viewer/bookings/editLocation.schema.ts (1 hunks)
  • packages/trpc/server/routers/viewer/eventTypes/create.handler.ts (1 hunks)
  • packages/trpc/server/routers/viewer/eventTypes/update.handler.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/app-store/constants.ts
  • packages/trpc/server/routers/viewer/eventTypes/create.handler.ts
  • packages/lib/defaultEvents.ts
  • packages/trpc/server/routers/viewer/bookings/editLocation.schema.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts
  • packages/lib/server/getDefaultLocations.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.integration-test.ts
  • packages/lib/videoClient.ts
  • packages/app-store/locations.ts
  • packages/trpc/server/routers/viewer/eventTypes/update.handler.ts
  • packages/features/bookings/lib/handleCancelBooking.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/app-store/constants.ts
  • packages/trpc/server/routers/viewer/eventTypes/create.handler.ts
  • packages/lib/defaultEvents.ts
  • packages/trpc/server/routers/viewer/bookings/editLocation.schema.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts
  • packages/lib/server/getDefaultLocations.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.integration-test.ts
  • packages/lib/videoClient.ts
  • packages/app-store/locations.ts
  • packages/trpc/server/routers/viewer/eventTypes/update.handler.ts
  • packages/features/bookings/lib/handleCancelBooking.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/app-store/constants.ts
  • packages/trpc/server/routers/viewer/eventTypes/create.handler.ts
  • packages/lib/defaultEvents.ts
  • packages/trpc/server/routers/viewer/bookings/editLocation.schema.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts
  • packages/lib/server/getDefaultLocations.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.integration-test.ts
  • packages/lib/videoClient.ts
  • packages/app-store/locations.ts
  • packages/trpc/server/routers/viewer/eventTypes/update.handler.ts
  • packages/features/bookings/lib/handleCancelBooking.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: supalarry
PR: calcom/cal.com#23364
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/internal-to-api/internal-to-api.spec.ts:295-296
Timestamp: 2025-08-27T13:32:46.887Z
Learning: In calcom/cal.com, when transforming booking fields from internal to API format, tests in organizations-event-types.e2e-spec.ts already expect name field label and placeholder to be empty strings ("") rather than undefined. PR changes that set these to explicit empty strings are typically fixing implementation to match existing test expectations rather than breaking changes.
📚 Learning: 2025-09-01T10:25:51.923Z
Learnt from: nangelina
PR: calcom/cal.com#23486
File: packages/app-store/kyzonspacevideo/package.json:7-12
Timestamp: 2025-09-01T10:25:51.923Z
Learning: In Cal.com's monorepo, app-store packages don't need to declare `zod` as a direct dependency in their package.json files. The monorepo uses yarn workspaces with dependency hoisting, where `zod` is available through workspace-level dependency management. Most app-store packages successfully import zod without declaring it as a dependency, following the established monorepo pattern.

Applied to files:

  • packages/trpc/server/routers/viewer/bookings/editLocation.schema.ts
📚 Learning: 2025-08-27T13:32:46.887Z
Learnt from: supalarry
PR: calcom/cal.com#23364
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/internal-to-api/internal-to-api.spec.ts:295-296
Timestamp: 2025-08-27T13:32:46.887Z
Learning: In calcom/cal.com, when transforming booking fields from internal to API format, tests in organizations-event-types.e2e-spec.ts already expect name field label and placeholder to be empty strings ("") rather than undefined. PR changes that set these to explicit empty strings are typically fixing implementation to match existing test expectations rather than breaking changes.

Applied to files:

  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts
  • packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.integration-test.ts
  • packages/features/bookings/lib/handleCancelBooking.ts
📚 Learning: 2025-09-01T07:31:00.963Z
Learnt from: nangelina
PR: calcom/cal.com#23486
File: packages/app-store/kyzon-space/config.json:5-5
Timestamp: 2025-09-01T07:31:00.963Z
Learning: In Cal.com's video integration system, credential types (e.g., "kyzon-space_video") are transformed to app names by removing underscores using `cred.type.split("_").join("")` in videoClient.ts line 28. This means the key in packages/app-store/index.ts should match the underscore-removed version (e.g., "kyzon-spacevideo") rather than the original type name. This same pattern is used in other parts of the system like getCalendar.ts.

Applied to files:

  • packages/lib/videoClient.ts
  • packages/app-store/locations.ts
🧬 Code graph analysis (2)
packages/app-store/constants.ts (1)
packages/app-store/locations.ts (1)
  • DailyLocationType (21-21)
packages/app-store/locations.ts (1)
packages/app-store/constants.ts (3)
  • MeetLocationType (1-1)
  • MSTeamsLocationType (3-3)
  • DailyLocationType (5-5)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (11)
packages/app-store/constants.ts (1)

5-5: Centralize DailyLocationType — LGTM

Import source consolidation looks good and keeps a single source of truth.

packages/trpc/server/routers/viewer/eventTypes/create.handler.ts (1)

3-3: Import path switched to constants — LGTM

No behavioral change; aligns with the new single source.

packages/lib/videoClient.ts (1)

4-4: Import path switched to constants — LGTM

Fallback assignment to DailyLocationType on failure remains intact.

packages/lib/defaultEvents.ts (1)

3-3: Import path switched to constants — LGTM

No logic changes in defaults.

packages/trpc/server/routers/viewer/eventTypes/update.handler.ts (1)

5-5: Import path switched to constants — LGTM

Keeps location checks consistent across handlers.

packages/trpc/server/routers/viewer/bookings/editLocation.schema.ts (1)

3-3: Import path switched to constants — LGTM

Schema fallback to DailyLocationType remains unchanged.

packages/features/bookings/lib/handleCancelBooking.ts (1)

4-4: Import path switched to constants — LGTM

Cancellation flow and credential fallback are unaffected.

packages/lib/server/getDefaultLocations.ts (1)

2-2: Import path switched to constants — LGTM

Defaulting to DailyLocationType when needed is preserved.

packages/app-store/locations.ts (1)

16-17: Centralized DailyLocationType import/re-export — LGTM

Importing from ./constants and re-exporting here removes duplication and keeps a single source of truth.

Also applies to: 21-21

packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.integration-test.ts (1)

4-4: Import path update — LGTM

Switching to @calcom/app-store/constants aligns tests with the new single source of truth.

packages/features/bookings/lib/handleNewBooking/scheduleNoShowTriggers.ts (1)

1-1: Import path update — LGTM

Consistent with the refactor to centralize constants.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2025

E2E results are ready!

keithwillcode
keithwillcode previously approved these changes Sep 8, 2025
@vercel
Copy link

vercel bot commented Sep 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 8, 2025 11:08am
cal-eu Ignored Ignored Sep 8, 2025 11:08am

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts (1)

521-524: Replace Prisma include with select (repo guideline)

Follow project rule: never use include; use select. This preserves payload while aligning with guidelines.

-    const workflows = await ctx.prisma.workflow.findMany({
+    const workflows = await ctx.prisma.workflow.findMany({
       where: {
         activeOn: {
           some: {
             eventTypeId: input.id,
           },
         },
       },
-      include: {
-        steps: true,
-      },
+      select: {
+        steps: true,
+        // add other fields explicitly if needed by allowDisabling* helpers
+      },
     });
🧹 Nitpick comments (1)
packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts (1)

549-555: Avoid console.log in server handlers; use logger

Use the existing logger for consistent levels/transport and to avoid noisy stdout.

-  console.log("multiplePrivateLinks", multiplePrivateLinks);
+  logger.debug({ multiplePrivateLinks }, "multiplePrivateLinks");
   // Handle multiple private links using the service
   const privateLinksRepo = HashedLinkRepository.create();
   const connectedLinks = await privateLinksRepo.findLinksByEventTypeId(input.id);
-  console.log("connectedLinks", connectedLinks);
+  logger.debug({ connectedLinks }, "connectedLinks");
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb50e5 and e5c2643.

📒 Files selected for processing (2)
  • packages/trpc/server/routers/viewer/eventTypes/heavy/create.handler.ts (1 hunks)
  • packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/trpc/server/routers/viewer/eventTypes/heavy/create.handler.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: supalarry
PR: calcom/cal.com#23364
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/internal-to-api/internal-to-api.spec.ts:295-296
Timestamp: 2025-08-27T13:32:46.887Z
Learning: In calcom/cal.com, when transforming booking fields from internal to API format, tests in organizations-event-types.e2e-spec.ts already expect name field label and placeholder to be empty strings ("") rather than undefined. PR changes that set these to explicit empty strings are typically fixing implementation to match existing test expectations rather than breaking changes.
Learnt from: nangelina
PR: calcom/cal.com#23486
File: packages/app-store/kyzon-space/config.json:5-5
Timestamp: 2025-09-01T07:31:00.963Z
Learning: In Cal.com's video integration system, credential types (e.g., "kyzon-space_video") are transformed to app names by removing underscores using `cred.type.split("_").join("")` in videoClient.ts line 28. This means the key in packages/app-store/index.ts should match the underscore-removed version (e.g., "kyzon-spacevideo") rather than the original type name. This same pattern is used in other parts of the system like getCalendar.ts.
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Production builds / Build Docs
🔇 Additional comments (1)
packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts (1)

717-717: Confirm return value: pre-update eventType vs updatedEventType

Handler computes updatedEventType but returns the original eventType. If clients expect updated fields, consider returning updatedEventType.


import type { appDataSchemas } from "@calcom/app-store/apps.schemas.generated";
import { DailyLocationType } from "@calcom/app-store/locations";
import { DailyLocationType } from "@calcom/app-store/constants";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Import moved to constants — good call

This avoids pulling heavy deps from locations; nice perf/treeshaking win.

Run to confirm repo-wide consistency and a safe transition:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "1) Ensure no remaining imports from locations for DailyLocationType"
rg -nP 'import\s+{[^}]*\bDailyLocationType\b[^}]*}\s+from\s+["'\'']@calcom/app-store/locations["'\'']'

echo "2) Ensure constants exports DailyLocationType"
rg -nP '^export\s+.*\bDailyLocationType\b' packages/app-store/constants.ts

echo "3) If keeping a transitional re-export, verify it exists (or intentionally removed)"
rg -nP '\bDailyLocationType\b' packages/app-store/locations.ts -n -C2 || true

Length of output: 1095


Update test import for DailyLocationType (and MeetLocationType)
In packages/lib/server/getDefaultLocations.test.ts (line 7), change the import from

import { DailyLocationType, MeetLocationType } from "@calcom/app-store/locations";

to

import { DailyLocationType, MeetLocationType } from "@calcom/app-store/constants";
🤖 Prompt for AI Agents
In packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts around
line 5, the import for DailyLocationType is from the wrong module; update the
import source from "@calcom/app-store/locations" to
"@calcom/app-store/constants" (and do the same for MeetLocationType if present)
so the test and code use the correct exported enums/constants; ensure only the
constants module is referenced and remove any obsolete/duplicate imports.

@hbjORbj hbjORbj merged commit 086bae0 into main Sep 8, 2025
39 of 40 checks passed
@hbjORbj hbjORbj deleted the refactor/better-imports-location branch September 8, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants