@holistics/anfra-sdk 0.11.0 → 0.12.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 CHANGED
@@ -51,6 +51,10 @@ Everything beyond queries comes from a **plugin** the host installed, which adds
51
51
  own name (`query.export`, `Anfra.render`, `Anfra.lineage`). Where the host didn't install it, the
52
52
  member isn't there: check `Anfra.plugins.has(name)` before using an optional one.
53
53
 
54
+ Data Apps written before plugins read `Anfra.features.export` (`.render`, `.lineage`). It still
55
+ answers, from the installed plugins, but it is deprecated and warns in the console: replace it with
56
+ `Anfra.plugins.has('export')`. It goes in the next breaking release.
57
+
54
58
  A reader can download a query's whole result, with the inputs its result on screen was run with
55
59
  (the `export` plugin):
56
60
 
@@ -124,12 +128,12 @@ const host = createHost({ // one per page
124
128
  renderPlugin(), // Anfra.render(): the host saves PNGs and PDFs the frame makes
125
129
  inspectPlugin(), // what an inspect panel needs
126
130
  ],
131
+ allowOrigins: ['https://cdn.acme.com'], // optional: more origins apps may load from
127
132
  });
128
133
 
129
134
  const mounted = host.mount({
130
135
  container: document.querySelector('#data-app')!,
131
136
  definition: await (await fetch('/appserve/files/sales/overview.html')).text(),
132
- baseHref: '/appserve/files/sales/', // where its relative URLs resolve
133
137
  datasets,
134
138
  user,
135
139
  });
@@ -139,6 +143,12 @@ await mounted.call('inspect.watch', true); // start the snapshots
139
143
  mounted.unmount(); // when done
140
144
  ```
141
145
 
146
+ A frame runs under a content policy the host puts first in its document: scripts, styles and fonts
147
+ only from a few CDNs (cdnjs, jsDelivr, esm.sh, unpkg, Google Fonts) and the host's `allowOrigins`,
148
+ images from any `https://` server, and no network beyond those origins: data reaches the app over
149
+ the bridge only. A definition is one self-contained file; nothing beside it is served. See
150
+ `contentPolicy` and docs/designs/security.md.
151
+
142
152
  `host.mount` puts the definition in an iframe with `sandbox="allow-scripts"`, as its `srcdoc`, with
143
153
  the frame's kernel, the provisioned data and each plugin's frame setup ahead of it. Every call the
144
154
  frame makes, and every call a plugin makes of another, goes through the host's one pipeline to the
package/dist/api.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Client } from 'openapi-fetch';
2
- import { aj as paths, D as DatasetDescriptor, B as Backend, f as BackendExportRequest, ak as components, i as BackendQueryRequest } from './types-BTyDyld7.js';
3
- import { D as DataAppError } from './errors-CKvqVaqU.js';
2
+ import { ak as paths, al as components } from './types-B9DqPgWS.js';
3
+ import { DatasetDescriptor, Backend, BackendExportRequest, BackendQueryRequest } from './app.js';
4
+ import { DataAppError } from './app.js';
4
5
 
5
6
  /** The core API, typed from anfra core's spec (`api/openapi.yaml`, generated into `schema.d.ts`). */
6
7
  type CoreClient = Client<paths>;
@@ -70,4 +71,5 @@ interface ApiErrorBody {
70
71
  */
71
72
  declare function toSdkError(status: number, body: ApiErrorBody | undefined): DataAppError;
72
73
 
73
- export { type ApiErrorBody, type CoreApiBackendOptions, type CoreClient, type LoadedDatasets, SUGGESTION_LIMIT, components, coreApiBackend, coreClient, loadDatasets, paths, toDescriptor, toExportInput, toQueryInput, toSdkError };
74
+ export { SUGGESTION_LIMIT, components, coreApiBackend, coreClient, loadDatasets, paths, toDescriptor, toExportInput, toQueryInput, toSdkError };
75
+ export type { ApiErrorBody, CoreApiBackendOptions, CoreClient, LoadedDatasets };
package/dist/api.js CHANGED
@@ -44,6 +44,42 @@ function toSdkError(status, body) {
44
44
  }
45
45
  }
46
46
 
