@simpleapps-com/augur-server 2026.11.9 → 2026.11.11

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.
@@ -122,8 +122,11 @@ function verifiedFlag(s) {
122
122
  function recaptchaOk(hasSecret, httpOk, success) {
123
123
  return hasSecret && httpOk && success === true;
124
124
  }
125
- function positiveOrZero(n) {
126
- return n > 0 ? n : 0;
125
+ function cartLookupRuns(hasLookup, hasUserId, customerId) {
126
+ return hasLookup && hasUserId && customerId !== null;
127
+ }
128
+ function customerRefusalOf(customerId, refusal) {
129
+ return customerId === null ? refusal : null;
127
130
  }
128
131
  function itemsLimitOf(limit) {
129
132
  if (limit === void 0) return 24;
@@ -300,7 +303,8 @@ export {
300
303
  recordSuccessOf,
301
304
  verifiedFlag,
302
305
  recaptchaOk,
303
- positiveOrZero,
306
+ cartLookupRuns,
307
+ customerRefusalOf,
304
308
  itemsLimitOf,
305
309
  crossSiteOf,
306
310
  readsSession,
@@ -330,4 +334,4 @@ export {
330
334
  getOrCreateScopedClient,
331
335
  parseMethodPath
332
336
  };
333
- //# sourceMappingURL=chunk-4KPTIVYO.js.map
337
+ //# sourceMappingURL=chunk-5X2QWOTO.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 { AddressId } from \"./address-id\";\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 * Whether the session's cart header is looked up: a lookup to call, the user's id and a usable\n * customer (`customerId`, resolved by augur-utils `resolveAddressId`; null when none is), so no\n * cart is ever looked up for customer 0 (atlas#95).\n *\n * @ensures exactly the model's CartLookupRuns, a customer being customerId ≠ null\n */\nexport function cartLookupRuns(\n hasLookup: boolean,\n hasUserId: boolean,\n customerId: AddressId | null,\n): boolean {\n //@ verify\n //@ ensures \\result === (hasLookup && hasUserId && customerId !== null)\n return hasLookup && hasUserId && customerId !== null;\n}\n\n/**\n * Why a call scoped to one customer is refused: the caller's `refusal` when no usable customer\n * resolved (`customerId` null), else null and the call is asked (atlas#95). Pricing (a price, a\n * tax estimate, a whole batch, refused once before any item) and the customers actions use it,\n * so none is ever asked for customer 0.\n *\n * @ensures exactly the model's CustomerRefusal\n */\nexport function customerRefusalOf(customerId: AddressId | null, refusal: string): string | null {\n //@ verify\n //@ ensures \\result === (customerId === null ? refusal : null)\n return customerId === null ? refusal : null;\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":";;;;;;AA4BO,SAAS,QAAQ,GAAoB;AAK1C,SAAO;AACT;AAOO,SAAS,QAAQ,GAAoB;AAK1C,SAAQ,IAAI;AACd;AAOO,SAAS,MAAM,GAAoB;AAKxC,SAAQ,IAAI;AACd;AAoBO,SAAS,OAAO,GAAmB;AAKxC,SAAO;AACT;AAOO,SAAS,SAAS,GAAoB;AAI3C,SAAQ,IAAI;AACd;AAqBO,SAAS,UAAU,GAAW,GAAmB;AAItD,SAAQ,IAAI;AACd;;;AC3GO,SAAS,aAAa,GAAW,GAAW,GAAoB;AAKrE,WAAS,IAAI,GAAG,MAAM,EAAE,SAAS,GAAG,KAAK;AAIvC,QAAI,aAAa,GAAG,GAAG,CAAC,EAAG,QAAO;AAAA,EACpC;AACA,SAAO;AACT;;;ACZO,SAAS,iBAAiB,UAAiC;AAKhE,QAAM,IAAI,YAAY,UAAU,KAAK,CAAC;AACtC,MAAI,IAAI,EAAG,QAAO;AAClB,MAAI,IAAI,KAAK,SAAS,OAAQ,QAAO;AACrC,SAAO,SAAS,MAAM,IAAI,CAAC;AAC7B;AAYO,SAAS,kBACd,UACA,cACA,OACA,cACM;AAIN,MAAI,CAAC,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AGO,SAAS,sBAAsB,SAA8B;AAClE,yBAAuB;AACvB,IAAE,yBAAyB;AAC7B;AAQO,SAAS,2BAA2B,SAAmC;AAC5E,8BAA4B;AAC5B,IAAE,+BAA+B;AACnC;AAGO,SAAS,wBAAmD;AACjE,SAAO,EAAE,gCAAgC,6BAA6B;AACxE;AA6FO,SAAS,wBAAwB,aAA0C;AAChF,QAAM,EAAE,QAAQ,MAAM,IAAI;AAC1B,QAAM,MAAM,gBAAgB,QAAQ,KAAK;AACzC,QAAM,UAAU,EAAE,0BAA0B;AAC5C,QAAM,WAAW,eAAe,eAAe,OAAO,IAAI,KAAK,CAAC,CAAC,OAAO;AACxE,MAAI,aAAa,MAAO,QAAO,cAAe;AAC9C,MAAI,aAAa,YAAa,QAAO;AAErC,QAAM,SAAS,QAAS,QAAQ,KAAK;AACrC,kBAAgB,EAAE,KAAK,OAAO;AAC9B,SAAO;AACT;AAgDO,SAAS,gBAAgB,WAA+C;AAC7E,MAAI,OAAO,cAAc,SAAU,QAAO;AAC1C,QAAM,UAAU,EAAE,gCAAgC;AAClD,QAAM,SAAS,YAAY,QAAQ,QAAQ,IAAI,SAAS;AACxD,MAAI,CAAC,YAAY,WAAW,YAAY,MAAM,MAAM,EAAG,QAAO;AAC9D,SAAO;AACT;","names":[]}
@@ -1,10 +1,12 @@
1
1
  import {
2
+ cartLookupRuns,
2
3
  getCrossSite,
3
4
  signInTarget,
4
5
  verifiedFlag
5
- } from "./chunk-4KPTIVYO.js";
6
+ } from "./chunk-5X2QWOTO.js";
6
7
 
7
8
  // src/auth.ts
9
+ import { addressIdOf, resolveAddressId } from "@simpleapps-com/augur-utils";
8
10
  import Credentials from "next-auth/providers/credentials";
9
11
  function buildInternalCallbacks(augurClient) {
10
12
  return {
@@ -23,14 +25,16 @@ function buildInternalCallbacks(augurClient) {
23
25
  username: data["username"],
24
26
  email: data["email"],
25
27
  isVerified: true,
26
- customerId: data["customerId"],
28
+ // Joomla holds it as text; "" and "0" are no customer, so none reaches the session (atlas#95).
29
+ customerId: addressIdOf(data["customerId"]) ?? void 0,
27
30
  contactId: data["contactId"]
28
31
  };
29
32
  },
30
33
  async cartHdrLookup(userId, _token, contactId, customerId) {
31
34
  const result = await augurClient.commerce.cartHdr.lookup.get({
32
35
  userId: Number(userId) || 0,
33
- customerId: Number(customerId) || 0,
36
+ // Always a usable id: lookupCartHdr looks up no cart without one (atlas#95).
37
+ customerId,
34
38
  contactId: Number(contactId) || 0
35
39
  });
36
40
  return result.data || null;
@@ -55,12 +59,16 @@ function resolveCallbacks(options) {
55
59
  };
56
60
  }
57
61
  async function lookupCartHdr(siteCallbacks, profile, defaultCustomerId, defaultContactId) {
58
- if (!siteCallbacks.cartHdrLookup || !profile.id) return void 0;
59
- const cartHdr = await siteCallbacks.cartHdrLookup(
62
+ const customerId = resolveAddressId(profile.customerId, defaultCustomerId);
63
+ const lookup = siteCallbacks.cartHdrLookup;
64
+ if (!cartLookupRuns(lookup !== void 0, !!profile.id, customerId)) {
65
+ return void 0;
66
+ }
67
+ const cartHdr = await lookup(
60
68
  profile.id,
61
69
  "",
62
70
  profile.contactId ?? defaultContactId ?? "",
63
- profile.customerId ?? defaultCustomerId ?? ""
71
+ customerId
64
72
  );
65
73
  return cartHdr?.cartHdrUid;
66
74
  }
@@ -135,7 +143,8 @@ function createAuthConfig(options) {
135
143
  return buildSession({
136
144
  name: userProfile.name ?? session.user?.name,
137
145
  email: userProfile.email ?? session.user?.email,
138
- customerId: userProfile.customerId ?? defaultCustomerId,
146
+ // Never "" or "0": the profile's usable id, else the default's, else none (atlas#95).
147
+ customerId: resolveAddressId(userProfile.customerId, defaultCustomerId) ?? void 0,
139
148
  contactId: userProfile.contactId,
140
149
  cartHdrUid
141
150
  });
@@ -171,4 +180,4 @@ function createAuthConfig(options) {
171
180
  export {
172
181
  createAuthConfig
173
182
  };
174
- //# sourceMappingURL=chunk-AUIC4HS2.js.map
183
+ //# sourceMappingURL=chunk-AEFUT3MB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth.ts"],"sourcesContent":["// @simpleapps-com/augur-server/auth\n// NextAuth 5 configuration factory for Augur ecommerce sites.\n\nimport type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport { addressIdOf, resolveAddressId } from \"@simpleapps-com/augur-utils\";\nimport type { NextAuthConfig } from \"next-auth\";\nimport Credentials from \"next-auth/providers/credentials\";\nimport type { AddressId } from \"./address-id\";\nimport { cartLookupRuns, signInTarget, verifiedFlag } from \"./rules\";\nimport { getCrossSite } from \"./sdk-client-store\";\n\n/** Base user fields shared across all Augur sites. */\nexport interface AugurUser {\n id: string;\n username: string;\n isVerified: boolean;\n name?: string;\n email?: string;\n customerId?: string | number;\n contactId?: string | number;\n cartHdrUid?: number;\n token?: string;\n /** Target site ID for cross-site auth sessions (augur_info + body siteId). */\n targetSiteId?: string;\n}\n\n/** Session shape returned by all Augur sites. */\nexport interface AugurSession {\n user: AugurUser;\n token?: string;\n targetSiteId?: string;\n expires: string;\n}\n\n/** JWT token shape used by Augur auth. */\nexport interface AugurJWT {\n id: string;\n username: string;\n isVerified: boolean;\n token?: string;\n targetSiteId?: string;\n}\n\n/** Site-specific callbacks the consumer can provide. */\nexport interface AugurAuthCallbacks {\n /** Fetch user profile from the Augur API given the user's Joomla ID. */\n getUserProfile: (userId: string) => Promise<AugurUser | null>;\n /**\n * Look up or create a cart header for the authenticated user. `customerId` is always a usable\n * P21 customer id (resolved by augur-utils `resolveAddressId`): without one no lookup is made\n * (atlas#95).\n */\n cartHdrLookup?: (\n userId: string | number,\n token: string,\n contactId: string | number,\n customerId: number,\n ) => Promise<{ cartHdrUid?: number } | null>;\n}\n\n/** Derived from augur-api SDK — keeps types in sync automatically. */\nexport type AugurAuthClient = Pick<AugurAPI, \"joomla\" | \"commerce\">;\n\nexport interface CreateAuthConfigOptions {\n /** Augur SDK client. When provided, auth SDK calls are handled internally. */\n augurClient?: AugurAuthClient;\n /** Site-specific callbacks. Override internal SDK calls when custom behavior is needed. */\n callbacks?: Partial<AugurAuthCallbacks>;\n /** NextAuth secret (defaults to AUTH_SECRET env var). */\n secret?: string;\n /** Session max age in seconds (defaults to 4 hours). */\n maxAge?: number;\n /** Default customer ID when profile doesn't provide one. */\n defaultCustomerId?: string | number;\n /** Default contact ID for cart header lookups. */\n defaultContactId?: string | number;\n /** Enable NextAuth debug logging (defaults to NODE_ENV === \"development\"). */\n debug?: boolean;\n}\n\n/** Build internal callbacks that call the Augur SDK directly. */\nfunction buildInternalCallbacks(augurClient: AugurAuthClient): AugurAuthCallbacks {\n return {\n async getUserProfile(userId: string): Promise<AugurUser | null> {\n if (!userId) return null;\n const uid = parseInt(userId, 10);\n if (isNaN(uid)) return null;\n const result = await augurClient.joomla.users.doc.get(uid, {\n edgeCache: 1,\n });\n const data = result.data as Record<string, unknown>;\n if (!data) return null;\n return {\n id: String(data[\"id\"]),\n name: data[\"name\"] as string | undefined,\n username: data[\"username\"] as string,\n email: data[\"email\"] as string | undefined,\n isVerified: true,\n // Joomla holds it as text; \"\" and \"0\" are no customer, so none reaches the session (atlas#95).\n customerId: addressIdOf(data[\"customerId\"] as string | number | undefined) ?? undefined,\n contactId: data[\"contactId\"] as string | number | undefined,\n };\n },\n async cartHdrLookup(\n userId: string | number,\n _token: string,\n contactId: string | number,\n customerId: number,\n ): Promise<{ cartHdrUid?: number } | null> {\n const result = await augurClient.commerce.cartHdr.lookup.get({\n userId: Number(userId) || 0,\n // Always a usable id: lookupCartHdr looks up no cart without one (atlas#95).\n customerId,\n contactId: Number(contactId) || 0,\n });\n // The SDK returns `false` when no cart header exists.\n return result.data || null;\n },\n };\n}\n\n/** Resolve final callbacks: callback overrides take priority over internal SDK calls. */\nfunction resolveCallbacks(options: CreateAuthConfigOptions): AugurAuthCallbacks {\n const { augurClient, callbacks } = options;\n\n if (augurClient) {\n const internal = buildInternalCallbacks(augurClient);\n return {\n getUserProfile: callbacks?.getUserProfile ?? internal.getUserProfile,\n cartHdrLookup: callbacks?.cartHdrLookup ?? internal.cartHdrLookup,\n };\n }\n\n if (!callbacks?.getUserProfile) {\n throw new Error(\"createAuthConfig requires either `augurClient` or `callbacks.getUserProfile`\");\n }\n\n return {\n getUserProfile: callbacks.getUserProfile,\n cartHdrLookup: callbacks.cartHdrLookup,\n };\n}\n\n/**\n * Create a NextAuth 5 configuration for an Augur ecommerce site.\n *\n * Accepts either an `augurClient` (recommended) for zero-boilerplate auth,\n * or explicit `callbacks` for custom behavior. Callback overrides take\n * priority when both are provided.\n *\n * For cross-site auth (augur-support pattern): use an augur_info API client,\n * opt in with `createServerSite(client, { auth: { crossSite: true } })`, and\n * pass `siteId` in the signIn credentials. The API uses augur_info as the\n * header siteId and the body siteId as the target. The session stores the\n * targetSiteId and user-scoped token for later API calls. Without the opt-in\n * the `siteId` is ignored and queryAction never reads the session (atlas#105).\n *\n * @example\n * ```ts\n * // Single-site (recommended)\n * export const { handlers, signIn, signOut, auth } = NextAuth(\n * createAuthConfig({ augurClient }),\n * );\n * ```\n *\n * @example\n * ```ts\n * // Cross-site: site passes siteId in signIn credentials\n * await signIn(\"credentials\", { id, username, isVerified: \"true\", token, siteId: targetSiteId });\n * ```\n */\nasync function lookupCartHdr(\n siteCallbacks: AugurAuthCallbacks,\n profile: AugurUser,\n defaultCustomerId?: string | number,\n defaultContactId?: string | number,\n): Promise<number | undefined> {\n // The profile's customer when usable, else the default. With neither there is no cart to look\n // up: never one for customer 0 (atlas#95; commerce's cartHdrLookup refuses the same case).\n const customerId = resolveAddressId(profile.customerId, defaultCustomerId);\n const lookup = siteCallbacks.cartHdrLookup;\n if (!cartLookupRuns(lookup !== undefined, !!profile.id, customerId)) {\n return undefined;\n }\n // Both set: cartLookupRuns refused the lookup above without either.\n const cartHdr = await (lookup as NonNullable<typeof lookup>)(\n profile.id,\n \"\",\n profile.contactId ?? defaultContactId ?? \"\",\n customerId as AddressId,\n );\n return cartHdr?.cartHdrUid;\n}\n\n/** The user fields the JWT carries, each defaulted when absent (\"\", \"\", false). */\nfunction baseUserOf(token: Record<string, unknown>): {\n id: string;\n username: string;\n isVerified: boolean;\n} {\n return {\n id: (token[\"id\"] as string) || \"\",\n username: (token[\"username\"] as string) || \"\",\n isVerified: (token[\"isVerified\"] as boolean) || false,\n };\n}\n\n/** Creates a NextAuth configuration with Joomla credential provider, session callbacks, and automatic cart initialization. */\nexport function createAuthConfig(options: CreateAuthConfigOptions): NextAuthConfig {\n const {\n secret = process.env[\"AUTH_SECRET\"],\n maxAge = 4 * 60 * 60,\n defaultCustomerId,\n defaultContactId,\n debug = process.env[\"NODE_ENV\"] === \"development\",\n } = options;\n\n const siteCallbacks = resolveCallbacks(options);\n\n return {\n providers: [\n Credentials({\n name: \"Credentials\",\n credentials: {\n username: { label: \"Username\", type: \"text\" },\n password: { label: \"Password\", type: \"password\" },\n id: { label: \"ID\", type: \"text\" },\n isVerified: { label: \"Is Verified\", type: \"text\" },\n token: { label: \"Token\", type: \"text\" },\n siteId: { label: \"Site ID\", type: \"text\" },\n },\n async authorize(credentials) {\n if (!credentials) return null;\n\n const { id, isVerified, username, token, siteId } = credentials as {\n id: string;\n isVerified: string;\n username: string;\n token: string;\n siteId?: string;\n };\n\n return {\n id,\n isVerified: verifiedFlag(isVerified),\n username,\n token,\n // Kept only on a site that opted in (createServerSite's auth.crossSite), read from\n // the same store queryAction reads, at sign-in time (rules.signInTarget, atlas#105).\n targetSiteId: signInTarget(getCrossSite(), siteId),\n };\n },\n }),\n ],\n callbacks: {\n async signIn() {\n return true;\n },\n async redirect({ baseUrl }) {\n return baseUrl;\n },\n async session({ session, token }) {\n const baseUser = baseUserOf(token);\n\n const targetSiteId = token[\"targetSiteId\"] as string | undefined;\n\n const buildSession = (userOverrides = {}) => ({\n ...session,\n user: { ...session.user, ...baseUser, ...userOverrides, targetSiteId },\n token: token[\"token\"] as string | undefined,\n targetSiteId,\n });\n\n try {\n const userProfile = await siteCallbacks.getUserProfile(baseUser.id);\n if (!userProfile) return buildSession();\n\n const cartHdrUid = await lookupCartHdr(\n siteCallbacks,\n userProfile,\n defaultCustomerId,\n defaultContactId,\n );\n\n return buildSession({\n name: userProfile.name ?? session.user?.name,\n email: userProfile.email ?? session.user?.email,\n // Never \"\" or \"0\": the profile's usable id, else the default's, else none (atlas#95).\n customerId: resolveAddressId(userProfile.customerId, defaultCustomerId) ?? undefined,\n contactId: userProfile.contactId,\n cartHdrUid,\n });\n } catch {\n return buildSession();\n }\n },\n async jwt({ token, user }) {\n if (user) {\n const typedUser = user as {\n id: string;\n isVerified: boolean;\n username: string;\n token?: string;\n targetSiteId?: string;\n };\n\n return {\n ...token,\n id: typedUser.id,\n isVerified: typedUser.isVerified,\n username: typedUser.username,\n token: typedUser.token,\n targetSiteId: typedUser.targetSiteId,\n };\n }\n return token;\n },\n },\n secret,\n debug,\n session: {\n strategy: \"jwt\",\n maxAge,\n },\n trustHost: true,\n };\n}\n"],"mappings":";;;;;;;;AAIA,SAAS,aAAa,wBAAwB;AAE9C,OAAO,iBAAiB;AA2ExB,SAAS,uBAAuB,aAAkD;AAChF,SAAO;AAAA,IACL,MAAM,eAAe,QAA2C;AAC9D,UAAI,CAAC,OAAQ,QAAO;AACpB,YAAM,MAAM,SAAS,QAAQ,EAAE;AAC/B,UAAI,MAAM,GAAG,EAAG,QAAO;AACvB,YAAM,SAAS,MAAM,YAAY,OAAO,MAAM,IAAI,IAAI,KAAK;AAAA,QACzD,WAAW;AAAA,MACb,CAAC;AACD,YAAM,OAAO,OAAO;AACpB,UAAI,CAAC,KAAM,QAAO;AAClB,aAAO;AAAA,QACL,IAAI,OAAO,KAAK,IAAI,CAAC;AAAA,QACrB,MAAM,KAAK,MAAM;AAAA,QACjB,UAAU,KAAK,UAAU;AAAA,QACzB,OAAO,KAAK,OAAO;AAAA,QACnB,YAAY;AAAA;AAAA,QAEZ,YAAY,YAAY,KAAK,YAAY,CAAgC,KAAK;AAAA,QAC9E,WAAW,KAAK,WAAW;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,MAAM,cACJ,QACA,QAC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F;AAEA,YAAI;AACF,gBAAM,cAAc,MAAM,cAAc,eAAe,SAAS,EAAE;AAClE,cAAI,CAAC,YAAa,QAAO,aAAa;AAEtC,gBAAM,aAAa,MAAM;AAAA,YACvB;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAEA,iBAAO,aAAa;AAAA,YAClB,MAAM,YAAY,QAAQ,QAAQ,MAAM;AAAA,YACxC,OAAO,YAAY,SAAS,QAAQ,MAAM;AAAA;AAAA,YAE1C,YAAY,iBAAiB,YAAY,YAAY,iBAAiB,KAAK;AAAA,YAC3E,WAAW,YAAY;AAAA,YACvB;AAAA,UACF,CAAC;AAAA,QACH,QAAQ;AACN,iBAAO,aAAa;AAAA,QACtB;AAAA,MACF;AAAA,MACA,MAAM,IAAI,EAAE,OAAO,KAAK,GAAG;AACzB,YAAI,MAAM;AACR,gBAAM,YAAY;AAQlB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,IAAI,UAAU;AAAA,YACd,YAAY,UAAU;AAAA,YACtB,UAAU,UAAU;AAAA,YACpB,OAAO,UAAU;AAAA,YACjB,cAAc,UAAU;AAAA,UAC1B;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF;AAAA,IACA,WAAW;AAAA,EACb;AACF;","names":[]}
@@ -14,7 +14,7 @@ import {
14
14
  scopedPrefix,
15
15
  sessionCookieName,
16
16
  usesCache
17
- } from "./chunk-4KPTIVYO.js";
17
+ } from "./chunk-5X2QWOTO.js";
18
18
 
19
19
  // src/query-action.ts
20
20
  import {
@@ -187,4 +187,4 @@ export {
187
187
  queryActionRawWith,
188
188
  resetSessionImports
189
189
  };
190
- //# sourceMappingURL=chunk-G5P4IDK7.js.map
190
+ //# sourceMappingURL=chunk-OTZUEADV.js.map
package/dist/hooks.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import {
3
3
  queryAction
4
- } from "./chunk-G5P4IDK7.js";
5
- import "./chunk-4KPTIVYO.js";
4
+ } from "./chunk-OTZUEADV.js";
5
+ import "./chunk-5X2QWOTO.js";
6
6
  import "./chunk-BG4G5QUQ.js";
7
7
 
8
8
  // src/hooks.ts
package/dist/index.js CHANGED
@@ -21,11 +21,11 @@ import {
21
21
  unwrap,
22
22
  unwrapOr,
23
23
  withServerCache
24
- } from "./chunk-AYHUM7SG.js";
24
+ } from "./chunk-4CU4UNBH.js";
25
25
  import "./chunk-JIYVQWXK.js";
26
26
  import {
27
27
  recaptchaOk
28
- } from "./chunk-4KPTIVYO.js";
28
+ } from "./chunk-5X2QWOTO.js";
29
29
  import "./chunk-BG4G5QUQ.js";
30
30
 
31
31
  // src/server-query-client.ts
@@ -8,8 +8,8 @@ import {
8
8
  resetSessionImports,
9
9
  resolveMethod,
10
10
  unwrapBaseResponse
11
- } from "./chunk-G5P4IDK7.js";
12
- import "./chunk-4KPTIVYO.js";
11
+ } from "./chunk-OTZUEADV.js";
12
+ import "./chunk-5X2QWOTO.js";
13
13
  import "./chunk-BG4G5QUQ.js";
14
14
  export {
15
15
  getSessionCredentials,
package/dist/rules.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { AddressId } from "./address-id";
1
2
  import type { Millis, Seconds } from "./duration";
2
3
  /**
3
4
  * The siteId of a bearer's client_id claim (`<n>|<siteId>`): the text after the first "|", when
@@ -155,11 +156,22 @@ export declare function verifiedFlag(s: string): boolean;
155
156
  */
156
157
  export declare function recaptchaOk(hasSecret: boolean, httpOk: boolean, success: boolean | undefined): boolean;
157
158
  /**
158
- * A customer id is used only above 0; anything else (NaN included, at the caller) is 0.
159
+ * Whether the session's cart header is looked up: a lookup to call, the user's id and a usable
160
+ * customer (`customerId`, resolved by augur-utils `resolveAddressId`; null when none is), so no
161
+ * cart is ever looked up for customer 0 (atlas#95).
159
162
  *
160
- * @ensures result = n when n > 0, else 0
163
+ * @ensures exactly the model's CartLookupRuns, a customer being customerId ≠ null
161
164
  */
162
- export declare function positiveOrZero(n: number): number;
165
+ export declare function cartLookupRuns(hasLookup: boolean, hasUserId: boolean, customerId: AddressId | null): boolean;
166
+ /**
167
+ * Why a call scoped to one customer is refused: the caller's `refusal` when no usable customer
168
+ * resolved (`customerId` null), else null and the call is asked (atlas#95). Pricing (a price, a
169
+ * tax estimate, a whole batch, refused once before any item) and the customers actions use it,
170
+ * so none is ever asked for customer 0.
171
+ *
172
+ * @ensures exactly the model's CustomerRefusal
173
+ */
174
+ export declare function customerRefusalOf(customerId: AddressId | null, refusal: string): string | null;
163
175
  /**
164
176
  * The category page size: 24 when none (or 0) is given.
165
177
  *
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAMlD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAShE;AAED,kEAAkE;AAClE,MAAM,MAAM,IAAI,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAE3F;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,GACnB,IAAI,CAQN;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,MAAM,GAChB,OAAO,CAMT;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EA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E,OAAO,GAAG,OAAO,CAIjD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAIlE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMxD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAIhE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAIlE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMvE"}
package/dist/site.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  createAuthConfig
3
- } from "./chunk-AUIC4HS2.js";
3
+ } from "./chunk-AEFUT3MB.js";
4
4
  import {
5
5
  createSiteActions,
6
6
  registerSiteActions,
7
7
  serverTtlOf,
8
8
  withRawSdkCache
9
- } from "./chunk-AYHUM7SG.js";
9
+ } from "./chunk-4CU4UNBH.js";
10
10
  import "./chunk-JIYVQWXK.js";
11
11
  import {
12
12
  crossSiteOf,
@@ -16,7 +16,7 @@ import {
16
16
  registerScopedCacheWrapper,
17
17
  registerSdkCallWrapper,
18
18
  registerSdkClient
19
- } from "./chunk-4KPTIVYO.js";
19
+ } from "./chunk-5X2QWOTO.js";
20
20
  import "./chunk-BG4G5QUQ.js";
21
21
 
22
22
  // src/server-site.ts
package/dist/testing.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  clearSiteActions
3
- } from "./chunk-AYHUM7SG.js";
3
+ } from "./chunk-4CU4UNBH.js";
4
4
  import "./chunk-JIYVQWXK.js";
5
- import "./chunk-4KPTIVYO.js";
5
+ import "./chunk-5X2QWOTO.js";
6
6
  import "./chunk-BG4G5QUQ.js";
7
7
 
8
8
  // src/testing.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleapps-com/augur-server",
3
- "version": "2026.11.9",
3
+ "version": "2026.11.11",
4
4
  "description": "Server-side utilities for Augur ecommerce sites (Redis caching, SDK helpers, auth)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -63,17 +63,17 @@
63
63
  ],
64
64
  "dependencies": {
65
65
  "@simpleapps-com/augur-core": "^2026.11.5",
66
- "@simpleapps-com/augur-hooks": "^2026.11.6",
67
- "@simpleapps-com/augur-utils": "^2026.11.4"
66
+ "@simpleapps-com/augur-hooks": "^2026.11.8",
67
+ "@simpleapps-com/augur-utils": "^2026.11.5"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@simpleapps-com/augur-api": "^2026.11.4",
71
71
  "@tanstack/react-query": "^5.80.0",
72
72
  "ioredis": "^5.9.0",
73
73
  "jose": "^5.0.0 || ^6.0.0",
74
- "next": "^16.1.6",
74
+ "next": "^16.4.5",
75
75
  "next-auth": ">=5.0.0-beta.30",
76
- "react": "^19.0.0"
76
+ "react": "^19.3.1"
77
77
  },
78
78
  "peerDependenciesMeta": {
79
79
  "ioredis": {
@@ -95,17 +95,17 @@
95
95
  "ioredis": "^5.9.0",
96
96
  "jose": "^5.0.0",
97
97
  "lemmascript": "0.6.5",
98
- "react": "^19.0.0",
98
+ "react": "^19.3.1",
99
99
  "tsup": "^9.0.0",
100
100
  "typescript": "~6.0.3",
101
101
  "vitest": "~5.0.3",
102
102
  "@atlas/eslint-config": "0.0.0",
103
103
  "@atlas/tsconfig": "0.0.0",
104
- "@atlas/tsup-config": "0.0.0",
105
104
  "@atlas/foundation": "0.0.0",
106
105
  "@atlas/utils": "0.0.0",
106
+ "@atlas/tsup-config": "0.0.0",
107
107
  "@atlas/vitest-config": "0.0.0",
108
- "@simpleapps-com/augur-api": "2026.11.5"
108
+ "@simpleapps-com/augur-api": "2026.11.7"
109
109
  },
110
110
  "engines": {
111
111
  "node": ">=22.0.0"