@sanity/validation 2.34.1-canary.0 → 2.34.2-empty-template-cli.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.
@@ -4,41 +4,54 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _genericValidator = _interopRequireDefault(require("./genericValidator"));
9
+
8
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
9
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
+
10
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+
11
16
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
+
12
18
  var DUMMY_ORIGIN = 'http://sanity';
13
19
  var emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
20
+
14
21
  var isRelativeUrl = url => /^\.*\//.test(url);
22
+
15
23
  var stringValidators = _objectSpread(_objectSpread({}, _genericValidator.default), {}, {
16
24
  min: (minLength, value, message) => {
17
25
  if (!value || value.length >= minLength) {
18
26
  return true;
19
27
  }
28
+
20
29
  return message || "Must be at least ".concat(minLength, " characters long");
21
30
  },
22
31
  max: (maxLength, value, message) => {
23
32
  if (!value || value.length <= maxLength) {
24
33
  return true;
25
34
  }
35
+
26
36
  return message || "Must be at most ".concat(maxLength, " characters long");
27
37
  },
28
38
  length: (wantedLength, value, message) => {
29
39
  var strValue = value || '';
40
+
30
41
  if (strValue.length === wantedLength) {
31
42
  return true;
32
43
  }
44
+
33
45
  return message || "Must be exactly ".concat(wantedLength, " characters long");
34
46
  },
35
47
  uri: (constraints, value, message) => {
36
48
  var strValue = value || '';
37
49
  var options = constraints.options;
38
50
  var allowCredentials = options.allowCredentials,
39
- relativeOnly = options.relativeOnly;
51
+ relativeOnly = options.relativeOnly;
40
52
  var allowRelative = options.allowRelative || relativeOnly;
41
53
  var url;
54
+
42
55
  try {
43
56
  // WARNING: Safari checks for a given `base` param by looking at the length of arguments passed
44
57
  // to new URL(str, base), and will fail if invoked with new URL(strValue, undefined)
@@ -46,58 +59,73 @@ var stringValidators = _objectSpread(_objectSpread({}, _genericValidator.default
46
59
  } catch (err) {
47
60
  return message || 'Not a valid URL';
48
61
  }
62
+
49
63
  if (relativeOnly && url.origin !== DUMMY_ORIGIN) {
50
64
  return message || 'Only relative URLs are allowed';
51
65
  }
66
+
52
67
  if (!allowRelative && url.origin === DUMMY_ORIGIN && isRelativeUrl(strValue)) {
53
68
  return message || 'Relative URLs are not allowed';
54
69
  }
70
+
55
71
  if (!allowCredentials && (url.username || url.password)) {
56
72
  return message || "Username/password not allowed";
57
73
  }
74
+
58
75
  var urlScheme = url.protocol.replace(/:$/, '');
59
76
  var matchesAllowedScheme = options.scheme.some(scheme => scheme.test(urlScheme));
77
+
60
78
  if (!matchesAllowedScheme) {
61
79
  return message || 'Does not match allowed protocols/schemes';
62
80
  }
81
+
63
82
  return true;
64
83
  },
65
84
  stringCasing: (casing, value, message) => {
66
85
  var strValue = value || '';
86
+
67
87
  if (casing === 'uppercase' && strValue !== strValue.toLocaleUpperCase()) {
68
88
  return message || "Must be all uppercase letters";
69
89
  }
90
+
70
91
  if (casing === 'lowercase' && strValue !== strValue.toLocaleLowerCase()) {
71
92
  return message || "Must be all lowercase letters";
72
93
  }
94
+
73
95
  return true;
74
96
  },
75
97
  presence: (flag, value, message) => {
76
98
  if (flag === 'required' && !value) {
77
99
  return message || 'Required';
78
100
  }
101
+
79
102
  return true;
80
103
  },
81
104
  regex: (options, value, message) => {
82
105
  var pattern = options.pattern,
83
- name = options.name,
84
- invert = options.invert;
106
+ name = options.name,
107
+ invert = options.invert;
85
108
  var regName = name || "\"".concat(pattern.toString(), "\"");
86
109
  var strValue = value || '';
87
110
  var matches = pattern.test(strValue);
111
+
88
112
  if (!invert && !matches || invert && matches) {
89
113
  var defaultMessage = invert ? "Should not match ".concat(regName, "-pattern") : "Does not match ".concat(regName, "-pattern");
90
114
  return message || defaultMessage;
91
115
  }
116
+
92
117
  return true;
93
118
  },
94
119
  email: (_unused, value, message) => {
95
120
  var strValue = "".concat(value || '').trim();
121
+
96
122
  if (!strValue || emailRegex.test(strValue)) {
97
123
  return true;
98
124
  }
125
+
99
126
  return message || 'Must be a valid email address';
100
127
  }
101
128
  });
129
+
102
130
  var _default = stringValidators;
103
131
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/validation",
3
- "version": "2.34.1-canary.0+b3e58b8893",
3
+ "version": "2.34.2-empty-template-cli.0+184a9350e5",
4
4
  "description": "Validation and warning infrastructure for Sanity projects",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./dist/dts",
@@ -33,13 +33,13 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@sanity/client": "^3.3.3",
36
- "@sanity/schema": "2.34.1-canary.0+b3e58b8893"
36
+ "@sanity/schema": "2.34.2-empty-template-cli.0+184a9350e5"
37
37
  },
38
38
  "dependencies": {
39
- "@sanity/types": "2.34.1-canary.0+b3e58b8893",
39
+ "@sanity/types": "2.34.2-empty-template-cli.0+184a9350e5",
40
40
  "date-fns": "^2.16.1",
41
41
  "lodash": "^4.17.15",
42
42
  "rxjs": "^6.5.3"
43
43
  },
44
- "gitHead": "b3e58b8893c9573844279488896df2313df914f1"
44
+ "gitHead": "184a9350e50aa05877a3b10e052ce4e2ca743ef0"
45
45
  }