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

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.
@@ -3,7 +3,7 @@ name: mastra-deployer
3
3
  description: Documentation for @mastra/deployer. Use when working with @mastra/deployer APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/deployer"
6
- version: "1.64.0-alpha.2"
6
+ version: "1.64.0-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.64.0-alpha.2",
2
+ "version": "1.64.0-alpha.3",
3
3
  "package": "@mastra/deployer",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -3175,9 +3175,23 @@ const skipIfFrameworkPublic = (handler) => {
3175
3175
  return handler(c, next);
3176
3176
  };
3177
3177
  };
3178
+ /**
3179
+ * Context key holding a pristine clone of the incoming request, captured by
3180
+ * the context middleware before user middleware runs. The custom-route bridge
3181
+ * reads the body from this clone so user middleware that consumes the request
3182
+ * body (e.g. `await c.req.json()`) does not break custom API routes.
3183
+ */
3184
+ const MASTRA_PRISTINE_REQUEST_KEY = "__mastraPristineRequest";
3185
+ const BODY_METHODS = /* @__PURE__ */ new Set([
3186
+ "POST",
3187
+ "PUT",
3188
+ "PATCH",
3189
+ "DELETE"
3190
+ ]);
3178
3191
  var MastraServer = class extends _mastra_server_server_adapter.MastraServer {
3179
3192
  createContextMiddleware() {
3180
3193
  return async (c, next) => {
3194
+ if (this.hasCustomRouteHandler && BODY_METHODS.has(c.req.method) && c.req.raw.body) c.set(MASTRA_PRISTINE_REQUEST_KEY, c.req.raw.clone());
3181
3195
  const originalJson = c.req.json.bind(c.req);
3182
3196
  let jsonPromise;
3183
3197
  c.req.json = () => {
@@ -3605,16 +3619,17 @@ var MastraServer = class extends _mastra_server_server_adapter.MastraServer {
3605
3619
  }, permissionError.status);
3606
3620
  }
3607
3621
  }
3622
+ const pristineRequest = c.get(MASTRA_PRISTINE_REQUEST_KEY) ?? c.req.raw;
3608
3623
  let bodyParams = {};
3609
3624
  const contentType = c.req.header("content-type");
3610
3625
  if (contentType?.includes("application/json")) try {
3611
- const body = await c.req.raw.clone().json();
3626
+ const body = await pristineRequest.clone().json();
3612
3627
  if (body && typeof body === "object" && !Array.isArray(body)) bodyParams = body;
3613
3628
  } catch {
3614
3629
  bodyParams = {};
3615
3630
  }
3616
3631
  else if (contentType?.includes("application/x-www-form-urlencoded") || contentType?.includes("multipart/form-data")) try {
3617
- bodyParams = Object.fromEntries(await c.req.raw.clone().formData());
3632
+ bodyParams = Object.fromEntries(await pristineRequest.clone().formData());
3618
3633
  } catch {
3619
3634
  bodyParams = {};
3620
3635
  }
@@ -3637,7 +3652,7 @@ var MastraServer = class extends _mastra_server_server_adapter.MastraServer {
3637
3652
  } catch {
3638
3653
  executionCtx = void 0;
3639
3654
  }
3640
- const response = await this.handleCustomRouteRequest(c.req.url, c.req.method, reqHeaders, c.req.raw.body, c.get("requestContext"), c.req.raw.signal, executionCtx);
3655
+ const response = await this.handleCustomRouteRequest(c.req.url, c.req.method, reqHeaders, pristineRequest.body, c.get("requestContext"), c.req.raw.signal, executionCtx);
3641
3656
  if (!response) return c.json({ error: "Not Found" }, 404);
3642
3657
  return response;
3643
3658
  };