storebound/cli/lib/zip.ts
CRT 9d0af72806 Store operations: TestFlight wait / expire, IAP review submissions, listing pulls, release notes per language, offers, custom product pages, in-app events, reports, triage, keyword ranks, AdAttributionKit scan
- apple testflight wait --build N (progress, timeout, exit 0/1/7) and expire --keep N | --older-than D (dry run, asks)
- apple iap-submit: IAP / subscription / group versions into a review submission; first of a type only with the app
  version (--with-version), --no-submit keeps the draft; read-only MCP plan
- apple listing pull, play listing pull (diff, --write), catalog pull (config proposal, never rewritten)
- whats-new --languages / check / apply: one file per language, agent or hook translation, per-store limits
- apple offer-codes, win-back, promoted, preorder; Play pre-registration as a guide (no API)
- apple cpp and apple events: list, create, upload, submit (asks)
- reports: Apple sales / finance, Play earnings / sales into .storebound/reports with summary and CSV
- triage: TestFlight crash / feedback and Play error reports grouped by signature, device, OS
- aso rank: iTunes Search API ranks and competitors, rate limited
- ads scan: AdAttributionKit / SKAdNetwork Info.plist and source checks
- tests against recorded, sanitized answers; skills, README, CHANGELOG
2026-10-11 15:58:17 +00:00

32 lines
2 KiB
TypeScript

// Minimal ZIP reader for the Play financial report exports (earnings_YYYYMM.zip, salesreport_YYYYMM.zip: one CSV
// inside). Reads the central directory, supports stored (0) and deflate (8) entries; no ZIP64, no encryption. Uses
// node:zlib (built into Bun), so storebound keeps zero runtime dependencies. Pure.
import { inflateRawSync } from 'node:zlib';
export interface ZipEntry { name: string; data: Uint8Array }
export function unzip(buf: Uint8Array): ZipEntry[] {
const dv = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
// end of central directory: signature 0x06054b50 within the last 64 KiB + 22 bytes
let eocd = -1;
for (let i = buf.length - 22; i >= Math.max(0, buf.length - 65_557); i--) if (dv.getUint32(i, true) === 0x06054b50) { eocd = i; break; }
if (eocd < 0) throw new Error('not a zip file (no end of central directory)');
const count = dv.getUint16(eocd + 10, true);
let p = dv.getUint32(eocd + 16, true);
const out: ZipEntry[] = [];
const dec = new TextDecoder();
for (let i = 0; i < count; i++) {
if (dv.getUint32(p, true) !== 0x02014b50) throw new Error('zip: bad central directory entry');
const method = dv.getUint16(p + 10, true), size = dv.getUint32(p + 20, true), nameLen = dv.getUint16(p + 28, true);
const extraLen = dv.getUint16(p + 30, true), commentLen = dv.getUint16(p + 32, true), local = dv.getUint32(p + 42, true);
const name = dec.decode(buf.subarray(p + 46, p + 46 + nameLen));
if (dv.getUint32(local, true) !== 0x04034b50) throw new Error(`zip: bad local header for ${name}`);
const start = local + 30 + dv.getUint16(local + 26, true) + dv.getUint16(local + 28, true);
const raw = buf.subarray(start, start + size);
if (method === 0) out.push({ name, data: raw });
else if (method === 8) out.push({ name, data: new Uint8Array(inflateRawSync(raw)) });
else throw new Error(`zip: ${name} uses compression method ${method}`);
p += 46 + nameLen + extraLen + commentLen;
}
return out;
}