postchain-client 2.1.3 → 2.1.4

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.
@@ -39186,7 +39186,7 @@
39186
39186
  var errors = {};
39187
39187
 
39188
39188
  Object.defineProperty(errors, "__esModule", { value: true });
39189
- errors.GetBridFromChainException = errors.SerializedTransactionFormatException = errors.InvalidTxRidException = errors.UnexpectedStatusError = errors.TxRejectedError = errors.GetTransactionRidException = errors.InvalidTransactionFormatException = errors.DirectoryNodeUrlPoolException = errors.BlockchainUrlUndefinedException = errors.MissingNodeUrlError = errors.MissingBlockchainIdentifierError = errors.MissingPubKeyError = void 0;
39189
+ errors.GetBridFromChainException = errors.SerializedTransactionFormatException = errors.InvalidTxRidException = errors.UnexpectedStatusError = errors.TxRejectedError = errors.GetTransactionRidException = errors.InvalidTransactionFormatException = errors.FilteredNodeUrlPoolEmptyError = errors.DirectoryNodeUrlPoolException = errors.BlockchainUrlUndefinedException = errors.MissingNodeUrlError = errors.MissingBlockchainIdentifierError = errors.MissingPubKeyError = void 0;
39190
39190
  const customError_1 = customError;
39191
39191
  const formatter_1$1 = formatter;
39192
39192
  class MissingPubKeyError extends customError_1.CustomError {
@@ -39220,6 +39220,12 @@
39220
39220
  }
39221
39221
  }
39222
39222
  errors.DirectoryNodeUrlPoolException = DirectoryNodeUrlPoolException;
39223
+ class FilteredNodeUrlPoolEmptyError extends customError_1.CustomError {
39224
+ constructor(poolName) {
39225
+ super(`All node URLs were filtered out for pool "${poolName}". Update node URL filters or pool configuration.`, 400);
39226
+ }
39227
+ }
39228
+ errors.FilteredNodeUrlPoolEmptyError = FilteredNodeUrlPoolEmptyError;
39223
39229
  class InvalidTransactionFormatException extends customError_1.CustomError {
39224
39230
  constructor() {
39225
39231
  super(`The transaction is not in the right format`, 400);
@@ -40547,23 +40553,9 @@
40547
40553
  responseTimeout: settings.responseTimeout,
40548
40554
  });
40549
40555
  }))();
40550
- return {
40551
- endpointPool,
40552
- nodeManager: nodeManager,
40553
- blockchainRid: blockchainRidToUse,
40554
- merkleHashVersion: (_e = settings.merkleHashVersion) !== null && _e !== void 0 ? _e : constants_1.MERKLE_HASH_VERSIONS.UNSET,
40555
- dappStatusPolling: setStatusPolling(settings.dappStatusPolling),
40556
- clusterAnchoringStatusPolling: setStatusPolling(settings.clusterAnchoringStatusPolling),
40557
- systemAnchoringStatusPolling: setStatusPolling(settings.systemAnchoringStatusPolling),
40558
- retryTransactionPolling: setRetryTransactionPolling(settings.retryTransactionPolling),
40559
- failoverStrategy: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.strategy) || exports.defaultFailoverConfig.strategy,
40560
- attemptsPerEndpoint: ((_g = settings.failOverConfig) === null || _g === void 0 ? void 0 : _g.attemptsPerEndpoint) || exports.defaultFailoverConfig.attemptsPerEndpoint,
40561
- attemptInterval: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.attemptInterval) || exports.defaultFailoverConfig.attemptInterval,
40562
- unreachableDuration: ((_j = settings.failOverConfig) === null || _j === void 0 ? void 0 : _j.unreachableDuration) || exports.defaultFailoverConfig.unreachableDuration,
40563
- directoryChainRid: settings.directoryChainRid || directoryChainRid,
40564
- connectTimeout: settings.connectTimeout,
40565
- responseTimeout: settings.responseTimeout,
40566
- };
40556
+ return Object.assign(Object.assign(Object.assign({ endpointPool, nodeManager: nodeManager }, (settings.blockedNodeUrlSubstrings !== undefined
40557
+ ? { blockedNodeUrlSubstrings: settings.blockedNodeUrlSubstrings }
40558
+ : {})), (settings.nodeUrlFilter !== undefined ? { nodeUrlFilter: settings.nodeUrlFilter } : {})), { blockchainRid: blockchainRidToUse, merkleHashVersion: (_e = settings.merkleHashVersion) !== null && _e !== void 0 ? _e : constants_1.MERKLE_HASH_VERSIONS.UNSET, dappStatusPolling: setStatusPolling(settings.dappStatusPolling), clusterAnchoringStatusPolling: setStatusPolling(settings.clusterAnchoringStatusPolling), systemAnchoringStatusPolling: setStatusPolling(settings.systemAnchoringStatusPolling), retryTransactionPolling: setRetryTransactionPolling(settings.retryTransactionPolling), failoverStrategy: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.strategy) || exports.defaultFailoverConfig.strategy, attemptsPerEndpoint: ((_g = settings.failOverConfig) === null || _g === void 0 ? void 0 : _g.attemptsPerEndpoint) || exports.defaultFailoverConfig.attemptsPerEndpoint, attemptInterval: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.attemptInterval) || exports.defaultFailoverConfig.attemptInterval, unreachableDuration: ((_j = settings.failOverConfig) === null || _j === void 0 ? void 0 : _j.unreachableDuration) || exports.defaultFailoverConfig.unreachableDuration, directoryChainRid: settings.directoryChainRid || directoryChainRid, connectTimeout: settings.connectTimeout, responseTimeout: settings.responseTimeout });
40567
40559
  });
