Add styles download - #70
Conversation
The operation is now enabled for the CLI. Same upstream revision as before; the only change is the new operation.
styles:download is registrable now, so login asks for it and downloadStyleZip leaves UNSUPPORTED_OPERATIONS. The endpoint also needs account access no token carries. A 403 is read for which cause it is: missing access says to contact Mapbox, a named missing scope says to log in again, anything else keeps the old advice.
A redirected download otherwise ends in silence. At a terminal, and not under --quiet, say what was written and how large it was.
e135f62 to
e6b91b2
Compare
The shared 403 says "prerelease" for every account flag, including ones that gate special access rather than an early release.
A token from --token or MAPBOX_ACCESS_TOKEN outranks the login, so logging in again re-sends the same token and gets the same 403. The advice now depends on where the token came from, as a 401's does.
mattpodwysocki
left a comment
There was a problem hiding this comment.
Built and ran the full suite on the actual branch: 517 unit tests plus every integration suite pass, fmt/clippy clean, CI all green.
Traced the new 403 classifier closely, since it is the real logic in this PR. It tells apart three causes: an account-access gate ("contact Mapbox"), a missing scope (parsed out of the real error text and checked against a scope-shape regex, so it never echoes arbitrary server text back into advice), and the generic fallback. Verified the missing-scope path gives different fixes depending on where the token came from, a login versus --token/the environment get genuinely different advice since only a login benefits from running mapbox auth login again. Also checked the terminal-refusal message text and the new docs example against the actual code, they match.
Nothing wrong found. Approving.
Adds
mapbox styles download <style-id> > style.zip, now that thestyles:downloadscope can be granted at login.openapi/api-stylesregenerated withdownloadStyleZipenabled. The only change is the new operation.mapbox auth loginnow requestsstyles:download. Existing logins need to log in again.<scope>scope" → depends on where the token came from, like a 401: a login is told to runmapbox auth loginagain (also innext_actions); a--tokenorMAPBOX_ACCESS_TOKENtoken is told to add the scope to that token, withmapbox auth whoamias the action.Wrote application/zip (988165 bytes).to stderr. stdout is unchanged, and--quiethides it. This applies to every binary command, not juststyles download.Testing
cargo fmt,cargo clippy --all-targets -- -D warnings,cargo testpass.styles:download) gets the "log in again" advice; the same token passed throughMAPBOX_ACCESS_TOKENgets "add the scope to that token" instead.mapbox auth login,styles downloaddownloads a complete ZIP (566 files:style.json, 561 SVG icons and the style's custom.otf), and prints the confirmation line.static get-imagedoes.