@nordhavnhq/beacon 0.6.0 → 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/README.md +4 -3
- package/dist/{cache-q8uLEGYg.d.cts → cache-DIs1jN1m.d.cts} +8 -3
- package/dist/{cache-q8uLEGYg.d.ts → cache-DIs1jN1m.d.ts} +8 -3
- package/dist/chunk-FLRBCD6H.js +361 -0
- package/dist/chunk-FLRBCD6H.js.map +1 -0
- package/dist/file-store.cjs +293 -34
- package/dist/file-store.cjs.map +1 -1
- package/dist/file-store.d.cts +10 -24
- package/dist/file-store.d.ts +10 -24
- package/dist/file-store.js +34 -128
- package/dist/file-store.js.map +1 -1
- package/dist/index.cjs +1443 -106
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +225 -81
- package/dist/index.d.ts +225 -81
- package/dist/index.js +1085 -103
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as CacheOptions } from './cache-
|
|
2
|
-
export { a as CacheEntry, C as CacheStore, c as ContentCache, M as MemoryCacheStore } from './cache-
|
|
1
|
+
import { b as CacheOptions } from './cache-DIs1jN1m.cjs';
|
|
2
|
+
export { a as CacheEntry, C as CacheStore, c as ContentCache, M as MemoryCacheStore } from './cache-DIs1jN1m.cjs';
|
|
3
3
|
import { C as ChartData } from './chart-CxtDbYAs.cjs';
|
|
4
4
|
export { A as AGGREGATIONS, a as Aggregation, B as BUCKET_MODES, b as BucketMode, c as CHART_AXES, d as CHART_SORTS, e as CHART_TYPES, f as CHART_TYPE_INFO, g as ChartAxis, h as ChartFamily, i as ChartSeriesData, j as ChartSeriesSpec, k as ChartSort, l as ChartSpec, m as ChartType, n as ChartTypeInfo, D as DATE_BUCKET_VALUES, o as DateBucket, P as PALETTE_KEYS, p as PaletteKey, q as chartTypeInfo, r as isBarChart, s as isPartChart } from './chart-CxtDbYAs.cjs';
|
|
5
5
|
|
|
@@ -102,13 +102,33 @@ interface UploadedFile {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* which is exactly when caching must get out of the way - see `forRequest`.
|
|
105
|
+
* Where beacon's lines go: the client's `logger` option. Both methods are
|
|
106
|
+
* optional; a missing one drops that level.
|
|
108
107
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
interface Logger {
|
|
109
|
+
info?(...args: unknown[]): void;
|
|
110
|
+
warn?(...args: unknown[]): void;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The hosted platform. Used when no `baseUrl` is passed or set in the environment. */
|
|
111
114
|
declare const DEFAULT_BASE_URL = "https://beacon.nordhavn.ai";
|
|
115
|
+
/** The `cache` option of a client: `CacheOptions` and the disk cache, which only a client builds. */
|
|
116
|
+
interface ClientCacheOptions extends CacheOptions {
|
|
117
|
+
/**
|
|
118
|
+
* Keep the cache on disk too, in this directory, so a process that restarts
|
|
119
|
+
* while the studio is down still has the last good content (Node 22.3 or
|
|
120
|
+
* later). Put it on a volume that survives a redeploy. An empty string
|
|
121
|
+
* counts as not given, so `dir: process.env.CACHE_DIR` works unset.
|
|
122
|
+
*
|
|
123
|
+
* The entries go in a folder of `dir` named after a short hash of the
|
|
124
|
+
* server and the key (never the key itself), so sites, or a developer's
|
|
125
|
+
* keys, sharing a directory never see each other's content. Folders of
|
|
126
|
+
* beacon's that went unused for 30 days are removed when a client starts;
|
|
127
|
+
* nothing else in `dir` is touched. Not with `store`.
|
|
128
|
+
*/
|
|
129
|
+
dir?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
112
132
|
/** A studio failure the client absorbed, handed to `onError`. */
|
|
113
133
|
interface StudioFailure {
|
|
114
134
|
/**
|
|
@@ -118,19 +138,28 @@ interface StudioFailure {
|
|
|
118
138
|
during: 'stamp-check' | 'read';
|
|
119
139
|
/** Cache key of the entry that could not be refreshed. Only for `read`. */
|
|
120
140
|
key?: string;
|
|
121
|
-
/** What went wrong: a `
|
|
141
|
+
/** What went wrong: a `NordhavnError`, a `TimeoutError`, a network error. */
|
|
122
142
|
error: unknown;
|
|
123
143
|
}
|
|
124
|
-
interface
|
|
144
|
+
interface NordhavnClientOptions {
|
|
125
145
|
/**
|
|
126
146
|
* Project API key, `slk_...`. Mint one in the project's settings under
|
|
127
147
|
* "API keys". Its reach is the union of its per-node read/write scopes.
|
|
148
|
+
*
|
|
149
|
+
* Left out of the options altogether, it is read from the environment
|
|
150
|
+
* variable `NORDHAVN_API_KEY` (`process.env`, where the runtime has one). A
|
|
151
|
+
* key passed here always wins. Passed without a value (`undefined`, as from
|
|
152
|
+
* an unset variable of the site's own, or an empty string) it throws, as up
|
|
153
|
+
* to 0.7: it never falls back to the environment.
|
|
128
154
|
*/
|
|
129
|
-
apiKey
|
|
155
|
+
apiKey?: string;
|
|
130
156
|
/**
|
|
131
|
-
* Base URL of your
|
|
132
|
-
*
|
|
133
|
-
* `
|
|
157
|
+
* Base URL of your server, without a trailing `/api/content` (that path is
|
|
158
|
+
* appended automatically). Left out of the options altogether, it is read
|
|
159
|
+
* from the environment variable `NORDHAVN_BASE_URL`, else it is the hosted
|
|
160
|
+
* platform (`DEFAULT_BASE_URL`). A URL passed here always wins; passed as
|
|
161
|
+
* `undefined` it is the hosted platform, as up to 0.7; an empty string
|
|
162
|
+
* throws.
|
|
134
163
|
*/
|
|
135
164
|
baseUrl?: string;
|
|
136
165
|
/**
|
|
@@ -140,8 +169,8 @@ interface HavenClientOptions {
|
|
|
140
169
|
* locale. Discover available locales with `client.locales()`.
|
|
141
170
|
*/
|
|
142
171
|
locale?: string;
|
|
143
|
-
/** Read caching. Pass `false` to disable, or an options object to tune it. */
|
|
144
|
-
cache?: boolean |
|
|
172
|
+
/** Read caching. Pass `false` to disable, or an options object to tune it (and `dir` to keep it on disk). */
|
|
173
|
+
cache?: boolean | ClientCacheOptions;
|
|
145
174
|
/** Custom `fetch` implementation. Defaults to the global `fetch`. */
|
|
146
175
|
fetch?: typeof fetch;
|
|
147
176
|
/**
|
|
@@ -154,10 +183,21 @@ interface HavenClientOptions {
|
|
|
154
183
|
* once-a-minute stamp check uses at most 3 seconds of it, as every read in
|
|
155
184
|
* that moment waits on the check.
|
|
156
185
|
*
|
|
157
|
-
*
|
|
158
|
-
* studio, so do not blindly send it again: you could store it twice.
|
|
186
|
+
* Writes and uploads have their own, longer deadline: `writeTimeout`.
|
|
159
187
|
*/
|
|
160
188
|
timeout?: number;
|
|
189
|
+
/**
|
|
190
|
+
* Give up on a write (`createRecord`, `updateRecord`) after this many ms,
|
|
191
|
+
* body included. Default: `timeout`, but at least `30000`; `0` disables it,
|
|
192
|
+
* as does a client `timeout` of `0` when this is not set. An upload gets
|
|
193
|
+
* this too, but at least 60 s.
|
|
194
|
+
*
|
|
195
|
+
* Longer than a read's on purpose. A read that times out serves its cached
|
|
196
|
+
* value; a write that times out may still have reached the studio, and the
|
|
197
|
+
* visitor sees an error for a form that arrived. Do not blindly send it
|
|
198
|
+
* again: you could store it twice.
|
|
199
|
+
*/
|
|
200
|
+
writeTimeout?: number;
|
|
161
201
|
/**
|
|
162
202
|
* A read with nothing cached that gets a `502` or `503` tries once more after
|
|
163
203
|
* this many ms, plus up to as many again at random (so the reads of one page
|
|
@@ -165,10 +205,36 @@ interface HavenClientOptions {
|
|
|
165
205
|
*
|
|
166
206
|
* Often one bad moment, such as a proxy switching to a new studio container;
|
|
167
207
|
* and with nothing cached the error is all the caller would get. Never for a
|
|
168
|
-
* read with a value cached (that value is served), a
|
|
169
|
-
*
|
|
208
|
+
* read with a value cached (that value is served), a `cache: false` read,
|
|
209
|
+
* a write, or an answer carrying `Retry-After`.
|
|
170
210
|
*/
|
|
171
211
|
gatewayRetry?: number | false;
|
|
212
|
+
/**
|
|
213
|
+
* How long, in ms from when it began, a read with nothing cached (or a
|
|
214
|
+
* `cache: false` read) may wait for the studio's rate limit. Default
|
|
215
|
+
* `10000`. `false` turns waiting off: a `429` is thrown at once.
|
|
216
|
+
*
|
|
217
|
+
* The studio's own `429` with `Retry-After` shuts a gate for this server
|
|
218
|
+
* and key in the process, until the time it names but at most a minute:
|
|
219
|
+
* reads with nothing cached hold back until then, instead of going out to
|
|
220
|
+
* be refused as well, and the one that was refused is sent again, at most
|
|
221
|
+
* twice. A `429` from something in front of the studio (a proxy's page)
|
|
222
|
+
* shuts no gate; only the read it refused waits. Each adds a random spread to its
|
|
223
|
+
* wait (up to a fifth of it, at least up to 1 s), so they do not come back
|
|
224
|
+
* together. A wait that would end more than `rateLimitWait` after the read
|
|
225
|
+
* began is not started; the random spread may take a read a little past it.
|
|
226
|
+
* While the gate is shut nothing is sent that would only be refused: a
|
|
227
|
+
* read that cannot wait for it (or has a value cached, or with `false`)
|
|
228
|
+
* fails as a `429` would, without a request: a cached value is served,
|
|
229
|
+
* else that `429` is thrown.
|
|
230
|
+
*
|
|
231
|
+
* The studio limits the requests per key and asks to wait a few seconds at
|
|
232
|
+
* most; with nothing to show instead, waiting is better than an error. A
|
|
233
|
+
* build that reads everything at once may want more. Never for a read with
|
|
234
|
+
* a value cached (that value is served), a write, an upload, or a `429`
|
|
235
|
+
* without `Retry-After`.
|
|
236
|
+
*/
|
|
237
|
+
rateLimitWait?: number | false;
|
|
172
238
|
/**
|
|
173
239
|
* Called for every studio failure the client absorbs: a failed stamp check,
|
|
174
240
|
* or a read answered from the cache because its refresh failed. These never
|
|
@@ -177,18 +243,41 @@ interface HavenClientOptions {
|
|
|
177
243
|
* (a read with nothing cached, a write) are not repeated here.
|
|
178
244
|
*
|
|
179
245
|
* At most one call per stamp check and one per cache entry per retry pause,
|
|
180
|
-
* so it is safe to log or alert from. Without it the client
|
|
181
|
-
*
|
|
246
|
+
* so it is safe to log or alert from. Without it the client writes one
|
|
247
|
+
* warning per outage to `logger`.
|
|
182
248
|
*/
|
|
183
249
|
onError?: (failure: StudioFailure) => void;
|
|
184
250
|
/** Extra headers merged into every request. */
|
|
185
251
|
headers?: Record<string, string>;
|
|
186
252
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
|
|
191
|
-
|
|
253
|
+
* Hold a live connection to the studio, which tells the moment content
|
|
254
|
+
* changes, so an edit shows at the next read instead of up to `revalidate`
|
|
255
|
+
* later. While it is up, reads skip the once-a-minute stamp check; when it
|
|
256
|
+
* is down, they make it as before. It only ever replaces that check: it
|
|
257
|
+
* fetches no content itself, keeps no process alive, and cannot fail a read.
|
|
258
|
+
*
|
|
259
|
+
* On by default in a long-lived Node process, for a client with a cache.
|
|
260
|
+
* Off by default on serverless and in CI (`VERCEL`, `NETLIFY`, AWS Lambda,
|
|
261
|
+
* Azure Functions, Google Cloud Functions and Cloud Run, Deno Deploy, `CI`),
|
|
262
|
+
* with `cache.waitForFresh: false`, and with a custom `fetch` (the
|
|
263
|
+
* connection goes over Node's `http`, not through it); `true` turns it on
|
|
264
|
+
* there. Never in a browser or an edge runtime, nor without a cache or with
|
|
265
|
+
* `revalidate: false`. One connection per server and key in a process, shared
|
|
266
|
+
* by every client with those.
|
|
267
|
+
*/
|
|
268
|
+
live?: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* Where beacon writes its lines. Default: the console. `false` writes
|
|
271
|
+
* nothing at all. Every line goes here: once per process what a file cache
|
|
272
|
+
* found on disk; in development (`NODE_ENV` is `development`, not in CI)
|
|
273
|
+
* which project and key the client reads with, `connected to "<project>"
|
|
274
|
+
* (key "<key>")`; and the warnings: an outage (unless `onError` is set), a
|
|
275
|
+
* disk the cache cannot use (unless the `FileCacheStore` has its own
|
|
276
|
+
* `onError`), a store shared by two keys, a Node too old for `cache.dir`.
|
|
277
|
+
* Each line is one string, prefixed `[@nordhavnhq/beacon]`, sometimes with
|
|
278
|
+
* the error's message as a second argument.
|
|
279
|
+
*/
|
|
280
|
+
logger?: Logger | false;
|
|
192
281
|
}
|
|
193
282
|
/** Per-call read options. */
|
|
194
283
|
interface ReadOptions {
|
|
@@ -214,9 +303,10 @@ interface UploadOptions {
|
|
|
214
303
|
filename?: string;
|
|
215
304
|
/**
|
|
216
305
|
* Give up after this many ms, body included. Defaults to the client's
|
|
217
|
-
* `
|
|
218
|
-
* client
|
|
219
|
-
* number or `NaN` counts
|
|
306
|
+
* `writeTimeout`, but at least 60 s (an upload may be 10 MB); `0` for none.
|
|
307
|
+
* A client whose writes have no timeout (`writeTimeout: 0`, or `timeout: 0`
|
|
308
|
+
* without one) uploads without one too. A negative number or `NaN` counts
|
|
309
|
+
* as not given.
|
|
220
310
|
*/
|
|
221
311
|
timeout?: number;
|
|
222
312
|
}
|
|
@@ -226,30 +316,38 @@ interface UploadOptions {
|
|
|
226
316
|
* writes invalidate the affected cache entries automatically.
|
|
227
317
|
*
|
|
228
318
|
* ```ts
|
|
229
|
-
* const studio = new
|
|
319
|
+
* const studio = new NordhavnClient({ apiKey: 'slk_...', baseUrl: 'https://studio.example.com' })
|
|
230
320
|
* const posts = await studio.dataset<Post>('blog', 'posts').list()
|
|
231
321
|
* ```
|
|
322
|
+
*
|
|
323
|
+
* With `NORDHAVN_API_KEY` (and for a self-hosted studio `NORDHAVN_BASE_URL`)
|
|
324
|
+
* in the environment, `new NordhavnClient()` is enough.
|
|
232
325
|
*/
|
|
233
|
-
declare class
|
|
326
|
+
declare class NordhavnClient {
|
|
234
327
|
private readonly apiKey;
|
|
235
328
|
private readonly baseUrl;
|
|
236
329
|
private readonly fetchImpl;
|
|
237
330
|
private readonly headers;
|
|
238
331
|
private readonly cache;
|
|
239
332
|
private readonly versionTracker;
|
|
240
|
-
/**
|
|
241
|
-
|
|
242
|
-
* default. The one field such a view has of its own; all the rest is shared.
|
|
243
|
-
*/
|
|
244
|
-
private readDefault;
|
|
333
|
+
/** The client's share of the live connection, when it has one (`live` option). */
|
|
334
|
+
private live;
|
|
245
335
|
/** Client-level default locale for reads (undefined = project default). */
|
|
246
336
|
private readonly locale?;
|
|
247
337
|
/** Request timeout in ms, `0` for none. */
|
|
248
338
|
private readonly timeout;
|
|
339
|
+
/** `writeTimeout` in ms, `0` for none. */
|
|
340
|
+
private readonly writeTimeout;
|
|
249
341
|
/** `cache.waitForFresh` in ms, `Infinity` to wait for the studio. */
|
|
250
342
|
private readonly waitForFresh;
|
|
251
343
|
/** `gatewayRetry` in ms, `undefined` when it is off. */
|
|
252
344
|
private readonly gatewayRetry;
|
|
345
|
+
/** `rateLimitWait` in ms, `undefined` when it is off. */
|
|
346
|
+
private readonly rateLimitWait;
|
|
347
|
+
/** Who this client is to the studio (`identityOf`): what the rate gate is kept per. Holds the key. */
|
|
348
|
+
private readonly identity;
|
|
349
|
+
/** The `logger` option, `undefined` for `false`. */
|
|
350
|
+
private readonly log;
|
|
253
351
|
/**
|
|
254
352
|
* The refresh under way per cache key, so concurrent reads of one key share
|
|
255
353
|
* one request, with the ticket it left on (see `state.ticket`).
|
|
@@ -263,35 +361,17 @@ declare class HavenClient {
|
|
|
263
361
|
private readonly onError?;
|
|
264
362
|
/**
|
|
265
363
|
* Everything that changes while the client runs and is not a collection of
|
|
266
|
-
* its own.
|
|
267
|
-
* fields through its prototype - changes the same values and never a copy.
|
|
364
|
+
* its own.
|
|
268
365
|
*/
|
|
269
366
|
private readonly state;
|
|
270
|
-
constructor(options
|
|
367
|
+
constructor(options?: NordhavnClientOptions);
|
|
271
368
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
* `URL`, `URLSearchParams`, or a plain searchParams object.
|
|
279
|
-
*
|
|
280
|
-
* ```ts
|
|
281
|
-
* // Next.js app router
|
|
282
|
-
* export default async function Page({ searchParams }) {
|
|
283
|
-
* const posts = await studio.forRequest(await searchParams).dataset('blog', 'posts').list()
|
|
284
|
-
* }
|
|
285
|
-
* ```
|
|
286
|
-
*
|
|
287
|
-
* Note this only bypasses the SDK's own cache. If the page itself sits behind
|
|
288
|
-
* a CDN or framework data cache, that layer needs the same treatment (e.g.
|
|
289
|
-
* `cache: 'no-store'` when the preview marker is present) or the editor keeps
|
|
290
|
-
* seeing a stale page no matter what this client returns.
|
|
291
|
-
*/
|
|
292
|
-
forRequest(input: PreviewInput): HavenClient;
|
|
293
|
-
/** Whether this client bypasses the cache (i.e. came from a preview request). */
|
|
294
|
-
get isPreview(): boolean;
|
|
369
|
+
* Lets go of the live connection: the last client of a server and key to
|
|
370
|
+
* close it closes the connection. The client keeps working, on the stamp
|
|
371
|
+
* check alone. Not needed to let a process end (the connection never keeps
|
|
372
|
+
* one alive); for a test, or code that builds clients and drops them.
|
|
373
|
+
*/
|
|
374
|
+
close(): void;
|
|
295
375
|
/** The full content shape this key can reach: nodes, datasets, field schemas. */
|
|
296
376
|
schema(opts?: ReadOptions): Promise<ContentSchema>;
|
|
297
377
|
/** Shorthand for `schema()` then `.nodes`. */
|
|
@@ -370,7 +450,7 @@ declare class HavenClient {
|
|
|
370
450
|
* The field decides what it takes: its `mimes` and `max_size` rules, within
|
|
371
451
|
* what the studio accepts from a key at all (pdf, jpg, png, webp; 10 MB). The
|
|
372
452
|
* studio reads the type from the content, so a renamed file is refused. Only
|
|
373
|
-
* top-level fields. A file of the wrong type or size throws `
|
|
453
|
+
* top-level fields. A file of the wrong type or size throws `NordhavnError` 400
|
|
374
454
|
* with a message fit to show; other refusals (400, 403, 404) are setup
|
|
375
455
|
* errors. More than 10 uploads a minute per key throws 429. From a Node
|
|
376
456
|
* `Buffer`, send `new Blob([buffer])` with a `filename`.
|
|
@@ -489,6 +569,10 @@ declare class HavenClient {
|
|
|
489
569
|
* 5. One request per key at a time (`refresh`).
|
|
490
570
|
*/
|
|
491
571
|
private cachedGet;
|
|
572
|
+
/** On the first read, in development: which project this key reads (`announceProject`). */
|
|
573
|
+
private announceOnce;
|
|
574
|
+
/** The stamp gate of a read: the live connection's stamp while it is healthy, else the poll. */
|
|
575
|
+
private checkVersion;
|
|
492
576
|
/**
|
|
493
577
|
* Fetches `cacheKey` from the studio and settles the cache with the answer.
|
|
494
578
|
* One per key at a time: reads that arrive while it runs get the same promise,
|
|
@@ -499,6 +583,52 @@ declare class HavenClient {
|
|
|
499
583
|
* nothing cached to serve in its place.
|
|
500
584
|
*/
|
|
501
585
|
private refresh;
|
|
586
|
+
/**
|
|
587
|
+
* Sends a read's request, and sends it again where the failure says that
|
|
588
|
+
* may help (`retryPause`) and `hooks.allowed()` says the read has nothing to
|
|
589
|
+
* serve instead; such a read is also held back while its key is rate
|
|
590
|
+
* limited (`holdBack`). Every other failure is thrown as it is.
|
|
591
|
+
*
|
|
592
|
+
* The one retry loop of the read path, for the cached read (`refresh`) and
|
|
593
|
+
* the bypass alike, so the waits are the same for both. What differs sits in
|
|
594
|
+
* the hooks: `resume` runs after each wait, just before the next try, and
|
|
595
|
+
* either ends the read without one (`{ value }`: what another request stored
|
|
596
|
+
* meanwhile, a newer refresh to join) or takes the ticket and stamp the
|
|
597
|
+
* next try leaves with and returns `undefined`.
|
|
598
|
+
*
|
|
599
|
+
* A next try only ever happens with nothing cached, so it never has an etag
|
|
600
|
+
* to send: `etag` is the first try's.
|
|
601
|
+
*/
|
|
602
|
+
private askRetrying;
|
|
603
|
+
/**
|
|
604
|
+
* Whether, and how, a failed read with nothing cached is sent again;
|
|
605
|
+
* counts what it allows in `read`.
|
|
606
|
+
*
|
|
607
|
+
* - A `502` or `503` is often one bad moment (a proxy switching to a new
|
|
608
|
+
* studio container): once, `gatewayRetry` later plus up to as much at
|
|
609
|
+
* random. Not when it carried `Retry-After`: that one asked to wait.
|
|
610
|
+
* - A `429` with `Retry-After`: `'hold'`, so `holdBack` waits as asked, at
|
|
611
|
+
* most `MAX_RATE_LIMIT_RETRIES` times, and only when that wait ends
|
|
612
|
+
* within `rateLimitWait` of the read's start. Without `Retry-After`
|
|
613
|
+
* nothing says when it would help: thrown.
|
|
614
|
+
*/
|
|
615
|
+
private retryPause;
|
|
616
|
+
/**
|
|
617
|
+
* Keeps a read from going out while its key is rate limited: until its own
|
|
618
|
+
* `429` said, or the studio's own `429` to any read of this server and key
|
|
619
|
+
* in the process (`gateRemaining`, at most a minute). Resolves `true` after
|
|
620
|
+
* waiting, `false` to go now.
|
|
621
|
+
*
|
|
622
|
+
* A read with nothing cached (`uncached`) waits for the gate, plus a random
|
|
623
|
+
* spread (`spreadOf`, also after a `Retry-After: 0`), when that wait ends
|
|
624
|
+
* within `rateLimitWait` of the read's start. Otherwise (a read with a value
|
|
625
|
+
* cached, a wait that does not fit, `rateLimitWait: false`) the request is
|
|
626
|
+
* not sent: the studio already said this key must wait, so it would be
|
|
627
|
+
* refused, and count against the key's limit as well. It fails as that
|
|
628
|
+
* refusal would (`heldBackError`), so a cached value is served in its place
|
|
629
|
+
* and a read with nothing cached throws, without a request.
|
|
630
|
+
*/
|
|
631
|
+
private holdBack;
|
|
502
632
|
/**
|
|
503
633
|
* Hands an absorbed failure to `onError`, or without one warns once per
|
|
504
634
|
* outage. Never throws and never leaves a rejection behind: a broken hook
|
|
@@ -523,7 +653,7 @@ declare class HavenClient {
|
|
|
523
653
|
*/
|
|
524
654
|
private conditionalGet;
|
|
525
655
|
private request;
|
|
526
|
-
/** Parse a non-2xx response into a `
|
|
656
|
+
/** Parse a non-2xx response into a `NordhavnError`, preferring its message. */
|
|
527
657
|
private toError;
|
|
528
658
|
}
|
|
529
659
|
/** Fluent, dataset-scoped view returned by `client.dataset()`. */
|
|
@@ -531,35 +661,35 @@ declare class DatasetHandle<T = Record<string, unknown>> {
|
|
|
531
661
|
private readonly client;
|
|
532
662
|
private readonly nodeSlug;
|
|
533
663
|
private readonly datasetSlug;
|
|
534
|
-
constructor(client:
|
|
664
|
+
constructor(client: NordhavnClient, nodeSlug: string, datasetSlug: string);
|
|
535
665
|
list(opts?: ReadOptions): Promise<ContentRecord<T>[]>;
|
|
536
666
|
get(recordUid: string, opts?: ReadOptions): Promise<ContentRecord<T>>;
|
|
537
667
|
create(data: Record<string, unknown>): Promise<ContentRecord<T>>;
|
|
538
668
|
update(recordUid: string, data: Record<string, unknown>): Promise<ContentRecord<T>>;
|
|
539
|
-
/** Upload a file for one of this dataset's file fields; see `
|
|
669
|
+
/** Upload a file for one of this dataset's file fields; see `NordhavnClient.uploadFile`. */
|
|
540
670
|
uploadFile(fieldSlug: string, file: Blob, opts?: UploadOptions): Promise<UploadedFile>;
|
|
541
671
|
/** Clear cached reads for this dataset. */
|
|
542
672
|
clearCache(): void;
|
|
543
673
|
}
|
|
544
|
-
/** Anything a framework might hand you that could carry the preview marker. */
|
|
545
|
-
type PreviewInput = string | URL | URLSearchParams | {
|
|
546
|
-
url: string;
|
|
547
|
-
} | Record<string, string | string[] | undefined> | null | undefined;
|
|
548
|
-
/**
|
|
549
|
-
* True when the request was opened from a Nordhavn OS surface preview, i.e. it
|
|
550
|
-
* carries the `sl-preview` query parameter the studio appends to the iframe URL.
|
|
551
|
-
*/
|
|
552
|
-
declare function isPreviewRequest(input: PreviewInput): boolean;
|
|
553
674
|
|
|
554
675
|
/**
|
|
555
676
|
* Error thrown for any non-2xx response from the content API. `status` carries
|
|
556
677
|
* the HTTP status code so callers can branch (401 bad key, 403 out of scope,
|
|
557
|
-
* 404 missing node/dataset/record, 422 query failed).
|
|
678
|
+
* 404 missing node/dataset/record, 422 query failed). `code` says more where
|
|
679
|
+
* the studio sends one: why an upload was refused, for example
|
|
680
|
+
* (`upload_too_large`).
|
|
558
681
|
*/
|
|
559
|
-
declare class
|
|
682
|
+
declare class NordhavnError extends Error {
|
|
560
683
|
readonly status: number;
|
|
561
684
|
/** The raw parsed response body, when the server returned one. */
|
|
562
685
|
readonly body: unknown;
|
|
686
|
+
/**
|
|
687
|
+
* The studio's code for this error (`data.code` in the body), when it sent
|
|
688
|
+
* one, else `undefined`. Unlike the message it never changes wording, so it
|
|
689
|
+
* is what a site branches on: the upload codes are `upload_type_not_allowed`,
|
|
690
|
+
* `upload_content_invalid`, `upload_too_large` and the ones about the field.
|
|
691
|
+
*/
|
|
692
|
+
readonly code: string | undefined;
|
|
563
693
|
constructor(message: string, status: number, body?: unknown);
|
|
564
694
|
get isUnauthorized(): boolean;
|
|
565
695
|
get isForbidden(): boolean;
|
|
@@ -765,8 +895,22 @@ interface ForecastSeries {
|
|
|
765
895
|
unit?: string;
|
|
766
896
|
}
|
|
767
897
|
|
|
768
|
-
/**
|
|
769
|
-
|
|
898
|
+
/**
|
|
899
|
+
* Convenience factory: `createClient({ apiKey, baseUrl })`. Both fall back to
|
|
900
|
+
* the environment (`NORDHAVN_API_KEY`, `NORDHAVN_BASE_URL`), so on a server
|
|
901
|
+
* with those set `createClient()` is enough.
|
|
902
|
+
*/
|
|
903
|
+
declare function createClient(options?: NordhavnClientOptions): NordhavnClient;
|
|
904
|
+
/** @deprecated Renamed in 0.8.0: use `NordhavnClient`. */
|
|
905
|
+
declare const HavenClient: typeof NordhavnClient;
|
|
906
|
+
/** @deprecated Renamed in 0.8.0: use `NordhavnClient`. */
|
|
907
|
+
type HavenClient = NordhavnClient;
|
|
908
|
+
/** @deprecated Renamed in 0.8.0: use `NordhavnClientOptions`. */
|
|
909
|
+
type HavenClientOptions = NordhavnClientOptions;
|
|
910
|
+
/** @deprecated Renamed in 0.8.0: use `NordhavnError`. */
|
|
911
|
+
declare const HavenError: typeof NordhavnError;
|
|
912
|
+
/** @deprecated Renamed in 0.8.0: use `NordhavnError`. */
|
|
913
|
+
type HavenError = NordhavnError;
|
|
770
914
|
|
|
771
|
-
export { CHART_FENCE_LANG, CHART_FENCE_LIMITS, CacheOptions, ChartData, DEFAULT_BASE_URL, DatasetHandle, HavenClient, HavenError,
|
|
772
|
-
export type { ChartFence, ChartFenceResult, ContentLocale, ContentRecord, ContentSchema, FieldKind, FieldType, ForecastSeries, HavenClientOptions,
|
|
915
|
+
export { CHART_FENCE_LANG, CHART_FENCE_LIMITS, CacheOptions, ChartData, DEFAULT_BASE_URL, DatasetHandle, HavenClient, HavenError, NordhavnClient, NordhavnError, chartFenceHeight, createClient, isChartFence, parseChartFence };
|
|
916
|
+
export type { ChartFence, ChartFenceResult, ClientCacheOptions, ContentLocale, ContentRecord, ContentSchema, FieldKind, FieldType, ForecastSeries, HavenClientOptions, Logger, NordhavnClientOptions, QueryResult, QueryShape, ReadOptions, RoadmapData, RoadmapEvent, RoadmapHappening, RoadmapLane, RoadmapMilestone, RoadmapPhase, RoadmapPhaseState, RoadmapRepeat, RoadmapTask, RoadmapTip, RoadmapTone, RoadmapWaiting, RoadmapWorkState, SchemaDataset, SchemaField, SchemaNode, StudioFailure, UploadOptions, UploadedFile };
|