@caelo-cms/shared 0.11.8 → 0.11.10

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.
Files changed (134) hide show
  1. package/certs/aws-rds-global.pem +2888 -0
  2. package/certs/cloudsql-global.pem +1897 -0
  3. package/dist/ai-tools.d.ts +2 -2
  4. package/dist/body-cap.d.ts +35 -0
  5. package/dist/body-cap.d.ts.map +1 -0
  6. package/dist/body-cap.js +63 -0
  7. package/dist/body-cap.js.map +1 -0
  8. package/dist/build-page.d.ts +4 -4
  9. package/dist/change-journal.d.ts.map +1 -1
  10. package/dist/change-journal.js +1 -0
  11. package/dist/change-journal.js.map +1 -1
  12. package/dist/client-address.d.ts +69 -0
  13. package/dist/client-address.d.ts.map +1 -0
  14. package/dist/client-address.js +99 -0
  15. package/dist/client-address.js.map +1 -0
  16. package/dist/content.d.ts +6 -6
  17. package/dist/content.d.ts.map +1 -1
  18. package/dist/content.js +8 -1
  19. package/dist/content.js.map +1 -1
  20. package/dist/context.d.ts +8 -0
  21. package/dist/context.d.ts.map +1 -1
  22. package/dist/database-tls.d.ts +64 -0
  23. package/dist/database-tls.d.ts.map +1 -0
  24. package/dist/database-tls.js +95 -0
  25. package/dist/database-tls.js.map +1 -0
  26. package/dist/database-url.d.ts +2 -15
  27. package/dist/database-url.d.ts.map +1 -1
  28. package/dist/database-url.js +14 -1
  29. package/dist/database-url.js.map +1 -1
  30. package/dist/index.d.ts +7 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +7 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/interim-forwarded-host.d.ts +15 -0
  35. package/dist/interim-forwarded-host.d.ts.map +1 -0
  36. package/dist/interim-forwarded-host.js +16 -0
  37. package/dist/interim-forwarded-host.js.map +1 -0
  38. package/dist/json-security-headers.d.ts +23 -0
  39. package/dist/json-security-headers.d.ts.map +1 -0
  40. package/dist/json-security-headers.js +53 -0
  41. package/dist/json-security-headers.js.map +1 -0
  42. package/dist/lists/fields.d.ts +6 -0
  43. package/dist/lists/fields.d.ts.map +1 -1
  44. package/dist/lists/fields.js +70 -7
  45. package/dist/lists/fields.js.map +1 -1
  46. package/dist/lists/index.d.ts +1 -0
  47. package/dist/lists/index.d.ts.map +1 -1
  48. package/dist/lists/index.js +1 -0
  49. package/dist/lists/index.js.map +1 -1
  50. package/dist/lists/list-type.d.ts +28 -6
  51. package/dist/lists/list-type.d.ts.map +1 -1
  52. package/dist/lists/list-type.js +43 -15
  53. package/dist/lists/list-type.js.map +1 -1
  54. package/dist/lists/overlay-scope.d.ts +68 -0
  55. package/dist/lists/overlay-scope.d.ts.map +1 -0
  56. package/dist/lists/overlay-scope.js +56 -0
  57. package/dist/lists/overlay-scope.js.map +1 -0
  58. package/dist/lists/query-merge.d.ts +27 -0
  59. package/dist/lists/query-merge.d.ts.map +1 -0
  60. package/dist/lists/query-merge.js +53 -0
  61. package/dist/lists/query-merge.js.map +1 -0
  62. package/dist/lists/resolve.d.ts +1 -0
  63. package/dist/lists/resolve.d.ts.map +1 -1
  64. package/dist/lists/resolve.js +11 -25
  65. package/dist/lists/resolve.js.map +1 -1
  66. package/dist/lists/scope.d.ts +4 -1
  67. package/dist/lists/scope.d.ts.map +1 -1
  68. package/dist/pool-budget.d.ts +10 -0
  69. package/dist/pool-budget.d.ts.map +1 -1
  70. package/dist/pool-budget.js +15 -0
  71. package/dist/pool-budget.js.map +1 -1
  72. package/dist/redirect-emit-gcp.d.ts +16 -8
  73. package/dist/redirect-emit-gcp.d.ts.map +1 -1
  74. package/dist/redirect-emit-gcp.js +22 -11
  75. package/dist/redirect-emit-gcp.js.map +1 -1
  76. package/dist/release-manifest.d.ts +18 -2
  77. package/dist/release-manifest.d.ts.map +1 -1
  78. package/dist/release-manifest.js +32 -4
  79. package/dist/release-manifest.js.map +1 -1
  80. package/dist/session-cookie.d.ts +88 -0
  81. package/dist/session-cookie.d.ts.map +1 -0
  82. package/dist/session-cookie.js +151 -0
  83. package/dist/session-cookie.js.map +1 -0
  84. package/dist/staging-plugin-stub.d.ts +28 -0
  85. package/dist/staging-plugin-stub.d.ts.map +1 -0
  86. package/dist/staging-plugin-stub.js +34 -0
  87. package/dist/staging-plugin-stub.js.map +1 -0
  88. package/dist/template-engine.d.ts.map +1 -1
  89. package/dist/template-engine.js +4 -1
  90. package/dist/template-engine.js.map +1 -1
  91. package/dist/version.d.ts +2 -2
  92. package/dist/version.d.ts.map +1 -1
  93. package/dist/version.js +1 -1
  94. package/dist/version.js.map +1 -1
  95. package/package.json +2 -1
  96. package/src/body-cap.test.ts +44 -0
  97. package/src/body-cap.ts +83 -0
  98. package/src/change-journal.ts +1 -0
  99. package/src/client-address.test.ts +90 -0
  100. package/src/client-address.ts +111 -0
  101. package/src/content.test.ts +54 -0
  102. package/src/content.ts +10 -1
  103. package/src/context.ts +8 -0
  104. package/src/database-tls.test.ts +83 -0
  105. package/src/database-tls.ts +99 -0
  106. package/src/database-url.test.ts +49 -11
  107. package/src/database-url.ts +21 -1
  108. package/src/index.ts +7 -0
  109. package/src/interim-forwarded-host.ts +16 -0
  110. package/src/json-security-headers.test.ts +31 -0
  111. package/src/json-security-headers.ts +53 -0
  112. package/src/lists/fields.ts +88 -7
  113. package/src/lists/index.ts +1 -0
  114. package/src/lists/list-type.ts +53 -18
  115. package/src/lists/lists.test.ts +70 -0
  116. package/src/lists/overlay-scope.test.ts +140 -0
  117. package/src/lists/overlay-scope.ts +120 -0
  118. package/src/lists/pagination.test.ts +15 -0
  119. package/src/lists/query-merge.ts +84 -0
  120. package/src/lists/resolve.test.ts +24 -4
  121. package/src/lists/resolve.ts +12 -33
  122. package/src/lists/scope.ts +4 -2
  123. package/src/pool-budget.test.ts +17 -3
  124. package/src/pool-budget.ts +19 -0
  125. package/src/redirect-emit-gcp.ts +24 -11
  126. package/src/redirect-emit.test.ts +6 -5
  127. package/src/release-manifest.ts +33 -4
  128. package/src/session-cookie.test.ts +96 -0
  129. package/src/session-cookie.ts +163 -0
  130. package/src/staging-plugin-stub.test.ts +23 -0
  131. package/src/staging-plugin-stub.ts +37 -0
  132. package/src/template-engine-lists.test.ts +27 -1
  133. package/src/template-engine.ts +4 -1
  134. package/src/version.ts +1 -1
