strapi-plugin-magic-sessionmanager 4.11.0 → 4.12.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/CHANGELOG.md +49 -1
- package/README.md +24 -15
- package/dist/admin/{Analytics-D56O8Q6e.mjs → Analytics-C_c24Uzq.mjs} +45 -75
- package/dist/admin/{Analytics-CBHeWeGn.js → Analytics-lP0-RsVd.js} +45 -75
- package/dist/admin/{App-EDIkLJdb.mjs → App-DCyNPn1k.mjs} +161 -117
- package/dist/admin/{App-D4cBPwB_.js → App-miWDdmdX.js} +161 -117
- package/dist/admin/{OnlineUsersWidget-BF2R2YIy.js → OnlineUsersWidget-C6b7e4jb.js} +18 -26
- package/dist/admin/{OnlineUsersWidget-MwUutkKQ.mjs → OnlineUsersWidget-C6wlwENC.mjs} +18 -26
- package/dist/admin/{Settings-CMzEF8EH.js → Settings-D9zyn5xn.js} +1 -1
- package/dist/admin/{Settings-bLMyi0BN.mjs → Settings-DssYw2W4.mjs} +1 -1
- package/dist/admin/{de-CxfuTF6C.mjs → de--yNl7MPl.mjs} +4 -6
- package/dist/admin/{de-DVNTHmSo.js → de-DjPEATFf.js} +4 -6
- package/dist/admin/{en-BcPIlQYL.mjs → en-5U7g51cH.mjs} +4 -6
- package/dist/admin/{en-BuVXIcHA.js → en-BoO12UQw.js} +4 -6
- package/dist/admin/{es-DxHpaNA1.mjs → es-BJR-zCXL.mjs} +4 -6
- package/dist/admin/{es-CEteHmBO.js → es-BLpEuycJ.js} +4 -6
- package/dist/admin/{fr-BMd2-wW7.js → fr-BE828R9Q.js} +4 -6
- package/dist/admin/{fr-Dw43lHg7.mjs → fr-CeeCYQCs.mjs} +4 -6
- package/dist/admin/{index-DvNfekoR.js → index-CfQOMZVX.js} +9 -46
- package/dist/admin/{index-qa6Qnfkc.mjs → index-rbxJZcLv.mjs} +35 -72
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/{pt-BvO63p01.js → pt-BWEFiuvo.js} +4 -6
- package/dist/admin/{pt-7jnxDSX-.mjs → pt-CorrU3yG.mjs} +4 -6
- package/dist/server/index.js +789 -36
- package/dist/server/index.mjs +789 -36
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
+
# [4.12.0](https://github.com/Schero94/Magic-Sessionmanager/compare/v4.11.0...v4.12.0) (2026-11-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **sessions:** page, filter and count sessions on the server ([#9](https://github.com/Schero94/Magic-Sessionmanager/issues/9)) ([c389614](https://github.com/Schero94/Magic-Sessionmanager/commit/c38961432d4415ded4b9c37c80414dbe787e518a))
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
Release type: minor (`feat`), no breaking change. Callers of `GET /sessions` without paging parameters get the same response as before.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
* **No 1,000-session limit in the admin.** The dashboard used to load the latest 1,000 sessions and filter, search and page them in the browser, so counts, filters and exports stopped at 1,000 and every load read and enriched all of them. The list is now paged, filtered, searched and sorted on the server with exact totals; only the 25 to 100 rows on the screen are loaded and enriched.
|
|
15
|
+
* **The homepage widget loads counts only** (`GET /sessions/stats`) instead of the whole session list every 30 seconds.
|
|
16
|
+
* **Analytics covers every session** (`GET /sessions/analytics`): counts, sessions per device and browser, distinct users and the average length are computed in SQL and cached for 30 seconds.
|
|
17
|
+
* **Export covers every matching session** up to 50,000 (newest first), read in batches of 1,000 with a cursor. A larger result says so.
|
|
18
|
+
* **In `refresh` mode** the list reconciles the rows on the page with one query on Strapi's session table instead of listing the sessions of every user. Open Strapi sessions without session details from this plugin are counted in a notice; they stay listed on each user's sessions panel.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
* `GET /sessions` and `GET /sessions/active` accept `page`, `pageSize` (1-100), `status`, `reason`, `search` (up to 100 characters) and `sort` (whitelisted values). Unknown or out-of-range parameters return 400; pages that start after the first 50,000 matching sessions return 400.
|
|
23
|
+
* `GET /sessions/stats`, `GET /sessions/analytics` and `GET /sessions/export`, protected like every admin route (`plugin::magic-sessionmanager.access`).
|
|
24
|
+
* Database indexes for the list, counts and export (`login_time`, `last_active`, `is_active` with `last_active`, `login_time` or `termination_reason`, and `native_session_id`), created at startup if missing.
|
|
25
|
+
|
|
26
|
+
### Security
|
|
27
|
+
|
|
28
|
+
* The list, statistics, analytics, export and `/users/stats` routes use the read rate limit (120 per minute per admin, raised with `rateLimitReadMax`).
|
|
29
|
+
* CSV exports neutralise cells that start with `=`, `+`, `-`, `@`, a tab or a carriage return (spreadsheet formula injection).
|
|
30
|
+
|
|
31
|
+
### Performance
|
|
32
|
+
|
|
33
|
+
Measured on PostgreSQL 16 with 50,000 sessions over 10,000 users (Strapi 5.61, synthetic data):
|
|
34
|
+
|
|
35
|
+
| Request | 4.11.0 | This release |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| Dashboard (`legacy-support` mode) | 30 ms, 1,000 rows (730 KB), counts capped at 1,000 | 7 ms for a page of 25 (18 KB); 12 ms page plus exact counts |
|
|
38
|
+
| Dashboard (`refresh` mode) | 892 ms, 10,319 queries | 16 ms page plus counts, 13 queries |
|
|
39
|
+
| Widget (`refresh` mode) | 814 ms, 10,328 queries | 10 ms, 10 queries, counts only |
|
|
40
|
+
| Analytics | latest 1,000 sessions only | every session; 5 ms when cached (30 s) |
|
|
41
|
+
|
|
42
|
+
Most remaining queries per request are Strapi's admin authentication, permission check and the rate limiter; the plugin's own list work is a COUNT, the page and one user lookup. Admin requests no longer run the end-user "last seen" lookup (three queries each).
|
|
43
|
+
|
|
44
|
+
### Migration
|
|
45
|
+
|
|
46
|
+
1. Nothing to do. Rebuild the admin (`npm run build`) after upgrading.
|
|
47
|
+
2. Scripts that call `GET /magic-sessionmanager/sessions` without `page` keep working unchanged; add `?page=1&pageSize=100` to page through every session.
|
|
48
|
+
|
|
1
49
|
# [4.11.0](https://github.com/Schero94/Magic-Sessionmanager/compare/v4.10.0...v4.11.0) (2026-11-07)
|
|
2
50
|
|
|
3
51
|
|
|
@@ -5,7 +53,7 @@
|
|
|
5
53
|
|
|
6
54
|
* remove the license feature and every license server call ([#8](https://github.com/Schero94/Magic-Sessionmanager/issues/8)) ([c5ba2ef](https://github.com/Schero94/Magic-Sessionmanager/commit/c5ba2ef6b3e32f11cfadaed479a6d2e5688b3415))
|
|
7
55
|
|
|
8
|
-
##
|
|
56
|
+
## 4.11.0 details (written before the release)
|
|
9
57
|
|
|
10
58
|
Release type: minor. `feat:` removes the license feature; `fix:` corrects the package metadata. No `BREAKING CHANGE` footer, see "Version decision" below.
|
|
11
59
|
|
package/README.md
CHANGED
|
@@ -176,13 +176,14 @@ All screenshots use synthetic data: users `*.example.test`, IP addresses from th
|
|
|
176
176
|
|
|
177
177
|
### Sessions dashboard
|
|
178
178
|
|
|
179
|
-
- **Header:** title "Sessions", the links **Analytics** and **Settings** (opens Configuration), and **Export** (CSV or JSON of the
|
|
179
|
+
- **Header:** title "Sessions", the links **Analytics** and **Settings** (opens Configuration), and **Export** (CSV or JSON of every session that matches the filter, up to 50,000 newest, with an "End reason" column and never any tokens).
|
|
180
180
|
- **How sessions work:** a collapsed legend of the three states.
|
|
181
181
|
- **Four stat cards** that set the status filter: **Active** ("{n} users online"), **Idle**, **Ended** ("{a} logged out · {b} timed out · {c} other reasons") and **All**.
|
|
182
182
|
- **Action bar:** search by user, email, IP or device; **Status** filter (All sessions, Open, Active, Idle, Ended); an **End reason** filter when Ended is selected; Refresh. "Last updated" shows when the list was loaded; it also refreshes every 10 minutes.
|
|
183
183
|
- **Table:** Status (badge and a second line, for example "Ended manually · {date}"), User, Device, IP address, Signed in, Last active and the row actions **View details**, **End session** (disabled on ended rows) and **More actions › Delete record**. Clicking a row opens the details.
|
|
184
184
|
- Filters, search, page and page size are kept in the URL, so `?search=<email>` is a shareable link.
|
|
185
|
-
-
|
|
185
|
+
- Search, filters, sorting and paging run on the server, so the list, the counts and the page numbers cover every session, however many there are. Only the 25 to 100 rows on the screen are loaded.
|
|
186
|
+
- In `refresh` mode, open Strapi sessions that have no session details from this plugin (for example sign-ins from before it was installed) are counted in a notice and listed on each user's sessions panel.
|
|
186
187
|
- Below the large breakpoint the IP address and Signed in columns are hidden; below the medium breakpoint the table becomes a card list.
|
|
187
188
|
|
|
188
189
|
### Session details
|
|
@@ -223,7 +224,7 @@ Two links: **Configuration** and **Analytics**.
|
|
|
223
224
|
|
|
224
225
|
**Save** applies the whole form; **Discard changes** re-loads the stored values (it does not restore defaults). Leaving with unsaved changes asks first. Settings are saved in the database; other server processes apply them within 30 seconds.
|
|
225
226
|
|
|
226
|
-
**Analytics** shows All sessions, Active sessions, Sign-ins in the last 24 hours and in the last 7 days (rolling windows), sessions by device and by browser, and the average session length,
|
|
227
|
+
**Analytics** shows All sessions, Active sessions, Sign-ins in the last 24 hours and in the last 7 days (rolling windows), sessions by device and by browser, and the average session length, computed on the server over every session (cached for 30 seconds).
|
|
227
228
|
|
|
228
229
|
---
|
|
229
230
|
|
|
@@ -587,8 +588,11 @@ Prefix `/magic-sessionmanager` (Strapi admin API). Every route requires an authe
|
|
|
587
588
|
|
|
588
589
|
| Method | Path | Admin UI action |
|
|
589
590
|
| -------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
590
|
-
| GET | `/sessions` | Sessions dashboard
|
|
591
|
-
| GET | `/sessions/active` |
|
|
591
|
+
| GET | `/sessions` | Sessions dashboard: `?page=&pageSize=` (1-100), `status`, `reason`, `search`, `sort`; see below |
|
|
592
|
+
| GET | `/sessions/active` | Active sessions only; same paging parameters |
|
|
593
|
+
| GET | `/sessions/stats` | Dashboard cards and widget: counts only, cached 5 seconds per process |
|
|
594
|
+
| GET | `/sessions/analytics` | Analytics page: counts and grouped counts over every session, cached 30 seconds |
|
|
595
|
+
| GET | `/sessions/export` | Export batches of up to 1,000 rows, newest first; follow `meta.nextCursor` |
|
|
592
596
|
| GET | `/user/:userId/sessions` | Sessions panel |
|
|
593
597
|
| POST | `/sessions/:sessionId/terminate` | **End session** (reason `manual`; in refresh mode the Strapi session is revoked first; the record stays) |
|
|
594
598
|
| DELETE | `/sessions/:sessionId` | **Delete record** (record removed, token stays revoked; an open session also ends) |
|
|
@@ -603,6 +607,10 @@ Prefix `/magic-sessionmanager` (Strapi admin API). Every route requires an authe
|
|
|
603
607
|
| GET, PUT | `/settings` | Configuration (PUT validates every field and returns `error.details.errors` on invalid input) |
|
|
604
608
|
| POST | `/sessions/:sessionId/simulate-timeout` | Development only; removed when `NODE_ENV` is `production` or `staging` |
|
|
605
609
|
|
|
610
|
+
**Session list parameters.** `page` (from 1), `pageSize` (1-100), `status` (`all`, `open`, `active`, `idle`, `ended`), `reason` (with `status=ended`: `logout`, `idle`, `expired`, `manual`, `blocked`, `unrecorded`), `search` (up to 100 characters; matches email, username, IP address, browser, operating system and device type) and `sort` (`loginTime:desc`, `loginTime:asc`, `lastActive:desc`, `lastActive:asc`). The response is `{ data, meta: { pagination: { page, pageSize, total, pageCount } } }` with exact totals. Unknown or out-of-range parameters return 400. Pages that start after the first 50,000 matching sessions return 400; narrow the filter or use the export, which walks every row with a cursor. Without `page` and `pageSize`, `GET /sessions` keeps the 4.x response (latest 1,000 rows, `meta.truncated`) for existing scripts.
|
|
611
|
+
|
|
612
|
+
The list, statistics, analytics, export and `/users/stats` routes share the read rate limit (120 requests per minute per admin, raise it with `rateLimitReadMax`).
|
|
613
|
+
|
|
606
614
|
**Block / unblock** (`toggle-block`): send `{ "blocked": true }` or `{ "blocked": false }`. This sets the state, is safe to retry and is what the admin UI sends. A request without a body still toggles, but is deprecated, because a retry after a lost response can reverse the intended state. A non-boolean `blocked` returns 400. The response contains `blocked` and `mode` (`explicit` or `toggle`). Blocking ends all open sessions with the reason `blocked`; if that fails, the response is 500 and the request can be retried.
|
|
607
615
|
|
|
608
616
|
Errors use Strapi's `{ data: null, error }` envelope: 400 for invalid input, 404 for unknown IDs, 500 for server-side failures, 502 for a failed MaxMind download, 409 for a settings save based on an outdated `revision`.
|
|
@@ -765,16 +773,17 @@ Measured over HTTP on an isolated Strapi 5.61 host with one PostgreSQL 16 databa
|
|
|
765
773
|
|
|
766
774
|
The plugin sits in the request path of every authenticated Content API call, so it keeps that path short:
|
|
767
775
|
|
|
768
|
-
| Work | How it is kept cheap
|
|
769
|
-
| ------------------------- |
|
|
770
|
-
| Session check per request | One lookup by token hash. Startup creates the indexes `idx_magic_sessions_token_hash` and `idx_magic_sessions_refresh_hash` if they are missing.
|
|
771
|
-
|
|
|
772
|
-
|
|
|
773
|
-
|
|
|
774
|
-
|
|
|
775
|
-
|
|
|
776
|
-
|
|
|
777
|
-
|
|
|
776
|
+
| Work | How it is kept cheap |
|
|
777
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
778
|
+
| Session check per request | One lookup by token hash. Startup creates the indexes `idx_magic_sessions_token_hash` and `idx_magic_sessions_refresh_hash` if they are missing. |
|
|
779
|
+
| Admin list and counts | Paged in SQL with exact `COUNT` totals; indexes on `login_time`, `last_active`, `is_active` combinations, `termination_reason` and `native_session_id`. Measured on PostgreSQL 16 with 50,000 sessions: a dashboard page in about 7-10 ms, page plus counts in about 12-16 ms. |
|
|
780
|
+
| "Last active" updates | At most one write per session per `lastSeenRateLimit` (30 seconds by default), as a conditional update. |
|
|
781
|
+
| Settings | Cached for 30 seconds per process; a shared revision is checked at most every 2 seconds (one primary-key read). |
|
|
782
|
+
| User lookups | Resolving a user's `documentId` is cached for 5 minutes per process. |
|
|
783
|
+
| ipapi.co lookups | Results are cached for 24 hours (failures for 5 minutes) and shared across processes, with the IP stored only as a hash. A local MaxMind database avoids the network call entirely. |
|
|
784
|
+
| Admin lists | Only the visible page (25-100 rows) is loaded and enriched. Counts for the cards and the widget are cached 5 seconds per process, Analytics 30 seconds. `GET /my-sessions` returns at most 200. |
|
|
785
|
+
| Idle cleanup | Runs on one process per interval (job lease). In `legacy-support` mode, `cleanupUseDbDirect: true` ends idle sessions with a single SQL update instead of one Document Service call per session. |
|
|
786
|
+
| Old history | Retention deletes ended sessions older than `retentionDays` (90 by default) once a day, so the table does not grow without bound. |
|
|
778
787
|
|
|
779
788
|
---
|
|
780
789
|
|
|
@@ -7,16 +7,9 @@ import styled from "styled-components";
|
|
|
7
7
|
import { Typography, Flex, LinkButton, Button, EmptyStateLayout, VisuallyHidden } from "@strapi/design-system";
|
|
8
8
|
import { ArrowClockwise, ChartBubble, User, Clock, Calendar } from "@strapi/icons";
|
|
9
9
|
import { EmptyDocuments } from "@strapi/icons/symbols";
|
|
10
|
-
import {
|
|
10
|
+
import { J as normalizeDeviceType, u as useSessionFormatters, l as pluginId, m as logSafeAdminError, n as PersistentAlert, R as ReadableText, v as PageShell, w as StatGrid, x as StatCard, F as EqualGrid, b as getTranslation, K as getDeviceTypeMessage } from "./index-rbxJZcLv.mjs";
|
|
11
11
|
import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
|
|
12
12
|
const ANALYTICS_UNKNOWN_KEY = "unknown";
|
|
13
|
-
function increment(target, key) {
|
|
14
|
-
target[key] = (target[key] || 0) + 1;
|
|
15
|
-
}
|
|
16
|
-
function getUserKey(session) {
|
|
17
|
-
return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
|
|
18
|
-
}
|
|
19
|
-
const toTime = (value) => value ? Date.parse(value) : Number.NaN;
|
|
20
13
|
const VERSION_TOKEN = /^v?\d[\w.]*$/i;
|
|
21
14
|
function toNameBucket(value) {
|
|
22
15
|
if (typeof value !== "string") return ANALYTICS_UNKNOWN_KEY;
|
|
@@ -32,22 +25,6 @@ function getDeviceBucket(session) {
|
|
|
32
25
|
function getBrowserBucket(session) {
|
|
33
26
|
return toNameBucket(session?.browserName);
|
|
34
27
|
}
|
|
35
|
-
function getSessionDurationMinutes(session, now = Date.now()) {
|
|
36
|
-
const start = toTime(session?.loginTime);
|
|
37
|
-
if (!Number.isFinite(start)) return null;
|
|
38
|
-
const lastActive = toTime(session?.lastActive);
|
|
39
|
-
const logoutTime = toTime(session?.logoutTime);
|
|
40
|
-
let end;
|
|
41
|
-
if (session?.isActive) {
|
|
42
|
-
end = Number.isFinite(lastActive) ? lastActive : now;
|
|
43
|
-
} else if (Number.isFinite(logoutTime)) {
|
|
44
|
-
end = logoutTime;
|
|
45
|
-
} else {
|
|
46
|
-
end = lastActive;
|
|
47
|
-
}
|
|
48
|
-
if (!Number.isFinite(end)) return null;
|
|
49
|
-
return Math.max(0, Math.floor((end - start) / 6e4));
|
|
50
|
-
}
|
|
51
28
|
function getAnalyticsBarRows(counts) {
|
|
52
29
|
const entries = Object.entries(counts || {}).filter(
|
|
53
30
|
([, count]) => Number.isFinite(count) && count > 0
|
|
@@ -63,49 +40,50 @@ function getAnalyticsBarRows(counts) {
|
|
|
63
40
|
percent: Math.max(0, Math.min(100, Math.round(count / max * 100)))
|
|
64
41
|
}));
|
|
65
42
|
}
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
43
|
+
function mergeGroups(groups, bucket) {
|
|
44
|
+
const out = {};
|
|
45
|
+
for (const group of Array.isArray(groups) ? groups : []) {
|
|
46
|
+
const count = Number(group?.count);
|
|
47
|
+
if (!Number.isInteger(count) || count <= 0) continue;
|
|
48
|
+
const key = bucket(group?.value ?? null);
|
|
49
|
+
out[key] = (out[key] || 0) + count;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function analyticsFromServer(payload) {
|
|
54
|
+
const data = (
|
|
55
|
+
/** @type {any} */
|
|
56
|
+
payload?.data
|
|
57
|
+
);
|
|
58
|
+
const counts = [
|
|
59
|
+
"totalSessions",
|
|
60
|
+
"activeSessions",
|
|
61
|
+
"idleSessions",
|
|
62
|
+
"endedSessions",
|
|
63
|
+
"signInsLast24Hours",
|
|
64
|
+
"signInsLast7Days",
|
|
65
|
+
"uniqueUsers",
|
|
66
|
+
"avgSessionDuration"
|
|
67
|
+
];
|
|
68
|
+
for (const key of counts) {
|
|
69
|
+
if (!Number.isInteger(data?.[key]) || data[key] < 0) {
|
|
70
|
+
throw new Error("Invalid session analytics response");
|
|
90
71
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (userKey) uniqueUsers.add(userKey);
|
|
95
|
-
const duration = getSessionDurationMinutes(session, now);
|
|
96
|
-
if (duration !== null) durations.push(duration);
|
|
72
|
+
}
|
|
73
|
+
if (!Array.isArray(data.devices) || !Array.isArray(data.browsers)) {
|
|
74
|
+
throw new Error("Invalid session analytics response");
|
|
97
75
|
}
|
|
98
76
|
return {
|
|
99
|
-
totalSessions:
|
|
100
|
-
activeSessions,
|
|
101
|
-
idleSessions,
|
|
102
|
-
endedSessions,
|
|
103
|
-
signInsLast24Hours,
|
|
104
|
-
signInsLast7Days,
|
|
105
|
-
devices,
|
|
106
|
-
browsers,
|
|
107
|
-
uniqueUsers: uniqueUsers
|
|
108
|
-
avgSessionDuration:
|
|
77
|
+
totalSessions: data.totalSessions,
|
|
78
|
+
activeSessions: data.activeSessions,
|
|
79
|
+
idleSessions: data.idleSessions,
|
|
80
|
+
endedSessions: data.endedSessions,
|
|
81
|
+
signInsLast24Hours: data.signInsLast24Hours,
|
|
82
|
+
signInsLast7Days: data.signInsLast7Days,
|
|
83
|
+
devices: mergeGroups(data.devices, (value) => getDeviceBucket({ deviceType: value })),
|
|
84
|
+
browsers: mergeGroups(data.browsers, (value) => getBrowserBucket({ browserName: value })),
|
|
85
|
+
uniqueUsers: data.uniqueUsers,
|
|
86
|
+
avgSessionDuration: data.avgSessionDuration
|
|
109
87
|
};
|
|
110
88
|
}
|
|
111
89
|
const BAR_ROW_INLINE_REM = 24;
|
|
@@ -193,7 +171,6 @@ const AnalyticsPage = () => {
|
|
|
193
171
|
const [loading, setLoading] = useState(true);
|
|
194
172
|
const [refreshing, setRefreshing] = useState(false);
|
|
195
173
|
const [analytics, setAnalytics] = useState(null);
|
|
196
|
-
const [truncated, setTruncated] = useState(false);
|
|
197
174
|
const [updatedAt, setUpdatedAt] = useState(null);
|
|
198
175
|
const [loadError, setLoadError] = useState(false);
|
|
199
176
|
const [forbidden, setForbidden] = useState(false);
|
|
@@ -202,10 +179,8 @@ const AnalyticsPage = () => {
|
|
|
202
179
|
if (requestPendingRef.current) return;
|
|
203
180
|
requestPendingRef.current = true;
|
|
204
181
|
try {
|
|
205
|
-
const { data } = await get(`/${pluginId}/sessions`);
|
|
206
|
-
|
|
207
|
-
setAnalytics(computeSessionAnalytics(sessions));
|
|
208
|
-
setTruncated(data?.meta?.truncated === true);
|
|
182
|
+
const { data } = await get(`/${pluginId}/sessions/analytics`);
|
|
183
|
+
setAnalytics(analyticsFromServer(data));
|
|
209
184
|
setUpdatedAt(Date.now());
|
|
210
185
|
setLoadError(false);
|
|
211
186
|
} catch (err) {
|
|
@@ -237,7 +212,7 @@ const AnalyticsPage = () => {
|
|
|
237
212
|
const subtitle = analytics ? /* @__PURE__ */ jsxs(Typography, { variant: "epsilon", textColor: "neutral600", tag: "p", children: [
|
|
238
213
|
t(
|
|
239
214
|
"analytics.subtitle",
|
|
240
|
-
"{count, plural, =0 {No sessions
|
|
215
|
+
"{count, plural, =0 {No sessions yet.} one {Based on all # session.} other {Based on all # sessions.}}",
|
|
241
216
|
{ count: totalSessions }
|
|
242
217
|
),
|
|
243
218
|
updatedAt ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -298,11 +273,6 @@ const AnalyticsPage = () => {
|
|
|
298
273
|
primaryAction: headerActions,
|
|
299
274
|
children: [
|
|
300
275
|
errorAlert,
|
|
301
|
-
truncated ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t(
|
|
302
|
-
"analytics.truncated",
|
|
303
|
-
"Only the latest {count, number} sessions are loaded. Counts, filters and exports cover these sessions only.",
|
|
304
|
-
{ count: totalSessions }
|
|
305
|
-
) }) }) : null,
|
|
306
276
|
hasSessions ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
307
277
|
/* @__PURE__ */ jsxs(StatGrid, { label: t("analytics.stats.label", "Session overview"), alignValues: true, children: [
|
|
308
278
|
/* @__PURE__ */ jsx(
|
|
@@ -9,18 +9,11 @@ const styled = require("styled-components");
|
|
|
9
9
|
const designSystem = require("@strapi/design-system");
|
|
10
10
|
const icons = require("@strapi/icons");
|
|
11
11
|
const symbols = require("@strapi/icons/symbols");
|
|
12
|
-
const index = require("./index-
|
|
12
|
+
const index = require("./index-CfQOMZVX.js");
|
|
13
13
|
const SectionCard = require("./SectionCard-BlWv8CRt.js");
|
|
14
14
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
15
15
|
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
16
16
|
const ANALYTICS_UNKNOWN_KEY = "unknown";
|
|
17
|
-
function increment(target, key) {
|
|
18
|
-
target[key] = (target[key] || 0) + 1;
|
|
19
|
-
}
|
|
20
|
-
function getUserKey(session) {
|
|
21
|
-
return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
|
|
22
|
-
}
|
|
23
|
-
const toTime = (value) => value ? Date.parse(value) : Number.NaN;
|
|
24
17
|
const VERSION_TOKEN = /^v?\d[\w.]*$/i;
|
|
25
18
|
function toNameBucket(value) {
|
|
26
19
|
if (typeof value !== "string") return ANALYTICS_UNKNOWN_KEY;
|
|
@@ -36,22 +29,6 @@ function getDeviceBucket(session) {
|
|
|
36
29
|
function getBrowserBucket(session) {
|
|
37
30
|
return toNameBucket(session?.browserName);
|
|
38
31
|
}
|
|
39
|
-
function getSessionDurationMinutes(session, now = Date.now()) {
|
|
40
|
-
const start = toTime(session?.loginTime);
|
|
41
|
-
if (!Number.isFinite(start)) return null;
|
|
42
|
-
const lastActive = toTime(session?.lastActive);
|
|
43
|
-
const logoutTime = toTime(session?.logoutTime);
|
|
44
|
-
let end;
|
|
45
|
-
if (session?.isActive) {
|
|
46
|
-
end = Number.isFinite(lastActive) ? lastActive : now;
|
|
47
|
-
} else if (Number.isFinite(logoutTime)) {
|
|
48
|
-
end = logoutTime;
|
|
49
|
-
} else {
|
|
50
|
-
end = lastActive;
|
|
51
|
-
}
|
|
52
|
-
if (!Number.isFinite(end)) return null;
|
|
53
|
-
return Math.max(0, Math.floor((end - start) / 6e4));
|
|
54
|
-
}
|
|
55
32
|
function getAnalyticsBarRows(counts) {
|
|
56
33
|
const entries = Object.entries(counts || {}).filter(
|
|
57
34
|
([, count]) => Number.isFinite(count) && count > 0
|
|
@@ -67,49 +44,50 @@ function getAnalyticsBarRows(counts) {
|
|
|
67
44
|
percent: Math.max(0, Math.min(100, Math.round(count / max * 100)))
|
|
68
45
|
}));
|
|
69
46
|
}
|
|
70
|
-
function
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
47
|
+
function mergeGroups(groups, bucket) {
|
|
48
|
+
const out = {};
|
|
49
|
+
for (const group of Array.isArray(groups) ? groups : []) {
|
|
50
|
+
const count = Number(group?.count);
|
|
51
|
+
if (!Number.isInteger(count) || count <= 0) continue;
|
|
52
|
+
const key = bucket(group?.value ?? null);
|
|
53
|
+
out[key] = (out[key] || 0) + count;
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function analyticsFromServer(payload) {
|
|
58
|
+
const data = (
|
|
59
|
+
/** @type {any} */
|
|
60
|
+
payload?.data
|
|
61
|
+
);
|
|
62
|
+
const counts = [
|
|
63
|
+
"totalSessions",
|
|
64
|
+
"activeSessions",
|
|
65
|
+
"idleSessions",
|
|
66
|
+
"endedSessions",
|
|
67
|
+
"signInsLast24Hours",
|
|
68
|
+
"signInsLast7Days",
|
|
69
|
+
"uniqueUsers",
|
|
70
|
+
"avgSessionDuration"
|
|
71
|
+
];
|
|
72
|
+
for (const key of counts) {
|
|
73
|
+
if (!Number.isInteger(data?.[key]) || data[key] < 0) {
|
|
74
|
+
throw new Error("Invalid session analytics response");
|
|
94
75
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (userKey) uniqueUsers.add(userKey);
|
|
99
|
-
const duration = getSessionDurationMinutes(session, now);
|
|
100
|
-
if (duration !== null) durations.push(duration);
|
|
76
|
+
}
|
|
77
|
+
if (!Array.isArray(data.devices) || !Array.isArray(data.browsers)) {
|
|
78
|
+
throw new Error("Invalid session analytics response");
|
|
101
79
|
}
|
|
102
80
|
return {
|
|
103
|
-
totalSessions:
|
|
104
|
-
activeSessions,
|
|
105
|
-
idleSessions,
|
|
106
|
-
endedSessions,
|
|
107
|
-
signInsLast24Hours,
|
|
108
|
-
signInsLast7Days,
|
|
109
|
-
devices,
|
|
110
|
-
browsers,
|
|
111
|
-
uniqueUsers: uniqueUsers
|
|
112
|
-
avgSessionDuration:
|
|
81
|
+
totalSessions: data.totalSessions,
|
|
82
|
+
activeSessions: data.activeSessions,
|
|
83
|
+
idleSessions: data.idleSessions,
|
|
84
|
+
endedSessions: data.endedSessions,
|
|
85
|
+
signInsLast24Hours: data.signInsLast24Hours,
|
|
86
|
+
signInsLast7Days: data.signInsLast7Days,
|
|
87
|
+
devices: mergeGroups(data.devices, (value) => getDeviceBucket({ deviceType: value })),
|
|
88
|
+
browsers: mergeGroups(data.browsers, (value) => getBrowserBucket({ browserName: value })),
|
|
89
|
+
uniqueUsers: data.uniqueUsers,
|
|
90
|
+
avgSessionDuration: data.avgSessionDuration
|
|
113
91
|
};
|
|
114
92
|
}
|
|
115
93
|
const BAR_ROW_INLINE_REM = 24;
|
|
@@ -197,7 +175,6 @@ const AnalyticsPage = () => {
|
|
|
197
175
|
const [loading, setLoading] = react.useState(true);
|
|
198
176
|
const [refreshing, setRefreshing] = react.useState(false);
|
|
199
177
|
const [analytics, setAnalytics] = react.useState(null);
|
|
200
|
-
const [truncated, setTruncated] = react.useState(false);
|
|
201
178
|
const [updatedAt, setUpdatedAt] = react.useState(null);
|
|
202
179
|
const [loadError, setLoadError] = react.useState(false);
|
|
203
180
|
const [forbidden, setForbidden] = react.useState(false);
|
|
@@ -206,10 +183,8 @@ const AnalyticsPage = () => {
|
|
|
206
183
|
if (requestPendingRef.current) return;
|
|
207
184
|
requestPendingRef.current = true;
|
|
208
185
|
try {
|
|
209
|
-
const { data } = await get(`/${index.pluginId}/sessions`);
|
|
210
|
-
|
|
211
|
-
setAnalytics(computeSessionAnalytics(sessions));
|
|
212
|
-
setTruncated(data?.meta?.truncated === true);
|
|
186
|
+
const { data } = await get(`/${index.pluginId}/sessions/analytics`);
|
|
187
|
+
setAnalytics(analyticsFromServer(data));
|
|
213
188
|
setUpdatedAt(Date.now());
|
|
214
189
|
setLoadError(false);
|
|
215
190
|
} catch (err) {
|
|
@@ -241,7 +216,7 @@ const AnalyticsPage = () => {
|
|
|
241
216
|
const subtitle = analytics ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", tag: "p", children: [
|
|
242
217
|
t(
|
|
243
218
|
"analytics.subtitle",
|
|
244
|
-
"{count, plural, =0 {No sessions
|
|
219
|
+
"{count, plural, =0 {No sessions yet.} one {Based on all # session.} other {Based on all # sessions.}}",
|
|
245
220
|
{ count: totalSessions }
|
|
246
221
|
),
|
|
247
222
|
updatedAt ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
@@ -302,11 +277,6 @@ const AnalyticsPage = () => {
|
|
|
302
277
|
primaryAction: headerActions,
|
|
303
278
|
children: [
|
|
304
279
|
errorAlert,
|
|
305
|
-
truncated ? /* @__PURE__ */ jsxRuntime.jsx(index.PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t(
|
|
306
|
-
"analytics.truncated",
|
|
307
|
-
"Only the latest {count, number} sessions are loaded. Counts, filters and exports cover these sessions only.",
|
|
308
|
-
{ count: totalSessions }
|
|
309
|
-
) }) }) : null,
|
|
310
280
|
hasSessions ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
311
281
|
/* @__PURE__ */ jsxRuntime.jsxs(index.StatGrid, { label: t("analytics.stats.label", "Session overview"), alignValues: true, children: [
|
|
312
282
|
/* @__PURE__ */ jsxRuntime.jsx(
|