@healchain/sdk 0.4.0 → 0.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@healchain/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "JavaScript SDK for HealChain — self-healing decentralized storage via Reed-Solomon erasure coding",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
package/src/index.js CHANGED
@@ -64,7 +64,8 @@ class HealChain {
64
64
  * @param {number} [options.pollTimeout] - Fulfillment poll timeout in ms
65
65
  * @param {number} [options.dataShards] - Default RS data shards
66
66
  * @param {number} [options.parityShards] - Default RS parity shards
67
- * @param {string} [options.network] - Chain name, 'auto' (default), or specific chain
67
+ * @param {string} [options.chain] - Chain name, 'auto' (default), or specific chain
68
+ * @param {string} [options.network] - Deprecated: use chain instead
68
69
  * @param {string} [options.preference] - 'cheapest' | 'fastest' | 'redundant' | '' (auto weighted)
69
70
  */
70
71
  constructor(options = {}) {
@@ -74,7 +75,8 @@ class HealChain {
74
75
  this.pollTimeout = options.pollTimeout ?? DEFAULT_POLL_TIMEOUT;
75
76
  this.dataShards = options.dataShards ?? DEFAULT_DATA_SHARDS;
76
77
  this.parityShards = options.parityShards ?? DEFAULT_PARITY_SHARDS;
77
- this.network = options.network ?? 'auto';
78
+ this.chain = options.chain ?? options.network ?? 'auto';
79
+ this.network = this.chain; // backward compat
78
80
  this.preference = options.preference ?? '';
79
81
  }
80
82
 
@@ -128,7 +130,8 @@ class HealChain {
128
130
  * @param {string} [options.label='sdk upload'] - Record label
129
131
  * @param {number} [options.dataShards] - Override RS data shards
130
132
  * @param {number} [options.parityShards] - Override RS parity shards
131
- * @param {string} [options.network] - Chain name or 'auto' (default)
133
+ * @param {string} [options.chain] - Chain name or 'auto' (default)
134
+ * @param {string} [options.network] - Deprecated: use chain instead
132
135
  * @param {string} [options.preference] - 'cheapest' | 'fastest' | 'redundant' | ''
133
136
  * @param {function} [options.onPending] - Called with requestId when submitted
134
137
  * @param {function} [options.onFulfilled] - Called when oracle fulfills
@@ -148,7 +151,7 @@ class HealChain {
148
151
  const label = options.label ?? 'sdk upload';
149
152
  const dataShards = options.dataShards ?? this.dataShards;
150
153
  const parityShards = options.parityShards ?? this.parityShards;
151
- const network = options.network ?? this.network;
154
+ const network = options.chain ?? options.network ?? this.chain;
152
155
  const preference = options.preference ?? this.preference;
153
156
 
154
157
  // Submit store request
@@ -277,6 +280,34 @@ class HealChain {
277
280
  return this._fetch(`/listRecords?page=${page}&limit=${limit}`);
278
281
  }
279
282
 
283
+ // ── chainScores() ──────────────────────────────────────────────────────────
284
+
285
+ /**
286
+ * Get scored and ranked list of all available chains.
287
+ * No API key required — public endpoint.
288
+ * Useful for displaying chain selection UI or debugging auto-selection.
289
+ *
290
+ * @returns {Promise<ChainScoresResult>}
291
+ *
292
+ * @typedef {object} ChainScore
293
+ * @property {number} chainId - Chain ID
294
+ * @property {string} label - Chain name
295
+ * @property {number} score - Weighted score (higher = better)
296
+ * @property {boolean} viable - Whether chain meets minimum threshold
297
+ * @property {number} avgGasPriceGwei - Average gas price in Gwei
298
+ * @property {number} avgBlockTimeSec - Average block time in seconds
299
+ * @property {number} reliabilityScore - Reliability score 0-1
300
+ * @property {number} fulfillRate - Oracle fulfillment success rate 0-1
301
+ * @property {number} rpcResponseMs - Average RPC response time in ms
302
+ *
303
+ * @typedef {object} ChainScoresResult
304
+ * @property {string} status - 'ok'
305
+ * @property {ChainScore[]} chains - Chains sorted by score descending
306
+ */
307
+ async chainScores() {
308
+ return this._fetch('/chainScores');
309
+ }
310
+
280
311
  // ── getBillingBalance() ───────────────────────────────────────────────────
281
312
  /**
282
313
  * Get credit balances for a wallet address. No API key required.
Binary file
Binary file