@simpleapps-com/augur-server 0.5.1 → 1.0.1

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.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { E as EdgeCacheValue } from './site-D21WJ8z1.js';
2
- export { A as ActionResult, a as AddressValidationResult, b as AgrInfoActions, c as AgrInfoActionsConfig, d as AgrInfoApiClient, e as AgrSiteActions, f as AgrSiteActionsConfig, g as AgrSiteApiClient, h as AgrWorkActions, i as AgrWorkActionsConfig, j as AgrWorkApiClient, k as AvalaraActions, l as AvalaraActionsConfig, m as AvalaraApiClient, B as Basecamp2Actions, n as Basecamp2ActionsConfig, o as Basecamp2ApiClient, p as BrandFolderActions, q as BrandFolderActionsConfig, r as BrandFolderApiClient, C as CommerceActions, s as CommerceActionsConfig, t as CommerceApiClient, u as CustomerListResult, v as CustomersActions, w as CustomersActionsConfig, x as CustomersApiClient, G as GregorovichActions, y as GregorovichActionsConfig, z as GregorovichApiClient, I as ItemActions, D as ItemActionsConfig, F as ItemsApiClient, J as JoomlaActions, H as JoomlaActionsConfig, K as JoomlaApiClient, L as LegacyActions, M as LegacyActionsConfig, N as LegacyApiClient, O as LogisticsActions, P as LogisticsActionsConfig, Q as LogisticsApiClient, R as NexusActions, S as NexusActionsConfig, T as NexusApiClient, U as NormalizedUserProfile, V as OrderActions, W as OrderActionsConfig, X as OrderApiClient, Y as P21ApisActions, Z as P21ApisActionsConfig, _ as P21ApisApiClient, $ as P21CoreActions, a0 as P21CoreActionsConfig, a1 as P21CoreApiClient, a2 as P21PimActions, a3 as P21PimActionsConfig, a4 as P21PimApiClient, a5 as P21SismActions, a6 as P21SismActionsConfig, a7 as P21SismApiClient, a8 as PaymentsActions, a9 as PaymentsActionsConfig, aa as PaymentsApiClient, ab as PricingActions, ac as PricingActionsConfig, ad as PricingApiClient, ae as SearchActions, af as SearchActionsConfig, ag as SearchApiClient, ah as SearchPage, ai as ShippingActions, aj as ShippingActionsConfig, ak as ShippingAddress, al as ShippingApiClient, am as SiteActions, an as SiteActionsConfig, ao as SlackActions, ap as SlackActionsConfig, aq as SlackApiClient, ar as SmartyStreetsActions, as as SmartyStreetsActionsConfig, at as SmartyStreetsApiClient, au as UpsActions, av as UpsActionsConfig, aw as UpsApiClient, ax as VmiActions, ay as VmiActionsConfig, az as VmiApiClient, aA as createAgrInfoActions, aB as createAgrSiteActions, aC as createAgrWorkActions, aD as createAvalaraActions, aE as createBasecamp2Actions, aF as createBrandFolderActions, aG as createCommerceActions, aH as createCustomersActions, aI as createGregorovichActions, aJ as createItemActions, aK as createJoomlaActions, aL as createLegacyActions, aM as createLogisticsActions, aN as createNexusActions, aO as createOrderActions, aP as createP21ApisActions, aQ as createP21CoreActions, aR as createP21PimActions, aS as createP21SismActions, aT as createPaymentsActions, aU as createPricingActions, aV as createSearchActions, aW as createShippingActions, aX as createSiteActions, aY as createSlackActions, aZ as createSmartyStreetsActions, a_ as createUpsActions, a$ as createVmiActions, b0 as safeAction, b1 as sdkCall } from './site-D21WJ8z1.js';
3
1
  import { QueryClient } from '@tanstack/react-query';
4
2
  export { QueryOptionsConfig, createQueryOptions, createSuspenseQueryOptions } from './query.js';
