@tileflow/static 0.1.0-alpha.24 → 0.1.0-alpha.26
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/README.md +79 -19
- package/dist/{chunk-N63IFMFM.js → chunk-RGXE4HDY.js} +6 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
# @tileflow/static
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Validate static map scenes, author overlays, and request hosted image renders. The client follows
|
|
4
|
+
an asynchronous operation until an immutable image is ready. It does not display the image or
|
|
5
|
+
provide an interactive map.
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
> Related packages and guides: [documentation index](https://raw.githubusercontent.com/tileflow/tileflow-sdk/main/llms.txt).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @tileflow/static@alpha
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Validation and overlay authoring work without a hosted account. Creating a render needs a deployed
|
|
16
|
+
Tileflow map, an enabled Static Maps service, and an authorized credential. Run authenticated
|
|
17
|
+
requests on a trusted server with `fetch` available, such as Node.js 22 or newer. Keep credentials
|
|
18
|
+
out of browser bundles. A React application can use
|
|
19
|
+
[`@tileflow/react/static`](https://github.com/tileflow/tileflow-sdk/blob/main/packages/react/README.md)
|
|
20
|
+
through its own authorized server endpoint.
|
|
21
|
+
|
|
22
|
+
## Create a render
|
|
8
23
|
|
|
9
24
|
Every scene names one concrete `theme`. The browser-only `"system"` selector is rejected so hashes,
|
|
10
25
|
cache keys, receipts, and regenerated images remain reproducible.
|
|
@@ -13,14 +28,19 @@ Scene, size, camera, attribution, padding, and overlay objects are strict. Unkno
|
|
|
13
28
|
rejected instead of being removed during normalization, so misspelled or unsupported options cannot
|
|
14
29
|
silently share another scene's identity.
|
|
15
30
|
|
|
31
|
+
<!-- docs:check -->
|
|
32
|
+
|
|
16
33
|
```ts
|
|
17
34
|
import {
|
|
18
35
|
createStaticMapIdempotencyKey,
|
|
19
36
|
marker,
|
|
20
|
-
|
|
37
|
+
createStaticMap,
|
|
21
38
|
validateStaticScene,
|
|
22
39
|
} from '@tileflow/static';
|
|
23
40
|
|
|
41
|
+
const apiKey = process.env.TILEFLOW_API_KEY;
|
|
42
|
+
if (!apiKey) throw new Error('Set TILEFLOW_API_KEY on the server.');
|
|
43
|
+
|
|
24
44
|
const scene = validateStaticScene({
|
|
25
45
|
map: 'madrid',
|
|
26
46
|
theme: 'dark',
|
|
@@ -32,14 +52,27 @@ const scene = validateStaticScene({
|
|
|
32
52
|
|
|
33
53
|
if (!scene.ok) throw new Error(scene.error);
|
|
34
54
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
const idempotencyKey = createStaticMapIdempotencyKey();
|
|
56
|
+
const result = await createStaticMap(scene.scene, {
|
|
57
|
+
apiKey,
|
|
58
|
+
idempotencyKey,
|
|
38
59
|
});
|
|
39
60
|
|
|
40
|
-
console.log(result.attribution.entries);
|
|
61
|
+
console.log(result.imageUrl, result.attribution.entries);
|
|
41
62
|
```
|
|
42
63
|
|
|
64
|
+
`map: 'madrid'` is the deployed portable map name; replace it with yours. For a Team credential,
|
|
65
|
+
pass the destination's public `mapId` separately in the request options, as described below.
|
|
66
|
+
`createStaticMap` and `precacheStaticMap` both return a hosted result with `resultVersion: 1`, an
|
|
67
|
+
operation ID, image URL, and attribution. Use precache for cache warming, not as a free validation
|
|
68
|
+
operation. Neither helper is the same as `<Map mode="image">`, which only displays an existing image.
|
|
69
|
+
|
|
70
|
+
Create one idempotency key per intentional action and retain it across retries. Do not put the key
|
|
71
|
+
factory inside a retry callback. The helper handles polling; cancellation or a timeout does not
|
|
72
|
+
prove that the server did no work.
|
|
73
|
+
|
|
74
|
+
## Image size and format
|
|
75
|
+
|
|
43
76
|
`width` and `height` are logical CSS pixels. `dpr` accepts 1 or 2 and defaults to 1, so a 600 by
|
|
44
77
|
400 scene at DPR 2 produces a 1200 by 800 image without changing camera, padding, or overlay paint
|
|
45
78
|
sizes. Logical dimensions may reach 2048 per axis; the physical budget permits 4096 by 4096 output,
|
|
@@ -119,24 +152,39 @@ bounds cameras never move.
|
|
|
119
152
|
|
|
120
153
|
Choose a corner when composition requires it:
|
|
121
154
|
|
|
155
|
+
<!-- docs:check -->
|
|
156
|
+
|
|
122
157
|
```ts
|
|
123
|
-
|
|
158
|
+
import type {StaticAttributionRequest} from '@tileflow/static';
|
|
159
|
+
|
|
160
|
+
const attribution = {
|
|
161
|
+
mode: 'embedded',
|
|
162
|
+
position: 'bottom-left',
|
|
163
|
+
} satisfies StaticAttributionRequest;
|
|
124
164
|
```
|
|
125
165
|
|
|
126
166
|
Or request structured external attribution:
|
|
127
167
|
|
|
168
|
+
<!-- docs:check -->
|
|
169
|
+
|
|
128
170
|
```ts
|
|
171
|
+
import {createStaticMap, createStaticMapIdempotencyKey} from '@tileflow/static';
|
|
172
|
+
|
|
173
|
+
const apiKey = process.env.TILEFLOW_API_KEY;
|
|
174
|
+
if (!apiKey) throw new Error('Set TILEFLOW_API_KEY on the server.');
|
|
175
|
+
|
|
129
176
|
const result = await createStaticMap(
|
|
130
|
-
{...scene.scene, attribution: {mode: 'external'}},
|
|
131
177
|
{
|
|
132
|
-
|
|
133
|
-
|
|
178
|
+
map: 'madrid',
|
|
179
|
+
theme: 'dark',
|
|
180
|
+
camera: {type: 'center', center: [-3.7038, 40.4168], zoom: 12},
|
|
181
|
+
size: {width: 600, height: 400},
|
|
182
|
+
attribution: {mode: 'external'},
|
|
134
183
|
},
|
|
184
|
+
{apiKey, idempotencyKey: createStaticMapIdempotencyKey()},
|
|
135
185
|
);
|
|
136
186
|
|
|
137
|
-
|
|
138
|
-
renderAttributionText(entry.text, entry.links);
|
|
139
|
-
}
|
|
187
|
+
console.log(JSON.stringify({imageUrl: result.imageUrl, entries: result.attribution.entries}));
|
|
140
188
|
```
|
|
141
189
|
|
|
142
190
|
External mode leaves the image unchanged and returns `position: null`. The caller must retain and
|
|
@@ -157,12 +205,12 @@ measurement, anchor, scale, and offset. It works with Mercator and Globe styles
|
|
|
157
205
|
can be shown. It never clips silently.
|
|
158
206
|
|
|
159
207
|
```ts
|
|
160
|
-
camera
|
|
208
|
+
const camera = {
|
|
161
209
|
type: 'auto',
|
|
162
210
|
padding: {top: 24, right: 240, bottom: 24, left: 24},
|
|
163
211
|
maxZoom: 16,
|
|
164
212
|
bearing: 0,
|
|
165
|
-
}
|
|
213
|
+
} as const;
|
|
166
214
|
```
|
|
167
215
|
|
|
168
216
|
Padding uses logical CSS pixels. A number applies to every side; omitted sides in an object are
|
|
@@ -180,6 +228,8 @@ Current overlay primitives use MapLibre's GeoJSON pipeline and require
|
|
|
180
228
|
clamping them. A Globe basemap may display polar regions even though these overlay primitives cannot
|
|
181
229
|
yet be drawn there.
|
|
182
230
|
|
|
231
|
+
## Handle failures
|
|
232
|
+
|
|
183
233
|
Deterministic request failures return `422`, set `retryable: false`, and preserve a stable code,
|
|
184
234
|
reason, and bounded details. `validateStaticScene` returns that document; request helpers throw
|
|
185
235
|
`StaticMapRequestError` either locally or from the Hosted response. The reasons distinguish an empty
|
|
@@ -195,6 +245,8 @@ Other bounded Hosted JSON failures throw `StaticMapError`. It preserves HTTP `st
|
|
|
195
245
|
`null`. `StaticMapRequestError` extends the same class. Malformed, oversized, or unsafe remote
|
|
196
246
|
documents remain generic errors and are never reflected to the caller.
|
|
197
247
|
|
|
248
|
+
## API entry points
|
|
249
|
+
|
|
198
250
|
The package has four deliberately separate surfaces, all available from the root for compatibility:
|
|
199
251
|
|
|
200
252
|
- scene validation and normalization: `staticSceneSchema`, `validateStaticScene`, and
|
|
@@ -215,6 +267,8 @@ anchors, and resolved sprite dimensions. Its top-level `mapId` identifies the re
|
|
|
215
267
|
while `scene.map` retains the portable map name supplied by the application. It is unrelated to the
|
|
216
268
|
runtime delivery manifest generated by application build or deploy workflows.
|
|
217
269
|
|
|
270
|
+
## Operation identity and usage
|
|
271
|
+
|
|
218
272
|
Create one idempotency key per intentional create/precache action and retain it across network
|
|
219
273
|
retries. Reusing the key with the same normalized scene returns the stored result; reusing it with a
|
|
220
274
|
different scene returns 409. A successful paid operation reports `unitCost: 15`, shared
|
|
@@ -236,4 +290,10 @@ Free cannot initiate Static Maps work. Starter consumes 15 shared API units for
|
|
|
236
290
|
logical operation, including a distinct-key cache reuse. Downloading an immutable PNG, JPEG, or WebP
|
|
237
291
|
consumes zero units.
|
|
238
292
|
|
|
239
|
-
|
|
293
|
+
## Team credentials
|
|
294
|
+
|
|
295
|
+
A Team credential can serve multiple Maps. Pass `mapId` in the options to `createStaticMap` or
|
|
296
|
+
`precacheStaticMap`; it must be a Managed Map ID such as `map_1234567890abcdef`. The client sends
|
|
297
|
+
`X-Tileflow-Map-Id` separately from the portable scene. `scene.map` remains the deployed environment
|
|
298
|
+
name. The Hosted API must support unified Team credentials and authorize the selected Map.
|
|
299
|
+
Existing Map-scoped keys remain usable without this option. Keep either key on a trusted server.
|
|
@@ -136,6 +136,12 @@ async function requestStaticMapUntilReady(request, options) {
|
|
|
136
136
|
if (options.apiKey) {
|
|
137
137
|
headers.Authorization = `Bearer ${options.apiKey}`;
|
|
138
138
|
}
|
|
139
|
+
if (options.mapId !== void 0) {
|
|
140
|
+
if (!/^map_[A-Za-z0-9_-]{16}$/u.test(options.mapId)) {
|
|
141
|
+
throw new Error("Invalid Tileflow Map ID.");
|
|
142
|
+
}
|
|
143
|
+
headers["X-Tileflow-Map-Id"] = options.mapId;
|
|
144
|
+
}
|
|
139
145
|
return runWithinStaticMapBudget(maxWaitMs, options.signal, async (signal) => {
|
|
140
146
|
let operationId = null;
|
|
141
147
|
while (true) {
|
package/dist/client.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ type StaticMapHostedResult = StaticMapResultBase & Readonly<{
|
|
|
39
39
|
type StaticMapResult = StaticMapImageResult | StaticMapHostedResult;
|
|
40
40
|
type StaticMapCreateOptions = {
|
|
41
41
|
apiKey?: string;
|
|
42
|
+
mapId?: string;
|
|
42
43
|
apiUrl?: string;
|
|
43
44
|
fetch?: typeof fetch;
|
|
44
45
|
idempotencyKey: string;
|
package/dist/client.js
CHANGED
package/dist/index.js
CHANGED