Stone.js API
    Preparing search index...

    Interface NoticeInstance<EventType>

    A notice: a class that knows what to say, and to whom.

    The decorator declares what a notice is; the class holds what it says. That separation is the point: metadata belongs on the declaration, content belongs in code, where it can read the event, translate, format a date, or ask a service for a link.

    @Notice({ name: 'guardianship.consent_needed', on: 'identity.guardian.invited.v1' })
    export class ConsentNeeded {
    constructor ({ i18n }) { this.i18n = i18n }

    recipients (event) { return event.guardianId }

    notify (event, { locale }) {
    return {
    smtp: { subject: this.i18n.t('consent.subject', { lng: locale }), body: … },
    'in-app': { body: … }
    }
    }
    }
    interface NoticeInstance<EventType = any> {
        dedupe?: (event: EventType) => Promiseable<string>;
        notify: (
            event: EventType,
            context: NoticeContext,
        ) => Promiseable<NoticeContentInput>;
        recipients?: (
            event: EventType,
        ) => Promiseable<RecipientInput | RecipientInput[]>;
    }

    Type Parameters

    • EventType = any
    Index
    dedupe?: (event: EventType) => Promiseable<string>

    A key that makes this occurrence unique.

    The answer to the most common production failure of any notification system: the same message twice, because a queue is at-least-once, because a retry half succeeded, or because two events describe one fact. Return a key and the second attempt is dropped.

    notify: (
        event: EventType,
        context: NoticeContext,
    ) => Promiseable<NoticeContentInput>

    What this notice says, for this person.

    Called once per recipient, never once per channel, so a name in the body is rendered once and a channel-specific body is chosen from what it returns.

    recipients?: (
        event: EventType,
    ) => Promiseable<RecipientInput | RecipientInput[]>

    Who learns about it.

    Required when the notice reacts to an event, because nobody else can say: the event carries the account, and only the notice knows which field that is. Unused when a caller names the recipient itself.