Files
Peer RichelsenGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ba6a87b699 refactor(companion): split calcom.ts into modular service files (#27206)
* 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>
2026-01-26 19:03:41 +05:30

109 lines
2.6 KiB
TypeScript

/**
* Private links functions for Cal.com API
*/
import type { CreatePrivateLinkInput, PrivateLink, UpdatePrivateLinkInput } from "../types";
import { makeRequest } from "./request";
import { sanitizePayload } from "./utils";
/**
* Get all private links for an event type
*/
export async function getEventTypePrivateLinks(eventTypeId: number): Promise<PrivateLink[]> {
try {
const response = await makeRequest<{ status: string; data: PrivateLink[] }>(
`/event-types/${eventTypeId}/private-links`
);
if (response?.data && Array.isArray(response.data)) {
return response.data;
}
return [];
} catch (error) {
console.error("getEventTypePrivateLinks error");
throw error;
}
}
/**
* Create a private link for an event type
*/
export async function createEventTypePrivateLink(
eventTypeId: number,
input: CreatePrivateLinkInput = {}
): Promise<PrivateLink> {
try {
const sanitizedInput = sanitizePayload(input as Record<string, unknown>);
const response = await makeRequest<{ status: string; data: PrivateLink }>(
`/event-types/${eventTypeId}/private-links`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(sanitizedInput),
}
);
if (response?.data) {
return response.data;
}
throw new Error("Invalid response from create private link API");
} catch (error) {
console.error("createEventTypePrivateLink error");
throw error;
}
}
/**
* Update a private link
*/
export async function updateEventTypePrivateLink(
eventTypeId: number,
linkId: number,
updates: UpdatePrivateLinkInput
): Promise<PrivateLink> {
try {
const sanitizedUpdates = sanitizePayload(updates as Record<string, unknown>);
const response = await makeRequest<{ status: string; data: PrivateLink }>(
`/event-types/${eventTypeId}/private-links/${linkId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(sanitizedUpdates),
}
);
if (response?.data) {
return response.data;
}
throw new Error("Invalid response from update private link API");
} catch (error) {
console.error("updateEventTypePrivateLink error");
throw error;
}
}
/**
* Delete a private link
*/
export async function deleteEventTypePrivateLink(
eventTypeId: number,
linkId: number
): Promise<void> {
try {
await makeRequest(`/event-types/${eventTypeId}/private-links/${linkId}`, {
method: "DELETE",
});
} catch (error) {
console.error("deleteEventTypePrivateLink error");
throw error;
}
}