fetchSupportedDartSdkPolicy function
Future<SupportedDartSdkPolicy?>
fetchSupportedDartSdkPolicy(
- Client cloudApiClient, {
- required CommandLogger logger,
Fetches the Dart SDK version policy from Serverpod Cloud.
Returns null if the policy cannot be fetched or is invalid, such as on a network error or a server that does not serve the policy endpoint. The caller should then skip policy-based validation - the server enforces the policy when the deployment is created.
Implementation
Future<SupportedDartSdkPolicy?> fetchSupportedDartSdkPolicy(
final Client cloudApiClient, {
required final CommandLogger logger,
}) async {
try {
final policy = await cloudApiClient.platform.getDartSdkVersionPolicy();
final min = Version.parse(policy.minVersionInclusive);
final max = Version.parse(policy.maxVersionExclusive);
if (min >= max) {
logger.debug(
'Skipping Dart SDK version validation: invalid policy range $min..$max',
);
return null;
}
return SupportedDartSdkPolicy(
supportedRange: VersionRange(min: min, includeMin: true, max: max),
supportedVersions: [
for (final version in policy.supportedVersions) version.version,
],
documentationUrl: policy.documentationUrl,
);
} on Exception catch (e) {
logger.debug('Skipping Dart SDK version validation: $e');
return null;
}
}