47
+ // src/api/stream.ts
48
+ async function readEvents(body, onEvent) {
49
+ const reader = body.getReader();
50
+ const decoder = new TextDecoder();
51
+ let buffered = "";
52
+ const line = (text) => {
53
+ if (!text.trim()) return false;
54
+ const event = JSON.parse(text);
55
+ if (event.type === "ping") return false;
56
+ if (event.type === "end") {
57
+ const end = event;
58
+ if (end.status === "failed") throw toSdkError(end.error?.status ?? 500, end.error);
59
+ return true;
60
+ }
61
+ onEvent(event);
62
+ return false;
63
+ };
64
+ try {
65
+ for (; ; ) {
66
+ const { value, done } = await reader.read();
67
+ if (done) break;
68
+ buffered += decoder.decode(value, { stream: true });
69
+ let start = 0;
70
+ for (let newline = buffered.indexOf("\n"); newline >= 0; newline = buffered.indexOf("\n", start)) {
71
+ if (line(buffered.slice(start, newline))) return;
72
+ start = newline + 1;
73
+ }
74
+ buffered = buffered.slice(start);
75
+ }
76
+ if (line(buffered + decoder.decode())) return;
77
+ } finally {
78
+ reader.releaseLock();
79
+ }
80
+ throw new TransportError("The connection to the server was cut before the answer ended.");
81
+ }
82
+
47
83
  // src/api/backend.ts
48
84
  var SUGGESTION_LIMIT = 100;
