@base44-preview/cli 0.3.1-pr.694.b9f40b5 → 0.3.1-pr.696.7cd2a53
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/assets/backend-runtime/exec.ts +1 -1
- package/dist/cli/index.js +167 -36
- package/dist/cli/index.js.map +5 -5
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - SCRIPT_PATH: Absolute path (or file:// URL) to the user's script
|
|
9
9
|
* - BASE44_APP_ID: App identifier from .app.jsonc
|
|
10
10
|
* - BASE44_ACCESS_TOKEN: User's access token
|
|
11
|
-
* - BASE44_APP_BASE_URL: App's published URL
|
|
11
|
+
* - BASE44_APP_BASE_URL: App's published URL, or its preview URL before the first publish (function calls need an app host)
|
|
12
12
|
* - BASE44_PRIVILEGED: When "true", adds the X-Bypass-RLS header (bypass RLS)
|
|
13
13
|
* - BASE44_DATA_ENV: When set, adds the X-Data-Env header (target data environment)
|
|
14
14
|
* - BASE44_SERVICE_TOKEN: When set, passed as `serviceToken` (enables `base44.asServiceRole`)
|
package/dist/cli/index.js
CHANGED
|
@@ -256813,6 +256813,24 @@ var Actor = class _Actor extends Server {
|
|
|
256813
256813
|
}
|
|
256814
256814
|
handleWake(_key) {
|
|
256815
256815
|
}
|
|
256816
|
+
// Optional: the platform posted an event into this room. Delivery is
|
|
256817
|
+
// at-least-once; a repeat of an event_id this instance already took is dropped
|
|
256818
|
+
// here, so a room that must be exact across evictions dedups on event_id too.
|
|
256819
|
+
handlePlatformEvent(_event) {
|
|
256820
|
+
}
|
|
256821
|
+
takenPlatformEvents = [];
|
|
256822
|
+
static REMEMBERED_PLATFORM_EVENTS = 64;
|
|
256823
|
+
// Called by the generated wrapper for a verified POST .../events; never user-facing.
|
|
256824
|
+
async _b44PlatformEvent(request) {
|
|
256825
|
+
const event = await request.json();
|
|
256826
|
+
if (!this.takenPlatformEvents.includes(event.event_id)) {
|
|
256827
|
+
await this.handlePlatformEvent(event);
|
|
256828
|
+
this.takenPlatformEvents.push(event.event_id);
|
|
256829
|
+
if (this.takenPlatformEvents.length > _Actor.REMEMBERED_PLATFORM_EVENTS) this.takenPlatformEvents.shift();
|
|
256830
|
+
await this.maintainTicker();
|
|
256831
|
+
}
|
|
256832
|
+
return new Response(null, { status: 204 });
|
|
256833
|
+
}
|
|
256816
256834
|
async schedule(key, at) {
|
|
256817
256835
|
const when = typeof at === "number" ? at : at.getTime();
|
|
256818
256836
|
await this.mutateSchedules((m) => {
|
|
@@ -259052,8 +259070,12 @@ function buildActorAuth() {
|
|
|
259052
259070
|
return `// Auto-generated by the base44 bundler. Do not edit.
|
|
259053
259071
|
const TOKEN_HEADER = "X-Base44-Actor-Token";
|
|
259054
259072
|
const IDENTITY_HEADER = "X-Base44-Actor-Identity";
|
|
259073
|
+
const EVENT_TOKEN_HEADER = "X-Base44-Actor-Event-Token";
|
|
259055
259074
|
const CLOCK_SKEW_SECONDS = 30;
|
|
259056
259075
|
const TOKEN_TTL_SECONDS = 300;
|
|
259076
|
+
const EVENT_TOKEN_TTL_SECONDS = 60;
|
|
259077
|
+
const EVENT_MAX_BYTES = 64 * 1024;
|
|
259078
|
+
const EVENT_TYPE_PREFIX = "__";
|
|
259057
259079
|
|
|
259058
259080
|
const decodeSegment = (segment) => {
|
|
259059
259081
|
const normalized = segment.replace(/-/g, "+").replace(/_/g, "/");
|
|
@@ -259069,6 +259091,37 @@ const unauthorized = () => ({
|
|
|
259069
259091
|
ok: false,
|
|
259070
259092
|
response: new Response("Unauthorized", { status: 401 }),
|
|
259071
259093
|
});
|
|
259094
|
+
const refused = (status, text) => ({ ok: false, response: new Response(text, { status }) });
|
|
259095
|
+
|
|
259096
|
+
// The claims of an EdDSA JWT whose signature the actor's public key verifies, else null.
|
|
259097
|
+
const verifiedClaims = async (token, publicKey) => {
|
|
259098
|
+
if (typeof token !== "string" || token.length > 4096) return null;
|
|
259099
|
+
const parts = token.split(".");
|
|
259100
|
+
if (parts.length !== 3) return null;
|
|
259101
|
+
const header = decodeJsonSegment(parts[0]);
|
|
259102
|
+
if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) return null;
|
|
259103
|
+
const key = await crypto.subtle.importKey(
|
|
259104
|
+
"raw",
|
|
259105
|
+
decodeSegment(publicKey),
|
|
259106
|
+
{ name: "Ed25519" },
|
|
259107
|
+
false,
|
|
259108
|
+
["verify"],
|
|
259109
|
+
);
|
|
259110
|
+
const validSignature = await crypto.subtle.verify(
|
|
259111
|
+
{ name: "Ed25519" },
|
|
259112
|
+
key,
|
|
259113
|
+
decodeSegment(parts[2]),
|
|
259114
|
+
new TextEncoder().encode(parts[0] + "." + parts[1]),
|
|
259115
|
+
);
|
|
259116
|
+
return validSignature ? decodeJsonSegment(parts[1]) : null;
|
|
259117
|
+
};
|
|
259118
|
+
|
|
259119
|
+
const validTimes = (claims, now, ttlSeconds) =>
|
|
259120
|
+
[claims.iat, claims.nbf, claims.exp].every(Number.isInteger) &&
|
|
259121
|
+
claims.iat <= now + CLOCK_SKEW_SECONDS &&
|
|
259122
|
+
claims.nbf <= now + CLOCK_SKEW_SECONDS &&
|
|
259123
|
+
claims.exp >= now - CLOCK_SKEW_SECONDS &&
|
|
259124
|
+
claims.exp > claims.iat && claims.exp - claims.iat <= ttlSeconds;
|
|
259072
259125
|
|
|
259073
259126
|
const validPrincipal = (principal) => {
|
|
259074
259127
|
if (principal === null || typeof principal !== "object" || Array.isArray(principal)) return false;
|
|
@@ -259087,46 +259140,21 @@ export async function verifyActorConnection(request, env, actorName, room) {
|
|
|
259087
259140
|
const token = request.headers.get(TOKEN_HEADER) ?? new URL(request.url).searchParams.get("token");
|
|
259088
259141
|
if (
|
|
259089
259142
|
typeof publicKey !== "string" || !publicKey ||
|
|
259090
|
-
typeof scriptId !== "string" || !scriptId
|
|
259091
|
-
typeof token !== "string" || token.length > 4096
|
|
259143
|
+
typeof scriptId !== "string" || !scriptId
|
|
259092
259144
|
) return unauthorized();
|
|
259093
259145
|
|
|
259094
|
-
const parts = token.split(".");
|
|
259095
|
-
if (parts.length !== 3) return unauthorized();
|
|
259096
259146
|
try {
|
|
259097
|
-
const
|
|
259098
|
-
|
|
259099
|
-
if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) {
|
|
259100
|
-
return unauthorized();
|
|
259101
|
-
}
|
|
259102
|
-
const key = await crypto.subtle.importKey(
|
|
259103
|
-
"raw",
|
|
259104
|
-
decodeSegment(publicKey),
|
|
259105
|
-
{ name: "Ed25519" },
|
|
259106
|
-
false,
|
|
259107
|
-
["verify"],
|
|
259108
|
-
);
|
|
259109
|
-
const validSignature = await crypto.subtle.verify(
|
|
259110
|
-
{ name: "Ed25519" },
|
|
259111
|
-
key,
|
|
259112
|
-
decodeSegment(parts[2]),
|
|
259113
|
-
new TextEncoder().encode(parts[0] + "." + parts[1]),
|
|
259114
|
-
);
|
|
259115
|
-
if (!validSignature) return unauthorized();
|
|
259147
|
+
const claims = await verifiedClaims(token, publicKey);
|
|
259148
|
+
if (!claims) return unauthorized();
|
|
259116
259149
|
|
|
259117
259150
|
const now = Math.floor(Date.now() / 1000);
|
|
259118
|
-
const times = [claims.iat, claims.nbf, claims.exp];
|
|
259119
|
-
if (!times.every(Number.isInteger)) return unauthorized();
|
|
259120
259151
|
if (
|
|
259121
259152
|
claims.iss !== "base44" ||
|
|
259122
259153
|
claims.aud !== "base44-actor-connect" ||
|
|
259123
259154
|
claims.purpose !== "actor-connect" ||
|
|
259124
259155
|
claims.v !== 1 ||
|
|
259125
259156
|
typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
|
|
259126
|
-
claims
|
|
259127
|
-
claims.nbf > now + CLOCK_SKEW_SECONDS ||
|
|
259128
|
-
claims.exp < now - CLOCK_SKEW_SECONDS ||
|
|
259129
|
-
claims.exp <= claims.iat || claims.exp - claims.iat > TOKEN_TTL_SECONDS ||
|
|
259157
|
+
!validTimes(claims, now, TOKEN_TTL_SECONDS) ||
|
|
259130
259158
|
claims.app_id !== env.BASE44_APP_ID ||
|
|
259131
259159
|
claims.actor_name !== actorName ||
|
|
259132
259160
|
claims.actor_script_id !== scriptId ||
|
|
@@ -259156,6 +259184,75 @@ export function authorizedActorRequest(request, identity, actorName, room, runti
|
|
|
259156
259184
|
headers.set("base44-functions-version", runtimeMode === "prod" ? "prod" : "preview");
|
|
259157
259185
|
return new Request(new Request(url.toString(), request), { headers });
|
|
259158
259186
|
}
|
|
259187
|
+
|
|
259188
|
+
// A platform event the backend posts into one room. Same key as connection
|
|
259189
|
+
// tokens, its own audience and purpose: neither token is accepted as the other.
|
|
259190
|
+
// 401 is a token this key did not mint or that has lapsed; 403 is a good token
|
|
259191
|
+
// for another app, actor, script or room.
|
|
259192
|
+
export async function verifyActorEvent(request, env, actorName, room) {
|
|
259193
|
+
const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
|
|
259194
|
+
const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
|
|
259195
|
+
if (
|
|
259196
|
+
typeof publicKey !== "string" || !publicKey ||
|
|
259197
|
+
typeof scriptId !== "string" || !scriptId
|
|
259198
|
+
) return unauthorized();
|
|
259199
|
+
try {
|
|
259200
|
+
const claims = await verifiedClaims(request.headers.get(EVENT_TOKEN_HEADER), publicKey);
|
|
259201
|
+
if (!claims) return unauthorized();
|
|
259202
|
+
const now = Math.floor(Date.now() / 1000);
|
|
259203
|
+
if (
|
|
259204
|
+
claims.iss !== "base44" ||
|
|
259205
|
+
claims.aud !== "base44-actor-event" ||
|
|
259206
|
+
claims.purpose !== "actor-platform-event" ||
|
|
259207
|
+
claims.v !== 1 ||
|
|
259208
|
+
typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
|
|
259209
|
+
!validTimes(claims, now, EVENT_TOKEN_TTL_SECONDS) ||
|
|
259210
|
+
typeof claims.event_id !== "string" || !claims.event_id || claims.event_id.length > 256
|
|
259211
|
+
) return unauthorized();
|
|
259212
|
+
if (
|
|
259213
|
+
claims.app_id !== env.BASE44_APP_ID ||
|
|
259214
|
+
claims.actor_name !== actorName ||
|
|
259215
|
+
claims.actor_script_id !== scriptId ||
|
|
259216
|
+
claims.room !== room
|
|
259217
|
+
) return refused(403, "Forbidden");
|
|
259218
|
+
return { ok: true, eventId: claims.event_id };
|
|
259219
|
+
} catch {
|
|
259220
|
+
return unauthorized();
|
|
259221
|
+
}
|
|
259222
|
+
}
|
|
259223
|
+
|
|
259224
|
+
// The JSON body of a verified event: one object in the platform's "__" type
|
|
259225
|
+
// namespace whose event_id is the one the token was minted for.
|
|
259226
|
+
export async function readPlatformEvent(request, eventId) {
|
|
259227
|
+
let text;
|
|
259228
|
+
try { text = await request.text(); } catch { return refused(400, "Unreadable event"); }
|
|
259229
|
+
if (new TextEncoder().encode(text).length > EVENT_MAX_BYTES) return refused(413, "Event too large");
|
|
259230
|
+
let event;
|
|
259231
|
+
try { event = JSON.parse(text); } catch { return refused(400, "Invalid event"); }
|
|
259232
|
+
if (
|
|
259233
|
+
event === null || typeof event !== "object" || Array.isArray(event) ||
|
|
259234
|
+
typeof event.type !== "string" || !event.type.startsWith(EVENT_TYPE_PREFIX) || event.type.length > 128 ||
|
|
259235
|
+
event.event_id !== eventId
|
|
259236
|
+
) return refused(400, "Invalid event");
|
|
259237
|
+
return { ok: true, event };
|
|
259238
|
+
}
|
|
259239
|
+
|
|
259240
|
+
// Into the room as POST /parties/<actor>/<room>/events: a path no client route
|
|
259241
|
+
// forwards (the legacy route is exactly four segments, the direct route rewrites
|
|
259242
|
+
// the path), so the Durable Object can trust the shape alone.
|
|
259243
|
+
export function platformEventRequest(request, env, actorName, room, event) {
|
|
259244
|
+
const url = new URL(request.url);
|
|
259245
|
+
url.search = "";
|
|
259246
|
+
url.pathname = "/parties/" + encodeURIComponent(actorName) + "/" + encodeURIComponent(room) + "/events";
|
|
259247
|
+
return new Request(url.toString(), {
|
|
259248
|
+
method: "POST",
|
|
259249
|
+
headers: {
|
|
259250
|
+
"Content-Type": "application/json",
|
|
259251
|
+
"base44-functions-version": env.BASE44_FUNCTIONS_VERSION === "prod" ? "prod" : "preview",
|
|
259252
|
+
},
|
|
259253
|
+
body: JSON.stringify(event),
|
|
259254
|
+
});
|
|
259255
|
+
}
|
|
259159
259256
|
`;
|
|
259160
259257
|
}
|
|
259161
259258
|
function buildPrelude() {
|
|
@@ -259176,7 +259273,13 @@ function buildEntryWrapper(doClassName, userEntry) {
|
|
|
259176
259273
|
import "./${ACTOR_PRELUDE_FILENAME}";
|
|
259177
259274
|
import Base44UserActor from ${JSON.stringify(userImport)};
|
|
259178
259275
|
import { runWithWorkerEnvironment as _b44Run } from ${JSON.stringify(RUNTIME_CONTEXT_SPECIFIER)};
|
|
259179
|
-
import {
|
|
259276
|
+
import {
|
|
259277
|
+
authorizedActorRequest as _b44AuthorizedActorRequest,
|
|
259278
|
+
platformEventRequest as _b44PlatformEventRequest,
|
|
259279
|
+
readPlatformEvent as _b44ReadPlatformEvent,
|
|
259280
|
+
verifyActorConnection as _b44VerifyActorConnection,
|
|
259281
|
+
verifyActorEvent as _b44VerifyActorEvent,
|
|
259282
|
+
} from "./${ACTOR_AUTH_FILENAME}";
|
|
259180
259283
|
|
|
259181
259284
|
const _b44ActorState = new WeakMap();
|
|
259182
259285
|
const _b44RunWithActorEnvironment = (ctx, env, runtimeEnv, callback) => _b44Run({
|
|
@@ -259206,6 +259309,11 @@ const _b44RunActor = (actor, request, callback) => {
|
|
|
259206
259309
|
state.runtimeEnv = runtimeEnv;
|
|
259207
259310
|
return _b44RunWithActorEnvironment(state.ctx, state.env, runtimeEnv, callback);
|
|
259208
259311
|
};
|
|
259312
|
+
const _b44IsPlatformEvent = (request) => {
|
|
259313
|
+
if (request.method !== "POST") return false;
|
|
259314
|
+
const parts = new URL(request.url).pathname.split("/");
|
|
259315
|
+
return parts.length === 5 && parts[1] === "parties" && parts[4] === "events";
|
|
259316
|
+
};
|
|
259209
259317
|
|
|
259210
259318
|
export class ${doClassName} extends Base44UserActor {
|
|
259211
259319
|
// Read by the shim's service-token exchange: the assertion's actor_name claim
|
|
@@ -259218,6 +259326,11 @@ export class ${doClassName} extends Base44UserActor {
|
|
|
259218
259326
|
}
|
|
259219
259327
|
|
|
259220
259328
|
fetch(request) {
|
|
259329
|
+
// Ahead of the user's own fetch override: a platform event is the wrapper's,
|
|
259330
|
+
// never a request the room handles itself.
|
|
259331
|
+
if (_b44IsPlatformEvent(request)) {
|
|
259332
|
+
return _b44RunActor(this, request, () => this._b44PlatformEvent(request));
|
|
259333
|
+
}
|
|
259221
259334
|
return _b44RunActor(this, request, () => super.fetch(request));
|
|
259222
259335
|
}
|
|
259223
259336
|
|
|
@@ -259251,15 +259364,22 @@ export default {
|
|
|
259251
259364
|
const parts = url.pathname.split("/");
|
|
259252
259365
|
const direct = parts[1] === "rooms" && parts.length === 3;
|
|
259253
259366
|
const legacy = parts[1] === "parties" && parts.length === 4;
|
|
259254
|
-
|
|
259367
|
+
const event = request.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "events";
|
|
259368
|
+
if (direct || legacy || event) {
|
|
259255
259369
|
// Decode the room: the token was verified against the decoded instance id,
|
|
259256
259370
|
// so an escaped room must map to the same Durable Object.
|
|
259257
|
-
const namespace =
|
|
259258
|
-
const encodedRoom =
|
|
259371
|
+
const namespace = legacy ? parts[2] : "${doClassName}";
|
|
259372
|
+
const encodedRoom = legacy ? parts[3] : parts[2];
|
|
259259
259373
|
let room;
|
|
259260
259374
|
try { room = decodeURIComponent(encodedRoom); } catch { return new Response("Invalid room", { status: 400 }); }
|
|
259261
259375
|
let actorRequest = request;
|
|
259262
|
-
if (
|
|
259376
|
+
if (event) {
|
|
259377
|
+
const verification = await _b44VerifyActorEvent(request, env, "${doClassName}", room);
|
|
259378
|
+
if (!verification.ok) return verification.response;
|
|
259379
|
+
const platformEvent = await _b44ReadPlatformEvent(request, verification.eventId);
|
|
259380
|
+
if (!platformEvent.ok) return platformEvent.response;
|
|
259381
|
+
actorRequest = _b44PlatformEventRequest(request, env, "${doClassName}", room, platformEvent.event);
|
|
259382
|
+
} else if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
|
|
259263
259383
|
const verification = await _b44VerifyActorConnection(request, env, "${doClassName}", room);
|
|
259264
259384
|
if (!verification.ok) return verification.response;
|
|
259265
259385
|
actorRequest = _b44AuthorizedActorRequest(
|
|
@@ -270720,6 +270840,17 @@ function inheritedEnv() {
|
|
|
270720
270840
|
}
|
|
270721
270841
|
return env;
|
|
270722
270842
|
}
|
|
270843
|
+
var appPreviewUrl = (appId) => `https://preview--${appId}.base44.app`;
|
|
270844
|
+
async function resolveAppBaseUrl(appId) {
|
|
270845
|
+
try {
|
|
270846
|
+
return await getSiteUrl();
|
|
270847
|
+
} catch (error) {
|
|
270848
|
+
if (error instanceof ApiError && error.statusCode === 404) {
|
|
270849
|
+
return appPreviewUrl(appId);
|
|
270850
|
+
}
|
|
270851
|
+
throw error;
|
|
270852
|
+
}
|
|
270853
|
+
}
|
|
270723
270854
|
async function runScript(options) {
|
|
270724
270855
|
const { appId, code, local, privileged, dataEnv, serviceToken, sdkVersion } = options;
|
|
270725
270856
|
verifyDenoInstalled("to run scripts with exec");
|
|
@@ -270728,7 +270859,7 @@ async function runScript(options) {
|
|
|
270728
270859
|
cleanupFns.push(tempScript.cleanup);
|
|
270729
270860
|
writeFileSync3(tempScript.path, code, "utf-8");
|
|
270730
270861
|
const scriptPath = `file://${tempScript.path}`;
|
|
270731
|
-
const [appUserToken, appBaseUrl] = local ? [local.token, local.serverUrl] : await Promise.all([getAppUserToken(),
|
|
270862
|
+
const [appUserToken, appBaseUrl] = local ? [local.token, local.serverUrl] : await Promise.all([getAppUserToken(), resolveAppBaseUrl(appId)]);
|
|
270732
270863
|
const tempWrapper = await $file({ postfix: ".ts" });
|
|
270733
270864
|
cleanupFns.push(tempWrapper.cleanup);
|
|
270734
270865
|
writeFileSync3(tempWrapper.path, wrapperSource(sdkVersion), "utf-8");
|
|
@@ -275065,4 +275196,4 @@ export {
|
|
|
275065
275196
|
runCLI
|
|
275066
275197
|
};
|
|
275067
275198
|
|
|
275068
|
-
//# debugId=
|
|
275199
|
+
//# debugId=0543661A2E4EC46564756E2164756E21
|