@simpleapps-com/augur-server 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.d.ts +1 -1
- package/dist/actions.js +1 -1
- package/dist/{chunk-ZBS5CNBC.js → chunk-C3V6CBNQ.js} +11 -2
- package/dist/{chunk-ZBS5CNBC.js.map → chunk-C3V6CBNQ.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/{sdk-call-BgnoWAZK.d.ts → sdk-call-CaW_esvl.d.ts} +25 -1
- package/package.json +5 -5
package/dist/actions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SafeActionResult } from './sdk-call-
|
|
1
|
+
import { S as SafeActionResult } from './sdk-call-CaW_esvl.js';
|
|
2
2
|
import { C as CustomerListResult, k as ShippingAddress, N as NormalizedUserProfile, h as SearchPage, A as AddressValidationResult } from './smarty-streets-BS4ifhxQ.js';
|
|
3
3
|
import { TInvMastDoc, TPriceData, TStockData, TCartLookUp, TCartLine, TInvMast, TItemAccessory, TAttribute, TCategory, TWebDesc, TTaxItem, TTax, TProductItem } from '@simpleapps-com/augur-utils';
|
|
4
4
|
import '@simpleapps-com/augur-api';
|
package/dist/actions.js
CHANGED
|
@@ -12,9 +12,18 @@ async function safeAction(fn, onError) {
|
|
|
12
12
|
return { ok: false, error: error.message };
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
function unwrap(result) {
|
|
16
|
+
if (!result.ok) throw new Error(result.error || "Action failed");
|
|
17
|
+
return result.data;
|
|
18
|
+
}
|
|
19
|
+
function unwrapOr(result) {
|
|
20
|
+
return result.ok ? result.data ?? null : null;
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
export {
|
|
17
24
|
sdkCall,
|
|
18
|
-
safeAction
|
|
25
|
+
safeAction,
|
|
26
|
+
unwrap,
|
|
27
|
+
unwrapOr
|
|
19
28
|
};
|
|
20
|
-
//# sourceMappingURL=chunk-
|
|
29
|
+
//# sourceMappingURL=chunk-C3V6CBNQ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk-call.ts"],"sourcesContent":["// Re-export EdgeCacheValue and ActionResult from augur-core (single source of truth)\nexport type { EdgeCacheValue, ActionResult } from \"@simpleapps-com/augur-core\";\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\n/** Maps void-returning actions to `true` so `data` is never `undefined` on success. */\nexport type SafeData<T> = T extends void ? true : T;\n\n/** Result type for `safeAction` — void-returning actions get `data: true`. */\nexport type SafeActionResult<T> =\n | { ok: true; data: SafeData<T> }\n | { ok: false; error: string };\n\n/**\n * Wraps an async function call with error handling, returning a\n * `SafeActionResult<T>` instead of throwing.\n *\n * Use this to eliminate try/catch boilerplate in server actions.\n * Reads that go through React Query should NOT use this — let errors\n * propagate so React Query can handle retries and error state.\n *\n * When the wrapped function returns `void`, `data` is set to `true`\n * so that `result.data` is never `undefined` on a successful call.\n *\n * @param fn — The async function to execute\n * @param onError — Optional callback for logging/reporting\n *\n * @example\n * ```ts\n * const result = await safeAction(\n * () => actions.commerce.addToCart(cartId, items),\n * );\n * if (result.ok) {\n * // result.data is `true` for void actions, or the response data\n * } else {\n * // result.error is the error message\n * }\n * ```\n */\nexport async function safeAction<T>(\n fn: () => Promise<T>,\n onError?: (error: Error) => void,\n): Promise<SafeActionResult<T>> {\n try {\n const data = await fn();\n return { ok: true, data: (data ?? true) as SafeData<T> };\n } catch (e) {\n const error = e instanceof Error ? e : new Error(String(e));\n if (onError) onError(error);\n return { ok: false, error: error.message };\n }\n}\n"],"mappings":";AAmBA,eAAsB,QACpB,WACG,MACe;AAClB,SAAO,OAAO,GAAG,IAAI;AACvB;AAoCA,eAAsB,WACpB,IACA,SAC8B;AAC9B,MAAI;AACF,UAAM,OAAO,MAAM,GAAG;AACtB,WAAO,EAAE,IAAI,MAAM,MAAO,QAAQ,KAAqB;AAAA,EACzD,SAAS,GAAG;AACV,UAAM,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC;AAC1D,QAAI,QAAS,SAAQ,KAAK;AAC1B,WAAO,EAAE,IAAI,OAAO,OAAO,MAAM,QAAQ;AAAA,EAC3C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/sdk-call.ts"],"sourcesContent":["// Re-export EdgeCacheValue and ActionResult from augur-core (single source of truth)\nexport type { EdgeCacheValue, ActionResult } from \"@simpleapps-com/augur-core\";\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\n/** Maps void-returning actions to `true` so `data` is never `undefined` on success. */\nexport type SafeData<T> = T extends void ? true : T;\n\n/** Result type for `safeAction` — void-returning actions get `data: true`. */\nexport type SafeActionResult<T> =\n | { ok: true; data: SafeData<T> }\n | { ok: false; error: string };\n\n/**\n * Wraps an async function call with error handling, returning a\n * `SafeActionResult<T>` instead of throwing.\n *\n * Use this to eliminate try/catch boilerplate in server actions.\n * Reads that go through React Query should NOT use this — let errors\n * propagate so React Query can handle retries and error state.\n *\n * When the wrapped function returns `void`, `data` is set to `true`\n * so that `result.data` is never `undefined` on a successful call.\n *\n * @param fn — The async function to execute\n * @param onError — Optional callback for logging/reporting\n *\n * @example\n * ```ts\n * const result = await safeAction(\n * () => actions.commerce.addToCart(cartId, items),\n * );\n * if (result.ok) {\n * // result.data is `true` for void actions, or the response data\n * } else {\n * // result.error is the error message\n * }\n * ```\n */\nexport async function safeAction<T>(\n fn: () => Promise<T>,\n onError?: (error: Error) => void,\n): Promise<SafeActionResult<T>> {\n try {\n const data = await fn();\n return { ok: true, data: (data ?? true) as SafeData<T> };\n } catch (e) {\n const error = e instanceof Error ? e : new Error(String(e));\n if (onError) onError(error);\n return { ok: false, error: error.message };\n }\n}\n\n/**\n * Extracts the data from a `SafeActionResult`, throwing on error.\n *\n * Ideal for React Query `queryFn` where errors should propagate\n * to the error boundary.\n *\n * @example\n * ```ts\n * const cart = unwrap(await getCartLines(cartId));\n * ```\n */\nexport function unwrap<T>(result: SafeActionResult<T>): SafeData<T> {\n if (!result.ok) throw new Error(result.error || \"Action failed\");\n return result.data;\n}\n\n/**\n * Extracts the data from a `SafeActionResult`, returning `null` on error.\n *\n * For direct calls that prefer `null` over thrown errors.\n *\n * @example\n * ```ts\n * const cart = unwrapOr(await getCartLines(cartId));\n * if (!cart) { /* handle missing data *\\/ }\n * ```\n */\nexport function unwrapOr<T>(result: SafeActionResult<T>): SafeData<T> | null {\n return result.ok ? result.data ?? null : null;\n}\n"],"mappings":";AAmBA,eAAsB,QACpB,WACG,MACe;AAClB,SAAO,OAAO,GAAG,IAAI;AACvB;AAoCA,eAAsB,WACpB,IACA,SAC8B;AAC9B,MAAI;AACF,UAAM,OAAO,MAAM,GAAG;AACtB,WAAO,EAAE,IAAI,MAAM,MAAO,QAAQ,KAAqB;AAAA,EACzD,SAAS,GAAG;AACV,UAAM,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC;AAC1D,QAAI,QAAS,SAAQ,KAAK;AAC1B,WAAO,EAAE,IAAI,OAAO,OAAO,MAAM,QAAQ;AAAA,EAC3C;AACF;AAaO,SAAS,OAAU,QAA0C;AAClE,MAAI,CAAC,OAAO,GAAI,OAAM,IAAI,MAAM,OAAO,SAAS,eAAe;AAC/D,SAAO,OAAO;AAChB;AAaO,SAAS,SAAY,QAAiD;AAC3E,SAAO,OAAO,KAAK,OAAO,QAAQ,OAAO;AAC3C;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { S as SafeActionResult, a as SafeData, s as safeAction, b as sdkCall } from './sdk-call-
|
|
1
|
+
export { S as SafeActionResult, a as SafeData, s as safeAction, b as sdkCall, u as unwrap, c as unwrapOr } from './sdk-call-CaW_esvl.js';
|
|
2
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
3
|
export { QueryOptionsConfig, createQueryOptions, createSuspenseQueryOptions } from './query.js';
|
|
4
4
|
export { A as AgrInfoActions, a as AgrInfoActionsConfig, b as AgrInfoApiClient, c as AgrSiteActions, d as AgrSiteActionsConfig, e as AgrSiteApiClient, f as AgrWorkActions, g as AgrWorkActionsConfig, h as AgrWorkApiClient, i as AvalaraActions, j as AvalaraActionsConfig, k as AvalaraApiClient, B as Basecamp2Actions, l as Basecamp2ActionsConfig, m as Basecamp2ApiClient, n as BrandFolderActions, o as BrandFolderActionsConfig, p as BrandFolderApiClient, C as CommerceActions, q as CommerceActionsConfig, r as CommerceApiClient, G as GregorovichActions, s as GregorovichActionsConfig, t as GregorovichApiClient, I as ItemActions, u as ItemActionsConfig, v as ItemsApiClient, L as LegacyActions, w as LegacyActionsConfig, x as LegacyApiClient, y as LogisticsActions, z as LogisticsActionsConfig, D as LogisticsApiClient, N as NexusActions, E as NexusActionsConfig, F as NexusApiClient, O as OrderActions, H as OrderActionsConfig, J as OrderApiClient, P as P21ApisActions, K as P21ApisActionsConfig, M as P21ApisApiClient, Q as P21CoreActions, R as P21CoreActionsConfig, S as P21CoreApiClient, T as P21PimActions, U as P21PimActionsConfig, V as P21PimApiClient, W as P21SismActions, X as P21SismActionsConfig, Y as P21SismApiClient, Z as PaymentsActions, _ as PaymentsActionsConfig, $ as PaymentsApiClient, a0 as PricingActions, a1 as PricingActionsConfig, a2 as PricingApiClient, a3 as SiteActions, a4 as SiteActionsConfig, a5 as SlackActions, a6 as SlackActionsConfig, a7 as SlackApiClient, a8 as UpsActions, a9 as UpsActionsConfig, aa as UpsApiClient, ab as VmiActions, ac as VmiActionsConfig, ad as VmiApiClient, ae as createAgrInfoActions, af as createAgrSiteActions, ag as createAgrWorkActions, ah as createAvalaraActions, ai as createBasecamp2Actions, aj as createBrandFolderActions, ak as createCommerceActions, al as createGregorovichActions, am as createItemActions, an as createLegacyActions, ao as createLogisticsActions, ap as createNexusActions, aq as createOrderActions, ar as createP21ApisActions, as as createP21CoreActions, at as createP21PimActions, au as createP21SismActions, av as createPaymentsActions, aw as createPricingActions, ax as createSiteActions, ay as createSlackActions, az as createUpsActions, aA as createVmiActions } from './site-BKPGMqQx.js';
|
package/dist/index.js
CHANGED
|
@@ -50,8 +50,10 @@ import {
|
|
|
50
50
|
} from "./chunk-XGRQ53P2.js";
|
|
51
51
|
import {
|
|
52
52
|
safeAction,
|
|
53
|
-
sdkCall
|
|
54
|
-
|
|
53
|
+
sdkCall,
|
|
54
|
+
unwrap,
|
|
55
|
+
unwrapOr
|
|
56
|
+
} from "./chunk-C3V6CBNQ.js";
|
|
55
57
|
import {
|
|
56
58
|
getSiteActions,
|
|
57
59
|
registerSiteActions
|
|
@@ -208,6 +210,8 @@ export {
|
|
|
208
210
|
registerSiteActions,
|
|
209
211
|
safeAction,
|
|
210
212
|
sdkCall,
|
|
213
|
+
unwrap,
|
|
214
|
+
unwrapOr,
|
|
211
215
|
withServerCache
|
|
212
216
|
};
|
|
213
217
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pagination.ts","../src/actions/wishlists.ts","../src/actions/favorites.ts"],"sourcesContent":["/**\n * Standardized paginated response shape.\n * Works with any factory method — compose with `paginateOffset()`.\n */\nexport interface PaginatedResult<T> {\n data: T[];\n total?: number;\n nextCursor?: number;\n hasMore: boolean;\n}\n\n/**\n * Wraps a list of items with offset-based pagination metadata.\n *\n * Use this to standardize pagination responses from any factory method.\n * Compatible with React Query's infinite query pattern (`getNextPageParam`).\n *\n * @param items - The items returned from the current page\n * @param pageParam - The current page number (0-based)\n * @param limit - The page size\n * @param total - Optional total count of items (from API response)\n *\n * @example\n * ```ts\n * const result = await actions.items.getCategoryItems(uid, {\n * ...filters, offset: page * 24, limit: 24,\n * });\n * return paginateOffset(result.items, page, 24, result.total);\n * // { data: [...], total: 150, nextCursor: 1, hasMore: true }\n * ```\n */\nexport function paginateOffset<T>(\n items: T[],\n pageParam: number,\n limit: number,\n total?: number,\n): PaginatedResult<T> {\n const hasMore =\n total !== undefined\n ? (pageParam + 1) * limit < total\n : items.length === limit;\n\n return {\n data: items,\n total,\n nextCursor: hasMore ? pageParam + 1 : undefined,\n hasMore,\n };\n}\n","import type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport type { EdgeCacheValue } from \"../sdk-call\";\nimport { withServerCache } from \"../cache/with-cache\";\n\n/** Derived from augur-api SDK — keeps types in sync automatically. */\nexport type WishlistsApiClient = Pick<AugurAPI, \"items\">;\n\nexport interface WishlistActionsConfig {\n /** Cache key prefix (e.g. \"ampro:\"). Default: \"\". */\n cachePrefix?: string;\n /** CDN edge cache value passed to SDK. Default: 1 (hour). */\n edgeCache?: EdgeCacheValue;\n /** Redis TTL in seconds. Default: 3600 (1 hour). */\n redisTtl?: number;\n}\n\nexport interface WishlistActions {\n getWishlists: (userId: number) => Promise<unknown[]>;\n createWishlist: (\n userId: number,\n data: { name: string; description?: string },\n ) => Promise<unknown>;\n getWishlistDetail: (\n userId: number,\n wishlistId: number,\n ) => Promise<unknown>;\n deleteWishlist: (userId: number, wishlistId: number) => Promise<void>;\n addWishlistItems: (\n userId: number,\n wishlistId: number,\n items: { invMastUid: number }[],\n ) => Promise<unknown>;\n removeWishlistItem: (\n userId: number,\n wishlistId: number,\n lineId: number,\n ) => Promise<void>;\n}\n\n/** @deprecated Use `createSiteActions()` instead. This factory will be removed in the next major version. */\nexport function createWishlistActions(\n api: WishlistsApiClient,\n config: WishlistActionsConfig = {},\n): WishlistActions {\n const { cachePrefix = \"\", edgeCache = 1, redisTtl = 3600 } = config;\n\n async function getWishlists(userId: number): Promise<unknown[]> {\n return withServerCache(\n cachePrefix,\n redisTtl,\n \"items.itemWishlist.list\",\n async () => {\n const response = await api.items.itemWishlist.list(userId, {\n edgeCache,\n });\n return response.data;\n },\n userId,\n );\n }\n\n async function createWishlist(\n userId: number,\n data: { name: string; description?: string },\n ): Promise<unknown> {\n const response = await api.items.itemWishlist.create(userId, data);\n return response.data;\n }\n\n async function getWishlistDetail(\n userId: number,\n wishlistId: number,\n ): Promise<unknown> {\n return withServerCache(\n cachePrefix,\n redisTtl,\n \"items.itemWishlist.hdr.get\",\n async () => {\n const response = await api.items.itemWishlist.hdr.get(\n userId,\n wishlistId,\n { edgeCache },\n );\n return response.data;\n },\n userId,\n wishlistId,\n );\n }\n\n async function deleteWishlist(\n userId: number,\n wishlistId: number,\n ): Promise<void> {\n await api.items.itemWishlist.hdr.delete(userId, wishlistId);\n }\n\n async function addWishlistItems(\n userId: number,\n wishlistId: number,\n items: { invMastUid: number }[],\n ): Promise<unknown> {\n const response = await api.items.itemWishlist.hdr.create(\n userId,\n wishlistId,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n items as any,\n );\n return response.data;\n }\n\n async function removeWishlistItem(\n userId: number,\n wishlistId: number,\n lineId: number,\n ): Promise<void> {\n await api.items.itemWishlist.hdr.line.delete(userId, wishlistId, lineId);\n }\n\n return {\n getWishlists,\n createWishlist,\n getWishlistDetail,\n deleteWishlist,\n addWishlistItems,\n removeWishlistItem,\n };\n}\n","import type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport type { EdgeCacheValue } from \"../sdk-call\";\nimport { withServerCache } from \"../cache/with-cache\";\n\n/** Derived from augur-api SDK — keeps types in sync automatically. */\nexport type FavoritesApiClient = Pick<AugurAPI, \"items\">;\n\nexport interface FavoritesActionsConfig {\n /** Cache key prefix (e.g. \"ampro:\"). Default: \"\". */\n cachePrefix?: string;\n /** CDN edge cache value passed to SDK. Default: 1 (hour). */\n edgeCache?: EdgeCacheValue;\n /** Redis TTL in seconds. Default: 3600 (1 hour). */\n redisTtl?: number;\n}\n\nexport interface FavoritesActions {\n getFavorites: (userId: number) => Promise<unknown[]>;\n addFavorite: (userId: number, invMastUid: number) => Promise<unknown>;\n removeFavorite: (userId: number, invMastUid: number) => Promise<void>;\n}\n\n/** @deprecated Use `createSiteActions()` instead. This factory will be removed in the next major version. */\nexport function createFavoritesActions(\n api: FavoritesApiClient,\n config: FavoritesActionsConfig = {},\n): FavoritesActions {\n const { cachePrefix = \"\", edgeCache = 1, redisTtl = 3600 } = config;\n\n async function getFavorites(userId: number): Promise<unknown[]> {\n return withServerCache(\n cachePrefix,\n redisTtl,\n \"items.itemFavorites.list\",\n async () => {\n const response = await api.items.itemFavorites.list(userId, {\n edgeCache,\n });\n return response.data;\n },\n userId,\n );\n }\n\n async function addFavorite(\n userId: number,\n invMastUid: number,\n ): Promise<unknown> {\n const response = await api.items.itemFavorites.create(userId, {\n invMastUid,\n });\n return response.data;\n }\n\n async function removeFavorite(\n userId: number,\n invMastUid: number,\n ): Promise<void> {\n await api.items.itemFavorites.delete(userId, invMastUid);\n }\n\n return { getFavorites, addFavorite, removeFavorite };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/pagination.ts","../src/actions/wishlists.ts","../src/actions/favorites.ts"],"sourcesContent":["/**\n * Standardized paginated response shape.\n * Works with any factory method — compose with `paginateOffset()`.\n */\nexport interface PaginatedResult<T> {\n data: T[];\n total?: number;\n nextCursor?: number;\n hasMore: boolean;\n}\n\n/**\n * Wraps a list of items with offset-based pagination metadata.\n *\n * Use this to standardize pagination responses from any factory method.\n * Compatible with React Query's infinite query pattern (`getNextPageParam`).\n *\n * @param items - The items returned from the current page\n * @param pageParam - The current page number (0-based)\n * @param limit - The page size\n * @param total - Optional total count of items (from API response)\n *\n * @example\n * ```ts\n * const result = await actions.items.getCategoryItems(uid, {\n * ...filters, offset: page * 24, limit: 24,\n * });\n * return paginateOffset(result.items, page, 24, result.total);\n * // { data: [...], total: 150, nextCursor: 1, hasMore: true }\n * ```\n */\nexport function paginateOffset<T>(\n items: T[],\n pageParam: number,\n limit: number,\n total?: number,\n): PaginatedResult<T> {\n const hasMore =\n total !== undefined\n ? (pageParam + 1) * limit < total\n : items.length === limit;\n\n return {\n data: items,\n total,\n nextCursor: hasMore ? pageParam + 1 : undefined,\n hasMore,\n };\n}\n","import type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport type { EdgeCacheValue } from \"../sdk-call\";\nimport { withServerCache } from \"../cache/with-cache\";\n\n/** Derived from augur-api SDK — keeps types in sync automatically. */\nexport type WishlistsApiClient = Pick<AugurAPI, \"items\">;\n\nexport interface WishlistActionsConfig {\n /** Cache key prefix (e.g. \"ampro:\"). Default: \"\". */\n cachePrefix?: string;\n /** CDN edge cache value passed to SDK. Default: 1 (hour). */\n edgeCache?: EdgeCacheValue;\n /** Redis TTL in seconds. Default: 3600 (1 hour). */\n redisTtl?: number;\n}\n\nexport interface WishlistActions {\n getWishlists: (userId: number) => Promise<unknown[]>;\n createWishlist: (\n userId: number,\n data: { name: string; description?: string },\n ) => Promise<unknown>;\n getWishlistDetail: (\n userId: number,\n wishlistId: number,\n ) => Promise<unknown>;\n deleteWishlist: (userId: number, wishlistId: number) => Promise<void>;\n addWishlistItems: (\n userId: number,\n wishlistId: number,\n items: { invMastUid: number }[],\n ) => Promise<unknown>;\n removeWishlistItem: (\n userId: number,\n wishlistId: number,\n lineId: number,\n ) => Promise<void>;\n}\n\n/** @deprecated Use `createSiteActions()` instead. This factory will be removed in the next major version. */\nexport function createWishlistActions(\n api: WishlistsApiClient,\n config: WishlistActionsConfig = {},\n): WishlistActions {\n const { cachePrefix = \"\", edgeCache = 1, redisTtl = 3600 } = config;\n\n async function getWishlists(userId: number): Promise<unknown[]> {\n return withServerCache(\n cachePrefix,\n redisTtl,\n \"items.itemWishlist.list\",\n async () => {\n const response = await api.items.itemWishlist.list(userId, {\n edgeCache,\n });\n return response.data;\n },\n userId,\n );\n }\n\n async function createWishlist(\n userId: number,\n data: { name: string; description?: string },\n ): Promise<unknown> {\n const response = await api.items.itemWishlist.create(userId, data);\n return response.data;\n }\n\n async function getWishlistDetail(\n userId: number,\n wishlistId: number,\n ): Promise<unknown> {\n return withServerCache(\n cachePrefix,\n redisTtl,\n \"items.itemWishlist.hdr.get\",\n async () => {\n const response = await api.items.itemWishlist.hdr.get(\n userId,\n wishlistId,\n { edgeCache },\n );\n return response.data;\n },\n userId,\n wishlistId,\n );\n }\n\n async function deleteWishlist(\n userId: number,\n wishlistId: number,\n ): Promise<void> {\n await api.items.itemWishlist.hdr.delete(userId, wishlistId);\n }\n\n async function addWishlistItems(\n userId: number,\n wishlistId: number,\n items: { invMastUid: number }[],\n ): Promise<unknown> {\n const response = await api.items.itemWishlist.hdr.create(\n userId,\n wishlistId,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n items as any,\n );\n return response.data;\n }\n\n async function removeWishlistItem(\n userId: number,\n wishlistId: number,\n lineId: number,\n ): Promise<void> {\n await api.items.itemWishlist.hdr.line.delete(userId, wishlistId, lineId);\n }\n\n return {\n getWishlists,\n createWishlist,\n getWishlistDetail,\n deleteWishlist,\n addWishlistItems,\n removeWishlistItem,\n };\n}\n","import type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport type { EdgeCacheValue } from \"../sdk-call\";\nimport { withServerCache } from \"../cache/with-cache\";\n\n/** Derived from augur-api SDK — keeps types in sync automatically. */\nexport type FavoritesApiClient = Pick<AugurAPI, \"items\">;\n\nexport interface FavoritesActionsConfig {\n /** Cache key prefix (e.g. \"ampro:\"). Default: \"\". */\n cachePrefix?: string;\n /** CDN edge cache value passed to SDK. Default: 1 (hour). */\n edgeCache?: EdgeCacheValue;\n /** Redis TTL in seconds. Default: 3600 (1 hour). */\n redisTtl?: number;\n}\n\nexport interface FavoritesActions {\n getFavorites: (userId: number) => Promise<unknown[]>;\n addFavorite: (userId: number, invMastUid: number) => Promise<unknown>;\n removeFavorite: (userId: number, invMastUid: number) => Promise<void>;\n}\n\n/** @deprecated Use `createSiteActions()` instead. This factory will be removed in the next major version. */\nexport function createFavoritesActions(\n api: FavoritesApiClient,\n config: FavoritesActionsConfig = {},\n): FavoritesActions {\n const { cachePrefix = \"\", edgeCache = 1, redisTtl = 3600 } = config;\n\n async function getFavorites(userId: number): Promise<unknown[]> {\n return withServerCache(\n cachePrefix,\n redisTtl,\n \"items.itemFavorites.list\",\n async () => {\n const response = await api.items.itemFavorites.list(userId, {\n edgeCache,\n });\n return response.data;\n },\n userId,\n );\n }\n\n async function addFavorite(\n userId: number,\n invMastUid: number,\n ): Promise<unknown> {\n const response = await api.items.itemFavorites.create(userId, {\n invMastUid,\n });\n return response.data;\n }\n\n async function removeFavorite(\n userId: number,\n invMastUid: number,\n ): Promise<void> {\n await api.items.itemFavorites.delete(userId, invMastUid);\n }\n\n return { getFavorites, addFavorite, removeFavorite };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BO,SAAS,eACd,OACA,WACA,OACA,OACoB;AACpB,QAAM,UACJ,UAAU,UACL,YAAY,KAAK,QAAQ,QAC1B,MAAM,WAAW;AAEvB,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA,YAAY,UAAU,YAAY,IAAI;AAAA,IACtC;AAAA,EACF;AACF;;;ACRO,SAAS,sBACd,KACA,SAAgC,CAAC,GAChB;AACjB,QAAM,EAAE,cAAc,IAAI,YAAY,GAAG,WAAW,KAAK,IAAI;AAE7D,iBAAe,aAAa,QAAoC;AAC9D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AACV,cAAM,WAAW,MAAM,IAAI,MAAM,aAAa,KAAK,QAAQ;AAAA,UACzD;AAAA,QACF,CAAC;AACD,eAAO,SAAS;AAAA,MAClB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,iBAAe,eACb,QACA,MACkB;AAClB,UAAM,WAAW,MAAM,IAAI,MAAM,aAAa,OAAO,QAAQ,IAAI;AACjE,WAAO,SAAS;AAAA,EAClB;AAEA,iBAAe,kBACb,QACA,YACkB;AAClB,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AACV,cAAM,WAAW,MAAM,IAAI,MAAM,aAAa,IAAI;AAAA,UAChD;AAAA,UACA;AAAA,UACA,EAAE,UAAU;AAAA,QACd;AACA,eAAO,SAAS;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,iBAAe,eACb,QACA,YACe;AACf,UAAM,IAAI,MAAM,aAAa,IAAI,OAAO,QAAQ,UAAU;AAAA,EAC5D;AAEA,iBAAe,iBACb,QACA,YACA,OACkB;AAClB,UAAM,WAAW,MAAM,IAAI,MAAM,aAAa,IAAI;AAAA,MAChD;AAAA,MACA;AAAA;AAAA,MAEA;AAAA,IACF;AACA,WAAO,SAAS;AAAA,EAClB;AAEA,iBAAe,mBACb,QACA,YACA,QACe;AACf,UAAM,IAAI,MAAM,aAAa,IAAI,KAAK,OAAO,QAAQ,YAAY,MAAM;AAAA,EACzE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;ACxGO,SAAS,uBACd,KACA,SAAiC,CAAC,GAChB;AAClB,QAAM,EAAE,cAAc,IAAI,YAAY,GAAG,WAAW,KAAK,IAAI;AAE7D,iBAAe,aAAa,QAAoC;AAC9D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AACV,cAAM,WAAW,MAAM,IAAI,MAAM,cAAc,KAAK,QAAQ;AAAA,UAC1D;AAAA,QACF,CAAC;AACD,eAAO,SAAS;AAAA,MAClB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,iBAAe,YACb,QACA,YACkB;AAClB,UAAM,WAAW,MAAM,IAAI,MAAM,cAAc,OAAO,QAAQ;AAAA,MAC5D;AAAA,IACF,CAAC;AACD,WAAO,SAAS;AAAA,EAClB;AAEA,iBAAe,eACb,QACA,YACe;AACf,UAAM,IAAI,MAAM,cAAc,OAAO,QAAQ,UAAU;AAAA,EACzD;AAEA,SAAO,EAAE,cAAc,aAAa,eAAe;AACrD;","names":[]}
|
|
@@ -52,5 +52,29 @@ type SafeActionResult<T> = {
|
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
54
|
declare function safeAction<T>(fn: () => Promise<T>, onError?: (error: Error) => void): Promise<SafeActionResult<T>>;
|
|
55
|
+
/**
|
|
56
|
+
* Extracts the data from a `SafeActionResult`, throwing on error.
|
|
57
|
+
*
|
|
58
|
+
* Ideal for React Query `queryFn` where errors should propagate
|
|
59
|
+
* to the error boundary.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const cart = unwrap(await getCartLines(cartId));
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function unwrap<T>(result: SafeActionResult<T>): SafeData<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Extracts the data from a `SafeActionResult`, returning `null` on error.
|
|
69
|
+
*
|
|
70
|
+
* For direct calls that prefer `null` over thrown errors.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const cart = unwrapOr(await getCartLines(cartId));
|
|
75
|
+
* if (!cart) { /* handle missing data *\/ }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare function unwrapOr<T>(result: SafeActionResult<T>): SafeData<T> | null;
|
|
55
79
|
|
|
56
|
-
export { type SafeActionResult as S, type SafeData as a, sdkCall as b, safeAction as s };
|
|
80
|
+
export { type SafeActionResult as S, type SafeData as a, sdkCall as b, unwrapOr as c, safeAction as s, unwrap as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simpleapps-com/augur-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "Server-side utilities for Augur ecommerce sites (Redis caching, SDK helpers, auth)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"valibot": "^1.0.0",
|
|
52
|
-
"@simpleapps-com/augur-core": "1.0.
|
|
53
|
-
"@simpleapps-com/augur-utils": "1.0.
|
|
52
|
+
"@simpleapps-com/augur-core": "1.0.18",
|
|
53
|
+
"@simpleapps-com/augur-utils": "1.0.18"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@simpleapps-com/augur-api": "^2026.3.1",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"next": "^16.1.6",
|
|
60
60
|
"next-auth": ">=5.0.0-beta.30",
|
|
61
61
|
"react": "^19.0.0",
|
|
62
|
-
"@simpleapps-com/augur-hooks": "1.0.
|
|
62
|
+
"@simpleapps-com/augur-hooks": "1.0.18"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"ioredis": {
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"tsup": "^8.5.0",
|
|
83
83
|
"vitest": "^3.2.0",
|
|
84
84
|
"@augur-packages/tsconfig": "0.0.0",
|
|
85
|
-
"@simpleapps-com/augur-hooks": "1.0.
|
|
85
|
+
"@simpleapps-com/augur-hooks": "1.0.18"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "tsup",
|