@holistics/anfra-sdk 0.7.1 → 0.9.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
@@ -44,9 +44,36 @@ app.subscribe(() => render(byRegion.result));
44
44
  await app.execute();
45
45
  ```
46
46
 
47
+ A reader can download a query's whole result, with the inputs its result on screen was run with:
48
+
49
+ ```js
50
+ if (Anfra.features.export && Anfra.user.permissions.canExportData) {
51
+ button.onclick = () => byRegion.export().catch((err) => showError(err.message));
52
+ }
53
+ ```
54
+
55
+ `export()` resolves once the file is made and the host has started saving it, with its link and
56
+ `rowCount`. The file is a CSV named after the app and the query unless you pass `filename`.
57
+
58
+ A reader can download a picture of the app, or of one block or container, as they see it:
59
+
60
+ ```js
61
+ await Anfra.render({ block: 'trend', format: 'png' }); // or 'pdf'; no node: the whole app
62
+ ```
63
+
64
+ It works only where the host turned rendering on (`mountDataApp({ render: true })`; `anfra serve`
65
+ does). Check `Anfra.features.render` and `Anfra.user.permissions.canExportData` before offering it, and
66
+ mark what shouldn't be drawn (the download button itself) `data-anfra-render="skip"`. Serve images
67
+ and web fonts with CORS: an image without it is left blank (listed in the result's `omitted`), a
68
+ font without it falls back.
69
+
47
70
  `Anfra.datasets` describes what there is to query. For TypeScript, `@holistics/anfra-sdk/ambient` declares the
48
71
  global.
49
72
 
73
+ `Anfra.lineage({ parent: 'orders', child: 'amount' })` traces fields through the repo's catalog, each named
74
+ by its parent and its name in it: what each is built from, as a diagram to draw (`results[i].diagram`), or
75
+ why it could not be (`results[i].error`). It reads the catalog the host last ingested (`anfra ingest`).
76
+
50
77
  A definition can mark its parts, so a host's inspect panel can show them as a tree and find them on
51
78
  the page:
52
79
 
@@ -81,20 +108,22 @@ const mounted = mountDataApp({
81
108
  baseHref: '/appserve/files/sales/', // where its relative URLs resolve
82
109
  datasets,
83
110
  user,
84
- backend: coreApiBackend(client, { datasets }), // queries and field suggestions, as core.query
111
+ backend: coreApiBackend(client, { datasets }), // queries, field suggestions and exports, as core ops; lineage as core.lineage
112
+ render: true, // let it save PNGs and PDFs of itself (off by default)
85
113
  });
86
- // mounted.setInspecting(true) to receive inspection snapshots; mounted.unmount() when done.
114
+ // mounted.setInspecting(true) to receive inspection snapshots; mounted.render({ format: 'pdf' }) to
115
+ // save a picture of the app (needs render: true); mounted.unmount() when done.
87
116
  ```
88
117
 
89
118
  `mountDataApp` puts the definition in an iframe with `sandbox="allow-scripts"`, as its `srcdoc`,
90
- with the frame bootstrap and the provisioned data ahead of it. The bootstrap's Backend forwards each call to the host over postMessage; the host answers it with the Backend it was given.
119
+ with the frame bootstrap and the provisioned data ahead of it. The bootstrap's Backend forwards each call to the host over postMessage; the host answers it with the Backend it was given. An export's file is saved from the host's page, by following its link: the frame can't download. A Backend without `exportQuery` makes a host that can't export, and its frames see `Anfra.features.export` false; likewise a Backend without `lineage`, and `Anfra.features.lineage`.
91
120
 
92
121
  ## The boundary
93
122
 
94
123
  A Data App definition can come from any author, often an agent, which may not think of security while building an analysis. So the SDK guards it for its author, and makes the safe way the easy one:
95
124
 
96
125
  - Its frame has an opaque origin. Its own requests to the API are cross-origin, which `anfra serve` refuses, and carry no credentials on a platform that has them.
97
- - The bridge answers only the Backend's two methods, `submitQuery` and `fieldSuggestions`. Nothing else of the API is reachable from a frame.
126
+ - The bridge answers only the Backend's methods, `submitQuery`, `fieldSuggestions`, `exportQuery` and the optional `lineage`, and the two a rendering needs, the renderer's code and saving its file. Nothing else of the API is reachable from a frame.
98
127
  - `@holistics/anfra-sdk/app` imports only `common`: the script injected into a frame carries no API client. A test on the built frame script holds this.
99
128
 
100
129
  ## Development