@strapi/plugin-users-permissions 4.12.0 → 4.12.2

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.
@@ -2,8 +2,6 @@ import { useCallback, useEffect, useReducer, useRef } from 'react';
2
2
 
3
3
  import { useFetchClient, useNotification, useRBAC } from '@strapi/helper-plugin';
4
4
 
5
- import { getRequestURL } from '../../utils';
6
-
7
5
  import reducer, { initialState } from './reducer';
8
6
 
9
7
  const useUserForm = (endPoint, permissions) => {
@@ -21,7 +19,7 @@ const useUserForm = (endPoint, permissions) => {
21
19
  type: 'GET_DATA',
22
20
  });
23
21
 
24
- const { data } = await get(getRequestURL(endPoint));
22
+ const { data } = await get(`/users-permissions/${endPoint}`);
25
23
 
26
24
  dispatch({
27
25
  type: 'GET_DATA_SUCCEEDED',
@@ -1,10 +1,8 @@
1
1
  import { getFetchClient } from '@strapi/helper-plugin';
2
2
 
3
- import { getRequestURL } from '../../../utils';
4
-
5
3
  const fetchData = async () => {
6
4
  const { get } = getFetchClient();
7
- const { data } = await get(getRequestURL('advanced'));
5
+ const { data } = await get('/users-permissions/advanced');
8
6
 
9
7
  return data;
10
8
  };
@@ -12,7 +10,7 @@ const fetchData = async () => {
12
10
  const putAdvancedSettings = (body) => {
13
11
  const { put } = getFetchClient();
14
12
 
15
- return put(getRequestURL('advanced'), body);
13
+ return put('/users-permissions/advanced', body);
16
14
  };
17
15
 
18
16
  export { fetchData, putAdvancedSettings };
@@ -1,10 +1,8 @@
1
1
  import { getFetchClient } from '@strapi/helper-plugin';
2
2
 
3
- import { getRequestURL } from '../../../utils';
4
-
5
3
  const fetchData = async () => {
6
4
  const { get } = getFetchClient();
7
- const { data } = await get(getRequestURL('email-templates'));
5
+ const { data } = await get('/users-permissions/email-templates');
8
6
 
9
7
  return data;
10
8
  };
@@ -12,7 +10,7 @@ const fetchData = async () => {
12
10
  const putEmailTemplate = (body) => {
13
11
  const { put } = getFetchClient();
14
12
 
15
- return put(getRequestURL('email-templates'), body);
13
+ return put('/users-permissions/email-templates', body);
16
14
  };
17
15
 
18
16
  export { fetchData, putEmailTemplate };
@@ -1,12 +1,10 @@
1
1
  import { getFetchClient } from '@strapi/helper-plugin';
2
2
 
3
- import { getRequestURL } from '../../../utils';
4
-
5
3
  // eslint-disable-next-line import/prefer-default-export
6
4
  export const fetchData = async (toggleNotification) => {
7
5
  try {
8
6
  const { get } = getFetchClient();
9
- const { data } = await get(getRequestURL('providers'));
7
+ const { data } = await get('/users-permissions/providers');
10
8
 
11
9
  return data;
12
10
  } catch (err) {
@@ -22,5 +20,5 @@ export const fetchData = async (toggleNotification) => {
22
20
  export const putProvider = (body) => {
23
21
  const { put } = getFetchClient();
24
22
 
25
- return put(getRequestURL('providers'), body);
23
+ return put('/users-permissions/providers', body);
26
24
  };
@@ -1,11 +1,9 @@
1
1
  import { getFetchClient } from '@strapi/helper-plugin';
2
2
 
3
- import { getRequestURL } from '../../../../utils';
4
-
5
3
  export const fetchData = async (toggleNotification, notifyStatus) => {
6
4
  try {
7
5
  const { get } = getFetchClient();
8
- const { data } = await get(getRequestURL('roles'));
6
+ const { data } = await get('/users-permissions/roles');
9
7
  notifyStatus('The roles have loaded successfully');
10
8
 
11
9
  return data;
@@ -22,7 +20,7 @@ export const fetchData = async (toggleNotification, notifyStatus) => {
22
20
  export const deleteData = async (id, toggleNotification) => {
23
21
  try {
24
22
  const { del } = getFetchClient();
25
- await del(`${getRequestURL('roles')}/${id}`);
23
+ await del(`/users-permissions/roles/${id}`);
26
24
  } catch (error) {
27
25
  toggleNotification({
28
26
  type: 'warning',
@@ -1,4 +1,3 @@
1
1
  export { default as cleanPermissions } from './cleanPermissions';
2
2
  export { default as formatPolicies } from './formatPolicies';
3
- export { default as getRequestURL } from './getRequestURL';
4
3
  export { default as getTrad } from './getTrad';
@@ -93,7 +93,7 @@ paths:
93
93
  required: true
94
94
  responses:
95
95
  200:
96
- description: Successfull registration
96
+ description: Successful registration
97
97
  content:
98
98
  application/json:
99
99
  schema:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-users-permissions",
3
- "version": "4.12.0",
3
+ "version": "4.12.2",
4
4
  "description": "Protect your API with a full-authentication process based on JWT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,16 +30,16 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@strapi/design-system": "1.8.2",
33
- "@strapi/helper-plugin": "4.12.0",
33
+ "@strapi/helper-plugin": "4.12.2",
34
34
  "@strapi/icons": "1.8.2",
35
- "@strapi/utils": "4.12.0",
35
+ "@strapi/utils": "4.12.2",
36
36
  "bcryptjs": "2.4.3",
37
37
  "formik": "2.4.0",
38
38
  "grant-koa": "5.4.8",
39
39
  "immer": "9.0.19",
40
40
  "jsonwebtoken": "9.0.0",
41
41
  "jwk-to-pem": "2.0.5",
42
- "koa": "^2.13.4",
42
+ "koa": "2.13.4",
43
43
  "koa2-ratelimit": "^1.1.2",
44
44
  "lodash": "4.17.21",
45
45
  "prop-types": "^15.8.1",
@@ -48,7 +48,7 @@
48
48
  "react-query": "3.39.3",
49
49
  "react-redux": "8.1.1",
50
50
  "url-join": "4.0.1",
51
- "yup": "^0.32.9"
51
+ "yup": "0.32.9"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@testing-library/dom": "9.2.0",
@@ -67,7 +67,7 @@
67
67
  "styled-components": "5.3.3"
68
68
  },
69
69
  "engines": {
70
- "node": ">=14.19.1 <=18.x.x",
70
+ "node": ">=16.0.0 <=20.x.x",
71
71
  "npm": ">=6.0.0"
72
72
  },
73
73
  "strapi": {
@@ -77,5 +77,5 @@
77
77
  "required": true,
78
78
  "kind": "plugin"
79
79
  },
80
- "gitHead": "7f8109a1a736c1d997fbb445469b3b59550c7aeb"
80
+ "gitHead": "b5a0cb4020ee9b170243e458decd5b1babf474e3"
81
81
  }
@@ -1,27 +1,47 @@
1
1
  'use strict';
2
2
 
3
+ const path = require('path');
4
+ const utils = require('@strapi/utils');
5
+ const { isString, has, toLower } = require('lodash/fp');
6
+
7
+ const { RateLimitError } = utils.errors;
8
+
3
9
  module.exports =
4
10
  (config, { strapi }) =>
5
11
  async (ctx, next) => {
6
- const ratelimit = require('koa2-ratelimit').RateLimit;
7
-
8
- const message = [
9
- {
10
- messages: [
11
- {
12
- id: 'Auth.form.error.ratelimit',
13
- message: 'Too many attempts, please try again in a minute.',
14
- },
15
- ],
16
- },
17
- ];
18
-
19
- return ratelimit.middleware({
20
- interval: 1 * 60 * 1000,
21
- max: 5,
22
- prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
23
- message,
24
- ...strapi.config.get('plugin.users-permissions.ratelimit'),
25
- ...config,
26
- })(ctx, next);
12
+ let rateLimitConfig = strapi.config.get('plugin.users-permissions.ratelimit');
13
+
14
+ if (!rateLimitConfig) {
15
+ rateLimitConfig = {
16
+ enabled: true,
17
+ };
18
+ }
19
+
20
+ if (!has('enabled', rateLimitConfig)) {
21
+ rateLimitConfig.enabled = true;
22
+ }
23
+
24
+ if (rateLimitConfig.enabled === true) {
25
+ const rateLimit = require('koa2-ratelimit').RateLimit;
26
+
27
+ const userIdentifier = toLower(ctx.request.body.email) || 'unknownIdentifier';
28
+ const requestPath = isString(ctx.request.path)
29
+ ? toLower(path.normalize(ctx.request.path))
30
+ : 'invalidPath';
31
+
32
+ const loadConfig = {
33
+ interval: { min: 5 },
34
+ max: 5,
35
+ prefixKey: `${userIdentifier}:${requestPath}:${ctx.request.ip}`,
36
+ handler() {
37
+ throw new RateLimitError();
38
+ },
39
+ ...rateLimitConfig,
40
+ ...config,
41
+ };
42
+
43
+ return rateLimit.middleware(loadConfig)(ctx, next);
44
+ }
45
+
46
+ return next();
27
47
  };
@@ -1,5 +0,0 @@
1
- import pluginId from '../pluginId';
2
-
3
- const getRequestURL = (endPoint) => `/${pluginId}/${endPoint}`;
4
-
5
- export default getRequestURL;