* wip * update layoutHOC * wip * remove app router related code no longer used * remove more * await cookies, headers, params, serachparams * update yarn.lock * await cookies, headers, params, serachparams more * update yarn lock again * downgrade next-auth to 4.22.1 * update yarn lock * fix * update yarn lock * fix type checks * update yarn lock * await headers and cookies * restore pages folder * restore yarn.lock * update yarn.lock * await headers and cookies * remove * await params in API routes * updates * restore next.config.js * remove i18n from next.config.js * Fixed tests * Fixed types * Removed duplicate favicon.ico * Fixing more types * ImageResponse moved to next/og * Fixed prisma import issues * dynamic import for @ewsjs/xhr * remove deasync dep * dynamic import for @tryvital/vital-node * fix type checks * add back turbopack command * Type fix * Removed unneeded file * fix turbopack relative path errors * add comments * remove unneeded code * Fixed build errors * await apis * use Promise<Params> type in defaultResponderForAppDir util * refactor scim api route * fix type checks * separate app-routing.config into client-config and server-config * wip * refactor routing forms components * revert unneeded changes for easier review * fix * fix * use CustomTrans * fix type * fix unit tests * fix type error * fix build error * fix build error * fix build error * fix warnings * fix warnings * upgrade @tremor/react and tailwindcss * numCols -> numItems * fix forgot-password e2e test * fix 1 more e2e test * fix login e2e test * fix e2e tests * fix e2e tests * clean up * remove error * use tremor/react 2.11.0 * fix * rename CustomTrans to ServerTrans * address comment * fix test * fix ServerTrans * fix * fix type * fix ServerTrans usages 1 * fix translations * fix type checks * fix type checks * link styling * fix --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
114 lines
3.6 KiB
TypeScript
114 lines
3.6 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next";
|
|
import type { CollectOpts, EventHandler } from "next-collect";
|
|
// Importing types so we're not directly importing next/server
|
|
import type { NextRequest, NextResponse } from "next/server";
|
|
|
|
import { CONSOLE_URL } from "./constants";
|
|
|
|
export const telemetryEventTypes = {
|
|
pageView: "page_view",
|
|
apiCall: "api_call",
|
|
bookingConfirmed: "booking_confirmed",
|
|
bookingCancelled: "booking_cancelled",
|
|
importSubmitted: "import_submitted",
|
|
login: "login",
|
|
embedView: "embed_view",
|
|
embedBookingConfirmed: "embed_booking_confirmed",
|
|
onboardingFinished: "onboarding_finished",
|
|
onboardingStarted: "onboarding_started",
|
|
signup: "signup",
|
|
team_checkout_session_created: "team_checkout_session_created",
|
|
team_created: "team_created",
|
|
slugReplacementAction: "slug_replacement_action",
|
|
org_created: "org_created",
|
|
license_key_created: "license_key_created",
|
|
};
|
|
|
|
export function collectPageParameters(
|
|
route?: string,
|
|
extraData: Record<string, unknown> = {}
|
|
): Record<string, unknown> {
|
|
const host = document.location.host;
|
|
const docPath = route ?? "";
|
|
return {
|
|
page_url: route,
|
|
doc_encoding: document.characterSet,
|
|
url: `${document.location.protocol}//${host}${docPath ?? ""}`,
|
|
...extraData,
|
|
};
|
|
}
|
|
|
|
const reportUsage: EventHandler = async (event, { fetch }) => {
|
|
const ets = telemetryEventTypes;
|
|
if ([ets.bookingConfirmed, ets.embedBookingConfirmed].includes(event.eventType)) {
|
|
const key = process.env.CALCOM_LICENSE_KEY;
|
|
const url = `${CONSOLE_URL}/api/deployments/usage?key=${key}&quantity=1`;
|
|
try {
|
|
return fetch(url, { method: "POST", mode: "cors" });
|
|
} catch (e) {
|
|
console.error(`Error reporting booking for key: '${key}'`, e);
|
|
return Promise.resolve();
|
|
}
|
|
} else {
|
|
return Promise.resolve();
|
|
}
|
|
};
|
|
|
|
export const nextCollectBasicSettings: CollectOpts = {
|
|
drivers: [
|
|
process.env.CALCOM_LICENSE_KEY && process.env.NEXT_PUBLIC_IS_E2E !== "1" ? reportUsage : undefined,
|
|
process.env.CALCOM_TELEMETRY_DISABLED === "1" || process.env.NEXT_PUBLIC_IS_E2E === "1"
|
|
? undefined
|
|
: {
|
|
type: "jitsu",
|
|
opts: {
|
|
key: "s2s.2pvs2bbpqq1zxna97wcml.esb6cikfrf7yn0qoh1nj1",
|
|
server: "https://t.calendso.com",
|
|
},
|
|
},
|
|
process.env.TELEMETRY_DEBUG && { type: "echo", opts: { disableColor: true } },
|
|
],
|
|
eventTypes: [
|
|
{ "*.ttf": null },
|
|
{ "*.webmanifest": null },
|
|
{ "*.json": null },
|
|
{ "*.svg": null },
|
|
{ "*.map": null },
|
|
{ "*.png": null },
|
|
{ "*.gif": null },
|
|
{ "/api/collect-events": null },
|
|
{ "/api*": null },
|
|
{ "/img*": null },
|
|
{ "/favicon*": null },
|
|
{ "/*": telemetryEventTypes.pageView },
|
|
],
|
|
};
|
|
|
|
export const extendEventData = (
|
|
req: NextRequest | NextApiRequest,
|
|
res: NextResponse | NextApiResponse,
|
|
original: { page_url: string; isTeamBooking: boolean }
|
|
) => {
|
|
const onVercel =
|
|
typeof req.headers?.get === "function"
|
|
? !!req.headers.get("x-vercel-id")
|
|
: !!(req.headers as { [key: string]: string })?.["x-vercel-id"];
|
|
const pageUrl = original?.page_url || req.url || undefined;
|
|
const cookies = req.cookies as { [key: string]: string };
|
|
return {
|
|
title: "",
|
|
ipAddress: "",
|
|
queryString: "",
|
|
page_url: pageUrl,
|
|
licensekey: process.env.CALCOM_LICENSE_KEY,
|
|
isTeamBooking:
|
|
original?.isTeamBooking === undefined
|
|
? pageUrl?.includes("team/") || undefined
|
|
: original?.isTeamBooking,
|
|
referrer: "",
|
|
onVercel,
|
|
isAuthorized: !!cookies["next-auth.session-token"] || !!cookies["__Secure-next-auth.session-token"],
|
|
utc_time: new Date().toISOString(),
|
|
};
|
|
};
|