brawlstars-sdk 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,76 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ ## [0.3.0] - 2026-02-28
6
+
7
+ ### Added
8
+
9
+ - Validation modes: `off`, `warn` (default), `strict`.
10
+ - `onRateLimit` hook with retry metadata.
11
+ - Public export: `encodeTag` and `EncodeTagOptions`.
12
+ - Integration test suite with mocked HTTP API scenarios (`test:integration`).
13
+ - API parity script: `npm run verify:api`.
14
+ - `CHANGES.md` update log.
15
+ - Security scanner script: `npm run scan:secrets`.
16
+ - Verification report output: `npm run verify:api:report` (`reports/verify-api.json`).
17
+
18
+ ### Changed
19
+
20
+ - Strict validation now throws `ResponseValidationError` with `expectedSchema` and `actualPayload`.
21
+ - Validation `warn` mode now uses configurable `logger.warn`.
22
+ - Error metadata now includes `headers`, `retryAfter` (seconds), and `request` metadata.
23
+ - Retry logic now consumes normalized `Retry-After` and `x-ratelimit-*` header variants.
24
+ - Cache key generation now uses stable `method|path|sortedQuery|bodyHash|whitelistedHeaders`.
25
+ - Cache-key whitelist is configurable through `cacheKeyHeaders`.
26
+ - CI now runs integration tests in addition to unit tests.
27
+ - CI and release workflows now use `npm ci`.
28
+
29
+ ## [0.2.0] - 2026-02-28
30
+
31
+ ### Added
32
+
33
+ - Amélioration: corrections critiques et durcissement complet du SDK.
34
+ - `ClientError` and `ValidationError` error classes with unified metadata fields (`body`, `requestId`, `retryAfterMs`).
35
+ - Observability module with `requestStart`, `requestEnd`, `requestError` events.
36
+ - Optional `prom-client` compatible adapter helper (`createPromClientAdapter`).
37
+ - Endpoint-level cache invalidation (`invalidateCache(endpoint?)`).
38
+ - Coverage gates via Vitest (`>= 90%` thresholds).
39
+ - Coverage plugin `@vitest/coverage-v8` and thresholded runtime coverage reports.
40
+ - Benchmark tooling (`benchmarks/local-bench.mjs`, `bench:local`, `bench:smoke`).
41
+ - Consumer test for built package import (`tests/consumer.test.ts`).
42
+ - Added targeted tests for validators, response parsers, list normalization, encoding, retry/rate-limit, cache and observability metadata.
43
+ - Architecture, security, audit and benchmark documentation.
44
+ - Release workflow (`.github/workflows/release.yml`) and Dependabot config.
45
+ - `types/index.d.ts` public type entry.
46
+
47
+ ### Changed
48
+
49
+ - Retry strategy now supports explicit jitter modes (`jitter: "full" | "none"`).
50
+ - Default retry base delay is now `100ms` with `maxAttempts: 4`.
51
+ - Rate-limit handling distinguishes route-scoped and global throttling windows.
52
+ - Concurrency slots are now reserved only during active fetch attempts, so route-scoped waits do not block unrelated routes.
53
+ - Preferred paginated signatures are now `opts?` with backward-compatible legacy overloads.
54
+ - CI now runs lint, typecheck, tests, coverage, build, consumer test and benchmark smoke.
55
+ - README rewritten with migration guide, architecture rationale and release policy.
56
+
57
+ ### Kept for Compatibility
58
+
59
+ - `ResponseValidationError` remains exported as an alias-compatible class.
60
+ - Legacy paginated method signatures (`query?, options?`) continue to work.
61
+
62
+ ## [0.1.0] - 2026-02-27
63
+
64
+ ### Added
65
+
66
+ - Initial TypeScript wrapper for all discovered Brawl Stars API endpoints.
67
+ - Strict public typings and normalized list response model.
68
+ - `BrawlStarsClient` with endpoint groups: players, clubs, rankings, brawlers, gamemodes, events.
69
+ - Resilience layer: timeout, retry with jitter, adaptive rate-limit handling, concurrency pool.
70
+ - Optional in-memory LRU cache with request and endpoint overrides.
71
+ - Hook system: `beforeRequest`, `afterResponse`, `onError`.
72
+ - Typed error classes with structured metadata.
73
+ - Optional runtime response validation.
74
+ - Unit tests for retries, throttling, cache, parsing, hooks, and error behavior.
75
+ - API discovery parser script and generated documentation (`docs/API_DISCOVERY.md`).
76
+ - ESM + CJS packaging, CI workflow, and examples.
package/CHANGES.md ADDED
@@ -0,0 +1,19 @@
1
+ # Update Log
2
+
3
+ ## Quality 10 Upgrade
4
+
5
+ - Added validation modes: `off`, `warn` (default), and `strict`.
6
+ - Added strict `ResponseValidationError` metadata (`expectedSchema`, `actualPayload`).
7
+ - Improved rate-limit parsing (`Retry-After` numeric/date + x-ratelimit variants).
8
+ - Extended typed error metadata with response headers, retry metadata, and request metadata.
9
+ - Added `onRateLimit` hook.
10
+ - Added stable cache-key utility with volatile-header exclusion.
11
+ - Added cache-key body hashing and path-based key composition.
12
+ - Added configurable cache-key header whitelist (`cacheKeyHeaders`).
13
+ - Exported `encodeTag` from public API with configurable uppercasing.
14
+ - Added integration tests with mocked HTTP API scenarios (200/404/429).
15
+ - Added `verify:api` fixture-based test and support for `--doc`/positional path.
16
+ - Added JSON report output for `verify-api` in `reports/verify-api.json`.
17
+ - Added repository secret scan script for CI (`scripts/scan-secrets.sh`).
18
+ - Updated CI to run integration tests.
19
+ - Updated README with new configuration and error-handling guidance.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,212 @@
1
+ # Brawl Stars TypeScript SDK
2
+
3
+ Production-ready TypeScript wrapper for the official Brawl Stars API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @dontbepooronbrawlstarsbrawlstars-sdk
9
+ ```
10
+
11
+ ## Quickstart
12
+
13
+ ```bash
14
+ export BRAWLSTARS_API_TOKEN="your-token"
15
+ ```
16
+
17
+ ```ts
18
+ import { BrawlStarsClient } from "@dontbepooronbrawlstarsbrawlstars-sdk";
19
+ const client = new BrawlStarsClient({ token: process.env.BRAWLSTARS_API_TOKEN! });
20
+ const player = await client.players.get("#2ABC");
21
+ ```
22
+
23
+ ## Core Usage
24
+
25
+ ```ts
26
+ import { BrawlStarsClient } from "@dontbepooronbrawlstarsbrawlstars-sdk";
27
+
28
+ const client = new BrawlStarsClient({ token: process.env.BRAWLSTARS_API_TOKEN! });
29
+
30
+ const player = await client.players.get("#2ABC");
31
+ const club = await client.clubs.get("#2XYZ");
32
+ const brawlers = await client.brawlers.list({ limit: 25 });
33
+ ```
34
+
35
+ ## Tag Utility
36
+
37
+ `encodeTag` is exported for direct use:
38
+
39
+ ```ts
40
+ import { encodeTag } from "@dontbepooronbrawlstarsbrawlstars-sdk";
41
+
42
+ encodeTag(" 2ab c "); // %232ABC
43
+ encodeTag(" 2AbC ", { uppercase: false }); // %232AbC
44
+ ```
45
+
46
+ Behavior:
47
+ - removes whitespace
48
+ - prefixes `#` if missing
49
+ - uppercases by default
50
+ - applies `encodeURIComponent`
51
+
52
+ ## Configuration
53
+
54
+ ```ts
55
+ new BrawlStarsClient({
56
+ token: string,
57
+ baseUrl?: string,
58
+ timeoutMs?: number,
59
+ retries?: number | Partial<RetryOptions>,
60
+ concurrencyLimit?: number,
61
+ cache?: boolean | CacheOptions,
62
+ cacheKeyHeaders?: readonly string[],
63
+ validation?: "off" | "warn" | "strict",
64
+ logger?: { warn: (...args: unknown[]) => void; error?: (...args: unknown[]) => void; info?: (...args: unknown[]) => void },
65
+ hooks?: ClientHooks,
66
+ observability?: ObservabilityOptions,
67
+ fetch?: typeof fetch,
68
+ });
69
+ ```
70
+
71
+ ### Validation Modes
72
+
73
+ - `off`: no runtime validation (fastest)
74
+ - `warn` (default): validates responses; on mismatch calls `logger.warn` and returns raw payload
75
+ - `strict`: validates responses and throws `ResponseValidationError` on mismatch
76
+
77
+ Detailed semantics are documented in [docs/VALIDATION.md](./docs/VALIDATION.md).
78
+
79
+ Per-request overrides:
80
+
81
+ ```ts
82
+ await client.players.get("#2ABC", {
83
+ timeoutMs: 8_000,
84
+ cache: false,
85
+ validation: "strict",
86
+ });
87
+ ```
88
+
89
+ ## Errors, Rate Limit, and Retries
90
+
91
+ All request failures throw typed errors (`ApiError`, `RateLimitError`, `TimeoutError`, `NetworkError`, `ResponseValidationError`).
92
+
93
+ Error metadata includes:
94
+ - `statusCode`
95
+ - `headers`
96
+ - `body`
97
+ - `retryAfter` (seconds, when calculable)
98
+ - `request` (`method`, `url`, request options)
99
+
100
+ Example:
101
+
102
+ ```ts
103
+ import { RateLimitError } from "@dontbepooronbrawlstarsbrawlstars-sdk";
104
+
105
+ try {
106
+ await client.players.get("#2ABC");
107
+ } catch (error) {
108
+ if (error instanceof RateLimitError && error.retryAfter) {
109
+ console.error(`Retry after ${error.retryAfter}s`);
110
+ }
111
+ }
112
+ ```
113
+
114
+ Retries use exponential backoff + jitter and respect `Retry-After` when present.
115
+
116
+ ## Hooks
117
+
118
+ ```ts
119
+ const client = new BrawlStarsClient({
120
+ token,
121
+ hooks: {
122
+ onRateLimit: (ctx) => {
123
+ // ctx.retryAfter is in seconds
124
+ console.warn("Rate-limited", ctx.retryAfter);
125
+ },
126
+ onError: (ctx) => {
127
+ console.error(ctx.error.name, ctx.error.statusCode);
128
+ },
129
+ },
130
+ });
131
+ ```
132
+
133
+ ## Cache
134
+
135
+ - caches successful `GET` responses only
136
+ - never caches error responses
137
+ - cache key format: `method|path|sortedQuery|bodyHash|whitelistedHeaders`
138
+ - default cache-key header whitelist: `accept-language`
139
+ - volatile headers (e.g. `authorization`, `x-request-id`, `date`, `traceparent`, `user-agent`) do not affect key
140
+ - whitelist is configurable via `cacheKeyHeaders`
141
+
142
+ ```ts
143
+ client.invalidateCache("players.get");
144
+ client.clearCache();
145
+ ```
146
+
147
+ ## Scripts
148
+
149
+ ```bash
150
+ npm run lint
151
+ npm run typecheck
152
+ npm test
153
+ npm run test:integration
154
+ npm run test:coverage
155
+ npm run verify:api
156
+ npm run verify:api -- "./api-spec.txt"
157
+ npm run verify:api:report
158
+ npm run build
159
+ npm run pack:check
160
+ npm run scan:secrets
161
+ npm run prepublish:verify
162
+ ```
163
+
164
+ `verify:api` compares key TypeScript models against the provided API reference file (`api-spec.txt`) and prints JSON:
165
+
166
+ ```json
167
+ {"missingInTs":[],"extraInTs":[]}
168
+ ```
169
+
170
+ `verify:api:report` writes proof output to `reports/verify-apibrawlstars-sdkon`.
171
+
172
+ You can provide a custom document path:
173
+
174
+ ```bash
175
+ npm run verify:api -- --doc ./api-spec.txt
176
+ # or positional:
177
+ npm run verify:api -- ./api-spec.txt
178
+ ```
179
+
180
+ ## CI
181
+
182
+ GitHub Actions runs:
183
+ - lint
184
+ - typecheck
185
+ - verify-api
186
+ - unit tests
187
+ - integration tests (mocked)
188
+ - pack check
189
+
190
+ `tests/integration.live.test.ts` is optional and only runs when `BRAWLSTARS_TOKEN` is set.
191
+
192
+ ## Contributing
193
+
194
+ 1. Run `npm install`
195
+ 2. Run `npm run validate`
196
+ 3. Open PR with tests and documentation updates
197
+
198
+ ## Architecture
199
+
200
+ See [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md).
201
+
202
+ ## Security
203
+
204
+ See [docs/SECURITY.md](./docs/SECURITY.md).
205
+
206
+ ## API Verification
207
+
208
+ See [docs/VERIFY_API_RUN.md](./docs/VERIFY_API_RUN.md).
209
+
210
+ ## Audit
211
+
212
+ See [docs/AUDIT.md](./docs/AUDIT.md).