@l10nmonster/server 3.0.0-alpha.1 → 3.0.0-alpha.11

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 (43) hide show
  1. package/.releaserc.json +31 -0
  2. package/CHANGELOG.md +6 -0
  3. package/CLAUDE.md +740 -0
  4. package/README.md +90 -23
  5. package/index.js +111 -33
  6. package/package.json +38 -10
  7. package/routes/dispatcher.js +77 -0
  8. package/routes/info.js +24 -0
  9. package/routes/providers.js +19 -0
  10. package/routes/sources.js +14 -0
  11. package/routes/status.js +30 -0
  12. package/routes/tm.js +71 -0
  13. package/ui/dist/assets/Cart-jHOAGjwC.js +1 -0
  14. package/ui/dist/assets/Job-vnJpBXcp.js +1 -0
  15. package/ui/dist/assets/Providers-DUp_y6mi.js +1 -0
  16. package/ui/dist/assets/Sources-CC5dBiir.js +1 -0
  17. package/ui/dist/assets/Status-SRPm28Cg.js +1 -0
  18. package/ui/dist/assets/StatusDetail-DqXzi16U.js +1 -0
  19. package/ui/dist/assets/TM-CUqywRKC.js +1 -0
  20. package/ui/dist/assets/TMDetail-Bl4xHL_X.js +1 -0
  21. package/ui/dist/assets/Welcome-D33rOKBc.js +1 -0
  22. package/ui/dist/assets/api-CQ_emPlI.js +1 -0
  23. package/ui/dist/assets/badge-D0XxOmqE.js +1 -0
  24. package/ui/dist/assets/grid-c9ySqPWI.js +1 -0
  25. package/ui/dist/assets/index-BHll-Wur.js +1 -0
  26. package/ui/dist/assets/index-CE6JgXwC.js +76 -0
  27. package/ui/dist/assets/input-C_b-hL0i.js +1 -0
  28. package/ui/dist/assets/link-BJrTt4Ej.js +1 -0
  29. package/ui/dist/assets/namespace-DqVzlNZ0.js +1 -0
  30. package/ui/dist/assets/select-B7OxVhQ5.js +1 -0
  31. package/ui/dist/assets/tooltip-DsbPmc5I.js +1 -0
  32. package/ui/dist/assets/use-field-context-DPgnX2eS.js +1 -0
  33. package/ui/dist/assets/use-presence-context-w7qGDwCc.js +1 -0
  34. package/ui/dist/assets/useQuery-DJATtsyt.js +1 -0
  35. package/ui/dist/assets/v-stack-BLV93Nj6.js +1 -0
  36. package/ui/dist/favicon.ico +0 -0
  37. package/ui/dist/index.html +1 -1
  38. package/ui/dist/logo.svg +123 -0
  39. package/ui/dist/manifest.json +3 -8
  40. package/mockData.js +0 -67
  41. package/ui/dist/assets/index-DexglpRr.js +0 -253
  42. package/ui/dist/logo192.png +0 -0
  43. package/ui/dist/logo512.png +0 -0
package/README.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  L10n Monster Manager UI - Web-based interface for managing localization projects and translation workflows.
4
4
 
5
+ ## How It Works
6
+
7
+ The L10n Monster server is implemented as an **action** in the L10n Monster CLI. When you run `l10n serve --ui`, it:
8
+
9
+ 1. **Starts an Express server** that connects to the current L10n Monster project
10
+ 2. **Serves real-time data** from your project's translation memory and source files
11
+ 3. **Optionally serves the web UI** (when `--ui` flag is used) from pre-built static files
12
+
13
+ ### Important: This is NOT a standalone server
14
+ - The server must be run from within a L10n Monster project directory (where `l10nmonster.config.mjs` exists)
15
+ - It accesses the project's MonsterManager instance (`mm`) to fetch real translation data
16
+ - The API endpoints return actual project data, not mock data
17
+
5
18
  ## Installation
6
19
 
7
20
  ```bash
@@ -10,76 +23,128 @@ npm install @l10nmonster/server
10
23
 
11
24
  ## Usage
12
25
 
13
- Start the server with API only:
26
+ ### From within a L10n Monster project:
14
27
 
15
28
  ```bash
