Skip to content

Commit a63bf11

Browse files
authored
refactor: companion event type query parameters (#27125)
1 parent 509ceea commit a63bf11

File tree

2 files changed

+6
-57
lines changed

2 files changed

+6
-57
lines changed

companion/extension/entrypoints/background/index.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -933,34 +933,9 @@ async function getAuthHeader(): Promise<string> {
933933
async function fetchEventTypes(): Promise<unknown[]> {
934934
const authHeader = await getAuthHeader();
935935

936-
const userResponse = await fetchWithTimeout(`${API_BASE_URL}/me`, {
937-
headers: {
938-
Authorization: authHeader,
939-
"Content-Type": "application/json",
940-
"cal-api-version": "2024-06-11",
941-
},
942-
});
943-
944-
if (!userResponse.ok) {
945-
throw new Error(`Failed to get user: ${userResponse.statusText}`);
946-
}
947-
948-
const userData = await userResponse.json();
949-
const username = userData?.data?.username as string | undefined;
950-
// For org users, include org slug to avoid username collisions across orgs
951-
const orgSlug = userData?.data?.organization?.slug as string | undefined;
952-
953-
const params = new URLSearchParams();
954-
if (username) {
955-
params.append("username", username);
956-
}
957-
if (orgSlug) {
958-
params.append("orgSlug", orgSlug);
959-
}
960-
const queryString = params.toString();
961-
const endpoint = `${API_BASE_URL}/event-types${queryString ? `?${queryString}` : ""}`;
962-
963-
const response = await fetchWithTimeout(endpoint, {
936+
// For authenticated users, no username/orgSlug params needed - API uses auth token
937+
// This also ensures hidden event types are returned (they're filtered out when username is provided)
938+
const response = await fetchWithTimeout(`${API_BASE_URL}/event-types`, {
964939
headers: {
965940
Authorization: authHeader,
966941
"Content-Type": "application/json",

companion/services/calcom.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -862,36 +862,10 @@ async function getTranscripts(bookingUid: string): Promise<BookingTranscript[]>
862862
}
863863

864864
async function getEventTypes(): Promise<EventType[]> {
865-
// Get cached user profile to extract username and org slug (uses in-flight deduplication)
866-
let username: string | undefined;
867-
let orgSlug: string | undefined;
868-
try {
869-
const userProfile = await getUserProfile();
870-
// Extract username from response
871-
if (userProfile?.username) {
872-
username = userProfile.username;
873-
}
874-
// For org users, include org slug to avoid username collisions across orgs
875-
if (userProfile?.organization?.slug) {
876-
orgSlug = userProfile.organization.slug;
877-
}
878-
} catch (_error) {}
879-
880-
// Build query string with username, orgSlug, and sorting
881-
const params = new URLSearchParams();
882-
if (username) {
883-
params.append("username", username);
884-
}
885-
if (orgSlug) {
886-
params.append("orgSlug", orgSlug);
887-
}
865+
// For authenticated users, no username/orgSlug params needed - API uses auth token
866+
// This also ensures hidden event types are returned (they're filtered out when username is provided)
888867
// Sort by creation date descending (newer first) to match main codebase behavior
889-
// Main codebase uses position: "desc", id: "desc" - since API doesn't expose position,
890-
// we use sortCreatedAt: "desc" for similar behavior (newer event types first)
891-
params.append("sortCreatedAt", "desc");
892-
893-
const queryString = params.toString();
894-
const endpoint = `/event-types${queryString ? `?${queryString}` : ""}`;
868+
const endpoint = `/event-types?sortCreatedAt=desc`;
895869

896870
const response = await makeRequest<unknown>(endpoint, {}, "2024-06-14");
897871

0 commit comments

Comments
 (0)