diff --git a/dist/globals/Notifications/fields.d.ts b/dist/globals/Notifications/fields.d.ts new file mode 100644 index 0000000..ea36397 --- /dev/null +++ b/dist/globals/Notifications/fields.d.ts @@ -0,0 +1,13 @@ +import type { Field } from 'payload'; +/** + * Fields for the Notifications global — localized user-facing texts for action + * results (form submission outcomes, and future contexts). Every text is + * localized: true so each language has its own value. Empty fields fall back to + * built-in English defaults (see modules/notifications/defaults). + * + * Grouped per context. `form` holds the outcomes of submitForm; more groups + * (e.g. `newsletter`, `system`) can be added the same way without touching + * consumers — getNotificationTexts resolves whatever exists, falling back + * per field. + */ +export declare const notificationsFields: Field[]; diff --git a/dist/globals/Notifications/index.d.ts b/dist/globals/Notifications/index.d.ts new file mode 100644 index 0000000..97d970e --- /dev/null +++ b/dist/globals/Notifications/index.d.ts @@ -0,0 +1,7 @@ +import type { GlobalConfig } from 'payload'; +/** + * Builds the Notifications global — localized action-result texts. Readable by + * any authenticated panel user; server-side helpers read it with overrideAccess + * so the frontend can resolve texts without a session. + */ +export declare function buildNotifications(): GlobalConfig; diff --git a/dist/globals/SiteIntegrations/components/MaskedField.d.ts b/dist/globals/SiteIntegrations/components/MaskedField.d.ts new file mode 100644 index 0000000..12a4ed8 --- /dev/null +++ b/dist/globals/SiteIntegrations/components/MaskedField.d.ts @@ -0,0 +1,3 @@ +import type { TextFieldClientComponent } from 'payload'; +export declare const MaskedField: TextFieldClientComponent; +export default MaskedField; diff --git a/dist/modules/notifications/defaults.d.ts b/dist/modules/notifications/defaults.d.ts new file mode 100644 index 0000000..c0b9d09 --- /dev/null +++ b/dist/modules/notifications/defaults.d.ts @@ -0,0 +1,7 @@ +import type { NotificationTexts } from './types.js'; +/** + * Built-in English fallbacks, used per field when the Notifications global + * leaves a text empty. Same philosophy as consent FALLBACK: the site works out + * of the box, editors override per locale as needed. + */ +export declare const NOTIFICATION_FALLBACK: NotificationTexts; diff --git a/dist/modules/notifications/getNotificationTexts.d.ts b/dist/modules/notifications/getNotificationTexts.d.ts new file mode 100644 index 0000000..0f44ef1 --- /dev/null +++ b/dist/modules/notifications/getNotificationTexts.d.ts @@ -0,0 +1,15 @@ +import type { BasePayload } from 'payload'; +import type { NotificationTexts } from './types.js'; +type GetNotificationTextsArgs = { + /** Active locale — selects the language variant of each text. */ + locale?: string; + payload: BasePayload; +}; +/** + * Resolves notification texts from the Notifications global, falling back to + * English defaults per field. Mirrors getConsentTexts: one read, per-field + * fallback, locale-aware. The frontend maps a submitForm result code to the + * matching text and styles it however it likes (toast, inline, banner). + */ +export declare function getNotificationTexts({ locale, payload, }: GetNotificationTextsArgs): Promise; +export {}; diff --git a/dist/modules/notifications/index.d.ts b/dist/modules/notifications/index.d.ts new file mode 100644 index 0000000..f882db4 --- /dev/null +++ b/dist/modules/notifications/index.d.ts @@ -0,0 +1,4 @@ +export { NOTIFICATION_FALLBACK } from './defaults.js'; +export { getNotificationTexts } from './getNotificationTexts.js'; +export { resolveFormMessage } from './resolveFormMessage.js'; +export type { FormNotificationTexts, NotificationsData, NotificationTexts } from './types.js'; diff --git a/dist/modules/notifications/resolveFormMessage.d.ts b/dist/modules/notifications/resolveFormMessage.d.ts new file mode 100644 index 0000000..527910c --- /dev/null +++ b/dist/modules/notifications/resolveFormMessage.d.ts @@ -0,0 +1,13 @@ +import type { SubmitFormResult } from '../forms/index.js'; +import type { FormNotificationTexts } from './types.js'; +/** + * Maps a submitForm result to the user-facing message, interpolating {field} + * for validation errors. This is the bridge the frontend uses: it gets a result + * code from submitForm and the resolved texts from getNotificationTexts, and + * this turns them into one string to display. Keeping the mapping here means the + * frontend never hard-codes messages or knows about result codes. + * + * Never surfaces raw backend/exception detail — 'error' maps to a friendly + * generic message, not the thrown error's text (which could leak internals). + */ +export declare function resolveFormMessage(result: SubmitFormResult, texts: FormNotificationTexts): string; diff --git a/dist/modules/notifications/types.d.ts b/dist/modules/notifications/types.d.ts new file mode 100644 index 0000000..c438ef7 --- /dev/null +++ b/dist/modules/notifications/types.d.ts @@ -0,0 +1,22 @@ +/** + * Resolved notification texts, ready for the frontend. Grouped per context; + * `form` maps submitForm result codes to user-facing messages. + */ +export type FormNotificationTexts = { + success: string; + error: string; + rateLimited: string; + turnstile: string; + /** May contain the {field} placeholder — resolve with resolveValidationText. */ + validation: string; + /** Shown when a required GDPR consent checkbox was left unchecked. */ + consent: string; + notFound: string; +}; +export type NotificationTexts = { + form: FormNotificationTexts; +}; +/** Raw shape read from the Notifications global (all fields optional). */ +export type NotificationsData = { + form?: Partial; +}; diff --git a/package.json b/package.json index 0df7cff..c7a2fcf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@intecion/ipal-kit", - "version": "1.0.3", + "version": "1.0.4", "description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.", "license": "MIT", "repository": {