@thecorporation/server 0.1.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/index.d.ts +45 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ChildProcess } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the path to the server binary.
|
|
5
|
+
*
|
|
6
|
+
* Resolution order:
|
|
7
|
+
* 1. CORP_SERVER_BIN environment variable
|
|
8
|
+
* 2. Platform-specific npm package (installed via optionalDependencies)
|
|
9
|
+
* 3. Local dev build at services/api-rs/target/release/api-rs
|
|
10
|
+
*/
|
|
11
|
+
declare function getBinaryPath(): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a server binary is available for the current platform.
|
|
14
|
+
*/
|
|
15
|
+
declare function isAvailable(): boolean;
|
|
16
|
+
interface StartServerOptions {
|
|
17
|
+
/** Port to listen on (default: 8000) */
|
|
18
|
+
port?: number;
|
|
19
|
+
/** Data directory for git repos (default: ./data/repos) */
|
|
20
|
+
dataDir?: string;
|
|
21
|
+
/** Redis URL for caching */
|
|
22
|
+
redisUrl?: string;
|
|
23
|
+
/** PEM-encoded JWT private key */
|
|
24
|
+
jwtPrivateKeyPem?: string;
|
|
25
|
+
/** PEM-encoded JWT public key */
|
|
26
|
+
jwtPublicKeyPem?: string;
|
|
27
|
+
/** Stripe secret key */
|
|
28
|
+
stripeSecretKey?: string;
|
|
29
|
+
/** Stripe webhook secret */
|
|
30
|
+
stripeWebhookSecret?: string;
|
|
31
|
+
/** PEM-encoded Ed25519 key for signing git commits */
|
|
32
|
+
commitSigningKey?: string;
|
|
33
|
+
/** Inherit stdio from parent process (default: true) */
|
|
34
|
+
stdio?: "inherit" | "pipe" | "ignore";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Start the API server as a child process.
|
|
38
|
+
*
|
|
39
|
+
* Environment variables match `services/api-rs/src/config.rs`:
|
|
40
|
+
* - PORT, DATA_DIR, REDIS_URL, JWT_PRIVATE_KEY_PEM, JWT_PUBLIC_KEY_PEM,
|
|
41
|
+
* STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, COMMIT_SIGNING_KEY
|
|
42
|
+
*/
|
|
43
|
+
declare function startServer(options?: StartServerOptions): ChildProcess;
|
|
44
|
+
|
|
45
|
+
export { type StartServerOptions, getBinaryPath, isAvailable, startServer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import { spawn } from "child_process";
|
|
10
|
+
import { existsSync } from "fs";
|
|
11
|
+
import { resolve, join } from "path";
|
|
12
|
+
import { platform, arch } from "os";
|
|
13
|
+
import { fileURLToPath } from "url";
|
|
14
|
+
var __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
15
|
+
var PLATFORM_PACKAGES = {
|
|
16
|
+
"linux-x64": "@thecorporation/server-linux-x64-gnu",
|
|
17
|
+
"linux-arm64": "@thecorporation/server-linux-arm64-gnu",
|
|
18
|
+
"darwin-x64": "@thecorporation/server-darwin-x64",
|
|
19
|
+
"darwin-arm64": "@thecorporation/server-darwin-arm64",
|
|
20
|
+
"win32-x64": "@thecorporation/server-win32-x64-msvc"
|
|
21
|
+
};
|
|
22
|
+
function getPlatformKey() {
|
|
23
|
+
return `${platform()}-${arch()}`;
|
|
24
|
+
}
|
|
25
|
+
function getBinaryName() {
|
|
26
|
+
return platform() === "win32" ? "api-rs.exe" : "api-rs";
|
|
27
|
+
}
|
|
28
|
+
function getBinaryPath() {
|
|
29
|
+
const envBin = process.env.CORP_SERVER_BIN;
|
|
30
|
+
if (envBin && existsSync(envBin)) {
|
|
31
|
+
return envBin;
|
|
32
|
+
}
|
|
33
|
+
const key = getPlatformKey();
|
|
34
|
+
const pkg = PLATFORM_PACKAGES[key];
|
|
35
|
+
if (pkg) {
|
|
36
|
+
try {
|
|
37
|
+
const pkgDir = resolve(__require.resolve(`${pkg}/package.json`), "..");
|
|
38
|
+
const binPath = join(pkgDir, "bin", getBinaryName());
|
|
39
|
+
if (existsSync(binPath)) {
|
|
40
|
+
return binPath;
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const devBuild = resolve(__dirname, "..", "..", "services", "api-rs", "target", "release", getBinaryName());
|
|
46
|
+
if (existsSync(devBuild)) {
|
|
47
|
+
return devBuild;
|
|
48
|
+
}
|
|
49
|
+
const repoRoot = resolve(__dirname, "..", "..", "..");
|
|
50
|
+
const repoDevBuild = join(repoRoot, "services", "api-rs", "target", "release", getBinaryName());
|
|
51
|
+
if (existsSync(repoDevBuild)) {
|
|
52
|
+
return repoDevBuild;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function isAvailable() {
|
|
57
|
+
return getBinaryPath() !== null;
|
|
58
|
+
}
|
|
59
|
+
function startServer(options = {}) {
|
|
60
|
+
const binPath = getBinaryPath();
|
|
61
|
+
if (!binPath) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`No server binary found for platform ${getPlatformKey()}. Set CORP_SERVER_BIN or install the platform-specific package.`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const env = { ...process.env };
|
|
67
|
+
if (options.port !== void 0) env.PORT = String(options.port);
|
|
68
|
+
if (options.dataDir !== void 0) env.DATA_DIR = options.dataDir;
|
|
69
|
+
if (options.redisUrl !== void 0) env.REDIS_URL = options.redisUrl;
|
|
70
|
+
if (options.jwtPrivateKeyPem !== void 0) env.JWT_PRIVATE_KEY_PEM = options.jwtPrivateKeyPem;
|
|
71
|
+
if (options.jwtPublicKeyPem !== void 0) env.JWT_PUBLIC_KEY_PEM = options.jwtPublicKeyPem;
|
|
72
|
+
if (options.stripeSecretKey !== void 0) env.STRIPE_SECRET_KEY = options.stripeSecretKey;
|
|
73
|
+
if (options.stripeWebhookSecret !== void 0) env.STRIPE_WEBHOOK_SECRET = options.stripeWebhookSecret;
|
|
74
|
+
if (options.commitSigningKey !== void 0) env.COMMIT_SIGNING_KEY = options.commitSigningKey;
|
|
75
|
+
return spawn(binPath, [], {
|
|
76
|
+
env,
|
|
77
|
+
stdio: options.stdio ?? "inherit"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
getBinaryPath,
|
|
82
|
+
isAvailable,
|
|
83
|
+
startServer
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { spawn, type ChildProcess } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { resolve, join } from \"node:path\";\nimport { platform, arch } from \"node:os\";\nimport { fileURLToPath } from \"node:url\";\n\nconst __dirname = fileURLToPath(new URL(\".\", import.meta.url));\n\n/** Platform-to-package mapping */\nconst PLATFORM_PACKAGES: Record<string, string> = {\n \"linux-x64\": \"@thecorporation/server-linux-x64-gnu\",\n \"linux-arm64\": \"@thecorporation/server-linux-arm64-gnu\",\n \"darwin-x64\": \"@thecorporation/server-darwin-x64\",\n \"darwin-arm64\": \"@thecorporation/server-darwin-arm64\",\n \"win32-x64\": \"@thecorporation/server-win32-x64-msvc\",\n};\n\nfunction getPlatformKey(): string {\n return `${platform()}-${arch()}`;\n}\n\nfunction getBinaryName(): string {\n return platform() === \"win32\" ? \"api-rs.exe\" : \"api-rs\";\n}\n\n/**\n * Resolve the path to the server binary.\n *\n * Resolution order:\n * 1. CORP_SERVER_BIN environment variable\n * 2. Platform-specific npm package (installed via optionalDependencies)\n * 3. Local dev build at services/api-rs/target/release/api-rs\n */\nexport function getBinaryPath(): string | null {\n // 1. Explicit env override\n const envBin = process.env.CORP_SERVER_BIN;\n if (envBin && existsSync(envBin)) {\n return envBin;\n }\n\n // 2. Platform npm package\n const key = getPlatformKey();\n const pkg = PLATFORM_PACKAGES[key];\n if (pkg) {\n try {\n const pkgDir = resolve(require.resolve(`${pkg}/package.json`), \"..\");\n const binPath = join(pkgDir, \"bin\", getBinaryName());\n if (existsSync(binPath)) {\n return binPath;\n }\n } catch {\n // Package not installed — fall through\n }\n }\n\n // 3. Local dev build (monorepo layout)\n const devBuild = resolve(__dirname, \"..\", \"..\", \"services\", \"api-rs\", \"target\", \"release\", getBinaryName());\n if (existsSync(devBuild)) {\n return devBuild;\n }\n\n // Also try from repo root (when installed as a package)\n const repoRoot = resolve(__dirname, \"..\", \"..\", \"..\");\n const repoDevBuild = join(repoRoot, \"services\", \"api-rs\", \"target\", \"release\", getBinaryName());\n if (existsSync(repoDevBuild)) {\n return repoDevBuild;\n }\n\n return null;\n}\n\n/**\n * Check if a server binary is available for the current platform.\n */\nexport function isAvailable(): boolean {\n return getBinaryPath() !== null;\n}\n\nexport interface StartServerOptions {\n /** Port to listen on (default: 8000) */\n port?: number;\n /** Data directory for git repos (default: ./data/repos) */\n dataDir?: string;\n /** Redis URL for caching */\n redisUrl?: string;\n /** PEM-encoded JWT private key */\n jwtPrivateKeyPem?: string;\n /** PEM-encoded JWT public key */\n jwtPublicKeyPem?: string;\n /** Stripe secret key */\n stripeSecretKey?: string;\n /** Stripe webhook secret */\n stripeWebhookSecret?: string;\n /** PEM-encoded Ed25519 key for signing git commits */\n commitSigningKey?: string;\n /** Inherit stdio from parent process (default: true) */\n stdio?: \"inherit\" | \"pipe\" | \"ignore\";\n}\n\n/**\n * Start the API server as a child process.\n *\n * Environment variables match `services/api-rs/src/config.rs`:\n * - PORT, DATA_DIR, REDIS_URL, JWT_PRIVATE_KEY_PEM, JWT_PUBLIC_KEY_PEM,\n * STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, COMMIT_SIGNING_KEY\n */\nexport function startServer(options: StartServerOptions = {}): ChildProcess {\n const binPath = getBinaryPath();\n if (!binPath) {\n throw new Error(\n `No server binary found for platform ${getPlatformKey()}. ` +\n `Set CORP_SERVER_BIN or install the platform-specific package.`\n );\n }\n\n const env: Record<string, string> = { ...process.env as Record<string, string> };\n\n if (options.port !== undefined) env.PORT = String(options.port);\n if (options.dataDir !== undefined) env.DATA_DIR = options.dataDir;\n if (options.redisUrl !== undefined) env.REDIS_URL = options.redisUrl;\n if (options.jwtPrivateKeyPem !== undefined) env.JWT_PRIVATE_KEY_PEM = options.jwtPrivateKeyPem;\n if (options.jwtPublicKeyPem !== undefined) env.JWT_PUBLIC_KEY_PEM = options.jwtPublicKeyPem;\n if (options.stripeSecretKey !== undefined) env.STRIPE_SECRET_KEY = options.stripeSecretKey;\n if (options.stripeWebhookSecret !== undefined) env.STRIPE_WEBHOOK_SECRET = options.stripeWebhookSecret;\n if (options.commitSigningKey !== undefined) env.COMMIT_SIGNING_KEY = options.commitSigningKey;\n\n return spawn(binPath, [], {\n env,\n stdio: options.stdio ?? \"inherit\",\n });\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,aAAgC;AACzC,SAAS,kBAAkB;AAC3B,SAAS,SAAS,YAAY;AAC9B,SAAS,UAAU,YAAY;AAC/B,SAAS,qBAAqB;AAE9B,IAAM,YAAY,cAAc,IAAI,IAAI,KAAK,YAAY,GAAG,CAAC;AAG7D,IAAM,oBAA4C;AAAA,EAChD,aAAa;AAAA,EACb,eAAe;AAAA,EACf,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,aAAa;AACf;AAEA,SAAS,iBAAyB;AAChC,SAAO,GAAG,SAAS,CAAC,IAAI,KAAK,CAA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AAC5D,MAAI,QAAQ,qBAAqB,OAAW,KAAI,sBAAsB,QAAQ;AAC9E,MAAI,QAAQ,oBAAoB,OAAW,KAAI,qBAAqB,QAAQ;AAC5E,MAAI,QAAQ,oBAAoB,OAAW,KAAI,oBAAoB,QAAQ;AAC3E,MAAI,QAAQ,wBAAwB,OAAW,KAAI,wBAAwB,QAAQ;AACnF,MAAI,QAAQ,qBAAqB,OAAW,KAAI,qBAAqB,QAAQ;AAE7E,SAAO,MAAM,SAAS,CAAC,GAAG;AAAA,IACxB;AAAA,IACA,OAAO,QAAQ,SAAS;AAAA,EAC1B,CAAC;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@thecorporation/server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pre-built binaries for the Corporation API server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"optionalDependencies": {
|
|
25
|
+
"@thecorporation/server-linux-x64-gnu": "0.1.0",
|
|
26
|
+
"@thecorporation/server-linux-arm64-gnu": "0.1.0",
|
|
27
|
+
"@thecorporation/server-darwin-x64": "0.1.0",
|
|
28
|
+
"@thecorporation/server-darwin-arm64": "0.1.0",
|
|
29
|
+
"@thecorporation/server-win32-x64-msvc": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"tsup": "^8.4.0",
|
|
33
|
+
"typescript": "^5.8.0",
|
|
34
|
+
"@types/node": "^22.0.0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20"
|
|
38
|
+
},
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/thecorporationai/thecorporation-mono.git",
|
|
43
|
+
"directory": "packages/server"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://thecorporation.ai"
|
|
46
|
+
}
|