16
- l10n serve --port 9691
29
+ # Navigate to your l10nmonster project directory
30
+ cd samples/CardboardSDK/l10nmonster
31
+
32
+ # Start the server with API only
33
+ npx l10n serve --port 9691
34
+
35
+ # Start the server with web UI
36
+ npx l10n serve --port 9691 --ui
17
37
  ```
18
38
 
19
- Start the server with web UI:
39
+ ## Building the UI
40
+
41
+ The UI must be built before it can be served:
20
42
 
21
43
  ```bash
22
- l10n serve --port 9691 --ui
44
+ cd server
45
+ npm install
46
+ npm run build
23
47
  ```
24
48
 
49
+ This creates the `ui/dist` directory with the built static files.
50
+
25
51
  ## Features
26
52
 
27
53
  ### Web UI
28
54
 
29
55
  Modern React-based interface built with:
30
- - **Material-UI**: Professional design system
56
+ - **Chakra UI 3.0**: Modern component library with excellent performance
57
+ - **React 19**: Latest React with improved performance
58
+ - **TypeScript**: Type-safe development
31
59
  - **React Router**: Client-side routing
32
60
  - **Vite**: Fast development and build tooling
33
61
  - **Responsive Design**: Works on desktop and mobile
34
62
 
35
63
  ### API Endpoints
36
64
 
37
- - `GET /api/status` - Translation status and project overview
38
- - `GET /api/untranslated/:sourceLang/:targetLang` - Untranslated content for language pairs
39
- - `GET /api/tm/stats/:sourceLang/:targetLang` - Translation memory statistics
65
+ All endpoints return **real project data** from the MonsterManager instance:
66
+
67
+ - `GET /api/status` - Real-time translation status from `mm.getTranslationStatus()`
68
+ - `GET /api/untranslated/:sourceLang/:targetLang` - Actual untranslated content (currently using mock data, needs implementation)
69
+ - `GET /api/tm/stats/:sourceLang/:targetLang` - Translation memory statistics (currently using mock data, needs implementation)
40
70
 
41
71
  ### Pages
42
72
 
43
- - **Home**: Project overview and status dashboard
73
+ - **Home**: Project overview with real translation status
44
74
  - **Untranslated**: Browse untranslated content by language pair
45
- - **Translation Memory**: View and manage translation memory statistics
75
+ - **Translation Memory**: View translation memory statistics
46
76
  - **404**: Error handling for unknown routes
47
77
 
48
78
  ## Development
49
79
 
50
- ### Start Development Server
80
+ ### Prerequisites
51
81
 
82
+ 1. Build the UI first:
52
83
  ```bash
53
- npm run dev
84
+ cd server
85
+ npm install
86
+ npm run build
54
87
  ```
55
88
 
89
+ 2. Run from a L10n Monster project:
90
+ ```bash
91
+ cd your-project/l10nmonster
92
+ npx l10n serve --ui
93
+ ```
94
+
95
+ ### Development Mode
96
+
97
+ For UI development with hot reload:
98
+
99
+ ```bash
100
+ cd server
101
+ npm run dev # Runs Vite dev server on port 5173
102
+ ```
103
+
104
+ Note: In development mode, the Vite dev server proxies API calls to `http://localhost:9691`, so you need the L10n Monster server running.
105
+
56
106
  ### Build for Production
57
107
 
58
108
  ```bash
109
+ cd server
59
110
  npm run build
60
111
  ```
61
112
 
62
- ### Preview Production Build
113
+ ### Run Tests
63
114
 
64
115
  ```bash
65
- npm run preview
116
+ # Frontend tests
117
+ npm run test
118
+
119
+ # Server tests
120
+ npm run test:server
121
+
122
+ # Test coverage
123
+ npm run test:coverage
66
124
  ```
67
125
 
68
126
  ## Configuration
69
127
 
70
128
  The server supports:
71
- - **Custom Port**: Specify listening port with `--port` option
129
+ - **Custom Port**: Specify listening port with `--port` option (default: 9691)
72
130
  - **UI Toggle**: Enable/disable web interface with `--ui` flag
