refactor: Remove Plan model from protocol package (#3649)
This commit is contained in:
@@ -9,7 +9,6 @@ export 'organization_membership.dart';
|
||||
export 'organization_user.dart';
|
||||
export 'patch.dart';
|
||||
export 'patch_artifact.dart';
|
||||
export 'plan.dart';
|
||||
export 'private_user.dart';
|
||||
export 'public_user.dart';
|
||||
export 'release.dart';
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import 'package:decimal/decimal.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
|
||||
|
||||
part 'plan.g.dart';
|
||||
|
||||
/// {@template plan}
|
||||
/// A plan represents a user's subscription to the Code Push product. It
|
||||
/// includes details about the plan, such as the name, price, and billing
|
||||
/// period.
|
||||
/// {@endtemplate}
|
||||
@JsonSerializable()
|
||||
class Plan {
|
||||
/// {@macro plan}
|
||||
Plan({
|
||||
required this.name,
|
||||
required this.currency,
|
||||
required this.basePrice,
|
||||
required this.baseInstallCount,
|
||||
required this.currentPeriodStart,
|
||||
required this.currentPeriodEnd,
|
||||
required this.cancelAtPeriodEnd,
|
||||
required this.isTiered,
|
||||
required this.isTrial,
|
||||
required this.availableRoles,
|
||||
required this.mauInsightEnabled,
|
||||
this.pricePerOverageInstall,
|
||||
this.maxTeamSize,
|
||||
});
|
||||
|
||||
/// Deserialize a [Plan] from [json].
|
||||
static Plan fromJson(Map<String, dynamic> json) => _$PlanFromJson(json);
|
||||
|
||||
/// Serialize the [Plan] to [Json].
|
||||
Json toJson() => _$PlanToJson(this);
|
||||
|
||||
/// The display name of the plan
|
||||
final String name;
|
||||
|
||||
/// The ISO 4217 currency code for the plan.
|
||||
final String currency;
|
||||
|
||||
/// The price paid per billing period, irrespective of the number of patch
|
||||
/// installs used. This number is in minor units of [currency]
|
||||
/// (e.g., cents for USD).
|
||||
final int basePrice;
|
||||
|
||||
/// The number of patch installs included with the base price.
|
||||
final int baseInstallCount;
|
||||
|
||||
/// The price per patch install over [baseInstallCount]. This is in minor
|
||||
/// units of [currency] (e.g., cents for USD) and may be a fractional value.
|
||||
/// Will be null if the user's plan does not support overage billing.
|
||||
final Decimal? pricePerOverageInstall;
|
||||
|
||||
/// The start of the current billing period.
|
||||
/// If the user is on a free plan, this will be the start of the current
|
||||
/// month.
|
||||
final DateTime currentPeriodStart;
|
||||
|
||||
/// The end of the current billing period.
|
||||
/// If the user is on a free plan, this will be the start of the next month.
|
||||
final DateTime currentPeriodEnd;
|
||||
|
||||
/// Whether the subscription will be canceled at the end of the current
|
||||
/// billing period.
|
||||
final bool cancelAtPeriodEnd;
|
||||
|
||||
/// Whether the plan is tier (i.e., whether the user can change their plan).
|
||||
final bool isTiered;
|
||||
|
||||
/// Whether the user is on a trial plan. Trial plans are not billed and cancel
|
||||
/// automatically at the end of the trial period.
|
||||
final bool isTrial;
|
||||
|
||||
/// Whether or not MAU insights are supported for the plan.
|
||||
final bool mauInsightEnabled;
|
||||
|
||||
/// 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, mapped to the
|
||||
/// permissions they have.
|
||||
final Map<Role, List<String>> availableRoles;
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars
|
||||
|
||||
part of 'plan.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Plan _$PlanFromJson(Map<String, dynamic> json) => $checkedCreate(
|
||||
'Plan',
|
||||
json,
|
||||
($checkedConvert) {
|
||||
final val = Plan(
|
||||
name: $checkedConvert('name', (v) => v as String),
|
||||
currency: $checkedConvert('currency', (v) => v as String),
|
||||
basePrice: $checkedConvert('base_price', (v) => (v as num).toInt()),
|
||||
baseInstallCount: $checkedConvert(
|
||||
'base_install_count',
|
||||
(v) => (v as num).toInt(),
|
||||
),
|
||||
currentPeriodStart: $checkedConvert(
|
||||
'current_period_start',
|
||||
(v) => DateTime.parse(v as String),
|
||||
),
|
||||
currentPeriodEnd: $checkedConvert(
|
||||
'current_period_end',
|
||||
(v) => DateTime.parse(v as String),
|
||||
),
|
||||
cancelAtPeriodEnd: $checkedConvert(
|
||||
'cancel_at_period_end',
|
||||
(v) => v as bool,
|
||||
),
|
||||
isTiered: $checkedConvert('is_tiered', (v) => v as bool),
|
||||
isTrial: $checkedConvert('is_trial', (v) => v as bool),
|
||||
availableRoles: $checkedConvert(
|
||||
'available_roles',
|
||||
(v) => (v as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(
|
||||
$enumDecode(_$RoleEnumMap, k),
|
||||
(e as List<dynamic>).map((e) => e as String).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
mauInsightEnabled: $checkedConvert(
|
||||
'mau_insight_enabled',
|
||||
(v) => v as bool,
|
||||
),
|
||||
pricePerOverageInstall: $checkedConvert(
|
||||
'price_per_overage_install',
|
||||
(v) => v == null ? null : Decimal.fromJson(v as String),
|
||||
),
|
||||
maxTeamSize: $checkedConvert(
|
||||
'max_team_size',
|
||||
(v) => (v as num?)?.toInt(),
|
||||
),
|
||||
);
|
||||
return val;
|
||||
},
|
||||
fieldKeyMap: const {
|
||||
'basePrice': 'base_price',
|
||||
'baseInstallCount': 'base_install_count',
|
||||
'currentPeriodStart': 'current_period_start',
|
||||
'currentPeriodEnd': 'current_period_end',
|
||||
'cancelAtPeriodEnd': 'cancel_at_period_end',
|
||||
'isTiered': 'is_tiered',
|
||||
'isTrial': 'is_trial',
|
||||
'availableRoles': 'available_roles',
|
||||
'mauInsightEnabled': 'mau_insight_enabled',
|
||||
'pricePerOverageInstall': 'price_per_overage_install',
|
||||
'maxTeamSize': 'max_team_size',
|
||||
},
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$PlanToJson(Plan instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'currency': instance.currency,
|
||||
'base_price': instance.basePrice,
|
||||
'base_install_count': instance.baseInstallCount,
|
||||
'price_per_overage_install': instance.pricePerOverageInstall?.toJson(),
|
||||
'current_period_start': instance.currentPeriodStart.toIso8601String(),
|
||||
'current_period_end': instance.currentPeriodEnd.toIso8601String(),
|
||||
'cancel_at_period_end': instance.cancelAtPeriodEnd,
|
||||
'is_tiered': instance.isTiered,
|
||||
'is_trial': instance.isTrial,
|
||||
'mau_insight_enabled': instance.mauInsightEnabled,
|
||||
'max_team_size': instance.maxTeamSize,
|
||||
'available_roles': instance.availableRoles.map(
|
||||
(k, e) => MapEntry(_$RoleEnumMap[k]!, e),
|
||||
),
|
||||
};
|
||||
|
||||
const _$RoleEnumMap = {
|
||||
Role.owner: 'owner',
|
||||
Role.admin: 'admin',
|
||||
Role.appManager: 'appManager',
|
||||
Role.developer: 'developer',
|
||||
Role.viewer: 'viewer',
|
||||
Role.none: 'none',
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
import 'package:decimal/decimal.dart';
|
||||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group(Plan, () {
|
||||
test('can be (de)serialized', () {
|
||||
final plan = Plan(
|
||||
name: 'name',
|
||||
currency: 'currency',
|
||||
basePrice: 42,
|
||||
baseInstallCount: 42,
|
||||
currentPeriodStart: DateTime.now(),
|
||||
currentPeriodEnd: DateTime.now(),
|
||||
cancelAtPeriodEnd: true,
|
||||
isTiered: true,
|
||||
maxTeamSize: 42,
|
||||
pricePerOverageInstall: Decimal.fromInt(10),
|
||||
isTrial: true,
|
||||
mauInsightEnabled: true,
|
||||
availableRoles: {
|
||||
Role.admin: [
|
||||
'apps.view',
|
||||
'releases.view',
|
||||
'patches.view',
|
||||
'channels.view',
|
||||
'organizations.view',
|
||||
'organizationApps.view',
|
||||
'organizationMembers.view',
|
||||
'appRoleGrants.view',
|
||||
'insights.view',
|
||||
'plans.view',
|
||||
],
|
||||
Role.developer: [
|
||||
'apps.view',
|
||||
'releases.view',
|
||||
'patches.view',
|
||||
'channels.view',
|
||||
'organizations.view',
|
||||
'organizationApps.view',
|
||||
'organizationMembers.view',
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
expect(Plan.fromJson(plan.toJson()).toJson(), equals(plan.toJson()));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user