From 70c653709ed23fd352cd3404a11d0bfe71ac615b Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Mon, 8 Dec 2025 15:04:08 -0500 Subject: [PATCH] feat(code_push_protocol): add availableRoles to ShorebirdPlan (#3423) --- .../lib/src/models/plan.dart | 4 ++++ .../lib/src/models/plan.g.dart | 17 +++++++++++++++++ .../test/src/models/plan_test.dart | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/shorebird_code_push_protocol/lib/src/models/plan.dart b/packages/shorebird_code_push_protocol/lib/src/models/plan.dart index 0636f711..3df36a68 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/plan.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/plan.dart @@ -22,6 +22,7 @@ class Plan { required this.cancelAtPeriodEnd, required this.isTiered, required this.isTrial, + required this.availableRoles, this.pricePerOverageInstall, this.maxTeamSize, }); @@ -74,4 +75,7 @@ class Plan { /// The maximum number of collaborators allowed per account. This will be null /// for accounts with unlimited collaborators. final int? maxTeamSize; + + /// Roles assignable to users associated with this plan. + final List availableRoles; } diff --git a/packages/shorebird_code_push_protocol/lib/src/models/plan.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/plan.g.dart index 6585c408..731553b0 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/plan.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/plan.g.dart @@ -34,6 +34,12 @@ Plan _$PlanFromJson(Map json) => $checkedCreate( ), isTiered: $checkedConvert('is_tiered', (v) => v as bool), isTrial: $checkedConvert('is_trial', (v) => v as bool), + availableRoles: $checkedConvert( + 'available_roles', + (v) => (v as List) + .map((e) => $enumDecode(_$RoleEnumMap, e)) + .toList(), + ), pricePerOverageInstall: $checkedConvert( 'price_per_overage_install', (v) => v == null ? null : Decimal.fromJson(v as String), @@ -53,6 +59,7 @@ Plan _$PlanFromJson(Map json) => $checkedCreate( 'cancelAtPeriodEnd': 'cancel_at_period_end', 'isTiered': 'is_tiered', 'isTrial': 'is_trial', + 'availableRoles': 'available_roles', 'pricePerOverageInstall': 'price_per_overage_install', 'maxTeamSize': 'max_team_size', }, @@ -70,4 +77,14 @@ Map _$PlanToJson(Plan instance) => { 'is_tiered': instance.isTiered, 'is_trial': instance.isTrial, 'max_team_size': instance.maxTeamSize, + 'available_roles': instance.availableRoles + .map((e) => _$RoleEnumMap[e]!) + .toList(), +}; + +const _$RoleEnumMap = { + Role.owner: 'owner', + Role.admin: 'admin', + Role.developer: 'developer', + Role.none: 'none', }; diff --git a/packages/shorebird_code_push_protocol/test/src/models/plan_test.dart b/packages/shorebird_code_push_protocol/test/src/models/plan_test.dart index c6533716..b41cd8a8 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/plan_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/plan_test.dart @@ -1,5 +1,5 @@ import 'package:decimal/decimal.dart'; -import 'package:shorebird_code_push_protocol/src/models/plan.dart'; +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { @@ -17,6 +17,7 @@ void main() { maxTeamSize: 42, pricePerOverageInstall: Decimal.fromInt(10), isTrial: true, + availableRoles: [Role.admin, Role.developer], ); expect(Plan.fromJson(plan.toJson()).toJson(), equals(plan.toJson()));