@valbuild/server 0.28.0 → 0.30.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.
@@ -24,4 +24,5 @@ export declare class LocalValServer implements ValServer {
|
|
24
24
|
callback(req: express.Request, res: express.Response): Promise<void>;
|
25
25
|
logout(req: express.Request, res: express.Response): Promise<void>;
|
26
26
|
getFiles(req: express.Request, res: express.Response): Promise<void>;
|
27
|
+
getPatches(req: express.Request, res: express.Response): Promise<void>;
|
27
28
|
}
|
@@ -12,4 +12,5 @@ export interface ValServer {
|
|
12
12
|
disable(req: express.Request, res: express.Response): Promise<void>;
|
13
13
|
getTree(req: express.Request, res: express.Response): Promise<void>;
|
14
14
|
getFiles(req: express.Request, res: express.Response): Promise<void>;
|
15
|
+
getPatches(req: express.Request, res: express.Response): Promise<void>;
|
15
16
|
}
|
@@ -1052,7 +1052,7 @@ function createRequestHandler(valServer) {
|
|
1052
1052
|
router.post("/patches/*", express__default["default"].json({
|
1053
1053
|
type: "application/json",
|
1054
1054
|
limit: "10mb"
|
1055
|
-
}), valServer.postPatches.bind(valServer));
|
1055
|
+
}), valServer.postPatches.bind(valServer)).get("/patches/*", valServer.getPatches.bind(valServer));
|
1056
1056
|
router.post("/commit", valServer.commit.bind(valServer));
|
1057
1057
|
router.get("/enable", valServer.enable.bind(valServer));
|
1058
1058
|
router.get("/disable", valServer.disable.bind(valServer));
|
@@ -1285,7 +1285,11 @@ class ProxyValServer {
|
|
1285
1285
|
res.sendStatus(401);
|
1286
1286
|
return;
|
1287
1287
|
}
|
1288
|
-
return handler(verification.data)
|
1288
|
+
return handler(verification.data).catch(err => {
|
1289
|
+
console.error(`Failed while processing: ${req.url}`, err);
|
1290
|
+
res.sendStatus(500);
|
1291
|
+
return undefined;
|
1292
|
+
});
|
1289
1293
|
} else {
|
1290
1294
|
res.sendStatus(401);
|
1291
1295
|
}
|
@@ -1329,10 +1333,41 @@ class ProxyValServer {
|
|
1329
1333
|
const url = new URL(`/v1/tree/${this.options.valName}/heads/${this.options.gitBranch}/${req.params["0"]}/?${params}`, this.options.valContentUrl);
|
1330
1334
|
const json = await fetch(url, {
|
1331
1335
|
headers: this.getAuthHeaders(data.token, "application/json")
|
1332
|
-
}).then(res => res.json())
|
1336
|
+
}).then(res => res.json()).catch(err => {
|
1337
|
+
console.error(err);
|
1338
|
+
throw err;
|
1339
|
+
});
|
1333
1340
|
res.send(json);
|
1334
1341
|
});
|
1335
1342
|
}
|
1343
|
+
async getPatches(req, res) {
|
1344
|
+
const patchIds = typeof req.params["id"] === "string" ? [req.params["id"]] : Array.isArray(req.params["id"]) ? req.params["id"] : [];
|
1345
|
+
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1346
|
+
await this.withAuth(req, res, async ({
|
1347
|
+
token
|
1348
|
+
}) => {
|
1349
|
+
const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/${req.params["0"]}${params}`, this.options.valContentUrl);
|
1350
|
+
console.log(url);
|
1351
|
+
// Proxy patch to val.build
|
1352
|
+
const fetchRes = await fetch(url, {
|
1353
|
+
method: "GET",
|
1354
|
+
headers: this.getAuthHeaders(token, "application/json")
|
1355
|
+
});
|
1356
|
+
if (fetchRes.ok) {
|
1357
|
+
const json = await fetchRes.json();
|
1358
|
+
res.status(fetchRes.status).json(json);
|
1359
|
+
} else {
|
1360
|
+
res.sendStatus(fetchRes.status);
|
1361
|
+
}
|
1362
|
+
}).catch(e => {
|
1363
|
+
res.status(500).send({
|
1364
|
+
error: {
|
1365
|
+
message: e === null || e === void 0 ? void 0 : e.message,
|
1366
|
+
status: 500
|
1367
|
+
}
|
1368
|
+
});
|
1369
|
+
});
|
1370
|
+
}
|
1336
1371
|
async postPatches(req, res) {
|
1337
1372
|
const commit = this.options.gitCommit;
|
1338
1373
|
if (!commit) {
|
@@ -1344,7 +1379,7 @@ class ProxyValServer {
|
|
1344
1379
|
const params = new URLSearchParams({
|
1345
1380
|
commit
|
1346
1381
|
});
|
1347
|
-
this.withAuth(req, res, async ({
|
1382
|
+
await this.withAuth(req, res, async ({
|
1348
1383
|
token
|
1349
1384
|
}) => {
|
1350
1385
|
// First validate that the body has the right structure
|
@@ -1383,7 +1418,7 @@ class ProxyValServer {
|
|
1383
1418
|
});
|
1384
1419
|
}
|
1385
1420
|
async commit(req, res) {
|
1386
|
-
this.withAuth(req, res, async ({
|
1421
|
+
await this.withAuth(req, res, async ({
|
1387
1422
|
token
|
1388
1423
|
}) => {
|
1389
1424
|
const url = new URL(`/api/val/commit/${encodeURIComponent(this.options.gitBranch)}`, this.options.valBuildUrl);
|
@@ -1714,6 +1749,9 @@ class LocalValServer {
|
|
1714
1749
|
getFiles(req, res) {
|
1715
1750
|
return this.badRequest(req, res);
|
1716
1751
|
}
|
1752
|
+
getPatches(req, res) {
|
1753
|
+
return this.badRequest(req, res);
|
1754
|
+
}
|
1717
1755
|
}
|
1718
1756
|
|
1719
1757
|
async function _createRequestListener(route, opts) {
|
@@ -1052,7 +1052,7 @@ function createRequestHandler(valServer) {
|
|
1052
1052
|
router.post("/patches/*", express__default["default"].json({
|
1053
1053
|
type: "application/json",
|
1054
1054
|
limit: "10mb"
|
1055
|
-
}), valServer.postPatches.bind(valServer));
|
1055
|
+
}), valServer.postPatches.bind(valServer)).get("/patches/*", valServer.getPatches.bind(valServer));
|
1056
1056
|
router.post("/commit", valServer.commit.bind(valServer));
|
1057
1057
|
router.get("/enable", valServer.enable.bind(valServer));
|
1058
1058
|
router.get("/disable", valServer.disable.bind(valServer));
|
@@ -1285,7 +1285,11 @@ class ProxyValServer {
|
|
1285
1285
|
res.sendStatus(401);
|
1286
1286
|
return;
|
1287
1287
|
}
|
1288
|
-
return handler(verification.data)
|
1288
|
+
return handler(verification.data).catch(err => {
|
1289
|
+
console.error(`Failed while processing: ${req.url}`, err);
|
1290
|
+
res.sendStatus(500);
|
1291
|
+
return undefined;
|
1292
|
+
});
|
1289
1293
|
} else {
|
1290
1294
|
res.sendStatus(401);
|
1291
1295
|
}
|
@@ -1329,10 +1333,41 @@ class ProxyValServer {
|
|
1329
1333
|
const url = new URL(`/v1/tree/${this.options.valName}/heads/${this.options.gitBranch}/${req.params["0"]}/?${params}`, this.options.valContentUrl);
|
1330
1334
|
const json = await fetch(url, {
|
1331
1335
|
headers: this.getAuthHeaders(data.token, "application/json")
|
1332
|
-
}).then(res => res.json())
|
1336
|
+
}).then(res => res.json()).catch(err => {
|
1337
|
+
console.error(err);
|
1338
|
+
throw err;
|
1339
|
+
});
|
1333
1340
|
res.send(json);
|
1334
1341
|
});
|
1335
1342
|
}
|
1343
|
+
async getPatches(req, res) {
|
1344
|
+
const patchIds = typeof req.params["id"] === "string" ? [req.params["id"]] : Array.isArray(req.params["id"]) ? req.params["id"] : [];
|
1345
|
+
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1346
|
+
await this.withAuth(req, res, async ({
|
1347
|
+
token
|
1348
|
+
}) => {
|
1349
|
+
const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/${req.params["0"]}${params}`, this.options.valContentUrl);
|
1350
|
+
console.log(url);
|
1351
|
+
// Proxy patch to val.build
|
1352
|
+
const fetchRes = await fetch(url, {
|
1353
|
+
method: "GET",
|
1354
|
+
headers: this.getAuthHeaders(token, "application/json")
|
1355
|
+
});
|
1356
|
+
if (fetchRes.ok) {
|
1357
|
+
const json = await fetchRes.json();
|
1358
|
+
res.status(fetchRes.status).json(json);
|
1359
|
+
} else {
|
1360
|
+
res.sendStatus(fetchRes.status);
|
1361
|
+
}
|
1362
|
+
}).catch(e => {
|
1363
|
+
res.status(500).send({
|
1364
|
+
error: {
|
1365
|
+
message: e === null || e === void 0 ? void 0 : e.message,
|
1366
|
+
status: 500
|
1367
|
+
}
|
1368
|
+
});
|
1369
|
+
});
|
1370
|
+
}
|
1336
1371
|
async postPatches(req, res) {
|
1337
1372
|
const commit = this.options.gitCommit;
|
1338
1373
|
if (!commit) {
|
@@ -1344,7 +1379,7 @@ class ProxyValServer {
|
|
1344
1379
|
const params = new URLSearchParams({
|
1345
1380
|
commit
|
1346
1381
|
});
|
1347
|
-
this.withAuth(req, res, async ({
|
1382
|
+
await this.withAuth(req, res, async ({
|
1348
1383
|
token
|
1349
1384
|
}) => {
|
1350
1385
|
// First validate that the body has the right structure
|
@@ -1383,7 +1418,7 @@ class ProxyValServer {
|
|
1383
1418
|
});
|
1384
1419
|
}
|
1385
1420
|
async commit(req, res) {
|
1386
|
-
this.withAuth(req, res, async ({
|
1421
|
+
await this.withAuth(req, res, async ({
|
1387
1422
|
token
|
1388
1423
|
}) => {
|
1389
1424
|
const url = new URL(`/api/val/commit/${encodeURIComponent(this.options.gitBranch)}`, this.options.valBuildUrl);
|
@@ -1714,6 +1749,9 @@ class LocalValServer {
|
|
1714
1749
|
getFiles(req, res) {
|
1715
1750
|
return this.badRequest(req, res);
|
1716
1751
|
}
|
1752
|
+
getPatches(req, res) {
|
1753
|
+
return this.badRequest(req, res);
|
1754
|
+
}
|
1717
1755
|
}
|
1718
1756
|
|
1719
1757
|
async function _createRequestListener(route, opts) {
|
@@ -1021,7 +1021,7 @@ function createRequestHandler(valServer) {
|
|
1021
1021
|
router.post("/patches/*", express.json({
|
1022
1022
|
type: "application/json",
|
1023
1023
|
limit: "10mb"
|
1024
|
-
}), valServer.postPatches.bind(valServer));
|
1024
|
+
}), valServer.postPatches.bind(valServer)).get("/patches/*", valServer.getPatches.bind(valServer));
|
1025
1025
|
router.post("/commit", valServer.commit.bind(valServer));
|
1026
1026
|
router.get("/enable", valServer.enable.bind(valServer));
|
1027
1027
|
router.get("/disable", valServer.disable.bind(valServer));
|
@@ -1254,7 +1254,11 @@ class ProxyValServer {
|
|
1254
1254
|
res.sendStatus(401);
|
1255
1255
|
return;
|
1256
1256
|
}
|
1257
|
-
return handler(verification.data)
|
1257
|
+
return handler(verification.data).catch(err => {
|
1258
|
+
console.error(`Failed while processing: ${req.url}`, err);
|
1259
|
+
res.sendStatus(500);
|
1260
|
+
return undefined;
|
1261
|
+
});
|
1258
1262
|
} else {
|
1259
1263
|
res.sendStatus(401);
|
1260
1264
|
}
|
@@ -1298,10 +1302,41 @@ class ProxyValServer {
|
|
1298
1302
|
const url = new URL(`/v1/tree/${this.options.valName}/heads/${this.options.gitBranch}/${req.params["0"]}/?${params}`, this.options.valContentUrl);
|
1299
1303
|
const json = await fetch(url, {
|
1300
1304
|
headers: this.getAuthHeaders(data.token, "application/json")
|
1301
|
-
}).then(res => res.json())
|
1305
|
+
}).then(res => res.json()).catch(err => {
|
1306
|
+
console.error(err);
|
1307
|
+
throw err;
|
1308
|
+
});
|
1302
1309
|
res.send(json);
|
1303
1310
|
});
|
1304
1311
|
}
|
1312
|
+
async getPatches(req, res) {
|
1313
|
+
const patchIds = typeof req.params["id"] === "string" ? [req.params["id"]] : Array.isArray(req.params["id"]) ? req.params["id"] : [];
|
1314
|
+
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1315
|
+
await this.withAuth(req, res, async ({
|
1316
|
+
token
|
1317
|
+
}) => {
|
1318
|
+
const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/${req.params["0"]}${params}`, this.options.valContentUrl);
|
1319
|
+
console.log(url);
|
1320
|
+
// Proxy patch to val.build
|
1321
|
+
const fetchRes = await fetch(url, {
|
1322
|
+
method: "GET",
|
1323
|
+
headers: this.getAuthHeaders(token, "application/json")
|
1324
|
+
});
|
1325
|
+
if (fetchRes.ok) {
|
1326
|
+
const json = await fetchRes.json();
|
1327
|
+
res.status(fetchRes.status).json(json);
|
1328
|
+
} else {
|
1329
|
+
res.sendStatus(fetchRes.status);
|
1330
|
+
}
|
1331
|
+
}).catch(e => {
|
1332
|
+
res.status(500).send({
|
1333
|
+
error: {
|
1334
|
+
message: e === null || e === void 0 ? void 0 : e.message,
|
1335
|
+
status: 500
|
1336
|
+
}
|
1337
|
+
});
|
1338
|
+
});
|
1339
|
+
}
|
1305
1340
|
async postPatches(req, res) {
|
1306
1341
|
const commit = this.options.gitCommit;
|
1307
1342
|
if (!commit) {
|
@@ -1313,7 +1348,7 @@ class ProxyValServer {
|
|
1313
1348
|
const params = new URLSearchParams({
|
1314
1349
|
commit
|
1315
1350
|
});
|
1316
|
-
this.withAuth(req, res, async ({
|
1351
|
+
await this.withAuth(req, res, async ({
|
1317
1352
|
token
|
1318
1353
|
}) => {
|
1319
1354
|
// First validate that the body has the right structure
|
@@ -1352,7 +1387,7 @@ class ProxyValServer {
|
|
1352
1387
|
});
|
1353
1388
|
}
|
1354
1389
|
async commit(req, res) {
|
1355
|
-
this.withAuth(req, res, async ({
|
1390
|
+
await this.withAuth(req, res, async ({
|
1356
1391
|
token
|
1357
1392
|
}) => {
|
1358
1393
|
const url = new URL(`/api/val/commit/${encodeURIComponent(this.options.gitBranch)}`, this.options.valBuildUrl);
|
@@ -1683,6 +1718,9 @@ class LocalValServer {
|
|
1683
1718
|
getFiles(req, res) {
|
1684
1719
|
return this.badRequest(req, res);
|
1685
1720
|
}
|
1721
|
+
getPatches(req, res) {
|
1722
|
+
return this.badRequest(req, res);
|
1723
|
+
}
|
1686
1724
|
}
|
1687
1725
|
|
1688
1726
|
async function _createRequestListener(route, opts) {
|
package/package.json
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
"./package.json": "./package.json"
|
13
13
|
},
|
14
14
|
"types": "dist/valbuild-server.cjs.d.ts",
|
15
|
-
"version": "0.
|
15
|
+
"version": "0.30.0",
|
16
16
|
"scripts": {
|
17
17
|
"typecheck": "tsc --noEmit",
|
18
18
|
"test": "jest",
|
@@ -25,8 +25,8 @@
|
|
25
25
|
"concurrently": "^7.6.0"
|
26
26
|
},
|
27
27
|
"dependencies": {
|
28
|
-
"@valbuild/core": "~0.
|
29
|
-
"@valbuild/ui": "~0.
|
28
|
+
"@valbuild/core": "~0.30.0",
|
29
|
+
"@valbuild/ui": "~0.30.0",
|
30
30
|
"express": "^4.18.2",
|
31
31
|
"image-size": "^1.0.2",
|
32
32
|
"quickjs-emscripten": "^0.21.1",
|