@base44-preview/cli 0.3.3-pr.700.e2948cc → 0.3.4-pr.701.87b0681

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
@@ -228529,6 +228529,20 @@ class AppNotPublishedError extends UserError {
228529
228529
  });
228530
228530
  }
228531
228531
  }
228532
+
228533
+ class DeploymentExistsError extends UserError {
228534
+ code = "DEPLOYMENT_EXISTS";
228535
+ constructor(gitHash, options) {
228536
+ super(`Commit ${gitHash.slice(0, 12)} already has a different build, so this one was not deployed`, {
228537
+ hints: options?.hints ?? [
228538
+ {
228539
+ message: "Run the same command again with --overwrite to replace that build, or commit your changes and deploy the new commit"
228540
+ }
228541
+ ],
228542
+ cause: options?.cause
228543
+ });
228544
+ }
228545
+ }
228532
228546
  var MAX_RESPONSE_TEXT_CHARS = 500;
228533
228547
  async function readResponseText(response) {
228534
228548
  try {
@@ -236613,6 +236627,9 @@ var DeployResponseSchema = object({
236613
236627
  var PublishedUrlResponseSchema = object({
236614
236628
  url: string2()
236615
236629
  });
236630
+ var DeploymentExistsRefusalSchema = object({
236631
+ error: object({ code: literal("deployment_already_exists") })
236632
+ });
236616
236633
  var CreateDeploymentResponseSchema = object({
236617
236634
  deployment_id: string2(),
236618
236635
  session_id: string2(),
@@ -239446,7 +239463,7 @@ import { join as join13 } from "node:path";
239446
239463
  // package.json
239447
239464
  var package_default = {
239448
239465
  name: "base44",
239449
- version: "0.3.3",
239466
+ version: "0.3.4",
239450
239467
  description: "Base44 CLI - Unified interface for managing Base44 applications",
239451
239468
  type: "module",
239452
239469
  bin: {
@@ -239713,7 +239730,11 @@ async function createDeployment(request) {
239713
239730
  timeout: 120000
239714
239731
  });
239715
239732
  } catch (error) {
239716
- throw await ApiError.fromHttpError(error, "creating deployment");
239733
+ const apiError = await ApiError.fromHttpError(error, "creating deployment");
239734
+ if (apiError.statusCode === 409 && DeploymentExistsRefusalSchema.safeParse(apiError.responseBody).success) {
239735
+ throw new DeploymentExistsError(request.git_hash, { cause: apiError });
239736
+ }
239737
+ throw apiError;
239717
239738
  }
239718
239739
  const result = CreateDeploymentResponseSchema.safeParse(await response.json());
239719
239740
  if (!result.success) {
@@ -240350,7 +240371,7 @@ async function putPresignedBody(upload, body) {
240350
240371
  // src/core/site/deployment.ts
240351
240372
  var NO_ASSETS = { manifest: {}, filesByHash: new Map };
240352
240373
  async function deployToDeployments(options) {
240353
- const { projectRoot, outputDir, gitHash, concurrency, progress } = options;
240374
+ const { projectRoot, outputDir, gitHash, concurrency, overwrite, progress } = options;
240354
240375
  const worker = await resolveWorkerBuild(projectRoot, progress);
240355
240376
  const assetsDir = worker ? worker.assetsDir : outputDir;
240356
240377
  const assets = assetsDir ? await buildAssetManifest(assetsDir, getAppContext().id) : NO_ASSETS;
@@ -240360,7 +240381,8 @@ async function deployToDeployments(options) {
240360
240381
  const created = await createDeployment({
240361
240382
  git_hash: gitHash,
240362
240383
  config: worker?.config,
240363
- asset_manifest: assets.manifest
240384
+ asset_manifest: assets.manifest,
240385
+ overwrite
240364
240386
  });
240365
240387
  const completionJwt = await uploadDeploymentAssets(created.assetUploads, assets, { concurrency, progress });
240366
240388
  const completion = worker ? { kind: "worker", modules: worker.modules, completionJwt } : await resolveStaticCompletion(assetsDir, assets, created.indexHtmlStaged);
@@ -247063,6 +247085,7 @@ async function shipCommit(projectRoot, outputDir, gitHash, options) {
247063
247085
  projectRoot,
247064
247086
  outputDir,
247065
247087
  gitHash,
247088
+ overwrite: options?.overwrite,
247066
247089
  progress: {
247067
247090
  onWarning: (message) => options?.onSiteProgress?.(message),
247068
247091
  onAssets: ({ totalAssets, newAssets }) => options?.onSiteProgress?.(`Found ${totalAssets} static assets (${newAssets} new)`)
@@ -252183,6 +252206,7 @@ ${summaryLines.join(`
252183
252206
  let actorCompleted = 0;
252184
252207
  const result = await deployAll(projectData, {
252185
252208
  gitHash: options.gitHash,
252209
+ overwrite: options.overwrite,
252186
252210
  onSiteProgress: (message) => {
252187
252211
  log.message(theme.styles.dim(message));
252188
252212
  },
@@ -252224,7 +252248,7 @@ ${summaryLines.join(`
252224
252248
  return { outroMessage: "App deployed successfully" };
252225
252249
  }
252226
252250
  function getDeployCommand3() {
252227
- return new Base44Command("deploy").description("Deploy all project resources (entities, functions, actors, agents, connectors, and site)").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").addOption(new Option2("--git-hash <hash>", "Deploy by the commit the build came from, through the deployments API").argParser(parseGitHash)).action(deployAction);
252251
+ return new Base44Command("deploy").description("Deploy all project resources (entities, functions, actors, agents, connectors, and site)").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").addOption(new Option2("--git-hash <hash>", "Deploy by the commit the build came from, through the deployments API").argParser(parseGitHash)).option("--overwrite", "Replace the build the commit already has (with --git-hash)").action(deployAction);
252228
252252
  }
252229
252253
  async function handleOAuthConnectors(connectorResults, isNonInteractive, options, log) {
252230
252254
  const needsOAuth = filterPendingOAuth(connectorResults);
@@ -256508,6 +256532,14 @@ var TickLoop = class {
256508
256532
  };
256509
256533
 
256510
256534
  // src/shim/actor.ts
256535
+ var ActorError = class extends Error {
256536
+ constructor(status, message) {
256537
+ super(message);
256538
+ this.status = status;
256539
+ this.name = "ActorError";
256540
+ }
256541
+ status;
256542
+ };
256511
256543
  var SUPERSEDED_PREFIX = "__superseded__:";
256512
256544
  function buildConn(ws, identity) {
256513
256545
  return {
@@ -256842,40 +256874,59 @@ var Actor = class _Actor extends Server {
256842
256874
  }
256843
256875
  handleWake(_key) {
256844
256876
  }
256845
- static parseRequestIdentity(value) {
256877
+ /** Methods a caller may run on this room, as \`base44.actors.<Name>(room).<method>(args)\`.
256878
+ * Nothing else is callable. Each is called as \`method(args, { identity, request })\`;
256879
+ * check \`identity\` before acting: a client can call any room it can name. */
256880
+ static callable;
256881
+ static NOT_CALLABLE = /^(?:handle[A-Z]|on[A-Z]|_)|^(?:constructor|fetch|alarm|setName|broadcast|schedule|cancelSchedule|getConnections|webSocket[A-Z].*)$/;
256882
+ static CALLER_AUTHORIZATION_HEADER = "X-Base44-Actor-Caller-Authorization";
256883
+ static parseCallIdentity(value) {
256846
256884
  if (value === '{"type":"service"}') return Object.freeze({ type: "service" });
256847
256885
  return _Actor.parseIdentity(value);
256848
256886
  }
256849
256887
  // Called by the generated wrapper for a verified POST .../requests; never user-facing.
256850
- async _b44ActorRequest(request) {
256888
+ async _b44ActorCall(request) {
256851
256889
  const room = request.headers.get("x-partykit-room");
256852
256890
  if (room) await this.setName(room);
256853
- if (typeof this.handleRequest !== "function") {
256854
- return new Response("This actor does not accept requests", { status: 404 });
256855
- }
256856
- const identity = _Actor.parseRequestIdentity(request.headers.get(_Actor.IDENTITY_HEADER));
256891
+ const identity = _Actor.parseCallIdentity(request.headers.get(_Actor.IDENTITY_HEADER));
256857
256892
  if (!identity) return new Response("Unauthorized", { status: 401 });
256858
- const forHandler = new Request(
256859
- \`https://actor.base44/rooms/\${encodeURIComponent(this.name)}/requests\`,
256860
- {
256861
- method: "POST",
256862
- headers: { "Content-Type": request.headers.get("Content-Type") ?? "application/json" },
256863
- body: await request.arrayBuffer()
256864
- }
256893
+ let call;
256894
+ try {
256895
+ call = JSON.parse(await request.text());
256896
+ } catch {
256897
+ return Response.json({ message: "Invalid call" }, { status: 400 });
256898
+ }
256899
+ const name = call?.method;
256900
+ const callable = this.constructor.callable;
256901
+ if (typeof name !== "string" || !Array.isArray(callable) || !callable.includes(name) || _Actor.NOT_CALLABLE.test(name) || typeof this[name] !== "function") {
256902
+ return Response.json({ message: \`No callable method "\${String(name)}"\` }, { status: 404 });
256903
+ }
256904
+ const headers = new Headers({
256905
+ "Content-Type": "application/json",
256906
+ "Base44-App-Id": String(this._b44Env.BASE44_APP_ID ?? ""),
256907
+ "Base44-Api-Url": String(this._b44Env.BASE44_API_URL ?? ""),
256908
+ "Base44-Functions-Version": String(this._b44Env.BASE44_FUNCTIONS_VERSION ?? "")
256909
+ });
256910
+ const callerAuthorization = request.headers.get(_Actor.CALLER_AUTHORIZATION_HEADER);
256911
+ if (callerAuthorization) headers.set("Authorization", callerAuthorization);
256912
+ const forMethod = new Request(
256913
+ \`https://actor.base44/rooms/\${encodeURIComponent(this.name)}/methods/\${encodeURIComponent(name)}\`,
256914
+ { method: "POST", headers, body: JSON.stringify(call.args ?? null) }
256865
256915
  );
256866
256916
  let response;
256867
256917
  try {
256868
- response = await this.handleRequest(forHandler, { identity });
256918
+ const result = await this[name](call.args, { identity, request: forMethod });
256919
+ response = result === void 0 ? new Response(null, { status: 204 }) : Response.json(result);
256869
256920
  } catch (err) {
256870
- console.error("Actor.handleRequest threw:", err);
256871
- response = new Response("Actor request failed", { status: 500 });
256921
+ const status = err?.status;
256922
+ if (typeof status === "number" && status >= 400 && status < 500) {
256923
+ response = Response.json({ message: err.message }, { status });
256924
+ } else {
256925
+ console.error(\`Actor.\${name} threw:\`, err);
256926
+ response = Response.json({ message: "Actor method failed" }, { status: 500 });
256927
+ }
256872
256928
  }
256873
256929
  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
256930
  return response;
256880
256931
  }
256881
256932
  async schedule(key, at) {
@@ -257027,6 +257078,7 @@ var Actor = class _Actor extends Server {
257027
257078
  };
257028
257079
  export {
257029
257080
  Actor,
257081
+ ActorError,
257030
257082
  routePartykitRequest
257031
257083
  };
257032
257084
  `,
@@ -258618,7 +258670,7 @@ var TELEMETRY_PATCH = [
258618
258670
  var TELEMETRY_STORE_FIELDS = "reqId: crypto.randomUUID(), respondedAt: null, inflight: new Map(), inflightTotal: 0, hadRejection: false, hadNonOk: false, logBudget: 5";
258619
258671
 
258620
258672
  // ../functions-compiler/src/version.ts
258621
- var COMPILER_VERSION = "0.3.0";
258673
+ var COMPILER_VERSION = "0.4.0";
258622
258674
 
258623
258675
  // ../functions-compiler/src/worker-entry.ts
258624
258676
  function denoShimSource() {
@@ -259118,6 +259170,7 @@ function buildActorAuth() {
259118
259170
  const TOKEN_HEADER = "X-Base44-Actor-Token";
259119
259171
  const IDENTITY_HEADER = "X-Base44-Actor-Identity";
259120
259172
  const REQUEST_TOKEN_HEADER = "X-Base44-Actor-Request-Token";
259173
+ const CALLER_AUTHORIZATION_HEADER = "X-Base44-Actor-Caller-Authorization";
259121
259174
  const CLOCK_SKEW_SECONDS = 30;
259122
259175
  const TOKEN_TTL_SECONDS = 300;
259123
259176
  const REQUEST_TOKEN_TTL_SECONDS = 60;
@@ -259240,11 +259293,12 @@ const sha256 = async (bytes) => {
259240
259293
  return btoa(String.fromCharCode(...digest)).replace(/\\+/g, "-").replace(/\\//g, "_").replace(/=+$/, "");
259241
259294
  };
259242
259295
 
259243
- // A request the backend relays into one room for a caller it authenticated. Same
259296
+ // A method call the backend relays into one room for a caller it authenticated. Same
259244
259297
  // key as connection tokens, its own audience and purpose: neither is accepted as
259245
- // the other. The token is bound to the body, so a leaked token can't carry another.
259246
- // 401 is a token this key did not mint or that has lapsed; 403 is a good token for
259247
- // another app, actor, script, room or runtime.
259298
+ // the other. The token is bound to the body and to the caller's forwarded
259299
+ // credential, so a leaked token can carry neither another call nor another caller.
259300
+ // 401 is a token this key did not mint, that has lapsed or whose hashes don't match;
259301
+ // 403 is a good token for another app, actor, script, room or runtime.
259248
259302
  export async function verifyActorRequest(request, env, actorName, room) {
259249
259303
  const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
259250
259304
  const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
@@ -259264,6 +259318,7 @@ export async function verifyActorRequest(request, env, actorName, room) {
259264
259318
  typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259265
259319
  !validTimes(claims, now, REQUEST_TOKEN_TTL_SECONDS) ||
259266
259320
  typeof claims.body_sha256 !== "string" ||
259321
+ !(claims.caller_token_sha256 === null || typeof claims.caller_token_sha256 === "string") ||
259267
259322
  !validRequestPrincipal(claims.principal)
259268
259323
  ) return unauthorized();
259269
259324
  if (
@@ -259277,11 +259332,19 @@ export async function verifyActorRequest(request, env, actorName, room) {
259277
259332
  const body = new Uint8Array(await request.arrayBuffer());
259278
259333
  if (body.length > REQUEST_MAX_BYTES) return refused(413, "Request too large");
259279
259334
  if (await sha256(body) !== claims.body_sha256) return unauthorized();
259335
+ const callerAuthorization = request.headers.get(CALLER_AUTHORIZATION_HEADER);
259336
+ if (callerAuthorization === null) {
259337
+ if (claims.caller_token_sha256 !== null) return unauthorized();
259338
+ } else if (
259339
+ callerAuthorization.length > 8192 ||
259340
+ await sha256(new TextEncoder().encode(callerAuthorization)) !== claims.caller_token_sha256
259341
+ ) return unauthorized();
259280
259342
  return {
259281
259343
  ok: true,
259282
259344
  identity: Object.freeze({ ...claims.principal }),
259283
259345
  runtimeMode: claims.runtime_mode,
259284
259346
  body,
259347
+ callerAuthorization,
259285
259348
  };
259286
259349
  } catch {
259287
259350
  return unauthorized();
@@ -259290,7 +259353,8 @@ export async function verifyActorRequest(request, env, actorName, room) {
259290
259353
 
259291
259354
  // Into the room as POST /parties/<actor>/<room>/requests: a path no client route
259292
259355
  // 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 header.
259356
+ // the path), so the Durable Object can trust the shape and its identity and caller
259357
+ // headers.
259294
259358
  export function actorRequestToRoom(request, actorName, room, verified) {
259295
259359
  const url = new URL(request.url);
259296
259360
  url.search = "";
@@ -259301,6 +259365,7 @@ export function actorRequestToRoom(request, actorName, room, verified) {
259301
259365
  "Content-Type": request.headers.get("Content-Type") ?? "application/json",
259302
259366
  [IDENTITY_HEADER]: JSON.stringify(verified.identity),
259303
259367
  "base44-functions-version": verified.runtimeMode,
259368
+ ...(verified.callerAuthorization === null ? {} : { [CALLER_AUTHORIZATION_HEADER]: verified.callerAuthorization }),
259304
259369
  },
259305
259370
  body: verified.body,
259306
259371
  });
@@ -259377,10 +259442,10 @@ export class ${doClassName} extends Base44UserActor {
259377
259442
  }
259378
259443
 
259379
259444
  fetch(request) {
259380
- // Ahead of the user's own fetch override: a relayed request reaches the room
259381
- // only through the shim, which hands handleRequest the verified identity.
259445
+ // Ahead of the user's own fetch override: a relayed call reaches the room only
259446
+ // through the shim, which runs a callable method with the verified identity.
259382
259447
  if (_b44IsActorRequest(request)) {
259383
- return _b44RunActor(this, request, () => this._b44ActorRequest(request));
259448
+ return _b44RunActor(this, request, () => this._b44ActorCall(request));
259384
259449
  }
259385
259450
  return _b44RunActor(this, request, () => super.fetch(request));
259386
259451
  }
@@ -266059,6 +266124,7 @@ async function deployToDeploymentsApi(ctx, project, options) {
266059
266124
  outputDir,
266060
266125
  gitHash,
266061
266126
  concurrency: options.concurrency,
266127
+ overwrite: options.overwrite,
266062
266128
  progress: {
266063
266129
  onWarning: (message) => {
266064
266130
  warnings.push(message);
@@ -266110,7 +266176,7 @@ function siteOutputDir(project) {
266110
266176
  return resolve17(project.root, outputDirectory);
266111
266177
  }
266112
266178
  function getSiteDeployCommand() {
266113
- return new Base44Command("deploy").description("Deploy built site files to Base44 hosting").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").option("--publish", "Serve this build in production once it is deployed").addOption(new Option2("--git-hash <hash>", "Deploy by the commit the build came from, through the deployments API").argParser(parseGitHash)).addOption(new Option2("--concurrency <n>", "Parallel asset uploads").default(DEFAULT_UPLOAD_CONCURRENCY).argParser(parseConcurrency)).action(deployAction2);
266179
+ return new Base44Command("deploy").description("Deploy built site files to Base44 hosting").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").option("--publish", "Serve this build in production once it is deployed").option("--overwrite", "Replace the build the commit already has (with --git-hash)").addOption(new Option2("--git-hash <hash>", "Deploy by the commit the build came from, through the deployments API").argParser(parseGitHash)).addOption(new Option2("--concurrency <n>", "Parallel asset uploads").default(DEFAULT_UPLOAD_CONCURRENCY).argParser(parseConcurrency)).action(deployAction2);
266114
266180
  }
266115
266181
  function parseConcurrency(value) {
266116
266182
  const parsed = Number(value);
@@ -275266,4 +275332,4 @@ export {
275266
275332
  runCLI
275267
275333
  };
275268
275334
 
275269
- //# debugId=B98A0F7103A0C01B64756E2164756E21
275335
+ //# debugId=B97BC2F260368ED664756E2164756E21