@lushly-dev/afd-auth 2.5.0 → 3.1.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 +67 -3
- package/dist/adapters/convex-v2.d.ts +54 -0
- package/dist/adapters/convex-v2.d.ts.map +1 -0
- package/dist/adapters/convex-v2.js +107 -0
- package/dist/adapters/convex-v2.js.map +1 -0
- package/dist/adapters/convex.d.ts +45 -2
- package/dist/adapters/convex.d.ts.map +1 -1
- package/dist/adapters/convex.js +26 -6
- package/dist/adapters/convex.js.map +1 -1
- package/dist/middleware.d.ts +3 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +12 -3
- package/dist/middleware.js.map +1 -1
- package/dist/mutation-commands.d.ts.map +1 -1
- package/dist/mutation-commands.js +5 -1
- package/dist/mutation-commands.js.map +1 -1
- package/dist/react.d.ts +2 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js.map +1 -1
- package/dist/testing/index.d.ts +165 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +294 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +20 -14
package/README.md
CHANGED
|
@@ -55,6 +55,9 @@ const middleware = createAuthMiddleware(adapter, { exclude: ['public-cmd'] });
|
|
|
55
55
|
- The built-in commands `auth-sign-in`, `auth-sign-out` and `auth-session-get`
|
|
56
56
|
(`AUTH_COMMAND_NAMES`) always run, so a signed-out caller can sign in.
|
|
57
57
|
`exclude` adds more commands.
|
|
58
|
+
- `auth-sign-in` is exposed to the palette and the CLI, not to agents or MCP:
|
|
59
|
+
a person signs in, so an agent is never handed a password or a sign-in to
|
|
60
|
+
drive, and asks the person instead.
|
|
58
61
|
- The middleware sets or deletes `context.auth` on every call, excluded
|
|
59
62
|
commands included. A handler never sees a `context.auth` that the caller
|
|
60
63
|
supplied.
|
|
@@ -85,8 +88,14 @@ const middleware = createAuthMiddleware(adapter, { isVerifiedCredentials });
|
|
|
85
88
|
```
|
|
86
89
|
|
|
87
90
|
- A host that serves MCP with token authorization through this middleware
|
|
88
|
-
must pass it. Without it, a token's call
|
|
89
|
-
and its actor
|
|
91
|
+
must pass it. Without it, a token's call would be gated on the adapter's
|
|
92
|
+
session and its actor stamped with the session user, so afd-server's
|
|
93
|
+
`createMcpServer` and `createMcpHandler` with `auth` throw when they are
|
|
94
|
+
built with this middleware lacking it, in `middleware` directly or inside
|
|
95
|
+
`composeMiddleware`. A server without `auth` is unaffected. A middleware
|
|
96
|
+
wrapped in a function of your own is not seen, so pass the option there too,
|
|
97
|
+
and take `isVerifiedCredentials` from the copy of afd-server that serves the
|
|
98
|
+
request: each copy keeps its own brand.
|
|
90
99
|
- afd-server marks the `credentials` object it sets after verifying a token
|
|
91
100
|
with a private brand, and freezes it; `isVerifiedCredentials` recognises only
|
|
92
101
|
that object, and only until its `expiresAt` (or the end of its request).
|
|
@@ -154,6 +163,51 @@ goes to `onListenerError`, or is rethrown in a microtask when none is set.
|
|
|
154
163
|
|
|
155
164
|
### Convex
|
|
156
165
|
|
|
166
|
+
The adapter supports `@convex-dev/auth` 0.0.x (from 0.0.95) and 2.x. It takes
|
|
167
|
+
a different options shape for each line. Keep to one shape for a component's
|
|
168
|
+
life, because the 0.0.x shape calls `useAuthActions` as a hook.
|
|
169
|
+
|
|
170
|
+
**2.x**, where each sign-in method has its own hook. Call the hooks for the
|
|
171
|
+
methods the app offers and pass the functions they return:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { useAuthActions } from '@convex-dev/auth/react';
|
|
175
|
+
import { useSignInWithEmailPassword } from '@convex-dev/auth/methods/email-password/react';
|
|
176
|
+
import { useSignInWithGithub } from '@convex-dev/auth/methods/github/react';
|
|
177
|
+
|
|
178
|
+
const adapter = useConvexAuthAdapter({
|
|
179
|
+
signOut: useAuthActions().signOut,
|
|
180
|
+
signInWithPassword: useSignInWithEmailPassword(api.auth).signIn,
|
|
181
|
+
oauth: { github: useSignInWithGithub(api.auth).signIn },
|
|
182
|
+
useConvexAuth,
|
|
183
|
+
meQuery: () => useQuery(api.users.me),
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- Credentials sign-in calls `signInWithPassword({ email, password })`. A
|
|
188
|
+
missing password is `INVALID_CREDENTIALS`, and a missing
|
|
189
|
+
`signInWithPassword` is `PROVIDER_ERROR`.
|
|
190
|
+
- An OAuth sign-in calls `oauth[provider]`, forwarding `redirectTo`, and resolves
|
|
191
|
+
with a `redirect` outcome. A provider missing from `oauth` is rejected with
|
|
192
|
+
`PROVIDER_ERROR`, and so are `scopes`.
|
|
193
|
+
- In 2.x, `redirectTo` must be an absolute `http` or `https` URL that the
|
|
194
|
+
deployment allows as a redirect origin; 0.0.x accepted a relative path.
|
|
195
|
+
- The 2.x methods return errors as values. `INVALID_CREDENTIALS`,
|
|
196
|
+
`USER_NOT_FOUND` and the password rules become `INVALID_CREDENTIALS`, so a
|
|
197
|
+
form does not reveal which accounts exist. `RATE_LIMITED` becomes
|
|
198
|
+
`PROVIDER_ERROR`, with the wait in its suggestion. An `OTHER_ERROR` is mapped
|
|
199
|
+
from its `cause`, so a failed fetch is `NETWORK_ERROR`.
|
|
200
|
+
|
|
201
|
+
The 2.x support is checked against the types of `@convex-dev/auth` 2.1.0, by
|
|
202
|
+
unit tests, and by the hosted Convex fixture, which runs on 2.x. A credentialed
|
|
203
|
+
hosted run is tracked in #3006.
|
|
204
|
+
|
|
205
|
+
2.x email and password sign-up sends a link that must be opened before the first
|
|
206
|
+
sign-in, so a test without an inbox needs a stand-in for the Resend component's
|
|
207
|
+
`sendEmail`; the hosted fixture's `convex/mail.ts` is one.
|
|
208
|
+
|
|
209
|
+
**0.0.x**, through `useAuthActions().signIn`:
|
|
210
|
+
|
|
157
211
|
```ts
|
|
158
212
|
const adapter = useConvexAuthAdapter({
|
|
159
213
|
useAuthActions,
|
|
@@ -173,6 +227,9 @@ const adapter = useConvexAuthAdapter({
|
|
|
173
227
|
failures `NETWORK_ERROR`, everything else `PROVIDER_ERROR`. Production
|
|
174
228
|
Convex deployments hide server error text unless it is thrown as a
|
|
175
229
|
`ConvexError`, so there bad credentials surface as `PROVIDER_ERROR`.
|
|
230
|
+
|
|
231
|
+
For both lines:
|
|
232
|
+
|
|
176
233
|
- The state is `loading` while `meQuery` returns `undefined`, and
|
|
177
234
|
`unauthenticated` when it returns `null`.
|
|
178
235
|
- The session has no `expiresAt`, because Convex refreshes its token
|
|
@@ -321,7 +378,14 @@ remain tracked in [#362](https://github.com/lushly-dev/afd/issues/362).
|
|
|
321
378
|
|
|
322
379
|
The additional [Better Auth HTTPS/OAuth fixture](hosted/better-auth/README.md)
|
|
323
380
|
uses a local test OAuth provider and SQLite-backed Better Auth. It exercises the
|
|
324
|
-
callback, Secure cookies and restart persistence without a hosted account.
|
|
381
|
+
callback, Secure cookies and restart persistence without a hosted account. Its
|
|
382
|
+
child-process lifecycle, scratch-directory cleanup, loopback port allocation,
|
|
383
|
+
SQLite WAL/FK initialization and HTTP/HTTPS server helpers are exported from the
|
|
384
|
+
Node-only `@lushly-dev/afd-auth/testing` subpath (excluded from the browser
|
|
385
|
+
entries; `openTestSqliteDatabase` loads `node:sqlite` lazily for Node 22.13+ /
|
|
386
|
+
24+, while the other helpers run on Node 22.12+) so downstream Better Auth test
|
|
387
|
+
hosts (such as Loam's `@lushly-dev/loam-identity/testing`) share the same host
|
|
388
|
+
machinery. The
|
|
325
389
|
[Convex fixture](hosted/convex/README.md) bundles actual React/provider SDKs and
|
|
326
390
|
deployable backend functions; its local checks do not execute a Convex deployment.
|
|
327
391
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Sign-in for @convex-dev/auth 2.x
|
|
3
|
+
*
|
|
4
|
+
* Version 2 has no `useAuthActions().signIn(provider, params)`. Each method
|
|
5
|
+
* has its own hook (`useSignInWithEmailPassword(api.auth)`,
|
|
6
|
+
* `useSignInWithGithub(api.auth)`, ...) whose `signIn` resolves to a result
|
|
7
|
+
* value instead of throwing. The app calls those hooks and passes their
|
|
8
|
+
* `signIn` functions here; this module turns their results into the
|
|
9
|
+
* adapter's outcomes and error codes.
|
|
10
|
+
*/
|
|
11
|
+
import { AuthAdapterError } from '../errors.js';
|
|
12
|
+
import type { SignInOptions, SignInOutcome } from '../types.js';
|
|
13
|
+
/** What `useSignInWithEmailPassword(api.auth).signIn` resolves to in @convex-dev/auth 2.x. */
|
|
14
|
+
export type ConvexPasswordSignInResult = {
|
|
15
|
+
status: 'complete';
|
|
16
|
+
} | {
|
|
17
|
+
status: 'error';
|
|
18
|
+
userError: {
|
|
19
|
+
error: string;
|
|
20
|
+
retryAfterMs?: number;
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/** What an OAuth sign-in hook's `signIn` resolves to in @convex-dev/auth 2.x, when starting a flow. */
|
|
25
|
+
export type ConvexOauthStartResult = {
|
|
26
|
+
status: 'redirect';
|
|
27
|
+
redirect: URL;
|
|
28
|
+
} | {
|
|
29
|
+
status: 'error';
|
|
30
|
+
userError: {
|
|
31
|
+
error: string;
|
|
32
|
+
cause?: unknown;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/** `useSignInWithEmailPassword(api.auth).signIn` from `@convex-dev/auth/methods/email-password/react`. */
|
|
36
|
+
export type ConvexPasswordSignIn = (credentials: {
|
|
37
|
+
email: string;
|
|
38
|
+
password: string;
|
|
39
|
+
}) => Promise<ConvexPasswordSignInResult>;
|
|
40
|
+
/** The `signIn` of an OAuth method hook, such as `useSignInWithGithub(api.auth).signIn`. */
|
|
41
|
+
export type ConvexOauthSignIn = (options?: {
|
|
42
|
+
redirectTo?: string;
|
|
43
|
+
}) => Promise<ConvexOauthStartResult>;
|
|
44
|
+
/** The sign-in functions a 2.x app passes to the adapter. */
|
|
45
|
+
export interface ConvexV2SignIns {
|
|
46
|
+
signInWithPassword?: ConvexPasswordSignIn;
|
|
47
|
+
oauth?: Readonly<Record<string, ConvexOauthSignIn>>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sign in through the 2.x method functions. Failures reject with an
|
|
51
|
+
* {@link AuthAdapterError}; `mapThrown` maps a thrown or `OTHER_ERROR` cause.
|
|
52
|
+
*/
|
|
53
|
+
export declare function signInWithConvexV2(signIns: ConvexV2SignIns, options: SignInOptions, mapThrown: (error: unknown, credentials: boolean) => AuthAdapterError): Promise<SignInOutcome>;
|
|
54
|
+
//# sourceMappingURL=convex-v2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convex-v2.d.ts","sourceRoot":"","sources":["../../src/adapters/convex-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,gBAAgB,EAAsB,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEhE,8FAA8F;AAC9F,MAAM,MAAM,0BAA0B,GACnC;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,GACtB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAC;AAE7F,uGAAuG;AACvG,MAAM,MAAM,sBAAsB,GAC/B;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAA;CAAE,GACrC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAC;AAEtE,0GAA0G;AAC1G,MAAM,MAAM,oBAAoB,GAAG,CAAC,WAAW,EAAE;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CACjB,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAE1C,4FAA4F;AAC5F,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,CAAC,EAAE;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAEtC,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC/B,kBAAkB,CAAC,EAAE,oBAAoB,CAAC;IAC1C,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;CACpD;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACvC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,KAAK,gBAAgB,GACnE,OAAO,CAAC,aAAa,CAAC,CA4DxB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Sign-in for @convex-dev/auth 2.x
|
|
3
|
+
*
|
|
4
|
+
* Version 2 has no `useAuthActions().signIn(provider, params)`. Each method
|
|
5
|
+
* has its own hook (`useSignInWithEmailPassword(api.auth)`,
|
|
6
|
+
* `useSignInWithGithub(api.auth)`, ...) whose `signIn` resolves to a result
|
|
7
|
+
* value instead of throwing. The app calls those hooks and passes their
|
|
8
|
+
* `signIn` functions here; this module turns their results into the
|
|
9
|
+
* adapter's outcomes and error codes.
|
|
10
|
+
*/
|
|
11
|
+
import { AuthAdapterError, passkeyUnsupported } from '../errors.js';
|
|
12
|
+
/**
|
|
13
|
+
* Sign in through the 2.x method functions. Failures reject with an
|
|
14
|
+
* {@link AuthAdapterError}; `mapThrown` maps a thrown or `OTHER_ERROR` cause.
|
|
15
|
+
*/
|
|
16
|
+
export async function signInWithConvexV2(signIns, options, mapThrown) {
|
|
17
|
+
if (options.method === 'passkey')
|
|
18
|
+
throw passkeyUnsupported();
|
|
19
|
+
if (options.method === 'credentials') {
|
|
20
|
+
if (options.password === undefined) {
|
|
21
|
+
throw new AuthAdapterError({
|
|
22
|
+
code: 'INVALID_CREDENTIALS',
|
|
23
|
+
message: 'A password is required to sign in with Convex Auth email and password',
|
|
24
|
+
suggestion: 'Provide the account password and try again',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const signIn = signIns.signInWithPassword;
|
|
28
|
+
if (signIn === undefined) {
|
|
29
|
+
throw new AuthAdapterError({
|
|
30
|
+
code: 'PROVIDER_ERROR',
|
|
31
|
+
message: 'Email and password sign-in is not configured for this Convex adapter',
|
|
32
|
+
suggestion: 'Pass signInWithPassword: useSignInWithEmailPassword(api.auth).signIn to useConvexAuthAdapter',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
let result;
|
|
36
|
+
try {
|
|
37
|
+
result = await signIn({ email: options.email, password: options.password });
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw mapThrown(error, true);
|
|
41
|
+
}
|
|
42
|
+
if (result.status === 'complete')
|
|
43
|
+
return { kind: 'signed-in' };
|
|
44
|
+
throw passwordError(result.userError, mapThrown);
|
|
45
|
+
}
|
|
46
|
+
if (options.scopes !== undefined && options.scopes.length > 0) {
|
|
47
|
+
throw new AuthAdapterError({
|
|
48
|
+
code: 'PROVIDER_ERROR',
|
|
49
|
+
message: 'Convex Auth does not accept OAuth scopes at sign-in',
|
|
50
|
+
suggestion: `Configure scopes where the '${options.provider}' method is set up in convex/auth.ts, then sign in without scopes`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Own keys only: a provider id such as 'toString' must not reach Object.prototype.
|
|
54
|
+
const oauth = signIns.oauth;
|
|
55
|
+
const signIn = oauth !== undefined && Object.hasOwn(oauth, options.provider)
|
|
56
|
+
? oauth[options.provider]
|
|
57
|
+
: undefined;
|
|
58
|
+
if (signIn === undefined) {
|
|
59
|
+
throw new AuthAdapterError({
|
|
60
|
+
code: 'PROVIDER_ERROR',
|
|
61
|
+
message: `OAuth sign-in with '${options.provider}' is not configured for this Convex adapter`,
|
|
62
|
+
suggestion: `Pass oauth: { '${options.provider}': <the provider's sign-in hook>(api.auth).signIn } to useConvexAuthAdapter`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
let result;
|
|
66
|
+
try {
|
|
67
|
+
result = await signIn(options.redirectTo === undefined ? undefined : { redirectTo: options.redirectTo });
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw mapThrown(error, false);
|
|
71
|
+
}
|
|
72
|
+
if (result.status === 'redirect')
|
|
73
|
+
return { kind: 'redirect', url: result.redirect.href };
|
|
74
|
+
throw mapThrown(result.userError.cause ?? result.userError.error, false);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A wrong password and an unknown account are both INVALID_CREDENTIALS, so a
|
|
78
|
+
* sign-in form does not tell an attacker which accounts exist. The password
|
|
79
|
+
* rules (`PASSWORD_TOO_SHORT`, ...) apply at sign-in too: a password that
|
|
80
|
+
* breaks them cannot be the account's, so they are INVALID_CREDENTIALS as well.
|
|
81
|
+
*/
|
|
82
|
+
function passwordError(userError, mapThrown) {
|
|
83
|
+
switch (userError.error) {
|
|
84
|
+
case 'INVALID_CREDENTIALS':
|
|
85
|
+
case 'USER_NOT_FOUND':
|
|
86
|
+
case 'PASSWORD_TOO_SHORT':
|
|
87
|
+
case 'PASSWORD_TOO_LONG':
|
|
88
|
+
case 'PASSWORD_HAS_SURROUNDING_WHITESPACE':
|
|
89
|
+
return AuthAdapterError.invalidCredentials();
|
|
90
|
+
case 'RATE_LIMITED': {
|
|
91
|
+
const wait = userError.retryAfterMs;
|
|
92
|
+
const seconds = typeof wait === 'number' && Number.isFinite(wait) && wait > 0
|
|
93
|
+
? Math.ceil(wait / 1000)
|
|
94
|
+
: undefined;
|
|
95
|
+
return new AuthAdapterError({
|
|
96
|
+
code: 'PROVIDER_ERROR',
|
|
97
|
+
message: 'Too many failed sign-in attempts for this account',
|
|
98
|
+
suggestion: seconds === undefined
|
|
99
|
+
? 'Wait before trying again, or reset the password'
|
|
100
|
+
: `Wait ${seconds} ${seconds === 1 ? 'second' : 'seconds'} before trying again, or reset the password`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
return mapThrown(userError.cause ?? userError.error, true);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=convex-v2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convex-v2.js","sourceRoot":"","sources":["../../src/adapters/convex-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AA8BpE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,OAAwB,EACxB,OAAsB,EACtB,SAAqE;IAErE,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;QAAE,MAAM,kBAAkB,EAAE,CAAC;IAE7D,IAAI,OAAO,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;QACtC,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACpC,MAAM,IAAI,gBAAgB,CAAC;gBAC1B,IAAI,EAAE,qBAAqB;gBAC3B,OAAO,EAAE,uEAAuE;gBAChF,UAAU,EAAE,4CAA4C;aACxD,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;QAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,IAAI,gBAAgB,CAAC;gBAC1B,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,sEAAsE;gBAC/E,UAAU,EACT,8FAA8F;aAC/F,CAAC,CAAC;QACJ,CAAC;QACD,IAAI,MAAkC,CAAC;QACvC,IAAI,CAAC;YACJ,MAAM,GAAG,MAAM,MAAM,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D,CAAC,CAAC,QAAQ,OAAO,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,6CAA6C;aACxG,CAAC,CAAC;QACJ,CAAC;QACD;YACC,OAAO,SAAS,CAAC,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;AACF,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Convex auth adapter
|
|
3
3
|
*
|
|
4
|
-
* Bridges @convex-dev/auth React hooks to the AuthAdapter interface
|
|
4
|
+
* Bridges @convex-dev/auth React hooks to the AuthAdapter interface, for the
|
|
5
|
+
* 0.0.x line (`useAuthActions().signIn`) and the 2.x line (a hook per method).
|
|
5
6
|
* This is a React hook — must be called inside a component.
|
|
6
7
|
*/
|
|
7
8
|
import { type ListenerErrorHandler } from '../listeners.js';
|
|
8
9
|
import type { AuthAdapter, User } from '../types.js';
|
|
10
|
+
import { type ConvexOauthSignIn, type ConvexPasswordSignIn, type ConvexV2SignIns } from './convex-v2.js';
|
|
9
11
|
/** The part of `useAuthActions()` from `@convex-dev/auth/react` that the adapter calls. */
|
|
10
12
|
export interface ConvexAuthActions {
|
|
11
13
|
/** Resolves with `{ signingIn, redirect? }` in @convex-dev/auth. */
|
|
@@ -15,6 +17,12 @@ export interface ConvexAuthActions {
|
|
|
15
17
|
export interface ConvexAuthAdapterOptions {
|
|
16
18
|
/** Return value of useAuthActions() from @convex-dev/auth/react */
|
|
17
19
|
useAuthActions: () => ConvexAuthActions;
|
|
20
|
+
/** 2.x options only; with `useAuthActions`, the 0.0.x shape signs out through it. */
|
|
21
|
+
signOut?: never;
|
|
22
|
+
/** 2.x options only. */
|
|
23
|
+
signInWithPassword?: never;
|
|
24
|
+
/** 2.x options only. */
|
|
25
|
+
oauth?: never;
|
|
18
26
|
/** Return value of useConvexAuth() from convex/react */
|
|
19
27
|
useConvexAuth: () => {
|
|
20
28
|
isAuthenticated: boolean;
|
|
@@ -40,12 +48,47 @@ export interface ConvexAuthAdapterOptions {
|
|
|
40
48
|
*/
|
|
41
49
|
onListenerError?: ListenerErrorHandler;
|
|
42
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Options for `@convex-dev/auth` 2.x, where each sign-in method has its own
|
|
53
|
+
* hook. Call those hooks in the component and pass the functions they return.
|
|
54
|
+
* Only the methods passed can sign in; the others reject with PROVIDER_ERROR.
|
|
55
|
+
*/
|
|
56
|
+
export interface ConvexAuthV2AdapterOptions extends ConvexV2SignIns {
|
|
57
|
+
/** 0.0.x options only: its presence selects the 0.0.x shape. */
|
|
58
|
+
useAuthActions?: never;
|
|
59
|
+
/** `useAuthActions().signOut` from `@convex-dev/auth/react` 2.x. */
|
|
60
|
+
signOut: () => Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* `useSignInWithEmailPassword(api.auth).signIn` from
|
|
63
|
+
* `@convex-dev/auth/methods/email-password/react`, for `credentials` sign-in.
|
|
64
|
+
*/
|
|
65
|
+
signInWithPassword?: ConvexPasswordSignIn;
|
|
66
|
+
/**
|
|
67
|
+
* OAuth sign-in by provider id, the `provider` of an `oauth` sign-in: for
|
|
68
|
+
* example `{ github: useSignInWithGithub(api.auth).signIn }`.
|
|
69
|
+
*/
|
|
70
|
+
oauth?: Readonly<Record<string, ConvexOauthSignIn>>;
|
|
71
|
+
/** Return value of useConvexAuth() from convex/react */
|
|
72
|
+
useConvexAuth: () => {
|
|
73
|
+
isAuthenticated: boolean;
|
|
74
|
+
isLoading: boolean;
|
|
75
|
+
};
|
|
76
|
+
/** As in {@link ConvexAuthAdapterOptions.meQuery}. */
|
|
77
|
+
meQuery: () => User | null | undefined;
|
|
78
|
+
/** As in {@link ConvexAuthAdapterOptions.onListenerError}. */
|
|
79
|
+
onListenerError?: ListenerErrorHandler;
|
|
80
|
+
}
|
|
43
81
|
/**
|
|
44
82
|
* React hook that creates an AuthAdapter backed by Convex.
|
|
45
83
|
*
|
|
84
|
+
* Pass {@link ConvexAuthAdapterOptions} (`useAuthActions`) for
|
|
85
|
+
* `@convex-dev/auth` 0.0.x and {@link ConvexAuthV2AdapterOptions}
|
|
86
|
+
* (`signOut` and the method sign-in functions) for 2.x. Keep to one shape for
|
|
87
|
+
* the component's life: the 0.0.x shape calls `useAuthActions` as a hook.
|
|
88
|
+
*
|
|
46
89
|
* Must be called inside a ConvexProvider + ConvexAuthProvider tree. It returns
|
|
47
90
|
* the same adapter object on every render; the adapter always uses the latest
|
|
48
91
|
* actions and options passed to the hook.
|
|
49
92
|
*/
|
|
50
|
-
export declare function useConvexAuthAdapter(options: ConvexAuthAdapterOptions): AuthAdapter;
|
|
93
|
+
export declare function useConvexAuthAdapter(options: ConvexAuthAdapterOptions | ConvexAuthV2AdapterOptions): AuthAdapter;
|
|
51
94
|
//# sourceMappingURL=convex.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convex.d.ts","sourceRoot":"","sources":["../../src/adapters/convex.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"convex.d.ts","sourceRoot":"","sources":["../../src/adapters/convex.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,KAAK,oBAAoB,EAAoC,MAAM,iBAAiB,CAAC;AAE9F,OAAO,KAAK,EACX,WAAW,EAIX,IAAI,EACJ,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EAEpB,MAAM,gBAAgB,CAAC;AAMxB,2FAA2F;AAC3F,MAAM,WAAW,iBAAiB;IACjC,oEAAoE;IACpE,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAChF,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI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"}
|
package/dist/adapters/convex.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Convex auth adapter
|
|
3
3
|
*
|
|
4
|
-
* Bridges @convex-dev/auth React hooks to the AuthAdapter interface
|
|
4
|
+
* Bridges @convex-dev/auth React hooks to the AuthAdapter interface, for the
|
|
5
|
+
* 0.0.x line (`useAuthActions().signIn`) and the 2.x line (a hook per method).
|
|
5
6
|
* This is a React hook — must be called inside a component.
|
|
6
7
|
*/
|
|
7
8
|
import { useEffect, useRef, useState } from 'react';
|
|
@@ -9,22 +10,31 @@ import { AuthAdapterError, passkeyUnsupported } from '../errors.js';
|
|
|
9
10
|
import { ListenerSet, reportListenerError } from '../listeners.js';
|
|
10
11
|
import { areSessionStatesEqual, areUsersEqual } from '../session-state.js';
|
|
11
12
|
import { LOADING, UNAUTHENTICATED } from '../types.js';
|
|
13
|
+
import { signInWithConvexV2, } from './convex-v2.js';
|
|
12
14
|
import { describeThrown, isKnownNetworkFailure } from './provider-errors.js';
|
|
13
15
|
/** Id of `Password()` from `@convex-dev/auth/providers/Password`. */
|
|
14
16
|
const DEFAULT_PASSWORD_PROVIDER_ID = 'password';
|
|
15
17
|
/**
|
|
16
18
|
* React hook that creates an AuthAdapter backed by Convex.
|
|
17
19
|
*
|
|
20
|
+
* Pass {@link ConvexAuthAdapterOptions} (`useAuthActions`) for
|
|
21
|
+
* `@convex-dev/auth` 0.0.x and {@link ConvexAuthV2AdapterOptions}
|
|
22
|
+
* (`signOut` and the method sign-in functions) for 2.x. Keep to one shape for
|
|
23
|
+
* the component's life: the 0.0.x shape calls `useAuthActions` as a hook.
|
|
24
|
+
*
|
|
18
25
|
* Must be called inside a ConvexProvider + ConvexAuthProvider tree. It returns
|
|
19
26
|
* the same adapter object on every render; the adapter always uses the latest
|
|
20
27
|
* actions and options passed to the hook.
|
|
21
28
|
*/
|
|
22
29
|
export function useConvexAuthAdapter(options) {
|
|
23
|
-
const
|
|
30
|
+
const backend = isV2Options(options)
|
|
31
|
+
? { version: 2, options }
|
|
32
|
+
: // biome-ignore lint/correctness/useHookAtTopLevel: the options keep one shape for the component's life (see above), so this runs on every render or on none
|
|
33
|
+
{ version: 0, options, actions: options.useAuthActions() };
|
|
24
34
|
const { isAuthenticated, isLoading } = options.useConvexAuth();
|
|
25
35
|
const me = options.meQuery();
|
|
26
|
-
const latest = useRef(
|
|
27
|
-
latest.current =
|
|
36
|
+
const latest = useRef(backend);
|
|
37
|
+
latest.current = backend;
|
|
28
38
|
const stateRef = useRef(LOADING);
|
|
29
39
|
const notifiedStateRef = useRef(LOADING);
|
|
30
40
|
const [listeners] = useState(() => new ListenerSet((error) => reportListenerError(error, latest.current.options.onListenerError)));
|
|
@@ -42,10 +52,17 @@ export function useConvexAuthAdapter(options) {
|
|
|
42
52
|
}
|
|
43
53
|
}, [currentState, listeners]);
|
|
44
54
|
const [adapter] = useState(() => ({
|
|
45
|
-
signIn: (signInOptions) =>
|
|
55
|
+
signIn: (signInOptions) => {
|
|
56
|
+
const current = latest.current;
|
|
57
|
+
if (current.version === 2) {
|
|
58
|
+
return signInWithConvexV2(current.options, signInOptions, mapConvexError);
|
|
59
|
+
}
|
|
60
|
+
return signInWithConvex(current.actions, current.options.passwordProviderId ?? DEFAULT_PASSWORD_PROVIDER_ID, signInOptions);
|
|
61
|
+
},
|
|
46
62
|
signOut: async () => {
|
|
63
|
+
const current = latest.current;
|
|
47
64
|
try {
|
|
48
|
-
await
|
|
65
|
+
await (current.version === 2 ? current.options : current.actions).signOut();
|
|
49
66
|
}
|
|
50
67
|
catch (error) {
|
|
51
68
|
throw mapConvexError(error, false);
|
|
@@ -56,6 +73,9 @@ export function useConvexAuthAdapter(options) {
|
|
|
56
73
|
}));
|
|
57
74
|
return adapter;
|
|
58
75
|
}
|
|
76
|
+
function isV2Options(options) {
|
|
77
|
+
return options.useAuthActions === undefined;
|
|
78
|
+
}
|
|
59
79
|
function deriveState(previous, isLoading, isAuthenticated, me) {
|
|
60
80
|
if (isLoading)
|
|
61
81
|
return LOADING;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convex.js","sourceRoot":"","sources":["../../src/adapters/convex.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"convex.js","sourceRoot":"","sources":["../../src/adapters/convex.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAA6B,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQ3E,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAIN,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7E,qEAAqE;AACrE,MAAM,4BAA4B,GAAG,UAAU,CAAC;AAqEhD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CACnC,OAA8D;IAE9D,MAAM,OAAO,GAAkB,WAAW,CAAC,OAAO,CAAC;QAClD,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE;QACzB,CAAC,CAAC,4JAA4J;YAC7J,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;IAC7D,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAC/D,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAE7B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,C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AAK;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACpF,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,KAAc,EAAE,WAAoB;IAC3D,IAAI,KAAK,YAAY,gBAAgB;QAAE,OAAO,KAAK,CAAC;IAEpD,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,WAAW,IAAI,qDAAqD,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxF,OAAO,gBAAgB,CAAC,kBAAkB,EAAE,CAAC;IAC9C,CAAC;IACD,IAAI,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,OAAO,IAAI,gBAAgB,CAAC;YAC3B,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,mDAAmD;YAC5D,UAAU,EAAE,iDAAiD;SAC7D,CAAC,CAAC;IACJ,CAAC;IACD,IAAI,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;QAC3C,OAAO,gBAAgB,CAAC,YAAY,EAAE,CAAC;IACxC,CAAC;IACD,OAAO,gBAAgB,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -28,7 +28,9 @@ export interface AuthMiddlewareOptions {
|
|
|
28
28
|
* actor, never reads the session for it, deletes `context.auth` and runs the command.
|
|
29
29
|
*
|
|
30
30
|
* A host that serves MCP with token authorization through this middleware must pass it, or
|
|
31
|
-
* the session's user is stamped on every token's call
|
|
31
|
+
* the session's user is stamped on every token's call: afd-server's `createMcpServer` and
|
|
32
|
+
* `createMcpHandler` with `auth` refuse to be built with this middleware without it, in
|
|
33
|
+
* `middleware` directly or inside `composeMiddleware`. Without it, no call is treated so:
|
|
32
34
|
* every call is gated on the session, as before. `credentials` a caller put on the context
|
|
33
35
|
* itself (a direct-registry call, say) are never recognised, since only afd-server can mark
|
|
34
36
|
* them.
|
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAS,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI5E,OAAO,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,QAAQ,sBAAsB,CAAC;IACrC,UAAU,cAAc;QACvB;;;;;WAKG;QACH,IAAI,CAAC,EAAE,yBAAyB,CAAC;KACjC;CACD;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAS,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI5E,OAAO,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,QAAQ,sBAAsB,CAAC;IACrC,UAAU,cAAc;QACvB;;;;;WAKG;QACH,IAAI,CAAC,EAAE,yBAAyB,CAAC;KACjC;CACD;AAUD,MAAM,WAAW,qBAAqB;IACrC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,qBAAqB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAEvE;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;CACd;AAgBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CACnC,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,qBAA0B,GACjC,iBAAiB,CAkFnB"}
|
package/dist/middleware.js
CHANGED
|
@@ -5,6 +5,11 @@ import { failure } from '@lushly-dev/afd-core';
|
|
|
5
5
|
import { AUTH_COMMAND_NAMES } from './command-names.js';
|
|
6
6
|
import { isSessionExpired } from './session-state.js';
|
|
7
7
|
const SESSION_COMMANDS = new Set(AUTH_COMMAND_NAMES);
|
|
8
|
+
/**
|
|
9
|
+
* Registered, so afd-server (from any installed copy) can see whether this middleware was given
|
|
10
|
+
* `isVerifiedCredentials`, and refuse a server with `auth` that runs it without.
|
|
11
|
+
*/
|
|
12
|
+
const CREDENTIALS_MARK = Symbol.for('dev.afd/auth-middleware-credentials');
|
|
8
13
|
/**
|
|
9
14
|
* The actor for a call made with a verified session. A human (or unset) actor becomes the
|
|
10
15
|
* session user (`id`, and `label` from the user's name). An agent, service or script keeps
|
|
@@ -36,7 +41,7 @@ function actorForSession(actor, session) {
|
|
|
36
41
|
export function createAuthMiddleware(adapter, options = {}) {
|
|
37
42
|
const excluded = new Set([...AUTH_COMMAND_NAMES, ...(options.exclude ?? [])]);
|
|
38
43
|
const { isVerifiedCredentials, clock } = options;
|
|
39
|
-
|
|
44
|
+
const middleware = async (commandName, _input, context, next) => {
|
|
40
45
|
const now = clock ? clock.now() : Date.now();
|
|
41
46
|
if (context.credentials !== undefined && isVerifiedCredentials !== undefined) {
|
|
42
47
|
if (isVerifiedCredentials(context.credentials, now) === true) {
|
|
@@ -90,16 +95,20 @@ export function createAuthMiddleware(adapter, options = {}) {
|
|
|
90
95
|
return failure({
|
|
91
96
|
code: 'TOKEN_EXPIRED',
|
|
92
97
|
message: 'Session has expired',
|
|
93
|
-
suggestion: 'Try again once the auth provider has refreshed the session, or sign in again with auth-sign-in',
|
|
98
|
+
suggestion: 'Try again once the auth provider has refreshed the session, or sign in again with auth-sign-in (an agent asks the person to)',
|
|
94
99
|
retryable: true,
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
102
|
return failure({
|
|
98
103
|
code: 'UNAUTHORIZED',
|
|
99
104
|
message: 'Authentication required',
|
|
100
|
-
suggestion: 'Sign in with auth-sign-in to access this command',
|
|
105
|
+
suggestion: 'Sign in with auth-sign-in to access this command; an agent asks the person to sign in, then calls again',
|
|
101
106
|
retryable: false,
|
|
102
107
|
});
|
|
103
108
|
};
|
|
109
|
+
Object.defineProperty(middleware, CREDENTIALS_MARK, {
|
|
110
|
+
value: { recognisesVerifiedCredentials: isVerifiedCredentials !== undefined },
|
|
111
|
+
});
|
|
112
|
+
return middleware;
|
|
104
113
|
}
|
|
105
114
|
//# sourceMappingURL=middleware.js.map
|
package/dist/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAetD,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAetD,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;AAgD3E;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAwB,EAAE,OAAkC;IACpF,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzB,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC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ACf,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,eAAe,EAAE,CAAC;YACtC,OAAO,OAAO,CAAC;gBACd,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,qBAAqB;gBAC9B,UAAU,EACT,8HAA8H;gBAC/H,SAAS,EAAE,IAAI;aACf,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,OAAO,CAAC;YACd,IAAI,EAAE,cAAc;YACpB,OAAO,EAAE,yBAAyB;YAClC,UAAU,EACT,yGAAyG;YAC1G,SAAS,EAAE,KAAK;SAChB,CAAC,CAAC;IACJ,CAAC,CAAC;IACF,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,gBAAgB,EAAE;QACnD,KAAK,EAAE,EAAE,6BAA6B,EAAE,qBAAqB,KAAK,SAAS,EAAE;KAC7E,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-commands.d.ts","sourceRoot":"","sources":["../src/mutation-commands.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAIN,KAAK,oBAAoB,EACzB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,WAAW,EAAkD,MAAM,YAAY,CAAC;AAE9F,MAAM,WAAW,mBAAmB;IACnC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAyBD;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,mBAAwB,GAC/B,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"mutation-commands.d.ts","sourceRoot":"","sources":["../src/mutation-commands.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAIN,KAAK,oBAAoB,EACzB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,WAAW,EAAkD,MAAM,YAAY,CAAC;AAE9F,MAAM,WAAW,mBAAmB;IACnC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAyBD;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,mBAAwB,GAC/B,oBAAoB,EAAE,CAiHxB"}
|
|
@@ -40,7 +40,11 @@ export function createAuthMutationCommands(adapter, options = {}) {
|
|
|
40
40
|
category: 'auth',
|
|
41
41
|
tags: ['auth', 'session'],
|
|
42
42
|
mutation: true,
|
|
43
|
-
|
|
43
|
+
// It takes a password: no journal records it without a `redact` that removes it.
|
|
44
|
+
secret: true,
|
|
45
|
+
// A person signs in: an agent is never handed a password or a sign-in to drive, so the
|
|
46
|
+
// command is not on the agent surface. An agent asks the person to sign in instead.
|
|
47
|
+
expose: { palette: true, agent: false, cli: true, mcp: false },
|
|
44
48
|
input: signInInput,
|
|
45
49
|
jsonSchema: {
|
|
46
50
|
type: 'object',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-commands.js","sourceRoot":"","sources":["../src/mutation-commands.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oFAAoF;AACpF,OAAO,EACN,uBAAuB,EACvB,OAAO,EACP,OAAO,GAEP,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAa3D,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,sBAAsB,GAAG,8DAA8D,CAAC;AAE9F,MAAM,WAAW,GAAG,CAAC,CAAC,kBAAkB,CAAC,QAAQ,EAAE;IAClD,CAAC,CAAC,MAAM,CAAC;QACR,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;QAChC,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE;QAChB,QAA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d.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Sub-path export: import from '@lushly-dev/afd-auth/react'
|
|
5
5
|
*/
|
|
6
6
|
import type { AuthAdapter, AuthSessionState, User } from './types.js';
|
|
7
|
-
export type { ConvexAuthAdapterOptions } from './adapters/convex.js';
|
|
7
|
+
export type { ConvexAuthAdapterOptions, ConvexAuthV2AdapterOptions, } from './adapters/convex.js';
|
|
8
8
|
export { useConvexAuthAdapter } from './adapters/convex.js';
|
|
9
|
+
export type { ConvexOauthSignIn, ConvexOauthStartResult, ConvexPasswordSignIn, ConvexPasswordSignInResult, } from './adapters/convex-v2.js';
|
|
9
10
|
export interface AuthHooks {
|
|
10
11
|
useAuth: () => AuthAdapter;
|
|
11
12
|
useSession: () => AuthSessionState;
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGtE,YAAY,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGtE,YAAY,EACX,wBAAwB,EACxB,0BAA0B,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,YAAY,EACX,iBAAiB,EACjB,sBAAsB,EACtB,oBAAoB,EACpB,0BAA0B,GAC1B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,SAAS;IACzB,OAAO,EAAE,MAAM,WAAW,CAAC;IAC3B,UAAU,EAAE,MAAM,gBAAgB,CAAC;IACnC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAyC/D"}
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,sKAAsK;AAEtK,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,sKAAsK;AAEtK,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAMrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAc5D;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAoB;IACnD,yEAAyE;IACzE,6EAA6E;IAC7E,uDAAuD;IACvD,IAAI,cAA4C,CAAC;IACjD,MAAM,YAAY,GAAG,GAAqB,EAAE;QAC3C,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QAC1C,IAAI,cAAc,IAAI,qBAAqB,CAAC,cAAc,EAAE,YAAY,CAAC,EAAE,CAAC;YAC3E,OAAO,cAAc,CAAC;QACvB,CAAC;QACD,cAAc,GAAG,YAAY,CAAC;QAC9B,OAAO,YAAY,CAAC;IACrB,CAAC,CAAC;IAEF,SAAS,OAAO;QACf,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,SAAS,UAAU;QAClB,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,aAAyB,EAAE,EAAE;YAC3D,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG,EAAE;gBACtD,aAAa,EAAE,CAAC;YACjB,CAAC,CAAC,CAAC;YACH,OAAO,WAAW,CAAC;QACpB,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,sEAAsE;QACtE,wEAAwE;QACxE,sEAAsE;QACtE,MAAM,WAAW,GAAG,WAAW,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAClD,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAEzD,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;IACxE,CAAC;IAED,SAAS,OAAO;QACf,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC,MAAM,KAAK,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared Node-only test-host primitives for Better Auth fixtures (`@lushly-dev/afd-auth/testing`).
|
|
3
|
+
*
|
|
4
|
+
* Used by both `packages/auth/hosted/better-auth` and `@lushly-dev/loam-identity/testing` to manage
|
|
5
|
+
* disposable child-process auth servers, scratch directories, loopback ports, SQLite databases and
|
|
6
|
+
* HTTP/HTTPS listeners. Never imported from browser entries.
|
|
7
|
+
*/
|
|
8
|
+
import { type ChildProcess } from 'node:child_process';
|
|
9
|
+
import { type Server as HttpServer, type RequestListener } from 'node:http';
|
|
10
|
+
import { type Server as HttpsServer } from 'node:https';
|
|
11
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
12
|
+
/** IPC message sent by a test-host child once startup settles. */
|
|
13
|
+
export type TestHostReadyMessage<TPayload extends object = Record<string, unknown>> = ({
|
|
14
|
+
ready: true;
|
|
15
|
+
} & TPayload) | {
|
|
16
|
+
ready: false;
|
|
17
|
+
message?: string;
|
|
18
|
+
};
|
|
19
|
+
/** Options for starting a single test-host child process and awaiting its IPC ready message. */
|
|
20
|
+
export interface StartTestHostChildOptions {
|
|
21
|
+
/** Absolute path to the child entry script. */
|
|
22
|
+
entryPath: string;
|
|
23
|
+
/** Environment variable name used to pass the serialized JSON configuration to the child. */
|
|
24
|
+
envVar: string;
|
|
25
|
+
/** JSON-serializable configuration passed to the child via `envVar`. */
|
|
26
|
+
config: unknown;
|
|
27
|
+
/** Maximum milliseconds to wait for the child's ready message. */
|
|
28
|
+
timeoutMs: number;
|
|
29
|
+
/** Optional abort signal to cancel startup. */
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/** Optional working directory for the child process. */
|
|
32
|
+
cwd?: string;
|
|
33
|
+
/** Optional Node execArgv passed to `fork`. */
|
|
34
|
+
execArgv?: string[];
|
|
35
|
+
/** Base environment for the child process. Defaults to `process.env`. */
|
|
36
|
+
env?: NodeJS.ProcessEnv;
|
|
37
|
+
/** Prefix for startup error messages (never includes config or secrets). */
|
|
38
|
+
errorPrefix?: string;
|
|
39
|
+
/** Grace period in milliseconds between SIGTERM and SIGKILL when stopping a failed child. */
|
|
40
|
+
graceMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/** Context supplied to {@link StartManagedTestHostOptions.prepare}. */
|
|
43
|
+
export interface ManagedTestHostContext {
|
|
44
|
+
readonly port: number;
|
|
45
|
+
readonly scratch: string;
|
|
46
|
+
readonly databasePath: string;
|
|
47
|
+
}
|
|
48
|
+
/** Options for {@link startManagedTestHost}. */
|
|
49
|
+
export interface StartManagedTestHostOptions<TConfig> {
|
|
50
|
+
/** Prefix passed to `mkdtemp` in the OS temporary directory. */
|
|
51
|
+
scratchPrefix: string;
|
|
52
|
+
/** Filename of the SQLite database inside the scratch directory. Defaults to `auth.sqlite`. */
|
|
53
|
+
databaseFilename?: string;
|
|
54
|
+
/** Loopback host for port allocation. Defaults to `127.0.0.1`. */
|
|
55
|
+
host?: string;
|
|
56
|
+
/** Absolute path to the child entry script. */
|
|
57
|
+
entryPath: string;
|
|
58
|
+
/** Environment variable name used to pass the serialized JSON configuration to the child. */
|
|
59
|
+
envVar: string;
|
|
60
|
+
/** Maximum milliseconds to wait for the child's ready message. */
|
|
61
|
+
timeoutMs: number;
|
|
62
|
+
/** Optional abort signal to cancel preparation, startup or restart. */
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
/** Optional working directory for the child process. */
|
|
65
|
+
cwd?: string;
|
|
66
|
+
/** Optional Node execArgv passed to `fork`. */
|
|
67
|
+
execArgv?: string[];
|
|
68
|
+
/** Base environment for the child process. Defaults to `process.env`. */
|
|
69
|
+
env?: NodeJS.ProcessEnv;
|
|
70
|
+
/** Prefix for startup error messages (never includes config or secrets). */
|
|
71
|
+
errorPrefix?: string;
|
|
72
|
+
/** Grace period in milliseconds between SIGTERM and SIGKILL when stopping the child. */
|
|
73
|
+
graceMs?: number;
|
|
74
|
+
/** Build the child configuration once the scratch directory and loopback port are allocated. */
|
|
75
|
+
prepare(context: ManagedTestHostContext): Promise<TConfig> | TConfig;
|
|
76
|
+
/** Optional cleanup hook run in `close()` (and on startup failure) before removing the scratch directory. */
|
|
77
|
+
onClose?: () => Promise<void> | void;
|
|
78
|
+
}
|
|
79
|
+
/** Running test host with restart and idempotent scratch cleanup. */
|
|
80
|
+
export interface ManagedTestHost<TPayload extends object = Record<string, unknown>> {
|
|
81
|
+
readonly port: number;
|
|
82
|
+
readonly scratch: string;
|
|
83
|
+
readonly databasePath: string;
|
|
84
|
+
readonly ready: {
|
|
85
|
+
ready: true;
|
|
86
|
+
} & TPayload;
|
|
87
|
+
/** Stop the current child and start a new one against the same scratch directory and config. */
|
|
88
|
+
restart(timeoutMs?: number): Promise<{
|
|
89
|
+
ready: true;
|
|
90
|
+
} & TPayload>;
|
|
91
|
+
/** Stop the child, invoke `onClose`, and remove the scratch directory. Idempotent. */
|
|
92
|
+
close(): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/** Options for {@link listenTestHttpServer}. */
|
|
95
|
+
export interface ListenTestHttpServerOptions {
|
|
96
|
+
port: number;
|
|
97
|
+
host?: string;
|
|
98
|
+
handler: RequestListener;
|
|
99
|
+
tls?: {
|
|
100
|
+
cert: Buffer | string;
|
|
101
|
+
key: Buffer | string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Listening HTTP or HTTPS test server with connection-draining shutdown. */
|
|
105
|
+
export interface ListeningTestServer {
|
|
106
|
+
readonly server: HttpServer | HttpsServer;
|
|
107
|
+
close(): Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
/** Runtime hooks for {@link runTestHostChild}, exposed so tests can exercise signal and IPC branches in-process. */
|
|
110
|
+
export interface TestHostChildRuntime {
|
|
111
|
+
env: NodeJS.ProcessEnv;
|
|
112
|
+
send(message: TestHostReadyMessage): void;
|
|
113
|
+
onSignal(signal: 'SIGTERM' | 'SIGINT', listener: () => void): void;
|
|
114
|
+
exit(code: number): void;
|
|
115
|
+
setExitCode(code: number): void;
|
|
116
|
+
}
|
|
117
|
+
/** Options for {@link runTestHostChild}. */
|
|
118
|
+
export interface RunTestHostChildOptions<TConfig, TPayload extends object = Record<string, unknown>> {
|
|
119
|
+
/** Environment variable holding the JSON-serialized configuration. Deleted immediately after reading. */
|
|
120
|
+
envVar: string;
|
|
121
|
+
/** Start the child server and return its ready payload and shutdown callback. */
|
|
122
|
+
start(config: TConfig): Promise<{
|
|
123
|
+
payload: TPayload;
|
|
124
|
+
close(): Promise<void> | void;
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Whether to include the caught error message in `{ ready: false, message }`.
|
|
128
|
+
* Defaults to `false` so fixtures that handle sensitive config cannot leak it over IPC.
|
|
129
|
+
*/
|
|
130
|
+
includeErrorMessage?: boolean;
|
|
131
|
+
/** Optional process hooks, for unit testing. */
|
|
132
|
+
runtime?: TestHostChildRuntime;
|
|
133
|
+
}
|
|
134
|
+
/** Reserve an ephemeral TCP port on loopback (default `127.0.0.1`) and release it for the child to bind. */
|
|
135
|
+
export declare function allocateLoopbackPort(host?: string): Promise<number>;
|
|
136
|
+
/** Stop a child process with SIGTERM, escalating to SIGKILL after `graceMs` (default 1,000 ms). */
|
|
137
|
+
export declare function stopTestHostChild(child: ChildProcess, graceMs?: number): Promise<void>;
|
|
138
|
+
/** Fork a test-host child process, wait for its IPC ready message, and stop it if startup fails. */
|
|
139
|
+
export declare function startTestHostChild<TPayload extends object = Record<string, unknown>>(options: StartTestHostChildOptions): Promise<{
|
|
140
|
+
child: ChildProcess;
|
|
141
|
+
ready: {
|
|
142
|
+
ready: true;
|
|
143
|
+
} & TPayload;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Allocate a scratch directory and loopback port, prepare a child configuration, fork the test-host
|
|
147
|
+
* child, and return a handle with `restart()` and idempotent `close()`. Any failure during
|
|
148
|
+
* preparation or startup stops the child, runs `onClose`, and removes the scratch directory.
|
|
149
|
+
*/
|
|
150
|
+
export declare function startManagedTestHost<TConfig, TPayload extends object = Record<string, unknown>>(options: StartManagedTestHostOptions<TConfig>): Promise<ManagedTestHost<TPayload>>;
|
|
151
|
+
/**
|
|
152
|
+
* Open a test SQLite database via `node:sqlite`, enabling WAL mode and foreign keys.
|
|
153
|
+
* Loaded lazily so other helpers in this module work on Node 22.12; calling this helper
|
|
154
|
+
* requires Node 22.13+ (or 24+ without experimental warnings).
|
|
155
|
+
*/
|
|
156
|
+
export declare function openTestSqliteDatabase(databasePath: string): DatabaseSync;
|
|
157
|
+
/** Start an HTTP or HTTPS test server and return a handle whose `close()` drains all connections. */
|
|
158
|
+
export declare function listenTestHttpServer(options: ListenTestHttpServerOptions): Promise<ListeningTestServer>;
|
|
159
|
+
/**
|
|
160
|
+
* Bootstrap a forked test-host child process: read and immediately scrub its JSON config from
|
|
161
|
+
* `envVar`, run `start(config)`, register idempotent SIGTERM/SIGINT shutdown handlers, and notify
|
|
162
|
+
* the parent via IPC.
|
|
163
|
+
*/
|
|
164
|
+
export declare function runTestHostChild<TConfig, TPayload extends object = Record<string, unknown>>(options: RunTestHostChildOptions<TConfig, TPayload>): Promise<void>;
|
|
165
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAQ,MAAM,oBAAoB,CAAC;AAG7D,OAAO,EAEN,KAAK,MAAM,IAAI,UAAU,EACzB,KAAK,eAAe,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAqC,KAAK,MAAM,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AAK3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,kEAAkE;AAClE,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC/E,CAAC;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG,QAAQ,CAAC,GAC5B;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,gGAAgG;AAChG,MAAM,WAAW,yBAAyB;IACzC,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,6FAA6F;IAC7F,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,MAAM,EAAE,OAAO,CAAC;IAChB,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,wDAAwD;IACxD,GAAG,CAAC,EAAE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AAQ,CAAC,CAAC,CAoGnF;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CAYzE;AAED,qGAAqG;AACrG,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,2BAA2B,GAClC,OAAO,CAAC,mBAAmB,CAAC,CAkB9B;AAkBD;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,QAAQ,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChG,OAAO,EAAE,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,GACjD,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared Node-only test-host primitives for Better Auth fixtures (`@lushly-dev/afd-auth/testing`).
|
|
3
|
+
*
|
|
4
|
+
* Used by both `packages/auth/hosted/better-auth` and `@lushly-dev/loam-identity/testing` to manage
|
|
5
|
+
* disposable child-process auth servers, scratch directories, loopback ports, SQLite databases and
|
|
6
|
+
* HTTP/HTTPS listeners. Never imported from browser entries.
|
|
7
|
+
*/
|
|
8
|
+
import { fork } from 'node:child_process';
|
|
9
|
+
import { once } from 'node:events';
|
|
10
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
11
|
+
import { createServer as createHttpServer, } from 'node:http';
|
|
12
|
+
import { createServer as createHttpsServer } from 'node:https';
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
import { createServer as createNetServer } from 'node:net';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { join, resolve } from 'node:path';
|
|
17
|
+
const requireModule = createRequire(import.meta.url);
|
|
18
|
+
/** Reserve an ephemeral TCP port on loopback (default `127.0.0.1`) and release it for the child to bind. */
|
|
19
|
+
export async function allocateLoopbackPort(host = '127.0.0.1') {
|
|
20
|
+
const socket = createNetServer();
|
|
21
|
+
socket.listen(0, host);
|
|
22
|
+
await once(socket, 'listening');
|
|
23
|
+
const address = socket.address();
|
|
24
|
+
await new Promise((done) => socket.close(() => done()));
|
|
25
|
+
if (!address || typeof address === 'string')
|
|
26
|
+
throw new Error('Port allocation failed');
|
|
27
|
+
return address.port;
|
|
28
|
+
}
|
|
29
|
+
/** Stop a child process with SIGTERM, escalating to SIGKILL after `graceMs` (default 1,000 ms). */
|
|
30
|
+
export async function stopTestHostChild(child, graceMs = 1_000) {
|
|
31
|
+
if (!child.pid || child.exitCode !== null || child.signalCode !== null)
|
|
32
|
+
return;
|
|
33
|
+
const exited = once(child, 'exit');
|
|
34
|
+
child.kill('SIGTERM');
|
|
35
|
+
const timer = setTimeout(() => child.kill('SIGKILL'), graceMs);
|
|
36
|
+
try {
|
|
37
|
+
await exited;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Fork a test-host child process, wait for its IPC ready message, and stop it if startup fails. */
|
|
44
|
+
export async function startTestHostChild(options) {
|
|
45
|
+
const prefix = options.errorPrefix ?? 'Test host startup';
|
|
46
|
+
if (options.signal?.aborted)
|
|
47
|
+
throw new Error(`${prefix} interrupted`);
|
|
48
|
+
const child = fork(options.entryPath, [], {
|
|
49
|
+
...(options.cwd ? { cwd: options.cwd } : {}),
|
|
50
|
+
...(options.execArgv ? { execArgv: options.execArgv } : {}),
|
|
51
|
+
env: { ...(options.env ?? process.env), [options.envVar]: JSON.stringify(options.config) },
|
|
52
|
+
stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
const ready = await new Promise((resolveReady, reject) => {
|
|
56
|
+
let settled = false;
|
|
57
|
+
const finish = (action) => {
|
|
58
|
+
if (settled)
|
|
59
|
+
return;
|
|
60
|
+
settled = true;
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
63
|
+
child.off('error', onError);
|
|
64
|
+
child.off('exit', onExit);
|
|
65
|
+
child.off('message', onMessage);
|
|
66
|
+
action();
|
|
67
|
+
};
|
|
68
|
+
const onAbort = () => finish(() => reject(new Error(`${prefix} interrupted`)));
|
|
69
|
+
const onError = () => finish(() => reject(new Error(`${prefix} launch failed`)));
|
|
70
|
+
const onExit = () => finish(() => reject(new Error(`${prefix} exited before ready`)));
|
|
71
|
+
const onMessage = (message) => {
|
|
72
|
+
finish(() => {
|
|
73
|
+
if (message?.ready) {
|
|
74
|
+
resolveReady(message);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const detail = message && !message.ready && typeof message.message === 'string' && message.message
|
|
78
|
+
? `: ${message.message}`
|
|
79
|
+
: ' failed';
|
|
80
|
+
reject(new Error(`${prefix}${detail}`));
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const timer = setTimeout(() => finish(() => reject(new Error(`${prefix} deadline`))), options.timeoutMs);
|
|
84
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
85
|
+
child.once('error', onError);
|
|
86
|
+
child.once('exit', onExit);
|
|
87
|
+
child.once('message', onMessage);
|
|
88
|
+
});
|
|
89
|
+
return { child, ready };
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const ignoreLateError = () => { };
|
|
93
|
+
child.on('error', ignoreLateError);
|
|
94
|
+
try {
|
|
95
|
+
await stopTestHostChild(child, options.graceMs);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
child.off('error', ignoreLateError);
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Allocate a scratch directory and loopback port, prepare a child configuration, fork the test-host
|
|
105
|
+
* child, and return a handle with `restart()` and idempotent `close()`. Any failure during
|
|
106
|
+
* preparation or startup stops the child, runs `onClose`, and removes the scratch directory.
|
|
107
|
+
*/
|
|
108
|
+
export async function startManagedTestHost(options) {
|
|
109
|
+
options.signal?.throwIfAborted();
|
|
110
|
+
const scratch = await mkdtemp(resolve(tmpdir(), options.scratchPrefix));
|
|
111
|
+
const databasePath = join(scratch, options.databaseFilename ?? 'auth.sqlite');
|
|
112
|
+
const closeController = new AbortController();
|
|
113
|
+
const startSignal = options.signal
|
|
114
|
+
? AbortSignal.any([options.signal, closeController.signal])
|
|
115
|
+
: closeController.signal;
|
|
116
|
+
let child;
|
|
117
|
+
let pendingRestart;
|
|
118
|
+
let closePromise;
|
|
119
|
+
let config;
|
|
120
|
+
const close = () => {
|
|
121
|
+
closePromise ??= (async () => {
|
|
122
|
+
closeController.abort();
|
|
123
|
+
try {
|
|
124
|
+
await pendingRestart?.catch(() => { });
|
|
125
|
+
if (child) {
|
|
126
|
+
const running = child;
|
|
127
|
+
child = undefined;
|
|
128
|
+
await stopTestHostChild(running, options.graceMs);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
try {
|
|
133
|
+
await options.onClose?.();
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
await rm(scratch, { recursive: true, force: true });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
return closePromise;
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
const port = await allocateLoopbackPort(options.host);
|
|
144
|
+
options.signal?.throwIfAborted();
|
|
145
|
+
config = await options.prepare({ port, scratch, databasePath });
|
|
146
|
+
options.signal?.throwIfAborted();
|
|
147
|
+
const start = (timeoutMs) => startTestHostChild({
|
|
148
|
+
entryPath: options.entryPath,
|
|
149
|
+
envVar: options.envVar,
|
|
150
|
+
config,
|
|
151
|
+
timeoutMs,
|
|
152
|
+
signal: startSignal,
|
|
153
|
+
...(options.cwd ? { cwd: options.cwd } : {}),
|
|
154
|
+
...(options.execArgv ? { execArgv: options.execArgv } : {}),
|
|
155
|
+
...(options.env ? { env: options.env } : {}),
|
|
156
|
+
...(options.errorPrefix ? { errorPrefix: options.errorPrefix } : {}),
|
|
157
|
+
...(options.graceMs !== undefined ? { graceMs: options.graceMs } : {}),
|
|
158
|
+
});
|
|
159
|
+
const started = await start(options.timeoutMs);
|
|
160
|
+
child = started.child;
|
|
161
|
+
options.signal?.throwIfAborted();
|
|
162
|
+
let currentReady = started.ready;
|
|
163
|
+
return {
|
|
164
|
+
port,
|
|
165
|
+
scratch,
|
|
166
|
+
databasePath,
|
|
167
|
+
get ready() {
|
|
168
|
+
return currentReady;
|
|
169
|
+
},
|
|
170
|
+
restart(timeoutMs = options.timeoutMs) {
|
|
171
|
+
if (closePromise)
|
|
172
|
+
return Promise.reject(new Error('Test host is closed'));
|
|
173
|
+
if (pendingRestart) {
|
|
174
|
+
return Promise.reject(new Error('Test host restart already in progress'));
|
|
175
|
+
}
|
|
176
|
+
const run = (async () => {
|
|
177
|
+
try {
|
|
178
|
+
if (child) {
|
|
179
|
+
const previous = child;
|
|
180
|
+
child = undefined;
|
|
181
|
+
await stopTestHostChild(previous, options.graceMs);
|
|
182
|
+
}
|
|
183
|
+
if (closePromise)
|
|
184
|
+
throw new Error('Test host is closed');
|
|
185
|
+
const restarted = await start(timeoutMs);
|
|
186
|
+
if (closePromise) {
|
|
187
|
+
await stopTestHostChild(restarted.child, options.graceMs);
|
|
188
|
+
throw new Error('Test host is closed');
|
|
189
|
+
}
|
|
190
|
+
child = restarted.child;
|
|
191
|
+
currentReady = restarted.ready;
|
|
192
|
+
return currentReady;
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
pendingRestart = undefined;
|
|
196
|
+
}
|
|
197
|
+
})();
|
|
198
|
+
pendingRestart = run;
|
|
199
|
+
return run;
|
|
200
|
+
},
|
|
201
|
+
close,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
await close();
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Open a test SQLite database via `node:sqlite`, enabling WAL mode and foreign keys.
|
|
211
|
+
* Loaded lazily so other helpers in this module work on Node 22.12; calling this helper
|
|
212
|
+
* requires Node 22.13+ (or 24+ without experimental warnings).
|
|
213
|
+
*/
|
|
214
|
+
export function openTestSqliteDatabase(databasePath) {
|
|
215
|
+
const { DatabaseSync: SqliteDatabaseSync } = requireModule('node:sqlite');
|
|
216
|
+
const database = new SqliteDatabaseSync(databasePath);
|
|
217
|
+
try {
|
|
218
|
+
database.exec('PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;');
|
|
219
|
+
return database;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
database.close();
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/** Start an HTTP or HTTPS test server and return a handle whose `close()` drains all connections. */
|
|
227
|
+
export async function listenTestHttpServer(options) {
|
|
228
|
+
const server = options.tls
|
|
229
|
+
? createHttpsServer(options.tls, options.handler)
|
|
230
|
+
: createHttpServer(options.handler);
|
|
231
|
+
await new Promise((resolveListening, reject) => {
|
|
232
|
+
server.once('error', reject);
|
|
233
|
+
server.listen(options.port, options.host ?? '127.0.0.1', () => {
|
|
234
|
+
server.off('error', reject);
|
|
235
|
+
resolveListening();
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
return {
|
|
239
|
+
server,
|
|
240
|
+
async close() {
|
|
241
|
+
server.closeAllConnections();
|
|
242
|
+
await new Promise((resolveClose) => server.close(() => resolveClose()));
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
const defaultChildRuntime = {
|
|
247
|
+
env: process.env,
|
|
248
|
+
send: (message) => {
|
|
249
|
+
process.send?.(message);
|
|
250
|
+
},
|
|
251
|
+
onSignal: (signal, listener) => {
|
|
252
|
+
process.once(signal, listener);
|
|
253
|
+
},
|
|
254
|
+
exit: (code) => {
|
|
255
|
+
process.exit(code);
|
|
256
|
+
},
|
|
257
|
+
setExitCode: (code) => {
|
|
258
|
+
process.exitCode = code;
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Bootstrap a forked test-host child process: read and immediately scrub its JSON config from
|
|
263
|
+
* `envVar`, run `start(config)`, register idempotent SIGTERM/SIGINT shutdown handlers, and notify
|
|
264
|
+
* the parent via IPC.
|
|
265
|
+
*/
|
|
266
|
+
export async function runTestHostChild(options) {
|
|
267
|
+
const runtime = options.runtime ?? defaultChildRuntime;
|
|
268
|
+
try {
|
|
269
|
+
const raw = runtime.env[options.envVar] ?? '';
|
|
270
|
+
delete runtime.env[options.envVar];
|
|
271
|
+
const config = JSON.parse(raw);
|
|
272
|
+
const started = await options.start(config);
|
|
273
|
+
let closing = false;
|
|
274
|
+
const shutdown = () => {
|
|
275
|
+
if (closing)
|
|
276
|
+
return;
|
|
277
|
+
closing = true;
|
|
278
|
+
void Promise.resolve()
|
|
279
|
+
.then(() => started.close())
|
|
280
|
+
.catch(() => { })
|
|
281
|
+
.finally(() => runtime.exit(0));
|
|
282
|
+
};
|
|
283
|
+
runtime.onSignal('SIGTERM', shutdown);
|
|
284
|
+
runtime.onSignal('SIGINT', shutdown);
|
|
285
|
+
runtime.send({ ...started.payload, ready: true });
|
|
286
|
+
}
|
|
287
|
+
catch (cause) {
|
|
288
|
+
runtime.send(options.includeErrorMessage
|
|
289
|
+
? { ready: false, message: String(cause?.message ?? cause) }
|
|
290
|
+
: { ready: false });
|
|
291
|
+
runtime.setExitCode(1);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAqB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAA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1.0",
|
|
4
4
|
"description": "Provider-agnostic authentication adapter for AFD applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"./mock-capabilities": {
|
|
22
22
|
"types": "./dist/mock-capabilities.d.ts",
|
|
23
23
|
"import": "./dist/mock-capabilities.js"
|
|
24
|
+
},
|
|
25
|
+
"./testing": {
|
|
26
|
+
"types": "./dist/testing/index.d.ts",
|
|
27
|
+
"import": "./dist/testing/index.js"
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
@@ -28,15 +32,15 @@
|
|
|
28
32
|
"README.md"
|
|
29
33
|
],
|
|
30
34
|
"dependencies": {
|
|
31
|
-
"@lushly-dev/afd-core": "
|
|
35
|
+
"@lushly-dev/afd-core": "3.1.0"
|
|
32
36
|
},
|
|
33
37
|
"peerDependencies": {
|
|
34
38
|
"@better-auth/passkey": "^1.7.18",
|
|
35
|
-
"@convex-dev/auth": ">=0.0.95",
|
|
36
|
-
"@lushly-dev/afd-server": "^
|
|
39
|
+
"@convex-dev/auth": ">=0.0.95 <3",
|
|
40
|
+
"@lushly-dev/afd-server": "^3.1.0",
|
|
37
41
|
"better-auth": "^1.7.18",
|
|
38
42
|
"react": "^18.0.0 || ^19.0.0",
|
|
39
|
-
"zod": "^4.
|
|
43
|
+
"zod": "^4.6.6"
|
|
40
44
|
},
|
|
41
45
|
"peerDependenciesMeta": {
|
|
42
46
|
"@lushly-dev/afd-server": {
|
|
@@ -60,21 +64,23 @@
|
|
|
60
64
|
},
|
|
61
65
|
"devDependencies": {
|
|
62
66
|
"@auth/core": "^0.41.3",
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
67
|
+
"@convex-dev/auth": "2.1.0",
|
|
68
|
+
"@convex-dev/auth-v0": "npm:@convex-dev/auth@0.0.96",
|
|
69
|
+
"@better-auth/passkey": "1.7.28",
|
|
70
|
+
"@lushly-dev/afd-server": "3.1.0",
|
|
65
71
|
"@testing-library/react": "^16.3.3",
|
|
66
|
-
"@types/react": "^19.3.
|
|
72
|
+
"@types/react": "^19.3.3",
|
|
67
73
|
"@types/react-dom": "19.3.0",
|
|
68
|
-
"@vitest/coverage-v8": "^5.1.
|
|
69
|
-
"better-auth": "1.7.
|
|
70
|
-
"convex": "1.
|
|
74
|
+
"@vitest/coverage-v8": "^5.1.2",
|
|
75
|
+
"better-auth": "1.7.28",
|
|
76
|
+
"convex": "1.51.0",
|
|
71
77
|
"esbuild": "0.28.2",
|
|
72
78
|
"jsdom": "^31.0.1",
|
|
73
|
-
"playwright": "1.
|
|
79
|
+
"playwright": "1.65.1",
|
|
74
80
|
"react": "^19.3.0",
|
|
75
81
|
"react-dom": "^19.3.0",
|
|
76
82
|
"typescript": "^7.0.2",
|
|
77
|
-
"vitest": "^5.1.
|
|
83
|
+
"vitest": "^5.1.2",
|
|
78
84
|
"zod": "^4.6.6"
|
|
79
85
|
},
|
|
80
86
|
"keywords": [
|
|
@@ -103,7 +109,7 @@
|
|
|
103
109
|
"access": "public"
|
|
104
110
|
},
|
|
105
111
|
"scripts": {
|
|
106
|
-
"build": "tsc",
|
|
112
|
+
"build": "tsc && tsc -p tsconfig.testing.json",
|
|
107
113
|
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
108
114
|
"dev": "tsc --watch",
|
|
109
115
|
"test": "vitest run",
|