@base44-preview/cli 0.3.3-pr.700.881d5e4 → 0.3.3-pr.700.d3249f9
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/cli/index.js +71 -30
- package/dist/cli/index.js.map +4 -4
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -256508,6 +256508,14 @@ var TickLoop = class {
|
|
|
256508
256508
|
};
|
|
256509
256509
|
|
|
256510
256510
|
// src/shim/actor.ts
|
|
256511
|
+
var ActorError = class extends Error {
|
|
256512
|
+
constructor(status, message) {
|
|
256513
|
+
super(message);
|
|
256514
|
+
this.status = status;
|
|
256515
|
+
this.name = "ActorError";
|
|
256516
|
+
}
|
|
256517
|
+
status;
|
|
256518
|
+
};
|
|
256511
256519
|
var SUPERSEDED_PREFIX = "__superseded__:";
|
|
256512
256520
|
function buildConn(ws, identity) {
|
|
256513
256521
|
return {
|
|
@@ -256842,40 +256850,59 @@ var Actor = class _Actor extends Server {
|
|
|
256842
256850
|
}
|
|
256843
256851
|
handleWake(_key) {
|
|
256844
256852
|
}
|
|
256845
|
-
|
|
256853
|
+
/** Methods a caller may run on this room, as \`base44.actors.<Name>(room).<method>(args)\`.
|
|
256854
|
+
* Nothing else is callable. Each is called as \`method(args, { identity, request })\`;
|
|
256855
|
+
* check \`identity\` before acting: a client can call any room it can name. */
|
|
256856
|
+
static callable;
|
|
256857
|
+
static NOT_CALLABLE = /^(?:handle[A-Z]|on[A-Z]|_)|^(?:constructor|fetch|alarm|setName|broadcast|schedule|cancelSchedule|getConnections|webSocket[A-Z].*)$/;
|
|
256858
|
+
static CALLER_AUTHORIZATION_HEADER = "X-Base44-Actor-Caller-Authorization";
|
|
256859
|
+
static parseCallIdentity(value) {
|
|
256846
256860
|
if (value === '{"type":"service"}') return Object.freeze({ type: "service" });
|
|
256847
256861
|
return _Actor.parseIdentity(value);
|
|
256848
256862
|
}
|
|
256849
256863
|
// Called by the generated wrapper for a verified POST .../requests; never user-facing.
|
|
256850
|
-
async
|
|
256864
|
+
async _b44ActorCall(request) {
|
|
256851
256865
|
const room = request.headers.get("x-partykit-room");
|
|
256852
256866
|
if (room) await this.setName(room);
|
|
256853
|
-
|
|
256854
|
-
return new Response("This actor does not accept requests", { status: 404 });
|
|
256855
|
-
}
|
|
256856
|
-
const identity = _Actor.parseRequestIdentity(request.headers.get(_Actor.IDENTITY_HEADER));
|
|
256867
|
+
const identity = _Actor.parseCallIdentity(request.headers.get(_Actor.IDENTITY_HEADER));
|
|
256857
256868
|
if (!identity) return new Response("Unauthorized", { status: 401 });
|
|
256858
|
-
|
|
256859
|
-
|
|
256860
|
-
|
|
256861
|
-
|
|
256862
|
-
|
|
256863
|
-
|
|
256864
|
-
|
|
256869
|
+
let call;
|
|
256870
|
+
try {
|
|
256871
|
+
call = JSON.parse(await request.text());
|
|
256872
|
+
} catch {
|
|
256873
|
+
return Response.json({ message: "Invalid call" }, { status: 400 });
|
|
256874
|
+
}
|
|
256875
|
+
const name = call?.method;
|
|
256876
|
+
const callable = this.constructor.callable;
|
|
256877
|
+
if (typeof name !== "string" || !Array.isArray(callable) || !callable.includes(name) || _Actor.NOT_CALLABLE.test(name) || typeof this[name] !== "function") {
|
|
256878
|
+
return Response.json({ message: \`No callable method "\${String(name)}"\` }, { status: 404 });
|
|
256879
|
+
}
|
|
256880
|
+
const headers = new Headers({
|
|
256881
|
+
"Content-Type": "application/json",
|
|
256882
|
+
"Base44-App-Id": String(this._b44Env.BASE44_APP_ID ?? ""),
|
|
256883
|
+
"Base44-Api-Url": String(this._b44Env.BASE44_API_URL ?? ""),
|
|
256884
|
+
"Base44-Functions-Version": String(this._b44Env.BASE44_FUNCTIONS_VERSION ?? "")
|
|
256885
|
+
});
|
|
256886
|
+
const callerAuthorization = request.headers.get(_Actor.CALLER_AUTHORIZATION_HEADER);
|
|
256887
|
+
if (callerAuthorization) headers.set("Authorization", callerAuthorization);
|
|
256888
|
+
const forMethod = new Request(
|
|
256889
|
+
\`https://actor.base44/rooms/\${encodeURIComponent(this.name)}/methods/\${encodeURIComponent(name)}\`,
|
|
256890
|
+
{ method: "POST", headers, body: JSON.stringify(call.args ?? null) }
|
|
256865
256891
|
);
|
|
256866
256892
|
let response;
|
|
256867
256893
|
try {
|
|
256868
|
-
|
|
256894
|
+
const result = await this[name](call.args, { identity, request: forMethod });
|
|
256895
|
+
response = result === void 0 ? new Response(null, { status: 204 }) : Response.json(result);
|
|
256869
256896
|
} catch (err) {
|
|
256870
|
-
|
|
256871
|
-
|
|
256897
|
+
const status = err?.status;
|
|
256898
|
+
if (typeof status === "number" && status >= 400 && status < 500) {
|
|
256899
|
+
response = Response.json({ message: err.message }, { status });
|
|
256900
|
+
} else {
|
|
256901
|
+
console.error(\`Actor.\${name} threw:\`, err);
|
|
256902
|
+
response = Response.json({ message: "Actor method failed" }, { status: 500 });
|
|
256903
|
+
}
|
|
256872
256904
|
}
|
|
256873
256905
|
await this.maintainTicker();
|
|
256874
|
-
if (response === void 0) return new Response(null, { status: 204 });
|
|
256875
|
-
if (!(response instanceof Response)) {
|
|
256876
|
-
console.error("Actor.handleRequest must return a Response or nothing");
|
|
256877
|
-
return new Response("Actor request failed", { status: 500 });
|
|
256878
|
-
}
|
|
256879
256906
|
return response;
|
|
256880
256907
|
}
|
|
256881
256908
|
async schedule(key, at) {
|
|
@@ -257027,6 +257054,7 @@ var Actor = class _Actor extends Server {
|
|
|
257027
257054
|
};
|
|
257028
257055
|
export {
|
|
257029
257056
|
Actor,
|
|
257057
|
+
ActorError,
|
|
257030
257058
|
routePartykitRequest
|
|
257031
257059
|
};
|
|
257032
257060
|
`,
|
|
@@ -259118,6 +259146,7 @@ function buildActorAuth() {
|
|
|
259118
259146
|
const TOKEN_HEADER = "X-Base44-Actor-Token";
|
|
259119
259147
|
const IDENTITY_HEADER = "X-Base44-Actor-Identity";
|
|
259120
259148
|
const REQUEST_TOKEN_HEADER = "X-Base44-Actor-Request-Token";
|
|
259149
|
+
const CALLER_AUTHORIZATION_HEADER = "X-Base44-Actor-Caller-Authorization";
|
|
259121
259150
|
const CLOCK_SKEW_SECONDS = 30;
|
|
259122
259151
|
const TOKEN_TTL_SECONDS = 300;
|
|
259123
259152
|
const REQUEST_TOKEN_TTL_SECONDS = 60;
|
|
@@ -259240,11 +259269,12 @@ const sha256 = async (bytes) => {
|
|
|
259240
259269
|
return btoa(String.fromCharCode(...digest)).replace(/\\+/g, "-").replace(/\\//g, "_").replace(/=+$/, "");
|
|
259241
259270
|
};
|
|
259242
259271
|
|
|
259243
|
-
// A
|
|
259272
|
+
// A method call the backend relays into one room for a caller it authenticated. Same
|
|
259244
259273
|
// key as connection tokens, its own audience and purpose: neither is accepted as
|
|
259245
|
-
// the other. The token is bound to the body
|
|
259246
|
-
//
|
|
259247
|
-
//
|
|
259274
|
+
// the other. The token is bound to the body and to the caller's forwarded
|
|
259275
|
+
// credential, so a leaked token can carry neither another call nor another caller.
|
|
259276
|
+
// 401 is a token this key did not mint, that has lapsed or whose hashes don't match;
|
|
259277
|
+
// 403 is a good token for another app, actor, script, room or runtime.
|
|
259248
259278
|
export async function verifyActorRequest(request, env, actorName, room) {
|
|
259249
259279
|
const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
|
|
259250
259280
|
const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
|
|
@@ -259264,6 +259294,7 @@ export async function verifyActorRequest(request, env, actorName, room) {
|
|
|
259264
259294
|
typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
|
|
259265
259295
|
!validTimes(claims, now, REQUEST_TOKEN_TTL_SECONDS) ||
|
|
259266
259296
|
typeof claims.body_sha256 !== "string" ||
|
|
259297
|
+
!(claims.caller_token_sha256 === null || typeof claims.caller_token_sha256 === "string") ||
|
|
259267
259298
|
!validRequestPrincipal(claims.principal)
|
|
259268
259299
|
) return unauthorized();
|
|
259269
259300
|
if (
|
|
@@ -259277,11 +259308,19 @@ export async function verifyActorRequest(request, env, actorName, room) {
|
|
|
259277
259308
|
const body = new Uint8Array(await request.arrayBuffer());
|
|
259278
259309
|
if (body.length > REQUEST_MAX_BYTES) return refused(413, "Request too large");
|
|
259279
259310
|
if (await sha256(body) !== claims.body_sha256) return unauthorized();
|
|
259311
|
+
const callerAuthorization = request.headers.get(CALLER_AUTHORIZATION_HEADER);
|
|
259312
|
+
if (callerAuthorization === null) {
|
|
259313
|
+
if (claims.caller_token_sha256 !== null) return unauthorized();
|
|
259314
|
+
} else if (
|
|
259315
|
+
callerAuthorization.length > 8192 ||
|
|
259316
|
+
await sha256(new TextEncoder().encode(callerAuthorization)) !== claims.caller_token_sha256
|
|
259317
|
+
) return unauthorized();
|
|
259280
259318
|
return {
|
|
259281
259319
|
ok: true,
|
|
259282
259320
|
identity: Object.freeze({ ...claims.principal }),
|
|
259283
259321
|
runtimeMode: claims.runtime_mode,
|
|
259284
259322
|
body,
|
|
259323
|
+
callerAuthorization,
|
|
259285
259324
|
};
|
|
259286
259325
|
} catch {
|
|
259287
259326
|
return unauthorized();
|
|
@@ -259290,7 +259329,8 @@ export async function verifyActorRequest(request, env, actorName, room) {
|
|
|
259290
259329
|
|
|
259291
259330
|
// Into the room as POST /parties/<actor>/<room>/requests: a path no client route
|
|
259292
259331
|
// forwards (the legacy route is exactly four segments, the direct route rewrites
|
|
259293
|
-
// the path), so the Durable Object can trust the shape and its identity
|
|
259332
|
+
// the path), so the Durable Object can trust the shape and its identity and caller
|
|
259333
|
+
// headers.
|
|
259294
259334
|
export function actorRequestToRoom(request, actorName, room, verified) {
|
|
259295
259335
|
const url = new URL(request.url);
|
|
259296
259336
|
url.search = "";
|
|
@@ -259301,6 +259341,7 @@ export function actorRequestToRoom(request, actorName, room, verified) {
|
|
|
259301
259341
|
"Content-Type": request.headers.get("Content-Type") ?? "application/json",
|
|
259302
259342
|
[IDENTITY_HEADER]: JSON.stringify(verified.identity),
|
|
259303
259343
|
"base44-functions-version": verified.runtimeMode,
|
|
259344
|
+
...(verified.callerAuthorization === null ? {} : { [CALLER_AUTHORIZATION_HEADER]: verified.callerAuthorization }),
|
|
259304
259345
|
},
|
|
259305
259346
|
body: verified.body,
|
|
259306
259347
|
});
|
|
@@ -259377,10 +259418,10 @@ export class ${doClassName} extends Base44UserActor {
|
|
|
259377
259418
|
}
|
|
259378
259419
|
|
|
259379
259420
|
fetch(request) {
|
|
259380
|
-
// Ahead of the user's own fetch override: a relayed
|
|
259381
|
-
//
|
|
259421
|
+
// Ahead of the user's own fetch override: a relayed call reaches the room only
|
|
259422
|
+
// through the shim, which runs a callable method with the verified identity.
|
|
259382
259423
|
if (_b44IsActorRequest(request)) {
|
|
259383
|
-
return _b44RunActor(this, request, () => this.
|
|
259424
|
+
return _b44RunActor(this, request, () => this._b44ActorCall(request));
|
|
259384
259425
|
}
|
|
259385
259426
|
return _b44RunActor(this, request, () => super.fetch(request));
|
|
259386
259427
|
}
|
|
@@ -275266,4 +275307,4 @@ export {
|
|
|
275266
275307
|
runCLI
|
|
275267
275308
|
};
|
|
275268
275309
|
|
|
275269
|
-
//# debugId=
|
|
275310
|
+
//# debugId=94AB1C17F7B06B9364756E2164756E21
|