49
85
  function isAbort(err) {
@@ -94,8 +130,40 @@ async function callCoreAPI(call) {
94
130
  if (!data) throw toSdkError(response.status, error?.error);
95
131
  return data;
96
132
  }
97
- function runQuery(client, body, signal) {
98
- return callCoreAPI(() => client.POST("/core.query", { body, signal }));
133
+ async function runQuery(client, body, signal) {
134
+ const stream = await callCoreAPI(() => client.POST("/core.query", {
135
+ body,
136
+ signal,
137
+ parseAs: "stream",
138
+ headers: { Accept: "application/x-ndjson" }
139
+ }));
140
+ if (!stream) throw new TransportError("The server answered the query with no body.");
141
+ const result = { sql: "", columns: [], result: { fields: [], records: [] }, has_more: false, timings: { steps: [], end_ms: 0 } };
142
+ try {
143
+ await readEvents(stream, (event) => {
144
+ switch (event.type) {
145
+ case "compiled":
146
+ result.sql = event.sql;
147
+ if (event.aql) result.aql = event.aql;
148
+ break;
149
+ case "header":
150
+ result.columns = event.columns;
151
+ result.result.fields = event.fields;
152
+ break;
153
+ case "rows":
154
+ for (const row of event.records) result.result.records.push(row);
155
+ break;
156
+ case "summary":
157
+ result.has_more = event.has_more;
158
+ result.timings = event.timings;
159
+ break;
160
+ }
161
+ });
162
+ } catch (err) {
163
+ if (isAbort(err) || !(err instanceof Error) || err.name !== "TypeError") throw err;
164
+ throw new TransportError(`The connection to the server failed: ${err.message}`);
165
+ }
166
+ return result;
99
167
  }
100
168
  function coreApiBackend(base, options = {}) {
101
169
  const client = typeof base === "string" ? coreClient(base) : base;
@@ -107,13 +175,17 @@ function coreApiBackend(base, options = {}) {
107
175
  columns: toColumns(data.columns),
108
176
  values,
109
177
  meta: {
110
- ...request.pageSize !== void 0 ? { page: request.page ?? 1, pageSize: request.pageSize } : {},
178
+ ...request.pageSize !== void 0 ? { page: request.page ?? 1, pageSize: request.pageSize, hasMore: data.has_more } : {},
111
179
  numRows: values.length
112
180
  },
113
181
  debug: {
114
182
  ...data.aql ? { executedAql: data.aql } : {},
115
183
  executedSql: data.sql,
116
184
  fromCache: false,
185
+ timings: {
186
+ steps: data.timings.steps.map((s) => ({ step: s.step, startMs: s.start_ms })),
187
+ endMs: data.timings.end_ms
188
+ },
117
189
  executedAt: /* @__PURE__ */ new Date()
118
190
  }
119
191
  };
package/dist/app.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { S as Sdk } from './bootstrap-B7r0ggJN.js';
2
- export { A as AnfraPlugins, a as App, C as Control, b as CrossFilter, D as DateDrillControl, E as Edge, F as Filter, c as FrameKernel, I as InstalledPlugins, M as Mapping, O as OVERLAY_ID, d as PluginApi, e as PluginMembers, f as PluginName, P as PluginSetup, Q as Query, g as STRUCTURE_ATTRIBUTES, V as VERSION, h as bootstrap, i as buildStructure, j as createSdk, p as parseRef } from './bootstrap-B7r0ggJN.js';
1
+ import { S as Sdk } from './bootstrap-DctKHBAj.js';
2
+ export { A as AnfraPlugins, a as App, C as Control, b as CrossFilter, D as DateDrillControl, c as DeprecatedFeatures, E as Edge, F as Filter, d as FrameKernel, I as InstalledPlugins, M as Mapping, O as OVERLAY_ID, e as PluginApi, f as PluginMembers, g as PluginName, P as PluginSetup, Q as Query, h as STRUCTURE_ATTRIBUTES, V as VERSION, i as bootstrap, j as buildStructure, k as createSdk, p as parseRef } from './bootstrap-DctKHBAj.js';
3
3
  export { D as DataAppError, P as PermissionError, Q as QueryError, T as TransportError, V as ValidationError } from './errors-CKvqVaqU.js';
4
- export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as RenderFormat, a7 as RenderRequest, a8 as Rendering, a9 as Row, aa as SdkEnvironment, ab as SdkFeatures, ac as Selection, ad as SelectionCondition, ae as SemanticType, af as StructureKind, ag as StructureNode, ah as Unsubscribe, ai as User } from './types-BTyDyld7.js';
5
- export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-Byq62yS8.js';
4
+ export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as QueryTimings, a7 as RenderFormat, a8 as RenderRequest, a9 as Rendering, aa as Row, ab as SdkEnvironment, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, af as SemanticType, ag as StructureKind, ah as StructureNode, ai as Unsubscribe, aj as User } from './types-B9DqPgWS.js';
5
+ export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-_Ez5VZV9.js';
6
6
 
7
7
  declare const SANDBOX_GLOBAL = "Anfra";
8
8
  /**
package/dist/app.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  createSdk,
20
20
  installSandbox,
21
21
  parseRef
22
- } from "./chunk-BL7SPVAS.js";
22
+ } from "./chunk-IDNQIVUZ.js";
23
23
  import {
24
24
  FILTER_AGGREGATIONS
25
25
  } from "./chunk-XIUFHRZE.js";
@@ -27,7 +27,7 @@ import "./chunk-ADWBOQW2.js";
27
27
  import {
28
28
  PROVISION_ELEMENT_ID
29
29
  } from "./chunk-33B2D4U5.js";
30
- import "./chunk-ENWRS6AT.js";
30
+ import "./chunk-S3YHTZKJ.js";
31
31
  import {
32
32
  DataAppError,
33
33
  PermissionError,
@@ -1,6 +1,6 @@
1
1
  import { D as DataAppError, V as ValidationError, Q as QueryError, P as PermissionError, T as TransportError } from './errors-CKvqVaqU.js';
2
- import { X as Listener, ah as Unsubscribe, D as DatasetDescriptor, y as ExportOptions, z as ExportResult, a7 as RenderRequest, a8 as Rendering, W as LineageTarget, U as LineageOptions, V as LineageResult, E as EntityKind, l as Condition, J as FilterDeclaration, K as FilterValueType, B as Backend, m as ConditionValue, p as DateDrillDeclaration, q as DateGrain, I as FilterAggregation, n as ControlMappingJson, o as CrossFilterJson, ab as SdkFeatures, ac as Selection, ad as SelectionCondition, a9 as Row, Y as LocateKind, a1 as QueryDeclaration, a5 as QueryState, a3 as QueryResult, a4 as QuerySort, a as AppDeclaration, u as ExecuteOptions, v as ExecuteSummary, f as BackendExportRequest, b as AppJson, L as InspectedApp, ai as User, aa as SdkEnvironment, Q as InspectedStructure } from './types-BTyDyld7.js';
3
- import { b as PluginInfo } from './bridge-Byq62yS8.js';
2
+ import { X as Listener, ai as Unsubscribe, D as DatasetDescriptor, y as ExportOptions, z as ExportResult, a8 as RenderRequest, a9 as Rendering, W as LineageTarget, U as LineageOptions, V as LineageResult, E as EntityKind, l as Condition, J as FilterDeclaration, K as FilterValueType, B as Backend, m as ConditionValue, p as DateDrillDeclaration, q as DateGrain, I as FilterAggregation, n as ControlMappingJson, o as CrossFilterJson, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, aa as Row, Y as LocateKind, a1 as QueryDeclaration, a5 as QueryState, a3 as QueryResult, a4 as QuerySort, a as AppDeclaration, u as ExecuteOptions, v as ExecuteSummary, f as BackendExportRequest, b as AppJson, L as InspectedApp, aj as User, ab as SdkEnvironment, Q as InspectedStructure } from './types-B9DqPgWS.js';
3
+ import { b as PluginInfo } from './bridge-_Ez5VZV9.js';
4
4
 
5
5
  interface NotificationTarget {
6
6
  notifyChange(): void;
@@ -301,6 +301,10 @@ declare class Query extends Observable {
301
301
  get sort(): readonly QuerySort[];
302
302
  /** Replaces the sort applied to this query's result. Pass `[]` to clear it back to the AQL's own. */
303
303
  setSort(sort: readonly QuerySort[]): void;
304
+ /**
305
+ * Whether another page may follow: as the backend said of the last page, or, when it did not
306
+ * say, whether that page came back full.
307
+ */
304
308
  get hasMore(): boolean;
305
309
  /**
306
310
  * Everything that changes the rows: the declaration, the conditions reaching this query through
@@ -523,6 +527,21 @@ declare class InstalledPlugins {
523
527
  /** The installed plugin's version, or undefined. */
524
528
  version(name: PluginName): string | undefined;
525
529
  }
