@thecorporation/server 0.1.0 → 1.0.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/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # @thecorporation/server
2
+
3
+ Pre-built binaries for the Corporation API server. Wraps the Rust backend as a Node.js child process with automatic platform detection.
4
+
5
+ Part of [The Corporation](https://thecorporation.ai) — agent-native corporate infrastructure.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @thecorporation/server
11
+ ```
12
+
13
+ The correct binary for your platform is installed automatically via `optionalDependencies`.
14
+
15
+ **Supported platforms:** macOS (Apple Silicon, Intel), Linux (x64, arm64), Windows (x64).
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ import { startServer, isAvailable, getBinaryPath } from "@thecorporation/server";
21
+
22
+ // Check if a binary exists for this platform
23
+ if (isAvailable()) {
24
+ const child = startServer({
25
+ port: 8000,
26
+ dataDir: "./data/repos",
27
+ });
28
+ }
29
+ ```
30
+
31
+ ### `startServer(options?)`
32
+
33
+ Spawns the server as a child process and returns a `ChildProcess`.
34
+
35
+ | Option | Env var | Default |
36
+ |---|---|---|
37
+ | `port` | `PORT` | `8000` |
38
+ | `dataDir` | `DATA_DIR` | `./data/repos` |
39
+ | `redisUrl` | `REDIS_URL` | — |
40
+ | `jwtPrivateKeyPem` | `JWT_PRIVATE_KEY_PEM` | — |
41
+ | `jwtPublicKeyPem` | `JWT_PUBLIC_KEY_PEM` | — |
42
+ | `stripeSecretKey` | `STRIPE_SECRET_KEY` | — |
43
+ | `stripeWebhookSecret` | `STRIPE_WEBHOOK_SECRET` | — |
44
+ | `commitSigningKey` | `COMMIT_SIGNING_KEY` | — |
45
+ | `stdio` | — | `"inherit"` |
46
+
47
+ ### `getBinaryPath()`
48
+
49
+ Returns the resolved binary path, or `null` if unavailable. Resolution order:
50
+
51
+ 1. `CORP_SERVER_BIN` environment variable
52
+ 2. Platform-specific npm optional dependency
53
+ 3. Local dev build at `services/api-rs/target/release/api-rs`
54
+
55
+ ### `isAvailable()`
56
+
57
+ Returns `true` if a binary exists for the current platform.
58
+
59
+ ## Links
60
+
61
+ - [thecorporation.ai](https://thecorporation.ai)
62
+ - [GitHub](https://github.com/thecorporationai/thecorporation-mono/tree/main/packages/server)
63
+
64
+ ## License
65
+
66
+ MIT
package/dist/index.d.ts CHANGED
@@ -41,5 +41,38 @@ interface StartServerOptions {
41
41
  * STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, COMMIT_SIGNING_KEY
42
42
  */
43
43
  declare function startServer(options?: StartServerOptions): ChildProcess;
44
+ /**
45
+ * Resolve the path to the agent-worker binary.
46
+ *
47
+ * Resolution order:
48
+ * 1. CORP_WORKER_BIN environment variable
49
+ * 2. Platform-specific npm package (installed via optionalDependencies)
50
+ * 3. Local dev build at services/agent-worker/target/release/agent-worker
51
+ */
52
+ declare function getWorkerBinaryPath(): string | null;
53
+ interface StartWorkerOptions {
54
+ /** Redis URL for job queue (default: redis://localhost:6379/0) */
55
+ redisUrl?: string;
56
+ /** Base URL of the API server (default: http://localhost:8000) */
57
+ apiBaseUrl?: string;
58
+ /** Docker host socket or URL */
59
+ dockerHost?: string;
60
+ /** Root directory for agent workspaces */
61
+ workspaceRoot?: string;
62
+ /** Docker image for agent runtime containers */
63
+ runtimeImage?: string;
64
+ /** Maximum concurrent agent executions */
65
+ maxConcurrency?: number;
66
+ /** Inherit stdio from parent process (default: true) */
67
+ stdio?: "inherit" | "pipe" | "ignore";
68
+ }
69
+ /**
70
+ * Start the agent-worker as a child process.
71
+ *
72
+ * Environment variables match `services/agent-worker/src/config.rs`:
73
+ * - REDIS_URL, API_BASE_URL, DOCKER_HOST, WORKSPACE_ROOT,
74
+ * RUNTIME_IMAGE, MAX_CONCURRENCY, RUST_LOG
75
+ */
76
+ declare function startWorker(options?: StartWorkerOptions): ChildProcess;
44
77
 
45
- export { type StartServerOptions, getBinaryPath, isAvailable, startServer };
78
+ export { type StartServerOptions, type StartWorkerOptions, getBinaryPath, getWorkerBinaryPath, isAvailable, startServer, startWorker };
package/dist/index.js CHANGED
@@ -25,6 +25,9 @@ function getPlatformKey() {
25
25
  function getBinaryName() {
26
26
  return platform() === "win32" ? "api-rs.exe" : "api-rs";
27
27
  }
28
+ function getWorkerBinaryName() {
29
+ return platform() === "win32" ? "agent-worker.exe" : "agent-worker";
30
+ }
28
31
  function getBinaryPath() {
29
32
  const envBin = process.env.CORP_SERVER_BIN;
30
33
  if (envBin && existsSync(envBin)) {
@@ -77,9 +80,59 @@ function startServer(options = {}) {
77
80
  stdio: options.stdio ?? "inherit"
78
81
  });
79
82
  }
83
+ function getWorkerBinaryPath() {
84
+ const envBin = process.env.CORP_WORKER_BIN;
85
+ if (envBin && existsSync(envBin)) {
86
+ return envBin;
87
+ }
88
+ const key = getPlatformKey();
89
+ const pkg = PLATFORM_PACKAGES[key];
90
+ if (pkg) {
91
+ try {
92
+ const pkgDir = resolve(__require.resolve(`${pkg}/package.json`), "..");
93
+ const binPath = join(pkgDir, "bin", getWorkerBinaryName());
94
+ if (existsSync(binPath)) {
95
+ return binPath;
96
+ }
97
+ } catch {
98
+ }
99
+ }
100
+ const devBuild = resolve(__dirname, "..", "..", "services", "agent-worker", "target", "release", getWorkerBinaryName());
101
+ if (existsSync(devBuild)) {
102
+ return devBuild;
103
+ }
104
+ const repoRoot = resolve(__dirname, "..", "..", "..");
105
+ const repoDevBuild = join(repoRoot, "services", "agent-worker", "target", "release", getWorkerBinaryName());
106
+ if (existsSync(repoDevBuild)) {
107
+ return repoDevBuild;
108
+ }
109
+ return null;
110
+ }
111
+ function startWorker(options = {}) {
112
+ const binPath = getWorkerBinaryPath();
113
+ if (!binPath) {
114
+ throw new Error(
115
+ `No agent-worker binary found for platform ${getPlatformKey()}. Set CORP_WORKER_BIN or install the platform-specific package.`
116
+ );
117
+ }
118
+ const env = { ...process.env };
119
+ if (options.redisUrl !== void 0) env.REDIS_URL = options.redisUrl;
120
+ if (options.apiBaseUrl !== void 0) env.API_BASE_URL = options.apiBaseUrl;
121
+ if (options.dockerHost !== void 0) env.DOCKER_HOST = options.dockerHost;
122
+ if (options.workspaceRoot !== void 0) env.WORKSPACE_ROOT = options.workspaceRoot;
123
+ if (options.runtimeImage !== void 0) env.RUNTIME_IMAGE = options.runtimeImage;
124
+ if (options.maxConcurrency !== void 0) env.MAX_CONCURRENCY = String(options.maxConcurrency);
125
+ if (!env.RUST_LOG) env.RUST_LOG = "agent_worker=info";
126
+ return spawn(binPath, [], {
127
+ env,
128
+ stdio: options.stdio ?? "inherit"
129
+ });
130
+ }
80
131
  export {
81
132
  getBinaryPath,
133
+ getWorkerBinaryPath,
82
134
  isAvailable,
83
- startServer
135
+ startServer,
136
+ startWorker
84
137
  };
85
138
  //# sourceMappingURL=index.js.map
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\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,CAAC;AAChC;AAEA,SAAS,gBAAwB;AAC/B,SAAO,SAAS,MAAM,UAAU,eAAe;AACjD;AAUO,SAAS,gBAA+B;AAE7C,QAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,UAAU,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AW,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":[]}
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;A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Q,GAAG;AACxB,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,QAAQ,WAAW,MAAM,MAAM,IAAI;AACpD,QAAM,eAAe,KAAK,UAAU,YAAY,gBAAgB,UAAU,WAAW,oBAAoB,CAAC;AAC1G,MAAI,WAAW,YAAY,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AA0BO,SAAS,YAAY,UAA8B,CAAC,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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecorporation/server",
3
- "version": "0.1.0",
3
+ "version": "1.0.3",
4
4
  "description": "Pre-built binaries for the Corporation API server",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,11 +22,11 @@
22
22
  "access": "public"
23
23
  },
24
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"
25
+ "@thecorporation/server-linux-x64-gnu": "1.0.3",
26
+ "@thecorporation/server-linux-arm64-gnu": "1.0.3",
27
+ "@thecorporation/server-darwin-x64": "1.0.3",
28
+ "@thecorporation/server-darwin-arm64": "1.0.3",
29
+ "@thecorporation/server-win32-x64-msvc": "1.0.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "tsup": "^8.4.0",