@simpleapps-com/augur-server 2.2.18 → 2.2.20

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/dist/actions.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use server";
2
2
  import {
3
3
  queryAction
4
- } from "./chunk-YHI2PFKJ.js";
4
+ } from "./chunk-OOR3XGUT.js";
5
5
  import {
6
6
  getSiteActions,
7
7
  safeAction
8
- } from "./chunk-3YCNHOMC.js";
9
- import "./chunk-XSM747FM.js";
8
+ } from "./chunk-4OK7EWLJ.js";
9
+ import "./chunk-HPQQYROJ.js";
10
10
  import "./chunk-DGUM43GV.js";
11
11
 
12
12
  // src/server-actions.ts
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  registerSdkCallWrapper,
3
3
  registerSdkClient
4
- } from "./chunk-XSM747FM.js";
4
+ } from "./chunk-HPQQYROJ.js";
5
5
  import {
6
6
  __require
7
7
  } from "./chunk-DGUM43GV.js";
@@ -2738,4 +2738,4 @@ export {
2738
2738
  getSiteActions,
2739
2739
  clearSiteActions2 as clearSiteActions
2740
2740
  };
2741
- //# sourceMappingURL=chunk-3YCNHOMC.js.map
2741
+ //# sourceMappingURL=chunk-4OK7EWLJ.js.map
@@ -0,0 +1,70 @@
1
+ // src/sdk-client-store.ts
2
+ var g = globalThis;
3
+ var _cachedClient = null;
4
+ var _cachedWrapper = null;
5
+ var _cachedAuthSecret = null;
6
+ var _cachedClientFactory = null;
7
+ var _cachedScopedCacheWrapper = null;
8
+ var _scopedClient = null;
9
+ function registerSdkClient(client) {
10
+ _cachedClient = client;
11
+ g.__augur_sdk_client = client;
12
+ }
13
+ function getSdkClientOrNull() {
14
+ const client = g.__augur_sdk_client ?? _cachedClient;
15
+ if (client) {
16
+ if (!g.__augur_sdk_client) {
17
+ g.__augur_sdk_client = client;
18
+ }
19
+ return client;
20
+ }
21
+ return null;
22
+ }
23
+ function registerSdkCallWrapper(wrapper) {
24
+ _cachedWrapper = wrapper;
25
+ g.__augur_sdk_call_wrapper = wrapper;
26
+ }
27
+ function getSdkCallWrapper() {
28
+ return g.__augur_sdk_call_wrapper ?? _cachedWrapper ?? null;
29
+ }
30
+ function registerAuthSecret(secret) {
31
+ _cachedAuthSecret = secret;
32
+ g.__augur_auth_secret = secret;
33
+ }
34
+ function getAuthSecret() {
35
+ return g.__augur_auth_secret ?? _cachedAuthSecret ?? null;
36
+ }
37
+ function registerClientFactory(factory) {
38
+ _cachedClientFactory = factory;
39
+ g.__augur_client_factory = factory;
40
+ }
41
+ function registerScopedCacheWrapper(wrapper) {
42
+ _cachedScopedCacheWrapper = wrapper;
43
+ g.__augur_scoped_cache_wrapper = wrapper;
44
+ }
45
+ function getScopedCacheWrapper() {
46
+ return g.__augur_scoped_cache_wrapper ?? _cachedScopedCacheWrapper ?? null;
47
+ }
48
+ function getOrCreateScopedClient(siteId, bearerToken) {
49
+ const key = `${siteId}\0${bearerToken}`;
50
+ if (_scopedClient?.key === key) return _scopedClient.client;
51
+ const factory = g.__augur_client_factory ?? _cachedClientFactory;
52
+ if (!factory) return null;
53
+ const client = factory(siteId, bearerToken);
54
+ _scopedClient = { key, client };
55
+ return client;
56
+ }
57
+
58
+ export {
59
+ registerSdkClient,
60
+ getSdkClientOrNull,
61
+ registerSdkCallWrapper,
62
+ getSdkCallWrapper,
63
+ registerAuthSecret,
64
+ getAuthSecret,
65
+ registerClientFactory,
66
+ registerScopedCacheWrapper,
67
+ getScopedCacheWrapper,
68
+ getOrCreateScopedClient
69
+ };
70
+ //# sourceMappingURL=chunk-HPQQYROJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sdk-client-store.ts"],"sourcesContent":["/**\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\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\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};\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;\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 (siteId, token) pair so that\n * multiple queryAction calls in the same request reuse the same client.\n */\nexport function getOrCreateScopedClient(siteId: string, bearerToken: string): unknown {\n const key = `${siteId}\\0${bearerToken}`;\n if (_scopedClient?.key === key) return _scopedClient.client;\n\n const factory = g.__augur_client_factory ?? _cachedClientFactory;\n if (!factory) return null;\n\n const client = factory(siteId, bearerToken);\n _scopedClient = { key, client };\n return client;\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 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.__augur_scoped_cache_wrapper = undefined;\n}\n"],"mappings":";AAwCA,IAAM,IAAI;AAQV,IAAI,gBAAyB;AAC7B,IAAI,iBAAwC;AAC5C,IAAI,oBAAmC;AACvC,IAAI,uBAA6C;AACjD,IAAI,4BAAuD;AAC3D,IAAI,gBAAyD;AAGtD,SAAS,kBAAkB,QAAuB;AACvD,kBAAgB;AAChB,IAAE,qBAAqB;AACzB;AAGO,SAAS,qBAA8B;AAC5C,QAAM,SAAS,EAAE,sBAAsB;AACvC,MAAI,QAAQ;AACV,QAAI,CAAC,EAAE,oBAAoB;AACzB,QAAE,qBAAqB;AAAA,IACzB;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAOO,SAAS,uBAAuB,SAA+B;AACpE,mBAAiB;AACjB,IAAE,2BAA2B;AAC/B;AAGO,SAAS,oBAA2C;AACzD,SAAO,EAAE,4BAA4B,kBAAkB;AACzD;AAGO,SAAS,mBAAmB,QAAsB;AACvD,sBAAoB;AACpB,IAAE,sBAAsB;AAC1B;AAGO,SAAS,gBAA+B;AAC7C,SAAO,EAAE,uBAAuB,qBAAqB;AACvD;AAGO,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;AAOO,SAAS,wBAAwB,QAAgB,aAA8B;AACpF,QAAM,MAAM,GAAG,MAAM,KAAK,WAAW;AACrC,MAAI,eAAe,QAAQ,IAAK,QAAO,cAAc;AAErD,QAAM,UAAU,EAAE,0BAA0B;AAC5C,MAAI,CAAC,QAAS,QAAO;AAErB,QAAM,SAAS,QAAQ,QAAQ,WAAW;AAC1C,kBAAgB,EAAE,KAAK,OAAO;AAC9B,SAAO;AACT;","names":[]}
@@ -0,0 +1,135 @@
1
+ import {
2
+ getAuthSecret,
3
+ getOrCreateScopedClient,
4
+ getScopedCacheWrapper,
5
+ getSdkCallWrapper,
6
+ getSdkClientOrNull
7
+ } from "./chunk-HPQQYROJ.js";
8
+
9
+ // src/query-action.ts
10
+ import { isReadMethod } from "@simpleapps-com/augur-core";
11
+ var SECURE_COOKIE = "__Secure-authjs.session-token";
12
+ var PLAIN_COOKIE = "authjs.session-token";
13
+ var _decode;
14
+ var _cookies;
15
+ async function ensureImports() {
16
+ if (_decode === void 0) {
17
+ try {
18
+ const mod = await import("next-auth/jwt");
19
+ _decode = mod.decode;
20
+ } catch {
21
+ _decode = null;
22
+ }
23
+ }
24
+ if (_cookies === void 0) {
25
+ try {
26
+ const mod = await import("next/headers");
27
+ _cookies = mod.cookies;
28
+ } catch {
29
+ _cookies = null;
30
+ }
31
+ }
32
+ return !!_decode && !!_cookies;
33
+ }
34
+ async function decodeSessionJwt(secret) {
35
+ const cookieStore = await _cookies();
36
+ const secureCookie = cookieStore.get(SECURE_COOKIE);
37
+ const plainCookie = secureCookie ? void 0 : cookieStore.get(PLAIN_COOKIE);
38
+ const cookie = secureCookie ?? plainCookie;
39
+ if (!cookie?.value) return null;
40
+ const salt = secureCookie ? SECURE_COOKIE : PLAIN_COOKIE;
41
+ return _decode({ token: cookie.value, secret, salt });
42
+ }
43
+ async function getSessionCredentials() {
44
+ const secret = getAuthSecret();
45
+ if (!secret) return null;
46
+ if (!await ensureImports()) return null;
47
+ try {
48
+ const decoded = await decodeSessionJwt(secret);
49
+ if (!decoded) return null;
50
+ const targetSiteId = decoded["targetSiteId"];
51
+ const token = decoded["token"];
52
+ if (targetSiteId && token) {
53
+ return { siteId: targetSiteId, token };
54
+ }
55
+ } catch {
56
+ }
57
+ return null;
58
+ }
59
+ async function resolveClientAndPrefix() {
60
+ const globalClient = getSdkClientOrNull();
61
+ const creds = await getSessionCredentials();
62
+ if (creds) {
63
+ const scoped = getOrCreateScopedClient(creds.siteId, creds.token);
64
+ if (scoped) {
65
+ return { client: scoped, cachePrefix: `${creds.siteId}:` };
66
+ }
67
+ }
68
+ return { client: globalClient, cachePrefix: null };
69
+ }
70
+ function unwrapBaseResponse(raw) {
71
+ if (raw != null && typeof raw === "object" && "data" in raw && "status" in raw && "message" in raw) {
72
+ return raw.data;
73
+ }
74
+ return raw;
75
+ }
76
+ function resolveMethod(client, methodPath) {
77
+ const segments = methodPath.split(".");
78
+ let current = client;
79
+ for (const segment of segments) {
80
+ if (current == null || typeof current !== "object" && typeof current !== "function") {
81
+ throw new Error(
82
+ `Cannot resolve "${methodPath}": "${segment}" is not accessible on ${typeof current}`
83
+ );
84
+ }
85
+ current = current[segment];
86
+ }
87
+ if (typeof current !== "function") {
88
+ throw new Error(`"${methodPath}" does not resolve to a function (got ${typeof current})`);
89
+ }
90
+ return current;
91
+ }
92
+ async function queryAction(methodPath, ...args) {
93
+ const { client, cachePrefix } = await resolveClientAndPrefix();
94
+ if (!client) {
95
+ throw new Error(
96
+ "SDK client not initialized. Call createServerSite() or set AUGUR_SITE_ID + AUGUR_JWT env vars."
97
+ );
98
+ }
99
+ const resolvedMethod = resolveMethod(client, methodPath);
100
+ const leafName = methodPath.split(".").pop();
101
+ if (cachePrefix !== null) {
102
+ const scopedWrapper = getScopedCacheWrapper();
103
+ if (scopedWrapper && isReadMethod(leafName)) {
104
+ const result3 = await scopedWrapper(
105
+ cachePrefix,
106
+ methodPath,
107
+ () => resolvedMethod(...args),
108
+ ...args
109
+ );
110
+ return unwrapBaseResponse(result3);
111
+ }
112
+ const result2 = await resolvedMethod(...args);
113
+ return unwrapBaseResponse(result2);
114
+ }
115
+ const wrapper = getSdkCallWrapper();
116
+ if (wrapper && isReadMethod(leafName)) {
117
+ const result2 = await wrapper(methodPath, () => resolvedMethod(...args), ...args);
118
+ return unwrapBaseResponse(result2);
119
+ }
120
+ const result = await resolvedMethod(...args);
121
+ return unwrapBaseResponse(result);
122
+ }
123
+ function resetSessionImports() {
124
+ _decode = void 0;
125
+ _cookies = void 0;
126
+ }
127
+
128
+ export {
129
+ getSessionCredentials,
130
+ unwrapBaseResponse,
131
+ resolveMethod,
132
+ queryAction,
133
+ resetSessionImports
134
+ };
135
+ //# sourceMappingURL=chunk-OOR3XGUT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/query-action.ts"],"sourcesContent":["// \"use server\" banner is injected by tsup at build time.\n// Isolated server action for the proxy pattern.\n// This file MUST NOT import from server-actions.ts, server-site-registry.ts,\n// cache/, or any factory. It imports only from lightweight stores with zero\n// deps, plus augur-core (external in tsup — not bundled into chunks).\n// Dynamic imports of next/headers and next-auth/jwt are used for session\n// credential resolution (both are external in tsup).\n\nimport {\n getSdkClientOrNull,\n getSdkCallWrapper,\n getAuthSecret,\n getOrCreateScopedClient,\n getScopedCacheWrapper,\n} from \"./sdk-client-store\";\nimport { isReadMethod } from \"@simpleapps-com/augur-core\";\n\n/** Auth.js v5 session cookie names (HTTPS secure prefix + HTTP fallback). */\nconst SECURE_COOKIE = \"__Secure-authjs.session-token\";\nconst PLAIN_COOKIE = \"authjs.session-token\";\n\n/** Simplified function types for lazy-loaded external deps. */\ntype DecodeFn = (params: {\n token?: string;\n secret: string | string[];\n salt: string;\n}) => Promise<Record<string, unknown> | null>;\ntype CookiesFn = () => Promise<{ get: (name: string) => { value: string } | undefined }>;\n\n/** Cached dynamic imports for next-auth/jwt decode and next/headers cookies. */\nlet _decode: DecodeFn | null | undefined;\nlet _cookies: CookiesFn | null | undefined;\n\n/** Lazy-load decode and cookies functions from external deps. Cached after first call. */\nasync function ensureImports(): Promise<boolean> {\n if (_decode === undefined) {\n try {\n const mod = await import(\"next-auth/jwt\");\n _decode = mod.decode as unknown as DecodeFn;\n /* v8 ignore next 3 -- dynamic import only fails when next-auth is not installed */\n } catch {\n _decode = null;\n }\n }\n if (_cookies === undefined) {\n try {\n const mod = await import(\"next/headers\");\n _cookies = mod.cookies as unknown as CookiesFn;\n /* v8 ignore next 3 -- dynamic import only fails when next is not installed */\n } catch {\n _cookies = null;\n }\n }\n /* v8 ignore next -- _decode/_cookies null branch only when imports fail (untestable with vi.mock) */\n return !!_decode && !!_cookies;\n}\n\n/** Read and decode the Auth.js session JWT from request cookies. */\nasync function decodeSessionJwt(secret: string): Promise<Record<string, unknown> | null> {\n const cookieStore = await _cookies!();\n const secureCookie = cookieStore.get(SECURE_COOKIE);\n const plainCookie = secureCookie ? undefined : cookieStore.get(PLAIN_COOKIE);\n const cookie = secureCookie ?? plainCookie;\n if (!cookie?.value) return null;\n\n const salt = secureCookie ? SECURE_COOKIE : PLAIN_COOKIE;\n return _decode!({ token: cookie.value, secret, salt });\n}\n\n/**\n * Resolve session credentials from the Auth.js JWT cookie.\n * Returns the targetSiteId and token if present, or null.\n * Falls back to null on any error (no cookie, no secret, not in request context).\n */\nasync function getSessionCredentials(): Promise<{ siteId: string; token: string } | null> {\n const secret = getAuthSecret();\n if (!secret) return null;\n /* v8 ignore next -- ensureImports returns false only when dynamic imports fail (untestable with vi.mock) */\n if (!(await ensureImports())) return null;\n\n try {\n const decoded = await decodeSessionJwt(secret);\n if (!decoded) return null;\n\n const targetSiteId = decoded[\"targetSiteId\"] as string | undefined;\n const token = decoded[\"token\"] as string | undefined;\n if (targetSiteId && token) {\n return { siteId: targetSiteId, token };\n }\n } catch {\n // Not in a request context (build time, tests), or decode failed\n }\n\n return null;\n}\n\n/**\n * Resolve the SDK client and cache prefix for this request.\n * If the session has targetSiteId + token, returns a scoped client.\n * Otherwise returns the global client.\n */\nasync function resolveClientAndPrefix(): Promise<{\n client: unknown;\n cachePrefix: string | null;\n}> {\n const globalClient = getSdkClientOrNull();\n\n const creds = await getSessionCredentials();\n if (creds) {\n const scoped = getOrCreateScopedClient(creds.siteId, creds.token);\n if (scoped) {\n return { client: scoped, cachePrefix: `${creds.siteId}:` };\n }\n }\n\n return { client: globalClient, cachePrefix: null };\n}\n\n/**\n * Unwrap SDK BaseResponse if the result matches the standard shape.\n * The SDK wraps all responses in `{ data: T, status: number, message: string }`.\n * SiteActions previously unwrapped this; queryAction now does it automatically\n * so consumers receive `T` directly.\n */\nfunction unwrapBaseResponse(raw: unknown): unknown {\n if (\n raw != null &&\n typeof raw === \"object\" &&\n \"data\" in raw &&\n \"status\" in raw &&\n \"message\" in raw\n ) {\n return (raw as { data: unknown }).data;\n }\n return raw;\n}\n\n/** Resolve a dot-separated method path on an object, returning the leaf function. */\nfunction resolveMethod(client: unknown, methodPath: string): (...a: unknown[]) => Promise<unknown> {\n const segments = methodPath.split(\".\");\n\n let current: unknown = client;\n for (const segment of segments) {\n if (current == null || (typeof current !== \"object\" && typeof current !== \"function\")) {\n throw new Error(\n `Cannot resolve \"${methodPath}\": \"${segment}\" is not accessible on ${typeof current}`,\n );\n }\n current = (current as Record<string, unknown>)[segment];\n }\n\n if (typeof current !== \"function\") {\n throw new Error(`\"${methodPath}\" does not resolve to a function (got ${typeof current})`);\n }\n\n return current as (...a: unknown[]) => Promise<unknown>;\n}\n\n/**\n * Generic server action that routes any SDK method call through the raw\n * SDK client with optional Redis caching. Used internally by\n * `createServerQueryProxy()` to bridge client-side React Query hooks\n * to server-side API calls.\n *\n * For read methods (get, list, lookup, search, suggest), the call is\n * wrapped in the registered cache wrapper (Redis) if one was registered\n * by createServerSite(). Write methods bypass caching.\n *\n * When the request has an active session with targetSiteId + token\n * (from cross-site auth), the call uses a scoped SDK client with those\n * credentials. Redis caching uses targetSiteId as the cache prefix so\n * users managing the same site share cached data.\n *\n * SDK responses wrapped in BaseResponse are automatically unwrapped --\n * consumers receive `T` instead of `{ data: T, status, message }`.\n *\n * @param methodPath Dot-separated SDK method path (e.g. \"items.invMast.doc.get\")\n * @param args Arguments to pass to the resolved method\n * @returns The unwrapped result from the SDK method (possibly from Redis cache)\n */\nexport async function queryAction(methodPath: string, ...args: unknown[]): Promise<unknown> {\n const { client, cachePrefix } = await resolveClientAndPrefix();\n if (!client) {\n throw new Error(\n \"SDK client not initialized. Call createServerSite() or set AUGUR_SITE_ID + AUGUR_JWT env vars.\",\n );\n }\n\n const resolvedMethod = resolveMethod(client, methodPath);\n const leafName = methodPath.split(\".\").pop()!;\n\n // Scoped client — use scoped cache wrapper with targetSiteId prefix\n if (cachePrefix !== null) {\n const scopedWrapper = getScopedCacheWrapper();\n if (scopedWrapper && isReadMethod(leafName)) {\n const result = await scopedWrapper(\n cachePrefix,\n methodPath,\n () => resolvedMethod(...args),\n ...args,\n );\n return unwrapBaseResponse(result);\n }\n const result = await resolvedMethod(...args);\n return unwrapBaseResponse(result);\n }\n\n // Global client — use standard cache wrapper\n const wrapper = getSdkCallWrapper();\n if (wrapper && isReadMethod(leafName)) {\n const result = await wrapper(methodPath, () => resolvedMethod(...args), ...args);\n return unwrapBaseResponse(result);\n }\n\n const result = await resolvedMethod(...args);\n return unwrapBaseResponse(result);\n}\n\n/** Reset lazy-loaded imports. Used in tests only. @internal */\nexport function resetSessionImports(): void {\n _decode = undefined;\n _cookies = undefined;\n}\n\nexport { unwrapBaseResponse, getSessionCredentials, resolveMethod };\n"],"mappings":"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","names":["result"]}
package/dist/hooks.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import {
3
3
  queryAction
4
- } from "./chunk-YHI2PFKJ.js";
5
- import "./chunk-XSM747FM.js";
4
+ } from "./chunk-OOR3XGUT.js";
5
+ import "./chunk-HPQQYROJ.js";
6
6
  import "./chunk-DGUM43GV.js";