530
+ /**
531
+ * What `Anfra.features` says: the kernel's gates, and whether each of anfra's optional plugins is
532
+ * installed.
533
+ *
534
+ * @deprecated Check `Anfra.plugins.has(name)` instead. Kept so Data Apps written before plugins keep
535
+ * working; removed in the next breaking release.
536
+ */
537
+ interface DeprecatedFeatures extends SdkFeatures {
538
+ /** `Anfra.plugins.has('export')`. */
539
+ readonly export: boolean;
540
+ /** `Anfra.plugins.has('render')`. */
541
+ readonly render: boolean;
542
+ /** `Anfra.plugins.has('lineage')`. */
543
+ readonly lineage: boolean;
544
+ }
526
545
  /** The package's version: anfra's own, as each release publishes the SDK with it. */
527
546
  declare const VERSION: string;
528
547
  /**
@@ -555,10 +574,21 @@ declare class Sdk {
555
574
  * before using an optional one.
556
575
  */
557
576
  readonly plugins: InstalledPlugins;
558
- private readonly features;
577
+ /** The kernel's gates (`dateDrill`), as the environment gave them. */
578
+ private readonly gates;
579
+ private deprecatedFeatures?;
559
580
  /** @internal What plugins add to each query and control, by plugin name (the kernel's `provideOn*`). */
560
581
  readonly extensions: EntityExtensions<Query, Control>;
561
582
  constructor(environment: SdkEnvironment);
583
+ /**
584
+ * Whether the host offers each of anfra's optional plugins, from before there were plugins. The
585
+ * first read warns once, in the console.
586
+ *
587
+ * @deprecated Check `Anfra.plugins.has(name)` instead: `Anfra.plugins.has('export')` for
588
+ * `Anfra.features.export`. Kept so Data Apps written before plugins keep working; removed in the
589
+ * next breaking release.
590
+ */
591
+ get features(): Readonly<DeprecatedFeatures>;
562
592
  createApp(declaration?: AppDeclaration): App;
563
593
  /**
564
594
  * Every app this instance has built, for a host rendering an inspection panel.
@@ -691,4 +721,5 @@ type PluginSetup = readonly [name: string, setup: ((kernel: FrameKernel) => void
691
721
  /** Provision the SDK in `win` from its host, run the plugins' setups, and install it. Returns once `Anfra` exists. */
692
722
  declare function bootstrap(win: Window, setups?: readonly PluginSetup[]): void;
693
723
 
