@warmhub/sdk-ts 0.44.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/README.md +111 -0
- package/dist/chunk-PKA25PT7.js +4775 -0
- package/dist/chunk-PKA25PT7.js.map +1 -0
- package/dist/index.d.ts +3316 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +27 -0
- package/dist/react.js +75 -0
- package/dist/react.js.map +1 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @warmhub/sdk-ts
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for WarmHub.
|
|
4
|
+
|
|
5
|
+
📖 **Full docs:** [docs.warmhub.ai/sdk/overview/](https://docs.warmhub.ai/sdk/overview/) · **API reference:** [docs.warmhub.ai/sdk-reference/readme/](https://docs.warmhub.ai/sdk-reference/readme/)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @warmhub/sdk-ts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Get a Token
|
|
14
|
+
|
|
15
|
+
The `WH_TOKEN` used below is a personal access token. Mint one with the [WarmHub CLI](https://docs.warmhub.ai/get-started/quickstart/#connect-via-cli):
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
wh auth login
|
|
19
|
+
wh token create --name my-app
|
|
20
|
+
export WH_TOKEN=eyJhbGciOi...
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
See [Personal Access Tokens](https://docs.warmhub.ai/auth/personal-access-tokens/) for scopes, rotation, and CI usage.
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { WarmHubClient } from '@warmhub/sdk-ts'
|
|
29
|
+
|
|
30
|
+
const client = new WarmHubClient({
|
|
31
|
+
auth: { getToken: async () => process.env.WH_TOKEN },
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// One-time setup. Skip these three calls (or catch CONFLICT) on re-runs.
|
|
35
|
+
await client.org.create('acme')
|
|
36
|
+
await client.repo.create('acme', 'world', 'Game world')
|
|
37
|
+
await client.shape.create('acme', 'world', 'Location', {
|
|
38
|
+
x: 'number',
|
|
39
|
+
y: 'number',
|
|
40
|
+
label: 'string',
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
await client.commit.apply('acme', 'world', 'seed cave', [
|
|
44
|
+
{
|
|
45
|
+
operation: 'add',
|
|
46
|
+
kind: 'thing',
|
|
47
|
+
name: 'Location/cave',
|
|
48
|
+
data: { x: 0, y: 0, label: 'Dark Cave' },
|
|
49
|
+
},
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
const head = await client.thing.head('acme', 'world', { shape: 'Location' })
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For the connect-and-read flow without setup, see the [Quickstart](https://docs.warmhub.ai/get-started/quickstart/#connect-via-sdk). For reference on shapes, things, and writes, see [Data Modeling](https://docs.warmhub.ai/data-modeling/wrefs/).
|
|
56
|
+
|
|
57
|
+
## Function Logs
|
|
58
|
+
|
|
59
|
+
Backend function `console.*` lines are suppressed by default. SDK consumers can
|
|
60
|
+
opt into log replay for debugging:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const client = new WarmHubClient({
|
|
64
|
+
auth: { getToken: async () => process.env.WH_TOKEN },
|
|
65
|
+
functionLogs: 'raw',
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Entrypoints
|
|
70
|
+
|
|
71
|
+
- `@warmhub/sdk-ts`: core client, types, errors, `OperationBuilder`
|
|
72
|
+
|
|
73
|
+
## Error Handling
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { isRetryable, isWarmHubError } from '@warmhub/sdk-ts'
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
await client.repo.get('acme', 'world')
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (isWarmHubError(err) && err.kind === 'NOT_FOUND') {
|
|
82
|
+
// handle missing repo
|
|
83
|
+
}
|
|
84
|
+
if (isRetryable(err)) {
|
|
85
|
+
// retry strategy
|
|
86
|
+
}
|
|
87
|
+
throw err
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## OperationBuilder
|
|
92
|
+
|
|
93
|
+
`OperationBuilder` is single-use: after a successful `commit()`, the builder
|
|
94
|
+
is sealed and cannot be modified or reused.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { OperationBuilder } from '@warmhub/sdk-ts'
|
|
98
|
+
|
|
99
|
+
const ob = new OperationBuilder()
|
|
100
|
+
ob.add({ name: 'Location/cave', data: { x: 0, y: 0 } })
|
|
101
|
+
const result = await ob.commit({
|
|
102
|
+
client,
|
|
103
|
+
orgName: 'acme',
|
|
104
|
+
repoName: 'world',
|
|
105
|
+
message: 'seed cave',
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## API Docs
|
|
110
|
+
|
|
111
|
+
Generated API reference is published at [docs.warmhub.ai/sdk-reference/readme/](https://docs.warmhub.ai/sdk-reference/readme/) — the landing page lists every public class, interface, type alias, variable, and function exported from the main `@warmhub/sdk-ts` entrypoint.
|