@fabrika/cli 0.9.0-dev.20 → 0.9.0-dev.22

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": "@fabrika/cli",
3
- "version": "0.9.0-dev.20",
3
+ "version": "0.9.0-dev.22",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,20 +31,20 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "zod": "^3.25.76",
34
- "@fabrika/app": "0.9.0-dev.20",
35
- "@fabrika/auth-core": "0.9.0-dev.20",
36
- "@fabrika/control-contract": "0.9.0-dev.20",
37
- "@fabrika/operations-contract": "0.9.0-dev.20",
38
- "@fabrika/provider-contract": "0.9.0-dev.20",
39
- "@fabrika/db": "0.9.0-dev.20",
40
- "@fabrika/platform": "0.9.0-dev.20",
41
- "@fabrika/platform-node": "0.9.0-dev.20",
42
- "@fabrika/check": "0.9.0-dev.20"
34
+ "@fabrika/app": "0.9.0-dev.22",
35
+ "@fabrika/auth-core": "0.9.0-dev.22",
36
+ "@fabrika/control-contract": "0.9.0-dev.22",
37
+ "@fabrika/operations-contract": "0.9.0-dev.22",
38
+ "@fabrika/provider-contract": "0.9.0-dev.22",
39
+ "@fabrika/db": "0.9.0-dev.22",
40
+ "@fabrika/platform": "0.9.0-dev.22",
41
+ "@fabrika/platform-node": "0.9.0-dev.22",
42
+ "@fabrika/check": "0.9.0-dev.22"
43
43
  },
44
44
  "peerDependencies": {
45
- "@fabrika/builder": "0.9.0-dev.20",
46
- "@fabrika/provider-cloudflare": "0.9.0-dev.20",
47
- "@fabrika/provider-zerops": "0.9.0-dev.20"
45
+ "@fabrika/builder": "0.9.0-dev.22",
46
+ "@fabrika/provider-cloudflare": "0.9.0-dev.22",
47
+ "@fabrika/provider-zerops": "0.9.0-dev.22"
48
48
  },
