|
| 1 | +--- |
| 2 | +type: executor-prompt |
| 3 | +title: Improve IGDB Wrapper Reliability and Ergonomics |
| 4 | +slug: api-wrapper-improvements |
| 5 | +created: 2026-06-25 |
| 6 | +status: ready |
| 7 | +target: TypeScript IGDB wrapper reliability, ergonomics, endpoint metadata, docs, and release validation |
| 8 | +related: |
| 9 | + - audit.html |
| 10 | +--- |
| 11 | + |
| 12 | +# Task |
| 13 | + |
| 14 | +Implement the following plan exactly. Do not redesign the approach unless you find a real blocker. |
| 15 | + |
| 16 | +# Context |
| 17 | + |
| 18 | +This repository is `@api-wrappers/igdb-wrapper`, a TypeScript package for IGDB v4. It uses Bun tests, tsdown, strict TypeScript, and `@api-wrappers/api-core` for HTTP transport, retry, rate limiting, auth plugin wiring, timeout, custom fetch, plugins, and logging. |
| 19 | + |
| 20 | +The current baseline is healthy: `bun run typecheck`, `bun test`, and `bun run build` passed during the strategist audit. The package should be improved incrementally, with no broad rewrite and no removal of raw APICalypse escape hatches. |
| 21 | + |
| 22 | +Relevant files: |
| 23 | +- `src/auth/AuthManager.ts` |
| 24 | +- `src/http/HttpClient.ts` |
| 25 | +- `src/client/IGDBClient.ts` |
| 26 | +- `src/client/config.ts` |
| 27 | +- `src/endpoints/registry.ts` |
| 28 | +- `src/endpoints/Endpoint.ts` |
| 29 | +- `src/query/QueryBuilder.ts` |
| 30 | +- `src/query/compiler.ts` |
| 31 | +- `src/query/ast.ts` |
| 32 | +- `src/query/helpers.ts` |
| 33 | +- `src/query/operators.ts` |
| 34 | +- `src/query/fieldProxy.ts` |
| 35 | +- `src/types/models.ts` |
| 36 | +- `src/types/query.types.ts` |
| 37 | +- `src/types/response.types.ts` |
| 38 | +- `src/__tests__/igdb-client.test.ts` |
| 39 | +- `README.md`, `ROADMAP.md`, and `docs/` |
| 40 | +- `package.json`, `tsdown.config.mjs`, and `tsconfig.json` |
| 41 | + |
| 42 | +# Implementation Plan |
| 43 | + |
| 44 | +1. Add single-flight token refresh. |
| 45 | + - In `AuthManager`, add a private in-flight refresh promise, for example `#refreshing: Promise<string> | null`. |
| 46 | + - Keep the current cache check. |
| 47 | + - When the cache is missing or stale, reuse the pending refresh promise if present. |
| 48 | + - When starting a new refresh, store the promise and clear it in `finally`. |
| 49 | + - Preserve current Twitch token request shape and current `IGDBAuthError` mapping. |
| 50 | + - Add a test that fires multiple concurrent IGDB requests against an empty cache and asserts exactly one Twitch token request. |
| 51 | + |
| 52 | +2. Expand error and validation tests. |
| 53 | + - Add focused tests for 401 IGDB responses mapping to `IGDBAuthError`. |
| 54 | + - Add a failed Twitch token fetch test that maps to `IGDBAuthError`. |
| 55 | + - Add tests for non-JSON or string-ish error body formatting if api-core exposes it through `ApiError.responseBody`. |
| 56 | + - Add validation tests for invalid `limit()`, `offset()`, `paginate()`, empty `fields()`, and unsupported `count()` on a manually created `QueryBuilder`. |
| 57 | + - Add a not-found test for `findById()` or endpoint `firstOrThrow()`. |
| 58 | + |
| 59 | +3. Create endpoint metadata as the single source of truth. |
| 60 | + - Introduce structured metadata that binds public key, endpoint path, model type name, and searchability. |
| 61 | + - Derive `IGDB_ENDPOINTS` and `IGDB_SEARCHABLE_ENDPOINTS` from that metadata. |
| 62 | + - Preserve the existing exported type names: `IGDBEndpointKey`, `IGDBEndpointPath`, and `IGDBSearchableEndpointPath`. |
| 63 | + - Preserve all existing endpoint paths and client property names. |
| 64 | + - If code generation is used, commit generated output and add a check that fails when generation output is stale. |
| 65 | + |
| 66 | +4. Reduce manual endpoint-client drift. |
| 67 | + - Keep existing named `IGDBClient` properties for backward compatibility. |
| 68 | + - Either generate the property declarations/assignments from endpoint metadata or add a type-level/runtime drift test that verifies every metadata row has a client property and docs entry. |
| 69 | + - Do not replace the named properties with only a generic map. |
| 70 | + |
| 71 | +5. Add a minimal typed multi-query builder. |
| 72 | + - Keep `client.multiQuery(rawString)` unchanged. |
| 73 | + - Add a small API that supports named list queries and named count queries. |
| 74 | + - Reuse existing `QueryBuilder.raw()` output for query bodies instead of reimplementing APICalypse compilation. |
| 75 | + - Ensure output matches IGDB multi-query syntax. |
| 76 | + - Add tests for compiled body and response typing. |
| 77 | + - Document the API in README/docs with one concise example. |
| 78 | + |
| 79 | +6. Improve query introspection behavior. |
| 80 | + - Prefer non-printing introspection as the stable path. `raw()` already exists; add `inspect()` or `toJSON()` only if useful. |
| 81 | + - If `debug()` and `explain()` remain, document that they write to console and are debug-only. |
| 82 | + - Do not introduce unconditional extra console output elsewhere. |
| 83 | + |
| 84 | +7. Add package smoke validation. |
| 85 | + - Add a script or test that runs after build, packs the package locally, verifies expected files, imports ESM, requires CJS, and typechecks a minimal consumer snippet. |
| 86 | + - Wire it into `verify` if it is fast and deterministic. |
| 87 | + - Avoid new dependencies unless the smoke test cannot be done cleanly with Bun/Node built-ins. |
| 88 | + |
| 89 | +8. Update docs and roadmap. |
| 90 | + - Update README/docs for typed multi-query usage, debug guidance, and package verification. |
| 91 | + - Keep browser credential guidance server-side; do not encourage exposing Twitch client secrets. |
| 92 | + - Mark completed roadmap items rather than duplicating them. |
| 93 | + |
| 94 | +# Constraints |
| 95 | + |
| 96 | +- Follow existing project patterns. |
| 97 | +- Keep the change focused. |
| 98 | +- Do not perform unrelated refactors. |
| 99 | +- Preserve existing behavior unless explicitly changed by the plan. |
| 100 | +- Reuse existing types, schemas, utilities, services, and components before creating new ones. |
| 101 | +- Avoid adding dependencies unless explicitly allowed. |
| 102 | +- Do not remove raw APICalypse methods or raw `multiQuery(string)`. |
| 103 | +- Do not replace `@api-wrappers/api-core`. |
| 104 | +- Keep named endpoint properties source-compatible. |
| 105 | + |
| 106 | +# TypeScript Rules |
| 107 | + |
| 108 | +- Do not use `any`. |
| 109 | +- Avoid weakening public types. |
| 110 | +- Prefer clear exported types for new public APIs. |
| 111 | +- Keep generic types understandable; do not over-engineer typed multi-query. |
| 112 | +- Maintain strict TypeScript compatibility. |
| 113 | + |
| 114 | +# Validation |
| 115 | + |
| 116 | +Before finishing: |
| 117 | + |
| 118 | +- Run `bun run typecheck`. |
| 119 | +- Run `bun test`. |
| 120 | +- Run `bun run build`. |
| 121 | +- Run `npm pack --dry-run`. |
| 122 | +- Run the new package smoke validation if added. |
| 123 | +- Confirm README examples affected by public API changes still typecheck or are otherwise covered. |
| 124 | + |
| 125 | +# Acceptance Criteria |
| 126 | + |
| 127 | +- Concurrent cold-start requests share exactly one Twitch token refresh. |
| 128 | +- Existing public API remains source-compatible for current README examples. |
| 129 | +- Endpoint metadata has one clear source of truth and tests catch registry/client/searchability drift. |
| 130 | +- Typed multi-query supports at least named list queries and named count queries while raw multi-query remains available. |
| 131 | +- Error mapping and validation behavior are covered by focused tests. |
| 132 | +- Package smoke validation proves ESM, CJS, and declarations work from the built package. |
| 133 | +- `bun run typecheck`, `bun test`, `bun run build`, and package verification pass. |
| 134 | + |
| 135 | +# Final Response |
| 136 | + |
| 137 | +When done, respond with: |
| 138 | + |
| 139 | +1. Summary of changes |
| 140 | +2. Files changed |
| 141 | +3. Commands run |
| 142 | +4. Tests/checks completed |
| 143 | +5. Any blockers, assumptions, or follow-up recommendations |
0 commit comments