@base44-preview/cli 0.3.1-pr.697.d8b6e5d → 0.3.2-pr.696.4860b6a

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: {
@@ -256404,7 +256404,7 @@ Did you try connecting directly to this Durable Object? Try using getServerByNam
256404
256404
  };
256405
256405
 
256406
256406
  // src/shim/actor.ts
256407
- import { createClient } from "npm:@base44/sdk@0.8.41";
256407
+ import { createClient } from "npm:@base44/sdk@0.8.54";
256408
256408
 
256409
256409
  // src/shim/tick-loop.ts
256410
256410
  var TickLoop = class {
@@ -256814,6 +256814,36 @@ 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
+ platformEventsInFlight = /* @__PURE__ */ new Map();
256824
+ static REMEMBERED_PLATFORM_EVENTS = 64;
256825
+ // Called by the generated wrapper for a verified POST .../events; never user-facing.
256826
+ async _b44PlatformEvent(request) {
256827
+ const room = request.headers.get("x-partykit-room");
256828
+ if (room) await this.setName(room);
256829
+ const event = await request.json();
256830
+ const eventId = event.event_id;
256831
+ if (!this.takenPlatformEvents.includes(eventId)) {
256832
+ let delivery = this.platformEventsInFlight.get(eventId);
256833
+ if (!delivery) {
256834
+ delivery = this.takePlatformEvent(event).finally(() => this.platformEventsInFlight.delete(eventId));
256835
+ this.platformEventsInFlight.set(eventId, delivery);
256836
+ }
256837
+ await delivery;
256838
+ }
256839
+ return new Response(null, { status: 204 });
256840
+ }
256841
+ async takePlatformEvent(event) {
256842
+ await this.handlePlatformEvent(event);
256843
+ this.takenPlatformEvents.push(event.event_id);
256844
+ if (this.takenPlatformEvents.length > _Actor.REMEMBERED_PLATFORM_EVENTS) this.takenPlatformEvents.shift();
256845
+ await this.maintainTicker();
256846
+ }
256817
256847
  async schedule(key, at) {
256818
256848
  const when = typeof at === "number" ? at : at.getTime();
256819
256849
  await this.mutateSchedules((m) => {
@@ -258554,7 +258584,7 @@ var TELEMETRY_PATCH = [
258554
258584
  var TELEMETRY_STORE_FIELDS = "reqId: crypto.randomUUID(), respondedAt: null, inflight: new Map(), inflightTotal: 0, hadRejection: false, hadNonOk: false, logBudget: 5";
258555
258585
 
258556
258586
  // ../functions-compiler/src/version.ts
258557
- var COMPILER_VERSION = "0.2.0";
258587
+ var COMPILER_VERSION = "0.3.0";
258558
258588
 
258559
258589
  // ../functions-compiler/src/worker-entry.ts
258560
258590
  function denoShimSource() {
@@ -259053,8 +259083,12 @@ function buildActorAuth() {
259053
259083
  return `// Auto-generated by the base44 bundler. Do not edit.
259054
259084
  const TOKEN_HEADER = "X-Base44-Actor-Token";
259055
259085
  const IDENTITY_HEADER = "X-Base44-Actor-Identity";
259086
+ const EVENT_TOKEN_HEADER = "X-Base44-Actor-Event-Token";
259056
259087
  const CLOCK_SKEW_SECONDS = 30;
259057
259088
  const TOKEN_TTL_SECONDS = 300;
259089
+ const EVENT_TOKEN_TTL_SECONDS = 60;
259090
+ const EVENT_MAX_BYTES = 64 * 1024;
259091
+ const EVENT_TYPE_PREFIX = "__";
259058
259092
 
259059
259093
  const decodeSegment = (segment) => {
259060
259094
  const normalized = segment.replace(/-/g, "+").replace(/_/g, "/");
@@ -259070,6 +259104,37 @@ const unauthorized = () => ({
259070
259104
  ok: false,
259071
259105
  response: new Response("Unauthorized", { status: 401 }),
259072
259106
  });
259107
+ const refused = (status, text) => ({ ok: false, response: new Response(text, { status }) });
259108
+
259109
+ // The claims of an EdDSA JWT whose signature the actor's public key verifies, else null.
259110
+ const verifiedClaims = async (token, publicKey) => {
259111
+ if (typeof token !== "string" || token.length > 4096) return null;
259112
+ const parts = token.split(".");
259113
+ if (parts.length !== 3) return null;
259114
+ const header = decodeJsonSegment(parts[0]);
259115
+ if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) return null;
259116
+ const key = await crypto.subtle.importKey(
259117
+ "raw",
259118
+ decodeSegment(publicKey),
259119
+ { name: "Ed25519" },
259120
+ false,
259121
+ ["verify"],
259122
+ );
259123
+ const validSignature = await crypto.subtle.verify(
259124
+ { name: "Ed25519" },
259125
+ key,
259126
+ decodeSegment(parts[2]),
259127
+ new TextEncoder().encode(parts[0] + "." + parts[1]),
259128
+ );
259129
+ return validSignature ? decodeJsonSegment(parts[1]) : null;
259130
+ };
259131
+
259132
+ const validTimes = (claims, now, ttlSeconds) =>
259133
+ [claims.iat, claims.nbf, claims.exp].every(Number.isInteger) &&
259134
+ claims.iat <= now + CLOCK_SKEW_SECONDS &&
259135
+ claims.nbf <= now + CLOCK_SKEW_SECONDS &&
259136
+ claims.exp >= now - CLOCK_SKEW_SECONDS &&
259137
+ claims.exp > claims.iat && claims.exp - claims.iat <= ttlSeconds;
259073
259138
 
259074
259139
  const validPrincipal = (principal) => {
259075
259140
  if (principal === null || typeof principal !== "object" || Array.isArray(principal)) return false;
@@ -259088,46 +259153,21 @@ export async function verifyActorConnection(request, env, actorName, room) {
259088
259153
  const token = request.headers.get(TOKEN_HEADER) ?? new URL(request.url).searchParams.get("token");
259089
259154
  if (
259090
259155
  typeof publicKey !== "string" || !publicKey ||
259091
- typeof scriptId !== "string" || !scriptId ||
259092
- typeof token !== "string" || token.length > 4096
259156
+ typeof scriptId !== "string" || !scriptId
259093
259157
  ) return unauthorized();
259094
259158
 
259095
- const parts = token.split(".");
259096
- if (parts.length !== 3) return unauthorized();
259097
259159
  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();
259160
+ const claims = await verifiedClaims(token, publicKey);
259161
+ if (!claims) return unauthorized();
259117
259162
 
259118
259163
  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
259164
  if (
259122
259165
  claims.iss !== "base44" ||
259123
259166
  claims.aud !== "base44-actor-connect" ||
259124
259167
  claims.purpose !== "actor-connect" ||
259125
259168
  claims.v !== 1 ||
259126
259169
  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 ||
259170
+ !validTimes(claims, now, TOKEN_TTL_SECONDS) ||
259131
259171
  claims.app_id !== env.BASE44_APP_ID ||
259132
259172
  claims.actor_name !== actorName ||
259133
259173
  claims.actor_script_id !== scriptId ||
@@ -259157,6 +259197,75 @@ export function authorizedActorRequest(request, identity, actorName, room, runti
259157
259197
  headers.set("base44-functions-version", runtimeMode === "prod" ? "prod" : "preview");
259158
259198
  return new Request(new Request(url.toString(), request), { headers });
259159
259199
  }
259200
+
259201
+ // A platform event the backend posts into one room. Same key as connection
259202
+ // tokens, its own audience and purpose: neither token is accepted as the other.
259203
+ // 401 is a token this key did not mint or that has lapsed; 403 is a good token
259204
+ // for another app, actor, script or room.
259205
+ export async function verifyActorEvent(request, env, actorName, room) {
259206
+ const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
259207
+ const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
259208
+ if (
259209
+ typeof publicKey !== "string" || !publicKey ||
259210
+ typeof scriptId !== "string" || !scriptId
259211
+ ) return unauthorized();
259212
+ try {
259213
+ const claims = await verifiedClaims(request.headers.get(EVENT_TOKEN_HEADER), publicKey);
259214
+ if (!claims) return unauthorized();
259215
+ const now = Math.floor(Date.now() / 1000);
259216
+ if (
259217
+ claims.iss !== "base44" ||
259218
+ claims.aud !== "base44-actor-event" ||
259219
+ claims.purpose !== "actor-platform-event" ||
259220
+ claims.v !== 1 ||
259221
+ typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259222
+ !validTimes(claims, now, EVENT_TOKEN_TTL_SECONDS) ||
259223
+ typeof claims.event_id !== "string" || !claims.event_id || claims.event_id.length > 256
259224
+ ) return unauthorized();
259225
+ if (
259226
+ claims.app_id !== env.BASE44_APP_ID ||
259227
+ claims.actor_name !== actorName ||
259228
+ claims.actor_script_id !== scriptId ||
259229
+ claims.room !== room
259230
+ ) return refused(403, "Forbidden");
259231
+ return { ok: true, eventId: claims.event_id };
259232
+ } catch {
259233
+ return unauthorized();
259234
+ }
259235
+ }
259236
+
259237
+ // The JSON body of a verified event: one object in the platform's "__" type
259238
+ // namespace whose event_id is the one the token was minted for.
259239
+ export async function readPlatformEvent(request, eventId) {
259240
+ let text;
259241
+ try { text = await request.text(); } catch { return refused(400, "Unreadable event"); }
259242
+ if (new TextEncoder().encode(text).length > EVENT_MAX_BYTES) return refused(413, "Event too large");
259243
+ let event;
259244
+ try { event = JSON.parse(text); } catch { return refused(400, "Invalid event"); }
259245
+ if (
259246
+ event === null || typeof event !== "object" || Array.isArray(event) ||
259247
+ typeof event.type !== "string" || !event.type.startsWith(EVENT_TYPE_PREFIX) || event.type.length > 128 ||
259248
+ event.event_id !== eventId
259249
+ ) return refused(400, "Invalid event");
259250
+ return { ok: true, event };
259251
+ }
259252
+
259253
+ // Into the room as POST /parties/<actor>/<room>/events: a path no client route
259254
+ // forwards (the legacy route is exactly four segments, the direct route rewrites
259255
+ // the path), so the Durable Object can trust the shape alone.
259256
+ export function platformEventRequest(request, env, actorName, room, event) {
259257
+ const url = new URL(request.url);
259258
+ url.search = "";
259259
+ url.pathname = "/parties/" + encodeURIComponent(actorName) + "/" + encodeURIComponent(room) + "/events";
259260
+ return new Request(url.toString(), {
259261
+ method: "POST",
259262
+ headers: {
259263
+ "Content-Type": "application/json",
259264
+ "base44-functions-version": env.BASE44_FUNCTIONS_VERSION === "prod" ? "prod" : "preview",
259265
+ },
259266
+ body: JSON.stringify(event),
259267
+ });
259268
+ }
259160
259269
  `;
259161
259270
  }
259162
259271
  function buildPrelude() {
@@ -259177,7 +259286,13 @@ function buildEntryWrapper(doClassName, userEntry) {
259177
259286
  import "./${ACTOR_PRELUDE_FILENAME}";
259178
259287
  import Base44UserActor from ${JSON.stringify(userImport)};
259179
259288
  import { runWithWorkerEnvironment as _b44Run } from ${JSON.stringify(RUNTIME_CONTEXT_SPECIFIER)};
259180
- import { authorizedActorRequest as _b44AuthorizedActorRequest, verifyActorConnection as _b44VerifyActorConnection } from "./${ACTOR_AUTH_FILENAME}";
259289
+ import {
259290
+ authorizedActorRequest as _b44AuthorizedActorRequest,
259291
+ platformEventRequest as _b44PlatformEventRequest,
259292
+ readPlatformEvent as _b44ReadPlatformEvent,
259293
+ verifyActorConnection as _b44VerifyActorConnection,
259294
+ verifyActorEvent as _b44VerifyActorEvent,
259295
+ } from "./${ACTOR_AUTH_FILENAME}";
259181
259296
 
259182
259297
  const _b44ActorState = new WeakMap();
259183
259298
  const _b44RunWithActorEnvironment = (ctx, env, runtimeEnv, callback) => _b44Run({
@@ -259207,6 +259322,11 @@ const _b44RunActor = (actor, request, callback) => {
259207
259322
  state.runtimeEnv = runtimeEnv;
259208
259323
  return _b44RunWithActorEnvironment(state.ctx, state.env, runtimeEnv, callback);
259209
259324
  };
259325
+ const _b44IsPlatformEvent = (request) => {
259326
+ if (request.method !== "POST") return false;
259327
+ const parts = new URL(request.url).pathname.split("/");
259328
+ return parts.length === 5 && parts[1] === "parties" && parts[4] === "events";
259329
+ };
259210
259330
 
259211
259331
  export class ${doClassName} extends Base44UserActor {
259212
259332
  // Read by the shim's service-token exchange: the assertion's actor_name claim
@@ -259219,6 +259339,11 @@ export class ${doClassName} extends Base44UserActor {
259219
259339
  }
259220
259340
 
259221
259341
  fetch(request) {
259342
+ // Ahead of the user's own fetch override: a platform event is the wrapper's,
259343
+ // never a request the room handles itself.
259344
+ if (_b44IsPlatformEvent(request)) {
259345
+ return _b44RunActor(this, request, () => this._b44PlatformEvent(request));
259346
+ }
259222
259347
  return _b44RunActor(this, request, () => super.fetch(request));
259223
259348
  }
259224
259349
 
@@ -259252,15 +259377,22 @@ export default {
259252
259377
  const parts = url.pathname.split("/");
259253
259378
  const direct = parts[1] === "rooms" && parts.length === 3;
259254
259379
  const legacy = parts[1] === "parties" && parts.length === 4;
259255
- if (direct || legacy) {
259380
+ const event = request.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "events";
259381
+ if (direct || legacy || event) {
259256
259382
  // Decode the room: the token was verified against the decoded instance id,
259257
259383
  // 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];
259384
+ const namespace = legacy ? parts[2] : "${doClassName}";
259385
+ const encodedRoom = legacy ? parts[3] : parts[2];
259260
259386
  let room;
259261
259387
  try { room = decodeURIComponent(encodedRoom); } catch { return new Response("Invalid room", { status: 400 }); }
259262
259388
  let actorRequest = request;
259263
- if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259389
+ if (event) {
259390
+ const verification = await _b44VerifyActorEvent(request, env, "${doClassName}", room);
259391
+ if (!verification.ok) return verification.response;
259392
+ const platformEvent = await _b44ReadPlatformEvent(request, verification.eventId);
259393
+ if (!platformEvent.ok) return platformEvent.response;
259394
+ actorRequest = _b44PlatformEventRequest(request, env, "${doClassName}", room, platformEvent.event);
259395
+ } else if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
259264
259396
  const verification = await _b44VerifyActorConnection(request, env, "${doClassName}", room);
259265
259397
  if (!verification.ok) return verification.response;
259266
259398
  actorRequest = _b44AuthorizedActorRequest(
@@ -275082,4 +275214,4 @@ export {
275082
275214
  runCLI
275083
275215
  };
275084
275216
 
275085
- //# debugId=8C1B105F76867A6564756E2164756E21
275217
+ //# debugId=DB3B9E2289BBFFBC64756E2164756E21