postchain-client 2.1.3 → 2.1.5

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,11 +43616,37 @@ function requireUtils$1 () {
43613
43616
  }
43614
43617
  });
43615
43618
  }
43616
- function getSystemClient(directoryNodeUrlPool, directoryChainRid) {
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
+ }
43643
+ function getSystemClient(directoryNodeUrlPool, directoryChainRid, blockedNodeUrlSubstrings, nodeUrlFilter) {
43617
43644
  return __awaiter(this, void 0, void 0, function* () {
43618
43645
  return yield (0, blockchainClient_1.createClient)({
43619
43646
  directoryNodeUrlPool,
43620
43647
  blockchainRid: directoryChainRid,
43648
+ blockedNodeUrlSubstrings,
43649
+ nodeUrlFilter,
43621
43650
  });
43622
43651
  });
43623
43652
  }
@@ -43746,16 +43775,16 @@ function requireUtils$1 () {
43746
43775
  }
43747
43776
  function getAnchoringClientAndSystemChainRid(client) {
43748
43777
  return __awaiter(this, void 0, void 0, function* () {
43749
- const directoryClient = yield getSystemClient((0, exports.getUrlsFromEndpoints)(client.config.endpointPool), client.config.directoryChainRid);
43778
+ const directoryClient = yield getSystemClient((0, exports.getUrlsFromEndpoints)(client.config.endpointPool), client.config.directoryChainRid, client.config.blockedNodeUrlSubstrings, client.config.nodeUrlFilter);
43750
43779
  const anchoringClient = yield (0, IccfProofTxMaterialBuilder_1.getAnchoringClient)(directoryClient, client.config.blockchainRid);
43751
43780
  const systemAnchoringChainRidBuffer = yield getSystemAnchoringChain(directoryClient);
43752
43781
  const systemAnchoringChainBridString = systemAnchoringChainRidBuffer.toString("hex");
43753
43782
  return { anchoringClient, systemAnchoringChainBridString };
43754
43783
  });
43755
43784
  }
43756
- function getSystemAnchoringTransaction(dappClientEndpointPool, anchoredTxRid, anchoringClient, systemAnchoringChainRid, systemAnchoringStatusPolling, merkleHashVersion) {
43785
+ function getSystemAnchoringTransaction(dappClientEndpointPool, anchoredTxRid, anchoringClient, systemAnchoringChainRid, systemAnchoringStatusPolling, merkleHashVersion, blockedNodeUrlSubstrings, nodeUrlFilter) {
43757
43786
  return __awaiter(this, void 0, void 0, function* () {
43758
- const systemAnchoringChainClient = yield getSystemClient((0, exports.getUrlsFromEndpoints)(dappClientEndpointPool), systemAnchoringChainRid);
43787
+ const systemAnchoringChainClient = yield getSystemClient((0, exports.getUrlsFromEndpoints)(dappClientEndpointPool), systemAnchoringChainRid, blockedNodeUrlSubstrings, nodeUrlFilter);
43759
43788
  const clusterAnchoringProof = yield anchoringClient.getConfirmationProof(anchoredTxRid);
43760
43789
  const clusterBlockRid = (0, utils_1.calculateBlockRID)(clusterAnchoringProof, merkleHashVersion);
43761
43790
  const systemAnchoringTransactionConfirmation = yield (0, utils_1.awaitGetAnchoringTransactionForBlockRid)(systemAnchoringChainClient, (0, formatter_1.toBuffer)(anchoringClient.config.blockchainRid), clusterBlockRid, systemAnchoringStatusPolling);
@@ -44131,6 +44160,8 @@ function requireIccfProofTxMaterialBuilder () {
44131
44160
  blockchainRid: (0, formatter_1.ensureString)(sourceBlockchainRid),
44132
44161
  merkleHashVersion: merkleHashVersion,
44133
44162
  useStickyNode: true,
44163
+ blockedNodeUrlSubstrings: directoryClient.config.blockedNodeUrlSubstrings,
44164
+ nodeUrlFilter: directoryClient.config.nodeUrlFilter,
44134
44165
  });
44135
44166
  }
44136
44167
  else {
@@ -44139,6 +44170,8 @@ function requireIccfProofTxMaterialBuilder () {
44139
44170
  blockchainRid: (0, formatter_1.ensureString)(sourceBlockchainRid),
44140
44171
  merkleHashVersion: merkleHashVersion,
44141
44172
  useStickyNode: true,
44173
+ blockedNodeUrlSubstrings: directoryClient.config.blockedNodeUrlSubstrings,
44174
+ nodeUrlFilter: directoryClient.config.nodeUrlFilter,
44142
44175
  });
44143
44176
  }
44144
44177
  const txProof = yield clientConfiguredToSource.getConfirmationProof(txToProveRid);
@@ -44917,7 +44950,7 @@ function requireBlockchainClient () {
44917
44950
  }
44918
44951
  result.status = enums_1.AnchoringStatus.ClusterAnchored;
44919
44952
  result.clusterAnchoredTx = anchoringTransactionValidation.data;
44920
- const systemAnchoredTransaction = yield (0, utils_1.getSystemAnchoringTransaction)(config.endpointPool, anchoringTransactionValidation.data.txRid, anchoringClient, systemAnchoringChainRid, config.systemAnchoringStatusPolling, config.merkleHashVersion);
44953
+ const systemAnchoredTransaction = yield (0, utils_1.getSystemAnchoringTransaction)(config.endpointPool, anchoringTransactionValidation.data.txRid, anchoringClient, systemAnchoringChainRid, config.systemAnchoringStatusPolling, config.merkleHashVersion, config.blockedNodeUrlSubstrings, config.nodeUrlFilter);
44921
44954
  if (!systemAnchoredTransaction) {
44922
44955
  return result;
44923
44956
  }
@@ -45147,7 +45180,7 @@ function requireBlockchainClient () {
45147
45180
  callback === null || callback === void 0 ? void 0 : callback(error, null);
45148
45181
  throw error;
45149
45182
  }
45150
- const systemAnchoringTransactionTransaction = yield (0, utils_1.getSystemAnchoringTransaction)(config.endpointPool, anchoredTxRid, anchoringClient, systemAnchoringChainRid, config.systemAnchoringStatusPolling, config.merkleHashVersion);
45183
+ const systemAnchoringTransactionTransaction = yield (0, utils_1.getSystemAnchoringTransaction)(config.endpointPool, anchoredTxRid, anchoringClient, systemAnchoringChainRid, config.systemAnchoringStatusPolling, config.merkleHashVersion, config.blockedNodeUrlSubstrings, config.nodeUrlFilter);
45151
45184
  return systemAnchoringTransactionTransaction;
45152
45185
  });
45153
45186
  },
@@ -45220,6 +45253,8 @@ function requireBlockchainClient () {
45220
45253
  blockchainRid: client.config.blockchainRid,
45221
45254
  merkleHashVersion: client.config.merkleHashVersion,
45222
45255
  useStickyNode: true,
45256
+ blockedNodeUrlSubstrings: client.config.blockedNodeUrlSubstrings,
45257
+ nodeUrlFilter: client.config.nodeUrlFilter,
45223
45258
  });
45224
45259
  return stickyNodeClient;
45225
45260
  });