@toshicloud/sdk 0.3.1 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +21 -2
  2. package/package.json +10 -2
package/README.md CHANGED
@@ -19,6 +19,8 @@ generated clients alike.
19
19
 
20
20
  In Node, with `@connectrpc/connect-node`:
21
21
 
22
+ <!-- examples/quick-start.ts -->
23
+
22
24
  ```ts
23
25
  import { readFileSync } from "node:fs";
24
26
  import { createConnectTransport } from "@connectrpc/connect-node";
@@ -38,15 +40,21 @@ const toshi = createToshiClient({
38
40
  });
39
41
 
40
42
  const { projects } = await toshi.project.listProjects({});
43
+ console.log(projects.length);
41
44
  ```
42
45
 
43
46
  In a browser, with `@connectrpc/connect-web`:
44
47
 
48
+ <!-- examples/browser.ts -->
49
+
45
50
  ```ts
46
51
  import { createConnectTransport } from "@connectrpc/connect-web";
47
52
  import { createToshiClient } from "@toshicloud/sdk";
48
53
 
49
- const toshi = createToshiClient({
54
+ // The token the browser app already holds.
55
+ declare const token: string;
56
+
57
+ export const toshi = createToshiClient({
50
58
  transport: (interceptors) =>
51
59
  createConnectTransport({ baseUrl: "https://toshi.example.com", interceptors }),
52
60
  token,
@@ -86,9 +94,12 @@ span the three types sit on `workload` itself: `listEvents`, `watchEvents`,
86
94
  `getOperation` and `waitOperation`. `run` sits at the top of the client, as
87
95
  `toshi run` sits at the top of the CLI.
88
96
 
97
+ <!-- examples/client-shape.ts -->
98
+
89
99
  ```ts
90
100
  const { jobs } = await toshi.workload.jobs.list({ pageSize: 10 });
91
- const job = await toshi.workload.jobs.get({ id: jobs[0].id });
101
+ const { job } = await toshi.workload.jobs.get({ id: jobs[0].id });
102
+ console.log(job?.id);
92
103
  ```
93
104
 
94
105
  ### Retries
@@ -130,7 +141,10 @@ from a server error.
130
141
  `WatchEventsResponse` (`event`), and the output watch yields
131
142
  `WatchOutputResponse` (`stdout`, `stderr` or `end`).
132
143
 
144
+ <!-- examples/watch-events.ts -->
145
+
133
146
  ```ts
147
+ const id = "workload-id";
134
148
  const watch = await toshi.workload.watchEvents({ workloadId: id });
135
149
  for await (const { event } of watch) {
136
150
  console.log(event?.name);
@@ -151,7 +165,10 @@ client holds at most one buffer of input. `closeStdin` ends standard input
151
165
  after a pending write, and a later `write` is refused. `wait` settles when
152
166
  the command ends.
153
167
 
168
+ <!-- examples/execute.ts -->
169
+
154
170
  ```ts
171
+ const id = "sandbox-id";
155
172
  const proc = await toshi.workload.sandboxes.execute({
156
173
  sandboxId: id,
157
174
  command: { argv: ["cat"] },
@@ -184,6 +201,8 @@ job and its output, which is what `toshi run` does: `CreateJob`, then
184
201
  `WatchOutput`. It yields output chunks like an execution, and `wait()`
185
202
  resolves when the job exits 0 and rejects with `JobExitError` otherwise.
186
203
 
204
+ <!-- examples/run-job.ts -->
205
+
187
206
  ```ts
188
207
  const run = await toshi.run({
189
208
  spec: { command: { argv: ["./test.sh"] } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toshicloud/sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "TypeScript client for the Toshi Workspace API",
5
5
  "license": "Apache-2.0",
6
6
  "packageManager": "pnpm@12.15.0+sha512.b3951d6d6ff4a9f13dc7cf56cd28d2b8eb37dbcc9c68e52e1e1191873ea9f82a017287ab50baadc5ccc494f036c67c0e47eb13608c2fa36f47711b61ea128e61",
@@ -18,7 +18,14 @@
18
18
  ],
19
19
  "sideEffects": false,
20
20
  "engines": {
21
- "node": ">=24.22 <25"
21
+ "node": ">=22"
22
+ },
23
+ "devEngines": {
24
+ "runtime": {
25
+ "name": "node",
26
+ "version": ">=24.22 <25",
27
+ "onFail": "error"
28
+ }
22
29
  },
23
30
  "repository": {
24
31
  "type": "git",
@@ -38,6 +45,7 @@
38
45
  },
39
46
  "devDependencies": {
40
47
  "@connectrpc/connect-node": "2.2.0",
48
+ "@connectrpc/connect-web": "2.2.0",
41
49
  "@eslint/js": "10.0.1",
42
50
  "@types/node": "26.6.5",
43
51
  "@vitest/coverage-v8": "5.0.5",