@buildaureon/sdk 0.1.8 → 0.1.9
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/CHANGELOG.md +71 -0
- package/README.md +673 -658
- package/config/network.json +6 -6
- package/dist/index.d.ts +31 -26
- package/dist/index.js +30 -20
- package/dist/index.js.map +1 -1
- package/docs/architecture.md +210 -208
- package/docs/auth.md +176 -176
- package/docs/client-api.md +788 -788
- package/docs/data-contracts.md +3 -3
- package/docs/error-model.md +217 -217
- package/docs/integration-guide.md +400 -400
- package/docs/receipt-validation.md +66 -66
- package/docs/security.md +120 -120
- package/docs/transport.md +143 -143
- package/examples/ai-to-objective-to-portfolio/main.ts +1 -1
- package/examples/drift-detect-restore/main.ts +1 -1
- package/examples/e2e-policy-rebalance/main.ts +431 -431
- package/examples/e2e-policy-rebalance/underrun.ts +143 -143
- package/examples/e2e-policy-rebalance/verify-sizing.ts +155 -155
- package/examples/e2e-vault-flow/main.ts +221 -221
- package/examples/full-aureon-loop/main.ts +1 -1
- package/examples/green-vs-plan/main.ts +1 -1
- package/examples/market-event/main.ts +1 -1
- package/examples/portfolio-watch/main.ts +1 -1
- package/examples/quickstart/main.ts +75 -75
- package/examples/receipt-verification/main.ts +1 -1
- package/examples/sdk-demo-terminal/main.ts +2 -2
- package/package.json +2 -1
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
# Receipt validation
|
|
2
|
-
|
|
3
|
-
Phase 2 receipts must follow honest settlement rules. Use the SDK validator after every restore or when ingesting receipts from logs.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Quick example
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
import {
|
|
11
|
-
createAureonClient,
|
|
12
|
-
resolveAureonNetworkFromEnv,
|
|
13
|
-
validateExecutionReceipt,
|
|
14
|
-
assertValidExecutionReceipt,
|
|
15
|
-
} from "@buildaureon/sdk";
|
|
16
|
-
|
|
17
|
-
const resolved = resolveAureonNetworkFromEnv();
|
|
18
|
-
const client = createAureonClient({
|
|
19
|
-
network: resolved.network,
|
|
20
|
-
baseUrl: resolved.baseUrl,
|
|
21
|
-
apiKey: process.env.AUREON_API_KEY!,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const receipt = await client.restoreObjective("obj_abc123");
|
|
25
|
-
|
|
26
|
-
const check = validateExecutionReceipt(receipt);
|
|
27
|
-
if (!check.valid) {
|
|
28
|
-
for (const issue of check.issues) {
|
|
29
|
-
console.error(issue.code, issue.path, issue.message);
|
|
30
|
-
}
|
|
31
|
-
throw new Error("Receipt failed validation");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Or throw in one step:
|
|
35
|
-
assertValidExecutionReceipt(receipt);
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
List recent receipts and validate each:
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
for (const receipt of await client.listExecutions()) {
|
|
42
|
-
assertValidExecutionReceipt(receipt);
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## What gets checked
|
|
49
|
-
|
|
50
|
-
| Rule | Fail code (examples) |
|
|
51
|
-
|------|----------------------|
|
|
52
|
-
| Required fields present | `MISSING_FIELD` |
|
|
53
|
-
| `settlement` is `vault` or `staged` | `INVALID_SETTLEMENT` |
|
|
54
|
-
| Staged: no explorer, not verified | `STAGED_WITH_EXPLORER`, `STAGED_VERIFIED_ON_CHAIN` |
|
|
55
|
-
| Vault with real `0x` tx: explorer required | `VAULT_MISSING_EXPLORER` |
|
|
56
|
-
| `verifiedOnChain: true` needs matching record | `VERIFIED_WITHOUT_RECORD` |
|
|
57
|
-
| Registry ref hex shape | `INVALID_REGISTRY_REF` |
|
|
58
|
-
|
|
59
|
-
The validator does **not** re-query the chain — it checks shape and honesty only.
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
## Related
|
|
64
|
-
|
|
65
|
-
- [Data contracts](./data-contracts.md) — receipt and settlement fields
|
|
66
|
-
- [Integration guide](./integration-guide.md) — agent restore loop
|
|
1
|
+
# Receipt validation
|
|
2
|
+
|
|
3
|
+
Phase 2 receipts must follow honest settlement rules. Use the SDK validator after every restore or when ingesting receipts from logs.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Quick example
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import {
|
|
11
|
+
createAureonClient,
|
|
12
|
+
resolveAureonNetworkFromEnv,
|
|
13
|
+
validateExecutionReceipt,
|
|
14
|
+
assertValidExecutionReceipt,
|
|
15
|
+
} from "@buildaureon/sdk";
|
|
16
|
+
|
|
17
|
+
const resolved = resolveAureonNetworkFromEnv();
|
|
18
|
+
const client = createAureonClient({
|
|
19
|
+
network: resolved.network,
|
|
20
|
+
baseUrl: resolved.baseUrl,
|
|
21
|
+
apiKey: process.env.AUREON_API_KEY!,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const receipt = await client.restoreObjective("obj_abc123");
|
|
25
|
+
|
|
26
|
+
const check = validateExecutionReceipt(receipt);
|
|
27
|
+
if (!check.valid) {
|
|
28
|
+
for (const issue of check.issues) {
|
|
29
|
+
console.error(issue.code, issue.path, issue.message);
|
|
30
|
+
}
|
|
31
|
+
throw new Error("Receipt failed validation");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Or throw in one step:
|
|
35
|
+
assertValidExecutionReceipt(receipt);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
List recent receipts and validate each:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
for (const receipt of await client.listExecutions()) {
|
|
42
|
+
assertValidExecutionReceipt(receipt);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## What gets checked
|
|
49
|
+
|
|
50
|
+
| Rule | Fail code (examples) |
|
|
51
|
+
|------|----------------------|
|
|
52
|
+
| Required fields present | `MISSING_FIELD` |
|
|
53
|
+
| `settlement` is `vault` or `staged` | `INVALID_SETTLEMENT` |
|
|
54
|
+
| Staged: no explorer, not verified | `STAGED_WITH_EXPLORER`, `STAGED_VERIFIED_ON_CHAIN` |
|
|
55
|
+
| Vault with real `0x` tx: explorer required | `VAULT_MISSING_EXPLORER` |
|
|
56
|
+
| `verifiedOnChain: true` needs matching record | `VERIFIED_WITHOUT_RECORD` |
|
|
57
|
+
| Registry ref hex shape | `INVALID_REGISTRY_REF` |
|
|
58
|
+
|
|
59
|
+
The validator does **not** re-query the chain — it checks shape and honesty only.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Related
|
|
64
|
+
|
|
65
|
+
- [Data contracts](./data-contracts.md) — receipt and settlement fields
|
|
66
|
+
- [Integration guide](./integration-guide.md) — agent restore loop
|
package/docs/security.md
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
# Security Model and Practices
|
|
2
|
-
|
|
3
|
-
Security architecture for `@buildaureon/sdk`: trust boundaries, credentials, vault signing, and production checklist.
|
|
4
|
-
|
|
5
|
-
**Automation note:** SDK agents should run **Automatic** objectives only. Manual Approve flows are utility concerns, not SDK security surface.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 1. Gateway trust boundaries
|
|
10
|
-
|
|
11
|
-
AUREON is non-custodial. The API is a policy engine, price indexer, and coordinator. It does not hold private keys and does not broadcast owner withdrawals for you.
|
|
12
|
-
|
|
13
|
-
```mermaid
|
|
14
|
-
flowchart TD
|
|
15
|
-
Host[Host_application] -->|1_request_calldata| Gateway[Aureon_API]
|
|
16
|
-
Gateway -->|2_unsigned_steps| Host
|
|
17
|
-
Host -->|3_sign_locally| Wallet[Private_key_or_KMS]
|
|
18
|
-
Wallet -->|4_broadcast| Chain[Robinhood_Chain_RPC]
|
|
19
|
-
|
|
20
|
-
subgraph OnChain [Smart_contract_controls]
|
|
21
|
-
Vault[Smart_Vault]
|
|
22
|
-
DX[Allowlisted_DEX_routes]
|
|
23
|
-
Vault -->|keeper_swaps_only| DX
|
|
24
|
-
end
|
|
25
|
-
Wallet -.->|owner_deposit_withdraw| Vault
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### 1.1 Private key isolation
|
|
29
|
-
|
|
30
|
-
The SDK never loads, stores, or transmits private keys or mnemonics. Signing stays in the host (viem, ethers, HSM, KMS). A gateway breach cannot drain vaults by itself.
|
|
31
|
-
|
|
32
|
-
### 1.2 Issued API keys are wallet credentials
|
|
33
|
-
|
|
34
|
-
An **issued** developer key identifies the bound wallet for control-plane operations (sync, objectives, health, restore, prepare). Treat it like a password:
|
|
35
|
-
|
|
36
|
-
- Create in utility **Developers**
|
|
37
|
-
- Store in env / secret manager
|
|
38
|
-
- Pause or revoke on leak
|
|
39
|
-
- Prefer one key per agent host
|
|
40
|
-
|
|
41
|
-
Env bootstrap keys on the server unlock product access only. They do **not** identify a wallet and must not be used as agent identity.
|
|
42
|
-
|
|
43
|
-
### 1.3 Unsigned calldata
|
|
44
|
-
|
|
45
|
-
`prepareVaultDeposit` / `prepareVaultWithdraw` return structured steps. Decode against published ABIs before signing. Broadcast is always host-side.
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
## 2. What a compromised API key can and cannot do
|
|
50
|
-
|
|
51
|
-
| Can | Cannot |
|
|
52
|
-
| --- | --- |
|
|
53
|
-
| Read portfolio, vault, health, timeline | Sign owner deposit/withdraw txs |
|
|
54
|
-
| Create / update / pause Auto objectives | Withdraw vault funds to arbitrary addresses |
|
|
55
|
-
| Request restore plans and trigger Automatic restore coordination | Bypass vault keeper allowlists |
|
|
56
|
-
| Create additional developer keys under the same wallet | Recover a private key |
|
|
57
|
-
|
|
58
|
-
Keeper-driven Automatic restores execute allowlisted vault swaps. Keepers cannot send vault assets to arbitrary third parties.
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## 3. Smart vault access control
|
|
63
|
-
|
|
64
|
-
- **Owner path:** deposits and withdrawals require owner-signed txs from prepare steps.
|
|
65
|
-
- **Keeper path:** Automatic restores use registered keepers on allowlisted routes only.
|
|
66
|
-
- **Slippage / limits:** vault and planner enforce execution bounds to reduce bad fills.
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## 4. Settlement honesty
|
|
71
|
-
|
|
72
|
-
Every execution receipt includes `settlement`:
|
|
73
|
-
|
|
74
|
-
| Value | Meaning | UI rule |
|
|
75
|
-
| --- | --- | --- |
|
|
76
|
-
| `vault` | On-chain vault / keeper settlement with verifiable hash | May show as on-chain |
|
|
77
|
-
| `staged` | Ledger-local / rehearsal — not a chain settlement | Must **not** be labeled as on-chain |
|
|
78
|
-
|
|
79
|
-
Never collapse staged into “confirmed on Robinhood Chain.”
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
## 5. Transport and logging hygiene
|
|
84
|
-
|
|
85
|
-
- Default omitted client is
|
|
86
|
-
- Do not log raw `Authorization` or `X-Aureon-Api-Key`.
|
|
87
|
-
- Redact prepare step calldata in public logs if it includes sensitive amounts in your threat model.
|
|
88
|
-
- Set `timeoutMs` / `maxRetries` deliberately for agent loops (see [transport.md](./transport.md)).
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## 6. Frontend vs agent hosts
|
|
93
|
-
|
|
94
|
-
| Host | Guidance |
|
|
95
|
-
| --- | --- |
|
|
96
|
-
| Server agent / cron | Issued API key in secret store; private key in KMS if broadcasting deposits |
|
|
97
|
-
| Browser SPA | Do **not** embed issued API keys in public bundles; proxy through your backend |
|
|
98
|
-
| Operator utility | Wallet Bearer only — separate from SDK agent auth |
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## 7. Production checklist
|
|
103
|
-
|
|
104
|
-
- [ ] Issued developer key (not a shared env bootstrap key) in secrets
|
|
105
|
-
- [ ] Private keys isolated from the API key and never logged
|
|
106
|
-
- [ ] Deposit/withdraw broadcast path reviewed and ABI-checked
|
|
107
|
-
- [ ] Automatic objectives only in SDK loops
|
|
108
|
-
- [ ] UI / agent summaries honor `settlement: vault | staged`
|
|
109
|
-
- [ ] Gas reserve on the signing wallet for owner txs
|
|
110
|
-
- [ ] Key rotation plan (pause/revoke in Developers)
|
|
111
|
-
- [ ] Error handling branches on `error.code` (see [error-model.md](./error-model.md))
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## 8. Related docs
|
|
116
|
-
|
|
117
|
-
- [Auth](./auth.md)
|
|
118
|
-
- [Architecture](./architecture.md)
|
|
119
|
-
- [Integration guide](./integration-guide.md)
|
|
120
|
-
- [Error model](./error-model.md)
|
|
1
|
+
# Security Model and Practices
|
|
2
|
+
|
|
3
|
+
Security architecture for `@buildaureon/sdk`: trust boundaries, credentials, vault signing, and production checklist.
|
|
4
|
+
|
|
5
|
+
**Automation note:** SDK agents should run **Automatic** objectives only. Manual Approve flows are utility concerns, not SDK security surface.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Gateway trust boundaries
|
|
10
|
+
|
|
11
|
+
AUREON is non-custodial. The API is a policy engine, price indexer, and coordinator. It does not hold private keys and does not broadcast owner withdrawals for you.
|
|
12
|
+
|
|
13
|
+
```mermaid
|
|
14
|
+
flowchart TD
|
|
15
|
+
Host[Host_application] -->|1_request_calldata| Gateway[Aureon_API]
|
|
16
|
+
Gateway -->|2_unsigned_steps| Host
|
|
17
|
+
Host -->|3_sign_locally| Wallet[Private_key_or_KMS]
|
|
18
|
+
Wallet -->|4_broadcast| Chain[Robinhood_Chain_RPC]
|
|
19
|
+
|
|
20
|
+
subgraph OnChain [Smart_contract_controls]
|
|
21
|
+
Vault[Smart_Vault]
|
|
22
|
+
DX[Allowlisted_DEX_routes]
|
|
23
|
+
Vault -->|keeper_swaps_only| DX
|
|
24
|
+
end
|
|
25
|
+
Wallet -.->|owner_deposit_withdraw| Vault
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 1.1 Private key isolation
|
|
29
|
+
|
|
30
|
+
The SDK never loads, stores, or transmits private keys or mnemonics. Signing stays in the host (viem, ethers, HSM, KMS). A gateway breach cannot drain vaults by itself.
|
|
31
|
+
|
|
32
|
+
### 1.2 Issued API keys are wallet credentials
|
|
33
|
+
|
|
34
|
+
An **issued** developer key identifies the bound wallet for control-plane operations (sync, objectives, health, restore, prepare). Treat it like a password:
|
|
35
|
+
|
|
36
|
+
- Create in utility **Developers**
|
|
37
|
+
- Store in env / secret manager
|
|
38
|
+
- Pause or revoke on leak
|
|
39
|
+
- Prefer one key per agent host
|
|
40
|
+
|
|
41
|
+
Env bootstrap keys on the server unlock product access only. They do **not** identify a wallet and must not be used as agent identity.
|
|
42
|
+
|
|
43
|
+
### 1.3 Unsigned calldata
|
|
44
|
+
|
|
45
|
+
`prepareVaultDeposit` / `prepareVaultWithdraw` return structured steps. Decode against published ABIs before signing. Broadcast is always host-side.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 2. What a compromised API key can and cannot do
|
|
50
|
+
|
|
51
|
+
| Can | Cannot |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| Read portfolio, vault, health, timeline | Sign owner deposit/withdraw txs |
|
|
54
|
+
| Create / update / pause Auto objectives | Withdraw vault funds to arbitrary addresses |
|
|
55
|
+
| Request restore plans and trigger Automatic restore coordination | Bypass vault keeper allowlists |
|
|
56
|
+
| Create additional developer keys under the same wallet | Recover a private key |
|
|
57
|
+
|
|
58
|
+
Keeper-driven Automatic restores execute allowlisted vault swaps. Keepers cannot send vault assets to arbitrary third parties.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 3. Smart vault access control
|
|
63
|
+
|
|
64
|
+
- **Owner path:** deposits and withdrawals require owner-signed txs from prepare steps.
|
|
65
|
+
- **Keeper path:** Automatic restores use registered keepers on allowlisted routes only.
|
|
66
|
+
- **Slippage / limits:** vault and planner enforce execution bounds to reduce bad fills.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 4. Settlement honesty
|
|
71
|
+
|
|
72
|
+
Every execution receipt includes `settlement`:
|
|
73
|
+
|
|
74
|
+
| Value | Meaning | UI rule |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `vault` | On-chain vault / keeper settlement with verifiable hash | May show as on-chain |
|
|
77
|
+
| `staged` | Ledger-local / rehearsal — not a chain settlement | Must **not** be labeled as on-chain |
|
|
78
|
+
|
|
79
|
+
Never collapse staged into “confirmed on Robinhood Chain.”
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 5. Transport and logging hygiene
|
|
84
|
+
|
|
85
|
+
- Default omitted client is the official API `https://api.aureonlabs.network` (currently testnet 46630). Use `network: "mainnet"` for chain 4663 on the same host. Do not call that host production until it is cut over.
|
|
86
|
+
- Do not log raw `Authorization` or `X-Aureon-Api-Key`.
|
|
87
|
+
- Redact prepare step calldata in public logs if it includes sensitive amounts in your threat model.
|
|
88
|
+
- Set `timeoutMs` / `maxRetries` deliberately for agent loops (see [transport.md](./transport.md)).
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## 6. Frontend vs agent hosts
|
|
93
|
+
|
|
94
|
+
| Host | Guidance |
|
|
95
|
+
| --- | --- |
|
|
96
|
+
| Server agent / cron | Issued API key in secret store; private key in KMS if broadcasting deposits |
|
|
97
|
+
| Browser SPA | Do **not** embed issued API keys in public bundles; proxy through your backend |
|
|
98
|
+
| Operator utility | Wallet Bearer only — separate from SDK agent auth |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 7. Production checklist
|
|
103
|
+
|
|
104
|
+
- [ ] Issued developer key (not a shared env bootstrap key) in secrets
|
|
105
|
+
- [ ] Private keys isolated from the API key and never logged
|
|
106
|
+
- [ ] Deposit/withdraw broadcast path reviewed and ABI-checked
|
|
107
|
+
- [ ] Automatic objectives only in SDK loops
|
|
108
|
+
- [ ] UI / agent summaries honor `settlement: vault | staged`
|
|
109
|
+
- [ ] Gas reserve on the signing wallet for owner txs
|
|
110
|
+
- [ ] Key rotation plan (pause/revoke in Developers)
|
|
111
|
+
- [ ] Error handling branches on `error.code` (see [error-model.md](./error-model.md))
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 8. Related docs
|
|
116
|
+
|
|
117
|
+
- [Auth](./auth.md)
|
|
118
|
+
- [Architecture](./architecture.md)
|
|
119
|
+
- [Integration guide](./integration-guide.md)
|
|
120
|
+
- [Error model](./error-model.md)
|
package/docs/transport.md
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
# Transport Layer Reference
|
|
2
|
-
|
|
3
|
-
HTTP transport for `@buildaureon/sdk` (`src/transport/http.ts`): headers, timeouts, retries, URL helpers, and logging.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 1. Request lifecycle
|
|
8
|
-
|
|
9
|
-
```mermaid
|
|
10
|
-
flowchart TD
|
|
11
|
-
Call[Client_method] --> Prep[Join_URL_and_headers]
|
|
12
|
-
Prep --> Auth[Resolve_API_key_and_Bearer]
|
|
13
|
-
Auth --> Abort[AbortController_timeout]
|
|
14
|
-
Abort --> Fetch[fetch_implementation]
|
|
15
|
-
Fetch --> Ok{HTTP_OK?}
|
|
16
|
-
Ok -->|Yes| Parse[Parse_JSON]
|
|
17
|
-
Ok -->|No| Map[Map_to_AureonError]
|
|
18
|
-
Map --> Retry{Retryable_and_budget?}
|
|
19
|
-
Retry -->|Yes| Sleep[retryDelayMs]
|
|
20
|
-
Sleep --> Fetch
|
|
21
|
-
Retry -->|No| Throw[Throw]
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
1. Join `baseUrl` + path; attach query string when needed.
|
|
25
|
-
2. Resolve `X-Aureon-Api-Key` from `apiKey` / `getApiKey`.
|
|
26
|
-
3. Resolve `Authorization: Bearer …` from `getAccessToken` / `authToken` (optional).
|
|
27
|
-
4. Apply timeout via `AbortController` (default 30s).
|
|
28
|
-
5. On failure, map status → typed error; retry only if configured and retryable.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## 2. Headers
|
|
33
|
-
|
|
34
|
-
| Header | When | Purpose |
|
|
35
|
-
| --- | --- | --- |
|
|
36
|
-
| `Accept` | Always | `application/json` |
|
|
37
|
-
| `Content-Type` | Body present | `application/json` |
|
|
38
|
-
| `X-Aureon-SDK` | Always | Package identity / version |
|
|
39
|
-
| `X-Aureon-Api-Key` | Key configured | Product access + issued-key identity |
|
|
40
|
-
| `Authorization` | Token configured | Optional Bearer session |
|
|
41
|
-
| Custom `headers` | If set on client | Merged into every request |
|
|
42
|
-
|
|
43
|
-
Issued developer keys in `X-Aureon-Api-Key` are enough for control-plane identity on the live API. Bearer is optional and wins when both are present.
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## 3. Client transport options
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
createAureonClient({
|
|
51
|
-
// omit network →
|
|
52
|
-
// network: "
|
|
53
|
-
apiKey: process.env.AUREON_API_KEY!,
|
|
54
|
-
timeoutMs: 30_000, // per attempt
|
|
55
|
-
maxRetries: 2, // extra attempts after first failure
|
|
56
|
-
retryDelayMs: 500, // fixed delay between attempts
|
|
57
|
-
fetch: customFetch, // optional
|
|
58
|
-
headers: { "X-Debug": "1" },
|
|
59
|
-
logger: myLogger,
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
| Option | Default | Notes |
|
|
64
|
-
| --- | --- | --- |
|
|
65
|
-
| `timeoutMs` | `30000` | Must be positive finite |
|
|
66
|
-
| `maxRetries` | `0` | Extra tries after the first failure |
|
|
67
|
-
| `retryDelayMs` | `250` | Fixed sleep between tries |
|
|
68
|
-
| `fetch` | `globalThis.fetch` | Inject for tests / unusual runtimes |
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## 4. Retry policy
|
|
73
|
-
|
|
74
|
-
**Retryable:** network failures, timeouts, HTTP 429, HTTP 5xx (when mapped as retryable).
|
|
75
|
-
|
|
76
|
-
**Not retryable:** 400 validation, 401/403 auth, 404, most 409 conflicts (operator must change state).
|
|
77
|
-
|
|
78
|
-
Total attempts = `1 + maxRetries`.
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## 5. URL helpers
|
|
83
|
-
|
|
84
|
-
### `joinUrl`
|
|
85
|
-
|
|
86
|
-
Prevents double slashes when combining base + path.
|
|
87
|
-
|
|
88
|
-
### `withQuery`
|
|
89
|
-
|
|
90
|
-
Serializes defined query params with `encodeURIComponent`. Omits `null` / `undefined`.
|
|
91
|
-
|
|
92
|
-
---
|
|
93
|
-
|
|
94
|
-
## 6. Timeouts and aborts
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
const controller = new AbortController();
|
|
98
|
-
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
99
|
-
try {
|
|
100
|
-
return await fetchImpl(url, { ...init, signal: controller.signal });
|
|
101
|
-
} catch (error) {
|
|
102
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
103
|
-
throw /* AureonTimeoutError */;
|
|
104
|
-
}
|
|
105
|
-
throw /* AureonNetworkError */;
|
|
106
|
-
} finally {
|
|
107
|
-
clearTimeout(timeoutId);
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
For agent loops that call restore + sync, prefer slightly higher `timeoutMs` under load rather than disabling timeouts.
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## 7. Logger interface
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
interface AureonLogger {
|
|
119
|
-
debug(message: string, context?: Record<string, unknown>): void;
|
|
120
|
-
info(message: string, context?: Record<string, unknown>): void;
|
|
121
|
-
warn(message: string, context?: Record<string, unknown>): void;
|
|
122
|
-
error(message: string, context?: Record<string, unknown>): void;
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Helpers may include console / silent adapters depending on package exports. Never log secrets from context.
|
|
127
|
-
|
|
128
|
-
---
|
|
129
|
-
|
|
130
|
-
## 8. Testing transport
|
|
131
|
-
|
|
132
|
-
- Inject a
|
|
133
|
-
- Assert header presence of `X-Aureon-Api-Key` for SDK clients.
|
|
134
|
-
- Assert retries by counting fetch invocations with `maxRetries > 0` and 503 responses.
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
## 9. Related docs
|
|
139
|
-
|
|
140
|
-
- [Error model](./error-model.md)
|
|
141
|
-
- [Auth](./auth.md)
|
|
142
|
-
- [Client API](./client-api.md)
|
|
143
|
-
- [Security](./security.md)
|
|
1
|
+
# Transport Layer Reference
|
|
2
|
+
|
|
3
|
+
HTTP transport for `@buildaureon/sdk` (`src/transport/http.ts`): headers, timeouts, retries, URL helpers, and logging.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Request lifecycle
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
flowchart TD
|
|
11
|
+
Call[Client_method] --> Prep[Join_URL_and_headers]
|
|
12
|
+
Prep --> Auth[Resolve_API_key_and_Bearer]
|
|
13
|
+
Auth --> Abort[AbortController_timeout]
|
|
14
|
+
Abort --> Fetch[fetch_implementation]
|
|
15
|
+
Fetch --> Ok{HTTP_OK?}
|
|
16
|
+
Ok -->|Yes| Parse[Parse_JSON]
|
|
17
|
+
Ok -->|No| Map[Map_to_AureonError]
|
|
18
|
+
Map --> Retry{Retryable_and_budget?}
|
|
19
|
+
Retry -->|Yes| Sleep[retryDelayMs]
|
|
20
|
+
Sleep --> Fetch
|
|
21
|
+
Retry -->|No| Throw[Throw]
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
1. Join `baseUrl` + path; attach query string when needed.
|
|
25
|
+
2. Resolve `X-Aureon-Api-Key` from `apiKey` / `getApiKey`.
|
|
26
|
+
3. Resolve `Authorization: Bearer …` from `getAccessToken` / `authToken` (optional).
|
|
27
|
+
4. Apply timeout via `AbortController` (default 30s).
|
|
28
|
+
5. On failure, map status → typed error; retry only if configured and retryable.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 2. Headers
|
|
33
|
+
|
|
34
|
+
| Header | When | Purpose |
|
|
35
|
+
| --- | --- | --- |
|
|
36
|
+
| `Accept` | Always | `application/json` |
|
|
37
|
+
| `Content-Type` | Body present | `application/json` |
|
|
38
|
+
| `X-Aureon-SDK` | Always | Package identity / version |
|
|
39
|
+
| `X-Aureon-Api-Key` | Key configured | Product access + issued-key identity |
|
|
40
|
+
| `Authorization` | Token configured | Optional Bearer session |
|
|
41
|
+
| Custom `headers` | If set on client | Merged into every request |
|
|
42
|
+
|
|
43
|
+
Issued developer keys in `X-Aureon-Api-Key` are enough for control-plane identity on the live API. Bearer is optional and wins when both are present.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 3. Client transport options
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
createAureonClient({
|
|
51
|
+
// omit network → official API / testnet 46630
|
|
52
|
+
// network: "mainnet" → chain 4663 on the same official host
|
|
53
|
+
apiKey: process.env.AUREON_API_KEY!,
|
|
54
|
+
timeoutMs: 30_000, // per attempt
|
|
55
|
+
maxRetries: 2, // extra attempts after first failure
|
|
56
|
+
retryDelayMs: 500, // fixed delay between attempts
|
|
57
|
+
fetch: customFetch, // optional
|
|
58
|
+
headers: { "X-Debug": "1" },
|
|
59
|
+
logger: myLogger,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
| Option | Default | Notes |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| `timeoutMs` | `30000` | Must be positive finite |
|
|
66
|
+
| `maxRetries` | `0` | Extra tries after the first failure |
|
|
67
|
+
| `retryDelayMs` | `250` | Fixed sleep between tries |
|
|
68
|
+
| `fetch` | `globalThis.fetch` | Inject for tests / unusual runtimes |
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 4. Retry policy
|
|
73
|
+
|
|
74
|
+
**Retryable:** network failures, timeouts, HTTP 429, HTTP 5xx (when mapped as retryable).
|
|
75
|
+
|
|
76
|
+
**Not retryable:** 400 validation, 401/403 auth, 404, most 409 conflicts (operator must change state).
|
|
77
|
+
|
|
78
|
+
Total attempts = `1 + maxRetries`.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 5. URL helpers
|
|
83
|
+
|
|
84
|
+
### `joinUrl`
|
|
85
|
+
|
|
86
|
+
Prevents double slashes when combining base + path.
|
|
87
|
+
|
|
88
|
+
### `withQuery`
|
|
89
|
+
|
|
90
|
+
Serializes defined query params with `encodeURIComponent`. Omits `null` / `undefined`.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 6. Timeouts and aborts
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const controller = new AbortController();
|
|
98
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
99
|
+
try {
|
|
100
|
+
return await fetchImpl(url, { ...init, signal: controller.signal });
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
103
|
+
throw /* AureonTimeoutError */;
|
|
104
|
+
}
|
|
105
|
+
throw /* AureonNetworkError */;
|
|
106
|
+
} finally {
|
|
107
|
+
clearTimeout(timeoutId);
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
For agent loops that call restore + sync, prefer slightly higher `timeoutMs` under load rather than disabling timeouts.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 7. Logger interface
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
interface AureonLogger {
|
|
119
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
120
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
121
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
122
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Helpers may include console / silent adapters depending on package exports. Never log secrets from context.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 8. Testing transport
|
|
131
|
+
|
|
132
|
+
- Inject a test `fetch` that returns a controlled status and body.
|
|
133
|
+
- Assert header presence of `X-Aureon-Api-Key` for SDK clients.
|
|
134
|
+
- Assert retries by counting fetch invocations with `maxRetries > 0` and 503 responses.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 9. Related docs
|
|
139
|
+
|
|
140
|
+
- [Error model](./error-model.md)
|
|
141
|
+
- [Auth](./auth.md)
|
|
142
|
+
- [Client API](./client-api.md)
|
|
143
|
+
- [Security](./security.md)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Env:
|
|
5
5
|
* AUREON_API_KEY issued developer key (required)
|
|
6
|
-
* AUREON_NETWORK optional; omit for
|
|
6
|
+
* AUREON_NETWORK optional; omit for official API / testnet 46630; set mainnet for chain 4663
|
|
7
7
|
* AUREON_API_URL optional override (must match network if both set)
|
|
8
8
|
*
|
|
9
9
|
* pnpm example:ai-to-objective-to-portfolio
|