@ultimat3/cli 31.45.0 → 31.46.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/cli",
3
- "version": "31.45.0",
3
+ "version": "31.46.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.10",
56
- "@ultimat3/action": "31.45.0",
57
- "@ultimat3/admin": "31.45.0",
58
- "@ultimat3/ai": "31.45.0",
59
- "@ultimat3/auth": "31.45.0",
60
- "@ultimat3/cache": "31.45.0",
61
- "@ultimat3/core": "31.45.0",
62
- "@ultimat3/db": "31.45.0",
63
- "@ultimat3/entity": "31.45.0",
64
- "@ultimat3/flags": "31.45.0",
65
- "@ultimat3/http": "31.45.0",
66
- "@ultimat3/i18n": "31.45.0",
67
- "@ultimat3/jobs": "31.45.0",
68
- "@ultimat3/mail": "31.45.0",
69
- "@ultimat3/manifest": "31.45.0",
70
- "@ultimat3/mcp": "31.45.0",
71
- "@ultimat3/money": "31.45.0",
72
- "@ultimat3/notify": "31.45.0",
73
- "@ultimat3/policy": "31.45.0",
74
- "@ultimat3/pwa": "31.45.0",
75
- "@ultimat3/query": "31.45.0",
76
- "@ultimat3/realtime": "31.45.0",
77
- "@ultimat3/render": "31.45.0",
78
- "@ultimat3/schema": "31.45.0",
79
- "@ultimat3/scraping": "31.45.0",
80
- "@ultimat3/seo": "31.45.0",
81
- "@ultimat3/storage": "31.45.0",
82
- "@ultimat3/testing": "31.45.0",
83
- "@ultimat3/time": "31.45.0",
56
+ "@ultimat3/action": "31.46.0",
57
+ "@ultimat3/admin": "31.46.0",
58
+ "@ultimat3/ai": "31.46.0",
59
+ "@ultimat3/auth": "31.46.0",
60
+ "@ultimat3/cache": "31.46.0",
61
+ "@ultimat3/core": "31.46.0",
62
+ "@ultimat3/db": "31.46.0",
63
+ "@ultimat3/entity": "31.46.0",
64
+ "@ultimat3/flags": "31.46.0",
65
+ "@ultimat3/http": "31.46.0",
66
+ "@ultimat3/i18n": "31.46.0",
67
+ "@ultimat3/jobs": "31.46.0",
68
+ "@ultimat3/mail": "31.46.0",
69
+ "@ultimat3/manifest": "31.46.0",
70
+ "@ultimat3/mcp": "31.46.0",
71
+ "@ultimat3/money": "31.46.0",
72
+ "@ultimat3/notify": "31.46.0",
73
+ "@ultimat3/policy": "31.46.0",
74
+ "@ultimat3/pwa": "31.46.0",
75
+ "@ultimat3/query": "31.46.0",
76
+ "@ultimat3/realtime": "31.46.0",
77
+ "@ultimat3/render": "31.46.0",
78
+ "@ultimat3/schema": "31.46.0",
79
+ "@ultimat3/scraping": "31.46.0",
80
+ "@ultimat3/seo": "31.46.0",
81
+ "@ultimat3/storage": "31.46.0",
82
+ "@ultimat3/testing": "31.46.0",
83
+ "@ultimat3/time": "31.46.0",
84
84
  "babel-preset-solid": "^1.9.16"
85
85
  }
86
86
  }
@@ -1,6 +1,9 @@
1
1
  // The tests `x g invite` writes beside its files: the link shape on its own, then each action RUN
2
2
  // inside a real request context over the app's migrated database, so the paths a person takes —
3
- // refused, invited, joined, replayed, removed — are what is held.
3
+ // refused, invited, joined, replayed, removed — are what is held. A browser's own form is posted
4
+ // through the pipeline as well (`formPostSource`), so each 303 is the action's `native:` answer.
5
+
6
+ import { formPostSource } from './sign-in-action-tests';
4
7
 
5
8
  const DATABASE = `// A template restore is ~0.5 s; its first build (initdb plus every migration) is what this bounds.
6
9
  const BOOT_MS = 120_000;
@@ -15,7 +18,7 @@ afterAll(() => setDbClient(undefined));`;
15
18
  const SHARED_IMPORTS = `import { migratedDatabase } from '@ultimat3/cli';
16
19
  import { type Actor, runWithContext } from '@ultimat3/core';
17
20
  import { setDbClient } from '@ultimat3/db';
18
- import { asCtx, defineHttpConfig, requestContext } from '@ultimat3/http';
21
+ import { asCtx, defineHttpConfig, httpServer, requestContext } from '@ultimat3/http';
19
22
  import { testActor } from '@ultimat3/policy';
20
23
  import { afterAll, beforeAll, expect, reusableDatabase, unitTest } from '@ultimat3/testing';`;
