From 06b1288f8e501c38166ec1895d227d4f832e4144 Mon Sep 17 00:00:00 2001 From: DatDang Date: Mon, 23 Sep 2024 10:13:31 +0700 Subject: [PATCH] Add web socket ticket capability --- CHANGELOG.md | 5 ++- .../converter/capabilities_converter.dart | 2 ++ .../capability/capability_identifier.dart | 1 + .../web_socket_ticket_capability.dart | 21 ++++++++++++ .../web_socket_ticket_capability.g.dart | 33 +++++++++++++++++++ pubspec.yaml | 2 +- test/jmap/core/session/session_test.dart | 10 ++++++ 7 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 lib/jmap/core/capability/web_socket_ticket_capability.dart create mode 100644 lib/jmap/core/capability/web_socket_ticket_capability.g.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 97e5f67..d7d96fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -## [0.2.1] - 2024-09-16 +## [0.2.3] - 2024-09-16 +- Add web socket ticket capability + +## [0.2.2] - 2024-09-16 - Add X-JMAP-Identity header ## [0.2.1] - 2024-08-28 diff --git a/lib/http/converter/capabilities_converter.dart b/lib/http/converter/capabilities_converter.dart index 12c6305..5905fa4 100644 --- a/lib/http/converter/capabilities_converter.dart +++ b/lib/http/converter/capabilities_converter.dart @@ -9,6 +9,7 @@ import 'package:jmap_dart_client/jmap/core/capability/mail_capability.dart'; import 'package:jmap_dart_client/jmap/core/capability/mdn_capability.dart'; import 'package:jmap_dart_client/jmap/core/capability/submission_capability.dart'; import 'package:jmap_dart_client/jmap/core/capability/vacation_capability.dart'; +import 'package:jmap_dart_client/jmap/core/capability/web_socket_ticket_capability.dart'; import 'package:jmap_dart_client/jmap/core/capability/websocket_capability.dart'; class CapabilitiesConverter { @@ -26,6 +27,7 @@ class CapabilitiesConverter { CapabilityIdentifier.jamesCalendarEvent: CalendarEventCapability.deserialize, CapabilityIdentifier.jmapVacationResponse: VacationCapability.deserialize, CapabilityIdentifier.jmapWebSocket: WebSocketCapability.deserialize, + CapabilityIdentifier.jmapWebSocketTicket: WebSocketTicketCapability.deserialize, CapabilityIdentifier.jmapMdn: MdnCapability.deserialize }); } diff --git a/lib/jmap/core/capability/capability_identifier.dart b/lib/jmap/core/capability/capability_identifier.dart index 2113a4b..6288627 100644 --- a/lib/jmap/core/capability/capability_identifier.dart +++ b/lib/jmap/core/capability/capability_identifier.dart @@ -6,6 +6,7 @@ class CapabilityIdentifier with EquatableMixin { static final jmapSubmission = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:submission')); static final jmapVacationResponse = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:vacationresponse')); static final jmapWebSocket = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:websocket')); + static final jmapWebSocketTicket = CapabilityIdentifier(Uri.parse('com:linagora:params:jmap:ws:ticket')); static final jmapMdn = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:mdn')); static final jmapQuota = CapabilityIdentifier(Uri.parse('urn:ietf:params:jmap:quota')); static final jmapTeamMailboxes = CapabilityIdentifier(Uri.parse('urn:apache:james:params:jmap:mail:shares')); diff --git a/lib/jmap/core/capability/web_socket_ticket_capability.dart b/lib/jmap/core/capability/web_socket_ticket_capability.dart new file mode 100644 index 0000000..0b0c6f5 --- /dev/null +++ b/lib/jmap/core/capability/web_socket_ticket_capability.dart @@ -0,0 +1,21 @@ +import 'package:jmap_dart_client/jmap/core/capability/capability_properties.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'web_socket_ticket_capability.g.dart'; + +@JsonSerializable(explicitToJson: true, includeIfNull: false) +class WebSocketTicketCapability extends CapabilityProperties { + final Uri? generationEndpoint; + final Uri? revocationEndpoint; + + WebSocketTicketCapability({required this.generationEndpoint, required this.revocationEndpoint}); + + factory WebSocketTicketCapability.fromJson(Map json) => _$WebSocketTicketCapabilityFromJson(json); + + Map toJson() => _$WebSocketTicketCapabilityToJson(this); + + static WebSocketTicketCapability deserialize(Map json) => WebSocketTicketCapability.fromJson(json); + + @override + List get props => [generationEndpoint, revocationEndpoint]; +} \ No newline at end of file diff --git a/lib/jmap/core/capability/web_socket_ticket_capability.g.dart b/lib/jmap/core/capability/web_socket_ticket_capability.g.dart new file mode 100644 index 0000000..14603b7 --- /dev/null +++ b/lib/jmap/core/capability/web_socket_ticket_capability.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'web_socket_ticket_capability.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +WebSocketTicketCapability _$WebSocketTicketCapabilityFromJson( + Map json) => + WebSocketTicketCapability( + generationEndpoint: json['generationEndpoint'] == null + ? null + : Uri.parse(json['generationEndpoint'] as String), + revocationEndpoint: json['revocationEndpoint'] == null + ? null + : Uri.parse(json['revocationEndpoint'] as String), + ); + +Map _$WebSocketTicketCapabilityToJson( + WebSocketTicketCapability instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('generationEndpoint', instance.generationEndpoint?.toString()); + writeNotNull('revocationEndpoint', instance.revocationEndpoint?.toString()); + return val; +} diff --git a/pubspec.yaml b/pubspec.yaml index ddfce00..e712e23 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: jmap_dart_client description: A JMAP client library to make JMAP method calls and process the responses. -version: 0.2.2 +version: 0.2.3 homepage: https://github.com/linagora/jmap-dart-client.git environment: diff --git a/test/jmap/core/session/session_test.dart b/test/jmap/core/session/session_test.dart index cdda03a..0b352b5 100644 --- a/test/jmap/core/session/session_test.dart +++ b/test/jmap/core/session/session_test.dart @@ -12,6 +12,7 @@ import 'package:jmap_dart_client/jmap/core/capability/mail_capability.dart'; import 'package:jmap_dart_client/jmap/core/capability/mdn_capability.dart'; import 'package:jmap_dart_client/jmap/core/capability/submission_capability.dart'; import 'package:jmap_dart_client/jmap/core/capability/vacation_capability.dart'; +import 'package:jmap_dart_client/jmap/core/capability/web_socket_ticket_capability.dart'; import 'package:jmap_dart_client/jmap/core/capability/websocket_capability.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/session/session.dart'; @@ -68,6 +69,10 @@ void main() { "supportsPush": true, "url": "ws://domain.com/jmap/ws" }, + "com:linagora:params:jmap:ws:ticket": { + "generationEndpoint": "http://localhost/jmap/ws/ticket", + "revocationEndpoint": "http://localhost/jmap/ws/ticket" + }, "urn:apache:james:params:jmap:mail:quota": {}, "urn:apache:james:params:jmap:mail:shares": {}, "urn:ietf:params:jmap:vacationresponse": {}, @@ -125,6 +130,7 @@ void main() { "urn:ietf:params:jmap:submission": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", "com:linagora:params:calendar:event": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", "urn:ietf:params:jmap:websocket": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", + "com:linagora:params:jmap:ws:ticket": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", "urn:ietf:params:jmap:core": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", "urn:ietf:params:jmap:mail": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", "urn:apache:james:params:jmap:mail:quota": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", @@ -170,6 +176,9 @@ void main() { supportsPush: true, url: Uri.parse('ws://domain.com/jmap/ws') ), + CapabilityIdentifier.jmapWebSocketTicket: WebSocketTicketCapability( + generationEndpoint: Uri.parse('http://localhost/jmap/ws/ticket'), + revocationEndpoint: Uri.parse('http://localhost/jmap/ws/ticket')), CapabilityIdentifier(Uri.parse('urn:apache:james:params:jmap:mail:quota')): DefaultCapability({}), CapabilityIdentifier(Uri.parse('urn:apache:james:params:jmap:mail:shares')): DefaultCapability({}), CapabilityIdentifier.jmapVacationResponse: VacationCapability(), @@ -217,6 +226,7 @@ void main() { CapabilityIdentifier.jmapSubmission: AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')), CapabilityIdentifier.jamesCalendarEvent: AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')), CapabilityIdentifier.jmapWebSocket: AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')), + CapabilityIdentifier.jmapWebSocketTicket: AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')), CapabilityIdentifier.jmapCore: AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')), CapabilityIdentifier.jmapMail: AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')), CapabilityIdentifier(Uri.parse('urn:apache:james:params:jmap:mail:quota')): AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')),