@simpleapps-com/augur-core 1.0.0
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/index.cjs +205 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +298 -0
- package/dist/index.d.ts +298 -0
- package/dist/index.js +205 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.cjs +6 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +1 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +6 -0
- package/dist/testing.js.map +1 -0
- package/package.json +47 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/classification.ts
|
|
2
|
+
var READ_METHODS = /* @__PURE__ */ new Set(["get", "list", "lookup", "search", "suggest"]);
|
|
3
|
+
function isReadMethod(methodName) {
|
|
4
|
+
return READ_METHODS.has(methodName);
|
|
5
|
+
}
|
|
6
|
+
function isWriteMethod(methodName) {
|
|
7
|
+
return !READ_METHODS.has(methodName);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/cache.ts
|
|
11
|
+
var DEFAULT_CACHE_TIERS = {
|
|
12
|
+
static: {
|
|
13
|
+
staleTime: 60 * 60 * 1e3,
|
|
14
|
+
// 60 min
|
|
15
|
+
gcTime: 2 * 60 * 60 * 1e3,
|
|
16
|
+
// 120 min
|
|
17
|
+
edgeCache: 8,
|
|
18
|
+
redisTtl: 28800
|
|
19
|
+
// 8 hours
|
|
20
|
+
},
|
|
21
|
+
semiStatic: {
|
|
22
|
+
staleTime: 60 * 1e3,
|
|
23
|
+
// 1 min
|
|
24
|
+
gcTime: 5 * 60 * 1e3,
|
|
25
|
+
// 5 min
|
|
26
|
+
edgeCache: 1,
|
|
27
|
+
redisTtl: 3600
|
|
28
|
+
// 1 hour
|
|
29
|
+
},
|
|
30
|
+
none: {
|
|
31
|
+
staleTime: 0,
|
|
32
|
+
gcTime: 0
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var STATIC_PATHS = [
|
|
36
|
+
"agrSite.settings",
|
|
37
|
+
"agrSite.metaFiles",
|
|
38
|
+
"agrSite.geoCodesPostalCodes",
|
|
39
|
+
"items.categories",
|
|
40
|
+
"items.itemCategory",
|
|
41
|
+
"items.brands",
|
|
42
|
+
"items.attributeGroups",
|
|
43
|
+
"items.attributes",
|
|
44
|
+
"p21Core.company",
|
|
45
|
+
"p21Core.location",
|
|
46
|
+
"p21Core.paymentTypes",
|
|
47
|
+
"p21Core.codeP21",
|
|
48
|
+
"p21Core.cashDrawer",
|
|
49
|
+
"joomla.menu",
|
|
50
|
+
"joomla.tags",
|
|
51
|
+
"joomla.userGroups",
|
|
52
|
+
"legacy.state"
|
|
53
|
+
];
|
|
54
|
+
var NO_CACHE_PATHS = ["commerce"];
|
|
55
|
+
function getCacheTier(methodPath, overrides) {
|
|
56
|
+
if (NO_CACHE_PATHS.some((p) => methodPath.startsWith(p))) {
|
|
57
|
+
return DEFAULT_CACHE_TIERS.none;
|
|
58
|
+
}
|
|
59
|
+
if (STATIC_PATHS.some((p) => methodPath.startsWith(p))) {
|
|
60
|
+
const base2 = DEFAULT_CACHE_TIERS.static;
|
|
61
|
+
const tier2 = _optionalChain([overrides, 'optionalAccess', _ => _.static]);
|
|
62
|
+
if (!tier2) return base2;
|
|
63
|
+
return {
|
|
64
|
+
staleTime: _nullishCoalesce(tier2.staleTime, () => ( base2.staleTime)),
|
|
65
|
+
gcTime: _nullishCoalesce(tier2.gcTime, () => ( base2.gcTime)),
|
|
66
|
+
edgeCache: _nullishCoalesce(tier2.edgeCache, () => ( base2.edgeCache)),
|
|
67
|
+
redisTtl: _nullishCoalesce(tier2.redis, () => ( base2.redisTtl))
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const base = DEFAULT_CACHE_TIERS.semiStatic;
|
|
71
|
+
const tier = _optionalChain([overrides, 'optionalAccess', _2 => _2.semiStatic]);
|
|
72
|
+
if (!tier) return base;
|
|
73
|
+
return {
|
|
74
|
+
staleTime: _nullishCoalesce(tier.staleTime, () => ( base.staleTime)),
|
|
75
|
+
gcTime: _nullishCoalesce(tier.gcTime, () => ( base.gcTime)),
|
|
76
|
+
edgeCache: _nullishCoalesce(tier.edgeCache, () => ( base.edgeCache)),
|
|
77
|
+
redisTtl: _nullishCoalesce(tier.redis, () => ( base.redisTtl))
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/keys.ts
|
|
82
|
+
function stableStringify(value) {
|
|
83
|
+
if (value === null || value === void 0) return JSON.stringify(value);
|
|
84
|
+
if (typeof value !== "object") return JSON.stringify(value);
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
return `[${value.map(stableStringify).join(",")}]`;
|
|
87
|
+
}
|
|
88
|
+
const obj = value;
|
|
89
|
+
const keys = Object.keys(obj).sort();
|
|
90
|
+
const entries = keys.map(
|
|
91
|
+
(key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`
|
|
92
|
+
);
|
|
93
|
+
return `{${entries.join(",")}}`;
|
|
94
|
+
}
|
|
95
|
+
function fnv1a(str) {
|
|
96
|
+
let h = 2166136261;
|
|
97
|
+
for (let i = 0; i < str.length; i++) {
|
|
98
|
+
h ^= str.charCodeAt(i);
|
|
99
|
+
h = Math.imul(h, 16777619);
|
|
100
|
+
}
|
|
101
|
+
return (h >>> 0).toString(16).padStart(8, "0");
|
|
102
|
+
}
|
|
103
|
+
function buildQueryKey(path, args) {
|
|
104
|
+
return [...path, ...args];
|
|
105
|
+
}
|
|
106
|
+
function buildCacheKey(prefix, methodPath, args) {
|
|
107
|
+
return `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(args))}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/utils.ts
|
|
111
|
+
function resolveMethod(obj, path) {
|
|
112
|
+
let current = obj;
|
|
113
|
+
for (const segment of path) {
|
|
114
|
+
if (current == null || typeof current !== "object") {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`Cannot resolve method path "${path.join(".")}": "${segment}" is not accessible on ${typeof current}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
current = current[segment];
|
|
120
|
+
}
|
|
121
|
+
if (typeof current !== "function") {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`Method path "${path.join(".")}" does not resolve to a function (got ${typeof current})`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return current;
|
|
127
|
+
}
|
|
128
|
+
function stableArgs(args) {
|
|
129
|
+
return args.map((arg) => {
|
|
130
|
+
if (arg === null || arg === void 0 || typeof arg !== "object") return arg;
|
|
131
|
+
if (Array.isArray(arg)) return arg;
|
|
132
|
+
const obj = arg;
|
|
133
|
+
const filtered = {};
|
|
134
|
+
for (const key of Object.keys(obj).sort()) {
|
|
135
|
+
if (obj[key] !== void 0) {
|
|
136
|
+
filtered[key] = obj[key];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return filtered;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/proxy.ts
|
|
144
|
+
function createDeepProxy(handler, path = []) {
|
|
145
|
+
const callable = function() {
|
|
146
|
+
};
|
|
147
|
+
return new Proxy(callable, {
|
|
148
|
+
get(_target, prop) {
|
|
149
|
+
if (typeof prop === "symbol") return void 0;
|
|
150
|
+
return createDeepProxy(handler, [...path, prop]);
|
|
151
|
+
},
|
|
152
|
+
apply(_target, _thisArg, args) {
|
|
153
|
+
return handler(path, args);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function createOptionsProxy(api, config) {
|
|
158
|
+
return createDeepProxy(
|
|
159
|
+
(path, args) => {
|
|
160
|
+
const methodName = path[path.length - 1];
|
|
161
|
+
const methodPath = path.join(".");
|
|
162
|
+
const sdkMethod = resolveMethod(api, path);
|
|
163
|
+
const normalizedArgs = stableArgs(args);
|
|
164
|
+
if (isReadMethod(methodName)) {
|
|
165
|
+
const tier = getCacheTier(methodPath, _optionalChain([config, 'optionalAccess', _3 => _3.cache]));
|
|
166
|
+
return {
|
|
167
|
+
queryKey: buildQueryKey(path, normalizedArgs),
|
|
168
|
+
queryFn: () => sdkMethod(...args),
|
|
169
|
+
staleTime: tier.staleTime,
|
|
170
|
+
gcTime: tier.gcTime
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
mutationKey: path,
|
|
175
|
+
mutationFn: (...mutationArgs) => sdkMethod(...mutationArgs)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
function createActionsProxy(api, config) {
|
|
181
|
+
return createDeepProxy(async (path, args) => {
|
|
182
|
+
const methodPath = path.join(".");
|
|
183
|
+
const sdkMethod = resolveMethod(api, path);
|
|
184
|
+
const transform = _optionalChain([config, 'optionalAccess', _4 => _4.transforms, 'optionalAccess', _5 => _5[methodPath]]);
|
|
185
|
+
const finalArgs = _optionalChain([transform, 'optionalAccess', _6 => _6.pre]) ? transform.pre(args) : args;
|
|
186
|
+
const result = await sdkMethod(...finalArgs);
|
|
187
|
+
return _optionalChain([transform, 'optionalAccess', _7 => _7.post]) ? transform.post(result) : result;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
exports.DEFAULT_CACHE_TIERS = DEFAULT_CACHE_TIERS; exports.buildCacheKey = buildCacheKey; exports.buildQueryKey = buildQueryKey; exports.createActionsProxy = createActionsProxy; exports.createDeepProxy = createDeepProxy; exports.createOptionsProxy = createOptionsProxy; exports.fnv1a = fnv1a; exports.getCacheTier = getCacheTier; exports.isReadMethod = isReadMethod; exports.isWriteMethod = isWriteMethod; exports.resolveMethod = resolveMethod; exports.stableArgs = stableArgs; exports.stableStringify = stableStringify;
|
|
205
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-core/dist/index.cjs","../src/classification.ts","../src/cache.ts","../src/keys.ts","../src/utils.ts","../src/proxy.ts"],"names":["base","tier"],"mappings":"AAAA;ACOA,IAAM,aAAA,kBAAe,IAAI,GAAA,CAAI,CAAC,KAAA,EAAO,MAAA,EAAQ,QAAA,EAAU,QAAA,EAAU,SAAS,CAAC,CAAA;AAOpE,SAAS,YAAA,CAAa,UAAA,EAA6B;AACxD,EAAA,OAAO,YAAA,CAAa,GAAA,CAAI,UAAU,CAAA;AACpC;AAOO,SAAS,aAAA,CAAc,UAAA,EAA6B;AACzD,EAAA,OAAO,CAAC,YAAA,CAAa,GAAA,CAAI,UAAU,CAAA;AACrC;ADjBA;AACA;AEeO,IAAM,oBAAA,EAAyC;AAAA,EACpD,MAAA,EAAQ;AAAA,IACN,SAAA,EAAW,GAAA,EAAK,GAAA,EAAK,GAAA;AAAA;AAAA,IACrB,MAAA,EAAQ,EAAA,EAAI,GAAA,EAAK,GAAA,EAAK,GAAA;AAAA;AAAA,IACtB,SAAA,EAAW,CAAA;AAAA,IACX,QAAA,EAAU;AAAA;AAAA,EACZ,CAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,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;AACA","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-core/dist/index.cjs","sourcesContent":[null,"/**\n * Method classification — determines whether an SDK method is a read (GET)\n * or write (POST/PUT/DELETE) based on its leaf method name.\n *\n * Read methods produce UseQueryOptions; write methods produce UseMutationOptions.\n */\n\nconst READ_METHODS = new Set([\"get\", \"list\", \"lookup\", \"search\", \"suggest\"]);\n\n/**\n * Returns true if the leaf method name represents a read (GET) operation.\n *\n * Read methods: get, list, lookup, search, suggest\n */\nexport function isReadMethod(methodName: string): boolean {\n return READ_METHODS.has(methodName);\n}\n\n/**\n * Returns true if the leaf method name represents a write (POST/PUT/DELETE) operation.\n *\n * Write methods: create, update, delete, enable, and anything not in the read set.\n */\nexport function isWriteMethod(methodName: string): boolean {\n return !READ_METHODS.has(methodName);\n}\n","/**\n * Cache tier resolution — maps SDK method paths to cache tiers.\n *\n * The same tiers apply on client (staleTime/gcTime) and server (edgeCache/redisTtl).\n */\n\nimport type { CacheTierConfig } from \"./shared-types\";\n\n/** Internal resolved cache tier with all timing values. */\nexport interface ResolvedCacheTier {\n staleTime: number;\n gcTime: number;\n edgeCache?: number | string;\n redisTtl?: number;\n}\n\n/** Cache tier configuration with defaults for all tiers. */\nexport interface CacheTierDefaults {\n static: ResolvedCacheTier;\n semiStatic: ResolvedCacheTier;\n none: ResolvedCacheTier;\n}\n\n/** Default cache tier values. */\nexport const DEFAULT_CACHE_TIERS: CacheTierDefaults = {\n static: {\n staleTime: 60 * 60 * 1000, // 60 min\n gcTime: 2 * 60 * 60 * 1000, // 120 min\n edgeCache: 8,\n redisTtl: 28800, // 8 hours\n },\n semiStatic: {\n staleTime: 60 * 1000, // 1 min\n gcTime: 5 * 60 * 1000, // 5 min\n edgeCache: 1,\n redisTtl: 3600, // 1 hour\n },\n none: {\n staleTime: 0,\n gcTime: 0,\n },\n};\n\n/** Paths that should use the static cache tier. */\nconst STATIC_PATHS = [\n \"agrSite.settings\",\n \"agrSite.metaFiles\",\n \"agrSite.geoCodesPostalCodes\",\n \"items.categories\",\n \"items.itemCategory\",\n \"items.brands\",\n \"items.attributeGroups\",\n \"items.attributes\",\n \"p21Core.company\",\n \"p21Core.location\",\n \"p21Core.paymentTypes\",\n \"p21Core.codeP21\",\n \"p21Core.cashDrawer\",\n \"joomla.menu\",\n \"joomla.tags\",\n \"joomla.userGroups\",\n \"legacy.state\",\n];\n\n/** Paths that should not be cached. */\nconst NO_CACHE_PATHS = [\"commerce\"];\n\n/**\n * Resolves the cache tier for a given SDK method path.\n *\n * @param methodPath Dot-separated SDK method path (e.g. \"items.invMast.stock.get\")\n * @param overrides Optional per-tier overrides from consumer config\n * @returns Resolved cache tier with timing values\n *\n * @example\n * getCacheTier(\"items.categories.list\") → static (60 min stale)\n * getCacheTier(\"pricing.priceEngine.get\") → semiStatic (1 min stale)\n * getCacheTier(\"commerce.cartLine.add.create\") → none (0 stale)\n */\nexport function getCacheTier(\n methodPath: string,\n overrides?: { static?: CacheTierConfig; semiStatic?: CacheTierConfig },\n): ResolvedCacheTier {\n if (NO_CACHE_PATHS.some((p) => methodPath.startsWith(p))) {\n return DEFAULT_CACHE_TIERS.none;\n }\n\n if (STATIC_PATHS.some((p) => methodPath.startsWith(p))) {\n const base = DEFAULT_CACHE_TIERS.static;\n const tier = overrides?.static;\n if (!tier) return base;\n return {\n staleTime: tier.staleTime ?? base.staleTime,\n gcTime: tier.gcTime ?? base.gcTime,\n edgeCache: tier.edgeCache ?? base.edgeCache,\n redisTtl: tier.redis ?? base.redisTtl,\n };\n }\n\n // Default: semiStatic\n const base = DEFAULT_CACHE_TIERS.semiStatic;\n const tier = overrides?.semiStatic;\n if (!tier) return base;\n return {\n staleTime: tier.staleTime ?? base.staleTime,\n gcTime: tier.gcTime ?? base.gcTime,\n edgeCache: tier.edgeCache ?? base.edgeCache,\n redisTtl: tier.redis ?? base.redisTtl,\n };\n}\n","/**\n * Deterministic key generation utilities.\n *\n * stableStringify and fnv1a are the single source of truth —\n * augur-hooks and augur-server both import from here so cache keys\n * are guaranteed identical across client and server.\n */\n\n/**\n * JSON.stringify with sorted object keys for deterministic cache keys.\n * Ensures { a: 1, b: 2 } and { b: 2, a: 1 } produce the same string.\n */\nexport function stableStringify(value: unknown): string {\n if (value === null || value === undefined) return JSON.stringify(value);\n if (typeof value !== \"object\") return JSON.stringify(value);\n if (Array.isArray(value)) {\n return `[${value.map(stableStringify).join(\",\")}]`;\n }\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj).sort();\n const entries = keys.map(\n (key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`,\n );\n return `{${entries.join(\",\")}}`;\n}\n\n/**\n * FNV-1a 32-bit hash. Fast non-cryptographic hash for cache keys.\n * Returns an 8-character zero-padded hex string.\n */\nexport function fnv1a(str: string): string {\n let h = 0x811c9dc5;\n for (let i = 0; i < str.length; i++) {\n h ^= str.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0).toString(16).padStart(8, \"0\");\n}\n\n/**\n * Builds a deterministic query key from a method path and arguments.\n *\n * @example\n * buildQueryKey([\"items\", \"invMast\", \"get\"], [42])\n * → [\"items\", \"invMast\", \"get\", 42]\n *\n * buildQueryKey([\"pricing\", \"priceEngine\", \"get\"], [{ itemId: \"X\", customerId: 1 }])\n * → [\"pricing\", \"priceEngine\", \"get\", { itemId: \"X\", customerId: 1 }]\n */\nexport function buildQueryKey(path: string[], args: unknown[]): unknown[] {\n return [...path, ...args];\n}\n\n/**\n * Builds a deterministic cache key for Redis/CDN caching.\n *\n * Format: `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(args))}`\n *\n * @example\n * buildCacheKey(\"ampro:\", \"pricing.priceEngine.get\", [{ itemId: \"X\" }])\n * → \"ampro:sdk:pricing.priceEngine.get:a1b2c3d4\"\n */\nexport function buildCacheKey(\n prefix: string,\n methodPath: string,\n args: unknown[],\n): string {\n return `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(args))}`;\n}\n","/**\n * Utility functions for the proxy infrastructure.\n */\n\n/**\n * Walk an object by path array to find the leaf function.\n *\n * @example\n * resolveMethod(api, [\"items\", \"invMast\", \"stock\", \"get\"])\n * → api.items.invMast.stock.get\n */\nexport function resolveMethod(\n obj: unknown,\n path: string[],\n): (...args: unknown[]) => unknown {\n let current: unknown = obj;\n for (const segment of path) {\n if (current == null || typeof current !== \"object\") {\n throw new Error(\n `Cannot resolve method path \"${path.join(\".\")}\": ` +\n `\"${segment}\" is not accessible on ${typeof current}`,\n );\n }\n current = (current as Record<string, unknown>)[segment];\n }\n if (typeof current !== \"function\") {\n throw new Error(\n `Method path \"${path.join(\".\")}\" does not resolve to a function ` +\n `(got ${typeof current})`,\n );\n }\n return current as (...args: unknown[]) => unknown;\n}\n\n/**\n * Normalize arguments for deterministic cache/query keys.\n * Filters out undefined values from argument objects.\n */\nexport function stableArgs(args: unknown[]): unknown[] {\n return args.map((arg) => {\n if (arg === null || arg === undefined || typeof arg !== \"object\") return arg;\n if (Array.isArray(arg)) return arg;\n const obj = arg as Record<string, unknown>;\n const filtered: Record<string, unknown> = {};\n for (const key of Object.keys(obj).sort()) {\n if (obj[key] !== undefined) {\n filtered[key] = obj[key];\n }\n }\n return filtered;\n });\n}\n","/**\n * Deep proxy factories — runtime SDK namespace mirroring.\n *\n * The same Proxy pattern that powers `createMockClient()` in the SDK\n * powers every downstream consumer. One proxy shape, multiple behaviors\n * via the handler callback.\n */\n\nimport { isReadMethod } from \"./classification\";\nimport { getCacheTier } from \"./cache\";\nimport type { CacheTierConfig } from \"./shared-types\";\nimport { buildQueryKey, buildCacheKey, stableStringify, fnv1a } from \"./keys\";\nimport { resolveMethod, stableArgs } from \"./utils\";\nimport type { ProxyQueryOptions, ProxyMutationOptions } from \"./types\";\n\n/** Configuration for the options proxy (hooks). */\nexport interface OptionsProxyConfig {\n /** Per-tier cache overrides. */\n cache?: {\n static?: CacheTierConfig;\n semiStatic?: CacheTierConfig;\n };\n}\n\n/** Configuration for the actions proxy (server). */\nexport interface ActionsProxyConfig {\n /** Cache key prefix (e.g. \"ampro:\"). */\n cachePrefix?: string;\n /** Per-tier cache overrides. */\n cache?: {\n static?: CacheTierConfig;\n semiStatic?: CacheTierConfig;\n };\n /** Pre/post transforms per method path. */\n transforms?: Record<\n string,\n {\n pre?: (args: unknown[]) => unknown[];\n post?: (result: unknown) => unknown;\n }\n >;\n}\n\n/**\n * Creates a deep proxy that intercepts property access to build a method\n * path, then calls the handler when the proxy is invoked as a function.\n *\n * This is the core mechanism. `createOptionsProxy` and `createActionsProxy`\n * are thin wrappers that provide different handlers.\n */\nexport function createDeepProxy<TResult>(\n handler: (path: string[], args: unknown[]) => TResult,\n path: string[] = [],\n): unknown {\n /* v8 ignore next -- placeholder body, only the Proxy traps execute */\n const callable = function () {};\n\n return new Proxy(callable, {\n get(_target, prop: string | symbol) {\n if (typeof prop === \"symbol\") return undefined;\n return createDeepProxy(handler, [...path, prop]);\n },\n apply(_target, _thisArg, args: unknown[]) {\n return handler(path, args);\n },\n });\n}\n\n/**\n * Creates a proxy that returns TanStack Query options for every SDK method.\n *\n * Read methods (get, list, lookup, search, suggest) return ProxyQueryOptions.\n * Write methods (create, update, delete, etc.) return ProxyMutationOptions.\n *\n * @param api The SDK client instance\n * @param config Optional cache configuration\n * @returns Proxy mirroring the SDK with query/mutation options at every leaf\n *\n * @example\n * const q = createOptionsProxy(api);\n * const opts = q.items.invMast.stock.get(42);\n * // opts.queryKey → [\"items\", \"invMast\", \"stock\", \"get\", 42]\n * // opts.queryFn → () => api.items.invMast.stock.get(42)\n * // opts.staleTime → 60000 (semiStatic default)\n */\nexport function createOptionsProxy<TApi extends object>(\n api: TApi,\n config?: OptionsProxyConfig,\n): unknown {\n return createDeepProxy(\n (\n path: string[],\n args: unknown[],\n ): ProxyQueryOptions<unknown> | ProxyMutationOptions<unknown, unknown[]> => {\n const methodName = path[path.length - 1]!;\n const methodPath = path.join(\".\");\n const sdkMethod = resolveMethod(api, path);\n const normalizedArgs = stableArgs(args);\n\n if (isReadMethod(methodName)) {\n const tier = getCacheTier(methodPath, config?.cache);\n return {\n queryKey: buildQueryKey(path, normalizedArgs),\n queryFn: () => sdkMethod(...args) as Promise<unknown>,\n staleTime: tier.staleTime,\n gcTime: tier.gcTime,\n };\n }\n\n return {\n mutationKey: path,\n mutationFn: (...mutationArgs: unknown[]) =>\n sdkMethod(...mutationArgs) as Promise<unknown>,\n };\n },\n );\n}\n\n/**\n * Creates a proxy that wraps every SDK method as a direct async action.\n *\n * For read methods, the result is cached using the cache key builder.\n * For write methods, the call passes through directly.\n *\n * @param api The SDK client instance\n * @param config Optional cache and transform configuration\n * @returns Proxy mirroring the SDK with cached/transformed actions at every leaf\n *\n * @example\n * const actions = createActionsProxy(api, { cachePrefix: \"ampro:\" });\n * const stock = await actions.items.invMast.stock.get(42);\n */\nexport function createActionsProxy<TApi extends object>(\n api: TApi,\n config?: ActionsProxyConfig,\n): unknown {\n return createDeepProxy(async (path: string[], args: unknown[]) => {\n const methodPath = path.join(\".\");\n const sdkMethod = resolveMethod(api, path);\n const transform = config?.transforms?.[methodPath];\n\n const finalArgs = transform?.pre ? transform.pre(args) : args;\n const result = await (sdkMethod(...finalArgs) as Promise<unknown>);\n return transform?.post ? transform.post(result) : result;\n });\n}\n\n// Re-export key utilities for consumers who need to build keys manually\nexport { buildQueryKey, buildCacheKey, stableStringify, fnv1a };\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { TProductItem } from '@simpleapps-com/augur-utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Valid CDN edge cache durations accepted by the augur-api SDK.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors `CacheParams['edgeCache']` from `@simpleapps-com/augur-api`.
|
|
7
|
+
*/
|
|
8
|
+
type EdgeCacheValue = "30s" | "1m" | "5m" | 1 | 2 | 3 | 4 | 5 | 8 | "1" | "2" | "3" | "4" | "5" | "8";
|
|
9
|
+
/**
|
|
10
|
+
* Auth context provided at the provider level.
|
|
11
|
+
* Auth-provider-agnostic — works with NextAuth, Clerk, Supabase Auth, etc.
|
|
12
|
+
*/
|
|
13
|
+
interface AugurAuthContext {
|
|
14
|
+
/** Auth loading state — hooks disable queries while "loading". */
|
|
15
|
+
status: "loading" | "authenticated" | "unauthenticated";
|
|
16
|
+
/** Customer ID for pricing. Falls back to env default if undefined. */
|
|
17
|
+
customerId?: string | number;
|
|
18
|
+
/** User ID for cart ownership. */
|
|
19
|
+
userId?: string | number;
|
|
20
|
+
/** Cart header UID from session (if available). */
|
|
21
|
+
cartHdrUid?: string | number;
|
|
22
|
+
}
|
|
23
|
+
/** Paginated response for infinite scroll hooks. */
|
|
24
|
+
interface InfiniteScrollPage {
|
|
25
|
+
data: TProductItem[];
|
|
26
|
+
total: number;
|
|
27
|
+
nextCursor?: number;
|
|
28
|
+
}
|
|
29
|
+
/** Cache provider for Redis-compatible storage. */
|
|
30
|
+
interface CacheProvider {
|
|
31
|
+
prefix: string;
|
|
32
|
+
get: (key: string) => Promise<string | null>;
|
|
33
|
+
set: (key: string, value: string, ttlSeconds: number) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** Cache settings for a single tier. */
|
|
36
|
+
interface CacheTierConfig {
|
|
37
|
+
/** CDN edge cache. Passed directly to SDK as edgeCache. Valid values: 1–8 (hours) or '30s', '1m', '5m'. */
|
|
38
|
+
edgeCache?: number | string;
|
|
39
|
+
/** Redis cache TTL in seconds. Requires provider. */
|
|
40
|
+
redis?: number;
|
|
41
|
+
/** React Query staleTime in ms. Overrides the built-in default. */
|
|
42
|
+
staleTime?: number;
|
|
43
|
+
/** React Query gcTime (garbage collection) in ms. Overrides the built-in default. */
|
|
44
|
+
gcTime?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Cache configuration. All fields optional, all off by default. */
|
|
47
|
+
interface CacheConfig {
|
|
48
|
+
/** Redis-compatible cache. Required for redis caching. */
|
|
49
|
+
provider?: CacheProvider;
|
|
50
|
+
/** TTLs for long-lived data (categories, item details, docs). */
|
|
51
|
+
static?: CacheTierConfig;
|
|
52
|
+
/** TTLs for frequently-changing data (prices, stock, search). */
|
|
53
|
+
semiStatic?: CacheTierConfig;
|
|
54
|
+
}
|
|
55
|
+
/** Discriminated union for safe action results. */
|
|
56
|
+
type ActionResult<T> = {
|
|
57
|
+
ok: true;
|
|
58
|
+
data: T;
|
|
59
|
+
} | {
|
|
60
|
+
ok: false;
|
|
61
|
+
error: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Deterministic key generation utilities.
|
|
66
|
+
*
|
|
67
|
+
* stableStringify and fnv1a are the single source of truth —
|
|
68
|
+
* augur-hooks and augur-server both import from here so cache keys
|
|
69
|
+
* are guaranteed identical across client and server.
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* JSON.stringify with sorted object keys for deterministic cache keys.
|
|
73
|
+
* Ensures { a: 1, b: 2 } and { b: 2, a: 1 } produce the same string.
|
|
74
|
+
*/
|
|
75
|
+
declare function stableStringify(value: unknown): string;
|
|
76
|
+
/**
|
|
77
|
+
* FNV-1a 32-bit hash. Fast non-cryptographic hash for cache keys.
|
|
78
|
+
* Returns an 8-character zero-padded hex string.
|
|
79
|
+
*/
|
|
80
|
+
declare function fnv1a(str: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Builds a deterministic query key from a method path and arguments.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* buildQueryKey(["items", "invMast", "get"], [42])
|
|
86
|
+
* → ["items", "invMast", "get", 42]
|
|
87
|
+
*
|
|
88
|
+
* buildQueryKey(["pricing", "priceEngine", "get"], [{ itemId: "X", customerId: 1 }])
|
|
89
|
+
* → ["pricing", "priceEngine", "get", { itemId: "X", customerId: 1 }]
|
|
90
|
+
*/
|
|
91
|
+
declare function buildQueryKey(path: string[], args: unknown[]): unknown[];
|
|
92
|
+
/**
|
|
93
|
+
* Builds a deterministic cache key for Redis/CDN caching.
|
|
94
|
+
*
|
|
95
|
+
* Format: `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(args))}`
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* buildCacheKey("ampro:", "pricing.priceEngine.get", [{ itemId: "X" }])
|
|
99
|
+
* → "ampro:sdk:pricing.priceEngine.get:a1b2c3d4"
|
|
100
|
+
*/
|
|
101
|
+
declare function buildCacheKey(prefix: string, methodPath: string, args: unknown[]): string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Deep proxy factories — runtime SDK namespace mirroring.
|
|
105
|
+
*
|
|
106
|
+
* The same Proxy pattern that powers `createMockClient()` in the SDK
|
|
107
|
+
* powers every downstream consumer. One proxy shape, multiple behaviors
|
|
108
|
+
* via the handler callback.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/** Configuration for the options proxy (hooks). */
|
|
112
|
+
interface OptionsProxyConfig {
|
|
113
|
+
/** Per-tier cache overrides. */
|
|
114
|
+
cache?: {
|
|
115
|
+
static?: CacheTierConfig;
|
|
116
|
+
semiStatic?: CacheTierConfig;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Configuration for the actions proxy (server). */
|
|
120
|
+
interface ActionsProxyConfig {
|
|
121
|
+
/** Cache key prefix (e.g. "ampro:"). */
|
|
122
|
+
cachePrefix?: string;
|
|
123
|
+
/** Per-tier cache overrides. */
|
|
124
|
+
cache?: {
|
|
125
|
+
static?: CacheTierConfig;
|
|
126
|
+
semiStatic?: CacheTierConfig;
|
|
127
|
+
};
|
|
128
|
+
/** Pre/post transforms per method path. */
|
|
129
|
+
transforms?: Record<string, {
|
|
130
|
+
pre?: (args: unknown[]) => unknown[];
|
|
131
|
+
post?: (result: unknown) => unknown;
|
|
132
|
+
}>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Creates a deep proxy that intercepts property access to build a method
|
|
136
|
+
* path, then calls the handler when the proxy is invoked as a function.
|
|
137
|
+
*
|
|
138
|
+
* This is the core mechanism. `createOptionsProxy` and `createActionsProxy`
|
|
139
|
+
* are thin wrappers that provide different handlers.
|
|
140
|
+
*/
|
|
141
|
+
declare function createDeepProxy<TResult>(handler: (path: string[], args: unknown[]) => TResult, path?: string[]): unknown;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a proxy that returns TanStack Query options for every SDK method.
|
|
144
|
+
*
|
|
145
|
+
* Read methods (get, list, lookup, search, suggest) return ProxyQueryOptions.
|
|
146
|
+
* Write methods (create, update, delete, etc.) return ProxyMutationOptions.
|
|
147
|
+
*
|
|
148
|
+
* @param api The SDK client instance
|
|
149
|
+
* @param config Optional cache configuration
|
|
150
|
+
* @returns Proxy mirroring the SDK with query/mutation options at every leaf
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* const q = createOptionsProxy(api);
|
|
154
|
+
* const opts = q.items.invMast.stock.get(42);
|
|
155
|
+
* // opts.queryKey → ["items", "invMast", "stock", "get", 42]
|
|
156
|
+
* // opts.queryFn → () => api.items.invMast.stock.get(42)
|
|
157
|
+
* // opts.staleTime → 60000 (semiStatic default)
|
|
158
|
+
*/
|
|
159
|
+
declare function createOptionsProxy<TApi extends object>(api: TApi, config?: OptionsProxyConfig): unknown;
|
|
160
|
+
/**
|
|
161
|
+
* Creates a proxy that wraps every SDK method as a direct async action.
|
|
162
|
+
*
|
|
163
|
+
* For read methods, the result is cached using the cache key builder.
|
|
164
|
+
* For write methods, the call passes through directly.
|
|
165
|
+
*
|
|
166
|
+
* @param api The SDK client instance
|
|
167
|
+
* @param config Optional cache and transform configuration
|
|
168
|
+
* @returns Proxy mirroring the SDK with cached/transformed actions at every leaf
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* const actions = createActionsProxy(api, { cachePrefix: "ampro:" });
|
|
172
|
+
* const stock = await actions.items.invMast.stock.get(42);
|
|
173
|
+
*/
|
|
174
|
+
declare function createActionsProxy<TApi extends object>(api: TApi, config?: ActionsProxyConfig): unknown;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Method classification — determines whether an SDK method is a read (GET)
|
|
178
|
+
* or write (POST/PUT/DELETE) based on its leaf method name.
|
|
179
|
+
*
|
|
180
|
+
* Read methods produce UseQueryOptions; write methods produce UseMutationOptions.
|
|
181
|
+
*/
|
|
182
|
+
/**
|
|
183
|
+
* Returns true if the leaf method name represents a read (GET) operation.
|
|
184
|
+
*
|
|
185
|
+
* Read methods: get, list, lookup, search, suggest
|
|
186
|
+
*/
|
|
187
|
+
declare function isReadMethod(methodName: string): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Returns true if the leaf method name represents a write (POST/PUT/DELETE) operation.
|
|
190
|
+
*
|
|
191
|
+
* Write methods: create, update, delete, enable, and anything not in the read set.
|
|
192
|
+
*/
|
|
193
|
+
declare function isWriteMethod(methodName: string): boolean;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Cache tier resolution — maps SDK method paths to cache tiers.
|
|
197
|
+
*
|
|
198
|
+
* The same tiers apply on client (staleTime/gcTime) and server (edgeCache/redisTtl).
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/** Internal resolved cache tier with all timing values. */
|
|
202
|
+
interface ResolvedCacheTier {
|
|
203
|
+
staleTime: number;
|
|
204
|
+
gcTime: number;
|
|
205
|
+
edgeCache?: number | string;
|
|
206
|
+
redisTtl?: number;
|
|
207
|
+
}
|
|
208
|
+
/** Cache tier configuration with defaults for all tiers. */
|
|
209
|
+
interface CacheTierDefaults {
|
|
210
|
+
static: ResolvedCacheTier;
|
|
211
|
+
semiStatic: ResolvedCacheTier;
|
|
212
|
+
none: ResolvedCacheTier;
|
|
213
|
+
}
|
|
214
|
+
/** Default cache tier values. */
|
|
215
|
+
declare const DEFAULT_CACHE_TIERS: CacheTierDefaults;
|
|
216
|
+
/**
|
|
217
|
+
* Resolves the cache tier for a given SDK method path.
|
|
218
|
+
*
|
|
219
|
+
* @param methodPath Dot-separated SDK method path (e.g. "items.invMast.stock.get")
|
|
220
|
+
* @param overrides Optional per-tier overrides from consumer config
|
|
221
|
+
* @returns Resolved cache tier with timing values
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* getCacheTier("items.categories.list") → static (60 min stale)
|
|
225
|
+
* getCacheTier("pricing.priceEngine.get") → semiStatic (1 min stale)
|
|
226
|
+
* getCacheTier("commerce.cartLine.add.create") → none (0 stale)
|
|
227
|
+
*/
|
|
228
|
+
declare function getCacheTier(methodPath: string, overrides?: {
|
|
229
|
+
static?: CacheTierConfig;
|
|
230
|
+
semiStatic?: CacheTierConfig;
|
|
231
|
+
}): ResolvedCacheTier;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Utility functions for the proxy infrastructure.
|
|
235
|
+
*/
|
|
236
|
+
/**
|
|
237
|
+
* Walk an object by path array to find the leaf function.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* resolveMethod(api, ["items", "invMast", "stock", "get"])
|
|
241
|
+
* → api.items.invMast.stock.get
|
|
242
|
+
*/
|
|
243
|
+
declare function resolveMethod(obj: unknown, path: string[]): (...args: unknown[]) => unknown;
|
|
244
|
+
/**
|
|
245
|
+
* Normalize arguments for deterministic cache/query keys.
|
|
246
|
+
* Filters out undefined values from argument objects.
|
|
247
|
+
*/
|
|
248
|
+
declare function stableArgs(args: unknown[]): unknown[];
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Recursive mapped types for compile-time SDK mirroring.
|
|
252
|
+
*
|
|
253
|
+
* DeepQueryOptions<T> transforms the SDK type tree into TanStack Query options.
|
|
254
|
+
* DeepActions<T> transforms it into direct async actions.
|
|
255
|
+
* Both provide IDE autocomplete that mirrors the SDK exactly.
|
|
256
|
+
*/
|
|
257
|
+
/**
|
|
258
|
+
* Determines if a method name represents a read (GET) operation at the type level.
|
|
259
|
+
*/
|
|
260
|
+
type IsReadMethod<K> = K extends "get" | "list" | "lookup" | "search" | "suggest" ? true : false;
|
|
261
|
+
/** Standard SDK response wrapper. */
|
|
262
|
+
interface BaseResponse<T> {
|
|
263
|
+
data: T;
|
|
264
|
+
status: number;
|
|
265
|
+
message: string;
|
|
266
|
+
}
|
|
267
|
+
/** Query options shape returned by the proxy for read methods. */
|
|
268
|
+
interface ProxyQueryOptions<TData> {
|
|
269
|
+
queryKey: unknown[];
|
|
270
|
+
queryFn: () => Promise<TData>;
|
|
271
|
+
staleTime: number;
|
|
272
|
+
gcTime: number;
|
|
273
|
+
}
|
|
274
|
+
/** Mutation options shape returned by the proxy for write methods. */
|
|
275
|
+
interface ProxyMutationOptions<TData, TVariables extends unknown[]> {
|
|
276
|
+
mutationKey: string[];
|
|
277
|
+
mutationFn: (...args: TVariables) => Promise<TData>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Recursively transforms an SDK client type into TanStack Query options.
|
|
281
|
+
*
|
|
282
|
+
* - Leaf functions with read method names → (...args) => ProxyQueryOptions
|
|
283
|
+
* - Leaf functions with write method names → () => ProxyMutationOptions
|
|
284
|
+
* - Namespaces → recurse
|
|
285
|
+
*/
|
|
286
|
+
type DeepQueryOptions<T> = {
|
|
287
|
+
[K in keyof T]: T[K] extends (...args: infer A) => Promise<BaseResponse<infer R>> ? IsReadMethod<K> extends true ? (...args: A) => ProxyQueryOptions<R> : (...args: A) => ProxyMutationOptions<R, A> : T[K] extends (...args: infer A) => Promise<infer R> ? IsReadMethod<K> extends true ? (...args: A) => ProxyQueryOptions<R> : (...args: A) => ProxyMutationOptions<R, A> : T[K] extends object ? DeepQueryOptions<T[K]> : never;
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Recursively transforms an SDK client type into direct async actions.
|
|
291
|
+
*
|
|
292
|
+
* Every leaf function keeps its original signature. Namespaces recurse.
|
|
293
|
+
*/
|
|
294
|
+
type DeepActions<T> = {
|
|
295
|
+
[K in keyof T]: T[K] extends (...args: infer A) => Promise<infer R> ? (...args: A) => Promise<R> : T[K] extends object ? DeepActions<T[K]> : never;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export { type ActionResult, type ActionsProxyConfig, type AugurAuthContext, type CacheConfig, type CacheProvider, type CacheTierConfig, type CacheTierDefaults, DEFAULT_CACHE_TIERS, type DeepActions, type DeepQueryOptions, type EdgeCacheValue, type InfiniteScrollPage, type IsReadMethod, type OptionsProxyConfig, type ProxyMutationOptions, type ProxyQueryOptions, type ResolvedCacheTier, buildCacheKey, buildQueryKey, createActionsProxy, createDeepProxy, createOptionsProxy, fnv1a, getCacheTier, isReadMethod, isWriteMethod, resolveMethod, stableArgs, stableStringify };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { TProductItem } from '@simpleapps-com/augur-utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Valid CDN edge cache durations accepted by the augur-api SDK.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors `CacheParams['edgeCache']` from `@simpleapps-com/augur-api`.
|
|
7
|
+
*/
|
|
8
|
+
type EdgeCacheValue = "30s" | "1m" | "5m" | 1 | 2 | 3 | 4 | 5 | 8 | "1" | "2" | "3" | "4" | "5" | "8";
|
|
9
|
+
/**
|
|
10
|
+
* Auth context provided at the provider level.
|
|
11
|
+
* Auth-provider-agnostic — works with NextAuth, Clerk, Supabase Auth, etc.
|
|
12
|
+
*/
|
|
13
|
+
interface AugurAuthContext {
|
|
14
|
+
/** Auth loading state — hooks disable queries while "loading". */
|
|
15
|
+
status: "loading" | "authenticated" | "unauthenticated";
|
|
16
|
+
/** Customer ID for pricing. Falls back to env default if undefined. */
|
|
17
|
+
customerId?: string | number;
|
|
18
|
+
/** User ID for cart ownership. */
|
|
19
|
+
userId?: string | number;
|
|
20
|
+
/** Cart header UID from session (if available). */
|
|
21
|
+
cartHdrUid?: string | number;
|
|
22
|
+
}
|
|
23
|
+
/** Paginated response for infinite scroll hooks. */
|
|
24
|
+
interface InfiniteScrollPage {
|
|
25
|
+
data: TProductItem[];
|
|
26
|
+
total: number;
|
|
27
|
+
nextCursor?: number;
|
|
28
|
+
}
|
|
29
|
+
/** Cache provider for Redis-compatible storage. */
|
|
30
|
+
interface CacheProvider {
|
|
31
|
+
prefix: string;
|
|
32
|
+
get: (key: string) => Promise<string | null>;
|
|
33
|
+
set: (key: string, value: string, ttlSeconds: number) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** Cache settings for a single tier. */
|
|
36
|
+
interface CacheTierConfig {
|
|
37
|
+
/** CDN edge cache. Passed directly to SDK as edgeCache. Valid values: 1–8 (hours) or '30s', '1m', '5m'. */
|
|
38
|
+
edgeCache?: number | string;
|
|
39
|
+
/** Redis cache TTL in seconds. Requires provider. */
|
|
40
|
+
redis?: number;
|
|
41
|
+
/** React Query staleTime in ms. Overrides the built-in default. */
|
|
42
|
+
staleTime?: number;
|
|
43
|
+
/** React Query gcTime (garbage collection) in ms. Overrides the built-in default. */
|
|
44
|
+
gcTime?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Cache configuration. All fields optional, all off by default. */
|
|
47
|
+
interface CacheConfig {
|
|
48
|
+
/** Redis-compatible cache. Required for redis caching. */
|
|
49
|
+
provider?: CacheProvider;
|
|
50
|
+
/** TTLs for long-lived data (categories, item details, docs). */
|
|
51
|
+
static?: CacheTierConfig;
|
|
52
|
+
/** TTLs for frequently-changing data (prices, stock, search). */
|
|
53
|
+
semiStatic?: CacheTierConfig;
|
|
54
|
+
}
|
|
55
|
+
/** Discriminated union for safe action results. */
|
|
56
|
+
type ActionResult<T> = {
|
|
57
|
+
ok: true;
|
|
58
|
+
data: T;
|
|
59
|
+
} | {
|
|
60
|
+
ok: false;
|
|
61
|
+
error: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Deterministic key generation utilities.
|
|
66
|
+
*
|
|
67
|
+
* stableStringify and fnv1a are the single source of truth —
|
|
68
|
+
* augur-hooks and augur-server both import from here so cache keys
|
|
69
|
+
* are guaranteed identical across client and server.
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* JSON.stringify with sorted object keys for deterministic cache keys.
|
|
73
|
+
* Ensures { a: 1, b: 2 } and { b: 2, a: 1 } produce the same string.
|
|
74
|
+
*/
|
|
75
|
+
declare function stableStringify(value: unknown): string;
|
|
76
|
+
/**
|
|
77
|
+
* FNV-1a 32-bit hash. Fast non-cryptographic hash for cache keys.
|
|
78
|
+
* Returns an 8-character zero-padded hex string.
|
|
79
|
+
*/
|
|
80
|
+
declare function fnv1a(str: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Builds a deterministic query key from a method path and arguments.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* buildQueryKey(["items", "invMast", "get"], [42])
|
|
86
|
+
* → ["items", "invMast", "get", 42]
|
|
87
|
+
*
|
|
88
|
+
* buildQueryKey(["pricing", "priceEngine", "get"], [{ itemId: "X", customerId: 1 }])
|
|
89
|
+
* → ["pricing", "priceEngine", "get", { itemId: "X", customerId: 1 }]
|
|
90
|
+
*/
|
|
91
|
+
declare function buildQueryKey(path: string[], args: unknown[]): unknown[];
|
|
92
|
+
/**
|
|
93
|
+
* Builds a deterministic cache key for Redis/CDN caching.
|
|
94
|
+
*
|
|
95
|
+
* Format: `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(args))}`
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* buildCacheKey("ampro:", "pricing.priceEngine.get", [{ itemId: "X" }])
|
|
99
|
+
* → "ampro:sdk:pricing.priceEngine.get:a1b2c3d4"
|
|
100
|
+
*/
|
|
101
|
+
declare function buildCacheKey(prefix: string, methodPath: string, args: unknown[]): string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Deep proxy factories — runtime SDK namespace mirroring.
|
|
105
|
+
*
|
|
106
|
+
* The same Proxy pattern that powers `createMockClient()` in the SDK
|
|
107
|
+
* powers every downstream consumer. One proxy shape, multiple behaviors
|
|
108
|
+
* via the handler callback.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/** Configuration for the options proxy (hooks). */
|
|
112
|
+
interface OptionsProxyConfig {
|
|
113
|
+
/** Per-tier cache overrides. */
|
|
114
|
+
cache?: {
|
|
115
|
+
static?: CacheTierConfig;
|
|
116
|
+
semiStatic?: CacheTierConfig;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Configuration for the actions proxy (server). */
|
|
120
|
+
interface ActionsProxyConfig {
|
|
121
|
+
/** Cache key prefix (e.g. "ampro:"). */
|
|
122
|
+
cachePrefix?: string;
|
|
123
|
+
/** Per-tier cache overrides. */
|
|
124
|
+
cache?: {
|
|
125
|
+
static?: CacheTierConfig;
|
|
126
|
+
semiStatic?: CacheTierConfig;
|
|
127
|
+
};
|
|
128
|
+
/** Pre/post transforms per method path. */
|
|
129
|
+
transforms?: Record<string, {
|
|
130
|
+
pre?: (args: unknown[]) => unknown[];
|
|
131
|
+
post?: (result: unknown) => unknown;
|
|
132
|
+
}>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Creates a deep proxy that intercepts property access to build a method
|
|
136
|
+
* path, then calls the handler when the proxy is invoked as a function.
|
|
137
|
+
*
|
|
138
|
+
* This is the core mechanism. `createOptionsProxy` and `createActionsProxy`
|
|
139
|
+
* are thin wrappers that provide different handlers.
|
|
140
|
+
*/
|
|
141
|
+
declare function createDeepProxy<TResult>(handler: (path: string[], args: unknown[]) => TResult, path?: string[]): unknown;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a proxy that returns TanStack Query options for every SDK method.
|
|
144
|
+
*
|
|
145
|
+
* Read methods (get, list, lookup, search, suggest) return ProxyQueryOptions.
|
|
146
|
+
* Write methods (create, update, delete, etc.) return ProxyMutationOptions.
|
|
147
|
+
*
|
|
148
|
+
* @param api The SDK client instance
|
|
149
|
+
* @param config Optional cache configuration
|
|
150
|
+
* @returns Proxy mirroring the SDK with query/mutation options at every leaf
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* const q = createOptionsProxy(api);
|
|
154
|
+
* const opts = q.items.invMast.stock.get(42);
|
|
155
|
+
* // opts.queryKey → ["items", "invMast", "stock", "get", 42]
|
|
156
|
+
* // opts.queryFn → () => api.items.invMast.stock.get(42)
|
|
157
|
+
* // opts.staleTime → 60000 (semiStatic default)
|
|
158
|
+
*/
|
|
159
|
+
declare function createOptionsProxy<TApi extends object>(api: TApi, config?: OptionsProxyConfig): unknown;
|
|
160
|
+
/**
|
|
161
|
+
* Creates a proxy that wraps every SDK method as a direct async action.
|
|
162
|
+
*
|
|
163
|
+
* For read methods, the result is cached using the cache key builder.
|
|
164
|
+
* For write methods, the call passes through directly.
|
|
165
|
+
*
|
|
166
|
+
* @param api The SDK client instance
|
|
167
|
+
* @param config Optional cache and transform configuration
|
|
168
|
+
* @returns Proxy mirroring the SDK with cached/transformed actions at every leaf
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* const actions = createActionsProxy(api, { cachePrefix: "ampro:" });
|
|
172
|
+
* const stock = await actions.items.invMast.stock.get(42);
|
|
173
|
+
*/
|
|
174
|
+
declare function createActionsProxy<TApi extends object>(api: TApi, config?: ActionsProxyConfig): unknown;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Method classification — determines whether an SDK method is a read (GET)
|
|
178
|
+
* or write (POST/PUT/DELETE) based on its leaf method name.
|
|
179
|
+
*
|
|
180
|
+
* Read methods produce UseQueryOptions; write methods produce UseMutationOptions.
|
|
181
|
+
*/
|
|
182
|
+
/**
|
|
183
|
+
* Returns true if the leaf method name represents a read (GET) operation.
|
|
184
|
+
*
|
|
185
|
+
* Read methods: get, list, lookup, search, suggest
|
|
186
|
+
*/
|
|
187
|
+
declare function isReadMethod(methodName: string): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Returns true if the leaf method name represents a write (POST/PUT/DELETE) operation.
|
|
190
|
+
*
|
|
191
|
+
* Write methods: create, update, delete, enable, and anything not in the read set.
|
|
192
|
+
*/
|
|
193
|
+
declare function isWriteMethod(methodName: string): boolean;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Cache tier resolution — maps SDK method paths to cache tiers.
|
|
197
|
+
*
|
|
198
|
+
* The same tiers apply on client (staleTime/gcTime) and server (edgeCache/redisTtl).
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/** Internal resolved cache tier with all timing values. */
|
|
202
|
+
interface ResolvedCacheTier {
|
|
203
|
+
staleTime: number;
|
|
204
|
+
gcTime: number;
|
|
205
|
+
edgeCache?: number | string;
|
|
206
|
+
redisTtl?: number;
|
|
207
|
+
}
|
|
208
|
+
/** Cache tier configuration with defaults for all tiers. */
|
|
209
|
+
interface CacheTierDefaults {
|
|
210
|
+
static: ResolvedCacheTier;
|
|
211
|
+
semiStatic: ResolvedCacheTier;
|
|
212
|
+
none: ResolvedCacheTier;
|
|
213
|
+
}
|
|
214
|
+
/** Default cache tier values. */
|
|
215
|
+
declare const DEFAULT_CACHE_TIERS: CacheTierDefaults;
|
|
216
|
+
/**
|
|
217
|
+
* Resolves the cache tier for a given SDK method path.
|
|
218
|
+
*
|
|
219
|
+
* @param methodPath Dot-separated SDK method path (e.g. "items.invMast.stock.get")
|
|
220
|
+
* @param overrides Optional per-tier overrides from consumer config
|
|
221
|
+
* @returns Resolved cache tier with timing values
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* getCacheTier("items.categories.list") → static (60 min stale)
|
|
225
|
+
* getCacheTier("pricing.priceEngine.get") → semiStatic (1 min stale)
|
|
226
|
+
* getCacheTier("commerce.cartLine.add.create") → none (0 stale)
|
|
227
|
+
*/
|
|
228
|
+
declare function getCacheTier(methodPath: string, overrides?: {
|
|
229
|
+
static?: CacheTierConfig;
|
|
230
|
+
semiStatic?: CacheTierConfig;
|
|
231
|
+
}): ResolvedCacheTier;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Utility functions for the proxy infrastructure.
|
|
235
|
+
*/
|
|
236
|
+
/**
|
|
237
|
+
* Walk an object by path array to find the leaf function.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* resolveMethod(api, ["items", "invMast", "stock", "get"])
|
|
241
|
+
* → api.items.invMast.stock.get
|
|
242
|
+
*/
|
|
243
|
+
declare function resolveMethod(obj: unknown, path: string[]): (...args: unknown[]) => unknown;
|
|
244
|
+
/**
|
|
245
|
+
* Normalize arguments for deterministic cache/query keys.
|
|
246
|
+
* Filters out undefined values from argument objects.
|
|
247
|
+
*/
|
|
248
|
+
declare function stableArgs(args: unknown[]): unknown[];
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Recursive mapped types for compile-time SDK mirroring.
|
|
252
|
+
*
|
|
253
|
+
* DeepQueryOptions<T> transforms the SDK type tree into TanStack Query options.
|
|
254
|
+
* DeepActions<T> transforms it into direct async actions.
|
|
255
|
+
* Both provide IDE autocomplete that mirrors the SDK exactly.
|
|
256
|
+
*/
|
|
257
|
+
/**
|
|
258
|
+
* Determines if a method name represents a read (GET) operation at the type level.
|
|
259
|
+
*/
|
|
260
|
+
type IsReadMethod<K> = K extends "get" | "list" | "lookup" | "search" | "suggest" ? true : false;
|
|
261
|
+
/** Standard SDK response wrapper. */
|
|
262
|
+
interface BaseResponse<T> {
|
|
263
|
+
data: T;
|
|
264
|
+
status: number;
|
|
265
|
+
message: string;
|
|
266
|
+
}
|
|
267
|
+
/** Query options shape returned by the proxy for read methods. */
|
|
268
|
+
interface ProxyQueryOptions<TData> {
|
|
269
|
+
queryKey: unknown[];
|
|
270
|
+
queryFn: () => Promise<TData>;
|
|
271
|
+
staleTime: number;
|
|
272
|
+
gcTime: number;
|
|
273
|
+
}
|
|
274
|
+
/** Mutation options shape returned by the proxy for write methods. */
|
|
275
|
+
interface ProxyMutationOptions<TData, TVariables extends unknown[]> {
|
|
276
|
+
mutationKey: string[];
|
|
277
|
+
mutationFn: (...args: TVariables) => Promise<TData>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Recursively transforms an SDK client type into TanStack Query options.
|
|
281
|
+
*
|
|
282
|
+
* - Leaf functions with read method names → (...args) => ProxyQueryOptions
|
|
283
|
+
* - Leaf functions with write method names → () => ProxyMutationOptions
|
|
284
|
+
* - Namespaces → recurse
|
|
285
|
+
*/
|
|
286
|
+
type DeepQueryOptions<T> = {
|
|
287
|
+
[K in keyof T]: T[K] extends (...args: infer A) => Promise<BaseResponse<infer R>> ? IsReadMethod<K> extends true ? (...args: A) => ProxyQueryOptions<R> : (...args: A) => ProxyMutationOptions<R, A> : T[K] extends (...args: infer A) => Promise<infer R> ? IsReadMethod<K> extends true ? (...args: A) => ProxyQueryOptions<R> : (...args: A) => ProxyMutationOptions<R, A> : T[K] extends object ? DeepQueryOptions<T[K]> : never;
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Recursively transforms an SDK client type into direct async actions.
|
|
291
|
+
*
|
|
292
|
+
* Every leaf function keeps its original signature. Namespaces recurse.
|
|
293
|
+
*/
|
|
294
|
+
type DeepActions<T> = {
|
|
295
|
+
[K in keyof T]: T[K] extends (...args: infer A) => Promise<infer R> ? (...args: A) => Promise<R> : T[K] extends object ? DeepActions<T[K]> : never;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export { type ActionResult, type ActionsProxyConfig, type AugurAuthContext, type CacheConfig, type CacheProvider, type CacheTierConfig, type CacheTierDefaults, DEFAULT_CACHE_TIERS, type DeepActions, type DeepQueryOptions, type EdgeCacheValue, type InfiniteScrollPage, type IsReadMethod, type OptionsProxyConfig, type ProxyMutationOptions, type ProxyQueryOptions, type ResolvedCacheTier, buildCacheKey, buildQueryKey, createActionsProxy, createDeepProxy, createOptionsProxy, fnv1a, getCacheTier, isReadMethod, isWriteMethod, resolveMethod, stableArgs, stableStringify };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// src/classification.ts
|
|
2
|
+
var READ_METHODS = /* @__PURE__ */ new Set(["get", "list", "lookup", "search", "suggest"]);
|
|
3
|
+
function isReadMethod(methodName) {
|
|
4
|
+
return READ_METHODS.has(methodName);
|
|
5
|
+
}
|
|
6
|
+
function isWriteMethod(methodName) {
|
|
7
|
+
return !READ_METHODS.has(methodName);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/cache.ts
|
|
11
|
+
var DEFAULT_CACHE_TIERS = {
|
|
12
|
+
static: {
|
|
13
|
+
staleTime: 60 * 60 * 1e3,
|
|
14
|
+
// 60 min
|
|
15
|
+
gcTime: 2 * 60 * 60 * 1e3,
|
|
16
|
+
// 120 min
|
|
17
|
+
edgeCache: 8,
|
|
18
|
+
redisTtl: 28800
|
|
19
|
+
// 8 hours
|
|
20
|
+
},
|
|
21
|
+
semiStatic: {
|
|
22
|
+
staleTime: 60 * 1e3,
|
|
23
|
+
// 1 min
|
|
24
|
+
gcTime: 5 * 60 * 1e3,
|
|
25
|
+
// 5 min
|
|
26
|
+
edgeCache: 1,
|
|
27
|
+
redisTtl: 3600
|
|
28
|
+
// 1 hour
|
|
29
|
+
},
|
|
30
|
+
none: {
|
|
31
|
+
staleTime: 0,
|
|
32
|
+
gcTime: 0
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var STATIC_PATHS = [
|
|
36
|
+
"agrSite.settings",
|
|
37
|
+
"agrSite.metaFiles",
|
|
38
|
+
"agrSite.geoCodesPostalCodes",
|
|
39
|
+
"items.categories",
|
|
40
|
+
"items.itemCategory",
|
|
41
|
+
"items.brands",
|
|
42
|
+
"items.attributeGroups",
|
|
43
|
+
"items.attributes",
|
|
44
|
+
"p21Core.company",
|
|
45
|
+
"p21Core.location",
|
|
46
|
+
"p21Core.paymentTypes",
|
|
47
|
+
"p21Core.codeP21",
|
|
48
|
+
"p21Core.cashDrawer",
|
|
49
|
+
"joomla.menu",
|
|
50
|
+
"joomla.tags",
|
|
51
|
+
"joomla.userGroups",
|
|
52
|
+
"legacy.state"
|
|
53
|
+
];
|
|
54
|
+
var NO_CACHE_PATHS = ["commerce"];
|
|
55
|
+
function getCacheTier(methodPath, overrides) {
|
|
56
|
+
if (NO_CACHE_PATHS.some((p) => methodPath.startsWith(p))) {
|
|
57
|
+
return DEFAULT_CACHE_TIERS.none;
|
|
58
|
+
}
|
|
59
|
+
if (STATIC_PATHS.some((p) => methodPath.startsWith(p))) {
|
|
60
|
+
const base2 = DEFAULT_CACHE_TIERS.static;
|
|
61
|
+
const tier2 = overrides?.static;
|
|
62
|
+
if (!tier2) return base2;
|
|
63
|
+
return {
|
|
64
|
+
staleTime: tier2.staleTime ?? base2.staleTime,
|
|
65
|
+
gcTime: tier2.gcTime ?? base2.gcTime,
|
|
66
|
+
edgeCache: tier2.edgeCache ?? base2.edgeCache,
|
|
67
|
+
redisTtl: tier2.redis ?? base2.redisTtl
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const base = DEFAULT_CACHE_TIERS.semiStatic;
|
|
71
|
+
const tier = overrides?.semiStatic;
|
|
72
|
+
if (!tier) return base;
|
|
73
|
+
return {
|
|
74
|
+
staleTime: tier.staleTime ?? base.staleTime,
|
|
75
|
+
gcTime: tier.gcTime ?? base.gcTime,
|
|
76
|
+
edgeCache: tier.edgeCache ?? base.edgeCache,
|
|
77
|
+
redisTtl: tier.redis ?? base.redisTtl
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/keys.ts
|
|
82
|
+
function stableStringify(value) {
|
|
83
|
+
if (value === null || value === void 0) return JSON.stringify(value);
|
|
84
|
+
if (typeof value !== "object") return JSON.stringify(value);
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
return `[${value.map(stableStringify).join(",")}]`;
|
|
87
|
+
}
|
|
88
|
+
const obj = value;
|
|
89
|
+
const keys = Object.keys(obj).sort();
|
|
90
|
+
const entries = keys.map(
|
|
91
|
+
(key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`
|
|
92
|
+
);
|
|
93
|
+
return `{${entries.join(",")}}`;
|
|
94
|
+
}
|
|
95
|
+
function fnv1a(str) {
|
|
96
|
+
let h = 2166136261;
|
|
97
|
+
for (let i = 0; i < str.length; i++) {
|
|
98
|
+
h ^= str.charCodeAt(i);
|
|
99
|
+
h = Math.imul(h, 16777619);
|
|
100
|
+
}
|
|
101
|
+
return (h >>> 0).toString(16).padStart(8, "0");
|
|
102
|
+
}
|
|
103
|
+
function buildQueryKey(path, args) {
|
|
104
|
+
return [...path, ...args];
|
|
105
|
+
}
|
|
106
|
+
function buildCacheKey(prefix, methodPath, args) {
|
|
107
|
+
return `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(args))}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/utils.ts
|
|
111
|
+
function resolveMethod(obj, path) {
|
|
112
|
+
let current = obj;
|
|
113
|
+
for (const segment of path) {
|
|
114
|
+
if (current == null || typeof current !== "object") {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`Cannot resolve method path "${path.join(".")}": "${segment}" is not accessible on ${typeof current}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
current = current[segment];
|
|
120
|
+
}
|
|
121
|
+
if (typeof current !== "function") {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`Method path "${path.join(".")}" does not resolve to a function (got ${typeof current})`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return current;
|
|
127
|
+
}
|
|
128
|
+
function stableArgs(args) {
|
|
129
|
+
return args.map((arg) => {
|
|
130
|
+
if (arg === null || arg === void 0 || typeof arg !== "object") return arg;
|
|
131
|
+
if (Array.isArray(arg)) return arg;
|
|
132
|
+
const obj = arg;
|
|
133
|
+
const filtered = {};
|
|
134
|
+
for (const key of Object.keys(obj).sort()) {
|
|
135
|
+
if (obj[key] !== void 0) {
|
|
136
|
+
filtered[key] = obj[key];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return filtered;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/proxy.ts
|
|
144
|
+
function createDeepProxy(handler, path = []) {
|
|
145
|
+
const callable = function() {
|
|
146
|
+
};
|
|
147
|
+
return new Proxy(callable, {
|
|
148
|
+
get(_target, prop) {
|
|
149
|
+
if (typeof prop === "symbol") return void 0;
|
|
150
|
+
return createDeepProxy(handler, [...path, prop]);
|
|
151
|
+
},
|
|
152
|
+
apply(_target, _thisArg, args) {
|
|
153
|
+
return handler(path, args);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function createOptionsProxy(api, config) {
|
|
158
|
+
return createDeepProxy(
|
|
159
|
+
(path, args) => {
|
|
160
|
+
const methodName = path[path.length - 1];
|
|
161
|
+
const methodPath = path.join(".");
|
|
162
|
+
const sdkMethod = resolveMethod(api, path);
|
|
163
|
+
const normalizedArgs = stableArgs(args);
|
|
164
|
+
if (isReadMethod(methodName)) {
|
|
165
|
+
const tier = getCacheTier(methodPath, config?.cache);
|
|
166
|
+
return {
|
|
167
|
+
queryKey: buildQueryKey(path, normalizedArgs),
|
|
168
|
+
queryFn: () => sdkMethod(...args),
|
|
169
|
+
staleTime: tier.staleTime,
|
|
170
|
+
gcTime: tier.gcTime
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
mutationKey: path,
|
|
175
|
+
mutationFn: (...mutationArgs) => sdkMethod(...mutationArgs)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
function createActionsProxy(api, config) {
|
|
181
|
+
return createDeepProxy(async (path, args) => {
|
|
182
|
+
const methodPath = path.join(".");
|
|
183
|
+
const sdkMethod = resolveMethod(api, path);
|
|
184
|
+
const transform = config?.transforms?.[methodPath];
|
|
185
|
+
const finalArgs = transform?.pre ? transform.pre(args) : args;
|
|
186
|
+
const result = await sdkMethod(...finalArgs);
|
|
187
|
+
return transform?.post ? transform.post(result) : result;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
DEFAULT_CACHE_TIERS,
|
|
192
|
+
buildCacheKey,
|
|
193
|
+
buildQueryKey,
|
|
194
|
+
createActionsProxy,
|
|
195
|
+
createDeepProxy,
|
|
196
|
+
createOptionsProxy,
|
|
197
|
+
fnv1a,
|
|
198
|
+
getCacheTier,
|
|
199
|
+
isReadMethod,
|
|
200
|
+
isWriteMethod,
|
|
201
|
+
resolveMethod,
|
|
202
|
+
stableArgs,
|
|
203
|
+
stableStringify
|
|
204
|
+
};
|
|
205
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/classification.ts","../src/cache.ts","../src/keys.ts","../src/utils.ts","../src/proxy.ts"],"sourcesContent":["/**\n * Method classification — determines whether an SDK method is a read (GET)\n * or write (POST/PUT/DELETE) based on its leaf method name.\n *\n * Read methods produce UseQueryOptions; write methods produce UseMutationOptions.\n */\n\nconst READ_METHODS = new Set([\"get\", \"list\", \"lookup\", \"search\", \"suggest\"]);\n\n/**\n * Returns true if the leaf method name represents a read (GET) operation.\n *\n * Read methods: get, list, lookup, search, suggest\n */\nexport function isReadMethod(methodName: string): boolean {\n return READ_METHODS.has(methodName);\n}\n\n/**\n * Returns true if the leaf method name represents a write (POST/PUT/DELETE) operation.\n *\n * Write methods: create, update, delete, enable, and anything not in the read set.\n */\nexport function isWriteMethod(methodName: string): boolean {\n return !READ_METHODS.has(methodName);\n}\n","/**\n * Cache tier resolution — maps SDK method paths to cache tiers.\n *\n * The same tiers apply on client (staleTime/gcTime) and server (edgeCache/redisTtl).\n */\n\nimport type { CacheTierConfig } from \"./shared-types\";\n\n/** Internal resolved cache tier with all timing values. */\nexport interface ResolvedCacheTier {\n staleTime: number;\n gcTime: number;\n edgeCache?: number | string;\n redisTtl?: number;\n}\n\n/** Cache tier configuration with defaults for all tiers. */\nexport interface CacheTierDefaults {\n static: ResolvedCacheTier;\n semiStatic: ResolvedCacheTier;\n none: ResolvedCacheTier;\n}\n\n/** Default cache tier values. */\nexport const DEFAULT_CACHE_TIERS: CacheTierDefaults = {\n static: {\n staleTime: 60 * 60 * 1000, // 60 min\n gcTime: 2 * 60 * 60 * 1000, // 120 min\n edgeCache: 8,\n redisTtl: 28800, // 8 hours\n },\n semiStatic: {\n staleTime: 60 * 1000, // 1 min\n gcTime: 5 * 60 * 1000, // 5 min\n edgeCache: 1,\n redisTtl: 3600, // 1 hour\n },\n none: {\n staleTime: 0,\n gcTime: 0,\n },\n};\n\n/** Paths that should use the static cache tier. */\nconst STATIC_PATHS = [\n \"agrSite.settings\",\n \"agrSite.metaFiles\",\n \"agrSite.geoCodesPostalCodes\",\n \"items.categories\",\n \"items.itemCategory\",\n \"items.brands\",\n \"items.attributeGroups\",\n \"items.attributes\",\n \"p21Core.company\",\n \"p21Core.location\",\n \"p21Core.paymentTypes\",\n \"p21Core.codeP21\",\n \"p21Core.cashDrawer\",\n \"joomla.menu\",\n \"joomla.tags\",\n \"joomla.userGroups\",\n \"legacy.state\",\n];\n\n/** Paths that should not be cached. */\nconst NO_CACHE_PATHS = [\"commerce\"];\n\n/**\n * Resolves the cache tier for a given SDK method path.\n *\n * @param methodPath Dot-separated SDK method path (e.g. \"items.invMast.stock.get\")\n * @param overrides Optional per-tier overrides from consumer config\n * @returns Resolved cache tier with timing values\n *\n * @example\n * getCacheTier(\"items.categories.list\") → static (60 min stale)\n * getCacheTier(\"pricing.priceEngine.get\") → semiStatic (1 min stale)\n * getCacheTier(\"commerce.cartLine.add.create\") → none (0 stale)\n */\nexport function getCacheTier(\n methodPath: string,\n overrides?: { static?: CacheTierConfig; semiStatic?: CacheTierConfig },\n): ResolvedCacheTier {\n if (NO_CACHE_PATHS.some((p) => methodPath.startsWith(p))) {\n return DEFAULT_CACHE_TIERS.none;\n }\n\n if (STATIC_PATHS.some((p) => methodPath.startsWith(p))) {\n const base = DEFAULT_CACHE_TIERS.static;\n const tier = overrides?.static;\n if (!tier) return base;\n return {\n staleTime: tier.staleTime ?? base.staleTime,\n gcTime: tier.gcTime ?? base.gcTime,\n edgeCache: tier.edgeCache ?? base.edgeCache,\n redisTtl: tier.redis ?? base.redisTtl,\n };\n }\n\n // Default: semiStatic\n const base = DEFAULT_CACHE_TIERS.semiStatic;\n const tier = overrides?.semiStatic;\n if (!tier) return base;\n return {\n staleTime: tier.staleTime ?? base.staleTime,\n gcTime: tier.gcTime ?? base.gcTime,\n edgeCache: tier.edgeCache ?? base.edgeCache,\n redisTtl: tier.redis ?? base.redisTtl,\n };\n}\n","/**\n * Deterministic key generation utilities.\n *\n * stableStringify and fnv1a are the single source of truth —\n * augur-hooks and augur-server both import from here so cache keys\n * are guaranteed identical across client and server.\n */\n\n/**\n * JSON.stringify with sorted object keys for deterministic cache keys.\n * Ensures { a: 1, b: 2 } and { b: 2, a: 1 } produce the same string.\n */\nexport function stableStringify(value: unknown): string {\n if (value === null || value === undefined) return JSON.stringify(value);\n if (typeof value !== \"object\") return JSON.stringify(value);\n if (Array.isArray(value)) {\n return `[${value.map(stableStringify).join(\",\")}]`;\n }\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj).sort();\n const entries = keys.map(\n (key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`,\n );\n return `{${entries.join(\",\")}}`;\n}\n\n/**\n * FNV-1a 32-bit hash. Fast non-cryptographic hash for cache keys.\n * Returns an 8-character zero-padded hex string.\n */\nexport function fnv1a(str: string): string {\n let h = 0x811c9dc5;\n for (let i = 0; i < str.length; i++) {\n h ^= str.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0).toString(16).padStart(8, \"0\");\n}\n\n/**\n * Builds a deterministic query key from a method path and arguments.\n *\n * @example\n * buildQueryKey([\"items\", \"invMast\", \"get\"], [42])\n * → [\"items\", \"invMast\", \"get\", 42]\n *\n * buildQueryKey([\"pricing\", \"priceEngine\", \"get\"], [{ itemId: \"X\", customerId: 1 }])\n * → [\"pricing\", \"priceEngine\", \"get\", { itemId: \"X\", customerId: 1 }]\n */\nexport function buildQueryKey(path: string[], args: unknown[]): unknown[] {\n return [...path, ...args];\n}\n\n/**\n * Builds a deterministic cache key for Redis/CDN caching.\n *\n * Format: `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(args))}`\n *\n * @example\n * buildCacheKey(\"ampro:\", \"pricing.priceEngine.get\", [{ itemId: \"X\" }])\n * → \"ampro:sdk:pricing.priceEngine.get:a1b2c3d4\"\n */\nexport function buildCacheKey(\n prefix: string,\n methodPath: string,\n args: unknown[],\n): string {\n return `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(args))}`;\n}\n","/**\n * Utility functions for the proxy infrastructure.\n */\n\n/**\n * Walk an object by path array to find the leaf function.\n *\n * @example\n * resolveMethod(api, [\"items\", \"invMast\", \"stock\", \"get\"])\n * → api.items.invMast.stock.get\n */\nexport function resolveMethod(\n obj: unknown,\n path: string[],\n): (...args: unknown[]) => unknown {\n let current: unknown = obj;\n for (const segment of path) {\n if (current == null || typeof current !== \"object\") {\n throw new Error(\n `Cannot resolve method path \"${path.join(\".\")}\": ` +\n `\"${segment}\" is not accessible on ${typeof current}`,\n );\n }\n current = (current as Record<string, unknown>)[segment];\n }\n if (typeof current !== \"function\") {\n throw new Error(\n `Method path \"${path.join(\".\")}\" does not resolve to a function ` +\n `(got ${typeof current})`,\n );\n }\n return current as (...args: unknown[]) => unknown;\n}\n\n/**\n * Normalize arguments for deterministic cache/query keys.\n * Filters out undefined values from argument objects.\n */\nexport function stableArgs(args: unknown[]): unknown[] {\n return args.map((arg) => {\n if (arg === null || arg === undefined || typeof arg !== \"object\") return arg;\n if (Array.isArray(arg)) return arg;\n const obj = arg as Record<string, unknown>;\n const filtered: Record<string, unknown> = {};\n for (const key of Object.keys(obj).sort()) {\n if (obj[key] !== undefined) {\n filtered[key] = obj[key];\n }\n }\n return filtered;\n });\n}\n","/**\n * Deep proxy factories — runtime SDK namespace mirroring.\n *\n * The same Proxy pattern that powers `createMockClient()` in the SDK\n * powers every downstream consumer. One proxy shape, multiple behaviors\n * via the handler callback.\n */\n\nimport { isReadMethod } from \"./classification\";\nimport { getCacheTier } from \"./cache\";\nimport type { CacheTierConfig } from \"./shared-types\";\nimport { buildQueryKey, buildCacheKey, stableStringify, fnv1a } from \"./keys\";\nimport { resolveMethod, stableArgs } from \"./utils\";\nimport type { ProxyQueryOptions, ProxyMutationOptions } from \"./types\";\n\n/** Configuration for the options proxy (hooks). */\nexport interface OptionsProxyConfig {\n /** Per-tier cache overrides. */\n cache?: {\n static?: CacheTierConfig;\n semiStatic?: CacheTierConfig;\n };\n}\n\n/** Configuration for the actions proxy (server). */\nexport interface ActionsProxyConfig {\n /** Cache key prefix (e.g. \"ampro:\"). */\n cachePrefix?: string;\n /** Per-tier cache overrides. */\n cache?: {\n static?: CacheTierConfig;\n semiStatic?: CacheTierConfig;\n };\n /** Pre/post transforms per method path. */\n transforms?: Record<\n string,\n {\n pre?: (args: unknown[]) => unknown[];\n post?: (result: unknown) => unknown;\n }\n >;\n}\n\n/**\n * Creates a deep proxy that intercepts property access to build a method\n * path, then calls the handler when the proxy is invoked as a function.\n *\n * This is the core mechanism. `createOptionsProxy` and `createActionsProxy`\n * are thin wrappers that provide different handlers.\n */\nexport function createDeepProxy<TResult>(\n handler: (path: string[], args: unknown[]) => TResult,\n path: string[] = [],\n): unknown {\n /* v8 ignore next -- placeholder body, only the Proxy traps execute */\n const callable = function () {};\n\n return new Proxy(callable, {\n get(_target, prop: string | symbol) {\n if (typeof prop === \"symbol\") return undefined;\n return createDeepProxy(handler, [...path, prop]);\n },\n apply(_target, _thisArg, args: unknown[]) {\n return handler(path, args);\n },\n });\n}\n\n/**\n * Creates a proxy that returns TanStack Query options for every SDK method.\n *\n * Read methods (get, list, lookup, search, suggest) return ProxyQueryOptions.\n * Write methods (create, update, delete, etc.) return ProxyMutationOptions.\n *\n * @param api The SDK client instance\n * @param config Optional cache configuration\n * @returns Proxy mirroring the SDK with query/mutation options at every leaf\n *\n * @example\n * const q = createOptionsProxy(api);\n * const opts = q.items.invMast.stock.get(42);\n * // opts.queryKey → [\"items\", \"invMast\", \"stock\", \"get\", 42]\n * // opts.queryFn → () => api.items.invMast.stock.get(42)\n * // opts.staleTime → 60000 (semiStatic default)\n */\nexport function createOptionsProxy<TApi extends object>(\n api: TApi,\n config?: OptionsProxyConfig,\n): unknown {\n return createDeepProxy(\n (\n path: string[],\n args: unknown[],\n ): ProxyQueryOptions<unknown> | ProxyMutationOptions<unknown, unknown[]> => {\n const methodName = path[path.length - 1]!;\n const methodPath = path.join(\".\");\n const sdkMethod = resolveMethod(api, path);\n const normalizedArgs = stableArgs(args);\n\n if (isReadMethod(methodName)) {\n const tier = getCacheTier(methodPath, config?.cache);\n return {\n queryKey: buildQueryKey(path, normalizedArgs),\n queryFn: () => sdkMethod(...args) as Promise<unknown>,\n staleTime: tier.staleTime,\n gcTime: tier.gcTime,\n };\n }\n\n return {\n mutationKey: path,\n mutationFn: (...mutationArgs: unknown[]) =>\n sdkMethod(...mutationArgs) as Promise<unknown>,\n };\n },\n );\n}\n\n/**\n * Creates a proxy that wraps every SDK method as a direct async action.\n *\n * For read methods, the result is cached using the cache key builder.\n * For write methods, the call passes through directly.\n *\n * @param api The SDK client instance\n * @param config Optional cache and transform configuration\n * @returns Proxy mirroring the SDK with cached/transformed actions at every leaf\n *\n * @example\n * const actions = createActionsProxy(api, { cachePrefix: \"ampro:\" });\n * const stock = await actions.items.invMast.stock.get(42);\n */\nexport function createActionsProxy<TApi extends object>(\n api: TApi,\n config?: ActionsProxyConfig,\n): unknown {\n return createDeepProxy(async (path: string[], args: unknown[]) => {\n const methodPath = path.join(\".\");\n const sdkMethod = resolveMethod(api, path);\n const transform = config?.transforms?.[methodPath];\n\n const finalArgs = transform?.pre ? transform.pre(args) : args;\n const result = await (sdkMethod(...finalArgs) as Promise<unknown>);\n return transform?.post ? transform.post(result) : result;\n });\n}\n\n// Re-export key utilities for consumers who need to build keys manually\nexport { buildQueryKey, buildCacheKey, stableStringify, fnv1a };\n"],"mappings":";AAOA,IAAM,eAAe,oB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E;AAC1E,YAAM,aAAa,KAAK,KAAK,SAAS,CAAC;AACvC,YAAM,aAAa,KAAK,KAAK,GAAG;AAChC,YAAM,YAAY,cAAc,KAAK,IAAI;AACzC,YAAM,iBAAiB,WAAW,IAAI;AAEtC,UAAI,aAAa,UAAU,GAAG;AAC5B,cAAM,OAAO,aAAa,YAAY,QAAQ,KAAK;AACnD,eAAO;AAAA,UACL,UAAU,cAAc,MAAM,cAAc;AAAA,UAC5C,SAAS,MAAM,UAAU,GAAG,IAAI;AAAA,UAChC,WAAW,KAAK;AAAA,UAChB,QAAQ,KAAK;AAAA,QACf;AAAA,MACF;AAEA,aAAO;AAAA,QACL,aAAa;AAAA,QACb,YAAY,IAAI,iBACd,UAAU,GAAG,YAAY;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACF;AAgBO,SAAS,mBACd,KACA,QACS;AACT,SAAO,gBAAgB,OAAO,MAAgB,SAAoB;AAChE,UAAM,aAAa,KAAK,KAAK,GAAG;AAChC,UAAM,YAAY,cAAc,KAAK,IAAI;AACzC,UAAM,YAAY,QAAQ,aAAa,UAAU;AAEjD,UAAM,YAAY,WAAW,MAAM,UAAU,IAAI,IAAI,IAAI;AACzD,UAAM,SAAS,MAAO,UAAU,GAAG,SAAS;AAC5C,WAAO,WAAW,OAAO,UAAU,KAAK,MAAM,IAAI;AAAA,EACpD,CAAC;AACH;","names":["base","tier"]}
|
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-core/dist/testing.cjs","../src/testing.ts"],"names":[],"mappings":"AAAA;ACAA,4DAAiC;ADEjC;AACE;AACF,qDAAC","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-core/dist/testing.cjs","sourcesContent":[null,"export { createMockClient } from \"@simpleapps-com/augur-api/testing\";\nexport type {\n MockFn,\n DeepMockClient,\n MockClientResult,\n} from \"@simpleapps-com/augur-api/testing\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DeepMockClient, MockClientResult, MockFn, createMockClient } from '@simpleapps-com/augur-api/testing';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DeepMockClient, MockClientResult, MockFn, createMockClient } from '@simpleapps-com/augur-api/testing';
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing.ts"],"sourcesContent":["export { createMockClient } from \"@simpleapps-com/augur-api/testing\";\nexport type {\n MockFn,\n DeepMockClient,\n MockClientResult,\n} from \"@simpleapps-com/augur-api/testing\";\n"],"mappings":";AAAA,SAAS,wBAAwB;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@simpleapps-com/augur-core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Universal foundation for Augur packages — proxy infrastructure, cache keys, method classification, shared types",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/simpleapps-com/augur-packages.git",
|
|
9
|
+
"directory": "packages/augur-core"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./testing": {
|
|
19
|
+
"types": "./dist/testing.d.ts",
|
|
20
|
+
"import": "./dist/testing.js",
|
|
21
|
+
"require": "./dist/testing.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@simpleapps-com/augur-utils": "1.0.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@simpleapps-com/augur-api": "^0.9.12"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
36
|
+
"tsup": "^8.5.0",
|
|
37
|
+
"vitest": "^3.2.0",
|
|
38
|
+
"@augur-packages/tsconfig": "0.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup",
|
|
42
|
+
"dev": "tsup --watch",
|
|
43
|
+
"lint": "eslint src/",
|
|
44
|
+
"test": "vitest run --coverage",
|
|
45
|
+
"typecheck": "tsc --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|