@secure-exec/sidecar 0.0.0-nathan-docs-sdk-expansion.c9c2e4e

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.
Files changed (4) hide show
  1. package/README.md +18 -0
  2. package/index.d.ts +12 -0
  3. package/index.js +74 -0
  4. package/package.json +27 -0
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @secure-exec/sidecar
2
+
3
+ Platform-specific resolver for the Secure Exec native sidecar binary.
4
+
5
+ The compiled `secure-exec-sidecar` binary ships inside one of the
6
+ `@secure-exec/sidecar-<platform>` packages. npm installs only the package
7
+ matching the current `os`/`cpu`/`libc` at install time.
8
+
9
+ ```js
10
+ const { getSidecarPath } = require("@secure-exec/sidecar");
11
+
12
+ const binaryPath = getSidecarPath();
13
+ ```
14
+
15
+ Set `SECURE_EXEC_SIDECAR_BIN` to an absolute path to override resolution for
16
+ development or custom builds.
17
+
18
+ Supported platforms: `linux-x64-gnu`, `linux-arm64-gnu`.
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Resolve the absolute path to the prebuilt `secure-exec-sidecar` binary for
3
+ * the current platform.
4
+ *
5
+ * Resolution priority:
6
+ * 1. `SECURE_EXEC_SIDECAR_BIN` env var.
7
+ * 2. A `secure-exec-sidecar` binary placed next to this package.
8
+ * 3. The platform-specific `@secure-exec/sidecar-<platform>` package.
9
+ *
10
+ * @throws if the platform is unsupported or no binary can be found.
11
+ */
12
+ export function getSidecarPath(): string;
package/index.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ // Platform-specific resolver for the prebuilt `secure-exec-sidecar` binary.
4
+ // The binary itself ships inside one of the `@secure-exec/sidecar-<platform>`
5
+ // packages, declared as optionalDependencies at publish time so npm only
6
+ // installs the package matching the current `os`/`cpu`/`libc`.
7
+ //
8
+ // Resolution priority:
9
+ // 1. `SECURE_EXEC_SIDECAR_BIN` env var.
10
+ // 2. A `secure-exec-sidecar` binary placed next to this package.
11
+ // 3. The platform-specific `@secure-exec/sidecar-<platform>` package.
12
+
13
+ const { existsSync } = require("node:fs");
14
+ const { join, dirname } = require("node:path");
15
+
16
+ const BINARY_NAME = "secure-exec-sidecar";
17
+
18
+ // No runtime chmod. Platform packages are published with `npm publish`, which
19
+ // preserves the binary's 0755 executable bit.
20
+
21
+ function getPlatformPackageName() {
22
+ const { platform, arch } = process;
23
+ switch (platform) {
24
+ case "linux":
25
+ if (arch === "x64") return "@secure-exec/sidecar-linux-x64-gnu";
26
+ if (arch === "arm64") return "@secure-exec/sidecar-linux-arm64-gnu";
27
+ break;
28
+ default:
29
+ break;
30
+ }
31
+ return null;
32
+ }
33
+
34
+ function getSidecarPath() {
35
+ const override = process.env.SECURE_EXEC_SIDECAR_BIN;
36
+ if (override) {
37
+ if (!existsSync(override)) {
38
+ throw new Error(
39
+ `SECURE_EXEC_SIDECAR_BIN is set to ${override} but the file does not exist`,
40
+ );
41
+ }
42
+ return override;
43
+ }
44
+
45
+ const localBinary = join(__dirname, BINARY_NAME);
46
+ if (existsSync(localBinary)) {
47
+ return localBinary;
48
+ }
49
+
50
+ const platformPkg = getPlatformPackageName();
51
+ if (!platformPkg) {
52
+ throw new Error(
53
+ `@secure-exec/sidecar: unsupported platform ${process.platform}/${process.arch}. ` +
54
+ "The Secure Exec sidecar currently supports linux x64 and arm64. " +
55
+ "Set SECURE_EXEC_SIDECAR_BIN to a local secure-exec-sidecar binary to override.",
56
+ );
57
+ }
58
+
59
+ let pkgJsonPath;
60
+ try {
61
+ pkgJsonPath = require.resolve(`${platformPkg}/package.json`);
62
+ } catch {
63
+ throw new Error(
64
+ `@secure-exec/sidecar: platform package ${platformPkg} is not installed.\n` +
65
+ "This usually means the platform is unsupported or optionalDependencies were\n" +
66
+ `skipped during install. Try: npm install --include=optional ${platformPkg}\n` +
67
+ "Or set SECURE_EXEC_SIDECAR_BIN to a local secure-exec-sidecar binary.",
68
+ );
69
+ }
70
+
71
+ return join(dirname(pkgJsonPath), BINARY_NAME);
72
+ }
73
+
74
+ module.exports = { getSidecarPath };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@secure-exec/sidecar",
3
+ "version": "0.0.0-nathan-docs-sdk-expansion.c9c2e4e",
4
+ "description": "Platform-specific resolver for the Secure Exec native sidecar binary",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/rivet-dev/secure-exec.git",
9
+ "directory": "packages/sidecar"
10
+ },
11
+ "main": "./index.js",
12
+ "types": "./index.d.ts",
13
+ "files": [
14
+ "index.js",
15
+ "index.d.ts",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "test": "node --test tests/*.test.cjs"
20
+ },
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "optionalDependencies": {
25
+ "@secure-exec/sidecar-linux-x64-gnu": "0.0.0-nathan-docs-sdk-expansion.c9c2e4e"
26
+ }
27
+ }