@chrtco/sdk 0.4.1 → 0.6.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,51 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@chrtco/sdk` will be documented in this file.
4
+
5
+ ## [0.6.0] — 2026-04-27
6
+ - **New sub-export `@chrtco/sdk/atlas/browser`** — S-52 atlas helpers for browser-side rendering. Previously lived in the React app's `src/lib/atlas/` and was internal-only; now part of the SDK so external consumers can drive map styling consistently with the platform.
7
+ - **`OfflineError.detail.level` (`"team" | "key"`)** — `budget_exceeded` errors from `mint-offline-token` now carry a `level` field on `error.detail` so consumers can branch their messaging between per-key caps ("raise this key's storage cap") and per-team caps ("upgrade your team plan"). `team_used_bytes` is also surfaced on team-level refusals so dashboards can show usage context. Existing `budget_bytes` / `required_bytes` / `over_by_bytes` keys are unchanged.
8
+ - **Internal**: `@maplibre/maplibre-gl-style-spec` declared as a devDep (was a runtime dep but only needed at build/typecheck time).
9
+
10
+ ## [0.5.0] — 2026-04-23
11
+ - **CHRToffline** — download MBTiles bundles for offline rendering:
12
+ - `chrt.offline.list()`, `chrt.offline.download(region, opts)`, `chrt.offline.remove(region, opts)`, `chrt.offline.heartbeat(opts?)`, `chrt.offline.setStorageBudget(bytes, fs)`
13
+ - HTTP Range-based download resumption via `.partial` sidecar file
14
+ - SHA-256 verification before rename to final path
15
+ - `AbortSignal` support; interrupted downloads leave `.partial` on disk for resume
16
+ - Progress callback throttled to max(1 MB, 1%) boundaries; always fires at 0 and completion
17
+ - Optional local manifest (`ChrtConfig.manifestPath`) for budget enforcement and device-state tracking
18
+ - Typed errors via `OfflineError` with `code` discriminator (`budget_exceeded`, `download_corrupt`, `network_interrupted`, `coverage_denied`, `quota_exceeded`, `offline_not_enabled`, `sha_missing`, `missing_device_id`, `missing_manifest_path`, `region_not_available`, `invalid_api_key`, `unexpected_response`)
19
+ - **New config options**: `deviceId` (required for `offline.*`), `manifestPath` (optional)
20
+ - **New sub-export `@chrtco/sdk/node`**: `nodeFileSystemAdapter()` — Node 18+ implementation of `FileSystemAdapter` (core remains zero runtime deps)
21
+ - **Runtime target v1**: Node, Bun, Deno only. React Native and browser support deferred to a follow-up phase.
22
+ - **Internal**: SDK mints its own short-lived offline JWTs; customers never see them. Mint + offline traffic routes through `api.chrt.co/v1/mint/offline-token` and `api.chrt.co/v1/offline/*` (new `api-worker` proxy).
23
+
24
+ ## [0.4.0] — 2026-03-27 (republish)
25
+ - **Coverage endpoint** — `chrt.coverage.list()` returns chart sources by country with cell counts
26
+ - **Webhook event types** — discriminated-union types for `cell.updated`, `cell.new`, `cell.deleted` payloads; `parseWebhook()` runtime helper
27
+ - **Async auto-pagination** — `chrt.featuresIter()` and `chrt.cellsIter()` return `AsyncIterable` for `for-await-of` loops
28
+ - **AbortController support** — all request methods accept `signal?: AbortSignal` for cancellation
29
+
30
+ ## [0.3.2] — 2026-03-27
31
+ - Fixed CI publish pipeline (removed --provenance flag incompatible with private repos)
32
+
33
+ ## [0.3.1] — 2026-03-27
34
+ - Improved README with clearer quick-start examples and configuration options
35
+
36
+ ## [0.3.0] — 2026-03-26
37
+ - Reordered package exports for bundler compatibility (types first)
38
+ - Updated docs with Mapbox GL JS / MapLibre integration examples
39
+
40
+ ## [0.2.0] — 2026-02-01
41
+ - Added Feature API endpoint (`chrt.features()`) with bbox, layer filtering, pagination
42
+ - Added Spatial Query endpoint (`chrt.query()`) with point + radius search
43
+ - Added Cell Metadata endpoints (`chrt.cells.list()`, `chrt.cells.get()`)
44
+
45
+ ## [0.1.0] — 2026-01-15
46
+ - Initial release
47
+ - Chrt client with API key authentication
48
+ - Tiles endpoints: `styleUrl()`, `tileUrl()`, `groups()`
49
+ - `transformRequest()` helper for Mapbox GL / MapLibre
50
+ - `ChrtError` typed error class
51
+ - Configurable retries on 5xx responses
package/README.md CHANGED
@@ -121,6 +121,75 @@ try {
121
121
  }
122
122
  ```
123
123
 
124
+ ## Offline Downloads (CHRToffline)
125
+
126
+ Download MBTiles bundles for offline rendering. Bundles are SHA-256 verified before commit. Interrupted downloads resume from a `.partial` sidecar file.
127
+
128
+ **Runtime support in v1:** Node 18+, Bun, Deno. Browser and React Native are deferred to a follow-up.
129
+
130
+ ```typescript
131
+ import { Chrt } from '@chrtco/sdk';
132
+ import { nodeFileSystemAdapter } from '@chrtco/sdk/node';
133
+
134
+ const chrt = new Chrt({
135
+ apiKey: process.env.CHRT_API_KEY!,
136
+ // Required for offline.* — generate once at first launch, persist per
137
+ // install. Echoed into the offline JWT + heartbeat for device-level usage
138
+ // tracking.
139
+ deviceId: 'my-app-install-uuid',
140
+ // Optional — enables budget enforcement + `list()` of local state. If
141
+ // unset, budget is not enforced and `setStorageBudget()` throws.
142
+ manifestPath: './chrt-offline-manifest.json',
143
+ });
144
+
145
+ const fs = nodeFileSystemAdapter();
146
+
147
+ // Optional: cap total local storage across all regions.
148
+ await chrt.offline.setStorageBudget(10 * 1024 ** 3, fs); // 10 GB
149
+
150
+ // List what you're licensed to download.
151
+ const regions = await chrt.offline.list();
152
+
153
+ // Download a region. Resumes from a partial if one exists.
154
+ await chrt.offline.download('NOAA_ENC', {
155
+ path: './noaa.mbtiles',
156
+ fs,
157
+ onProgress: (p) => console.log(`${p.fraction * 100}%`),
158
+ });
159
+
160
+ // Remove a region (deletes the file + updates manifest + heartbeats).
161
+ await chrt.offline.remove('NOAA_ENC', { path: './noaa.mbtiles', fs });
162
+
163
+ // Manual heartbeat — call at app launch + every 24h while running.
164
+ await chrt.offline.heartbeat({ fs }); // derives regions + total from manifest
165
+ ```
166
+
167
+ ### Typed offline errors
168
+
169
+ ```typescript
170
+ import { OfflineError } from '@chrtco/sdk';
171
+
172
+ try {
173
+ await chrt.offline.download('NOAA_ENC', { path: './noaa.mbtiles', fs });
174
+ } catch (e) {
175
+ if (e instanceof OfflineError) {
176
+ switch (e.code) {
177
+ case 'budget_exceeded': console.log(e.detail); break;
178
+ case 'download_corrupt': console.log('SHA mismatch'); break;
179
+ case 'network_interrupted': console.log('resume later'); break;
180
+ case 'coverage_denied': console.log('region not licensed'); break;
181
+ case 'offline_not_enabled': console.log('enable use_offline on this API key'); break;
182
+ }
183
+ }
184
+ }
185
+ ```
186
+
187
+ ### Notes
188
+
189
+ - The SDK mints its own short-lived JWTs internally. You never see them.
190
+ - Heartbeats in v1 are manual — auto-scheduling comes in a later phase.
191
+ - A budget smaller than current usage will not auto-prune; it only refuses new downloads. Use `remove()` explicitly.
192
+
124
193
  ## License
125
194
 
126
195
  MIT