@buka/nestjs-kit 4.4.3 → 4.4.4
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 +9 -0
- package/dist/index.d.mts +8 -4
- package/dist/index.d.ts +7 -3
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import * as fs from "node:fs";
|
|
|
17
17
|
import { KeqRequest, RequestException } from "keq";
|
|
18
18
|
import { setBaseUrl } from "@keq-request/url";
|
|
19
19
|
import { createExceptionByStatusCode, validateStatusCode } from "@keq-request/exception";
|
|
20
|
+
import { KeqModule } from "@keq-request/nestjs";
|
|
20
21
|
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "crypto";
|
|
21
22
|
import bcrypt from "bcryptjs";
|
|
22
23
|
import { Base32, Base32 as Base32$1, ErrorCategory, ErrorCategory as ErrorCategory$1, ErrorCode, ErrorCode as ErrorCode$1 } from "@buka/error-codes";
|
|
@@ -728,12 +729,16 @@ function ValidateNestedDictionary(typeFunc, validationOptions) {
|
|
|
728
729
|
//#endregion
|
|
729
730
|
//#region src/modules/core/decorators/is-browser-request.ts
|
|
730
731
|
/**
|
|
731
|
-
* 参数装饰器,通过检测请求头中是否存在 `Sec-Fetch
|
|
732
|
+
* 参数装饰器,通过检测请求头中是否存在 `Sec-Fetch-Site` 头,
|
|
732
733
|
* 判断请求是否来自浏览器。
|
|
733
734
|
*
|
|
734
735
|
* 浏览器在发起请求时会自动附加 `Sec-Fetch-Site`、`Sec-Fetch-Mode`、
|
|
735
|
-
* `Sec-Fetch-Dest` 等头([Fetch Metadata Request Headers](https://www.w3.org/TR/fetch-metadata/)
|
|
736
|
-
* 非浏览器客户端(如 curl、Postman
|
|
736
|
+
* `Sec-Fetch-Dest` 等头([Fetch Metadata Request Headers](https://www.w3.org/TR/fetch-metadata/))。
|
|
737
|
+
* 非浏览器客户端(如 curl、Postman)通常不会携带这些头。
|
|
738
|
+
*
|
|
739
|
+
* **注意:** Node.js 的 undici(globalThis.fetch)会自动添加 `Sec-Fetch-Mode: cors`,
|
|
740
|
+
* 但不会添加 `Sec-Fetch-Site`。因此使用 `Sec-Fetch-Site` 而非任意 `Sec-Fetch-*`
|
|
741
|
+
* 头来区分真正的浏览器请求和服务端 fetch 调用。
|
|
737
742
|
*
|
|
738
743
|
* 装饰的参数类型应为 `boolean`。
|
|
739
744
|
*
|
|
@@ -752,7 +757,7 @@ function ValidateNestedDictionary(typeFunc, validationOptions) {
|
|
|
752
757
|
*/
|
|
753
758
|
const IsBrowserRequest = createParamDecorator((_data, ctx) => {
|
|
754
759
|
const request = ctx.switchToHttp().getRequest();
|
|
755
|
-
return Object.keys(request.headers).some((key) => key.toLowerCase()
|
|
760
|
+
return Object.keys(request.headers).some((key) => key.toLowerCase() === "sec-fetch-site");
|
|
756
761
|
});
|
|
757
762
|
//#endregion
|
|
758
763
|
//#region src/modules/core/decorators/model/model.register.ts
|
|
@@ -2835,6 +2840,7 @@ function PrimaryKeyType(classRef) {
|
|
|
2835
2840
|
const primaryProperties = getMetadata(classRef).filter((prop) => prop.primary).map((prop) => prop.name);
|
|
2836
2841
|
if (!primaryProperties.length) throw new Error(`Cannot create PrimaryKeyType for ${classRef.name} because it has no primary properties.`);
|
|
2837
2842
|
class PrimaryKeyTypeClass {}
|
|
2843
|
+
Object.defineProperty(PrimaryKeyTypeClass, "name", { value: `${classRef.name}PrimaryKeyType` });
|
|
2838
2844
|
PrimaryKeyTypeClass[PrimaryKeyTypeClassMetadataPropertyKey] = classRef;
|
|
2839
2845
|
cloneMetadata(PrimaryKeyTypeClass, classRef, primaryProperties);
|
|
2840
2846
|
inheritValidationMetadata(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
|
|
@@ -6597,7 +6603,7 @@ let OpenBaoModule = class OpenBaoModule extends ConfigurableModuleClass$4 {
|
|
|
6597
6603
|
OpenBaoModule = __decorate([
|
|
6598
6604
|
Global(),
|
|
6599
6605
|
Module({
|
|
6600
|
-
imports: [OpenBaoHttpModule.register({ isGlobal: true })],
|
|
6606
|
+
imports: [KeqModule, OpenBaoHttpModule.register({ isGlobal: true })],
|
|
6601
6607
|
providers: [OpenBaoTokenManager],
|
|
6602
6608
|
exports: [OpenBaoTokenManager, OpenBaoHttpModule]
|
|
6603
6609
|
}),
|