@nordhavnhq/beacon 0.6.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { b as CacheOptions } from './cache-q8uLEGYg.cjs';
2
- export { a as CacheEntry, C as CacheStore, c as ContentCache, M as MemoryCacheStore } from './cache-q8uLEGYg.cjs';
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
 
@@ -101,12 +101,6 @@ interface UploadedFile {
101
101
  size: number;
102
102
  }
103
103
 
104
- /**
105
- * Query parameter Nordhavn OS appends when it loads your site in a
106
- * surface preview. Its presence means "an editor is looking at this right now",
107
- * which is exactly when caching must get out of the way - see `forRequest`.
108
- */
109
- declare const PREVIEW_PARAM = "sl-preview";
110
104
  /** Hosted Nordhavn OS platform. Used when no `baseUrl` is provided. */
111
105
  declare const DEFAULT_BASE_URL = "https://beacon.nordhavn.ai";
112
106
  /** A studio failure the client absorbed, handed to `onError`. */
@@ -165,8 +159,8 @@ interface HavenClientOptions {
165
159
  *
166
160
  * Often one bad moment, such as a proxy switching to a new studio container;
167
161
  * 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 preview or
169
- * `cache: false` read, a write, or an answer carrying `Retry-After`.
162
+ * read with a value cached (that value is served), a `cache: false` read,
163
+ * a write, or an answer carrying `Retry-After`.
170
164
  */
171
165
  gatewayRetry?: number | false;
172
166
  /**
@@ -184,11 +178,22 @@ interface HavenClientOptions {
184
178
  /** Extra headers merged into every request. */
185
179
  headers?: Record<string, string>;
186
180
  /**
187
- * Force preview behaviour: every read bypasses the cache and refreshes it.
188
- * Usually you do not set this by hand - use `client.forRequest(req)`, which
189
- * turns it on only for requests that carry the studio's preview marker.
190
- */
191
- preview?: boolean;
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;
192
197
  }
193
198
  /** Per-call read options. */
