sinew_network 1.0.0
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) andSinewHooksInterceptor(after auth: faults, the host override,debugExpireToken).SinewHttp.dio(…, hooks:)andSinewHttp.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'sfetch<T>rewrites the response type from anyTbutdynamic, so a plain-text orStringrequest got its JSON body decoded into aMapafter a refresh, failing the caller's cast. -
S3:
NetworkCheckeronconnectivity_plus, for the UI:status(startsonlineuntil the platform first reports),isOnline, a broadcastchangesstream of distinctNetworkStatuschanges, anddispose(). Online when any interface butnoneis 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 bytool/network_checker_device_test.sh) and iOS. -
S3:
retryWithBackoff(exponential backoff with full jitter, capped atmaxDelay; a 429 waits at leastretryAfter, or is returned at once when that's longer thanmaxDelay; the last failure returned unchanged) andpoll(1.5× growth with equal jitter up tomaxInterval; retryable failures keep polling;PollingTimeOutExceptionwith 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:
processApiCallandprocessOptionalApiCall(a 404 isnull): envelopefailure()→ValidationExceptionorApiErrorExceptionbeforetoDomain(),message()→Success.message, and a cause the auth interceptor wrapped passed through unreported. The publicapiHandlerstable overDioException(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 → reportedParseException), and a plainDio'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 sharedCompleter; a 401 for an older token replays at once; the replay goes through the sameDio, once;Rejectedand a replayed 401 pass the 401 on;Unavailablefails with its cause and keeps the session; a request's ownAuthorization, a 401 after sign-out and a one-shot body are left alone),SinewHttp.resetAuth, andSessionTokenSourcewithRefreshTokenStore,RefreshCallandRefreshResult(session epoch under an async lock,start,onSessionEnded, a rejection ending only the session it started in).SinewHttp.dionow takes theTokenSource. -
S3: the Dio interceptors, each installable alone:
SinewTimeoutInterceptor(a total deadline by method that cancels withDeadlineExceededon the request's own token, a request'ssinewDeadlinewinning),SinewHeadersInterceptor,SinewErrorBodyInterceptor(attachesHttpStatusError) andSinewLogInterceptorwithHttpLogger; and the optionalSinewHttp.dio(config)preset. Redirects are the platform's own (dart:io and the browser dropAuthorizationacross hosts), so there's no redirect interceptor. -
S3:
SinewConfig(validated on construction;localeanddefaultHeadersread per request),TokenSourcewithRefreshOutcome(Refreshed,Rejected,Unavailable(cause)) and theclear()contract,ErrorBodyReader.standard(readsmessageanderrorsfrom a decoded map or a JSON string) andErrorBodyReader.from, and the unexportedHttpStatusErrorwithRetry-Afterin seconds or an IMF-fixdate. -
S0: package skeleton.