@buka/nestjs-kit 4.3.1 → 4.3.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.3.2](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.3.1...v4.3.2) (2026-05-26)
4
+
5
+
6
+ ### Performance Improvements
7
+
8
+ * 对象存储模块添加错误日志 ([968aaab](https://github.com/buka-ltd/npm.nestjs-kit/commit/968aaab5542e3a1f952027f61ad17cafca8fd4ba))
9
+
3
10
  ## [4.3.1](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.3.0...v4.3.1) (2026-05-25)
4
11
 
5
12
 
package/dist/index.js CHANGED
@@ -3737,12 +3737,12 @@ let OpenBaoTokenManager = _OpenBaoTokenManager = class OpenBaoTokenManager {
3737
3737
  this.logger.log("Token renewed successfully");
3738
3738
  this.scheduleRenewal();
3739
3739
  } catch (renewError) {
3740
- this.logger.error("Failed to renew token, attempting re-authentication", renewError);
3740
+ this.logger.error("Failed to renew token, attempting re-authentication", renewError instanceof Error ? renewError.stack : void 0);
3741
3741
  try {
3742
3742
  await this.authenticate();
3743
3743
  this.scheduleRenewal();
3744
3744
  } catch (authError) {
3745
- this.logger.error("Re-authentication also failed, will retry in 5s", authError);
3745
+ this.logger.error("Re-authentication also failed, will retry in 5s", authError instanceof Error ? authError.stack : void 0);
3746
3746
  this.renewalTimer = setTimeout(() => {
3747
3747
  this.renewToken();
3748
3748
  }, 5e3);
@@ -9956,13 +9956,19 @@ let ObjectStorageService = _ObjectStorageService = class ObjectStorageService {
9956
9956
  * @param options - 可选配置,如是否自动添加前缀
9957
9957
  */
9958
9958
  async get(path, options) {
9959
+ const key = this.buildPath(path, options);
9959
9960
  const command = new _aws_sdk_client_s3.GetObjectCommand({
9960
9961
  Bucket: this.config.bucket,
9961
- Key: this.buildPath(path, options)
9962
+ Key: key
9962
9963
  });
9963
- const res = await this.client.send(command);
9964
- if (!res.Body) throw new Error("No body");
9965
- return node_stream.Readable.fromWeb(res.Body.transformToWebStream());
9964
+ try {
9965
+ const res = await this.client.send(command);
9966
+ if (!res.Body) throw new Error("No body");
9967
+ return node_stream.Readable.fromWeb(res.Body.transformToWebStream());
9968
+ } catch (err) {
9969
+ this.logger.error(`对象存储下载失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
9970
+ throw err;
9971
+ }
9966
9972
  }
9967
9973
  /**
9968
9974
  * 上传文件内容到指定路径。
@@ -9974,41 +9980,55 @@ let ObjectStorageService = _ObjectStorageService = class ObjectStorageService {
9974
9980
  */
9975
9981
  async upload(path, contents, options) {
9976
9982
  const key = this.buildPath(path, options);
9977
- await new _aws_sdk_lib_storage.Upload({
9983
+ const upload = new _aws_sdk_lib_storage.Upload({
9978
9984
  client: this.client,
9979
9985
  params: {
9980
9986
  Bucket: this.config.bucket,
9981
9987
  Key: key,
9982
9988
  Body: contents
9983
9989
  }
9984
- }).done();
9985
- return key;
9990
+ });
9991
+ try {
9992
+ await upload.done();
9993
+ return key;
9994
+ } catch (err) {
9995
+ this.logger.error(`对象存储上传失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
9996
+ throw err;
9997
+ }
9986
9998
  }
9987
9999
  /**
9988
10000
  * 获取文件的元数据(metadata)。
9989
10001
  */
9990
10002
  async getMetadata(path, options) {
10003
+ const key = this.buildPath(path, options);
9991
10004
  const command = new _aws_sdk_client_s3.HeadObjectCommand({
9992
10005
  Bucket: this.config.bucket,
9993
- Key: this.buildPath(path, options)
10006
+ Key: key
9994
10007
  });
9995
- const res = await this.client.send(command);
9996
- if (!res.Metadata) throw new Error("No metadata");
9997
- return res.Metadata;
10008
+ try {
10009
+ const res = await this.client.send(command);
10010
+ if (!res.Metadata) throw new Error("No metadata");
10011
+ return res.Metadata;
10012
+ } catch (err) {
10013
+ this.logger.error(`对象存储获取元数据失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
10014
+ throw err;
10015
+ }
9998
10016
  }
9999
10017
  /**
10000
10018
  * 检查文件是否存在。
10001
10019
  */
10002
10020
  async exists(path, options) {
10021
+ const key = this.buildPath(path, options);
10003
10022
  const command = new _aws_sdk_client_s3.HeadObjectCommand({
10004
10023
  Bucket: this.config.bucket,
10005
- Key: this.buildPath(path, options)
10024
+ Key: key
10006
10025
  });
10007
10026
  try {
10008
10027
  await this.client.send(command);
10009
10028
  return true;
10010
10029
  } catch (err) {
10011
10030
  if (err instanceof Error && err.name === "NotFound") return false;
10031
+ this.logger.error(`对象存储检查文件存在性失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
10012
10032
  throw err;
10013
10033
  }
10014
10034
  }
@@ -10016,11 +10036,17 @@ let ObjectStorageService = _ObjectStorageService = class ObjectStorageService {
10016
10036
  * 删除指定路径的文件。
10017
10037
  */
10018
10038
  async remove(path, options) {
10039
+ const key = this.buildPath(path, options);
10019
10040
  const command = new _aws_sdk_client_s3.DeleteObjectCommand({
10020
10041
  Bucket: this.config.bucket,
10021
- Key: this.buildPath(path, options)
10042
+ Key: key
10022
10043
  });
10023
- await this.client.send(command);
10044
+ try {
10045
+ await this.client.send(command);
10046
+ } catch (err) {
10047
+ this.logger.error(`对象存储删除文件失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
10048
+ throw err;
10049
+ }
10024
10050
  }
10025
10051
  /**
10026
10052
  * 获取文件的预签名 URL,用于临时授权访问。
@@ -10030,11 +10056,17 @@ let ObjectStorageService = _ObjectStorageService = class ObjectStorageService {
10030
10056
  * @param options - 可选配置
10031
10057
  */
10032
10058
  async getSignedUrl(path, expiresInSecond, options) {
10059
+ const key = this.buildPath(path, options);
10033
10060
  const command = new _aws_sdk_client_s3.GetObjectCommand({
10034
10061
  Bucket: this.config.bucket,
10035
- Key: this.buildPath(path, options)
10062
+ Key: key
10036
10063
  });
10037
- return await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn: expiresInSecond });
10064
+ try {
10065
+ return await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn: expiresInSecond });
10066
+ } catch (err) {
10067
+ this.logger.error(`对象存储获取签名URL失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
10068
+ throw err;
10069
+ }
10038
10070
  }
10039
10071
  };
10040
10072
  ObjectStorageService = _ObjectStorageService = __decorate([