strapi-plugin-timeline 0.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patiparnne Vongchompue
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # Strapi Plugin Timeline
2
+
3
+ A content history and version control plugin for **Strapi 5**. Automatically tracks changes to your content entries and lets you browse, compare, and restore previous versions — all from within the Strapi admin panel.
4
+
5
+ ## Features
6
+
7
+ - **Automatic Change Tracking** — Records snapshots on create, update, delete, and publish actions via lifecycle hooks. No manual work required.
8
+ - **Per-Content-Type Configuration** — Choose which content types to track, which actions to log, and set retention limits independently for each.
9
+ - **Full Snapshot Storage** — Each timeline entry stores the complete content payload and the content type schema at that point in time.
10
+ - **Restore with Diff Preview** — Before restoring, see a side-by-side comparison of what will change. One-click restore reverts the entry and logs a "restore" action.
11
+ - **Homepage Dashboard** — Filterable, sortable, paginated table of all timeline entries across content types, users, locales, actions, and date ranges.
12
+ - **CM Edit View Panel** — A sidebar panel in the content manager showing the history of the document you're editing, grouped by date.
13
+ - **Locale Aware** — Tracks i18n locale per entry. Filter by locale. Restores respect locale context.
14
+ - **Scheduled Cleanup** — Configure a cron job to automatically remove entries older than a retention duration (hours, days, weeks, or months).
15
+ - **Entries Limit** — Set a maximum number of entries per content type. Oldest entries are automatically pruned (FIFO).
16
+ - **Role-Based Permissions** — Separate permissions for read, edit, delete, and schedule actions via Strapi's RBAC system.
17
+ - **User Attribution** — Captures the admin user who performed each action, with links to user profiles.
18
+ - **Schema Migration** — Automatically migrates from legacy configuration format.
19
+
20
+ ## Requirements
21
+
22
+ - Strapi **v5.x**
23
+ - Node.js **18+**
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install strapi-plugin-timeline
29
+ ```
30
+
31
+ Or with yarn:
32
+
33
+ ```bash
34
+ yarn add strapi-plugin-timeline
35
+ ```
36
+
37
+ ### Enable the Plugin
38
+
39
+ Add it to your Strapi plugin configuration:
40
+
41
+ ```typescript
42
+ // config/plugins.ts
43
+ export default () => ({
44
+ timeline: {
45
+ enabled: true,
46
+ },
47
+ });
48
+ ```
49
+
50
+ Then rebuild and restart your Strapi application.
51
+
52
+ ## Configuration
53
+
54
+ All configuration is done through the **Strapi Admin Panel** — no code changes needed.
55
+
56
+ ### Settings Page
57
+
58
+ Navigate to **Settings → Timeline** in the admin panel to:
59
+
60
+ 1. **Add content types** to track from a dropdown of all available API content types.
61
+ 2. **Configure each content type** independently:
62
+ - **Enable/Disable** — Toggle tracking on or off.
63
+ - **Tracked Actions** — Select which actions to log: `create`, `update`, `delete`, `publish`. Leave empty to track all.
64
+ - **Entries Limit** — Maximum entries to keep (0 = unlimited). When exceeded, oldest entries are removed automatically.
65
+ - **Retention Duration** — How long to keep entries before scheduled cleanup removes them. Set the value and unit (hours, days, weeks, months).
66
+ 3. **Remove content types** — Stop tracking and optionally clean up existing entries.
67
+
68
+ ### Scheduled Cleanup
69
+
70
+ Navigate to **Settings → Timeline → Schedule** to:
71
+
72
+ - **Enable/Disable** automatic cleanup.
73
+ - **Set the cron expression** (default: `0 * * * *` — every hour).
74
+ - **Run cleanup manually** with the "Run Now" button.
75
+ - **View last cleanup results** including per-content-type deletion counts.
76
+
77
+ > **Note:** Changes to the cron schedule require a server restart to take effect.
78
+
79
+ ## Usage
80
+
81
+ ### Homepage
82
+
83
+ The Timeline homepage (`/plugins/timeline`) shows a paginated table of all tracked changes. You can:
84
+
85
+ - **Filter** by content type, user, action, locale, date range, or document ID.
86
+ - **Sort** by action, content type, user, or date.
87
+ - **View** — Click the eye icon to open a detail modal showing the full snapshot with formatted content (rich text, blocks, relations, media).
88
+ - **Restore** — Click the restore icon to open a diff preview, then confirm to revert the entry to that snapshot.
89
+ - **Clean** — Bulk delete timeline entries by content type.
90
+
91
+ ### Content Manager Panel
92
+
93
+ When editing any tracked content entry, a **Timeline** panel appears in the sidebar showing:
94
+
95
+ - Recent changes to this specific document, grouped by date.
96
+ - A date picker to browse changes on a specific day.
97
+ - Quick view and restore buttons for each entry.
98
+
99
+ ### Restore
100
+
101
+ When you restore a snapshot:
102
+
103
+ 1. A **diff table** shows which fields will change, comparing current values against the snapshot.
104
+ 2. The plugin performs the restore server-side in a single operation.
105
+ 3. A "restore" action is logged in the timeline.
106
+ 4. The entries limit is enforced after the restore.
107
+ 5. The lifecycle `afterUpdate` hook is suppressed during restore to avoid a duplicate "update" entry.
108
+
109
+ ## Tracked Actions
110
+
111
+ | Action | Description |
112
+ |--------|-------------|
113
+ | `create` | A new entry was created |
114
+ | `update` | An existing draft/entry was modified |
115
+ | `publish` | Content was published |
116
+ | `delete` | An entry was deleted |
117
+ | `restore` | An entry was reverted to a previous snapshot |
118
+ | `clean` | Timeline entries were manually bulk-deleted |
119
+
120
+ ## Permissions
121
+
122
+ The plugin registers its own permissions under **Settings → Roles**:
123
+
124
+ | Permission | Description |
125
+ |------------|-------------|
126
+ | `plugin::timeline.read` | View timeline entries and history |
127
+ | `plugin::timeline.edit` | Restore entries and modify settings |
128
+ | `plugin::timeline.delete` | Delete / clean timeline entries |
129
+ | `plugin::timeline.schedule.run` | Execute scheduled cleanup |
130
+
131
+ ## API Endpoints
132
+
133
+ All endpoints are admin-only and require authentication.
134
+
135
+ | Method | Endpoint | Description |
136
+ |--------|----------|-------------|
137
+ | `GET` | `/timeline/settings` | Get plugin settings |
138
+ | `PUT` | `/timeline/settings` | Update plugin settings |
139
+ | `GET` | `/timeline/content-types` | List available content types |
140
+ | `GET` | `/timeline/entries` | Query timeline entries (with filters, pagination, sorting) |
141
+ | `GET` | `/timeline/entries/users` | Get distinct users |
142
+ | `GET` | `/timeline/entries/locales` | Get distinct locales |
143
+ | `GET` | `/timeline/entries/:contentType/:entryDocumentId` | Get history for a specific document |
144
+ | `POST` | `/timeline/entries/snapshot-before-restore` | Restore an entry to a previous snapshot |
145
+ | `POST` | `/timeline/entries/clean` | Delete entries for selected content types |
146
+ | `DELETE` | `/timeline/entries` | Delete all timeline entries |
147
+ | `GET` | `/timeline/schedule` | Get cleanup schedule status |
148
+ | `PUT` | `/timeline/schedule` | Update cleanup schedule |
149
+ | `POST` | `/timeline/schedule/run` | Run cleanup now |
150
+
151
+ ## How It Works
152
+
153
+ The plugin subscribes to Strapi's database lifecycle events (`afterCreate`, `afterUpdate`, `beforeDelete`) at the global level. On each event:
154
+
155
+ 1. Checks if the content type is tracked and the action is enabled in settings.
156
+ 2. Extracts the admin user from the request context.
157
+ 3. Resolves relation fields to document IDs.
158
+ 4. Captures the content type schema (attributes, types, relations).
159
+ 5. Stores the full snapshot as a JSON timeline entry.
160
+ 6. Enforces the entries limit by removing the oldest entries if exceeded.
161
+
162
+ Snapshots are stored in the plugin's own `timeline-entry` collection type, hidden from the content manager.
163
+
164
+ ## License
165
+
166
+ [MIT](LICENSE) — Patiparnne Vongchompue
167
+
168
+ ## Support
169
+
170
+ If you find this plugin useful, consider supporting the development:
171
+
172
+ - [Buy Me a Coffee](https://buymeacoffee.com/patiparnne)
173
+ - [Patreon](https://www.patreon.com/patiparnne)