7
7
 
8
8
  // src/hooks.ts
package/dist/index.js CHANGED
@@ -21,8 +21,8 @@ import {
21
21
  unwrap,
22
22
  unwrapOr,
23
23
  withServerCache
24
- } from "./chunk-3YCNHOMC.js";
25
- import "./chunk-XSM747FM.js";
24
+ } from "./chunk-4OK7EWLJ.js";
25
+ import "./chunk-HPQQYROJ.js";
26
26
  import "./chunk-DGUM43GV.js";
27
27
 
28
28
  // src/server-query-client.ts
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Resolve session credentials from the Auth.js JWT cookie.
3
+ * Returns the targetSiteId and token if present, or null.
4
+ * Falls back to null on any error (no cookie, no secret, not in request context).
5
+ */
6
+ declare function getSessionCredentials(): Promise<{
7
+ siteId: string;
8
+ token: string;
9
+ } | null>;
1
10
  /**
2
11
  * Unwrap SDK BaseResponse if the result matches the standard shape.
3
12
  * The SDK wraps all responses in `{ data: T, status: number, message: string }`.
@@ -5,6 +14,8 @@
5
14
  * so consumers receive `T` directly.
6
15
  */
7
16
  declare function unwrapBaseResponse(raw: unknown): unknown;
17
+ /** Resolve a dot-separated method path on an object, returning the leaf function. */
18
+ declare function resolveMethod(client: unknown, methodPath: string): (...a: unknown[]) => Promise<unknown>;
8
19
  /**
9
20
  * Generic server action that routes any SDK method call through the raw
10
21
  * SDK client with optional Redis caching. Used internally by
@@ -15,6 +26,11 @@ declare function unwrapBaseResponse(raw: unknown): unknown;
15
26
  * wrapped in the registered cache wrapper (Redis) if one was registered
16
27
  * by createServerSite(). Write methods bypass caching.
17
28
  *
29
+ * When the request has an active session with targetSiteId + token
30
+ * (from cross-site auth), the call uses a scoped SDK client with those
31
+ * credentials. Redis caching uses targetSiteId as the cache prefix so
32
+ * users managing the same site share cached data.
33
+ *
18
34
  * SDK responses wrapped in BaseResponse are automatically unwrapped --
19
35
  * consumers receive `T` instead of `{ data: T, status, message }`.
20
36
  *
@@ -23,5 +39,7 @@ declare function unwrapBaseResponse(raw: unknown): unknown;
23
39
  * @returns The unwrapped result from the SDK method (possibly from Redis cache)
24
40
  */