40568
40560
  }
40569
40561
  function getMerkleHashVersionFromDapp(config) {
@@ -40589,7 +40581,7 @@
40589
40581
  return true;
40590
40582
  }
40591
40583
  function nodeDiscovery(_a) {
40592
- return __awaiter(this, arguments, void 0, function* ({ nodeManager, directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid, connectTimeout, responseTimeout, }) {
40584
+ return __awaiter(this, arguments, void 0, function* ({ nodeManager, directoryEndpointPool, blockedNodeUrlSubstrings, nodeUrlFilter, failOverConfig, blockchainRid, blockchainIid, connectTimeout, responseTimeout, }) {
40593
40585
  if (directoryEndpointPool.length === 0) {
40594
40586
  throw new errors_2.DirectoryNodeUrlPoolException();
40595
40587
  }
@@ -40625,7 +40617,11 @@
40625
40617
  nodeUrlPool: (0, exports.getUrlsFromEndpoints)(directoryEndpointPool),
40626
40618
  blockchainRid: directoryBRID,
40627
40619
  });
40628
- return yield getBlockchainApiUrls(D1Client, (0, formatter_1.ensureBuffer)(blockchainRidToUse));
40620
+ const discoveredNodes = yield getBlockchainApiUrls(D1Client, (0, formatter_1.ensureBuffer)(blockchainRidToUse));
40621
+ return applyNodeUrlFilters(discoveredNodes, {
40622
+ blockedNodeUrlSubstrings,
40623
+ nodeUrlFilter,
40624
+ }, "discoveredNodeUrlPool");
40629
40625
  });
40630
40626
  }
