@ultimat3/cli 31.19.0 → 31.20.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/package.json +29 -29
- package/src/templates/scaffold-auth.ts +35 -11
- package/src/templates/sign-in-authenticator.ts +33 -10
- package/wiki/Testing.md +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.20.0",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -53,34 +53,34 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/core": "^8.0.9",
|
|
56
|
-
"@ultimat3/action": "31.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
56
|
+
"@ultimat3/action": "31.20.0",
|
|
57
|
+
"@ultimat3/admin": "31.20.0",
|
|
58
|
+
"@ultimat3/ai": "31.20.0",
|
|
59
|
+
"@ultimat3/auth": "31.20.0",
|
|
60
|
+
"@ultimat3/cache": "31.20.0",
|
|
61
|
+
"@ultimat3/core": "31.20.0",
|
|
62
|
+
"@ultimat3/db": "31.20.0",
|
|
63
|
+
"@ultimat3/entity": "31.20.0",
|
|
64
|
+
"@ultimat3/flags": "31.20.0",
|
|
65
|
+
"@ultimat3/http": "31.20.0",
|
|
66
|
+
"@ultimat3/i18n": "31.20.0",
|
|
67
|
+
"@ultimat3/jobs": "31.20.0",
|
|
68
|
+
"@ultimat3/mail": "31.20.0",
|
|
69
|
+
"@ultimat3/manifest": "31.20.0",
|
|
70
|
+
"@ultimat3/mcp": "31.20.0",
|
|
71
|
+
"@ultimat3/money": "31.20.0",
|
|
72
|
+
"@ultimat3/notify": "31.20.0",
|
|
73
|
+
"@ultimat3/policy": "31.20.0",
|
|
74
|
+
"@ultimat3/pwa": "31.20.0",
|
|
75
|
+
"@ultimat3/query": "31.20.0",
|
|
76
|
+
"@ultimat3/realtime": "31.20.0",
|
|
77
|
+
"@ultimat3/render": "31.20.0",
|
|
78
|
+
"@ultimat3/schema": "31.20.0",
|
|
79
|
+
"@ultimat3/scraping": "31.20.0",
|
|
80
|
+
"@ultimat3/seo": "31.20.0",
|
|
81
|
+
"@ultimat3/storage": "31.20.0",
|
|
82
|
+
"@ultimat3/testing": "31.20.0",
|
|
83
|
+
"@ultimat3/time": "31.20.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -138,7 +138,7 @@ const authenticatorModule =
|
|
|
138
138
|
// otherwise read as development too. \`x dev\` declares \`ULTIMATE_ENV=development\` for exactly this
|
|
139
139
|
// reason, and \`bun test\` sets \`NODE_ENV=test\`, where a fixture mints its own actor.
|
|
140
140
|
import { type Auth, authenticate } from '@ultimat3/auth';
|
|
141
|
-
import { type Actor, logger, tryResolveEnvironment } from '@ultimat3/core';
|
|
141
|
+
import { type Actor, isSessionRefusal, logger, tryResolveEnvironment } from '@ultimat3/core';
|
|
142
142
|
import { configureAuthenticator } from '@ultimat3/http';
|
|
143
143
|
import { appAuth } from './auth';
|
|
144
144
|
import {
|
|
@@ -161,18 +161,27 @@ export interface SessionAuthenticatorOptions {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
* A session cookie is that session's user, or
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
164
|
+
* A session cookie is that session's user, or nobody — never a fallback to anyone else. A session
|
|
165
|
+
* past its expiry, or one unknown, revoked or forged, or whose user is disabled, is a refusal
|
|
166
|
+
* \`authenticate()\` THROWS (\`isSessionRefusal\`: \`X_SESSION_EXPIRED\`, \`X_UNAUTHENTICATED\`), and it
|
|
167
|
+
* is answered \`null\`: a stale cookie is an anonymous visitor, so sign-in still opens and a live
|
|
168
|
+
* socket it opened is closed. Anything else it throws — a session store that is down — is not an
|
|
169
|
+
* answer about this visitor and propagates. No cookie is the development viewer or nobody.
|
|
168
170
|
*/
|
|
169
171
|
export const sessionAuthenticator =
|
|
170
172
|
(options: SessionAuthenticatorOptions) =>
|
|
171
173
|
async (request: SessionRequest): Promise<Actor | null> => {
|
|
172
174
|
const auth = options.auth();
|
|
173
175
|
const token = request.cookie(auth.sessions.policy.cookieName);
|
|
174
|
-
if (token
|
|
175
|
-
|
|
176
|
+
if (token === null || token.length === 0) {
|
|
177
|
+
return options.development ? devAuthenticate(request) : null;
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
return await authenticate(auth, token);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (isSessionRefusal(error)) return null;
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
176
185
|
};
|
|
177
186
|
|
|
178
187
|
/**
|
|
@@ -283,7 +292,7 @@ unitTest('an undeclared role is answered as ANONYMOUS, and the log names what it
|
|
|
283
292
|
const authenticatorTest =
|
|
284
293
|
(): string => `// The real path and its one fallback: a session cookie is its user in every environment, a bad
|
|
285
294
|
// one is refused rather than replaced, and only development answers a request with no session.
|
|
286
|
-
import { defineAuth, login, memoryAuthAdapter, register } from '@ultimat3/auth';
|
|
295
|
+
import { defineAuth, login, logout, memoryAuthAdapter, register } from '@ultimat3/auth';
|
|
287
296
|
import { configuredAuthenticator, resetAuthenticator } from '@ultimat3/http';
|
|
288
297
|
import { expect, unitTest } from '@ultimat3/testing';
|
|
289
298
|
import { DEMO_ORG_ID } from '../../shared/demo-org';
|
|
@@ -326,12 +335,27 @@ unitTest('a session cookie is the user it was issued to, in every environment',
|
|
|
326
335
|
}
|
|
327
336
|
});
|
|
328
337
|
|
|
329
|
-
unitTest('a cookie naming no live session is
|
|
338
|
+
unitTest('a cookie naming no live session is nobody, never answered as the viewer', async () => {
|
|
330
339
|
const auth = memoryAuth();
|
|
331
340
|
const request = requestWith({ [auth().sessions.policy.cookieName]: 'forged.token' });
|
|
332
|
-
|
|
333
|
-
|
|
341
|
+
// \`null\`, not a throw: thrown, a stale cookie was a 401 on the sign-in page itself.
|
|
342
|
+
expect(await sessionAuthenticator({ auth, development: true })(request)).toBeNull();
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
unitTest('a signed-out cookie is nobody, so its socket is closed on re-check', async () => {
|
|
346
|
+
const auth = memoryAuth();
|
|
347
|
+
await register(auth(), {
|
|
348
|
+
email: 'ada@example.com',
|
|
349
|
+
password: PASSWORD,
|
|
350
|
+
orgId: DEMO_ORG_ID,
|
|
351
|
+
roles: ['member'],
|
|
334
352
|
});
|
|
353
|
+
const { token } = await login(auth(), { email: 'ada@example.com', password: PASSWORD });
|
|
354
|
+
await logout(auth(), token);
|
|
355
|
+
const request = requestWith({ [auth().sessions.policy.cookieName]: token });
|
|
356
|
+
for (const development of [true, false]) {
|
|
357
|
+
expect(await sessionAuthenticator({ auth, development })(request)).toBeNull();
|
|
358
|
+
}
|
|
335
359
|
});
|
|
336
360
|
|
|
337
361
|
unitTest('no session: the development viewer under x dev, anonymous anywhere else', async () => {
|
|
@@ -12,7 +12,7 @@ const authenticatorSource =
|
|
|
12
12
|
// live subscribers, MCP tools) reads the actor this returns. With no session the request is
|
|
13
13
|
// anonymous, everywhere: a developer signs in through \`/auth/sign-in\` like everyone else.
|
|
14
14
|
import { type Auth, authenticate } from '@ultimat3/auth';
|
|
15
|
-
import type
|
|
15
|
+
import { type Actor, isSessionRefusal } from '@ultimat3/core';
|
|
16
16
|
import { configureAuthenticator } from '@ultimat3/http';
|
|
17
17
|
import { appAuth } from './auth';
|
|
18
18
|
|
|
@@ -22,15 +22,24 @@ export interface SessionRequest {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* A session cookie is that session's user, or
|
|
26
|
-
*
|
|
25
|
+
* A session cookie is that session's user, or nobody — never a fallback to anyone else. A session
|
|
26
|
+
* past its expiry, or one unknown, revoked or forged, is a refusal \`authenticate()\` THROWS
|
|
27
|
+
* (\`isSessionRefusal\`: \`X_SESSION_EXPIRED\`, \`X_UNAUTHENTICATED\`), answered \`null\`: a stale
|
|
28
|
+
* cookie is an anonymous visitor, so sign-in still opens and a live socket it opened is closed.
|
|
29
|
+
* Anything else it throws — a session store that is down — propagates.
|
|
27
30
|
*/
|
|
28
31
|
export const sessionAuthenticator =
|
|
29
32
|
(auth: () => Auth) =>
|
|
30
33
|
async (request: SessionRequest): Promise<Actor | null> => {
|
|
31
34
|
const resolved = auth();
|
|
32
35
|
const token = request.cookie(resolved.sessions.policy.cookieName);
|
|
33
|
-
|
|
36
|
+
if (token === null || token.length === 0) return null;
|
|
37
|
+
try {
|
|
38
|
+
return await authenticate(resolved, token);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (isSessionRefusal(error)) return null;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
34
43
|
};
|
|
35
44
|
|
|
36
45
|
/** Installs the session authenticator. */
|
|
@@ -44,8 +53,9 @@ installAuthenticator();
|
|
|
44
53
|
`;
|
|
45
54
|
|
|
46
55
|
const authenticatorTest =
|
|
47
|
-
(): string => `// A session cookie is the user it was issued to; a bad
|
|
48
|
-
|
|
56
|
+
(): string => `// A session cookie is the user it was issued to; a bad, expired or signed-out one is nobody, and
|
|
57
|
+
// so is none.
|
|
58
|
+
import { defineAuth, login, logout, memoryAuthAdapter, register } from '@ultimat3/auth';
|
|
49
59
|
import { configuredAuthenticator, resetAuthenticator } from '@ultimat3/http';
|
|
50
60
|
import { expect, unitTest } from '@ultimat3/testing';
|
|
51
61
|
import { DEMO_ORG_ID } from '../../shared/demo-org';
|
|
@@ -78,15 +88,28 @@ unitTest('a session cookie is the user it was issued to', async () => {
|
|
|
78
88
|
expect(actor?.roles).toEqual(['member']);
|
|
79
89
|
});
|
|
80
90
|
|
|
81
|
-
unitTest('a forged cookie is
|
|
91
|
+
unitTest('a forged cookie is nobody, and no cookie is anonymous', async () => {
|
|
82
92
|
const auth = memoryAuth();
|
|
83
93
|
const forged = requestWith({ [auth().sessions.policy.cookieName]: 'forged.token' });
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
94
|
+
// \`null\`, not a throw: thrown, a stale cookie was a 401 on the sign-in page itself.
|
|
95
|
+
expect(await sessionAuthenticator(auth)(forged)).toBeNull();
|
|
87
96
|
expect(await sessionAuthenticator(auth)(requestWith({}))).toBeNull();
|
|
88
97
|
});
|
|
89
98
|
|
|
99
|
+
unitTest('a signed-out cookie is nobody, so its socket is closed on re-check', async () => {
|
|
100
|
+
const auth = memoryAuth();
|
|
101
|
+
await register(auth(), {
|
|
102
|
+
email: 'ada@example.com',
|
|
103
|
+
password: PASSWORD,
|
|
104
|
+
orgId: DEMO_ORG_ID,
|
|
105
|
+
roles: ['member'],
|
|
106
|
+
});
|
|
107
|
+
const { token } = await login(auth(), { email: 'ada@example.com', password: PASSWORD });
|
|
108
|
+
await logout(auth(), token);
|
|
109
|
+
const cookie = requestWith({ [auth().sessions.policy.cookieName]: token });
|
|
110
|
+
expect(await sessionAuthenticator(auth)(cookie)).toBeNull();
|
|
111
|
+
});
|
|
112
|
+
|
|
90
113
|
unitTest('it installs', () => {
|
|
91
114
|
try {
|
|
92
115
|
installAuthenticator(memoryAuth());
|
package/wiki/Testing.md
CHANGED
|
@@ -1484,7 +1484,7 @@ Full list: [Error codes](Error-Codes).
|
|
|
1484
1484
|
- Never assert on wall-clock time. Advance the frozen clock.
|
|
1485
1485
|
- Never let a test reach the network unmocked — it fails by design.
|
|
1486
1486
|
- A flaky test is deleted or fixed the day it flakes. There is no `retry: 3`.
|
|
1487
|
-
- Hunting an order flake: `x test unit --filter <file> -- --rerun-each=30 --randomize` — the `--` hands the rest to `bun test`.
|
|
1487
|
+
- Hunting an order flake: `x test unit --filter <file> -- --rerun-each=30 --randomize` — the `--` hands the rest to `bun test`. A rerun forgets the `entity()` and `job()` calls the file's module body made on its last load, so they declare again. `As of 2026-11`, an `action()`, a mail template or an OAuth provider declared at module scope still fails its second load with `X_*_DUPLICATE`. Declare those inside the test, or put the file in its own run.
|
|
1488
1488
|
- Every framework package ships at least 2 tests that would catch a real regression. No `expect(true).toBe(true)`.
|
|
1489
1489
|
- Tests live next to their source as `<file>.test.ts`.
|
|
1490
1490
|
- A denial test per policy branch, not one happy-path test per action.
|