@xemahq/ui-kernel 0.9.0 → 0.9.1
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.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/biome-host/biome-registry.d.ts.map +1 -1
- package/dist/lib/biome-host/biome-registry.js +14 -9
- package/dist/lib/biome-host/biome-registry.js.map +1 -1
- package/dist/lib/contribution-registry/contribution-registry.d.ts +24 -0
- package/dist/lib/contribution-registry/contribution-registry.d.ts.map +1 -0
- package/dist/lib/contribution-registry/contribution-registry.js +67 -0
- package/dist/lib/contribution-registry/contribution-registry.js.map +1 -0
- package/dist/lib/contribution-registry/index.d.ts +3 -0
- package/dist/lib/contribution-registry/index.d.ts.map +1 -0
- package/dist/lib/contribution-registry/index.js +3 -0
- package/dist/lib/contribution-registry/index.js.map +1 -0
- package/dist/lib/contribution-registry/renderable-registry.d.ts +33 -0
- package/dist/lib/contribution-registry/renderable-registry.d.ts.map +1 -0
- package/dist/lib/contribution-registry/renderable-registry.js +51 -0
- package/dist/lib/contribution-registry/renderable-registry.js.map +1 -0
- package/dist/ui/capture/field-spec-to-zod.d.ts +1 -0
- package/dist/ui/capture/field-spec-to-zod.d.ts.map +1 -1
- package/dist/ui/capture/field-spec-to-zod.js +19 -0
- package/dist/ui/capture/field-spec-to-zod.js.map +1 -1
- package/dist/ui/capture/field-spec-validate.d.ts +4 -0
- package/dist/ui/capture/field-spec-validate.d.ts.map +1 -0
- package/dist/ui/capture/field-spec-validate.js +129 -0
- package/dist/ui/capture/field-spec-validate.js.map +1 -0
- package/dist/ui/capture/field-spec.d.ts +13 -1
- package/dist/ui/capture/field-spec.d.ts.map +1 -1
- package/dist/ui/capture/field-spec.js +25 -0
- package/dist/ui/capture/field-spec.js.map +1 -1
- package/dist/ui/capture/index.d.ts +4 -2
- package/dist/ui/capture/index.d.ts.map +1 -1
- package/dist/ui/capture/index.js +4 -2
- package/dist/ui/capture/index.js.map +1 -1
- package/dist/ui/capture/schema-field-input.d.ts.map +1 -1
- package/dist/ui/capture/schema-field-input.js +39 -12
- package/dist/ui/capture/schema-field-input.js.map +1 -1
- package/dist/ui/capture/submit-values.d.ts +6 -0
- package/dist/ui/capture/submit-values.d.ts.map +1 -0
- package/dist/ui/capture/submit-values.js +28 -0
- package/dist/ui/capture/submit-values.js.map +1 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/primitives/overflow-tabs.d.ts +5 -0
- package/dist/ui/primitives/overflow-tabs.d.ts.map +1 -1
- package/dist/ui/primitives/overflow-tabs.js +4 -4
- package/dist/ui/primitives/overflow-tabs.js.map +1 -1
- package/dist/ui/primitives/url-preview-chrome.d.ts +8 -0
- package/dist/ui/primitives/url-preview-chrome.d.ts.map +1 -0
- package/dist/ui/primitives/url-preview-chrome.js +40 -0
- package/dist/ui/primitives/url-preview-chrome.js.map +1 -0
- package/dist/vista/GenericCatalogueSurface.d.ts +10 -0
- package/dist/vista/GenericCatalogueSurface.d.ts.map +1 -0
- package/dist/vista/GenericCatalogueSurface.js +80 -0
- package/dist/vista/GenericCatalogueSurface.js.map +1 -0
- package/dist/vista/SurfaceFallbackCard.d.ts +9 -0
- package/dist/vista/SurfaceFallbackCard.d.ts.map +1 -0
- package/dist/vista/SurfaceFallbackCard.js +44 -0
- package/dist/vista/SurfaceFallbackCard.js.map +1 -0
- package/dist/vista/VistaPanel.d.ts +21 -0
- package/dist/vista/VistaPanel.d.ts.map +1 -0
- package/dist/vista/VistaPanel.js +31 -0
- package/dist/vista/VistaPanel.js.map +1 -0
- package/dist/vista/html/CustomUiFrame.d.ts +20 -0
- package/dist/vista/html/CustomUiFrame.d.ts.map +1 -0
- package/dist/vista/html/CustomUiFrame.js +69 -0
- package/dist/vista/html/CustomUiFrame.js.map +1 -0
- package/dist/vista/html/custom-ui-frame-bridge.d.ts +13 -0
- package/dist/vista/html/custom-ui-frame-bridge.d.ts.map +1 -0
- package/dist/vista/html/custom-ui-frame-bridge.js +30 -0
- package/dist/vista/html/custom-ui-frame-bridge.js.map +1 -0
- package/dist/vista/html/custom-ui-frame-contract.d.ts +29 -0
- package/dist/vista/html/custom-ui-frame-contract.d.ts.map +1 -0
- package/dist/vista/html/custom-ui-frame-contract.js +16 -0
- package/dist/vista/html/custom-ui-frame-contract.js.map +1 -0
- package/dist/vista/html/custom-ui-intents.d.ts +20 -0
- package/dist/vista/html/custom-ui-intents.d.ts.map +1 -0
- package/dist/vista/html/custom-ui-intents.js +57 -0
- package/dist/vista/html/custom-ui-intents.js.map +1 -0
- package/dist/vista/html/custom-ui-srcdoc.d.ts +17 -0
- package/dist/vista/html/custom-ui-srcdoc.d.ts.map +1 -0
- package/dist/vista/html/custom-ui-srcdoc.js +70 -0
- package/dist/vista/html/custom-ui-srcdoc.js.map +1 -0
- package/dist/vista/html/index.d.ts +6 -0
- package/dist/vista/html/index.d.ts.map +1 -0
- package/dist/vista/html/index.js +6 -0
- package/dist/vista/html/index.js.map +1 -0
- package/dist/vista/index.d.ts +18 -0
- package/dist/vista/index.d.ts.map +1 -0
- package/dist/vista/index.js +18 -0
- package/dist/vista/index.js.map +1 -0
- package/dist/vista/surface-catalogue.d.ts +5 -0
- package/dist/vista/surface-catalogue.d.ts.map +1 -0
- package/dist/vista/surface-catalogue.js +30 -0
- package/dist/vista/surface-catalogue.js.map +1 -0
- package/dist/vista/surface-icons.d.ts +7 -0
- package/dist/vista/surface-icons.d.ts.map +1 -0
- package/dist/vista/surface-icons.js +26 -0
- package/dist/vista/surface-icons.js.map +1 -0
- package/dist/vista/surface-registry.d.ts +7 -0
- package/dist/vista/surface-registry.d.ts.map +1 -0
- package/dist/vista/surface-registry.js +7 -0
- package/dist/vista/surface-registry.js.map +1 -0
- package/dist/vista/surfaces/ChartSurface.d.ts +4 -0
- package/dist/vista/surfaces/ChartSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/ChartSurface.js +17 -0
- package/dist/vista/surfaces/ChartSurface.js.map +1 -0
- package/dist/vista/surfaces/FilesSurface.d.ts +15 -0
- package/dist/vista/surfaces/FilesSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/FilesSurface.js +121 -0
- package/dist/vista/surfaces/FilesSurface.js.map +1 -0
- package/dist/vista/surfaces/FormSurface.d.ts +4 -0
- package/dist/vista/surfaces/FormSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/FormSurface.js +97 -0
- package/dist/vista/surfaces/FormSurface.js.map +1 -0
- package/dist/vista/surfaces/HtmlSurface.d.ts +4 -0
- package/dist/vista/surfaces/HtmlSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/HtmlSurface.js +11 -0
- package/dist/vista/surfaces/HtmlSurface.js.map +1 -0
- package/dist/vista/surfaces/TableSurface.d.ts +4 -0
- package/dist/vista/surfaces/TableSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/TableSurface.js +42 -0
- package/dist/vista/surfaces/TableSurface.js.map +1 -0
- package/dist/vista/surfaces/UrlSurface.d.ts +4 -0
- package/dist/vista/surfaces/UrlSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/UrlSurface.js +7 -0
- package/dist/vista/surfaces/UrlSurface.js.map +1 -0
- package/dist/vista/surfaces/blob-surfaces.d.ts +6 -0
- package/dist/vista/surfaces/blob-surfaces.d.ts.map +1 -0
- package/dist/vista/surfaces/blob-surfaces.js +38 -0
- package/dist/vista/surfaces/blob-surfaces.js.map +1 -0
- package/dist/vista/surfaces/elicitation-transport.d.ts +18 -0
- package/dist/vista/surfaces/elicitation-transport.d.ts.map +1 -0
- package/dist/vista/surfaces/elicitation-transport.js +100 -0
- package/dist/vista/surfaces/elicitation-transport.js.map +1 -0
- package/dist/vista/surfaces/index.d.ts +11 -0
- package/dist/vista/surfaces/index.d.ts.map +1 -0
- package/dist/vista/surfaces/index.js +89 -0
- package/dist/vista/surfaces/index.js.map +1 -0
- package/dist/vista/surfaces/text-surfaces.d.ts +8 -0
- package/dist/vista/surfaces/text-surfaces.d.ts.map +1 -0
- package/dist/vista/surfaces/text-surfaces.js +54 -0
- package/dist/vista/surfaces/text-surfaces.js.map +1 -0
- package/dist/vista/use-vista-tabs.d.ts +30 -0
- package/dist/vista/use-vista-tabs.d.ts.map +1 -0
- package/dist/vista/use-vista-tabs.js +77 -0
- package/dist/vista/use-vista-tabs.js.map +1 -0
- package/dist/vista/vista-code-renderer.d.ts +12 -0
- package/dist/vista/vista-code-renderer.d.ts.map +1 -0
- package/dist/vista/vista-code-renderer.js +10 -0
- package/dist/vista/vista-code-renderer.js.map +1 -0
- package/dist/vista/vista-file-source.d.ts +20 -0
- package/dist/vista/vista-file-source.d.ts.map +1 -0
- package/dist/vista/vista-file-source.js +69 -0
- package/dist/vista/vista-file-source.js.map +1 -0
- package/dist/vista/vista-form-host.d.ts +16 -0
- package/dist/vista/vista-form-host.d.ts.map +1 -0
- package/dist/vista/vista-form-host.js +10 -0
- package/dist/vista/vista-form-host.js.map +1 -0
- package/dist/vista/vista-model.d.ts +12 -0
- package/dist/vista/vista-model.d.ts.map +1 -0
- package/dist/vista/vista-model.js +72 -0
- package/dist/vista/vista-model.js.map +1 -0
- package/dist/vista/vista-open-context.d.ts +9 -0
- package/dist/vista/vista-open-context.d.ts.map +1 -0
- package/dist/vista/vista-open-context.js +10 -0
- package/dist/vista/vista-open-context.js.map +1 -0
- package/dist/vista/vista-payloads.d.ts +107 -0
- package/dist/vista/vista-payloads.d.ts.map +1 -0
- package/dist/vista/vista-payloads.js +305 -0
- package/dist/vista/vista-payloads.js.map +1 -0
- package/dist/vista/vista-tabs-manifest.d.ts +17 -0
- package/dist/vista/vista-tabs-manifest.d.ts.map +1 -0
- package/dist/vista/vista-tabs-manifest.js +60 -0
- package/dist/vista/vista-tabs-manifest.js.map +1 -0
- package/dist/vista/vista-tools.d.ts +41 -0
- package/dist/vista/vista-tools.d.ts.map +1 -0
- package/dist/vista/vista-tools.js +113 -0
- package/dist/vista/vista-tools.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +5 -0
- package/src/lib/biome-host/biome-registry.ts +31 -11
- package/src/lib/contribution-registry/contribution-registry.spec.ts +141 -0
- package/src/lib/contribution-registry/contribution-registry.ts +202 -0
- package/src/lib/contribution-registry/index.ts +9 -0
- package/src/lib/contribution-registry/renderable-registry.ts +142 -0
- package/src/ui/capture/field-spec-to-zod.ts +22 -0
- package/src/ui/capture/field-spec-validate.ts +147 -0
- package/src/ui/capture/field-spec.ts +62 -0
- package/src/ui/capture/index.ts +9 -1
- package/src/ui/capture/schema-field-input.tsx +134 -14
- package/src/ui/capture/submit-values.test.ts +70 -0
- package/src/ui/capture/submit-values.ts +63 -0
- package/src/ui/index.ts +4 -0
- package/src/ui/primitives/overflow-tabs.tsx +24 -4
- package/src/ui/primitives/url-preview-chrome.tsx +102 -0
- package/src/vista/GenericCatalogueSurface.tsx +177 -0
- package/src/vista/SurfaceFallbackCard.tsx +109 -0
- package/src/vista/VistaPanel.tsx +155 -0
- package/src/vista/form-payload.spec.ts +93 -0
- package/src/vista/html/CustomUiFrame.spec.tsx +125 -0
- package/src/vista/html/CustomUiFrame.tsx +204 -0
- package/src/vista/html/custom-ui-frame-bridge.spec.ts +191 -0
- package/src/vista/html/custom-ui-frame-bridge.ts +92 -0
- package/src/vista/html/custom-ui-frame-contract.ts +88 -0
- package/src/vista/html/custom-ui-intents.spec.ts +133 -0
- package/src/vista/html/custom-ui-intents.ts +151 -0
- package/src/vista/html/custom-ui-srcdoc.spec.ts +151 -0
- package/src/vista/html/custom-ui-srcdoc.ts +193 -0
- package/src/vista/html/index.ts +13 -0
- package/src/vista/index.ts +48 -0
- package/src/vista/surface-catalogue.spec.ts +140 -0
- package/src/vista/surface-catalogue.ts +84 -0
- package/src/vista/surface-icons.ts +57 -0
- package/src/vista/surface-registry.ts +56 -0
- package/src/vista/surfaces/ChartSurface.tsx +34 -0
- package/src/vista/surfaces/FilesSurface.tsx +268 -0
- package/src/vista/surfaces/FormSurface.tsx +264 -0
- package/src/vista/surfaces/HtmlSurface.tsx +43 -0
- package/src/vista/surfaces/TableSurface.tsx +99 -0
- package/src/vista/surfaces/UrlSurface.tsx +40 -0
- package/src/vista/surfaces/blob-surfaces.tsx +129 -0
- package/src/vista/surfaces/elicitation-transport.spec.ts +187 -0
- package/src/vista/surfaces/elicitation-transport.ts +175 -0
- package/src/vista/surfaces/index.tsx +157 -0
- package/src/vista/surfaces/text-surfaces.tsx +119 -0
- package/src/vista/use-vista-tabs.ts +188 -0
- package/src/vista/vista-code-renderer.tsx +46 -0
- package/src/vista/vista-file-source.tsx +163 -0
- package/src/vista/vista-form-host.tsx +78 -0
- package/src/vista/vista-model.ts +130 -0
- package/src/vista/vista-open-context.tsx +42 -0
- package/src/vista/vista-payloads.ts +514 -0
- package/src/vista/vista-tabs-manifest.ts +123 -0
- package/src/vista/vista-tools.ts +220 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SurfaceKind.Table` — generic columns + rows, the universal "show me
|
|
3
|
+
* structured records" surface.
|
|
4
|
+
*
|
|
5
|
+
* Presentation only: no sorting model, no paging, no cell semantics. A cell
|
|
6
|
+
* value that is not a primitive is JSON-serialised rather than dropped, so a
|
|
7
|
+
* nested value is visible instead of silently blank.
|
|
8
|
+
*/
|
|
9
|
+
import type { VistaTablePayload } from '../vista-payloads';
|
|
10
|
+
import type { ReactElement } from 'react';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
function cellText(value: unknown): string {
|
|
14
|
+
if (value === null || value === undefined) return '';
|
|
15
|
+
if (typeof value === 'object') {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.stringify(value);
|
|
18
|
+
} catch {
|
|
19
|
+
return String(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return String(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function TableSurface({
|
|
26
|
+
columns,
|
|
27
|
+
rows,
|
|
28
|
+
}: Readonly<VistaTablePayload>): ReactElement {
|
|
29
|
+
return (
|
|
30
|
+
<div style={{ height: '100%', overflow: 'auto' }}>
|
|
31
|
+
<table
|
|
32
|
+
style={{
|
|
33
|
+
width: '100%',
|
|
34
|
+
borderCollapse: 'collapse',
|
|
35
|
+
fontSize: 12.5,
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<thead>
|
|
39
|
+
<tr>
|
|
40
|
+
{columns.map((column) => (
|
|
41
|
+
<th
|
|
42
|
+
key={column}
|
|
43
|
+
style={{
|
|
44
|
+
position: 'sticky',
|
|
45
|
+
top: 0,
|
|
46
|
+
textAlign: 'left',
|
|
47
|
+
padding: '8px 12px',
|
|
48
|
+
background: 'hsl(var(--paper-elev))',
|
|
49
|
+
borderBottom: '1px solid hsl(var(--rule))',
|
|
50
|
+
color: 'hsl(var(--ink-3))',
|
|
51
|
+
fontWeight: 600,
|
|
52
|
+
whiteSpace: 'nowrap',
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{column}
|
|
56
|
+
</th>
|
|
57
|
+
))}
|
|
58
|
+
</tr>
|
|
59
|
+
</thead>
|
|
60
|
+
<tbody>
|
|
61
|
+
{rows.map((row, rowIndex) => (
|
|
62
|
+
<tr
|
|
63
|
+
// Rows carry no identity in the generic contract; position is the
|
|
64
|
+
// only stable key available.
|
|
65
|
+
|
|
66
|
+
key={rowIndex}
|
|
67
|
+
>
|
|
68
|
+
{columns.map((column, columnIndex) => (
|
|
69
|
+
<td
|
|
70
|
+
key={column}
|
|
71
|
+
style={{
|
|
72
|
+
padding: '7px 12px',
|
|
73
|
+
borderBottom: '1px solid hsl(var(--rule) / 0.6)',
|
|
74
|
+
color: 'hsl(var(--ink-2))',
|
|
75
|
+
verticalAlign: 'top',
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
{cellText(row[columnIndex])}
|
|
79
|
+
</td>
|
|
80
|
+
))}
|
|
81
|
+
</tr>
|
|
82
|
+
))}
|
|
83
|
+
</tbody>
|
|
84
|
+
</table>
|
|
85
|
+
{rows.length === 0 && (
|
|
86
|
+
<div
|
|
87
|
+
style={{
|
|
88
|
+
padding: 24,
|
|
89
|
+
textAlign: 'center',
|
|
90
|
+
fontSize: 12.5,
|
|
91
|
+
color: 'hsl(var(--ink-4))',
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
No rows.
|
|
95
|
+
</div>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SurfaceKind.Url` — a live external URL inside mock browser chrome.
|
|
3
|
+
*
|
|
4
|
+
* The chrome (traffic lights + address bar + reload) is `UrlPreviewChrome`,
|
|
5
|
+
* lifted out of the thin session workspace; the device bezel is the shared
|
|
6
|
+
* `PreviewDeviceFrame`. The frame itself is `sandbox="allow-scripts
|
|
7
|
+
* allow-forms"` and NEVER `allow-same-origin`: a previewed app runs in its own
|
|
8
|
+
* opaque origin and cannot reach the host's DOM, cookies or tokens.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { PreviewDeviceFrame } from '../../ui/primitives/preview-device-frame';
|
|
12
|
+
import { UrlPreviewChrome } from '../../ui/primitives/url-preview-chrome';
|
|
13
|
+
|
|
14
|
+
import type { VistaUrlPayload } from '../vista-payloads';
|
|
15
|
+
import type { ReactElement } from 'react';
|
|
16
|
+
|
|
17
|
+
export function UrlSurface({
|
|
18
|
+
url,
|
|
19
|
+
device = 'desktop',
|
|
20
|
+
reloadNonce,
|
|
21
|
+
}: Readonly<VistaUrlPayload>): ReactElement {
|
|
22
|
+
return (
|
|
23
|
+
<UrlPreviewChrome url={url}>
|
|
24
|
+
<PreviewDeviceFrame device={device}>
|
|
25
|
+
<iframe
|
|
26
|
+
// Remounting on a nonce change is how a reload is requested without
|
|
27
|
+
// reaching into the frame (which we cannot do: it is cross-origin).
|
|
28
|
+
key={`${url}::${device}::${reloadNonce ?? 0}`}
|
|
29
|
+
title={`Preview of ${url}`}
|
|
30
|
+
src={url}
|
|
31
|
+
// NEVER add allow-same-origin — it would dissolve the origin boundary
|
|
32
|
+
// between the previewed app and the host.
|
|
33
|
+
sandbox="allow-scripts allow-forms"
|
|
34
|
+
loading="lazy"
|
|
35
|
+
style={{ height: '100%', width: '100%', border: 0 }}
|
|
36
|
+
/>
|
|
37
|
+
</PreviewDeviceFrame>
|
|
38
|
+
</UrlPreviewChrome>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The binary-bodied first-party surfaces: `image`, `media`, `pdf`.
|
|
3
|
+
*
|
|
4
|
+
* Each accepts an already-resolved `url` OR a workspace `path` resolved through
|
|
5
|
+
* the host {@link VistaFileSource}.
|
|
6
|
+
*
|
|
7
|
+
* SECURITY — `pdf`: the bytes are frequently UNTRUSTED (user uploads,
|
|
8
|
+
* agent-produced artifacts). The PDF is painted onto a `<canvas>` by pdf.js
|
|
9
|
+
* (the shared `PdfPreview`) — NO iframe, NO script execution — never embedded
|
|
10
|
+
* in the browser's own viewer. `PdfPreview` is lazy-imported so pdf.js
|
|
11
|
+
* (~1.9 MB) stays out of any bundle that never opens a PDF; that dynamic import
|
|
12
|
+
* is the whole point of the `@xemahq/ui-kernel/pdf` subpath.
|
|
13
|
+
*/
|
|
14
|
+
import { Suspense, lazy, type ReactElement, type ReactNode } from 'react';
|
|
15
|
+
|
|
16
|
+
import { VistaFileUrl } from '../vista-file-source';
|
|
17
|
+
|
|
18
|
+
import type { VistaBlobPayload } from '../vista-payloads';
|
|
19
|
+
|
|
20
|
+
const PdfPreview = lazy(() =>
|
|
21
|
+
import('../../pdf').then((m) => ({ default: m.PdfPreview })),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/** Render from an inline url, or resolve the path first. */
|
|
25
|
+
function BlobBody({
|
|
26
|
+
payload,
|
|
27
|
+
render,
|
|
28
|
+
}: Readonly<{
|
|
29
|
+
payload: VistaBlobPayload;
|
|
30
|
+
render: (url: string) => ReactNode;
|
|
31
|
+
}>): ReactElement {
|
|
32
|
+
if (payload.url !== undefined) return <>{render(payload.url)}</>;
|
|
33
|
+
// `validateBlobPayload` guarantees exactly one of url/path.
|
|
34
|
+
return <VistaFileUrl path={payload.path as string} render={render} />;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function ImageSurface(payload: VistaBlobPayload): ReactElement {
|
|
38
|
+
return (
|
|
39
|
+
<BlobBody
|
|
40
|
+
payload={payload}
|
|
41
|
+
render={(url) => (
|
|
42
|
+
<div
|
|
43
|
+
style={{
|
|
44
|
+
height: '100%',
|
|
45
|
+
display: 'grid',
|
|
46
|
+
placeItems: 'center',
|
|
47
|
+
padding: 16,
|
|
48
|
+
overflow: 'auto',
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
<img
|
|
52
|
+
src={url}
|
|
53
|
+
alt={payload.alt ?? 'Preview'}
|
|
54
|
+
style={{ maxWidth: '100%', maxHeight: '100%', objectFit: 'contain' }}
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
)}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function PdfSurface(payload: VistaBlobPayload): ReactElement {
|
|
63
|
+
return (
|
|
64
|
+
<BlobBody
|
|
65
|
+
payload={payload}
|
|
66
|
+
render={(url) => (
|
|
67
|
+
<Suspense
|
|
68
|
+
fallback={
|
|
69
|
+
<div
|
|
70
|
+
style={{
|
|
71
|
+
height: '100%',
|
|
72
|
+
display: 'grid',
|
|
73
|
+
placeItems: 'center',
|
|
74
|
+
fontSize: 12.5,
|
|
75
|
+
color: 'hsl(var(--ink-4))',
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
Loading viewer…
|
|
79
|
+
</div>
|
|
80
|
+
}
|
|
81
|
+
>
|
|
82
|
+
<PdfPreview
|
|
83
|
+
url={url}
|
|
84
|
+
title={payload.alt ?? 'PDF preview'}
|
|
85
|
+
className="h-full w-full"
|
|
86
|
+
/>
|
|
87
|
+
</Suspense>
|
|
88
|
+
)}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* `media` — audio or video, chosen by `contentType`. The type is REQUIRED by the
|
|
95
|
+
* payload validator for this kind (see the registration): guessing between an
|
|
96
|
+
* `<audio>` and a `<video>` element from a URL would be a heuristic that fails
|
|
97
|
+
* on extension-less URLs.
|
|
98
|
+
*/
|
|
99
|
+
export function MediaSurface(payload: VistaBlobPayload): ReactElement {
|
|
100
|
+
const isAudio = (payload.contentType ?? '').startsWith('audio/');
|
|
101
|
+
return (
|
|
102
|
+
<BlobBody
|
|
103
|
+
payload={payload}
|
|
104
|
+
render={(url) => (
|
|
105
|
+
<div
|
|
106
|
+
style={{
|
|
107
|
+
height: '100%',
|
|
108
|
+
display: 'grid',
|
|
109
|
+
placeItems: 'center',
|
|
110
|
+
padding: 16,
|
|
111
|
+
background: 'hsl(var(--paper-sunk))',
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
{isAudio ? (
|
|
115
|
+
// eslint-disable-next-line jsx-a11y/media-has-caption
|
|
116
|
+
<audio src={url} controls style={{ width: '100%', maxWidth: 520 }} />
|
|
117
|
+
) : (
|
|
118
|
+
// eslint-disable-next-line jsx-a11y/media-has-caption
|
|
119
|
+
<video
|
|
120
|
+
src={url}
|
|
121
|
+
controls
|
|
122
|
+
style={{ maxWidth: '100%', maxHeight: '100%' }}
|
|
123
|
+
/>
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
)}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guards the secure-elicitation transport — the ONE place a captured field
|
|
3
|
+
* value is read out of the `form` surface.
|
|
4
|
+
*
|
|
5
|
+
* These are the load-bearing proofs of Canopy §8.4: the value goes browser →
|
|
6
|
+
* service and the only thing that comes back out is `{ submitted, ref,
|
|
7
|
+
* connectionId }`. Runs under the host-web vitest mirror (this package carries
|
|
8
|
+
* no vitest dep).
|
|
9
|
+
*/
|
|
10
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
extractServiceMessage,
|
|
14
|
+
readElicitationStatus,
|
|
15
|
+
submitElicitationFields,
|
|
16
|
+
VistaFormSubmitError,
|
|
17
|
+
} from './elicitation-transport';
|
|
18
|
+
|
|
19
|
+
const SERVICE_ORIGIN = 'https://connector-gateway.example.test';
|
|
20
|
+
const SUBMIT_URL = `${SERVICE_ORIGIN}/credential-elicitations/ref-1/submit`;
|
|
21
|
+
const STATUS_URL = `${SERVICE_ORIGIN}/credential-elicitations/ref-1`;
|
|
22
|
+
const SECRET = 'sk-live-DO-NOT-LEAK';
|
|
23
|
+
|
|
24
|
+
function jsonResponse(status: number, body: unknown): Response {
|
|
25
|
+
return new Response(JSON.stringify(body), {
|
|
26
|
+
status,
|
|
27
|
+
headers: { 'content-type': 'application/json' },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function stubFetch(response: Response): ReturnType<typeof vi.fn> {
|
|
32
|
+
const fetchMock = vi.fn().mockResolvedValue(response);
|
|
33
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
34
|
+
return fetchMock;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
vi.unstubAllGlobals();
|
|
39
|
+
vi.restoreAllMocks();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('submitElicitationFields', () => {
|
|
43
|
+
it('POSTs to the SERVICE origin directly — not a host-relative path', async () => {
|
|
44
|
+
const fetchMock = stubFetch(
|
|
45
|
+
jsonResponse(201, { data: { submitted: true, ref: 'ref-1', connectionId: 'conn-9' } }),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
await submitElicitationFields({
|
|
49
|
+
submitUrl: SUBMIT_URL,
|
|
50
|
+
ref: 'ref-1',
|
|
51
|
+
accessToken: 'user-jwt',
|
|
52
|
+
fields: { apiKey: SECRET },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
56
|
+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
57
|
+
expect(url).toBe(SUBMIT_URL);
|
|
58
|
+
expect(new URL(url).origin).toBe(SERVICE_ORIGIN);
|
|
59
|
+
expect(init.method).toBe('POST');
|
|
60
|
+
// The SUBJECT's own bearer — not a service token, not the agent's.
|
|
61
|
+
expect((init.headers as Record<string, string>).Authorization).toBe('Bearer user-jwt');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('never hands a secret back to the caller, even when the service echoes it', async () => {
|
|
65
|
+
stubFetch(
|
|
66
|
+
jsonResponse(201, {
|
|
67
|
+
data: {
|
|
68
|
+
submitted: true,
|
|
69
|
+
ref: 'ref-1',
|
|
70
|
+
connectionId: 'conn-9',
|
|
71
|
+
// A hostile / careless service echoing the submission back.
|
|
72
|
+
fields: { apiKey: SECRET },
|
|
73
|
+
credentials: { apiKey: SECRET },
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const outcome = await submitElicitationFields({
|
|
79
|
+
submitUrl: SUBMIT_URL,
|
|
80
|
+
ref: 'ref-1',
|
|
81
|
+
accessToken: 'user-jwt',
|
|
82
|
+
fields: { apiKey: SECRET },
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// The outcome is a FRESH object with exactly three keys.
|
|
86
|
+
expect(Object.keys(outcome).sort()).toEqual(['connectionId', 'ref', 'submitted']);
|
|
87
|
+
expect(outcome).toEqual({ submitted: true, ref: 'ref-1', connectionId: 'conn-9' });
|
|
88
|
+
expect(JSON.stringify(outcome)).not.toContain(SECRET);
|
|
89
|
+
expect(JSON.stringify(outcome)).not.toContain('apiKey');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('round-trips a NON-secret field to the service body', async () => {
|
|
93
|
+
const fetchMock = stubFetch(
|
|
94
|
+
jsonResponse(201, { data: { submitted: true, ref: 'ref-1', connectionId: 'conn-9' } }),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
await submitElicitationFields({
|
|
98
|
+
submitUrl: SUBMIT_URL,
|
|
99
|
+
ref: 'ref-1',
|
|
100
|
+
accessToken: 'user-jwt',
|
|
101
|
+
fields: { baseUrl: 'https://acme.example.com', apiKey: SECRET },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
105
|
+
expect(JSON.parse(init.body as string)).toEqual({
|
|
106
|
+
fields: { baseUrl: 'https://acme.example.com', apiKey: SECRET },
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('accepts a flat (un-enveloped) response body', async () => {
|
|
111
|
+
stubFetch(jsonResponse(200, { submitted: true, ref: 'ref-1', connectionId: 'conn-2' }));
|
|
112
|
+
await expect(
|
|
113
|
+
submitElicitationFields({ submitUrl: SUBMIT_URL, ref: 'ref-1', accessToken: 't', fields: {} }),
|
|
114
|
+
).resolves.toEqual({ submitted: true, ref: 'ref-1', connectionId: 'conn-2' });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("surfaces the backend's empty-schema 400 as a usable message", async () => {
|
|
118
|
+
stubFetch(
|
|
119
|
+
jsonResponse(400, {
|
|
120
|
+
statusCode: 400,
|
|
121
|
+
message:
|
|
122
|
+
'No credential form is declared for a connection to "ACME" — there is nothing to validate ' +
|
|
123
|
+
'the submitted values against, so they cannot be stored.',
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
// An empty field schema submits an empty map; the SERVICE is the authority.
|
|
128
|
+
const promise = submitElicitationFields({
|
|
129
|
+
submitUrl: SUBMIT_URL,
|
|
130
|
+
ref: 'ref-1',
|
|
131
|
+
accessToken: 'user-jwt',
|
|
132
|
+
fields: {},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
await expect(promise).rejects.toBeInstanceOf(VistaFormSubmitError);
|
|
136
|
+
await expect(promise).rejects.toThrow(/No credential form is declared/);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('refuses a 2xx that does not report the elicitation as submitted', async () => {
|
|
140
|
+
stubFetch(jsonResponse(200, { data: { ref: 'ref-1' } }));
|
|
141
|
+
await expect(
|
|
142
|
+
submitElicitationFields({ submitUrl: SUBMIT_URL, ref: 'ref-1', accessToken: 't', fields: {} }),
|
|
143
|
+
).rejects.toThrow(/did not report the elicitation as submitted/);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe('readElicitationStatus', () => {
|
|
148
|
+
it('returns null while pending — an explicit "not yet", never a guess', async () => {
|
|
149
|
+
stubFetch(jsonResponse(200, { data: { ref: 'ref-1', status: 'pending', connectionId: null } }));
|
|
150
|
+
await expect(
|
|
151
|
+
readElicitationStatus({ statusUrl: STATUS_URL, ref: 'ref-1', accessToken: 't' }),
|
|
152
|
+
).resolves.toBeNull();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('settles on the service-reported submitted status', async () => {
|
|
156
|
+
stubFetch(
|
|
157
|
+
jsonResponse(200, { data: { ref: 'ref-1', status: 'submitted', connectionId: 'conn-3' } }),
|
|
158
|
+
);
|
|
159
|
+
await expect(
|
|
160
|
+
readElicitationStatus({ statusUrl: STATUS_URL, ref: 'ref-1', accessToken: 't' }),
|
|
161
|
+
).resolves.toEqual({ submitted: true, ref: 'ref-1', connectionId: 'conn-3' });
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('GETs the service origin with the subject bearer', async () => {
|
|
165
|
+
const fetchMock = stubFetch(jsonResponse(200, { data: { ref: 'ref-1', status: 'pending' } }));
|
|
166
|
+
await readElicitationStatus({ statusUrl: STATUS_URL, ref: 'ref-1', accessToken: 'user-jwt' });
|
|
167
|
+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
168
|
+
expect(new URL(url).origin).toBe(SERVICE_ORIGIN);
|
|
169
|
+
expect(init.method).toBe('GET');
|
|
170
|
+
expect((init.headers as Record<string, string>).Authorization).toBe('Bearer user-jwt');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('extractServiceMessage', () => {
|
|
175
|
+
it('reads a string message, a message array, and a nested error message', () => {
|
|
176
|
+
expect(extractServiceMessage({ message: 'nope' }, 400)).toBe('nope');
|
|
177
|
+
expect(extractServiceMessage({ message: ['a', 'b'] }, 400)).toBe('a b');
|
|
178
|
+
expect(extractServiceMessage({ error: { message: 'deep' } }, 400)).toBe('deep');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('never yields an empty string', () => {
|
|
182
|
+
expect(extractServiceMessage(null, 503)).toBe('The service rejected the submission (HTTP 503).');
|
|
183
|
+
expect(extractServiceMessage({ message: '' }, 500)).toBe(
|
|
184
|
+
'The service rejected the submission (HTTP 500).',
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// The `form` surface's transport — browser → owning service, direct.
|
|
3
|
+
//
|
|
4
|
+
// This module is the ONLY code that ever reads a captured field value out of
|
|
5
|
+
// the form surface, and it does exactly one thing with it: put it in the body
|
|
6
|
+
// of a `fetch` to the ABSOLUTE service URL carried by the (already validated)
|
|
7
|
+
// surface payload, bearing the SUBJECT's own JWT.
|
|
8
|
+
//
|
|
9
|
+
// Three properties make "the agent cannot receive the value" structural:
|
|
10
|
+
//
|
|
11
|
+
// • the value is a PARAMETER, never a return: every exported function returns
|
|
12
|
+
// `VistaFormOutcome | null`, a closed scalar-only shape (see
|
|
13
|
+
// `../vista-form-host`). The values object is not reachable from any
|
|
14
|
+
// return, any thrown error, or any callback;
|
|
15
|
+
// • the response is PROJECTED, not passed through: `toOutcome` constructs a
|
|
16
|
+
// fresh object with exactly three keys, so a service that echoed a secret
|
|
17
|
+
// back could still not leak one through this boundary;
|
|
18
|
+
// • the URL is absolute and comes from the payload validator, which rejects
|
|
19
|
+
// anything that is not `http(s)://…` — there is no host-relative path, so
|
|
20
|
+
// the request cannot be aimed at the app's own BFF or the chat transport.
|
|
21
|
+
//
|
|
22
|
+
// Errors carry the SERVICE's message verbatim (that is how the backend's hard
|
|
23
|
+
// 400 on an empty credential form becomes readable UI copy) and never the
|
|
24
|
+
// request body.
|
|
25
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
26
|
+
import type { VistaFormOutcome } from '../vista-form-host';
|
|
27
|
+
|
|
28
|
+
/** A non-2xx answer from the owning service, carrying its message verbatim. */
|
|
29
|
+
export class VistaFormSubmitError extends Error {
|
|
30
|
+
constructor(
|
|
31
|
+
readonly status: number,
|
|
32
|
+
message: string,
|
|
33
|
+
) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = 'VistaFormSubmitError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type UnknownRecord = Readonly<Record<string, unknown>>;
|
|
40
|
+
|
|
41
|
+
function asRecord(value: unknown): UnknownRecord | null {
|
|
42
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
43
|
+
? (value as UnknownRecord)
|
|
44
|
+
: null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Unwrap the platform `{ data: … }` envelope when present. Total: a flat body
|
|
49
|
+
* is returned as-is, so the transport works against either wire shape without
|
|
50
|
+
* a second code path.
|
|
51
|
+
*/
|
|
52
|
+
function unwrapEnvelope(body: unknown): UnknownRecord | null {
|
|
53
|
+
const record = asRecord(body);
|
|
54
|
+
if (record === null) return null;
|
|
55
|
+
const inner = asRecord(record.data);
|
|
56
|
+
return inner ?? record;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Best-effort extraction of the SERVICE's error message. Falls back to a
|
|
61
|
+
* status-derived sentence — never to an empty string, because an empty error is
|
|
62
|
+
* indistinguishable from success in the UI.
|
|
63
|
+
*/
|
|
64
|
+
export function extractServiceMessage(body: unknown, status: number): string {
|
|
65
|
+
const record = asRecord(body);
|
|
66
|
+
const candidate =
|
|
67
|
+
record === null
|
|
68
|
+
? undefined
|
|
69
|
+
: (record.message ?? asRecord(record.error)?.message ?? record.error);
|
|
70
|
+
if (typeof candidate === 'string' && candidate.length > 0) return candidate;
|
|
71
|
+
if (Array.isArray(candidate)) {
|
|
72
|
+
const joined = candidate.filter((m): m is string => typeof m === 'string').join(' ');
|
|
73
|
+
if (joined.length > 0) return joined;
|
|
74
|
+
}
|
|
75
|
+
if (typeof body === 'string' && body.length > 0) return body;
|
|
76
|
+
return `The service rejected the submission (HTTP ${status}).`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function readBody(response: Response): Promise<unknown> {
|
|
80
|
+
const contentType = response.headers.get('content-type');
|
|
81
|
+
try {
|
|
82
|
+
if (contentType !== null && contentType.includes('application/json')) {
|
|
83
|
+
return await response.json();
|
|
84
|
+
}
|
|
85
|
+
return await response.text();
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Project a service response onto {@link VistaFormOutcome}. Constructs a FRESH
|
|
93
|
+
* object with exactly three keys — nothing else from the response survives.
|
|
94
|
+
* Returns `null` when the service reports the elicitation is not settled.
|
|
95
|
+
*/
|
|
96
|
+
function toOutcome(body: unknown, ref: string): VistaFormOutcome | null {
|
|
97
|
+
const record = unwrapEnvelope(body);
|
|
98
|
+
if (record === null) return null;
|
|
99
|
+
const submitted =
|
|
100
|
+
record.submitted === true ||
|
|
101
|
+
(typeof record.status === 'string' && record.status === 'submitted');
|
|
102
|
+
if (!submitted) return null;
|
|
103
|
+
const connectionId =
|
|
104
|
+
typeof record.connectionId === 'string' && record.connectionId.length > 0
|
|
105
|
+
? record.connectionId
|
|
106
|
+
: null;
|
|
107
|
+
return { submitted: true, ref, connectionId };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The `Authorization`/`Content-Type` pair every request here carries. */
|
|
111
|
+
function authHeaders(accessToken: string, json: boolean): Record<string, string> {
|
|
112
|
+
const headers: Record<string, string> = {
|
|
113
|
+
Authorization: `Bearer ${accessToken}`,
|
|
114
|
+
Accept: 'application/json',
|
|
115
|
+
};
|
|
116
|
+
if (json) headers['Content-Type'] = 'application/json';
|
|
117
|
+
return headers;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* POST the captured fields to the owning service.
|
|
122
|
+
*
|
|
123
|
+
* @throws {VistaFormSubmitError} on a non-2xx answer, carrying the service's
|
|
124
|
+
* own message so a hard 400 (e.g. "no credential form is declared") is what the
|
|
125
|
+
* user reads.
|
|
126
|
+
*/
|
|
127
|
+
export async function submitElicitationFields(args: {
|
|
128
|
+
readonly submitUrl: string;
|
|
129
|
+
readonly ref: string;
|
|
130
|
+
readonly accessToken: string;
|
|
131
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
132
|
+
}): Promise<VistaFormOutcome> {
|
|
133
|
+
const response = await fetch(args.submitUrl, {
|
|
134
|
+
method: 'POST',
|
|
135
|
+
headers: authHeaders(args.accessToken, true),
|
|
136
|
+
body: JSON.stringify({ fields: args.fields }),
|
|
137
|
+
credentials: 'omit',
|
|
138
|
+
});
|
|
139
|
+
const body = await readBody(response);
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
throw new VistaFormSubmitError(response.status, extractServiceMessage(body, response.status));
|
|
142
|
+
}
|
|
143
|
+
const outcome = toOutcome(body, args.ref);
|
|
144
|
+
if (outcome === null) {
|
|
145
|
+
throw new VistaFormSubmitError(
|
|
146
|
+
response.status,
|
|
147
|
+
'The service accepted the request but did not report the elicitation as submitted.',
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return outcome;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Read the elicitation's current state. Used by the OAuth / app-install handoff,
|
|
155
|
+
* where completion happens in another window and the only signal available to
|
|
156
|
+
* this tab is the service's own record.
|
|
157
|
+
*
|
|
158
|
+
* Returns `null` while still pending — an explicit "not yet", never a guess.
|
|
159
|
+
*/
|
|
160
|
+
export async function readElicitationStatus(args: {
|
|
161
|
+
readonly statusUrl: string;
|
|
162
|
+
readonly ref: string;
|
|
163
|
+
readonly accessToken: string;
|
|
164
|
+
}): Promise<VistaFormOutcome | null> {
|
|
165
|
+
const response = await fetch(args.statusUrl, {
|
|
166
|
+
method: 'GET',
|
|
167
|
+
headers: authHeaders(args.accessToken, false),
|
|
168
|
+
credentials: 'omit',
|
|
169
|
+
});
|
|
170
|
+
const body = await readBody(response);
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
throw new VistaFormSubmitError(response.status, extractServiceMessage(body, response.status));
|
|
173
|
+
}
|
|
174
|
+
return toOutcome(body, args.ref);
|
|
175
|
+
}
|