@hiero-ledger/sdk 2.74.0 → 2.75.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/umd.js CHANGED
@@ -97032,8 +97032,15 @@
97032
97032
  * description: string,
97033
97033
  * stake: number
97034
97034
  * }>} nodes
97035
+ * @property {?{next: ?string}} links - Links object containing pagination information
97035
97036
  */
97036
97037
 
97038
+ /**
97039
+ * Default page size limit for optimal pagination performance
97040
+ * @constant {number}
97041
+ */
97042
+ const DEFAULT_PAGE_SIZE = 25;
97043
+
97037
97044
  /**
97038
97045
  * Web-compatible query to get a list of Hedera network node addresses from a mirror node.
97039
97046
  * Uses fetch API instead of gRPC for web environments.
@@ -97048,7 +97055,7 @@
97048
97055
  /**
97049
97056
  * @param {object} props
97050
97057
  * @param {FileId | string} [props.fileId]
97051
- * @param {number} [props.limit]
97058
+ * @param {number} [props.limit] - Page size limit (defaults to 25 for optimal performance)
97052
97059
  */
97053
97060
  constructor(props = {}) {
97054
97061
  super();
@@ -97215,111 +97222,135 @@
97215
97222
  baseUrl = `${baseUrl}:${port}`;
97216
97223
  }
97217
97224
 
97218
- const url = new URL(`${baseUrl}/api/v1/network/nodes`);
97225
+ // Initialize aggregated results
97226
+ this._addresses = [];
97227
+ let nextUrl = null;
97228
+ let isLastPage = false;
97219
97229
 
97230
+ // Build initial URL
97231
+ const initialUrl = new URL(`${baseUrl}/api/v1/network/nodes`);
97220
97232
  if (this._fileId != null) {
97221
- url.searchParams.append("file.id", this._fileId.toString());
97222
- }
97223
- if (this._limit != null) {
97224
- url.searchParams.append("limit", this._limit.toString());
97233
+ initialUrl.searchParams.append("file.id", this._fileId.toString());
97225
97234
  }
97226
97235
 
