@valbuild/server 0.42.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.
@@ -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}'`);
|
@@ -1391,7 +1396,7 @@ class ProxyValServer {
|
|
1391
1396
|
}
|
1392
1397
|
async getFiles(treePath, query, cookies) {
|
1393
1398
|
return this.withAuth(cookies, "getFiles", async data => {
|
1394
|
-
const url = new URL(`/v1/files/${this.options.valName}
|
1399
|
+
const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
|
1395
1400
|
if (typeof query.sha256 === "string") {
|
1396
1401
|
url.searchParams.append("sha256", query.sha256);
|
1397
1402
|
} else {
|
@@ -1684,12 +1689,21 @@ class ProxyValServer {
|
|
1684
1689
|
});
|
1685
1690
|
}
|
1686
1691
|
async getPatches(query, cookies) {
|
1687
|
-
const patchIds = query.id || [];
|
1688
|
-
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1689
1692
|
return this.withAuth(cookies, "getPatches", async ({
|
1690
1693
|
token
|
1691
1694
|
}) => {
|
1692
|
-
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);
|
1693
1707
|
// Proxy patch to val.build
|
1694
1708
|
const fetchRes = await fetch(url, {
|
1695
1709
|
method: "GET",
|
@@ -1764,14 +1778,28 @@ class ProxyValServer {
|
|
1764
1778
|
}
|
1765
1779
|
});
|
1766
1780
|
}
|
1767
|
-
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
|
+
});
|
1768
1794
|
return this.withAuth(cookies, "postCommit", async ({
|
1769
1795
|
token
|
1770
1796
|
}) => {
|
1771
|
-
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);
|
1772
1799
|
const fetchRes = await fetch(url, {
|
1773
1800
|
method: "POST",
|
1774
|
-
headers: this.getAuthHeaders(token)
|
1801
|
+
headers: this.getAuthHeaders(token, "application/json"),
|
1802
|
+
body
|
1775
1803
|
});
|
1776
1804
|
if (fetchRes.status === 200) {
|
1777
1805
|
return {
|
@@ -2140,7 +2168,8 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
2140
2168
|
redirect_to: url.searchParams.get("redirect_to") || undefined
|
2141
2169
|
}));
|
2142
2170
|
} else if (method === "POST" && path === "/commit") {
|
2143
|
-
|
2171
|
+
const body = await req.json();
|
2172
|
+
return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
|
2144
2173
|
} else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
|
2145
2174
|
return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
|
2146
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}'`);
|
@@ -1391,7 +1396,7 @@ class ProxyValServer {
|
|
1391
1396
|
}
|
1392
1397
|
async getFiles(treePath, query, cookies) {
|
1393
1398
|
return this.withAuth(cookies, "getFiles", async data => {
|
1394
|
-
const url = new URL(`/v1/files/${this.options.valName}
|
1399
|
+
const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
|
1395
1400
|
if (typeof query.sha256 === "string") {
|
1396
1401
|
url.searchParams.append("sha256", query.sha256);
|
1397
1402
|
} else {
|
@@ -1684,12 +1689,21 @@ class ProxyValServer {
|
|
1684
1689
|
});
|
1685
1690
|
}
|
1686
1691
|
async getPatches(query, cookies) {
|
1687
|
-
const patchIds = query.id || [];
|
1688
|
-
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1689
1692
|
return this.withAuth(cookies, "getPatches", async ({
|
1690
1693
|
token
|
1691
1694
|
}) => {
|
1692
|
-
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);
|
1693
1707
|
// Proxy patch to val.build
|
1694
1708
|
const fetchRes = await fetch(url, {
|
1695
1709
|
method: "GET",
|
@@ -1764,14 +1778,28 @@ class ProxyValServer {
|
|
1764
1778
|
}
|
1765
1779
|
});
|
1766
1780
|
}
|
1767
|
-
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
|
+
});
|
1768
1794
|
return this.withAuth(cookies, "postCommit", async ({
|
1769
1795
|
token
|
1770
1796
|
}) => {
|
1771
|
-
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);
|
1772
1799
|
const fetchRes = await fetch(url, {
|
1773
1800
|
method: "POST",
|
1774
|
-
headers: this.getAuthHeaders(token)
|
1801
|
+
headers: this.getAuthHeaders(token, "application/json"),
|
1802
|
+
body
|
1775
1803
|
});
|
1776
1804
|
if (fetchRes.status === 200) {
|
1777
1805
|
return {
|
@@ -2140,7 +2168,8 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
2140
2168
|
redirect_to: url.searchParams.get("redirect_to") || undefined
|
2141
2169
|
}));
|
2142
2170
|
} else if (method === "POST" && path === "/commit") {
|
2143
|
-
|
2171
|
+
const body = await req.json();
|
2172
|
+
return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
|
2144
2173
|
} else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
|
2145
2174
|
return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
|
2146
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}'`);
|
@@ -1361,7 +1366,7 @@ class ProxyValServer {
|
|
1361
1366
|
}
|
1362
1367
|
async getFiles(treePath, query, cookies) {
|
1363
1368
|
return this.withAuth(cookies, "getFiles", async data => {
|
1364
|
-
const url = new URL(`/v1/files/${this.options.valName}
|
1369
|
+
const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
|
1365
1370
|
if (typeof query.sha256 === "string") {
|
1366
1371
|
url.searchParams.append("sha256", query.sha256);
|
1367
1372
|
} else {
|
@@ -1654,12 +1659,21 @@ class ProxyValServer {
|
|
1654
1659
|
});
|
1655
1660
|
}
|
1656
1661
|
async getPatches(query, cookies) {
|
1657
|
-
const patchIds = query.id || [];
|
1658
|
-
const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
|
1659
1662
|
return this.withAuth(cookies, "getPatches", async ({
|
1660
1663
|
token
|
1661
1664
|
}) => {
|
1662
|
-
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);
|
1663
1677
|
// Proxy patch to val.build
|
1664
1678
|
const fetchRes = await fetch(url, {
|
1665
1679
|
method: "GET",
|
@@ -1734,14 +1748,28 @@ class ProxyValServer {
|
|
1734
1748
|
}
|
1735
1749
|
});
|
1736
1750
|
}
|
1737
|
-
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
|
+
});
|
1738
1764
|
return this.withAuth(cookies, "postCommit", async ({
|
1739
1765
|
token
|
1740
1766
|
}) => {
|
1741
|
-
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);
|
1742
1769
|
const fetchRes = await fetch(url, {
|
1743
1770
|
method: "POST",
|
1744
|
-
headers: this.getAuthHeaders(token)
|
1771
|
+
headers: this.getAuthHeaders(token, "application/json"),
|
1772
|
+
body
|
1745
1773
|
});
|
1746
1774
|
if (fetchRes.status === 200) {
|
1747
1775
|
return {
|
@@ -2110,7 +2138,8 @@ function createValApiRouter(route, valServerPromise, convert) {
|
|
2110
2138
|
redirect_to: url.searchParams.get("redirect_to") || undefined
|
2111
2139
|
}));
|
2112
2140
|
} else if (method === "POST" && path === "/commit") {
|
2113
|
-
|
2141
|
+
const body = await req.json();
|
2142
|
+
return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
|
2114
2143
|
} else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
|
2115
2144
|
return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
|
2116
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",
|