3
+ export { A as AddressValidationResult, a as AgrInfoActions, b as AgrInfoActionsConfig, c as AgrInfoApiClient, d as AgrSiteActions, e as AgrSiteActionsConfig, f as AgrSiteApiClient, g as AgrWorkActions, h as AgrWorkActionsConfig, i as AgrWorkApiClient, j as AvalaraActions, k as AvalaraActionsConfig, l as AvalaraApiClient, B as Basecamp2Actions, m as Basecamp2ActionsConfig, n as Basecamp2ApiClient, o as BrandFolderActions, p as BrandFolderActionsConfig, q as BrandFolderApiClient, C as CommerceActions, r as CommerceActionsConfig, s as CommerceApiClient, t as CustomerListResult, u as CustomersActions, v as CustomersActionsConfig, w as CustomersApiClient, G as GregorovichActions, x as GregorovichActionsConfig, y as GregorovichApiClient, I as ItemActions, z as ItemActionsConfig, D as ItemsApiClient, J as JoomlaActions, E as JoomlaActionsConfig, F as JoomlaApiClient, L as LegacyActions, H as LegacyActionsConfig, K as LegacyApiClient, M as LogisticsActions, N as LogisticsActionsConfig, O as LogisticsApiClient, P as NexusActions, Q as NexusActionsConfig, R as NexusApiClient, S as NormalizedUserProfile, T as OrderActions, U as OrderActionsConfig, V as OrderApiClient, W as P21ApisActions, X as P21ApisActionsConfig, Y as P21ApisApiClient, Z as P21CoreActions, _ as P21CoreActionsConfig, $ as P21CoreApiClient, a0 as P21PimActions, a1 as P21PimActionsConfig, a2 as P21PimApiClient, a3 as P21SismActions, a4 as P21SismActionsConfig, a5 as P21SismApiClient, a6 as PaymentsActions, a7 as PaymentsActionsConfig, a8 as PaymentsApiClient, a9 as PricingActions, aa as PricingActionsConfig, ab as PricingApiClient, ac as SearchActions, ad as SearchActionsConfig, ae as SearchApiClient, af as SearchPage, ag as ShippingActions, ah as ShippingActionsConfig, ai as ShippingAddress, aj as ShippingApiClient, ak as SiteActions, al as SiteActionsConfig, am as SlackActions, an as SlackActionsConfig, ao as SlackApiClient, ap as SmartyStreetsActions, aq as SmartyStreetsActionsConfig, ar as SmartyStreetsApiClient, as as UpsActions, at as UpsActionsConfig, au as UpsApiClient, av as VmiActions, aw as VmiActionsConfig, ax as VmiApiClient, ay as createAgrInfoActions, az as createAgrSiteActions, aA as createAgrWorkActions, aB as createAvalaraActions, aC as createBasecamp2Actions, aD as createBrandFolderActions, aE as createCommerceActions, aF as createCustomersActions, aG as createGregorovichActions, aH as createItemActions, aI as createJoomlaActions, aJ as createLegacyActions, aK as createLogisticsActions, aL as createNexusActions, aM as createOrderActions, aN as createP21ApisActions, aO as createP21CoreActions, aP as createP21PimActions, aQ as createP21SismActions, aR as createPaymentsActions, aS as createPricingActions, aT as createSearchActions, aU as createShippingActions, aV as createSiteActions, aW as createSlackActions, aX as createSmartyStreetsActions, aY as createUpsActions, aZ as createVmiActions } from './site-CfLO511J.js';
5
4
  import { AugurAPI } from '@simpleapps-com/augur-api';
5
+ import { EdgeCacheValue } from '@simpleapps-com/augur-core';
6
+ export { ActionResult, EdgeCacheValue } from '@simpleapps-com/augur-core';
6
7
  import '@simpleapps-com/augur-utils';
7
8
 
8
9
  declare const env: "development" | "staging" | "production";
@@ -15,6 +16,54 @@ declare function cacheSet(key: string, value: string, ttlSeconds: number): Promi
15
16
  declare function getCircuitState(): "closed" | "open";
16
17
  declare function isRedisConnected(): boolean;
17
18
 