25
41
  declare function queryAction(methodPath: string, ...args: unknown[]): Promise<unknown>;
42
+ /** Reset lazy-loaded imports. Used in tests only. @internal */
43
+ declare function resetSessionImports(): void;
26
44
 
27
- export { queryAction, unwrapBaseResponse };
45
+ export { getSessionCredentials, queryAction, resetSessionImports, resolveMethod, unwrapBaseResponse };
@@ -1,12 +1,18 @@
1
1
  "use server";
2
2
  import {
3
+ getSessionCredentials,
3
4
  queryAction,
5
+ resetSessionImports,
6
+ resolveMethod,
4
7
  unwrapBaseResponse
5
- } from "./chunk-YHI2PFKJ.js";
6
- import "./chunk-XSM747FM.js";
8
+ } from "./chunk-OOR3XGUT.js";
9
+ import "./chunk-HPQQYROJ.js";
7
10
  import "./chunk-DGUM43GV.js";
8
11
  export {
12
+ getSessionCredentials,
9
13
  queryAction,
14
+ resetSessionImports,
15
+ resolveMethod,
10
16
  unwrapBaseResponse
11
17
  };
12
18
  //# sourceMappingURL=query-action.js.map
package/dist/site.js CHANGED
@@ -5,11 +5,14 @@ import {
5
5
  createSiteActions,
6
6
  registerSiteActions,
7
7
  withServerCache
8
- } from "./chunk-3YCNHOMC.js";
8
+ } from "./chunk-4OK7EWLJ.js";
9
9
  import {
10
+ registerAuthSecret,
11
+ registerClientFactory,
12
+ registerScopedCacheWrapper,
10
13
  registerSdkCallWrapper,
11
14
  registerSdkClient
12
- } from "./chunk-XSM747FM.js";
15
+ } from "./chunk-HPQQYROJ.js";
13
16
  import "./chunk-DGUM43GV.js";
