@landstrip/landstrip-api 0.20.9 → 0.20.11

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 CHANGED
@@ -1,7 +1,8 @@
1
1
  # @landstrip/landstrip-api
2
2
 
3
- Node.js wrapper and types for Landstrip. Requires Node.js ≥18; native binaries
4
- support Linux, macOS, and Windows on x64/arm64.
3
+ TypeScript APIs for Landstrip. Requires Node.js ≥18 and depends on
4
+ `@landstrip/landstrip` to install the executable for Linux, macOS, and Windows on
5
+ x64/arm64. This API package does not own the CLI or platform binary packages.
5
6
 
6
7
  ## Install
7
8
 
@@ -9,8 +10,17 @@ support Linux, macOS, and Windows on x64/arm64.
9
10
  npm install --save-dev @landstrip/landstrip-api
10
11
  ```
11
12
 
12
- See the [quick start](../../README.md#quick-start) for a policy and CLI example;
13
- [landstrip(1)](../landstrip/man/man1/landstrip.1) covers policy and platform limits.
13
+ ## Usage
14
+
15
+ ```sh
16
+ npx landstrip run -p policy.json -- cargo test
17
+ npx landstrip check -p policy.json
18
+ npx landstrip doctor
19
+ ```
20
+
21
+ See the [quick start](../../README.md#quick-start) for a policy example;
22
+ [landstrip(1)](../landstrip/man/man1/landstrip.1) covers policy and platform
23
+ limits.
14
24
 
15
25
  ## Node.js API
16
26
 
@@ -77,5 +87,5 @@ Run `make ci` from the repository root.
77
87
 
78
88
  ## License
79
89
 
80
- [Apache-2.0](LICENSE); bundled native binaries are
81
- [LGPL-2.1-or-later](../landstrip/LICENSE).
90
+ [Apache-2.0](LICENSE); native binaries installed through `@landstrip/landstrip`
91
+ are [LGPL-2.1-or-later](../landstrip/LICENSE).
package/lib/index.js CHANGED
@@ -1,100 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  'use strict';
3
3
 
4
- const fs = require('node:fs');
5
- const path = require('node:path');
6
-
7
- const packages = {
8
- 'darwin-arm64': {
9
- packageName: '@landstrip/landstrip-darwin-arm64',
10
- binary: 'bin/landstrip',
11
- },
12
- 'darwin-x64': {
13
- packageName: '@landstrip/landstrip-darwin-x64',
14
- binary: 'bin/landstrip',
15
- },
16
- 'linux-x64': {
17
- packageName: '@landstrip/landstrip-linux-x64',
18
- binary: 'bin/landstrip',
19
- },
20
- 'linux-arm64': {
21
- packageName: '@landstrip/landstrip-linux-arm64',
22
- binary: 'bin/landstrip',
23
- },
24
- 'win32-x64': {
25
- packageName: '@landstrip/landstrip-win32-x64',
26
- binary: 'bin/landstrip.exe',
27
- },
28
- 'win32-arm64': {
29
- packageName: '@landstrip/landstrip-win32-arm64',
30
- binary: 'bin/landstrip.exe',
31
- },
32
- };
33
-
34
- const officialPackageNames = new Set([
35
- '@landstrip/landstrip-api',
36
- ...Object.values(packages).map((value) => value.packageName),
37
- ]);
38
-
39
- function target(platform = process.platform, arch = process.arch) {
40
- const key = `${platform}-${arch}`;
41
- const value = packages[key];
42
-
43
- if (!value) {
44
- throw new Error(`Unsupported landstrip platform: ${platform} ${arch}`);
45
- }
46
-
47
- return value;
48
- }
49
-
50
- function packageName(platform = process.platform, arch = process.arch) {
51
- return target(platform, arch).packageName;
52
- }
53
-
54
- function binaryPath(platform = process.platform, arch = process.arch) {
55
- const value = target(platform, arch);
56
- let manifest;
57
-
58
- try {
59
- manifest = require.resolve(`${value.packageName}/package.json`);
60
- } catch (error) {
61
- throw new Error(
62
- `The landstrip binary package ${value.packageName} is not installed. ` +
63
- 'Reinstall @landstrip/landstrip-api with optional dependencies enabled.'
64
- );
65
- }
66
-
67
- const resolved = path.join(path.dirname(manifest), value.binary);
68
-
69
- if (!fs.statSync(resolved).isFile()) {
70
- throw new Error(`landstrip binary not found at ${resolved}`);
71
- }
72
-
73
- const filePath = fs.realpathSync.native(resolved);
74
- let probe = path.dirname(filePath);
75
- while (true) {
76
- let owner;
77
- try {
78
- owner = JSON.parse(fs.readFileSync(path.join(probe, 'package.json'), 'utf8'));
79
- } catch (error) {
80
- if (error.code !== 'ENOENT' && !(error instanceof SyntaxError)) throw error;
81
- }
82
- if (
83
- owner !== null &&
84
- typeof owner === 'object' &&
85
- !Array.isArray(owner) &&
86
- officialPackageNames.has(owner.name)
87
- ) {
88
- return filePath;
89
- }
90
- const parent = path.dirname(probe);
91
- if (parent === probe) break;
92
- probe = parent;
93
- }
94
- throw new Error(
95
- `Refusing to use landstrip binary outside official @landstrip/landstrip-api packages: ${filePath}`,
96
- );
97
- }
4
+ const { binaryPath, packageName } = require('@landstrip/landstrip');
98
5
 
99
6
  exports.binaryPath = binaryPath;
100
7
  exports.packageName = packageName;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@landstrip/landstrip-api",
3
- "version": "0.20.9",
4
- "description": "Sandbox runner using Landlock, Seatbelt, and AppContainer",
3
+ "version": "0.20.11",
4
+ "description": "TypeScript APIs for the Landstrip sandbox",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/landstrip/landstrip#readme",
7
7
  "repository": {
@@ -27,26 +27,15 @@
27
27
  "default": "./lib/proxy.js"
28
28
  }
29
29
  },
30
- "bin": {
31
- "landstrip": "bin/landstrip.js"
32
- },
33
30
  "files": [
34
- "bin",
35
31
  "lib",
36
32
  "README.md",
37
33
  "LICENSE"
38
34
  ],
39
35
  "dependencies": {
36
+ "@landstrip/landstrip": "0.20.11",
40
37
  "ipaddr.js": "^2.5.0"
41
38
  },
42
- "optionalDependencies": {
43
- "@landstrip/landstrip-darwin-arm64": "0.20.9",
44
- "@landstrip/landstrip-darwin-x64": "0.20.9",
45
- "@landstrip/landstrip-linux-x64": "0.20.9",
46
- "@landstrip/landstrip-linux-arm64": "0.20.9",
47
- "@landstrip/landstrip-win32-x64": "0.20.9",
48
- "@landstrip/landstrip-win32-arm64": "0.20.9"
49
- },
50
39
  "publishConfig": {
51
40
  "access": "public"
52
41
  },
package/bin/landstrip.js DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
- // SPDX-License-Identifier: Apache-2.0
3
- 'use strict';
4
-
5
- const { spawn } = require('node:child_process');
6
- const { binaryPath } = require('../lib');
7
-
8
- let child;
9
-
10
- try {
11
- const options = { stdio: 'inherit' };
12
- if (process.platform === 'linux') {
13
- options.env = { ...process.env, APPIMAGE_EXTRACT_AND_RUN: '1' };
14
- }
15
- child = spawn(binaryPath(), process.argv.slice(2), options);
16
- } catch (error) {
17
- console.error(error.message);
18
- process.exit(1);
19
- }
20
-
21
- child.on('error', (error) => {
22
- console.error(error.message);
23
- process.exit(1);
24
- });
25
-
26
- child.on('exit', (code, signal) => {
27
- if (signal) {
28
- if (process.platform === 'win32') {
29
- process.exit(1);
30
- }
31
-
32
- process.kill(process.pid, signal);
33
- return;
34
- }
35
-
36
- process.exit(code === null ? 1 : code);
37
- });