reifyui 0.19.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +128 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +122 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/auth/AuthForm.jsx +2 -0
- package/src/auth/client.js +34 -4
- package/src/auth/personCheck.js +98 -0
- package/src/index.d.ts +7 -1
- package/src/index.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reifyui",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI — model-agnostic, framework-agnostic, design-system-native. The foundation for building generative-UI and agent products.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
package/src/auth/AuthForm.jsx
CHANGED
|
@@ -140,6 +140,7 @@ export function AuthForm({ onDone, subtitle, brand = null, productName = '' }) {
|
|
|
140
140
|
<label>Email</label>
|
|
141
141
|
<input className="input" type="email" value={email} onChange={(e) => setEmail(e.target.value)} autoFocus required autoComplete="email" />
|
|
142
142
|
</div>
|
|
143
|
+
<div data-person-check="" className="person-check" />
|
|
143
144
|
{err && <div className="auth-err">{err}</div>}
|
|
144
145
|
<button type="submit" className="btn primary lg" style={{ width: '100%', marginTop: 8 }} disabled={busy}>
|
|
145
146
|
{busy ? 'Please wait...' : 'Send reset link'}
|
|
@@ -180,6 +181,7 @@ export function AuthForm({ onDone, subtitle, brand = null, productName = '' }) {
|
|
|
180
181
|
placeholder={mode === 'register' ? 'At least 8 characters' : ''}
|
|
181
182
|
/>
|
|
182
183
|
</div>
|
|
184
|
+
{mode === 'register' && <div data-person-check="" className="person-check" />}
|
|
183
185
|
{err && <div className="auth-err">{err}</div>}
|
|
184
186
|
<button type="submit" className="btn primary lg" style={{ width: '100%', marginTop: 8 }} disabled={busy}>
|
|
185
187
|
{busy ? 'Please wait...' : mode === 'register' ? 'Create account' : 'Sign in'}
|
package/src/auth/client.js
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
// call order (configure first) is the only contract.
|
|
12
12
|
/* eslint-env browser */
|
|
13
13
|
|
|
14
|
+
import { personToken } from './personCheck.js';
|
|
15
|
+
|
|
14
16
|
const _cfg = {
|
|
15
17
|
// Same-origin. A product that forgets to configure gets the working default rather than the
|
|
16
18
|
// engine's Azure FQDN, which no browser may call — its ingress admits only the VM that fronts
|
|
@@ -97,7 +99,8 @@ export async function login(email, password) {
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
export async function register(email, password, name = '') {
|
|
100
|
-
const
|
|
102
|
+
const turnstile_token = await personToken('register', _cfg.engine);
|
|
103
|
+
const s = toSession(await authPost('/v1/auth/register', { email, password, name, product: _cfg.product, turnstile_token }));
|
|
101
104
|
setSession(s);
|
|
102
105
|
return s;
|
|
103
106
|
}
|
|
@@ -117,12 +120,39 @@ export async function microsoftSignIn(credential) {
|
|
|
117
120
|
return s;
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
// A reset or resend refusal in the person's words: the engine's own sentence for a check it refused
|
|
124
|
+
// (the person check, an address whose domain takes no mail), else the general one. Neither says
|
|
125
|
+
// whether the address has an account: the engine answers 200 for one it doesn't know.
|
|
126
|
+
async function readMailDoorError(res) {
|
|
127
|
+
if (res.status === 400 || res.status === 403 || res.status === 503) {
|
|
128
|
+
try {
|
|
129
|
+
const d = (await res.json())?.detail;
|
|
130
|
+
if (typeof d === 'string' && d.length > 0 && d.length < 200) return d;
|
|
131
|
+
} catch { /* not JSON */ }
|
|
132
|
+
}
|
|
133
|
+
return 'We could not send the request. Please try again later.';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function mailDoor(path, door, email) {
|
|
137
|
+
const turnstile_token = await personToken(door, _cfg.engine);
|
|
138
|
+
const res = await fetch(`${_cfg.engine}${path}`, {
|
|
122
139
|
method: 'POST',
|
|
123
140
|
headers: { 'content-type': 'application/json' },
|
|
124
|
-
body: JSON.stringify({ email, product: _cfg.product }),
|
|
141
|
+
body: JSON.stringify({ email, product: _cfg.product, turnstile_token }),
|
|
125
142
|
});
|
|
143
|
+
// a refusal is said, never shown as "check your email" with no mail coming
|
|
144
|
+
if (!res.ok) throw new Error(await readMailDoorError(res));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Ask for a password reset link. Resolves when the engine took the request (it answers the same
|
|
148
|
+
* whether or not the address has an account); throws with words for the person when it refused. */
|
|
149
|
+
export async function requestPasswordReset(email) {
|
|
150
|
+
await mailDoor('/v1/auth/request-password-reset', 'reset', email);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Send the confirmation email again, as requestPasswordReset does. */
|
|
154
|
+
export async function resendVerification(email) {
|
|
155
|
+
await mailDoor('/v1/auth/resend-verification', 'resend', email);
|
|
126
156
|
}
|
|
127
157
|
|
|
128
158
|
/** Re-mint an org-scoped token for the chosen org. */
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// The person check on the engine's three doors that send mail: sign-up (register), password reset
|
|
2
|
+
// (request-password-reset) and resending the confirmation email (resend-verification). The engine
|
|
3
|
+
// checks the token this gets on the server; for a door it enforces, a request without a good token
|
|
4
|
+
// is refused (403) and no mail goes out.
|
|
5
|
+
//
|
|
6
|
+
// The site key is public and the engine hands it out (GET <engine>/v1/auth/person-check), so a
|
|
7
|
+
// product sets nothing at build time; with none set, no widget runs and no token is sent. The widget
|
|
8
|
+
// runs in Cloudflare's managed mode and is shown only when Cloudflare asks the person to do
|
|
9
|
+
// something; it renders into the visible [data-person-check] slot of the form being sent (AuthForm
|
|
10
|
+
// carries one), else into a box at the end of the page, so the form looks as it always has.
|
|
11
|
+
// A token is good for one request and only for the door it was made for (its action).
|
|
12
|
+
/* eslint-env browser */
|
|
13
|
+
|
|
14
|
+
const SCRIPT = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
|
|
15
|
+
const WAIT_MS = 60_000;
|
|
16
|
+
|
|
17
|
+
/** What a person reads when the check can't finish here (the engine's own words for its refusal). */
|
|
18
|
+
export const PERSON_CHECK_FAILED = "We couldn't confirm you're a person. Please try again.";
|
|
19
|
+
|
|
20
|
+
/** @type {Map<string, Promise<string>>} engine -> its site key; only an answer is kept */
|
|
21
|
+
const keys = new Map();
|
|
22
|
+
/** @type {Promise<any> | null} */
|
|
23
|
+
let script = null;
|
|
24
|
+
|
|
25
|
+
function siteKey(engine) {
|
|
26
|
+
let p = keys.get(engine);
|
|
27
|
+
if (!p) {
|
|
28
|
+
p = fetch(`${engine}/v1/auth/person-check`, { cache: 'no-store' })
|
|
29
|
+
.then(async (r) => {
|
|
30
|
+
if (!r.ok) throw new Error('no answer');
|
|
31
|
+
const b = await r.json();
|
|
32
|
+
return typeof b?.site_key === 'string' ? b.site_key : '';
|
|
33
|
+
})
|
|
34
|
+
// a failed read is asked again next time, never remembered as "no key"
|
|
35
|
+
.catch(() => { keys.delete(engine); return ''; });
|
|
36
|
+
keys.set(engine, p);
|
|
37
|
+
}
|
|
38
|
+
return p;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function loadScript() {
|
|
42
|
+
script ??= new Promise((resolve, reject) => {
|
|
43
|
+
if (window.turnstile) { resolve(window.turnstile); return; }
|
|
44
|
+
const s = document.createElement('script');
|
|
45
|
+
s.src = SCRIPT; s.async = true; s.defer = true;
|
|
46
|
+
s.onload = () => (window.turnstile ? resolve(window.turnstile) : reject(new Error(PERSON_CHECK_FAILED)));
|
|
47
|
+
s.onerror = () => { script = null; s.remove(); reject(new Error(PERSON_CHECK_FAILED)); };
|
|
48
|
+
document.head.appendChild(s);
|
|
49
|
+
});
|
|
50
|
+
return script;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function slot() {
|
|
54
|
+
const shown = Array.from(document.querySelectorAll('[data-person-check]')).find((el) => el.offsetParent !== null);
|
|
55
|
+
if (shown) return shown;
|
|
56
|
+
let el = document.getElementById('person-check-fallback');
|
|
57
|
+
if (!el) {
|
|
58
|
+
el = document.createElement('div');
|
|
59
|
+
el.id = 'person-check-fallback';
|
|
60
|
+
el.className = 'person-check-fallback';
|
|
61
|
+
document.body.appendChild(el);
|
|
62
|
+
}
|
|
63
|
+
return el;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A fresh token for one door ('register' | 'reset' | 'resend'), or '' when the engine has no site key
|
|
68
|
+
* set (nothing to check). Call it right before the request it goes with. Throws, with words for the
|
|
69
|
+
* person, when the check can't finish.
|
|
70
|
+
* @param {'register'|'reset'|'resend'} door
|
|
71
|
+
* @param {string} engine the engine's base, as configureAuth was given it
|
|
72
|
+
* @returns {Promise<string>}
|
|
73
|
+
*/
|
|
74
|
+
export async function personToken(door, engine) {
|
|
75
|
+
const key = await siteKey(engine);
|
|
76
|
+
if (!key) return '';
|
|
77
|
+
const ts = await loadScript();
|
|
78
|
+
const host = document.createElement('div');
|
|
79
|
+
slot().appendChild(host);
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
let id = '';
|
|
82
|
+
const done = (fn) => {
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
try { if (id) ts.remove(id); } catch { /* already gone */ }
|
|
85
|
+
host.remove();
|
|
86
|
+
fn();
|
|
87
|
+
};
|
|
88
|
+
const fail = () => done(() => reject(new Error(PERSON_CHECK_FAILED)));
|
|
89
|
+
const timer = setTimeout(fail, WAIT_MS);
|
|
90
|
+
try {
|
|
91
|
+
id = ts.render(host, {
|
|
92
|
+
sitekey: key, action: door, appearance: 'interaction-only', theme: 'auto', 'refresh-expired': 'never',
|
|
93
|
+
callback: (token) => done(() => resolve(token)),
|
|
94
|
+
'error-callback': fail, 'expired-callback': fail, 'timeout-callback': fail,
|
|
95
|
+
});
|
|
96
|
+
} catch { fail(); }
|
|
97
|
+
});
|
|
98
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -513,7 +513,13 @@ export function isAuthed(): boolean;
|
|
|
513
513
|
export function login(email: string, password: string): Promise<unknown>;
|
|
514
514
|
export function register(payload: Record<string, unknown>): Promise<unknown>;
|
|
515
515
|
export function googleSignIn(credential: string, extra?: Record<string, unknown>): Promise<unknown>;
|
|
516
|
-
|
|
516
|
+
/** Throws with words for the person when the engine refused (the person check, a domain that takes no mail). */
|
|
517
|
+
export function requestPasswordReset(email: string): Promise<void>;
|
|
518
|
+
/** Send the confirmation email again; throws as requestPasswordReset does. */
|
|
519
|
+
export function resendVerification(email: string): Promise<void>;
|
|
520
|
+
/** A fresh person-check token for one of the engine's mail doors, or '' when the engine sets no site key. */
|
|
521
|
+
export function personToken(door: 'register' | 'reset' | 'resend', engine: string): Promise<string>;
|
|
522
|
+
export const PERSON_CHECK_FAILED: string;
|
|
517
523
|
export function switchOrg(orgId: string): Promise<unknown>;
|
|
518
524
|
export function refreshToken(): Promise<unknown>;
|
|
519
525
|
export function handleAuthExpired(): void;
|
package/src/index.js
CHANGED
|
@@ -38,9 +38,10 @@ export { DialogHost, useDialog } from './components/Dialog.jsx';
|
|
|
38
38
|
export {
|
|
39
39
|
configureAuth, authConfig, SESSION_EVENT,
|
|
40
40
|
getSession, clearSession, getToken, isAuthed,
|
|
41
|
-
login, register, googleSignIn, microsoftSignIn, requestPasswordReset, switchOrg,
|
|
41
|
+
login, register, googleSignIn, microsoftSignIn, requestPasswordReset, resendVerification, switchOrg,
|
|
42
42
|
refreshToken, handleAuthExpired, logout, authFetch, fetchBalance,
|
|
43
43
|
} from './auth/client.js';
|
|
44
|
+
export { personToken, PERSON_CHECK_FAILED } from './auth/personCheck.js';
|
|
44
45
|
export { AuthForm } from './auth/AuthForm.jsx';
|
|
45
46
|
export { GoogleButton, GOOGLE_ENABLED } from './auth/GoogleButton.jsx';
|
|
46
47
|
export { MicrosoftButton, MICROSOFT_ENABLED, microsoftIdToken } from './auth/MicrosoftButton.jsx';
|