694
- export { type AnfraPlugins as A, Control as C, DateDrillControl as D, type Edge as E, Filter as F, InstalledPlugins as I, Mapping as M, OVERLAY_ID as O, type PluginSetup as P, Query as Q, Sdk as S, VERSION as V, App as a, CrossFilter as b, type FrameKernel as c, type PluginApi as d, type PluginMembers as e, type PluginName as f, ATTR as g, bootstrap as h, buildStructure as i, createSdk as j, parseRef as p };
724
+ export { Control as C, DateDrillControl as D, Filter as F, InstalledPlugins as I, Mapping as M, OVERLAY_ID as O, Query as Q, Sdk as S, VERSION as V, App as a, CrossFilter as b, ATTR as h, bootstrap as i, buildStructure as j, createSdk as k, parseRef as p };
725
+ export type { AnfraPlugins as A, Edge as E, PluginSetup as P, DeprecatedFeatures as c, FrameKernel as d, PluginApi as e, PluginMembers as f, PluginName as g };
@@ -1,4 +1,4 @@
1
- import { D as DatasetDescriptor, ai as User } from './types-BTyDyld7.js';
1
+ import { D as DatasetDescriptor, aj as User } from './types-B9DqPgWS.js';
2
2
 
3
3
  /**
4
4
  * The bridge: the postMessage protocol between a Data App's frame (`app`'s bootstrap) and the
@@ -69,4 +69,5 @@ type HostMessage = Exclude<BridgeMessage, {
69
69
  type: 'anfra:ready';
70
70
  }>;
71
71
 
72
- export { type BridgeError as B, type FrameMessage as F, type HostMessage as H, PROVISION_ELEMENT_ID as P, type BridgeMessage as a, type PluginInfo as b, type Provision as c };
72
+ export { PROVISION_ELEMENT_ID as P };
73
+ export type { BridgeError as B, FrameMessage as F, HostMessage as H, BridgeMessage as a, PluginInfo as b, Provision as c };
package/dist/build.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { F as FrameHalf } from './plugin-C5cihcQD.js';
1
+ import { FrameHalf } from './host.js';
2
2
 
3
3
  /**
4
4
  * @holistics/anfra-sdk/build: building an SDK plugin's frame half into the script source a host
@@ -17,4 +17,5 @@ interface BuildFrameHalfOptions {
17
17
  /** Build a frame half: the setup, and the body if there is one, as script source for `plugin.frame`. */
18
18
  declare function buildFrameHalf(options: BuildFrameHalfOptions): Promise<FrameHalf>;
19
19
 
20
- export { type BuildFrameHalfOptions, buildFrameHalf };
20
+ export { buildFrameHalf };
21
+ export type { BuildFrameHalfOptions };
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-33B2D4U5.js";
10
10
  import {
11
11
  version
12
- } from "./chunk-ENWRS6AT.js";
12
+ } from "./chunk-S3YHTZKJ.js";
13
13
  import {
14
14
  DataAppError,
15
15
  PermissionError,
@@ -122,9 +122,13 @@ var Query = class extends Observable {
122
122
  this._sort = [...sort];
123
123
  this.notify();
124
124
  }
125
+ /**
126
+ * Whether another page may follow: as the backend said of the last page, or, when it did not
127
+ * say, whether that page came back full.
128
+ */
125
129
  get hasMore() {
126
130
  if (!this._result || this.pageSize === void 0) return false;
127
- return this.lastPageRows >= this.pageSize;
131
+ return this._result.meta.hasMore ?? this.lastPageRows >= this.pageSize;
128
132
  }
129
133
  /**
130
134
  * Everything that changes the rows: the declaration, the conditions reaching this query through
@@ -862,7 +866,11 @@ function toResult(query, data) {
862
866
  rows,
863
867
  meta: {
864
868
  // Only a paged query has a page to report.
865
- ...pageSize !== void 0 ? { page: data.meta?.page ?? query.page, pageSize: data.meta?.pageSize ?? pageSize } : {},
869
+ ...pageSize !== void 0 ? {
870
+ page: data.meta?.page ?? query.page,
871
+ pageSize: data.meta?.pageSize ?? pageSize,
872
+ ...data.meta?.hasMore !== void 0 ? { hasMore: data.meta.hasMore } : {}
873
+ } : {},
866
874
  numRows: data.meta?.numRows ?? rows.length
867
875
  },
868
876
  ...data.debug ? { debug: data.debug } : {}
@@ -1788,7 +1796,9 @@ var Sdk = class {
1788
1796
  * before using an optional one.
1789
1797
  */
1790
1798
  __publicField(this, "plugins");
1791
- __publicField(this, "features");
1799
+ /** The kernel's gates (`dateDrill`), as the environment gave them. */
1800
+ __publicField(this, "gates");
1801
+ __publicField(this, "deprecatedFeatures");
1792
1802
  /** @internal What plugins add to each query and control, by plugin name (the kernel's `provideOn*`). */
1793
1803
  __publicField(this, "extensions", { query: /* @__PURE__ */ new Map(), control: /* @__PURE__ */ new Map() });
1794
1804
  if (!environment?.datasets) {
@@ -1818,11 +1828,31 @@ var Sdk = class {
1818
1828
  ])
1819
1829
  );
