@simpleapps-com/augur-server 2026.11.6 → 2026.11.8
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/README.md +12 -0
- package/dist/actions/commerce.d.ts +19 -8
- package/dist/actions/commerce.d.ts.map +1 -1
- package/dist/api-handler.d.ts.map +1 -1
- package/dist/api.js +1 -1
- package/dist/api.js.map +1 -1
- package/dist/{chunk-SFXO74RC.js → chunk-5PIBNKCX.js} +6 -4
- package/dist/chunk-5PIBNKCX.js.map +1 -0
- package/dist/{chunk-2RAKVFB5.js → chunk-GJHQPBK7.js} +4 -2
- package/dist/chunk-GJHQPBK7.js.map +1 -0
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +3 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/query-action.d.ts +11 -4
- package/dist/query-action.d.ts.map +1 -1
- package/dist/query-action.js +1 -1
- package/dist/site.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-2RAKVFB5.js.map +0 -1
- package/dist/chunk-SFXO74RC.js.map +0 -1
package/README.md
CHANGED
|
@@ -43,6 +43,18 @@ cancels it too (server code only: a signal can't cross a server action from the
|
|
|
43
43
|
options never enter the cache key. It needs an `@simpleapps-com/augur-api` with
|
|
44
44
|
`AugurAPI.withRequest`; on an older client the call is refused rather than run unbounded.
|
|
45
45
|
|
|
46
|
+
**Typed by path** (atlas#103): `queryAction` and `queryActionWith` take one of the SDK's method
|
|
47
|
+
paths, that method's own arguments, and return its `data` type (augur-core `MethodPath`,
|
|
48
|
+
`MethodArgs`, `MethodData`; model `models/AugurQueryTypes.dfy`), so an unknown path or arguments
|
|
49
|
+
that no longer match an upgraded SDK fail `tsc` instead of a live request, and `as` casts on the
|
|
50
|
+
result can go. **On upgrade a site may see new type errors: they are real bugs** (calls the SDK
|
|
51
|
+
would refuse). Pass one literal path per call: a union of paths is typed loosely. A path built at
|
|
52
|
+
runtime has no literal type: cast the path, `queryAction(path as MethodPath<AugurAPI>, ...args)`
|
|
53
|
+
(augur-core `MethodPath`; its arguments are then `unknown[]` and its result `unknown`), as
|
|
54
|
+
`createAugurApiHandler` does; the allowlist still checks it. `createAugurOptions(queryAction)`, `registerQueryAction` and
|
|
55
|
+
`createServerQueryProxy` accept it as before (`AnyQueryAction`), and `vi.mocked(queryAction)`
|
|
56
|
+
keeps its untyped signature. `queryActionRaw` / `queryActionRawWith` keep their caller-named `T`.
|
|
57
|
+
|
|
46
58
|
**Reads** (atlas#102): every site-action read follows a read spec (`src/actions/read-specs.ts`).
|
|
47
59
|
|
|
48
60
|
- **Paging:** a read that returns every row pages 100 rows a call until an empty page, at most 50 calls, and returns `{ data, total, capReached }` (so `getWishlistDetail` no longer returns a bare array). `capReached` is true when the cap stopped it: the result may be incomplete.
|
|
@@ -9,6 +9,18 @@ export interface CommerceActionsConfig {
|
|
|
9
9
|
/** Optional UOM conversion function. E.g. (uom) => uom === "EA" ? "EACH" : uom */
|
|
10
10
|
convertUnitOfMeasure?: (uom: string) => string;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* A cart line as `updateCartLines` sends it: `lineNo` 0 makes the server match by item and unit of
|
|
14
|
+
* measure; `unitPrice` goes only when the line has one (a sent `null` is stored as 0.0).
|
|
15
|
+
*/
|
|
16
|
+
interface CartLineSent {
|
|
17
|
+
lineNo: number;
|
|
18
|
+
invMastUid: number;
|
|
19
|
+
quantity: number;
|
|
20
|
+
unitOfMeasure: string;
|
|
21
|
+
unitPrice?: number;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
12
24
|
export interface CommerceActions {
|
|
13
25
|
cartHdrLookup: (params: {
|
|
14
26
|
userId?: string | number;
|
|
@@ -17,19 +29,17 @@ export interface CommerceActions {
|
|
|
17
29
|
customerId?: string | number;
|
|
18
30
|
}) => Promise<TCartLookUp | false>;
|
|
19
31
|
getCartLines: (cartHdrUid: number) => Promise<ListResult<TCartLine>>;
|
|
32
|
+
/** Resolves `true` when the server added every item. */
|
|
20
33
|
addToCart: (cartHdrUid: number, items: {
|
|
21
34
|
itemId?: string;
|
|
22
35
|
invMastUid: number;
|
|
23
36
|
quantity: number;
|
|
24
37
|
unitOfMeasure: string;
|
|
25
|
-
}[]) => Promise<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
unitOfMeasure: string;
|
|
31
|
-
}[]) => Promise<unknown>;
|
|
32
|
-
deleteCartItems: (cartHdrUid: number) => Promise<void>;
|
|
38
|
+
}[]) => Promise<boolean>;
|
|
39
|
+
/** Resolves `true` when the server answered success (it sends `lineNo` 0 to match by item and unit). */
|
|
40
|
+
updateCartLines: (cartHdrUid: number, lines: CartLineSent[]) => Promise<boolean>;
|
|
41
|
+
/** Resolves `true` when the server emptied the cart, `false` on a failure. */
|
|
42
|
+
deleteCartItems: (cartHdrUid: number) => Promise<boolean>;
|
|
33
43
|
getCartAlsoBought: (cartHdrUid: number) => Promise<ListResult<CommerceTypes.CartHdrAlsoBoughtListItem>>;
|
|
34
44
|
checkoutOrder: (cartHdrUid: number, data: Record<string, unknown>) => Promise<TCheckoutResult>;
|
|
35
45
|
}
|
|
@@ -55,4 +65,5 @@ export interface CommerceActions {
|
|
|
55
65
|
* const lines = await commerceActions.getCartLines(cart.cartHdrUid);
|
|
56
66
|
* ``` */
|
|
57
67
|
export declare function createCommerceActions(api: CommerceApiClient, config?: CommerceActionsConfig): CommerceActions;
|
|
68
|
+
export {};
|
|
58
69
|
//# sourceMappingURL=commerce.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commerce.d.ts","sourceRoot":"","sources":["../../src/actions/commerce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,E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AAE,KACA,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtB,wGAAwG;IACxG,eAAe,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjF,8EAA8E;IAC9E,eAAe,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1D,iBAAiB,EAAE,CACjB,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAElE,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;CAChG;AAED;;;;;;;;;;;;;;;;;;;;SAoBS;AACT,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,iBAAiB,EACtB,MAAM,GAAE,qBAA0B,GACjC,eAAe,CAuGjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.d.ts","sourceRoot":"","sources":["../src/api-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"api-handler.d.ts","sourceRoot":"","sources":["../src/api-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA2BH;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,KACrB,KAAK,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAiC/C"}
|
package/dist/api.js
CHANGED
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api-handler.ts"],"sourcesContent":["/**\n * Generic API route handler for fetch-mode proxy.\n *\n * Exposes the existing queryAction as an HTTP POST endpoint so that\n * `createFetchQueryAction()` from augur-core can route calls through\n * fetch() instead of server actions. This is needed on platforms where\n * server actions cannot access request cookies (e.g., CF Workers via OpenNext).\n *\n * The handler validates same-origin requests via the Sec-Fetch-Site header\n * (set by browsers automatically and cannot be forged by scripts).\n */\n\nimport { queryAction, queryActionRaw } from \"./query-action\";\nimport {\n answersFullOf,\n apiMessageOf,\n apiStatusOf,\n bodyOutcomeOf,\n isCrossOrigin,\n runsOf,\n type ApiOutcome,\n} from \"./rules\";\n\n/** A refused request's response: the outcome's text and status. */\nfunction refusal(outcome: ApiOutcome): Response {\n return new Response(apiMessageOf(outcome), { status: apiStatusOf(outcome) });\n}\n\n/** Request body shape for the API handler; `raw: true` asks for the full response. */\ninterface AugurApiRequestBody {\n methodPath: string;\n args: unknown[];\n raw?: unknown;\n}\n\n/**\n * Creates a Next.js Route Handler that routes method calls through queryAction, or through\n * queryActionRaw when the body has `raw: true` (augur-core's `createFetchQueryActionRaw`).\n *\n * @example\n * ```ts\n * // app/api/augur/route.ts\n * import { createAugurApiHandler } from \"@simpleapps-com/augur-server/api\";\n *\n * const handler = createAugurApiHandler();\n * export const POST = handler;\n * ```\n */\nexport function createAugurApiHandler() {\n return async (req: Request): Promise<Response> => {\n // Same-origin validation: Sec-Fetch-Site is set by browsers and\n // cannot be forged by JavaScript. Reject cross-origin requests.\n if (isCrossOrigin(req.headers.get(\"sec-fetch-site\") ?? \"\")) return refusal(\"forbidden\");\n\n let body: AugurApiRequestBody;\n try {\n body = (await req.json()) as AugurApiRequestBody;\n } catch {\n return refusal(\"bad-json\");\n }\n\n const { methodPath, args, raw } = body;\n const outcome = bodyOutcomeOf(\n true,\n typeof methodPath === \"string\" && methodPath !== \"\",\n Array.isArray(args),\n raw === true,\n );\n if (!runsOf(outcome)) return refusal(outcome);\n\n try {\n const result = answersFullOf(outcome)\n ? await queryActionRaw(methodPath, ...args)\n : await queryAction(methodPath
|
|
1
|
+
{"version":3,"sources":["../src/api-handler.ts"],"sourcesContent":["/**\n * Generic API route handler for fetch-mode proxy.\n *\n * Exposes the existing queryAction as an HTTP POST endpoint so that\n * `createFetchQueryAction()` from augur-core can route calls through\n * fetch() instead of server actions. This is needed on platforms where\n * server actions cannot access request cookies (e.g., CF Workers via OpenNext).\n *\n * The handler validates same-origin requests via the Sec-Fetch-Site header\n * (set by browsers automatically and cannot be forged by scripts).\n */\n\nimport type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport type { MethodPath } from \"@simpleapps-com/augur-core\";\nimport { queryAction, queryActionRaw } from \"./query-action\";\nimport {\n answersFullOf,\n apiMessageOf,\n apiStatusOf,\n bodyOutcomeOf,\n isCrossOrigin,\n runsOf,\n type ApiOutcome,\n} from \"./rules\";\n\n/** A refused request's response: the outcome's text and status. */\nfunction refusal(outcome: ApiOutcome): Response {\n return new Response(apiMessageOf(outcome), { status: apiStatusOf(outcome) });\n}\n\n/** Request body shape for the API handler; `raw: true` asks for the full response. */\ninterface AugurApiRequestBody {\n methodPath: string;\n args: unknown[];\n raw?: unknown;\n}\n\n/**\n * Creates a Next.js Route Handler that routes method calls through queryAction, or through\n * queryActionRaw when the body has `raw: true` (augur-core's `createFetchQueryActionRaw`).\n *\n * @example\n * ```ts\n * // app/api/augur/route.ts\n * import { createAugurApiHandler } from \"@simpleapps-com/augur-server/api\";\n *\n * const handler = createAugurApiHandler();\n * export const POST = handler;\n * ```\n */\nexport function createAugurApiHandler() {\n return async (req: Request): Promise<Response> => {\n // Same-origin validation: Sec-Fetch-Site is set by browsers and\n // cannot be forged by JavaScript. Reject cross-origin requests.\n if (isCrossOrigin(req.headers.get(\"sec-fetch-site\") ?? \"\")) return refusal(\"forbidden\");\n\n let body: AugurApiRequestBody;\n try {\n body = (await req.json()) as AugurApiRequestBody;\n } catch {\n return refusal(\"bad-json\");\n }\n\n const { methodPath, args, raw } = body;\n const outcome = bodyOutcomeOf(\n true,\n typeof methodPath === \"string\" && methodPath !== \"\",\n Array.isArray(args),\n raw === true,\n );\n if (!runsOf(outcome)) return refusal(outcome);\n\n try {\n // The path arrives in a request, so it has no literal type: typed as any method path, its\n // arguments are unknown[] (atlas#103), and the allowlist checks it at runtime\n const result = answersFullOf(outcome)\n ? await queryActionRaw(methodPath, ...args)\n : await queryAction(methodPath as MethodPath<AugurAPI>, ...args);\n return Response.json(result);\n } catch (error) {\n const message = error instanceof Error ? error.message : \"Internal server error\";\n return new Response(message, { status: 500 });\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,SAAS,QAAQ,SAA+B;AAC9C,SAAO,IAAI,SAAS,aAAa,OAAO,GAAG,EAAE,QAAQ,YAAY,OAAO,EAAE,CAAC;AAC7E;AAsBO,SAAS,wBAAwB;AACtC,SAAO,OAAO,QAAoC;AAGhD,QAAI,cAAc,IAAI,QAAQ,IAAI,gBAAgB,KAAK,EAAE,EAAG,QAAO,QAAQ,WAAW;AAEtF,QAAI;AACJ,QAAI;AACF,aAAQ,MAAM,IAAI,KAAK;AAAA,IACzB,QAAQ;AACN,aAAO,QAAQ,UAAU;AAAA,IAC3B;AAEA,UAAM,EAAE,YAAY,MAAM,IAAI,IAAI;AAClC,UAAM,UAAU;AAAA,MACd;AAAA,MACA,OAAO,eAAe,YAAY,eAAe;AAAA,MACjD,MAAM,QAAQ,IAAI;AAAA,MAClB,QAAQ;AAAA,IACV;AACA,QAAI,CAAC,OAAO,OAAO,EAAG,QAAO,QAAQ,OAAO;AAE5C,QAAI;AAGF,YAAM,SAAS,cAAc,OAAO,IAChC,MAAM,eAAe,YAAY,GAAG,IAAI,IACxC,MAAM,YAAY,YAAoC,GAAG,IAAI;AACjE,aAAO,SAAS,KAAK,MAAM;AAAA,IAC7B,SAAS,OAAO;AACd,YAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;AACzD,aAAO,IAAI,SAAS,SAAS,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC9C;AAAA,EACF;AACF;","names":[]}
|
|
@@ -935,7 +935,7 @@ function createCommerceActions(api, config = {}) {
|
|
|
935
935
|
unitOfMeasure: lineUom(convertUnitOfMeasure?.(item.unitOfMeasure), item.unitOfMeasure)
|
|
936
936
|
}));
|
|
937
937
|
const response = await api.commerce.cartLine.add.create(cartHdrUid, mappedItems);
|
|
938
|
-
return response.data;
|
|
938
|
+
return response.data === true;
|
|
939
939
|
}
|
|
940
940
|
async function updateCartLines(cartHdrUid, lines) {
|
|
941
941
|
const mappedLines = lines.map((line) => ({
|
|
@@ -943,12 +943,14 @@ function createCommerceActions(api, config = {}) {
|
|
|
943
943
|
unitOfMeasure: lineUom(convertUnitOfMeasure?.(line.unitOfMeasure), line.unitOfMeasure)
|
|
944
944
|
}));
|
|
945
945
|
const response = await api.commerce.cartLine.update.create(cartHdrUid, mappedLines);
|
|
946
|
-
return response.data;
|
|
946
|
+
return response.data === true;
|
|
947
947
|
}
|
|
948
948
|
async function deleteCartItems(cartHdrUid) {
|
|
949
949
|
try {
|
|
950
|
-
await api.commerce.cartLine.delete(cartHdrUid);
|
|
950
|
+
const response = await api.commerce.cartLine.delete(cartHdrUid);
|
|
951
|
+
return response.data === true;
|
|
951
952
|
} catch {
|
|
953
|
+
return false;
|
|
952
954
|
}
|
|
953
955
|
}
|
|
954
956
|
async function getCartAlsoBought(cartHdrUid) {
|
|
@@ -2497,4 +2499,4 @@ export {
|
|
|
2497
2499
|
getSiteActions,
|
|
2498
2500
|
clearSiteActions2 as clearSiteActions
|
|
2499
2501
|
};
|
|
2500
|
-
//# sourceMappingURL=chunk-
|
|
2502
|
+
//# sourceMappingURL=chunk-5PIBNKCX.js.map
|