@fabrika/auth-core 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/auth-core",
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",
@@ -0,0 +1,354 @@
1
+ // IAM's own e-mails, in every language it speaks, and how an application's wording of them (`mail`, `MailTemplate`)
2
+ // is rendered. IAM sends them; `fabrika app dev`'s stand-in IAM shows the same messages, so both read them from here
3
+ // and a preview matches what IAM of the same release sends. A value is plain text: every one is escaped where HTML inserts it.
4
+ // The wording is IAM's and changes with IAM, in any release: an application words its e-mails through its contract's
5
+ // `mail` templates, not by reading these strings.
6
+
7
+ import { DEFAULT_LOCALE, type Locale } from './locale'
8
+ import {
9
+ fillMailTemplate,
10
+ type MailHtmlToken,
11
+ mailHtmlTokens,
12
+ type MailPlaceholder,
13
+ type MailTemplate,
14
+ mailTemplateProblems,
15
+ type MessageKind,
16
+ } from './mail'
17
+
18
+ /** A rendered e-mail: the subject and both bodies, from the same values. */
19
+ export interface RenderedMessage {
20
+ readonly subject: string
21
+ readonly text: string
22
+ readonly html: string
23
+ }
24
+
25
+ /**
26
+ * How the owner of an invitation's mailbox accepts it. `create`: no principal holds the mailbox and accepting creates
27
+ * one with the password its owner chooses (ADR-0051). `sign_in`: a principal holds it, or single sign-on would admit
28
+ * it, so its owner signs in and accepts. `no_account`: neither, so the owner cannot accept until someone gives the
29
+ * mailbox an account.
30
+ */
31
+ export type InvitationAcceptance = 'create' | 'sign_in' | 'no_account'
32
+
33
+ export interface PasswordActionValues {
34
+ /** The application the action returns to; `null` for an action on the installation itself. */
35
+ readonly appName: string | null
36
+ readonly recipient: string
37
+ readonly actionUrl: string
38
+ readonly expiresAt: number
39
+ }
40
+
41
+ /**
42
+ * The closed set of values each IAM message is rendered from. Every value is plain text; a template escapes it. IAM
43
+ * builds the action URL itself, and a template places it. `expiresAt` is the link's expiry in seconds since the epoch.
44
+ */
45
+ export interface MessageValues {
46
+ readonly invitation: {
47
+ readonly appName: string
48
+ readonly role: string
49
+ readonly scope: string
50
+ readonly recipient: string
51
+ readonly inviterLabel: string
52
+ /** The invited person's company, as the inviting application names it; empty when the invitation names none. */
53
+ readonly companyLabel: string
54
+ /** The inviter's personal message; empty when the invitation carries none. */
55
+ readonly message: string
56
+ readonly actionUrl: string
57
+ readonly expiresAt: number
58
+ /** How the mailbox's owner accepts, as IAM can tell when it sends; it picks IAM's words, and is no placeholder. */
59
+ readonly acceptance: InvitationAcceptance
60
+ }
61
+ readonly enrollment: PasswordActionValues
62
+ readonly reset: PasswordActionValues
63
+ }
64
+
65
+ /** One template per message. IAM's catalog supplies a default set per language. */
66
+ export type MessageTemplates = { readonly [K in MessageKind]: (values: MessageValues[K]) => RenderedMessage }
67
+
68
+ /** IAM's words around an application's own wording of a message: the HTML part's button and the expiry. */
69
+ export interface ApplicationMailText {
70
+ readonly button: { readonly [K in MessageKind]: string }
71
+ /** `expiresAt` in seconds since the epoch, as the `{{expiry}}` placeholder shows it. */
72
+ readonly expiry: (expiresAt: number) => string
73
+ }
74
+
75
+ /** IAM's wording of its e-mails in one language. */
76
+ export interface IamMailCatalog {
77
+ readonly messages: MessageTemplates
78
+ readonly applicationMail: ApplicationMailText
79
+ }
80
+
81
+ /** Escape a value for HTML text and a quoted attribute, as IAM's pages do. */
82
+ function escapeHtml(value: string): string {
83
+ return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#39;')
84
+ }
85
+
86
+ /** The HTML of an inviter's personal message: its introduction, then the message escaped and quoted, line breaks kept. */
87
+ function quotedNote(note: { readonly intro: string; readonly message: string } | null): string {
88
+ if (note === null) return ''
89
+ const paragraphs = note.message.replaceAll('\r\n', '\n').split(/\n{2,}/).filter((paragraph) => paragraph.trim() !== '')
90
+ const quoted = paragraphs.map((paragraph) => `<p>${escapeHtml(paragraph).replaceAll('\n', '<br>')}</p>`).join('')
91
+ return `<p>${escapeHtml(note.intro)}</p><blockquote>${quoted}</blockquote>`
92
+ }
93
+
94
+ /** An invitation in one language's words: the sentence of what it gives, the note's introduction, how to accept. */
95
+ interface InvitationWords {
96
+ readonly subject: (appName: string) => string
97
+ readonly invited: (what: string) => string
98
+ readonly what: (values: { readonly appName: string; readonly role: string; readonly scope: string; readonly companyLabel: string }) => string
99
+ readonly writes: (inviterLabel: string) => string
100
+ readonly accept: { readonly [A in InvitationAcceptance]: string }
101
+ readonly button: string
102
+ readonly ignore: string
103
+ }
104
+
105
+ function invitationMessage(words: InvitationWords): MessageTemplates['invitation'] {
106
+ return ({ appName, role, scope, inviterLabel, companyLabel, message, actionUrl, acceptance }) => {
107
+ const what = words.what({ appName, role, scope, companyLabel })
108
+ const note = message === '' ? null : { intro: words.writes(inviterLabel), message }
109
+ const accept = words.accept[acceptance]
110
+ return {
111
+ subject: words.subject(appName),
112
+ text: [words.invited(what), ...(note === null ? [] : [note.intro, note.message]), accept, actionUrl, words.ignore].join('\n\n'),
113
+ html: `<p>${escapeHtml(words.invited(what))}</p>${quotedNote(note)}<p>${escapeHtml(accept)}</p><p><a href="${escapeHtml(actionUrl)}">${
114
+ escapeHtml(words.button)
115
+ }</a></p><p>${escapeHtml(words.ignore)}</p>`,
116
+ }
117
+ }
118
+ }
119
+
120
+ /** A password message in one language's words: the link sentence before the link, and the closing line. */
121
+ function passwordMessage(intro: (action: string) => string, ignore: string) {
122
+ return (subject: string, action: string, actionUrl: string): RenderedMessage => ({
123
+ subject,
124
+ text: `${intro(action)}\n\n${actionUrl}\n\n${ignore}`,
125
+ html: `<p>${escapeHtml(intro(action))}</p><p><a href="${escapeHtml(actionUrl)}">${escapeHtml(subject)}</a></p><p>${escapeHtml(ignore)}</p>`,
126
+ })
127
+ }
128
+
129
+ const expiryIn = (tag: string): ApplicationMailText['expiry'] => {
130
+ const format = new Intl.DateTimeFormat(tag, { dateStyle: 'long', timeStyle: 'short', timeZone: 'UTC' })
131
+ return (expiresAt) => `${format.format(new Date(expiresAt * 1000))} UTC`
132
+ }
133
+
134
+ function enCatalog(): IamMailCatalog {
135
+ const password = passwordMessage((action) => `Use this one-time link to ${action}:`, 'If you did not request this, you can ignore this email.')
136
+ return {
137
+ messages: {
138
+ invitation: invitationMessage({
139
+ subject: (appName) => `You are invited to ${appName}`,
140
+ invited: (what) => `You are invited to join a ${what}.`,
141
+ what: ({ appName, role, scope, companyLabel }) => `${scope} of ${appName} as ${role}${companyLabel === '' ? '' : `, for ${companyLabel}`}`,
142
+ writes: (inviterLabel) => `${inviterLabel} writes:`,
143
+ accept: {
144
+ create: 'Open this one-time link to accept. With an account here, sign in with this address first; without one, you choose a password.',
145
+ sign_in: 'Open this one-time link and sign in with this address to accept.',
146
+ no_account:
147
+ 'There is no account for this address here yet, and this invitation does not create one. Ask the person who invited you to have one set up, then open this one-time link and sign in to accept.',
148
+ },
149
+ button: 'Accept the invitation',
150
+ ignore: 'If you did not expect this, you can ignore this email.',
151
+ }),
152
+ enrollment: ({ appName, actionUrl }) =>
153
+ password(
154
+ appName === null ? 'Set your Fabrika password' : `Set your password for ${appName}`,
155
+ appName === null ? 'set your Fabrika password' : `set your password for ${appName}`,
156
+ actionUrl,
157
+ ),
158
+ reset: ({ appName, actionUrl }) =>
159
+ password(
160
+ appName === null ? 'Reset your Fabrika password' : `Reset your password for ${appName}`,
161
+ appName === null ? 'reset your Fabrika password' : `reset your password for ${appName}`,
162
+ actionUrl,
163
+ ),
164
+ },
165
+ applicationMail: {
166
+ button: { invitation: 'Accept the invitation', enrollment: 'Set your password', reset: 'Reset your password' },
167
+ expiry: expiryIn('en-GB'),
168
+ },
169
+ }
170
+ }
171
+
172
+ function csCatalog(): IamMailCatalog {
173
+ const password = passwordMessage((action) => `Tímto jednorázovým odkazem ${action}:`, 'Pokud jste o to nežádali, můžete tento e-mail ignorovat.')
174
+ return {
175
+ messages: {
176
+ invitation: invitationMessage({
177
+ subject: (appName) => `Pozvánka do aplikace ${appName}`,
178
+ invited: (what) => `Dostali jste pozvánku ${what}.`,
179
+ what: ({ appName, role, scope, companyLabel }) =>
180
+ `do aplikace ${appName} s rolí ${role} (${scope})${companyLabel === '' ? '' : ` za ${companyLabel}`}`,
181
+ writes: (inviterLabel) => `${inviterLabel} píše:`,
182
+ accept: {
183
+ create: 'Pozvánku přijmete tímto jednorázovým odkazem. Máte-li zde účet, nejprve se přihlaste touto adresou; pokud ho nemáte, zvolíte si heslo.',
184
+ sign_in: 'Pozvánku přijmete tímto jednorázovým odkazem po přihlášení touto adresou.',
185
+ no_account:
186
+ 'Pro tuto adresu tu zatím není účet a tato pozvánka ho nezakládá. Požádejte toho, kdo vás pozval, aby vám ho zřídil; potom pozvánku přijmete tímto jednorázovým odkazem po přihlášení.',
187
+ },
188
+ button: 'Přijmout pozvánku',
189
+ ignore: 'Pokud jste pozvánku nečekali, můžete tento e-mail ignorovat.',
190
+ }),
191
+ enrollment: ({ appName, actionUrl }) =>
192
+ password(appName === null ? 'Nastavení hesla' : `Nastavení hesla pro aplikaci ${appName}`, 'si nastavíte heslo', actionUrl),
193
+ reset: ({ appName, actionUrl }) =>
194
+ password(appName === null ? 'Obnovení hesla' : `Obnovení hesla pro aplikaci ${appName}`, 'si obnovíte heslo', actionUrl),
195
+ },
196
+ applicationMail: {
197
+ button: { invitation: 'Přijmout pozvánku', enrollment: 'Nastavit heslo', reset: 'Obnovit heslo' },
198
+ expiry: expiryIn('cs'),
199
+ },
200
+ }
201
+ }
202
+
203
+ function ukCatalog(): IamMailCatalog {
204
+ const password = passwordMessage(
205
+ (action) => `Скористайтеся цим одноразовим посиланням, щоб ${action}:`,
206
+ 'Якщо ви цього не запитували, просто проігноруйте цей лист.',
207
+ )
208
+ return {
209
+ messages: {
210
+ invitation: invitationMessage({
211
+ subject: (appName) => `Запрошення до застосунку ${appName}`,
212
+ invited: (what) => `Вас запрошено ${what}.`,
213
+ what: ({ appName, role, scope, companyLabel }) =>
214
+ `до застосунку ${appName} з роллю ${role} (${scope})${companyLabel === '' ? '' : `, організація: ${companyLabel}`}`,
215
+ writes: (inviterLabel) => `${inviterLabel} пише:`,
216
+ accept: {
217
+ create:
218
+ 'Щоб прийняти запрошення, відкрийте це одноразове посилання. Якщо у вас тут уже є обліковий запис, спочатку увійдіть із цією адресою; якщо немає, ви створите пароль.',
219
+ sign_in: 'Щоб прийняти запрошення, відкрийте це одноразове посилання й увійдіть із цією адресою.',
220
+ no_account:
221
+ 'Для цієї адреси тут ще немає облікового запису, і це запрошення його не створює. Попросіть того, хто вас запросив, створити його, а потім відкрийте це одноразове посилання й увійдіть, щоб прийняти запрошення.',
222
+ },
223
+ button: 'Прийняти запрошення',
224
+ ignore: 'Якщо ви не очікували цього запрошення, просто проігноруйте цей лист.',
225
+ }),
226
+ enrollment: ({ appName, actionUrl }) =>
227
+ password(appName === null ? 'Створення пароля' : `Створення пароля для застосунку ${appName}`, 'створити пароль', actionUrl),
228
+ reset: ({ appName, actionUrl }) =>
229
+ password(appName === null ? 'Відновлення пароля' : `Відновлення пароля для застосунку ${appName}`, 'відновити пароль', actionUrl),
230
+ },
231
+ applicationMail: {
232
+ button: { invitation: 'Прийняти запрошення', enrollment: 'Створити пароль', reset: 'Відновити пароль' },
233
+ expiry: expiryIn('uk'),
234
+ },
235
+ }
236
+ }
237
+
238
+ /** Each language's words, built on first use: a consumer of this package that sends no IAM e-mail bundles none of them. */
239
+ const catalogs: { readonly [L in Locale]: () => IamMailCatalog } = { en: enCatalog, cs: csCatalog, uk: ukCatalog }
240
+ const built: { [L in Locale]?: IamMailCatalog } = {}
241
+
242
+ /** IAM's wording of its e-mails in `locale`. */
243
+ export function iamMailCatalog(locale: Locale): IamMailCatalog {
244
+ built[locale] ??= catalogs[locale]()
245
+ return built[locale]
246
+ }
247
+
248
+ /**
249
+ * The language IAM writes an e-mail in: the person's own (the language an invitation names, else the one the mailbox's
250
+ * principal keeps, ADR-0077), else the application's, else the default. An e-mail has no request to ask, so IAM's
251
+ * `chooseLocale` without one comes to the same language; IAM's tests hold the two equal.
252
+ */
253
+ export function mailLocale(sources: { readonly person?: Locale | null; readonly app?: Locale | null }): Locale {
254
+ return sources.person ?? sources.app ?? DEFAULT_LOCALE
255
+ }
256
+
257
+ type Placeholders<K extends MessageKind> = { readonly [P in MailPlaceholder<K>]: string }
258
+
259
+ /** The values an application's template of each message names, beside those every message names. */
260
+ const PLACEHOLDER_VALUES: {
261
+ readonly [K in MessageKind]: (values: MessageValues[K]) => Omit<Placeholders<K>, 'displayName' | 'expiry' | 'appUrl'>
262
+ } = {
263
+ invitation: ({ recipient, inviterLabel, companyLabel, message, actionUrl }) => ({ recipient, inviterLabel, companyLabel, message, actionUrl }),
264
+ enrollment: ({ recipient, actionUrl }) => ({ recipient, actionUrl }),
265
+ reset: ({ recipient, actionUrl }) => ({ recipient, actionUrl }),
266
+ }
267
+
268
+ /** What an IAM e-mail of one application is rendered with, beside its message's values. */
269
+ export interface MailRendering {
270
+ /** The e-mail's language (`mailLocale`). */
271
+ readonly locale: Locale
272
+ /** The application's own template of the message in that language; `null` when it declares none. */
273
+ readonly template: MailTemplate | null
274
+ /** `{{displayName}}`: the application's display name, else its id. */
275
+ readonly displayName: string
276
+ /** `{{appUrl}}`: the application's address with a trailing slash; `null` while no return origin is registered. */
277
+ readonly appUrl: string | null
278
+ /** The longest subject the sender accepts: a filled template's subject gives way at its end. */
279
+ readonly maxSubjectLength: number
280
+ }
281
+
282
+ /**
283
+ * The template IAM renders a `kind` e-mail with: the application's own wording when it declares one in the e-mail's
284
+ * language, else the catalog's. A template the rule no longer admits is the catalog's, and so is one that names
285
+ * `{{appUrl}}` while the application has no registered return origin to build it from.
286
+ */
287
+ export function iamMessageTemplate<K extends MessageKind>(kind: K, rendering: MailRendering): (values: MessageValues[K]) => RenderedMessage {
288
+ const catalog = iamMailCatalog(rendering.locale)
289
+ const { template, appUrl } = rendering
290
+ if (template === null) return catalog.messages[kind]
291
+ const html = template.html === undefined ? null : mailHtmlTokens(template.html)
292
+ const namesAppUrl = [template.subject, template.text, template.html ?? ''].some((part) => part.includes('{{appUrl}}'))
293
+ if (mailTemplateProblems(kind, template).length > 0 || (namesAppUrl && appUrl === null)) {
294
+ return catalog.messages[kind]
295
+ }
296
+ const tokens = html !== null && html.ok ? html.tokens : null
297
+ return (values) => {
298
+ const placeholders: Readonly<Record<string, string>> = {
299
+ ...PLACEHOLDER_VALUES[kind](values),
300
+ displayName: rendering.displayName,
301
+ expiry: catalog.applicationMail.expiry(values.expiresAt),
302
+ appUrl: appUrl ?? '',
303
+ }
304
+ const message = applicationMessage(template, placeholders, values.actionUrl, catalog.applicationMail.button[kind], rendering.maxSubjectLength)
305
+ return tokens === null ? message : { ...message, html: renderHtml(tokens, placeholders) }
306
+ }
307
+ }
308
+
309
+ /**
310
+ * An application's HTML body, rendered from its tokens and never from its source: each element as the subset writes
311
+ * it, the literal text as the application wrote it (`mailHtmlTokens` admitted no `<` and no bare `&` in it), every value
312
+ * escaped, and each link's `href` the escaped URL it names.
313
+ */
314
+ function renderHtml(tokens: readonly MailHtmlToken[], placeholders: Readonly<Record<string, string>>): string {
315
+ return tokens.map((token) => {
316
+ if (token.kind === 'close') return `</${token.name}>`
317
+ if (token.kind === 'open') {
318
+ return token.href === null ? `<${token.name}>` : `<${token.name} href="${escapeHtml(fillMailTemplate(token.href, placeholders))}">`
319
+ }
320
+ return token.text.replaceAll(/\{\{([^{}]*)\}\}/g, (_, name: string) => escapeHtml(placeholders[name] ?? ''))
321
+ }).join('')
322
+ }
323
+
324
+ /**
325
+ * An application's wording filled in: the text as written, the subject on one line, and IAM's own HTML part — the
326
+ * escaped text as paragraphs and IAM's button to the action URL. An application's own HTML body replaces that part.
327
+ */
328
+ function applicationMessage(
329
+ template: MailTemplate,
330
+ placeholders: Readonly<Record<string, string>>,
331
+ actionUrl: string,
332
+ button: string,
333
+ maxSubjectLength: number,
334
+ ): RenderedMessage {
335
+ const text = fillMailTemplate(template.text, placeholders).replaceAll('\r\n', '\n')
336
+ const oneLine = Object.fromEntries(Object.entries(placeholders).map(([name, value]) => [name, value.replaceAll(/\p{Cc}+/gu, ' ')]))
337
+ const paragraphs = text.split(/\n{2,}/).filter((paragraph) => paragraph.trim() !== '')
338
+ const html = [
339
+ ...paragraphs.map((paragraph) => `<p>${escapeHtml(paragraph).replaceAll('\n', '<br>')}</p>`),
340
+ `<p><a href="${escapeHtml(actionUrl)}">${escapeHtml(button)}</a></p>`,
341
+ ].join('')
342
+ return { subject: boundedSubject(fillMailTemplate(template.subject, oneLine), maxSubjectLength), text, html }
343
+ }
344
+
345
+ /** A filled subject the sender accepts: values can expand a short template past its limit, so the end gives way. */
346
+ function boundedSubject(subject: string, max: number): string {
347
+ if (subject.length <= max) return subject
348
+ let bounded = ''
349
+ for (const character of subject) {
350
+ if (bounded.length + character.length > max - 1) break
351
+ bounded += character
352
+ }
353
+ return `${bounded}…`
354
+ }
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ export * from './endpoints'
13
13
  export * from './environment'
