diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.g.dart index 6d03cb5d..bb7a1b4a 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.g.dart @@ -14,7 +14,7 @@ CreatePatchRequest _$CreatePatchRequestFromJson(Map json) => json, ($checkedConvert) { final val = CreatePatchRequest( - releaseId: $checkedConvert('release_id', (v) => v as int), + releaseId: $checkedConvert('release_id', (v) => (v as num).toInt()), metadata: $checkedConvert('metadata', (v) => v as Map), ); diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_response.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_response.g.dart index da073d5a..7a1be727 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_response.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_response.g.dart @@ -14,8 +14,8 @@ CreatePatchResponse _$CreatePatchResponseFromJson(Map json) => json, ($checkedConvert) { final val = CreatePatchResponse( - id: $checkedConvert('id', (v) => v as int), - number: $checkedConvert('number', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), + number: $checkedConvert('number', (v) => (v as num).toInt()), ); return val; }, diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch_artifact/create_patch_artifact_response.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch_artifact/create_patch_artifact_response.g.dart index 58d79ec1..5a3aca31 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch_artifact/create_patch_artifact_response.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch_artifact/create_patch_artifact_response.g.dart @@ -15,13 +15,13 @@ CreatePatchArtifactResponse _$CreatePatchArtifactResponseFromJson( json, ($checkedConvert) { final val = CreatePatchArtifactResponse( - id: $checkedConvert('id', (v) => v as int), - patchId: $checkedConvert('patch_id', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), + patchId: $checkedConvert('patch_id', (v) => (v as num).toInt()), arch: $checkedConvert('arch', (v) => v as String), platform: $checkedConvert( 'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)), hash: $checkedConvert('hash', (v) => v as String), - size: $checkedConvert('size', (v) => v as int), + size: $checkedConvert('size', (v) => (v as num).toInt()), url: $checkedConvert('url', (v) => v as String), ); return val; diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_release_artifact/create_release_artifact_response.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_release_artifact/create_release_artifact_response.g.dart index be9c1b1f..ae1757fd 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/create_release_artifact/create_release_artifact_response.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_release_artifact/create_release_artifact_response.g.dart @@ -15,13 +15,13 @@ CreateReleaseArtifactResponse _$CreateReleaseArtifactResponseFromJson( json, ($checkedConvert) { final val = CreateReleaseArtifactResponse( - id: $checkedConvert('id', (v) => v as int), - releaseId: $checkedConvert('release_id', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), + releaseId: $checkedConvert('release_id', (v) => (v as num).toInt()), arch: $checkedConvert('arch', (v) => v as String), platform: $checkedConvert( 'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)), hash: $checkedConvert('hash', (v) => v as String), - size: $checkedConvert('size', (v) => v as int), + size: $checkedConvert('size', (v) => (v as num).toInt()), url: $checkedConvert('url', (v) => v as String), ); return val; diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/promote_patch/promote_patch_request.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/promote_patch/promote_patch_request.g.dart index a2203ab1..26468805 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/promote_patch/promote_patch_request.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/promote_patch/promote_patch_request.g.dart @@ -14,8 +14,8 @@ PromotePatchRequest _$PromotePatchRequestFromJson(Map json) => json, ($checkedConvert) { final val = PromotePatchRequest( - patchId: $checkedConvert('patch_id', (v) => v as int), - channelId: $checkedConvert('channel_id', (v) => v as int), + patchId: $checkedConvert('patch_id', (v) => (v as num).toInt()), + channelId: $checkedConvert('channel_id', (v) => (v as num).toInt()), ); return val; }, diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator.dart b/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator.dart new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator.dart @@ -0,0 +1 @@ + diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator_request.dart b/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator_request.dart new file mode 100644 index 00000000..abafa7ea --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator_request.dart @@ -0,0 +1,26 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; + +part 'update_app_collaborator_request.g.dart'; + +/// {@template update_app_collaborator_request} +/// The request body for +/// PATCH /api/v1/apps//collaborators/ +/// {@endtemplate} +@JsonSerializable() +class UpdateAppCollaboratorRequest { + /// {@macro update_app_collaborator_request} + const UpdateAppCollaboratorRequest({ + required this.role, + }); + + /// Converts a Map to a [UpdateAppCollaboratorRequest]. + factory UpdateAppCollaboratorRequest.fromJson(Map json) => + _$UpdateAppCollaboratorRequestFromJson(json); + + /// Converts a [UpdateAppCollaboratorRequest] to a Map. + Map toJson() => _$UpdateAppCollaboratorRequestToJson(this); + + /// The new role for the collaborator. + final AppCollaboratorRole role; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator_request.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator_request.g.dart new file mode 100644 index 00000000..b2965e94 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/update_app_collaborator/update_app_collaborator_request.g.dart @@ -0,0 +1,34 @@ +// 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 'update_app_collaborator_request.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UpdateAppCollaboratorRequest _$UpdateAppCollaboratorRequestFromJson( + Map json) => + $checkedCreate( + 'UpdateAppCollaboratorRequest', + json, + ($checkedConvert) { + final val = UpdateAppCollaboratorRequest( + role: $checkedConvert( + 'role', (v) => $enumDecode(_$AppCollaboratorRoleEnumMap, v)), + ); + return val; + }, + ); + +Map _$UpdateAppCollaboratorRequestToJson( + UpdateAppCollaboratorRequest instance) => + { + 'role': _$AppCollaboratorRoleEnumMap[instance.role]!, + }; + +const _$AppCollaboratorRoleEnumMap = { + AppCollaboratorRole.admin: 'admin', + AppCollaboratorRole.developer: 'developer', +}; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/app_collaborator_role.dart b/packages/shorebird_code_push_protocol/lib/src/models/app_collaborator_role.dart new file mode 100644 index 00000000..55fb1dd8 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/app_collaborator_role.dart @@ -0,0 +1,19 @@ +/// {@template app_collaborator_role} +/// The role a user has for a specific app. Roles are associated with different +/// permission levels. +/// {@endtemplate} +enum AppCollaboratorRole { + /// A user with this role can perform all available actions on apps, releases, + /// patches, channels, and collaborators. + admin('admin'), + + /// A user with this role can manage releases and patches, but cannot manage + /// collaborators or the application itself. + developer('developer'); + + /// {@macro app_collaborator_role} + const AppCollaboratorRole(this.name); + + /// The name of the role. + final String name; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/app_metadata.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/app_metadata.g.dart index 9a4240c8..2d4c248a 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/app_metadata.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/app_metadata.g.dart @@ -21,8 +21,8 @@ AppMetadata _$AppMetadataFromJson(Map json) => $checkedCreate( $checkedConvert('updated_at', (v) => DateTime.parse(v as String)), latestReleaseVersion: $checkedConvert('latest_release_version', (v) => v as String?), - latestPatchNumber: - $checkedConvert('latest_patch_number', (v) => v as int?), + latestPatchNumber: $checkedConvert( + 'latest_patch_number', (v) => (v as num?)?.toInt()), ); return val; }, diff --git a/packages/shorebird_code_push_protocol/lib/src/models/channel.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/channel.g.dart index 2ddcafe4..3f53b490 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/channel.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/channel.g.dart @@ -13,7 +13,7 @@ Channel _$ChannelFromJson(Map json) => $checkedCreate( json, ($checkedConvert) { final val = Channel( - id: $checkedConvert('id', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), appId: $checkedConvert('app_id', (v) => v as String), name: $checkedConvert('name', (v) => v as String), ); 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 9d97941c..d12774da 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/models.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/models.dart @@ -1,4 +1,5 @@ export 'app.dart'; +export 'app_collaborator_role.dart'; export 'app_metadata.dart'; export 'auth_provider.dart'; export 'channel.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/patch.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/patch.g.dart index 3f04be68..77dae73e 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/patch.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/patch.g.dart @@ -13,8 +13,8 @@ Patch _$PatchFromJson(Map json) => $checkedCreate( json, ($checkedConvert) { final val = Patch( - id: $checkedConvert('id', (v) => v as int), - number: $checkedConvert('number', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), + number: $checkedConvert('number', (v) => (v as num).toInt()), ); return val; }, diff --git a/packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.g.dart index 234532e9..18fc88e1 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.g.dart @@ -14,13 +14,13 @@ PatchArtifact _$PatchArtifactFromJson(Map json) => json, ($checkedConvert) { final val = PatchArtifact( - id: $checkedConvert('id', (v) => v as int), - patchId: $checkedConvert('patch_id', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), + patchId: $checkedConvert('patch_id', (v) => (v as num).toInt()), arch: $checkedConvert('arch', (v) => v as String), platform: $checkedConvert( 'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)), hash: $checkedConvert('hash', (v) => v as String), - size: $checkedConvert('size', (v) => v as int), + size: $checkedConvert('size', (v) => (v as num).toInt()), createdAt: $checkedConvert('created_at', (v) => DateTime.parse(v as String)), ); diff --git a/packages/shorebird_code_push_protocol/lib/src/models/release.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/release.g.dart index 79496d44..9e2d85a7 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/release.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/release.g.dart @@ -13,7 +13,7 @@ Release _$ReleaseFromJson(Map json) => $checkedCreate( json, ($checkedConvert) { final val = Release( - id: $checkedConvert('id', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), appId: $checkedConvert('app_id', (v) => v as String), version: $checkedConvert('version', (v) => v as String), flutterRevision: diff --git a/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.g.dart index c3deb5d0..f2b34e0d 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.g.dart @@ -14,13 +14,13 @@ ReleaseArtifact _$ReleaseArtifactFromJson(Map json) => json, ($checkedConvert) { final val = ReleaseArtifact( - id: $checkedConvert('id', (v) => v as int), - releaseId: $checkedConvert('release_id', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), + releaseId: $checkedConvert('release_id', (v) => (v as num).toInt()), arch: $checkedConvert('arch', (v) => v as String), platform: $checkedConvert( 'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)), hash: $checkedConvert('hash', (v) => v as String), - size: $checkedConvert('size', (v) => v as int), + size: $checkedConvert('size', (v) => (v as num).toInt()), url: $checkedConvert('url', (v) => v as String), podfileLockHash: $checkedConvert('podfile_lock_hash', (v) => v as String?), diff --git a/packages/shorebird_code_push_protocol/lib/src/models/release_patch.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/release_patch.g.dart index 0dfb624a..a8cc47be 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/release_patch.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/release_patch.g.dart @@ -14,8 +14,8 @@ ReleasePatch _$ReleasePatchFromJson(Map json) => json, ($checkedConvert) { final val = ReleasePatch( - id: $checkedConvert('id', (v) => v as int), - number: $checkedConvert('number', (v) => v as int), + id: $checkedConvert('id', (v) => (v as num).toInt()), + number: $checkedConvert('number', (v) => (v as num).toInt()), channel: $checkedConvert('channel', (v) => v as String?), artifacts: $checkedConvert( 'artifacts', diff --git a/packages/shorebird_code_push_protocol/test/src/messages/update_app_collaborator/update_app_collaborator_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/update_app_collaborator/update_app_collaborator_request_test.dart new file mode 100644 index 00000000..0e0be474 --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/messages/update_app_collaborator/update_app_collaborator_request_test.dart @@ -0,0 +1,16 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:shorebird_code_push_protocol/src/messages/update_app_collaborator/update_app_collaborator_request.dart'; +import 'package:test/test.dart'; + +void main() { + group(UpdateAppCollaboratorRequest, () { + test('can be (de)serialized', () { + const request = + UpdateAppCollaboratorRequest(role: AppCollaboratorRole.admin); + expect( + UpdateAppCollaboratorRequest.fromJson(request.toJson()).toJson(), + equals(request.toJson()), + ); + }); + }); +}