@fabrika/cli 0.4.8 → 0.5.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 +12 -12
- package/src/app-dev-outside.ts +5 -3
- package/src/app-dev-ui.ts +173 -21
- package/src/app-dev.ts +35 -13
- package/src/control.ts +3 -2
- package/src/namespace.ts +35 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,19 +30,19 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"zod": "^3.25.76",
|
|
33
|
-
"@fabrika/app": "0.
|
|
34
|
-
"@fabrika/auth-core": "0.
|
|
35
|
-
"@fabrika/control-contract": "0.
|
|
36
|
-
"@fabrika/provider-contract": "0.
|
|
37
|
-
"@fabrika/db": "0.
|
|
38
|
-
"@fabrika/platform": "0.
|
|
39
|
-
"@fabrika/platform-node": "0.
|
|
40
|
-
"@fabrika/check": "0.
|
|
33
|
+
"@fabrika/app": "0.5.0",
|
|
34
|
+
"@fabrika/auth-core": "0.5.0",
|
|
35
|
+
"@fabrika/control-contract": "0.5.0",
|
|
36
|
+
"@fabrika/provider-contract": "0.5.0",
|
|
37
|
+
"@fabrika/db": "0.5.0",
|
|
38
|
+
"@fabrika/platform": "0.5.0",
|
|
39
|
+
"@fabrika/platform-node": "0.5.0",
|
|
40
|
+
"@fabrika/check": "0.5.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@fabrika/builder": "0.
|
|
44
|
-
"@fabrika/provider-cloudflare": "0.
|
|
45
|
-
"@fabrika/provider-zerops": "0.
|
|
43
|
+
"@fabrika/builder": "0.5.0",
|
|
44
|
+
"@fabrika/provider-cloudflare": "0.5.0",
|
|
45
|
+
"@fabrika/provider-zerops": "0.5.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"@fabrika/builder": {
|
package/src/app-dev-outside.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// What `fabrika app dev` stands in for outside the application: the dev outbox, which captures every request the
|
|
2
|
-
// process sends to `DEV_OUTBOX_ORIGIN` (
|
|
2
|
+
// process sends to `DEV_OUTBOX_ORIGIN` (another provider's stand-in), and `dev/dev.env`, the application's variables.
|
|
3
3
|
|
|
4
|
-
import { DEV_OUTBOX_ORIGIN, type DevOutboxMessage
|
|
4
|
+
import { DEV_OUTBOX_ORIGIN, type DevOutboxMessage } from '@fabrika/app/testing'
|
|
5
5
|
import { existsSync, readFileSync } from 'node:fs'
|
|
6
6
|
import { join } from 'node:path'
|
|
7
7
|
import { z } from 'zod/v4'
|
|
@@ -46,7 +46,9 @@ export function readDevEnv(root: string): Readonly<Record<string, string>> {
|
|
|
46
46
|
return variables
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export interface DevOutbox
|
|
49
|
+
export interface DevOutbox {
|
|
50
|
+
/** Every request sent to `DEV_OUTBOX_ORIGIN` so far, oldest first. */
|
|
51
|
+
outbox(): readonly DevOutboxMessage[]
|
|
50
52
|
/** Captures the process's requests to `DEV_OUTBOX_ORIGIN` until the returned function restores `fetch`. */
|
|
51
53
|
install(): () => void
|
|
52
54
|
}
|
package/src/app-dev-ui.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// What `fabrika app dev` shows a person: the caller picker page, and the toolbar script it injects
|
|
2
|
-
//
|
|
1
|
+
// What `fabrika app dev` shows a person: the caller picker page, one mail a job sent, and the toolbar script it injects
|
|
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
|
+
import type { DevMail, SentInvitation } from '@fabrika/app/testing'
|
|
6
7
|
import type { Locale } from '@fabrika/auth-core'
|
|
7
8
|
|
|
8
9
|
/** A label beside a caller: a role it holds (with the scope value it holds it in), or that it is external. */
|
|
@@ -48,14 +49,39 @@ export interface LinkView {
|
|
|
48
49
|
readonly href: string
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
/** An invitation's state, or how a job's message ended: `sent` when the transport accepted it. */
|
|
53
|
+
export type MailStatus = SentInvitation['status'] | 'sent' | 'not_sent' | 'unknown'
|
|
54
|
+
|
|
51
55
|
export interface MailView {
|
|
52
56
|
readonly to: string
|
|
53
57
|
readonly subject: string
|
|
54
|
-
/**
|
|
55
|
-
readonly
|
|
58
|
+
/** When it was sent, in ms: an invitation's latest send, or a job's handoff. */
|
|
59
|
+
readonly at: number
|
|
60
|
+
/** The key the job passed; `null` for an invitation. */
|
|
61
|
+
readonly key: string | null
|
|
62
|
+
readonly status: MailStatus
|
|
63
|
+
/** The transport's refusal code (`provider_rejected`) when it did not accept; otherwise `null`. */
|
|
64
|
+
readonly answer: string | null
|
|
56
65
|
readonly action: { readonly label: string; readonly href: string } | null
|
|
57
66
|
}
|
|
58
67
|
|
|
68
|
+
/** A request the application sent to the dev outbox. */
|
|
69
|
+
export interface OutboxView {
|
|
70
|
+
readonly to: string
|
|
71
|
+
readonly subject: string
|
|
72
|
+
readonly href: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const MAX_MAIL_ROWS = 200
|
|
76
|
+
|
|
77
|
+
/** Newest first, at most `MAX_MAIL_ROWS`. On equal times, the row given later comes first. */
|
|
78
|
+
export function newestMail(rows: readonly MailView[]): MailView[] {
|
|
79
|
+
return rows.map((row, index) => ({ row, index }))
|
|
80
|
+
.sort((left, right) => right.row.at - left.row.at || right.index - left.index)
|
|
81
|
+
.slice(0, MAX_MAIL_ROWS)
|
|
82
|
+
.map(({ row }) => row)
|
|
83
|
+
}
|
|
84
|
+
|
|
59
85
|
export interface DevView {
|
|
60
86
|
readonly locale: Locale
|
|
61
87
|
/** The application's display name, or its id. */
|
|
@@ -66,6 +92,7 @@ export interface DevView {
|
|
|
66
92
|
readonly anonymousHref: string
|
|
67
93
|
readonly links: readonly LinkView[]
|
|
68
94
|
readonly mail: readonly MailView[]
|
|
95
|
+
readonly outbox: readonly OutboxView[]
|
|
69
96
|
readonly pickerHref: string
|
|
70
97
|
}
|
|
71
98
|
|
|
@@ -96,8 +123,21 @@ interface Strings {
|
|
|
96
123
|
readonly accept: string
|
|
97
124
|
readonly continueAs: string
|
|
98
125
|
readonly openMessage: string
|
|
99
|
-
readonly status: Readonly<Record<
|
|
126
|
+
readonly status: Readonly<Record<MailStatus, string>>
|
|
100
127
|
readonly to: string
|
|
128
|
+
readonly subject: string
|
|
129
|
+
readonly key: string
|
|
130
|
+
readonly transportKey: string
|
|
131
|
+
readonly sentAt: string
|
|
132
|
+
readonly answer: string
|
|
133
|
+
readonly fromName: string
|
|
134
|
+
readonly replyTo: string
|
|
135
|
+
readonly text: string
|
|
136
|
+
readonly html: string
|
|
137
|
+
readonly noHtml: string
|
|
138
|
+
readonly outbox: string
|
|
139
|
+
readonly outboxText: string
|
|
140
|
+
readonly noOutbox: string
|
|
101
141
|
readonly picker: string
|
|
102
142
|
readonly close: string
|
|
103
143
|
readonly back: string
|
|
@@ -125,14 +165,35 @@ const STRINGS: Readonly<Record<Locale, Strings>> = {
|
|
|
125
165
|
linksText: 'Each opens as the holder of a link the application issued.',
|
|
126
166
|
openLink: 'Open as link holder',
|
|
127
167
|
mail: 'Mail',
|
|
128
|
-
mailText:
|
|
168
|
+
mailText: "The invitations the stand-in IAM would have e-mailed, and the mail the application's jobs sent.",
|
|
129
169
|
noMail: 'Nothing has been sent yet.',
|
|
130
170
|
invitation: (role, scope) => `Invitation: ${role} in ${scope}`,
|
|
131
171
|
accept: 'Accept invitation',
|
|
132
172
|
continueAs: 'Continue as this person',
|
|
133
173
|
openMessage: 'Open the message',
|
|
134
|
-
status: {
|
|
174
|
+
status: {
|
|
175
|
+
open: 'waiting',
|
|
176
|
+
accepted: 'accepted',
|
|
177
|
+
cancelled: 'cancelled',
|
|
178
|
+
expired: 'expired',
|
|
179
|
+
sent: 'sent',
|
|
180
|
+
not_sent: 'not sent',
|
|
181
|
+
unknown: 'may have been sent',
|
|
182
|
+
},
|
|
135
183
|
to: 'To',
|
|
184
|
+
subject: 'Subject',
|
|
185
|
+
key: 'Key',
|
|
186
|
+
transportKey: 'Transport key',
|
|
187
|
+
sentAt: 'Sent',
|
|
188
|
+
answer: 'Transport answer',
|
|
189
|
+
fromName: 'From name',
|
|
190
|
+
replyTo: 'Reply to',
|
|
191
|
+
text: 'Text',
|
|
192
|
+
html: 'HTML',
|
|
193
|
+
noHtml: 'The message has no HTML part.',
|
|
194
|
+
outbox: 'Dev outbox',
|
|
195
|
+
outboxText: 'The requests the application sent to the dev outbox, newest first.',
|
|
196
|
+
noOutbox: 'Nothing has reached the dev outbox yet.',
|
|
136
197
|
picker: 'Choose another caller',
|
|
137
198
|
close: 'Close',
|
|
138
199
|
back: 'Back to the picker',
|
|
@@ -158,14 +219,35 @@ const STRINGS: Readonly<Record<Locale, Strings>> = {
|
|
|
158
219
|
linksText: 'Každá se otevře jako držitel odkazu, který aplikace vydala.',
|
|
159
220
|
openLink: 'Otevřít jako držitel odkazu',
|
|
160
221
|
mail: 'Pošta',
|
|
161
|
-
mailText: 'Pozvánky, které by zástupný IAM odeslal e-mailem, a
|
|
222
|
+
mailText: 'Pozvánky, které by zástupný IAM odeslal e-mailem, a pošta, kterou odeslaly úlohy aplikace.',
|
|
162
223
|
noMail: 'Zatím nebylo nic odesláno.',
|
|
163
224
|
invitation: (role, scope) => `Pozvánka: ${role} v ${scope}`,
|
|
164
225
|
accept: 'Přijmout pozvánku',
|
|
165
226
|
continueAs: 'Pokračovat jako tato osoba',
|
|
166
227
|
openMessage: 'Otevřít zprávu',
|
|
167
|
-
status: {
|
|
228
|
+
status: {
|
|
229
|
+
open: 'čeká',
|
|
230
|
+
accepted: 'přijata',
|
|
231
|
+
cancelled: 'zrušena',
|
|
232
|
+
expired: 'vypršela',
|
|
233
|
+
sent: 'odesláno',
|
|
234
|
+
not_sent: 'neodesláno',
|
|
235
|
+
unknown: 'možná odesláno',
|
|
236
|
+
},
|
|
168
237
|
to: 'Komu',
|
|
238
|
+
subject: 'Předmět',
|
|
239
|
+
key: 'Klíč',
|
|
240
|
+
transportKey: 'Klíč transportu',
|
|
241
|
+
sentAt: 'Odesláno',
|
|
242
|
+
answer: 'Odpověď transportu',
|
|
243
|
+
fromName: 'Jméno odesílatele',
|
|
244
|
+
replyTo: 'Odpovědět na',
|
|
245
|
+
text: 'Text',
|
|
246
|
+
html: 'HTML',
|
|
247
|
+
noHtml: 'Zpráva nemá část HTML.',
|
|
248
|
+
outbox: 'Vývojová schránka',
|
|
249
|
+
outboxText: 'Požadavky, které aplikace poslala do vývojové schránky, od nejnovějšího.',
|
|
250
|
+
noOutbox: 'Do vývojové schránky zatím nic nedorazilo.',
|
|
169
251
|
picker: 'Vybrat jiného volajícího',
|
|
170
252
|
close: 'Zavřít',
|
|
171
253
|
back: 'Zpět na výběr',
|
|
@@ -174,6 +256,8 @@ const STRINGS: Readonly<Record<Locale, Strings>> = {
|
|
|
174
256
|
|
|
175
257
|
export const stringsOf = (locale: Locale): Strings => STRINGS[locale]
|
|
176
258
|
|
|
259
|
+
const timeOf = (locale: Locale, at: number): string => new Intl.DateTimeFormat(locale, { dateStyle: 'short', timeStyle: 'medium' }).format(at)
|
|
260
|
+
|
|
177
261
|
/** The palette: neutral greys and one accent, redefined for a dark color scheme. */
|
|
178
262
|
const TOKENS = `
|
|
179
263
|
--fd-bg: #f6f6f4;
|
|
@@ -263,12 +347,19 @@ input::placeholder { color: var(--fd-muted); }
|
|
|
263
347
|
.button.quiet { background: transparent; color: var(--fd-text); border-color: var(--fd-border-strong); }
|
|
264
348
|
.button.quiet:hover { background: var(--fd-surface-2); }
|
|
265
349
|
.empty { padding: 16px; border: 1px dashed var(--fd-border-strong); border-radius: 12px; color: var(--fd-muted); font-size: 14px; }
|
|
350
|
+
.mono { font-family: var(--fd-mono); font-size: 12px; overflow-wrap: anywhere; }
|
|
351
|
+
.fields { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 24px 0 0; padding: 16px; border: 1px solid var(--fd-border); border-radius: 12px; background: var(--fd-surface); font-size: 14px; }
|
|
352
|
+
.fields dt { color: var(--fd-muted); }
|
|
353
|
+
.fields dd { margin: 0; overflow-wrap: anywhere; }
|
|
354
|
+
pre.text { margin: 14px 0 0; padding: 16px; border: 1px solid var(--fd-border); border-radius: 12px; background: var(--fd-surface); font: 13px/1.5 var(--fd-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
355
|
+
iframe.mail-html { display: block; width: 100%; min-height: 420px; margin-top: 14px; border: 1px solid var(--fd-border-strong); border-radius: 12px; background: #ffffff; }
|
|
266
356
|
a:focus-visible, button:focus-visible, input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--fd-ring); border-color: var(--fd-accent); }
|
|
267
357
|
@media (max-width: 560px) {
|
|
268
358
|
main { padding-top: 28px; }
|
|
269
359
|
h1 { font-size: 24px; }
|
|
270
360
|
.row .control { flex: 1 1 100%; }
|
|
271
361
|
.row .control input { flex: 1; width: auto; min-width: 0; }
|
|
362
|
+
.fields { grid-template-columns: 1fr; }
|
|
272
363
|
}
|
|
273
364
|
`
|
|
274
365
|
|
|
@@ -342,22 +433,34 @@ function roleRow(role: RoleView, text: Strings): string {
|
|
|
342
433
|
}"><datalist id="${list}">${options}</datalist><button class="button quiet" type="submit">${escapeHtml(text.use)}</button></span></form>`
|
|
343
434
|
}
|
|
344
435
|
|
|
345
|
-
|
|
436
|
+
const actionButton = (action: { readonly label: string; readonly href: string } | null): string =>
|
|
437
|
+
action === null ? '' : `<span class="control"><a class="button quiet" href="${escapeHtml(action.href)}">${escapeHtml(action.label)}</a></span>`
|
|
438
|
+
|
|
439
|
+
function mailRows(mail: readonly MailView[], text: Strings, locale: Locale): string {
|
|
346
440
|
if (mail.length === 0) return `<div class="empty">${escapeHtml(text.noMail)}</div>`
|
|
347
441
|
return `<div class="rows">${
|
|
348
|
-
mail.map((item) =>
|
|
442
|
+
mail.map((item) => {
|
|
443
|
+
const when = [...(item.key === null ? [] : [item.key]), timeOf(locale, item.at)].join(' · ')
|
|
444
|
+
return `<div class="row"><span class="meta stack"><span class="subject">${escapeHtml(item.subject)}</span><span class="to">${
|
|
445
|
+
escapeHtml(text.to)
|
|
446
|
+
}: ${escapeHtml(item.to)}</span><span class="to">${escapeHtml(when)}</span></span><span class="badge">${
|
|
447
|
+
escapeHtml(text.status[item.status])
|
|
448
|
+
}</span>${item.answer === null ? '' : `<span class="mono">${escapeHtml(item.answer)}</span>`}${actionButton(item.action)}</div>`
|
|
449
|
+
}).join('')
|
|
450
|
+
}</div>`
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function outboxRows(outbox: readonly OutboxView[], text: Strings): string {
|
|
454
|
+
return `<div class="rows">${
|
|
455
|
+
outbox.map((item) =>
|
|
349
456
|
`<div class="row"><span class="meta stack"><span class="subject">${escapeHtml(item.subject)}</span><span class="to">${escapeHtml(text.to)}: ${
|
|
350
457
|
escapeHtml(item.to)
|
|
351
|
-
}</span></span
|
|
352
|
-
item.action === null
|
|
353
|
-
? ''
|
|
354
|
-
: `<span class="control"><a class="button quiet" href="${escapeHtml(item.action.href)}">${escapeHtml(item.action.label)}</a></span>`
|
|
355
|
-
}</div>`
|
|
458
|
+
}</span></span>${actionButton({ label: text.openMessage, href: item.href })}</div>`
|
|
356
459
|
).join('')
|
|
357
460
|
}</div>`
|
|
358
461
|
}
|
|
359
462
|
|
|
360
|
-
/** The picker: the personas, another role, anonymous, the link pages,
|
|
463
|
+
/** The picker: the personas, another role, anonymous, the link pages, the mail IAM and the jobs sent, and the dev outbox. */
|
|
361
464
|
export function pickerPage(view: DevView): string {
|
|
362
465
|
const text = stringsOf(view.locale)
|
|
363
466
|
const personas = view.personas.length === 0
|
|
@@ -374,6 +477,11 @@ export function pickerPage(view: DevView): string {
|
|
|
374
477
|
}<span class="cta">${escapeHtml(text.openLink)} →</span></a>`
|
|
375
478
|
).join('')
|
|
376
479
|
}</div></section>`
|
|
480
|
+
const outbox = view.outbox.length === 0
|
|
481
|
+
? ''
|
|
482
|
+
: `<section aria-labelledby="outbox"><h2 id="outbox">${escapeHtml(text.outbox)}</h2><p class="hint">${escapeHtml(text.outboxText)}</p>${
|
|
483
|
+
outboxRows(view.outbox, text)
|
|
484
|
+
}</section>`
|
|
377
485
|
const body = `<p class="lede">${escapeHtml(text.lede)}</p>
|
|
378
486
|
<section aria-labelledby="personas"><h2 id="personas">${escapeHtml(text.personas)}</h2>${personas}</section>
|
|
379
487
|
<section aria-labelledby="roles"><h2 id="roles">${escapeHtml(text.another)}</h2><div class="rows">${
|
|
@@ -384,8 +492,9 @@ export function pickerPage(view: DevView): string {
|
|
|
384
492
|
}</p><a class="button quiet" href="${escapeHtml(view.anonymousHref)}">${escapeHtml(text.anonymousButton)}</a></section>
|
|
385
493
|
${links}
|
|
386
494
|
<section aria-labelledby="mail"><h2 id="mail">${escapeHtml(text.mail)}</h2><p class="hint">${escapeHtml(text.mailText)}</p>${
|
|
387
|
-
mailRows(view.mail, text)
|
|
388
|
-
}</section
|
|
495
|
+
mailRows(view.mail, text, view.locale)
|
|
496
|
+
}</section>
|
|
497
|
+
${outbox}`
|
|
389
498
|
return page(view, `${view.title}: ${text.choose.toLowerCase()}`, body)
|
|
390
499
|
}
|
|
391
500
|
|
|
@@ -401,6 +510,36 @@ export function noticePage(view: Pick<DevView, 'locale' | 'title' | 'current' |
|
|
|
401
510
|
)
|
|
402
511
|
}
|
|
403
512
|
|
|
513
|
+
/**
|
|
514
|
+
* 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
|
|
515
|
+
* origin and submits nothing. The frame's document inherits the page's policy (`default-src 'none'`), so it loads nothing.
|
|
516
|
+
*/
|
|
517
|
+
export function mailPage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>, mail: DevMail): string {
|
|
518
|
+
const text = stringsOf(view.locale)
|
|
519
|
+
const status = mail.outcome === 'accepted' ? text.status.sent : text.status[mail.outcome]
|
|
520
|
+
const fields: readonly (readonly [string, string | null])[] = [
|
|
521
|
+
[text.to, mail.to],
|
|
522
|
+
[text.subject, mail.subject],
|
|
523
|
+
[text.fromName, mail.fromName],
|
|
524
|
+
[text.replyTo, mail.replyTo],
|
|
525
|
+
[text.key, mail.key],
|
|
526
|
+
[text.transportKey, mail.transportKey],
|
|
527
|
+
[text.answer, mail.answer === 'accepted' ? status : `${status} · ${mail.answer}`],
|
|
528
|
+
[text.sentAt, timeOf(view.locale, Date.parse(mail.at))],
|
|
529
|
+
]
|
|
530
|
+
const html = mail.html === null
|
|
531
|
+
? `<div class="empty">${escapeHtml(text.noHtml)}</div>`
|
|
532
|
+
: `<iframe class="mail-html" sandbox="" referrerpolicy="no-referrer" title="${escapeHtml(text.html)}" srcdoc="${escapeHtml(mail.html)}"></iframe>`
|
|
533
|
+
return page(
|
|
534
|
+
view,
|
|
535
|
+
mail.subject,
|
|
536
|
+
`<p class="actions"><a class="button quiet" href="${escapeHtml(view.pickerHref)}">${escapeHtml(text.back)}</a></p>
|
|
537
|
+
<dl class="fields">${fields.map(([name, value]) => (value === null ? '' : `<dt>${escapeHtml(name)}</dt><dd>${escapeHtml(value)}</dd>`)).join('')}</dl>
|
|
538
|
+
<section aria-labelledby="text"><h2 id="text">${escapeHtml(text.text)}</h2><pre class="text">${escapeHtml(mail.text)}</pre></section>
|
|
539
|
+
<section aria-labelledby="html"><h2 id="html">${escapeHtml(text.html)}</h2>${html}</section>`,
|
|
540
|
+
)
|
|
541
|
+
}
|
|
542
|
+
|
|
404
543
|
/** What the toolbar renders: its labels and the view, with every caller already put into words. */
|
|
405
544
|
export function toolbarState(view: DevView): unknown {
|
|
406
545
|
const text = stringsOf(view.locale)
|
|
@@ -412,6 +551,7 @@ export function toolbarState(view: DevView): unknown {
|
|
|
412
551
|
links: text.links,
|
|
413
552
|
mail: text.mail,
|
|
414
553
|
noMail: text.noMail,
|
|
554
|
+
outbox: text.outbox,
|
|
415
555
|
picker: text.picker,
|
|
416
556
|
close: text.close,
|
|
417
557
|
preview: text.preview,
|
|
@@ -421,6 +561,11 @@ export function toolbarState(view: DevView): unknown {
|
|
|
421
561
|
personas: view.personas.map((persona) => ({ name: persona.name, detail: detail(persona.badges), href: persona.href, current: persona.current })),
|
|
422
562
|
links: view.links.map((link) => ({ title: link.title, detail: link.description ?? '', href: link.href })),
|
|
423
563
|
mail: view.mail.map((item) => ({ subject: item.subject, detail: `${text.to}: ${item.to} · ${text.status[item.status]}`, action: item.action })),
|
|
564
|
+
outbox: view.outbox.map((item) => ({
|
|
565
|
+
subject: item.subject,
|
|
566
|
+
detail: `${text.to}: ${item.to}`,
|
|
567
|
+
action: { label: text.openMessage, href: item.href },
|
|
568
|
+
})),
|
|
424
569
|
picker: view.pickerHref,
|
|
425
570
|
}
|
|
426
571
|
}
|
|
@@ -534,13 +679,20 @@ export function toolbarScript(statePath: string): string {
|
|
|
534
679
|
|
|
535
680
|
const mail = section(state.labels.mail)
|
|
536
681
|
if (state.mail.length === 0) mail.append(node('div', 'empty', state.labels.noMail))
|
|
537
|
-
|
|
682
|
+
const message = (item) => {
|
|
538
683
|
const element = entry(item.action === null ? null : item.action.href, item.subject, item.detail, false)
|
|
539
684
|
if (item.action !== null) element.append(node('span', 'act', item.action.label + ' →'))
|
|
540
|
-
|
|
685
|
+
return element
|
|
541
686
|
}
|
|
687
|
+
for (const item of state.mail) mail.append(message(item))
|
|
542
688
|
panel.append(mail)
|
|
543
689
|
|
|
690
|
+
if (state.outbox.length > 0) {
|
|
691
|
+
const outbox = section(state.labels.outbox)
|
|
692
|
+
for (const item of state.outbox) outbox.append(message(item))
|
|
693
|
+
panel.append(outbox)
|
|
694
|
+
}
|
|
695
|
+
|
|
544
696
|
const open = (opened) => {
|
|
545
697
|
panel.hidden = !opened
|
|
546
698
|
pill.setAttribute('aria-expanded', String(opened))
|
package/src/app-dev.ts
CHANGED
|
@@ -15,14 +15,17 @@ import { MemoryFileObjects } from '@fabrika/platform/testing'
|
|
|
15
15
|
import { existsSync } from 'node:fs'
|
|
16
16
|
import { join } from 'node:path'
|
|
17
17
|
import { z } from 'zod/v4'
|
|
18
|
-
import { DEV_ENV_FILE, DevEnvProblem, devOutbox, mailHeadOf, readDevEnv, shownBody } from './app-dev-outside'
|
|
18
|
+
import { DEV_ENV_FILE, DevEnvProblem, type DevOutbox, devOutbox, mailHeadOf, readDevEnv, shownBody } from './app-dev-outside'
|
|
19
19
|
import { DEFAULT_SEED, importSeed, isLocalPath, NOTHING_SEEDED, parseSeeded, type Seeded, seedPath, SeedProblem } from './app-dev-seed'
|
|
20
20
|
import {
|
|
21
21
|
type Badge,
|
|
22
22
|
type CurrentView,
|
|
23
23
|
type DevView,
|
|
24
|
+
mailPage,
|
|
24
25
|
type MailView,
|
|
26
|
+
newestMail,
|
|
25
27
|
noticePage,
|
|
28
|
+
type OutboxView,
|
|
26
29
|
pickerPage,
|
|
27
30
|
type RoleView,
|
|
28
31
|
stringsOf,
|
|
@@ -42,10 +45,11 @@ and a throwaway schema of the database in ${TEST_POSTGRES_URL}, migrated from db
|
|
|
42
45
|
The seed module (--seed, or ${DEFAULT_SEED} when it exists) default-exports a DevSeed of @fabrika/app/testing: it
|
|
43
46
|
receives the kit, writes through the endpoints, and answers the personas, link pages and scope values to offer.
|
|
44
47
|
Pick who the browser is at /__fabrika/dev; every SPA page shows a toolbar that switches the caller and lists the
|
|
45
|
-
mail IAM sent and the requests the application sent to ${DEV_OUTBOX_ORIGIN}, the dev
|
|
46
|
-
passes. The application's own variables come from ${DEV_ENV_FILE} (NAME=value lines)
|
|
47
|
-
seed or a job's handler throws is printed with its stack. It listens on 127.0.0.1
|
|
48
|
-
3000 unless --port says otherwise (0 picks a free one), and prints the address it
|
|
48
|
+
mail IAM and the application's jobs sent, and the requests the application sent to ${DEV_OUTBOX_ORIGIN}, the dev
|
|
49
|
+
outbox. A form's challenge passes. The application's own variables come from ${DEV_ENV_FILE} (NAME=value lines)
|
|
50
|
+
over the environment. What the seed or a job's handler throws is printed with its stack. It listens on 127.0.0.1
|
|
51
|
+
(or ::1, localhost) only, port 3000 unless --port says otherwise (0 picks a free one), and prints the address it
|
|
52
|
+
serves.
|
|
49
53
|
`
|
|
50
54
|
|
|
51
55
|
const LOOPBACK: ReadonlySet<string> = new Set(['127.0.0.1', '::1', 'localhost'])
|
|
@@ -55,6 +59,7 @@ const CHOOSE_PATH = '/__fabrika/dev/as'
|
|
|
55
59
|
const ACCEPT_PATH = '/__fabrika/dev/accept'
|
|
56
60
|
const STATE_PATH = '/__fabrika/dev/state'
|
|
57
61
|
const OUTBOX_PATH = '/__fabrika/dev/outbox/'
|
|
62
|
+
const MAIL_PATH = '/__fabrika/dev/mail/'
|
|
58
63
|
const TOOLBAR_PATH = '/__fabrika/dev/toolbar.js'
|
|
59
64
|
const CHOICE_COOKIE = 'fabrika-dev-as'
|
|
60
65
|
const MAX_SCOPE_VALUE = 200
|
|
@@ -249,7 +254,7 @@ async function serveDevKit(
|
|
|
249
254
|
app: ContractImplementation<AnyContract>,
|
|
250
255
|
options: AppDevOptions,
|
|
251
256
|
postgres: TestDatabase | null,
|
|
252
|
-
outbox:
|
|
257
|
+
outbox: DevOutbox,
|
|
253
258
|
restoreFetch: () => void,
|
|
254
259
|
): Promise<AppDevServer> {
|
|
255
260
|
const contract = app.contract
|
|
@@ -263,7 +268,8 @@ async function serveDevKit(
|
|
|
263
268
|
revealHandlerErrors: printHandlerError,
|
|
264
269
|
})
|
|
265
270
|
const kit = dev.kit
|
|
266
|
-
const
|
|
271
|
+
const outside: DevOutside = { outbox: () => outbox.outbox(), mails: () => dev.mails() }
|
|
272
|
+
const seeded = await runSeed(dev, outside, options.seed)
|
|
267
273
|
const text = stringsOf(vocabulary.locale ?? 'en')
|
|
268
274
|
const title = vocabulary.displayName ?? vocabulary.app
|
|
269
275
|
const mounts = Object.values(kit.artifact.mounts)
|
|
@@ -361,23 +367,31 @@ async function serveDevKit(
|
|
|
361
367
|
})),
|
|
362
368
|
anonymousHref: chooseHref({ anonymous: '1' }, next),
|
|
363
369
|
links: seeded.links.map((link) => ({ title: link.title, description: link.description, href: link.url })),
|
|
364
|
-
mail: [
|
|
370
|
+
mail: newestMail([
|
|
365
371
|
...dev.invitations().map((invitation): MailView => ({
|
|
366
372
|
to: invitation.email,
|
|
367
373
|
subject: text.invitation(invitation.role, scopeLabel(invitation.scope.type, invitation.scope.value)),
|
|
374
|
+
at: invitation.sentAt * 1000,
|
|
375
|
+
key: null,
|
|
368
376
|
status: invitation.status,
|
|
377
|
+
answer: null,
|
|
369
378
|
action: invitation.status === 'open'
|
|
370
379
|
? { label: text.accept, href: `${ACCEPT_PATH}?${new URLSearchParams({ invitation: invitation.id, next }).toString()}` }
|
|
371
380
|
: invitation.status === 'accepted' && invitees.has(invitation.id)
|
|
372
381
|
? { label: text.continueAs, href: chooseHref({ invitation: invitation.id }, next) }
|
|
373
382
|
: null,
|
|
374
383
|
})),
|
|
375
|
-
...
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
384
|
+
...dev.mails().map((sent): MailView => ({
|
|
385
|
+
to: sent.to,
|
|
386
|
+
subject: sent.subject,
|
|
387
|
+
at: Date.parse(sent.at),
|
|
388
|
+
key: sent.key,
|
|
389
|
+
status: sent.outcome === 'accepted' ? 'sent' : sent.outcome,
|
|
390
|
+
answer: sent.answer === 'accepted' ? null : sent.answer,
|
|
391
|
+
action: { label: text.openMessage, href: `${MAIL_PATH}${sent.id}` },
|
|
379
392
|
})),
|
|
380
|
-
],
|
|
393
|
+
]),
|
|
394
|
+
outbox: [...outbox.outbox()].reverse().map((message): OutboxView => ({ ...mailHeadOf(message), href: `${OUTBOX_PATH}${message.id}` })),
|
|
381
395
|
pickerHref: `${PICKER_PATH}?${new URLSearchParams({ next }).toString()}`,
|
|
382
396
|
})
|
|
383
397
|
|
|
@@ -489,9 +503,17 @@ async function serveDevKit(
|
|
|
489
503
|
})
|
|
490
504
|
}
|
|
491
505
|
|
|
506
|
+
/** A message a job handed to the mail stand-in: its fields, its text, and its HTML in a sandboxed frame. */
|
|
507
|
+
const mailMessage = (request: Request, path: string): Response => {
|
|
508
|
+
const sent = dev.mails().find((candidate) => `${MAIL_PATH}${candidate.id}` === path)
|
|
509
|
+
if (sent === undefined) return plain(404, 'no such mail in app dev')
|
|
510
|
+
return new Response(mailPage(viewOf(choiceOf(request), firstSpa), sent), { headers: PAGE_HEADERS })
|
|
511
|
+
}
|
|
512
|
+
|
|
492
513
|
const devRoute = (request: Request, url: URL): Response | null => {
|
|
493
514
|
if (request.method !== 'GET') return null
|
|
494
515
|
if (url.pathname.startsWith(OUTBOX_PATH)) return outboxMessage(url.pathname)
|
|
516
|
+
if (url.pathname.startsWith(MAIL_PATH)) return mailMessage(request, url.pathname)
|
|
495
517
|
switch (url.pathname) {
|
|
496
518
|
case PICKER_PATH:
|
|
497
519
|
return new Response(pickerPage(viewOf(choiceOf(request), nextOf(url.searchParams.get('next')))), { headers: PAGE_HEADERS })
|
package/src/control.ts
CHANGED
|
@@ -629,7 +629,8 @@ const runRuns = async (verb: string | undefined, flags: Flags, env: Readonly<Rec
|
|
|
629
629
|
throw new Error(`Unknown \`control runs\` verb: ${verb ?? '(missing)'}`)
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
-
|
|
632
|
+
/** Also `fabrika namespace`'s row, which reads only these fields of Control's answer. */
|
|
633
|
+
export const namespaceLine = (namespace: Pick<DeploymentNamespaceDto, 'id' | 'env' | 'state' | 'exclusiveAppId'>): string =>
|
|
633
634
|
`${namespace.id}\t${namespace.env}\t${namespace.state}\t${namespace.exclusiveAppId ?? '-'}`
|
|
634
635
|
|
|
635
636
|
/** One line per host the placement serves: a `free` one is exactly what the next `--domain` accepts. */
|
|
@@ -657,7 +658,7 @@ const payloadRows = (path: string, value: JsonValue): string[] => {
|
|
|
657
658
|
/** A value that would break a row — a line break or a tab — is shown by size only; `--json` prints it whole. */
|
|
658
659
|
const cell = (value: string): string => /[\r\n\t]/.test(value) ? `(${new TextEncoder().encode(value).byteLength} bytes; --json prints it)` : value
|
|
659
660
|
|
|
660
|
-
const namespacePlanLines = (plan: PlanDeploymentNamespaceResponse): string[] => [
|
|
661
|
+
export const namespacePlanLines = (plan: PlanDeploymentNamespaceResponse): string[] => [
|
|
661
662
|
`namespace.id\t${plan.namespace.id}`,
|
|
662
663
|
`namespace.env\t${plan.namespace.env}`,
|
|
663
664
|
`namespace.exclusiveAppId\t${plan.namespace.exclusiveAppId ?? '-'}`,
|
package/src/namespace.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
zeropsNamespaceTargetCodec,
|
|
13
13
|
} from '@fabrika/provider-zerops'
|
|
14
14
|
import { z } from 'zod'
|
|
15
|
+
import { namespaceLine, namespacePlanLines } from './control'
|
|
15
16
|
|
|
16
17
|
export const NAMESPACE_USAGE = `fabrika namespace — Zerops deployment namespaces
|
|
17
18
|
|
|
@@ -34,14 +35,25 @@ Options:
|
|
|
34
35
|
--postgres-type=<type> Cheap-tier PostgreSQL type.
|
|
35
36
|
--postgres-profile=<profile> Cheap-tier PostgreSQL profile.
|
|
36
37
|
--control-url=<url> Control origin; or FABRIKA_CONTROL_URL.
|
|
38
|
+
--json Print the result as JSON instead of rows.
|
|
37
39
|
-h, --help Show this help.
|
|
38
40
|
|
|
41
|
+
\`plan\` prints one \`<path>\\t<value>\` row per field of the plan, keyed by its path in --json; a multi-line
|
|
42
|
+
value such as the proxy's descriptor file is shown by size only. The other commands print one
|
|
43
|
+
\`<id>\\t<env>\\t<state>\\t<exclusive app>\` row.
|
|
44
|
+
|
|
39
45
|
Mutating namespace commands read the Bearer credential from FABRIKA_CONTROL_TOKEN.
|
|
40
46
|
Plan/create/adopt require FABRIKA_ZEROPS_PROXY_SOURCE_JSON:
|
|
41
47
|
{"repository":{"owner":"...","name":"..."},"commitSha":"...","descriptor":{"path":"zerops.yaml","contents":"...","sha256":"..."}}
|
|
42
48
|
Reconcile uses the persisted namespace source.
|
|
43
49
|
`
|
|
44
50
|
|
|
51
|
+
export interface ZeropsNamespaceCommand {
|
|
52
|
+
readonly args: ZeropsCliArgs
|
|
53
|
+
/** The result as JSON; otherwise the rows `fabrika control namespaces` prints. */
|
|
54
|
+
readonly json: boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
export interface ZeropsNamespaceCommandDependencies {
|
|
46
58
|
readonly source: Readonly<Record<string, string | undefined>>
|
|
47
59
|
readonly fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>
|
|
@@ -146,14 +158,19 @@ const controlClient = (
|
|
|
146
158
|
},
|
|
147
159
|
})
|
|
148
160
|
|
|
149
|
-
// Passthrough on purpose: the operator
|
|
150
|
-
const namespaceResponseSchema = z.object({
|
|
151
|
-
|
|
161
|
+
// Passthrough on purpose: `--json` shows the operator the whole namespace detail, this only checks it is one.
|
|
162
|
+
const namespaceResponseSchema = z.object({
|
|
163
|
+
id: z.string(),
|
|
164
|
+
env: z.string(),
|
|
165
|
+
state: z.enum(['pending', 'provisioning', 'ready', 'failed']),
|
|
166
|
+
exclusiveAppId: z.string().nullable(),
|
|
167
|
+
}).passthrough()
|
|
168
|
+
const writeNamespace = (command: ZeropsNamespaceCommand, deps: ZeropsNamespaceCommandDependencies, result: unknown): void => {
|
|
152
169
|
const parsed = namespaceResponseSchema.safeParse(result)
|
|
153
170
|
if (!parsed.success) {
|
|
154
171
|
throw new Error('Control API returned an invalid namespace')
|
|
155
172
|
}
|
|
156
|
-
deps.write(outputJson(parsed.data))
|
|
173
|
+
deps.write(command.json ? outputJson(parsed.data) : `${namespaceLine(parsed.data)}\n`)
|
|
157
174
|
}
|
|
158
175
|
|
|
159
176
|
const createBody = (namespace: ProviderDeploymentNamespace): CreateDeploymentNamespaceRequest => ({
|
|
@@ -171,18 +188,20 @@ const adoptBody = (namespace: ProviderDeploymentNamespace): AdoptDeploymentNames
|
|
|
171
188
|
|
|
172
189
|
/** Execute one namespace command. All command inputs are validated before the first fetch. */
|
|
173
190
|
export const runZeropsNamespaceCommand = async (
|
|
174
|
-
|
|
191
|
+
command: ZeropsNamespaceCommand,
|
|
175
192
|
deps: ZeropsNamespaceCommandDependencies,
|
|
176
193
|
): Promise<void> => {
|
|
194
|
+
const { args } = command
|
|
177
195
|
const subcommand = required(args.subcommand, 'namespace command')
|
|
178
196
|
if (subcommand === 'plan') {
|
|
179
|
-
|
|
197
|
+
const plan = await namespacePlan(args, deps.source)
|
|
198
|
+
deps.write(command.json ? outputJson(plan) : `${namespacePlanLines(plan).join('\n')}\n`)
|
|
180
199
|
return
|
|
181
200
|
}
|
|
182
201
|
if (subcommand === 'reconcile') {
|
|
183
202
|
const id = required(args.namespaceId, '--id')
|
|
184
203
|
const control = controlCoordinates(args, deps.source)
|
|
185
|
-
writeNamespace(deps, await controlClient(deps, control).namespaces.reconcile({ namespaceId: id }))
|
|
204
|
+
writeNamespace(command, deps, await controlClient(deps, control).namespaces.reconcile({ namespaceId: id }))
|
|
186
205
|
return
|
|
187
206
|
}
|
|
188
207
|
if (subcommand !== 'create' && subcommand !== 'adopt') {
|
|
@@ -192,7 +211,7 @@ export const runZeropsNamespaceCommand = async (
|
|
|
192
211
|
const planned = await namespacePlan(args, deps.source)
|
|
193
212
|
const control = controlCoordinates(args, deps.source)
|
|
194
213
|
if (subcommand === 'create') {
|
|
195
|
-
writeNamespace(deps, await controlClient(deps, control).namespaces.create(createBody(planned.namespace)))
|
|
214
|
+
writeNamespace(command, deps, await controlClient(deps, control).namespaces.create(createBody(planned.namespace)))
|
|
196
215
|
return
|
|
197
216
|
}
|
|
198
217
|
|
|
@@ -213,11 +232,17 @@ export const runZeropsNamespaceCommand = async (
|
|
|
213
232
|
}),
|
|
214
233
|
},
|
|
215
234
|
}
|
|
216
|
-
writeNamespace(deps, await controlClient(deps, control).namespaces.adopt({ namespaceId: namespace.id, namespace: adoptBody(namespace) }))
|
|
235
|
+
writeNamespace(command, deps, await controlClient(deps, control).namespaces.adopt({ namespaceId: namespace.id, namespace: adoptBody(namespace) }))
|
|
217
236
|
}
|
|
218
237
|
|
|
238
|
+
/** `--json` is this area's own flag, so it is taken out before the provider's parser, which refuses unknown options. */
|
|
239
|
+
export const parseZeropsNamespaceCommand = (subcommand: string, argv: readonly string[]): ZeropsNamespaceCommand => ({
|
|
240
|
+
args: parseZeropsCliArgs(['namespace', subcommand, ...argv.filter((arg) => arg !== '--json')]),
|
|
241
|
+
json: argv.includes('--json'),
|
|
242
|
+
})
|
|
243
|
+
|
|
219
244
|
export const runZeropsNamespaceCli = (subcommand: string, argv: readonly string[]): Promise<void> =>
|
|
220
|
-
runZeropsNamespaceCommand(
|
|
245
|
+
runZeropsNamespaceCommand(parseZeropsNamespaceCommand(subcommand, argv), {
|
|
221
246
|
source: process.env,
|
|
222
247
|
fetch: globalThis.fetch,
|
|
223
248
|
write: (value) => console.info(value.trimEnd()),
|