1820
1830
  this.backend = environment.backend;
1821
- this.features = Object.freeze({ ...environment.features });
1831
+ this.gates = Object.freeze({ ...environment.features });
1822
1832
  this.plugins = new InstalledPlugins(environment.plugins ?? []);
1823
1833
  }
1834
+ /**
1835
+ * Whether the host offers each of anfra's optional plugins, from before there were plugins. The
1836
+ * first read warns once, in the console.
1837
+ *
1838
+ * @deprecated Check `Anfra.plugins.has(name)` instead: `Anfra.plugins.has('export')` for
1839
+ * `Anfra.features.export`. Kept so Data Apps written before plugins keep working; removed in the
1840
+ * next breaking release.
1841
+ */
1842
+ get features() {
1843
+ if (!this.deprecatedFeatures) {
1844
+ console.warn("anfra: Anfra.features is deprecated and will be removed. Check Anfra.plugins.has('export'), Anfra.plugins.has('render') or Anfra.plugins.has('lineage') instead.");
1845
+ this.deprecatedFeatures = Object.freeze({
1846
+ ...this.gates,
1847
+ export: this.plugins.has("export"),
1848
+ render: this.plugins.has("render"),
1849
+ lineage: this.plugins.has("lineage")
1850
+ });
1851
+ }
1852
+ return this.deprecatedFeatures;
1853
+ }
1824
1854
  createApp(declaration = {}) {
1825
- const app = new App(declaration, this.indices, this.backend, this.features, this.extensions);
1855
+ const app = new App(declaration, this.indices, this.backend, this.gates, this.extensions);
1826
1856
  app.index = this._apps.length;
1827
1857
  this._apps.push(app);
1828
1858
  return app;
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.11.0";
2
+ var version = "0.12.0";
3
3
 
4
4
  export {
5
5
  version
package/dist/common.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { D as DataAppError, P as PermissionError, Q as QueryError, T as TransportError, V as ValidationError } from './errors-CKvqVaqU.js';
2
- export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as RenderFormat, a7 as RenderRequest, a8 as Rendering, a9 as Row, aa as SdkEnvironment, ab as SdkFeatures, ac as Selection, ad as SelectionCondition, ae as SemanticType, af as StructureKind, ag as StructureNode, ah as Unsubscribe, ai as User } from './types-BTyDyld7.js';
3
- export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-Byq62yS8.js';
2
+ export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as QueryTimings, a7 as RenderFormat, a8 as RenderRequest, a9 as Rendering, aa as Row, ab as SdkEnvironment, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, af as SemanticType, ag as StructureKind, ah as StructureNode, ai as Unsubscribe, aj as User } from './types-B9DqPgWS.js';
3
+ export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-_Ez5VZV9.js';
package/dist/host.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { b as PluginInfo, c as Provision } from './bridge-Byq62yS8.js';
2
- import { D as DatasetDescriptor, ai as User } from './types-BTyDyld7.js';
3
- import { C as CallOptions, P as Plugin, M as Middleware } from './plugin-C5cihcQD.js';
4
- export { a as CallContext, b as CallDefinition, c as CallHandler, d as Caller, E as EventCheck, F as FrameHalf, H as HandlerCallOptions, e as HandlerContext, f as HostHalf, g as MountContext, h as definePlugin } from './plugin-C5cihcQD.js';
1
+ import { PluginInfo, Provision } from './app.js';
2
+ import { DatasetDescriptor, User } from './app.js';
3
+ import { C as CallOptions, P as Plugin, M as Middleware } from './plugin-056-SKwd.js';
4
+ export { a as CallContext, b as CallDefinition, c as CallHandler, d as Caller, E as EventCheck, F as FrameHalf, H as HandlerCallOptions, e as HandlerContext, f as HostHalf, g as MountContext, h as definePlugin } from './plugin-056-SKwd.js';
5
5
 
