@simpleapps-com/augur-server 2026.11.3 → 2026.11.5
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/EXPORTS.md +5 -2
- package/README.md +21 -12
- package/dist/api-handler.d.ts +2 -1
- package/dist/api-handler.d.ts.map +1 -1
- package/dist/api.js +12 -8
- package/dist/api.js.map +1 -1
- package/dist/auth.js +2 -2
- package/dist/{chunk-RGOLZMU3.js → chunk-6GPKXGPG.js} +21 -3
- package/dist/{chunk-RGOLZMU3.js.map → chunk-6GPKXGPG.js.map} +1 -1
- package/dist/{chunk-R573MZQL.js → chunk-FIM6LDMD.js} +39 -13
- package/dist/chunk-FIM6LDMD.js.map +1 -0
- package/dist/{chunk-22B3WOGA.js → chunk-KSGH4DXD.js} +2 -2
- package/dist/{chunk-5I7TBMGU.js → chunk-U54IM6FL.js} +2 -2
- package/dist/hooks.js +2 -2
- package/dist/index.js +2 -2
- package/dist/query-action.d.ts +44 -98
- package/dist/query-action.d.ts.map +1 -1
- package/dist/query-action.js +8 -2
- package/dist/rules.d.ts +36 -4
- package/dist/rules.d.ts.map +1 -1
- package/dist/site.js +3 -3
- package/dist/testing.js +2 -2
- package/llms.txt +13 -2
- package/package.json +5 -5
- package/dist/chunk-R573MZQL.js.map +0 -1
- /package/dist/{chunk-22B3WOGA.js.map → chunk-KSGH4DXD.js.map} +0 -0
- /package/dist/{chunk-5I7TBMGU.js.map → chunk-U54IM6FL.js.map} +0 -0
package/EXPORTS.md
CHANGED
|
@@ -113,7 +113,10 @@
|
|
|
113
113
|
| Export | Kind | Description |
|
|
114
114
|
|--------|------|-------------|
|
|
115
115
|
| `getSessionCredentials` | function | Resolve session credentials from the Auth.js JWT cookie. |
|
|
116
|
-
| `queryAction` | function |
|
|
116
|
+
| `queryAction` | function | The SDK call `callSdk` makes (everything above), answered as its envelope's data. |
|
|
117
|
+
| `queryActionRaw` | function | The same call as `queryAction` (allowlist, client, `edgeCache` strip, Redis), answered as the SDK returned it: augur-api's `BaseResponse<T>` envelope (every SDK method's result) with `data`, `total`, `totalResults` and `count`, so client code can page a list (atlas#107). A method path carries no type, so the caller names `T` (`queryActionRaw<Article[]>(…)`). A `queryAction` and a `queryActionRaw` of one call share one Redis entry. |
|
|
118
|
+
| `queryActionRawWith` | function | `queryActionRaw`, bounded: the same options as {@link queryActionWith}. |
|
|
119
|
+
| `queryActionWith` | function | `queryAction`, bounded (atlas#106): `options.deadline` caps the whole call in milliseconds (every retry and the waits between them), and `options.signal` lets the caller cancel it. At the deadline the call rejects with a `TimeoutError` (the request is cancelled, nothing more is retried, nothing is cached), so a server render can fall back to a client-side fetch. |
|
|
117
120
|
| `resetSessionImports` | function | Reset lazy-loaded imports. Used in tests only. @internal |
|
|
118
121
|
| `resolveMethod` | function | Resolve a dot-separated method path on an object, returning the leaf function. |
|
|
119
122
|
| `unwrapBaseResponse` | value | |
|
|
@@ -124,7 +127,7 @@
|
|
|
124
127
|
|
|
125
128
|
| Export | Kind | Description |
|
|
126
129
|
|--------|------|-------------|
|
|
127
|
-
| `createAugurApiHandler` | function | Creates a Next.js Route Handler that routes method calls through queryAction. |
|
|
130
|
+
| `createAugurApiHandler` | function | Creates a Next.js Route Handler that routes method calls through queryAction, or through queryActionRaw when the body has `raw: true` (augur-core's `createFetchQueryActionRaw`). |
|
|
128
131
|
|
|
129
132
|
## `@simpleapps-com/augur-server/next-auth`
|
|
130
133
|
|
package/README.md
CHANGED
|
@@ -15,24 +15,33 @@ version; nothing requires them to share one.
|
|
|
15
15
|
pnpm add @simpleapps-com/augur-server
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
| Import | Purpose
|
|
19
|
-
| ------------------------------------------- |
|
|
20
|
-
| `@simpleapps-com/augur-server` | Site actions, caching, `safeAction`, environment, Redis
|
|
21
|
-
| `@simpleapps-com/augur-server/site` | `createServerSite`
|
|
22
|
-
| `@simpleapps-com/augur-server/hooks` | `createServerQueryProxy` (registers `queryAction`)
|
|
23
|
-
| `@simpleapps-com/augur-server/query-action` | `queryAction`, `getSessionCredentials`
|
|
24
|
-
| `@simpleapps-com/augur-server/api` | `createAugurApiHandler` (fetch mode)
|
|
25
|
-
| `@simpleapps-com/augur-server/auth` | `createAuthConfig`
|
|
26
|
-
| `@simpleapps-com/augur-server/query` | `createQueryOptions`, `createSuspenseQueryOptions`
|
|
27
|
-
| `@simpleapps-com/augur-server/actions` | Types only
|
|
28
|
-
| `@simpleapps-com/augur-server/testing` | `createMockSiteActions`, `createMockClient`
|
|
29
|
-
| `@simpleapps-com/augur-server/next-auth` | NextAuth type augmentations
|
|
18
|
+
| Import | Purpose |
|
|
19
|
+
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| `@simpleapps-com/augur-server` | Site actions, caching, `safeAction`, environment, Redis |
|
|
21
|
+
| `@simpleapps-com/augur-server/site` | `createServerSite` |
|
|
22
|
+
| `@simpleapps-com/augur-server/hooks` | `createServerQueryProxy` (registers `queryAction`) |
|
|
23
|
+
| `@simpleapps-com/augur-server/query-action` | `queryAction`, `queryActionRaw`, `queryActionWith`, `queryActionRawWith` (bounded by a deadline or signal, atlas#106), `getSessionCredentials` |
|
|
24
|
+
| `@simpleapps-com/augur-server/api` | `createAugurApiHandler` (fetch mode) |
|
|
25
|
+
| `@simpleapps-com/augur-server/auth` | `createAuthConfig` |
|
|
26
|
+
| `@simpleapps-com/augur-server/query` | `createQueryOptions`, `createSuspenseQueryOptions` |
|
|
27
|
+
| `@simpleapps-com/augur-server/actions` | Types only |
|
|
28
|
+
| `@simpleapps-com/augur-server/testing` | `createMockSiteActions`, `createMockClient` |
|
|
29
|
+
| `@simpleapps-com/augur-server/next-auth` | NextAuth type augmentations |
|
|
30
30
|
|
|
31
31
|
**Cross-site sessions** (a site signing users in for other sites, augur-support's pattern) need
|
|
32
32
|
`createServerSite(client, { auth: { crossSite: true } })`. Without it, sign-in ignores the
|
|
33
33
|
target `siteId` and `queryAction` never reads the session cookie, so pages that prefetch through
|
|
34
34
|
it can render statically (atlas#105). A multi-tenant site MUST set it.
|
|
35
35
|
|
|
36
|
+
**Bounded calls** (atlas#106): a server render that awaits a read SHOULD bound it with
|
|
37
|
+
`queryActionWith({ deadline: 5000 }, methodPath, ...args)` (or `queryActionRawWith`). With no
|
|
38
|
+
bound, the SDK's retry budget (3 retries at 30 s each, plus backoff) becomes page latency. At
|
|
39
|
+
the deadline the call rejects with a `TimeoutError`: the request is cancelled, nothing more is
|
|
40
|
+
retried and nothing is cached, so the page can fall back to a client-side fetch. `options.signal`
|
|
41
|
+
cancels it too (server code only: a signal can't cross a server action from the browser). The
|
|
42
|
+
options never enter the cache key. It needs an `@simpleapps-com/augur-api` with
|
|
43
|
+
`AugurAPI.withRequest`; on an older client the call is refused rather than run unbounded.
|
|
44
|
+
|
|
36
45
|
## Development
|
|
37
46
|
|
|
38
47
|
TypeScript in `src/`, built to `dist/` (ESM) by tsup with `"use server"` and `"use client"`
|
package/dist/api-handler.d.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* (set by browsers automatically and cannot be forged by scripts).
|
|
11
11
|
*/
|
|
12
12
|
/**
|
|
13
|
-
* Creates a Next.js Route Handler that routes method calls through queryAction
|
|
13
|
+
* Creates a Next.js Route Handler that routes method calls through queryAction, or through
|
|
14
|
+
* queryActionRaw when the body has `raw: true` (augur-core's `createFetchQueryActionRaw`).
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
16
17
|
* ```ts
|
|
@@ -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;AAyBH;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,KACrB,KAAK,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CA+B/C"}
|
package/dist/api.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
queryAction
|
|
3
|
-
|
|
2
|
+
queryAction,
|
|
3
|
+
queryActionRaw
|
|
4
|
+
} from "./chunk-FIM6LDMD.js";
|
|
4
5
|
import {
|
|
6
|
+
answersFullOf,
|
|
5
7
|
apiMessageOf,
|
|
6
8
|
apiStatusOf,
|
|
7
9
|
bodyOutcomeOf,
|
|
8
|
-
isCrossOrigin
|
|
9
|
-
|
|
10
|
+
isCrossOrigin,
|
|
11
|
+
runsOf
|
|
12
|
+
} from "./chunk-6GPKXGPG.js";
|
|
10
13
|
|
|
11
14
|
// src/api-handler.ts
|
|
12
15
|
function refusal(outcome) {
|
|
@@ -21,15 +24,16 @@ function createAugurApiHandler() {
|
|
|
21
24
|
} catch {
|
|
22
25
|
return refusal("bad-json");
|
|
23
26
|
}
|
|
24
|
-
const { methodPath, args } = body;
|
|
27
|
+
const { methodPath, args, raw } = body;
|
|
25
28
|
const outcome = bodyOutcomeOf(
|
|
26
29
|
true,
|
|
27
30
|
typeof methodPath === "string" && methodPath !== "",
|
|
28
|
-
Array.isArray(args)
|
|
31
|
+
Array.isArray(args),
|
|
32
|
+
raw === true
|
|
29
33
|
);
|
|
30
|
-
if (outcome
|
|
34
|
+
if (!runsOf(outcome)) return refusal(outcome);
|
|
31
35
|
try {
|
|
32
|
-
const result = await queryAction(methodPath, ...args);
|
|
36
|
+
const result = answersFullOf(outcome) ? await queryActionRaw(methodPath, ...args) : await queryAction(methodPath, ...args);
|
|
33
37
|
return Response.json(result);
|
|
34
38
|
} catch (error) {
|
|
35
39
|
const message = error instanceof Error ? error.message : "Internal server error";
|
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 } from \"./query-action\";\nimport {
|
|
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, ...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":";;;;;;;;;;;;;;AAwBA,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;AACF,YAAM,SAAS,cAAc,OAAO,IAChC,MAAM,eAAe,YAAY,GAAG,IAAI,IACxC,MAAM,YAAY,YAAY,GAAG,IAAI;AACzC,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/dist/auth.js
CHANGED
|
@@ -80,15 +80,22 @@ function hostEnvOf(host) {
|
|
|
80
80
|
function isCrossOrigin(fetchSite) {
|
|
81
81
|
return fetchSite !== "" && fetchSite !== "same-origin";
|
|
82
82
|
}
|
|
83
|
-
function bodyOutcomeOf(jsonOk, methodPathOk, argsIsArray) {
|
|
83
|
+
function bodyOutcomeOf(jsonOk, methodPathOk, argsIsArray, full) {
|
|
84
84
|
if (!jsonOk) return "bad-json";
|
|
85
85
|
if (!methodPathOk) return "bad-method-path";
|
|
86
86
|
if (!argsIsArray) return "bad-args";
|
|
87
|
+
if (full) return "run-full";
|
|
87
88
|
return "run";
|
|
88
89
|
}
|
|
90
|
+
function runsOf(o) {
|
|
91
|
+
return o === "run" || o === "run-full";
|
|
92
|
+
}
|
|
93
|
+
function answersFullOf(o) {
|
|
94
|
+
return o === "run-full";
|
|
95
|
+
}
|
|
89
96
|
function apiStatusOf(o) {
|
|
90
97
|
if (o === "forbidden") return 403;
|
|
91
|
-
if (o === "run") return 200;
|
|
98
|
+
if (o === "run" || o === "run-full") return 200;
|
|
92
99
|
return 400;
|
|
93
100
|
}
|
|
94
101
|
function apiMessageOf(o) {
|
|
@@ -159,6 +166,13 @@ function approvePath(path, hasAllowlist, listed) {
|
|
|
159
166
|
function usesCache(hasWrapper, isRead) {
|
|
160
167
|
return hasWrapper && isRead;
|
|
161
168
|
}
|
|
169
|
+
function sessionCookieName(hasSecure) {
|
|
170
|
+
return hasSecure ? "__Secure-authjs.session-token" : "authjs.session-token";
|
|
171
|
+
}
|
|
172
|
+
function clientFor(hasOptions, hasWithRequest) {
|
|
173
|
+
if (!hasOptions) return "client";
|
|
174
|
+
return hasWithRequest ? "view" : "refuse";
|
|
175
|
+
}
|
|
162
176
|
function scopedPrefix(siteId) {
|
|
163
177
|
return siteId + ":";
|
|
164
178
|
}
|
|
@@ -283,6 +297,8 @@ export {
|
|
|
283
297
|
envOf,
|
|
284
298
|
isCrossOrigin,
|
|
285
299
|
bodyOutcomeOf,
|
|
300
|
+
runsOf,
|
|
301
|
+
answersFullOf,
|
|
286
302
|
apiStatusOf,
|
|
287
303
|
apiMessageOf,
|
|
288
304
|
ttlFor,
|
|
@@ -299,6 +315,8 @@ export {
|
|
|
299
315
|
signInTarget,
|
|
300
316
|
resolutionOf,
|
|
301
317
|
usesCache,
|
|
318
|
+
sessionCookieName,
|
|
319
|
+
clientFor,
|
|
302
320
|
scopedPrefix,
|
|
303
321
|
shouldCache,
|
|
304
322
|
cacheTtlOf,
|
|
@@ -320,4 +338,4 @@ export {
|
|
|
320
338
|
getOrCreateScopedClient,
|
|
321
339
|
parseMethodPath
|
|
322
340
|
};
|
|
323
|
-
//# sourceMappingURL=chunk-
|
|
341
|
+
//# sourceMappingURL=chunk-6GPKXGPG.js.map
|