@valbuild/server 0.150.23 → 0.152.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.
- package/CHANGELOG.md +341 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +5 -137
- package/browser/dist/valbuild-server-browser.cjs.prod.js +5 -137
- package/browser/dist/valbuild-server-browser.esm.js +4 -140
- package/dist/ValRouter-05fcb0da.esm.js +14663 -0
- package/dist/ValRouter-afcba447.cjs.dev.js +14759 -0
- package/dist/ValRouter-b4e5b412.cjs.prod.js +14759 -0
- package/dist/{ValRouterCore-0c7ae881.cjs.prod.js → ValRouterCore-a0ea46bf.cjs.prod.js} +3324 -1883
- package/dist/{ValRouterCore-5b6cccd4.esm.js → ValRouterCore-b5d70504.esm.js} +3316 -1879
- package/dist/{ValRouterCore-cfa7b001.cjs.dev.js → ValRouterCore-d16c3327.cjs.dev.js} +3324 -1883
- package/dist/declarations/src/ValOps.d.ts +334 -70
- package/dist/declarations/src/ValOpsFS.d.ts +32 -0
- package/dist/declarations/src/ValOpsHttp.d.ts +93 -3
- package/dist/declarations/src/ValOpsMemory.d.ts +22 -47
- package/dist/declarations/src/ValRouter.d.ts +10 -0
- package/dist/declarations/src/ValServer.d.ts +0 -10
- package/dist/declarations/src/browser/inTabFetch.d.ts +19 -2
- package/dist/declarations/src/draftOverlay.d.ts +51 -0
- package/dist/declarations/src/draftReads.d.ts +103 -0
- package/dist/declarations/src/head.d.ts +312 -0
- package/dist/declarations/src/history/getJsonEntryAtCommit.d.ts +52 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/internal/browser/index.d.ts +11 -0
- package/dist/declarations/src/internal/index.d.ts +15 -0
- package/dist/declarations/src/patch/jsonValuesPatch.d.ts +2 -165
- package/dist/declarations/src/patch/ts/jsonValuesModule.d.ts +38 -0
- package/dist/declarations/src/patch/ts/loadTypeScriptKit.d.ts +14 -0
- package/dist/declarations/src/patch/ts/ops.d.ts +45 -0
- package/dist/declarations/src/patch/ts/publishKit.d.ts +26 -0
- package/dist/declarations/src/platform.d.ts +14 -0
- package/dist/declarations/src/proposal.d.ts +54 -3
- package/dist/declarations/src/valRuntime.d.ts +35 -0
- package/dist/draftReads-05415ff6.cjs.dev.js +366 -0
- package/dist/draftReads-5f99edd3.esm.js +361 -0
- package/dist/draftReads-ea3946e0.cjs.prod.js +366 -0
- package/dist/inTabFetch-095bb2be.cjs.prod.js +179 -0
- package/dist/inTabFetch-2cbbfaa4.cjs.dev.js +179 -0
- package/dist/inTabFetch-91c3e85e.esm.js +176 -0
- package/dist/{getJsonEntryAtCommit-d9b5f753.cjs.dev.js → publishKit-4e2b0014.cjs.dev.js} +55 -6
- package/dist/{getJsonEntryAtCommit-acf8c269.cjs.prod.js → publishKit-6e52ffa6.cjs.prod.js} +55 -6
- package/dist/{getJsonEntryAtCommit-8ff81ef5.esm.js → publishKit-af14cd7a.esm.js} +48 -5
- package/dist/valbuild-server.cjs.dev.js +160 -13319
- package/dist/valbuild-server.cjs.prod.js +160 -13319
- package/dist/valbuild-server.esm.js +34 -13174
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.d.ts +2 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +19 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.js +7 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +19 -0
- package/internal/browser/dist/valbuild-server-internal-browser.esm.js +10 -0
- package/internal/browser/package.json +4 -0
- package/internal/dist/valbuild-server-internal.cjs.d.ts +2 -0
- package/internal/dist/valbuild-server-internal.cjs.dev.js +43 -0
- package/internal/dist/valbuild-server-internal.cjs.js +7 -0
- package/internal/dist/valbuild-server-internal.cjs.prod.js +43 -0
- package/internal/dist/valbuild-server-internal.esm.js +24 -0
- package/internal/package.json +4 -0
- package/package.json +17 -6
- package/dist/jsonValuesModule-235bd751.cjs.dev.js +0 -326
- package/dist/jsonValuesModule-23eb6f53.esm.js +0 -310
- package/dist/jsonValuesModule-625ebae8.cjs.prod.js +0 -326
- package/dist/ops-0e54b388.cjs.prod.js +0 -361
- package/dist/ops-9ca2ef2a.cjs.dev.js +0 -361
- package/dist/ops-b904007e.esm.js +0 -353
- package/dist/publishKit-34f71e50.cjs.dev.js +0 -42
- package/dist/publishKit-65e9e564.cjs.prod.js +0 -42
- package/dist/publishKit-7441c0fd.esm.js +0 -31
|
@@ -1,145 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import '
|
|
1
|
+
export { c as createInTabValFetch } from '../../dist/inTabFetch-91c3e85e.esm.js';
|
|
2
|
+
import '@valbuild/core';
|
|
3
|
+
import '../../dist/ValRouterCore-b5d70504.esm.js';
|
|
4
4
|
import 'zod';
|
|
5
|
+
import '@valbuild/shared/internal';
|
|
5
6
|
import 'zod-validation-error';
|
|
6
7
|
import '@valbuild/core/fp';
|
|
7
8
|
import '@valbuild/core/patch';
|
|
8
9
|
import 'image-size';
|
|
9
|
-
|
|
10
|
-
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.";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The platform for a server running in a browser tab.
|
|
14
|
-
*
|
|
15
|
-
* Memory mode only: there is no filesystem for `fs` mode and no credential for
|
|
16
|
-
* `http` mode. Everything else answers as a server without those things does
|
|
17
|
-
* -- no `val login` token, no credential for remote files, no link checks --
|
|
18
|
-
* and the session functions refuse, because a tab has no secret to sign with
|
|
19
|
-
* and the server is constructed with `unsafelyAllowUnauthenticated`, so
|
|
20
|
-
* nothing asks for one.
|
|
21
|
-
*/
|
|
22
|
-
const browserPlatform = {
|
|
23
|
-
createOps: (valModules, options) => {
|
|
24
|
-
if (options.mode !== "memory") {
|
|
25
|
-
throw new Error(`Val: a server in the browser runs in memory mode, not '${options.mode}'.`);
|
|
26
|
-
}
|
|
27
|
-
return new ValOpsMemory(valModules, {
|
|
28
|
-
formatter: options.formatter,
|
|
29
|
-
config: options.config,
|
|
30
|
-
sourceFiles: options.sourceFiles,
|
|
31
|
-
patchStore: options.patchStore,
|
|
32
|
-
unsafelyAllowUnauthenticated: options.unsafelyAllowUnauthenticated,
|
|
33
|
-
// Nothing can reach a server in a tab but the page it runs in.
|
|
34
|
-
warnUnauthenticated: false,
|
|
35
|
-
contentUrl: options.valContentUrl
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
probeUrl: async () => ({
|
|
39
|
-
kind: "skipped",
|
|
40
|
-
message: "Links are not checked in the browser."
|
|
41
|
-
}),
|
|
42
|
-
jwt: {
|
|
43
|
-
verifyJwt: () => ({
|
|
44
|
-
success: false,
|
|
45
|
-
reason: "missing-secret",
|
|
46
|
-
message: NO_SESSIONS
|
|
47
|
-
}),
|
|
48
|
-
decodeJwtWithoutVerifying: () => ({
|
|
49
|
-
success: false,
|
|
50
|
-
reason: "missing-secret",
|
|
51
|
-
message: NO_SESSIONS
|
|
52
|
-
}),
|
|
53
|
-
encodeJwt: () => {
|
|
54
|
-
throw new Error(NO_SESSIONS);
|
|
55
|
-
},
|
|
56
|
-
getExpire: () => Math.floor(Date.now() / 1000) + 60 * 60
|
|
57
|
-
},
|
|
58
|
-
bytesToBase64,
|
|
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
|
-
...(options.framework !== undefined ? {
|
|
93
|
-
framework: options.framework
|
|
94
|
-
} : {})
|
|
95
|
-
};
|
|
96
|
-
const server = ValServer(valModules, serverConfig, {
|
|
97
|
-
// Draft content is the only content a demo has.
|
|
98
|
-
isEnabled: async () => true,
|
|
99
|
-
onEnable: async () => {},
|
|
100
|
-
onDisable: async () => {}
|
|
101
|
-
}, browserPlatform);
|
|
102
|
-
const handle = createValRequestHandler(route, Promise.resolve(server), toResponse);
|
|
103
|
-
return (input, init) => {
|
|
104
|
-
const base = typeof window === "undefined" ? "http://localhost" : window.location.origin;
|
|
105
|
-
// A `Request` already has an absolute URL, and `init` overrides what it
|
|
106
|
-
// carries, as it does for `fetch`. Only a string or URL is resolved.
|
|
107
|
-
return handle(input instanceof Request ? new Request(input, init) : new Request(new URL(String(input), base).href, init));
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* The server's answer as a `Response`. The same conversion a host makes,
|
|
113
|
-
* less the cookies: a `Response` made in the page cannot set one, and a server
|
|
114
|
-
* that never authenticates has none to set.
|
|
115
|
-
*/
|
|
116
|
-
function toResponse(valRes) {
|
|
117
|
-
const headers = new Headers();
|
|
118
|
-
const valResHeaders = "headers" in valRes && valRes.headers || {};
|
|
119
|
-
for (const key in valResHeaders) {
|
|
120
|
-
const value = valResHeaders[key];
|
|
121
|
-
if (typeof value === "string") {
|
|
122
|
-
headers.set(key, value);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if ("json" in valRes) {
|
|
126
|
-
headers.set("Content-Type", "application/json");
|
|
127
|
-
return new Response(JSON.stringify(valRes.json), {
|
|
128
|
-
headers,
|
|
129
|
-
status: valRes.status
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
if (valRes.status === 302) {
|
|
133
|
-
headers.set("Location", valRes.redirectTo);
|
|
134
|
-
return new Response(null, {
|
|
135
|
-
status: valRes.status,
|
|
136
|
-
headers
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return new Response("body" in valRes ? valRes.body : null, {
|
|
140
|
-
headers,
|
|
141
|
-
status: valRes.status
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export { createInTabValFetch };
|