@vezlo/assistant-server 1.4.0 → 2.0.0
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 +56 -4
- package/database-schema.sql +193 -33
- package/dist/knexfile.d.ts.map +1 -1
- package/dist/knexfile.js +17 -8
- package/dist/knexfile.js.map +1 -1
- package/dist/src/config/database.d.ts.map +1 -1
- package/dist/src/config/database.js +9 -1
- package/dist/src/config/database.js.map +1 -1
- package/dist/src/config/knex.d.ts.map +1 -1
- package/dist/src/config/knex.js +22 -2
- package/dist/src/config/knex.js.map +1 -1
- package/dist/src/config/swagger.d.ts.map +1 -1
- package/dist/src/config/swagger.js +18 -71
- package/dist/src/config/swagger.js.map +1 -1
- package/dist/src/controllers/ApiKeyController.d.ts +17 -0
- package/dist/src/controllers/ApiKeyController.d.ts.map +1 -0
- package/dist/src/controllers/ApiKeyController.js +84 -0
- package/dist/src/controllers/ApiKeyController.js.map +1 -0
- package/dist/src/controllers/AuthController.d.ts +14 -0
- package/dist/src/controllers/AuthController.d.ts.map +1 -0
- package/dist/src/controllers/AuthController.js +212 -0
- package/dist/src/controllers/AuthController.js.map +1 -0
- package/dist/src/controllers/ChatController.d.ts +8 -5
- package/dist/src/controllers/ChatController.d.ts.map +1 -1
- package/dist/src/controllers/ChatController.js +139 -31
- package/dist/src/controllers/ChatController.js.map +1 -1
- package/dist/src/controllers/KnowledgeController.d.ts +5 -4
- package/dist/src/controllers/KnowledgeController.d.ts.map +1 -1
- package/dist/src/controllers/KnowledgeController.js +54 -16
- package/dist/src/controllers/KnowledgeController.js.map +1 -1
- package/dist/src/middleware/auth.d.ts +51 -0
- package/dist/src/middleware/auth.d.ts.map +1 -0
- package/dist/src/middleware/auth.js +232 -0
- package/dist/src/middleware/auth.js.map +1 -0
- package/dist/src/middleware/errorHandler.d.ts.map +1 -1
- package/dist/src/middleware/errorHandler.js +13 -19
- package/dist/src/middleware/errorHandler.js.map +1 -1
- package/dist/src/migrations/001_initial_schema.d.ts.map +1 -1
- package/dist/src/migrations/001_initial_schema.js +39 -64
- package/dist/src/migrations/001_initial_schema.js.map +1 -1
- package/dist/src/migrations/002_multitenancy_schema.d.ts +4 -0
- package/dist/src/migrations/002_multitenancy_schema.d.ts.map +1 -0
- package/dist/src/migrations/002_multitenancy_schema.js +119 -0
- package/dist/src/migrations/002_multitenancy_schema.js.map +1 -0
- package/dist/src/schemas/AuthSchemas.d.ts +89 -0
- package/dist/src/schemas/AuthSchemas.d.ts.map +1 -0
- package/dist/src/schemas/AuthSchemas.js +63 -0
- package/dist/src/schemas/AuthSchemas.js.map +1 -0
- package/dist/src/schemas/CommonSchemas.d.ts +62 -0
- package/dist/src/schemas/CommonSchemas.d.ts.map +1 -0
- package/dist/src/schemas/CommonSchemas.js +65 -0
- package/dist/src/schemas/CommonSchemas.js.map +1 -0
- package/dist/src/schemas/ConversationSchemas.d.ts +64 -27
- package/dist/src/schemas/ConversationSchemas.d.ts.map +1 -1
- package/dist/src/schemas/ConversationSchemas.js +28 -9
- package/dist/src/schemas/ConversationSchemas.js.map +1 -1
- package/dist/src/schemas/FeedbackSchemas.d.ts +43 -5
- package/dist/src/schemas/FeedbackSchemas.d.ts.map +1 -1
- package/dist/src/schemas/FeedbackSchemas.js +20 -2
- package/dist/src/schemas/FeedbackSchemas.js.map +1 -1
- package/dist/src/schemas/KnowledgeSchemas.d.ts +114 -35
- package/dist/src/schemas/KnowledgeSchemas.d.ts.map +1 -1
- package/dist/src/schemas/KnowledgeSchemas.js +58 -16
- package/dist/src/schemas/KnowledgeSchemas.js.map +1 -1
- package/dist/src/schemas/MessageSchemas.d.ts +57 -8
- package/dist/src/schemas/MessageSchemas.d.ts.map +1 -1
- package/dist/src/schemas/MessageSchemas.js +22 -3
- package/dist/src/schemas/MessageSchemas.js.map +1 -1
- package/dist/src/schemas/index.d.ts +410 -68
- package/dist/src/schemas/index.d.ts.map +1 -1
- package/dist/src/schemas/index.js +8 -2
- package/dist/src/schemas/index.js.map +1 -1
- package/dist/src/server.js +1047 -613
- package/dist/src/server.js.map +1 -1
- package/dist/src/services/AIService.d.ts +1 -1
- package/dist/src/services/AIService.d.ts.map +1 -1
- package/dist/src/services/AIService.js +6 -2
- package/dist/src/services/AIService.js.map +1 -1
- package/dist/src/services/ApiKeyService.d.ts +38 -0
- package/dist/src/services/ApiKeyService.d.ts.map +1 -0
- package/dist/src/services/ApiKeyService.js +123 -0
- package/dist/src/services/ApiKeyService.js.map +1 -0
- package/dist/src/services/KnowledgeBaseService.d.ts +2 -2
- package/dist/src/services/KnowledgeBaseService.d.ts.map +1 -1
- package/dist/src/services/KnowledgeBaseService.js +9 -2
- package/dist/src/services/KnowledgeBaseService.js.map +1 -1
- package/dist/src/services/MigrationService.d.ts +1 -1
- package/dist/src/services/MigrationService.d.ts.map +1 -1
- package/dist/src/services/MigrationService.js +4 -8
- package/dist/src/services/MigrationService.js.map +1 -1
- package/dist/src/services/SetupService.d.ts +102 -0
- package/dist/src/services/SetupService.d.ts.map +1 -0
- package/dist/src/services/SetupService.js +343 -0
- package/dist/src/services/SetupService.js.map +1 -0
- package/dist/src/storage/ConversationRepository.d.ts.map +1 -1
- package/dist/src/storage/ConversationRepository.js +42 -8
- package/dist/src/storage/ConversationRepository.js.map +1 -1
- package/dist/src/storage/MessageRepository.d.ts.map +1 -1
- package/dist/src/storage/MessageRepository.js +23 -27
- package/dist/src/storage/MessageRepository.js.map +1 -1
- package/env.example +5 -0
- package/knexfile.ts +17 -8
- package/package.json +10 -2
- package/scripts/generate-key.js +124 -0
- package/scripts/seed-default.js +72 -0
- package/scripts/setup.js +148 -13
- package/scripts/validate-db.js +22 -6
|
@@ -37,83 +37,39 @@ const options = {
|
|
|
37
37
|
description: process.env.VERCEL_URL ? 'Current deployment' : 'Development server'
|
|
38
38
|
}
|
|
39
39
|
],
|
|
40
|
+
security: [
|
|
41
|
+
{
|
|
42
|
+
bearerAuth: []
|
|
43
|
+
}
|
|
44
|
+
],
|
|
40
45
|
components: {
|
|
41
46
|
schemas: {
|
|
42
47
|
// ============================================================================
|
|
43
|
-
//
|
|
48
|
+
// ALL SCHEMAS (Common and Controller-specific)
|
|
44
49
|
// ============================================================================
|
|
45
|
-
...schemas_1.AllSchemas
|
|
46
|
-
// ============================================================================
|
|
47
|
-
// COMMON/GLOBAL SCHEMAS (Keep these here)
|
|
48
|
-
// ============================================================================
|
|
49
|
-
Error: {
|
|
50
|
-
type: 'object',
|
|
51
|
-
properties: {
|
|
52
|
-
error: {
|
|
53
|
-
type: 'object',
|
|
54
|
-
properties: {
|
|
55
|
-
code: { type: 'string', description: 'Error code' },
|
|
56
|
-
message: { type: 'string', description: 'Error message' },
|
|
57
|
-
details: { type: 'object', description: 'Additional error details' },
|
|
58
|
-
timestamp: { type: 'string', format: 'date-time', description: 'Error timestamp' },
|
|
59
|
-
path: { type: 'string', description: 'Request path' },
|
|
60
|
-
method: { type: 'string', description: 'HTTP method' }
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
success: { type: 'boolean', example: false }
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
SuccessResponse: {
|
|
67
|
-
type: 'object',
|
|
68
|
-
properties: {
|
|
69
|
-
success: { type: 'boolean', example: true },
|
|
70
|
-
message: { type: 'string', description: 'Success message' },
|
|
71
|
-
data: { type: 'object', description: 'Response data' }
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
HealthCheck: {
|
|
75
|
-
type: 'object',
|
|
76
|
-
properties: {
|
|
77
|
-
status: { type: 'string', example: 'healthy' },
|
|
78
|
-
checks: {
|
|
79
|
-
type: 'object',
|
|
80
|
-
properties: {
|
|
81
|
-
server: { type: 'string', example: 'healthy' },
|
|
82
|
-
supabase: { type: 'string', example: 'connected' },
|
|
83
|
-
openai: { type: 'string', example: 'connected' },
|
|
84
|
-
timestamp: { type: 'string', format: 'date-time' }
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
uptime: { type: 'number', description: 'Server uptime in seconds' },
|
|
88
|
-
version: { type: 'string', description: 'API version' }
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
PaginationMeta: {
|
|
92
|
-
type: 'object',
|
|
93
|
-
properties: {
|
|
94
|
-
total: { type: 'integer', description: 'Total number of items' },
|
|
95
|
-
limit: { type: 'integer', description: 'Items per page' },
|
|
96
|
-
offset: { type: 'integer', description: 'Items skipped' },
|
|
97
|
-
page: { type: 'integer', description: 'Current page number' },
|
|
98
|
-
pages: { type: 'integer', description: 'Total number of pages' }
|
|
99
|
-
}
|
|
100
|
-
}
|
|
50
|
+
...schemas_1.AllSchemas
|
|
101
51
|
},
|
|
102
52
|
// ============================================================================
|
|
103
53
|
// SECURITY SCHEMES
|
|
104
54
|
// ============================================================================
|
|
105
55
|
securitySchemes: {
|
|
106
|
-
|
|
56
|
+
bearerAuth: {
|
|
107
57
|
type: 'http',
|
|
108
58
|
scheme: 'bearer',
|
|
109
59
|
bearerFormat: 'JWT',
|
|
110
|
-
description: 'JWT token for authentication'
|
|
60
|
+
description: 'JWT token for user authentication'
|
|
111
61
|
},
|
|
112
|
-
|
|
62
|
+
apiKeyAuth: {
|
|
113
63
|
type: 'apiKey',
|
|
114
64
|
in: 'header',
|
|
115
|
-
name: '
|
|
116
|
-
description: 'API key for authentication'
|
|
65
|
+
name: 'x-api-key',
|
|
66
|
+
description: 'API key for service authentication'
|
|
67
|
+
},
|
|
68
|
+
migrationKey: {
|
|
69
|
+
type: 'apiKey',
|
|
70
|
+
in: 'query',
|
|
71
|
+
name: 'key',
|
|
72
|
+
description: 'Migration secret key from MIGRATION_SECRET_KEY environment variable'
|
|
117
73
|
}
|
|
118
74
|
},
|
|
119
75
|
// ============================================================================
|
|
@@ -141,15 +97,6 @@ const options = {
|
|
|
141
97
|
default: 0
|
|
142
98
|
}
|
|
143
99
|
},
|
|
144
|
-
CompanyUuidParam: {
|
|
145
|
-
name: 'company_uuid',
|
|
146
|
-
in: 'query',
|
|
147
|
-
description: 'Filter by company UUID',
|
|
148
|
-
schema: {
|
|
149
|
-
type: 'integer',
|
|
150
|
-
default: 67890
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
100
|
},
|
|
154
101
|
// ============================================================================
|
|
155
102
|
// COMMON RESPONSES
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../src/config/swagger.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgD;AAChD,kEAAyC;AACzC,4EAA2C;
|
|
1
|
+
{"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../src/config/swagger.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgD;AAChD,kEAAyC;AACzC,4EAA2C;AAyKlC,oBAzKF,4BAAS,CAyKE;AAxKlB,qCAAkC;AAClC,wCAAwC;AAExC,6BAA6B;AAC7B,IAAA,eAAY,GAAE,CAAC;AAEf,MAAM,YAAY,GAAG,GAAG,EAAE;IACxB,wEAAwE;IACxE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC9B,CAAC;IAED,sCAAsC;IACtC,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;QAC3B,OAAO,WAAW,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;IAC7C,CAAC;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG;IACd,UAAU,EAAE;QACV,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE;YACJ,KAAK,EAAE,eAAM,CAAC,OAAO,CAAC,KAAK;YAC3B,OAAO,EAAE,eAAM,CAAC,OAAO,CAAC,OAAO;YAC/B,WAAW,EAAE,eAAM,CAAC,OAAO,CAAC,WAAW;SACxC;QACD,OAAO,EAAE;YACP;gBACE,GAAG,EAAE,YAAY,EAAE;gBACnB,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CA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,EAAC,OAAO,CAAC,CAAC;AAE9B,QAAA,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,KAAK;IACf,eAAe,EAAE,uBAAuB;IACxC,SAAS,EAAE;;;;;;;GAOV;IACD,cAAc,EAAE;QACd,YAAY,EAAE,MAAM;QACpB,MAAM,EAAE,KAAK;QACb,mBAAmB,EAAE,IAAI;QACzB,wBAAwB,EAAE,CAAC;QAC3B,uBAAuB,EAAE,CAAC;QAC1B,kBAAkB,EAAE,KAAK;QACzB,sBAAsB,EAAE,IAAI;KAC7B;CACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Response } from 'express';
|
|
2
|
+
import { ApiKeyService } from '../services/ApiKeyService';
|
|
3
|
+
import { AuthenticatedRequest } from '../middleware/auth';
|
|
4
|
+
export declare class ApiKeyController {
|
|
5
|
+
private apiKeyService;
|
|
6
|
+
constructor(apiKeyService: ApiKeyService);
|
|
7
|
+
/**
|
|
8
|
+
* Generate or update API key
|
|
9
|
+
* Only admins can generate API keys
|
|
10
|
+
*/
|
|
11
|
+
generateApiKey(req: AuthenticatedRequest, res: Response): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Get API key status
|
|
14
|
+
*/
|
|
15
|
+
getApiKeyStatus(req: AuthenticatedRequest, res: Response): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ApiKeyController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiKeyController.d.ts","sourceRoot":"","sources":["../../../src/controllers/ApiKeyController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAIxC;;;OAGG;IACG,cAAc,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC7E;;OAEG;IACG,eAAe,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CA6B/E"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
exports.ApiKeyController = void 0;
|
|
7
|
+
const logger_1 = __importDefault(require("../config/logger"));
|
|
8
|
+
class ApiKeyController {
|
|
9
|
+
constructor(apiKeyService) {
|
|
10
|
+
this.apiKeyService = apiKeyService;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generate or update API key
|
|
14
|
+
* Only admins can generate API keys
|
|
15
|
+
*/
|
|
16
|
+
async generateApiKey(req, res) {
|
|
17
|
+
try {
|
|
18
|
+
if (!req.profile) {
|
|
19
|
+
res.status(401).json({
|
|
20
|
+
success: false,
|
|
21
|
+
error: 'Not authenticated'
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Check if user is an admin
|
|
26
|
+
if (req.profile.role !== 'admin') {
|
|
27
|
+
res.status(403).json({
|
|
28
|
+
success: false,
|
|
29
|
+
error: 'Only admin users can generate API keys'
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const companyId = parseInt(req.profile.companyId);
|
|
34
|
+
const result = await this.apiKeyService.generateApiKey(companyId);
|
|
35
|
+
res.status(200).json({
|
|
36
|
+
success: true,
|
|
37
|
+
uuid: result.uuid,
|
|
38
|
+
api_key: result.apiKey,
|
|
39
|
+
message: 'API key generated successfully'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
logger_1.default.error('Error generating API key:', error);
|
|
44
|
+
res.status(500).json({
|
|
45
|
+
success: false,
|
|
46
|
+
message: 'Failed to generate API key',
|
|
47
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get API key status
|
|
53
|
+
*/
|
|
54
|
+
async getApiKeyStatus(req, res) {
|
|
55
|
+
try {
|
|
56
|
+
if (!req.profile) {
|
|
57
|
+
res.status(401).json({
|
|
58
|
+
success: false,
|
|
59
|
+
error: 'Not authenticated'
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const companyId = parseInt(req.profile.companyId);
|
|
64
|
+
const status = await this.apiKeyService.getApiKeyStatus(companyId);
|
|
65
|
+
res.status(200).json({
|
|
66
|
+
exists: status.exists,
|
|
67
|
+
uuid: status.uuid || null,
|
|
68
|
+
message: status.exists
|
|
69
|
+
? 'API key exists for this company'
|
|
70
|
+
: 'No API key exists for this company'
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
logger_1.default.error('Error getting API key status:', error);
|
|
75
|
+
res.status(500).json({
|
|
76
|
+
success: false,
|
|
77
|
+
message: 'Failed to get API key status',
|
|
78
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.ApiKeyController = ApiKeyController;
|
|
84
|
+
//# sourceMappingURL=ApiKeyController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiKeyController.js","sourceRoot":"","sources":["../../../src/controllers/ApiKeyController.ts"],"names":[],"mappings":";;;;;;AAGA,8DAAsC;AAGtC,MAAa,gBAAgB;IAG3B,YAAY,aAA4B;QACtC,IAAI,CAAC,aAAa,GAAG,aAAa,CA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C;QACL,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,GAAyB,EAAE,GAAa;QAC5D,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;gBACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACnB,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,mBAAmB;iBAC3B,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YAED,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;YAEnE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI;gBACzB,OAAO,EAAE,MAAM,CAAC,MAAM;oBACpB,CAAC,CAAC,iCAAiC;oBACnC,CAAC,CAAC,oCAAoC;aACzC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,gBAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;YACrD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,8BAA8B;gBACvC,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAjFD,4CAiFC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
export declare class AuthController {
|
|
3
|
+
private supabase;
|
|
4
|
+
constructor(supabase: SupabaseClient);
|
|
5
|
+
login(req: any, res: any): Promise<void>;
|
|
6
|
+
logout(req: any, res: any): Promise<void>;
|
|
7
|
+
getMe(req: any, res: any): Promise<void>;
|
|
8
|
+
private getUserById;
|
|
9
|
+
private getProfileById;
|
|
10
|
+
private getUserByEmail;
|
|
11
|
+
private getProfilesByUserId;
|
|
12
|
+
private updateUserTokenUpdatedAt;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=AuthController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthController.d.ts","sourceRoot":"","sources":["../../../src/controllers/AuthController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAiB;gBAErB,QAAQ,EAAE,cAAc;IAK9B,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DxC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBzC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;YA+BhC,WAAW;YAcX,cAAc;YAsBd,cAAc;YAcd,mBAAmB;YAsBnB,wBAAwB;CAUvC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.AuthController = void 0;
|
|
40
|
+
const auth_1 = require("../middleware/auth");
|
|
41
|
+
const logger_1 = __importDefault(require("../config/logger"));
|
|
42
|
+
class AuthController {
|
|
43
|
+
constructor(supabase) {
|
|
44
|
+
this.supabase = supabase;
|
|
45
|
+
}
|
|
46
|
+
// Login endpoint
|
|
47
|
+
async login(req, res) {
|
|
48
|
+
try {
|
|
49
|
+
const { email, password } = req.body;
|
|
50
|
+
if (!email || !password) {
|
|
51
|
+
res.status(400).json({ error: 'email and password are required' });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Get user by email
|
|
55
|
+
const user = await this.getUserByEmail(email);
|
|
56
|
+
if (!user) {
|
|
57
|
+
res.status(401).json({ error: 'Invalid credentials' });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Verify password
|
|
61
|
+
const isPasswordValid = await auth_1.PasswordUtils.compare(password, user.password_hash);
|
|
62
|
+
if (!isPasswordValid) {
|
|
63
|
+
res.status(401).json({ error: 'Invalid credentials' });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Get user's profiles
|
|
67
|
+
const profiles = await this.getProfilesByUserId(user.id.toString());
|
|
68
|
+
if (profiles.length === 0) {
|
|
69
|
+
res.status(401).json({ error: 'User has no active company profiles' });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Use first profile (default to first available company)
|
|
73
|
+
const selectedProfile = profiles[0];
|
|
74
|
+
// Generate token
|
|
75
|
+
const { JWTUtils } = await Promise.resolve().then(() => __importStar(require('../middleware/auth')));
|
|
76
|
+
const accessToken = JWTUtils.generateToken(selectedProfile.id.toString(), user.id.toString(), selectedProfile.company_id.toString(), user.token_updated_at, selectedProfile.role);
|
|
77
|
+
res.json({
|
|
78
|
+
access_token: accessToken
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
logger_1.default.error('Login error:', error);
|
|
83
|
+
res.status(500).json({
|
|
84
|
+
error: 'Failed to login',
|
|
85
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Logout endpoint
|
|
90
|
+
async logout(req, res) {
|
|
91
|
+
try {
|
|
92
|
+
if (!req.user) {
|
|
93
|
+
res.status(401).json({ error: 'Not authenticated' });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Update token_updated_at to invalidate all tokens
|
|
97
|
+
await this.updateUserTokenUpdatedAt(req.user.id);
|
|
98
|
+
res.json({
|
|
99
|
+
success: true,
|
|
100
|
+
message: 'Logged out successfully'
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
logger_1.default.error('Logout error:', error);
|
|
105
|
+
res.status(500).json({
|
|
106
|
+
error: 'Failed to logout',
|
|
107
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Get current user info
|
|
112
|
+
async getMe(req, res) {
|
|
113
|
+
try {
|
|
114
|
+
if (!req.user || !req.profile) {
|
|
115
|
+
res.status(401).json({ error: 'Not authenticated' });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
res.json({
|
|
119
|
+
user: {
|
|
120
|
+
uuid: req.user.uuid,
|
|
121
|
+
email: req.user.email,
|
|
122
|
+
name: req.user.name
|
|
123
|
+
},
|
|
124
|
+
profile: {
|
|
125
|
+
uuid: req.profile.uuid,
|
|
126
|
+
company_uuid: req.profile.companyUuid,
|
|
127
|
+
company_name: req.profile.companyName,
|
|
128
|
+
role: req.profile.role
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
logger_1.default.error('Get me error:', error);
|
|
134
|
+
res.status(500).json({
|
|
135
|
+
error: 'Failed to get user info',
|
|
136
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Helper methods
|
|
141
|
+
async getUserById(userId) {
|
|
142
|
+
const { data, error } = await this.supabase
|
|
143
|
+
.from('vezlo_users')
|
|
144
|
+
.select('*')
|
|
145
|
+
.eq('id', userId)
|
|
146
|
+
.single();
|
|
147
|
+
if (error || !data) {
|
|
148
|
+
throw new Error('User not found');
|
|
149
|
+
}
|
|
150
|
+
return data;
|
|
151
|
+
}
|
|
152
|
+
async getProfileById(profileId) {
|
|
153
|
+
const { data, error } = await this.supabase
|
|
154
|
+
.from('vezlo_user_company_profiles')
|
|
155
|
+
.select(`
|
|
156
|
+
*,
|
|
157
|
+
companies:company_id (
|
|
158
|
+
id,
|
|
159
|
+
uuid,
|
|
160
|
+
name,
|
|
161
|
+
domain
|
|
162
|
+
)
|
|
163
|
+
`)
|
|
164
|
+
.eq('id', profileId)
|
|
165
|
+
.single();
|
|
166
|
+
if (error || !data) {
|
|
167
|
+
throw new Error('Profile not found');
|
|
168
|
+
}
|
|
169
|
+
return data;
|
|
170
|
+
}
|
|
171
|
+
async getUserByEmail(email) {
|
|
172
|
+
const { data, error } = await this.supabase
|
|
173
|
+
.from('vezlo_users')
|
|
174
|
+
.select('*')
|
|
175
|
+
.eq('email', email)
|
|
176
|
+
.single();
|
|
177
|
+
if (error || !data) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return data;
|
|
181
|
+
}
|
|
182
|
+
async getProfilesByUserId(userId) {
|
|
183
|
+
const { data, error } = await this.supabase
|
|
184
|
+
.from('vezlo_user_company_profiles')
|
|
185
|
+
.select(`
|
|
186
|
+
*,
|
|
187
|
+
companies:company_id (
|
|
188
|
+
id,
|
|
189
|
+
uuid,
|
|
190
|
+
name,
|
|
191
|
+
domain
|
|
192
|
+
)
|
|
193
|
+
`)
|
|
194
|
+
.eq('user_id', userId)
|
|
195
|
+
.eq('status', 'active');
|
|
196
|
+
if (error) {
|
|
197
|
+
throw new Error('Failed to fetch profiles');
|
|
198
|
+
}
|
|
199
|
+
return data || [];
|
|
200
|
+
}
|
|
201
|
+
async updateUserTokenUpdatedAt(userId) {
|
|
202
|
+
const { error } = await this.supabase
|
|
203
|
+
.from('vezlo_users')
|
|
204
|
+
.update({ token_updated_at: new Date().toISOString() })
|
|
205
|
+
.eq('id', userId);
|
|
206
|
+
if (error) {
|
|
207
|
+
throw new Error('Failed to update token timestamp');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.AuthController = AuthController;
|
|
212
|
+
//# sourceMappingURL=AuthController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthController.js","sourceRoot":"","sources":["../../../src/controllers/AuthController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6CAAmD;AACnD,8DAAsC;AAEtC,MAAa,cAAc;IAGzB,YAAY,QAAwB;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,iBAAiB;IACjB,KAAK,CAAC,KAAK,CAAC,GAAQ,EAAE,GAAQ;QAC5B,IAAI,CAAC;YACH,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;YAErC,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACxB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,iCAAiC,EAAE,CAAC,CAAC;gBACnE,OAAO;YACT,CAAC;YAED,oBAAoB;YACpB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC9C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;gBACvD,OAAO;YACT,CAAC;YAED,kBAAkB;YAClB,MAAM,eAAe,GAAG,MAAM,oBAAa,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YAClF,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;gBACvD,OAAO;YACT,CAAC;YAED,sBAAsB;YACtB,MAAM,QAAQ,GA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abase/supabase-js';
|
|
2
3
|
import { ChatManager } from '../services/ChatManager';
|
|
3
4
|
import { UnifiedStorage } from '../storage/UnifiedStorage';
|
|
5
|
+
import { AuthenticatedRequest } from '../middleware/auth';
|
|
4
6
|
export declare class ChatController {
|
|
5
7
|
private chatManager;
|
|
6
8
|
private storage;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
private supabase;
|
|
10
|
+
constructor(chatManager: ChatManager, storage: UnifiedStorage, supabase: SupabaseClient);
|
|
11
|
+
createConversation(req: AuthenticatedRequest, res: Response): Promise<void>;
|
|
9
12
|
createUserMessage(req: Request, res: Response): Promise<void>;
|
|
10
|
-
generateResponse(req:
|
|
13
|
+
generateResponse(req: AuthenticatedRequest, res: Response): Promise<void>;
|
|
11
14
|
getConversation(req: Request, res: Response): Promise<void>;
|
|
12
|
-
getUserConversations(req:
|
|
15
|
+
getUserConversations(req: AuthenticatedRequest, res: Response): Promise<void>;
|
|
13
16
|
deleteConversation(req: Request, res: Response): Promise<void>;
|
|
14
|
-
submitFeedback(req:
|
|
17
|
+
submitFeedback(req: AuthenticatedRequest, res: Response): Promise<void>;
|
|
15
18
|
}
|
|
16
19
|
//# sourceMappingURL=ChatController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatController.d.ts","sourceRoot":"","sources":["../../../src/controllers/ChatController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"ChatController.d.ts","sourceRoot":"","sources":["../../../src/controllers/ChatController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,O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