orgEntitlements function
Per-organization entitlements — what does THIS org's plan unlock, regardless of which orgs the caller also belongs to.
Returns a lightweight wrapper around the org_entitlements() Postgres
function. Screens gated by org-scoped features (SSO, webhooks, learning
paths, etc.) should watch this provider for the specific orgId they're
displaying, NOT currentEntitlements, to avoid a multi-org edge case
where a user who belongs to an enterprise org on the side incorrectly
sees their trial org as unlocked.
Implementation
@riverpod
Future<OrgEntitlement> orgEntitlements(Ref ref, String orgId) async {
ref.watch(authStateProvider);
final ds = ref.watch(entitlementDatasourceProvider);
final raw = await ds.getOrgEntitlements(orgId);
return OrgEntitlement.fromJson(raw ?? const {});
}