21
24
 
@@ -36,7 +39,9 @@ const postAs = (
36
39
  return { output, request };
37
40
  };
38
41
 
39
- const target = ${action}.named('${action}');`;
42
+ const target = ${action}.named('${action}');
43
+
44
+ ${formPostSource(true)}`;
40
45
 
41
46
  /** Org ids are uuids: \`x_users.org_id\` is one. */
42
47
  const ORGS = `const ORG = '00000000-0000-4000-8000-0000000000a1';
@@ -75,8 +80,9 @@ unitTest('an invite is the declared member-invite purpose and lives a week', ()
75
80
  export const inviteMemberTest =
76
81
  (): string => `// inviteMember, run inside a real request over the app's migrated database: an actor without the
77
82
  // grant is refused, and one holding it mails a single-use link into their own org.
83
+ import { toRoute } from '@ultimat3/action';
78
84
  ${SHARED_IMPORTS}
79
- import { INVITE_ACCEPT_PATH } from '../invite';
85
+ import { INVITE_ACCEPT_PATH, INVITES_PATH } from '../invite';
80
86
  import { inviteMember } from './invite-member';
81
87
 
82
88
  ${DATABASE}
@@ -133,15 +139,27 @@ unitTest('with no APP_URL declared nothing is mailed', async ({ mail, runJobs })
133
139
  await runJobs.drain();
134
140
  expect(mail.lastTo('nobody@example.com')).toBeUndefined();
135
141
  });
142
+
143
+ // \`mail\` named so the fixture installs the test mail driver the pipeline's send reaches.
144
+ unitTest('a browser posting the invite form is sent back', async ({ mail, runJobs }) => {
145
+ const inviter = testActor('inviter', { orgId: ORG, permissions: ['member:invite'] }).actor;
146
+ await withAppUrl('https://invites.example', async () => {
147
+ const { landed } = await formPost({ email: 'form@example.com' }, inviter);
148
+ expect(landed).toEqual({ status: 303, location: INVITES_PATH });
149
+ });
150
+ await runJobs.drain();
151
+ expect(mail.lastTo('form@example.com')).toBeDefined();
152
+ });
136
153
  `;
137
154
 
138
155
  export const acceptInviteTest =
139
156
  (): string => `// acceptInvite, run inside a real request over the app's migrated database: anonymous is refused,
140
157
  // the invited account joins and its session is rotated, and the spent link never works again.
158
+ import { toRoute } from '@ultimat3/action';
141
159
  import { login, register } from '@ultimat3/auth';
142
160
  ${SHARED_IMPORTS}
143
161
  import { appAuth } from '../auth';
144
- import { memberInvite } from '../invite';
162
+ import { AFTER_JOIN, memberInvite } from '../invite';
145
163
  import { acceptInvite } from './accept-invite';
146
164
 
147
165
  ${DATABASE}
@@ -186,15 +204,28 @@ unitTest('a link for one org redeems in no other', async () => {
186
204
  expect(refused).toBeUltimateError('X_UNAUTHENTICATED');
187
205
  expect((await appAuth().adapter.findUserById(user.id))?.orgId).toBeNull();
188
206
  });
207
+
208
+ unitTest('a browser accepting from the invite page is sent on into the app', async () => {
209
+ const user = await register(appAuth(), { email: 'form-join@example.com', password: PASSWORD });
210
+ const { token } = await memberInvite.invite(appAuth(), silent, {
211
+ orgId: ORG,
212
+ email: 'form-join@example.com',
213
+ locale: 'en',
214
+ });
215
+ const { landed } = await formPost({ orgId: ORG, token }, testActor(user.id).actor);
216
+ expect(landed).toEqual({ status: 303, location: AFTER_JOIN });
217
+ expect((await appAuth().adapter.findUserById(user.id))?.orgId).toBe(ORG);
218
+ });
189
219
  `;
190
220
 
191
221
  export const revokeInviteTest =
192
222
  (): string => `// revokeInvite, run inside a real request over the app's migrated database: an actor without the
193
223
  // grant is refused, and an inviter removes a joined member from their own org.
224
+ import { toRoute } from '@ultimat3/action';
194
225
  import { register } from '@ultimat3/auth';
195
226
  ${SHARED_IMPORTS}
