@devstroupe/devkit-nest 1.1.16 → 1.2.0-beta.1
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/README.md +35 -55
- package/dist/application/crud-use-cases.d.ts +35 -0
- package/dist/application/crud-use-cases.js +44 -0
- package/dist/application/crud-use-cases.test.d.ts +1 -0
- package/dist/application/crud-use-cases.test.js +19 -0
- package/dist/application/index.d.ts +2 -0
- package/dist/application/index.js +18 -0
- package/dist/application/read-model.d.ts +5 -0
- package/dist/application/read-model.js +2 -0
- package/dist/context/execution-context.d.ts +19 -0
- package/dist/context/execution-context.interceptor.d.ts +5 -0
- package/dist/context/execution-context.interceptor.js +35 -0
- package/dist/context/execution-context.interceptor.test.d.ts +1 -0
- package/dist/context/execution-context.interceptor.test.js +26 -0
- package/dist/context/execution-context.js +38 -0
- package/dist/context/execution-context.test.d.ts +1 -0
- package/dist/context/execution-context.test.js +18 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +18 -0
- package/dist/database/base.repository.d.ts +25 -13
- package/dist/database/base.repository.js +63 -29
- package/dist/database/base.repository.test.d.ts +1 -0
- package/dist/database/base.repository.test.js +46 -0
- package/dist/database/typeorm-explain.d.ts +3 -0
- package/dist/database/typeorm-explain.js +8 -0
- package/dist/database/typeorm-explain.test.d.ts +1 -0
- package/dist/database/typeorm-explain.test.js +15 -0
- package/dist/database/typeorm-query.builder.d.ts +36 -8
- package/dist/database/typeorm-query.builder.js +150 -165
- package/dist/database/typeorm-query.builder.test.js +32 -1
- package/dist/database/typeorm-reader.d.ts +9 -0
- package/dist/database/typeorm-reader.js +49 -0
- package/dist/database/typeorm-reader.test.d.ts +1 -0
- package/dist/database/typeorm-reader.test.js +55 -0
- package/dist/database/typeorm-sql.d.ts +3 -0
- package/dist/database/typeorm-sql.js +7 -0
- package/dist/database/typeorm-sql.test.d.ts +1 -0
- package/dist/database/typeorm-sql.test.js +21 -0
- package/dist/database/typeorm-unit-of-work.d.ts +13 -0
- package/dist/database/typeorm-unit-of-work.js +16 -0
- package/dist/database/typeorm-unit-of-work.test.d.ts +1 -0
- package/dist/database/typeorm-unit-of-work.test.js +34 -0
- package/dist/http/base-crud.controller.d.ts +26 -10
- package/dist/http/base-crud.controller.js +46 -36
- package/dist/http/base-crud.controller.test.d.ts +1 -0
- package/dist/http/base-crud.controller.test.js +18 -0
- package/dist/http/module-http-proxy.d.ts +16 -0
- package/dist/http/module-http-proxy.js +160 -0
- package/dist/http/module-http-proxy.test.d.ts +1 -0
- package/dist/http/module-http-proxy.test.js +37 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/platform/index.d.ts +3 -0
- package/dist/platform/index.js +19 -0
- package/dist/platform/integrations/company-registry.d.ts +16 -0
- package/dist/platform/integrations/company-registry.js +2 -0
- package/dist/platform/integrations/external-http.d.ts +38 -0
- package/dist/platform/integrations/external-http.js +78 -0
- package/dist/platform/integrations/external-http.test.d.ts +1 -0
- package/dist/platform/integrations/external-http.test.js +42 -0
- package/dist/platform/integrations/index.d.ts +3 -0
- package/dist/platform/integrations/index.js +19 -0
- package/dist/platform/integrations/webhook.d.ts +45 -0
- package/dist/platform/integrations/webhook.js +74 -0
- package/dist/platform/integrations/webhook.test.d.ts +1 -0
- package/dist/platform/integrations/webhook.test.js +66 -0
- package/dist/platform/messaging/index.d.ts +1 -0
- package/dist/platform/messaging/index.js +17 -0
- package/dist/platform/messaging/outbox.d.ts +56 -0
- package/dist/platform/messaging/outbox.js +90 -0
- package/dist/platform/messaging/outbox.test.d.ts +1 -0
- package/dist/platform/messaging/outbox.test.js +65 -0
- package/dist/platform/security/index.d.ts +2 -0
- package/dist/platform/security/index.js +18 -0
- package/dist/platform/security/password-hasher.d.ts +14 -0
- package/dist/platform/security/password-hasher.js +20 -0
- package/dist/platform/security/security.test.d.ts +1 -0
- package/dist/platform/security/security.test.js +24 -0
- package/dist/platform/security/token.d.ts +22 -0
- package/dist/platform/security/token.js +44 -0
- package/dist/realtime/index.d.ts +1 -0
- package/dist/realtime/index.js +1 -0
- package/dist/realtime/realtime.gateway.d.ts +4 -1
- package/dist/realtime/realtime.gateway.js +10 -38
- package/dist/realtime/realtime.gateway.test.d.ts +1 -0
- package/dist/realtime/realtime.gateway.test.js +34 -0
- package/dist/realtime/realtime.module.d.ts +7 -0
- package/dist/realtime/realtime.module.js +17 -6
- package/dist/realtime/realtime.tokens.d.ts +1 -0
- package/dist/realtime/realtime.tokens.js +4 -0
- package/dist/storage/drivers/local.storage.js +8 -1
- package/package.json +18 -14
package/dist/realtime/index.d.ts
CHANGED
package/dist/realtime/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./realtime.module"), exports);
|
|
18
18
|
__exportStar(require("./realtime.service"), exports);
|
|
19
19
|
__exportStar(require("./realtime.gateway"), exports);
|
|
20
|
+
__exportStar(require("./realtime.tokens"), exports);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { OnGatewayConnection, OnGatewayDisconnect } from '@nestjs/websockets';
|
|
2
2
|
import { Server, Socket } from 'socket.io';
|
|
3
|
+
import type { TokenVerifier } from '../platform/security';
|
|
3
4
|
export declare class RealtimeGateway implements OnGatewayConnection, OnGatewayDisconnect {
|
|
5
|
+
private readonly tokenVerifier;
|
|
4
6
|
server: Server;
|
|
5
7
|
private readonly logger;
|
|
6
8
|
private connectedUsers;
|
|
7
|
-
|
|
9
|
+
constructor(tokenVerifier: TokenVerifier);
|
|
10
|
+
handleConnection(client: Socket): Promise<void>;
|
|
8
11
|
handleDisconnect(client: Socket): void;
|
|
9
12
|
emitEntityChange(entityName: string, action: string, data: any, tenantId?: string): void;
|
|
10
13
|
handleSubscribeEntity(entity: string, client: Socket): {
|
|
@@ -1,43 +1,10 @@
|
|
|
1
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
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
10
|
};
|
|
@@ -50,12 +17,16 @@ exports.RealtimeGateway = void 0;
|
|
|
50
17
|
const websockets_1 = require("@nestjs/websockets");
|
|
51
18
|
const socket_io_1 = require("socket.io");
|
|
52
19
|
const common_1 = require("@nestjs/common");
|
|
53
|
-
const
|
|
20
|
+
const realtime_tokens_1 = require("./realtime.tokens");
|
|
54
21
|
let RealtimeGateway = RealtimeGateway_1 = class RealtimeGateway {
|
|
22
|
+
tokenVerifier;
|
|
55
23
|
server;
|
|
56
24
|
logger = new common_1.Logger(RealtimeGateway_1.name);
|
|
57
25
|
connectedUsers = new Map();
|
|
58
|
-
|
|
26
|
+
constructor(tokenVerifier) {
|
|
27
|
+
this.tokenVerifier = tokenVerifier;
|
|
28
|
+
}
|
|
29
|
+
async handleConnection(client) {
|
|
59
30
|
try {
|
|
60
31
|
const token = client.handshake.auth?.token || client.handshake.headers?.authorization?.split(' ')[1];
|
|
61
32
|
if (!token) {
|
|
@@ -63,8 +34,7 @@ let RealtimeGateway = RealtimeGateway_1 = class RealtimeGateway {
|
|
|
63
34
|
client.disconnect();
|
|
64
35
|
return;
|
|
65
36
|
}
|
|
66
|
-
const
|
|
67
|
-
const decoded = jwt.verify(token, secret);
|
|
37
|
+
const decoded = await this.tokenVerifier.verify(token);
|
|
68
38
|
client.data = {
|
|
69
39
|
userId: decoded.sub,
|
|
70
40
|
email: decoded.email,
|
|
@@ -130,5 +100,7 @@ exports.RealtimeGateway = RealtimeGateway = RealtimeGateway_1 = __decorate([
|
|
|
130
100
|
},
|
|
131
101
|
transports: ['websocket'],
|
|
132
102
|
}),
|
|
133
|
-
(0, common_1.Injectable)()
|
|
103
|
+
(0, common_1.Injectable)(),
|
|
104
|
+
__param(0, (0, common_1.Inject)(realtime_tokens_1.REALTIME_TOKEN_VERIFIER)),
|
|
105
|
+
__metadata("design:paramtypes", [Object])
|
|
134
106
|
], RealtimeGateway);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
7
|
+
const node_test_1 = __importDefault(require("node:test"));
|
|
8
|
+
const realtime_gateway_1 = require("./realtime.gateway");
|
|
9
|
+
function socket(token) {
|
|
10
|
+
return {
|
|
11
|
+
id: 'socket-1',
|
|
12
|
+
handshake: { auth: { token }, headers: {} },
|
|
13
|
+
data: {},
|
|
14
|
+
rooms: [],
|
|
15
|
+
disconnected: false,
|
|
16
|
+
join(room) { this.rooms.push(room); },
|
|
17
|
+
disconnect() { this.disconnected = true; },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
(0, node_test_1.default)('realtime receives verification-only capability and joins trusted claim rooms', async () => {
|
|
21
|
+
const gateway = new realtime_gateway_1.RealtimeGateway({
|
|
22
|
+
verify: async () => ({ sub: 'user-1', tenantId: 'tenant-1', role: 'admin' }),
|
|
23
|
+
});
|
|
24
|
+
const client = socket('signed-token');
|
|
25
|
+
await gateway.handleConnection(client);
|
|
26
|
+
strict_1.default.equal(client.disconnected, false);
|
|
27
|
+
strict_1.default.deepEqual(client.rooms, ['user:user-1', 'role:admin', 'tenant:tenant-1']);
|
|
28
|
+
});
|
|
29
|
+
(0, node_test_1.default)('realtime rejects a token when the verifier fails', async () => {
|
|
30
|
+
const gateway = new realtime_gateway_1.RealtimeGateway({ verify: async () => { throw new Error('invalid'); } });
|
|
31
|
+
const client = socket('invalid-token');
|
|
32
|
+
await gateway.handleConnection(client);
|
|
33
|
+
strict_1.default.equal(client.disconnected, true);
|
|
34
|
+
});
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import type { TokenVerifier } from '../platform/security';
|
|
3
|
+
export interface RealtimeModuleOptions {
|
|
4
|
+
/** Pass only verification capability; realtime never receives a signing key. */
|
|
5
|
+
tokenVerifier: TokenVerifier;
|
|
6
|
+
}
|
|
1
7
|
export declare class RealtimeModule {
|
|
8
|
+
static register(options: RealtimeModuleOptions): DynamicModule;
|
|
2
9
|
}
|
|
@@ -5,18 +5,29 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var RealtimeModule_1;
|
|
8
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
10
|
exports.RealtimeModule = void 0;
|
|
10
11
|
const common_1 = require("@nestjs/common");
|
|
11
12
|
const realtime_gateway_1 = require("./realtime.gateway");
|
|
12
13
|
const realtime_service_1 = require("./realtime.service");
|
|
13
|
-
|
|
14
|
+
const realtime_tokens_1 = require("./realtime.tokens");
|
|
15
|
+
let RealtimeModule = RealtimeModule_1 = class RealtimeModule {
|
|
16
|
+
static register(options) {
|
|
17
|
+
return {
|
|
18
|
+
module: RealtimeModule_1,
|
|
19
|
+
global: true,
|
|
20
|
+
providers: [
|
|
21
|
+
{ provide: realtime_tokens_1.REALTIME_TOKEN_VERIFIER, useValue: options.tokenVerifier },
|
|
22
|
+
realtime_gateway_1.RealtimeGateway,
|
|
23
|
+
realtime_service_1.RealtimeService,
|
|
24
|
+
],
|
|
25
|
+
exports: [realtime_service_1.RealtimeService],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
14
28
|
};
|
|
15
29
|
exports.RealtimeModule = RealtimeModule;
|
|
16
|
-
exports.RealtimeModule = RealtimeModule = __decorate([
|
|
30
|
+
exports.RealtimeModule = RealtimeModule = RealtimeModule_1 = __decorate([
|
|
17
31
|
(0, common_1.Global)(),
|
|
18
|
-
(0, common_1.Module)({
|
|
19
|
-
providers: [realtime_gateway_1.RealtimeGateway, realtime_service_1.RealtimeService],
|
|
20
|
-
exports: [realtime_service_1.RealtimeService],
|
|
21
|
-
})
|
|
32
|
+
(0, common_1.Module)({})
|
|
22
33
|
], RealtimeModule);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const REALTIME_TOKEN_VERIFIER: unique symbol;
|
|
@@ -62,8 +62,15 @@ let LocalStorageService = class LocalStorageService {
|
|
|
62
62
|
const filename = options?.filename
|
|
63
63
|
? options.filename.replace(/[^a-zA-Z0-9._-]/g, '')
|
|
64
64
|
: `${crypto.randomUUID()}${sanitizedExt}`;
|
|
65
|
+
if (!filename || filename === '.' || filename === '..') {
|
|
66
|
+
throw new Error('Invalid storage filename');
|
|
67
|
+
}
|
|
65
68
|
// 3. Resolver caminho da subpasta e mitigar Directory Traversal
|
|
66
|
-
const
|
|
69
|
+
const requestedPath = options?.path ?? '';
|
|
70
|
+
if (path.isAbsolute(requestedPath) || requestedPath.split(/[\\/]+/).includes('..')) {
|
|
71
|
+
throw new Error('Directory traversal attempt detected');
|
|
72
|
+
}
|
|
73
|
+
const subPath = requestedPath ? path.normalize(requestedPath) : '';
|
|
67
74
|
const targetDir = path.resolve(this.storagePath, subPath);
|
|
68
75
|
// Adicionamos a barra final para segurança máxima de limite de diretório
|
|
69
76
|
const rootPrefix = this.storagePath.endsWith(path.sep) ? this.storagePath : this.storagePath + path.sep;
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devstroupe/devkit-nest",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.0-beta.1",
|
|
4
4
|
"description": "DevsTroupe Development Kit — NestJS base classes: BaseRepository, BaseCrudController and query parsers",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20"
|
|
8
|
+
},
|
|
6
9
|
"keywords": [
|
|
7
10
|
"devstroupe",
|
|
8
11
|
"devkit",
|
|
@@ -31,40 +34,41 @@
|
|
|
31
34
|
"dependencies": {
|
|
32
35
|
"@aws-sdk/client-s3": "^3.500.0",
|
|
33
36
|
"@aws-sdk/s3-request-presigner": "^3.500.0",
|
|
37
|
+
"bcryptjs": "^3.0.3",
|
|
34
38
|
"jsonwebtoken": "^9.0.2",
|
|
35
|
-
"@devstroupe/devkit-core": "1.1
|
|
39
|
+
"@devstroupe/devkit-core": "1.2.0-beta.1"
|
|
36
40
|
},
|
|
37
41
|
"peerDependencies": {
|
|
38
42
|
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
39
43
|
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
44
|
+
"@nestjs/platform-socket.io": "^10.0.0 || ^11.0.0",
|
|
40
45
|
"@nestjs/swagger": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
41
46
|
"@nestjs/websockets": "^10.0.0 || ^11.0.0",
|
|
42
|
-
"
|
|
43
|
-
"socket.io": "^4.7.0",
|
|
44
|
-
"rxjs": "^7.0.0",
|
|
45
|
-
"typeorm": "^0.3.0",
|
|
46
|
-
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
47
|
+
"class-transformer": "^0.4.0 || ^0.5.0",
|
|
47
48
|
"class-validator": "^0.13.0 || ^0.14.0",
|
|
48
|
-
"
|
|
49
|
+
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
50
|
+
"rxjs": "^7.0.0",
|
|
51
|
+
"socket.io": "^4.7.0",
|
|
52
|
+
"typeorm": "^1.0.0"
|
|
49
53
|
},
|
|
50
54
|
"devDependencies": {
|
|
51
55
|
"@nestjs/common": "^10.3.8",
|
|
52
56
|
"@nestjs/core": "^10.3.8",
|
|
57
|
+
"@nestjs/platform-socket.io": "^10.3.8",
|
|
53
58
|
"@nestjs/swagger": "^7.3.1",
|
|
54
59
|
"@nestjs/websockets": "^10.3.8",
|
|
55
|
-
"@nestjs/platform-socket.io": "^10.3.8",
|
|
56
60
|
"@types/jsonwebtoken": "^9.0.6",
|
|
57
61
|
"@types/node": "^20.11.0",
|
|
62
|
+
"class-transformer": "^0.5.1",
|
|
63
|
+
"class-validator": "^0.14.1",
|
|
64
|
+
"reflect-metadata": "^0.1.13",
|
|
58
65
|
"rxjs": "^7.8.1",
|
|
59
66
|
"socket.io": "^4.7.5",
|
|
60
|
-
"typeorm": "^0.
|
|
61
|
-
"reflect-metadata": "^0.1.13",
|
|
62
|
-
"class-validator": "^0.14.1",
|
|
63
|
-
"class-transformer": "^0.5.1",
|
|
67
|
+
"typeorm": "^1.0.0",
|
|
64
68
|
"typescript": "^5.4.5"
|
|
65
69
|
},
|
|
66
70
|
"scripts": {
|
|
67
71
|
"build": "tsc",
|
|
68
|
-
"test": "tsc && node --test dist
|
|
72
|
+
"test": "tsc && node --test dist"
|
|
69
73
|
}
|
|
70
74
|
}
|