chore: rename platform endpoints provider/gcal (#14248)

This commit is contained in:
Morgan authored and GitHub committed 2024-03-28 12:04:28 +00:00
1 parent a1840c9362
commit ccc8cdc1ff
8 files changed
+181 -40

No files matched your search

@@ -82,16 +82,16 @@ describe("Platform Gcal Endpoints", () => {
expect(user).toBeDefined(); expect(user).toBeDefined();
}); });
it(`/GET/platform/gcal/oauth/auth-url: it should respond 401 with invalid access token`, async () => { it(`/GET/ee/gcal/oauth/auth-url: it should respond 401 with invalid access token`, async () => {
await request(app.getHttpServer()) await request(app.getHttpServer())
.get(`/api/v2/platform/gcal/oauth/auth-url`) .get(`/api/v2/ee/gcal/oauth/auth-url`)
.set("Authorization", `Bearer invalid_access_token`) .set("Authorization", `Bearer invalid_access_token`)
.expect(401); .expect(401);
}); });
it(`/GET/platform/gcal/oauth/auth-url: it should auth-url to google oauth with valid access token `, async () => { it(`/GET/ee/gcal/oauth/auth-url: it should auth-url to google oauth with valid access token `, async () => {
const response = await request(app.getHttpServer()) const response = await request(app.getHttpServer())
.get(`/api/v2/platform/gcal/oauth/auth-url`) .get(`/api/v2/ee/gcal/oauth/auth-url`)
.set("Authorization", `Bearer ${accessTokenSecret}`) .set("Authorization", `Bearer ${accessTokenSecret}`)
.set("Origin", CLIENT_REDIRECT_URI) .set("Origin", CLIENT_REDIRECT_URI)
.expect(200); .expect(200);
@@ -99,50 +99,50 @@ describe("Platform Gcal Endpoints", () => {
expect(data.authUrl).toBeDefined(); expect(data.authUrl).toBeDefined();
}); });
it(`/GET/platform/gcal/oauth/save: without oauth code`, async () => { it(`/GET/ee/gcal/oauth/save: without oauth code`, async () => {
await request(app.getHttpServer()) await request(app.getHttpServer())
.get( .get(
`/api/v2/platform/gcal/oauth/save?state=accessToken=${accessTokenSecret}&origin%3D${CLIENT_REDIRECT_URI}&scope=https://www.googleapis.com/auth/calendar.readonly%20https://www.googleapis.com/auth/calendar.events` `/api/v2/ee/gcal/oauth/save?state=accessToken=${accessTokenSecret}&origin%3D${CLIENT_REDIRECT_URI}&scope=https://www.googleapis.com/auth/calendar.readonly%20https://www.googleapis.com/auth/calendar.events`
) )
.expect(400); .expect(400);
}); });
it(`/GET/platform/gcal/oauth/save: without access token`, async () => { it(`/GET/ee/gcal/oauth/save: without access token`, async () => {
await request(app.getHttpServer()) await request(app.getHttpServer())
.get( .get(
`/api/v2/platform/gcal/oauth/save?state=origin%3D${CLIENT_REDIRECT_URI}&code=4/0AfJohXmBuT7QVrEPlAJLBu4ZcSnyj5jtDoJqSW_riPUhPXQ70RPGkOEbVO3xs-OzQwpPQw&scope=https://www.googleapis.com/auth/calendar.readonly%20https://www.googleapis.com/auth/calendar.events` `/api/v2/ee/gcal/oauth/save?state=origin%3D${CLIENT_REDIRECT_URI}&code=4/0AfJohXmBuT7QVrEPlAJLBu4ZcSnyj5jtDoJqSW_riPUhPXQ70RPGkOEbVO3xs-OzQwpPQw&scope=https://www.googleapis.com/auth/calendar.readonly%20https://www.googleapis.com/auth/calendar.events`
) )
.expect(400); .expect(400);
}); });
it(`/GET/platform/gcal/oauth/save: without origin`, async () => { it(`/GET/ee/gcal/oauth/save: without origin`, async () => {
await request(app.getHttpServer()) await request(app.getHttpServer())
.get( .get(
`/api/v2/platform/gcal/oauth/save?state=accessToken=${accessTokenSecret}&code=4/0AfJohXmBuT7QVrEPlAJLBu4ZcSnyj5jtDoJqSW_riPUhPXQ70RPGkOEbVO3xs-OzQwpPQw&scope=https://www.googleapis.com/auth/calendar.readonly%20https://www.googleapis.com/auth/calendar.events` `/api/v2/ee/gcal/oauth/save?state=accessToken=${accessTokenSecret}&code=4/0AfJohXmBuT7QVrEPlAJLBu4ZcSnyj5jtDoJqSW_riPUhPXQ70RPGkOEbVO3xs-OzQwpPQw&scope=https://www.googleapis.com/auth/calendar.readonly%20https://www.googleapis.com/auth/calendar.events`
) )
.expect(400); .expect(400);
}); });
it(`/GET/platform/gcal/check with access token but without origin`, async () => { it(`/GET/ee/gcal/check with access token but without origin`, async () => {
await request(app.getHttpServer()) await request(app.getHttpServer())
.get(`/api/v2/platform/gcal/check`) .get(`/api/v2/ee/gcal/check`)
.set("Authorization", `Bearer ${accessTokenSecret}`) .set("Authorization", `Bearer ${accessTokenSecret}`)
.expect(400); .expect(400);
}); });
it(`/GET/platform/gcal/check without access token`, async () => { it(`/GET/ee/gcal/check without access token`, async () => {
await request(app.getHttpServer()).get(`/api/v2/platform/gcal/check`).expect(401); await request(app.getHttpServer()).get(`/api/v2/ee/gcal/check`).expect(401);
}); });
it(`/GET/platform/gcal/check with access token and origin but no credentials`, async () => { it(`/GET/ee/gcal/check with access token and origin but no credentials`, async () => {
await request(app.getHttpServer()) await request(app.getHttpServer())
.get(`/api/v2/platform/gcal/check`) .get(`/api/v2/ee/gcal/check`)
.set("Authorization", `Bearer ${accessTokenSecret}`) .set("Authorization", `Bearer ${accessTokenSecret}`)
.set("Origin", CLIENT_REDIRECT_URI) .set("Origin", CLIENT_REDIRECT_URI)
.expect(400); .expect(400);
}); });
it(`/GET/platform/gcal/check with access token and origin and gcal credentials`, async () => { it(`/GET/ee/gcal/check with access token and origin and gcal credentials`, async () => {
gcalCredentials = await credentialsRepositoryFixture.create( gcalCredentials = await credentialsRepositoryFixture.create(
"google_calendar", "google_calendar",
{}, {},
@@ -150,7 +150,7 @@ describe("Platform Gcal Endpoints", () => {
"google-calendar" "google-calendar"
); );
await request(app.getHttpServer()) await request(app.getHttpServer())
.get(`/api/v2/platform/gcal/check`) .get(`/api/v2/ee/gcal/check`)
.set("Authorization", `Bearer ${accessTokenSecret}`) .set("Authorization", `Bearer ${accessTokenSecret}`)
.set("Origin", CLIENT_REDIRECT_URI) .set("Origin", CLIENT_REDIRECT_URI)
.expect(200); .expect(200);
+2 -2
View File
@@ -40,7 +40,7 @@ const CALENDAR_SCOPES = [
]; ];
@Controller({ @Controller({
path: "platform/gcal", path: "ee/gcal",
version: "2", version: "2",
}) })
export class GcalController { export class GcalController {
@@ -55,7 +55,7 @@ export class GcalController {
private readonly gcalService: GcalService private readonly gcalService: GcalService
) {} ) {}
private redirectUri = `${this.config.get("api.url")}/platform/gcal/oauth/save`; private redirectUri = `${this.config.get("api.url")}/ee/gcal/oauth/save`;
@Get("/oauth/auth-url") @Get("/oauth/auth-url")
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@@ -20,7 +20,7 @@ import { SUCCESS_STATUS } from "@calcom/platform-constants";
import { ApiResponse } from "@calcom/platform-types"; import { ApiResponse } from "@calcom/platform-types";
@Controller({ @Controller({
path: "platform/provider", path: "ee/provider",
version: "2", version: "2",
}) })
export class CalProviderController { export class CalProviderController {
+155 -14
View File
@@ -22,7 +22,40 @@
"/api/v2/events/public": { "/api/v2/events/public": {
"get": { "get": {
"operationId": "EventsController_getPublicEvent", "operationId": "EventsController_getPublicEvent",
"parameters": [], "parameters": [
{
"name": "username",
"required": true,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "eventSlug",
"required": true,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "isTeamEvent",
"required": false,
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "org",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "", "description": "",
@@ -55,7 +88,7 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "#/components/schemas/CreateUserInput" "$ref": "#/components/schemas/CreateManagedPlatformUserInput"
} }
} }
} }
@@ -133,7 +166,7 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "#/components/schemas/UpdateUserInput" "$ref": "#/components/schemas/UpdateManagedPlatformUserInput"
} }
} }
} }
@@ -578,7 +611,7 @@
} }
} }
}, },
"/api/v2/platform/gcal/oauth/auth-url": { "/api/v2/ee/gcal/oauth/auth-url": {
"get": { "get": {
"operationId": "GcalController_redirect", "operationId": "GcalController_redirect",
"parameters": [ "parameters": [
@@ -605,7 +638,7 @@
} }
} }
}, },
"/api/v2/platform/gcal/oauth/save": { "/api/v2/ee/gcal/oauth/save": {
"get": { "get": {
"operationId": "GcalController_save", "operationId": "GcalController_save",
"parameters": [ "parameters": [
@@ -640,7 +673,7 @@
} }
} }
}, },
"/api/v2/platform/gcal/check": { "/api/v2/ee/gcal/check": {
"get": { "get": {
"operationId": "GcalController_check", "operationId": "GcalController_check",
"parameters": [], "parameters": [],
@@ -658,7 +691,7 @@
} }
} }
}, },
"/api/v2/platform/provider/{clientId}": { "/api/v2/ee/provider/{clientId}": {
"get": { "get": {
"operationId": "CalProviderController_verifyClientId", "operationId": "CalProviderController_verifyClientId",
"parameters": [ "parameters": [
@@ -685,7 +718,7 @@
} }
} }
}, },
"/api/v2/platform/provider/{clientId}/access-token": { "/api/v2/ee/provider/{clientId}/access-token": {
"get": { "get": {
"operationId": "CalProviderController_verifyAccessToken", "operationId": "CalProviderController_verifyAccessToken",
"parameters": [ "parameters": [
@@ -895,7 +928,7 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "#/components/schemas/UpdateUserInput" "$ref": "#/components/schemas/UpdateManagedPlatformUserInput"
} }
} }
} }
@@ -951,6 +984,22 @@
} }
}, },
"/api/v2/ee/bookings": { "/api/v2/ee/bookings": {
"get": {
"operationId": "BookingsController_getBookings",
"parameters": [],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
},
"post": { "post": {
"operationId": "BookingsController_createBooking", "operationId": "BookingsController_createBooking",
"parameters": [], "parameters": [],
@@ -978,6 +1027,97 @@
} }
} }
}, },
"/api/v2/ee/bookings/{bookingUid}": {
"get": {
"operationId": "BookingsController_getBooking",
"parameters": [
{
"name": "bookingUid",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/api/v2/ee/bookings/{bookingUid}/reschedule": {
"get": {
"operationId": "BookingsController_getBookingForReschedule",
"parameters": [
{
"name": "bookingUid",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/api/v2/ee/bookings/{bookingId}/cancel": {
"post": {
"operationId": "BookingsController_cancelBooking",
"parameters": [
{
"name": "bookingId",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CancelBookingInput"
}
}
}
},
"responses": {
"201": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/api/v2/ee/bookings/reccuring": { "/api/v2/ee/bookings/reccuring": {
"post": { "post": {
"operationId": "BookingsController_createReccuringBooking", "operationId": "BookingsController_createReccuringBooking",
@@ -1112,7 +1252,7 @@
"servers": [], "servers": [],
"components": { "components": {
"schemas": { "schemas": {
"CreateUserInput": { "CreateManagedPlatformUserInput": {
"type": "object", "type": "object",
"properties": { "properties": {
"email": { "email": {
@@ -1124,9 +1264,6 @@
"timeFormat": { "timeFormat": {
"type": "number" "type": "number"
}, },
"defaultScheduleId": {
"type": "number"
},
"weekStart": { "weekStart": {
"type": "string" "type": "string"
}, },
@@ -1138,7 +1275,7 @@
"email" "email"
] ]
}, },
"UpdateUserInput": { "UpdateManagedPlatformUserInput": {
"type": "object", "type": "object",
"properties": { "properties": {
"email": { "email": {
@@ -1526,6 +1663,10 @@
"hashedLink" "hashedLink"
] ]
}, },
"CancelBookingInput": {
"type": "object",
"properties": {}
},
"ReserveSlotInput": { "ReserveSlotInput": {
"type": "object", "type": "object",
"properties": {} "properties": {}
+2 -2
View File
@@ -12,7 +12,7 @@ export const useGcal = ({ isAuth }: useGcalProps) => {
const redirectToGcalOAuth = () => { const redirectToGcalOAuth = () => {
http http
?.get("/platform/gcal/oauth/auth-url") ?.get("/ee/gcal/oauth/auth-url")
.then(({ data: responseBody }) => { .then(({ data: responseBody }) => {
if (responseBody.data?.authUrl) { if (responseBody.data?.authUrl) {
window.location.href = responseBody.data.authUrl; window.location.href = responseBody.data.authUrl;
@@ -24,7 +24,7 @@ export const useGcal = ({ isAuth }: useGcalProps) => {
useEffect(() => { useEffect(() => {
if (isAuth) { if (isAuth) {
http http
?.get("/platform/gcal/check") ?.get("/ee/gcal/check")
.then(() => setAllowConnect(false)) .then(() => setAllowConnect(false))
.catch(() => setAllowConnect(true)) .catch(() => setAllowConnect(true))
.finally(() => setChecked(true)); .finally(() => setChecked(true));
@@ -30,7 +30,7 @@ export const useOAuthClient = ({ clientId, apiUrl, refreshUrl, onError, onSucces
useEffect(() => { useEffect(() => {
if (clientId && http.getUrl() && prevClientId !== clientId) { if (clientId && http.getUrl() && prevClientId !== clientId) {
try { try {
http.get<ApiResponse>(`/platform/provider/${clientId}`).catch((err: AxiosError) => { http.get<ApiResponse>(`/ee/provider/${clientId}`).catch((err: AxiosError) => {
if (err.response?.status === 401) { if (err.response?.status === 401) {
onError("Invalid oAuth Client."); onError("Invalid oAuth Client.");
} else { } else {
@@ -58,7 +58,7 @@ export const useOAuthFlow = ({ accessToken, refreshUrl, clientId, onError, onSuc
http.setAuthorizationHeader(accessToken); http.setAuthorizationHeader(accessToken);
try { try {
http http
.get<ApiResponse>(`/platform/provider/${clientId}/access-token`) .get<ApiResponse>(`/ee/provider/${clientId}/access-token`)
.catch(async (err: AxiosError) => { .catch(async (err: AxiosError) => {
if ((err.response?.status === 498 || err.response?.status === 401) && refreshUrl) { if ((err.response?.status === 498 || err.response?.status === 401) && refreshUrl) {
setIsRefreshing(true); setIsRefreshing(true);
+1 -1
View File
@@ -29,7 +29,7 @@ REDIS_URL="redis://localhost:6379"
2. Open ".env" file and paste client id from step 8 in `NEXT_PUBLIC_X_CAL_ID` and client secret in `X_CAL_SECRET_KEY`. If in step 2 you used the same environment variables, then `NEXT_PUBLIC_CALCOM_API_URL` can stay as is. Otherwise adjust the port to point to the same `API_PORT` as you used in step 2. 2. Open ".env" file and paste client id from step 8 in `NEXT_PUBLIC_X_CAL_ID` and client secret in `X_CAL_SECRET_KEY`. If in step 2 you used the same environment variables, then `NEXT_PUBLIC_CALCOM_API_URL` can stay as is. Otherwise adjust the port to point to the same `API_PORT` as you used in step 2.
10. Navigate to example app and setup database by running `rm -f prisma/dev.db && yarn prisma db push`. 10. Navigate to example app and setup database by running `rm -f prisma/dev.db && yarn prisma db push`.
11. Start the example app by running `yarn dev` and go to `http://localhost:4321`. 11. Start the example app by running `yarn dev` and go to `http://localhost:4321`.
12. In the Google Cloud Console "API & Services" "Credentials" `https://console.cloud.google.com/apis/credentials` open web project setup in step 1 and add `http://localhost:5555/api/v2/platform/gcal/oauth/save` to the authorized redirect URIs. 12. In the Google Cloud Console "API & Services" "Credentials" `https://console.cloud.google.com/apis/credentials` open web project setup in step 1 and add `http://localhost:5555/api/v2/ee/gcal/oauth/save` to the authorized redirect URIs.
<img width="1000" alt="Screenshot 2024-03-21 at 09 42 36" src="https://github.com/calcom/atoms-examples/assets/42170848/82ce4d7a-fc08-489a-ab06-a8eb41a68a2a"> <img width="1000" alt="Screenshot 2024-03-21 at 09 42 36" src="https://github.com/calcom/atoms-examples/assets/42170848/82ce4d7a-fc08-489a-ab06-a8eb41a68a2a">