@simpleapps-com/augur-server 2.2.7 → 2.2.9
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 +3 -3
- package/dist/{chunk-3N37FS5N.js → chunk-OJZBX6L4.js} +38 -6
- package/dist/chunk-OJZBX6L4.js.map +1 -0
- package/dist/chunk-XSM747FM.js +33 -0
- package/dist/chunk-XSM747FM.js.map +1 -0
- package/dist/chunk-YHI2PFKJ.js +49 -0
- package/dist/chunk-YHI2PFKJ.js.map +1 -0
- package/dist/hooks.js +2 -2
- package/dist/index.js +2 -2
- package/dist/query-action.d.ts +20 -5
- package/dist/query-action.js +6 -4
- package/dist/site.js +16 -3
- package/dist/site.js.map +1 -1
- package/dist/testing.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-3N37FS5N.js.map +0 -1
- package/dist/chunk-EYMB52E5.js +0 -28
- package/dist/chunk-EYMB52E5.js.map +0 -1
- package/dist/chunk-GP6W4BV3.js +0 -32
- package/dist/chunk-GP6W4BV3.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -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\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"]}
|
package/dist/hooks.js
CHANGED
package/dist/index.js
CHANGED
package/dist/query-action.d.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Unwrap SDK BaseResponse if the result matches the standard shape.
|
|
3
|
+
* The SDK wraps all responses in `{ data: T, status: number, message: string }`.
|
|
4
|
+
* SiteActions previously unwrapped this; queryAction now does it automatically
|
|
5
|
+
* so consumers receive `T` directly.
|
|
6
|
+
*/
|
|
7
|
+
declare function unwrapBaseResponse(raw: unknown): unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Generic server action that routes any SDK method call through the raw
|
|
10
|
+
* SDK client with optional Redis caching. Used internally by
|
|
11
|
+
* `createServerQueryProxy()` to bridge client-side React Query hooks
|
|
12
|
+
* to server-side API calls.
|
|
13
|
+
*
|
|
14
|
+
* For read methods (get, list, lookup, search, suggest), the call is
|
|
15
|
+
* wrapped in the registered cache wrapper (Redis) if one was registered
|
|
16
|
+
* by createServerSite(). Write methods bypass caching.
|
|
17
|
+
*
|
|
18
|
+
* SDK responses wrapped in BaseResponse are automatically unwrapped --
|
|
19
|
+
* consumers receive `T` instead of `{ data: T, status, message }`.
|
|
5
20
|
*
|
|
6
21
|
* @param methodPath Dot-separated SDK method path (e.g. "items.invMast.doc.get")
|
|
7
22
|
* @param args Arguments to pass to the resolved method
|
|
8
|
-
* @returns The
|
|
23
|
+
* @returns The unwrapped result from the SDK method (possibly from Redis cache)
|
|
9
24
|
*/
|
|
10
25
|
declare function queryAction(methodPath: string, ...args: unknown[]): Promise<unknown>;
|
|
11
26
|
|
|
12
|
-
export { queryAction };
|
|
27
|
+
export { queryAction, unwrapBaseResponse };
|
package/dist/query-action.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import {
|
|
3
|
-
queryAction
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
queryAction,
|
|
4
|
+
unwrapBaseResponse
|
|
5
|
+
} from "./chunk-YHI2PFKJ.js";
|
|
6
|
+
import "./chunk-XSM747FM.js";
|
|
6
7
|
import "./chunk-DGUM43GV.js";
|
|
7
8
|
export {
|
|
8
|
-
queryAction
|
|
9
|
+
queryAction,
|
|
10
|
+
unwrapBaseResponse
|
|
9
11
|
};
|
|
10
12
|
//# sourceMappingURL=query-action.js.map
|
package/dist/site.js
CHANGED
|
@@ -3,15 +3,28 @@ import {
|
|
|
3
3
|
} from "./chunk-DYHYL6ZS.js";
|
|
4
4
|
import {
|
|
5
5
|
createSiteActions,
|
|
6
|
-
registerSiteActions
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
registerSiteActions,
|
|
7
|
+
withServerCache
|
|
8
|
+
} from "./chunk-OJZBX6L4.js";
|
|
9
|
+
import {
|
|
10
|
+
registerSdkCallWrapper,
|
|
11
|
+
registerSdkClient
|
|
12
|
+
} from "./chunk-XSM747FM.js";
|
|
9
13
|
import "./chunk-DGUM43GV.js";
|
|
10
14
|
|
|
11
15
|
// src/server-site.ts
|
|
16
|
+
import { getCacheTier } from "@simpleapps-com/augur-core";
|
|
12
17
|
function createServerSite(client, config = {}) {
|
|
13
18
|
const actions = createSiteActions(client, config);
|
|
14
19
|
registerSiteActions(actions);
|
|
20
|
+
registerSdkClient(client);
|
|
21
|
+
const { cachePrefix = "", redisTtl = 3600, longRedisTtl = 28800 } = config;
|
|
22
|
+
registerSdkCallWrapper((methodPath, sdkCall, ...keyArgs) => {
|
|
23
|
+
const tier = getCacheTier(methodPath);
|
|
24
|
+
if (tier.staleTime === 0) return sdkCall();
|
|
25
|
+
const ttl = tier.staleTime >= 36e5 ? longRedisTtl : redisTtl;
|
|
26
|
+
return withServerCache(cachePrefix, ttl, methodPath, sdkCall, ...keyArgs);
|
|
27
|
+
});
|
|
15
28
|
const auth = config.auth ? createAuthConfig({
|
|
16
29
|
augurClient: client,
|
|
17
30
|
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\";\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\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":"
|
|
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":[]}
|
package/dist/testing.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simpleapps-com/augur-server",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.9",
|
|
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.
|
|
58
|
-
"@simpleapps-com/augur-hooks": "2.2.
|
|
59
|
-
"@simpleapps-com/augur-utils": "2.2.
|
|
57
|
+
"@simpleapps-com/augur-core": "2.2.9",
|
|
58
|
+
"@simpleapps-com/augur-hooks": "2.2.9",
|
|
59
|
+
"@simpleapps-com/augur-utils": "2.2.9"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@simpleapps-com/augur-api": "^2026.3.5",
|
|
@@ -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.
|
|
87
|
+
"@simpleapps-com/augur-hooks": "2.2.9"
|
|
88
88
|
},
|
|
89
89
|
"scripts": {
|
|
90
90
|
"build": "tsup",
|