// Store lists lag right after a create: App Store Connect's /inAppPurchasesV2 (and Play's oneTimeProducts list) can // leave out a product created a minute ago. A command that walks the store's list then silently skips it. These // helpers compare the config's product ids with what the store returned, so the gap is said out loud // (docs/pitfalls.md, "Store lists lag right after create"). import { warn } from './log'; export const LAG_HINT = "the store's list can lag a minute after creating; re-run"; /** Config ids the store's list does not contain, in config order. Pure. */ export function missingFromStore(want: string[], got: Iterable): string[] { const have = new Set(got); return [...new Set(want)].filter(id => !have.has(id)); } /** * Warns with the missing ids and the lag hint. `fail` sets a non-zero exit code (the command could not do its job for * them, e.g. a dry-run plan that would skip them). Returns the missing ids. */ export function reportMissing(tag: string, what: string, want: string[], got: Iterable, o: { fail: boolean }): string[] { const missing = missingFromStore(want, got); if (!missing.length) return missing; warn(tag, `${missing.length} of ${want.length} ${what} not in the store's list: ${missing.join(', ')} (${LAG_HINT})`); if (o.fail) process.exitCode = 1; return missing; }