@simpleapps-com/augur-server 2026.11.1 → 2026.11.3
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 +1 -1
- package/README.md +5 -0
- package/dist/actions/agr-info.d.ts +3 -2
- package/dist/actions/agr-info.d.ts.map +1 -1
- package/dist/actions/agr-site.d.ts +2 -1
- package/dist/actions/agr-site.d.ts.map +1 -1
- package/dist/actions/basecamp2.d.ts +3 -2
- package/dist/actions/basecamp2.d.ts.map +1 -1
- package/dist/actions/brand-folder.d.ts +2 -1
- package/dist/actions/brand-folder.d.ts.map +1 -1
- package/dist/actions/customers.d.ts +2 -1
- package/dist/actions/customers.d.ts.map +1 -1
- package/dist/actions/favorites.d.ts +2 -1
- package/dist/actions/favorites.d.ts.map +1 -1
- package/dist/actions/gregorovich.d.ts +2 -1
- package/dist/actions/gregorovich.d.ts.map +1 -1
- package/dist/actions/items.d.ts +3 -2
- package/dist/actions/items.d.ts.map +1 -1
- package/dist/actions/joomla.d.ts +2 -1
- package/dist/actions/joomla.d.ts.map +1 -1
- package/dist/actions/legacy.d.ts +3 -2
- package/dist/actions/legacy.d.ts.map +1 -1
- package/dist/actions/logistics.d.ts +3 -2
- package/dist/actions/logistics.d.ts.map +1 -1
- package/dist/actions/orders.d.ts +2 -1
- package/dist/actions/orders.d.ts.map +1 -1
- package/dist/actions/p21-apis.d.ts +2 -1
- package/dist/actions/p21-apis.d.ts.map +1 -1
- package/dist/actions/p21-core.d.ts +3 -2
- package/dist/actions/p21-core.d.ts.map +1 -1
- package/dist/actions/p21-pim.d.ts +2 -1
- package/dist/actions/p21-pim.d.ts.map +1 -1
- package/dist/actions/p21-sism.d.ts +2 -1
- package/dist/actions/p21-sism.d.ts.map +1 -1
- package/dist/actions/pricing.d.ts +3 -2
- package/dist/actions/pricing.d.ts.map +1 -1
- package/dist/actions/search.d.ts +2 -1
- package/dist/actions/search.d.ts.map +1 -1
- package/dist/actions/shipping.d.ts +2 -1
- package/dist/actions/shipping.d.ts.map +1 -1
- package/dist/actions/site.d.ts +6 -5
- package/dist/actions/site.d.ts.map +1 -1
- package/dist/actions/vmi.d.ts +3 -2
- package/dist/actions/vmi.d.ts.map +1 -1
- package/dist/actions/wishlists.d.ts +2 -1
- package/dist/actions/wishlists.d.ts.map +1 -1
- package/dist/api.js +2 -3
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +2 -2
- package/dist/cache/redis-client.d.ts +4 -2
- package/dist/cache/redis-client.d.ts.map +1 -1
- package/dist/cache/with-cache.d.ts +9 -10
- package/dist/cache/with-cache.d.ts.map +1 -1
- package/dist/{chunk-SXXWBSTX.js → chunk-22B3WOGA.js} +7 -3
- package/dist/chunk-22B3WOGA.js.map +1 -0
- package/dist/{chunk-PFYEMJTQ.js → chunk-5I7TBMGU.js} +80 -46
- package/dist/chunk-5I7TBMGU.js.map +1 -0
- package/dist/{chunk-U2BKHRJC.js → chunk-6CSVIBHQ.js} +6 -6
- package/dist/chunk-6CSVIBHQ.js.map +1 -0
- package/dist/{chunk-FWO6Q43T.js → chunk-R573MZQL.js} +7 -7
- package/dist/chunk-R573MZQL.js.map +1 -0
- package/dist/{chunk-TVH5EONP.js → chunk-RGOLZMU3.js} +157 -12
- package/dist/chunk-RGOLZMU3.js.map +1 -0
- package/dist/duration.d.ts +16 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/hooks.js +2 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/query-action.d.ts +3 -0
- package/dist/query-action.d.ts.map +1 -1
- package/dist/query-action.js +2 -3
- package/dist/query-options-helper.d.ts +7 -6
- package/dist/query-options-helper.d.ts.map +1 -1
- package/dist/query.js +1 -1
- package/dist/rules.d.ts +39 -8
- package/dist/rules.d.ts.map +1 -1
- package/dist/sdk-client-store.d.ts +8 -0
- package/dist/sdk-client-store.d.ts.map +1 -1
- package/dist/server-site-registry.d.ts.map +1 -1
- package/dist/server-site.d.ts +8 -0
- package/dist/server-site.d.ts.map +1 -1
- package/dist/site.js +19 -14
- package/dist/site.js.map +1 -1
- package/dist/testing.js +2 -3
- package/dist/testing.js.map +1 -1
- package/llms.txt +1 -1
- package/package.json +7 -6
- package/dist/chunk-FWO6Q43T.js.map +0 -1
- package/dist/chunk-NTUPTNOI.js +0 -103
- package/dist/chunk-NTUPTNOI.js.map +0 -1
- package/dist/chunk-PFYEMJTQ.js.map +0 -1
- package/dist/chunk-SXXWBSTX.js.map +0 -1
- package/dist/chunk-TVH5EONP.js.map +0 -1
- package/dist/chunk-U2BKHRJC.js.map +0 -1
package/dist/chunk-NTUPTNOI.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
approvePath,
|
|
3
|
-
slotDecisionOf
|
|
4
|
-
} from "./chunk-TVH5EONP.js";
|
|
5
|
-
|
|
6
|
-
// src/scoped-client-key.ts
|
|
7
|
-
var SEPARATOR_CODE = 0;
|
|
8
|
-
function hasNoSeparator(siteId) {
|
|
9
|
-
return !siteId.includes(String.fromCharCode(SEPARATOR_CODE));
|
|
10
|
-
}
|
|
11
|
-
function scopedClientKeyOf(siteId, token) {
|
|
12
|
-
if (!hasNoSeparator(siteId)) return null;
|
|
13
|
-
return siteId + String.fromCharCode(SEPARATOR_CODE) + token;
|
|
14
|
-
}
|
|
15
|
-
function scopedClientKey(siteId, token) {
|
|
16
|
-
const key = scopedClientKeyOf(siteId, token);
|
|
17
|
-
if (key === null) {
|
|
18
|
-
throw new TypeError("scopedClientKey: siteId must not contain a NUL character");
|
|
19
|
-
}
|
|
20
|
-
return key;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/sdk-client-store.ts
|
|
24
|
-
var g = globalThis;
|
|
25
|
-
var _cachedClient = null;
|
|
26
|
-
var _cachedWrapper = null;
|
|
27
|
-
var _cachedAuthSecret = null;
|
|
28
|
-
var _cachedClientFactory = null;
|
|
29
|
-
var _cachedScopedCacheWrapper = null;
|
|
30
|
-
var _scopedClient = null;
|
|
31
|
-
var _allowedMethodPaths = null;
|
|
32
|
-
function registerSdkClient(client) {
|
|
33
|
-
_cachedClient = client;
|
|
34
|
-
g.__augur_sdk_client = client;
|
|
35
|
-
}
|
|
36
|
-
function getSdkClientOrNull() {
|
|
37
|
-
const client = g.__augur_sdk_client ?? _cachedClient;
|
|
38
|
-
if (client) {
|
|
39
|
-
if (!g.__augur_sdk_client) {
|
|
40
|
-
g.__augur_sdk_client = client;
|
|
41
|
-
}
|
|
42
|
-
return client;
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
function registerSdkCallWrapper(wrapper) {
|
|
47
|
-
_cachedWrapper = wrapper;
|
|
48
|
-
g.__augur_sdk_call_wrapper = wrapper;
|
|
49
|
-
}
|
|
50
|
-
function getSdkCallWrapper() {
|
|
51
|
-
return g.__augur_sdk_call_wrapper ?? _cachedWrapper ?? null;
|
|
52
|
-
}
|
|
53
|
-
function registerAuthSecret(secret) {
|
|
54
|
-
_cachedAuthSecret = secret;
|
|
55
|
-
g.__augur_auth_secret = secret;
|
|
56
|
-
}
|
|
57
|
-
function getAuthSecret() {
|
|
58
|
-
return g.__augur_auth_secret ?? _cachedAuthSecret ?? null;
|
|
59
|
-
}
|
|
60
|
-
function registerClientFactory(factory) {
|
|
61
|
-
_cachedClientFactory = factory;
|
|
62
|
-
g.__augur_client_factory = factory;
|
|
63
|
-
}
|
|
64
|
-
function registerScopedCacheWrapper(wrapper) {
|
|
65
|
-
_cachedScopedCacheWrapper = wrapper;
|
|
66
|
-
g.__augur_scoped_cache_wrapper = wrapper;
|
|
67
|
-
}
|
|
68
|
-
function getScopedCacheWrapper() {
|
|
69
|
-
return g.__augur_scoped_cache_wrapper ?? _cachedScopedCacheWrapper ?? null;
|
|
70
|
-
}
|
|
71
|
-
function getOrCreateScopedClient(credentials) {
|
|
72
|
-
const { siteId, token } = credentials;
|
|
73
|
-
const key = scopedClientKey(siteId, token);
|
|
74
|
-
const factory = g.__augur_client_factory ?? _cachedClientFactory;
|
|
75
|
-
const decision = slotDecisionOf(_scopedClient?.key ?? "", key, !!factory);
|
|
76
|
-
if (decision === "hit") return _scopedClient.client;
|
|
77
|
-
if (decision === "no-client") return null;
|
|
78
|
-
const client = factory(siteId, token);
|
|
79
|
-
_scopedClient = { key, client };
|
|
80
|
-
return client;
|
|
81
|
-
}
|
|
82
|
-
function parseMethodPath(candidate) {
|
|
83
|
-
if (typeof candidate !== "string") return null;
|
|
84
|
-
const allowed = g.__augur_allowed_method_paths ?? _allowedMethodPaths;
|
|
85
|
-
const listed = allowed !== null && allowed.has(candidate);
|
|
86
|
-
if (!approvePath(candidate, allowed !== null, listed)) return null;
|
|
87
|
-
return candidate;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export {
|
|
91
|
-
registerSdkClient,
|
|
92
|
-
getSdkClientOrNull,
|
|
93
|
-
registerSdkCallWrapper,
|
|
94
|
-
getSdkCallWrapper,
|
|
95
|
-
registerAuthSecret,
|
|
96
|
-
getAuthSecret,
|
|
97
|
-
registerClientFactory,
|
|
98
|
-
registerScopedCacheWrapper,
|
|
99
|
-
getScopedCacheWrapper,
|
|
100
|
-
getOrCreateScopedClient,
|
|
101
|
-
parseMethodPath
|
|
102
|
-
};
|
|
103
|
-
//# sourceMappingURL=chunk-NTUPTNOI.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scoped-client-key.ts","../src/sdk-client-store.ts"],"sourcesContent":["//@ 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_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 _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/** 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 _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_client_factory = undefined;\n g.__aug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