@amadeus-protocol/sdk 1.0.7 → 1.1.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.
- package/dist/api/chain.d.ts +144 -117
- package/dist/api/chain.d.ts.map +1 -1
- package/dist/api/chain.js +175 -146
- package/dist/api/chain.js.map +1 -1
- package/dist/api/contract.d.ts +78 -60
- package/dist/api/contract.d.ts.map +1 -1
- package/dist/api/contract.js +102 -75
- package/dist/api/contract.js.map +1 -1
- package/dist/api/epoch.d.ts +65 -66
- package/dist/api/epoch.d.ts.map +1 -1
- package/dist/api/epoch.js +90 -98
- package/dist/api/epoch.js.map +1 -1
- package/dist/api/peer.d.ts +77 -78
- package/dist/api/peer.d.ts.map +1 -1
- package/dist/api/peer.js +93 -94
- package/dist/api/peer.js.map +1 -1
- package/dist/api/proof.d.ts +44 -23
- package/dist/api/proof.d.ts.map +1 -1
- package/dist/api/proof.js +56 -29
- package/dist/api/proof.js.map +1 -1
- package/dist/api/transaction.d.ts +68 -69
- package/dist/api/transaction.d.ts.map +1 -1
- package/dist/api/transaction.js +84 -84
- package/dist/api/transaction.js.map +1 -1
- package/dist/api/wallet.d.ts +36 -37
- package/dist/api/wallet.d.ts.map +1 -1
- package/dist/api/wallet.js +47 -50
- package/dist/api/wallet.js.map +1 -1
- package/dist/client.d.ts +66 -68
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +231 -276
- package/dist/client.js.map +1 -1
- package/dist/constants.d.ts +13 -10
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +49 -45
- package/dist/constants.js.map +1 -1
- package/dist/contract-state.d.ts +6 -3
- package/dist/contract-state.d.ts.map +1 -1
- package/dist/contract-state.js +88 -106
- package/dist/contract-state.js.map +1 -1
- package/dist/contracts/abi-types.d.ts +32 -32
- package/dist/contracts/abi-types.d.ts.map +1 -1
- package/dist/contracts/coin.d.ts +13 -20
- package/dist/contracts/coin.d.ts.map +1 -1
- package/dist/contracts/coin.js +42 -38
- package/dist/contracts/coin.js.map +1 -1
- package/dist/contracts/contract-call.d.ts +14 -16
- package/dist/contracts/contract-call.d.ts.map +1 -1
- package/dist/contracts/contract-call.js +45 -54
- package/dist/contracts/contract-call.js.map +1 -1
- package/dist/contracts/contract.d.ts +24 -55
- package/dist/contracts/contract.d.ts.map +1 -1
- package/dist/contracts/contract.js +63 -101
- package/dist/contracts/contract.js.map +1 -1
- package/dist/contracts/lockup/abi.d.ts +54 -51
- package/dist/contracts/lockup/abi.d.ts.map +1 -1
- package/dist/contracts/lockup/abi.js +65 -74
- package/dist/contracts/lockup/abi.js.map +1 -1
- package/dist/contracts/lockup/helpers.d.ts +22 -18
- package/dist/contracts/lockup/helpers.d.ts.map +1 -1
- package/dist/contracts/lockup/helpers.js +44 -47
- package/dist/contracts/lockup/helpers.js.map +1 -1
- package/dist/contracts/lockup/parsers.d.ts +7 -3
- package/dist/contracts/lockup/parsers.d.ts.map +1 -1
- package/dist/contracts/lockup/parsers.js +51 -55
- package/dist/contracts/lockup/parsers.js.map +1 -1
- package/dist/contracts/lockup/storage-keys.d.ts +5 -2
- package/dist/contracts/lockup/storage-keys.d.ts.map +1 -1
- package/dist/contracts/lockup/storage-keys.js +54 -70
- package/dist/contracts/lockup/storage-keys.js.map +1 -1
- package/dist/contracts/lockup/types.d.ts +73 -70
- package/dist/contracts/lockup/types.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/abi.d.ts +328 -325
- package/dist/contracts/lockup-prime/abi.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/abi.js +397 -417
- package/dist/contracts/lockup-prime/abi.js.map +1 -1
- package/dist/contracts/lockup-prime/helpers.d.ts +35 -31
- package/dist/contracts/lockup-prime/helpers.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/helpers.js +131 -137
- package/dist/contracts/lockup-prime/helpers.js.map +1 -1
- package/dist/contracts/lockup-prime/parsers.d.ts +9 -5
- package/dist/contracts/lockup-prime/parsers.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/parsers.js +61 -61
- package/dist/contracts/lockup-prime/parsers.js.map +1 -1
- package/dist/contracts/lockup-prime/storage-keys.d.ts +7 -4
- package/dist/contracts/lockup-prime/storage-keys.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/storage-keys.js +64 -80
- package/dist/contracts/lockup-prime/storage-keys.js.map +1 -1
- package/dist/contracts/lockup-prime/types.d.ts +92 -89
- package/dist/contracts/lockup-prime/types.d.ts.map +1 -1
- package/dist/contracts/lockup-prime/types.js +12 -13
- package/dist/contracts/lockup-prime/types.js.map +1 -1
- package/dist/contracts/nft/abi.d.ts +104 -0
- package/dist/contracts/nft/abi.d.ts.map +1 -0
- package/dist/contracts/nft/abi.js +135 -0
- package/dist/contracts/nft/abi.js.map +1 -0
- package/dist/contracts/nft/helpers.d.ts +21 -0
- package/dist/contracts/nft/helpers.d.ts.map +1 -0
- package/dist/contracts/nft/helpers.js +61 -0
- package/dist/contracts/nft/helpers.js.map +1 -0
- package/dist/contracts/nft/types.d.ts +47 -0
- package/dist/contracts/nft/types.d.ts.map +1 -0
- package/dist/conversion.d.ts +5 -2
- package/dist/conversion.d.ts.map +1 -1
- package/dist/conversion.js +45 -50
- package/dist/conversion.js.map +1 -1
- package/dist/crypto.d.ts +14 -16
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +121 -140
- package/dist/crypto.js.map +1 -1
- package/dist/encoding.d.ts +11 -8
- package/dist/encoding.d.ts.map +1 -1
- package/dist/encoding.js +123 -144
- package/dist/encoding.js.map +1 -1
- package/dist/encryption.d.ts +15 -12
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +119 -117
- package/dist/encryption.js.map +1 -1
- package/dist/explorer.d.ts +10 -7
- package/dist/explorer.d.ts.map +1 -1
- package/dist/explorer.js +51 -48
- package/dist/explorer.js.map +1 -1
- package/dist/formatters.d.ts +8 -5
- package/dist/formatters.d.ts.map +1 -1
- package/dist/formatters.js +67 -68
- package/dist/formatters.js.map +1 -1
- package/dist/index.d.ts +42 -54
- package/dist/index.js +39 -54
- package/dist/mnemonic.d.ts +99 -0
- package/dist/mnemonic.d.ts.map +1 -0
- package/dist/mnemonic.js +119 -0
- package/dist/mnemonic.js.map +1 -0
- package/dist/networks.d.ts +14 -17
- package/dist/networks.d.ts.map +1 -1
- package/dist/networks.js +40 -36
- package/dist/networks.js.map +1 -1
- package/dist/schemas.js +75 -79
- package/dist/schemas.js.map +1 -1
- package/dist/sdk.d.ts +69 -65
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +126 -117
- package/dist/sdk.js.map +1 -1
- package/dist/serialization.d.ts +8 -18
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +207 -260
- package/dist/serialization.js.map +1 -1
- package/dist/signing.js +67 -67
- package/dist/signing.js.map +1 -1
- package/dist/transaction-builder.d.ts +175 -184
- package/dist/transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder.js +295 -344
- package/dist/transaction-builder.js.map +1 -1
- package/dist/transaction-errors.d.ts +10 -12
- package/dist/transaction-errors.d.ts.map +1 -1
- package/dist/transaction-errors.js +145 -166
- package/dist/transaction-errors.js.map +1 -1
- package/dist/types.d.ts +530 -450
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +169 -183
- package/dist/types.js.map +1 -1
- package/dist/validation.d.ts +24 -26
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +194 -192
- package/dist/validation.js.map +1 -1
- package/package.json +5 -3
- package/dist/api/index.d.ts +0 -8
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -8
- package/dist/api/index.js.map +0 -1
- package/dist/contracts/abi-types.js +0 -8
- package/dist/contracts/abi-types.js.map +0 -1
- package/dist/contracts/index.d.ts +0 -7
- package/dist/contracts/index.d.ts.map +0 -1
- package/dist/contracts/index.js +0 -7
- package/dist/contracts/index.js.map +0 -1
- package/dist/contracts/lockup/calls.d.ts +0 -23
- package/dist/contracts/lockup/calls.d.ts.map +0 -1
- package/dist/contracts/lockup/calls.js +0 -25
- package/dist/contracts/lockup/calls.js.map +0 -1
- package/dist/contracts/lockup/index.d.ts +0 -6
- package/dist/contracts/lockup/index.d.ts.map +0 -1
- package/dist/contracts/lockup/index.js +0 -6
- package/dist/contracts/lockup/index.js.map +0 -1
- package/dist/contracts/lockup/types.js +0 -7
- package/dist/contracts/lockup/types.js.map +0 -1
- package/dist/contracts/lockup-prime/calls.d.ts +0 -53
- package/dist/contracts/lockup-prime/calls.d.ts.map +0 -1
- package/dist/contracts/lockup-prime/calls.js +0 -60
- package/dist/contracts/lockup-prime/calls.js.map +0 -1
- package/dist/contracts/lockup-prime/index.d.ts +0 -6
- package/dist/contracts/lockup-prime/index.d.ts.map +0 -1
- package/dist/contracts/lockup-prime/index.js +0 -6
- package/dist/contracts/lockup-prime/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/schemas.d.ts +0 -67
- package/dist/schemas.d.ts.map +0 -1
- package/dist/signing.d.ts +0 -39
- package/dist/signing.d.ts.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,280 +1,235 @@
|
|
|
1
|
+
import { AmadeusSDKError } from "./types.js";
|
|
2
|
+
import { DEFAULT_TIMEOUT, SDK_VERSION } from "./constants.js";
|
|
3
|
+
import { validate } from "./validation.js";
|
|
4
|
+
import { NonEmptyStringSchema } from "./schemas.js";
|
|
5
|
+
//#region src/client.ts
|
|
1
6
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Lightweight HTTP client using native fetch API (no axios dependency)
|
|
5
|
-
* Provides request/response handling, timeout management, and error handling.
|
|
6
|
-
*/
|
|
7
|
-
import { AmadeusSDKError } from './types';
|
|
8
|
-
import { NODE_API_URL, DEFAULT_TIMEOUT, SDK_VERSION } from './constants';
|
|
9
|
-
import { NonEmptyStringSchema } from './schemas';
|
|
10
|
-
import { validate } from './validation';
|
|
11
|
-
/**
|
|
12
|
-
* Validates a URL string
|
|
13
|
-
*/
|
|
7
|
+
* Validates a URL string
|
|
8
|
+
*/
|
|
14
9
|
function isValidUrl(url) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export class AmadeusClient {
|
|
24
|
-
config;
|
|
25
|
-
abortController = null;
|
|
26
|
-
/**
|
|
27
|
-
* Create a new AmadeusClient instance
|
|
28
|
-
*
|
|
29
|
-
* @param config - SDK configuration
|
|
30
|
-
* @throws {AmadeusSDKError} If baseUrl is invalid
|
|
31
|
-
*/
|
|
32
|
-
constructor(config) {
|
|
33
|
-
const baseUrl = config.baseUrl || NODE_API_URL;
|
|
34
|
-
if (!isValidUrl(baseUrl)) {
|
|
35
|
-
throw new AmadeusSDKError(`Invalid baseUrl: ${baseUrl}. Must be a valid HTTP/HTTPS URL.`);
|
|
36
|
-
}
|
|
37
|
-
// Ensure baseUrl doesn't end with a slash
|
|
38
|
-
const normalizedBaseUrl = baseUrl.replace(/\/+$/, '');
|
|
39
|
-
this.config = {
|
|
40
|
-
baseUrl: normalizedBaseUrl,
|
|
41
|
-
timeout: config.timeout && config.timeout > 0 ? config.timeout : DEFAULT_TIMEOUT,
|
|
42
|
-
headers: {
|
|
43
|
-
'Content-Type': 'application/octet-stream',
|
|
44
|
-
'X-Client-Type': `@amadeus-protocol/sdk/${SDK_VERSION}`,
|
|
45
|
-
...config.headers
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Make a GET request
|
|
51
|
-
*
|
|
52
|
-
* @param endpoint - API endpoint path
|
|
53
|
-
* @param params - Optional query parameters
|
|
54
|
-
* @returns Promise resolving to the response data
|
|
55
|
-
*/
|
|
56
|
-
async get(endpoint, params) {
|
|
57
|
-
validate(NonEmptyStringSchema, endpoint);
|
|
58
|
-
const url = this.buildUrl(endpoint, params);
|
|
59
|
-
const response = await this.request(url, {
|
|
60
|
-
method: 'GET'
|
|
61
|
-
});
|
|
62
|
-
return this.handleResponse(response);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Make a POST request
|
|
66
|
-
*
|
|
67
|
-
* @param endpoint - API endpoint path
|
|
68
|
-
* @param data - Request body data (Uint8Array for binary, object for JSON)
|
|
69
|
-
* @returns Promise resolving to the response data
|
|
70
|
-
*/
|
|
71
|
-
async post(endpoint, data) {
|
|
72
|
-
validate(NonEmptyStringSchema, endpoint);
|
|
73
|
-
const url = this.buildUrl(endpoint);
|
|
74
|
-
const { body, contentType } = this.prepareBody(data);
|
|
75
|
-
const response = await this.request(url, {
|
|
76
|
-
method: 'POST',
|
|
77
|
-
body,
|
|
78
|
-
headers: {
|
|
79
|
-
'Content-Type': contentType
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return this.handleResponse(response);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Build full URL with query parameters
|
|
86
|
-
*/
|
|
87
|
-
buildUrl(endpoint, params) {
|
|
88
|
-
const url = new URL(endpoint, this.config.baseUrl);
|
|
89
|
-
if (params) {
|
|
90
|
-
for (const [key, value] of Object.entries(params)) {
|
|
91
|
-
if (value !== undefined && value !== null) {
|
|
92
|
-
url.searchParams.append(key, String(value));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return url.toString();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Prepare request body and determine Content-Type
|
|
100
|
-
*/
|
|
101
|
-
prepareBody(data) {
|
|
102
|
-
if (!data) {
|
|
103
|
-
return { body: undefined, contentType: 'application/octet-stream' };
|
|
104
|
-
}
|
|
105
|
-
// If it's already a Uint8Array or ArrayBuffer, send as binary
|
|
106
|
-
if (data instanceof Uint8Array) {
|
|
107
|
-
return { body: data, contentType: 'application/octet-stream' };
|
|
108
|
-
}
|
|
109
|
-
if (data instanceof ArrayBuffer) {
|
|
110
|
-
return { body: data, contentType: 'application/octet-stream' };
|
|
111
|
-
}
|
|
112
|
-
// If it's a Buffer (Node.js), convert to Uint8Array
|
|
113
|
-
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) {
|
|
114
|
-
return {
|
|
115
|
-
body: new Uint8Array(data),
|
|
116
|
-
contentType: 'application/octet-stream'
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
// For objects, try to send as binary if it has txPacked or tx_packed
|
|
120
|
-
if (typeof data === 'object' && data !== null) {
|
|
121
|
-
const obj = data;
|
|
122
|
-
if ('txPacked' in obj && obj.txPacked instanceof Uint8Array) {
|
|
123
|
-
return { body: obj.txPacked, contentType: 'application/octet-stream' };
|
|
124
|
-
}
|
|
125
|
-
if ('tx_packed' in obj && obj.tx_packed instanceof Uint8Array) {
|
|
126
|
-
return { body: obj.tx_packed, contentType: 'application/octet-stream' };
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// Default: send as JSON
|
|
130
|
-
return { body: JSON.stringify(data), contentType: 'application/json' };
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Make HTTP request with timeout
|
|
134
|
-
*/
|
|
135
|
-
async request(url, options) {
|
|
136
|
-
// Cancel previous request if any
|
|
137
|
-
if (this.abortController) {
|
|
138
|
-
this.abortController.abort();
|
|
139
|
-
}
|
|
140
|
-
this.abortController = new AbortController();
|
|
141
|
-
const timeoutId = setTimeout(() => {
|
|
142
|
-
this.abortController?.abort();
|
|
143
|
-
}, this.config.timeout);
|
|
144
|
-
try {
|
|
145
|
-
const response = await fetch(url, {
|
|
146
|
-
...options,
|
|
147
|
-
headers: {
|
|
148
|
-
...this.config.headers,
|
|
149
|
-
...options.headers
|
|
150
|
-
},
|
|
151
|
-
signal: this.abortController.signal
|
|
152
|
-
});
|
|
153
|
-
clearTimeout(timeoutId);
|
|
154
|
-
return response;
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
clearTimeout(timeoutId);
|
|
158
|
-
if (error instanceof Error) {
|
|
159
|
-
if (error.name === 'AbortError' || error.name === 'TimeoutError') {
|
|
160
|
-
throw new AmadeusSDKError(`Request timeout after ${this.config.timeout}ms`, 408);
|
|
161
|
-
}
|
|
162
|
-
throw new AmadeusSDKError(`Request failed: ${error.message}`, 0, error instanceof Error
|
|
163
|
-
? { message: error.message, name: error.name }
|
|
164
|
-
: { error: String(error) });
|
|
165
|
-
}
|
|
166
|
-
throw new AmadeusSDKError(`Request failed: ${String(error)}`, 0, {
|
|
167
|
-
error: String(error)
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Handle API response and parse errors
|
|
173
|
-
*/
|
|
174
|
-
async handleResponse(response) {
|
|
175
|
-
if (!response.ok) {
|
|
176
|
-
let errorData;
|
|
177
|
-
const contentType = response.headers.get('content-type');
|
|
178
|
-
try {
|
|
179
|
-
if (contentType?.includes('application/json')) {
|
|
180
|
-
errorData = await response.json();
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
const text = await response.text();
|
|
184
|
-
// If it's HTML, try to extract a meaningful error message
|
|
185
|
-
if (contentType?.includes('text/html')) {
|
|
186
|
-
// Try to extract title or error message from HTML
|
|
187
|
-
const titleMatch = text.match(/<title>([^<]+)<\/title>/i);
|
|
188
|
-
const h1Match = text.match(/<h1[^>]*>([^<]+)<\/h1>/i);
|
|
189
|
-
errorData =
|
|
190
|
-
titleMatch?.[1] || h1Match?.[1] || `HTTP ${response.status} Error`;
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
errorData = text;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
catch (parseError) {
|
|
198
|
-
errorData = `Failed to parse error response: ${parseError instanceof Error ? parseError.message : String(parseError)}`;
|
|
199
|
-
}
|
|
200
|
-
const message = typeof errorData === 'object' && errorData !== null && 'error' in errorData
|
|
201
|
-
? String(errorData.error)
|
|
202
|
-
: typeof errorData === 'string'
|
|
203
|
-
? errorData.length > 500
|
|
204
|
-
? `${errorData.substring(0, 500)}... (truncated)`
|
|
205
|
-
: errorData
|
|
206
|
-
: response.statusText || 'Unknown error';
|
|
207
|
-
throw new AmadeusSDKError(`HTTP ${response.status}: ${message}`, response.status, errorData);
|
|
208
|
-
}
|
|
209
|
-
const contentType = response.headers.get('content-type');
|
|
210
|
-
let data;
|
|
211
|
-
try {
|
|
212
|
-
if (contentType?.includes('application/json')) {
|
|
213
|
-
data = await response.json();
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
// Try JSON first, fallback to text
|
|
217
|
-
const text = await response.text();
|
|
218
|
-
try {
|
|
219
|
-
data = JSON.parse(text);
|
|
220
|
-
}
|
|
221
|
-
catch {
|
|
222
|
-
data = text;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
catch (parseError) {
|
|
227
|
-
throw new AmadeusSDKError(`Failed to parse response: ${parseError instanceof Error ? parseError.message : String(parseError)}`, response.status);
|
|
228
|
-
}
|
|
229
|
-
// Handle API response format
|
|
230
|
-
if (typeof data === 'object' && data !== null && 'error' in data) {
|
|
231
|
-
const apiResponse = data;
|
|
232
|
-
if (apiResponse.error === 'ok') {
|
|
233
|
-
// Remove error property from response (intentionally unused)
|
|
234
|
-
const { error: _error, ...rest } = apiResponse;
|
|
235
|
-
return rest;
|
|
236
|
-
}
|
|
237
|
-
else if (apiResponse.error === 'not_found') {
|
|
238
|
-
throw new AmadeusSDKError('Resource not found', 404, apiResponse);
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
throw new AmadeusSDKError(apiResponse.error || 'Unknown API error', 400, apiResponse);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return data;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Get current configuration
|
|
248
|
-
*/
|
|
249
|
-
getConfig() {
|
|
250
|
-
return { ...this.config };
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Update base URL
|
|
254
|
-
*
|
|
255
|
-
* @param url - New base URL
|
|
256
|
-
* @throws {AmadeusSDKError} If URL is invalid
|
|
257
|
-
*/
|
|
258
|
-
setBaseUrl(url) {
|
|
259
|
-
if (!isValidUrl(url)) {
|
|
260
|
-
throw new AmadeusSDKError(`Invalid baseUrl: ${url}. Must be a valid HTTP/HTTPS URL.`);
|
|
261
|
-
}
|
|
262
|
-
this.config.baseUrl = url.replace(/\/+$/, '');
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Update headers
|
|
266
|
-
*/
|
|
267
|
-
setHeaders(headers) {
|
|
268
|
-
this.config.headers = { ...this.config.headers, ...headers };
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Cancel ongoing requests
|
|
272
|
-
*/
|
|
273
|
-
cancel() {
|
|
274
|
-
if (this.abortController) {
|
|
275
|
-
this.abortController.abort();
|
|
276
|
-
this.abortController = null;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
10
|
+
try {
|
|
11
|
+
const parsed = new URL(url);
|
|
12
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
279
16
|
}
|
|
17
|
+
var AmadeusClient = class {
|
|
18
|
+
config;
|
|
19
|
+
abortController = null;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new AmadeusClient instance
|
|
22
|
+
*
|
|
23
|
+
* @param config - SDK configuration
|
|
24
|
+
* @throws {AmadeusSDKError} If baseUrl is invalid
|
|
25
|
+
*/
|
|
26
|
+
constructor(config) {
|
|
27
|
+
const baseUrl = config.baseUrl || "https://mainnet-rpc.ama.one/api";
|
|
28
|
+
if (!isValidUrl(baseUrl)) throw new AmadeusSDKError(`Invalid baseUrl: ${baseUrl}. Must be a valid HTTP/HTTPS URL.`);
|
|
29
|
+
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
|
|
30
|
+
this.config = {
|
|
31
|
+
baseUrl: normalizedBaseUrl,
|
|
32
|
+
timeout: config.timeout && config.timeout > 0 ? config.timeout : DEFAULT_TIMEOUT,
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "application/octet-stream",
|
|
35
|
+
"X-Client-Type": `@amadeus-protocol/sdk/${SDK_VERSION}`,
|
|
36
|
+
...config.headers
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Make a GET request
|
|
42
|
+
*
|
|
43
|
+
* @param endpoint - API endpoint path
|
|
44
|
+
* @param params - Optional query parameters
|
|
45
|
+
* @returns Promise resolving to the response data
|
|
46
|
+
*/
|
|
47
|
+
async get(endpoint, params) {
|
|
48
|
+
validate(NonEmptyStringSchema, endpoint);
|
|
49
|
+
const url = this.buildUrl(endpoint, params);
|
|
50
|
+
const response = await this.request(url, { method: "GET" });
|
|
51
|
+
return this.handleResponse(response);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Make a POST request
|
|
55
|
+
*
|
|
56
|
+
* @param endpoint - API endpoint path
|
|
57
|
+
* @param data - Request body data (Uint8Array for binary, object for JSON)
|
|
58
|
+
* @returns Promise resolving to the response data
|
|
59
|
+
*/
|
|
60
|
+
async post(endpoint, data) {
|
|
61
|
+
validate(NonEmptyStringSchema, endpoint);
|
|
62
|
+
const url = this.buildUrl(endpoint);
|
|
63
|
+
const { body, contentType } = this.prepareBody(data);
|
|
64
|
+
const response = await this.request(url, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body,
|
|
67
|
+
headers: { "Content-Type": contentType }
|
|
68
|
+
});
|
|
69
|
+
return this.handleResponse(response);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Build full URL with query parameters
|
|
73
|
+
*/
|
|
74
|
+
buildUrl(endpoint, params) {
|
|
75
|
+
const url = new URL(endpoint, this.config.baseUrl);
|
|
76
|
+
if (params) {
|
|
77
|
+
for (const [key, value] of Object.entries(params)) if (value !== void 0 && value !== null) url.searchParams.append(key, String(value));
|
|
78
|
+
}
|
|
79
|
+
return url.toString();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Prepare request body and determine Content-Type
|
|
83
|
+
*/
|
|
84
|
+
prepareBody(data) {
|
|
85
|
+
if (!data) return {
|
|
86
|
+
body: void 0,
|
|
87
|
+
contentType: "application/octet-stream"
|
|
88
|
+
};
|
|
89
|
+
if (data instanceof Uint8Array) return {
|
|
90
|
+
body: data,
|
|
91
|
+
contentType: "application/octet-stream"
|
|
92
|
+
};
|
|
93
|
+
if (data instanceof ArrayBuffer) return {
|
|
94
|
+
body: data,
|
|
95
|
+
contentType: "application/octet-stream"
|
|
96
|
+
};
|
|
97
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) return {
|
|
98
|
+
body: new Uint8Array(data),
|
|
99
|
+
contentType: "application/octet-stream"
|
|
100
|
+
};
|
|
101
|
+
if (typeof data === "object" && data !== null) {
|
|
102
|
+
const obj = data;
|
|
103
|
+
if ("txPacked" in obj && obj.txPacked instanceof Uint8Array) return {
|
|
104
|
+
body: obj.txPacked,
|
|
105
|
+
contentType: "application/octet-stream"
|
|
106
|
+
};
|
|
107
|
+
if ("tx_packed" in obj && obj.tx_packed instanceof Uint8Array) return {
|
|
108
|
+
body: obj.tx_packed,
|
|
109
|
+
contentType: "application/octet-stream"
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
body: JSON.stringify(data),
|
|
114
|
+
contentType: "application/json"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Make HTTP request with timeout
|
|
119
|
+
*/
|
|
120
|
+
async request(url, options) {
|
|
121
|
+
if (this.abortController) this.abortController.abort();
|
|
122
|
+
this.abortController = new AbortController();
|
|
123
|
+
const timeoutId = setTimeout(() => {
|
|
124
|
+
this.abortController?.abort();
|
|
125
|
+
}, this.config.timeout);
|
|
126
|
+
try {
|
|
127
|
+
const response = await fetch(url, {
|
|
128
|
+
...options,
|
|
129
|
+
headers: {
|
|
130
|
+
...this.config.headers,
|
|
131
|
+
...options.headers
|
|
132
|
+
},
|
|
133
|
+
signal: this.abortController.signal
|
|
134
|
+
});
|
|
135
|
+
clearTimeout(timeoutId);
|
|
136
|
+
return response;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
clearTimeout(timeoutId);
|
|
139
|
+
if (error instanceof Error) {
|
|
140
|
+
if (error.name === "AbortError" || error.name === "TimeoutError") throw new AmadeusSDKError(`Request timeout after ${this.config.timeout}ms`, 408);
|
|
141
|
+
throw new AmadeusSDKError(`Request failed: ${error.message}`, 0, error instanceof Error ? {
|
|
142
|
+
message: error.message,
|
|
143
|
+
name: error.name
|
|
144
|
+
} : { error: String(error) });
|
|
145
|
+
}
|
|
146
|
+
throw new AmadeusSDKError(`Request failed: ${String(error)}`, 0, { error: String(error) });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Handle API response and parse errors
|
|
151
|
+
*/
|
|
152
|
+
async handleResponse(response) {
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
let errorData;
|
|
155
|
+
const contentType = response.headers.get("content-type");
|
|
156
|
+
try {
|
|
157
|
+
if (contentType?.includes("application/json")) errorData = await response.json();
|
|
158
|
+
else {
|
|
159
|
+
const text = await response.text();
|
|
160
|
+
if (contentType?.includes("text/html")) {
|
|
161
|
+
const titleMatch = text.match(/<title>([^<]+)<\/title>/i);
|
|
162
|
+
const h1Match = text.match(/<h1[^>]*>([^<]+)<\/h1>/i);
|
|
163
|
+
errorData = titleMatch?.[1] || h1Match?.[1] || `HTTP ${response.status} Error`;
|
|
164
|
+
} else errorData = text;
|
|
165
|
+
}
|
|
166
|
+
} catch (parseError) {
|
|
167
|
+
errorData = `Failed to parse error response: ${parseError instanceof Error ? parseError.message : String(parseError)}`;
|
|
168
|
+
}
|
|
169
|
+
const message = typeof errorData === "object" && errorData !== null && "error" in errorData ? String(errorData.error) : typeof errorData === "string" ? errorData.length > 500 ? `${errorData.substring(0, 500)}... (truncated)` : errorData : response.statusText || "Unknown error";
|
|
170
|
+
throw new AmadeusSDKError(`HTTP ${response.status}: ${message}`, response.status, errorData);
|
|
171
|
+
}
|
|
172
|
+
const contentType = response.headers.get("content-type");
|
|
173
|
+
let data;
|
|
174
|
+
try {
|
|
175
|
+
if (contentType?.includes("application/json")) data = await response.json();
|
|
176
|
+
else {
|
|
177
|
+
const text = await response.text();
|
|
178
|
+
try {
|
|
179
|
+
data = JSON.parse(text);
|
|
180
|
+
} catch {
|
|
181
|
+
data = text;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} catch (parseError) {
|
|
185
|
+
throw new AmadeusSDKError(`Failed to parse response: ${parseError instanceof Error ? parseError.message : String(parseError)}`, response.status);
|
|
186
|
+
}
|
|
187
|
+
if (typeof data === "object" && data !== null && "error" in data) {
|
|
188
|
+
const apiResponse = data;
|
|
189
|
+
if (apiResponse.error === "ok") {
|
|
190
|
+
const { error: _error, ...rest } = apiResponse;
|
|
191
|
+
return rest;
|
|
192
|
+
} else if (apiResponse.error === "not_found") throw new AmadeusSDKError("Resource not found", 404, apiResponse);
|
|
193
|
+
else throw new AmadeusSDKError(apiResponse.error || "Unknown API error", 400, apiResponse);
|
|
194
|
+
}
|
|
195
|
+
return data;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get current configuration
|
|
199
|
+
*/
|
|
200
|
+
getConfig() {
|
|
201
|
+
return { ...this.config };
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Update base URL
|
|
205
|
+
*
|
|
206
|
+
* @param url - New base URL
|
|
207
|
+
* @throws {AmadeusSDKError} If URL is invalid
|
|
208
|
+
*/
|
|
209
|
+
setBaseUrl(url) {
|
|
210
|
+
if (!isValidUrl(url)) throw new AmadeusSDKError(`Invalid baseUrl: ${url}. Must be a valid HTTP/HTTPS URL.`);
|
|
211
|
+
this.config.baseUrl = url.replace(/\/+$/, "");
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Update headers
|
|
215
|
+
*/
|
|
216
|
+
setHeaders(headers) {
|
|
217
|
+
this.config.headers = {
|
|
218
|
+
...this.config.headers,
|
|
219
|
+
...headers
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Cancel ongoing requests
|
|
224
|
+
*/
|
|
225
|
+
cancel() {
|
|
226
|
+
if (this.abortController) {
|
|
227
|
+
this.abortController.abort();
|
|
228
|
+
this.abortController = null;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
//#endregion
|
|
233
|
+
export { AmadeusClient };
|
|
234
|
+
|
|
280
235
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEvC;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW;IAC9B,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,OAAO,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAA;IACnE,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAA;IACb,CAAC;AACF,CAAC;AAED,MAAM,OAAO,aAAa;IACjB,MAAM,CAA4B;IAClC,eAAe,GAA2B,IAAI,CAAA;IAEtD;;;;;OAKG;IACH,YAAY,MAAwB;QACnC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,YAAY,CA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AAG,WAAW,CAAA;gBAC9C,OAAO,IAAI,CAAA;YACZ,CAAC;iBAAM,IAAI,WAAW,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;gBAC9C,MAAM,IAAI,eAAe,CACxB,oBAAoB,EACpB,GAAG,EACH,WAAsC,CACtC,CAAA;YACF,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,eAAe,CACxB,WAAW,CAAC,KAAK,IAAI,mBAAmB,EACxC,GAAG,EACH,WAAsC,CACtC,CAAA;YACF,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;IAED;;OAEG;IACH,SAAS;QACR,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;IAC1B,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,GAAW;QACrB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,eAAe,CAAC,oBAAoB,GAAG,mCAAmC,CAAC,CAAA;QACtF,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC9C,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAA+B;QACzC,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAA;IAC7D,CAAC;IAED;;OAEG;IACH,MAAM;QACL,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;YAC5B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAA;QAC5B,CAAC;IACF,CAAC;CACD"}
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["/**\n * HTTP Client\n *\n * Lightweight HTTP client using native fetch API (no axios dependency)\n * Provides request/response handling, timeout management, and error handling.\n */\n\nimport type { AmadeusSDKConfig, ApiResponse } from './types'\nimport { AmadeusSDKError } from './types'\nimport { NODE_API_URL, DEFAULT_TIMEOUT, SDK_VERSION } from './constants'\nimport { NonEmptyStringSchema } from './schemas'\nimport { validate } from './validation'\n\n/**\n * Validates a URL string\n */\nfunction isValidUrl(url: string): boolean {\n\ttry {\n\t\tconst parsed = new URL(url)\n\t\treturn parsed.protocol === 'http:' || parsed.protocol === 'https:'\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport class AmadeusClient {\n\tprivate config: Required<AmadeusSDKConfig>\n\tprivate abortController: AbortController | null = null\n\n\t/**\n\t * Create a new AmadeusClient instance\n\t *\n\t * @param config - SDK configuration\n\t * @throws {AmadeusSDKError} If baseUrl is invalid\n\t */\n\tconstructor(config: AmadeusSDKConfig) {\n\t\tconst baseUrl = config.baseUrl || NODE_API_URL\n\n\t\tif (!isValidUrl(baseUrl)) {\n\t\t\tthrow new AmadeusSDKError(\n\t\t\t\t`Invalid baseUrl: ${baseUrl}. Must be a valid HTTP/HTTPS URL.`\n\t\t\t)\n\t\t}\n\n\t\t// Ensure baseUrl doesn't end with a slash\n\t\tconst normalizedBaseUrl = baseUrl.replace(/\\/+$/, '')\n\n\t\tthis.config = {\n\t\t\tbaseUrl: normalizedBaseUrl,\n\t\t\ttimeout: config.timeout && config.timeout > 0 ? config.timeout : DEFAULT_TIMEOUT,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/octet-stream',\n\t\t\t\t'X-Client-Type': `@amadeus-protocol/sdk/${SDK_VERSION}`,\n\t\t\t\t...config.headers\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Make a GET request\n\t *\n\t * @param endpoint - API endpoint path\n\t * @param params - Optional query parameters\n\t * @returns Promise resolving to the response data\n\t */\n\tasync get<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<T> {\n\t\tvalidate(NonEmptyStringSchema, endpoint)\n\n\t\tconst url = this.buildUrl(endpoint, params)\n\t\tconst response = await this.request(url, {\n\t\t\tmethod: 'GET'\n\t\t})\n\t\treturn this.handleResponse(response) as Promise<T>\n\t}\n\n\t/**\n\t * Make a POST request\n\t *\n\t * @param endpoint - API endpoint path\n\t * @param data - Request body data (Uint8Array for binary, object for JSON)\n\t * @returns Promise resolving to the response data\n\t */\n\tasync post<T = unknown>(endpoint: string, data?: unknown): Promise<T> {\n\t\tvalidate(NonEmptyStringSchema, endpoint)\n\n\t\tconst url = this.buildUrl(endpoint)\n\t\tconst { body, contentType } = this.prepareBody(data)\n\n\t\tconst response = await this.request(url, {\n\t\t\tmethod: 'POST',\n\t\t\tbody,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': contentType\n\t\t\t}\n\t\t})\n\t\treturn this.handleResponse(response) as Promise<T>\n\t}\n\n\t/**\n\t * Build full URL with query parameters\n\t */\n\tprivate buildUrl(endpoint: string, params?: Record<string, unknown>): string {\n\t\tconst url = new URL(endpoint, this.config.baseUrl)\n\n\t\tif (params) {\n\t\t\tfor (const [key, value] of Object.entries(params)) {\n\t\t\t\tif (value !== undefined && value !== null) {\n\t\t\t\t\turl.searchParams.append(key, String(value))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn url.toString()\n\t}\n\n\t/**\n\t * Prepare request body and determine Content-Type\n\t */\n\tprivate prepareBody(data?: unknown): { body: BodyInit | undefined; contentType: string } {\n\t\tif (!data) {\n\t\t\treturn { body: undefined, contentType: 'application/octet-stream' }\n\t\t}\n\n\t\t// If it's already a Uint8Array or ArrayBuffer, send as binary\n\t\tif (data instanceof Uint8Array) {\n\t\t\treturn { body: data as BodyInit, contentType: 'application/octet-stream' }\n\t\t}\n\t\tif (data instanceof ArrayBuffer) {\n\t\t\treturn { body: data as BodyInit, contentType: 'application/octet-stream' }\n\t\t}\n\n\t\t// If it's a Buffer (Node.js), convert to Uint8Array\n\t\tif (typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) {\n\t\t\treturn {\n\t\t\t\tbody: new Uint8Array(data) as BodyInit,\n\t\t\t\tcontentType: 'application/octet-stream'\n\t\t\t}\n\t\t}\n\n\t\t// For objects, try to send as binary if it has txPacked or tx_packed\n\t\tif (typeof data === 'object' && data !== null) {\n\t\t\tconst obj = data as Record<string, unknown>\n\t\t\tif ('txPacked' in obj && obj.txPacked instanceof Uint8Array) {\n\t\t\t\treturn { body: obj.txPacked as BodyInit, contentType: 'application/octet-stream' }\n\t\t\t}\n\t\t\tif ('tx_packed' in obj && obj.tx_packed instanceof Uint8Array) {\n\t\t\t\treturn { body: obj.tx_packed as BodyInit, contentType: 'application/octet-stream' }\n\t\t\t}\n\t\t}\n\n\t\t// Default: send as JSON\n\t\treturn { body: JSON.stringify(data), contentType: 'application/json' }\n\t}\n\n\t/**\n\t * Make HTTP request with timeout\n\t */\n\tprivate async request(url: string, options: RequestInit): Promise<Response> {\n\t\t// Cancel previous request if any\n\t\tif (this.abortController) {\n\t\t\tthis.abortController.abort()\n\t\t}\n\n\t\tthis.abortController = new AbortController()\n\t\tconst timeoutId = setTimeout(() => {\n\t\t\tthis.abortController?.abort()\n\t\t}, this.config.timeout)\n\n\t\ttry {\n\t\t\tconst response = await fetch(url, {\n\t\t\t\t...options,\n\t\t\t\theaders: {\n\t\t\t\t\t...this.config.headers,\n\t\t\t\t\t...options.headers\n\t\t\t\t},\n\t\t\t\tsignal: this.abortController.signal\n\t\t\t})\n\n\t\t\tclearTimeout(timeoutId)\n\t\t\treturn response\n\t\t} catch (error) {\n\t\t\tclearTimeout(timeoutId)\n\t\t\tif (error instanceof Error) {\n\t\t\t\tif (error.name === 'AbortError' || error.name === 'TimeoutError') {\n\t\t\t\t\tthrow new AmadeusSDKError(`Request timeout after ${this.config.timeout}ms`, 408)\n\t\t\t\t}\n\t\t\t\tthrow new AmadeusSDKError(\n\t\t\t\t\t`Request failed: ${error.message}`,\n\t\t\t\t\t0,\n\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t? { message: error.message, name: error.name }\n\t\t\t\t\t\t: { error: String(error) }\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new AmadeusSDKError(`Request failed: ${String(error)}`, 0, {\n\t\t\t\terror: String(error)\n\t\t\t})\n\t\t}\n\t}\n\n\t/**\n\t * Handle API response and parse errors\n\t */\n\tprivate async handleResponse(response: Response): Promise<unknown> {\n\t\tif (!response.ok) {\n\t\t\tlet errorData: unknown\n\t\t\tconst contentType = response.headers.get('content-type')\n\n\t\t\ttry {\n\t\t\t\tif (contentType?.includes('application/json')) {\n\t\t\t\t\terrorData = await response.json()\n\t\t\t\t} else {\n\t\t\t\t\tconst text = await response.text()\n\t\t\t\t\t// If it's HTML, try to extract a meaningful error message\n\t\t\t\t\tif (contentType?.includes('text/html')) {\n\t\t\t\t\t\t// Try to extract title or error message from HTML\n\t\t\t\t\t\tconst titleMatch = text.match(/<title>([^<]+)<\\/title>/i)\n\t\t\t\t\t\tconst h1Match = text.match(/<h1[^>]*>([^<]+)<\\/h1>/i)\n\t\t\t\t\t\terrorData =\n\t\t\t\t\t\t\ttitleMatch?.[1] || h1Match?.[1] || `HTTP ${response.status} Error`\n\t\t\t\t\t} else {\n\t\t\t\t\t\terrorData = text\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (parseError) {\n\t\t\t\terrorData = `Failed to parse error response: ${\n\t\t\t\t\tparseError instanceof Error ? parseError.message : String(parseError)\n\t\t\t\t}`\n\t\t\t}\n\n\t\t\tconst message =\n\t\t\t\ttypeof errorData === 'object' && errorData !== null && 'error' in errorData\n\t\t\t\t\t? String((errorData as { error: unknown }).error)\n\t\t\t\t\t: typeof errorData === 'string'\n\t\t\t\t\t\t? errorData.length > 500\n\t\t\t\t\t\t\t? `${errorData.substring(0, 500)}... (truncated)`\n\t\t\t\t\t\t\t: errorData\n\t\t\t\t\t\t: response.statusText || 'Unknown error'\n\n\t\t\tthrow new AmadeusSDKError(\n\t\t\t\t`HTTP ${response.status}: ${message}`,\n\t\t\t\tresponse.status,\n\t\t\t\terrorData as Record<string, unknown>\n\t\t\t)\n\t\t}\n\n\t\tconst contentType = response.headers.get('content-type')\n\t\tlet data: unknown\n\n\t\ttry {\n\t\t\tif (contentType?.includes('application/json')) {\n\t\t\t\tdata = await response.json()\n\t\t\t} else {\n\t\t\t\t// Try JSON first, fallback to text\n\t\t\t\tconst text = await response.text()\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse(text)\n\t\t\t\t} catch {\n\t\t\t\t\tdata = text\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (parseError) {\n\t\t\tthrow new AmadeusSDKError(\n\t\t\t\t`Failed to parse response: ${parseError instanceof Error ? parseError.message : String(parseError)}`,\n\t\t\t\tresponse.status\n\t\t\t)\n\t\t}\n\n\t\t// Handle API response format\n\t\tif (typeof data === 'object' && data !== null && 'error' in data) {\n\t\t\tconst apiResponse = data as ApiResponse\n\t\t\tif (apiResponse.error === 'ok') {\n\t\t\t\t// Remove error property from response (intentionally unused)\n\t\t\t\tconst { error: _error, ...rest } = apiResponse\n\t\t\t\treturn rest\n\t\t\t} else if (apiResponse.error === 'not_found') {\n\t\t\t\tthrow new AmadeusSDKError(\n\t\t\t\t\t'Resource not found',\n\t\t\t\t\t404,\n\t\t\t\t\tapiResponse as Record<string, unknown>\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tthrow new AmadeusSDKError(\n\t\t\t\t\tapiResponse.error || 'Unknown API error',\n\t\t\t\t\t400,\n\t\t\t\t\tapiResponse as Record<string, unknown>\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn data\n\t}\n\n\t/**\n\t * Get current configuration\n\t */\n\tgetConfig(): AmadeusSDKConfig {\n\t\treturn { ...this.config }\n\t}\n\n\t/**\n\t * Update base URL\n\t *\n\t * @param url - New base URL\n\t * @throws {AmadeusSDKError} If URL is invalid\n\t */\n\tsetBaseUrl(url: string): void {\n\t\tif (!isValidUrl(url)) {\n\t\t\tthrow new AmadeusSDKError(`Invalid baseUrl: ${url}. Must be a valid HTTP/HTTPS URL.`)\n\t\t}\n\t\tthis.config.baseUrl = url.replace(/\\/+$/, '')\n\t}\n\n\t/**\n\t * Update headers\n\t */\n\tsetHeaders(headers: Record<string, string>): void {\n\t\tthis.config.headers = { ...this.config.headers, ...headers }\n\t}\n\n\t/**\n\t * Cancel ongoing requests\n\t */\n\tcancel(): void {\n\t\tif (this.abortController) {\n\t\t\tthis.abortController.abort()\n\t\t\tthis.abortController = null\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;AAgBA,SAAS,WAAW,KAAsB;CACzC,IAAI;EACH,MAAM,SAAS,IAAI,IAAI,IAAI;EAC3B,OAAO,OAAO,aAAa,WAAW,OAAO,aAAa;SACnD;EACP,OAAO;;;AAIT,IAAa,gBAAb,MAA2B;CAC1B;CACA,kBAAkD;;;;;;;CAQlD,YAAY,QAA0B;EACrC,MAAM,UAAU,OAAO,WAAA;EAEvB,IAAI,CAAC,WAAW,QAAQ,EACvB,MAAM,IAAI,gBACT,oBAAoB,QAAQ,mCAC5B;EAIF,MAAM,oBAAoB,QAAQ,QAAQ,QAAQ,GAAG;EAErD,KAAK,SAAS;GACb,SAAS;GACT,SAAS,OAAO,WAAW,OAAO,UAAU,IAAI,OAAO,UAAU;GACjE,SAAS;IACR,gBAAgB;IAChB,iBAAiB,yBAAyB;IAC1C,GAAG,OAAO;IACV;GACD;;;;;;;;;CAUF,MAAM,IAAiB,UAAkB,QAA8C;EACtF,SAAS,sBAAsB,SAAS;EAExC,MAAM,MAAM,KAAK,SAAS,UAAU,OAAO;EAC3C,MAAM,WAAW,MAAM,KAAK,QAAQ,KAAK,EACxC,QAAQ,OACR,CAAC;EACF,OAAO,KAAK,eAAe,SAAS;;;;;;;;;CAUrC,MAAM,KAAkB,UAAkB,MAA4B;EACrE,SAAS,sBAAsB,SAAS;EAExC,MAAM,MAAM,KAAK,SAAS,SAAS;EACnC,MAAM,EAAE,MAAM,gBAAgB,KAAK,YAAY,KAAK;EAEpD,MAAM,WAAW,MAAM,KAAK,QAAQ,KAAK;GAC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
*
|
|
@@ -6,41 +7,43 @@
|
|
|
6
7
|
/**
|
|
7
8
|
* SDK version
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
declare const SDK_VERSION = "1.0.0";
|
|
10
11
|
/**
|
|
11
12
|
* Byte length of an Amadeus public key (BLS12-381 public key)
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
declare const AMADEUS_PUBLIC_KEY_BYTE_LENGTH = 48;
|
|
14
15
|
/**
|
|
15
16
|
* Byte length of an Amadeus seed (private key seed)
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
declare const AMADEUS_SEED_BYTE_LENGTH = 64;
|
|
18
19
|
/**
|
|
19
20
|
* Number of decimal places for AMA token
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
declare const AMA_TOKEN_DECIMALS = 9;
|
|
22
23
|
/**
|
|
23
24
|
* Multiplier for converting between atomic units and AMA tokens
|
|
24
25
|
*/
|
|
25
|
-
|
|
26
|
+
declare const AMA_TOKEN_DECIMALS_MULTIPLIER: number;
|
|
26
27
|
/**
|
|
27
28
|
* Minimum transferable amount in AMA (1 atomic unit)
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
+
declare const MIN_TRANSFERABLE_AMOUNT: number;
|
|
30
31
|
/**
|
|
31
32
|
* Flat network transfer fee in AMA for standard transfers
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
|
+
declare const AMA_TRANSFER_FEE = 0.02;
|
|
34
35
|
/**
|
|
35
36
|
* Default explorer URL
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
declare const EXPLORER_URL = "https://explorer.ama.one";
|
|
38
39
|
/**
|
|
39
40
|
* Default node API URL
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
declare const NODE_API_URL = "https://mainnet-rpc.ama.one/api";
|
|
42
43
|
/**
|
|
43
44
|
* Default request timeout in milliseconds
|
|
44
45
|
*/
|
|
45
|
-
|
|
46
|
+
declare const DEFAULT_TIMEOUT = 30000;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { AMADEUS_PUBLIC_KEY_BYTE_LENGTH, AMADEUS_SEED_BYTE_LENGTH, AMA_TOKEN_DECIMALS, AMA_TOKEN_DECIMALS_MULTIPLIER, AMA_TRANSFER_FEE, DEFAULT_TIMEOUT, EXPLORER_URL, MIN_TRANSFERABLE_AMOUNT, NODE_API_URL, SDK_VERSION };
|
|
46
49
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","
|
|
1
|
+
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;AASA;;;;;AAKA;;cALa,WAAA;;;AAUb;cALa,8BAAA;;;;cAKA,wBAAA;;;;cAKA,kBAAA;AAKb;;;AAAA,cAAa,6BAAA;;AAKb;;cAAa,uBAAA;;;AAKb;cAAa,gBAAA;;;;cAKA,YAAA;;;;cAKA,YAAA;AAAb;;;AAAA,cAKa,eAAA"}
|