- docs, AGENT.md, the 16 skills, PROGRAMISTA and README use the preferred names (scripted, same list of forms); past CHANGELOG entries and the proposals in docs/dev are not rewritten - AGENT.md: 'Names: IAPL and ipal-kit' — old name, new name, state in 1.x; what is not renamed; storageNames - iapl-upgrade '→ 1.17.0', PROGRAMISTA §6 item 72, CHANGELOG 1.17.0 (draft): nothing required - env.md, doctor.md (legacy-names, storage-names), stats.md, security.md, project-starter.md, iapl-reference, iapl-setup - skill scripts read ipal-audit-skip and IPAL_IP_HEADER too; audit rule ids stay what they were - reference site: iapl(), iapl-doctor.json, iapl-* skills, storageNames: 'iapl'; INDEX.md regenerated Co-Authored-By: Claude Fable 5.2 <[email protected]>
6.5 KiB
notifications
Notification texts (action results) configured in the admin panel, per language, with a
fallback. Today it covers form result messages (submitForm),
with room for future contexts. The Notifications global is always built.
Principle
The plugin returns a result CODE (submitForm returns reason), not text. This module
maps code → text from the panel (localized), with an English fallback per field.
The frontend gets a ready string and styles it as it likes (toast, inline, banner).
This way no message is hardcoded — everything goes through the panel.
Config
No options — the Notifications global (slug notifications, shown in the panel as Form messages, group Forms) is always built. The editor manages
the texts in the panel (Form messages), grouped per context. Group form:
success, error, rateLimited, turnstile, validation, consent,
notFound and the multi-step form buttons: next ("Next"), back ("Back"),
stepOf ("Step {current} of {total}"). Every empty field → the built-in default in the page language
(notificationFallback(locale): NOTIFICATION_FALLBACK_PL for pl, else NOTIFICATION_FALLBACK — EN;
all exported from @intecion/ipal-kit). In validation, {field} is the field's label in the page language.
For forms: getFormTexts(locale) from lib/content = the form group in the given language.
Group lightbox (only with iapl({ lightbox: true }) — adds columns, run a migration on Postgres):
open ("Enlarge image"), dialog ("Image viewer"), previous, next, close, counter
("{current} / {total}"). getNotificationTexts(...).lightbox always returns the full set (fallback
LIGHTBOX_FALLBACK), and getSiteShell(locale).lightboxTexts carries it to <SiteProviders lightbox>.
Details: lightbox.md.
Helper — getNotificationTexts
Reads the texts from the global per language, with a fallback per field. The counterpart of getConsentTexts:
import { getNotificationTexts } from '@intecion/ipal-kit'
const notifications = await getNotificationTexts({ payload, locale }) // in lib/content: getFormTexts(locale) = .form
// notifications.form.error, notifications.form.success, ..., notifications.lightbox.close
Mapping the result — resolveFormMessage
The bridge between submitForm and the UI: takes the result and the texts, returns one message.
Interpolates {field} in the validation text. NEVER shows a raw exception
(error → a generic text, not the backend error message).
import { resolveFormMessage } from '@intecion/ipal-kit'
const result = await submitFormAction(...)
if (!result.success) {
setError(resolveFormMessage(result, notifications.form))
}
This replaces a hardcoded Error: ${result.reason} — now a friendly text from the panel,
per language.
File field texts
With forms.attachments (forms.md "Files") the Files group of Form messages holds:
Each one tells the visitor that the problem is the file, why, and what to do next.
| Key | Placeholders | English default |
|---|---|---|
fileTooLarge |
{file}, {max} (MB) |
The file "{file}" is too large. Choose a file of up to {max} MB. |
fileType |
{file}, {types} |
The file "{file}" is in a format we do not accept. Choose one of: {types}. |
fileRefused |
{file}, {types} |
The file "{file}" was refused: it is a program or an archive, it holds macros, or its content does not match its type. Choose another file ({types}). |
fileCount |
{field}, {max} |
Too many files in "{field}". Remove some: the limit is {max}. |
fileNotSent |
{file} |
We could not send the file "{file}". Choose a smaller file or another format and try again. |
fileOptional |
— | You can also send the form without the file. — added to the five above when the File field is not required |
fileRemove |
{file} |
Remove {file} |
Polish defaults ship too; any other language is filled in the panel (an empty field falls back to English there).
resolveFormMessage maps kind: 'file_too_large' | 'file_type' | 'file_refused' | 'file_count' and
reason: 'delivery' to them and appends fileOptional when the result says optional; a texts object without
these keys falls back to validation / error. The result carries field, so the message shows at the File field.
{field} interpolation
The validation text may contain {field} — it is replaced with the label of the field with
the error in the page language (the technical name only when the field has no label), only the first {field} occurrence;
no field at fault → the generic error text instead:
Panel: "Sprawdź pole {field} i spróbuj ponownie."
Result: "Sprawdź pole E-mail i spróbuj ponownie."
Adding new contexts
The form group is the first context. Further ones (newsletter, system) are added
the same way — a new group in globals/Notifications/fields.ts + a field in the types +
a fallback. getNotificationTexts resolves whatever exists.
Access
The global has read: () => true — the texts are public (shown to end
users), so the frontend reads them without a session. Write: editor+ (adminOrEditor). Unlike SiteIntegrations
(read: isAdmin — secrets live there).
Turn off, override, extend
- Turn off: none — the
notificationsglobal is currently always added (also without theformsoption). Thelightboxgroup is opt-in (iapl({ lightbox: true }));lightboxNotificationFieldsputs it in your own global instead. - Override texts: in the panel, per language; empty field →
notificationFallback(locale)(Polish onplpages, English otherwise). The fallbacks cannot be swapped with a plugin option — apply your own default texts in the project on the result ofgetNotificationTexts(e.g.texts.form.error ||= '…'). - Override access / hooks / admin:
iapl({ globalOverrides: { notifications: … } })— an object mergesaccess,adminandhookskey by key over the plugin's (e.g. let any logged-in user edit:{ notifications: { access: { update: authenticated } } }), a function gets the global and returns the one to use. - Override mapping:
resolveFormMessageis optional — you can mapresult.reasonwith your own switch. - Extend: the global's fields are fixed in the plugin (no
iaploption to add groups / fields); for a project-only extra, aglobalOverrides.notificationsfunction can append fields, butgetNotificationTextswill not read them — a new shared context needs a change in the plugin (globals/Notifications/fields.ts, types, fallback).