@bpinhosilva/agent-orchestrator 1.0.0-alpha.13 → 1.0.0-alpha.15
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 +15 -0
- package/dist/agents/agents.module.js +3 -5
- package/dist/agents/agents.service.js +14 -8
- package/dist/agents/implementations/claude.agent.js +11 -5
- package/dist/agents/implementations/gemini.agent.js +15 -6
- package/dist/app.module.js +47 -9
- package/dist/auth/auth.controller.js +65 -0
- package/dist/auth/auth.module.js +39 -0
- package/dist/auth/auth.service.js +106 -0
- package/dist/auth/decorators/public.decorator.js +7 -0
- package/dist/auth/dto/login.dto.js +27 -0
- package/dist/auth/dto/register.dto.js +33 -0
- package/dist/auth/guards/jwt-auth.guard.js +37 -0
- package/dist/auth/strategies/jwt.strategy.js +41 -0
- package/dist/config/env.validation.js +47 -0
- package/dist/scripts/seed-admin.d.ts +1 -0
- package/dist/scripts/seed-admin.js +40 -0
- package/dist/scripts/seed-admin.js.map +1 -0
- package/dist/src/agents/agents.module.d.ts +0 -2
- package/dist/src/agents/agents.module.js +3 -3
- package/dist/src/agents/agents.module.js.map +1 -1
- package/dist/src/agents/agents.service.d.ts +3 -1
- package/dist/src/agents/agents.service.js +13 -8
- package/dist/src/agents/agents.service.js.map +1 -1
- package/dist/src/agents/implementations/claude.agent.d.ts +4 -1
- package/dist/src/agents/implementations/claude.agent.js +12 -5
- package/dist/src/agents/implementations/claude.agent.js.map +1 -1
- package/dist/src/agents/implementations/gemini.agent.d.ts +4 -1
- package/dist/src/agents/implementations/gemini.agent.js +16 -7
- package/dist/src/agents/implementations/gemini.agent.js.map +1 -1
- package/dist/src/app.module.js +47 -9
- package/dist/src/app.module.js.map +1 -1
- package/dist/src/auth/auth.controller.d.ts +20 -0
- package/dist/src/auth/auth.controller.js +71 -0
- package/dist/src/auth/auth.controller.js.map +1 -0
- package/dist/src/auth/auth.module.d.ts +2 -0
- package/dist/src/auth/auth.module.js +40 -0
- package/dist/src/auth/auth.module.js.map +1 -0
- package/dist/src/auth/auth.service.d.ts +21 -0
- package/dist/src/auth/auth.service.js +107 -0
- package/dist/src/auth/auth.service.js.map +1 -0
- package/dist/src/auth/decorators/public.decorator.d.ts +2 -0
- package/dist/src/auth/decorators/public.decorator.js +8 -0
- package/dist/src/auth/decorators/public.decorator.js.map +1 -0
- package/dist/src/auth/dto/login.dto.d.ts +4 -0
- package/dist/src/auth/dto/login.dto.js +34 -0
- package/dist/src/auth/dto/login.dto.js.map +1 -0
- package/dist/src/auth/dto/register.dto.d.ts +5 -0
- package/dist/src/auth/dto/register.dto.js +41 -0
- package/dist/src/auth/dto/register.dto.js.map +1 -0
- package/dist/src/auth/guards/jwt-auth.guard.d.ts +9 -0
- package/dist/src/auth/guards/jwt-auth.guard.js +39 -0
- package/dist/src/auth/guards/jwt-auth.guard.js.map +1 -0
- package/dist/src/auth/strategies/jwt.strategy.d.ts +16 -0
- package/dist/src/auth/strategies/jwt.strategy.js +44 -0
- package/dist/src/auth/strategies/jwt.strategy.js.map +1 -0
- package/dist/src/common/filters/http-exception.filter.d.ts +4 -0
- package/dist/src/common/filters/http-exception.filter.js +49 -0
- package/dist/src/common/filters/http-exception.filter.js.map +1 -0
- package/dist/src/config/env.validation.d.ts +2 -0
- package/dist/src/config/env.validation.js +48 -0
- package/dist/src/config/env.validation.js.map +1 -0
- package/dist/src/main.js +8 -1
- package/dist/src/main.js.map +1 -1
- package/dist/src/tasks/dto/create-comment.dto.js +2 -1
- package/dist/src/tasks/dto/create-comment.dto.js.map +1 -1
- package/dist/src/tasks/dto/create-task.dto.js +4 -3
- package/dist/src/tasks/dto/create-task.dto.js.map +1 -1
- package/dist/src/tasks/entities/task.entity.d.ts +2 -1
- package/dist/src/tasks/entities/task.entity.js +1 -0
- package/dist/src/tasks/entities/task.entity.js.map +1 -1
- package/dist/src/tasks/tasks.controller.d.ts +7 -1
- package/dist/src/tasks/tasks.controller.js +8 -4
- package/dist/src/tasks/tasks.controller.js.map +1 -1
- package/dist/src/tasks/tasks.service.d.ts +11 -2
- package/dist/src/tasks/tasks.service.js +21 -3
- package/dist/src/tasks/tasks.service.js.map +1 -1
- package/dist/src/users/dto/create-user.dto.d.ts +2 -0
- package/dist/src/users/dto/create-user.dto.js +15 -1
- package/dist/src/users/dto/create-user.dto.js.map +1 -1
- package/dist/src/users/entities/user.entity.d.ts +2 -0
- package/dist/src/users/entities/user.entity.js +11 -1
- package/dist/src/users/entities/user.entity.js.map +1 -1
- package/dist/src/users/users.service.d.ts +1 -0
- package/dist/src/users/users.service.js +6 -0
- package/dist/src/users/users.service.js.map +1 -1
- package/dist/tasks/dto/create-comment.dto.js +1 -0
- package/dist/tasks/dto/create-task.dto.js +3 -2
- package/dist/tasks/entities/task.entity.js +1 -0
- package/dist/tasks/tasks.controller.js +7 -3
- package/dist/tasks/tasks.service.js +21 -3
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/users/dto/create-user.dto.js +12 -0
- package/dist/users/entities/user.entity.js +8 -0
- package/dist/users/users.service.js +6 -0
- package/package.json +13 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [1.0.0-alpha.15](https://github.com/bpinhosilva/agent-orchestrator/compare/v1.0.0-alpha.14...v1.0.0-alpha.15) (2026-03-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* implement user authentication system with JWT, registration, and login functionality ([63582fa](https://github.com/bpinhosilva/agent-orchestrator/commit/63582fa8f318c8a6bc174795364a4d3cbd221d45))
|
|
7
|
+
|
|
8
|
+
# [1.0.0-alpha.14](https://github.com/bpinhosilva/agent-orchestrator/compare/v1.0.0-alpha.13...v1.0.0-alpha.14) (2026-03-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add CreateTaskDto ([1604945](https://github.com/bpinhosilva/agent-orchestrator/commit/1604945737b5df5480c6c0814c369902f7cc9142))
|
|
14
|
+
* implement transient agent instances with dynamic configurationn ([5d57b08](https://github.com/bpinhosilva/agent-orchestrator/commit/5d57b0886edf4b14d93ab76f245f4311b6657f7d))
|
|
15
|
+
|
|
1
16
|
# [1.0.0-alpha.13](https://github.com/bpinhosilva/agent-orchestrator/compare/v1.0.0-alpha.12...v1.0.0-alpha.13) (2026-03-26)
|
|
2
17
|
|
|
3
18
|
|
|
@@ -12,10 +12,8 @@ const typeorm_1 = require("@nestjs/typeorm");
|
|
|
12
12
|
const agents_controller_1 = require("./agents.controller");
|
|
13
13
|
const agents_service_1 = require("./agents.service");
|
|
14
14
|
const agent_entity_1 = require("./entities/agent.entity");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
require("./implementations/gemini.agent");
|
|
18
|
-
require("./implementations/claude.agent");
|
|
15
|
+
const gemini_agent_1 = require("./implementations/gemini.agent");
|
|
16
|
+
const claude_agent_1 = require("./implementations/claude.agent");
|
|
19
17
|
let AgentsModule = class AgentsModule {
|
|
20
18
|
};
|
|
21
19
|
exports.AgentsModule = AgentsModule;
|
|
@@ -23,7 +21,7 @@ exports.AgentsModule = AgentsModule = __decorate([
|
|
|
23
21
|
(0, common_1.Module)({
|
|
24
22
|
imports: [typeorm_1.TypeOrmModule.forFeature([agent_entity_1.AgentEntity])],
|
|
25
23
|
controllers: [agents_controller_1.AgentsController],
|
|
26
|
-
providers: [agents_service_1.AgentsService],
|
|
24
|
+
providers: [agents_service_1.AgentsService, gemini_agent_1.GeminiAgent, claude_agent_1.ClaudeAgent],
|
|
27
25
|
exports: [agents_service_1.AgentsService],
|
|
28
26
|
})
|
|
29
27
|
], AgentsModule);
|
|
@@ -19,10 +19,12 @@ const typeorm_1 = require("@nestjs/typeorm");
|
|
|
19
19
|
const typeorm_2 = require("typeorm");
|
|
20
20
|
const agent_entity_1 = require("./entities/agent.entity");
|
|
21
21
|
const agent_registry_1 = require("./registry/agent.registry");
|
|
22
|
+
const core_1 = require("@nestjs/core");
|
|
22
23
|
const AGENT_RELATIONS = ['model', 'provider'];
|
|
23
24
|
let AgentsService = AgentsService_1 = class AgentsService {
|
|
24
|
-
constructor(agentRepository) {
|
|
25
|
+
constructor(agentRepository, moduleRef) {
|
|
25
26
|
this.agentRepository = agentRepository;
|
|
27
|
+
this.moduleRef = moduleRef;
|
|
26
28
|
this.logger = new common_1.Logger(AgentsService_1.name);
|
|
27
29
|
this.agentInstances = new Map();
|
|
28
30
|
}
|
|
@@ -34,7 +36,7 @@ let AgentsService = AgentsService_1 = class AgentsService {
|
|
|
34
36
|
for (const agentEntity of agents) {
|
|
35
37
|
if (agentEntity.status !== 'inactive') {
|
|
36
38
|
try {
|
|
37
|
-
this.syncAgentInstance(agentEntity);
|
|
39
|
+
await this.syncAgentInstance(agentEntity);
|
|
38
40
|
}
|
|
39
41
|
catch (error) {
|
|
40
42
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -44,7 +46,7 @@ let AgentsService = AgentsService_1 = class AgentsService {
|
|
|
44
46
|
}
|
|
45
47
|
this.logger.log(`Initialized ${this.agentInstances.size} agent instances.`);
|
|
46
48
|
}
|
|
47
|
-
syncAgentInstance(agentEntity) {
|
|
49
|
+
async syncAgentInstance(agentEntity) {
|
|
48
50
|
if (agentEntity.status === 'inactive') {
|
|
49
51
|
this.agentInstances.delete(agentEntity.id);
|
|
50
52
|
return;
|
|
@@ -60,13 +62,16 @@ let AgentsService = AgentsService_1 = class AgentsService {
|
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
64
|
try {
|
|
63
|
-
|
|
65
|
+
// Use resolve for TRANSIENT scoped providers. This ensures we get a fresh instance
|
|
66
|
+
// which we then configure and store in our Map (making it a singleton for this ID).
|
|
67
|
+
const instance = await this.moduleRef.resolve(AgentClass);
|
|
64
68
|
instance.updateConfig?.({
|
|
65
69
|
name: agentEntity.name,
|
|
66
70
|
description: agentEntity.description,
|
|
67
71
|
systemInstructions: agentEntity.systemInstructions,
|
|
68
72
|
role: agentEntity.role,
|
|
69
73
|
provider: providerName,
|
|
74
|
+
model: agentEntity.model?.name,
|
|
70
75
|
});
|
|
71
76
|
this.agentInstances.set(agentEntity.id, instance);
|
|
72
77
|
this.logger.debug(`Synchronized agent instance #${agentEntity.id}`);
|
|
@@ -98,7 +103,7 @@ let AgentsService = AgentsService_1 = class AgentsService {
|
|
|
98
103
|
throw new Error(`Agent #${savedAgent.id} not found immediately after save`);
|
|
99
104
|
}
|
|
100
105
|
// This will throw BadRequestException if instantiation fails, rolling back the transaction
|
|
101
|
-
this.syncAgentInstance(fullyLoadedAgent);
|
|
106
|
+
await this.syncAgentInstance(fullyLoadedAgent);
|
|
102
107
|
return fullyLoadedAgent;
|
|
103
108
|
});
|
|
104
109
|
}
|
|
@@ -134,7 +139,7 @@ let AgentsService = AgentsService_1 = class AgentsService {
|
|
|
134
139
|
throw new common_1.NotFoundException(`Agent #${id} not found`);
|
|
135
140
|
}
|
|
136
141
|
// This will throw BadRequestException if instantiation fails, rolling back the transaction
|
|
137
|
-
this.syncAgentInstance(updatedAgent);
|
|
142
|
+
await this.syncAgentInstance(updatedAgent);
|
|
138
143
|
return updatedAgent;
|
|
139
144
|
});
|
|
140
145
|
}
|
|
@@ -172,7 +177,7 @@ let AgentsService = AgentsService_1 = class AgentsService {
|
|
|
172
177
|
if (agentEntity.status === 'inactive') {
|
|
173
178
|
throw new common_1.NotFoundException(`Agent #${agentId} is currently inactive and cannot be probed.`);
|
|
174
179
|
}
|
|
175
|
-
this.syncAgentInstance(agentEntity);
|
|
180
|
+
await this.syncAgentInstance(agentEntity);
|
|
176
181
|
agent = this.agentInstances.get(agentId);
|
|
177
182
|
if (!agent) {
|
|
178
183
|
throw new common_1.NotFoundException(`Failed to initialize agent #${agentId} after database fetch`);
|
|
@@ -185,5 +190,6 @@ exports.AgentsService = AgentsService;
|
|
|
185
190
|
exports.AgentsService = AgentsService = AgentsService_1 = __decorate([
|
|
186
191
|
(0, common_1.Injectable)(),
|
|
187
192
|
__param(0, (0, typeorm_1.InjectRepository)(agent_entity_1.AgentEntity)),
|
|
188
|
-
__metadata("design:paramtypes", [typeorm_2.Repository
|
|
193
|
+
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
194
|
+
core_1.ModuleRef])
|
|
189
195
|
], AgentsService);
|
|
@@ -16,18 +16,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.ClaudeAgent = void 0;
|
|
17
17
|
const claude_agent_sdk_1 = require("@anthropic-ai/claude-agent-sdk");
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
|
+
const config_1 = require("@nestjs/config");
|
|
19
20
|
const agent_registry_1 = require("../registry/agent.registry");
|
|
20
21
|
let ClaudeAgent = ClaudeAgent_1 = class ClaudeAgent {
|
|
21
|
-
constructor(model = 'claude-opus-4-6') {
|
|
22
|
+
constructor(configService, model = 'claude-opus-4-6') {
|
|
23
|
+
this.configService = configService;
|
|
22
24
|
this.logger = new common_1.Logger(ClaudeAgent_1.name);
|
|
23
25
|
this.name = 'ClaudeAgent';
|
|
24
26
|
this.provider = 'anthropic';
|
|
25
27
|
this.model = model;
|
|
26
|
-
|
|
28
|
+
}
|
|
29
|
+
validateApiKey() {
|
|
30
|
+
const apiKey = this.configService.get('ANTHROPIC_API_KEY');
|
|
27
31
|
if (!apiKey) {
|
|
28
32
|
this.logger.error('ANTHROPIC_API_KEY environment variable is not set');
|
|
29
33
|
throw new Error('ANTHROPIC_API_KEY is required to initialize ClaudeAgent');
|
|
30
34
|
}
|
|
35
|
+
return apiKey;
|
|
31
36
|
}
|
|
32
37
|
getName() {
|
|
33
38
|
return this.name;
|
|
@@ -74,6 +79,7 @@ let ClaudeAgent = ClaudeAgent_1 = class ClaudeAgent {
|
|
|
74
79
|
.join('\n');
|
|
75
80
|
}
|
|
76
81
|
async processText(input) {
|
|
82
|
+
this.validateApiKey();
|
|
77
83
|
this.logger.debug(`Processing input with ClaudeAgent. Model: ${this.model}`);
|
|
78
84
|
try {
|
|
79
85
|
const systemPrompt = this.buildSystemPrompt();
|
|
@@ -129,8 +135,8 @@ Please perform the task and provide the output.
|
|
|
129
135
|
};
|
|
130
136
|
exports.ClaudeAgent = ClaudeAgent;
|
|
131
137
|
exports.ClaudeAgent = ClaudeAgent = ClaudeAgent_1 = __decorate([
|
|
132
|
-
(0, common_1.Injectable)(),
|
|
138
|
+
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
133
139
|
(0, agent_registry_1.RegisterAgent)('anthropic'),
|
|
134
|
-
__param(
|
|
135
|
-
__metadata("design:paramtypes", [String])
|
|
140
|
+
__param(1, (0, common_1.Optional)()),
|
|
141
|
+
__metadata("design:paramtypes", [config_1.ConfigService, String])
|
|
136
142
|
], ClaudeAgent);
|
|
@@ -16,20 +16,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.GeminiAgent = void 0;
|
|
17
17
|
const genai_1 = require("@google/genai");
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
|
+
const config_1 = require("@nestjs/config");
|
|
19
20
|
const agent_registry_1 = require("../registry/agent.registry");
|
|
20
21
|
let GeminiAgent = GeminiAgent_1 = class GeminiAgent {
|
|
21
|
-
constructor(model = 'gemini-2.5-flash-lite') {
|
|
22
|
+
constructor(configService, model = 'gemini-2.5-flash-lite') {
|
|
23
|
+
this.configService = configService;
|
|
22
24
|
this.logger = new common_1.Logger(GeminiAgent_1.name);
|
|
25
|
+
this.genAI = null;
|
|
23
26
|
this.name = 'GeminiAgent';
|
|
24
27
|
this.provider = 'google';
|
|
25
28
|
this.enableGrounding = true;
|
|
26
29
|
this.model = model;
|
|
27
|
-
|
|
30
|
+
}
|
|
31
|
+
getGenAI() {
|
|
32
|
+
if (this.genAI)
|
|
33
|
+
return this.genAI;
|
|
34
|
+
const apiKey = this.configService.get('GEMINI_API_KEY');
|
|
28
35
|
if (!apiKey) {
|
|
29
36
|
this.logger.error('GEMINI_API_KEY environment variable is not set');
|
|
30
37
|
throw new Error('GEMINI_API_KEY is required to initialize GeminiAgent');
|
|
31
38
|
}
|
|
32
39
|
this.genAI = new genai_1.GoogleGenAI({ apiKey });
|
|
40
|
+
return this.genAI;
|
|
33
41
|
}
|
|
34
42
|
getName() {
|
|
35
43
|
return this.name;
|
|
@@ -74,7 +82,8 @@ let GeminiAgent = GeminiAgent_1 = class GeminiAgent {
|
|
|
74
82
|
if (tools.length > 0) {
|
|
75
83
|
this.logger.debug(`Adding tools to request: ${JSON.stringify(tools)}`);
|
|
76
84
|
}
|
|
77
|
-
const
|
|
85
|
+
const genAI = this.getGenAI();
|
|
86
|
+
const response = await genAI.models.generateContent({
|
|
78
87
|
model: this.model,
|
|
79
88
|
contents,
|
|
80
89
|
config: {
|
|
@@ -172,8 +181,8 @@ Please perform the task and provide the output.
|
|
|
172
181
|
};
|
|
173
182
|
exports.GeminiAgent = GeminiAgent;
|
|
174
183
|
exports.GeminiAgent = GeminiAgent = GeminiAgent_1 = __decorate([
|
|
175
|
-
(0, common_1.Injectable)(),
|
|
184
|
+
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
176
185
|
(0, agent_registry_1.RegisterAgent)('google'),
|
|
177
|
-
__param(
|
|
178
|
-
__metadata("design:paramtypes", [String])
|
|
186
|
+
__param(1, (0, common_1.Optional)()),
|
|
187
|
+
__metadata("design:paramtypes", [config_1.ConfigService, String])
|
|
179
188
|
], GeminiAgent);
|
package/dist/app.module.js
CHANGED
|
@@ -22,21 +22,48 @@ const users_module_1 = require("./users/users.module");
|
|
|
22
22
|
const common_module_1 = require("./common/common.module");
|
|
23
23
|
const uploads_module_1 = require("./uploads/uploads.module");
|
|
24
24
|
const schedule_1 = require("@nestjs/schedule");
|
|
25
|
+
const config_1 = require("@nestjs/config");
|
|
26
|
+
const env_validation_1 = require("./config/env.validation");
|
|
27
|
+
const throttler_1 = require("@nestjs/throttler");
|
|
28
|
+
const core_1 = require("@nestjs/core");
|
|
29
|
+
const auth_module_1 = require("./auth/auth.module");
|
|
30
|
+
const jwt_auth_guard_1 = require("./auth/guards/jwt-auth.guard");
|
|
25
31
|
let AppModule = class AppModule {
|
|
26
32
|
};
|
|
27
33
|
exports.AppModule = AppModule;
|
|
28
34
|
exports.AppModule = AppModule = __decorate([
|
|
29
35
|
(0, common_1.Module)({
|
|
30
36
|
imports: [
|
|
37
|
+
config_1.ConfigModule.forRoot({
|
|
38
|
+
isGlobal: true,
|
|
39
|
+
validationSchema: env_validation_1.envValidationSchema,
|
|
40
|
+
}),
|
|
41
|
+
throttler_1.ThrottlerModule.forRootAsync({
|
|
42
|
+
imports: [config_1.ConfigModule],
|
|
43
|
+
inject: [config_1.ConfigService],
|
|
44
|
+
useFactory: (config) => [
|
|
45
|
+
{
|
|
46
|
+
ttl: config.get('THROTTLE_TTL') || 60000,
|
|
47
|
+
limit: config.get('THROTTLE_LIMIT') || 60,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
}),
|
|
31
51
|
schedule_1.ScheduleModule.forRoot(),
|
|
32
|
-
typeorm_1.TypeOrmModule.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
typeorm_1.TypeOrmModule.forRootAsync({
|
|
53
|
+
imports: [config_1.ConfigModule],
|
|
54
|
+
inject: [config_1.ConfigService],
|
|
55
|
+
useFactory: (configService) => {
|
|
56
|
+
const databaseUrl = configService.get('DATABASE_URL');
|
|
57
|
+
return {
|
|
58
|
+
type: databaseUrl ? 'postgres' : 'sqlite',
|
|
59
|
+
database: databaseUrl
|
|
60
|
+
? undefined
|
|
61
|
+
: (0, path_1.join)(process.cwd(), 'local.sqlite'),
|
|
62
|
+
url: databaseUrl,
|
|
63
|
+
autoLoadEntities: true,
|
|
64
|
+
synchronize: configService.get('NODE_ENV') !== 'production',
|
|
65
|
+
};
|
|
66
|
+
},
|
|
40
67
|
}),
|
|
41
68
|
serve_static_1.ServeStaticModule.forRoot({
|
|
42
69
|
rootPath: (0, path_1.join)(__dirname, '..', '..', 'ui', 'dist'),
|
|
@@ -49,8 +76,19 @@ exports.AppModule = AppModule = __decorate([
|
|
|
49
76
|
tasks_module_1.TasksModule,
|
|
50
77
|
projects_module_1.ProjectsModule,
|
|
51
78
|
users_module_1.UsersModule,
|
|
79
|
+
auth_module_1.AuthModule,
|
|
52
80
|
],
|
|
53
81
|
controllers: [app_controller_1.AppController],
|
|
54
|
-
providers: [
|
|
82
|
+
providers: [
|
|
83
|
+
app_service_1.AppService,
|
|
84
|
+
{
|
|
85
|
+
provide: core_1.APP_GUARD,
|
|
86
|
+
useClass: throttler_1.ThrottlerGuard,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
provide: core_1.APP_GUARD,
|
|
90
|
+
useClass: jwt_auth_guard_1.JwtAuthGuard,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
55
93
|
})
|
|
56
94
|
], AppModule);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AuthController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const auth_service_1 = require("./auth.service");
|
|
18
|
+
const register_dto_1 = require("./dto/register.dto");
|
|
19
|
+
const login_dto_1 = require("./dto/login.dto");
|
|
20
|
+
const public_decorator_1 = require("./decorators/public.decorator");
|
|
21
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
22
|
+
let AuthController = class AuthController {
|
|
23
|
+
constructor(authService) {
|
|
24
|
+
this.authService = authService;
|
|
25
|
+
}
|
|
26
|
+
register(registerDto) {
|
|
27
|
+
return this.authService.register(registerDto);
|
|
28
|
+
}
|
|
29
|
+
login(loginDto) {
|
|
30
|
+
return this.authService.login(loginDto);
|
|
31
|
+
}
|
|
32
|
+
getMe(req) {
|
|
33
|
+
return req.user;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.AuthController = AuthController;
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, public_decorator_1.Public)(),
|
|
39
|
+
(0, common_1.Post)('register'),
|
|
40
|
+
__param(0, (0, common_1.Body)()),
|
|
41
|
+
__metadata("design:type", Function),
|
|
42
|
+
__metadata("design:paramtypes", [register_dto_1.RegisterDto]),
|
|
43
|
+
__metadata("design:returntype", void 0)
|
|
44
|
+
], AuthController.prototype, "register", null);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, public_decorator_1.Public)(),
|
|
47
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
|
48
|
+
(0, common_1.Post)('login'),
|
|
49
|
+
__param(0, (0, common_1.Body)()),
|
|
50
|
+
__metadata("design:type", Function),
|
|
51
|
+
__metadata("design:paramtypes", [login_dto_1.LoginDto]),
|
|
52
|
+
__metadata("design:returntype", void 0)
|
|
53
|
+
], AuthController.prototype, "login", null);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, common_1.Get)('me'),
|
|
56
|
+
__param(0, (0, common_1.Request)()),
|
|
57
|
+
__metadata("design:type", Function),
|
|
58
|
+
__metadata("design:paramtypes", [Object]),
|
|
59
|
+
__metadata("design:returntype", void 0)
|
|
60
|
+
], AuthController.prototype, "getMe", null);
|
|
61
|
+
exports.AuthController = AuthController = __decorate([
|
|
62
|
+
(0, swagger_1.ApiTags)('auth'),
|
|
63
|
+
(0, common_1.Controller)('auth'),
|
|
64
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
|
65
|
+
], AuthController);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AuthModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const auth_service_1 = require("./auth.service");
|
|
12
|
+
const auth_controller_1 = require("./auth.controller");
|
|
13
|
+
const users_module_1 = require("../users/users.module");
|
|
14
|
+
const passport_1 = require("@nestjs/passport");
|
|
15
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
16
|
+
const config_1 = require("@nestjs/config");
|
|
17
|
+
const jwt_strategy_1 = require("./strategies/jwt.strategy");
|
|
18
|
+
let AuthModule = class AuthModule {
|
|
19
|
+
};
|
|
20
|
+
exports.AuthModule = AuthModule;
|
|
21
|
+
exports.AuthModule = AuthModule = __decorate([
|
|
22
|
+
(0, common_1.Module)({
|
|
23
|
+
imports: [
|
|
24
|
+
users_module_1.UsersModule,
|
|
25
|
+
passport_1.PassportModule,
|
|
26
|
+
jwt_1.JwtModule.registerAsync({
|
|
27
|
+
imports: [config_1.ConfigModule],
|
|
28
|
+
inject: [config_1.ConfigService],
|
|
29
|
+
useFactory: (configService) => ({
|
|
30
|
+
secret: configService.get('JWT_SECRET'),
|
|
31
|
+
signOptions: { expiresIn: '60m' },
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
providers: [auth_service_1.AuthService, jwt_strategy_1.JwtStrategy],
|
|
36
|
+
controllers: [auth_controller_1.AuthController],
|
|
37
|
+
exports: [auth_service_1.AuthService],
|
|
38
|
+
})
|
|
39
|
+
], AuthModule);
|
|
@@ -0,0 +1,106 @@
|
|
|
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.AuthService = void 0;
|
|
46
|
+
const common_1 = require("@nestjs/common");
|
|
47
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
48
|
+
const users_service_1 = require("../users/users.service");
|
|
49
|
+
const bcrypt = __importStar(require("bcrypt"));
|
|
50
|
+
let AuthService = class AuthService {
|
|
51
|
+
constructor(usersService, jwtService) {
|
|
52
|
+
this.usersService = usersService;
|
|
53
|
+
this.jwtService = jwtService;
|
|
54
|
+
}
|
|
55
|
+
async validateUser(userId) {
|
|
56
|
+
try {
|
|
57
|
+
const user = await this.usersService.findOne(userId);
|
|
58
|
+
if (user) {
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
60
|
+
const { password, ...result } = user;
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
async register(registerDto) {
|
|
70
|
+
const existingUser = await this.usersService.findByEmail(registerDto.email);
|
|
71
|
+
if (existingUser) {
|
|
72
|
+
throw new common_1.ConflictException('Email already in use');
|
|
73
|
+
}
|
|
74
|
+
const hashedPassword = await bcrypt.hash(registerDto.password, 10);
|
|
75
|
+
const user = await this.usersService.create({
|
|
76
|
+
...registerDto,
|
|
77
|
+
password: hashedPassword,
|
|
78
|
+
});
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
+
const { password, ...result } = user;
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
async login(loginDto) {
|
|
84
|
+
const user = await this.usersService.findByEmail(loginDto.email);
|
|
85
|
+
if (!user) {
|
|
86
|
+
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
87
|
+
}
|
|
88
|
+
if (!user.password) {
|
|
89
|
+
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
90
|
+
}
|
|
91
|
+
const isMatch = await bcrypt.compare(loginDto.password, user.password);
|
|
92
|
+
if (!isMatch) {
|
|
93
|
+
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
94
|
+
}
|
|
95
|
+
const payload = { email: user.email, sub: user.id };
|
|
96
|
+
return {
|
|
97
|
+
access_token: this.jwtService.sign(payload),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
exports.AuthService = AuthService;
|
|
102
|
+
exports.AuthService = AuthService = __decorate([
|
|
103
|
+
(0, common_1.Injectable)(),
|
|
104
|
+
__metadata("design:paramtypes", [users_service_1.UsersService,
|
|
105
|
+
jwt_1.JwtService])
|
|
106
|
+
], AuthService);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.IS_PUBLIC_KEY = 'isPublic';
|
|
6
|
+
const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
|
|
7
|
+
exports.Public = Public;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LoginDto = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class LoginDto {
|
|
15
|
+
}
|
|
16
|
+
exports.LoginDto = LoginDto;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsEmail)(),
|
|
19
|
+
(0, class_validator_1.MaxLength)(255),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], LoginDto.prototype, "email", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsString)(),
|
|
24
|
+
(0, class_validator_1.MinLength)(8),
|
|
25
|
+
(0, class_validator_1.MaxLength)(72),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], LoginDto.prototype, "password", void 0);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RegisterDto = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
class RegisterDto {
|
|
15
|
+
}
|
|
16
|
+
exports.RegisterDto = RegisterDto;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsString)(),
|
|
19
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
20
|
+
(0, class_validator_1.MaxLength)(100),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], RegisterDto.prototype, "name", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, class_validator_1.IsEmail)(),
|
|
25
|
+
(0, class_validator_1.MaxLength)(255),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], RegisterDto.prototype, "email", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_validator_1.IsString)(),
|
|
30
|
+
(0, class_validator_1.MinLength)(8),
|
|
31
|
+
(0, class_validator_1.MaxLength)(72),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], RegisterDto.prototype, "password", void 0);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.JwtAuthGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const passport_1 = require("@nestjs/passport");
|
|
16
|
+
const public_decorator_1 = require("../decorators/public.decorator");
|
|
17
|
+
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)('jwt') {
|
|
18
|
+
constructor(reflector) {
|
|
19
|
+
super();
|
|
20
|
+
this.reflector = reflector;
|
|
21
|
+
}
|
|
22
|
+
canActivate(context) {
|
|
23
|
+
const isPublic = this.reflector.getAllAndOverride(public_decorator_1.IS_PUBLIC_KEY, [
|
|
24
|
+
context.getHandler(),
|
|
25
|
+
context.getClass(),
|
|
26
|
+
]);
|
|
27
|
+
if (isPublic) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return super.canActivate(context);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.JwtAuthGuard = JwtAuthGuard;
|
|
34
|
+
exports.JwtAuthGuard = JwtAuthGuard = __decorate([
|
|
35
|
+
(0, common_1.Injectable)(),
|
|
36
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
37
|
+
], JwtAuthGuard);
|