Merge branch 'main' into production

pull/9078/head
Agusti Fernandez Pardo 2022-09-06 18:13:06 +02:00
commit 22359dda1b
9 changed files with 115 additions and 20 deletions

View File

@ -1,3 +1,6 @@
API_KEY_PREFIX=cal_
DATABASE_URL="postgresql://postgres:@localhost:5450/calendso"
NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
# Get it in console.cal.com
CALCOM_LICENSE_KEY=""

42
LICENSE Normal file
View File

@ -0,0 +1,42 @@
The Cal.com Enterprise Edition (EE) license (the “EE License”)
Copyright (c) 2020-present Cal.com, Inc
With regard to the Cal.com Software:
This software and associated documentation files (the "Software") may only be
used in production, if you (and any entity that you represent) have agreed to,
and are in compliance with, the Cal.com Subscription Terms available
at https://cal.com/terms (the “EE Terms”), or other agreements governing
the use of the Software, as mutually agreed by you and Cal.com, Inc ("Cal.com"),
and otherwise have a valid Cal.com Enterprise Edition subscription ("EE Subscription")
for the correct number of hosts as defined in the EE Terms ("Hosts"). Subject to the foregoing sentence,
you are free to modify this Software and publish patches to the Software. You agree
that Cal.com and/or its licensors (as applicable) retain all right, title and interest in
and to all such modifications and/or patches, and all such modifications and/or
patches may only be used, copied, modified, displayed, distributed, or otherwise
exploited with a valid EE Subscription for the correct number of hosts.
Notwithstanding the foregoing, you may copy and modify the Software for development
and testing purposes, without requiring a subscription. You agree that Cal.com and/or
its licensors (as applicable) retain all right, title and interest in and to all such
modifications. You are not granted any other rights beyond what is expressly stated herein.
Subject to the foregoing, it is forbidden to copy, merge, publish, distribute, sublicense,
and/or sell the Software.
This EE License applies only to the part of this Software that is not distributed under
the AGPLv3 license. Any part of this Software distributed under the MIT license or which
is served client-side as an image, font, cascading stylesheet (CSS), file which produces
or is compiled, arranged, augmented, or combined into client-side JavaScript, in whole or
in part, is copyrighted under the AGPLv3 license. The full text of this EE License shall
be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
For all third party components incorporated into the Cal.com Software, those
components are licensed under the original license provided by the owner of the
applicable component.

View File

