@opendatalabs/personal-server-ts-server 0.0.1-canary.0078f25
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/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/app.d.ts +35 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +124 -0
- package/dist/app.js.map +1 -0
- package/dist/bootstrap.d.ts +35 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +232 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/dev-token.d.ts +6 -0
- package/dist/dev-token.d.ts.map +1 -0
- package/dist/dev-token.js +9 -0
- package/dist/dev-token.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/access-log.d.ts +8 -0
- package/dist/middleware/access-log.d.ts.map +1 -0
- package/dist/middleware/access-log.js +38 -0
- package/dist/middleware/access-log.js.map +1 -0
- package/dist/middleware/body-limit.d.ts +10 -0
- package/dist/middleware/body-limit.d.ts.map +1 -0
- package/dist/middleware/body-limit.js +20 -0
- package/dist/middleware/body-limit.js.map +1 -0
- package/dist/middleware/builder-check.d.ts +8 -0
- package/dist/middleware/builder-check.d.ts.map +1 -0
- package/dist/middleware/builder-check.js +29 -0
- package/dist/middleware/builder-check.js.map +1 -0
- package/dist/middleware/grant-check.d.ts +12 -0
- package/dist/middleware/grant-check.d.ts.map +1 -0
- package/dist/middleware/grant-check.js +90 -0
- package/dist/middleware/grant-check.js.map +1 -0
- package/dist/middleware/owner-check.d.ts +9 -0
- package/dist/middleware/owner-check.d.ts.map +1 -0
- package/dist/middleware/owner-check.js +37 -0
- package/dist/middleware/owner-check.js.map +1 -0
- package/dist/middleware/web3-auth.d.ts +16 -0
- package/dist/middleware/web3-auth.d.ts.map +1 -0
- package/dist/middleware/web3-auth.js +58 -0
- package/dist/middleware/web3-auth.js.map +1 -0
- package/dist/routes/access-logs.d.ts +16 -0
- package/dist/routes/access-logs.d.ts.map +1 -0
- package/dist/routes/access-logs.js +30 -0
- package/dist/routes/access-logs.js.map +1 -0
- package/dist/routes/data.d.ts +20 -0
- package/dist/routes/data.d.ts.map +1 -0
- package/dist/routes/data.js +213 -0
- package/dist/routes/data.js.map +1 -0
- package/dist/routes/grants.d.ts +17 -0
- package/dist/routes/grants.d.ts.map +1 -0
- package/dist/routes/grants.js +208 -0
- package/dist/routes/grants.js.map +1 -0
- package/dist/routes/health.d.ts +16 -0
- package/dist/routes/health.d.ts.map +1 -0
- package/dist/routes/health.js +37 -0
- package/dist/routes/health.js.map +1 -0
- package/dist/routes/mcp.d.ts +7 -0
- package/dist/routes/mcp.d.ts.map +1 -0
- package/dist/routes/mcp.js +14 -0
- package/dist/routes/mcp.js.map +1 -0
- package/dist/routes/sync.d.ts +16 -0
- package/dist/routes/sync.d.ts.map +1 -0
- package/dist/routes/sync.js +52 -0
- package/dist/routes/sync.js.map +1 -0
- package/dist/routes/ui-config.d.ts +7 -0
- package/dist/routes/ui-config.d.ts.map +1 -0
- package/dist/routes/ui-config.js +89 -0
- package/dist/routes/ui-config.js.map +1 -0
- package/dist/routes/ui.d.ts +6 -0
- package/dist/routes/ui.d.ts.map +1 -0
- package/dist/routes/ui.js +36 -0
- package/dist/routes/ui.js.map +1 -0
- package/dist/tunnel/auth.d.ts +46 -0
- package/dist/tunnel/auth.d.ts.map +1 -0
- package/dist/tunnel/auth.js +46 -0
- package/dist/tunnel/auth.js.map +1 -0
- package/dist/tunnel/binary.d.ts +57 -0
- package/dist/tunnel/binary.d.ts.map +1 -0
- package/dist/tunnel/binary.js +180 -0
- package/dist/tunnel/binary.js.map +1 -0
- package/dist/tunnel/config.d.ts +27 -0
- package/dist/tunnel/config.d.ts.map +1 -0
- package/dist/tunnel/config.js +38 -0
- package/dist/tunnel/config.js.map +1 -0
- package/dist/tunnel/index.d.ts +13 -0
- package/dist/tunnel/index.d.ts.map +1 -0
- package/dist/tunnel/index.js +9 -0
- package/dist/tunnel/index.js.map +1 -0
- package/dist/tunnel/manager.d.ts +88 -0
- package/dist/tunnel/manager.d.ts.map +1 -0
- package/dist/tunnel/manager.js +279 -0
- package/dist/tunnel/manager.js.map +1 -0
- package/dist/tunnel/verify.d.ts +28 -0
- package/dist/tunnel/verify.d.ts.map +1 -0
- package/dist/tunnel/verify.js +40 -0
- package/dist/tunnel/verify.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/tunnel/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAEhF,kEAAkE;AAClE,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED,uDAAuD;AACvD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMrD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,WAAW,CAAC,CAiBtB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tunnel authentication via EIP-191 signed claims.
|
|
3
|
+
*
|
|
4
|
+
* Generates signed claims for FRP server plugin-first Login/NewProxy validation.
|
|
5
|
+
* The claim is a base64url-encoded JSON payload signed with EIP-191.
|
|
6
|
+
*/
|
|
7
|
+
/** Claim time-to-live in seconds. Used for refresh scheduling. */
|
|
8
|
+
export const CLAIM_TTL_SECONDS = 300;
|
|
9
|
+
/** Encode a UTF-8 string to base64url (no padding). */
|
|
10
|
+
export function base64urlEncode(input) {
|
|
11
|
+
return Buffer.from(input, "utf-8")
|
|
12
|
+
.toString("base64")
|
|
13
|
+
.replace(/\+/g, "-")
|
|
14
|
+
.replace(/\//g, "_")
|
|
15
|
+
.replace(/=+$/, "");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate a signed claim for tunnel authentication.
|
|
19
|
+
*
|
|
20
|
+
* The claim payload contains:
|
|
21
|
+
* - aud: "https://tunnel.vana.org" (audience)
|
|
22
|
+
* - iat: issued-at timestamp (seconds)
|
|
23
|
+
* - exp: expiration timestamp (5 min TTL)
|
|
24
|
+
* - owner: owner wallet address
|
|
25
|
+
* - wallet: server wallet address
|
|
26
|
+
* - subdomain: lowercased wallet address
|
|
27
|
+
* - runId: unique per-process session ID
|
|
28
|
+
*
|
|
29
|
+
* The signature is EIP-191 over the base64url-encoded claim string.
|
|
30
|
+
*/
|
|
31
|
+
export async function generateSignedClaim(config) {
|
|
32
|
+
const now = Math.floor(Date.now() / 1000);
|
|
33
|
+
const payload = {
|
|
34
|
+
aud: "https://tunnel.vana.org",
|
|
35
|
+
iat: now,
|
|
36
|
+
exp: now + CLAIM_TTL_SECONDS,
|
|
37
|
+
owner: config.ownerAddress,
|
|
38
|
+
wallet: config.walletAddress,
|
|
39
|
+
subdomain: config.walletAddress.toLowerCase(),
|
|
40
|
+
runId: config.runId,
|
|
41
|
+
};
|
|
42
|
+
const claim = base64urlEncode(JSON.stringify(payload));
|
|
43
|
+
const sig = await config.serverKeypair.signMessage(claim);
|
|
44
|
+
return { claim, sig };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/tunnel/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,kEAAkE;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAwBrC,uDAAuD;AACvD,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;SAC/B,QAAQ,CAAC,QAAQ,CAAC;SAClB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAmB;IAEnB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAE1C,MAAM,OAAO,GAAiB;QAC5B,GAAG,EAAE,yBAAyB;QAC9B,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,iBAAiB;QAC5B,KAAK,EAAE,MAAM,CAAC,YAAY;QAC1B,MAAM,EAAE,MAAM,CAAC,aAAa;QAC5B,SAAS,EAAE,MAAM,CAAC,aAAa,CAAC,WAAW,EAAE;QAC7C,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;IAEF,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAE1D,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-demand frpc binary download and version management.
|
|
3
|
+
*
|
|
4
|
+
* Downloads the correct frpc binary for the current platform from GitHub
|
|
5
|
+
* releases, stores it in the user's data directory, and re-downloads only
|
|
6
|
+
* when the pinned version changes.
|
|
7
|
+
*/
|
|
8
|
+
/** Pinned frpc version — bump this to trigger re-download on next startup. */
|
|
9
|
+
export declare const FRPC_VERSION = "0.67.0";
|
|
10
|
+
export interface PlatformInfo {
|
|
11
|
+
/** e.g. "darwin_arm64" */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Archive extension: "tar.gz" or "zip" */
|
|
14
|
+
ext: "tar.gz" | "zip";
|
|
15
|
+
/** Binary file name inside the archive */
|
|
16
|
+
binaryName: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Map current process.platform / process.arch to frp release naming.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getPlatformInfo(): PlatformInfo;
|
|
22
|
+
/**
|
|
23
|
+
* Return the expected path to the frpc binary under storageRoot.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getBinaryPath(storageRoot: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Read the installed version from the metadata file.
|
|
28
|
+
* Returns null if the file is missing or corrupt.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getInstalledVersion(storageRoot: string): Promise<string | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Write version metadata after successful installation.
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeVersionFile(storageRoot: string, version: string): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Build the GitHub release download URL for a given version and platform.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getDownloadUrl(version: string, platformInfo: PlatformInfo): string;
|
|
39
|
+
/**
|
|
40
|
+
* Download a file from `url` to `destPath` using fetch + stream pipeline.
|
|
41
|
+
*/
|
|
42
|
+
export declare function downloadArchive(url: string, destPath: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Extract the frpc binary from a downloaded archive into destDir.
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractBinary(archivePath: string, destDir: string, version: string, platformInfo: PlatformInfo): Promise<string>;
|
|
47
|
+
export interface EnsureFrpcOptions {
|
|
48
|
+
log?: (msg: string) => void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Main entry point: ensure the correct frpc binary is available.
|
|
52
|
+
*
|
|
53
|
+
* 1. Check version file — if version matches and binary exists, return path (fast path).
|
|
54
|
+
* 2. Otherwise download, extract, chmod, write version file, return path.
|
|
55
|
+
*/
|
|
56
|
+
export declare function ensureFrpcBinary(storageRoot: string, options?: EnsureFrpcOptions): Promise<string>;
|
|
57
|
+
//# sourceMappingURL=binary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../../src/tunnel/binary.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAqBH,8EAA8E;AAC9E,eAAO,MAAM,YAAY,WAAW,CAAC;AAIrC,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,GAAG,EAAE,QAAQ,GAAG,KAAK,CAAC;IACtB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;CACpB;AAQD;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,CA+B9C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAGzD;AAMD;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY,GACzB,MAAM,CAGR;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,CA8CjB"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-demand frpc binary download and version management.
|
|
3
|
+
*
|
|
4
|
+
* Downloads the correct frpc binary for the current platform from GitHub
|
|
5
|
+
* releases, stores it in the user's data directory, and re-downloads only
|
|
6
|
+
* when the pinned version changes.
|
|
7
|
+
*/
|
|
8
|
+
import { createWriteStream } from "node:fs";
|
|
9
|
+
import { access, chmod, mkdir, readFile, rename, rm, writeFile, constants, } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { pipeline } from "node:stream/promises";
|
|
12
|
+
import { Readable } from "node:stream";
|
|
13
|
+
import { exec } from "node:child_process";
|
|
14
|
+
import { promisify } from "node:util";
|
|
15
|
+
const execAsync = promisify(exec);
|
|
16
|
+
/** Pinned frpc version — bump this to trigger re-download on next startup. */
|
|
17
|
+
export const FRPC_VERSION = "0.67.0";
|
|
18
|
+
const GITHUB_RELEASE_BASE = "https://github.com/fatedier/frp/releases/download";
|
|
19
|
+
/**
|
|
20
|
+
* Map current process.platform / process.arch to frp release naming.
|
|
21
|
+
*/
|
|
22
|
+
export function getPlatformInfo() {
|
|
23
|
+
const platform = process.platform;
|
|
24
|
+
const arch = process.arch;
|
|
25
|
+
if (platform === "darwin") {
|
|
26
|
+
const archName = arch === "arm64" ? "arm64" : "amd64";
|
|
27
|
+
return {
|
|
28
|
+
name: `darwin_${archName}`,
|
|
29
|
+
ext: "tar.gz",
|
|
30
|
+
binaryName: "frpc",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (platform === "linux") {
|
|
34
|
+
const archName = arch === "arm64" ? "arm64" : "amd64";
|
|
35
|
+
return {
|
|
36
|
+
name: `linux_${archName}`,
|
|
37
|
+
ext: "tar.gz",
|
|
38
|
+
binaryName: "frpc",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (platform === "win32") {
|
|
42
|
+
return {
|
|
43
|
+
name: "windows_amd64",
|
|
44
|
+
ext: "zip",
|
|
45
|
+
binaryName: "frpc.exe",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`Unsupported platform: ${platform} ${arch}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Return the expected path to the frpc binary under storageRoot.
|
|
52
|
+
*/
|
|
53
|
+
export function getBinaryPath(storageRoot) {
|
|
54
|
+
const isWindows = process.platform === "win32";
|
|
55
|
+
return join(storageRoot, "bin", isWindows ? "frpc.exe" : "frpc");
|
|
56
|
+
}
|
|
57
|
+
function versionFilePath(storageRoot) {
|
|
58
|
+
return join(storageRoot, "bin", "frpc-version.json");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Read the installed version from the metadata file.
|
|
62
|
+
* Returns null if the file is missing or corrupt.
|
|
63
|
+
*/
|
|
64
|
+
export async function getInstalledVersion(storageRoot) {
|
|
65
|
+
try {
|
|
66
|
+
const raw = await readFile(versionFilePath(storageRoot), "utf-8");
|
|
67
|
+
const meta = JSON.parse(raw);
|
|
68
|
+
return meta.version ?? null;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Write version metadata after successful installation.
|
|
76
|
+
*/
|
|
77
|
+
export async function writeVersionFile(storageRoot, version) {
|
|
78
|
+
const meta = {
|
|
79
|
+
version,
|
|
80
|
+
platform: `${process.platform}_${process.arch}`,
|
|
81
|
+
installedAt: new Date().toISOString(),
|
|
82
|
+
};
|
|
83
|
+
await writeFile(versionFilePath(storageRoot), JSON.stringify(meta, null, 2));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build the GitHub release download URL for a given version and platform.
|
|
87
|
+
*/
|
|
88
|
+
export function getDownloadUrl(version, platformInfo) {
|
|
89
|
+
const archiveName = `frp_${version}_${platformInfo.name}.${platformInfo.ext}`;
|
|
90
|
+
return `${GITHUB_RELEASE_BASE}/v${version}/${archiveName}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Download a file from `url` to `destPath` using fetch + stream pipeline.
|
|
94
|
+
*/
|
|
95
|
+
export async function downloadArchive(url, destPath) {
|
|
96
|
+
const response = await fetch(url);
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
throw new Error(`Failed to download frpc: HTTP ${response.status} from ${url}`);
|
|
99
|
+
}
|
|
100
|
+
if (!response.body) {
|
|
101
|
+
throw new Error("No response body received");
|
|
102
|
+
}
|
|
103
|
+
const fileStream = createWriteStream(destPath);
|
|
104
|
+
await pipeline(Readable.fromWeb(response.body), fileStream);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Extract the frpc binary from a downloaded archive into destDir.
|
|
108
|
+
*/
|
|
109
|
+
export async function extractBinary(archivePath, destDir, version, platformInfo) {
|
|
110
|
+
const extractDir = join(destDir, "_extract");
|
|
111
|
+
await mkdir(extractDir, { recursive: true });
|
|
112
|
+
try {
|
|
113
|
+
if (platformInfo.ext === "tar.gz") {
|
|
114
|
+
await execAsync(`tar -xzf "${archivePath}" -C "${extractDir}"`);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// Windows: use PowerShell
|
|
118
|
+
await execAsync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${extractDir}' -Force"`);
|
|
119
|
+
}
|
|
120
|
+
// The archive extracts to frp_<version>_<platform>/frpc
|
|
121
|
+
const innerDir = join(extractDir, `frp_${version}_${platformInfo.name}`);
|
|
122
|
+
const srcBinary = join(innerDir, platformInfo.binaryName);
|
|
123
|
+
// Verify extracted binary exists
|
|
124
|
+
await access(srcBinary, constants.F_OK);
|
|
125
|
+
// Move binary to final destination
|
|
126
|
+
const finalPath = join(destDir, platformInfo.binaryName);
|
|
127
|
+
await rename(srcBinary, finalPath);
|
|
128
|
+
return finalPath;
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
await rm(extractDir, { recursive: true, force: true });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Main entry point: ensure the correct frpc binary is available.
|
|
136
|
+
*
|
|
137
|
+
* 1. Check version file — if version matches and binary exists, return path (fast path).
|
|
138
|
+
* 2. Otherwise download, extract, chmod, write version file, return path.
|
|
139
|
+
*/
|
|
140
|
+
export async function ensureFrpcBinary(storageRoot, options) {
|
|
141
|
+
const log = options?.log ?? (() => { });
|
|
142
|
+
const binDir = join(storageRoot, "bin");
|
|
143
|
+
const binaryPath = getBinaryPath(storageRoot);
|
|
144
|
+
// Fast path: version matches and binary exists
|
|
145
|
+
const installedVersion = await getInstalledVersion(storageRoot);
|
|
146
|
+
if (installedVersion === FRPC_VERSION) {
|
|
147
|
+
try {
|
|
148
|
+
await access(binaryPath, constants.F_OK);
|
|
149
|
+
log(`frpc v${FRPC_VERSION} already installed`);
|
|
150
|
+
return binaryPath;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// Binary missing despite version file — re-download
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Need to download
|
|
157
|
+
log(`Downloading frpc v${FRPC_VERSION}...`);
|
|
158
|
+
await mkdir(binDir, { recursive: true });
|
|
159
|
+
const platformInfo = getPlatformInfo();
|
|
160
|
+
const url = getDownloadUrl(FRPC_VERSION, platformInfo);
|
|
161
|
+
// Download to a temp file in the bin directory
|
|
162
|
+
const tempArchive = join(binDir, `_frpc_download.${platformInfo.ext}`);
|
|
163
|
+
try {
|
|
164
|
+
await downloadArchive(url, tempArchive);
|
|
165
|
+
log("Download complete, extracting...");
|
|
166
|
+
await extractBinary(tempArchive, binDir, FRPC_VERSION, platformInfo);
|
|
167
|
+
// Make executable on unix
|
|
168
|
+
if (process.platform !== "win32") {
|
|
169
|
+
await chmod(binaryPath, 0o755);
|
|
170
|
+
}
|
|
171
|
+
await writeVersionFile(storageRoot, FRPC_VERSION);
|
|
172
|
+
log(`frpc v${FRPC_VERSION} installed successfully`);
|
|
173
|
+
return binaryPath;
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
// Clean up temp archive
|
|
177
|
+
await rm(tempArchive, { force: true });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=binary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.js","sourceRoot":"","sources":["../../src/tunnel/binary.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,EAAE,EACF,SAAS,EACT,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,QAAQ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AAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEzC,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,GAAG,GAAG,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IAEvD,+CAA+C;IAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,EAAE,kBAAkB,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;IAEvE,IAAI,CAAC;QACH,MAAM,eAAe,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACxC,GAAG,CAAC,kCAAkC,CAAC,CAAC;QAExC,MAAM,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;QAErE,0BAA0B;QAC1B,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACjC,MAAM,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;QAED,MAAM,gBAAgB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAClD,GAAG,CAAC,SAAS,YAAY,yBAAyB,CAAC,CAAC;QAEpD,OAAO,UAAU,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,wBAAwB;QACxB,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FRP client configuration generation.
|
|
3
|
+
*
|
|
4
|
+
* Generates frpc.toml configuration for connecting to the FRP server.
|
|
5
|
+
*/
|
|
6
|
+
export interface FrpcConfigOptions {
|
|
7
|
+
serverAddr: string;
|
|
8
|
+
serverPort: number;
|
|
9
|
+
localPort: number;
|
|
10
|
+
subdomain: string;
|
|
11
|
+
walletAddress: string;
|
|
12
|
+
ownerAddress: string;
|
|
13
|
+
runId: string;
|
|
14
|
+
authClaim: string;
|
|
15
|
+
authSig: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate frpc.toml configuration content.
|
|
19
|
+
*
|
|
20
|
+
* Uses TOML format with:
|
|
21
|
+
* - serverAddr/serverPort for FRP control plane connection
|
|
22
|
+
* - loginFailExit = false for resilience (keeps trying on auth failure)
|
|
23
|
+
* - HTTP proxy with subdomain routing
|
|
24
|
+
* - Root-level metadatas for Auth Plugin validation (required by frps server)
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateFrpcConfig(options: FrpcConfigOptions): string;
|
|
27
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/tunnel/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAsBrE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FRP client configuration generation.
|
|
3
|
+
*
|
|
4
|
+
* Generates frpc.toml configuration for connecting to the FRP server.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generate frpc.toml configuration content.
|
|
8
|
+
*
|
|
9
|
+
* Uses TOML format with:
|
|
10
|
+
* - serverAddr/serverPort for FRP control plane connection
|
|
11
|
+
* - loginFailExit = false for resilience (keeps trying on auth failure)
|
|
12
|
+
* - HTTP proxy with subdomain routing
|
|
13
|
+
* - Root-level metadatas for Auth Plugin validation (required by frps server)
|
|
14
|
+
*/
|
|
15
|
+
export function generateFrpcConfig(options) {
|
|
16
|
+
return `# Auto-generated frpc configuration
|
|
17
|
+
# Do not edit - regenerated on each server start
|
|
18
|
+
|
|
19
|
+
serverAddr = "${options.serverAddr}"
|
|
20
|
+
serverPort = ${options.serverPort}
|
|
21
|
+
loginFailExit = false
|
|
22
|
+
|
|
23
|
+
# Metadata for Auth Plugin validation (at root level for Login operation)
|
|
24
|
+
metadatas.wallet = "${options.walletAddress}"
|
|
25
|
+
metadatas.owner = "${options.ownerAddress}"
|
|
26
|
+
metadatas.run_id = "${options.runId}"
|
|
27
|
+
metadatas.auth_claim = "${options.authClaim}"
|
|
28
|
+
metadatas.auth_sig = "${options.authSig}"
|
|
29
|
+
|
|
30
|
+
[[proxies]]
|
|
31
|
+
name = "personal-server"
|
|
32
|
+
type = "http"
|
|
33
|
+
localIP = "127.0.0.1"
|
|
34
|
+
localPort = ${options.localPort}
|
|
35
|
+
subdomain = "${options.subdomain}"
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/tunnel/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA0B;IAC3D,OAAO;;;gBAGO,OAAO,CAAC,UAAU;eACnB,OAAO,CAAC,UAAU;;;;sBAIX,OAAO,CAAC,aAAa;qBACtB,OAAO,CAAC,YAAY;sBACnB,OAAO,CAAC,KAAK;0BACT,OAAO,CAAC,SAAS;wBACnB,OAAO,CAAC,OAAO;;;;;;cAMzB,OAAO,CAAC,SAAS;eAChB,OAAO,CAAC,SAAS;CAC/B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FRP tunnel module for establishing reverse proxy connections.
|
|
3
|
+
*/
|
|
4
|
+
export { generateSignedClaim, base64urlEncode, CLAIM_TTL_SECONDS, } from "./auth.js";
|
|
5
|
+
export type { SignedClaim, ClaimPayload, ClaimConfig } from "./auth.js";
|
|
6
|
+
export { generateFrpcConfig } from "./config.js";
|
|
7
|
+
export type { FrpcConfigOptions } from "./config.js";
|
|
8
|
+
export { TunnelManager } from "./manager.js";
|
|
9
|
+
export type { TunnelConfig, TunnelStatus, TunnelStatusInfo, } from "./manager.js";
|
|
10
|
+
export { ensureFrpcBinary, getBinaryPath } from "./binary.js";
|
|
11
|
+
export { buildTunnelUrl, verifyTunnelUrl } from "./verify.js";
|
|
12
|
+
export type { VerifyTunnelOptions, VerifyTunnelResult } from "./verify.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tunnel/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FRP tunnel module for establishing reverse proxy connections.
|
|
3
|
+
*/
|
|
4
|
+
export { generateSignedClaim, base64urlEncode, CLAIM_TTL_SECONDS, } from "./auth.js";
|
|
5
|
+
export { generateFrpcConfig } from "./config.js";
|
|
6
|
+
export { TunnelManager } from "./manager.js";
|
|
7
|
+
export { ensureFrpcBinary, getBinaryPath } from "./binary.js";
|
|
8
|
+
export { buildTunnelUrl, verifyTunnelUrl } from "./verify.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tunnel/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAO7C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TunnelManager handles the frpc process lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Generate signed claim and frpc.toml config
|
|
6
|
+
* - Spawn frpc process with a caller-provided binary path
|
|
7
|
+
* - Monitor process lifecycle
|
|
8
|
+
* - Periodically refresh the auth claim before it expires
|
|
9
|
+
* - Provide status for health endpoint
|
|
10
|
+
*/
|
|
11
|
+
import type { ServerAccount } from "@opendatalabs/personal-server-ts-core/keys";
|
|
12
|
+
export type TunnelStatus = "stopped" | "starting" | "connected" | "disconnected" | "error";
|
|
13
|
+
export interface TunnelStatusInfo {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
status: TunnelStatus;
|
|
16
|
+
publicUrl: string | null;
|
|
17
|
+
connectedSince: string | null;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface TunnelConfig {
|
|
21
|
+
walletAddress: string;
|
|
22
|
+
ownerAddress: string;
|
|
23
|
+
serverKeypair: ServerAccount;
|
|
24
|
+
runId: string;
|
|
25
|
+
serverAddr: string;
|
|
26
|
+
serverPort: number;
|
|
27
|
+
localPort: number;
|
|
28
|
+
}
|
|
29
|
+
export declare class TunnelManager {
|
|
30
|
+
private storageRoot;
|
|
31
|
+
private process;
|
|
32
|
+
private status;
|
|
33
|
+
private publicUrl;
|
|
34
|
+
private connectedSince;
|
|
35
|
+
private lastError;
|
|
36
|
+
private config;
|
|
37
|
+
private binaryPath;
|
|
38
|
+
private refreshTimer;
|
|
39
|
+
private refreshing;
|
|
40
|
+
constructor(storageRoot: string);
|
|
41
|
+
/**
|
|
42
|
+
* Start the frpc process with the given configuration.
|
|
43
|
+
* Returns the public URL once the tunnel is established.
|
|
44
|
+
* Automatically schedules periodic claim refresh.
|
|
45
|
+
*/
|
|
46
|
+
start(config: TunnelConfig, binaryPath: string): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Stop the frpc process gracefully.
|
|
49
|
+
*/
|
|
50
|
+
stop(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Check if the tunnel is currently running.
|
|
53
|
+
*/
|
|
54
|
+
isRunning(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Update status based on external verification of the tunnel URL.
|
|
57
|
+
*/
|
|
58
|
+
setVerified(reachable: boolean, error?: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get the current tunnel status.
|
|
61
|
+
*/
|
|
62
|
+
getStatus(): TunnelStatusInfo;
|
|
63
|
+
/**
|
|
64
|
+
* Get the public URL if connected.
|
|
65
|
+
*/
|
|
66
|
+
getPublicUrl(): string | null;
|
|
67
|
+
/**
|
|
68
|
+
* Generate a fresh signed claim, write frpc.toml, and return the config path.
|
|
69
|
+
*/
|
|
70
|
+
private writeFreshConfig;
|
|
71
|
+
/**
|
|
72
|
+
* Spawn the frpc process and wait for it to report a successful connection
|
|
73
|
+
* (or resolve optimistically after a timeout).
|
|
74
|
+
*/
|
|
75
|
+
private spawnProcess;
|
|
76
|
+
/**
|
|
77
|
+
* Kill the running frpc process and wait for it to exit.
|
|
78
|
+
*/
|
|
79
|
+
private killProcess;
|
|
80
|
+
private scheduleRefresh;
|
|
81
|
+
private clearRefreshTimer;
|
|
82
|
+
/**
|
|
83
|
+
* Refresh the auth claim by rewriting frpc.toml and restarting the process.
|
|
84
|
+
* On failure, retries after a shorter interval.
|
|
85
|
+
*/
|
|
86
|
+
private refreshClaim;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/tunnel/manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAKhF,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,UAAU,GACV,WAAW,GACX,cAAc,GACd,OAAO,CAAC;AAEZ,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAQD,qBAAa,aAAa;IACxB,OAAO,CA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