@simmit/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/index.cjs +776 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2143 -0
- package/dist/index.d.ts +2143 -0
- package/dist/index.js +718 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Voidly Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Simmit SDK for TypeScript
|
|
2
|
+
|
|
3
|
+
[](https://github.com/voidly-labs/simmit-sdk-typescript/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@simmit/sdk)
|
|
5
|
+
|
|
6
|
+
TypeScript SDK for the [Simmit API](https://api.simmit.com) — cloud execution for SimulationCraft.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @simmit/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Node 20+. Zero runtime dependencies — global `fetch` and WebCrypto only.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import Simmit from '@simmit/sdk'
|
|
20
|
+
|
|
21
|
+
const client = new Simmit() // reads SIMMIT_SECRET_KEY from the environment
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or pass the secret key explicitly:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
const client = new Simmit({ secretKey: 'smt_sk_...' })
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Run a sim and wait for the result
|
|
31
|
+
|
|
32
|
+
`createAndWait` submits a job and polls until it reaches a terminal state,
|
|
33
|
+
resolving with the completed job — ideal for scripts and queue workers that can
|
|
34
|
+
hold a promise open:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const job = await client.jobs.createAndWait({
|
|
38
|
+
build: { channel: 'latest' },
|
|
39
|
+
profile: { text: profileText } // a SimC profile, up to 2 MB
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const result = await client.jobs.getResult(job.id)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Observe progress, or capture the job id before polling starts:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
await client.jobs.createAndWait(
|
|
49
|
+
{ build: { channel: 'latest' }, profile: { text: profileText } },
|
|
50
|
+
{
|
|
51
|
+
onCreated: (res) => console.log('queued', res.id),
|
|
52
|
+
onPoll: (status) => console.log(status.status, status.progress.percent)
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Submit, poll, and read the result (decoupled)
|
|
58
|
+
|
|
59
|
+
For web apps that can't hold a promise open, drive the lifecycle yourself:
|
|
60
|
+
`create` returns immediately with a job id to persist, then poll `getStatus` on
|
|
61
|
+
your own cadence and read the result once terminal. A `job.terminal` webhook is
|
|
62
|
+
the reliable completion signal when a browser poll can pause (see below).
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const { id } = await client.jobs.create({
|
|
66
|
+
build: { channel: 'nightly' },
|
|
67
|
+
profile: { text: profileText }
|
|
68
|
+
})
|
|
69
|
+
// persist `id`, return to the caller, then from a later request:
|
|
70
|
+
|
|
71
|
+
const status = await client.jobs.getStatus(id) // status + progress, in any state
|
|
72
|
+
if (status.status === 'completed') {
|
|
73
|
+
const result = await client.jobs.getResult(id)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await client.jobs.cancel(id) // request cancellation
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Artifact download URLs
|
|
80
|
+
|
|
81
|
+
`getResult` returns each artifact with a stable download `url`, valid for the
|
|
82
|
+
artifact's full retention window. To fetch that URL on demand instead — e.g. a
|
|
83
|
+
browser flow that controls the final fetch — use:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
const { url } = await client.artifacts.getUrl(artifactId)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Credits
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const balance = await client.credits.get()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Errors
|
|
96
|
+
|
|
97
|
+
Every API error is a typed subclass of `SimmitError`, with a narrowed `code`
|
|
98
|
+
and `meta`:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { InsufficientCreditsError, InvalidProfileError } from '@simmit/sdk'
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await client.jobs.create({ build: { channel: 'latest' }, profile: { text } })
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (err instanceof InvalidProfileError) {
|
|
107
|
+
console.error(err.meta.blocked) // the rejected profile lines
|
|
108
|
+
} else if (err instanceof InsufficientCreditsError) {
|
|
109
|
+
console.error(err.meta?.maxAffordableRuntimeSeconds)
|
|
110
|
+
} else {
|
|
111
|
+
throw err
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`createAndWait` also throws `JobFailedError` / `JobCancelledError` /
|
|
117
|
+
`JobTimedOutError` (each carrying the full `.job`), and `JobWaitTimeoutError` if
|
|
118
|
+
the wait deadline passes before the job finishes — the job keeps running, so
|
|
119
|
+
call `client.jobs.cancel(jobId)` to stop the spend.
|
|
120
|
+
|
|
121
|
+
### Response headers
|
|
122
|
+
|
|
123
|
+
Single-request methods return an `APIPromise`. Await it for the parsed body, or
|
|
124
|
+
use `.withResponse()` to reach the raw `Response` (rate-limit headers, idempotent
|
|
125
|
+
replays):
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const { data, response } = await client.jobs.create(params).withResponse()
|
|
129
|
+
response.headers.get('x-idempotent-replay')
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Verifying webhooks
|
|
133
|
+
|
|
134
|
+
`unwrapWebhook` verifies a webhook signature and returns the parsed event. It is
|
|
135
|
+
standalone — no client and no API key required, just your webhook signing
|
|
136
|
+
secret — so it is safe to run in a webhook receiver:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { unwrapWebhook } from '@simmit/sdk'
|
|
140
|
+
|
|
141
|
+
const event = await unwrapWebhook(
|
|
142
|
+
rawBody, // the raw request body, exactly as received
|
|
143
|
+
signatureHeader, // the X-Simmit-Signature header value
|
|
144
|
+
process.env.SIMMIT_WEBHOOK_SECRET
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
if (event.payload.status === 'completed') {
|
|
148
|
+
// ...
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Development
|
|
153
|
+
|
|
154
|
+
- Node 20+ (`.nvmrc` pins the dev version), pnpm.
|
|
155
|
+
- `pnpm generate` — regenerate `src/generated/openapi.d.ts` from the committed `openapi.json` snapshot. Never hand-edit generated output; only `src/api-types.ts` may import from `src/generated/`.
|
|
156
|
+
- `pnpm build` — dual ESM+CJS via tsup.
|
|
157
|
+
- `pnpm test` — vitest (hermetic; mocks `fetch`, no network).
|
|
158
|
+
- `pnpm smoke` — manual check against a real API (needs `SIMMIT_SECRET_KEY`; set `SIMMIT_PROFILE_FILE` to also run a full create→result, or `TEST_API_BASE_URL` to target a non-prod endpoint). See `scripts/smoke.mjs`.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT
|