@rsc-kit/core 0.30.52 → 0.30.54

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/host.js CHANGED
@@ -86,6 +86,7 @@ export { matchIntercept, matchRoute, sharedDepth } from "./routing.js";
86
86
  import { FLIGHT_TYPE, HEADER, HTML_TYPE, PER_CLIENT, PER_REQUEST, REVALIDATE, EDGE, VARY_ON_RSC, } from "./headers.js";
87
87
  import { ServerAuthenticationError, ServerAuthorizationError, } from "./js/errors.js";
88
88
  import { assertSigningSecret, serveChanges } from "./changed.js";
89
+ import { purgeUrl } from "./purge.js";
89
90
  /**
90
91
  * Whether instances live for a request or a few: a Worker's isolates, a
91
92
  * Vercel function. Memory there is a store few requests ever find.
@@ -94,10 +95,9 @@ function shortLivedInstances() {
94
95
  const env = globalThis.process?.env;
95
96
  return globalThis.navigator?.userAgent === "Cloudflare-Workers" || Boolean(env?.VERCEL);
96
97
  }
97
- /** Whether the app runs on Homeport, whose edge keeps pages itself. */
98
- function onHomeport() {
99
- const env = globalThis.process?.env;
100
- return Boolean(env?.HOMEPORT_PURGE_URL);
98
+ /** Whether an edge in front keeps pages itself, and is told what changed. */
99
+ function edgeKeepsPages() {
100
+ return purgeUrl() !== undefined;
101
101
  }
102
102
  /**
103
103
  * The answer to a redirect that was decided before anything was written.
@@ -503,7 +503,7 @@ export function createRscHandler(options) {
503
503
  // The page cache, made on the first request: the app installs its store in
504
504
  // register(), which runs after the handler is made.
505
505
  let pages;
506
- const pageCacheOption = onHomeport() ? false : (options.pageCache ?? true);
506
+ const pageCacheOption = edgeKeepsPages() ? false : (options.pageCache ?? true);
507
507
  // Annotated rather than inferred: the narrowing below is lost inside the
508
508
  // closures that use it, and every one of them runs after the throw.
509
509
  const manifest = options.manifest ?? engine.manifest?.();
@@ -1304,21 +1304,31 @@ export function createRscHandler(options) {
1304
1304
  headers: { "content-type": "application/json", "cache-control": "no-store" },
1305
1305
  });
1306
1306
  }
1307
- /** Whether a health probe sent this deployment's host-call secret, compared in constant time. */
1307
+ /**
1308
+ * Whether a health probe sent this deployment's host-call secret, compared in
1309
+ * constant time - or the one it replaced, while RSC_HOST_CALL_SECRET_PREVIOUS
1310
+ * still names it, so a rotation fails no probe.
1311
+ */
1308
1312
  function probeHoldsSecret(request) {
1309
- return holdsSecret(request, "x-rsc-host-secret", "RSC_HOST_CALL_SECRET");
1313
+ return holdsSecret(request, "x-rsc-host-secret", "RSC_HOST_CALL_SECRET", "RSC_HOST_CALL_SECRET_PREVIOUS");
1310
1314
  }
1311
- /** Whether the request's header holds the secret in the environment's variable, compared in constant time. */
1312
- function holdsSecret(request, header, variable) {
1313
- const expected = (typeof process === "undefined" ? undefined : process.env[variable]) ?? "";
1315
+ /** Whether the request's header holds the secret in one of the environment's variables, compared in constant time. */
1316
+ function holdsSecret(request, header, ...variables) {
1314
1317
  const given = request.headers.get(header) ?? "";
1315
- // An unset secret matches nothing, the empty string included.
1316
- if (expected === "" || given.length !== expected.length)
1317
- return false;
1318
- let differ = 0;
1319
- for (let i = 0; i < expected.length; i++)
1320
- differ |= expected.charCodeAt(i) ^ given.charCodeAt(i);
1321
- return differ === 0;
1318
+ let held = false;
1319
+ // Every variable is compared, not the first match returned: how long the
1320
+ // check takes says nothing about which one held.
1321
+ for (const variable of variables) {
1322
+ const expected = (typeof process === "undefined" ? undefined : process.env[variable]) ?? "";
1323
+ // An unset secret matches nothing, the empty string included.
1324
+ if (expected === "" || given.length !== expected.length)
1325
+ continue;
1326
+ let differ = 0;
1327
+ for (let i = 0; i < expected.length; i++)
1328
+ differ |= expected.charCodeAt(i) ^ given.charCodeAt(i);
1329
+ held = held || differ === 0;
1330
+ }
1331
+ return held;
1322
1332
  }
1323
1333
  async function frozenApi(request, url, api) {
1324
1334
  if (isGuarded(api))