@crossworks/share-ui 0.232.380 → 0.232.384

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossworks/share-ui",
3
- "version": "0.232.380",
3
+ "version": "0.232.384",
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.232.380",
42
- "@mantle/content-core": "npm:@crossworks/content-core@0.232.380",
41
+ "@mantle/client-types": "npm:@crossworks/client-types@0.232.384",
42
+ "@mantle/content-core": "npm:@crossworks/content-core@0.232.384",
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",
@@ -15,6 +15,12 @@
15
15
 
16
16
  export const BRIDGE_VERSION = 1 as const;
17
17
 
18
+ /** What `host.me()` answers inside an app (app identity, 2026-10-02). It is
19
+ * NOT a bridge message: the frame route bakes it into the frame document
20
+ * from its verified ticket, so hosts need no change to support it. Exported
21
+ * here so the app-facing contract lives in one place. */
22
+ export type { AppViewer, AppViewerKind } from '@mantle/client-types/app-viewer';
23
+
18
24
  /** Requests the app sends UP to the host (await a matching BridgeRes by `id`). */
19
25
  export type BridgeReq =
20
26
  | { v: 1; id: string; kind: 'tool.call'; slug: string; input: unknown }
@@ -6,7 +6,7 @@
6
6
  * exactly what a wrong `@host` import cost in the field.
7
7
  */
8
8
  import { describe, expect, it } from 'vitest';
9
- import { buildAppFrameHtml } from './app-frame-html';
9
+ import { buildAppFrameHtml, viewerScript } from './app-frame-html';
10
10
 
11
11
  const frame = (bundleCode: string) =>
12
12
  buildAppFrameHtml({
@@ -105,3 +105,60 @@ describe('buildAppFrameHtml — the Neat backdrop', () => {
105
105
  expect(frame('console.log(1)')).not.toContain('--card-on-neat');
106
106
  });
107
107
  });
108
+
109
+ describe('buildAppFrameHtml: host.me() (app identity)', () => {
110
+ const withViewer = (viewer: Parameters<typeof viewerScript>[0]) =>
111
+ buildAppFrameHtml({
112
+ bundleCode: 'console.log(1)',
113
+ appCss: '',
114
+ importMapJson: '{"imports":{}}',
115
+ cls: '',
116
+ colorTheme: null,
117
+ viewport: true,
118
+ viewer,
119
+ });
120
+
121
+ it('bakes the viewer in BEFORE the app module, read-only', () => {
122
+ const html = withViewer({ id: 'u_abc', name: 'Pat', kind: 'member' });
123
+ const at = html.indexOf('__mantleHostMe');
124
+ expect(at).toBeGreaterThan(-1);
125
+ expect(at).toBeLessThan(html.indexOf('<script type="module">'));
126
+ expect(html).toContain('Object.freeze({"id":"u_abc","name":"Pat","kind":"member"})');
127
+ });
128
+
129
+ it('bakes nothing without a viewer (host.me() then rejects)', () => {
130
+ expect(withViewer(null)).not.toContain('__mantleHostMe');
131
+ expect(frame('x')).not.toContain('__mantleHostMe');
132
+ });
133
+
134
+ it('a display name cannot close the script tag', () => {
135
+ const html = withViewer({
136
+ id: 'u_x',
137
+ name: '</script><script>alert(1)</script>\u2028',
138
+ kind: 'client',
139
+ });
140
+ const script = viewerScript({ id: 'u_x', name: '</script>', kind: 'client' });
141
+ expect(script).not.toContain('</script><');
142
+ expect(script).toContain('\\u003c/script>');
143
+ expect(html.match(/<\/script>/g)?.length).toBe(
144
+ withViewer({ id: 'u', name: 'n', kind: 'client' }).match(/<\/script>/g)?.length,
145
+ );
146
+ });
147
+
148
+ it('carries only id, name and kind, whatever else the object holds', () => {
149
+ const script = viewerScript({
150
+ id: 'u_x',
151
+ name: 'Pat',
152
+ kind: 'member',
153
+ email: 'pat@example.invalid',
154
+ } as never);
155
+ expect(script).not.toContain('email');
156
+ expect(script).not.toContain('example.invalid');
157
+ });
158
+
159
+ it('an open link bakes the anonymous viewer', () => {
160
+ expect(viewerScript({ id: null, name: null, kind: 'public' })).toContain(
161
+ '{"id":null,"name":null,"kind":"public"}',
162
+ );
163
+ });
164
+ });
@@ -14,6 +14,8 @@
14
14
  * server-side.
15
15
  */
16
16
 
17
+ import type { AppViewer } from '@mantle/client-types/app-viewer';
18
+
17
19
  /** The strict sandbox CSP, served as a Content-Security-Policy HEADER on the
18
20
  * frame response. The app may only render — NO network of its own.
19
21
  * `connect-src 'none'` blocks fetch/XHR/WebSocket, and img/font loads are
@@ -174,6 +176,29 @@ const ERROR_REPORTER = `(function(){
174
176
  });
175
177
  })();`;
176
178
 
179
+ /**
180
+ * host.me() (app identity): who runs the app, resolved by the frame route
181
+ * from its verified ticket and baked in BEFORE the app module, where the
182
+ * `@host` kit reads it. Read-only so the app cannot overwrite it by
183
+ * accident; the app could still lie to itself, which is why it is for
184
+ * display only and the SQL `:host_me_*` values are filled by the broker.
185
+ * JSON in a script: `<` and the two JS line separators are escaped, so a
186
+ * display name cannot close the tag.
187
+ */
188
+ export function viewerScript(viewer: AppViewer | null | undefined): string {
189
+ if (!viewer) return '';
190
+ const safe = {
191
+ id: typeof viewer.id === 'string' ? viewer.id : null,
192
+ name: typeof viewer.name === 'string' ? viewer.name : null,
193
+ kind: viewer.kind,
194
+ };
195
+ const json = JSON.stringify(safe)
196
+ .replace(/</g, '\\u003c')
197
+ .replace(/\u2028/g, '\\u2028')
198
+ .replace(/\u2029/g, '\\u2029');
199
+ return `<script>Object.defineProperty(window,'__mantleHostMe',{value:Object.freeze(${json})});</script>\n`;
200
+ }
201
+
177
202
  export function buildAppFrameHtml(opts: {
178
203
  /** The app's built module bundle (esbuild output; esbuild escapes any
179
204
  * `</script` inside string literals, so inlining it is safe). */
@@ -196,6 +221,9 @@ export function buildAppFrameHtml(opts: {
196
221
  /** Neat licence key for watermark removal — same env-sourced value the
197
222
  * other surfaces ride. */
198
223
  neatLicense?: string | null;
224
+ /** Who runs the app (host.me()); null/absent bakes nothing and host.me()
225
+ * rejects. Never email: the type has no such field. */
226
+ viewer?: AppViewer | null;
199
227
  }): string {
200
228
  const colorThemeAttr = opts.colorTheme ? ` data-color-theme="${attr(opts.colorTheme)}"` : '';
201
229
  return `<!doctype html>
@@ -286,7 +314,7 @@ ${
286
314
  : ''
287
315
  }<div id="root"></div>
288
316
  <script>${ERROR_REPORTER}</script>
289
- <script type="module">${opts.bundleCode}</script>
317
+ ${viewerScript(opts.viewer)}<script type="module">${opts.bundleCode}</script>
290
318
  <script>${INSPECTOR}</script>
291
319
  ${opts.neatSpec ? `<script type="module" src="/share-runtime/share-page.js"></script>\n` : ''}</body>
292
320
  </html>`;