-
Notifications
You must be signed in to change notification settings - Fork 11.4k
perf: convert services to factory functions and add TypeScript project references #26117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…type exports This change converts CRM, Calendar, Payment, and Analytics services from exporting classes to exporting factory functions that return interface types. This prevents SDK types (HubSpot, Stripe, etc.) from leaking into the type system when TypeScript emits .d.ts files. Services modified: - CRM: hubspot, salesforce, closecom, pipedrive-crm, zoho-bigin, zohocrm - Calendar: all 13 calendar services - Payment: stripe, paypal, alby, btcpayserver, hitpay, mock-payment-app - Analytics: dub Video adapters were audited and already use factory pattern. WIP: Salesforce CRM service has a type error that needs fixing. Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
- getAnalytics.ts: call factory function instead of new - getConnectedApps.ts: call factory function instead of new - salesforce/CrmService.ts: fix type assertion with default value - salesforce/routingForm/incompleteBookingAction.ts: use factory function - salesforce/routingFormBookingFormHandler.ts: use factory function Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
…methods - Create SalesforceCRM interface extending CRM with findUserEmailFromLookupField and incompleteBookingWriteToRecord methods - Add createSalesforceCrmServiceWithSalesforceType factory function for internal Salesforce modules - Update routing form files to use the new factory function with proper typing Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
The findUserEmailFromLookupField method returns { email: string; recordType: RoutingReasons } | undefined,
not string | undefined. Updated the interface to match the actual implementation.
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
- Update calendar API add files to use factory functions (7 files) - Update Google Calendar test files to use factory functions (3 files) - Update Salesforce test files to use SalesforceCRM interface - Add testMode parameter to createSalesforceCrmServiceWithSalesforceType - Remove unused @ts-expect-error directive in bookingScenario.ts Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
…rvice-specific methods Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
… function Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
… function Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
… type error Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
…nd payment services Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
… new Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
…vice in e2e test Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 93 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.
volnei
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beyond the review, I ran it locally and see no issues. Looks good 🚀
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 93 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.
What does this PR do?
Converts CRM, Calendar, Payment, and Analytics services from exporting classes to exporting factory functions that return interface types. This prevents SDK types (HubSpot, Stripe, jsforce, etc.) from leaking into TypeScript's emitted
.d.tsfiles.Additionally, this PR sets up TypeScript project references so that
@calcom/trpcconsumes prebuilt.d.tsfiles from@calcom/app-storeinstead of typechecking source files. This reduces the tRPC build file count from 7,733 to 5,618 files (27% reduction).Background: When TypeScript emits
.d.tsfiles for exported classes, it includes private fields. If a class hasprivate hubspotClient: hubspot.Client, TypeScript must resolve the full HubSpot SDK type graph (1,822.d.tsfiles). By exporting factory functions typed as returning interfaces (e.g.,CRM,Calendar), the emitted declarations only reference the interface types, not SDK internals.Services modified:
Video adapters were audited and already use factory pattern - no changes needed.
Updates since last revision
Latest - Merged main to resolve conflicts:
packages/app-store/_utils/getCalendar.ts- kept main's refactored structure while using factory function pattern (createCalendarServiceinstead ofnew CalendarService)packages/app-store/googlecalendar/lib/__tests__/CalendarService.test.ts- accepted main's version which removed the "Delegation Credential Batching" tests (these tests were moved/refactored in main)Previous - Code cleanup:
deletePayment.ts,handleNoShowFee.ts,handlePaymentRefund.ts,handlePayment.ts) and test file (getCalendarsEvents.test.ts).gitignoreto use*.tsbuildinfopattern to catch all TypeScript build info files (not justtsconfig.tsbuildinfo)Previous - Renamed factory functions to
Build*naming convention:Build*prefix to make it clear they are factory functions, not classes:create*CalendarService→BuildCalendarServicecreate*CrmService→BuildCrmServicePaymentService→BuildPaymentServicecreateDubAnalyticsService→BuildAnalyticsServicegetConnectedApps.ts,handlePayment.ts,deletePayment.ts,handleNoShowFee.ts,handlePaymentRefund.ts)handleNoShowFee.test.tsto useBuildPaymentServicePrevious - Fixed E2E API v2 test for ICS calendar service:
calendars.controller.e2e-spec.tsto mock the factory function instead of the class prototypePrevious - Renamed
dist-typestotypesfor consistency:dist-typestotypesto match the convention used by@calcom/trpcand other packages in the monorepoPrevious - Fixed circular build dependency:
@calcom/trpc#build→@calcom/app-store#build:typestypesVersionsfallback pattern["./types/*", "./*"]handles this: uses prebuilt declarations when they exist, falls back to source files otherwisePrevious - TypeScript project references setup:
packages/app-store/tsconfig.build.jsonwith composite settings for declaration emit totypes/typesandtypesVersionstopackages/app-store/package.jsonto redirect type resolutionbuild:typesscript to app-store for generating declarationsMandatory Tasks (DO NOT REMOVE)
How should this be tested?
yarn type-check:ci --forceto verify no type errorscd packages/app-store && yarn build:typesto generate declarations (should complete without errors)yarn buildon the tRPC package to verify the build still worksTZ=UTC yarn test packages/features/bookings/lib/payment/handleNoShowFee.test.tsto verify payment test mocks workTZ=UTC yarn test packages/features/calendars/lib/getCalendarsEvents.test.tsto verify calendar test mocks workHuman Review Checklist
packages/app-store/_utils/getCalendar.tscorrectly usescreateCalendarServicefactory function (lines 64 and 76)Build*prefix consistently (e.g.,BuildPaymentService,BuildCalendarService,BuildCrmService,BuildAnalyticsService)deletePayment.ts,handleNoShowFee.ts,handlePaymentRefund.tsafter comment removal\.PaymentService,\.CalendarService,\.CrmServiceto ensure all call sites were updated to useBuild*namesjest.spyOn(module, "functionName").mockImplementation()instead ofjest.spyOn(Class.prototype, "method"). Verify this pattern is correctly applied.instanceofchecks against these service classes (would break with factory pattern)build:typesmay surface pre-existing Prisma type mismatches - these are NOT caused by this PR.Checklist
Link to Devin run: https://app.devin.ai/sessions/5508be898fa641a99c0a30b83c8d3162
Requested by: keith@cal.com (@keithwillcode)