97227
- for (let attempt = 0; attempt <= this._maxAttempts; attempt++) {
97228
- try {
97229
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
97230
- const response = await fetch(url.toString(), {
97231
- method: "GET",
97232
- headers: {
97233
- Accept: "application/json",
97234
- },
97235
- signal: requestTimeout
97236
- ? AbortSignal.timeout(requestTimeout)
97237
- : undefined,
97238
- });
97236
+ // Use the specified limit, or default to DEFAULT_PAGE_SIZE for optimal pagination performance
97237
+ const effectiveLimit =
97238
+ this._limit != null ? this._limit : DEFAULT_PAGE_SIZE;
97239
+ initialUrl.searchParams.append("limit", effectiveLimit.toString());
97239
97240
 
97240
- if (!response.ok) {
97241
- throw new Error(`HTTP error! status: ${response.status}`);
97242
- }
97241
+ // Fetch all pages
97242
+ while (!isLastPage) {
97243
+ const currentUrl = nextUrl ? new URL(nextUrl, baseUrl) : initialUrl;
97243
97244
 
97244
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
97245
- const data = /** @type {AddressBookQueryWebResponse} */ (
97246
- await response.json()
97247
- );
97245
+ for (let attempt = 0; attempt <= this._maxAttempts; attempt++) {
97246
+ try {
97247
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
97248
+ const response = await fetch(currentUrl.toString(), {
97249
+ method: "GET",
97250
+ headers: {
97251
+ Accept: "application/json",
97252
+ },
97253
+ signal: requestTimeout
97254
+ ? AbortSignal.timeout(requestTimeout)
97255
+ : undefined,
97256
+ });
97248
97257
 
97249
- const nodes = data.nodes || [];
97258
+ if (!response.ok) {
97259
+ throw new Error(
97260
+ `HTTP error! status: ${response.status}`,
97261
+ );
97262
+ }
97250
97263
 
97251
- // eslint-disable-next-line ie11/no-loop-func
97252
- this._addresses = nodes.map((node) =>
97253
- NodeAddress.fromJSON({
97254
- nodeId: node.node_id.toString(),
97255
- accountId: node.node_account_id,
97256
- addresses: this._handleAddressesFromGrpcProxyEndpoint(
97257
- node,
97258
- client,
97259
- ),
97260
- certHash: node.node_cert_hash,
97261
- publicKey: node.public_key,
97262
- description: node.description,
97263
- stake: node.stake.toString(),
97264
- }),
97265
- );
97264
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
97265
+ const data = /** @type {AddressBookQueryWebResponse} */ (
97266
+ await response.json()
97267
+ );
97266
97268
 
97267
- const addressBook = new NodeAddressBook({
97268
- nodeAddresses: this._addresses,
97269
- });
97269
+ const nodes = data.nodes || [];
97270
+
97271
+ // Aggregate nodes from this page
97272
+ const pageNodes = nodes.map((node) =>
97273
+ NodeAddress.fromJSON({
97274
+ nodeId: node.node_id.toString(),
97275
+ accountId: node.node_account_id,
97276
+ addresses:
97277
+ this._handleAddressesFromGrpcProxyEndpoint(
97278
+ node,
97279
+ client,
97280
+ ),
97281
+ certHash: node.node_cert_hash,
97282
+ publicKey: node.public_key,
97283
+ description: node.description,
97284
+ stake: node.stake.toString(),
97285
+ }),
97286
+ );
97270
97287
 
97271
- resolve(addressBook);
97272
- return;
97273
- } catch (error) {
97274
- console.error("Error in _makeFetchRequest:", error);
97275
- const message =
97276
- error instanceof Error ? error.message : String(error);
97288
+ this._addresses.push(...pageNodes);
97289
+ nextUrl = data.links?.next || null;
97277
97290
 
97278
- // Check if we should retry
97279
- if (
97280
- attempt < this._maxAttempts &&
97281
- !client.isClientShutDown &&
97282
- this._retryHandler(
97283
- /** @type {MirrorError | Error | null} */ (error),
97284
- )
97285
- ) {
97286
- const delay = Math.min(
97287
- 250 * 2 ** attempt,
97288
- this._maxBackoff,
97289
- );
97291
+ // If no more pages, set flag to exit loop
97292
+ if (!nextUrl) {
97293
+ isLastPage = true;
97294
+ }
97290
97295
 
97291
- if (this._logger) {
97292
- this._logger.debug(
97293
- `Error getting nodes from mirror for file ${
97294
- this._fileId != null
97295
- ? this._fileId.toString()
97296
- : "UNKNOWN"
97297
- } during attempt ${
97298
- attempt + 1
97299
- }. Waiting ${delay} ms before next attempt: ${message}`,
97296
+ // Move to next page
97297
+ break;
97298
+ } catch (error) {
97299
+ console.error("Error in _makeFetchRequest:", error);
97300
+ const message =
97301
+ error instanceof Error ? error.message : String(error);
97302
+
97303
+ // Check if we should retry
97304
+ if (
97305
+ attempt < this._maxAttempts &&
97306
+ !client.isClientShutDown &&
97307
+ this._retryHandler(
97308
+ /** @type {MirrorError | Error | null} */ (error),
97309
+ )
97310
+ ) {
97311
+ const delay = Math.min(
97312
+ 250 * 2 ** attempt,
97313
+ this._maxBackoff,
97300
97314
  );
97315
+
97316
+ if (this._logger) {
97317
+ this._logger.debug(
97318
+ `Error getting nodes from mirror for file ${
97319
+ this._fileId != null
97320
+ ? this._fileId.toString()
97321
+ : "UNKNOWN"
97322
+ } during attempt ${
97323
+ attempt + 1
97324
+ }. Waiting ${delay} ms before next attempt: ${message}`,
97325
+ );
97326
+ }
97327
+
97328
+ // Wait before next attempt
97329
+ // eslint-disable-next-line ie11/no-loop-func
97330
+ await new Promise((resolve) =>
97331
+ setTimeout(resolve, delay),
97332
+ );
97333
+ continue;
97301
97334
  }
97302
97335
 
97303
- // Wait before next attempt
97304
- // eslint-disable-next-line ie11/no-loop-func
97305
- await new Promise((resolve) => setTimeout(resolve, delay));
97306
- continue;
97336
+ // If we shouldn't retry or have exhausted attempts, reject
97337
+ const maxAttemptsReached = attempt >= this._maxAttempts;
97338
+ const errorMessage = maxAttemptsReached
97339
+ ? `Failed to query address book after ${
97340
+ this._maxAttempts + 1
97341
+ } attempts. Last error: ${message}`
97342
+ : `Failed to query address book: ${message}`;
97343
+ reject(new Error(errorMessage));
97344
+ return;
97307
97345
  }
97308
-
97309
- // If we shouldn't retry or have exhausted attempts, reject
97310
- const maxAttemptsReached = attempt >= this._maxAttempts;
97311
- const errorMessage = maxAttemptsReached
97312
- ? `Failed to query address book after ${
97313
- this._maxAttempts + 1
97314
- } attempts. Last error: ${message}`
97315
- : `Failed to query address book: ${message}`;
97316
- reject(new Error(errorMessage));
97317
- return;
97318
97346
  }
97319
97347
  }
97320
97348
 
97321
- // This should never be reached, but just in case
97322
- reject(new Error("failed to query address book"));
97349
+ // Return the aggregated results
97350
+ const addressBook = new NodeAddressBook({
97351
+ nodeAddresses: this._addresses,
97352
+ });
97353
+ resolve(addressBook);
97323
97354
  }
97324
97355
 
97325
97356
  /**
@@ -98257,7 +98288,7 @@
98257
98288
 
98258
98289
  const SDK_NAME = "hiero-sdk-js";
98259
98290
  const SDK_VERSION =
98260
- "2.74.0" ;
98291
+ "2.75.0" ;
98261
98292
 
98262
98293
  // SPDX-License-Identifier: Apache-2.0
98263
98294