@@ -153,8 +153,9 @@ describe("GCP URL-map rules", () => {
153
153
  });
154
154
 
155
155
  it("refuses a plan over the 1,000-predicate quota with the counts, before any change", () => {
156
- // The base rule routes /api/* and the remote-MCP discovery paths (#806).
157
- expect(GCP_PUBLIC_BASE_PATHS).toHaveLength(3);
156
+ // The base rules route /api/* to the gateway and /api/mcp/* plus the
157
+ // remote-MCP discovery paths to the MCP-Auth-Proxy (#806, #1328).
158
+ expect(GCP_PUBLIC_BASE_PATHS).toHaveLength(4);
158
159
  const base = [{ paths: [...GCP_PUBLIC_BASE_PATHS] }];
159
160
  const rows = (n: number) => Array.from({ length: n }, (_, i) => row(`/p${i}`, "/x"));
160
161
  expect(() => assertGcpRedirectBudget(planOf(rows(498)), base)).not.toThrow();
@@ -163,12 +164,12 @@ describe("GCP URL-map rules", () => {
163
164
  throw new Error("expected GcpUrlMapBudgetError");
164
165
  } catch (e) {
165
166
  expect(e).toBeInstanceOf(GcpUrlMapBudgetError);
166
- expect((e as GcpUrlMapBudgetError).predicatesNeeded).toBe(1001);
167
- expect((e as Error).message).toContain("499 redirect(s) need 1001 paths");
167
+ expect((e as GcpUrlMapBudgetError).predicatesNeeded).toBe(1002);
168
+ expect((e as Error).message).toContain("499 redirect(s) need 1002 paths");
168
169
  expect((e as Error).message).toContain("bulk_delete_redirects");
169
170
  }
170
171
  // File-like paths cost one predicate each.
171
- const files = Array.from({ length: 997 }, (_, i) => row(`/p${i}.html`, "/x"));
172
+ const files = Array.from({ length: 996 }, (_, i) => row(`/p${i}.html`, "/x"));
172
173
  expect(() => assertGcpRedirectBudget(planOf(files), base)).not.toThrow();
173
174
  });
174
175
 
@@ -19,10 +19,25 @@ import { z } from "zod";
19
19
  export const RELEASE_CHANNELS = ["stable", "rc", "beta", "alpha"] as const;
20
20
  export type ReleaseChannel = (typeof RELEASE_CHANNELS)[number];
21
21
 
22
- /** The services a release ships images for. */
23
- export const RELEASE_IMAGES = ["admin", "gateway", "ops"] as const;
22
+ /**
23
+ * The services a release ships images for. Every release cut from now on
24
+ * signs all of them (scripts/release-manifest.ts requires a digest each);
25
+ * `mcp-auth-proxy` (#1328) is the one manifests of older releases lack —
26
+ * see {@link OPTIONAL_RELEASE_IMAGES}.
27
+ */
28
+ export const RELEASE_IMAGES = ["admin", "gateway", "ops", "mcp-auth-proxy"] as const;
24
29
  export type ReleaseImage = (typeof RELEASE_IMAGES)[number];
25
30
 
31
+ /**
32
+ * Images a signed manifest may lack because they were added after
33
+ * releases that are still installable or rolled back to: the
34
+ * MCP-Auth-Proxy got its own image in #1328, so every manifest signed
35
+ * before it names none. Optional in the schema (manifestVersion stays 1;
36
+ * readers older than the key strip it as an unknown key), required by the
37
+ * release script for every new release.
38
+ */
39
+ export const OPTIONAL_RELEASE_IMAGES: readonly ReleaseImage[] = ["mcp-auth-proxy"];
40
+
26
41
  /** A `sha256:<64 hex>` image / blob digest. */
27
42
  export const IMAGE_DIGEST = /^sha256:[0-9a-f]{64}$/;
28
43
 
@@ -39,7 +54,13 @@ export const ReleaseManifestSchema = z.object({
39
54
  manifestVersion: z.literal(1),
40
55
  version: z.string().regex(SEMVER, "expected a SemVer version without a leading v"),
41
56
  channel: z.enum(RELEASE_CHANNELS),
42
- digests: z.object({ admin: digest, gateway: digest, ops: digest }),
57
+ digests: z.object({
58
+ admin: digest,
59
+ gateway: digest,
60
+ ops: digest,
61
+ /** Absent on releases before #1328 (see {@link OPTIONAL_RELEASE_IMAGES}). */
62
+ "mcp-auth-proxy": digest.optional(),
63
+ }),
43
64
  /**
44
65
  * #1025 — the linux/amd64 platform manifest inside each image index of
45
66
  * `digests`. The release images are OCI indexes (buildx adds an
@@ -52,7 +73,15 @@ export const ReleaseManifestSchema = z.object({
52
73
  * and older readers ignore it; readers then list the index itself
53
74
  * (content-addressed, so it cannot be forged either).
54
75
  */
55
- platformDigests: z.object({ admin: digest, gateway: digest, ops: digest }).optional(),
76
+ platformDigests: z
77
+ .object({
78
+ admin: digest,
79
+ gateway: digest,
80
+ ops: digest,
81
+ /** Absent on releases before #1328 (see {@link OPTIONAL_RELEASE_IMAGES}). */
82
+ "mcp-auth-proxy": digest.optional(),
83
+ })
84
+ .optional(),
56
85
  minFromVersion: z.string().regex(SEMVER),
57
86
  infraContractVersion: z.number().int().positive(),
58
87
  migrations: z.object({
@@ -0,0 +1,96 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ import { describe, expect, it } from "bun:test";
4
+ import {
5
+ readSessionCookie,
6
+ SESSION_COOKIE_NAME,
7
+ SESSION_ENTRY,
8
+ type SessionEntry,
9
+ sessionCookieValue,
10
+ sessionSetCookieHeader,
11
+ } from "./session-cookie.js";
12
+
13
+ const NOW = 1_800_000_000;
14
+ const SIGNED_VID = "0b1c2d3e-4f50-4617-8899-aabbccddeeff.1799999000.ab12";
15
+ const STAGING = "session.1800003600.Zm9v-_bar";
16
+
17
+ function entries(o: Record<string, SessionEntry>): Map<string, SessionEntry> {
18
+ return new Map(Object.entries(o));
19
+ }
20
+
21
+ /** The Cookie header a browser sends back for a Set-Cookie value. */
22
+ function cookieFor(setCookie: string, others = ""): string {
23
+ return `${others}${setCookie.split(";")[0]}`;
24
+ }
25
+
26
+ describe("__session container (#1343)", () => {
27
+ it("is named __session: the only cookie Firebase Hosting forwards", () => {
28
+ expect(SESSION_COOKIE_NAME).toBe("__session");
29
+ });
30
+
31
+ it("round-trips several owners' entries without one clobbering another", () => {
32
+ const written = entries({
33
+ [SESSION_ENTRY.visitorId]: { value: SIGNED_VID, expiresAt: NOW + 100 },
34
+ [SESSION_ENTRY.staging]: { value: STAGING, expiresAt: NOW + 3600 },
35
+ });
36
+ const header = sessionSetCookieHeader(written, { nowSeconds: NOW, secure: true });
37
+ const read = readSessionCookie(cookieFor(header, "other=1; "), NOW);
38
+ expect([...read]).toEqual([...written].sort(([a], [b]) => a.localeCompare(b)));
39
+ });
40
+
41
+ it("sets HttpOnly, SameSite=Lax, Secure and the longest entry's Max-Age", () => {
42
+ const header = sessionSetCookieHeader(
43
+ entries({
44
+ vid: { value: SIGNED_VID, expiresAt: NOW + 100 },
45
+ login: { value: "a.1.b", expiresAt: NOW + 50 },
46
+ }),
47
+ { nowSeconds: NOW, secure: true },
48
+ );
49
+ expect(header).toStartWith("__session=");
50
+ expect(header).toContain("; Path=/; HttpOnly; SameSite=Lax; Max-Age=100; Secure");
51
+ expect(sessionSetCookieHeader(new Map(), { nowSeconds: NOW, secure: false })).toBe(
52
+ "__session=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0",
53
+ );
54
+ });
55
+
56
+ it("leaves out expired, malformed and unknown-shaped entries", () => {
57
+ const value = encodeURIComponent(
58
+ new URLSearchParams([
59
+ ["vid", `${NOW - 1}.${SIGNED_VID}`],
60
+ ["login", "notanumber.abc"],
61
+ ["Bad-Key", `${NOW + 9}.x`],
62
+ ["staging", `${NOW + 9}.has space`],
63
+ ["vid", `${NOW + 9}.fine`],
64
+ ["vid", `${NOW + 9}.repeated`],
65
+ ]).toString(),
66
+ );
67
+ const read = readSessionCookie(`__session=${value}`, NOW);
68
+ expect([...read]).toEqual([["vid", { value: "fine", expiresAt: NOW + 9 }]]);
69
+ expect(readSessionCookie("__session=%E0%A4%A", NOW).size).toBe(0);
70
+ expect(readSessionCookie("caelo_visitor_id=x", NOW).size).toBe(0);
71
+ expect(readSessionCookie(null, NOW).size).toBe(0);
72
+ });
73
+
74
+ it("refuses to write what it could not read back", () => {
75
+ expect(() => sessionCookieValue(entries({ vid: { value: "a;b", expiresAt: NOW } }))).toThrow(
76
+ "invalid value",
77
+ );
78
+ expect(() => sessionCookieValue(entries({ other: { value: "a", expiresAt: NOW } }))).toThrow(
79
+ "unknown entry key",
80
+ );
81
+ });
82
+
83
+ it("holds only the known owners' keys, so no visitor input can grow it (PR #1354 review)", () => {
84
+ const crafted = new URLSearchParams(
85
+ Array.from({ length: 20 }, (_, i) => [`k${i}`, `${NOW + 9}.x`] as [string, string]),
86
+ );
87
+ crafted.append("login", `${NOW + 9}.kept`);
88
+ const read = readSessionCookie(`__session=${encodeURIComponent(crafted.toString())}`, NOW);
89
+ expect([...read.keys()]).toEqual(["login"]);
90
+ // A gateway write on top of the full known set still serialises.
91
+ const all = new Map(read);
92
+ all.set("vid", { value: "v", expiresAt: NOW + 9 });
93
+ all.set("staging", { value: "s", expiresAt: NOW + 9 });
94
+ expect(() => sessionCookieValue(all)).not.toThrow();
95
+ });
96
+ });
@@ -0,0 +1,163 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * The one cookie the API gateway reads from a visitor's browser:
5
+ * `__session`, a container of named entries (#1343).
6
+ *
7
+ * ## Why one cookie, and why this name
8
+ *
9
+ * Firebase Hosting forwards exactly one cookie over a rewrite to Cloud Run,
10
+ * the one named `__session`, and strips every other
11
+ * (docs/dev/firebase-hosting-behaviour.md, section 1). On gcp-firebase a
12
+ * gateway cookie by any other name is set in the browser and never comes
13
+ * back. Every provider uses the same container (CLAUDE.md §11.B: one shape
14
+ * per tier), so no provider has a code path of its own and a site moved
15
+ * between providers keeps its visitors' state.
16
+ *
17
+ * ## Shape
18
+ *
19
+ * The cookie value is a URI-encoded `URLSearchParams` string, one parameter
20
+ * per entry: `<key>=<expiresAt>.<value>`. Known keys are in
21
+ * {@link SESSION_ENTRY}; each belongs to one owner, which writes, reads and
22
+ * verifies its own entry's value:
23
+ *
24
+ * - `vid` the visitor id (gateway, only with consent, #677)
25
+ * - `login` the visitor's login session (gateway, for the auth plugin)
26
+ * - `staging` reserved for the staging gate's session (E13 (a), #763)
27
+ *
28
+ * A component that updates one entry keeps every other entry it received,
29
+ * so entries of different owners never clash.
30
+ *
31
+ * ## What is and is not protected
32
+ *
33
+ * The container itself is not signed: `expiresAt` is metadata that sets the
34
+ * browser's Max-Age and lets the reader drop an entry that has run out.
35
+ * Changing it buys a client nothing it could not do anyway (keep or drop its
36
+ * own cookie). Every entry VALUE must carry its own integrity check, made
37
+ * and checked by its owner (the gateway HMAC-signs `vid` and `login` with
38
+ * its cookie secret and bounds their age itself).
39
+ */
40
+
41
+ /** The cookie name, the only one Firebase Hosting passes through a rewrite. */
42
+ export const SESSION_COOKIE_NAME = "__session";
43
+
44
+ /** The entries the container holds, by owner. */
45
+ export const SESSION_ENTRY = {
46
+ /** The gateway's visitor id, set only with the visitor's consent (#677). */
47
+ visitorId: "vid",
48
+ /** The gateway's signed visitor login session (auth plugin). */
49
+ login: "login",
50
+ /** Reserved for the staging gate's session cookie (E13 (a), #763). */
51
+ staging: "staging",
52
+ } as const;
53
+
54
+ /** One entry: an owner-verified value and when it runs out. */
55
+ export interface SessionEntry {
56
+ readonly value: string;
57
+ /** Unix seconds. Not authenticated; see the module comment. */
58
+ readonly expiresAt: number;
59
+ }
60
+
61
+ /** Entries by key, as {@link readSessionCookie} returns them. */
62
+ export type SessionEntries = ReadonlyMap<string, SessionEntry>;
63
+
64
+ /**
65
+ * The only keys the container holds. An unknown key is visitor input with
66
+ * no owner: reading leaves it out, so the container never grows past these
67
+ * three and a gateway write can never overflow it (PR #1354 review). A new
68
+ * owner adds its key to {@link SESSION_ENTRY}.
69
+ */
70
+ const KNOWN_KEYS: ReadonlySet<string> = new Set(Object.values(SESSION_ENTRY));
71
+ /** Values the entries' owners write: signed tokens, no separators of ours. */
72
+ const ENTRY_VALUE = /^[A-Za-z0-9._~-]{1,512}$/;
73
+
74
+ /** The raw `__session` value of a `Cookie` header, or null. */
75
+ function rawSessionCookie(cookieHeader: string | null): string | null {
76
+ if (!cookieHeader) return null;
77
+ for (const part of cookieHeader.split(/;\s*/)) {
78
+ const eq = part.indexOf("=");
79
+ if (eq > 0 && part.slice(0, eq).trim() === SESSION_COOKIE_NAME) {
80
+ return part.slice(eq + 1).trim();
81
+ }
82
+ }
83
+ return null;
84
+ }
85
+
86
+ /**
87
+ * Parse the request's `__session` container.
88
+ *
89
+ * Visitor-controlled input: a malformed container, entry or value, a key
90
+ * not in {@link SESSION_ENTRY} and a repeated key are left out rather than
91
+ * failing the request, and an entry past its `expiresAt` is left out too.
92
+ * The caller still verifies each value it uses.
93
+ *
94
+ * @param cookieHeader the request's `Cookie` header.
95
+ * @param nowSeconds the current time, unix seconds.
96
+ */
97
+ export function readSessionCookie(cookieHeader: string | null, nowSeconds: number): SessionEntries {
98
+ const out = new Map<string, SessionEntry>();
99
+ const raw = rawSessionCookie(cookieHeader);
100
+ if (!raw) return out;
101
+ let decoded: string;
102
+ try {
103
+ decoded = decodeURIComponent(raw);
104
+ } catch {
105
+ return out;
106
+ }
107
+ for (const [key, entry] of new URLSearchParams(decoded)) {
108
+ if (!KNOWN_KEYS.has(key) || out.has(key)) continue;
109
+ const dot = entry.indexOf(".");
110
+ const expRaw = entry.slice(0, dot);
111
+ const value = entry.slice(dot + 1);
112
+ if (dot <= 0 || !/^\d{1,12}$/.test(expRaw) || !ENTRY_VALUE.test(value)) continue;
113
+ const expiresAt = Number(expRaw);
114
+ if (expiresAt <= nowSeconds) continue;
115
+ out.set(key, { value, expiresAt });
116
+ }
117
+ return out;
118
+ }
119
+
120
+ /**
121
+ * Serialise entries into a `__session` cookie value (URI-encoded).
122
+ *
123
+ * @throws on a key or value {@link readSessionCookie} would not read back:
124
+ * an owner writing one is a bug, not visitor input.
125
+ */
126
+ export function sessionCookieValue(entries: SessionEntries): string {
127
+ const params = new URLSearchParams();
128
+ for (const [key, e] of [...entries].sort(([a], [b]) => a.localeCompare(b))) {
129
+ if (!KNOWN_KEYS.has(key)) throw new Error(`session cookie: unknown entry key "${key}"`);
130
+ if (!ENTRY_VALUE.test(e.value)) throw new Error(`session cookie: invalid value for "${key}"`);
131
+ if (!Number.isInteger(e.expiresAt) || e.expiresAt <= 0) {
132
+ throw new Error(`session cookie: invalid expiresAt for "${key}"`);
133
+ }
134
+ params.append(key, `${e.expiresAt}.${e.value}`);
135
+ }
136
+ return encodeURIComponent(params.toString());
137
+ }
138
+
139
+ /**
140
+ * The `Set-Cookie` header that stores `entries` as the `__session`
141
+ * container, or expires it when no entry is left.
142
+ *
143
+ * HttpOnly and SameSite=Lax always; Secure when `secure` (every deployed
144
+ * environment — plain-http local development cannot keep a Secure cookie).
145
+ * Max-Age follows the longest-lived entry.
146
+ */
147
+ export function sessionSetCookieHeader(
148
+ entries: SessionEntries,
149
+ opts: { readonly nowSeconds: number; readonly secure: boolean },
150
+ ): string {
151
+ const flags =
152
+ entries.size === 0
153
+ ? [`${SESSION_COOKIE_NAME}=`, "Path=/", "HttpOnly", "SameSite=Lax", "Max-Age=0"]
154
+ : [
155
+ `${SESSION_COOKIE_NAME}=${sessionCookieValue(entries)}`,
156
+ "Path=/",
157
+ "HttpOnly",
158
+ "SameSite=Lax",
159
+ `Max-Age=${Math.max(1, Math.max(...[...entries.values()].map((e) => e.expiresAt)) - opts.nowSeconds)}`,
160
+ ];
161
+ if (opts.secure) flags.push("Secure");
162
+ return flags.join("; ");
163
+ }
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ import { describe, expect, it } from "bun:test";
4
+ import {
5
+ isPluginCallPath,
6
+ STAGING_PLUGIN_STUB_BODY,
7
+ STAGING_PREVIEW_ERROR_KIND,
8
+ } from "./staging-plugin-stub.js";
9
+
10
+ describe("staging plugin stub (#1326)", () => {
11
+ it("is an ok:false answer of its own kind, with nothing else", () => {
12
+ expect(JSON.parse(STAGING_PLUGIN_STUB_BODY)).toEqual({
13
+ ok: false,
14
+ error: { kind: STAGING_PREVIEW_ERROR_KIND },
15
+ });
16
+ });
17
+
18
+ it("recognises plugin calls only", () => {
19
+ expect(isPluginCallPath("/api/plugin/forms/submit")).toBe(true);
20
+ expect(isPluginCallPath("/api/captcha/challenge")).toBe(false);
21
+ expect(isPluginCallPath("/api/variant.js")).toBe(false);
22
+ });
23
+ });
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * What a staged page's plugin call gets until staging has its own gateway
5
+ * (#1326 interim, #1329/#1330; epic #763 N4).
6
+ *
7
+ * The live gateway takes plugin posts only from a live-site Origin, and
8
+ * staging is never one: unreviewed module JS on staging must not write
9
+ * into live data. A plain 403 would make every staged page with a plugin
10
+ * component log "Failed to load resource" in the browser console, which the
11
+ * Stage quality audit counts as a page error and which would then block
12
+ * Publish live. So the two places a staged page's `/api/plugin/*` call can
13
+ * reach answer it with this instead, without dispatching anything:
14
+ *
15
+ * - the API gateway, for a POST whose Origin is the staging host
16
+ * (gcp-firebase, self-hosted: staging's `/api` reaches the live gateway);
17
+ * - the audit's loopback origin (admin-core `quality/staged-origin.ts`,
18
+ * gcp / aws / azure), which no longer forwards plugin calls to live.
19
+ *
20
+ * HTTP 200 with `ok: false`: the browser logs nothing, and the component
21
+ * takes its ordinary "no data" / "failed" path (plugin-component-kit
22
+ * `postPluginJson` callers all read `ok`).
23
+ */
24
+
25
+ /** The error kind a staged page's plugin call answers with. */
26
+ export const STAGING_PREVIEW_ERROR_KIND = "StagingPreview";
27
+
28
+ /** The JSON body of that answer. */
29
+ export const STAGING_PLUGIN_STUB_BODY = JSON.stringify({
30
+ ok: false,
31
+ error: { kind: STAGING_PREVIEW_ERROR_KIND },
32
+ });
33
+
34
+ /** Whether `pathname` is a plugin operation call (`/api/plugin/…`). */
35
+ export function isPluginCallPath(pathname: string): boolean {
36
+ return pathname.startsWith("/api/plugin/");
37
+ }
@@ -19,7 +19,7 @@ import {
19
19
  TERM,
20
20
  } from "./lists/list-fixtures.test.js";
21
21
  import { createListRenderContext, type ListPageContext } from "./lists/resolve.js";
22
- import { renderTemplate, type TemplateField } from "./template-engine.js";
22
+ import { renderTemplate, type TemplateField, templateFieldsFromJson } from "./template-engine.js";
23
23
 
24
24
  function ctx(
25
25
  pageId: string | null = PAGE.home,
@@ -397,6 +397,32 @@ describe("lists — {{page.*}}", () => {
397
397
  '<img src="/_caelo/media/hero" alt="Hero">We launched.|4;<img src="" alt="">|5;',
398
398
  );
399
399
  });
400
+
401
+ // #1304 — a stored `modules.fields` jsonb whose query source omits
402
+ // `editable` renders through the parsed source (editable: []), never a
403
+ // raw one the resolver would read `editable` off.
404
+ it("a stored query source without editable renders (#1304)", () => {
405
+ const fields = templateFieldsFromJson([
406
+ {
407
+ name: "latest",
408
+ kind: "list",
409
+ listType: "links",
410
+ bind: "source",
411
+ source: {
412
+ kind: "query",
413
+ defaults: { page_type: "news", order: "prop_asc:rating", limit: 5 },
414
+ },
415
+ },
416
+ ]);
417
+ expect(fields[0]?.source).toEqual({
418
+ kind: "query",
419
+ editable: [],
420
+ defaults: { page_type: "news", order: "prop_asc:rating", limit: 5 },
421
+ });
422
+ const r = render("{{#latest}}{{props.rating}};{{/latest}}", fields, {}, ctx(PAGE.home));
423
+ expect(r.html).toBe("4;5;");
424
+ expect(r.missingSlots).toEqual([]);
425
+ });
400
426
  });
401
427
 
402
428
  describe("lists — terms", () => {
@@ -140,6 +140,9 @@ export function templateFieldsFromJson(raw: unknown): TemplateField[] {
140
140
  if (!f || typeof f !== "object") continue;
141
141
  const o = f as Record<string, unknown>;
142
142
  if (typeof o.name !== "string") continue;
143
+ // The parsed source, not the stored one: parsing fills defaults
144
+ // (`editable: []` when the source omits it, #1304).
145
+ const source = sourceDefSchema.safeParse(o.source);
143
146
  out.push({
144
147
  name: o.name,
145
148
  kind: (typeof o.kind === "string" ? o.kind : "text") as ModuleFieldKind,
@@ -149,7 +152,7 @@ export function templateFieldsFromJson(raw: unknown): TemplateField[] {
149
152
  ...(typeof o.list === "string" ? { list: o.list } : {}),
150
153
  // A source that fails its schema stays absent: the resolver then
151
154
  // reports `list-malformed:<field>[source]` instead of guessing.
152
- ...(sourceDefSchema.safeParse(o.source).success ? { source: o.source as SourceDef } : {}),
155
+ ...(source.success ? { source: source.data } : {}),
153
156
  // Passed as stored: the resolver validates it and reports a
154
157
  // malformed one as `list-malformed:<field>[paginate]`.
155
158
  ...(o.paginate !== undefined ? { paginate: o.paginate as ListPaginationSettings } : {}),
package/src/version.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  * follow standard SemVer.
23
23
  */
24
24
 
25
- export const CAELO_VERSION = "0.11.8";
25
+ export const CAELO_VERSION = "0.11.10";
26
26
 
27
27
  /**
28
28
  * Deprecated alias for back-compat — early P17 work spelled this