@aiveth/react 0.12.0 → 0.14.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/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## 0.12.0 — unreleased
3
+ ## 0.14.0 — unreleased
4
+
5
+ - The steps after the password, on your page (Clerk's session tasks): where your organization requires two-step, `needs_two_step_setup` shows the QR code and its key (`twoStepSetup()` for it again, `verifyTwoStepSetup(code)`), then `needs_recovery_codes_saved` shows the recovery codes once with their file (`recoveryCodesSaved()`). Where your app requires a workspace and the person is in several, `needs_workspace` lists them (`chooseWorkspace(id)`). `<SignIn />` shows all three; before, they went to Aiveth's page.
6
+ - `<SignIn />` no longer stretches to the height of a flex parent.
7
+
8
+ ## 0.13.0 — 2026-11-30
9
+
10
+ - `<SignIn />` and `<SignUp />`: a ready-made sign-in box for your own page. One line, and it runs every step of `signInHere` — address, password, email code, Google / Microsoft / GitHub / SSO, second factor, a new password, sign-up details, your organization's terms — in your organization's look and the person's language (the sign-in card's own translations; `locale` to choose). `invitation` opens an invitation link's token. A step only Aiveth's page can do goes there and comes back. "Secured by Aiveth" shows on Free and Pro only. `signInHere.settings()` returns what the box reads.
11
+ - An email code sent during a sign-in now answers `needs_email_code`.
12
+
13
+ ## 0.12.0 — 2026-11-30
4
14
 
5
15
  - `signInHere` (on the client and from `useAiveth()`): sign-in on your own page through Aiveth's sign-in API — `start({ email })`, `signUp({ email })`, `invitation(token)` answer a `flow` and its first `Step`; then `flow.password()`, `sendEmailCode()` / `verifyEmailCode()`, `secondFactor()`, `acceptTerms()`, `sendResetCode()` / `verifyResetCode()` / `setNewPassword()`, `verifySignUpCode()` / `resendSignUpCode()`, `details()`, `continueOnAiveth()`. The code is swapped here at the end (`signed_in`). A refused step throws `StepRefused` with its HTTP status.
6
16
 
