Dashboard › cli › Distillation
97a64b33-907e-404f-96b1-17a955dd8c96["lore_tm_v1_5crnSW5U1MArXRwOOwyjUiLV0s6IrYx6lGi9Igin37E"]
packages/cli/src/lib/region.ts:8-14 imports getOrganization from @sentry/api; getConfiguredSentryUrl; getOrgByNumericId, getOrgRegion, and setOrgRegion; stripDsnOrgPrefix; withAuthGuard; getSdkConfig; and getSentryBaseUrl plus isSentrySaasUrl.packages/cli/src/lib/region.ts:16-26 defines regionCache as new Map<string, Promise<string>>(), keyed by orgSlug. It deduplicates concurrent region resolution, retains resolved promises as a warm in-memory cache, and evicts rejected promises so retries after re-authentication can succeed without restarting the CLI.resolveOrgRegion(orgSlug) in packages/cli/src/lib/region.ts:46-59 returns an existing cached promise when present; otherwise it calls resolveOrgRegionUncached(orgSlug), inserts that promise into regionCache, and attaches promise.catch(() => regionCache.delete(orgSlug)). The rejection eviction specifically addresses propagated AuthErrors; non-authentication failures resolve to the base-URL fallback.packages/cli/src/lib/region.ts:35-41 is exactly: 1. return an in-flight or previously resolved promise; 2. check the SQLite cache; 3. fetch organization details through the SDK for the region URL; 4. fall back to the default URL if resolution fails. The SDK is used directly rather than api-client to avoid a circular dependency.resolveOrgRegionUncached(orgSlug) in packages/cli/src/lib/region.ts:65-101 first calls getOrgRegion(orgSlug) and immediately returns a SQLite-cached URL. On a miss, it obtains baseUrl = getSentryBaseUrl() and config = getSdkConfig(baseUrl), then runs the organization lookup through withAuthGuard.resolveOrgRegionUncached() calls getOrganization({ ...config, path: { organization_id_or_slug: orgSlug } }). If response.error !== undefined, it throws the SDK error so withAuthGuard can propagate authentication errors while allowing other errors to fall back.resolveOrgRegionUncached() selects response.data?.links?.regionUrl || baseUrl, calls setOrgRegion(orgSlug, regionUrl), and returns regionUrl. The setOrgRegion() call both persists the mapping and extends the in-process trust class so the next regional request passes the fetch-layer guard without separate registration.withAuthGuard, resolveOrgRegionUncached() returns result.ok ? result.value : baseUrl; network failures, HTTP 404 responses, and similar non-authentication errors therefore use the default URL, supporting self-hosted instances without multi-region behavior.isMultiRegionEnabled() in packages/cli/src/lib/region.ts:107-114 reads getConfiguredSentryUrl() and returns false when a configured base URL exists and !isSentrySaasUrl(baseUrl); otherwise it returns true. This treats custom SENTRY_HOST/SENTRY_URL self-hosted instances as not typically supporting regional URLs.resolveOrgFromCache(orgSlug) in packages/cli/src/lib/region.ts:125-140 first tests whether the supplied slug is directly represented by getOrgRegion(orgSlug) and returns the original slug on a hit. Otherwise it computes numericId = stripDsnOrgPrefix(orgSlug); when the value changed, it queries getOrgByNumericId(numericId) and returns match.slug if found. Example normalization is o1081365 → 1081365 → cached slug; a cache miss returns undefined.resolveEffectiveOrg(orgSlug) begins at packages/cli/src/lib/region.ts:165. Its documented behavior distinguishes normal slugs such as acme-corp from DSN-derived numeric identifiers such as o1081365, which are not recognized directly by the Sentry API.resolveEffectiveOrg() is exactly: 1. check the local cache and return the slug; 2. call resolveOrgRegion(orgSlug) once to fetch organization details and populate the region cache, treating success as validation; 3. fall back to the original slug for downstream error handling.resolveEffectiveOrg() is exactly: 1. check the local cache for a numeric-ID-to-slug mapping; 2. refresh the full organization list from the API, fanning out across all regions to populate that mapping; 3. retry the cache lookup and fall back to the original identifier if still unresolved.resolveEffectiveOrg() in packages/cli/src/lib/region.ts:165-180 first calls resolveOrgFromCache(orgSlug) and returns its result on a hit. It then computes numericId = stripDsnOrgPrefix(orgSlug) and isDsnNumericId = numericId !== orgSlug. For a normal slug, it chooses a single resolveOrgRegion() request rather than the heavier listOrganizationsUncached() fan-out, documented as 1 API request versus 1+N requests; the remainder of this branch lies beyond the displayed line 180.