@hamak/smart-data-dico 1.0.4 → 1.1.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.
Files changed (49) hide show
  1. package/backend/dist/server.mjs +82212 -0
  2. package/bin/cli.js +28 -17
  3. package/package.json +28 -27
  4. package/backend/package.json +0 -51
  5. package/backend/src/__tests__/integration/api.test.ts +0 -149
  6. package/backend/src/__tests__/setup.ts +0 -24
  7. package/backend/src/__tests__/utils/testUtils.ts +0 -76
  8. package/backend/src/adapters/EntityFileAdapter.ts +0 -154
  9. package/backend/src/adapters/YamlFileInfoEnricher.ts +0 -52
  10. package/backend/src/controllers/authController.ts +0 -131
  11. package/backend/src/controllers/diagramController.ts +0 -143
  12. package/backend/src/controllers/dictionaryController.ts +0 -306
  13. package/backend/src/controllers/importExportController.ts +0 -64
  14. package/backend/src/controllers/perspectiveController.ts +0 -90
  15. package/backend/src/controllers/serviceController.ts +0 -418
  16. package/backend/src/controllers/stereotypeController.ts +0 -59
  17. package/backend/src/controllers/versionController.ts +0 -226
  18. package/backend/src/kernel/config.ts +0 -43
  19. package/backend/src/middleware/auth.ts +0 -128
  20. package/backend/src/middleware/jwtAuth.ts +0 -100
  21. package/backend/src/models/Dictionary.ts +0 -38
  22. package/backend/src/models/EntitySchema.ts +0 -393
  23. package/backend/src/models/__tests__/Dictionary.test.ts +0 -92
  24. package/backend/src/models/__tests__/EntitySchema.test.ts +0 -119
  25. package/backend/src/routes/index.ts +0 -120
  26. package/backend/src/scripts/migrate-to-uuid.ts +0 -24
  27. package/backend/src/server.ts +0 -158
  28. package/backend/src/services/__mocks__/entityService.ts +0 -38
  29. package/backend/src/services/__mocks__/serviceService.ts +0 -88
  30. package/backend/src/services/__mocks__/versionService.ts +0 -38
  31. package/backend/src/services/__tests__/dictionaryService.test.ts +0 -74
  32. package/backend/src/services/diagramService.ts +0 -165
  33. package/backend/src/services/dictionaryService.ts +0 -582
  34. package/backend/src/services/entityService.ts +0 -102
  35. package/backend/src/services/exportService.ts +0 -172
  36. package/backend/src/services/importService.ts +0 -208
  37. package/backend/src/services/perspectiveService.ts +0 -276
  38. package/backend/src/services/qualityService.ts +0 -121
  39. package/backend/src/services/serviceService.ts +0 -763
  40. package/backend/src/services/stereotypeService.ts +0 -98
  41. package/backend/src/services/versionService.ts +0 -135
  42. package/backend/src/setupTests.ts +0 -12
  43. package/backend/src/utils/__mocks__/fileOperations.ts +0 -116
  44. package/backend/src/utils/fileOperations.ts +0 -602
  45. package/backend/src/utils/logger.ts +0 -38
  46. package/backend/src/utils/migration.ts +0 -254
  47. package/backend/src/utils/swagger.ts +0 -358
  48. package/backend/src/utils/uuid.ts +0 -41
  49. package/backend/tsconfig.json +0 -20
