@buka/nestjs-kit 4.4.4 → 4.4.6

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/dist/index.mjs CHANGED
@@ -16,8 +16,8 @@ import { Migrator } from "@mikro-orm/migrations";
16
16
  import * as fs from "node:fs";
17
17
  import { KeqRequest, RequestException } from "keq";
18
18
  import { setBaseUrl } from "@keq-request/url";
19
- import { createExceptionByStatusCode, validateStatusCode } from "@keq-request/exception";
20
- import { KeqModule } from "@keq-request/nestjs";
19
+ import { clarifyFetchFailed, createExceptionByStatusCode, validateStatusCode } from "@keq-request/exception";
20
+ import { InjectKeqConsumer, KEQ_ROUTES, KeqConsumer, KeqModule } from "@keq-request/nestjs";
21
21
  import { createCipheriv, createDecipheriv, createHash, randomBytes } from "crypto";
22
22
  import bcrypt from "bcryptjs";
23
23
  import { Base32, Base32 as Base32$1, ErrorCategory, ErrorCategory as ErrorCategory$1, ErrorCode, ErrorCode as ErrorCode$1 } from "@buka/error-codes";
@@ -2694,7 +2694,7 @@ const Column = {
2694
2694
  };
2695
2695
  //#endregion
2696
2696
  //#region src/modules/mikro-orm/models/timestamped-entity.ts
2697
- var _ref$14, _ref2$3;
2697
+ var _ref$14, _ref2$4;
2698
2698
  var TimestampedEntity = class {
2699
2699
  [OptionalProps];
2700
2700
  createdAt = /* @__PURE__ */ new Date();
@@ -2709,7 +2709,7 @@ __decorate([Column.Timestamptz({
2709
2709
  onUpdate: () => /* @__PURE__ */ new Date(),
2710
2710
  defaultRaw: "CURRENT_TIMESTAMP",
2711
2711
  comment: "更新时间"
2712
- }), __decorateMetadata("design:type", typeof (_ref2$3 = typeof Date !== "undefined" && Date) === "function" ? _ref2$3 : Object)], TimestampedEntity.prototype, "updatedAt", void 0);
2712
+ }), __decorateMetadata("design:type", typeof (_ref2$4 = typeof Date !== "undefined" && Date) === "function" ? _ref2$4 : Object)], TimestampedEntity.prototype, "updatedAt", void 0);
2713
2713
  //#endregion
2714
2714
  //#region src/modules/mikro-orm/models/linear-entity.ts
2715
2715
  var LinearEntity = class extends TimestampedEntity {
@@ -3166,7 +3166,7 @@ __decorate([
3166
3166
  ], DatabaseConfig.prototype, "poolIdleTimeoutMillis", void 0);
3167
3167
  //#endregion
3168
3168
  //#region src/modules/core/pipes/validation.pipe.ts
3169
- var _ref$13, _ref2$2, _ref3$1, _BukaValidationPipe;
3169
+ var _ref$13, _ref2$3, _ref3$1, _BukaValidationPipe;
3170
3170
  function deepMap(obj, fn) {
3171
3171
  if (Array.isArray(obj)) return obj.map((item) => deepMap(item, fn));
3172
3172
  else return fn(obj);
@@ -3227,7 +3227,7 @@ let BukaValidationPipe = _BukaValidationPipe = class BukaValidationPipe extends
3227
3227
  };
3228
3228
  BukaValidationPipe = _BukaValidationPipe = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [
3229
3229
  typeof (_ref$13 = typeof MikroORM !== "undefined" && MikroORM) === "function" ? _ref$13 : Object,
3230
- typeof (_ref2$2 = typeof EntityManager !== "undefined" && EntityManager) === "function" ? _ref2$2 : Object,
3230
+ typeof (_ref2$3 = typeof EntityManager !== "undefined" && EntityManager) === "function" ? _ref2$3 : Object,
3231
3231
  typeof (_ref3$1 = typeof ValidationPipeOptions !== "undefined" && ValidationPipeOptions) === "function" ? _ref3$1 : Object
3232
3232
  ])], BukaValidationPipe);
3233
3233
  //#endregion