49
49
  "peerDependenciesMeta": {
50
50
  "@fabrika/builder": {
package/src/app-dev-ui.ts CHANGED
@@ -1,10 +1,10 @@
1
- // What `fabrika app dev` shows a person: the caller picker page, one mail a job sent, and the toolbar script it injects
1
+ // What `fabrika app dev` shows a person: the caller picker page, one mail a job or the stand-in IAM sent, and the toolbar script it injects
2
2
  // into every SPA page. All are self-contained (no font, no CDN) and take their colors from `--fd-*` custom properties, light and dark.
3
3
  // Every value here comes from the seed, the vocabulary or the request, so the page escapes it and the script only ever
4
4
  // sets `textContent` and `href`.
5
5
 
6
6
  import type { DevMail, SentInvitation } from '@fabrika/app/testing'
7
- import type { Locale } from '@fabrika/auth-core'
7
+ import type { Locale, RenderedMessage } from '@fabrika/auth-core'
8
8
 
9
9
  /** A label beside a caller: a role it holds (with the scope value it holds it in), or that it is external. */
10
10
  export interface Badge {
@@ -52,9 +52,20 @@ export interface LinkView {
52
52
  /** An invitation's state, or how a job's message ended: `sent` when the transport accepted it. */
53
53
  export type MailStatus = SentInvitation['status'] | 'sent' | 'not_sent' | 'unknown'
54
54
 
55
+ /** A link a row offers: accept an invitation, continue as its invitee, open a message. */
56
+ export interface MailAction {
57
+ readonly label: string
58
+ readonly href: string
59
+ }
60
+
55
61
  export interface MailView {
56
62
  readonly to: string
63
+ /** The subject the addressee reads: an invitation's in the language IAM writes it in. */
57
64
  readonly subject: string
65
+ /** The language the subject is written in when it is not the page's (an invitation's `mailLocale`); otherwise `null`. */
66
+ readonly subjectLocale: Locale | null
67
+ /** One more line of what it is: an invitation's role, scope value and language; `null` for a job's message. */
68
+ readonly note: string | null
58
69
  /** When it was sent, in ms: an invitation's latest send, or a job's handoff. */
59
70
  readonly at: number
60
71
  /** The key the job passed; `null` for an invitation. */
@@ -62,7 +73,8 @@ export interface MailView {
62
73
  readonly status: MailStatus
63
74
  /** The transport's refusal code (`provider_rejected`) when it did not accept; otherwise `null`. */
64
75
  readonly answer: string | null
65
- readonly action: { readonly label: string; readonly href: string } | null
76
+ /** The row's links, the main one first: the toolbar offers that one only. */
77
+ readonly actions: readonly MailAction[]
66
78
  }
67
79
 
68
80
  /** A request the application sent to the dev outbox. */
@@ -129,6 +141,8 @@ interface Strings {
129
141
  readonly key: string
130
142
  readonly transportKey: string
131
143
  readonly sentAt: string
144
+ readonly language: string
145
+ readonly state: string
132
146
  readonly answer: string
133
147
  readonly fromName: string
134
148
  readonly replyTo: string
@@ -185,6 +199,8 @@ const STRINGS: Readonly<Record<Locale, Strings>> = {
185
199
  key: 'Key',
186
200
  transportKey: 'Transport key',
187
201
  sentAt: 'Sent',
202
+ language: 'Language',
203
+ state: 'State',
188
204
  answer: 'Transport answer',
189
205
  fromName: 'From name',
190
206
  replyTo: 'Reply to',
@@ -239,6 +255,8 @@ const STRINGS: Readonly<Record<Locale, Strings>> = {
239
255
  key: 'Klíč',
240
256
  transportKey: 'Klíč transportu',
241
257
  sentAt: 'Odesláno',
258
+ language: 'Jazyk',
259
+ state: 'Stav',
242
260
  answer: 'Odpověď transportu',
243
261
  fromName: 'Jméno odesílatele',
244
262
  replyTo: 'Odpovědět na',
@@ -294,6 +312,8 @@ const STRINGS: Readonly<Record<Locale, Strings>> = {
294
312
  key: 'Ключ',
295
313
  transportKey: 'Ключ транспорту',
296
314
  sentAt: 'Надіслано',
315
+ language: 'Мова',
316
+ state: 'Стан',
297
317
  answer: 'Відповідь транспорту',
298
318
  fromName: 'Ім’я відправника',
299
319
  replyTo: 'Адреса для відповіді',
@@ -393,7 +413,7 @@ h2 + .grid, h2 + .rows { margin-top: 14px; }
393
413
  .row .meta .grants { font-family: var(--fd-mono); font-size: 12px; overflow-wrap: anywhere; }
394
414
  .row .control { display: flex; gap: 8px; align-items: center; }
395
415
  .row .meta.stack { flex-direction: column; align-items: flex-start; gap: 2px; }
396
- .actions { margin-top: 24px; }
416
+ .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
397
417
  .subject { font-weight: 600; color: var(--fd-text); font-size: 15px; }
398
418
  .to { font-size: 13px; color: var(--fd-muted); overflow-wrap: anywhere; }
399
419
  input { font: inherit; font-size: 14px; height: 34px; padding: 0 10px; width: 200px; border: 1px solid var(--fd-border-strong); border-radius: 8px; background: var(--fd-bg); color: var(--fd-text); }
@@ -426,7 +446,10 @@ const badges = (list: readonly Badge[]): string =>
426
446
  ? ''
427
447
  : `<div class="badges">${list.map((badge) => `<span class="badge ${badge.tone}">${escapeHtml(badge.text)}</span>`).join('')}</div>`
428
448
 
429
- function page(view: Pick<DevView, 'locale' | 'title' | 'current'>, heading: string, body: string): string {
449
+ /** The `lang` attribute of text written in `locale` on a page in another language; none when they agree. */
450
+ const langOf = (page: Locale, locale: Locale | null): string => (locale === null || locale === page ? '' : ` lang="${locale}"`)
451
+
452
+ function page(view: Pick<DevView, 'locale' | 'title' | 'current'>, heading: string, body: string, headingLocale: Locale | null = null): string {
430
453
  const text = stringsOf(view.locale)
431
454
  const now = view.current === null
432
455
  ? `<span>${escapeHtml(text.now)}:</span> <strong>${escapeHtml(text.nobody)}</strong>`
@@ -446,7 +469,7 @@ function page(view: Pick<DevView, 'locale' | 'title' | 'current'>, heading: stri
446
469
  escapeHtml(text.preview)
447
470
  }</span></span><span class="now">${now}</span></div></header>
448
471
  <main>
449
- <h1>${escapeHtml(heading)}</h1>
472
+ <h1${langOf(view.locale, headingLocale)}>${escapeHtml(heading)}</h1>
450
473
  ${body}
451
474
  </main>
452
475
  </body>
@@ -488,7 +511,7 @@ function roleRow(role: RoleView, text: Strings): string {
488
511
  }"><datalist id="${list}">${options}</datalist><button class="button quiet" type="submit">${escapeHtml(text.use)}</button></span></form>`
489
512
  }
490
513
 
491
- const actionButton = (action: { readonly label: string; readonly href: string } | null): string =>
514
+ const actionButton = (action: MailAction | null): string =>
492
515
  action === null ? '' : `<span class="control"><a class="button quiet" href="${escapeHtml(action.href)}">${escapeHtml(action.label)}</a></span>`
493
516
 
494
517
  function mailRows(mail: readonly MailView[], text: Strings, locale: Locale): string {
@@ -496,11 +519,11 @@ function mailRows(mail: readonly MailView[], text: Strings, locale: Locale): str
496
519
  return `<div class="rows">${
497
520
  mail.map((item) => {
498
521
  const when = [...(item.key === null ? [] : [item.key]), timeOf(locale, item.at)].join(' · ')
499
- return `<div class="row"><span class="meta stack"><span class="subject">${escapeHtml(item.subject)}</span><span class="to">${
500
- escapeHtml(text.to)
501
- }: ${escapeHtml(item.to)}</span><span class="to">${escapeHtml(when)}</span></span><span class="badge">${
522
+ return `<div class="row"><span class="meta stack"><span class="subject"${langOf(locale, item.subjectLocale)}>${escapeHtml(item.subject)}</span>${
523
+ item.note === null ? '' : `<span class="to">${escapeHtml(item.note)}</span>`
524
+ }<span class="to">${escapeHtml(text.to)}: ${escapeHtml(item.to)}</span><span class="to">${escapeHtml(when)}</span></span><span class="badge">${
502
525
  escapeHtml(text.status[item.status])
503
- }</span>${item.answer === null ? '' : `<span class="mono">${escapeHtml(item.answer)}</span>`}${actionButton(item.action)}</div>`
526
+ }</span>${item.answer === null ? '' : `<span class="mono">${escapeHtml(item.answer)}</span>`}${item.actions.map(actionButton).join('')}</div>`
504
527
  }).join('')
505
528
  }</div>`
506
529
  }
@@ -566,13 +589,44 @@ export function noticePage(view: Pick<DevView, 'locale' | 'title' | 'current' |
566
589
  }
567
590
 
568
591
  /**
569
- * One message a job handed to the mail stand-in: its fields, its text, and its HTML in a frame that runs no script, has no
570
- * origin and submits nothing. The frame's document inherits the page's policy (`default-src 'none'`), so it loads nothing.
592
+ * One message: its fields, its text, and its HTML in a frame that runs no script, has no origin and submits nothing. The
593
+ * frame's document inherits the page's policy (`default-src 'none'`), so it loads nothing, and a link in it opens
594
+ * nothing, so what the message offers is a button beside the way back. `messageLocale` is the message's language when it
595
+ * is not the page's.
571
596
  */
597
+ function messagePage(
598
+ view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>,
599
+ subject: string,
600
+ fields: readonly (readonly [string, string | null])[],
601
+ message: { readonly text: string; readonly html: string | null },
602
+ actions: readonly MailAction[] = [],
603
+ messageLocale: Locale | null = null,
604
+ ): string {
605
+ const text = stringsOf(view.locale)
606
+ const lang = langOf(view.locale, messageLocale)
607
+ const html = message.html === null
608
+ ? `<div class="empty">${escapeHtml(text.noHtml)}</div>`
609
+ : `<iframe class="mail-html" sandbox="" referrerpolicy="no-referrer" title="${escapeHtml(text.html)}" srcdoc="${
610
+ escapeHtml(message.html)
611
+ }"></iframe>`
612
+ return page(
613
+ view,
614
+ subject,
615
+ `<p class="actions"><a class="button quiet" href="${escapeHtml(view.pickerHref)}">${escapeHtml(text.back)}</a>${
616
+ actions.map((action) => `<a class="button quiet" href="${escapeHtml(action.href)}">${escapeHtml(action.label)}</a>`).join('')
617
+ }</p>
618
+ <dl class="fields">${fields.map(([name, value]) => (value === null ? '' : `<dt>${escapeHtml(name)}</dt><dd>${escapeHtml(value)}</dd>`)).join('')}</dl>
619
+ <section aria-labelledby="text"><h2 id="text">${escapeHtml(text.text)}</h2><pre class="text"${lang}>${escapeHtml(message.text)}</pre></section>
620
+ <section aria-labelledby="html"><h2 id="html">${escapeHtml(text.html)}</h2>${html}</section>`,
621
+ messageLocale,
622
+ )
623
+ }
624
+
625
+ /** One message a job handed to the mail stand-in. */
572
626
  export function mailPage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>, mail: DevMail): string {
573
627
  const text = stringsOf(view.locale)
574
628
  const status = mail.outcome === 'accepted' ? text.status.sent : text.status[mail.outcome]
575
- const fields: readonly (readonly [string, string | null])[] = [
629
+ return messagePage(view, mail.subject, [
576
630
  [text.to, mail.to],
577
631
  [text.subject, mail.subject],
578
632
  [text.fromName, mail.fromName],
@@ -581,17 +635,35 @@ export function mailPage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'p
581
635
  [text.transportKey, mail.transportKey],
582
636
  [text.answer, mail.answer === 'accepted' ? status : `${status} · ${mail.answer}`],
583
637
  [text.sentAt, timeOf(view.locale, Date.parse(mail.at))],
584
- ]
585
- const html = mail.html === null
586
- ? `<div class="empty">${escapeHtml(text.noHtml)}</div>`
587
- : `<iframe class="mail-html" sandbox="" referrerpolicy="no-referrer" title="${escapeHtml(text.html)}" srcdoc="${escapeHtml(mail.html)}"></iframe>`
588
- return page(
638
+ ], mail)
639
+ }
640
+
641
+ /**
642
+ * The e-mail the stand-in IAM would have sent for an invitation, as IAM writes it: in the language it chose
643
+ * (`mailLocale`), from the application's template of that language or IAM's own wording. The page around it speaks the
644
+ * application's language; only the message is the invitee's. `actions` are what its row offers (accept it, continue as
645
+ * its invitee).
646
+ */
647
+ export function invitationMailPage(
648
+ view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>,
649
+ invitation: SentInvitation,
650
+ mail: RenderedMessage,
651
+ actions: readonly MailAction[] = [],
652
+ ): string {
653
+ const text = stringsOf(view.locale)
654
+ return messagePage(
589
655
  view,
590
656
  mail.subject,
591
- `<p class="actions"><a class="button quiet" href="${escapeHtml(view.pickerHref)}">${escapeHtml(text.back)}</a></p>
592
- <dl class="fields">${fields.map(([name, value]) => (value === null ? '' : `<dt>${escapeHtml(name)}</dt><dd>${escapeHtml(value)}</dd>`)).join('')}</dl>
593
- <section aria-labelledby="text"><h2 id="text">${escapeHtml(text.text)}</h2><pre class="text">${escapeHtml(mail.text)}</pre></section>
594
- <section aria-labelledby="html"><h2 id="html">${escapeHtml(text.html)}</h2>${html}</section>`,
657
+ [
658
+ [text.to, invitation.email],
659
+ [text.subject, mail.subject],
660
+ [text.language, invitation.mailLocale],
661
+ [text.state, text.status[invitation.status]],
662
+ [text.sentAt, timeOf(view.locale, invitation.sentAt * 1000)],
663
+ ],
664
+ mail,
665
+ actions,
666
+ invitation.mailLocale,
595
667
  )
596
668
  }
597
669
 
@@ -615,7 +687,11 @@ export function toolbarState(view: DevView): unknown {
615
687
  current: view.current === null ? { name: text.nobody, detail: '' } : { name: view.current.name, detail: detail(view.current.badges) },
616
688
  personas: view.personas.map((persona) => ({ name: persona.name, detail: detail(persona.badges), href: persona.href, current: persona.current })),
617
689
  links: view.links.map((link) => ({ title: link.title, detail: link.description ?? '', href: link.href })),
618
- mail: view.mail.map((item) => ({ subject: item.subject, detail: `${text.to}: ${item.to} · ${text.status[item.status]}`, action: item.action })),
690
+ mail: view.mail.map((item) => ({
691
+ subject: item.subject,
692
+ detail: [...(item.note === null ? [] : [item.note]), `${text.to}: ${item.to}`, text.status[item.status]].join(' · '),
693
+ action: item.actions[0] ?? null,
694
+ })),
619
695
  outbox: view.outbox.map((item) => ({
620
696
  subject: item.subject,
621
697
  detail: `${text.to}: ${item.to}`,
package/src/app-dev.ts CHANGED
@@ -9,7 +9,15 @@ import { CONTRACT_FILE, IMPLEMENTATION_FILE } from '@fabrika/app/build'
9
9
  import { implementationAt } from '@fabrika/app/bun'
10
10
  import type { AnyContract } from '@fabrika/app/contract'
11
11
  import { BootError, type ContractImplementation } from '@fabrika/app/implement'
12
- import { DEV_OUTBOX_ORIGIN, type DevKit, devKit, type DevOutside, type LabelledTestCaller, type TestCaller } from '@fabrika/app/testing'
12
+ import {
13
+ DEV_OUTBOX_ORIGIN,
14
+ type DevKit,
15
+ devKit,
16
+ type DevOutside,
17
+ type LabelledTestCaller,
18
+ type SentInvitation,
19
+ type TestCaller,
20
+ } from '@fabrika/app/testing'
13
21
  import { sameOriginTarget } from '@fabrika/auth-core'
14
22
  import { type ApplicationDialect, applicationDialect, CONFIG_FILE } from '@fabrika/check'
15
23
  import { SqliteMigrationError } from '@fabrika/db/sqlite-migrate'
@@ -25,6 +33,8 @@ import {
25
33
  type Badge,
26
34
  type CurrentView,
27
35
  type DevView,
36
+ invitationMailPage,
37
+ type MailAction,
28
38
  mailPage,
29
39
  type MailView,
30
40
  newestMail,
@@ -293,6 +303,8 @@ async function serveDevKit(
293
303
  const callers = new Map<string, LabelledTestCaller>()
294
304
  const invitees = new Map<string, LabelledTestCaller>()
295
305
  const toolbar = toolbarScript(STATE_PATH)
306
+ const urlHost = options.host.includes(':') ? `[${options.host}]` : options.host
307
+ let port = options.port
296
308
 
297
309
  /** A path of this origin to go on to; anything else is the first SPA. */
298
310
  const nextOf = (next: string | null): string => (next !== null && sameOriginTarget(kit.origin, next) !== null ? next : firstSpa)
@@ -346,6 +358,25 @@ async function serveDevKit(
346
358
  }
347
359
 
348
360
  const chooseHref = (params: Record<string, string>, next: string): string => `${CHOOSE_PATH}?${new URLSearchParams({ ...params, next }).toString()}`
361
+ const acceptHref = (invitation: string, next: string): string => `${ACCEPT_PATH}?${new URLSearchParams({ invitation, next }).toString()}`
362
+
363
+ /**
364
+ * The e-mail the stand-in IAM would have sent for an invitation, in the language IAM chooses for it: its link is this
365
+ * server's accept route, where IAM's would be its own accept page, and `{{appUrl}}` is this server, where the
366
+ * application's registered return origin would be.
367
+ */
368
+ const invitationMailOf = (invitation: SentInvitation) => {
369
+ const origin = `http://${urlHost}:${port}`
370
+ return dev.invitationMail(invitation.id, new URL(acceptHref(invitation.id, firstSpa), origin).toString(), `${origin}/`)
371
+ }
372
+
373
+ /** What an invitation offers: accept it while it is open, or continue as the invitee who accepted it here. */
374
+ const invitationActions = (invitation: SentInvitation, next: string): MailAction[] =>
375
+ invitation.status === 'open'
376
+ ? [{ label: text.accept, href: acceptHref(invitation.id, next) }]
377
+ : invitation.status === 'accepted' && invitees.has(invitation.id)
378
+ ? [{ label: text.continueAs, href: chooseHref({ invitation: invitation.id }, next) }]
379
+ : []
349
380
 
350
381
  /** The values a membership role is offered in: the seed's, then those its personas hold. */
351
382
  const valuesOf = (dimension: string): { readonly value: string; readonly label: string }[] => {
@@ -383,27 +414,31 @@ async function serveDevKit(
383
414
  anonymousHref: chooseHref({ anonymous: '1' }, next),
384
415
  links: seeded.links.map((link) => ({ title: link.title, description: link.description, href: link.url })),
385
416
  mail: newestMail([
386
- ...dev.invitations().map((invitation): MailView => ({
387
- to: invitation.email,
388
- subject: text.invitation(invitation.role, scopeLabel(invitation.scope.type, invitation.scope.value)),
389
- at: invitation.sentAt * 1000,
390
- key: null,
391
- status: invitation.status,
392
- answer: null,
393
- action: invitation.status === 'open'
394
- ? { label: text.accept, href: `${ACCEPT_PATH}?${new URLSearchParams({ invitation: invitation.id, next }).toString()}` }
395
- : invitation.status === 'accepted' && invitees.has(invitation.id)
396
- ? { label: text.continueAs, href: chooseHref({ invitation: invitation.id }, next) }
397
- : null,
398
- })),
417
+ ...dev.invitations().map((invitation): MailView => {
418
+ const label = text.invitation(invitation.role, scopeLabel(invitation.scope.type, invitation.scope.value))
419
+ const mail = invitationMailOf(invitation)
420
+ return {
421
+ to: invitation.email,
422
+ subject: mail?.subject ?? label,
423
+ subjectLocale: mail === undefined ? null : invitation.mailLocale,
424
+ note: `${label} · ${invitation.mailLocale}`,
425
+ at: invitation.sentAt * 1000,
426
+ key: null,
427
+ status: invitation.status,
428
+ answer: null,
429
+ actions: [...invitationActions(invitation, next), { label: text.openMessage, href: `${MAIL_PATH}${invitation.id}` }],
430
+ }
431
+ }),
399
432
  ...dev.mails().map((sent): MailView => ({
400
433
  to: sent.to,
401
434
  subject: sent.subject,
435
+ subjectLocale: null,
402
436
  at: Date.parse(sent.at),
403
437
  key: sent.key,
404
438
  status: sent.outcome === 'accepted' ? 'sent' : sent.outcome,
405
439
  answer: sent.answer === 'accepted' ? null : sent.answer,
406
- action: { label: text.openMessage, href: `${MAIL_PATH}${sent.id}` },
440
+ note: null,
441
+ actions: [{ label: text.openMessage, href: `${MAIL_PATH}${sent.id}` }],
407
442
  })),
408
443
  ]),
409
444
  outbox: [...outbox.outbox()].reverse().map((message): OutboxView => ({ ...mailHeadOf(message), href: `${OUTBOX_PATH}${message.id}` })),
@@ -518,11 +553,18 @@ async function serveDevKit(
518
553
  })
519
554
  }
520
555
 
521
- /** A message a job handed to the mail stand-in: its fields, its text, and its HTML in a sandboxed frame. */
556
+ /**
557
+ * A message a job handed to the mail stand-in, or the e-mail of an invitation the stand-in IAM sent: its fields, its
558
+ * text, and its HTML in a sandboxed frame.
559
+ */
522
560
  const mailMessage = (request: Request, path: string): Response => {
561
+ const view = viewOf(choiceOf(request), firstSpa)
523
562
  const sent = dev.mails().find((candidate) => `${MAIL_PATH}${candidate.id}` === path)
524
- if (sent === undefined) return plain(404, 'no such mail in app dev')
525
- return new Response(mailPage(viewOf(choiceOf(request), firstSpa), sent), { headers: PAGE_HEADERS })
563
+ if (sent !== undefined) return new Response(mailPage(view, sent), { headers: PAGE_HEADERS })
564
+ const invitation = dev.invitations().find((candidate) => `${MAIL_PATH}${candidate.id}` === path)
565
+ const mail = invitation === undefined ? undefined : invitationMailOf(invitation)
566
+ if (invitation === undefined || mail === undefined) return plain(404, 'no such mail in app dev')
567
+ return new Response(invitationMailPage(view, invitation, mail, invitationActions(invitation, firstSpa)), { headers: PAGE_HEADERS })
526
568
  }
527
569
 
528
570
  const devRoute = (request: Request, url: URL): Response | null => {
@@ -549,7 +591,6 @@ async function serveDevKit(
549
591
  }
550
592
  }
551
593
 
552
- let port = options.port
553
594
  const server = listen({
554
595
  hostname: options.host,
555
596
  port: options.port,
@@ -567,9 +608,8 @@ async function serveDevKit(
567
608
  error: () => plain(500, 'app dev could not serve the request'),
568
609
  })
569
610
  port = server.port ?? options.port
570
- const host = options.host.includes(':') ? `[${options.host}]` : options.host
571
611
  return {
572
- url: `http://${host}:${port}/`,
612
+ url: `http://${urlHost}:${port}/`,
573
613
  seeded: { personas: seeded.personas.length, links: seeded.links.length },
574
614
  async stop() {
575
615
  try {
package/src/control.ts CHANGED
@@ -82,8 +82,9 @@ Usage:
82
82
  fabrika control runs log --run=<id>
83
83
 
84
84
  \`register\` CREATES an app and refuses a second one with the same id. Re-registering a changed
85
- manifest — a new \`zerops.yaml\`, a new import document — is \`apps environments put\`, which replaces
86
- one environment's envelopes and leaves the app row alone.
85
+ manifest — a new import document, or a new \`zerops.yaml\` of an app without a contract — is
86
+ \`apps environments put\`, which replaces one environment's envelopes and leaves the app row alone. A
87
+ contract app's deploy registers the \`zerops.yaml\` of its commit itself.
87
88
 
88
89
  A manifest that publishes the app through the namespace proxy is routed by HOST, so \`--domain\` is
89
90
  REQUIRED for it — on \`register\` and on \`apps environments put\` alike — and a registration without one is
@@ -1,5 +1,5 @@
1
1
  import type { DevMail, SentInvitation } from '@fabrika/app/testing';
2
- import type { Locale } from '@fabrika/auth-core';
2
+ import type { Locale, RenderedMessage } from '@fabrika/auth-core';
3
3
  /** A label beside a caller: a role it holds (with the scope value it holds it in), or that it is external. */
4
4
  export interface Badge {
5
5
  readonly text: string;
@@ -44,9 +44,19 @@ export interface LinkView {
44
44
  }
45
45
  /** An invitation's state, or how a job's message ended: `sent` when the transport accepted it. */
46
46
  export type MailStatus = SentInvitation['status'] | 'sent' | 'not_sent' | 'unknown';
47
+ /** A link a row offers: accept an invitation, continue as its invitee, open a message. */
48
+ export interface MailAction {
49
+ readonly label: string;
50
+ readonly href: string;
51
+ }
47
52
  export interface MailView {
48
53
  readonly to: string;
54
+ /** The subject the addressee reads: an invitation's in the language IAM writes it in. */
49
55
  readonly subject: string;
56
+ /** The language the subject is written in when it is not the page's (an invitation's `mailLocale`); otherwise `null`. */
57
+ readonly subjectLocale: Locale | null;
58
+ /** One more line of what it is: an invitation's role, scope value and language; `null` for a job's message. */
59
+ readonly note: string | null;
50
60
  /** When it was sent, in ms: an invitation's latest send, or a job's handoff. */
51
61
  readonly at: number;
52
62
  /** The key the job passed; `null` for an invitation. */
@@ -54,10 +64,8 @@ export interface MailView {
54
64
  readonly status: MailStatus;
55
65
  /** The transport's refusal code (`provider_rejected`) when it did not accept; otherwise `null`. */
56
66
  readonly answer: string | null;
57
- readonly action: {
58
- readonly label: string;
59
- readonly href: string;
60
- } | null;
67
+ /** The row's links, the main one first: the toolbar offers that one only. */
68
+ readonly actions: readonly MailAction[];
61
69
  }
62
70
  /** A request the application sent to the dev outbox. */
63
71
  export interface OutboxView {
@@ -114,6 +122,8 @@ interface Strings {
114
122
  readonly key: string;
115
123
  readonly transportKey: string;
116
124
  readonly sentAt: string;
125
+ readonly language: string;
126
+ readonly state: string;
117
127
  readonly answer: string;
118
128
  readonly fromName: string;
119
129
  readonly replyTo: string;
@@ -132,11 +142,15 @@ export declare const stringsOf: (locale: Locale) => Strings;
132
142
  export declare function pickerPage(view: DevView): string;
133
143
  /** A refusal of a dev route, with the way back to the picker. */
134
144
  export declare function noticePage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>, heading: string, message: string): string;
145
+ /** One message a job handed to the mail stand-in. */
146
+ export declare function mailPage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>, mail: DevMail): string;
135
147
  /**
136
- * One message a job handed to the mail stand-in: its fields, its text, and its HTML in a frame that runs no script, has no
137
- * origin and submits nothing. The frame's document inherits the page's policy (`default-src 'none'`), so it loads nothing.
148
+ * The e-mail the stand-in IAM would have sent for an invitation, as IAM writes it: in the language it chose
149
+ * (`mailLocale`), from the application's template of that language or IAM's own wording. The page around it speaks the
150
+ * application's language; only the message is the invitee's. `actions` are what its row offers (accept it, continue as
151
+ * its invitee).
138
152
  */
139
- export declare function mailPage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>, mail: DevMail): string;
153
+ export declare function invitationMailPage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>, invitation: SentInvitation, mail: RenderedMessage, actions?: readonly MailAction[]): string;
140
154
  /** What the toolbar renders: its labels and the view, with every caller already put into words. */
141
155
  export declare function toolbarState(view: DevView): unknown;
142
156
  /** The toolbar: a pill in the bottom corner, in a shadow root so neither the page's styles nor its layout meet it. */
@@ -1,6 +1,6 @@
1
1
  import { type InferRpcClient, type RpcFetch } from '@fabrika/app';
2
2
  import type { AppEnvDto, ControlRpcContract, DeploymentNamespaceDto, PlanDeploymentNamespaceResponse } from '@fabrika/control-contract';
3
- declare const USAGE = "fabrika control \u2014 operate the Delivery control plane\n\nUsage:\n fabrika control key issue --label=<name> --permissions=<a,b,c> --expires-in=<seconds> [--iam-url=<origin>]\n fabrika control apps list\n fabrika control apps get --app=<id>\n fabrika control apps environments list --app=<id>\n fabrika control apps environments put --provider=<name> --app=<id> --env=<name> --manifest=<path>\n [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>] [--namespace=<id>]\n [--cross-origin=<origin> ...] [--kind=standard|dev]\n fabrika control apps variables list --app=<id>\n fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>] [--not-secret]\n fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]\n fabrika control apps secrets list --app=<id>\n fabrika control apps secrets put --app=<id> --name=<name> [--env=<name>] (the value on stdin)\n fabrika control apps secrets delete --app=<id> --name=<name> [--env=<name>]\n fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>\n [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]\n [--namespace=<id>] [--installation-id=<n|none>] [--cross-origin=<origin> ...]\n fabrika control namespaces list\n fabrika control namespaces get --namespace=<id>\n fabrika control namespaces plan --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]\n fabrika control namespaces create --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]\n fabrika control namespaces reconcile --namespace=<id>\n fabrika control namespaces update --namespace=<id> --proxy-source=current\n fabrika control namespaces remove --namespace=<id>\n fabrika control namespaces release-claims --namespace=<id> --app=<id> --env=<name>\n fabrika control deploy --app=<id> --env=<name> [--ref=<ref>]\n fabrika control runs list [--app=<id>] [--env=<name>] [--limit=<n>]\n fabrika control runs get --run=<id>\n fabrika control runs log --run=<id>\n\n`register` CREATES an app and refuses a second one with the same id. Re-registering a changed\nmanifest \u2014 a new `zerops.yaml`, a new import document \u2014 is `apps environments put`, which replaces\none environment's envelopes and leaves the app row alone.\n\nA manifest that publishes the app through the namespace proxy is routed by HOST, so `--domain` is\nREQUIRED for it \u2014 on `register` and on `apps environments put` alike \u2014 and a registration without one is\nrefused before anything is created. `namespaces get` lists the hosts a `zerops-subdomain` namespace\nserves and which of them are still free; a custom-domain namespace serves the domain you bound to its\nproxy. A manifest with no proxy target needs no domain.\n\nA variable's value is stored and printed in clear, so `apps variables put` refuses one that looks like a\ncredential (by its name, such as `*_TOKEN` or `*_PASSWORD`, or by its value) and names `apps secrets put` instead.\n`--not-secret` stores it anyway, for a value you have checked is not one. A secret's value is write-only: `apps secrets put`\nreads it from STDIN, never from a flag, so it reaches neither shell history nor a process listing, and\none trailing newline is dropped. No command prints it back; `apps secrets list` shows names, scope and\nstorage only. Generate one in the pipe:\n\n openssl rand -base64 32 | fabrika control apps secrets put --app=<id> --name=<name>\n\n`--public-origin` is where IAM may return a signed-in person: without one, sign-in to the environment is\nrefused. When `register` is given none and the namespace lists `--domain` among its hosts, it sets\n`https://<domain>` and says so on stderr. A custom domain needs the flag.\n\n`--cross-origin` names an origin whose pages may call the environment's cross-origin endpoints (ADR-0022), and\nrepeats: the flags given are the environment's whole list. Each is an exact origin with a literal host\n(`https://app.example.com`; `http://` only for a local one), never the environment's own domain, at most 16.\n`apps environments put` without the flag keeps the stored list, and a lone empty `--cross-origin=` clears it.\nOn Zerops the change reaches the namespace proxy at once; on Cloudflare the next deploy of the environment\napplies it.\n\n`--installation-id` has three states: omitted resolves the installation from the repository owner's\nconnected GitHub App, `none` registers an anonymous PUBLIC repository source, and a number names one\ninstallation outright. With `none`, control reads the repository once without a token and refuses one\nGitHub hides: a private repository needs the GitHub App connected in the console first.\n\n`--trigger-ref` is the git ref whose push deploys the environment; without it the environment deploys only\non `deploy`. A bare name is a branch: `--trigger-ref=deploy/prod` is stored as `refs/heads/deploy/prod`.\nA full ref is kept as given: `refs/heads/<branch>`, `refs/tags/<tag>`, or a `*` glob such as\n`refs/tags/v*`, which deploys every matching tag. A tag always needs the `refs/tags/` form. Each\nenvironment of an app needs its own trigger ref. Branches named `fabrika/\u2026` are reserved for MCP\nworkspaces and are never a trigger ref.\n\nNamespace placement options, each defaulting to what the preset would choose:\n\n --project=<name> the provider project the namespace owns; on Zerops the default is\n fabrika-<env>-<namespace id>, beside the installation's fabrika-<env>\n --core-package=<LIGHT|SERIOUS> defaults to LIGHT on every environment, `prod` included (ADR-0038).\n SERIOUS is a deliberate choice: a project cannot be downgraded again\n --public-access=<custom-domain|zerops-subdomain>\n --exclusive-app=<id> required by, and only by, the `full` preset\n --postgres-type=<type> the `cheap` preset's shared PostgreSQL; on Zerops postgresql:single@18\n (default) or postgresql:ha@18, which keeps its data through a node loss.\n Fixed once created\n --postgres-profile=<profile> its profile, given together with --postgres-type: oltp-hobby for single,\n oltp-staging (about $11) or oltp-production (about $72) for HA\n\n`namespaces plan` is a preview and changes nothing. It prints one `<path>\\t<value>` row per field of\nthe plan, keyed by its path in `--json`; a multi-line value such as the proxy's descriptor file is shown\nby size only. `namespaces create` commits that exact plan \u2014 the\nsame two steps the console's form takes \u2014 and returns as soon as the placement is recorded: provisioning\nruns behind the control queue and takes minutes, so the state comes back `pending`. Follow it with\n`namespaces get` or `namespaces list`; nothing needs to stay connected. `namespaces remove` frees the id\nof a placement no application is registered in. It deletes nothing at the provider and prints, on stderr,\nthe provider resources it stopped tracking. `namespaces update --proxy-source=current` re-pins a placement's\nproxy to the source this control plane deploys new placements from \u2014 a placement keeps the one it was created\nwith until you do \u2014 and queues the reconcile that rebuilds the proxy from it; a `failed` placement accepts it.\n\n`namespaces release-claims` frees the resource names one app environment holds in a placement, which an\nenvironment or app delete otherwise refuses over. Delete those resources at the provider first: the release\nreads each one back and refuses, naming it, while any still exists. It prints one released key per line.\n\nEvery command accepts --json, which prints the procedure's result verbatim.\n\nThe control origin is not a credential and takes either form:\n\n --url=<origin> FABRIKA_CONTROL_URL\n\nCredentials are read from the ENVIRONMENT ONLY and have no flag, so they cannot reach a CI log or a\nprocess listing:\n\n FABRIKA_CONTROL_KEY required a machine `px_` credential for the control app\n\n`key issue` mints that credential and therefore authenticates differently \u2014 it presents the\ninstallation's IAM RPC key as transport authentication and its provisioning key as the ISSUING\ncredential. Every key expires: `--expires-in` is required and at most 2592000 (30 days). Both\ncredentials are read from the environment only:\n\n FABRIKA_IAM_RPC_URL required IAM's PUBLIC origin, or --iam-url\n FABRIKA_IAM_RPC_KEY required the installation's IAM RPC key\n FABRIKA_IAM_PROVISIONING_KEY required the installation's seeded `px_` provisioning key\n FABRIKA_CONTROL_APP_ID optional the control app's IAM id (default `vozka`)\n\nThe PUBLIC origin is the `https://` address the installation answers on \u2014 the one `platform admin`\nand `platform init` print in their closing block, and the value `FABRIKA_IAM_ISSUER` holds on the\ncontrol service. It is NOT the private hostname the services use between themselves: `http://iam:3000`\nresolves inside the provider's project and nowhere else, so from here it only ever fails to connect.\n\nConnecting a GitHub source is NOT here and will not be: App creation is a browser flow whose\nauthorization requires a human principal (ADR-0029). Use Settings \u2192 Source in the console.\n";
3
+ declare const USAGE = "fabrika control \u2014 operate the Delivery control plane\n\nUsage:\n fabrika control key issue --label=<name> --permissions=<a,b,c> --expires-in=<seconds> [--iam-url=<origin>]\n fabrika control apps list\n fabrika control apps get --app=<id>\n fabrika control apps environments list --app=<id>\n fabrika control apps environments put --provider=<name> --app=<id> --env=<name> --manifest=<path>\n [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>] [--namespace=<id>]\n [--cross-origin=<origin> ...] [--kind=standard|dev]\n fabrika control apps variables list --app=<id>\n fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>] [--not-secret]\n fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]\n fabrika control apps secrets list --app=<id>\n fabrika control apps secrets put --app=<id> --name=<name> [--env=<name>] (the value on stdin)\n fabrika control apps secrets delete --app=<id> --name=<name> [--env=<name>]\n fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>\n [--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]\n [--namespace=<id>] [--installation-id=<n|none>] [--cross-origin=<origin> ...]\n fabrika control namespaces list\n fabrika control namespaces get --namespace=<id>\n fabrika control namespaces plan --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]\n fabrika control namespaces create --namespace=<id> --env=<name> --preset=<cheap|mid|full> [placement]\n fabrika control namespaces reconcile --namespace=<id>\n fabrika control namespaces update --namespace=<id> --proxy-source=current\n fabrika control namespaces remove --namespace=<id>\n fabrika control namespaces release-claims --namespace=<id> --app=<id> --env=<name>\n fabrika control deploy --app=<id> --env=<name> [--ref=<ref>]\n fabrika control runs list [--app=<id>] [--env=<name>] [--limit=<n>]\n fabrika control runs get --run=<id>\n fabrika control runs log --run=<id>\n\n`register` CREATES an app and refuses a second one with the same id. Re-registering a changed\nmanifest \u2014 a new import document, or a new `zerops.yaml` of an app without a contract \u2014 is\n`apps environments put`, which replaces one environment's envelopes and leaves the app row alone. A\ncontract app's deploy registers the `zerops.yaml` of its commit itself.\n\nA manifest that publishes the app through the namespace proxy is routed by HOST, so `--domain` is\nREQUIRED for it \u2014 on `register` and on `apps environments put` alike \u2014 and a registration without one is\nrefused before anything is created. `namespaces get` lists the hosts a `zerops-subdomain` namespace\nserves and which of them are still free; a custom-domain namespace serves the domain you bound to its\nproxy. A manifest with no proxy target needs no domain.\n\nA variable's value is stored and printed in clear, so `apps variables put` refuses one that looks like a\ncredential (by its name, such as `*_TOKEN` or `*_PASSWORD`, or by its value) and names `apps secrets put` instead.\n`--not-secret` stores it anyway, for a value you have checked is not one. A secret's value is write-only: `apps secrets put`\nreads it from STDIN, never from a flag, so it reaches neither shell history nor a process listing, and\none trailing newline is dropped. No command prints it back; `apps secrets list` shows names, scope and\nstorage only. Generate one in the pipe:\n\n openssl rand -base64 32 | fabrika control apps secrets put --app=<id> --name=<name>\n\n`--public-origin` is where IAM may return a signed-in person: without one, sign-in to the environment is\nrefused. When `register` is given none and the namespace lists `--domain` among its hosts, it sets\n`https://<domain>` and says so on stderr. A custom domain needs the flag.\n\n`--cross-origin` names an origin whose pages may call the environment's cross-origin endpoints (ADR-0022), and\nrepeats: the flags given are the environment's whole list. Each is an exact origin with a literal host\n(`https://app.example.com`; `http://` only for a local one), never the environment's own domain, at most 16.\n`apps environments put` without the flag keeps the stored list, and a lone empty `--cross-origin=` clears it.\nOn Zerops the change reaches the namespace proxy at once; on Cloudflare the next deploy of the environment\napplies it.\n\n`--installation-id` has three states: omitted resolves the installation from the repository owner's\nconnected GitHub App, `none` registers an anonymous PUBLIC repository source, and a number names one\ninstallation outright. With `none`, control reads the repository once without a token and refuses one\nGitHub hides: a private repository needs the GitHub App connected in the console first.\n\n`--trigger-ref` is the git ref whose push deploys the environment; without it the environment deploys only\non `deploy`. A bare name is a branch: `--trigger-ref=deploy/prod` is stored as `refs/heads/deploy/prod`.\nA full ref is kept as given: `refs/heads/<branch>`, `refs/tags/<tag>`, or a `*` glob such as\n`refs/tags/v*`, which deploys every matching tag. A tag always needs the `refs/tags/` form. Each\nenvironment of an app needs its own trigger ref. Branches named `fabrika/\u2026` are reserved for MCP\nworkspaces and are never a trigger ref.\n\nNamespace placement options, each defaulting to what the preset would choose:\n\n --project=<name> the provider project the namespace owns; on Zerops the default is\n fabrika-<env>-<namespace id>, beside the installation's fabrika-<env>\n --core-package=<LIGHT|SERIOUS> defaults to LIGHT on every environment, `prod` included (ADR-0038).\n SERIOUS is a deliberate choice: a project cannot be downgraded again\n --public-access=<custom-domain|zerops-subdomain>\n --exclusive-app=<id> required by, and only by, the `full` preset\n --postgres-type=<type> the `cheap` preset's shared PostgreSQL; on Zerops postgresql:single@18\n (default) or postgresql:ha@18, which keeps its data through a node loss.\n Fixed once created\n --postgres-profile=<profile> its profile, given together with --postgres-type: oltp-hobby for single,\n oltp-staging (about $11) or oltp-production (about $72) for HA\n\n`namespaces plan` is a preview and changes nothing. It prints one `<path>\\t<value>` row per field of\nthe plan, keyed by its path in `--json`; a multi-line value such as the proxy's descriptor file is shown\nby size only. `namespaces create` commits that exact plan \u2014 the\nsame two steps the console's form takes \u2014 and returns as soon as the placement is recorded: provisioning\nruns behind the control queue and takes minutes, so the state comes back `pending`. Follow it with\n`namespaces get` or `namespaces list`; nothing needs to stay connected. `namespaces remove` frees the id\nof a placement no application is registered in. It deletes nothing at the provider and prints, on stderr,\nthe provider resources it stopped tracking. `namespaces update --proxy-source=current` re-pins a placement's\nproxy to the source this control plane deploys new placements from \u2014 a placement keeps the one it was created\nwith until you do \u2014 and queues the reconcile that rebuilds the proxy from it; a `failed` placement accepts it.\n\n`namespaces release-claims` frees the resource names one app environment holds in a placement, which an\nenvironment or app delete otherwise refuses over. Delete those resources at the provider first: the release\nreads each one back and refuses, naming it, while any still exists. It prints one released key per line.\n\nEvery command accepts --json, which prints the procedure's result verbatim.\n\nThe control origin is not a credential and takes either form:\n\n --url=<origin> FABRIKA_CONTROL_URL\n\nCredentials are read from the ENVIRONMENT ONLY and have no flag, so they cannot reach a CI log or a\nprocess listing:\n\n FABRIKA_CONTROL_KEY required a machine `px_` credential for the control app\n\n`key issue` mints that credential and therefore authenticates differently \u2014 it presents the\ninstallation's IAM RPC key as transport authentication and its provisioning key as the ISSUING\ncredential. Every key expires: `--expires-in` is required and at most 2592000 (30 days). Both\ncredentials are read from the environment only:\n\n FABRIKA_IAM_RPC_URL required IAM's PUBLIC origin, or --iam-url\n FABRIKA_IAM_RPC_KEY required the installation's IAM RPC key\n FABRIKA_IAM_PROVISIONING_KEY required the installation's seeded `px_` provisioning key\n FABRIKA_CONTROL_APP_ID optional the control app's IAM id (default `vozka`)\n\nThe PUBLIC origin is the `https://` address the installation answers on \u2014 the one `platform admin`\nand `platform init` print in their closing block, and the value `FABRIKA_IAM_ISSUER` holds on the\ncontrol service. It is NOT the private hostname the services use between themselves: `http://iam:3000`\nresolves inside the provider's project and nowhere else, so from here it only ever fails to connect.\n\nConnecting a GitHub source is NOT here and will not be: App creation is a browser flow whose\nauthorization requires a human principal (ADR-0029). Use Settings \u2192 Source in the console.\n";
4
4
  interface Flags {
5
5
  readonly values: ReadonlyMap<string, string>;
6
6
  /** Every value of every option, in order; `values` keeps the last. Only a repeatable option reads it. */