valta-sdk 2.0.1 → 2.1.1

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 ADDED
@@ -0,0 +1,276 @@
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
+ "Authorization": `Bearer ${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
+ });
@@ -0,0 +1,197 @@
1
+ interface RequestOptions {
2
+ method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
3
+ body?: unknown;
4
+ }
5
+ declare class Requester {
6
+ private apiKey;
7
+ private baseUrl;
8
+ constructor(apiKey: string, baseUrl?: string);
9
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
10
+ }
11
+
12
+ interface Agent {
13
+ id: string;
14
+ name: string;
15
+ type: string;
16
+ status: 'active' | 'frozen' | 'paused';
17
+ walletAddress?: string;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ }
21
+ interface CreateAgentParams {
22
+ name: string;
23
+ type: string;
24
+ description?: string;
25
+ }
26
+ interface ListAgentsParams {
27
+ limit?: number;
28
+ offset?: number;
29
+ status?: 'active' | 'frozen' | 'paused';
30
+ }
31
+ interface ListAgentsResponse {
32
+ agents: Agent[];
33
+ total: number;
34
+ limit: number;
35
+ offset: number;
36
+ }
37
+ declare class AgentsResource {
38
+ private requester;
39
+ constructor(requester: Requester);
40
+ list(params?: ListAgentsParams): Promise<ListAgentsResponse>;
41
+ get(agentId: string): Promise<Agent>;
42
+ create(params: CreateAgentParams): Promise<Agent>;
43
+ update(agentId: string, params: Partial<CreateAgentParams>): Promise<Agent>;
44
+ freeze(agentId: string): Promise<Agent>;
45
+ unfreeze(agentId: string): Promise<Agent>;
46
+ delete(agentId: string): Promise<{
47
+ deleted: boolean;
48
+ id: string;
49
+ }>;
50
+ }
51
+
52
+ interface WalletBalance {
53
+ usdc: string;
54
+ usdcPending: string;
55
+ lastUpdated: string;
56
+ }
57
+ interface WalletTransferParams {
58
+ toAgentId?: string;
59
+ toAddress?: string;
60
+ amount: string;
61
+ currency: 'USDC';
62
+ note?: string;
63
+ }
64
+ interface WalletTransfer {
65
+ id: string;
66
+ fromAgentId: string;
67
+ toAgentId?: string;
68
+ toAddress?: string;
69
+ amount: string;
70
+ currency: string;
71
+ status: 'pending' | 'completed' | 'failed';
72
+ createdAt: string;
73
+ }
74
+ declare class WalletsResource {
75
+ private requester;
76
+ constructor(requester: Requester);
77
+ get(agentId: string): Promise<WalletBalance>;
78
+ transfer(agentId: string, params: WalletTransferParams): Promise<WalletTransfer>;
79
+ }
80
+
81
+ interface Policy {
82
+ id: string;
83
+ agentId: string;
84
+ name: string;
85
+ maxSpendPerDay?: number;
86
+ maxSpendPerTransaction?: number;
87
+ allowedRecipients?: string[];
88
+ currency: string;
89
+ active: boolean;
90
+ createdAt: string;
91
+ }
92
+ interface CreatePolicyParams {
93
+ agentId: string;
94
+ name: string;
95
+ maxSpendPerDay?: number;
96
+ maxSpendPerTransaction?: number;
97
+ allowedRecipients?: string[];
98
+ currency?: string;
99
+ }
100
+ declare class PoliciesResource {
101
+ private requester;
102
+ constructor(requester: Requester);
103
+ list(agentId?: string): Promise<Policy[]>;
104
+ create(params: CreatePolicyParams): Promise<Policy>;
105
+ update(policyId: string, params: Partial<CreatePolicyParams>): Promise<Policy>;
106
+ delete(policyId: string): Promise<{
107
+ deleted: boolean;
108
+ }>;
109
+ }
110
+
111
+ interface AuditLog {
112
+ id: string;
113
+ agentId: string;
114
+ action: string;
115
+ amount?: string;
116
+ currency?: string;
117
+ metadata?: Record<string, unknown>;
118
+ hash: string;
119
+ previousHash: string;
120
+ createdAt: string;
121
+ }
122
+ interface ListAuditParams {
123
+ agentId?: string;
124
+ limit?: number;
125
+ offset?: number;
126
+ from?: string;
127
+ to?: string;
128
+ }
129
+ interface ListAuditResponse {
130
+ logs: AuditLog[];
131
+ total: number;
132
+ }
133
+ declare class AuditResource {
134
+ private requester;
135
+ constructor(requester: Requester);
136
+ list(params?: ListAuditParams): Promise<ListAuditResponse>;
137
+ }
138
+
139
+ interface ApiKey {
140
+ id: string;
141
+ name: string;
142
+ prefix: string;
143
+ tier: 'free' | 'builder' | 'startup' | 'enterprise';
144
+ lastUsed?: string;
145
+ createdAt: string;
146
+ }
147
+ interface CreateKeyResponse {
148
+ id: string;
149
+ name: string;
150
+ key: string;
151
+ tier: string;
152
+ createdAt: string;
153
+ }
154
+ declare class KeysResource {
155
+ private requester;
156
+ constructor(requester: Requester);
157
+ list(): Promise<ApiKey[]>;
158
+ create(name: string): Promise<CreateKeyResponse>;
159
+ revoke(keyId: string): Promise<{
160
+ deleted: boolean;
161
+ }>;
162
+ }
163
+
164
+ interface ValtaConfig {
165
+ apiKey: string;
166
+ baseUrl?: string;
167
+ }
168
+ declare class ValtaClient {
169
+ agents: AgentsResource;
170
+ wallets: WalletsResource;
171
+ policies: PoliciesResource;
172
+ audit: AuditResource;
173
+ keys: KeysResource;
174
+ constructor(config: ValtaConfig | string);
175
+ }
176
+
177
+ declare class ValtaError extends Error {
178
+ code: string;
179
+ status: number;
180
+ constructor(message: string, code: string, status: number);
181
+ }
182
+ declare class AuthError extends ValtaError {
183
+ constructor(message?: string);
184
+ }
185
+ declare class TierError extends ValtaError {
186
+ requiredTier: string;
187
+ upgradeUrl: string;
188
+ constructor(message: string, requiredTier: string);
189
+ }
190
+ declare class RateLimitError extends ValtaError {
191
+ constructor(message?: string);
192
+ }
193
+ declare class NotFoundError extends ValtaError {
194
+ constructor(resource: string);
195
+ }
196
+
197
+ export { type Agent, type ApiKey, type AuditLog, AuthError, type CreateAgentParams, type CreateKeyResponse, type CreatePolicyParams, type ListAgentsParams, type ListAuditParams, NotFoundError, type Policy, RateLimitError, TierError, ValtaClient, ValtaError, type WalletBalance, type WalletTransfer, type WalletTransferParams, ValtaClient as default };