@simpleapps-com/augur-server 0.1.7 → 0.1.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/chunk-I26RJDRF.js +50 -0
- package/dist/chunk-I26RJDRF.js.map +1 -0
- package/dist/index.d.ts +10 -30
- package/dist/index.js +8 -52
- package/dist/index.js.map +1 -1
- package/dist/query.d.ts +31 -0
- package/dist/query.js +10 -0
- package/dist/query.js.map +1 -0
- package/next-auth.d.ts +50 -0
- package/package.json +12 -3
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/query-options-helper.ts
|
|
2
|
+
import { CACHE_CONFIG } from "@simpleapps-com/augur-utils";
|
|
3
|
+
var createQueryOptions = ({
|
|
4
|
+
baseKey,
|
|
5
|
+
params,
|
|
6
|
+
queryFn,
|
|
7
|
+
enabledFn,
|
|
8
|
+
staleTime = CACHE_CONFIG.SEMI_STATIC.staleTime,
|
|
9
|
+
gcTime = CACHE_CONFIG.SEMI_STATIC.gcTime,
|
|
10
|
+
excludeFromKey
|
|
11
|
+
}) => {
|
|
12
|
+
const paramEntries = Object.entries(params).filter(([key, value]) => {
|
|
13
|
+
if (excludeFromKey && key === excludeFromKey) return false;
|
|
14
|
+
return value !== void 0 && value !== null && value !== "";
|
|
15
|
+
}).map(([key, value]) => `${key}:${value}`).sort();
|
|
16
|
+
const queryKey = [baseKey, ...paramEntries];
|
|
17
|
+
return {
|
|
18
|
+
queryKey,
|
|
19
|
+
queryFn: () => queryFn(params),
|
|
20
|
+
enabled: enabledFn ? enabledFn(params) : true,
|
|
21
|
+
staleTime,
|
|
22
|
+
gcTime
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
var createSuspenseQueryOptions = ({
|
|
26
|
+
baseKey,
|
|
27
|
+
params,
|
|
28
|
+
queryFn,
|
|
29
|
+
staleTime = CACHE_CONFIG.SEMI_STATIC.staleTime,
|
|
30
|
+
gcTime = CACHE_CONFIG.SEMI_STATIC.gcTime,
|
|
31
|
+
excludeFromKey
|
|
32
|
+
}) => {
|
|
33
|
+
const paramEntries = Object.entries(params).filter(([key, value]) => {
|
|
34
|
+
if (excludeFromKey && key === excludeFromKey) return false;
|
|
35
|
+
return value !== void 0 && value !== null && value !== "";
|
|
36
|
+
}).map(([key, value]) => `${key}:${value}`).sort();
|
|
37
|
+
const queryKey = [baseKey, ...paramEntries];
|
|
38
|
+
return {
|
|
39
|
+
queryKey,
|
|
40
|
+
queryFn: () => queryFn(params),
|
|
41
|
+
staleTime,
|
|
42
|
+
gcTime
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
createQueryOptions,
|
|
48
|
+
createSuspenseQueryOptions
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=chunk-I26RJDRF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/query-options-helper.ts"],"sourcesContent":["import type {\n UseQueryOptions,\n UseSuspenseQueryOptions,\n} from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\nexport interface QueryOptionsConfig<TParams, TData> {\n /** Base query key (e.g., \"customer-orders\") */\n baseKey: string;\n /** Parameters object */\n params: TParams;\n /** Function that returns the data */\n queryFn: (params: TParams) => Promise<TData>;\n /** Function to determine if query should be enabled */\n enabledFn?: (params: TParams) => boolean;\n /** Custom stale time in milliseconds (default: SEMI_STATIC) */\n staleTime?: number;\n /** Custom garbage collection time in milliseconds (default: SEMI_STATIC) */\n gcTime?: number;\n /** Key to exclude from query key generation */\n excludeFromKey?: keyof TParams;\n}\n\n/**\n * Creates useQuery options with consistent key generation.\n * Filters out undefined/null/empty params from the query key.\n */\nexport const createQueryOptions = <\n TParams extends Record<string, unknown>,\n TData,\n>({\n baseKey,\n params,\n queryFn,\n enabledFn,\n staleTime = CACHE_CONFIG.SEMI_STATIC.staleTime,\n gcTime = CACHE_CONFIG.SEMI_STATIC.gcTime,\n excludeFromKey,\n}: QueryOptionsConfig<TParams, TData>): UseQueryOptions<TData> => {\n const paramEntries = Object.entries(params)\n .filter(([key, value]) => {\n if (excludeFromKey && key === excludeFromKey) return false;\n return value !== undefined && value !== null && value !== \"\";\n })\n .map(([key, value]) => `${key}:${value}`)\n .sort();\n\n const queryKey = [baseKey, ...paramEntries];\n\n return {\n queryKey,\n queryFn: () => queryFn(params),\n enabled: enabledFn ? enabledFn(params) : true,\n staleTime,\n gcTime,\n };\n};\n\n/**\n * Creates useSuspenseQuery options with consistent key generation.\n * Same as createQueryOptions but without enabledFn (suspense queries\n * cannot be disabled).\n */\nexport const createSuspenseQueryOptions = <\n TParams extends Record<string, unknown>,\n TData,\n>({\n baseKey,\n params,\n queryFn,\n staleTime = CACHE_CONFIG.SEMI_STATIC.staleTime,\n gcTime = CACHE_CONFIG.SEMI_STATIC.gcTime,\n excludeFromKey,\n}: Omit<\n QueryOptionsConfig<TParams, TData>,\n \"enabledFn\"\n>): UseSuspenseQueryOptions<TData> => {\n const paramEntries = Object.entries(params)\n .filter(([key, value]) => {\n if (excludeFromKey && key === excludeFromKey) return false;\n return value !== undefined && value !== null && value !== \"\";\n })\n .map(([key, value]) => `${key}:${value}`)\n .sort();\n\n const queryKey = [baseKey, ...paramEntries];\n\n return {\n queryKey,\n queryFn: () => queryFn(params),\n staleTime,\n gcTime,\n };\n};\n"],"mappings":";AAIA,SAAS,oBAAoB;AAuBtB,IAAM,qBAAqB,CAGhC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,aAAa,YAAY;AAAA,EACrC,SAAS,aAAa,YAAY;AAAA,EAClC;AACF,MAAkE;AAChE,QAAM,eAAe,OAAO,QAAQ,MAAM,EACvC,OAAO,CAAC,CAAC,KAAK,KAAK,MAAM;AACxB,QAAI,kBAAkB,QAAQ,eAAgB,QAAO;AACrD,WAAO,UAAU,UAAa,UAAU,QAAQ,UAAU;AAAA,EAC5D,CAAC,EACA,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,EACvC,KAAK;AAER,QAAM,WAAW,CAAC,SAAS,GAAG,YAAY;AAE1C,SAAO;AAAA,IACL;AAAA,IACA,SAAS,MAAM,QAAQ,MAAM;AAAA,IAC7B,SAAS,YAAY,UAAU,MAAM,IAAI;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AACF;AAOO,IAAM,6BAA6B,CAGxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,aAAa,YAAY;AAAA,EACrC,SAAS,aAAa,YAAY;AAAA,EAClC;AACF,MAGsC;AACpC,QAAM,eAAe,OAAO,QAAQ,MAAM,EACvC,OAAO,CAAC,CAAC,KAAK,KAAK,MAAM;AACxB,QAAI,kBAAkB,QAAQ,eAAgB,QAAO;AACrD,WAAO,UAAU,UAAa,UAAU,QAAQ,UAAU;AAAA,EAC5D,CAAC,EACA,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,EACvC,KAAK;AAER,QAAM,WAAW,CAAC,SAAS,GAAG,YAAY;AAE1C,SAAO;AAAA,IACL;AAAA,IACA,SAAS,MAAM,QAAQ,MAAM;AAAA,IAC7B;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { QueryClient
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
export { QueryOptionsConfig, createQueryOptions, createSuspenseQueryOptions } from './query.js';
|
|
2
3
|
|
|
3
4
|
declare const env: "development" | "staging" | "production";
|
|
4
5
|
declare const isDev: boolean;
|
|
@@ -36,6 +37,7 @@ declare function isRedisConnected(): boolean;
|
|
|
36
37
|
* ```
|
|
37
38
|
*/
|
|
38
39
|
declare function cachedSdkCall<TArgs extends unknown[], TResult>(prefix: string, methodPath: string, method: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
|
|
40
|
+
declare function cachedSdkCall(prefix: string, methodPath: string, method: (...args: any[]) => Promise<any>, ...args: any[]): Promise<any>;
|
|
39
41
|
/** Returns aggregated cache stats for monitoring endpoints. */
|
|
40
42
|
declare function getCacheStats(): {
|
|
41
43
|
stats: {
|
|
@@ -85,35 +87,13 @@ declare function sdkCall<TArgs extends unknown[], TResult>(method: (...args: TAr
|
|
|
85
87
|
* - No refetching (server renders are one-shot)
|
|
86
88
|
*/
|
|
87
89
|
declare function createServerQueryClient(): QueryClient;
|
|
88
|
-
/** Singleton server query client, reused across requests. */
|
|
89
|
-
declare function getServerQueryClient(): QueryClient;
|
|
90
|
-
|
|
91
|
-
interface QueryOptionsConfig<TParams, TData> {
|
|
92
|
-
/** Base query key (e.g., "customer-orders") */
|
|
93
|
-
baseKey: string;
|
|
94
|
-
/** Parameters object */
|
|
95
|
-
params: TParams;
|
|
96
|
-
/** Function that returns the data */
|
|
97
|
-
queryFn: (params: TParams) => Promise<TData>;
|
|
98
|
-
/** Function to determine if query should be enabled */
|
|
99
|
-
enabledFn?: (params: TParams) => boolean;
|
|
100
|
-
/** Custom stale time in milliseconds (default: SEMI_STATIC) */
|
|
101
|
-
staleTime?: number;
|
|
102
|
-
/** Custom garbage collection time in milliseconds (default: SEMI_STATIC) */
|
|
103
|
-
gcTime?: number;
|
|
104
|
-
/** Key to exclude from query key generation */
|
|
105
|
-
excludeFromKey?: keyof TParams;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Creates useQuery options with consistent key generation.
|
|
109
|
-
* Filters out undefined/null/empty params from the query key.
|
|
110
|
-
*/
|
|
111
|
-
declare const createQueryOptions: <TParams extends Record<string, unknown>, TData>({ baseKey, params, queryFn, enabledFn, staleTime, gcTime, excludeFromKey, }: QueryOptionsConfig<TParams, TData>) => UseQueryOptions<TData>;
|
|
112
90
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
91
|
+
* Returns a per-request singleton QueryClient for React Server Components.
|
|
92
|
+
*
|
|
93
|
+
* React's `cache()` deduplicates calls within a single server request,
|
|
94
|
+
* so each request gets its own QueryClient while avoiding the cross-request
|
|
95
|
+
* state leakage that a module-level singleton would cause.
|
|
116
96
|
*/
|
|
117
|
-
declare const
|
|
97
|
+
declare const getServerQueryClient: () => QueryClient;
|
|
118
98
|
|
|
119
|
-
export {
|
|
99
|
+
export { cacheGet, cacheSet, cachedSdkCall, createServerQueryClient, env, getCacheStats, getCircuitState, getServerQueryClient, isDev, isProduction, isRedisConnected, isStaging, sdkCall };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createQueryOptions,
|
|
3
|
+
createSuspenseQueryOptions
|
|
4
|
+
} from "./chunk-I26RJDRF.js";
|
|
1
5
|
import {
|
|
2
6
|
__require
|
|
3
7
|
} from "./chunk-DGUM43GV.js";
|
|
@@ -291,6 +295,7 @@ async function sdkCall(method, ...args) {
|
|
|
291
295
|
}
|
|
292
296
|
|
|
293
297
|
// src/server-query-client.ts
|
|
298
|
+
import { cache } from "react";
|
|
294
299
|
import { QueryClient } from "@tanstack/react-query";
|
|
295
300
|
import { CACHE_CONFIG } from "@simpleapps-com/augur-utils";
|
|
296
301
|
function createServerQueryClient() {
|
|
@@ -307,58 +312,9 @@ function createServerQueryClient() {
|
|
|
307
312
|
}
|
|
308
313
|
});
|
|
309
314
|
}
|
|
310
|
-
var
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
serverQueryClient = createServerQueryClient();
|
|
314
|
-
}
|
|
315
|
-
return serverQueryClient;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// src/query-options-helper.ts
|
|
319
|
-
import { CACHE_CONFIG as CACHE_CONFIG2 } from "@simpleapps-com/augur-utils";
|
|
320
|
-
var createQueryOptions = ({
|
|
321
|
-
baseKey,
|
|
322
|
-
params,
|
|
323
|
-
queryFn,
|
|
324
|
-
enabledFn,
|
|
325
|
-
staleTime = CACHE_CONFIG2.SEMI_STATIC.staleTime,
|
|
326
|
-
gcTime = CACHE_CONFIG2.SEMI_STATIC.gcTime,
|
|
327
|
-
excludeFromKey
|
|
328
|
-
}) => {
|
|
329
|
-
const paramEntries = Object.entries(params).filter(([key, value]) => {
|
|
330
|
-
if (excludeFromKey && key === excludeFromKey) return false;
|
|
331
|
-
return value !== void 0 && value !== null && value !== "";
|
|
332
|
-
}).map(([key, value]) => `${key}: ${value}`);
|
|
333
|
-
const queryKey = [baseKey, ...paramEntries];
|
|
334
|
-
return {
|
|
335
|
-
queryKey,
|
|
336
|
-
queryFn: () => queryFn(params),
|
|
337
|
-
enabled: enabledFn ? enabledFn(params) : true,
|
|
338
|
-
staleTime,
|
|
339
|
-
gcTime
|
|
340
|
-
};
|
|
341
|
-
};
|
|
342
|
-
var createSuspenseQueryOptions = ({
|
|
343
|
-
baseKey,
|
|
344
|
-
params,
|
|
345
|
-
queryFn,
|
|
346
|
-
staleTime = CACHE_CONFIG2.SEMI_STATIC.staleTime,
|
|
347
|
-
gcTime = CACHE_CONFIG2.SEMI_STATIC.gcTime,
|
|
348
|
-
excludeFromKey
|
|
349
|
-
}) => {
|
|
350
|
-
const paramEntries = Object.entries(params).filter(([key, value]) => {
|
|
351
|
-
if (excludeFromKey && key === excludeFromKey) return false;
|
|
352
|
-
return value !== void 0 && value !== null && value !== "";
|
|
353
|
-
}).map(([key, value]) => `${key}: ${value}`);
|
|
354
|
-
const queryKey = [baseKey, ...paramEntries];
|
|
355
|
-
return {
|
|
356
|
-
queryKey,
|
|
357
|
-
queryFn: () => queryFn(params),
|
|
358
|
-
staleTime,
|
|
359
|
-
gcTime
|
|
360
|
-
};
|
|
361
|
-
};
|
|
315
|
+
var getServerQueryClient = cache(
|
|
316
|
+
() => createServerQueryClient()
|
|
317
|
+
);
|
|
362
318
|
export {
|
|
363
319
|
cacheGet,
|
|
364
320
|
cacheSet,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/environment.ts","../src/cache/redis-client.ts","../src/cache/sdk-cache.ts","../src/sdk-call.ts","../src/server-query-client.ts","../src/query-options-helper.ts"],"sourcesContent":["/**\n * Environment detection that works across server, client, and containers.\n *\n * Priority:\n * 1. DEPLOYMENT_ENV (\"dev\" → staging, \"live\" → production)\n * 2. Server-side NODE_ENV fallback\n * 3. Client-side hostname detection\n */\nfunction getEnvironment(): \"development\" | \"staging\" | \"production\" {\n const deploymentEnv = process.env.DEPLOYMENT_ENV;\n if (deploymentEnv === \"dev\") return \"staging\";\n if (deploymentEnv === \"live\") return \"production\";\n\n if (typeof window === \"undefined\") {\n if (process.env.NODE_ENV === \"development\") return \"development\";\n return \"production\";\n }\n\n const host = window.location.hostname;\n if (host.includes(\"localhost\") || host.includes(\"127.0.0.1\"))\n return \"development\";\n if (host.includes(\"agr-hosting.dev\")) return \"staging\";\n return \"production\";\n}\n\nexport const env = getEnvironment();\nexport const isDev = env === \"development\";\nexport const isStaging = env === \"staging\";\nexport const isProduction = env === \"production\";\n","import type Redis from \"ioredis\";\nimport { isDev, isStaging } from \"../environment\";\n\nconst CIRCUIT_BREAKER_THRESHOLD = 5;\nconst CIRCUIT_BREAKER_RESET_MS = 60_000;\n\ninterface RedisGlobalState {\n client: Redis | null;\n consecutiveFailures: number;\n circuitOpenUntil: number;\n}\n\nconst g = globalThis as unknown as { __redisState?: RedisGlobalState };\nif (!g.__redisState) {\n g.__redisState = {\n client: null,\n consecutiveFailures: 0,\n circuitOpenUntil: 0,\n };\n}\nconst state = g.__redisState;\n\nconst debugEnabled = isDev || isStaging;\n\nfunction log(...args: unknown[]) {\n if (debugEnabled) {\n console.log(\"[Redis]\", ...args);\n }\n}\n\nfunction isCircuitOpen(): boolean {\n if (state.circuitOpenUntil === 0) return false;\n if (Date.now() >= state.circuitOpenUntil) {\n state.circuitOpenUntil = 0;\n state.consecutiveFailures = 0;\n log(\"Circuit breaker reset -- retrying Redis\");\n return false;\n }\n return true;\n}\n\nfunction recordFailure() {\n state.consecutiveFailures++;\n if (state.consecutiveFailures >= CIRCUIT_BREAKER_THRESHOLD) {\n state.circuitOpenUntil = Date.now() + CIRCUIT_BREAKER_RESET_MS;\n log(\n `Circuit breaker OPEN -- skipping Redis for ${CIRCUIT_BREAKER_RESET_MS / 1000}s`,\n );\n }\n}\n\nfunction recordSuccess() {\n state.consecutiveFailures = 0;\n}\n\nfunction getRedisUrl(): string | undefined {\n const containerRedis = process.env.REDIS_SERVERS;\n if (containerRedis) return `redis://${containerRedis}`;\n\n if (isDev) return process.env.REDIS_URL_DEV;\n if (isStaging) return process.env.REDIS_URL_STAGING;\n return process.env.REDIS_URL_PROD;\n}\n\nfunction getClient(): Redis | null {\n if (state.client) return state.client;\n\n const url = getRedisUrl();\n if (!url) {\n log(\"No REDIS_URL -- cache disabled\");\n return null;\n }\n\n try {\n // Dynamic import at module level isn't possible, so we require ioredis\n // at runtime. It's an optional peer dep -- if not installed, cache is\n // silently disabled.\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const IORedis = require(\"ioredis\") as typeof import(\"ioredis\").default;\n\n state.client = new IORedis(url, {\n maxRetriesPerRequest: 1,\n connectTimeout: 3000,\n lazyConnect: true,\n enableOfflineQueue: false,\n });\n\n state.client.on(\"error\", (err: Error) => {\n log(\"Connection error:\", err.message);\n recordFailure();\n });\n\n state.client.on(\"connect\", () => log(\"Connected\"));\n\n state.client.connect().catch(() => {\n /* handled by error event */\n });\n\n return state.client;\n } catch {\n log(\"Failed to create client (ioredis not installed?)\");\n return null;\n }\n}\n\nexport async function cacheGet(key: string): Promise<string | null> {\n if (isCircuitOpen()) return null;\n\n const client = getClient();\n if (!client) return null;\n\n try {\n const value = await client.get(key);\n recordSuccess();\n return value;\n } catch {\n recordFailure();\n return null;\n }\n}\n\nexport async function cacheSet(\n key: string,\n value: string,\n ttlSeconds: number,\n): Promise<void> {\n if (isCircuitOpen()) return;\n\n const client = getClient();\n if (!client) return;\n\n try {\n await client.setex(key, ttlSeconds, value);\n recordSuccess();\n } catch {\n recordFailure();\n }\n}\n\nexport function getCircuitState(): \"closed\" | \"open\" {\n return isCircuitOpen() ? \"open\" : \"closed\";\n}\n\nexport function isRedisConnected(): boolean {\n return state.client?.status === \"ready\";\n}\n","import crypto from \"crypto\";\nimport { cacheGet, cacheSet } from \"./redis-client\";\nimport { isDev, isStaging } from \"../environment\";\n\nconst CACHE_ENABLED = process.env.REDIS_CACHE_ENABLED !== \"false\";\nconst debugEnabled = isDev || isStaging;\n\ninterface MethodStats {\n hits: number;\n misses: number;\n errors: number;\n totalMs: number;\n}\n\ninterface RecentOp {\n op: \"HIT\" | \"MISS\" | \"SKIP\" | \"ERROR\";\n key: string;\n ms: number;\n ts: number;\n}\n\ninterface CacheGlobalState {\n statsMap: Map<string, MethodStats>;\n recentOps: RecentOp[];\n}\n\nconst g = globalThis as unknown as { __sdkCacheState?: CacheGlobalState };\nif (!g.__sdkCacheState) {\n g.__sdkCacheState = { statsMap: new Map(), recentOps: [] };\n}\nconst { statsMap, recentOps } = g.__sdkCacheState;\n\nconst MAX_RECENT = 50;\n\nfunction pushRecent(op: RecentOp) {\n recentOps.push(op);\n if (recentOps.length > MAX_RECENT) recentOps.shift();\n}\n\nfunction getOrCreateStats(method: string): MethodStats {\n let s = statsMap.get(method);\n if (!s) {\n s = { hits: 0, misses: 0, errors: 0, totalMs: 0 };\n statsMap.set(method, s);\n }\n return s;\n}\n\nfunction hashArgs(args: unknown[]): string {\n const normalized = JSON.stringify(args, (_, v) => {\n if (v && typeof v === \"object\" && !Array.isArray(v)) {\n return Object.keys(v)\n .sort()\n .reduce(\n (acc, k) => {\n acc[k] = v[k];\n return acc;\n },\n {} as Record<string, unknown>,\n );\n }\n return v;\n });\n return crypto\n .createHash(\"sha256\")\n .update(normalized)\n .digest(\"hex\")\n .slice(0, 8);\n}\n\n/**\n * Extracts the `edgeCache` value from the arguments and converts it to\n * a TTL in seconds. Supports both the legacy numeric-hours format and the\n * augur-api >= 0.9.6 sub-hour string formats ('30s', '1m', '5m').\n *\n * - Number values (1, 2, 3, 4, 5, 8): treated as hours\n * - Numeric strings ('1', '2', etc.): treated as hours\n * - Duration strings ('30s', '1m', '5m'): parsed as seconds/minutes\n */\nfunction extractTtlSeconds(args: unknown[]): number | undefined {\n for (let i = args.length - 1; i >= 0; i--) {\n const arg = args[i];\n if (arg && typeof arg === \"object\" && \"edgeCache\" in arg) {\n const val = (arg as { edgeCache: unknown }).edgeCache;\n if (typeof val === \"number\") return val * 3600;\n if (typeof val === \"string\") {\n if (val.endsWith(\"s\")) return parseInt(val, 10);\n if (val.endsWith(\"m\")) return parseInt(val, 10) * 60;\n const n = Number(val);\n return isNaN(n) ? undefined : n * 3600;\n }\n return undefined;\n }\n }\n return undefined;\n}\n\nfunction formatTtl(seconds: number): string {\n if (seconds < 60) return `${seconds}s`;\n if (seconds < 3600) return `${Math.round(seconds / 60)}m`;\n return `${Math.round(seconds / 3600)}h`;\n}\n\n/**\n * Wraps an SDK call with Redis caching.\n *\n * @param prefix - Redis key prefix (e.g. \"mysite:\")\n * @param methodPath - Dot-separated SDK method path (used as cache key)\n * @param method - The SDK method to call\n * @param args - Arguments to pass to the SDK method. If any argument\n * contains an `edgeCache` property, the result is cached in Redis for\n * that duration. Without `edgeCache`, the call bypasses cache.\n *\n * Accepted `edgeCache` values (matching augur-api CacheParams):\n * - Numbers: 1–8 (hours)\n * - Sub-hour strings: '30s', '1m', '5m'\n *\n * @example\n * ```ts\n * const result = await cachedSdkCall(\n * \"mysite:\",\n * \"items.categories.get\",\n * augurServices.items.categories.get,\n * itemCategoryUid,\n * { edgeCache: 1 },\n * );\n * ```\n */\nexport async function cachedSdkCall<TArgs extends unknown[], TResult>(\n prefix: string,\n methodPath: string,\n method: (...args: TArgs) => Promise<TResult>,\n ...args: TArgs\n): Promise<TResult> {\n const ttlSeconds = extractTtlSeconds(args);\n\n if (!CACHE_ENABLED || ttlSeconds === undefined) {\n if (debugEnabled) {\n console.log(`[SDK Cache] SKIP ${methodPath} (no edgeCache, REALTIME)`);\n }\n pushRecent({ op: \"SKIP\", key: methodPath, ms: 0, ts: Date.now() });\n return method(...args);\n }\n\n const argsHash = hashArgs(args);\n const cacheKey = `${prefix}sdk:${methodPath}:${argsHash}`;\n const start = Date.now();\n const stats = getOrCreateStats(methodPath);\n\n try {\n const cached = await cacheGet(cacheKey);\n if (cached !== null) {\n const parsed = JSON.parse(cached);\n const ms = Date.now() - start;\n stats.hits++;\n stats.totalMs += ms;\n if (debugEnabled) {\n console.log(`[SDK Cache] HIT ${methodPath}:${argsHash} (${ms}ms)`);\n }\n pushRecent({\n op: \"HIT\",\n key: `${methodPath}:${argsHash}`,\n ms,\n ts: Date.now(),\n });\n return parsed as TResult;\n }\n } catch {\n stats.errors++;\n }\n\n const result = await method(...args);\n const ms = Date.now() - start;\n stats.misses++;\n stats.totalMs += ms;\n\n if (debugEnabled) {\n console.log(\n `[SDK Cache] MISS ${methodPath}:${argsHash} (${ms}ms -> cached, TTL ${formatTtl(ttlSeconds)})`,\n );\n }\n pushRecent({\n op: \"MISS\",\n key: `${methodPath}:${argsHash}`,\n ms,\n ts: Date.now(),\n });\n\n try {\n const serialized = JSON.stringify(result);\n cacheSet(cacheKey, serialized, ttlSeconds).catch(() => {\n /* swallow */\n });\n } catch {\n // Non-serializable result -- skip caching\n }\n\n return result;\n}\n\nfunction formatAgo(ms: number): string {\n if (ms < 1000) return \"<1s\";\n const s = Math.floor(ms / 1000);\n if (s < 60) return `${s}s ago`;\n const m = Math.floor(s / 60);\n return `${m}m ago`;\n}\n\n/** Returns aggregated cache stats for monitoring endpoints. */\nexport function getCacheStats() {\n let totalHits = 0;\n let totalMisses = 0;\n let totalErrors = 0;\n\n const topKeys: {\n key: string;\n hits: number;\n misses: number;\n avgMs: number;\n }[] = [];\n\n statsMap.forEach((s, key) => {\n totalHits += s.hits;\n totalMisses += s.misses;\n totalErrors += s.errors;\n const total = s.hits + s.misses;\n topKeys.push({\n key,\n hits: s.hits,\n misses: s.misses,\n avgMs: total > 0 ? Math.round(s.totalMs / total) : 0,\n });\n });\n\n topKeys.sort((a, b) => b.hits - a.hits);\n\n const total = totalHits + totalMisses;\n const hitRate =\n total > 0 ? ((totalHits / total) * 100).toFixed(1) + \"%\" : \"0%\";\n\n const now = Date.now();\n const recent = recentOps\n .slice(-20)\n .reverse()\n .map((op) => ({\n op: op.op,\n key: op.key,\n ms: op.ms,\n ago: formatAgo(now - op.ts),\n }));\n\n return {\n stats: { hits: totalHits, misses: totalMisses, errors: totalErrors, hitRate },\n topKeys: topKeys.slice(0, 15),\n recentOps: recent,\n };\n}\n","/**\n * Calls an Augur SDK method, forwarding all arguments with full type safety.\n *\n * With augur-api >= 0.9.6, SDK methods properly declare their `CacheParams`\n * option (including `edgeCache`), so this wrapper preserves both parameter\n * and return-type inference end-to-end.\n *\n * @example\n * ```ts\n * const result = await sdkCall(\n * augurServices.items.invMast.get,\n * invMastUid,\n * { edgeCache: 4 },\n * );\n * ```\n */\nexport async function sdkCall<TArgs extends unknown[], TResult>(\n method: (...args: TArgs) => Promise<TResult>,\n ...args: TArgs\n): Promise<TResult> {\n return method(...args);\n}\n","import { QueryClient } from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\n/**\n * Creates a server-side query client optimised for prefetching.\n *\n * - No persistence (server-only)\n * - Longer cache times for prefetched data\n * - No retries (fail fast on server)\n * - No refetching (server renders are one-shot)\n */\nexport function createServerQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: CACHE_CONFIG.STATIC.staleTime,\n gcTime: CACHE_CONFIG.STATIC.staleTime,\n retry: 0,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n },\n },\n });\n}\n\nlet serverQueryClient: QueryClient | undefined = undefined;\n\n/** Singleton server query client, reused across requests. */\nexport function getServerQueryClient(): QueryClient {\n if (!serverQueryClient) {\n serverQueryClient = createServerQueryClient();\n }\n return serverQueryClient;\n}\n","import type {\n UseQueryOptions,\n UseSuspenseQueryOptions,\n} from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\nexport interface QueryOptionsConfig<TParams, TData> {\n /** Base query key (e.g., \"customer-orders\") */\n baseKey: string;\n /** Parameters object */\n params: TParams;\n /** Function that returns the data */\n queryFn: (params: TParams) => Promise<TData>;\n /** Function to determine if query should be enabled */\n enabledFn?: (params: TParams) => boolean;\n /** Custom stale time in milliseconds (default: SEMI_STATIC) */\n staleTime?: number;\n /** Custom garbage collection time in milliseconds (default: SEMI_STATIC) */\n gcTime?: number;\n /** Key to exclude from query key generation */\n excludeFromKey?: keyof TParams;\n}\n\n/**\n * Creates useQuery options with consistent key generation.\n * Filters out undefined/null/empty params from the query key.\n */\nexport const createQueryOptions = <\n TParams extends Record<string, unknown>,\n TData,\n>({\n baseKey,\n params,\n queryFn,\n enabledFn,\n staleTime = CACHE_CONFIG.SEMI_STATIC.staleTime,\n gcTime = CACHE_CONFIG.SEMI_STATIC.gcTime,\n excludeFromKey,\n}: QueryOptionsConfig<TParams, TData>): UseQueryOptions<TData> => {\n const paramEntries = Object.entries(params)\n .filter(([key, value]) => {\n if (excludeFromKey && key === excludeFromKey) return false;\n return value !== undefined && value !== null && value !== \"\";\n })\n .map(([key, value]) => `${key}: ${value}`);\n\n const queryKey = [baseKey, ...paramEntries];\n\n return {\n queryKey,\n queryFn: () => queryFn(params),\n enabled: enabledFn ? enabledFn(params) : true,\n staleTime,\n gcTime,\n };\n};\n\n/**\n * Creates useSuspenseQuery options with consistent key generation.\n * Same as createQueryOptions but without enabledFn (suspense queries\n * cannot be disabled).\n */\nexport const createSuspenseQueryOptions = <\n TParams extends Record<string, unknown>,\n TData,\n>({\n baseKey,\n params,\n queryFn,\n staleTime = CACHE_CONFIG.SEMI_STATIC.staleTime,\n gcTime = CACHE_CONFIG.SEMI_STATIC.gcTime,\n excludeFromKey,\n}: Omit<\n QueryOptionsConfig<TParams, TData>,\n \"enabledFn\"\n>): UseSuspenseQueryOptions<TData> => {\n const paramEntries = Object.entries(params)\n .filter(([key, value]) => {\n if (excludeFromKey && key === excludeFromKey) return false;\n return value !== undefined && value !== null && value !== \"\";\n })\n .map(([key, value]) => `${key}: ${value}`);\n\n const queryKey = [baseKey, ...paramEntries];\n\n return {\n queryKey,\n queryFn: () => queryFn(params),\n staleTime,\n gcTime,\n };\n};\n"],"mappings":";;;;;AAQA,SAAS,iBAA2D;AAClE,QAAM,gBAAgB,QAAQ,IAAI;AAClC,MAAI,kBAAkB,MAAO,QAAO;AACpC,MAAI,kBAAkB,OAAQ,QAAO;AAErC,MAAI,OAAO,WAAW,aAAa;AACjC,QAAI,QAAQ,IAAI,aAAa,cAAe,QAAO;AACnD,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,OAAO,SAAS;AAC7B,MAAI,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,WAAW;AACzD,WAAO;AACT,MAAI,KAAK,SAAS,iBAAiB,EAAG,QAAO;AAC7C,SAAO;AACT;AAEO,IAAM,MAAM,eAAe;AAC3B,IAAM,QAAQ,QAAQ;AACtB,IAAM,YAAY,QAAQ;AAC1B,IAAM,eAAe,QAAQ;;;ACzBpC,IAAM,4BAA4B;AAClC,IAAM,2BAA2B;AAQjC,IAAM,IAAI;AACV,IAAI,CAAC,EAAE,cAAc;AACnB,IAAE,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,qBAAqB;AAAA,IACrB,kBAAkB;AAAA,EACpB;AACF;AACA,IAAM,QAAQ,EAAE;AAEhB,IAAM,eAAe,SAAS;AAE9B,SAAS,OAAO,MAAiB;AAC/B,MAAI,cAAc;AAChB,YAAQ,IAAI,WAAW,GAAG,IAAI;AAAA,EAChC;AACF;AAEA,SAAS,gBAAyB;AAChC,MAAI,MAAM,qBAAqB,EAAG,QAAO;AACzC,MAAI,KAAK,IAAI,KAAK,MAAM,kBAAkB;AACxC,UAAM,mBAAmB;AACzB,UAAM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sC;AACpC,QAAM,eAAe,OAAO,QAAQ,MAAM,EACvC,OAAO,CAAC,CAAC,KAAK,KAAK,MAAM;AACxB,QAAI,kBAAkB,QAAQ,eAAgB,QAAO;AACrD,WAAO,UAAU,UAAa,UAAU,QAAQ,UAAU;AAAA,EAC5D,CAAC,EACA,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,KAAK,KAAK,EAAE;AAE3C,QAAM,WAAW,CAAC,SAAS,GAAG,YAAY;AAE1C,SAAO;AAAA,IACL;AAAA,IACA,SAAS,MAAM,QAAQ,MAAM;AAAA,IAC7B;AAAA,IACA;AAAA,EACF;AACF;","names":["debugEnabled","g","ms","total","CACHE_CONFIG"]}
|
|
1
|
+
{"version":3,"sources":["../src/environment.ts","../src/cache/redis-client.ts","../src/cache/sdk-cache.ts","../src/sdk-call.ts","../src/server-query-client.ts"],"sourcesContent":["/**\n * Environment detection that works across server, client, and containers.\n *\n * Priority:\n * 1. DEPLOYMENT_ENV (\"dev\" → staging, \"live\" → production)\n * 2. Server-side NODE_ENV fallback\n * 3. Client-side hostname detection\n */\nfunction getEnvironment(): \"development\" | \"staging\" | \"production\" {\n const deploymentEnv = process.env.DEPLOYMENT_ENV;\n if (deploymentEnv === \"dev\") return \"staging\";\n if (deploymentEnv === \"live\") return \"production\";\n\n if (typeof window === \"undefined\") {\n if (process.env.NODE_ENV === \"development\") return \"development\";\n return \"production\";\n }\n\n const host = window.location.hostname;\n if (host.includes(\"localhost\") || host.includes(\"127.0.0.1\"))\n return \"development\";\n if (host.includes(\"agr-hosting.dev\")) return \"staging\";\n return \"production\";\n}\n\nexport const env = getEnvironment();\nexport const isDev = env === \"development\";\nexport const isStaging = env === \"staging\";\nexport const isProduction = env === \"production\";\n","import type Redis from \"ioredis\";\nimport { isDev, isStaging } from \"../environment\";\n\nconst CIRCUIT_BREAKER_THRESHOLD = 5;\nconst CIRCUIT_BREAKER_RESET_MS = 60_000;\n\ninterface RedisGlobalState {\n client: Redis | null;\n consecutiveFailures: number;\n circuitOpenUntil: number;\n}\n\nconst g = globalThis as unknown as { __redisState?: RedisGlobalState };\nif (!g.__redisState) {\n g.__redisState = {\n client: null,\n consecutiveFailures: 0,\n circuitOpenUntil: 0,\n };\n}\nconst state = g.__redisState;\n\nconst debugEnabled = isDev || isStaging;\n\nfunction log(...args: unknown[]) {\n if (debugEnabled) {\n console.log(\"[Redis]\", ...args);\n }\n}\n\nfunction isCircuitOpen(): boolean {\n if (state.circuitOpenUntil === 0) return false;\n if (Date.now() >= state.circuitOpenUntil) {\n state.circuitOpenUntil = 0;\n state.consecutiveFailures = 0;\n log(\"Circuit breaker reset -- retrying Redis\");\n return false;\n }\n return true;\n}\n\nfunction recordFailure() {\n state.consecutiveFailures++;\n if (state.consecutiveFailures >= CIRCUIT_BREAKER_THRESHOLD) {\n state.circuitOpenUntil = Date.now() + CIRCUIT_BREAKER_RESET_MS;\n log(\n `Circuit breaker OPEN -- skipping Redis for ${CIRCUIT_BREAKER_RESET_MS / 1000}s`,\n );\n }\n}\n\nfunction recordSuccess() {\n state.consecutiveFailures = 0;\n}\n\nfunction getRedisUrl(): string | undefined {\n const containerRedis = process.env.REDIS_SERVERS;\n if (containerRedis) return `redis://${containerRedis}`;\n\n if (isDev) return process.env.REDIS_URL_DEV;\n if (isStaging) return process.env.REDIS_URL_STAGING;\n return process.env.REDIS_URL_PROD;\n}\n\nfunction getClient(): Redis | null {\n if (state.client) return state.client;\n\n const url = getRedisUrl();\n if (!url) {\n log(\"No REDIS_URL -- cache disabled\");\n return null;\n }\n\n try {\n // Dynamic import at module level isn't possible, so we require ioredis\n // at runtime. It's an optional peer dep -- if not installed, cache is\n // silently disabled.\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const IORedis = require(\"ioredis\") as typeof import(\"ioredis\").default;\n\n state.client = new IORedis(url, {\n maxRetriesPerRequest: 1,\n connectTimeout: 3000,\n lazyConnect: true,\n enableOfflineQueue: false,\n });\n\n state.client.on(\"error\", (err: Error) => {\n log(\"Connection error:\", err.message);\n recordFailure();\n });\n\n state.client.on(\"connect\", () => log(\"Connected\"));\n\n state.client.connect().catch(() => {\n /* handled by error event */\n });\n\n return state.client;\n } catch {\n log(\"Failed to create client (ioredis not installed?)\");\n return null;\n }\n}\n\nexport async function cacheGet(key: string): Promise<string | null> {\n if (isCircuitOpen()) return null;\n\n const client = getClient();\n if (!client) return null;\n\n try {\n const value = await client.get(key);\n recordSuccess();\n return value;\n } catch {\n recordFailure();\n return null;\n }\n}\n\nexport async function cacheSet(\n key: string,\n value: string,\n ttlSeconds: number,\n): Promise<void> {\n if (isCircuitOpen()) return;\n\n const client = getClient();\n if (!client) return;\n\n try {\n await client.setex(key, ttlSeconds, value);\n recordSuccess();\n } catch {\n recordFailure();\n }\n}\n\nexport function getCircuitState(): \"closed\" | \"open\" {\n return isCircuitOpen() ? \"open\" : \"closed\";\n}\n\nexport function isRedisConnected(): boolean {\n return state.client?.status === \"ready\";\n}\n","import crypto from \"crypto\";\nimport { cacheGet, cacheSet } from \"./redis-client\";\nimport { isDev, isStaging } from \"../environment\";\n\nconst CACHE_ENABLED = process.env.REDIS_CACHE_ENABLED !== \"false\";\nconst debugEnabled = isDev || isStaging;\n\ninterface MethodStats {\n hits: number;\n misses: number;\n errors: number;\n totalMs: number;\n}\n\ninterface RecentOp {\n op: \"HIT\" | \"MISS\" | \"SKIP\" | \"ERROR\";\n key: string;\n ms: number;\n ts: number;\n}\n\ninterface CacheGlobalState {\n statsMap: Map<string, MethodStats>;\n recentOps: RecentOp[];\n}\n\nconst g = globalThis as unknown as { __sdkCacheState?: CacheGlobalState };\nif (!g.__sdkCacheState) {\n g.__sdkCacheState = { statsMap: new Map(), recentOps: [] };\n}\nconst { statsMap, recentOps } = g.__sdkCacheState;\n\nconst MAX_RECENT = 50;\n\nfunction pushRecent(op: RecentOp) {\n recentOps.push(op);\n if (recentOps.length > MAX_RECENT) recentOps.shift();\n}\n\nfunction getOrCreateStats(method: string): MethodStats {\n let s = statsMap.get(method);\n if (!s) {\n s = { hits: 0, misses: 0, errors: 0, totalMs: 0 };\n statsMap.set(method, s);\n }\n return s;\n}\n\nfunction hashArgs(args: unknown[]): string {\n const normalized = JSON.stringify(args, (_, v) => {\n if (v && typeof v === \"object\" && !Array.isArray(v)) {\n return Object.keys(v)\n .sort()\n .reduce(\n (acc, k) => {\n acc[k] = v[k];\n return acc;\n },\n {} as Record<string, unknown>,\n );\n }\n return v;\n });\n return crypto\n .createHash(\"sha256\")\n .update(normalized)\n .digest(\"hex\")\n .slice(0, 8);\n}\n\n/**\n * Extracts the `edgeCache` value from the arguments and converts it to\n * a TTL in seconds. Supports both the legacy numeric-hours format and the\n * augur-api >= 0.9.6 sub-hour string formats ('30s', '1m', '5m').\n *\n * - Number values (1, 2, 3, 4, 5, 8): treated as hours\n * - Numeric strings ('1', '2', etc.): treated as hours\n * - Duration strings ('30s', '1m', '5m'): parsed as seconds/minutes\n */\nfunction extractTtlSeconds(args: unknown[]): number | undefined {\n for (let i = args.length - 1; i >= 0; i--) {\n const arg = args[i];\n if (arg && typeof arg === \"object\" && \"edgeCache\" in arg) {\n const val = (arg as { edgeCache: unknown }).edgeCache;\n if (typeof val === \"number\") return val * 3600;\n if (typeof val === \"string\") {\n if (val.endsWith(\"s\")) return parseInt(val, 10);\n if (val.endsWith(\"m\")) return parseInt(val, 10) * 60;\n const n = Number(val);\n return isNaN(n) ? undefined : n * 3600;\n }\n return undefined;\n }\n }\n return undefined;\n}\n\nfunction formatTtl(seconds: number): string {\n if (seconds < 60) return `${seconds}s`;\n if (seconds < 3600) return `${Math.round(seconds / 60)}m`;\n return `${Math.round(seconds / 3600)}h`;\n}\n\n/**\n * Wraps an SDK call with Redis caching.\n *\n * @param prefix - Redis key prefix (e.g. \"mysite:\")\n * @param methodPath - Dot-separated SDK method path (used as cache key)\n * @param method - The SDK method to call\n * @param args - Arguments to pass to the SDK method. If any argument\n * contains an `edgeCache` property, the result is cached in Redis for\n * that duration. Without `edgeCache`, the call bypasses cache.\n *\n * Accepted `edgeCache` values (matching augur-api CacheParams):\n * - Numbers: 1–8 (hours)\n * - Sub-hour strings: '30s', '1m', '5m'\n *\n * @example\n * ```ts\n * const result = await cachedSdkCall(\n * \"mysite:\",\n * \"items.categories.get\",\n * augurServices.items.categories.get,\n * itemCategoryUid,\n * { edgeCache: 1 },\n * );\n * ```\n */\n// Strict overload (preferred when types match)\nexport async function cachedSdkCall<TArgs extends unknown[], TResult>(\n prefix: string,\n methodPath: string,\n method: (...args: TArgs) => Promise<TResult>,\n ...args: TArgs\n): Promise<TResult>;\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// Relaxed overload for SDK methods whose types don't include edgeCache params\nexport async function cachedSdkCall(\n prefix: string,\n methodPath: string,\n method: (...args: any[]) => Promise<any>,\n ...args: any[]\n): Promise<any>;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n// Implementation\nexport async function cachedSdkCall<TArgs extends unknown[], TResult>(\n prefix: string,\n methodPath: string,\n method: (...args: TArgs) => Promise<TResult>,\n ...args: TArgs\n): Promise<TResult> {\n const ttlSeconds = extractTtlSeconds(args);\n\n if (!CACHE_ENABLED || ttlSeconds === undefined) {\n if (debugEnabled) {\n console.log(`[SDK Cache] SKIP ${methodPath} (no edgeCache, REALTIME)`);\n }\n pushRecent({ op: \"SKIP\", key: methodPath, ms: 0, ts: Date.now() });\n return method(...args);\n }\n\n const argsHash = hashArgs(args);\n const cacheKey = `${prefix}sdk:${methodPath}:${argsHash}`;\n const start = Date.now();\n const stats = getOrCreateStats(methodPath);\n\n try {\n const cached = await cacheGet(cacheKey);\n if (cached !== null) {\n const parsed = JSON.parse(cached);\n const ms = Date.now() - start;\n stats.hits++;\n stats.totalMs += ms;\n if (debugEnabled) {\n console.log(`[SDK Cache] HIT ${methodPath}:${argsHash} (${ms}ms)`);\n }\n pushRecent({\n op: \"HIT\",\n key: `${methodPath}:${argsHash}`,\n ms,\n ts: Date.now(),\n });\n return parsed as TResult;\n }\n } catch {\n stats.errors++;\n }\n\n const result = await method(...args);\n const ms = Date.now() - start;\n stats.misses++;\n stats.totalMs += ms;\n\n if (debugEnabled) {\n console.log(\n `[SDK Cache] MISS ${methodPath}:${argsHash} (${ms}ms -> cached, TTL ${formatTtl(ttlSeconds)})`,\n );\n }\n pushRecent({\n op: \"MISS\",\n key: `${methodPath}:${argsHash}`,\n ms,\n ts: Date.now(),\n });\n\n try {\n const serialized = JSON.stringify(result);\n cacheSet(cacheKey, serialized, ttlSeconds).catch(() => {\n /* swallow */\n });\n } catch {\n // Non-serializable result -- skip caching\n }\n\n return result;\n}\n\nfunction formatAgo(ms: number): string {\n if (ms < 1000) return \"<1s\";\n const s = Math.floor(ms / 1000);\n if (s < 60) return `${s}s ago`;\n const m = Math.floor(s / 60);\n return `${m}m ago`;\n}\n\n/** Returns aggregated cache stats for monitoring endpoints. */\nexport function getCacheStats() {\n let totalHits = 0;\n let totalMisses = 0;\n let totalErrors = 0;\n\n const topKeys: {\n key: string;\n hits: number;\n misses: number;\n avgMs: number;\n }[] = [];\n\n statsMap.forEach((s, key) => {\n totalHits += s.hits;\n totalMisses += s.misses;\n totalErrors += s.errors;\n const total = s.hits + s.misses;\n topKeys.push({\n key,\n hits: s.hits,\n misses: s.misses,\n avgMs: total > 0 ? Math.round(s.totalMs / total) : 0,\n });\n });\n\n topKeys.sort((a, b) => b.hits - a.hits);\n\n const total = totalHits + totalMisses;\n const hitRate =\n total > 0 ? ((totalHits / total) * 100).toFixed(1) + \"%\" : \"0%\";\n\n const now = Date.now();\n const recent = recentOps\n .slice(-20)\n .reverse()\n .map((op) => ({\n op: op.op,\n key: op.key,\n ms: op.ms,\n ago: formatAgo(now - op.ts),\n }));\n\n return {\n stats: { hits: totalHits, misses: totalMisses, errors: totalErrors, hitRate },\n topKeys: topKeys.slice(0, 15),\n recentOps: recent,\n };\n}\n","/**\n * Calls an Augur SDK method, forwarding all arguments with full type safety.\n *\n * With augur-api >= 0.9.6, SDK methods properly declare their `CacheParams`\n * option (including `edgeCache`), so this wrapper preserves both parameter\n * and return-type inference end-to-end.\n *\n * @example\n * ```ts\n * const result = await sdkCall(\n * augurServices.items.invMast.get,\n * invMastUid,\n * { edgeCache: 4 },\n * );\n * ```\n */\nexport async function sdkCall<TArgs extends unknown[], TResult>(\n method: (...args: TArgs) => Promise<TResult>,\n ...args: TArgs\n): Promise<TResult> {\n return method(...args);\n}\n","import { cache } from \"react\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { CACHE_CONFIG } from \"@simpleapps-com/augur-utils\";\n\n/**\n * Creates a server-side query client optimised for prefetching.\n *\n * - No persistence (server-only)\n * - Longer cache times for prefetched data\n * - No retries (fail fast on server)\n * - No refetching (server renders are one-shot)\n */\nexport function createServerQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: CACHE_CONFIG.STATIC.staleTime,\n gcTime: CACHE_CONFIG.STATIC.staleTime,\n retry: 0,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n },\n },\n });\n}\n\n/**\n * Returns a per-request singleton QueryClient for React Server Components.\n *\n * React's `cache()` deduplicates calls within a single server request,\n * so each request gets its own QueryClient while avoiding the cross-request\n * state leakage that a module-level singleton would cause.\n */\nexport const getServerQueryClient = cache(\n (): QueryClient => createServerQueryClient(),\n);\n"],"mappings":";;;;;;;;;AAQA,SAAS,iBAA2D;AAClE,QAAM,gBAAgB,QAAQ,IAAI;AAClC,MAAI,kBAAkB,MAAO,QAAO;AACpC,MAAI,kBAAkB,OAAQ,QAAO;AAErC,MAAI,OAAO,WAAW,aAAa;AACjC,QAAI,QAAQ,IAAI,aAAa,cAAe,QAAO;AACnD,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,OAAO,SAAS;AAC7B,MAAI,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,WAAW;AACzD,WAAO;AACT,MAAI,KAAK,SAAS,iBAAiB,EAAG,QAAO;AAC7C,SAAO;AACT;AAEO,IAAM,MAAM,eAAe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O,EAAE,IAAI;AAEtC,QAAM,QAAQ,YAAY;AAC1B,QAAM,UACJ,QAAQ,KAAM,YAAY,QAAS,KAAK,QAAQ,CAAC,IAAI,MAAM;AAE7D,QAAM,MAAM,KAAK,IAAI;AACrB,QAAM,SAAS,UACZ,MAAM,GAAG,EACT,QAAQ,EACR,IAAI,CAAC,QAAQ;AAAA,IACZ,IAAI,GAAG;AAAA,IACP,KAAK,GAAG;AAAA,IACR,IAAI,GAAG;AAAA,IACP,KAAK,UAAU,MAAM,GAAG,EAAE;AAAA,EAC5B,EAAE;AAEJ,SAAO;AAAA,IACL,OAAO,EAAE,MAAM,WAAW,QAAQ,aAAa,QAAQ,aAAa,QAAQ;AAAA,IAC5E,SAAS,QAAQ,MAAM,GAAG,EAAE;AAAA,IAC5B,WAAW;AAAA,EACb;AACF;;;ACjQA,eAAsB,QACpB,WACG,MACe;AAClB,SAAO,OAAO,GAAG,IAAI;AACvB;;;ACrBA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAUtB,SAAS,0BAAuC;AACrD,SAAO,IAAI,YAAY;AAAA,IACrB,gBAAgB;AAAA,MACd,SAAS;AAAA,QACP,WAAW,aAAa,OAAO;AAAA,QAC/B,QAAQ,aAAa,OAAO;AAAA,QAC5B,OAAO;AAAA,QACP,gBAAgB;AAAA,QAChB,sBAAsB;AAAA,QACtB,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AASO,IAAM,uBAAuB;AAAA,EAClC,MAAmB,wBAAwB;AAC7C;","names":["debugEnabled","g","ms","total"]}
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UseQueryOptions, UseSuspenseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
|
|
3
|
+
interface QueryOptionsConfig<TParams, TData> {
|
|
4
|
+
/** Base query key (e.g., "customer-orders") */
|
|
5
|
+
baseKey: string;
|
|
6
|
+
/** Parameters object */
|
|
7
|
+
params: TParams;
|
|
8
|
+
/** Function that returns the data */
|
|
9
|
+
queryFn: (params: TParams) => Promise<TData>;
|
|
10
|
+
/** Function to determine if query should be enabled */
|
|
11
|
+
enabledFn?: (params: TParams) => boolean;
|
|
12
|
+
/** Custom stale time in milliseconds (default: SEMI_STATIC) */
|
|
13
|
+
staleTime?: number;
|
|
14
|
+
/** Custom garbage collection time in milliseconds (default: SEMI_STATIC) */
|
|
15
|
+
gcTime?: number;
|
|
16
|
+
/** Key to exclude from query key generation */
|
|
17
|
+
excludeFromKey?: keyof TParams;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates useQuery options with consistent key generation.
|
|
21
|
+
* Filters out undefined/null/empty params from the query key.
|
|
22
|
+
*/
|
|
23
|
+
declare const createQueryOptions: <TParams extends Record<string, unknown>, TData>({ baseKey, params, queryFn, enabledFn, staleTime, gcTime, excludeFromKey, }: QueryOptionsConfig<TParams, TData>) => UseQueryOptions<TData>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates useSuspenseQuery options with consistent key generation.
|
|
26
|
+
* Same as createQueryOptions but without enabledFn (suspense queries
|
|
27
|
+
* cannot be disabled).
|
|
28
|
+
*/
|
|
29
|
+
declare const createSuspenseQueryOptions: <TParams extends Record<string, unknown>, TData>({ baseKey, params, queryFn, staleTime, gcTime, excludeFromKey, }: Omit<QueryOptionsConfig<TParams, TData>, "enabledFn">) => UseSuspenseQueryOptions<TData>;
|
|
30
|
+
|
|
31
|
+
export { type QueryOptionsConfig, createQueryOptions, createSuspenseQueryOptions };
|
package/dist/query.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/next-auth.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @simpleapps-com/augur-server/next-auth
|
|
2
|
+
// NextAuth 5 module augmentation for Augur ecommerce sites.
|
|
3
|
+
//
|
|
4
|
+
// Usage in consumer sites:
|
|
5
|
+
// /// <reference types="@simpleapps-com/augur-server/next-auth" />
|
|
6
|
+
//
|
|
7
|
+
// Or add to tsconfig.json:
|
|
8
|
+
// { "compilerOptions": { "types": ["@simpleapps-com/augur-server/next-auth"] } }
|
|
9
|
+
|
|
10
|
+
import type { DefaultSession, DefaultUser } from "next-auth";
|
|
11
|
+
import type { DefaultJWT } from "next-auth/jwt";
|
|
12
|
+
|
|
13
|
+
declare module "next-auth" {
|
|
14
|
+
interface User extends DefaultUser {
|
|
15
|
+
id: string;
|
|
16
|
+
username: string;
|
|
17
|
+
isVerified: boolean;
|
|
18
|
+
name?: string;
|
|
19
|
+
email?: string;
|
|
20
|
+
customerId?: string | number;
|
|
21
|
+
contactId?: string | number;
|
|
22
|
+
cartHdrUid?: number;
|
|
23
|
+
token?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Session {
|
|
27
|
+
user: {
|
|
28
|
+
id: string;
|
|
29
|
+
username: string;
|
|
30
|
+
isVerified: boolean;
|
|
31
|
+
name?: string;
|
|
32
|
+
email?: string;
|
|
33
|
+
customerId?: string | number;
|
|
34
|
+
contactId?: string | number;
|
|
35
|
+
cartHdrUid?: number;
|
|
36
|
+
token?: string;
|
|
37
|
+
} & DefaultSession["user"];
|
|
38
|
+
token?: string;
|
|
39
|
+
expires: string;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare module "next-auth/jwt" {
|
|
44
|
+
interface JWT extends DefaultJWT {
|
|
45
|
+
id?: string;
|
|
46
|
+
username?: string;
|
|
47
|
+
isVerified?: boolean;
|
|
48
|
+
token?: string;
|
|
49
|
+
}
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simpleapps-com/augur-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Server-side utilities for Augur ecommerce sites (Redis caching, SDK helpers, auth)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,15 +17,23 @@
|
|
|
17
17
|
"./auth": {
|
|
18
18
|
"types": "./dist/auth.d.ts",
|
|
19
19
|
"import": "./dist/auth.js"
|
|
20
|
+
},
|
|
21
|
+
"./query": {
|
|
22
|
+
"types": "./dist/query.d.ts",
|
|
23
|
+
"import": "./dist/query.js"
|
|
24
|
+
},
|
|
25
|
+
"./next-auth": {
|
|
26
|
+
"types": "./next-auth.d.ts"
|
|
20
27
|
}
|
|
21
28
|
},
|
|
22
29
|
"sideEffects": false,
|
|
23
30
|
"files": [
|
|
24
|
-
"dist"
|
|
31
|
+
"dist",
|
|
32
|
+
"next-auth.d.ts"
|
|
25
33
|
],
|
|
26
34
|
"dependencies": {
|
|
27
35
|
"valibot": "^1.0.0",
|
|
28
|
-
"@simpleapps-com/augur-utils": "0.1.
|
|
36
|
+
"@simpleapps-com/augur-utils": "0.1.9"
|
|
29
37
|
},
|
|
30
38
|
"peerDependencies": {
|
|
31
39
|
"@simpleapps-com/augur-api": "^0.9.6",
|
|
@@ -46,6 +54,7 @@
|
|
|
46
54
|
"devDependencies": {
|
|
47
55
|
"@tanstack/react-query": "^5.80.0",
|
|
48
56
|
"@types/node": "^22.0.0",
|
|
57
|
+
"@types/react": "^19.0.0",
|
|
49
58
|
"@vitest/coverage-v8": "^3.2.4",
|
|
50
59
|
"ioredis": "^5.9.0",
|
|
51
60
|
"react": "^19.0.0",
|