14
17
 
15
18
  // src/server-site.ts
@@ -25,6 +28,23 @@ function createServerSite(client, config = {}) {
25
28
  const ttl = tier.staleTime >= 36e5 ? longRedisTtl : redisTtl;
26
29
  return withServerCache(cachePrefix, ttl, methodPath, sdkCall, ...keyArgs);
27
30
  });
31
+ registerScopedCacheWrapper((prefix, methodPath, sdkCall, ...keyArgs) => {
32
+ const tier = getCacheTier(methodPath);
33
+ if (tier.staleTime === 0) return sdkCall();
34
+ const ttl = tier.staleTime >= 36e5 ? longRedisTtl : redisTtl;
35
+ return withServerCache(prefix, ttl, methodPath, sdkCall, ...keyArgs);
36
+ });
37
+ const baseConfig = client["config"];
38
+ if (baseConfig) {
39
+ const Ctor = client.constructor;
40
+ registerClientFactory((siteId, bearerToken) => {
41
+ return new Ctor({ ...baseConfig, siteId, bearerToken });
42
+ });
43
+ }
44
+ const authSecret = config.auth?.secret ?? process.env["AUTH_SECRET"];
45
+ if (authSecret) {
46
+ registerAuthSecret(authSecret);
47
+ }
28
48
  const auth = config.auth ? createAuthConfig({
29
49
  augurClient: client,
30
50
  defaultCustomerId: config.defaultCustomerId,
package/dist/site.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server-site.ts"],"sourcesContent":["import { createSiteActions } from \"./actions/site\";\nimport type { SiteActionsConfig, SiteActions } from \"./actions/site\";\nimport { createAuthConfig } from \"./auth\";\nimport type { AugurAuthCallbacks, AugurAuthClient } from \"./auth\";\nimport type { NextAuthConfig } from \"next-auth\";\nimport { registerSiteActions } from \"./server-site-registry\";\nimport { registerSdkClient, registerSdkCallWrapper } from \"./sdk-client-store\";\nimport { withServerCache } from \"./cache/with-cache\";\nimport { getCacheTier } from \"@simpleapps-com/augur-core\";\n\n/** Auth options forwarded to NextAuth when creating a server site. */\nexport interface ServerSiteAuthConfig {\n secret?: string;\n maxAge?: number;\n callbacks?: Partial<AugurAuthCallbacks>;\n debug?: boolean;\n}\n\n/** Configuration for {@link createServerSite}, combining action config and auth. */\nexport interface ServerSiteConfig extends SiteActionsConfig {\n auth?: ServerSiteAuthConfig;\n}\n\n/** The object returned by {@link createServerSite}. */\nexport interface ServerSite<TApi extends object> {\n client: TApi;\n actions: SiteActions;\n auth: NextAuthConfig | undefined;\n}\n\n/**\n * Create a server-side site instance that bundles the SDK client, server\n * actions, and (optional) NextAuth configuration.\n *\n * @example\n * ```ts\n * import { AugurApi } from \"@simpleapps-com/augur-api\";\n * import { createServerSite } from \"@simpleapps-com/augur-server\";\n *\n * const api = new AugurApi({ baseUrl: process.env.AUGUR_API_URL! });\n * export const site = createServerSite(api, {\n * defaultCustomerId: \"12345\",\n * auth: { secret: process.env.AUTH_SECRET },\n * });\n * ```\n */\nexport function createServerSite<TApi extends object>(\n client: TApi,\n config: ServerSiteConfig = {},\n): ServerSite<TApi> {\n const actions = createSiteActions(client, config);\n registerSiteActions(actions);\n registerSdkClient(client);\n\n // Register a cache wrapper that captures the site's Redis config.\n // queryAction uses this to wrap read methods in Redis caching without\n // importing withServerCache directly (which would pull ioredis into\n // the client bundle via tsup code splitting).\n const { cachePrefix = \"\", redisTtl = 3600, longRedisTtl = 28800 } = config;\n registerSdkCallWrapper((methodPath, sdkCall, ...keyArgs) => {\n const tier = getCacheTier(methodPath);\n // Static paths (staleTime >= 1 hour): long Redis TTL\n // SemiStatic paths (staleTime > 0): standard Redis TTL\n // None (staleTime === 0): no caching\n if (tier.staleTime === 0) return sdkCall();\n const ttl = tier.staleTime >= 3_600_000 ? longRedisTtl : redisTtl;\n return withServerCache(cachePrefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n const auth = config.auth\n ? createAuthConfig({\n augurClient: client as unknown as AugurAuthClient,\n defaultCustomerId: config.defaultCustomerId,\n defaultContactId: config.defaultContactId,\n ...config.auth,\n })\n : undefined;\n\n return { client, actions, auth };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAQA,SAAS,oBAAoB;AAsCtB,SAAS,iBACd,QACA,SAA2B,CAAC,GACV;AAClB,QAAM,UAAU,kBAAkB,QAAQ,MAAM;AAChD,sBAAoB,OAAO;AAC3B,oBAAkB,MAAM;AAMxB,QAAM,EAAE,cAAc,IAAI,WAAW,MAAM,eAAe,MAAM,IAAI;AACpE,yBAAuB,CAAC,YAAY,YAAY,YAAY;AAC1D,UAAM,OAAO,aAAa,UAAU;AAIpC,QAAI,KAAK,cAAc,EAAG,QAAO,QAAQ;AACzC,UAAM,MAAM,KAAK,aAAa,OAAY,eAAe;AACzD,WAAO,gBAAgB,aAAa,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EAC1E,CAAC;AAED,QAAM,OAAO,OAAO,OAChB,iBAAiB;AAAA,IACf,aAAa;AAAA,IACb,mBAAmB,OAAO;AAAA,IAC1B,kBAAkB,OAAO;AAAA,IACzB,GAAG,OAAO;AAAA,EACZ,CAAC,IACD;AAEJ,SAAO,EAAE,QAAQ,SAAS,KAAK;AACjC;","names":[]}
1
+ {"version":3,"sources":["../src/server-site.ts"],"sourcesContent":["import { createSiteActions } from \"./actions/site\";\nimport type { SiteActionsConfig, SiteActions } from \"./actions/site\";\nimport { createAuthConfig } from \"./auth\";\nimport type { AugurAuthCallbacks, AugurAuthClient } from \"./auth\";\nimport type { NextAuthConfig } from \"next-auth\";\nimport { registerSiteActions } from \"./server-site-registry\";\nimport {\n registerSdkClient,\n registerSdkCallWrapper,\n registerAuthSecret,\n registerClientFactory,\n registerScopedCacheWrapper,\n} from \"./sdk-client-store\";\nimport { withServerCache } from \"./cache/with-cache\";\nimport { getCacheTier } from \"@simpleapps-com/augur-core\";\n\n/** Auth options forwarded to NextAuth when creating a server site. */\nexport interface ServerSiteAuthConfig {\n secret?: string;\n maxAge?: number;\n callbacks?: Partial<AugurAuthCallbacks>;\n debug?: boolean;\n}\n\n/** Configuration for {@link createServerSite}, combining action config and auth. */\nexport interface ServerSiteConfig extends SiteActionsConfig {\n auth?: ServerSiteAuthConfig;\n}\n\n/** The object returned by {@link createServerSite}. */\nexport interface ServerSite<TApi extends object> {\n client: TApi;\n actions: SiteActions;\n auth: NextAuthConfig | undefined;\n}\n\n/**\n * Create a server-side site instance that bundles the SDK client, server\n * actions, and (optional) NextAuth configuration.\n *\n * @example\n * ```ts\n * import { AugurApi } from \"@simpleapps-com/augur-api\";\n * import { createServerSite } from \"@simpleapps-com/augur-server\";\n *\n * const api = new AugurApi({ baseUrl: process.env.AUGUR_API_URL! });\n * export const site = createServerSite(api, {\n * defaultCustomerId: \"12345\",\n * auth: { secret: process.env.AUTH_SECRET },\n * });\n * ```\n */\nexport function createServerSite<TApi extends object>(\n client: TApi,\n config: ServerSiteConfig = {},\n): ServerSite<TApi> {\n const actions = createSiteActions(client, config);\n registerSiteActions(actions);\n registerSdkClient(client);\n\n // Register a cache wrapper that captures the site's Redis config.\n // queryAction uses this to wrap read methods in Redis caching without\n // importing withServerCache directly (which would pull ioredis into\n // the client bundle via tsup code splitting).\n const { cachePrefix = \"\", redisTtl = 3600, longRedisTtl = 28800 } = config;\n registerSdkCallWrapper((methodPath, sdkCall, ...keyArgs) => {\n const tier = getCacheTier(methodPath);\n // Static paths (staleTime >= 1 hour): long Redis TTL\n // SemiStatic paths (staleTime > 0): standard Redis TTL\n // None (staleTime === 0): no caching\n if (tier.staleTime === 0) return sdkCall();\n const ttl = tier.staleTime >= 3_600_000 ? longRedisTtl : redisTtl;\n return withServerCache(cachePrefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n // Register scoped cache wrapper for per-request session credentials.\n // queryAction uses this to wrap scoped client calls with Redis caching\n // using the targetSiteId as the cache prefix.\n registerScopedCacheWrapper((prefix, methodPath, sdkCall, ...keyArgs) => {\n const tier = getCacheTier(methodPath);\n if (tier.staleTime === 0) return sdkCall();\n const ttl = tier.staleTime >= 3_600_000 ? longRedisTtl : redisTtl;\n return withServerCache(prefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n // Register client factory for creating scoped SDK clients with\n // per-request credentials. Uses the same constructor + base config\n // (baseUrl, timeout, retries) but different siteId/bearerToken.\n const baseConfig = (client as Record<string, unknown>)[\"config\"] as\n | Record<string, unknown>\n | undefined;\n if (baseConfig) {\n const Ctor = client.constructor as new (cfg: Record<string, unknown>) => object;\n registerClientFactory((siteId: string, bearerToken: string) => {\n return new Ctor({ ...baseConfig, siteId, bearerToken });\n });\n }\n\n const authSecret = config.auth?.secret ?? process.env[\"AUTH_SECRET\"];\n if (authSecret) {\n registerAuthSecret(authSecret);\n }\n\n const auth = config.auth\n ? createAuthConfig({\n augurClient: client as unknown as AugurAuthClient,\n defaultCustomerId: config.defaultCustomerId,\n defaultContactId: config.defaultContactId,\n ...config.auth,\n })\n : undefined;\n\n return { client, actions, auth };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,SAAS,oBAAoB;AAsCtB,SAAS,iBACd,QACA,SAA2B,CAAC,GACV;AAClB,QAAM,UAAU,kBAAkB,QAAQ,MAAM;AAChD,sBAAoB,OAAO;AAC3B,oBAAkB,MAAM;AAMxB,QAAM,EAAE,cAAc,IAAI,WAAW,MAAM,eAAe,MAAM,IAAI;AACpE,yBAAuB,CAAC,YAAY,YAAY,YAAY;AAC1D,UAAM,OAAO,aAAa,UAAU;AAIpC,QAAI,KAAK,cAAc,EAAG,QAAO,QAAQ;AACzC,UAAM,MAAM,KAAK,aAAa,OAAY,eAAe;AACzD,WAAO,gBAAgB,aAAa,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EAC1E,CAAC;AAKD,6BAA2B,CAAC,QAAQ,YAAY,YAAY,YAAY;AACtE,UAAM,OAAO,aAAa,UAAU;AACpC,QAAI,KAAK,cAAc,EAAG,QAAO,QAAQ;AACzC,UAAM,MAAM,KAAK,aAAa,OAAY,eAAe;AACzD,WAAO,gBAAgB,QAAQ,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EACrE,CAAC;AAKD,QAAM,aAAc,OAAmC,QAAQ;AAG/D,MAAI,YAAY;AACd,UAAM,OAAO,OAAO;AACpB,0BAAsB,CAAC,QAAgB,gBAAwB;AAC7D,aAAO,IAAI,KAAK,EAAE,GAAG,YAAY,QAAQ,YAAY,CAAC;AAAA,IACxD,CAAC;AAAA,EACH;AAEA,QAAM,aAAa,OAAO,MAAM,UAAU,QAAQ,IAAI,aAAa;AACnE,MAAI,YAAY;AACd,uBAAmB,UAAU;AAAA,EAC/B;AAEA,QAAM,OAAO,OAAO,OAChB,iBAAiB;AAAA,IACf,aAAa;AAAA,IACb,mBAAmB,OAAO;AAAA,IAC1B,kBAAkB,OAAO;AAAA,IACzB,GAAG,OAAO;AAAA,EACZ,CAAC,IACD;AAEJ,SAAO,EAAE,QAAQ,SAAS,KAAK;AACjC;","names":[]}
package/dist/testing.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  clearSiteActions
3
- } from "./chunk-3YCNHOMC.js";
4
- import "./chunk-XSM747FM.js";
3
+ } from "./chunk-4OK7EWLJ.js";
4
+ import "./chunk-HPQQYROJ.js";
5
5
  import "./chunk-DGUM43GV.js";