196
227
  import { appAuth } from '../auth';
197
- import { memberInvite } from '../invite';
228
+ import { INVITES_PATH, memberInvite } from '../invite';
198
229
  import { revokeInvite } from './revoke-invite';
199
230
 
200
231
  ${DATABASE}
@@ -225,4 +256,10 @@ unitTest('a joined member is removed from the inviter org, never from another',
225
256
  expect(output.memberRemoved).toBe(true);
226
257
  expect((await appAuth().adapter.findUserById(user.id))?.orgId).toBeNull();
227
258
  });
259
+
260
+ unitTest('a browser revoking from the invites page is sent back to it', async () => {
261
+ const inviter = testActor('inviter', { orgId: ORG, permissions: ['member:invite'] }).actor;
262
+ const { landed } = await formPost({ email: 'never-invited@example.com' }, inviter);
263
+ expect(landed).toEqual({ status: 303, location: INVITES_PATH });
264
+ });
228
265
  `;
@@ -43,7 +43,6 @@ const moduleSource = (
43
43
  // actions beside this file are the app's policy over it.
44
44
  ${catalogImport(module)}import { defineMemberInvite, type MailSender } from '@ultimat3/auth';
45
45
  import { EnvMissingError } from '@ultimat3/core';
46
- import { setRedirect, useRequestHeader } from '@ultimat3/http';
47
46
  import { blocks, defineMail, send, t } from '@ultimat3/mail';
48
47
 
49
48
  /** A week: long enough to survive a holiday, short enough that a stale inbox is not a door. */
@@ -100,12 +99,6 @@ export const inviteLink =
100
99
  url.search = new URLSearchParams({ orgId, token }).toString();
101
100
  return url.href;
102
101
  };
103
-
104
- /** A browser that posted the native form gets a 303; an agent posting JSON gets the path as data. */
105
- export const landAt = (path: string): string => {
106
- if ((useRequestHeader('accept') ?? '').includes('text/html')) setRedirect(path);
107
- return path;
108
- };
109
102
  `;
110
103
 
111
104
  const policySource =
@@ -140,7 +133,7 @@ const inviteMemberSource =
140
133
  import { action, t } from '@ultimat3/action';
141
134
  import { authForbidden } from '@ultimat3/auth';
142
135
  import { appAuth } from '../auth';
143
- import { appOrigin, INVITES_PATH, inviteLink, inviteMailer, landAt, memberInvite } from '../invite';
136
+ import { appOrigin, INVITES_PATH, inviteLink, inviteMailer, memberInvite } from '../invite';
144
137
  import { canInvite } from '../policy';
145
138
 
