@avalabs/glacier-sdk 2.8.0-canary.db60279.0 → 2.8.0-canary.db8f25f.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/index.d.ts CHANGED
@@ -23,15 +23,9 @@ interface OnCancel {
23
23
  (cancelHandler: () => void): void;
24
24
  }
25
25
  declare class CancelablePromise<T> implements Promise<T> {
26
- readonly [Symbol.toStringTag]: string;
27
- private _isResolved;
28
- private _isRejected;
29
- private _isCancelled;
30
- private readonly _cancelHandlers;
31
- private readonly _promise;
32
- private _resolve?;
33
- private _reject?;
26
+ #private;
34
27
  constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, onCancel: OnCancel) => void);
28
+ get [Symbol.toStringTag](): string;
35
29
  then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
36
30
  catch<TResult = never>(onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
37
31
  finally(onFinally?: (() => void) | null): Promise<T>;
@@ -46,11 +40,11 @@ type OpenAPIConfig = {
46
40
  VERSION: string;
47
41
  WITH_CREDENTIALS: boolean;
48
42
  CREDENTIALS: 'include' | 'omit' | 'same-origin';
49
- TOKEN?: string | Resolver<string>;
50
- USERNAME?: string | Resolver<string>;
51
- PASSWORD?: string | Resolver<string>;
52
- HEADERS?: Headers | Resolver<Headers>;
53
- ENCODE_PATH?: (path: string) => string;
43
+ TOKEN?: string | Resolver<string> | undefined;
44
+ USERNAME?: string | Resolver<string> | undefined;
45
+ PASSWORD?: string | Resolver<string> | undefined;
46
+ HEADERS?: Headers | Resolver<Headers> | undefined;
47
+ ENCODE_PATH?: ((path: string) => string) | undefined;
54
48
  };
55
49
  declare const OpenAPI: OpenAPIConfig;
56
50
 
@@ -2040,7 +2034,7 @@ declare enum PrimaryNetworkOperationType {
2040
2034
  }
2041
2035
 
2042
2036
  type PrimaryNetworkOptions = {
2043
- addresses: Array<string>;
2037
+ addresses?: Array<string>;
2044
2038
  cChainEvmAddresses?: Array<string>;
2045
2039
  includeChains: Array<'11111111111111111111111111111111LpoYY' | '2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM' | '2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm' | '2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5' | 'yH8D7ThNJkxmtkuv2jgBa4P1Rn3Qpr4pPr7QYNfcdoS6k6HWp' | 'p-chain' | 'x-chain' | 'c-chain'>;
2046
2040
  };
@@ -4108,6 +4102,49 @@ declare class PrimaryNetworkVerticesService {
4108
4102
  }): CancelablePromise<ListXChainVerticesResponse>;
4109
4103
  }
4110
4104
 
