strapi-plugin-magic-sessionmanager 4.21.0 → 4.22.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 +48 -0
- package/README.md +46 -11
- package/dist/admin/{Analytics-BqdZIBV4.js → Analytics-DeDLGiCe.js} +1 -1
- package/dist/admin/{Analytics-C-OLLzoB.mjs → Analytics-WbCUmkQQ.mjs} +1 -1
- package/dist/admin/{App-Cx9v6n_7.js → App-Bkv-W0Sv.js} +1336 -2591
- package/dist/admin/{App-BswHmNQT.mjs → App-C4bihk2K.mjs} +1309 -2564
- package/dist/admin/{OnlineUsersWidget-BRmQPPp9.js → OnlineUsersWidget-CSvNe2rC.js} +1 -1
- package/dist/admin/{OnlineUsersWidget-Dusgjc1d.mjs → OnlineUsersWidget-q0Z6nbbO.mjs} +1 -1
- package/dist/admin/{Settings-DZyQheUS.mjs → Settings-avD0DbXP.mjs} +2 -2
- package/dist/admin/{Settings-DWGuf_Z3.js → Settings-xokFI5LO.js} +44 -44
- package/dist/admin/dashboardModel-BBNRgcEr.mjs +170 -0
- package/dist/admin/dashboardModel-D4389iIV.js +169 -0
- package/dist/admin/{de-DUnrmFWk.mjs → de-BQlEdBMr.mjs} +73 -4
- package/dist/admin/{de-24TPqzG6.js → de-HcJ19LKI.js} +73 -4
- package/dist/admin/{en-8mBSkWOF.js → en-DI-98CPM.js} +74 -5
- package/dist/admin/{en-D8J__tyF.mjs → en-DzuXWL1W.mjs} +74 -5
- package/dist/admin/{es-BgpgWdk0.mjs → es-BfyED9YI.mjs} +73 -4
- package/dist/admin/{es-ChUKey-Q.js → es-Cm0Eklav.js} +73 -4
- package/dist/admin/{fr-DE_CWmgq.js → fr-C3nzszsI.js} +73 -4
- package/dist/admin/{fr-k1MHYKJo.mjs → fr-CzFNGWq0.mjs} +73 -4
- package/dist/admin/index-6zc5D8eb.mjs +4729 -0
- package/dist/admin/index-Dk5Jqe5U.js +4730 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/{pt-BjqU5ioB.js → pt-BPZ6chPT.js} +73 -4
- package/dist/admin/{pt-DPO4DmDc.mjs → pt-DmyQnGI_.mjs} +73 -4
- package/dist/server/index.js +552 -55
- package/dist/server/index.mjs +552 -55
- package/package.json +1 -1
- package/dist/admin/index-Ceh3Q1Ki.js +0 -2308
- package/dist/admin/index-meLDPPwt.mjs +0 -2307
- package/dist/admin/settingsTabs-C1q5iMMw.mjs +0 -437
- package/dist/admin/settingsTabs-CfquZuKH.js +0 -436
|
@@ -1,2307 +0,0 @@
|
|
|
1
|
-
import { useRef, useEffect, forwardRef, useId, Children, useCallback, useMemo, useState, useSyncExternalStore } from "react";
|
|
2
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { Monitor, CheckCircle, WarningCircle, Information, Server, Code, Phone, ExternalLink, Duplicate, SignOut, User, Lock } from "@strapi/icons";
|
|
4
|
-
import { useIntl } from "react-intl";
|
|
5
|
-
import { NavLink } from "react-router-dom";
|
|
6
|
-
import { Typography, Flex, Box, Grid, VisuallyHidden, Badge, Tooltip, Dialog, Button, Link, Modal, Field, Textarea, SingleSelect, SingleSelectOption, Checkbox, TextInput, Loader } from "@strapi/design-system";
|
|
7
|
-
import { Page, Layouts, ConfirmDialog, useFetchClient, useNotification, useRBAC, useForm } from "@strapi/strapi/admin";
|
|
8
|
-
import styled, { css } from "styled-components";
|
|
9
|
-
const strapi = { "name": "magic-sessionmanager", "displayName": "Magic Sessionmanager" };
|
|
10
|
-
const pluginPkg = {
|
|
11
|
-
strapi
|
|
12
|
-
};
|
|
13
|
-
const pluginId = "magic-sessionmanager";
|
|
14
|
-
const PLUGIN_ID = pluginId;
|
|
15
|
-
const Initializer = ({ setPlugin }) => {
|
|
16
|
-
const ref = useRef(setPlugin);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (ref.current) {
|
|
19
|
-
ref.current(pluginId);
|
|
20
|
-
}
|
|
21
|
-
}, []);
|
|
22
|
-
return null;
|
|
23
|
-
};
|
|
24
|
-
const PluginIcon = (props) => /* @__PURE__ */ jsx(Monitor, { "aria-hidden": true, focusable: false, ...props });
|
|
25
|
-
const TONES = {
|
|
26
|
-
danger: { background: "danger100", border: "danger200", icon: "danger700" },
|
|
27
|
-
success: { background: "success100", border: "success200", icon: "success700" },
|
|
28
|
-
warning: { background: "warning100", border: "warning200", icon: "warning700" },
|
|
29
|
-
default: { background: "primary100", border: "primary200", icon: "primary700" },
|
|
30
|
-
neutral: { background: "neutral0", border: "neutral200", icon: "neutral600" }
|
|
31
|
-
};
|
|
32
|
-
const AlertBody = styled(Typography)`
|
|
33
|
-
min-width: 0;
|
|
34
|
-
|
|
35
|
-
& > * {
|
|
36
|
-
display: inline;
|
|
37
|
-
max-width: none;
|
|
38
|
-
margin: 0;
|
|
39
|
-
font-size: inherit;
|
|
40
|
-
font-weight: inherit;
|
|
41
|
-
line-height: inherit;
|
|
42
|
-
color: inherit;
|
|
43
|
-
}
|
|
44
|
-
`;
|
|
45
|
-
const PersistentAlert = forwardRef(function PersistentAlert2({
|
|
46
|
-
variant = "default",
|
|
47
|
-
title,
|
|
48
|
-
titleAs = "p",
|
|
49
|
-
stacked = false,
|
|
50
|
-
action,
|
|
51
|
-
closeLabel: _closeLabel,
|
|
52
|
-
onClose: _onClose,
|
|
53
|
-
children,
|
|
54
|
-
...rest
|
|
55
|
-
}, ref) {
|
|
56
|
-
const tone = TONES[variant] || TONES.default;
|
|
57
|
-
const Icon = variant === "success" ? CheckCircle : variant === "danger" || variant === "warning" ? WarningCircle : Information;
|
|
58
|
-
return /* @__PURE__ */ jsxs(
|
|
59
|
-
Flex,
|
|
60
|
-
{
|
|
61
|
-
ref,
|
|
62
|
-
alignItems: "flex-start",
|
|
63
|
-
background: tone.background,
|
|
64
|
-
borderColor: tone.border,
|
|
65
|
-
shadow: "filterShadow",
|
|
66
|
-
gap: 3,
|
|
67
|
-
hasRadius: true,
|
|
68
|
-
padding: 5,
|
|
69
|
-
paddingRight: 6,
|
|
70
|
-
"data-persistent-alert": "",
|
|
71
|
-
...rest,
|
|
72
|
-
children: [
|
|
73
|
-
/* @__PURE__ */ jsx(Flex, { shrink: 0, width: "2rem", height: "2rem", children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, focusable: "false", width: "2rem", height: "2rem", fill: tone.icon }) }),
|
|
74
|
-
/* @__PURE__ */ jsxs(
|
|
75
|
-
Flex,
|
|
76
|
-
{
|
|
77
|
-
direction: stacked ? "column" : "row",
|
|
78
|
-
alignItems: stacked ? "stretch" : "start",
|
|
79
|
-
gap: action || stacked ? 2 : 1,
|
|
80
|
-
wrap: stacked ? "nowrap" : "wrap",
|
|
81
|
-
role: variant === "danger" ? "alert" : "status",
|
|
82
|
-
width: "100%",
|
|
83
|
-
minWidth: 0,
|
|
84
|
-
children: [
|
|
85
|
-
title ? /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", tag: titleAs, children: title }) : null,
|
|
86
|
-
/* @__PURE__ */ jsx(AlertBody, { tag: "div", variant: "omega", textColor: "neutral800", children }),
|
|
87
|
-
action ? /* @__PURE__ */ jsx(Box, { children: action }) : null
|
|
88
|
-
]
|
|
89
|
-
}
|
|
90
|
-
)
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
const paragraphRhythm = css`
|
|
96
|
-
p {
|
|
97
|
-
max-width: 72ch;
|
|
98
|
-
margin-block: 0;
|
|
99
|
-
line-height: 1.6;
|
|
100
|
-
text-wrap: pretty;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
p + p {
|
|
104
|
-
margin-block-start: ${({ theme }) => theme.spaces[3]};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
li {
|
|
108
|
-
max-width: 72ch;
|
|
109
|
-
line-height: 1.6;
|
|
110
|
-
text-wrap: pretty;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
li + li {
|
|
114
|
-
margin-block-start: ${({ theme }) => theme.spaces[2]};
|
|
115
|
-
}
|
|
116
|
-
`;
|
|
117
|
-
const ReadableText = styled(Typography)`
|
|
118
|
-
display: block;
|
|
119
|
-
width: 100%;
|
|
120
|
-
min-width: 0;
|
|
121
|
-
max-width: 72ch;
|
|
122
|
-
margin: 0;
|
|
123
|
-
line-height: 1.6;
|
|
124
|
-
text-wrap: pretty;
|
|
125
|
-
|
|
126
|
-
& + & {
|
|
127
|
-
margin-block-start: ${({ theme }) => theme.spaces[3]};
|
|
128
|
-
}
|
|
129
|
-
`;
|
|
130
|
-
const ParagraphGroup = styled.div`
|
|
131
|
-
display: block;
|
|
132
|
-
width: 100%;
|
|
133
|
-
min-width: 0;
|
|
134
|
-
`;
|
|
135
|
-
const InlineParagraphGroup = styled.span`
|
|
136
|
-
display: block;
|
|
137
|
-
width: 100%;
|
|
138
|
-
min-width: 0;
|
|
139
|
-
`;
|
|
140
|
-
const ReadableParagraphs = ({ id, text, ...typographyProps }) => {
|
|
141
|
-
const ParagraphContainer = typographyProps.tag === "span" ? InlineParagraphGroup : ParagraphGroup;
|
|
142
|
-
const paragraphs = String(text ?? "").split(/\n\s*\n/).map((paragraph) => paragraph.trim()).filter(Boolean);
|
|
143
|
-
return /* @__PURE__ */ jsx(ParagraphContainer, { id, "data-readable-paragraphs": "", children: paragraphs.map((paragraph, index2) => /* @__PURE__ */ jsx(
|
|
144
|
-
ReadableText,
|
|
145
|
-
{
|
|
146
|
-
...typographyProps,
|
|
147
|
-
tag: typographyProps.tag || "p",
|
|
148
|
-
children: paragraph
|
|
149
|
-
},
|
|
150
|
-
`${id || "readable-paragraph"}-${index2}`
|
|
151
|
-
)) });
|
|
152
|
-
};
|
|
153
|
-
const PageContent = styled(Flex)`
|
|
154
|
-
width: 100%;
|
|
155
|
-
min-width: 0;
|
|
156
|
-
|
|
157
|
-
${paragraphRhythm}
|
|
158
|
-
`;
|
|
159
|
-
const PageShell = ({
|
|
160
|
-
headingId,
|
|
161
|
-
title,
|
|
162
|
-
documentTitle,
|
|
163
|
-
subtitle,
|
|
164
|
-
primaryAction,
|
|
165
|
-
secondaryAction,
|
|
166
|
-
navigationAction,
|
|
167
|
-
startActions,
|
|
168
|
-
endActions,
|
|
169
|
-
children
|
|
170
|
-
}) => {
|
|
171
|
-
const generatedId = useId();
|
|
172
|
-
const titleId = headingId || `page-title-${generatedId.replace(/:/g, "")}`;
|
|
173
|
-
const hasActionBar = Boolean(startActions || endActions);
|
|
174
|
-
const tabTitle = documentTitle || (typeof title === "string" ? title : "");
|
|
175
|
-
return /* @__PURE__ */ jsxs(Page.Main, { "aria-labelledby": titleId, children: [
|
|
176
|
-
tabTitle ? /* @__PURE__ */ jsx(Page.Title, { children: tabTitle }) : null,
|
|
177
|
-
/* @__PURE__ */ jsx(
|
|
178
|
-
Layouts.Header,
|
|
179
|
-
{
|
|
180
|
-
id: titleId,
|
|
181
|
-
title,
|
|
182
|
-
subtitle,
|
|
183
|
-
primaryAction,
|
|
184
|
-
secondaryAction,
|
|
185
|
-
navigationAction
|
|
186
|
-
}
|
|
187
|
-
),
|
|
188
|
-
hasActionBar ? /* @__PURE__ */ jsx(Layouts.Action, { startActions, endActions }) : null,
|
|
189
|
-
/* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsx(
|
|
190
|
-
PageContent,
|
|
191
|
-
{
|
|
192
|
-
direction: "column",
|
|
193
|
-
alignItems: "stretch",
|
|
194
|
-
gap: 6,
|
|
195
|
-
paddingBottom: 8,
|
|
196
|
-
"data-text-rhythm": "page",
|
|
197
|
-
"data-page-shell": "",
|
|
198
|
-
children
|
|
199
|
-
}
|
|
200
|
-
) })
|
|
201
|
-
] });
|
|
202
|
-
};
|
|
203
|
-
const ALLOWED_COLUMNS = /* @__PURE__ */ new Set([1, 2, 3, 4, 6]);
|
|
204
|
-
function getGridItemSpans(columns, stackBelow = "medium") {
|
|
205
|
-
const count = ALLOWED_COLUMNS.has(columns) ? columns : 2;
|
|
206
|
-
const col = 12 / count;
|
|
207
|
-
const twoUp = count >= 2 ? 6 : 12;
|
|
208
|
-
if (stackBelow === "small") {
|
|
209
|
-
return { xs: 12, s: twoUp, m: twoUp, col };
|
|
210
|
-
}
|
|
211
|
-
return { xs: 12, s: 12, m: twoUp, col };
|
|
212
|
-
}
|
|
213
|
-
const EqualGrid = ({ columns = 2, stackBelow = "medium", gap = 6, label, children }) => {
|
|
214
|
-
const spans = getGridItemSpans(columns, stackBelow);
|
|
215
|
-
const items = Children.toArray(children).filter(Boolean);
|
|
216
|
-
return /* @__PURE__ */ jsx(
|
|
217
|
-
Grid.Root,
|
|
218
|
-
{
|
|
219
|
-
gap,
|
|
220
|
-
role: label ? "group" : void 0,
|
|
221
|
-
"aria-label": label,
|
|
222
|
-
"data-equal-grid": columns,
|
|
223
|
-
children: items.map((child, index2) => /* @__PURE__ */ jsx(
|
|
224
|
-
Grid.Item,
|
|
225
|
-
{
|
|
226
|
-
col: spans.col,
|
|
227
|
-
m: spans.m,
|
|
228
|
-
s: spans.s,
|
|
229
|
-
xs: spans.xs,
|
|
230
|
-
direction: "column",
|
|
231
|
-
alignItems: "stretch",
|
|
232
|
-
minWidth: 0,
|
|
233
|
-
children: child
|
|
234
|
-
},
|
|
235
|
-
child.key ?? index2
|
|
236
|
-
))
|
|
237
|
-
}
|
|
238
|
-
);
|
|
239
|
-
};
|
|
240
|
-
const STAT_GRID_FOLD_REM = (4 * 200 + 3 * 16) / 10;
|
|
241
|
-
const DS_SMALL_REM = 52;
|
|
242
|
-
const StatGridFrame = styled.div`
|
|
243
|
-
container-type: inline-size;
|
|
244
|
-
min-width: 0;
|
|
245
|
-
|
|
246
|
-
@container (min-width: ${DS_SMALL_REM}rem) and (max-width: ${STAT_GRID_FOLD_REM - 0.01}rem) {
|
|
247
|
-
[data-equal-grid='4'] > * {
|
|
248
|
-
grid-column: span 6;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/* Rows without secondary lines: pin every value to the card bottom, so a
|
|
253
|
-
label that wraps onto two lines does not push its value off the row's line. */
|
|
254
|
-
&[data-align-values] [data-stat-body] {
|
|
255
|
-
flex: 1 1 auto;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
&[data-align-values] [data-stat-text] {
|
|
259
|
-
justify-content: space-between;
|
|
260
|
-
}
|
|
261
|
-
`;
|
|
262
|
-
const StatGrid = ({ columns = 4, label, alignValues = false, children }) => /* @__PURE__ */ jsx(StatGridFrame, { "data-stat-grid": "", "data-align-values": alignValues ? "" : void 0, children: /* @__PURE__ */ jsx(EqualGrid, { columns, stackBelow: "small", gap: 4, label, children }) });
|
|
263
|
-
const IconTile = styled(Flex)`
|
|
264
|
-
align-self: flex-start;
|
|
265
|
-
|
|
266
|
-
svg {
|
|
267
|
-
width: ${({ theme }) => theme.spaces[5]};
|
|
268
|
-
height: ${({ theme }) => theme.spaces[5]};
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
svg path {
|
|
272
|
-
fill: ${({ theme, $tone }) => theme.colors[`${$tone}600`]};
|
|
273
|
-
}
|
|
274
|
-
`;
|
|
275
|
-
const STAT_TONES = /* @__PURE__ */ new Set([
|
|
276
|
-
"primary",
|
|
277
|
-
"success",
|
|
278
|
-
"warning",
|
|
279
|
-
"danger",
|
|
280
|
-
"neutral",
|
|
281
|
-
"secondary",
|
|
282
|
-
"alternative"
|
|
283
|
-
]);
|
|
284
|
-
const CardButton = styled(Box)`
|
|
285
|
-
appearance: none;
|
|
286
|
-
font: inherit;
|
|
287
|
-
color: inherit;
|
|
288
|
-
text-align: start;
|
|
289
|
-
cursor: pointer;
|
|
290
|
-
width: 100%;
|
|
291
|
-
|
|
292
|
-
&:hover {
|
|
293
|
-
background: ${({ theme }) => theme.colors.primary100};
|
|
294
|
-
}
|
|
295
|
-
`;
|
|
296
|
-
const StatCard = ({
|
|
297
|
-
label,
|
|
298
|
-
value,
|
|
299
|
-
icon: Icon,
|
|
300
|
-
tone = "neutral",
|
|
301
|
-
description,
|
|
302
|
-
onClick,
|
|
303
|
-
pressed,
|
|
304
|
-
actionLabel
|
|
305
|
-
}) => {
|
|
306
|
-
const safeTone = STAT_TONES.has(tone) ? tone : "neutral";
|
|
307
|
-
const clickable = typeof onClick === "function";
|
|
308
|
-
const buttonProps = clickable ? {
|
|
309
|
-
tag: "button",
|
|
310
|
-
type: "button",
|
|
311
|
-
onClick,
|
|
312
|
-
"aria-pressed": Boolean(pressed),
|
|
313
|
-
"aria-label": actionLabel
|
|
314
|
-
} : {};
|
|
315
|
-
const Card = clickable ? CardButton : Box;
|
|
316
|
-
return /* @__PURE__ */ jsx(
|
|
317
|
-
Card,
|
|
318
|
-
{
|
|
319
|
-
...buttonProps,
|
|
320
|
-
background: "neutral0",
|
|
321
|
-
hasRadius: true,
|
|
322
|
-
shadow: "tableShadow",
|
|
323
|
-
borderColor: clickable ? pressed ? "primary600" : "neutral150" : void 0,
|
|
324
|
-
padding: 4,
|
|
325
|
-
flex: "1 1 auto",
|
|
326
|
-
minWidth: 0,
|
|
327
|
-
"data-stat-card": safeTone,
|
|
328
|
-
children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, height: "100%", children: [
|
|
329
|
-
/* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "stretch", minWidth: 0, "data-stat-body": "", children: [
|
|
330
|
-
Icon ? /* @__PURE__ */ jsx(
|
|
331
|
-
IconTile,
|
|
332
|
-
{
|
|
333
|
-
$tone: safeTone,
|
|
334
|
-
background: `${safeTone}100`,
|
|
335
|
-
hasRadius: true,
|
|
336
|
-
padding: 2,
|
|
337
|
-
shrink: 0,
|
|
338
|
-
justifyContent: "center",
|
|
339
|
-
alignItems: "center",
|
|
340
|
-
"aria-hidden": true,
|
|
341
|
-
children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, focusable: false })
|
|
342
|
-
}
|
|
343
|
-
) : null,
|
|
344
|
-
/* @__PURE__ */ jsxs(
|
|
345
|
-
Flex,
|
|
346
|
-
{
|
|
347
|
-
direction: "column",
|
|
348
|
-
alignItems: "flex-start",
|
|
349
|
-
gap: 1,
|
|
350
|
-
minWidth: 0,
|
|
351
|
-
flex: "1 1 auto",
|
|
352
|
-
"data-stat-text": "",
|
|
353
|
-
children: [
|
|
354
|
-
/* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", tag: "span", children: label }),
|
|
355
|
-
/* @__PURE__ */ jsx(Typography, { variant: "beta", textColor: "neutral800", tag: "span", children: value })
|
|
356
|
-
]
|
|
357
|
-
}
|
|
358
|
-
)
|
|
359
|
-
] }),
|
|
360
|
-
description ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "span", children: description }) : null
|
|
361
|
-
] })
|
|
362
|
-
}
|
|
363
|
-
);
|
|
364
|
-
};
|
|
365
|
-
const MISSING_VALUE_GLYPH = "—";
|
|
366
|
-
const MISSING_VALUE_MESSAGE = Object.freeze({
|
|
367
|
-
messageId: "common.value.missing",
|
|
368
|
-
defaultMessage: "Not available"
|
|
369
|
-
});
|
|
370
|
-
function isMissingValue(value) {
|
|
371
|
-
if (value === null || value === void 0) return true;
|
|
372
|
-
if (typeof value === "number") return !Number.isFinite(value);
|
|
373
|
-
if (value instanceof Date) return !Number.isFinite(value.getTime());
|
|
374
|
-
if (typeof value === "string") {
|
|
375
|
-
const trimmed = value.trim();
|
|
376
|
-
return trimmed === "" || trimmed.toLowerCase() === "unknown";
|
|
377
|
-
}
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
function presentText(value) {
|
|
381
|
-
if (isMissingValue(value)) return "";
|
|
382
|
-
return String(value).trim();
|
|
383
|
-
}
|
|
384
|
-
const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
|
|
385
|
-
const MissingValue = ({ textColor = "neutral600", variant }) => {
|
|
386
|
-
const { formatMessage } = useIntl();
|
|
387
|
-
const label = formatMessage({
|
|
388
|
-
id: getTranslation(MISSING_VALUE_MESSAGE.messageId),
|
|
389
|
-
defaultMessage: MISSING_VALUE_MESSAGE.defaultMessage
|
|
390
|
-
});
|
|
391
|
-
return /* @__PURE__ */ jsxs(Typography, { textColor, variant, "data-missing-value": "", children: [
|
|
392
|
-
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: MISSING_VALUE_GLYPH }),
|
|
393
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { children: label })
|
|
394
|
-
] });
|
|
395
|
-
};
|
|
396
|
-
const ValueOrMissing = ({ value, children, textColor, variant }) => {
|
|
397
|
-
if (isMissingValue(value)) return /* @__PURE__ */ jsx(MissingValue, { textColor, variant });
|
|
398
|
-
return /* @__PURE__ */ jsx(Fragment, { children: children ?? String(value) });
|
|
399
|
-
};
|
|
400
|
-
const List = styled.dl`
|
|
401
|
-
display: grid;
|
|
402
|
-
grid-template-columns: minmax(0, 1fr);
|
|
403
|
-
gap: ${({ theme }) => theme.spaces[4]};
|
|
404
|
-
column-gap: ${({ theme, $columnGap }) => theme.spaces[$columnGap ?? 4]};
|
|
405
|
-
margin: 0;
|
|
406
|
-
min-width: 0;
|
|
407
|
-
|
|
408
|
-
${({ theme }) => theme.breakpoints.small} {
|
|
409
|
-
grid-template-columns: repeat(${({ $columns }) => $columns}, minmax(0, 1fr));
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
& > div {
|
|
413
|
-
display: flex;
|
|
414
|
-
flex-direction: column;
|
|
415
|
-
gap: ${({ theme }) => theme.spaces[1]};
|
|
416
|
-
min-width: 0;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
& > div[data-span='full'] {
|
|
420
|
-
grid-column: 1 / -1;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
dt,
|
|
424
|
-
dd {
|
|
425
|
-
margin: 0;
|
|
426
|
-
min-width: 0;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
dd {
|
|
430
|
-
overflow-wrap: break-word;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
dd[data-wrap='anywhere'] {
|
|
434
|
-
overflow-wrap: anywhere;
|
|
435
|
-
}
|
|
436
|
-
`;
|
|
437
|
-
const PropertyList = ({ items = [], columns = 2, label, columnGap }) => /* @__PURE__ */ jsx(
|
|
438
|
-
List,
|
|
439
|
-
{
|
|
440
|
-
$columns: columns === 1 ? 1 : 2,
|
|
441
|
-
$columnGap: columnGap,
|
|
442
|
-
"aria-label": label,
|
|
443
|
-
"data-property-list": "",
|
|
444
|
-
children: items.filter(Boolean).map((item) => {
|
|
445
|
-
const wrapsAnywhere = item.kind === "id" || item.kind === "email";
|
|
446
|
-
const missing = item.render === void 0 && isMissingValue(item.value);
|
|
447
|
-
return /* @__PURE__ */ jsxs("div", { "data-span": item.fullWidth ? "full" : void 0, children: [
|
|
448
|
-
/* @__PURE__ */ jsx("dt", { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: item.label }) }),
|
|
449
|
-
/* @__PURE__ */ jsx("dd", { "data-wrap": wrapsAnywhere ? "anywhere" : void 0, children: missing ? /* @__PURE__ */ jsx(MissingValue, { variant: "omega" }) : item.render ?? /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: String(item.value) }) })
|
|
450
|
-
] }, item.id);
|
|
451
|
-
})
|
|
452
|
-
}
|
|
453
|
-
);
|
|
454
|
-
const DEFAULT_DATE_OPTIONS = Object.freeze({ dateStyle: "medium", timeStyle: "short" });
|
|
455
|
-
const RELATIVE_UNITS = [
|
|
456
|
-
["year", 365 * 24 * 60 * 60],
|
|
457
|
-
["month", 30 * 24 * 60 * 60],
|
|
458
|
-
["week", 7 * 24 * 60 * 60],
|
|
459
|
-
["day", 24 * 60 * 60],
|
|
460
|
-
["hour", 60 * 60],
|
|
461
|
-
["minute", 60],
|
|
462
|
-
["second", 1]
|
|
463
|
-
];
|
|
464
|
-
function toValidDate(value) {
|
|
465
|
-
if (value === null || value === void 0 || value === "") return null;
|
|
466
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
467
|
-
return Number.isFinite(date.getTime()) ? date : null;
|
|
468
|
-
}
|
|
469
|
-
function formatSessionDate(value, locale, fallback = "", options = DEFAULT_DATE_OPTIONS) {
|
|
470
|
-
const date = toValidDate(value);
|
|
471
|
-
if (!date) return fallback;
|
|
472
|
-
try {
|
|
473
|
-
return new Intl.DateTimeFormat(locale || "en", options).format(date);
|
|
474
|
-
} catch {
|
|
475
|
-
return new Intl.DateTimeFormat("en", options).format(date);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
function getRelativeTimeParts(value, now = Date.now()) {
|
|
479
|
-
const date = toValidDate(value);
|
|
480
|
-
const reference = toValidDate(now);
|
|
481
|
-
if (!date || !reference) return null;
|
|
482
|
-
const diffSeconds = Math.round((date.getTime() - reference.getTime()) / 1e3);
|
|
483
|
-
const absolute = Math.abs(diffSeconds);
|
|
484
|
-
if (absolute < 45) return { value: 0, unit: "second" };
|
|
485
|
-
for (const [unit, seconds] of RELATIVE_UNITS) {
|
|
486
|
-
if (absolute >= seconds) {
|
|
487
|
-
const amount = Math.round(diffSeconds / seconds);
|
|
488
|
-
return { value: amount === 0 ? Math.sign(diffSeconds) : amount, unit };
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return { value: 0, unit: "second" };
|
|
492
|
-
}
|
|
493
|
-
function formatRelative(value, locale, { now = Date.now(), fallback = "" } = {}) {
|
|
494
|
-
const parts = getRelativeTimeParts(value, now);
|
|
495
|
-
if (!parts) return fallback;
|
|
496
|
-
const options = { numeric: "auto" };
|
|
497
|
-
try {
|
|
498
|
-
return new Intl.RelativeTimeFormat(locale || "en", options).format(parts.value, parts.unit);
|
|
499
|
-
} catch {
|
|
500
|
-
return new Intl.RelativeTimeFormat("en", options).format(parts.value, parts.unit);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
const API_CLIENTS = [
|
|
504
|
-
["curl/", "cURL"],
|
|
505
|
-
["postman", "Postman"],
|
|
506
|
-
["insomnia", "Insomnia"],
|
|
507
|
-
["okhttp", "OkHttp"],
|
|
508
|
-
["python-requests", "Python Requests"],
|
|
509
|
-
["axios/", "Axios"],
|
|
510
|
-
["node-fetch", "node-fetch"],
|
|
511
|
-
["undici", "undici"],
|
|
512
|
-
["go-http-client", "Go HTTP client"],
|
|
513
|
-
["cfnetwork/", "CFNetwork"],
|
|
514
|
-
["dart/", "Dart"],
|
|
515
|
-
["java/", "Java"],
|
|
516
|
-
["wget/", "Wget"],
|
|
517
|
-
["httpie/", "HTTPie"]
|
|
518
|
-
];
|
|
519
|
-
const RUNTIME_AGENTS = Object.freeze({ node: "Node.js", deno: "Deno", bun: "Bun" });
|
|
520
|
-
const BOT_PATTERN = /bot\b|crawler|spider|slurp|headlesschrome/i;
|
|
521
|
-
const TABLET_PATTERN = /(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i;
|
|
522
|
-
const MOBILE_PATTERN = /Mobile|Android|iP(?:hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(?:hpw|web)OS|Opera M(?:obi|ini)/;
|
|
523
|
-
const LEGACY_DEVICE_LABELS = Object.freeze({
|
|
524
|
-
desktop: "Desktop",
|
|
525
|
-
mobile: "Mobile",
|
|
526
|
-
tablet: "Tablet",
|
|
527
|
-
api: "API Client",
|
|
528
|
-
bot: "Bot",
|
|
529
|
-
"": ""
|
|
530
|
-
});
|
|
531
|
-
const detectBrowser = (ua) => {
|
|
532
|
-
if (ua.includes("edg/") || ua.includes("edga/") || ua.includes("edgios/")) return "Edge";
|
|
533
|
-
if (ua.includes("opr/") || ua.includes("opera")) return "Opera";
|
|
534
|
-
if (ua.includes("firefox/") || ua.includes("fxios/")) return "Firefox";
|
|
535
|
-
if (ua.includes("chrome/") || ua.includes("crios/")) return "Chrome";
|
|
536
|
-
if (ua.includes("safari/")) return "Safari";
|
|
537
|
-
return "";
|
|
538
|
-
};
|
|
539
|
-
const detectOs = (ua) => {
|
|
540
|
-
if (ua.includes("android")) return "Android";
|
|
541
|
-
if (ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod")) return "iOS";
|
|
542
|
-
if (ua.includes("windows")) return "Windows";
|
|
543
|
-
if (ua.includes("cros")) return "ChromeOS";
|
|
544
|
-
if (ua.includes("mac os x") || ua.includes("macintosh")) return "macOS";
|
|
545
|
-
if (ua.includes("linux") || ua.includes("x11")) return "Linux";
|
|
546
|
-
return "";
|
|
547
|
-
};
|
|
548
|
-
const DESKTOP_OPERATING_SYSTEMS = /* @__PURE__ */ new Set(["Windows", "macOS", "Linux", "ChromeOS"]);
|
|
549
|
-
function parseUserAgent(userAgent) {
|
|
550
|
-
const raw = typeof userAgent === "string" ? userAgent.trim() : "";
|
|
551
|
-
if (!raw || raw.toLowerCase() === "unknown") {
|
|
552
|
-
return { deviceType: "", device: "", deviceIcon: "unknown", browser: "", os: "" };
|
|
553
|
-
}
|
|
554
|
-
const ua = raw.toLowerCase();
|
|
555
|
-
const runtime = RUNTIME_AGENTS[ua.split("/")[0]];
|
|
556
|
-
if (runtime && !ua.includes(" ")) {
|
|
557
|
-
return {
|
|
558
|
-
deviceType: "api",
|
|
559
|
-
device: LEGACY_DEVICE_LABELS.api,
|
|
560
|
-
deviceIcon: "api",
|
|
561
|
-
browser: runtime,
|
|
562
|
-
os: ""
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
const apiClient = API_CLIENTS.find(([needle]) => ua.includes(needle));
|
|
566
|
-
if (apiClient) {
|
|
567
|
-
return {
|
|
568
|
-
deviceType: "api",
|
|
569
|
-
device: LEGACY_DEVICE_LABELS.api,
|
|
570
|
-
deviceIcon: "api",
|
|
571
|
-
browser: apiClient[1],
|
|
572
|
-
os: detectOs(ua)
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
const browser = detectBrowser(ua);
|
|
576
|
-
const os = detectOs(ua);
|
|
577
|
-
let deviceType = "";
|
|
578
|
-
if (BOT_PATTERN.test(raw)) deviceType = "bot";
|
|
579
|
-
else if (TABLET_PATTERN.test(raw)) deviceType = "tablet";
|
|
580
|
-
else if (MOBILE_PATTERN.test(raw)) deviceType = "mobile";
|
|
581
|
-
else if (DESKTOP_OPERATING_SYSTEMS.has(os)) deviceType = "desktop";
|
|
582
|
-
return {
|
|
583
|
-
deviceType,
|
|
584
|
-
device: LEGACY_DEVICE_LABELS[deviceType],
|
|
585
|
-
deviceIcon: deviceType || "unknown",
|
|
586
|
-
browser,
|
|
587
|
-
os
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
const BROWSER_VERSION_PATTERNS = [
|
|
591
|
-
/\bEdg(?:A|iOS)?\/([\d.]+)/i,
|
|
592
|
-
/\bOPR\/([\d.]+)/i,
|
|
593
|
-
/\b(?:Chrome|CriOS)\/([\d.]+)/i,
|
|
594
|
-
/\bFirefox\/([\d.]+)/i,
|
|
595
|
-
/\bVersion\/([\d.]+).*Safari/i
|
|
596
|
-
];
|
|
597
|
-
function getBrowserVersionFromUserAgent(userAgent) {
|
|
598
|
-
if (typeof userAgent !== "string" || !userAgent.trim() || userAgent.trim().toLowerCase() === "unknown") {
|
|
599
|
-
return "";
|
|
600
|
-
}
|
|
601
|
-
for (const pattern of BROWSER_VERSION_PATTERNS) {
|
|
602
|
-
const match = userAgent.match(pattern);
|
|
603
|
-
if (match?.[1]) return match[1];
|
|
604
|
-
}
|
|
605
|
-
return "";
|
|
606
|
-
}
|
|
607
|
-
const DEVICE_TYPE_MESSAGES = Object.freeze({
|
|
608
|
-
desktop: Object.freeze({ messageId: "common.device.type.desktop", defaultMessage: "Desktop" }),
|
|
609
|
-
mobile: Object.freeze({ messageId: "common.device.type.mobile", defaultMessage: "Mobile" }),
|
|
610
|
-
tablet: Object.freeze({ messageId: "common.device.type.tablet", defaultMessage: "Tablet" }),
|
|
611
|
-
api: Object.freeze({ messageId: "common.device.type.api", defaultMessage: "API client" }),
|
|
612
|
-
bot: Object.freeze({ messageId: "common.device.type.bot", defaultMessage: "Bot" }),
|
|
613
|
-
unknown: Object.freeze({
|
|
614
|
-
messageId: "common.device.type.unknown",
|
|
615
|
-
defaultMessage: "Unknown device"
|
|
616
|
-
})
|
|
617
|
-
});
|
|
618
|
-
const DEVICE_SUMMARY_MESSAGE = Object.freeze({
|
|
619
|
-
messageId: "common.device.summary",
|
|
620
|
-
defaultMessage: "{browser} · {os}"
|
|
621
|
-
});
|
|
622
|
-
const DEVICE_TYPE_ALIASES = Object.freeze({
|
|
623
|
-
desktop: "desktop",
|
|
624
|
-
laptop: "desktop",
|
|
625
|
-
pc: "desktop",
|
|
626
|
-
computer: "desktop",
|
|
627
|
-
mobile: "mobile",
|
|
628
|
-
phone: "mobile",
|
|
629
|
-
smartphone: "mobile",
|
|
630
|
-
tablet: "tablet",
|
|
631
|
-
"api client": "api",
|
|
632
|
-
api: "api",
|
|
633
|
-
apiclient: "api",
|
|
634
|
-
bot: "bot",
|
|
635
|
-
crawler: "bot"
|
|
636
|
-
});
|
|
637
|
-
function normalizeDeviceType(value) {
|
|
638
|
-
if (typeof value !== "string") return "";
|
|
639
|
-
const key = value.trim().toLowerCase().replace(/[\s_-]+/g, " ");
|
|
640
|
-
return DEVICE_TYPE_ALIASES[key] || DEVICE_TYPE_ALIASES[key.replace(/ /g, "")] || "";
|
|
641
|
-
}
|
|
642
|
-
function getDeviceTypeMessage(deviceType) {
|
|
643
|
-
return DEVICE_TYPE_MESSAGES[deviceType] || DEVICE_TYPE_MESSAGES.unknown;
|
|
644
|
-
}
|
|
645
|
-
const TRAILING_VERSION = /\s+v?\d[\w./-]*$/i;
|
|
646
|
-
function splitNameAndVersion(value) {
|
|
647
|
-
let name2 = presentText(value);
|
|
648
|
-
const versions = [];
|
|
649
|
-
while (TRAILING_VERSION.test(name2)) {
|
|
650
|
-
const match = name2.match(TRAILING_VERSION);
|
|
651
|
-
versions.unshift(match[0].trim());
|
|
652
|
-
name2 = name2.slice(0, match.index).trim();
|
|
653
|
-
}
|
|
654
|
-
return { name: presentText(name2), version: versions.join(" ") };
|
|
655
|
-
}
|
|
656
|
-
function getDevicePresentation(session = {}) {
|
|
657
|
-
const row = session || {};
|
|
658
|
-
const userAgent = presentText(row.userAgent);
|
|
659
|
-
const parsed = userAgent ? parseUserAgent(userAgent) : null;
|
|
660
|
-
const storedBrowser = splitNameAndVersion(row.browserName);
|
|
661
|
-
const storedOs = splitNameAndVersion(row.osName);
|
|
662
|
-
const deviceType = parsed ? parsed.deviceType : normalizeDeviceType(row.deviceType);
|
|
663
|
-
const browser = parsed?.browser || storedBrowser.name;
|
|
664
|
-
const os = parsed?.os || storedOs.name;
|
|
665
|
-
const browserVersion = userAgent && getBrowserVersionFromUserAgent(userAgent) || presentText(row.browserVersion) || storedBrowser.version;
|
|
666
|
-
let summary = { text: "" };
|
|
667
|
-
if (browser && os) {
|
|
668
|
-
summary = { ...DEVICE_SUMMARY_MESSAGE, values: { browser, os } };
|
|
669
|
-
} else if (browser || os) {
|
|
670
|
-
summary = { text: browser || os };
|
|
671
|
-
}
|
|
672
|
-
return {
|
|
673
|
-
deviceType,
|
|
674
|
-
hasDeviceType: Boolean(deviceType),
|
|
675
|
-
icon: deviceType || "unknown",
|
|
676
|
-
deviceTypeMessage: getDeviceTypeMessage(deviceType),
|
|
677
|
-
browser,
|
|
678
|
-
browserVersion,
|
|
679
|
-
browserLabel: browser,
|
|
680
|
-
os,
|
|
681
|
-
hasSummary: Boolean(browser || os),
|
|
682
|
-
summary
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
const SESSION_STATES = Object.freeze(["active", "idle", "ended"]);
|
|
686
|
-
const SESSION_END_REASONS = Object.freeze([
|
|
687
|
-
"logout",
|
|
688
|
-
"idle",
|
|
689
|
-
"expired",
|
|
690
|
-
"manual",
|
|
691
|
-
"blocked",
|
|
692
|
-
"unrecorded"
|
|
693
|
-
]);
|
|
694
|
-
const RECORDED_END_REASONS = /* @__PURE__ */ new Set(["logout", "idle", "expired", "manual", "blocked"]);
|
|
695
|
-
const ACTIVE_DEFINITION = Object.freeze({
|
|
696
|
-
messageId: "common.status.active.definition",
|
|
697
|
-
defaultMessage: "Open and used within the inactivity timeout."
|
|
698
|
-
});
|
|
699
|
-
const SESSION_STATUS_PRESENTATION = Object.freeze({
|
|
700
|
-
active: Object.freeze({
|
|
701
|
-
tone: "success",
|
|
702
|
-
messageId: "common.status.active",
|
|
703
|
-
defaultMessage: "Active",
|
|
704
|
-
// B.3 tooltip and A.3 definition are the same sentence: one message.
|
|
705
|
-
help: ACTIVE_DEFINITION,
|
|
706
|
-
definition: ACTIVE_DEFINITION
|
|
707
|
-
}),
|
|
708
|
-
idle: Object.freeze({
|
|
709
|
-
tone: "warning",
|
|
710
|
-
messageId: "common.status.idle",
|
|
711
|
-
defaultMessage: "Idle",
|
|
712
|
-
help: Object.freeze({
|
|
713
|
-
messageId: "common.status.idle.help",
|
|
714
|
-
defaultMessage: "Still open. It ends on its next request or at the next idle check. A token refresh makes it active again."
|
|
715
|
-
}),
|
|
716
|
-
definition: Object.freeze({
|
|
717
|
-
messageId: "common.status.idle.definition",
|
|
718
|
-
defaultMessage: "Open, but not used for longer than the inactivity timeout. It ends on its next request or at the next idle check. A token refresh makes it active again."
|
|
719
|
-
})
|
|
720
|
-
}),
|
|
721
|
-
ended: Object.freeze({
|
|
722
|
-
tone: "neutral",
|
|
723
|
-
messageId: "common.status.ended",
|
|
724
|
-
defaultMessage: "Ended",
|
|
725
|
-
help: null,
|
|
726
|
-
definition: Object.freeze({
|
|
727
|
-
messageId: "common.status.ended.definition",
|
|
728
|
-
defaultMessage: "The session can no longer be used. The user has to sign in again on this device."
|
|
729
|
-
})
|
|
730
|
-
})
|
|
731
|
-
});
|
|
732
|
-
const SESSION_END_REASON_PRESENTATION = Object.freeze({
|
|
733
|
-
logout: Object.freeze({
|
|
734
|
-
messageId: "common.endReason.logout",
|
|
735
|
-
defaultMessage: "Logged out",
|
|
736
|
-
description: Object.freeze({
|
|
737
|
-
messageId: "common.endReason.logout.description",
|
|
738
|
-
defaultMessage: "The user signed out."
|
|
739
|
-
})
|
|
740
|
-
}),
|
|
741
|
-
idle: Object.freeze({
|
|
742
|
-
messageId: "common.endReason.idle",
|
|
743
|
-
defaultMessage: "Timed out",
|
|
744
|
-
description: Object.freeze({
|
|
745
|
-
messageId: "common.endReason.idle.description",
|
|
746
|
-
defaultMessage: "Not used for longer than the inactivity timeout."
|
|
747
|
-
})
|
|
748
|
-
}),
|
|
749
|
-
expired: Object.freeze({
|
|
750
|
-
messageId: "common.endReason.expired",
|
|
751
|
-
defaultMessage: "Expired",
|
|
752
|
-
description: Object.freeze({
|
|
753
|
-
messageId: "common.endReason.expired.description",
|
|
754
|
-
defaultMessage: "Reached the maximum session age."
|
|
755
|
-
})
|
|
756
|
-
}),
|
|
757
|
-
manual: Object.freeze({
|
|
758
|
-
messageId: "common.endReason.manual",
|
|
759
|
-
defaultMessage: "Ended manually",
|
|
760
|
-
description: Object.freeze({
|
|
761
|
-
messageId: "common.endReason.manual.description",
|
|
762
|
-
defaultMessage: "Ended from the Strapi admin, or by the user from another of their devices."
|
|
763
|
-
})
|
|
764
|
-
}),
|
|
765
|
-
blocked: Object.freeze({
|
|
766
|
-
messageId: "common.endReason.blocked",
|
|
767
|
-
defaultMessage: "User blocked",
|
|
768
|
-
description: Object.freeze({
|
|
769
|
-
messageId: "common.endReason.blocked.description",
|
|
770
|
-
defaultMessage: "Ended because the user account was blocked."
|
|
771
|
-
})
|
|
772
|
-
}),
|
|
773
|
-
unrecorded: Object.freeze({
|
|
774
|
-
messageId: "common.endReason.unrecorded",
|
|
775
|
-
defaultMessage: "Reason not recorded",
|
|
776
|
-
description: Object.freeze({
|
|
777
|
-
messageId: "common.endReason.unrecorded.description",
|
|
778
|
-
defaultMessage: "No end reason was stored, for example because the session ended in Strapi’s own session store or was recorded by an older plugin version."
|
|
779
|
-
})
|
|
780
|
-
})
|
|
781
|
-
});
|
|
782
|
-
function getSessionState(session = {}) {
|
|
783
|
-
const row = session || {};
|
|
784
|
-
if (row.isActive === true) return row.isTrulyActive ? "active" : "idle";
|
|
785
|
-
return "ended";
|
|
786
|
-
}
|
|
787
|
-
function getSessionStatus(session = {}) {
|
|
788
|
-
return getSessionState(session);
|
|
789
|
-
}
|
|
790
|
-
function getSessionEndReason(session = {}) {
|
|
791
|
-
const row = session || {};
|
|
792
|
-
if (row.isActive === true) return null;
|
|
793
|
-
const reason = typeof row.terminationReason === "string" ? row.terminationReason.trim().toLowerCase() : "";
|
|
794
|
-
return RECORDED_END_REASONS.has(reason) ? (
|
|
795
|
-
/** @type {any} */
|
|
796
|
-
reason
|
|
797
|
-
) : "unrecorded";
|
|
798
|
-
}
|
|
799
|
-
function isNativeOnlySession(session) {
|
|
800
|
-
const id = session?.id;
|
|
801
|
-
return typeof id === "string" && id.startsWith("native_");
|
|
802
|
-
}
|
|
803
|
-
function isSessionStatus(status) {
|
|
804
|
-
return SESSION_STATES.includes(
|
|
805
|
-
/** @type {any} */
|
|
806
|
-
status
|
|
807
|
-
);
|
|
808
|
-
}
|
|
809
|
-
function isSessionEndReason(reason) {
|
|
810
|
-
return SESSION_END_REASONS.includes(
|
|
811
|
-
/** @type {any} */
|
|
812
|
-
reason
|
|
813
|
-
);
|
|
814
|
-
}
|
|
815
|
-
function getSessionStatusPresentation(statusOrSession) {
|
|
816
|
-
const status = typeof statusOrSession === "string" ? statusOrSession : getSessionState(statusOrSession);
|
|
817
|
-
const key = isSessionStatus(status) ? status : "ended";
|
|
818
|
-
return { status: key, ...SESSION_STATUS_PRESENTATION[key] };
|
|
819
|
-
}
|
|
820
|
-
function getEndReasonPresentation(reason) {
|
|
821
|
-
const key = isSessionEndReason(reason) ? reason : "unrecorded";
|
|
822
|
-
return { reason: key, ...SESSION_END_REASON_PRESENTATION[key] };
|
|
823
|
-
}
|
|
824
|
-
function getSessionEndReasonPresentation(session) {
|
|
825
|
-
const reason = getSessionEndReason(session);
|
|
826
|
-
return reason ? getEndReasonPresentation(reason) : null;
|
|
827
|
-
}
|
|
828
|
-
function useSessionFormatters() {
|
|
829
|
-
const { formatMessage, locale } = useIntl();
|
|
830
|
-
const translate = useCallback(
|
|
831
|
-
(descriptor, values) => formatMessage(
|
|
832
|
-
{ id: getTranslation(descriptor.messageId), defaultMessage: descriptor.defaultMessage },
|
|
833
|
-
values
|
|
834
|
-
),
|
|
835
|
-
[formatMessage]
|
|
836
|
-
);
|
|
837
|
-
return useMemo(() => {
|
|
838
|
-
const formatDate = (value, options) => formatSessionDate(value, locale, MISSING_VALUE_GLYPH, options);
|
|
839
|
-
const formatRelativeTime = (value, now) => formatRelative(value, locale, { now: now ?? Date.now(), fallback: MISSING_VALUE_GLYPH });
|
|
840
|
-
const statusLabel = (statusOrSession) => translate(getSessionStatusPresentation(statusOrSession));
|
|
841
|
-
const endReasonLabel = (sessionOrReason) => {
|
|
842
|
-
const reason = typeof sessionOrReason === "string" ? getEndReasonPresentation(sessionOrReason) : getSessionEndReasonPresentation(sessionOrReason);
|
|
843
|
-
return reason ? translate(reason) : "";
|
|
844
|
-
};
|
|
845
|
-
const deviceTypeLabel = (session) => translate(getDevicePresentation(session).deviceTypeMessage);
|
|
846
|
-
const deviceSummary = (session) => {
|
|
847
|
-
const { summary } = getDevicePresentation(session);
|
|
848
|
-
return summary.text ?? translate(summary, summary.values);
|
|
849
|
-
};
|
|
850
|
-
return {
|
|
851
|
-
locale,
|
|
852
|
-
formatDate,
|
|
853
|
-
formatRelativeTime,
|
|
854
|
-
translate,
|
|
855
|
-
statusLabel,
|
|
856
|
-
endReasonLabel,
|
|
857
|
-
deviceTypeLabel,
|
|
858
|
-
deviceSummary
|
|
859
|
-
};
|
|
860
|
-
}, [locale, translate]);
|
|
861
|
-
}
|
|
862
|
-
const NoWrap = styled.span`
|
|
863
|
-
white-space: nowrap;
|
|
864
|
-
`;
|
|
865
|
-
const StatusDetail = ({ session, status }) => {
|
|
866
|
-
const { formatMessage } = useIntl();
|
|
867
|
-
const { formatDate, formatRelativeTime, endReasonLabel } = useSessionFormatters();
|
|
868
|
-
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
869
|
-
let text;
|
|
870
|
-
if (status === "ended") {
|
|
871
|
-
const endedAt = toValidDate(session.logoutTime);
|
|
872
|
-
text = t("common.status.ended.detail", "{reason} · {endedAt}", {
|
|
873
|
-
reason: /* @__PURE__ */ jsx(NoWrap, { children: endReasonLabel(session) }, "reason"),
|
|
874
|
-
endedAt: endedAt ? /* @__PURE__ */ jsx(NoWrap, { children: formatDate(endedAt) }, "ended-at") : /* @__PURE__ */ jsx(MissingValue, { variant: "pi" }, "ended-at")
|
|
875
|
-
});
|
|
876
|
-
} else {
|
|
877
|
-
const minutes = Number(session.minutesSinceActive);
|
|
878
|
-
const hasMinutes = session.minutesSinceActive !== null && session.minutesSinceActive !== void 0 && Number.isFinite(minutes);
|
|
879
|
-
text = status === "idle" && hasMinutes ? t("common.status.idle.detail", "Not used for {minutes} min", { minutes }) : t("common.status.active.detail", "Last active {time}", {
|
|
880
|
-
time: formatRelativeTime(session.lastActive || session.loginTime)
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
return /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", "data-status-detail": "", children: text });
|
|
884
|
-
};
|
|
885
|
-
const getBadgeColors = (tone) => tone === "warning" ? { backgroundColor: "warning200", textColor: "neutral800" } : { variant: tone };
|
|
886
|
-
const StatusBadge = ({ status, session, detail = false, showEndReason = false, size = "M" }) => {
|
|
887
|
-
const { formatMessage } = useIntl();
|
|
888
|
-
const presentation = getSessionStatusPresentation(status || session || {});
|
|
889
|
-
const translate = (descriptor) => formatMessage({
|
|
890
|
-
id: getTranslation(descriptor.messageId),
|
|
891
|
-
defaultMessage: descriptor.defaultMessage
|
|
892
|
-
});
|
|
893
|
-
const label = translate(presentation);
|
|
894
|
-
const badge = /* @__PURE__ */ jsx(
|
|
895
|
-
Badge,
|
|
896
|
-
{
|
|
897
|
-
...getBadgeColors(presentation.tone),
|
|
898
|
-
size,
|
|
899
|
-
"data-session-status": presentation.status,
|
|
900
|
-
children: label
|
|
901
|
-
}
|
|
902
|
-
);
|
|
903
|
-
if (!(detail || showEndReason) || !session) return badge;
|
|
904
|
-
const reason = presentation.status === "ended" ? getSessionEndReasonPresentation(session) : null;
|
|
905
|
-
const help = reason ? reason.description : presentation.help;
|
|
906
|
-
const native = isNativeOnlySession(session);
|
|
907
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
|
|
908
|
-
/* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", wrap: "wrap", children: [
|
|
909
|
-
help ? /* @__PURE__ */ jsx(Tooltip, { label: translate(help), children: /* @__PURE__ */ jsx("span", { children: badge }) }) : badge,
|
|
910
|
-
native ? /* @__PURE__ */ jsx(
|
|
911
|
-
Tooltip,
|
|
912
|
-
{
|
|
913
|
-
label: formatMessage({
|
|
914
|
-
id: getTranslation("common.status.nativeSession.help"),
|
|
915
|
-
defaultMessage: "Created by Strapi’s own session store. No device or location details were recorded."
|
|
916
|
-
}),
|
|
917
|
-
children: /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(Badge, { variant: "neutral", size, "data-native-session": "", children: formatMessage({
|
|
918
|
-
id: getTranslation("common.status.nativeSession"),
|
|
919
|
-
defaultMessage: "Strapi session"
|
|
920
|
-
}) }) })
|
|
921
|
-
}
|
|
922
|
-
) : null
|
|
923
|
-
] }),
|
|
924
|
-
/* @__PURE__ */ jsx(StatusDetail, { session, status: presentation.status })
|
|
925
|
-
] });
|
|
926
|
-
};
|
|
927
|
-
const canTakeFocus = (element) => Boolean(
|
|
928
|
-
element?.isConnected && typeof element.focus === "function" && !element.disabled && element.getAttribute?.("aria-disabled") !== "true"
|
|
929
|
-
);
|
|
930
|
-
function pickFocusTarget(opener, fallback) {
|
|
931
|
-
if (canTakeFocus(opener)) return opener;
|
|
932
|
-
return canTakeFocus(fallback) ? fallback : null;
|
|
933
|
-
}
|
|
934
|
-
function restoreDialogFocus(event, opener, fallback) {
|
|
935
|
-
const target = pickFocusTarget(opener, fallback);
|
|
936
|
-
if (!target) return;
|
|
937
|
-
event.preventDefault();
|
|
938
|
-
target.focus();
|
|
939
|
-
}
|
|
940
|
-
function refocusIfLost(opener, fallback, doc = typeof document === "undefined" ? void 0 : document) {
|
|
941
|
-
if (!doc) return;
|
|
942
|
-
const active = doc.activeElement;
|
|
943
|
-
if (active && active !== doc.body) return;
|
|
944
|
-
pickFocusTarget(opener, fallback)?.focus();
|
|
945
|
-
}
|
|
946
|
-
const ConfirmAction = ({
|
|
947
|
-
trigger,
|
|
948
|
-
title,
|
|
949
|
-
body,
|
|
950
|
-
confirmLabel,
|
|
951
|
-
onConfirm,
|
|
952
|
-
variant = "danger",
|
|
953
|
-
disabled = false,
|
|
954
|
-
fallbackFocusRef,
|
|
955
|
-
isOpen,
|
|
956
|
-
onOpenChange,
|
|
957
|
-
returnFocusRef
|
|
958
|
-
}) => {
|
|
959
|
-
const [internalOpen, setInternalOpen] = useState(false);
|
|
960
|
-
const [busy, setBusy] = useState(false);
|
|
961
|
-
const triggerRef = useRef(null);
|
|
962
|
-
const controlled = !trigger;
|
|
963
|
-
const open = controlled ? Boolean(isOpen) : internalOpen;
|
|
964
|
-
const restoreFocus = () => {
|
|
965
|
-
if (typeof window === "undefined") return;
|
|
966
|
-
window.requestAnimationFrame(() => {
|
|
967
|
-
const active = document.activeElement;
|
|
968
|
-
if (active && active !== document.body) return;
|
|
969
|
-
const ownTrigger = controlled ? returnFocusRef?.current : triggerRef.current;
|
|
970
|
-
const target = pickFocusTarget(ownTrigger, fallbackFocusRef?.current);
|
|
971
|
-
if (target) target.focus();
|
|
972
|
-
});
|
|
973
|
-
};
|
|
974
|
-
const setOpen = (next) => {
|
|
975
|
-
if (controlled) onOpenChange?.(next);
|
|
976
|
-
else setInternalOpen(next);
|
|
977
|
-
};
|
|
978
|
-
const handleOpenChange = (next) => {
|
|
979
|
-
if (busy) return;
|
|
980
|
-
setOpen(next);
|
|
981
|
-
if (!next) restoreFocus();
|
|
982
|
-
};
|
|
983
|
-
const handleConfirm = async (event) => {
|
|
984
|
-
event?.preventDefault?.();
|
|
985
|
-
setBusy(true);
|
|
986
|
-
try {
|
|
987
|
-
await onConfirm();
|
|
988
|
-
setOpen(false);
|
|
989
|
-
restoreFocus();
|
|
990
|
-
} catch {
|
|
991
|
-
} finally {
|
|
992
|
-
setBusy(false);
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
return /* @__PURE__ */ jsxs(Dialog.Root, { open, onOpenChange: handleOpenChange, children: [
|
|
996
|
-
trigger ? /* @__PURE__ */ jsx(Dialog.Trigger, { ref: triggerRef, disabled, children: trigger }) : null,
|
|
997
|
-
/* @__PURE__ */ jsx(
|
|
998
|
-
ConfirmDialog,
|
|
999
|
-
{
|
|
1000
|
-
title,
|
|
1001
|
-
variant,
|
|
1002
|
-
endAction: /* @__PURE__ */ jsx(
|
|
1003
|
-
Button,
|
|
1004
|
-
{
|
|
1005
|
-
fullWidth: true,
|
|
1006
|
-
variant,
|
|
1007
|
-
onClick: handleConfirm,
|
|
1008
|
-
loading: busy,
|
|
1009
|
-
disabled: busy,
|
|
1010
|
-
children: confirmLabel
|
|
1011
|
-
}
|
|
1012
|
-
),
|
|
1013
|
-
children: body
|
|
1014
|
-
}
|
|
1015
|
-
)
|
|
1016
|
-
] });
|
|
1017
|
-
};
|
|
1018
|
-
const DEVICE_ICONS = {
|
|
1019
|
-
desktop: Monitor,
|
|
1020
|
-
mobile: Phone,
|
|
1021
|
-
tablet: Phone,
|
|
1022
|
-
api: Code,
|
|
1023
|
-
bot: Server,
|
|
1024
|
-
unknown: Information
|
|
1025
|
-
};
|
|
1026
|
-
const DeviceIcon = ({ icon }) => {
|
|
1027
|
-
const Icon = DEVICE_ICONS[icon] || Information;
|
|
1028
|
-
return /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, focusable: false });
|
|
1029
|
-
};
|
|
1030
|
-
const TargetLink = styled(Link)`
|
|
1031
|
-
min-height: 3.2rem;
|
|
1032
|
-
display: inline-flex;
|
|
1033
|
-
align-items: center;
|
|
1034
|
-
align-self: flex-start;
|
|
1035
|
-
`;
|
|
1036
|
-
const ActionStack = styled.div`
|
|
1037
|
-
display: grid;
|
|
1038
|
-
grid-template-columns: minmax(0, 1fr);
|
|
1039
|
-
grid-auto-rows: 1fr;
|
|
1040
|
-
gap: ${({ theme }) => theme.spaces[2]};
|
|
1041
|
-
min-width: 0;
|
|
1042
|
-
|
|
1043
|
-
/* The buttons are the plugin's own children; wrapped labels centre
|
|
1044
|
-
through inheritance, not through a selector into the DS button. */
|
|
1045
|
-
& > button {
|
|
1046
|
-
height: auto;
|
|
1047
|
-
min-height: 3.2rem;
|
|
1048
|
-
padding-block: ${({ theme }) => theme.spaces[1]};
|
|
1049
|
-
text-align: center;
|
|
1050
|
-
}
|
|
1051
|
-
`;
|
|
1052
|
-
const pluginPermissions = {
|
|
1053
|
-
access: [{ action: `plugin::${pluginId}.access`, subject: null }],
|
|
1054
|
-
/** Strapi admin panel sessions (view). The server also requires `access`. */
|
|
1055
|
-
adminSessionsRead: [{ action: `plugin::${pluginId}.admin-sessions.read`, subject: null }],
|
|
1056
|
-
/** Signing admins out. The server also requires `access` and `admin-sessions.read`. */
|
|
1057
|
-
adminSessionsRevoke: [{ action: `plugin::${pluginId}.admin-sessions.revoke`, subject: null }],
|
|
1058
|
-
/** Admin sign-in history and Content Manager activity. The server also requires `access` and `admin-sessions.read`. */
|
|
1059
|
-
adminActivityRead: [{ action: `plugin::${pluginId}.admin-activity.read`, subject: null }],
|
|
1060
|
-
/**
|
|
1061
|
-
* Protected settings (4.17): location lookup, webhooks and the security log.
|
|
1062
|
-
* The server also requires `access` (and `admin-activity.read` for the log).
|
|
1063
|
-
*/
|
|
1064
|
-
settingsUpdate: [{ action: `plugin::${pluginId}.settings.update`, subject: null }],
|
|
1065
|
-
/** Lifting a sign-in lock. The server also requires `access`. */
|
|
1066
|
-
lockoutsUnlock: [{ action: `plugin::${pluginId}.lockouts.unlock`, subject: null }],
|
|
1067
|
-
/**
|
|
1068
|
-
* Impersonating app users (4.20): start, list and end. The server also
|
|
1069
|
-
* requires `access` and the Impersonation switch.
|
|
1070
|
-
*/
|
|
1071
|
-
impersonateUsers: [{ action: `plugin::${pluginId}.impersonate.users`, subject: null }],
|
|
1072
|
-
/**
|
|
1073
|
-
* "View as admin" (4.20): the read-only permission preview of another
|
|
1074
|
-
* admin. The server also requires `access`, the switch and the
|
|
1075
|
-
* anti-escalation rules.
|
|
1076
|
-
*/
|
|
1077
|
-
impersonateAdmins: [{ action: `plugin::${pluginId}.impersonate.admins`, subject: null }]
|
|
1078
|
-
};
|
|
1079
|
-
const SAFE_SCOPE = /^[A-Za-z0-9_.:-]{1,48}$/;
|
|
1080
|
-
const CANCEL_NAMES = /* @__PURE__ */ new Set(["AbortError", "TimeoutError", "CanceledError"]);
|
|
1081
|
-
function safeGet(value, key) {
|
|
1082
|
-
try {
|
|
1083
|
-
return value && typeof value === "object" ? value[key] : void 0;
|
|
1084
|
-
} catch {
|
|
1085
|
-
return void 0;
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
function isCancelledRequest(error) {
|
|
1089
|
-
const name2 = safeGet(error, "name");
|
|
1090
|
-
return typeof name2 === "string" && CANCEL_NAMES.has(name2);
|
|
1091
|
-
}
|
|
1092
|
-
function logSafeAdminError(scope, error) {
|
|
1093
|
-
if (isCancelledRequest(error)) return;
|
|
1094
|
-
const safeScope = typeof scope === "string" && SAFE_SCOPE.test(scope) ? scope : "admin";
|
|
1095
|
-
const directStatus = safeGet(error, "status");
|
|
1096
|
-
const status = Number.isInteger(directStatus) ? directStatus : safeGet(safeGet(error, "response"), "status");
|
|
1097
|
-
const statusSuffix = Number.isInteger(status) && status >= 400 && status <= 599 ? ` (HTTP ${status})` : "";
|
|
1098
|
-
console.warn(`[${safeScope}] Request failed${statusSuffix}`);
|
|
1099
|
-
}
|
|
1100
|
-
function useSettingsTranslate() {
|
|
1101
|
-
const { formatMessage, locale } = useIntl();
|
|
1102
|
-
const t = useCallback(
|
|
1103
|
-
(id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values),
|
|
1104
|
-
[formatMessage]
|
|
1105
|
-
);
|
|
1106
|
-
const tError = useCallback(
|
|
1107
|
-
(descriptor) => descriptor ? t(descriptor.messageId, descriptor.defaultMessage, descriptor.values) : void 0,
|
|
1108
|
-
[t]
|
|
1109
|
-
);
|
|
1110
|
-
return { t, tError, locale };
|
|
1111
|
-
}
|
|
1112
|
-
async function copyText(value, clipboard = globalThis.navigator?.clipboard) {
|
|
1113
|
-
if (typeof value !== "string") {
|
|
1114
|
-
throw new TypeError("clipboard_value_must_be_text");
|
|
1115
|
-
}
|
|
1116
|
-
if (!clipboard || typeof clipboard.writeText !== "function") {
|
|
1117
|
-
throw new Error("clipboard_unavailable");
|
|
1118
|
-
}
|
|
1119
|
-
await clipboard.writeText(value);
|
|
1120
|
-
}
|
|
1121
|
-
const USER_IMPERSONATION_DURATIONS = Object.freeze([15, 30, 60]);
|
|
1122
|
-
const DEFAULT_IMPERSONATION_MINUTES = 15;
|
|
1123
|
-
const REASON_MIN = 3;
|
|
1124
|
-
const REASON_MAX = 255;
|
|
1125
|
-
function validateReason(value) {
|
|
1126
|
-
const clean = typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
1127
|
-
if (clean.length < REASON_MIN) {
|
|
1128
|
-
return {
|
|
1129
|
-
messageId: "impersonation.reason.tooShort",
|
|
1130
|
-
defaultMessage: "Enter a reason of at least {min} characters.",
|
|
1131
|
-
values: { min: REASON_MIN }
|
|
1132
|
-
};
|
|
1133
|
-
}
|
|
1134
|
-
if (clean.length > REASON_MAX) {
|
|
1135
|
-
return {
|
|
1136
|
-
messageId: "impersonation.reason.tooLong",
|
|
1137
|
-
defaultMessage: "Use at most {max} characters.",
|
|
1138
|
-
values: { max: REASON_MAX }
|
|
1139
|
-
};
|
|
1140
|
-
}
|
|
1141
|
-
return null;
|
|
1142
|
-
}
|
|
1143
|
-
function secondsUntil(iso, now = Date.now()) {
|
|
1144
|
-
const end = Date.parse(String(iso ?? ""));
|
|
1145
|
-
if (!Number.isFinite(end)) return 0;
|
|
1146
|
-
return Math.max(0, Math.floor((end - now) / 1e3));
|
|
1147
|
-
}
|
|
1148
|
-
function formatClock(seconds) {
|
|
1149
|
-
const total = Math.max(0, Math.floor(Number(seconds) || 0));
|
|
1150
|
-
const hours = Math.floor(total / 3600);
|
|
1151
|
-
const minutes = Math.floor(total % 3600 / 60);
|
|
1152
|
-
const rest = String(total % 60).padStart(2, "0");
|
|
1153
|
-
return hours > 0 ? `${hours}:${String(minutes).padStart(2, "0")}:${rest}` : `${minutes}:${rest}`;
|
|
1154
|
-
}
|
|
1155
|
-
function submitFrontendHandoff(doc, handoff) {
|
|
1156
|
-
if (!doc || !handoff || typeof handoff.url !== "string" || typeof handoff.code !== "string") {
|
|
1157
|
-
return false;
|
|
1158
|
-
}
|
|
1159
|
-
let url;
|
|
1160
|
-
try {
|
|
1161
|
-
url = new URL(handoff.url);
|
|
1162
|
-
} catch {
|
|
1163
|
-
return false;
|
|
1164
|
-
}
|
|
1165
|
-
if (url.protocol !== "https:" && url.protocol !== "http:") return false;
|
|
1166
|
-
const form = doc.createElement("form");
|
|
1167
|
-
form.method = "POST";
|
|
1168
|
-
form.action = url.toString();
|
|
1169
|
-
form.target = "_blank";
|
|
1170
|
-
form.rel = "noopener noreferrer";
|
|
1171
|
-
form.style.display = "none";
|
|
1172
|
-
const input = doc.createElement("input");
|
|
1173
|
-
input.type = "hidden";
|
|
1174
|
-
input.name = typeof handoff.field === "string" && handoff.field ? handoff.field : "code";
|
|
1175
|
-
input.value = handoff.code;
|
|
1176
|
-
form.appendChild(input);
|
|
1177
|
-
doc.body.appendChild(form);
|
|
1178
|
-
try {
|
|
1179
|
-
form.submit();
|
|
1180
|
-
} finally {
|
|
1181
|
-
form.remove();
|
|
1182
|
-
}
|
|
1183
|
-
return true;
|
|
1184
|
-
}
|
|
1185
|
-
const dialogs = /* @__PURE__ */ new Map();
|
|
1186
|
-
const mounted = /* @__PURE__ */ new Map();
|
|
1187
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1188
|
-
const notify = () => {
|
|
1189
|
-
for (const listener of listeners) listener();
|
|
1190
|
-
};
|
|
1191
|
-
function subscribeImpersonationDialogs(listener) {
|
|
1192
|
-
listeners.add(listener);
|
|
1193
|
-
return () => listeners.delete(listener);
|
|
1194
|
-
}
|
|
1195
|
-
function getImpersonationDialog(key) {
|
|
1196
|
-
return dialogs.get(key) || null;
|
|
1197
|
-
}
|
|
1198
|
-
function registerImpersonationPanel(key, instance) {
|
|
1199
|
-
const list = [...mounted.get(key) || [], instance];
|
|
1200
|
-
mounted.set(key, list);
|
|
1201
|
-
const dialog = dialogs.get(key);
|
|
1202
|
-
if (dialog && (!dialog.owner || !list.includes(dialog.owner))) {
|
|
1203
|
-
dialogs.set(key, { ...dialog, owner: instance });
|
|
1204
|
-
notify();
|
|
1205
|
-
}
|
|
1206
|
-
return () => {
|
|
1207
|
-
const rest = (mounted.get(key) || []).filter((id) => id !== instance);
|
|
1208
|
-
if (rest.length) mounted.set(key, rest);
|
|
1209
|
-
else mounted.delete(key);
|
|
1210
|
-
const current = dialogs.get(key);
|
|
1211
|
-
if (current && current.owner === instance) {
|
|
1212
|
-
dialogs.set(key, { ...current, owner: rest[rest.length - 1] || null });
|
|
1213
|
-
notify();
|
|
1214
|
-
}
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
function openImpersonationDialog(key, instance) {
|
|
1218
|
-
dialogs.set(key, { open: true, owner: instance, draft: {} });
|
|
1219
|
-
notify();
|
|
1220
|
-
}
|
|
1221
|
-
function saveImpersonationDraft(key, draft) {
|
|
1222
|
-
const current = dialogs.get(key);
|
|
1223
|
-
if (current) dialogs.set(key, { ...current, draft });
|
|
1224
|
-
}
|
|
1225
|
-
function closeImpersonationDialog(key) {
|
|
1226
|
-
if (dialogs.delete(key)) notify();
|
|
1227
|
-
}
|
|
1228
|
-
const REFUSALS = Object.freeze({
|
|
1229
|
-
disabled: ["impersonation.error.disabled", "Impersonation is turned off in the settings."],
|
|
1230
|
-
"already-active": [
|
|
1231
|
-
"impersonation.error.alreadyActive",
|
|
1232
|
-
"An impersonation of this user is already running. End it first."
|
|
1233
|
-
],
|
|
1234
|
-
blocked: ["impersonation.error.blocked", "Blocked accounts cannot be impersonated."],
|
|
1235
|
-
"api-token": ["impersonation.error.apiToken", "API tokens cannot impersonate."]
|
|
1236
|
-
});
|
|
1237
|
-
function useSecondsLeft(expiresAt) {
|
|
1238
|
-
const [now, setNow] = useState(() => Date.now());
|
|
1239
|
-
useEffect(() => {
|
|
1240
|
-
if (!expiresAt) return void 0;
|
|
1241
|
-
const timer = window.setInterval(() => setNow(Date.now()), 1e3);
|
|
1242
|
-
return () => window.clearInterval(timer);
|
|
1243
|
-
}, [expiresAt]);
|
|
1244
|
-
return secondsUntil(expiresAt, now);
|
|
1245
|
-
}
|
|
1246
|
-
const SecretField = ({ label, value, name: name2 }) => {
|
|
1247
|
-
const { t } = useSettingsTranslate();
|
|
1248
|
-
const { toggleNotification } = useNotification();
|
|
1249
|
-
const copy = async () => {
|
|
1250
|
-
try {
|
|
1251
|
-
await copyText(value);
|
|
1252
|
-
toggleNotification({
|
|
1253
|
-
type: "success",
|
|
1254
|
-
message: t("impersonation.result.copied", "Copied to the clipboard.")
|
|
1255
|
-
});
|
|
1256
|
-
} catch {
|
|
1257
|
-
toggleNotification({
|
|
1258
|
-
type: "warning",
|
|
1259
|
-
message: t(
|
|
1260
|
-
"impersonation.result.copyFailed",
|
|
1261
|
-
"Copying failed. Select the text and copy it yourself."
|
|
1262
|
-
)
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
};
|
|
1266
|
-
return /* @__PURE__ */ jsxs(Field.Root, { name: name2, children: [
|
|
1267
|
-
/* @__PURE__ */ jsx(Field.Label, { children: label }),
|
|
1268
|
-
/* @__PURE__ */ jsx(
|
|
1269
|
-
TextInput,
|
|
1270
|
-
{
|
|
1271
|
-
value,
|
|
1272
|
-
readOnly: true,
|
|
1273
|
-
onFocus: (event) => event.target.select(),
|
|
1274
|
-
endAction: /* @__PURE__ */ jsx(
|
|
1275
|
-
Field.Action,
|
|
1276
|
-
{
|
|
1277
|
-
label: t("impersonation.result.copy", "Copy {name}", { name: label }),
|
|
1278
|
-
onClick: copy,
|
|
1279
|
-
children: /* @__PURE__ */ jsx(Duplicate, {})
|
|
1280
|
-
}
|
|
1281
|
-
)
|
|
1282
|
-
}
|
|
1283
|
-
)
|
|
1284
|
-
] });
|
|
1285
|
-
};
|
|
1286
|
-
const ImpersonateUserModal = ({
|
|
1287
|
-
open,
|
|
1288
|
-
onOpenChange,
|
|
1289
|
-
onCloseAutoFocus,
|
|
1290
|
-
user,
|
|
1291
|
-
status,
|
|
1292
|
-
onChanged
|
|
1293
|
-
}) => {
|
|
1294
|
-
const { t, tError } = useSettingsTranslate();
|
|
1295
|
-
const { post } = useFetchClient();
|
|
1296
|
-
const { toggleNotification } = useNotification();
|
|
1297
|
-
const notifyHintId = useId();
|
|
1298
|
-
const [saved] = useState(() => getImpersonationDialog(user.documentId)?.draft || {});
|
|
1299
|
-
const [reason, setReason] = useState(saved.reason ?? "");
|
|
1300
|
-
const [minutes, setMinutes] = useState(saved.minutes ?? DEFAULT_IMPERSONATION_MINUTES);
|
|
1301
|
-
const [notifyUser, setNotifyUser] = useState(saved.notifyUser === true);
|
|
1302
|
-
const [touched, setTouched] = useState(false);
|
|
1303
|
-
const [pending, setPending] = useState(null);
|
|
1304
|
-
const [failure, setFailure] = useState(null);
|
|
1305
|
-
const [result, setResult] = useState(saved.result ?? null);
|
|
1306
|
-
useEffect(() => {
|
|
1307
|
-
if (!open) return;
|
|
1308
|
-
saveImpersonationDraft(user.documentId, { reason, minutes, notifyUser, result });
|
|
1309
|
-
}, [open, user.documentId, reason, minutes, notifyUser, result]);
|
|
1310
|
-
const secondsLeft = useSecondsLeft(result?.impersonation?.expiresAt || null);
|
|
1311
|
-
const durations = Array.isArray(status?.durations) ? status.durations : USER_IMPERSONATION_DURATIONS;
|
|
1312
|
-
const reasonError = validateReason(reason);
|
|
1313
|
-
const showReasonError = touched && reasonError;
|
|
1314
|
-
const start = async () => {
|
|
1315
|
-
setTouched(true);
|
|
1316
|
-
if (reasonError) return;
|
|
1317
|
-
setPending("start");
|
|
1318
|
-
setFailure(null);
|
|
1319
|
-
try {
|
|
1320
|
-
const { data } = await post(
|
|
1321
|
-
`/${pluginId}/impersonation/users/${encodeURIComponent(user.documentId)}`,
|
|
1322
|
-
{ reason: reason.trim(), durationMinutes: minutes, notifyUser }
|
|
1323
|
-
);
|
|
1324
|
-
setResult(data?.data || null);
|
|
1325
|
-
onChanged?.();
|
|
1326
|
-
} catch (err) {
|
|
1327
|
-
if (isCancelledRequest(err)) return;
|
|
1328
|
-
const response = err?.response;
|
|
1329
|
-
const reasonCode = response?.data?.error?.details?.reason;
|
|
1330
|
-
if (response?.status === 429) {
|
|
1331
|
-
setFailure(
|
|
1332
|
-
t(
|
|
1333
|
-
"impersonation.error.rateLimited",
|
|
1334
|
-
"Too many impersonations were started. Try again in a few minutes."
|
|
1335
|
-
)
|
|
1336
|
-
);
|
|
1337
|
-
} else if (REFUSALS[reasonCode]) {
|
|
1338
|
-
setFailure(t(...REFUSALS[reasonCode]));
|
|
1339
|
-
} else {
|
|
1340
|
-
logSafeAdminError("impersonation.start", err);
|
|
1341
|
-
setFailure(t("impersonation.error.start", "The impersonation could not be started."));
|
|
1342
|
-
}
|
|
1343
|
-
} finally {
|
|
1344
|
-
setPending(null);
|
|
1345
|
-
}
|
|
1346
|
-
};
|
|
1347
|
-
const end = async () => {
|
|
1348
|
-
if (!result?.impersonation?.id) return;
|
|
1349
|
-
setPending("end");
|
|
1350
|
-
try {
|
|
1351
|
-
await post(`/${pluginId}/impersonation/${result.impersonation.id}/end`, {});
|
|
1352
|
-
toggleNotification({
|
|
1353
|
-
type: "success",
|
|
1354
|
-
message: t("impersonation.ended", "Impersonation ended.")
|
|
1355
|
-
});
|
|
1356
|
-
onChanged?.();
|
|
1357
|
-
onOpenChange(false);
|
|
1358
|
-
} catch (err) {
|
|
1359
|
-
logSafeAdminError("impersonation.end", err);
|
|
1360
|
-
toggleNotification({
|
|
1361
|
-
type: "danger",
|
|
1362
|
-
message: t("impersonation.error.end", "The impersonation could not be ended.")
|
|
1363
|
-
});
|
|
1364
|
-
} finally {
|
|
1365
|
-
setPending(null);
|
|
1366
|
-
}
|
|
1367
|
-
};
|
|
1368
|
-
const openFrontend = () => {
|
|
1369
|
-
setFailure(null);
|
|
1370
|
-
const onViolation = (event) => {
|
|
1371
|
-
if (String(event?.violatedDirective || "").startsWith("form-action")) {
|
|
1372
|
-
setFailure(
|
|
1373
|
-
t(
|
|
1374
|
-
"impersonation.error.csp",
|
|
1375
|
-
"Your Strapi security settings block sending the sign-in to {origin}. Add this origin to form-action of the Content-Security-Policy (see the README), then start again.",
|
|
1376
|
-
{ origin: status?.frontendOrigin || "" }
|
|
1377
|
-
)
|
|
1378
|
-
);
|
|
1379
|
-
}
|
|
1380
|
-
};
|
|
1381
|
-
document.addEventListener("securitypolicyviolation", onViolation);
|
|
1382
|
-
window.setTimeout(
|
|
1383
|
-
() => document.removeEventListener("securitypolicyviolation", onViolation),
|
|
1384
|
-
3e3
|
|
1385
|
-
);
|
|
1386
|
-
if (!submitFrontendHandoff(document, result?.handoff)) {
|
|
1387
|
-
setFailure(t("impersonation.error.frontend", "The frontend could not be opened."));
|
|
1388
|
-
}
|
|
1389
|
-
};
|
|
1390
|
-
const handoff = result?.handoff;
|
|
1391
|
-
const clock = formatClock(secondsLeft);
|
|
1392
|
-
return /* @__PURE__ */ jsx(Modal.Root, { open, onOpenChange, children: /* @__PURE__ */ jsxs(Modal.Content, { onCloseAutoFocus, "aria-describedby": void 0, children: [
|
|
1393
|
-
/* @__PURE__ */ jsx(Modal.Header, { closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsx(Modal.Title, { children: result ? t("impersonation.result.title", "Impersonating {user}", { user: user.label }) : t("impersonation.modal.title", "Impersonate {user}", { user: user.label }) }) }),
|
|
1394
|
-
/* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
1395
|
-
failure ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "danger", closeLabel: t("common.close", "Close"), children: failure }) : null,
|
|
1396
|
-
!result ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1397
|
-
/* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "p", children: t(
|
|
1398
|
-
"impersonation.modal.intro",
|
|
1399
|
-
"You get a short-lived sign-in as this user to reproduce a problem. Password, email address, account and sessions cannot be changed with it. It is recorded in the security log."
|
|
1400
|
-
) }),
|
|
1401
|
-
/* @__PURE__ */ jsxs(
|
|
1402
|
-
Field.Root,
|
|
1403
|
-
{
|
|
1404
|
-
name: "reason",
|
|
1405
|
-
required: true,
|
|
1406
|
-
error: showReasonError ? tError(reasonError) : void 0,
|
|
1407
|
-
hint: t(
|
|
1408
|
-
"impersonation.reason.hint",
|
|
1409
|
-
"Stored in the security log and, if you email the user, shown to them."
|
|
1410
|
-
),
|
|
1411
|
-
children: [
|
|
1412
|
-
/* @__PURE__ */ jsx(Field.Label, { children: t("impersonation.reason.label", "Reason") }),
|
|
1413
|
-
/* @__PURE__ */ jsx(
|
|
1414
|
-
Textarea,
|
|
1415
|
-
{
|
|
1416
|
-
value: reason,
|
|
1417
|
-
maxLength: REASON_MAX,
|
|
1418
|
-
placeholder: t("impersonation.reason.placeholder", "For example: ticket 4711"),
|
|
1419
|
-
onChange: (event) => setReason(event.target.value),
|
|
1420
|
-
onBlur: () => setTouched(true)
|
|
1421
|
-
}
|
|
1422
|
-
),
|
|
1423
|
-
/* @__PURE__ */ jsx(Field.Hint, {}),
|
|
1424
|
-
/* @__PURE__ */ jsx(Field.Error, {})
|
|
1425
|
-
]
|
|
1426
|
-
}
|
|
1427
|
-
),
|
|
1428
|
-
/* @__PURE__ */ jsxs(Field.Root, { name: "durationMinutes", children: [
|
|
1429
|
-
/* @__PURE__ */ jsx(Field.Label, { children: t("impersonation.duration.label", "Duration") }),
|
|
1430
|
-
/* @__PURE__ */ jsx(
|
|
1431
|
-
SingleSelect,
|
|
1432
|
-
{
|
|
1433
|
-
value: String(minutes),
|
|
1434
|
-
onChange: (value) => setMinutes(Number(value)),
|
|
1435
|
-
children: durations.map((value) => /* @__PURE__ */ jsx(SingleSelectOption, { value: String(value), children: t(
|
|
1436
|
-
"impersonation.duration.minutes",
|
|
1437
|
-
"{count, plural, one {# minute} other {# minutes}}",
|
|
1438
|
-
{
|
|
1439
|
-
count: value
|
|
1440
|
-
}
|
|
1441
|
-
) }, value))
|
|
1442
|
-
}
|
|
1443
|
-
)
|
|
1444
|
-
] }),
|
|
1445
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
1446
|
-
/* @__PURE__ */ jsx(
|
|
1447
|
-
Checkbox,
|
|
1448
|
-
{
|
|
1449
|
-
checked: notifyUser,
|
|
1450
|
-
"aria-describedby": notifyHintId,
|
|
1451
|
-
onCheckedChange: (checked) => setNotifyUser(checked === true),
|
|
1452
|
-
children: t(
|
|
1453
|
-
"impersonation.notify.label",
|
|
1454
|
-
"Email the user that their account was opened"
|
|
1455
|
-
)
|
|
1456
|
-
}
|
|
1457
|
-
),
|
|
1458
|
-
/* @__PURE__ */ jsx(Typography, { id: notifyHintId, variant: "pi", textColor: "neutral600", children: t(
|
|
1459
|
-
"impersonation.notify.hint",
|
|
1460
|
-
"Sent through Strapi’s email plugin, with the reason and the duration."
|
|
1461
|
-
) })
|
|
1462
|
-
] })
|
|
1463
|
-
] }) : null,
|
|
1464
|
-
handoff?.type === "frontend" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1465
|
-
/* @__PURE__ */ jsx(PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: t(
|
|
1466
|
-
"impersonation.result.frontendBody",
|
|
1467
|
-
"Open {origin} within one minute. The sign-in link works once and is sent without appearing in the address bar.",
|
|
1468
|
-
{ origin: status?.frontendOrigin || "" }
|
|
1469
|
-
) }),
|
|
1470
|
-
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Button, { startIcon: /* @__PURE__ */ jsx(ExternalLink, {}), onClick: openFrontend, children: t("impersonation.result.openFrontend", "Open frontend") }) })
|
|
1471
|
-
] }) : null,
|
|
1472
|
-
handoff?.type === "token" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1473
|
-
/* @__PURE__ */ jsx(PersistentAlert, { variant: "warning", closeLabel: t("common.close", "Close"), children: t(
|
|
1474
|
-
"impersonation.result.tokenBody",
|
|
1475
|
-
"Shown only once. Anyone who has this token acts as {user} until it ends. Do not store or share it.",
|
|
1476
|
-
{ user: user.label }
|
|
1477
|
-
) }),
|
|
1478
|
-
/* @__PURE__ */ jsx(
|
|
1479
|
-
SecretField,
|
|
1480
|
-
{
|
|
1481
|
-
name: "jwt",
|
|
1482
|
-
label: t("impersonation.result.accessToken", "Access token"),
|
|
1483
|
-
value: handoff.jwt
|
|
1484
|
-
}
|
|
1485
|
-
),
|
|
1486
|
-
handoff.refreshToken ? /* @__PURE__ */ jsx(
|
|
1487
|
-
SecretField,
|
|
1488
|
-
{
|
|
1489
|
-
name: "refreshToken",
|
|
1490
|
-
label: t("impersonation.result.refreshToken", "Refresh token"),
|
|
1491
|
-
value: handoff.refreshToken
|
|
1492
|
-
}
|
|
1493
|
-
) : null
|
|
1494
|
-
] }) : null,
|
|
1495
|
-
result ? /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", tag: "p", "aria-live": "polite", children: t("impersonation.result.endsIn", "Ends in {time}.", { time: clock }) }) : null
|
|
1496
|
-
] }) }),
|
|
1497
|
-
/* @__PURE__ */ jsx(Modal.Footer, { children: result ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1498
|
-
/* @__PURE__ */ jsx(Button, { variant: "danger-light", onClick: end, loading: pending === "end", children: t("impersonation.end", "End impersonation") }),
|
|
1499
|
-
/* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: t("impersonation.result.done", "Done") }) })
|
|
1500
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1501
|
-
/* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: t("common.cancel", "Cancel") }) }),
|
|
1502
|
-
/* @__PURE__ */ jsx(Button, { onClick: start, loading: pending === "start", children: t("impersonation.start", "Start impersonation") })
|
|
1503
|
-
] }) })
|
|
1504
|
-
] }) });
|
|
1505
|
-
};
|
|
1506
|
-
const focusVisibleTrigger = (documentId, fallback) => {
|
|
1507
|
-
const candidates = [
|
|
1508
|
-
...document.querySelectorAll(
|
|
1509
|
-
`[data-impersonation-trigger="${globalThis.CSS?.escape ? globalThis.CSS.escape(documentId) : documentId}"]`
|
|
1510
|
-
)
|
|
1511
|
-
];
|
|
1512
|
-
const visible = candidates.find((node) => node.getClientRects().length > 0);
|
|
1513
|
-
(visible || fallback)?.focus?.();
|
|
1514
|
-
};
|
|
1515
|
-
const ImpersonationPanelSection = ({ documentId, userLabel }) => {
|
|
1516
|
-
const { t } = useSettingsTranslate();
|
|
1517
|
-
const { get, post } = useFetchClient();
|
|
1518
|
-
const { toggleNotification } = useNotification();
|
|
1519
|
-
const { formatDate } = useSessionFormatters();
|
|
1520
|
-
const {
|
|
1521
|
-
isLoading,
|
|
1522
|
-
allowedActions: { canUsers }
|
|
1523
|
-
} = useRBAC(pluginPermissions.impersonateUsers);
|
|
1524
|
-
const [status, setStatus] = useState(null);
|
|
1525
|
-
const [active, setActive] = useState(null);
|
|
1526
|
-
const instance = useId();
|
|
1527
|
-
const dialog = useSyncExternalStore(
|
|
1528
|
-
subscribeImpersonationDialogs,
|
|
1529
|
-
() => getImpersonationDialog(documentId)
|
|
1530
|
-
);
|
|
1531
|
-
const open = dialog?.open === true && dialog.owner === instance;
|
|
1532
|
-
useEffect(() => registerImpersonationPanel(documentId, instance), [documentId, instance]);
|
|
1533
|
-
const triggerRef = useRef(null);
|
|
1534
|
-
const endTriggerRef = useRef(null);
|
|
1535
|
-
const requestRef = useRef(0);
|
|
1536
|
-
const apply = useCallback(
|
|
1537
|
-
async (request, pending) => {
|
|
1538
|
-
try {
|
|
1539
|
-
const [statusResponse, listResponse] = await pending;
|
|
1540
|
-
if (request !== requestRef.current) return;
|
|
1541
|
-
setStatus(statusResponse?.data?.data || null);
|
|
1542
|
-
const rows = Array.isArray(listResponse?.data?.data) ? listResponse.data.data : [];
|
|
1543
|
-
setActive(
|
|
1544
|
-
rows.find((row) => row.targetType === "user" && row.targetId === documentId) || null
|
|
1545
|
-
);
|
|
1546
|
-
} catch (err) {
|
|
1547
|
-
if (isCancelledRequest(err) || request !== requestRef.current) return;
|
|
1548
|
-
logSafeAdminError("impersonation.panel", err);
|
|
1549
|
-
setStatus(null);
|
|
1550
|
-
}
|
|
1551
|
-
},
|
|
1552
|
-
[documentId]
|
|
1553
|
-
);
|
|
1554
|
-
const fetchState = useCallback(
|
|
1555
|
-
() => Promise.all([
|
|
1556
|
-
get(`/${pluginId}/impersonation/status`),
|
|
1557
|
-
get(`/${pluginId}/impersonation/active`)
|
|
1558
|
-
]),
|
|
1559
|
-
[get]
|
|
1560
|
-
);
|
|
1561
|
-
const load = useCallback(() => apply(++requestRef.current, fetchState()), [apply, fetchState]);
|
|
1562
|
-
useEffect(() => {
|
|
1563
|
-
if (isLoading || !canUsers || !documentId) return;
|
|
1564
|
-
apply(++requestRef.current, fetchState());
|
|
1565
|
-
}, [apply, canUsers, documentId, fetchState, isLoading]);
|
|
1566
|
-
if (isLoading || !canUsers || !status?.enabled) return null;
|
|
1567
|
-
const end = async () => {
|
|
1568
|
-
try {
|
|
1569
|
-
await post(`/${pluginId}/impersonation/${active.id}/end`, {});
|
|
1570
|
-
toggleNotification({
|
|
1571
|
-
type: "success",
|
|
1572
|
-
message: t("impersonation.ended", "Impersonation ended.")
|
|
1573
|
-
});
|
|
1574
|
-
} catch (err) {
|
|
1575
|
-
logSafeAdminError("impersonation.end", err);
|
|
1576
|
-
toggleNotification({
|
|
1577
|
-
type: "danger",
|
|
1578
|
-
message: t("impersonation.error.end", "The impersonation could not be ended.")
|
|
1579
|
-
});
|
|
1580
|
-
throw err;
|
|
1581
|
-
} finally {
|
|
1582
|
-
await load();
|
|
1583
|
-
}
|
|
1584
|
-
};
|
|
1585
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-panel-impersonation": "", children: [
|
|
1586
|
-
/* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", tag: "h3", children: t("impersonation.panel.title", "Impersonation") }),
|
|
1587
|
-
active ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1588
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral800", tag: "p", children: t("impersonation.panel.running", "Running until {time}.", {
|
|
1589
|
-
time: formatDate(active.expiresAt, { hour: "2-digit", minute: "2-digit" })
|
|
1590
|
-
}) }),
|
|
1591
|
-
/* @__PURE__ */ jsx(
|
|
1592
|
-
ConfirmAction,
|
|
1593
|
-
{
|
|
1594
|
-
title: t("impersonation.confirm.title", "End the impersonation of {user}?", {
|
|
1595
|
-
user: userLabel
|
|
1596
|
-
}),
|
|
1597
|
-
body: t(
|
|
1598
|
-
"impersonation.confirm.body",
|
|
1599
|
-
"The short-lived sign-in stops working at once. This is recorded in the security log."
|
|
1600
|
-
),
|
|
1601
|
-
confirmLabel: t("impersonation.end", "End impersonation"),
|
|
1602
|
-
onConfirm: end,
|
|
1603
|
-
fallbackFocusRef: triggerRef,
|
|
1604
|
-
trigger: /* @__PURE__ */ jsx(
|
|
1605
|
-
Button,
|
|
1606
|
-
{
|
|
1607
|
-
ref: endTriggerRef,
|
|
1608
|
-
"data-impersonation-trigger": documentId,
|
|
1609
|
-
fullWidth: true,
|
|
1610
|
-
size: "S",
|
|
1611
|
-
variant: "danger-light",
|
|
1612
|
-
startIcon: /* @__PURE__ */ jsx(SignOut, { "aria-hidden": true, focusable: false }),
|
|
1613
|
-
type: "button",
|
|
1614
|
-
children: t("impersonation.end", "End impersonation")
|
|
1615
|
-
}
|
|
1616
|
-
)
|
|
1617
|
-
}
|
|
1618
|
-
)
|
|
1619
|
-
] }) : /* @__PURE__ */ jsx(
|
|
1620
|
-
Button,
|
|
1621
|
-
{
|
|
1622
|
-
ref: triggerRef,
|
|
1623
|
-
"data-impersonation-trigger": documentId,
|
|
1624
|
-
fullWidth: true,
|
|
1625
|
-
size: "S",
|
|
1626
|
-
variant: "secondary",
|
|
1627
|
-
startIcon: /* @__PURE__ */ jsx(User, { "aria-hidden": true, focusable: false }),
|
|
1628
|
-
onClick: () => openImpersonationDialog(documentId, instance),
|
|
1629
|
-
type: "button",
|
|
1630
|
-
children: t("impersonation.panel.start", "Impersonate…")
|
|
1631
|
-
}
|
|
1632
|
-
),
|
|
1633
|
-
open ? /* @__PURE__ */ jsx(
|
|
1634
|
-
ImpersonateUserModal,
|
|
1635
|
-
{
|
|
1636
|
-
open: true,
|
|
1637
|
-
onOpenChange: (next) => {
|
|
1638
|
-
if (!next) {
|
|
1639
|
-
closeImpersonationDialog(documentId);
|
|
1640
|
-
load();
|
|
1641
|
-
window.setTimeout(
|
|
1642
|
-
() => focusVisibleTrigger(documentId, triggerRef.current || endTriggerRef.current),
|
|
1643
|
-
0
|
|
1644
|
-
);
|
|
1645
|
-
}
|
|
1646
|
-
},
|
|
1647
|
-
onCloseAutoFocus: (event) => {
|
|
1648
|
-
event.preventDefault();
|
|
1649
|
-
focusVisibleTrigger(documentId, triggerRef.current || endTriggerRef.current);
|
|
1650
|
-
},
|
|
1651
|
-
user: { documentId, label: userLabel },
|
|
1652
|
-
status,
|
|
1653
|
-
onChanged: load
|
|
1654
|
-
}
|
|
1655
|
-
) : null
|
|
1656
|
-
] });
|
|
1657
|
-
};
|
|
1658
|
-
function requireSessionList(payload) {
|
|
1659
|
-
if (!Array.isArray(payload?.data)) throw new Error("Invalid session response");
|
|
1660
|
-
return payload.data;
|
|
1661
|
-
}
|
|
1662
|
-
function requireSuccessfulMutation(payload) {
|
|
1663
|
-
if (payload?.success !== true) throw new Error("Invalid mutation response");
|
|
1664
|
-
return payload;
|
|
1665
|
-
}
|
|
1666
|
-
const DEFAULT_SESSION_FILTER = "all";
|
|
1667
|
-
const SESSION_FILTER_OPTIONS = Object.freeze(["all", "open", "active", "idle", "ended"]);
|
|
1668
|
-
const DEFAULT_END_REASON_FILTER = "all";
|
|
1669
|
-
const END_REASON_FILTER_OPTIONS = Object.freeze(["all", ...SESSION_END_REASONS]);
|
|
1670
|
-
const VALID_SESSION_FILTERS = new Set(SESSION_FILTER_OPTIONS);
|
|
1671
|
-
const VALID_END_REASON_FILTERS = new Set(END_REASON_FILTER_OPTIONS);
|
|
1672
|
-
function isSessionFilter(value) {
|
|
1673
|
-
return typeof value === "string" && VALID_SESSION_FILTERS.has(value);
|
|
1674
|
-
}
|
|
1675
|
-
function isEndReasonFilter(value) {
|
|
1676
|
-
return typeof value === "string" && VALID_END_REASON_FILTERS.has(value);
|
|
1677
|
-
}
|
|
1678
|
-
function getManageableSessions(sessions) {
|
|
1679
|
-
if (!Array.isArray(sessions)) return [];
|
|
1680
|
-
return sessions.filter((session) => session?.isActive === true);
|
|
1681
|
-
}
|
|
1682
|
-
const USER_MODEL_UID = "plugin::users-permissions.user";
|
|
1683
|
-
const PANEL_SESSION_LIMIT = 5;
|
|
1684
|
-
const DASHBOARD_PATH = "/plugins/magic-sessionmanager";
|
|
1685
|
-
function isUserModel(model) {
|
|
1686
|
-
return model === USER_MODEL_UID;
|
|
1687
|
-
}
|
|
1688
|
-
const getActivity = (session) => toValidDate(session?.lastActive) || toValidDate(session?.loginTime);
|
|
1689
|
-
function getUserSessionSummary(sessions) {
|
|
1690
|
-
const rows = Array.isArray(sessions) ? sessions.filter((row) => row && typeof row === "object") : [];
|
|
1691
|
-
const open = rows.filter((session) => session.isActive === true);
|
|
1692
|
-
const activeCount = open.filter((session) => session.isTrulyActive === true).length;
|
|
1693
|
-
let lastActive = null;
|
|
1694
|
-
for (const session of rows) {
|
|
1695
|
-
const activity = getActivity(session);
|
|
1696
|
-
if (activity && (!lastActive || activity.getTime() > lastActive.getTime()))
|
|
1697
|
-
lastActive = activity;
|
|
1698
|
-
}
|
|
1699
|
-
return { isOnline: activeCount > 0, openCount: open.length, activeCount, lastActive };
|
|
1700
|
-
}
|
|
1701
|
-
function getVisiblePanelSessions(sessions, limit = PANEL_SESSION_LIMIT) {
|
|
1702
|
-
const rows = Array.isArray(sessions) ? [...sessions] : [];
|
|
1703
|
-
rows.sort(
|
|
1704
|
-
(a, b) => (getActivity(b)?.getTime() ?? -Infinity) - (getActivity(a)?.getTime() ?? -Infinity)
|
|
1705
|
-
);
|
|
1706
|
-
return { visible: rows.slice(0, limit), hiddenCount: Math.max(0, rows.length - limit) };
|
|
1707
|
-
}
|
|
1708
|
-
function endOpenSessions(sessions, reason) {
|
|
1709
|
-
if (!Array.isArray(sessions)) return [];
|
|
1710
|
-
return sessions.map(
|
|
1711
|
-
(session) => session?.isActive === true ? { ...session, isActive: false, isTrulyActive: false, terminationReason: reason } : session
|
|
1712
|
-
);
|
|
1713
|
-
}
|
|
1714
|
-
function getPanelUserLabel(user) {
|
|
1715
|
-
return presentText(user?.username) || presentText(user?.email);
|
|
1716
|
-
}
|
|
1717
|
-
function isNotFoundError(error) {
|
|
1718
|
-
if (!error || typeof error !== "object") return false;
|
|
1719
|
-
return error.status === 404 || error.response?.status === 404;
|
|
1720
|
-
}
|
|
1721
|
-
function buildUserSessionsHref(user) {
|
|
1722
|
-
const query = presentText(user?.email) || presentText(user?.username);
|
|
1723
|
-
if (!query) return DASHBOARD_PATH;
|
|
1724
|
-
return `${DASHBOARD_PATH}?${new URLSearchParams({ search: query }).toString()}`;
|
|
1725
|
-
}
|
|
1726
|
-
function planBlockedFormSync({ initialValues, modified, blocked }) {
|
|
1727
|
-
const hasBlockedField = Boolean(initialValues) && typeof initialValues === "object" && Object.prototype.hasOwnProperty.call(initialValues, "blocked");
|
|
1728
|
-
if (!hasBlockedField || typeof blocked !== "boolean") return { mode: "notice" };
|
|
1729
|
-
if (!modified) return { mode: "reset", initialValues: { ...initialValues, blocked } };
|
|
1730
|
-
return { mode: "change", field: "blocked", value: blocked };
|
|
1731
|
-
}
|
|
1732
|
-
function applyBlockedFormSync(plan, form) {
|
|
1733
|
-
try {
|
|
1734
|
-
if (plan.mode === "reset" && typeof form?.resetForm === "function") {
|
|
1735
|
-
form.resetForm(plan.initialValues);
|
|
1736
|
-
return true;
|
|
1737
|
-
}
|
|
1738
|
-
if (plan.mode === "change" && typeof form?.onChange === "function") {
|
|
1739
|
-
form.onChange(plan.field, plan.value);
|
|
1740
|
-
return true;
|
|
1741
|
-
}
|
|
1742
|
-
} catch {
|
|
1743
|
-
return false;
|
|
1744
|
-
}
|
|
1745
|
-
return false;
|
|
1746
|
-
}
|
|
1747
|
-
const FORM_CONSUMER = "MagicSessionManagerPanel";
|
|
1748
|
-
const PanelSessionCard = ({ session, t }) => {
|
|
1749
|
-
const { formatDate, formatRelativeTime, translate } = useSessionFormatters();
|
|
1750
|
-
const device = getDevicePresentation(session);
|
|
1751
|
-
const hasSummary = Boolean(device.browserLabel || device.os);
|
|
1752
|
-
const summary = hasSummary ? device.summary.text ?? translate(device.summary, device.summary.values) : "";
|
|
1753
|
-
const lastActivity = toValidDate(session.lastActive) || toValidDate(session.loginTime);
|
|
1754
|
-
const ipAddress = presentText(session.ipAddress);
|
|
1755
|
-
return /* @__PURE__ */ jsx(
|
|
1756
|
-
Box,
|
|
1757
|
-
{
|
|
1758
|
-
tag: "li",
|
|
1759
|
-
padding: 3,
|
|
1760
|
-
background: "neutral0",
|
|
1761
|
-
borderColor: "neutral200",
|
|
1762
|
-
hasRadius: true,
|
|
1763
|
-
minWidth: 0,
|
|
1764
|
-
"data-panel-session": "",
|
|
1765
|
-
children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "flex-start", minWidth: 0, children: [
|
|
1766
|
-
/* @__PURE__ */ jsx(
|
|
1767
|
-
Flex,
|
|
1768
|
-
{
|
|
1769
|
-
background: "neutral100",
|
|
1770
|
-
color: "neutral700",
|
|
1771
|
-
hasRadius: true,
|
|
1772
|
-
padding: 2,
|
|
1773
|
-
shrink: 0,
|
|
1774
|
-
justifyContent: "center",
|
|
1775
|
-
alignItems: "center",
|
|
1776
|
-
"aria-hidden": true,
|
|
1777
|
-
children: /* @__PURE__ */ jsx(DeviceIcon, { icon: device.icon })
|
|
1778
|
-
}
|
|
1779
|
-
),
|
|
1780
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, minWidth: 0, flex: "1 1 auto", children: [
|
|
1781
|
-
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
|
|
1782
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: translate(device.deviceTypeMessage) }),
|
|
1783
|
-
/* @__PURE__ */ jsx(StatusBadge, { session, size: "S" })
|
|
1784
|
-
] }),
|
|
1785
|
-
summary ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: summary }) : null,
|
|
1786
|
-
ipAddress ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("panel.sessions.ip", "IP {ip}", { ip: ipAddress }) }) : null,
|
|
1787
|
-
lastActivity ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", title: formatDate(lastActivity), children: t("panel.sessions.lastActive", "Last active {time}", {
|
|
1788
|
-
time: formatRelativeTime(lastActivity)
|
|
1789
|
-
}) }) : null
|
|
1790
|
-
] })
|
|
1791
|
-
] })
|
|
1792
|
-
}
|
|
1793
|
-
);
|
|
1794
|
-
};
|
|
1795
|
-
const SessionInfoPanel = ({ documentId, model, document: document2 }) => {
|
|
1796
|
-
const { formatMessage } = useIntl();
|
|
1797
|
-
const { formatDate, formatRelativeTime } = useSessionFormatters();
|
|
1798
|
-
const {
|
|
1799
|
-
allowedActions: { canAccess },
|
|
1800
|
-
isLoading: permissionsLoading
|
|
1801
|
-
} = useRBAC(pluginPermissions.access);
|
|
1802
|
-
const [sessions, setSessions] = useState([]);
|
|
1803
|
-
const [loading, setLoading] = useState(true);
|
|
1804
|
-
const [loadError, setLoadError] = useState(false);
|
|
1805
|
-
const [reloadKey, setReloadKey] = useState(0);
|
|
1806
|
-
const [isBlocked, setIsBlocked] = useState(Boolean(document2?.blocked));
|
|
1807
|
-
const [pendingAction, setPendingAction] = useState(null);
|
|
1808
|
-
const [formOutOfSync, setFormOutOfSync] = useState(false);
|
|
1809
|
-
const panelRef = useRef(null);
|
|
1810
|
-
const blockToggleRef = useRef(null);
|
|
1811
|
-
const focusBlockToggle = useRef(false);
|
|
1812
|
-
const noOpenSessionsHintId = useId();
|
|
1813
|
-
const { get, post: postRequest } = useFetchClient();
|
|
1814
|
-
const { toggleNotification } = useNotification();
|
|
1815
|
-
const formInitialValues = useForm(FORM_CONSUMER, (state) => state.initialValues, false);
|
|
1816
|
-
const formModified = useForm(FORM_CONSUMER, (state) => state.modified, false);
|
|
1817
|
-
const formOnChange = useForm(FORM_CONSUMER, (state) => state.onChange, false);
|
|
1818
|
-
const formResetForm = useForm(FORM_CONSUMER, (state) => state.resetForm, false);
|
|
1819
|
-
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
1820
|
-
const userId = document2?.documentId || documentId;
|
|
1821
|
-
const isUserPanel = isUserModel(model);
|
|
1822
|
-
const persistedBlocked = Boolean(document2?.blocked);
|
|
1823
|
-
const userLabel = getPanelUserLabel(document2) || String(userId ?? "");
|
|
1824
|
-
useEffect(() => {
|
|
1825
|
-
setIsBlocked(persistedBlocked);
|
|
1826
|
-
setFormOutOfSync(false);
|
|
1827
|
-
}, [persistedBlocked, userId]);
|
|
1828
|
-
useEffect(() => {
|
|
1829
|
-
if (!focusBlockToggle.current || pendingAction !== null) return void 0;
|
|
1830
|
-
const expected = isBlocked ? "unblock" : "block";
|
|
1831
|
-
let attempts = 0;
|
|
1832
|
-
let timer;
|
|
1833
|
-
const tryFocus = () => {
|
|
1834
|
-
const button = blockToggleRef.current;
|
|
1835
|
-
if (button?.isConnected && !button.disabled && button.dataset.blockToggle === expected) {
|
|
1836
|
-
focusBlockToggle.current = false;
|
|
1837
|
-
button.focus();
|
|
1838
|
-
return;
|
|
1839
|
-
}
|
|
1840
|
-
attempts += 1;
|
|
1841
|
-
if (attempts < 20) timer = window.setTimeout(tryFocus, 25);
|
|
1842
|
-
else focusBlockToggle.current = false;
|
|
1843
|
-
};
|
|
1844
|
-
timer = window.setTimeout(tryFocus, 0);
|
|
1845
|
-
return () => window.clearTimeout(timer);
|
|
1846
|
-
}, [isBlocked, pendingAction]);
|
|
1847
|
-
useEffect(() => {
|
|
1848
|
-
if (model !== "plugin::users-permissions.user" || !userId || permissionsLoading || !canAccess) {
|
|
1849
|
-
setLoading(false);
|
|
1850
|
-
return void 0;
|
|
1851
|
-
}
|
|
1852
|
-
let cancelled = false;
|
|
1853
|
-
const fetchData = async () => {
|
|
1854
|
-
setLoading(true);
|
|
1855
|
-
setLoadError(false);
|
|
1856
|
-
try {
|
|
1857
|
-
const { data } = await get(`/magic-sessionmanager/user/${userId}/sessions`);
|
|
1858
|
-
if (cancelled) return;
|
|
1859
|
-
setSessions(requireSessionList(data));
|
|
1860
|
-
} catch (err) {
|
|
1861
|
-
if (!cancelled) setLoadError(true);
|
|
1862
|
-
logSafeAdminError("userSessions.load", err);
|
|
1863
|
-
} finally {
|
|
1864
|
-
if (!cancelled) setLoading(false);
|
|
1865
|
-
}
|
|
1866
|
-
};
|
|
1867
|
-
fetchData();
|
|
1868
|
-
return () => {
|
|
1869
|
-
cancelled = true;
|
|
1870
|
-
};
|
|
1871
|
-
}, [userId, model, get, reloadKey, canAccess, permissionsLoading]);
|
|
1872
|
-
const handleEndAll = async () => {
|
|
1873
|
-
if (!userId) return;
|
|
1874
|
-
setPendingAction("endAll");
|
|
1875
|
-
try {
|
|
1876
|
-
const response = await postRequest(`/magic-sessionmanager/user/${userId}/terminate-all`);
|
|
1877
|
-
requireSuccessfulMutation(response.data);
|
|
1878
|
-
setSessions((rows) => endOpenSessions(rows, "manual"));
|
|
1879
|
-
toggleNotification({
|
|
1880
|
-
type: "success",
|
|
1881
|
-
message: t("panel.notify.endAllSuccess", "All sessions of {user} ended.", {
|
|
1882
|
-
user: userLabel
|
|
1883
|
-
})
|
|
1884
|
-
});
|
|
1885
|
-
} catch (error) {
|
|
1886
|
-
toggleNotification({
|
|
1887
|
-
type: "danger",
|
|
1888
|
-
message: isNotFoundError(error) ? t("panel.notify.userNotFound", "User not found.") : t("panel.notify.endAllError", "The sessions could not be ended. Please try again.")
|
|
1889
|
-
});
|
|
1890
|
-
logSafeAdminError("userSessions.endAll", error);
|
|
1891
|
-
throw error;
|
|
1892
|
-
} finally {
|
|
1893
|
-
setPendingAction(null);
|
|
1894
|
-
}
|
|
1895
|
-
};
|
|
1896
|
-
const changeBlocked = async (blocked) => {
|
|
1897
|
-
const response = await postRequest(`/magic-sessionmanager/user/${userId}/toggle-block`, {
|
|
1898
|
-
blocked
|
|
1899
|
-
});
|
|
1900
|
-
requireSuccessfulMutation(response.data);
|
|
1901
|
-
const newBlockedStatus = response.data.blocked === true;
|
|
1902
|
-
focusBlockToggle.current = newBlockedStatus !== isBlocked;
|
|
1903
|
-
setIsBlocked(newBlockedStatus);
|
|
1904
|
-
if (newBlockedStatus) setSessions((rows) => endOpenSessions(rows, "blocked"));
|
|
1905
|
-
const plan = planBlockedFormSync({
|
|
1906
|
-
initialValues: formInitialValues,
|
|
1907
|
-
modified: formModified,
|
|
1908
|
-
blocked: newBlockedStatus
|
|
1909
|
-
});
|
|
1910
|
-
const synced = applyBlockedFormSync(plan, { resetForm: formResetForm, onChange: formOnChange });
|
|
1911
|
-
setFormOutOfSync(!synced);
|
|
1912
|
-
return newBlockedStatus;
|
|
1913
|
-
};
|
|
1914
|
-
const handleBlock = async () => {
|
|
1915
|
-
if (!userId) return;
|
|
1916
|
-
setPendingAction("block");
|
|
1917
|
-
try {
|
|
1918
|
-
await changeBlocked(true);
|
|
1919
|
-
toggleNotification({
|
|
1920
|
-
type: "success",
|
|
1921
|
-
message: t("panel.notify.blockSuccess", "{user} is blocked.", { user: userLabel })
|
|
1922
|
-
});
|
|
1923
|
-
} catch (error) {
|
|
1924
|
-
toggleNotification({
|
|
1925
|
-
type: "danger",
|
|
1926
|
-
message: isNotFoundError(error) ? t("panel.notify.userNotFound", "User not found.") : t("panel.notify.blockError", "The user could not be blocked. Please try again.")
|
|
1927
|
-
});
|
|
1928
|
-
logSafeAdminError("userSessions.block", error);
|
|
1929
|
-
throw error;
|
|
1930
|
-
} finally {
|
|
1931
|
-
setPendingAction(null);
|
|
1932
|
-
}
|
|
1933
|
-
};
|
|
1934
|
-
const handleUnblock = async () => {
|
|
1935
|
-
if (!userId) return;
|
|
1936
|
-
setPendingAction("unblock");
|
|
1937
|
-
try {
|
|
1938
|
-
await changeBlocked(false);
|
|
1939
|
-
toggleNotification({
|
|
1940
|
-
type: "success",
|
|
1941
|
-
message: t("panel.notify.unblockSuccess", "{user} can sign in again.", { user: userLabel })
|
|
1942
|
-
});
|
|
1943
|
-
} catch (error) {
|
|
1944
|
-
toggleNotification({
|
|
1945
|
-
type: "danger",
|
|
1946
|
-
message: isNotFoundError(error) ? t("panel.notify.userNotFound", "User not found.") : t("panel.notify.unblockError", "The block could not be removed. Please try again.")
|
|
1947
|
-
});
|
|
1948
|
-
logSafeAdminError("userSessions.unblock", error);
|
|
1949
|
-
} finally {
|
|
1950
|
-
setPendingAction(null);
|
|
1951
|
-
}
|
|
1952
|
-
};
|
|
1953
|
-
if (!isUserPanel) {
|
|
1954
|
-
return null;
|
|
1955
|
-
}
|
|
1956
|
-
if (permissionsLoading || !canAccess) {
|
|
1957
|
-
return null;
|
|
1958
|
-
}
|
|
1959
|
-
const title = t("panel.title", "Sessions");
|
|
1960
|
-
if (!userId) {
|
|
1961
|
-
return {
|
|
1962
|
-
title,
|
|
1963
|
-
content: /* @__PURE__ */ jsx(Box, { width: "100%", minWidth: 0, children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral700", tag: "p", children: t("panel.unsaved.description", "Save this user before you can manage sessions.") }) })
|
|
1964
|
-
};
|
|
1965
|
-
}
|
|
1966
|
-
if (loadError) {
|
|
1967
|
-
return {
|
|
1968
|
-
title,
|
|
1969
|
-
content: /* @__PURE__ */ jsx(Box, { width: "100%", minWidth: 0, children: /* @__PURE__ */ jsx(
|
|
1970
|
-
PersistentAlert,
|
|
1971
|
-
{
|
|
1972
|
-
variant: "danger",
|
|
1973
|
-
closeLabel: t("common.close", "Close"),
|
|
1974
|
-
action: /* @__PURE__ */ jsx(Button, { size: "S", variant: "secondary", onClick: () => setReloadKey((key) => key + 1), children: t("common.tryAgain", "Try again") }),
|
|
1975
|
-
children: t("panel.error.message", "Sessions could not be loaded.")
|
|
1976
|
-
}
|
|
1977
|
-
) })
|
|
1978
|
-
};
|
|
1979
|
-
}
|
|
1980
|
-
const openSessions = getManageableSessions(sessions);
|
|
1981
|
-
const summary = getUserSessionSummary(sessions);
|
|
1982
|
-
const { visible, hiddenCount } = getVisiblePanelSessions(openSessions);
|
|
1983
|
-
const actionsDisabled = loading || pendingAction !== null;
|
|
1984
|
-
const hasOpenSessions = summary.openCount > 0;
|
|
1985
|
-
const endAllLabel = t("panel.actions.endAll", "End all sessions");
|
|
1986
|
-
const blockLabel = t("panel.actions.blockUser", "Block user");
|
|
1987
|
-
const unblockLabel = t("panel.actions.unblock", "Unblock user");
|
|
1988
|
-
return {
|
|
1989
|
-
title,
|
|
1990
|
-
content: /* @__PURE__ */ jsxs(
|
|
1991
|
-
Flex,
|
|
1992
|
-
{
|
|
1993
|
-
ref: panelRef,
|
|
1994
|
-
direction: "column",
|
|
1995
|
-
alignItems: "stretch",
|
|
1996
|
-
gap: 4,
|
|
1997
|
-
width: "100%",
|
|
1998
|
-
minWidth: 0,
|
|
1999
|
-
tabIndex: -1,
|
|
2000
|
-
children: [
|
|
2001
|
-
loading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 2, "data-panel-summary": "", children: /* @__PURE__ */ jsx(Loader, { small: true, children: t("panel.loading", "Loading sessions") }) }) : /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, "data-panel-summary": "", children: [
|
|
2002
|
-
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
2003
|
-
/* @__PURE__ */ jsx(Badge, { variant: summary.isOnline ? "success" : "neutral", size: "M", children: summary.isOnline ? t("panel.status.online", "Online") : t("panel.status.notOnline", "Not online") }),
|
|
2004
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: t(
|
|
2005
|
-
"panel.summary.openCount",
|
|
2006
|
-
"{count, plural, one {# open session} other {# open sessions}}",
|
|
2007
|
-
{ count: summary.openCount }
|
|
2008
|
-
) })
|
|
2009
|
-
] }),
|
|
2010
|
-
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("panel.summary.openHint", "Active or idle") }),
|
|
2011
|
-
summary.lastActive ? /* @__PURE__ */ jsx(
|
|
2012
|
-
Typography,
|
|
2013
|
-
{
|
|
2014
|
-
variant: "pi",
|
|
2015
|
-
textColor: "neutral600",
|
|
2016
|
-
title: formatDate(summary.lastActive),
|
|
2017
|
-
children: t("panel.sessions.lastActive", "Last active {time}", {
|
|
2018
|
-
time: formatRelativeTime(summary.lastActive)
|
|
2019
|
-
})
|
|
2020
|
-
}
|
|
2021
|
-
) : /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("panel.summary.noSessions", "No sessions recorded") })
|
|
2022
|
-
] }),
|
|
2023
|
-
isBlocked ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "danger", closeLabel: t("common.close", "Close"), children: t("panel.blocked.message", "This account is blocked. The user cannot sign in.") }) : null,
|
|
2024
|
-
formOutOfSync ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "warning", closeLabel: t("common.close", "Close"), children: t(
|
|
2025
|
-
"panel.form.reloadNotice",
|
|
2026
|
-
"Reload this page before saving, or the Blocked field will be overwritten."
|
|
2027
|
-
) }) : null,
|
|
2028
|
-
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-panel-actions": "", children: [
|
|
2029
|
-
/* @__PURE__ */ jsxs(ActionStack, { children: [
|
|
2030
|
-
/* @__PURE__ */ jsx(
|
|
2031
|
-
ConfirmAction,
|
|
2032
|
-
{
|
|
2033
|
-
title: t("panel.confirm.endAllTitle", "End all sessions of {user}?", {
|
|
2034
|
-
user: userLabel
|
|
2035
|
-
}),
|
|
2036
|
-
body: t(
|
|
2037
|
-
"panel.confirm.endAllBody",
|
|
2038
|
-
"{count, plural, one {# open session ends} other {# open sessions end}} on all devices. {user} can sign in again unless you also block the account.",
|
|
2039
|
-
{ count: summary.openCount, user: userLabel }
|
|
2040
|
-
),
|
|
2041
|
-
confirmLabel: endAllLabel,
|
|
2042
|
-
onConfirm: handleEndAll,
|
|
2043
|
-
fallbackFocusRef: panelRef,
|
|
2044
|
-
disabled: actionsDisabled || !hasOpenSessions,
|
|
2045
|
-
trigger: /* @__PURE__ */ jsx(
|
|
2046
|
-
Button,
|
|
2047
|
-
{
|
|
2048
|
-
fullWidth: true,
|
|
2049
|
-
size: "S",
|
|
2050
|
-
variant: "danger-light",
|
|
2051
|
-
startIcon: /* @__PURE__ */ jsx(SignOut, { "aria-hidden": true, focusable: false }),
|
|
2052
|
-
loading: pendingAction === "endAll",
|
|
2053
|
-
disabled: actionsDisabled || !hasOpenSessions,
|
|
2054
|
-
"aria-describedby": !loading && !hasOpenSessions ? noOpenSessionsHintId : void 0,
|
|
2055
|
-
type: "button",
|
|
2056
|
-
children: endAllLabel
|
|
2057
|
-
}
|
|
2058
|
-
)
|
|
2059
|
-
}
|
|
2060
|
-
),
|
|
2061
|
-
isBlocked ? /* @__PURE__ */ jsx(
|
|
2062
|
-
Button,
|
|
2063
|
-
{
|
|
2064
|
-
ref: blockToggleRef,
|
|
2065
|
-
"data-block-toggle": "unblock",
|
|
2066
|
-
fullWidth: true,
|
|
2067
|
-
size: "S",
|
|
2068
|
-
variant: "secondary",
|
|
2069
|
-
startIcon: /* @__PURE__ */ jsx(CheckCircle, { "aria-hidden": true, focusable: false }),
|
|
2070
|
-
loading: pendingAction === "unblock",
|
|
2071
|
-
disabled: actionsDisabled,
|
|
2072
|
-
onClick: handleUnblock,
|
|
2073
|
-
type: "button",
|
|
2074
|
-
children: unblockLabel
|
|
2075
|
-
}
|
|
2076
|
-
) : /* @__PURE__ */ jsx(
|
|
2077
|
-
ConfirmAction,
|
|
2078
|
-
{
|
|
2079
|
-
title: t("panel.confirm.blockTitle", "Block {user}?", { user: userLabel }),
|
|
2080
|
-
body: t(
|
|
2081
|
-
"panel.confirm.blockBody",
|
|
2082
|
-
"{user} can no longer sign in, and {count, plural, =0 {no open sessions are affected} one {# open session ends now} other {# open sessions end now}}. You can unblock the account later; ended sessions stay ended.",
|
|
2083
|
-
{ count: summary.openCount, user: userLabel }
|
|
2084
|
-
),
|
|
2085
|
-
confirmLabel: blockLabel,
|
|
2086
|
-
onConfirm: handleBlock,
|
|
2087
|
-
fallbackFocusRef: panelRef,
|
|
2088
|
-
disabled: actionsDisabled,
|
|
2089
|
-
trigger: /* @__PURE__ */ jsx(
|
|
2090
|
-
Button,
|
|
2091
|
-
{
|
|
2092
|
-
ref: blockToggleRef,
|
|
2093
|
-
"data-block-toggle": "block",
|
|
2094
|
-
fullWidth: true,
|
|
2095
|
-
size: "S",
|
|
2096
|
-
variant: "danger-light",
|
|
2097
|
-
startIcon: /* @__PURE__ */ jsx(Lock, { "aria-hidden": true, focusable: false }),
|
|
2098
|
-
loading: pendingAction === "block",
|
|
2099
|
-
disabled: actionsDisabled,
|
|
2100
|
-
type: "button",
|
|
2101
|
-
children: blockLabel
|
|
2102
|
-
}
|
|
2103
|
-
)
|
|
2104
|
-
}
|
|
2105
|
-
)
|
|
2106
|
-
] }),
|
|
2107
|
-
!loading && !hasOpenSessions ? /* @__PURE__ */ jsx(Typography, { id: noOpenSessionsHintId, variant: "pi", textColor: "neutral600", children: t("panel.actions.noOpenSessions", "No open sessions") }) : null,
|
|
2108
|
-
/* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
|
|
2109
|
-
"panel.actions.hint",
|
|
2110
|
-
"End all sessions lets the user sign in again. Block user also prevents new sign-ins."
|
|
2111
|
-
) })
|
|
2112
|
-
] }),
|
|
2113
|
-
userId ? /* @__PURE__ */ jsx(ImpersonationPanelSection, { documentId: String(userId), userLabel }) : null,
|
|
2114
|
-
loading ? null : /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-panel-sessions": "", children: [
|
|
2115
|
-
/* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", tag: "h3", children: t("panel.sessions.openTitle", "Open sessions") }),
|
|
2116
|
-
visible.length > 0 ? /* @__PURE__ */ jsx(
|
|
2117
|
-
Flex,
|
|
2118
|
-
{
|
|
2119
|
-
tag: "ul",
|
|
2120
|
-
direction: "column",
|
|
2121
|
-
alignItems: "stretch",
|
|
2122
|
-
gap: 2,
|
|
2123
|
-
margin: 0,
|
|
2124
|
-
padding: 0,
|
|
2125
|
-
style: { listStyle: "none" },
|
|
2126
|
-
children: visible.map((session) => /* @__PURE__ */ jsx(PanelSessionCard, { session, t }, session.id))
|
|
2127
|
-
}
|
|
2128
|
-
) : /* @__PURE__ */ jsx(Box, { padding: 3, background: "neutral0", borderColor: "neutral200", hasRadius: true, children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "p", children: t(
|
|
2129
|
-
"panel.empty.noOpenSessions",
|
|
2130
|
-
"No open sessions. {user} is not signed in on any device.",
|
|
2131
|
-
{ user: userLabel }
|
|
2132
|
-
) }) }),
|
|
2133
|
-
hiddenCount > 0 ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("panel.sessions.more", "{count, plural, other {+# more}}", {
|
|
2134
|
-
count: hiddenCount
|
|
2135
|
-
}) }) : null
|
|
2136
|
-
] }),
|
|
2137
|
-
/* @__PURE__ */ jsx(TargetLink, { tag: NavLink, to: buildUserSessionsHref(document2), children: t("panel.sessions.showAllLink", "Show all sessions") })
|
|
2138
|
-
]
|
|
2139
|
-
}
|
|
2140
|
-
)
|
|
2141
|
-
};
|
|
2142
|
-
};
|
|
2143
|
-
const prefixPluginTranslations = (data, pluginId2) => {
|
|
2144
|
-
const prefixed = {};
|
|
2145
|
-
Object.keys(data).forEach((key) => {
|
|
2146
|
-
prefixed[`${pluginId2}.${key}`] = data[key];
|
|
2147
|
-
});
|
|
2148
|
-
return prefixed;
|
|
2149
|
-
};
|
|
2150
|
-
const name = pluginPkg.strapi.name;
|
|
2151
|
-
const index = {
|
|
2152
|
-
register(app) {
|
|
2153
|
-
const pluginPermissions$1 = pluginPermissions.access;
|
|
2154
|
-
app.addMenuLink({
|
|
2155
|
-
to: `plugins/${pluginId}`,
|
|
2156
|
-
icon: PluginIcon,
|
|
2157
|
-
intlLabel: {
|
|
2158
|
-
id: `${pluginId}.plugin.name`,
|
|
2159
|
-
defaultMessage: pluginPkg.strapi.displayName
|
|
2160
|
-
},
|
|
2161
|
-
Component: () => import("./App-BswHmNQT.mjs"),
|
|
2162
|
-
permissions: pluginPermissions$1
|
|
2163
|
-
});
|
|
2164
|
-
app.addSettingsLink(
|
|
2165
|
-
{
|
|
2166
|
-
id: pluginId,
|
|
2167
|
-
intlLabel: { id: `${pluginId}.settings.section`, defaultMessage: "Session Manager" }
|
|
2168
|
-
},
|
|
2169
|
-
[
|
|
2170
|
-
{
|
|
2171
|
-
intlLabel: {
|
|
2172
|
-
id: `${pluginId}.settings.link.configuration`,
|
|
2173
|
-
defaultMessage: "Configuration"
|
|
2174
|
-
},
|
|
2175
|
-
id: "general",
|
|
2176
|
-
to: `${pluginId}/general`,
|
|
2177
|
-
Component: () => import("./Settings-DZyQheUS.mjs"),
|
|
2178
|
-
permissions: pluginPermissions$1
|
|
2179
|
-
},
|
|
2180
|
-
{
|
|
2181
|
-
intlLabel: {
|
|
2182
|
-
id: `${pluginId}.settings.link.analytics`,
|
|
2183
|
-
defaultMessage: "Analytics"
|
|
2184
|
-
},
|
|
2185
|
-
id: "analytics",
|
|
2186
|
-
to: `${pluginId}/analytics`,
|
|
2187
|
-
Component: () => import("./Analytics-C-OLLzoB.mjs"),
|
|
2188
|
-
permissions: pluginPermissions$1
|
|
2189
|
-
}
|
|
2190
|
-
]
|
|
2191
|
-
);
|
|
2192
|
-
app.registerPlugin({
|
|
2193
|
-
id: pluginId,
|
|
2194
|
-
initializer: Initializer,
|
|
2195
|
-
isReady: true,
|
|
2196
|
-
name
|
|
2197
|
-
});
|
|
2198
|
-
if ("widgets" in app && app.widgets && typeof app.widgets.register === "function") {
|
|
2199
|
-
app.widgets.register({
|
|
2200
|
-
icon: PluginIcon,
|
|
2201
|
-
title: {
|
|
2202
|
-
id: `${pluginId}.widget.online-users.title`,
|
|
2203
|
-
defaultMessage: "Online users"
|
|
2204
|
-
},
|
|
2205
|
-
link: {
|
|
2206
|
-
label: {
|
|
2207
|
-
id: `${pluginId}.widget.link`,
|
|
2208
|
-
defaultMessage: "Open Session Manager"
|
|
2209
|
-
},
|
|
2210
|
-
href: `/plugins/${pluginId}`
|
|
2211
|
-
},
|
|
2212
|
-
component: async () => {
|
|
2213
|
-
const component = await import("./OnlineUsersWidget-Dusgjc1d.mjs");
|
|
2214
|
-
return component.default;
|
|
2215
|
-
},
|
|
2216
|
-
id: "online-users-widget",
|
|
2217
|
-
pluginId,
|
|
2218
|
-
permissions: pluginPermissions$1
|
|
2219
|
-
});
|
|
2220
|
-
}
|
|
2221
|
-
},
|
|
2222
|
-
bootstrap(app) {
|
|
2223
|
-
try {
|
|
2224
|
-
const contentManagerPlugin = app.getPlugin("content-manager");
|
|
2225
|
-
if (contentManagerPlugin?.apis?.addEditViewSidePanel) {
|
|
2226
|
-
contentManagerPlugin.apis.addEditViewSidePanel([SessionInfoPanel]);
|
|
2227
|
-
}
|
|
2228
|
-
} catch (error) {
|
|
2229
|
-
logSafeAdminError("plugin.bootstrap", error);
|
|
2230
|
-
}
|
|
2231
|
-
},
|
|
2232
|
-
async registerTrads({ locales }) {
|
|
2233
|
-
const importedTrads = {
|
|
2234
|
-
en: () => import("./en-D8J__tyF.mjs"),
|
|
2235
|
-
de: () => import("./de-DUnrmFWk.mjs"),
|
|
2236
|
-
es: () => import("./es-BgpgWdk0.mjs"),
|
|
2237
|
-
fr: () => import("./fr-k1MHYKJo.mjs"),
|
|
2238
|
-
pt: () => import("./pt-DPO4DmDc.mjs")
|
|
2239
|
-
};
|
|
2240
|
-
const translatedLanguages = Object.keys(importedTrads).filter((lang) => locales.includes(lang));
|
|
2241
|
-
const translations = await Promise.all(
|
|
2242
|
-
translatedLanguages.map(
|
|
2243
|
-
(language) => importedTrads[language]().then(({ default: data }) => ({
|
|
2244
|
-
data: prefixPluginTranslations(data, pluginId),
|
|
2245
|
-
locale: language
|
|
2246
|
-
})).catch(() => ({
|
|
2247
|
-
data: {},
|
|
2248
|
-
locale: language
|
|
2249
|
-
}))
|
|
2250
|
-
)
|
|
2251
|
-
);
|
|
2252
|
-
return Promise.resolve(translations);
|
|
2253
|
-
}
|
|
2254
|
-
};
|
|
2255
|
-
export {
|
|
2256
|
-
validateReason as A,
|
|
2257
|
-
REASON_MAX as B,
|
|
2258
|
-
ConfirmAction as C,
|
|
2259
|
-
DeviceIcon as D,
|
|
2260
|
-
END_REASON_FILTER_OPTIONS as E,
|
|
2261
|
-
formatClock as F,
|
|
2262
|
-
ReadableParagraphs as G,
|
|
2263
|
-
EqualGrid as H,
|
|
2264
|
-
formatSessionDate as I,
|
|
2265
|
-
refocusIfLost as J,
|
|
2266
|
-
copyText as K,
|
|
2267
|
-
requireSuccessfulMutation as L,
|
|
2268
|
-
MissingValue as M,
|
|
2269
|
-
isSessionFilter as N,
|
|
2270
|
-
DEFAULT_SESSION_FILTER as O,
|
|
2271
|
-
PropertyList as P,
|
|
2272
|
-
isEndReasonFilter as Q,
|
|
2273
|
-
ReadableText as R,
|
|
2274
|
-
StatusBadge as S,
|
|
2275
|
-
TargetLink as T,
|
|
2276
|
-
DEFAULT_END_REASON_FILTER as U,
|
|
2277
|
-
ValueOrMissing as V,
|
|
2278
|
-
normalizeDeviceType as W,
|
|
2279
|
-
getDeviceTypeMessage as X,
|
|
2280
|
-
index as Y,
|
|
2281
|
-
getEndReasonPresentation as a,
|
|
2282
|
-
getTranslation as b,
|
|
2283
|
-
getSessionStatus as c,
|
|
2284
|
-
getDevicePresentation as d,
|
|
2285
|
-
getSessionEndReasonPresentation as e,
|
|
2286
|
-
pluginId as f,
|
|
2287
|
-
getSessionEndReason as g,
|
|
2288
|
-
PersistentAlert as h,
|
|
2289
|
-
isNativeOnlySession as i,
|
|
2290
|
-
pluginPermissions as j,
|
|
2291
|
-
SESSION_STATES as k,
|
|
2292
|
-
logSafeAdminError as l,
|
|
2293
|
-
SESSION_STATUS_PRESENTATION as m,
|
|
2294
|
-
isCancelledRequest as n,
|
|
2295
|
-
SESSION_FILTER_OPTIONS as o,
|
|
2296
|
-
presentText as p,
|
|
2297
|
-
PageShell as q,
|
|
2298
|
-
StatGrid as r,
|
|
2299
|
-
StatCard as s,
|
|
2300
|
-
toValidDate as t,
|
|
2301
|
-
useSessionFormatters as u,
|
|
2302
|
-
restoreDialogFocus as v,
|
|
2303
|
-
requireSessionList as w,
|
|
2304
|
-
getBadgeColors as x,
|
|
2305
|
-
useSettingsTranslate as y,
|
|
2306
|
-
useSecondsLeft as z
|
|
2307
|
-
};
|