Adds booking reportUsage for enterprise

fix/license_text
zomars 2022-06-03 12:33:53 -06:00
parent 10edc1f4ac
commit d5e40faeb5
1 changed files with 19 additions and 1 deletions

View File

@ -1,10 +1,12 @@
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import { EventSinkOpts } from "next-collect"; import { EventHandler, EventSinkOpts } from "next-collect";
import { useCollector } from "next-collect/client"; import { useCollector } from "next-collect/client";
// it's ok to do this since we're importing only types which are harmless // it's ok to do this since we're importing only types which are harmless
// eslint-disable-next-line @next/next/no-server-import-in-page // eslint-disable-next-line @next/next/no-server-import-in-page
import type { NextRequest, NextResponse } from "next/server"; import type { NextRequest, NextResponse } from "next/server";
import { CONSOLE_URL } from "@calcom/lib/constants";
export const telemetryEventTypes = { export const telemetryEventTypes = {
pageView: "page_view", pageView: "page_view",
apiCall: "api_call", apiCall: "api_call",
@ -33,8 +35,24 @@ export function collectPageParameters(
}; };
} }
const reportUsage: EventHandler = async (event, { fetch }) => {
if (event.eventType === "booking") {
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: EventSinkOpts = { export const nextCollectBasicSettings: EventSinkOpts = {
drivers: [ drivers: [
process.env.CALCOM_LICENSE_KEY && reportUsage,
process.env.CALCOM_TELEMETRY_DISABLED !== "1" process.env.CALCOM_TELEMETRY_DISABLED !== "1"
? { ? {
type: "jitsu", type: "jitsu",