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.
@@ -42001,7 +42001,7 @@ var utils$1 = {};
42001
42001
  var errors = {};
42002
42002
 
42003
42003
  Object.defineProperty(errors, "__esModule", { value: true });
42004
- 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;
42004
+ 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;
42005
42005
  const customError_1 = customError;
42006
42006
  const formatter_1$1 = formatter;
42007
42007
  class MissingPubKeyError extends customError_1.CustomError {
@@ -42035,6 +42035,12 @@ class DirectoryNodeUrlPoolException extends customError_1.CustomError {
42035
42035
  }
42036
42036
  }
42037
42037
  errors.DirectoryNodeUrlPoolException = DirectoryNodeUrlPoolException;
42038
+ class FilteredNodeUrlPoolEmptyError extends customError_1.CustomError {
42039
+ constructor(poolName) {
42040
+ super(`All node URLs were filtered out for pool "${poolName}". Update node URL filters or pool configuration.`, 400);
42041
+ }
42042
+ }
42043
+ errors.FilteredNodeUrlPoolEmptyError = FilteredNodeUrlPoolEmptyError;
42038
42044
  class InvalidTransactionFormatException extends customError_1.CustomError {
42039
42045
  constructor() {
42040
42046
  super(`The transaction is not in the right format`, 400);
@@ -43362,23 +43368,9 @@ function requireUtils$1 () {
43362
43368
  responseTimeout: settings.responseTimeout,
43363
43369
  });
43364
43370
  }))();
43365
- return {
43366
- endpointPool,
43367
- nodeManager: nodeManager,
43368
- blockchainRid: blockchainRidToUse,
43369
- merkleHashVersion: (_e = settings.merkleHashVersion) !== null && _e !== void 0 ? _e : constants_1.MERKLE_HASH_VERSIONS.UNSET,
43370
- dappStatusPolling: setStatusPolling(settings.dappStatusPolling),
43371
- clusterAnchoringStatusPolling: setStatusPolling(settings.clusterAnchoringStatusPolling),
43372
- systemAnchoringStatusPolling: setStatusPolling(settings.systemAnchoringStatusPolling),
43373
- retryTransactionPolling: setRetryTransactionPolling(settings.retryTransactionPolling),
43374
- failoverStrategy: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.strategy) || exports.defaultFailoverConfig.strategy,
43375
- attemptsPerEndpoint: ((_g = settings.failOverConfig) === null || _g === void 0 ? void 0 : _g.attemptsPerEndpoint) || exports.defaultFailoverConfig.attemptsPerEndpoint,
43376
- attemptInterval: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.attemptInterval) || exports.defaultFailoverConfig.attemptInterval,
43377
- unreachableDuration: ((_j = settings.failOverConfig) === null || _j === void 0 ? void 0 : _j.unreachableDuration) || exports.defaultFailoverConfig.unreachableDuration,
43378
- directoryChainRid: settings.directoryChainRid || directoryChainRid,
43379
- connectTimeout: settings.connectTimeout,
43380
- responseTimeout: settings.responseTimeout,
43381
- };
43371
+ return Object.assign(Object.assign(Object.assign({ endpointPool, nodeManager: nodeManager }, (settings.blockedNodeUrlSubstrings !== undefined
43372
+ ? { blockedNodeUrlSubstrings: settings.blockedNodeUrlSubstrings }
43373
+ : {})), (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 });
43382
43374
  });
43383
43375
  }
