Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

har-validator

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

har-validator - npm Package Compare versions

Comparing version 2.0.6 to 2.1.0

lib/bin.js

128

lib/async.js

@@ -1,14 +0,122 @@

'use strict'
'use strict';
var runner = require('./runner')
var schemas = require('./schemas')
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validator = validator;
exports.default = har;
exports.cache = cache;
exports.cacheEntry = cacheEntry;
exports.content = content;
exports.cookie = cookie;
exports.creator = creator;
exports.entry = entry;
exports.log = log;
exports.page = page;
exports.pageTimings = pageTimings;
exports.postData = postData;
exports.record = record;
exports.request = request;
exports.response = response;
exports.timings = timings;
module.exports = function (data, cb) {
return runner(schemas.har, data, cb)
var _schemas = require('./schemas');
var schemas = _interopRequireWildcard(_schemas);
var _error = require('./error');
var _error2 = _interopRequireDefault(_error);
var _isMyJsonValid = require('is-my-json-valid');
var _isMyJsonValid2 = _interopRequireDefault(_isMyJsonValid);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function validator(schema) {
var data = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var cb = arguments[2];
// default value
var valid = false;
// validator config
var validate = (0, _isMyJsonValid2.default)(schema, {
greedy: true,
verbose: true,
schemas: schemas
});
// execute is-my-json-valid
valid = validate(data);
// callback?
if (typeof cb === 'function') {
return cb(validate.errors ? new _error2.default(validate.errors) : null, valid);
}
return valid;
}
Object.keys(schemas).map(function (name) {
module.exports[name] = function (data, cb) {
return runner(schemas[name], data, cb)
}
})
function har(data, cb) {
return validator(schemas.har, data, cb);
}
function cache(data, cb) {
return validator(schemas.cache, data, cb);
}
function cacheEntry(data, cb) {
return validator(schemas.cacheEntry, data, cb);
}
function content(data, cb) {
return validator(schemas.content, data, cb);
}
function cookie(data, cb) {
return validator(schemas.cookie, data, cb);
}
function creator(data, cb) {
return validator(schemas.creator, data, cb);
}
function entry(data, cb) {
return validator(schemas.entry, data, cb);
}
function log(data, cb) {
return validator(schemas.log, data, cb);
}
function page(data, cb) {
return validator(schemas.page, data, cb);
}
function pageTimings(data, cb) {
return validator(schemas.pageTimings, data, cb);
}
function postData(data, cb) {
return validator(schemas.postData, data, cb);
}
function record(data, cb) {
return validator(schemas.record, data, cb);
}
function request(data, cb) {
return validator(schemas.request, data, cb);
}
function response(data, cb) {
return validator(schemas.response, data, cb);
}
function timings(data, cb) {
return validator(schemas.timings, data, cb);
}

16

lib/error.js

@@ -1,10 +0,12 @@

'use strict'
'use strict';
function ValidationError (errors) {
this.name = 'ValidationError'
this.errors = errors
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = HARError;
function HARError(errors) {
this.name = 'HARError';
this.errors = errors;
}
ValidationError.prototype = Error.prototype
module.exports = ValidationError
HARError.prototype = Error.prototype;

@@ -1,22 +0,115 @@

'use strict'
'use strict';
var Promise = require('pinkie-promise')
var runner = require('./runner')
var schemas = require('./schemas')
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validator = validator;
exports.default = har;
exports.cache = cache;
exports.cacheEntry = cacheEntry;
exports.content = content;
exports.cookie = cookie;
exports.creator = creator;
exports.entry = entry;
exports.log = log;
exports.page = page;
exports.pageTimings = pageTimings;
exports.postData = postData;
exports.record = record;
exports.request = request;
exports.response = response;
exports.timings = timings;
var promisify = function (schema) {
return function (data) {
return new Promise(function (resolve, reject) {
runner(schema, data, function (err, valid) {
return err === null ? resolve(data) : reject(err)
})
})
}
var _schemas = require('./schemas');
var schemas = _interopRequireWildcard(_schemas);
var _error = require('./error');
var _error2 = _interopRequireDefault(_error);
var _isMyJsonValid = require('is-my-json-valid');
var _isMyJsonValid2 = _interopRequireDefault(_isMyJsonValid);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function validator(schema) {
var data = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
return new Promise(function (resolve, reject) {
// validator config
var validate = (0, _isMyJsonValid2.default)(schema, {
greedy: true,
verbose: true,
schemas: schemas
});
// execute is-my-json-valid
validate(data);
validate.errors ? reject(new _error2.default(validate.errors)) : resolve(data);
});
}
module.exports = promisify(schemas.har)
function har(data) {
return validator(schemas.har, data);
}
// utility methods for all parts of the schema
Object.keys(schemas).map(function (name) {
module.exports[name] = promisify(schemas[name])
})
function cache(data) {
return validator(schemas.cache, data);
}
function cacheEntry(data) {
return validator(schemas.cacheEntry, data);
}
function content(data) {
return validator(schemas.content, data);
}
function cookie(data) {
return validator(schemas.cookie, data);
}
function creator(data) {
return validator(schemas.creator, data);
}
function entry(data) {
return validator(schemas.entry, data);
}
function log(data) {
return validator(schemas.log, data);
}
function page(data) {
return validator(schemas.page, data);
}
function pageTimings(data) {
return validator(schemas.pageTimings, data);
}
function postData(data) {
return validator(schemas.postData, data);
}
function record(data) {
return validator(schemas.record, data);
}
function request(data) {
return validator(schemas.request, data);
}
function response(data) {
return validator(schemas.response, data);
}
function timings(data) {
return validator(schemas.timings, data);
}

@@ -1,49 +0,115 @@

'use strict'
'use strict';
var schemas = {
cache: require('./cache.json'),
cacheEntry: require('./cacheEntry.json'),
content: require('./content.json'),
cookie: require('./cookie.json'),
creator: require('./creator.json'),
entry: require('./entry.json'),
har: require('./har.json'),
log: require('./log.json'),
page: require('./page.json'),
pageTimings: require('./pageTimings.json'),
postData: require('./postData.json'),
record: require('./record.json'),
request: require('./request.json'),
response: require('./response.json'),
timings: require('./timings.json')
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.timings = exports.response = exports.request = exports.record = exports.postData = exports.pageTimings = exports.page = exports.log = exports.har = exports.entry = exports.creator = exports.cookie = exports.content = exports.cacheEntry = exports.cache = undefined;
// is-my-json-valid does not provide meaningful error messages for external schemas
// this is a workaround
schemas.cache.properties.beforeRequest = schemas.cacheEntry
schemas.cache.properties.afterRequest = schemas.cacheEntry
var _cache = require('./cache.json');
schemas.page.properties.pageTimings = schemas.pageTimings
var _cache2 = _interopRequireDefault(_cache);
schemas.request.properties.cookies.items = schemas.cookie
schemas.request.properties.headers.items = schemas.record
schemas.request.properties.queryString.items = schemas.record
schemas.request.properties.postData = schemas.postData
var _cacheEntry = require('./cacheEntry.json');
schemas.response.properties.cookies.items = schemas.cookie
schemas.response.properties.headers.items = schemas.record
schemas.response.properties.content = schemas.content
var _cacheEntry2 = _interopRequireDefault(_cacheEntry);
schemas.entry.properties.request = schemas.request
schemas.entry.properties.response = schemas.response
schemas.entry.properties.cache = schemas.cache
schemas.entry.properties.timings = schemas.timings
var _content = require('./content.json');
schemas.log.properties.creator = schemas.creator
schemas.log.properties.browser = schemas.creator
schemas.log.properties.pages.items = schemas.page
schemas.log.properties.entries.items = schemas.entry
var _content2 = _interopRequireDefault(_content);
schemas.har.properties.log = schemas.log
var _cookie = require('./cookie.json');
module.exports = schemas
var _cookie2 = _interopRequireDefault(_cookie);
var _creator = require('./creator.json');
var _creator2 = _interopRequireDefault(_creator);
var _entry = require('./entry.json');
var _entry2 = _interopRequireDefault(_entry);
var _har = require('./har.json');
var _har2 = _interopRequireDefault(_har);
var _log = require('./log.json');
var _log2 = _interopRequireDefault(_log);
var _page = require('./page.json');
var _page2 = _interopRequireDefault(_page);
var _pageTimings = require('./pageTimings.json');
var _pageTimings2 = _interopRequireDefault(_pageTimings);
var _postData = require('./postData.json');
var _postData2 = _interopRequireDefault(_postData);
var _record = require('./record.json');
var _record2 = _interopRequireDefault(_record);
var _request = require('./request.json');
var _request2 = _interopRequireDefault(_request);
var _response = require('./response.json');
var _response2 = _interopRequireDefault(_response);
var _timings = require('./timings.json');
var _timings2 = _interopRequireDefault(_timings);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
* copy external scheams internally
* is-my-json-valid does not provide meaningful error messages for external schemas
*/
_cache2.default.properties.beforeRequest = _cacheEntry2.default;
_cache2.default.properties.afterRequest = _cacheEntry2.default;
_page2.default.properties.pageTimings = _pageTimings2.default;
_request2.default.properties.cookies.items = _cookie2.default;
_request2.default.properties.headers.items = _record2.default;
_request2.default.properties.queryString.items = _record2.default;
_request2.default.properties.postData = _postData2.default;
_response2.default.properties.cookies.items = _cookie2.default;
_response2.default.properties.headers.items = _record2.default;
_response2.default.properties.content = _content2.default;
_entry2.default.properties.request = _request2.default;
_entry2.default.properties.response = _response2.default;
_entry2.default.properties.cache = _cache2.default;
_entry2.default.properties.timings = _timings2.default;
_log2.default.properties.creator = _creator2.default;
_log2.default.properties.browser = _creator2.default;
_log2.default.properties.pages.items = _page2.default;
_log2.default.properties.entries.items = _entry2.default;
_har2.default.properties.log = _log2.default;
exports.cache = _cache2.default;
exports.cacheEntry = _cacheEntry2.default;
exports.content = _content2.default;
exports.cookie = _cookie2.default;
exports.creator = _creator2.default;
exports.entry = _entry2.default;
exports.har = _har2.default;
exports.log = _log2.default;
exports.page = _page2.default;
exports.pageTimings = _pageTimings2.default;
exports.postData = _postData2.default;
exports.record = _record2.default;
exports.request = _request2.default;
exports.response = _response2.default;
exports.timings = _timings2.default;
{
"version": "2.0.6",
"name": "har-validator",
"description": "Extremely fast HTTP Archive (HAR) validator using JSON Schema",
"author": "Ahmad Nassri <ahmad@ahmadnassri.com> (https://www.ahmadnassri.com/)",
"description": "unnamed package",
"author": {
"name": "Ahmad Nassri",
"email": "ahmad@ahmadnassri.com",
"url": "https://www.ahmadnassri.com/"
},
"homepage": "https://github.com/ahmadnassri/har-validator",
"repository": "ahmadnassri/har-validator",
"repository": {
"type": "git",
"url": "git+https://github.com/ahmadnassri/har-validator.git"
},
"license": "ISC",
"main": "lib/index",
"bin": "bin/har-validator",
"main": "lib/index.js",
"bin": {
"har-validator": "lib/bin.js"
},
"keywords": [

@@ -22,4 +30,5 @@ "har",

"files": [
"bin",
"lib"
"schemas",
"lib",
"src"
],

@@ -30,21 +39,51 @@ "bugs": {

"scripts": {
"compile": "babel -q src --out-dir lib",
"test": "tap test/*.js --node-arg=--require --node-arg=babel-register --node-arg=--require --node-arg=babel-polyfill | tap-mocha-reporter spec",
"pretest": "standard && echint",
"test": "mocha",
"posttest": "npm run coverage",
"coverage": "istanbul cover --dir coverage _mocha -- -R dot",
"codeclimate": "codeclimate < coverage/lcov.info"
"coverage": "tap test/*.js --coverage --nyc-arg=--require --nyc-arg=babel-register --nyc-arg=--require --nyc-arg=babel-polyfill",
"codeclimate": "nyc report --reporter=text-lcov | codeclimate-test-reporter",
"prepublish": "npm run compile",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"babel": {
"presets": [
"es2015"
],
"plugins": [
"transform-export-extensions",
"transform-object-rest-spread"
]
},
"standard": {
"ignore": [
"lib/**",
"src/index.js",
"test/fixtures/**"
]
},
"echint": {
"ignore": [
"coverage/**"
"lib/**"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"devDependencies": {
"codeclimate-test-reporter": "0.2.1",
"echint": "^1.5.1",
"istanbul": "^0.4.2",
"mocha": "^2.3.4",
"require-directory": "^2.1.1",
"should": "^8.1.1",
"standard": "^5.4.1"
"babel-cli": "^6.6.5",
"babel-plugin-transform-export-extensions": "^6.5.0",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-polyfill": "^6.6.1",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.6.5",
"codeclimate-test-reporter": "^0.3.1",
"cz-conventional-changelog": "^1.1.5",
"echint": "^1.5.3",
"nyc": "^6.0.0",
"semantic-release": "^6.2.0",
"standard": "^6.0.7",
"tap": "^5.7.0",
"tap-mocha-reporter": "0.0.24"
},

@@ -54,5 +93,7 @@ "dependencies": {

"commander": "^2.9.0",
"is-my-json-valid": "^2.12.4",
"pinkie-promise": "^2.0.0"
}
}
"is-my-json-valid": "^2.13.1"
},
"version": "2.1.0",
"readme": "ERROR: No README data found!",
"_id": "har-validator@"
}

@@ -13,3 +13,3 @@ # HAR Validator [![version][npm-version]][npm-url] [![License][npm-license]][license-url]

```shell
```bash
# to use in cli

@@ -22,3 +22,3 @@ npm install --global har-validator

## Usage
## CLI Usage

@@ -45,243 +45,18 @@ ```

## API
## API
**Note**: as of [`v2.0.0`](https://github.com/ahmadnassri/har-validator/releases/tag/v2.0.0) this module defaults to Promise based API. *For backward comptability with `v1.x` an [async/callback API](#callback-api) is provided*
**Note**: as of [`v2.0.0`](https://github.com/ahmadnassri/har-validator/releases/tag/v2.0.0) this module defaults to Promise based API. *For backward comptability with `v1.x` an [async/callback API](docs/async.md) is also provided*
### Validate(data)
- [async API](docs/async.md)
- [callback API](docs/async.md)
- [Promise API](docs/promise.md) *(default)*
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a full [HAR](http://www.softwareishard.com/blog/har-12-spec/) object
```js
validate(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.log(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [log](http://www.softwareishard.com/blog/har-12-spec/#log) object
```js
validate.log(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.cache(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [cache](http://www.softwareishard.com/blog/har-12-spec/#cache) object
```js
validate.cache(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.cacheEntry(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a ["beforeRequest" or "afterRequest"](http://www.softwareishard.com/blog/har-12-spec/#cache) objects
```js
validate.cacheEntry(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.content(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [content](http://www.softwareishard.com/blog/har-12-spec/#content) object
```js
validate.content(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.cookie(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [cookie](http://www.softwareishard.com/blog/har-12-spec/#cookies) object
```js
validate.cookie(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.creator(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [creator](http://www.softwareishard.com/blog/har-12-spec/#creator) object
```js
validate.creator(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.entry(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
an [entry](http://www.softwareishard.com/blog/har-12-spec/#entries) object
```js
validate.entry(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.log(data)
alias of [`Validate(data)`](#validate-data-callback-)
### Validate.page(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [page](http://www.softwareishard.com/blog/har-12-spec/#pages) object
```js
validate.page(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.pageTimings(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [pageTimings](http://www.softwareishard.com/blog/har-12-spec/#pageTimings) object
```js
validate.pageTimings(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.postData(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [postData](http://www.softwareishard.com/blog/har-12-spec/#postData) object
```js
validate.postData(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.record(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [record](http://www.softwareishard.com/blog/har-12-spec/#headers) object
```js
validate.record(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.request(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [request](http://www.softwareishard.com/blog/har-12-spec/#request) object
```js
validate.request(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.response(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [response](http://www.softwareishard.com/blog/har-12-spec/#response) object
```js
validate.cacheEntry(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
### Validate.timings(data)
> Returns a promise that resolves to the valid object.
- **data**: `Object` *(Required)*
a [timings](http://www.softwareishard.com/blog/har-12-spec/#timings) object
```js
validate.timings(data)
.then(data => console.log('horray!'))
.catch(console.error)
```
----
> :copyright: [www.ahmadnassri.com](https://www.ahmadnassri.com/) &nbsp;&middot;&nbsp;
> License: [ISC](LICENSE) &nbsp;&middot;&nbsp;
> Github: [@ahmadnassri](https://github.com/ahmadnassri) &nbsp;&middot;&nbsp;
> Twitter: [@ahmadnassri](https://twitter.com/ahmadnassri)
## Callback API
[license-url]: http://choosealicense.com/licenses/isc/
### Validate(data [, callback])
> Returns `true` or `false`.
```js
var HAR = require('./har.json');
var validate = require('har-validator/lib/async');
validate(HAR, function (e, valid) {
if (e) console.log(e.errors)
if (valid) console.log('horray!');
});
```
The async API provides exactly the same methods as the [Promise API](#promise-api)
----
## Support
Donations are welcome to help support the continuous development of this project.
[![Gratipay][gratipay-image]][gratipay-url]
[![PayPal][paypal-image]][paypal-url]
[![Flattr][flattr-image]][flattr-url]
[![Bitcoin][bitcoin-image]][bitcoin-url]
## License
[ISC License](LICENSE) &copy; [Ahmad Nassri](https://www.ahmadnassri.com/)
[license-url]: https://github.com/ahmadnassri/har-validator/blob/master/LICENSE
[travis-url]: https://travis-ci.org/ahmadnassri/har-validator

@@ -301,13 +76,1 @@ [travis-image]: https://img.shields.io/travis/ahmadnassri/har-validator.svg?style=flat-square

[david-image]: https://img.shields.io/david/ahmadnassri/har-validator.svg?style=flat-square
[gratipay-url]: https://www.gratipay.com/ahmadnassri/
[gratipay-image]: https://img.shields.io/gratipay/ahmadnassri.svg?style=flat-square
[paypal-url]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UJ2B2BTK9VLRS&on0=project&os0=har-validator
[paypal-image]: http://img.shields.io/badge/paypal-donate-green.svg?style=flat-square
[flattr-url]: https://flattr.com/submit/auto?user_id=ahmadnassri&url=https://github.com/ahmadnassri/har-validator&title=har-validator&language=&tags=github&category=software
[flattr-image]: http://img.shields.io/badge/flattr-donate-green.svg?style=flat-square
[bitcoin-image]: http://img.shields.io/badge/bitcoin-1Nb46sZRVG3or7pNaDjthcGJpWhvoPpCxy-green.svg?style=flat-square
[bitcoin-url]: https://www.coinbase.com/checkouts/ae383ae6bb931a2fa5ad11cec115191e?name=har-validator
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc