@nordhavnhq/beacon 0.5.0 → 0.7.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 +2 -3
- package/dist/{cache-q8uLEGYg.d.cts → cache-1gURpP7O.d.cts} +2 -2
- package/dist/{cache-q8uLEGYg.d.ts → cache-1gURpP7O.d.ts} +2 -2
- package/dist/index.cjs +762 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +103 -56
- package/dist/index.d.ts +103 -56
- package/dist/index.js +763 -54
- 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-1gURpP7O.cjs';
|
|
2
|
+
export { a as CacheEntry, C as CacheStore, c as ContentCache, M as MemoryCacheStore } from './cache-1gURpP7O.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
|
|
|
@@ -84,13 +84,23 @@ interface QueryResult<V = unknown> {
|
|
|
84
84
|
shape: QueryShape;
|
|
85
85
|
value: V;
|
|
86
86
|
}
|
|
87
|
-
|
|
88
87
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
88
|
+
* Response of `POST /files`: one uploaded file, not yet on any record. Hang it
|
|
89
|
+
* on a record by writing `{ uid }` into the file field it was uploaded for;
|
|
90
|
+
* an upload no record takes up within 24 hours is removed.
|
|
92
91
|
*/
|
|
93
|
-
|
|
92
|
+
interface UploadedFile {
|
|
93
|
+
uid: string;
|
|
94
|
+
/** Absolute URL of the stored file. */
|
|
95
|
+
url: string;
|
|
96
|
+
/** The file name as uploaded. */
|
|
97
|
+
name: string;
|
|
98
|
+
/** Read from the file's content, not from what the upload declared. */
|
|
99
|
+
mimeType: string;
|
|
100
|
+
/** Size in bytes. */
|
|
101
|
+
size: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
94
104
|
/** Hosted Nordhavn OS platform. Used when no `baseUrl` is provided. */
|
|
95
105
|
declare const DEFAULT_BASE_URL = "https://beacon.nordhavn.ai";
|
|
96
106
|
/** A studio failure the client absorbed, handed to `onError`. */
|
|
@@ -149,8 +159,8 @@ interface HavenClientOptions {
|
|
|
149
159
|
*
|
|
150
160
|
* Often one bad moment, such as a proxy switching to a new studio container;
|
|
151
161
|
* and with nothing cached the error is all the caller would get. Never for a
|
|
152
|
-
* read with a value cached (that value is served), a
|
|
153
|
-
*
|
|
162
|
+
* read with a value cached (that value is served), a `cache: false` read,
|
|
163
|
+
* a write, or an answer carrying `Retry-After`.
|
|
154
164
|
*/
|
|
155
165
|
gatewayRetry?: number | false;
|
|
156
166
|
/**
|
|
@@ -168,11 +178,22 @@ interface HavenClientOptions {
|
|
|
168
178
|
/** Extra headers merged into every request. */
|
|
169
179
|
headers?: Record<string, string>;
|
|
170
180
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
181
|
+
* Hold a live connection to the studio, which tells the moment content
|
|
182
|
+
* changes, so an edit shows at the next read instead of up to `revalidate`
|
|
183
|
+
* later. While it is up, reads skip the once-a-minute stamp check; when it
|
|
184
|
+
* is down, they make it as before. It only ever replaces that check: it
|
|
185
|
+
* fetches no content itself, keeps no process alive, and cannot fail a read.
|
|
186
|
+
*
|
|
187
|
+
* On by default in a long-lived Node process, for a client with a cache.
|
|
188
|
+
* Off by default on serverless and in CI (`VERCEL`, `NETLIFY`, AWS Lambda,
|
|
189
|
+
* Azure Functions, Google Cloud Functions and Cloud Run, Deno Deploy, `CI`),
|
|
190
|
+
* with `cache.waitForFresh: false`, and with a custom `fetch` (the
|
|
191
|
+
* connection goes over Node's `http`, not through it); `true` turns it on
|
|
192
|
+
* there. Never in a browser or an edge runtime, nor without a cache or with
|
|
193
|
+
* `revalidate: false`. One connection per server and key in a process, shared
|
|
194
|
+
* by every client with those.
|
|
195
|
+
*/
|
|
196
|
+
live?: boolean;
|
|
176
197
|
}
|
|
177
198
|
/** Per-call read options. */
|
|
178
199
|
interface ReadOptions {
|
|
@@ -188,6 +209,22 @@ interface ReadOptions {
|
|
|
188
209
|
*/
|
|
189
210
|
locale?: string | null | undefined;
|
|
190
211
|
}
|
|
212
|
+
/** Per-call options for `uploadFile`. */
|
|
213
|
+
interface UploadOptions {
|
|
214
|
+
/**
|
|
215
|
+
* The file name to send, extension included: the studio checks the
|
|
216
|
+
* extension against the field's allowed types. Defaults to the name of a
|
|
217
|
+
* `File`; required for a plain `Blob`.
|
|
218
|
+
*/
|
|
219
|
+
filename?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Give up after this many ms, body included. Defaults to the client's
|
|
222
|
+
* `timeout`, but at least 60 s (an upload may be 10 MB); `0` for none. A
|
|
223
|
+
* client created with `timeout: 0` uploads without one too. A negative
|
|
224
|
+
* number or `NaN` counts as not given.
|
|
225
|
+
*/
|
|
226
|
+
timeout?: number;
|
|
227
|
+
}
|
|
191
228
|
/**
|
|
192
229
|
* Typed client for the Nordhavn OS content API: read and write a project's node
|
|
193
230
|
* datasets from any website or app. Reads are cached (see the `cache` option);
|
|
@@ -205,11 +242,8 @@ declare class HavenClient {
|
|
|
205
242
|
private readonly headers;
|
|
206
243
|
private readonly cache;
|
|
207
244
|
private readonly versionTracker;
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
* default. The one field such a view has of its own; all the rest is shared.
|
|
211
|
-
*/
|
|
212
|
-
private readDefault;
|
|
245
|
+
/** The client's share of the live connection, when it has one (`live` option). */
|
|
246
|
+
private live;
|
|
213
247
|
/** Client-level default locale for reads (undefined = project default). */
|
|
214
248
|
private readonly locale?;
|
|
215
249
|
/** Request timeout in ms, `0` for none. */
|
|
@@ -231,35 +265,17 @@ declare class HavenClient {
|
|
|
231
265
|
private readonly onError?;
|
|
232
266
|
/**
|
|
233
267
|
* Everything that changes while the client runs and is not a collection of
|
|
234
|
-
* its own.
|
|
235
|
-
* fields through its prototype - changes the same values and never a copy.
|
|
268
|
+
* its own.
|
|
236
269
|
*/
|
|
237
270
|
private readonly state;
|
|
238
271
|
constructor(options: HavenClientOptions);
|
|
239
272
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
* `URL`, `URLSearchParams`, or a plain searchParams object.
|
|
247
|
-
*
|
|
248
|
-
* ```ts
|
|
249
|
-
* // Next.js app router
|
|
250
|
-
* export default async function Page({ searchParams }) {
|
|
251
|
-
* const posts = await studio.forRequest(await searchParams).dataset('blog', 'posts').list()
|
|
252
|
-
* }
|
|
253
|
-
* ```
|
|
254
|
-
*
|
|
255
|
-
* Note this only bypasses the SDK's own cache. If the page itself sits behind
|
|
256
|
-
* a CDN or framework data cache, that layer needs the same treatment (e.g.
|
|
257
|
-
* `cache: 'no-store'` when the preview marker is present) or the editor keeps
|
|
258
|
-
* seeing a stale page no matter what this client returns.
|
|
259
|
-
*/
|
|
260
|
-
forRequest(input: PreviewInput): HavenClient;
|
|
261
|
-
/** Whether this client bypasses the cache (i.e. came from a preview request). */
|
|
262
|
-
get isPreview(): boolean;
|
|
273
|
+
* Lets go of the live connection: the last client of a server and key to
|
|
274
|
+
* close it closes the connection. The client keeps working, on the stamp
|
|
275
|
+
* check alone. Not needed to let a process end (the connection never keeps
|
|
276
|
+
* one alive); for a test, or code that builds clients and drops them.
|
|
277
|
+
*/
|
|
278
|
+
close(): void;
|
|
263
279
|
/** The full content shape this key can reach: nodes, datasets, field schemas. */
|
|
264
280
|
schema(opts?: ReadOptions): Promise<ContentSchema>;
|
|
265
281
|
/** Shorthand for `schema()` then `.nodes`. */
|
|
@@ -322,6 +338,33 @@ declare class HavenClient {
|
|
|
322
338
|
* reads of the dataset and of this record.
|
|
323
339
|
*/
|
|
324
340
|
updateRecord<T = Record<string, unknown>>(nodeSlug: string, datasetSlug: string, recordUid: string, data: Record<string, unknown>): Promise<ContentRecord<T>>;
|
|
341
|
+
/**
|
|
342
|
+
* Upload one file for a `file` field, for a form that sends an attachment.
|
|
343
|
+
* Requires write scope on the dataset. Returns the file; hang it on a record
|
|
344
|
+
* in a second call by writing `{ uid }` into that field:
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* const attachment = form.get('attachment')
|
|
348
|
+
* if (attachment instanceof File && attachment.size > 0) {
|
|
349
|
+
* const file = await studio.uploadFile('contact', 'requests', 'attachment', attachment)
|
|
350
|
+
* await studio.createRecord('contact', 'requests', { name, attachment: { uid: file.uid } })
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* The field decides what it takes: its `mimes` and `max_size` rules, within
|
|
355
|
+
* what the studio accepts from a key at all (pdf, jpg, png, webp; 10 MB). The
|
|
356
|
+
* studio reads the type from the content, so a renamed file is refused. Only
|
|
357
|
+
* top-level fields. A file of the wrong type or size throws `HavenError` 400
|
|
358
|
+
* with a message fit to show; other refusals (400, 403, 404) are setup
|
|
359
|
+
* errors. More than 10 uploads a minute per key throws 429. From a Node
|
|
360
|
+
* `Buffer`, send `new Blob([buffer])` with a `filename`.
|
|
361
|
+
*
|
|
362
|
+
* Server-side only: the key that uploads can write, and must never reach a
|
|
363
|
+
* browser. Not retried, not cached, and it leaves cached reads alone: until a
|
|
364
|
+
* record takes it up, the file belongs to no content. An upload that failed
|
|
365
|
+
* may still have been stored; an unused one is removed after 24 hours.
|
|
366
|
+
*/
|
|
367
|
+
uploadFile(nodeSlug: string, datasetSlug: string, fieldSlug: string, file: Blob, opts?: UploadOptions): Promise<UploadedFile>;
|
|
325
368
|
/**
|
|
326
369
|
* Sends a write and settles the cached reads of its dataset with the outcome.
|
|
327
370
|
*
|
|
@@ -430,6 +473,8 @@ declare class HavenClient {
|
|
|
430
473
|
* 5. One request per key at a time (`refresh`).
|
|
431
474
|
*/
|
|
432
475
|
private cachedGet;
|
|
476
|
+
/** The stamp gate of a read: the live connection's stamp while it is healthy, else the poll. */
|
|
477
|
+
private checkVersion;
|
|
433
478
|
/**
|
|
434
479
|
* Fetches `cacheKey` from the studio and settles the cache with the answer.
|
|
435
480
|
* One per key at a time: reads that arrive while it runs get the same promise,
|
|
@@ -477,28 +522,30 @@ declare class DatasetHandle<T = Record<string, unknown>> {
|
|
|
477
522
|
get(recordUid: string, opts?: ReadOptions): Promise<ContentRecord<T>>;
|
|
478
523
|
create(data: Record<string, unknown>): Promise<ContentRecord<T>>;
|
|
479
524
|
update(recordUid: string, data: Record<string, unknown>): Promise<ContentRecord<T>>;
|
|
525
|
+
/** Upload a file for one of this dataset's file fields; see `HavenClient.uploadFile`. */
|
|
526
|
+
uploadFile(fieldSlug: string, file: Blob, opts?: UploadOptions): Promise<UploadedFile>;
|
|
480
527
|
/** Clear cached reads for this dataset. */
|
|
481
528
|
clearCache(): void;
|
|
482
529
|
}
|
|
483
|
-
/** Anything a framework might hand you that could carry the preview marker. */
|
|
484
|
-
type PreviewInput = string | URL | URLSearchParams | {
|
|
485
|
-
url: string;
|
|
486
|
-
} | Record<string, string | string[] | undefined> | null | undefined;
|
|
487
|
-
/**
|
|
488
|
-
* True when the request was opened from a Nordhavn OS surface preview, i.e. it
|
|
489
|
-
* carries the `sl-preview` query parameter the studio appends to the iframe URL.
|
|
490
|
-
*/
|
|
491
|
-
declare function isPreviewRequest(input: PreviewInput): boolean;
|
|
492
530
|
|
|
493
531
|
/**
|
|
494
532
|
* Error thrown for any non-2xx response from the content API. `status` carries
|
|
495
533
|
* the HTTP status code so callers can branch (401 bad key, 403 out of scope,
|
|
496
|
-
* 404 missing node/dataset/record, 422 query failed).
|
|
534
|
+
* 404 missing node/dataset/record, 422 query failed). `code` says more where
|
|
535
|
+
* the studio sends one: why an upload was refused, for example
|
|
536
|
+
* (`upload_too_large`).
|
|
497
537
|
*/
|
|
498
538
|
declare class HavenError extends Error {
|
|
499
539
|
readonly status: number;
|
|
500
540
|
/** The raw parsed response body, when the server returned one. */
|
|
501
541
|
readonly body: unknown;
|
|
542
|
+
/**
|
|
543
|
+
* The studio's code for this error (`data.code` in the body), when it sent
|
|
544
|
+
* one, else `undefined`. Unlike the message it never changes wording, so it
|
|
545
|
+
* is what a site branches on: the upload codes are `upload_type_not_allowed`,
|
|
546
|
+
* `upload_content_invalid`, `upload_too_large` and the ones about the field.
|
|
547
|
+
*/
|
|
548
|
+
readonly code: string | undefined;
|
|
502
549
|
constructor(message: string, status: number, body?: unknown);
|
|
503
550
|
get isUnauthorized(): boolean;
|
|
504
551
|
get isForbidden(): boolean;
|
|
@@ -707,5 +754,5 @@ interface ForecastSeries {
|
|
|
707
754
|
/** Convenience factory: `createClient({ apiKey, baseUrl })`. */
|
|
708
755
|
declare function createClient(options: HavenClientOptions): HavenClient;
|
|
709
756
|
|
|
710
|
-
export { CHART_FENCE_LANG, CHART_FENCE_LIMITS, CacheOptions, ChartData, DEFAULT_BASE_URL, DatasetHandle, HavenClient, HavenError,
|
|
711
|
-
export type { ChartFence, ChartFenceResult, ContentLocale, ContentRecord, ContentSchema, FieldKind, FieldType, ForecastSeries, HavenClientOptions,
|
|
757
|
+
export { CHART_FENCE_LANG, CHART_FENCE_LIMITS, CacheOptions, ChartData, DEFAULT_BASE_URL, DatasetHandle, HavenClient, HavenError, chartFenceHeight, createClient, isChartFence, parseChartFence };
|
|
758
|
+
export type { ChartFence, ChartFenceResult, ContentLocale, ContentRecord, ContentSchema, FieldKind, FieldType, ForecastSeries, HavenClientOptions, QueryResult, QueryShape, ReadOptions, RoadmapData, RoadmapEvent, RoadmapHappening, RoadmapLane, RoadmapMilestone, RoadmapPhase, RoadmapPhaseState, RoadmapRepeat, RoadmapTask, RoadmapTip, RoadmapTone, RoadmapWaiting, RoadmapWorkState, SchemaDataset, SchemaField, SchemaNode, StudioFailure, UploadOptions, UploadedFile };
|
package/dist/index.d.ts
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-1gURpP7O.js';
|
|
2
|
+
export { a as CacheEntry, C as CacheStore, c as ContentCache, M as MemoryCacheStore } from './cache-1gURpP7O.js';
|
|
3
3
|
import { C as ChartData } from './chart-CxtDbYAs.js';
|
|
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.js';
|
|
5
5
|
|
|
@@ -84,13 +84,23 @@ interface QueryResult<V = unknown> {
|
|
|
84
84
|
shape: QueryShape;
|
|
85
85
|
value: V;
|
|
86
86
|
}
|
|
87
|
-
|
|
88
87
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
88
|
+
* Response of `POST /files`: one uploaded file, not yet on any record. Hang it
|
|
89
|
+
* on a record by writing `{ uid }` into the file field it was uploaded for;
|
|
90
|
+
* an upload no record takes up within 24 hours is removed.
|
|
92
91
|
*/
|
|
93
|
-
|
|
92
|
+
interface UploadedFile {
|
|
93
|
+
uid: string;
|
|
94
|
+
/** Absolute URL of the stored file. */
|
|
95
|
+
url: string;
|
|
96
|
+
/** The file name as uploaded. */
|
|
97
|
+
name: string;
|
|
98
|
+
/** Read from the file's content, not from what the upload declared. */
|
|
99
|
+
mimeType: string;
|
|
100
|
+
/** Size in bytes. */
|
|
101
|
+
size: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
94
104
|
/** Hosted Nordhavn OS platform. Used when no `baseUrl` is provided. */
|
|
95
105
|
declare const DEFAULT_BASE_URL = "https://beacon.nordhavn.ai";
|
|
96
106
|
/** A studio failure the client absorbed, handed to `onError`. */
|
|
@@ -149,8 +159,8 @@ interface HavenClientOptions {
|
|
|
149
159
|
*
|
|
150
160
|
* Often one bad moment, such as a proxy switching to a new studio container;
|
|
151
161
|
* and with nothing cached the error is all the caller would get. Never for a
|
|
152
|
-
* read with a value cached (that value is served), a
|
|
153
|
-
*
|
|
162
|
+
* read with a value cached (that value is served), a `cache: false` read,
|
|
163
|
+
* a write, or an answer carrying `Retry-After`.
|
|
154
164
|
*/
|
|
155
165
|
gatewayRetry?: number | false;
|
|
156
166
|
/**
|
|
@@ -168,11 +178,22 @@ interface HavenClientOptions {
|
|
|
168
178
|
/** Extra headers merged into every request. */
|
|
169
179
|
headers?: Record<string, string>;
|
|
170
180
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
181
|
+
* Hold a live connection to the studio, which tells the moment content
|
|
182
|
+
* changes, so an edit shows at the next read instead of up to `revalidate`
|
|
183
|
+
* later. While it is up, reads skip the once-a-minute stamp check; when it
|
|
184
|
+
* is down, they make it as before. It only ever replaces that check: it
|
|
185
|
+
* fetches no content itself, keeps no process alive, and cannot fail a read.
|
|
186
|
+
*
|
|
187
|
+
* On by default in a long-lived Node process, for a client with a cache.
|
|
188
|
+
* Off by default on serverless and in CI (`VERCEL`, `NETLIFY`, AWS Lambda,
|
|
189
|
+
* Azure Functions, Google Cloud Functions and Cloud Run, Deno Deploy, `CI`),
|
|
190
|
+
* with `cache.waitForFresh: false`, and with a custom `fetch` (the
|
|
191
|
+
* connection goes over Node's `http`, not through it); `true` turns it on
|
|
192
|
+
* there. Never in a browser or an edge runtime, nor without a cache or with
|
|
193
|
+
* `revalidate: false`. One connection per server and key in a process, shared
|
|
194
|
+
* by every client with those.
|
|
195
|
+
*/
|
|
196
|
+
live?: boolean;
|
|
176
197
|
}
|
|
177
198
|
/** Per-call read options. */
|
|
178
199
|
interface ReadOptions {
|
|
@@ -188,6 +209,22 @@ interface ReadOptions {
|
|
|
188
209
|
*/
|
|
189
210
|
locale?: string | null | undefined;
|
|
190
211
|
}
|
|
212
|
+
/** Per-call options for `uploadFile`. */
|
|
213
|
+
interface UploadOptions {
|
|
214
|
+
/**
|
|
215
|
+
* The file name to send, extension included: the studio checks the
|
|
216
|
+
* extension against the field's allowed types. Defaults to the name of a
|
|
217
|
+
* `File`; required for a plain `Blob`.
|
|
218
|
+
*/
|
|
219
|
+
filename?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Give up after this many ms, body included. Defaults to the client's
|
|
222
|
+
* `timeout`, but at least 60 s (an upload may be 10 MB); `0` for none. A
|
|
223
|
+
* client created with `timeout: 0` uploads without one too. A negative
|
|
224
|
+
* number or `NaN` counts as not given.
|
|
225
|
+
*/
|
|
226
|
+
timeout?: number;
|
|
227
|
+
}
|
|
191
228
|
/**
|
|
192
229
|
* Typed client for the Nordhavn OS content API: read and write a project's node
|
|
193
230
|
* datasets from any website or app. Reads are cached (see the `cache` option);
|
|
@@ -205,11 +242,8 @@ declare class HavenClient {
|
|
|
205
242
|
private readonly headers;
|
|
206
243
|
private readonly cache;
|
|
207
244
|
private readonly versionTracker;
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
* default. The one field such a view has of its own; all the rest is shared.
|
|
211
|
-
*/
|
|
212
|
-
private readDefault;
|
|
245
|
+
/** The client's share of the live connection, when it has one (`live` option). */
|
|
246
|
+
private live;
|
|
213
247
|
/** Client-level default locale for reads (undefined = project default). */
|
|
214
248
|
private readonly locale?;
|
|
215
249
|
/** Request timeout in ms, `0` for none. */
|
|
@@ -231,35 +265,17 @@ declare class HavenClient {
|
|
|
231
265
|
private readonly onError?;
|
|
232
266
|
/**
|
|
233
267
|
* Everything that changes while the client runs and is not a collection of
|
|
234
|
-
* its own.
|
|
235
|
-
* fields through its prototype - changes the same values and never a copy.
|
|
268
|
+
* its own.
|
|
236
269
|
*/
|
|
237
270
|
private readonly state;
|
|
238
271
|
constructor(options: HavenClientOptions);
|
|
239
272
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
* `URL`, `URLSearchParams`, or a plain searchParams object.
|
|
247
|
-
*
|
|
248
|
-
* ```ts
|
|
249
|
-
* // Next.js app router
|
|
250
|
-
* export default async function Page({ searchParams }) {
|
|
251
|
-
* const posts = await studio.forRequest(await searchParams).dataset('blog', 'posts').list()
|
|
252
|
-
* }
|
|
253
|
-
* ```
|
|
254
|
-
*
|
|
255
|
-
* Note this only bypasses the SDK's own cache. If the page itself sits behind
|
|
256
|
-
* a CDN or framework data cache, that layer needs the same treatment (e.g.
|
|
257
|
-
* `cache: 'no-store'` when the preview marker is present) or the editor keeps
|
|
258
|
-
* seeing a stale page no matter what this client returns.
|
|
259
|
-
*/
|
|
260
|
-
forRequest(input: PreviewInput): HavenClient;
|
|
261
|
-
/** Whether this client bypasses the cache (i.e. came from a preview request). */
|
|
262
|
-
get isPreview(): boolean;
|
|
273
|
+
* Lets go of the live connection: the last client of a server and key to
|
|
274
|
+
* close it closes the connection. The client keeps working, on the stamp
|
|
275
|
+
* check alone. Not needed to let a process end (the connection never keeps
|
|
276
|
+
* one alive); for a test, or code that builds clients and drops them.
|
|
277
|
+
*/
|
|
278
|
+
close(): void;
|
|
263
279
|
/** The full content shape this key can reach: nodes, datasets, field schemas. */
|
|
264
280
|
schema(opts?: ReadOptions): Promise<ContentSchema>;
|
|
265
281
|
/** Shorthand for `schema()` then `.nodes`. */
|
|
@@ -322,6 +338,33 @@ declare class HavenClient {
|
|
|
322
338
|
* reads of the dataset and of this record.
|
|
323
339
|
*/
|
|
324
340
|
updateRecord<T = Record<string, unknown>>(nodeSlug: string, datasetSlug: string, recordUid: string, data: Record<string, unknown>): Promise<ContentRecord<T>>;
|
|
341
|
+
/**
|
|
342
|
+
* Upload one file for a `file` field, for a form that sends an attachment.
|
|
343
|
+
* Requires write scope on the dataset. Returns the file; hang it on a record
|
|
344
|
+
* in a second call by writing `{ uid }` into that field:
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* const attachment = form.get('attachment')
|
|
348
|
+
* if (attachment instanceof File && attachment.size > 0) {
|
|
349
|
+
* const file = await studio.uploadFile('contact', 'requests', 'attachment', attachment)
|
|
350
|
+
* await studio.createRecord('contact', 'requests', { name, attachment: { uid: file.uid } })
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* The field decides what it takes: its `mimes` and `max_size` rules, within
|
|
355
|
+
* what the studio accepts from a key at all (pdf, jpg, png, webp; 10 MB). The
|
|
356
|
+
* studio reads the type from the content, so a renamed file is refused. Only
|
|
357
|
+
* top-level fields. A file of the wrong type or size throws `HavenError` 400
|
|
358
|
+
* with a message fit to show; other refusals (400, 403, 404) are setup
|
|
359
|
+
* errors. More than 10 uploads a minute per key throws 429. From a Node
|
|
360
|
+
* `Buffer`, send `new Blob([buffer])` with a `filename`.
|
|
361
|
+
*
|
|
362
|
+
* Server-side only: the key that uploads can write, and must never reach a
|
|
363
|
+
* browser. Not retried, not cached, and it leaves cached reads alone: until a
|
|
364
|
+
* record takes it up, the file belongs to no content. An upload that failed
|
|
365
|
+
* may still have been stored; an unused one is removed after 24 hours.
|
|
366
|
+
*/
|
|
367
|
+
uploadFile(nodeSlug: string, datasetSlug: string, fieldSlug: string, file: Blob, opts?: UploadOptions): Promise<UploadedFile>;
|
|
325
368
|
/**
|
|
326
369
|
* Sends a write and settles the cached reads of its dataset with the outcome.
|
|
327
370
|
*
|
|
@@ -430,6 +473,8 @@ declare class HavenClient {
|
|
|
430
473
|
* 5. One request per key at a time (`refresh`).
|
|
431
474
|
*/
|
|
432
475
|
private cachedGet;
|
|
476
|
+
/** The stamp gate of a read: the live connection's stamp while it is healthy, else the poll. */
|
|
477
|
+
private checkVersion;
|
|
433
478
|
/**
|
|
434
479
|
* Fetches `cacheKey` from the studio and settles the cache with the answer.
|
|
435
480
|
* One per key at a time: reads that arrive while it runs get the same promise,
|
|
@@ -477,28 +522,30 @@ declare class DatasetHandle<T = Record<string, unknown>> {
|
|
|
477
522
|
get(recordUid: string, opts?: ReadOptions): Promise<ContentRecord<T>>;
|
|
478
523
|
create(data: Record<string, unknown>): Promise<ContentRecord<T>>;
|
|
479
524
|
update(recordUid: string, data: Record<string, unknown>): Promise<ContentRecord<T>>;
|
|
525
|
+
/** Upload a file for one of this dataset's file fields; see `HavenClient.uploadFile`. */
|
|
526
|
+
uploadFile(fieldSlug: string, file: Blob, opts?: UploadOptions): Promise<UploadedFile>;
|
|
480
527
|
/** Clear cached reads for this dataset. */
|
|
481
528
|
clearCache(): void;
|
|
482
529
|
}
|
|
483
|
-
/** Anything a framework might hand you that could carry the preview marker. */
|
|
484
|
-
type PreviewInput = string | URL | URLSearchParams | {
|
|
485
|
-
url: string;
|
|
486
|
-
} | Record<string, string | string[] | undefined> | null | undefined;
|
|
487
|
-
/**
|
|
488
|
-
* True when the request was opened from a Nordhavn OS surface preview, i.e. it
|
|
489
|
-
* carries the `sl-preview` query parameter the studio appends to the iframe URL.
|
|
490
|
-
*/
|
|
491
|
-
declare function isPreviewRequest(input: PreviewInput): boolean;
|
|
492
530
|
|
|
493
531
|
/**
|
|
494
532
|
* Error thrown for any non-2xx response from the content API. `status` carries
|
|
495
533
|
* the HTTP status code so callers can branch (401 bad key, 403 out of scope,
|
|
496
|
-
* 404 missing node/dataset/record, 422 query failed).
|
|
534
|
+
* 404 missing node/dataset/record, 422 query failed). `code` says more where
|
|
535
|
+
* the studio sends one: why an upload was refused, for example
|
|
536
|
+
* (`upload_too_large`).
|
|
497
537
|
*/
|
|
498
538
|
declare class HavenError extends Error {
|
|
499
539
|
readonly status: number;
|
|
500
540
|
/** The raw parsed response body, when the server returned one. */
|
|
501
541
|
readonly body: unknown;
|
|
542
|
+
/**
|
|
543
|
+
* The studio's code for this error (`data.code` in the body), when it sent
|
|
544
|
+
* one, else `undefined`. Unlike the message it never changes wording, so it
|
|
545
|
+
* is what a site branches on: the upload codes are `upload_type_not_allowed`,
|
|
546
|
+
* `upload_content_invalid`, `upload_too_large` and the ones about the field.
|
|
547
|
+
*/
|
|
548
|
+
readonly code: string | undefined;
|
|
502
549
|
constructor(message: string, status: number, body?: unknown);
|
|
503
550
|
get isUnauthorized(): boolean;
|
|
504
551
|
get isForbidden(): boolean;
|
|
@@ -707,5 +754,5 @@ interface ForecastSeries {
|
|
|
707
754
|
/** Convenience factory: `createClient({ apiKey, baseUrl })`. */
|
|
708
755
|
declare function createClient(options: HavenClientOptions): HavenClient;
|
|
709
756
|
|
|
710
|
-
export { CHART_FENCE_LANG, CHART_FENCE_LIMITS, CacheOptions, ChartData, DEFAULT_BASE_URL, DatasetHandle, HavenClient, HavenError,
|
|
711
|
-
export type { ChartFence, ChartFenceResult, ContentLocale, ContentRecord, ContentSchema, FieldKind, FieldType, ForecastSeries, HavenClientOptions,
|
|
757
|
+
export { CHART_FENCE_LANG, CHART_FENCE_LIMITS, CacheOptions, ChartData, DEFAULT_BASE_URL, DatasetHandle, HavenClient, HavenError, chartFenceHeight, createClient, isChartFence, parseChartFence };
|
|
758
|
+
export type { ChartFence, ChartFenceResult, ContentLocale, ContentRecord, ContentSchema, FieldKind, FieldType, ForecastSeries, HavenClientOptions, QueryResult, QueryShape, ReadOptions, RoadmapData, RoadmapEvent, RoadmapHappening, RoadmapLane, RoadmapMilestone, RoadmapPhase, RoadmapPhaseState, RoadmapRepeat, RoadmapTask, RoadmapTip, RoadmapTone, RoadmapWaiting, RoadmapWorkState, SchemaDataset, SchemaField, SchemaNode, StudioFailure, UploadOptions, UploadedFile };
|