@base44-preview/cli 0.3.1-pr.697.d8b6e5d → 0.3.2-pr.696.9421a35

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 CHANGED
@@ -239420,7 +239420,7 @@ import { join as join13 } from "node:path";
239420
239420
  // package.json
239421
239421
  var package_default = {
239422
239422
  name: "base44",
239423
- version: "0.3.1",
239423
+ version: "0.3.2",
239424
239424
  description: "Base44 CLI - Unified interface for managing Base44 applications",
239425
239425
  type: "module",
239426
239426
  bin: {
@@ -256814,6 +256814,26 @@ var Actor = class _Actor extends Server {
256814
256814
  }
256815
256815
  handleWake(_key) {
256816
256816
  }
256817
+ // Optional: the platform posted an event into this room. Delivery is
256818
+ // at-least-once; a repeat of an event_id this instance already took is dropped
256819
+ // here, so a room that must be exact across evictions dedups on event_id too.
256820
+ handlePlatformEvent(_event) {
256821
+ }
256822
+ takenPlatformEvents = [];
256823
+ static REMEMBERED_PLATFORM_EVENTS = 64;
256824
+ // Called by the generated wrapper for a verified POST .../events; never user-facing.
256825
+ async _b44PlatformEvent(request) {
256826
+ const room = request.headers.get("x-partykit-room");
256827
+ if (room) await this.setName(room);
256828
+ const event = await request.json();
256829
+ if (!this.takenPlatformEvents.includes(event.event_id)) {
256830
+ await this.handlePlatformEvent(event);
256831
+ this.takenPlatformEvents.push(event.event_id);
256832
+ if (this.takenPlatformEvents.length > _Actor.REMEMBERED_PLATFORM_EVENTS) this.takenPlatformEvents.shift();
256833
+ await this.maintainTicker();
256834
+ }
256835
+ return new Response(null, { status: 204 });
256836
+ }
256817
256837
  async schedule(key, at) {
256818
256838
  const when = typeof at === "number" ? at : at.getTime();
256819
256839
  await this.mutateSchedules((m) => {
@@ -258554,7 +258574,7 @@ var TELEMETRY_PATCH = [
258554
258574
  var TELEMETRY_STORE_FIELDS = "reqId: crypto.randomUUID(), respondedAt: null, inflight: new Map(), inflightTotal: 0, hadRejection: false, hadNonOk: false, logBudget: 5";
258555
258575
 
258556
258576
  // ../functions-compiler/src/version.ts
258557
- var COMPILER_VERSION = "0.2.0";
258577
+ var COMPILER_VERSION = "0.3.0-beta.2";
258558
258578
 
258559
258579
  // ../functions-compiler/src/worker-entry.ts
258560
258580
  function denoShimSource() {
@@ -259053,8 +259073,12 @@ function buildActorAuth() {
259053
259073
  return `// Auto-generated by the base44 bundler. Do not edit.
259054
259074
  const TOKEN_HEADER = "X-Base44-Actor-Token";
259055
259075
  const IDENTITY_HEADER = "X-Base44-Actor-Identity";
259076
+ const EVENT_TOKEN_HEADER = "X-Base44-Actor-Event-Token";
259056
259077
  const CLOCK_SKEW_SECONDS = 30;
259057
259078
  const TOKEN_TTL_SECONDS = 300;
259079
+ const EVENT_TOKEN_TTL_SECONDS = 60;
259080
+ const EVENT_MAX_BYTES = 64 * 1024;
259081
+ const EVENT_TYPE_PREFIX = "__";
259058
259082
 
259059
259083
  const decodeSegment = (segment) => {
259060
259084
  const normalized = segment.replace(/-/g, "+").replace(/_/g, "/");
@@ -259070,6 +259094,37 @@ const unauthorized = () => ({
259070
259094
  ok: false,
259071
259095
  response: new Response("Unauthorized", { status: 401 }),
259072
259096
  });
259097
+ const refused = (status, text) => ({ ok: false, response: new Response(text, { status }) });
259098
+
259099
+ // The claims of an EdDSA JWT whose signature the actor's public key verifies, else null.
259100
+ const verifiedClaims = async (token, publicKey) => {
259101
+ if (typeof token !== "string" || token.length > 4096) return null;
259102
+ const parts = token.split(".");
259103
+ if (parts.length !== 3) return null;
259104
+ const header = decodeJsonSegment(parts[0]);
259105
+ if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) return null;
259106
+ const key = await crypto.subtle.importKey(
259107
+ "raw",
259108
+ decodeSegment(publicKey),
259109
+ { name: "Ed25519" },
259110
+ false,
259111
+ ["verify"],
259112
+ );
259113
+ const validSignature = await crypto.subtle.verify(
259114
+ { name: "Ed25519" },
259115
+ key,
259116
+ decodeSegment(parts[2]),
259117
+ new TextEncoder().encode(parts[0] + "." + parts[1]),
259118
+ );
259119
+ return validSignature ? decodeJsonSegment(parts[1]) : null;
259120
+ };
259121
+
259122
+ const validTimes = (claims, now, ttlSeconds) =>
259123
+ [claims.iat, claims.nbf, claims.exp].every(Number.isInteger) &&
259124
+ claims.iat <= now + CLOCK_SKEW_SECONDS &&
259125
+ claims.nbf <= now + CLOCK_SKEW_SECONDS &&
259126
+ claims.exp >= now - CLOCK_SKEW_SECONDS &&
259127
+ claims.exp > claims.iat && claims.exp - claims.iat <= ttlSeconds;
259073
259128
 
259074
259129
  const validPrincipal = (principal) => {
259075
259130
  if (principal === null || typeof principal !== "object" || Array.isArray(principal)) return false;
@@ -259088,46 +259143,21 @@ export async function verifyActorConnection(request, env, actorName, room) {
259088
259143
  const token = request.headers.get(TOKEN_HEADER) ?? new URL(request.url).searchParams.get("token");
259089
259144
  if (
259090
259145
  typeof publicKey !== "string" || !publicKey ||
259091
- typeof scriptId !== "string" || !scriptId ||
259092
- typeof token !== "string" || token.length > 4096
259146
+ typeof scriptId !== "string" || !scriptId
259093
259147
  ) return unauthorized();
259094
259148
 
259095
- const parts = token.split(".");
259096
- if (parts.length !== 3) return unauthorized();
259097
259149
  try {
259098
- const header = decodeJsonSegment(parts[0]);
259099
- const claims = decodeJsonSegment(parts[1]);
259100
- if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) {
259101
- return unauthorized();
259102
- }
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
- if (!validSignature) return unauthorized();
259150
+ const claims = await verifiedClaims(token, publicKey);
259151
+ if (!claims) return unauthorized();
259117
259152
 
259118
259153
  const now = Math.floor(Date.now() / 1000);
259119
- const times = [claims.iat, claims.nbf, claims.exp];
259120
- if (!times.every(Number.isInteger)) return unauthorized();
259121
259154
  if (
259122
259155
  claims.iss !== "base44" ||
259123
259156
  claims.aud !== "base44-actor-connect" ||
259124
259157
  claims.purpose !== "actor-connect" ||
259125
259158
  claims.v !== 1 ||
259126
259159
  typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259127
- claims.iat > now + CLOCK_SKEW_SECONDS ||
259128
- claims.nbf > now + CLOCK_SKEW_SECONDS ||
259129
- claims.exp < now - CLOCK_SKEW_SECONDS ||
259130
- claims.exp <= claims.iat || claims.exp - claims.iat > TOKEN_TTL_SECONDS ||
259160
+ !validTimes(claims, now, TOKEN_TTL_SECONDS) ||
259131
259161
  claims.app_id !== env.BASE44_APP_ID ||
259132
259162
  claims.actor_name !== actorName ||
259133
259163
  claims.actor_script_id !== scriptId ||
@@ -259157,6 +259187,75 @@ export function authorizedActorRequest(request, identity, actorName, room, runti
259157
259187
  headers.set("base44-functions-version", runtimeMode === "prod" ? "prod" : "preview");
259158
259188
  return new Request(new Request(url.toString(), request), { headers });
259159
259189
  }
259190
+
259191
+ // A platform event the backend posts into one room. Same key as connection
259192
+ // tokens, its own audience and purpose: neither token is accepted as the other.
259193
+ // 401 is a token this key did not mint or that has lapsed; 403 is a good token
259194
+ // for another app, actor, script or room.
259195
+ export async function verifyActorEvent(request, env, actorName, room) {
259196
+ const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
259197
+ const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
259198
+ if (
259199
+ typeof publicKey !== "string" || !publicKey ||
259200
+ typeof scriptId !== "string" || !scriptId
259201
+ ) return unauthorized();
259202
+ try {
259203
+ const claims = await verifiedClaims(request.headers.get(EVENT_TOKEN_HEADER), publicKey);
259204
+ if (!claims) return unauthorized();
259205
+ const now = Math.floor(Date.now() / 1000);
259206
+ if (
259207
+ claims.iss !== "base44" ||
259208
+ claims.aud !== "base44-actor-event" ||
259209
+ claims.purpose !== "actor-platform-event" ||
259210
+ claims.v !== 1 ||
259211
+ typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259212
+ !validTimes(claims, now, EVENT_TOKEN_TTL_SECONDS) ||
259213
+ typeof claims.event_id !== "string" || !claims.event_id || claims.event_id.length > 256
259214
+ ) return unauthorized();
259215
+ if (
259216
+ claims.app_id !== env.BASE44_APP_ID ||
259217
+ claims.actor_name !== actorName ||
259218
+ claims.actor_script_id !== scriptId ||
259219
+ claims.room !== room
259220
+ ) return refused(403, "Forbidden");
259221
+ return { ok: true, eventId: claims.event_id };
259222
+ } catch {
259223
+ return unauthorized();
259224
+ }
259225
+ }
259226
+
259227
+ // The JSON body of a verified event: one object in the platform's "__" type
259228
+ // namespace whose event_id is the one the token was minted for.
259229
+ export async function readPlatformEvent(request, eventId) {
259230
+ let text;
259231
+ try { text = await request.text(); } catch { return refused(400, "Unreadable event"); }
259232
+ if (new TextEncoder().encode(text).length > EVENT_MAX_BYTES) return refused(413, "Event too large");
259233
+ let event;
259234
+ try { event = JSON.parse(text); } catch { return refused(400, "Invalid event"); }
259235
+ if (
259236
+ event === null || typeof event !== "object" || Array.isArray(event) ||
259237
+ typeof event.type !== "string" || !event.type.startsWith(EVENT_TYPE_PREFIX) || event.type.length > 128 ||
259238
+ event.event_id !== eventId
259239
+ ) return refused(400, "Invalid event");
259240
+ return { ok: true, event };
259241
+ }
259242
+
259243
+ // Into the room as POST /parties/<actor>/<room>/events: a path no client route
259244
+ // forwards (the legacy route is exactly four segments, the direct route rewrites
259245
+ // the path), so the Durable Object can trust the shape alone.
259246
+ export function platformEventRequest(request, env, actorName, room, event) {
259247
+ const url = new URL(request.url);
259248
+ url.search = "";
259249
+ url.pathname = "/parties/" + encodeURIComponent(actorName) + "/" + encodeURIComponent(room) + "/events";
259250
+ return new Request(url.toString(), {
259251
+ method: "POST",
259252
+ headers: {
259253
+ "Content-Type": "application/json",
259254
+ "base44-functions-version": env.BASE44_FUNCTIONS_VERSION === "prod" ? "prod" : "preview",
259255
+ },
259256
+ body: JSON.stringify(event),
259257
+ });
259258
+ }
259160
259259
  `;
259161
259260
  }
259162
259261
  function buildPrelude() {
@@ -259177,7 +259276,13 @@ function buildEntryWrapper(doClassName, userEntry) {
259177
259276
  import "./${ACTOR_PRELUDE_FILENAME}";
259178
259277
  import Base44UserActor from ${JSON.stringify(userImport)};
259179
259278
  import { runWithWorkerEnvironment as _b44Run } from ${JSON.stringify(RUNTIME_CONTEXT_SPECIFIER)};
259180
- import { authorizedActorRequest as _b44AuthorizedActorRequest, verifyActorConnection as _b44VerifyActorConnection } from "./${ACTOR_AUTH_FILENAME}";
259279
+ import {
259280
+ authorizedActorRequest as _b44AuthorizedActorRequest,
259281
+ platformEventRequest as _b44PlatformEventRequest,
259282
+ readPlatformEvent as _b44ReadPlatformEvent,
259283
+ verifyActorConnection as _b44VerifyActorConnection,
259284
+ verifyActorEvent as _b44VerifyActorEvent,
259285
+ } from "./${ACTOR_AUTH_FILENAME}";
259181
259286
 
259182
259287
  const _b44ActorState = new WeakMap();
259183
259288
  const _b44RunWithActorEnvironment = (ctx, env, runtimeEnv, callback) => _b44Run({
@@ -259207,6 +259312,11 @@ const _b44RunActor = (actor, request, callback) => {
259207
259312
  state.runtimeEnv = runtimeEnv;
259208
259313
  return _b44RunWithActorEnvironment(state.ctx, state.env, runtimeEnv, callback);
259209
259314
  };
259315
+ const _b44IsPlatformEvent = (request) => {
259316
+ if (request.method !== "POST") return false;
259317
+ const parts = new URL(request.url).pathname.split("/");
259318
+ return parts.length === 5 && parts[1] === "parties" && parts[4] === "events";
259319
+ };
259210
259320
 
259211
259321
  export class ${doClassName} extends Base44UserActor {
259212
259322
  // Read by the shim's service-token exchange: the assertion's actor_name claim
@@ -259219,6 +259329,11 @@ export class ${doClassName} extends Base44UserActor {
259219
259329
  }
259220
259330
 
259221
259331
  fetch(request) {
259332
+ // Ahead of the user's own fetch override: a platform event is the wrapper's,
259333
+ // never a request the room handles itself.
259334
+ if (_b44IsPlatformEvent(request)) {
259335
+ return _b44RunActor(this, request, () => this._b44PlatformEvent(request));
259336
+ }
259222
259337
  return _b44RunActor(this, request, () => super.fetch(request));
259223
259338
  }
259224
259339
 
@@ -259252,15 +259367,22 @@ export default {
259252
259367
  const parts = url.pathname.split("/");
259253
259368
  const direct = parts[1] === "rooms" && parts.length === 3;
259254
259369
  const legacy = parts[1] === "parties" && parts.length === 4;
259255
- if (direct || legacy) {
259370
+ const event = request.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "events";
259371
+ if (direct || legacy || event) {
259256
259372
  // Decode the room: the token was verified against the decoded instance id,
259257
259373
  // so an escaped room must map to the same Durable Object.
259258
- const namespace = direct ? "${doClassName}" : parts[2];
259259
- const encodedRoom = direct ? parts[2] : parts[3];
259374
+ const namespace = legacy ? parts[2] : "${doClassName}";
259375
+ const encodedRoom = legacy ? parts[3] : parts[2];
259260
259376
  let room;
259261
259377
  try { room = decodeURIComponent(encodedRoom); } catch { return new Response("Invalid room", { status: 400 }); }
259262
259378
  let actorRequest = request;
259263
- if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259379
+ if (event) {
259380
+ const verification = await _b44VerifyActorEvent(request, env, "${doClassName}", room);
259381
+ if (!verification.ok) return verification.response;
259382
+ const platformEvent = await _b44ReadPlatformEvent(request, verification.eventId);
259383
+ if (!platformEvent.ok) return platformEvent.response;
259384
+ actorRequest = _b44PlatformEventRequest(request, env, "${doClassName}", room, platformEvent.event);
259385
+ } else if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259264
259386
  const verification = await _b44VerifyActorConnection(request, env, "${doClassName}", room);
259265
259387
  if (!verification.ok) return verification.response;
259266
259388
  actorRequest = _b44AuthorizedActorRequest(
@@ -275082,4 +275204,4 @@ export {
275082
275204
  runCLI
275083
275205
  };
275084
275206
 
275085
- //# debugId=8C1B105F76867A6564756E2164756E21
275207
+ //# debugId=9F323218D61403B464756E2164756E21