4105
+ type RpcErrorDto = {
4106
+ code: number;
4107
+ message: string;
4108
+ data?: Record<string, any>;
4109
+ };
4110
+
4111
+ type RpcErrorResponseDto = {
4112
+ jsonrpc: string;
4113
+ id?: (string | number);
4114
+ error: RpcErrorDto;
4115
+ };
4116
+
4117
+ type RpcRequestBodyDto = {
4118
+ method: string;
4119
+ params?: Record<string, any>;
4120
+ id?: (string | number);
4121
+ jsonrpc?: string;
4122
+ };
4123
+
4124
+ type RpcSuccessResponseDto = {
4125
+ jsonrpc: string;
4126
+ id?: (string | number);
4127
+ result: Record<string, any>;
4128
+ };
4129
+
4130
+ declare class RpcService {
4131
+ readonly httpRequest: BaseHttpRequest;
4132
+ constructor(httpRequest: BaseHttpRequest);
4133
+ /**
4134
+ * Calls JSON-RPC method
4135
+ * Calls JSON-RPC method.
4136
+ * @returns any
4137
+ * @throws ApiError
4138
+ */
4139
+ rpc({ chainId, requestBody, }: {
4140
+ /**
4141
+ * A supported evm chain id, chain alias or blockchain id. Use the `/chains` endpoint to get a list of supported chain ids.
4142
+ */
4143
+ chainId: string;
4144
+ requestBody: (RpcRequestBodyDto | Array<RpcRequestBodyDto>);
4145
+ }): CancelablePromise<(RpcSuccessResponseDto | RpcErrorResponseDto)>;
4146
+ }
4147
+
4111
4148
  type TeleporterDestinationTransaction = {
4112
4149
  txHash: string;
4113
4150
  timestamp: number;
@@ -4311,7 +4348,7 @@ type WebhookResponse = {
4311
4348
  /**
4312
4349
  * Whether to include traces in the webhook payload.
4313
4350
  */
4314
- includeTraces?: boolean;
4351
+ includeInternalTxs?: boolean;
4315
4352
  /**
4316
4353
  * Whether to include logs in the webhook payload.
4317
4354
  */
@@ -4340,7 +4377,7 @@ type RegisterWebhookRequest = {
4340
4377
  /**
4341
4378
  * Whether to include traces in the webhook payload.
4342
4379
  */
4343
- includeTraces?: boolean;
4380
+ includeInternalTxs?: boolean;
4344
4381
  /**
4345
4382
  * Whether to include logs in the webhook payload.
4346
4383
  */
@@ -4356,7 +4393,7 @@ type UpdateWebhookRequest = {
4356
4393
  description?: string;
4357
4394
  url?: string;
4358
4395
  status?: WebhookStatusType;
4359
- includeTraces?: boolean;
4396
+ includeInternalTxs?: boolean;
4360
4397
  includeLogs?: boolean;
4361
4398
  };
4362
4399
 
@@ -4468,6 +4505,7 @@ declare class Glacier {
4468
4505
  readonly primaryNetworkTransactions: PrimaryNetworkTransactionsService;
4469
4506
  readonly primaryNetworkUtxOs: PrimaryNetworkUtxOsService;
4470
4507
  readonly primaryNetworkVertices: PrimaryNetworkVerticesService;
4508
+ readonly rpc: RpcService;
4471
4509
  readonly teleporter: TeleporterService;
4472
4510
  readonly webhooks: WebhooksService;
4473
4511
  readonly request: BaseHttpRequest;
@@ -4491,4 +4529,4 @@ declare class ApiError extends Error {
4491
4529
  constructor(request: ApiRequestOptions, response: ApiResult, message: string);
4492
4530
  }
4493
4531
 
4494
- export { ActiveDelegatorDetails, ActiveValidatorDetails, AddressActivityMetadata, AggregatedAssetAmount, ApiError, AssetAmount, AssetWithPriceInfo, BaseHttpRequest, Blockchain, BlockchainId, BlockchainIds, BlockchainInfo, CChainAtomicBalances, CChainExportTransaction, CChainImportTransaction, CChainSharedAssetBalance, CancelError, CancelablePromise, ChainAddressChainIdMap, ChainAddressChainIdMapListResponse, ChainInfo, ChainStatus, CompletedDelegatorDetails, CompletedValidatorDetails, ContractDeploymentDetails, ContractSubmissionBody, ContractSubmissionErc1155, ContractSubmissionErc20, ContractSubmissionErc721, ContractSubmissionUnknown, CreateEvmTransactionExportRequest, CreatePrimaryNetworkTransactionExportRequest, CurrencyCode, DefaultService, DelegationStatusType, DelegatorsDetails, DeliveredSourceNotIndexedTeleporterMessage, DeliveredTeleporterMessage, EVMInput, EVMOperationType, EVMOutput, Erc1155Contract, Erc1155Token, Erc1155TokenBalance, Erc1155TokenMetadata, Erc1155Transfer, Erc1155TransferDetails, Erc20Contract, Erc20Token, Erc20TokenBalance, Erc20Transfer, Erc20TransferDetails, Erc721Contract, Erc721Token, Erc721TokenBalance, Erc721TokenMetadata, Erc721Transfer, Erc721TransferDetails, EventType, EvmBalancesService, EvmBlock, EvmBlocksService, EvmChainsService, EvmContractsService, EvmNetworkOptions, EvmTransactionsService, FullNativeTransactionDetails, GetChainResponse, GetEvmBlockResponse, GetNativeBalanceResponse, GetNetworkDetailsResponse, GetPrimaryNetworkBlockResponse, GetTransactionResponse, Glacier, GlacierApiFeature, HealthCheckService, HistoricalReward, ImageAsset, InternalTransaction, InternalTransactionDetails, InternalTransactionOpCall, ListBlockchainsResponse, ListCChainAtomicBalancesResponse, ListCChainAtomicTransactionsResponse, ListChainsResponse, ListCollectibleBalancesResponse, ListContractsResponse, ListDelegatorDetailsResponse, ListErc1155BalancesResponse, ListErc1155TransactionsResponse, ListErc20BalancesResponse, ListErc20TransactionsResponse, ListErc721BalancesResponse, ListErc721TransactionsResponse, ListEvmBlocksResponse, ListHistoricalRewardsResponse, ListInternalTransactionsResponse, ListNativeTransactionsResponse, ListNftTokens, ListPChainBalancesResponse, ListPChainTransactionsResponse, ListPChainUtxosResponse, ListPendingRewardsResponse, ListPrimaryNetworkBlocksResponse, ListSubnetsResponse, ListTransactionDetailsResponse, ListTransfersResponse, ListUtxosResponse, ListValidatorDetailsResponse, ListWebhooksResponse, ListXChainBalancesResponse, ListXChainTransactionsResponse, ListXChainVerticesResponse, Method, Money, NativeTokenBalance, NativeTransaction, Network, NetworkToken, NetworkTokenDetails, NetworkType, NextPageToken, NfTsService, NftTokenMetadataStatus, OpenAPI, OpenAPIConfig, OperationStatus, OperationStatusCode, OperationStatusResponse, OperationType, OperationsService, PChainBalance, PChainId, PChainSharedAsset, PChainTransaction, PChainTransactionType, PChainUtxo, PendingDelegatorDetails, PendingReward, PendingTeleporterMessage, PendingValidatorDetails, PricingProviders, PrimaryNetwork, PrimaryNetworkAssetCap, PrimaryNetworkAssetType, PrimaryNetworkBalancesService, PrimaryNetworkBlock, PrimaryNetworkBlocksService, PrimaryNetworkChainInfo, PrimaryNetworkChainName, PrimaryNetworkOperationType, PrimaryNetworkOptions, PrimaryNetworkRewardsService, PrimaryNetworkService, PrimaryNetworkTransactionsService, PrimaryNetworkTxType, PrimaryNetworkUtxOsService, PrimaryNetworkVerticesService, ProposerDetails, RegisterWebhookRequest, RemovedValidatorDetails, ResourceLink, ResourceLinkType, RewardType, Rewards, RichAddress, SharedSecretsResponse, SortOrder, StakingDistribution, Subnet, SubnetOwnershipInfo, TeleporterDestinationTransaction, TeleporterReceipt, TeleporterRewardDetails, TeleporterService, TeleporterSourceTransaction, TransactionDetails, TransactionExportMetadata, TransactionMethodType, TransactionStatus, TransactionVertexDetail, UnknownContract, UpdateContractResponse, UpdateWebhookRequest, UtilityAddresses, Utxo, UtxoCredential, UtxoType, ValidationStatusType, ValidatorHealthDetails, ValidatorsDetails, VmName, WebhookResponse, WebhookStatus, WebhookStatusType, WebhooksService, XChainAssetDetails, XChainBalances, XChainId, XChainLinearTransaction, XChainNonLinearTransaction, XChainSharedAssetBalance, XChainTransactionType, XChainVertex };
4532
+ export { ActiveDelegatorDetails, ActiveValidatorDetails, AddressActivityMetadata, AggregatedAssetAmount, ApiError, AssetAmount, AssetWithPriceInfo, BaseHttpRequest, Blockchain, BlockchainId, BlockchainIds, BlockchainInfo, CChainAtomicBalances, CChainExportTransaction, CChainImportTransaction, CChainSharedAssetBalance, CancelError, CancelablePromise, ChainAddressChainIdMap, ChainAddressChainIdMapListResponse, ChainInfo, ChainStatus, CompletedDelegatorDetails, CompletedValidatorDetails, ContractDeploymentDetails, ContractSubmissionBody, ContractSubmissionErc1155, ContractSubmissionErc20, ContractSubmissionErc721, ContractSubmissionUnknown, CreateEvmTransactionExportRequest, CreatePrimaryNetworkTransactionExportRequest, CurrencyCode, DefaultService, DelegationStatusType, DelegatorsDetails, DeliveredSourceNotIndexedTeleporterMessage, DeliveredTeleporterMessage, EVMInput, EVMOperationType, EVMOutput, Erc1155Contract, Erc1155Token, Erc1155TokenBalance, Erc1155TokenMetadata, Erc1155Transfer, Erc1155TransferDetails, Erc20Contract, Erc20Token, Erc20TokenBalance, Erc20Transfer, Erc20TransferDetails, Erc721Contract, Erc721Token, Erc721TokenBalance, Erc721TokenMetadata, Erc721Transfer, Erc721TransferDetails, EventType, EvmBalancesService, EvmBlock, EvmBlocksService, EvmChainsService, EvmContractsService, EvmNetworkOptions, EvmTransactionsService, FullNativeTransactionDetails, GetChainResponse, GetEvmBlockResponse, GetNativeBalanceResponse, GetNetworkDetailsResponse, GetPrimaryNetworkBlockResponse, GetTransactionResponse, Glacier, GlacierApiFeature, HealthCheckService, HistoricalReward, ImageAsset, InternalTransaction, InternalTransactionDetails, InternalTransactionOpCall, ListBlockchainsResponse, ListCChainAtomicBalancesResponse, ListCChainAtomicTransactionsResponse, ListChainsResponse, ListCollectibleBalancesResponse, ListContractsResponse, ListDelegatorDetailsResponse, ListErc1155BalancesResponse, ListErc1155TransactionsResponse, ListErc20BalancesResponse, ListErc20TransactionsResponse, ListErc721BalancesResponse, ListErc721TransactionsResponse, ListEvmBlocksResponse, ListHistoricalRewardsResponse, ListInternalTransactionsResponse, ListNativeTransactionsResponse, ListNftTokens, ListPChainBalancesResponse, ListPChainTransactionsResponse, ListPChainUtxosResponse, ListPendingRewardsResponse, ListPrimaryNetworkBlocksResponse, ListSubnetsResponse, ListTransactionDetailsResponse, ListTransfersResponse, ListUtxosResponse, ListValidatorDetailsResponse, ListWebhooksResponse, ListXChainBalancesResponse, ListXChainTransactionsResponse, ListXChainVerticesResponse, Method, Money, NativeTokenBalance, NativeTransaction, Network, NetworkToken, NetworkTokenDetails, NetworkType, NextPageToken, NfTsService, NftTokenMetadataStatus, OpenAPI, OpenAPIConfig, OperationStatus, OperationStatusCode, OperationStatusResponse, OperationType, OperationsService, PChainBalance, PChainId, PChainSharedAsset, PChainTransaction, PChainTransactionType, PChainUtxo, PendingDelegatorDetails, PendingReward, PendingTeleporterMessage, PendingValidatorDetails, PricingProviders, PrimaryNetwork, PrimaryNetworkAssetCap, PrimaryNetworkAssetType, PrimaryNetworkBalancesService, PrimaryNetworkBlock, PrimaryNetworkBlocksService, PrimaryNetworkChainInfo, PrimaryNetworkChainName, PrimaryNetworkOperationType, PrimaryNetworkOptions, PrimaryNetworkRewardsService, PrimaryNetworkService, PrimaryNetworkTransactionsService, PrimaryNetworkTxType, PrimaryNetworkUtxOsService, PrimaryNetworkVerticesService, ProposerDetails, RegisterWebhookRequest, RemovedValidatorDetails, ResourceLink, ResourceLinkType, RewardType, Rewards, RichAddress, RpcErrorDto, RpcErrorResponseDto, RpcRequestBodyDto, RpcService, RpcSuccessResponseDto, SharedSecretsResponse, SortOrder, StakingDistribution, Subnet, SubnetOwnershipInfo, TeleporterDestinationTransaction, TeleporterReceipt, TeleporterRewardDetails, TeleporterService, TeleporterSourceTransaction, TransactionDetails, TransactionExportMetadata, TransactionMethodType, TransactionStatus, TransactionVertexDetail, UnknownContract, UpdateContractResponse, UpdateWebhookRequest, UtilityAddresses, Utxo, UtxoCredential, UtxoType, ValidationStatusType, ValidatorHealthDetails, ValidatorsDetails, VmName, WebhookResponse, WebhookStatus, WebhookStatusType, WebhooksService, XChainAssetDetails, XChainBalances, XChainId, XChainLinearTransaction, XChainNonLinearTransaction, XChainSharedAssetBalance, XChainTransactionType, XChainVertex };
package/dist/index.js CHANGED
@@ -33,71 +33,75 @@ class CancelError extends Error {
33
33
  }
34
34
  }
35
35
  class CancelablePromise {
36
- [Symbol.toStringTag];
37
- _isResolved;
38
- _isRejected;
39
- _isCancelled;
40
- _cancelHandlers;
41
- _promise;
42
- _resolve;
43
- _reject;
36
+ #isResolved;
37
+ #isRejected;
38
+ #isCancelled;
39
+ #cancelHandlers;
40
+ #promise;
41
+ #resolve;
42
+ #reject;
44
43
  constructor(executor) {
45
- this._isResolved = false;
46
- this._isRejected = false;
47
- this._isCancelled = false;
48
- this._cancelHandlers = [];
49
- this._promise = new Promise((resolve, reject) => {
50
- this._resolve = resolve;
51
- this._reject = reject;
44
+ this.#isResolved = false;
45
+ this.#isRejected = false;
46
+ this.#isCancelled = false;
47
+ this.#cancelHandlers = [];
48
+ this.#promise = new Promise((resolve, reject) => {
49
+ this.#resolve = resolve;
50
+ this.#reject = reject;
52
51
  const onResolve = (value) => {
53
- if (this._isResolved || this._isRejected || this._isCancelled) {
52
+ if (this.#isResolved || this.#isRejected || this.#isCancelled) {
54
53
  return;
55
54
  }
56
- this._isResolved = true;
57
- this._resolve?.(value);
55
+ this.#isResolved = true;
56
+ if (this.#resolve)
57
+ this.#resolve(value);
58
58
  };
59
59
  const onReject = (reason) => {
60
- if (this._isResolved || this._isRejected || this._isCancelled) {
60
+ if (this.#isResolved || this.#isRejected || this.#isCancelled) {
61
61
  return;
62
62
  }
63
- this._isRejected = true;
64
- this._reject?.(reason);
63
+ this.#isRejected = true;
64
+ if (this.#reject)
65
+ this.#reject(reason);
65
66
  };
66
67
  const onCancel = (cancelHandler) => {
67
- if (this._isResolved || this._isRejected || this._isCancelled) {
68
+ if (this.#isResolved || this.#isRejected || this.#isCancelled) {
68
69
  return;
69
70
  }
70
- this._cancelHandlers.push(cancelHandler);
71
+ this.#cancelHandlers.push(cancelHandler);
71
72
  };
72
73
  Object.defineProperty(onCancel, "isResolved", {
73
- get: () => this._isResolved
74
+ get: () => this.#isResolved
74
75
  });
75
76
  Object.defineProperty(onCancel, "isRejected", {
76
- get: () => this._isRejected
77
+ get: () => this.#isRejected
77
78
  });
78
79
  Object.defineProperty(onCancel, "isCancelled", {
79
- get: () => this._isCancelled
80
+ get: () => this.#isCancelled
80
81
  });
81
82
  return executor(onResolve, onReject, onCancel);
82
83
  });
83
84
  }
85
+ get [Symbol.toStringTag]() {
86
+ return "Cancellable Promise";
87
+ }
84
88
  then(onFulfilled, onRejected) {
85
- return this._promise.then(onFulfilled, onRejected);
89
+ return this.#promise.then(onFulfilled, onRejected);
86
90
  }
87
91
  catch(onRejected) {
88
- return this._promise.catch(onRejected);
92
+ return this.#promise.catch(onRejected);
89
93
  }
90
94
  finally(onFinally) {
91
- return this._promise.finally(onFinally);
95
+ return this.#promise.finally(onFinally);
92
96
  }
93
97
  cancel() {
94
- if (this._isResolved || this._isRejected || this._isCancelled) {
98
+ if (this.#isResolved || this.#isRejected || this.#isCancelled) {
95
99
  return;
96
100
  }
97
- this._isCancelled = true;
98
- if (this._cancelHandlers.length) {
101
+ this.#isCancelled = true;
102
+ if (this.#cancelHandlers.length) {
99
103
  try {
100
- for (const cancelHandler of this._cancelHandlers) {
104
+ for (const cancelHandler of this.#cancelHandlers) {
101
105
  cancelHandler();
102
106
  }
103
107
  } catch (error) {
@@ -105,11 +109,12 @@ class CancelablePromise {
105
109
  return;
106
110
  }
107
111
  }
108
- this._cancelHandlers.length = 0;
109
- this._reject?.(new CancelError("Request aborted"));
112
+ this.#cancelHandlers.length = 0;
113
+ if (this.#reject)
114
+ this.#reject(new CancelError("Request aborted"));
110
115
  }
111
116
  get isCancelled() {
112
- return this._isCancelled;
117
+ return this.#isCancelled;
113
118
  }
114
119
  }
115
120
 
@@ -205,10 +210,12 @@ const resolve = async (options, resolver) => {
205
210
  return resolver;
206
211
  };
207
212
  const getHeaders = async (config, options) => {
208
- const token = await resolve(options, config.TOKEN);
209
- const username = await resolve(options, config.USERNAME);
210
- const password = await resolve(options, config.PASSWORD);
211
- const additionalHeaders = await resolve(options, config.HEADERS);
213
+ const [token, username, password, additionalHeaders] = await Promise.all([
214
+ resolve(options, config.TOKEN),
215
+ resolve(options, config.USERNAME),
216
+ resolve(options, config.PASSWORD),
217
+ resolve(options, config.HEADERS)
218
+ ]);
212
219
  const headers = Object.entries({
213
220
  Accept: "application/json",
214
221
  ...additionalHeaders,
@@ -224,7 +231,7 @@ const getHeaders = async (config, options) => {
224
231
  const credentials = base64(`${username}:${password}`);
225
232
  headers["Authorization"] = `Basic ${credentials}`;
226
233
  }
227
- if (options.body) {
234
+ if (options.body !== void 0) {
228
235
  if (options.mediaType) {
229
236
  headers["Content-Type"] = options.mediaType;
230
237
  } else if (isBlob(options.body)) {
@@ -238,7 +245,7 @@ const getHeaders = async (config, options) => {
238
245
  return new Headers(headers);
239
246
  };
240
247
  const getRequestBody = (options) => {
241
- if (options.body) {
248
+ if (options.body !== void 0) {
242
249
  if (options.mediaType?.includes("/json")) {
243
250
  return JSON.stringify(options.body);
244
251
  } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
@@ -277,7 +284,8 @@ const getResponseBody = async (response) => {
277
284
  try {
278
285
  const contentType = response.headers.get("Content-Type");
279
286
  if (contentType) {
280
- const isJSON = contentType.toLowerCase().startsWith("application/json");
287
+ const jsonTypes = ["application/json", "application/problem+json"];
288
+ const isJSON = jsonTypes.some((type) => contentType.toLowerCase().startsWith(type));
281
289
  if (isJSON) {
282
290
  return await response.json();
283
291
  } else {
@@ -306,7 +314,20 @@ const catchErrorCodes = (options, result) => {
306
314
  throw new ApiError(options, result, error);
307
315
  }
308
316
  if (!result.ok) {
309
- throw new ApiError(options, result, "Generic Error");
317
+ const errorStatus = result.status ?? "unknown";
318
+ const errorStatusText = result.statusText ?? "unknown";
319
+ const errorBody = (() => {
320
+ try {
321
+ return JSON.stringify(result.body, null, 2);
322
+ } catch (e) {
323
+ return void 0;
324
+ }
325
+ })();
326
+ throw new ApiError(
327
+ options,
328
+ result,
329
+ `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
330
+ );
310
331
  }
311
332
  };
312
333
  const request = (config, options) => {
@@ -1432,6 +1453,29 @@ class PrimaryNetworkVerticesService {
1432
1453
  }
1433
1454
  }
1434
1455
 
1456
+ class RpcService {
1457
+ constructor(httpRequest) {
1458
+ this.httpRequest = httpRequest;
1459
+ }
1460
+ rpc({
1461
+ chainId,
1462
+ requestBody
1463
+ }) {
1464
+ return this.httpRequest.request({
1465
+ method: "POST",
1466
+ url: "/v1/ext/bc/{chainId}/rpc",
1467
+ path: {
1468
+ "chainId": chainId
1469
+ },
1470
+ body: requestBody,
1471
+ mediaType: "application/json",
1472
+ errors: {
1473
+ 504: `Request timed out`
1474
+ }
1475
+ });
1476
+ }
1477
+ }
1478
+
1435
1479
  class TeleporterService {
1436
1480
  constructor(httpRequest) {
1437
1481
  this.httpRequest = httpRequest;
@@ -1566,6 +1610,7 @@ class Glacier {
1566
1610
  primaryNetworkTransactions;
1567
1611
  primaryNetworkUtxOs;
1568
1612
  primaryNetworkVertices;
1613
+ rpc;
1569
1614
  teleporter;
1570
1615
  webhooks;
1571
1616
  request;
@@ -1597,6 +1642,7 @@ class Glacier {
1597
1642
  this.primaryNetworkTransactions = new PrimaryNetworkTransactionsService(this.request);
1598
1643
  this.primaryNetworkUtxOs = new PrimaryNetworkUtxOsService(this.request);
1599
1644
  this.primaryNetworkVertices = new PrimaryNetworkVerticesService(this.request);
1645
+ this.rpc = new RpcService(this.request);
1600
1646
  this.teleporter = new TeleporterService(this.request);
1601
1647
  this.webhooks = new WebhooksService(this.request);
1602
1648
  }
@@ -2172,6 +2218,7 @@ exports.PrimaryNetworkUtxOsService = PrimaryNetworkUtxOsService;
2172
2218
  exports.PrimaryNetworkVerticesService = PrimaryNetworkVerticesService;
2173
2219
  exports.ResourceLinkType = ResourceLinkType;
2174
2220
  exports.RewardType = RewardType;
2221
+ exports.RpcService = RpcService;
2175
2222
  exports.SortOrder = SortOrder;
2176
2223
  exports.TeleporterService = TeleporterService;
2177
2224
  exports.TransactionMethodType = TransactionMethodType;
@@ -16,6 +16,7 @@ import { PrimaryNetworkRewardsService } from './services/PrimaryNetworkRewardsSe
16
16
  import { PrimaryNetworkTransactionsService } from './services/PrimaryNetworkTransactionsService.js';
17
17
  import { PrimaryNetworkUtxOsService } from './services/PrimaryNetworkUtxOsService.js';
18
18
  import { PrimaryNetworkVerticesService } from './services/PrimaryNetworkVerticesService.js';
19
+ import { RpcService } from './services/RpcService.js';
19
20
  import { TeleporterService } from './services/TeleporterService.js';
20
21
  import { WebhooksService } from './services/WebhooksService.js';
21
22
 
@@ -37,6 +38,7 @@ declare class Glacier {
37
38
  readonly primaryNetworkTransactions: PrimaryNetworkTransactionsService;
38
39
  readonly primaryNetworkUtxOs: PrimaryNetworkUtxOsService;
39
40
  readonly primaryNetworkVertices: PrimaryNetworkVerticesService;
41
+ readonly rpc: RpcService;
40
42
  readonly teleporter: TeleporterService;
41
43
  readonly webhooks: WebhooksService;
42
44
  readonly request: BaseHttpRequest;
@@ -15,6 +15,7 @@ import { PrimaryNetworkRewardsService } from './services/PrimaryNetworkRewardsSe
15
15
  import { PrimaryNetworkTransactionsService } from './services/PrimaryNetworkTransactionsService.js';
16
16
  import { PrimaryNetworkUtxOsService } from './services/PrimaryNetworkUtxOsService.js';
17
17
  import { PrimaryNetworkVerticesService } from './services/PrimaryNetworkVerticesService.js';
18
+ import { RpcService } from './services/RpcService.js';
18
19
  import { TeleporterService } from './services/TeleporterService.js';
19
20
  import { WebhooksService } from './services/WebhooksService.js';
20
21
 
@@ -35,6 +36,7 @@ class Glacier {
35
36
  primaryNetworkTransactions;
36
37
  primaryNetworkUtxOs;
37
38
  primaryNetworkVertices;
39
+ rpc;
38
40
  teleporter;
39
41
  webhooks;
40
42
  request;
@@ -66,6 +68,7 @@ class Glacier {
66
68
  this.primaryNetworkTransactions = new PrimaryNetworkTransactionsService(this.request);
67
69
  this.primaryNetworkUtxOs = new PrimaryNetworkUtxOsService(this.request);
68
70
  this.primaryNetworkVertices = new PrimaryNetworkVerticesService(this.request);
71
+ this.rpc = new RpcService(this.request);
69
72
  this.teleporter = new TeleporterService(this.request);
70
73
  this.webhooks = new WebhooksService(this.request);
71
74
  }
@@ -9,15 +9,9 @@ interface OnCancel {
9
9
  (cancelHandler: () => void): void;
10
10
  }
11
11
  declare class CancelablePromise<T> implements Promise<T> {
12
- readonly [Symbol.toStringTag]: string;
13
- private _isResolved;
14
- private _isRejected;
15
- private _isCancelled;
16
- private readonly _cancelHandlers;
17
- private readonly _promise;
18
- private _resolve?;
19
- private _reject?;
12
+ #private;
20
13
  constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, onCancel: OnCancel) => void);
14
+ get [Symbol.toStringTag](): string;
21
15
  then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
22
16
  catch<TResult = never>(onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
23
17
  finally(onFinally?: (() => void) | null): Promise<T>;
@@ -8,71 +8,75 @@ class CancelError extends Error {
8
8
  }
9
9
  }
10
10
  class CancelablePromise {
11
- [Symbol.toStringTag];
12
- _isResolved;
13
- _isRejected;
14
- _isCancelled;
15
- _cancelHandlers;
16
- _promise;
17
- _resolve;
18
- _reject;
11
+ #isResolved;
12
+ #isRejected;
13
+ #isCancelled;
14
+ #cancelHandlers;
15
+ #promise;
16
+ #resolve;
17
+ #reject;
19
18
  constructor(executor) {
20
- this._isResolved = false;
21
- this._isRejected = false;
22
- this._isCancelled = false;
23
- this._cancelHandlers = [];
24
- this._promise = new Promise((resolve, reject) => {
25
- this._resolve = resolve;
26
- this._reject = reject;
19
+ this.#isResolved = false;
20
+ this.#isRejected = false;
21
+ this.#isCancelled = false;
22
+ this.#cancelHandlers = [];
23
+ this.#promise = new Promise((resolve, reject) => {
24
+ this.#resolve = resolve;
25
+ this.#reject = reject;
27
26
  const onResolve = (value) => {
28
- if (this._isResolved || this._isRejected || this._isCancelled) {
27
+ if (this.#isResolved || this.#isRejected || this.#isCancelled) {
29
28
  return;
30
29
  }
31
- this._isResolved = true;
32
- this._resolve?.(value);
30
+ this.#isResolved = true;
31
+ if (this.#resolve)
32
+ this.#resolve(value);
33
33
  };
34
34
  const onReject = (reason) => {
35
- if (this._isResolved || this._isRejected || this._isCancelled) {
35
+ if (this.#isResolved || this.#isRejected || this.#isCancelled) {
36
36
  return;
37
37
  }
38
- this._isRejected = true;
39
- this._reject?.(reason);
38
+ this.#isRejected = true;
39
+ if (this.#reject)
40
+ this.#reject(reason);
40
41
  };
41
42
  const onCancel = (cancelHandler) => {
42
- if (this._isResolved || this._isRejected || this._isCancelled) {
43
+ if (this.#isResolved || this.#isRejected || this.#isCancelled) {
43
44
  return;
44
45
  }
45
- this._cancelHandlers.push(cancelHandler);
46
+ this.#cancelHandlers.push(cancelHandler);
46
47
  };
47
48
  Object.defineProperty(onCancel, "isResolved", {
48
- get: () => this._isResolved
49
+ get: () => this.#isResolved
49
50
  });
50
51
  Object.defineProperty(onCancel, "isRejected", {
51
- get: () => this._isRejected
52
+ get: () => this.#isRejected
52
53
  });
53
54
  Object.defineProperty(onCancel, "isCancelled", {
54
- get: () => this._isCancelled
55
+ get: () => this.#isCancelled
55
56
  });
56
57
  return executor(onResolve, onReject, onCancel);
57
58
  });
58
59
  }
60
+ get [Symbol.toStringTag]() {
61
+ return "Cancellable Promise";
62
+ }
59
63
  then(onFulfilled, onRejected) {
60
- return this._promise.then(onFulfilled, onRejected);
64
+ return this.#promise.then(onFulfilled, onRejected);
61
65
  }
62
66
  catch(onRejected) {
63
- return this._promise.catch(onRejected);
67
+ return this.#promise.catch(onRejected);
64
68
  }
65
69
  finally(onFinally) {
66
- return this._promise.finally(onFinally);
70
+ return this.#promise.finally(onFinally);
67
71
  }
68
72
  cancel() {
69
- if (this._isResolved || this._isRejected || this._isCancelled) {
73
+ if (this.#isResolved || this.#isRejected || this.#isCancelled) {
70
74
  return;
71
75
  }
72
- this._isCancelled = true;
73
- if (this._cancelHandlers.length) {
76
+ this.#isCancelled = true;
77
+ if (this.#cancelHandlers.length) {
74
78
  try {
75
- for (const cancelHandler of this._cancelHandlers) {
79
+ for (const cancelHandler of this.#cancelHandlers) {
76
80
  cancelHandler();
77
81
  }
78
82
  } catch (error) {
@@ -80,11 +84,12 @@ class CancelablePromise {
80
84
  return;
81
85
  }
82
86
  }
83
- this._cancelHandlers.length = 0;
84
- this._reject?.(new CancelError("Request aborted"));
87
+ this.#cancelHandlers.length = 0;
88
+ if (this.#reject)
89
+ this.#reject(new CancelError("Request aborted"));
85
90
  }
86
91
  get isCancelled() {
87
- return this._isCancelled;
92
+ return this.#isCancelled;
88
93
  }
89
94
  }
90
95
 
@@ -7,11 +7,11 @@ type OpenAPIConfig = {
7
7
  VERSION: string;
8
8
  WITH_CREDENTIALS: boolean;
9
9
  CREDENTIALS: 'include' | 'omit' | 'same-origin';
10
- TOKEN?: string | Resolver<string>;
11
- USERNAME?: string | Resolver<string>;
12
- PASSWORD?: string | Resolver<string>;
13
- HEADERS?: Headers | Resolver<Headers>;
14
- ENCODE_PATH?: (path: string) => string;
10
+ TOKEN?: string | Resolver<string> | undefined;
11
+ USERNAME?: string | Resolver<string> | undefined;
12
+ PASSWORD?: string | Resolver<string> | undefined;
13
+ HEADERS?: Headers | Resolver<Headers> | undefined;
14
+ ENCODE_PATH?: ((path: string) => string) | undefined;
15
15
  };
16
16
  declare const OpenAPI: OpenAPIConfig;
17
17
 
@@ -93,10 +93,12 @@ const resolve = async (options, resolver) => {
93
93
  return resolver;
94
94
  };
95
95
  const getHeaders = async (config, options) => {
96
- const token = await resolve(options, config.TOKEN);
97
- const username = await resolve(options, config.USERNAME);
98
- const password = await resolve(options, config.PASSWORD);
99
- const additionalHeaders = await resolve(options, config.HEADERS);
96
+ const [token, username, password, additionalHeaders] = await Promise.all([
97
+ resolve(options, config.TOKEN),
98
+ resolve(options, config.USERNAME),
99
+ resolve(options, config.PASSWORD),
100
+ resolve(options, config.HEADERS)
101
+ ]);
100
102
  const headers = Object.entries({
101
103
  Accept: "application/json",
102
104
  ...additionalHeaders,
@@ -112,7 +114,7 @@ const getHeaders = async (config, options) => {
112
114
  const credentials = base64(`${username}:${password}`);
113
115
  headers["Authorization"] = `Basic ${credentials}`;
114
116
  }
115
- if (options.body) {
117
+ if (options.body !== void 0) {
116
118
  if (options.mediaType) {
117
119
  headers["Content-Type"] = options.mediaType;
118
120
  } else if (isBlob(options.body)) {
@@ -126,7 +128,7 @@ const getHeaders = async (config, options) => {
126
128
  return new Headers(headers);
127
129
  };
128
130
  const getRequestBody = (options) => {
129
- if (options.body) {
131
+ if (options.body !== void 0) {
130
132
  if (options.mediaType?.includes("/json")) {
131
133
  return JSON.stringify(options.body);
132
134
  } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
@@ -165,7 +167,8 @@ const getResponseBody = async (response) => {
165
167
  try {
166
168
  const contentType = response.headers.get("Content-Type");
167
169
  if (contentType) {
168
- const isJSON = contentType.toLowerCase().startsWith("application/json");
170
+ const jsonTypes = ["application/json", "application/problem+json"];
171
+ const isJSON = jsonTypes.some((type) => contentType.toLowerCase().startsWith(type));
169
172
  if (isJSON) {
170
173
  return await response.json();
171
174
  } else {
@@ -194,7 +197,20 @@ const catchErrorCodes = (options, result) => {
194
197
  throw new ApiError(options, result, error);
195
198
  }
196
199
  if (!result.ok) {
197
- throw new ApiError(options, result, "Generic Error");
200
+ const errorStatus = result.status ?? "unknown";
201
+ const errorStatusText = result.statusText ?? "unknown";
202
+ const errorBody = (() => {
203
+ try {
204
+ return JSON.stringify(result.body, null, 2);
205
+ } catch (e) {
206
+ return void 0;
207
+ }
208
+ })();
209
+ throw new ApiError(
210
+ options,
211
+ result,
212
+ `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
213
+ );
198
214
  }
199
215
  };
200
216
  const request = (config, options) => {
@@ -224,4 +240,4 @@ const request = (config, options) => {
224
240
  });
225
241
  };
226
242
 
227
- export { request, sendRequest };
243
+ export { base64, catchErrorCodes, getFormData, getHeaders, getQueryString, getRequestBody, getResponseBody, getResponseHeader, isBlob, isDefined, isFormData, isString, isStringWithValue, request, resolve, sendRequest };
@@ -1,5 +1,5 @@
1
1
  type PrimaryNetworkOptions = {
2
- addresses: Array<string>;
2
+ addresses?: Array<string>;
3
3
  cChainEvmAddresses?: Array<string>;
4
4
  includeChains: Array<'11111111111111111111111111111111LpoYY' | '2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM' | '2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm' | '2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5' | 'yH8D7ThNJkxmtkuv2jgBa4P1Rn3Qpr4pPr7QYNfcdoS6k6HWp' | 'p-chain' | 'x-chain' | 'c-chain'>;
5
5
  };
@@ -9,7 +9,7 @@ type RegisterWebhookRequest = {
9
9
  /**
10
10
  * Whether to include traces in the webhook payload.
11
11
  */
12
- includeTraces?: boolean;
12
+ includeInternalTxs?: boolean;
13
13
  /**
14
14
  * Whether to include logs in the webhook payload.
15
15
  */
@@ -0,0 +1,7 @@
1
+ type RpcErrorDto = {
2
+ code: number;
3
+ message: string;
4
+ data?: Record<string, any>;
5
+ };
6
+
7
+ export { RpcErrorDto };
@@ -0,0 +1,9 @@
1
+ import { RpcErrorDto } from './RpcErrorDto.js';
2
+
3
+ type RpcErrorResponseDto = {
4
+ jsonrpc: string;
5
+ id?: (string | number);
6
+ error: RpcErrorDto;
7
+ };
8
+
9
+ export { RpcErrorResponseDto };
@@ -0,0 +1,8 @@
1
+ type RpcRequestBodyDto = {
2
+ method: string;
3
+ params?: Record<string, any>;
4
+ id?: (string | number);
5
+ jsonrpc?: string;
6
+ };
7
+
8
+ export { RpcRequestBodyDto };
@@ -0,0 +1,7 @@
1
+ type RpcSuccessResponseDto = {
2
+ jsonrpc: string;
3
+ id?: (string | number);
4
+ result: Record<string, any>;
5
+ };
6
+
7
+ export { RpcSuccessResponseDto };
@@ -5,7 +5,7 @@ type UpdateWebhookRequest = {
5
5
  description?: string;
6
6
  url?: string;
7
7
  status?: WebhookStatusType;
8
- includeTraces?: boolean;
8
+ includeInternalTxs?: boolean;
9
9
  includeLogs?: boolean;
10
10
  };
11
11
 
@@ -9,7 +9,7 @@ type WebhookResponse = {
9
9
  /**
10
10
  * Whether to include traces in the webhook payload.
11
11
  */
12
- includeTraces?: boolean;
12
+ includeInternalTxs?: boolean;
13
13
  /**
14
14
  * Whether to include logs in the webhook payload.
15
15
  */
@@ -0,0 +1,25 @@
1
+ import { RpcErrorResponseDto } from '../models/RpcErrorResponseDto.js';
2
+ import { RpcRequestBodyDto } from '../models/RpcRequestBodyDto.js';
3
+ import { RpcSuccessResponseDto } from '../models/RpcSuccessResponseDto.js';
4
+ import { CancelablePromise } from '../core/CancelablePromise.js';
5
+ import { BaseHttpRequest } from '../core/BaseHttpRequest.js';
6
+
7
+ declare class RpcService {
8
+ readonly httpRequest: BaseHttpRequest;
9
+ constructor(httpRequest: BaseHttpRequest);
10
+ /**
11
+ * Calls JSON-RPC method
12
+ * Calls JSON-RPC method.
13
+ * @returns any
14
+ * @throws ApiError
15
+ */
16
+ rpc({ chainId, requestBody, }: {
17
+ /**
18
+ * A supported evm chain id, chain alias or blockchain id. Use the `/chains` endpoint to get a list of supported chain ids.
19
+ */
20
+ chainId: string;
21
+ requestBody: (RpcRequestBodyDto | Array<RpcRequestBodyDto>);
22
+ }): CancelablePromise<(RpcSuccessResponseDto | RpcErrorResponseDto)>;
23
+ }
24
+
25
+ export { RpcService };
@@ -0,0 +1,24 @@
1
+ class RpcService {
2
+ constructor(httpRequest) {
3
+ this.httpRequest = httpRequest;
4
+ }
5
+ rpc({
6
+ chainId,
7
+ requestBody
8
+ }) {
9
+ return this.httpRequest.request({
10
+ method: "POST",
11
+ url: "/v1/ext/bc/{chainId}/rpc",
12
+ path: {
13
+ "chainId": chainId
14
+ },
15
+ body: requestBody,
16
+ mediaType: "application/json",
17
+ errors: {
18
+ 504: `Request timed out`
19
+ }
20
+ });
21
+ }
22
+ }
23
+
24
+ export { RpcService };
package/esm/index.d.ts CHANGED
@@ -146,6 +146,10 @@ export { ResourceLinkType } from './generated/models/ResourceLinkType.js';
146
146
  export { Rewards } from './generated/models/Rewards.js';
147
147
  export { RewardType } from './generated/models/RewardType.js';
148
148
  export { RichAddress } from './generated/models/RichAddress.js';
149
+ export { RpcErrorDto } from './generated/models/RpcErrorDto.js';
150
+ export { RpcErrorResponseDto } from './generated/models/RpcErrorResponseDto.js';
151
+ export { RpcRequestBodyDto } from './generated/models/RpcRequestBodyDto.js';
152
+ export { RpcSuccessResponseDto } from './generated/models/RpcSuccessResponseDto.js';
149
153
  export { SharedSecretsResponse } from './generated/models/SharedSecretsResponse.js';
150
154
  export { SortOrder } from './generated/models/SortOrder.js';
151
155
  export { StakingDistribution } from './generated/models/StakingDistribution.js';
@@ -198,5 +202,6 @@ export { PrimaryNetworkRewardsService } from './generated/services/PrimaryNetwor
198
202
  export { PrimaryNetworkTransactionsService } from './generated/services/PrimaryNetworkTransactionsService.js';
199
203
  export { PrimaryNetworkUtxOsService } from './generated/services/PrimaryNetworkUtxOsService.js';
200
204
  export { PrimaryNetworkVerticesService } from './generated/services/PrimaryNetworkVerticesService.js';
205
+ export { RpcService } from './generated/services/RpcService.js';
201
206
  export { TeleporterService } from './generated/services/TeleporterService.js';
202
207
  export { WebhooksService } from './generated/services/WebhooksService.js';
package/esm/index.js CHANGED
@@ -83,5 +83,6 @@ export { PrimaryNetworkRewardsService } from './generated/services/PrimaryNetwor
83
83
  export { PrimaryNetworkTransactionsService } from './generated/services/PrimaryNetworkTransactionsService.js';
84
84
  export { PrimaryNetworkUtxOsService } from './generated/services/PrimaryNetworkUtxOsService.js';
85
85
  export { PrimaryNetworkVerticesService } from './generated/services/PrimaryNetworkVerticesService.js';
86
+ export { RpcService } from './generated/services/RpcService.js';
86
87
  export { TeleporterService } from './generated/services/TeleporterService.js';
87
88
  export { WebhooksService } from './generated/services/WebhooksService.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avalabs/glacier-sdk",
3
- "version": "2.8.0-canary.db60279.0+db60279",
3
+ "version": "2.8.0-canary.db8f25f.0+db8f25f",
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",
@@ -14,7 +14,7 @@
14
14
  ],
15
15
  "sideEffects": false,
16
16
  "devDependencies": {
17
- "openapi-typescript-codegen": "0.23.0"
17
+ "openapi-typescript-codegen": "0.28.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -29,5 +29,5 @@
29
29
  "bugs": {
30
30
  "url": "https://github.com/ava-labs/avalanche-sdks/issues"
31
31
  },
32
- "gitHead": "db602791585bb0c8a678b3649df399879b44cb06"
32
+ "gitHead": "db8f25fc7f3b824364a4db0e306c35eedfd7a779"
33
33
  }