@steemit/steem-js 1.0.8 → 1.0.9

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/README.md CHANGED
@@ -40,7 +40,7 @@ import { steem } from '@steemit/steem-js';
40
40
 
41
41
  // Configure API endpoint
42
42
  steem.config.set({
43
- node: 'https://api.steemit.com',
43
+ nodes: ['https://api.steemit.com'],
44
44
  address_prefix: 'STM'
45
45
  });
46
46
 
@@ -58,7 +58,7 @@ await steem.broadcast.voteAsync(postingWif, 'voter', 'author', 'permlink', 10000
58
58
  ```html
59
59
  <script src="https://cdn.jsdelivr.net/npm/@steemit/steem-js/dist/index.umd.min.js"></script>
60
60
  <script>
61
- steem.config.set({ node: 'https://api.steemit.com' });
61
+ steem.config.set({ nodes: ['https://api.steemit.com'] });
62
62
  steem.api.getAccountsAsync(['username']).then(console.log);
63
63
  </script>
64
64
  ```
@@ -3,7 +3,6 @@ import type { Transport } from './transports/types';
3
3
  import type { TransportOptions } from './transports/types';
4
4
  interface ApiOptions {
5
5
  url?: string;
6
- uri?: string;
7
6
  transport?: string | (new (options: TransportOptions) => Transport);
8
7
  logger?: Logger;
9
8
  useTestNet?: boolean;
@@ -38,7 +37,7 @@ export declare class Api extends EventEmitter {
38
37
  */
39
38
  verifySignedRequest(signedRequest: unknown, callback: (err: Error | null, result?: unknown) => void): void;
40
39
  setOptions(options: ApiOptions): void;
41
- setUri(url: string): void;
40
+ setUrl(url: string): void;
42
41
  streamBlockNumber(mode?: string | ((err: Error | null, blockNumber?: unknown) => void), callback?: (err: Error | null, blockNumber?: unknown) => void, ts?: number): () => void;
43
42
  streamBlock(mode: string | undefined, callback: (err: Error | null, block?: unknown) => void): () => void;
44
43
  streamTransactions(mode?: string | ((err: Error | null, tx?: unknown) => void), callback?: (err: Error | null, tx?: unknown) => void): () => void;
@@ -4,13 +4,13 @@ import { BaseTransport } from './base';
4
4
  * Makes a JSON-RPC request using native fetch API
5
5
  * Universal implementation that works in both Node.js (18+) and browser
6
6
  *
7
- * @param uri - The URI to the JSON-RPC endpoint
7
+ * @param url - The URL to the JSON-RPC endpoint
8
8
  * @param request - The JSON-RPC request object
9
9
  * @param fetchMethod - Optional fetch implementation (defaults to global fetch)
10
10
  * @param timeoutMs - Request timeout in milliseconds (default: 30000)
11
11
  * @returns Promise resolving to the JSON-RPC result
12
12
  */
13
- export declare const jsonRpc: (uri: string, request: Partial<JsonRpcRequest>, fetchMethod?: typeof fetch, timeoutMs?: number) => Promise<unknown>;
13
+ export declare const jsonRpc: (url: string, request: Partial<JsonRpcRequest>, fetchMethod?: typeof fetch, timeoutMs?: number) => Promise<unknown>;
14
14
  export declare class HttpTransport extends BaseTransport {
15
15
  constructor(options: TransportOptions);
16
16
  get nonRetriableOperations(): string[];
@@ -1,11 +1,10 @@
1
1
  export interface TransportOptions {
2
2
  url?: string;
3
- uri?: string;
4
3
  /**
5
4
  * WebSocket URL
6
5
  * NOTE: WebSocket functionality is currently not supported.
7
6
  * This field is kept for backward compatibility only.
8
- * Please use HTTP transport (via url or uri field) for API calls.
7
+ * Please use HTTP transport (via url field) for API calls.
9
8
  */
10
9
  websocket?: string;
11
10
  transport?: string | unknown;
@@ -551,12 +551,10 @@ class Config {
551
551
  const DEFAULT_CONFIG = {
552
552
  address_prefix: 'STM',
553
553
  chain_id: '0000000000000000000000000000000000000000000000000000000000000000',
554
- // Default API endpoint: api.steemit.com
555
- node: 'https://api.steemit.com',
554
+ // Default API endpoints: api.steemit.com
556
555
  nodes: [
557
556
  'https://api.steemit.com'
558
- ],
559
- uri: 'https://api.steemit.com'
557
+ ]
560
558
  };
561
559
  // Singleton config instance
562
560
  const config = new Config();
@@ -18601,13 +18599,13 @@ class JsonRpcError extends Error {
18601
18599
  * Makes a JSON-RPC request using native fetch API
18602
18600
  * Universal implementation that works in both Node.js (18+) and browser
18603
18601
  *
18604
- * @param uri - The URI to the JSON-RPC endpoint
18602
+ * @param url - The URL to the JSON-RPC endpoint
18605
18603
  * @param request - The JSON-RPC request object
18606
18604
  * @param fetchMethod - Optional fetch implementation (defaults to global fetch)
18607
18605
  * @param timeoutMs - Request timeout in milliseconds (default: 30000)
18608
18606
  * @returns Promise resolving to the JSON-RPC result
18609
18607
  */
18610
- const jsonRpc = async (uri, request, fetchMethod = fetch, timeoutMs = 30000) => {
18608
+ const jsonRpc = async (url, request, fetchMethod = fetch, timeoutMs = 30000) => {
18611
18609
  const payload = {
18612
18610
  jsonrpc: '2.0',
18613
18611
  ...request
@@ -18620,7 +18618,7 @@ const jsonRpc = async (uri, request, fetchMethod = fetch, timeoutMs = 30000) =>
18620
18618
  }, timeoutMs);
18621
18619
  });
18622
18620
  // Create the fetch promise
18623
- const fetchPromise = fetchMethod(uri, {
18621
+ const fetchPromise = fetchMethod(url, {
18624
18622
  method: 'POST',
18625
18623
  headers: {
18626
18624
  'Content-Type': 'application/json',
@@ -18669,9 +18667,9 @@ class HttpTransport extends BaseTransport {
18669
18667
  if (typeof callback !== 'function') {
18670
18668
  callback = () => { };
18671
18669
  }
18672
- const uri = this.options.uri;
18673
- if (!uri) {
18674
- throw new Error('HTTP transport requires a valid URI');
18670
+ const url = this.options.url;
18671
+ if (!url) {
18672
+ throw new Error('HTTP transport requires a valid URL');
18675
18673
  }
18676
18674
  const fetchMethod = this.options.fetchMethod || fetch;
18677
18675
  const id = data.id;
@@ -18682,7 +18680,7 @@ class HttpTransport extends BaseTransport {
18682
18680
  if (!isBroadcast && retryOptions) {
18683
18681
  const operation = typeof retryOptions === 'object' ? retry.operation(retryOptions) : retry.operation();
18684
18682
  operation.attempt((currentAttempt) => {
18685
- fetchMethod(uri, {
18683
+ fetchMethod(url, {
18686
18684
  method: 'POST',
18687
18685
  body: JSON.stringify({
18688
18686
  jsonrpc: '2.0',
@@ -18716,7 +18714,7 @@ class HttpTransport extends BaseTransport {
18716
18714
  });
18717
18715
  }
18718
18716
  else {
18719
- fetchMethod(uri, {
18717
+ fetchMethod(url, {
18720
18718
  method: 'POST',
18721
18719
  body: JSON.stringify({
18722
18720
  jsonrpc: '2.0',
@@ -25947,7 +25945,6 @@ class Api extends eventsExports.EventEmitter {
25947
25945
  _setTransport(options) {
25948
25946
  // Use HTTP transport only
25949
25947
  if (options.url && options.url.match(/^((http|https)?:\/\/)/)) {
25950
- options.uri = options.url;
25951
25948
  options.transport = 'http';
25952
25949
  this._transportType = options.transport;
25953
25950
  this.options = options;
@@ -25973,9 +25970,10 @@ class Api extends eventsExports.EventEmitter {
25973
25970
  }
25974
25971
  }
25975
25972
  else {
25976
- // Default to HTTP for https://api.steemit.com
25977
- const defaultNode = getConfig().get('node') || 'https://api.steemit.com';
25978
- options.uri = defaultNode;
25973
+ // Default to HTTP using first node from config.nodes
25974
+ const nodes = getConfig().get('nodes') || ['https://api.steemit.com'];
25975
+ const defaultNode = nodes[0] || 'https://api.steemit.com';
25976
+ options.url = defaultNode;
25979
25977
  options.transport = 'http';
25980
25978
  this._transportType = options.transport;
25981
25979
  this.options = options;
@@ -26058,7 +26056,7 @@ class Api extends eventsExports.EventEmitter {
26058
26056
  }
26059
26057
  const id = ++this.seqNo;
26060
26058
  const fetchMethod = this.options.fetchMethod || fetch;
26061
- jsonRpc(this.options.uri, { method, params, id }, fetchMethod)
26059
+ jsonRpc(this.options.url, { method, params, id }, fetchMethod)
26062
26060
  .then(res => { callback(null, res); }, err => { callback(err); });
26063
26061
  }
26064
26062
  signedCall(method, params, account, key, callback) {
@@ -26076,7 +26074,7 @@ class Api extends eventsExports.EventEmitter {
26076
26074
  return;
26077
26075
  }
26078
26076
  const fetchMethod = this.options.fetchMethod || fetch;
26079
- jsonRpc(this.options.uri, request, fetchMethod)
26077
+ jsonRpc(this.options.url, request, fetchMethod)
26080
26078
  .then(res => { callback(null, res); }, err => { callback(err); });
26081
26079
  }
26082
26080
  /**
@@ -26153,9 +26151,9 @@ class Api extends eventsExports.EventEmitter {
26153
26151
  getConfig().set('address_prefix', options.useTestNet ? 'TST' : 'STM');
26154
26152
  }
26155
26153
  }
26156
- setUri(url) {
26154
+ setUrl(url) {
26157
26155
  this.setOptions({
26158
- uri: url
26156
+ url: url
26159
26157
  });
26160
26158
  }
26161
26159
  streamBlockNumber(mode = 'head', callback, ts = 200) {
@@ -26485,15 +26483,17 @@ class Api extends eventsExports.EventEmitter {
26485
26483
  }
26486
26484
  }
26487
26485
  // Export singleton instance for compatibility
26488
- const api$1 = new Api({ uri: getConfig().get('uri') || 'https://api.steemit.com' });
26486
+ // Use first node from config.nodes array
26487
+ const nodes = getConfig().get('nodes') || ['https://api.steemit.com'];
26488
+ const api = new Api({ url: nodes[0] || 'https://api.steemit.com' });
26489
26489
  function setOptions(options) {
26490
- api$1.setOptions(options);
26490
+ api.setOptions(options);
26491
26491
  }
26492
26492
  // Export async variants and listeners for compatibility with tests
26493
- api$1.getDynamicGlobalPropertiesAsync;
26494
- api$1.getBlockAsync;
26495
- api$1.getFollowersAsync;
26496
- api$1.getContentAsync;
26493
+ api.getDynamicGlobalPropertiesAsync;
26494
+ api.getBlockAsync;
26495
+ api.getFollowersAsync;
26496
+ api.getContentAsync;
26497
26497
 
26498
26498
  const operations$1 = [
26499
26499
  {
@@ -28901,8 +28901,8 @@ const verify = (message, signature, publicKey) => {
28901
28901
  }
28902
28902
  };
28903
28903
 
28904
- // Create the API instance
28905
- const api = new Api();
28904
+ // Use the singleton API instance exported from api module
28905
+ // This ensures steem.api and setOptions() operate on the same instance
28906
28906
  // Create the main steem object with all modules
28907
28907
  const steem = {
28908
28908
  api,
@@ -28913,10 +28913,15 @@ const steem = {
28913
28913
  operations,
28914
28914
  serializer,
28915
28915
  utils: utils$3,
28916
- version: '1.0.8',
28916
+ version: '1.0.9',
28917
28917
  config: {
28918
28918
  set: (options) => {
28919
- setOptions(options);
28919
+ // If nodes is provided, extract the first node as url for API
28920
+ const apiOptions = { ...options };
28921
+ if (options.nodes && Array.isArray(options.nodes) && options.nodes.length > 0) {
28922
+ apiOptions.url = options.nodes[0];
28923
+ }
28924
+ setOptions(apiOptions);
28920
28925
  setOptions$1(options);
28921
28926
  },
28922
28927
  get: (key) => getConfig().get(key),
@@ -28948,5 +28953,5 @@ if (typeof window !== 'undefined' || typeof globalThis !== 'undefined') {
28948
28953
  }
28949
28954
  }
28950
28955
 
28951
- export { doubleSha256, generateKeyPair, hmacSha256, ripemd160, sha256, sign, steem, verify };
28956
+ export { Api, doubleSha256, generateKeyPair, hmacSha256, ripemd160, sha256, sign, steem, verify };
28952
28957
  //# sourceMappingURL=browser.esm.js.map