@valbuild/server 0.42.0 → 0.43.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.
@@ -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,
@@ -730,6 +732,8 @@ globalThis.valModule = {
730
732
  const valModule = context.getProp(context.global, "valModule").consume(context.dump);
731
733
  if (!valModule) {
732
734
  fatalErrors.push(`Could not find any modules at: ${id}`);
735
+ } else if (valModule.defaultExport === false) {
736
+ fatalErrors.push(`Could not find a default export in: ${id}. Check if file has a export default val.content(...)`);
733
737
  } else {
734
738
  if (valModule.id !== id) {
735
739
  fatalErrors.push(`Wrong val.content id! In the file of with: '${id}', found: '${valModule.id}'`);
@@ -1391,7 +1395,7 @@ class ProxyValServer {
1391
1395
  }
1392
1396
  async getFiles(treePath, query, cookies) {
1393
1397
  return this.withAuth(cookies, "getFiles", async data => {
1394
- const url = new URL(`/v1/files/${this.options.valName}/~${treePath}`, this.options.valContentUrl);
1398
+ const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
1395
1399
  if (typeof query.sha256 === "string") {
1396
1400
  url.searchParams.append("sha256", query.sha256);
1397
1401
  } else {
@@ -1684,12 +1688,21 @@ class ProxyValServer {
1684
1688
  });
1685
1689
  }
1686
1690
  async getPatches(query, cookies) {
1687
- const patchIds = query.id || [];
1688
- const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
1689
1691
  return this.withAuth(cookies, "getPatches", async ({
1690
1692
  token
1691
1693
  }) => {
1692
- const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~${params}`, this.options.valContentUrl);
1694
+ const commit = this.options.gitCommit;
1695
+ if (!commit) {
1696
+ return {
1697
+ status: 400,
1698
+ body: {
1699
+ message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
1700
+ }
1701
+ };
1702
+ }
1703
+ const patchIds = query.id || [];
1704
+ const params = patchIds.length > 0 ? `commit=${encodeURIComponent(commit)}&${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : `commit=${encodeURIComponent(commit)}`;
1705
+ const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
1693
1706
  // Proxy patch to val.build
1694
1707
  const fetchRes = await fetch(url, {
1695
1708
  method: "GET",
@@ -1764,14 +1777,28 @@ class ProxyValServer {
1764
1777
  }
1765
1778
  });
1766
1779
  }
1767
- async postCommit(cookies) {
1780
+ async postCommit(rawBody, cookies) {
1781
+ const commit = this.options.gitCommit;
1782
+ if (!commit) {
1783
+ return {
1784
+ status: 401,
1785
+ json: {
1786
+ message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
1787
+ }
1788
+ };
1789
+ }
1790
+ const params = new URLSearchParams({
1791
+ commit
1792
+ });
1768
1793
  return this.withAuth(cookies, "postCommit", async ({
1769
1794
  token
1770
1795
  }) => {
1771
- const url = new URL(`/api/val/commit/${encodeURIComponent(this.options.gitBranch)}`, this.options.valBuildUrl);
1796
+ const url = new URL(`/v1/commit/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
1797
+ const body = JSON.stringify(rawBody);
1772
1798
  const fetchRes = await fetch(url, {
1773
1799
  method: "POST",
1774
- headers: this.getAuthHeaders(token)
1800
+ headers: this.getAuthHeaders(token, "application/json"),
1801
+ body
1775
1802
  });
1776
1803
  if (fetchRes.status === 200) {
1777
1804
  return {
@@ -2140,7 +2167,8 @@ function createValApiRouter(route, valServerPromise, convert) {
2140
2167
  redirect_to: url.searchParams.get("redirect_to") || undefined
2141
2168
  }));
2142
2169
  } else if (method === "POST" && path === "/commit") {
2143
- return convert(await valServer.postCommit(getCookies(req, [VAL_SESSION_COOKIE])));
2170
+ const body = await req.json();
2171
+ return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
2144
2172
  } else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
2145
2173
  return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
2146
2174
  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,
@@ -730,6 +732,8 @@ globalThis.valModule = {
730
732
  const valModule = context.getProp(context.global, "valModule").consume(context.dump);
731
733
  if (!valModule) {
732
734
  fatalErrors.push(`Could not find any modules at: ${id}`);
735
+ } else if (valModule.defaultExport === false) {
736
+ fatalErrors.push(`Could not find a default export in: ${id}. Check if file has a export default val.content(...)`);
733
737
  } else {
734
738
  if (valModule.id !== id) {
735
739
  fatalErrors.push(`Wrong val.content id! In the file of with: '${id}', found: '${valModule.id}'`);
@@ -1391,7 +1395,7 @@ class ProxyValServer {
1391
1395
  }
1392
1396
  async getFiles(treePath, query, cookies) {
1393
1397
  return this.withAuth(cookies, "getFiles", async data => {
1394
- const url = new URL(`/v1/files/${this.options.valName}/~${treePath}`, this.options.valContentUrl);
1398
+ const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
1395
1399
  if (typeof query.sha256 === "string") {
1396
1400
  url.searchParams.append("sha256", query.sha256);
1397
1401
  } else {
@@ -1684,12 +1688,21 @@ class ProxyValServer {
1684
1688
  });
1685
1689
  }
1686
1690
  async getPatches(query, cookies) {
1687
- const patchIds = query.id || [];
1688
- const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
1689
1691
  return this.withAuth(cookies, "getPatches", async ({
1690
1692
  token
1691
1693
  }) => {
1692
- const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~${params}`, this.options.valContentUrl);
1694
+ const commit = this.options.gitCommit;
1695
+ if (!commit) {
1696
+ return {
1697
+ status: 400,
1698
+ body: {
1699
+ message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
1700
+ }
1701
+ };
1702
+ }
1703
+ const patchIds = query.id || [];
1704
+ const params = patchIds.length > 0 ? `commit=${encodeURIComponent(commit)}&${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : `commit=${encodeURIComponent(commit)}`;
1705
+ const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
1693
1706
  // Proxy patch to val.build
1694
1707
  const fetchRes = await fetch(url, {
1695
1708
  method: "GET",
@@ -1764,14 +1777,28 @@ class ProxyValServer {
1764
1777
  }
1765
1778
  });
1766
1779
  }
1767
- async postCommit(cookies) {
1780
+ async postCommit(rawBody, cookies) {
1781
+ const commit = this.options.gitCommit;
1782
+ if (!commit) {
1783
+ return {
1784
+ status: 401,
1785
+ json: {
1786
+ message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
1787
+ }
1788
+ };
1789
+ }
1790
+ const params = new URLSearchParams({
1791
+ commit
1792
+ });
1768
1793
  return this.withAuth(cookies, "postCommit", async ({
1769
1794
  token
1770
1795
  }) => {
1771
- const url = new URL(`/api/val/commit/${encodeURIComponent(this.options.gitBranch)}`, this.options.valBuildUrl);
1796
+ const url = new URL(`/v1/commit/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
1797
+ const body = JSON.stringify(rawBody);
1772
1798
  const fetchRes = await fetch(url, {
1773
1799
  method: "POST",
1774
- headers: this.getAuthHeaders(token)
1800
+ headers: this.getAuthHeaders(token, "application/json"),
1801
+ body
1775
1802
  });
1776
1803
  if (fetchRes.status === 200) {
1777
1804
  return {
@@ -2140,7 +2167,8 @@ function createValApiRouter(route, valServerPromise, convert) {
2140
2167
  redirect_to: url.searchParams.get("redirect_to") || undefined
2141
2168
  }));
2142
2169
  } else if (method === "POST" && path === "/commit") {
2143
- return convert(await valServer.postCommit(getCookies(req, [VAL_SESSION_COOKIE])));
2170
+ const body = await req.json();
2171
+ return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
2144
2172
  } else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
2145
2173
  return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
2146
2174
  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,
@@ -700,6 +702,8 @@ globalThis.valModule = {
700
702
  const valModule = context.getProp(context.global, "valModule").consume(context.dump);
701
703
  if (!valModule) {
702
704
  fatalErrors.push(`Could not find any modules at: ${id}`);
705
+ } else if (valModule.defaultExport === false) {
706
+ fatalErrors.push(`Could not find a default export in: ${id}. Check if file has a export default val.content(...)`);
703
707
  } else {
704
708
  if (valModule.id !== id) {
705
709
  fatalErrors.push(`Wrong val.content id! In the file of with: '${id}', found: '${valModule.id}'`);
@@ -1361,7 +1365,7 @@ class ProxyValServer {
1361
1365
  }
1362
1366
  async getFiles(treePath, query, cookies) {
1363
1367
  return this.withAuth(cookies, "getFiles", async data => {
1364
- const url = new URL(`/v1/files/${this.options.valName}/~${treePath}`, this.options.valContentUrl);
1368
+ const url = new URL(`/v1/files/${this.options.valName}${treePath}`, this.options.valContentUrl);
1365
1369
  if (typeof query.sha256 === "string") {
1366
1370
  url.searchParams.append("sha256", query.sha256);
1367
1371
  } else {
@@ -1654,12 +1658,21 @@ class ProxyValServer {
1654
1658
  });
1655
1659
  }
1656
1660
  async getPatches(query, cookies) {
1657
- const patchIds = query.id || [];
1658
- const params = patchIds.length > 0 ? `?${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : "";
1659
1661
  return this.withAuth(cookies, "getPatches", async ({
1660
1662
  token
1661
1663
  }) => {
1662
- const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~${params}`, this.options.valContentUrl);
1664
+ const commit = this.options.gitCommit;
1665
+ if (!commit) {
1666
+ return {
1667
+ status: 400,
1668
+ body: {
1669
+ message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
1670
+ }
1671
+ };
1672
+ }
1673
+ const patchIds = query.id || [];
1674
+ const params = patchIds.length > 0 ? `commit=${encodeURIComponent(commit)}&${patchIds.map(id => `id=${encodeURIComponent(id)}`).join("&")}` : `commit=${encodeURIComponent(commit)}`;
1675
+ const url = new URL(`/v1/patches/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
1663
1676
  // Proxy patch to val.build
1664
1677
  const fetchRes = await fetch(url, {
1665
1678
  method: "GET",
@@ -1734,14 +1747,28 @@ class ProxyValServer {
1734
1747
  }
1735
1748
  });
1736
1749
  }
1737
- async postCommit(cookies) {
1750
+ async postCommit(rawBody, cookies) {
1751
+ const commit = this.options.gitCommit;
1752
+ if (!commit) {
1753
+ return {
1754
+ status: 401,
1755
+ json: {
1756
+ message: "Could not detect the git commit. Check if env is missing VAL_GIT_COMMIT."
1757
+ }
1758
+ };
1759
+ }
1760
+ const params = new URLSearchParams({
1761
+ commit
1762
+ });
1738
1763
  return this.withAuth(cookies, "postCommit", async ({
1739
1764
  token
1740
1765
  }) => {
1741
- const url = new URL(`/api/val/commit/${encodeURIComponent(this.options.gitBranch)}`, this.options.valBuildUrl);
1766
+ const url = new URL(`/v1/commit/${this.options.valName}/heads/${this.options.gitBranch}/~?${params}`, this.options.valContentUrl);
1767
+ const body = JSON.stringify(rawBody);
1742
1768
  const fetchRes = await fetch(url, {
1743
1769
  method: "POST",
1744
- headers: this.getAuthHeaders(token)
1770
+ headers: this.getAuthHeaders(token, "application/json"),
1771
+ body
1745
1772
  });
1746
1773
  if (fetchRes.status === 200) {
1747
1774
  return {
@@ -2110,7 +2137,8 @@ function createValApiRouter(route, valServerPromise, convert) {
2110
2137
  redirect_to: url.searchParams.get("redirect_to") || undefined
2111
2138
  }));
2112
2139
  } else if (method === "POST" && path === "/commit") {
2113
- return convert(await valServer.postCommit(getCookies(req, [VAL_SESSION_COOKIE])));
2140
+ const body = await req.json();
2141
+ return convert(await valServer.postCommit(body, getCookies(req, [VAL_SESSION_COOKIE])));
2114
2142
  } else if (method === "GET" && path.startsWith(TREE_PATH_PREFIX)) {
2115
2143
  return withTreePath(path, TREE_PATH_PREFIX)(async treePath => convert(await valServer.getTree(treePath, {
2116
2144
  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.42.0",
15
+ "version": "0.43.1",
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.42.0",
28
- "@valbuild/shared": "~0.42.0",
29
- "@valbuild/ui": "~0.42.0",
27
+ "@valbuild/core": "~0.43.1",
28
+ "@valbuild/shared": "~0.43.1",
29
+ "@valbuild/ui": "~0.43.1",
30
30
  "express": "^4.18.2",
31
31
  "image-size": "^1.0.2",
32
32
  "queue": "^6.0.2",