Read-only mirror of github.com/smbcloudXYZ/smbcloud-ascapi.
Mirrored from https://github.com/smbcloudXYZ/smbcloud-ascapi.git
Synced Nov 25, 09:15 UTC
Report a created-but-inactive product, and page through every product
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.6 <noreply@sigit.si>
Seto Elkahfi committed
Nov 8, 2026 at 13:58 UTC
f907d916be39a9f81cb3a88eded6f08aa27d629f
2 files changed
+37
-17
crates/frontend/src/play.rs
+10
-2
@@ -636,8 +636,16 @@ pub async fn create_product(
636
client
637
.activate_purchase_option(package, id, &product.purchase_option_id)
638
.await
639
- .map_err(err)?;
640
- let stored = client.get_product(package, id).await.map_err(err)?;
639
+ .map_err(|e| {
640
+ format!(
641
+ "created {id}, but activating its purchase option failed: {}",
642
+ err(e)
643
+ )
644
+ })?;
645
+ let stored = client
646
+ .get_product(package, id)
647
+ .await
648
+ .map_err(|e| format!("created {id}, but reading it back failed: {}", err(e)))?;
649
let state = stored
650
.pointer("/purchaseOptions/0/state")
651
.and_then(|v| v.as_str());
crates/play/src/client.rs
+27
-15
@@ -270,23 +270,35 @@ impl PlayClient {
270
Ok(deleted.deleted.len())
271
}
272
273
- /// All one-time products of the app, as Play returns them.
273
+ /// All one-time products of the app, as Play returns them, following
274
+ /// `nextPageToken` so an app with more than one page is not truncated.
275
pub async fn list_products(&self, package: &str) -> Result<Vec<serde_json::Value>> {
275
- // An app with no products can answer with an empty body, not `{}`.
276
- let text = self
277
- .send(Method::GET, &products_path(package, ""), None)
278
- .await?
279
- .text()
280
- .await?;
281
- if text.trim().is_empty() {
282
- return Ok(Vec::new());
276
+ let mut products = Vec::new();
277
+ let mut page_token: Option<String> = None;
278
+ loop {
279
+ let suffix = match &page_token {
280
+ Some(token) => format!("?pageToken={token}"),
281
+ None => String::new(),
282
+ };
283
+ // An app with no products can answer with an empty body, not `{}`.
284
+ let text = self
285
+ .send(Method::GET, &products_path(package, &suffix), None)
286
+ .await?
287
+ .text()
288
+ .await?;
289
+ if text.trim().is_empty() {
290
+ break;
291
+ }
292
+ let page: serde_json::Value = serde_json::from_str(&text)?;
293
+ if let Some(items) = page.get("oneTimeProducts").and_then(|v| v.as_array()) {
294
+ products.extend(items.iter().cloned());
295
+ }
296
+ match page.get("nextPageToken").and_then(|v| v.as_str()) {
297
+ Some(token) if !token.is_empty() => page_token = Some(token.to_string()),
298
+ _ => break,
299
+ }
300
}
284
- let page: serde_json::Value = serde_json::from_str(&text)?;
285
- Ok(page
286
- .get("oneTimeProducts")
287
- .and_then(|v| v.as_array())
288
- .cloned()
289
- .unwrap_or_default())
301
+ Ok(products)
302
}
303
304
pub async fn get_product(&self, package: &str, product_id: &str) -> Result<serde_json::Value> {