* fix: APIV2 team membership addition * feat: Add trimming for email domain and orgAutoAcceptEmail in auto-accept logic - Trim whitespace from both user email domain and orgAutoAcceptEmail - Ensures consistent matching even with accidental whitespace - Addresses feedback from PR review Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * simplify * feat: Use shared OrganizationMembershipService in TRPC for consistent auto-accept logic - Create OrganizationMembershipService.container.ts for DI in TRPC - Update getOrgConnectionInfo to apply trimming + case-insensitive comparison - Precompute auto-accept decisions in createNewUsersConnectToOrgIfExists using the service - Use service in handleNewUsersInvites for consistent auto-accept determination - Ensures both API v2 and TRPC paths use identical trimming and normalization logic Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Revert "feat: Use shared OrganizationMembershipService in TRPC for consistent auto-accept logic" This reverts commit 0b2bd28b6e32e8c1d3dea139ca8ff9cbf402ac00. * refactor: Unify OrganizationRepository and remove duplicate PrismaOrganizationRepository (#24869) * refactor: Convert OrganizationRepository from static to instance methods - Add constructor accepting deps object with prismaClient - Convert all static methods to instance methods - Add getOrganizationAutoAcceptSettings method - Create singleton instance export in repository barrel file - Update API v2 OrganizationsRepository to extend from OrganizationRepository - Update all call sites to use singleton instance - Add platform-libraries organizations.ts export - Fix mock imports to use repository barrel - Fix unsafe optional chaining in next-auth-options.ts - Fix any types in test files with proper type inference Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update all imports to use OrganizationRepository barrel export - Update imports from direct OrganizationRepository file to barrel export - This ensures mocks work correctly in tests - Fixes 202 failing tests related to organizationRepository mock Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update test mocks to use partial mock pattern - Convert organizationMock to partial mock that preserves real class - Add proper prisma mocks to failing test files - Remove old OrganizationRepository mocks from test files - This fixes test failures related to mock interception Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Export mocked singleton and update tests to use it directly - Export mockedSingleton as organizationRepositoryMock from organizationMock - Update delegationCredential.test.ts to import and use the exported mock - This fixes 'vi.mocked(...).mockResolvedValue is not a function' errors Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Use platform-libraries import for API v2 OrganizationRepository API v2 should import shared features through @calcom/platform-libraries instead of directly from @calcom/features to maintain proper architectural boundaries and packaging/licensing separation. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Implement DI pattern for OrganizationRepository - Create OrganizationRepository.module.ts and .container.ts for DI - Replace singleton pattern with getOrganizationRepository() across 20 files - Update platform-libraries to export getOrganizationRepository - Delete duplicate PrismaOrganizationRepository.ts - Remove singleton export file (repositories/index.ts) - Update test mocks to use DI container pattern - All type checks and unit tests passing Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Implement read/write client separation in OrganizationRepository - Updated OrganizationRepository constructor to accept optional prismaWriteClient parameter - Routed all write operations (create, update) through prismaWrite client - Routed all read operations (find, get) through prismaRead client - Updated API v2 OrganizationsRepository to pass both dbRead.prisma and dbWrite.prisma to super() - Optimized getOrganizationRepository() calls by storing in local variables to avoid repeated function calls - This fixes the critical issue where API v2 was passing read-only client to base class with write methods Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Fix mock setup and optimize getOrganizationRepository() calls - Fixed verify-email.test.ts mock to return mocked repository instance instead of scenario helper object - Added mockReset to organizationMock.ts beforeEach to properly reset mock implementations between tests - Added local variables in page.tsx to store getOrganizationRepository() result for consistency This fixes the issue where getOrganizationRepository() was returning organizationScenarios.organizationRepository (scenario helper) instead of the actual mocked repository instance, causing findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail to be undefined. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Simplify OrganizationRepository to use single prismaClient - Updated base OrganizationRepository constructor to accept only { prismaClient } instead of { prismaClient, prismaWriteClient? } - Replaced this.prismaRead and this.prismaWrite with single this.prismaClient property - Updated API v2 OrganizationsRepository to pass only dbWrite.prisma as prismaClient - Removed unused PrismaReadService import from API v2 - All read and write operations now use the same client instance This simplifies the architecture as requested - API v2 uses write client for all operations, and apps/web uses the client from DI container. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: Match OrganizationsRepository.findById signature with base class The findById method in OrganizationsRepository was using a different signature than the base OrganizationRepository class, causing type errors in CI. Changed from: findById(organizationId: number) Changed to: findById({ id }: { id: number }) This matches the base class signature and resolves the CI unit test failures. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update all findById call sites to use object parameter Fixed 6 call sites in API v2 that were calling findById with a number instead of the required { id: number } object parameter: - is-org.guard.ts - is-admin-api-enabled.guard.ts - is-webhook-in-org.guard.ts - organizations.service.ts - managed-organizations.service.ts (2 call sites) This resolves the API v2 build failure caused by the signature change in OrganizationsRepository.findById to match the base class. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Remove redundant findById override from OrganizationsRepository The findById method was duplicating the base class OrganizationRepository implementation. Both methods had identical logic (filtering by isOrganization: true), so the override was unnecessary. Since OrganizationsRepository extends OrganizationRepository and passes dbWrite.prisma to the base constructor, the base class method already provides the exact same functionality. This resolves the API v2 build failure by eliminating the duplicate method that was causing conflicts. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Remove unncessary changes * Store in variable * Revert "Remove unncessary changes" This reverts commit af9351786a21616c9508c441191c17f2374fb2cc. * Revert dbRead/dbWrite changes * Add organizations library to tsconfig.json --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
A progressive Node.js framework for building efficient and scalable server-side applications.
Description
Cal.com is using the Nest framework TypeScript starter repository.
Installation
$ yarn install
Prisma setup
$ yarn prisma generate
Env setup
Copy .env.example to .env and fill values.
Add license Key to Deployment table in DB
id, logo, theme, licenseKey, agreedLicenseAt:- 1, null, null, '00000000-0000-0000-0000-000000000000', '2023-05-15 21:39:47.611'
Replace with your actual license key.
your CALCOM_LICENSE_KEY env var need to contain the same value
.env CALCOM_LICENSE_KEY=00000000-0000-0000-0000-000000000000
Running the app
Development
$ yarn run start
OR if you don't want to use docker, you can run following command.
$ yarn dev:no-docker
Additionally you can run following command(in different terminal) to ensure that any change in any of the dependencies is rebuilt and detected. It watches platform-libraries, platform-constants, platform-enums, platform-utils, platform-types.
$ yarn run dev:build:watch
If you are making changes in packages/platform/libraries, you should run the following command too that would connect your local packages/platform/libraries to the api/v2
$ yarn local
watch mode
$ yarn run start:dev
production mode
$ yarn run start:prod
## Test
```bash
# unit tests
$ yarn run test
# e2e tests
$ yarn run test:e2e
# e2e tests in watch mode
$ yarn test:e2e:watch
# run specific e2e test file in watch mode
$ yarn test:e2e:watch --testPathPattern=filePath
# test coverage
$ yarn run test:cov
Conventions
Guards
- In case a guard would return "false" for "canActivate" instead throw ForbiddenException with an error message containing guard name and the error.
- In case a guard would return "false" for "canActivate" DO NOT cache the result in redis, because we don't want that someone is forbidden, updates whatever was the problem, and then has to wait for cache to expire. We only cache in redis guard results where "canAccess" is "true".
- If you use ApiAuthGuard but want that only specific auth method is allowed, for example, api key, then you also need to add
@ApiAuthGuardOnlyAllow(["API_KEY"])under the@UseGuards(ApiAuthGuard). Shortly, useApiAuthGuardOnlyAllowto specify which auth methods are allowed byApiAuthGuard. IfApiAuthGuardOnlyAllowis not used or nothing is passed to it or empty array it means that all auth methods are allowed.
Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Stay in touch
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
License
Nest is MIT licensed.