Skip to content

Commit 428111b

Browse files
chore: minor changes
1 parent d3a85ad commit 428111b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/lib/api-client.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747

4848
import type { AutofixResponse, AutofixState } from "../types/seer.js";
4949
import { ApiError, AuthError } from "./errors.js";
50+
import { resolveOrgRegion } from "./region.js";
5051
import {
5152
getApiBaseUrl,
5253
getControlSiloUrl,
@@ -162,7 +163,6 @@ export function buildSearchParams(
162163
* Resolves the org's region URL and returns the config.
163164
*/
164165
async function getOrgSdkConfig(orgSlug: string) {
165-
const { resolveOrgRegion } = await import("./region.js");
166166
const regionUrl = await resolveOrgRegion(orgSlug);
167167
return getSdkConfig(regionUrl);
168168
}
@@ -460,7 +460,6 @@ export type ProjectWithOrg = SentryProject & {
460460
*/
461461
export function listRepositories(orgSlug: string): Promise<SentryRepository[]> {
462462
return withHttpSpan("GET", `/organizations/${orgSlug}/repos/`, async () => {
463-
const { resolveOrgRegion } = await import("./region.js");
464463
const regionUrl = await resolveOrgRegion(orgSlug);
465464

466465
return apiRequestToRegion<SentryRepository[]>(
@@ -698,7 +697,6 @@ export function listIssues(
698697
"GET",
699698
`/projects/${orgSlug}/${projectSlug}/issues/`,
700699
async () => {
701-
const { resolveOrgRegion } = await import("./region.js");
702700
const regionUrl = await resolveOrgRegion(orgSlug);
703701

704702
// Use raw request: the SDK type doesn't support limit/sort params
@@ -855,7 +853,6 @@ export function getDetailedTrace(
855853
"GET",
856854
`/organizations/${orgSlug}/trace/${traceId}/`,
857855
async () => {
858-
const { resolveOrgRegion } = await import("./region.js");
859856
const regionUrl = await resolveOrgRegion(orgSlug);
860857

861858
return apiRequestToRegion<TraceSpan[]>(
@@ -917,7 +914,6 @@ export function listTransactions(
917914
const projectFilter = isNumericProject ? "" : `project:${projectSlug}`;
918915
const fullQuery = [projectFilter, options.query].filter(Boolean).join(" ");
919916

920-
const { resolveOrgRegion } = await import("./region.js");
921917
const regionUrl = await resolveOrgRegion(orgSlug);
922918

923919
// Use raw request: the SDK's dataset type doesn't include "transactions"
@@ -1056,7 +1052,6 @@ export function triggerSolutionPlanning(
10561052
"POST",
10571053
`/organizations/${orgSlug}/issues/${issueId}/autofix/`,
10581054
async () => {
1059-
const { resolveOrgRegion } = await import("./region.js");
10601055
const regionUrl = await resolveOrgRegion(orgSlug);
10611056

10621057
return apiRequestToRegion(

src/lib/region.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
* using cached data when available or fetching from the API when needed.
66
*/
77

8+
import { retrieveAnOrganization } from "@sentry/api";
89
import { getOrgRegion, setOrgRegion } from "./db/regions.js";
10+
import { getSdkConfig } from "./sentry-client.js";
911
import { getSentryBaseUrl, isSentrySaasUrl } from "./sentry-urls.js";
1012

1113
/**
1214
* Resolve the region URL for an organization.
1315
*
1416
* Resolution order:
1517
* 1. Check SQLite cache
16-
* 2. Fetch organization details to get region URL
18+
* 2. Fetch organization details via SDK to get region URL
1719
* 3. Fall back to default URL if resolution fails
1820
*
21+
* Uses the SDK directly (not api-client) to avoid circular dependency.
22+
*
1923
* @param orgSlug - The organization slug
2024
* @returns The region URL for the organization
2125
*/
@@ -26,20 +30,21 @@ export async function resolveOrgRegion(orgSlug: string): Promise<string> {
2630
return cached;
2731
}
2832

29-
// 2. Try to fetch org details to get region
30-
// Import dynamically to avoid circular dependency
31-
const { apiRequestToRegion } = await import("./api-client.js");
32-
type OrgWithLinks = { links?: { regionUrl?: string } };
33+
// 2. Fetch org details via SDK to discover the region URL
34+
const baseUrl = getSentryBaseUrl();
35+
const config = getSdkConfig(baseUrl);
3336

3437
try {
35-
// First try the default URL - it may route correctly
36-
const baseUrl = getSentryBaseUrl();
37-
const org = await apiRequestToRegion<OrgWithLinks>(
38-
baseUrl,
39-
`/organizations/${orgSlug}/`
40-
);
38+
const result = await retrieveAnOrganization({
39+
...config,
40+
path: { organization_id_or_slug: orgSlug },
41+
});
42+
43+
if (result.error !== undefined) {
44+
return baseUrl;
45+
}
4146

42-
const regionUrl = org.links?.regionUrl ?? baseUrl;
47+
const regionUrl = result.data?.links?.regionUrl ?? baseUrl;
4348

4449
// Cache for future use
4550
await setOrgRegion(orgSlug, regionUrl);

0 commit comments

Comments
 (0)