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

@sumor/api-middleware

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sumor/api-middleware - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

2

package.json
{
"name": "@sumor/api-middleware",
"description": "API Middleware is a middleware for Node.JS. It can easily expose function to api, and validate parameters",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",

@@ -6,0 +6,0 @@ "repository": "sumor-cloud/api-middleware",

@@ -5,2 +5,3 @@ # api-middleware

[More Documentation](https://sumor.cloud/api-middleware)
API Middleware is a middleware for Node.JS.

@@ -24,3 +25,3 @@ It can easily expose function to api, and validate parameters

Require Node.JS version 16.x or above
Require Node.JS version 18.x or above

@@ -42,3 +43,3 @@ ### require Node.JS ES module

##### 1. Add a file named `plus.js` in your project folder `api`
1. Add a file named `plus.js` in your project folder `api`

@@ -53,3 +54,3 @@ ```js

##### [Optional] 2. Add a file named `plus.json` in your project folder `api`
2. [Optional] Add a file named `plus.json` in your project folder `api`

@@ -73,3 +74,3 @@ ```json

##### 3. Add the following code in your `index.js` file
3. Add the following code in your `index.js` file

@@ -88,3 +89,3 @@ ```javascript

##### 4. run index.js
4. run index.js

@@ -95,2 +96,36 @@ ```bash

### Parameter Rule
You can reference below example to apply rules to parameters
```json
{
"name": "plus",
"parameters": {
"a": {
"name": "parameter a",
"type": "number",
"length": 3,
"rule": [
{
"code": "GREATER_THAN_0",
"expression": "^[1-9][0-9]*$",
"message": "must be greater than 0"
}
],
"i18n": {
"zh": {
"GREATER_THAN_0": "必须大于0"
}
}
},
"b": {
"name": "parameter b",
"type": "number"
}
}
}
```
For more usage, please reference [Validator](https://sumor.cloud/validator/)
### context

@@ -97,0 +132,0 @@

@@ -43,3 +43,5 @@ import { meta } from '@sumor/config'

apiMeta[path].error = 'syntaxError'
logger.code('API_LOAD_FAILED_SYNTAX_ERROR', { path: apiMeta[path].route })
logger.code('API_LOAD_FAILED_SYNTAX_ERROR', {
path: apiMeta[path].route
})
logger.error(programResult.error)

@@ -54,3 +56,5 @@ } else {

if (hasFile) {
logger.code('API_LOAD_SUCCESS_WITH_FILE', { path: apiMeta[path].route })
logger.code('API_LOAD_SUCCESS_WITH_FILE', {
path: apiMeta[path].route
})
} else {

@@ -61,3 +65,5 @@ logger.code('API_LOAD_SUCCESS', { path: apiMeta[path].route })

apiMeta[path].error = 'missingDefaultExport'
logger.code('API_LOAD_FAILED_MISSING_DEFAULT', { path: apiMeta[path].route })
logger.code('API_LOAD_FAILED_MISSING_DEFAULT', {
path: apiMeta[path].route
})
}

@@ -64,0 +70,0 @@ apiMeta[path].program = program

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