@avallon-labs/sdk 0.0.0-40188bf9
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 +135 -0
- package/dist/index.d.ts +1617 -0
- package/dist/index.js +636 -0
- package/dist/index.js.map +1 -0
- package/openapi.yaml +1259 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# @avallon/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Avallon API. Auto-generated from OpenAPI with custom auth utilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @avallon/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For React/SWR hooks:
|
|
12
|
+
```bash
|
|
13
|
+
npm install @avallon/sdk swr react
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Configure
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { configure } from "@avallon/sdk";
|
|
22
|
+
|
|
23
|
+
configure({
|
|
24
|
+
baseUrl: "https://api.avallon.ai",
|
|
25
|
+
apiKey: "your-api-key",
|
|
26
|
+
// OR for user auth:
|
|
27
|
+
getAccessToken: () => localStorage.getItem("access_token"),
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### API Calls (Plain Fetch)
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { listAgents, createAgent } from "@avallon/sdk";
|
|
35
|
+
|
|
36
|
+
// List agents
|
|
37
|
+
const response = await listAgents();
|
|
38
|
+
console.log(response.data.data.agents);
|
|
39
|
+
|
|
40
|
+
// Create agent
|
|
41
|
+
const created = await createAgent({ agent_name: "My Agent" });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### API Calls (React SWR Hooks)
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { useListAgents, useCreateAgent } from "@avallon/sdk";
|
|
48
|
+
|
|
49
|
+
function AgentsList() {
|
|
50
|
+
const { data, error, isLoading } = useListAgents();
|
|
51
|
+
|
|
52
|
+
if (isLoading) return <Spinner />;
|
|
53
|
+
if (error) return <Error message={error.message} />;
|
|
54
|
+
|
|
55
|
+
return <ul>{data.data.data.agents.map(a => <li key={a.id}>{a.agent_name}</li>)}</ul>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function CreateAgent() {
|
|
59
|
+
const { trigger, isMutating } = useCreateAgent();
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<button onClick={() => trigger({ agent_name: "New Agent" })} disabled={isMutating}>
|
|
63
|
+
Create
|
|
64
|
+
</button>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### OAuth Flow
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { startOAuthFlow, getStoredVerifier, clearStoredVerifier, postV1AuthSignIn } from "@avallon/sdk";
|
|
73
|
+
|
|
74
|
+
// 1. Start OAuth (redirects user)
|
|
75
|
+
const { url } = await startOAuthFlow({
|
|
76
|
+
provider: "google",
|
|
77
|
+
redirectUri: "https://app.example.com/callback",
|
|
78
|
+
});
|
|
79
|
+
window.location.href = url;
|
|
80
|
+
|
|
81
|
+
// 2. After redirect, exchange code for tokens
|
|
82
|
+
const verifier = getStoredVerifier();
|
|
83
|
+
const response = await postV1AuthSignIn({
|
|
84
|
+
type: "oauth",
|
|
85
|
+
code: new URLSearchParams(location.search).get("code"),
|
|
86
|
+
verifier,
|
|
87
|
+
});
|
|
88
|
+
clearStoredVerifier();
|
|
89
|
+
|
|
90
|
+
// 3. Store tokens and configure SDK
|
|
91
|
+
const { access_token, refresh_token, expires_at } = response.data.data;
|
|
92
|
+
localStorage.setItem("access_token", access_token);
|
|
93
|
+
configure({ getAccessToken: () => localStorage.getItem("access_token") });
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Error Handling
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { AvallonError } from "@avallon/sdk";
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
await createAgent({ agent_name: "" });
|
|
103
|
+
} catch (e) {
|
|
104
|
+
if (e instanceof AvallonError) {
|
|
105
|
+
if (e.isValidationError()) {
|
|
106
|
+
console.log("Validation errors:", e.errors);
|
|
107
|
+
} else if (e.isUnauthorized()) {
|
|
108
|
+
// Redirect to login
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Development
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Regenerate SDK from OpenAPI (from repo root)
|
|
118
|
+
npm run sdk:gen
|
|
119
|
+
|
|
120
|
+
# Build
|
|
121
|
+
npm run build
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Structure
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
src/ # Handwritten code
|
|
128
|
+
index.ts # Main exports
|
|
129
|
+
fetcher.ts # Fetch wrapper with auth
|
|
130
|
+
auth.ts # OAuth PKCE utilities
|
|
131
|
+
|
|
132
|
+
generated/ # Auto-generated (do not edit)
|
|
133
|
+
endpoints/ # API functions + SWR hooks
|
|
134
|
+
models/ # Request/response types
|
|
135
|
+
```
|