@omirion/orbit-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 +83 -0
- package/dist/index.cjs +1684 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3714 -0
- package/dist/index.d.ts +3714 -0
- package/dist/index.js +1661 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Omirion
|
|
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,83 @@
|
|
|
1
|
+
# @omirion/orbit-sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the [Omirion Orbit](https://orbit.omirion.com)
|
|
4
|
+
public API (`/api/v1`). Works in Node 18+, Deno, Bun, Cloudflare Workers, and
|
|
5
|
+
browsers. ESM + CJS, fully typed, zero runtime dependencies (the fetch client is
|
|
6
|
+
bundled).
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @omirion/orbit-sdk # or pnpm add / yarn add
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quickstart
|
|
15
|
+
|
|
16
|
+
Create a token in the dashboard (**Account → API tokens**), then:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { OrbitClient, decodeSample } from '@omirion/orbit-sdk'
|
|
20
|
+
|
|
21
|
+
const orbit = new OrbitClient({ token: process.env.ORBIT_TOKEN! })
|
|
22
|
+
// baseUrl defaults to https://orbit.omirion.com; sends `Authorization: Bearer oat_…`
|
|
23
|
+
|
|
24
|
+
// Cursor pagination is automatic, iterate every device, online only:
|
|
25
|
+
for await (const device of orbit.devices.iterate({ status: 'online' })) {
|
|
26
|
+
const sample = await orbit.telemetry.latest(device.id)
|
|
27
|
+
if (!sample) continue
|
|
28
|
+
|
|
29
|
+
// Join abbreviated metric keys to their labels/units via the manifest:
|
|
30
|
+
const manifest = await orbit.telemetry.manifest(device.id)
|
|
31
|
+
const rows = manifest ? decodeSample(sample, manifest) : []
|
|
32
|
+
for (const r of rows) console.log(`${device.name} · ${r.label}: ${r.value}${r.unit ?? ''}`)
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`OrbitClient` wraps the generated transport client with bearer auth, automatic
|
|
37
|
+
retries (429/502/503/504 + network) with backoff, response unwrapping, cursor
|
|
38
|
+
auto-pagination, and **typed errors** you can `catch`:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { InsufficientScopeError, DeviceRpcError } from '@omirion/orbit-sdk'
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await orbit.commands.exec(deviceId, { argv: ['systemctl', 'status', 'orbit-agent'] })
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (err instanceof InsufficientScopeError) {/* token missing api:command:exec */}
|
|
47
|
+
else if (err instanceof DeviceRpcError) {/* device offline / transport failed */}
|
|
48
|
+
else throw err
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Surface
|
|
53
|
+
|
|
54
|
+
- `orbit.me()`. Who the token authenticates as, its abilities and project
|
|
55
|
+
scope, and the projects it reaches. Requires no ability: the cheapest way to
|
|
56
|
+
verify a token works and to discover valid `projectId` values.
|
|
57
|
+
- `orbit.devices`. `list(params?)`, `get(id)`, `iterate(params?)` (async generator)
|
|
58
|
+
- `orbit.telemetry`. `latest(deviceId)`, `history(deviceId, { hours? })`, `manifest(deviceId)`
|
|
59
|
+
- `orbit.firmware`. `upload({ file, projectId, version, compatible, description? })`
|
|
60
|
+
- `orbit.commands`. `exec(deviceId, { argv, elevate?, timeoutMs? })`
|
|
61
|
+
- `decodeSample(sample, manifest)` / `decodeSamples(...)`, labelled telemetry rows
|
|
62
|
+
- Errors: `OrbitError` + `AuthenticationError`, `InsufficientScopeError`,
|
|
63
|
+
`ResourceNotFoundError`, `BadRequestError`, `ValidationError`,
|
|
64
|
+
`BundleExistsError`, `DeviceRpcError`, `RateLimitError`, `ServerError`, `NetworkError`
|
|
65
|
+
|
|
66
|
+
The raw generated transport client is still available under `import { raw } from '@omirion/orbit-sdk'`.
|
|
67
|
+
|
|
68
|
+
## Develop
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pnpm install --ignore-workspace
|
|
72
|
+
pnpm generate # regenerate src/generated/ from ../spec/openapi.json
|
|
73
|
+
pnpm typecheck
|
|
74
|
+
pnpm test # vitest (ergonomics layer)
|
|
75
|
+
pnpm build # tsup → dist/ (ESM + CJS + .d.ts)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`src/generated/` is committed and must never be hand-edited, change the server
|
|
79
|
+
spec and regenerate (`pnpm sdk:gen` from the repo root).
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|