73
131
  - **CORS**: Cross-Origin Resource Sharing enabled for API access
74
- - **Static Serving**: Production-ready static file serving
132
+ - **Static Serving**: Production-ready static file serving from `ui/dist`
75
133
 
76
134
  ## Architecture
77
135
 
78
- - **Express.js**: Backend API server
136
+ ### Backend (index.js)
137
+ - Implemented as a L10n Monster action class
138
+ - Receives MonsterManager instance (`mm`) with access to project data
139
+ - Express.js server with API routes
140
+ - Serves static UI files when `--ui` flag is used
141
+
142
+ ### Frontend (ui/)
79
143
  - **React 19**: Modern frontend framework
80
- - **Material-UI v7**: Component library and theming
144
+ - **Chakra UI 3.0**: High-performance component library
145
+ - **TypeScript**: Type safety throughout
146
+ - **Vite**: Build tool and development server
81
147
  - **Client-Side Routing**: Single-page application with React Router
82
- - **Mock Data**: Development-friendly mock data system
83
148
 
84
149
  ## Dependencies
85
150
 
@@ -89,13 +154,15 @@ The server supports:
89
154
  - `open`: Automatic browser launching
90
155
 
91
156
  ### Frontend
92
- - `react` & `react-dom`: Core React libraries
93
- - `@mui/material` & `@mui/icons-material`: Material Design components
94
- - `@emotion/react` & `@emotion/styled`: CSS-in-JS styling
157
+ - `react` & `react-dom`: Core React libraries (v19)
158
+ - `@chakra-ui/react`: Chakra UI 3.0 components
159
+ - `lucide-react`: Modern icon library
95
160
  - `react-router-dom`: Client-side routing
161
+ - `typescript`: Type-safe development
96
162
 
97
163
  ### Development
98
164
  - `vite`: Build tool and development server
99
165
  - `@vitejs/plugin-react`: React integration for Vite
100
166
  - `vitest`: Testing framework
101
- - `@testing-library/*`: React testing utilities
167
+ - `@testing-library/*`: React testing utilities
168
+ - `eslint` & `prettier`: Code quality tools
package/index.js CHANGED
@@ -2,19 +2,31 @@ import express from 'express';
2
2
  import cors from 'cors';
3
3
  import path from 'path';
4
4
  import open from 'open';
5
- import * as mockData from './mockData.js'; // Import named exports, add .js extension
5
+ import os from 'os';
6
+ import { readFileSync } from 'fs';
7
+ import { setupInfoRoute } from './routes/info.js';
8
+ import { setupStatusRoute } from './routes/status.js';
9
+ import { setupActiveContentStatsRoute } from './routes/sources.js';
10
+ import { setupTmRoutes } from './routes/tm.js';
11
+ import { setupProviderRoute } from './routes/providers.js';
12
+ import { setupDispatcherRoutes } from './routes/dispatcher.js';
13
+
14
+ const serverPackage = JSON.parse(readFileSync(path.join(import.meta.dirname, 'package.json'), 'utf-8'));
6
15
 
7
16
  export default class serve {
8
17
  static help = {
9
18
  description: 'starts the L10n Monster server.',
10
19
  options: [
11
- [ '--port <number>', 'listen to specified port' ],
20
+ [ '--host <address>', 'hostname/IP to bind to and open in browser (default: all interfaces)' ],
21
+ [ '--port <number>', 'listen to specified port (default: 9691)' ],
12
22
  [ '--ui', 'also serve a web frontend' ],
23
+ [ '--open', 'open browser with web frontend' ],
13
24
  ]
14
25
  };
15
26
 
16
27
  static async action(mm, options) {
17
28
  const port = options.port ?? 9691;
29
+ const host = options.host; // undefined means listen on all interfaces
18
30
  const app = express();
19
31
 
20
32
  // === Middleware ===
@@ -23,47 +35,113 @@ export default class serve {
23
35
 
24
36
  // === API Routes ===
25
37
  const apiRouter = express.Router();
26
-
27
- // GET /api/status
28
- apiRouter.get('/status', async (req, res) => {
29
- try {
30
- const status = await mm.getTranslationStatus()
31
- res.json(status);
32
- } catch (error) {
33
- console.error('Error fetching status: ', error);
34
- res.status(500).json({ message: 'Problems fetching status data' });
35
- }
36
- });
37
-
38
- // GET /api/untranslated/:sourceLang/:targetLang
39
- apiRouter.get('/untranslated/:sourceLang/:targetLang', (req, res) => {
40
- const { sourceLang, targetLang } = req.params;
41
- const pairKey = `${sourceLang}_${targetLang}`;
42
- const content = mockData.untranslatedContent[pairKey] || [];
43
- res.json(content);
44
- });
45
-
46
- // GET /api/tm/stats/:sourceLang/:targetLang
47
- apiRouter.get('/tm/stats/:sourceLang/:targetLang', (req, res) => {
48
- const { sourceLang, targetLang } = req.params;
49
- const pairKey = `${sourceLang}_${targetLang}`;
50
- const tmInfo = mockData.tmData[pairKey] || { summary: { totalUnits: 0, lastUpdated: 'N/A' }, units: [] };
51
- res.json(tmInfo);
52
- });
38
+
39
+ // Setup routes from separate files
40
+ setupInfoRoute(apiRouter, mm, serverPackage);
41
+ setupStatusRoute(apiRouter, mm);
42
+ setupActiveContentStatsRoute(apiRouter, mm);
43
+ setupTmRoutes(apiRouter, mm);
44
+ setupProviderRoute(apiRouter, mm);
45
+ setupDispatcherRoutes(apiRouter, mm);
53
46
 
54
47
  // Mount the API router under the /api prefix
55
48
  app.use('/api', apiRouter);
56
49
 
57
- if (options.ui) {
50
+ // API 404 handler - must come before the UI catch-all
51
+ app.use('/api/*splat', (req, res) => {
52
+ res.status(404).json({
53
+ error: 'API endpoint not found',
54
+ path: req.path,
55
+ method: req.method
56
+ });
57
+ });
58
+
59
+ if (options.ui || options.open) {
58
60
  const uiDistPath = path.join(import.meta.dirname, 'ui', 'dist');
59
61
  app.use(express.static(uiDistPath)); // rest of dist files
60
62
  app.get('/*splat', (req, res) => res.sendFile(path.join(uiDistPath, 'index.html'))); // fallback for Client-Side Routing
61
63
  }
62
64
 
63
65
  // === Start Server ===
64
- app.listen(port, async () => {
65
- console.log(`🚀 L10n Monster Server listening on port ${port}`);
66
- options.ui && await open(`http://localhost:${port}`);
66
+ const listenArgs = [port];
67
+ if (host) {
68
+ listenArgs.push(host);
69
+ }
70
+
71
+ const server = app.listen(...listenArgs, async () => {
72
+ const address = server.address();
73
+
74
+ console.log(`🚀 L10n Monster Server v${serverPackage.version} started\n`);
75
+
76
+ // Handle Unix domain sockets (string) vs TCP sockets (AddressInfo)
77
+ if (typeof address === 'string') {
78
+ console.log(' Listening on Unix socket:');
79
+ console.log(` - ${address}`);
80
+
81
+ if (options.open && options.ui) {
82
+ console.log('\n ⚠️ Cannot open browser for Unix domain socket. Please access the server manually.');
83
+ }
84
+ } else {
85
+ const boundPort = address.port;
86
+ const boundAddress = address.address;
87
+
88
+ console.log(' Available at:');
89
+
90
+ // Determine what URLs to show and what to open
91
+ let openHost = host || 'localhost'; // Default to localhost for opening
92
+
93
+ // If listening on all interfaces (0.0.0.0 or ::)
94
+ if (!host || boundAddress === '0.0.0.0' || boundAddress === '::') {
95
+ // Show localhost first
96
+ console.log(` - http://localhost:${boundPort}`);
97
+ console.log(` - http://127.0.0.1:${boundPort}`);
98
+
99
+ // Get all network interfaces
100
+ const interfaces = os.networkInterfaces();
101
+ for (const [name, addresses] of Object.entries(interfaces)) {
102
+ for (const addr of addresses) {
103
+ // Skip internal interfaces and IPv6 link-local addresses
104
+ if (!addr.internal && addr.family === 'IPv4') {
105
+ console.log(` - http://${addr.address}:${boundPort} (${name})`);
106
+ }
107
+ }
108
+ }
109
+ } else {
110
+ // Specific address was bound
111
+ openHost = boundAddress; // Use the bound address for opening
112
+ console.log(` - http://${boundAddress}:${boundPort}`);
113
+
114
+ // Also show localhost if we bound to 127.0.0.1
115
+ if (boundAddress === '127.0.0.1') {
116
+ console.log(` - http://localhost:${boundPort}`);
117
+ }
118
+ }
119
+
120
+ if (options.open) {
121
+ const openUrl = `http://${openHost}:${boundPort}`;
122
+ console.log('');
123
+ console.log(` Opening browser at: ${openUrl}`);
124
+ await open(openUrl);
125
+ }
126
+ }
127
+ console.log('');
67
128
  });
129
+
130
+ // Handle server binding errors
131
+ server.on('error', (error) => {
132
+ if (error.code === 'EADDRINUSE') {
133
+ const addressStr = host ? `${host}:${port}` : `port ${port}`;
134
+ throw new Error(`Failed to bind server: Address ${addressStr} is already in use`);
135
+ } else if (error.code === 'EACCES') {
136
+ const addressStr = host ? `${host}:${port}` : `port ${port}`;
137
+ throw new Error(`Failed to bind server: Permission denied for ${addressStr}`);
138
+ } else if (error.code === 'EADDRNOTAVAIL') {
139
+ throw new Error(`Failed to bind server: Address ${host} is not available on this system`);
140
+ } else {
141
+ throw new Error(`Failed to bind server: ${error.message}`);
142
+ }
143
+ });
144
+
145
+ return server;
68
146
  }
69
147
  }
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@l10nmonster/server",
3
- "version": "3.0.0-alpha.1",
4
- "description": "L10n Monster Manager UI",
3
+ "version": "3.0.0-alpha.11",
4
+ "description": "L10n Monster Manager",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "dependencies": {
8
+ "@chakra-ui/react": "^3.2.0",
8
9
  "@emotion/react": "^11.14.0",
9
- "@emotion/styled": "^11.14.0",
10
- "@mui/icons-material": "^7.0.2",
11
- "@mui/material": "^7.0.2",
12
- "@testing-library/dom": "^10.4.0",
13
- "@testing-library/user-event": "^14",
10
+ "@tanstack/react-query": "^5.85.5",
14
11
  "cors": "^2.8.5",
15
- "dotenv": "^16.5.0",
12
+ "dotenv": "^17",
16
13
  "express": "^5.1.0",
14
+ "lucide-react": "^0.525.0",
15
+ "next-themes": "^0.4.6",
17
16
  "open": "^10.1.1",
18
17
  "react": "^19.1.0",
19
18
  "react-dom": "^19.1.0",
19
+ "react-icons": "^5.5.0",
20
20
  "react-router-dom": "^7.5.2",
21
21
  "web-vitals": "^5"
22
22
  },
@@ -24,7 +24,15 @@
24
24
  "dev": "vite",
25
25
  "build": "vite build",
26
26
  "preview": "vite preview",
27
- "test": "node --test"
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
29
+ "test:ui": "vitest --ui",
30
+ "test:coverage": "vitest run --coverage",
31
+ "test:server": "node --test test/*.js",
32
+ "lint": "eslint .",
33
+ "lint:fix": "eslint . --fix",
34
+ "format": "prettier --write \"ui/src/**/*.{js,jsx,ts,tsx,json,css,md}\"",
35
+ "type-check": "tsc --noEmit"
28
36
  },
29
37
  "eslintConfig": {
30
38
  "extends": [
@@ -45,11 +53,31 @@
45
53
  ]
46
54
  },
47
55
  "devDependencies": {
56
+ "@testing-library/dom": "^10.4.0",
48
57
  "@testing-library/jest-dom": "^6.6.3",
49
58
  "@testing-library/react": "^16.3.0",
59
+ "@testing-library/user-event": "^14.5.2",
60
+ "@types/react": "^19.0.6",
61
+ "@types/react-dom": "^19.0.2",
62
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
63
+ "@typescript-eslint/parser": "^8.0.0",
50
64
  "@vitejs/plugin-react": "^4.4.1",
65
+ "@vitest/coverage-v8": "^3.1.2",
66
+ "@vitest/ui": "^3.1.2",
67
+ "eslint": "^9",
68
+ "eslint-config-prettier": "^10",
69
+ "eslint-plugin-prettier": "^5.0.0",
70
+ "eslint-plugin-react": "^7.35.0",
71
+ "eslint-plugin-react-hooks": "^5",
51
72
  "jsdom": "^26.1.0",
52
- "vite": "^6.3.3",
73
+ "prettier": "^3.5.0",
74
+ "supertest": "^7.0.0",
75
+ "typescript": "^5.7.3",
76
+ "vite": "^7",
77
+ "vite-tsconfig-paths": "^5.1.4",
53
78
  "vitest": "^3.1.2"
79
+ },
80
+ "engines": {
81
+ "node": ">=22.11.0"
54
82
  }
55
83
  }
@@ -0,0 +1,77 @@
1
+ import { logInfo, logVerbose } from '@l10nmonster/core';
2
+
3
+ export function setupDispatcherRoutes(router, mm) {
4
+ router.post('/dispatcher/createJobs', async (req, res) => {
5
+ logInfo`/dispatcher/createJobs`;
6
+
7
+ try {
8
+ const { sourceLang, targetLang, tus, providerList } = req.body;
9
+
10
+ // Validate required parameters
11
+ if (!sourceLang || !targetLang || !tus || !providerList) {
12
+ return res.status(400).json({
13
+ error: 'Missing required parameters: sourceLang, targetLang, tus, providerList'
14
+ });
15
+ }
16
+
17
+ // Validate that tus is an array
18
+ if (!Array.isArray(tus)) {
19
+ return res.status(400).json({
20
+ error: 'tus must be an array'
21
+ });
22
+ }
23
+
24
+ // Validate that providerList is an array
25
+ if (!Array.isArray(providerList)) {
26
+ return res.status(400).json({
27
+ error: 'providerList must be an array'
28
+ });
29
+ }
30
+
31
+ logVerbose`Creating jobs for ${tus.length} TUs with providers: ${providerList.join(', ')}`;
32
+
33
+ // Call the MonsterManager dispatcher
34
+ const result = await mm.dispatcher.createJobs({ sourceLang, targetLang, tus }, { providerList, skipQualityCheck: true, skipGroupCheck: true });
35
+
36
+ logVerbose`Created ${result?.length || 0} jobs successfully`;
37
+ res.json(result);
38
+
39
+ } catch (error) {
40
+ logInfo`Error creating jobs: ${error.message}`;
41
+ res.status(500).json({
42
+ error: 'Failed to create jobs',
43
+ message: error.message
44
+ });
45
+ }
46
+ });
47
+
48
+ router.post('/dispatcher/startJobs', async (req, res) => {
49
+ logInfo`/dispatcher/startJobs`;
50
+
51
+ try {
52
+ const { jobs, instructions } = req.body;
53
+
54
+ // Validate required parameters
55
+ if (!jobs || !Array.isArray(jobs)) {
56
+ return res.status(400).json({
57
+ error: 'Missing or invalid jobs parameter (must be an array)'
58
+ });
59
+ }
60
+
61
+ logVerbose`Starting ${jobs.length} jobs with instructions: ${instructions || 'none'}`;
62
+
63
+ // Call the MonsterManager dispatcher
64
+ const result = await mm.dispatcher.startJobs(jobs, { instructions });
65
+
66
+ logVerbose`Started jobs, returned ${result?.length || 0} job statuses`;
67
+ res.json(result);
68
+
69
+ } catch (error) {
70
+ logInfo`Error starting jobs: ${error.message}`;
71
+ res.status(500).json({
72
+ error: 'Failed to start jobs',
73
+ message: error.message
74
+ });
75
+ }
76
+ });
77
+ }
package/routes/info.js ADDED
@@ -0,0 +1,24 @@
1
+ import { logInfo, getBaseDir } from '@l10nmonster/core';
2
+ import path from 'path';
3
+
4
+ export function setupInfoRoute(router, mm, serverPackage) {
5
+ router.get('/info', async (req, res) => {
6
+ logInfo`/info`;
7
+ res.json({
8
+ version: serverPackage.version,
9
+ description: serverPackage.description,
10
+ baseDir: path.resolve(getBaseDir()),
11
+ providers: mm.dispatcher.providers.map(p => p.id),
12
+ channels: Object.keys(mm.rm.channels),
13
+ tmStores: mm.getTmStoreIds().map(id => {
14
+ const tmStore = mm.getTmStore(id);
15
+ return {
16
+ id: tmStore.id,
17
+ type: tmStore.constructor.name,
18
+ access: tmStore.access,
19
+ partitioning: tmStore.partitioning,
20
+ };
21
+ }),
22
+ });
23
+ });
24
+ }
@@ -0,0 +1,19 @@
1
+ import { logInfo, logVerbose } from '@l10nmonster/core';
2
+
3
+ export function setupProviderRoute(apiRouter, mm) {
4
+ apiRouter.get('/providers', async (req, res) => {
5
+ logInfo`/providers`;
6
+ try {
7
+ const providers = {};
8
+ for (const provider of mm.dispatcher.providers) {
9
+ const { id, ...info } = await provider.info();
10
+ providers[id] = { properties: provider, info };
11
+ }
12
+ logVerbose`Returned provider info for ${Object.keys(providers).length} providers`;
13
+ res.json(providers);
14
+ } catch (error) {
15
+ console.error('Error fetching provider data:', error);
16
+ res.status(500).json({ error: 'Failed to fetch provider data' });
17
+ }
18
+ });
19
+ }
@@ -0,0 +1,14 @@
1
+ import { logInfo, logVerbose } from '@l10nmonster/core';
2
+
3
+ export function setupActiveContentStatsRoute(router, mm) {
4
+ router.get('/activeContentStats', async (req, res) => {
5
+ logInfo`/activeContentStats`;
6
+ const sources = {};
7
+ for (const channelId of Object.keys(mm.rm.channels)) {
8
+ const channelStats = await mm.rm.getActiveContentStats(channelId);
9
+ sources[channelId] = channelStats;
10
+ }
11
+ logVerbose`Returned active content stats for ${Object.keys(sources).length} channels`;
12
+ res.json(sources);
13
+ });
14
+ }
@@ -0,0 +1,30 @@
1
+ import { logInfo, logVerbose } from '@l10nmonster/core';
2
+
3
+ export function setupStatusRoute(router, mm) {
4
+ router.get('/status', async (req, res) => {
5
+ logInfo`/status`;
6
+ try {
7
+ const status = await mm.getTranslationStatus();
8
+ // source_lang -> target_lang -> channel -> project -> data
9
+ logVerbose`Returned translation status`;
10
+ res.json(status);
11
+ } catch (error) {
12
+ console.error('Error fetching status: ', error);
13
+ res.status(500).json({ message: 'Problems fetching status data' });
14
+ }
15
+ });
16
+
17
+ router.get('/status/:sourceLang/:targetLang', async (req, res) => {
18
+ const { sourceLang, targetLang } = req.params;
19
+ logInfo`/status/${sourceLang}/${targetLang}`;
20
+ try {
21
+ const tm = mm.tmm.getTM(sourceLang, targetLang);
22
+ const tus = tm.getUntranslatedContent();
23
+ logVerbose`Returned ${tus.length} untranslated TUs for ${sourceLang}->${targetLang}`;
24
+ res.json(tus);
25
+ } catch (error) {
26
+ logInfo`Error: ${error.message}`;
27
+ res.status(500).json({ error: error.message });
28
+ }
29
+ });
30
+ }