strapi-plugin-oidc 1.6.3 → 1.6.5

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.
@@ -7,7 +7,7 @@ const react = require("react");
7
7
  const designSystem = require("@strapi/design-system");
8
8
  const icons = require("@strapi/icons");
9
9
  const reactIntl = require("react-intl");
10
- const index = require("./index-f3cmU_tE.js");
10
+ const index = require("./index-C2BnnDzh.js");
11
11
  const styled = require("styled-components");
12
12
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
13
13
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
@@ -22,9 +22,7 @@ function Role({ oidcRoles, roles, onChangeRole }) {
22
22
  placeholder: formatMessage(index.getTrad("roles.placeholder")),
23
23
  value: oidcRole.role ? oidcRole.role.map((r) => String(r)) : [],
24
24
  onChange: (value) => {
25
- if (value && value.length > 0) {
26
- onChangeRole(value, oidcRole.oauth_type);
27
- }
25
+ if (value && value.length > 0) onChangeRole(value, oidcRole.oauth_type);
28
26
  },
29
27
  children: roles.map((role) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.MultiSelectOption, { value: String(role.id), children: role.name }, role.id))
30
28
  }
@@ -77,19 +75,11 @@ function ConfirmDialog({
77
75
  function TablePagination({ page, pageCount, onPageChange }) {
78
76
  const { formatMessage } = reactIntl.useIntl();
79
77
  if (pageCount <= 1) return null;
80
- const pageLink = (num) => /* @__PURE__ */ jsxRuntime.jsx(
81
- designSystem.PageLink,
82
- {
83
- number: num,
84
- href: "#",
85
- onClick: (e) => {
86
- e.preventDefault();
87
- onPageChange(num);
88
- },
89
- children: formatMessage(index.getTrad("pagination.page"), { page: num })
90
- },
91
- num
92
- );
78
+ const handleClick = (e, num) => {
79
+ e.preventDefault();
80
+ onPageChange(num);
81
+ };
82
+ const pageLink = (num) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.PageLink, { number: num, href: "#", onClick: (e) => handleClick(e, num), children: formatMessage(index.getTrad("pagination.page"), { page: num }) }, num);
93
83
  const Ellipsis = () => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", paddingLeft: 2, paddingRight: 2, children: "…" });
94
84
  let pages;
95
85
  if (pageCount <= 10) {
@@ -116,31 +106,13 @@ function TablePagination({ page, pageCount, onPageChange }) {
116
106
  ] });
117
107
  }
118
108
  return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Pagination, { activePage: page, pageCount, children: [
119
- /* @__PURE__ */ jsxRuntime.jsx(
120
- designSystem.PreviousLink,
121
- {
122
- href: "#",
123
- onClick: (e) => {
124
- e.preventDefault();
125
- onPageChange(Math.max(1, page - 1));
126
- },
127
- children: formatMessage(index.getTrad("pagination.previous"))
128
- }
129
- ),
109
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.PreviousLink, { href: "#", onClick: (e) => handleClick(e, Math.max(1, page - 1)), children: formatMessage(index.getTrad("pagination.previous")) }),
130
110
  pages,
131
- /* @__PURE__ */ jsxRuntime.jsx(
132
- designSystem.NextLink,
133
- {
134
- href: "#",
135
- onClick: (e) => {
136
- e.preventDefault();
137
- onPageChange(Math.min(pageCount, page + 1));
138
- },
139
- children: formatMessage(index.getTrad("pagination.next"))
140
- }
141
- )
111
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.NextLink, { href: "#", onClick: (e) => handleClick(e, Math.min(pageCount, page + 1)), children: formatMessage(index.getTrad("pagination.next")) })
142
112
  ] }) }) });
143
113
  }
