@amadeus-protocol/sdk 1.0.8 → 1.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/README.md +215 -30
- 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 -55
- package/dist/index.js +39 -55
- package/dist/mnemonic.d.ts +12 -9
- package/dist/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic.js +105 -114
- package/dist/mnemonic.js.map +1 -1
- 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 +4 -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.d.ts
CHANGED
|
@@ -1,70 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Cancel ongoing requests
|
|
67
|
-
*/
|
|
68
|
-
cancel(): void;
|
|
1
|
+
import { AmadeusSDKConfig } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/client.d.ts
|
|
4
|
+
declare class AmadeusClient {
|
|
5
|
+
private config;
|
|
6
|
+
private abortController;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new AmadeusClient instance
|
|
9
|
+
*
|
|
10
|
+
* @param config - SDK configuration
|
|
11
|
+
* @throws {AmadeusSDKError} If baseUrl is invalid
|
|
12
|
+
*/
|
|
13
|
+
constructor(config: AmadeusSDKConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Make a GET request
|
|
16
|
+
*
|
|
17
|
+
* @param endpoint - API endpoint path
|
|
18
|
+
* @param params - Optional query parameters
|
|
19
|
+
* @returns Promise resolving to the response data
|
|
20
|
+
*/
|
|
21
|
+
get<T = unknown>(endpoint: string, params?: Record<string, unknown>): Promise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Make a POST request
|
|
24
|
+
*
|
|
25
|
+
* @param endpoint - API endpoint path
|
|
26
|
+
* @param data - Request body data (Uint8Array for binary, object for JSON)
|
|
27
|
+
* @returns Promise resolving to the response data
|
|
28
|
+
*/
|
|
29
|
+
post<T = unknown>(endpoint: string, data?: unknown): Promise<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Build full URL with query parameters
|
|
32
|
+
*/
|
|
33
|
+
private buildUrl;
|
|
34
|
+
/**
|
|
35
|
+
* Prepare request body and determine Content-Type
|
|
36
|
+
*/
|
|
37
|
+
private prepareBody;
|
|
38
|
+
/**
|
|
39
|
+
* Make HTTP request with timeout
|
|
40
|
+
*/
|
|
41
|
+
private request;
|
|
42
|
+
/**
|
|
43
|
+
* Handle API response and parse errors
|
|
44
|
+
*/
|
|
45
|
+
private handleResponse;
|
|
46
|
+
/**
|
|
47
|
+
* Get current configuration
|
|
48
|
+
*/
|
|
49
|
+
getConfig(): AmadeusSDKConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Update base URL
|
|
52
|
+
*
|
|
53
|
+
* @param url - New base URL
|
|
54
|
+
* @throws {AmadeusSDKError} If URL is invalid
|
|
55
|
+
*/
|
|
56
|
+
setBaseUrl(url: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Update headers
|
|
59
|
+
*/
|
|
60
|
+
setHeaders(headers: Record<string, string>): void;
|
|
61
|
+
/**
|
|
62
|
+
* Cancel ongoing requests
|
|
63
|
+
*/
|
|
64
|
+
cancel(): void;
|
|
69
65
|
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { AmadeusClient };
|
|
70
68
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","
|
|
1
|
+
{"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;;cAyBa,aAAA;EAAA,QACJ,MAAA;EAAA,QACA,eAAA;EAuD2D;;;;;;cA/CvD,MAAA,EAAQ,gBAAA;EARZ;;;;;;;EAsCF,GAAA,aAAA,CAAiB,QAAA,UAAkB,MAAA,GAAS,MAAA,oBAA0B,OAAA,CAAQ,CAAA;EAA3C;;;;;;;EAiBnC,IAAA,aAAA,CAAkB,QAAA,UAAkB,IAAA,aAAiB,OAAA,CAAQ,CAAA;EAAA;;;EAAA,QAmB3D,QAAA;EAsGM;;;EAAA,QArFN,WAAA;EA4LG;;;EAAA,QArJG,OAAA;EAsKd;;;EAAA,QAxHc,cAAA;;;;EA6Fd,SAAA,CAAA,GAAa,gBAAA;;;;;;;EAUb,UAAA,CAAW,GAAA;;;;EAUX,UAAA,CAAW,OAAA,EAAS,MAAA;;;;EAOpB,MAAA,CAAA;AAAA"}
|
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
|