14
14
  export * from './framework-release'
15
15
  export * from './framework-variables'
16
+ export * from './iam-mail'
16
17
  export * from './installation-endpoint'
17
18
  export { parseJsonStringArray } from './json'
18
19
  export * from './locale'
package/src/locale.ts CHANGED
@@ -13,6 +13,18 @@ export function isLocale(value: unknown): value is Locale {
13
13
  return LOCALES.some((locale) => locale === value)
14
14
  }
15
15
 
16
+ /**
17
+ * The cookie that names the language a browser reads fabrika's pages in, host-only on whichever host wrote it: IAM's
18
+ * on IAM's host, an application's on its own. An application's proxy passes the value on its host to IAM's sign-in as
19
+ * `LOCALE_PARAM`. It picks words and nothing else: no credential, landing or authority depends on it, and a value
20
+ * that is not a `Locale` counts as none. Its name does not start with `FABRIKA_COOKIE_PREFIX`, so the proxy leaves it
21
+ * on the request it sends an application.
22
+ */
23
+ export const LOCALE_COOKIE = '__Host-fabrika_locale'
24
+
25
+ /** The query parameter IAM's pages read the reader's language from: IAM's own links and the proxy's sign-in bounce. */
26
+ export const LOCALE_PARAM = 'locale'
27
+
16
28
  /** The longest display name, in code points: it is a page heading and part of an e-mail subject. */
