npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thinhnd028/strapi-plugin-presence

v0.0.5

Published

Real-time presence for Strapi 5 Admin Panel

Downloads

539

Readme

Strapi 5 Presence Plugin

Plugin cho Strapi 5 cung cấp: Real-time presence (ai đang xem/sửa entry), Action History (audit log), và Version Snapshot & Restore (khôi phục phiên bản cũ).


Mục lục

  1. Tính năng
  2. Cài đặt
  3. [Cấu hình](#cấu hình)
  4. Cấu trúc plugin
  5. API Endpoints
  6. Version Snapshot & Restore
  7. Phát triển

Tính năng

Real-time Presence

  • Hiển thị avatars của user đang xem/sửa cùng entry trong Content Manager
  • Typing indicators
  • Socket.io, deduplication nhiều tab

Action History

  • Ghi nhận mỗi thao tác: create, update, publish, unpublish, delete, discardDraft
  • Hỗ trợ admin user và API user
  • Lưu before/after data cho audit

Version Snapshot & Restore

  • Tự động chụp snapshot khi create/update/publish/delete
  • Giao diện Recovery xem chi tiết và phục hồi phiên bản cũ
  • Đánh giá % khôi phục: fields, relations, media, dynamic zone blocks

Cài đặt

  1. Bật plugin trong config/plugins.ts:
presence: {
  enabled: true,
  resolve: './src/plugins/strapi-plugin-presence',
  config: {
    retentionDays: 90,
    minActionRecords: 500,
    maxVersionsPerDoc: 5,
    snapshotContentTypes: [
      'api::about-page.about-page',
      'api::department.department',
      // ... thêm content types cần snapshot
    ],
  },
},
  1. Build plugin (nếu chạy từ source):
cd src/plugins/strapi-plugin-presence
npm install
npm run build
  1. Build Strapi admin:
cd backend
npm run build
npm run dev

Cấu hình

| Tham số | Mặc định | Mô tả | |---------|----------|-------| | retentionDays | 90 | Số ngày giữ action history và versions trước khi xóa | | minActionRecords | 500 | Số action tối thiểu trước khi chạy cleanup | | maxVersionsPerDoc | 5 | Số version tối đa mỗi document (cũ nhất bị xóa trước) | | snapshotContentTypes | [] | UIDs của Single/Collection types cần lưu snapshot |

Quyền (RBAC)

Tính năng phục hồi (restore) yêu cầu quyền plugin::presence.restore. Cấp quyền tại Settings > Administration panel > Roles cho role cần sử dụng restore.

Biến môi trường

  • PRESENCE_RETENTION_DAYS
  • PRESENCE_MIN_ACTION_RECORDS
  • PRESENCE_MAX_VERSIONS_PER_DOC

Cấu trúc plugin

strapi-plugin-presence/
├── admin/
│   └── src/
│       ├── components/
│       │   ├── PresenceAvatars.tsx    # Avatar real-time
│       │   ├── PublishHistoryButton.tsx  # Nút mở Recovery
│       │   ├── RecoveryView.tsx       # Giao diện đánh giá & restore
│       │   └── DetailModal.tsx        # Modal chi tiết action
│       ├── pages/
│       │   └── ActionHistoryPage.tsx  # Trang lịch sử hành động
│       └── index.ts
├── server/
│   ├── audit.ts           # Middleware: action log + snapshot
│   ├── audit-auth.ts      # Lifecycle: login/logout
│   ├── config/
│   ├── content-types/
│   │   ├── action-history/
│   │   └── version/
│   ├── controllers/
│   ├── routes/
│   ├── services/
│   │   ├── history-service.ts    # Version, assess, restore
│   │   ├── retention-service.ts  # Cleanup theo retention
│   │   └── restore-steps.ts      # Types cho restore
│   └── index.ts
├── VERSION-RESTORE.md     # Chi tiết logic snapshot/restore
└── README.md

API Endpoints

Tất cả endpoints dưới prefix /presence (hoặc /api/presence).

Version & Restore

| Method | Path | Mô tả | |--------|------|-------| | GET | /list?documentId=&contentType= | Danh sách versions của document | | GET | /assess/:versionId | Đánh giá version (fields, relations, media, %) | | GET | /version/:documentId | Chi tiết một version | | GET | /restore-stream/:versionId?token= | SSE stream restore (step-by-step) | | POST | /restore | Restore (body: versionId) | | POST | /cancel-restore | Hủy restore đang chạy (body: token) | | GET/POST | /snapshot-now?contentType=&locale= | Chụp snapshot thủ công (debug) |

Action History

| Method | Path | Mô tả | |--------|------|-------| | GET | /action-history | Danh sách action log | | GET | /action-history/:id | Chi tiết một action |


Version Snapshot & Restore

Snapshot lưu gì?

  • Fields thông thường: string, number, richtext…
  • Components / dynamic zones
  • Danh sách documentId của relations (không clone bản ghi liên quan)

Restore làm gì?

  • Ghi đè toàn bộ fields
  • Gán lại relations theo danh sách ID đã lưu
  • Relations mới (không có trong version cũ) bị remove
  • Thứ tự many-to-many được giữ

Những gì KHÔNG làm

  • Không khôi phục nội dung đã sửa của bản ghi relation
  • Không tạo lại relation nếu bản ghi đó đã bị xóa

Chi tiết: VERSION-RESTORE.md


Phát triển

# Watch mode
npm run watch

# Verify plugin
npm run verify

Dependencies

  • socket.io, socket.io-client – Real-time
  • @strapi/design-system, @strapi/icons – Admin UI