@thecorporation/server 26.3.2 → 26.3.3

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.js CHANGED
@@ -1,17 +1,12 @@
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
1
  // src/index.ts
9
2
  import { spawn } from "child_process";
10
3
  import { existsSync } from "fs";
11
4
  import { resolve, join } from "path";
12
5
  import { platform, arch } from "os";
13
6
  import { fileURLToPath } from "url";
7
+ import { createRequire } from "module";
14
8
  var __dirname = fileURLToPath(new URL(".", import.meta.url));
9
+ var require2 = createRequire(import.meta.url);
15
10
  var PLATFORM_PACKAGES = {
16
11
  "linux-x64": "@thecorporation/server-linux-x64-gnu",
17
12
  "linux-arm64": "@thecorporation/server-linux-arm64-gnu",
@@ -37,7 +32,7 @@ function getBinaryPath() {
37
32
  const pkg = PLATFORM_PACKAGES[key];
38
33
  if (pkg) {
39
34
  try {
40
- const pkgDir = resolve(__require.resolve(`${pkg}/package.json`), "..");
35
+ const pkgDir = resolve(require2.resolve(`${pkg}/package.json`), "..");
41
36
  const binPath = join(pkgDir, "bin", getBinaryName());
42
37
  if (existsSync(binPath)) {
43
38
  return binPath;
@@ -89,7 +84,7 @@ function getWorkerBinaryPath() {
89
84
  const pkg = PLATFORM_PACKAGES[key];
90
85
  if (pkg) {
91
86
  try {
92
- const pkgDir = resolve(__require.resolve(`${pkg}/package.json`), "..");
87
+ const pkgDir = resolve(require2.resolve(`${pkg}/package.json`), "..");
93
88
  const binPath = join(pkgDir, "bin", getWorkerBinaryName());
94
89
  if (existsSync(binPath)) {
95
90
  return binPath;
package/dist/index.js.map CHANGED
@@ -1 +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\nfunction getWorkerBinaryName(): string {\n return platform() === \"win32\" ? \"agent-worker.exe\" : \"agent-worker\";\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\n/**\n * Resolve the path to the agent-worker binary.\n *\n * Resolution order:\n * 1. CORP_WORKER_BIN environment variable\n * 2. Platform-specific npm package (installed via optionalDependencies)\n * 3. Local dev build at services/agent-worker/target/release/agent-worker\n */\nexport function getWorkerBinaryPath(): string | null {\n // 1. Explicit env override\n const envBin = process.env.CORP_WORKER_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\", getWorkerBinaryName());\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\", \"agent-worker\", \"target\", \"release\", getWorkerBinaryName());\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\", \"agent-worker\", \"target\", \"release\", getWorkerBinaryName());\n if (existsSync(repoDevBuild)) {\n return repoDevBuild;\n }\n\n return null;\n}\n\nexport interface StartWorkerOptions {\n /** Redis URL for job queue (default: redis://localhost:6379/0) */\n redisUrl?: string;\n /** Base URL of the API server (default: http://localhost:8000) */\n apiBaseUrl?: string;\n /** Docker host socket or URL */\n dockerHost?: string;\n /** Root directory for agent workspaces */\n workspaceRoot?: string;\n /** Docker image for agent runtime containers */\n runtimeImage?: string;\n /** Maximum concurrent agent executions */\n maxConcurrency?: number;\n /** Inherit stdio from parent process (default: true) */\n stdio?: \"inherit\" | \"pipe\" | \"ignore\";\n}\n\n/**\n * Start the agent-worker as a child process.\n *\n * Environment variables match `services/agent-worker/src/config.rs`:\n * - REDIS_URL, API_BASE_URL, DOCKER_HOST, WORKSPACE_ROOT,\n * RUNTIME_IMAGE, MAX_CONCURRENCY, RUST_LOG\n */\nexport function startWorker(options: StartWorkerOptions = {}): ChildProcess {\n const binPath = getWorkerBinaryPath();\n if (!binPath) {\n throw new Error(\n `No agent-worker binary found for platform ${getPlatformKey()}. ` +\n `Set CORP_WORKER_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.redisUrl !== undefined) env.REDIS_URL = options.redisUrl;\n if (options.apiBaseUrl !== undefined) env.API_BASE_URL = options.apiBaseUrl;\n if (options.dockerHost !== undefined) env.DOCKER_HOST = options.dockerHost;\n if (options.workspaceRoot !== undefined) env.WORKSPACE_ROOT = options.workspaceRoot;\n if (options.runtimeImage !== undefined) env.RUNTIME_IMAGE = options.runtimeImage;\n if (options.maxConcurrency !== undefined) env.MAX_CONCURRENCY = String(options.maxConcurrency);\n if (!env.RUST_LOG) env.RUST_LOG = \"agent_worker=info\";\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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AAC,GAAiB;AAC1E,QAAM,UAAU,oBAAoB;AACpC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR,6CAA6C,eAAe,CAAC;AAAA,IAE/D;AAAA,EACF;AAEA,QAAM,MAA8B,EAAE,GAAG,QAAQ,IAA8B;AAE/E,MAAI,QAAQ,aAAa,OAAW,KAAI,YAAY,QAAQ;AAC5D,MAAI,QAAQ,eAAe,OAAW,KAAI,eAAe,QAAQ;AACjE,MAAI,QAAQ,eAAe,OAAW,KAAI,cAAc,QAAQ;AAChE,MAAI,QAAQ,kBAAkB,OAAW,KAAI,iBAAiB,QAAQ;AACtE,MAAI,QAAQ,iBAAiB,OAAW,KAAI,gBAAgB,QAAQ;AACpE,MAAI,QAAQ,mBAAmB,OAAW,KAAI,kBAAkB,OAAO,QAAQ,cAAc;AAC7F,MAAI,CAAC,IAAI,SAAU,KAAI,WAAW;AAElC,SAAO,MAAM,SAAS,CAAC,GAAG;AAAA,IACxB;AAAA,IACA,OAAO,QAAQ,SAAS;AAAA,EAC1B,CAAC;AACH;","names":[]}
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\";\nimport { createRequire } from \"node:module\";\n\nconst __dirname = fileURLToPath(new URL(\".\", import.meta.url));\nconst require = createRequire(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\nfunction getWorkerBinaryName(): string {\n return platform() === \"win32\" ? \"agent-worker.exe\" : \"agent-worker\";\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\n/**\n * Resolve the path to the agent-worker binary.\n *\n * Resolution order:\n * 1. CORP_WORKER_BIN environment variable\n * 2. Platform-specific npm package (installed via optionalDependencies)\n * 3. Local dev build at services/agent-worker/target/release/agent-worker\n */\nexport function getWorkerBinaryPath(): string | null {\n // 1. Explicit env override\n const envBin = process.env.CORP_WORKER_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\", getWorkerBinaryName());\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\", \"agent-worker\", \"target\", \"release\", getWorkerBinaryName());\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\", \"agent-worker\", \"target\", \"release\", getWorkerBinaryName());\n if (existsSync(repoDevBuild)) {\n return repoDevBuild;\n }\n\n return null;\n}\n\nexport interface StartWorkerOptions {\n /** Redis URL for job queue (default: redis://localhost:6379/0) */\n redisUrl?: string;\n /** Base URL of the API server (default: http://localhost:8000) */\n apiBaseUrl?: string;\n /** Docker host socket or URL */\n dockerHost?: string;\n /** Root directory for agent workspaces */\n workspaceRoot?: string;\n /** Docker image for agent runtime containers */\n runtimeImage?: string;\n /** Maximum concurrent agent executions */\n maxConcurrency?: number;\n /** Inherit stdio from parent process (default: true) */\n stdio?: \"inherit\" | \"pipe\" | \"ignore\";\n}\n\n/**\n * Start the agent-worker as a child process.\n *\n * Environment variables match `services/agent-worker/src/config.rs`:\n * - REDIS_URL, API_BASE_URL, DOCKER_HOST, WORKSPACE_ROOT,\n * RUNTIME_IMAGE, MAX_CONCURRENCY, RUST_LOG\n */\nexport function startWorker(options: StartWorkerOptions = {}): ChildProcess {\n const binPath = getWorkerBinaryPath();\n if (!binPath) {\n throw new Error(\n `No agent-worker binary found for platform ${getPlatformKey()}. ` +\n `Set CORP_WORKER_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.redisUrl !== undefined) env.REDIS_URL = options.redisUrl;\n if (options.apiBaseUrl !== undefined) env.API_BASE_URL = options.apiBaseUrl;\n if (options.dockerHost !== undefined) env.DOCKER_HOST = options.dockerHost;\n if (options.workspaceRoot !== undefined) env.WORKSPACE_ROOT = options.workspaceRoot;\n if (options.runtimeImage !== undefined) env.RUNTIME_IMAGE = options.runtimeImage;\n if (options.maxConcurrency !== undefined) env.MAX_CONCURRENCY = String(options.maxConcurrency);\n if (!env.RUST_LOG) env.RUST_LOG = \"agent_worker=info\";\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;AAC9B,SAAS,qBAAqB;AAE9B,IAAM,YAAY,cAAc,IAAI,IAAI,KAAK,YAAY,GAAG,CAAC;AAC7D,IAAMA,WAAU,cAAc,YAAY,GAAG;AAG7C,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,CAAC;AAChC;AAEA,SAAS,gBAAwB;AAC/B,SAAO,SAAS,MAAM,UAAU,eAAe;AACjD;AAEA,SAAS,sBAA8B;AACrC,SAAO,SAAS,MAAM,UAAU,qBAAqB;AACvD;AAUO,SAAS,gBAA+B;AAE7C,QAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,UAAU,WAAW,MAAM,GAAG;AAChC,WAAO;AAAA,EACT;AAGA,QAAM,MAAM,eAAe;AAC3B,QAAM,MAAM,kBAAkB,GAAG;AACjC,MAAI,KAAK;AACP,QAAI;AACF,YAAM,SAAS,QAAQA,SAAQ,QAAQ,GAAG,GAAG,eAAe,GAAG,IAAI;AACnE,YAAM,UAAU,KAAK,QAAQ,OAAO,cAAc,CAAC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,mBAAmB,OAAW,KAAI,kBAAkB,OAAO,QAAQ,cAAc;AAC7F,MAAI,CAAC,IAAI,SAAU,KAAI,WAAW;AAElC,SAAO,MAAM,SAAS,CAAC,GAAG;AAAA,IACxB;AAAA,IACA,OAAO,QAAQ,SAAS;AAAA,EAC1B,CAAC;AACH;","names":["require"]}
package/install.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ import { platform, arch } from "node:os";
3
+ import { execSync } from "node:child_process";
4
+ import { existsSync } from "node:fs";
5
+ import { resolve, join } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ const __dirname = fileURLToPath(new URL(".", import.meta.url));
9
+
10
+ const PLATFORM_PACKAGES = {
11
+ "linux-x64": "@thecorporation/server-linux-x64-gnu",
12
+ "linux-arm64": "@thecorporation/server-linux-arm64-gnu",
13
+ "darwin-x64": "@thecorporation/server-darwin-x64",
14
+ "darwin-arm64": "@thecorporation/server-darwin-arm64",
15
+ "win32-x64": "@thecorporation/server-win32-x64-msvc",
16
+ };
17
+
18
+ const key = `${platform()}-${arch()}`;
19
+ const pkg = PLATFORM_PACKAGES[key];
20
+
21
+ if (!pkg) {
22
+ console.warn(`@thecorporation/server: unsupported platform ${key}`);
23
+ process.exit(0);
24
+ }
25
+
26
+ // Check if the binary is already available (e.g. installed by parent)
27
+ try {
28
+ const pkgDir = resolve(require.resolve(`${pkg}/package.json`), "..");
29
+ const binName = platform() === "win32" ? "api-rs.exe" : "api-rs";
30
+ if (existsSync(join(pkgDir, "bin", binName))) {
31
+ process.exit(0);
32
+ }
33
+ } catch {
34
+ // Not installed yet — continue
35
+ }
36
+
37
+ console.log(`@thecorporation/server: installing ${pkg} for ${key}...`);
38
+ try {
39
+ execSync(`npm install ${pkg}`, { stdio: "inherit", cwd: __dirname });
40
+ } catch {
41
+ console.warn(`@thecorporation/server: failed to install ${pkg} (non-fatal)`);
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecorporation/server",
3
- "version": "26.3.2",
3
+ "version": "26.3.3",
4
4
  "description": "Pre-built binaries for the Corporation API server",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -13,25 +13,27 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist/"
16
+ "dist/",
17
+ "install.js"
17
18
  ],
18
19
  "scripts": {
19
- "build": "tsup"
20
+ "build": "tsup",
21
+ "postinstall": "node install.js"
20
22
  },
21
23
  "publishConfig": {
22
24
  "access": "public"
23
25
  },
24
26
  "optionalDependencies": {
25
- "@thecorporation/server-linux-x64-gnu": "26.3.2",
26
- "@thecorporation/server-linux-arm64-gnu": "26.3.2",
27
- "@thecorporation/server-darwin-x64": "26.3.2",
28
- "@thecorporation/server-darwin-arm64": "26.3.2",
29
- "@thecorporation/server-win32-x64-msvc": "26.3.2"
27
+ "@thecorporation/server-darwin-arm64": "26.3.3",
28
+ "@thecorporation/server-darwin-x64": "26.3.3",
29
+ "@thecorporation/server-linux-arm64-gnu": "26.3.3",
30
+ "@thecorporation/server-linux-x64-gnu": "26.3.3",
31
+ "@thecorporation/server-win32-x64-msvc": "26.3.3"
30
32
  },
31
33
  "devDependencies": {
34
+ "@types/node": "^22.0.0",
32
35
  "tsup": "^8.4.0",
33
- "typescript": "^5.8.0",
34
- "@types/node": "^22.0.0"
36
+ "typescript": "^5.8.0"
35
37
  },
36
38
  "engines": {
37
39
  "node": ">=20"