@infrapilot-jur/sdk 0.0.0-stage → 0.2.6
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/README.md +122 -2
- package/dist/index.cjs +787 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2773 -0
- package/dist/index.d.ts +2773 -0
- package/dist/index.js +774 -0
- package/dist/index.js.map +1 -0
- package/docs/operation-coverage.md +48 -0
- package/package.json +52 -4
package/README.md
CHANGED
|
@@ -1,3 +1,123 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@infrapilot-jur/sdk`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for the InfraPilot **domains** node API (`0.2.5`).
|
|
4
|
+
|
|
5
|
+
Lives in the monorepo at `sdks/typescript/`. Types are generated from
|
|
6
|
+
`services/domains/docs/openapi.yaml`.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @infrapilot-jur/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Node.js
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { AuthErrorCodes, InfraPilot, InfraPilotHttpError } from "@infrapilot-jur/sdk";
|
|
18
|
+
|
|
19
|
+
const infra = new InfraPilot({
|
|
20
|
+
baseUrl: "http://127.0.0.1:8787",
|
|
21
|
+
apiKey: process.env.INFRAPILOT_API_KEY!,
|
|
22
|
+
timeoutMs: 10_000,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const health = await infra.system.getHealthz();
|
|
26
|
+
const node = await infra.node.get();
|
|
27
|
+
await infra.node.update({ name: "production-01" });
|
|
28
|
+
await infra.node.capabilities();
|
|
29
|
+
const domains = await infra.domains.list();
|
|
30
|
+
const me = await infra.auth.me();
|
|
31
|
+
|
|
32
|
+
const { client } = await infra.clients.create({
|
|
33
|
+
name: "Acme",
|
|
34
|
+
description: "integrations",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const created = await infra.apiKeys.create({
|
|
38
|
+
client_id: client.id,
|
|
39
|
+
name: "ci-readonly",
|
|
40
|
+
scopes: ["domains:read", "domains:health"],
|
|
41
|
+
expires_in_seconds: 2592000,
|
|
42
|
+
});
|
|
43
|
+
// Persist `created.key` once; the SDK never stores credentials.
|
|
44
|
+
|
|
45
|
+
await infra.domains.update("app.example.com", {
|
|
46
|
+
http_only: false, // boolean false is preserved
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
await infra.domains.get("missing.example.com");
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (err instanceof InfraPilotHttpError) {
|
|
53
|
+
console.error(err.status, err.code, err.retryAfter, err.body);
|
|
54
|
+
if (err.code === AuthErrorCodes.RATE_LIMIT_EXCEEDED) {
|
|
55
|
+
// Caller decides whether to wait; no automatic retry.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Browser (required for the operator panel)
|
|
62
|
+
|
|
63
|
+
Do **not** store API keys in `localStorage`. Use web sessions:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { InfraPilot } from "@infrapilot-jur/sdk";
|
|
67
|
+
|
|
68
|
+
let csrfToken: string | undefined; // memory only
|
|
69
|
+
|
|
70
|
+
const infra = new InfraPilot({
|
|
71
|
+
baseUrl: window.location.origin, // same-origin proxy to infrad
|
|
72
|
+
authMode: "session",
|
|
73
|
+
credentials: "same-origin",
|
|
74
|
+
getCsrfToken: () => csrfToken,
|
|
75
|
+
timeoutMs: 10_000,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Login form collects the admin API key once (in memory), then discards it.
|
|
79
|
+
const session = await infra.auth.login({ api_key: apiKeyFromForm });
|
|
80
|
+
csrfToken = session.csrf_token;
|
|
81
|
+
|
|
82
|
+
await infra.auth.me();
|
|
83
|
+
await infra.domains.list();
|
|
84
|
+
await infra.auth.logout(); // clears HttpOnly cookie; also clear csrfToken
|
|
85
|
+
csrfToken = undefined;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Bearer mode remains for automation/CLI. Panel UX must use `authMode: "session"`.
|
|
89
|
+
|
|
90
|
+
## Resources
|
|
91
|
+
|
|
92
|
+
- `infra.system` — health, docs, openapi
|
|
93
|
+
- `infra.domains` — CRUD, preview, probes, per-domain backups (`domains.backups.*`)
|
|
94
|
+
- `infra.caddy` — systemd status, storage status (`caddy.storage`), journal logs
|
|
95
|
+
- `infra.backups` — list/restore (dual-read legacy + modular)
|
|
96
|
+
- `infra.operations` — audit pagination
|
|
97
|
+
- `infra.auth` — `GET /api/v1/auth/me`
|
|
98
|
+
- `infra.clients` — admin client management
|
|
99
|
+
- `infra.apiKeys` — admin API key create/list/update/revoke/rotate
|
|
100
|
+
- `infra.node` — local node identity + capabilities (singular daemon; `infra.nodes` reserved for Control Plane)
|
|
101
|
+
|
|
102
|
+
## Behavior
|
|
103
|
+
|
|
104
|
+
- No automatic retries (including mutable operations)
|
|
105
|
+
- No automatic credential renewal or persistence
|
|
106
|
+
- Redirects default to `error` (not followed)
|
|
107
|
+
- Credentials are never logged by the SDK
|
|
108
|
+
- HTTP errors expose optional `code` and `retryAfter` (from `429` + `Retry-After`)
|
|
109
|
+
- Partial PATCH supported (`DomainUpdateInput`, client/key updates)
|
|
110
|
+
- Discriminated preview (`create` | `update` | `delete`)
|
|
111
|
+
- Compatible with prior v0.2.x operationIds; v0.2.4 adds storage + domain backup ops (38 total)
|
|
112
|
+
|
|
113
|
+
## Develop
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pnpm install
|
|
117
|
+
pnpm generate
|
|
118
|
+
pnpm typecheck
|
|
119
|
+
pnpm lint
|
|
120
|
+
pnpm test
|
|
121
|
+
pnpm build
|
|
122
|
+
pnpm check:openapi-sync
|
|
123
|
+
```
|