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:
1 parent
c0504993a6
commit
431fbe44fc
26 files changed
+196
-210
No files matched your search
@@ -2,7 +2,26 @@ import { useMemo } from "react";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { CalendarAvailableTimeslots } from "@calcom/features/calendars/weeklyview/types/state";
|
||||
import type { IGetAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||
import type { IFromUser, IToUser } from "@calcom/features/availability/lib/getUserAvailability";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
interface UseAvailableTimeSlotsProps {
|
||||
eventDuration: number;
|
||||
@@ -27,4 +46,4 @@ export const useAvailableTimeSlots = ({ schedule, eventDuration }: UseAvailableT
|
||||
|
||||
return availableTimeslots;
|
||||
}, [schedule, eventDuration]);
|
||||
};
|
||||
};
|
||||
@@ -1,9 +1,16 @@
|
||||
import { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";
|
||||
import type { OrgMembershipLookup } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||
|
||||
import { createModule, type Module } from "../di";
|
||||
import { DI_TOKENS } from "../tokens";
|
||||
|
||||
/**
|
||||
* 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>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter that wraps ProfileRepository's static method to satisfy the OrgMembershipLookup interface.
|
||||
* This lives in the composition root where implementation details are wired together.
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
ConditionIdentifierEnum,
|
||||
ConditionOperatorEnum,
|
||||
type IAttributeSyncRule,
|
||||
type ICreateAttributeSyncInput,
|
||||
type IFieldMapping,
|
||||
type IFieldMappingFormState,
|
||||
type IFieldMappingWithOptionalId,
|
||||
@@ -80,3 +81,13 @@ export const syncFormDataSchema: z.ZodType<ISyncFormData> = z.object({
|
||||
rule: attributeSyncRuleSchema,
|
||||
syncFieldMappings: z.array(z.union([fieldMappingSchema, newFieldMappingSchema])),
|
||||
});
|
||||
|
||||
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
-2
@@ -1,6 +1,5 @@
|
||||
import type { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";
|
||||
import type { TeamRepository } from "@calcom/features/ee/teams/repositories/TeamRepository";
|
||||
import type { ZCreateAttributeSyncSchema } from "@calcom/trpc/server/routers/viewer/attribute-sync/createAttributeSync.schema";
|
||||
|
||||
import { enabledAppSlugs } from "../constants";
|
||||
import {
|
||||
@@ -11,7 +10,7 @@ import {
|
||||
AttributeSyncIntegrations,
|
||||
ConditionIdentifierEnum,
|
||||
} from "../repositories/IIntegrationAttributeSyncRepository";
|
||||
import { attributeSyncRuleSchema } from "../schemas/zod";
|
||||
import { attributeSyncRuleSchema, type ZCreateAttributeSyncSchema } from "../schemas/zod";
|
||||
|
||||
export class DuplicateAttributeWithinSyncError extends Error {
|
||||
constructor(public attributeId: string) {
|
||||
|
||||
@@ -5,8 +5,17 @@ import { renameDomain } from "@calcom/lib/domainManager/organization";
|
||||
import { getMetadataHelpers } from "@calcom/lib/getMetadataHelpers";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import type { Prisma, PrismaClient } from "@calcom/prisma/client";
|
||||
import { teamMetadataStrictSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { TAdminUpdate } from "@calcom/trpc/server/routers/viewer/organizations/adminUpdate.schema";
|
||||
import { orgSettingsSchema, teamMetadataStrictSchema } from "@calcom/prisma/zod-utils";
|
||||
import { z } from "zod";
|
||||
|
||||
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>;
|
||||
|
||||
type AdminOrganizationUpdateServiceDeps = {
|
||||
prismaClient: PrismaClient;
|
||||
|
||||
@@ -13,6 +13,8 @@ import type { TimeUnit, WorkflowTemplates, WorkflowTriggerEvents } from "@calcom
|
||||
import { WorkflowActions } from "@calcom/prisma/enums";
|
||||
import type { CalEventResponses, RecurringEvent } from "@calcom/types/Calendar";
|
||||
import type { MultiSelectCheckboxesOptionType as Option } from "@calcom/ui/components/form";
|
||||
import { z } from "zod";
|
||||
import { TIME_UNIT, WORKFLOW_ACTIONS, WORKFLOW_TEMPLATES, WORKFLOW_TRIGGER_EVENTS } from "./constants";
|
||||
|
||||
export type Workflow = {
|
||||
id: number;
|
||||
@@ -39,6 +41,31 @@ export type WorkflowStep = {
|
||||
verifiedAt?: Date | null;
|
||||
};
|
||||
|
||||
export const ZWorkflow: z.ZodType<Workflow> = 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(),
|
||||
});
|
||||
|
||||
export type FormSubmissionData = {
|
||||
responses: FORM_SUBMITTED_WEBHOOK_RESPONSES;
|
||||
routedEventTypeId: number | null;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { deleteScheduledAIPhoneCall } from "@calcom/ee/workflows/lib/reminders/a
|
||||
import { deleteScheduledEmailReminder } from "@calcom/ee/workflows/lib/reminders/emailReminderManager";
|
||||
import { deleteScheduledSMSReminder } from "@calcom/ee/workflows/lib/reminders/smsReminderManager";
|
||||
import type { WorkflowStep, WorkflowListType as WorkflowType } from "@calcom/ee/workflows/lib/types";
|
||||
import type { filterQuerySchemaStrict } from "@calcom/features/filters/lib/getTeamsFiltersFromQuery";
|
||||
import { hasFilter } from "@calcom/features/filters/lib/hasFilter";
|
||||
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
@@ -16,15 +17,29 @@ import {
|
||||
WorkflowMethods,
|
||||
type WorkflowTriggerEvents,
|
||||
} from "@calcom/prisma/enums";
|
||||
import type { TFilteredListInputSchema } from "@calcom/trpc/server/routers/viewer/workflows/filteredList.schema";
|
||||
import type { TGetVerifiedEmailsInputSchema } from "@calcom/trpc/server/routers/viewer/workflows/getVerifiedEmails.schema";
|
||||
import type { TGetVerifiedNumbersInputSchema } from "@calcom/trpc/server/routers/viewer/workflows/getVerifiedNumbers.schema";
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZGetInputSchema = z.object({
|
||||
id: z.number(),
|
||||
});
|
||||
|
||||
export type TGetInputSchema = z.infer<typeof ZGetInputSchema>;
|
||||
|
||||
export type TFilteredListInputSchema =
|
||||
| {
|
||||
filters?: z.infer<typeof filterQuerySchemaStrict>;
|
||||
}
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
export type TGetVerifiedEmailsInputSchema = {
|
||||
teamId?: number;
|
||||
};
|
||||
|
||||
export type TGetVerifiedNumbersInputSchema = {
|
||||
teamId?: number;
|
||||
};
|
||||
|
||||
const excludeFormTriggersWhereClause = {
|
||||
trigger: {
|
||||
not: {
|
||||
@@ -40,8 +55,6 @@ const getWorkflowType = (trigger: WorkflowTriggerEvents): PrismaWorkflowType =>
|
||||
return PrismaWorkflowType.EVENT_TYPE;
|
||||
};
|
||||
|
||||
export type TGetInputSchema = z.infer<typeof ZGetInputSchema>;
|
||||
|
||||
const deleteScheduledWhatsappReminder = deleteScheduledSMSReminder;
|
||||
|
||||
const includedFields = {
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { TEventInputSchema } from "@calcom/trpc/server/routers/publicViewer/event.schema";
|
||||
|
||||
export type GetPublicEventInput = {
|
||||
username: string;
|
||||
eventSlug: string;
|
||||
isTeamEvent?: boolean;
|
||||
org: string | null;
|
||||
fromRedirectOfNonOrgLink: boolean;
|
||||
};
|
||||
|
||||
export class EventRepository {
|
||||
static async getPublicEvent(input: TEventInputSchema, userId?: number) {
|
||||
static async getPublicEvent(input: GetPublicEventInput, userId?: number) {
|
||||
const event = await getPublicEvent(
|
||||
input.username,
|
||||
input.eventSlug,
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
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,25 +0,0 @@
|
||||
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 "./procedures/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,
|
||||
});
|
||||
@@ -26,8 +26,34 @@ import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { WebhookTriggerEvents, WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
||||
import { bookingMetadataSchema, type PlatformClientParams } from "@calcom/prisma/zod-utils";
|
||||
import type { TNoShowInputSchema } from "@calcom/trpc/server/routers/loggedInViewer/markNoShow.schema";
|
||||
import type { TFunction } from "i18next";
|
||||
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>;
|
||||
|
||||
import handleSendingAttendeeNoShowDataToApps from "./noShow/handleSendingAttendeeNoShowDataToApps";
|
||||
|
||||
export type NoShowAttendees = { email: string; noShow: boolean }[];
|
||||
|
||||
@@ -1,13 +1,40 @@
|
||||
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
||||
import { timeZoneSchema } from "@calcom/lib/dayjs/timeZone.schema";
|
||||
import { hasEditPermissionForUserID } from "@calcom/lib/hasEditPermissionForUser";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { transformScheduleToAvailabilityForAtom } from "@calcom/lib/schedules/transformers/for-atom";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { TUpdateInputSchema } from "@calcom/trpc/server/routers/viewer/availability/schedule/update.schema";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { z } from "zod";
|
||||
import { ScheduleRepository } from "../repositories/ScheduleRepository";
|
||||
|
||||
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>;
|
||||
|
||||
interface IUpdateScheduleOptions {
|
||||
input: TUpdateInputSchema;
|
||||
user: Pick<NonNullable<TrpcSessionUser>, "id" | "defaultScheduleId" | "timeZone">;
|
||||
|
||||
+1
-1
@@ -3,9 +3,9 @@ import { z } from "zod";
|
||||
import type { FORM_SUBMITTED_WEBHOOK_RESPONSES } from "@calcom/app-store/routing-forms/lib/formSubmissionUtils";
|
||||
import { scheduleWorkflowReminders } from "@calcom/ee/workflows/lib/reminders/reminderScheduler";
|
||||
import type { Workflow } from "@calcom/ee/workflows/lib/types";
|
||||
import { ZWorkflow } from "@calcom/ee/workflows/lib/types";
|
||||
import { CreditService } from "@calcom/features/ee/billing/credit-service";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { ZWorkflow } from "@calcom/trpc/server/routers/viewer/workflows/getAllActiveWorkflows.schema";
|
||||
|
||||
import { shouldTriggerFormSubmittedNoEvent } from "./formSubmissionValidation";
|
||||
|
||||
|
||||
Reference in new issue
Block a user