@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.
Files changed (145) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/LICENSE +21 -0
  3. package/README.md +100 -2
  4. package/README.zh-CN.md +103 -0
  5. package/dist/action-log/action-log.interface.d.ts +12 -0
  6. package/dist/action-log/action-log.interface.js +2 -0
  7. package/dist/action-log/action-log.module.d.ts +2 -0
  8. package/dist/action-log/action-log.module.js +22 -0
  9. package/dist/action-log/action-log.service.d.ts +10 -0
  10. package/dist/action-log/action-log.service.js +42 -0
  11. package/dist/action-log/index.d.ts +3 -0
  12. package/dist/action-log/index.js +19 -0
  13. package/dist/authentication/authentication-context.interceptor.d.ts +7 -0
  14. package/dist/authentication/authentication-context.interceptor.js +70 -0
  15. package/dist/authentication/authentication.enum.d.ts +6 -0
  16. package/dist/authentication/authentication.enum.js +9 -0
  17. package/dist/authentication/authentication.guard.d.ts +13 -0
  18. package/dist/authentication/authentication.guard.js +92 -0
  19. package/dist/authentication/authentication.interface.d.ts +2 -0
  20. package/dist/authentication/authentication.interface.js +2 -0
  21. package/dist/authentication/index.d.ts +4 -0
  22. package/dist/authentication/index.js +20 -0
  23. package/dist/authorization/authorization.interface.d.ts +3 -0
  24. package/dist/authorization/authorization.interface.js +2 -0
  25. package/dist/authorization/authorization.module.d.ts +2 -0
  26. package/dist/authorization/authorization.module.js +22 -0
  27. package/dist/authorization/authorization.service.d.ts +10 -0
  28. package/dist/authorization/authorization.service.js +56 -0
  29. package/dist/authorization/index.d.ts +3 -0
  30. package/dist/authorization/index.js +19 -0
  31. package/dist/base-service/base-service.interface.d.ts +84 -0
  32. package/dist/base-service/base-service.interface.js +2 -0
  33. package/dist/base-service/base-service.module.d.ts +2 -0
  34. package/dist/base-service/base-service.module.js +22 -0
  35. package/dist/base-service/base-service.service.d.ts +27 -0
  36. package/dist/base-service/base-service.service.js +517 -0
  37. package/dist/base-service/index.d.ts +3 -0
  38. package/dist/base-service/index.js +19 -0
  39. package/dist/common.dto.d.ts +19 -0
  40. package/dist/common.dto.js +111 -0
  41. package/dist/common.entity.d.ts +11 -0
  42. package/dist/common.entity.js +76 -0
  43. package/dist/common.enum.d.ts +19 -0
  44. package/dist/common.enum.js +24 -0
  45. package/dist/common.interface.d.ts +19 -0
  46. package/dist/common.interface.js +2 -0
  47. package/dist/database/database.module.d.ts +5 -0
  48. package/dist/database/database.module.js +58 -0
  49. package/dist/database/index.d.ts +1 -0
  50. package/dist/database/index.js +17 -0
  51. package/dist/decorators/allow-access.decorator.d.ts +3 -0
  52. package/dist/decorators/allow-access.decorator.js +7 -0
  53. package/dist/decorators/index.d.ts +8 -0
  54. package/dist/decorators/index.js +24 -0
  55. package/dist/decorators/is-captcha.decorator.d.ts +2 -0
  56. package/dist/decorators/is-captcha.decorator.js +23 -0
  57. package/dist/decorators/is-nano-id.decorator.d.ts +2 -0
  58. package/dist/decorators/is-nano-id.decorator.js +22 -0
  59. package/dist/decorators/is-password.decorator.d.ts +2 -0
  60. package/dist/decorators/is-password.decorator.js +23 -0
  61. package/dist/decorators/is-version.decorator.d.ts +2 -0
  62. package/dist/decorators/is-version.decorator.js +22 -0
  63. package/dist/decorators/omit-entity-keys.decorator.d.ts +2 -0
  64. package/dist/decorators/omit-entity-keys.decorator.js +7 -0
  65. package/dist/decorators/require-permissions.decorator.d.ts +3 -0
  66. package/dist/decorators/require-permissions.decorator.js +7 -0
  67. package/dist/decorators/require-subscription-features.decorator.d.ts +3 -0
  68. package/dist/decorators/require-subscription-features.decorator.js +7 -0
  69. package/dist/exception/exception.enum.d.ts +12 -0
  70. package/dist/exception/exception.enum.js +16 -0
  71. package/dist/exception/exception.interface.d.ts +9 -0
  72. package/dist/exception/exception.interface.js +2 -0
  73. package/dist/exception/http.exception.d.ts +4 -0
  74. package/dist/exception/http.exception.js +47 -0
  75. package/dist/exception/index.d.ts +3 -0
  76. package/dist/exception/index.js +19 -0
  77. package/dist/external/external.interface.d.ts +58 -0
  78. package/dist/external/external.interface.js +2 -0
  79. package/dist/external/external.module.d.ts +2 -0
  80. package/dist/external/external.module.js +24 -0
  81. package/dist/external/external.service.d.ts +15 -0
  82. package/dist/external/external.service.js +160 -0
  83. package/dist/external/index.d.ts +3 -0
  84. package/dist/external/index.js +19 -0
  85. package/dist/index.d.ts +17 -0
  86. package/dist/index.js +39 -0
  87. package/dist/jwt/index.d.ts +3 -0
  88. package/dist/jwt/index.js +19 -0
  89. package/dist/jwt/jwt.interface.d.ts +15 -0
  90. package/dist/jwt/jwt.interface.js +2 -0
  91. package/dist/jwt/jwt.module.d.ts +2 -0
  92. package/dist/jwt/jwt.module.js +43 -0
  93. package/dist/jwt/jwt.service.d.ts +10 -0
  94. package/dist/jwt/jwt.service.js +52 -0
  95. package/dist/permission/index.d.ts +3 -0
  96. package/dist/permission/index.js +19 -0
  97. package/dist/permission/permission.enum.d.ts +70 -0
  98. package/dist/permission/permission.enum.js +73 -0
  99. package/dist/permission/permission.guard.d.ts +9 -0
  100. package/dist/permission/permission.guard.js +55 -0
  101. package/dist/permission/permission.interface.d.ts +2 -0
  102. package/dist/permission/permission.interface.js +2 -0
  103. package/dist/redis/index.d.ts +3 -0
  104. package/dist/redis/index.js +19 -0
  105. package/dist/redis/redis.interface.d.ts +4 -0
  106. package/dist/redis/redis.interface.js +2 -0
  107. package/dist/redis/redis.module.d.ts +2 -0
  108. package/dist/redis/redis.module.js +22 -0
  109. package/dist/redis/redis.service.d.ts +14 -0
  110. package/dist/redis/redis.service.js +51 -0
  111. package/dist/subscription-feature/index.d.ts +3 -0
  112. package/dist/subscription-feature/index.js +19 -0
  113. package/dist/subscription-feature/subscription-feature.enum.d.ts +3 -0
  114. package/dist/subscription-feature/subscription-feature.enum.js +6 -0
  115. package/dist/subscription-feature/subscription-feature.interceptor.d.ts +9 -0
  116. package/dist/subscription-feature/subscription-feature.interceptor.js +68 -0
  117. package/dist/subscription-feature/subscription-feature.interface.d.ts +2 -0
  118. package/dist/subscription-feature/subscription-feature.interface.js +2 -0
  119. package/dist/utils/create-response-sanitizer/create-response-sanitizer.utils.d.ts +1 -0
  120. package/dist/utils/create-response-sanitizer/create-response-sanitizer.utils.js +23 -0
  121. package/dist/utils/create-response-sanitizer/index.d.ts +1 -0
  122. package/dist/utils/create-response-sanitizer/index.js +17 -0
  123. package/dist/utils/extract-bearer-token/extract-bearer-token.utils.d.ts +1 -0
  124. package/dist/utils/extract-bearer-token/extract-bearer-token.utils.js +13 -0
  125. package/dist/utils/extract-bearer-token/index.d.ts +1 -0
  126. package/dist/utils/extract-bearer-token/index.js +17 -0
  127. package/dist/utils/format-mobile-number/format-mobile-number.utils.d.ts +1 -0
  128. package/dist/utils/format-mobile-number/format-mobile-number.utils.js +5 -0
  129. package/dist/utils/format-mobile-number/index.d.ts +1 -0
  130. package/dist/utils/format-mobile-number/index.js +17 -0
  131. package/dist/utils/generate-random-number-string/generate-random-number-string.utils.d.ts +1 -0
  132. package/dist/utils/generate-random-number-string/generate-random-number-string.utils.js +6 -0
  133. package/dist/utils/generate-random-number-string/index.d.ts +1 -0
  134. package/dist/utils/generate-random-number-string/index.js +17 -0
  135. package/dist/utils/index.d.ts +6 -0
  136. package/dist/utils/index.js +22 -0
  137. package/dist/utils/run-with-database-retry/index.d.ts +1 -0
  138. package/dist/utils/run-with-database-retry/index.js +17 -0
  139. package/dist/utils/run-with-database-retry/run-with-database-retry.utils.d.ts +1 -0
  140. package/dist/utils/run-with-database-retry/run-with-database-retry.utils.js +23 -0
  141. package/dist/utils/sign/index.d.ts +1 -0
  142. package/dist/utils/sign/index.js +17 -0
  143. package/dist/utils/sign/sign.utils.d.ts +5 -0
  144. package/dist/utils/sign/sign.utils.js +82 -0
  145. 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": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
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
  }