@buka/nestjs-kit 4.1.1 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/index.js +53 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.1.2](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.1.1...v4.1.2) (2026-05-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Performance Improvements
|
|
7
|
+
|
|
8
|
+
* 优化 openbao module 报错信息提示准确性 ([2245b17](https://github.com/buka-ltd/npm.nestjs-kit/commit/2245b1765b7d65ee4827727eb2f5fddb67b523a2))
|
|
9
|
+
|
|
3
10
|
## [4.1.1](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.1.0...v4.1.1) (2026-05-10)
|
|
4
11
|
|
|
5
12
|
|
package/dist/index.js
CHANGED
|
@@ -33,9 +33,9 @@ let ramda = require("ramda");
|
|
|
33
33
|
ramda = __toESM(ramda);
|
|
34
34
|
let class_transformer_cjs_storage_js = require("class-transformer/cjs/storage.js");
|
|
35
35
|
class_transformer_cjs_storage_js = __toESM(class_transformer_cjs_storage_js);
|
|
36
|
-
let
|
|
37
|
-
let
|
|
38
|
-
let
|
|
36
|
+
let _nestjs_swagger_dist_services_model_properties_accessor = require("@nestjs/swagger/dist/services/model-properties-accessor");
|
|
37
|
+
let _nestjs_swagger_dist_constants = require("@nestjs/swagger/dist/constants");
|
|
38
|
+
let _nestjs_swagger_dist_plugin_plugin_constants = require("@nestjs/swagger/dist/plugin/plugin-constants");
|
|
39
39
|
let _nestjs_swagger_dist_type_helpers_mapped_types_utils = require("@nestjs/swagger/dist/type-helpers/mapped-types.utils");
|
|
40
40
|
let _nestjs_common_utils_shared_utils = require("@nestjs/common/utils/shared.utils");
|
|
41
41
|
require("@nestjs/swagger/dist/utils/is-built-in-type.util");
|
|
@@ -1435,7 +1435,7 @@ function getPropertyOperators(target, propertyKey) {
|
|
|
1435
1435
|
}
|
|
1436
1436
|
//#endregion
|
|
1437
1437
|
//#region src/utils/nestjs-swagger-utils.ts
|
|
1438
|
-
const modelPropertiesAccessor = new
|
|
1438
|
+
const modelPropertiesAccessor = new _nestjs_swagger_dist_services_model_properties_accessor.ModelPropertiesAccessor();
|
|
1439
1439
|
/**
|
|
1440
1440
|
* 克隆 @nestjs/swagger Plugin 添加的元数据
|
|
1441
1441
|
*/
|
|
@@ -1447,12 +1447,12 @@ function cloneMetadata(target, source, keys) {
|
|
|
1447
1447
|
}
|
|
1448
1448
|
}
|
|
1449
1449
|
function getMetadataOfDecorator(classRef, propertyKey) {
|
|
1450
|
-
if (propertyKey) return Reflect.getMetadata(
|
|
1450
|
+
if (propertyKey) return Reflect.getMetadata(_nestjs_swagger_dist_constants.DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, propertyKey);
|
|
1451
1451
|
const props = modelPropertiesAccessor.getModelProperties(classRef.prototype);
|
|
1452
|
-
return ramda.fromPairs(props.map((prop) => [prop, Reflect.getMetadata(
|
|
1452
|
+
return ramda.fromPairs(props.map((prop) => [prop, Reflect.getMetadata(_nestjs_swagger_dist_constants.DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, prop)]));
|
|
1453
1453
|
}
|
|
1454
1454
|
function getMetadataOfPlugin(classRef, propertyKey) {
|
|
1455
|
-
const propsInPlugin = typeof classRef[
|
|
1455
|
+
const propsInPlugin = typeof classRef[_nestjs_swagger_dist_plugin_plugin_constants.METADATA_FACTORY_NAME] === "function" ? classRef[_nestjs_swagger_dist_plugin_plugin_constants.METADATA_FACTORY_NAME]() : {};
|
|
1456
1456
|
if (propertyKey) return propsInPlugin[propertyKey];
|
|
1457
1457
|
return propsInPlugin;
|
|
1458
1458
|
}
|
|
@@ -8091,6 +8091,51 @@ function setOpenBaoToken(getToken) {
|
|
|
8091
8091
|
return middleware;
|
|
8092
8092
|
}
|
|
8093
8093
|
//#endregion
|
|
8094
|
+
//#region src/modules/open-bao/request/format-error.ts
|
|
8095
|
+
/**
|
|
8096
|
+
* 根据 HTTP 状态码生成中文操作建议
|
|
8097
|
+
*/
|
|
8098
|
+
function getStatusCodeGuidance(statusCode) {
|
|
8099
|
+
if (statusCode === 400) return "请检查请求参数是否正确";
|
|
8100
|
+
if (statusCode === 403) return "请检查 OpenBao 策略(Policy)是否为该 Token 授予了足够的权限";
|
|
8101
|
+
if (statusCode === 404) return "请检查请求的路径或密钥是否存在";
|
|
8102
|
+
if (statusCode >= 500) return "请检查 OpenBao 服务器日志以获取更多信息";
|
|
8103
|
+
return "";
|
|
8104
|
+
}
|
|
8105
|
+
/**
|
|
8106
|
+
* OpenBao 请求错误格式化中间件
|
|
8107
|
+
*
|
|
8108
|
+
* 必须注册在 `validateStatusCode` 之后,作为中间件链的最外层,
|
|
8109
|
+
* 捕获 `RequestException` 并重写其错误消息,补充请求上下文和操作建议。
|
|
8110
|
+
*
|
|
8111
|
+
* 非 RequestException 错误(网络故障、超时等)原样透传。
|
|
8112
|
+
*/
|
|
8113
|
+
function formatError() {
|
|
8114
|
+
const middleware = async (ctx, next) => {
|
|
8115
|
+
try {
|
|
8116
|
+
await next();
|
|
8117
|
+
} catch (err) {
|
|
8118
|
+
if (!(err instanceof keq.RequestException)) throw err;
|
|
8119
|
+
const method = ctx.request.method.toUpperCase();
|
|
8120
|
+
const url = ctx.request.url.toString();
|
|
8121
|
+
const statusCode = err.statusCode;
|
|
8122
|
+
const statusText = err.response?.statusText ?? "";
|
|
8123
|
+
let message = `OpenBaoModule API 请求失败: ${method} ${url}`;
|
|
8124
|
+
message += `\n响应状态: ${String(statusCode)} ${statusText}`;
|
|
8125
|
+
if (err.response) try {
|
|
8126
|
+
const bodyText = await err.response.clone().text();
|
|
8127
|
+
if (bodyText) message += `\n响应体: ${bodyText}`;
|
|
8128
|
+
} catch {}
|
|
8129
|
+
const guidance = getStatusCodeGuidance(typeof statusCode === "number" ? statusCode : parseInt(String(statusCode), 10));
|
|
8130
|
+
if (guidance) message += `\n建议: ${guidance}`;
|
|
8131
|
+
err.message = message;
|
|
8132
|
+
throw err;
|
|
8133
|
+
}
|
|
8134
|
+
};
|
|
8135
|
+
middleware.__keqMiddlewareName__ = "formatError";
|
|
8136
|
+
return middleware;
|
|
8137
|
+
}
|
|
8138
|
+
//#endregion
|
|
8094
8139
|
//#region src/modules/open-bao/open-bao.module.ts
|
|
8095
8140
|
/**
|
|
8096
8141
|
* 内部 KeqRequest 注入 Token
|
|
@@ -8106,6 +8151,7 @@ const KEQ_REQUEST_PROVIDER = {
|
|
|
8106
8151
|
request.use((0, _keq_request_url.setBaseUrl)(options.address + "/v1/"));
|
|
8107
8152
|
request.use(setOpenBaoToken(() => tokenManager.getToken()));
|
|
8108
8153
|
request.use((0, _keq_request_exception.validateStatusCode)());
|
|
8154
|
+
request.use(formatError());
|
|
8109
8155
|
return request;
|
|
8110
8156
|
},
|
|
8111
8157
|
inject: [MODULE_OPTIONS_TOKEN$3, OpenBaoTokenManager]
|