@buildaureon/sdk 0.1.1 → 0.1.7

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.
@@ -1,217 +1,217 @@
1
- # Error Model and Diagnostics
2
-
3
- Error classification, payloads, recovery patterns, and live failure modes for `@buildaureon/sdk`.
4
-
5
- **Automation note:** Examples assume **Automatic** objectives. Manual Approve error paths are out of scope for SDK agents.
6
-
7
- ---
8
-
9
- ## 1. Exception hierarchy
10
-
11
- All SDK failures that represent API/client faults extend `AureonError`.
12
-
13
- ```mermaid
14
- graph TD
15
- Native[Error] --> Base[AureonError]
16
- Base --> Val[AureonValidationError_400]
17
- Base --> NotFound[AureonNotFoundError_404]
18
- Base --> Conflict[AureonConflictError_409]
19
- Base --> Net[AureonNetworkError]
20
- Base --> Timeout[AureonTimeoutError]
21
- ```
22
-
23
- ### Properties
24
-
25
- | Field | Meaning |
26
- | --- | --- |
27
- | `code` | Stable string for branching (`UNAUTHORIZED`, `VALIDATION_ERROR`, …) |
28
- | `status` | HTTP status, or `null` for pure network failures |
29
- | `details` | Optional structured metadata from the API |
30
- | `retryable` | Whether an immediate retry is reasonable |
31
- | `message` | Human-readable summary |
32
-
33
- ```ts
34
- import { isAureonError } from "@buildaureon/sdk";
35
-
36
- try {
37
- await aureon.restoreObjective(id);
38
- } catch (err) {
39
- if (isAureonError(err)) {
40
- console.error(err.code, err.status, err.details);
41
- }
42
- throw err;
43
- }
44
- ```
45
-
46
- ---
47
-
48
- ## 2. Common API payloads
49
-
50
- ### Validation (400)
51
-
52
- ```json
53
- {
54
- "code": "VALIDATION_ERROR",
55
- "message": "Create objective parameters failed validation",
56
- "details": {
57
- "targetWeight": "must be between 0 and 1",
58
- "tolerance": "must be between 0 and 0.5"
59
- }
60
- }
61
- ```
62
-
63
- Also covers locked-field updates (e.g. attempting to change `targetSymbol` / `automationMode` after create).
64
-
65
- ### Unauthorized (401)
66
-
67
- ```json
68
- {
69
- "message": "Invalid API key",
70
- "details": null
71
- }
72
- ```
73
-
74
- Or, when an env bootstrap key is used without wallet identity:
75
-
76
- ```json
77
- {
78
- "message": "Wallet session required (env API keys cannot identify a wallet; use an issued developer key or Bearer)",
79
- "details": null
80
- }
81
- ```
82
-
83
- ### Not found (404)
84
-
85
- Missing objective / key id / resource.
86
-
87
- ### Conflict (409)
88
-
89
- ```json
90
- {
91
- "code": "CONFLICT",
92
- "message": "Cannot modify objective while restore is in flight",
93
- "details": {
94
- "objectiveId": "obj_...",
95
- "status": "pending_confirmation"
96
- }
97
- }
98
- ```
99
-
100
- Also appears when restore is rejected because capital / plan / vault state conflicts with the request.
101
-
102
- ### Rate limit (429)
103
-
104
- ```json
105
- {
106
- "code": "RATE_LIMITED",
107
- "message": "Too many requests",
108
- "details": { "retryAfterSeconds": 15 }
109
- }
110
- ```
111
-
112
- ### Server (5xx)
113
-
114
- Retryable when `maxRetries` > 0. Alert ops if persistent.
115
-
116
- ---
117
-
118
- ## 3. Operational recovery map
119
-
120
- ```mermaid
121
- flowchart TD
122
- Catch[Catch_AureonError] --> Code{error.code_or_status}
123
-
124
- Code -->|UNAUTHORIZED| Auth[Rotate_issued_key_or_refresh_Bearer]
125
- Code -->|VALIDATION_ERROR| ValFix[Fix_inputs_recreate_if_locked_fields]
126
- Code -->|NOT_FOUND| Missing[Refresh_lists_check_ids]
127
- Code -->|CONFLICT| Wait[Backoff_recheck_health_and_plan]
128
- Code -->|RATE_LIMITED| Sleep[Sleep_retryAfter_or_retryDelayMs]
129
- Code -->|TIMEOUT_NETWORK| Retry[Increase_timeoutMs_enable_maxRetries]
130
- Code -->|5xx| Alert[Alert_ops_retry_bounded]
131
- ```
132
-
133
- | Situation | Agent action |
134
- | --- | --- |
135
- | Invalid / paused key | Stop loop; operator rotates Developers key |
136
- | Bootstrap key alone | Switch to issued key |
137
- | Vault empty on restore | Prepare deposit → broadcast → sync → retry |
138
- | Locked field on update | Recreate objective |
139
- | Conflict mid-restore | Back off; read timeline / executions |
140
- | Staged settlement returned | Do not treat as on-chain success |
141
-
142
- ---
143
-
144
- ## 4. Logging hooks
145
-
146
- ```ts
147
- import { createAureonClient } from "@buildaureon/sdk";
148
-
149
- const aureon = createAureonClient({
150
- apiKey: process.env.AUREON_API_KEY!,
151
- logger: {
152
- debug: (msg, ctx) => console.debug(msg, ctx),
153
- info: (msg, ctx) => console.info(msg, ctx),
154
- warn: (msg, ctx) => console.warn(msg, ctx),
155
- error: (msg, ctx) => {
156
- // forward to your APM — never include secrets from ctx
157
- console.error(msg, ctx);
158
- },
159
- },
160
- });
161
- ```
162
-
163
- ---
164
-
165
- ## 5. Client-side validation vs server errors
166
-
167
- The SDK normalizes create/update inputs before HTTP (weights, locked fields, automation defaults). Failures can therefore happen:
168
-
169
- 1. **Preflight** in the SDK (no network), or
170
- 2. **Gateway** after HTTP (allowlists, vault state, conflicts).
171
-
172
- Always catch with `isAureonError` and inspect `code` + `details`.
173
-
174
- ---
175
-
176
- ## 6. Unit test sketch
177
-
178
- ```ts
179
- import assert from "node:assert/strict";
180
- import test from "node:test";
181
- import {
182
- createAureonClient,
183
- isAureonError,
184
- AureonValidationError,
185
- } from "@buildaureon/sdk";
186
-
187
- test("empty objective name fails validation", async () => {
188
- const client = createAureonClient({
189
- baseUrl: "https://api.aureonlabs.network",
190
- apiKey: "test",
191
- });
192
-
193
- await assert.rejects(
194
- () =>
195
- client.createObjective({
196
- name: " ",
197
- kind: "balanced_portfolio",
198
- targetWeight: 0.2,
199
- tolerance: 0.02,
200
- targetSymbol: "WETH",
201
- }),
202
- (err: unknown) =>
203
- isAureonError(err) &&
204
- err instanceof AureonValidationError &&
205
- err.code === "VALIDATION_ERROR"
206
- );
207
- });
208
- ```
209
-
210
- ---
211
-
212
- ## 7. Related docs
213
-
214
- - [Transport](./transport.md)
215
- - [Auth](./auth.md)
216
- - [Integration guide](./integration-guide.md)
217
- - [Client API](./client-api.md)
1
+ # Error Model and Diagnostics
2
+
3
+ Error classification, payloads, recovery patterns, and live failure modes for `@buildaureon/sdk`.
4
+
5
+ **Automation note:** Examples assume **Automatic** objectives. Manual Approve error paths are out of scope for SDK agents.
6
+
7
+ ---
8
+
9
+ ## 1. Exception hierarchy
10
+
11
+ All SDK failures that represent API/client faults extend `AureonError`.
12
+
13
+ ```mermaid
14
+ graph TD
15
+ Native[Error] --> Base[AureonError]
16
+ Base --> Val[AureonValidationError_400]
17
+ Base --> NotFound[AureonNotFoundError_404]
18
+ Base --> Conflict[AureonConflictError_409]
19
+ Base --> Net[AureonNetworkError]
20
+ Base --> Timeout[AureonTimeoutError]
21
+ ```
22
+
23
+ ### Properties
24
+
25
+ | Field | Meaning |
26
+ | --- | --- |
27
+ | `code` | Stable string for branching (`UNAUTHORIZED`, `VALIDATION_ERROR`, …) |
28
+ | `status` | HTTP status, or `null` for pure network failures |
29
+ | `details` | Optional structured metadata from the API |
30
+ | `retryable` | Whether an immediate retry is reasonable |
31
+ | `message` | Human-readable summary |
32
+
33
+ ```ts
34
+ import { isAureonError } from "@buildaureon/sdk";
35
+
36
+ try {
37
+ await aureon.restoreObjective(id);
38
+ } catch (err) {
39
+ if (isAureonError(err)) {
40
+ console.error(err.code, err.status, err.details);
41
+ }
42
+ throw err;
43
+ }
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 2. Common API payloads
49
+
50
+ ### Validation (400)
51
+
52
+ ```json
53
+ {
54
+ "code": "VALIDATION_ERROR",
55
+ "message": "Create objective parameters failed validation",
56
+ "details": {
57
+ "targetWeight": "must be between 0 and 1",
58
+ "tolerance": "must be between 0 and 0.5"
59
+ }
60
+ }
61
+ ```
62
+
63
+ Also covers locked-field updates (e.g. attempting to change `targetSymbol` / `automationMode` after create).
64
+
65
+ ### Unauthorized (401)
66
+
67
+ ```json
68
+ {
69
+ "message": "Invalid API key",
70
+ "details": null
71
+ }
72
+ ```
73
+
74
+ Or, when an env bootstrap key is used without wallet identity:
75
+
76
+ ```json
77
+ {
78
+ "message": "Wallet session required (env API keys cannot identify a wallet; use an issued developer key or Bearer)",
79
+ "details": null
80
+ }
81
+ ```
82
+
83
+ ### Not found (404)
84
+
85
+ Missing objective / key id / resource.
86
+
87
+ ### Conflict (409)
88
+
89
+ ```json
90
+ {
91
+ "code": "CONFLICT",
92
+ "message": "Cannot modify objective while restore is in flight",
93
+ "details": {
94
+ "objectiveId": "obj_...",
95
+ "status": "pending_confirmation"
96
+ }
97
+ }
98
+ ```
99
+
100
+ Also appears when restore is rejected because capital / plan / vault state conflicts with the request.
101
+
102
+ ### Rate limit (429)
103
+
104
+ ```json
105
+ {
106
+ "code": "RATE_LIMITED",
107
+ "message": "Too many requests",
108
+ "details": { "retryAfterSeconds": 15 }
109
+ }
110
+ ```
111
+
112
+ ### Server (5xx)
113
+
114
+ Retryable when `maxRetries` > 0. Alert ops if persistent.
115
+
116
+ ---
117
+
118
+ ## 3. Operational recovery map
119
+
120
+ ```mermaid
121
+ flowchart TD
122
+ Catch[Catch_AureonError] --> Code{error.code_or_status}
123
+
124
+ Code -->|UNAUTHORIZED| Auth[Rotate_issued_key_or_refresh_Bearer]
125
+ Code -->|VALIDATION_ERROR| ValFix[Fix_inputs_recreate_if_locked_fields]
126
+ Code -->|NOT_FOUND| Missing[Refresh_lists_check_ids]
127
+ Code -->|CONFLICT| Wait[Backoff_recheck_health_and_plan]
128
+ Code -->|RATE_LIMITED| Sleep[Sleep_retryAfter_or_retryDelayMs]
129
+ Code -->|TIMEOUT_NETWORK| Retry[Increase_timeoutMs_enable_maxRetries]
130
+ Code -->|5xx| Alert[Alert_ops_retry_bounded]
131
+ ```
132
+
133
+ | Situation | Agent action |
134
+ | --- | --- |
135
+ | Invalid / paused key | Stop loop; operator rotates Developers key |
136
+ | Bootstrap key alone | Switch to issued key |
137
+ | Vault empty on restore | Prepare deposit → broadcast → sync → retry |
138
+ | Locked field on update | Recreate objective |
139
+ | Conflict mid-restore | Back off; read timeline / executions |
140
+ | Staged settlement returned | Do not treat as on-chain success |
141
+
142
+ ---
143
+
144
+ ## 4. Logging hooks
145
+
146
+ ```ts
147
+ import { createAureonClient } from "@buildaureon/sdk";
148
+
149
+ const aureon = createAureonClient({
150
+ apiKey: process.env.AUREON_API_KEY!,
151
+ logger: {
152
+ debug: (msg, ctx) => console.debug(msg, ctx),
153
+ info: (msg, ctx) => console.info(msg, ctx),
154
+ warn: (msg, ctx) => console.warn(msg, ctx),
155
+ error: (msg, ctx) => {
156
+ // forward to your APM — never include secrets from ctx
157
+ console.error(msg, ctx);
158
+ },
159
+ },
160
+ });
161
+ ```
162
+
163
+ ---
164
+
165
+ ## 5. Client-side validation vs server errors
166
+
167
+ The SDK normalizes create/update inputs before HTTP (weights, locked fields, automation defaults). Failures can therefore happen:
168
+
169
+ 1. **Preflight** in the SDK (no network), or
170
+ 2. **Gateway** after HTTP (allowlists, vault state, conflicts).
171
+
172
+ Always catch with `isAureonError` and inspect `code` + `details`.
173
+
174
+ ---
175
+
176
+ ## 6. Unit test sketch
177
+
178
+ ```ts
179
+ import assert from "node:assert/strict";
180
+ import test from "node:test";
181
+ import {
182
+ createAureonClient,
183
+ isAureonError,
184
+ AureonValidationError,
185
+ } from "@buildaureon/sdk";
186
+
187
+ test("empty objective name fails validation", async () => {
188
+ const client = createAureonClient({
189
+ baseUrl: "https://api.aureonlabs.network",
190
+ apiKey: "test",
191
+ });
192
+
193
+ await assert.rejects(
194
+ () =>
195
+ client.createObjective({
196
+ name: " ",
197
+ kind: "balanced_portfolio",
198
+ targetWeight: 0.2,
199
+ tolerance: 0.02,
200
+ targetSymbol: "WETH",
201
+ }),
202
+ (err: unknown) =>
203
+ isAureonError(err) &&
204
+ err instanceof AureonValidationError &&
205
+ err.code === "VALIDATION_ERROR"
206
+ );
207
+ });
208
+ ```
209
+
210
+ ---
211
+
212
+ ## 7. Related docs
213
+
214
+ - [Transport](./transport.md)
215
+ - [Auth](./auth.md)
216
+ - [Integration guide](./integration-guide.md)
217
+ - [Client API](./client-api.md)