resolveEndpointKeyName function
Resolves the effective key-slot NAME for baseUrl — the host-facing
half of the same chain resolveEndpointKey resolves values through
(issue #1322 Gap 2). Order mirrors the value chain exactly:
- (default endpoint only) the first
envNamesentry holding a genuine environment value — the ecosystem convention stays first; - the endpoint-scoped secure-store slot (
FA_KEY_<HOST>, oractiveCustomKeyNamefor a non-default endpoint — the entry's own pinned slot wins over the host-scoped one); - (default endpoint only) legacy env-name store entries.
defaultBaseUrl is nullable: a host that does not know the catalog
default passes null (the default) and gets store-only resolution —
the env-name leg can then never hijack a custom endpoint (issue #40).
Implementation
String? resolveEndpointKeyName({
required List<String> envNames,
required String? defaultBaseUrl,
required String baseUrl,
required String? Function(String name) envRead,
required String? Function(String name)? storeRead,
String? activeCustomKeyName,
}) {
final defaultEndpoint = defaultBaseUrl != null && baseUrl == defaultBaseUrl;
if (defaultEndpoint) {
final genuine = _firstGenuineEnvName(envNames, envRead, storeRead);
if (genuine != null) return genuine;
}
final pinned = _pinnedSlotName(
defaultEndpoint,
activeCustomKeyName,
storeRead,
);
if (pinned != null) return pinned;
final scoped = CustomProviderRegistry.keyNameFor(baseUrl);
if (_hasStoreValue(scoped, storeRead)) return scoped;
if (defaultEndpoint) return _legacyEnvSlotName(envNames, storeRead);
return null;
}