@mastra/deployer 1.64.0-alpha.2 → 1.64.0-alpha.4

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.
@@ -3170,9 +3170,23 @@ const skipIfFrameworkPublic = (handler) => {
3170
3170
  return handler(c, next);
3171
3171
  };
3172
3172
  };
3173
+ /**
3174
+ * Context key holding a pristine clone of the incoming request, captured by
3175
+ * the context middleware before user middleware runs. The custom-route bridge
3176
+ * reads the body from this clone so user middleware that consumes the request
3177
+ * body (e.g. `await c.req.json()`) does not break custom API routes.
3178
+ */
3179
+ const MASTRA_PRISTINE_REQUEST_KEY = "__mastraPristineRequest";
3180
+ const BODY_METHODS = /* @__PURE__ */ new Set([
3181
+ "POST",
3182
+ "PUT",
3183
+ "PATCH",
3184
+ "DELETE"
3185
+ ]);
3173
3186
  var MastraServer$1 = class extends MastraServer {
3174
3187
  createContextMiddleware() {
3175
3188
  return async (c, next) => {
3189
+ if (this.hasCustomRouteHandler && BODY_METHODS.has(c.req.method) && c.req.raw.body) c.set(MASTRA_PRISTINE_REQUEST_KEY, c.req.raw.clone());
3176
3190
  const originalJson = c.req.json.bind(c.req);
3177
3191
  let jsonPromise;
3178
3192
  c.req.json = () => {
@@ -3600,16 +3614,17 @@ var MastraServer$1 = class extends MastraServer {
3600
3614
  }, permissionError.status);
3601
3615
  }
3602
3616
  }
3617
+ const pristineRequest = c.get(MASTRA_PRISTINE_REQUEST_KEY) ?? c.req.raw;
3603
3618
  let bodyParams = {};
3604
3619
  const contentType = c.req.header("content-type");
3605
3620
  if (contentType?.includes("application/json")) try {
3606
- const body = await c.req.raw.clone().json();
3621
+ const body = await pristineRequest.clone().json();
3607
3622
  if (body && typeof body === "object" && !Array.isArray(body)) bodyParams = body;
3608
3623
  } catch {
3609
3624
  bodyParams = {};
3610
3625
  }
3611
3626
  else if (contentType?.includes("application/x-www-form-urlencoded") || contentType?.includes("multipart/form-data")) try {
3612
- bodyParams = Object.fromEntries(await c.req.raw.clone().formData());
3627
+ bodyParams = Object.fromEntries(await pristineRequest.clone().formData());
3613
3628
  } catch {
3614
3629
  bodyParams = {};
3615
3630
  }
@@ -3632,7 +3647,7 @@ var MastraServer$1 = class extends MastraServer {
3632
3647
  } catch {
3633
3648
  executionCtx = void 0;
3634
3649
  }
3635
- const response = await this.handleCustomRouteRequest(c.req.url, c.req.method, reqHeaders, c.req.raw.body, c.get("requestContext"), c.req.raw.signal, executionCtx);
3650
+ const response = await this.handleCustomRouteRequest(c.req.url, c.req.method, reqHeaders, pristineRequest.body, c.get("requestContext"), c.req.raw.signal, executionCtx);
3636
3651
  if (!response) return c.json({ error: "Not Found" }, 404);
3637
3652
  return response;
3638
3653
  };