@fabrika/cli 0.9.0-dev.5 → 0.9.0-dev.50
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 +16 -13
- package/src/app-dev-seed.ts +2 -6
- package/src/app-dev-ui.ts +155 -24
- package/src/app-dev.ts +65 -24
- package/src/connect.ts +24 -8
- package/src/control-oauth.ts +463 -0
- package/src/control.ts +899 -105
- package/src/credential-origin.ts +54 -0
- package/src/data.ts +61 -24
- package/src/db.ts +35 -212
- package/src/index.ts +21 -5
- package/src/job.ts +2 -2
- package/src/operations.ts +737 -0
- package/types/src/app-dev-seed.d.ts +0 -2
- package/types/src/app-dev-ui.d.ts +22 -8
- package/types/src/connect.d.ts +4 -1
- package/types/src/control-oauth.d.ts +56 -0
- package/types/src/control.d.ts +86 -14
- package/types/src/credential-origin.d.ts +14 -0
- package/types/src/data.d.ts +3 -1
- package/types/src/db.d.ts +1 -3
- package/types/src/job.d.ts +1 -1
- package/types/src/operations.d.ts +23 -0
- package/src/junit.ts +0 -37
- package/types/src/junit.d.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/cli",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.50",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,24 +26,27 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"typecheck": "
|
|
29
|
+
"typecheck": "tsrs --build tsconfig.test.json",
|
|
30
30
|
"test": "bun test"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"jose": "^5.9.0",
|
|
33
34
|
"zod": "^3.25.76",
|
|
34
|
-
"@fabrika/app": "0.9.0-dev.
|
|
35
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
36
|
-
"@fabrika/control-contract": "0.9.0-dev.
|
|
37
|
-
"@fabrika/
|
|
38
|
-
"@fabrika/
|
|
39
|
-
"@fabrika/
|
|
40
|
-
"@fabrika/
|
|
41
|
-
"@fabrika/
|
|
35
|
+
"@fabrika/app": "0.9.0-dev.50",
|
|
36
|
+
"@fabrika/auth-core": "0.9.0-dev.50",
|
|
37
|
+
"@fabrika/control-contract": "0.9.0-dev.50",
|
|
38
|
+
"@fabrika/iam-contract": "0.9.0-dev.50",
|
|
39
|
+
"@fabrika/operations-contract": "0.9.0-dev.50",
|
|
40
|
+
"@fabrika/provider-contract": "0.9.0-dev.50",
|
|
41
|
+
"@fabrika/db": "0.9.0-dev.50",
|
|
42
|
+
"@fabrika/platform": "0.9.0-dev.50",
|
|
43
|
+
"@fabrika/platform-node": "0.9.0-dev.50",
|
|
44
|
+
"@fabrika/check": "0.9.0-dev.50"
|
|
42
45
|
},
|
|
43
46
|
"peerDependencies": {
|
|
44
|
-
"@fabrika/builder": "0.9.0-dev.
|
|
45
|
-
"@fabrika/provider-cloudflare": "0.9.0-dev.
|
|
46
|
-
"@fabrika/provider-zerops": "0.9.0-dev.
|
|
47
|
+
"@fabrika/builder": "0.9.0-dev.50",
|
|
48
|
+
"@fabrika/provider-cloudflare": "0.9.0-dev.50",
|
|
49
|
+
"@fabrika/provider-zerops": "0.9.0-dev.50"
|
|
47
50
|
},
|
|
48
51
|
"peerDependenciesMeta": {
|
|
49
52
|
"@fabrika/builder": {
|
package/src/app-dev-seed.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { AnyContract } from '@fabrika/app/contract'
|
|
5
5
|
import type { DevKit, PersonTestCaller } from '@fabrika/app/testing'
|
|
6
|
+
import { sameOriginTarget } from '@fabrika/auth-core'
|
|
6
7
|
import { existsSync } from 'node:fs'
|
|
7
8
|
import { isAbsolute, join } from 'node:path'
|
|
8
9
|
import { pathToFileURL } from 'node:url'
|
|
@@ -53,11 +54,6 @@ const SeedResult = z.strictObject({
|
|
|
53
54
|
scopes: z.record(z.string(), z.array(z.strictObject({ value: Text(MAX_SCOPE_VALUE), label: Text(MAX_NAME) })).max(MAX_ENTRIES)).optional(),
|
|
54
55
|
}).optional()
|
|
55
56
|
|
|
56
|
-
/** A path of this origin; a link the application issued is one (`/s/#px_…`). */
|
|
57
|
-
export function isLocalPath(path: string): boolean {
|
|
58
|
-
return path.startsWith('/') && !path.startsWith('//') && !path.startsWith('/\\')
|
|
59
|
-
}
|
|
60
|
-
|
|
61
57
|
/** The seed module's path: `--seed`, relative to the root, or `dev/seed.ts` when it exists; `null` for none. */
|
|
62
58
|
export function seedPath(root: string, given: string | null): string | null {
|
|
63
59
|
if (given !== null) {
|
|
@@ -102,7 +98,7 @@ export function parseSeeded<C extends AnyContract>(dev: DevKit<C>, answer: unkno
|
|
|
102
98
|
return { name: persona.name, description: persona.description ?? null, caller }
|
|
103
99
|
})
|
|
104
100
|
const links = (result.links ?? []).map((link, index): SeedLink => {
|
|
105
|
-
if (
|
|
101
|
+
if (sameOriginTarget(dev.kit.origin, link.url) === null) {
|
|
106
102
|
throw new SeedProblem(`app dev: link ${index + 1} of the seed is not a path of the application, as ctx.links answers it`)
|
|
107
103
|
}
|
|
108
104
|
return { title: link.title, description: link.description ?? null, url: link.url }
|
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
|
-
|
|
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',
|
|
@@ -252,6 +270,63 @@ const STRINGS: Readonly<Record<Locale, Strings>> = {
|
|
|
252
270
|
close: 'Zavřít',
|
|
253
271
|
back: 'Zpět na výběr',
|
|
254
272
|
},
|
|
273
|
+
uk: {
|
|
274
|
+
preview: 'Попередній перегляд для розробки',
|
|
275
|
+
choose: 'Виберіть, ким ви є',
|
|
276
|
+
lede:
|
|
277
|
+
'Кожен варіант визначає, від чийого імені ви звертаєтеся до тестового IAM. Дані зберігаються в тимчасовій схемі й зникають, коли app dev завершується.',
|
|
278
|
+
now: 'Ви',
|
|
279
|
+
nobody: 'Ніхто (анонімно)',
|
|
280
|
+
personas: 'Персони',
|
|
281
|
+
noPersonas: 'Seed не створив жодної персони. Поверніть їх із dev/seed.ts.',
|
|
282
|
+
another: 'Інша роль',
|
|
283
|
+
appWide: 'у всьому застосунку',
|
|
284
|
+
inScope: (dimension) => `в одному значенні ${dimension}`,
|
|
285
|
+
external: 'зовнішній',
|
|
286
|
+
use: 'Використати',
|
|
287
|
+
scopePlaceholder: (dimension) => `значення ${dimension}`,
|
|
288
|
+
anonymous: 'Анонімно',
|
|
289
|
+
anonymousText: 'Сторінка, що потребує входу, поверне вас сюди.',
|
|
290
|
+
anonymousButton: 'Продовжити анонімно',
|
|
291
|
+
links: 'Сторінки за посиланням',
|
|
292
|
+
linksText: 'Кожна відкривається від імені власника посилання, яке видав застосунок.',
|
|
293
|
+
openLink: 'Відкрити як власник посилання',
|
|
294
|
+
mail: 'Пошта',
|
|
295
|
+
mailText: 'Запрошення, які тестовий IAM надіслав би електронною поштою, і листи, які надіслали завдання застосунку.',
|
|
296
|
+
noMail: 'Ще нічого не надіслано.',
|
|
297
|
+
invitation: (role, scope) => `Запрошення: ${role} у ${scope}`,
|
|
298
|
+
accept: 'Прийняти запрошення',
|
|
299
|
+
continueAs: 'Продовжити як ця особа',
|
|
300
|
+
openMessage: 'Відкрити лист',
|
|
301
|
+
status: {
|
|
302
|
+
open: 'очікує',
|
|
303
|
+
accepted: 'прийнято',
|
|
304
|
+
cancelled: 'скасовано',
|
|
305
|
+
expired: 'термін минув',
|
|
306
|
+
sent: 'надіслано',
|
|
307
|
+
not_sent: 'не надіслано',
|
|
308
|
+
unknown: 'можливо, надіслано',
|
|
309
|
+
},
|
|
310
|
+
to: 'Кому',
|
|
311
|
+
subject: 'Тема',
|
|
312
|
+
key: 'Ключ',
|
|
313
|
+
transportKey: 'Ключ транспорту',
|
|
314
|
+
sentAt: 'Надіслано',
|
|
315
|
+
language: 'Мова',
|
|
316
|
+
state: 'Стан',
|
|
317
|
+
answer: 'Відповідь транспорту',
|
|
318
|
+
fromName: 'Ім’я відправника',
|
|
319
|
+
replyTo: 'Адреса для відповіді',
|
|
320
|
+
text: 'Текст',
|
|
321
|
+
html: 'HTML',
|
|
322
|
+
noHtml: 'Лист не має частини HTML.',
|
|
323
|
+
outbox: 'Скринька розробки',
|
|
324
|
+
outboxText: 'Запити, які застосунок надіслав до скриньки розробки, від найновішого.',
|
|
325
|
+
noOutbox: 'До скриньки розробки ще нічого не надійшло.',
|
|
326
|
+
picker: 'Вибрати інший варіант',
|
|
327
|
+
close: 'Закрити',
|
|
328
|
+
back: 'Назад до вибору',
|
|
329
|
+
},
|
|
255
330
|
}
|
|
256
331
|
|
|
257
332
|
export const stringsOf = (locale: Locale): Strings => STRINGS[locale]
|
|
@@ -338,7 +413,7 @@ h2 + .grid, h2 + .rows { margin-top: 14px; }
|
|
|
338
413
|
.row .meta .grants { font-family: var(--fd-mono); font-size: 12px; overflow-wrap: anywhere; }
|
|
339
414
|
.row .control { display: flex; gap: 8px; align-items: center; }
|
|
340
415
|
.row .meta.stack { flex-direction: column; align-items: flex-start; gap: 2px; }
|
|
341
|
-
.actions { margin-top: 24px; }
|
|
416
|
+
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
|
|
342
417
|
.subject { font-weight: 600; color: var(--fd-text); font-size: 15px; }
|
|
343
418
|
.to { font-size: 13px; color: var(--fd-muted); overflow-wrap: anywhere; }
|
|
344
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); }
|
|
@@ -371,7 +446,10 @@ const badges = (list: readonly Badge[]): string =>
|
|
|
371
446
|
? ''
|
|
372
447
|
: `<div class="badges">${list.map((badge) => `<span class="badge ${badge.tone}">${escapeHtml(badge.text)}</span>`).join('')}</div>`
|
|
373
448
|
|
|
374
|
-
|
|
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 {
|
|
375
453
|
const text = stringsOf(view.locale)
|
|
376
454
|
const now = view.current === null
|
|
377
455
|
? `<span>${escapeHtml(text.now)}:</span> <strong>${escapeHtml(text.nobody)}</strong>`
|
|
@@ -391,7 +469,7 @@ function page(view: Pick<DevView, 'locale' | 'title' | 'current'>, heading: stri
|
|
|
391
469
|
escapeHtml(text.preview)
|
|
392
470
|
}</span></span><span class="now">${now}</span></div></header>
|
|
393
471
|
<main>
|
|
394
|
-
<h1>${escapeHtml(heading)}</h1>
|
|
472
|
+
<h1${langOf(view.locale, headingLocale)}>${escapeHtml(heading)}</h1>
|
|
395
473
|
${body}
|
|
396
474
|
</main>
|
|
397
475
|
</body>
|
|
@@ -433,7 +511,7 @@ function roleRow(role: RoleView, text: Strings): string {
|
|
|
433
511
|
}"><datalist id="${list}">${options}</datalist><button class="button quiet" type="submit">${escapeHtml(text.use)}</button></span></form>`
|
|
434
512
|
}
|
|
435
513
|
|
|
436
|
-
const actionButton = (action:
|
|
514
|
+
const actionButton = (action: MailAction | null): string =>
|
|
437
515
|
action === null ? '' : `<span class="control"><a class="button quiet" href="${escapeHtml(action.href)}">${escapeHtml(action.label)}</a></span>`
|
|
438
516
|
|
|
439
517
|
function mailRows(mail: readonly MailView[], text: Strings, locale: Locale): string {
|
|
@@ -441,11 +519,11 @@ function mailRows(mail: readonly MailView[], text: Strings, locale: Locale): str
|
|
|
441
519
|
return `<div class="rows">${
|
|
442
520
|
mail.map((item) => {
|
|
443
521
|
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
|
|
445
|
-
escapeHtml(
|
|
446
|
-
}: ${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">${
|
|
447
525
|
escapeHtml(text.status[item.status])
|
|
448
|
-
}</span>${item.answer === null ? '' : `<span class="mono">${escapeHtml(item.answer)}</span>`}${
|
|
526
|
+
}</span>${item.answer === null ? '' : `<span class="mono">${escapeHtml(item.answer)}</span>`}${item.actions.map(actionButton).join('')}</div>`
|
|
449
527
|
}).join('')
|
|
450
528
|
}</div>`
|
|
451
529
|
}
|
|
@@ -511,13 +589,44 @@ export function noticePage(view: Pick<DevView, 'locale' | 'title' | 'current' |
|
|
|
511
589
|
}
|
|
512
590
|
|
|
513
591
|
/**
|
|
514
|
-
* One message
|
|
515
|
-
*
|
|
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.
|
|
516
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. */
|
|
517
626
|
export function mailPage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'pickerHref'>, mail: DevMail): string {
|
|
518
627
|
const text = stringsOf(view.locale)
|
|
519
628
|
const status = mail.outcome === 'accepted' ? text.status.sent : text.status[mail.outcome]
|
|
520
|
-
|
|
629
|
+
return messagePage(view, mail.subject, [
|
|
521
630
|
[text.to, mail.to],
|
|
522
631
|
[text.subject, mail.subject],
|
|
523
632
|
[text.fromName, mail.fromName],
|
|
@@ -526,17 +635,35 @@ export function mailPage(view: Pick<DevView, 'locale' | 'title' | 'current' | 'p
|
|
|
526
635
|
[text.transportKey, mail.transportKey],
|
|
527
636
|
[text.answer, mail.answer === 'accepted' ? status : `${status} · ${mail.answer}`],
|
|
528
637
|
[text.sentAt, timeOf(view.locale, Date.parse(mail.at))],
|
|
529
|
-
]
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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(
|
|
534
655
|
view,
|
|
535
656
|
mail.subject,
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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,
|
|
540
667
|
)
|
|
541
668
|
}
|
|
542
669
|
|
|
@@ -560,7 +687,11 @@ export function toolbarState(view: DevView): unknown {
|
|
|
560
687
|
current: view.current === null ? { name: text.nobody, detail: '' } : { name: view.current.name, detail: detail(view.current.badges) },
|
|
561
688
|
personas: view.personas.map((persona) => ({ name: persona.name, detail: detail(persona.badges), href: persona.href, current: persona.current })),
|
|
562
689
|
links: view.links.map((link) => ({ title: link.title, detail: link.description ?? '', href: link.href })),
|
|
563
|
-
mail: view.mail.map((item) => ({
|
|
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
|
+
})),
|
|
564
695
|
outbox: view.outbox.map((item) => ({
|
|
565
696
|
subject: item.subject,
|
|
566
697
|
detail: `${text.to}: ${item.to}`,
|
package/src/app-dev.ts
CHANGED
|
@@ -9,7 +9,16 @@ 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 {
|
|
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'
|
|
21
|
+
import { sameOriginTarget } from '@fabrika/auth-core'
|
|
13
22
|
import { type ApplicationDialect, applicationDialect, CONFIG_FILE } from '@fabrika/check'
|
|
14
23
|
import { SqliteMigrationError } from '@fabrika/db/sqlite-migrate'
|
|
15
24
|
import { TEST_POSTGRES_URL, type TestDatabase, testDatabase } from '@fabrika/db/testing'
|
|
@@ -19,11 +28,13 @@ import { existsSync, readFileSync } from 'node:fs'
|
|
|
19
28
|
import { join } from 'node:path'
|
|
20
29
|
import { z } from 'zod/v4'
|
|
21
30
|
import { DEV_ENV_FILE, DevEnvProblem, type DevOutbox, devOutbox, mailHeadOf, readDevEnv, shownBody } from './app-dev-outside'
|
|
22
|
-
import { DEFAULT_SEED, importSeed,
|
|
31
|
+
import { DEFAULT_SEED, importSeed, NOTHING_SEEDED, parseSeeded, type Seeded, seedPath, SeedProblem } from './app-dev-seed'
|
|
23
32
|
import {
|
|
24
33
|
type Badge,
|
|
25
34
|
type CurrentView,
|
|
26
35
|
type DevView,
|
|
36
|
+
invitationMailPage,
|
|
37
|
+
type MailAction,
|
|
27
38
|
mailPage,
|
|
28
39
|
type MailView,
|
|
29
40
|
newestMail,
|
|
@@ -240,7 +251,7 @@ async function runSeed(dev: DevKit<AnyContract>, outside: DevOutside, path: stri
|
|
|
240
251
|
return parseSeeded(dev, answer)
|
|
241
252
|
}
|
|
242
253
|
|
|
243
|
-
/** What a
|
|
254
|
+
/** What a request's 5xx or a job attempt threw, printed whole on the developer's terminal. */
|
|
244
255
|
const printHandlerError = (where: string, error: unknown): void => {
|
|
245
256
|
console.error(`fabrika app dev: ${where} threw\n${Bun.inspect(error)}`)
|
|
246
257
|
}
|
|
@@ -292,9 +303,11 @@ async function serveDevKit(
|
|
|
292
303
|
const callers = new Map<string, LabelledTestCaller>()
|
|
293
304
|
const invitees = new Map<string, LabelledTestCaller>()
|
|
294
305
|
const toolbar = toolbarScript(STATE_PATH)
|
|
306
|
+
const urlHost = options.host.includes(':') ? `[${options.host}]` : options.host
|
|
307
|
+
let port = options.port
|
|
295
308
|
|
|
296
309
|
/** A path of this origin to go on to; anything else is the first SPA. */
|
|
297
|
-
const nextOf = (next: string | null): string => (next !== null &&
|
|
310
|
+
const nextOf = (next: string | null): string => (next !== null && sameOriginTarget(kit.origin, next) !== null ? next : firstSpa)
|
|
298
311
|
|
|
299
312
|
/** The caller a role choice names, made once and kept, so its membership changes last; `null` when it is no grant. */
|
|
300
313
|
const roleCaller = (role: string, value: string | null): LabelledTestCaller | null => {
|
|
@@ -345,6 +358,25 @@ async function serveDevKit(
|
|
|
345
358
|
}
|
|
346
359
|
|
|
347
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
|
+
: []
|
|
348
380
|
|
|
349
381
|
/** The values a membership role is offered in: the seed's, then those its personas hold. */
|
|
350
382
|
const valuesOf = (dimension: string): { readonly value: string; readonly label: string }[] => {
|
|
@@ -382,27 +414,31 @@ async function serveDevKit(
|
|
|
382
414
|
anonymousHref: chooseHref({ anonymous: '1' }, next),
|
|
383
415
|
links: seeded.links.map((link) => ({ title: link.title, description: link.description, href: link.url })),
|
|
384
416
|
mail: newestMail([
|
|
385
|
-
...dev.invitations().map((invitation): MailView =>
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
:
|
|
395
|
-
|
|
396
|
-
: null,
|
|
397
|
-
|
|
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
|
+
}),
|
|
398
432
|
...dev.mails().map((sent): MailView => ({
|
|
399
433
|
to: sent.to,
|
|
400
434
|
subject: sent.subject,
|
|
435
|
+
subjectLocale: null,
|
|
401
436
|
at: Date.parse(sent.at),
|
|
402
437
|
key: sent.key,
|
|
403
438
|
status: sent.outcome === 'accepted' ? 'sent' : sent.outcome,
|
|
404
439
|
answer: sent.answer === 'accepted' ? null : sent.answer,
|
|
405
|
-
|
|
440
|
+
note: null,
|
|
441
|
+
actions: [{ label: text.openMessage, href: `${MAIL_PATH}${sent.id}` }],
|
|
406
442
|
})),
|
|
407
443
|
]),
|
|
408
444
|
outbox: [...outbox.outbox()].reverse().map((message): OutboxView => ({ ...mailHeadOf(message), href: `${OUTBOX_PATH}${message.id}` })),
|
|
@@ -517,11 +553,18 @@ async function serveDevKit(
|
|
|
517
553
|
})
|
|
518
554
|
}
|
|
519
555
|
|
|
520
|
-
/**
|
|
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
|
+
*/
|
|
521
560
|
const mailMessage = (request: Request, path: string): Response => {
|
|
561
|
+
const view = viewOf(choiceOf(request), firstSpa)
|
|
522
562
|
const sent = dev.mails().find((candidate) => `${MAIL_PATH}${candidate.id}` === path)
|
|
523
|
-
if (sent
|
|
524
|
-
|
|
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 })
|
|
525
568
|
}
|
|
526
569
|
|
|
527
570
|
const devRoute = (request: Request, url: URL): Response | null => {
|
|
@@ -548,7 +591,6 @@ async function serveDevKit(
|
|
|
548
591
|
}
|
|
549
592
|
}
|
|
550
593
|
|
|
551
|
-
let port = options.port
|
|
552
594
|
const server = listen({
|
|
553
595
|
hostname: options.host,
|
|
554
596
|
port: options.port,
|
|
@@ -566,9 +608,8 @@ async function serveDevKit(
|
|
|
566
608
|
error: () => plain(500, 'app dev could not serve the request'),
|
|
567
609
|
})
|
|
568
610
|
port = server.port ?? options.port
|
|
569
|
-
const host = options.host.includes(':') ? `[${options.host}]` : options.host
|
|
570
611
|
return {
|
|
571
|
-
url: `http://${
|
|
612
|
+
url: `http://${urlHost}:${port}/`,
|
|
572
613
|
seeded: { personas: seeded.personas.length, links: seeded.links.length },
|
|
573
614
|
async stop() {
|
|
574
615
|
try {
|
package/src/connect.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { CONNECT_LIMITS, ContractError, parseExportDescription, snapshotNames, snapshotSource } from '@fabrika/app/contract'
|
|
2
2
|
import { isJsonMediaType, readBoundedBytes } from '@fabrika/app/implement'
|
|
3
3
|
import { API_KEY_PREFIX, type ExportDescription } from '@fabrika/auth-core'
|
|
4
|
+
import { CONTROL_RPC_PATH } from '@fabrika/control-contract'
|
|
4
5
|
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
5
6
|
import { dirname, join } from 'node:path'
|
|
7
|
+
import { controlOAuthBearer, type ControlOAuthDependencies, CREDENTIAL_HELPER_VARIABLE, defaultControlOAuthDependencies } from './control-oauth.js'
|
|
6
8
|
|
|
7
9
|
const KEY_VARIABLE = 'FABRIKA_CONTROL_KEY'
|
|
8
10
|
const URL_VARIABLE = 'FABRIKA_CONTROL_URL'
|
|
@@ -21,7 +23,8 @@ Usage:
|
|
|
21
23
|
|
|
22
24
|
Run from the application root. Both read the export the owner's environment <env> approved for the consumer from
|
|
23
25
|
Control (${URL_VARIABLE} or --url), with a machine key that holds deploy.read on the consumer, read from
|
|
24
|
-
${KEY_VARIABLE} in the environment only
|
|
26
|
+
${KEY_VARIABLE} in the environment only, or with the grant \`fabrika control auth device\` stored through
|
|
27
|
+
${CREDENTIAL_HELPER_VARIABLE}. The origin is https; plain http only for localhost. \`add\` refuses an
|
|
25
28
|
existing snapshot and prints what to add to src/app-kit.ts and to the endpoints that call it; \`pull\` refuses a missing one
|
|
26
29
|
and says whether the digest changed. The platform writes each import's address and key when it deploys the consumer.
|
|
27
30
|
`
|
|
@@ -35,6 +38,8 @@ export interface ConnectCommandDependencies {
|
|
|
35
38
|
readonly write: (line: string) => void
|
|
36
39
|
/** Guidance for the person running it. */
|
|
37
40
|
readonly note: (line: string) => void
|
|
41
|
+
/** Replaces the credential helper, its lock and the clock; only a test passes it. */
|
|
42
|
+
readonly oauth?: ControlOAuthDependencies
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
interface Target {
|
|
@@ -85,12 +90,23 @@ function parseTarget(command: string, argv: readonly string[], source: ConnectCo
|
|
|
85
90
|
return { app, export: name, version: Number(version), consumer, env, control: url.origin }
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
/** The key when it is set, else an access token for Control's RPC from the grant the credential helper holds. */
|
|
94
|
+
async function controlBearer(target: Target, deps: ConnectCommandDependencies): Promise<string> {
|
|
95
|
+
const key = deps.source[KEY_VARIABLE]?.trim() ?? ''
|
|
96
|
+
if (key !== '') {
|
|
97
|
+
if (!key.startsWith(API_KEY_PREFIX)) {
|
|
98
|
+
throw new Error(`${KEY_VARIABLE} must hold a ${API_KEY_PREFIX} machine key that holds deploy.read on the consumer`)
|
|
99
|
+
}
|
|
100
|
+
return key
|
|
101
|
+
}
|
|
102
|
+
const helper = deps.source[CREDENTIAL_HELPER_VARIABLE]?.trim() ?? ''
|
|
103
|
+
if (helper === '') {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`${KEY_VARIABLE} must hold a ${API_KEY_PREFIX} machine key that holds deploy.read on the consumer, or ${CREDENTIAL_HELPER_VARIABLE} the helper a \`fabrika control auth device\` grant is stored through`,
|
|
106
|
+
)
|
|
92
107
|
}
|
|
93
|
-
|
|
108
|
+
const oauth = deps.oauth ?? defaultControlOAuthDependencies(helper, deps.source, (input, init) => deps.fetch(new Request(input, init)))
|
|
109
|
+
return await controlOAuthBearer(target.control, oauth)(`${target.control}${CONTROL_RPC_PATH}`)
|
|
94
110
|
}
|
|
95
111
|
|
|
96
112
|
/**
|
|
@@ -188,7 +204,7 @@ function contractHint(description: ExportDescription): string[] {
|
|
|
188
204
|
|
|
189
205
|
async function add(argv: readonly string[], deps: ConnectCommandDependencies): Promise<void> {
|
|
190
206
|
const target = parseTarget('add', argv, deps.source)
|
|
191
|
-
const description = await fetchDescription(target,
|
|
207
|
+
const description = await fetchDescription(target, await controlBearer(target, deps), deps)
|
|
192
208
|
const { file } = snapshotNames(target.app, target.export, target.version)
|
|
193
209
|
const path = join(deps.cwd, file)
|
|
194
210
|
await mkdir(dirname(path), { recursive: true })
|
|
@@ -211,7 +227,7 @@ async function pull(argv: readonly string[], deps: ConnectCommandDependencies):
|
|
|
211
227
|
if (previous === null) {
|
|
212
228
|
throw new Error(`connect pull: ${file} does not exist; run fabrika connect add first`)
|
|
213
229
|
}
|
|
214
|
-
const description = await fetchDescription(target,
|
|
230
|
+
const description = await fetchDescription(target, await controlBearer(target, deps), deps)
|
|
215
231
|
const source = snapshotSource(description)
|
|
216
232
|
await writeFile(path, source)
|
|
217
233
|
deps.write(`${file}\n`)
|