17
29
  export const MAX_DISPLAY_NAME_LENGTH = 80
18
30
 
@@ -0,0 +1,92 @@
1
+ import { type Locale } from './locale';
2
+ import { type MailTemplate, type MessageKind } from './mail';
3
+ /** A rendered e-mail: the subject and both bodies, from the same values. */
4
+ export interface RenderedMessage {
5
+ readonly subject: string;
6
+ readonly text: string;
7
+ readonly html: string;
8
+ }
9
+ /**
10
+ * How the owner of an invitation's mailbox accepts it. `create`: no principal holds the mailbox and accepting creates
11
+ * one with the password its owner chooses (ADR-0051). `sign_in`: a principal holds it, or single sign-on would admit
12
+ * it, so its owner signs in and accepts. `no_account`: neither, so the owner cannot accept until someone gives the
13
+ * mailbox an account.
14
+ */
15
+ export type InvitationAcceptance = 'create' | 'sign_in' | 'no_account';
16
+ export interface PasswordActionValues {
17
+ /** The application the action returns to; `null` for an action on the installation itself. */
18
+ readonly appName: string | null;
19
+ readonly recipient: string;
20
+ readonly actionUrl: string;
21
+ readonly expiresAt: number;
22
+ }
23
+ /**
24
+ * The closed set of values each IAM message is rendered from. Every value is plain text; a template escapes it. IAM
25
+ * builds the action URL itself, and a template places it. `expiresAt` is the link's expiry in seconds since the epoch.
26
+ */
27
+ export interface MessageValues {
28
+ readonly invitation: {
29
+ readonly appName: string;
30
+ readonly role: string;
31
+ readonly scope: string;
32
+ readonly recipient: string;
33
+ readonly inviterLabel: string;
34
+ /** The invited person's company, as the inviting application names it; empty when the invitation names none. */
35
+ readonly companyLabel: string;
36
+ /** The inviter's personal message; empty when the invitation carries none. */
37
+ readonly message: string;
38
+ readonly actionUrl: string;
39
+ readonly expiresAt: number;
40
+ /** How the mailbox's owner accepts, as IAM can tell when it sends; it picks IAM's words, and is no placeholder. */
41
+ readonly acceptance: InvitationAcceptance;
42
+ };
43
+ readonly enrollment: PasswordActionValues;
44
+ readonly reset: PasswordActionValues;
45
+ }
46
+ /** One template per message. IAM's catalog supplies a default set per language. */
47
+ export type MessageTemplates = {
48
+ readonly [K in MessageKind]: (values: MessageValues[K]) => RenderedMessage;
49
+ };
50
+ /** IAM's words around an application's own wording of a message: the HTML part's button and the expiry. */
51
+ export interface ApplicationMailText {
52
+ readonly button: {
53
+ readonly [K in MessageKind]: string;
54
+ };
55
+ /** `expiresAt` in seconds since the epoch, as the `{{expiry}}` placeholder shows it. */
56
+ readonly expiry: (expiresAt: number) => string;
57
+ }
58
+ /** IAM's wording of its e-mails in one language. */
59
+ export interface IamMailCatalog {
60
+ readonly messages: MessageTemplates;
61
+ readonly applicationMail: ApplicationMailText;
62
+ }
63
+ /** IAM's wording of its e-mails in `locale`. */
64
+ export declare function iamMailCatalog(locale: Locale): IamMailCatalog;
65
+ /**
66
+ * The language IAM writes an e-mail in: the person's own (the language an invitation names, else the one the mailbox's
67
+ * principal keeps, ADR-0077), else the application's, else the default. An e-mail has no request to ask, so IAM's
68
+ * `chooseLocale` without one comes to the same language; IAM's tests hold the two equal.
69
+ */
70
+ export declare function mailLocale(sources: {
71
+ readonly person?: Locale | null;
72
+ readonly app?: Locale | null;
73
+ }): Locale;
74
+ /** What an IAM e-mail of one application is rendered with, beside its message's values. */
75
+ export interface MailRendering {
76
+ /** The e-mail's language (`mailLocale`). */
77
+ readonly locale: Locale;
78
+ /** The application's own template of the message in that language; `null` when it declares none. */
79
+ readonly template: MailTemplate | null;
80
+ /** `{{displayName}}`: the application's display name, else its id. */
81
+ readonly displayName: string;
82
+ /** `{{appUrl}}`: the application's address with a trailing slash; `null` while no return origin is registered. */
83
+ readonly appUrl: string | null;
84
+ /** The longest subject the sender accepts: a filled template's subject gives way at its end. */
85
+ readonly maxSubjectLength: number;
86
+ }
87
+ /**
88
+ * The template IAM renders a `kind` e-mail with: the application's own wording when it declares one in the e-mail's
89
+ * language, else the catalog's. A template the rule no longer admits is the catalog's, and so is one that names
90
+ * `{{appUrl}}` while the application has no registered return origin to build it from.
91
+ */
92
+ export declare function iamMessageTemplate<K extends MessageKind>(kind: K, rendering: MailRendering): (values: MessageValues[K]) => RenderedMessage;
@@ -12,6 +12,7 @@ export * from './endpoints';
12
12
  export * from './environment';