146
139
  export const inviteMember = action({
@@ -149,6 +142,8 @@ export const inviteMember = action({
149
142
  policy: canInvite,
150
143
  // Mailing a person is a browser operation here; an app that wants it as a tool exposes it.
151
144
  mcp: { expose: false },
145
+ // A browser's own form lands where the output says; fetch and the typed client read \`next\`.
146
+ native: { success: (output) => output.next },
152
147
  async handle({ input, ctx }) {
153
148
  const orgId = ctx.actor.orgId;
154
149
  if (typeof orgId !== 'string' || orgId === '') {
@@ -160,7 +155,7 @@ export const inviteMember = action({
160
155
  locale: ctx.locale,
161
156
  link: inviteLink(appOrigin(), orgId),
162
157
  });
163
- return { ok: true, next: landAt(INVITES_PATH) };
158
+ return { ok: true, next: INVITES_PATH };
164
159
  },
165
160
  });
166
161
  `;
@@ -175,7 +170,7 @@ import { isAnonymous } from '@ultimat3/core';
175
170
  import { useRequestContext, useRequestCookie } from '@ultimat3/http';
176
171
  import { allow } from '@ultimat3/policy';
177
172
  import { appAuth } from '../auth';
178
- import { AFTER_JOIN, landAt, memberInvite } from '../invite';
173
+ import { AFTER_JOIN, memberInvite } from '../invite';
179
174
 
180
175
  export const acceptInvite = action({
181
176
  input: t.object({ orgId: t.uuid, token: t.string.min(1).max(256) }),
@@ -184,6 +179,8 @@ export const acceptInvite = action({
184
179
  // the handler refuses an anonymous caller before it reads it.
185
180
  policy: allow('invite-link'),
186
181
  mcp: { expose: false },
182
+ // A browser's own form lands where the output says; fetch and the typed client read \`next\`.
183
+ native: { success: (output) => output.next },
187
184
  async handle({ input, ctx }) {
188
185
  if (isAnonymous(ctx.actor)) throw authUnauthenticated('POST acceptInvite');
189
186
  const auth = appAuth();
@@ -199,7 +196,7 @@ export const acceptInvite = action({
199
196
  if (joined.cookie !== undefined) {
200
197
  useRequestContext('acceptInvite').headers.append('set-cookie', joined.cookie);
201
198
  }
202
- return { ok: true, next: landAt(AFTER_JOIN) };
199
+ return { ok: true, next: AFTER_JOIN };
203
200
  },
204
201
  });
205
202
  `;
@@ -210,7 +207,7 @@ const revokeInviteSource =
210
207
  import { action, t } from '@ultimat3/action';
211
208
  import { authForbidden } from '@ultimat3/auth';
212
209
  import { appAuth } from '../auth';
213
- import { INVITES_PATH, landAt, memberInvite } from '../invite';
210
+ import { INVITES_PATH, memberInvite } from '../invite';
214
211
  import { canInvite } from '../policy';
215
212
 
216
213
  export const revokeInvite = action({
@@ -218,6 +215,8 @@ export const revokeInvite = action({
218
215
  output: t.object({ ok: t.boolean, next: t.string, memberRemoved: t.boolean }),
219
216
  policy: canInvite,
220
217
  mcp: { expose: false },
218
+ // A browser's own form lands where the output says; fetch and the typed client read \`next\`.
219
+ native: { success: (output) => output.next },
221
220
  async handle({ input, ctx }) {
222
221
  const orgId = ctx.actor.orgId;
223
222
  if (typeof orgId !== 'string' || orgId === '') {
@@ -228,8 +227,7 @@ export const revokeInvite = action({
228
227
  email: input.email,
229
228
  reason: \`revokeInvite by \${ctx.actor.id}\`,
230
229
  });
231
- const next = landAt(INVITES_PATH);
232
- return { ok: true, next, memberRemoved: revoked.memberRemoved };
230
+ return { ok: true, next: INVITES_PATH, memberRemoved: revoked.memberRemoved };
233
231
  },
234
232
  });
235
233
  `;
@@ -1,7 +1,7 @@
1
- // The tests `x g sign-in` writes for its actions: each handler RUN inside a real request context,
2
- // over the app's migrated database (`migratedDatabase`, the framework tables included), so the
3
- // paths a person takes — refused, signed in, a second factor owed, signed out — are what is held.
4
- // `destroySessionTest` is both shapes'; the other two are the password shape's.
1
+ // The tests `x g sign-in` writes for its actions: each handler run in a real request context over
2
+ // the app's migrated database, so refused, signed in, second factor owed and signed out are held.
3
+ // `destroySessionTest` is both shapes'; the other two are the password shape's. A browser's own
4
+ // form is posted through the pipeline (`formPostSource`): its 303 is the action's `native:`.
5
5
 
6
6
  /** The app's migrated database installed under `db()` for the file, as `page-db.test.ts` does. */
7
7
  const DATABASE = `// A template restore is ~0.5 s; its first build (initdb plus every migration) is what this bounds.
@@ -18,10 +18,45 @@ afterAll(() => setDbClient(undefined));`;
18
18
  const SHARED_IMPORTS = `import { migratedDatabase } from '@ultimat3/cli';
19
19
  import { runWithContext } from '@ultimat3/core';
20
20
  import { setDbClient } from '@ultimat3/db';
21
- import { asCtx, defineHttpConfig, requestContext } from '@ultimat3/http';
21
+ import { asCtx, defineHttpConfig, httpServer, requestContext } from '@ultimat3/http';
22
22
  import { afterAll, beforeAll, expect, reusableDatabase, unitTest } from '@ultimat3/testing';
23
23
  import { appAuth } from '../auth';`;
24
24
 
25
+ /**
26
+ * \`formPost\`: \`target\` posted the way a browser's own \`<form method="post">\` posts it — through
27
+ * the pipeline, so the 303 is what the action's \`native:\` answers. \`actor\` adds the signed-in
28
+ * caller an \`authenticate\` hook would resolve; without it the caller is anonymous.
29
+ */
30
+ export const formPostSource = (actor: boolean): string => {
31
+ // Biome's layout: the two-parameter list fits on one line, the three-parameter one does not.
32
+ const signature = actor
33
+ ? '(\n fields: Record<string, string>,\n actor: Actor,\n headers: Record<string, string> = {},\n)'
34
+ : '(fields: Record<string, string>, headers: Record<string, string> = {})';
35
+ const hooks = actor ? '\n hooks: { authenticate: () => actor },' : '';
36
+ return `/** \`target\` posted as a browser's own form, through the pipeline: its \`native:\` answers. */
37
+ const formPost = async ${signature} => {
38
+ const route = toRoute(target);
39
+ const server = httpServer({
40
+ routes: [route],
41
+ config: defineHttpConfig({ dev: true, rateLimit: { scope: 'process' } }),${hooks}
42
+ });
43
+ const response = await server.fetch(
44
+ new Request(\`https://app.test\${route.path}\`, {
45
+ method: 'POST',
46
+ headers: {
47
+ accept: 'text/html',
48
+ 'content-type': 'application/x-www-form-urlencoded',
49
+ origin: 'https://app.test',
50
+ ...headers,
51
+ },
52
+ body: new URLSearchParams(fields),
53
+ }),
54
+ );
55
+ const landed = { status: response.status, location: response.headers.get('location') };
56
+ return { response, landed };
57
+ };`;
58
+ };
59
+
25
60
  /** The request the pipeline would build, the action run inside it, and both handed back. */
26
61
  const requestOf = (
27
62
  path: string,
@@ -41,6 +76,7 @@ const requestOf = (
41
76
  export const createSessionTest =
42
77
  (): string => `// createSession, run inside a real request over the app's migrated database: a wrong password is
43
78
  // refused, a right one sets the session cookie, and a second factor still owed holds the challenge.
79
+ import { toRoute } from '@ultimat3/action';
44
80
  import { generateTotpSecret, register, saveTotpSecret } from '@ultimat3/auth';
45
81
  ${SHARED_IMPORTS}
46
82
  import { MFA_CHALLENGE_COOKIE, SECOND_FACTOR_PATH } from '../sign-in-challenge';
@@ -53,10 +89,12 @@ const target = createSession.named('createSession');
53
89
  const PASSWORD = 'a long scaffold test passphrase';
54
90
 
55
91
  /** One POST, as the pipeline hands it to the action: the response headers come back with it. */
56
- const post = async (input: Parameters<typeof target>[0], accept = 'application/json') => {
57
- ${requestOf('/auth/sign-in', '{ accept }', 'target(input, { ctx })')}
92
+ const post = async (input: Parameters<typeof target>[0]) => {
93
+ ${requestOf('/auth/sign-in', "{ accept: 'application/json' }", 'target(input, { ctx })')}
58
94
  };
59
95
 
96
+ ${formPostSource(false)}
97
+
60
98
  /** A person who can sign in, under an address no other test in this file uses. */
61
99
  const person = (email: string) => register(appAuth(), { email, password: PASSWORD });
62
100
 
@@ -91,12 +129,11 @@ unitTest('the right password sets the session cookie and lands where it was goin
91
129
  expect(request.redirect).toBeUndefined();
92
130
  });
93
131
 
94
- unitTest('a browser posting the form is sent on with a 303', async () => {
132
+ unitTest('a browser posting the form is sent on with a 303 and the session', async () => {
95
133
  await person('form@example.com');
96
- const input = { email: 'form@example.com', password: PASSWORD };
97
- const { output, request } = await post(input, 'text/html');
98
- expect(output.next).toBe(AFTER_SIGN_IN);
99
- expect(request.redirect).toEqual({ location: AFTER_SIGN_IN, status: 303 });
134
+ const { response, landed } = await formPost({ email: 'form@example.com', password: PASSWORD });
135
+ expect(landed).toEqual({ status: 303, location: AFTER_SIGN_IN });
136
+ expect(sets(response, appAuth().sessions.policy.cookieName)).toBe(true);
100
137
  });
101
138
 
102
139
  unitTest('a second factor still owed holds the challenge and sets no session', async () => {
@@ -112,6 +149,7 @@ unitTest('a second factor still owed holds the challenge and sets no session', a
112
149
  export const confirmSessionTest =
113
150
  (): string => `// confirmSession, run inside a real request over the app's migrated database: with no challenge
114
151
  // held it refuses, a wrong code is refused, and the held challenge plus the right code signs in.
152
+ import { toRoute } from '@ultimat3/action';
115
153
  import {
116
154
  generateTotpSecret,
117
155
  login,
@@ -138,6 +176,8 @@ ${requestOf(
138
176
  )}
139
177
  };
140
178
 
179
+ ${formPostSource(false)}
180
+
141
181
  /** A person with a second factor, and the cookie holding the challenge the first leg sealed. */
142
182
  const challenged = async (email: string) => {
143
183
  const user = await register(appAuth(), { email, password: PASSWORD });
@@ -182,11 +222,19 @@ unitTest('the held challenge and the right code sign in, and drop the challenge'
182
222
  // Cleared, an empty value: the challenge is spent, and a reload starts the sign-in over.
183
223
  expect(lines.some((line) => line.startsWith(\`\${MFA_CHALLENGE_COOKIE}=;\`))).toBe(true);
184
224
  });
225
+
226
+ unitTest('a browser posting the second-factor form is sent on with a 303', async () => {
227
+ const { secret, cookie } = await challenged('second-form@example.com');
228
+ const code = totpCode(secret, totpStep(new Date()));
229
+ const { landed } = await formPost({ code, next: '/posts' }, { cookie });
230
+ expect(landed).toEqual({ status: 303, location: '/posts' });
231
+ });
185
232
  `;
186
233
 
187
234
  export const destroySessionTest =
188
235
  (): string => `// destroySession, run inside a real request over the app's migrated database: a live session is
189
236
  // revoked, and a caller with none still signs out — cleared, and landed at the home page.
237
+ import { toRoute } from '@ultimat3/action';
190
238
  import { login, register } from '@ultimat3/auth';
191
239
  ${SHARED_IMPORTS}
192
240
  import { destroySession } from './destroy-session';
@@ -196,14 +244,16 @@ ${DATABASE}
196
244
  const target = destroySession.named('destroySession');
197
245
 
198
246
  /** One sign-out POST carrying \`cookie\`, as the pipeline hands it to the action. */
199
- const signOut = async (accept: string, cookie?: string) => {
247
+ const signOut = async (cookie?: string) => {
200
248
  ${requestOf(
201
249
  '/auth/sign-out',
202
- '{ accept, ...(cookie === undefined ? {} : { cookie }) }',
250
+ "{ accept: 'application/json', ...(cookie === undefined ? {} : { cookie }) }",
203
251
  "target({ confirm: 'sign-out' }, { ctx })",
204
252
  )}
205
253
  };
206
254
 
255
+ ${formPostSource(false)}
256
+
207
257
  unitTest('destroySession is a declared action off the MCP surface', () => {
208
258
  expect(target.kind).toBe('action');
209
259
  expect(target.describe().name).toBe('destroySession');
@@ -220,18 +270,18 @@ unitTest('a live session is revoked, and a second sign-out finds nothing to revo
220
270
  await register(appAuth(), { email: 'leaving@example.com', password });
221
271
  const { token } = await login(appAuth(), { email: 'leaving@example.com', password });
222
272
  const cookie = \`\${appAuth().sessions.policy.cookieName}=\${token}\`;
223
- const { output } = await signOut('application/json', cookie);
273
+ const { output } = await signOut(cookie);
224
274
  expect(output).toEqual({ ok: true, next: '/', revoked: true });
225
- expect((await signOut('application/json', cookie)).output.revoked).toBe(false);
275
+ expect((await signOut(cookie)).output.revoked).toBe(false);
226
276
  });
227
277
 
228
278
  unitTest('with no session it still signs out, and a browser lands at the home page', async () => {
229
- const { output, request } = await signOut('text/html');
230
- expect(output).toEqual({ ok: true, next: '/', revoked: false });
231
- expect(request.redirect).toEqual({ location: '/', status: 303 });
279
+ expect((await signOut()).output).toEqual({ ok: true, next: '/', revoked: false });
280
+ const { response, landed } = await formPost({ confirm: 'sign-out' });
281
+ expect(landed).toEqual({ status: 303, location: '/' });
232
282
  // The expired session cookie and the cleared browser state, whether or not a session existed.
233
283
  const expired = \`\${appAuth().sessions.policy.cookieName}=;\`;
234
- expect(request.headers.getSetCookie().some((line) => line.startsWith(expired))).toBe(true);
235
- expect(request.headers.get('clear-site-data')).not.toBeNull();
284
+ expect(response.headers.getSetCookie().some((line) => line.startsWith(expired))).toBe(true);
285
+ expect(response.headers.get('clear-site-data')).not.toBeNull();
236
286
  });
237
287
  `;
@@ -74,7 +74,7 @@ import { useRequestContext } from '@ultimat3/http';
74
74
  import { allow } from '@ultimat3/policy';
75
75
  import { appAuth } from '../auth';
76
76
  import { challengeOf, holdChallenge, SECOND_FACTOR_PATH } from '../sign-in-challenge';
77
- import { landAt, NEXT_PARAM, nextPath } from '../sign-in-flow';
77
+ import { NEXT_PARAM, nextPath } from '../sign-in-flow';
78
78
 
79
79
  export const createSession = action({
80
80
  input: t.object({
@@ -86,6 +86,8 @@ export const createSession = action({
86
86
  // Public by declaration: signing in is the one operation nobody holds a permission for yet.
87
87
  policy: allow('public'),
88
88
  mcp: { expose: false },
89
+ // A browser's own form lands where the output says; fetch and the typed client read \`next\`.
90
+ native: { success: (output) => output.next },
89
91
  async handle({ input }) {
90
92
  const request = useRequestContext('createSession');
91
93
  try {
@@ -95,7 +97,7 @@ export const createSession = action({
95
97
  ip: request.ip,
96
98
  });
97
99
  request.headers.append('set-cookie', signedIn.cookie);
98
- return { ok: true, next: landAt(nextPath(input[NEXT_PARAM])), secondFactor: false };
100
+ return { ok: true, next: nextPath(input[NEXT_PARAM]), secondFactor: false };
99
101
  } catch (error) {
100
102
  const challenge = challengeOf(error);
101
103
  if (challenge === null) throw error;
@@ -106,7 +108,7 @@ export const createSession = action({
106
108
  next === undefined
107
109
  ? SECOND_FACTOR_PATH
108
110
  : \`\${SECOND_FACTOR_PATH}?\${NEXT_PARAM}=\${encodeURIComponent(nextPath(next))}\`;
109
- return { ok: false, next: landAt(then), secondFactor: true };
111
+ return { ok: false, next: then, secondFactor: true };
110
112
  }
111
113
  },
112
114
  });
@@ -121,7 +123,7 @@ import { useRequestContext } from '@ultimat3/http';
121
123
  import { allow } from '@ultimat3/policy';
122
124
  import { appAuth } from '../auth';
123
125
  import { dropChallenge, heldChallenge } from '../sign-in-challenge';
124
- import { landAt, NEXT_PARAM, nextPath } from '../sign-in-flow';
126
+ import { NEXT_PARAM, nextPath } from '../sign-in-flow';
125
127
 
126
128
  export const confirmSession = action({
127
129
  input: t.object({
@@ -131,6 +133,8 @@ export const confirmSession = action({
131
133
  output: t.object({ ok: t.boolean, next: t.string }),
132
134
  policy: allow('public'),
133
135
  mcp: { expose: false },
136
+ // A browser's own form lands where the output says; fetch and the typed client read \`next\`.
137
+ native: { success: (output) => output.next },
134
138
  async handle({ input }) {
135
139
  const request = useRequestContext('confirmSession');
136
140
  const challenge = heldChallenge();
@@ -138,7 +142,7 @@ export const confirmSession = action({
138
142
  const signedIn = await completeMfa(appAuth(), challenge, input.code, { ip: request.ip });
139
143
  dropChallenge();
140
144
  request.headers.append('set-cookie', signedIn.cookie);
141
- return { ok: true, next: landAt(nextPath(input[NEXT_PARAM])) };
145
+ return { ok: true, next: nextPath(input[NEXT_PARAM]) };
142
146
  },
143
147
  });
144
148
  `;
@@ -56,10 +56,10 @@ export const arrayLiteral = (prefix: string, items: readonly string[], suffix: s
56
56
  };
57
57
 
58
58
  const flowSource =
59
- (): string => `// Where a signed-in browser goes, and the one browser/agent split every sign-in action makes. The
60
- // destination is a FIXED path or a same-origin \`?next=\`: the endpoint that hands out a session is
61
- // the classic open redirect, and \`nextAfterSignIn\` is the framework's one check for it.
62
- import { NEXT_PARAM, nextAfterSignIn, setRedirect, useRequestHeader } from '@ultimat3/http';
59
+ (): string => `// Where a signed-in browser goes. The destination is a FIXED path or a same-origin \`?next=\`: the
60
+ // endpoint that hands out a session is the classic open redirect, and \`nextAfterSignIn\` is the
61
+ // framework's one check for it. Each action returns it as \`next\`; its \`native:\` lands there.
62
+ import { NEXT_PARAM, nextAfterSignIn } from '@ultimat3/http';
63
63
 
64
64
  /** Where a browser lands with no \`?next=\`. The app's to move. */
65
65
  export const AFTER_SIGN_IN = '/dashboard';
@@ -70,15 +70,6 @@ export { NEXT_PARAM };
70
70
  /** A same-origin path to go to next, or the fallback. Never another origin. */
71
71
  export const nextPath = (raw: string | undefined, fallback = AFTER_SIGN_IN): string =>
72
72
  nextAfterSignIn(raw, fallback);
73
-
74
- /**
75
- * A browser that posted the native form gets a 303 to where it was going; an agent that posted
76
- * JSON gets the same path as data. One operation, two audiences — \`setRedirect\` is that seam.
77
- */
78
- export const landAt = (path: string): string => {
79
- if ((useRequestHeader('accept') ?? '').includes('text/html')) setRedirect(path);
80
- return path;
81
- };
82
73
  `;
83
74
 
84
75
  const flowTest =
@@ -104,7 +95,6 @@ import { logout, signOutHeaders } from '@ultimat3/auth';
104
95
  import { useRequestContext, useRequestCookie } from '@ultimat3/http';
105
96
  import { allow } from '@ultimat3/policy';
106
97
  import { appAuth } from '../auth';
107
- import { landAt } from '../sign-in-flow';
108
98
 
109
99
  export const destroySession = action({
110
100
  // A native form with no field posts no body, and an action's input is an object: the form
@@ -113,6 +103,8 @@ export const destroySession = action({
113
103
  output: t.object({ ok: t.boolean, next: t.string, revoked: t.boolean }),
114
104
  policy: allow('public'),
115
105
  mcp: { expose: false },
106
+ // A browser's own form lands where the output says; fetch and the typed client read \`next\`.
107
+ native: { success: (output) => output.next },
116
108
  async handle() {
117
109
  const auth = appAuth();
118
110
  const token = useRequestCookie(auth.sessions.policy.cookieName);
@@ -121,7 +113,7 @@ export const destroySession = action({
121
113
  for (const [name, value] of signOutHeaders({ session: auth.sessions.policy })) {
122
114
  response.append(name, value);
123
115
  }
124
- return { ok: true, next: landAt('/'), revoked };
116
+ return { ok: true, next: '/', revoked };
125
117
  },
126
118
  });
127
119
  `;
package/wiki/Upgrading.md CHANGED
@@ -315,6 +315,7 @@ A setter still on a package's `.` barrel is `X_ADAPTER_PORT_INCOMPLETE` on the `
315
315
  | `x new`'s `ci.yml` uploads each `verify-part-*` document with `retention-days: 1` (**31.45.0**): the verdict job reads it in the same run, and GitHub's 90-day default let one adopter's parts fill the org's artifact storage quota until CI could not run | nothing: `x upgrade` applies codemod `ci-artifact-retention`; an upload that already sets `retention-days` is left as it is. Artifacts already stored keep their 90 days: delete them from the repository's Actions storage settings if the quota is already full |
316
316
  | codemod `ci-pinned-actions` pins any tagged major of `actions/checkout`, `cache`, `upload-artifact` and `download-artifact` (**31.45.0**), and adds `persist-credentials: false` to each checkout it pins, inside the step's own `with:` when it has one; 31.43–31.44 skipped a workflow on another major (`actions/checkout@v5`) | nothing: `x doctor` names it as `X_UPGRADE_CODEMODS_PENDING`, and `x upgrade --json` applies it. A SHA-pinned line and an action with no pin are never touched |
317
317
  | the shipped `undeclared-env` guard's fix changes (**31.45.0**), built in; its findings do not: `X_UNDECLARED_ENV` still opens with the `envSchema` line to paste, and adds a second branch for a build-time constant injected by `bun build --define process.env.X=…` (declare a global, `--define NAME=…`), which no deploy sets. A copy still in `guards/` keeps the old text until `x upgrade` migrates it to the release after 31.44.0 | nothing; for a `--define` constant, follow the second branch rather than declaring an env var |
318
+ | `x g sign-in --password` and `x g invite` declare `native: { success: (output) => output.next }` on their six actions and drop the `landAt()` helper (**31.46.0**); an app scaffolded before keeps its `landAt`, whose `setRedirect` still answers its forms with a 303 | nothing. Optional, to have one redirect path: on each action, add `native: { success: (output) => output.next }`, replace `landAt(x)` with `x`, delete `landAt` from `sign-in-flow.ts` / `invite.ts`, and move the test that asserted `request.redirect` to a form post through `httpServer({ routes: [toRoute(target)] }).fetch(…)` with `accept: text/html`, asserting `303` and the `Location` — a fresh `x g sign-in --password` writes that test. Then `x verify --only unit,manifest` |
318
319
 
319
320
  ## 29.x → 30.0.0, entry by entry
320
321