@farm.js/plugin 0.1.38 → 0.1.40

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/index.d.ts CHANGED
@@ -39,5 +39,5 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export declare const version = "0.1.38";
42
+ export declare const version = "0.1.40";
43
43
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export const version = "0.1.38";
42
+ export const version = "0.1.40";
43
43
  // Note: Import plugins from their respective subpaths:
44
44
  // - @farm.js/plugin/rsc
45
45
  // - @farm.js/plugin/middleware
@@ -1 +1 @@
1
- {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAuwC1D"}
1
+ {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CA2yC1D"}
@@ -89,6 +89,7 @@ import {
89
89
  applyProductionMiddlewareHeaders,
90
90
  createProductionMiddlewareRunner,
91
91
  } from '@farm.js/core/middleware';
92
+ import { _withFarmGuardedResponseCache } from '@farm.js/core/internal/production-runtime';
92
93
  import {
93
94
  getAllowedAPIRouteMethods,
94
95
  invokeAPIRouteEndpoint,
@@ -124,8 +125,10 @@ const farmMarkdownConfig = ${JSON.stringify(ctx.markdown ?? { enabled: false, ex
124
125
  createFarmLlmsFullRenderer,
125
126
  createFarmLlmsMarkdownReader,
126
127
  createFarmMetadataRouteResponse,
128
+ farmPathGuardCoversPage,
127
129
  renderFarmLlmsFullTxt,
128
130
  } from '@farm.js/core/internal/production-runtime';
131
+ import { FARM_MARKDOWN_ANONYMOUS_CLIENT_ADDRESS } from '@farm.js/core/internal/app-markdown-runtime';
129
132
 
130
133
  const farmLlmsTxtConfig = ${JSON.stringify(ctx.llmsTxt)};
131
134
  const farmLlmsFullRenderer = createFarmLlmsFullRenderer({ revalidate: farmLlmsTxtConfig.revalidate });
@@ -218,6 +221,10 @@ function applyActionResponseHeaders(headers, request) {
218
221
  headers.set('cache-control', 'no-store');
219
222
  headers.set('x-content-type-options', 'nosniff');
220
223
  }
224
+ // A page renders per request (cookies, headers, client address), so a shared
225
+ // cache must not keep its HTML or Flight payload unless middleware chose a
226
+ // policy. Core's server defaults pages the same way.
227
+ if (!headers.has('cache-control')) headers.set('cache-control', 'private, no-store');
221
228
  }
222
229
 
223
230
  // Auto-discover all route modules. Every glob remains a literal so Vite can analyze it.
@@ -661,8 +668,19 @@ function getMatchingBoundary(pageFilePath, modules, kind) {
661
668
  /**
662
669
  * Main request handler - entry point for both dev and production (Nitro).
663
670
  * Exported as { fetch: handler } for the RSC/Nitro contract (see vite-plugin-rsc-deploy-example).
671
+ *
672
+ * Middleware that let a request through may have been a guard: an IP allowlist, an API key
673
+ * header, a VPN header. A CDN keys its copy by URL and never runs the guard on a hit, so
674
+ * whatever such a request answers stays out of shared caches, as in core's server. Only
675
+ * middleware declaring cache: "public" leaves the policy alone.
664
676
  */
665
677
  async function handleFarmRequest(request, context) {
678
+ const farmCacheGuard = { guarded: false };
679
+ const response = await resolveFarmRequest(farmCacheGuard, request, context);
680
+ return farmCacheGuard.guarded ? _withFarmGuardedResponseCache(response) : response;
681
+ }
682
+
683
+ async function resolveFarmRequest(farmCacheGuard, request, context) {
666
684
  let url = new URL(request.url);
667
685
  let matchedPage = null;
668
686
  let errorData = new Map();
@@ -702,6 +720,7 @@ async function handleFarmRequest(request, context) {
702
720
  // Execute middleware first
703
721
  const middlewareResult = await executeMiddleware(request, context);
704
722
  ${generateRscMiddlewareResultHandling()}
723
+ if (middlewareResult.guarded) farmCacheGuard.guarded = true;
705
724
 
706
725
  request = middlewareResult.request;
707
726
  url = new URL(request.url);
@@ -1164,14 +1183,24 @@ ${ctx.llmsTxt?.enabled
1164
1183
  */
1165
1184
  function createFarmLlmsTxtContext(request, context, full) {
1166
1185
  const origin = new URL(request.url).origin;
1186
+ // A page a path-specific guard covers (a non-root middleware.ts, a config
1187
+ // middleware matcher naming the path) is left out, as core's server does.
1188
+ const guard = {
1189
+ config: { middleware: farmConfigMiddleware },
1190
+ middlewareRoutes: Object.keys(middlewares)
1191
+ .map((filePath) => ({ path: middlewarePathToRoute(filePath) }))
1192
+ .filter((route) => route.path !== null),
1193
+ };
1167
1194
  const pages = collectFarmLlmsTxtPages(
1168
- pageRoutes.map(({ module, segments }) => ({
1169
- // Dynamic routes have no single URL, so the collector skips them.
1170
- pattern: '/' + segments
1171
- .map((part) => (part.isDynamic ? '[' + part.segment + ']' : part.segment))
1172
- .join('/'),
1173
- metadata: module && module.metadata,
1174
- })),
1195
+ pageRoutes
1196
+ .map(({ module, segments }) => ({
1197
+ // Dynamic routes have no single URL, so the collector skips them.
1198
+ pattern: '/' + segments
1199
+ .map((part) => (part.isDynamic ? '[' + part.segment + ']' : part.segment))
1200
+ .join('/'),
1201
+ metadata: module && module.metadata,
1202
+ }))
1203
+ .filter((page) => page.pattern.includes('[') || !farmPathGuardCoversPage(guard, page.pattern)),
1175
1204
  {
1176
1205
  origin,
1177
1206
  markdown: farmMarkdownConfig,
@@ -1187,10 +1216,17 @@ function createFarmLlmsTxtContext(request, context, full) {
1187
1216
  config: farmLlmsTxtConfig,
1188
1217
  rootMetadata: rootLayout && rootLayout.metadata,
1189
1218
  }),
1190
- // Pages are read in-process through the full handler with a fresh request,
1191
- // so the caller's cookies never shape the file. HEAD reads nothing.
1219
+ // Pages are read in-process through the full handler as an anonymous
1220
+ // visitor: a fresh request, so the caller's cookies never shape the file,
1221
+ // and a neutral client address, so an IP allowlist never admits the read.
1222
+ // The body is shared across callers. HEAD reads nothing.
1192
1223
  markdown: full && request.method.toUpperCase() !== 'HEAD'
1193
- ? createFarmLlmsMarkdownReader((page) => handler(page, context))
1224
+ ? createFarmLlmsMarkdownReader((page) =>
1225
+ handler(page, {
1226
+ waitUntil: context && context.waitUntil,
1227
+ clientAddress: FARM_MARKDOWN_ANONYMOUS_CLIENT_ADDRESS,
1228
+ }),
1229
+ )
1194
1230
  : async () => null,
1195
1231
  };
1196
1232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/plugin",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "Official plugins for Farm.js framework",
5
5
  "license": "MIT",
6
6
  "author": "Farm.js Team",
@@ -62,7 +62,7 @@
62
62
  "nitro": "3.0.260903-beta",
63
63
  "picocolors": "^1.0.0",
64
64
  "rsc-html-stream": "^0.0.4",
65
- "@farm.js/core": "0.1.38"
65
+ "@farm.js/core": "0.1.40"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/node": "^22.20.5",
@@ -83,7 +83,7 @@
83
83
  "react-dom": "19.2.8",
84
84
  "react-server-dom-webpack": "19.2.8",
85
85
  "vite": ">=6.0.0",
86
- "@farm.js/core": "0.1.38"
86
+ "@farm.js/core": "0.1.40"
87
87
  },
88
88
  "peerDependenciesMeta": {
89
89
  "@vitejs/plugin-rsc": {