Repository navigation
product.js: --file and --get, for games with more than one product - #210
Conversation
…ames with more than one product
| // --file: a whole product body of the game's own; --get: read one product. | ||
| const BODY_FILE = argument('--file'); | ||
| const GET = argument('--get'); | ||
| const PRODUCT_FILE = path.join(HERE, 'Monetization', 'iap', `${SOURCE.product.productId}.json`); |
There was a problem hiding this comment.
--get and --file don't need listing.json's product, but this line still reads SOURCE.product.productId before either mode runs. For a game whose listing.json has only package (no single product), which is the case these modes are for, both crash right away with TypeError: Cannot read properties of undefined (reading 'productId'). I reproduced this with {"package": "com.example.game"} and both --get com.example.a and --file a.json. Only compute PRODUCT_FILE when neither flag is given (or use SOURCE.product?.productId), so the new modes depend on package alone.
There was a problem hiding this comment.
Fixed in 5e4f733. The one product's file is now computed only when neither --get nor --file is given, so both modes need only package. New tests run both against a listing.json that holds only package.
|
Claude review (house rules) |
| if (!(product.listings ?? []).length) { | ||
| if (!exists) problems.push('a new product needs listings'); | ||
| else product.listings = existing.body.listings ?? []; | ||
| } |
There was a problem hiding this comment.
This crashes on a --file body that has no listings key, when the product is new. The !exists branch adds the problem but leaves product.listings undefined. The next line, product.listings.length (L172), then throws Cannot read properties of undefined (reading 'length'). So the run exits before it prints the problems list, and "a new product needs listings" never shows. I reproduced this with the stubbed Play from product.test.js: the output is Product … missing, would be created and then that TypeError. Nothing gets sent, but the refusal the PR describes never appears.
spritekit-android/Tools/Pricing/product.js
Lines 166 to 173 in 70a034d
| if (!(product.listings ?? []).length) { | |
| if (!exists) problems.push('a new product needs listings'); | |
| else product.listings = existing.body.listings ?? []; | |
| } | |
| if (!(product.listings ?? []).length) { | |
| if (!exists) problems.push('a new product needs listings'); | |
| product.listings = exists ? existing.body.listings ?? [] : []; | |
| } |
There was a problem hiding this comment.
Fixed in 5e4f733, with your suggestion. A new test sends a body with no listings: the run exits with 'a new product needs listings' and 'nothing was sent', and makes no PATCH.
…body without listings is refused, not a crash
Switchlings now sells nine world products beside its full game (fleon/switchlings#556). Its price tool needed to read any product and send a whole product body, so it had copied this tool's auth and Publisher API calls into the game. This PR adds those two modes here instead, so the game can drop its copy.
--get <productId>prints the product as Play holds it (JSON), or{"missing": true}. It only reads.--file <body.json> [--send|--verify]runs the existing plan, send and verify steps on a whole oneTimeProduct body, in place oflisting.json's one product file. A product that already exists keeps its listings when the body has none. A new product with no listings is refused.Without these flags the tool behaves as before. I checked it read-only on Switchlings:
--geton an existing product and on a missing one, and--fileproducing a plan.product.test.jspasses.