@base44-preview/cli 0.3.1-pr.695.503ca43 → 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/cli/index.js CHANGED
@@ -228514,6 +228514,21 @@ class DependencyNotFoundError extends UserError {
228514
228514
  });
228515
228515
  }
228516
228516
  }
228517
+
228518
+ class AppNotPublishedError extends UserError {
228519
+ code = "APP_NOT_PUBLISHED";
228520
+ constructor(message = "This app has not been published yet, so it has no site URL", options) {
228521
+ super(message, {
228522
+ hints: options?.hints ?? [
228523
+ {
228524
+ message: "Publish the app in the Base44 builder, or deploy its site with 'base44 deploy'",
228525
+ command: "base44 deploy"
228526
+ }
228527
+ ],
228528
+ cause: options?.cause
228529
+ });
228530
+ }
228531
+ }
228517
228532
  var MAX_RESPONSE_TEXT_CHARS = 500;
228518
228533
  async function readResponseText(response) {
228519
228534
  try {
@@ -256798,6 +256813,24 @@ var Actor = class _Actor extends Server {
256798
256813
  }
256799
256814
  handleWake(_key) {
256800
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
+ }
256801
256834
  async schedule(key, at) {
256802
256835
  const when = typeof at === "number" ? at : at.getTime();
256803
256836
  await this.mutateSchedules((m) => {
@@ -259037,8 +259070,12 @@ function buildActorAuth() {
259037
259070
  return `// Auto-generated by the base44 bundler. Do not edit.
259038
259071
  const TOKEN_HEADER = "X-Base44-Actor-Token";
259039
259072
  const IDENTITY_HEADER = "X-Base44-Actor-Identity";
259073
+ const EVENT_TOKEN_HEADER = "X-Base44-Actor-Event-Token";
259040
259074
  const CLOCK_SKEW_SECONDS = 30;
259041
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 = "__";
259042
259079
 
259043
259080
  const decodeSegment = (segment) => {
259044
259081
  const normalized = segment.replace(/-/g, "+").replace(/_/g, "/");
@@ -259054,6 +259091,37 @@ const unauthorized = () => ({
259054
259091
  ok: false,
259055
259092
  response: new Response("Unauthorized", { status: 401 }),
259056
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;
259057
259125
 
259058
259126
  const validPrincipal = (principal) => {
259059
259127
  if (principal === null || typeof principal !== "object" || Array.isArray(principal)) return false;
@@ -259072,46 +259140,21 @@ export async function verifyActorConnection(request, env, actorName, room) {
259072
259140
  const token = request.headers.get(TOKEN_HEADER) ?? new URL(request.url).searchParams.get("token");
259073
259141
  if (
259074
259142
  typeof publicKey !== "string" || !publicKey ||
259075
- typeof scriptId !== "string" || !scriptId ||
259076
- typeof token !== "string" || token.length > 4096
259143
+ typeof scriptId !== "string" || !scriptId
259077
259144
  ) return unauthorized();
259078
259145
 
259079
- const parts = token.split(".");
259080
- if (parts.length !== 3) return unauthorized();
259081
259146
  try {
259082
- const header = decodeJsonSegment(parts[0]);
259083
- const claims = decodeJsonSegment(parts[1]);
259084
- if (header?.alg !== "EdDSA" || (header.typ !== undefined && header.typ !== "JWT")) {
259085
- return unauthorized();
259086
- }
259087
- const key = await crypto.subtle.importKey(
259088
- "raw",
259089
- decodeSegment(publicKey),
259090
- { name: "Ed25519" },
259091
- false,
259092
- ["verify"],
259093
- );
259094
- const validSignature = await crypto.subtle.verify(
259095
- { name: "Ed25519" },
259096
- key,
259097
- decodeSegment(parts[2]),
259098
- new TextEncoder().encode(parts[0] + "." + parts[1]),
259099
- );
259100
- if (!validSignature) return unauthorized();
259147
+ const claims = await verifiedClaims(token, publicKey);
259148
+ if (!claims) return unauthorized();
259101
259149
 
259102
259150
  const now = Math.floor(Date.now() / 1000);
259103
- const times = [claims.iat, claims.nbf, claims.exp];
259104
- if (!times.every(Number.isInteger)) return unauthorized();
259105
259151
  if (
259106
259152
  claims.iss !== "base44" ||
259107
259153
  claims.aud !== "base44-actor-connect" ||
259108
259154
  claims.purpose !== "actor-connect" ||
259109
259155
  claims.v !== 1 ||
259110
259156
  typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259111
- claims.iat > now + CLOCK_SKEW_SECONDS ||
259112
- claims.nbf > now + CLOCK_SKEW_SECONDS ||
259113
- claims.exp < now - CLOCK_SKEW_SECONDS ||
259114
- claims.exp <= claims.iat || claims.exp - claims.iat > TOKEN_TTL_SECONDS ||
259157
+ !validTimes(claims, now, TOKEN_TTL_SECONDS) ||
259115
259158
  claims.app_id !== env.BASE44_APP_ID ||
259116
259159
  claims.actor_name !== actorName ||
259117
259160
  claims.actor_script_id !== scriptId ||
@@ -259141,6 +259184,75 @@ export function authorizedActorRequest(request, identity, actorName, room, runti
259141
259184
  headers.set("base44-functions-version", runtimeMode === "prod" ? "prod" : "preview");
259142
259185
  return new Request(new Request(url.toString(), request), { headers });
259143
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
+ }
259144
259256
  `;
259145
259257
  }
259146
259258
  function buildPrelude() {
@@ -259161,7 +259273,13 @@ function buildEntryWrapper(doClassName, userEntry) {
259161
259273
  import "./${ACTOR_PRELUDE_FILENAME}";
259162
259274
  import Base44UserActor from ${JSON.stringify(userImport)};
259163
259275
  import { runWithWorkerEnvironment as _b44Run } from ${JSON.stringify(RUNTIME_CONTEXT_SPECIFIER)};
259164
- import { authorizedActorRequest as _b44AuthorizedActorRequest, verifyActorConnection as _b44VerifyActorConnection } from "./${ACTOR_AUTH_FILENAME}";
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}";
259165
259283
 
259166
259284
  const _b44ActorState = new WeakMap();
259167
259285
  const _b44RunWithActorEnvironment = (ctx, env, runtimeEnv, callback) => _b44Run({
@@ -259191,6 +259309,11 @@ const _b44RunActor = (actor, request, callback) => {
259191
259309
  state.runtimeEnv = runtimeEnv;
259192
259310
  return _b44RunWithActorEnvironment(state.ctx, state.env, runtimeEnv, callback);
259193
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
+ };
259194
259317
 
259195
259318
  export class ${doClassName} extends Base44UserActor {
259196
259319
  // Read by the shim's service-token exchange: the assertion's actor_name claim
@@ -259203,6 +259326,11 @@ export class ${doClassName} extends Base44UserActor {
259203
259326
  }
259204
259327
 
259205
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
+ }
259206
259334
  return _b44RunActor(this, request, () => super.fetch(request));
259207
259335
  }
259208
259336
 
@@ -259236,15 +259364,22 @@ export default {
259236
259364
  const parts = url.pathname.split("/");
259237
259365
  const direct = parts[1] === "rooms" && parts.length === 3;
259238
259366
  const legacy = parts[1] === "parties" && parts.length === 4;
259239
- if (direct || legacy) {
259367
+ const event = request.method === "POST" && parts[1] === "rooms" && parts.length === 4 && parts[3] === "events";
259368
+ if (direct || legacy || event) {
259240
259369
  // Decode the room: the token was verified against the decoded instance id,
259241
259370
  // so an escaped room must map to the same Durable Object.
259242
- const namespace = direct ? "${doClassName}" : parts[2];
259243
- const encodedRoom = direct ? parts[2] : parts[3];
259371
+ const namespace = legacy ? parts[2] : "${doClassName}";
259372
+ const encodedRoom = legacy ? parts[3] : parts[2];
259244
259373
  let room;
259245
259374
  try { room = decodeURIComponent(encodedRoom); } catch { return new Response("Invalid room", { status: 400 }); }
259246
259375
  let actorRequest = request;
259247
- if (direct || typeof env.BASE44_ACTOR_PUBLIC_KEY === "string") {
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") {
259248
259383
  const verification = await _b44VerifyActorConnection(request, env, "${doClassName}", room);
259249
259384
  if (!verification.ok) return verification.response;
259250
259385
  actorRequest = _b44AuthorizedActorRequest(
@@ -266128,10 +266263,18 @@ function getSiteInstallCommand() {
266128
266263
  }
266129
266264
 
266130
266265
  // src/cli/commands/site/open.ts
266266
+ var isAppNotPublished = (error) => error instanceof ApiError && error.statusCode === 404;
266267
+ async function getPublishedSiteUrl() {
266268
+ try {
266269
+ return await getSiteUrl();
266270
+ } catch (error) {
266271
+ throw isAppNotPublished(error) ? new AppNotPublishedError : error;
266272
+ }
266273
+ }
266131
266274
  async function openAction({
266132
266275
  isNonInteractive
266133
266276
  }) {
266134
- const siteUrl = await getSiteUrl();
266277
+ const siteUrl = await getPublishedSiteUrl();
266135
266278
  if (!isNonInteractive) {
266136
266279
  await open_default(siteUrl);
266137
266280
  }
@@ -270538,19 +270681,6 @@ async function createDevServer(options) {
270538
270681
  return { port, server, shutdown };
270539
270682
  }
270540
270683
 
270541
- // src/core/project/app-base-url.ts
270542
- var appPreviewUrl = (appId) => `https://preview--${appId}.base44.app`;
270543
- var isAppNotPublished = (error) => error instanceof ApiError && error.statusCode === 404;
270544
- async function resolveAppBaseUrl(appId) {
270545
- try {
270546
- return await getSiteUrl();
270547
- } catch (error) {
270548
- if (isAppNotPublished(error))
270549
- return appPreviewUrl(appId);
270550
- throw error;
270551
- }
270552
- }
270553
-
270554
270684
  // src/cli/commands/dev.ts
270555
270685
  function localServerUrl(port) {
270556
270686
  return `http://localhost:${port}`;
@@ -270589,7 +270719,7 @@ async function remoteDevAction(app) {
270589
270719
  if (!site) {
270590
270720
  throw new ConfigInvalidError("base44 dev --remote serves the frontend against the production backend, but this project has no site.serveCommand in base44/config.jsonc.");
270591
270721
  }
270592
- const appBaseUrl = await resolveAppBaseUrl(app.id);
270722
+ const appBaseUrl = await getSiteUrl();
270593
270723
  const runner = createServeCommandRunner({
270594
270724
  ...site,
270595
270725
  appId: app.id,
@@ -270710,6 +270840,17 @@ function inheritedEnv() {
270710
270840
  }
270711
270841
  return env;
270712
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
+ }
270713
270854
  async function runScript(options) {
270714
270855
  const { appId, code, local, privileged, dataEnv, serviceToken, sdkVersion } = options;
270715
270856
  verifyDenoInstalled("to run scripts with exec");
@@ -275055,4 +275196,4 @@ export {
275055
275196
  runCLI
275056
275197
  };
275057
275198
 
275058
- //# debugId=5897AB86D8A0BE5164756E2164756E21
275199
+ //# debugId=0543661A2E4EC46564756E2164756E21