6
6
  interface HostOptions {
7
7
  /** The plugins this page's Data Apps get. `core` is required: the app model runs its queries with it. */
@@ -10,14 +10,18 @@ interface HostOptions {
10
10
  middleware?: readonly Middleware[];
11
11
  /** The frame script; the one built into this package unless given (tests). */
12
12
  frameScript?: string;
13
+ /**
14
+ * Origins a Data App may load scripts, styles, fonts and images from, and fetch them from, beside
15
+ * the policy's own CDNs: each `https://<host>[:<port>]`, nothing after it. Never a way to the
16
+ * network at large (docs/designs/security.md).
17
+ */
18
+ allowOrigins?: readonly string[];
13
19
  }
14
20
  interface MountOptions {
15
21
  /** Where the frame goes: it is appended to this element. */
16
22
  container: HTMLElement;
17
23
  /** The Data App definition: its HTML, as its author wrote it. */
18
24
  definition: string;
19
- /** Where the definition's relative URLs resolve. */
20
- baseHref: string;
21
25
  datasets: Record<string, DatasetDescriptor>;
22
26
  user: User;
23
27
  title?: string;
@@ -51,8 +55,8 @@ interface Host {
51
55
  declare function createHost(options: HostOptions): Host;
52
56
 
53
57
  interface ProvisionOptions {
54
- /** Where the definition's relative URLs resolve: the directory it was read from. */
55
- baseHref: string;
58
+ /** The frame's content policy (`contentPolicy`), set before anything of the definition's. */
59
+ contentPolicy: string;
56
60
  provision: Provision;
57
61
  /** The frame script (`@holistics/anfra-sdk/app`'s kernel, as `__anfraKernel`), run before any of the definition's own. */
58
62
  frameScript: string;
@@ -72,11 +76,34 @@ declare function composeFrameScript(frameScript: string, setups?: readonly {
72
76
  setup: string;
73
77
  }[]): string;
74
78
  /**
75
- * A Data App's frame document: its definition, with its base URL, the provision data and the frame
76
- * script (the kernel and the plugins' setups) added at the top of its <head> (after <meta charset> when there is one, so the encoding is
77
- * still declared first), so `Anfra` exists before the definition's first script runs. The
78
- * definition itself never mentions the SDK.
79
+ * A Data App's frame document: its definition, with its content policy as the first element the
80
+ * parser meets, so it governs every script, style and fetch of the definition's, even one written
81
+ * ahead of its `<meta charset>`; then the provision data and the frame script (the kernel and the
82
+ * plugins' setups) at the top of its <head> (after <meta charset> when there is one, so the
83
+ * encoding is still declared first), so `Anfra` exists before the definition's first script runs.
84
+ * The definition itself never mentions the SDK.
79
85
  */
80
86
  declare function provisionDocument(definition: string, options: ProvisionOptions): string;
81
87
 
82
- export { CallOptions, type Host, type HostOptions, Middleware, type MountOptions, type MountedDataApp, Plugin, type ProvisionOptions, composeFrameScript, createHost, provisionDocument };
88
+ /**
89
+ * The content policy a Data App's frame runs under: libraries from a short list of CDNs, data only
90
+ * over the bridge. The sandbox keeps the frame away from the page around it; this keeps it away
91
+ * from the network, so an app, or a library it loads, cannot send what its reader can query to a
92
+ * server of its choosing (docs/designs/security.md).
93
+ */
94
+ /** Where an app may load scripts from, and styles and fonts beside them. */
95
+ declare const SCRIPT_ORIGINS: readonly string[];
96
+ /**
97
+ * An origin a host may add: `https://` with a host and nothing after it, as `URL` writes it, so it
98
+ * cannot widen a directive (a scheme, a wildcard) or end one (a space, a `;`).
99
+ */
100
+ declare function checkOrigin(origin: unknown): string;
101
+ /**
102
+ * The policy, with a host's own origins added to every source an app loads from, and to what it
103
+ * may fetch: the render plugin fetches the images, stylesheets and fonts it embeds in a picture.
104
+ * Nothing else is reachable. `'self'` is absent: the frame's origin is opaque, so it matches nothing.
105
+ */
106
+ declare function contentPolicy(allowOrigins?: readonly string[]): string;
107
+
108
+ export { CallOptions, Middleware, Plugin, SCRIPT_ORIGINS, checkOrigin, composeFrameScript, contentPolicy, createHost, provisionDocument };
109
+ export type { Host, HostOptions, MountOptions, MountedDataApp, ProvisionOptions };