activeGrants function
The active entitlements in grants at now: active, with a future
validUntil (milliseconds); and the soonest expiry, to check again at.
Implementation
(Set<String>, int?) activeGrants(Iterable<(String id, Map<String, Object?> data)> grants, int now) {
final active = <String>{};
int? nearest;
for (final (id, data) in grants) {
final until = data['validUntil'];
if (data['active'] == true && until is num && until.isFinite && until > now) {
active.add(id);
if (nearest == null || until < nearest) nearest = until.toInt();
}
}
return (active, nearest);
}