From 9451f38cec7e0372a2ff3c1e2217c7525e7d3910 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 2 Apr 2024 15:31:01 -0300 Subject: [PATCH] chore: SDK Fixes and add swagger docs (#14218) * chore: fixes and add swagger docs * chore: add script --- packages/platform/sdk/package.json | 4 +- .../src/endpoints/events/event-types/index.ts | 10 +- packages/platform/sdk/src/swagger-types.d.ts | 877 ++++++++++++++++++ 3 files changed, 883 insertions(+), 8 deletions(-) create mode 100644 packages/platform/sdk/src/swagger-types.d.ts diff --git a/packages/platform/sdk/package.json b/packages/platform/sdk/package.json index c128dea816073a..1cb7b2862023fa 100644 --- a/packages/platform/sdk/package.json +++ b/packages/platform/sdk/package.json @@ -10,7 +10,8 @@ ], "scripts": { "build": "rollup -c --bundleConfigAsCjs", - "release": "release-it --only-version" + "release": "release-it --only-version", + "generate-types": "openapi-typescript http://localhost:5555/docs-yaml -o ./src/swagger-types.d.ts" }, "packageManager": "yarn@3.4.1", "devDependencies": { @@ -18,6 +19,7 @@ "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-typescript": "^11.1.6", + "openapi-typescript": "^6.7.5", "release-it": "^17.1.1", "rollup": "^4.12.0", "rollup-plugin-bundle-size": "^1.0.3", diff --git a/packages/platform/sdk/src/endpoints/events/event-types/index.ts b/packages/platform/sdk/src/endpoints/events/event-types/index.ts index 46d33c9cad83b5..28c687bea47bb9 100644 --- a/packages/platform/sdk/src/endpoints/events/event-types/index.ts +++ b/packages/platform/sdk/src/endpoints/events/event-types/index.ts @@ -4,10 +4,6 @@ import type { BasicPlatformResponse } from "../../../types"; import { EndpointHandler } from "../../endpoint-handler"; import type { CreateEventTypeArgs, EventType, GetEventTypeByIdArgs } from "./types"; -type BodyWithEventTypeResponse = { - eventType: EventType; -}; - export class EventTypes extends EndpointHandler { constructor(private readonly sdk: CalSdk) { super("event-types", sdk); @@ -16,20 +12,20 @@ export class EventTypes extends EndpointHandler { async createEventType(args: CreateEventTypeArgs): Promise { this.assertAccessToken("createEventType"); - const { data } = await this.sdk.httpCaller.post>( + const { data } = await this.sdk.httpCaller.post>( Endpoints.CREATE_EVENT_TYPE, { body: args, } ); - return data.eventType; + return data; } async getEventType(args: GetEventTypeByIdArgs): Promise { this.assertAccessToken("getEventType"); - const { data } = await this.sdk.httpCaller.get>( + const { data } = await this.sdk.httpCaller.get>( Endpoints.GET_EVENT_TYPE_BY_ID, { urlParams: [args.id], diff --git a/packages/platform/sdk/src/swagger-types.d.ts b/packages/platform/sdk/src/swagger-types.d.ts new file mode 100644 index 00000000000000..edca446943a1c9 --- /dev/null +++ b/packages/platform/sdk/src/swagger-types.d.ts @@ -0,0 +1,877 @@ +/** + * This file was auto-generated by openapi-typescript. + * Do not make direct changes to the file. + */ + +export interface paths { + "/health": { + get: operations["AppController_getHealth"]; + }; + "/api/v2/events/public": { + get: operations["EventsController_getPublicEvent"]; + }; + "/api/v2/oauth-clients/{clientId}/users": { + post: operations["OAuthClientUsersController_createUser"]; + }; + "/api/v2/oauth-clients/{clientId}/users/{userId}": { + get: operations["OAuthClientUsersController_getUserById"]; + delete: operations["OAuthClientUsersController_deleteUser"]; + patch: operations["OAuthClientUsersController_updateUser"]; + }; + "/api/v2/oauth-clients": { + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + get: operations["OAuthClientsController_getOAuthClients"]; + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + post: operations["OAuthClientsController_createOAuthClient"]; + }; + "/api/v2/oauth-clients/{clientId}": { + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + get: operations["OAuthClientsController_getOAuthClientById"]; + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + delete: operations["OAuthClientsController_deleteOAuthClient"]; + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + patch: operations["OAuthClientsController_updateOAuthClient"]; + }; + "/api/v2/oauth/{clientId}/authorize": { + /** + * Authorize an OAuth client + * @description Redirects the user to the specified 'redirect_uri' with an authorization code in query parameter if the client is authorized successfully. The code is then exchanged for access and refresh tokens via the `/exchange` endpoint. + */ + post: operations["OAuthFlowController_authorize"]; + }; + "/api/v2/oauth/{clientId}/exchange": { + /** + * Exchange authorization code for access tokens + * @description Exchanges the authorization code received from the `/authorize` endpoint for access and refresh tokens. The authorization code should be provided in the 'Authorization' header prefixed with 'Bearer '. + */ + post: operations["OAuthFlowController_exchange"]; + }; + "/api/v2/oauth/{clientId}/refresh": { + post: operations["OAuthFlowController_refreshAccessToken"]; + }; + "/api/v2/event-types": { + get: operations["EventTypesController_getEventTypes"]; + post: operations["EventTypesController_createEventType"]; + }; + "/api/v2/event-types/{eventTypeId}": { + get: operations["EventTypesController_getEventType"]; + }; + "/api/v2/event-types/{username}/public": { + get: operations["EventTypesController_getPublicEventTypes"]; + }; + "/api/v2/platform/gcal/oauth/auth-url": { + get: operations["GcalController_redirect"]; + }; + "/api/v2/platform/gcal/oauth/save": { + get: operations["GcalController_save"]; + }; + "/api/v2/platform/gcal/check": { + get: operations["GcalController_check"]; + }; + "/api/v2/platform/provider/{clientId}": { + get: operations["CalProviderController_verifyClientId"]; + }; + "/api/v2/platform/provider/{clientId}/access-token": { + get: operations["CalProviderController_verifyAccessToken"]; + }; + "/api/v2/schedules": { + get: operations["SchedulesController_getSchedules"]; + post: operations["SchedulesController_createSchedule"]; + }; + "/api/v2/schedules/default": { + get: operations["SchedulesController_getDefaultSchedule"]; + }; + "/api/v2/schedules/time-zones": { + get: operations["SchedulesController_getTimeZones"]; + }; + "/api/v2/schedules/{scheduleId}": { + get: operations["SchedulesController_getSchedule"]; + delete: operations["SchedulesController_deleteSchedule"]; + patch: operations["SchedulesController_updateSchedule"]; + }; + "/api/v2/me": { + get: operations["MeController_getMe"]; + patch: operations["MeController_updateMe"]; + }; + "/api/v2/ee/calendars/busy-times": { + get: operations["CalendarsController_getBusyTimes"]; + }; + "/api/v2/ee/calendars": { + get: operations["CalendarsController_getCalendars"]; + }; + "/api/v2/ee/bookings": { + post: operations["BookingsController_createBooking"]; + }; + "/api/v2/ee/bookings/reccuring": { + post: operations["BookingsController_createReccuringBooking"]; + }; + "/api/v2/ee/bookings/instant": { + post: operations["BookingsController_createInstantBooking"]; + }; + "/api/v2/slots/reserve": { + post: operations["SlotsController_reserveSlot"]; + }; + "/api/v2/slots/selected-slot": { + delete: operations["SlotsController_deleteSelectedSlot"]; + }; + "/api/v2/slots/available": { + get: operations["SlotsController_getAvailableSlots"]; + }; +} + +export type webhooks = Record; + +export interface components { + schemas: { + CreateManagedPlatformUserInput: { + email: string; + name?: string; + timeFormat?: number; + weekStart?: string; + timeZone?: string; + }; + UpdateManagedPlatformUserInput: { + email?: string; + name?: string; + timeFormat?: number; + defaultScheduleId?: number; + weekStart?: string; + timeZone?: string; + }; + CreateOAuthClientInput: Record; + DataDto: { + /** @example clsx38nbl0001vkhlwin9fmt0 */ + clientId: string; + /** @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoib2F1dGgtY2xpZW50Iiwi */ + clientSecret: string; + }; + CreateOAuthClientResponseDto: { + /** + * @example success + * @enum {string} + */ + status: "success" | "error"; + /** + * @example { + * "clientId": "clsx38nbl0001vkhlwin9fmt0", + * "clientSecret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoib2F1dGgtY2xpZW50Iiwi" + * } + */ + data: components["schemas"]["DataDto"]; + }; + PlatformOAuthClientDto: { + /** @example clsx38nbl0001vkhlwin9fmt0 */ + id: string; + /** @example MyClient */ + name: string; + /** @example secretValue */ + secret: string; + /** @example 3 */ + permissions: number; + /** @example https://example.com/logo.png */ + logo?: Record; + /** + * @example [ + * "https://example.com/callback" + * ] + */ + redirectUris: string[]; + /** @example 1 */ + organizationId: number; + /** + * Format: date-time + * @example 2024-03-23T08:33:21.851Z + */ + createdAt: string; + }; + GetOAuthClientsResponseDto: { + /** + * @example success + * @enum {string} + */ + status: "success" | "error"; + data: components["schemas"]["PlatformOAuthClientDto"][]; + }; + GetOAuthClientResponseDto: { + /** + * @example success + * @enum {string} + */ + status: "success" | "error"; + data: components["schemas"]["PlatformOAuthClientDto"]; + }; + UpdateOAuthClientInput: { + logo?: string; + name?: string; + /** @default [] */ + redirectUris?: string[]; + }; + OAuthAuthorizeInput: { + redirectUri: string; + }; + ExchangeAuthorizationCodeInput: { + clientSecret: string; + }; + KeysDto: { + /** @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 */ + accessToken: string; + /** @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 */ + refreshToken: string; + }; + KeysResponseDto: { + /** + * @example success + * @enum {string} + */ + status: "success" | "error"; + data: components["schemas"]["KeysDto"]; + }; + RefreshTokenInput: { + refreshToken: string; + }; + CreateEventTypeInput: { + length: number; + slug: string; + title: string; + }; + CreateAvailabilityInput: { + days: number[]; + /** Format: date-time */ + startTime: string; + /** Format: date-time */ + endTime: string; + }; + CreateScheduleInput: { + name: string; + timeZone: string; + availabilities?: components["schemas"]["CreateAvailabilityInput"][]; + /** @default true */ + isDefault: Record; + }; + UpdateScheduleInput: Record; + CreateBookingInput: { + end?: string; + start: string; + eventTypeId: number; + eventTypeSlug?: string; + rescheduleUid?: string; + recurringEventId?: string; + timeZone: string; + user?: string[]; + language: string; + bookingUid?: string; + metadata: Record; + hasHashedBookingLink?: boolean; + hashedLink: string | null; + seatReferenceUid?: string; + }; + ReserveSlotInput: Record; + }; + responses: never; + parameters: never; + requestBodies: never; + headers: never; + pathItems: never; +} + +export type $defs = Record; + +export type external = Record; + +export interface operations { + AppController_getHealth: { + responses: { + 200: { + content: { + "application/json": string; + }; + }; + }; + }; + EventsController_getPublicEvent: { + parameters: { + query: { + username: string; + eventSlug: string; + isTeamEvent?: boolean; + org?: string; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + OAuthClientUsersController_createUser: { + parameters: { + path: { + clientId: string; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["CreateManagedPlatformUserInput"]; + }; + }; + responses: { + 201: { + content: { + "application/json": Record; + }; + }; + }; + }; + OAuthClientUsersController_getUserById: { + parameters: { + path: { + clientId: string; + userId: number; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + OAuthClientUsersController_deleteUser: { + parameters: { + path: { + clientId: string; + userId: number; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + OAuthClientUsersController_updateUser: { + parameters: { + path: { + clientId: string; + userId: number; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["UpdateManagedPlatformUserInput"]; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + OAuthClientsController_getOAuthClients: { + responses: { + 200: { + content: { + "application/json": components["schemas"]["GetOAuthClientsResponseDto"]; + }; + }; + }; + }; + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + OAuthClientsController_createOAuthClient: { + requestBody: { + content: { + "application/json": components["schemas"]["CreateOAuthClientInput"]; + }; + }; + responses: { + /** @description Create an OAuth client */ + 201: { + content: { + "application/json": components["schemas"]["CreateOAuthClientResponseDto"]; + }; + }; + }; + }; + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + OAuthClientsController_getOAuthClientById: { + parameters: { + path: { + clientId: string; + }; + }; + responses: { + 200: { + content: { + "application/json": components["schemas"]["GetOAuthClientResponseDto"]; + }; + }; + }; + }; + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + OAuthClientsController_deleteOAuthClient: { + parameters: { + path: { + clientId: string; + }; + }; + responses: { + 200: { + content: { + "application/json": components["schemas"]["GetOAuthClientResponseDto"]; + }; + }; + }; + }; + /** + * @description ⚠️ First, this endpoint requires `Cookie: next-auth.session-token=eyJhbGciOiJ` header. Log into Cal web app using owner of organization that was created after visiting `/settings/organizations/new`, refresh swagger docs, and the cookie will be added to requests automatically to pass the NextAuthGuard. + * Second, make sure that the logged in user has organizationId set to pass the OrganizationRolesGuard guard. + */ + OAuthClientsController_updateOAuthClient: { + parameters: { + path: { + clientId: string; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["UpdateOAuthClientInput"]; + }; + }; + responses: { + 200: { + content: { + "application/json": components["schemas"]["GetOAuthClientResponseDto"]; + }; + }; + }; + }; + /** + * Authorize an OAuth client + * @description Redirects the user to the specified 'redirect_uri' with an authorization code in query parameter if the client is authorized successfully. The code is then exchanged for access and refresh tokens via the `/exchange` endpoint. + */ + OAuthFlowController_authorize: { + parameters: { + path: { + clientId: string; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["OAuthAuthorizeInput"]; + }; + }; + responses: { + /** @description The user is redirected to the 'redirect_uri' with an authorization code in query parameter e.g. `redirectUri?code=secretcode.` */ + 200: { + content: never; + }; + /** @description Bad request if the OAuth client is not found, if the redirect URI is invalid, or if the user has already authorized the client. */ + 400: { + content: never; + }; + }; + }; + /** + * Exchange authorization code for access tokens + * @description Exchanges the authorization code received from the `/authorize` endpoint for access and refresh tokens. The authorization code should be provided in the 'Authorization' header prefixed with 'Bearer '. + */ + OAuthFlowController_exchange: { + parameters: { + header: { + Authorization: string; + }; + path: { + clientId: string; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["ExchangeAuthorizationCodeInput"]; + }; + }; + responses: { + /** @description Successfully exchanged authorization code for access and refresh tokens. */ + 200: { + content: { + "application/json": components["schemas"]["KeysResponseDto"]; + }; + }; + /** @description Bad request if the authorization code is missing, invalid, or if the client ID and secret do not match. */ + 400: { + content: never; + }; + }; + }; + OAuthFlowController_refreshAccessToken: { + parameters: { + header: { + "x-cal-secret-key": string; + }; + path: { + clientId: string; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["RefreshTokenInput"]; + }; + }; + responses: { + 200: { + content: { + "application/json": components["schemas"]["KeysResponseDto"]; + }; + }; + }; + }; + EventTypesController_getEventTypes: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + EventTypesController_createEventType: { + requestBody: { + content: { + "application/json": components["schemas"]["CreateEventTypeInput"]; + }; + }; + responses: { + 201: { + content: { + "application/json": Record; + }; + }; + }; + }; + EventTypesController_getEventType: { + parameters: { + path: { + eventTypeId: string; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + EventTypesController_getPublicEventTypes: { + parameters: { + path: { + username: string; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + GcalController_redirect: { + parameters: { + header: { + Authorization: string; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + GcalController_save: { + parameters: { + query: { + state: string; + code: string; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + GcalController_check: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + CalProviderController_verifyClientId: { + parameters: { + path: { + clientId: string; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + CalProviderController_verifyAccessToken: { + parameters: { + path: { + clientId: string; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + SchedulesController_getSchedules: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + SchedulesController_createSchedule: { + requestBody: { + content: { + "application/json": components["schemas"]["CreateScheduleInput"]; + }; + }; + responses: { + 201: { + content: { + "application/json": Record; + }; + }; + }; + }; + SchedulesController_getDefaultSchedule: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + SchedulesController_getTimeZones: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + SchedulesController_getSchedule: { + parameters: { + path: { + scheduleId: number; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + SchedulesController_deleteSchedule: { + parameters: { + path: { + scheduleId: number; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + SchedulesController_updateSchedule: { + requestBody: { + content: { + "application/json": components["schemas"]["UpdateScheduleInput"]; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + MeController_getMe: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + MeController_updateMe: { + requestBody: { + content: { + "application/json": components["schemas"]["UpdateManagedPlatformUserInput"]; + }; + }; + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + CalendarsController_getBusyTimes: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + CalendarsController_getCalendars: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + BookingsController_createBooking: { + requestBody: { + content: { + "application/json": components["schemas"]["CreateBookingInput"]; + }; + }; + responses: { + 201: { + content: { + "application/json": Record; + }; + }; + }; + }; + BookingsController_createReccuringBooking: { + requestBody: { + content: { + "application/json": string[]; + }; + }; + responses: { + 201: { + content: { + "application/json": Record; + }; + }; + }; + }; + BookingsController_createInstantBooking: { + requestBody: { + content: { + "application/json": components["schemas"]["CreateBookingInput"]; + }; + }; + responses: { + 201: { + content: { + "application/json": Record; + }; + }; + }; + }; + SlotsController_reserveSlot: { + requestBody: { + content: { + "application/json": components["schemas"]["ReserveSlotInput"]; + }; + }; + responses: { + 201: { + content: { + "application/json": Record; + }; + }; + }; + }; + SlotsController_deleteSelectedSlot: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; + SlotsController_getAvailableSlots: { + responses: { + 200: { + content: { + "application/json": Record; + }; + }; + }; + }; +}