@avalabs/glacier-sdk 2.8.0-alpha.79 → 2.8.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,190 @@
1
+ import { HttpClient, HttpOptions } from '@avalabs/utils-sdk';
2
+ import {
3
+ ChainInfo,
4
+ Chains,
5
+ CurrencyCode,
6
+ Erc20Balances,
7
+ Erc721Balances,
8
+ ListTransactionDetails,
9
+ NativeBalance,
10
+ TransactionDetails,
11
+ } from './generated/models';
12
+ import { HealthStatusCheck } from './types';
13
+
14
+ export class GlacierClient {
15
+ private httpClient: HttpClient;
16
+ constructor(
17
+ private baseUrl: string,
18
+ private version = 'v1',
19
+ private httpOptions?: HttpOptions
20
+ ) {
21
+ this.httpClient = new HttpClient(
22
+ `${this.baseUrl}/${this.version}`,
23
+ this.httpOptions
24
+ );
25
+ }
26
+ /**
27
+ *
28
+ * @name HealthCheck
29
+ * @summary Get the health of the service.
30
+ * @request GET:/${version}/health-check
31
+ * @response `200` `{ status?: string, info?: Record<string, { status?: string }>, error?: Record<string, { status?: string }>, details?: Record<string, { status?: string }> }` The Health Check is successful
32
+ * @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
33
+ */
34
+ healthCheck(
35
+ params: Record<string, any> = {},
36
+ customOptions: HttpOptions = {}
37
+ ) {
38
+ return this.httpClient.get<HealthStatusCheck>(
39
+ `/health-check`,
40
+ params,
41
+ customOptions
42
+ );
43
+ }
44
+
45
+ /**
46
+ * No description
47
+ *
48
+ * @name GetNativeBalance
49
+ * @summary Get native token balance of a wallet address for a given chain.
50
+ * @request GET:/v1/chains/{chainId}/addresses/{address}/balances:getNative
51
+ * @response `200` `NativeBalanceDto`
52
+ */
53
+ getNativeBalance(
54
+ chainId: string,
55
+ address: string,
56
+ query?: {
57
+ currency?: CurrencyCode;
58
+ },
59
+ params: Record<string, any> = {},
60
+ customOptions: HttpOptions = {}
61
+ ) {
62
+ return this.httpClient.get<NativeBalance>(
63
+ `/chains/${chainId}/addresses/${address}/balances:getNative`,
64
+ { ...query, ...params },
65
+ customOptions
66
+ );
67
+ }
68
+ /**
69
+ *
70
+ * @name ListErc20Balances
71
+ * @summary Get erc-20 token balances of a wallet address for a given chain.
72
+ * @request GET:/v1/chains/{chainId}/addresses/{address}/balances:listErc20
73
+ * @response `200` `Erc20BalancesDto`
74
+ */
75
+ listErc20Balances(
76
+ chainId: string,
77
+ address: string,
78
+ query?: {
79
+ pageSize?: number;
80
+ pageToken?: string;
81
+ currency?: CurrencyCode;
82
+ },
83
+ params: Record<string, any> = {},
84
+ customOptions: HttpOptions = {}
85
+ ) {
86
+ return this.httpClient.get<Erc20Balances>(
87
+ `/chains/${chainId}/addresses/${address}/balances:listErc20`,
88
+ { ...query, ...params },
89
+ customOptions
90
+ );
91
+ }
92
+ /**
93
+ * No description
94
+ *
95
+ * @name ListErc721Balances
96
+ * @summary Get erc-721 token balances of a wallet address for a given chain.
97
+ * @request GET:/v1/chains/{chainId}/addresses/{address}/balances:listErc721
98
+ * @response `200` `Erc721BalancesDto`
99
+ */
100
+ listErc721Balances(
101
+ chainId: string,
102
+ address: string,
103
+ query?: {
104
+ pageSize?: number;
105
+ pageToken?: string;
106
+ currency?: CurrencyCode;
107
+ },
108
+ params: Record<string, any> = {},
109
+ customOptions: HttpOptions = {}
110
+ ) {
111
+ return this.httpClient.get<Erc721Balances>(
112
+ `/chains/${chainId}/addresses/${address}/balances:listErc721`,
113
+ { ...query, ...params },
114
+ customOptions
115
+ );
116
+ }
117
+ /**
118
+ * @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.
119
+ *
120
+ * @name ListTransactions
121
+ * @summary Gets a list of transactions for a wallet address and chain.
122
+ * @request GET:/v1/chains/{chainId}/addresses/{address}/transactions
123
+ * @response `200` `ListTransactionDetailsDto`
124
+ */
125
+ listTransactions(
126
+ chainId: string,
127
+ address: string,
128
+ query?: { pageSize?: number; pageToken?: string },
129
+ params: Record<string, any> = {},
130
+ customOptions: HttpOptions = {}
131
+ ) {
132
+ return this.httpClient.get<ListTransactionDetails>(
133
+ `/chains/${chainId}/addresses/${address}/transactions`,
134
+ { ...query, ...params },
135
+ customOptions
136
+ );
137
+ }
138
+ /**
139
+ *
140
+ * @name GetTransaction
141
+ * @summary Gets the details of a single transaction.
142
+ * @request GET:/v1/chains/{chainId}/transactions/{txHash}
143
+ * @response `200` `TransactionDetailsDto`
144
+ */
145
+ getTransaction(
146
+ chainId: string,
147
+ txHash: string,
148
+ params: Record<string, any> = {},
149
+ customOptions: HttpOptions = {}
150
+ ) {
151
+ return this.httpClient.get<TransactionDetails>(
152
+ `/chains/${chainId}/transactions/${txHash}`,
153
+ params,
154
+ customOptions
155
+ );
156
+ }
157
+ /**
158
+ *
159
+ * @name SupportedChains
160
+ * @summary Gets the list of chains supported by the api.
161
+ * @request GET:/v1/chains
162
+ * @response `200` `ChainsDto`
163
+ */
164
+ supportedChains(
165
+ params: Record<string, any> = {},
166
+ customOptions: HttpOptions = {}
167
+ ) {
168
+ return this.httpClient.get<Chains>(`/chains`, params, customOptions);
169
+ }
170
+
171
+ /**
172
+ * No description
173
+ *
174
+ * @name GetChainInfo
175
+ * @summary Gets chain information by chain id.
176
+ * @request GET:/v1/chains/{chainId}
177
+ * @response `200` `ChainInfoDto`
178
+ */
179
+ getChainInfo(
180
+ chainId: string,
181
+ params: Record<string, any> = {},
182
+ customOptions: HttpOptions = {}
183
+ ) {
184
+ return this.httpClient.get<ChainInfo>(
185
+ `/chains/${chainId}`,
186
+ params,
187
+ customOptions
188
+ );
189
+ }
190
+ }
package/src/types.ts ADDED
@@ -0,0 +1,6 @@
1
+ export interface HealthStatusCheck {
2
+ status?: string;
3
+ info?: Record<string, { status?: string }>;
4
+ error?: Record<string, { status?: string }>;
5
+ details?: Record<string, { status?: string }>;
6
+ }
@@ -0,0 +1,40 @@
1
+ const { generateApi } = require('swagger-typescript-api');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ const SCHEMA_URL = 'https://glacier-api-dev.avax.network/api-json';
6
+
7
+ const OUTPUT_FOLDER = path.resolve(process.cwd(), 'src/generated');
8
+
9
+ const dataContractFilenames = { raw: 'data-contracts.ts', actual: 'models.ts' };
10
+
11
+ generateApi({
12
+ output: OUTPUT_FOLDER,
13
+ url: SCHEMA_URL,
14
+ modular: true,
15
+ generateClient: false,
16
+ generateResponses: false,
17
+ hooks: {
18
+ onFormatTypeName: (_typeName, rawTypeName) => {
19
+ // remove Dto suffix from type name
20
+ if (rawTypeName.includes('Dto')) {
21
+ return rawTypeName.replace(/Dto/g, '');
22
+ }
23
+ },
24
+ },
25
+ })
26
+ .then(({ files }) => {
27
+ files.forEach(({ name }) => {
28
+ if (name === dataContractFilenames.raw) {
29
+ // rename data contract file name
30
+ fs.rename(
31
+ path.resolve(OUTPUT_FOLDER, dataContractFilenames.raw),
32
+ path.resolve(OUTPUT_FOLDER, dataContractFilenames.actual),
33
+ () => {
34
+ // noop
35
+ }
36
+ );
37
+ }
38
+ });
39
+ })
40
+ .catch(console.error);
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "plugins": [{ "transform": "@zerollup/ts-transform-paths" }]
5
+ },
6
+ "include": ["src"]
7
+ }