strapi-plugin-oidc 1.6.5 → 1.7.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.
@@ -1,841 +0,0 @@
1
- import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
- import { useBlocker, Routes, Route } from "react-router-dom";
3
- import { useNotification, useFetchClient, Page, Layouts } from "@strapi/strapi/admin";
4
- import { useState, useRef, useCallback, useEffect, memo } from "react";
5
- import { Typography, Flex, Box, MultiSelect, MultiSelectOption, Dialog, Button, Table, Pagination, PreviousLink, NextLink, PageLink, Field, Divider, Thead, Tr, Th, Tbody, Td, IconButton, Tooltip, Alert } from "@strapi/design-system";
6
- import { WarningCircle, Download, Upload, Trash, Plus, Information } from "@strapi/icons";
7
- import { useIntl } from "react-intl";
8
- import { g as getTrad } from "./index-DgUClS5s.mjs";
9
- import styled from "styled-components";
10
- function Role({ oidcRoles, roles, onChangeRole }) {
11
- const { formatMessage } = useIntl();
12
- return /* @__PURE__ */ jsxs(Fragment, { children: [
13
- /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textColor: "neutral600", marginBottom: 4, children: formatMessage(getTrad("roles.notes")) }),
14
- /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 4, marginBottom: 4, children: oidcRoles.map((oidcRole) => /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
15
- MultiSelect,
16
- {
17
- withTags: true,
18
- placeholder: formatMessage(getTrad("roles.placeholder")),
19
- value: oidcRole.role ? oidcRole.role.map((r) => String(r)) : [],
20
- onChange: (value) => {
21
- if (value && value.length > 0) onChangeRole(value, oidcRole.oauth_type);
22
- },
23
- children: roles.map((role) => /* @__PURE__ */ jsx(MultiSelectOption, { value: String(role.id), children: role.name }, role.id))
24
- }
25
- ) }, oidcRole.oauth_type)) })
26
- ] });
27
- }
28
- function LocalizedDate({
29
- date,
30
- options
31
- }) {
32
- const userLocale = navigator.language || "en-US";
33
- return new Intl.DateTimeFormat(userLocale, {
34
- year: "numeric",
35
- month: "short",
36
- day: "numeric",
37
- hour: "2-digit",
38
- minute: "2-digit",
39
- ...options
40
- }).format(new Date(date));
41
- }
42
- const CustomTable = styled(Table)`
43
- th,
44
- td,
45
- th span,
46
- td span {
47
- font-size: 1.3rem !important;
48
- }
49
- `;
50
- function ConfirmDialog({
51
- trigger,
52
- title,
53
- body,
54
- confirmLabel,
55
- onConfirm,
56
- confirmVariant = "danger"
57
- }) {
58
- const { formatMessage } = useIntl();
59
- return /* @__PURE__ */ jsxs(Dialog.Root, { children: [
60
- /* @__PURE__ */ jsx(Dialog.Trigger, { children: trigger }),
61
- /* @__PURE__ */ jsxs(Dialog.Content, { children: [
62
- /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
63
- /* @__PURE__ */ jsx(Dialog.Body, { icon: /* @__PURE__ */ jsx(WarningCircle, { fill: "danger600" }), children: body }),
64
- /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
65
- /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, variant: "tertiary", children: formatMessage(getTrad("page.cancel")) }) }),
66
- /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, variant: confirmVariant, onClick: onConfirm, children: confirmLabel }) })
67
- ] })
68
- ] })
69
- ] });
70
- }
71
- function TablePagination({ page, pageCount, onPageChange }) {
72
- const { formatMessage } = useIntl();
73
- if (pageCount <= 1) return null;
74
- const handleClick = (e, num) => {
75
- e.preventDefault();
76
- onPageChange(num);
77
- };
78
- const pageLink = (num) => /* @__PURE__ */ jsx(PageLink, { number: num, href: "#", onClick: (e) => handleClick(e, num), children: formatMessage(getTrad("pagination.page"), { page: num }) }, num);
79
- const Ellipsis = () => /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", paddingLeft: 2, paddingRight: 2, children: "…" });
80
- let pages;
81
- if (pageCount <= 10) {
82
- pages = Array.from({ length: pageCount }, (_, i) => pageLink(i + 1));
83
- } else if (page <= 6) {
84
- pages = /* @__PURE__ */ jsxs(Fragment, { children: [
85
- Array.from({ length: 9 }, (_, i) => pageLink(i + 1)),
86
- /* @__PURE__ */ jsx(Ellipsis, {}),
87
- pageLink(pageCount)
88
- ] });
89
- } else if (page >= pageCount - 5) {
90
- pages = /* @__PURE__ */ jsxs(Fragment, { children: [
91
- pageLink(1),
92
- /* @__PURE__ */ jsx(Ellipsis, {}),
93
- Array.from({ length: 9 }, (_, i) => pageLink(pageCount - 8 + i))
94
- ] });
95
- } else {
96
- pages = /* @__PURE__ */ jsxs(Fragment, { children: [
97
- pageLink(1),
98
- /* @__PURE__ */ jsx(Ellipsis, {}),
99
- Array.from({ length: 7 }, (_, i) => pageLink(page - 3 + i)),
100
- /* @__PURE__ */ jsx(Ellipsis, {}),
101
- pageLink(pageCount)
102
- ] });
103
- }
104
- return /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxs(Pagination, { activePage: page, pageCount, children: [
105
- /* @__PURE__ */ jsx(PreviousLink, { href: "#", onClick: (e) => handleClick(e, Math.max(1, page - 1)), children: formatMessage(getTrad("pagination.previous")) }),
106
- pages,
107
- /* @__PURE__ */ jsx(NextLink, { href: "#", onClick: (e) => handleClick(e, Math.min(pageCount, page + 1)), children: formatMessage(getTrad("pagination.next")) })
108
- ] }) }) });
109
- }
110
- const PAGE_SIZE$1 = 10;
111
- const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
112
- function Whitelist({
113
- users,
114
- useWhitelist,
115
- loading,
116
- onSave,
117
- onDelete,
118
- onDeleteAll,
119
- onImport,
120
- onExport
121
- }) {
122
- const [email, setEmail] = useState("");
123
- const [page, setPage] = useState(1);
124
- const { formatMessage } = useIntl();
125
- const { toggleNotification } = useNotification();
126
- const fileInputRef = useRef(null);
127
- const pageCount = Math.ceil(users.length / PAGE_SIZE$1) || 1;
128
- const paginatedUsers = users.slice((page - 1) * PAGE_SIZE$1, page * PAGE_SIZE$1);
129
- const onSaveEmail = useCallback(() => {
130
- const emailText = email.trim();
131
- if (users.some((user) => user.email === emailText)) {
132
- toggleNotification({
133
- type: "warning",
134
- message: formatMessage(getTrad("whitelist.error.unique"))
135
- });
136
- } else {
137
- onSave(emailText);
138
- setEmail("");
139
- }
140
- }, [email, users, onSave, formatMessage, toggleNotification]);
141
- const handleImport = useCallback(
142
- async (e) => {
143
- const file = e.target.files?.[0];
144
- if (!fileInputRef.current || !file) return;
145
- fileInputRef.current.value = "";
146
- try {
147
- const text = await file.text();
148
- const parsed = JSON.parse(text);
149
- if (!Array.isArray(parsed)) throw new Error();
150
- const emails = parsed.filter((item) => item?.email).map(
151
- (item) => String(item.email).trim().toLowerCase()
152
- ).filter((email2) => EMAIL_REGEX.test(email2));
153
- const count = await onImport(emails);
154
- if (count === 0) {
155
- toggleNotification({
156
- type: "info",
157
- message: formatMessage(getTrad("whitelist.import.none"))
158
- });
159
- } else {
160
- toggleNotification({
161
- type: "success",
162
- message: formatMessage(getTrad("whitelist.import.success"), { count })
163
- });
164
- }
165
- } catch {
166
- toggleNotification({
167
- type: "warning",
168
- message: formatMessage(getTrad("whitelist.import.error"))
169
- });
170
- }
171
- },
172
- [onImport, formatMessage, toggleNotification]
173
- );
174
- return /* @__PURE__ */ jsxs(Box, { children: [
175
- /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textColor: "neutral600", marginBottom: 4, children: formatMessage(getTrad("whitelist.description")) }),
176
- useWhitelist && /* @__PURE__ */ jsxs(Fragment, { children: [
177
- /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 4, children: [
178
- /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: formatMessage(getTrad("whitelist.count"), { count: users.length }) }),
179
- /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
180
- /* @__PURE__ */ jsx(
181
- Button,
182
- {
183
- size: "S",
184
- variant: "tertiary",
185
- startIcon: /* @__PURE__ */ jsx(Download, {}),
186
- onClick: onExport,
187
- disabled: users.length === 0,
188
- children: formatMessage(getTrad("whitelist.export"))
189
- }
190
- ),
191
- /* @__PURE__ */ jsx(
192
- Button,
193
- {
194
- size: "S",
195
- variant: "tertiary",
196
- startIcon: /* @__PURE__ */ jsx(Upload, {}),
197
- onClick: () => fileInputRef.current?.click(),
198
- children: formatMessage(getTrad("whitelist.import"))
199
- }
200
- ),
201
- /* @__PURE__ */ jsx(
202
- "input",
203
- {
204
- ref: fileInputRef,
205
- type: "file",
206
- accept: ".json,application/json",
207
- style: { display: "none" },
208
- onChange: handleImport
209
- }
210
- ),
211
- users.length > 0 && /* @__PURE__ */ jsx(
212
- ConfirmDialog,
213
- {
214
- trigger: /* @__PURE__ */ jsx(Button, { size: "S", variant: "danger-light", startIcon: /* @__PURE__ */ jsx(Trash, {}), children: formatMessage(getTrad("whitelist.delete.all.label")) }),
215
- title: formatMessage(getTrad("whitelist.delete.all.title")),
216
- body: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", textAlign: "center", children: formatMessage(getTrad("whitelist.delete.all.description"), {
217
- count: users.length
218
- }) }) }),
219
- confirmLabel: formatMessage(getTrad("whitelist.delete.all.label")),
220
- onConfirm: onDeleteAll
221
- }
222
- )
223
- ] })
224
- ] }),
225
- /* @__PURE__ */ jsxs(Flex, { gap: 4, marginTop: 5, marginBottom: 5, alignItems: "flex-start", children: [
226
- /* @__PURE__ */ jsx(Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsx(Field.Root, { children: /* @__PURE__ */ jsx(
227
- Field.Input,
228
- {
229
- type: "text",
230
- disabled: loading,
231
- value: email,
232
- hasError: Boolean(email && !EMAIL_REGEX.test(email)),
233
- onChange: (e) => setEmail(e.currentTarget.value),
234
- placeholder: formatMessage(getTrad("whitelist.email.placeholder"))
235
- }
236
- ) }) }),
237
- /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
238
- Button,
239
- {
240
- size: "L",
241
- startIcon: /* @__PURE__ */ jsx(Plus, {}),
242
- disabled: loading || email.trim() === "" || !EMAIL_REGEX.test(email),
243
- loading,
244
- onClick: onSaveEmail,
245
- children: formatMessage(getTrad("page.add"))
246
- }
247
- ) })
248
- ] }),
249
- /* @__PURE__ */ jsx(Divider, {}),
250
- /* @__PURE__ */ jsxs(CustomTable, { colCount: 4, rowCount: users.length, children: [
251
- /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
252
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.no")) }),
253
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.email")) }),
254
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("whitelist.table.created")) }),
255
- /* @__PURE__ */ jsx(Th, { style: { paddingRight: 0 }, children: " " })
256
- ] }) }),
257
- /* @__PURE__ */ jsx(Tbody, { children: users.length === 0 ? /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 4, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage(getTrad("whitelist.table.empty")) }) }) }) }) : paginatedUsers.map((user, index) => /* @__PURE__ */ jsxs(Tr, { children: [
258
- /* @__PURE__ */ jsx(Td, { children: index + 1 + (page - 1) * PAGE_SIZE$1 }),
259
- /* @__PURE__ */ jsx(Td, { children: user.email }),
260
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(LocalizedDate, { date: user.createdAt, options: { month: "long" } }) }),
261
- /* @__PURE__ */ jsx(Td, { style: { paddingRight: 0 }, children: /* @__PURE__ */ jsx(
262
- Flex,
263
- {
264
- justifyContent: "flex-end",
265
- onClick: (e) => e.stopPropagation(),
266
- style: { width: "100%" },
267
- children: /* @__PURE__ */ jsx(
268
- ConfirmDialog,
269
- {
270
- trigger: /* @__PURE__ */ jsx(
271
- IconButton,
272
- {
273
- label: formatMessage(getTrad("whitelist.delete.label")),
274
- withTooltip: false,
275
- children: /* @__PURE__ */ jsx(Trash, {})
276
- }
277
- ),
278
- title: formatMessage(getTrad("whitelist.delete.title")),
279
- body: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "center", gap: 2, children: [
280
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { id: "confirm-description", children: formatMessage(getTrad("whitelist.delete.description")) }) }),
281
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", children: user.email }) }),
282
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", marginTop: 2, children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: formatMessage(getTrad("whitelist.delete.note")) }) })
283
- ] }),
284
- confirmLabel: formatMessage(getTrad("page.ok")),
285
- onConfirm: () => onDelete(user.email),
286
- confirmVariant: "danger-light"
287
- }
288
- )
289
- }
290
- ) })
291
- ] }, user.email)) })
292
- ] }),
293
- /* @__PURE__ */ jsx(TablePagination, { page, pageCount, onPageChange: setPage })
294
- ] })
295
- ] });
296
- }
297
- const PAGE_SIZE = 10;
298
- const DETAILS_TEXT_STYLE = {
299
- display: "block",
300
- overflow: "hidden",
301
- textOverflow: "ellipsis",
302
- whiteSpace: "nowrap",
303
- maxWidth: "180px",
304
- cursor: "help"
305
- };
306
- function AuditLog() {
307
- const { formatMessage } = useIntl();
308
- const { get, del } = useFetchClient();
309
- const { toggleNotification } = useNotification();
310
- const [records, setRecords] = useState([]);
311
- const [pagination, setPagination] = useState({
312
- page: 1,
313
- pageSize: PAGE_SIZE,
314
- total: 0,
315
- pageCount: 1
316
- });
317
- const [page, setPage] = useState(1);
318
- const [loading, setLoading] = useState(false);
319
- const fetchLogs = useCallback(
320
- async (p) => {
321
- setLoading(true);
322
- try {
323
- const response = await get(
324
- `/strapi-plugin-oidc/audit-logs?page=${p}&pageSize=${PAGE_SIZE}`
325
- );
326
- setRecords(response.data.results ?? []);
327
- setPagination(
328
- response.data.pagination ?? { page: p, pageSize: PAGE_SIZE, total: 0, pageCount: 1 }
329
- );
330
- } catch {
331
- setRecords([]);
332
- } finally {
333
- setLoading(false);
334
- }
335
- },
336
- [get]
337
- );
338
- useEffect(() => {
339
- fetchLogs(page);
340
- }, [fetchLogs, page]);
341
- const handleClearAll = async () => {
342
- try {
343
- await del("/strapi-plugin-oidc/audit-logs");
344
- toggleNotification({
345
- type: "success",
346
- message: formatMessage(getTrad("auditlog.clear.success"))
347
- });
348
- fetchLogs(1);
349
- } catch {
350
- toggleNotification({
351
- type: "danger",
352
- message: formatMessage(getTrad("auditlog.clear.error"))
353
- });
354
- }
355
- };
356
- const handleExport = async () => {
357
- try {
358
- const cookieMatch = document.cookie.match(/(?:^|;\s*)jwtToken=([^;]+)/);
359
- const token = cookieMatch ? decodeURIComponent(cookieMatch[1]) : "";
360
- const response = await fetch("/strapi-plugin-oidc/audit-logs/export", {
361
- headers: { Authorization: `Bearer ${token}` }
362
- });
363
- if (!response.ok) {
364
- toggleNotification({
365
- type: "danger",
366
- message: formatMessage(getTrad("auditlog.export.error"))
367
- });
368
- return;
369
- }
370
- const text = await response.text();
371
- const blob = new Blob([text], { type: "application/x-ndjson" });
372
- const url = URL.createObjectURL(blob);
373
- const a = document.createElement("a");
374
- a.href = url;
375
- a.download = `oidc-audit-log-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.ndjson`;
376
- a.click();
377
- URL.revokeObjectURL(url);
378
- } catch {
379
- toggleNotification({
380
- type: "danger",
381
- message: formatMessage(getTrad("auditlog.export.error"))
382
- });
383
- }
384
- };
385
- return /* @__PURE__ */ jsxs(Box, { children: [
386
- /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 4, children: [
387
- /* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral600", children: [
388
- pagination.total,
389
- " ",
390
- pagination.total === 1 ? "entry" : "entries"
391
- ] }),
392
- /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
393
- /* @__PURE__ */ jsx(
394
- Button,
395
- {
396
- size: "S",
397
- variant: "tertiary",
398
- startIcon: /* @__PURE__ */ jsx(Download, {}),
399
- onClick: handleExport,
400
- disabled: pagination.total === 0,
401
- children: formatMessage(getTrad("auditlog.export"))
402
- }
403
- ),
404
- /* @__PURE__ */ jsx(
405
- ConfirmDialog,
406
- {
407
- trigger: /* @__PURE__ */ jsx(
408
- Button,
409
- {
410
- size: "S",
411
- variant: "danger-light",
412
- startIcon: /* @__PURE__ */ jsx(Trash, {}),
413
- disabled: pagination.total === 0,
414
- children: formatMessage(getTrad("auditlog.clear"))
415
- }
416
- ),
417
- title: formatMessage(getTrad("auditlog.clear.title")),
418
- body: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", textAlign: "center", children: formatMessage(getTrad("auditlog.clear.description"), {
419
- count: pagination.total
420
- }) }) }),
421
- confirmLabel: formatMessage(getTrad("auditlog.clear")),
422
- onConfirm: handleClearAll
423
- }
424
- )
425
- ] })
426
- ] }),
427
- /* @__PURE__ */ jsxs(CustomTable, { colCount: 5, rowCount: records.length, children: [
428
- /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
429
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("auditlog.table.timestamp")) }),
430
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("auditlog.table.action")) }),
431
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("auditlog.table.email")) }),
432
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("auditlog.table.ip")) }),
433
- /* @__PURE__ */ jsx(Th, { children: formatMessage(getTrad("auditlog.table.details")) })
434
- ] }) }),
435
- /* @__PURE__ */ jsxs(Tbody, { children: [
436
- loading && /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 5, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage(getTrad("auditlog.loading")) }) }) }) }),
437
- !loading && records.length === 0 && /* @__PURE__ */ jsx(Tr, { children: /* @__PURE__ */ jsx(Td, { colSpan: 5, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage(getTrad("auditlog.table.empty")) }) }) }) }),
438
- !loading && records.map((record) => /* @__PURE__ */ jsxs(Tr, { children: [
439
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: /* @__PURE__ */ jsx(LocalizedDate, { date: record.createdAt, options: { second: "2-digit" } }) }) }),
440
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
441
- /* @__PURE__ */ jsx(Typography, { variant: "omega", children: record.action }),
442
- /* @__PURE__ */ jsx(Tooltip, { label: formatMessage(getTrad(`auditlog.action.${record.action}`)), children: /* @__PURE__ */ jsx(
443
- Information,
444
- {
445
- "aria-hidden": true,
446
- style: { cursor: "help" },
447
- width: "1.4rem",
448
- height: "1.4rem",
449
- fill: "primary600"
450
- }
451
- ) })
452
- ] }) }),
453
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: record.email ?? "—" }) }),
454
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: record.ip ?? "—" }) }),
455
- /* @__PURE__ */ jsx(Td, { style: { maxWidth: "200px" }, children: record.details ? /* @__PURE__ */ jsx(Tooltip, { label: record.details, side: "top", children: /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", style: DETAILS_TEXT_STYLE, children: record.details }) }) : /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: "—" }) })
456
- ] }, record.id))
457
- ] })
458
- ] }),
459
- /* @__PURE__ */ jsx(TablePagination, { page, pageCount: pagination.pageCount, onPageChange: setPage })
460
- ] });
461
- }
462
- const AlertMessage = styled.div`
463
- position: fixed;
464
- left: 50%;
465
- transform: translateX(-50%);
466
- top: 2.875rem;
467
- z-index: 10;
468
- width: 31.25rem;
469
- `;
470
- function SuccessAlertMessage({ onClose }) {
471
- const { formatMessage } = useIntl();
472
- return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
473
- Alert,
474
- {
475
- title: formatMessage(getTrad("alert.title.success")),
476
- variant: "success",
477
- closeLabel: "",
478
- onClose,
479
- children: formatMessage(getTrad("page.save.success"))
480
- }
481
- ) });
482
- }
483
- function ErrorAlertMessage({ onClose }) {
484
- const { formatMessage } = useIntl();
485
- return /* @__PURE__ */ jsx(AlertMessage, { children: /* @__PURE__ */ jsx(
486
- Alert,
487
- {
488
- title: formatMessage(getTrad("alert.title.error")),
489
- variant: "danger",
490
- closeLabel: "",
491
- onClose,
492
- children: formatMessage(getTrad("page.save.error"))
493
- }
494
- ) });
495
- }
496
- const SwitchContainer = styled.label`
497
- position: relative;
498
- display: inline-block;
499
- width: 40px;
500
- height: 24px;
501
- cursor: ${({ $disabled }) => $disabled ? "not-allowed" : "pointer"};
502
- opacity: ${({ $disabled }) => $disabled ? 0.5 : 1};
503
- `;
504
- const SwitchInput = styled.input`
505
- opacity: 0;
506
- width: 0;
507
- height: 0;
508
-
509
- &:checked + span {
510
- background-color: ${({ theme }) => theme.colors.primary600};
511
- }
512
-
513
- &:focus + span {
514
- box-shadow: 0 0 1px ${({ theme }) => theme.colors.primary600};
515
- }
516
-
517
- &:checked + span:before {
518
- transform: translateX(16px);
519
- }
520
-
521
- &:disabled + span {
522
- pointer-events: none;
523
- }
524
- `;
525
- const SwitchSlider = styled.span`
526
- position: absolute;
527
- cursor: inherit;
528
- top: 0;
529
- left: 0;
530
- right: 0;
531
- bottom: 0;
532
- background-color: ${({ theme }) => theme.colors.neutral300};
533
- transition: 0.4s;
534
- border-radius: 24px;
535
-
536
- &:before {
537
- position: absolute;
538
- content: "";
539
- height: 18px;
540
- width: 18px;
541
- left: 3px;
542
- bottom: 3px;
543
- background-color: white;
544
- transition: 0.4s;
545
- border-radius: 50%;
546
- }
547
- `;
548
- function CustomSwitch({ checked, onChange, label, disabled }) {
549
- return /* @__PURE__ */ jsxs(Flex, { gap: 3, children: [
550
- /* @__PURE__ */ jsxs(SwitchContainer, { $disabled: disabled, children: [
551
- /* @__PURE__ */ jsx(
552
- SwitchInput,
553
- {
554
- type: "checkbox",
555
- checked,
556
- onChange,
557
- disabled
558
- }
559
- ),
560
- /* @__PURE__ */ jsx(SwitchSlider, {})
561
- ] }),
562
- label && /* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", textColor: disabled ? "neutral500" : "neutral800", children: label })
563
- ] });
564
- }
565
- function formatDatetimeForFilename(date) {
566
- const year = date.getFullYear();
567
- const month = String(date.getMonth() + 1).padStart(2, "0");
568
- const day = String(date.getDate()).padStart(2, "0");
569
- const hours = String(date.getHours()).padStart(2, "0");
570
- const minutes = String(date.getMinutes()).padStart(2, "0");
571
- const seconds = String(date.getSeconds()).padStart(2, "0");
572
- return `${year}${month}${day}_${hours}${minutes}${seconds}`;
573
- }
574
- function deepClone(value) {
575
- return JSON.parse(JSON.stringify(value));
576
- }
577
- function useOidcSettings() {
578
- const { get, put, post } = useFetchClient();
579
- const [loading, setLoading] = useState(false);
580
- const [showSuccess, setSuccess] = useState(false);
581
- const [showError, setError] = useState(false);
582
- const [initialOidcRoles, setInitialOIDCRoles] = useState([]);
583
- const [oidcRoles, setOIDCRoles] = useState([]);
584
- const [roles, setRoles] = useState([]);
585
- const [initialUseWhitelist, setInitialUseWhitelist] = useState(false);
586
- const [useWhitelist, setUseWhitelist] = useState(false);
587
- const [initialEnforceOIDC, setInitialEnforceOIDC] = useState(false);
588
- const [enforceOIDC, setEnforceOIDC] = useState(false);
589
- const [enforceOIDCConfig, setEnforceOIDCConfig] = useState(null);
590
- const [initialUsers, setInitialUsers] = useState([]);
591
- const [users, setUsers] = useState([]);
592
- const [whitelistResponse, setWhitelistResponse] = useState({});
593
- useEffect(() => {
594
- get(`/strapi-plugin-oidc/oidc-roles`).then((response) => {
595
- setOIDCRoles(response.data);
596
- setInitialOIDCRoles(deepClone(response.data));
597
- });
598
- get(`/admin/roles`).then((response) => {
599
- setRoles(response.data.data);
600
- });
601
- get("/strapi-plugin-oidc/whitelist").then((response) => {
602
- const data = response.data;
603
- setWhitelistResponse(data);
604
- setUsers(data.whitelistUsers);
605
- setInitialUsers(deepClone(data.whitelistUsers));
606
- setUseWhitelist(data.useWhitelist);
607
- setInitialUseWhitelist(data.useWhitelist);
608
- setEnforceOIDC(data.enforceOIDC);
609
- setInitialEnforceOIDC(data.enforceOIDC);
610
- setEnforceOIDCConfig(data.enforceOIDCConfig ?? null);
611
- });
612
- }, [get]);
613
- const onChangeRole = useCallback((values, oidcId) => {
614
- setOIDCRoles(
615
- (prev) => prev.map((role) => role.oauth_type === oidcId ? { ...role, role: values } : role)
616
- );
617
- }, []);
618
- const onRegisterWhitelist = useCallback((email) => {
619
- setUsers((prev) => [...prev, { email, createdAt: (/* @__PURE__ */ new Date()).toISOString() }]);
620
- }, []);
621
- const onDeleteWhitelist = useCallback(
622
- (email) => {
623
- setUsers((prev) => {
624
- const updated = prev.filter((u) => u.email !== email);
625
- if (useWhitelist && updated.length === 0) setEnforceOIDC(false);
626
- return updated;
627
- });
628
- },
629
- [useWhitelist]
630
- );
631
- const onDeleteAll = useCallback(() => {
632
- setUsers([]);
633
- if (useWhitelist) setEnforceOIDC(false);
634
- }, [useWhitelist]);
635
- const onImport = useCallback(
636
- async (emails) => {
637
- const response = await post("/strapi-plugin-oidc/whitelist/import", {
638
- users: emails.map((e) => ({ email: e }))
639
- });
640
- const refreshed = await get("/strapi-plugin-oidc/whitelist");
641
- setUsers(refreshed.data.whitelistUsers);
642
- setInitialUsers(deepClone(refreshed.data.whitelistUsers));
643
- return response.data.importedCount;
644
- },
645
- [post, get]
646
- );
647
- const onExport = useCallback(async () => {
648
- const response = await get("/strapi-plugin-oidc/whitelist/export");
649
- const data = response.data;
650
- const datetime = formatDatetimeForFilename(/* @__PURE__ */ new Date());
651
- const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
652
- const url = URL.createObjectURL(blob);
653
- const a = document.createElement("a");
654
- a.href = url;
655
- a.download = `strapi-oidc-whitelist-${datetime}.json`;
656
- a.click();
657
- URL.revokeObjectURL(url);
658
- }, [get]);
659
- const onToggleWhitelist = useCallback(
660
- (e) => {
661
- const checked = e.target.checked;
662
- setUseWhitelist(checked);
663
- if (checked && users.length === 0) setEnforceOIDC(false);
664
- },
665
- [users.length]
666
- );
667
- const onToggleEnforce = useCallback((e) => {
668
- setEnforceOIDC(e.target.checked);
669
- }, []);
670
- const isDirty = useWhitelist !== initialUseWhitelist || enforceOIDC !== initialEnforceOIDC || JSON.stringify(oidcRoles) !== JSON.stringify(initialOidcRoles) || JSON.stringify(users) !== JSON.stringify(initialUsers);
671
- const onSaveAll = useCallback(async () => {
672
- setLoading(true);
673
- try {
674
- await put("/strapi-plugin-oidc/oidc-roles", {
675
- roles: oidcRoles.map((role) => ({ oauth_type: role.oauth_type, role: role.role }))
676
- });
677
- await put("/strapi-plugin-oidc/whitelist/sync", {
678
- users: users.map((u) => ({ email: u.email }))
679
- });
680
- await put("/strapi-plugin-oidc/whitelist/settings", { useWhitelist, enforceOIDC });
681
- setInitialOIDCRoles(deepClone(oidcRoles));
682
- setInitialUseWhitelist(useWhitelist);
683
- setInitialEnforceOIDC(enforceOIDC);
684
- get("/strapi-plugin-oidc/whitelist").then((getResponse) => {
685
- const data = getResponse.data;
686
- setWhitelistResponse(data);
687
- setUsers(data.whitelistUsers);
688
- setInitialUsers(deepClone(data.whitelistUsers));
689
- });
690
- setSuccess(true);
691
- setTimeout(() => setSuccess(false), 3e3);
692
- } catch (e) {
693
- console.error(e);
694
- setError(true);
695
- setTimeout(() => setError(false), 3e3);
696
- } finally {
697
- setLoading(false);
698
- }
699
- }, [put, get, oidcRoles, users, useWhitelist, enforceOIDC]);
700
- return {
701
- state: {
702
- loading,
703
- showSuccess,
704
- showError,
705
- oidcRoles,
706
- roles,
707
- useWhitelist,
708
- enforceOIDC,
709
- enforceOIDCConfig,
710
- initialEnforceOIDC,
711
- users,
712
- isDirty,
713
- auditLogEnabled: whitelistResponse.auditLogEnabled ?? true
714
- },
715
- actions: {
716
- setSuccess,
717
- setError,
718
- onChangeRole,
719
- onRegisterWhitelist,
720
- onDeleteWhitelist,
721
- onDeleteAll,
722
- onImport,
723
- onExport,
724
- onToggleWhitelist,
725
- onToggleEnforce,
726
- onSaveAll
727
- }
728
- };
729
- }
730
- function HomePage() {
731
- const { formatMessage } = useIntl();
732
- const { state, actions } = useOidcSettings();
733
- const blocker = useBlocker(state.isDirty);
734
- return /* @__PURE__ */ jsxs(Page.Protect, { permissions: [{ action: "plugin::strapi-plugin-oidc.read", subject: null }], children: [
735
- /* @__PURE__ */ jsx(
736
- Layouts.Header,
737
- {
738
- title: formatMessage(getTrad("page.title.oidc")),
739
- subtitle: formatMessage(getTrad("page.title"))
740
- }
741
- ),
742
- state.showSuccess && /* @__PURE__ */ jsx(SuccessAlertMessage, { onClose: () => actions.setSuccess(false) }),
743
- state.showError && /* @__PURE__ */ jsx(ErrorAlertMessage, { onClose: () => actions.setError(false) }),
744
- /* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
745
- /* @__PURE__ */ jsxs(Box, { background: "neutral0", hasRadius: true, shadow: "filterShadow", padding: 6, children: [
746
- /* @__PURE__ */ jsx(Box, { paddingBottom: 4, children: /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: formatMessage(getTrad("roles.title")) }) }),
747
- /* @__PURE__ */ jsx(
748
- Role,
749
- {
750
- roles: state.roles,
751
- oidcRoles: state.oidcRoles,
752
- onChangeRole: actions.onChangeRole
753
- }
754
- )
755
- ] }),
756
- /* @__PURE__ */ jsxs(Box, { background: "neutral0", hasRadius: true, shadow: "filterShadow", padding: 6, children: [
757
- /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", paddingBottom: 4, children: [
758
- /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: formatMessage(getTrad("whitelist.title")) }),
759
- /* @__PURE__ */ jsx(
760
- CustomSwitch,
761
- {
762
- checked: state.useWhitelist,
763
- onChange: actions.onToggleWhitelist,
764
- label: state.useWhitelist ? formatMessage(getTrad("whitelist.toggle.enabled")) : formatMessage(getTrad("whitelist.toggle.disabled"))
765
- }
766
- )
767
- ] }),
768
- /* @__PURE__ */ jsx(
769
- Whitelist,
770
- {
771
- loading: state.loading,
772
- users: state.users,
773
- useWhitelist: state.useWhitelist,
774
- onSave: actions.onRegisterWhitelist,
775
- onDelete: actions.onDeleteWhitelist,
776
- onDeleteAll: actions.onDeleteAll,
777
- onImport: actions.onImport,
778
- onExport: actions.onExport
779
- }
780
- )
781
- ] }),
782
- /* @__PURE__ */ jsxs(Box, { background: "neutral0", hasRadius: true, shadow: "filterShadow", padding: 6, children: [
783
- /* @__PURE__ */ jsx(Box, { paddingBottom: 6, children: /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: formatMessage(getTrad("login.settings.title")) }) }),
784
- /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
785
- /* @__PURE__ */ jsxs(Flex, { alignItems: "center", gap: 3, wrap: "wrap", children: [
786
- /* @__PURE__ */ jsx(Typography, { variant: "omega", style: { minWidth: "280px" }, children: formatMessage(getTrad("enforce.title")) }),
787
- /* @__PURE__ */ jsx(Box, { minWidth: "160px", children: /* @__PURE__ */ jsx(
788
- CustomSwitch,
789
- {
790
- checked: state.enforceOIDC,
791
- onChange: actions.onToggleEnforce,
792
- disabled: state.enforceOIDCConfig !== null || state.useWhitelist && state.users.length === 0,
793
- label: state.enforceOIDC ? formatMessage(getTrad("enforce.toggle.enabled")) : formatMessage(getTrad("enforce.toggle.disabled"))
794
- }
795
- ) })
796
- ] }),
797
- state.enforceOIDCConfig !== null && /* @__PURE__ */ jsx(Box, { background: "primary100", padding: 3, hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", children: [
798
- /* @__PURE__ */ jsx(Information, { fill: "primary600" }),
799
- /* @__PURE__ */ jsx(Typography, { textColor: "primary600", children: formatMessage(getTrad("enforce.config.info")) })
800
- ] }) }),
801
- state.enforceOIDCConfig === null && state.enforceOIDC && state.enforceOIDC !== state.initialEnforceOIDC && /* @__PURE__ */ jsx(Box, { background: "danger100", padding: 3, hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", children: [
802
- /* @__PURE__ */ jsx(WarningCircle, { fill: "danger600" }),
803
- /* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: formatMessage(getTrad("enforce.warning")) })
804
- ] }) })
805
- ] })
806
- ] }),
807
- /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsx(
808
- Button,
809
- {
810
- size: "L",
811
- onClick: actions.onSaveAll,
812
- disabled: !state.isDirty || state.loading,
813
- loading: state.loading,
814
- children: formatMessage(getTrad("page.save"))
815
- }
816
- ) }),
817
- state.auditLogEnabled && /* @__PURE__ */ jsxs(Box, { background: "neutral0", hasRadius: true, shadow: "filterShadow", padding: 6, children: [
818
- /* @__PURE__ */ jsx(Box, { paddingBottom: 4, children: /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: formatMessage(getTrad("auditlog.title")) }) }),
819
- /* @__PURE__ */ jsx(AuditLog, {})
820
- ] })
821
- ] }) }),
822
- /* @__PURE__ */ jsx(Dialog.Root, { open: blocker.state === "blocked", children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
823
- /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage(getTrad("unsaved.title")) }),
824
- /* @__PURE__ */ jsx(Dialog.Body, { children: formatMessage(getTrad("unsaved.description")) }),
825
- /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
826
- /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: () => blocker.reset?.(), children: formatMessage(getTrad("unsaved.cancel")) }) }),
827
- /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(Button, { variant: "danger", onClick: () => blocker.proceed?.(), children: formatMessage(getTrad("unsaved.confirm")) }) })
828
- ] })
829
- ] }) })
830
- ] });
831
- }
832
- const HomePage$1 = memo(HomePage);
833
- function App() {
834
- return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(Routes, { children: [
835
- /* @__PURE__ */ jsx(Route, { index: true, element: /* @__PURE__ */ jsx(HomePage$1, {}) }),
836
- /* @__PURE__ */ jsx(Route, { path: "*", element: /* @__PURE__ */ jsx(Page.Error, {}) })
837
- ] }) });
838
- }
839
- export {
840
- App as default
841
- };