@valbuild/server 0.121.0 → 0.123.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.
@@ -36,22 +36,25 @@ export declare function initHandlerOptions(route: string, opts: ValApiOptions, c
36
36
  /**
37
37
  * Build the data layer a {@link ValServerConfig} calls for.
38
38
  *
39
- * `auth` decides *whose* credential the http backend sees. Left out, it is the
40
- * app's own API key — which is what the Studio wants, because there the app has
41
- * already verified a session cookie and is acting on the user's behalf under its
42
- * own authority.
39
+ * The http backend always sees the app's own API key. That is what the Studio
40
+ * wants — there the app has already verified a session cookie and is acting on
41
+ * the user's behalf under its own authority — and it is now the only shape:
42
+ * every caller that reaches here has been authenticated by the app itself, so
43
+ * there is no request left on which the app is a pipe rather than an authority.
43
44
  *
44
- * A caller acting for a user it has *not* authenticated itself must pass that
45
- * user's personal access token instead, so the backend is the one that decides
46
- * what the caller may do. That is the whole of `docs/plans/mcp.md` D.2: the app
47
- * stops being an authority and goes back to being a pipe. Passing the app's API
48
- * key on such a request is the D.6 confused deputy, and it is worth being blunt
49
- * about why it is tempting — it works, and it works for every project the key
50
- * can reach, including the ones the caller cannot.
45
+ * This took a parameter for the other case: a caller acting for a user it had
46
+ * *not* authenticated passed that user's personal access token, and the backend
47
+ * decided what the caller could do. `ValOpsHttp` still accepts such a token —
48
+ * the CLI's `debug` command uses the developer's own from `val login` — but no
49
+ * server request builds one any more, because a request the app cannot
50
+ * authenticate is now refused instead of relayed.
51
+ *
52
+ * What has not changed is why the API key must never stand in for a credential
53
+ * that was merely *absent*: it works, and it works for every project the key
54
+ * can reach, including the ones the caller cannot. Callers are refused for a
55
+ * missing credential well before this point.
51
56
  */
52
- export declare function createValOps(valModules: ValModules, options: ValServerConfig, auth?: {
53
- pat: string;
54
- }): ValOpsFS | ValOpsHttp;
57
+ export declare function createValOps(valModules: ValModules, options: ValServerConfig): ValOpsFS | ValOpsHttp;
55
58
  /**
56
59
  * Hosts we send credentials to, and what each one puts at risk. They differ:
57
60
  * only `valBuildUrl` hands back the app token that becomes the session cookie,
@@ -78,4 +81,41 @@ type CredentialBearingUrl = "valBuildUrl" | "valContentUrl";
78
81
  * internal http host today.
79
82
  */
80
83
  export declare function insecureUrlWarning(name: CredentialBearingUrl, url: string): string | null;
84
+ /**
85
+ * Which credential talks to the content host about REMOTE FILES.
86
+ *
87
+ * A separate question from the one `createValOps` answers, and it has to be:
88
+ * `ValOps` is authenticated per caller, but remote files are project-level —
89
+ * looking up a project's public id and its buckets, and later pushing bytes to
90
+ * them, is the same operation whoever asked for it.
91
+ *
92
+ * The rule, in order:
93
+ *
94
+ * 1. The app's API key, if there is one. Proxy mode always has one; fs mode has
95
+ * one when `VAL_API_KEY` is set.
96
+ * 2. In fs mode, the developer's own `val login` token, read off disk. This is
97
+ * the same file `val validate --fix` reads, and it is why local remote
98
+ * uploads work with no configuration beyond having logged in.
99
+ * 3. Nothing, which is an error rather than a fallback.
100
+ *
101
+ * Lives here rather than inside `createValServer` because the MCP image tool
102
+ * needs the same answer, and this is the file that exists so that two callers
103
+ * cannot disagree about how a project is configured. A registry that decided it
104
+ * had no credential while the Studio in the same process had one would be a
105
+ * genuinely confusing afternoon.
106
+ */
107
+ export type RemoteFileAuth = {
108
+ apiKey: string;
109
+ } | {
110
+ pat: string;
111
+ };
112
+ export type ResolveRemoteFileAuthResult = {
113
+ status: "success";
114
+ auth: RemoteFileAuth;
115
+ } | {
116
+ status: "error";
117
+ errorCode: "project-not-configured" | "pat-error";
118
+ message: string;
119
+ };
120
+ export declare function resolveRemoteFileAuth(options: ValServerConfig): Promise<ResolveRemoteFileAuthResult>;
81
121
  export {};