Skip to main content

sinew_network 1.0.0 copy "sinew_network: ^1.0.0" to clipboard
sinew_network: ^1.0.0 copied to clipboard

SinewHttp (Dio), the auth layer, processApiCall, retry, polling and NetworkChecker.

1.0.0 #

  • SinewHttpHooks, FaultDecision, HttpExchange, SinewRecorderInterceptor (before auth) and SinewHooksInterceptor (after auth: faults, the host override, debugExpireToken). SinewHttp.dio(…, hooks:) and SinewHttp.debugExpireToken(dio).

  • S5 fix: a request replayed after a token refresh keeps its response type. The auth interceptor replayed with dio.fetch<Object?>, and Dio's fetch<T> rewrites the response type from any T but dynamic, so a plain-text or String request got its JSON body decoded into a Map after a refresh, failing the caller's cast.

  • S3: NetworkChecker on connectivity_plus, for the UI: status (starts online until the platform first reports), isOnline, a broadcast changes stream of distinct NetworkStatus changes, and dispose(). Online when any interface but none is reported; a platform error keeps the last status, and a platform without an implementation stays online. Integration tests on Android (Wi-Fi and data switched off and on by tool/network_checker_device_test.sh) and iOS.

  • S3: retryWithBackoff (exponential backoff with full jitter, capped at maxDelay; a 429 waits at least retryAfter, or is returned at once when that's longer than maxDelay; the last failure returned unchanged) and poll (1.5× growth with equal jitter up to maxInterval; retryable failures keep polling; PollingTimeOutException with the last failure as its cause; a call in flight at the timeout finishes in the background, ignored).

  • S3: pinCertificateAuthorities(dio, authorities): trusts only the pinned authorities (no system root), so an unpinned chain fails at the TLS handshake before anything is sent; keeps the app's IO adapter; does nothing in the browser, which owns TLS.

  • S3: processApiCall and processOptionalApiCall (a 404 is null): envelope failure() → ValidationException or ApiErrorException before toDomain(), message() → Success.message, and a cause the auth interceptor wrapped passed through unreported. The public apiHandlers table over DioException (a deadline and Dio's timeouts → RequestTimeOutException; any other cancel → CancelException, never reported; a connection error or socket failure → NoInternetConnectionException, never with a TLS failure in it; the status rows; unreadable JSON, a DTO that doesn't fit and an enum with no fallback → reported ParseException), and a plain Dio's failed status classified by status. RefreshResult.from(result).

  • S3: SinewAuthInterceptor (the token only for the base URL's host and port outside the exact anonymous paths; one refresh for any number of 401s through a shared Completer; a 401 for an older token replays at once; the replay goes through the same Dio, once; Rejected and a replayed 401 pass the 401 on; Unavailable fails with its cause and keeps the session; a request's own Authorization, a 401 after sign-out and a one-shot body are left alone), SinewHttp.resetAuth, and SessionTokenSource with RefreshTokenStore, RefreshCall and RefreshResult (session epoch under an async lock, start, onSessionEnded, a rejection ending only the session it started in). SinewHttp.dio now takes the TokenSource.

  • S3: the Dio interceptors, each installable alone: SinewTimeoutInterceptor (a total deadline by method that cancels with DeadlineExceeded on the request's own token, a request's sinewDeadline winning), SinewHeadersInterceptor, SinewErrorBodyInterceptor (attaches HttpStatusError) and SinewLogInterceptor with HttpLogger; and the optional SinewHttp.dio(config) preset. Redirects are the platform's own (dart:io and the browser drop Authorization across hosts), so there's no redirect interceptor.

  • S3: SinewConfig (validated on construction; locale and defaultHeaders read per request), TokenSource with RefreshOutcome (Refreshed, Rejected, Unavailable(cause)) and the clear() contract, ErrorBodyReader.standard (reads message and errors from a decoded map or a JSON string) and ErrorBodyReader.from, and the unexported HttpStatusError with Retry-After in seconds or an IMF-fixdate.

  • S0: package skeleton.

0
likes
160
points
306
downloads

Documentation

Documentation
API reference

Publisher

verified publishersrctool.com

Weekly Downloads

SinewHttp (Dio), the auth layer, processApiCall, retry, polling and NetworkChecker.

Repository (GitHub)
View/report issues
Contributing

Topics

#http #dio #networking #authentication

License

Apache-2.0 (license)

Dependencies

connectivity_plus, dio, flutter, sinew_exception, sinew_models

More

Packages that depend on sinew_network