feat(shorebird_code_push_protocol): add currentPeriodCost to GetUsageResponse (#778)
Co-authored-by: Felix Angelov <felix@shorebird.dev>
This commit is contained in:
@@ -42,6 +42,8 @@ class AccountUsageCommand extends ShorebirdCommand
|
||||
|
||||
extension on GetUsageResponse {
|
||||
String prettyPrint() {
|
||||
final currencyFormatter = NumberFormat('#,##0.00', 'en_US');
|
||||
|
||||
const cellStyle = CellStyle(
|
||||
paddingLeft: 1,
|
||||
paddingRight: 1,
|
||||
@@ -60,6 +62,9 @@ extension on GetUsageResponse {
|
||||
: '${patchInstallLimit! - totalPatchInstalls}';
|
||||
|
||||
return '''
|
||||
|
||||
You are on the ${lightCyan.wrap(plan.name)} plan.
|
||||
|
||||
${Table(
|
||||
cellStyle: cellStyle,
|
||||
header: const TableSection(
|
||||
@@ -94,6 +99,7 @@ ${Table(
|
||||
${styleBold.wrap('${lightCyan.wrap(remainingPatchInstalls)} patch installs remaining in the current billing period.')}
|
||||
|
||||
Current Billing Period: ${lightCyan.wrap(DateFormat.yMMMd().format(currentPeriodStart))} - ${lightCyan.wrap(DateFormat.yMMMd().format(currentPeriodEnd))}
|
||||
Month-to-date cost: ${lightCyan.wrap('\$${currencyFormatter.format(currentPeriodCost * 100.0)}')}
|
||||
|
||||
${styleBold.wrap('*Usage data is not reported in real-time and may be delayed by up to 48 hours.')}''';
|
||||
}
|
||||
|
||||
@@ -1693,6 +1693,7 @@ Please bump your version number and try again.''',
|
||||
),
|
||||
],
|
||||
patchInstallLimit: 20000,
|
||||
currentPeriodCost: 0,
|
||||
currentPeriodStart: DateTime(2023),
|
||||
currentPeriodEnd: DateTime(2023, 2),
|
||||
);
|
||||
|
||||
@@ -87,6 +87,7 @@ void main() {
|
||||
),
|
||||
],
|
||||
patchInstallLimit: 20000,
|
||||
currentPeriodCost: 0,
|
||||
currentPeriodStart: DateTime(2023),
|
||||
currentPeriodEnd: DateTime(2023, 2),
|
||||
);
|
||||
@@ -102,6 +103,9 @@ void main() {
|
||||
() => logger.info(
|
||||
any(
|
||||
that: contains('''
|
||||
|
||||
You are on the ${lightCyan.wrap('Hobby')} plan.
|
||||
|
||||
┌────────────┬────────────────┐
|
||||
│ App │ Patch Installs │
|
||||
├────────────┼────────────────┤
|
||||
@@ -115,6 +119,7 @@ void main() {
|
||||
${styleBold.wrap('${lightCyan.wrap('${20000 - 84}')} patch installs remaining in the current billing period.')}
|
||||
|
||||
Current Billing Period: ${lightCyan.wrap(DateFormat.yMMMd().format(usage.currentPeriodStart))} - ${lightCyan.wrap(DateFormat.yMMMd().format(usage.currentPeriodEnd))}
|
||||
Month-to-date cost: ${lightCyan.wrap(r'$0.00')}
|
||||
|
||||
${styleBold.wrap('*Usage data is not reported in real-time and may be delayed by up to 48 hours.')}'''),
|
||||
),
|
||||
@@ -142,6 +147,7 @@ ${styleBold.wrap('*Usage data is not reported in real-time and may be delayed by
|
||||
patchInstallCount: 42,
|
||||
),
|
||||
],
|
||||
currentPeriodCost: 0,
|
||||
currentPeriodStart: DateTime(2023),
|
||||
currentPeriodEnd: DateTime(2023, 2),
|
||||
);
|
||||
@@ -157,6 +163,9 @@ ${styleBold.wrap('*Usage data is not reported in real-time and may be delayed by
|
||||
() => logger.info(
|
||||
any(
|
||||
that: contains('''
|
||||
|
||||
You are on the ${lightCyan.wrap('Hobby')} plan.
|
||||
|
||||
┌────────────┬────────────────┐
|
||||
│ App │ Patch Installs │
|
||||
├────────────┼────────────────┤
|
||||
@@ -170,6 +179,7 @@ ${styleBold.wrap('*Usage data is not reported in real-time and may be delayed by
|
||||
${styleBold.wrap('${lightCyan.wrap('∞')} patch installs remaining in the current billing period.')}
|
||||
|
||||
Current Billing Period: ${lightCyan.wrap(DateFormat.yMMMd().format(usage.currentPeriodStart))} - ${lightCyan.wrap(DateFormat.yMMMd().format(usage.currentPeriodEnd))}
|
||||
Month-to-date cost: ${lightCyan.wrap(r'$0.00')}
|
||||
|
||||
${styleBold.wrap('*Usage data is not reported in real-time and may be delayed by up to 48 hours.')}'''),
|
||||
),
|
||||
|
||||
@@ -1944,6 +1944,7 @@ void main() {
|
||||
)
|
||||
],
|
||||
patchInstallLimit: 1337,
|
||||
currentPeriodCost: 0,
|
||||
currentPeriodStart: DateTime(2023),
|
||||
currentPeriodEnd: DateTime(2023, 2),
|
||||
);
|
||||
|
||||
+5
@@ -14,6 +14,7 @@ class GetUsageResponse {
|
||||
required this.apps,
|
||||
required this.currentPeriodStart,
|
||||
required this.currentPeriodEnd,
|
||||
required this.currentPeriodCost,
|
||||
this.patchInstallLimit,
|
||||
});
|
||||
|
||||
@@ -36,6 +37,10 @@ class GetUsageResponse {
|
||||
/// The end of the current billing period.
|
||||
final DateTime currentPeriodEnd;
|
||||
|
||||
/// The total cost so far for the current billing period. Includes base
|
||||
/// monthly cost and any overages.
|
||||
final int currentPeriodCost;
|
||||
|
||||
/// The upper limit of patch installs for the current billing period.
|
||||
/// If `null`, there is no limit.
|
||||
final int? patchInstallLimit;
|
||||
|
||||
+4
@@ -25,6 +25,8 @@ GetUsageResponse _$GetUsageResponseFromJson(Map<String, dynamic> json) =>
|
||||
'current_period_start', (v) => DateTime.parse(v as String)),
|
||||
currentPeriodEnd: $checkedConvert(
|
||||
'current_period_end', (v) => DateTime.parse(v as String)),
|
||||
currentPeriodCost:
|
||||
$checkedConvert('current_period_cost', (v) => v as int),
|
||||
patchInstallLimit:
|
||||
$checkedConvert('patch_install_limit', (v) => v as int?),
|
||||
);
|
||||
@@ -33,6 +35,7 @@ GetUsageResponse _$GetUsageResponseFromJson(Map<String, dynamic> json) =>
|
||||
fieldKeyMap: const {
|
||||
'currentPeriodStart': 'current_period_start',
|
||||
'currentPeriodEnd': 'current_period_end',
|
||||
'currentPeriodCost': 'current_period_cost',
|
||||
'patchInstallLimit': 'patch_install_limit'
|
||||
},
|
||||
);
|
||||
@@ -43,6 +46,7 @@ Map<String, dynamic> _$GetUsageResponseToJson(GetUsageResponse instance) =>
|
||||
'apps': instance.apps.map((e) => e.toJson()).toList(),
|
||||
'current_period_start': instance.currentPeriodStart.toIso8601String(),
|
||||
'current_period_end': instance.currentPeriodEnd.toIso8601String(),
|
||||
'current_period_cost': instance.currentPeriodCost,
|
||||
'patch_install_limit': instance.patchInstallLimit,
|
||||
};
|
||||
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ void main() {
|
||||
const AppUsage(id: 'app-id', name: 'My app', patchInstallCount: 1337),
|
||||
],
|
||||
patchInstallLimit: 42,
|
||||
currentPeriodCost: 0,
|
||||
currentPeriodStart: DateTime(2021),
|
||||
currentPeriodEnd: DateTime(2021, 1, 2),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user