@valbuild/server 0.16.0 → 0.16.1
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/dist/declarations/src/hosting.d.ts +8 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/patch/validation.d.ts +4 -0
- package/dist/valbuild-server.cjs.dev.js +12 -4
- package/dist/valbuild-server.cjs.prod.js +12 -4
- package/dist/valbuild-server.esm.js +12 -5
- package/package.json +1 -1
- package/src/ProxyValServer.ts +11 -3
- package/src/createFixPatch.ts +1 -0
- package/src/hosting.ts +13 -0
- package/src/index.ts +1 -0
|
@@ -66,6 +66,14 @@ type ValServerOverrides = Partial<{
|
|
|
66
66
|
* @example "https://app.val.build"
|
|
67
67
|
*/
|
|
68
68
|
valBuildUrl: string;
|
|
69
|
+
/**
|
|
70
|
+
* The full name of this Val project.
|
|
71
|
+
*
|
|
72
|
+
* Typically this is set using the VAL_NAME env var.
|
|
73
|
+
*
|
|
74
|
+
* @example "myorg/my-project"
|
|
75
|
+
*/
|
|
76
|
+
valName: string;
|
|
69
77
|
}>;
|
|
70
78
|
export declare function createRequestListener(route: string, opts: Opts): RequestListener;
|
|
71
79
|
export {};
|
|
@@ -12,3 +12,4 @@ export { patchSourceFile } from "./patchValFile.js";
|
|
|
12
12
|
export { formatSyntaxErrorTree } from "./patch/ts/syntax.js";
|
|
13
13
|
export { LocalValServer } from "./LocalValServer.js";
|
|
14
14
|
export { createFixPatch } from "./createFixPatch.js";
|
|
15
|
+
export { PatchJSON } from "./patch/validation.js";
|
|
@@ -1193,8 +1193,9 @@ class ProxyValServer {
|
|
|
1193
1193
|
}
|
|
1194
1194
|
}
|
|
1195
1195
|
async session(req, res) {
|
|
1196
|
+
console.log("hit session");
|
|
1196
1197
|
return this.withAuth(req, res, async data => {
|
|
1197
|
-
const url = new URL(
|
|
1198
|
+
const url = new URL(`/api/val/${this.options.valName}/auth/session`, this.options.valBuildUrl);
|
|
1198
1199
|
const fetchRes = await fetch(url, {
|
|
1199
1200
|
headers: this.getAuthHeaders(data.token, "application/json")
|
|
1200
1201
|
});
|
|
@@ -1297,7 +1298,7 @@ class ProxyValServer {
|
|
|
1297
1298
|
};
|
|
1298
1299
|
}
|
|
1299
1300
|
async consumeCode(code) {
|
|
1300
|
-
const url = new URL(
|
|
1301
|
+
const url = new URL(`/api/val/${this.options.valName}/auth/token`, this.options.valBuildUrl);
|
|
1301
1302
|
url.searchParams.set("code", encodeURIComponent(code));
|
|
1302
1303
|
return fetch(url, {
|
|
1303
1304
|
method: "POST",
|
|
@@ -1323,7 +1324,7 @@ class ProxyValServer {
|
|
|
1323
1324
|
});
|
|
1324
1325
|
}
|
|
1325
1326
|
getAuthorizeUrl(publicValApiRoute, token) {
|
|
1326
|
-
const url = new URL(
|
|
1327
|
+
const url = new URL(`/auth/${this.options.valName}/authorize`, this.options.valBuildUrl);
|
|
1327
1328
|
url.searchParams.set("redirect_uri", encodeURIComponent(`${publicValApiRoute}/callback`));
|
|
1328
1329
|
url.searchParams.set("state", token);
|
|
1329
1330
|
return url.toString();
|
|
@@ -1479,6 +1480,10 @@ async function initHandlerOptions(route, opts) {
|
|
|
1479
1480
|
if (!maybeGitBranch) {
|
|
1480
1481
|
throw new Error("VAL_GIT_BRANCH env var must be set in proxy mode");
|
|
1481
1482
|
}
|
|
1483
|
+
const maybeValName = opts.gitBranch || process.env.VAL_NAME;
|
|
1484
|
+
if (!maybeValName) {
|
|
1485
|
+
throw new Error("VAL_NAME env var must be set in proxy mode");
|
|
1486
|
+
}
|
|
1482
1487
|
return {
|
|
1483
1488
|
mode: "proxy",
|
|
1484
1489
|
route,
|
|
@@ -1486,7 +1491,8 @@ async function initHandlerOptions(route, opts) {
|
|
|
1486
1491
|
valSecret: maybeValSecret,
|
|
1487
1492
|
valBuildUrl,
|
|
1488
1493
|
gitCommit: maybeGitCommit,
|
|
1489
|
-
gitBranch: maybeGitBranch
|
|
1494
|
+
gitBranch: maybeGitBranch,
|
|
1495
|
+
valName: maybeValName
|
|
1490
1496
|
};
|
|
1491
1497
|
} else {
|
|
1492
1498
|
const service = await createService(process.cwd(), opts);
|
|
@@ -1549,6 +1555,7 @@ class ValFSHost {
|
|
|
1549
1555
|
}
|
|
1550
1556
|
}
|
|
1551
1557
|
|
|
1558
|
+
// TODO: find a better name? transformFixesToPatch?
|
|
1552
1559
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
1553
1560
|
async function getImageMetadata() {
|
|
1554
1561
|
const maybeRef = validationError.value && typeof validationError.value === "object" && core.FILE_REF_PROP in validationError.value && typeof validationError.value[core.FILE_REF_PROP] === "string" ? validationError.value[core.FILE_REF_PROP] : undefined;
|
|
@@ -1658,6 +1665,7 @@ const getSHA256Hash = async bits => {
|
|
|
1658
1665
|
};
|
|
1659
1666
|
|
|
1660
1667
|
exports.LocalValServer = LocalValServer;
|
|
1668
|
+
exports.PatchJSON = PatchJSON;
|
|
1661
1669
|
exports.Service = Service;
|
|
1662
1670
|
exports.ValFSHost = ValFSHost;
|
|
1663
1671
|
exports.ValModuleLoader = ValModuleLoader;
|
|
@@ -1193,8 +1193,9 @@ class ProxyValServer {
|
|
|
1193
1193
|
}
|
|
1194
1194
|
}
|
|
1195
1195
|
async session(req, res) {
|
|
1196
|
+
console.log("hit session");
|
|
1196
1197
|
return this.withAuth(req, res, async data => {
|
|
1197
|
-
const url = new URL(
|
|
1198
|
+
const url = new URL(`/api/val/${this.options.valName}/auth/session`, this.options.valBuildUrl);
|
|
1198
1199
|
const fetchRes = await fetch(url, {
|
|
1199
1200
|
headers: this.getAuthHeaders(data.token, "application/json")
|
|
1200
1201
|
});
|
|
@@ -1297,7 +1298,7 @@ class ProxyValServer {
|
|
|
1297
1298
|
};
|
|
1298
1299
|
}
|
|
1299
1300
|
async consumeCode(code) {
|
|
1300
|
-
const url = new URL(
|
|
1301
|
+
const url = new URL(`/api/val/${this.options.valName}/auth/token`, this.options.valBuildUrl);
|
|
1301
1302
|
url.searchParams.set("code", encodeURIComponent(code));
|
|
1302
1303
|
return fetch(url, {
|
|
1303
1304
|
method: "POST",
|
|
@@ -1323,7 +1324,7 @@ class ProxyValServer {
|
|
|
1323
1324
|
});
|
|
1324
1325
|
}
|
|
1325
1326
|
getAuthorizeUrl(publicValApiRoute, token) {
|
|
1326
|
-
const url = new URL(
|
|
1327
|
+
const url = new URL(`/auth/${this.options.valName}/authorize`, this.options.valBuildUrl);
|
|
1327
1328
|
url.searchParams.set("redirect_uri", encodeURIComponent(`${publicValApiRoute}/callback`));
|
|
1328
1329
|
url.searchParams.set("state", token);
|
|
1329
1330
|
return url.toString();
|
|
@@ -1479,6 +1480,10 @@ async function initHandlerOptions(route, opts) {
|
|
|
1479
1480
|
if (!maybeGitBranch) {
|
|
1480
1481
|
throw new Error("VAL_GIT_BRANCH env var must be set in proxy mode");
|
|
1481
1482
|
}
|
|
1483
|
+
const maybeValName = opts.gitBranch || process.env.VAL_NAME;
|
|
1484
|
+
if (!maybeValName) {
|
|
1485
|
+
throw new Error("VAL_NAME env var must be set in proxy mode");
|
|
1486
|
+
}
|
|
1482
1487
|
return {
|
|
1483
1488
|
mode: "proxy",
|
|
1484
1489
|
route,
|
|
@@ -1486,7 +1491,8 @@ async function initHandlerOptions(route, opts) {
|
|
|
1486
1491
|
valSecret: maybeValSecret,
|
|
1487
1492
|
valBuildUrl,
|
|
1488
1493
|
gitCommit: maybeGitCommit,
|
|
1489
|
-
gitBranch: maybeGitBranch
|
|
1494
|
+
gitBranch: maybeGitBranch,
|
|
1495
|
+
valName: maybeValName
|
|
1490
1496
|
};
|
|
1491
1497
|
} else {
|
|
1492
1498
|
const service = await createService(process.cwd(), opts);
|
|
@@ -1549,6 +1555,7 @@ class ValFSHost {
|
|
|
1549
1555
|
}
|
|
1550
1556
|
}
|
|
1551
1557
|
|
|
1558
|
+
// TODO: find a better name? transformFixesToPatch?
|
|
1552
1559
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
1553
1560
|
async function getImageMetadata() {
|
|
1554
1561
|
const maybeRef = validationError.value && typeof validationError.value === "object" && core.FILE_REF_PROP in validationError.value && typeof validationError.value[core.FILE_REF_PROP] === "string" ? validationError.value[core.FILE_REF_PROP] : undefined;
|
|
@@ -1658,6 +1665,7 @@ const getSHA256Hash = async bits => {
|
|
|
1658
1665
|
};
|
|
1659
1666
|
|
|
1660
1667
|
exports.LocalValServer = LocalValServer;
|
|
1668
|
+
exports.PatchJSON = PatchJSON;
|
|
1661
1669
|
exports.Service = Service;
|
|
1662
1670
|
exports.ValFSHost = ValFSHost;
|
|
1663
1671
|
exports.ValModuleLoader = ValModuleLoader;
|
|
@@ -1179,8 +1179,9 @@ class ProxyValServer {
|
|
|
1179
1179
|
}
|
|
1180
1180
|
}
|
|
1181
1181
|
async session(req, res) {
|
|
1182
|
+
console.log("hit session");
|
|
1182
1183
|
return this.withAuth(req, res, async data => {
|
|
1183
|
-
const url = new URL(
|
|
1184
|
+
const url = new URL(`/api/val/${this.options.valName}/auth/session`, this.options.valBuildUrl);
|
|
1184
1185
|
const fetchRes = await fetch(url, {
|
|
1185
1186
|
headers: this.getAuthHeaders(data.token, "application/json")
|
|
1186
1187
|
});
|
|
@@ -1283,7 +1284,7 @@ class ProxyValServer {
|
|
|
1283
1284
|
};
|
|
1284
1285
|
}
|
|
1285
1286
|
async consumeCode(code) {
|
|
1286
|
-
const url = new URL(
|
|
1287
|
+
const url = new URL(`/api/val/${this.options.valName}/auth/token`, this.options.valBuildUrl);
|
|
1287
1288
|
url.searchParams.set("code", encodeURIComponent(code));
|
|
1288
1289
|
return fetch(url, {
|
|
1289
1290
|
method: "POST",
|
|
@@ -1309,7 +1310,7 @@ class ProxyValServer {
|
|
|
1309
1310
|
});
|
|
1310
1311
|
}
|
|
1311
1312
|
getAuthorizeUrl(publicValApiRoute, token) {
|
|
1312
|
-
const url = new URL(
|
|
1313
|
+
const url = new URL(`/auth/${this.options.valName}/authorize`, this.options.valBuildUrl);
|
|
1313
1314
|
url.searchParams.set("redirect_uri", encodeURIComponent(`${publicValApiRoute}/callback`));
|
|
1314
1315
|
url.searchParams.set("state", token);
|
|
1315
1316
|
return url.toString();
|
|
@@ -1465,6 +1466,10 @@ async function initHandlerOptions(route, opts) {
|
|
|
1465
1466
|
if (!maybeGitBranch) {
|
|
1466
1467
|
throw new Error("VAL_GIT_BRANCH env var must be set in proxy mode");
|
|
1467
1468
|
}
|
|
1469
|
+
const maybeValName = opts.gitBranch || process.env.VAL_NAME;
|
|
1470
|
+
if (!maybeValName) {
|
|
1471
|
+
throw new Error("VAL_NAME env var must be set in proxy mode");
|
|
1472
|
+
}
|
|
1468
1473
|
return {
|
|
1469
1474
|
mode: "proxy",
|
|
1470
1475
|
route,
|
|
@@ -1472,7 +1477,8 @@ async function initHandlerOptions(route, opts) {
|
|
|
1472
1477
|
valSecret: maybeValSecret,
|
|
1473
1478
|
valBuildUrl,
|
|
1474
1479
|
gitCommit: maybeGitCommit,
|
|
1475
|
-
gitBranch: maybeGitBranch
|
|
1480
|
+
gitBranch: maybeGitBranch,
|
|
1481
|
+
valName: maybeValName
|
|
1476
1482
|
};
|
|
1477
1483
|
} else {
|
|
1478
1484
|
const service = await createService(process.cwd(), opts);
|
|
@@ -1535,6 +1541,7 @@ class ValFSHost {
|
|
|
1535
1541
|
}
|
|
1536
1542
|
}
|
|
1537
1543
|
|
|
1544
|
+
// TODO: find a better name? transformFixesToPatch?
|
|
1538
1545
|
async function createFixPatch(config, apply, sourcePath, validationError) {
|
|
1539
1546
|
async function getImageMetadata() {
|
|
1540
1547
|
const maybeRef = validationError.value && typeof validationError.value === "object" && FILE_REF_PROP in validationError.value && typeof validationError.value[FILE_REF_PROP] === "string" ? validationError.value[FILE_REF_PROP] : undefined;
|
|
@@ -1643,4 +1650,4 @@ const getSHA256Hash = async bits => {
|
|
|
1643
1650
|
return hash;
|
|
1644
1651
|
};
|
|
1645
1652
|
|
|
1646
|
-
export { LocalValServer, Service, ValFSHost, ValModuleLoader, ValSourceFileHandler, createFixPatch, createRequestHandler, createRequestListener, createService, formatSyntaxErrorTree, getCompilerOptions, patchSourceFile };
|
|
1653
|
+
export { LocalValServer, PatchJSON, Service, ValFSHost, ValModuleLoader, ValSourceFileHandler, createFixPatch, createRequestHandler, createRequestListener, createService, formatSyntaxErrorTree, getCompilerOptions, patchSourceFile };
|
package/package.json
CHANGED
package/src/ProxyValServer.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type ProxyValServerOptions = {
|
|
|
18
18
|
valBuildUrl: string;
|
|
19
19
|
gitCommit: string;
|
|
20
20
|
gitBranch: string;
|
|
21
|
+
valName: string;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
export class ProxyValServer implements ValServer {
|
|
@@ -112,9 +113,10 @@ export class ProxyValServer implements ValServer {
|
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
async session(req: express.Request, res: express.Response): Promise<void> {
|
|
116
|
+
console.log("hit session");
|
|
115
117
|
return this.withAuth(req, res, async (data) => {
|
|
116
118
|
const url = new URL(
|
|
117
|
-
|
|
119
|
+
`/api/val/${this.options.valName}/auth/session`,
|
|
118
120
|
this.options.valBuildUrl
|
|
119
121
|
);
|
|
120
122
|
const fetchRes = await fetch(url, {
|
|
@@ -233,7 +235,10 @@ export class ProxyValServer implements ValServer {
|
|
|
233
235
|
project: string;
|
|
234
236
|
token: string;
|
|
235
237
|
} | null> {
|
|
236
|
-
const url = new URL(
|
|
238
|
+
const url = new URL(
|
|
239
|
+
`/api/val/${this.options.valName}/auth/token`,
|
|
240
|
+
this.options.valBuildUrl
|
|
241
|
+
);
|
|
237
242
|
url.searchParams.set("code", encodeURIComponent(code));
|
|
238
243
|
return fetch(url, {
|
|
239
244
|
method: "POST",
|
|
@@ -262,7 +267,10 @@ export class ProxyValServer implements ValServer {
|
|
|
262
267
|
}
|
|
263
268
|
|
|
264
269
|
private getAuthorizeUrl(publicValApiRoute: string, token: string): string {
|
|
265
|
-
const url = new URL(
|
|
270
|
+
const url = new URL(
|
|
271
|
+
`/auth/${this.options.valName}/authorize`,
|
|
272
|
+
this.options.valBuildUrl
|
|
273
|
+
);
|
|
266
274
|
url.searchParams.set(
|
|
267
275
|
"redirect_uri",
|
|
268
276
|
encodeURIComponent(`${publicValApiRoute}/callback`)
|
package/src/createFixPatch.ts
CHANGED
package/src/hosting.ts
CHANGED
|
@@ -73,6 +73,14 @@ type ValServerOverrides = Partial<{
|
|
|
73
73
|
* @example "https://app.val.build"
|
|
74
74
|
*/
|
|
75
75
|
valBuildUrl: string;
|
|
76
|
+
/**
|
|
77
|
+
* The full name of this Val project.
|
|
78
|
+
*
|
|
79
|
+
* Typically this is set using the VAL_NAME env var.
|
|
80
|
+
*
|
|
81
|
+
* @example "myorg/my-project"
|
|
82
|
+
*/
|
|
83
|
+
valName: string;
|
|
76
84
|
}>;
|
|
77
85
|
|
|
78
86
|
async function _createRequestListener(
|
|
@@ -119,6 +127,10 @@ async function initHandlerOptions(
|
|
|
119
127
|
if (!maybeGitBranch) {
|
|
120
128
|
throw new Error("VAL_GIT_BRANCH env var must be set in proxy mode");
|
|
121
129
|
}
|
|
130
|
+
const maybeValName = opts.gitBranch || process.env.VAL_NAME;
|
|
131
|
+
if (!maybeValName) {
|
|
132
|
+
throw new Error("VAL_NAME env var must be set in proxy mode");
|
|
133
|
+
}
|
|
122
134
|
return {
|
|
123
135
|
mode: "proxy",
|
|
124
136
|
route,
|
|
@@ -127,6 +139,7 @@ async function initHandlerOptions(
|
|
|
127
139
|
valBuildUrl,
|
|
128
140
|
gitCommit: maybeGitCommit,
|
|
129
141
|
gitBranch: maybeGitBranch,
|
|
142
|
+
valName: maybeValName,
|
|
130
143
|
};
|
|
131
144
|
} else {
|
|
132
145
|
const service = await createService(process.cwd(), opts);
|
package/src/index.ts
CHANGED