@base44-preview/cli 0.1.32-pr.660.402dccb → 0.1.32-pr.662.1bdb1fe

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
@@ -253161,6 +253161,10 @@ var STATIC_EGRESS_ENABLED_ENV = "BASE44_STATIC_EGRESS_ENABLED";
253161
253161
  var STATIC_EGRESS_DIAGNOSTIC_LIMIT = 5;
253162
253162
  var staticEgressFetchInstalled = false;
253163
253163
  var staticEgressDiagnosticCount = 0;
253164
+ var dedicatedEgressResponses = /* @__PURE__ */ new WeakSet();
253165
+ function isDedicatedEgressResponse(response) {
253166
+ return dedicatedEgressResponses.has(response);
253167
+ }
253164
253168
  function inputKind(input) {
253165
253169
  if (typeof input === "string") return "string";
253166
253170
  return input instanceof URL ? "url" : "request";
@@ -253262,7 +253266,10 @@ function createRequestScopedStaticEgressFetch(originalFetch, readEnvironment) {
253262
253266
  return originalFetch(input, init);
253263
253267
  }
253264
253268
  logStaticEgressDecision("dedicated", input, binding, enableSecret);
253265
- return binding.fetch(input, init);
253269
+ return binding.fetch(input, init).then((response) => {
253270
+ dedicatedEgressResponses.add(response);
253271
+ return response;
253272
+ });
253266
253273
  };
253267
253274
  }
