@valbuild/server 0.146.2 → 0.147.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/browser/dist/valbuild-server-browser.cjs.d.ts +2 -0
  3. package/browser/dist/valbuild-server-browser.cjs.dev.js +146 -0
  4. package/browser/dist/valbuild-server-browser.cjs.js +7 -0
  5. package/browser/dist/valbuild-server-browser.cjs.prod.js +146 -0
  6. package/browser/dist/valbuild-server-browser.esm.js +142 -0
  7. package/browser/package.json +4 -0
  8. package/dist/ValRouterCore-3fd3d444.cjs.dev.js +9897 -0
  9. package/dist/ValRouterCore-7ffcc08c.cjs.prod.js +9897 -0
  10. package/dist/ValRouterCore-f5004f8f.esm.js +9866 -0
  11. package/dist/declarations/src/ValOps.d.ts +13 -1
  12. package/dist/declarations/src/ValOpsFS.d.ts +1 -0
  13. package/dist/declarations/src/ValOpsHttp.d.ts +11 -0
  14. package/dist/declarations/src/ValOpsMemory.d.ts +9 -0
  15. package/dist/declarations/src/ValRouter.d.ts +1 -1
  16. package/dist/declarations/src/ValServer.d.ts +9 -2
  17. package/dist/declarations/src/browser/inTabFetch.d.ts +27 -0
  18. package/dist/declarations/src/browser/index.d.ts +9 -0
  19. package/dist/declarations/src/fixHandlers.d.ts +1 -1
  20. package/dist/declarations/src/linkCheck/probeUrl.d.ts +40 -0
  21. package/dist/declarations/src/platform.d.ts +39 -0
  22. package/dist/getJsonEntryAtCommit-1e08d724.esm.js +136 -0
  23. package/dist/getJsonEntryAtCommit-df65d861.cjs.prod.js +143 -0
  24. package/dist/getJsonEntryAtCommit-e96beb9e.cjs.dev.js +143 -0
  25. package/dist/jsonValuesModule-427d68c8.esm.js +273 -0
  26. package/dist/jsonValuesModule-8ae503a8.cjs.dev.js +288 -0
  27. package/dist/jsonValuesModule-d1bb8d8f.cjs.prod.js +288 -0
  28. package/dist/ops-0d05feaf.esm.js +353 -0
  29. package/dist/ops-b15239ac.cjs.prod.js +361 -0
  30. package/dist/ops-f37d18c6.cjs.dev.js +361 -0
  31. package/dist/publishKit-580f558a.cjs.prod.js +41 -0
  32. package/dist/publishKit-5865095c.cjs.dev.js +41 -0
  33. package/dist/publishKit-bc8df53d.esm.js +31 -0
  34. package/dist/valbuild-server.cjs.dev.js +7795 -18093
  35. package/dist/valbuild-server.cjs.prod.js +7795 -18093
  36. package/dist/valbuild-server.esm.js +7988 -18285
  37. package/package.json +18 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # @valbuild/server
2
2
 
