mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
ba6a87b699
* refactor(companion): split calcom.ts into modular service files Split the monolithic 1692-line calcom.ts file into focused modules: - auth.ts: Authentication configuration and token management - bookings.ts: Booking CRUD operations and actions - conferencing.ts: Conferencing options - event-types.ts: Event type CRUD operations - private-links.ts: Private link management for event types - request.ts: Core HTTP request functionality - schedules.ts: Schedule CRUD operations - user.ts: User profile management - utils.ts: JSON parsing and payload sanitization utilities - webhooks.ts: Webhook management (global and event type specific) - index.ts: Re-exports all functions and maintains backward compatibility This improves code organization, maintainability, and makes it easier to understand and modify specific functionality. Co-Authored-By: [email protected] <[email protected]> * fix(companion): avoid logging sensitive booking response data Replace logging of full responseText (which may contain PII like attendee emails and names) with responseLength for safer debugging. Addresses Cubic AI review feedback (confidence 9/10). Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
/**
|
|
* Authentication configuration and functions for Cal.com API
|
|
*/
|
|
|
|
// Authentication configuration
|
|
interface AuthConfig {
|
|
accessToken?: string;
|
|
refreshToken?: string;
|
|
}
|
|
|
|
// Global auth state
|
|
const authConfig: AuthConfig = {};
|
|
|
|
// Token refresh callback - will be set by AuthContext
|
|
let tokenRefreshCallback: ((accessToken: string, refreshToken?: string) => Promise<void>) | null =
|
|
null;
|
|
|
|
// Refresh token function - will be set by AuthContext
|
|
let refreshTokenFunction:
|
|
| ((refreshToken: string) => Promise<{ accessToken: string; refreshToken?: string }>)
|
|
| null = null;
|
|
|
|
/**
|
|
* Set OAuth access token for authentication
|
|
*/
|
|
export function setAccessToken(accessToken: string, refreshToken?: string): void {
|
|
authConfig.accessToken = accessToken;
|
|
if (refreshToken) {
|
|
authConfig.refreshToken = refreshToken;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Set refresh token function for automatic token refresh
|
|
*/
|
|
export function setRefreshTokenFunction(
|
|
refreshFn: (refreshToken: string) => Promise<{ accessToken: string; refreshToken?: string }>
|
|
): void {
|
|
refreshTokenFunction = refreshFn;
|
|
}
|
|
|
|
/**
|
|
* Clear all authentication
|
|
*/
|
|
export function clearAuth(): void {
|
|
authConfig.accessToken = undefined;
|
|
authConfig.refreshToken = undefined;
|
|
tokenRefreshCallback = null;
|
|
refreshTokenFunction = null;
|
|
}
|
|
|
|
/**
|
|
* Set token refresh callback for OAuth token refresh
|
|
*/
|
|
export function setTokenRefreshCallback(
|
|
callback: (accessToken: string, refreshToken?: string) => Promise<void>
|
|
): void {
|
|
tokenRefreshCallback = callback;
|
|
}
|
|
|
|
/**
|
|
* Get current authentication header
|
|
*/
|
|
export function getAuthHeader(): string {
|
|
if (authConfig.accessToken) {
|
|
return `Bearer ${authConfig.accessToken}`;
|
|
} else {
|
|
throw new Error("No authentication configured. Please sign in with OAuth.");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the current auth config (for internal use by request module)
|
|
*/
|
|
export function getAuthConfig(): AuthConfig {
|
|
return authConfig;
|
|
}
|
|
|
|
/**
|
|
* Get the token refresh callback (for internal use by request module)
|
|
*/
|
|
export function getTokenRefreshCallback(): typeof tokenRefreshCallback {
|
|
return tokenRefreshCallback;
|
|
}
|
|
|
|
/**
|
|
* Get the refresh token function (for internal use by request module)
|
|
*/
|
|
export function getRefreshTokenFunction(): typeof refreshTokenFunction {
|
|
return refreshTokenFunction;
|
|
}
|