strapi-plugin-magic-sessionmanager 4.9.1 → 4.11.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +86 -5
  2. package/README.md +427 -91
  3. package/dist/admin/{Analytics-lVDnHBYp.js → Analytics-CBHeWeGn.js} +1 -1
  4. package/dist/admin/{Analytics-dyJmyxO-.mjs → Analytics-D56O8Q6e.mjs} +1 -1
  5. package/dist/admin/{App-CdgiY_Y7.js → App-D4cBPwB_.js} +2 -3
  6. package/dist/admin/{App-Cgf_CSjw.mjs → App-EDIkLJdb.mjs} +2 -3
  7. package/dist/admin/{OnlineUsersWidget-DMPtuIpm.js → OnlineUsersWidget-BF2R2YIy.js} +1 -1
  8. package/dist/admin/{OnlineUsersWidget-DJC4V1KS.mjs → OnlineUsersWidget-MwUutkKQ.mjs} +1 -1
  9. package/dist/admin/{Settings-0QsyY7fe.js → Settings-CMzEF8EH.js} +21 -5
  10. package/dist/admin/{Settings-DgeuUiMF.mjs → Settings-bLMyi0BN.mjs} +20 -4
  11. package/dist/admin/{de-j0oZH9Pz.mjs → de-CxfuTF6C.mjs} +1 -42
  12. package/dist/admin/{de-BFKoGEVT.js → de-DVNTHmSo.js} +1 -42
  13. package/dist/admin/{en-UY4Tb5tE.mjs → en-BcPIlQYL.mjs} +1 -42
  14. package/dist/admin/{en-s7Ksdkcg.js → en-BuVXIcHA.js} +1 -42
  15. package/dist/admin/{es-07OGMe_5.js → es-CEteHmBO.js} +1 -42
  16. package/dist/admin/{es-DGBcZwQy.mjs → es-DxHpaNA1.mjs} +1 -42
  17. package/dist/admin/{fr-ETj_2UBY.js → fr-BMd2-wW7.js} +1 -42
  18. package/dist/admin/{fr-B6-DWhGO.mjs → fr-Dw43lHg7.mjs} +1 -42
  19. package/dist/admin/{index-D-Nr0TCm.js → index-DvNfekoR.js} +9 -19
  20. package/dist/admin/{index-Ck19e8qw.mjs → index-qa6Qnfkc.mjs} +9 -19
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +1 -1
  23. package/dist/admin/{pt-YMRLm9gx.mjs → pt-7jnxDSX-.mjs} +1 -42
  24. package/dist/admin/{pt-C7PwrQtV.js → pt-BvO63p01.js} +1 -42
  25. package/dist/server/index.js +1322 -827
  26. package/dist/server/index.mjs +1322 -827
  27. package/package.json +32 -13
  28. package/dist/admin/License-1XUfQty5.js +0 -443
  29. package/dist/admin/License-C4WSYoqY.mjs +0 -443
  30. package/dist/admin/maskSensitiveValue-BWcSjow7.js +0 -9
  31. package/dist/admin/maskSensitiveValue-lLRhN_S7.mjs +0 -10