3
+ ## 0.147.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#876](https://github.com/valbuild/val/pull/876) [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd) Thanks [@freekh](https://github.com/freekh)! - Demo mode: run the Val Studio with no account and no backend (TanStack Start).
8
+
9
+ `<ValApp demo>` starts Val's own server in the visitor's browser tab, and the Studio talks to it there instead of to `/api/val`. Edits show up in the page as they are typed and are held in the tab's memory: nothing is sent anywhere, and a reload starts over. Images and videos can be uploaded too: a small service worker, served by `initValDemoServer()`, hands the upload and the unpublished files to the server in the tab, so an uploaded photo or video shows in the page with nothing leaving the browser. Uploads are capped by their size after encoding. Pair `<ValApp demo>` with `<ValProvider demo>` on the site and `initValDemoServer()` from the new `@valbuild/tanstack/demo` entry on the API route. In a demo the Studio opens with a guided tour, Publish explains what it would do instead of publishing, and Preview in a new tab is shown but disabled.
10
+
11
+ Also:
12
+
13
+ - `@valbuild/server/browser` is a new entry: Val's request handling, bundleable for a browser. The TypeScript compiler, which only publishing and history need, is loaded when they ask for it, so a browser bundle of the server is about 140 KB rather than 3.6 MB.
14
+ - `s.image({ encode })` now scales an image down in browsers that cannot write WebP (Safari), as a JPEG or PNG in the image's own format, instead of uploading it at full size.
15
+ - `GET /profiles` answers with no profiles, rather than an error, when edits are stored locally and no project is configured.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [[`2f09cd5`](https://github.com/valbuild/val/commit/2f09cd5e2f4fc37f06917899f24f9ad2ee8d3a8b), [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd), [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd)]:
20
+ - @valbuild/core@0.147.0
21
+ - @valbuild/shared@0.147.0
22
+ - @valbuild/ui@0.147.0
23
+
24
+ ## 0.146.4
25
+
26
+ ### Patch Changes
27
+
28
+ - [#877](https://github.com/valbuild/val/pull/877) [`c31f609`](https://github.com/valbuild/val/commit/c31f609fdeed79aa0e139fa4f652ba0684e96ea3) Thanks [@freekh](https://github.com/freekh)! - The Studio has an unlinked page, `/val/adept`, for trying out dependency
29
+ upgrades on a hosted project: it computes a lockfile for the live site's
30
+ `package.json`, previews each kind of upgrade from it, and fetches the type
31
+ declarations and TypeScript compiler a typecheck would load. It only shows
32
+ results; nothing on it is staged or published. Nothing links to it yet.
33
+
34
+ For it, the server now forwards Val Build's `/adept/*` routes for a signed-in
35
+ Studio session: lockfiles, upgrades, their jobs, type bundles and the
36
+ compiler. Like everything else the Studio asks Val Build for, they go with the
37
+ project's own credential, and they are open at a proposal's address too,
38
+ since they publish nothing.
39
+
40
+ - Updated dependencies [[`81f2e80`](https://github.com/valbuild/val/commit/81f2e803c4cefdf58bbe6856c06e98ace95a8e0b), [`59ff6c3`](https://github.com/valbuild/val/commit/59ff6c367bc313b2bb7718b00c1641aaccab949d), [`c31f609`](https://github.com/valbuild/val/commit/c31f609fdeed79aa0e139fa4f652ba0684e96ea3)]:
41
+ - @valbuild/shared@0.146.4
42
+ - @valbuild/ui@0.146.4
43
+
3
44
  ## 0.146.2
4
45
 
5
46
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/browser/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsYnVpbGQtc2VydmVyLWJyb3dzZXIuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9kaXN0L2RlY2xhcmF0aW9ucy9zcmMvYnJvd3Nlci9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@valbuild/core');
6
+ var ValRouterCore = require('../../dist/ValRouterCore-3fd3d444.cjs.dev.js');
7
+ require('buffer');
8
+ require('@valbuild/shared/internal');
9
+ require('zod');
10
+ require('zod-validation-error');
11
+ require('@valbuild/core/fp');
12
+ require('@valbuild/core/patch');
13
+ require('image-size');
14
+
15
+ const NO_SESSIONS = "Val: sessions are not available here -- this server runs in the browser, " + "has no secret to sign them with, and serves without authenticating.";
16
+
17
+ /**
18
+ * The platform for a server running in a browser tab.
19
+ *
20
+ * Memory mode only: there is no filesystem for `fs` mode and no credential for
21
+ * `http` mode. Everything else answers as a server without those things does
22
+ * -- no `val login` token, no credential for remote files, no link checks --
23
+ * and the session functions refuse, because a tab has no secret to sign with
24
+ * and the server is constructed with `unsafelyAllowUnauthenticated`, so
25
+ * nothing asks for one.
26
+ */
27
+ const browserPlatform = {
28
+ createOps: (valModules, options) => {
29
+ if (options.mode !== "memory") {
30
+ throw new Error(`Val: a server in the browser runs in memory mode, not '${options.mode}'.`);
31
+ }
32
+ return new ValRouterCore.ValOpsMemory(valModules, {
33
+ formatter: options.formatter,
34
+ config: options.config,
35
+ sourceFiles: options.sourceFiles,
36
+ patchStore: options.patchStore,
37
+ unsafelyAllowUnauthenticated: options.unsafelyAllowUnauthenticated,
38
+ // Nothing can reach a server in a tab but the page it runs in.
39
+ warnUnauthenticated: false,
40
+ contentUrl: options.valContentUrl
41
+ });
42
+ },
43
+ probeUrl: async () => ({
44
+ kind: "skipped",
45
+ message: "Links are not checked in the browser."
46
+ }),
47
+ jwt: {
48
+ verifyJwt: () => ({
49
+ success: false,
50
+ reason: "missing-secret",
51
+ message: NO_SESSIONS
52
+ }),
53
+ decodeJwtWithoutVerifying: () => ({
54
+ success: false,
55
+ reason: "missing-secret",
56
+ message: NO_SESSIONS
57
+ }),
58
+ encodeJwt: () => {
59
+ throw new Error(NO_SESSIONS);
60
+ },
61
+ getExpire: () => Math.floor(Date.now() / 1000) + 60 * 60
62
+ },
63
+ readValLoginToken: async () => null,
64
+ resolveRemoteFileAuth: async () => ({
65
+ status: "error",
66
+ errorCode: "api-key-missing",
67
+ message: "Remote files are not available in the browser."
68
+ })
69
+ };
70
+
71
+ /** A `fetch`, as far as the Studio's client calls one. */
72
+
73
+ /**
74
+ * Val's API, served in this tab: a `fetch` that never touches the network.
75
+ *
76
+ * The whole server -- the router's request parsing, `ValServer`'s routes,
77
+ * memory mode's patch chain -- runs here, exactly as it runs on a server.
78
+ * What is removed is the hop between them, and nothing else, which is why the
79
+ * demo built on it cannot drift from the product: there is no second
80
+ * implementation to drift. See `docs/plans/demo-mode.md`.
81
+ *
82
+ * Memory mode with no source files, because nothing here publishes (only a
83
+ * publish reads `.val.ts` text), and without authentication, because the only
84
+ * caller is the page this runs in.
85
+ */
86
+ function createInTabValFetch(valModules, options) {
87
+ const route = options.route ?? "/api/val";
88
+ const serverConfig = {
89
+ mode: "memory",
90
+ route,
91
+ sourceFiles: {},
92
+ patchStore: options.patchStore,
93
+ unsafelyAllowUnauthenticated: true,
94
+ valContentUrl: core.DEFAULT_CONTENT_HOST,
95
+ config: options.config
96
+ };
97
+ const server = ValRouterCore.ValServer(valModules, serverConfig, {
98
+ // Draft content is the only content a demo has.
99
+ isEnabled: async () => true,
100
+ onEnable: async () => {},
101
+ onDisable: async () => {}
102
+ }, browserPlatform);
103
+ const handle = ValRouterCore.createValRequestHandler(route, Promise.resolve(server), toResponse);
104
+ return (input, init) => {
105
+ const base = typeof window === "undefined" ? "http://localhost" : window.location.origin;
106
+ // A `Request` already has an absolute URL, and `init` overrides what it
107
+ // carries, as it does for `fetch`. Only a string or URL is resolved.
108
+ return handle(input instanceof Request ? new Request(input, init) : new Request(new URL(String(input), base).href, init));
109
+ };
110
+ }
111
+
112
+ /**
113
+ * The server's answer as a `Response`. The same conversion a host makes,
114
+ * less the cookies: a `Response` made in the page cannot set one, and a server
115
+ * that never authenticates has none to set.
116
+ */
117
+ function toResponse(valRes) {
118
+ const headers = new Headers();
119
+ const valResHeaders = "headers" in valRes && valRes.headers || {};
120
+ for (const key in valResHeaders) {
121
+ const value = valResHeaders[key];
122
+ if (typeof value === "string") {
123
+ headers.set(key, value);
124
+ }
125
+ }
126
+ if ("json" in valRes) {
127
+ headers.set("Content-Type", "application/json");
128
+ return new Response(JSON.stringify(valRes.json), {
129
+ headers,
130
+ status: valRes.status
131
+ });
132
+ }
133
+ if (valRes.status === 302) {
134
+ headers.set("Location", valRes.redirectTo);
135
+ return new Response(null, {
136
+ status: valRes.status,
137
+ headers
138
+ });
139
+ }
140
+ return new Response("body" in valRes ? valRes.body : null, {
141
+ headers,
142
+ status: valRes.status
143
+ });
144
+ }
145
+
146
+ exports.createInTabValFetch = createInTabValFetch;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./valbuild-server-browser.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./valbuild-server-browser.cjs.dev.js");
7
+ }
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@valbuild/core');
6
+ var ValRouterCore = require('../../dist/ValRouterCore-7ffcc08c.cjs.prod.js');
7
+ require('buffer');
8
+ require('@valbuild/shared/internal');
9
+ require('zod');
10
+ require('zod-validation-error');
11
+ require('@valbuild/core/fp');
12
+ require('@valbuild/core/patch');
13
+ require('image-size');
14
+
15
+ const NO_SESSIONS = "Val: sessions are not available here -- this server runs in the browser, " + "has no secret to sign them with, and serves without authenticating.";
16
+
17
+ /**
18
+ * The platform for a server running in a browser tab.
19
+ *
20
+ * Memory mode only: there is no filesystem for `fs` mode and no credential for
21
+ * `http` mode. Everything else answers as a server without those things does
22
+ * -- no `val login` token, no credential for remote files, no link checks --
23
+ * and the session functions refuse, because a tab has no secret to sign with
24
+ * and the server is constructed with `unsafelyAllowUnauthenticated`, so
25
+ * nothing asks for one.
26
+ */
27
+ const browserPlatform = {
28
+ createOps: (valModules, options) => {
29
+ if (options.mode !== "memory") {
30
+ throw new Error(`Val: a server in the browser runs in memory mode, not '${options.mode}'.`);
31
+ }
32
+ return new ValRouterCore.ValOpsMemory(valModules, {
33
+ formatter: options.formatter,
34
+ config: options.config,
35
+ sourceFiles: options.sourceFiles,
36
+ patchStore: options.patchStore,
37
+ unsafelyAllowUnauthenticated: options.unsafelyAllowUnauthenticated,
38
+ // Nothing can reach a server in a tab but the page it runs in.
39
+ warnUnauthenticated: false,
40
+ contentUrl: options.valContentUrl
41
+ });
42
+ },
43
+ probeUrl: async () => ({
44
+ kind: "skipped",
45
+ message: "Links are not checked in the browser."
46
+ }),
47
+ jwt: {
48
+ verifyJwt: () => ({
49
+ success: false,
50
+ reason: "missing-secret",
51
+ message: NO_SESSIONS
52
+ }),
53
+ decodeJwtWithoutVerifying: () => ({
54
+ success: false,
55
+ reason: "missing-secret",
56
+ message: NO_SESSIONS
57
+ }),
58
+ encodeJwt: () => {
59
+ throw new Error(NO_SESSIONS);
60
+ },
61
+ getExpire: () => Math.floor(Date.now() / 1000) + 60 * 60
62
+ },
63
+ readValLoginToken: async () => null,
64
+ resolveRemoteFileAuth: async () => ({
65
+ status: "error",
66
+ errorCode: "api-key-missing",
67
+ message: "Remote files are not available in the browser."
68
+ })
69
+ };
70
+
71
+ /** A `fetch`, as far as the Studio's client calls one. */
72
+
73
+ /**
74
+ * Val's API, served in this tab: a `fetch` that never touches the network.
75
+ *
76
+ * The whole server -- the router's request parsing, `ValServer`'s routes,
77
+ * memory mode's patch chain -- runs here, exactly as it runs on a server.
78
+ * What is removed is the hop between them, and nothing else, which is why the
79
+ * demo built on it cannot drift from the product: there is no second
80
+ * implementation to drift. See `docs/plans/demo-mode.md`.
81
+ *
82
+ * Memory mode with no source files, because nothing here publishes (only a
83
+ * publish reads `.val.ts` text), and without authentication, because the only
84
+ * caller is the page this runs in.
85
+ */
86
+ function createInTabValFetch(valModules, options) {
87
+ const route = options.route ?? "/api/val";
88
+ const serverConfig = {
89
+ mode: "memory",
90
+ route,
91
+ sourceFiles: {},
92
+ patchStore: options.patchStore,
93
+ unsafelyAllowUnauthenticated: true,
94
+ valContentUrl: core.DEFAULT_CONTENT_HOST,
95
+ config: options.config
96
+ };
97
+ const server = ValRouterCore.ValServer(valModules, serverConfig, {
98
+ // Draft content is the only content a demo has.
99
+ isEnabled: async () => true,
100
+ onEnable: async () => {},
101
+ onDisable: async () => {}
102
+ }, browserPlatform);
103
+ const handle = ValRouterCore.createValRequestHandler(route, Promise.resolve(server), toResponse);
104
+ return (input, init) => {
105
+ const base = typeof window === "undefined" ? "http://localhost" : window.location.origin;
106
+ // A `Request` already has an absolute URL, and `init` overrides what it
107
+ // carries, as it does for `fetch`. Only a string or URL is resolved.
108
+ return handle(input instanceof Request ? new Request(input, init) : new Request(new URL(String(input), base).href, init));
109
+ };
110
+ }
111
+
112
+ /**
113
+ * The server's answer as a `Response`. The same conversion a host makes,
114
+ * less the cookies: a `Response` made in the page cannot set one, and a server
115
+ * that never authenticates has none to set.
116
+ */
117
+ function toResponse(valRes) {
118
+ const headers = new Headers();
119
+ const valResHeaders = "headers" in valRes && valRes.headers || {};
120
+ for (const key in valResHeaders) {
121
+ const value = valResHeaders[key];
122
+ if (typeof value === "string") {
123
+ headers.set(key, value);
124
+ }
125
+ }
126
+ if ("json" in valRes) {
127
+ headers.set("Content-Type", "application/json");
128
+ return new Response(JSON.stringify(valRes.json), {
129
+ headers,
130
+ status: valRes.status
131
+ });
132
+ }
133
+ if (valRes.status === 302) {
134
+ headers.set("Location", valRes.redirectTo);
135
+ return new Response(null, {
136
+ status: valRes.status,
137
+ headers
138
+ });
139
+ }
140
+ return new Response("body" in valRes ? valRes.body : null, {
141
+ headers,
142
+ status: valRes.status
143
+ });
144
+ }
145
+
146
+ exports.createInTabValFetch = createInTabValFetch;
@@ -0,0 +1,142 @@
1
+ import { DEFAULT_CONTENT_HOST } from '@valbuild/core';
2
+ import { j as ValOpsMemory, k as ValServer, l as createValRequestHandler } from '../../dist/ValRouterCore-f5004f8f.esm.js';
3
+ import 'buffer';
4
+ import '@valbuild/shared/internal';
5
+ import 'zod';
6
+ import 'zod-validation-error';
7
+ import '@valbuild/core/fp';
8
+ import '@valbuild/core/patch';
9
+ import 'image-size';
10
+
11
+ const NO_SESSIONS = "Val: sessions are not available here -- this server runs in the browser, " + "has no secret to sign them with, and serves without authenticating.";
12
+
13
+ /**
14
+ * The platform for a server running in a browser tab.
15
+ *
16
+ * Memory mode only: there is no filesystem for `fs` mode and no credential for
17
+ * `http` mode. Everything else answers as a server without those things does
18
+ * -- no `val login` token, no credential for remote files, no link checks --
19
+ * and the session functions refuse, because a tab has no secret to sign with
20
+ * and the server is constructed with `unsafelyAllowUnauthenticated`, so
21
+ * nothing asks for one.
22
+ */
23
+ const browserPlatform = {
24
+ createOps: (valModules, options) => {
25
+ if (options.mode !== "memory") {
26
+ throw new Error(`Val: a server in the browser runs in memory mode, not '${options.mode}'.`);
27
+ }
28
+ return new ValOpsMemory(valModules, {
29
+ formatter: options.formatter,
30
+ config: options.config,
31
+ sourceFiles: options.sourceFiles,
32
+ patchStore: options.patchStore,
33
+ unsafelyAllowUnauthenticated: options.unsafelyAllowUnauthenticated,
34
+ // Nothing can reach a server in a tab but the page it runs in.
35
+ warnUnauthenticated: false,
36
+ contentUrl: options.valContentUrl
37
+ });
38
+ },
39
+ probeUrl: async () => ({
40
+ kind: "skipped",
41
+ message: "Links are not checked in the browser."
42
+ }),
43
+ jwt: {
44
+ verifyJwt: () => ({
45
+ success: false,
46
+ reason: "missing-secret",
47
+ message: NO_SESSIONS
48
+ }),
49
+ decodeJwtWithoutVerifying: () => ({
50
+ success: false,
51
+ reason: "missing-secret",
52
+ message: NO_SESSIONS
53
+ }),
54
+ encodeJwt: () => {
55
+ throw new Error(NO_SESSIONS);
56
+ },
57
+ getExpire: () => Math.floor(Date.now() / 1000) + 60 * 60
58
+ },
59
+ readValLoginToken: async () => null,
60
+ resolveRemoteFileAuth: async () => ({
61
+ status: "error",
62
+ errorCode: "api-key-missing",
63
+ message: "Remote files are not available in the browser."
64
+ })
65
+ };
66
+
67
+ /** A `fetch`, as far as the Studio's client calls one. */
68
+
69
+ /**
70
+ * Val's API, served in this tab: a `fetch` that never touches the network.
71
+ *
72
+ * The whole server -- the router's request parsing, `ValServer`'s routes,
73
+ * memory mode's patch chain -- runs here, exactly as it runs on a server.
74
+ * What is removed is the hop between them, and nothing else, which is why the
75
+ * demo built on it cannot drift from the product: there is no second
76
+ * implementation to drift. See `docs/plans/demo-mode.md`.
77
+ *
78
+ * Memory mode with no source files, because nothing here publishes (only a
79
+ * publish reads `.val.ts` text), and without authentication, because the only
80
+ * caller is the page this runs in.
81
+ */
82
+ function createInTabValFetch(valModules, options) {
83
+ const route = options.route ?? "/api/val";
84
+ const serverConfig = {
85
+ mode: "memory",
86
+ route,
87
+ sourceFiles: {},
88
+ patchStore: options.patchStore,
89
+ unsafelyAllowUnauthenticated: true,
90
+ valContentUrl: DEFAULT_CONTENT_HOST,
91
+ config: options.config
92
+ };
93
+ const server = ValServer(valModules, serverConfig, {
94
+ // Draft content is the only content a demo has.
95
+ isEnabled: async () => true,
96
+ onEnable: async () => {},
97
+ onDisable: async () => {}
98
+ }, browserPlatform);
99
+ const handle = createValRequestHandler(route, Promise.resolve(server), toResponse);
100
+ return (input, init) => {
101
+ const base = typeof window === "undefined" ? "http://localhost" : window.location.origin;
102
+ // A `Request` already has an absolute URL, and `init` overrides what it
103
+ // carries, as it does for `fetch`. Only a string or URL is resolved.
104
+ return handle(input instanceof Request ? new Request(input, init) : new Request(new URL(String(input), base).href, init));
105
+ };
106
+ }
107
+
108
+ /**
109
+ * The server's answer as a `Response`. The same conversion a host makes,
110
+ * less the cookies: a `Response` made in the page cannot set one, and a server
111
+ * that never authenticates has none to set.
112
+ */
113
+ function toResponse(valRes) {
114
+ const headers = new Headers();
115
+ const valResHeaders = "headers" in valRes && valRes.headers || {};
116
+ for (const key in valResHeaders) {
117
+ const value = valResHeaders[key];
118
+ if (typeof value === "string") {
119
+ headers.set(key, value);
120
+ }
121
+ }
122
+ if ("json" in valRes) {
123
+ headers.set("Content-Type", "application/json");
124
+ return new Response(JSON.stringify(valRes.json), {
125
+ headers,
126
+ status: valRes.status
127
+ });
128
+ }
129
+ if (valRes.status === 302) {
130
+ headers.set("Location", valRes.redirectTo);
131
+ return new Response(null, {
132
+ status: valRes.status,
133
+ headers
134
+ });
135
+ }
136
+ return new Response("body" in valRes ? valRes.body : null, {
137
+ headers,
138
+ status: valRes.status
139
+ });
140
+ }
141
+
142
+ export { createInTabValFetch };
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/valbuild-server-browser.cjs.js",
3
+ "module": "dist/valbuild-server-browser.esm.js"
4
+ }