@ -1,4 +1,19 @@
# Cal.com Public API (Enterprise Only)
<!-- PROJECT LOGO -->
<div align="center">
<a href="https://cal.com/enterprise">
<img src="https://user-images.githubusercontent.com/8019099/133430653-24422d2a-3c8d-4052-9ad6-0580597151ee.png" alt="Logo">
</a>
<a href="https://cal.com/enterprise">Get Started with Enterprise</a>
</div>
# Cal.com Public API - Enterprise Edition
Welcome to the Public API Enterprise Edition ("/apps/api") of the Cal.com Public API.
The [/apps/api](https://github.com/calcom/cal.com/tree/main/apps/api) subfolder is the place for our Public API, which we serve at api.cal.com, and enterprise customers can also run [enterprise-grade](https://cal.com/enterprise)
> _❗ WARNING: This repository is copyrighted (unlike our [main repo](https://github.com/calcom/cal.com)). You are not allowed to use this code to host your own version of app.cal.com without obtaining a proper [license](https://cal.com/pricing?infra) first❗_
This is the public REST api for cal.com.
It exposes CRUD Endpoints of all our most important resources.
@ -30,7 +45,7 @@ And it makes it easy for anyone to integrate with Cal.com at the application pro
```sh
cp apps/api/.env.example apps/api/.env
cp packages/prisma/.env.example packages/prisma/.env
cp .env.example .env
```
1. Install packages with yarn
@ -84,7 +99,7 @@ We're calling several packages from monorepo, this need to be transpiled before
"@calcom/app-store",
"@calcom/prisma",
"@calcom/lib",
"@calcom/ee",
"@calcom/features",
```
## API Endpoint Validation
@ -186,18 +201,21 @@ Add a deployment or go to an existing one.
Activate API or Admin addon
Provide your `DATABASE_URL`
Now you can call api.cal.com?key=CALCOM_LICENSE_KEY, which will connect to your own databaseUrl.
## How to deploy
We recommend deploying API in vercel.
There's some settings that you'll need to setup.
Under Vercel > Your API Deployment > Settings
Under Vercel > Your API Deployment > Settings
In General > Build & Development Settings
BUILD COMMAND: `yarn turbo run build --scope=@calcom/api --include-dependencies --no-deps`
OUTPUT DIRECTORY: `apps/api/.next`
See `scripts/vercel-deploy.sh` for more info on how the deployment is done.
## Environment variables
Lastly API requires an env var for `DATABASE_URL`
Lastly API requires an env var for `DATABASE_URL` and `CALCOM_LICENSE_KEY`

View File

@ -1,6 +1,7 @@
import { NextMiddleware } from "next-api-middleware";
import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys";
import { hashAPIKey } from "@calcom/features/ee/api-keys/lib/apiKeys";
import checkLicense from "@calcom/features/ee/common/server/checkLicense";
import { isAdminGuard } from "@lib/utils/isAdmin";
@ -14,6 +15,9 @@ export const dateNotInPast = function (date: Date) {
// This verifies the apiKey and sets the user if it is valid.
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
const hasValidLicense = await checkLicense(process.env.CALCOM_LICENSE_KEY || "");
if (!hasValidLicense)
return res.status(401).json({ error: "Invalid or missing CALCOM_LICENSE_KEY environment variable" });
const { prisma, userId, isAdmin } = req;
// If the user is an admin and using a license key (from customPrisma), skip the apiKey check.
if (userId === 0 && isAdmin) {

View File

@ -3,17 +3,15 @@
const withTM = require("next-transpile-modules")([
"@calcom/app-store",
"@calcom/core",
"@calcom/ee",
"@calcom/lib",
"@calcom/prisma",
"@calcom/stripe",
"@calcom/ui",
"@calcom/dayjs",
"@calcom/emails",
"@calcom/dayjs",
"@calcom/embed-core",
"@calcom/dayjs",
"@calcom/embed-snippet",
"@calcom/features",
"@calcom/lib",
"@calcom/prisma",
"@calcom/trpc",
"@calcom/ui",
]);
const { withAxiom } = require("next-axiom");

View File

@ -10,7 +10,7 @@
"build": "next build",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next",
"dev": "PORT=3002 next dev",
"lint": "next lint",
"lint": "eslint . --ignore-path .gitignore",
"lint:report": "eslint . --format json --output-file ../../lint-results/api.json",
"lint:fix": "eslint . --ext .ts,.js,.tsx,.jsx --fix",
"start": "PORT=3002 next start",
@ -25,21 +25,21 @@
"node-mocks-http": "^1.11.0"
},
"dependencies": {
"@calcom/app-store-cli": "*",
"@calcom/prisma": "*",
"@calcom/trpc": "*",
"@sentry/nextjs": "^6.19.7",
"bcryptjs": "^2.4.3",
"memory-cache": "^0.2.0",
"modify-response-middleware": "^1.1.0",
"next": "^12.2.0",
"next": "^12.2.5",
"next-api-middleware": "^1.0.1",
"next-axiom": "^0.10.0",
"next-swagger-doc": "^0.3.4",
"next-transpile-modules": "^9.0.0",
"next-validations": "^0.2.0",
"typescript": "^4.6.4",
"typescript": "^4.7.4",
"tzdata": "^1.0.30",
"uuid": "^8.3.2",
"zod": "^3.16.0"
"zod": "^3.18.0"
}
}

21
pages/api/me/_get.ts Normal file
View File

@ -0,0 +1,21 @@
import type { NextApiRequest } from "next";
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
import { schemaUserReadPublic } from "@lib/validations/user";
import { User } from ".prisma/client";
async function handler(req: NextApiRequest): Promise<{ error?: string; user?: Partial<User> }> {
if (!prisma) return { error: "Cant connect to database" };
console.log(req);
if (!req.userId) return { error: "No user id found" };
const data = await prisma.user.findUniqueOrThrow({ where: { id: req.userId } });
if (!data) return { error: "You need to pass apiKey" };
const user = schemaUserReadPublic.parse(data);
return { user };
}
export default defaultHandler({
GET: Promise.resolve({ default: defaultResponder(handler) }),
});

9
pages/api/me/index.ts Normal file
View File

@ -0,0 +1,9 @@
import { defaultHandler } from "@calcom/lib/server";
import { withMiddleware } from "@lib/helpers/withMiddleware";
export default withMiddleware("HTTP_GET")(
defaultHandler({
GET: import("./_get"),
})
);

View File

@ -9,6 +9,6 @@
"@/*": ["*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "../../packages/types/next-auth.d.ts"],
"exclude": ["node_modules", "templates", "auth"]
}