2023-02-16 22:39:57 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import type { CollectOpts, EventHandler } from "next-collect";
|
2022-06-02 16:19:01 +00:00
|
|
|
import { useCollector } from "next-collect/client";
|
2022-08-24 20:18:42 +00:00
|
|
|
// Importing types so we're not directly importing next/server
|
2022-06-02 16:19:01 +00:00
|
|
|
import type { NextRequest, NextResponse } from "next/server";
|
2021-04-27 14:19:12 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import { CONSOLE_URL } from "./constants";
|
2022-06-03 18:33:53 +00:00
|
|
|
|
2021-05-07 17:05:33 +00:00
|
|
|
export const telemetryEventTypes = {
|
2021-08-19 12:27:01 +00:00
|
|
|
pageView: "page_view",
|
2022-06-02 16:19:01 +00:00
|
|
|
apiCall: "api_call",
|
2021-08-19 12:27:01 +00:00
|
|
|
bookingConfirmed: "booking_confirmed",
|
|
|
|
bookingCancelled: "booking_cancelled",
|
2022-01-19 17:26:44 +00:00
|
|
|
importSubmitted: "import_submitted",
|
2022-05-17 16:22:57 +00:00
|
|
|
login: "login",
|
2022-05-11 05:14:08 +00:00
|
|
|
embedView: "embed_view",
|
|
|
|
embedBookingConfirmed: "embed_booking_confirmed",
|
2023-02-10 09:53:03 +00:00
|
|
|
onboardingFinished: "onboarding_finished",
|
|
|
|
onboardingStarted: "onboarding_started",
|
|
|
|
signup: "signup",
|
|
|
|
team_created: "team_created",
|
2023-04-13 02:10:23 +00:00
|
|
|
slugReplacementAction: "slug_replacement_action",
|
feat: Organizations (#8993)
* Initial commit
* Adding feature flag
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* Letting duplicate slugs for teams to support orgs
* Covering null on unique clauses
* Supporting having the orgId in the session cookie
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* feat: Onboarding process to create an organization (#9184)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Making sure we check requestedSlug now
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: [CAL-1816] Organization subdomain support (#9345)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* Covering users and subteams, excluding non-org users
* Unpublished teams shows correctly
* Create subdomain in Vercel
* feedback
* Renaming Vercel env vars
* Vercel domain check before creation
* Supporting cal-staging.com
* Change to have vercel detect it
* vercel domain check data message error
* Remove check domain
* Making sure we check requestedSlug now
* Feedback and unneeded code
* Reverting unneeded changes
* Unneeded changes
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Vercel subdomain creation in PROD only
* Making sure we let localhost still work
* Feedback
* Type check fixes
* feat: Organization branding in side menu (#9279)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Org branding provider used in shell sidebar
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Using org avatar (temp)
* Not showing org logo if not set
* User onboarding with org branding (slug)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Feedback
* Org public profile
* Public profiles for team event types
* Added setup profile alert
* Using org avatar on subteams avatar
* Making sure we show the set up profile on org only
* Profile username availability rely on org hook
* Update apps/web/pages/team/[slug].tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Update apps/web/pages/team/[slug].tsx
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: Organization support for event types page (#9449)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Org branding provider used in shell sidebar
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Using org avatar (temp)
* Not showing org logo if not set
* User onboarding with org branding (slug)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Feedback
* Org public profile
* Public profiles for team event types
* Added setup profile alert
* Using org avatar on subteams avatar
* Processing orgs and children as profile options
* Reverting change not belonging to this PR
* Making sure we show the set up profile on org only
* Removing console.log
* Comparing memberships to choose the highest one
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Type errors
* Refactor and type fixes
* Update orgDomains.ts
* Feedback
* Reverting
* NIT
* fix issue getting org slug from domain
* Improving orgDomains util
* Host comes with port
* Update useRouterQuery.ts
* Feedback
* Feedback
* Feedback
* Feedback: SSR for user event-types to have org context
* chore: Cache node_modules (#9492)
* Adding check for cache hit
* Adding a separate install step first
* Put the restore cache steps back
* Revert the uses type for restoring cache
* Added step to restore nm cache
* Removed the cache-hit check
* Comments and naming
* Removed extra install command
* Updated the name of the linting step to be more clear
* Removes the need for useEffect here
* Feedback
* Feedback
* Cookie domain needs a dot
* Type fix
* Update apps/web/public/static/locales/en/common.json
Co-authored-by: Omar López <zomars@me.com>
* Update packages/emails/src/templates/OrganizationAccountVerifyEmail.tsx
* Feedback
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Efraín Rochín <roae.85@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2023-06-14 21:40:20 +00:00
|
|
|
org_created: "org_created",
|
2021-08-19 12:27:01 +00:00
|
|
|
};
|
2021-04-27 14:19:12 +00:00
|
|
|
|
2022-05-17 20:43:27 +00:00
|
|
|
export function collectPageParameters(
|
|
|
|
route?: string,
|
|
|
|
extraData: Record<string, unknown> = {}
|
|
|
|
): Record<string, unknown> {
|
2022-06-02 16:19:01 +00:00
|
|
|
const host = document.location.host;
|
2021-08-19 12:27:01 +00:00
|
|
|
const docPath = route ?? "";
|
|
|
|
return {
|
|
|
|
page_url: route,
|
2022-06-02 16:19:01 +00:00
|
|
|
doc_encoding: document.characterSet,
|
2021-08-19 12:27:01 +00:00
|
|
|
url: document.location.protocol + "//" + host + (docPath ?? ""),
|
2022-04-14 02:47:34 +00:00
|
|
|
...extraData,
|
2021-08-19 12:27:01 +00:00
|
|
|
};
|
2021-05-07 17:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 18:33:53 +00:00
|
|
|
const reportUsage: EventHandler = async (event, { fetch }) => {
|
2022-06-06 21:33:13 +00:00
|
|
|
const ets = telemetryEventTypes;
|
|
|
|
if ([ets.bookingConfirmed, ets.embedBookingConfirmed].includes(event.eventType)) {
|
2022-06-03 18:33:53 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
export const nextCollectBasicSettings: CollectOpts = {
|
2022-06-02 16:19:01 +00:00
|
|
|
drivers: [
|
2022-06-22 20:41:19 +00:00
|
|
|
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
|
|
|
|
: {
|
2022-06-02 20:06:13 +00:00
|
|
|
type: "jitsu",
|
|
|
|
opts: {
|
|
|
|
key: "s2s.2pvs2bbpqq1zxna97wcml.esb6cikfrf7yn0qoh1nj1",
|
|
|
|
server: "https://t.calendso.com",
|
|
|
|
},
|
2022-06-22 20:41:19 +00:00
|
|
|
},
|
2022-06-02 16:19:01 +00:00
|
|
|
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 },
|
|
|
|
],
|
|
|
|
};
|
2021-04-27 14:19:12 +00:00
|
|
|
|
2022-06-02 16:19:01 +00:00
|
|
|
export const extendEventData = (
|
|
|
|
req: NextRequest | NextApiRequest,
|
|
|
|
res: NextResponse | NextApiResponse,
|
2023-06-06 11:59:57 +00:00
|
|
|
original: { page_url: string; isTeamBooking: boolean }
|
2022-06-02 16:19:01 +00:00
|
|
|
) => {
|
|
|
|
const onVercel =
|
|
|
|
typeof req.headers?.get === "function"
|
|
|
|
? !!req.headers.get("x-vercel-id")
|
2023-06-06 11:59:57 +00:00
|
|
|
: !!(req.headers as { [key: string]: string })?.["x-vercel-id"];
|
2022-08-17 17:38:21 +00:00
|
|
|
const pageUrl = original?.page_url || req.url || undefined;
|
2023-06-06 11:59:57 +00:00
|
|
|
const cookies = req.cookies as { [key: string]: string };
|
2022-06-02 16:19:01 +00:00
|
|
|
return {
|
|
|
|
title: "",
|
|
|
|
ipAddress: "",
|
|
|
|
queryString: "",
|
|
|
|
page_url: pageUrl,
|
2022-06-02 17:53:02 +00:00
|
|
|
licensekey: process.env.CALCOM_LICENSE_KEY,
|
2022-06-02 16:19:01 +00:00
|
|
|
isTeamBooking:
|
|
|
|
original?.isTeamBooking === undefined
|
|
|
|
? pageUrl?.includes("team/") || undefined
|
|
|
|
: original?.isTeamBooking,
|
|
|
|
referrer: "",
|
|
|
|
onVercel,
|
2022-07-12 17:43:53 +00:00
|
|
|
isAuthorized: !!cookies["next-auth.session-token"] || !!cookies["__Secure-next-auth.session-token"],
|
2022-06-02 16:19:01 +00:00
|
|
|
utc_time: new Date().toISOString(),
|
|
|
|
};
|
|
|
|
};
|
2021-04-27 14:19:12 +00:00
|
|
|
|
2022-06-02 16:19:01 +00:00
|
|
|
export const useTelemetry = useCollector;
|