Coverage for src/lexigram/notification/hooks.py: 100%
29 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-26 02:26 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-26 02:26 +0800
1"""Root hook payload surface for lexigram-notification.
3Defines canonical payload dataclasses for notification delivery hook points.
4Actual hook registration and invocation use the framework's string-keyed
5``HookRegistryProtocol`` action/filter APIs.
6"""
8from __future__ import annotations
10from dataclasses import dataclass
12__all__ = [
13 "EmailDispatchedHook",
14 "EmailRenderedHook",
15 "InboxMessageCreatedHook",
16 "InboxMessageReadHook",
17 "NotificationFailedHook",
18 "NotificationSentHook",
19]
22# === Existing Notification Hooks ===
25@dataclass(frozen=True, kw_only=True)
26class NotificationSentHook:
27 """Payload fired when a notification is successfully dispatched.
29 Attributes:
30 channel: Delivery channel used (e.g. ``"email"``, ``"sms"``, ``"push"``).
31 recipient_id: Identifier of the notification recipient.
32 """
34 channel: str
35 recipient_id: str
38@dataclass(frozen=True, kw_only=True)
39class NotificationFailedHook:
40 """Payload fired when a notification dispatch attempt fails.
42 Attributes:
43 channel: Delivery channel that failed.
44 recipient_id: Identifier of the intended recipient.
45 reason: Short description of the failure.
46 """
48 channel: str
49 recipient_id: str
50 reason: str
53# === Mail Hooks (merged from mail/hooks.py) ===
56@dataclass(frozen=True)
57class EmailDispatchedHook:
58 """Payload fired when an email is dispatched to the sending provider.
60 Attributes:
61 recipient: Email address of the recipient.
62 message_id: Provider-assigned message identifier.
63 backend: Name of the sending backend (e.g., "sendgrid", "ses").
64 """
66 recipient: str
67 message_id: str
68 backend: str
71@dataclass(frozen=True)
72class EmailRenderedHook:
73 """Payload fired when an email template is rendered.
75 Attributes:
76 template_name: Name of the template used.
77 recipient: Target recipient email address.
78 """
80 template_name: str
81 recipient: str
84# === Inbox Hooks (merged from inbox/hooks.py) ===
87@dataclass(frozen=True)
88class InboxMessageCreatedHook:
89 """Payload fired when a new message is added to a user's inbox.
91 Attributes:
92 message_id: Unique identifier of the inbox message.
93 user_id: Identifier of the recipient user.
94 """
96 message_id: str
97 user_id: str
100@dataclass(frozen=True)
101class InboxMessageReadHook:
102 """Payload fired when a user opens an inbox message.
104 Attributes:
105 message_id: Unique identifier of the inbox message.
106 user_id: Identifier of the user who read the message.
107 """
109 message_id: str
110 user_id: str