fastpluggy-notification-center 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastpluggy_notification_center-0.2.0/PKG-INFO +123 -0
- fastpluggy_notification_center-0.2.0/README.md +108 -0
- fastpluggy_notification_center-0.2.0/fastpluggy_notification_center.egg-info/PKG-INFO +123 -0
- fastpluggy_notification_center-0.2.0/fastpluggy_notification_center.egg-info/SOURCES.txt +32 -0
- fastpluggy_notification_center-0.2.0/fastpluggy_notification_center.egg-info/dependency_links.txt +1 -0
- fastpluggy_notification_center-0.2.0/fastpluggy_notification_center.egg-info/entry_points.txt +2 -0
- fastpluggy_notification_center-0.2.0/fastpluggy_notification_center.egg-info/requires.txt +11 -0
- fastpluggy_notification_center-0.2.0/fastpluggy_notification_center.egg-info/top_level.txt +1 -0
- fastpluggy_notification_center-0.2.0/pyproject.toml +42 -0
- fastpluggy_notification_center-0.2.0/setup.cfg +4 -0
- fastpluggy_notification_center-0.2.0/src/__init__.py +0 -0
- fastpluggy_notification_center-0.2.0/src/channels.py +67 -0
- fastpluggy_notification_center-0.2.0/src/config.py +17 -0
- fastpluggy_notification_center-0.2.0/src/hooks.py +20 -0
- fastpluggy_notification_center-0.2.0/src/models.py +54 -0
- fastpluggy_notification_center-0.2.0/src/plugin.py +131 -0
- fastpluggy_notification_center-0.2.0/src/push_service.py +75 -0
- fastpluggy_notification_center-0.2.0/src/repository.py +84 -0
- fastpluggy_notification_center-0.2.0/src/routers/__init__.py +10 -0
- fastpluggy_notification_center-0.2.0/src/routers/api.py +122 -0
- fastpluggy_notification_center-0.2.0/src/routers/front.py +48 -0
- fastpluggy_notification_center-0.2.0/src/routers/push_api.py +92 -0
- fastpluggy_notification_center-0.2.0/src/static/css/notifications.css +71 -0
- fastpluggy_notification_center-0.2.0/src/static/js/notifications.js +178 -0
- fastpluggy_notification_center-0.2.0/src/static/js/push-subscribe.js +168 -0
- fastpluggy_notification_center-0.2.0/src/static/js/sw-handlers.js +53 -0
- fastpluggy_notification_center-0.2.0/src/templates/full_page.html.j2 +140 -0
- fastpluggy_notification_center-0.2.0/src/templates/panel_item.html.j2 +25 -0
- fastpluggy_notification_center-0.2.0/src/vapid_keys.py +34 -0
- fastpluggy_notification_center-0.2.0/tests/test_api.py +236 -0
- fastpluggy_notification_center-0.2.0/tests/test_channels.py +229 -0
- fastpluggy_notification_center-0.2.0/tests/test_push_api.py +189 -0
- fastpluggy_notification_center-0.2.0/tests/test_push_service.py +240 -0
- fastpluggy_notification_center-0.2.0/tests/test_repository.py +159 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastpluggy-notification-center
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Persistent notification center with topbar bell, event bus integration, and optional Web Push
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: FastPluggy>=0.4.0
|
|
8
|
+
Provides-Extra: push
|
|
9
|
+
Requires-Dist: pywebpush>=2.0.0; extra == "push"
|
|
10
|
+
Provides-Extra: tests
|
|
11
|
+
Requires-Dist: pytest>=7.0; extra == "tests"
|
|
12
|
+
Requires-Dist: pytest-cov>=4.0; extra == "tests"
|
|
13
|
+
Provides-Extra: e2e
|
|
14
|
+
Requires-Dist: fastpluggy-cli; extra == "e2e"
|
|
15
|
+
|
|
16
|
+
# fastpluggy-notification-center
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/releases)
|
|
20
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/pipelines?ignore_skipped=true)
|
|
21
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/pipelines)
|
|
22
|
+
|
|
23
|
+
Persistent notification center for FastPluggy with topbar bell icon, event bus integration, pluggable delivery channels, and optional Web Push support.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install fastpluggy-notification-center
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For Web Push support:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install fastpluggy-notification-center[push]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- **Topbar bell icon** — unread badge count, slide-out notification panel
|
|
40
|
+
- **Event bus integration** — listens to all `notification.*` events automatically
|
|
41
|
+
- **Pluggable channels** — any plugin can register as a delivery channel via the `NotificationChannel` protocol
|
|
42
|
+
- **Channel relay** — forward notifications to external channels (ntfy, email, etc.) based on category
|
|
43
|
+
- **Web Push** — browser push notifications via VAPID (auto-generates keys on first load)
|
|
44
|
+
- **Notification categories** — `info`, `success`, `warning`, `error` with colored badges
|
|
45
|
+
- **Read/unread tracking** — mark individual or bulk mark-as-read
|
|
46
|
+
- **Auto-cleanup** — configurable retention period (default 30 days)
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
Settings are managed via `NotificationCenterSettings` (database-backed). Configure through the FastPluggy settings UI.
|
|
51
|
+
|
|
52
|
+
| Setting | Default | Description |
|
|
53
|
+
|---------|---------|-------------|
|
|
54
|
+
| `notification_retention_days` | `30` | Days to keep notifications before cleanup |
|
|
55
|
+
| `max_notifications_per_page` | `50` | Pagination size for notification list |
|
|
56
|
+
| `relay_enabled` | `false` | Enable forwarding to delivery channels |
|
|
57
|
+
| `relay_channels` | `[]` | Channel names to relay to (empty = all discovered) |
|
|
58
|
+
| `relay_categories` | `["error"]` | Only relay notifications with these categories |
|
|
59
|
+
| `web_push_enabled` | `true` | Enable browser Web Push support |
|
|
60
|
+
| `vapid_private_key` | `""` | VAPID private key (auto-generated if empty) |
|
|
61
|
+
| `vapid_public_key` | `""` | VAPID public key (auto-generated if empty) |
|
|
62
|
+
| `vapid_contact_email` | `""` | Contact email for VAPID identification |
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
### Sending notifications via event bus
|
|
67
|
+
|
|
68
|
+
Any plugin can emit a notification event:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
fast_pluggy.events.emit("notification.info", payload={
|
|
72
|
+
"title": "Task completed",
|
|
73
|
+
"message": "Backup finished successfully",
|
|
74
|
+
"category": "success",
|
|
75
|
+
"data": {"task_id": 42},
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Sending browser push notifications
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
fast_pluggy.events.emit("notification.push", payload={
|
|
83
|
+
"title": "Deployment ready",
|
|
84
|
+
"message": "v1.2.0 is live",
|
|
85
|
+
"url": "/plugin/ecosystem_status/",
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Explicit relay to all channels
|
|
90
|
+
|
|
91
|
+
Bypasses the category filter:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
fast_pluggy.events.emit("notification.relay", payload={
|
|
95
|
+
"title": "Critical alert",
|
|
96
|
+
"message": "Database connection lost",
|
|
97
|
+
"category": "error",
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Registering a delivery channel
|
|
102
|
+
|
|
103
|
+
Any plugin can act as a delivery channel by implementing the `NotificationChannel` protocol:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from fastpluggy_plugin.notification_center.channels import NotificationChannel
|
|
107
|
+
|
|
108
|
+
class MyChannel:
|
|
109
|
+
channel_name = "my_channel"
|
|
110
|
+
|
|
111
|
+
def send(self, title, message, category, data=None):
|
|
112
|
+
# deliver the notification
|
|
113
|
+
...
|
|
114
|
+
|
|
115
|
+
class MyPlugin(FastPluggyBaseModule):
|
|
116
|
+
notification_channel = MyChannel()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The notification center discovers channels automatically at startup.
|
|
120
|
+
|
|
121
|
+
## Dashboard
|
|
122
|
+
|
|
123
|
+
The notification panel is accessible via the topbar bell icon on every page. A full notification history page is available at `/plugin/notification_center/` (CI) or `/plugin-pkg/notification_center/` (local dev).
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# fastpluggy-notification-center
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/releases)
|
|
5
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/pipelines?ignore_skipped=true)
|
|
6
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/pipelines)
|
|
7
|
+
|
|
8
|
+
Persistent notification center for FastPluggy with topbar bell icon, event bus integration, pluggable delivery channels, and optional Web Push support.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install fastpluggy-notification-center
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
For Web Push support:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install fastpluggy-notification-center[push]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- **Topbar bell icon** — unread badge count, slide-out notification panel
|
|
25
|
+
- **Event bus integration** — listens to all `notification.*` events automatically
|
|
26
|
+
- **Pluggable channels** — any plugin can register as a delivery channel via the `NotificationChannel` protocol
|
|
27
|
+
- **Channel relay** — forward notifications to external channels (ntfy, email, etc.) based on category
|
|
28
|
+
- **Web Push** — browser push notifications via VAPID (auto-generates keys on first load)
|
|
29
|
+
- **Notification categories** — `info`, `success`, `warning`, `error` with colored badges
|
|
30
|
+
- **Read/unread tracking** — mark individual or bulk mark-as-read
|
|
31
|
+
- **Auto-cleanup** — configurable retention period (default 30 days)
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
Settings are managed via `NotificationCenterSettings` (database-backed). Configure through the FastPluggy settings UI.
|
|
36
|
+
|
|
37
|
+
| Setting | Default | Description |
|
|
38
|
+
|---------|---------|-------------|
|
|
39
|
+
| `notification_retention_days` | `30` | Days to keep notifications before cleanup |
|
|
40
|
+
| `max_notifications_per_page` | `50` | Pagination size for notification list |
|
|
41
|
+
| `relay_enabled` | `false` | Enable forwarding to delivery channels |
|
|
42
|
+
| `relay_channels` | `[]` | Channel names to relay to (empty = all discovered) |
|
|
43
|
+
| `relay_categories` | `["error"]` | Only relay notifications with these categories |
|
|
44
|
+
| `web_push_enabled` | `true` | Enable browser Web Push support |
|
|
45
|
+
| `vapid_private_key` | `""` | VAPID private key (auto-generated if empty) |
|
|
46
|
+
| `vapid_public_key` | `""` | VAPID public key (auto-generated if empty) |
|
|
47
|
+
| `vapid_contact_email` | `""` | Contact email for VAPID identification |
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
### Sending notifications via event bus
|
|
52
|
+
|
|
53
|
+
Any plugin can emit a notification event:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
fast_pluggy.events.emit("notification.info", payload={
|
|
57
|
+
"title": "Task completed",
|
|
58
|
+
"message": "Backup finished successfully",
|
|
59
|
+
"category": "success",
|
|
60
|
+
"data": {"task_id": 42},
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Sending browser push notifications
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
fast_pluggy.events.emit("notification.push", payload={
|
|
68
|
+
"title": "Deployment ready",
|
|
69
|
+
"message": "v1.2.0 is live",
|
|
70
|
+
"url": "/plugin/ecosystem_status/",
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Explicit relay to all channels
|
|
75
|
+
|
|
76
|
+
Bypasses the category filter:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
fast_pluggy.events.emit("notification.relay", payload={
|
|
80
|
+
"title": "Critical alert",
|
|
81
|
+
"message": "Database connection lost",
|
|
82
|
+
"category": "error",
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Registering a delivery channel
|
|
87
|
+
|
|
88
|
+
Any plugin can act as a delivery channel by implementing the `NotificationChannel` protocol:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from fastpluggy_plugin.notification_center.channels import NotificationChannel
|
|
92
|
+
|
|
93
|
+
class MyChannel:
|
|
94
|
+
channel_name = "my_channel"
|
|
95
|
+
|
|
96
|
+
def send(self, title, message, category, data=None):
|
|
97
|
+
# deliver the notification
|
|
98
|
+
...
|
|
99
|
+
|
|
100
|
+
class MyPlugin(FastPluggyBaseModule):
|
|
101
|
+
notification_channel = MyChannel()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The notification center discovers channels automatically at startup.
|
|
105
|
+
|
|
106
|
+
## Dashboard
|
|
107
|
+
|
|
108
|
+
The notification panel is accessible via the topbar bell icon on every page. A full notification history page is available at `/plugin/notification_center/` (CI) or `/plugin-pkg/notification_center/` (local dev).
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastpluggy-notification-center
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Persistent notification center with topbar bell, event bus integration, and optional Web Push
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: FastPluggy>=0.4.0
|
|
8
|
+
Provides-Extra: push
|
|
9
|
+
Requires-Dist: pywebpush>=2.0.0; extra == "push"
|
|
10
|
+
Provides-Extra: tests
|
|
11
|
+
Requires-Dist: pytest>=7.0; extra == "tests"
|
|
12
|
+
Requires-Dist: pytest-cov>=4.0; extra == "tests"
|
|
13
|
+
Provides-Extra: e2e
|
|
14
|
+
Requires-Dist: fastpluggy-cli; extra == "e2e"
|
|
15
|
+
|
|
16
|
+
# fastpluggy-notification-center
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/releases)
|
|
20
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/pipelines?ignore_skipped=true)
|
|
21
|
+
[](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/notification_center/-/pipelines)
|
|
22
|
+
|
|
23
|
+
Persistent notification center for FastPluggy with topbar bell icon, event bus integration, pluggable delivery channels, and optional Web Push support.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install fastpluggy-notification-center
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For Web Push support:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install fastpluggy-notification-center[push]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- **Topbar bell icon** — unread badge count, slide-out notification panel
|
|
40
|
+
- **Event bus integration** — listens to all `notification.*` events automatically
|
|
41
|
+
- **Pluggable channels** — any plugin can register as a delivery channel via the `NotificationChannel` protocol
|
|
42
|
+
- **Channel relay** — forward notifications to external channels (ntfy, email, etc.) based on category
|
|
43
|
+
- **Web Push** — browser push notifications via VAPID (auto-generates keys on first load)
|
|
44
|
+
- **Notification categories** — `info`, `success`, `warning`, `error` with colored badges
|
|
45
|
+
- **Read/unread tracking** — mark individual or bulk mark-as-read
|
|
46
|
+
- **Auto-cleanup** — configurable retention period (default 30 days)
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
Settings are managed via `NotificationCenterSettings` (database-backed). Configure through the FastPluggy settings UI.
|
|
51
|
+
|
|
52
|
+
| Setting | Default | Description |
|
|
53
|
+
|---------|---------|-------------|
|
|
54
|
+
| `notification_retention_days` | `30` | Days to keep notifications before cleanup |
|
|
55
|
+
| `max_notifications_per_page` | `50` | Pagination size for notification list |
|
|
56
|
+
| `relay_enabled` | `false` | Enable forwarding to delivery channels |
|
|
57
|
+
| `relay_channels` | `[]` | Channel names to relay to (empty = all discovered) |
|
|
58
|
+
| `relay_categories` | `["error"]` | Only relay notifications with these categories |
|
|
59
|
+
| `web_push_enabled` | `true` | Enable browser Web Push support |
|
|
60
|
+
| `vapid_private_key` | `""` | VAPID private key (auto-generated if empty) |
|
|
61
|
+
| `vapid_public_key` | `""` | VAPID public key (auto-generated if empty) |
|
|
62
|
+
| `vapid_contact_email` | `""` | Contact email for VAPID identification |
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
### Sending notifications via event bus
|
|
67
|
+
|
|
68
|
+
Any plugin can emit a notification event:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
fast_pluggy.events.emit("notification.info", payload={
|
|
72
|
+
"title": "Task completed",
|
|
73
|
+
"message": "Backup finished successfully",
|
|
74
|
+
"category": "success",
|
|
75
|
+
"data": {"task_id": 42},
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Sending browser push notifications
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
fast_pluggy.events.emit("notification.push", payload={
|
|
83
|
+
"title": "Deployment ready",
|
|
84
|
+
"message": "v1.2.0 is live",
|
|
85
|
+
"url": "/plugin/ecosystem_status/",
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Explicit relay to all channels
|
|
90
|
+
|
|
91
|
+
Bypasses the category filter:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
fast_pluggy.events.emit("notification.relay", payload={
|
|
95
|
+
"title": "Critical alert",
|
|
96
|
+
"message": "Database connection lost",
|
|
97
|
+
"category": "error",
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Registering a delivery channel
|
|
102
|
+
|
|
103
|
+
Any plugin can act as a delivery channel by implementing the `NotificationChannel` protocol:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from fastpluggy_plugin.notification_center.channels import NotificationChannel
|
|
107
|
+
|
|
108
|
+
class MyChannel:
|
|
109
|
+
channel_name = "my_channel"
|
|
110
|
+
|
|
111
|
+
def send(self, title, message, category, data=None):
|
|
112
|
+
# deliver the notification
|
|
113
|
+
...
|
|
114
|
+
|
|
115
|
+
class MyPlugin(FastPluggyBaseModule):
|
|
116
|
+
notification_channel = MyChannel()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The notification center discovers channels automatically at startup.
|
|
120
|
+
|
|
121
|
+
## Dashboard
|
|
122
|
+
|
|
123
|
+
The notification panel is accessible via the topbar bell icon on every page. A full notification history page is available at `/plugin/notification_center/` (CI) or `/plugin-pkg/notification_center/` (local dev).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
fastpluggy_notification_center.egg-info/PKG-INFO
|
|
4
|
+
fastpluggy_notification_center.egg-info/SOURCES.txt
|
|
5
|
+
fastpluggy_notification_center.egg-info/dependency_links.txt
|
|
6
|
+
fastpluggy_notification_center.egg-info/entry_points.txt
|
|
7
|
+
fastpluggy_notification_center.egg-info/requires.txt
|
|
8
|
+
fastpluggy_notification_center.egg-info/top_level.txt
|
|
9
|
+
src/__init__.py
|
|
10
|
+
src/channels.py
|
|
11
|
+
src/config.py
|
|
12
|
+
src/hooks.py
|
|
13
|
+
src/models.py
|
|
14
|
+
src/plugin.py
|
|
15
|
+
src/push_service.py
|
|
16
|
+
src/repository.py
|
|
17
|
+
src/vapid_keys.py
|
|
18
|
+
src/routers/__init__.py
|
|
19
|
+
src/routers/api.py
|
|
20
|
+
src/routers/front.py
|
|
21
|
+
src/routers/push_api.py
|
|
22
|
+
src/static/css/notifications.css
|
|
23
|
+
src/static/js/notifications.js
|
|
24
|
+
src/static/js/push-subscribe.js
|
|
25
|
+
src/static/js/sw-handlers.js
|
|
26
|
+
src/templates/full_page.html.j2
|
|
27
|
+
src/templates/panel_item.html.j2
|
|
28
|
+
tests/test_api.py
|
|
29
|
+
tests/test_channels.py
|
|
30
|
+
tests/test_push_api.py
|
|
31
|
+
tests/test_push_service.py
|
|
32
|
+
tests/test_repository.py
|
fastpluggy_notification_center-0.2.0/fastpluggy_notification_center.egg-info/dependency_links.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fastpluggy_plugin
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fastpluggy-notification-center"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Persistent notification center with topbar bell, event bus integration, and optional Web Push"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"FastPluggy>=0.4.0",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.optional-dependencies]
|
|
16
|
+
push = [
|
|
17
|
+
"pywebpush>=2.0.0",
|
|
18
|
+
]
|
|
19
|
+
tests = [
|
|
20
|
+
"pytest>=7.0",
|
|
21
|
+
"pytest-cov>=4.0",
|
|
22
|
+
]
|
|
23
|
+
e2e = ["fastpluggy-cli"]
|
|
24
|
+
|
|
25
|
+
[tool.setuptools]
|
|
26
|
+
packages = ["fastpluggy_plugin.notification_center"]
|
|
27
|
+
package-dir = { "fastpluggy_plugin.notification_center" = "src" }
|
|
28
|
+
include-package-data = true
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.package-data]
|
|
31
|
+
"fastpluggy_plugin.notification_center" = ["**/*", "templates/**/*.html", "templates/**/*.j2", "static/**/*"]
|
|
32
|
+
|
|
33
|
+
[project.entry-points."fastpluggy.plugins"]
|
|
34
|
+
notification_center = "fastpluggy_plugin.notification_center.plugin:NotificationCenterPlugin"
|
|
35
|
+
|
|
36
|
+
[tool.pytest.ini_options]
|
|
37
|
+
testpaths = ["tests"]
|
|
38
|
+
pythonpath = ["tests"]
|
|
39
|
+
|
|
40
|
+
[tool.fastpluggy]
|
|
41
|
+
category = ['system', 'ui']
|
|
42
|
+
keywords = ['notifications', 'bell', 'event bus', 'push']
|
|
File without changes
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Pluggable notification delivery channels."""
|
|
2
|
+
from typing import Protocol, runtime_checkable
|
|
3
|
+
|
|
4
|
+
from loguru import logger
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@runtime_checkable
|
|
8
|
+
class NotificationChannel(Protocol):
|
|
9
|
+
"""Protocol for notification delivery channels.
|
|
10
|
+
|
|
11
|
+
Any plugin can register as a channel by adding a `notification_channel`
|
|
12
|
+
attribute to its plugin class that implements this protocol.
|
|
13
|
+
"""
|
|
14
|
+
channel_name: str
|
|
15
|
+
|
|
16
|
+
def send(self, title: str, message: str, category: str, data: dict | None = None) -> None: ...
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Registry of discovered channels
|
|
20
|
+
_channels: dict[str, NotificationChannel] = {}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def discover_channels(fast_pluggy) -> None:
|
|
24
|
+
"""Discover notification channels from all loaded plugins."""
|
|
25
|
+
_channels.clear()
|
|
26
|
+
for name, plugin_state in fast_pluggy.module_manager.modules.items():
|
|
27
|
+
plugin = plugin_state.plugin
|
|
28
|
+
channel = getattr(plugin, 'notification_channel', None)
|
|
29
|
+
if channel is not None and isinstance(channel, NotificationChannel):
|
|
30
|
+
_channels[channel.channel_name] = channel
|
|
31
|
+
logger.info(f"notification_center: discovered channel '{channel.channel_name}' from {name}")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_channels() -> dict[str, NotificationChannel]:
|
|
35
|
+
"""Return all discovered channels."""
|
|
36
|
+
return dict(_channels)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def relay_to_channels(title: str, message: str, category: str, data: dict | None = None,
|
|
40
|
+
channels: list[str] | None = None) -> dict:
|
|
41
|
+
"""Send a notification to matching channels.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
channels: If provided, only send to these channel names. None = all.
|
|
45
|
+
Returns:
|
|
46
|
+
{"sent": [...channel_names], "failed": [...]}
|
|
47
|
+
"""
|
|
48
|
+
from .config import NotificationCenterSettings
|
|
49
|
+
settings = NotificationCenterSettings()
|
|
50
|
+
|
|
51
|
+
target_channels = _channels
|
|
52
|
+
if channels:
|
|
53
|
+
target_channels = {k: v for k, v in _channels.items() if k in channels}
|
|
54
|
+
elif settings.relay_channels:
|
|
55
|
+
target_channels = {k: v for k, v in _channels.items() if k in settings.relay_channels}
|
|
56
|
+
|
|
57
|
+
sent = []
|
|
58
|
+
failed = []
|
|
59
|
+
for name, channel in target_channels.items():
|
|
60
|
+
try:
|
|
61
|
+
channel.send(title=title, message=message, category=category, data=data)
|
|
62
|
+
sent.append(name)
|
|
63
|
+
except Exception as e:
|
|
64
|
+
failed.append(name)
|
|
65
|
+
logger.error(f"notification_center: channel '{name}' relay failed: {e}")
|
|
66
|
+
|
|
67
|
+
return {"sent": sent, "failed": failed}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from fastpluggy.core.config import BaseDatabaseSettings
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class NotificationCenterSettings(BaseDatabaseSettings):
|
|
5
|
+
notification_retention_days: int = 30
|
|
6
|
+
max_notifications_per_page: int = 50
|
|
7
|
+
|
|
8
|
+
# Channel relay settings
|
|
9
|
+
relay_enabled: bool = False
|
|
10
|
+
relay_channels: list = [] # empty = all discovered channels
|
|
11
|
+
relay_categories: list = ["error"] # only relay these categories by default
|
|
12
|
+
|
|
13
|
+
# VAPID Web Push settings
|
|
14
|
+
vapid_private_key: str = ""
|
|
15
|
+
vapid_public_key: str = ""
|
|
16
|
+
vapid_contact_email: str = ""
|
|
17
|
+
web_push_enabled: bool = True
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""db_purge integration — register notification cleanup target."""
|
|
2
|
+
|
|
3
|
+
from .models import Notification
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def register_purge_targets() -> None:
|
|
7
|
+
"""Register notification_center tables as purgeable.
|
|
8
|
+
|
|
9
|
+
Notification center — remove notifications older than 30 days.
|
|
10
|
+
"""
|
|
11
|
+
try:
|
|
12
|
+
from fastpluggy_plugin.db_purge.hooks import register_purge_target
|
|
13
|
+
except ImportError:
|
|
14
|
+
return
|
|
15
|
+
|
|
16
|
+
register_purge_target(
|
|
17
|
+
Notification.__tablename__,
|
|
18
|
+
"created_at",
|
|
19
|
+
default_retention_days=30,
|
|
20
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from fastpluggy.core.database import Base
|
|
2
|
+
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, JSON, Index, func
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Notification(Base):
|
|
6
|
+
__tablename__ = "notification_center_notifications"
|
|
7
|
+
__table_args__ = (
|
|
8
|
+
Index("ix_notification_created_at", "created_at"),
|
|
9
|
+
Index("ix_notification_read", "read"),
|
|
10
|
+
Index("ix_notification_source", "source"),
|
|
11
|
+
Index("ix_notification_category", "category"),
|
|
12
|
+
{"extend_existing": True},
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
16
|
+
title = Column(String(256), nullable=False)
|
|
17
|
+
message = Column(Text, nullable=False)
|
|
18
|
+
category = Column(String(32), nullable=False, default="info")
|
|
19
|
+
source = Column(String(128), nullable=True)
|
|
20
|
+
read = Column(Boolean, nullable=False, default=False)
|
|
21
|
+
read_at = Column(DateTime, nullable=True)
|
|
22
|
+
created_at = Column(DateTime, nullable=False, server_default=func.now())
|
|
23
|
+
updated_at = Column(DateTime, nullable=True, server_default=func.now(), onupdate=func.now())
|
|
24
|
+
data = Column(JSON, nullable=True)
|
|
25
|
+
|
|
26
|
+
def __repr__(self) -> str:
|
|
27
|
+
return (
|
|
28
|
+
f"<Notification(id={self.id}, title={self.title!r}, "
|
|
29
|
+
f"category={self.category!r}, source={self.source!r}, read={self.read})>"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class PushSubscription(Base):
|
|
34
|
+
__tablename__ = "notification_center_push_subscriptions"
|
|
35
|
+
__table_args__ = (
|
|
36
|
+
Index("ix_push_sub_endpoint", "endpoint"),
|
|
37
|
+
Index("ix_push_sub_failed_count", "failed_count"),
|
|
38
|
+
{"extend_existing": True},
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
42
|
+
endpoint = Column(String(2048), unique=True, nullable=False)
|
|
43
|
+
p256dh_key = Column(String(256), nullable=False)
|
|
44
|
+
auth_key = Column(String(256), nullable=False)
|
|
45
|
+
user_agent = Column(String(512), nullable=True)
|
|
46
|
+
created_at = Column(DateTime, nullable=False, server_default=func.now())
|
|
47
|
+
last_used_at = Column(DateTime, nullable=True)
|
|
48
|
+
failed_count = Column(Integer, nullable=False, default=0)
|
|
49
|
+
|
|
50
|
+
def __repr__(self) -> str:
|
|
51
|
+
return (
|
|
52
|
+
f"<PushSubscription(id={self.id}, endpoint={self.endpoint[:60]!r}..., "
|
|
53
|
+
f"failed_count={self.failed_count})>"
|
|
54
|
+
)
|