194
199
  interface ReadOptions {
@@ -237,11 +242,8 @@ declare class HavenClient {
237
242
  private readonly headers;
238
243
  private readonly cache;
239
244
  private readonly versionTracker;
240
- /**
241
- * `false` on a preview view (see `forRequest`), so reads bypass the cache by
242
- * default. The one field such a view has of its own; all the rest is shared.
243
- */
244
- private readDefault;
245
+ /** The client's share of the live connection, when it has one (`live` option). */
246
+ private live;
245
247
  /** Client-level default locale for reads (undefined = project default). */
246
248
  private readonly locale?;
247
249
  /** Request timeout in ms, `0` for none. */
@@ -263,35 +265,17 @@ declare class HavenClient {
263
265
  private readonly onError?;
264
266
  /**
265
267
  * Everything that changes while the client runs and is not a collection of
266
- * its own. One object, so that a preview view - which shares this client's
267
- * fields through its prototype - changes the same values and never a copy.
268
+ * its own.
268
269
  */
269
270
  private readonly state;
270
271
  constructor(options: HavenClientOptions);
271
272
  /**
272
- * A per-request view of this client that skips the cache when the request
273
- * comes from a Nordhavn OS surface preview, and behaves exactly like this
274
- * client otherwise. Reads still refresh the shared cache, so an editor
275
- * refreshing the preview also warms what real visitors get.
276
- *
277
- * Accepts whatever your framework hands you: a `Request`, a URL string or
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;
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;
295
279
  /** The full content shape this key can reach: nodes, datasets, field schemas. */
296
280
  schema(opts?: ReadOptions): Promise<ContentSchema>;
297
281
  /** Shorthand for `schema()` then `.nodes`. */
@@ -489,6 +473,8 @@ declare class HavenClient {
489
473
  * 5. One request per key at a time (`refresh`).
490
474
  */
491
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;
492
478
  /**
493
479
  * Fetches `cacheKey` from the studio and settles the cache with the answer.
494
480
  * One per key at a time: reads that arrive while it runs get the same promise,
@@ -541,25 +527,25 @@ declare class DatasetHandle<T = Record<string, unknown>> {
541
527
  /** Clear cached reads for this dataset. */
542
528
  clearCache(): void;
543
529
  }
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
530
 
554
531
  /**
555
532
  * Error thrown for any non-2xx response from the content API. `status` carries
556
533
  * the HTTP status code so callers can branch (401 bad key, 403 out of scope,
557
- * 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`).
558
537
  */
559
538
  declare class HavenError extends Error {
560
539
  readonly status: number;
561
540
  /** The raw parsed response body, when the server returned one. */
562
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;
563
549
  constructor(message: string, status: number, body?: unknown);
564
550
  get isUnauthorized(): boolean;
565
551
  get isForbidden(): boolean;
@@ -768,5 +754,5 @@ interface ForecastSeries {
768
754
  /** Convenience factory: `createClient({ apiKey, baseUrl })`. */
769
755
  declare function createClient(options: HavenClientOptions): HavenClient;
770
756
 
771
- export { CHART_FENCE_LANG, CHART_FENCE_LIMITS, CacheOptions, ChartData, DEFAULT_BASE_URL, DatasetHandle, HavenClient, HavenError, HavenClient as JustmadeClient, HavenError as JustmadeError, PREVIEW_PARAM, chartFenceHeight, createClient, isChartFence, isPreviewRequest, parseChartFence };
772
- export type { ChartFence, ChartFenceResult, ContentLocale, ContentRecord, ContentSchema, FieldKind, FieldType, ForecastSeries, HavenClientOptions, HavenClientOptions as JustmadeClientOptions, PreviewInput, QueryResult, QueryShape, ReadOptions, RoadmapData, RoadmapEvent, RoadmapHappening, RoadmapLane, RoadmapMilestone, RoadmapPhase, RoadmapPhaseState, RoadmapRepeat, RoadmapTask, RoadmapTip, RoadmapTone, RoadmapWaiting, RoadmapWorkState, SchemaDataset, SchemaField, SchemaNode, StudioFailure, UploadOptions, UploadedFile };
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-q8uLEGYg.js';
2
- export { a as CacheEntry, C as CacheStore, c as ContentCache, M as MemoryCacheStore } from './cache-q8uLEGYg.js';
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
 
@@ -101,12 +101,6 @@ interface UploadedFile {
101
101
  size: number;
102
102
  }
103
103
 
104
- /**
105
- * Query parameter Nordhavn OS appends when it loads your site in a
106
- * surface preview. Its presence means "an editor is looking at this right now",
107
- * which is exactly when caching must get out of the way - see `forRequest`.
108
- */
109
- declare const PREVIEW_PARAM = "sl-preview";
110
104
  /** Hosted Nordhavn OS platform. Used when no `baseUrl` is provided. */
111
105
  declare const DEFAULT_BASE_URL = "https://beacon.nordhavn.ai";
112
106
  /** A studio failure the client absorbed, handed to `onError`. */
@@ -165,8 +159,8 @@ interface HavenClientOptions {
165
159
  *
166
160
  * Often one bad moment, such as a proxy switching to a new studio container;
167
161
  * 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 preview or
169
- * `cache: false` read, a write, or an answer carrying `Retry-After`.
162
+ * read with a value cached (that value is served), a `cache: false` read,
163
+ * a write, or an answer carrying `Retry-After`.
170
164
  */
171
165
  gatewayRetry?: number | false;
172
166
  /**
@@ -184,11 +178,22 @@ interface HavenClientOptions {
184
178
  /** Extra headers merged into every request. */
185
179
  headers?: Record<string, string>;
186
180
  /**
187
- * Force preview behaviour: every read bypasses the cache and refreshes it.
188
- * Usually you do not set this by hand - use `client.forRequest(req)`, which
189
- * turns it on only for requests that carry the studio's preview marker.
190
- */
191
- preview?: boolean;
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;
192
197
  }
193
198
  /** Per-call read options. */
194
199
  interface ReadOptions {
@@ -237,11 +242,8 @@ declare class HavenClient {
237
242
  private readonly headers;
238
243
  private readonly cache;
239
244
  private readonly versionTracker;
240
- /**
241
- * `false` on a preview view (see `forRequest`), so reads bypass the cache by
242
- * default. The one field such a view has of its own; all the rest is shared.
243
- */
244
- private readDefault;
245
+ /** The client's share of the live connection, when it has one (`live` option). */
246
+ private live;
245
247
  /** Client-level default locale for reads (undefined = project default). */
246
248
  private readonly locale?;
247
249
  /** Request timeout in ms, `0` for none. */
@@ -263,35 +265,17 @@ declare class HavenClient {
263
265
  private readonly onError?;
264
266
  /**
265
267
  * Everything that changes while the client runs and is not a collection of
266
- * its own. One object, so that a preview view - which shares this client's
267
- * fields through its prototype - changes the same values and never a copy.
268
+ * its own.
268
269
  */
269
270
  private readonly state;
270
271
  constructor(options: HavenClientOptions);
271
272
  /**
272
- * A per-request view of this client that skips the cache when the request
273
- * comes from a Nordhavn OS surface preview, and behaves exactly like this
274
- * client otherwise. Reads still refresh the shared cache, so an editor
275
- * refreshing the preview also warms what real visitors get.
276
- *
277
- * Accepts whatever your framework hands you: a `Request`, a URL string or
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;
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;
295
279
  /** The full content shape this key can reach: nodes, datasets, field schemas. */
296
280
  schema(opts?: ReadOptions): Promise<ContentSchema>;
297
281
  /** Shorthand for `schema()` then `.nodes`. */
@@ -489,6 +473,8 @@ declare class HavenClient {
489
473
  * 5. One request per key at a time (`refresh`).
490
474
  */
491
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;
492
478
  /**
493
479
  * Fetches `cacheKey` from the studio and settles the cache with the answer.
494
480
  * One per key at a time: reads that arrive while it runs get the same promise,
@@ -541,25 +527,25 @@ declare class DatasetHandle<T = Record<string, unknown>> {
541
527
  /** Clear cached reads for this dataset. */
542
528
  clearCache(): void;
543
529
  }
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
530
 
554
531
  /**
555
532
  * Error thrown for any non-2xx response from the content API. `status` carries
556
533
  * the HTTP status code so callers can branch (401 bad key, 403 out of scope,
557
- * 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`).
558
537
  */
559
538
  declare class HavenError extends Error {
560
539
  readonly status: number;
561
540
  /** The raw parsed response body, when the server returned one. */
562
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;
563
549
  constructor(message: string, status: number, body?: unknown);
564
550
  get isUnauthorized(): boolean;
565
551
  get isForbidden(): boolean;
@@ -768,5 +754,5 @@ interface ForecastSeries {
768
754
  /** Convenience factory: `createClient({ apiKey, baseUrl })`. */
769
755
  declare function createClient(options: HavenClientOptions): HavenClient;
770
756
 
771
- export { CHART_FENCE_LANG, CHART_FENCE_LIMITS, CacheOptions, ChartData, DEFAULT_BASE_URL, DatasetHandle, HavenClient, HavenError, HavenClient as JustmadeClient, HavenError as JustmadeError, PREVIEW_PARAM, chartFenceHeight, createClient, isChartFence, isPreviewRequest, parseChartFence };
772
- export type { ChartFence, ChartFenceResult, ContentLocale, ContentRecord, ContentSchema, FieldKind, FieldType, ForecastSeries, HavenClientOptions, HavenClientOptions as JustmadeClientOptions, PreviewInput, QueryResult, QueryShape, ReadOptions, RoadmapData, RoadmapEvent, RoadmapHappening, RoadmapLane, RoadmapMilestone, RoadmapPhase, RoadmapPhaseState, RoadmapRepeat, RoadmapTask, RoadmapTip, RoadmapTone, RoadmapWaiting, RoadmapWorkState, SchemaDataset, SchemaField, SchemaNode, StudioFailure, UploadOptions, UploadedFile };
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 };