carta-controller 5.1.1 → 6.0.0-beta.1.0.3
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/.github/workflows/build.yml +43 -0
- package/COPYING.md +636 -0
- package/biome.jsonc +37 -0
- package/dist/auth/external.js +10 -4
- package/dist/auth/external.js.map +1 -1
- package/dist/auth/google.js +18 -11
- package/dist/auth/google.js.map +1 -1
- package/dist/auth/index.js +12 -12
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/ldap.js +6 -3
- package/dist/auth/ldap.js.map +1 -1
- package/dist/auth/local.js +30 -14
- package/dist/auth/local.js.map +1 -1
- package/dist/auth/oidc.js +95 -91
- package/dist/auth/oidc.js.map +1 -1
- package/dist/auth/oidcRefreshManager.js +21 -24
- package/dist/auth/oidcRefreshManager.js.map +1 -1
- package/dist/auth/pam.js +8 -5
- package/dist/auth/pam.js.map +1 -1
- package/dist/config.js +17 -16
- package/dist/controllerTests.js +10 -10
- package/dist/database.js +50 -22
- package/dist/index.js +24 -23
- package/dist/serverHandlers.js +70 -33
- package/dist/util.js +14 -5
- package/npm-shrinkwrap.json +4855 -20113
- package/package.json +12 -9
- package/public/dashboard.js +47 -48
- package/public/templated.css +155 -143
- package/test/auth.external.test.ts +19 -18
- package/.prettierrc.json +0 -18
package/dist/config.js
CHANGED
|
@@ -38,23 +38,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
var _a, _b;
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.testUser = exports.RuntimeConfig = exports.ServerConfig = void 0;
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const path = __importStar(require("path"));
|
|
45
|
-
const JSONC = __importStar(require("jsonc-parser"));
|
|
46
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
41
|
+
const fs = __importStar(require("node:fs"));
|
|
42
|
+
const path = __importStar(require("node:path"));
|
|
43
|
+
const url = __importStar(require("node:url"));
|
|
47
44
|
const ajv_1 = __importDefault(require("ajv"));
|
|
48
45
|
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
49
|
-
const
|
|
50
|
-
const
|
|
46
|
+
const JSONC = __importStar(require("jsonc-parser"));
|
|
47
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
51
48
|
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
49
|
+
const winston_1 = __importDefault(require("winston"));
|
|
50
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
51
|
+
const util_1 = require("./util");
|
|
52
52
|
let timeZone;
|
|
53
53
|
const customTimestamp = () => {
|
|
54
54
|
if (timeZone)
|
|
55
|
-
return (0, moment_timezone_1.default)().tz(timeZone).format(
|
|
55
|
+
return (0, moment_timezone_1.default)().tz(timeZone).format("YYYY-MM-DD HH:mm:ss");
|
|
56
56
|
else
|
|
57
|
-
return (0, moment_timezone_1.default)().format(
|
|
57
|
+
return (0, moment_timezone_1.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
58
58
|
};
|
|
59
59
|
// Different log formats
|
|
60
60
|
const logTextFormat = winston_1.default.format.combine(winston_1.default.format.timestamp({ format: customTimestamp }), winston_1.default.format.printf(({ level, message, timestamp }) => {
|
|
@@ -68,7 +68,7 @@ const logJsonFormat = winston_1.default.format.combine(winston_1.default.format.
|
|
|
68
68
|
const defaultConfigPath = "/etc/carta/config.json";
|
|
69
69
|
const argv = yargs_1.default
|
|
70
70
|
.parserConfiguration({
|
|
71
|
-
|
|
71
|
+
"short-option-groups": false
|
|
72
72
|
})
|
|
73
73
|
.options({
|
|
74
74
|
config: {
|
|
@@ -114,7 +114,7 @@ const consoleTransport = new winston_1.default.transports.Console({
|
|
|
114
114
|
});
|
|
115
115
|
util_1.logger.add(consoleTransport);
|
|
116
116
|
try {
|
|
117
|
-
|
|
117
|
+
const configFiles = [];
|
|
118
118
|
if (fs.existsSync(argv.config)) {
|
|
119
119
|
configFiles.push(argv.config);
|
|
120
120
|
const jsonString = fs.readFileSync(argv.config).toString();
|
|
@@ -170,10 +170,11 @@ try {
|
|
|
170
170
|
// Validate timezone setting
|
|
171
171
|
if (serverConfig.timezone) {
|
|
172
172
|
try {
|
|
173
|
-
new Intl.DateTimeFormat(
|
|
173
|
+
new Intl.DateTimeFormat("en-US", { timeZone: serverConfig.timezone });
|
|
174
174
|
timeZone = serverConfig.timezone;
|
|
175
175
|
}
|
|
176
176
|
catch (err) {
|
|
177
|
+
util_1.logger.debug(err);
|
|
177
178
|
util_1.logger.error(`Ignoring invalid timezone "${serverConfig.timezone}" in config file`);
|
|
178
179
|
}
|
|
179
180
|
}
|
|
@@ -196,7 +197,7 @@ try {
|
|
|
196
197
|
util_1.logger.add(new winston_1.default.transports.File({
|
|
197
198
|
level: serverConfig.logLevelFile,
|
|
198
199
|
filename: serverConfig.logFile,
|
|
199
|
-
format: serverConfig.logTypeFile === "json" ? logJsonFormat : logTextFormat
|
|
200
|
+
format: serverConfig.logTypeFile === "json" ? logJsonFormat : logTextFormat
|
|
200
201
|
}));
|
|
201
202
|
util_1.logger.info(`Started logging to ${serverConfig.logFile}`);
|
|
202
203
|
}
|
|
@@ -241,8 +242,8 @@ if (serverConfig.authProviders.external) {
|
|
|
241
242
|
runtimeConfig.logoutAddress = serverConfig.authProviders.external.logoutAddress;
|
|
242
243
|
}
|
|
243
244
|
else {
|
|
244
|
-
runtimeConfig.tokenRefreshAddress = runtimeConfig.apiAddress
|
|
245
|
-
runtimeConfig.logoutAddress = runtimeConfig.apiAddress
|
|
245
|
+
runtimeConfig.tokenRefreshAddress = `${runtimeConfig.apiAddress}/auth/refresh`;
|
|
246
|
+
runtimeConfig.logoutAddress = `${runtimeConfig.apiAddress}/auth/logout`;
|
|
246
247
|
}
|
|
247
248
|
if (runtimeConfig.tokenRefreshAddress) {
|
|
248
249
|
const authUrl = url.parse(runtimeConfig.tokenRefreshAddress);
|
package/dist/controllerTests.js
CHANGED
|
@@ -46,17 +46,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.runTests = runTests;
|
|
49
|
-
const
|
|
50
|
-
const fs = __importStar(require("fs"));
|
|
51
|
-
const
|
|
49
|
+
const node_child_process_1 = require("node:child_process");
|
|
50
|
+
const fs = __importStar(require("node:fs"));
|
|
51
|
+
const path = __importStar(require("node:path"));
|
|
52
52
|
const ldapauth_fork_1 = __importDefault(require("ldapauth-fork"));
|
|
53
53
|
const logSymbols = __importStar(require("log-symbols"));
|
|
54
54
|
const moment_1 = __importDefault(require("moment"));
|
|
55
|
-
const
|
|
56
|
-
const child_process_1 = require("child_process");
|
|
57
|
-
const util_1 = require("./util");
|
|
55
|
+
const mongodb_1 = require("mongodb");
|
|
58
56
|
const websocket_1 = require("websocket");
|
|
59
57
|
const local_1 = require("./auth/local");
|
|
58
|
+
const config_1 = require("./config");
|
|
59
|
+
const util_1 = require("./util");
|
|
60
60
|
const read = require("read");
|
|
61
61
|
function runTests(username) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -194,7 +194,7 @@ function testFrontend() {
|
|
|
194
194
|
}
|
|
195
195
|
let indexContents;
|
|
196
196
|
try {
|
|
197
|
-
indexContents = fs.readFileSync(config_1.ServerConfig.frontendPath
|
|
197
|
+
indexContents = fs.readFileSync(`${config_1.ServerConfig.frontendPath}/index.html`).toString();
|
|
198
198
|
}
|
|
199
199
|
catch (e) {
|
|
200
200
|
util_1.logger.debug(e);
|
|
@@ -238,7 +238,7 @@ function testBackendStartup(username) {
|
|
|
238
238
|
args.push(config_1.ServerConfig.baseFolderTemplate.replace("{username}", username));
|
|
239
239
|
util_1.logger.debug(`running sudo ${args.join(" ")}`);
|
|
240
240
|
// Use same stdout and stderr stream for the backend process
|
|
241
|
-
const backendProcess = (0,
|
|
241
|
+
const backendProcess = (0, node_child_process_1.spawn)("sudo", args, { stdio: "inherit" });
|
|
242
242
|
yield (0, util_1.delay)(2000);
|
|
243
243
|
if (backendProcess.signalCode) {
|
|
244
244
|
throw new Error(`Backend process terminated with code ${backendProcess.signalCode}. Please check your sudoers config, processCommand option and additionalArgs section`);
|
|
@@ -251,7 +251,7 @@ function testBackendStartup(username) {
|
|
|
251
251
|
wsClient.on("connect", () => {
|
|
252
252
|
wsConnected = true;
|
|
253
253
|
});
|
|
254
|
-
wsClient.on("connectFailed",
|
|
254
|
+
wsClient.on("connectFailed", e => {
|
|
255
255
|
util_1.logger.debug(e);
|
|
256
256
|
});
|
|
257
257
|
wsClient.connect(`ws://localhost:${port}`);
|
|
@@ -272,7 +272,7 @@ function testKillScript(username, existingProcess) {
|
|
|
272
272
|
}
|
|
273
273
|
const args = ["-u", `${username}`, config_1.ServerConfig.killCommand, `${existingProcess.pid}`];
|
|
274
274
|
util_1.logger.debug(`running sudo ${args.join(" ")}`);
|
|
275
|
-
const res = (0,
|
|
275
|
+
const res = (0, node_child_process_1.spawnSync)("sudo", args, { encoding: "utf8" });
|
|
276
276
|
if (res.error) {
|
|
277
277
|
util_1.logger.debug(res.error);
|
|
278
278
|
util_1.logger.debug(`stdout:\t${res.stdout}`);
|
package/dist/database.js
CHANGED
|
@@ -14,13 +14,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.databaseRouter = void 0;
|
|
16
16
|
exports.initDB = initDB;
|
|
17
|
-
const express_1 = __importDefault(require("express"));
|
|
18
17
|
const ajv_1 = __importDefault(require("ajv"));
|
|
19
18
|
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
19
|
+
const express_1 = __importDefault(require("express"));
|
|
20
20
|
const mongodb_1 = require("mongodb");
|
|
21
21
|
const auth_1 = require("./auth");
|
|
22
|
-
const util_1 = require("./util");
|
|
23
22
|
const config_1 = require("./config");
|
|
23
|
+
const util_1 = require("./util");
|
|
24
24
|
const PREFERENCE_SCHEMA_VERSION = 2;
|
|
25
25
|
const LAYOUT_SCHEMA_VERSION = 2;
|
|
26
26
|
const SNIPPET_SCHEMA_VERSION = 1;
|
|
@@ -75,13 +75,17 @@ function initDB() {
|
|
|
75
75
|
preferenceCollection = yield createOrGetCollection(db, "preferences");
|
|
76
76
|
workspacesCollection = yield createOrGetCollection(db, "workspaces");
|
|
77
77
|
// Remove any existing validation in preferences collection
|
|
78
|
-
yield db.command({
|
|
78
|
+
yield db.command({
|
|
79
|
+
collMod: "preferences",
|
|
80
|
+
validator: {},
|
|
81
|
+
validationLevel: "off"
|
|
82
|
+
});
|
|
79
83
|
// Update collection indices if necessary
|
|
80
84
|
yield updateUsernameIndex(layoutsCollection, false);
|
|
81
85
|
yield updateUsernameIndex(snippetsCollection, false);
|
|
82
86
|
yield updateUsernameIndex(workspacesCollection, false);
|
|
83
87
|
yield updateUsernameIndex(preferenceCollection, true);
|
|
84
|
-
util_1.logger.info(`Connected to ${client.options.dbName} on ${client.options.hosts} (Authenticated: ${client.options.credentials ?
|
|
88
|
+
util_1.logger.info(`Connected to ${client.options.dbName} on ${client.options.hosts} (Authenticated: ${client.options.credentials ? "Yes" : "No"})`);
|
|
85
89
|
}
|
|
86
90
|
catch (err) {
|
|
87
91
|
util_1.logger.debug(err);
|
|
@@ -108,11 +112,13 @@ function handleGetPreferences(req, res, next) {
|
|
|
108
112
|
if (doc) {
|
|
109
113
|
const isValid = validatePreferences(doc);
|
|
110
114
|
if (!isValid) {
|
|
111
|
-
|
|
115
|
+
const errors = JSON.stringify(validatePreferences.errors);
|
|
116
|
+
util_1.logger.warning(`Returning invalid preferences:\n${errors}`);
|
|
112
117
|
}
|
|
113
118
|
res.json({ success: true, preferences: doc });
|
|
114
119
|
}
|
|
115
120
|
else {
|
|
121
|
+
util_1.logger.debug(`No preferences found for user ${req.username}`);
|
|
116
122
|
res.json({ success: true, preferences: {} });
|
|
117
123
|
}
|
|
118
124
|
}
|
|
@@ -139,7 +145,8 @@ function handleSetPreferences(req, res, next) {
|
|
|
139
145
|
update.version = PREFERENCE_SCHEMA_VERSION;
|
|
140
146
|
const validUpdate = validatePreferences(update);
|
|
141
147
|
if (!validUpdate) {
|
|
142
|
-
|
|
148
|
+
const errors = JSON.stringify(validatePreferences.errors);
|
|
149
|
+
util_1.logger.warning(`Rejecting invalid preference update:\n${errors}`);
|
|
143
150
|
return next({ statusCode: 400, message: "Invalid preference update" });
|
|
144
151
|
}
|
|
145
152
|
try {
|
|
@@ -211,7 +218,8 @@ function handleGetLayouts(req, res, next) {
|
|
|
211
218
|
if (entry.name && entry.layout) {
|
|
212
219
|
const isValid = validateLayout(entry.layout);
|
|
213
220
|
if (!isValid) {
|
|
214
|
-
|
|
221
|
+
const errors = JSON.stringify(validateLayout.errors);
|
|
222
|
+
util_1.logger.warning(`Returning invalid layout '${entry.name}':\n${errors}`);
|
|
215
223
|
}
|
|
216
224
|
layouts[entry.name] = entry.layout;
|
|
217
225
|
}
|
|
@@ -241,7 +249,8 @@ function handleSetLayout(req, res, next) {
|
|
|
241
249
|
}
|
|
242
250
|
const validUpdate = validateLayout(layout);
|
|
243
251
|
if (!validUpdate) {
|
|
244
|
-
|
|
252
|
+
const errors = JSON.stringify(validateLayout.errors);
|
|
253
|
+
util_1.logger.warning(`Rejecting invalid layout update:\n${errors}`);
|
|
245
254
|
return next({ statusCode: 400, message: "Invalid layout update" });
|
|
246
255
|
}
|
|
247
256
|
try {
|
|
@@ -270,7 +279,10 @@ function handleClearLayout(req, res, next) {
|
|
|
270
279
|
}
|
|
271
280
|
const layoutName = (_a = req.body) === null || _a === void 0 ? void 0 : _a.layoutName;
|
|
272
281
|
try {
|
|
273
|
-
const deleteResult = yield layoutsCollection.deleteOne({
|
|
282
|
+
const deleteResult = yield layoutsCollection.deleteOne({
|
|
283
|
+
username: req.username,
|
|
284
|
+
name: layoutName
|
|
285
|
+
});
|
|
274
286
|
if (deleteResult.acknowledged) {
|
|
275
287
|
res.json({ success: true });
|
|
276
288
|
}
|
|
@@ -299,7 +311,8 @@ function handleGetSnippets(req, res, next) {
|
|
|
299
311
|
if (entry.name && entry.snippet) {
|
|
300
312
|
const isValid = validateSnippet(entry.snippet);
|
|
301
313
|
if (!isValid) {
|
|
302
|
-
|
|
314
|
+
const errors = JSON.stringify(validateSnippet.errors);
|
|
315
|
+
util_1.logger.warning(`Returning invalid snippet '${entry.name}':\n${errors}`);
|
|
303
316
|
}
|
|
304
317
|
snippets[entry.name] = entry.snippet;
|
|
305
318
|
}
|
|
@@ -329,7 +342,8 @@ function handleSetSnippet(req, res, next) {
|
|
|
329
342
|
}
|
|
330
343
|
const validUpdate = validateSnippet(snippet);
|
|
331
344
|
if (!validUpdate) {
|
|
332
|
-
|
|
345
|
+
const errors = JSON.stringify(validateSnippet.errors);
|
|
346
|
+
util_1.logger.error(`Rejecting invalid snippet update:\n${errors}`);
|
|
333
347
|
return next({ statusCode: 400, message: "Invalid snippet update" });
|
|
334
348
|
}
|
|
335
349
|
try {
|
|
@@ -358,7 +372,10 @@ function handleClearSnippet(req, res, next) {
|
|
|
358
372
|
}
|
|
359
373
|
const snippetName = (_a = req.body) === null || _a === void 0 ? void 0 : _a.snippetName;
|
|
360
374
|
try {
|
|
361
|
-
const deleteResult = yield snippetsCollection.deleteOne({
|
|
375
|
+
const deleteResult = yield snippetsCollection.deleteOne({
|
|
376
|
+
username: req.username,
|
|
377
|
+
name: snippetName
|
|
378
|
+
});
|
|
362
379
|
if (deleteResult.acknowledged) {
|
|
363
380
|
res.json({ success: true });
|
|
364
381
|
}
|
|
@@ -374,7 +391,7 @@ function handleClearSnippet(req, res, next) {
|
|
|
374
391
|
}
|
|
375
392
|
function handleClearWorkspace(req, res, next) {
|
|
376
393
|
return __awaiter(this, void 0, void 0, function* () {
|
|
377
|
-
var _a
|
|
394
|
+
var _a;
|
|
378
395
|
if (!req.username) {
|
|
379
396
|
return next({ statusCode: 403, message: "Invalid username" });
|
|
380
397
|
}
|
|
@@ -383,9 +400,12 @@ function handleClearWorkspace(req, res, next) {
|
|
|
383
400
|
}
|
|
384
401
|
const workspaceName = (_a = req.body) === null || _a === void 0 ? void 0 : _a.workspaceName;
|
|
385
402
|
// TODO: handle CRUD with workspace ID instead of name
|
|
386
|
-
const workspaceId =
|
|
403
|
+
// const workspaceId = req.body?.id;
|
|
387
404
|
try {
|
|
388
|
-
const deleteResult = yield workspacesCollection.deleteOne({
|
|
405
|
+
const deleteResult = yield workspacesCollection.deleteOne({
|
|
406
|
+
username: req.username,
|
|
407
|
+
name: workspaceName
|
|
408
|
+
});
|
|
389
409
|
if (deleteResult.acknowledged) {
|
|
390
410
|
res.json({ success: true });
|
|
391
411
|
}
|
|
@@ -410,7 +430,10 @@ function handleGetWorkspaceList(req, res, next) {
|
|
|
410
430
|
}
|
|
411
431
|
try {
|
|
412
432
|
const workspaceList = yield workspacesCollection.find({ username: req.username }, { projection: { _id: 1, name: 1, "workspace.date": 1 } }).toArray();
|
|
413
|
-
const workspaces = (_a = workspaceList === null || workspaceList === void 0 ? void 0 : workspaceList.map(w => {
|
|
433
|
+
const workspaces = (_a = workspaceList === null || workspaceList === void 0 ? void 0 : workspaceList.map(w => {
|
|
434
|
+
var _a;
|
|
435
|
+
return (Object.assign(Object.assign({}, w), { id: w._id.toString(), date: (_a = w.workspace) === null || _a === void 0 ? void 0 : _a.date }));
|
|
436
|
+
})) !== null && _a !== void 0 ? _a : [];
|
|
414
437
|
res.json({ success: true, workspaces });
|
|
415
438
|
}
|
|
416
439
|
catch (err) {
|
|
@@ -437,10 +460,11 @@ function handleGetWorkspaceByName(req, res, next) {
|
|
|
437
460
|
return next({ statusCode: 404, message: "Workspace not found" });
|
|
438
461
|
}
|
|
439
462
|
else {
|
|
440
|
-
const workspace = Object.assign({ id: queryResult._id, name: queryResult.name, editable: true }, queryResult.workspace);
|
|
463
|
+
const workspace = Object.assign({ id: queryResult._id.toString(), name: queryResult.name, editable: true }, queryResult.workspace);
|
|
441
464
|
const isValid = validateWorkspace(workspace);
|
|
442
465
|
if (!isValid) {
|
|
443
|
-
|
|
466
|
+
const errors = JSON.stringify(validateWorkspace.errors);
|
|
467
|
+
util_1.logger.warning(`Returning invalid workspace '${workspace.name}':\n${errors}`);
|
|
444
468
|
}
|
|
445
469
|
res.json({ success: true, workspace: workspace });
|
|
446
470
|
}
|
|
@@ -465,7 +489,9 @@ function handleGetWorkspaceByKey(req, res, next) {
|
|
|
465
489
|
}
|
|
466
490
|
try {
|
|
467
491
|
const objectId = Buffer.from(req.params.key, "base64url").toString("hex");
|
|
468
|
-
const queryResult = yield workspacesCollection.findOne({
|
|
492
|
+
const queryResult = yield workspacesCollection.findOne({
|
|
493
|
+
_id: new mongodb_1.ObjectId(objectId)
|
|
494
|
+
});
|
|
469
495
|
if (!(queryResult === null || queryResult === void 0 ? void 0 : queryResult.workspace)) {
|
|
470
496
|
return next({ statusCode: 404, message: "Workspace not found" });
|
|
471
497
|
}
|
|
@@ -473,10 +499,11 @@ function handleGetWorkspaceByKey(req, res, next) {
|
|
|
473
499
|
return next({ statusCode: 403, message: "Workspace not accessible" });
|
|
474
500
|
}
|
|
475
501
|
else {
|
|
476
|
-
const workspace = Object.assign({ id: queryResult._id, name: queryResult.name, editable: queryResult.username === req.username }, queryResult.workspace);
|
|
502
|
+
const workspace = Object.assign({ id: queryResult._id.toString(), name: queryResult.name, editable: queryResult.username === req.username }, queryResult.workspace);
|
|
477
503
|
const isValid = validateWorkspace(workspace);
|
|
478
504
|
if (!isValid) {
|
|
479
|
-
|
|
505
|
+
const errors = JSON.stringify(validateWorkspace.errors);
|
|
506
|
+
util_1.logger.warning(`Returning invalid workspace '${workspace.name}':\n${errors}`);
|
|
480
507
|
}
|
|
481
508
|
res.json({ success: true, workspace: workspace });
|
|
482
509
|
}
|
|
@@ -504,7 +531,8 @@ function handleSetWorkspace(req, res, next) {
|
|
|
504
531
|
}
|
|
505
532
|
const validUpdate = validateWorkspace(workspace);
|
|
506
533
|
if (!validUpdate) {
|
|
507
|
-
|
|
534
|
+
const errors = JSON.stringify(validateWorkspace.errors);
|
|
535
|
+
util_1.logger.error(`Rejecting invalid workspace update:\n${errors}`);
|
|
508
536
|
return next({ statusCode: 400, message: "Invalid workspace update" });
|
|
509
537
|
}
|
|
510
538
|
try {
|
package/dist/index.js
CHANGED
|
@@ -46,22 +46,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
};
|
|
47
47
|
var _a;
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
-
const
|
|
49
|
+
const fs = __importStar(require("node:fs"));
|
|
50
|
+
const http = __importStar(require("node:http"));
|
|
51
|
+
const path = __importStar(require("node:path"));
|
|
52
|
+
const url = __importStar(require("node:url"));
|
|
50
53
|
const bodyParser = __importStar(require("body-parser"));
|
|
51
|
-
const
|
|
54
|
+
const compression_1 = __importDefault(require("compression"));
|
|
52
55
|
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
53
|
-
const http_proxy_1 = __importDefault(require("http-proxy"));
|
|
54
|
-
const http = __importStar(require("http"));
|
|
55
|
-
const url = __importStar(require("url"));
|
|
56
56
|
const cors_1 = __importDefault(require("cors"));
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const config_1 = require("./config");
|
|
61
|
-
const serverHandlers_1 = require("./serverHandlers");
|
|
57
|
+
const express_1 = __importDefault(require("express"));
|
|
58
|
+
const express_bearer_token_1 = __importDefault(require("express-bearer-token"));
|
|
59
|
+
const http_proxy_1 = __importDefault(require("http-proxy"));
|
|
62
60
|
const auth_1 = require("./auth");
|
|
63
|
-
const
|
|
61
|
+
const config_1 = require("./config");
|
|
64
62
|
const controllerTests_1 = require("./controllerTests");
|
|
63
|
+
const database_1 = require("./database");
|
|
64
|
+
const serverHandlers_1 = require("./serverHandlers");
|
|
65
65
|
const util_1 = require("./util");
|
|
66
66
|
if (config_1.testUser) {
|
|
67
67
|
(0, controllerTests_1.runTests)(config_1.testUser).then(() => {
|
|
@@ -74,7 +74,7 @@ if (config_1.testUser) {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
|
-
|
|
77
|
+
const app = (0, express_1.default)();
|
|
78
78
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
79
79
|
app.use((0, cookie_parser_1.default)());
|
|
80
80
|
app.use((0, express_bearer_token_1.default)());
|
|
@@ -85,7 +85,7 @@ else {
|
|
|
85
85
|
app.use("/api/auth", bodyParser.json(), auth_1.authRouter);
|
|
86
86
|
app.use("/api/server", bodyParser.json(), serverHandlers_1.serverRouter);
|
|
87
87
|
app.use("/api/database", bodyParser.json(), database_1.databaseRouter);
|
|
88
|
-
app.use("/config", (
|
|
88
|
+
app.use("/config", (_req, res) => {
|
|
89
89
|
return res.json(config_1.RuntimeConfig);
|
|
90
90
|
});
|
|
91
91
|
// Prevent caching of the frontend HTML code
|
|
@@ -96,7 +96,9 @@ else {
|
|
|
96
96
|
};
|
|
97
97
|
if (config_1.ServerConfig.frontendPath) {
|
|
98
98
|
util_1.logger.info(`Serving CARTA frontend from ${config_1.ServerConfig.frontendPath}`);
|
|
99
|
-
app.use("/", express_1.default.static(config_1.ServerConfig.frontendPath, {
|
|
99
|
+
app.use("/", express_1.default.static(config_1.ServerConfig.frontendPath, {
|
|
100
|
+
setHeaders: staticHeaderHandler
|
|
101
|
+
}));
|
|
100
102
|
}
|
|
101
103
|
else {
|
|
102
104
|
const frontendPackage = require("../node_modules/carta-frontend/package.json");
|
|
@@ -109,24 +111,24 @@ else {
|
|
|
109
111
|
const isBannerSvg = config_1.ServerConfig.dashboard.bannerImage.toLowerCase().endsWith(".svg");
|
|
110
112
|
const bannerDataBase64 = fs.readFileSync(config_1.ServerConfig.dashboard.bannerImage, "base64");
|
|
111
113
|
if (isBannerSvg) {
|
|
112
|
-
bannerDataUri =
|
|
114
|
+
bannerDataUri = `data:image/svg+xml;base64,${bannerDataBase64}`;
|
|
113
115
|
}
|
|
114
116
|
else {
|
|
115
|
-
bannerDataUri =
|
|
117
|
+
bannerDataUri = `data:image/png;base64,${bannerDataBase64}`;
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
app.get("/frontend", (req, res) => {
|
|
119
121
|
var _a, _b, _c;
|
|
120
122
|
const queryString = (_a = url.parse(req.url, false)) === null || _a === void 0 ? void 0 : _a.query;
|
|
121
123
|
if (queryString) {
|
|
122
|
-
return res.redirect((
|
|
124
|
+
return res.redirect(`${(_b = config_1.ServerConfig.serverAddress) !== null && _b !== void 0 ? _b : ""}/?${queryString}`);
|
|
123
125
|
}
|
|
124
126
|
else {
|
|
125
127
|
return res.redirect((_c = config_1.ServerConfig.serverAddress) !== null && _c !== void 0 ? _c : "");
|
|
126
128
|
}
|
|
127
129
|
});
|
|
128
130
|
const packageJson = require(path.join(__dirname, "../package.json"));
|
|
129
|
-
app.get("/dashboard", (
|
|
131
|
+
app.get("/dashboard", (_req, res) => {
|
|
130
132
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
131
133
|
res.render("templated", {
|
|
132
134
|
googleClientId: (_a = config_1.ServerConfig.authProviders.google) === null || _a === void 0 ? void 0 : _a.clientId,
|
|
@@ -147,11 +149,10 @@ else {
|
|
|
147
149
|
const backendProxy = http_proxy_1.default.createServer({ ws: true });
|
|
148
150
|
app.post("/api/scripting/*", auth_1.authGuard, (0, serverHandlers_1.createScriptingProxyHandler)(backendProxy));
|
|
149
151
|
// Simplified error handling
|
|
150
|
-
app.use((err,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
status: err.status,
|
|
152
|
+
app.use((err, _req, res, _next) => {
|
|
153
|
+
var _a, _b;
|
|
154
|
+
res.status((_a = err.statusCode) !== null && _a !== void 0 ? _a : 500).json({
|
|
155
|
+
status: (_b = err.status) !== null && _b !== void 0 ? _b : "error",
|
|
155
156
|
message: err.message
|
|
156
157
|
});
|
|
157
158
|
});
|