@vvedantb/server 0.6.0 → 0.6.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/CHANGELOG.md +7 -0
- package/dist/artifacts/protocol.d.ts +4 -2
- package/dist/artifacts/protocol.js +19 -6
- package/docs/artifacts.md +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
Fix: the artifact guest bridge now connects in a browser iframe. No API change.
|
|
6
|
+
|
|
7
|
+
- The 0.6.0 guest sent `artifact:ready` only through a port it did not have yet, so the host never sent one. State requests went nowhere, and the built-in quiz and flashcards pages waited forever on `getAll()`. The guest now posts `artifact:ready` to `window.parent`, queues requests made before the port arrives, and sends them when it does. React Native WebViews are unchanged.
|
|
8
|
+
- Tests: the guest run in a VM realm with a parent window and no `ReactNativeWebView`: ready goes to the parent, a `getAll()` made before the port is sent once the port arrives, and its result resolves.
|
|
9
|
+
|
|
3
10
|
## 0.6.0
|
|
4
11
|
|
|
5
12
|
Additive: a pure artifacts core joins the root. Nothing in 0.5.0 changes. See `docs/artifacts.md`.
|
|
@@ -19,8 +19,10 @@ export declare const ARTIFACT_ALIASES_GLOBAL = "__ARTIFACT_ALIASES__";
|
|
|
19
19
|
* `window[alias].state` for each alias in `window.__ARTIFACT_ALIASES__`.
|
|
20
20
|
* Replaces `localStorage` and `sessionStorage` with shims over the same state
|
|
21
21
|
* (keys prefixed `ls:` and `ss:`). Writes over the state limits fail in the
|
|
22
|
-
* guest before they reach the host.
|
|
23
|
-
*
|
|
22
|
+
* guest before they reach the host. In an iframe it posts `artifact:ready` to
|
|
23
|
+
* the parent window, then talks over the MessagePort the host sends back and
|
|
24
|
+
* queues requests made before the port arrives. In a React Native WebView it
|
|
25
|
+
* uses `window.ReactNativeWebView.postMessage`.
|
|
24
26
|
*/
|
|
25
27
|
export declare const GUEST_BOOTSTRAP_SCRIPT: string;
|
|
26
28
|
export type ArtifactGuestOptions = {
|
|
@@ -20,8 +20,10 @@ export const ARTIFACT_ALIASES_GLOBAL = "__ARTIFACT_ALIASES__";
|
|
|
20
20
|
* `window[alias].state` for each alias in `window.__ARTIFACT_ALIASES__`.
|
|
21
21
|
* Replaces `localStorage` and `sessionStorage` with shims over the same state
|
|
22
22
|
* (keys prefixed `ls:` and `ss:`). Writes over the state limits fail in the
|
|
23
|
-
* guest before they reach the host.
|
|
24
|
-
*
|
|
23
|
+
* guest before they reach the host. In an iframe it posts `artifact:ready` to
|
|
24
|
+
* the parent window, then talks over the MessagePort the host sends back and
|
|
25
|
+
* queues requests made before the port arrives. In a React Native WebView it
|
|
26
|
+
* uses `window.ReactNativeWebView.postMessage`.
|
|
25
27
|
*/
|
|
26
28
|
export const GUEST_BOOTSTRAP_SCRIPT = `(function(){
|
|
27
29
|
var port=null;
|
|
@@ -53,12 +55,18 @@ export const GUEST_BOOTSTRAP_SCRIPT = `(function(){
|
|
|
53
55
|
}
|
|
54
56
|
return total<=${String(ARTIFACT_STATE_MAX_TOTAL_BYTES)};
|
|
55
57
|
}
|
|
58
|
+
var queued=[];
|
|
59
|
+
function nativeView(){
|
|
60
|
+
return window.ReactNativeWebView&&typeof window.ReactNativeWebView.postMessage==="function"?window.ReactNativeWebView:null;
|
|
61
|
+
}
|
|
56
62
|
function send(msg){
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
var native=nativeView();
|
|
64
|
+
if(native){
|
|
65
|
+
native.postMessage(JSON.stringify(msg));
|
|
59
66
|
return;
|
|
60
67
|
}
|
|
61
|
-
if(port){port.postMessage(msg);}
|
|
68
|
+
if(port){port.postMessage(msg);return;}
|
|
69
|
+
queued.push(msg);
|
|
62
70
|
}
|
|
63
71
|
function call(op,extra){
|
|
64
72
|
return new Promise(function(resolve,reject){
|
|
@@ -180,11 +188,16 @@ export const GUEST_BOOTSTRAP_SCRIPT = `(function(){
|
|
|
180
188
|
var msg=e.data;
|
|
181
189
|
if(msg&&msg.type==="${ARTIFACT_STATE_RESULT_TYPE}")handleResult(msg);
|
|
182
190
|
};
|
|
191
|
+
for(var q=0;q<queued.length;q++)port.postMessage(queued[q]);
|
|
192
|
+
queued=[];
|
|
183
193
|
return;
|
|
184
194
|
}
|
|
185
195
|
if(data.type==="${ARTIFACT_STATE_RESULT_TYPE}")handleResult(data);
|
|
186
196
|
});
|
|
187
|
-
|
|
197
|
+
var ready={type:"${ARTIFACT_READY_TYPE}"};
|
|
198
|
+
var native=nativeView();
|
|
199
|
+
if(native)native.postMessage(JSON.stringify(ready));
|
|
200
|
+
else if(window.parent&&window.parent!==window)window.parent.postMessage(ready,"*");
|
|
188
201
|
})();`;
|
|
189
202
|
const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
190
203
|
const RESERVED_ALIASES = new Set([
|
package/docs/artifacts.md
CHANGED
|
@@ -93,7 +93,7 @@ Download helpers: `ARTIFACT_FORMAT_FILES[format]` gives `{ extension, mime }`, a
|
|
|
93
93
|
|
|
94
94
|
## Bridge protocol
|
|
95
95
|
|
|
96
|
-
1. The guest bootstrap runs first. It reads `window.__ARTIFACT_SNAPSHOT__` and `window.__ARTIFACT_ALIASES__` (set by `artifactGuestScript`), deletes them, and posts `{ type: "artifact:ready" }` to the parent.
|
|
96
|
+
1. The guest bootstrap runs first. It reads `window.__ARTIFACT_SNAPSHOT__` and `window.__ARTIFACT_ALIASES__` (set by `artifactGuestScript`), deletes them, and posts `{ type: "artifact:ready" }` to the parent. Requests the page makes before the port arrives are queued and sent once it does.
|
|
97
97
|
2. The host checks `event.source` is its frame, creates a `MessageChannel`, and posts `{ type: "artifact:port" }` with `port2`.
|
|
98
98
|
3. The guest sends `{ type: "artifact:state", requestId, op, key?, value? }` on the port. The host parses it with `parseArtifactStateOp`, applies it with `applyArtifactStateOp`, schedules a save after `set`, `remove` or `reset`, and answers `{ type: "artifact:state-result", requestId, ok, value?, error? }`.
|
|
99
99
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared Convex backend helpers, MCP server scaffolding and Node-side MCP OAuth client helpers from one root import: query-limit errors, Clerk auth and token verification, Clerk-user lookups and ensure-user for Convex functions, bearer tokens, env, CORS, JSON responses, MCP route registration, a bearer-auth MCP HTTP handler, OAuth metadata, a JSON-RPC dispatcher, explorer tools, WebCrypto primitives, Convex optimistic-update helpers, MCP OAuth client helpers (provider, sign-in, refresh, revocation, loopback redirect server) for desktop apps, a QuickJS code sandbox that bridges script tool calls to host handlers, and a pure artifacts core (Zod contract, state limits and ops, quiz and flashcards pages, a sandboxed document wrapper with CSP and a guest state bridge).",
|
|
6
6
|
"type": "module",
|