From d02947f8871368630892d8a3d04cbbd7e673db94 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 25 Apr 2024 20:22:47 -0300 Subject: [PATCH] chore: SDK cleanup (#14763) --- packages/platform/sdk/src/cal.ts | 4 ++-- packages/platform/sdk/src/endpoints/endpoint-handler.ts | 2 +- .../src/endpoints/{ee/users => managed-users}/index.ts | 8 ++++---- .../src/endpoints/{ee/users => managed-users}/types.ts | 0 packages/platform/sdk/src/lib/http-caller.ts | 8 +++----- packages/platform/sdk/src/lib/sdk-secrets.ts | 7 ++----- packages/platform/sdk/src/types.ts | 2 +- 7 files changed, 13 insertions(+), 18 deletions(-) rename packages/platform/sdk/src/endpoints/{ee/users => managed-users}/index.ts (88%) rename packages/platform/sdk/src/endpoints/{ee/users => managed-users}/types.ts (100%) diff --git a/packages/platform/sdk/src/cal.ts b/packages/platform/sdk/src/cal.ts index 14669427f2..bf27f4a26f 100644 --- a/packages/platform/sdk/src/cal.ts +++ b/packages/platform/sdk/src/cal.ts @@ -2,9 +2,9 @@ import axios from "axios"; import axiosRetry from "axios-retry"; import { Bookings } from "./endpoints/bookings"; -import { ManagedUsers } from "./endpoints/ee/users"; import { Events } from "./endpoints/events"; import { EventTypes } from "./endpoints/events/event-types"; +import { ManagedUsers } from "./endpoints/managed-users"; import { OAuthFlow } from "./endpoints/oauth-flow"; import { Schedules } from "./endpoints/schedules"; import { Slots } from "./endpoints/slots"; @@ -24,7 +24,7 @@ export class CalSdk { schedules: Schedules; users: ManagedUsers; - private _secrets: SdkSecrets; + private readonly _secrets: SdkSecrets; constructor( public readonly clientId: string, diff --git a/packages/platform/sdk/src/endpoints/endpoint-handler.ts b/packages/platform/sdk/src/endpoints/endpoint-handler.ts index 9d5723a2b6..caf7680c7a 100644 --- a/packages/platform/sdk/src/endpoints/endpoint-handler.ts +++ b/packages/platform/sdk/src/endpoints/endpoint-handler.ts @@ -6,7 +6,7 @@ import { assert } from "ts-essentials"; import type { CalSdk } from "../cal"; export abstract class EndpointHandler { - constructor(private readonly key: string, private readonly calSdk: CalSdk) {} + protected constructor(private readonly key: string, private readonly calSdk: CalSdk) {} withForAtomParam(forAtom: boolean, config?: AxiosRequestConfig) { if (!forAtom) return config; diff --git a/packages/platform/sdk/src/endpoints/ee/users/index.ts b/packages/platform/sdk/src/endpoints/managed-users/index.ts similarity index 88% rename from packages/platform/sdk/src/endpoints/ee/users/index.ts rename to packages/platform/sdk/src/endpoints/managed-users/index.ts index a78389fee1..3d35789f1d 100644 --- a/packages/platform/sdk/src/endpoints/ee/users/index.ts +++ b/packages/platform/sdk/src/endpoints/managed-users/index.ts @@ -1,7 +1,7 @@ -import type { CalSdk } from "../../../cal"; -import { Endpoints } from "../../../lib/endpoints"; -import type { BasicPlatformResponse, PaginationOptions } from "../../../types"; -import { EndpointHandler } from "../../endpoint-handler"; +import type { CalSdk } from "../../cal"; +import { Endpoints } from "../../lib/endpoints"; +import type { BasicPlatformResponse, PaginationOptions } from "../../types"; +import { EndpointHandler } from "../endpoint-handler"; import type { CreateUserArgs, CreateUserResponse, User } from "./types"; export class ManagedUsers extends EndpointHandler { diff --git a/packages/platform/sdk/src/endpoints/ee/users/types.ts b/packages/platform/sdk/src/endpoints/managed-users/types.ts similarity index 100% rename from packages/platform/sdk/src/endpoints/ee/users/types.ts rename to packages/platform/sdk/src/endpoints/managed-users/types.ts diff --git a/packages/platform/sdk/src/lib/http-caller.ts b/packages/platform/sdk/src/lib/http-caller.ts index bea196cfc9..c55bb7f33c 100644 --- a/packages/platform/sdk/src/lib/http-caller.ts +++ b/packages/platform/sdk/src/lib/http-caller.ts @@ -35,7 +35,9 @@ export class HttpCaller { private readonly axiosClient: AxiosInstance, private readonly options?: HttpCallerOptions ) { - this.setupInterceptors(); + if (options?.shouldHandleRefresh) { + this.setupInterceptors(); + } } private async retryQueuedRequests() { @@ -161,8 +163,4 @@ export class HttpCaller { params, }); } - - isAwaitingRefresh() { - return this.awaitingRefresh; - } } diff --git a/packages/platform/sdk/src/lib/sdk-secrets.ts b/packages/platform/sdk/src/lib/sdk-secrets.ts index babe6be7e7..44059e29a4 100644 --- a/packages/platform/sdk/src/lib/sdk-secrets.ts +++ b/packages/platform/sdk/src/lib/sdk-secrets.ts @@ -58,10 +58,7 @@ export class SdkSecrets { return !!this.accessToken; } - public _debug() { - return { - refreshedAt: this.refreshedAt, - accessToken: this.accessToken, - }; + public getRefreshedAt(): Date | null { + return this.refreshedAt; } } diff --git a/packages/platform/sdk/src/types.ts b/packages/platform/sdk/src/types.ts index c98c8543fc..4677cf342d 100644 --- a/packages/platform/sdk/src/types.ts +++ b/packages/platform/sdk/src/types.ts @@ -22,7 +22,7 @@ export enum ApiVersion { } export type SdkAuthOptions = { - clientSecret: string; + clientSecret?: string; accessToken?: string; refreshToken?: string; };