Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@janiscommerce/api-list
Advanced tools
A package to handle JANIS List APIs
npm install @janiscommerce/api-list
'use strict';
const { ApiListData } = require('@janiscommerce/api-list');
module.exports = class MyApiListData extends ApiListData {
get fieldsToSelect() {
return ['id', 'name', 'status'];
}
get sortableFields() {
return [
'id',
'status'
];
}
get availableFilters() {
return [
'id',
{
name: 'quantity',
valueMapper: Number
},
{
name: 'hasSubProperty',
internalName: (filterConfiguration, mappedValue, originalValue) => `rootProperty.${originalValue}`,
valueMapper: () => true
}
];
}
async formatRows(rows) {
return rows.map(row => ({ ...row, oneMoreField: true }));
}
};
If you have for example, a list API for a sub-entity of one specific record, the parent will be automatically be added as a filter.
Important: The parent entity must be listed as an available filter
For example, the following endpoint: /api/parent-entity/1/sub-entity
, will be a list of the sub-entity, and parentEntity: '1'
will be set as a filter.
It could be thought as if it's equivalent to the following request: /api/sub-entity?filters[parentEntity]=1
The following getters and methods can be used to customize and validate your List API. All of them are optional.
This is used to indicate which fields should be selected from the DB. This allows you to select fields from other tables, and automatically join them in relational databases. This fields must be defined in the model.
This is used to indicate which fields can be used to sort the list. Any other sort field will return a 400 status code.
This is used to indicate which fields can be used to filter the list. Any other filter will return a 400 status code. Filters can be customized by passing an object with the following properties:
name
: (string) The name of the filter param. This property is required.internalName
: (string|function) The name of the field, as defined in the model. This should not be defined in case it's equal to name
.
If it's a function (since 3.1.0), it must return a string and it will receive the following arguments: (filterConfiguration, mappedValue, originalValue)
valueMapper
: (function) A function to be called on the filter's value. This is optional.You can use this to format your records before they are returned. For example, mapping DB friendly values to user friendly values, add default values, translation keys, etc.
Since 3.1.0
This lib also exports some common filter value mappers (to use as valueMapper
in your availableFilters
getter) so you don't need to implement them yourself.
They are explained here with examples:
'use strict';
const {
ApiListData,
FilterMappers: {
booleanMapper,
dateMapper,
startOfTheDayMapper,
endOfTheDayMapper,
searchMapper,
customTypeMapper
}
} = require('@janiscommerce/api-list');
module.exports = class MyApiListData extends ApiListData {
get availableFilters() {
return [
{
name: 'canDoSomething',
valueMapper: booleanMapper // Maps '0', 'false', '', and false to false. Any other value is mapped to true.
},
{
name: 'someExactDate',
valueMapper: dateMapper // Maps to a date object
},
{
name: 'dateCreatedDay',
internalName: 'dateCreatedFrom',
valueMapper: startOfTheDayMapper // Maps to a date object at the start of the day
},
{
name: 'dateCreatedDay',
internalName: 'dateCreatedTo',
valueMapper: endOfTheDayMapper // Maps to a date object at the end of the day
},
{
name: 'name',
valueMapper: searchMapper // Maps to an object like this: { type: 'search', value }
},
{
name: 'isOlderThan',
internalName: 'age',
valueMapper: customTypeMapper('greater') // This returns a mapper like this: value => ({ type: 'greater', value })
}
];
}
};
[3.1.0] - 2020-02-27
FilterMappers
internalName
can now also be a functionFAQs
A package to handle Janis List APIs
The npm package @janiscommerce/api-list receives a total of 385 weekly downloads. As such, @janiscommerce/api-list popularity was classified as not popular.
We found that @janiscommerce/api-list demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.