@simpleapps-com/augur-server 2.2.21 → 2.2.23

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/api.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Generic API route handler for fetch-mode proxy.
3
+ *
4
+ * Exposes the existing queryAction as an HTTP POST endpoint so that
5
+ * `createFetchQueryAction()` from augur-core can route calls through
6
+ * fetch() instead of server actions. This is needed on platforms where
7
+ * server actions cannot access request cookies (e.g., CF Workers via OpenNext).
8
+ *
9
+ * The handler validates same-origin requests via the Sec-Fetch-Site header
10
+ * (set by browsers automatically and cannot be forged by scripts).
11
+ */
12
+ /**
13
+ * Creates a Next.js Route Handler that routes method calls through queryAction.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * // app/api/augur/route.ts
18
+ * import { createAugurApiHandler } from "@simpleapps-com/augur-server/api";
19
+ *
20
+ * const handler = createAugurApiHandler();
21
+ * export const POST = handler;
22
+ * ```
23
+ */
24
+ declare function createAugurApiHandler(): (req: Request) => Promise<Response>;
25
+
26
+ export { createAugurApiHandler };
package/dist/api.js ADDED
@@ -0,0 +1,39 @@
1
+ import {
2
+ queryAction
3
+ } from "./chunk-OOR3XGUT.js";
4
+ import "./chunk-HPQQYROJ.js";
5
+ import "./chunk-DGUM43GV.js";
6
+
7
+ // src/api-handler.ts
8
+ function createAugurApiHandler() {
9
+ return async (req) => {
10
+ const fetchSite = req.headers.get("sec-fetch-site");
11
+ if (fetchSite && fetchSite !== "same-origin") {
12
+ return new Response("Forbidden: cross-origin requests not allowed", { status: 403 });
13
+ }
14
+ let body;
15
+ try {
16
+ body = await req.json();
17
+ } catch {
18
+ return new Response("Invalid JSON body", { status: 400 });
19
+ }
20
+ const { methodPath, args } = body;
21
+ if (typeof methodPath !== "string" || !methodPath) {
22
+ return new Response("Missing or invalid methodPath", { status: 400 });
23
+ }
24
+ if (!Array.isArray(args)) {
25
+ return new Response("Missing or invalid args array", { status: 400 });
26
+ }
27
+ try {
28
+ const result = await queryAction(methodPath, ...args);
29
+ return Response.json(result);
30
+ } catch (error) {
31
+ const message = error instanceof Error ? error.message : "Internal server error";
32
+ return new Response(message, { status: 500 });
33
+ }
34
+ };
35
+ }
36
+ export {
37
+ createAugurApiHandler
38
+ };
39
+ //# sourceMappingURL=api.js.map
@@ -0,0 +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 } from \"./query-action\";\n\n/** Request body shape for the API handler. */\ninterface AugurApiRequestBody {\n methodPath: string;\n args: unknown[];\n}\n\n/**\n * Creates a Next.js Route Handler that routes method calls through queryAction.\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 const fetchSite = req.headers.get(\"sec-fetch-site\");\n if (fetchSite && fetchSite !== \"same-origin\") {\n return new Response(\"Forbidden: cross-origin requests not allowed\", { status: 403 });\n }\n\n let body: AugurApiRequestBody;\n try {\n body = (await req.json()) as AugurApiRequestBody;\n } catch {\n return new Response(\"Invalid JSON body\", { status: 400 });\n }\n\n const { methodPath, args } = body;\n\n if (typeof methodPath !== \"string\" || !methodPath) {\n return new Response(\"Missing or invalid methodPath\", { status: 400 });\n }\n\n if (!Array.isArray(args)) {\n return new Response(\"Missing or invalid args array\", { status: 400 });\n }\n\n try {\n const result = await queryAction(methodPath, ...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":";;;;;;;AAgCO,SAAS,wBAAwB;AACtC,SAAO,OAAO,QAAoC;AAGhD,UAAM,YAAY,IAAI,QAAQ,IAAI,gBAAgB;AAClD,QAAI,aAAa,cAAc,eAAe;AAC5C,aAAO,IAAI,SAAS,gDAAgD,EAAE,QAAQ,IAAI,CAAC;AAAA,IACrF;AAEA,QAAI;AACJ,QAAI;AACF,aAAQ,MAAM,IAAI,KAAK;AAAA,IACzB,QAAQ;AACN,aAAO,IAAI,SAAS,qBAAqB,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC1D;AAEA,UAAM,EAAE,YAAY,KAAK,IAAI;AAE7B,QAAI,OAAO,eAAe,YAAY,CAAC,YAAY;AACjD,aAAO,IAAI,SAAS,iCAAiC,EAAE,QAAQ,IAAI,CAAC;AAAA,IACtE;AAEA,QAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACxB,aAAO,IAAI,SAAS,iCAAiC,EAAE,QAAQ,IAAI,CAAC;AAAA,IACtE;AAEA,QAAI;AACF,YAAM,SAAS,MAAM,YAAY,YAAY,GAAG,IAAI;AACpD,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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleapps-com/augur-server",
3
- "version": "2.2.21",
3
+ "version": "2.2.23",
4
4
  "description": "Server-side utilities for Augur ecommerce sites (Redis caching, SDK helpers, auth)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -42,6 +42,10 @@
42
42
  "types": "./dist/query-action.d.ts",
43
43
  "import": "./dist/query-action.js"
44
44
  },
45
+ "./api": {
46
+ "types": "./dist/api.d.ts",
47
+ "import": "./dist/api.js"
48
+ },
45
49
  "./next-auth": {
46
50
  "types": "./next-auth.d.ts"
47
51
  }
@@ -54,9 +58,9 @@
54
58
  "llms.txt"
55
59
  ],
56
60
  "dependencies": {
57
- "@simpleapps-com/augur-core": "2.2.21",
58
- "@simpleapps-com/augur-hooks": "2.2.21",
59
- "@simpleapps-com/augur-utils": "2.2.21"
61
+ "@simpleapps-com/augur-core": "2.2.23",
62
+ "@simpleapps-com/augur-hooks": "2.2.23",
63
+ "@simpleapps-com/augur-utils": "2.2.23"
60
64
  },
61
65
  "peerDependencies": {
62
66
  "@simpleapps-com/augur-api": "^2026.3.7",
@@ -84,7 +88,7 @@
84
88
  "tsup": "^8.5.0",
85
89
  "vitest": "^3.2.0",
86
90
  "@augur-packages/tsconfig": "0.0.0",
87
- "@simpleapps-com/augur-hooks": "2.2.21"
91
+ "@simpleapps-com/augur-hooks": "2.2.23"
88
92
  },
89
93
  "scripts": {
90
94
  "build": "tsup",