resolveEndpointKey function
Resolves the API key for baseUrl given the catalog env envNames and
the spec's defaultBaseUrl. envRead reads genuine environment values;
storeRead reads the secure store (null store = env-only resolution,
e.g. tests or the web build). activeCustomKeyName is the active custom
registry entry's own key name, when known (wins over the host-scoped
entry for non-default endpoints).
Implementation
String? resolveEndpointKey({
required List<String> envNames,
required String defaultBaseUrl,
required String baseUrl,
required String? Function(String name) envRead,
required String? Function(String name)? storeRead,
String? activeCustomKeyName,
}) {
if (baseUrl == defaultBaseUrl) {
return _genuineEnvValue(envNames, envRead, storeRead) ??
_storeValue(CustomProviderRegistry.keyNameFor(baseUrl), storeRead) ??
_firstStoreValue(envNames, storeRead);
}
if (activeCustomKeyName != null) {
final value = _storeValue(activeCustomKeyName, storeRead);
if (value != null) return value;
}
return _storeValue(CustomProviderRegistry.keyNameFor(baseUrl), storeRead);
}