joi 12.0.0 → 12.1.1

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.
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ COMMERCIAL LICENSE
2
+
3
+ Copyright (c) 2019-2020 Sideway Inc.
4
+
5
+ This package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact [sales@sideway.com](mailto:sales@sideway.com).
6
+
7
+ This package contains code previously published under an open source license. You can find the previous materials and the terms under which they were originally published at: [https://github.com/hapijs/joi/blob/master/LICENSE](https://github.com/hapijs/joi/blob/master/LICENSE).
package/README.md CHANGED
@@ -1,23 +1,12 @@
1
- ![joi Logo](https://raw.github.com/hapijs/joi/master/images/joi.png)
1
+ # joi
2
2
 
3
3
  Object schema description language and validator for JavaScript objects.
4
4
 
5
- [![npm version](https://badge.fury.io/js/joi.svg)](http://badge.fury.io/js/joi)
6
- [![Build Status](https://secure.travis-ci.org/hapijs/joi.svg?branch=master)](http://travis-ci.org/hapijs/joi)
7
- <!--
5
+ [![Build Status](https://travis-ci.org/hapijs/joi.svg?branch=v12-commercial)](https://travis-ci.org/hapijs/joi)
8
6
 
9
- Remove those badges until they work properly on semver.
7
+ ## License
10
8
 
11
- [![Dependencies Status](https://david-dm.org/hapijs/joi.svg)](https://david-dm.org/hapijs/joi)
12
- [![DevDependencies Status](https://david-dm.org/hapijs/joi/dev-status.svg)](https://david-dm.org/hapijs/joi#info=devDependencies)
13
-
14
- -->
15
- [![NSP Status](https://nodesecurity.io/orgs/hapijs/projects/0394bf83-b5bc-410b-878c-e8cf1b92033e/badge)](https://nodesecurity.io/orgs/hapijs/projects/0394bf83-b5bc-410b-878c-e8cf1b92033e)
16
- [![Known Vulnerabilities](https://snyk.io/test/github/hapijs/joi/badge.svg)](https://snyk.io/test/github/hapijs/joi)
17
-
18
- [![Join the chat at https://gitter.im/hapijs/joi](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/hapijs/joi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
19
-
20
- Lead Maintainer: [Nicolas Morel](https://github.com/marsup)
9
+ This version of the package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact [sales@sideway.com](mailto:sales@sideway.com). The open source version of this package can be found [here](https://github.com/hapijs/joi).
21
10
 
22
11
  # Introduction
23
12
 
@@ -26,7 +15,8 @@ Imagine you run facebook and you want visitors to sign up on the website with re
26
15
  This is joi, joi allows you to create *blueprints* or *schemas* for JavaScript objects (an object that stores information) to ensure *validation* of key information.
27
16
 
28
17
  # API
29
- See the detailed [API Reference](https://github.com/hapijs/joi/blob/v12.0.0/API.md).
18
+
19
+ See the detailed [API Reference](https://github.com/hapijs/joi/blob/v12-commercial/API.md).
30
20
 
31
21
  # Example
32
22
 
package/lib/cast.js CHANGED
@@ -1,15 +1,11 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Hoek = require('hoek');
6
- const Ref = require('./ref');
7
4
 
5
+ const Ref = require('./ref');
8
6
  // Type modules are delay-loaded to prevent circular dependencies
9
7
 
10
8
 
11
- // Declare internals
12
-
13
9
  const internals = {};
14
10
 
15
11
 
package/lib/errors.js CHANGED
@@ -1,17 +1,15 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Hoek = require('hoek');
6
- const Language = require('./language');
7
4
 
5
+ const Language = require('./language');
8
6
 
9
- // Declare internals
10
7
 
11
8
  const internals = {
12
9
  annotations: Symbol('joi-annotations')
13
10
  };
14
11
 
12
+
15
13
  internals.stringify = function (value, wrapArrays) {
16
14
 
17
15
  const type = typeof value;
@@ -45,6 +43,7 @@ internals.stringify = function (value, wrapArrays) {
45
43
  return JSON.stringify(value);
46
44
  };
47
45
 
46
+
48
47
  exports.Err = class {
49
48
 
50
49
  constructor(type, context, state, options, flags, message, template) {
@@ -198,11 +197,13 @@ exports.process = function (errors, object) {
198
197
 
199
198
 
200
199
  // Inspired by json-stringify-safe
200
+
201
201
  internals.safeStringify = function (obj, spaces) {
202
202
 
203
203
  return JSON.stringify(obj, internals.serializer(), spaces);
204
204
  };
205
205
 
206
+
206
207
  internals.serializer = function () {
207
208
 
208
209
  const keys = [];
package/lib/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Hoek = require('hoek');
4
+
6
5
  const Any = require('./types/any');
7
6
  const Cast = require('./cast');
8
7
  const Errors = require('./errors');
@@ -10,8 +9,6 @@ const Lazy = require('./types/lazy');
10
9
  const Ref = require('./ref');
11
10
 
12
11
 
13
- // Declare internals
14
-
15
12
  const internals = {
16
13
  alternatives: require('./types/alternatives'),
17
14
  array: require('./types/array'),
@@ -24,6 +21,7 @@ const internals = {
24
21
  string: require('./types/string')
25
22
  };
26
23
 
24
+
27
25
  internals.applyDefaults = function (schema) {
28
26
 
29
27
  Hoek.assert(this, 'Must be invoked on a Joi instance.');
@@ -37,6 +35,7 @@ internals.applyDefaults = function (schema) {
37
35
  return schema;
38
36
  };
39
37
 
38
+
40
39
  internals.root = function () {
41
40
 
42
41
  const any = new Any();
@@ -430,5 +429,4 @@ internals.root = function () {
430
429
  return root;
431
430
  };
432
431
 
433
-
434
432
  module.exports = internals.root();
package/lib/language.js CHANGED
@@ -1,10 +1,5 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
-
6
- // Declare internals
7
-
8
3
  const internals = {};
9
4
 
10
5
 
package/lib/ref.js CHANGED
@@ -1,12 +1,8 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Hoek = require('hoek');
6
4
 
7
5
 
8
- // Declare internals
9
-
10
6
  const internals = {};
11
7
 
12
8
 
package/lib/schemas.js CHANGED
@@ -1,14 +1,11 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Joi = require('../');
6
4
 
7
5
 
8
- // Declare internals
9
-
10
6
  const internals = {};
11
7
 
8
+
12
9
  exports.options = Joi.object({
13
10
  abortEarly: Joi.boolean(),
14
11
  convert: Joi.boolean(),
package/lib/set.js CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  const Ref = require('./ref');
4
4
 
5
+
6
+ const internals = {};
7
+
8
+
5
9
  module.exports = class Set {
6
10
 
7
11
  constructor() {
@@ -1,15 +1,12 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Hoek = require('hoek');
4
+
6
5
  const Any = require('../any');
7
6
  const Cast = require('../../cast');
8
7
  const Ref = require('../../ref');
9
8
 
10
9
 
11
- // Declare internals
12
-
13
10
  const internals = {};
14
11
 
15
12
 
@@ -1,16 +1,13 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Hoek = require('hoek');
4
+
6
5
  const Ref = require('../../ref');
7
6
  const Errors = require('../../errors');
8
7
  let Alternatives = null; // Delay-loaded to prevent circular dependencies
9
8
  let Cast = null;
10
9
 
11
10
 
12
- // Declare internals
13
-
14
11
  const internals = {
15
12
  Set: require('../../set')
16
13
  };
@@ -1,14 +1,11 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
3
+ const Hoek = require('hoek');
4
4
 
5
5
  const Any = require('../any');
6
6
  const Cast = require('../../cast');
7
7
  const Ref = require('../../ref');
8
- const Hoek = require('hoek');
9
-
10
8
 
11
- // Declare internals
12
9
 
13
10
  const internals = {};
14
11
 
@@ -1,12 +1,9 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
- const Any = require('../any');
6
3
  const Hoek = require('hoek');
7
4
 
5
+ const Any = require('../any');
8
6
 
9
- // Declare internals
10
7
 
11
8
  const internals = {};
12
9
 
@@ -29,7 +26,7 @@ internals.Binary = class extends Any {
29
26
  options.convert) {
30
27
 
31
28
  try {
32
- result.value = new Buffer(value, this._flags.encoding);
29
+ result.value = Buffer.from(value, this._flags.encoding);
33
30
  }
34
31
  catch (e) {
35
32
  }
@@ -1,12 +1,9 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
- const Any = require('../any');
6
3
  const Hoek = require('hoek');
7
4
 
5
+ const Any = require('../any');
8
6
 
9
- // Declare internals
10
7
 
11
8
  const internals = {
12
9
  Set: require('../../set')
@@ -1,16 +1,14 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
3
+ const Hoek = require('hoek');
4
4
 
5
5
  const Any = require('../any');
6
6
  const Ref = require('../../ref');
7
- const Hoek = require('hoek');
8
-
9
7
 
10
- // Declare internals
11
8
 
12
9
  const internals = {};
13
10
 
11
+
14
12
  internals.isoDate = /^(?:[-+]\d{2})?(?:\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?![T]$|[T][\d]+Z$)(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24\:?00)(?:[.,]\d+(?!:))?)(?:\2[0-5]\d(?:[.,]\d+)?)?(?:[Z]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)?)?$/;
15
13
  internals.invalidDate = new Date('');
16
14
  internals.isIsoDate = (() => {
@@ -23,6 +21,7 @@ internals.isIsoDate = (() => {
23
21
  };
24
22
  })();
25
23
 
24
+
26
25
  internals.Date = class extends Any {
27
26
 
28
27
  constructor() {
@@ -1,14 +1,11 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Hoek = require('hoek');
4
+
6
5
  const ObjectType = require('../object');
7
6
  const Ref = require('../../ref');
8
7
 
9
8
 
10
- // Declare internals
11
-
12
9
  const internals = {};
13
10
 
14
11
 
@@ -1,12 +1,9 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
- const Any = require('../any');
6
3
  const Hoek = require('hoek');
7
4
 
5
+ const Any = require('../any');
8
6
 
9
- // Declare internals
10
7
 
11
8
  const internals = {};
12
9
 
@@ -1,13 +1,10 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
3
+ const Hoek = require('hoek');
4
4
 
5
5
  const Any = require('../any');
6
6
  const Ref = require('../../ref');
7
- const Hoek = require('hoek');
8
-
9
7
 
10
- // Declare internals
11
8
 
12
9
  const internals = {
13
10
  precisionRx: /(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/
@@ -1,16 +1,13 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Hoek = require('hoek');
6
4
  const Topo = require('topo');
5
+
7
6
  const Any = require('../any');
8
7
  const Errors = require('../../errors');
9
8
  const Cast = require('../../cast');
10
9
 
11
10
 
12
- // Declare internals
13
-
14
11
  const internals = {};
15
12
 
16
13
 
@@ -1,17 +1,16 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const Net = require('net');
4
+
5
+ const Address = require('@hapi/address');
6
6
  const Hoek = require('hoek');
7
- let Isemail; // Loaded on demand
7
+
8
8
  const Any = require('../any');
9
9
  const Ref = require('../../ref');
10
10
  const JoiDate = require('../date');
11
11
  const Uri = require('./uri');
12
12
  const Ip = require('./ip');
13
13
 
14
- // Declare internals
15
14
 
16
15
  const internals = {
17
16
  uriRegex: Uri.createUriRegex(),
@@ -30,6 +29,7 @@ const internals = {
30
29
  normalizationForms: ['NFC', 'NFD', 'NFKC', 'NFKD']
31
30
  };
32
31
 
32
+
33
33
  internals.String = class extends Any {
34
34
 
35
35
  constructor() {
@@ -168,41 +168,62 @@ internals.String = class extends Any {
168
168
  });
169
169
  }
170
170
 
171
- email(isEmailOptions) {
172
-
173
- if (isEmailOptions) {
174
- Hoek.assert(typeof isEmailOptions === 'object', 'email options must be an object');
175
- Hoek.assert(typeof isEmailOptions.checkDNS === 'undefined', 'checkDNS option is not supported');
176
- Hoek.assert(typeof isEmailOptions.tldWhitelist === 'undefined' ||
177
- typeof isEmailOptions.tldWhitelist === 'object', 'tldWhitelist must be an array or object');
178
- Hoek.assert(
179
- typeof isEmailOptions.minDomainAtoms === 'undefined' ||
180
- Number.isSafeInteger(isEmailOptions.minDomainAtoms) &&
181
- isEmailOptions.minDomainAtoms > 0,
182
- 'minDomainAtoms must be a positive integer'
183
- );
184
- Hoek.assert(
185
- typeof isEmailOptions.errorLevel === 'undefined' ||
186
- typeof isEmailOptions.errorLevel === 'boolean' ||
187
- (
188
- Number.isSafeInteger(isEmailOptions.errorLevel) &&
189
- isEmailOptions.errorLevel >= 0
190
- ),
191
- 'errorLevel must be a non-negative integer or boolean'
192
- );
193
- }
171
+ email(validationOptions) {
194
172
 
195
- return this._test('email', isEmailOptions, function (value, state, options) {
173
+ if (validationOptions) {
174
+ Hoek.assert(typeof validationOptions === 'object', 'email options must be an object');
196
175
 
197
- Isemail = Isemail || require('isemail');
176
+ // Migration validation for unsupported options
198
177
 
199
- try {
200
- const result = Isemail.validate(value, isEmailOptions);
201
- if (result === true || result === 0) {
202
- return value;
203
- }
178
+ Hoek.assert(validationOptions.checkDNS === undefined, 'checkDNS option is not supported');
179
+ Hoek.assert(validationOptions.errorLevel === undefined, 'errorLevel option is not supported');
180
+ Hoek.assert(validationOptions.minDomainAtoms === undefined, 'minDomainAtoms option is not supported, use minDomainSegments instead');
181
+ Hoek.assert(validationOptions.tldBlacklist === undefined, 'tldBlacklist option is not supported, use tlds.deny instead');
182
+ Hoek.assert(validationOptions.tldWhitelist === undefined, 'tldWhitelist option is not supported, use tlds.allow instead');
183
+
184
+ // Validate options
185
+
186
+ if (validationOptions.tlds &&
187
+ typeof validationOptions.tlds === 'object') {
188
+
189
+ Hoek.assert(validationOptions.tlds.allow === undefined ||
190
+ validationOptions.tlds.allow === false ||
191
+ validationOptions.tlds.allow === true ||
192
+ Array.isArray(validationOptions.tlds.allow) ||
193
+ validationOptions.tlds.allow instanceof Set, 'tlds.allow must be an array, Set, or boolean');
194
+
195
+ Hoek.assert(validationOptions.tlds.deny === undefined ||
196
+ Array.isArray(validationOptions.tlds.deny) ||
197
+ validationOptions.tlds.deny instanceof Set, 'tlds.deny must be an array or Set');
198
+
199
+ const normalizeTable = (table, name) => {
200
+
201
+ if (table === undefined ||
202
+ typeof table === 'boolean' ||
203
+ table instanceof Set) {
204
+
205
+ return table;
206
+ }
207
+
208
+ return new Set(table);
209
+ };
210
+
211
+ validationOptions = Object.assign({}, validationOptions); // Shallow cloned
212
+ validationOptions.tlds = {
213
+ allow: normalizeTable(validationOptions.tlds.allow),
214
+ deny: normalizeTable(validationOptions.tlds.deny)
215
+ };
216
+ }
217
+
218
+ Hoek.assert(validationOptions.minDomainSegments === undefined ||
219
+ Number.isSafeInteger(validationOptions.minDomainSegments) && validationOptions.minDomainSegments > 0, 'minDomainSegments must be a positive integer');
220
+ }
221
+
222
+ return this._test('email', validationOptions, function (value, state, options) {
223
+
224
+ if (Address.email.isValid(value, validationOptions)) {
225
+ return value;
204
226
  }
205
- catch (e) { }
206
227
 
207
228
  return this.createError('string.email', { value }, state, options);
208
229
  });
@@ -1,12 +1,8 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
3
  const RFC3986 = require('./rfc3986');
6
4
 
7
5
 
8
- // Declare internals
9
-
10
6
  const internals = {
11
7
  Ip: {
12
8
  cidrs: {
@@ -1,10 +1,5 @@
1
1
  'use strict';
2
2
 
3
- // Load modules
4
-
5
-
6
- // Delcare internals
7
-
8
3
  const internals = {
9
4
  rfc3986: {}
10
5
  };
@@ -1,12 +1,8 @@
1
1
  'use strict';
2
2
 
3
- // Load Modules
4
-
5
3
  const RFC3986 = require('./rfc3986');
6
4
 
7
5
 
8
- // Declare internals
9
-
10
6
  const internals = {
11
7
  Uri: {
12
8
  createUriRegex: function (optionalScheme, allowRelative, relativeOnly) {
@@ -42,5 +38,4 @@ const internals = {
42
38
  }
43
39
  };
44
40
 
45
-
46
41
  module.exports = internals.Uri;
package/package.json CHANGED
@@ -1,33 +1,30 @@
1
1
  {
2
2
  "name": "joi",
3
3
  "description": "Object schema validation",
4
- "version": "12.0.0",
4
+ "version": "12.1.1",
5
5
  "homepage": "https://github.com/hapijs/joi",
6
6
  "repository": "git://github.com/hapijs/joi",
7
+ "engines": {
8
+ "node": ">=6.0.0"
9
+ },
7
10
  "main": "lib/index.js",
8
11
  "keywords": [
9
12
  "hapi",
10
13
  "schema",
11
14
  "validation"
12
15
  ],
13
- "engines": {
14
- "node": ">=4.0.0"
15
- },
16
16
  "dependencies": {
17
+ "@hapi/address": "1.x.x",
17
18
  "hoek": "4.x.x",
18
- "isemail": "3.x.x",
19
19
  "topo": "2.x.x"
20
20
  },
21
21
  "devDependencies": {
22
- "hapitoc": "1.x.x",
22
+ "code": "4.x.x",
23
23
  "lab": "14.x.x"
24
24
  },
25
25
  "scripts": {
26
- "test": "lab -t 100 -a code -L",
27
- "test-debug": "lab -a code",
28
- "test-cov-html": "lab -r html -o coverage.html -a code",
29
- "toc": "hapitoc",
30
- "version": "npm run toc && git add API.md README.md"
26
+ "test": "lab -t 100 -a code -L -l",
27
+ "test-cov-html": "lab -r html -o coverage.html -a code -l"
31
28
  },
32
- "license": "BSD-3-Clause"
29
+ "license": "SEE LICENSE IN LICENSE.md"
33
30
  }
package/CHANGELOG.md DELETED
@@ -1,3 +0,0 @@
1
- Breaking changes are documented using GitHub issues, see [issues labeled "release notes"](https://github.com/hapijs/joi/issues?q=is%3Aissue+label%3A%22release+notes%22).
2
-
3
- If you want changes of a specific minor or patch release, you can browse the [GitHub milestones](https://github.com/hapijs/joi/milestones?state=closed&direction=asc&sort=due_date).
package/LICENSE DELETED
@@ -1,29 +0,0 @@
1
- Copyright (c) 2012-2017, Project contributors
2
- Copyright (c) 2012-2014, Walmart
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
- * Redistributions of source code must retain the above copyright
8
- notice, this list of conditions and the following disclaimer.
9
- * Redistributions in binary form must reproduce the above copyright
10
- notice, this list of conditions and the following disclaimer in the
11
- documentation and/or other materials provided with the distribution.
12
- * The names of any contributors may not be used to endorse or promote
13
- products derived from this software without specific prior written
14
- permission.
15
-
16
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
20
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
- * * *
28
-
29
- The complete list of contributors can be found at: https://github.com/hapijs/joi/graphs/contributors