refactor: decouple @calcom/features from @calcom/trpc/server (#27751)

* make GetPublicEventInput

* space

* mv feature flags router to trpc

* remove trpc imports

* wip

* mv OrgMembershipLookup to features

* fix

* fix

* update

* fix

* revert formatting-only changes to improve PR reviewability

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

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Benny JooandDevin AI authored and GitHub committed 2026-02-10 09:28:37 -03:00
1 parent c0504993a6
commit 431fbe44fc
26 files changed
+196 -210

No files matched your search

@@ -0,0 +1,25 @@
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
import type { AppFlags } from "@calcom/features/flags/config";
import publicProcedure from "@calcom/trpc/server/procedures/publicProcedure";
import { router } from "@calcom/trpc/server/trpc";
import { z } from "zod";
import { map } from "./map";
export const featureFlagRouter = router({
list: publicProcedure.query(async () => {
const featuresRepository = getFeaturesRepository();
return featuresRepository.getAllFeatures();
}),
checkTeamFeature: publicProcedure
.input(
z.object({
teamId: z.number(),
feature: z.string(),
})
)
.query(async ({ input }) => {
const featuresRepository = getFeaturesRepository();
return featuresRepository.checkIfTeamHasFeature(input.teamId, input.feature as keyof AppFlags);
}),
map,
});
@@ -0,0 +1,12 @@
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
import prisma from "@calcom/prisma";
import publicProcedure from "@calcom/trpc/server/procedures/publicProcedure";
/**
* TRPC procedure that returns a map of all feature flags and their enabled status.
* Uses the FeaturesRepository to handle caching and database access.
*/
export const map = publicProcedure.query(async () => {
const featuresRepository = new FeaturesRepository(prisma);
return featuresRepository.getFeatureFlagMap();
});
@@ -1,26 +1 @@
import { z } from "zod";
export const ZNoShowInputSchema = z
.object({
bookingUid: z.string(),
attendees: z
.array(
z.object({
email: z.string(),
noShow: z.boolean(),
})
)
.optional(),
noShowHost: z.boolean().optional(),
})
.refine(
(data) => {
return (data.attendees && data.attendees.length > 0) || data.noShowHost !== undefined;
},
{
message: "At least one of 'attendees' or 'noShowHost' must be provided",
path: ["attendees", "noShowHost"],
}
);
export type TNoShowInputSchema = z.infer<typeof ZNoShowInputSchema>;
export { type TNoShowInputSchema, ZNoShowInputSchema } from "@calcom/features/handleMarkNoShow";
@@ -1,4 +1,5 @@
import z from "zod";
import type { GetPublicEventInput } from "@calcom/features/eventtypes/repositories/EventRepository";
// Note: fromRedirectOfNonOrgLink has .default(false), so input has it optional but output has it required
@@ -10,13 +11,7 @@ export type TEventInputSchemaInput = {
fromRedirectOfNonOrgLink?: boolean;
};
export type TEventInputSchema = {
username: string;
eventSlug: string;
isTeamEvent?: boolean;
org: string | null;
fromRedirectOfNonOrgLink: boolean;
};
export type TEventInputSchema = GetPublicEventInput;
export const ZEventInputSchema: z.ZodType<TEventInputSchema, z.ZodTypeDef, TEventInputSchemaInput> = z.object({
username: z.string(),
@@ -1,6 +1,6 @@
import { featureFlagRouter } from "@calcom/features/flags/server/router";
import { router } from "../../trpc";
import app_RoutingForms from "../apps/routing-forms/_router";
import { featureFlagRouter } from "../features/_router";
import { loggedInViewerRouter } from "../loggedInViewer/_router";
import { publicViewerRouter } from "../publicViewer/_router";
import { timezonesRouter } from "../publicViewer/timezones/_router";
@@ -1,17 +1,4 @@
import { z } from "zod";
import type { ICreateAttributeSyncInput } from "@calcom/features/ee/integration-attribute-sync/repositories/IIntegrationAttributeSyncRepository";
import {
attributeSyncRuleSchema,
newFieldMappingSchema,
export {
createAttributeSyncSchema,
type ZCreateAttributeSyncSchema,
} from "@calcom/features/ee/integration-attribute-sync/schemas/zod";
export const createAttributeSyncSchema: z.ZodType<ICreateAttributeSyncInput> = z.object({
name: z.string().min(1, "Name is required"),
credentialId: z.number(),
rule: attributeSyncRuleSchema,
syncFieldMappings: z.array(newFieldMappingSchema),
enabled: z.boolean(),
});
export type ZCreateAttributeSyncSchema = ICreateAttributeSyncInput;
@@ -1,30 +1,4 @@
import { z } from "zod";
import { timeZoneSchema } from "@calcom/lib/dayjs/timeZone.schema";
export const ZUpdateInputSchema = z.object({
scheduleId: z.number(),
timeZone: timeZoneSchema.optional(),
name: z.string().trim().min(1, "Schedule name cannot be empty").optional(),
isDefault: z.boolean().optional(),
schedule: z
.array(
z.array(
z.object({
start: z.date(),
end: z.date(),
})
)
)
.optional(),
dateOverrides: z
.array(
z.object({
start: z.date(),
end: z.date(),
})
)
.optional(),
});
export type TUpdateInputSchema = z.infer<typeof ZUpdateInputSchema>;
export {
type TUpdateInputSchema,
ZUpdateInputSchema,
} from "@calcom/features/schedules/services/ScheduleService";
@@ -1,12 +1,4 @@
import { z } from "zod";
import { orgSettingsSchema } from "@calcom/prisma/zod-utils";
export const ZAdminUpdate = z.object({
id: z.number(),
name: z.string().optional(),
slug: z.string().nullish(),
organizationSettings: orgSettingsSchema.unwrap().optional(),
});
export type TAdminUpdate = z.infer<typeof ZAdminUpdate>;
export {
type TAdminUpdate,
ZAdminUpdate,
} from "@calcom/features/ee/organizations/lib/service/AdminOrganizationUpdateService";
@@ -7,8 +7,6 @@ import type {
CurrentSeats,
EventType,
GetAvailabilityUser,
IFromUser,
IToUser,
UserAvailabilityService,
} from "@calcom/features/availability/lib/getUserAvailability";
import type { CheckBookingLimitsService } from "@calcom/features/bookings/lib/checkBookingLimits";
@@ -59,6 +57,8 @@ import type { Logger } from "tslog";
import { v4 as uuid } from "uuid";
import type { TGetScheduleInputSchema } from "./getSchedule.schema";
import type { GetScheduleOptions } from "./types";
import type { OrgMembershipLookup } from "@calcom/features/di/modules/OrgMembershipLookup";
import type { IGetAvailableSlots } from "@calcom/features/bookings/Booker/hooks/useAvailableTimeSlots";
const log = logger.getSubLogger({ prefix: ["[slots/util]"] });
const DEFAULT_SLOTS_CACHE_TTL = 2000;
@@ -67,37 +67,10 @@ type GetAvailabilityUserWithDelegationCredentials = Omit<NonNullable<GetAvailabi
credentials: CredentialForCalendarService[];
};
export interface IGetAvailableSlots {
slots: Record<
string,
{
time: string;
attendees?: number | undefined;
bookingUid?: string | undefined;
away?: boolean | undefined;
fromUser?: IFromUser | undefined;
toUser?: IToUser | undefined;
reason?: string | undefined;
emoji?: string | undefined;
showNotePublicly?: boolean | undefined;
}[]
>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
troubleshooter?: any;
}
export type GetAvailableSlotsResponse = Awaited<
ReturnType<(typeof AvailableSlotsService)["prototype"]["_getAvailableSlots"]>
>;
/**
* Minimal capability interface for looking up a user's organization membership.
* Used as a fallback when org context can't be determined from request or eventType.
*/
export interface OrgMembershipLookup {
findFirstOrganizationIdForUser(args: { userId: number }): Promise<number | null>;
}
export interface IAvailableSlotsService {
oooRepo: PrismaOOORepository;
scheduleRepo: ScheduleRepository;
@@ -2,12 +2,13 @@
import { z } from "zod";
import type { TFilteredListInputSchema } from "@calcom/features/ee/workflows/repositories/WorkflowRepository";
import { filterQuerySchemaStrict } from "@calcom/features/filters/lib/getTeamsFiltersFromQuery";
export const ZFilteredListInputSchema = z
export const ZFilteredListInputSchema: z.ZodType<TFilteredListInputSchema> = z
.object({
filters: filterQuerySchemaStrict.optional(),
})
.nullish();
export type TFilteredListInputSchema = z.infer<typeof ZFilteredListInputSchema>;
export type { TFilteredListInputSchema };
@@ -1,63 +1,9 @@
import type { Workflow } from "@calcom/ee/workflows/lib/types";
import { ZWorkflow } from "@calcom/ee/workflows/lib/types";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import { z } from "zod";
import {
TIME_UNIT,
WORKFLOW_ACTIONS,
WORKFLOW_TEMPLATES,
WORKFLOW_TRIGGER_EVENTS,
} from "@calcom/ee/workflows/lib/constants";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
// Define types first to use with z.ZodType annotations
type TWorkflow = {
id: number;
name: string;
trigger: (typeof WORKFLOW_TRIGGER_EVENTS)[number];
time: number | null;
timeUnit: (typeof TIME_UNIT)[number] | null;
userId: number | null;
teamId: number | null;
steps: {
id: number;
action: (typeof WORKFLOW_ACTIONS)[number];
sendTo: string | null;
template: (typeof WORKFLOW_TEMPLATES)[number];
reminderBody: string | null;
emailSubject: string | null;
numberRequired: boolean | null;
sender: string | null;
includeCalendarEvent: boolean;
numberVerificationPending: boolean;
verifiedAt?: Date | null;
}[];
};
export const ZWorkflow: z.ZodType<TWorkflow> = z.object({
id: z.number(),
name: z.string(),
trigger: z.enum(WORKFLOW_TRIGGER_EVENTS),
time: z.number().nullable(),
timeUnit: z.enum(TIME_UNIT).nullable(),
userId: z.number().nullable(),
teamId: z.number().nullable(),
steps: z
.object({
id: z.number(),
action: z.enum(WORKFLOW_ACTIONS),
sendTo: z.string().nullable(),
template: z.enum(WORKFLOW_TEMPLATES),
reminderBody: z.string().nullable(),
emailSubject: z.string().nullable(),
numberRequired: z.boolean().nullable(),
sender: z.string().nullable(),
includeCalendarEvent: z.boolean(),
numberVerificationPending: z.boolean(),
verifiedAt: z.coerce.date().nullable().optional(),
})
.array(),
});
type TWorkflows = { workflow: TWorkflow }[] | undefined;
type TWorkflows = { workflow: Workflow }[] | undefined;
export const ZWorkflows: z.ZodType<TWorkflows> = z
.object({
@@ -1,9 +1,8 @@
import type { TGetVerifiedEmailsInputSchema } from "@calcom/features/ee/workflows/repositories/WorkflowRepository";
import { z } from "zod";
export type TGetVerifiedEmailsInputSchema = {
teamId?: number;
};
export const ZGetVerifiedEmailsInputSchema: z.ZodType<TGetVerifiedEmailsInputSchema> = z.object({
teamId: z.number().optional(),
});
export type { TGetVerifiedEmailsInputSchema };
@@ -1,9 +1,8 @@
import type { TGetVerifiedNumbersInputSchema } from "@calcom/features/ee/workflows/repositories/WorkflowRepository";
import { z } from "zod";
export type TGetVerifiedNumbersInputSchema = {
teamId?: number;
};
export const ZGetVerifiedNumbersInputSchema: z.ZodType<TGetVerifiedNumbersInputSchema> = z.object({
teamId: z.number().optional(),
});
export type { TGetVerifiedNumbersInputSchema };