valta-sdk 2.1.7 → 2.2.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/index.cjs CHANGED
@@ -1,276 +1,2 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- AuthError: () => AuthError,
24
- NotFoundError: () => NotFoundError,
25
- RateLimitError: () => RateLimitError,
26
- TierError: () => TierError,
27
- ValtaClient: () => ValtaClient,
28
- ValtaError: () => ValtaError,
29
- default: () => ValtaClient
30
- });
31
- module.exports = __toCommonJS(index_exports);
32
-
33
- // src/errors/index.ts
34
- var ValtaError = class extends Error {
35
- constructor(message, code, status) {
36
- super(message);
37
- this.name = "ValtaError";
38
- this.code = code;
39
- this.status = status;
40
- }
41
- };
42
- var AuthError = class extends ValtaError {
43
- constructor(message = "Invalid or missing API key") {
44
- super(message, "UNAUTHORIZED", 401);
45
- this.name = "AuthError";
46
- }
47
- };
48
- var TierError = class extends ValtaError {
49
- constructor(message, requiredTier) {
50
- super(message, "TIER_LIMIT", 403);
51
- this.name = "TierError";
52
- this.requiredTier = requiredTier;
53
- this.upgradeUrl = "https://valta.co/upgrade";
54
- }
55
- };
56
- var RateLimitError = class extends ValtaError {
57
- constructor(message = "Rate limit exceeded. Slow down your requests.") {
58
- super(message, "RATE_LIMIT", 429);
59
- this.name = "RateLimitError";
60
- }
61
- };
62
- var NotFoundError = class extends ValtaError {
63
- constructor(resource) {
64
- super(`${resource} not found`, "NOT_FOUND", 404);
65
- this.name = "NotFoundError";
66
- }
67
- };
68
-
69
- // src/http/requester.ts
70
- var DEFAULT_BASE_URL = "https://valta.co/api/v1";
71
- var Requester = class {
72
- constructor(apiKey, baseUrl) {
73
- if (!apiKey || typeof apiKey !== "string") {
74
- throw new AuthError("An API key is required. Get one at https://valta.co/dashboard/api-keys");
75
- }
76
- this.apiKey = apiKey;
77
- this.baseUrl = baseUrl ?? DEFAULT_BASE_URL;
78
- }
79
- async request(path, options = {}) {
80
- const { method = "GET", body } = options;
81
- const res = await fetch(`${this.baseUrl}${path}`, {
82
- method,
83
- headers: {
84
- "x-api-key": this.apiKey,
85
- "Content-Type": "application/json",
86
- "X-Valta-SDK": "0.2.0"
87
- },
88
- body: body ? JSON.stringify(body) : void 0
89
- });
90
- if (!res.ok) {
91
- let errorData = {};
92
- try {
93
- errorData = await res.json();
94
- } catch {
95
- }
96
- const message = errorData.message ?? "An unknown error occurred";
97
- switch (res.status) {
98
- case 401:
99
- throw new AuthError(message);
100
- case 403:
101
- throw new TierError(message, errorData.requiredTier ?? "builder");
102
- case 404:
103
- throw new NotFoundError(path);
104
- case 429:
105
- throw new RateLimitError(message);
106
- default:
107
- throw new ValtaError(message, "SERVER_ERROR", res.status);
108
- }
109
- }
110
- return res.json();
111
- }
112
- };
113
-
114
- // src/resources/agents.ts
115
- var AgentsResource = class {
116
- constructor(requester) {
117
- this.requester = requester;
118
- }
119
- // Get all agents
120
- async list(params = {}) {
121
- const query = new URLSearchParams();
122
- if (params.limit) query.set("limit", String(params.limit));
123
- if (params.offset) query.set("offset", String(params.offset));
124
- if (params.status) query.set("status", params.status);
125
- const qs = query.toString();
126
- return this.requester.request(
127
- `/agents${qs ? `?${qs}` : ""}`
128
- );
129
- }
130
- // Get one agent by ID
131
- async get(agentId) {
132
- return this.requester.request(`/agents/${agentId}`);
133
- }
134
- // Create a new agent
135
- async create(params) {
136
- return this.requester.request("/agents", {
137
- method: "POST",
138
- body: params
139
- });
140
- }
141
- // Update an agent
142
- async update(agentId, params) {
143
- return this.requester.request(`/agents/${agentId}`, {
144
- method: "PATCH",
145
- body: params
146
- });
147
- }
148
- // Freeze an agent (stops it from spending)
149
- async freeze(agentId) {
150
- return this.requester.request(`/agents/${agentId}/freeze`, {
151
- method: "POST"
152
- });
153
- }
154
- // Unfreeze an agent
155
- async unfreeze(agentId) {
156
- return this.requester.request(`/agents/${agentId}/unfreeze`, {
157
- method: "POST"
158
- });
159
- }
160
- // Delete an agent
161
- async delete(agentId) {
162
- return this.requester.request(
163
- `/agents/${agentId}`,
164
- { method: "DELETE" }
165
- );
166
- }
167
- };
168
-
169
- // src/resources/wallets.ts
170
- var WalletsResource = class {
171
- constructor(requester) {
172
- this.requester = requester;
173
- }
174
- // Get wallet balance for an agent
175
- async get(agentId) {
176
- return this.requester.request(
177
- `/agents/${agentId}/wallet`
178
- );
179
- }
180
- // Transfer funds from one agent wallet to another
181
- async transfer(agentId, params) {
182
- return this.requester.request(
183
- `/agents/${agentId}/wallet/transfer`,
184
- { method: "POST", body: params }
185
- );
186
- }
187
- };
188
-
189
- // src/resources/policies.ts
190
- var PoliciesResource = class {
191
- constructor(requester) {
192
- this.requester = requester;
193
- }
194
- async list(agentId) {
195
- const qs = agentId ? `?agentId=${agentId}` : "";
196
- return this.requester.request(`/policies${qs}`);
197
- }
198
- async create(params) {
199
- return this.requester.request("/policies", {
200
- method: "POST",
201
- body: params
202
- });
203
- }
204
- async update(policyId, params) {
205
- return this.requester.request(`/policies/${policyId}`, {
206
- method: "PATCH",
207
- body: params
208
- });
209
- }
210
- async delete(policyId) {
211
- return this.requester.request(`/policies/${policyId}`, {
212
- method: "DELETE"
213
- });
214
- }
215
- };
216
-
217
- // src/resources/audit.ts
218
- var AuditResource = class {
219
- constructor(requester) {
220
- this.requester = requester;
221
- }
222
- async list(params = {}) {
223
- const query = new URLSearchParams();
224
- if (params.agentId) query.set("agentId", params.agentId);
225
- if (params.limit) query.set("limit", String(params.limit));
226
- if (params.offset) query.set("offset", String(params.offset));
227
- if (params.from) query.set("from", params.from);
228
- if (params.to) query.set("to", params.to);
229
- const qs = query.toString();
230
- return this.requester.request(`/audit${qs ? `?${qs}` : ""}`);
231
- }
232
- };
233
-
234
- // src/resources/keys.ts
235
- var KeysResource = class {
236
- constructor(requester) {
237
- this.requester = requester;
238
- }
239
- async list() {
240
- return this.requester.request("/keys");
241
- }
242
- async create(name) {
243
- return this.requester.request("/keys", {
244
- method: "POST",
245
- body: { name }
246
- });
247
- }
248
- async revoke(keyId) {
249
- return this.requester.request(`/keys/${keyId}`, {
250
- method: "DELETE"
251
- });
252
- }
253
- };
254
-
255
- // src/client.ts
256
- var ValtaClient = class {
257
- constructor(config) {
258
- const apiKey = typeof config === "string" ? config : config.apiKey;
259
- const baseUrl = typeof config === "object" ? config.baseUrl : void 0;
260
- const requester = new Requester(apiKey, baseUrl);
261
- this.agents = new AgentsResource(requester);
262
- this.wallets = new WalletsResource(requester);
263
- this.policies = new PoliciesResource(requester);
264
- this.audit = new AuditResource(requester);
265
- this.keys = new KeysResource(requester);
266
- }
267
- };
268
- // Annotate the CommonJS export names for ESM import in node:
269
- 0 && (module.exports = {
270
- AuthError,
271
- NotFoundError,
272
- RateLimitError,
273
- TierError,
274
- ValtaClient,
275
- ValtaError
276
- });
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var d=class{constructor(t){this.http=t;}async login(t,e){return this.http.post("/auth/login",{email:t,password:e},false)}async logout(){await this.http.post("/auth/logout");}async whoami(){return this.http.get("/auth/whoami")}async refreshToken(){return this.http.post("/auth/refresh-token")}};var m=class{constructor(t){this.http=t;}async create(t){return this.http.post("/agents",t)}async list(t){return this.http.get("/agents",t)}async get(t){return this.http.get(`/agents/${encodeURIComponent(t)}`)}async update(t,e){return this.http.patch(`/agents/${encodeURIComponent(t)}`,e)}async delete(t){return this.http.delete(`/agents/${encodeURIComponent(t)}`)}async freeze(t){return this.http.post(`/agents/${encodeURIComponent(t)}/freeze`)}async unfreeze(t){return this.http.post(`/agents/${encodeURIComponent(t)}/unfreeze`)}async run(t,e){return this.http.post(`/agents/${encodeURIComponent(t)}/run`,e)}async getRun(t,e){return this.http.get(`/agents/${encodeURIComponent(t)}/runs/${encodeURIComponent(e)}`)}async listRuns(t,e){return this.http.get(`/agents/${encodeURIComponent(t)}/runs`,e)}};var g=class{constructor(t){this.http=t;}async list(t){return this.http.get("/audit",t)}async get(t){return this.http.get(`/audit/${encodeURIComponent(t)}`)}async export(t){let e=[],o=1,i=true;for(;i;){let p=await this.list({...t,page:o,limit:100});e.push(...p.data),i=p.pagination.hasMore,o+=1;}return e}async verify(t){return this.http.get(`/audit/verify/${encodeURIComponent(t)}`)}};var h=class{constructor(t){this.http=t;}async create(t){return this.http.post("/keys",t)}async list(){return this.http.get("/keys")}async revoke(t){return this.http.delete(`/keys/${encodeURIComponent(t)}`)}};var n=class extends Error{constructor(t){super(t.message),this.name="ValtaError",this.code=t.code,this.status=t.status??null,this.details=t.details??null;}isRateLimit(){return this.code==="RATE_LIMIT_EXCEEDED"}isAuth(){return this.code==="UNAUTHORISED"||this.code==="FORBIDDEN"}requiresApproval(){return this.code==="APPROVAL_REQUIRED"}},A=class extends n{constructor(t="Invalid or missing API key"){super({message:t,code:"UNAUTHORISED",status:401}),this.name="AuthError";}},P=class extends n{constructor(t,e){super({message:t,code:"TIER_LIMIT_EXCEEDED",status:403,details:{requiredTier:e}}),this.name="TierError",this.requiredTier=e??null,this.upgradeUrl="https://valta.co/upgrade";}},I=class extends n{constructor(t="Rate limit exceeded"){super({message:t,code:"RATE_LIMIT_EXCEEDED",status:429}),this.name="RateLimitError";}},T=class extends n{constructor(t="Resource not found"){super({message:t,code:"NOT_FOUND",status:404}),this.name="NotFoundError";}};var E=class{constructor(t){this.http=t;}async create(t){return this.http.post("/policies",t)}async get(t){try{return await this.http.get(`/policies/${encodeURIComponent(t)}`)}catch(e){if(e instanceof n&&e.code==="NOT_FOUND")return null;throw e}}async update(t,e){return this.http.patch(`/policies/${encodeURIComponent(t)}`,e)}async delete(t){return this.http.delete(`/policies/${encodeURIComponent(t)}`)}async list(){return this.http.get("/policies")}};var y=class{constructor(t){this.http=t;}async get(t){return this.http.get(`/wallets/${encodeURIComponent(t)}`)}async getBalance(t){return (await this.get(t)).balance}async getDepositAddress(t){return this.http.get(`/wallets/${encodeURIComponent(t)}/deposit-address`)}async listTransactions(t,e){return this.http.get(`/wallets/${encodeURIComponent(t)}/transactions`,e)}async transfer(t){return this.http.post("/wallets/transfer",t)}};var f="2.2.0",R=class{constructor(t){this.apiKey=t.apiKey,this.baseUrl=(t.baseUrl??"https://valta.co/api/v1").replace(/\/$/,""),this.timeout=t.timeout??3e4;}async request(t){let e=`${this.baseUrl}${t.path}`;if(t.query){let r=new URLSearchParams;for(let[u,a]of Object.entries(t.query))a!==void 0&&r.set(u,String(a));let l=r.toString();l&&(e+=`?${l}`);}let o=new AbortController,i=setTimeout(()=>o.abort(),this.timeout),p={"Content-Type":"application/json","User-Agent":`valta-sdk/${f}`,"X-Valta-SDK":f};t.authenticated!==false&&(p["x-api-key"]=this.apiKey);try{let r=await fetch(e,{method:t.method,headers:p,body:t.body===void 0?void 0:JSON.stringify(t.body),signal:o.signal});clearTimeout(i);let l=await r.text(),u=l?C(l,r.status):null;if(!r.ok){let a=u??{};throw new n({message:a.message??a.error??`HTTP ${r.status}`,code:U(a.code,r.status),status:r.status,details:a})}return u}catch(r){throw clearTimeout(i),r instanceof n?r:r instanceof Error&&r.name==="AbortError"?new n({message:`Request timed out after ${this.timeout}ms`,code:"TIMEOUT"}):new n({message:r instanceof Error?r.message:"An unknown network error occurred",code:"NETWORK_ERROR"})}}get(t,e){return this.request({method:"GET",path:t,query:e})}post(t,e,o=true){return this.request({method:"POST",path:t,body:e,authenticated:o})}patch(t,e){return this.request({method:"PATCH",path:t,body:e})}delete(t){return this.request({method:"DELETE",path:t})}};function C(s,t){try{return JSON.parse(s)}catch{throw new n({message:"Invalid JSON response from server",code:"SERVER_ERROR",status:t})}}function U(s,t){let e=String(s||"").toUpperCase();if(e==="UNAUTHORIZED"||e==="API_KEY_REQUIRED"||e==="INVALID_API_KEY")return "UNAUTHORISED";if(e==="RATE_LIMIT"||e==="API_KEY_RATE_LIMITED")return "RATE_LIMIT_EXCEEDED";if(e==="TIER_LIMIT")return "TIER_LIMIT_EXCEEDED";if(D(e))return e;switch(t){case 400:return "INVALID_REQUEST";case 401:return "UNAUTHORISED";case 403:return "FORBIDDEN";case 404:return "NOT_FOUND";case 429:return "RATE_LIMIT_EXCEEDED";default:return "SERVER_ERROR"}}function D(s){return ["UNAUTHORISED","FORBIDDEN","NOT_FOUND","RATE_LIMIT_EXCEEDED","TIER_LIMIT_EXCEEDED","AGENT_FROZEN","POLICY_VIOLATION","INSUFFICIENT_BALANCE","APPROVAL_REQUIRED","INVALID_REQUEST","SERVER_ERROR","NETWORK_ERROR","TIMEOUT"].includes(s)}var c=class{constructor(t){let e=typeof t=="string"?{apiKey:t}:t;if(!e.apiKey)throw new Error("Valta API key is required. Get one at https://valta.co/dashboard/api-keys");this.http=new R(e),this.auth=new d(this.http),this.agents=new m(this.http),this.wallets=new y(this.http),this.policies=new E(this.http),this.audit=new g(this.http),this.keys=new h(this.http);}};
2
+ exports.AuthError=A;exports.NotFoundError=T;exports.RateLimitError=I;exports.TierError=P;exports.Valta=c;exports.ValtaClient=c;exports.ValtaError=n;exports.default=c;