13
13
  export * from './framework-release';
14
14
  export * from './framework-variables';
15
+ export * from './iam-mail';
15
16
  export * from './installation-endpoint';
16
17
  export { parseJsonStringArray } from './json';
17
18
  export * from './locale';
@@ -4,6 +4,16 @@ export type Locale = (typeof LOCALES)[number];
4
4
  /** IAM's language for a request that names no application, or one that declares none. */
5
5
  export declare const DEFAULT_LOCALE: Locale;
6
6
  export declare function isLocale(value: unknown): value is Locale;
7
+ /**
8
+ * The cookie that names the language a browser reads fabrika's pages in, host-only on whichever host wrote it: IAM's
9
+ * on IAM's host, an application's on its own. An application's proxy passes the value on its host to IAM's sign-in as
10
+ * `LOCALE_PARAM`. It picks words and nothing else: no credential, landing or authority depends on it, and a value
11
+ * that is not a `Locale` counts as none. Its name does not start with `FABRIKA_COOKIE_PREFIX`, so the proxy leaves it
12
+ * on the request it sends an application.
13
+ */
14
+ export declare const LOCALE_COOKIE = "__Host-fabrika_locale";
15
+ /** The query parameter IAM's pages read the reader's language from: IAM's own links and the proxy's sign-in bounce. */
16
+ export declare const LOCALE_PARAM = "locale";
7
17
  /** The longest display name, in code points: it is a page heading and part of an e-mail subject. */
8
18
  export declare const MAX_DISPLAY_NAME_LENGTH = 80;
9
19
  /**