diff --git a/packages/shorebird_code_push_protocol/lib/shorebird_code_push_protocol.dart b/packages/shorebird_code_push_protocol/lib/shorebird_code_push_protocol.dart index ef127e20..25b78206 100644 --- a/packages/shorebird_code_push_protocol/lib/shorebird_code_push_protocol.dart +++ b/packages/shorebird_code_push_protocol/lib/shorebird_code_push_protocol.dart @@ -1,8 +1,6 @@ /// The Shorebird CodePush Protocol library shorebird_code_push_protocol; -export 'package:money2/money2.dart' show Currency, Money; -export 'src/converters/converters.dart'; export 'src/messages/messages.dart'; export 'src/models/models.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/converters/converters.dart b/packages/shorebird_code_push_protocol/lib/src/converters/converters.dart deleted file mode 100644 index b7bdc0ad..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/converters/converters.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'money_converter.dart'; -export 'timestamp_converter.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/converters/money_converter.dart b/packages/shorebird_code_push_protocol/lib/src/converters/money_converter.dart deleted file mode 100644 index c0d404a4..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/converters/money_converter.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; -import 'package:money2/money2.dart'; - -/// The US dollar. -Currency get usd => Currency.create('USD', 2); - -/// {@template money_converter} -/// Converts between [Money] and [int]. -/// {@endtemplate} -// TODO(bryanoltman): change this to use String as the transport type the next -// time we make a breaking change to the API. -class MoneyConverter implements JsonConverter { - /// {@macro money_converter} - const MoneyConverter(); - - @override - Money fromJson(int cents) => Money.fromIntWithCurrency(cents, usd); - - @override - int toJson(Money money) => money.minorUnits.toInt(); -} diff --git a/packages/shorebird_code_push_protocol/lib/src/converters/timestamp_converter.dart b/packages/shorebird_code_push_protocol/lib/src/converters/timestamp_converter.dart deleted file mode 100644 index f6eb4d7f..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/converters/timestamp_converter.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -/// {@template timestamp_converter} -/// Converts between Unix timestamps and [DateTime]. -/// {@endtemplate} -class TimestampConverter implements JsonConverter { - /// {@macro timestamp_converter} - const TimestampConverter(); - - @override - DateTime fromJson(int timestamp) => - DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); - - @override - int toJson(DateTime dateTime) => dateTime.millisecondsSinceEpoch ~/ 1000; -} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/models.dart b/packages/shorebird_code_push_protocol/lib/src/models/models.dart index 2fdf4fed..e3d47ef2 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/models.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/models.dart @@ -9,6 +9,4 @@ export 'release.dart'; export 'release_artifact.dart'; export 'release_platform.dart'; export 'release_status.dart'; -export 'shorebird_plan.dart'; -export 'subscription.dart'; export 'user.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.dart b/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.dart deleted file mode 100644 index 2dc1887a..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; - -part 'shorebird_plan.g.dart'; - -/// {@template shorebird_plan} -/// A Shorebird plan. -/// {@endtemplate} -@JsonSerializable() -class ShorebirdPlan { - /// {@macro shorebird_plan} - const ShorebirdPlan({ - required this.name, - required this.monthlyCost, - required this.currency, - required this.patchInstallLimit, - this.maxTeamSize, - }); - - /// Creates a [ShorebirdPlan] from a JSON object. - factory ShorebirdPlan.fromJson(Json json) => _$ShorebirdPlanFromJson(json); - - /// Converts a [ShorebirdPlan] to a JSON object. - Json toJson() => _$ShorebirdPlanToJson(this); - - /// The name of the plan. - final String name; - - /// Monthly billing rate. - @MoneyConverter() - final Money monthlyCost; - - /// The currency of the plan (e.g. USD, CAD, etc.) - final String currency; - - /// The number of patch installs allowed per billing period. This will be null - /// for accounts with unlimited patch installs. - final int? patchInstallLimit; - - /// The maximum number of collaborators allowed per account. This will be null - /// for accounts with unlimited collaborators. - final int? maxTeamSize; -} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.g.dart deleted file mode 100644 index 8d6537b9..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.g.dart +++ /dev/null @@ -1,41 +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 'shorebird_plan.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -ShorebirdPlan _$ShorebirdPlanFromJson(Map json) => - $checkedCreate( - 'ShorebirdPlan', - json, - ($checkedConvert) { - final val = ShorebirdPlan( - name: $checkedConvert('name', (v) => v as String), - monthlyCost: $checkedConvert( - 'monthly_cost', (v) => const MoneyConverter().fromJson(v as int)), - currency: $checkedConvert('currency', (v) => v as String), - patchInstallLimit: - $checkedConvert('patch_install_limit', (v) => v as int?), - maxTeamSize: $checkedConvert('max_team_size', (v) => v as int?), - ); - return val; - }, - fieldKeyMap: const { - 'monthlyCost': 'monthly_cost', - 'patchInstallLimit': 'patch_install_limit', - 'maxTeamSize': 'max_team_size' - }, - ); - -Map _$ShorebirdPlanToJson(ShorebirdPlan instance) => - { - 'name': instance.name, - 'monthly_cost': const MoneyConverter().toJson(instance.monthlyCost), - 'currency': instance.currency, - 'patch_install_limit': instance.patchInstallLimit, - 'max_team_size': instance.maxTeamSize, - }; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/subscription.dart b/packages/shorebird_code_push_protocol/lib/src/models/subscription.dart deleted file mode 100644 index 17355879..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/subscription.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; - -part 'subscription.g.dart'; - -/// {@template subscription} -/// A user's Shorebird subscription. -/// {@endtemplate} -@JsonSerializable() -class Subscription { - /// {@macro subscription} - Subscription({ - required this.plan, - required this.paidThroughDate, - required this.willRenew, - }); - - /// Creates a [Subscription] from a JSON object. - factory Subscription.fromJson(Json json) => _$SubscriptionFromJson(json); - - /// Converts a [Subscription] to a JSON object. - Json toJson() => _$SubscriptionToJson(this); - - /// The plan associated with this subscription. - final ShorebirdPlan plan; - - /// When the subscription will be renewed or expire. - @TimestampConverter() - final DateTime paidThroughDate; - - /// Whether this subscription will renew on [paidThroughDate]. - final bool willRenew; - - /// Whether this subscription is currently active. - bool get isActive => paidThroughDate.isAfter(DateTime.now()); -} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/subscription.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/subscription.g.dart deleted file mode 100644 index 3f90adb5..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/subscription.g.dart +++ /dev/null @@ -1,37 +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 'subscription.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Subscription _$SubscriptionFromJson(Map json) => - $checkedCreate( - 'Subscription', - json, - ($checkedConvert) { - final val = Subscription( - plan: $checkedConvert( - 'plan', (v) => ShorebirdPlan.fromJson(v as Map)), - paidThroughDate: $checkedConvert('paid_through_date', - (v) => const TimestampConverter().fromJson(v as int)), - willRenew: $checkedConvert('will_renew', (v) => v as bool), - ); - return val; - }, - fieldKeyMap: const { - 'paidThroughDate': 'paid_through_date', - 'willRenew': 'will_renew' - }, - ); - -Map _$SubscriptionToJson(Subscription instance) => - { - 'plan': instance.plan.toJson(), - 'paid_through_date': - const TimestampConverter().toJson(instance.paidThroughDate), - 'will_renew': instance.willRenew, - }; diff --git a/packages/shorebird_code_push_protocol/pubspec.yaml b/packages/shorebird_code_push_protocol/pubspec.yaml index dda08c42..42184594 100644 --- a/packages/shorebird_code_push_protocol/pubspec.yaml +++ b/packages/shorebird_code_push_protocol/pubspec.yaml @@ -9,13 +9,11 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - json_annotation: ^4.8.1 - money2: ^3.4.1 + json_annotation: ^4.8.1 dev_dependencies: build_runner: ^2.0.0 json_serializable: ^6.6.1 mocktail: ^1.0.0 - path: ^1.8.3 test: ^1.19.2 very_good_analysis: ^5.1.0 diff --git a/packages/shorebird_code_push_protocol/test/src/models/shorebird_plan_test.dart b/packages/shorebird_code_push_protocol/test/src/models/shorebird_plan_test.dart deleted file mode 100644 index 351d310f..00000000 --- a/packages/shorebird_code_push_protocol/test/src/models/shorebird_plan_test.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; -import 'package:test/test.dart'; - -void main() { - group(ShorebirdPlan, () { - test('can be (de)serialized', () { - final plan = ShorebirdPlan( - name: 'Hobby', - monthlyCost: Money.fromIntWithCurrency(0, usd), - currency: 'USD', - patchInstallLimit: 1000, - maxTeamSize: 1, - ); - expect( - ShorebirdPlan.fromJson(plan.toJson()).toJson(), - equals(plan.toJson()), - ); - }); - }); -} diff --git a/packages/shorebird_code_push_protocol/test/src/models/subscription_test.dart b/packages/shorebird_code_push_protocol/test/src/models/subscription_test.dart deleted file mode 100644 index 97b09a4d..00000000 --- a/packages/shorebird_code_push_protocol/test/src/models/subscription_test.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; -import 'package:test/test.dart'; - -void main() { - group(Subscription, () { - final plan = ShorebirdPlan( - name: 'Hobby', - monthlyCost: Money.fromIntWithCurrency(0, usd), - currency: 'USD', - patchInstallLimit: 1000, - maxTeamSize: 1, - ); - - test('can be (de)serialized', () { - final subscription = Subscription( - plan: plan, - paidThroughDate: DateTime.now(), - willRenew: true, - ); - expect( - Subscription.fromJson(subscription.toJson()).toJson(), - equals(subscription.toJson()), - ); - }); - - group('isActive', () { - test('returns true if paidThroughDate is in the future', () { - final subscription = Subscription( - plan: plan, - paidThroughDate: DateTime.now().add(const Duration(days: 1)), - willRenew: true, - ); - expect(subscription.isActive, isTrue); - }); - - test('returns false if paidThroughDate is in the past', () { - final subscription = Subscription( - plan: plan, - paidThroughDate: DateTime.now().subtract(const Duration(days: 1)), - willRenew: true, - ); - expect(subscription.isActive, isFalse); - }); - }); - }); -}