253268
253275
  function installStaticEgressFetch() {
@@ -253274,6 +253281,112 @@ function installStaticEgressFetch() {
253274
253281
  staticEgressFetchInstalled = true;
253275
253282
  }
253276
253283
 
253284
+ // src/edge-errors.ts
253285
+ var EDGE_ERRORS_HEADER = "X-B44-Edge-Errors";
253286
+ var MAX_EDGE_ERRORS = 5;
253287
+ var MAX_INSPECTED_BODY_BYTES = 8192;
253288
+ var BODY_READ_TIMEOUT_MS = 500;
253289
+ var PLAIN_TEXT_EDGE_ERROR = /^error code: (\\d{3,4})\\s*$/;
253290
+ var SAFE_VALUE = /^[\\x20-\\x7e]{1,253}$/;
253291
+ function safe(value) {
253292
+ return typeof value === "string" && SAFE_VALUE.test(value) ? value : void 0;
253293
+ }
253294
+ function parseEdgeErrorBody(body) {
253295
+ const plain = PLAIN_TEXT_EDGE_ERROR.exec(body);
253296
+ if (plain) return { code: Number(plain[1]) };
253297
+ if (!body.trimStart().startsWith("{")) return null;
253298
+ try {
253299
+ const json = JSON.parse(body);
253300
+ if (json === null || typeof json !== "object") return null;
253301
+ const fields = json;
253302
+ if (fields.cloudflare_error !== true || !Number.isInteger(fields.error_code)) return null;
253303
+ return {
253304
+ code: fields.error_code,
253305
+ name: safe(fields.error_name),
253306
+ category: safe(fields.error_category),
253307
+ zone: safe(fields.zone)
253308
+ };
253309
+ } catch {
253310
+ return null;
253311
+ }
253312
+ }
253313
+ async function readEdgeError(response) {
253314
+ if (response.status < 400) return null;
253315
+ const length = Number(response.headers.get("content-length"));
253316
+ if (!response.headers.get("cf-ray") || !(length > 0 && length <= MAX_INSPECTED_BODY_BYTES)) {
253317
+ return null;
253318
+ }
253319
+ let timer;
253320
+ try {
253321
+ const body = await Promise.race([
253322
+ response.clone().text(),
253323
+ new Promise((resolve2) => {
253324
+ timer = setTimeout(() => resolve2(null), BODY_READ_TIMEOUT_MS);
253325
+ })
253326
+ ]);
253327
+ return body === null ? null : parseEdgeErrorBody(body);
253328
+ } finally {
253329
+ clearTimeout(timer);
253330
+ }
253331
+ }
253332
+ function targetOrigin(input) {
253333
+ try {
253334
+ const raw = input instanceof URL ? input.href : typeof input === "string" ? input : input.url;
253335
+ return new URL(raw).origin;
253336
+ } catch {
253337
+ return null;
253338
+ }
253339
+ }
253340
+ async function recordEdgeError(input, response, startedAt) {
253341
+ const store = currentWorkerRuntimeContext();
253342
+ if (!store) return;
253343
+ const body = await readEdgeError(response);
253344
+ const target = targetOrigin(input);
253345
+ if (!body || !target) return;
253346
+ const record = store.edgeErrors ??= { errors: [], dropped: 0 };
253347
+ if (record.errors.length >= MAX_EDGE_ERRORS) {
253348
+ record.dropped += 1;
253349
+ return;
253350
+ }
253351
+ record.errors.push({
253352
+ ...body,
253353
+ target,
253354
+ status: response.status,
253355
+ ray: safe(response.headers.get("cf-ray")) ?? "",
253356
+ egress: isDedicatedEgressResponse(response) ? "dedicated" : "shared",
253357
+ elapsed_ms: Date.now() - startedAt
253358
+ });
253359
+ }
253360
+ function createEdgeErrorFetch(innerFetch) {
253361
+ return async (input, init) => {
253362
+ const startedAt = Date.now();
253363
+ const response = await innerFetch(input, init);
253364
+ try {
253365
+ await recordEdgeError(input, response, startedAt);
253366
+ } catch {
253367
+ }
253368
+ return response;
253369
+ };
253370
+ }
253371
+ var edgeErrorFetchInstalled = false;
253372
+ function installEdgeErrorFetch() {
253373
+ if (edgeErrorFetchInstalled) return;
253374
+ globalThis.fetch = createEdgeErrorFetch(globalThis.fetch.bind(globalThis));
253375
+ edgeErrorFetchInstalled = true;
253376
+ }
253377
+ function attachEdgeErrors(response) {
253378
+ const record = currentWorkerRuntimeContext()?.edgeErrors;
253379
+ if (!record || !(response instanceof Response)) return response;
253380
+ if (response.status === 101 || response.webSocket) return response;
253381
+ try {
253382
+ const wrapped = new Response(response.body, response);
253383
+ wrapped.headers.set(EDGE_ERRORS_HEADER, JSON.stringify(record));
253384
+ return wrapped;
253385
+ } catch {
253386
+ return response;
253387
+ }
253388
+ }
253389
+
253277
253390
  // src/static-egress-tcp-core.mjs
253278
253391
  function normalizeHost(host) {
253279
253392
  return host.toLowerCase().replace(/^\\[(.*)\\]$/, "$1").replace(/\\.$/, "");
@@ -253427,7 +253540,9 @@ function resolveHandler(functionName) {
253427
253540
  return handler;
253428
253541
  }
253429
253542
  export {
253543
+ attachEdgeErrors,
253430
253544
  getRegisteredHandler,
253545
+ installEdgeErrorFetch,
253431
253546
  installStaticEgressFetch,
253432
253547
  registerLazy,
253433
253548
  resolveHandler
@@ -256320,10 +256435,10 @@ var INVOCATION_LOGS_PATCH = [
256320
256435
  "};",
256321
256436
  "const _b44CrashResponse = (e) => {",
256322
256437
  " const c = _b44Context();",
256323
- " if (!c || !c.invocationLogs) return null;",
256438
+ " if (!c || !(c.invocationLogs || c.edgeErrors)) return null;",
256324
256439
  " const m = String(e instanceof Error ? e.message : e).toLowerCase();",
256325
256440
  " if (m.includes('cpu time limit') || m.includes('too many subrequests')) return null;",
256326
- " return _b44AttachInvocationLogs(new Response(JSON.stringify({ error: 'user-exception', detail: 'user worker threw an exception' }), { status: 500, headers: { 'Content-Type': 'application/json' } }));",
256441
+ " return _b44AttachInvocationLogs(_b44AttachEdgeErrors(new Response(JSON.stringify({ error: 'user-exception', detail: 'user worker threw an exception' }), { status: 500, headers: { 'Content-Type': 'application/json' } })));",
256327
256442
  "};"
256328
256443
  ].join(`
256329
256444
  `);
@@ -256367,7 +256482,7 @@ var TELEMETRY_PATCH = [
256367
256482
  var TELEMETRY_STORE_FIELDS = "reqId: crypto.randomUUID(), respondedAt: null, inflight: new Map(), inflightTotal: 0, hadRejection: false, hadNonOk: false, logBudget: 5";
256368
256483
 
256369
256484
  // ../functions-compiler/src/version.ts
256370
- var COMPILER_VERSION = "0.1.6";
256485
+ var COMPILER_VERSION = "0.1.7";
256371
256486
 
256372
256487
  // ../functions-compiler/src/worker-entry.ts
256373
256488
  function denoShimSource() {
@@ -256472,20 +256587,22 @@ registerLazy(${JSON.stringify(functionName)}, () => import(${JSON.stringify(user
256472
256587
  function buildAppEntrySource(functionModules, telemetry, runtimeSecrets = false) {
256473
256588
  const moduleImports = functionModules.map((file) => `import "./${file}";`).join(`
256474
256589
  `);
256475
- const handlerExpr = `_b44AttachInvocationLogs(${telemetry ? "_b44AttachTelemetry(await handler(request, info))" : "await handler(request, info)"})`;
256590
+ const handlerExpr = `_b44AttachInvocationLogs(_b44AttachEdgeErrors(${telemetry ? "_b44AttachTelemetry(await handler(request, info))" : "await handler(request, info)"}))`;
256476
256591
  const guard = activationGuard(runtimeSecrets);
256477
256592
  const returnExpr = guard(handlerExpr);
256478
256593
  return `// Auto-generated by the base44 bundler. Do not edit.
256479
256594
 
256480
256595
  import { currentWorkerRuntimeContext as _b44Context, runWithWorkerEnvironment as _b44Run } from ${JSON.stringify(RUNTIME_CONTEXT_SPECIFIER)};
256481
- import { installStaticEgressFetch, resolveHandler } from "./${SHIM_FILENAME}";${activationImport(runtimeSecrets)}
256596
+ import { attachEdgeErrors as _b44AttachEdgeErrors, installEdgeErrorFetch, installStaticEgressFetch, resolveHandler } from "./${SHIM_FILENAME}";${activationImport(runtimeSecrets)}
256482
256597
  ${moduleImports}
256483
256598
 
256484
256599
  ${consolePatch(runtimeSecrets)}
256485
256600
  ${INVOCATION_LOGS_PATCH}
256486
- // Static egress reads workerEnv from the active request store. Install it
256487
- // before telemetry so telemetry remains the outermost fetch wrapper.
256601
+ // Static egress reads workerEnv from the active request store. Install it and
256602
+ // the edge-error recorder before telemetry so telemetry remains the outermost
256603
+ // fetch wrapper.
256488
256604
  installStaticEgressFetch();
256605
+ installEdgeErrorFetch();
256489
256606
  ${telemetry ? TELEMETRY_PATCH : ""}
256490
256607
 
256491
256608
  export default {
@@ -271402,4 +271519,4 @@ export {
271402
271519
  runCLI
271403
271520
  };
271404
271521
 
271405
- //# debugId=5ADBB560F1D5EE5164756E2164756E21
271522
+ //# debugId=07CB780E430930C364756E2164756E21