43384
43376
  function getMerkleHashVersionFromDapp(config) {
@@ -43404,7 +43396,7 @@ function requireUtils$1 () {
43404
43396
  return true;
43405
43397
  }
43406
43398
  function nodeDiscovery(_a) {
43407
- return __awaiter(this, arguments, void 0, function* ({ nodeManager, directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid, connectTimeout, responseTimeout, }) {
43399
+ return __awaiter(this, arguments, void 0, function* ({ nodeManager, directoryEndpointPool, blockedNodeUrlSubstrings, nodeUrlFilter, failOverConfig, blockchainRid, blockchainIid, connectTimeout, responseTimeout, }) {
43408
43400
  if (directoryEndpointPool.length === 0) {
43409
43401
  throw new errors_2.DirectoryNodeUrlPoolException();
43410
43402
  }
@@ -43440,7 +43432,11 @@ function requireUtils$1 () {
43440
43432
  nodeUrlPool: (0, exports.getUrlsFromEndpoints)(directoryEndpointPool),
43441
43433
  blockchainRid: directoryBRID,
43442
43434
  });
43443
- return yield getBlockchainApiUrls(D1Client, (0, formatter_1.ensureBuffer)(blockchainRidToUse));
43435
+ const discoveredNodes = yield getBlockchainApiUrls(D1Client, (0, formatter_1.ensureBuffer)(blockchainRidToUse));
43436
+ return applyNodeUrlFilters(discoveredNodes, {
43437
+ blockedNodeUrlSubstrings,
43438
+ nodeUrlFilter,
43439
+ }, "discoveredNodeUrlPool");
43444
43440
  });
43445
43441
  }
43446
43442
  function getBlockchainApiUrls(directoryClient, blockchainRid) {
@@ -43583,14 +43579,21 @@ function requireUtils$1 () {
43583
43579
  return __awaiter(this, void 0, void 0, function* () {
43584
43580
  var _a;
43585
43581
  if (settings.directoryNodeUrlPool) {
43582
+ const directoryNodeUrlsOrNull = applyNodeUrlFilters(ensureArray(settings.directoryNodeUrlPool), settings, "directoryNodeUrlPool");
43583
+ if (directoryNodeUrlsOrNull === null) {
43584
+ throw new errors_2.DirectoryNodeUrlPoolException();
43585
+ }
43586
+ const directoryNodeUrls = directoryNodeUrlsOrNull;
43586
43587
  // If directoryNodeUrlPool is provided, use nodeDiscovery
43587
43588
  const nodeManager = (0, nodeManager_1.createNodeManager)({
43588
- nodeUrls: ensureArray(settings.directoryNodeUrlPool),
43589
+ nodeUrls: directoryNodeUrls,
43589
43590
  unavailableDuration: (_a = settings.failOverConfig) === null || _a === void 0 ? void 0 : _a.unreachableDuration,
43590
43591
  });
43591
43592
  const discoveredNodes = yield nodeDiscovery({
43592
43593
  nodeManager,
43593
- directoryEndpointPool: (0, exports.createEndpointObjects)(ensureArray(settings.directoryNodeUrlPool)),
43594
+ directoryEndpointPool: (0, exports.createEndpointObjects)(directoryNodeUrls),
43595
+ blockedNodeUrlSubstrings: settings.blockedNodeUrlSubstrings,
43596
+ nodeUrlFilter: settings.nodeUrlFilter,
43594
43597
  failOverConfig: settings.failOverConfig,
43595
43598
  blockchainRid: settings.blockchainRid,
43596
43599
  blockchainIid: settings.blockchainIid,
@@ -43601,11 +43604,11 @@ function requireUtils$1 () {
43601
43604
  }
43602
43605
  else if (typeof settings.nodeUrlPool === "string") {
43603
43606
  // If nodeUrlPool is a string, convert it to an array
43604
- return [settings.nodeUrlPool];
43607
+ return applyNodeUrlFilters([settings.nodeUrlPool], settings, "nodeUrlPool");
43605
43608
  }
43606
43609
  else if (Array.isArray(settings.nodeUrlPool)) {
43607
43610
  // If nodeUrlPool is already an array, use it as-is
43608
- return settings.nodeUrlPool;
43611
+ return applyNodeUrlFilters(settings.nodeUrlPool, settings, "nodeUrlPool");
43609
43612
  }
43610
43613
  else {
43611
43614
  // Default to an empty array if no valid configuration is provided
@@ -43613,6 +43616,30 @@ function requireUtils$1 () {
43613
43616
  }
43614
43617
  });
43615
43618
  }
43619
+ function applyNodeUrlFilters(nodeUrls, settings, poolName) {
43620
+ var _a;
43621
+ if (nodeUrls === null) {
43622
+ return null;
43623
+ }
43624
+ const hasBlockedSubstringsFilter = Array.isArray(settings.blockedNodeUrlSubstrings) &&
43625
+ settings.blockedNodeUrlSubstrings.length > 0;
43626
+ const hasNodeUrlFilter = typeof settings.nodeUrlFilter === "function";
43627
+ if (!hasBlockedSubstringsFilter && !hasNodeUrlFilter) {
43628
+ return nodeUrls;
43629
+ }
43630
+ const blockedSubstrings = ((_a = settings.blockedNodeUrlSubstrings) !== null && _a !== void 0 ? _a : [])
43631
+ .map(substring => substring.toLowerCase())
43632
+ .filter(substring => substring.length > 0);
43633
+ const filteredNodeUrls = nodeUrls.filter(url => {
43634
+ const isBlockedBySubstring = blockedSubstrings.some(substring => url.toLowerCase().includes(substring));
43635
+ const passesCustomFilter = settings.nodeUrlFilter ? settings.nodeUrlFilter(url) : true;
43636
+ return !isBlockedBySubstring && passesCustomFilter;
43637
+ });
43638
+ if (filteredNodeUrls.length === 0) {
43639
+ throw new errors_2.FilteredNodeUrlPoolEmptyError(poolName);
43640
+ }
43641
+ return filteredNodeUrls;
43642
+ }
43616
43643
  function getSystemClient(directoryNodeUrlPool, directoryChainRid) {
43617
43644
  return __awaiter(this, void 0, void 0, function* () {
43618
43645
  return yield (0, blockchainClient_1.createClient)({
@@ -44131,6 +44158,8 @@ function requireIccfProofTxMaterialBuilder () {
44131
44158
  blockchainRid: (0, formatter_1.ensureString)(sourceBlockchainRid),
44132
44159
  merkleHashVersion: merkleHashVersion,
44133
44160
  useStickyNode: true,
44161
+ blockedNodeUrlSubstrings: directoryClient.config.blockedNodeUrlSubstrings,
44162
+ nodeUrlFilter: directoryClient.config.nodeUrlFilter,
44134
44163
  });
44135
44164
  }
44136
44165
  else {
@@ -44139,6 +44168,8 @@ function requireIccfProofTxMaterialBuilder () {
44139
44168
  blockchainRid: (0, formatter_1.ensureString)(sourceBlockchainRid),
44140
44169
  merkleHashVersion: merkleHashVersion,
44141
44170
  useStickyNode: true,
44171
+ blockedNodeUrlSubstrings: directoryClient.config.blockedNodeUrlSubstrings,
44172
+ nodeUrlFilter: directoryClient.config.nodeUrlFilter,
44142
44173
  });
44143
44174
  }
44144
44175
  const txProof = yield clientConfiguredToSource.getConfirmationProof(txToProveRid);