* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main: - Rebrand Cal.com to Cal.diy across the entire codebase - Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions - Switch license from AGPL-3.0 to MIT - Remove docs/ directory (migrated to Nextra at cal.diy) - Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc. - Clean up .env.example for self-hosted Cal.diy - Update Docker image references to calcom/cal.diy - Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork - Add PR welcome bot for Cal.diy contributors - Fix API v2 breaking changes oasdiff ignore entries - Replace Blacksmith CI runners with default GitHub Actions 3893 files changed, 20789 insertions(+), 411020 deletions(-) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * rip out org related comments in api v2 --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
|
|
import { cookies, headers } from "next/headers";
|
|
import { NextResponse } from "next/server";
|
|
import type { NextRequest } from "next/server";
|
|
|
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|
import handleCancelBooking from "@calcom/features/bookings/lib/handleCancelBooking";
|
|
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
|
import getIP from "@calcom/lib/getIP";
|
|
import { piiHasher } from "@calcom/lib/server/PiiHasher";
|
|
import { bookingCancelWithCsrfSchema } from "@calcom/prisma/zod-utils";
|
|
import { validateCsrfToken } from "@calcom/web/lib/validateCsrfToken";
|
|
|
|
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
|
|
|
async function handler(req: NextRequest) {
|
|
let appDirRequestBody;
|
|
try {
|
|
appDirRequestBody = await req.json();
|
|
} catch {
|
|
return NextResponse.json({ success: false, message: "Invalid JSON" }, { status: 400 });
|
|
}
|
|
const bookingData = bookingCancelWithCsrfSchema.parse(appDirRequestBody);
|
|
|
|
// Integer IDs are sequential/guessable — only accept high-entropy UIDs on this route
|
|
if (!bookingData.uid) {
|
|
return NextResponse.json(
|
|
{ success: false, message: "uid is required for booking cancellation" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const csrfError = await validateCsrfToken(bookingData.csrfToken);
|
|
if (csrfError) {
|
|
return csrfError;
|
|
}
|
|
|
|
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
|
|
|
|
// Rate limit: 10 booking cancellations per 60 seconds per user (or IP if not authenticated)
|
|
const identifier = session?.user?.id
|
|
? `api:cancel-user:${session.user.id}`
|
|
: `api:cancel-ip:${piiHasher.hash(getIP(req))}`;
|
|
await checkRateLimitAndThrowError({
|
|
rateLimitingType: "core",
|
|
identifier,
|
|
});
|
|
|
|
// Strip integer id to ensure lookup is always by uid
|
|
const { id: _id, ...safeBookingData } = bookingData;
|
|
|
|
const result = await handleCancelBooking({
|
|
bookingData: safeBookingData,
|
|
userId: session?.user?.id || -1,
|
|
});
|
|
|
|
// const bookingCancelService = getBookingCancelService();
|
|
// const result = await bookingCancelService.cancelBooking({
|
|
// bookingData: bookingData,
|
|
// bookingMeta: {
|
|
// userId: session?.user?.id || -1,
|
|
// },
|
|
// });
|
|
|
|
const statusCode = result.success ? 200 : 400;
|
|
|
|
return NextResponse.json(result, { status: statusCode });
|
|
}
|
|
|
|
export const DELETE = defaultResponderForAppDir(handler);
|
|
export const POST = defaultResponderForAppDir(handler);
|