@farm.js/plugin 0.1.70 → 0.1.71

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.70";
42
+ export declare const version = "0.1.71";
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.70";
42
+ export const version = "0.1.71";
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":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAgKhE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,YAAY,EACjB,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,EAC1C,eAAe,EAAE,OAAO,GACvB,MAAM,CAqGR;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAo+E1D"}
1
+ {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAgKhE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,YAAY,EACjB,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,EAC1C,eAAe,EAAE,OAAO,GACvB,MAAM,CAqGR;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAo7E1D"}
@@ -348,7 +348,6 @@ import {
348
348
  }
349
349
  code += `} from '@vitejs/plugin-rsc/rsc';
350
350
  import {
351
- createFarmDeploymentCookie,
352
351
  createFarmDeploymentMismatchResponse,
353
352
  getFarmDeploymentMismatch,
354
353
  } from '@farm.js/core/deployment';
@@ -358,7 +357,7 @@ import {
358
357
  applyProductionMiddlewareHeaders,
359
358
  createProductionMiddlewareRunner,
360
359
  } from '@farm.js/core/middleware';
361
- import { _withFarmGuardedResponseCache, _withFarmResponseHeaders } from '@farm.js/core/internal/production-runtime';
360
+ import { _withFarmDeploymentCookie, _withFarmGuardedResponseCache } from '@farm.js/core/internal/production-runtime';
362
361
  ${ctx.mobileClient === "entry" ? "import { _applyFarmMobileShellClient, createFarmNativeTreeResponse, resolveFarmWebRequestOrigin } from '@farm.js/core/internal/production-runtime';\n" : ctx.mobileClient === "inline" ? "import { createFarmNativeTreeResponse, resolveFarmWebRequestOrigin } from '@farm.js/core/internal/production-runtime';\n" : ""}import {
363
362
  getAllowedAPIRouteMethods,
364
363
  invokeAPIRouteEndpoint,
@@ -594,40 +593,17 @@ function debug(...args) {
594
593
  ${debugLog}
595
594
  }
596
595
 
597
- // Directives a CDN reads in place of Cache-Control, as core's CDN_CACHE_CONTROL_HEADERS lists them.
598
- const FARM_CDN_CACHE_CONTROL_HEADERS = [
599
- 'cdn-cache-control',
600
- 'vercel-cdn-cache-control',
601
- 'netlify-cdn-cache-control',
602
- 'cloudflare-cdn-cache-control',
603
- ];
604
- const FARM_PRIVATE_CACHE_DIRECTIVE = /(?:^|,)\\s*(?:private|no-store)\\s*(?:[,=]|$)/i;
605
-
606
596
  /**
607
597
  * Store the deployment ID in the deployment cookie on a page document a browser loads, so a form
608
- * posted from it before JavaScript runs names its deployment. Only a GET page document that names
609
- * this deployment and stays out of shared caches carries it: a CDN does not cache a response that
610
- * sets a cookie (and one that does would hand it to every visitor), so a publicly cached page is
611
- * sent as it was. A request naming another deployment keeps its cookie, so its forms stay refused.
612
- *
613
- * These are the rules of core's _withFarmDeploymentCookie for its production server (deployment
614
- * skew protection); reuse that helper here once core exports it. A Flight payload is fetched by
615
- * the client router, which names its deployment in a header, so it never carries the cookie.
598
+ * posted from it before JavaScript runs names its deployment. Core's _withFarmDeploymentCookie
599
+ * decides, as on its production server: only a GET page response that names this deployment and
600
+ * stays out of shared caches carries it, and a request naming another deployment keeps its cookie.
601
+ * A Flight payload is fetched by the client router, which names its deployment in a header, so it
602
+ * never carries the cookie.
616
603
  */
617
604
  function withFarmDeploymentCookie(request, response) {
618
- if (request.method.toUpperCase() !== 'GET') return response;
619
605
  if ((request.headers.get('accept') || '').includes('text/x-component')) return response;
620
- if (response.headers.get('x-farm-deployment-id') !== farmDeploymentId) return response;
621
- if (!FARM_PRIVATE_CACHE_DIRECTIVE.test(response.headers.get('cache-control') || '')) return response;
622
- if (FARM_CDN_CACHE_CONTROL_HEADERS.some((name) => response.headers.has(name))) return response;
623
- if (getFarmDeploymentMismatch(request, farmDeploymentId)) return response;
624
- return _withFarmResponseHeaders(response, (headers) => {
625
- headers.append('set-cookie', createFarmDeploymentCookie(
626
- farmDeploymentId,
627
- ${JSON.stringify(ctx.basePath)},
628
- new URL(request.url).protocol === 'https:',
629
- ));
630
- });
606
+ return _withFarmDeploymentCookie(request, response, farmDeploymentId, ${JSON.stringify(ctx.basePath)});
631
607
  }
632
608
 
633
609
  function applyActionResponseHeaders(headers, request, pageCacheControl) {
@@ -2417,30 +2393,6 @@ function addFarmMetadataFileReferences(metadata, pathname) {
2417
2393
 
2418
2394
  `
2419
2395
  : ""}/**
2420
- * A Markdown request whose only cookie is the deployment cookie, without it. That cookie names a
2421
- * release, never a visitor, so a browser holding it may still read (and fill) a mirror md.cache
2422
- * shares; any other cookie keeps the mirror private. Core's withoutFarmDeploymentCookie applies
2423
- * the same rule inside createMarkdownMirrorResponse with deployment skew protection; drop this
2424
- * once that ships. The mirror renders the page with a GET, where the cookie is never read.
2425
- */
2426
- function withoutLoneFarmDeploymentCookie(request) {
2427
- const cookie = request.headers.get('cookie');
2428
- if (!cookie || !cookie.includes('__farm_deployment')) return request;
2429
- if (!farmRequestWantsMarkdown(new URL(request.url).pathname, request.headers.get('accept'))) {
2430
- return request;
2431
- }
2432
- const otherCookie = cookie.split(';').some((part) => {
2433
- const separator = part.indexOf('=');
2434
- const name = (separator === -1 ? part : part.slice(0, separator)).trim();
2435
- return name !== '' && name !== '__farm_deployment';
2436
- });
2437
- if (otherCookie) return request;
2438
- const headers = new Headers(request.headers);
2439
- headers.delete('cookie');
2440
- return new Request(request, { headers });
2441
- }
2442
-
2443
- /**
2444
2396
  * Serves a page's Markdown mirror (\`/page.md\` or \`Accept: text/markdown\`) by
2445
2397
  * rendering the page through the normal request path, so middleware and sign-in
2446
2398
  * gates apply; every other request renders as usual, and HTML pages advertise
@@ -2449,7 +2401,7 @@ function withoutLoneFarmDeploymentCookie(request) {
2449
2401
  async function handleFarmPageOrMarkdown(request, context) {
2450
2402
  if (!farmMarkdownConfig.enabled) return handleFarmRequest(request, context);
2451
2403
  const markdown = await createMarkdownMirrorResponse({
2452
- request: withoutLoneFarmDeploymentCookie(request),
2404
+ request,
2453
2405
  config: farmMarkdownConfig,
2454
2406
  routePathname: getFarmRoutePathname,
2455
2407
  // The page the render below selects for the mirrored URL, below the basePath and locale.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/plugin",
3
- "version": "0.1.70",
3
+ "version": "0.1.71",
4
4
  "description": "Official plugins for Farm.js framework",
5
5
  "license": "MIT",
6
6
  "author": "Farm.js Team",
@@ -63,7 +63,7 @@
63
63
  "nitro": "3.0.260903-beta",
64
64
  "picocolors": "^1.0.0",
65
65
  "rsc-html-stream": "^0.0.4",
66
- "@farm.js/core": "0.1.70"
66
+ "@farm.js/core": "0.1.71"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/node": "^22.20.5",
@@ -84,7 +84,7 @@
84
84
  "react-dom": "19.2.8",
85
85
  "react-server-dom-webpack": "19.2.8",
86
86
  "vite": ">=6.0.0",
87
- "@farm.js/core": "0.1.70"
87
+ "@farm.js/core": "0.1.71"
88
88
  },
89
89
  "peerDependenciesMeta": {
90
90
  "@vitejs/plugin-rsc": {