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

@aomex/web

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aomex/web - npm Package Compare versions

Comparing version 0.0.22 to 0.0.23

162

CHANGELOG.md
# @aomex/web
## 0.0.22
## 0.0.23
### Patch Changes
- [`e9996cb`](https://github.com/aomex/aomex/commit/e9996cb33cc0ef70b42147be02fbbe2b4954e022) Thanks [@geekact](https://github.com/geekact)! - feat(validator): docs method provide second parameter determine how to merge document
- [`e21007a`](https://github.com/aomex/aomex/commit/e21007a82cb8eac73e1f696340bbe986d57dc159) Thanks [@geekact](https://github.com/geekact)! - chore(web): 升级依赖formidable到v3.4.0
- Updated dependencies []:
- @aomex/core@0.0.21
- [`e21007a`](https://github.com/aomex/aomex/commit/e21007a82cb8eac73e1f696340bbe986d57dc159) Thanks [@geekact](https://github.com/geekact)! - feat(web): 验证响应的数据
## 0.0.21
- [`818e840`](https://github.com/aomex/aomex/commit/818e840d36c7456a863fc071968b246c123c17f5) Thanks [@geekact](https://github.com/geekact)! - refactor(core): 对象使用统一逻辑转换成验证器
### Patch Changes
- [`a8dbaf3`](https://github.com/aomex/aomex/commit/a8dbaf38524f5a5d58337bc617175115742f9e1a) Thanks [@geekact](https://github.com/geekact)! - feat(web): remove readonly modifier from request.method and request.url
- Updated dependencies [[`ddcec91`](https://github.com/aomex/aomex/commit/ddcec91803b00f35f7c55964d1a2d97c40a22c6e)]:
- @aomex/core@0.0.20
## 0.0.20
### Patch Changes
- Updated dependencies [[`6cbc69b`](https://github.com/aomex/aomex/commit/6cbc69bfce9d03b4880b94f9ec0ee20c9ae937a8)]:
- @aomex/utility@0.0.7
- @aomex/core@0.0.19
## 0.0.19
### Patch Changes
- Updated dependencies []:
- @aomex/core@0.0.18
## 0.0.18
### Patch Changes
- Updated dependencies [[`37946d2`](https://github.com/aomex/aomex/commit/37946d2b91a560c851fa21fa327b5b968b794862)]:
- @aomex/utility@0.0.6
- @aomex/core@0.0.17
## 0.0.17
### Patch Changes
- [`216aa79`](https://github.com/aomex/aomex/commit/216aa798bcd2d0856f5fe4028235aa54d4b10922) Thanks [@geekact](https://github.com/geekact)! - refactor(validator): replace docs modifier to protected and redeclare public in each child validator
- Updated dependencies []:
- @aomex/core@0.0.16
## 0.0.16
### Patch Changes
- [`280359e`](https://github.com/aomex/aomex/commit/280359eb90b71720304cfc212374b6dc4c90236d) Thanks [@geekact](https://github.com/geekact)! - feat(web): make file-validator immutable
- [`9881653`](https://github.com/aomex/aomex/commit/988165361439738d27bc29bd0ed5a85c608db5ef) Thanks [@geekact](https://github.com/geekact)! - feat(validator)!: create namespace for each validator
- [`15ecd1c`](https://github.com/aomex/aomex/commit/15ecd1c75bc21929f79980b32e63ea46e081cc6a) Thanks [@geekact](https://github.com/geekact)! - refactor(validator)!: declare magistrate namespace
- Updated dependencies []:
- @aomex/core@0.0.15
## 0.0.15
### Patch Changes
- Updated dependencies []:
- @aomex/core@0.0.14
## 0.0.14
### Patch Changes
- [`715cf66`](https://github.com/aomex/aomex/commit/715cf660e3b275b338dcf15c25ba9523cf6fb204) Thanks [@geekact](https://github.com/geekact)! - feat(web): translate error message to English
- Updated dependencies []:
- @aomex/core@0.0.13
## 0.0.13
### Patch Changes
- [`6e63df8`](https://github.com/aomex/aomex/commit/6e63df84d1b32e713aba8c52451e289a72b57bae) Thanks [@geekact](https://github.com/geekact)! - feat(web): make sure path parameter includes 'required' property when generate openapi document
- [`67acf4f`](https://github.com/aomex/aomex/commit/67acf4f42cd86bf1f0a7c647a5ff779c7cd0fa10) Thanks [@geekact](https://github.com/geekact)! - feat(web): response.schema is optional
- Updated dependencies []:
- @aomex/core@0.0.12
## 0.0.12
### Patch Changes
- [`f14eb5f`](https://github.com/aomex/aomex/commit/f14eb5fe7bf06e1e2f64d45e3546c96d6079a2f1) Thanks [@geekact](https://github.com/geekact)! - feat(web): add getters to request
- [`7d923cf`](https://github.com/aomex/aomex/commit/7d923cf971b6a23d50113ab104c67041c6489053) Thanks [@geekact](https://github.com/geekact)! - feat(web)!: do not transform querystring value to array
- [`3c5ad4e`](https://github.com/aomex/aomex/commit/3c5ad4e2f34be7da54c8b63f6fd4b88fd1e593c4) Thanks [@geekact](https://github.com/geekact)! - chore(web): upgrade qs from 6.11.0 to 6.11.1
- [`6154ee5`](https://github.com/aomex/aomex/commit/6154ee5ed500984f969d4c335ac3ad800c739937) Thanks [@geekact](https://github.com/geekact)! - refactor(web): replace lru-cache to memory-cache
- [`a0fd49e`](https://github.com/aomex/aomex/commit/a0fd49ef276c05f312257521c75887458857bbb7) Thanks [@geekact](https://github.com/geekact)! - refactor(web): rename request.path to request.pathname
- Updated dependencies [[`92273f9`](https://github.com/aomex/aomex/commit/92273f913e38543f34f41ec5941ff43b6e1caaa9)]:
- @aomex/core@0.0.11
## 0.0.11
### Patch Changes
- [`d9dc050`](https://github.com/aomex/aomex/commit/d9dc050897367353588c4bb778cbafb7607406ab) Thanks [@geekact](https://github.com/geekact)! - fix(web): don't override content-length in some case
- [`41ae605`](https://github.com/aomex/aomex/commit/41ae6054b2e87c4120f3fcee12302bb3d96f1df3) Thanks [@geekact](https://github.com/geekact)! - feat(web): auto bind onError
- Updated dependencies []:
- @aomex/core@0.0.10
## 0.0.10
### Patch Changes
- [`2439286`](https://github.com/aomex/aomex/commit/2439286e69dcc7211ac280b91dbca5de95cc488b) Thanks [@geekact](https://github.com/geekact)! - refactor: rename web-router to router
- Updated dependencies [[`fbb7ab2`](https://github.com/aomex/aomex/commit/fbb7ab2e6ec2a18e7ad8f018788523952049b6fd)]:
- @aomex/utility@0.0.5
- @aomex/core@0.0.9
## 0.0.9
### Patch Changes
- [`dcf2f4b`](https://github.com/aomex/aomex/commit/dcf2f4b6a13228d4731e4969e6abff9bef8ef0e2) Thanks [@geekact](https://github.com/geekact)! - fix(web): hasHeader and removeHeader cannot tip keyword Set-Cookie
- [`d788ce7`](https://github.com/aomex/aomex/commit/d788ce731af885eae3819683813b2a9502742cea) Thanks [@geekact](https://github.com/geekact)! - refactor(web): rename option queryParser to query
- [`c6fe6cb`](https://github.com/aomex/aomex/commit/c6fe6cb2f21acf74bc06db1509deff4aa35c48b3) Thanks [@geekact](https://github.com/geekact)! - feat(web): export response middleware
- [`a2727fb`](https://github.com/aomex/aomex/commit/a2727fb7619341dc3b23736e5dc11cee7d65e0bc) Thanks [@geekact](https://github.com/geekact)! - feat(web): add cookie support
- [`4253004`](https://github.com/aomex/aomex/commit/42530043854956a42d16be090b89fbac70e2fa17) Thanks [@geekact](https://github.com/geekact)! - fix(web): response returning invalid content-type for openapi
- [`fc7008e`](https://github.com/aomex/aomex/commit/fc7008e889a55e6a0a268bb77cab5be0f0bd9d30) Thanks [@geekact](https://github.com/geekact)! - refactor(web,router): move method enum from router to web
- [`d80df1a`](https://github.com/aomex/aomex/commit/d80df1a07eb92214a9c3c7fa15c629ea1ee88c43) Thanks [@geekact](https://github.com/geekact)! - feat(web): request add protocol and secure getter
- Updated dependencies []:
- @aomex/core@0.0.8
## 0.0.7
### Patch Changes
- [`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f) Thanks [@geekact](https://github.com/geekact)! - refactor: rename package helper to utility
- [`ceb2d82`](https://github.com/aomex/aomex/commit/ceb2d8269755dca3f79b755224259b8a99bc65d0) Thanks [@geekact](https://github.com/geekact)! - chore(cache,web): upgrade lru-cache from 7.14.1 to 7.17.0
- Updated dependencies [[`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f)]:
- @aomex/utility@0.0.4
- @aomex/core@0.0.6
- [`fb6c72d`](https://github.com/aomex/aomex/commit/fb6c72dbb266be4db92a542afe93dfa5d8c7cd41) Thanks [@geekact](https://github.com/geekact)! - chore(web): 升级依赖 formidable 3.4.0 -> 3.5.0
chore(web): 升级依赖 qs 6.11.1 -> 6.11.2
- Updated dependencies [[`6f7d706`](https://github.com/aomex/aomex/commit/6f7d7066c23711abdd149eb1c9a293ab8c4284a4), [`e7bf93c`](https://github.com/aomex/aomex/commit/e7bf93cee6896c61d0bf3eb0921151dc6c1bc107), [`818e840`](https://github.com/aomex/aomex/commit/818e840d36c7456a863fc071968b246c123c17f5)]:
- @aomex/core@0.0.22

69

dist/index.d.ts

@@ -1,3 +0,2 @@

import { Chain, PureChain, PureMiddlewareToken, Next, Middleware, OpenAPI, Validator, TransformedValidator, magistrate } from '@aomex/core';
import { NonReadonly } from '@aomex/utility';
import { Chain, PureChain, PureMiddlewareToken, NonReadonly, Next, Middleware, OpenAPI, Validator, TransformedValidator, magistrate } from '@aomex/core';
import { Server, RequestListener, ServerResponse, IncomingMessage } from 'node:http';

@@ -30,15 +29,18 @@ import EventEmitter from 'node:events';

interface WebAppOption {
/**
* 静默模式。默认值:`false`
*/
silent?: boolean;
/**
* 调试模式。默认值:`process.env.NODE_ENV !== 'production'`
*/
debug?: boolean;
/**
* Set default options for `qs` when parsing querystring from request
* 查询字符串的解析配置。使用依赖库`qs`作为解析器
* @see WebRequest.query
*/
query?: IParseOptions;
/**
* Set default/common options for cookie
*/
cookie?: {
/**
* Default option for request.cookie
* `ctx.request.cookie`的配置
* @see WebRequest.cookie

@@ -48,3 +50,3 @@ */

/**
* Default option for response.cookie
* `ctx.response.cookie`的配置
* @see WebResponse.cookie

@@ -54,2 +56,7 @@ */

};
/**
* 是否验证响应数据。如果不设置,则在debug开启的情况下进行验证操作
* @see response()
*/
validateResponse?: boolean;
}

@@ -182,4 +189,3 @@ declare class WebApp extends EventEmitter {

/**
* Get the search string. Same as the query string
* except it includes the leading `?`
* 搜索字符串,比查询字符串多了一个开头问号(?)
*/

@@ -195,3 +201,3 @@ get search(): string;

/**
* Get full request URL, include protocol, host and url
* 包括了协议,域名,端口和路径的完整链接
*/

@@ -205,3 +211,3 @@ get href(): string;

/**
* A short hand for request header `Cookie`
* 把请求头部的`Cookie`字段解析成对象格式
*/

@@ -229,3 +235,3 @@ get cookie(): {

/**
* Throw a http error
* 抛出Http请求异常
*

@@ -257,6 +263,6 @@ * ```typescript

/**
* Skip specific middleware or chain
* - by condition: options=`object|function`
* - never skip : options=`false`
* - always skip : options=`true`
* 跳过中间件或者链条
* - 通过条件判断 - options=`object|function`
* - 不跳过 - options=`false`
* - 总是跳过 - options=`true`
*/

@@ -304,3 +310,3 @@ declare function skip<Props extends object, T extends WebMiddlewareSkipOptions | NonNullable<WebMiddlewareSkipOptions['custom']> | boolean>(token: WebMiddlewareToken<Props>, options: T): WebMiddleware<T extends false ? Props : T extends true ? object : Partial<Props>>;

/**
* Examples:
* 可选格式:
* - 1024

@@ -337,3 +343,3 @@ * - 2048

/**
* Validate web request body
* 验证请求实体
*

@@ -369,3 +375,3 @@ * ```typescript

/**
* Validate web request querystring
* 验证请求查询字符串
*

@@ -400,3 +406,3 @@ * ```typescript

/**
* Validate web request path params
* 验证请求路径参数
*

@@ -420,3 +426,3 @@ * ```typescript

/**
* Examples:
* 可选格式:
* - 200

@@ -426,2 +432,4 @@ * - 201

* - 3xx
* - 20x
* - 40x
* - default (handle unknown response)

@@ -441,3 +449,3 @@ */

/**
* Final data schema
* 最终的响应格式
*/

@@ -451,5 +459,17 @@ schema?: Validator | {

description?: string;
/**
* 验证响应数据。
*
* 如果未设置,则查看`app.options.validateResponse`。仍未设置,则查看`app.options.debug`
*
* ```typescript
* const app = new WebApp({
* validateResponse: false
* })
* ```
*/
validate?: boolean;
}
/**
* web响应中间件,帮助openapi生成最合适的文档
* 为openapi生成响应数据文档,并提供运行时验证(严格模式)
*/

@@ -460,2 +480,3 @@ declare const response: (options: WebResponseOptions) => WebResponseMiddleware;

constructor(options: WebResponseOptions);
matchStatusCode(expected: number | string, statusCode: number): boolean;
toDocument({ methodItem }: WebMiddlewareToDocument): void;

@@ -462,0 +483,0 @@ protected fixContentType(contentType: string): string;

@@ -6,4 +6,3 @@ // src/override/middleware.ts

import { extname } from "node:path";
import { compose, Middleware, middleware } from "@aomex/core";
import { toArray } from "@aomex/utility";
import { compose, Middleware, middleware, toArray } from "@aomex/core";
function skip(token, options) {

@@ -72,8 +71,8 @@ if (options === true) {

magistrate,
Rule
Rule,
bytes
} from "@aomex/core";
import { bytes } from "@aomex/utility";
var FileValidator = class extends Validator {
/**
* Examples:
* 可选格式:
* - 1024

@@ -160,4 +159,3 @@ * - 2048

import { EOL } from "node:os";
import { Chain as Chain2, compose as compose2 } from "@aomex/core";
import { chalk } from "@aomex/utility";
import { Chain as Chain2, chalk, compose as compose2 } from "@aomex/core";

@@ -219,4 +217,3 @@ // src/util/get-content-type.ts

/**
* Get the search string. Same as the query string
* except it includes the leading `?`
* 搜索字符串,比查询字符串多了一个开头问号(?)
*/

@@ -242,11 +239,10 @@ get search() {

});
return this._body = new Promise((resolve, reject) => {
form.parse(this, (err, fields, files) => {
if (err)
return reject(err);
resolve({
...fields,
...files
});
});
return this._body = form.parse(this).then(([fields, files]) => {
const fixedFields = Object.fromEntries(
Object.entries(fields).map(([key, values]) => [
key,
values.length > 1 ? values : values[0]
])
);
return this._body = { ...fixedFields, ...files };
});

@@ -256,2 +252,4 @@ }

returnRawBody: false
}).then((fields) => {
return this._body = fields;
});

@@ -277,3 +275,3 @@ }

/**
* Get full request URL, include protocol, host and url
* 包括了协议,域名,端口和路径的完整链接
*/

@@ -317,3 +315,3 @@ get href() {

/**
* A short hand for request header `Cookie`
* 把请求头部的`Cookie`字段解析成对象格式
*/

@@ -352,3 +350,3 @@ get cookie() {

get debug() {
return this.options.debug || false;
return this.options.debug ?? process.env["NODE_ENV"] !== "production";
}

@@ -760,9 +758,46 @@ listen = (...args) => {

// src/middleware/response.ts
import { rule as rule2, Validator as Validator5 } from "@aomex/core";
import { forceValidator, validate as validate4, Validator as Validator5 } from "@aomex/core";
import { Stream as Stream2 } from "node:stream";
var num3length = /^\d{3}$/;
var num2length = /^\d{2}x$/i;
var num1length = /^\dxx$/i;
var response = (options) => new WebResponseMiddleware(options);
var WebResponseMiddleware = class extends WebMiddleware {
constructor(options) {
super((_, next) => next());
const schema = forceValidator(options.schema)?.strict();
const headerSchema = forceValidator(options.headers)?.strict();
super(async (ctx, next) => {
await next();
const { statusCode, body: body2 } = ctx.response;
const shouldValidate = options.validate ?? ctx.app.options.validateResponse ?? ctx.app.debug;
if (!shouldValidate)
return;
if (!this.matchStatusCode(options.statusCode, statusCode))
return;
try {
if (schema && !(body2 instanceof Stream2)) {
await validate4(body2, schema);
}
if (headerSchema) {
await validate4(ctx.response.getHeaders(), headerSchema);
}
} catch (e) {
ctx.throw(500, e);
}
});
this.options = options;
}
matchStatusCode(expected, statusCode) {
expected = expected.toString();
if (num3length.test(expected)) {
return statusCode === Number(expected);
}
if (num1length.test(expected)) {
return expected[0] === statusCode.toString()[0];
}
if (num2length.test(expected)) {
return expected.slice(0, 2) === statusCode.toString().slice(0, 2);
}
return false;
}
toDocument({ methodItem }) {

@@ -784,5 +819,3 @@ if (!methodItem)

[this.fixContentType(contentType3)]: {
schema: Validator5.toDocument(
schema instanceof Validator5 ? schema : rule2.object(schema)
).schema,
schema: Validator5.toDocument(forceValidator(schema)).schema,
example

@@ -789,0 +822,0 @@ }

{
"name": "@aomex/web",
"version": "0.0.22",
"version": "0.0.23",
"description": "",

@@ -29,10 +29,9 @@ "type": "module",

"peerDependencies": {
"@aomex/core": "^0.0.21"
"@aomex/core": "^0.0.22"
},
"dependencies": {
"@aomex/utility": "^0.0.7",
"@types/accepts": "^1.3.5",
"@types/content-disposition": "^0.5.5",
"@types/cookie": "^0.5.1",
"@types/formidable": "^2.0.5",
"@types/formidable": "^3.4.0",
"@types/http-errors": "^2.0.1",

@@ -49,7 +48,7 @@ "@types/qs": "^6.9.7",

"escape-html": "^1.0.3",
"formidable": "^3.2.5",
"formidable": "^3.5.0",
"fresh": "^0.5.2",
"http-errors": "^2.0.0",
"mime-types": "^2.1.35",
"qs": "^6.11.1",
"qs": "^6.11.2",
"request-ip": "^3.3.0",

@@ -61,3 +60,3 @@ "statuses": "^2.0.1",

"devDependencies": {
"@aomex/core": "^0.0.21",
"@aomex/core": "^0.0.22",
"@types/co-body": "^6.1.0",

@@ -70,3 +69,3 @@ "@types/content-type": "^1.1.5",

"@types/mime-types": "^2.1.1",
"@types/request-ip": "^0.0.37",
"@types/request-ip": "^0.0.38",
"@types/type-is": "^1.6.3",

@@ -73,0 +72,0 @@ "@types/vary": "^1.1.0"

Sorry, the diff of this file is not supported yet

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