@simpleapps-com/augur-server 2026.11.4 → 2026.11.6
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/EXPORTS.md +28 -1
- package/README.md +42 -14
- package/dist/actions/action-rules.d.ts +99 -0
- package/dist/actions/action-rules.d.ts.map +1 -0
- package/dist/actions/agr-site.d.ts +7 -15
- package/dist/actions/agr-site.d.ts.map +1 -1
- package/dist/actions/commerce.d.ts.map +1 -1
- package/dist/actions/customers.d.ts +12 -15
- package/dist/actions/customers.d.ts.map +1 -1
- package/dist/actions/favorites.d.ts +9 -12
- package/dist/actions/favorites.d.ts.map +1 -1
- package/dist/actions/gregorovich.d.ts +7 -15
- package/dist/actions/gregorovich.d.ts.map +1 -1
- package/dist/actions/items.d.ts +8 -20
- package/dist/actions/items.d.ts.map +1 -1
- package/dist/actions/joomla.d.ts +8 -14
- package/dist/actions/joomla.d.ts.map +1 -1
- package/dist/actions/legacy.d.ts +10 -20
- package/dist/actions/legacy.d.ts.map +1 -1
- package/dist/actions/orders.d.ts +7 -14
- package/dist/actions/orders.d.ts.map +1 -1
- package/dist/actions/read-specs.d.ts +119 -0
- package/dist/actions/read-specs.d.ts.map +1 -0
- package/dist/actions/site.d.ts.map +1 -1
- package/dist/actions/vmi.d.ts +10 -16
- package/dist/actions/vmi.d.ts.map +1 -1
- package/dist/actions/wishlists.d.ts +11 -13
- package/dist/actions/wishlists.d.ts.map +1 -1
- package/dist/api.js +3 -2
- package/dist/api.js.map +1 -1
- package/dist/auth.js +3 -2
- package/dist/cache/redis-client.d.ts.map +1 -1
- package/dist/cache/redis-rules.d.ts +21 -0
- package/dist/cache/redis-rules.d.ts.map +1 -0
- package/dist/cache/spec-read.d.ts +39 -0
- package/dist/cache/spec-read.d.ts.map +1 -0
- package/dist/cache/with-cache.d.ts +2 -2
- package/dist/cache/with-cache.d.ts.map +1 -1
- package/dist/{chunk-WR7WT2FI.js → chunk-2RAKVFB5.js} +30 -9
- package/dist/chunk-2RAKVFB5.js.map +1 -0
- package/dist/{chunk-F7QWHMHH.js → chunk-4JPJQHT6.js} +2 -2
- package/dist/chunk-JIYVQWXK.js +10 -0
- package/dist/chunk-JIYVQWXK.js.map +1 -0
- package/dist/{chunk-34NCJS52.js → chunk-SFXO74RC.js} +874 -719
- package/dist/chunk-SFXO74RC.js.map +1 -0
- package/dist/chunk-V76GZZF3.js +66 -0
- package/dist/chunk-V76GZZF3.js.map +1 -0
- package/dist/{chunk-B4MGIUCU.js → chunk-Z53NEFEQ.js} +17 -16
- package/dist/chunk-Z53NEFEQ.js.map +1 -0
- package/dist/hooks.js +3 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/query-action.d.ts +24 -1
- package/dist/query-action.d.ts.map +1 -1
- package/dist/query-action.js +7 -2
- package/dist/read-rules.d.ts +45 -0
- package/dist/read-rules.d.ts.map +1 -0
- package/dist/rules.d.ts +16 -0
- package/dist/rules.d.ts.map +1 -1
- package/dist/server-site-registry.d.ts.map +1 -1
- package/dist/server-site.d.ts.map +1 -1
- package/dist/site.js +24 -14
- package/dist/site.js.map +1 -1
- package/dist/sitemap-rules.d.ts +154 -0
- package/dist/sitemap-rules.d.ts.map +1 -0
- package/dist/sitemap.d.ts +80 -0
- package/dist/sitemap.d.ts.map +1 -0
- package/dist/sitemap.js +242 -0
- package/dist/sitemap.js.map +1 -0
- package/dist/testing.js +4 -2
- package/dist/testing.js.map +1 -1
- package/dist/utils/read-all-pages.d.ts +17 -0
- package/dist/utils/read-all-pages.d.ts.map +1 -0
- package/llms.txt +54 -1
- package/package.json +9 -5
- package/dist/chunk-34NCJS52.js.map +0 -1
- package/dist/chunk-B4MGIUCU.js.map +0 -1
- package/dist/chunk-WR7WT2FI.js.map +0 -1
- /package/dist/{chunk-F7QWHMHH.js.map → chunk-4JPJQHT6.js.map} +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// ../foundation/src/chars.ts
|
|
2
|
+
function isDigit(c) {
|
|
3
|
+
return c >= 48 && c <= 57;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// ../utils/src/strings.ts
|
|
7
|
+
function codeAt(s, i) {
|
|
8
|
+
return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
|
|
9
|
+
}
|
|
10
|
+
function digitsFrom(s, i) {
|
|
11
|
+
return i >= s.length || isDigit(s.charCodeAt(i)) && digitsFrom(s, i + 1);
|
|
12
|
+
}
|
|
13
|
+
function indexOfCode(s, code, from) {
|
|
14
|
+
const c = codeAt(s, from);
|
|
15
|
+
if (c === code) return from;
|
|
16
|
+
if (c === -1) return -1;
|
|
17
|
+
return indexOfCode(s, code, from + 1);
|
|
18
|
+
}
|
|
19
|
+
function rStripCode(s, code) {
|
|
20
|
+
if (codeAt(s, s.length - 1) === code) {
|
|
21
|
+
return rStripCode(s.slice(0, s.length - 1), code);
|
|
22
|
+
}
|
|
23
|
+
return s;
|
|
24
|
+
}
|
|
25
|
+
function startsWithAt(s, x, pos) {
|
|
26
|
+
const at = Math.min(pos, s.length);
|
|
27
|
+
return s.slice(at, Math.min(at + x.length, s.length)) === x;
|
|
28
|
+
}
|
|
29
|
+
function endsWith(s, suffix) {
|
|
30
|
+
return s.slice(Math.max(s.length - suffix.length, 0)) === suffix;
|
|
31
|
+
}
|
|
32
|
+
function isCanonicalNat(s) {
|
|
33
|
+
if (s === "0") return true;
|
|
34
|
+
const first = codeAt(s, 0);
|
|
35
|
+
return first >= 49 && first <= 57 && digitsFrom(s, 1);
|
|
36
|
+
}
|
|
37
|
+
function digitsValue(s) {
|
|
38
|
+
if (s.length === 0) return 0;
|
|
39
|
+
return digitsValue(s.slice(0, s.length - 1)) * 10 + (s.charCodeAt(s.length - 1) - 48);
|
|
40
|
+
}
|
|
41
|
+
function canonicalNatValue(s) {
|
|
42
|
+
if (!isCanonicalNat(s)) return 0;
|
|
43
|
+
return digitsValue(s);
|
|
44
|
+
}
|
|
45
|
+
function lineFeed() {
|
|
46
|
+
return `
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
function upperAscii(s) {
|
|
50
|
+
if (s.length === 0) return "";
|
|
51
|
+
const c = s.charCodeAt(0);
|
|
52
|
+
const head = c >= 97 && c <= 122 ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ".slice(c - 97, c - 96) : s.slice(0, 1);
|
|
53
|
+
return head + upperAscii(s.slice(1));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
indexOfCode,
|
|
58
|
+
rStripCode,
|
|
59
|
+
startsWithAt,
|
|
60
|
+
endsWith,
|
|
61
|
+
isCanonicalNat,
|
|
62
|
+
canonicalNatValue,
|
|
63
|
+
lineFeed,
|
|
64
|
+
upperAscii
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=chunk-V76GZZF3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../foundation/src/chars.ts","../../utils/src/strings.ts"],"sourcesContent":["//@ backend dafny\n\n/* Character classes over UTF-16 code units (what charCodeAt returns), verified with\n LemmaScript → Dafny (model: models/Foundation.dfy; link: models/links/foundation-chars.dfy).\n Every contract is an iff, so an importer, which sees only the contract, knows each class\n exactly. */\n\n/**\n * A decimal digit: 0-9.\n *\n * @ensures result ⟺ c ∈ [48, 57]\n */\nexport function isDigit(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> (c >= 48 && c <= 57)\n return c >= 48 && c <= 57;\n}\n\n/**\n * A JS line terminator (what regex `.` doesn't match): LF, CR, LS, PS.\n *\n * @ensures result ⟺ c ∈ {10, 13, 8232, 8233}\n */\nexport function isLineTerminator(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> (c === 10 || c === 13 || c === 8232 || c === 8233)\n return c === 10 || c === 13 || c === 8232 || c === 8233;\n}\n\n/**\n * The code ASCII-lowered: A-Z to a-z, any other value (-1 from `codeAt` included) unchanged.\n *\n * @ensures exactly the model's LowerCode\n */\nexport function lowerCode(c: number): number {\n //@ verify\n //@ ensures \\result === (c >= 65 && c <= 90 ? c + 32 : c)\n return c >= 65 && c <= 90 ? c + 32 : c;\n}\n/**\n * A lowercase ASCII letter: a-z.\n *\n * @ensures result ⟺ c ∈ [97, 122]\n */\nexport function isLowerAlphaChar(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> (c >= 97 && c <= 122)\n return c >= 97 && c <= 122;\n}\n\n/**\n * An ASCII letter or digit: A-Z a-z 0-9.\n *\n * @ensures result ⟺ c ∈ [A-Z] ∪ [a-z] ∪ [0-9]\n */\nexport function isAlnumChar(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57))\n return (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57);\n}\n\n/**\n * A lowercase hex digit: 0-9 a-f.\n *\n * @ensures result ⟺ c ∈ [0-9] ∪ [a-f]\n */\nexport function isLowerHexChar(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 48 && c <= 57) || (c >= 97 && c <= 102))\n return (c >= 48 && c <= 57) || (c >= 97 && c <= 102);\n}\n\n/**\n * A hex digit in either case: 0-9 a-f A-F.\n *\n * @ensures result ⟺ c ∈ [0-9] ∪ [a-f] ∪ [A-F]\n */\nexport function isHexChar(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 48 && c <= 57) || (c >= 97 && c <= 102) || (c >= 65 && c <= 70))\n return (c >= 48 && c <= 57) || (c >= 97 && c <= 102) || (c >= 65 && c <= 70);\n}\n\n/**\n * A base64url character (RFC 4648 §5): A-Z a-z 0-9 - _.\n *\n * @ensures result ⟺ c ∈ [A-Z] ∪ [a-z] ∪ [0-9] ∪ {\"-\", \"_\"} — never \".\" or \"=\"\n */\nexport function isBase64UrlChar(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 45 || c === 95)\n return (\n (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 45 || c === 95\n );\n}\n\n/**\n * JS whitespace, the regex `\\s` and what `trim()` strips: tab, LF, VT, FF, CR, space, NBSP,\n * U+1680, U+2000-U+200A, LS, PS, U+202F, U+205F, U+3000 and the BOM.\n *\n * @ensures result ⟺ c ∈ {9..13, 32, 160, 5760, 8192..8202, 8232, 8233, 8239, 8287, 12288, 65279}\n */\nexport function isJsSpace(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 9 && c <= 13) || c === 32 || c === 160 || c === 5760 || (c >= 8192 && c <= 8202) || c === 8232 || c === 8233 || c === 8239 || c === 8287 || c === 12288 || c === 65279)\n return isAsciiSpace(c) || isGeneralPunctuationSpace(c) || isOtherSpace(c);\n}\n\n/**\n * ASCII whitespace: tab, LF, VT, FF, CR and space.\n *\n * @ensures result ⟺ c ∈ [9, 13] ∪ {32}\n */\nfunction isAsciiSpace(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 9 && c <= 13) || c === 32)\n return (c >= 9 && c <= 13) || c === 32;\n}\n\n/**\n * The spaces in the General Punctuation block: U+2000-U+200A, LS, PS, U+202F, U+205F.\n *\n * @ensures result ⟺ c ∈ [8192, 8202] ∪ {8232, 8233, 8239, 8287}\n */\nfunction isGeneralPunctuationSpace(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 8192 && c <= 8202) || c === 8232 || c === 8233 || c === 8239 || c === 8287)\n return (c >= 8192 && c <= 8202) || c === 8232 || c === 8233 || c === 8239 || c === 8287;\n}\n\n/**\n * The other spaces: NBSP, U+1680 (Ogham), U+3000 (ideographic) and the BOM.\n *\n * @ensures result ⟺ c ∈ {160, 5760, 12288, 65279}\n */\nfunction isOtherSpace(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> (c === 160 || c === 5760 || c === 12288 || c === 65279)\n return c === 160 || c === 5760 || c === 12288 || c === 65279;\n}\n\n/**\n * A word character, the regex `\\w`: A-Z a-z 0-9 _.\n *\n * @ensures result ⟺ c ∈ [A-Z] ∪ [a-z] ∪ [0-9] ∪ {\"_\"}\n */\nexport function isWordChar(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 95)\n return (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 95;\n}\n\n/**\n * A snake_case character: a-z 0-9 _.\n *\n * @ensures result ⟺ c ∈ [a-z] ∪ [0-9] ∪ {\"_\"}\n */\nexport function isSnakeChar(c: number): boolean {\n //@ verify\n //@ ensures \\result <==> ((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 95)\n return (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 95;\n}\n","//@ backend dafny\nimport {\n isAlnumChar,\n isBase64UrlChar,\n isDigit,\n isHexChar,\n isJsSpace,\n isLineTerminator,\n isLowerHexChar,\n isSnakeChar,\n isWordChar,\n lowerCode,\n} from \"@atlas/foundation/chars\";\n\n/* String scans and slices, verified with LemmaScript → Dafny (hand lemmas in strings.dfy;\n model: models/Utils.dfy; link: models/links/utils-strings.dfy). Recursive and\n expression-bodied so specs can use them, and each contract pins the result exactly, so\n an importer (which sees only the contract) knows what it returns. Two of them stand in\n for constructs lsc mistranslates: `prefix` for an unclamped `slice`, and the code-unit\n scans for \"\\r\" / \"\\n\" literals. */\n\n/**\n * The code unit at `i`, or -1 when `i` is outside `s`. JS `charCodeAt` gives NaN there,\n * which no code equals, so a scan's own bounds test would change no result and no test\n * could tell it from none (an equivalent mutant); with the bound here once, the boundary is\n * observable (tests pin -1) and the scans that use it carry no bound of their own. A code\n * unit is never negative, so -1 matches no `code` a caller passes (`requires code >= 0`).\n *\n * @ensures 0 ≤ i < |s| ⟹ result = s[i]; otherwise result = -1\n */\nexport function codeAt(s: string, i: number): number {\n //@ verify\n //@ ensures (i >= 0 && i < s.length) ==> \\result === s.charCodeAt(i)\n //@ ensures !(i >= 0 && i < s.length) ==> \\result === -1\n return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;\n}\n\n/**\n * Every character of `s` from index `i` on is base64url.\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). isBase64UrlChar(s[k])\n */\nexport function base64UrlFrom(s: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> isBase64UrlChar(s.charCodeAt(k)))\n return i >= s.length || (isBase64UrlChar(s.charCodeAt(i)) && base64UrlFrom(s, i + 1));\n}\n\n/**\n * The base64url digit for `v` (RFC 4648 §5): A-Z a-z 0-9 - _.\n *\n * @ensures exactly the model's Base64UrlDigit\n */\nexport function base64UrlDigit(v: number): string {\n //@ verify\n //@ type v nat\n //@ requires v >= 0 && v < 64\n //@ ensures \\result === \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\".slice(v, v + 1)\n return \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\".slice(v, v + 1);\n}\n\n/**\n * Bytes from `i` on as unpadded base64url: each three as four digits, a last one or two as two or\n * three (JS `btoa` with `+/` as `-_` and the `=` dropped). One frame per three bytes: a JWT part\n * is a few hundred.\n *\n * @ensures exactly the model's Base64UrlFrom (links/utils-strings.dfy)\n */\nexport function encodeBase64UrlFrom(b: number[], i: number): string {\n //@ verify\n //@ type i nat\n //@ requires i >= 0 && forall(k: nat, k < b.length ==> (b[k] >= 0 && b[k] < 256))\n //@ decreases b.length - i\n //@ ensures i >= b.length ==> \\result === \"\"\n if (i >= b.length) return \"\";\n const x = b[i] as number;\n const first = base64UrlDigit(Math.floor(x / 4));\n if (i + 1 === b.length) return first + base64UrlDigit((x % 4) * 16);\n const y = b[i + 1] as number;\n const second = base64UrlDigit((x % 4) * 16 + Math.floor(y / 16));\n if (i + 2 === b.length) return first + second + base64UrlDigit((y % 16) * 4);\n const z = b[i + 2] as number;\n return (\n first +\n second +\n base64UrlDigit((y % 16) * 4 + Math.floor(z / 64)) +\n base64UrlDigit(z % 64) +\n encodeBase64UrlFrom(b, i + 3)\n );\n}\n\n/**\n * Every character of `s` from index `i` on is lowercase hex.\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). isLowerHexChar(s[k])\n */\nexport function lowerHexFrom(s: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> isLowerHexChar(s.charCodeAt(k)))\n return i >= s.length || (isLowerHexChar(s.charCodeAt(i)) && lowerHexFrom(s, i + 1));\n}\n\n/**\n * Every character of `s` from index `i` on is hex, either case.\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). isHexChar(s[k])\n */\nexport function hexFrom(s: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> isHexChar(s.charCodeAt(k)))\n return i >= s.length || (isHexChar(s.charCodeAt(i)) && hexFrom(s, i + 1));\n}\n\n/**\n * Every character of `s` from index `i` on is an ASCII digit (`\\d` without the `u` flag).\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). isDigit(s[k])\n */\nexport function digitsFrom(s: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> isDigit(s.charCodeAt(k)))\n return i >= s.length || (isDigit(s.charCodeAt(i)) && digitsFrom(s, i + 1));\n}\n\n/**\n * Every character of `s` from index `i` on is a word character (`\\w`: `[A-Za-z0-9_]`).\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). isWordChar(s[k])\n */\nexport function wordCharsFrom(s: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> isWordChar(s.charCodeAt(k)))\n return i >= s.length || (isWordChar(s.charCodeAt(i)) && wordCharsFrom(s, i + 1));\n}\n\n/**\n * Every character of `s` from index `i` on is a snake_case character (`[a-z0-9_]`).\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). isSnakeChar(s[k])\n */\nexport function snakeCharsFrom(s: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> isSnakeChar(s.charCodeAt(k)))\n return i >= s.length || (isSnakeChar(s.charCodeAt(i)) && snakeCharsFrom(s, i + 1));\n}\n\n/**\n * Every character of `s` from index `i` on is an ASCII letter or digit (`[A-Za-z0-9]`).\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). isAlnumChar(s[k])\n */\nexport function alnumFrom(s: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> isAlnumChar(s.charCodeAt(k)))\n return i >= s.length || (isAlnumChar(s.charCodeAt(i)) && alnumFrom(s, i + 1));\n}\n\n/**\n * Every character of `s` from index `i` on is an ASCII letter, digit or `-` (`[A-Za-z0-9-]`):\n * a domain label's tail, a service name's tail.\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). isAlnumChar(s[k]) ∨ s[k] = \"-\" — the model's AlnumDashFrom\n */\nexport function alnumDashFrom(s: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> (isAlnumChar(s.charCodeAt(k)) || s.charCodeAt(k) === 45))\n if (i >= s.length) return true;\n const c = s.charCodeAt(i);\n return (isAlnumChar(c) || c === 45) && alnumDashFrom(s, i + 1);\n}\n\n/**\n * The last index before `end` holding `code`, or -1 (JS `s.lastIndexOf(c)` at end = |s|).\n *\n * @ensures result = -1 ∨ (0 ≤ result < end ∧ s[result] = code ∧ no `code` in (result, end))\n */\nexport function lastIndexOfCode(s: string, code: number, end: number): number {\n //@ verify\n //@ type end nat\n //@ requires 0 <= end && end <= s.length\n //@ decreases end\n //@ ensures \\result === -1 || (0 <= \\result && \\result < end)\n //@ ensures \\result >= 0 ==> s.charCodeAt(\\result) === code\n //@ ensures \\result >= 0 ==> forall(k: nat, (\\result < k && k < end) ==> s.charCodeAt(k) !== code)\n //@ ensures \\result === -1 ==> forall(k: nat, k < end ==> s.charCodeAt(k) !== code)\n if (end === 0) return -1;\n if (s.charCodeAt(end - 1) === code) return end - 1;\n return lastIndexOfCode(s, code, end - 1);\n}\n\n/**\n * No character of `s` from index `i` on is `code`.\n *\n * @ensures result ⟺ ∀ k ∈ [i, |s|). s[k] ≠ code\n */\nexport function lacksCode(s: string, code: number, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires 0 <= i && i <= s.length\n //@ decreases s.length - i\n //@ ensures \\result <==> forall(k: nat, (i <= k && k < s.length) ==> s.charCodeAt(k) !== code)\n // `===`, not `>=`: past the end a read is NaN !== code, so `>=` vs `>` would be equivalent\n return i === s.length || (s.charCodeAt(i) !== code && lacksCode(s, code, i + 1));\n}\n\n/**\n * The end of the run of `code` starting at `i`: the first index ≥ i that isn't `code`\n * (skip spaces: `codeRunEnd(header, 32, i)`).\n *\n * @requires i ≤ |s|\n * @ensures i ≤ result ≤ |s| ∧ ∀ k ∈ [i, result). s[k] = code ∧ (result < |s| ⟹ s[result] ≠ code)\n * — exactly the run's end\n */\nexport function codeRunEnd(s: string, code: number, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires 0 <= i && i <= s.length\n //@ requires code >= 0\n //@ decreases s.length - i\n //@ ensures i <= \\result && \\result <= s.length\n //@ ensures forall(k: nat, (i <= k && k < \\result) ==> s.charCodeAt(k) === code)\n //@ ensures \\result < s.length ==> s.charCodeAt(\\result) !== code\n return codeAt(s, i) === code ? codeRunEnd(s, code, i + 1) : i;\n}\n\n/**\n * The first index ≥ `from` holding `code`, or -1 (`indexOf` for one code unit, so \"\\n\" is\n * passed as 10, never as a literal).\n *\n * @ensures result = -1 ∨ (from ≤ result < |s| ∧ s[result] = code), with no `code` in\n * [from, result) — the first one; result = -1 ⟹ none from `from` on\n */\nexport function indexOfCode(s: string, code: number, from: number): number {\n //@ verify\n //@ type from nat\n //@ requires code >= 0 && from >= 0\n //@ decreases s.length - from\n //@ ensures \\result === -1 || (from <= \\result && \\result < s.length)\n //@ ensures \\result >= 0 ==> s.charCodeAt(\\result) === code\n //@ ensures \\result >= 0 ==> forall(k: nat, (from <= k && k < \\result) ==> s.charCodeAt(k) !== code)\n //@ ensures \\result === -1 ==> forall(k: nat, (from <= k && k < s.length) ==> s.charCodeAt(k) !== code)\n const c = codeAt(s, from);\n if (c === code) return from;\n if (c === -1) return -1;\n return indexOfCode(s, code, from + 1);\n}\n\n/**\n * The first index ≥ `i` holding `a` or `b`, or |s| (a run either code ends: a path segment's\n * run to \"/\" or \"?\"). One scan: the lesser of two `indexOfCode` ends is the same index, but\n * its two sides are equal only when both are |s|, a boundary no test can observe.\n *\n * @requires i ≤ |s|\n * @ensures i ≤ result ≤ |s| ∧ ∀ k ∈ [i, result). s[k] ∉ {a, b} ∧ (result < |s| ⟹ s[result] ∈ {a, b})\n * — exactly the first such index\n */\nexport function eitherCodeEnd(s: string, a: number, b: number, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires 0 <= i && i <= s.length\n //@ requires a >= 0 && b >= 0\n //@ decreases s.length - i\n //@ ensures i <= \\result && \\result <= s.length\n //@ ensures forall(k: nat, (i <= k && k < \\result) ==> (s.charCodeAt(k) !== a && s.charCodeAt(k) !== b))\n //@ ensures \\result < s.length ==> (s.charCodeAt(\\result) === a || s.charCodeAt(\\result) === b)\n const c = codeAt(s, i);\n if (c === -1 || c === a || c === b) return i;\n return eitherCodeEnd(s, a, b, i + 1);\n}\n\n/**\n * `s` without one trailing `code` (\"\\r\" before a \"\\n\", say); unchanged otherwise.\n *\n * @ensures s ends with code ⟹ result = s[0, |s| − 1)\n * @ensures otherwise result = s\n */\nexport function dropLast(s: string, code: number): string {\n //@ verify\n //@ requires code >= 0\n //@ ensures (s.length > 0 && s.charCodeAt(s.length - 1) === code) ==> \\result === s.slice(0, s.length - 1)\n //@ ensures !(s.length > 0 && s.charCodeAt(s.length - 1) === code) ==> \\result === s\n return codeAt(s, s.length - 1) === code ? s.slice(0, s.length - 1) : s;\n}\n\n/**\n * `s` without its leading `code` units (every one of them).\n *\n * @ensures exactly the model's LStripCode\n */\nexport function lStripCode(s: string, code: number): string {\n //@ verify\n //@ requires code >= 0\n //@ decreases s.length\n //@ ensures \\result.length <= s.length\n if (codeAt(s, 0) === code) return lStripCode(s.slice(1), code);\n return s;\n}\n\n/**\n * `s` without its trailing `code` units (every one of them).\n *\n * @ensures exactly the model's RStripCode\n */\nexport function rStripCode(s: string, code: number): string {\n //@ verify\n //@ requires code >= 0\n //@ decreases s.length\n //@ ensures \\result.length <= s.length\n if (codeAt(s, s.length - 1) === code) {\n return rStripCode(s.slice(0, s.length - 1), code);\n }\n return s;\n}\n\n/**\n * `s` without its leading and trailing `code` units, the middle kept (`/a/b/` with `/` →\n * `a/b`).\n *\n * @ensures exactly the model's StripCode — neither end is `code` (StripCodeTrims)\n */\nexport function stripCode(s: string, code: number): string {\n //@ verify\n //@ requires code >= 0\n //@ ensures \\result === rStripCode(lStripCode(s, code), code)\n return rStripCode(lStripCode(s, code), code);\n}\n\n/**\n * JS `s.startsWith(x, pos)`, which lsc mistranslates (it drops `pos`). Like JS, a `pos`\n * past the end counts as the end, so the empty string matches anywhere.\n *\n * @ensures pos ≤ |s| ⟹ (result ⟺ pos + |x| ≤ |s| ∧ s[pos, pos + |x|) = x) — so a true\n * result also gives the bounds for slicing after the match\n * @ensures pos > |s| ⟹ (result ⟺ x = \"\")\n */\nexport function startsWithAt(s: string, x: string, pos: number): boolean {\n //@ verify\n //@ type pos nat\n //@ requires pos >= 0\n //@ ensures pos <= s.length ==> (\\result <==> (pos + x.length <= s.length && s.slice(pos, pos + x.length) === x))\n //@ ensures pos > s.length ==> (\\result <==> x.length === 0)\n // Math.min, not a ternary: at pos = |s| both branches agree, so `<` vs `<=` is equivalent\n const at = Math.min(pos, s.length);\n // The slice is clamped to the end, so a too-long x differs by length: no separate fit test\n // (JS slice clamps too, which made one unobservable)\n return s.slice(at, Math.min(at + x.length, s.length)) === x;\n}\n\n/**\n * `s` with A-Z lowercased and every other character kept: what lsc's proofs take\n * `toLowerCase()` to be. JS's `toLowerCase()` also maps non-ASCII letters, some onto ASCII\n * (the Kelvin sign K, U+212A, becomes \"k\") or onto two characters (İ, U+0130), so a proved\n * function that lowercases MUST use this, or the runtime does what the proof says it\n * doesn't.\n *\n * @ensures |result| = |s| ∧ ∀ k < |s|. result[k] = (s[k] ∈ A-Z ? s[k] + 32 : s[k]) — A-Z\n * lowered, every other code unit unchanged; true in JS (a contract `=== s.toLowerCase()` held\n * only in lsc's ASCII model of the built-in, Fable review 2026-11-06). Helper-free, since an\n * importer is given only the helpers its own body calls; exactly the model's LowerAscii in\n * the link\n */\nexport function lowerAscii(s: string): string {\n //@ verify\n //@ decreases s.length\n //@ ensures \\result.length === s.length\n //@ ensures forall(k: nat, k < s.length ==> \\result.charCodeAt(k) === ((s.charCodeAt(k) >= 65 && s.charCodeAt(k) <= 90) ? s.charCodeAt(k) + 32 : s.charCodeAt(k)))\n if (s.length === 0) return \"\";\n const c = s.charCodeAt(0);\n const head =\n c >= 65 && c <= 90 ? \"abcdefghijklmnopqrstuvwxyz\".slice(c - 65, c - 64) : s.slice(0, 1);\n return head + lowerAscii(s.slice(1));\n}\n\n/**\n * `lowerAscii` as a loop: a constant stack depth (and linear time) on long text, where the\n * recursive spec takes a frame and a slice per character.\n *\n * @ensures result = lowerAscii(s)\n */\nexport function lowerAsciiText(s: string): string {\n //@ verify\n //@ ensures \\result === lowerAscii(s)\n let out = \"\";\n let i = 0;\n while (i !== s.length) {\n //@ invariant 0 <= i && i <= s.length\n //@ invariant out + lowerAscii(s.slice(i)) === lowerAscii(s)\n //@ decreases s.length - i\n const c = s.charCodeAt(i);\n out =\n out +\n (c >= 65 && c <= 90 ? \"abcdefghijklmnopqrstuvwxyz\".slice(c - 65, c - 64) : s.slice(i, i + 1));\n i = i + 1;\n }\n return out;\n}\n\n/**\n * Whether `x` from index `k` matches `s` from `pos + k`, code by code, ASCII-lowered. A code\n * past the end of `s` is -1 (`codeAt`), which no code of `x` is, so there is no bound to\n * check (a `pos + |x| ≤ |s|` guard before a slice never changed the answer at runtime, where\n * `slice` clamps: an equivalent mutant, 2026-11-02).\n *\n * @ensures exactly the model's CaselessFrom\n */\nexport function caselessFrom(s: string, x: string, pos: number, k: number): boolean {\n //@ verify\n //@ type pos nat\n //@ type k nat\n //@ requires pos >= 0 && k >= 0 && k <= x.length\n //@ decreases x.length - k\n //@ ensures k === x.length ==> \\result\n if (k === x.length) return true;\n return lowerCode(codeAt(s, pos + k)) === x.charCodeAt(k) && caselessFrom(s, x, pos, k + 1);\n}\n\n/**\n * Whether the text of `s` at `pos`, ASCII-lowered, is `x` (`x` given lowercase): a case-free\n * `startsWith`; callers carry no length guard of their own. Only `pos ≤ |s|` is checked: it\n * decides an empty `x` past the end, the one case the code-by-code test can't see.\n *\n * @ensures result ⟺ pos + |x| ≤ |s| ∧ ∀ j < |x|. lowered(s[pos + j]) = x[j] — the text at pos,\n * ASCII-lowered (A-Z + 32), is x; helper-free; exactly the model's StartsWithCaseless in the link\n */\nexport function startsWithCaseless(s: string, x: string, pos: number): boolean {\n //@ verify\n //@ type pos nat\n //@ requires pos >= 0\n //@ ensures \\result <==> (pos + x.length <= s.length && forall(j: nat, j < x.length ==> ((s.charCodeAt(pos + j) >= 65 && s.charCodeAt(pos + j) <= 90) ? s.charCodeAt(pos + j) + 32 : s.charCodeAt(pos + j)) === x.charCodeAt(j)))\n return pos <= s.length && caselessFrom(s, x, pos, 0);\n}\n\n/**\n * Whether `s` ends with `suffix` (JS one-argument `endsWith`, which lsc reads as its\n * two-argument form; moved from the augur-api generator 2026-11-01).\n *\n * @ensures result ⟺ |s| ≥ |suffix| ∧ s[|s| − |suffix|, |s|) = suffix — exactly the model's EndsWith\n */\nexport function endsWith(s: string, suffix: string): boolean {\n //@ verify\n //@ ensures \\result <==> (s.length >= suffix.length && s.slice(s.length - suffix.length) === suffix)\n // No length test: from max(|s| − |suffix|, 0), a too-long suffix compares unequal by length\n return s.slice(Math.max(s.length - suffix.length, 0)) === suffix;\n}\n\n/**\n * The order of `a` and `b` by UTF-16 code unit from index `i`, as a recursive spec: -1, 0\n * or 1 (JS `<` on strings; a proper prefix comes first). Locale-free, unlike `localeCompare`.\n *\n * @ensures result ∈ {-1, 0, 1} — exactly the model's CompareFrom\n */\nexport function compareFrom(a: string, b: string, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases a.length - i\n //@ ensures \\result === -1 || \\result === 0 || \\result === 1\n if (i >= a.length) return i >= b.length ? 0 : -1;\n if (i >= b.length) return 1;\n const x = a.charCodeAt(i);\n const y = b.charCodeAt(i);\n if (x < y) return -1;\n if (x > y) return 1;\n return compareFrom(a, b, i + 1);\n}\n\n/**\n * The order of two strings by UTF-16 code unit, for `sort` (what the default `sort` uses on\n * strings), so sorted output never depends on locale.\n *\n * @ensures result = compareFrom(a, b, 0)\n */\nexport function compareCodeUnits(a: string, b: string): number {\n //@ verify\n //@ ensures \\result === compareFrom(a, b, 0)\n return compareFrom(a, b, 0);\n}\n\n/**\n * JS `s.slice(0, n)`: at most `n` characters, clamped to the length. lsc reads a bare\n * `slice(0, n)` without JS's clamp, so use this instead.\n *\n * @ensures result = s[0, min(n, |s|))\n */\nexport function prefix(s: string, n: number): string {\n //@ verify\n //@ type n nat\n //@ requires n >= 0\n //@ ensures n < s.length ==> \\result === s.slice(0, n)\n //@ ensures n >= s.length ==> \\result === s\n // Math.min, not a ternary: JS slice already clamps, so a ternary's branch is unobservable\n return s.slice(0, Math.min(n, s.length));\n}\n\n/**\n * The end of the JS-whitespace (`\\s`) run starting at `i`: the first index ≥ i that is not\n * whitespace, or |s|.\n *\n * @ensures i ≤ result ≤ |s| ∧ s[i, result) all whitespace ∧ (result = |s| ∨ ¬space(s[result]))\n */\nexport function spaceRunEnd(s: string, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires 0 <= i && i <= s.length\n //@ decreases s.length - i\n //@ ensures i <= \\result && \\result <= s.length\n //@ ensures forall(k: nat, (i <= k && k < \\result) ==> isJsSpace(s.charCodeAt(k)))\n //@ ensures \\result < s.length ==> !isJsSpace(s.charCodeAt(\\result))\n // codeAt is -1 at the end, which is no space: the bound needs no test of its own here\n if (!isJsSpace(codeAt(s, i))) return i;\n return spaceRunEnd(s, i + 1);\n}\n\n/**\n * The end of the ASCII-digit run starting at `i` (a regex's `\\d+`, from `i`): the first index\n * ≥ i that is not 0-9, or |s|.\n *\n * @ensures i ≤ result ≤ |s| ∧ s[i, result) all digits ∧ (result = |s| ∨ ¬digit(s[result])) —\n * exactly the model's DigitRunEnd\n */\nexport function digitRunEnd(s: string, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires 0 <= i && i <= s.length\n //@ decreases s.length - i\n //@ ensures i <= \\result && \\result <= s.length\n //@ ensures forall(k: nat, (i <= k && k < \\result) ==> (s.charCodeAt(k) >= 48 && s.charCodeAt(k) <= 57))\n //@ ensures \\result < s.length ==> !(s.charCodeAt(\\result) >= 48 && s.charCodeAt(\\result) <= 57)\n // codeAt is -1 at the end, which is no digit\n if (!isDigit(codeAt(s, i))) return i;\n return digitRunEnd(s, i + 1);\n}\n\n/**\n * A natural number written canonically (`^(0|[1-9][0-9]*)$`): the keys JS objects move\n * first, ahead of their source order.\n *\n * @ensures exactly the model's CanonicalNat, stated over the codes themselves so an importer\n * can use it (a contract naming `digitsFrom` can't be resolved there, models/LSC-GAPS.md)\n */\nexport function isCanonicalNat(s: string): boolean {\n //@ verify\n //@ ensures \\result <==> (s === \"0\" || (s.length > 0 && s.charCodeAt(0) >= 49 && s.charCodeAt(0) <= 57 && forall(k: nat, (1 <= k && k < s.length) ==> (s.charCodeAt(k) >= 48 && s.charCodeAt(k) <= 57))))\n if (s === \"0\") return true;\n const first = codeAt(s, 0);\n return first >= 49 && first <= 57 && digitsFrom(s, 1);\n}\n\n/**\n * The value of a run of decimal digits, most significant first (\"\" is 0).\n *\n * @requires ∀ k ∈ [0, |s|). isDigit(s[k])\n * @ensures exactly the model's DigitsValue (proved in links/utils-strings.dfy)\n */\nexport function digitsValue(s: string): number {\n //@ verify\n //@ requires forall(k: nat, k < s.length ==> (s.charCodeAt(k) >= 48 && s.charCodeAt(k) <= 57))\n //@ decreases s.length\n //@ ensures \\result >= 0\n if (s.length === 0) return 0;\n return digitsValue(s.slice(0, s.length - 1)) * 10 + (s.charCodeAt(s.length - 1) - 48);\n}\n\n/**\n * What a number from the environment means (owner 2026-11-04: a bad one fails at start):\n * \"default\" when unset (\"\": the wrapper reads a missing variable as \"\"), \"value\" when it is\n * a canonical natural number at least `min` (its value is `digitsValue(raw)`), and \"bad\"\n * otherwise: a sign, a space, a fraction, an exponent, hex, text, or below `min`.\n *\n * @ensures exactly the model's EnvNumberOf (proved in links/utils-strings.dfy)\n */\nexport function envNumberKind(raw: string, min: number): string {\n //@ verify\n //@ type min nat\n //@ ensures raw === \"\" ==> \\result === \"default\"\n //@ ensures (raw !== \"\" && !isCanonicalNat(raw)) ==> \\result === \"bad\"\n if (raw === \"\") return \"default\";\n if (!isCanonicalNat(raw)) return \"bad\";\n return digitsValue(raw) < min ? \"bad\" : \"value\";\n}\n\n/**\n * A canonical natural number's value, 0 for any other text (a count written as JSON).\n *\n * @ensures exactly the model's CanonicalNatValue (in the link: `digitsValue` needs the digits\n * isCanonicalNat's contract gives, which a contract can't call for); 0 for other text\n */\nexport function canonicalNatValue(s: string): number {\n //@ verify\n //@ ensures \\result >= 0\n //@ ensures !isCanonicalNat(s) ==> \\result === 0\n if (!isCanonicalNat(s)) return 0;\n return digitsValue(s);\n}\n\n/**\n * The first index ≥ `i` holding a line terminator, or |s|: where a regex `.+` started at `i`\n * stops.\n *\n * @ensures i ≤ result ≤ |s| ∧ no terminator in s[i, result) ∧ (result = |s| ∨ terminator at result)\n */\nexport function lineEnd(s: string, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires 0 <= i && i <= s.length\n //@ decreases s.length - i\n //@ ensures i <= \\result && \\result <= s.length\n //@ ensures forall(k: nat, (i <= k && k < \\result) ==> !isLineTerminator(s.charCodeAt(k)))\n //@ ensures \\result < s.length ==> isLineTerminator(s.charCodeAt(\\result))\n if (i === s.length || isLineTerminator(s.charCodeAt(i))) return i;\n return lineEnd(s, i + 1);\n}\n\n/**\n * The largest p with lo ≤ p < hi whose character is not a line terminator, or -1: where a\n * backtracking regex `.` can start.\n *\n * @ensures result = -1 ∨ (lo ≤ result < hi ∧ ¬terminator(s[result]) ∧ only terminators in (result, hi))\n */\nexport function lastLineCharBelow(s: string, hi: number, lo: number): number {\n //@ verify\n //@ type hi nat\n //@ type lo nat\n //@ requires 0 <= lo && 0 <= hi && hi <= s.length\n //@ decreases hi\n //@ ensures \\result === -1 || (lo <= \\result && \\result < hi)\n //@ ensures \\result >= 0 ==> !isLineTerminator(s.charCodeAt(\\result))\n //@ ensures \\result >= 0 ==> forall(k: nat, (\\result < k && k < hi) ==> isLineTerminator(s.charCodeAt(k)))\n //@ ensures \\result === -1 ==> forall(k: nat, (lo <= k && k < hi) ==> isLineTerminator(s.charCodeAt(k)))\n if (hi <= lo) return -1;\n if (!isLineTerminator(s.charCodeAt(hi - 1))) return hi - 1;\n return lastLineCharBelow(s, hi - 1, lo);\n}\n\n/**\n * Nothing but JS whitespace (`s.trim() === \"\"`).\n *\n * @ensures exactly the model's Blank\n */\nexport function isBlank(s: string): boolean {\n //@ verify\n //@ ensures \\result <==> s.trim() === \"\"\n return s.trim() === \"\";\n}\n\n/**\n * The first index ≥ `i` where `x` occurs in `s`, or -1 (JS `s.indexOf(x, i)` for i ≤ |s|).\n *\n * @ensures result = -1 ∨ (i ≤ result ∧ s[result, result + |x|) = x) — and the first such\n * index: links/utils-strings.dfy proves it is exactly the model's IndexOfFrom (lsc can't\n * give the \"no earlier match\" quantifier a trigger)\n */\nexport function indexOfFrom(s: string, x: string, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires i >= 0 && i <= s.length\n //@ decreases s.length - i\n //@ ensures \\result === -1 || (i <= \\result && \\result + x.length <= s.length)\n //@ ensures \\result >= 0 ==> s.slice(\\result, \\result + x.length) === x\n // A match here, else the end, else the next index: stopping at `i === |s|` (not \"x no\n // longer fits\") leaves no bound whose slip a later, harmless step would hide\n if (startsWithAt(s, x, i)) return i;\n if (i === s.length) return -1;\n return indexOfFrom(s, x, i + 1);\n}\n\n/**\n * `indexOfFrom` as a loop: the same answer at a constant stack depth, for text long enough that\n * one frame per character would overflow the stack (a rendered page, 50–60 KB with its inlined\n * stylesheet). Specs and links use `indexOfFrom`; runtime scans over long text use this.\n *\n * @ensures result = indexOfFrom(s, x, i)\n */\nexport function findFrom(s: string, x: string, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires i >= 0 && i <= s.length\n //@ ensures \\result === indexOfFrom(s, x, i)\n let k = i;\n while (k !== s.length) {\n //@ invariant i <= k && k <= s.length\n //@ invariant indexOfFrom(s, x, k) === indexOfFrom(s, x, i)\n //@ decreases s.length - k\n if (startsWithAt(s, x, k)) return k;\n k = k + 1;\n }\n return startsWithAt(s, x, k) ? k : -1;\n}\n\n/**\n * `indexOfCode` as a loop: the same answer at a constant stack depth (see `findFrom`).\n *\n * @ensures result = indexOfCode(s, code, from)\n */\nexport function findCodeFrom(s: string, code: number, from: number): number {\n //@ verify\n //@ type from nat\n //@ requires code >= 0 && from >= 0\n //@ ensures \\result === indexOfCode(s, code, from)\n let k = from;\n while (k < s.length) {\n //@ invariant from <= k\n //@ invariant indexOfCode(s, code, k) === indexOfCode(s, code, from)\n //@ decreases s.length - k\n if (s.charCodeAt(k) === code) return k;\n k = k + 1;\n }\n return -1;\n}\n\n/**\n * How many times `x` occurs in `s` from `i` on, left to right without overlaps (repeated JS\n * `s.indexOf(x, at + x.length)`).\n *\n * @requires |x| > 0\n * @ensures result ≥ 0 — exactly the model's CountFrom (links/utils-strings.dfy)\n */\nexport function countFrom(s: string, x: string, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires x.length > 0 && i >= 0 && i <= s.length\n //@ decreases s.length - i\n //@ ensures \\result >= 0\n const at = indexOfFrom(s, x, i);\n if (at === -1) return 0;\n return 1 + countFrom(s, x, at + x.length);\n}\n\n/**\n * `countFrom(s, x, 0)` as a loop: a constant stack depth on long text (see `findFrom`).\n *\n * @requires |x| > 0\n * @ensures result = countFrom(s, x, 0)\n */\nexport function countOf(s: string, x: string): number {\n //@ verify\n //@ requires x.length > 0\n //@ ensures \\result === countFrom(s, x, 0)\n let n = 0;\n let i = 0;\n let at = findFrom(s, x, 0);\n while (at !== -1) {\n //@ invariant 0 <= i && i <= s.length\n //@ invariant at === indexOfFrom(s, x, i)\n //@ invariant n + countFrom(s, x, i) === countFrom(s, x, 0)\n //@ decreases s.length - i\n n = n + 1;\n i = at + x.length;\n at = findFrom(s, x, i);\n }\n return n;\n}\n\n/**\n * The text before the first `code`, or all of it when there is none (JS `s.split(c)[0]`).\n *\n * @ensures result = s[0, first code) when s holds one, else s — the model's UntilCode\n */\nexport function untilCode(s: string, code: number): string {\n //@ verify\n //@ requires code >= 0\n //@ ensures \\result === (indexOfCode(s, code, 0) >= 0 && indexOfCode(s, code, 0) <= s.length ? s.slice(0, indexOfCode(s, code, 0)) : s)\n const k = indexOfCode(s, code, 0);\n return k >= 0 ? s.slice(0, k) : s;\n}\n\n/**\n * `s` from `i` on split at every `code` (JS `s.split(c)` at i = 0, for a one-character\n * separator): always at least one part.\n *\n * @ensures |result| ≥ 1 — exactly the model's SplitCodeFrom (links/utils-strings.dfy)\n */\nexport function splitCodeFrom(s: string, code: number, i: number): string[] {\n //@ verify\n //@ type i nat\n //@ requires code >= 0 && i >= 0 && i <= s.length\n //@ decreases s.length - i\n //@ ensures \\result.length > 0\n const k = indexOfCode(s, code, i);\n if (k === -1) return [s.slice(i)];\n return [s.slice(i, k), ...splitCodeFrom(s, code, k + 1)];\n}\n\n/**\n * Every run of JS whitespace in `s` from `i` on as one space (JS `s.replace(/\\s+/g, \" \")` at\n * i = 0).\n *\n * @ensures |result| ≤ |s| − i — exactly the model's CollapseSpacesFrom (links/utils-strings.dfy)\n */\nexport function collapseSpacesFrom(s: string, i: number): string {\n //@ verify\n //@ type i nat\n //@ requires 0 <= i && i <= s.length\n //@ decreases s.length - i\n //@ ensures \\result.length <= s.length - i\n if (i === s.length) return \"\";\n if (isJsSpace(s.charCodeAt(i))) return \" \" + collapseSpacesFrom(s, spaceRunEnd(s, i));\n return s.slice(i, i + 1) + collapseSpacesFrom(s, i + 1);\n}\n\n/**\n * `collapseSpacesFrom(s, 0)` at a constant stack depth (a page's text is tens of KB).\n *\n * @ensures result = collapseSpacesFrom(s, 0)\n */\nexport function collapseSpaces(s: string): string {\n //@ verify\n //@ ensures \\result === collapseSpacesFrom(s, 0)\n let out = \"\";\n let i = 0;\n while (i < s.length) {\n //@ invariant 0 <= i && i <= s.length\n //@ invariant out + collapseSpacesFrom(s, i) === collapseSpacesFrom(s, 0)\n //@ decreases s.length - i\n if (isJsSpace(s.charCodeAt(i))) {\n out = out + \" \";\n // the run's end as a loop too: spaceRunEnd takes a frame per space (Fable review 2026-11-06)\n let e = i + 1;\n while (e !== s.length && isJsSpace(s.charCodeAt(e))) {\n //@ invariant i < e && e <= s.length\n //@ invariant forall(k: nat, (i <= k && k < e) ==> isJsSpace(s.charCodeAt(k)))\n //@ decreases s.length - e\n e = e + 1;\n }\n i = e;\n } else {\n out = out + s.slice(i, i + 1);\n i = i + 1;\n }\n }\n return out;\n}\n\n/**\n * `n` spaces.\n *\n * @ensures result = \" \" repeated n times — the model's Spaces\n */\nexport function spaces(n: number): string {\n //@ verify\n //@ type n nat\n //@ requires n >= 0\n //@ decreases n\n //@ ensures \\result.length === n\n //@ ensures forall(k: nat, k < n ==> \\result.charCodeAt(k) === 32)\n // `<= 0`, not `=== 0`: the same for a nat, and a fraction a caller slips in (outside the\n // contract) ends instead of recursing forever (Fable review 2026-11-06: spaces(0.5))\n if (n <= 0) return \"\";\n return \" \" + spaces(n - 1);\n}\n\n/**\n * A line feed, `\"\\n\"`, for proved text that spans lines: lsc emits a `\"\\n\"` escape raw, which\n * Dafny cannot parse (models/LSC-GAPS.md), so the contract pins it by code unit and the body is\n * a template literal holding the line break itself.\n *\n * @ensures result = \"\\n\" — one code unit, 10\n */\nexport function lineFeed(): string {\n //@ verify\n //@ ensures \\result.length === 1 && \\result.charCodeAt(0) === 10\n return `\n`;\n}\n\n/**\n * `s` padded on the left with spaces to `width` (JS `s.padStart(width)`).\n *\n * @ensures result = Spaces(width − |s|) + s when width > |s|, else s\n */\nexport function padLeft(s: string, width: number): string {\n //@ verify\n //@ ensures width <= s.length ==> \\result === s\n // width > |s| ⟹ spaces(width − |s|) + s: a hand ensures in strings.dfy, so importers'\n // axioms name no helper (models/LSC-GAPS.md). Math.max, not a ternary: at width = |s|\n // both branches agree (spaces(0) is \"\"), so `>` vs `>=` would be equivalent.\n return spaces(Math.max(width - s.length, 0)) + s;\n}\n\n/**\n * `s` padded on the right with spaces to `width` (JS `s.padEnd(width)`).\n *\n * @ensures result = s + Spaces(width − |s|) when width > |s|, else s\n */\nexport function padRight(s: string, width: number): string {\n //@ verify\n //@ ensures width <= s.length ==> \\result === s\n // width > |s| ⟹ s + spaces(width − |s|): a hand ensures in strings.dfy, as padLeft's.\n return s + spaces(Math.max(width - s.length, 0));\n}\n\n/**\n * An optional part of a key: `tag` then `text`, or nothing when `text` is empty, so an absent\n * part never leaves a bare tag.\n *\n * @ensures result = \"\" when text = \"\", else tag + text — exactly the model's KeyPart\n */\nexport function keyPart(tag: string, text: string): string {\n //@ verify\n //@ ensures \\result === (text === \"\" ? \"\" : tag + text)\n return text === \"\" ? \"\" : tag + text;\n}\n\n/**\n * Two texts joined by one space: the one rule behind a loader key's `<column> <direction>`, a\n * sync line's `METHOD /path` and a field's description then note.\n *\n * @ensures result = a + \" \" + b — exactly the model's SpaceJoined\n */\nexport function spaceJoined(a: string, b: string): string {\n //@ verify\n //@ ensures \\result === a + \" \" + b\n return a + \" \" + b;\n}\n\n/**\n * The first code point of `w` as text: a surrogate pair whole, else the first code unit, or \"\"\n * (Fable review 2026-11-06: an astral initial was a lone surrogate).\n *\n * @ensures exactly the model's FirstChar\n */\nexport function firstCodePoint(w: string): string {\n //@ verify\n //@ ensures \\result === ((w.length >= 2 && w.charCodeAt(0) >= 55296 && w.charCodeAt(0) <= 56319 && w.charCodeAt(1) >= 56320 && w.charCodeAt(1) <= 57343) ? w.slice(0, 2) : (w.length > 0 ? w.slice(0, 1) : \"\"))\n if (w.length >= 2) {\n const hi = w.charCodeAt(0);\n const lo = w.charCodeAt(1);\n if (hi >= 55296 && hi <= 56319 && lo >= 56320 && lo <= 57343) return w.slice(0, 2);\n }\n return w.length > 0 ? w.slice(0, 1) : \"\";\n}\n\n/**\n * An ASCII letter (A-Z, a-z) somewhere in `w` from `i` on (moved from readability.ts\n * 2026-11-06, so `readableWords`' contract can name it and importers resolve it).\n *\n * @ensures result ⟺ ∃ k ∈ [i, |w|). w[k] ∈ A-Z ∪ a-z — at i = 0 exactly the model's HasAsciiLetter\n */\nexport function hasAsciiLetterFrom(w: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0\n //@ decreases w.length - i\n //@ ensures \\result <==> exists(k: nat, i <= k && k < w.length && ((w.charCodeAt(k) >= 65 && w.charCodeAt(k) <= 90) || (w.charCodeAt(k) >= 97 && w.charCodeAt(k) <= 122)))\n if (i >= w.length) return false;\n const c = w.charCodeAt(i);\n if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) return true;\n return hasAsciiLetterFrom(w, i + 1);\n}\n\n/**\n * `s` with a-z uppercased and every other character kept, the mirror of `lowerAscii`: JS's\n * `toUpperCase()` also maps non-ASCII letters (ß becomes \"SS\").\n *\n * @ensures |result| = |s| ∧ ∀ k < |s|. result[k] = (s[k] ∈ a-z ? s[k] − 32 : s[k]) — a-z\n * raised, every other code unit unchanged; exactly the model's UpperAscii in the link\n */\nexport function upperAscii(s: string): string {\n //@ verify\n //@ decreases s.length\n //@ ensures \\result.length === s.length\n //@ ensures forall(k: nat, k < s.length ==> \\result.charCodeAt(k) === ((s.charCodeAt(k) >= 97 && s.charCodeAt(k) <= 122) ? s.charCodeAt(k) - 32 : s.charCodeAt(k)))\n if (s.length === 0) return \"\";\n const c = s.charCodeAt(0);\n const head =\n c >= 97 && c <= 122 ? \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".slice(c - 97, c - 96) : s.slice(0, 1);\n return head + upperAscii(s.slice(1));\n}\n"],"mappings":";AAYO,SAAS,QAAQ,GAAoB;AAG1C,SAAO,KAAK,MAAM,KAAK;AACzB;;;ACcO,SAAS,OAAO,GAAW,GAAmB;AAInD,SAAO,KAAK,KAAK,IAAI,EAAE,SAAS,EAAE,WAAW,CAAC,IAAI;AACpD;AA4FO,SAAS,WAAW,GAAW,GAAoB;AAMxD,SAAO,KAAK,EAAE,UAAW,QAAQ,EAAE,WAAW,CAAC,CAAC,KAAK,WAAW,GAAG,IAAI,CAAC;AAC1E;AA0HO,SAAS,YAAY,GAAW,MAAc,MAAsB;AASzE,QAAM,IAAI,OAAO,GAAG,IAAI;AACxB,MAAI,MAAM,KAAM,QAAO;AACvB,MAAI,MAAM,GAAI,QAAO;AACrB,SAAO,YAAY,GAAG,MAAM,OAAO,CAAC;AACtC;AA0DO,SAAS,WAAW,GAAW,MAAsB;AAK1D,MAAI,OAAO,GAAG,EAAE,SAAS,CAAC,MAAM,MAAM;AACpC,WAAO,WAAW,EAAE,MAAM,GAAG,EAAE,SAAS,CAAC,GAAG,IAAI;AAAA,EAClD;AACA,SAAO;AACT;AAuBO,SAAS,aAAa,GAAW,GAAW,KAAsB;AAOvE,QAAM,KAAK,KAAK,IAAI,KAAK,EAAE,MAAM;AAGjC,SAAO,EAAE,MAAM,IAAI,KAAK,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM;AAC5D;AA4FO,SAAS,SAAS,GAAW,QAAyB;AAI3D,SAAO,EAAE,MAAM,KAAK,IAAI,EAAE,SAAS,OAAO,QAAQ,CAAC,CAAC,MAAM;AAC5D;AAiGO,SAAS,eAAe,GAAoB;AAGjD,MAAI,MAAM,IAAK,QAAO;AACtB,QAAM,QAAQ,OAAO,GAAG,CAAC;AACzB,SAAO,SAAS,MAAM,SAAS,MAAM,WAAW,GAAG,CAAC;AACtD;AAQO,SAAS,YAAY,GAAmB;AAK7C,MAAI,EAAE,WAAW,EAAG,QAAO;AAC3B,SAAO,YAAY,EAAE,MAAM,GAAG,EAAE,SAAS,CAAC,CAAC,IAAI,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,IAAI;AACpF;AA0BO,SAAS,kBAAkB,GAAmB;AAInD,MAAI,CAAC,eAAe,CAAC,EAAG,QAAO;AAC/B,SAAO,YAAY,CAAC;AACtB;AAyQO,SAAS,WAAmB;AAGjC,SAAO;AAAA;AAET;AA8FO,SAAS,WAAW,GAAmB;AAK5C,MAAI,EAAE,WAAW,EAAG,QAAO;AAC3B,QAAM,IAAI,EAAE,WAAW,CAAC;AACxB,QAAM,OACJ,KAAK,MAAM,KAAK,MAAM,6BAA6B,MAAM,IAAI,IAAI,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AACzF,SAAO,OAAO,WAAW,EAAE,MAAM,CAAC,CAAC;AACrC;","names":[]}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
indexOfCode,
|
|
3
|
+
startsWithAt
|
|
4
|
+
} from "./chunk-V76GZZF3.js";
|
|
5
|
+
|
|
1
6
|
// ../foundation/src/duration.ts
|
|
2
7
|
function seconds(n) {
|
|
3
8
|
return n;
|
|
@@ -18,21 +23,6 @@ function addMillis(a, b) {
|
|
|
18
23
|
return a + b;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
// ../utils/src/strings.ts
|
|
22
|
-
function codeAt(s, i) {
|
|
23
|
-
return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
|
|
24
|
-
}
|
|
25
|
-
function indexOfCode(s, code, from) {
|
|
26
|
-
const c = codeAt(s, from);
|
|
27
|
-
if (c === code) return from;
|
|
28
|
-
if (c === -1) return -1;
|
|
29
|
-
return indexOfCode(s, code, from + 1);
|
|
30
|
-
}
|
|
31
|
-
function startsWithAt(s, x, pos) {
|
|
32
|
-
const at = Math.min(pos, s.length);
|
|
33
|
-
return s.slice(at, Math.min(at + x.length, s.length)) === x;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
26
|
// ../utils/src/includes.ts
|
|
37
27
|
function includesFrom(s, x, i) {
|
|
38
28
|
for (let k = i; k !== s.length + 1; k++) {
|
|
@@ -166,6 +156,13 @@ function approvePath(path, hasAllowlist, listed) {
|
|
|
166
156
|
function usesCache(hasWrapper, isRead) {
|
|
167
157
|
return hasWrapper && isRead;
|
|
168
158
|
}
|
|
159
|
+
function sessionCookieName(hasSecure) {
|
|
160
|
+
return hasSecure ? "__Secure-authjs.session-token" : "authjs.session-token";
|
|
161
|
+
}
|
|
162
|
+
function clientFor(hasOptions, hasWithRequest) {
|
|
163
|
+
if (!hasOptions) return "client";
|
|
164
|
+
return hasWithRequest ? "view" : "refuse";
|
|
165
|
+
}
|
|
169
166
|
function scopedPrefix(siteId) {
|
|
170
167
|
return siteId + ":";
|
|
171
168
|
}
|
|
@@ -283,6 +280,8 @@ function parseMethodPath(candidate) {
|
|
|
283
280
|
}
|
|
284
281
|
|
|
285
282
|
export {
|
|
283
|
+
seconds,
|
|
284
|
+
minutes,
|
|
286
285
|
clientIdSiteIdOf,
|
|
287
286
|
mintedCredentials,
|
|
288
287
|
hasMoreOf,
|
|
@@ -308,6 +307,8 @@ export {
|
|
|
308
307
|
signInTarget,
|
|
309
308
|
resolutionOf,
|
|
310
309
|
usesCache,
|
|
310
|
+
sessionCookieName,
|
|
311
|
+
clientFor,
|
|
311
312
|
scopedPrefix,
|
|
312
313
|
shouldCache,
|
|
313
314
|
cacheTtlOf,
|
|
@@ -329,4 +330,4 @@ export {
|
|
|
329
330
|
getOrCreateScopedClient,
|
|
330
331
|
parseMethodPath
|
|
331
332
|
};
|
|
332
|
-
//# sourceMappingURL=chunk-
|
|
333
|
+
//# sourceMappingURL=chunk-Z53NEFEQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../foundation/src/duration.ts","../../utils/src/includes.ts","../src/rules.ts","../src/scoped-client-key.ts","../src/sdk-client-store.ts"],"sourcesContent":["//@ backend dafny\n\n/* Seconds and milliseconds as two types (2026-11-08). Verified with LemmaScript → Dafny\n (`pnpm proofs`; model: models/Durations.dfy, where they are two datatypes; link:\n models/links/foundation-duration.dfy).\n\n Both are branded: a plain `number` is neither, and a `Seconds` is not a `Millis`, so a TTL in\n seconds can't be passed where milliseconds are meant (augur-core's `staleTime` vs\n `redisTtl`), and a JWT `exp` can't be compared with `Date.now()` unconverted. Write a\n duration in the unit people think in (`minutes(15)`) and convert with `toMillis`; read a\n clock or a millisecond count back with `floorSeconds`. Values enter through the guards\n `secondsOf` / `millisOf` (an env value, a JSON `expires_in`); the clock is `millis(Date.now())`\n (the platform's time value is a whole, non-negative number of milliseconds).\n lsc writes both aliases as `nat` (no refinement, models/LSC-GAPS.md). */\n\n/** A whole number of seconds, made only by the builders and guards below. */\n//@ type nat\nexport type Seconds = number & { readonly __seconds: true };\n\n/** A whole number of milliseconds, made only by the builders and guards below. */\n//@ type nat\nexport type Millis = number & { readonly __millis: true };\n\n/**\n * `n` seconds.\n *\n * @ensures exactly the model's Seconds(n)\n */\nexport function seconds(n: number): Seconds {\n //@ verify\n //@ type n nat\n //@ requires n >= 0\n //@ ensures \\result === n\n return n as Seconds;\n}\n\n/**\n * `n` minutes, in seconds.\n *\n * @ensures exactly the model's Minutes\n */\nexport function minutes(n: number): Seconds {\n //@ verify\n //@ type n nat\n //@ requires n >= 0\n //@ ensures \\result === n * 60\n return (n * 60) as Seconds;\n}\n\n/**\n * `n` hours, in seconds.\n *\n * @ensures exactly the model's Hours\n */\nexport function hours(n: number): Seconds {\n //@ verify\n //@ type n nat\n //@ requires n >= 0\n //@ ensures \\result === n * 3600\n return (n * 3600) as Seconds;\n}\n\n/**\n * `n` days, in seconds.\n *\n * @ensures exactly the model's Days\n */\nexport function days(n: number): Seconds {\n //@ verify\n //@ type n nat\n //@ requires n >= 0\n //@ ensures \\result === n * 86400\n return (n * 86400) as Seconds;\n}\n\n/**\n * `n` milliseconds: for a duration under a second (a retry backoff, a debounce).\n *\n * @ensures exactly the model's Millis(n)\n */\nexport function millis(n: number): Millis {\n //@ verify\n //@ type n nat\n //@ requires n >= 0\n //@ ensures \\result === n\n return n as Millis;\n}\n\n/**\n * Seconds as milliseconds, exactly.\n *\n * @ensures exactly the model's ToMillis\n */\nexport function toMillis(d: Seconds): Millis {\n //@ verify\n //@ requires d >= 0\n //@ ensures \\result === d * 1000\n return (d * 1000) as Millis;\n}\n\n/**\n * Milliseconds as whole seconds, rounded down (a JWT `exp` or `iat` from a clock).\n *\n * @ensures exactly the model's FloorSeconds\n */\nexport function floorSeconds(m: Millis): Seconds {\n //@ verify\n //@ type m nat\n //@ requires m >= 0\n //@ ensures \\result === Math.floor(m / 1000)\n return Math.floor(m / 1000) as Seconds;\n}\n\n/**\n * A clock reading plus a duration, both `Millis`: when something expires (`addMillis(now,\n * toMillis(minutes(15)))`).\n *\n * @ensures exactly the model's AddMillis\n */\nexport function addMillis(a: Millis, b: Millis): Millis {\n //@ verify\n //@ requires a >= 0 && b >= 0\n //@ ensures \\result === a + b\n return (a + b) as Millis;\n}\n\n/**\n * A reading less a duration, never below 0 (a token used until a minute before it expires). An\n * expiry clamped to 0 is no more live than the negative one it stands for (the model's\n * MinusMillisKeepsLiveness).\n *\n * @ensures exactly the model's MinusMillis\n */\nexport function minusMillis(a: Millis, b: Millis): Millis {\n //@ verify\n //@ requires a >= 0 && b >= 0\n //@ ensures \\result === (a >= b ? a - b : 0)\n return a >= b ? ((a - b) as Millis) : millis(0);\n}\n\n/**\n * `n` as `Seconds`, or null when it is not a safe integer at least 0: a fraction, NaN, a\n * negative, an infinity, or past `Number.MAX_SAFE_INTEGER`. Where a number of seconds enters.\n *\n * @ensures exactly the model's AcceptedAsDuration, and the value is kept\n */\nexport function secondsOf(n: number): Seconds | null {\n //@ verify\n //@ ensures (\\result !== null) <==> (n >= 0 && n <= 9007199254740991)\n //@ ensures \\result !== null ==> \\result === n\n return Math.floor(n) === n && n >= 0 && n <= 9007199254740991 ? (n as Seconds) : null;\n}\n\n/**\n * An outside count of seconds (a token's `expires_in`, a JWT's `exp`) as `Seconds`: rounded\n * down, and 0 when it is then no safe integer at least 0 (a negative, NaN, an infinity), so a\n * bad lifetime is no lifetime and a bad expiry is already past.\n *\n * @ensures exactly the model's WholeSeconds (the proof reads a number as an integer)\n */\nexport function wholeSeconds(n: number): Seconds {\n //@ verify\n //@ ensures (n >= 0 && n <= 9007199254740991) ==> \\result === n\n //@ ensures !(n >= 0 && n <= 9007199254740991) ==> \\result === 0\n const whole = secondsOf(Math.floor(n));\n return whole === null ? seconds(0) : whole;\n}\n\n/**\n * `n` as `Millis`, or null when it is not a safe integer at least 0 (the same rule as\n * `secondsOf`). Where a number of milliseconds enters.\n *\n * @ensures exactly the model's AcceptedAsDuration, and the value is kept\n */\nexport function millisOf(n: number): Millis | null {\n //@ verify\n //@ ensures (\\result !== null) <==> (n >= 0 && n <= 9007199254740991)\n //@ ensures \\result !== null ==> \\result === n\n return Math.floor(n) === n && n >= 0 && n <= 9007199254740991 ? (n as Millis) : null;\n}\n","//@ backend dafny\nimport { startsWithAt } from \"./strings\";\n\n/* Substring search from an index, verified with LemmaScript → Dafny (model: models/Utils.dfy\n IncludesFrom; link: models/links/utils-includes.dfy). Its own file (moved out of strings.ts,\n 2026-11-06) so its contract can name `startsWithAt`: lsc gives an importer a helper from\n another file with that helper's contract, never one from the same file (models/LSC-GAPS.md). */\n\n/**\n * Whether `x` occurs in `s` at some index ≥ `i` (JS `s.includes(x, i)`). `i` MUST be at most\n * |s|: past the end JS clamps it to |s| (Fable review 2026-11-06), so a start there is the end.\n *\n * A loop, so its depth doesn't grow with `s` (agr-entity-graphql runs it on a whole schema's JSON).\n *\n * @requires i ≤ |s|\n * @ensures result ⟺ ∃ k. i ≤ k ≤ |s| ∧ startsWithAt(s, x, k) — exactly the model's IncludesFrom\n */\nexport function includesFrom(s: string, x: string, i: number): boolean {\n //@ verify\n //@ type i nat\n //@ requires i >= 0 && i <= s.length\n //@ ensures \\result <==> exists(k: nat, i <= k && k <= s.length && startsWithAt(s, x, k))\n for (let k = i; k !== s.length + 1; k++) {\n //@ invariant i <= k && k <= s.length + 1\n //@ invariant forall(j: nat, (i <= j && j < k) ==> !startsWithAt(s, x, j))\n //@ decreases s.length + 1 - k\n if (startsWithAt(s, x, k)) return true;\n }\n return false;\n}\n","//@ backend dafny\nimport { addMillis, hours, millis, minutes, seconds, toMillis } from \"@atlas/foundation/duration\";\nimport { includesFrom } from \"@atlas/utils/includes\";\nimport { indexOfCode } from \"@atlas/utils/strings\";\nimport type { Millis, Seconds } from \"./duration\";\n\n/* The server's decisions, as pure functions verified with LemmaScript → Dafny (model:\n models/AugurServer.dfy; link: models/links/augur-server-rules.dfy). Cookies, JWT decoding,\n fetch, Redis and process.env stay in the callers, which hand over plain values. */\n\n/**\n * The siteId of a bearer's client_id claim (`<n>|<siteId>`): the text after the first \"|\", when\n * there is one and it is non-empty. The prefix is not checked.\n *\n * @ensures exactly the model's ClientIdSiteId on a string claim\n */\nexport function clientIdSiteIdOf(clientId: string): string | null {\n //@ verify\n //@ ensures indexOfCode(clientId, 124, 0) < 0 ==> \\result === null\n //@ ensures indexOfCode(clientId, 124, 0) >= 0 && indexOfCode(clientId, 124, 0) + 1 >= clientId.length ==> \\result === null\n //@ ensures indexOfCode(clientId, 124, 0) >= 0 && indexOfCode(clientId, 124, 0) + 1 < clientId.length ==> \\result === clientId.slice(indexOfCode(clientId, 124, 0) + 1)\n const k = indexOfCode(clientId, 124, 0);\n if (k < 0) return null;\n if (k + 1 >= clientId.length) return null;\n return clientId.slice(k + 1);\n}\n\n/** A session's siteId and bearer token, as minted, or refused. */\nexport type Mint = { kind: \"minted\"; siteId: string; token: string } | { kind: \"refused\" };\n\n/**\n * getSessionCredentials' mint, once the secret and the decoded session are in hand: a valid\n * siteId (augur-api's `isSiteId`, checked by the caller), a non-empty token, and the bearer's\n * client_id siteId (`\"\"` for none: `clientIdSiteIdOf` never gives `\"\"`) equal to it.\n *\n * @ensures exactly the model's MintCredentials with a secret and a decoded session\n */\nexport function mintedCredentials(\n siteIdOk: boolean,\n targetSiteId: string,\n token: string,\n bearerSiteId: string,\n): Mint {\n //@ verify\n //@ ensures siteIdOk && token !== \"\" && bearerSiteId !== \"\" && bearerSiteId === targetSiteId ==> \\result.kind === \"minted\" && \\result.siteId === targetSiteId && \\result.token === token\n //@ ensures !(siteIdOk && token !== \"\" && bearerSiteId !== \"\" && bearerSiteId === targetSiteId) ==> \\result.kind === \"refused\"\n if (!siteIdOk || token === \"\" || bearerSiteId === \"\" || bearerSiteId !== targetSiteId) {\n return { kind: \"refused\" };\n }\n return { kind: \"minted\", siteId: targetSiteId, token };\n}\n\n/**\n * Whether there is another page: from the total when one is given, else a full page.\n *\n * @ensures exactly the model's HasMore\n */\nexport function hasMoreOf(\n page: number,\n limit: number,\n total: number | undefined,\n itemCount: number,\n): boolean {\n //@ verify\n //@ ensures total !== undefined ==> \\result === ((page + 1) * limit < total)\n //@ ensures total === undefined ==> \\result === (itemCount === limit)\n if (total !== undefined) return (page + 1) * limit < total;\n return itemCount === limit;\n}\n\n/**\n * The next page's cursor: page + 1 while there is more.\n *\n * @ensures exactly the model's NextCursor given HasMore\n */\nexport function nextCursorOf(hasMore: boolean, page: number): number | undefined {\n //@ verify\n //@ ensures hasMore ==> \\result === page + 1\n //@ ensures !hasMore ==> \\result === undefined\n if (hasMore) return page + 1;\n return undefined;\n}\n\n/** The deployment environment. */\nexport type Env = \"development\" | \"staging\" | \"production\";\n\n/**\n * DEPLOYMENT_ENV first; then the server's NODE_ENV; then the browser's host (substring). A missing\n * variable is \"\".\n *\n * @ensures exactly the model's EnvOf\n */\nexport function envOf(\n deploymentEnv: string,\n isServer: boolean,\n nodeEnv: string,\n host: string,\n): Env {\n //@ verify\n //@ ensures deploymentEnv === \"dev\" ==> \\result === \"staging\"\n //@ ensures deploymentEnv !== \"dev\" && deploymentEnv === \"live\" ==> \\result === \"production\"\n //@ ensures deploymentEnv !== \"dev\" && deploymentEnv !== \"live\" && isServer ==> \\result === serverEnvOf(nodeEnv)\n //@ ensures deploymentEnv !== \"dev\" && deploymentEnv !== \"live\" && !isServer ==> \\result === hostEnvOf(host)\n if (deploymentEnv === \"dev\") return \"staging\";\n if (deploymentEnv === \"live\") return \"production\";\n if (isServer) return serverEnvOf(nodeEnv);\n return hostEnvOf(host);\n}\n\n/**\n * On the server: development only for NODE_ENV \"development\".\n *\n * @ensures result = development ⟺ nodeEnv = \"development\", else production\n */\nexport function serverEnvOf(nodeEnv: string): Env {\n //@ verify\n //@ ensures nodeEnv === \"development\" ==> \\result === \"development\"\n //@ ensures nodeEnv !== \"development\" ==> \\result === \"production\"\n return nodeEnv === \"development\" ? \"development\" : \"production\";\n}\n\n/**\n * In the browser: localhost or 127.0.0.1 anywhere in the host is development, agr-hosting.dev\n * staging, anything else production.\n *\n * @ensures exactly the model's host rule\n */\nexport function hostEnvOf(host: string): Env {\n //@ verify\n //@ ensures (includesFrom(host, \"localhost\", 0) || includesFrom(host, \"127.0.0.1\", 0)) ==> \\result === \"development\"\n //@ ensures !(includesFrom(host, \"localhost\", 0) || includesFrom(host, \"127.0.0.1\", 0)) && includesFrom(host, \"agr-hosting.dev\", 0) ==> \\result === \"staging\"\n //@ ensures !(includesFrom(host, \"localhost\", 0) || includesFrom(host, \"127.0.0.1\", 0)) && !includesFrom(host, \"agr-hosting.dev\", 0) ==> \\result === \"production\"\n if (includesFrom(host, \"localhost\", 0) || includesFrom(host, \"127.0.0.1\", 0))\n return \"development\";\n if (includesFrom(host, \"agr-hosting.dev\", 0)) return \"staging\";\n return \"production\";\n}\n\n/**\n * The API route's outcome for a request: \"run\" answers queryAction's data, \"run-full\"\n * queryActionRaw's full response (atlas#107).\n */\nexport type ApiOutcome =\n \"forbidden\" | \"bad-json\" | \"bad-method-path\" | \"bad-args\" | \"run\" | \"run-full\";\n\n/**\n * A present, non-empty Sec-Fetch-Site other than same-origin is refused (a missing one, `\"\"`\n * from the caller, passes).\n *\n * @ensures result ⟺ fetchSite ∉ {\"\", \"same-origin\"}\n */\nexport function isCrossOrigin(fetchSite: string): boolean {\n //@ verify\n //@ ensures \\result === (fetchSite !== \"\" && fetchSite !== \"same-origin\")\n return fetchSite !== \"\" && fetchSite !== \"same-origin\";\n}\n\n/**\n * The body's outcome: JSON, then a non-empty methodPath string, then an args array; a valid\n * body with `raw: true` (`full`) runs for the full response, any other for its data.\n *\n * @ensures exactly the model's ApiOutcomeOf past the origin check\n */\nexport function bodyOutcomeOf(\n jsonOk: boolean,\n methodPathOk: boolean,\n argsIsArray: boolean,\n full: boolean,\n): ApiOutcome {\n //@ verify\n //@ ensures !jsonOk ==> \\result === \"bad-json\"\n //@ ensures jsonOk && !methodPathOk ==> \\result === \"bad-method-path\"\n //@ ensures jsonOk && methodPathOk && !argsIsArray ==> \\result === \"bad-args\"\n //@ ensures jsonOk && methodPathOk && argsIsArray && full ==> \\result === \"run-full\"\n //@ ensures jsonOk && methodPathOk && argsIsArray && !full ==> \\result === \"run\"\n if (!jsonOk) return \"bad-json\";\n if (!methodPathOk) return \"bad-method-path\";\n if (!argsIsArray) return \"bad-args\";\n if (full) return \"run-full\";\n return \"run\";\n}\n\n/**\n * The route runs the call: either view; any other outcome is a refusal.\n *\n * @ensures exactly the model's Runs\n */\nexport function runsOf(o: ApiOutcome): boolean {\n //@ verify\n //@ ensures \\result === (o === \"run\" || o === \"run-full\")\n return o === \"run\" || o === \"run-full\";\n}\n\n/**\n * The route answers the full response (queryActionRaw), not its data.\n *\n * @ensures exactly the model's AnswersFull\n */\nexport function answersFullOf(o: ApiOutcome): boolean {\n //@ verify\n //@ ensures \\result === (o === \"run-full\")\n return o === \"run-full\";\n}\n\n/**\n * An outcome's HTTP status: 403, 400 for a bad body, 200 to run.\n *\n * @ensures exactly the model's ApiStatus\n */\nexport function apiStatusOf(o: ApiOutcome): number {\n //@ verify\n //@ ensures o === \"forbidden\" ==> \\result === 403\n //@ ensures (o === \"bad-json\" || o === \"bad-method-path\" || o === \"bad-args\") ==> \\result === 400\n //@ ensures (o === \"run\" || o === \"run-full\") ==> \\result === 200\n if (o === \"forbidden\") return 403;\n if (o === \"run\" || o === \"run-full\") return 200;\n return 400;\n}\n\n/**\n * A refusal's response text (\"\" to run).\n *\n * @ensures each refusal has its fixed text\n */\nexport function apiMessageOf(o: ApiOutcome): string {\n //@ verify\n //@ ensures o === \"forbidden\" ==> \\result === \"Forbidden: cross-origin requests not allowed\"\n //@ ensures o === \"bad-json\" ==> \\result === \"Invalid JSON body\"\n //@ ensures o === \"bad-method-path\" ==> \\result === \"Missing or invalid methodPath\"\n //@ ensures o === \"bad-args\" ==> \\result === \"Missing or invalid args array\"\n //@ ensures (o === \"run\" || o === \"run-full\") ==> \\result === \"\"\n if (o === \"forbidden\") return \"Forbidden: cross-origin requests not allowed\";\n if (o === \"bad-json\") return \"Invalid JSON body\";\n if (o === \"bad-method-path\") return \"Missing or invalid methodPath\";\n if (o === \"bad-args\") return \"Missing or invalid args array\";\n return \"\";\n}\n\n/**\n * The Redis TTL for a cache tier: none for staleTime 0, the long TTL from an hour up, else the\n * standard one. `staleTime` is React Query's `Millis`, the TTLs Redis's `Seconds`; the hour is\n * compared in milliseconds.\n *\n * @ensures exactly the model's TtlFor\n */\nexport function ttlFor(\n staleTime: Millis,\n redisTtl: Seconds,\n longRedisTtl: Seconds,\n): Seconds | null {\n //@ verify\n //@ ensures staleTime === 0 ==> \\result === null\n //@ ensures staleTime !== 0 && staleTime >= 3600000 ==> \\result === longRedisTtl\n //@ ensures staleTime !== 0 && staleTime < 3600000 ==> \\result === redisTtl\n if (staleTime === 0) return null;\n if (staleTime >= toMillis(hours(1))) return longRedisTtl;\n return redisTtl;\n}\n\n/** The Redis circuit breaker's state: consecutive failures, and when it closes (0 = closed). */\nexport interface Circuit {\n failures: number;\n openUntil: Millis;\n}\n\n/** The circuit's answer at a time: whether it is open, and its state after the check. */\nexport interface CircuitAnswer {\n open: boolean;\n next: Circuit;\n}\n\n/**\n * isCircuitOpen at `now`: closed at openUntil 0; past it, reset and closed; else open.\n *\n * @ensures exactly the model's CircuitCheck\n */\nexport function circuitCheck(c: Circuit, now: Millis): CircuitAnswer {\n //@ verify\n //@ ensures c.openUntil === 0 ==> !\\result.open && \\result.next === c\n //@ ensures c.openUntil !== 0 && now >= c.openUntil ==> !\\result.open && \\result.next.failures === 0 && \\result.next.openUntil === 0\n //@ ensures c.openUntil !== 0 && now < c.openUntil ==> \\result.open && \\result.next === c\n if (c.openUntil === 0) return { open: false, next: c };\n if (now >= c.openUntil) return { open: false, next: { failures: 0, openUntil: millis(0) } };\n return { open: true, next: c };\n}\n\n/**\n * Whether a failure count opens the circuit: five in a row.\n *\n * @ensures result ⟺ failures ≥ 5\n */\nexport function opensAt(failures: number): boolean {\n //@ verify\n //@ ensures \\result === (failures >= 5)\n return failures >= 5;\n}\n\n/**\n * A failure counts; from the threshold on the circuit opens for a minute from now.\n *\n * @ensures exactly the model's RecordFailure\n */\nexport function recordFailureOf(c: Circuit, now: Millis): Circuit {\n //@ verify\n //@ ensures \\result.failures === c.failures + 1\n //@ ensures opensAt(c.failures + 1) ==> \\result.openUntil === now + 60000\n //@ ensures !opensAt(c.failures + 1) ==> \\result.openUntil === c.openUntil\n const failures = c.failures + 1;\n if (opensAt(failures)) return { failures, openUntil: addMillis(now, toMillis(minutes(1))) };\n return { failures, openUntil: c.openUntil };\n}\n\n/**\n * A success clears the failure count and leaves openUntil.\n *\n * @ensures exactly the model's RecordSuccess\n */\nexport function recordSuccessOf(c: Circuit): Circuit {\n //@ verify\n //@ ensures \\result.failures === 0 && \\result.openUntil === c.openUntil\n return { failures: 0, openUntil: c.openUntil };\n}\n\n/**\n * authorize's verified flag: exactly the text \"true\".\n *\n * @ensures result ⟺ s = \"true\"\n */\nexport function verifiedFlag(s: string): boolean {\n //@ verify\n //@ ensures \\result === (s === \"true\")\n return s === \"true\";\n}\n\n/**\n * reCAPTCHA passes only with a secret, an ok response and the reply's optional `success` exactly\n * true (the score is not read).\n *\n * @ensures exactly the model's RecaptchaOk, success read as `=== true`\n */\nexport function recaptchaOk(\n hasSecret: boolean,\n httpOk: boolean,\n success: boolean | undefined,\n): boolean {\n //@ verify\n //@ ensures \\result === (hasSecret && httpOk && success === true)\n return hasSecret && httpOk && success === true;\n}\n\n/**\n * A customer id is used only above 0; anything else (NaN included, at the caller) is 0.\n *\n * @ensures result = n when n > 0, else 0\n */\nexport function positiveOrZero(n: number): number {\n //@ verify\n //@ ensures n > 0 ==> \\result === n\n //@ ensures n <= 0 ==> \\result === 0\n return n > 0 ? n : 0;\n}\n\n/**\n * The category page size: 24 when none (or 0) is given.\n *\n * @ensures exactly the model's ItemsLimit, a missing limit as 0\n */\nexport function itemsLimitOf(limit: number | undefined): number {\n //@ verify\n //@ ensures (limit === undefined || limit === 0) ==> \\result === 24\n //@ ensures limit !== undefined && limit !== 0 ==> \\result === limit\n if (limit === undefined) return 24;\n if (limit === 0) return 24;\n return limit;\n}\n\n/**\n * The cross-site opt-in as configured (`auth.crossSite`): on only when set to true, so a site\n * that says nothing stays off (atlas#105).\n *\n * @ensures exactly the model's CrossSiteOf\n */\nexport function crossSiteOf(flag: boolean | undefined): boolean {\n //@ verify\n //@ ensures \\result === (flag === true)\n return flag === true;\n}\n\n/**\n * Whether queryAction looks for a cross-site session (imports next/headers and reads the\n * cookie): only on a site that opted in and has a secret. Every other site never reads cookies\n * here, so its pages can render statically (atlas#105).\n *\n * @ensures exactly the model's ReadsSession\n */\nexport function readsSession(crossSite: boolean, hasSecret: boolean): boolean {\n //@ verify\n //@ ensures \\result === (crossSite && hasSecret)\n return crossSite && hasSecret;\n}\n\n/**\n * The target siteId authorize writes into the session: the sign-in's `siteId` only on an\n * opted-in site, and only when it is not empty (atlas#105).\n *\n * @ensures exactly the model's SignInTarget\n */\nexport function signInTarget(crossSite: boolean, siteId: string | undefined): string | undefined {\n //@ verify\n //@ ensures !crossSite ==> \\result === undefined\n //@ ensures crossSite && siteId === undefined ==> \\result === undefined\n //@ ensures crossSite && siteId !== undefined && siteId === \"\" ==> \\result === undefined\n //@ ensures crossSite && siteId !== undefined && siteId !== \"\" ==> \\result === siteId\n if (!crossSite) return undefined;\n if (siteId === undefined) return undefined;\n if (siteId === \"\") return undefined;\n return siteId;\n}\n\n/** How queryAction resolves its client. */\nexport type Resolution = \"scoped\" | \"global\" | \"uninit\";\n\n/**\n * resolveClient: scoped when credentials minted and a scoped client was made; else the global\n * client when one is registered (also for a valid session without a factory); else none.\n *\n * @ensures exactly the model's ResolveClient\n */\nexport function resolutionOf(minted: boolean, scopedMade: boolean, hasGlobal: boolean): Resolution {\n //@ verify\n //@ ensures minted && scopedMade ==> \\result === \"scoped\"\n //@ ensures !(minted && scopedMade) && hasGlobal ==> \\result === \"global\"\n //@ ensures !(minted && scopedMade) && !hasGlobal ==> \\result === \"uninit\"\n if (minted && scopedMade) return \"scoped\";\n return hasGlobal ? \"global\" : \"uninit\";\n}\n\n/** The scoped-client slot's decision. */\nexport type SlotDecision = \"hit\" | \"mint\" | \"no-client\";\n\n/**\n * getOrCreateScopedClient's single slot: a hit when it holds this key; else a new client when a\n * factory is registered; else none. An empty slot is \"\" at the caller, which no key equals (a\n * key holds a NUL).\n *\n * @ensures exactly the model's SlotDecisionOf\n */\nexport function slotDecisionOf(slotKey: string, key: string, hasFactory: boolean): SlotDecision {\n //@ verify\n //@ ensures slotKey === key ==> \\result === \"hit\"\n //@ ensures slotKey !== key && hasFactory ==> \\result === \"mint\"\n //@ ensures slotKey !== key && !hasFactory ==> \\result === \"no-client\"\n if (slotKey === key) return \"hit\";\n return hasFactory ? \"mint\" : \"no-client\";\n}\n\n/**\n * parseMethodPath: a non-empty path, in the allowlist when one is registered (permissive by\n * default); `listed` is the caller's Set lookup.\n *\n * @ensures exactly the model's ApprovePath\n */\nexport function approvePath(path: string, hasAllowlist: boolean, listed: boolean): boolean {\n //@ verify\n //@ ensures \\result === (path !== \"\" && (!hasAllowlist || listed))\n return path !== \"\" && (!hasAllowlist || listed);\n}\n\n/**\n * queryAction caches a call only through a wrapper, and only for a read leaf (augur-core's\n * `isReadMethod`, checked by the caller).\n *\n * @ensures exactly the model's UsesCache\n */\nexport function usesCache(hasWrapper: boolean, isRead: boolean): boolean {\n //@ verify\n //@ ensures \\result === (hasWrapper && isRead)\n return hasWrapper && isRead;\n}\n\n/**\n * The Auth.js session cookie decodeSessionJwt reads, and the salt it decodes with: the HTTPS\n * cookie when the request has one, else the plain one.\n *\n * @ensures exactly the model's SessionCookieName\n */\nexport function sessionCookieName(hasSecure: boolean): string {\n //@ verify\n //@ ensures hasSecure ==> \\result === \"__Secure-authjs.session-token\"\n //@ ensures !hasSecure ==> \\result === \"authjs.session-token\"\n return hasSecure ? \"__Secure-authjs.session-token\" : \"authjs.session-token\";\n}\n\n/** Which client a bounded call runs on (atlas#106). */\nexport type ClientChoice = \"client\" | \"view\" | \"refuse\";\n\n/**\n * queryActionWith's client: today's client with no options; else the client's `withRequest`\n * view, refused when the client has none (a call asked to be bounded never runs unbounded).\n *\n * @ensures exactly the model's ClientFor\n */\nexport function clientFor(hasOptions: boolean, hasWithRequest: boolean): ClientChoice {\n //@ verify\n //@ ensures !hasOptions ==> \\result === \"client\"\n //@ ensures hasOptions && hasWithRequest ==> \\result === \"view\"\n //@ ensures hasOptions && !hasWithRequest ==> \\result === \"refuse\"\n if (!hasOptions) return \"client\";\n return hasWithRequest ? \"view\" : \"refuse\";\n}\n\n/**\n * The scoped cache prefix: the session's siteId and \":\".\n *\n * @ensures exactly the model's ScopedPrefix\n */\nexport function scopedPrefix(siteId: string): string {\n //@ verify\n //@ ensures \\result === siteId + \":\"\n return siteId + \":\";\n}\n\n/**\n * withServerCache caches when the TTL is not 0 (missing or NaN is 0 at the caller; a `Seconds`\n * is never negative).\n *\n * @ensures exactly the model's ShouldCache\n */\nexport function shouldCache(ttl: Seconds): boolean {\n //@ verify\n //@ ensures \\result === (ttl !== 0)\n return ttl !== 0;\n}\n\n/**\n * The TTL a server cache call uses: a missing one (undefined or NaN, which the caller reads) is 0,\n * as `!redisTtl` had it.\n *\n * @ensures exactly the model's CacheTtl\n */\nexport function cacheTtlOf(missing: boolean, ttl: Seconds): Seconds {\n //@ verify\n //@ ensures \\result === (missing ? 0 : ttl)\n return missing ? seconds(0) : ttl;\n}\n\n/**\n * getInvMastDoc's positional uid: kept above 0, else none.\n *\n * @ensures result = uid when uid > 0, else undefined\n */\nexport function docUidOf(uid: number): number | undefined {\n //@ verify\n //@ ensures uid > 0 ==> \\result === uid\n //@ ensures uid <= 0 ==> \\result === undefined\n if (uid > 0) return uid;\n return undefined;\n}\n\n/**\n * The positional itemId is used only at uid 0 and when non-empty (\"\" for none, at the caller).\n *\n * @ensures result ⟺ uid = 0 ∧ itemId ≠ \"\"\n */\nexport function takesItemId(uid: number, itemId: string): boolean {\n //@ verify\n //@ ensures \\result === (uid === 0 && itemId !== \"\")\n return uid === 0 && itemId !== \"\";\n}\n\n/**\n * A doc call needs a uid (truthy at the caller) or a non-empty itemId.\n *\n * @ensures result ⟺ uidSet ∨ itemId ≠ \"\"\n */\nexport function hasDocKey(uidSet: boolean, itemId: string): boolean {\n //@ verify\n //@ ensures \\result === (uidSet || itemId !== \"\")\n return uidSet || itemId !== \"\";\n}\n\n/**\n * The configured payments mode, \"live\" by default.\n *\n * @ensures result = configured ?? \"live\"\n */\nexport function configuredModeOf(configured: string | undefined): string {\n //@ verify\n //@ ensures configured === undefined ==> \\result === \"live\"\n //@ ensures configured !== undefined ==> \\result === configured\n if (configured === undefined) return \"live\";\n return configured;\n}\n","//@ backend dafny\n\n/* Cache key for the per-request scoped SDK client (`sdk-client-store.ts`\n `getOrCreateScopedClient`). Verified with LemmaScript → Dafny (`pnpm proofs`; model:\n models/AugurServer.dfy `ScopedClientKey`, whose `ScopedClientKeyInjective` proves that for two\n siteIds with no NUL character, equal keys mean equal siteIds AND equal tokens, so two\n credential pairs never share a cached client; link:\n models/links/augur-server-scoped-client-key.dfy). Only the siteId needs to be NUL-free; the\n token may contain anything. Not proved: that every siteId reaching this function is NUL-free.\n That rests on `getSessionCredentials` (query-action.ts), the only mint point, refusing any\n siteId that fails augur-api's `isSiteId` (`[a-z0-9_-]+`, proved in augur-api), which is\n tested. */\n\n/** Character code of the separator; no siteId contains it. */\nconst SEPARATOR_CODE = 0;\n\n/** `siteId` has no NUL character, so the first NUL in a key marks where the siteId ends. */\nfunction hasNoSeparator(siteId: string): boolean {\n //@ verify\n //@ ensures \\result === !siteId.includes(String.fromCharCode(0))\n return !siteId.includes(String.fromCharCode(SEPARATOR_CODE));\n}\n\n/** The key `siteId + \"\\0\" + token`, or null (the refusal) when the siteId has a NUL. */\nfunction scopedClientKeyOf(siteId: string, token: string): string | null {\n //@ verify\n //@ ensures hasNoSeparator(siteId) ==> \\result === siteId + String.fromCharCode(0) + token\n //@ ensures !hasNoSeparator(siteId) ==> \\result === null\n if (!hasNoSeparator(siteId)) return null;\n return siteId + String.fromCharCode(SEPARATOR_CODE) + token;\n}\n\n/**\n * The key `siteId + \"\\0\" + token`. Callers MUST pass a siteId with no NUL character\n * (`getSessionCredentials` enforces `isSiteId`); with that, distinct pairs give distinct keys.\n * A siteId with a NUL throws instead of returning a key that could collide.\n *\n * @throws TypeError when `siteId` contains a NUL character\n */\nexport function scopedClientKey(siteId: string, token: string): string {\n const key = scopedClientKeyOf(siteId, token);\n if (key === null) {\n throw new TypeError(\"scopedClientKey: siteId must not contain a NUL character\");\n }\n return key;\n}\n","/**\n * Lightweight getter/setter for the raw SDK client instance, cache wrapper,\n * auth secret, client factory, and scoped client cache.\n *\n * queryAction resolves method paths on the SDK client directly (not on\n * SiteActions). This ensures the proxy pattern works end-to-end: the\n * proxy generates SDK namespace paths (e.g. \"pricing.priceEngine.get\")\n * which match the SDK client structure.\n *\n * The cache wrapper is a function registered by createServerSite() that\n * wraps SDK calls with Redis caching. It captures withServerCache + config\n * in its closure, so queryAction can use it without importing heavy deps.\n *\n * The auth secret, client factory, and scoped cache wrapper support\n * per-request session credentials for multi-tenant apps. queryAction\n * decodes the JWT from request cookies and creates scoped SDK clients\n * when the session contains a targetSiteId + token.\n *\n * This module has ZERO imports from actions/site, cache/, or any factory.\n * Same isolation constraints as site-actions-store.ts.\n */\n\nimport { approvePath, slotDecisionOf } from \"./rules\";\nimport { scopedClientKey } from \"./scoped-client-key\";\n\n/** Function that wraps an SDK call with server-side caching. */\nexport type SdkCallWrapper = (\n methodPath: string,\n sdkCall: () => Promise<unknown>,\n ...keyArgs: unknown[]\n) => Promise<unknown>;\n\n/** Function that wraps an SDK call with server-side caching using a specific prefix. */\nexport type ScopedCacheWrapper = (\n prefix: string,\n methodPath: string,\n sdkCall: () => Promise<unknown>,\n ...keyArgs: unknown[]\n) => Promise<unknown>;\n\n/** Function that creates a scoped SDK client with different credentials. */\nexport type ClientFactory = (siteId: string, bearerToken: string) => unknown;\n\ndeclare const SessionSiteIdBrand: unique symbol;\ndeclare const SessionBearerTokenBrand: unique symbol;\ndeclare const SessionCredentialsBrand: unique symbol;\ndeclare const ApprovedMethodPathBrand: unique symbol;\n\n/**\n * Site identifier extracted from a validated Auth.js session JWT cookie.\n *\n * Intended to be minted only by `getSessionCredentials` in query-action.ts.\n *\n * Brand strength: code-review signal, not type-system enforcement. TypeScript\n * allows `value as SessionSiteId` casts, so audit `as SessionSiteId` usages\n * to catch unintended mints — there should be exactly one, at the JWT mint\n * point.\n */\nexport type SessionSiteId = string & { readonly [SessionSiteIdBrand]: true };\n\n/**\n * Bearer token extracted from a validated Auth.js session JWT cookie.\n * Same intended-mint and brand-strength caveat as {@link SessionSiteId}.\n */\nexport type SessionBearerToken = string & { readonly [SessionBearerTokenBrand]: true };\n\n/**\n * Paired session credentials. Bundles `siteId` and `token` from the same\n * validated session into one value so downstream functions can accept the\n * pair as a unit, instead of two separate parameters that callers might\n * accidentally mix across sessions.\n *\n * Intended to be minted only by `getSessionCredentials` in query-action.ts,\n * which performs the cross-check that the bearer's `client_id` siteId\n * matches `targetSiteId`. Anything that holds a `SessionCredentials` *was*\n * cross-checked at mint time — provided the value came through that mint\n * and not via a cast.\n *\n * Brand strength: same code-review signal as the field brands. `value as\n * SessionCredentials` compiles. Audit `as SessionCredentials` usages — there\n * should be exactly one, in `getSessionCredentials`.\n */\nexport type SessionCredentials = {\n readonly siteId: SessionSiteId;\n readonly token: SessionBearerToken;\n readonly [SessionCredentialsBrand]: true;\n};\n\n/**\n * SDK method path validated against the registered allowlist.\n *\n * Intended to be minted only by `parseMethodPath` below. Functions that walk\n * the path into the SDK client (notably `resolveMethod`) demand this type\n * so that an unvalidated string flowing into the walker is a compile error\n * for code that respects the convention.\n *\n * Brand strength: code-review signal. `value as ApprovedMethodPath` compiles.\n * Audit `as ApprovedMethodPath` usages — there should be one, in\n * `parseMethodPath`.\n *\n * Scope of validation: this is a *site-level surface restriction*, not a\n * security boundary. augur-api is the auth authority; the allowlist limits\n * what the application's proxy will forward to the SDK, not what tokens are\n * permitted to do. Useful for narrowing same-origin attack surface (XSS,\n * malicious bundled deps); not a substitute for API-level authorization.\n */\nexport type ApprovedMethodPath = string & { readonly [ApprovedMethodPathBrand]: true };\n\nconst g = globalThis as unknown as {\n __augur_sdk_client?: unknown;\n __augur_sdk_call_wrapper?: SdkCallWrapper;\n __augur_auth_secret?: string;\n __augur_cross_site?: boolean;\n __augur_client_factory?: ClientFactory;\n __augur_scoped_cache_wrapper?: ScopedCacheWrapper;\n __augur_allowed_method_paths?: Set<string>;\n};\n\nlet _cachedClient: unknown = null;\nlet _cachedWrapper: SdkCallWrapper | null = null;\nlet _cachedAuthSecret: string | null = null;\nlet _cachedCrossSite = false;\nlet _cachedClientFactory: ClientFactory | null = null;\nlet _cachedScopedCacheWrapper: ScopedCacheWrapper | null = null;\nlet _scopedClient: { key: string; client: unknown } | null = null;\nlet _allowedMethodPaths: Set<string> | null = null;\n\n/** Register the raw SDK client instance. Called by createServerSite(). */\nexport function registerSdkClient(client: unknown): void {\n _cachedClient = client;\n g.__augur_sdk_client = client;\n}\n\n/** Returns the registered SDK client, or null if not yet registered. */\nexport function getSdkClientOrNull(): unknown {\n const client = g.__augur_sdk_client ?? _cachedClient;\n if (client) {\n if (!g.__augur_sdk_client) {\n g.__augur_sdk_client = client;\n }\n return client;\n }\n return null;\n}\n\n/**\n * Register a cache wrapper for SDK calls. Called by createServerSite().\n * The wrapper captures withServerCache + config in its closure so that\n * queryAction can use Redis caching without importing heavy deps.\n */\nexport function registerSdkCallWrapper(wrapper: SdkCallWrapper): void {\n _cachedWrapper = wrapper;\n g.__augur_sdk_call_wrapper = wrapper;\n}\n\n/** Returns the registered cache wrapper, or null if not registered. */\nexport function getSdkCallWrapper(): SdkCallWrapper | null {\n return g.__augur_sdk_call_wrapper ?? _cachedWrapper ?? null;\n}\n\n/** Register the auth secret for JWT decoding. Called by createServerSite(). */\nexport function registerAuthSecret(secret: string): void {\n _cachedAuthSecret = secret;\n g.__augur_auth_secret = secret;\n}\n\n/** Returns the registered auth secret, or null if not registered. */\nexport function getAuthSecret(): string | null {\n return g.__augur_auth_secret ?? _cachedAuthSecret ?? null;\n}\n\n/**\n * Register the cross-site opt-in (`auth.crossSite`, through rules.crossSiteOf). Called by\n * createServerSite(). The ONE source both queryAction's session read and authorize's sign-in\n * target read (models/AugurServer.dfy, \"the cross-site opt-in\", atlas#105).\n */\nexport function registerCrossSite(on: boolean): void {\n _cachedCrossSite = on;\n g.__augur_cross_site = on;\n}\n\n/** Whether this site opted in to cross-site sessions; false unless registered. */\nexport function getCrossSite(): boolean {\n return g.__augur_cross_site ?? _cachedCrossSite;\n}\n\n/** Register a factory that creates scoped SDK clients. Called by createServerSite(). */\nexport function registerClientFactory(factory: ClientFactory): void {\n _cachedClientFactory = factory;\n g.__augur_client_factory = factory;\n}\n\n/** Returns the registered client factory, or null if not registered. */\nexport function getClientFactory(): ClientFactory | null {\n return g.__augur_client_factory ?? _cachedClientFactory ?? null;\n}\n\n/** Register a scoped cache wrapper that accepts a prefix. Called by createServerSite(). */\nexport function registerScopedCacheWrapper(wrapper: ScopedCacheWrapper): void {\n _cachedScopedCacheWrapper = wrapper;\n g.__augur_scoped_cache_wrapper = wrapper;\n}\n\n/** Returns the registered scoped cache wrapper, or null if not registered. */\nexport function getScopedCacheWrapper(): ScopedCacheWrapper | null {\n return g.__augur_scoped_cache_wrapper ?? _cachedScopedCacheWrapper ?? null;\n}\n\n/**\n * Returns a cached scoped client for the given credentials, or creates one\n * via the registered factory. Caches the last credential pair so that\n * multiple queryAction calls in the same request reuse the same client.\n *\n * Accepts `SessionCredentials` (a branded paired type) rather than two raw\n * strings: well-behaved callers pass the pair as a unit, eliminating the\n * \"siteId from session A combined with token from session B\" mistake at\n * the type level — see {@link SessionCredentials} brand-strength caveat.\n * The factory itself still receives strings (its signature is user-facing API).\n *\n * ## Trust\n *\n * @trusted credentials // the SessionCredentials brand carries the\n * // bearer/session siteId cross-check discharged at\n * // mint time by `getSessionCredentials`. This\n * // function does NOT re-validate; if a non-mint\n * // path produces a SessionCredentials value (via\n * // `as` cast), this function will materialise a\n * // client for whatever siteId + token are present\n * // in the value. Audit `as SessionCredentials`\n * // usages — there should be exactly one, in\n * // getSessionCredentials.\n *\n * ## Decision (Property)\n *\n * let key = `${credentials.siteId}\\0${credentials.token}` in\n * result(credentials) =\n * _scopedClient.client when _scopedClient?.key = key // cache hit\n * factory(siteId, token) when factory ≠ null // mint + cache\n * null when factory = null // uninitialised\n *\n * Three outcomes. Throws only if `credentials.siteId` contains a NUL\n * (`scopedClientKey`), which the mint point rules out by `isSiteId`, so it\n * is reachable only through an `as SessionCredentials` cast. Side effect on\n * the mint path only:\n * `_scopedClient` is replaced with `{key, client}` so the next call with\n * the same credentials hits the cached branch. Minting implicitly evicts\n * the previous `_scopedClient` value (single-slot semantics — see invariant).\n *\n * ## Invariant — null-byte key separator (machine-checked)\n *\n * The key is `scopedClientKey(siteId, token)` = `siteId + \"\\0\" + token`\n * (`scoped-client-key.ts`). Dafny proves (`ScopedClientKeyInjective`) that\n * for two NUL-free siteIds, equal keys mean equal siteIds and equal tokens,\n * so the cache cannot hand one credential pair another pair's client. Only\n * the siteId has to be NUL-free; the token may contain anything.\n *\n * The precondition is enforced, not assumed: `getSessionCredentials`, the\n * only mint point, refuses any `targetSiteId` that fails augur-api's\n * `isSiteId` (`[a-z0-9_-]+`, machine-checked in augur-api), and\n * `scopedClientKey` throws on a NUL rather than return a key that could\n * collide. What is NOT proved: that no other code path casts a value to\n * `SessionCredentials` (see the Trust note above).\n *\n * Do NOT change the separator to a character that could appear in a\n * siteId; the proof is stated for NUL and would have to be redone.\n *\n * ## Invariant — single-slot cache (eviction is implicit)\n *\n * `_scopedClient` holds at most one entry. Minting a client for\n * credentials A AFTER credentials B were cached evicts B unrecoverably;\n * a later request with credentials B will call the factory again rather\n * than retrieving the previously-minted client.\n *\n * This is intentional. Scoped clients are per-request shortcuts; the\n * cache exists to let multiple queryAction calls within a single request\n * share an SDK client without re-running the factory. Cross-request\n * caching is NOT a goal — Next.js may or may not preserve module state\n * across invocations, so any retention beyond the single slot is\n * best-effort and MUST NOT be relied upon for correctness.\n *\n * A future refactor to multi-slot LRU would change this contract:\n * per-credential client identity becomes ambiguous across requests, and\n * eviction policy becomes security-relevant (e.g. oldest-out could re-mint\n * a client immediately after a credential rotation, surfacing stale\n * permissions to the next caller). Do not multi-slot this without\n * re-deriving the contract — particularly the relationship to credential\n * rotation and bearer-token revocation in augur-api.\n *\n * ## Postcondition — identity, not transformation\n *\n * result ≠ null ⟹ result is referentially identical to the value the\n * factory returned for the matching credentials.\n *\n * The cache stores and serves the factory's exact return value. It does\n * not wrap, transform, proxy, or copy the client. Consumers that mutate\n * the returned client (e.g. setting per-request properties on a singleton\n * field) will observe the mutation on subsequent cache hits within the\n * same request — by design.\n */\nexport function getOrCreateScopedClient(credentials: SessionCredentials): unknown {\n const { siteId, token } = credentials;\n const key = scopedClientKey(siteId, token);\n const factory = g.__augur_client_factory ?? _cachedClientFactory;\n const decision = slotDecisionOf(_scopedClient?.key ?? \"\", key, !!factory);\n if (decision === \"hit\") return _scopedClient!.client;\n if (decision === \"no-client\") return null;\n\n const client = factory!(siteId, token);\n _scopedClient = { key, client };\n return client;\n}\n\n/**\n * Register one or more SDK method paths the application is permitted to call\n * through `queryAction`. Subsequent calls accumulate (idempotent on repeats).\n *\n * This is *site-level surface restriction*, not security. augur-api remains\n * the auth authority; this primitive lets a site narrow its proxy's surface\n * to the methods its UI actually wires up. Useful as defense-in-depth against\n * same-origin XSS or compromised bundled deps POSTing arbitrary methodPaths\n * to `/api/augur` — those calls will hit augur-api with the user's bearer\n * (which augur-api will allow if the bearer is authorized), but the allowlist\n * stops them from leaving the proxy in the first place.\n *\n * Permissive default: if `registerAllowedMethodPaths` is never called, all\n * non-empty paths pass — the proxy behaves as a transparent forwarder, which\n * is the package's design intent. Sites that want surface restriction opt in\n * by calling this function.\n */\nexport function registerAllowedMethodPaths(paths: readonly string[]): void {\n if (_allowedMethodPaths === null) {\n _allowedMethodPaths = new Set();\n g.__augur_allowed_method_paths = _allowedMethodPaths;\n }\n for (const p of paths) _allowedMethodPaths.add(p);\n}\n\n/**\n * Returns true if the application has registered an allowlist via\n * {@link registerAllowedMethodPaths}. When false, `parseMethodPath` operates\n * in permissive mode (any non-empty string passes).\n */\nexport function isMethodPathAllowlistRegistered(): boolean {\n return (g.__augur_allowed_method_paths ?? _allowedMethodPaths) !== null;\n}\n\n/**\n * Validate a candidate method path against the registered allowlist.\n *\n * - Returns the branded value if the path is a non-empty string AND\n * (no allowlist is registered OR the path is in the allowlist).\n * - Returns null if the path is not a non-empty string, or if an allowlist\n * has been registered and the path is not in it.\n *\n * The brand on the return type is the only way internal code can produce an\n * `ApprovedMethodPath`. Functions that walk the path into the SDK should\n * accept `ApprovedMethodPath`, forcing the caller to discharge the validation.\n */\nexport function parseMethodPath(candidate: unknown): ApprovedMethodPath | null {\n if (typeof candidate !== \"string\") return null;\n const allowed = g.__augur_allowed_method_paths ?? _allowedMethodPaths;\n const listed = allowed !== null && allowed.has(candidate);\n if (!approvePath(candidate, allowed !== null, listed)) return null;\n return candidate as ApprovedMethodPath;\n}\n\n/** Clears the registered SDK client, wrapper, and session stores. Used in tests only. @internal */\nexport function clearSdkClient(): void {\n _cachedClient = null;\n _cachedWrapper = null;\n _cachedAuthSecret = null;\n _cachedCrossSite = false;\n _cachedClientFactory = null;\n _cachedScopedCacheWrapper = null;\n _scopedClient = null;\n _allowedMethodPaths = null;\n g.__augur_sdk_client = undefined;\n g.__augur_sdk_call_wrapper = undefined;\n g.__augur_auth_secret = undefined;\n g.__augur_cross_site = undefined;\n g.__augur_client_factory = undefined;\n g.__augur_scoped_cache_wrapper = undefined;\n g.__augur_allowed_method_paths = undefined;\n}\n"],"mappings":"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","names":[]}
|
package/dist/hooks.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
queryAction
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-2RAKVFB5.js";
|
|
5
|
+
import "./chunk-Z53NEFEQ.js";
|
|
6
|
+
import "./chunk-V76GZZF3.js";
|
|
6
7
|
|
|
7
8
|
// src/hooks.ts
|
|
8
9
|
import { createQueryActionProxy } from "@simpleapps-com/augur-core";
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks.ts"],"sourcesContent":["// \"use client\" banner is injected by tsup at build time.\n// Client-side proxy that generates React Query options backed by server actions.\n//\n// IMPORTANT: This file MUST NOT import from server-actions.ts or any module\n// that transitively depends on ioredis/withServerCache/action factories.\n// The queryAction import comes from query-action.ts which only depends on\n// site-actions-store.ts (a lightweight globalThis getter with zero deps).\n\nimport { createQueryActionProxy } from \"@simpleapps-com/augur-core\";\nimport type {\n DeepQueryOptions,\n OptionsProxyConfig,\n QueryActionFn,\n} from \"@simpleapps-com/augur-core\";\nimport type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport { registerQueryAction } from \"@simpleapps-com/augur-hooks\";\nimport { queryAction as defaultQueryAction } from \"./query-action\";\n\n// Auto-register queryAction so augur-hooks provider and hooks can detect it.\n// This runs as a side effect when any site imports from augur-server/hooks.\nregisterQueryAction(defaultQueryAction);\n\n// Re-export for consumers who need the type\nexport type { QueryActionFn };\n\n/**\n * Creates a client-side proxy that mirrors the SDK namespace and routes\n * every method call through a server action function.\n *\n * The `queryAction` parameter is optional. If omitted, it uses the built-in\n * server action from `@simpleapps-com/augur-server/query-action`.\n *\n * @example\n * ```tsx\n * import { createServerQueryProxy } from \"@simpleapps-com/augur-server/hooks\";\n *\n * const q = createServerQueryProxy();\n *\n * // Reads — any SDK method, routed through server actions\n * const { data: item } = useQuery(q.items.invMast.doc.get(42));\n * const { data: price } = useQuery(q.pricing.priceEngine.list({ itemId, customerId }));\n *\n * // Infinite queries — spread and add infinite-specific options\n * const { data, fetchNextPage } = useInfiniteQuery({\n * ...q.items.categories.items.list(itemCategoryUid, filters),\n * getNextPageParam: (lastPage, pages) => nextOffset(lastPage, pages), // the site's paging rule\n * initialPageParam: 0,\n * });\n *\n * // Mutations — write methods return mutation options\n * const addToCart = useMutation(q.commerce.cartLine.add.create());\n * ```\n */\nexport function createServerQueryProxy<TApi extends object = AugurAPI>(\n queryActionOrConfig?: QueryActionFn | OptionsProxyConfig,\n config?: OptionsProxyConfig,\n): DeepQueryOptions<TApi> {\n const queryAction =\n typeof queryActionOrConfig === \"function\" ? queryActionOrConfig : defaultQueryAction;\n const resolvedConfig = typeof queryActionOrConfig === \"function\" ? config : queryActionOrConfig;\n\n return createQueryActionProxy<TApi>(queryAction, resolvedConfig);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/hooks.ts"],"sourcesContent":["// \"use client\" banner is injected by tsup at build time.\n// Client-side proxy that generates React Query options backed by server actions.\n//\n// IMPORTANT: This file MUST NOT import from server-actions.ts or any module\n// that transitively depends on ioredis/withServerCache/action factories.\n// The queryAction import comes from query-action.ts which only depends on\n// site-actions-store.ts (a lightweight globalThis getter with zero deps).\n\nimport { createQueryActionProxy } from \"@simpleapps-com/augur-core\";\nimport type {\n DeepQueryOptions,\n OptionsProxyConfig,\n QueryActionFn,\n} from \"@simpleapps-com/augur-core\";\nimport type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport { registerQueryAction } from \"@simpleapps-com/augur-hooks\";\nimport { queryAction as defaultQueryAction } from \"./query-action\";\n\n// Auto-register queryAction so augur-hooks provider and hooks can detect it.\n// This runs as a side effect when any site imports from augur-server/hooks.\nregisterQueryAction(defaultQueryAction);\n\n// Re-export for consumers who need the type\nexport type { QueryActionFn };\n\n/**\n * Creates a client-side proxy that mirrors the SDK namespace and routes\n * every method call through a server action function.\n *\n * The `queryAction` parameter is optional. If omitted, it uses the built-in\n * server action from `@simpleapps-com/augur-server/query-action`.\n *\n * @example\n * ```tsx\n * import { createServerQueryProxy } from \"@simpleapps-com/augur-server/hooks\";\n *\n * const q = createServerQueryProxy();\n *\n * // Reads — any SDK method, routed through server actions\n * const { data: item } = useQuery(q.items.invMast.doc.get(42));\n * const { data: price } = useQuery(q.pricing.priceEngine.list({ itemId, customerId }));\n *\n * // Infinite queries — spread and add infinite-specific options\n * const { data, fetchNextPage } = useInfiniteQuery({\n * ...q.items.categories.items.list(itemCategoryUid, filters),\n * getNextPageParam: (lastPage, pages) => nextOffset(lastPage, pages), // the site's paging rule\n * initialPageParam: 0,\n * });\n *\n * // Mutations — write methods return mutation options\n * const addToCart = useMutation(q.commerce.cartLine.add.create());\n * ```\n */\nexport function createServerQueryProxy<TApi extends object = AugurAPI>(\n queryActionOrConfig?: QueryActionFn | OptionsProxyConfig,\n config?: OptionsProxyConfig,\n): DeepQueryOptions<TApi> {\n const queryAction =\n typeof queryActionOrConfig === \"function\" ? queryActionOrConfig : defaultQueryAction;\n const resolvedConfig = typeof queryActionOrConfig === \"function\" ? config : queryActionOrConfig;\n\n return createQueryActionProxy<TApi>(queryAction, resolvedConfig);\n}\n"],"mappings":";;;;;;;AAQA,SAAS,8BAA8B;AAOvC,SAAS,2BAA2B;AAKpC,oBAAoB,WAAkB;AAiC/B,SAAS,uBACd,qBACA,QACwB;AACxB,QAAMA,eACJ,OAAO,wBAAwB,aAAa,sBAAsB;AACpE,QAAM,iBAAiB,OAAO,wBAAwB,aAAa,SAAS;AAE5E,SAAO,uBAA6BA,cAAa,cAAc;AACjE;","names":["queryAction"]}
|
package/dist/index.js
CHANGED
|
@@ -21,10 +21,12 @@ import {
|
|
|
21
21
|
unwrap,
|
|
22
22
|
unwrapOr,
|
|
23
23
|
withServerCache
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-SFXO74RC.js";
|
|
25
|
+
import "./chunk-JIYVQWXK.js";
|
|
25
26
|
import {
|
|
26
27
|
recaptchaOk
|
|
27
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-Z53NEFEQ.js";
|
|
29
|
+
import "./chunk-V76GZZF3.js";
|
|
28
30
|
|
|
29
31
|
// src/server-query-client.ts
|
|
30
32
|
import { cache } from "react";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server-query-client.ts","../src/recaptcha.ts"],"sourcesContent":["import { cache } from \"react\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\n/**\n * Creates a server-side query client optimised for prefetching.\n *\n * - No persistence (server-only)\n * - No GC timers (gcTime: Infinity), so the client is freed with the request\n * - No retries (fail fast on server)\n * - No refetching (server renders are one-shot)\n */\nexport function createServerQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: CACHE_CONFIG.STATIC.staleTime,\n // Infinity = no GC timer. A finite value pins this per-request client\n // (and its whole cache) in memory until the timer fires (#481).\n gcTime: Infinity,\n retry: 0,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n },\n },\n });\n}\n\n/**\n * Returns a per-request singleton QueryClient for React Server Components.\n *\n * React's `cache()` deduplicates calls within a single server request,\n * so each request gets its own QueryClient while avoiding the cross-request\n * state leakage that a module-level singleton would cause.\n */\nexport const getServerQueryClient = cache((): QueryClient => createServerQueryClient());\n","import { recaptchaOk } from \"./rules\";\n\n/**\n * Server-side Google reCAPTCHA v3 verification.\n * Used by API routes that accept public form submissions.\n */\nexport async function verifyRecaptcha(token: string): Promise<boolean> {\n try {\n const secretKey = process.env[\"RECAPTCHA_SECRET_KEY\"];\n if (!secretKey) return recaptchaOk(false, false, undefined);\n\n const res = await fetch(\"https://www.google.com/recaptcha/api/siteverify\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n body: new URLSearchParams({ secret: secretKey, response: token }),\n });\n if (!res.ok) {\n console.error(\"reCAPTCHA verify failed:\", res.status);\n return recaptchaOk(true, false, undefined);\n }\n const result = (await res.json()) as { success?: boolean };\n return recaptchaOk(true, true, result.success);\n } catch (error) {\n console.error(\"reCAPTCHA verify error:\", error);\n return false;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/server-query-client.ts","../src/recaptcha.ts"],"sourcesContent":["import { cache } from \"react\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\n/**\n * Creates a server-side query client optimised for prefetching.\n *\n * - No persistence (server-only)\n * - No GC timers (gcTime: Infinity), so the client is freed with the request\n * - No retries (fail fast on server)\n * - No refetching (server renders are one-shot)\n */\nexport function createServerQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: CACHE_CONFIG.STATIC.staleTime,\n // Infinity = no GC timer. A finite value pins this per-request client\n // (and its whole cache) in memory until the timer fires (#481).\n gcTime: Infinity,\n retry: 0,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n },\n },\n });\n}\n\n/**\n * Returns a per-request singleton QueryClient for React Server Components.\n *\n * React's `cache()` deduplicates calls within a single server request,\n * so each request gets its own QueryClient while avoiding the cross-request\n * state leakage that a module-level singleton would cause.\n */\nexport const getServerQueryClient = cache((): QueryClient => createServerQueryClient());\n","import { recaptchaOk } from \"./rules\";\n\n/**\n * Server-side Google reCAPTCHA v3 verification.\n * Used by API routes that accept public form submissions.\n */\nexport async function verifyRecaptcha(token: string): Promise<boolean> {\n try {\n const secretKey = process.env[\"RECAPTCHA_SECRET_KEY\"];\n if (!secretKey) return recaptchaOk(false, false, undefined);\n\n const res = await fetch(\"https://www.google.com/recaptcha/api/siteverify\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n body: new URLSearchParams({ secret: secretKey, response: token }),\n });\n if (!res.ok) {\n console.error(\"reCAPTCHA verify failed:\", res.status);\n return recaptchaOk(true, false, undefined);\n }\n const result = (await res.json()) as { success?: boolean };\n return recaptchaOk(true, true, result.success);\n } catch (error) {\n console.error(\"reCAPTCHA verify error:\", error);\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAUtB,SAAS,0BAAuC;AACrD,SAAO,IAAI,YAAY;AAAA,IACrB,gBAAgB;AAAA,MACd,SAAS;AAAA,QACP,WAAW,aAAa,OAAO;AAAA;AAAA;AAAA,QAG/B,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,gBAAgB;AAAA,QAChB,sBAAsB;AAAA,QACtB,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AASO,IAAM,uBAAuB,MAAM,MAAmB,wBAAwB,CAAC;;;AC9BtF,eAAsB,gBAAgB,OAAiC;AACrE,MAAI;AACF,UAAM,YAAY,QAAQ,IAAI,sBAAsB;AACpD,QAAI,CAAC,UAAW,QAAO,YAAY,OAAO,OAAO,MAAS;AAE1D,UAAM,MAAM,MAAM,MAAM,mDAAmD;AAAA,MACzE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,oCAAoC;AAAA,MAC/D,MAAM,IAAI,gBAAgB,EAAE,QAAQ,WAAW,UAAU,MAAM,CAAC;AAAA,IAClE,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,cAAQ,MAAM,4BAA4B,IAAI,MAAM;AACpD,aAAO,YAAY,MAAM,OAAO,MAAS;AAAA,IAC3C;AACA,UAAM,SAAU,MAAM,IAAI,KAAK;AAC/B,WAAO,YAAY,MAAM,MAAM,OAAO,OAAO;AAAA,EAC/C,SAAS,OAAO;AACd,YAAQ,MAAM,2BAA2B,KAAK;AAC9C,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/query-action.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SessionCredentials, type ApprovedMethodPath } from "./sdk-client-store";
|
|
2
2
|
import { unwrapBaseResponse } from "@simpleapps-com/augur-core";
|
|
3
|
-
import { type BaseResponse } from "@simpleapps-com/augur-api";
|
|
3
|
+
import { type BaseResponse, type CallOptions } from "@simpleapps-com/augur-api";
|
|
4
4
|
/**
|
|
5
5
|
* Resolve session credentials from the Auth.js JWT cookie.
|
|
6
6
|
*
|
|
@@ -104,6 +104,29 @@ export declare function queryAction(methodPath: string, ...args: unknown[]): Pro
|
|
|
104
104
|
* @returns The SDK method's result unchanged (possibly from Redis cache)
|
|
105
105
|
*/
|
|
106
106
|
export declare function queryActionRaw<T = unknown>(methodPath: string, ...args: unknown[]): Promise<BaseResponse<T>>;
|
|
107
|
+
/**
|
|
108
|
+
* `queryAction`, bounded (atlas#106): `options.deadline` caps the whole call in milliseconds
|
|
109
|
+
* (every retry and the waits between them), and `options.signal` lets the caller cancel it. At
|
|
110
|
+
* the deadline the call rejects with a `TimeoutError` (the request is cancelled, nothing more is
|
|
111
|
+
* retried, nothing is cached), so a server render can fall back to a client-side fetch.
|
|
112
|
+
*
|
|
113
|
+
* Server code (an SSR render) SHOULD set a deadline: with none, the SDK's retry budget (3 retries
|
|
114
|
+
* at 30 s each, plus backoff) becomes page latency. Called as a server action from the browser,
|
|
115
|
+
* only `deadline` crosses: an `AbortSignal` can't be serialized.
|
|
116
|
+
*
|
|
117
|
+
* The options are not SDK arguments and not part of the cache key, so a bounded call and an
|
|
118
|
+
* unbounded one share one Redis entry. Needs an `@simpleapps-com/augur-api` with
|
|
119
|
+
* `AugurAPI.withRequest`; with an older client the call is refused rather than run unbounded.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const items = await queryActionWith({ deadline: 5000 }, "items.categories.items.list", uid, params)
|
|
124
|
+
* .catch(() => undefined); // past 5 s: render without them, fetch on the client
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function queryActionWith(options: CallOptions, methodPath: string, ...args: unknown[]): Promise<unknown>;
|
|
128
|
+
/** `queryActionRaw`, bounded: the same options as {@link queryActionWith}. */
|
|
129
|
+
export declare function queryActionRawWith<T = unknown>(options: CallOptions, methodPath: string, ...args: unknown[]): Promise<BaseResponse<T>>;
|
|
107
130
|
/** Reset lazy-loaded imports. Used in tests only. @internal */
|
|
108
131
|
export declare function resetSessionImports(): void;
|
|
109
132
|
export { unwrapBaseResponse, getSessionCredentials, resolveMethod };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-action.d.ts","sourceRoot":"","sources":["../src/query-action.ts"],"names":[],"mappings":"AAUA,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EAGxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAGL,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"query-action.d.ts","sourceRoot":"","sources":["../src/query-action.ts"],"names":[],"mappings":"AAUA,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EAGxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAGL,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAiG1F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,iBAAe,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CA6BzE;AAmFD;;;;;GAKG;AACH,iBAAS,aAAa,CACpB,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,kBAAkB,GAC7B,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAkBvC;AA4LD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAE1F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9C,UAAU,EAAE,MAAM,EAClB,GAAG,IAAI,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,EAClB,GAAG,IAAI,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,OAAO,CAAC,CAElB;AAED,8EAA8E;AAC9E,wBAAsB,kBAAkB,CAAC,CAAC,GAAG,OAAO,EAClD,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,EAClB,GAAG,IAAI,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1B;AAED,+DAA+D;AAC/D,wBAAgB,mBAAmB,IAAI,IAAI,CAI1C;AAED,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/query-action.js
CHANGED
|
@@ -3,15 +3,20 @@ import {
|
|
|
3
3
|
getSessionCredentials,
|
|
4
4
|
queryAction,
|
|
5
5
|
queryActionRaw,
|
|
6
|
+
queryActionRawWith,
|
|
7
|
+
queryActionWith,
|
|
6
8
|
resetSessionImports,
|
|
7
9
|
resolveMethod,
|
|
8
10
|
unwrapBaseResponse
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-2RAKVFB5.js";
|
|
12
|
+
import "./chunk-Z53NEFEQ.js";
|
|
13
|
+
import "./chunk-V76GZZF3.js";
|
|
11
14
|
export {
|
|
12
15
|
getSessionCredentials,
|
|
13
16
|
queryAction,
|
|
14
17
|
queryActionRaw,
|
|
18
|
+
queryActionRawWith,
|
|
19
|
+
queryActionWith,
|
|
15
20
|
resetSessionImports,
|
|
16
21
|
resolveMethod,
|
|
17
22
|
unwrapBaseResponse
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Millis, Seconds } from "./duration";
|
|
2
|
+
/**
|
|
3
|
+
* Rows asked for per call: 100. With an empty-page stop, the route's own ceiling can be lower
|
|
4
|
+
* without losing rows (model `CappedRouteShowsWhy`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function pageSize(): number;
|
|
7
|
+
/** Calls one read makes at most: 50 (5,000 rows at 100 a call). */
|
|
8
|
+
export declare function pageCap(): number;
|
|
9
|
+
/**
|
|
10
|
+
* After a page, read on while it held rows and the cap leaves another call.
|
|
11
|
+
*
|
|
12
|
+
* @ensures exactly the model's Continues
|
|
13
|
+
*/
|
|
14
|
+
export declare function continues(pageLength: number, pagesRead: number, cap: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The next page starts past the rows this page actually held, never at page × size, so a route
|
|
17
|
+
* that answers fewer rows than asked loses none.
|
|
18
|
+
*
|
|
19
|
+
* @ensures exactly the model's NextOffset
|
|
20
|
+
*/
|
|
21
|
+
export declare function nextOffset(offset: number, pageLength: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* The read stopped on the cap, not on an empty page: it may be missing rows, and says so.
|
|
24
|
+
*
|
|
25
|
+
* @ensures exactly the model's CapReached
|
|
26
|
+
*/
|
|
27
|
+
export declare function capReached(lastPageLength: number, pagesRead: number, cap: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The TTL a factory's read-through uses: 0 (no cache) when missing or on a path the server never
|
|
30
|
+
* caches (augur-core `isServerNoCachePath`), the minute on a P21 path (`isP21Path`), else the
|
|
31
|
+
* factory's TTL.
|
|
32
|
+
*
|
|
33
|
+
* @ensures exactly the model's ReadThroughTtl
|
|
34
|
+
*/
|
|
35
|
+
export declare function readThroughTtl(missing: boolean, noCachePath: boolean, p21Path: boolean, ttl: Seconds): Seconds;
|
|
36
|
+
/**
|
|
37
|
+
* queryAction's server TTL: none for a tier without a Redis TTL (the user tier, which caches only
|
|
38
|
+
* in the browser), the P21 tier's own minute, else `ttlFor` as before. `ttlFor` alone reads only
|
|
39
|
+
* the browser's staleTime, so it would put user reads back in Redis and give P21 reads the
|
|
40
|
+
* site's hour (model `TtlForAloneWouldCacheUserReads`).
|
|
41
|
+
*
|
|
42
|
+
* @ensures exactly the model's ServerTtl
|
|
43
|
+
*/
|
|
44
|
+
export declare function serverTtlOf(hasRedisTtl: boolean, isP21: boolean, staleTime: Millis, redisTtl: Seconds, longRedisTtl: Seconds): Seconds | null;
|
|
45
|
+
//# sourceMappingURL=read-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-rules.d.ts","sourceRoot":"","sources":["../src/read-rules.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAYlD;;;GAGG;AACH,wBAAgB,QAAQ,IAAI,MAAM,CAIjC;AAED,mEAAmE;AACnE,wBAAgB,OAAO,IAAI,MAAM,CAIhC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAQrF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAOrE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAQ1F;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,GACX,OAAO,CAST;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,OAAO,EACpB,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,OAAO,GACpB,OAAO,GAAG,IAAI,CAWhB"}
|
package/dist/rules.d.ts
CHANGED
|
@@ -221,6 +221,22 @@ export declare function approvePath(path: string, hasAllowlist: boolean, listed:
|
|
|
221
221
|
* @ensures exactly the model's UsesCache
|
|
222
222
|
*/
|
|
223
223
|
export declare function usesCache(hasWrapper: boolean, isRead: boolean): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* The Auth.js session cookie decodeSessionJwt reads, and the salt it decodes with: the HTTPS
|
|
226
|
+
* cookie when the request has one, else the plain one.
|
|
227
|
+
*
|
|
228
|
+
* @ensures exactly the model's SessionCookieName
|
|
229
|
+
*/
|
|
230
|
+
export declare function sessionCookieName(hasSecure: boolean): string;
|
|
231
|
+
/** Which client a bounded call runs on (atlas#106). */
|
|
232
|
+
export type ClientChoice = "client" | "view" | "refuse";
|
|
233
|
+
/**
|
|
234
|
+
* queryActionWith's client: today's client with no options; else the client's `withRequest`
|
|
235
|
+
* view, refused when the client has none (a call asked to be bounded never runs unbounded).
|
|
236
|
+
*
|
|
237
|
+
* @ensures exactly the model's ClientFor
|
|
238
|
+
*/
|
|
239
|
+
export declare function clientFor(hasOptions: boolean, hasWithRequest: boolean): ClientChoice;
|
|
224
240
|
/**
|
|
225
241
|
* The scoped cache prefix: the session's siteId and ":".
|
|
226
242
|
*
|