@dhis2/ui-forms 7.11.0 → 7.11.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +1,31 @@
1
1
  {
2
- "Upload file": "",
3
- "Upload files": "",
4
- "Remove": "",
5
- "No file(s) selected yet": "",
6
- "Please provide an alpha-numeric value": "",
7
- "Please provide a boolean value": "",
8
- "Please enter between {{lowerBound}} and {{upperBound}} characters": "",
9
- "Please make sure the value of this input matches the value in \"{{otherField}}\".": "",
10
- "Please enter a maximum of {{upperBound}} characters": "",
11
- "Please enter a number with a maximum of {{upperBound}}": "",
12
- "Please enter at least {{lowerBound}} characters": "",
13
- "Please enter a number of at least {{lowerBound}}": "",
14
- "Number cannot be less than {{lowerBound}} or more than {{upperBound}}": "",
15
- "Please make sure the value of this input matches the pattern {{patternString}}.": "",
16
- "Password should be a string": "",
17
- "Password should be at least 8 characters long": "",
18
- "Password should be no longer than 34 characters": "",
19
- "Password should contain at least one lowercase letter": "",
20
- "Password should contain at least one UPPERCASE letter": "",
21
- "Password should contain at least one number": "",
22
- "Password should have at least one special character": "",
23
- "Please provide a username between 1 and 255 characters": "",
24
- "Please provide a valid email address": "",
25
- "Please provide a value": "",
26
- "Please provide a round number without decimals": "",
27
- "Please provide a valid international phone number.": "",
28
- "Please provide a number": "",
29
- "Please provide a string": "",
30
- "Please provide a valid url": ""
2
+ "Upload file": "Upload file",
3
+ "Upload files": "Upload files",
4
+ "Remove": "Remove",
5
+ "No file(s) selected yet": "No file(s) selected yet",
6
+ "Please provide an alpha-numeric value": "Please provide an alpha-numeric value",
7
+ "Please provide a boolean value": "Please provide a boolean value",
8
+ "Please enter between {{lowerBound}} and {{upperBound}} characters": "Please enter between {{lowerBound}} and {{upperBound}} characters",
9
+ "Please make sure the value of this input matches the value in \"{{otherField}}\".": "Please make sure the value of this input matches the value in \"{{otherField}}\".",
10
+ "Please enter a maximum of {{upperBound}} characters": "Please enter a maximum of {{upperBound}} characters",
11
+ "Please enter a number with a maximum of {{upperBound}}": "Please enter a number with a maximum of {{upperBound}}",
12
+ "Please enter at least {{lowerBound}} characters": "Please enter at least {{lowerBound}} characters",
13
+ "Please enter a number of at least {{lowerBound}}": "Please enter a number of at least {{lowerBound}}",
14
+ "Number cannot be less than {{lowerBound}} or more than {{upperBound}}": "Number cannot be less than {{lowerBound}} or more than {{upperBound}}",
15
+ "Please make sure the value of this input matches the pattern {{patternString}}.": "Please make sure the value of this input matches the pattern {{patternString}}.",
16
+ "Password should be a string": "Password should be a string",
17
+ "Password should be at least 8 characters long": "Password should be at least 8 characters long",
18
+ "Password should be no longer than 34 characters": "Password should be no longer than 34 characters",
19
+ "Password should contain at least one lowercase letter": "Password should contain at least one lowercase letter",
20
+ "Password should contain at least one UPPERCASE letter": "Password should contain at least one UPPERCASE letter",
21
+ "Password should contain at least one number": "Password should contain at least one number",
22
+ "Password should have at least one special character": "Password should have at least one special character",
23
+ "Please provide a username between 4 and 255 characters": "Please provide a username between 4 and 255 characters",
24
+ "Please provide a valid email address": "Please provide a valid email address",
25
+ "Please provide a value": "Please provide a value",
26
+ "Please provide a round number without decimals": "Please provide a round number without decimals",
27
+ "Please provide a valid international phone number.": "Please provide a valid international phone number.",
28
+ "Please provide a number": "Please provide a number",
29
+ "Please provide a string": "Please provide a string",
30
+ "Please provide a valid url": "Please provide a valid url"
31
31
  }
