@valbuild/server 0.41.0 → 0.43.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.
@@ -10,7 +10,8 @@ export declare class ValModuleLoader {
|
|
10
10
|
private readonly disableCache;
|
11
11
|
private cache;
|
12
12
|
private cacheSize;
|
13
|
-
constructor(projectRoot: string, compilerOptions: ts.CompilerOptions,
|
13
|
+
constructor(projectRoot: string, compilerOptions: ts.CompilerOptions, // TODO: remove this?
|
14
|
+
sourceFileHandler: ValSourceFileHandler, host?: IValFSHost, disableCache?: boolean);
|
14
15
|
getModule(modulePath: string): string;
|
15
16
|
resolveModulePath(containingFilePath: string, requestedModuleName: string): string;
|
16
17
|
private findMatchingJsFile;
|
@@ -40,7 +40,7 @@ export interface ValServer {
|
|
40
40
|
id?: string[];
|
41
41
|
}, cookies: ValCookies<VAL_SESSION_COOKIE>): Promise<ValServerJsonResult<ApiGetPatchResponse>>;
|
42
42
|
postPatches(body: unknown, cookies: ValCookies<VAL_SESSION_COOKIE>): Promise<ValServerJsonResult<ApiPostPatchResponse>>;
|
43
|
-
postCommit(cookies: ValCookies<VAL_SESSION_COOKIE>): Promise<ValServerJsonResult<{}>>;
|
43
|
+
postCommit(body: unknown, cookies: ValCookies<VAL_SESSION_COOKIE>): Promise<ValServerJsonResult<{}>>;
|
44
44
|
getFiles(treePath: string, query: {
|
45
45
|
sha256?: string;
|
46
46
|
}, cookies: ValCookies<VAL_SESSION_COOKIE>): Promise<ValServerResult<never, ReadableStream<Uint8Array>>>;
|
@@ -698,6 +698,7 @@ const readValFile = async (id, valConfigPath, runtime) => {
|
|
698
698
|
const modulePath = `.${id}.val`;
|
699
699
|
const code = `import * as valModule from ${JSON.stringify(modulePath)};
|
700
700
|
import { Internal } from "@valbuild/core";
|
701
|
+
|
701
702
|
globalThis.valModule = {
|
702
703
|
id: valModule?.default && Internal.getValPath(valModule?.default),
|
703
704
|
schema: valModule?.default && Internal.getSchema(valModule?.default)?.serialize(),
|
@@ -705,7 +706,8 @@ globalThis.valModule = {
|
|
705
706
|
validation: valModule?.default && Internal.getSchema(valModule?.default)?.validate(
|
706
707
|
valModule?.default && Internal.getValPath(valModule?.default) || "/",
|
707
708
|
valModule?.default && Internal.getSource(valModule?.default)
|
708
|
-
)
|
709
|
+
),
|
710
|
+
defaultExport: !!valModule?.default,
|
709
711
|
};
|
710
712
|
`;
|
711
713
|
const result = context.evalCode(code,
|
@@ -728,8 +730,11 @@ globalThis.valModule = {
|
|
728
730
|
} else {
|
729
731
|
result.value.dispose();
|
730
732
|
const valModule = context.getProp(context.global, "valModule").consume(context.dump);
|
733
|
+
console.log(valModule);
|
731
734
|
if (!valModule) {
|
732
735
|
fatalErrors.push(`Could not find any modules at: ${id}`);
|
736
|
+
} else if (valModule.defaultExport === false) {
|
737
|
+
fatalErrors.push(`Could not find a default export in: ${id}. Check if file has a export default val.content(...)`);
|
733
738
|
} else {
|
734
739
|
if (valModule.id !== id) {
|
735
740
|
fatalErrors.push(`Wrong val.content id! In the file of with: '${id}', found: '${valModule.id}'`);
|
@@ -844,7 +849,9 @@ const MAX_OBJECT_KEY_SIZE = 2 ** 27; // https://stackoverflow.com/questions/1336
|
|
844
849
|
class ValModuleLoader {
|
845
850
|
constructor(projectRoot,
|
846
851
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
847
|
-
compilerOptions,
|
852
|
+
compilerOptions,
|
853
|
+
// TODO: remove this?
|
854
|
+
sourceFileHandler, host = {
|
848
855
|
...ts__default["default"].sys,
|
849
856
|
writeFile: fs__default["default"].writeFileSync
|
850
857
|
}, disableCache = false) {
|
@@ -946,9 +953,9 @@ class ValModuleLoader {
|
|
946
953
|
}
|
947
954
|
|
948
955
|
async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
|
949
|
-
maxStackSize = 1024 *
|
950
|
-
//
|
951
|
-
memoryLimit = 1024 * 640
|
956
|
+
maxStackSize = 1024 * 20,
|
957
|
+
// maximum stack size that works: 1024 * 640 * 8
|
958
|
+
memoryLimit = 1024 * 640 // 640 mbs
|
952
959
|
} = {}) {
|
953
960
|
const runtime = quickJSModule.newRuntime();
|
954
961
|
runtime.setMaxStackSize(maxStackSize);
|
@@ -1068,7 +1075,7 @@ async function createService(projectRoot, opts, host = {
|
|
1068
1075
|
const compilerOptions = getCompilerOptions(projectRoot, host);
|
1069
1076
|
const sourceFileHandler = new ValSourceFileHandler(projectRoot, compilerOptions, host);
|
1070
1077
|
const module = await quickjsEmscripten.newQuickJSWASMModule();
|
1071
|
-
const runtime = await newValQuickJSRuntime(module, loader || new ValModuleLoader(projectRoot, compilerOptions, sourceFileHandler, host));
|
1078
|
+
const runtime = await newValQuickJSRuntime(module, loader || new ValModuleLoader(projectRoot, compilerOptions, sourceFileHandler, host, opts.disableCache === undefined ? process.env.NODE_ENV === "development" ? false : true : opts.disableCache));
|
1072
1079
|
return new Service(opts, sourceFileHandler, runtime);
|
1073
1080
|
}
|
1074
1081
|
class Service {
|
@@ -1389,7 +1396,7 @@ class ProxyValServer {
|
|
1389
1396
|
}
|
1390
1397
|
async getFiles(treePath, query, cookies) {
|
1391
1398
|
return this.withAuth(cookies, "getFiles", async data => {
|
1392
|
-
const url = new URL(`/v1/files/${this.options.valName}
|
1399
|
+
const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
|
1393
1400
|
if (typeof query.sha256 === "string") {
|
1394
1401
|
url.searchParams.append("sha256", query.sha256);
|
1395
1402
|
} else {
|
@@ -1682,12 +1689,21 @@ class ProxyValServer {
|
|
1682
1689
|
});
|
1683
1690
|
}
|
1684
1691
|
async getPatches(query, cookies) {
|
1685
|
-
const patchIds = query.id || [];
|
1686
|
-
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1687
1692
|
return this.withAuth(cookies, "getPatches", async ({
|
1688
1693
|
token
|
1689
1694
|
}) => {
|
1690
|
-
const
|
1695
|
+
const commit = this.options.gitCommit;
|
1696
|
+
if (!commit) {
|
1697
|
+
return {
|
1698
|
+
status: 400,
|
1699
|
+
body: {
|
1700
|
+
message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
|
1701
|
+
}
|
1702
|
+
};
|
1703
|
+
}
|
1704
|
+
const patchIds = query.id || [];
|
1705
|
+
const params = patchIds.length > 0 ? `commit=${encodeURIComponent(commit)}&${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : `commit=${encodeURIComponent(commit)}`;
|
1706
|
+
const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
|
1691
1707
|
// Proxy patch to val.build
|
1692
1708
|
const fetchRes = await fetch(url, {
|
1693
1709
|
method: "GET",
|
@@ -1762,14 +1778,28 @@ class ProxyValServer {
|
|
1762
1778
|
}
|
1763
1779
|
});
|
1764
1780
|
}
|
1765
|
-
async postCommit(cookies) {
|
1781
|
+
async postCommit(rawBody, cookies) {
|
1782
|
+
const commit = this.options.gitCommit;
|
1783
|
+
if (!commit) {
|
1784
|
+
return {
|
1785
|
+
status: 401,
|
1786
|
+
json: {
|
1787
|
+
message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
|
1788
|
+
}
|
1789
|
+
};
|
1790
|
+
}
|
1791
|
+
const params = new URLSearchParams({
|
1792
|
+
commit
|
1793
|
+
});
|
1766
1794
|
return this.withAuth(cookies, "postCommit", async ({
|
1767
1795
|
token
|
1768
1796
|
}) => {
|
1769
|
-
const url = new URL(`/
|
1797
|
+
const url = new URL(`/v1/commit/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
|
1798
|
+
const body = JSON.stringify(rawBody);
|
1770
1799
|
const fetchRes = await fetch(url, {
|
1771
1800
|
method: "POST",
|
1772
|
-
headers: this.getAuthHeaders(token)
|
1801
|
+
headers: this.getAuthHeaders(token, "application/json"),
|
1802
|
+
body
|
1773
1803
|
});
|
1774
1804
|
if (fetchRes.status === 200) {
|
1775
1805
|
return {
|
@@ -2138,7 +2168,8 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
2138
2168
|
redirect_to: url.searchParams.get("redirect_to") || undefined
|
2139
2169
|
}));
|
2140
2170
|
} else if (method === "POST" && path === "/commit") {
|
2141
|
-
|
2171
|
+
const body = await req.json();
|
2172
|
+
return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
|
2142
2173
|
} else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
|
2143
2174
|
return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
|
2144
2175
|
patch: url.searchParams.get("patch") || undefined,
|
@@ -698,6 +698,7 @@ const readValFile = async (id, valConfigPath, runtime) => {
|
|
698
698
|
const modulePath = `.${id}.val`;
|
699
699
|
const code = `import * as valModule from ${JSON.stringify(modulePath)};
|
700
700
|
import { Internal } from "@valbuild/core";
|
701
|
+
|
701
702
|
globalThis.valModule = {
|
702
703
|
id: valModule?.default && Internal.getValPath(valModule?.default),
|
703
704
|
schema: valModule?.default && Internal.getSchema(valModule?.default)?.serialize(),
|
@@ -705,7 +706,8 @@ globalThis.valModule = {
|
|
705
706
|
validation: valModule?.default && Internal.getSchema(valModule?.default)?.validate(
|
706
707
|
valModule?.default && Internal.getValPath(valModule?.default) || "/",
|
707
708
|
valModule?.default && Internal.getSource(valModule?.default)
|
708
|
-
)
|
709
|
+
),
|
710
|
+
defaultExport: !!valModule?.default,
|
709
711
|
};
|
710
712
|
`;
|
711
713
|
const result = context.evalCode(code,
|
@@ -728,8 +730,11 @@ globalThis.valModule = {
|
|
728
730
|
} else {
|
729
731
|
result.value.dispose();
|
730
732
|
const valModule = context.getProp(context.global, "valModule").consume(context.dump);
|
733
|
+
console.log(valModule);
|
731
734
|
if (!valModule) {
|
732
735
|
fatalErrors.push(`Could not find any modules at: ${id}`);
|
736
|
+
} else if (valModule.defaultExport === false) {
|
737
|
+
fatalErrors.push(`Could not find a default export in: ${id}. Check if file has a export default val.content(...)`);
|
733
738
|
} else {
|
734
739
|
if (valModule.id !== id) {
|
735
740
|
fatalErrors.push(`Wrong val.content id! In the file of with: '${id}', found: '${valModule.id}'`);
|
@@ -844,7 +849,9 @@ const MAX_OBJECT_KEY_SIZE = 2 ** 27; // https://stackoverflow.com/questions/1336
|
|
844
849
|
class ValModuleLoader {
|
845
850
|
constructor(projectRoot,
|
846
851
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
847
|
-
compilerOptions,
|
852
|
+
compilerOptions,
|
853
|
+
// TODO: remove this?
|
854
|
+
sourceFileHandler, host = {
|
848
855
|
...ts__default["default"].sys,
|
849
856
|
writeFile: fs__default["default"].writeFileSync
|
850
857
|
}, disableCache = false) {
|
@@ -946,9 +953,9 @@ class ValModuleLoader {
|
|
946
953
|
}
|
947
954
|
|
948
955
|
async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
|
949
|
-
maxStackSize = 1024 *
|
950
|
-
//
|
951
|
-
memoryLimit = 1024 * 640
|
956
|
+
maxStackSize = 1024 * 20,
|
957
|
+
// maximum stack size that works: 1024 * 640 * 8
|
958
|
+
memoryLimit = 1024 * 640 // 640 mbs
|
952
959
|
} = {}) {
|
953
960
|
const runtime = quickJSModule.newRuntime();
|
954
961
|
runtime.setMaxStackSize(maxStackSize);
|
@@ -1068,7 +1075,7 @@ async function createService(projectRoot, opts, host = {
|
|
1068
1075
|
const compilerOptions = getCompilerOptions(projectRoot, host);
|
1069
1076
|
const sourceFileHandler = new ValSourceFileHandler(projectRoot, compilerOptions, host);
|
1070
1077
|
const module = await quickjsEmscripten.newQuickJSWASMModule();
|
1071
|
-
const runtime = await newValQuickJSRuntime(module, loader || new ValModuleLoader(projectRoot, compilerOptions, sourceFileHandler, host));
|
1078
|
+
const runtime = await newValQuickJSRuntime(module, loader || new ValModuleLoader(projectRoot, compilerOptions, sourceFileHandler, host, opts.disableCache === undefined ? true : opts.disableCache));
|
1072
1079
|
return new Service(opts, sourceFileHandler, runtime);
|
1073
1080
|
}
|
1074
1081
|
class Service {
|
@@ -1389,7 +1396,7 @@ class ProxyValServer {
|
|
1389
1396
|
}
|
1390
1397
|
async getFiles(treePath, query, cookies) {
|
1391
1398
|
return this.withAuth(cookies, "getFiles", async data => {
|
1392
|
-
const url = new URL(`/v1/files/${this.options.valName}
|
1399
|
+
const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
|
1393
1400
|
if (typeof query.sha256 === "string") {
|
1394
1401
|
url.searchParams.append("sha256", query.sha256);
|
1395
1402
|
} else {
|
@@ -1682,12 +1689,21 @@ class ProxyValServer {
|
|
1682
1689
|
});
|
1683
1690
|
}
|
1684
1691
|
async getPatches(query, cookies) {
|
1685
|
-
const patchIds = query.id || [];
|
1686
|
-
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1687
1692
|
return this.withAuth(cookies, "getPatches", async ({
|
1688
1693
|
token
|
1689
1694
|
}) => {
|
1690
|
-
const
|
1695
|
+
const commit = this.options.gitCommit;
|
1696
|
+
if (!commit) {
|
1697
|
+
return {
|
1698
|
+
status: 400,
|
1699
|
+
body: {
|
1700
|
+
message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
|
1701
|
+
}
|
1702
|
+
};
|
1703
|
+
}
|
1704
|
+
const patchIds = query.id || [];
|
1705
|
+
const params = patchIds.length > 0 ? `commit=${encodeURIComponent(commit)}&${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : `commit=${encodeURIComponent(commit)}`;
|
1706
|
+
const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
|
1691
1707
|
// Proxy patch to val.build
|
1692
1708
|
const fetchRes = await fetch(url, {
|
1693
1709
|
method: "GET",
|
@@ -1762,14 +1778,28 @@ class ProxyValServer {
|
|
1762
1778
|
}
|
1763
1779
|
});
|
1764
1780
|
}
|
1765
|
-
async postCommit(cookies) {
|
1781
|
+
async postCommit(rawBody, cookies) {
|
1782
|
+
const commit = this.options.gitCommit;
|
1783
|
+
if (!commit) {
|
1784
|
+
return {
|
1785
|
+
status: 401,
|
1786
|
+
json: {
|
1787
|
+
message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
|
1788
|
+
}
|
1789
|
+
};
|
1790
|
+
}
|
1791
|
+
const params = new URLSearchParams({
|
1792
|
+
commit
|
1793
|
+
});
|
1766
1794
|
return this.withAuth(cookies, "postCommit", async ({
|
1767
1795
|
token
|
1768
1796
|
}) => {
|
1769
|
-
const url = new URL(`/
|
1797
|
+
const url = new URL(`/v1/commit/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
|
1798
|
+
const body = JSON.stringify(rawBody);
|
1770
1799
|
const fetchRes = await fetch(url, {
|
1771
1800
|
method: "POST",
|
1772
|
-
headers: this.getAuthHeaders(token)
|
1801
|
+
headers: this.getAuthHeaders(token, "application/json"),
|
1802
|
+
body
|
1773
1803
|
});
|
1774
1804
|
if (fetchRes.status === 200) {
|
1775
1805
|
return {
|
@@ -2138,7 +2168,8 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
2138
2168
|
redirect_to: url.searchParams.get("redirect_to") || undefined
|
2139
2169
|
}));
|
2140
2170
|
} else if (method === "POST" && path === "/commit") {
|
2141
|
-
|
2171
|
+
const body = await req.json();
|
2172
|
+
return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
|
2142
2173
|
} else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
|
2143
2174
|
return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
|
2144
2175
|
patch: url.searchParams.get("patch") || undefined,
|
@@ -668,6 +668,7 @@ const readValFile = async (id, valConfigPath, runtime) => {
|
|
668
668
|
const modulePath = `.${id}.val`;
|
669
669
|
const code = `import * as valModule from ${JSON.stringify(modulePath)};
|
670
670
|
import { Internal } from "@valbuild/core";
|
671
|
+
|
671
672
|
globalThis.valModule = {
|
672
673
|
id: valModule?.default && Internal.getValPath(valModule?.default),
|
673
674
|
schema: valModule?.default && Internal.getSchema(valModule?.default)?.serialize(),
|
@@ -675,7 +676,8 @@ globalThis.valModule = {
|
|
675
676
|
validation: valModule?.default && Internal.getSchema(valModule?.default)?.validate(
|
676
677
|
valModule?.default && Internal.getValPath(valModule?.default) || "/",
|
677
678
|
valModule?.default && Internal.getSource(valModule?.default)
|
678
|
-
)
|
679
|
+
),
|
680
|
+
defaultExport: !!valModule?.default,
|
679
681
|
};
|
680
682
|
`;
|
681
683
|
const result = context.evalCode(code,
|
@@ -698,8 +700,11 @@ globalThis.valModule = {
|
|
698
700
|
} else {
|
699
701
|
result.value.dispose();
|
700
702
|
const valModule = context.getProp(context.global, "valModule").consume(context.dump);
|
703
|
+
console.log(valModule);
|
701
704
|
if (!valModule) {
|
702
705
|
fatalErrors.push(`Could not find any modules at: ${id}`);
|
706
|
+
} else if (valModule.defaultExport === false) {
|
707
|
+
fatalErrors.push(`Could not find a default export in: ${id}. Check if file has a export default val.content(...)`);
|
703
708
|
} else {
|
704
709
|
if (valModule.id !== id) {
|
705
710
|
fatalErrors.push(`Wrong val.content id! In the file of with: '${id}', found: '${valModule.id}'`);
|
@@ -814,7 +819,9 @@ const MAX_OBJECT_KEY_SIZE = 2 ** 27; // https://stackoverflow.com/questions/1336
|
|
814
819
|
class ValModuleLoader {
|
815
820
|
constructor(projectRoot,
|
816
821
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
817
|
-
compilerOptions,
|
822
|
+
compilerOptions,
|
823
|
+
// TODO: remove this?
|
824
|
+
sourceFileHandler, host = {
|
818
825
|
...ts.sys,
|
819
826
|
writeFile: fs.writeFileSync
|
820
827
|
}, disableCache = false) {
|
@@ -916,9 +923,9 @@ class ValModuleLoader {
|
|
916
923
|
}
|
917
924
|
|
918
925
|
async function newValQuickJSRuntime(quickJSModule, moduleLoader, {
|
919
|
-
maxStackSize = 1024 *
|
920
|
-
//
|
921
|
-
memoryLimit = 1024 * 640
|
926
|
+
maxStackSize = 1024 * 20,
|
927
|
+
// maximum stack size that works: 1024 * 640 * 8
|
928
|
+
memoryLimit = 1024 * 640 // 640 mbs
|
922
929
|
} = {}) {
|
923
930
|
const runtime = quickJSModule.newRuntime();
|
924
931
|
runtime.setMaxStackSize(maxStackSize);
|
@@ -1038,7 +1045,7 @@ async function createService(projectRoot, opts, host = {
|
|
1038
1045
|
const compilerOptions = getCompilerOptions(projectRoot, host);
|
1039
1046
|
const sourceFileHandler = new ValSourceFileHandler(projectRoot, compilerOptions, host);
|
1040
1047
|
const module = await newQuickJSWASMModule();
|
1041
|
-
const runtime = await newValQuickJSRuntime(module, loader || new ValModuleLoader(projectRoot, compilerOptions, sourceFileHandler, host));
|
1048
|
+
const runtime = await newValQuickJSRuntime(module, loader || new ValModuleLoader(projectRoot, compilerOptions, sourceFileHandler, host, opts.disableCache === undefined ? process.env.NODE_ENV === "development" ? false : true : opts.disableCache));
|
1042
1049
|
return new Service(opts, sourceFileHandler, runtime);
|
1043
1050
|
}
|
1044
1051
|
class Service {
|
@@ -1359,7 +1366,7 @@ class ProxyValServer {
|
|
1359
1366
|
}
|
1360
1367
|
async getFiles(treePath, query, cookies) {
|
1361
1368
|
return this.withAuth(cookies, "getFiles", async data => {
|
1362
|
-
const url = new URL(`/v1/files/${this.options.valName}
|
1369
|
+
const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
|
1363
1370
|
if (typeof query.sha256 === "string") {
|
1364
1371
|
url.searchParams.append("sha256", query.sha256);
|
1365
1372
|
} else {
|
@@ -1652,12 +1659,21 @@ class ProxyValServer {
|
|
1652
1659
|
});
|
1653
1660
|
}
|
1654
1661
|
async getPatches(query, cookies) {
|
1655
|
-
const patchIds = query.id || [];
|
1656
|
-
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1657
1662
|
return this.withAuth(cookies, "getPatches", async ({
|
1658
1663
|
token
|
1659
1664
|
}) => {
|
1660
|
-
const
|
1665
|
+
const commit = this.options.gitCommit;
|
1666
|
+
if (!commit) {
|
1667
|
+
return {
|
1668
|
+
status: 400,
|
1669
|
+
body: {
|
1670
|
+
message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
|
1671
|
+
}
|
1672
|
+
};
|
1673
|
+
}
|
1674
|
+
const patchIds = query.id || [];
|
1675
|
+
const params = patchIds.length > 0 ? `commit=${encodeURIComponent(commit)}&${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : `commit=${encodeURIComponent(commit)}`;
|
1676
|
+
const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
|
1661
1677
|
// Proxy patch to val.build
|
1662
1678
|
const fetchRes = await fetch(url, {
|
1663
1679
|
method: "GET",
|
@@ -1732,14 +1748,28 @@ class ProxyValServer {
|
|
1732
1748
|
}
|
1733
1749
|
});
|
1734
1750
|
}
|
1735
|
-
async postCommit(cookies) {
|
1751
|
+
async postCommit(rawBody, cookies) {
|
1752
|
+
const commit = this.options.gitCommit;
|
1753
|
+
if (!commit) {
|
1754
|
+
return {
|
1755
|
+
status: 401,
|
1756
|
+
json: {
|
1757
|
+
message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
|
1758
|
+
}
|
1759
|
+
};
|
1760
|
+
}
|
1761
|
+
const params = new URLSearchParams({
|
1762
|
+
commit
|
1763
|
+
});
|
1736
1764
|
return this.withAuth(cookies, "postCommit", async ({
|
1737
1765
|
token
|
1738
1766
|
}) => {
|
1739
|
-
const url = new URL(`/
|
1767
|
+
const url = new URL(`/v1/commit/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
|
1768
|
+
const body = JSON.stringify(rawBody);
|
1740
1769
|
const fetchRes = await fetch(url, {
|
1741
1770
|
method: "POST",
|
1742
|
-
headers: this.getAuthHeaders(token)
|
1771
|
+
headers: this.getAuthHeaders(token, "application/json"),
|
1772
|
+
body
|
1743
1773
|
});
|
1744
1774
|
if (fetchRes.status === 200) {
|
1745
1775
|
return {
|
@@ -2108,7 +2138,8 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
2108
2138
|
redirect_to: url.searchParams.get("redirect_to") || undefined
|
2109
2139
|
}));
|
2110
2140
|
} else if (method === "POST" && path === "/commit") {
|
2111
|
-
|
2141
|
+
const body = await req.json();
|
2142
|
+
return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
|
2112
2143
|
} else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
|
2113
2144
|
return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
|
2114
2145
|
patch: url.searchParams.get("patch") || undefined,
|
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.43.0",
|
16
16
|
"scripts": {
|
17
17
|
"typecheck": "tsc --noEmit",
|
18
18
|
"test": "jest",
|
@@ -24,9 +24,9 @@
|
|
24
24
|
"concurrently": "^7.6.0"
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
|
-
"@valbuild/core": "~0.
|
28
|
-
"@valbuild/shared": "~0.
|
29
|
-
"@valbuild/ui": "~0.
|
27
|
+
"@valbuild/core": "~0.43.0",
|
28
|
+
"@valbuild/shared": "~0.43.0",
|
29
|
+
"@valbuild/ui": "~0.43.0",
|
30
30
|
"express": "^4.18.2",
|
31
31
|
"image-size": "^1.0.2",
|
32
32
|
"queue": "^6.0.2",
|