@openlatch/client 0.0.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/lib/index.js ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { execFileSync } = require("child_process");
6
+ const path = require("path");
7
+ const os = require("os");
8
+
9
+ // Map Node.js platform/arch to @openlatch/client-{platform} package names
10
+ const PLATFORMS = {
11
+ "darwin-arm64": "@openlatch/client-darwin-arm64",
12
+ "darwin-x64": "@openlatch/client-darwin-x64",
13
+ "linux-x64": "@openlatch/client-linux-x64",
14
+ "linux-arm64": "@openlatch/client-linux-arm64",
15
+ "win32-x64": "@openlatch/client-win32-x64",
16
+ };
17
+
18
+ function getBinaryPath() {
19
+ const platformKey = `${os.platform()}-${os.arch()}`;
20
+ const pkg = PLATFORMS[platformKey];
21
+
22
+ if (!pkg) {
23
+ console.error(
24
+ `openlatch: unsupported platform ${platformKey}. ` +
25
+ `Supported: ${Object.keys(PLATFORMS).join(", ")}`
26
+ );
27
+ process.exit(1);
28
+ }
29
+
30
+ const ext = os.platform() === "win32" ? ".exe" : "";
31
+ const binaryName = `openlatch${ext}`;
32
+
33
+ // Try to resolve from the platform-specific optional dependency
34
+ try {
35
+ const pkgDir = path.dirname(require.resolve(`${pkg}/package.json`));
36
+ return path.join(pkgDir, binaryName);
37
+ } catch {
38
+ // Optional dependency not installed (--no-optional, Yarn Plug-n-Play, etc.)
39
+ // Fall back to postinstall-downloaded binary
40
+ return path.join(__dirname, "..", "bin", binaryName);
41
+ }
42
+ }
43
+
44
+ const binary = getBinaryPath();
45
+
46
+ try {
47
+ execFileSync(binary, process.argv.slice(2), {
48
+ stdio: "inherit",
49
+ env: process.env,
50
+ });
51
+ } catch (err) {
52
+ if (err.status !== null && err.status !== undefined) {
53
+ process.exit(err.status);
54
+ }
55
+ if (err.code === "ENOENT") {
56
+ console.error(
57
+ `openlatch: binary not found at ${binary}\n` +
58
+ `Try reinstalling: npm install -g @openlatch/client`
59
+ );
60
+ process.exit(1);
61
+ }
62
+ process.exit(1);
63
+ }
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ // Postinstall fallback: downloads native binaries from GitHub Releases
6
+ // when the platform-specific optional dependency was not installed
7
+ // (e.g., --no-optional, unsupported package manager, corporate proxy).
8
+ //
9
+ // IMPORTANT: This script must NEVER fail the npm install (fail-open principle).
10
+
11
+ const os = require("os");
12
+ const fs = require("fs");
13
+ const path = require("path");
14
+ const { execSync } = require("child_process");
15
+
16
+ const PLATFORM_PACKAGES = {
17
+ "darwin-arm64": "@openlatch/client-darwin-arm64",
18
+ "darwin-x64": "@openlatch/client-darwin-x64",
19
+ "linux-x64": "@openlatch/client-linux-x64",
20
+ "linux-arm64": "@openlatch/client-linux-arm64",
21
+ "win32-x64": "@openlatch/client-win32-x64",
22
+ };
23
+
24
+ const RUST_TARGETS = {
25
+ "darwin-arm64": "aarch64-apple-darwin",
26
+ "darwin-x64": "x86_64-apple-darwin",
27
+ "linux-x64": "x86_64-unknown-linux-gnu",
28
+ "linux-arm64": "aarch64-unknown-linux-gnu",
29
+ "win32-x64": "x86_64-pc-windows-msvc",
30
+ };
31
+
32
+ function isPlatformPackageInstalled() {
33
+ const platformKey = `${os.platform()}-${os.arch()}`;
34
+ const pkg = PLATFORM_PACKAGES[platformKey];
35
+ if (!pkg) return false;
36
+
37
+ try {
38
+ require.resolve(`${pkg}/package.json`);
39
+ return true;
40
+ } catch {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ function downloadBinaries() {
46
+ if (isPlatformPackageInstalled()) {
47
+ return; // Platform package already installed, nothing to do
48
+ }
49
+
50
+ const platformKey = `${os.platform()}-${os.arch()}`;
51
+ const rustTarget = RUST_TARGETS[platformKey];
52
+
53
+ if (!rustTarget) {
54
+ console.warn(
55
+ `openlatch: postinstall skipped — unsupported platform ${platformKey}`
56
+ );
57
+ return;
58
+ }
59
+
60
+ // Read version from own package.json
61
+ const pkgJson = JSON.parse(
62
+ fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8")
63
+ );
64
+ const version = pkgJson.version;
65
+ const ext = os.platform() === "win32" ? ".exe" : "";
66
+
67
+ const binDir = path.join(__dirname, "..", "bin");
68
+ fs.mkdirSync(binDir, { recursive: true });
69
+
70
+ const binaries = ["openlatch", "openlatch-hook"];
71
+
72
+ for (const binaryName of binaries) {
73
+ const assetName = `${binaryName}-${rustTarget}${ext}`;
74
+ const url = `https://github.com/OpenLatch/openlatch-client/releases/download/v${version}/${assetName}`;
75
+ const dest = path.join(binDir, `${binaryName}${ext}`);
76
+
77
+ console.log(`openlatch: downloading ${binaryName} for ${platformKey}...`);
78
+
79
+ try {
80
+ execSync(`curl -fSL --retry 3 -o "${dest}" "${url}"`, {
81
+ stdio: "pipe",
82
+ timeout: 30000,
83
+ });
84
+ if (os.platform() !== "win32") {
85
+ fs.chmodSync(dest, 0o755);
86
+ }
87
+ } catch {
88
+ console.warn(
89
+ `openlatch: failed to download ${binaryName} — ` +
90
+ `you can download manually from ${url}`
91
+ );
92
+ return; // Don't fail the install
93
+ }
94
+ }
95
+
96
+ console.log("openlatch: binaries installed successfully");
97
+ }
98
+
99
+ try {
100
+ downloadBinaries();
101
+ } catch (err) {
102
+ // Never fail the npm install — fail-open principle
103
+ console.warn(`openlatch: postinstall warning — ${err.message}`);
104
+ }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@openlatch/client",
3
+ "version": "0.0.0",
4
+ "description": "OpenLatch — the open-source security layer for AI agents",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/OpenLatch/openlatch-client"
9
+ },
10
+ "homepage": "https://openlatch.ai",
11
+ "bin": {
12
+ "openlatch": "lib/index.js"
13
+ },
14
+ "files": ["lib/"],
15
+ "scripts": {
16
+ "postinstall": "node lib/postinstall.js"
17
+ },
18
+ "optionalDependencies": {
19
+ "@openlatch/client-darwin-arm64": "0.0.0",
20
+ "@openlatch/client-darwin-x64": "0.0.0",
21
+ "@openlatch/client-linux-x64": "0.0.0",
22
+ "@openlatch/client-linux-arm64": "0.0.0",
23
+ "@openlatch/client-win32-x64": "0.0.0"
24
+ }
25
+ }