@@ -6,16 +6,24 @@ var _index = require("../test-helpers/index.js");
6
6
 
7
7
  describe('validator: dhis2Username', () => {
8
8
  (0, _index.allowsEmptyValues)(_dhis2Username.dhis2Username);
9
- describe('allows all sorts of strings between 1 and 255 characters long', () => {
10
- (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, undefined, ['electricchicken', '1', //1
11
- 'sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss', //255
12
- 'some_username^%&*(', 'あいうえお']);
9
+ describe('constrains length of username to between 4 and 255 characters long', () => {
10
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, undefined, ['s'.repeat(4), 's'.repeat(255), 'valid_username']);
11
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, ['1', 's', 's'.repeat(256)]);
13
12
  });
14
- describe('rejects other data types', () => {
15
- (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, [1, true, {}, [], () => {}]);
13
+ describe('does not allow usernames to start with _, . or @', () => {
14
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, ['_xxx', '.xxx', '@xxx']);
15
+ });
16
+ describe('does not allow usernames to end with _, . or @', () => {
17
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, ['xxx_', 'xxx.', 'xxx@']);
18
+ });
19
+ describe('does not allow usernames to contain __, .. or @@', () => {
20
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, ['__xx', '..xx', '@@xx']);
16
21
  });
17
- describe('values that are too long', () => {
18
- (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, ['ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss' //256
19
- ]);
22
+ describe('constrains characters in usernames to [a-z0-9._@]', () => {
23
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, undefined, ['v@lid_user.name', '123another_v@lid_usern@me']);
24
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, ['あいうえお', 'some_username^%&*(']);
25
+ });
26
+ describe('rejects non-string data types', () => {
27
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, [1, true, {}, [], () => {}]);
20
28
  });
21
29
  });
@@ -11,10 +11,12 @@ var _index2 = require("./helpers/index.js");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- const invalidUsernameMessage = _index.default.t('Please provide a username between 1 and 255 characters');
14
+ const USERNAME_PATTERN = /^(?=.{4,255}$)(?![_.@])(?!.*[_.@]{2})[a-z0-9._@]+(?<![_.@])$/;
15
+
16
+ const invalidUsernameMessage = _index.default.t('Please provide a username between 4 and 255 characters');
15
17
 
16
18
  exports.invalidUsernameMessage = invalidUsernameMessage;
17
19
 
18
- const dhis2Username = value => (0, _index2.isEmpty)(value) || (0, _index2.isString)(value) && value.length >= 1 && value.length <= 255 ? undefined : invalidUsernameMessage;
20
+ const dhis2Username = value => (0, _index2.isEmpty)(value) || (0, _index2.isString)(value) && USERNAME_PATTERN.test(value) ? undefined : invalidUsernameMessage;
19
21
 
20
22
  exports.dhis2Username = dhis2Username;
