
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@centralping/json-api-query
Advanced tools
An extensible JSON Schema for validating and optionally coercing JSON API query parameters for fetching data.
// Example Original URL:
// http://localhost:3000/?include=author&fields%5Barticles%5D=title%2Cbody&fields%5Bpeople%5D=name
// Parsed querystring:
{
include: 'author',
fields: {
articles: ['title', 'body']
},
fields: {
people: 'name'
}
}
npm i --save @centralping/json-api-query
Object
Module property that generates a new deep copy of the default schema
on every import. Apply any extensions and provide as an optional schema
for the validate
method.
Kind: inner property of jsonApiQuery
Object
Kind: inner property of jsonApiQuery
Returns: Object
- A url parse object.
Param | Type | Description |
---|---|---|
url | String | Any URL string. |
Example
const url = '/foo/bar?include=author&fields%5Barticles%5D=title%2Cbody&fields%5Bpeople%5D=name';
const {query, pathname, ...extra} = parse(url);
// query
// {
// include: [ 'author' ],
// fields: {
// articles: ['title', 'body'],
// people: ['name']
// }
// }
// pathname
// '/foo/bar'
function
Kind: inner property of jsonApiQuery
Returns: function
- the configured validator function
Param | Type | Default | Description |
---|---|---|---|
[options] | Object | any AJV option. | |
[options.coerceTypes] | Boolean | String | 'array' | coerce validated values to specified types. |
[options.ownProperties] | Boolean | true | restrict validation to own properties of data object. |
[schema] | Object | JSON Schema. Defaults to the included schema . |
Example
const validator = validate();
const valid = validator(queryParams); // where queryParams is an object
if (!valid) {
// Log errors
console.log(validator.errors);
}
const {validate} = require('@centralping/json-api-query');
const validator = validate();
// queryParams would be an query param object to validate/coerce
const valid = validator(queryParams);
if (!valid) {
// Log errors
console.log(validator.errors);
}
const {validate, schema} = require('@centralping/json-api-query');
// extend schema
const validator = validate(undefined, schema);
// queryParams would be an query param object to validate/coerce
const valid = validator(queryParams);
if (!valid) {
// Log errors
console.log(validator.errors);
}
const {validate} = require('@centralping/json-api-query');
const validator = validate({allErrors: true});
// queryParams would be an query param object to validate/coerce
const valid = validator(queryParams);
if (!valid) {
// Log errors
console.log(validator.errors);
}
const {parse, validate} = require('@centralping/json-api-query');
const validator = validate();
const {query} = parse(url); // url is a string
const valid = validator(query);
if (!valid) {
// Log errors
console.log(validator.errors);
}
npm test
With coverage reporting:
npm test -- --coverage
With file watch:
npm run watch
MIT
v0.1.3 (2018-11-22)
FAQs
A JSON API compliant query parameter validator.
We found that @centralping/json-api-query demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.