@bearei/nest 0.0.0-stage → 2.0.0-dev.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 +84 -0
- package/LICENSE +21 -0
- package/README.md +100 -2
- package/README.zh-CN.md +103 -0
- package/dist/action-log/action-log.interface.d.ts +12 -0
- package/dist/action-log/action-log.interface.js +2 -0
- package/dist/action-log/action-log.module.d.ts +2 -0
- package/dist/action-log/action-log.module.js +22 -0
- package/dist/action-log/action-log.service.d.ts +10 -0
- package/dist/action-log/action-log.service.js +42 -0
- package/dist/action-log/index.d.ts +3 -0
- package/dist/action-log/index.js +19 -0
- package/dist/authentication/authentication-context.interceptor.d.ts +7 -0
- package/dist/authentication/authentication-context.interceptor.js +70 -0
- package/dist/authentication/authentication.enum.d.ts +6 -0
- package/dist/authentication/authentication.enum.js +9 -0
- package/dist/authentication/authentication.guard.d.ts +13 -0
- package/dist/authentication/authentication.guard.js +92 -0
- package/dist/authentication/authentication.interface.d.ts +2 -0
- package/dist/authentication/authentication.interface.js +2 -0
- package/dist/authentication/index.d.ts +4 -0
- package/dist/authentication/index.js +20 -0
- package/dist/authorization/authorization.interface.d.ts +3 -0
- package/dist/authorization/authorization.interface.js +2 -0
- package/dist/authorization/authorization.module.d.ts +2 -0
- package/dist/authorization/authorization.module.js +22 -0
- package/dist/authorization/authorization.service.d.ts +10 -0
- package/dist/authorization/authorization.service.js +56 -0
- package/dist/authorization/index.d.ts +3 -0
- package/dist/authorization/index.js +19 -0
- package/dist/base-service/base-service.interface.d.ts +84 -0
- package/dist/base-service/base-service.interface.js +2 -0
- package/dist/base-service/base-service.module.d.ts +2 -0
- package/dist/base-service/base-service.module.js +22 -0
- package/dist/base-service/base-service.service.d.ts +27 -0
- package/dist/base-service/base-service.service.js +517 -0
- package/dist/base-service/index.d.ts +3 -0
- package/dist/base-service/index.js +19 -0
- package/dist/common.dto.d.ts +19 -0
- package/dist/common.dto.js +111 -0
- package/dist/common.entity.d.ts +11 -0
- package/dist/common.entity.js +76 -0
- package/dist/common.enum.d.ts +19 -0
- package/dist/common.enum.js +24 -0
- package/dist/common.interface.d.ts +19 -0
- package/dist/common.interface.js +2 -0
- package/dist/database/database.module.d.ts +5 -0
- package/dist/database/database.module.js +58 -0
- package/dist/database/index.d.ts +1 -0
- package/dist/database/index.js +17 -0
- package/dist/decorators/allow-access.decorator.d.ts +3 -0
- package/dist/decorators/allow-access.decorator.js +7 -0
- package/dist/decorators/index.d.ts +8 -0
- package/dist/decorators/index.js +24 -0
- package/dist/decorators/is-captcha.decorator.d.ts +2 -0
- package/dist/decorators/is-captcha.decorator.js +23 -0
- package/dist/decorators/is-nano-id.decorator.d.ts +2 -0
- package/dist/decorators/is-nano-id.decorator.js +22 -0
- package/dist/decorators/is-password.decorator.d.ts +2 -0
- package/dist/decorators/is-password.decorator.js +23 -0
- package/dist/decorators/is-version.decorator.d.ts +2 -0
- package/dist/decorators/is-version.decorator.js +22 -0
- package/dist/decorators/omit-entity-keys.decorator.d.ts +2 -0
- package/dist/decorators/omit-entity-keys.decorator.js +7 -0
- package/dist/decorators/require-permissions.decorator.d.ts +3 -0
- package/dist/decorators/require-permissions.decorator.js +7 -0
- package/dist/decorators/require-subscription-features.decorator.d.ts +3 -0
- package/dist/decorators/require-subscription-features.decorator.js +7 -0
- package/dist/exception/exception.enum.d.ts +12 -0
- package/dist/exception/exception.enum.js +16 -0
- package/dist/exception/exception.interface.d.ts +9 -0
- package/dist/exception/exception.interface.js +2 -0
- package/dist/exception/http.exception.d.ts +4 -0
- package/dist/exception/http.exception.js +47 -0
- package/dist/exception/index.d.ts +3 -0
- package/dist/exception/index.js +19 -0
- package/dist/external/external.interface.d.ts +58 -0
- package/dist/external/external.interface.js +2 -0
- package/dist/external/external.module.d.ts +2 -0
- package/dist/external/external.module.js +24 -0
- package/dist/external/external.service.d.ts +15 -0
- package/dist/external/external.service.js +160 -0
- package/dist/external/index.d.ts +3 -0
- package/dist/external/index.js +19 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +39 -0
- package/dist/jwt/index.d.ts +3 -0
- package/dist/jwt/index.js +19 -0
- package/dist/jwt/jwt.interface.d.ts +15 -0
- package/dist/jwt/jwt.interface.js +2 -0
- package/dist/jwt/jwt.module.d.ts +2 -0
- package/dist/jwt/jwt.module.js +43 -0
- package/dist/jwt/jwt.service.d.ts +10 -0
- package/dist/jwt/jwt.service.js +52 -0
- package/dist/permission/index.d.ts +3 -0
- package/dist/permission/index.js +19 -0
- package/dist/permission/permission.enum.d.ts +70 -0
- package/dist/permission/permission.enum.js +73 -0
- package/dist/permission/permission.guard.d.ts +9 -0
- package/dist/permission/permission.guard.js +55 -0
- package/dist/permission/permission.interface.d.ts +2 -0
- package/dist/permission/permission.interface.js +2 -0
- package/dist/redis/index.d.ts +3 -0
- package/dist/redis/index.js +19 -0
- package/dist/redis/redis.interface.d.ts +4 -0
- package/dist/redis/redis.interface.js +2 -0
- package/dist/redis/redis.module.d.ts +2 -0
- package/dist/redis/redis.module.js +22 -0
- package/dist/redis/redis.service.d.ts +14 -0
- package/dist/redis/redis.service.js +51 -0
- package/dist/subscription-feature/index.d.ts +3 -0
- package/dist/subscription-feature/index.js +19 -0
- package/dist/subscription-feature/subscription-feature.enum.d.ts +3 -0
- package/dist/subscription-feature/subscription-feature.enum.js +6 -0
- package/dist/subscription-feature/subscription-feature.interceptor.d.ts +9 -0
- package/dist/subscription-feature/subscription-feature.interceptor.js +68 -0
- package/dist/subscription-feature/subscription-feature.interface.d.ts +2 -0
- package/dist/subscription-feature/subscription-feature.interface.js +2 -0
- package/dist/utils/create-response-sanitizer/create-response-sanitizer.utils.d.ts +1 -0
- package/dist/utils/create-response-sanitizer/create-response-sanitizer.utils.js +23 -0
- package/dist/utils/create-response-sanitizer/index.d.ts +1 -0
- package/dist/utils/create-response-sanitizer/index.js +17 -0
- package/dist/utils/extract-bearer-token/extract-bearer-token.utils.d.ts +1 -0
- package/dist/utils/extract-bearer-token/extract-bearer-token.utils.js +13 -0
- package/dist/utils/extract-bearer-token/index.d.ts +1 -0
- package/dist/utils/extract-bearer-token/index.js +17 -0
- package/dist/utils/format-mobile-number/format-mobile-number.utils.d.ts +1 -0
- package/dist/utils/format-mobile-number/format-mobile-number.utils.js +5 -0
- package/dist/utils/format-mobile-number/index.d.ts +1 -0
- package/dist/utils/format-mobile-number/index.js +17 -0
- package/dist/utils/generate-random-number-string/generate-random-number-string.utils.d.ts +1 -0
- package/dist/utils/generate-random-number-string/generate-random-number-string.utils.js +6 -0
- package/dist/utils/generate-random-number-string/index.d.ts +1 -0
- package/dist/utils/generate-random-number-string/index.js +17 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/run-with-database-retry/index.d.ts +1 -0
- package/dist/utils/run-with-database-retry/index.js +17 -0
- package/dist/utils/run-with-database-retry/run-with-database-retry.utils.d.ts +1 -0
- package/dist/utils/run-with-database-retry/run-with-database-retry.utils.js +23 -0
- package/dist/utils/sign/index.d.ts +1 -0
- package/dist/utils/sign/index.js +17 -0
- package/dist/utils/sign/sign.utils.d.ts +5 -0
- package/dist/utils/sign/sign.utils.js +82 -0
- package/package.json +126 -3
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.verifyBcryptHash = exports.hashWithBcrypt = exports.verifyHmacSignature = exports.createHmacSignature = exports.buildCanonicalString = void 0;
|
|
37
|
+
const bcrypt = __importStar(require("bcrypt"));
|
|
38
|
+
const crypto = __importStar(require("crypto"));
|
|
39
|
+
const exception_1 = require("../../exception");
|
|
40
|
+
const HMAC_ALGORITHM = 'sha256';
|
|
41
|
+
const buildCanonicalString = (object) => {
|
|
42
|
+
const entries = Object.entries(object)
|
|
43
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
44
|
+
.sort(([leftKey], [rightKey]) => leftKey < rightKey ? -1
|
|
45
|
+
: leftKey > rightKey ? 1
|
|
46
|
+
: 0);
|
|
47
|
+
let canonicalString = '';
|
|
48
|
+
for (const [key, value] of entries) {
|
|
49
|
+
const pair = `${key}=${String(value)}`;
|
|
50
|
+
canonicalString = canonicalString ? `${canonicalString}&${pair}` : pair;
|
|
51
|
+
}
|
|
52
|
+
return canonicalString;
|
|
53
|
+
};
|
|
54
|
+
exports.buildCanonicalString = buildCanonicalString;
|
|
55
|
+
const createHmacSignature = (secret, data) => crypto.createHmac(HMAC_ALGORITHM, secret).update((0, exports.buildCanonicalString)(data)).digest('hex');
|
|
56
|
+
exports.createHmacSignature = createHmacSignature;
|
|
57
|
+
const verifyHmacSignature = (secret, data, signature) => {
|
|
58
|
+
if (!signature) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const expected = Buffer.from((0, exports.createHmacSignature)(secret, data), 'utf8');
|
|
62
|
+
const received = Buffer.from(signature, 'utf8');
|
|
63
|
+
return expected.length === received.length && crypto.timingSafeEqual(expected, received);
|
|
64
|
+
};
|
|
65
|
+
exports.verifyHmacSignature = verifyHmacSignature;
|
|
66
|
+
const hashWithBcrypt = async (data, saltRounds = 10) => {
|
|
67
|
+
const canonicalString = (0, exports.buildCanonicalString)(data);
|
|
68
|
+
if (Buffer.byteLength(canonicalString, 'utf8') > 72) {
|
|
69
|
+
(0, exception_1.throwHttpException)(exception_1.HTTP_EXCEPTION.BAD_REQUEST, {
|
|
70
|
+
code: exception_1.HTTP_EXCEPTION_CODE.SIGNATURE_STRING_LENGTH_LIMIT,
|
|
71
|
+
message: 'Input string exceeds bcrypt maximum length of 72 bytes.'
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const salt = await bcrypt.genSalt(saltRounds);
|
|
75
|
+
return bcrypt.hash(canonicalString, salt);
|
|
76
|
+
};
|
|
77
|
+
exports.hashWithBcrypt = hashWithBcrypt;
|
|
78
|
+
const verifyBcryptHash = (data, hash) => {
|
|
79
|
+
const canonicalString = typeof data === 'string' ? data : (0, exports.buildCanonicalString)(data);
|
|
80
|
+
return bcrypt.compare(canonicalString, hash);
|
|
81
|
+
};
|
|
82
|
+
exports.verifyBcryptHash = verifyBcryptHash;
|
package/package.json
CHANGED
|
@@ -1,6 +1,129 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bearei/nest",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.0-dev.2",
|
|
4
|
+
"description": "Shared NestJS and TypeORM building blocks for Bearei services",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bearei",
|
|
7
|
+
"nestjs",
|
|
8
|
+
"shared-library",
|
|
9
|
+
"typeorm"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/bear-ei/nest#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/bear-ei/nest/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/bear-ei/nest.git"
|
|
18
|
+
},
|
|
19
|
+
"author": "bearei <bear_ei@outlook.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@bearei/contracts": "^2.0.0",
|
|
42
|
+
"bcrypt": "^5.1.1",
|
|
43
|
+
"dayjs": "^1.11.13",
|
|
44
|
+
"ioredis": "^5.4.1",
|
|
45
|
+
"nanoid": "^3.3.7"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@nestjs/axios": "^4.0.1",
|
|
49
|
+
"@nestjs/common": "^11.1.27",
|
|
50
|
+
"@nestjs/config": "^4.0.4",
|
|
51
|
+
"@nestjs/core": "^11.1.27",
|
|
52
|
+
"@nestjs/jwt": "^11.0.2",
|
|
53
|
+
"@nestjs/typeorm": "^11.0.2",
|
|
54
|
+
"axios": "^1.18.0",
|
|
55
|
+
"class-transformer": "^0.5.1",
|
|
56
|
+
"class-validator": "^0.14.1",
|
|
57
|
+
"reflect-metadata": "^0.2.0",
|
|
58
|
+
"rxjs": "^7.8.2",
|
|
59
|
+
"typeorm": "^1.0.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@bearei/eslint-config": "^2.0.0",
|
|
63
|
+
"@bearei/jest-preset": "^2.0.0",
|
|
64
|
+
"@bearei/tsconfig": "^2.0.0",
|
|
65
|
+
"@nestjs/axios": "^4.0.1",
|
|
66
|
+
"@nestjs/cli": "^11.0.0",
|
|
67
|
+
"@nestjs/common": "^11.1.27",
|
|
68
|
+
"@nestjs/config": "^4.0.4",
|
|
69
|
+
"@nestjs/core": "^11.1.27",
|
|
70
|
+
"@nestjs/jwt": "^11.0.2",
|
|
71
|
+
"@nestjs/schematics": "^11.0.0",
|
|
72
|
+
"@nestjs/typeorm": "^11.0.2",
|
|
73
|
+
"@types/bcrypt": "^5",
|
|
74
|
+
"@types/jest": "^29.5.13",
|
|
75
|
+
"@types/node": "^20.3.1",
|
|
76
|
+
"axios": "^1.18.0",
|
|
77
|
+
"class-transformer": "^0.5.1",
|
|
78
|
+
"class-validator": "^0.14.1",
|
|
79
|
+
"eslint": "^9.37.0",
|
|
80
|
+
"jest": "^29.7.0",
|
|
81
|
+
"prettier": "^3.9.6",
|
|
82
|
+
"reflect-metadata": "^0.2.0",
|
|
83
|
+
"rxjs": "^7.8.2",
|
|
84
|
+
"shx": "^0.3.4",
|
|
85
|
+
"ts-jest": "^29.1.0",
|
|
86
|
+
"ts-node": "^10.9.1",
|
|
87
|
+
"tsconfig-paths": "^4.2.0",
|
|
88
|
+
"typeorm": "^1.0.0",
|
|
89
|
+
"typescript": "^5.9.3"
|
|
90
|
+
},
|
|
91
|
+
"jest": {
|
|
92
|
+
"preset": "@bearei/jest-preset/nest",
|
|
93
|
+
"rootDir": ".",
|
|
94
|
+
"passWithNoTests": false,
|
|
95
|
+
"setupFilesAfterEnv": [
|
|
96
|
+
"<rootDir>/test/setup.ts"
|
|
97
|
+
],
|
|
98
|
+
"collectCoverageFrom": [
|
|
99
|
+
"src/**/*.ts",
|
|
100
|
+
"!src/**/*.spec.ts",
|
|
101
|
+
"!src/**/*.module.ts",
|
|
102
|
+
"!src/**/index.ts"
|
|
103
|
+
],
|
|
104
|
+
"coverageThreshold": {
|
|
105
|
+
"global": {
|
|
106
|
+
"branches": 90,
|
|
107
|
+
"functions": 90,
|
|
108
|
+
"lines": 90,
|
|
109
|
+
"statements": 90
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"scripts": {
|
|
114
|
+
"build": "yarn clean && nest build",
|
|
115
|
+
"clean": "shx rm -rf dist",
|
|
116
|
+
"format": "prettier --write .",
|
|
117
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
118
|
+
"pack": "yarn pack -o /tmp/bearei-nest.tgz && bash .github/scripts/verify-tarball.sh /tmp/bearei-nest.tgz",
|
|
119
|
+
"prepack": "yarn build",
|
|
120
|
+
"test": "jest",
|
|
121
|
+
"test:coverage": "jest --coverage",
|
|
122
|
+
"test:cov": "jest --coverage",
|
|
123
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
124
|
+
"test:watch": "jest --watch",
|
|
125
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
126
|
+
"verify": "yarn lint && yarn typecheck && yarn test:coverage && yarn build"
|
|
127
|
+
},
|
|
128
|
+
"packageManager": "yarn@4.18.0+sha512.fcb8716fe7cd0eece141ffc18b92193a9df9204c1ba83189c288835223fc0bbe64af473bab0d5e9927a7daeb5caf2bb07eb2787cc9338ca040ea125f2a1f2f7e"
|
|
6
129
|
}
|