40631
40627
  function getBlockchainApiUrls(directoryClient, blockchainRid) {
@@ -40768,14 +40764,21 @@
40768
40764
  return __awaiter(this, void 0, void 0, function* () {
40769
40765
  var _a;
40770
40766
  if (settings.directoryNodeUrlPool) {
40767
+ const directoryNodeUrlsOrNull = applyNodeUrlFilters(ensureArray(settings.directoryNodeUrlPool), settings, "directoryNodeUrlPool");
40768
+ if (directoryNodeUrlsOrNull === null) {
40769
+ throw new errors_2.DirectoryNodeUrlPoolException();
40770
+ }
40771
+ const directoryNodeUrls = directoryNodeUrlsOrNull;
40771
40772
  // If directoryNodeUrlPool is provided, use nodeDiscovery
40772
40773
  const nodeManager = (0, nodeManager_1.createNodeManager)({
40773
- nodeUrls: ensureArray(settings.directoryNodeUrlPool),
40774
+ nodeUrls: directoryNodeUrls,
40774
40775
  unavailableDuration: (_a = settings.failOverConfig) === null || _a === void 0 ? void 0 : _a.unreachableDuration,
40775
40776
  });
40776
40777
  const discoveredNodes = yield nodeDiscovery({
40777
40778
  nodeManager,
40778
- directoryEndpointPool: (0, exports.createEndpointObjects)(ensureArray(settings.directoryNodeUrlPool)),
40779
+ directoryEndpointPool: (0, exports.createEndpointObjects)(directoryNodeUrls),
40780
+ blockedNodeUrlSubstrings: settings.blockedNodeUrlSubstrings,
40781
+ nodeUrlFilter: settings.nodeUrlFilter,
40779
40782
  failOverConfig: settings.failOverConfig,
40780
40783
  blockchainRid: settings.blockchainRid,
40781
40784
  blockchainIid: settings.blockchainIid,
@@ -40786,11 +40789,11 @@
40786
40789
  }
40787
40790
  else if (typeof settings.nodeUrlPool === "string") {
40788
40791
  // If nodeUrlPool is a string, convert it to an array
40789
- return [settings.nodeUrlPool];
40792
+ return applyNodeUrlFilters([settings.nodeUrlPool], settings, "nodeUrlPool");
40790
40793
  }
40791
40794
  else if (Array.isArray(settings.nodeUrlPool)) {
40792
40795
  // If nodeUrlPool is already an array, use it as-is
40793
- return settings.nodeUrlPool;
40796
+ return applyNodeUrlFilters(settings.nodeUrlPool, settings, "nodeUrlPool");
40794
40797
  }
40795
40798
  else {
40796
40799
  // Default to an empty array if no valid configuration is provided
@@ -40798,6 +40801,30 @@
40798
40801
  }
40799
40802
  });
40800
40803
  }
40804
+ function applyNodeUrlFilters(nodeUrls, settings, poolName) {
40805
+ var _a;
40806
+ if (nodeUrls === null) {
40807
+ return null;
40808
+ }
40809
+ const hasBlockedSubstringsFilter = Array.isArray(settings.blockedNodeUrlSubstrings) &&
40810
+ settings.blockedNodeUrlSubstrings.length > 0;
40811
+ const hasNodeUrlFilter = typeof settings.nodeUrlFilter === "function";
40812
+ if (!hasBlockedSubstringsFilter && !hasNodeUrlFilter) {
40813
+ return nodeUrls;
40814
+ }
40815
+ const blockedSubstrings = ((_a = settings.blockedNodeUrlSubstrings) !== null && _a !== void 0 ? _a : [])
40816
+ .map(substring => substring.toLowerCase())
40817
+ .filter(substring => substring.length > 0);
40818
+ const filteredNodeUrls = nodeUrls.filter(url => {
40819
+ const isBlockedBySubstring = blockedSubstrings.some(substring => url.toLowerCase().includes(substring));
40820
+ const passesCustomFilter = settings.nodeUrlFilter ? settings.nodeUrlFilter(url) : true;
40821
+ return !isBlockedBySubstring && passesCustomFilter;
40822
+ });
40823
+ if (filteredNodeUrls.length === 0) {
40824
+ throw new errors_2.FilteredNodeUrlPoolEmptyError(poolName);
40825
+ }
40826
+ return filteredNodeUrls;
40827
+ }
40801
40828
  function getSystemClient(directoryNodeUrlPool, directoryChainRid) {
40802
40829
  return __awaiter(this, void 0, void 0, function* () {
40803
40830
  return yield (0, blockchainClient_1.createClient)({
@@ -41316,6 +41343,8 @@
41316
41343
  blockchainRid: (0, formatter_1.ensureString)(sourceBlockchainRid),
41317
41344
  merkleHashVersion: merkleHashVersion,
41318
41345
  useStickyNode: true,
41346
+ blockedNodeUrlSubstrings: directoryClient.config.blockedNodeUrlSubstrings,
41347
+ nodeUrlFilter: directoryClient.config.nodeUrlFilter,
41319
41348
  });
41320
41349
  }
41321
41350
  else {
@@ -41324,6 +41353,8 @@
41324
41353
  blockchainRid: (0, formatter_1.ensureString)(sourceBlockchainRid),
41325
41354
  merkleHashVersion: merkleHashVersion,
41326
41355
  useStickyNode: true,
41356
+ blockedNodeUrlSubstrings: directoryClient.config.blockedNodeUrlSubstrings,
41357
+ nodeUrlFilter: directoryClient.config.nodeUrlFilter,
41327
41358
  });
41328
41359
  }
41329
41360
  const txProof = yield clientConfiguredToSource.getConfirmationProof(txToProveRid);