@chrtco/sdk 0.7.6 → 0.8.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 +10 -0
- package/README.md +49 -16
- package/dist/atlas/browser.cjs +35 -11
- package/dist/atlas/browser.cjs.map +1 -1
- package/dist/atlas/browser.js +35 -11
- package/dist/atlas/browser.js.map +1 -1
- package/dist/index.cjs +384 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +291 -117
- package/dist/index.d.ts +291 -117
- package/dist/index.js +381 -77
- package/dist/index.js.map +1 -1
- package/package.json +3 -20
package/dist/index.d.cts
CHANGED
|
@@ -254,7 +254,8 @@ interface TileGroupsResponse {
|
|
|
254
254
|
}
|
|
255
255
|
interface TransformRequest {
|
|
256
256
|
url: string;
|
|
257
|
-
|
|
257
|
+
/** Optional — omitted for requests the transformer leaves unauthenticated. */
|
|
258
|
+
headers?: Record<string, string>;
|
|
258
259
|
}
|
|
259
260
|
interface ChrtErrorBody {
|
|
260
261
|
error: string;
|
|
@@ -268,6 +269,19 @@ interface ChrtConfig {
|
|
|
268
269
|
baseUrl?: string;
|
|
269
270
|
/** Max retries on 5xx/network errors (default 2) */
|
|
270
271
|
retries?: number;
|
|
272
|
+
/**
|
|
273
|
+
* Chart region for tile rendering, e.g. "NOAA_ENC" (default). Used as the
|
|
274
|
+
* default region by `chrt.style()` and `chrt.transformRequest()`. Override
|
|
275
|
+
* per call if you render more than one region.
|
|
276
|
+
*/
|
|
277
|
+
region?: string;
|
|
278
|
+
/**
|
|
279
|
+
* Override the tile-worker origin that serves vector tiles (default
|
|
280
|
+
* `https://tiles.chrt.co`). Point at `https://staging-tiles.chrt.co` for
|
|
281
|
+
* staging. Tiles are requested at
|
|
282
|
+
* `${tileBaseUrl}/v1/tiles/{region}/{z}/{x}/{y}.mvt`.
|
|
283
|
+
*/
|
|
284
|
+
tileBaseUrl?: string;
|
|
271
285
|
/**
|
|
272
286
|
* Stable per-install device identifier. Required to call `chrt.offline.*`.
|
|
273
287
|
* Generate once at first launch (e.g. UUIDv4), persist, reuse forever.
|
|
@@ -422,12 +436,31 @@ declare class HttpClient {
|
|
|
422
436
|
|
|
423
437
|
declare class TilesEndpoint {
|
|
424
438
|
private http;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
439
|
+
private readonly region;
|
|
440
|
+
private readonly tileBaseUrl;
|
|
441
|
+
constructor(http: HttpClient, opts?: {
|
|
442
|
+
region?: string;
|
|
443
|
+
tileBaseUrl?: string;
|
|
444
|
+
});
|
|
445
|
+
/**
|
|
446
|
+
* @deprecated CHRT has no remote `style.json` endpoint — the S-52 style is
|
|
447
|
+
* generated client-side. Use `chrt.style(opts)` to get a ready-to-use
|
|
448
|
+
* MapLibre style object instead. Calling this throws to prevent silently
|
|
449
|
+
* pointing a map at a dead URL.
|
|
450
|
+
*/
|
|
451
|
+
styleUrl(): never;
|
|
452
|
+
/**
|
|
453
|
+
* Vector tile URL template for the configured region, served by the
|
|
454
|
+
* tile-worker at `tiles.chrt.co`. Tiles are JWT-gated — pair this with
|
|
455
|
+
* `chrt.transformRequest()`, which attaches the `Authorization: Bearer`
|
|
456
|
+
* header. Prefer `chrt.style()`, which wires the source for you.
|
|
457
|
+
*/
|
|
458
|
+
tileUrl(z: number, x: number, y: number): string;
|
|
459
|
+
/**
|
|
460
|
+
* @deprecated Tilesets were consolidated to one PMTiles per region (2026-04);
|
|
461
|
+
* the per-group catalogue endpoint is legacy and no longer served. Render via
|
|
462
|
+
* `chrt.style()` instead, which emits a single vector source per region.
|
|
463
|
+
*/
|
|
431
464
|
groups(): Promise<TileGroupsResponse>;
|
|
432
465
|
}
|
|
433
466
|
|
|
@@ -541,101 +574,6 @@ declare class OfflineEndpoint {
|
|
|
541
574
|
private persistManifestEntry;
|
|
542
575
|
}
|
|
543
576
|
|
|
544
|
-
/**
|
|
545
|
-
* Generic async auto-pagination generator.
|
|
546
|
-
*
|
|
547
|
-
* Fetches pages from a callback that returns `{ items, total_count }` and
|
|
548
|
-
* yields individual items until all pages are consumed or the signal is aborted.
|
|
549
|
-
*
|
|
550
|
-
* @example
|
|
551
|
-
* ```ts
|
|
552
|
-
* for await (const feature of paginate(
|
|
553
|
-
* (offset, signal) => chrt.features({ bbox, limit: 100, offset, signal }),
|
|
554
|
-
* f => f.features,
|
|
555
|
-
* f => f.total_count ?? 0,
|
|
556
|
-
* )) {
|
|
557
|
-
* console.log(feature);
|
|
558
|
-
* }
|
|
559
|
-
* ```
|
|
560
|
-
*/
|
|
561
|
-
declare function paginate<TResponse, TItem>(fetchPage: (offset: number, signal?: AbortSignal) => Promise<TResponse>, getItems: (response: TResponse) => TItem[], getTotalCount: (response: TResponse) => number, options?: {
|
|
562
|
-
pageSize?: number;
|
|
563
|
-
signal?: AbortSignal;
|
|
564
|
-
}): AsyncGenerator<TItem, void, undefined>;
|
|
565
|
-
|
|
566
|
-
/** Base envelope for all webhook payloads */
|
|
567
|
-
interface WebhookPayload<T extends string, D> {
|
|
568
|
-
/** Unique event ID */
|
|
569
|
-
id: string;
|
|
570
|
-
/** ISO 8601 timestamp */
|
|
571
|
-
timestamp: string;
|
|
572
|
-
/** Event type discriminator */
|
|
573
|
-
type: T;
|
|
574
|
-
/** Event-specific data */
|
|
575
|
-
data: D;
|
|
576
|
-
}
|
|
577
|
-
interface CellEventData {
|
|
578
|
-
cell_id: string;
|
|
579
|
-
chart_source: string;
|
|
580
|
-
title: string | null;
|
|
581
|
-
edition: number | null;
|
|
582
|
-
update_number: number | null;
|
|
583
|
-
scale_band: string | null;
|
|
584
|
-
}
|
|
585
|
-
interface CellUpdatedData extends CellEventData {
|
|
586
|
-
previous_edition: number | null;
|
|
587
|
-
previous_update_number: number | null;
|
|
588
|
-
}
|
|
589
|
-
type CellUpdatedEvent = WebhookPayload<"cell.updated", CellUpdatedData>;
|
|
590
|
-
type CellNewEvent = WebhookPayload<"cell.new", CellEventData>;
|
|
591
|
-
type CellDeletedEvent = WebhookPayload<"cell.deleted", CellEventData>;
|
|
592
|
-
/** Discriminated union of all webhook events */
|
|
593
|
-
type WebhookEvent = CellUpdatedEvent | CellNewEvent | CellDeletedEvent;
|
|
594
|
-
/** All recognised webhook event type strings */
|
|
595
|
-
type WebhookEventType = WebhookEvent["type"];
|
|
596
|
-
/**
|
|
597
|
-
* Parse and validate a raw webhook payload.
|
|
598
|
-
*
|
|
599
|
-
* @param body - The raw request body (parsed JSON object)
|
|
600
|
-
* @returns A typed `WebhookEvent`
|
|
601
|
-
* @throws Error if the payload is malformed or has an unknown event type
|
|
602
|
-
*
|
|
603
|
-
* @example
|
|
604
|
-
* ```ts
|
|
605
|
-
* import { parseWebhook } from "@chrtco/sdk";
|
|
606
|
-
*
|
|
607
|
-
* app.post("/webhooks/chrt", (req, res) => {
|
|
608
|
-
* const event = parseWebhook(req.body);
|
|
609
|
-
* switch (event.type) {
|
|
610
|
-
* case "cell.updated":
|
|
611
|
-
* console.log("Cell updated:", event.data.cell_id);
|
|
612
|
-
* break;
|
|
613
|
-
* case "cell.new":
|
|
614
|
-
* console.log("New cell:", event.data.cell_id);
|
|
615
|
-
* break;
|
|
616
|
-
* }
|
|
617
|
-
* res.sendStatus(200);
|
|
618
|
-
* });
|
|
619
|
-
* ```
|
|
620
|
-
*/
|
|
621
|
-
declare function parseWebhook(body: unknown): WebhookEvent;
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* Typed errors surfaced by `chrt.offline.*`.
|
|
625
|
-
*
|
|
626
|
-
* Callers switch on `.code` — never parse `.message`. `.status` is set only
|
|
627
|
-
* when the error originated from an HTTP response. `.detail` carries
|
|
628
|
-
* machine-readable context for programmatic handling (byte math for budget
|
|
629
|
-
* violations, `resumable: true` for interrupts, etc.).
|
|
630
|
-
*/
|
|
631
|
-
type OfflineErrorCode = "budget_exceeded" | "coverage_denied" | "quota_exceeded" | "download_corrupt" | "network_interrupted" | "partial_file_invalid" | "invalid_api_key" | "region_not_available" | "offline_not_enabled" | "missing_device_id" | "missing_manifest_path" | "sha_missing" | "unexpected_response";
|
|
632
|
-
declare class OfflineError extends Error {
|
|
633
|
-
readonly code: OfflineErrorCode;
|
|
634
|
-
readonly status?: number;
|
|
635
|
-
readonly detail?: Record<string, unknown>;
|
|
636
|
-
constructor(code: OfflineErrorCode, message: string, status?: number, detail?: Record<string, unknown>);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
577
|
/** S-52 display categories – controls default visibility */
|
|
640
578
|
type DisplayCategory = "BASE" | "STANDARD" | "OTHER" | "MARINERS" | "META";
|
|
641
579
|
/** Mapbox GL layer type we'll use for this entry */
|
|
@@ -951,6 +889,8 @@ interface NauticalSymbol {
|
|
|
951
889
|
description?: string;
|
|
952
890
|
/** S-52 Presentation Library symbol name */
|
|
953
891
|
s52PlRef?: string;
|
|
892
|
+
/** S-57 object class (e.g. "LNDMRK") when it can't be derived from s52PlRef's prefix */
|
|
893
|
+
s57Class?: string;
|
|
954
894
|
/** Grouping key for family clustering */
|
|
955
895
|
group?: string;
|
|
956
896
|
/** IDs of related variant symbols */
|
|
@@ -1168,13 +1108,6 @@ interface PmtilesVectorSource {
|
|
|
1168
1108
|
}
|
|
1169
1109
|
type VectorSourceSpec = MapboxVectorSource | PmtilesVectorSource;
|
|
1170
1110
|
type SourceMode = "mapbox" | "pmtiles";
|
|
1171
|
-
/**
|
|
1172
|
-
* Default tile-worker origin for PMTiles mode. Callers should pass
|
|
1173
|
-
* `tileBaseUrl` explicitly via `BuildSourcesOptions` to override (e.g. the
|
|
1174
|
-
* React app reads `import.meta.env.VITE_TILE_WORKER_BASE`; the offline-worker
|
|
1175
|
-
* reads `env.TILE_BASE_URL`). This constant is the prod fallback only.
|
|
1176
|
-
*/
|
|
1177
|
-
declare const DEFAULT_TILE_BASE_URL = "https://tiles.chrt.co";
|
|
1178
1111
|
/** Canonical source id used in `generateStyle()` — matches the region name
|
|
1179
1112
|
* of the one consolidated PMTiles served by the tile-worker for this region. */
|
|
1180
1113
|
declare const DEFAULT_REGION = "NOAA_ENC";
|
|
@@ -1452,6 +1385,210 @@ declare function getStyleStats(style: MapboxStyle): {
|
|
|
1452
1385
|
objectClasses: Set<string>;
|
|
1453
1386
|
};
|
|
1454
1387
|
|
|
1388
|
+
/**
|
|
1389
|
+
* Tile authentication for the `tiles.chrt.co` PMTiles path.
|
|
1390
|
+
*
|
|
1391
|
+
* The CHRT tile-worker serves raw MVT at
|
|
1392
|
+
* `https://tiles.chrt.co/v1/tiles/{region}/{z}/{x}/{y}.mvt`
|
|
1393
|
+
* and authenticates each request with a short-lived ES256 JWT (5-min default,
|
|
1394
|
+
* 15-min max) carried in the `Authorization: Bearer` header. This module mints
|
|
1395
|
+
* those JWTs from the customer's API key and produces a MapLibre / Mapbox GL
|
|
1396
|
+
* `transformRequest` that attaches the Bearer to tile requests only.
|
|
1397
|
+
*
|
|
1398
|
+
* Responsibilities (mirrors the first-party web client at
|
|
1399
|
+
* `src/lib/map/tile-token-client.ts`, adapted to be instance-scoped and
|
|
1400
|
+
* zero-dependency so it runs in browsers, Node 18+, Deno, and Bun):
|
|
1401
|
+
* - Mint via `POST {baseUrl}/mint/tile-token` (default
|
|
1402
|
+
* `https://api.chrt.co/v1/mint/tile-token`) with the `x-api-key` header.
|
|
1403
|
+
* - Cache tokens in memory, keyed by region; refresh silently 30s before
|
|
1404
|
+
* expiry so long-lived maps never flicker.
|
|
1405
|
+
* - Expose a SYNC `transformRequest` (MapLibre requires sync) that attaches
|
|
1406
|
+
* the cached Bearer; it kicks off a background mint on first use so the
|
|
1407
|
+
* cache warms within one round-trip.
|
|
1408
|
+
*
|
|
1409
|
+
* NOTE: the public mint route `POST /v1/mint/tile-token` (the sibling of the
|
|
1410
|
+
* existing `/v1/mint/offline-token`) must be present on the `api.chrt.co`
|
|
1411
|
+
* edge worker for this path to serve. Until it lands, mints fail with a
|
|
1412
|
+
* network/HTTP error surfaced through `getToken()`.
|
|
1413
|
+
*/
|
|
1414
|
+
|
|
1415
|
+
/** Default chart region — the one consolidated PMTiles served per region. */
|
|
1416
|
+
declare const DEFAULT_TILE_REGION = "NOAA_ENC";
|
|
1417
|
+
/** Default tile-worker origin. Override via `ChrtConfig.tileBaseUrl`. */
|
|
1418
|
+
declare const DEFAULT_TILE_BASE_URL = "https://tiles.chrt.co";
|
|
1419
|
+
/** Full token response from the mint endpoint. */
|
|
1420
|
+
interface TileTokenResponse {
|
|
1421
|
+
/** ES256-signed JWT; do not log. */
|
|
1422
|
+
token: string;
|
|
1423
|
+
/** Unix seconds (matches JWT `exp`). */
|
|
1424
|
+
expiresAt: number;
|
|
1425
|
+
/** Key id used to sign (matches JWT header `kid`). */
|
|
1426
|
+
kid: string;
|
|
1427
|
+
/** Build id/tag pinned into the JWT — the tile-worker cache key. */
|
|
1428
|
+
buildTag: string;
|
|
1429
|
+
/** Echo of the region the token is scoped to. */
|
|
1430
|
+
region: string;
|
|
1431
|
+
}
|
|
1432
|
+
/** Typed error codes the mint flow surfaces; callers switch on `.code`. */
|
|
1433
|
+
type TileTokenErrorCode = "invalid_api_key" | "feature_flag_disabled" | "region_not_licensed" | "tile_quota_exceeded" | "region_not_available" | "network_error" | "unexpected_response";
|
|
1434
|
+
declare class TileTokenError extends Error {
|
|
1435
|
+
readonly code: TileTokenErrorCode;
|
|
1436
|
+
readonly status?: number;
|
|
1437
|
+
constructor(code: TileTokenErrorCode, message: string, status?: number);
|
|
1438
|
+
}
|
|
1439
|
+
/** MapLibre / Mapbox GL `transformRequest` return shape. */
|
|
1440
|
+
interface TransformedRequest {
|
|
1441
|
+
url: string;
|
|
1442
|
+
headers?: Record<string, string>;
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Instance-scoped tile-token manager. One per `Chrt` client so multiple
|
|
1446
|
+
* clients (e.g. different API keys) never share a cache.
|
|
1447
|
+
*/
|
|
1448
|
+
declare class TileAuth {
|
|
1449
|
+
private readonly http;
|
|
1450
|
+
private readonly cache;
|
|
1451
|
+
private readonly pending;
|
|
1452
|
+
private readonly defaultRegion;
|
|
1453
|
+
private readonly tileBaseUrl;
|
|
1454
|
+
private lifecycleRegistered;
|
|
1455
|
+
constructor(http: HttpClient, opts?: {
|
|
1456
|
+
region?: string;
|
|
1457
|
+
tileBaseUrl?: string;
|
|
1458
|
+
});
|
|
1459
|
+
/** Mint once via the HTTP client (POST `/mint/tile-token`, `x-api-key`). */
|
|
1460
|
+
private mintOnce;
|
|
1461
|
+
/** Mint with exponential backoff on network errors only. */
|
|
1462
|
+
private mintWithRetry;
|
|
1463
|
+
private scheduleRefresh;
|
|
1464
|
+
private refreshInBackground;
|
|
1465
|
+
private store;
|
|
1466
|
+
/**
|
|
1467
|
+
* Fetch (or reuse a cached) tile token for `region`. Concurrent callers for
|
|
1468
|
+
* the same region await the same in-flight mint.
|
|
1469
|
+
*/
|
|
1470
|
+
getToken(region?: string): Promise<TileTokenResponse>;
|
|
1471
|
+
/** Synchronous cache peek — null if absent or within the stale grace window. */
|
|
1472
|
+
peek(region?: string): string | null;
|
|
1473
|
+
/**
|
|
1474
|
+
* Produce a MapLibre / Mapbox GL `transformRequest`. Attaches
|
|
1475
|
+
* `Authorization: Bearer <jwt>` only to CHRT tile URLs; style, sprite, and
|
|
1476
|
+
* glyph URLs pass through untouched (never leak the token to third-party
|
|
1477
|
+
* CDNs). Kicks off a background mint immediately so the cache warms within
|
|
1478
|
+
* one round-trip; the first tile or two may go unauthenticated and be
|
|
1479
|
+
* retried by the renderer.
|
|
1480
|
+
*/
|
|
1481
|
+
transformRequest(region?: string): (url: string) => TransformedRequest | undefined;
|
|
1482
|
+
/** Clear the cached token + timer for a region. */
|
|
1483
|
+
invalidate(region?: string): void;
|
|
1484
|
+
/**
|
|
1485
|
+
* Browser-only defense against `setTimeout` freezing while a tab is
|
|
1486
|
+
* suspended (laptop sleep, mobile background, bfcache restore): proactively
|
|
1487
|
+
* re-mint near-expiry entries on wake. Inert under SSR / Node / Deno.
|
|
1488
|
+
*/
|
|
1489
|
+
private registerLifecycleHandlers;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
/**
|
|
1493
|
+
* Generic async auto-pagination generator.
|
|
1494
|
+
*
|
|
1495
|
+
* Fetches pages from a callback that returns `{ items, total_count }` and
|
|
1496
|
+
* yields individual items until all pages are consumed or the signal is aborted.
|
|
1497
|
+
*
|
|
1498
|
+
* @example
|
|
1499
|
+
* ```ts
|
|
1500
|
+
* for await (const feature of paginate(
|
|
1501
|
+
* (offset, signal) => chrt.features({ bbox, limit: 100, offset, signal }),
|
|
1502
|
+
* f => f.features,
|
|
1503
|
+
* f => f.total_count ?? 0,
|
|
1504
|
+
* )) {
|
|
1505
|
+
* console.log(feature);
|
|
1506
|
+
* }
|
|
1507
|
+
* ```
|
|
1508
|
+
*/
|
|
1509
|
+
declare function paginate<TResponse, TItem>(fetchPage: (offset: number, signal?: AbortSignal) => Promise<TResponse>, getItems: (response: TResponse) => TItem[], getTotalCount: (response: TResponse) => number, options?: {
|
|
1510
|
+
pageSize?: number;
|
|
1511
|
+
signal?: AbortSignal;
|
|
1512
|
+
}): AsyncGenerator<TItem, void, undefined>;
|
|
1513
|
+
|
|
1514
|
+
/** Base envelope for all webhook payloads */
|
|
1515
|
+
interface WebhookPayload<T extends string, D> {
|
|
1516
|
+
/** Unique event ID */
|
|
1517
|
+
id: string;
|
|
1518
|
+
/** ISO 8601 timestamp */
|
|
1519
|
+
timestamp: string;
|
|
1520
|
+
/** Event type discriminator */
|
|
1521
|
+
type: T;
|
|
1522
|
+
/** Event-specific data */
|
|
1523
|
+
data: D;
|
|
1524
|
+
}
|
|
1525
|
+
interface CellEventData {
|
|
1526
|
+
cell_id: string;
|
|
1527
|
+
chart_source: string;
|
|
1528
|
+
title: string | null;
|
|
1529
|
+
edition: number | null;
|
|
1530
|
+
update_number: number | null;
|
|
1531
|
+
scale_band: string | null;
|
|
1532
|
+
}
|
|
1533
|
+
interface CellUpdatedData extends CellEventData {
|
|
1534
|
+
previous_edition: number | null;
|
|
1535
|
+
previous_update_number: number | null;
|
|
1536
|
+
}
|
|
1537
|
+
type CellUpdatedEvent = WebhookPayload<"cell.updated", CellUpdatedData>;
|
|
1538
|
+
type CellNewEvent = WebhookPayload<"cell.new", CellEventData>;
|
|
1539
|
+
type CellDeletedEvent = WebhookPayload<"cell.deleted", CellEventData>;
|
|
1540
|
+
/** Discriminated union of all webhook events */
|
|
1541
|
+
type WebhookEvent = CellUpdatedEvent | CellNewEvent | CellDeletedEvent;
|
|
1542
|
+
/** All recognised webhook event type strings */
|
|
1543
|
+
type WebhookEventType = WebhookEvent["type"];
|
|
1544
|
+
/**
|
|
1545
|
+
* Parse and validate a raw webhook payload.
|
|
1546
|
+
*
|
|
1547
|
+
* @param body - The raw request body (parsed JSON object)
|
|
1548
|
+
* @returns A typed `WebhookEvent`
|
|
1549
|
+
* @throws Error if the payload is malformed or has an unknown event type
|
|
1550
|
+
*
|
|
1551
|
+
* @example
|
|
1552
|
+
* ```ts
|
|
1553
|
+
* import { parseWebhook } from "@chrtco/sdk";
|
|
1554
|
+
*
|
|
1555
|
+
* app.post("/webhooks/chrt", (req, res) => {
|
|
1556
|
+
* const event = parseWebhook(req.body);
|
|
1557
|
+
* switch (event.type) {
|
|
1558
|
+
* case "cell.updated":
|
|
1559
|
+
* console.log("Cell updated:", event.data.cell_id);
|
|
1560
|
+
* break;
|
|
1561
|
+
* case "cell.new":
|
|
1562
|
+
* console.log("New cell:", event.data.cell_id);
|
|
1563
|
+
* break;
|
|
1564
|
+
* }
|
|
1565
|
+
* res.sendStatus(200);
|
|
1566
|
+
* });
|
|
1567
|
+
* ```
|
|
1568
|
+
*/
|
|
1569
|
+
declare function parseWebhook(body: unknown): WebhookEvent;
|
|
1570
|
+
|
|
1571
|
+
/**
|
|
1572
|
+
* Typed errors surfaced by `chrt.offline.*`.
|
|
1573
|
+
*
|
|
1574
|
+
* Callers switch on `.code` — never parse `.message`. `.status` is set only
|
|
1575
|
+
* when the error originated from an HTTP response. `.detail` carries
|
|
1576
|
+
* machine-readable context for programmatic handling (byte math for budget
|
|
1577
|
+
* violations, `resumable: true` for interrupts, etc.).
|
|
1578
|
+
*/
|
|
1579
|
+
type OfflineErrorCode = "budget_exceeded" | "coverage_denied" | "quota_exceeded" | "download_corrupt" | "network_interrupted" | "partial_file_invalid" | "invalid_api_key" | "region_not_available" | "offline_not_enabled" | "missing_device_id" | "missing_manifest_path" | "sha_missing" | "unexpected_response";
|
|
1580
|
+
declare class OfflineError extends Error {
|
|
1581
|
+
readonly code: OfflineErrorCode;
|
|
1582
|
+
readonly status?: number;
|
|
1583
|
+
readonly detail?: Record<string, unknown>;
|
|
1584
|
+
constructor(code: OfflineErrorCode, message: string, status?: number, detail?: Record<string, unknown>);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/** Options for `chrt.style()`. Extends the atlas style generator options. */
|
|
1588
|
+
interface ChrtStyleOptions extends StyleGeneratorOptions {
|
|
1589
|
+
/** S-52 colour palette: "DAY" (default), "DUSK", or "NIGHT". */
|
|
1590
|
+
palette?: ColorTableName;
|
|
1591
|
+
}
|
|
1455
1592
|
declare class Chrt {
|
|
1456
1593
|
/** Tile endpoints — styleUrl, tileUrl, groups */
|
|
1457
1594
|
readonly tiles: TilesEndpoint;
|
|
@@ -1468,6 +1605,9 @@ declare class Chrt {
|
|
|
1468
1605
|
private featuresEp;
|
|
1469
1606
|
private queryEp;
|
|
1470
1607
|
private http;
|
|
1608
|
+
private tileAuth;
|
|
1609
|
+
private readonly region;
|
|
1610
|
+
private readonly tileBaseUrl;
|
|
1471
1611
|
constructor(apiKeyOrConfig: string | ChrtConfig);
|
|
1472
1612
|
/** Query GeoJSON features by bounding box */
|
|
1473
1613
|
features(options: FeaturesOptions): Promise<FeatureCollection>;
|
|
@@ -1495,19 +1635,53 @@ declare class Chrt {
|
|
|
1495
1635
|
* ```
|
|
1496
1636
|
*/
|
|
1497
1637
|
cellsIter(options?: Omit<CellsOptions, "offset">): AsyncIterable<CellDetail>;
|
|
1498
|
-
/** Returns a style.json URL ready for Mapbox GL / MapLibre */
|
|
1499
|
-
styleUrl(): string;
|
|
1500
1638
|
/**
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1639
|
+
* Build a ready-to-use MapLibre / Mapbox GL style object for CHRT's nautical
|
|
1640
|
+
* charts. The default is the full IHO **S-52** portrayal; pick a palette and
|
|
1641
|
+
* tweak rendering via `opts`. The returned object is a standard MapLibre
|
|
1642
|
+
* style — mutate it freely, or build your own from scratch over the CHRT
|
|
1643
|
+
* vector source (see `buildSources`) for a fully custom look.
|
|
1644
|
+
*
|
|
1645
|
+
* Pair with `transformRequest()` so tile requests carry their auth token.
|
|
1503
1646
|
*
|
|
1504
1647
|
* @example
|
|
1505
|
-
* const map = new
|
|
1506
|
-
*
|
|
1648
|
+
* const map = new maplibregl.Map({
|
|
1649
|
+
* container: 'map',
|
|
1650
|
+
* style: chrt.style({ palette: 'DAY' }),
|
|
1507
1651
|
* transformRequest: chrt.transformRequest(),
|
|
1508
1652
|
* });
|
|
1653
|
+
*
|
|
1654
|
+
* @remarks S-101 portrayal is on the roadmap; today `style()` emits S-52.
|
|
1655
|
+
*/
|
|
1656
|
+
style(opts?: ChrtStyleOptions): MapboxStyle;
|
|
1657
|
+
/**
|
|
1658
|
+
* @deprecated CHRT serves no remote `style.json`. Use {@link style} to get a
|
|
1659
|
+
* MapLibre style object instead. Throws to avoid silently pointing a map at a
|
|
1660
|
+
* dead URL.
|
|
1661
|
+
*/
|
|
1662
|
+
styleUrl(): never;
|
|
1663
|
+
/**
|
|
1664
|
+
* Returns a `transformRequest` for Mapbox GL JS / MapLibre GL JS that mints a
|
|
1665
|
+
* short-lived tile JWT from your API key and attaches it as
|
|
1666
|
+
* `Authorization: Bearer` on requests to `tiles.chrt.co` only. Style, sprite,
|
|
1667
|
+
* and glyph URLs pass through untouched. The cache warms in the background on
|
|
1668
|
+
* first call, so the first tile or two may be retried by the renderer.
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
* const map = new maplibregl.Map({
|
|
1672
|
+
* style: chrt.style(),
|
|
1673
|
+
* transformRequest: chrt.transformRequest(),
|
|
1674
|
+
* });
|
|
1675
|
+
*/
|
|
1676
|
+
transformRequest(opts?: {
|
|
1677
|
+
region?: string;
|
|
1678
|
+
}): (url: string) => TransformRequest | undefined;
|
|
1679
|
+
/**
|
|
1680
|
+
* Pre-mint the tile token for a region. Optional — `transformRequest()` warms
|
|
1681
|
+
* the cache automatically — but useful if you want to surface a mint error
|
|
1682
|
+
* (e.g. `region_not_licensed`, `tile_quota_exceeded`) before the map loads.
|
|
1509
1683
|
*/
|
|
1510
|
-
|
|
1684
|
+
warmTiles(region?: string): Promise<void>;
|
|
1511
1685
|
}
|
|
1512
1686
|
|
|
1513
|
-
export { type AtlasStyle, BAND_DRAW_ORDER, BAND_PRIORITY_RANGES, type BBox, BUILD_MAXZOOM, BUILD_MINZOOM, type BandCode, type BandPriorityRange, type BuildOfflineStyleOptions, type BuildSourcesOptions, CHART_BAND_CODES, CHART_CASCADE_CODES, CHART_SECTIONS, type CellDeletedEvent, type CellDetail, type CellEventData, type CellNewEvent, type CellUpdatedData, type CellUpdatedEvent, type CellsOptions, type CellsResponse, type ChartSection, Chrt, type ChrtConfig, ChrtError, ColorTableName, type CoverageOptions, type CoverageResponse, type CoverageSource, DEFAULT_REGION, DEFAULT_TILE_BASE_URL, type DisplayCategory, type DisplayMode, type FeatureCollection, type FeaturesOptions, FileSystemAdapter, type GeoJsonFeature, type GeoJsonGeometry, type GeomType, LABELED_LAYERS, LABEL_BEHAVIOR, type LabelBehavior, type LabelConfigOptions, type LabelLayerConfig, type LookupEntry, type MapLibreStyle, type MapboxStyle, type MapboxVectorSource, NAUTICAL_SYMBOLS, type NauticalCategory, type NauticalSymbol, type OfflineBundleResponse, type OfflineDownloadOptions, type OfflineDownloadProgress, type OfflineDownloadResult, OfflineError, type OfflineErrorCode, type OfflineFetchStyleOptions, type OfflineHeartbeatOptions, type OfflineRegionSummary, type OfflineRemoveOptions, OfflineStyleError, type OfflineStylePlatform, type OfflineStyleResponse, type PmtilesVectorSource, type QueryOptions, type ResolvedStyle, type RouteFeatureQueryOptions, type RouteFeatureQueryResponse, type RouteQueryOptions, type RouteQueryResponse, type S101Feature, S101_CHART_SECTIONS, S101_FEATURES, S101_NEW_SYMBOLS, S101_SYMBOL_GROUPS, S52_DRAW_ORDER, S52_LOOKUP, SYMBOL_GROUPS, SYMBOL_MAP, type ScaleBand, type SourceMode, type StyleGeneratorOptions, type StyleLayer, type SymbolGroup, type TileGroup, type TileGroupsResponse, type TransformRequest, type VectorSourceSpec, type WebhookEvent, type WebhookEventType, type WebhookPayload, applyColorTheme, bandFilterExpression, buildLabelLayer, buildLayersForClass, buildOfflineStyle, buildSources, combineWithBandFilter, daymarkColor, decimateFeatures, depareColor, depareFillExpression, generateSpriteManifest, generateSpriteSheet, generateStyle, generateStyleJSON, getAvailableLineSymbols, getAvailablePatterns, getAvailablePointSymbols, getCollisionSettings, getDrawPriority, getGridSizeForZoom, getIconExpression, getLabelBehavior, getLabelConfig, getLookupEntry, getMaxCellsForZoom, getOrderedClasses, getS52SvgString, getS52SymbolStats, getStyleStats, getSymbolSvgString, getThemedS52Svg, hazardColor, hazardFillExpression, isNavAidLayer, isVisibleInMode, lateralColor, lateralFillExpression, lightColor, lightFillExpression, paginate, parseWebhook, preprocessLights, preprocessNavAids, preprocessSoundings, preprocessWaterBodies, resolveStyle, scaminToMinZoom, withinBboxFilter, worldMinusBboxPolygon };
|
|
1687
|
+
export { type AtlasStyle, BAND_DRAW_ORDER, BAND_PRIORITY_RANGES, type BBox, BUILD_MAXZOOM, BUILD_MINZOOM, type BandCode, type BandPriorityRange, type BuildOfflineStyleOptions, type BuildSourcesOptions, CHART_BAND_CODES, CHART_CASCADE_CODES, CHART_SECTIONS, type CellDeletedEvent, type CellDetail, type CellEventData, type CellNewEvent, type CellUpdatedData, type CellUpdatedEvent, type CellsOptions, type CellsResponse, type ChartSection, Chrt, type ChrtConfig, ChrtError, type ChrtStyleOptions, ColorTableName, type CoverageOptions, type CoverageResponse, type CoverageSource, DEFAULT_REGION, DEFAULT_TILE_BASE_URL, DEFAULT_TILE_REGION, type DisplayCategory, type DisplayMode, type FeatureCollection, type FeaturesOptions, FileSystemAdapter, type GeoJsonFeature, type GeoJsonGeometry, type GeomType, LABELED_LAYERS, LABEL_BEHAVIOR, type LabelBehavior, type LabelConfigOptions, type LabelLayerConfig, type LookupEntry, type MapLibreStyle, type MapboxStyle, type MapboxVectorSource, NAUTICAL_SYMBOLS, type NauticalCategory, type NauticalSymbol, type OfflineBundleResponse, type OfflineDownloadOptions, type OfflineDownloadProgress, type OfflineDownloadResult, OfflineError, type OfflineErrorCode, type OfflineFetchStyleOptions, type OfflineHeartbeatOptions, type OfflineRegionSummary, type OfflineRemoveOptions, OfflineStyleError, type OfflineStylePlatform, type OfflineStyleResponse, type PmtilesVectorSource, type QueryOptions, type ResolvedStyle, type RouteFeatureQueryOptions, type RouteFeatureQueryResponse, type RouteQueryOptions, type RouteQueryResponse, type S101Feature, S101_CHART_SECTIONS, S101_FEATURES, S101_NEW_SYMBOLS, S101_SYMBOL_GROUPS, S52_DRAW_ORDER, S52_LOOKUP, SYMBOL_GROUPS, SYMBOL_MAP, type ScaleBand, type SourceMode, type StyleGeneratorOptions, type StyleLayer, type SymbolGroup, TileAuth, type TileGroup, type TileGroupsResponse, TileTokenError, type TileTokenErrorCode, type TileTokenResponse, type TransformRequest, type TransformedRequest, type VectorSourceSpec, type WebhookEvent, type WebhookEventType, type WebhookPayload, applyColorTheme, bandFilterExpression, buildLabelLayer, buildLayersForClass, buildOfflineStyle, buildSources, combineWithBandFilter, daymarkColor, decimateFeatures, depareColor, depareFillExpression, generateSpriteManifest, generateSpriteSheet, generateStyle, generateStyleJSON, getAvailableLineSymbols, getAvailablePatterns, getAvailablePointSymbols, getCollisionSettings, getDrawPriority, getGridSizeForZoom, getIconExpression, getLabelBehavior, getLabelConfig, getLookupEntry, getMaxCellsForZoom, getOrderedClasses, getS52SvgString, getS52SymbolStats, getStyleStats, getSymbolSvgString, getThemedS52Svg, hazardColor, hazardFillExpression, isNavAidLayer, isVisibleInMode, lateralColor, lateralFillExpression, lightColor, lightFillExpression, paginate, parseWebhook, preprocessLights, preprocessNavAids, preprocessSoundings, preprocessWaterBodies, resolveStyle, scaminToMinZoom, withinBboxFilter, worldMinusBboxPolygon };
|