feat: API v2 subversioning (#15135)

* feat: API v2 subversioning

* Update app.ts

* Added multiple versions to existing controllers

* Updated the slots controller

* chore: version platform library package with npm package alias

* chore: use consts to version

* chore: use consts to version

* chore: version api for cal provider

* chore: remove timezone controller subversion poc

* fixup! Merge branch 'main' into feat/api-v2-subversioning

---------

Co-authored-by: Morgan <[email protected]>
Co-authored-by: Morgan Vernay <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-06-04 15:05:39 +00:00
1 parent 93580ac4bc
commit 3a22fdb428
31 files changed
+128 -62

No files matched your search

@@ -1,6 +1,10 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import type { ReactNode } from "react";
import { useEffect, type ReactNode } from "react";
import type { API_VERSIONS_ENUM } from "@calcom/platform-constants";
import { VERSION_2024_04_15 } from "@calcom/platform-constants";
import http from "../lib/http";
import { BaseCalProvider } from "./BaseCalProvider";
const queryClient = new QueryClient();
@@ -12,6 +16,7 @@ export type CalProviderProps = {
options: { refreshUrl?: string; apiUrl: string };
autoUpdateTimezone?: boolean;
onTimezoneChange?: () => void;
version?: API_VERSIONS_ENUM;
};
/**
@@ -35,7 +40,12 @@ export function CalProvider({
children,
autoUpdateTimezone = true,
onTimezoneChange,
version = VERSION_2024_04_15,
}: CalProviderProps) {
useEffect(() => {
http.setVersionHeader(version);
}, [version]);
return (
<QueryClientProvider client={queryClient}>
<BaseCalProvider
@@ -43,7 +53,8 @@ export function CalProvider({
onTimezoneChange={onTimezoneChange}
clientId={clientId}
accessToken={accessToken}
options={options}>
options={options}
version={version}>
{children}
</BaseCalProvider>
</QueryClientProvider>
+10 -2
View File
@@ -1,5 +1,7 @@
import axios from "axios";
import { CAL_API_VERSION_HEADER, X_CAL_CLIENT_ID } from "@calcom/platform-constants";
// Immediately Invoked Function Expression to create simple singleton class like
const http = (function () {
@@ -35,10 +37,16 @@ const http = (function () {
return instance.defaults.headers.common?.["Authorization"]?.toString() ?? "";
},
setClientIdHeader: (clientId: string) => {
instance.defaults.headers.common["x-cal-client-id"] = clientId;
instance.defaults.headers.common[X_CAL_CLIENT_ID] = clientId;
},
getClientIdHeader: () => {
return instance.defaults.headers.common?.["x-cal-client-id"]?.toString() ?? "";
return instance.defaults.headers.common?.[X_CAL_CLIENT_ID]?.toString() ?? "";
},
setVersionHeader: (clientId: string) => {
instance.defaults.headers.common[CAL_API_VERSION_HEADER] = clientId;
},
getVersionHeader: () => {
return instance.defaults.headers.common?.[X_CAL_CLIENT_ID]?.toString() ?? "";
},
refreshTokens: async (refreshUrl: string): Promise<string> => {
const response = await fetch(`${refreshUrl}`, {
+7 -1
View File
@@ -1,5 +1,4 @@
export const BASE_URL = "http://localhost:5555";
export const API_VERSION = "v2";
export const V2_ENDPOINTS = {
me: "me",
availability: "schedules",
@@ -51,3 +50,10 @@ export const X_CAL_CLIENT_ID = "x-cal-client-id";
// HTTP status codes
export const HTTP_CODE_TOKEN_EXPIRED = 498;
export const VERSION_2024_04_15 = "2024-04-15";
export const VERSION_2024_05_21 = "2024-05-21";
export const API_VERSIONS = [VERSION_2024_04_15, VERSION_2024_05_21] as const;
export type API_VERSIONS_ENUM = (typeof API_VERSIONS)[number];
export type API_VERSIONS_TYPE = typeof API_VERSIONS;
export const CAL_API_VERSION_HEADER = "cal-api-version";