@tokenoftrust/storefront-runner 7.6.20 → 7.7.0

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.
@@ -248,12 +248,9 @@ export function isStaticBundleUploadPath(pathname: string): boolean {
248
248
  export function isCandidatePreviewPath(pathname: string): boolean {
249
249
  if (pathname.startsWith("/preview/render/")) return true;
250
250
  if (pathname === "/preview/change" || pathname.startsWith("/preview/change/")) return true;
251
- // /<tenant>/preview/pr and /<tenant>/preview/pr/<n> — the PR-number alias.
252
- if (/^\/[^/]+\/preview\/pr(?:\/|$)/.test(pathname)) return true;
253
- if (/^\/[^/]+\/preview\/staged(?:\/|$)/.test(pathname)) return true;
254
- // /<tenant>/preview/rev/<sha> and /<tenant>/preview/rev/<sha>/<path...> — the
255
- // immutable per-revision alias.
256
- return /^\/[^/]+\/preview\/rev(?:\/|$)/.test(pathname);
251
+ // Both bare host-routed (`/preview/pr|staged|rev`) and tenant-first (`/<tenant>/preview/...`).
252
+ if (/^\/preview\/(?:pr|staged|rev)(?:\/|$)/.test(pathname)) return true;
253
+ return /^\/[^/]+\/preview\/(?:pr|staged|rev)(?:\/|$)/.test(pathname);
257
254
  }
258
255
 
259
256
  /**
@@ -60,6 +60,21 @@ export async function getSessionStore(): Promise<SessionStore | null> {
60
60
  return kv ? new KvSessionStore(kv) : null;
61
61
  }
62
62
 
63
+ const inRequestViewerSessions = new WeakMap<Request, SessionRecord>();
64
+
65
+ /**
66
+ * Bind an in-request rotated session (e.g. after `enterStoreAsStaff` rotates the
67
+ * cookie) so downstream readers on the same request (`resolveRequestPrincipal`)
68
+ * see the new `staffSelection` without depending on incoming cookie headers or
69
+ * KV read-after-write timing.
70
+ */
71
+ export function rememberRequestViewerSession(
72
+ context: { request?: Request },
73
+ session: SessionRecord,
74
+ ): void {
75
+ if (context.request) inRequestViewerSessions.set(context.request, session);
76
+ }
77
+
63
78
  /**
64
79
  * Read the signed-in viewer's FULL session (email + all tenant memberships), or
65
80
  * null when there's no valid session. Unlike the gate's read, this is NOT scoped
@@ -68,8 +83,12 @@ export async function getSessionStore(): Promise<SessionStore | null> {
68
83
  * against the SELECTED vendor. Returns null in runtimes without the SESSION KV.
69
84
  */
70
85
  export async function readViewerSession(
71
- context: { cookies: APIContext["cookies"] },
86
+ context: { cookies: APIContext["cookies"]; request?: Request },
72
87
  ): Promise<SessionRecord | null> {
88
+ if (context.request) {
89
+ const remembered = inRequestViewerSessions.get(context.request);
90
+ if (remembered) return remembered;
91
+ }
73
92
  const store = await getSessionStore();
74
93
  if (!store) return null;
75
94
  const sid = context.cookies.get(SESSION_COOKIE)?.value ?? null;
@@ -127,6 +127,27 @@ export async function resolveTenantRouting(
127
127
  // the dev loop, the admin preview links and the post-deploy chrome canary.
128
128
  const byHost = await resolver.resolveStrict(host);
129
129
  if (byHost && !byHost.pathPrefixTenants) {
130
+ // A tenant host NEVER dispatches another tenant by path prefix, but a redundant
131
+ // self-prefix on a preview link (`/<own-domain>/preview/...`) on the tenant's own
132
+ // host resolves to that same tenant's preview route instead of 404ing.
133
+ const hostSegments = pathname.replace(/^\/+/, "").split("/");
134
+ let hostFirst = hostSegments[0] ?? "";
135
+ try {
136
+ hostFirst = decodeURIComponent(hostFirst);
137
+ } catch {
138
+ /* leave as-is if it isn't valid percent-encoding */
139
+ }
140
+ const selfMatch =
141
+ looksLikeHost(hostFirst) &&
142
+ (hostFirst.toLowerCase() === (byHost.appDomain ?? "").toLowerCase() ||
143
+ hostFirst.toLowerCase() === byHost.tenant_id.toLowerCase());
144
+ if (selfMatch && hostSegments[1] === "preview") {
145
+ return {
146
+ tenant: byHost,
147
+ basePath: `/${hostFirst}`,
148
+ renderPath: normalizePath(hostSegments.slice(1).join("/")),
149
+ };
150
+ }
130
151
  return { tenant: byHost, basePath: "", renderPath: normalizePath(pathname) };
131
152
  }
132
153
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.6.20",
3
+ "version": "7.7.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",
@@ -44,3 +44,43 @@ export function dependenciesForScanFinding(
44
44
  const group = indexDependenciesByFindingId(scan.dependencies).get(`${artifactIndex}:${groupOrdinal}`);
45
45
  return group ? [...group] : [];
46
46
  }
47
+
48
+ /**
49
+ * Every unresolved finding implied by `scan.dependencies`, without the pre-capture
50
+ * `MAX_VISIBLE_FINDINGS` display slice. Falls back to `scan.findings` when a caller
51
+ * supplied findings without raw dependencies (e.g. unit-test fixtures).
52
+ */
53
+ export function allUnresolvedImageFindings(
54
+ scan: Pick<ImageDependencyScan, "dependencies" | "findings"> & { warningBatch?: { omittedFindings?: number } | null },
55
+ ): ImageDependencyFinding[] {
56
+ const omitted = (scan.warningBatch?.omittedFindings ?? 0) > 0;
57
+ if (!scan.dependencies || scan.dependencies.length === 0 || (!omitted && scan.findings.length < 100)) {
58
+ return [...scan.findings];
59
+ }
60
+ const byId = new Map(scan.findings.map((finding) => [finding.id, finding]));
61
+ const out: ImageDependencyFinding[] = [...scan.findings];
62
+ for (const [key, group] of indexDependenciesByFindingId(scan.dependencies)) {
63
+ const dep = group[0];
64
+ if (!dep || !dep.reason) continue;
65
+ const [artifactRaw, ordinalRaw] = key.split(":");
66
+ const id = `image-dependency-${String(Number(artifactRaw) + 1).padStart(6, "0")}-${String(Number(ordinalRaw)).padStart(6, "0")}`;
67
+ if (byId.has(id)) continue;
68
+ const security = dep.disposition === "security-error";
69
+ const deferred = dep.disposition === "deferred";
70
+ out.push({
71
+ id,
72
+ code: security ? "image-reference-security" : deferred ? "image-reference-deferred" : "image-capture-required",
73
+ reason: dep.reason,
74
+ occurrences: group.length,
75
+ authoring: security ? "non-overridable-security-error" : "warning",
76
+ hostedPreview: security ? "non-overridable-security-error" : "overridable-quality-error",
77
+ overridable: !security,
78
+ message: security
79
+ ? "Image reference requires a security fix before preview or publish."
80
+ : deferred
81
+ ? "Image reference could not be statically resolved."
82
+ : "Image reference requires hosted capture.",
83
+ });
84
+ }
85
+ return out;
86
+ }