Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
ac-api-express-extensions
Advanced tools
This packages adds 3 valuable helper function to your express app:
yarn add ac-api-express-extensions
const acaee = require('acaee)
// as middleware
const app = express()
app.get('/v1/user', [acaee.allParams, acaee.sanitizer], (req, res) => {
const params = req.allParams()
// DO YOUR THING
})
Provides a single property of all available parameters (from query, path and JSON body).
const params = req.allParams()
Use a field definition to make sure only pre-defined data is allowed in your API. We use ac-sanitizer to provide sanitizing of the incoming data.
// your field definitions, e.g. for your user controller and the action find
const apiDoc = {
user: {
fields: [
{
actions: ["find"],
field: "lastname",
type: "string",
description: [
{
action: "find",
message: "Lastname of the user your want to find"
}
]
}
]
}
}
// route is usually an empty object. If you want to use a custom sanitizer you can
// define the sanitizing function in the route object
//
// Additionally you can add controller and action to the route object
// if you are not using req.option - please see ATTENTIOn section below.
const route = {}
const middleware = [acaee.allParams, sanitizer.bind(this, { apiDoc }, route)]
const app = express()
app.get('/v1/user', middleware, (req, res) => {
const params = req.allParams() // this is now sanitized
// DO YOUR THING
})
// EXAMPLE
GET /v1/user?firstname=tom&lastname=dooley
// -> req.allParams() = { lastname: dooley }
ATTENTION
Please keep in mind, that this sanitizer required allParams, so make sure to have it in your express middleware array BEFORE the sanitizer.
Additionally, the sanitizer requires the controller and action name in order to determine the proper field definition in your apiDoc configuration object. Make sure to provide them as req.options.controller and req.options.action or put them in your route object for the sanitizer.
This function adds a route/endpoint /apidoc to your controller and provides an API documentation object as response.
API documentation is based on the same field definitions as your sanitizer.
// your field definitions, e.g. for your user controller and the action find
const apiDoc = {
user: {
fields: [
{
actions: ["find"],
field: "lastname",
type: "string",
description: [
{
action: "find",
message: "Lastname of the user your want to find"
}
]
}
]
}
}
const app = express()
app.get('/v1/user', middleware, (req, res) => {
const params = req.allParams() // this is now sanitized
// DO YOUR THING
})
let aconfig = {
http: {
apiDoc: {
apiPrefix: 'v5'
}
},
apiDoc // from above
}
let aparams = {
name: 'find',
availableActions: ['find'],
routes: [{ method: 'get', path: '/v1/user, action: 'find' }]
}
const { apiDocRoute, apiDoc} = acaee.apidocRoute(aconfig, aparams)
app.express.get(apiDocRoute.path, expressMiddleWare, apiDoc)
// apiDocRoute contains some information regarding this route
// apiDoc is the actually function (req, res) that is called by express
// EXAMPLE
GET /v1/user/apidoc
[{
"name": user.find",
"method": "get",
"path": "/v1/user",
request: {
fields: [{ // field definition }]
}
}]
Use this function to get the default values for a given object (in APIdoc)
const def = {
fields: [{
field: 'field1',
type: 'string'
...
}, {
field: 'field2',
type: 'object',
properties: [{
field: 'prop1',
type: 'string,
defaultsTo: 'Prop1 default value'
}]
}]
}
const defaultObject = acaee.defaultValues({
fields: def.fields,
field: 'field2'
})
// response
{
field2: {
prop1: 'Prop1 default value'
}
}
Use this function to get a list of fields with special markers (e.g. deprecation markers)
const def = {
fields: [{
field: 'field1',
type: 'string'
deprecated: true
}, {
field: 'field2',
type: 'object',
properties: [{
field: 'prop1',
type: 'string,
deprecated: true
}]
}]
}
const defaultObject = acaee.markedFields({
fields: def.fields
})
// response
['field1', 'field2.prop1']
0.2.11 (2021-05-02 10:55:49)
FAQs
AdmiralCloud ExpressJS extensions for your API
The npm package ac-api-express-extensions receives a total of 4 weekly downloads. As such, ac-api-express-extensions popularity was classified as not popular.
We found that ac-api-express-extensions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.