@valbuild/server 0.97.7 → 0.98.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/dist/declarations/src/checkRemoteRef.d.ts +20 -0
- package/dist/declarations/src/evalValConfigFile.d.ts +17 -0
- package/dist/declarations/src/extractMetadata.d.ts +4 -0
- package/dist/declarations/src/getFileExt.d.ts +1 -0
- package/dist/declarations/src/getValidationErrorFileRef.d.ts +2 -0
- package/dist/declarations/src/hasRemoteFileSchema.d.ts +5 -0
- package/dist/declarations/src/index.d.ts +11 -0
- package/dist/declarations/src/loadValModules.d.ts +11 -1
- package/dist/declarations/src/login.d.ts +69 -0
- package/dist/declarations/src/modulePathMap.d.ts +4 -0
- package/dist/declarations/src/patch/ts/valModule.d.ts +8 -0
- package/dist/declarations/src/validateMetadata.d.ts +6 -0
- package/dist/valbuild-server.cjs.dev.js +503 -177
- package/dist/valbuild-server.cjs.prod.js +503 -177
- package/dist/valbuild-server.esm.js +325 -21
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FileMetadata, ImageMetadata, SerializedFileSchema, SerializedImageSchema } from "@valbuild/core";
|
|
2
|
+
export declare function checkRemoteRef(remoteHost: string, ref: string, projectRoot: string, schema: SerializedImageSchema | SerializedFileSchema, metadata: Record<string, unknown> | undefined): Promise<{
|
|
3
|
+
status: "success";
|
|
4
|
+
} | {
|
|
5
|
+
status: "fix-required";
|
|
6
|
+
metadata: ImageMetadata | FileMetadata;
|
|
7
|
+
ref: string;
|
|
8
|
+
} | {
|
|
9
|
+
status: "error";
|
|
10
|
+
error: string;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function getCachedRemoteFileDir(projectRoot: string): string;
|
|
13
|
+
export declare function getCachedRemoteFilePath(fileExt: string, currentFileHash: string, remoteFileCacheDir: string): string;
|
|
14
|
+
export declare function downloadFileFromRemote(ref: string, filePath: string): Promise<{
|
|
15
|
+
status: "success";
|
|
16
|
+
filePath: string;
|
|
17
|
+
} | {
|
|
18
|
+
status: "error";
|
|
19
|
+
error: string;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ValConfig } from "@valbuild/core";
|
|
2
|
+
/**
|
|
3
|
+
* Read and evaluate a `val.config.{ts,js}` file from disk.
|
|
4
|
+
*
|
|
5
|
+
* Returns `null` if the file does not exist, and throws if it exists but does
|
|
6
|
+
* not export a valid `config` object.
|
|
7
|
+
*
|
|
8
|
+
* Used by the Val CLI and by `@valbuild/language-server`, so that an editor
|
|
9
|
+
* resolves project config exactly the way the CLI does.
|
|
10
|
+
*/
|
|
11
|
+
export declare function evalValConfigFile(projectRoot: string, configFileName: string): Promise<ValConfig | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the project's Val config, trying the TypeScript file first and
|
|
14
|
+
* falling back to JavaScript. Mirrors what the CLI has always done at each of
|
|
15
|
+
* its call sites.
|
|
16
|
+
*/
|
|
17
|
+
export declare function findAndEvalValConfigFile(projectRoot: string): Promise<ValConfig | null>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FileMetadata, ImageMetadata } from "@valbuild/core";
|
|
2
|
+
import { Buffer } from "buffer";
|
|
3
|
+
export declare function extractImageMetadata(filename: string, input: Buffer): Promise<ImageMetadata>;
|
|
4
|
+
export declare function extractFileMetadata(filename: string, _input: Buffer): Promise<FileMetadata>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getFileExt(filePath: string): string;
|
|
@@ -8,12 +8,23 @@ export type { IValFSHost } from "./ValFSHost.js";
|
|
|
8
8
|
export type { ValFS } from "./ValFS.js";
|
|
9
9
|
export { patchSourceFile } from "./patchValFile.js";
|
|
10
10
|
export { formatSyntaxErrorTree } from "./patch/ts/syntax.js";
|
|
11
|
+
export { analyzeValModule } from "./patch/ts/valModule.js";
|
|
12
|
+
export type { ValModuleAnalysis } from "./patch/ts/valModule.js";
|
|
11
13
|
export { createFixPatch } from "./createFixPatch.js";
|
|
12
14
|
export * from "./jwt.js";
|
|
13
15
|
export type { ValServer } from "./ValServer.js";
|
|
14
16
|
export { getSettings } from "./getSettings.js";
|
|
15
17
|
export { getPersonalAccessTokenPath, parsePersonalAccessTokenFile, } from "./personalAccessTokens.js";
|
|
16
18
|
export { uploadRemoteFile } from "./uploadRemoteFile.js";
|
|
19
|
+
export { extractImageMetadata, extractFileMetadata } from "./extractMetadata.js";
|
|
20
|
+
export { validateMetadata } from "./validateMetadata.js";
|
|
21
|
+
export { getValidationErrorFileRef } from "./getValidationErrorFileRef.js";
|
|
22
|
+
export { checkRemoteRef, downloadFileFromRemote, getCachedRemoteFileDir, getCachedRemoteFilePath, } from "./checkRemoteRef.js";
|
|
23
|
+
export { hasRemoteFileSchema } from "./hasRemoteFileSchema.js";
|
|
24
|
+
export { getFileExt } from "./getFileExt.js";
|
|
25
|
+
export { evalValConfigFile, findAndEvalValConfigFile, } from "./evalValConfigFile.js";
|
|
26
|
+
export { startValLogin, awaitValLoginConfirmation, persistPersonalAccessToken, ValLoginError, DEFAULT_LOGIN_HOST, DEFAULT_LOGIN_MAX_DURATION, DEFAULT_LOGIN_POLL_INTERVAL, } from "./login.js";
|
|
27
|
+
export type { ValLoginErrorCode, ValLoginResult, ValLoginSession, } from "./login.js";
|
|
17
28
|
export { createModulePathMap, getModulePathRange } from "./modulePathMap.js";
|
|
18
29
|
export type { ModulePathMap } from "./modulePathMap.js";
|
|
19
30
|
export { ValOpsFS } from "./ValOpsFS.js";
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
1
2
|
import type { ValModules } from "@valbuild/core";
|
|
3
|
+
/**
|
|
4
|
+
* The filesystem seam `loadValModules` reads through.
|
|
5
|
+
*
|
|
6
|
+
* Defaults to `ts.sys`, i.e. the real filesystem. An editor integration (see
|
|
7
|
+
* `@valbuild/language-server`) passes a host that overlays unsaved buffers, so
|
|
8
|
+
* that evaluation sees what the user is looking at rather than what was last
|
|
9
|
+
* saved.
|
|
10
|
+
*/
|
|
11
|
+
export type ValModulesHost = ts.ParseConfigHost & ts.ModuleResolutionHost;
|
|
2
12
|
/**
|
|
3
13
|
* Loads the project's root `val.modules.ts` (or `.js`) using Node's `vm`
|
|
4
14
|
* module and returns its default export (a `ValModules` registry).
|
|
@@ -20,4 +30,4 @@ import type { ValModules } from "@valbuild/core";
|
|
|
20
30
|
* same trust level as running the project's build. It must never be used to
|
|
21
31
|
* evaluate untrusted or third-party modules.
|
|
22
32
|
*/
|
|
23
|
-
export declare function loadValModules(projectRoot: string): ValModules;
|
|
33
|
+
export declare function loadValModules(projectRoot: string, host?: ValModulesHost): ValModules;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Val login device flow, as reusable primitives.
|
|
3
|
+
*
|
|
4
|
+
* The CLI wraps these with terminal output, and `@valbuild/language-server`
|
|
5
|
+
* wraps them with LSP `window/showDocument` and progress reporting. Neither the
|
|
6
|
+
* polling nor the token handling is duplicated between them.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately no `console` output and no `process.exit`: every failure is a
|
|
9
|
+
* thrown {@link ValLoginError} so an embedder can decide how to surface it.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_LOGIN_HOST = "https://admin.val.build";
|
|
12
|
+
export type ValLoginErrorCode =
|
|
13
|
+
/** The server replied with something other than JSON. */
|
|
14
|
+
"unexpected-content-type"
|
|
15
|
+
/** The server replied with JSON, but not the shape we expect. */
|
|
16
|
+
| "unexpected-response"
|
|
17
|
+
/** The server returned a 5xx. */
|
|
18
|
+
| "server-error"
|
|
19
|
+
/** The user did not complete the login within the allotted time. */
|
|
20
|
+
| "timeout"
|
|
21
|
+
/** The caller aborted the flow. */
|
|
22
|
+
| "aborted";
|
|
23
|
+
export declare class ValLoginError extends Error {
|
|
24
|
+
readonly code: ValLoginErrorCode;
|
|
25
|
+
readonly details?: string | undefined;
|
|
26
|
+
constructor(code: ValLoginErrorCode, message: string, details?: string | undefined);
|
|
27
|
+
}
|
|
28
|
+
/** A login attempt that is waiting for the user to confirm in a browser. */
|
|
29
|
+
export type ValLoginSession = {
|
|
30
|
+
/** Opaque token used to poll for confirmation. */
|
|
31
|
+
nonce: string;
|
|
32
|
+
/** URL the user must open to confirm the login. */
|
|
33
|
+
url: string;
|
|
34
|
+
};
|
|
35
|
+
export type ValLoginResult = {
|
|
36
|
+
profile: {
|
|
37
|
+
email: string;
|
|
38
|
+
};
|
|
39
|
+
pat: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Begin a login attempt. The caller is responsible for getting
|
|
43
|
+
* {@link ValLoginSession.url} in front of the user.
|
|
44
|
+
*/
|
|
45
|
+
export declare function startValLogin(options?: {
|
|
46
|
+
host?: string;
|
|
47
|
+
}): Promise<ValLoginSession>;
|
|
48
|
+
export declare const DEFAULT_LOGIN_MAX_DURATION: number;
|
|
49
|
+
export declare const DEFAULT_LOGIN_POLL_INTERVAL = 1000;
|
|
50
|
+
/**
|
|
51
|
+
* Poll until the user confirms the login in their browser.
|
|
52
|
+
*
|
|
53
|
+
* Accepts an `AbortSignal` so an editor can cancel the flow when the user
|
|
54
|
+
* dismisses the prompt, instead of leaving a poll loop running for 5 minutes.
|
|
55
|
+
*/
|
|
56
|
+
export declare function awaitValLoginConfirmation(nonce: string, options?: {
|
|
57
|
+
host?: string;
|
|
58
|
+
maxDurationMs?: number;
|
|
59
|
+
pollIntervalMs?: number;
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
/** Wall clock, injectable for tests. */
|
|
62
|
+
now?: () => number;
|
|
63
|
+
}): Promise<ValLoginResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Write a completed login to the project's personal access token file.
|
|
66
|
+
*
|
|
67
|
+
* @returns the path the token was written to.
|
|
68
|
+
*/
|
|
69
|
+
export declare function persistPersonalAccessToken(projectRoot: string, result: ValLoginResult): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { result } from "@valbuild/core/fp";
|
|
3
|
+
import { ValSyntaxErrorTree } from "./syntax.js";
|
|
4
|
+
export type ValModuleAnalysis = {
|
|
5
|
+
schema: ts.Expression;
|
|
6
|
+
source: ts.Expression;
|
|
7
|
+
};
|
|
8
|
+
export declare function analyzeValModule(sourceFile: ts.SourceFile): result.Result<ValModuleAnalysis, ValSyntaxErrorTree>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FileMetadata, ImageMetadata } from "@valbuild/core";
|
|
2
|
+
export declare function validateMetadata<Metadata extends ImageMetadata | FileMetadata>(actualMetadata: unknown, expectedMetadata: Metadata): false | {
|
|
3
|
+
missingMetadata?: (keyof Metadata)[];
|
|
4
|
+
erroneousMetadata?: Partial<Record<keyof Metadata, string>>;
|
|
5
|
+
globalErrors?: string[];
|
|
6
|
+
};
|