@@ -6460,6 +6460,7 @@ OpenBaoHttpClient = _OpenBaoHttpClient = __decorate([Injectable(), __decorateMet
6460
6460
  //#endregion
6461
6461
  //#region src/apis/open-bao-http/open-bao-http.module.ts
6462
6462
  const KEQ_REQUEST_TOKEN = Symbol("OpenBaoHttpKeqRequest");
6463
+ const KEQ_CONSUMER_TOKEN = Symbol("OpenBaoHttpKeqConsumer");
6463
6464
  const { ConfigurableModuleClass: ConfigurableModuleClass$3, MODULE_OPTIONS_TOKEN: MODULE_OPTIONS_TOKEN$3 } = new ConfigurableModuleBuilder().setExtras({ isGlobal: false }, (definition, extras) => ({
6464
6465
  ...definition,
6465
6466
  global: extras.isGlobal
@@ -6482,12 +6483,23 @@ const CLIENT_PROVIDER = {
6482
6483
  useFactory: (request) => new OpenBaoHttpClient(request),
6483
6484
  inject: [KEQ_REQUEST_TOKEN]
6484
6485
  };
6486
+ const CONSUMER_PROVIDER = {
6487
+ provide: KEQ_CONSUMER_TOKEN,
6488
+ useFactory: (request) => new KeqConsumer(request),
6489
+ inject: [KEQ_REQUEST_TOKEN]
6490
+ };
6485
6491
  let OpenBaoHttpModule = class OpenBaoHttpModule extends ConfigurableModuleClass$3 {
6486
6492
  static KEQ_REQUEST = KEQ_REQUEST_TOKEN;
6493
+ static KEQ_CONSUMER = KEQ_CONSUMER_TOKEN;
6487
6494
  };
6488
6495
  OpenBaoHttpModule = __decorate([Module({
6489
- providers: [REQUEST_PROVIDER, CLIENT_PROVIDER],
6490
- exports: [OpenBaoHttpClient]
6496
+ imports: [KeqModule],
6497
+ providers: [
6498
+ REQUEST_PROVIDER,
6499
+ CONSUMER_PROVIDER,
6500
+ CLIENT_PROVIDER
6501
+ ],
6502
+ exports: [OpenBaoHttpClient, KEQ_CONSUMER_TOKEN]
6491
6503
  })], OpenBaoHttpModule);
6492
6504
  //#endregion
6493
6505
  //#region src/modules/open-bao/set-open-bao-token.middleware.ts
@@ -6544,6 +6556,7 @@ function setOpenBaoToken(getToken) {
6544
6556
  }
6545
6557
  //#endregion
6546
6558
  //#region src/modules/open-bao/request/format-error.ts
6559
+ const logger$1 = new Logger$1("ClarifyOpenbaoError");
6547
6560
  /**
6548
6561
  * 根据 HTTP 状态码生成中文操作建议
6549
6562
  */
@@ -6560,14 +6573,19 @@ function getStatusCodeGuidance(statusCode) {
6560
6573
  * 必须注册在 `validateStatusCode` 之后,作为中间件链的最外层,
6561
6574
  * 捕获 `RequestException` 并重写其错误消息,补充请求上下文和操作建议。
6562
6575
  *
6563
- * 非 RequestException 错误(网络故障、超时等)原样透传。
6576
+ * 非 RequestException 错误(网络故障、超时等)记录日志后原样透传。
6564
6577
  */
6565
- function formatError() {
6578
+ function clarifyOpenbaoError() {
6566
6579
  const middleware = async (ctx, next) => {
6567
6580
  try {
6568
6581
  await next();
6569
6582
  } catch (err) {
6570
- if (!(err instanceof RequestException)) throw err;
6583
+ if (!(err instanceof RequestException)) {
6584
+ const method = ctx.request.method.toUpperCase();
6585
+ const url = ctx.request.url.toString();
6586
+ logger$1.error(`OpenBaoModule API 请求异常: ${method} ${url}`, err instanceof Error ? err.stack : void 0);
6587
+ throw err;
6588
+ }
6571
6589
  const method = ctx.request.method.toUpperCase();
6572
6590
  const url = ctx.request.url.toString();
6573
6591
  const statusCode = err.statusCode;
@@ -6584,20 +6602,18 @@ function formatError() {
6584
6602
  throw err;
6585
6603
  }
6586
6604
  };
6587
- middleware.__keqMiddlewareName__ = "formatError";
6605
+ middleware.__keqMiddlewareName__ = "clarifyOpenbaoError";
6588
6606
  return middleware;
6589
6607
  }
6590
6608
  //#endregion
6591
6609
  //#region src/modules/open-bao/open-bao.module.ts
6592
- var _ref$10;
6610
+ var _ref$10, _ref2$2;
6593
6611
  let OpenBaoModule = class OpenBaoModule extends ConfigurableModuleClass$4 {
6594
- constructor(options, tokenManager) {
6612
+ constructor(options, tokenManager, consumer) {
6595
6613
  super();
6596
6614
  this.options = options;
6597
6615
  this.tokenManager = tokenManager;
6598
- }
6599
- configureKeqMiddleware(consumer) {
6600
- consumer.apply(formatError(), setBaseUrl(this.options.address + "/v1/"), setOpenBaoToken(() => this.tokenManager.getToken()), validateStatusCode()).forRoutes(OpenBaoHttpModule);
6616
+ consumer.apply(clarifyOpenbaoError(), setBaseUrl(this.options.address + "/v1/"), setOpenBaoToken(() => this.tokenManager.getToken()), validateStatusCode(), clarifyFetchFailed()).forRoutes(KEQ_ROUTES.ALL);
6601
6617
  }
6602
6618
  };
6603
6619
  OpenBaoModule = __decorate([
@@ -6608,7 +6624,12 @@ OpenBaoModule = __decorate([
6608
6624
  exports: [OpenBaoTokenManager, OpenBaoHttpModule]
6609
6625
  }),
6610
6626
  __decorateParam(0, Inject(MODULE_OPTIONS_TOKEN$4)),
6611
- __decorateMetadata("design:paramtypes", [Object, typeof (_ref$10 = typeof OpenBaoTokenManager !== "undefined" && OpenBaoTokenManager) === "function" ? _ref$10 : Object])
6627
+ __decorateParam(2, InjectKeqConsumer(OpenBaoHttpModule)),
6628
+ __decorateMetadata("design:paramtypes", [
6629
+ Object,
6630
+ typeof (_ref$10 = typeof OpenBaoTokenManager !== "undefined" && OpenBaoTokenManager) === "function" ? _ref$10 : Object,
6631
+ typeof (_ref2$2 = typeof KeqConsumer !== "undefined" && KeqConsumer) === "function" ? _ref2$2 : Object
6632
+ ])
6612
6633
  ], OpenBaoModule);
6613
6634
  //#endregion
6614
6635
  //#region src/modules/open-bao/open-bao.config.ts