@@ -1,31 +1,31 @@
1
1
  {
2
- "Upload file": "",
3
- "Upload files": "",
4
- "Remove": "",
5
- "No file(s) selected yet": "",
6
- "Please provide an alpha-numeric value": "",
7
- "Please provide a boolean value": "",
8
- "Please enter between {{lowerBound}} and {{upperBound}} characters": "",
9
- "Please make sure the value of this input matches the value in \"{{otherField}}\".": "",
10
- "Please enter a maximum of {{upperBound}} characters": "",
11
- "Please enter a number with a maximum of {{upperBound}}": "",
12
- "Please enter at least {{lowerBound}} characters": "",
13
- "Please enter a number of at least {{lowerBound}}": "",
14
- "Number cannot be less than {{lowerBound}} or more than {{upperBound}}": "",
15
- "Please make sure the value of this input matches the pattern {{patternString}}.": "",
16
- "Password should be a string": "",
17
- "Password should be at least 8 characters long": "",
18
- "Password should be no longer than 34 characters": "",
19
- "Password should contain at least one lowercase letter": "",
20
- "Password should contain at least one UPPERCASE letter": "",
21
- "Password should contain at least one number": "",
22
- "Password should have at least one special character": "",
23
- "Please provide a username between 1 and 255 characters": "",
24
- "Please provide a valid email address": "",
25
- "Please provide a value": "",
26
- "Please provide a round number without decimals": "",
27
- "Please provide a valid international phone number.": "",
28
- "Please provide a number": "",
29
- "Please provide a string": "",
30
- "Please provide a valid url": ""
2
+ "Upload file": "Upload file",
3
+ "Upload files": "Upload files",
4
+ "Remove": "Remove",
5
+ "No file(s) selected yet": "No file(s) selected yet",
6
+ "Please provide an alpha-numeric value": "Please provide an alpha-numeric value",
7
+ "Please provide a boolean value": "Please provide a boolean value",
8
+ "Please enter between {{lowerBound}} and {{upperBound}} characters": "Please enter between {{lowerBound}} and {{upperBound}} characters",
9
+ "Please make sure the value of this input matches the value in \"{{otherField}}\".": "Please make sure the value of this input matches the value in \"{{otherField}}\".",
10
+ "Please enter a maximum of {{upperBound}} characters": "Please enter a maximum of {{upperBound}} characters",
11
+ "Please enter a number with a maximum of {{upperBound}}": "Please enter a number with a maximum of {{upperBound}}",
12
+ "Please enter at least {{lowerBound}} characters": "Please enter at least {{lowerBound}} characters",
13
+ "Please enter a number of at least {{lowerBound}}": "Please enter a number of at least {{lowerBound}}",
14
+ "Number cannot be less than {{lowerBound}} or more than {{upperBound}}": "Number cannot be less than {{lowerBound}} or more than {{upperBound}}",
15
+ "Please make sure the value of this input matches the pattern {{patternString}}.": "Please make sure the value of this input matches the pattern {{patternString}}.",
16
+ "Password should be a string": "Password should be a string",
17
+ "Password should be at least 8 characters long": "Password should be at least 8 characters long",
18
+ "Password should be no longer than 34 characters": "Password should be no longer than 34 characters",
19
+ "Password should contain at least one lowercase letter": "Password should contain at least one lowercase letter",
20
+ "Password should contain at least one UPPERCASE letter": "Password should contain at least one UPPERCASE letter",
21
+ "Password should contain at least one number": "Password should contain at least one number",
22
+ "Password should have at least one special character": "Password should have at least one special character",
23
+ "Please provide a username between 4 and 255 characters": "Please provide a username between 4 and 255 characters",
24
+ "Please provide a valid email address": "Please provide a valid email address",
25
+ "Please provide a value": "Please provide a value",
26
+ "Please provide a round number without decimals": "Please provide a round number without decimals",
27
+ "Please provide a valid international phone number.": "Please provide a valid international phone number.",
28
+ "Please provide a number": "Please provide a number",
29
+ "Please provide a string": "Please provide a string",
30
+ "Please provide a valid url": "Please provide a valid url"
31
31
  }
@@ -2,16 +2,24 @@ import { dhis2Username, invalidUsernameMessage } from '../dhis2Username.js';
2
2
  import { testValidatorValues, allowsEmptyValues } from '../test-helpers/index.js';
