@avalabs/glacier-sdk 2.4.1-alpha.5 → 2.4.1-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +252 -0
- package/package.json +6 -6
package/dist/index.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/*! *****************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
|
|
20
|
+
function __rest(s, e) {
|
|
21
|
+
var t = {};
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
23
|
+
t[p] = s[p];
|
|
24
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
25
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
26
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
27
|
+
t[p[i]] = s[p[i]];
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* eslint-disable */
|
|
43
|
+
var ContentType;
|
|
44
|
+
(function (ContentType) {
|
|
45
|
+
ContentType["Json"] = "application/json";
|
|
46
|
+
ContentType["FormData"] = "multipart/form-data";
|
|
47
|
+
ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
|
|
48
|
+
})(ContentType || (ContentType = {}));
|
|
49
|
+
class HttpClient {
|
|
50
|
+
constructor(apiConfig = {}) {
|
|
51
|
+
this.baseUrl = '';
|
|
52
|
+
this.securityData = null;
|
|
53
|
+
this.abortControllers = new Map();
|
|
54
|
+
this.customFetch = (...fetchParams) => fetch(...fetchParams);
|
|
55
|
+
this.baseApiParams = {
|
|
56
|
+
credentials: 'same-origin',
|
|
57
|
+
headers: {},
|
|
58
|
+
redirect: 'follow',
|
|
59
|
+
referrerPolicy: 'no-referrer',
|
|
60
|
+
};
|
|
61
|
+
this.setSecurityData = (data) => {
|
|
62
|
+
this.securityData = data;
|
|
63
|
+
};
|
|
64
|
+
this.contentFormatters = {
|
|
65
|
+
[ContentType.Json]: (input) => input !== null && (typeof input === 'object' || typeof input === 'string')
|
|
66
|
+
? JSON.stringify(input)
|
|
67
|
+
: input,
|
|
68
|
+
[ContentType.FormData]: (input) => Object.keys(input || {}).reduce((formData, key) => {
|
|
69
|
+
const property = input[key];
|
|
70
|
+
formData.append(key, property instanceof Blob
|
|
71
|
+
? property
|
|
72
|
+
: typeof property === 'object' && property !== null
|
|
73
|
+
? JSON.stringify(property)
|
|
74
|
+
: `${property}`);
|
|
75
|
+
return formData;
|
|
76
|
+
}, new FormData()),
|
|
77
|
+
[ContentType.UrlEncoded]: (input) => this.toQueryString(input),
|
|
78
|
+
};
|
|
79
|
+
this.createAbortSignal = (cancelToken) => {
|
|
80
|
+
if (this.abortControllers.has(cancelToken)) {
|
|
81
|
+
const abortController = this.abortControllers.get(cancelToken);
|
|
82
|
+
if (abortController) {
|
|
83
|
+
return abortController.signal;
|
|
84
|
+
}
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const abortController = new AbortController();
|
|
88
|
+
this.abortControllers.set(cancelToken, abortController);
|
|
89
|
+
return abortController.signal;
|
|
90
|
+
};
|
|
91
|
+
this.abortRequest = (cancelToken) => {
|
|
92
|
+
const abortController = this.abortControllers.get(cancelToken);
|
|
93
|
+
if (abortController) {
|
|
94
|
+
abortController.abort();
|
|
95
|
+
this.abortControllers.delete(cancelToken);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
this.request = (_a) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
var { body, secure, path, type, query, format, baseUrl, cancelToken } = _a, params = __rest(_a, ["body", "secure", "path", "type", "query", "format", "baseUrl", "cancelToken"]);
|
|
100
|
+
const secureParams = ((typeof secure === 'boolean' ? secure : this.baseApiParams.secure) &&
|
|
101
|
+
this.securityWorker &&
|
|
102
|
+
(yield this.securityWorker(this.securityData))) ||
|
|
103
|
+
{};
|
|
104
|
+
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
105
|
+
const queryString = query && this.toQueryString(query);
|
|
106
|
+
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
|
|
107
|
+
const responseFormat = format || requestParams.format;
|
|
108
|
+
return this.customFetch(`${baseUrl || this.baseUrl || ''}${path}${queryString ? `?${queryString}` : ''}`, Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (type && type !== ContentType.FormData
|
|
109
|
+
? { 'Content-Type': type }
|
|
110
|
+
: {})), (requestParams.headers || {})), signal: cancelToken ? this.createAbortSignal(cancelToken) : void 0, body: typeof body === 'undefined' || body === null
|
|
111
|
+
? null
|
|
112
|
+
: payloadFormatter(body) })).then((response) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const r = response;
|
|
114
|
+
r.data = null;
|
|
115
|
+
r.error = null;
|
|
116
|
+
const data = !responseFormat
|
|
117
|
+
? r
|
|
118
|
+
: yield response[responseFormat]()
|
|
119
|
+
.then((data) => {
|
|
120
|
+
if (r.ok) {
|
|
121
|
+
r.data = data;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
r.error = data;
|
|
125
|
+
}
|
|
126
|
+
return r;
|
|
127
|
+
})
|
|
128
|
+
.catch((e) => {
|
|
129
|
+
r.error = e;
|
|
130
|
+
return r;
|
|
131
|
+
});
|
|
132
|
+
if (cancelToken) {
|
|
133
|
+
this.abortControllers.delete(cancelToken);
|
|
134
|
+
}
|
|
135
|
+
if (!response.ok)
|
|
136
|
+
throw data;
|
|
137
|
+
return data;
|
|
138
|
+
}));
|
|
139
|
+
});
|
|
140
|
+
Object.assign(this, apiConfig);
|
|
141
|
+
}
|
|
142
|
+
encodeQueryParam(key, value) {
|
|
143
|
+
const encodedKey = encodeURIComponent(key);
|
|
144
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === 'number' ? value : `${value}`)}`;
|
|
145
|
+
}
|
|
146
|
+
addQueryParam(query, key) {
|
|
147
|
+
return this.encodeQueryParam(key, query[key]);
|
|
148
|
+
}
|
|
149
|
+
addArrayQueryParam(query, key) {
|
|
150
|
+
const value = query[key];
|
|
151
|
+
return value.map((v) => this.encodeQueryParam(key, v)).join('&');
|
|
152
|
+
}
|
|
153
|
+
toQueryString(rawQuery) {
|
|
154
|
+
const query = rawQuery || {};
|
|
155
|
+
const keys = Object.keys(query).filter((key) => 'undefined' !== typeof query[key]);
|
|
156
|
+
return keys
|
|
157
|
+
.map((key) => Array.isArray(query[key])
|
|
158
|
+
? this.addArrayQueryParam(query, key)
|
|
159
|
+
: this.addQueryParam(query, key))
|
|
160
|
+
.join('&');
|
|
161
|
+
}
|
|
162
|
+
addQueryParams(rawQuery) {
|
|
163
|
+
const queryString = this.toQueryString(rawQuery);
|
|
164
|
+
return queryString ? `?${queryString}` : '';
|
|
165
|
+
}
|
|
166
|
+
mergeRequestParams(params1, params2) {
|
|
167
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, this.baseApiParams), params1), (params2 || {})), { headers: Object.assign(Object.assign(Object.assign({}, (this.baseApiParams.headers || {})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* eslint-disable */
|
|
172
|
+
class V1 extends HttpClient {
|
|
173
|
+
constructor() {
|
|
174
|
+
super(...arguments);
|
|
175
|
+
/**
|
|
176
|
+
* No description
|
|
177
|
+
*
|
|
178
|
+
* @name HealthCheck
|
|
179
|
+
* @summary Get the health of the service.
|
|
180
|
+
* @request GET:/v1/health-check
|
|
181
|
+
* @response `200` `{ status?: string, info?: Record<string, { status?: string }>, error?: Record<string, { status?: string }>, details?: Record<string, { status?: string }> }` The Health Check is successful
|
|
182
|
+
* @response `503` `{ status?: string, info?: Record<string, { status?: string }>, error?: Record<string, { status?: string }>, details?: Record<string, { status?: string }> }` The Health Check is not successful
|
|
183
|
+
*/
|
|
184
|
+
this.healthCheck = (params = {}) => this.request(Object.assign({ path: `/v1/health-check`, method: 'GET', format: 'json' }, params));
|
|
185
|
+
/**
|
|
186
|
+
* No description
|
|
187
|
+
*
|
|
188
|
+
* @name GetNativeBalance
|
|
189
|
+
* @summary Get native token balance of a wallet address for a given chain.
|
|
190
|
+
* @request GET:/v1/chains/{chainId}/addresses/{address}/balances:getNative
|
|
191
|
+
* @response `200` `NativeBalanceDto`
|
|
192
|
+
*/
|
|
193
|
+
this.getNativeBalance = (chainId, address, query, params = {}) => this.request(Object.assign({ path: `/v1/chains/${chainId}/addresses/${address}/balances:getNative`, method: 'GET', query: query, format: 'json' }, params));
|
|
194
|
+
/**
|
|
195
|
+
* No description
|
|
196
|
+
*
|
|
197
|
+
* @name ListErc20Balances
|
|
198
|
+
* @summary Get erc-20 token balances of a wallet address for a given chain.
|
|
199
|
+
* @request GET:/v1/chains/{chainId}/addresses/{address}/balances:listErc20
|
|
200
|
+
* @response `200` `Erc20BalancesDto`
|
|
201
|
+
*/
|
|
202
|
+
this.listErc20Balances = (chainId, address, query, params = {}) => this.request(Object.assign({ path: `/v1/chains/${chainId}/addresses/${address}/balances:listErc20`, method: 'GET', query: query, format: 'json' }, params));
|
|
203
|
+
/**
|
|
204
|
+
* No description
|
|
205
|
+
*
|
|
206
|
+
* @name ListErc721Balances
|
|
207
|
+
* @summary Get erc-721 token balances of a wallet address for a given chain.
|
|
208
|
+
* @request GET:/v1/chains/{chainId}/addresses/{address}/balances:listErc721
|
|
209
|
+
* @response `200` `Erc721BalancesDto`
|
|
210
|
+
*/
|
|
211
|
+
this.listErc721Balances = (chainId, address, query, params = {}) => this.request(Object.assign({ path: `/v1/chains/${chainId}/addresses/${address}/balances:listErc721`, method: 'GET', query: query, format: 'json' }, params));
|
|
212
|
+
/**
|
|
213
|
+
* @description Gets a list of transactions where the given wallet address had an on-chain interaction for a given chain. The erc20 transfers, erc721 transfers, and internal transactions returned as part of the native transactions are only those where the address had an interaction. Therefore the transactions returned from this list may not be complete representations of the on-chain data. For a complete view of a transaction use the `/chains/:chainId/transactions/:txHash` endpoint.
|
|
214
|
+
*
|
|
215
|
+
* @name ListTransactions
|
|
216
|
+
* @summary Gets a list of transactions for a wallet address and chain.
|
|
217
|
+
* @request GET:/v1/chains/{chainId}/addresses/{address}/transactions
|
|
218
|
+
* @response `200` `ListTransactionDetailsDto`
|
|
219
|
+
*/
|
|
220
|
+
this.listTransactions = (chainId, address, query, params = {}) => this.request(Object.assign({ path: `/v1/chains/${chainId}/addresses/${address}/transactions`, method: 'GET', query: query, format: 'json' }, params));
|
|
221
|
+
/**
|
|
222
|
+
* No description
|
|
223
|
+
*
|
|
224
|
+
* @name GetTransaction
|
|
225
|
+
* @summary Gets the details of a single transaction.
|
|
226
|
+
* @request GET:/v1/chains/{chainId}/transactions/{txHash}
|
|
227
|
+
* @response `200` `TransactionDetailsDto`
|
|
228
|
+
*/
|
|
229
|
+
this.getTransaction = (chainId, txHash, params = {}) => this.request(Object.assign({ path: `/v1/chains/${chainId}/transactions/${txHash}`, method: 'GET', format: 'json' }, params));
|
|
230
|
+
/**
|
|
231
|
+
* No description
|
|
232
|
+
*
|
|
233
|
+
* @name SupportedChains
|
|
234
|
+
* @summary Gets the list of chains supported by the api.
|
|
235
|
+
* @request GET:/v1/chains
|
|
236
|
+
* @response `200` `ChainsDto`
|
|
237
|
+
*/
|
|
238
|
+
this.supportedChains = (params = {}) => this.request(Object.assign({ path: `/v1/chains`, method: 'GET', format: 'json' }, params));
|
|
239
|
+
/**
|
|
240
|
+
* No description
|
|
241
|
+
*
|
|
242
|
+
* @name GetChainInfo
|
|
243
|
+
* @summary Gets chain information by chain id.
|
|
244
|
+
* @request GET:/v1/chains/{chainId}
|
|
245
|
+
* @response `200` `ChainInfoDto`
|
|
246
|
+
*/
|
|
247
|
+
this.getChainInfo = (chainId, params = {}) => this.request(Object.assign({ path: `/v1/chains/${chainId}`, method: 'GET', format: 'json' }, params));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
exports.V1 = V1;
|
|
252
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avalabs/glacier-sdk",
|
|
3
|
-
"version": "2.4.1-alpha.
|
|
3
|
+
"version": "2.4.1-alpha.6",
|
|
4
4
|
"description": "sdk for interacting with glacier-api",
|
|
5
5
|
"author": "Oliver Wang <oliver.wang@avalabs.org>",
|
|
6
6
|
"homepage": "https://github.com/ava-labs/avalanche-sdks#readme",
|
|
7
7
|
"license": "ISC",
|
|
8
|
-
"main": "
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"typings": "dist/index.d.ts",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "restricted"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@rollup/plugin-json": "^4.1.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"bugs": {
|
|
39
39
|
"url": "https://github.com/ava-labs/avalanche-sdks/issues"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "8ff8f24fa70c9fd74ee933eb15f13339f2f696ce"
|
|
42
42
|
}
|