@alxia/react-router 0.37.0 → 0.39.0
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 +37 -1
- package/dist/fetcher/index.d.ts +1 -0
- package/dist/fetcher/index.d.ts.map +1 -1
- package/dist/fetcher/index.js +57 -1
- package/dist/fetcher/index.js.map +4 -3
- package/dist/fetcher/use-fetcher-promise.d.ts +37 -0
- package/dist/fetcher/use-fetcher-promise.d.ts.map +1 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +97 -1
- package/dist/session/index.js.map +5 -4
- package/dist/session/throttle.d.ts +59 -0
- package/dist/session/throttle.d.ts.map +1 -0
- package/docs/README.md +2 -2
- package/docs/guide/fetcher.md +44 -0
- package/docs/guide/session.md +61 -0
- package/docs/roadmap.md +12 -0
- package/docs/troubleshooting.md +28 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1034,6 +1034,27 @@ on the form. `stepUpSteps` asks for a code before a sensitive action, and
|
|
|
1034
1034
|
[session guide](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/session.md)
|
|
1035
1035
|
has a complete sign-in route and the rest.
|
|
1036
1036
|
|
|
1037
|
+
A password sign-in of your own gets `createSignInThrottle` from the same
|
|
1038
|
+
subpath: failures per key within a window, a bounded number of keys, a global
|
|
1039
|
+
bucket that delays rather than locks, and a cap on concurrent password
|
|
1040
|
+
hashes. It is per process.
|
|
1041
|
+
|
|
1042
|
+
```ts
|
|
1043
|
+
import { createSignInThrottle } from '@alxia/react-router/session';
|
|
1044
|
+
|
|
1045
|
+
const throttle = createSignInThrottle({ max: 5, windowMs: 15 * 60_000 });
|
|
1046
|
+
|
|
1047
|
+
const seconds = throttle.wait(email); // 0 when allowed
|
|
1048
|
+
if (seconds > 0) return tooMany(seconds);
|
|
1049
|
+
const checked = await throttle.verify(() => Bun.password.verify(password, hash));
|
|
1050
|
+
if (checked.busy) return tryLater();
|
|
1051
|
+
if (!checked.value) {
|
|
1052
|
+
throttle.fail(email);
|
|
1053
|
+
return refused();
|
|
1054
|
+
}
|
|
1055
|
+
throttle.clear(email);
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1037
1058
|
## A GraphQL subscription for the browser
|
|
1038
1059
|
|
|
1039
1060
|
`@alxia/react-router/subscription` exposes subscriptions of your API to the
|
|
@@ -1109,6 +1130,20 @@ const { fetcher } = useJsonFetcher<typeof action>('save');
|
|
|
1109
1130
|
const answer = useFetcherAnswer(fetcher, (result) => toast(result.message));
|
|
1110
1131
|
```
|
|
1111
1132
|
|
|
1133
|
+
To await one submission's answer as a Promise (a confirm dialog whose `onConfirm` stays open and shows the error until it settles), `useFetcherPromise` resolves with the next new answer, or rejects with an `Error` when your `refusal(answer)` returns a message:
|
|
1134
|
+
|
|
1135
|
+
```tsx
|
|
1136
|
+
import { useJsonFetcher } from '@alxia/react-router/errors';
|
|
1137
|
+
import { useFetcherPromise } from '@alxia/react-router/fetcher';
|
|
1138
|
+
|
|
1139
|
+
const { fetcher, post } = useJsonFetcher<typeof action>('delete');
|
|
1140
|
+
const run = useFetcherPromise(fetcher, {
|
|
1141
|
+
refusal: (result) => (result.ok ? undefined : result.error),
|
|
1142
|
+
});
|
|
1143
|
+
// a confirm dialog that stays open, and shows the error, while this rejects
|
|
1144
|
+
const onConfirm = () => run(() => post({ intent: 'delete', id }));
|
|
1145
|
+
```
|
|
1146
|
+
|
|
1112
1147
|
A resource route loaded for what is typed (a typeahead, a preview): one load
|
|
1113
1148
|
after a pause, from a minimum length, the previous answer kept (`stale`) until
|
|
1114
1149
|
the new one lands, and a retry:
|
|
@@ -1421,6 +1456,7 @@ From `@alxia/react-router/fetcher` (`react` and `react-router` are its imports;
|
|
|
1421
1456
|
| export | |
|
|
1422
1457
|
| --- | --- |
|
|
1423
1458
|
| `useFetcherAnswer(fetcher, onAnswer?)`, `AnswerSource` | `onAnswer(answer)` once per answer that arrives while the fetcher is idle and differs from the last one seen (the data present at mount counts as seen); the handler is read from a ref; returns the latest answer handed over, `undefined` before the first |
|
|
1459
|
+
| `useFetcherPromise(fetcher, { refusal? }?)`, `FetcherPromiseOptions`, `FetcherPromiseAborted` | returns a stable `run(submit)` that calls `submit` (`() => fetcher.submit(...)`) and returns a Promise settled by the fetcher's next new answer: resolved with it, or rejected with an `Error` when `refusal(answer)` returns a message (or your own `Error`); an answer held before the call never settles it; a second `run` while one is pending rejects the older with `FetcherPromiseAborted` (`reason: 'superseded'`); an unmount rejects the pending one (`'unmounted'`); a `submit` that throws rejects with its error |
|
|
1424
1460
|
| `useFormRefusal(result)`, `FormRefusalResult` | `useFormRefusal(fetcher.data)` returns the `FormErrors` of a fetcher answer that carries `fieldErrors` (`apiErrors.formRefusal`'s), `undefined` for no answer, a done step or a refusal without them; stable for one answer |
|
|
1425
1461
|
| `useDebouncedFetcher(value, to, { delayMs?, minLength?, enabled?, key?, keep? }?)`, `DebouncedFetcher`, `DebouncedFetcherOptions`, `DebouncedFetcherState` | a resource route loaded for what is typed: one `fetcher.load` after `delayMs` (250) without a change and from `minLength` (1) trimmed characters; `to` is a URL or `(value) => url`; returns `{ data, stale, state, retry }`: `data` is the answer for the value as it stands, else the previous one with `stale` set; `state` is `'idle' \| 'waiting' \| 'loading' \| 'done'`; `keep(answer)` filters what may stay as the stale answer; `retry()` (stable) asks again at once |
|
|
1426
1462
|
|
|
@@ -1448,7 +1484,7 @@ The `alxia-react-router` bin, run with `bunx`:
|
|
|
1448
1484
|
- [Installable and offline](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/pwa.md): what the subpaths hold, the worker's contract, the worker, what it caches, the offline page, building the worker with `alxia()` or `buildWorker`, the hooks in React, registering the worker and offering an update, serving the worker's script, the web app manifest, and clearing at sign-out.
|
|
1449
1485
|
- [An API's refusals](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/errors.md): what `/errors` holds, recognising an API error, the request id, the page a request is for, the catalogue store, the form checks in the API's words, the provider, wording a refusal, loaders and the error page, actions, JSON actions and CSRF, and keeping the catalogue fresh.
|
|
1450
1486
|
- [A BFF session](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/session.md): redirects that stay on the site, the cookies, the sign-in route, the second factor, the viewer and sign-out, the step-up, and the pages a mail's link opens.
|
|
1451
|
-
- [A fetcher's fresh answer](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/fetcher.md): `useFetcherAnswer`: a handler called once per new answer of a keyed fetcher, not for the data it held at mount; `useDebouncedFetcher`: a resource route loaded for what is typed.
|
|
1487
|
+
- [A fetcher's fresh answer](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/fetcher.md): `useFetcherAnswer`: a handler called once per new answer of a keyed fetcher, not for the data it held at mount; `useFetcherPromise`: one submission's answer as a Promise; `useDebouncedFetcher`: a resource route loaded for what is typed.
|
|
1452
1488
|
- [Lists whose state is the URL](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/lists.md): `useSearchChange`, `useSameRouteLoading`, `usePagedRows`: a search that drops the cursor, a skeleton for the same page reloading, a load-more button.
|
|
1453
1489
|
- [Subscriptions for a BFF](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/guide/subscriptions.md): exposing a GraphQL subscription to the browser through a resource route: the allow-list, the session's bearer, the headers, the heartbeat, abort and rate limits.
|
|
1454
1490
|
- [Troubleshooting](https://github.com/softistx/alxia/blob/develop/packages/react-router/docs/troubleshooting.md): each message, and the traps that print none.
|
package/dist/fetcher/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { type DebouncedFetcher, type DebouncedFetcherOptions, type DebouncedFetcherState, useDebouncedFetcher, } from './use-debounced-fetcher';
|
|
7
7
|
export { type AnswerSource, useFetcherAnswer } from './use-fetcher-answer';
|
|
8
|
+
export { FetcherPromiseAborted, type FetcherPromiseOptions, useFetcherPromise, } from './use-fetcher-promise';
|
|
8
9
|
export { type FormRefusalResult, useFormRefusal } from './use-form-refusal';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,KAAK,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EACN,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,iBAAiB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/fetcher/index.js
CHANGED
|
@@ -92,6 +92,60 @@ function useFetcherAnswer(fetcher, onAnswer) {
|
|
|
92
92
|
}, [answer]);
|
|
93
93
|
return latest;
|
|
94
94
|
}
|
|
95
|
+
// src/fetcher/use-fetcher-promise.ts
|
|
96
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
97
|
+
class FetcherPromiseAborted extends Error {
|
|
98
|
+
name = "FetcherPromiseAborted";
|
|
99
|
+
reason;
|
|
100
|
+
constructor(reason) {
|
|
101
|
+
super(reason === "superseded" ? "useFetcherPromise: a newer call replaced this one before the fetcher answered" : "useFetcherPromise: the component unmounted before the fetcher answered");
|
|
102
|
+
this.reason = reason;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function useFetcherPromise(fetcher, options = {}) {
|
|
106
|
+
const waiting = useRef3(null);
|
|
107
|
+
const refusal = useRef3(options.refusal);
|
|
108
|
+
refusal.current = options.refusal;
|
|
109
|
+
useFetcherAnswer(fetcher, (answer) => {
|
|
110
|
+
const pending = waiting.current;
|
|
111
|
+
if (!pending)
|
|
112
|
+
return;
|
|
113
|
+
waiting.current = null;
|
|
114
|
+
let refused;
|
|
115
|
+
try {
|
|
116
|
+
refused = refusal.current?.(answer);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
pending.reject(error);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (refused === undefined)
|
|
122
|
+
pending.resolve(answer);
|
|
123
|
+
else
|
|
124
|
+
pending.reject(typeof refused === "string" ? new Error(refused) : refused);
|
|
125
|
+
});
|
|
126
|
+
useEffect3(() => () => {
|
|
127
|
+
const pending = waiting.current;
|
|
128
|
+
waiting.current = null;
|
|
129
|
+
pending?.reject(new FetcherPromiseAborted("unmounted"));
|
|
130
|
+
}, []);
|
|
131
|
+
return useCallback2((submit) => {
|
|
132
|
+
waiting.current?.reject(new FetcherPromiseAborted("superseded"));
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
const mine = { resolve, reject };
|
|
135
|
+
waiting.current = mine;
|
|
136
|
+
const fail = (error) => {
|
|
137
|
+
if (waiting.current === mine)
|
|
138
|
+
waiting.current = null;
|
|
139
|
+
reject(error);
|
|
140
|
+
};
|
|
141
|
+
try {
|
|
142
|
+
Promise.resolve(submit()).catch(fail);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
fail(error);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}, []);
|
|
148
|
+
}
|
|
95
149
|
// src/fetcher/use-form-refusal.ts
|
|
96
150
|
import { useMemo } from "react";
|
|
97
151
|
function useFormRefusal(result) {
|
|
@@ -101,10 +155,12 @@ function useFormRefusal(result) {
|
|
|
101
155
|
} : undefined, [result]);
|
|
102
156
|
}
|
|
103
157
|
export {
|
|
158
|
+
FetcherPromiseAborted,
|
|
104
159
|
useDebouncedFetcher,
|
|
105
160
|
useFetcherAnswer,
|
|
161
|
+
useFetcherPromise,
|
|
106
162
|
useFormRefusal
|
|
107
163
|
};
|
|
108
164
|
|
|
109
|
-
//# debugId=
|
|
165
|
+
//# debugId=6FFF1F15C0AB3E6F64756E2164756E21
|
|
110
166
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/fetcher/use-debounced-fetcher.ts", "../src/fetcher/use-fetcher-answer.ts", "../src/fetcher/use-form-refusal.ts"],
|
|
3
|
+
"sources": ["../src/fetcher/use-debounced-fetcher.ts", "../src/fetcher/use-fetcher-answer.ts", "../src/fetcher/use-fetcher-promise.ts", "../src/fetcher/use-form-refusal.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import {\n\tstartTransition,\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport { useFetcher } from 'react-router';\n\n/** What `useFetcher<Data>` hands back as `data` (`Data` may be `typeof loader`). */\ntype FetcherData<Data> = ReturnType<typeof useFetcher<Data>>['data'];\n\n/** What `useDebouncedFetcher` is doing for the value typed. */\nexport type DebouncedFetcherState =\n\t/** Nothing to ask: disabled, or the value is shorter than `minLength`. */\n\t| 'idle'\n\t/** The value changed and the pause after the last change is running. */\n\t| 'waiting'\n\t/** The resource route is loading. */\n\t| 'loading'\n\t/** The route answered for the value as it stands. */\n\t| 'done';\n\nexport interface DebouncedFetcherOptions<Data = unknown> {\n\t/** Pause after the last change before the route is asked. Default 250. */\n\treadonly delayMs?: number;\n\t/** The trimmed value must have this many characters. Default 1. */\n\treadonly minLength?: number;\n\t/** `false` asks nothing and forgets the previous answer. Default `true`. */\n\treadonly enabled?: boolean;\n\t/** The fetcher's key, to share it with another component. */\n\treadonly key?: string;\n\t/**\n\t * Which answers may be kept as the stale `data` while the next value waits\n\t * or loads. Default: all. An answer it refuses (a failure) is still `data`\n\t * while it is the current one, but is never shown as the previous one: after a refused answer, the stale\n\t * data is the last *kept* answer, not the refused one.\n\t */\n\treadonly keep?: (data: NonNullable<FetcherData<Data>>) => boolean;\n}\n\nexport interface DebouncedFetcher<Data> {\n\t/**\n\t * The route's answer for the value as it stands, else (`stale`) the last\n\t * answer for an earlier value, kept until the new one lands. `undefined`\n\t * before any answer, and again once the hook goes `idle`.\n\t */\n\treadonly data: FetcherData<Data>;\n\t/** `data` answers an earlier value (or none is current yet). */\n\treadonly stale: boolean;\n\treadonly state: DebouncedFetcherState;\n\t/** Asks the route again for the value as it stands, without waiting. */\n\treadonly retry: () => void;\n}\n\n/**\n * A resource route loaded through a fetcher for a value that changes as the\n * user types. After `delayMs` without a change, and from `minLength`\n * characters, it calls `fetcher.load` once (a newer load cancels the\n * previous one). An answer only counts for the value it was asked for: while\n * a newer value waits or loads, `data` is the previous answer with `stale`\n * set, and an answer for an older value is never returned as current.\n * `to` is the route's URL, or a function of the trimmed value that builds it\n * (a string without a function is loaded as it is, the value being only the\n * trigger). A refusal the route answers as data is `data` like any answer.\n */\nexport function useDebouncedFetcher<Data>(\n\tvalue: string,\n\tto: string | ((value: string) => string),\n\toptions: DebouncedFetcherOptions<Data> = {},\n): DebouncedFetcher<Data> {\n\tconst { delayMs = 250, minLength = 1, enabled = true, key, keep } = options;\n\tconst keepRef = useRef(keep);\n\tkeepRef.current = keep;\n\tconst fetcher = useFetcher<Data>(key === undefined ? undefined : { key });\n\tconst load = useRef(fetcher.load);\n\tload.current = fetcher.load;\n\tconst text = value.trim();\n\tconst url =\n\t\tenabled && text.length >= minLength\n\t\t\t? typeof to === 'function'\n\t\t\t\t? to(text)\n\t\t\t\t: to\n\t\t\t: null;\n\t// The URL the fetcher was last told to load.\n\tconst [loaded, setLoaded] = useState<string | null>(null);\n\tconst previous = useRef<FetcherData<Data>>(undefined);\n\t// React Router applies the fetcher's `loading` state in a transition, so\n\t// right after `load()` a render can still show `idle` and the previous\n\t// answer. A load has landed only once the fetcher was seen busy for that very load (the load number is kept, so a busy render of a superseded load does not count), or\n\t// its `load()` promise settled and a transition queued after it committed\n\t// (a fast load whose busy state was never rendered, or a route answering\n\t// the very same object twice). `seq` numbers the loads, so a superseded\n\t// one never counts.\n\tconst seq = useRef(0);\n\tconst [settled, setSettled] = useState(0);\n\tconst busySeq = useRef(0);\n\tuseLayoutEffect(() => {\n\t\tif (fetcher.state !== 'idle') busySeq.current = seq.current;\n\t}, [fetcher.state]);\n\tconst ask = (target: string) => {\n\t\tconst mine = ++seq.current;\n\t\tsetLoaded(target);\n\t\tvoid Promise.resolve(load.current(target)).then(() => {\n\t\t\tif (mine === seq.current) startTransition(() => setSettled(mine));\n\t\t});\n\t};\n\tconst askRef = useRef(ask);\n\taskRef.current = ask;\n\n\tuseEffect(() => {\n\t\tif (url === null) {\n\t\t\tprevious.current = undefined;\n\t\t\tsetLoaded(null);\n\t\t\treturn;\n\t\t}\n\t\tconst timer = setTimeout(() => {\n\t\t\taskRef.current(url);\n\t\t}, delayMs);\n\t\treturn () => clearTimeout(timer);\n\t}, [url, text, delayMs]);\n\n\tconst landed =\n\t\tfetcher.state === 'idle' &&\n\t\t(busySeq.current === seq.current || settled === seq.current);\n\tconst current =\n\t\turl !== null && loaded === url && landed && fetcher.data !== undefined;\n\tconst answer = current ? fetcher.data : undefined;\n\tuseEffect(() => {\n\t\tif (answer === undefined || answer === null) return;\n\t\tif (keepRef.current?.(answer) ?? true) previous.current = answer;\n\t}, [answer]);\n\n\tconst data = current ? answer : url === null ? undefined : previous.current;\n\tlet state: DebouncedFetcherState;\n\tif (url === null) state = 'idle';\n\telse if (loaded !== url) state = 'waiting';\n\telse state = landed ? 'done' : 'loading';\n\n\tconst urlRef = useRef(url);\n\turlRef.current = url;\n\tconst retry = useCallback(() => {\n\t\tconst now = urlRef.current;\n\t\tif (now === null) return;\n\t\taskRef.current(now);\n\t}, []);\n\treturn { data, stale: state !== 'done' && data !== undefined, state, retry };\n}\n",
|
|
6
6
|
"import { useEffect, useRef, useState } from 'react';\n\n/** What the hook reads of a React Router fetcher. */\nexport interface AnswerSource<Data> {\n\treadonly state: string;\n\treadonly data: Data | undefined;\n}\n\n/**\n * The answers a fetcher gives, one at a time. A keyed fetcher outlives its\n * component, so the data it holds when the component mounts is an earlier\n * visit's, not this one's. `onAnswer` is called once for each answer that\n * arrives while the fetcher is idle and is another object than the last one\n * seen (the data present at mount counts as seen). The handler is read from\n * a ref, so a new function each render never re-fires it. Returns the latest\n * answer handed over, `undefined` until one arrives.\n */\nexport function useFetcherAnswer<Data>(\n\tfetcher: AnswerSource<Data>,\n\tonAnswer?: (answer: Data) => void,\n): Data | undefined {\n\tconst seen = useRef(fetcher.data);\n\tconst handler = useRef(onAnswer);\n\thandler.current = onAnswer;\n\tconst [latest, setLatest] = useState<Data | undefined>(undefined);\n\tconst answer = fetcher.state === 'idle' ? fetcher.data : undefined;\n\tuseEffect(() => {\n\t\tif (answer === undefined || answer === null || answer === seen.current) {\n\t\t\treturn;\n\t\t}\n\t\tseen.current = answer;\n\t\tsetLatest(answer);\n\t\thandler.current?.(answer);\n\t}, [answer]);\n\treturn latest;\n}\n",
|
|
7
|
+
"import { useCallback, useEffect, useRef } from 'react';\nimport { type AnswerSource, useFetcherAnswer } from './use-fetcher-answer';\n\n/** What `useFetcherPromise` accepts. */\nexport interface FetcherPromiseOptions<Data> {\n\t/**\n\t * Decides whether an answer is a refusal: the message (or the `Error`) the\n\t * promise rejects with, `undefined` to resolve with the answer. Read from a\n\t * ref, so a new function each render is fine. Without it every answer\n\t * resolves.\n\t */\n\trefusal?: (answer: Data) => string | Error | undefined;\n}\n\n/** The rejection of a call replaced by a newer one, or cut off by an unmount. */\nexport class FetcherPromiseAborted extends Error {\n\toverride readonly name = 'FetcherPromiseAborted';\n\treadonly reason: 'superseded' | 'unmounted';\n\tconstructor(reason: 'superseded' | 'unmounted') {\n\t\tsuper(\n\t\t\treason === 'superseded'\n\t\t\t\t? 'useFetcherPromise: a newer call replaced this one before the fetcher answered'\n\t\t\t\t: 'useFetcherPromise: the component unmounted before the fetcher answered',\n\t\t);\n\t\tthis.reason = reason;\n\t}\n}\n\ninterface Waiting<Data> {\n\tresolve(answer: Data): void;\n\treject(error: unknown): void;\n}\n\n/**\n * Ties one submission to its answer. `run(submit)` calls `submit` (usually\n * `() => fetcher.submit(...)`) and returns a Promise settled by the fetcher's\n * next new answer (see `useFetcherAnswer`): it resolves with the answer, or\n * rejects with an `Error` when `options.refusal` returns a message for it. An\n * answer the fetcher already held when `run` was called never settles it.\n *\n * A second `run` while one is pending rejects the older promise with a\n * `FetcherPromiseAborted` (`'superseded'`) and waits for the answer to the\n * newer one. An unmount rejects the pending promise with a\n * `FetcherPromiseAborted` (`'unmounted'`). A `submit` that throws (or whose\n * promise rejects) rejects the promise with that error, and so does a\n * `refusal` that throws. `run` is stable.\n *\n * Catch every promise `run` returns: an abort rejects it, and one nobody\n * handles is an unhandled rejection. Ignore the aborts with\n * `.catch((e) => { if (!(e instanceof FetcherPromiseAborted)) throw e; })`.\n */\nexport function useFetcherPromise<Data>(\n\tfetcher: AnswerSource<Data>,\n\toptions: FetcherPromiseOptions<Data> = {},\n): (submit: () => void | Promise<unknown>) => Promise<Data> {\n\tconst waiting = useRef<Waiting<Data> | null>(null);\n\tconst refusal = useRef(options.refusal);\n\trefusal.current = options.refusal;\n\n\tuseFetcherAnswer(fetcher, (answer) => {\n\t\tconst pending = waiting.current;\n\t\tif (!pending) return;\n\t\twaiting.current = null;\n\t\tlet refused: string | Error | undefined;\n\t\ttry {\n\t\t\trefused = refusal.current?.(answer);\n\t\t} catch (error) {\n\t\t\tpending.reject(error);\n\t\t\treturn;\n\t\t}\n\t\tif (refused === undefined) pending.resolve(answer);\n\t\telse\n\t\t\tpending.reject(\n\t\t\t\ttypeof refused === 'string' ? new Error(refused) : refused,\n\t\t\t);\n\t});\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tconst pending = waiting.current;\n\t\t\twaiting.current = null;\n\t\t\tpending?.reject(new FetcherPromiseAborted('unmounted'));\n\t\t},\n\t\t[],\n\t);\n\n\treturn useCallback((submit) => {\n\t\twaiting.current?.reject(new FetcherPromiseAborted('superseded'));\n\t\treturn new Promise<Data>((resolve, reject) => {\n\t\t\tconst mine: Waiting<Data> = { resolve, reject };\n\t\t\twaiting.current = mine;\n\t\t\tconst fail = (error: unknown) => {\n\t\t\t\tif (waiting.current === mine) waiting.current = null;\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tPromise.resolve(submit()).catch(fail);\n\t\t\t} catch (error) {\n\t\t\t\tfail(error);\n\t\t\t}\n\t\t});\n\t}, []);\n}\n",
|
|
7
8
|
"import { useMemo } from 'react';\nimport type { FormErrors } from '../errors/form-errors';\n\n/**\n * What a form's fetcher answers: a done step (`ok: true`), or a refusal\n * (`formRefusal`, or `fetcherResult` with its `error`) that may carry the\n * form's field errors.\n */\nexport type FormRefusalResult =\n\t| { ok: true }\n\t| { ok?: false; fieldErrors?: Record<string, string>; error?: string };\n\n/**\n * The refusal of a form's last answer as its `FormErrors`: `undefined` for\n * no answer, a done step, or a refusal with no `fieldErrors` (a toast's\n * message, not the form's). Stable for one answer.\n */\nexport function useFormRefusal(\n\tresult: FormRefusalResult | undefined,\n): FormErrors | undefined {\n\treturn useMemo(\n\t\t() =>\n\t\t\tresult && !result.ok && result.fieldErrors\n\t\t\t\t? {\n\t\t\t\t\t\tfieldErrors: result.fieldErrors,\n\t\t\t\t\t\tformError: result.error || undefined,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t[result],\n\t);\n}\n"
|
|
8
9
|
],
|
|
9
|
-
"mappings": ";A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O,SAAS,cAAc,CAC7B,QACyB;AAAA,EACzB,OAAO,QACN,MACC,UAAU,CAAC,OAAO,MAAM,OAAO,cAC5B;AAAA,IACA,aAAa,OAAO;AAAA,IACpB,WAAW,OAAO,SAAS;AAAA,EAC5B,IACC,WACJ,CAAC,MAAM,CACR;AAAA;",
|
|
11
|
+
"debugId": "6FFF1F15C0AB3E6F64756E2164756E21",
|
|
11
12
|
"names": []
|
|
12
13
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type AnswerSource } from './use-fetcher-answer';
|
|
2
|
+
/** What `useFetcherPromise` accepts. */
|
|
3
|
+
export interface FetcherPromiseOptions<Data> {
|
|
4
|
+
/**
|
|
5
|
+
* Decides whether an answer is a refusal: the message (or the `Error`) the
|
|
6
|
+
* promise rejects with, `undefined` to resolve with the answer. Read from a
|
|
7
|
+
* ref, so a new function each render is fine. Without it every answer
|
|
8
|
+
* resolves.
|
|
9
|
+
*/
|
|
10
|
+
refusal?: (answer: Data) => string | Error | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** The rejection of a call replaced by a newer one, or cut off by an unmount. */
|
|
13
|
+
export declare class FetcherPromiseAborted extends Error {
|
|
14
|
+
readonly name = "FetcherPromiseAborted";
|
|
15
|
+
readonly reason: 'superseded' | 'unmounted';
|
|
16
|
+
constructor(reason: 'superseded' | 'unmounted');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Ties one submission to its answer. `run(submit)` calls `submit` (usually
|
|
20
|
+
* `() => fetcher.submit(...)`) and returns a Promise settled by the fetcher's
|
|
21
|
+
* next new answer (see `useFetcherAnswer`): it resolves with the answer, or
|
|
22
|
+
* rejects with an `Error` when `options.refusal` returns a message for it. An
|
|
23
|
+
* answer the fetcher already held when `run` was called never settles it.
|
|
24
|
+
*
|
|
25
|
+
* A second `run` while one is pending rejects the older promise with a
|
|
26
|
+
* `FetcherPromiseAborted` (`'superseded'`) and waits for the answer to the
|
|
27
|
+
* newer one. An unmount rejects the pending promise with a
|
|
28
|
+
* `FetcherPromiseAborted` (`'unmounted'`). A `submit` that throws (or whose
|
|
29
|
+
* promise rejects) rejects the promise with that error, and so does a
|
|
30
|
+
* `refusal` that throws. `run` is stable.
|
|
31
|
+
*
|
|
32
|
+
* Catch every promise `run` returns: an abort rejects it, and one nobody
|
|
33
|
+
* handles is an unhandled rejection. Ignore the aborts with
|
|
34
|
+
* `.catch((e) => { if (!(e instanceof FetcherPromiseAborted)) throw e; })`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function useFetcherPromise<Data>(fetcher: AnswerSource<Data>, options?: FetcherPromiseOptions<Data>): (submit: () => void | Promise<unknown>) => Promise<Data>;
|
|
37
|
+
//# sourceMappingURL=use-fetcher-promise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-fetcher-promise.d.ts","sourceRoot":"","sources":["../../src/fetcher/use-fetcher-promise.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,sBAAsB,CAAC;AAE3E,wCAAwC;AACxC,MAAM,WAAW,qBAAqB,CAAC,IAAI;IAC1C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,KAAK,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;CACvD;AAED,iFAAiF;AACjF,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,SAAkB,IAAI,2BAA2B;IACjD,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,CAAC;gBAChC,MAAM,EAAE,YAAY,GAAG,WAAW;CAQ9C;AAOD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EACrC,OAAO,EAAE,YAAY,CAAC,IAAI,CAAC,EAC3B,OAAO,GAAE,qBAAqB,CAAC,IAAI,CAAM,GACvC,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAgD1D"}
|
package/dist/session/index.d.ts
CHANGED
|
@@ -16,4 +16,5 @@ export { type SignedSession, type SignedSessionOptions, signedSession, } from '.
|
|
|
16
16
|
export { stepUpSteps } from './step-up';
|
|
17
17
|
export { STEP_UP_OVER, STEP_UP_REQUIRED } from './step-up-codes';
|
|
18
18
|
export type { StepUpCall, StepUpCodes, StepUpRun, StepUpSignIn, StepUpStayed, StepUpSteps, StepUpStepsOptions, } from './step-up-types';
|
|
19
|
+
export { createSignInThrottle, type SignInThrottle, type SignInThrottleOptions, type VerifyResult, } from './throttle';
|
|
19
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACN,cAAc,EACd,YAAY,EACZ,cAAc,EACd,eAAe,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,qCAAqC,EAC1C,cAAc,GACd,MAAM,WAAW,CAAC;AACnB,YAAY,EACX,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,oCAAoC,EACpC,eAAe,EACf,YAAY,GACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,YAAY,EACX,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,KAAK,GACL,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACN,UAAU,EACV,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,YAAY,EACZ,eAAe,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,aAAa,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjE,YAAY,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,kBAAkB,GAClB,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACN,cAAc,EACd,YAAY,EACZ,cAAc,EACd,eAAe,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,qCAAqC,EAC1C,cAAc,GACd,MAAM,WAAW,CAAC;AACnB,YAAY,EACX,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,oCAAoC,EACpC,eAAe,EACf,YAAY,GACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,YAAY,EACX,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,KAAK,GACL,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACN,UAAU,EACV,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,YAAY,EACZ,eAAe,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,aAAa,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjE,YAAY,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,kBAAkB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,GACjB,MAAM,YAAY,CAAC"}
|
package/dist/session/index.js
CHANGED
|
@@ -850,6 +850,101 @@ function stepUpSteps(options) {
|
|
|
850
850
|
isStepUpRequired: (error) => isApiErrorLike2(error) && error.code === context.stepUpRequired
|
|
851
851
|
};
|
|
852
852
|
}
|
|
853
|
+
// src/session/throttle.ts
|
|
854
|
+
var DEFAULTS = {
|
|
855
|
+
max: 5,
|
|
856
|
+
windowMs: 15 * 60000,
|
|
857
|
+
maxKeys: 1e4,
|
|
858
|
+
globalMax: 100,
|
|
859
|
+
globalWindowMs: 60000,
|
|
860
|
+
maxConcurrentVerifies: 2,
|
|
861
|
+
maxQueuedVerifies: 4
|
|
862
|
+
};
|
|
863
|
+
function positive(name, value, allowZero = false) {
|
|
864
|
+
const ok = Number.isInteger(value) && (allowZero ? value >= 0 : value > 0);
|
|
865
|
+
if (!ok) {
|
|
866
|
+
throw new TypeError(`createSignInThrottle(): ${name} must be a positive integer${allowZero ? " or 0" : ""}; got ${String(value)}.`);
|
|
867
|
+
}
|
|
868
|
+
return value;
|
|
869
|
+
}
|
|
870
|
+
function createSignInThrottle(options = {}) {
|
|
871
|
+
const max = positive("max", options.max ?? DEFAULTS.max);
|
|
872
|
+
const windowMs = positive("windowMs", options.windowMs ?? DEFAULTS.windowMs);
|
|
873
|
+
const maxKeys = positive("maxKeys", options.maxKeys ?? DEFAULTS.maxKeys);
|
|
874
|
+
const globalMax = positive("globalMax", options.globalMax ?? DEFAULTS.globalMax);
|
|
875
|
+
const globalWindowMs = positive("globalWindowMs", options.globalWindowMs ?? DEFAULTS.globalWindowMs);
|
|
876
|
+
const slots = positive("maxConcurrentVerifies", options.maxConcurrentVerifies ?? DEFAULTS.maxConcurrentVerifies);
|
|
877
|
+
const queueLimit = positive("maxQueuedVerifies", options.maxQueuedVerifies ?? DEFAULTS.maxQueuedVerifies, true);
|
|
878
|
+
const now = options.now ?? Date.now;
|
|
879
|
+
const failures = new Map;
|
|
880
|
+
let global = [];
|
|
881
|
+
const recent = (key, at) => {
|
|
882
|
+
const kept = (failures.get(key) ?? []).filter((time) => at - time < windowMs);
|
|
883
|
+
if (kept.length === 0)
|
|
884
|
+
failures.delete(key);
|
|
885
|
+
return kept;
|
|
886
|
+
};
|
|
887
|
+
const seconds = (ms) => Math.ceil(ms / 1000);
|
|
888
|
+
let running = 0;
|
|
889
|
+
const queue = [];
|
|
890
|
+
const release = () => {
|
|
891
|
+
const next = queue.shift();
|
|
892
|
+
if (next)
|
|
893
|
+
next();
|
|
894
|
+
else
|
|
895
|
+
running--;
|
|
896
|
+
};
|
|
897
|
+
return {
|
|
898
|
+
wait(key) {
|
|
899
|
+
const at = now();
|
|
900
|
+
let wait = 0;
|
|
901
|
+
const kept = recent(key, at);
|
|
902
|
+
if (kept.length >= max) {
|
|
903
|
+
wait = seconds(windowMs - (at - kept[0]));
|
|
904
|
+
}
|
|
905
|
+
global = global.filter((time) => at - time < globalWindowMs);
|
|
906
|
+
if (global.length >= globalMax) {
|
|
907
|
+
wait = Math.max(wait, seconds(globalWindowMs - (at - global[0])));
|
|
908
|
+
}
|
|
909
|
+
return wait;
|
|
910
|
+
},
|
|
911
|
+
fail(key) {
|
|
912
|
+
const at = now();
|
|
913
|
+
const kept = [...recent(key, at), at].slice(-max);
|
|
914
|
+
failures.delete(key);
|
|
915
|
+
failures.set(key, kept);
|
|
916
|
+
if (failures.size > maxKeys) {
|
|
917
|
+
const oldest = failures.keys().next().value;
|
|
918
|
+
if (oldest !== undefined)
|
|
919
|
+
failures.delete(oldest);
|
|
920
|
+
}
|
|
921
|
+
global = [
|
|
922
|
+
...global.filter((time) => at - time < globalWindowMs),
|
|
923
|
+
at
|
|
924
|
+
].slice(-globalMax);
|
|
925
|
+
},
|
|
926
|
+
clear(key) {
|
|
927
|
+
failures.delete(key);
|
|
928
|
+
},
|
|
929
|
+
async verify(task) {
|
|
930
|
+
if (running >= slots) {
|
|
931
|
+
if (queue.length >= queueLimit)
|
|
932
|
+
return { busy: true };
|
|
933
|
+
await new Promise((resolve) => queue.push(resolve));
|
|
934
|
+
} else {
|
|
935
|
+
running++;
|
|
936
|
+
}
|
|
937
|
+
try {
|
|
938
|
+
return { busy: false, value: await task() };
|
|
939
|
+
} finally {
|
|
940
|
+
release();
|
|
941
|
+
}
|
|
942
|
+
},
|
|
943
|
+
get size() {
|
|
944
|
+
return failures.size;
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
}
|
|
853
948
|
export {
|
|
854
949
|
CHALLENGE_OVER,
|
|
855
950
|
INVALID_CODE,
|
|
@@ -859,6 +954,7 @@ export {
|
|
|
859
954
|
TOKEN_PAGE_HEADERS,
|
|
860
955
|
UNAUTHENTICATED,
|
|
861
956
|
authLinks,
|
|
957
|
+
createSignInThrottle,
|
|
862
958
|
readCookie,
|
|
863
959
|
secondsUntil,
|
|
864
960
|
serializeCookie,
|
|
@@ -868,5 +964,5 @@ export {
|
|
|
868
964
|
stepUpSteps
|
|
869
965
|
};
|
|
870
966
|
|
|
871
|
-
//# debugId=
|
|
967
|
+
//# debugId=30B84BDDE86DDE4164756E2164756E21
|
|
872
968
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/session/codes.ts", "../src/session/serialize.ts", "../src/session/cookies.ts", "../src/session/link-token.ts", "../src/session/guard.ts", "../src/session/links.ts", "../src/session/link-land.ts", "../src/session/land.ts", "../src/session/second-factor.ts", "../src/session/step.ts", "../src/session/viewer.ts", "../src/session/sign-in.ts", "../src/session/signed.ts", "../src/session/step-up.ts", "../src/session/step-up-codes.ts", "../src/session/step-up-signed-out.ts"],
|
|
3
|
+
"sources": ["../src/session/codes.ts", "../src/session/serialize.ts", "../src/session/cookies.ts", "../src/session/link-token.ts", "../src/session/guard.ts", "../src/session/links.ts", "../src/session/link-land.ts", "../src/session/land.ts", "../src/session/second-factor.ts", "../src/session/step.ts", "../src/session/viewer.ts", "../src/session/sign-in.ts", "../src/session/signed.ts", "../src/session/step-up.ts", "../src/session/step-up-codes.ts", "../src/session/step-up-signed-out.ts", "../src/session/throttle.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/** `@nxgt/janus`'s code for a wrong second-factor or step-up code. */\nexport const INVALID_CODE = 'CODE_INVALID';\n\n/** `@nxgt/janus`'s codes for a challenge that is gone: unknown, spent or expired. */\nexport const CHALLENGE_OVER = [\n\t'TOKEN_UNKNOWN',\n\t'TOKEN_SPENT',\n\t'TOKEN_EXPIRED',\n] as const;\n\n/** `@nxgt/janus`'s code for a mail the API holds back: a link or a code asked for too often. */\nexport const MAIL_THROTTLED = 'MAIL_THROTTLED';\n\n/** The code of an API answer for no session, or a dead one. */\nexport const UNAUTHENTICATED = 'UNAUTHENTICATED';\n",
|
|
6
6
|
"/**\n * The bytes of a cookie, and the reading of one: `Name=v; Max-Age=n; Path=/;\n * HttpOnly[; Secure]; SameSite=Lax`, in this order, so a session set by an\n * app before it adopted this package is still read after, and the other way\n * round.\n */\n\nexport interface SerializeOptions {\n\t/** Seconds; floored, and never below 0 (0 removes the cookie, and so does a value that is not finite). */\n\treadonly maxAge: number;\n\t/** `/` by default. */\n\treadonly path?: string | undefined;\n\t/** Adds `Secure`. Required: it is never read from the environment. */\n\treadonly secure: boolean;\n\t/** `'lax'` by default. `'none'` needs `secure`. */\n\treadonly sameSite?: SameSite | undefined;\n}\n\n/** The `SameSite` attribute of a cookie. */\nexport type SameSite = 'lax' | 'strict' | 'none';\n\nconst SAME_SITE = { lax: 'Lax', strict: 'Strict', none: 'None' } as const;\n\n/** Throws a `TypeError` for a `SameSite` the package does not write, or `none` without `Secure`. */\nexport function checkSameSite(\n\tcaller: string,\n\tsameSite: string,\n\tsecure: boolean,\n): asserts sameSite is SameSite {\n\tif (!Object.hasOwn(SAME_SITE, sameSite)) {\n\t\tthrow new TypeError(\n\t\t\t`${caller}: sameSite must be \"lax\", \"strict\" or \"none\"; got ${JSON.stringify(sameSite)}.`,\n\t\t);\n\t}\n\tif (sameSite === 'none' && !secure) {\n\t\tthrow new TypeError(\n\t\t\t`${caller}: sameSite \"none\" needs secure: true, since a browser drops a SameSite=None cookie without Secure.`,\n\t\t);\n\t}\n}\n\n// RFC 6265 `token`: what a cookie name may be made of.\nconst TOKEN = /^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$/;\n// A path of the site: no `;` to open another attribute, no control character.\n// biome-ignore lint/suspicious/noControlCharactersInRegex: that is the point\nconst PATH = /^\\/[^;\\x00-\\x1f\\x7f]*$/;\n\n/** Whether `name` can name a cookie (an RFC 6265 token). */\nexport const isCookieName = (name: string): boolean => TOKEN.test(name);\n/** Whether `path` can be a cookie's `Path`: absolute, no `;`, no control character. */\nexport const isCookiePath = (path: string): boolean => PATH.test(path);\n\n/**\n * A `Set-Cookie` value: always `HttpOnly`, `SameSite=Lax` unless `sameSite`\n * says otherwise, `Secure` when asked. A name or a path that could open another attribute throws a\n * `TypeError`; a `maxAge` that is not finite is 0.\n */\nexport function serializeCookie(\n\tname: string,\n\tvalue: string,\n\t{ maxAge, path = '/', secure, sameSite = 'lax' }: SerializeOptions,\n): string {\n\tif (!isCookieName(name)) {\n\t\tthrow new TypeError(\n\t\t\t`serializeCookie(): the name ${JSON.stringify(name)} is not a cookie name (an RFC 6265 token).`,\n\t\t);\n\t}\n\tif (!isCookiePath(path)) {\n\t\tthrow new TypeError(\n\t\t\t`serializeCookie(): the path ${JSON.stringify(path)} is not a cookie path: it must start with \"/\" and hold no \";\" or control character.`,\n\t\t);\n\t}\n\tcheckSameSite('serializeCookie():', sameSite, secure);\n\treturn [\n\t\t`${name}=${encodeURIComponent(value)}`,\n\t\t`Max-Age=${Number.isFinite(maxAge) ? Math.max(0, Math.floor(maxAge)) : 0}`,\n\t\t`Path=${path}`,\n\t\t'HttpOnly',\n\t\t...(secure ? ['Secure'] : []),\n\t\t`SameSite=${SAME_SITE[sameSite]}`,\n\t].join('; ');\n}\n\n/**\n * A cookie of the request: the first one of that name that is not empty,\n * decoded; `null` when there is none, or when it is not valid percent-encoding.\n */\nexport function readCookie(request: Request, name: string): string | null {\n\tfor (const pair of request.headers.get('cookie')?.split(';') ?? []) {\n\t\tconst index = pair.indexOf('=');\n\t\tif (index < 0 || pair.slice(0, index).trim() !== name) continue;\n\t\tconst raw = pair.slice(index + 1).trim();\n\t\tif (!raw) continue;\n\t\ttry {\n\t\t\treturn decodeURIComponent(raw);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\treturn null;\n}\n\n/** An instant as milliseconds; 0 when it is not a date. */\nexport function millisOf(at: string | Date): number {\n\tconst time = typeof at === 'string' ? Date.parse(at) : at.getTime();\n\treturn Number.isNaN(time) ? 0 : time;\n}\n\n/** Seconds from `now` until `expiresAt`: 0 when past or unreadable. */\nexport function secondsUntil(\n\texpiresAt: string | Date,\n\tnow: number = Date.now(),\n): number {\n\tconst end = millisOf(expiresAt);\n\treturn end === 0 ? 0 : Math.max(0, (end - now) / 1000);\n}\n",
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
"import {\n\tcheckSameSite,\n\tisCookieName,\n\treadCookie,\n\ttype SameSite,\n\tserializeCookie,\n} from './serialize';\n\n/** What `signedSession` takes. */\nexport interface SignedSessionOptions {\n\t/** The HMAC key: at least 32 characters, from the environment, never committed. Changing it signs everyone out. */\n\treadonly secret: string;\n\t/** The base name of the cookie, e.g. `'my-app_operator'`; `__Host-` is added when `secure`. */\n\treadonly name: string;\n\t/** How long a session lasts, in seconds: a positive integer. It is the cookie's `Max-Age` and, signed, its expiry. */\n\treadonly maxAge: number;\n\t/** The app is served over HTTPS. Required, never read from the environment: pass `!import.meta.env.DEV`. */\n\treadonly secure: boolean;\n\t/** `'lax'` by default. */\n\treadonly sameSite?: SameSite | undefined;\n}\n\n/** A signed, stateless session: no token, no store. */\nexport interface SignedSession {\n\t/** The cookie name as sent, prefix included. */\n\treadonly name: string;\n\t/** A `Set-Cookie` value starting a session of `maxAge` seconds from `now`. */\n\tcommit(now?: number): Promise<string>;\n\t/** A `Set-Cookie` value removing the cookie. */\n\tdestroy(): string;\n\t/** Whether the request carries an unexpired cookie this secret signed. */\n\tvalid(request: Request, now?: number): Promise<boolean>;\n}\n\nconst MIN_SECRET = 32;\nconst MAC_LENGTH = 43; // 32 bytes, base64url, unpadded\nconst DIGITS = /^\\d{1,16}$/;\n\nconst encoder = new TextEncoder();\n\nconst base64url = (bytes: Uint8Array): string =>\n\tbtoa(String.fromCharCode(...bytes))\n\t\t.replaceAll('+', '-')\n\t\t.replaceAll('/', '_')\n\t\t.replaceAll('=', '');\n\n// Web Crypto, not `node:crypto`: the subpath imports `react-router` alone.\nconst keyOf = (secret: string): Promise<CryptoKey> =>\n\tcrypto.subtle.importKey(\n\t\t'raw',\n\t\tencoder.encode(secret),\n\t\t{ name: 'HMAC', hash: 'SHA-256' },\n\t\tfalse,\n\t\t['sign'],\n\t);\n\nasync function sign(key: CryptoKey, payload: string): Promise<string> {\n\tconst mac = await crypto.subtle.sign('HMAC', key, encoder.encode(payload));\n\treturn base64url(new Uint8Array(mac));\n}\n\n// Every byte is compared, whatever the first difference: the lengths are equal.\nfunction sameBytes(a: string, b: string): boolean {\n\tif (a.length !== b.length) return false;\n\tlet difference = 0;\n\tfor (let index = 0; index < a.length; index++) {\n\t\tdifference |= a.charCodeAt(index) ^ b.charCodeAt(index);\n\t}\n\treturn difference === 0;\n}\n\n/**\n * The session of a single local operator with no identity provider: the\n * cookie holds `<expiresAt ms>.<nonce>.<mac>`, the MAC an HMAC-SHA256 of\n * `<expiresAt>.<nonce>`, so the expiry cannot be moved without the secret.\n * `valid` checks it in constant time and never throws. Both are async (Web Crypto).\n *\n * @example\n * const operator = signedSession({\n * secret: process.env.SESSION_SECRET!,\n * name: 'my-app_operator',\n * maxAge: 8 * 3600,\n * secure: !import.meta.env.DEV,\n * sameSite: 'strict',\n * });\n * // after the password was checked: headers.append('Set-Cookie', await operator.commit())\n * // in a loader: if (!(await operator.valid(request))) throw redirect('/sign-in')\n */\nexport function signedSession(options: SignedSessionOptions): SignedSession {\n\tconst { secret, name: base, maxAge, secure, sameSite = 'lax' } = options;\n\tif (typeof secret !== 'string' || secret.length < MIN_SECRET) {\n\t\tthrow new TypeError(\n\t\t\t`signedSession(): secret must be a string of at least ${MIN_SECRET} characters.`,\n\t\t);\n\t}\n\tif (!isCookieName(base) || /^__(?:Host|Secure)-/.test(base)) {\n\t\tthrow new TypeError(\n\t\t\t`signedSession(): the name ${JSON.stringify(base)} must be an RFC 6265 token without a __Host- or __Secure- prefix; the package adds __Host- when secure is true.`,\n\t\t);\n\t}\n\tif (!Number.isInteger(maxAge) || maxAge <= 0) {\n\t\tthrow new TypeError(\n\t\t\t`signedSession(): maxAge must be a positive integer of seconds; got ${String(maxAge)}.`,\n\t\t);\n\t}\n\tcheckSameSite('signedSession():', sameSite, secure);\n\t// `__Host-` holds with `Path=/` and no `Domain`, which the cookie sets.\n\tconst name = secure ? `__Host-${base}` : base;\n\tconst key = keyOf(secret);\n\n\treturn {\n\t\tname,\n\t\tasync commit(now = Date.now()) {\n\t\t\tconst nonce = base64url(crypto.getRandomValues(new Uint8Array(16)));\n\t\t\tconst payload = `${now + maxAge * 1000}.${nonce}`;\n\t\t\treturn serializeCookie(\n\t\t\t\tname,\n\t\t\t\t`${payload}.${await sign(await key, payload)}`,\n\t\t\t\t{\n\t\t\t\t\tmaxAge,\n\t\t\t\t\tsecure,\n\t\t\t\t\tsameSite,\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\tdestroy: () => serializeCookie(name, '', { maxAge: 0, secure, sameSite }),\n\t\tasync valid(request, now = Date.now()) {\n\t\t\tconst value = readCookie(request, name);\n\t\t\tconst parts = value?.split('.') ?? [];\n\t\t\tif (parts.length !== 3) return false;\n\t\t\tconst [digits, nonce, mac] = parts as [string, string, string];\n\t\t\tif (mac.length !== MAC_LENGTH || !nonce || !DIGITS.test(digits)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst expected = await sign(await key, `${digits}.${nonce}`);\n\t\t\tif (!sameBytes(mac, expected)) return false;\n\t\t\treturn Number(digits) > now;\n\t\t},\n\t};\n}\n",
|
|
18
18
|
"import { data } from 'react-router';\nimport {\n\ttype ApiErrorLike,\n\tattemptsLeftOf,\n\tisApiErrorLike,\n\tretryAfterOf,\n} from '../errors/api-error';\nimport { INVALID_CODE, MAIL_THROTTLED, UNAUTHENTICATED } from './codes';\nimport type { CodeWording } from './flow-types';\nimport { samesitePost } from './guard';\nimport type {\n\tStepUpConfirmAnswer,\n\tStepUpError,\n\tStepUpRequestAnswer,\n\tStepUpVia,\n} from './model';\nimport { codeRefusal } from './step';\nimport { STEP_UP_OVER, STEP_UP_REQUIRED } from './step-up-codes';\nimport { signingOut } from './step-up-signed-out';\nimport type {\n\tStepUpRun,\n\tStepUpStayed,\n\tStepUpSteps,\n\tStepUpStepsOptions,\n} from './step-up-types';\n\ntype Refused = Extract<StepUpConfirmAnswer, { ok: false }>;\n\ninterface StepUpContext<L extends string, C> extends CodeWording<L> {\n\treadonly steps: StepUpStepsOptions<L, C>;\n\t/** The sign-in's redirect, bound; `resolve` makes sure `onSignedOut` has one. */\n\treadonly signInRedirect: ((request: Request) => Response) | undefined;\n\treadonly stepUpRequired: string;\n\treadonly mailThrottled: string;\n\treadonly unauthenticated: string;\n}\n\nfunction resolve<L extends string, C>(\n\tsteps: StepUpStepsOptions<L, C>,\n): StepUpContext<L, C> {\n\tconst invalidCode = steps.codes?.invalidCode ?? INVALID_CODE;\n\tconst challengeOver = steps.codes?.challengeOver ?? STEP_UP_OVER;\n\tif (challengeOver.includes(invalidCode)) {\n\t\tthrow new TypeError(\n\t\t\t`stepUpSteps(): the code ${JSON.stringify(invalidCode)} is both the wrong-code code (codes.invalidCode) and in codes.challengeOver. A wrong code that leaves tries cannot end the challenge.`,\n\t\t);\n\t}\n\tif (steps.onSignedOut === 'sign-in' && !steps.signIn.signInRedirect) {\n\t\tthrow new TypeError(\n\t\t\t\"stepUpSteps(): onSignedOut: 'sign-in' needs signIn.signInRedirect, which the sign-in given has not.\",\n\t\t);\n\t}\n\tconst { signIn } = steps;\n\treturn {\n\t\toptions: signIn,\n\t\tsignInRedirect: signIn.signInRedirect?.bind(signIn),\n\t\tsteps,\n\t\tinvalidCode,\n\t\tchallengeOver,\n\t\tstepUpRequired: steps.codes?.stepUpRequired ?? STEP_UP_REQUIRED,\n\t\tmailThrottled: steps.codes?.mailThrottled ?? MAIL_THROTTLED,\n\t\tunauthenticated: steps.codes?.unauthenticated ?? UNAUTHENTICATED,\n\t};\n}\n\n/** The refusal's message: the app's own wording, else `errors`'. */\nfunction worded<L extends string, C>(\n\t{ steps }: StepUpContext<L, C>,\n\terror: ApiErrorLike,\n\tlanguage: L,\n): string {\n\treturn (\n\t\tsteps.wording?.(error, language) ??\n\t\tsteps.signIn.errors.apiErrorMessage(error, language)\n\t);\n}\n\n/** A code the API refused. With none left, a mailed one is over and an app's is locked. */\nfunction refusedCode<L extends string, C>(\n\tcontext: StepUpContext<L, C>,\n\terror: ApiErrorLike,\n\tvia: StepUpVia | undefined,\n\tlanguage: L,\n): Omit<Refused, 'ok' | 'intent'> {\n\tconst { steps } = context;\n\tconst attemptsLeft = attemptsLeftOf(error);\n\tif (attemptsLeft === 0 && via !== 'secondFactor') {\n\t\treturn {\n\t\t\terror: 'expired',\n\t\t\tattemptsLeft,\n\t\t\tlocked: false,\n\t\t\tmessage: steps.spent(language),\n\t\t};\n\t}\n\tconst locked = attemptsLeft === 0;\n\tconst message =\n\t\tcodeRefusal(\n\t\t\tcontext,\n\t\t\terror,\n\t\t\tlanguage,\n\t\t\tlocked ? steps.locked?.(language) : undefined,\n\t\t) ?? steps.signIn.errors.apiErrorMessage(error, language);\n\treturn {\n\t\terror: 'invalid',\n\t\t...(attemptsLeft === undefined ? {} : { attemptsLeft }),\n\t\tlocked,\n\t\tmessage,\n\t};\n}\n\n/** The mail throttle's code, or any 429: a rate limit asks to wait, whatever its code. */\nfunction isThrottle<L extends string, C>(\n\tcontext: StepUpContext<L, C>,\n\terror: ApiErrorLike,\n): boolean {\n\treturn error.status === 429 || error.code === context.mailThrottled;\n}\n\nasync function requestStep<L extends string, C>(\n\tcontext: StepUpContext<L, C>,\n\trun: Parameters<StepUpSteps<L>['request']>[0],\n\t{ request, language }: Parameters<StepUpSteps<L>['request']>[1],\n): Promise<StepUpRequestAnswer | StepUpStayed<StepUpRequestAnswer>> {\n\tsamesitePost(context.steps.signIn.json, request);\n\tconst intent = 'request-step-up';\n\ttry {\n\t\tconst { challenge, via } = await run();\n\t\treturn { ok: true, intent, challenge, via };\n\t} catch (error) {\n\t\tconst refusal = context.steps.signIn.errors.apiRefusal(error, language);\n\t\tif (!refusal) throw error;\n\t\tconst api = isApiErrorLike(error);\n\t\tconst message = api ? worded(context, error, language) : refusal.message;\n\t\tconst throttled = api && isThrottle(context, error);\n\t\tconst retryAfter = throttled ? retryAfterOf(error) : undefined;\n\t\treturn data<StepUpRequestAnswer>(\n\t\t\t{\n\t\t\t\tok: false,\n\t\t\t\tintent,\n\t\t\t\terror: throttled ? 'throttled' : 'failed',\n\t\t\t\tmessage,\n\t\t\t\t...(retryAfter === undefined ? {} : { retryAfter }),\n\t\t\t},\n\t\t\t{ status: refusal.status },\n\t\t);\n\t}\n}\n\nasync function confirmStep<L extends string, C>(\n\tcontext: StepUpContext<L, C>,\n\trun: () => Promise<unknown>,\n\t{ request, language, via }: Parameters<StepUpSteps<L>['confirm']>[1],\n): Promise<StepUpConfirmAnswer | StepUpStayed<StepUpConfirmAnswer>> {\n\tsamesitePost(context.steps.signIn.json, request);\n\tconst intent = 'confirm-step-up';\n\ttry {\n\t\tawait run();\n\t\treturn { ok: true, intent };\n\t} catch (error) {\n\t\tconst refusal = context.steps.signIn.errors.apiRefusal(error, language);\n\t\tif (!refusal) throw error;\n\t\tconst stay = (\n\t\t\tfailure: Omit<Refused, 'ok' | 'intent'>,\n\t\t): StepUpStayed<StepUpConfirmAnswer> =>\n\t\t\tdata<StepUpConfirmAnswer>(\n\t\t\t\t{ ok: false, intent, ...failure },\n\t\t\t\t{ status: refusal.status },\n\t\t\t);\n\t\tconst failed = (message: string) =>\n\t\t\tstay({ error: 'failed' satisfies StepUpError, locked: false, message });\n\t\tif (!isApiErrorLike(error)) return failed(refusal.message);\n\t\tif (error.status === 429) {\n\t\t\tconst retryAfter = retryAfterOf(error);\n\t\t\treturn stay({\n\t\t\t\terror: 'throttled',\n\t\t\t\tlocked: false,\n\t\t\t\tmessage: worded(context, error, language),\n\t\t\t\t...(retryAfter === undefined ? {} : { retryAfter }),\n\t\t\t});\n\t\t}\n\t\tif (error.code === context.invalidCode) {\n\t\t\treturn stay(refusedCode(context, error, via, language));\n\t\t}\n\t\tif (error.code && context.challengeOver.includes(error.code)) {\n\t\t\treturn stay({\n\t\t\t\terror: 'expired',\n\t\t\t\tlocked: false,\n\t\t\t\tmessage:\n\t\t\t\t\tcontext.steps.wording?.(error, language) ??\n\t\t\t\t\tcontext.steps.spent(language),\n\t\t\t});\n\t\t}\n\t\treturn failed(worded(context, error, language));\n\t}\n}\n\nasync function routeStep<L extends string, C>(\n\tcontext: StepUpContext<L, C>,\n\trun: StepUpRun,\n\tcall: Parameters<StepUpSteps<L>['request']>[1],\n) {\n\tconst { json } = context.steps.signIn;\n\tsamesitePost(json, call.request);\n\tif (context.steps.onSignedOut !== 'sign-in')\n\t\treturn routeIntent(context, run, call);\n\tconst redirect = context.signInRedirect;\n\tif (!redirect) return routeIntent(context, run, call);\n\treturn signingOut(\n\t\t{\n\t\t\tsignIn: { signInRedirect: redirect },\n\t\t\tunauthenticated: context.unauthenticated,\n\t\t\trun,\n\t\t\trequest: call.request,\n\t\t},\n\t\t(watched) => routeIntent(context, watched, call),\n\t);\n}\n\nasync function routeIntent<L extends string, C>(\n\tcontext: StepUpContext<L, C>,\n\trun: StepUpRun,\n\tcall: Parameters<StepUpSteps<L>['request']>[1],\n) {\n\tconst { json } = context.steps.signIn;\n\tconst body = (await json.readJson(call.request)) as {\n\t\tintent?: unknown;\n\t\tchallenge?: unknown;\n\t\tcode?: unknown;\n\t\tvia?: unknown;\n\t} | null;\n\tif (body?.intent === 'request-step-up') {\n\t\treturn requestStep(context, () => run.request(), call);\n\t}\n\tif (\n\t\tbody?.intent === 'confirm-step-up' &&\n\t\ttypeof body.challenge === 'string' &&\n\t\ttypeof body.code === 'string'\n\t) {\n\t\tconst { challenge, code } = body;\n\t\tconst via =\n\t\t\tbody.via === 'email' || body.via === 'secondFactor'\n\t\t\t\t? body.via\n\t\t\t\t: undefined;\n\t\treturn confirmStep(context, () => run.confirm({ challenge, code }), {\n\t\t\t...call,\n\t\t\tvia,\n\t\t});\n\t}\n\tthrow data('Not a step-up intent', { status: 400 });\n}\n\n/**\n * The server side of a BFF's step-up: `request` and `confirm` answer the\n * page's fetcher with `StepUpRequestAnswer` and `StepUpConfirmAnswer`, which\n * `stepUpReducer` takes as they are. It speaks `@nxgt/janus`'s words\n * (`CODE_INVALID`, `TOKEN_*`, `STEP_UP_REQUIRED`); the app maps the rest.\n *\n * @example\n * const stepUp = stepUpSteps({\n * \terrors,\n * \tattemptsLeft: (count, language) => t('code.attempts-left', { count }, language),\n * \tspent: (language) => t('step-up.spent', {}, language),\n * \tlocked: (language) => t('step-up.locked', {}, language),\n * });\n */\nexport function stepUpSteps<L extends string, C = undefined>(\n\toptions: StepUpStepsOptions<L, C>,\n): StepUpSteps<L> {\n\tconst context = resolve(options);\n\treturn {\n\t\trequest: (run, o) => requestStep(context, run, o),\n\t\tconfirm: (run, o) => confirmStep(context, run, o),\n\t\troute: (run, o) => routeStep(context, run, o),\n\t\tisStepUpRequired: (error) =>\n\t\t\tisApiErrorLike(error) && error.code === context.stepUpRequired,\n\t};\n}\n",
|
|
19
19
|
"import { CHALLENGE_OVER } from './codes';\n\n/** `@nxgt/janus`'s code for a mutation that needs a recent step-up. */\nexport const STEP_UP_REQUIRED = 'STEP_UP_REQUIRED';\n\n/**\n * The codes that end a step-up's challenge: unknown, spent, expired or stale,\n * and a second factor that changed since the request (`SECOND_FACTOR_ACTIVE`,\n * `SECOND_FACTOR_NOT_ENROLLED`). The user asks again.\n */\nexport const STEP_UP_OVER = [\n\t...CHALLENGE_OVER,\n\t'TOKEN_STALE',\n\t'SECOND_FACTOR_ACTIVE',\n\t'SECOND_FACTOR_NOT_ENROLLED',\n] as const;\n",
|
|
20
|
-
"import { isApiErrorLike } from '../errors/api-error';\nimport type { SignInFlow } from './flow-types';\nimport type { StepUpRun } from './step-up-types';\n\n/**\n * A signed-out user's failure. From `request`, the API's no-session code or a\n * bare 401 response; from `confirm`, the code only: a 401 there is also what a\n * wrong code answers, so a bare one stays a refusal.\n */\nfunction isSignedOut(\n\terror: unknown,\n\tunauthenticated: string,\n\tfrom: 'request' | 'confirm',\n): boolean {\n\tif (error instanceof Response)\n\t\treturn from === 'request' && error.status === 401;\n\treturn isApiErrorLike(error) && error.code === unauthenticated;\n}\n\n/**\n * The request the sign-in redirect comes back to: the same-site `Referer`'s\n * page (the step-up route has none of its own), else the request's own URL.\n * A `Referer` of another origin (port and protocol count), or one that is not\n * a URL, is ignored. Behind a TLS-terminating proxy an `http` `request.url`\n * never matches an `https` `Referer`, so `next` is the route's own path.\n */\nexport function cameFrom(request: Request): Request {\n\tconst referer = request.headers.get('referer');\n\tif (referer) {\n\t\ttry {\n\t\t\tconst from = new URL(referer);\n\t\t\tif (from.origin === new URL(request.url).origin) {\n\t\t\t\treturn new Request(from, { headers: request.headers });\n\t\t\t}\n\t\t} catch {\n\t\t\t// Not a URL: the request's own path.\n\t\t}\n\t}\n\treturn request;\n}\n\n/**\n * Runs `route` over a `run` that notes a signed-out failure, then throws the\n * flow's sign-in redirect in place of whatever the step answered or threw.\n */\nexport async function signingOut<A>(\n\t{\n\t\tsignIn,\n\t\tunauthenticated,\n\t\trun,\n\t\trequest,\n\t}: {\n\t\treadonly signIn: Pick<SignInFlow<string, never>, 'signInRedirect'>;\n\t\treadonly unauthenticated: string;\n\t\treadonly run: StepUpRun;\n\t\treadonly request: Request;\n\t},\n\troute: (watched: StepUpRun) => Promise<A>,\n): Promise<A> {\n\tlet signedOut = false;\n\tconst watched: StepUpRun = {\n\t\trequest: async () => {\n\t\t\ttry {\n\t\t\t\treturn await run.request();\n\t\t\t} catch (error) {\n\t\t\t\tsignedOut ||= isSignedOut(error, unauthenticated, 'request');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tconfirm: async (input) => {\n\t\t\ttry {\n\t\t\t\treturn await run.confirm(input);\n\t\t\t} catch (error) {\n\t\t\t\tsignedOut ||= isSignedOut(error, unauthenticated, 'confirm');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n\tconst redirect = () => signIn.signInRedirect(cameFrom(request));\n\tlet answer: A;\n\ttry {\n\t\tanswer = await route(watched);\n\t} catch (error) {\n\t\tthrow signedOut ? redirect() : error;\n\t}\n\tif (signedOut) throw redirect();\n\treturn answer;\n}\n"
|
|
20
|
+
"import { isApiErrorLike } from '../errors/api-error';\nimport type { SignInFlow } from './flow-types';\nimport type { StepUpRun } from './step-up-types';\n\n/**\n * A signed-out user's failure. From `request`, the API's no-session code or a\n * bare 401 response; from `confirm`, the code only: a 401 there is also what a\n * wrong code answers, so a bare one stays a refusal.\n */\nfunction isSignedOut(\n\terror: unknown,\n\tunauthenticated: string,\n\tfrom: 'request' | 'confirm',\n): boolean {\n\tif (error instanceof Response)\n\t\treturn from === 'request' && error.status === 401;\n\treturn isApiErrorLike(error) && error.code === unauthenticated;\n}\n\n/**\n * The request the sign-in redirect comes back to: the same-site `Referer`'s\n * page (the step-up route has none of its own), else the request's own URL.\n * A `Referer` of another origin (port and protocol count), or one that is not\n * a URL, is ignored. Behind a TLS-terminating proxy an `http` `request.url`\n * never matches an `https` `Referer`, so `next` is the route's own path.\n */\nexport function cameFrom(request: Request): Request {\n\tconst referer = request.headers.get('referer');\n\tif (referer) {\n\t\ttry {\n\t\t\tconst from = new URL(referer);\n\t\t\tif (from.origin === new URL(request.url).origin) {\n\t\t\t\treturn new Request(from, { headers: request.headers });\n\t\t\t}\n\t\t} catch {\n\t\t\t// Not a URL: the request's own path.\n\t\t}\n\t}\n\treturn request;\n}\n\n/**\n * Runs `route` over a `run` that notes a signed-out failure, then throws the\n * flow's sign-in redirect in place of whatever the step answered or threw.\n */\nexport async function signingOut<A>(\n\t{\n\t\tsignIn,\n\t\tunauthenticated,\n\t\trun,\n\t\trequest,\n\t}: {\n\t\treadonly signIn: Pick<SignInFlow<string, never>, 'signInRedirect'>;\n\t\treadonly unauthenticated: string;\n\t\treadonly run: StepUpRun;\n\t\treadonly request: Request;\n\t},\n\troute: (watched: StepUpRun) => Promise<A>,\n): Promise<A> {\n\tlet signedOut = false;\n\tconst watched: StepUpRun = {\n\t\trequest: async () => {\n\t\t\ttry {\n\t\t\t\treturn await run.request();\n\t\t\t} catch (error) {\n\t\t\t\tsignedOut ||= isSignedOut(error, unauthenticated, 'request');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tconfirm: async (input) => {\n\t\t\ttry {\n\t\t\t\treturn await run.confirm(input);\n\t\t\t} catch (error) {\n\t\t\t\tsignedOut ||= isSignedOut(error, unauthenticated, 'confirm');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n\tconst redirect = () => signIn.signInRedirect(cameFrom(request));\n\tlet answer: A;\n\ttry {\n\t\tanswer = await route(watched);\n\t} catch (error) {\n\t\tthrow signedOut ? redirect() : error;\n\t}\n\tif (signedOut) throw redirect();\n\treturn answer;\n}\n",
|
|
21
|
+
"/** What `createSignInThrottle` takes; every field has a default. */\nexport interface SignInThrottleOptions {\n\t/** Failures one key may make within `windowMs` before it waits. 5 by default. */\n\treadonly max?: number | undefined;\n\t/** The per-key window, in milliseconds. 15 minutes by default. */\n\treadonly windowMs?: number | undefined;\n\t/** How many keys are held; past it the oldest is dropped. 10 000 by default. */\n\treadonly maxKeys?: number | undefined;\n\t/** Failures, all keys together, within `globalWindowMs` before every sign-in is delayed. 100 by default. */\n\treadonly globalMax?: number | undefined;\n\t/** The global window, in milliseconds: also the longest the global delay lasts. 1 minute by default. */\n\treadonly globalWindowMs?: number | undefined;\n\t/** Password verifications that run at once. 2 by default. */\n\treadonly maxConcurrentVerifies?: number | undefined;\n\t/** Verifications that wait for a slot; past it `verify` answers `{ busy: true }`. 4 by default; 0 for none. */\n\treadonly maxQueuedVerifies?: number | undefined;\n\t/** The clock, in milliseconds. `Date.now` by default; inject one in a test. */\n\treadonly now?: (() => number) | undefined;\n}\n\n/** What `verify` answers: the task's value, or a refusal because the queue was full. */\nexport type VerifyResult<T> =\n\t| { readonly busy: false; readonly value: T }\n\t| { readonly busy: true };\n\n/** A per-process sign-in throttle. */\nexport interface SignInThrottle {\n\t/** Seconds to wait before this key may try again, 0 when it may. Records nothing. */\n\twait(key: string): number;\n\t/** Record a failed attempt for the key (and in the global bucket). */\n\tfail(key: string): void;\n\t/** Forget the key's failures after a successful sign-in. The global bucket is left alone. */\n\tclear(key: string): void;\n\t/** Run a password verification under the concurrency limit, or refuse when the wait queue is full. A rejection of `task` passes through and frees its slot. */\n\tverify<T>(task: () => Promise<T>): Promise<VerifyResult<T>>;\n\t/** How many keys are held now. */\n\treadonly size: number;\n}\n\nconst DEFAULTS = {\n\tmax: 5,\n\twindowMs: 15 * 60_000,\n\tmaxKeys: 10_000,\n\tglobalMax: 100,\n\tglobalWindowMs: 60_000,\n\tmaxConcurrentVerifies: 2,\n\tmaxQueuedVerifies: 4,\n} as const;\n\nfunction positive(name: string, value: number, allowZero = false): number {\n\tconst ok = Number.isInteger(value) && (allowZero ? value >= 0 : value > 0);\n\tif (!ok) {\n\t\tthrow new TypeError(\n\t\t\t`createSignInThrottle(): ${name} must be a positive integer${allowZero ? ' or 0' : ''}; got ${String(value)}.`,\n\t\t);\n\t}\n\treturn value;\n}\n\n/**\n * A failed-attempt throttle for a password sign-in, in this process's memory:\n * `max` failures per key within `windowMs`, a bounded number of keys, a global\n * bucket that delays every sign-in for a few seconds rather than locking an\n * account, and `verify`, which holds password hashing (argon2 at 64 MiB each)\n * to a small concurrency. Each process counts alone: behind several instances\n * the limits multiply. Pass the lower-cased address as the key.\n *\n * @example\n * const throttle = createSignInThrottle({ max: 5, windowMs: 15 * 60_000 });\n * // in the sign-in action\n * const seconds = throttle.wait(email);\n * if (seconds > 0) return tooMany(seconds);\n * const checked = await throttle.verify(() => Bun.password.verify(password, hash));\n * if (checked.busy) return tryLater();\n * if (!checked.value) { throttle.fail(email); return refused(); }\n * throttle.clear(email);\n */\nexport function createSignInThrottle(\n\toptions: SignInThrottleOptions = {},\n): SignInThrottle {\n\tconst max = positive('max', options.max ?? DEFAULTS.max);\n\tconst windowMs = positive('windowMs', options.windowMs ?? DEFAULTS.windowMs);\n\tconst maxKeys = positive('maxKeys', options.maxKeys ?? DEFAULTS.maxKeys);\n\tconst globalMax = positive(\n\t\t'globalMax',\n\t\toptions.globalMax ?? DEFAULTS.globalMax,\n\t);\n\tconst globalWindowMs = positive(\n\t\t'globalWindowMs',\n\t\toptions.globalWindowMs ?? DEFAULTS.globalWindowMs,\n\t);\n\tconst slots = positive(\n\t\t'maxConcurrentVerifies',\n\t\toptions.maxConcurrentVerifies ?? DEFAULTS.maxConcurrentVerifies,\n\t);\n\tconst queueLimit = positive(\n\t\t'maxQueuedVerifies',\n\t\toptions.maxQueuedVerifies ?? DEFAULTS.maxQueuedVerifies,\n\t\ttrue,\n\t);\n\tconst now = options.now ?? Date.now;\n\n\t// A Map keeps insertion order: the first key is the oldest.\n\tconst failures = new Map<string, number[]>();\n\tlet global: number[] = [];\n\n\tconst recent = (key: string, at: number): number[] => {\n\t\tconst kept = (failures.get(key) ?? []).filter(\n\t\t\t(time) => at - time < windowMs,\n\t\t);\n\t\tif (kept.length === 0) failures.delete(key);\n\t\treturn kept;\n\t};\n\tconst seconds = (ms: number): number => Math.ceil(ms / 1000);\n\n\tlet running = 0;\n\tconst queue: Array<() => void> = [];\n\tconst release = () => {\n\t\tconst next = queue.shift();\n\t\tif (next) next();\n\t\telse running--;\n\t};\n\n\treturn {\n\t\twait(key) {\n\t\t\tconst at = now();\n\t\t\tlet wait = 0;\n\t\t\tconst kept = recent(key, at);\n\t\t\tif (kept.length >= max) {\n\t\t\t\twait = seconds(windowMs - (at - (kept[0] as number)));\n\t\t\t}\n\t\t\tglobal = global.filter((time) => at - time < globalWindowMs);\n\t\t\tif (global.length >= globalMax) {\n\t\t\t\twait = Math.max(\n\t\t\t\t\twait,\n\t\t\t\t\tseconds(globalWindowMs - (at - (global[0] as number))),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn wait;\n\t\t},\n\t\tfail(key) {\n\t\t\tconst at = now();\n\t\t\tconst kept = [...recent(key, at), at].slice(-max);\n\t\t\tfailures.delete(key);\n\t\t\tfailures.set(key, kept);\n\t\t\tif (failures.size > maxKeys) {\n\t\t\t\tconst oldest = failures.keys().next().value;\n\t\t\t\tif (oldest !== undefined) failures.delete(oldest);\n\t\t\t}\n\t\t\tglobal = [\n\t\t\t\t...global.filter((time) => at - time < globalWindowMs),\n\t\t\t\tat,\n\t\t\t].slice(-globalMax);\n\t\t},\n\t\tclear(key) {\n\t\t\tfailures.delete(key);\n\t\t},\n\t\tasync verify(task) {\n\t\t\tif (running >= slots) {\n\t\t\t\tif (queue.length >= queueLimit) return { busy: true };\n\t\t\t\tawait new Promise<void>((resolve) => queue.push(resolve));\n\t\t\t} else {\n\t\t\t\trunning++;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\treturn { busy: false, value: await task() };\n\t\t\t} finally {\n\t\t\t\trelease();\n\t\t\t}\n\t\t},\n\t\tget size() {\n\t\t\treturn failures.size;\n\t\t},\n\t};\n}\n"
|
|
21
22
|
],
|
|
22
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AACO,IAAM,eAAe;AAGrB,IAAM,iBAAiB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACD;AAGO,IAAM,iBAAiB;AAGvB,IAAM,kBAAkB;;ACO/B,IAAM,YAAY,EAAE,KAAK,OAAO,QAAQ,UAAU,MAAM,OAAO;AAGxD,SAAS,aAAa,CAC5B,QACA,UACA,QAC+B;AAAA,EAC/B,IAAI,CAAC,OAAO,OAAO,WAAW,QAAQ,GAAG;AAAA,IACxC,MAAM,IAAI,UACT,GAAG,2DAA2D,KAAK,UAAU,QAAQ,IACtF;AAAA,EACD;AAAA,EACA,IAAI,aAAa,UAAU,CAAC,QAAQ;AAAA,IACnC,MAAM,IAAI,UACT,GAAG,0GACJ;AAAA,EACD;AAAA;AAID,IAAM,QAAQ;AAGd,IAAM,OAAO;AAGN,IAAM,eAAe,CAAC,SAA0B,MAAM,KAAK,IAAI;AAE/D,IAAM,eAAe,CAAC,SAA0B,KAAK,KAAK,IAAI;AAO9D,SAAS,eAAe,CAC9B,MACA,SACE,QAAQ,OAAO,KAAK,QAAQ,WAAW,SAChC;AAAA,EACT,IAAI,CAAC,aAAa,IAAI,GAAG;AAAA,IACxB,MAAM,IAAI,UACT,+BAA+B,KAAK,UAAU,IAAI,6CACnD;AAAA,EACD;AAAA,EACA,IAAI,CAAC,aAAa,IAAI,GAAG;AAAA,IACxB,MAAM,IAAI,UACT,+BAA+B,KAAK,UAAU,IAAI,sFACnD;AAAA,EACD;AAAA,EACA,cAAc,sBAAsB,UAAU,MAAM;AAAA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,EAAE,EAAE,MAAM,CAAC,GAAG;AAAA,MAChD,SAAS,OAAO,GAAG;AAAA,MACnB,SAAS,IAAI,KAAK,IAAI;AAAA,MACtB,IAAI,SAAS,OAAO,SAAS;AAAA,QAC5B,MAAM,SAAS,SAAS,KAAK,EAAE,KAAK,EAAE;AAAA,QACtC,IAAI,WAAW;AAAA,UAAW,SAAS,OAAO,MAAM;AAAA,MACjD;AAAA,MACA,SAAS;AAAA,QACR,GAAG,OAAO,OAAO,CAAC,SAAS,KAAK,OAAO,cAAc;AAAA,QACrD;AAAA,MACD,EAAE,MAAM,CAAC,SAAS;AAAA;AAAA,IAEnB,KAAK,CAAC,KAAK;AAAA,MACV,SAAS,OAAO,GAAG;AAAA;AAAA,UAEd,MAAM,CAAC,MAAM;AAAA,MAClB,IAAI,WAAW,OAAO;AAAA,QACrB,IAAI,MAAM,UAAU;AAAA,UAAY,OAAO,EAAE,MAAM,KAAK;AAAA,QACpD,MAAM,IAAI,QAAc,CAAC,YAAY,MAAM,KAAK,OAAO,CAAC;AAAA,MACzD,EAAE,KAAK;AAAA,QACN;AAAA;AAAA,MAED,IAAI;AAAA,QACH,OAAO,EAAE,MAAM,OAAO,OAAO,MAAM,KAAK,EAAE;AAAA,QACzC,QAAQ;AAAA,QACT,QAAQ;AAAA;AAAA;AAAA,QAGN,IAAI,GAAG;AAAA,MACV,OAAO,SAAS;AAAA;AAAA,EAElB;AAAA;",
|
|
24
|
+
"debugId": "30B84BDDE86DDE4164756E2164756E21",
|
|
24
25
|
"names": []
|
|
25
26
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** What `createSignInThrottle` takes; every field has a default. */
|
|
2
|
+
export interface SignInThrottleOptions {
|
|
3
|
+
/** Failures one key may make within `windowMs` before it waits. 5 by default. */
|
|
4
|
+
readonly max?: number | undefined;
|
|
5
|
+
/** The per-key window, in milliseconds. 15 minutes by default. */
|
|
6
|
+
readonly windowMs?: number | undefined;
|
|
7
|
+
/** How many keys are held; past it the oldest is dropped. 10 000 by default. */
|
|
8
|
+
readonly maxKeys?: number | undefined;
|
|
9
|
+
/** Failures, all keys together, within `globalWindowMs` before every sign-in is delayed. 100 by default. */
|
|
10
|
+
readonly globalMax?: number | undefined;
|
|
11
|
+
/** The global window, in milliseconds: also the longest the global delay lasts. 1 minute by default. */
|
|
12
|
+
readonly globalWindowMs?: number | undefined;
|
|
13
|
+
/** Password verifications that run at once. 2 by default. */
|
|
14
|
+
readonly maxConcurrentVerifies?: number | undefined;
|
|
15
|
+
/** Verifications that wait for a slot; past it `verify` answers `{ busy: true }`. 4 by default; 0 for none. */
|
|
16
|
+
readonly maxQueuedVerifies?: number | undefined;
|
|
17
|
+
/** The clock, in milliseconds. `Date.now` by default; inject one in a test. */
|
|
18
|
+
readonly now?: (() => number) | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** What `verify` answers: the task's value, or a refusal because the queue was full. */
|
|
21
|
+
export type VerifyResult<T> = {
|
|
22
|
+
readonly busy: false;
|
|
23
|
+
readonly value: T;
|
|
24
|
+
} | {
|
|
25
|
+
readonly busy: true;
|
|
26
|
+
};
|
|
27
|
+
/** A per-process sign-in throttle. */
|
|
28
|
+
export interface SignInThrottle {
|
|
29
|
+
/** Seconds to wait before this key may try again, 0 when it may. Records nothing. */
|
|
30
|
+
wait(key: string): number;
|
|
31
|
+
/** Record a failed attempt for the key (and in the global bucket). */
|
|
32
|
+
fail(key: string): void;
|
|
33
|
+
/** Forget the key's failures after a successful sign-in. The global bucket is left alone. */
|
|
34
|
+
clear(key: string): void;
|
|
35
|
+
/** Run a password verification under the concurrency limit, or refuse when the wait queue is full. A rejection of `task` passes through and frees its slot. */
|
|
36
|
+
verify<T>(task: () => Promise<T>): Promise<VerifyResult<T>>;
|
|
37
|
+
/** How many keys are held now. */
|
|
38
|
+
readonly size: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A failed-attempt throttle for a password sign-in, in this process's memory:
|
|
42
|
+
* `max` failures per key within `windowMs`, a bounded number of keys, a global
|
|
43
|
+
* bucket that delays every sign-in for a few seconds rather than locking an
|
|
44
|
+
* account, and `verify`, which holds password hashing (argon2 at 64 MiB each)
|
|
45
|
+
* to a small concurrency. Each process counts alone: behind several instances
|
|
46
|
+
* the limits multiply. Pass the lower-cased address as the key.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const throttle = createSignInThrottle({ max: 5, windowMs: 15 * 60_000 });
|
|
50
|
+
* // in the sign-in action
|
|
51
|
+
* const seconds = throttle.wait(email);
|
|
52
|
+
* if (seconds > 0) return tooMany(seconds);
|
|
53
|
+
* const checked = await throttle.verify(() => Bun.password.verify(password, hash));
|
|
54
|
+
* if (checked.busy) return tryLater();
|
|
55
|
+
* if (!checked.value) { throttle.fail(email); return refused(); }
|
|
56
|
+
* throttle.clear(email);
|
|
57
|
+
*/
|
|
58
|
+
export declare function createSignInThrottle(options?: SignInThrottleOptions): SignInThrottle;
|
|
59
|
+
//# sourceMappingURL=throttle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../src/session/throttle.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,MAAM,WAAW,qBAAqB;IACrC,iFAAiF;IACjF,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,gFAAgF;IAChF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,4GAA4G;IAC5G,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,wGAAwG;IACxG,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7C,6DAA6D;IAC7D,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpD,+GAA+G;IAC/G,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,+EAA+E;IAC/E,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC;CAC1C;AAED,wFAAwF;AACxF,MAAM,MAAM,YAAY,CAAC,CAAC,IACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAE3B,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC9B,qFAAqF;IACrF,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,sEAAsE;IACtE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,6FAA6F;IAC7F,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,+JAA+J;IAC/J,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAsBD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CACnC,OAAO,GAAE,qBAA0B,GACjC,cAAc,CA+FhB"}
|
package/docs/README.md
CHANGED
|
@@ -19,9 +19,9 @@ installable and usable offline, wording an API's refusals, the BFF session, a Gr
|
|
|
19
19
|
| [Deploying](guide/deploying.md) | running the build with `bun build/server/index.js`, and the Docker image |
|
|
20
20
|
| [Installable and offline](guide/pwa.md) | making the app installable and usable offline: the subpaths of `@alxia/react-router/pwa`, the service worker (`startWorker`, `/pwa/worker`), its build by `alxia()` or `buildWorker` (`/pwa/build`), its contract and cache names, which requests the worker caches and which responses it stores, the precache list read from a build, or clearing the caches at sign-out |
|
|
21
21
|
| [An API's refusals](guide/errors.md) | wording a GraphQL API's refusals for the pages: recognising an `ApiError` or a REST API's `problemError`, the request id, the page a request is for, the catalogue store, the form checks in the API's words, the provider, and the loaders, the error page and the actions that answer with it, the JSON actions with their CSRF check and fetcher hook, calling the API from a loader (`apiCallFailure`), and keeping the catalogue fresh (`@alxia/react-router/errors`) |
|
|
22
|
-
| [A BFF session](guide/session.md) | redirecting after sign-in to a page of the site and nowhere else, the sign-in pages' paths, the session's cookies, the sign-in flow (where an answer lands, a refused code, the viewer, sign-out; `@alxia/react-router/session`), the pages a mail's link opens (a magic link, a password reset: `authLinks`), the page's hooks (sign-out, a mail link's parameter, a one-code field; `@alxia/react-router/session/react`), the step-up route's signed-out handling (`onSignedOut`), and the step-up's state and the props it gives the UI (`@alxia/react-router/session/model`) |
|
|
22
|
+
| [A BFF session](guide/session.md) | redirecting after sign-in to a page of the site and nowhere else, the sign-in pages' paths, the session's cookies, a signed session and a sign-in throttle (`signedSession`, `createSignInThrottle`), the sign-in flow (where an answer lands, a refused code, the viewer, sign-out; `@alxia/react-router/session`), the pages a mail's link opens (a magic link, a password reset: `authLinks`), the page's hooks (sign-out, a mail link's parameter, a one-code field; `@alxia/react-router/session/react`), the step-up route's signed-out handling (`onSignedOut`), and the step-up's state and the props it gives the UI (`@alxia/react-router/session/model`) |
|
|
23
23
|
| [Links through React Router](guide/link.md) | `RouterLink`, React Router's `Link` as the link component of a UI library that hands `href` and spreads anchor props; `@alxia/react-router/link` |
|
|
24
|
-
| [A fetcher's fresh answer](guide/fetcher.md) | `useFetcherAnswer`, a handler called once per new answer of a keyed fetcher, not for the data it held at mount; `useDebouncedFetcher`, a resource route loaded for what is typed (pause, minimum length, stale answer kept, retry); `@alxia/react-router/fetcher` |
|
|
24
|
+
| [A fetcher's fresh answer](guide/fetcher.md) | `useFetcherAnswer`, `useFetcherPromise` (one submission's answer as a Promise), a handler called once per new answer of a keyed fetcher, not for the data it held at mount; `useDebouncedFetcher`, a resource route loaded for what is typed (pause, minimum length, stale answer kept, retry); `@alxia/react-router/fetcher` |
|
|
25
25
|
| [Lists whose state is the URL](guide/lists.md) | a search and filters in the address bar that drop the cursor (`useSearchChange`), a skeleton while the same page reloads (`useSameRouteLoading`), and a load-more button that appends pages by cursor and keeps the rows when one fails (`usePagedRows`); `@alxia/react-router/lists` |
|
|
26
26
|
| [Subscriptions for a BFF](guide/subscriptions.md) | showing a GraphQL subscription in the browser without giving it the API's token or a way to write a document: a resource route with a map of operation names to the server's documents, the same-site check, the bearer from the session, extra upstream headers, a heartbeat, abort propagation, size limits and a 429 passed through with `retryAfter` (`@alxia/react-router/subscription`) |
|
|
27
27
|
| [Troubleshooting](troubleshooting.md) | something went wrong and you have the message, or a page streams, hydrates or reads its context unlike you expected |
|
package/docs/guide/fetcher.md
CHANGED
|
@@ -41,6 +41,50 @@ export function SaveForm() {
|
|
|
41
41
|
hands a new object each time. An answer that comes back as the object seen
|
|
42
42
|
before (A, B, then A again) is a new answer once B was seen.
|
|
43
43
|
|
|
44
|
+
## One submission's answer as a Promise: `useFetcherPromise(fetcher, options?)`
|
|
45
|
+
|
|
46
|
+
A confirm dialog whose `onConfirm` returns a Promise stays open, and shows the
|
|
47
|
+
error, while the Promise rejects. `useFetcherPromise` ties a submission to the
|
|
48
|
+
fetcher's next new answer, on top of `useFetcherAnswer`, so the app keeps no
|
|
49
|
+
ref of resolve and reject.
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { useJsonFetcher } from '@alxia/react-router/errors';
|
|
53
|
+
import { useFetcherPromise } from '@alxia/react-router/fetcher';
|
|
54
|
+
|
|
55
|
+
const { fetcher, post } = useJsonFetcher<typeof action>('delete');
|
|
56
|
+
const run = useFetcherPromise(fetcher, {
|
|
57
|
+
refusal: (result) => (result.ok ? undefined : result.error),
|
|
58
|
+
});
|
|
59
|
+
// a confirm dialog that stays open, and shows the error, while this rejects
|
|
60
|
+
const onConfirm = () => run(() => post({ intent: 'delete', id }));
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- `run(submit)` calls `submit` and returns a Promise. It resolves with the
|
|
64
|
+
next new answer, or rejects when `options.refusal(answer)` returns a
|
|
65
|
+
message (an `Error` with that message) or an `Error` (thrown as it is).
|
|
66
|
+
Without `refusal` every answer resolves. `run` is the same function on every
|
|
67
|
+
render.
|
|
68
|
+
- An answer the fetcher already held when `run` was called never settles the
|
|
69
|
+
Promise, nor does the data present at mount; only an answer that arrives
|
|
70
|
+
after the call, once the fetcher is idle, does.
|
|
71
|
+
- **A second `run` while one is pending replaces it**: the older Promise
|
|
72
|
+
rejects with a `FetcherPromiseAborted` (`reason: 'superseded'`) and the newer
|
|
73
|
+
one gets the answer. The fetcher itself still sends both submissions (React
|
|
74
|
+
Router answers the last), so disable the button while the dialog works if
|
|
75
|
+
the first must not be sent.
|
|
76
|
+
- **An unmount rejects the pending Promise** with a `FetcherPromiseAborted`
|
|
77
|
+
(`reason: 'unmounted'`), so nothing waits forever; the caller (the dialog)
|
|
78
|
+
is usually gone and ignores it. Check `error instanceof FetcherPromiseAborted`
|
|
79
|
+
to tell it from a refusal.
|
|
80
|
+
- Catch every Promise `run` returns: an abort rejects it, and one nobody
|
|
81
|
+
handles is an unhandled rejection. Where the caller does not await it:
|
|
82
|
+
`run(...).catch((e) => { if (!(e instanceof FetcherPromiseAborted)) throw e; })`.
|
|
83
|
+
The example assumes `fetcherResult`'s shape, `{ ok: false, error: string }`.
|
|
84
|
+
- A `refusal` that throws rejects the Promise with what it threw.
|
|
85
|
+
- A `submit` that throws, or returns a Promise that rejects, rejects the
|
|
86
|
+
Promise with that error.
|
|
87
|
+
|
|
44
88
|
## Typeahead: `useDebouncedFetcher(value, to, options?)`
|
|
45
89
|
|
|
46
90
|
A search box, a suggestion list or a preview loads a resource route for what
|
package/docs/guide/session.md
CHANGED
|
@@ -414,6 +414,67 @@ environment; changing it signs everyone out. The session is not revocable
|
|
|
414
414
|
before its expiry: keep `maxAge` short, and check the password again for
|
|
415
415
|
anything sensitive.
|
|
416
416
|
|
|
417
|
+
### A sign-in throttle
|
|
418
|
+
|
|
419
|
+
A password sign-in needs a failed-attempt throttle and a cap on concurrent
|
|
420
|
+
password hashes (argon2 at 64 MiB each is a memory spike when a hundred
|
|
421
|
+
requests arrive together). `createSignInThrottle` is both, next to
|
|
422
|
+
`signedSession`, and works with any sign-in, not only a signed session.
|
|
423
|
+
|
|
424
|
+
```ts
|
|
425
|
+
// app/throttle.server.ts
|
|
426
|
+
import { createSignInThrottle } from '@alxia/react-router/session';
|
|
427
|
+
|
|
428
|
+
export const throttle = createSignInThrottle({
|
|
429
|
+
max: 5, // failures per key...
|
|
430
|
+
windowMs: 15 * 60_000, // ...within this window
|
|
431
|
+
});
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
```ts
|
|
435
|
+
// in the sign-in action
|
|
436
|
+
const email = String(form.get('email')).trim().toLowerCase();
|
|
437
|
+
|
|
438
|
+
const seconds = throttle.wait(email);
|
|
439
|
+
if (seconds > 0) return tooMany(seconds); // e.g. a 429 with Retry-After: seconds
|
|
440
|
+
|
|
441
|
+
const checked = await throttle.verify(() => Bun.password.verify(password, hash));
|
|
442
|
+
if (checked.busy) return tryLater(); // e.g. a 503 with Retry-After: 2
|
|
443
|
+
if (!checked.value) {
|
|
444
|
+
throttle.fail(email);
|
|
445
|
+
return refused();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
throttle.clear(email);
|
|
449
|
+
headers.append('Set-Cookie', await operator.commit());
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
- `wait(key)` returns the seconds to wait, `0` when the key may try. It
|
|
453
|
+
records nothing, so call it before every attempt, also for an address that
|
|
454
|
+
does not exist: answer the same for a known and an unknown one.
|
|
455
|
+
- `fail(key)` records a failure; `clear(key)` forgets the key after a success.
|
|
456
|
+
A key is blocked at `max` failures within `windowMs`, until the oldest
|
|
457
|
+
leaves the window.
|
|
458
|
+
- `maxKeys` (10 000 by default) bounds the memory an attacker can make you
|
|
459
|
+
hold: past it the oldest key is dropped.
|
|
460
|
+
- The global bucket counts every failure, all keys together. Past `globalMax`
|
|
461
|
+
failures within `globalWindowMs` (100 and one minute by default), `wait`
|
|
462
|
+
answers the seconds until the oldest of them leaves that window, for every
|
|
463
|
+
key. It delays everyone briefly and lifts itself; it never locks an
|
|
464
|
+
account, so one attacker spraying addresses cannot lock the real owner out
|
|
465
|
+
for the per-key window. `clear` leaves it alone.
|
|
466
|
+
- `verify(task)` runs `task` (the password check) with at most
|
|
467
|
+
`maxConcurrentVerifies` (2) at once, and up to `maxQueuedVerifies` (4) more
|
|
468
|
+
waiting for a slot. Past that it answers `{ busy: true }` without running
|
|
469
|
+
the task. Otherwise `{ busy: false, value }`; a rejection of `task` passes
|
|
470
|
+
through and frees its slot.
|
|
471
|
+
- `now` replaces the clock (`() => number` in milliseconds), for a test.
|
|
472
|
+
|
|
473
|
+
It is per process, in memory: a restart forgets every failure, and behind
|
|
474
|
+
several instances (or workers) each counts alone, so the effective limits are
|
|
475
|
+
multiplied by the instance count. For a limit shared between instances, count
|
|
476
|
+
in a store they share (for example `@nxgt/redis`' rate limits).
|
|
477
|
+
|
|
417
478
|
### Safari and `http://localhost`
|
|
418
479
|
|
|
419
480
|
Safari (WebKit) drops a `Secure` cookie set over `http://localhost`, where
|
package/docs/roadmap.md
CHANGED
|
@@ -88,6 +88,18 @@ Nothing planned.
|
|
|
88
88
|
|
|
89
89
|
### Unreleased
|
|
90
90
|
|
|
91
|
+
- **`createSignInThrottle` on `/session`.** A failed-attempt throttle for a
|
|
92
|
+
password sign-in: `wait`, `fail` and `clear` per key within a window, a
|
|
93
|
+
bounded number of keys, a global bucket that delays rather than locks, and
|
|
94
|
+
`verify`, which holds password hashing to a small concurrency and refuses
|
|
95
|
+
past a short queue. Per process. See [A sign-in
|
|
96
|
+
throttle](guide/session.md#a-sign-in-throttle).
|
|
97
|
+
|
|
98
|
+
- **`useFetcherPromise` on `/fetcher`.** `run(submit)` returns a Promise
|
|
99
|
+
settled by the fetcher's next new answer, rejected with an `Error` when your
|
|
100
|
+
`refusal(answer)` returns a message. See [One submission's answer as a
|
|
101
|
+
Promise](guide/fetcher.md#one-submissions-answer-as-a-promise-usefetcherpromisefetcher-options).
|
|
102
|
+
|
|
91
103
|
- **A health probe in `createServer`.** `health: '/health'` or `{ path,
|
|
92
104
|
check, timeout }` declares `@alxia/core`'s liveness probe, in text, before
|
|
93
105
|
every middleware. See [A health
|
package/docs/troubleshooting.md
CHANGED
|
@@ -86,6 +86,7 @@ a loader, a message React Router or the browser prints, or an error from
|
|
|
86
86
|
- [`TypeError: sessionCookies(): sameSite "none" needs secure: true, since a browser drops a SameSite=None cookie without Secure.`](#typeerror-sessioncookies-samesite-none-needs-secure-true-since-a-browser-drops-a-samesitenone-cookie-without-secure)
|
|
87
87
|
- [`TypeError: signedSession(): secret must be a string of at least 32 characters.`](#typeerror-signedsession-secret-must-be-a-string-of-at-least-32-characters)
|
|
88
88
|
- [`TypeError: signedSession(): the name "…" must be an RFC 6265 token without a __Host- or __Secure- prefix; …` or `maxAge must be a positive integer of seconds; got ….`](#typeerror-signedsession-the-name--must-be-an-rfc-6265-token-without-a-__host--or-__secure--prefix--or-maxage-must-be-a-positive-integer-of-seconds-got-)
|
|
89
|
+
- [`TypeError: createSignInThrottle(): … must be a positive integer; got ….` or `… must be a positive integer or 0; got ….`](#typeerror-createsigninthrottle--must-be-a-positive-integer-got--or--must-be-a-positive-integer-or-0-got-)
|
|
89
90
|
- [`TypeError: signInFlow(): paths.… must be a path of this site with no query or fragment, starting with a single "/"; got ….`](#typeerror-signinflow-paths-must-be-a-path-of-this-site-with-no-query-or-fragment-starting-with-a-single--got-)
|
|
90
91
|
- [`TypeError: signInPath(): options.path must be a path of this site with no query or fragment, starting with a single "/"; got ….`](#typeerror-signinpath-optionspath-must-be-a-path-of-this-site-with-no-query-or-fragment-starting-with-a-single--got-)
|
|
91
92
|
- [`TypeError: signInFlow(): json must come from jsonActions(), which carries the site check every step runs; this object has none (a hand-made double?). Pass the app's jsonActions({ origin }) instance, or a spread copy of it.`](#typeerror-signinflow-json-must-come-from-jsonactions-which-carries-the-site-check-every-step-runs-this-object-has-none-a-hand-made-double-pass-the-apps-jsonactions-origin--instance-or-a-spread-copy-of-it)
|
|
@@ -631,6 +632,25 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|
|
631
632
|
|
|
632
633
|
The rows stay, `error` is `true`, and `loadMore` retries.
|
|
633
634
|
|
|
635
|
+
### `useFetcherPromise: a newer call replaced this one before the fetcher answered` (or `… the component unmounted before the fetcher answered`)
|
|
636
|
+
|
|
637
|
+
**When:** the Promise `run(submit)` returned rejects with a `FetcherPromiseAborted` instead of the action's answer.
|
|
638
|
+
|
|
639
|
+
**Why:** `'superseded'`: `run` was called again while the first call was still waiting (a double click), so only the newer call gets the answer. `'unmounted'`: the component left before the fetcher answered.
|
|
640
|
+
|
|
641
|
+
**Fix:** disable the control while the Promise is pending, and tell the two cases from a refusal by the class:
|
|
642
|
+
|
|
643
|
+
```ts
|
|
644
|
+
import { FetcherPromiseAborted } from '@alxia/react-router/fetcher';
|
|
645
|
+
|
|
646
|
+
try {
|
|
647
|
+
await run(() => post({ intent: 'delete', id }));
|
|
648
|
+
} catch (error) {
|
|
649
|
+
if (error instanceof FetcherPromiseAborted) return;
|
|
650
|
+
setError((error as Error).message); // the refusal's message
|
|
651
|
+
}
|
|
652
|
+
```
|
|
653
|
+
|
|
634
654
|
### A debounced load lands on the route's `ErrorBoundary`
|
|
635
655
|
|
|
636
656
|
**When:** the resource route behind `useDebouncedFetcher` throws (or throws a `Response`) and the whole page is replaced by its `ErrorBoundary` instead of showing the previous suggestions with a retry.
|
|
@@ -1862,6 +1882,14 @@ TypeError: sessionCookies(): sameSite must be "lax", "strict" or "none"; got "so
|
|
|
1862
1882
|
|
|
1863
1883
|
**Fix:** pass a base name such as `'my-app_operator'` and `maxAge: 8 * 60 * 60`.
|
|
1864
1884
|
|
|
1885
|
+
### `TypeError: createSignInThrottle(): … must be a positive integer; got ….` or `… must be a positive integer or 0; got ….`
|
|
1886
|
+
|
|
1887
|
+
**When:** the module that calls `createSignInThrottle` is imported (the message names the option: `max`, `windowMs`, `maxKeys`, `globalMax`, `globalWindowMs`, `maxConcurrentVerifies` or `maxQueuedVerifies`).
|
|
1888
|
+
|
|
1889
|
+
**Why:** the option is not a whole number above 0 (`maxQueuedVerifies` may be 0, and then the message ends `or 0`), often a value read from the environment as a string or `NaN`.
|
|
1890
|
+
|
|
1891
|
+
**Fix:** convert it first, `max: Number(process.env.SIGNIN_MAX ?? 5)`.
|
|
1892
|
+
|
|
1865
1893
|
### `TypeError: signInFlow(): paths.… must be a path of this site with no query or fragment, starting with a single "/"; got ….`
|
|
1866
1894
|
|
|
1867
1895
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alxia/react-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "alxia as the server of a React Router framework app: server rendering behind the app's hooks, loaders reading its typed context, the client's assets served; the code with no UI an installable app shares (`/pwa`), its hooks (`/pwa/react`), `noCache` for the worker's script (`/pwa/server`), the service worker on Workbox (`/pwa/worker`) and its build (`/pwa/build`), an API's refusals worded for the page (`/errors`), the BFF session: cookies, sign-in, step-up and mail links (`/session`), its page hooks (`/session/react`) and what it shares with the page (`/session/model`), a GraphQL subscription relayed to the browser over SSE (`/subscription`), the page's CSP nonce and inline boot scripts (`/document`) and a streaming `entry.server` (`/entry`)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|