@bloqzapi/api-ts 1.0.0

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.
@@ -0,0 +1,23 @@
1
+ export type BloqzClientOptions = {
2
+ baseUrl?: string;
3
+ apiKey?: string;
4
+ timeoutMs?: number;
5
+ maxRetries?: number;
6
+ retryDelayMs?: number;
7
+ };
8
+ export declare class BloqzClient {
9
+ private baseUrl;
10
+ private apiKey?;
11
+ private timeoutMs;
12
+ private maxRetries;
13
+ private retryDelayMs;
14
+ constructor(options?: BloqzClientOptions);
15
+ private request;
16
+ private isRetryableError;
17
+ private sleep;
18
+ parseIntent<T = unknown>(payload: unknown): Promise<T>;
19
+ buildPlan<T = unknown>(payload: unknown): Promise<T>;
20
+ simulatePlan<T = unknown>(payload: unknown): Promise<T>;
21
+ validatePlan<T = unknown>(payload: unknown): Promise<T>;
22
+ verifyPlan<T = unknown>(payload: unknown): Promise<T>;
23
+ }
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
1
+ export class BloqzClient {
2
+ baseUrl;
3
+ apiKey;
4
+ timeoutMs;
5
+ maxRetries;
6
+ retryDelayMs;
7
+ constructor(options = {}) {
8
+ this.baseUrl = options.baseUrl || 'http://localhost:4000';
9
+ this.apiKey = options.apiKey;
10
+ this.timeoutMs = options.timeoutMs || 30000;
11
+ this.maxRetries = options.maxRetries || 2;
12
+ this.retryDelayMs = options.retryDelayMs || 300;
13
+ }
14
+ async request(path, payload) {
15
+ const headers = { 'Content-Type': 'application/json' };
16
+ if (this.apiKey) {
17
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
18
+ }
19
+ let attempt = 0;
20
+ while (true) {
21
+ attempt += 1;
22
+ const controller = new AbortController();
23
+ const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
24
+ try {
25
+ const response = await fetch(`${this.baseUrl}${path}`, {
26
+ method: 'POST',
27
+ headers,
28
+ body: JSON.stringify(payload),
29
+ signal: controller.signal
30
+ });
31
+ if (!response.ok) {
32
+ const errorBody = await response.json().catch(() => ({}));
33
+ const message = errorBody.error || `Request failed (${response.status})`;
34
+ if (attempt <= this.maxRetries && response.status >= 500) {
35
+ await this.sleep(this.retryDelayMs * attempt);
36
+ continue;
37
+ }
38
+ const error = new Error(message);
39
+ error.details = errorBody.details;
40
+ throw error;
41
+ }
42
+ return response.json();
43
+ }
44
+ catch (error) {
45
+ if (attempt <= this.maxRetries && this.isRetryableError(error)) {
46
+ await this.sleep(this.retryDelayMs * attempt);
47
+ continue;
48
+ }
49
+ throw error;
50
+ }
51
+ finally {
52
+ clearTimeout(timeout);
53
+ }
54
+ }
55
+ }
56
+ isRetryableError(error) {
57
+ return Boolean(error && error.name === 'AbortError');
58
+ }
59
+ sleep(ms) {
60
+ return new Promise((resolve) => setTimeout(resolve, ms));
61
+ }
62
+ parseIntent(payload) {
63
+ return this.request('/v1/intents/parse', payload);
64
+ }
65
+ buildPlan(payload) {
66
+ return this.request('/v1/plans/build', payload);
67
+ }
68
+ simulatePlan(payload) {
69
+ return this.request('/v1/plans/simulate', payload);
70
+ }
71
+ validatePlan(payload) {
72
+ return this.request('/v1/plans/validate', payload);
73
+ }
74
+ verifyPlan(payload) {
75
+ return this.request('/v1/plans/verify', payload);
76
+ }
77
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@bloqzapi/api-ts",
3
+ "version": "1.0.0",
4
+ "description": "Bloqz Intent API SDK (TypeScript)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "dist",
10
+ "src/openapi.d.ts"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "generate:types": "node scripts/generate-types.mjs"
15
+ },
16
+ "devDependencies": {
17
+ "openapi-typescript": "^7.5.0",
18
+ "typescript": "^5.4.5"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "license": "UNLICENSED"
27
+ }
@@ -0,0 +1,361 @@
1
+ export interface paths {
2
+ "/v1/intents/parse": {
3
+ parameters: {
4
+ query?: never;
5
+ header?: never;
6
+ path?: never;
7
+ cookie?: never;
8
+ };
9
+ get?: never;
10
+ put?: never;
11
+ /** Parse intent */
12
+ post: {
13
+ parameters: {
14
+ query?: never;
15
+ header?: never;
16
+ path?: never;
17
+ cookie?: never;
18
+ };
19
+ requestBody: {
20
+ content: {
21
+ "application/json": {
22
+ text?: string;
23
+ intent?: components["schemas"]["IntentSchemaV1"];
24
+ context?: {
25
+ [key: string]: unknown;
26
+ };
27
+ };
28
+ };
29
+ };
30
+ responses: {
31
+ /** @description Parsed intent */
32
+ 200: {
33
+ headers: {
34
+ [name: string]: unknown;
35
+ };
36
+ content: {
37
+ "application/json": Record<string, never>;
38
+ };
39
+ };
40
+ };
41
+ };
42
+ delete?: never;
43
+ options?: never;
44
+ head?: never;
45
+ patch?: never;
46
+ trace?: never;
47
+ };
48
+ "/v1/plans/build": {
49
+ parameters: {
50
+ query?: never;
51
+ header?: never;
52
+ path?: never;
53
+ cookie?: never;
54
+ };
55
+ get?: never;
56
+ put?: never;
57
+ /** Build execution plan */
58
+ post: {
59
+ parameters: {
60
+ query?: never;
61
+ header?: never;
62
+ path?: never;
63
+ cookie?: never;
64
+ };
65
+ requestBody: {
66
+ content: {
67
+ "application/json": {
68
+ text?: string;
69
+ intent?: components["schemas"]["IntentSchemaV1"];
70
+ context?: {
71
+ [key: string]: unknown;
72
+ };
73
+ };
74
+ };
75
+ };
76
+ responses: {
77
+ /** @description Execution plan */
78
+ 200: {
79
+ headers: {
80
+ [name: string]: unknown;
81
+ };
82
+ content: {
83
+ "application/json": components["schemas"]["ExecutionPlanSchemaV1"];
84
+ };
85
+ };
86
+ };
87
+ };
88
+ delete?: never;
89
+ options?: never;
90
+ head?: never;
91
+ patch?: never;
92
+ trace?: never;
93
+ };
94
+ "/v1/plans/simulate": {
95
+ parameters: {
96
+ query?: never;
97
+ header?: never;
98
+ path?: never;
99
+ cookie?: never;
100
+ };
101
+ get?: never;
102
+ put?: never;
103
+ /** Simulate plan */
104
+ post: {
105
+ parameters: {
106
+ query?: never;
107
+ header?: never;
108
+ path?: never;
109
+ cookie?: never;
110
+ };
111
+ requestBody: {
112
+ content: {
113
+ "application/json": {
114
+ text?: string;
115
+ intent?: components["schemas"]["IntentSchemaV1"];
116
+ context?: {
117
+ [key: string]: unknown;
118
+ };
119
+ };
120
+ };
121
+ };
122
+ responses: {
123
+ /** @description Simulation result */
124
+ 200: {
125
+ headers: {
126
+ [name: string]: unknown;
127
+ };
128
+ content: {
129
+ "application/json": Record<string, never>;
130
+ };
131
+ };
132
+ };
133
+ };
134
+ delete?: never;
135
+ options?: never;
136
+ head?: never;
137
+ patch?: never;
138
+ trace?: never;
139
+ };
140
+ "/v1/plans/validate": {
141
+ parameters: {
142
+ query?: never;
143
+ header?: never;
144
+ path?: never;
145
+ cookie?: never;
146
+ };
147
+ get?: never;
148
+ put?: never;
149
+ /** Validate plan schema */
150
+ post: {
151
+ parameters: {
152
+ query?: never;
153
+ header?: never;
154
+ path?: never;
155
+ cookie?: never;
156
+ };
157
+ requestBody: {
158
+ content: {
159
+ "application/json": components["schemas"]["ExecutionPlanSchemaV1"];
160
+ };
161
+ };
162
+ responses: {
163
+ /** @description Validation result */
164
+ 200: {
165
+ headers: {
166
+ [name: string]: unknown;
167
+ };
168
+ content: {
169
+ "application/json": Record<string, never>;
170
+ };
171
+ };
172
+ };
173
+ };
174
+ delete?: never;
175
+ options?: never;
176
+ head?: never;
177
+ patch?: never;
178
+ trace?: never;
179
+ };
180
+ "/v1/plans/verify": {
181
+ parameters: {
182
+ query?: never;
183
+ header?: never;
184
+ path?: never;
185
+ cookie?: never;
186
+ };
187
+ get?: never;
188
+ put?: never;
189
+ /** Verify plan hash proof */
190
+ post: {
191
+ parameters: {
192
+ query?: never;
193
+ header?: never;
194
+ path?: never;
195
+ cookie?: never;
196
+ };
197
+ requestBody: {
198
+ content: {
199
+ "application/json": components["schemas"]["ExecutionPlanSchemaV1"];
200
+ };
201
+ };
202
+ responses: {
203
+ /** @description Verification result */
204
+ 200: {
205
+ headers: {
206
+ [name: string]: unknown;
207
+ };
208
+ content: {
209
+ "application/json": Record<string, never>;
210
+ };
211
+ };
212
+ };
213
+ };
214
+ delete?: never;
215
+ options?: never;
216
+ head?: never;
217
+ patch?: never;
218
+ trace?: never;
219
+ };
220
+ "/v1/schemas": {
221
+ parameters: {
222
+ query?: never;
223
+ header?: never;
224
+ path?: never;
225
+ cookie?: never;
226
+ };
227
+ /** Get JSON schemas */
228
+ get: {
229
+ parameters: {
230
+ query?: never;
231
+ header?: never;
232
+ path?: never;
233
+ cookie?: never;
234
+ };
235
+ requestBody?: never;
236
+ responses: {
237
+ /** @description Schemas */
238
+ 200: {
239
+ headers: {
240
+ [name: string]: unknown;
241
+ };
242
+ content: {
243
+ "application/json": Record<string, never>;
244
+ };
245
+ };
246
+ };
247
+ };
248
+ put?: never;
249
+ post?: never;
250
+ delete?: never;
251
+ options?: never;
252
+ head?: never;
253
+ patch?: never;
254
+ trace?: never;
255
+ };
256
+ }
257
+ export type webhooks = Record<string, never>;
258
+ export interface components {
259
+ schemas: {
260
+ IntentSchemaV1: {
261
+ /** @enum {string} */
262
+ action: "stake" | "swap" | "transfer" | "bridge";
263
+ asset?: string;
264
+ amount?: string;
265
+ /** @enum {string} */
266
+ chain?: "ethereum" | "polygon" | "arbitrum" | "optimism" | "base" | "solana" | "bsc";
267
+ protocol?: string;
268
+ from_asset?: string;
269
+ to_asset?: string;
270
+ recipient?: string;
271
+ /** @enum {string} */
272
+ destination_chain?: "ethereum" | "polygon" | "arbitrum" | "optimism" | "base" | "solana" | "bsc";
273
+ constraints?: {
274
+ max_slippage?: string;
275
+ custody?: string;
276
+ } & {
277
+ [key: string]: unknown;
278
+ };
279
+ schedule?: {
280
+ cadence?: string;
281
+ duration?: string;
282
+ } & {
283
+ [key: string]: unknown;
284
+ };
285
+ targets?: {
286
+ asset: string;
287
+ allocation: number;
288
+ }[];
289
+ };
290
+ ExecutionPlanSchemaV1: {
291
+ /** @enum {string} */
292
+ version: "v1";
293
+ intent: {
294
+ /** @enum {string} */
295
+ action: "stake" | "swap" | "transfer" | "bridge";
296
+ asset?: string;
297
+ amount?: string;
298
+ /** @enum {string} */
299
+ chain?: "ethereum" | "polygon" | "arbitrum" | "optimism" | "base" | "solana" | "bsc";
300
+ protocol?: string;
301
+ from_asset?: string;
302
+ to_asset?: string;
303
+ recipient?: string;
304
+ /** @enum {string} */
305
+ destination_chain?: "ethereum" | "polygon" | "arbitrum" | "optimism" | "base" | "solana" | "bsc";
306
+ constraints?: {
307
+ max_slippage?: string;
308
+ custody?: string;
309
+ } & {
310
+ [key: string]: unknown;
311
+ };
312
+ schedule?: {
313
+ cadence?: string;
314
+ duration?: string;
315
+ } & {
316
+ [key: string]: unknown;
317
+ };
318
+ targets?: {
319
+ asset: string;
320
+ allocation: number;
321
+ }[];
322
+ };
323
+ plan: {
324
+ type: string;
325
+ steps: {
326
+ id: string;
327
+ type: string;
328
+ params: {
329
+ [key: string]: unknown;
330
+ };
331
+ }[];
332
+ summary: string;
333
+ };
334
+ assumptions: string[];
335
+ constraints?: {
336
+ max_slippage?: string;
337
+ custody?: string;
338
+ } & {
339
+ [key: string]: unknown;
340
+ };
341
+ audit: {
342
+ hash: string;
343
+ deterministic: boolean;
344
+ /** @enum {string} */
345
+ hash_version: "sha256-v1";
346
+ proof: {
347
+ hash: string;
348
+ signer?: string;
349
+ timestamp: string;
350
+ };
351
+ };
352
+ };
353
+ };
354
+ responses: never;
355
+ parameters: never;
356
+ requestBodies: never;
357
+ headers: never;
358
+ pathItems: never;
359
+ }
360
+ export type $defs = Record<string, never>;
361
+ export type operations = Record<string, never>;