package/README.md CHANGED
@@ -63,6 +63,28 @@ Also `signInHere.signUp({ email })` (`verifySignUpCode`, `details`), `signInHere
63
63
  (`details`), and on a sign-in `sendResetCode` / `verifyResetCode` / `setNewPassword` and
64
64
  `acceptTerms`. A refused step throws `StepRefused` with its HTTP `status` (401, 422, 429, 404).
65
65
 
66
+ After the password, two more steps can come: `needs_two_step_setup` where your organization
67
+ requires two-step (`step.qr`, `step.secret`; `verifyTwoStepSetup(code)`, then
68
+ `needs_recovery_codes_saved` with `step.recoveryCodes` shown once and `recoveryCodesSaved()`), and
69
+ `needs_workspace` where your app requires a workspace (`step.workspaces`; `chooseWorkspace(id)`).
70
+
71
+ ## A ready-made sign-in box
72
+
73
+ `<SignIn />` runs every step above in your organization's look (Aiveth → Branding) and the person's
74
+ language — one line on your page:
75
+
76
+ ```tsx
77
+ import { SignIn, SignUp } from '@aiveth/react';
78
+
79
+ <SignIn returnTo="/dashboard" onSignedIn={(to) => navigate(to ?? '/')} />
80
+ <SignUp /> {/* opens on "Create an account" */}
81
+ ```
82
+
83
+ It reads `?invitation=` from the address (or take `invitation`), and `locale` picks the language
84
+ (the browser's otherwise). A step only Aiveth's page can do goes there and comes back. "Secured by
85
+ Aiveth" shows on the Free and Pro plans only. The tokens stay in memory, so a reload signs the
86
+ person out — use `<SignInButton>` or Next.js when sessions must survive a reload.
87
+
66
88
  ## Sign in in your organization's own look
67
89
 
68
90
  `<AivethButton>` draws "Sign in" with what you set in Aiveth → Branding — colours (light and
package/dist/box.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { type CSSProperties } from 'react';
2
+ import { type HereFlow, type Step } from './here.js';
3
+ /** What Aiveth tells the box: the organization's name and look, the words, the badge. */
4
+ export interface BoxSettings {
5
+ name: string;
6
+ lang: string;
7
+ dir: 'ltr' | 'rtl';
8
+ words: Record<string, string>;
9
+ look: {
10
+ custom: boolean;
11
+ radius?: number;
12
+ button_style?: 'filled' | 'outlined';
13
+ appearance?: 'system' | 'light' | 'dark';
14
+ font?: {
15
+ family: string;
16
+ url: string | null;
17
+ };
18
+ colours?: Record<'light' | 'dark', {
19
+ page: string;
20
+ button: string;
21
+ button_text: string;
22
+ link: string;
23
+ }>;
24
+ more_colours?: Record<'light' | 'dark', {
25
+ card: string;
26
+ input: string;
27
+ border: string;
28
+ button_hover: string;
29
+ }>;
30
+ logo?: string | null;
31
+ logo_dark?: string | null;
32
+ };
33
+ secured_by: boolean;
34
+ sign_up: boolean;
35
+ }
36
+ /** How a package plugs in: where the settings are, how a flow starts, how a provider opens. */
37
+ export interface BoxSetup {
38
+ settings: (lang?: string) => Promise<BoxSettings>;
39
+ start: (email: string) => Promise<{
40
+ flow: HereFlow;
41
+ step: Step;
42
+ }>;
43
+ signUp: (email: string) => Promise<{
44
+ flow: HereFlow;
45
+ step: Step;
46
+ }>;
47
+ invitation: (token: string) => Promise<{
48
+ flow: HereFlow;
49
+ step: Step;
50
+ }>;
51
+ /** Google, Microsoft, GitHub or single sign-on: a redirect to that way in. */
52
+ withProvider: (connection: string, email: string) => void;
53
+ onSignedIn: (step: Step) => void;
54
+ }
55
+ export interface BoxProps {
56
+ /** `ui_locales`-like, e.g. `'hi'` or `'ta en'`; the browser's language when left out. */
57
+ locale?: string;
58
+ /** An invitation's token (your sign-in page's `?invitation=`); read from the address when left out. */
59
+ invitation?: string;
60
+ className?: string;
61
+ style?: CSSProperties;
62
+ }
63
+ export declare function SignInBox({ setup, mode, locale, invitation, className, style }: BoxProps & {
64
+ setup: BoxSetup;
65
+ mode: 'sign-in' | 'sign-up';
66
+ }): import("react/jsx-runtime").JSX.Element | null;
package/dist/box.js ADDED
@@ -0,0 +1,187 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
+ /* The ready-made sign-in on your own page (`<SignIn />`, `<SignUp />`; Clerk's components): every
4
+ * step of Aiveth's sign-in API (`here.ts`), in your organization's look, in the person's language
5
+ * — the sign-in card's own words, from Aiveth (`/v1/sign-in/{client_id}/box`) — with "Secured by
6
+ * Aiveth" below on Free and Pro. The same file is in `@aiveth/react` and `@aiveth/nextjs`. */
7
+ import { useEffect, useRef, useState } from 'react';
8
+ import { StepRefused } from './here.js';
9
+ const AIVETH_LOOK = {
10
+ light: { page: '#ffffff', button: '#1d4ed8', button_text: '#ffffff', link: '#1d4ed8', card: '#ffffff', input: '#ffffff', border: '#d4d4d8', text: '#18181b', muted: '#52525b' },
11
+ dark: { page: '#09090b', button: '#3b82f6', button_text: '#ffffff', link: '#93c5fd', card: '#18181b', input: '#09090b', border: '#3f3f46', text: '#fafafa', muted: '#a1a1aa' },
12
+ };
13
+ const PROVIDERS = { google: 'Google', microsoft: 'Microsoft', github: 'GitHub' };
14
+ function dark(look) {
15
+ if (look.appearance === 'dark')
16
+ return true;
17
+ if (look.appearance === 'light')
18
+ return false;
19
+ return typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)').matches === true;
20
+ }
21
+ function palette(look) {
22
+ const mode = dark(look) ? 'dark' : 'light';
23
+ return { ...AIVETH_LOOK[mode], ...(look.colours?.[mode] ?? {}), ...(look.more_colours?.[mode] ?? {}) };
24
+ }
25
+ /** A sentence in the person's language, its `{values}` filled in. */
26
+ function say(words, text, values = {}) {
27
+ return (words[text] ?? text).replace(/\{(\w+)\}/g, (_m, k) => values[k] ?? `{${k}}`);
28
+ }
29
+ /** A sentence with a link (or links) in its middle: the translation decides where it sits. */
30
+ function sayAround(words, text, slot, node, values = {}) {
31
+ const [before, after = ''] = say(words, text, { ...values, [slot]: '\u0000' }).split('\u0000');
32
+ return _jsxs(_Fragment, { children: [before, node, after] });
33
+ }
34
+ /** The recovery codes as the file Aiveth's own page offers (its name and text from Aiveth). */
35
+ function download(name, contents) {
36
+ const url = URL.createObjectURL(new Blob([contents], { type: 'text/plain;charset=utf-8' }));
37
+ const a = Object.assign(document.createElement('a'), { href: url, download: name });
38
+ a.click();
39
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
40
+ }
41
+ function inviteFromAddress() {
42
+ if (typeof window === 'undefined')
43
+ return '';
44
+ return new URLSearchParams(window.location.search).get('invitation') ?? '';
45
+ }
46
+ export function SignInBox({ setup, mode, locale, invitation, className, style }) {
47
+ const [settings, setSettings] = useState(null);
48
+ const [step, setStep] = useState(null);
49
+ const [email, setEmail] = useState('');
50
+ const [asSignUp, setAsSignUp] = useState(mode === 'sign-up');
51
+ const [problem, setProblem] = useState('');
52
+ const [busy, setBusy] = useState(false);
53
+ const flow = useRef(null);
54
+ const started = useRef(false);
55
+ useEffect(() => {
56
+ let live = true;
57
+ setup.settings(locale).then((s) => { if (live)
58
+ setSettings(s); }).catch(() => { if (live)
59
+ setProblem('Sign-in is not available here.'); });
60
+ return () => { live = false; };
61
+ }, [setup, locale]);
62
+ const run = async (work) => {
63
+ setBusy(true);
64
+ setProblem('');
65
+ try {
66
+ const got = await work();
67
+ const next = 'flow' in got ? (flow.current = got.flow, got.step) : got;
68
+ if (next.status === 'needs_aiveth') {
69
+ flow.current?.continueOnAiveth();
70
+ return;
71
+ }
72
+ if (next.status === 'signed_in') {
73
+ setup.onSignedIn(next);
74
+ return;
75
+ }
76
+ if (next.status === 'refused')
77
+ setProblem(next.errorDescription ?? next.error ?? '');
78
+ if (next.status === 'needs_first_factor')
79
+ setAsSignUp(false); // an account already: its sign-in
80
+ if (next.email)
81
+ setEmail(next.email);
82
+ setStep(next);
83
+ }
84
+ catch (e) {
85
+ setProblem(e instanceof StepRefused ? e.message : 'Something went wrong. Try again.');
86
+ }
87
+ finally {
88
+ setBusy(false);
89
+ }
90
+ };
91
+ useEffect(() => {
92
+ const token = invitation ?? inviteFromAddress();
93
+ if (!settings || !token || started.current)
94
+ return;
95
+ started.current = true;
96
+ void run(() => setup.invitation(token));
97
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- once, when the settings arrive
98
+ }, [settings]);
99
+ if (!settings)
100
+ return problem ? _jsx("p", { role: "alert", children: problem }) : null;
101
+ const w = settings.words;
102
+ const c = palette(settings.look);
103
+ const radius = settings.look.radius ?? 10;
104
+ const outlined = settings.look.button_style === 'outlined';
105
+ const font = settings.look.font?.family;
106
+ const s = {
107
+ card: { boxSizing: 'border-box', width: '100%', maxWidth: 400, height: 'fit-content', padding: 28, background: c.card, color: c.text, border: `1px solid ${c.border}`, borderRadius: radius + 4, fontFamily: font ? `'${font}', system-ui, sans-serif` : 'system-ui, sans-serif', ...style },
108
+ title: { margin: '0 0 16px', fontSize: 20, fontWeight: 600, textAlign: 'center' },
109
+ label: { display: 'block', fontSize: 14, fontWeight: 500, margin: '12px 0 6px' },
110
+ input: { boxSizing: 'border-box', width: '100%', minHeight: 44, padding: '0 12px', background: c.input, color: c.text, border: `1px solid ${c.border}`, borderRadius: radius, fontSize: 16, fontFamily: 'inherit' },
111
+ button: { width: '100%', minHeight: 44, marginTop: 16, border: outlined ? `1px solid ${c.button}` : 'none', borderRadius: radius, background: outlined ? 'transparent' : c.button, color: outlined ? c.button : c.button_text, fontSize: 15, fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit' },
112
+ quiet: { width: '100%', minHeight: 44, marginTop: 10, background: 'transparent', color: c.text, border: `1px solid ${c.border}`, borderRadius: radius, fontSize: 15, cursor: 'pointer', fontFamily: 'inherit' },
113
+ link: { background: 'none', border: 'none', padding: 0, color: c.link, cursor: 'pointer', fontSize: 14, fontFamily: 'inherit' },
114
+ note: { fontSize: 14, color: c.muted, margin: '8px 0 0', textAlign: 'center' },
115
+ alert: { fontSize: 14, color: '#dc2626', margin: '12px 0 0' },
116
+ foot: { fontSize: 12, color: c.muted, textAlign: 'center', margin: '18px 0 0' },
117
+ };
118
+ const logo = dark(settings.look) ? settings.look.logo_dark ?? settings.look.logo : settings.look.logo;
119
+ const field = (id, label, props) => (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: id, style: s.label, children: label }), _jsx("input", { id: id, name: id, required: true, style: s.input, ...props })] }));
120
+ const submit = (work) => (e) => {
121
+ e.preventDefault();
122
+ const form = new FormData(e.currentTarget);
123
+ void run(() => work(form));
124
+ };
125
+ const text = (form, key) => String(form.get(key) ?? '');
126
+ const who = (_jsxs("p", { style: s.note, children: [say(w, 'Signing in as {email}', { email }), " \u00B7", ' ', _jsx("button", { type: "button", style: s.link, onClick: () => { setStep(null); flow.current = null; }, children: say(w, 'Change') })] }));
127
+ let body;
128
+ const status = step?.status;
129
+ if (!step) {
130
+ body = (_jsxs("form", { onSubmit: submit((f) => { const typed = text(f, 'email'); setEmail(typed); return asSignUp ? setup.signUp(typed) : setup.start(typed); }), children: [field('email', say(w, 'Work email'), { type: 'email', autoComplete: 'username', defaultValue: email }), _jsx("button", { type: "submit", style: s.button, disabled: busy, children: say(w, 'Continue') }), settings.sign_up && (asSignUp
131
+ ? _jsx("p", { style: s.note, children: _jsx("button", { type: "button", style: s.link, onClick: () => setAsSignUp(false), children: say(w, 'Back to sign in') }) })
132
+ : _jsx("p", { style: s.note, children: sayAround(w, 'New here? {link}', 'link', _jsx("button", { type: "button", style: s.link, onClick: () => setAsSignUp(true), children: say(w, 'Create an account') })) }))] }));
133
+ }
134
+ else if (status === 'needs_first_factor') {
135
+ const ways = step.ways ?? [];
136
+ body = (_jsxs(_Fragment, { children: [who, ways.includes('password') && (_jsxs("form", { onSubmit: submit((f) => flow.current.password(text(f, 'password'))), children: [field('password', say(w, 'Password'), { type: 'password', autoComplete: 'current-password', autoFocus: true }), _jsx("p", { style: { ...s.note, textAlign: 'end' }, children: _jsx("button", { type: "button", style: s.link, onClick: () => void run(() => flow.current.sendResetCode()), children: say(w, 'Forgot password?') }) }), _jsx("button", { type: "submit", style: s.button, disabled: busy, children: say(w, 'Continue') })] })), ways.includes('email_code') && _jsx("button", { type: "button", style: s.quiet, disabled: busy, onClick: () => void run(() => flow.current.sendEmailCode()), children: say(w, 'Email me a code') }), ways.filter((x) => PROVIDERS[x]).map((x) => (_jsx("button", { type: "button", style: s.quiet, onClick: () => setup.withProvider(x, email), children: say(w, 'Continue with {name}', { name: PROVIDERS[x] ?? x }) }, x))), ways.includes('sso') && _jsx("button", { type: "button", style: s.quiet, onClick: () => setup.withProvider('sso', email), children: say(w, 'Single sign-on (SSO)') })] }));
137
+ }
138
+ else if (status === 'needs_email_code' || status === 'needs_reset_code') {
139
+ const signUp = asSignUp && status === 'needs_email_code';
140
+ body = (_jsxs("form", { onSubmit: submit((f) => {
141
+ const code = text(f, 'code');
142
+ if (status === 'needs_reset_code')
143
+ return flow.current.verifyResetCode(code);
144
+ return signUp ? flow.current.verifySignUpCode(code) : flow.current.verifyEmailCode(code);
145
+ }), children: [_jsx("p", { style: s.note, children: say(w, 'We sent a code to {email}. It ends in 10 minutes.', { email }) }), field('code', say(w, '8-digit code'), { inputMode: 'numeric', autoComplete: 'one-time-code', autoFocus: true }), _jsx("button", { type: "submit", style: s.button, disabled: busy, children: say(w, 'Continue') })] }));
146
+ }
147
+ else if (status === 'needs_second_factor') {
148
+ body = (_jsxs("form", { onSubmit: submit((f) => flow.current.secondFactor(text(f, 'code'))), children: [who, field('code', say(w, 'Code from your app, or a recovery code'), { autoComplete: 'one-time-code', autoFocus: true }), _jsx("button", { type: "submit", style: s.button, disabled: busy, children: say(w, 'Continue') })] }));
149
+ }
150
+ else if (status === 'needs_new_password') {
151
+ body = (_jsxs("form", { onSubmit: submit((f) => flow.current.setNewPassword(text(f, 'password'))), children: [field('password', say(w, 'New password'), { type: 'password', autoComplete: 'new-password', autoFocus: true }), _jsx("button", { type: "submit", style: s.button, disabled: busy, children: say(w, 'Continue') })] }));
152
+ }
153
+ else if (status === 'needs_details') {
154
+ body = (_jsxs("form", { onSubmit: submit((f) => flow.current.details({ firstName: text(f, 'first_name'), lastName: text(f, 'last_name'), password: text(f, 'password') })), children: [email && _jsx("p", { style: s.note, children: email }), field('first_name', say(w, 'First name'), { autoComplete: 'given-name', autoFocus: true }), _jsx("label", { htmlFor: "last_name", style: s.label, children: say(w, 'Last name') }), _jsx("input", { id: "last_name", name: "last_name", style: s.input, autoComplete: "family-name" }), field('password', say(w, 'Password'), { type: 'password', autoComplete: 'new-password' }), _jsx("button", { type: "submit", style: s.button, disabled: busy, children: say(w, 'Continue') })] }));
155
+ }
156
+ else if (status === 'needs_legal_acceptance') {
157
+ const links = [[step.termsUrl, 'Terms of Service'], [step.privacyUrl, 'Privacy Policy']].filter(([u]) => u);
158
+ body = (_jsxs("form", { onSubmit: submit(() => flow.current.acceptTerms()), children: [_jsxs("label", { style: { display: 'flex', gap: 8, alignItems: 'flex-start', fontSize: 14 }, children: [_jsx("input", { type: "checkbox", required: true }), _jsx("span", { children: sayAround(w, "I agree to {company}'s {links}", 'links', links.map(([u, t], i) => _jsxs("span", { children: [i ? ', ' : '', _jsx("a", { href: u, target: "_blank", rel: "noopener noreferrer", style: { color: c.link }, children: say(w, t) })] }, u)), { company: settings.name }) })] }), _jsx("button", { type: "submit", style: s.button, disabled: busy, children: say(w, 'Continue') })] }));
159
+ }
160
+ else if (status === 'needs_two_step_setup') {
161
+ const key = (step.secret ?? '').replace(/(.{4})/g, '$1 ').trim();
162
+ body = (_jsxs("form", { onSubmit: submit((f) => flow.current.verifyTwoStepSetup(text(f, 'code'))), children: [_jsx("p", { style: s.note, children: say(w, 'Your organization asks everyone to use two-step sign-in. It takes a minute.') }), _jsxs("ol", { style: { fontSize: 14, paddingInlineStart: 20, margin: '12px 0' }, children: [_jsx("li", { children: say(w, 'Open an authenticator app — Google Authenticator, Microsoft Authenticator, 1Password or any other.') }), _jsx("li", { children: say(w, 'Scan this code, then type the 6 digits it shows.') })] }), step.qr && _jsx("img", { src: step.qr, alt: say(w, 'QR code for your authenticator app'), width: 180, height: 180, style: { display: 'block', margin: '0 auto', background: '#fff', borderRadius: 8 } }), _jsx("p", { style: { ...s.note, overflowWrap: 'anywhere' }, children: sayAround(w, "Can't scan? Type this key: {key}", 'key', _jsx("code", { children: key })) }), field('code', say(w, '6-digit code'), { inputMode: 'numeric', autoComplete: 'one-time-code', autoFocus: true }), _jsx("button", { type: "submit", style: s.button, disabled: busy, children: say(w, 'Turn on two-step') })] }));
163
+ }
164
+ else if (status === 'needs_recovery_codes_saved') {
165
+ const codes = step.recoveryCodes ?? [];
166
+ body = (_jsxs(_Fragment, { children: [_jsx("p", { style: s.note, children: say(w, 'Two-step is on.') }), _jsx("ul", { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 6, listStyle: 'none', padding: 0, margin: '14px 0', fontFamily: 'ui-monospace, monospace', fontSize: 14, textAlign: 'center' }, children: codes.map((code) => _jsx("li", { children: code }, code)) }), _jsx("p", { style: s.note, children: say(w, "Each one signs you in once if you lose your phone. This is the only time they're shown — keep them somewhere safe.") }), step.recoveryFile && _jsx("button", { type: "button", style: s.quiet, onClick: () => download(step.recoveryFileName ?? 'recovery-codes.txt', step.recoveryFile ?? ''), children: say(w, 'Download codes') }), _jsx("button", { type: "button", style: s.button, disabled: busy, onClick: () => void run(() => flow.current.recoveryCodesSaved()), children: say(w, "I've saved them — continue") })] }));
167
+ }
168
+ else if (status === 'needs_workspace') {
169
+ body = (_jsxs(_Fragment, { children: [_jsx("p", { style: s.note, children: say(w, 'The app opens in the one you choose.') }), (step.workspaces ?? []).map((ws) => (_jsx("button", { type: "button", style: s.quiet, disabled: busy, onClick: () => void run(() => flow.current.chooseWorkspace(ws.id)), children: ws.name }, ws.id)))] }));
170
+ }
171
+ else if (status === 'waiting') {
172
+ body = _jsx("p", { style: s.note, children: say(w, "Request sent. If an admin approves it, you'll get an invitation by email.") });
173
+ }
174
+ else {
175
+ body = _jsx("button", { type: "button", style: s.button, onClick: () => { setStep(null); flow.current = null; }, children: say(w, 'Back to sign in') });
176
+ }
177
+ const heading = status === 'needs_details' && step?.reason === 'invited' ? say(w, 'Join {name}', { name: settings.name })
178
+ : status === 'needs_legal_acceptance' ? say(w, 'Before you continue')
179
+ : status === 'needs_new_password' ? say(w, 'Choose a new password')
180
+ : status === 'needs_two_step_setup' ? say(w, 'Set up two-step sign-in')
181
+ : status === 'needs_recovery_codes_saved' ? say(w, 'Save your recovery codes')
182
+ : status === 'needs_workspace' ? say(w, 'Choose a workspace')
183
+ : asSignUp ? say(w, 'Create your account for {name}', { name: settings.name })
184
+ : say(w, 'Sign in to {name}', { name: settings.name });
185
+ const fontUrl = settings.look.font?.url;
186
+ return (_jsxs("div", { className: className, style: s.card, lang: settings.lang, dir: settings.dir, children: [font && fontUrl && _jsx("style", { children: `@font-face{font-family:'${font.replace(/'/g, '')}';src:url('${fontUrl.replace(/'/g, '')}') format('woff2');font-display:swap}` }), logo && _jsx("img", { src: logo, alt: settings.name, style: { display: 'block', maxHeight: 40, margin: '0 auto 16px' } }), _jsx("h1", { style: s.title, children: heading }), body, problem && _jsx("p", { role: "alert", style: s.alert, children: problem }), settings.secured_by && _jsx("p", { style: s.foot, children: say(w, 'Secured by {name}', { name: 'Aiveth' }) })] }));
187
+ }
package/dist/client.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { BoxSettings } from './box.js';
1
2
  import { HereFlow } from './here.js';
2
3
  export interface AivethConfig {
3
4
  /** Your Aiveth address, e.g. https://accounts.aiveth.com */
@@ -172,6 +173,8 @@ export declare class AivethClient {
172
173
  flow: HereFlow;
173
174
  step: import("./here.js").Step;
174
175
  }>;
176
+ /** What the ready-made `<SignIn />` shows: the look, the words in ``lang``, the badge. */
177
+ settings: (lang?: string) => Promise<BoxSettings>;
175
178
  };
176
179
  private hereFlow;
177
180
  /** On the return address: swap the code for tokens. Answers where the app wanted to go
package/dist/client.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * A reload forgets the tokens: `signIn()` again comes straight back while the person is still
9
9
  * signed in at Aiveth. The app must be a PUBLIC app (no secret) whose return address is
10
10
  * `redirectUri`; its origin may then call Aiveth's token endpoint (CORS). */
11
- import { HereFlow } from './here.js';
11
+ import { HereFlow, StepRefused } from './here.js';
12
12
  /** The audience of Aiveth's My workspace API for this issuer. */
13
13
  export function myWorkspaceAudience(issuer) {
14
14
  return `${issuer.replace(/\/+$/, '')}/my-workspace`;
@@ -161,6 +161,13 @@ export class AivethClient {
161
161
  const flow = this.hereFlow();
162
162
  return { flow, step: await flow.beginInvitation(await this.pending(returnTo), invitation) };
163
163
  },
164
+ /** What the ready-made `<SignIn />` shows: the look, the words in ``lang``, the badge. */
165
+ settings: async (lang = '') => {
166
+ const res = await this.fetcher(`${this.issuer}/v1/sign-in/${encodeURIComponent(this.config.clientId)}/box?${new URLSearchParams({ lang })}`);
167
+ if (!res.ok)
168
+ throw new StepRefused(res.status, 'Sign-in on this page is not turned on for the app.');
169
+ return (await res.json());
170
+ },
164
171
  };
165
172
  hereFlow() {
166
173
  return new HereFlow({
package/dist/here.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** What the next screen is. `signed_in`: done. `needs_aiveth`: send the browser to
2
2
  * `continueUrl` (a step only Aiveth's page can do), or call `continueOnAiveth()`. */
3
- export type StepStatus = 'needs_first_factor' | 'needs_second_factor' | 'needs_legal_acceptance' | 'needs_email_code' | 'needs_details' | 'needs_reset_code' | 'needs_new_password' | 'waiting' | 'needs_aiveth' | 'refused' | 'signed_in';
3
+ export type StepStatus = 'needs_first_factor' | 'needs_second_factor' | 'needs_legal_acceptance' | 'needs_email_code' | 'needs_details' | 'needs_reset_code' | 'needs_new_password' | 'needs_two_step_setup' | 'needs_recovery_codes_saved' | 'needs_workspace' | 'waiting' | 'needs_aiveth' | 'refused' | 'signed_in';
4
4
  export interface Step {
5
5
  status: StepStatus;
6
6
  /** needs_first_factor: `password`, `email_code`, and `google` / `microsoft` / `github` / `sso`
@@ -12,6 +12,20 @@ export interface Step {
12
12
  fields?: string[];
13
13
  /** needs_details from an invitation: the address it was sent to. */
14
14
  email?: string;
15
+ /** needs_two_step_setup: the QR code (an image address), its key to type by hand, its link. */
16
+ qr?: string;
17
+ secret?: string;
18
+ otpauthUri?: string;
19
+ /** needs_recovery_codes_saved: the codes, shown this once, and their file (name and text). */
20
+ recoveryCodes?: string[];
21
+ recoveryFileName?: string;
22
+ recoveryFile?: string;
23
+ /** needs_workspace: the person's workspaces to pick from. */
24
+ workspaces?: {
25
+ id: string;
26
+ slug: string;
27
+ name: string;
28
+ }[];
15
29
  reason?: string;
16
30
  termsUrl?: string;
17
31
  privacyUrl?: string;
@@ -82,6 +96,15 @@ export declare class HereFlow {
82
96
  lastName?: string;
83
97
  password: string;
84
98
  }): Promise<Step>;
99
+ /** needs_two_step_setup (the organization requires two-step): the set-up again — the same QR
100
+ * while it is open, a fresh one after it took too long (a 410 from `verifyTwoStepSetup`). */
101
+ twoStepSetup(): Promise<Step>;
102
+ /** The 6 digits the authenticator app shows: two-step is on; the recovery codes come next. */
103
+ verifyTwoStepSetup(code: string): Promise<Step>;
104
+ /** The person saved their recovery codes: the sign-in goes on. */
105
+ recoveryCodesSaved(): Promise<Step>;
106
+ /** needs_workspace: the workspace picked (its `id` or `slug`). */
107
+ chooseWorkspace(workspace: string): Promise<Step>;
85
108
  /** After `needs_aiveth`: the rest on Aiveth's page, then back to your app. */
86
109
  continueOnAiveth(): void;
87
110
  }
package/dist/here.js CHANGED
@@ -48,6 +48,8 @@ export class HereFlow {
48
48
  status: said.status, ways: said.ways, factors: said.factors, fields: said.fields,
49
49
  email: said.email, reason: said.reason, termsUrl: said.terms_url, privacyUrl: said.privacy_url,
50
50
  continueUrl: said.continue_url, error: said.error, errorDescription: said.error_description,
51
+ qr: said.qr, secret: said.secret, otpauthUri: said.otpauth_uri, recoveryCodes: said.recovery_codes,
52
+ recoveryFileName: said.recovery_file_name, recoveryFile: said.recovery_file, workspaces: said.workspaces,
51
53
  };
52
54
  }
53
55
  at(kind, step) {
@@ -83,6 +85,15 @@ export class HereFlow {
83
85
  details(d) {
84
86
  return this.send(this.at('sign-ups', 'details'), { first_name: d.firstName, last_name: d.lastName ?? '', password: d.password });
85
87
  }
88
+ /** needs_two_step_setup (the organization requires two-step): the set-up again — the same QR
89
+ * while it is open, a fresh one after it took too long (a 410 from `verifyTwoStepSetup`). */
90
+ twoStepSetup() { return this.send(this.at('attempts', 'two-step-setup')); }
91
+ /** The 6 digits the authenticator app shows: two-step is on; the recovery codes come next. */
92
+ verifyTwoStepSetup(code) { return this.send(this.at('attempts', 'two-step-setup/verify'), { code }); }
93
+ /** The person saved their recovery codes: the sign-in goes on. */
94
+ recoveryCodesSaved() { return this.send(this.at('attempts', 'two-step-setup/saved')); }
95
+ /** needs_workspace: the workspace picked (its `id` or `slug`). */
96
+ chooseWorkspace(workspace) { return this.send(this.at('attempts', 'workspace'), { workspace }); }
86
97
  /** After `needs_aiveth`: the rest on Aiveth's page, then back to your app. */
87
98
  continueOnAiveth() {
88
99
  if (!this.continueUrl)
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { AivethClient, RefusedError, SignInError, authorizeHints, claimsOf, type Connection, type SignInOptions, myWorkspaceAudience, type MyWorkspace, type WorkspaceMember, type WorkspaceInvitationView, type Actor, type AivethConfig, type Returned, type User } from './client.js';
2
- export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, AivethButton, SignOutButton, UserButton, ActingBanner, type AivethProviderProps, type UseAiveth } from './react.js';
2
+ export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, AivethButton, SignOutButton, UserButton, ActingBanner, SignIn, SignUp, type AivethProviderProps, type UseAiveth } from './react.js';
3
+ export { SignInBox, type BoxProps, type BoxSettings, type BoxSetup } from './box.js';
3
4
  export { BrandedButton, useBrandLook, type BrandLook, type BrandedButtonProps } from './brand.js';
4
5
  export { HereFlow, StepRefused, type Step, type StepStatus } from './here.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { AivethClient, RefusedError, SignInError, authorizeHints, claimsOf, myWorkspaceAudience } from './client.js';
2
- export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, AivethButton, SignOutButton, UserButton, ActingBanner } from './react.js';
2
+ export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, AivethButton, SignOutButton, UserButton, ActingBanner, SignIn, SignUp } from './react.js';
3
+ export { SignInBox } from './box.js';
3
4
  export { BrandedButton, useBrandLook } from './brand.js';
4
5
  export { HereFlow, StepRefused } from './here.js';
package/dist/react.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type CSSProperties, type ReactNode } from 'react';
2
+ import { type BoxProps } from './box.js';
2
3
  import { AivethClient, type Actor, type AivethConfig, type SignInOptions, type User } from './client.js';
3
4
  export interface AivethProviderProps extends AivethConfig {
4
5
  children: ReactNode;
@@ -65,3 +66,16 @@ export declare function UserButton({ className }: {
65
66
  export declare function ActingBanner({ className }: {
66
67
  className?: string;
67
68
  }): import("react/jsx-runtime").JSX.Element | null;
69
+ /** The ready-made sign-in on your own page (turn on "Sign-in on your page" for the app in
70
+ * Aiveth): every step, in your organization's look and the person's language, "Secured by
71
+ * Aiveth" below on Free and Pro. `onSignedIn`: where to go next with your router (tokens are
72
+ * kept in memory — never reload the page to move on). */
73
+ export declare function SignIn(props: BoxProps & {
74
+ returnTo?: string;
75
+ onSignedIn?: (returnTo: string | null) => void;
76
+ }): import("react/jsx-runtime").JSX.Element;
77
+ /** `<SignIn />` opening on sign-up, where your organization lets people join from its apps. */
78
+ export declare function SignUp(props: BoxProps & {
79
+ returnTo?: string;
80
+ onSignedIn?: (returnTo: string | null) => void;
81
+ }): import("react/jsx-runtime").JSX.Element;
package/dist/react.js CHANGED
@@ -4,6 +4,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
4
4
  * itself happens on Aiveth's page (RFC 8252). */
5
5
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
6
6
  import { BrandedButton, useBrandLook } from './brand.js';
7
+ import { SignInBox } from './box.js';
7
8
  import { AivethClient } from './client.js';
8
9
  const Context = createContext(null);
9
10
  /** Put it around your app. On the return address it finishes the sign-in by itself. */
@@ -114,3 +115,32 @@ export function ActingBanner({ className }) {
114
115
  const name = user.name ?? user.email ?? 'this person';
115
116
  return (_jsxs("div", { role: "status", style: BANNER.bar, className: className, children: [_jsxs("span", { children: [_jsxs("strong", { children: ["Acting as ", name] }), " \u00B7 by ", actor.email ?? 'support', actor.reason ? ` · ${actor.reason}` : ''] }), _jsx("a", { href: actingUrl, style: BANNER.end, children: "End" })] }));
116
117
  }
118
+ /** The ready-made sign-in on your own page (turn on "Sign-in on your page" for the app in
119
+ * Aiveth): every step, in your organization's look and the person's language, "Secured by
120
+ * Aiveth" below on Free and Pro. `onSignedIn`: where to go next with your router (tokens are
121
+ * kept in memory — never reload the page to move on). */
122
+ export function SignIn(props) {
123
+ return _jsx(SignInBox, { setup: useBoxSetup(props), mode: "sign-in", ...props });
124
+ }
125
+ /** `<SignIn />` opening on sign-up, where your organization lets people join from its apps. */
126
+ export function SignUp(props) {
127
+ return _jsx(SignInBox, { setup: useBoxSetup(props), mode: "sign-up", ...props });
128
+ }
129
+ function useBoxSetup({ returnTo, onSignedIn }) {
130
+ const ctx = useContext(Context);
131
+ if (!ctx)
132
+ throw new Error('<SignIn /> needs <AivethProvider> around your app.');
133
+ const { client } = ctx;
134
+ const after = useRef(onSignedIn);
135
+ after.current = onSignedIn;
136
+ return useMemo(() => ({
137
+ settings: (lang) => client.signInHere.settings(lang),
138
+ start: (email) => client.signInHere.start({ email, returnTo }),
139
+ signUp: (email) => client.signInHere.signUp({ email, returnTo }),
140
+ invitation: (token) => client.signInHere.invitation(token, { returnTo }),
141
+ withProvider: (connection, email) => {
142
+ void client.signIn({ connection: connection, loginHint: email || undefined, returnTo });
143
+ },
144
+ onSignedIn: (step) => after.current?.(step.returnTo ?? null),
145
+ }), [client, returnTo]);
146
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiveth/react",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Official Aiveth SDK for React: sign in on Aiveth's page with PKCE, tokens kept in memory, and ready-made sign-in pieces.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Aiveth team",