castle-web-cli 0.4.148 → 0.4.149
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/castle-host/host.js +55 -0
- package/dist/init.js +1 -1
- package/dist/serve.js +49 -23
- package/dist/serveSecurity.d.ts +2 -0
- package/dist/serveSecurity.js +17 -6
- package/dist/shell/assets/{index-CL9TuLXb.js → index-BzFzFtEP.js} +1 -1
- package/dist/shell/index.html +1 -1
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/editors/SceneEditor.jsx +150 -85
- package/kits/physics-3d/castle.json +1 -1
- package/kits/physics-3d/engine3d/PxModelEditor.jsx +29 -13
- package/kits/physics-3d/engine3d/Scene3DEditor.jsx +26 -7
- package/kits/physics-3d/engine3d/editorChrome.jsx +26 -1
- package/package.json +1 -1
- package/kits/blank/.castle/agent/children.json +0 -1
- package/kits/blank/.castle/agent/messages.json +0 -9
- package/kits/blank/.castle/agent/pending-sends.json +0 -1
- package/kits/blank/.castle/agent/tasks/index.md +0 -2
- package/kits/blank/.castle/docs/platform.md +0 -36
- package/kits/blank/node_modules/.vite/deps/_metadata.json +0 -8
- package/kits/blank/node_modules/.vite/deps/package.json +0 -3
package/dist/castle-host/host.js
CHANGED
|
@@ -30,6 +30,7 @@ const COMMAND_NAMES = [
|
|
|
30
30
|
"portal.open",
|
|
31
31
|
"portal.prefetch",
|
|
32
32
|
"haptics.play",
|
|
33
|
+
"multiplayer.getSession",
|
|
33
34
|
];
|
|
34
35
|
// Platform/capability commands: NOT serviced by graphqlFetch. They're dispatched
|
|
35
36
|
// to the host's optional platformHandler (mobile renders native UI; web shows an
|
|
@@ -110,6 +111,8 @@ function runCommand(ctx, command, params, caps) {
|
|
|
110
111
|
return timeGetServerTime(gql);
|
|
111
112
|
case "pass.has":
|
|
112
113
|
return passHas(ctx, params, caps);
|
|
114
|
+
case "multiplayer.getSession":
|
|
115
|
+
return multiplayerGetSession(ctx, params, caps);
|
|
113
116
|
// Platform commands are handled above; listed here to keep the switch
|
|
114
117
|
// exhaustive over CommandName.
|
|
115
118
|
case "pass.offer":
|
|
@@ -119,6 +122,33 @@ function runCommand(ctx, command, params, caps) {
|
|
|
119
122
|
return runPlatformCommand(ctx, command, params, caps);
|
|
120
123
|
}
|
|
121
124
|
}
|
|
125
|
+
async function multiplayerGetSession(ctx, params, caps) {
|
|
126
|
+
const mode = asMultiplayerMode(params.mode);
|
|
127
|
+
const request = {
|
|
128
|
+
mode,
|
|
129
|
+
key: mode === "named"
|
|
130
|
+
? asString(params.key, "key", "multiplayer.getSession")
|
|
131
|
+
: null,
|
|
132
|
+
};
|
|
133
|
+
if (caps.getMultiplayerSession) {
|
|
134
|
+
return caps.getMultiplayerSession(request, ctx);
|
|
135
|
+
}
|
|
136
|
+
const deckId = requireDeckId(ctx, "multiplayer.getSession");
|
|
137
|
+
const data = await graphql(caps.graphqlFetch, CAULDRON_MULTIPLAYER_SESSION_QUERY, { deckId, mode, key: request.key ?? null, partyId: ctx.partyId ?? null }, "multiplayer.getSession");
|
|
138
|
+
return multiplayerSessionResult(data.getCauldronMultiplayerSession);
|
|
139
|
+
}
|
|
140
|
+
function multiplayerSessionResult(value) {
|
|
141
|
+
const sessionId = asOptionalString(value?.sessionId);
|
|
142
|
+
if (value?.isSingleUserSession === true) {
|
|
143
|
+
return { status: "solo", url: null, nonce: null, sessionId };
|
|
144
|
+
}
|
|
145
|
+
const url = asOptionalString(value?.url);
|
|
146
|
+
const nonce = asOptionalString(value?.nonce);
|
|
147
|
+
if (!url || !nonce) {
|
|
148
|
+
return { status: "unavailable", url: null, nonce: null, sessionId };
|
|
149
|
+
}
|
|
150
|
+
return { status: "ok", url, nonce, sessionId };
|
|
151
|
+
}
|
|
122
152
|
// Dispatch a platform/capability command to the host's platformHandler. No
|
|
123
153
|
// handler → the command's normalized "unavailable" outcome (a SUCCESS, not an
|
|
124
154
|
// error: a deck on a host without this capability still gets one uniform
|
|
@@ -534,6 +564,11 @@ function asOptionalString(value) {
|
|
|
534
564
|
function asOptionalNumber(value) {
|
|
535
565
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
536
566
|
}
|
|
567
|
+
function asMultiplayerMode(value) {
|
|
568
|
+
if (value === "named" || value === "party" || value === "public")
|
|
569
|
+
return value;
|
|
570
|
+
throw new HostCommandError("INVALID_ARGUMENT", "Castle command multiplayer.getSession requires mode.", "multiplayer.getSession");
|
|
571
|
+
}
|
|
537
572
|
// GraphQL hands numeric fields back as numbers or as strings depending on the
|
|
538
573
|
// scalar, so leaderboard payload shaping accepts both.
|
|
539
574
|
function asNumberish(value) {
|
|
@@ -780,3 +815,23 @@ const SERVER_TIME_QUERY = `
|
|
|
780
815
|
}
|
|
781
816
|
}
|
|
782
817
|
`;
|
|
818
|
+
const CAULDRON_MULTIPLAYER_SESSION_QUERY = `
|
|
819
|
+
query CastleCauldronMultiplayerSession(
|
|
820
|
+
$deckId: ID!
|
|
821
|
+
$mode: String!
|
|
822
|
+
$key: String
|
|
823
|
+
$partyId: ID
|
|
824
|
+
) {
|
|
825
|
+
getCauldronMultiplayerSession(
|
|
826
|
+
deckId: $deckId
|
|
827
|
+
mode: $mode
|
|
828
|
+
key: $key
|
|
829
|
+
partyId: $partyId
|
|
830
|
+
) {
|
|
831
|
+
sessionId
|
|
832
|
+
isSingleUserSession
|
|
833
|
+
url
|
|
834
|
+
nonce
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
`;
|
package/dist/init.js
CHANGED
|
@@ -46,7 +46,7 @@ export const BARE_DOCS_KIT = 'blank';
|
|
|
46
46
|
// Registry version of castle-web-sdk to inject when scaffolding from a
|
|
47
47
|
// globally-installed castle-web (not from inside the workspace). Bumped
|
|
48
48
|
// alongside cli/sdk version bumps.
|
|
49
|
-
const PUBLISHED_SDK_VERSION = '0.4.
|
|
49
|
+
const PUBLISHED_SDK_VERSION = '0.4.19';
|
|
50
50
|
// The account the first-party kits are (to be) published under, so a kit
|
|
51
51
|
// imported from the CLI's copy is named the same as one fetched from the server.
|
|
52
52
|
const KIT_AUTHOR = 'castle';
|
package/dist/serve.js
CHANGED
|
@@ -17,7 +17,7 @@ import { FORKS_DIR, ownForkFile, splitImportRel } from './forks.js';
|
|
|
17
17
|
import * as config from './config.js';
|
|
18
18
|
import { graphql as castleGraphql } from './api.js';
|
|
19
19
|
import { executeCommand } from './castle-host/host.js';
|
|
20
|
-
import { ServeSecurity
|
|
20
|
+
import { ServeSecurity } from './serveSecurity.js';
|
|
21
21
|
import { isSameOriginUpgrade } from './wsOrigin.js';
|
|
22
22
|
// The log is a tail, not an archive: append, and once it passes the cap drop
|
|
23
23
|
// whole lines off the front until it is back under.
|
|
@@ -205,7 +205,7 @@ export function isAllowedShellHost(hostHeader, configuredHost) {
|
|
|
205
205
|
if (host.endsWith('.local') || host.endsWith('.ts.net'))
|
|
206
206
|
return true;
|
|
207
207
|
const configured = configuredHost ? hostnameFromHeader(configuredHost) : '';
|
|
208
|
-
return configured !== '' && configured !== '0.0.0.0' && configured !== '::' && host === configured;
|
|
208
|
+
return (configured !== '' && configured !== '0.0.0.0' && configured !== '::' && host === configured);
|
|
209
209
|
}
|
|
210
210
|
const EDIT_CONTENT_READ_ENDPOINTS = new Set([
|
|
211
211
|
'/__castle/files/raw',
|
|
@@ -243,6 +243,21 @@ window.__castleShellOrigin=(function(){
|
|
|
243
243
|
if(h.endsWith('.sandboxes.castlexyz.com'))return 'https://'+p+'-'+sid+'.sandboxes.castle.xyz';
|
|
244
244
|
return null;
|
|
245
245
|
})();
|
|
246
|
+
(function(){
|
|
247
|
+
var role=new URLSearchParams(location.search).get('edit')==='0'?'play':'edit';
|
|
248
|
+
var target=window.__castleShellOrigin||'*';
|
|
249
|
+
var announce=function(){
|
|
250
|
+
if(window.parent===window)return;
|
|
251
|
+
window.parent.postMessage({type:'castle-content-frame-ready',role:role},target);
|
|
252
|
+
};
|
|
253
|
+
window.addEventListener('message',function(event){
|
|
254
|
+
var d=event&&event.data;
|
|
255
|
+
if(event.source!==window.parent||!d||d.type!=='castle-request-content-frame-ready')return;
|
|
256
|
+
if(window.__castleShellOrigin&&event.origin!==window.__castleShellOrigin)return;
|
|
257
|
+
announce();
|
|
258
|
+
});
|
|
259
|
+
window.addEventListener('load',function(){setTimeout(announce,0);},{once:true});
|
|
260
|
+
})();
|
|
246
261
|
</script>\n ${CONSOLE_CAPTURE}`);
|
|
247
262
|
},
|
|
248
263
|
},
|
|
@@ -275,7 +290,9 @@ window.__castleShellOrigin=(function(){
|
|
|
275
290
|
res.end(JSON.stringify({ ticket: security.issueTicket(endpoint) }));
|
|
276
291
|
return;
|
|
277
292
|
}
|
|
278
|
-
if (reqPath === '/__castle/auth' ||
|
|
293
|
+
if (reqPath === '/__castle/auth' ||
|
|
294
|
+
reqPath === '/__castle/ws-port' ||
|
|
295
|
+
reqPath === '/__castle/context') {
|
|
279
296
|
res.writeHead(404).end();
|
|
280
297
|
return;
|
|
281
298
|
}
|
|
@@ -289,7 +306,8 @@ window.__castleShellOrigin=(function(){
|
|
|
289
306
|
res.writeHead(403).end('content capability does not allow this endpoint');
|
|
290
307
|
return;
|
|
291
308
|
}
|
|
292
|
-
if ((allowedFilesRequest || allowedVendor || allowedFavicon) &&
|
|
309
|
+
if ((allowedFilesRequest || allowedVendor || allowedFavicon) &&
|
|
310
|
+
ideServer.handleHttpRequest(req, res, reqPath))
|
|
293
311
|
return;
|
|
294
312
|
next();
|
|
295
313
|
return;
|
|
@@ -317,29 +335,32 @@ window.__castleShellOrigin=(function(){
|
|
|
317
335
|
},
|
|
318
336
|
};
|
|
319
337
|
}
|
|
320
|
-
// The
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
338
|
+
// The serve's own user, fetched once and cached for the serve lifetime so
|
|
339
|
+
// User.getCurrent works in dev. Config may carry only a token: a sandbox
|
|
340
|
+
// starts the serve with CASTLE_TOKEN alone and no config.json, so the userId
|
|
341
|
+
// has to come from `me` there too, not just the username.
|
|
342
|
+
let cachedDevMe;
|
|
343
|
+
async function devMe() {
|
|
344
|
+
if (cachedDevMe !== undefined)
|
|
345
|
+
return cachedDevMe;
|
|
326
346
|
try {
|
|
327
|
-
const res = await castleGraphql('query { me { username } }', {});
|
|
347
|
+
const res = await castleGraphql('query { me { userId username } }', {});
|
|
328
348
|
const me = res.data?.me;
|
|
329
|
-
|
|
349
|
+
cachedDevMe = { userId: me?.userId ?? null, username: me?.username ?? null };
|
|
330
350
|
}
|
|
331
351
|
catch {
|
|
332
|
-
|
|
352
|
+
cachedDevMe = { userId: null, username: null };
|
|
333
353
|
}
|
|
334
|
-
return
|
|
354
|
+
return cachedDevMe;
|
|
335
355
|
}
|
|
336
356
|
async function devHostContext(projectDir) {
|
|
337
357
|
const ctx = readDeckContext(projectDir);
|
|
358
|
+
const me = await devMe();
|
|
338
359
|
return {
|
|
339
360
|
deckId: ctx.deckId ?? null,
|
|
340
361
|
sessionId: null,
|
|
341
|
-
userId: config.getUserId(),
|
|
342
|
-
username:
|
|
362
|
+
userId: config.getUserId() ?? me.userId,
|
|
363
|
+
username: me.username,
|
|
343
364
|
};
|
|
344
365
|
}
|
|
345
366
|
async function handleCastleCommand(ws, projectDir, broadcast, requestId, command, params) {
|
|
@@ -618,7 +639,17 @@ export async function serve(dir, options = {}) {
|
|
|
618
639
|
fs: {
|
|
619
640
|
strict: true,
|
|
620
641
|
allow: [projectDir],
|
|
621
|
-
deny: [
|
|
642
|
+
deny: [
|
|
643
|
+
'.env',
|
|
644
|
+
'.env.*',
|
|
645
|
+
'*.pem',
|
|
646
|
+
'*.key',
|
|
647
|
+
'*.crt',
|
|
648
|
+
'.castle',
|
|
649
|
+
'.castle/**',
|
|
650
|
+
'.git',
|
|
651
|
+
'.git/**',
|
|
652
|
+
],
|
|
622
653
|
},
|
|
623
654
|
},
|
|
624
655
|
logLevel: 'info',
|
|
@@ -846,12 +877,7 @@ function startWSServer(port, projectDir, logFile, screenshotsDir, viteHolder, se
|
|
|
846
877
|
return;
|
|
847
878
|
bridgeRole = msg.role;
|
|
848
879
|
msg = msg.message;
|
|
849
|
-
const allowed = new Set([
|
|
850
|
-
'log',
|
|
851
|
-
'screenshot_response',
|
|
852
|
-
'write_file',
|
|
853
|
-
'castle_command',
|
|
854
|
-
]);
|
|
880
|
+
const allowed = new Set(['log', 'screenshot_response', 'write_file', 'castle_command']);
|
|
855
881
|
if (!allowed.has(String(msg.type)))
|
|
856
882
|
return;
|
|
857
883
|
}
|
package/dist/serveSecurity.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type * as http from 'http';
|
|
|
2
2
|
export type ContentRole = 'edit' | 'play';
|
|
3
3
|
export type SocketEndpoint = 'serve' | 'pty' | 'agent';
|
|
4
4
|
export type LocalContentPorts = Record<ContentRole, number>;
|
|
5
|
+
export declare const MOBILE_HOST_PROTOCOL = "2";
|
|
5
6
|
export declare function mintContentGrantLabel(grant: {
|
|
6
7
|
role: ContentRole;
|
|
7
8
|
publicPort: number;
|
|
@@ -33,5 +34,6 @@ export declare class ServeSecurity {
|
|
|
33
34
|
compatibilityContentRole(req: http.IncomingMessage): ContentRole | null;
|
|
34
35
|
shellOrigin(req: http.IncomingMessage): string;
|
|
35
36
|
private mintContentLabel;
|
|
37
|
+
private requestsIsolatedContentOrigins;
|
|
36
38
|
private contentMac;
|
|
37
39
|
}
|
package/dist/serveSecurity.js
CHANGED
|
@@ -3,6 +3,7 @@ const CROCKFORD = '0123456789abcdefghjkmnpqrstvwxyz';
|
|
|
3
3
|
const CONTENT_LABEL_RE = /^1([ep])([0-9a-z]{1,4})-([a-z0-9]{14})-([0-9a-z]{1,8})-([0-9a-hjkmnp-tv-z]{13})-([0-9a-hjkmnp-tv-z]{20})$/;
|
|
4
4
|
const MAX_GRANT_SECONDS = 12 * 60 * 60;
|
|
5
5
|
const GRANT_CLOCK_SKEW_SECONDS = 60;
|
|
6
|
+
export const MOBILE_HOST_PROTOCOL = '2';
|
|
6
7
|
function base32Lower(bytes) {
|
|
7
8
|
let bits = 0;
|
|
8
9
|
let value = 0;
|
|
@@ -135,12 +136,11 @@ window.fetch=function(input,init){
|
|
|
135
136
|
contentOrigins(req) {
|
|
136
137
|
const host = hostWithoutPort(req.headers.host || 'localhost');
|
|
137
138
|
const cloud = host.match(/^\d+-([a-z0-9]{14})\.(sandboxes(?:-staging)?\.castle\.xyz)$/);
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
if (cloud && process.env.CASTLE_ISOLATED_CONTENT_ORIGINS !== '1') {
|
|
139
|
+
// Released clients that predate protocol 2 reject the separate registrable
|
|
140
|
+
// content domain at the native WebView layer. Missing and unknown protocol
|
|
141
|
+
// values therefore stay on the compatibility origin forever; only an
|
|
142
|
+
// explicit client capability (or the staging override) opts into isolation.
|
|
143
|
+
if (cloud && !this.requestsIsolatedContentOrigins(req)) {
|
|
144
144
|
const origin = requestOrigin(req);
|
|
145
145
|
return { editOrigin: origin, playOrigin: origin };
|
|
146
146
|
}
|
|
@@ -254,6 +254,17 @@ window.fetch=function(input,init){
|
|
|
254
254
|
serveNonce: this.serveNonce,
|
|
255
255
|
}, this.signingKey);
|
|
256
256
|
}
|
|
257
|
+
requestsIsolatedContentOrigins(req) {
|
|
258
|
+
if (process.env.CASTLE_ISOLATED_CONTENT_ORIGINS === '1')
|
|
259
|
+
return true;
|
|
260
|
+
try {
|
|
261
|
+
return (new URL(req.url || '/', requestOrigin(req)).searchParams.get('mobileHostProtocol') ===
|
|
262
|
+
MOBILE_HOST_PROTOCOL);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
257
268
|
contentMac(role, publicPort, sandboxId, expiresAtSeconds, serveNonce) {
|
|
258
269
|
return mintContentGrantLabel({ role, publicPort, sandboxId, expiresAtSeconds, serveNonce }, this.signingKey)
|
|
259
270
|
.split('-')
|