19
+ /**
20
+ * Calls an Augur SDK method, forwarding all arguments with full type safety.
21
+ *
22
+ * With augur-api >= 0.9.6, SDK methods properly declare their `CacheParams`
23
+ * option (including `edgeCache`), so this wrapper preserves both parameter
24
+ * and return-type inference end-to-end.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const result = await sdkCall(
29
+ * augurServices.items.invMast.get,
30
+ * invMastUid,
31
+ * { edgeCache: 4 },
32
+ * );
33
+ * ```
34
+ */
35
+ declare function sdkCall<TArgs extends unknown[], TResult>(method: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
36
+ /**
37
+ * Wraps an async function call with error handling, returning an
38
+ * `ActionResult<T>` instead of throwing.
39
+ *
40
+ * Use this to eliminate try/catch boilerplate in server actions.
41
+ * Reads that go through React Query should NOT use this — let errors
42
+ * propagate so React Query can handle retries and error state.
43
+ *
44
+ * @param fn — The async function to execute
45
+ * @param onError — Optional callback for logging/reporting
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const result = await safeAction(
50
+ * () => actions.commerce.addToCart(cartId, items),
51
+ * );
52
+ * if (result.ok) {
53
+ * // result.data is the response
54
+ * } else {
55
+ * // result.error is the error message
56
+ * }
57
+ * ```
58
+ */
59
+ declare function safeAction<T>(fn: () => Promise<T>, onError?: (error: Error) => void): Promise<{
60
+ ok: true;
61
+ data: T;
62
+ } | {
63
+ ok: false;
64
+ error: string;
65
+ }>;
66
+
18
67
  /**
19
68
  * Fetches data for multiple params in parallel, returning a Record keyed by
20
69
  * `getKey(param)`. Individual failures are silently excluded from the result
@@ -43,7 +92,8 @@ declare const getServerQueryClient: () => QueryClient;
43
92
  /**
44
93
  * Server-side cache wrapper using augur-server's Redis client.
45
94
  *
46
- * Uses the same cache key format as augur-hooks' `withCache`:
95
+ * Uses the same cache key format as augur-hooks' client-side caching
96
+ * via augur-core's `buildCacheKey`:
47
97
  * `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(keyArgs))}`
48
98
  *
49
99
  * This means server-side cached data can be read by client-side hooks
@@ -131,4 +181,4 @@ interface FavoritesActions {
131
181
  }
132
182
  declare function createFavoritesActions(api: FavoritesApiClient, config?: FavoritesActionsConfig): FavoritesActions;
133
183
 
134
- export { EdgeCacheValue, type FavoritesActions, type FavoritesActionsConfig, type FavoritesApiClient, type PaginatedResult, type WishlistActions, type WishlistActionsConfig, type WishlistsApiClient, batchFetch, cacheGet, cacheSet, createFavoritesActions, createServerQueryClient, createWishlistActions, env, getCircuitState, getServerQueryClient, isDev, isProduction, isRedisConnected, isStaging, paginateOffset, withServerCache };
184
+ export { type FavoritesActions, type FavoritesActionsConfig, type FavoritesApiClient, type PaginatedResult, type WishlistActions, type WishlistActionsConfig, type WishlistsApiClient, batchFetch, cacheGet, cacheSet, createFavoritesActions, createServerQueryClient, createWishlistActions, env, getCircuitState, getServerQueryClient, isDev, isProduction, isRedisConnected, isStaging, paginateOffset, safeAction, sdkCall, withServerCache };
package/dist/index.js CHANGED
@@ -150,30 +150,10 @@ async function safeAction(fn, onError) {
150
150
  }
151
151
 
152
152
  // src/cache/with-cache.ts
153
- function fnv1a(str) {
154
- let h = 2166136261;
155
- for (let i = 0; i < str.length; i++) {
156
- h ^= str.charCodeAt(i);
157
- h = Math.imul(h, 16777619);
158
- }
159
- return (h >>> 0).toString(16).padStart(8, "0");
160
- }
161
- function stableStringify(value) {
162
- if (value === null || value === void 0) return JSON.stringify(value);
163
- if (typeof value !== "object") return JSON.stringify(value);
164
- if (Array.isArray(value)) {
165
- return `[${value.map(stableStringify).join(",")}]`;
166
- }
167
- const obj = value;
168
- const keys = Object.keys(obj).sort();
169
- const entries = keys.map(
170
- (key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`
171
- );
172
- return `{${entries.join(",")}}`;
173
- }
153
+ import { buildCacheKey } from "@simpleapps-com/augur-core";
174
154
  async function withServerCache(prefix, redisTtl, methodPath, fn, ...keyArgs) {
175
155
  if (!redisTtl) return fn();
176
- const key = `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(keyArgs))}`;
156
+ const key = buildCacheKey(prefix, methodPath, keyArgs);
177
157
  try {
178
158
  const cached = await cacheGet(key);
179
159
  if (cached != null) return JSON.parse(cached);