@voidaisdk/bridge-sdk 0.0.3 → 0.0.4
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/api/client.d.ts +1 -12
- package/dist/api/client.js +6 -71
- package/dist-browser/voidai-sdk.js +1 -1
- package/package.json +1 -1
package/dist/api/client.d.ts
CHANGED
|
@@ -9,9 +9,7 @@ export declare class VoidAIBridgeClient {
|
|
|
9
9
|
readonly ready: Promise<void>;
|
|
10
10
|
constructor(config: BridgeConfig);
|
|
11
11
|
/**
|
|
12
|
-
* Authenticate and set Authorization header
|
|
13
|
-
* New flow: POST /api/v1/auth/login
|
|
14
|
-
* Fallback: GET /api/v1/auth/validate-api-key (legacy)
|
|
12
|
+
* Authenticate via POST /api/v1/auth/login and set Authorization header.
|
|
15
13
|
*/
|
|
16
14
|
private authenticate;
|
|
17
15
|
private setAccessToken;
|
|
@@ -32,15 +30,6 @@ export declare class VoidAIBridgeClient {
|
|
|
32
30
|
login(): Promise<string>;
|
|
33
31
|
private tryDecodeTokenToValidationData;
|
|
34
32
|
private base64UrlDecode;
|
|
35
|
-
/**
|
|
36
|
-
* Validate API key with the backend
|
|
37
|
-
* @throws Error if API key is invalid
|
|
38
|
-
*/
|
|
39
|
-
validateApiKey(): Promise<ApiKeyValidationData>;
|
|
40
|
-
/**
|
|
41
|
-
* Get validation URL - uses baseUrl from config
|
|
42
|
-
*/
|
|
43
|
-
private getValidationUrl;
|
|
44
33
|
/**
|
|
45
34
|
* Get validated API key data
|
|
46
35
|
*/
|
package/dist/api/client.js
CHANGED
|
@@ -17,31 +17,15 @@ class VoidAIBridgeClient {
|
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
19
|
// Start auth immediately. Requests will await this promise.
|
|
20
|
-
// New flow: POST /auth/login to get JWT. Fallback to validate-api-key for backward compatibility.
|
|
21
20
|
this.ready = this.authenticate().then(() => undefined);
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
|
-
* Authenticate and set Authorization header
|
|
25
|
-
* New flow: POST /api/v1/auth/login
|
|
26
|
-
* Fallback: GET /api/v1/auth/validate-api-key (legacy)
|
|
23
|
+
* Authenticate via POST /api/v1/auth/login and set Authorization header.
|
|
27
24
|
*/
|
|
28
25
|
async authenticate() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// Populate validatedApiKeyData from JWT payload (best-effort) so existing getters keep working.
|
|
33
|
-
this.validatedApiKeyData = this.tryDecodeTokenToValidationData(token);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
// If login isn't available or fails unexpectedly, fallback to legacy validation
|
|
37
|
-
// (do not break current working functionality).
|
|
38
|
-
try {
|
|
39
|
-
await this.validateApiKey();
|
|
40
|
-
}
|
|
41
|
-
catch (fallbackError) {
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
26
|
+
const token = await this.login();
|
|
27
|
+
this.setAccessToken(token);
|
|
28
|
+
this.validatedApiKeyData = this.tryDecodeTokenToValidationData(token);
|
|
45
29
|
}
|
|
46
30
|
setAccessToken(token) {
|
|
47
31
|
this.accessToken = token;
|
|
@@ -130,53 +114,6 @@ class VoidAIBridgeClient {
|
|
|
130
114
|
// @ts-ignore
|
|
131
115
|
return atob(padded);
|
|
132
116
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Validate API key with the backend
|
|
135
|
-
* @throws Error if API key is invalid
|
|
136
|
-
*/
|
|
137
|
-
async validateApiKey() {
|
|
138
|
-
try {
|
|
139
|
-
// Use a temporary axios instance for validation since baseUrl might be different
|
|
140
|
-
const validationUrl = this.getValidationUrl();
|
|
141
|
-
const response = await axios_1.default.get(validationUrl, {
|
|
142
|
-
headers: {
|
|
143
|
-
'api-key': this.config.apiKey,
|
|
144
|
-
},
|
|
145
|
-
timeout: 10000,
|
|
146
|
-
});
|
|
147
|
-
if (response.data.success) {
|
|
148
|
-
this.validatedApiKeyData = response.data.data;
|
|
149
|
-
return response.data.data;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
const error = new Error(response.data.error.message);
|
|
153
|
-
error.code = response.data.error.code;
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
catch (error) {
|
|
158
|
-
// If validation fails, ensure we don't keep stale validated data around.
|
|
159
|
-
this.validatedApiKeyData = null;
|
|
160
|
-
if (axios_1.default.isAxiosError(error)) {
|
|
161
|
-
if (error.response?.status === 401) {
|
|
162
|
-
const errorData = error.response.data;
|
|
163
|
-
const apiError = new Error(errorData.error?.message || 'API key is invalid or inactive');
|
|
164
|
-
apiError.code = errorData.error?.code || 'INVALID_API_KEY';
|
|
165
|
-
throw apiError;
|
|
166
|
-
}
|
|
167
|
-
throw new Error(`Failed to validate API key: ${error.message}`);
|
|
168
|
-
}
|
|
169
|
-
throw error;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Get validation URL - uses baseUrl from config
|
|
174
|
-
*/
|
|
175
|
-
getValidationUrl() {
|
|
176
|
-
const baseUrl = this.config.getBaseUrl();
|
|
177
|
-
const cleanBase = baseUrl.replace(/\/$/, '');
|
|
178
|
-
return `${cleanBase}/api/v1/auth/validate-api-key`;
|
|
179
|
-
}
|
|
180
117
|
/**
|
|
181
118
|
* Get validated API key data
|
|
182
119
|
*/
|
|
@@ -406,9 +343,7 @@ class VoidAIBridgeClient {
|
|
|
406
343
|
toToken: params.toToken,
|
|
407
344
|
amount: String(params.amount),
|
|
408
345
|
};
|
|
409
|
-
return this.get('api/v1/bridge/call-fee', queryParams
|
|
410
|
-
headers: { 'x-api-key': this.config.apiKey },
|
|
411
|
-
});
|
|
346
|
+
return this.get('api/v1/bridge/call-fee', queryParams);
|
|
412
347
|
}
|
|
413
348
|
/**
|
|
414
349
|
* Get router swap fee estimate
|
|
@@ -422,7 +357,7 @@ class VoidAIBridgeClient {
|
|
|
422
357
|
operationType: params.operationType,
|
|
423
358
|
toAddress: params.toAddress,
|
|
424
359
|
};
|
|
425
|
-
return this.get('api/v1/router-swap/call-fee', queryParams
|
|
360
|
+
return this.get('api/v1/router-swap/call-fee', queryParams);
|
|
426
361
|
}
|
|
427
362
|
/**
|
|
428
363
|
* Normalize and rethrow errors with backend message (if available) so
|