valta-sdk 2.1.1 → 2.1.2
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/dist/chunk-LBY67QV7.js +244 -0
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// src/errors/index.ts
|
|
2
|
+
var ValtaError = class extends Error {
|
|
3
|
+
constructor(message, code, status) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "ValtaError";
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.status = status;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var AuthError = class extends ValtaError {
|
|
11
|
+
constructor(message = "Invalid or missing API key") {
|
|
12
|
+
super(message, "UNAUTHORIZED", 401);
|
|
13
|
+
this.name = "AuthError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var TierError = class extends ValtaError {
|
|
17
|
+
constructor(message, requiredTier) {
|
|
18
|
+
super(message, "TIER_LIMIT", 403);
|
|
19
|
+
this.name = "TierError";
|
|
20
|
+
this.requiredTier = requiredTier;
|
|
21
|
+
this.upgradeUrl = "https://valta.co/upgrade";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var RateLimitError = class extends ValtaError {
|
|
25
|
+
constructor(message = "Rate limit exceeded. Slow down your requests.") {
|
|
26
|
+
super(message, "RATE_LIMIT", 429);
|
|
27
|
+
this.name = "RateLimitError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var NotFoundError = class extends ValtaError {
|
|
31
|
+
constructor(resource) {
|
|
32
|
+
super(`${resource} not found`, "NOT_FOUND", 404);
|
|
33
|
+
this.name = "NotFoundError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/http/requester.ts
|
|
38
|
+
var DEFAULT_BASE_URL = "https://valta.co/api/v1";
|
|
39
|
+
var Requester = class {
|
|
40
|
+
constructor(apiKey, baseUrl) {
|
|
41
|
+
if (!apiKey || typeof apiKey !== "string") {
|
|
42
|
+
throw new AuthError("An API key is required. Get one at https://valta.co/dashboard/api-keys");
|
|
43
|
+
}
|
|
44
|
+
this.apiKey = apiKey;
|
|
45
|
+
this.baseUrl = baseUrl ?? DEFAULT_BASE_URL;
|
|
46
|
+
}
|
|
47
|
+
async request(path, options = {}) {
|
|
48
|
+
const { method = "GET", body } = options;
|
|
49
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
50
|
+
method,
|
|
51
|
+
headers: {
|
|
52
|
+
"x-api-key": this.apiKey,
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
"X-Valta-SDK": "0.2.0"
|
|
55
|
+
},
|
|
56
|
+
body: body ? JSON.stringify(body) : void 0
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
let errorData = {};
|
|
60
|
+
try {
|
|
61
|
+
errorData = await res.json();
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
const message = errorData.message ?? "An unknown error occurred";
|
|
65
|
+
switch (res.status) {
|
|
66
|
+
case 401:
|
|
67
|
+
throw new AuthError(message);
|
|
68
|
+
case 403:
|
|
69
|
+
throw new TierError(message, errorData.requiredTier ?? "builder");
|
|
70
|
+
case 404:
|
|
71
|
+
throw new NotFoundError(path);
|
|
72
|
+
case 429:
|
|
73
|
+
throw new RateLimitError(message);
|
|
74
|
+
default:
|
|
75
|
+
throw new ValtaError(message, "SERVER_ERROR", res.status);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return res.json();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/resources/agents.ts
|
|
83
|
+
var AgentsResource = class {
|
|
84
|
+
constructor(requester) {
|
|
85
|
+
this.requester = requester;
|
|
86
|
+
}
|
|
87
|
+
// Get all agents
|
|
88
|
+
async list(params = {}) {
|
|
89
|
+
const query = new URLSearchParams();
|
|
90
|
+
if (params.limit) query.set("limit", String(params.limit));
|
|
91
|
+
if (params.offset) query.set("offset", String(params.offset));
|
|
92
|
+
if (params.status) query.set("status", params.status);
|
|
93
|
+
const qs = query.toString();
|
|
94
|
+
return this.requester.request(
|
|
95
|
+
`/agents${qs ? `?${qs}` : ""}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
// Get one agent by ID
|
|
99
|
+
async get(agentId) {
|
|
100
|
+
return this.requester.request(`/agents/${agentId}`);
|
|
101
|
+
}
|
|
102
|
+
// Create a new agent
|
|
103
|
+
async create(params) {
|
|
104
|
+
return this.requester.request("/agents", {
|
|
105
|
+
method: "POST",
|
|
106
|
+
body: params
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// Update an agent
|
|
110
|
+
async update(agentId, params) {
|
|
111
|
+
return this.requester.request(`/agents/${agentId}`, {
|
|
112
|
+
method: "PATCH",
|
|
113
|
+
body: params
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// Freeze an agent (stops it from spending)
|
|
117
|
+
async freeze(agentId) {
|
|
118
|
+
return this.requester.request(`/agents/${agentId}/freeze`, {
|
|
119
|
+
method: "POST"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// Unfreeze an agent
|
|
123
|
+
async unfreeze(agentId) {
|
|
124
|
+
return this.requester.request(`/agents/${agentId}/unfreeze`, {
|
|
125
|
+
method: "POST"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Delete an agent
|
|
129
|
+
async delete(agentId) {
|
|
130
|
+
return this.requester.request(
|
|
131
|
+
`/agents/${agentId}`,
|
|
132
|
+
{ method: "DELETE" }
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/resources/wallets.ts
|
|
138
|
+
var WalletsResource = class {
|
|
139
|
+
constructor(requester) {
|
|
140
|
+
this.requester = requester;
|
|
141
|
+
}
|
|
142
|
+
// Get wallet balance for an agent
|
|
143
|
+
async get(agentId) {
|
|
144
|
+
return this.requester.request(
|
|
145
|
+
`/agents/${agentId}/wallet`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
// Transfer funds from one agent wallet to another
|
|
149
|
+
async transfer(agentId, params) {
|
|
150
|
+
return this.requester.request(
|
|
151
|
+
`/agents/${agentId}/wallet/transfer`,
|
|
152
|
+
{ method: "POST", body: params }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/resources/policies.ts
|
|
158
|
+
var PoliciesResource = class {
|
|
159
|
+
constructor(requester) {
|
|
160
|
+
this.requester = requester;
|
|
161
|
+
}
|
|
162
|
+
async list(agentId) {
|
|
163
|
+
const qs = agentId ? `?agentId=${agentId}` : "";
|
|
164
|
+
return this.requester.request(`/policies${qs}`);
|
|
165
|
+
}
|
|
166
|
+
async create(params) {
|
|
167
|
+
return this.requester.request("/policies", {
|
|
168
|
+
method: "POST",
|
|
169
|
+
body: params
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async update(policyId, params) {
|
|
173
|
+
return this.requester.request(`/policies/${policyId}`, {
|
|
174
|
+
method: "PATCH",
|
|
175
|
+
body: params
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async delete(policyId) {
|
|
179
|
+
return this.requester.request(`/policies/${policyId}`, {
|
|
180
|
+
method: "DELETE"
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/resources/audit.ts
|
|
186
|
+
var AuditResource = class {
|
|
187
|
+
constructor(requester) {
|
|
188
|
+
this.requester = requester;
|
|
189
|
+
}
|
|
190
|
+
async list(params = {}) {
|
|
191
|
+
const query = new URLSearchParams();
|
|
192
|
+
if (params.agentId) query.set("agentId", params.agentId);
|
|
193
|
+
if (params.limit) query.set("limit", String(params.limit));
|
|
194
|
+
if (params.offset) query.set("offset", String(params.offset));
|
|
195
|
+
if (params.from) query.set("from", params.from);
|
|
196
|
+
if (params.to) query.set("to", params.to);
|
|
197
|
+
const qs = query.toString();
|
|
198
|
+
return this.requester.request(`/audit${qs ? `?${qs}` : ""}`);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/resources/keys.ts
|
|
203
|
+
var KeysResource = class {
|
|
204
|
+
constructor(requester) {
|
|
205
|
+
this.requester = requester;
|
|
206
|
+
}
|
|
207
|
+
async list() {
|
|
208
|
+
return this.requester.request("/keys");
|
|
209
|
+
}
|
|
210
|
+
async create(name) {
|
|
211
|
+
return this.requester.request("/keys", {
|
|
212
|
+
method: "POST",
|
|
213
|
+
body: { name }
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async revoke(keyId) {
|
|
217
|
+
return this.requester.request(`/keys/${keyId}`, {
|
|
218
|
+
method: "DELETE"
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// src/client.ts
|
|
224
|
+
var ValtaClient = class {
|
|
225
|
+
constructor(config) {
|
|
226
|
+
const apiKey = typeof config === "string" ? config : config.apiKey;
|
|
227
|
+
const baseUrl = typeof config === "object" ? config.baseUrl : void 0;
|
|
228
|
+
const requester = new Requester(apiKey, baseUrl);
|
|
229
|
+
this.agents = new AgentsResource(requester);
|
|
230
|
+
this.wallets = new WalletsResource(requester);
|
|
231
|
+
this.policies = new PoliciesResource(requester);
|
|
232
|
+
this.audit = new AuditResource(requester);
|
|
233
|
+
this.keys = new KeysResource(requester);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
ValtaError,
|
|
239
|
+
AuthError,
|
|
240
|
+
TierError,
|
|
241
|
+
RateLimitError,
|
|
242
|
+
NotFoundError,
|
|
243
|
+
ValtaClient
|
|
244
|
+
};
|
package/dist/cli/index.cjs
CHANGED
|
@@ -101,7 +101,7 @@ var Requester = class {
|
|
|
101
101
|
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
102
102
|
method,
|
|
103
103
|
headers: {
|
|
104
|
-
"
|
|
104
|
+
"x-api-key": this.apiKey,
|
|
105
105
|
"Content-Type": "application/json",
|
|
106
106
|
"X-Valta-SDK": "0.2.0"
|
|
107
107
|
},
|
package/dist/cli/index.js
CHANGED
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valta-sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Official SDK for Valta — AI agent financial infrastructure",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
+
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"import": "./dist/index.mjs",
|