@treeship/sdk 0.2.1 → 0.3.1
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/attest.js +4 -2
- package/dist/ship.d.ts +14 -0
- package/dist/ship.js +33 -0
- package/dist/types.d.ts +4 -2
- package/dist/verify.js +54 -7
- package/package.json +1 -1
package/dist/attest.js
CHANGED
|
@@ -13,8 +13,10 @@ export class AttestModule {
|
|
|
13
13
|
}
|
|
14
14
|
async approval(params) {
|
|
15
15
|
const args = ["attest", "approval", "--approver", params.approver, "--description", params.description, "--format", "json"];
|
|
16
|
-
if (params.
|
|
17
|
-
args.push("--expires", params.
|
|
16
|
+
if (params.expires)
|
|
17
|
+
args.push("--expires", params.expires);
|
|
18
|
+
if (params.subject)
|
|
19
|
+
args.push("--subject", params.subject);
|
|
18
20
|
const result = await runTreeship(args);
|
|
19
21
|
return { artifactId: (result.id || result.artifact_id), nonce: result.nonce };
|
|
20
22
|
}
|
package/dist/ship.d.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { AttestModule } from "./attest.js";
|
|
2
2
|
import { VerifyModule } from "./verify.js";
|
|
3
3
|
import { DockModule } from "./dock.js";
|
|
4
|
+
/**
|
|
5
|
+
* Main entry point for the Treeship TypeScript SDK.
|
|
6
|
+
*
|
|
7
|
+
* This SDK shells out to the `treeship` CLI binary, which must be installed
|
|
8
|
+
* and available on your PATH. Use {@link Ship.checkCli} to verify the
|
|
9
|
+
* binary is reachable before calling other methods.
|
|
10
|
+
*/
|
|
4
11
|
export declare class Ship {
|
|
5
12
|
readonly attest: AttestModule;
|
|
6
13
|
readonly verify: VerifyModule;
|
|
7
14
|
readonly dock: DockModule;
|
|
15
|
+
/**
|
|
16
|
+
* Checks that the `treeship` CLI binary is available and returns its
|
|
17
|
+
* version string (e.g. "0.4.1").
|
|
18
|
+
*
|
|
19
|
+
* Throws a descriptive error if the binary is not found on PATH.
|
|
20
|
+
*/
|
|
21
|
+
static checkCli(): Promise<string>;
|
|
8
22
|
}
|
package/dist/ship.js
CHANGED
|
@@ -1,8 +1,41 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
1
3
|
import { AttestModule } from "./attest.js";
|
|
2
4
|
import { VerifyModule } from "./verify.js";
|
|
3
5
|
import { DockModule } from "./dock.js";
|
|
6
|
+
const exec = promisify(execFile);
|
|
7
|
+
/**
|
|
8
|
+
* Main entry point for the Treeship TypeScript SDK.
|
|
9
|
+
*
|
|
10
|
+
* This SDK shells out to the `treeship` CLI binary, which must be installed
|
|
11
|
+
* and available on your PATH. Use {@link Ship.checkCli} to verify the
|
|
12
|
+
* binary is reachable before calling other methods.
|
|
13
|
+
*/
|
|
4
14
|
export class Ship {
|
|
5
15
|
attest = new AttestModule();
|
|
6
16
|
verify = new VerifyModule();
|
|
7
17
|
dock = new DockModule();
|
|
18
|
+
/**
|
|
19
|
+
* Checks that the `treeship` CLI binary is available and returns its
|
|
20
|
+
* version string (e.g. "0.4.1").
|
|
21
|
+
*
|
|
22
|
+
* Throws a descriptive error if the binary is not found on PATH.
|
|
23
|
+
*/
|
|
24
|
+
static async checkCli() {
|
|
25
|
+
try {
|
|
26
|
+
const { stdout } = await exec("treeship", ["version"], {
|
|
27
|
+
timeout: 5_000,
|
|
28
|
+
env: { ...process.env },
|
|
29
|
+
});
|
|
30
|
+
return stdout.trim();
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
34
|
+
if (msg.includes("ENOENT") || msg.includes("not found")) {
|
|
35
|
+
throw new Error("treeship CLI binary not found on PATH. " +
|
|
36
|
+
"Install it from https://treeship.dev/docs/install before using the SDK.");
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Failed to run 'treeship version': ${msg}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
8
41
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -8,8 +8,10 @@ export interface ActionParams {
|
|
|
8
8
|
export interface ApprovalParams {
|
|
9
9
|
approver: string;
|
|
10
10
|
description: string;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** ISO-8601 timestamp when the approval expires (e.g. "2026-12-31T00:00:00Z"). */
|
|
12
|
+
expires?: string;
|
|
13
|
+
/** Maps to the CLI --subject flag. Identifies what this approval covers. */
|
|
14
|
+
subject?: string;
|
|
13
15
|
}
|
|
14
16
|
export interface HandoffParams {
|
|
15
17
|
from: string;
|
package/dist/verify.js
CHANGED
|
@@ -1,11 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const exec = promisify(execFile);
|
|
2
4
|
export class VerifyModule {
|
|
3
5
|
async verify(id) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
let stdout = "";
|
|
7
|
+
let stderr = "";
|
|
8
|
+
try {
|
|
9
|
+
const result = await exec("treeship", ["verify", id, "--format", "json"], {
|
|
10
|
+
timeout: 10_000,
|
|
11
|
+
env: { ...process.env },
|
|
12
|
+
});
|
|
13
|
+
stdout = result.stdout;
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
// Binary not found -- re-throw as operational error
|
|
17
|
+
if (err instanceof Error && (err.message.includes("ENOENT") || err.message.includes("not found"))) {
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
// Non-zero exit: try to parse stdout/stderr for structured output.
|
|
21
|
+
// The CLI writes JSON to stdout even on verification failure.
|
|
22
|
+
const execErr = err;
|
|
23
|
+
stdout = execErr.stdout || "";
|
|
24
|
+
stderr = execErr.stderr || "";
|
|
25
|
+
if (!stdout) {
|
|
26
|
+
// No JSON output at all -- this is an operational error, not a verification failure.
|
|
27
|
+
throw new Error(`treeship verify failed: ${stderr || (err instanceof Error ? err.message : String(err))}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Parse the JSON output from the CLI.
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = JSON.parse(stdout);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error(`treeship verify returned invalid JSON: ${stdout.slice(0, 200)}`);
|
|
37
|
+
}
|
|
38
|
+
const outcome = parsed.outcome;
|
|
39
|
+
if (outcome === "pass") {
|
|
40
|
+
return {
|
|
41
|
+
outcome: "pass",
|
|
42
|
+
chain: (parsed.passed || parsed.total || 1),
|
|
43
|
+
target: id,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else if (outcome === "fail") {
|
|
47
|
+
return {
|
|
48
|
+
outcome: "fail",
|
|
49
|
+
chain: (parsed.failed || 0),
|
|
50
|
+
target: id,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// outcome: "error" or unknown -- propagate as operational error
|
|
55
|
+
throw new Error(`treeship verify error: ${parsed.message || JSON.stringify(parsed)}`);
|
|
56
|
+
}
|
|
10
57
|
}
|
|
11
58
|
}
|