@simpleapps-com/augur-server 2.0.6 → 2.0.7
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 +5 -5
- package/dist/actions.js +1 -1
- package/dist/actions.js.map +1 -1
- package/dist/{chunk-OHXPJ225.js → chunk-6T2IRPPO.js} +2 -8
- package/dist/chunk-6T2IRPPO.js.map +1 -0
- package/dist/{chunk-3YLC52GL.js → chunk-RQIWNNTR.js} +2 -2
- package/dist/chunk-RQIWNNTR.js.map +1 -0
- package/dist/index.d.ts +53 -6
- package/dist/index.js +2 -2
- package/dist/{server-site-registry-BtBMmWYF.d.ts → server-site-registry-C76mQOn1.d.ts} +1 -1
- package/dist/{site-C1raVxkq.d.ts → site-DIkAeW67.d.ts} +1 -1
- package/dist/site.d.ts +2 -2
- package/dist/site.js +2 -2
- package/dist/{smarty-streets-DshoLeug.d.ts → smarty-streets-xhe-ldMO.d.ts} +2 -2
- package/dist/testing.d.ts +3 -3
- package/package.json +5 -5
- package/dist/chunk-3YLC52GL.js.map +0 -1
- package/dist/chunk-OHXPJ225.js.map +0 -1
- package/dist/sdk-call-CPDSzeu0.d.ts +0 -80
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk-call.ts"],"sourcesContent":["// Re-export shared types from augur-core (single source of truth)\nexport type {\n EdgeCacheValue,\n ActionResult,\n ApiResult,\n ListResult,\n} from \"@simpleapps-com/augur-core\";\nimport type { ApiResult, ListResult } 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/**\n * @deprecated No longer needed — `SafeActionResult<T>` uses `T` directly.\n * Kept as a passthrough alias for backwards compatibility.\n */\nexport type SafeData<T> = T;\n\n/**\n * Extracts an ApiResult from an SDK response, preserving envelope metadata.\n * Use this for single-item endpoints where `data` is a single object.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function toApiResult<T>(response: any): ApiResult<T> {\n return {\n data: response.data as T,\n total: response.total ?? 0,\n count: response.count,\n totalResults: response.totalResults,\n message: response.message,\n status: response.status,\n };\n}\n\n/**\n * Extracts a ListResult from an SDK response, preserving envelope metadata.\n * Use this for list endpoints where `data` is an array.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function toListResult<T>(response: any): ListResult<T> {\n return {\n data: response.data as T[],\n total: response.total ?? 0,\n count: response.count,\n totalResults: response.totalResults,\n message: response.message,\n status: response.status,\n };\n}\n\n/** Result type for `safeAction`. */\nexport type SafeActionResult<T> = { ok: true; data: T } | { 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 * @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 the response data (undefined for void actions)\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 as 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>): 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>): T | null {\n return result.ok ? (result.data ?? null) : null;\n}\n"],"mappings":";AAyBA,eAAsB,QACpB,WACG,MACe;AAClB,SAAO,OAAO,GAAG,IAAI;AACvB;AA6BO,SAAS,aAAgB,UAA8B;AAC5D,SAAO;AAAA,IACL,MAAM,SAAS;AAAA,IACf,OAAO,SAAS,SAAS;AAAA,IACzB,OAAO,SAAS;AAAA,IAChB,cAAc,SAAS;AAAA,IACvB,SAAS,SAAS;AAAA,IAClB,QAAQ,SAAS;AAAA,EACnB;AACF;AA4BA,eAAsB,WACpB,IACA,SAC8B;AAC9B,MAAI;AACF,UAAM,OAAO,MAAM,GAAG;AACtB,WAAO,EAAE,IAAI,MAAM,KAAgB;AAAA,EACrC,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,QAAgC;AACxD,MAAI,CAAC,OAAO,GAAI,OAAM,IAAI,MAAM,OAAO,SAAS,eAAe;AAC/D,SAAO,OAAO;AAChB;AAaO,SAAS,SAAY,QAAuC;AACjE,SAAO,OAAO,KAAM,OAAO,QAAQ,OAAQ;AAC7C;","names":[]}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calls an Augur SDK method, forwarding all arguments with full type safety.
|
|
3
|
-
*
|
|
4
|
-
* With augur-api >= 0.9.6, SDK methods properly declare their `CacheParams`
|
|
5
|
-
* option (including `edgeCache`), so this wrapper preserves both parameter
|
|
6
|
-
* and return-type inference end-to-end.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const result = await sdkCall(
|
|
11
|
-
* augurServices.items.invMast.get,
|
|
12
|
-
* invMastUid,
|
|
13
|
-
* { edgeCache: 4 },
|
|
14
|
-
* );
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
declare function sdkCall<TArgs extends unknown[], TResult>(method: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated No longer needed — `SafeActionResult<T>` uses `T` directly.
|
|
20
|
-
* Kept as a passthrough alias for backwards compatibility.
|
|
21
|
-
*/
|
|
22
|
-
type SafeData<T> = T;
|
|
23
|
-
/** Result type for `safeAction`. */
|
|
24
|
-
type SafeActionResult<T> = {
|
|
25
|
-
ok: true;
|
|
26
|
-
data: T;
|
|
27
|
-
} | {
|
|
28
|
-
ok: false;
|
|
29
|
-
error: string;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Wraps an async function call with error handling, returning a
|
|
33
|
-
* `SafeActionResult<T>` instead of throwing.
|
|
34
|
-
*
|
|
35
|
-
* Use this to eliminate try/catch boilerplate in server actions.
|
|
36
|
-
* Reads that go through React Query should NOT use this — let errors
|
|
37
|
-
* propagate so React Query can handle retries and error state.
|
|
38
|
-
*
|
|
39
|
-
* @param fn — The async function to execute
|
|
40
|
-
* @param onError — Optional callback for logging/reporting
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* const result = await safeAction(
|
|
45
|
-
* () => actions.commerce.addToCart(cartId, items),
|
|
46
|
-
* );
|
|
47
|
-
* if (result.ok) {
|
|
48
|
-
* // result.data is the response data (undefined for void actions)
|
|
49
|
-
* } else {
|
|
50
|
-
* // result.error is the error message
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
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>): 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>): T | null;
|
|
79
|
-
|
|
80
|
-
export { type SafeActionResult as S, type SafeData as a, sdkCall as b, unwrapOr as c, safeAction as s, unwrap as u };
|