@connextar/house 0.23.1 → 0.23.3
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 +22 -3
- package/dist/analytics/browser.d.ts +1 -0
- package/dist/analytics/browser.d.ts.map +1 -1
- package/dist/analytics/browser.js +20 -3
- package/dist/analytics/browser.js.map +1 -1
- package/dist/analytics/config.d.ts +5 -0
- package/dist/analytics/config.d.ts.map +1 -1
- package/dist/analytics/config.js +4 -1
- package/dist/analytics/config.js.map +1 -1
- package/dist/analytics/react.d.ts.map +1 -1
- package/dist/analytics/react.js +4 -2
- package/dist/analytics/react.js.map +1 -1
- package/dist/analytics/redact.d.ts.map +1 -1
- package/dist/analytics/redact.js +6 -1
- package/dist/analytics/redact.js.map +1 -1
- package/package.json +5 -2
- package/src/account/data-contract.ts +112 -0
- package/src/account/index.ts +11 -0
- package/src/admin/access.ts +267 -0
- package/src/admin/audit.ts +238 -0
- package/src/admin/bootstrap.ts +220 -0
- package/src/admin/client-index.ts +19 -0
- package/src/admin/client.tsx +187 -0
- package/src/admin/index.ts +91 -0
- package/src/admin/proof.ts +155 -0
- package/src/admin/second-factor-index.ts +16 -0
- package/src/admin/second-factor.ts +403 -0
- package/src/admin/testing-index.ts +13 -0
- package/src/admin/testing.ts +299 -0
- package/src/admin/view-as.ts +511 -0
- package/src/ai/config-index.ts +40 -0
- package/src/ai/config.ts +176 -0
- package/src/ai/images.ts +18 -0
- package/src/ai/index.ts +21 -0
- package/src/ai/pricing.ts +107 -0
- package/src/ai/provider.ts +403 -0
- package/src/analytics/browser.ts +400 -0
- package/src/analytics/client-index.ts +12 -0
- package/src/analytics/config.ts +89 -0
- package/src/analytics/index.ts +17 -0
- package/src/analytics/ingest.ts +81 -0
- package/src/analytics/react-index.ts +16 -0
- package/src/analytics/react.tsx +241 -0
- package/src/analytics/redact.ts +146 -0
- package/src/analytics/server-index.ts +17 -0
- package/src/analytics/server.ts +277 -0
- package/src/auth/index.ts +30 -0
- package/src/auth/second-factor-index.ts +16 -0
- package/src/auth/second-factor-next.ts +136 -0
- package/src/auth/second-factor-routes.ts +40 -0
- package/src/auth/second-factor.ts +226 -0
- package/src/auth/step-up-client-index.ts +13 -0
- package/src/auth/step-up-client.ts +23 -0
- package/src/auth/step-up-index.ts +19 -0
- package/src/auth/step-up-routes.ts +99 -0
- package/src/auth/step-up.ts +432 -0
- package/src/auth/two-factor-policy.ts +112 -0
- package/src/changelog/changelog.tsx +367 -0
- package/src/changelog/index.ts +12 -0
- package/src/editor/block-handle.tsx +312 -0
- package/src/editor/blocks.ts +169 -0
- package/src/editor/bubble-toolbar.tsx +208 -0
- package/src/editor/collapsible.ts +159 -0
- package/src/editor/content-index.ts +1 -0
- package/src/editor/content.tsx +343 -0
- package/src/editor/editor.tsx +333 -0
- package/src/editor/emoji-index.ts +1 -0
- package/src/editor/emoji-picker.tsx +114 -0
- package/src/editor/emoji.ts +436 -0
- package/src/editor/index.ts +6 -0
- package/src/editor/sections.ts +83 -0
- package/src/editor/suggestion-popup.tsx +136 -0
- package/src/editor/suggestions.ts +309 -0
- package/src/editor/ui.tsx +171 -0
- package/src/errors/error-shell.tsx +72 -0
- package/src/errors/global-error-shell.tsx +116 -0
- package/src/errors/index.ts +2 -0
- package/src/grid/columns.ts +48 -0
- package/src/grid/compare.ts +35 -0
- package/src/grid/hidden-columns.ts +95 -0
- package/src/grid/index.ts +27 -0
- package/src/grid/use-grid.ts +282 -0
- package/src/grid/views.ts +70 -0
- package/src/guides/guide-article.tsx +92 -0
- package/src/guides/guide-figure-zoom.tsx +533 -0
- package/src/guides/guide-figure.tsx +68 -0
- package/src/guides/guide-toc.tsx +133 -0
- package/src/guides/guides-landing.tsx +57 -0
- package/src/guides/guides-search.tsx +160 -0
- package/src/guides/guides-shell.tsx +60 -0
- package/src/guides/guides-sidebar.tsx +93 -0
- package/src/guides/index.ts +28 -0
- package/src/guides/library.ts +165 -0
- package/src/health/health.ts +115 -0
- package/src/health/index.ts +11 -0
- package/src/internal/cx.ts +4 -0
- package/src/internal/next-link.ts +23 -0
- package/src/jobs/counts.ts +151 -0
- package/src/jobs/cron-auth.ts +60 -0
- package/src/jobs/health.ts +315 -0
- package/src/jobs/idle.ts +86 -0
- package/src/jobs/index.ts +120 -0
- package/src/jobs/job-health-list.tsx +316 -0
- package/src/jobs/next-index.ts +4 -0
- package/src/jobs/next.ts +65 -0
- package/src/jobs/prisma-index.ts +12 -0
- package/src/jobs/prisma.ts +170 -0
- package/src/jobs/prune.ts +79 -0
- package/src/jobs/react-index.ts +35 -0
- package/src/jobs/registry.ts +189 -0
- package/src/jobs/scheduler.ts +437 -0
- package/src/jobs/store.ts +212 -0
- package/src/jobs/windows.ts +157 -0
- package/src/maintenance/core.ts +270 -0
- package/src/maintenance/gate.ts +171 -0
- package/src/maintenance/index.ts +40 -0
- package/src/maintenance/page.ts +76 -0
- package/src/maintenance/proxy.ts +88 -0
- package/src/maintenance/react-index.ts +7 -0
- package/src/maintenance/react.tsx +190 -0
- package/src/maintenance/route.ts +82 -0
- package/src/maintenance/unavailable.ts +61 -0
- package/src/markdown/figure.tsx +132 -0
- package/src/markdown/figures.ts +237 -0
- package/src/markdown/guide.tsx +536 -0
- package/src/markdown/index.ts +53 -0
- package/src/markdown/table-view.tsx +74 -0
- package/src/markdown/table.ts +90 -0
- package/src/password/common.ts +58 -0
- package/src/password/estimate-index.ts +18 -0
- package/src/password/estimate.ts +715 -0
- package/src/password/index.ts +40 -0
- package/src/password/password-input.tsx +116 -0
- package/src/password/password-strength.tsx +157 -0
- package/src/password/reveal.ts +151 -0
- package/src/rate-limit/better-auth.ts +94 -0
- package/src/rate-limit/index.ts +32 -0
- package/src/rate-limit/keys.ts +110 -0
- package/src/rate-limit/limiter.ts +276 -0
- package/src/rate-limit/prisma-index.ts +12 -0
- package/src/rate-limit/prisma.ts +157 -0
- package/src/rate-limit/store.ts +47 -0
- package/src/release/changelog.ts +364 -0
- package/src/release/index.ts +32 -0
- package/src/release/version.ts +64 -0
- package/src/setup-guide/bits.tsx +420 -0
- package/src/setup-guide/card.tsx +358 -0
- package/src/setup-guide/class-names.ts +144 -0
- package/src/setup-guide/context.tsx +239 -0
- package/src/setup-guide/guide.ts +271 -0
- package/src/setup-guide/index.ts +76 -0
- package/src/setup-guide/launcher.tsx +207 -0
- package/src/setup-guide/strip.tsx +127 -0
- package/src/styles/house.css +384 -0
- package/src/trail/index.ts +12 -0
- package/src/trail/rules.ts +84 -0
- package/src/trail/trail.tsx +367 -0
- package/src/ux/errors.ts +32 -0
- package/src/ux/feedback.tsx +41 -0
- package/src/ux/index.ts +44 -0
- package/src/ux/navigation-index.ts +16 -0
- package/src/ux/navigation-progress.tsx +270 -0
- package/src/ux/optimistic.ts +415 -0
- package/src/ux/use-action.ts +155 -0
- package/src/ux/use-optimistic-list.ts +227 -0
- package/src/ux/use-optimistic-value.ts +136 -0
- package/src/web-search/index.ts +13 -0
- package/src/web-search/providers.ts +177 -0
- package/src/web-search/types.ts +98 -0
- package/src/whats-new/body.tsx +190 -0
- package/src/whats-new/index.ts +43 -0
- package/src/whats-new/seen.ts +40 -0
- package/src/whats-new/select.ts +230 -0
- package/src/whats-new/use-whats-new.ts +109 -0
- package/src/wizard/index.ts +61 -0
- package/src/wizard/invalid.ts +152 -0
- package/src/wizard/react-hook-form-index.ts +11 -0
- package/src/wizard/rhf-adapter.ts +67 -0
- package/src/wizard/rules.ts +137 -0
- package/src/wizard/wizard.tsx +442 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@connextar/house/password` — the password field every form uses, and the
|
|
3
|
+
* strength meter for the ones where a password is being chosen.
|
|
4
|
+
*
|
|
5
|
+
* Ten apps had password fields and not one could show what had been typed.
|
|
6
|
+
* One showed a strength meter — a hand-rolled checklist, with an unused copy in
|
|
7
|
+
* a second app — and "Password1!" ticks every box on it. This is one toggle and
|
|
8
|
+
* one honest estimate, so a person meets the same field and the same judgement
|
|
9
|
+
* in every app.
|
|
10
|
+
*
|
|
11
|
+
* React is the only peer it needs. Nothing here imports a form library — the
|
|
12
|
+
* input forwards its ref and every prop, so react-hook-form's `register`, a
|
|
13
|
+
* `Controller` and plain state all fit — and nothing imports a design system:
|
|
14
|
+
* the look is theme-token classes replaced through `classNames`, as in
|
|
15
|
+
* `wizard` and `markdown`. The estimator alone, for a server, is
|
|
16
|
+
* `@connextar/house/password/estimate`.
|
|
17
|
+
*/
|
|
18
|
+
export {
|
|
19
|
+
estimatePasswordStrength,
|
|
20
|
+
MAX_ANALYSED_LENGTH,
|
|
21
|
+
PASSWORD_STRENGTH_MESSAGES,
|
|
22
|
+
type EstimatePasswordStrengthOptions,
|
|
23
|
+
type PasswordScore,
|
|
24
|
+
type PasswordStrengthEstimate,
|
|
25
|
+
type PasswordStrengthMessages,
|
|
26
|
+
type PasswordWeakness,
|
|
27
|
+
} from "./estimate.js";
|
|
28
|
+
export {
|
|
29
|
+
PASSWORD_INPUT_CLASS_NAMES,
|
|
30
|
+
PasswordInput,
|
|
31
|
+
type PasswordInputClassNames,
|
|
32
|
+
type PasswordInputProps,
|
|
33
|
+
} from "./password-input.js";
|
|
34
|
+
export {
|
|
35
|
+
PASSWORD_STRENGTH_CLASS_NAMES,
|
|
36
|
+
PasswordStrength,
|
|
37
|
+
type PasswordStrengthClassNames,
|
|
38
|
+
type PasswordStrengthProps,
|
|
39
|
+
} from "./password-strength.js";
|
|
40
|
+
export { usePasswordReveal, type PasswordReveal, type PasswordRevealOptions } from "./reveal.js";
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Eye, EyeOff } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
import { cx } from "../internal/cx.js";
|
|
7
|
+
import { mergeRefs, usePasswordReveal } from "./reveal.js";
|
|
8
|
+
|
|
9
|
+
/** Every element the input draws. Each value replaces the default for that part. */
|
|
10
|
+
export interface PasswordInputClassNames {
|
|
11
|
+
wrapper: string;
|
|
12
|
+
input: string;
|
|
13
|
+
toggle: string;
|
|
14
|
+
icon: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The house look: the shadcn input on the shared theme tokens, with room on the
|
|
19
|
+
* right for the toggle. An app whose own `Input` differs passes its classes as
|
|
20
|
+
* `classNames.input`; one without theme tokens replaces the parts it needs.
|
|
21
|
+
*
|
|
22
|
+
* `[&::-ms-reveal]:hidden` removes the eye Edge draws in every password field,
|
|
23
|
+
* which would otherwise sit beside ours.
|
|
24
|
+
*/
|
|
25
|
+
export const PASSWORD_INPUT_CLASS_NAMES: PasswordInputClassNames = {
|
|
26
|
+
wrapper: "relative w-full",
|
|
27
|
+
input:
|
|
28
|
+
"flex h-9 w-full min-w-0 rounded-md border border-input bg-transparent py-1 pr-10 pl-3 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive md:text-sm [&::-ms-reveal]:hidden",
|
|
29
|
+
toggle:
|
|
30
|
+
"absolute inset-y-0 right-0 flex w-9 items-center justify-center rounded-r-md text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",
|
|
31
|
+
icon: "size-4",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface PasswordInputProps extends Omit<React.ComponentPropsWithoutRef<"input">, "type"> {
|
|
35
|
+
/**
|
|
36
|
+
* What the field is for, which decides `autoComplete`: `"current"` for
|
|
37
|
+
* signing in and for confirming who you are (two-factor, deleting an
|
|
38
|
+
* account); `"new"` wherever a password is being chosen, confirm fields
|
|
39
|
+
* included. An explicit `autoComplete` wins.
|
|
40
|
+
*/
|
|
41
|
+
purpose?: "current" | "new";
|
|
42
|
+
/** Controlled reveal — one toggle shared by a new and a confirm field, say. */
|
|
43
|
+
revealed?: boolean;
|
|
44
|
+
defaultRevealed?: boolean;
|
|
45
|
+
onRevealedChange?: (revealed: boolean) => void;
|
|
46
|
+
/** The toggle's accessible name. Constant: the pressed state says whether it is on. */
|
|
47
|
+
toggleLabel?: string;
|
|
48
|
+
/** Appended to the input's classes, as with the app's own `Input`. */
|
|
49
|
+
className?: string;
|
|
50
|
+
classNames?: Partial<PasswordInputClassNames>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A password field with a show/hide toggle — the one every form in every app
|
|
55
|
+
* uses, whatever it is asking for.
|
|
56
|
+
*
|
|
57
|
+
* A drop-in for `<Input type="password">`: every input prop and the ref pass
|
|
58
|
+
* straight through, so `{...register("password")}`, a `Controller`'s `field`
|
|
59
|
+
* and plain `value`/`onChange` state all work unchanged.
|
|
60
|
+
*
|
|
61
|
+
* The toggle is a real `<button type="button">` inside the field, so it never
|
|
62
|
+
* submits the form and is reached with Tab. Its accessible name stays
|
|
63
|
+
* "Show password" and `aria-pressed` carries the state — a toggle whose label
|
|
64
|
+
* changed as well would be read as "Hide password, pressed", which says the
|
|
65
|
+
* opposite of what is on screen. The eye becomes a struck-through eye for
|
|
66
|
+
* everyone else.
|
|
67
|
+
*
|
|
68
|
+
* See `usePasswordReveal` for what else the toggle takes care of: focus and
|
|
69
|
+
* caret kept, hidden again on submit, no spellcheck.
|
|
70
|
+
*/
|
|
71
|
+
export const PasswordInput = React.forwardRef<HTMLInputElement, PasswordInputProps>(function PasswordInput(
|
|
72
|
+
{
|
|
73
|
+
purpose = "current",
|
|
74
|
+
revealed: revealedProp,
|
|
75
|
+
defaultRevealed,
|
|
76
|
+
onRevealedChange,
|
|
77
|
+
toggleLabel = "Show password",
|
|
78
|
+
className,
|
|
79
|
+
classNames,
|
|
80
|
+
id: idProp,
|
|
81
|
+
autoComplete,
|
|
82
|
+
disabled,
|
|
83
|
+
...props
|
|
84
|
+
},
|
|
85
|
+
ref,
|
|
86
|
+
) {
|
|
87
|
+
const c: PasswordInputClassNames = { ...PASSWORD_INPUT_CLASS_NAMES, ...classNames };
|
|
88
|
+
const generatedId = React.useId();
|
|
89
|
+
const id = idProp ?? generatedId;
|
|
90
|
+
const reveal = usePasswordReveal({
|
|
91
|
+
revealed: revealedProp,
|
|
92
|
+
defaultRevealed,
|
|
93
|
+
onRevealedChange,
|
|
94
|
+
inputId: id,
|
|
95
|
+
disabled,
|
|
96
|
+
});
|
|
97
|
+
const inputRef = React.useMemo(() => mergeRefs(ref, reveal.inputRef), [ref, reveal.inputRef]);
|
|
98
|
+
const Icon = reveal.revealed ? EyeOff : Eye;
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div className={c.wrapper}>
|
|
102
|
+
<input
|
|
103
|
+
{...props}
|
|
104
|
+
{...reveal.inputProps}
|
|
105
|
+
ref={inputRef}
|
|
106
|
+
id={id}
|
|
107
|
+
disabled={disabled}
|
|
108
|
+
autoComplete={autoComplete ?? (purpose === "new" ? "new-password" : "current-password")}
|
|
109
|
+
className={cx(c.input, className)}
|
|
110
|
+
/>
|
|
111
|
+
<button {...reveal.toggleProps} aria-label={toggleLabel} className={c.toggle}>
|
|
112
|
+
<Icon aria-hidden="true" className={c.icon} />
|
|
113
|
+
</button>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { cx } from "../internal/cx.js";
|
|
6
|
+
import {
|
|
7
|
+
estimatePasswordStrength,
|
|
8
|
+
type PasswordScore,
|
|
9
|
+
type PasswordStrengthEstimate,
|
|
10
|
+
type PasswordStrengthMessages,
|
|
11
|
+
} from "./estimate.js";
|
|
12
|
+
|
|
13
|
+
/** Every element the meter draws. Each value replaces the default for that part. */
|
|
14
|
+
export interface PasswordStrengthClassNames {
|
|
15
|
+
root: string;
|
|
16
|
+
bar: string;
|
|
17
|
+
/** Every segment's shape. No colour here: a segment is either `empty` or a score. */
|
|
18
|
+
segment: string;
|
|
19
|
+
/** A segment the score does not reach. */
|
|
20
|
+
empty: string;
|
|
21
|
+
/** A filled segment, by score. */
|
|
22
|
+
score0: string;
|
|
23
|
+
score1: string;
|
|
24
|
+
score2: string;
|
|
25
|
+
score3: string;
|
|
26
|
+
score4: string;
|
|
27
|
+
text: string;
|
|
28
|
+
label: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The house look on the shared theme tokens, with amber and green for the two
|
|
33
|
+
* scores no theme token names. The root also carries `data-score`, for an app
|
|
34
|
+
* that styles the meter from its own stylesheet instead.
|
|
35
|
+
*/
|
|
36
|
+
export const PASSWORD_STRENGTH_CLASS_NAMES: PasswordStrengthClassNames = {
|
|
37
|
+
root: "mt-2 space-y-1.5",
|
|
38
|
+
bar: "grid grid-cols-4 gap-1",
|
|
39
|
+
segment: "h-1 rounded-full transition-colors",
|
|
40
|
+
empty: "bg-muted",
|
|
41
|
+
score0: "bg-destructive",
|
|
42
|
+
score1: "bg-destructive",
|
|
43
|
+
score2: "bg-amber-500",
|
|
44
|
+
score3: "bg-emerald-500",
|
|
45
|
+
score4: "bg-emerald-600",
|
|
46
|
+
text: "text-xs text-muted-foreground",
|
|
47
|
+
label: "font-medium text-foreground",
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** Visually hidden, from inline style so it cannot depend on the app's CSS. */
|
|
51
|
+
const VISUALLY_HIDDEN: React.CSSProperties = {
|
|
52
|
+
position: "absolute",
|
|
53
|
+
width: 1,
|
|
54
|
+
height: 1,
|
|
55
|
+
padding: 0,
|
|
56
|
+
margin: -1,
|
|
57
|
+
overflow: "hidden",
|
|
58
|
+
clip: "rect(0, 0, 0, 0)",
|
|
59
|
+
whiteSpace: "nowrap",
|
|
60
|
+
border: 0,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export interface PasswordStrengthProps {
|
|
64
|
+
/** The password being typed — the field's current value. */
|
|
65
|
+
password: string;
|
|
66
|
+
/** The person's email, name, username, organisation, the app's name. */
|
|
67
|
+
userInputs?: ReadonlyArray<string | null | undefined>;
|
|
68
|
+
/** The app's own minimum, so the sentence can say it while the password is shorter. */
|
|
69
|
+
minLength?: number;
|
|
70
|
+
messages?: Partial<PasswordStrengthMessages>;
|
|
71
|
+
/**
|
|
72
|
+
* Put on the sentence, for the field's `aria-describedby`, so the strength is
|
|
73
|
+
* read with the field when someone returns to it.
|
|
74
|
+
*/
|
|
75
|
+
id?: string;
|
|
76
|
+
/** How long typing must pause before a screen reader hears the new strength. */
|
|
77
|
+
announceDelay?: number;
|
|
78
|
+
className?: string;
|
|
79
|
+
classNames?: Partial<PasswordStrengthClassNames>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* How guessable a new password is: four bars and one plain sentence.
|
|
84
|
+
*
|
|
85
|
+
* **Only where a password is being chosen** — sign-up, reset, set, change, and a
|
|
86
|
+
* person setting one for someone else. Never on sign-in or a "confirm it's you"
|
|
87
|
+
* field: rating a password someone already has tells them nothing they can act
|
|
88
|
+
* on, and tells anyone watching the screen something about it.
|
|
89
|
+
*
|
|
90
|
+
* **It refuses nothing.** The meter is advice; whether a password is allowed is
|
|
91
|
+
* the app's rule — its minimum length, and a server check with
|
|
92
|
+
* `estimatePasswordStrength` if it chooses to refuse the weakest. So there is no
|
|
93
|
+
* `valid` here to wire a submit button to.
|
|
94
|
+
*
|
|
95
|
+
* Nothing shows for an empty field. Screen readers hear the strength once typing
|
|
96
|
+
* pauses and only when it has changed, through a polite live region — never a
|
|
97
|
+
* word per keystroke.
|
|
98
|
+
*/
|
|
99
|
+
export function PasswordStrength({
|
|
100
|
+
password,
|
|
101
|
+
userInputs,
|
|
102
|
+
minLength,
|
|
103
|
+
messages,
|
|
104
|
+
id,
|
|
105
|
+
announceDelay = 1000,
|
|
106
|
+
className,
|
|
107
|
+
classNames,
|
|
108
|
+
}: PasswordStrengthProps) {
|
|
109
|
+
const c: PasswordStrengthClassNames = { ...PASSWORD_STRENGTH_CLASS_NAMES, ...classNames };
|
|
110
|
+
const inputsKey = (userInputs ?? []).join("\u0000");
|
|
111
|
+
const estimate: PasswordStrengthEstimate = React.useMemo(
|
|
112
|
+
() =>
|
|
113
|
+
estimatePasswordStrength(password, {
|
|
114
|
+
userInputs: inputsKey ? inputsKey.split("\u0000") : [],
|
|
115
|
+
minLength,
|
|
116
|
+
messages,
|
|
117
|
+
}),
|
|
118
|
+
[password, inputsKey, minLength, messages],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const message = password ? `${estimate.label}. ${estimate.sentence}` : "";
|
|
122
|
+
const [announced, setAnnounced] = React.useState("");
|
|
123
|
+
React.useEffect(() => {
|
|
124
|
+
if (!message) {
|
|
125
|
+
setAnnounced("");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const timer = setTimeout(() => setAnnounced(message), announceDelay);
|
|
129
|
+
return () => clearTimeout(timer);
|
|
130
|
+
}, [message, announceDelay]);
|
|
131
|
+
|
|
132
|
+
const filled = Math.max(estimate.score, 1);
|
|
133
|
+
const tone = c[`score${estimate.score}` as `score${PasswordScore}`];
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<div className={cx(c.root, className)} data-score={password ? estimate.score : undefined} hidden={!password}>
|
|
137
|
+
{password ? (
|
|
138
|
+
<>
|
|
139
|
+
<div className={c.bar} aria-hidden="true">
|
|
140
|
+
{[0, 1, 2, 3].map((segment) => (
|
|
141
|
+
// One background class per segment. Two would be settled by the
|
|
142
|
+
// order Tailwind emits them, which is alphabetical: `bg-muted`
|
|
143
|
+
// comes after every score colour and would win.
|
|
144
|
+
<span key={segment} className={cx(c.segment, segment < filled ? tone : c.empty)} />
|
|
145
|
+
))}
|
|
146
|
+
</div>
|
|
147
|
+
<p id={id} className={c.text}>
|
|
148
|
+
<span className={c.label}>{estimate.label}.</span> {estimate.sentence}
|
|
149
|
+
</p>
|
|
150
|
+
</>
|
|
151
|
+
) : null}
|
|
152
|
+
<span role="status" aria-live="polite" style={VISUALLY_HIDDEN}>
|
|
153
|
+
{announced}
|
|
154
|
+
</span>
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
export interface PasswordRevealOptions {
|
|
6
|
+
/** Controlled: whether the password is shown. Pair with `onRevealedChange`. */
|
|
7
|
+
revealed?: boolean;
|
|
8
|
+
/** Uncontrolled starting state. Hidden unless said otherwise. */
|
|
9
|
+
defaultRevealed?: boolean;
|
|
10
|
+
onRevealedChange?: (revealed: boolean) => void;
|
|
11
|
+
/** The input's id, for the toggle's `aria-controls`. */
|
|
12
|
+
inputId: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PasswordReveal {
|
|
17
|
+
revealed: boolean;
|
|
18
|
+
setRevealed: (revealed: boolean) => void;
|
|
19
|
+
toggle: () => void;
|
|
20
|
+
/** Attach to the password input, merged with any ref of the host's own. */
|
|
21
|
+
inputRef: React.RefCallback<HTMLInputElement>;
|
|
22
|
+
/** Spread onto the input, after the host's own props. */
|
|
23
|
+
inputProps: {
|
|
24
|
+
type: "password" | "text";
|
|
25
|
+
spellCheck: false;
|
|
26
|
+
autoCapitalize: "off";
|
|
27
|
+
autoCorrect: "off";
|
|
28
|
+
"data-revealed": boolean;
|
|
29
|
+
};
|
|
30
|
+
/** Spread onto the toggle button. It supplies no label: give it one. */
|
|
31
|
+
toggleProps: {
|
|
32
|
+
type: "button";
|
|
33
|
+
"aria-pressed": boolean;
|
|
34
|
+
"aria-controls": string;
|
|
35
|
+
disabled: boolean | undefined;
|
|
36
|
+
onClick: () => void;
|
|
37
|
+
onMouseDown: (event: React.MouseEvent) => void;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Show and hide a password, with everything a bare `type` switch gets wrong.
|
|
43
|
+
* `PasswordInput` is built on this; an app whose field is not a plain input —
|
|
44
|
+
* an MUI `TextField`, a floating-label row — spreads the two prop sets itself
|
|
45
|
+
* and keeps the same behaviour.
|
|
46
|
+
*
|
|
47
|
+
* - **The field keeps focus and the caret stays put.** Clicking the toggle
|
|
48
|
+
* would move focus to it, and switching `type` resets the selection in some
|
|
49
|
+
* browsers; so a pointer press never takes focus, and the caret is put back
|
|
50
|
+
* where it was. A keyboard user who tabbed to the toggle stays on it.
|
|
51
|
+
* - **It is hidden again the moment its form submits**, synchronously, before
|
|
52
|
+
* the browser reads the form. A password submitted from a text field is a
|
|
53
|
+
* value the browser may keep in its ordinary autofill history and offer in
|
|
54
|
+
* any other text box — the odd autocomplete a reveal must never cause.
|
|
55
|
+
* - **Spellcheck and autocorrect are off, always.** A revealed field is a text
|
|
56
|
+
* field, and enhanced spellcheck sends the text of text fields to a server.
|
|
57
|
+
*/
|
|
58
|
+
export function usePasswordReveal({
|
|
59
|
+
revealed: controlled,
|
|
60
|
+
defaultRevealed = false,
|
|
61
|
+
onRevealedChange,
|
|
62
|
+
inputId,
|
|
63
|
+
disabled,
|
|
64
|
+
}: PasswordRevealOptions): PasswordReveal {
|
|
65
|
+
const [uncontrolled, setUncontrolled] = React.useState(defaultRevealed);
|
|
66
|
+
const revealed = controlled ?? uncontrolled;
|
|
67
|
+
const input = React.useRef<HTMLInputElement | null>(null);
|
|
68
|
+
const selection = React.useRef<[number | null, number | null] | null>(null);
|
|
69
|
+
const latest = React.useRef({ controlled, onRevealedChange });
|
|
70
|
+
latest.current = { controlled, onRevealedChange };
|
|
71
|
+
|
|
72
|
+
const setRevealed = React.useCallback((next: boolean) => {
|
|
73
|
+
if (latest.current.controlled === undefined) setUncontrolled(next);
|
|
74
|
+
latest.current.onRevealedChange?.(next);
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
const toggle = React.useCallback(() => {
|
|
78
|
+
const node = input.current;
|
|
79
|
+
selection.current =
|
|
80
|
+
node && node.ownerDocument.activeElement === node ? [node.selectionStart, node.selectionEnd] : null;
|
|
81
|
+
setRevealed(!revealed);
|
|
82
|
+
}, [revealed, setRevealed]);
|
|
83
|
+
|
|
84
|
+
// Put the caret back after the type switch, while the field still has focus.
|
|
85
|
+
React.useLayoutEffect(() => {
|
|
86
|
+
const node = input.current;
|
|
87
|
+
const kept = selection.current;
|
|
88
|
+
selection.current = null;
|
|
89
|
+
if (!node || !kept || node.ownerDocument.activeElement !== node) return;
|
|
90
|
+
const [start, end] = kept;
|
|
91
|
+
if (start !== null && end !== null) node.setSelectionRange(start, end);
|
|
92
|
+
}, [revealed]);
|
|
93
|
+
|
|
94
|
+
const hideOnSubmit = React.useRef<(() => void) | null>(null);
|
|
95
|
+
hideOnSubmit.current = () => {
|
|
96
|
+
// Before React re-renders: the browser reads the form as soon as this returns.
|
|
97
|
+
if (input.current) input.current.type = "password";
|
|
98
|
+
if (revealed) setRevealed(false);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const [form, setForm] = React.useState<HTMLFormElement | null>(null);
|
|
102
|
+
const inputRef = React.useCallback((node: HTMLInputElement | null) => {
|
|
103
|
+
input.current = node;
|
|
104
|
+
// Only on attach: a ref detached and re-attached between renders must not churn state.
|
|
105
|
+
if (node) setForm(node.form);
|
|
106
|
+
}, []);
|
|
107
|
+
|
|
108
|
+
React.useEffect(() => {
|
|
109
|
+
if (!form) return;
|
|
110
|
+
const hide = () => hideOnSubmit.current?.();
|
|
111
|
+
form.addEventListener("submit", hide);
|
|
112
|
+
form.addEventListener("reset", hide);
|
|
113
|
+
return () => {
|
|
114
|
+
form.removeEventListener("submit", hide);
|
|
115
|
+
form.removeEventListener("reset", hide);
|
|
116
|
+
};
|
|
117
|
+
}, [form]);
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
revealed,
|
|
121
|
+
setRevealed,
|
|
122
|
+
toggle,
|
|
123
|
+
inputRef,
|
|
124
|
+
inputProps: {
|
|
125
|
+
type: revealed ? "text" : "password",
|
|
126
|
+
spellCheck: false,
|
|
127
|
+
autoCapitalize: "off",
|
|
128
|
+
autoCorrect: "off",
|
|
129
|
+
"data-revealed": revealed,
|
|
130
|
+
},
|
|
131
|
+
toggleProps: {
|
|
132
|
+
type: "button",
|
|
133
|
+
"aria-pressed": revealed,
|
|
134
|
+
"aria-controls": inputId,
|
|
135
|
+
disabled,
|
|
136
|
+
onClick: toggle,
|
|
137
|
+
// A pointer press must not take focus from the field.
|
|
138
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** One ref from several — the host's (react-hook-form's `register`, say) and ours. */
|
|
144
|
+
export function mergeRefs<T>(...refs: Array<React.Ref<T> | undefined>): React.RefCallback<T> {
|
|
145
|
+
return (node) => {
|
|
146
|
+
for (const ref of refs) {
|
|
147
|
+
if (typeof ref === "function") ref(node);
|
|
148
|
+
else if (ref) (ref as React.RefObject<T | null>).current = node;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { RateLimiter } from "./limiter.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Better Auth's rate limits, counted by the app's limiter in the app's table.
|
|
5
|
+
*
|
|
6
|
+
* The critical finding behind this: AltEd's 2026-09-01 outage. Better Auth was set to `storage: "database"`, so it
|
|
7
|
+
* wrote its own `{ key, count, lastRequest }` rows into the model named `rateLimit` — the app's `RateLimit`, with a
|
|
8
|
+
* different shape — and every sign-in failed on "Argument windowAt is missing". Two limiters were fighting over one
|
|
9
|
+
* table. The fix every app then made by hand: Better Auth's counts go through the app's own limiter, as one more
|
|
10
|
+
* caller, under keys that start `auth:`. This is that adapter, and `rateLimitConfigProblems` is the test each app wrote
|
|
11
|
+
* to keep it so.
|
|
12
|
+
*
|
|
13
|
+
* Better Auth calls `consume(key, { window, max })` — `window` in seconds, the key `<ip>|<path>` — on 1.7, and on 1.6.33
|
|
14
|
+
* whenever the storage has it. `get` and `set` are there only because 1.6's type still lists them: a Better Auth that
|
|
15
|
+
* calls them predates `consume`, counts without atomicity, and is refused loudly rather than counted wrongly.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const BETTER_AUTH_KEY_PREFIX = "auth:";
|
|
19
|
+
|
|
20
|
+
const HOUSE_STORAGE = Symbol.for("@connextar/house/rate-limit:better-auth-storage");
|
|
21
|
+
|
|
22
|
+
export interface BetterAuthRateLimitStorage {
|
|
23
|
+
consume(key: string, rule: { window: number; max: number }): Promise<{ allowed: boolean; retryAfter: number | null }>;
|
|
24
|
+
get(key: string): Promise<null>;
|
|
25
|
+
set(key: string, value: unknown, update?: boolean): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface BetterAuthStorageOptions {
|
|
29
|
+
/** Default `auth:`, which every app's rows already use. */
|
|
30
|
+
prefix?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Refuse a sign-in when the count cannot be kept. Default true: a password guess the limiter cannot count is
|
|
33
|
+
* one more than it allowed.
|
|
34
|
+
*/
|
|
35
|
+
failClosed?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** `rateLimit: { enabled: true, customStorage: betterAuthRateLimitStorage(limiter) }` in the Better Auth options. */
|
|
39
|
+
export function betterAuthRateLimitStorage(
|
|
40
|
+
limiter: RateLimiter,
|
|
41
|
+
options: BetterAuthStorageOptions = {},
|
|
42
|
+
): BetterAuthRateLimitStorage {
|
|
43
|
+
const prefix = options.prefix ?? BETTER_AUTH_KEY_PREFIX;
|
|
44
|
+
const failClosed = options.failClosed ?? true;
|
|
45
|
+
const legacy = () =>
|
|
46
|
+
Promise.reject(
|
|
47
|
+
new Error(
|
|
48
|
+
"[rate-limit] Better Auth asked for get/set: it predates consume() and cannot count atomically. " +
|
|
49
|
+
"Upgrade Better Auth to 1.6.33 or later.",
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
const storage: BetterAuthRateLimitStorage = {
|
|
53
|
+
async consume(key, rule) {
|
|
54
|
+
// Better Auth counts its windows in seconds; the limiter in milliseconds.
|
|
55
|
+
const result = await limiter.consume(`${prefix}${key}`, {
|
|
56
|
+
limit: Math.max(1, Math.floor(rule.max)),
|
|
57
|
+
windowMs: Math.max(1, rule.window) * 1000,
|
|
58
|
+
failClosed,
|
|
59
|
+
});
|
|
60
|
+
return { allowed: result.allowed, retryAfter: result.allowed ? null : result.retryAfter };
|
|
61
|
+
},
|
|
62
|
+
get: legacy,
|
|
63
|
+
set: legacy,
|
|
64
|
+
};
|
|
65
|
+
Object.defineProperty(storage, HOUSE_STORAGE, { value: true });
|
|
66
|
+
return storage;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* What is wrong with a Better Auth `rateLimit` configuration, as sentences — empty when it counts through the house's
|
|
71
|
+
* adapter. For each app's config test: `expect(rateLimitConfigProblems(authOptions)).toEqual([])`.
|
|
72
|
+
*/
|
|
73
|
+
export function rateLimitConfigProblems(options: {
|
|
74
|
+
rateLimit?: { enabled?: boolean; storage?: string; customStorage?: unknown } | null;
|
|
75
|
+
}): string[] {
|
|
76
|
+
const rateLimit = options?.rateLimit;
|
|
77
|
+
const problems: string[] = [];
|
|
78
|
+
if (!rateLimit) return ["Better Auth has no rateLimit configuration, so it counts in memory, per instance."];
|
|
79
|
+
if (rateLimit.storage === "database") {
|
|
80
|
+
problems.push(
|
|
81
|
+
'rateLimit.storage is "database": Better Auth would write its own rows into the app\'s rate_limit table, ' +
|
|
82
|
+
"the outage of 2026-09-01. Count through the app's limiter instead.",
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const custom = rateLimit.customStorage as Record<PropertyKey, unknown> | undefined;
|
|
86
|
+
if (!custom) {
|
|
87
|
+
problems.push("rateLimit.customStorage is missing: pass betterAuthRateLimitStorage(limiter).");
|
|
88
|
+
} else if (typeof custom.consume !== "function") {
|
|
89
|
+
problems.push("rateLimit.customStorage has no consume(): Better Auth would count with get/set, non-atomically.");
|
|
90
|
+
} else if (custom[HOUSE_STORAGE] !== true) {
|
|
91
|
+
problems.push("rateLimit.customStorage is not betterAuthRateLimitStorage(limiter), the app's own limiter.");
|
|
92
|
+
}
|
|
93
|
+
return problems;
|
|
94
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@connextar/house/rate-limit` — a fixed-window limiter over the app's own table: consume and usage, per-rule
|
|
3
|
+
* fail-closed, ceilings over everyone, long keys hashed, private keys made unreadable, IPv6 counted per /64, the
|
|
4
|
+
* standard headers, pruning, and Better Auth's limits counted by the same limiter.
|
|
5
|
+
*
|
|
6
|
+
* Server code. It owns no schema — the app's table sits behind `RateLimitStore`, and `/rate-limit/prisma` is the
|
|
7
|
+
* adapter for the `RateLimit` model every app already has — and it imports nothing but `node:crypto`.
|
|
8
|
+
*/
|
|
9
|
+
export {
|
|
10
|
+
BETTER_AUTH_KEY_PREFIX,
|
|
11
|
+
betterAuthRateLimitStorage,
|
|
12
|
+
rateLimitConfigProblems,
|
|
13
|
+
type BetterAuthRateLimitStorage,
|
|
14
|
+
type BetterAuthStorageOptions,
|
|
15
|
+
} from "./better-auth.js";
|
|
16
|
+
export { DEFAULT_MAX_KEY_LENGTH, callerIp, ipBucket, privateKey, storedKey, type CallerIpOptions } from "./keys.js";
|
|
17
|
+
export {
|
|
18
|
+
DEFAULT_RATE_LIMIT_PRUNE_BATCH,
|
|
19
|
+
DEFAULT_RATE_LIMIT_RETENTION_MS,
|
|
20
|
+
createRateLimiter,
|
|
21
|
+
defineRateLimits,
|
|
22
|
+
rateLimitHeaders,
|
|
23
|
+
type AutoPruneOptions,
|
|
24
|
+
type PruneOptions,
|
|
25
|
+
type RateLimitResult,
|
|
26
|
+
type RateLimitRule,
|
|
27
|
+
type RateLimitUsage,
|
|
28
|
+
type RateLimiter,
|
|
29
|
+
type RateLimiterLogger,
|
|
30
|
+
type RateLimiterOptions,
|
|
31
|
+
} from "./limiter.js";
|
|
32
|
+
export { memoryRateLimitStore, type RateLimitStore } from "./store.js";
|