@base44-preview/cli 0.3.3-pr.700.e2948cc → 0.3.4-pr.702.1894d21

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
@@ -230833,7 +230833,8 @@ var TestOverridesSchema = object({
230833
230833
  projectRoot: string2()
230834
230834
  }).optional(),
230835
230835
  latestVersion: string2().nullable().optional(),
230836
- claudeBin: string2().optional()
230836
+ claudeBin: string2().optional(),
230837
+ skipRetryWait: boolean2().optional()
230837
230838
  });
230838
230839
 
230839
230840
  // src/core/config.ts
@@ -239446,7 +239447,7 @@ import { join as join13 } from "node:path";
239446
239447
  // package.json
239447
239448
  var package_default = {
239448
239449
  name: "base44",
239449
- version: "0.3.3",
239450
+ version: "0.3.4",
239450
239451
  description: "Base44 CLI - Unified interface for managing Base44 applications",
239451
239452
  type: "module",
239452
239453
  bin: {
@@ -256508,6 +256509,14 @@ var TickLoop = class {
256508
256509
  };
256509
256510
 
256510
256511
  // src/shim/actor.ts
256512
+ var ActorError = class extends Error {
256513
+ constructor(status, message) {
256514
+ super(message);
256515
+ this.status = status;
256516
+ this.name = "ActorError";
256517
+ }
256518
+ status;
256519
+ };
256511
256520
  var SUPERSEDED_PREFIX = "__superseded__:";
256512
256521
  function buildConn(ws, identity) {
256513
256522
  return {
@@ -256842,40 +256851,59 @@ var Actor = class _Actor extends Server {
256842
256851
  }
256843
256852
  handleWake(_key) {
256844
256853
  }
256845
- static parseRequestIdentity(value) {
256854
+ /** Methods a caller may run on this room, as \`base44.actors.<Name>(room).<method>(args)\`.
256855
+ * Nothing else is callable. Each is called as \`method(args, { identity, request })\`;
256856
+ * check \`identity\` before acting: a client can call any room it can name. */
256857
+ static callable;
256858
+ static NOT_CALLABLE = /^(?:handle[A-Z]|on[A-Z]|_)|^(?:constructor|fetch|alarm|setName|broadcast|schedule|cancelSchedule|getConnections|webSocket[A-Z].*)$/;
256859
+ static CALLER_AUTHORIZATION_HEADER = "X-Base44-Actor-Caller-Authorization";
256860
+ static parseCallIdentity(value) {
256846
256861
  if (value === '{"type":"service"}') return Object.freeze({ type: "service" });
256847
256862
  return _Actor.parseIdentity(value);
256848
256863
  }
256849
256864
  // Called by the generated wrapper for a verified POST .../requests; never user-facing.
256850
- async _b44ActorRequest(request) {
256865
+ async _b44ActorCall(request) {
256851
256866
  const room = request.headers.get("x-partykit-room");
256852
256867
  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));
256868
+ const identity = _Actor.parseCallIdentity(request.headers.get(_Actor.IDENTITY_HEADER));
256857
256869
  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
- }
256870
+ let call;
256871
+ try {
256872
+ call = JSON.parse(await request.text());
256873
+ } catch {
256874
+ return Response.json({ message: "Invalid call" }, { status: 400 });
256875
+ }
256876
+ const name = call?.method;
256877
+ const callable = this.constructor.callable;
256878
+ if (typeof name !== "string" || !Array.isArray(callable) || !callable.includes(name) || _Actor.NOT_CALLABLE.test(name) || typeof this[name] !== "function") {
256879
+ return Response.json({ message: \`No callable method "\${String(name)}"\` }, { status: 404 });
256880
+ }
256881
+ const headers = new Headers({
256882
+ "Content-Type": "application/json",
256883
+ "Base44-App-Id": String(this._b44Env.BASE44_APP_ID ?? ""),
256884
+ "Base44-Api-Url": String(this._b44Env.BASE44_API_URL ?? ""),
256885
+ "Base44-Functions-Version": String(this._b44Env.BASE44_FUNCTIONS_VERSION ?? "")
256886
+ });
256887
+ const callerAuthorization = request.headers.get(_Actor.CALLER_AUTHORIZATION_HEADER);
256888
+ if (callerAuthorization) headers.set("Authorization", callerAuthorization);
256889
+ const forMethod = new Request(
256890
+ \`https://actor.base44/rooms/\${encodeURIComponent(this.name)}/methods/\${encodeURIComponent(name)}\`,
256891
+ { method: "POST", headers, body: JSON.stringify(call.args ?? null) }
256865
256892
  );
256866
256893
  let response;
256867
256894
  try {
256868
- response = await this.handleRequest(forHandler, { identity });
256895
+ const result = await this[name](call.args, { identity, request: forMethod });
256896
+ response = result === void 0 ? new Response(null, { status: 204 }) : Response.json(result);
256869
256897
  } catch (err) {
256870
- console.error("Actor.handleRequest threw:", err);
256871
- response = new Response("Actor request failed", { status: 500 });
256898
+ const status = err?.status;
256899
+ if (typeof status === "number" && status >= 400 && status < 500) {
256900
+ response = Response.json({ message: err.message }, { status });
256901
+ } else {
256902
+ console.error(\`Actor.\${name} threw:\`, err);
256903
+ response = Response.json({ message: "Actor method failed" }, { status: 500 });
256904
+ }
256872
256905
  }
256873
256906
  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
256907
  return response;
256880
256908
  }
256881
256909
  async schedule(key, at) {
@@ -257027,6 +257055,7 @@ var Actor = class _Actor extends Server {
257027
257055
  };
257028
257056
  export {
257029
257057
  Actor,
257058
+ ActorError,
257030
257059
  routePartykitRequest
257031
257060
  };
257032
257061
  `,
@@ -258618,7 +258647,7 @@ var TELEMETRY_PATCH = [
258618
258647
  var TELEMETRY_STORE_FIELDS = "reqId: crypto.randomUUID(), respondedAt: null, inflight: new Map(), inflightTotal: 0, hadRejection: false, hadNonOk: false, logBudget: 5";
258619
258648
 
258620
258649
  // ../functions-compiler/src/version.ts
258621
- var COMPILER_VERSION = "0.3.0";
258650
+ var COMPILER_VERSION = "0.4.0";
258622
258651
 
258623
258652
  // ../functions-compiler/src/worker-entry.ts
258624
258653
  function denoShimSource() {
@@ -259118,6 +259147,7 @@ function buildActorAuth() {
259118
259147
  const TOKEN_HEADER = "X-Base44-Actor-Token";
259119
259148
  const IDENTITY_HEADER = "X-Base44-Actor-Identity";
259120
259149
  const REQUEST_TOKEN_HEADER = "X-Base44-Actor-Request-Token";
259150
+ const CALLER_AUTHORIZATION_HEADER = "X-Base44-Actor-Caller-Authorization";
259121
259151
  const CLOCK_SKEW_SECONDS = 30;
259122
259152
  const TOKEN_TTL_SECONDS = 300;
259123
259153
  const REQUEST_TOKEN_TTL_SECONDS = 60;
@@ -259240,11 +259270,12 @@ const sha256 = async (bytes) => {
259240
259270
  return btoa(String.fromCharCode(...digest)).replace(/\\+/g, "-").replace(/\\//g, "_").replace(/=+$/, "");
259241
259271
  };
259242
259272
 
259243
- // A request the backend relays into one room for a caller it authenticated. Same
259273
+ // A method call the backend relays into one room for a caller it authenticated. Same
259244
259274
  // 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.
259275
+ // the other. The token is bound to the body and to the caller's forwarded
259276
+ // credential, so a leaked token can carry neither another call nor another caller.
259277
+ // 401 is a token this key did not mint, that has lapsed or whose hashes don't match;
259278
+ // 403 is a good token for another app, actor, script, room or runtime.
259248
259279
  export async function verifyActorRequest(request, env, actorName, room) {
259249
259280
  const publicKey = env.BASE44_ACTOR_PUBLIC_KEY;
259250
259281
  const scriptId = env.BASE44_ACTOR_SCRIPT_ID;
@@ -259264,6 +259295,7 @@ export async function verifyActorRequest(request, env, actorName, room) {
259264
259295
  typeof claims.jti !== "string" || !claims.jti || claims.jti.length > 64 ||
259265
259296
  !validTimes(claims, now, REQUEST_TOKEN_TTL_SECONDS) ||
259266
259297
  typeof claims.body_sha256 !== "string" ||
259298
+ !(claims.caller_token_sha256 === null || typeof claims.caller_token_sha256 === "string") ||
259267
259299
  !validRequestPrincipal(claims.principal)
259268
259300
  ) return unauthorized();
259269
259301
  if (
@@ -259277,11 +259309,19 @@ export async function verifyActorRequest(request, env, actorName, room) {
259277
259309
  const body = new Uint8Array(await request.arrayBuffer());
259278
259310
  if (body.length > REQUEST_MAX_BYTES) return refused(413, "Request too large");
259279
259311
  if (await sha256(body) !== claims.body_sha256) return unauthorized();
259312
+ const callerAuthorization = request.headers.get(CALLER_AUTHORIZATION_HEADER);
259313
+ if (callerAuthorization === null) {
259314
+ if (claims.caller_token_sha256 !== null) return unauthorized();
259315
+ } else if (
259316
+ callerAuthorization.length > 8192 ||
259317
+ await sha256(new TextEncoder().encode(callerAuthorization)) !== claims.caller_token_sha256
259318
+ ) return unauthorized();
259280
259319
  return {
259281
259320
  ok: true,
259282
259321
  identity: Object.freeze({ ...claims.principal }),
259283
259322
  runtimeMode: claims.runtime_mode,
259284
259323
  body,
259324
+ callerAuthorization,
259285
259325
  };
259286
259326
  } catch {
259287
259327
  return unauthorized();
@@ -259290,7 +259330,8 @@ export async function verifyActorRequest(request, env, actorName, room) {
259290
259330
 
259291
259331
  // Into the room as POST /parties/<actor>/<room>/requests: a path no client route
259292
259332
  // 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.
259333
+ // the path), so the Durable Object can trust the shape and its identity and caller
259334
+ // headers.
259294
259335
  export function actorRequestToRoom(request, actorName, room, verified) {
259295
259336
  const url = new URL(request.url);
259296
259337
  url.search = "";
@@ -259301,6 +259342,7 @@ export function actorRequestToRoom(request, actorName, room, verified) {
259301
259342
  "Content-Type": request.headers.get("Content-Type") ?? "application/json",
259302
259343
  [IDENTITY_HEADER]: JSON.stringify(verified.identity),
259303
259344
  "base44-functions-version": verified.runtimeMode,
259345
+ ...(verified.callerAuthorization === null ? {} : { [CALLER_AUTHORIZATION_HEADER]: verified.callerAuthorization }),
259304
259346
  },
259305
259347
  body: verified.body,
259306
259348
  });
@@ -259377,10 +259419,10 @@ export class ${doClassName} extends Base44UserActor {
259377
259419
  }
259378
259420
 
259379
259421
  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.
259422
+ // Ahead of the user's own fetch override: a relayed call reaches the room only
259423
+ // through the shim, which runs a callable method with the verified identity.
259382
259424
  if (_b44IsActorRequest(request)) {
259383
- return _b44RunActor(this, request, () => this._b44ActorRequest(request));
259425
+ return _b44RunActor(this, request, () => this._b44ActorCall(request));
259384
259426
  }
259385
259427
  return _b44RunActor(this, request, () => super.fetch(request));
259386
259428
  }
@@ -265302,11 +265344,14 @@ var SessionImportResponseSchema = object({
265302
265344
  var ErrorEnvelopeSchema = object({
265303
265345
  error: object({
265304
265346
  code: string2().optional(),
265347
+ message: string2().optional(),
265305
265348
  details: object({ branch_name: string2(), branch_url: string2() }).partial().optional()
265306
265349
  })
265307
265350
  });
265308
265351
  var NETWORK_BLOCKED = "Your Claude cloud environment can't reach Base44 yet. In the environment's settings, open Network access, add `app.base44.com` to Allowed domains, and try again.";
265309
- function messageFor(status, code, details, viaToken) {
265352
+ function messageFor(status, code, details, viaToken, serverMessage) {
265353
+ if (code === "authority_unavailable" && serverMessage)
265354
+ return serverMessage;
265310
265355
  if (code === "branch_exists" && details?.branch_url) {
265311
265356
  return `Base Code already has ${details.branch_name ?? "a branch for this session"}. Open it: ${new URL(details.branch_url, getBase44ApiUrl())}`;
265312
265357
  }
@@ -265350,9 +265395,9 @@ async function toImportError(error, viaToken) {
265350
265395
  const { status } = error.response;
265351
265396
  const fallback = await ApiError.fromHttpError(error, "importing session");
265352
265397
  const envelope = ErrorEnvelopeSchema.safeParse(fallback.responseBody);
265353
- const { code, details } = envelope.success ? envelope.data.error : {};
265398
+ const { code, details, message } = envelope.success ? envelope.data.error : {};
265354
265399
  const blocked = process.env.CLAUDE_CODE_REMOTE && status === 403 && typeof fallback.responseBody !== "object";
265355
- const known = blocked ? NETWORK_BLOCKED : messageFor(status, code, details, viaToken);
265400
+ const known = blocked ? NETWORK_BLOCKED : messageFor(status, code, details, viaToken, message);
265356
265401
  return new ApiError(known ?? fallback.message, {
265357
265402
  statusCode: status,
265358
265403
  requestUrl: error.request.url,
@@ -265361,10 +265406,29 @@ async function toImportError(error, viaToken) {
265361
265406
  hints: known ? [] : fallback.hints
265362
265407
  });
265363
265408
  }
265409
+ var MAX_RETRIES = 3;
265410
+ var MAX_TOTAL_WAIT_SECONDS = 600;
265411
+ async function retryDelay(error) {
265412
+ if (!(error instanceof HTTPError))
265413
+ return;
265414
+ const { status, headers } = error.response;
265415
+ if (status !== 503 && status !== 429)
265416
+ return;
265417
+ const body = await error.response.clone().json().catch(() => {
265418
+ return;
265419
+ });
265420
+ const code = ErrorEnvelopeSchema.safeParse(body).data?.error.code;
265421
+ if (!(status === 503 && code === "authority_unavailable") && !(status === 429 && code === "rate_limited")) {
265422
+ return;
265423
+ }
265424
+ const seconds = Number(headers.get("Retry-After") ?? Number.NaN);
265425
+ return Number.isFinite(seconds) && seconds >= 0 ? seconds : 60;
265426
+ }
265364
265427
  async function uploadSession(appId, content, {
265365
265428
  token,
265366
265429
  sourceBranch,
265367
- artifacts = []
265430
+ artifacts = [],
265431
+ onRetry
265368
265432
  } = {}) {
265369
265433
  const form = new FormData;
265370
265434
  form.append("file", new Blob([content]), "session.jsonl");
@@ -265380,23 +265444,41 @@ async function uploadSession(appId, content, {
265380
265444
  }))));
265381
265445
  }
265382
265446
  const idempotencyKey = randomUUID5();
265447
+ const post = () => token ? distribution_default.post(new URL(`/api/apps/${appId}/imported/session-imports`, getBase44ApiUrl()), {
265448
+ body: form,
265449
+ headers: {
265450
+ Authorization: `Bearer ${token}`,
265451
+ "User-Agent": "Base44 CLI",
265452
+ "Idempotency-Key": idempotencyKey
265453
+ },
265454
+ timeout: 180000
265455
+ }) : getAppClient().post("imported/session-imports", {
265456
+ body: form,
265457
+ headers: { "Idempotency-Key": idempotencyKey },
265458
+ timeout: 180000
265459
+ });
265383
265460
  let response;
265384
- try {
265385
- response = token ? await distribution_default.post(new URL(`/api/apps/${appId}/imported/session-imports`, getBase44ApiUrl()), {
265386
- body: form,
265387
- headers: {
265388
- Authorization: `Bearer ${token}`,
265389
- "User-Agent": "Base44 CLI",
265390
- "Idempotency-Key": idempotencyKey
265391
- },
265392
- timeout: 180000
265393
- }) : await getAppClient().post("imported/session-imports", {
265394
- body: form,
265395
- headers: { "Idempotency-Key": idempotencyKey },
265396
- timeout: 180000
265397
- });
265398
- } catch (error) {
265399
- throw await toImportError(error, Boolean(token));
265461
+ let waited = 0;
265462
+ for (let attempt = 1;; attempt++) {
265463
+ try {
265464
+ response = await post();
265465
+ break;
265466
+ } catch (error) {
265467
+ const seconds = await retryDelay(error);
265468
+ if (seconds === undefined || attempt > MAX_RETRIES || waited + seconds > MAX_TOTAL_WAIT_SECONDS) {
265469
+ throw await toImportError(error, Boolean(token));
265470
+ }
265471
+ waited += seconds;
265472
+ onRetry?.({
265473
+ status: error.response.status,
265474
+ seconds,
265475
+ attempt: attempt + 1,
265476
+ attempts: MAX_RETRIES + 1
265477
+ });
265478
+ if (!getTestOverrides()?.skipRetryWait) {
265479
+ await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
265480
+ }
265481
+ }
265400
265482
  }
265401
265483
  const result = SessionImportResponseSchema.safeParse(await response.json());
265402
265484
  if (!result.success) {
@@ -265979,10 +266061,11 @@ async function importAction(ctx, link, options, command) {
265979
266061
  for (const { fileName, reason } of skipped) {
265980
266062
  ctx.log.warn(`Not sending ${fileName}: ${reason}.`);
265981
266063
  }
265982
- const imported = await ctx.runTask("Importing session", () => uploadSession(appId, content, {
266064
+ const imported = await ctx.runTask("Importing session", (updateMessage) => uploadSession(appId, content, {
265983
266065
  token: options.token,
265984
266066
  sourceBranch: git?.branch,
265985
- artifacts
266067
+ artifacts,
266068
+ onRetry: ({ status, seconds, attempt, attempts }) => updateMessage(`${status === 503 ? "GitHub is rate-limiting access checks" : "Too many imports"}. Retrying in ${seconds}s (attempt ${attempt} of ${attempts})…`)
265986
266069
  }));
265987
266070
  const url = `${getBase44ApiUrl()}${imported.branchUrl}`;
265988
266071
  const { importedArtifacts: saved, skippedArtifacts: refused } = imported;
@@ -275266,4 +275349,4 @@ export {
275266
275349
  runCLI
275267
275350
  };
275268
275351
 
275269
- //# debugId=B98A0F7103A0C01B64756E2164756E21
275352
+ //# debugId=9D8063E65A56942D64756E2164756E21