resolveEndpointKey function

String? resolveEndpointKey({
  1. required List<String> envNames,
  2. required String defaultBaseUrl,
  3. required String baseUrl,
  4. required String? envRead(
    1. String name
    ),
  5. required String? storeRead(
    1. String name
    )?,
  6. String? activeCustomKeyName,
})

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);
}