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 in-app-purchases promotional-image
Uploads the optional 1024x1024 image the App Store shows for a product, using the same reserve, PUT and commit sequence as the review screenshot and the shared chunk helper. A product can hold several images, so --replace deletes the existing ones first. get now lists them under promotionalImages. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.6 <noreply@sigit.si>
Seto Elkahfi committed
Nov 4, 2026 at 19:02 UTC
9dd529f992cadc8423cf8d22e52efafcf95947c9
5 files changed
+235
-1
.agents/AGENTS.md
+1
@@ -91,6 +91,7 @@ asc in-app-purchases price-points <IAP_ID> [--territory USA]
91
asc in-app-purchases set-price <IAP_ID> --price 4.99 [--territory USA]
92
asc in-app-purchases set-availability <IAP_ID> (--all-territories | --territory SWE …) [--no-new-territories]
93
asc in-app-purchases review-screenshot <IAP_ID> paywall.png [--replace]
94
+asc in-app-purchases promotional-image <IAP_ID> unlock.png [--replace] # optional 1024x1024 store image
95
```
96
97
- Every write honours the global `--dry-run` and reads the result back,
crates/cli/src/main.rs
+50
@@ -1953,6 +1953,15 @@ enum InAppPurchasesCommand {
1953
#[arg(long)]
1954
replace: bool,
1955
},
1956
+ /// Upload the 1024x1024 promotional image the App Store shows for the
1957
+ /// product. A product can hold several; --replace deletes the existing
1958
+ /// ones first.
1959
+ PromotionalImage {
1960
+ id: String,
1961
+ path: PathBuf,
1962
+ #[arg(long)]
1963
+ replace: bool,
1964
+ },
1965
}
1966
1967
#[derive(Subcommand)]
@@ -3760,12 +3769,14 @@ async fn run_in_app_purchases(
3769
let manual_prices = client.list_manual_prices(&id).await?;
3770
let availability = client.get_in_app_purchase_availability(&id).await?;
3771
let screenshot = client.get_review_screenshot(&id).await?;
3772
+ let images = client.list_promotional_images(&id).await?;
3773
print_json(&serde_json::json!({
3774
"product": product,
3775
"localizations": localizations,
3776
"manualPrices": manual_prices,
3777
"availability": availability,
3778
"reviewScreenshot": screenshot,
3779
+ "promotionalImages": images,
3780
}))
3781
}
3782
InAppPurchasesCommand::Create {
@@ -4045,6 +4056,45 @@ async fn run_in_app_purchases(
4056
}
4057
print_json(&back)
4058
}
4059
+ InAppPurchasesCommand::PromotionalImage { id, path, replace } => {
4060
+ let bytes =
4061
+ std::fs::read(&path).with_context(|| format!("cannot read {}", path.display()))?;
4062
+ let file_name = path
4063
+ .file_name()
4064
+ .and_then(|n| n.to_str())
4065
+ .context("the image path has no file name")?
4066
+ .to_string();
4067
+ let existing = client.list_promotional_images(&id).await?;
4068
+ if dry_run {
4069
+ println!(
4070
+ "# dry run: would {}upload {file_name} ({} bytes) as a promotional image of {id}",
4071
+ if existing.is_empty() { "" } else { "delete the current images and " },
4072
+ bytes.len()
4073
+ );
4074
+ return Ok(());
4075
+ }
4076
+ if !existing.is_empty() && !replace {
4077
+ anyhow::bail!(
4078
+ "{id} already has {} promotional image(s); pass --replace",
4079
+ existing.len()
4080
+ );
4081
+ }
4082
+ for old in &existing {
4083
+ client.delete_promotional_image(&old.id).await?;
4084
+ }
4085
+ let uploaded = client
4086
+ .upload_promotional_image(&id, file_name, bytes)
4087
+ .await?;
4088
+ let back = client.list_promotional_images(&id).await?;
4089
+ if !back.iter().any(|i| i.id == uploaded.id) {
4090
+ anyhow::bail!(
4091
+ "the image was committed but {} does not list it ({})",
4092
+ id,
4093
+ uploaded.id
4094
+ );
4095
+ }
4096
+ print_json(&back)
4097
+ }
4098
}
4099
}
4100
crates/iap/src/lib.rs
+5
@@ -14,6 +14,9 @@
14
//! 4. territory availability ([`availability`]);
15
//! 5. an App Review screenshot ([`review_screenshot`]).
16
//!
17
+//! A promotional image ([`promotional_image`]) is optional: it only feeds
18
+//! the App Store product page.
19
+//!
20
//! With those in place the product reaches `READY_TO_SUBMIT`. An app's
21
//! first in-app purchase is reviewed together with an app version, which is
22
//! done on the version page, so this crate has no submit call.
@@ -25,6 +28,7 @@ pub mod availability;
28
pub mod in_app_purchase;
29
pub mod localization;
30
pub mod price;
31
+pub mod promotional_image;
32
pub mod review_screenshot;
33
34
/// Every extension trait in this crate, for one glob import.
@@ -33,5 +37,6 @@ pub mod prelude {
37
pub use crate::in_app_purchase::InAppPurchasesApi;
38
pub use crate::localization::InAppPurchaseLocalizationsApi;
39
pub use crate::price::InAppPurchasePricesApi;
40
+ pub use crate::promotional_image::InAppPurchasePromotionalImageApi;
41
pub use crate::review_screenshot::InAppPurchaseReviewScreenshotApi;
42
}
crates/iap/src/promotional_image.rs
new
+178
@@ -0,0 +1,178 @@
1
+//! `inAppPurchaseImages`: the 1024x1024 promotional image the App Store
2
+//! shows for a product (product page, offer codes, payment sheet).
3
+//!
4
+//! The same reserve, PUT, commit sequence as the review screenshot, and the
5
+//! same upload operations. Unlike the screenshot a product can hold several
6
+//! images, so listing returns a `Vec`.
7
+
8
+use async_trait::async_trait;
9
+use reqwest::Method;
10
+use serde::{Deserialize, Serialize};
11
+use smbcloud_ascapi_core::jsonapi::{
12
+ CreateBody, CreateData, Document, Resource, ResourceId, ToOne, UpdateBody, UpdateData,
13
+};
14
+use smbcloud_ascapi_core::{Client, Result};
15
+
16
+use crate::review_screenshot::{null_as_default, upload_operations, UploadOperation};
17
+
18
+pub const RESOURCE_TYPE: &str = "inAppPurchaseImages";
19
+
20
+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
21
+#[serde(rename_all = "camelCase")]
22
+pub struct PromotionalImageAttributes {
23
+ #[serde(default)]
24
+ pub file_name: Option<String>,
25
+ #[serde(default)]
26
+ pub file_size: Option<u64>,
27
+ #[serde(default)]
28
+ pub source_file_checksum: Option<String>,
29
+ #[serde(default)]
30
+ pub state: Option<String>,
31
+ #[serde(default, deserialize_with = "null_as_default")]
32
+ pub upload_operations: Vec<UploadOperation>,
33
+}
34
+
35
+pub type PromotionalImage = Resource<PromotionalImageAttributes>;
36
+
37
+#[derive(Debug, Clone, Serialize)]
38
+#[serde(rename_all = "camelCase")]
39
+struct CreateAttributes {
40
+ file_name: String,
41
+ file_size: u64,
42
+}
43
+
44
+#[derive(Debug, Clone, Serialize)]
45
+#[serde(rename_all = "camelCase")]
46
+struct CreateRelationships {
47
+ in_app_purchase: ToOne,
48
+}
49
+
50
+#[derive(Debug, Clone, Serialize)]
51
+#[serde(rename_all = "camelCase")]
52
+struct CommitAttributes {
53
+ uploaded: bool,
54
+ source_file_checksum: String,
55
+}
56
+
57
+/// The reserve (`POST`) body.
58
+pub fn create_body(
59
+ in_app_purchase_id: &str,
60
+ file_name: &str,
61
+ file_size: u64,
62
+) -> impl Serialize + Send + Sync {
63
+ CreateBody {
64
+ data: CreateData {
65
+ resource_type: RESOURCE_TYPE,
66
+ attributes: CreateAttributes {
67
+ file_name: file_name.to_string(),
68
+ file_size,
69
+ },
70
+ relationships: Some(CreateRelationships {
71
+ in_app_purchase: ToOne {
72
+ data: ResourceId {
73
+ resource_type: crate::in_app_purchase::RESOURCE_TYPE,
74
+ id: in_app_purchase_id.to_string(),
75
+ },
76
+ },
77
+ }),
78
+ },
79
+ }
80
+}
81
+
82
+#[async_trait]
83
+pub trait InAppPurchasePromotionalImageApi {
84
+ /// `GET /v2/inAppPurchases/{id}/images`.
85
+ async fn list_promotional_images(
86
+ &self,
87
+ in_app_purchase_id: &str,
88
+ ) -> Result<Vec<PromotionalImage>>;
89
+
90
+ /// `DELETE /v1/inAppPurchaseImages/{id}`.
91
+ async fn delete_promotional_image(&self, id: &str) -> Result<()>;
92
+
93
+ /// Reserve, upload and commit `bytes` as a promotional image.
94
+ async fn upload_promotional_image(
95
+ &self,
96
+ in_app_purchase_id: &str,
97
+ file_name: String,
98
+ bytes: Vec<u8>,
99
+ ) -> Result<PromotionalImage>;
100
+}
101
+
102
+#[async_trait]
103
+impl InAppPurchasePromotionalImageApi for Client {
104
+ async fn list_promotional_images(
105
+ &self,
106
+ in_app_purchase_id: &str,
107
+ ) -> Result<Vec<PromotionalImage>> {
108
+ let path = format!("/v2/inAppPurchases/{in_app_purchase_id}/images");
109
+ self.list_all::<PromotionalImageAttributes>(&path, &[("limit", "200")])
110
+ .await
111
+ }
112
+
113
+ async fn delete_promotional_image(&self, id: &str) -> Result<()> {
114
+ let path = format!("/v1/inAppPurchaseImages/{id}");
115
+ self.request_no_content::<()>(Method::DELETE, &path, &[], None)
116
+ .await
117
+ }
118
+
119
+ async fn upload_promotional_image(
120
+ &self,
121
+ in_app_purchase_id: &str,
122
+ file_name: String,
123
+ bytes: Vec<u8>,
124
+ ) -> Result<PromotionalImage> {
125
+ let checksum = format!("{:x}", md5::compute(&bytes));
126
+ let body = create_body(in_app_purchase_id, &file_name, bytes.len() as u64);
127
+ let reserved: Document<PromotionalImageAttributes> = self
128
+ .request(Method::POST, "/v1/inAppPurchaseImages", &[], Some(&body))
129
+ .await?;
130
+ let reserved = reserved.data;
131
+
132
+ upload_operations(self, &reserved.attributes.upload_operations, &bytes).await?;
133
+
134
+ let path = format!("/v1/inAppPurchaseImages/{}", reserved.id);
135
+ let commit = UpdateBody {
136
+ data: UpdateData {
137
+ resource_type: RESOURCE_TYPE,
138
+ id: reserved.id.clone(),
139
+ attributes: CommitAttributes {
140
+ uploaded: true,
141
+ source_file_checksum: checksum,
142
+ },
143
+ },
144
+ };
145
+ let doc: Document<PromotionalImageAttributes> = self
146
+ .request(Method::PATCH, &path, &[], Some(&commit))
147
+ .await?;
148
+ Ok(doc.data)
149
+ }
150
+}
151
+
152
+#[cfg(test)]
153
+mod tests {
154
+ use super::*;
155
+
156
+ #[test]
157
+ fn the_reserve_body_names_the_product_relationship() {
158
+ let v = serde_json::to_value(create_body("IAP1", "unlock.png", 99)).unwrap();
159
+ assert_eq!(v["data"]["type"], "inAppPurchaseImages");
160
+ assert_eq!(v["data"]["attributes"]["fileName"], "unlock.png");
161
+ assert_eq!(v["data"]["attributes"]["fileSize"], 99);
162
+ assert_eq!(
163
+ v["data"]["relationships"]["inAppPurchase"]["data"]["id"],
164
+ "IAP1"
165
+ );
166
+ }
167
+
168
+ #[test]
169
+ fn a_committed_image_with_null_operations_deserializes() {
170
+ let doc: Document<PromotionalImageAttributes> = serde_json::from_value(serde_json::json!({
171
+ "data": { "id": "I1", "type": RESOURCE_TYPE,
172
+ "attributes": { "fileName": "unlock.png", "fileSize": 10,
173
+ "uploadOperations": null, "state": "PREPARE_FOR_SUBMISSION" } }
174
+ }))
175
+ .unwrap();
176
+ assert!(doc.data.attributes.upload_operations.is_empty());
177
+ }
178
+}
crates/iap/src/review_screenshot.rs
+1
-1
@@ -17,7 +17,7 @@ use smbcloud_ascapi_core::{Client, Error, Result};
17
pub const RESOURCE_TYPE: &str = "inAppPurchaseAppStoreReviewScreenshots";
18
19
/// Apple sends `null` for these lists once an asset is committed.
20
-fn null_as_default<'de, D, T>(deserializer: D) -> std::result::Result<T, D::Error>
20
+pub(crate) fn null_as_default<'de, D, T>(deserializer: D) -> std::result::Result<T, D::Error>
21
where
22
D: Deserializer<'de>,
23
T: Default + Deserialize<'de>,