The notice's metadata.
A class decorator.
@Notice({
name: 'guardianship.consent_needed',
on: 'identity.guardian.invited.v1',
channels: ['smtp', 'in-app']
})
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: this.i18n.t('consent.body', { lng: locale, child: event.childHandle })
},
'in-app': { body: this.i18n.t('consent.short', { lng: locale }) }
}
}
}
Declare a class as a notice: something a person receives.
The decorator says what it is; the class says what it says. There is no
contentoption, and that is deliberate: a decorator carrying message bodies would put text in the one place it cannot be translated, formatted, or computed from the event. The class answersnotify(event, context), and it is built through the container, so it can ask for i18n, a repository, a URL signer.With
on, nobody calls the notifier. A module emits what happened, and the notice that named that event decides who learns about it. The emitting module imports nothing and is never reopened when a channel is added, which is the whole reason this exists rather than a service call.