114
+ const PAGE_SIZE$1 = 10;
115
+ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
144
116
  function Whitelist({
145
117
  users,
146
118
  useWhitelist,
@@ -156,11 +128,8 @@ function Whitelist({
156
128
  const { formatMessage } = reactIntl.useIntl();
157
129
  const { toggleNotification } = admin.useNotification();
158
130
  const fileInputRef = react.useRef(null);
159
- const PAGE_SIZE2 = 10;
160
- const pageCount = Math.ceil(users.length / PAGE_SIZE2) || 1;
161
- const paginatedUsers = users.slice((page - 1) * PAGE_SIZE2, page * PAGE_SIZE2);
162
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
163
- const isValidEmail = emailRegex.test(email);
131
+ const pageCount = Math.ceil(users.length / PAGE_SIZE$1) || 1;
132
+ const paginatedUsers = users.slice((page - 1) * PAGE_SIZE$1, page * PAGE_SIZE$1);
164
133
  const onSaveEmail = react.useCallback(() => {
165
134
  const emailText = email.trim();
166
135
  if (users.some((user) => user.email === emailText)) {
@@ -176,14 +145,15 @@ function Whitelist({
176
145
  const handleImport = react.useCallback(
177
146
  async (e) => {
178
147
  const file = e.target.files?.[0];
179
- if (!fileInputRef.current) return;
148
+ if (!fileInputRef.current || !file) return;
180
149
  fileInputRef.current.value = "";
181
- if (!file) return;
182
150
  try {
183
151
  const text = await file.text();
184
152
  const parsed = JSON.parse(text);
185
153
  if (!Array.isArray(parsed)) throw new Error();
186
- const emails = parsed.filter((item) => item?.email).map((item) => String(item.email).trim().toLowerCase()).filter((email2) => emailRegex.test(email2));
154
+ const emails = parsed.filter((item) => item?.email).map(
155
+ (item) => String(item.email).trim().toLowerCase()
156
+ ).filter((email2) => EMAIL_REGEX.test(email2));
187
157
  const count = await onImport(emails);
188
158
  if (count === 0) {
189
159
  toggleNotification({
@@ -263,7 +233,7 @@ function Whitelist({
263
233
  type: "text",
264
234
  disabled: loading,
265
235
  value: email,
266
- hasError: Boolean(email && !isValidEmail),
236
+ hasError: Boolean(email && !EMAIL_REGEX.test(email)),
267
237
  onChange: (e) => setEmail(e.currentTarget.value),
268
238
  placeholder: formatMessage(index.getTrad("whitelist.email.placeholder"))
269
239
  }
@@ -273,7 +243,7 @@ function Whitelist({
273
243
  {
274
244
  size: "L",
275
245
  startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
276
- disabled: loading || email.trim() === "" || !isValidEmail,
246
+ disabled: loading || email.trim() === "" || !EMAIL_REGEX.test(email),
277
247
  loading,
278
248
  onClick: onSaveEmail,
279
249
  children: formatMessage(index.getTrad("page.add"))
@@ -289,7 +259,7 @@ function Whitelist({
289
259
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { style: { paddingRight: 0 }, children: " " })
290
260
  ] }) }),
291
261
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: users.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tr, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { colSpan: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: formatMessage(index.getTrad("whitelist.table.empty")) }) }) }) }) : paginatedUsers.map((user, index$1) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
292
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: index$1 + 1 + (page - 1) * PAGE_SIZE2 }),
262
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: index$1 + 1 + (page - 1) * PAGE_SIZE$1 }),
293
263
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: user.email }),
294
264
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(LocalizedDate, { date: user.createdAt, options: { month: "long" } }) }),
295
265
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { style: { paddingRight: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -467,7 +437,7 @@ function AuditLog() {
467
437
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: formatMessage(index.getTrad("auditlog.table.details")) })
468
438
  ] }) }),
469
439
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tbody, { children: [
470
- loading && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tr, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { colSpan: 5, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: "Loading…" }) }) }) }),
440
+ loading && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tr, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { colSpan: 5, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: formatMessage(index.getTrad("auditlog.loading")) }) }) }) }),
471
441
  !loading && records.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tr, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { colSpan: 5, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: formatMessage(index.getTrad("auditlog.table.empty")) }) }) }) }),
472
442
  !loading && records.map((record) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
473
443
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: /* @__PURE__ */ jsxRuntime.jsx(LocalizedDate, { date: record.createdAt, options: { second: "2-digit" } }) }) }),
@@ -633,47 +603,52 @@ function useOidcSettings() {
633
603
  setRoles(response.data.data);
634
604
  });
