@openstrap/plugin-contract 0.1.0 → 0.1.2

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/Transport.d.ts CHANGED
@@ -62,6 +62,20 @@ export type TransportConnection = Transport & {
62
62
  authMethods: readonly string[];
63
63
  };
64
64
 
65
+ /**
66
+ * How a standard OpenSSH client reaches a machine through a transport: what openstrap hands a tool
67
+ * it runs against the machine, such as Ansible, that speaks OpenSSH rather than openstrap's ports.
68
+ */
69
+ export type OpenSshAccess = {
70
+ host: string;
71
+ port: number;
72
+ user: string;
73
+ /** The private key to log in with, where the transport logs in by key. Absent where it does not. */
74
+ privateKey?: string;
75
+ /** `ssh -o` options the transport needs, as name and value. */
76
+ options?: Readonly<Record<string, string>>;
77
+ };
78
+
65
79
  /**
66
80
  * Opens a transport to a target.
67
81
  *
@@ -90,5 +104,10 @@ export type TransportConnector = {
90
104
  * key it was given rather than one of the connector's own. Nothing is kept.
91
105
  */
92
106
  publicKeyOf?(privateKey: string): Promise<string>;
107
+ /**
108
+ * How an OpenSSH client reaches the machine the way this transport does. Optional: a transport
109
+ * that is not SSH underneath has nothing to say to OpenSSH.
110
+ */
111
+ openSshAccess?(request: TransportConnectionRequest): Promise<OpenSshAccess>;
93
112
  connect(request: TransportConnectionRequest): Promise<TransportConnection>;
94
113
  };
package/index.d.ts CHANGED
@@ -32,6 +32,7 @@ export type {
32
32
  SecretStore,
33
33
  } from "./Secret.js";
34
34
  export type {
35
+ OpenSshAccess,
35
36
  TransportConnection,
36
37
  TransportConnectionRequest,
37
38
  TransportConnector,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openstrap/plugin-contract",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "The shape an OpenStrap plugin has. Types only: no runtime code, so a plugin depends on the contract and never on OpenStrap.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -10,9 +10,15 @@
10
10
  },
11
11
  "files": [
12
12
  "*.d.ts",
13
+ "ports/*.d.ts",
13
14
  "README.md"
14
15
  ],
15
16
  "license": "UNLICENSED",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/yardencom/openstrap.git",
20
+ "directory": "contract"
21
+ },
16
22
  "publishConfig": {
17
23
  "access": "public"
18
24
  }
@@ -0,0 +1,42 @@
1
+ export type FileAccess = "executable" | "private" | "readable";
2
+
3
+ export type FileSystemWriteOptions = {
4
+ mode?: number;
5
+ };
6
+
7
+ export type TextFileWriteOptions = FileSystemWriteOptions & {
8
+ access?: FileAccess;
9
+ strategy?: "atomic";
10
+ };
11
+
12
+ export type RemovePathOptions = {
13
+ force?: boolean;
14
+ recursive?: boolean;
15
+ };
16
+
17
+ export type BinaryFileWriteOptions = FileSystemWriteOptions & {
18
+ access?: FileAccess;
19
+ };
20
+
21
+ export interface FileSystemAPI {
22
+ copyFile(source: string, destination: string): Promise<void>;
23
+ createDirectory(path: string, options?: FileSystemWriteOptions): Promise<void>;
24
+ createExclusiveDirectory(path: string): Promise<boolean>;
25
+ executable(path: string): Promise<boolean>;
26
+ mode(path: string): Promise<number | null>;
27
+ joinPath(...parts: string[]): string;
28
+ parentPath(path: string): string;
29
+ resolvePathWithin(directory: string, ...parts: string[]): string;
30
+ setAccess(path: string, access: FileAccess): Promise<void>;
31
+ readTextFile(path: string): Promise<string | null>;
32
+ removePath(path: string, options?: RemovePathOptions): Promise<void>;
33
+ writeTextFile(path: string, content: string, options?: TextFileWriteOptions): Promise<void>;
34
+ /**
35
+ * The bytes of a file, or null when there is no such file.
36
+ *
37
+ * Separate from `readTextFile` because a decoding is a decision: an executable
38
+ * read as UTF-8 comes back corrupted, and the corruption is silent.
39
+ */
40
+ readFile(path: string): Promise<Buffer | null>;
41
+ writeFile(path: string, content: Buffer, options?: BinaryFileWriteOptions): Promise<void>;
42
+ }
@@ -0,0 +1,23 @@
1
+ export type DownloadResult = {
2
+ bytes: number;
3
+ sha256: string;
4
+ };
5
+
6
+ export type NetworkRequest = {
7
+ body?: string;
8
+ headers: Record<string, string>;
9
+ method: "GET" | "POST";
10
+ timeoutMs?: number;
11
+ };
12
+
13
+ export type NetworkResponse = {
14
+ body: string;
15
+ status: number;
16
+ };
17
+
18
+ export interface NetworkAPI {
19
+ download(url: string, destination: string): Promise<DownloadResult>;
20
+ endpointReady(url: string, timeoutMs: number): Promise<boolean>;
21
+ readText(url: string): Promise<string>;
22
+ request(url: string, request: NetworkRequest): Promise<NetworkResponse>;
23
+ }
@@ -0,0 +1,35 @@
1
+ export type SystemCommand = {
2
+ command: string;
3
+ args: string[];
4
+ cwd: string;
5
+ environment?: Record<string, string | undefined>;
6
+ /** UTF-8 input delivered to the program's stdin, never through arguments or environment. */
7
+ stdin?: string;
8
+ stdio: "ignore" | "inherit";
9
+ };
10
+
11
+ export type CapturedSystemCommand = Omit<SystemCommand, "stdio">;
12
+
13
+ export type DetachedProcessCommand = {
14
+ command: string;
15
+ args: string[];
16
+ cwd: string;
17
+ environment?: Record<string, string | undefined>;
18
+ stdoutLog: string;
19
+ stderrLog: string;
20
+ };
21
+
22
+ export type ProcessOutput = {
23
+ exitCode: number | null;
24
+ stdout: string;
25
+ stderr: string;
26
+ };
27
+
28
+ export interface ProcessAPI {
29
+ capture(command: CapturedSystemCommand): Promise<ProcessOutput>;
30
+ processRunning(pid: number): Promise<boolean>;
31
+ run(command: SystemCommand): Promise<void>;
32
+ startDetachedProcess(command: DetachedProcessCommand): Promise<number>;
33
+ stopDetachedProcess(pid: number, timeoutMs: number): Promise<void>;
34
+ succeeds(command: SystemCommand): Promise<boolean>;
35
+ }
@@ -0,0 +1,17 @@
1
+ import type { FileSystemAPI } from "./FileSystem.js";
2
+ import type { NetworkAPI } from "./Network.js";
3
+ import type { ProcessAPI } from "./Process.js";
4
+
5
+ /**
6
+ * A channel of access to a target, plus the operations performed through it.
7
+ *
8
+ * Progress output and the openstrap process environment are deliberately absent:
9
+ * they belong to the host process, not to the channel. The port also returns no
10
+ * derived data — deciding which operating system a target runs is fact collection,
11
+ * not transport.
12
+ */
13
+ export type Transport = {
14
+ fileSystem: FileSystemAPI;
15
+ network: NetworkAPI;
16
+ processes: ProcessAPI;
17
+ };