@@ -1,443 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useState, useRef, useCallback, useEffect } from "react";
3
- import { useIntl } from "react-intl";
4
- import { Badge, Button, Flex, Typography, Field, TextInput, IconButton } from "@strapi/design-system";
5
- import { useFetchClient, useNotification, useClipboard, Page } from "@strapi/strapi/admin";
6
- import { EyeStriked, Eye, Duplicate, Download, ArrowClockwise } from "@strapi/icons";
7
- import { u as useSessionFormatters, m as pluginId, n as logSafeAdminError, z as PageShell, o as PersistentAlert, R as ReadableText, P as PropertyList, b as getTranslation } from "./index-Ck19e8qw.mjs";
8
- import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
9
- import { m as maskSensitiveValue } from "./maskSensitiveValue-lLRhN_S7.mjs";
10
- const LICENSE_STATE_MESSAGES = Object.freeze({
11
- noKey: Object.freeze({
12
- messageId: "license.state.noKey",
13
- defaultMessage: "No license key stored."
14
- }),
15
- valid: Object.freeze({
16
- messageId: "license.state.valid",
17
- defaultMessage: "License valid until {date}."
18
- }),
19
- validNoExpiry: Object.freeze({
20
- messageId: "license.state.validNoExpiry",
21
- defaultMessage: "License valid. It has no expiry date."
22
- }),
23
- expired: Object.freeze({
24
- messageId: "license.state.expired",
25
- defaultMessage: "License expired on {date}."
26
- }),
27
- expiredNoDate: Object.freeze({
28
- messageId: "license.state.expiredNoDate",
29
- defaultMessage: "License expired."
30
- }),
31
- invalid: Object.freeze({
32
- messageId: "license.state.invalid",
33
- defaultMessage: "This license key is not valid."
34
- }),
35
- unchecked: Object.freeze({
36
- messageId: "license.state.unchecked",
37
- defaultMessage: "The license status could not be checked."
38
- })
39
- });
40
- const LICENSE_FEATURES_MESSAGE = Object.freeze({
41
- messageId: "license.features.always",
42
- defaultMessage: "All features are available with or without a key."
43
- });
44
- const LICENSE_EXPIRY_DATE_OPTIONS = Object.freeze({ dateStyle: "medium" });
45
- const present = (value) => typeof value === "string" ? value.trim() !== "" : value !== null && value !== void 0;
46
- function getLicenseState(response, now = Date.now()) {
47
- const data = response?.data && typeof response.data === "object" ? response.data : {};
48
- const hasKey = typeof response?.hasKey === "boolean" ? response.hasKey : present(data.licenseKey);
49
- const expiresAt = present(data.expiresAt) ? data.expiresAt : null;
50
- const expiresAtMs = expiresAt ? Date.parse(expiresAt) : Number.NaN;
51
- const base = { hasKey, expiresAt, serverReachable: data.isOnline === true, data };
52
- if (!hasKey) return { ...base, state: "noKey" };
53
- const described = [
54
- "email",
55
- "firstName",
56
- "lastName",
57
- "expiresAt",
58
- "lastPingAt",
59
- "deviceName"
60
- ].some((field) => present(data[field]));
61
- if (!described) return { ...base, state: "unchecked" };
62
- const expired = data.isExpired === true || Number.isFinite(expiresAtMs) && expiresAtMs <= now;
63
- if (expired)
64
- return { ...base, state: Number.isFinite(expiresAtMs) ? "expired" : "expiredNoDate" };
65
- if (data.isActive === false) return { ...base, state: "invalid" };
66
- return { ...base, state: Number.isFinite(expiresAtMs) ? "valid" : "validNoExpiry" };
67
- }
68
- function describeLicenseState(licenseState, formatDate) {
69
- const descriptor = LICENSE_STATE_MESSAGES[licenseState?.state] || LICENSE_STATE_MESSAGES.unchecked;
70
- if (licenseState?.state === "valid" || licenseState?.state === "expired") {
71
- return {
72
- ...descriptor,
73
- values: { date: formatDate(licenseState.expiresAt, LICENSE_EXPIRY_DATE_OPTIONS) }
74
- };
75
- }
76
- return { ...descriptor };
77
- }
78
- const LICENSE_SUMMARY_MESSAGES = Object.freeze({
79
- heading: Object.freeze({
80
- messageId: "license.download.heading",
81
- defaultMessage: "Session Manager license"
82
- }),
83
- status: Object.freeze({ messageId: "license.download.status", defaultMessage: "Status" }),
84
- key: Object.freeze({ messageId: "license.key.title", defaultMessage: "License key" }),
85
- holder: Object.freeze({ messageId: "license.details.holder", defaultMessage: "Holder" }),
86
- email: Object.freeze({ messageId: "license.account.email", defaultMessage: "Email address" }),
87
- expires: Object.freeze({ messageId: "license.details.expires", defaultMessage: "Expires" }),
88
- noExpiry: Object.freeze({
89
- messageId: "license.details.noExpiry",
90
- defaultMessage: "No expiry date"
91
- }),
92
- deviceName: Object.freeze({
93
- messageId: "license.details.deviceName",
94
- defaultMessage: "Device name"
95
- }),
96
- ipAddress: Object.freeze({
97
- messageId: "license.details.ipAddress",
98
- defaultMessage: "IP address"
99
- }),
100
- lastCheck: Object.freeze({
101
- messageId: "license.details.lastCheck",
102
- defaultMessage: "Last check"
103
- }),
104
- deviceLimit: Object.freeze({
105
- messageId: "license.system.deviceLimit",
106
- defaultMessage: "Device limit"
107
- }),
108
- deviceLimitValue: Object.freeze({
109
- messageId: "license.system.deviceLimitValue",
110
- defaultMessage: "{current} of {max}"
111
- }),
112
- serverReachable: Object.freeze({
113
- messageId: "license.details.serverReachable",
114
- defaultMessage: "License server reachable"
115
- }),
116
- yes: Object.freeze({ messageId: "common.yes", defaultMessage: "Yes" }),
117
- no: Object.freeze({ messageId: "common.no", defaultMessage: "No" }),
118
- generated: Object.freeze({
119
- messageId: "license.download.generated",
120
- defaultMessage: "Generated"
121
- }),
122
- notProvided: Object.freeze({
123
- messageId: "license.value.notProvided",
124
- defaultMessage: "Not provided"
125
- })
126
- });
127
- const RULE = "========================================";
128
- const text = (value) => typeof value === "string" ? value.trim() : "";
129
- function getLicenseHolderName(data) {
130
- return [text(data?.firstName), text(data?.lastName)].filter(Boolean).join(" ");
131
- }
132
- function buildLicenseSummary({
133
- response,
134
- translate,
135
- formatDate,
136
- generatedAt = Date.now(),
137
- now = Date.now()
138
- }) {
139
- const m = LICENSE_SUMMARY_MESSAGES;
140
- const licenseState = getLicenseState(response, now);
141
- const data = licenseState.data;
142
- const statusMessage = describeLicenseState(licenseState, formatDate);
143
- const notProvided = translate(m.notProvided);
144
- const orMissing = (value) => text(value) || notProvided;
145
- const line = (descriptor, value) => `${translate(descriptor)}: ${value}`;
146
- return [
147
- translate(m.heading),
148
- RULE,
149
- line(m.status, translate(statusMessage, statusMessage.values)),
150
- translate(LICENSE_FEATURES_MESSAGE),
151
- "",
152
- line(m.key, orMissing(data.licenseKey)),
153
- line(m.holder, getLicenseHolderName(data) || notProvided),
154
- line(m.email, orMissing(data.email)),
155
- line(
156
- m.expires,
157
- licenseState.expiresAt ? formatDate(licenseState.expiresAt, LICENSE_EXPIRY_DATE_OPTIONS) : translate(m.noExpiry)
158
- ),
159
- line(m.deviceName, orMissing(data.deviceName)),
160
- line(m.ipAddress, orMissing(data.ipAddress)),
161
- line(m.lastCheck, data.lastPingAt ? formatDate(data.lastPingAt) : notProvided),
162
- line(
163
- m.deviceLimit,
164
- translate(m.deviceLimitValue, {
165
- current: Number(data.currentDevices) || 0,
166
- max: Number(data.maxDevices) || 1
167
- })
168
- ),
169
- line(m.serverReachable, translate(licenseState.serverReachable ? m.yes : m.no)),
170
- RULE,
171
- line(m.generated, formatDate(generatedAt)),
172
- ""
173
- ].join("\n");
174
- }
175
- const isForbidden = (error) => error?.status === 403 || error?.response?.status === 403;
176
- const LicensePage = () => {
177
- const { formatMessage } = useIntl();
178
- const { get } = useFetchClient();
179
- const { toggleNotification } = useNotification();
180
- const { copy } = useClipboard();
181
- const { formatDate } = useSessionFormatters();
182
- const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
183
- const translate = (descriptor, values) => formatMessage(
184
- { id: getTranslation(descriptor.messageId), defaultMessage: descriptor.defaultMessage },
185
- values
186
- );
187
- const [loading, setLoading] = useState(true);
188
- const [refreshing, setRefreshing] = useState(false);
189
- const [licenseData, setLicenseData] = useState(null);
190
- const [showLicenseKey, setShowLicenseKey] = useState(false);
191
- const [error, setError] = useState(false);
192
- const [forbidden, setForbidden] = useState(false);
193
- const requestPendingRef = useRef(false);
194
- const fetchLicenseStatus = useCallback(async () => {
195
- if (requestPendingRef.current) return false;
196
- requestPendingRef.current = true;
197
- try {
198
- const response = await get(`/${pluginId}/license/status`);
199
- setLicenseData(response.data);
200
- setError(false);
201
- return true;
202
- } catch (err) {
203
- logSafeAdminError("license.load", err);
204
- if (isForbidden(err)) setForbidden(true);
205
- setError(true);
206
- return false;
207
- } finally {
208
- requestPendingRef.current = false;
209
- setRefreshing(false);
210
- setLoading(false);
211
- }
212
- }, [get]);
213
- const checkLicenseStatus = async ({ announce }) => {
214
- if (requestPendingRef.current) return;
215
- setRefreshing(true);
216
- const loaded = await fetchLicenseStatus();
217
- if (loaded && announce) {
218
- toggleNotification({
219
- type: "success",
220
- message: t("license.success.refreshed", "License status checked.")
221
- });
222
- }
223
- };
224
- const handleRefresh = () => checkLicenseStatus({ announce: true });
225
- const handleCopyLicenseKey = async () => {
226
- try {
227
- const copied = await copy(licenseData?.data?.licenseKey || "");
228
- if (!copied) throw new Error("clipboard_unavailable");
229
- toggleNotification({
230
- type: "success",
231
- message: t("license.success.copied", "Copied.")
232
- });
233
- } catch (err) {
234
- logSafeAdminError("license.copyKey", err);
235
- toggleNotification({
236
- type: "danger",
237
- message: t("license.error.copy", "The key could not be copied.")
238
- });
239
- }
240
- };
241
- const handleDownloadLicenseKey = () => {
242
- try {
243
- const content = buildLicenseSummary({
244
- response: licenseData,
245
- translate,
246
- formatDate,
247
- generatedAt: Date.now()
248
- });
249
- const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
250
- const url = window.URL.createObjectURL(blob);
251
- const link = document.createElement("a");
252
- link.href = url;
253
- link.download = "session-manager-license.txt";
254
- document.body.appendChild(link);
255
- link.click();
256
- document.body.removeChild(link);
257
- window.URL.revokeObjectURL(url);
258
- toggleNotification({
259
- type: "success",
260
- message: t("license.success.downloaded", "License details downloaded.")
261
- });
262
- } catch (err) {
263
- logSafeAdminError("license.download", err);
264
- toggleNotification({
265
- type: "danger",
266
- message: t("license.error.download", "The file could not be created.")
267
- });
268
- }
269
- };
270
- useEffect(() => {
271
- fetchLicenseStatus();
272
- }, [fetchLicenseStatus]);
273
- if (loading) {
274
- return /* @__PURE__ */ jsx(Page.Loading, {});
275
- }
276
- if (forbidden) {
277
- return /* @__PURE__ */ jsx(Page.NoPermissions, {});
278
- }
279
- const licenseState = licenseData ? getLicenseState(licenseData) : null;
280
- const hasKey = licenseState?.hasKey === true;
281
- const data = licenseState?.data || {};
282
- const statusMessage = licenseState ? describeLicenseState(licenseState, formatDate) : null;
283
- const yesNo = (value) => value ? t("common.yes", "Yes") : t("common.no", "No");
284
- const detailItems = [
285
- {
286
- id: "holder",
287
- label: t("license.details.holder", "Holder"),
288
- value: getLicenseHolderName(data)
289
- },
290
- {
291
- id: "email",
292
- kind: "email",
293
- label: t("license.account.email", "Email address"),
294
- value: data.email
295
- },
296
- {
297
- id: "expires",
298
- label: t("license.details.expires", "Expires"),
299
- value: licenseState?.expiresAt ? formatDate(licenseState.expiresAt, LICENSE_EXPIRY_DATE_OPTIONS) : t("license.details.noExpiry", "No expiry date")
300
- },
301
- {
302
- id: "device-name",
303
- label: t("license.details.deviceName", "Device name"),
304
- value: data.deviceName
305
- },
306
- {
307
- id: "ip",
308
- kind: "id",
309
- label: t("license.details.ipAddress", "IP address"),
310
- value: data.ipAddress
311
- },
312
- {
313
- id: "last-check",
314
- label: t("license.details.lastCheck", "Last check"),
315
- value: data.lastPingAt ? formatDate(data.lastPingAt) : null
316
- },
317
- {
318
- id: "device-limit",
319
- label: t("license.system.deviceLimit", "Device limit"),
320
- value: t("license.system.deviceLimitValue", "{current} of {max}", {
321
- current: Number(data.currentDevices) || 0,
322
- max: Number(data.maxDevices) || 1
323
- })
324
- },
325
- {
326
- id: "server-reachable",
327
- label: t("license.details.serverReachable", "License server reachable"),
328
- render: /* @__PURE__ */ jsx(Badge, { children: yesNo(licenseState?.serverReachable) })
329
- }
330
- ];
331
- return /* @__PURE__ */ jsxs(
332
- PageShell,
333
- {
334
- headingId: "magic-sessionmanager-license-title",
335
- title: t("license.title", "License"),
336
- subtitle: t("license.subtitle", "Optional license key for this installation."),
337
- primaryAction: /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", justifyContent: "flex-end", children: [
338
- hasKey ? /* @__PURE__ */ jsx(
339
- Button,
340
- {
341
- variant: "secondary",
342
- startIcon: /* @__PURE__ */ jsx(Download, { "aria-hidden": true }),
343
- onClick: handleDownloadLicenseKey,
344
- children: t("license.key.download", "Download as text")
345
- }
346
- ) : null,
347
- /* @__PURE__ */ jsx(
348
- Button,
349
- {
350
- variant: "secondary",
351
- startIcon: /* @__PURE__ */ jsx(ArrowClockwise, { "aria-hidden": true }),
352
- onClick: handleRefresh,
353
- "aria-busy": refreshing,
354
- children: t("license.refresh", "Check again")
355
- }
356
- )
357
- ] }),
358
- children: [
359
- /* @__PURE__ */ jsxs(SectionCard, { title: t("license.status.title", "License status"), children: [
360
- error ? /* @__PURE__ */ jsx(
361
- PersistentAlert,
362
- {
363
- variant: "danger",
364
- closeLabel: t("common.close", "Close"),
365
- action: /* @__PURE__ */ jsx(
366
- Button,
367
- {
368
- variant: "secondary",
369
- onClick: () => checkLicenseStatus({ announce: false }),
370
- "aria-busy": refreshing,
371
- children: t("license.error.retry", "Try again")
372
- }
373
- ),
374
- children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t("license.error.load", "The license status could not be checked.") })
375
- }
376
- ) : null,
377
- /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, "aria-live": "polite", children: [
378
- statusMessage ? /* @__PURE__ */ jsx(
379
- Typography,
380
- {
381
- variant: "omega",
382
- tag: "p",
383
- textColor: "neutral800",
384
- fontWeight: "semiBold",
385
- "data-license-state": "",
386
- children: translate(statusMessage, statusMessage.values)
387
- }
388
- ) : null,
389
- /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral600", tag: "p", children: translate(LICENSE_FEATURES_MESSAGE) })
390
- ] })
391
- ] }),
392
- hasKey ? /* @__PURE__ */ jsx(SectionCard, { title: t("license.details.title", "License details"), children: /* @__PURE__ */ jsx(PropertyList, { items: detailItems }) }) : null,
393
- hasKey ? /* @__PURE__ */ jsx(SectionCard, { title: t("license.key.title", "License key"), children: /* @__PURE__ */ jsxs(
394
- Field.Root,
395
- {
396
- name: "license-key",
397
- id: "magic-sessionmanager-license-key",
398
- hint: t("license.key.hint", "The key stays masked until you reveal it."),
399
- children: [
400
- /* @__PURE__ */ jsx(Field.Label, { children: t("license.key.label", "Stored key") }),
401
- /* @__PURE__ */ jsx(
402
- TextInput,
403
- {
404
- readOnly: true,
405
- autoComplete: "off",
406
- spellCheck: false,
407
- value: showLicenseKey ? data.licenseKey : maskSensitiveValue(data.licenseKey),
408
- endAction: /* @__PURE__ */ jsxs(Flex, { gap: 1, children: [
409
- /* @__PURE__ */ jsx(
410
- IconButton,
411
- {
412
- variant: "ghost",
413
- label: t(
414
- showLicenseKey ? "license.key.hide" : "license.key.show",
415
- showLicenseKey ? "Hide key" : "Show key"
416
- ),
417
- onClick: () => setShowLicenseKey((visible) => !visible),
418
- children: showLicenseKey ? /* @__PURE__ */ jsx(EyeStriked, { "aria-hidden": true }) : /* @__PURE__ */ jsx(Eye, { "aria-hidden": true })
419
- }
420
- ),
421
- /* @__PURE__ */ jsx(
422
- IconButton,
423
- {
424
- variant: "ghost",
425
- label: t("license.key.copy", "Copy key"),
426
- onClick: handleCopyLicenseKey,
427
- children: /* @__PURE__ */ jsx(Duplicate, { "aria-hidden": true })
428
- }
429
- )
430
- ] })
431
- }
432
- ),
433
- /* @__PURE__ */ jsx(Field.Hint, {})
434
- ]
435
- }
436
- ) }) : null
437
- ]
438
- }
439
- );
440
- };
441
- export {
442
- LicensePage as default
443
- };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- const KEY_MASK = "••••••••";
3
- function maskSensitiveValue(value) {
4
- if (typeof value !== "string" || value.length <= 4) {
5
- return KEY_MASK;
6
- }
7
- return `${KEY_MASK}${value.slice(-4)}`;
8
- }
9
- exports.maskSensitiveValue = maskSensitiveValue;
@@ -1,10 +0,0 @@
1
- const KEY_MASK = "••••••••";
2
- function maskSensitiveValue(value) {
3
- if (typeof value !== "string" || value.length <= 4) {
4
- return KEY_MASK;
5
- }
6
- return `${KEY_MASK}${value.slice(-4)}`;
7
- }
8
- export {
9
- maskSensitiveValue as m
10
- };