@crossworks/share-ui 0.232.384 → 0.234.4
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/package.json +3 -3
- package/src/app-sandbox-confirm.test.ts +21 -0
- package/src/app-sandbox.tsx +98 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossworks/share-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.234.4",
|
|
4
4
|
"description": "The server-rendered share surface — the /s/<token> presenters, view-payload contract, mini-app sandbox, and the few primitives they need. Lives in MANTLE (the server renders these), published for jackdaw to consume; may depend only on @mantle/{client-types,content-core} (the jackdaw-repo-split boundary).",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./app-presenter": "./src/app-presenter.tsx",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@dicebear/core": "^10.7.0",
|
|
39
39
|
"@dicebear/styles": "^10.6.0",
|
|
40
40
|
"@firecms/neat": "1.0.2",
|
|
41
|
-
"@mantle/client-types": "npm:@crossworks/client-types@0.
|
|
42
|
-
"@mantle/content-core": "npm:@crossworks/content-core@0.
|
|
41
|
+
"@mantle/client-types": "npm:@crossworks/client-types@0.234.4",
|
|
42
|
+
"@mantle/content-core": "npm:@crossworks/content-core@0.234.4",
|
|
43
43
|
"@radix-ui/react-label": "^2.1.15",
|
|
44
44
|
"@radix-ui/react-slot": "^1.3.3",
|
|
45
45
|
"class-variance-authority": "^0.7.1",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser-dialog fallback for a tool confirmation never cuts the input in
|
|
3
|
+
* silence (apps audit 2026-10-02, low): it shows the start and the end and
|
|
4
|
+
* says how much is left out.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import { confirmInputText } from './app-sandbox';
|
|
8
|
+
|
|
9
|
+
describe('confirmInputText', () => {
|
|
10
|
+
it('shows a short input whole', () => {
|
|
11
|
+
expect(confirmInputText({ id: 'n1' })).toBe('{\n "id": "n1"\n}');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('shows the start and the end of a long one, and says what is left out', () => {
|
|
15
|
+
const text = confirmInputText({ body: `${'a'.repeat(3000)}TAIL` }, 100);
|
|
16
|
+
expect(text.startsWith('{\n "body": "aaa')).toBe(true);
|
|
17
|
+
expect(text).toContain('TAIL"\n}');
|
|
18
|
+
expect(text).toMatch(/characters not shown/);
|
|
19
|
+
expect(text).toMatch(/only its start and end are shown/);
|
|
20
|
+
});
|
|
21
|
+
});
|
package/src/app-sandbox.tsx
CHANGED
|
@@ -32,6 +32,46 @@ import {
|
|
|
32
32
|
|
|
33
33
|
type Status = 'loading' | 'ready' | 'nobuild' | 'error';
|
|
34
34
|
|
|
35
|
+
/** A tool call the owner must confirm before it runs (apps audit S1): what
|
|
36
|
+
* the owner tool broker named in its 409 `reason: 'confirm'` answer, and the
|
|
37
|
+
* input the app sent. */
|
|
38
|
+
export type AppToolConfirmRequest = {
|
|
39
|
+
appId: string;
|
|
40
|
+
slug: string;
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
input: Record<string, unknown>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The most input the browser's own dialog shows. */
|
|
47
|
+
const DEFAULT_CONFIRM_SHOWN = 1200;
|
|
48
|
+
|
|
49
|
+
/** A tool input as the browser's dialog shows it: whole when it fits, else
|
|
50
|
+
* its start and end and a line that says how much is left out. */
|
|
51
|
+
export function confirmInputText(input: unknown, max = DEFAULT_CONFIRM_SHOWN): string {
|
|
52
|
+
const full = JSON.stringify(input, null, 2) ?? 'null';
|
|
53
|
+
if (full.length <= max) return full;
|
|
54
|
+
const half = Math.floor(max / 2);
|
|
55
|
+
return `${full.slice(0, half)}\n… ${full.length - half * 2} characters not shown …\n${full.slice(-half)}\n\n(The input is ${full.length} characters; only its start and end are shown. Say no if you are not sure what it does.)`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Ask with the browser's own dialog when the host passes no `confirmTool`.
|
|
59
|
+
* Plain, but the app keeps working on a host that predates the prop. An
|
|
60
|
+
* input too long for the dialog is never cut in silence (apps audit
|
|
61
|
+
* 2026-10-02, low: the tail was hidden): the start and the end show, and
|
|
62
|
+
* the dialog says how much is left out. */
|
|
63
|
+
function defaultConfirmTool(req: AppToolConfirmRequest): Promise<boolean> {
|
|
64
|
+
if (typeof window === 'undefined' || typeof window.confirm !== 'function') {
|
|
65
|
+
return Promise.resolve(false);
|
|
66
|
+
}
|
|
67
|
+
const shown = confirmInputText(req.input);
|
|
68
|
+
return Promise.resolve(
|
|
69
|
+
window.confirm(
|
|
70
|
+
`This app wants to run "${req.name}" (${req.slug}).\n\n${req.description}\n\nWith:\n${shown}\n\nRun it?`,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
35
75
|
export function AppSandbox({
|
|
36
76
|
appId,
|
|
37
77
|
shareToken,
|
|
@@ -47,6 +87,7 @@ export function AppSandbox({
|
|
|
47
87
|
fetcher,
|
|
48
88
|
onLoadFailure,
|
|
49
89
|
loader,
|
|
90
|
+
confirmTool,
|
|
50
91
|
}: {
|
|
51
92
|
appId: string;
|
|
52
93
|
/** When set, render in share mode: the bundle + tool/db brokers are
|
|
@@ -101,6 +142,12 @@ export function AppSandbox({
|
|
|
101
142
|
* plain "Loading…" line. Kept a slot so this package needs no animation
|
|
102
143
|
* dependency. */
|
|
103
144
|
loader?: ReactNode;
|
|
145
|
+
/** Ask the owner whether a confirm-gated tool may run (apps audit S1);
|
|
146
|
+
* resolve true to run it. Only the owner surface ever gets asked (member,
|
|
147
|
+
* client and share brokers refuse such tools). Absent ⇒ the browser's
|
|
148
|
+
* own confirm dialog. The app never sees the ticket: this host sends the
|
|
149
|
+
* second call itself. */
|
|
150
|
+
confirmTool?: (req: AppToolConfirmRequest) => Promise<boolean>;
|
|
104
151
|
}) {
|
|
105
152
|
// Public share mode swaps the session-authed API base for the token-authed
|
|
106
153
|
// public one; the route suffixes (bundle / tool-broker / db-broker) match.
|
|
@@ -143,8 +190,10 @@ export function AppSandbox({
|
|
|
143
190
|
// re-ran the bundle-fetch effect below and reloaded the iframe (white flash).
|
|
144
191
|
// `fetcher` rides along for the same reason (the split hub passes an inline
|
|
145
192
|
// bearer-attaching wrapper); the default stays a plain window-bound fetch.
|
|
146
|
-
const cbRef = useRef({ onError, onSelect, onInspectChange, hub, onLoadFailure });
|
|
147
|
-
|
|
193
|
+
const cbRef = useRef({ onError, onSelect, onInspectChange, hub, onLoadFailure, confirmTool });
|
|
194
|
+
/** A tool confirmation is open (one at a time). */
|
|
195
|
+
const confirmOpenRef = useRef(false);
|
|
196
|
+
cbRef.current = { onError, onSelect, onInspectChange, hub, onLoadFailure, confirmTool };
|
|
148
197
|
const fetcherRef = useRef(fetcher);
|
|
149
198
|
fetcherRef.current = fetcher;
|
|
150
199
|
const doFetch = useCallback(
|
|
@@ -206,12 +255,52 @@ export function AppSandbox({
|
|
|
206
255
|
}
|
|
207
256
|
if (req.kind === 'tool.call') {
|
|
208
257
|
gateRef.current?.requestStart();
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
258
|
+
// The body is built here from the slug and input only: nothing the
|
|
259
|
+
// app sends can carry a confirmation ticket.
|
|
260
|
+
const send = (confirmToken?: string) =>
|
|
261
|
+
doFetch(`${apiBase}/tool-broker`, {
|
|
262
|
+
method: 'POST',
|
|
263
|
+
headers: { 'content-type': 'application/json' },
|
|
264
|
+
body: JSON.stringify({
|
|
265
|
+
slug: req.slug,
|
|
266
|
+
input: req.input,
|
|
267
|
+
...(confirmToken ? { confirmToken } : {}),
|
|
268
|
+
}),
|
|
269
|
+
});
|
|
270
|
+
let r = await send();
|
|
271
|
+
let data = await r.json();
|
|
272
|
+
if (r.status === 409 && data?.reason === 'confirm' && data.confirm?.token) {
|
|
273
|
+
// One question at a time (apps audit 2026-10-02, item 6): a
|
|
274
|
+
// second request while the owner reads the first is refused, so
|
|
275
|
+
// an app cannot swap what sits under the open Run button.
|
|
276
|
+
if (confirmOpenRef.current) {
|
|
277
|
+
reply({
|
|
278
|
+
ok: false,
|
|
279
|
+
error: `Another tool is waiting for your confirmation; “${req.slug}” was not run.`,
|
|
280
|
+
});
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const ask = cbRef.current.confirmTool ?? defaultConfirmTool;
|
|
284
|
+
confirmOpenRef.current = true;
|
|
285
|
+
let yes = false;
|
|
286
|
+
try {
|
|
287
|
+
yes = await ask({
|
|
288
|
+
appId,
|
|
289
|
+
slug: String(data.confirm.slug ?? req.slug),
|
|
290
|
+
name: String(data.confirm.name ?? req.slug),
|
|
291
|
+
description: String(data.confirm.description ?? ''),
|
|
292
|
+
input: (req.input ?? {}) as Record<string, unknown>,
|
|
293
|
+
});
|
|
294
|
+
} finally {
|
|
295
|
+
confirmOpenRef.current = false;
|
|
296
|
+
}
|
|
297
|
+
if (!yes) {
|
|
298
|
+
reply({ ok: false, error: `You declined to run the tool “${req.slug}”.` });
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
r = await send(String(data.confirm.token));
|
|
302
|
+
data = await r.json();
|
|
303
|
+
}
|
|
215
304
|
// 403 == the slug isn't in the app's declared tools. That's a wiring
|
|
216
305
|
// bug, not a transient failure — surface it plainly to the builder
|
|
217
306
|
// even if the app's own code swallows the rejection.
|
|
@@ -240,7 +329,7 @@ export function AppSandbox({
|
|
|
240
329
|
if (req.kind !== 'hub.get') gateRef.current?.requestEnd();
|
|
241
330
|
}
|
|
242
331
|
},
|
|
243
|
-
[apiBase, doFetch],
|
|
332
|
+
[apiBase, appId, doFetch],
|
|
244
333
|
);
|
|
245
334
|
|
|
246
335
|
// Listen for messages from THIS iframe only.
|