3
3
  describe('validator: dhis2Username', () => {
4
4
  allowsEmptyValues(dhis2Username);
5
- describe('allows all sorts of strings between 1 and 255 characters long', () => {
6
- testValidatorValues(dhis2Username, undefined, ['electricchicken', '1', //1
7
- 'sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss', //255
8
- 'some_username^%&*(', 'あいうえお']);
5
+ describe('constrains length of username to between 4 and 255 characters long', () => {
6
+ testValidatorValues(dhis2Username, undefined, ['s'.repeat(4), 's'.repeat(255), 'valid_username']);
7
+ testValidatorValues(dhis2Username, invalidUsernameMessage, ['1', 's', 's'.repeat(256)]);
9
8
  });
10
- describe('rejects other data types', () => {
11
- testValidatorValues(dhis2Username, invalidUsernameMessage, [1, true, {}, [], () => {}]);
9
+ describe('does not allow usernames to start with _, . or @', () => {
10
+ testValidatorValues(dhis2Username, invalidUsernameMessage, ['_xxx', '.xxx', '@xxx']);
11
+ });
12
+ describe('does not allow usernames to end with _, . or @', () => {
13
+ testValidatorValues(dhis2Username, invalidUsernameMessage, ['xxx_', 'xxx.', 'xxx@']);
14
+ });
15
+ describe('does not allow usernames to contain __, .. or @@', () => {
16
+ testValidatorValues(dhis2Username, invalidUsernameMessage, ['__xx', '..xx', '@@xx']);
12
17
  });
13
- describe('values that are too long', () => {
14
- testValidatorValues(dhis2Username, invalidUsernameMessage, ['ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss' //256
15
- ]);
18
+ describe('constrains characters in usernames to [a-z0-9._@]', () => {
19
+ testValidatorValues(dhis2Username, undefined, ['v@lid_user.name', '123another_v@lid_usern@me']);
20
+ testValidatorValues(dhis2Username, invalidUsernameMessage, ['あいうえお', 'some_username^%&*(']);
21
+ });
22
+ describe('rejects non-string data types', () => {
23
+ testValidatorValues(dhis2Username, invalidUsernameMessage, [1, true, {}, [], () => {}]);
16
24
  });
17
25
  });
@@ -1,7 +1,8 @@
1
1
  import i18n from '../locales/index.js';
2
2
  import { isEmpty, isString } from './helpers/index.js';
3
- const invalidUsernameMessage = i18n.t('Please provide a username between 1 and 255 characters');
3
+ const USERNAME_PATTERN = /^(?=.{4,255}$)(?![_.@])(?!.*[_.@]{2})[a-z0-9._@]+(?<![_.@])$/;
4
+ const invalidUsernameMessage = i18n.t('Please provide a username between 4 and 255 characters');
4
5
 
5
- const dhis2Username = value => isEmpty(value) || isString(value) && value.length >= 1 && value.length <= 255 ? undefined : invalidUsernameMessage;
6
+ const dhis2Username = value => isEmpty(value) || isString(value) && USERNAME_PATTERN.test(value) ? undefined : invalidUsernameMessage;
6
7
 
7
8
  export { dhis2Username, invalidUsernameMessage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/ui-forms",
3
- "version": "7.11.0",
3
+ "version": "7.11.4",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "sideEffects": [
@@ -34,15 +34,15 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@dhis2/prop-types": "^3.0.0-beta.1",
37
- "@dhis2-ui/button": "7.11.0",
38
- "@dhis2-ui/checkbox": "7.11.0",
39
- "@dhis2-ui/field": "7.11.0",
40
- "@dhis2-ui/file-input": "7.11.0",
41
- "@dhis2-ui/input": "7.11.0",
42
- "@dhis2-ui/radio": "7.11.0",
43
- "@dhis2-ui/select": "7.11.0",
44
- "@dhis2-ui/switch": "7.11.0",
45
- "@dhis2-ui/text-area": "7.11.0",
37
+ "@dhis2-ui/button": "7.11.4",
38
+ "@dhis2-ui/checkbox": "7.11.4",
39
+ "@dhis2-ui/field": "7.11.4",
40
+ "@dhis2-ui/file-input": "7.11.4",
41
+ "@dhis2-ui/input": "7.11.4",
42
+ "@dhis2-ui/radio": "7.11.4",
43
+ "@dhis2-ui/select": "7.11.4",
44
+ "@dhis2-ui/switch": "7.11.4",
45
+ "@dhis2-ui/text-area": "7.11.4",
46
46
  "classnames": "^2.3.1",
47
47
  "final-form": "^4.20.2",
48
48
  "prop-types": "^15.7.2",