@@ -1,226 +0,0 @@
1
- import { Request, Response } from 'express';
2
- import { versionService } from '../services/versionService.js';
3
- import { logger } from '../utils/logger.js';
4
-
5
- /**
6
- * @swagger
7
- * /api/commit:
8
- * post:
9
- * summary: Commit changes to the local git repository
10
- * description: Creates a new commit with all pending changes
11
- * tags: [Version Control]
12
- * security:
13
- * - basicAuth: []
14
- * requestBody:
15
- * required: true
16
- * content:
17
- * application/json:
18
- * schema:
19
- * type: object
20
- * required:
21
- * - message
22
- * properties:
23
- * message:
24
- * type: string
25
- * description: Commit message
26
- * responses:
27
- * 200:
28
- * description: Changes committed successfully
29
- * content:
30
- * application/json:
31
- * schema:
32
- * type: object
33
- * properties:
34
- * message:
35
- * type: string
36
- * example: Changes committed successfully
37
- * data:
38
- * type: object
39
- * properties:
40
- * commitHash:
41
- * type: string
42
- * description: Hash of the new commit
43
- * commitMessage:
44
- * type: string
45
- * description: Commit message
46
- * timestamp:
47
- * type: string
48
- * format: date-time
49
- * description: Timestamp of the commit
50
- * 400:
51
- * description: Failed to commit changes
52
- * 401:
53
- * description: Unauthorized
54
- * 403:
55
- * description: Forbidden
56
- * 500:
57
- * description: Server error
58
- *
59
- * @param req Express request
60
- * @param res Express response
61
- */
62
- export const commitChanges = async (req: Request, res: Response) => {
63
- try {
64
- const { message } = req.body;
65
-
66
- if (!message) {
67
- return res.status(400).json({ message: 'Commit message is required' });
68
- }
69
-
70
- const result = await versionService.commitChanges(message);
71
-
72
- if (!result.success) {
73
- return res.status(400).json({
74
- message: 'Failed to commit changes',
75
- errors: result.errors
76
- });
77
- }
78
-
79
- res.json({
80
- message: 'Changes committed successfully',
81
- data: {
82
- commitHash: result.commitHash,
83
- commitMessage: message,
84
- timestamp: result.timestamp
85
- }
86
- });
87
- } catch (error) {
88
- logger.error(`Error committing changes: ${error}`);
89
- res.status(500).json({ message: 'Error committing changes', error });
90
- }
91
- };
92
-
93
- /**
94
- * @swagger
95
- * /api/history:
96
- * get:
97
- * summary: Get commit history
98
- * description: Returns the commit history for the repository
99
- * tags: [Version Control]
100
- * parameters:
101
- * - in: query
102
- * name: limit
103
- * schema:
104
- * type: integer
105
- * default: 10
106
- * description: Maximum number of commits to return
107
- * responses:
108
- * 200:
109
- * description: Commit history
110
- * content:
111
- * application/json:
112
- * schema:
113
- * type: object
114
- * properties:
115
- * message:
116
- * type: string
117
- * example: Success
118
- * data:
119
- * type: array
120
- * items:
121
- * $ref: '#/components/schemas/CommitInfo'
122
- * 500:
123
- * description: Server error
124
- *
125
- * @param req Express request
126
- * @param res Express response
127
- */
128
- export const getCommitHistory = async (req: Request, res: Response) => {
129
- try {
130
- const { limit } = req.query;
131
- const limitNum = limit ? parseInt(limit as string, 10) : 10;
132
-
133
- const history = await versionService.getCommitHistory(limitNum);
134
-
135
- res.json({
136
- message: 'Success',
137
- data: history
138
- });
139
- } catch (error) {
140
- logger.error(`Error fetching commit history: ${error}`);
141
- res.status(500).json({ message: 'Error fetching commit history', error });
142
- }
143
- };
144
-
145
- /**
146
- * @swagger
147
- * /api/revert:
148
- * post:
149
- * summary: Revert to a previous commit
150
- * description: Creates a new commit that reverts the changes in the specified commit
151
- * tags: [Version Control]
152
- * security:
153
- * - basicAuth: []
154
- * requestBody:
155
- * required: true
156
- * content:
157
- * application/json:
158
- * schema:
159
- * type: object
160
- * required:
161
- * - commitHash
162
- * properties:
163
- * commitHash:
164
- * type: string
165
- * description: Hash of the commit to revert
166
- * responses:
167
- * 200:
168
- * description: Successfully reverted to commit
169
- * content:
170
- * application/json:
171
- * schema:
172
- * type: object
173
- * properties:
174
- * message:
175
- * type: string
176
- * example: Successfully reverted to commit
177
- * data:
178
- * type: object
179
- * properties:
180
- * commitHash:
181
- * type: string
182
- * description: Hash of the reverted commit
183
- * newCommitHash:
184
- * type: string
185
- * description: Hash of the new revert commit
186
- * 400:
187
- * description: Failed to revert to commit
188
- * 401:
189
- * description: Unauthorized
190
- * 403:
191
- * description: Forbidden
192
- * 500:
193
- * description: Server error
194
- *
195
- * @param req Express request
196
- * @param res Express response
197
- */
198
- export const revertToCommit = async (req: Request, res: Response) => {
199
- try {
200
- const { commitHash } = req.body;
201
-
202
- if (!commitHash) {
203
- return res.status(400).json({ message: 'Commit hash is required' });
204
- }
205
-
206
- const result = await versionService.revertToCommit(commitHash);
207
-
208
- if (!result.success) {
209
- return res.status(400).json({
210
- message: 'Failed to revert to commit',
211
- errors: result.errors
212
- });
213
- }
214
-
215
- res.json({
216
- message: 'Successfully reverted to commit',
217
- data: {
218
- commitHash,
219
- newCommitHash: result.newCommitHash
220
- }
221
- });
222
- } catch (error) {
223
- logger.error(`Error reverting to commit: ${error}`);
224
- res.status(500).json({ message: 'Error reverting to commit', error });
225
- }
226
- };
@@ -1,43 +0,0 @@
1
- /**
2
- * Centralized Configuration
3
- *
4
- * Single source of truth for backend configuration values.
5
- * Reads from environment variables with sensible defaults.
6
- */
7
-
8
- import path from 'path';
9
- import dotenv from 'dotenv';
10
-
11
- dotenv.config();
12
-
13
- const isProduction = process.env.NODE_ENV === 'production';
14
-
15
- export const config = {
16
- /** Server port */
17
- port: parseInt(process.env.PORT || '3001', 10),
18
-
19
- /** Base directory for data dictionaries (YAML files) */
20
- dataDir: process.env.DATA_DIR
21
- || (isProduction
22
- ? path.join(process.cwd(), 'data-dictionaries')
23
- : path.join(process.cwd(), '..', 'data-dictionaries')),
24
-
25
- /** Deployment profile: local | team | server */
26
- profile: (process.env.PROFILE || 'local') as 'local' | 'team' | 'server',
27
-
28
- /** JWT configuration */
29
- jwt: {
30
- secret: process.env.JWT_SECRET || 'dev-secret-key',
31
- expiresIn: process.env.JWT_EXPIRES_IN || '24h',
32
- },
33
-
34
- /** Git configuration */
35
- git: {
36
- /** Whether to auto-commit on entity changes */
37
- autoCommit: process.env.GIT_AUTO_COMMIT !== 'false',
38
- },
39
-
40
- /** Environment */
41
- nodeEnv: process.env.NODE_ENV || 'development',
42
- isProduction,
43
- };
@@ -1,128 +0,0 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- import { logger } from '../utils/logger.js';
3
-
4
- // Interface for user roles
5
- export enum UserRole {
6
- ADMIN = 'admin',
7
- EDITOR = 'editor',
8
- VIEWER = 'viewer'
9
- }
10
-
11
- // Interface for user information
12
- export interface User {
13
- id: string;
14
- username: string;
15
- role: UserRole;
16
- }
17
-
18
- /**
19
- * Mock user database - in a real application, this would be stored in a database
20
- * and passwords would be hashed
21
- */
22
- const users: Record<string, { password: string; user: User }> = {
23
- 'admin': {
24
- password: 'admin123',
25
- user: {
26
- id: '1',
27
- username: 'admin',
28
- role: UserRole.ADMIN
29
- }
30
- },
31
- 'editor': {
32
- password: 'editor123',
33
- user: {
34
- id: '2',
35
- username: 'editor',
36
- role: UserRole.EDITOR
37
- }
38
- },
39
- 'viewer': {
40
- password: 'viewer123',
41
- user: {
42
- id: '3',
43
- username: 'viewer',
44
- role: UserRole.VIEWER
45
- }
46
- }
47
- };
48
-
49
- /**
50
- * Basic authentication middleware
51
- * Extracts credentials from Authorization header and validates them
52
- * @param req Express request
53
- * @param res Express response
54
- * @param next Next function
55
- */
56
- export const basicAuth = (req: Request, res: Response, next: NextFunction) => {
57
- // Get authorization header
58
- const authHeader = req.headers.authorization;
59
-
60
- if (!authHeader || !authHeader.startsWith('Basic ')) {
61
- return res.status(401).json({
62
- message: 'Authentication required',
63
- error: 'Missing or invalid Authorization header'
64
- });
65
- }
66
-
67
- // Extract and decode credentials
68
- try {
69
- const base64Credentials = authHeader.split(' ')[1];
70
- const credentials = Buffer.from(base64Credentials, 'base64').toString('utf-8');
71
- const [username, password] = credentials.split(':');
72
-
73
- // Validate credentials
74
- const userRecord = users[username];
75
-
76
- if (!userRecord || userRecord.password !== password) {
77
- return res.status(401).json({
78
- message: 'Authentication failed',
79
- error: 'Invalid username or password'
80
- });
81
- }
82
-
83
- // Add user to request object
84
- (req as any).user = userRecord.user;
85
-
86
- next();
87
- } catch (error) {
88
- logger.error(`Authentication error: ${error}`);
89
- return res.status(401).json({
90
- message: 'Authentication failed',
91
- error: 'Invalid credentials format'
92
- });
93
- }
94
- };
95
-
96
- /**
97
- * Role-based authorization middleware
98
- * Checks if the authenticated user has one of the required roles
99
- * @param allowedRoles Array of allowed roles
100
- * @returns Middleware function
101
- */
102
- export const authenticate = (allowedRoles: UserRole[]) => {
103
- return (req: Request, res: Response, next: NextFunction) => {
104
- // First apply basic authentication
105
- basicAuth(req, res, (err) => {
106
- if (err) return next(err);
107
-
108
- // Check if user has required role
109
- const user = (req as any).user as User;
110
-
111
- if (!user) {
112
- return res.status(401).json({
113
- message: 'Authentication required',
114
- error: 'User not authenticated'
115
- });
116
- }
117
-
118
- if (!allowedRoles.includes(user.role)) {
119
- return res.status(403).json({
120
- message: 'Access denied',
121
- error: 'Insufficient permissions'
122
- });
123
- }
124
-
125
- next();
126
- });
127
- };
128
- };
@@ -1,100 +0,0 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- import jwt from 'jsonwebtoken';
3
- import { logger } from '../utils/logger.js';
4
- import { User } from './auth.js';
5
-
6
- // JWT secret key - should be in environment variables in production
7
- const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key';
8
-
9
- /**
10
- * JWT authentication middleware
11
- * Verifies JWT token from Authorization header
12
- * @param req Express request
13
- * @param res Express response
14
- * @param next Next function
15
- */
16
- export const verifyToken = (req: Request, res: Response, next: NextFunction) => {
17
- // Development mode bypass for testing
18
- if (process.env.NODE_ENV === 'development' && req.headers.authorization === 'Bearer mock-token-for-testing') {
19
- logger.info('Using mock authentication token for development');
20
- // Set a mock user for development
21
- (req as any).user = {
22
- id: 'dev-user',
23
- username: 'developer',
24
- email: 'dev@example.com',
25
- role: 'admin'
26
- };
27
- return next();
28
- }
29
-
30
- // Get authorization header
31
- const authHeader = req.headers.authorization;
32
-
33
- if (!authHeader || !authHeader.startsWith('Bearer ')) {
34
- return res.status(401).json({
35
- message: 'Authentication required',
36
- error: 'Missing or invalid Authorization header'
37
- });
38
- }
39
-
40
- // Extract token
41
- const token = authHeader.split(' ')[1];
42
-
43
- try {
44
- // Verify token
45
- const decoded = jwt.verify(token, JWT_SECRET as jwt.Secret) as User;
46
-
47
- // Add user to request object
48
- (req as any).user = decoded;
49
-
50
- next();
51
- } catch (error: any) {
52
- logger.error(`JWT verification error: ${error.message}`);
53
-
54
- if (error.name === 'TokenExpiredError') {
55
- return res.status(401).json({
56
- message: 'Authentication failed',
57
- error: 'Token expired'
58
- });
59
- }
60
-
61
- return res.status(401).json({
62
- message: 'Authentication failed',
63
- error: 'Invalid token'
64
- });
65
- }
66
- };
67
-
68
- /**
69
- * Role-based authorization middleware using JWT
70
- * Checks if the authenticated user has one of the required roles
71
- * @param allowedRoles Array of allowed roles
72
- * @returns Middleware function
73
- */
74
- export const authorizeJwt = (allowedRoles: string[]) => {
75
- return (req: Request, res: Response, next: NextFunction) => {
76
- // First verify token
77
- verifyToken(req, res, (err) => {
78
- if (err) return next(err);
79
-
80
- // Check if user has required role
81
- const user = (req as any).user as User;
82
-
83
- if (!user) {
84
- return res.status(401).json({
85
- message: 'Authentication required',
86
- error: 'User not authenticated'
87
- });
88
- }
89
-
90
- if (!allowedRoles.includes(user.role)) {
91
- return res.status(403).json({
92
- message: 'Access denied',
93
- error: 'Insufficient permissions'
94
- });
95
- }
96
-
97
- next();
98
- });
99
- };
100
- };
@@ -1,38 +0,0 @@
1
- import { Entity, MetadataDefinition, MetadataEntry, Relationship } from './EntitySchema.js';
2
-
3
- /**
4
- * Package type annotation
5
- */
6
- export enum PackageType {
7
- PROJECT = 'project',
8
- MICROSERVICE = 'microservice',
9
- MODULE = 'module'
10
- }
11
-
12
- /**
13
- * Represents a hierarchical package, which can contain subpackages and/or entities.
14
- */
15
- export interface Package {
16
- id: string;
17
- name: string;
18
- description?: string;
19
- type?: PackageType | string;
20
- entities: Entity[];
21
- subPackages: Package[];
22
- relationships: Relationship[];
23
- metadata?: MetadataEntry[];
24
- }
25
-
26
- /**
27
- * Dictionary model interface.
28
- * Supports a hierarchy of packages via the rootPackage property.
29
- */
30
- export interface Dictionary {
31
- id: string;
32
- name: string;
33
- description?: string;
34
- metadataDefinitions?: MetadataDefinition[];
35
- createdAt?: Date;
36
- updatedAt?: Date;
37
- rootPackage: Package;
38
- }