6
6
 
7
7
  // src/testing.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleapps-com/augur-server",
3
- "version": "2.2.18",
3
+ "version": "2.2.20",
4
4
  "description": "Server-side utilities for Augur ecommerce sites (Redis caching, SDK helpers, auth)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -54,9 +54,9 @@
54
54
  "llms.txt"
55
55
  ],
56
56
  "dependencies": {
57
- "@simpleapps-com/augur-core": "2.2.18",
58
- "@simpleapps-com/augur-hooks": "2.2.18",
59
- "@simpleapps-com/augur-utils": "2.2.18"
57
+ "@simpleapps-com/augur-core": "2.2.20",
58
+ "@simpleapps-com/augur-hooks": "2.2.20",
59
+ "@simpleapps-com/augur-utils": "2.2.20"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@simpleapps-com/augur-api": "^2026.3.7",
@@ -84,7 +84,7 @@
84
84
  "tsup": "^8.5.0",
85
85
  "vitest": "^3.2.0",
86
86
  "@augur-packages/tsconfig": "0.0.0",
87
- "@simpleapps-com/augur-hooks": "2.2.18"
87
+ "@simpleapps-com/augur-hooks": "2.2.20"
88
88
  },
89
89
  "scripts": {
90
90
  "build": "tsup",
@@ -1,33 +0,0 @@
1
- // src/sdk-client-store.ts
2
- var g = globalThis;
3
- var _cachedClient = null;
4
- var _cachedWrapper = null;
5
- function registerSdkClient(client) {
6
- _cachedClient = client;
7
- g.__augur_sdk_client = client;
8
- }
9
- function getSdkClientOrNull() {
10
- const client = g.__augur_sdk_client ?? _cachedClient;
11
- if (client) {
12
- if (!g.__augur_sdk_client) {
13
- g.__augur_sdk_client = client;
14
- }
15
- return client;
16
- }
17
- return null;
18
- }
19
- function registerSdkCallWrapper(wrapper) {
20
- _cachedWrapper = wrapper;
21
- g.__augur_sdk_call_wrapper = wrapper;
22
- }
23
- function getSdkCallWrapper() {
24
- return g.__augur_sdk_call_wrapper ?? _cachedWrapper ?? null;
25
- }
26
-
27
- export {
28
- registerSdkClient,
29
- getSdkClientOrNull,
30
- registerSdkCallWrapper,
31
- getSdkCallWrapper
32
- };
33
- //# sourceMappingURL=chunk-XSM747FM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/sdk-client-store.ts"],"sourcesContent":["/**\n * Lightweight getter/setter for the raw SDK client instance and cache wrapper.\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 * This module has ZERO imports from actions/site, cache/, or any factory.\n * Same isolation constraints as site-actions-store.ts.\n */\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\nconst g = globalThis as unknown as {\n __augur_sdk_client?: unknown;\n __augur_sdk_call_wrapper?: SdkCallWrapper;\n};\n\nlet _cachedClient: unknown = null;\nlet _cachedWrapper: SdkCallWrapper | 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/** Clears the registered SDK client and wrapper. Used in tests only. @internal */\nexport function clearSdkClient(): void {\n _cachedClient = null;\n _cachedWrapper = null;\n g.__augur_sdk_client = undefined;\n g.__augur_sdk_call_wrapper = undefined;\n}\n"],"mappings":";AAuBA,IAAM,IAAI;AAKV,IAAI,gBAAyB;AAC7B,IAAI,iBAAwC;AAGrC,SAAS,kBAAkB,QAAuB;AACvD,kBAAgB;AAChB,IAAE,qBAAqB;AACzB;AAGO,SAAS,qBAA8B;AAC5C,QAAM,SAAS,EAAE,sBAAsB;AACvC,MAAI,QAAQ;AACV,QAAI,CAAC,EAAE,oBAAoB;AACzB,QAAE,qBAAqB;AAAA,IACzB;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAOO,SAAS,uBAAuB,SAA+B;AACpE,mBAAiB;AACjB,IAAE,2BAA2B;AAC/B;AAGO,SAAS,oBAA2C;AACzD,SAAO,EAAE,4BAA4B,kBAAkB;AACzD;","names":[]}
@@ -1,49 +0,0 @@
1
- import {
2
- getSdkCallWrapper,
3
- getSdkClientOrNull
4
- } from "./chunk-XSM747FM.js";
5
-
6
- // src/query-action.ts
7
- import { isReadMethod } from "@simpleapps-com/augur-core";
8
- function unwrapBaseResponse(raw) {
9
- if (raw != null && typeof raw === "object" && "data" in raw && "status" in raw && "message" in raw) {
10
- return raw.data;
11
- }
12
- return raw;
13
- }
14
- async function queryAction(methodPath, ...args) {
15
- const client = getSdkClientOrNull();
16
- if (!client) {
17
- throw new Error(
18
- "SDK client not initialized. Call createServerSite() or set AUGUR_SITE_ID + AUGUR_JWT env vars."
19
- );
20
- }
21
- const segments = methodPath.split(".");
22
- let current = client;
23
- for (const segment of segments) {
24
- if (current == null || typeof current !== "object" && typeof current !== "function") {
25
- throw new Error(
26
- `Cannot resolve "${methodPath}": "${segment}" is not accessible on ${typeof current}`
27
- );
28
- }
29
- current = current[segment];
30
- }
31
- if (typeof current !== "function") {
32
- throw new Error(`"${methodPath}" does not resolve to a function (got ${typeof current})`);
33
- }
34
- const resolvedMethod = current;
35
- const leafName = segments[segments.length - 1];
36
- const wrapper = getSdkCallWrapper();
37
- if (wrapper && isReadMethod(leafName)) {
38
- const result2 = await wrapper(methodPath, () => resolvedMethod(...args), ...args);
39
- return unwrapBaseResponse(result2);
40
- }
41
- const result = await resolvedMethod(...args);
42
- return unwrapBaseResponse(result);
43
- }
44
-
45
- export {
46
- unwrapBaseResponse,
47
- queryAction
48
- };
49
- //# sourceMappingURL=chunk-YHI2PFKJ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/query-action.ts"],"sourcesContent":["// \"use server\" banner is injected by tsup at build time.\n// Isolated server action for the proxy pattern.\n// This file MUST NOT import from server-actions.ts, server-site-registry.ts,\n// cache/, or any factory. It imports only from lightweight stores with zero\n// deps, plus augur-core (external in tsup — not bundled into chunks).\n\nimport { getSdkClientOrNull, getSdkCallWrapper } from \"./sdk-client-store\";\nimport { isReadMethod } from \"@simpleapps-com/augur-core\";\n\n/**\n * Unwrap SDK BaseResponse if the result matches the standard shape.\n * The SDK wraps all responses in `{ data: T, status: number, message: string }`.\n * SiteActions previously unwrapped this; queryAction now does it automatically\n * so consumers receive `T` directly.\n */\nfunction unwrapBaseResponse(raw: unknown): unknown {\n if (\n raw != null &&\n typeof raw === \"object\" &&\n \"data\" in raw &&\n \"status\" in raw &&\n \"message\" in raw\n ) {\n return (raw as { data: unknown }).data;\n }\n return raw;\n}\n\n/**\n * Generic server action that routes any SDK method call through the raw\n * SDK client with optional Redis caching. Used internally by\n * `createServerQueryProxy()` to bridge client-side React Query hooks\n * to server-side API calls.\n *\n * For read methods (get, list, lookup, search, suggest), the call is\n * wrapped in the registered cache wrapper (Redis) if one was registered\n * by createServerSite(). Write methods bypass caching.\n *\n * SDK responses wrapped in BaseResponse are automatically unwrapped --\n * consumers receive `T` instead of `{ data: T, status, message }`.\n *\n * @param methodPath Dot-separated SDK method path (e.g. \"items.invMast.doc.get\")\n * @param args Arguments to pass to the resolved method\n * @returns The unwrapped result from the SDK method (possibly from Redis cache)\n */\nexport async function queryAction(methodPath: string, ...args: unknown[]): Promise<unknown> {\n const client = getSdkClientOrNull();\n if (!client) {\n throw new Error(\n \"SDK client not initialized. Call createServerSite() or set AUGUR_SITE_ID + AUGUR_JWT env vars.\",\n );\n }\n const segments = methodPath.split(\".\");\n\n let current: unknown = client;\n for (const segment of segments) {\n if (current == null || (typeof current !== \"object\" && typeof current !== \"function\")) {\n throw new Error(\n `Cannot resolve \"${methodPath}\": \"${segment}\" is not accessible on ${typeof current}`,\n );\n }\n current = (current as Record<string, unknown>)[segment];\n }\n\n if (typeof current !== \"function\") {\n throw new Error(`\"${methodPath}\" does not resolve to a function (got ${typeof current})`);\n }\n\n const resolvedMethod = current as (...a: unknown[]) => Promise<unknown>;\n const leafName = segments[segments.length - 1]!;\n const wrapper = getSdkCallWrapper();\n\n // Read methods get Redis caching via the registered wrapper\n if (wrapper && isReadMethod(leafName)) {\n const result = await wrapper(methodPath, () => resolvedMethod(...args), ...args);\n return unwrapBaseResponse(result);\n }\n\n const result = await resolvedMethod(...args);\n return unwrapBaseResponse(result);\n}\n\nexport { unwrapBaseResponse };\n"],"mappings":";;;;;;AAOA,SAAS,oBAAoB;AAQ7B,SAAS,mBAAmB,KAAuB;AACjD,MACE,OAAO,QACP,OAAO,QAAQ,YACf,UAAU,OACV,YAAY,OACZ,aAAa,KACb;AACA,WAAQ,IAA0B;AAAA,EACpC;AACA,SAAO;AACT;AAmBA,eAAsB,YAAY,eAAuB,MAAmC;AAC1F,QAAM,SAAS,mBAAmB;AAClC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,WAAW,WAAW,MAAM,GAAG;AAErC,MAAI,UAAmB;AACvB,aAAW,WAAW,UAAU;AAC9B,QAAI,WAAW,QAAS,OAAO,YAAY,YAAY,OAAO,YAAY,YAAa;AACrF,YAAM,IAAI;AAAA,QACR,mBAAmB,UAAU,OAAO,OAAO,0BAA0B,OAAO,OAAO;AAAA,MACrF;AAAA,IACF;AACA,cAAW,QAAoC,OAAO;AAAA,EACxD;AAEA,MAAI,OAAO,YAAY,YAAY;AACjC,UAAM,IAAI,MAAM,IAAI,UAAU,yCAAyC,OAAO,OAAO,GAAG;AAAA,EAC1F;AAEA,QAAM,iBAAiB;AACvB,QAAM,WAAW,SAAS,SAAS,SAAS,CAAC;AAC7C,QAAM,UAAU,kBAAkB;AAGlC,MAAI,WAAW,aAAa,QAAQ,GAAG;AACrC,UAAMA,UAAS,MAAM,QAAQ,YAAY,MAAM,eAAe,GAAG,IAAI,GAAG,GAAG,IAAI;AAC/E,WAAO,mBAAmBA,OAAM;AAAA,EAClC;AAEA,QAAM,SAAS,MAAM,eAAe,GAAG,IAAI;AAC3C,SAAO,mBAAmB,MAAM;AAClC;","names":["result"]}