diff --git a/.github/actions/setup-flutter/action.yaml b/.github/actions/setup-flutter/action.yaml new file mode 100644 index 0000000..cfe73b9 --- /dev/null +++ b/.github/actions/setup-flutter/action.yaml @@ -0,0 +1,27 @@ +name: "Init Flutter" +description: "Initializes Flutter repo" +runs: + using: "composite" + steps: + - name: ๐Ÿ“š Checkout repository + uses: actions/checkout@v4 + + - name: ๐Ÿฆ Setup Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: '3.22.2' + cache: true + + - name: ๐Ÿ“ฆ Get dependencies + shell: bash + run: flutter pub get + + - name: โ˜•๏ธ Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: '17' + distribution: 'temurin' + + - name: ๐Ÿ”Ž Check Flutter environment + shell: bash + run: flutter doctor -v \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8740151..fd3465d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,9 +3,12 @@ name: Publish to pub.dev on: push: tags: - - '[0-9]+.[0-9]+.[0-9]+*' - workflow_dispatch: + - "[0-9]+.[0-9]+.[0-9]+*" jobs: publish: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_pub_publish.yml@v1 + permissions: + id-token: write # Required for authentication using OIDC + uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 + # with: + # working-directory: path/to/package/within/repository diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml new file mode 100644 index 0000000..12d2c2d --- /dev/null +++ b/.github/workflows/validate.yaml @@ -0,0 +1,29 @@ +name: validate + +on: + workflow_dispatch: + pull_request: + branches: + - main + +jobs: + analyze: + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ“š Checkout repository + uses: actions/checkout@v4 + + - name: ๐Ÿ“ฆ Setup Flutter & Deps + uses: ./.github/actions/setup-flutter + + - name: ๐Ÿ“ Format + run: dart format . --set-exit-if-changed + + - name: ๐Ÿ“Š Analyze + run: flutter analyze + + - name: ๐Ÿงช Test + run: flutter test --coverage + + - name: ๐Ÿ”Ž Check Publish Warnings + run: flutter pub publish --dry-run \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8288b27..a9462a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,149 +1,156 @@ # Changelog +## 2.0.0 + +* feat: Simplify configuration of delay between retries by @jonasschaude in +* refactor!: use FutureOr to allow synchronous interceptors by @Leptopoda in +* docs: add ayyysh04 as a contributor for ideas by @allcontributors in + +**Beta Changelog**: + +**Full Changelog**: + ## 2.0.0-beta.7 -### What's Changed -* docs: add ntimesc as a contributor for ideas by @allcontributors in https://github.com/CodingAleCR/http_interceptor/pull/116 -* updated packages by @mauryagaurav947 in https://github.com/CodingAleCR/http_interceptor/pull/129 -### New Contributors -* @mauryagaurav947 made their first contribution in https://github.com/CodingAleCR/http_interceptor/pull/129 +* docs: add @ntimesc as a contributor for ideas by @allcontributors in +* updated packages by @mauryagaurav947 in -**Full Changelog**: https://github.com/CodingAleCR/http_interceptor/compare/2.0.0-beta.6...2.0.0-beta.7 +**Full Changelog**: ## 2.0.0-beta.6 -- โœจ  Added: `Future shouldInterceptRequest()` and `Future shouldInterceptResponse()`. This enables individual interceptor checks and conditional intercepting configurations. -- โœจ  Added: `bodyBytes` to `Request.copyWith`. This adds support to set and modify the body as a stream of bytes. -- โ—๏ธ๐Ÿ›   Changed: `RetryPolicy` to be `Future` instead of `bool` so that you can support different exception retrying scenarios (See #115). -- ๐Ÿ“–  Changed: **example** project to showcase updated Flutter 3.0, new library APIs and `MultipartRequest` handling. +* โœจ  Added: `Future shouldInterceptRequest()` and `Future shouldInterceptResponse()`. This enables individual interceptor checks and conditional intercepting configurations. +* โœจ  Added: `bodyBytes` to `Request.copyWith`. This adds support to set and modify the body as a stream of bytes. +* โ—๏ธ๐Ÿ›   Changed: `RetryPolicy` to be `Future` instead of `bool` so that you can support different exception retrying scenarios (See #115). +* ๐Ÿ“–  Changed: **example** project to showcase updated Flutter 3.0, new library APIs and `MultipartRequest` handling. ## 2.0.0-beta.5 -- โœจ  Added: Support for `onRequestTimeout` when setting up `requestTimeout` on the interceptor. +* โœจ  Added: Support for `onRequestTimeout` when setting up `requestTimeout` on the interceptor. ## 2.0.0-beta.4 -- โ—๏ธ๐Ÿ›   Changed: `shouldAttemptRetryOnException` will now also pass the `BaseRequest`. -- ๐Ÿšฆ  Tests: Updated tests. +* โ—๏ธ๐Ÿ›   Changed: `shouldAttemptRetryOnException` will now also pass the `BaseRequest`. +* ๐Ÿšฆ  Tests: Updated tests. ## 2.0.0-beta.3 -- ๐Ÿž  Fixed: `MultipartRequest` does not get intercepted correctly (has missing fields). -- ๐Ÿž  Fixed: `MultipartRequest` ignores retry policy. -- ๐Ÿž  Fixed: Changing `body` causes that the `headers` also change and ignore previous interceptions (i.e. content-type headers are overriden). -- ๐Ÿž  Fixed: `copyWith` was missing fields -- ๐Ÿšฆ  Tests: Updated tests. +* ๐Ÿž  Fixed: `MultipartRequest` does not get intercepted correctly (has missing fields). +* ๐Ÿž  Fixed: `MultipartRequest` ignores retry policy. +* ๐Ÿž  Fixed: Changing `body` causes that the `headers` also change and ignore previous interceptions (i.e. content-type headers are overriden). +* ๐Ÿž  Fixed: `copyWith` was missing fields +* ๐Ÿšฆ  Tests: Updated tests. ## 2.0.0-beta.2 -- ๐Ÿž  Fixed: Changing `body` causes that the `headers` also change and ignore previous interceptions (i.e. content-type headers are overriden). -- ๐Ÿšฆ  Tests: Updated tests. +* ๐Ÿž  Fixed: Changing `body` causes that the `headers` also change and ignore previous interceptions (i.e. content-type headers are overriden). +* ๐Ÿšฆ  Tests: Updated tests. ## 2.0.0-beta.1 -- โ—๏ธ๐Ÿ›   Changed: Renamed `Method` to use `HttpMethod` and refactored helper functions into extensions (`StringToMethod`, and `MethodToString`). -- โ—๏ธ๐Ÿ›   Changed: `InterceptorContract` to use `BaseRequest` and `BaseResponse` instead of custom models. -- โ—๏ธ๐Ÿ›   Removed: `RequestData` and `ResponseData` since the classes are no longer used. -- โœจ  Added: Support for intercepting `Request`,`StreamedRequest` and `MultipartRequest`. -- โœจ  Added: Support for intercepting `Response`,`StreamedResponse` and `MultipartRequest`. -- โœจ  Added: Extensions for `BaseRequest`, `Request`,`StreamedRequest` and `MultipartRequest` that allows copying requests through a `copyWith` method. -- โœจ  Added: Extensions for `BaseResponse`, `Response`,`StreamedResponse` and `IOStreamedResponse` that allows copying responses through a `copyWith` method. -- ๐Ÿ“–  Changed: **example** project to showcase updated APIs. -- ๐Ÿšฆ  Tests: Improved testing and documentation. +* โ—๏ธ๐Ÿ›   Changed: Renamed `Method` to use `HttpMethod` and refactored helper functions into extensions (`StringToMethod`, and `MethodToString`). +* โ—๏ธ๐Ÿ›   Changed: `InterceptorContract` to use `BaseRequest` and `BaseResponse` instead of custom models. +* โ—๏ธ๐Ÿ›   Removed: `RequestData` and `ResponseData` since the classes are no longer used. +* โœจ  Added: Support for intercepting `Request`,`StreamedRequest` and `MultipartRequest`. +* โœจ  Added: Support for intercepting `Response`,`StreamedResponse` and `MultipartRequest`. +* โœจ  Added: Extensions for `BaseRequest`, `Request`,`StreamedRequest` and `MultipartRequest` that allows copying requests through a `copyWith` method. +* โœจ  Added: Extensions for `BaseResponse`, `Response`,`StreamedResponse` and `IOStreamedResponse` that allows copying responses through a `copyWith` method. +* ๐Ÿ“–  Changed: **example** project to showcase updated APIs. +* ๐Ÿšฆ  Tests: Improved testing and documentation. ## 1.0.2 -- ๐Ÿ“–  Changed: example project to showcase `RetryPolicy` usage. -- ๐Ÿž  Fixed: `parameters` were missing in requests of type `POST`, `PUT`, `PATCH`, and `DELETE`. -- ๐Ÿž  Fixed: `int` or other non-string parameters are not being added to request. Thanks to @meysammahfouzi -- ๐Ÿž  Fixed: `body` is not sent in delete requests despite being accepted as parameter. Thanks to @MaciejZuk +* ๐Ÿ“–  Changed: example project to showcase `RetryPolicy` usage. +* ๐Ÿž  Fixed: `parameters` were missing in requests of type `POST`, `PUT`, `PATCH`, and `DELETE`. +* ๐Ÿž  Fixed: `int` or other non-string parameters are not being added to request. Thanks to @meysammahfouzi +* ๐Ÿž  Fixed: `body` is not sent in delete requests despite being accepted as parameter. Thanks to @MaciejZuk ## 1.0.1 -- โœจ  Changed: `ResponseData` now has `request` to allow checking on the request that triggered the response. Thanks to @II11II -- ๐Ÿž  Fixed: Use `queryParametersAll` when creating `RequestData`. Thanks to @Mawi137 -- ๐Ÿ“–  Fixed: `README` to include `required` keywords needed. Thanks to @meysammahfouzi -- ๐Ÿšฆ  Tests: Improved testing and documentation. +* โœจ  Changed: `ResponseData` now has `request` to allow checking on the request that triggered the response. Thanks to @II11II +* ๐Ÿž  Fixed: Use `queryParametersAll` when creating `RequestData`. Thanks to @Mawi137 +* ๐Ÿ“–  Fixed: `README` to include `required` keywords needed. Thanks to @meysammahfouzi +* ๐Ÿšฆ  Tests: Improved testing and documentation. ## 1.0.0 Check out the [1.0.0 migration guide](./guides/migration_guide_1.0.0.md) for information on how to migrate your code. -- โ—๏ธ๐Ÿ›   Changed: Renamed `HttpClientWithInterceptor` to `InterceptedClient`. -- โ—๏ธ๐Ÿ›   Changed: Renamed `HttpWithInterceptor` to `InterceptedHttp`. -- โ—๏ธ๐Ÿ›   Removed: `badCertificateCallback` from `InterceptedClient` and `InterceptedHttp` in order to fully support Flutter Web ๐ŸŒ . In order to use refer to the migration guide. -- โœจ  Added: Array parameters on `RequestData` following a similar principle than `http`'s `queryParametersAll` . -- โœจ  Changed: `ResponseData` now has `bodyBytes` to allow encoding or decoding in the format desired. -- โœจ  Changed: Migrated tests to use `test` package instead of `flutter_test`. -- โœจ  Changed: More tests and coverage, this is a work in progress. -- ๐Ÿ—‘  Removed: Package no longer depends on Flutter, which means that it can be used with standalone Dart projects. +* โ—๏ธ๐Ÿ›   Changed: Renamed `HttpClientWithInterceptor` to `InterceptedClient`. +* โ—๏ธ๐Ÿ›   Changed: Renamed `HttpWithInterceptor` to `InterceptedHttp`. +* โ—๏ธ๐Ÿ›   Removed: `badCertificateCallback` from `InterceptedClient` and `InterceptedHttp` in order to fully support Flutter Web ๐ŸŒ . In order to use refer to the migration guide. +* โœจ  Added: Array parameters on `RequestData` following a similar principle than `http`'s `queryParametersAll` . +* โœจ  Changed: `ResponseData` now has `bodyBytes` to allow encoding or decoding in the format desired. +* โœจ  Changed: Migrated tests to use `test` package instead of `flutter_test`. +* โœจ  Changed: More tests and coverage, this is a work in progress. +* ๐Ÿ—‘  Removed: Package no longer depends on Flutter, which means that it can be used with standalone Dart projects. ## 0.4.1 -- ๐Ÿ›   Changed: Pre initialized `headers` and `params` on `RequestData`. This was a missed change on null-safety migration. +* ๐Ÿ›   Changed: Pre initialized `headers` and `params` on `RequestData`. This was a missed change on null-safety migration. ## 0.4.0 Check out [our 0.4.0 migration guide](./guides/migration_guide_0.4.0.md) for information on how to migrate your code. -- โ—๏ธโœจ  Added: String extension to allow `toUri()` usage when importing the library. Since `http` dropped support for string url usage and since Dart does not yet support function overloading, we had to implement an alternative through extensions. -- โœจ  Added: Flutter web support ๐ŸŒ   (`badCertificateCallback` and `findProxy` features are not supported on Flutter Web due to browser limitations) -- ๐Ÿ›   Changed: Upgraded `http` to `0.13.0`. -- ๐Ÿ›   Changed: Upgraded `effective_dart` to `1.3.0`. -- ๐Ÿ›   Changed: Upgraded Dart `sdk` to `>=2.12.0 <3.0.0`. (Yay! Sound null safety! ๐ŸŽ‰) -- ๐Ÿ—‘  Removed: `meta` is removed since Dart's null safety now covers all uses inside this plugin +* โ—๏ธโœจ  Added: String extension to allow `toUri()` usage when importing the library. Since `http` dropped support for string url usage and since Dart does not yet support function overloading, we had to implement an alternative through extensions. +* โœจ  Added: Flutter web support ๐ŸŒ   (`badCertificateCallback` and `findProxy` features are not supported on Flutter Web due to browser limitations) +* ๐Ÿ›   Changed: Upgraded `http` to `0.13.0`. +* ๐Ÿ›   Changed: Upgraded `effective_dart` to `1.3.0`. +* ๐Ÿ›   Changed: Upgraded Dart `sdk` to `>=2.12.0 <3.0.0`. (Yay! Sound null safety! ๐ŸŽ‰) +* ๐Ÿ—‘  Removed: `meta` is removed since Dart's null safety now covers all uses inside this plugin ## 0.3.3 -- ๐Ÿ›   Changed: Plugin no longer depends on the `flutter/foundation.dart`, instead it uses `meta` plugin which allows for usage on non flutter environments. -- ๐Ÿ›   Changed: README now features a contribution and a roadmap sections for improving visibility on the project's future. -- ๐Ÿ›   Changed: `badCertificateCallback` is now available to use without the experimental tag. +* ๐Ÿ›   Changed: Plugin no longer depends on the `flutter/foundation.dart`, instead it uses `meta` plugin which allows for usage on non flutter environments. +* ๐Ÿ›   Changed: README now features a contribution and a roadmap sections for improving visibility on the project's future. +* ๐Ÿ›   Changed: `badCertificateCallback` is now available to use without the experimental tag. ## 0.3.2 -- ๐Ÿ›   Changed: Example now showcases exception handling. -- ๐Ÿ›   Changed: README now showcases exception handling. -- ๐Ÿž  Fixed: Interceptor no longer using custom exceptions, instead it rethrows in the case that the retry policy is not set or if it has reached max attempts. +* ๐Ÿ›   Changed: Example now showcases exception handling. +* ๐Ÿ›   Changed: README now showcases exception handling. +* ๐Ÿž  Fixed: Interceptor no longer using custom exceptions, instead it rethrows in the case that the retry policy is not set or if it has reached max attempts. ## 0.3.1 -- ๐Ÿž  Fixed: Retry Policy's `shouldAttemptRetryOnResponse` was synchronous which would not allow async token updates. -- ๐Ÿž  Fixed: Retry Policy would only trigger once when using `HttpClientWithInterceptor`. -- ๐Ÿž  Fixed: Retry Policy would use the `http` Response class, which would force plugin users to add http plugin separately. -- ๐Ÿงช  Experimental: `badCertificateCallback` allows you to use self-signing certificates. +* ๐Ÿž  Fixed: Retry Policy's `shouldAttemptRetryOnResponse` was synchronous which would not allow async token updates. +* ๐Ÿž  Fixed: Retry Policy would only trigger once when using `HttpClientWithInterceptor`. +* ๐Ÿž  Fixed: Retry Policy would use the `http` Response class, which would force plugin users to add http plugin separately. +* ๐Ÿงช  Experimental: `badCertificateCallback` allows you to use self-signing certificates. ## 0.3.0 -- โœจ  Added: RetryPolicy. It allows to attempt retries on a request when an exception occurs or when a condition from the response is met. -- ๐Ÿž  Fixed: URI type urls not concatenating parameters. +* โœจ  Added: RetryPolicy. It allows to attempt retries on a request when an exception occurs or when a condition from the response is met. +* ๐Ÿž  Fixed: URI type urls not concatenating parameters. ## 0.2.0 -- โœจ  Added: Unit testing for a few of the files. -- ๐Ÿ›   Changed: Android and iOS projects both in the plugin and the example now use Kotlin/Swift. -- ๐Ÿ›   Changed: Android projects both in the plugin and the example now use AndroidX namespaces. -- ๐Ÿž  Fixed: Last 'ย ' character was not removed from parametized URLs. -- ๐Ÿž  Fixed: Duplicate GET parameters when using `get`. +* โœจ  Added: Unit testing for a few of the files. +* ๐Ÿ›   Changed: Android and iOS projects both in the plugin and the example now use Kotlin/Swift. +* ๐Ÿ›   Changed: Android projects both in the plugin and the example now use AndroidX namespaces. +* ๐Ÿž  Fixed: Last 'ย ' character was not removed from parametized URLs. +* ๐Ÿž  Fixed: Duplicate GET parameters when using `get`. ## 0.1.1 -- ๐Ÿž  Fixed: HTTP Methods have misaligned parameters. Now they are called via named parameters to avoid type mismatch exceptions when being used. +* ๐Ÿž  Fixed: HTTP Methods have misaligned parameters. Now they are called via named parameters to avoid type mismatch exceptions when being used. ## 0.1.0 -- โœจ  Added: Query Parameters to GET requests, it allows you to set proper parameters without having to add them to the URL beforehand. -- ๐Ÿ›   Changed: Documentation for the example to include the new Query Parameters usage. +* โœจ  Added: Query Parameters to GET requests, it allows you to set proper parameters without having to add them to the URL beforehand. +* ๐Ÿ›   Changed: Documentation for the example to include the new Query Parameters usage. ## 0.0.3 -- โœจ  Added: Documentation for the example. +* โœจ  Added: Documentation for the example. ## 0.0.2 -- ๐Ÿž  Fixed: All the warnings regarding plugin publication. +* ๐Ÿž  Fixed: All the warnings regarding plugin publication. ## 0.0.1 -- โœจ  Added: Initial plugin implementation. -- โœจ  Added: Example of usage for the plugin. -- โœจ  Added: README.md and LICENSE files. +* โœจ  Added: Initial plugin implementation. +* โœจ  Added: Example of usage for the plugin. +* โœจ  Added: README.md and LICENSE files. diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 7483781..8d7af33 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -22,8 +22,8 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 image_picker_ios: 4a8aadfbb6dc30ad5141a2ce3832af9214a705b5 - shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 + shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011 -COCOAPODS: 1.11.3 +COCOAPODS: 1.15.2 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 96966a4..76075a6 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -156,7 +156,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a6b826d..5e31d3d 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ interceptRequest({required BaseRequest request}) async { + FutureOr interceptRequest({required BaseRequest request}) async { final cache = await SharedPreferences.getInstance(); final Map? headers = Map.from(request.headers); @@ -55,7 +55,7 @@ class WeatherApiInterceptor extends InterceptorContract { } @override - Future interceptResponse( + FutureOr interceptResponse( {required BaseResponse response}) async => response; } @@ -92,7 +92,7 @@ v2.0.0 and up class ExpiredTokenRetryPolicy extends RetryPolicy { @override - Future shouldAttemptRetryOnResponse(BaseResponse response) async { + FutureOr shouldAttemptRetryOnResponse(BaseResponse response) async { if (response.statusCode == 401) { log("Retrying request..."); final cache = await SharedPreferences.getInstance(); @@ -111,7 +111,7 @@ If you are using `shouldAttemptRetryOnException` then you will also have to conv ```dart @override -Future shouldAttemptRetryOnException( +FutureOr shouldAttemptRetryOnException( Exception reason, BaseRequest request, ) async { diff --git a/lib/http/intercepted_client.dart b/lib/http/intercepted_client.dart index 3ce7e3e..52178a5 100644 --- a/lib/http/intercepted_client.dart +++ b/lib/http/intercepted_client.dart @@ -45,7 +45,7 @@ class InterceptedClient extends BaseClient { final List interceptors; /// Maximum duration of a request. - final Duration? requestTimeout; + Duration? requestTimeout; /// Request timeout handler TimeoutCallback? onRequestTimeout; diff --git a/pubspec.yaml b/pubspec.yaml index 3127d6a..7aaff9b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,8 +11,8 @@ environment: sdk: ">=3.0.3 <4.0.0" dependencies: - http: ^1.1.0 + http: ^1.2.1 dev_dependencies: - lints: ^3.0.0 - test: ^1.25.2 + lints: ^4.0.0 + test: ^1.25.8