635
605
  get("/strapi-plugin-oidc/whitelist").then((response) => {
636
- setWhitelistResponse(response.data);
637
- setUsers(response.data.whitelistUsers);
638
- setInitialUsers(deepClone(response.data.whitelistUsers));
639
- setUseWhitelist(response.data.useWhitelist);
640
- setInitialUseWhitelist(response.data.useWhitelist);
641
- setEnforceOIDC(response.data.enforceOIDC);
642
- setInitialEnforceOIDC(response.data.enforceOIDC);
643
- setEnforceOIDCConfig(response.data.enforceOIDCConfig ?? null);
606
+ const data = response.data;
607
+ setWhitelistResponse(data);
608
+ setUsers(data.whitelistUsers);
609
+ setInitialUsers(deepClone(data.whitelistUsers));
610
+ setUseWhitelist(data.useWhitelist);
611
+ setInitialUseWhitelist(data.useWhitelist);
612
+ setEnforceOIDC(data.enforceOIDC);
613
+ setInitialEnforceOIDC(data.enforceOIDC);
614
+ setEnforceOIDCConfig(data.enforceOIDCConfig ?? null);
644
615
  });
645
616
  }, [get]);
646
- const onChangeRole = (values, oidcId) => {
647
- const updatedRoles = oidcRoles.map(
648
- (role) => role.oauth_type === oidcId ? { ...role, role: values } : role
617
+ const onChangeRole = react.useCallback((values, oidcId) => {
618
+ setOIDCRoles(
619
+ (prev) => prev.map((role) => role.oauth_type === oidcId ? { ...role, role: values } : role)
649
620
  );
650
- setOIDCRoles(updatedRoles);
651
- };
652
- const onRegisterWhitelist = (email) => {
653
- const newUser = { email, createdAt: (/* @__PURE__ */ new Date()).toISOString() };
654
- setUsers([...users, newUser]);
655
- };
656
- const onDeleteWhitelist = (email) => {
657
- const updatedUsers = users.filter((u) => u.email !== email);
658
- setUsers(updatedUsers);
659
- if (useWhitelist && updatedUsers.length === 0) {
660
- setEnforceOIDC(false);
661
- }
662
- };
663
- const onDeleteAll = () => {
621
+ }, []);
622
+ const onRegisterWhitelist = react.useCallback((email) => {
623
+ setUsers((prev) => [...prev, { email, createdAt: (/* @__PURE__ */ new Date()).toISOString() }]);
624
+ }, []);
625
+ const onDeleteWhitelist = react.useCallback(
626
+ (email) => {
627
+ setUsers((prev) => {
628
+ const updated = prev.filter((u) => u.email !== email);
629
+ if (useWhitelist && updated.length === 0) setEnforceOIDC(false);
630
+ return updated;
631
+ });
632
+ },
633
+ [useWhitelist]
634
+ );
635
+ const onDeleteAll = react.useCallback(() => {
664
636
  setUsers([]);
665
637
  if (useWhitelist) setEnforceOIDC(false);
666
- };
667
- const onImport = async (emails) => {
668
- const response = await post("/strapi-plugin-oidc/whitelist/import", {
669
- users: emails.map((e) => ({ email: e }))
670
- });
671
- const refreshed = await get("/strapi-plugin-oidc/whitelist");
672
- setUsers(refreshed.data.whitelistUsers);
673
- setInitialUsers(deepClone(refreshed.data.whitelistUsers));
674
- return response.data.importedCount;
675
- };
676
- const onExport = async () => {
638
+ }, [useWhitelist]);
639
+ const onImport = react.useCallback(
640
+ async (emails) => {
641
+ const response = await post("/strapi-plugin-oidc/whitelist/import", {
642
+ users: emails.map((e) => ({ email: e }))
643
+ });
644
+ const refreshed = await get("/strapi-plugin-oidc/whitelist");
645
+ setUsers(refreshed.data.whitelistUsers);
646
+ setInitialUsers(deepClone(refreshed.data.whitelistUsers));
647
+ return response.data.importedCount;
648
+ },
649
+ [post, get]
650
+ );
651
+ const onExport = react.useCallback(async () => {
677
652
  const response = await get("/strapi-plugin-oidc/whitelist/export");
678
653
  const data = response.data;
679
654
  const datetime = formatDatetimeForFilename(/* @__PURE__ */ new Date());
@@ -684,41 +659,37 @@ function useOidcSettings() {
684
659
  a.download = `strapi-oidc-whitelist-${datetime}.json`;
685
660
  a.click();
686
661
  URL.revokeObjectURL(url);
687
- };
688
- const onToggleWhitelist = (e) => {
689
- const checked = e.target.checked;
690
- setUseWhitelist(checked);
691
- if (checked && users.length === 0) {
692
- setEnforceOIDC(false);
693
- }
694
- };
695
- const onToggleEnforce = (e) => {
662
+ }, [get]);
663
+ const onToggleWhitelist = react.useCallback(
664
+ (e) => {
665
+ const checked = e.target.checked;
666
+ setUseWhitelist(checked);
667
+ if (checked && users.length === 0) setEnforceOIDC(false);
668
+ },
669
+ [users.length]
670
+ );
671
+ const onToggleEnforce = react.useCallback((e) => {
696
672
  setEnforceOIDC(e.target.checked);
697
- };
673
+ }, []);
698
674
  const isDirty = useWhitelist !== initialUseWhitelist || enforceOIDC !== initialEnforceOIDC || JSON.stringify(oidcRoles) !== JSON.stringify(initialOidcRoles) || JSON.stringify(users) !== JSON.stringify(initialUsers);
699
- const onSaveAll = async () => {
675
+ const onSaveAll = react.useCallback(async () => {
700
676
  setLoading(true);
701
677
  try {
702
678
  await put("/strapi-plugin-oidc/oidc-roles", {
703
- roles: oidcRoles.map((role) => ({
704
- oauth_type: role.oauth_type,
705
- role: role.role
706
- }))
679
+ roles: oidcRoles.map((role) => ({ oauth_type: role.oauth_type, role: role.role }))
707
680
  });
708
681
  await put("/strapi-plugin-oidc/whitelist/sync", {
709
682
  users: users.map((u) => ({ email: u.email }))
710
683
  });
711
- await put("/strapi-plugin-oidc/whitelist/settings", {
712
- useWhitelist,
713
- enforceOIDC
714
- });
684
+ await put("/strapi-plugin-oidc/whitelist/settings", { useWhitelist, enforceOIDC });
715
685
  setInitialOIDCRoles(deepClone(oidcRoles));
716
686
  setInitialUseWhitelist(useWhitelist);
717
687
  setInitialEnforceOIDC(enforceOIDC);
718
688
  get("/strapi-plugin-oidc/whitelist").then((getResponse) => {
719
- setWhitelistResponse(getResponse.data);
720
- setUsers(getResponse.data.whitelistUsers);
721
- setInitialUsers(deepClone(getResponse.data.whitelistUsers));
689
+ const data = getResponse.data;
690
+ setWhitelistResponse(data);
691
+ setUsers(data.whitelistUsers);
692
+ setInitialUsers(deepClone(data.whitelistUsers));
722
693
  });
723
694
  setSuccess(true);
724
695
  setTimeout(() => setSuccess(false), 3e3);
@@ -729,7 +700,7 @@ function useOidcSettings() {
729
700
  } finally {
730
701
  setLoading(false);
731
702
  }
732
- };
703
+ }, [put, get, oidcRoles, users, useWhitelist, enforceOIDC]);
733
704
  return {
734
705
  state: {
735
706
  loading,
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const index = require("./index-f3cmU_tE.js");
3
+ const index = require("./index-C2BnnDzh.js");
4
4
  exports.default = index.index;
@@ -1,4 +1,4 @@
1
- import { i } from "./index-P9HriRms.mjs";
1
+ import { i } from "./index-DgUClS5s.mjs";
2
2
  export {
3
3
  i as default
4
4
  };