Read-only mirror of github.com/smbcloudXYZ/smbcloud-ascapi.
Mirrored from https://github.com/smbcloudXYZ/smbcloud-ascapi.git
Synced Nov 25, 09:15 UTC
Add asc amazon for the Amazon Appstore submission API
New crate smbcloud-ascapi-amazon signs in with Login with Amazon client credentials and wraps the open edit, APK upload and replace (ETag in If-Match), per-APK targeting and validate. asc amazon edits|apks|targeting sit on top of it, and every write takes --dry-run. MCP gets two read-only tools, amazon_edit_get and amazon_apk_list. There is no commit call on purpose: submitting for review stays a human step in the Developer Console. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Seto Elkahfi committed
Nov 12, 2026 at 09:34 UTC
1c4a3cf5c0ce55ad0e245c70f27a3e5d3e473c2f
22 files changed
+1052
-6
Cargo.lock
+12
@@ -1817,6 +1817,17 @@ dependencies = [
1817
"tokio",
1818
]
1819
1820
+[[package]]
1821
+name = "smbcloud-ascapi-amazon"
1822
+version = "0.3.0"
1823
+dependencies = [
1824
+ "reqwest",
1825
+ "serde",
1826
+ "serde_json",
1827
+ "thiserror",
1828
+ "tokio",
1829
+]
1830
+
1831
[[package]]
1832
name = "smbcloud-ascapi-appgallery"
1833
version = "0.3.0"
@@ -1890,6 +1901,7 @@ dependencies = [
1901
"serde_json",
1902
"sha2",
1903
"smbcloud-ascapi-admob",
1904
+ "smbcloud-ascapi-amazon",
1905
"smbcloud-ascapi-appgallery",
1906
"smbcloud-ascapi-aso",
1907
"smbcloud-ascapi-core",
Cargo.toml
+2
@@ -6,6 +6,7 @@ members = [
6
"crates/play",
7
"crates/admob",
8
"crates/appgallery",
9
+ "crates/amazon",
10
"crates/msstore",
11
"crates/signing",
12
"crates/pricing",
@@ -28,6 +29,7 @@ smbcloud-ascapi-core = { version = "0.3.0", path = "crates/core" }
29
smbcloud-ascapi-aso = { version = "0.3.0", path = "crates/aso" }
30
smbcloud-ascapi-play = { version = "0.3.0", path = "crates/play" }
31
smbcloud-ascapi-admob = { version = "0.3.0", path = "crates/admob" }
32
+smbcloud-ascapi-amazon = { version = "0.3.0", path = "crates/amazon" }
33
smbcloud-ascapi-appgallery = { version = "0.3.0", path = "crates/appgallery" }
34
smbcloud-ascapi-msstore = { version = "0.3.0", path = "crates/msstore" }
35
smbcloud-ascapi-signing = { version = "0.3.0", path = "crates/signing" }
README.md
+1
-1
@@ -35,7 +35,7 @@ Pre-built binaries are on [GitHub Releases](https://github.com/smbcloudXYZ/smbcl
35
36
## Docs
37
38
-[Install](docs/install.md) · [Credentials](docs/credentials.md) · [AppGallery](docs/appgallery.md) · [AdMob](docs/admob.md) · [Architecture](docs/architecture.md)
38
+[Install](docs/install.md) · [Credentials](docs/credentials.md) · [AppGallery](docs/appgallery.md) · [Amazon](docs/amazon.md) · [AdMob](docs/admob.md) · [Architecture](docs/architecture.md)
39
40
## Contributing
41
crates/amazon/Cargo.toml
new
+22
@@ -0,0 +1,22 @@
1
+[package]
2
+name = "smbcloud-ascapi-amazon"
3
+version.workspace = true
4
+edition.workspace = true
5
+authors.workspace = true
6
+license.workspace = true
7
+repository.workspace = true
8
+description = "Amazon Appstore App Submission API: Login with Amazon client-credentials authentication, edits, APK upload and device targeting."
9
+readme = "README.md"
10
+
11
+[lib]
12
+path = "src/lib.rs"
13
+
14
+[dependencies]
15
+reqwest = { workspace = true, features = ["json", "rustls-tls-native-roots"] }
16
+serde = { workspace = true, features = ["derive"] }
17
+serde_json = { workspace = true }
18
+thiserror = { workspace = true }
19
+tokio = { workspace = true, features = ["fs"] }
20
+
21
+[dev-dependencies]
22
+tokio = { workspace = true, features = ["macros", "rt", "net", "io-util"] }
crates/amazon/README.md
new
+6
@@ -0,0 +1,6 @@
1
+# smbcloud-ascapi-amazon
2
+
3
+Amazon Appstore App Submission API for `asc amazon`: Login with Amazon
4
+client-credentials sign-in, the open edit, APK upload and replace, and
5
+per-APK device targeting. There is deliberately no `commit`: submitting an
6
+edit for review stays a human action in the Developer Console.
crates/amazon/src/apk.rs
new
+152
@@ -0,0 +1,152 @@
1
+use std::path::Path;
2
+
3
+use reqwest::header::{CONTENT_TYPE, IF_MATCH};
4
+use reqwest::Method;
5
+use serde_json::Value;
6
+
7
+use crate::client::AmazonClient;
8
+use crate::error::{Error, Result};
9
+
10
+/// The body type Amazon requires for APK uploads.
11
+pub const APK_CONTENT_TYPE: &str = "application/vnd.android.package-archive";
12
+
13
+async fn read_apk(path: &Path) -> Result<Vec<u8>> {
14
+ tokio::fs::read(path)
15
+ .await
16
+ .map_err(|source| Error::FileRead {
17
+ path: path.display().to_string(),
18
+ source,
19
+ })
20
+}
21
+
22
+impl AmazonClient {
23
+ /// APKs on the edit, as Amazon returns them (id, versionCode, name, …).
24
+ pub async fn list_apks(&self, app_id: &str, edit_id: &str) -> Result<Value> {
25
+ let url = self.url(app_id, &format!("/edits/{edit_id}/apks"));
26
+ let request = self.request(Method::GET, &url).await?;
27
+ Ok(self.send(request).await?.json().await?)
28
+ }
29
+
30
+ /// Upload the first APK of an edit.
31
+ pub async fn upload_apk(&self, app_id: &str, edit_id: &str, apk: &Path) -> Result<Value> {
32
+ let body = read_apk(apk).await?;
33
+ let url = self.url(app_id, &format!("/edits/{edit_id}/apks/upload"));
34
+ let request = self
35
+ .request(Method::POST, &url)
36
+ .await?
37
+ .header(CONTENT_TYPE, APK_CONTENT_TYPE)
38
+ .body(body);
39
+ Ok(self.send(request).await?.json().await?)
40
+ }
41
+
42
+ /// The APK's `ETag`, which `replace` must echo in `If-Match`.
43
+ pub async fn apk_etag(&self, app_id: &str, edit_id: &str, apk_id: &str) -> Result<String> {
44
+ let url = self.url(app_id, &format!("/edits/{edit_id}/apks/{apk_id}"));
45
+ let request = self.request(Method::GET, &url).await?;
46
+ let response = self.send(request).await?;
47
+ response
48
+ .headers()
49
+ .get(reqwest::header::ETAG)
50
+ .and_then(|v| v.to_str().ok())
51
+ .map(str::to_string)
52
+ .ok_or(Error::NoEtag("apk"))
53
+ }
54
+
55
+ /// Replace an APK in place. `etag` comes from [`Self::apk_etag`].
56
+ pub async fn replace_apk(
57
+ &self,
58
+ app_id: &str,
59
+ edit_id: &str,
60
+ apk_id: &str,
61
+ etag: &str,
62
+ apk: &Path,
63
+ ) -> Result<Value> {
64
+ let body = read_apk(apk).await?;
65
+ let url = self.url(app_id, &format!("/edits/{edit_id}/apks/{apk_id}/replace"));
66
+ let request = self
67
+ .request(Method::PUT, &url)
68
+ .await?
69
+ .header(CONTENT_TYPE, APK_CONTENT_TYPE)
70
+ .header(IF_MATCH, etag)
71
+ .body(body);
72
+ Ok(self.send(request).await?.json().await?)
73
+ }
74
+
75
+ pub async fn delete_apk(&self, app_id: &str, edit_id: &str, apk_id: &str) -> Result<()> {
76
+ let url = self.url(app_id, &format!("/edits/{edit_id}/apks/{apk_id}"));
77
+ let request = self.request(Method::DELETE, &url).await?;
78
+ self.send(request).await?;
79
+ Ok(())
80
+ }
81
+}
82
+
83
+#[cfg(test)]
84
+mod tests {
85
+ use super::*;
86
+ use crate::auth::Credentials;
87
+ use crate::client::testserver::serve;
88
+
89
+ const TOKEN_OK: &str =
90
+ "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 26\r\nConnection: close\r\n\r\n{\"access_token\":\"tok-123\"}";
91
+ const JSON_OK: &str =
92
+ "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 8\r\nConnection: close\r\n\r\n{\"id\":1}";
93
+ const ETAG_OK: &str =
94
+ "HTTP/1.1 200 OK\r\nETag: \"v7\"\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
95
+
96
+ fn creds() -> Credentials {
97
+ Credentials::from_json(r#"{"client_id":"cid","client_secret":"csecret"}"#).unwrap()
98
+ }
99
+
100
+ fn temp_apk() -> std::path::PathBuf {
101
+ let path = std::env::temp_dir().join(format!("amazon-test-{}.apk", std::process::id()));
102
+ std::fs::write(&path, b"PK-apk-bytes").unwrap();
103
+ path
104
+ }
105
+
106
+ #[tokio::test]
107
+ async fn the_token_request_posts_the_client_credentials_form() {
108
+ let (base, seen) = serve(vec![TOKEN_OK, JSON_OK]).await;
109
+ let client = AmazonClient::new(creds())
110
+ .with_endpoints(&format!("{base}/auth/o2/token"), &format!("{base}/apps"));
111
+ client.list_apks("APP", "EDIT").await.unwrap();
112
+ let requests = seen.await.unwrap();
113
+ assert!(requests[0].starts_with("POST /auth/o2/token"));
114
+ assert!(requests[0].contains("grant_type=client_credentials"));
115
+ assert!(requests[0].contains("scope=appstore%3A%3Aapps%3Areadwrite"));
116
+ assert!(requests[1].starts_with("GET /apps/APP/edits/EDIT/apks "));
117
+ assert!(requests[1]
118
+ .to_lowercase()
119
+ .contains("authorization: bearer tok-123"));
120
+ }
121
+
122
+ #[tokio::test]
123
+ async fn upload_sends_the_apk_content_type_and_bytes() {
124
+ let (base, seen) = serve(vec![TOKEN_OK, JSON_OK]).await;
125
+ let client = AmazonClient::new(creds())
126
+ .with_endpoints(&format!("{base}/auth/o2/token"), &format!("{base}/apps"));
127
+ let apk = temp_apk();
128
+ client.upload_apk("APP", "EDIT", &apk).await.unwrap();
129
+ let requests = seen.await.unwrap();
130
+ assert!(requests[1].starts_with("POST /apps/APP/edits/EDIT/apks/upload "));
131
+ assert!(requests[1]
132
+ .to_lowercase()
133
+ .contains("content-type: application/vnd.android.package-archive"));
134
+ assert!(requests[1].ends_with("PK-apk-bytes"));
135
+ }
136
+
137
+ #[tokio::test]
138
+ async fn replace_carries_the_etag_in_if_match() {
139
+ let (base, seen) = serve(vec![TOKEN_OK, ETAG_OK, JSON_OK]).await;
140
+ let client = AmazonClient::new(creds())
141
+ .with_endpoints(&format!("{base}/auth/o2/token"), &format!("{base}/apps"));
142
+ let etag = client.apk_etag("APP", "EDIT", "APK").await.unwrap();
143
+ assert_eq!(etag, "\"v7\"");
144
+ client
145
+ .replace_apk("APP", "EDIT", "APK", &etag, &temp_apk())
146
+ .await
147
+ .unwrap();
148
+ let requests = seen.await.unwrap();
149
+ assert!(requests[2].starts_with("PUT /apps/APP/edits/EDIT/apks/APK/replace "));
150
+ assert!(requests[2].to_lowercase().contains("if-match: \"v7\""));
151
+ }
152
+}
crates/amazon/src/auth.rs
new
+95
@@ -0,0 +1,95 @@
1
+use std::path::Path;
2
+
3
+use serde::Deserialize;
4
+
5
+use crate::error::{Error, Result};
6
+
7
+/// Login with Amazon token endpoint.
8
+pub const TOKEN_URL: &str = "https://api.amazon.com/auth/o2/token";
9
+/// The scope the App Submission API asks for.
10
+pub const SCOPE: &str = "appstore::apps:readwrite";
11
+
12
+/// The Security Profile credentials (`{"client_id": …, "client_secret": …}`).
13
+#[derive(Clone, Deserialize)]
14
+pub struct Credentials {
15
+ pub client_id: String,
16
+ client_secret: String,
17
+}
18
+
19
+// Hand-written so `{:?}` can never print the secret.
20
+impl std::fmt::Debug for Credentials {
21
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22
+ f.debug_struct("Credentials")
23
+ .field("client_id", &self.client_id)
24
+ .field("client_secret", &"<redacted>")
25
+ .finish()
26
+ }
27
+}
28
+
29
+impl Credentials {
30
+ pub fn from_json(json: &str) -> Result<Self> {
31
+ let credentials: Self =
32
+ serde_json::from_str(json).map_err(|_| Error::CredentialsInvalid)?;
33
+ if credentials.client_id.is_empty() || credentials.client_secret.is_empty() {
34
+ return Err(Error::CredentialsInvalid);
35
+ }
36
+ Ok(credentials)
37
+ }
38
+
39
+ pub fn from_json_file(path: impl AsRef<Path>) -> Result<Self> {
40
+ let path = path.as_ref();
41
+ let json = std::fs::read_to_string(path).map_err(|source| Error::CredentialsRead {
42
+ path: path.display().to_string(),
43
+ source,
44
+ })?;
45
+ Self::from_json(&json)
46
+ }
47
+
48
+ /// The form fields of the `client_credentials` token request.
49
+ pub fn token_form(&self) -> [(&'static str, &str); 4] {
50
+ [
51
+ ("grant_type", "client_credentials"),
52
+ ("client_id", &self.client_id),
53
+ ("client_secret", &self.client_secret),
54
+ ("scope", SCOPE),
55
+ ]
56
+ }
57
+}
58
+
59
+#[derive(Deserialize)]
60
+pub(crate) struct TokenResponse {
61
+ pub access_token: String,
62
+}
63
+
64
+#[cfg(test)]
65
+mod tests {
66
+ use super::*;
67
+
68
+ #[test]
69
+ fn token_request_is_a_client_credentials_form_with_the_appstore_scope() {
70
+ let c = Credentials::from_json(r#"{"client_id":"amzn1.id","client_secret":"s3"}"#).unwrap();
71
+ let form = c.token_form();
72
+ assert!(form.contains(&("grant_type", "client_credentials")));
73
+ assert!(form.contains(&("scope", "appstore::apps:readwrite")));
74
+ assert!(form.contains(&("client_id", "amzn1.id")));
75
+ assert!(form.contains(&("client_secret", "s3")));
76
+ assert_eq!(TOKEN_URL, "https://api.amazon.com/auth/o2/token");
77
+ }
78
+
79
+ #[test]
80
+ fn debug_output_never_contains_the_secret() {
81
+ let c = Credentials::from_json(r#"{"client_id":"id-1","client_secret":"SECRET"}"#).unwrap();
82
+ let shown = format!("{c:?}");
83
+ assert!(!shown.contains("SECRET"));
84
+ assert!(shown.contains("id-1"));
85
+ }
86
+
87
+ #[test]
88
+ fn invalid_credentials_are_rejected_without_echoing_them() {
89
+ let err = Credentials::from_json(r#"{"client_id":"id-1","client_secret":""}"#)
90
+ .unwrap_err()
91
+ .to_string();
92
+ assert!(!err.contains("id-1"));
93
+ assert!(Credentials::from_json("nope").is_err());
94
+ }
95
+}
crates/amazon/src/client.rs
new
+135
@@ -0,0 +1,135 @@
1
+use reqwest::Method;
2
+
3
+use crate::auth::{Credentials, TokenResponse, TOKEN_URL};
4
+use crate::error::{Error, Result};
5
+
6
+const API_ROOT: &str = "https://developer.amazon.com/api/appstore/v1/applications";
7
+
8
+/// A signed-in Amazon Appstore client. The access token is fetched on first
9
+/// use and reused (Amazon's lasts an hour, longer than a CLI run).
10
+pub struct AmazonClient {
11
+ http: reqwest::Client,
12
+ credentials: Credentials,
13
+ token_url: String,
14
+ root: String,
15
+ token: tokio::sync::OnceCell<String>,
16
+}
17
+
18
+impl AmazonClient {
19
+ pub fn new(credentials: Credentials) -> Self {
20
+ Self {
21
+ http: reqwest::Client::new(),
22
+ credentials,
23
+ token_url: TOKEN_URL.to_string(),
24
+ root: API_ROOT.to_string(),
25
+ token: tokio::sync::OnceCell::new(),
26
+ }
27
+ }
28
+
29
+ /// Point at other hosts; used by the tests.
30
+ #[doc(hidden)]
31
+ pub fn with_endpoints(mut self, token_url: &str, root: &str) -> Self {
32
+ self.token_url = token_url.to_string();
33
+ self.root = root.to_string();
34
+ self
35
+ }
36
+
37
+ pub fn client_id(&self) -> &str {
38
+ &self.credentials.client_id
39
+ }
40
+
41
+ async fn token(&self) -> Result<&str> {
42
+ self.token
43
+ .get_or_try_init(|| async {
44
+ let response = self
45
+ .http
46
+ .post(&self.token_url)
47
+ .form(&self.credentials.token_form())
48
+ .send()
49
+ .await?;
50
+ let status = response.status();
51
+ if !status.is_success() {
52
+ return Err(Error::Token {
53
+ status: status.as_u16(),
54
+ detail: response.text().await.unwrap_or_default(),
55
+ });
56
+ }
57
+ Ok(response.json::<TokenResponse>().await?.access_token)
58
+ })
59
+ .await
60
+ .map(String::as_str)
61
+ }
62
+
63
+ pub(crate) fn url(&self, app_id: &str, path: &str) -> String {
64
+ format!("{}/{app_id}{path}", self.root)
65
+ }
66
+
67
+ /// An authenticated request builder; the caller adds headers and body.
68
+ pub(crate) async fn request(
69
+ &self,
70
+ method: Method,
71
+ url: &str,
72
+ ) -> Result<reqwest::RequestBuilder> {
73
+ let token = self.token().await?;
74
+ Ok(self.http.request(method, url).bearer_auth(token))
75
+ }
76
+
77
+ /// Send, and turn a non-2xx into [`Error::Api`].
78
+ pub(crate) async fn send(&self, request: reqwest::RequestBuilder) -> Result<reqwest::Response> {
79
+ let response = request.send().await?;
80
+ let status = response.status();
81
+ if status.is_success() {
82
+ Ok(response)
83
+ } else {
84
+ Err(Error::Api {
85
+ status: status.as_u16(),
86
+ detail: response.text().await.unwrap_or_default(),
87
+ })
88
+ }
89
+ }
90
+}
91
+
92
+/// Test helper: a one-shot HTTP server that records raw requests and answers
93
+/// each with the next canned response.
94
+#[cfg(test)]
95
+pub(crate) mod testserver {
96
+ use tokio::io::{AsyncReadExt, AsyncWriteExt};
97
+
98
+ /// Returns the base URL and a handle yielding the raw requests received.
99
+ pub async fn serve(
100
+ responses: Vec<&'static str>,
101
+ ) -> (String, tokio::task::JoinHandle<Vec<String>>) {
102
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
103
+ let base = format!("http://{}", listener.local_addr().unwrap());
104
+ let handle = tokio::spawn(async move {
105
+ let mut seen = Vec::new();
106
+ for body in responses {
107
+ let (mut sock, _) = listener.accept().await.unwrap();
108
+ let mut buf = Vec::new();
109
+ let mut chunk = [0u8; 4096];
110
+ loop {
111
+ let n = sock.read(&mut chunk).await.unwrap();
112
+ buf.extend_from_slice(&chunk[..n]);
113
+ if let Some(end) = buf.windows(4).position(|w| w == b"\r\n\r\n") {
114
+ let head = String::from_utf8_lossy(&buf[..end]).to_lowercase();
115
+ let len = head
116
+ .lines()
117
+ .find_map(|l| l.strip_prefix("content-length:"))
118
+ .and_then(|v| v.trim().parse::<usize>().ok())
119
+ .unwrap_or(0);
120
+ if buf.len() >= end + 4 + len || n == 0 {
121
+ break;
122
+ }
123
+ } else if n == 0 {
124
+ break;
125
+ }
126
+ }
127
+ seen.push(String::from_utf8_lossy(&buf).to_string());
128
+ sock.write_all(body.as_bytes()).await.unwrap();
129
+ sock.shutdown().await.ok();
130
+ }
131
+ seen
132
+ });
133
+ (base, handle)
134
+ }
135
+}
crates/amazon/src/edit.rs
new
+64
@@ -0,0 +1,64 @@
1
+//! The edit is Amazon's draft of the next release: APKs, targeting and
2
+//! listing changes accumulate on it until it is committed in the console.
3
+
4
+use reqwest::{Method, StatusCode};
5
+use serde::{Deserialize, Serialize};
6
+
7
+use crate::client::AmazonClient;
8
+use crate::error::{Error, Result};
9
+
10
+#[derive(Debug, Clone, Serialize, Deserialize)]
11
+#[serde(rename_all = "camelCase")]
12
+pub struct Edit {
13
+ pub id: String,
14
+ #[serde(default)]
15
+ pub status: Option<String>,
16
+ /// Fields this crate does not model are kept so output stays complete.
17
+ #[serde(flatten)]
18
+ pub rest: serde_json::Map<String, serde_json::Value>,
19
+}
20
+
21
+impl AmazonClient {
22
+ /// The open edit, or `None` when the app has none (HTTP 404).
23
+ pub async fn get_edit(&self, app_id: &str) -> Result<Option<Edit>> {
24
+ let url = self.url(app_id, "/edits");
25
+ let response = self.request(Method::GET, &url).await?.send().await?;
26
+ if response.status() == StatusCode::NOT_FOUND {
27
+ return Ok(None);
28
+ }
29
+ let status = response.status();
30
+ if !status.is_success() {
31
+ return Err(Error::Api {
32
+ status: status.as_u16(),
33
+ detail: response.text().await.unwrap_or_default(),
34
+ });
35
+ }
36
+ Ok(Some(response.json().await?))
37
+ }
38
+
39
+ /// Open a new edit. Fails if one is already open.
40
+ pub async fn create_edit(&self, app_id: &str) -> Result<Edit> {
41
+ let url = self.url(app_id, "/edits");
42
+ let request = self.request(Method::POST, &url).await?;
43
+ Ok(self.send(request).await?.json().await?)
44
+ }
45
+
46
+ /// Ask Amazon to validate the edit; the reply lists any problems.
47
+ pub async fn validate_edit(&self, app_id: &str, edit_id: &str) -> Result<serde_json::Value> {
48
+ let url = self.url(app_id, &format!("/edits/{edit_id}/validate"));
49
+ let request = self.request(Method::POST, &url).await?;
50
+ let response = self.send(request).await?;
51
+ let text = response.text().await?;
52
+ if text.trim().is_empty() {
53
+ return Ok(serde_json::Value::Null);
54
+ }
55
+ Ok(serde_json::from_str(&text)?)
56
+ }
57
+
58
+ pub async fn delete_edit(&self, app_id: &str, edit_id: &str) -> Result<()> {
59
+ let url = self.url(app_id, &format!("/edits/{edit_id}"));
60
+ let request = self.request(Method::DELETE, &url).await?;
61
+ self.send(request).await?;
62
+ Ok(())
63
+ }
64
+}
crates/amazon/src/error.rs
new
+40
@@ -0,0 +1,40 @@
1
+use thiserror::Error;
2
+
3
+#[derive(Debug, Error)]
4
+pub enum Error {
5
+ #[error("failed to read the credentials file {path}: {source}")]
6
+ CredentialsRead {
7
+ path: String,
8
+ #[source]
9
+ source: std::io::Error,
10
+ },
11
+
12
+ /// Deliberately carries no part of the file: a parse error could
13
+ /// otherwise quote the secret.
14
+ #[error("the credentials JSON is not valid or lacks client_id/client_secret")]
15
+ CredentialsInvalid,
16
+
17
+ #[error("http request failed: {0}")]
18
+ Http(#[from] reqwest::Error),
19
+
20
+ #[error("failed to decode JSON response: {0}")]
21
+ Json(#[from] serde_json::Error),
22
+
23
+ #[error("Login with Amazon returned {status}: {detail}")]
24
+ Token { status: u16, detail: String },
25
+
26
+ #[error("Amazon Appstore API returned {status}: {detail}")]
27
+ Api { status: u16, detail: String },
28
+
29
+ #[error("reading {path}: {source}")]
30
+ FileRead {
31
+ path: String,
32
+ #[source]
33
+ source: std::io::Error,
34
+ },
35
+
36
+ #[error("the {0} response had no ETag header")]
37
+ NoEtag(&'static str),
38
+}
39
+
40
+pub type Result<T> = std::result::Result<T, Error>;
crates/amazon/src/lib.rs
new
+19
@@ -0,0 +1,19 @@
1
+//! Amazon Appstore App Submission API.
2
+//!
3
+//! [`Credentials`] are a Login with Amazon Security Profile; the client
4
+//! exchanges them for a bearer token (`client_credentials`, scope
5
+//! `appstore::apps:readwrite`). [`edit`] manages the open edit, [`apk`]
6
+//! uploads and replaces packages, [`targeting`] reads and writes device
7
+//! targeting. There is no commit: submitting stays in the Developer Console.
8
+
9
+pub mod apk;
10
+pub mod auth;
11
+pub mod client;
12
+pub mod edit;
13
+pub mod error;
14
+pub mod targeting;
15
+
16
+pub use auth::Credentials;
17
+pub use client::AmazonClient;
18
+pub use edit::Edit;
19
+pub use error::{Error, Result};
crates/amazon/src/targeting.rs
new
+34
@@ -0,0 +1,34 @@
1
+//! Per-APK device targeting. The body is passed through untouched: Amazon
2
+//! owns its shape (supported and excluded devices), so the safe edit is
3
+//! read, change the fields you mean to, and put the whole document back.
4
+
5
+use reqwest::Method;
6
+use serde_json::Value;
7
+
8
+use crate::client::AmazonClient;
9
+use crate::error::Result;
10
+
11
+impl AmazonClient {
12
+ pub async fn get_targeting(&self, app_id: &str, edit_id: &str, apk_id: &str) -> Result<Value> {
13
+ let url = self.url(app_id, &format!("/edits/{edit_id}/apks/{apk_id}/targeting"));
14
+ let request = self.request(Method::GET, &url).await?;
15
+ Ok(self.send(request).await?.json().await?)
16
+ }
17
+
18
+ pub async fn put_targeting(
19
+ &self,
20
+ app_id: &str,
21
+ edit_id: &str,
22
+ apk_id: &str,
23
+ targeting: &Value,
24
+ ) -> Result<Value> {
25
+ let url = self.url(app_id, &format!("/edits/{edit_id}/apks/{apk_id}/targeting"));
26
+ let request = self.request(Method::PUT, &url).await?.json(targeting);
27
+ let response = self.send(request).await?;
28
+ let text = response.text().await?;
29
+ if text.trim().is_empty() {
30
+ return Ok(Value::Null);
31
+ }
32
+ Ok(serde_json::from_str(&text)?)
33
+ }
34
+}
crates/cli/src/main.rs
+150
@@ -820,6 +820,66 @@ enum PlayProductsCommand {
820
},
821
}
822
823
+#[derive(Subcommand)]
824
+enum AmazonCommand {
825
+ /// The app's open edit (the draft of the next release).
826
+ Edits {
827
+ #[command(subcommand)]
828
+ command: AmazonEditsCommand,
829
+ },
830
+ /// APKs on the open edit.
831
+ Apks {
832
+ #[command(subcommand)]
833
+ command: AmazonApksCommand,
834
+ },
835
+ /// Device targeting per APK (Fire tablets, Fire TV).
836
+ Targeting {
837
+ #[command(subcommand)]
838
+ command: AmazonTargetingCommand,
839
+ },
840
+}
841
+
842
+#[derive(Subcommand)]
843
+enum AmazonEditsCommand {
844
+ /// Print the open edit; prints `null` when there is none.
845
+ Get { app_id: String },
846
+ /// Open an edit; returns the existing one when there is already one.
847
+ Create { app_id: String },
848
+ /// Ask Amazon to validate the open edit. Submitting stays in the console.
849
+ Validate { app_id: String },
850
+ /// Discard the open edit.
851
+ Delete { app_id: String },
852
+}
853
+
854
+#[derive(Subcommand)]
855
+enum AmazonApksCommand {
856
+ /// List the edit's APKs.
857
+ List { app_id: String },
858
+ /// Upload an APK, or replace the edit's APK (ETag + If-Match) when it has one.
859
+ Upload {
860
+ app_id: String,
861
+ /// The signed .apk.
862
+ file: PathBuf,
863
+ },
864
+ /// Remove an APK from the edit.
865
+ Delete { app_id: String, apk_id: String },
866
+}
867
+
868
+#[derive(Subcommand)]
869
+enum AmazonTargetingCommand {
870
+ /// Print an APK's targeting.
871
+ Get { app_id: String, apk_id: String },
872
+ /// Replace an APK's targeting with a JSON document (read it with `get`
873
+ /// first and change only the fields you mean to). The result is read back.
874
+ Set {
875
+ app_id: String,
876
+ apk_id: String,
877
+ /// Path to the JSON document.
878
+ #[arg(long)]
879
+ file: PathBuf,
880
+ },
881
+}
882
+
883
#[derive(Subcommand)]
884
#[allow(clippy::large_enum_variant)]
885
enum MsStoreCommand {
@@ -963,6 +1023,18 @@ enum Command {
1023
#[command(subcommand)]
1024
command: PlayCommand,
1025
},
1026
+ /// Amazon Appstore (Fire tablets, Fire TV): edits, APKs and device
1027
+ /// targeting. Uses a Login with Amazon Security Profile, not the App
1028
+ /// Store Connect key. There is no submit: do that in the console.
1029
+ Amazon {
1030
+ /// JSON file `{"client_id": …, "client_secret": …}`. Falls back to
1031
+ /// `AMAZON_APPSTORE_CREDENTIALS_JSON_PATH`, then to the contents in
1032
+ /// `AMAZON_APPSTORE_CREDENTIALS_JSON`.
1033
+ #[arg(long, global = true)]
1034
+ credentials: Option<PathBuf>,
1035
+ #[command(subcommand)]
1036
+ command: AmazonCommand,
1037
+ },
1038
/// Microsoft Store listings: text on the app's pending submission. Uses
1039
/// Partner Center API credentials, not the App Store Connect key.
1040
Msstore {
@@ -1317,6 +1389,75 @@ fn lines_arg(file: Option<PathBuf>, flag: &str) -> Result<Option<Vec<String>>> {
1389
))
1390
}
1391
1392
+async fn run_amazon(
1393
+ credentials: Option<&std::path::Path>,
1394
+ command: AmazonCommand,
1395
+ dry_run: bool,
1396
+) -> Result<()> {
1397
+ use smbcloud_ascapi_frontend::amazon;
1398
+ let client = amazon::amazon_client(credentials).map_err(|e| anyhow::anyhow!(e))?;
1399
+ let fail = |e: String| anyhow::anyhow!(e);
1400
+ match command {
1401
+ AmazonCommand::Edits { command } => match command {
1402
+ AmazonEditsCommand::Get { app_id } => {
1403
+ print_json(&amazon::edit_get(&client, &app_id).await.map_err(fail)?)
1404
+ }
1405
+ AmazonEditsCommand::Create { app_id } => print_json(
1406
+ &amazon::edit_create(&client, &app_id, dry_run)
1407
+ .await
1408
+ .map_err(fail)?,
1409
+ ),
1410
+ AmazonEditsCommand::Validate { app_id } => print_json(
1411
+ &amazon::edit_validate(&client, &app_id)
1412
+ .await
1413
+ .map_err(fail)?,
1414
+ ),
1415
+ AmazonEditsCommand::Delete { app_id } => print_json(
1416
+ &amazon::edit_delete(&client, &app_id, dry_run)
1417
+ .await
1418
+ .map_err(fail)?,
1419
+ ),
1420
+ },
1421
+ AmazonCommand::Apks { command } => match command {
1422
+ AmazonApksCommand::List { app_id } => {
1423
+ print_json(&amazon::apk_list(&client, &app_id).await.map_err(fail)?)
1424
+ }
1425
+ AmazonApksCommand::Upload { app_id, file } => print_json(
1426
+ &amazon::apk_upload(&client, &app_id, &file, dry_run)
1427
+ .await
1428
+ .map_err(fail)?,
1429
+ ),
1430
+ AmazonApksCommand::Delete { app_id, apk_id } => print_json(
1431
+ &amazon::apk_delete(&client, &app_id, &apk_id, dry_run)
1432
+ .await
1433
+ .map_err(fail)?,
1434
+ ),
1435
+ },
1436
+ AmazonCommand::Targeting { command } => match command {
1437
+ AmazonTargetingCommand::Get { app_id, apk_id } => print_json(
1438
+ &amazon::targeting_get(&client, &app_id, &apk_id)
1439
+ .await
1440
+ .map_err(fail)?,
1441
+ ),
1442
+ AmazonTargetingCommand::Set {
1443
+ app_id,
1444
+ apk_id,
1445
+ file,
1446
+ } => {
1447
+ let text = std::fs::read_to_string(&file)
1448
+ .with_context(|| format!("reading {}", file.display()))?;
1449
+ let document: serde_json::Value = serde_json::from_str(&text)
1450
+ .with_context(|| format!("{} is not valid JSON", file.display()))?;
1451
+ print_json(
1452
+ &amazon::targeting_set(&client, &app_id, &apk_id, document, dry_run)
1453
+ .await
1454
+ .map_err(fail)?,
1455
+ )
1456
+ }
1457
+ },
1458
+ }
1459
+}
1460
+
1461
async fn run_msstore(
1462
env_path: Option<&std::path::Path>,
1463
command: MsStoreCommand,
@@ -3193,6 +3334,14 @@ async fn main() -> Result<()> {
3334
return run_play(play_service_account.as_deref(), command, cli.dry_run).await;
3335
}
3336
3337
+ if let Some(Command::Amazon {
3338
+ credentials,
3339
+ command,
3340
+ }) = cli.command
3341
+ {
3342
+ return run_amazon(credentials.as_deref(), command, cli.dry_run).await;
3343
+ }
3344
+
3345
if let Some(Command::Msstore {
3346
msstore_env,
3347
command,
@@ -3233,6 +3382,7 @@ async fn main() -> Result<()> {
3382
3383
match command {
3384
Command::AppGallery { .. }
3385
+ | Command::Amazon { .. }
3386
| Command::Msstore { .. }
3387
| Command::Play { .. }
3388
| Command::Admob { .. } => {
crates/frontend/Cargo.toml
+1
@@ -18,6 +18,7 @@ serde = { workspace = true, features = ["derive"] }
18
serde_json = { workspace = true }
19
sha2 = "0.10"
20
smbcloud-ascapi-admob = { workspace = true }
21
+smbcloud-ascapi-amazon = { workspace = true }
22
smbcloud-ascapi-appgallery = { workspace = true }
23
smbcloud-ascapi-aso = { workspace = true }
24
smbcloud-ascapi-msstore = { workspace = true }
crates/frontend/src/amazon.rs
new
+235
@@ -0,0 +1,235 @@
1
+//! Amazon Appstore operations shared by `asc amazon` and the MCP tools.
2
+//!
3
+//! Nothing here commits an edit: submitting for review stays a human action
4
+//! in the Developer Console.
5
+
6
+use std::path::Path;
7
+
8
+use serde::Serialize;
9
+use serde_json::Value;
10
+use sha2::{Digest, Sha256};
11
+use smbcloud_ascapi_amazon::{AmazonClient, Credentials, Edit};
12
+
13
+/// Resolve the client. `path` wins; then `AMAZON_APPSTORE_CREDENTIALS_JSON_PATH`;
14
+/// then the contents inline in `AMAZON_APPSTORE_CREDENTIALS_JSON`. Per call, so
15
+/// an unconfigured MCP server still lists its tools. The secret never appears
16
+/// in an error.
17
+pub fn amazon_client(path: Option<&Path>) -> Result<AmazonClient, String> {
18
+ let credentials = if let Some(path) = path {
19
+ Credentials::from_json_file(path)
20
+ } else if let Ok(path) = std::env::var("AMAZON_APPSTORE_CREDENTIALS_JSON_PATH") {
21
+ Credentials::from_json_file(path)
22
+ } else if let Ok(json) = std::env::var("AMAZON_APPSTORE_CREDENTIALS_JSON") {
23
+ Credentials::from_json(&json)
24
+ } else {
25
+ return Err(
26
+ "no Amazon Appstore credentials: pass --credentials, or set \
27
+ AMAZON_APPSTORE_CREDENTIALS_JSON_PATH (or AMAZON_APPSTORE_CREDENTIALS_JSON)"
28
+ .to_string(),
29
+ );
30
+ }
31
+ .map_err(|e| e.to_string())?;
32
+ Ok(AmazonClient::new(credentials))
33
+}
34
+
35
+fn err(error: impl std::fmt::Display) -> String {
36
+ error.to_string()
37
+}
38
+
39
+/// The open edit, or an error naming the remedy when there is none.
40
+pub async fn open_edit(client: &AmazonClient, app_id: &str) -> Result<Edit, String> {
41
+ client.get_edit(app_id).await.map_err(err)?.ok_or_else(|| {
42
+ format!("app {app_id} has no open edit; run `asc amazon edits create {app_id}`")
43
+ })
44
+}
45
+
46
+pub async fn edit_get(client: &AmazonClient, app_id: &str) -> Result<Option<Edit>, String> {
47
+ client.get_edit(app_id).await.map_err(err)
48
+}
49
+
50
+pub async fn apk_list(client: &AmazonClient, app_id: &str) -> Result<Value, String> {
51
+ let edit = open_edit(client, app_id).await?;
52
+ client.list_apks(app_id, &edit.id).await.map_err(err)
53
+}
54
+
55
+#[derive(Debug, Serialize)]
56
+pub struct UploadPlan {
57
+ pub dry_run: bool,
58
+ pub app_id: String,
59
+ pub edit_id: String,
60
+ pub file: String,
61
+ pub bytes: u64,
62
+ pub sha256: String,
63
+ /// `upload` when the edit has no APK, `replace` when it has one.
64
+ pub action: &'static str,
65
+ pub existing_apk_id: Option<String>,
66
+ /// The API reply; `None` on a dry run.
67
+ pub result: Option<Value>,
68
+}
69
+
70
+fn sha256_file(path: &Path) -> Result<(u64, String), String> {
71
+ let bytes = std::fs::read(path).map_err(|e| format!("reading {}: {e}", path.display()))?;
72
+ let digest = Sha256::digest(&bytes);
73
+ let hex: String = digest.iter().map(|b| format!("{b:02x}")).collect();
74
+ Ok((bytes.len() as u64, hex))
75
+}
76
+
77
+fn first_apk_id(list: &Value) -> Option<String> {
78
+ let items = list.as_array().or_else(|| list.get("apks")?.as_array())?;
79
+ items.first()?.get("id")?.as_str().map(str::to_string)
80
+}
81
+
82
+/// Upload the APK to the open edit; when the edit already has one, replace it
83
+/// (Amazon allows one APK per edit slot here, and replace keeps its targeting).
84
+pub async fn apk_upload(
85
+ client: &AmazonClient,
86
+ app_id: &str,
87
+ apk: &Path,
88
+ dry_run: bool,
89
+) -> Result<UploadPlan, String> {
90
+ let (bytes, sha256) = sha256_file(apk)?;
91
+ let edit = open_edit(client, app_id).await?;
92
+ let existing = first_apk_id(&client.list_apks(app_id, &edit.id).await.map_err(err)?);
93
+ let action = if existing.is_some() {
94
+ "replace"
95
+ } else {
96
+ "upload"
97
+ };
98
+ let mut plan = UploadPlan {
99
+ dry_run,
100
+ app_id: app_id.to_string(),
101
+ edit_id: edit.id.clone(),
102
+ file: apk.display().to_string(),
103
+ bytes,
104
+ sha256,
105
+ action,
106
+ existing_apk_id: existing.clone(),
107
+ result: None,
108
+ };
109
+ if dry_run {
110
+ return Ok(plan);
111
+ }
112
+ plan.result = Some(match existing {
113
+ Some(apk_id) => {
114
+ let etag = client
115
+ .apk_etag(app_id, &edit.id, &apk_id)
116
+ .await
117
+ .map_err(err)?;
118
+ client
119
+ .replace_apk(app_id, &edit.id, &apk_id, &etag, apk)
120
+ .await
121
+ .map_err(err)?
122
+ }
123
+ None => client
124
+ .upload_apk(app_id, &edit.id, apk)
125
+ .await
126
+ .map_err(err)?,
127
+ });
128
+ Ok(plan)
129
+}
130
+
131
+pub async fn apk_delete(
132
+ client: &AmazonClient,
133
+ app_id: &str,
134
+ apk_id: &str,
135
+ dry_run: bool,
136
+) -> Result<Value, String> {
137
+ let edit = open_edit(client, app_id).await?;
138
+ if !dry_run {
139
+ client
140
+ .delete_apk(app_id, &edit.id, apk_id)
141
+ .await
142
+ .map_err(err)?;
143
+ }
144
+ Ok(serde_json::json!({"dry_run": dry_run, "edit_id": edit.id, "deleted_apk_id": apk_id}))
145
+}
146
+
147
+pub async fn targeting_get(
148
+ client: &AmazonClient,
149
+ app_id: &str,
150
+ apk_id: &str,
151
+) -> Result<Value, String> {
152
+ let edit = open_edit(client, app_id).await?;
153
+ client
154
+ .get_targeting(app_id, &edit.id, apk_id)
155
+ .await
156
+ .map_err(err)
157
+}
158
+
159
+/// Put a targeting document for an APK, then read it back.
160
+pub async fn targeting_set(
161
+ client: &AmazonClient,
162
+ app_id: &str,
163
+ apk_id: &str,
164
+ targeting: Value,
165
+ dry_run: bool,
166
+) -> Result<Value, String> {
167
+ let edit = open_edit(client, app_id).await?;
168
+ let before = client
169
+ .get_targeting(app_id, &edit.id, apk_id)
170
+ .await
171
+ .map_err(err)?;
172
+ if dry_run {
173
+ return Ok(serde_json::json!({"dry_run": true, "before": before, "sent": targeting}));
174
+ }
175
+ client
176
+ .put_targeting(app_id, &edit.id, apk_id, &targeting)
177
+ .await
178
+ .map_err(err)?;
179
+ let after = client
180
+ .get_targeting(app_id, &edit.id, apk_id)
181
+ .await
182
+ .map_err(err)?;
183
+ Ok(serde_json::json!({"dry_run": false, "before": before, "after": after}))
184
+}
185
+
186
+pub async fn edit_create(
187
+ client: &AmazonClient,
188
+ app_id: &str,
189
+ dry_run: bool,
190
+) -> Result<Value, String> {
191
+ if let Some(edit) = client.get_edit(app_id).await.map_err(err)? {
192
+ return Ok(serde_json::json!({"dry_run": dry_run, "created": false, "edit": edit}));
193
+ }
194
+ if dry_run {
195
+ return Ok(serde_json::json!({"dry_run": true, "created": false, "would_create": true}));
196
+ }
197
+ let edit = client.create_edit(app_id).await.map_err(err)?;
198
+ Ok(serde_json::json!({"dry_run": false, "created": true, "edit": edit}))
199
+}
200
+
201
+pub async fn edit_validate(client: &AmazonClient, app_id: &str) -> Result<Value, String> {
202
+ let edit = open_edit(client, app_id).await?;
203
+ let reply = client.validate_edit(app_id, &edit.id).await.map_err(err)?;
204
+ Ok(serde_json::json!({"edit_id": edit.id, "validation": reply}))
205
+}
206
+
207
+pub async fn edit_delete(
208
+ client: &AmazonClient,
209
+ app_id: &str,
210
+ dry_run: bool,
211
+) -> Result<Value, String> {
212
+ let edit = open_edit(client, app_id).await?;
213
+ if !dry_run {
214
+ client.delete_edit(app_id, &edit.id).await.map_err(err)?;
215
+ }
216
+ Ok(serde_json::json!({"dry_run": dry_run, "deleted_edit_id": edit.id}))
217
+}
218
+
219
+#[cfg(test)]
220
+mod tests {
221
+ use super::*;
222
+
223
+ #[test]
224
+ fn first_apk_id_reads_a_bare_array_or_an_apks_wrapper() {
225
+ assert_eq!(
226
+ first_apk_id(&serde_json::json!([{"id": "a1"}])).as_deref(),
227
+ Some("a1")
228
+ );
229
+ assert_eq!(
230
+ first_apk_id(&serde_json::json!({"apks": [{"id": "a2"}]})).as_deref(),
231
+ Some("a2")
232
+ );
233
+ assert_eq!(first_apk_id(&serde_json::json!([])), None);
234
+ }
235
+}
crates/frontend/src/lib.rs
+1
@@ -21,6 +21,7 @@
21
//! it wrote instead.
22
23
pub mod admob;
24
+pub mod amazon;
25
pub mod appgallery;
26
pub mod attach_build;
27
pub mod await_processing;
crates/mcp/src/lib.rs
+47
-1
@@ -80,7 +80,9 @@ macro_rules! ascapi_mcp_tools {
80
$appgallery_package_status_name:literal,
81
$msstore_app_get_name:literal,
82
$msstore_submission_status_name:literal,
83
- $msstore_listing_get_name:literal
83
+ $msstore_listing_get_name:literal,
84
+ $amazon_edit_get_name:literal,
85
+ $amazon_apk_list_name:literal
86
) => {
87
#[::rmcp::tool_router(router = ascapi_tool_router, vis = "pub(crate)")]
88
impl $server {
@@ -1229,6 +1231,50 @@ macro_rules! ascapi_mcp_tools {
1231
::rmcp::model::ContentBlock::json(&value)?,
1232
]))
1233
}
1234
+
1235
+ #[::rmcp::tool(
1236
+ name = $amazon_edit_get_name,
1237
+ title = "Get the Amazon Appstore open edit",
1238
+ annotations(title = "Get the Amazon Appstore open edit", read_only_hint = true, idempotent_hint = true),
1239
+ description = "Purpose: read the open edit (the draft of the next release) of an Amazon Appstore app, or null when there is none. When to use vs siblings: amazon_apk_list lists the APKs on that edit. Behavior: GET edits, nothing changes. Prerequisites: a Login with Amazon Security Profile credential file ({client_id, client_secret}) at AMAZON_APPSTORE_CREDENTIALS_JSON_PATH or its contents in AMAZON_APPSTORE_CREDENTIALS_JSON, with App Submission API access enabled. Failure modes: missing credentials return an invalid-request error naming what is absent; an Amazon HTTP error is returned verbatim with its status. Limitations: read-only; uploading, targeting and validating go through asc amazon on the command line, and submitting stays in the Developer Console."
1240
+ )]
1241
+ async fn amazon_edit_get(
1242
+ &self,
1243
+ parameters: ::rmcp::handler::server::wrapper::Parameters<$crate::AmazonAppRequest>,
1244
+ ) -> ::std::result::Result<::rmcp::model::CallToolResult, ::rmcp::model::ErrorData> {
1245
+ use ::smbcloud_ascapi_frontend::amazon;
1246
+ let client = amazon::amazon_client(None)
1247
+ .map_err(|error| ::rmcp::model::ErrorData::invalid_request(error, None))?;
1248
+ let request = parameters.0;
1249
+ let value = amazon::edit_get(&client, &request.app_id)
1250
+ .await
1251
+ .map_err(|error| ::rmcp::model::ErrorData::internal_error(error, None))?;
1252
+ Ok(::rmcp::model::CallToolResult::success(vec![
1253
+ ::rmcp::model::ContentBlock::json(&value)?,
1254
+ ]))
1255
+ }
1256
+
1257
+ #[::rmcp::tool(
1258
+ name = $amazon_apk_list_name,
1259
+ title = "List Amazon Appstore APKs",
1260
+ annotations(title = "List Amazon Appstore APKs", read_only_hint = true, idempotent_hint = true),
1261
+ description = "Purpose: list the APKs on an Amazon Appstore app's open edit with their id, version code and name. When to use vs siblings: amazon_edit_get reads the edit itself. Behavior: GET edits/{id}/apks on the open edit, nothing changes. Prerequisites: a Login with Amazon Security Profile credential file ({client_id, client_secret}) at AMAZON_APPSTORE_CREDENTIALS_JSON_PATH or its contents in AMAZON_APPSTORE_CREDENTIALS_JSON, with App Submission API access enabled. Failure modes: missing credentials return an invalid-request error naming what is absent; an Amazon HTTP error is returned verbatim with its status. Limitations: read-only; fails when the app has no open edit."
1262
+ )]
1263
+ async fn amazon_apk_list(
1264
+ &self,
1265
+ parameters: ::rmcp::handler::server::wrapper::Parameters<$crate::AmazonAppRequest>,
1266
+ ) -> ::std::result::Result<::rmcp::model::CallToolResult, ::rmcp::model::ErrorData> {
1267
+ use ::smbcloud_ascapi_frontend::amazon;
1268
+ let client = amazon::amazon_client(None)
1269
+ .map_err(|error| ::rmcp::model::ErrorData::invalid_request(error, None))?;
1270
+ let request = parameters.0;
1271
+ let value = amazon::apk_list(&client, &request.app_id)
1272
+ .await
1273
+ .map_err(|error| ::rmcp::model::ErrorData::internal_error(error, None))?;
1274
+ Ok(::rmcp::model::CallToolResult::success(vec![
1275
+ ::rmcp::model::ContentBlock::json(&value)?,
1276
+ ]))
1277
+ }
1278
}
1279
};
1280
}
crates/mcp/src/requests.rs
+6
@@ -363,3 +363,9 @@ pub struct MsStoreListingGetRequest {
363
/// Listing locale, e.g. en-us.
364
pub locale: String,
365
}
366
+
367
+#[derive(Debug, Clone, Deserialize, schemars::JsonSchema)]
368
+pub struct AmazonAppRequest {
369
+ /// Amazon Appstore app id, e.g. amzn1.devportal.mobileapp.<hex>.
370
+ pub app_id: String,
371
+}
crates/mcp/src/server.rs
+6
-2
@@ -70,7 +70,9 @@ ascapi_mcp_tools!(
70
"appgallery_package_status",
71
"msstore_app_get",
72
"msstore_submission_status",
73
- "msstore_listing_get"
73
+ "msstore_listing_get",
74
+ "amazon_edit_get",
75
+ "amazon_apk_list"
76
);
77
78
#[rmcp::tool_handler(router = Self::ascapi_tool_router())]
@@ -119,7 +121,7 @@ mod tests {
121
/// The canonical tool names. Adding or renaming one is a
122
/// public-contract change, and this list is what makes that
123
/// deliberate rather than accidental.
122
- const CANONICAL_TOOL_NAMES: [&str; 42] = [
124
+ const CANONICAL_TOOL_NAMES: [&str; 44] = [
125
"app_list",
126
"app_get",
127
"app_update",
@@ -162,6 +164,8 @@ mod tests {
164
"msstore_app_get",
165
"msstore_submission_status",
166
"msstore_listing_get",
167
+ "amazon_edit_get",
168
+ "amazon_apk_list",
169
];
170
171
/// Never a tool, at any point, for any caller.
docs/README.md
+1
-1
@@ -1,3 +1,3 @@
1
# Docs
2
3
-[Install](install.md) · [Credentials](credentials.md) · [AppGallery](appgallery.md) · [New app on Google Play](google-play-new-app.md) · [Architecture](architecture.md)
3
+[Install](install.md) · [Credentials](credentials.md) · [AppGallery](appgallery.md) · [Amazon](amazon.md) · [New app on Google Play](google-play-new-app.md) · [Architecture](architecture.md)
docs/amazon.md
new
+21
@@ -0,0 +1,21 @@
1
+# Amazon Appstore
2
+
3
+`asc amazon` uses a Login with Amazon Security Profile with App Submission API
4
+access enabled. Save `{"client_id": "...", "client_secret": "..."}` to a file
5
+and point `AMAZON_APPSTORE_CREDENTIALS_JSON_PATH` at it (or pass
6
+`--credentials`). The token is requested with `client_credentials` and scope
7
+`appstore::apps:readwrite`. The secret is never printed.
8
+
9
+```bash
10
+asc amazon edits get <APP_ID> # the open edit, or null
11
+asc amazon edits create <APP_ID>
12
+asc amazon apks upload <APP_ID> app.apk # replaces (ETag) when the edit already has an APK
13
+asc amazon apks list <APP_ID>
14
+asc amazon targeting get <APP_ID> <APK_ID>
15
+asc amazon targeting set <APP_ID> <APK_ID> --file targeting.json
16
+asc amazon edits validate <APP_ID>
17
+```
18
+
19
+Every write honors `--dry-run`. There is no submit: review the edit and submit
20
+it in the Developer Console. Targeting documents are passed through as Amazon
21
+returns them, so read with `get`, change the fields you mean to, then `set`.
docs/architecture.md
+2
-1
@@ -7,6 +7,7 @@ from the other:
7
| --- | --- |
8
| `smbcloud-ascapi-core` | Shared transport: JWT auth, the HTTP client, JSON:API envelopes, error types |
9
| `smbcloud-ascapi-play` | Google Play (Edits v3): store listings, listing images, track release notes; service-account auth, independent of `core` |
10
+| `smbcloud-ascapi-amazon` | Amazon Appstore App Submission API (Fire tablets, Fire TV): Login with Amazon client-credentials auth, the open edit, APK upload and replace (ETag), device targeting, validate; no commit, independent of `core` |
11
| `smbcloud-ascapi-appgallery` | Huawei AppGallery Connect Publishing API (Android): app info and listings, file and package upload, submit, phased release, release time, GMS flag, package list and status; Service Account auth (PS256 JWT), independent of `core` |
12
| `smbcloud-ascapi-msstore` | Microsoft Store submission API v1.0: listing text on an MSIX app's pending submission; Entra client-credentials auth, independent of `core` |
13
| `smbcloud-ascapi-aso` | App Metadata: apps, app infos, versions, builds, pre-release versions, review submissions, bundle IDs, localizations, screenshots |
@@ -17,7 +18,7 @@ from the other:
18
| `smbcloud-ascapi-mcp` | The MCP contract and stdio server |
19
| `smbcloud-ascapi-cli` | The `asc` binary: clap command tree, plus `--mcp` |
20
20
-`aso`, `play`, `appgallery`, `msstore`, `pricing`, `signing` and `reports` know nothing about each other, and neither knows
21
+`aso`, `play`, `appgallery`, `amazon`, `msstore`, `pricing`, `signing` and `reports` know nothing about each other, and neither knows
22
anything about the front ends. Each adds its calls to
23
`smbcloud_ascapi_core::Client` as **extension traits**, since Rust only
24
allows inherent impls in the crate that defines a type: