@healchain/sdk 0.1.0 → 0.4.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 +1 -1
- package/src/index.js +54 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HealChain SDK v0.
|
|
2
|
+
* HealChain SDK v0.4.0
|
|
3
3
|
* REST API client for HealChain — self-healing decentralized storage.
|
|
4
4
|
*
|
|
5
5
|
* Browser (ESM) and Node.js compatible.
|
|
@@ -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] -
|
|
67
|
+
* @param {string} [options.network] - Chain name, 'auto' (default), or specific chain
|
|
68
|
+
* @param {string} [options.preference] - 'cheapest' | 'fastest' | 'redundant' | '' (auto weighted)
|
|
68
69
|
*/
|
|
69
70
|
constructor(options = {}) {
|
|
70
71
|
this.apiUrl = (options.apiUrl ?? DEFAULT_API_URL).replace(/\/$/, '');
|
|
@@ -73,7 +74,8 @@ class HealChain {
|
|
|
73
74
|
this.pollTimeout = options.pollTimeout ?? DEFAULT_POLL_TIMEOUT;
|
|
74
75
|
this.dataShards = options.dataShards ?? DEFAULT_DATA_SHARDS;
|
|
75
76
|
this.parityShards = options.parityShards ?? DEFAULT_PARITY_SHARDS;
|
|
76
|
-
this.network = options.network ?? '
|
|
77
|
+
this.network = options.network ?? 'auto';
|
|
78
|
+
this.preference = options.preference ?? '';
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
// ── Internal fetch wrapper ──────────────────────────────────────────────────
|
|
@@ -126,7 +128,8 @@ class HealChain {
|
|
|
126
128
|
* @param {string} [options.label='sdk upload'] - Record label
|
|
127
129
|
* @param {number} [options.dataShards] - Override RS data shards
|
|
128
130
|
* @param {number} [options.parityShards] - Override RS parity shards
|
|
129
|
-
* @param {string} [options.network] -
|
|
131
|
+
* @param {string} [options.network] - Chain name or 'auto' (default)
|
|
132
|
+
* @param {string} [options.preference] - 'cheapest' | 'fastest' | 'redundant' | ''
|
|
130
133
|
* @param {function} [options.onPending] - Called with requestId when submitted
|
|
131
134
|
* @param {function} [options.onFulfilled] - Called when oracle fulfills
|
|
132
135
|
*
|
|
@@ -146,11 +149,12 @@ class HealChain {
|
|
|
146
149
|
const dataShards = options.dataShards ?? this.dataShards;
|
|
147
150
|
const parityShards = options.parityShards ?? this.parityShards;
|
|
148
151
|
const network = options.network ?? this.network;
|
|
152
|
+
const preference = options.preference ?? this.preference;
|
|
149
153
|
|
|
150
154
|
// Submit store request
|
|
151
155
|
const submitted = await this._fetch('/storeOnChain', {
|
|
152
156
|
method: 'POST',
|
|
153
|
-
body: JSON.stringify({ data: hex, label, network, dataShards, parityShards }),
|
|
157
|
+
body: JSON.stringify({ data: hex, label, network, preference, dataShards, parityShards }),
|
|
154
158
|
});
|
|
155
159
|
|
|
156
160
|
// Devnet returns synchronously
|
|
@@ -272,6 +276,51 @@ class HealChain {
|
|
|
272
276
|
async list(page = 0, limit = 10) {
|
|
273
277
|
return this._fetch(`/listRecords?page=${page}&limit=${limit}`);
|
|
274
278
|
}
|
|
279
|
+
|
|
280
|
+
// ── getBillingBalance() ───────────────────────────────────────────────────
|
|
281
|
+
/**
|
|
282
|
+
* Get credit balances for a wallet address. No API key required.
|
|
283
|
+
*
|
|
284
|
+
* @param {string} walletAddress - Wallet address (0x...)
|
|
285
|
+
* @returns {Promise<object>} Production and testnet balances
|
|
286
|
+
*/
|
|
287
|
+
async getBillingBalance(walletAddress) {
|
|
288
|
+
const path = `/billing/balance?wallet=${encodeURIComponent(walletAddress)}`;
|
|
289
|
+
return this._fetch(path, { headers: { 'User-Agent': 'healchain-sdk/0.3.0' } });
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ── createCheckout() ──────────────────────────────────────────────────────
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Create a Stripe Checkout session for topping up credits.
|
|
296
|
+
* Redirects user to Stripe hosted payment page.
|
|
297
|
+
*
|
|
298
|
+
* @param {string} walletAddress - Wallet address to credit
|
|
299
|
+
* @param {number} amountCents - Amount in cents (min 500 = $5.00)
|
|
300
|
+
* @returns {Promise<object>} { checkout_url, session_id, amount_usd }
|
|
301
|
+
*/
|
|
302
|
+
async createCheckout(walletAddress, amountCents) {
|
|
303
|
+
return this._fetch('/checkout/create', {
|
|
304
|
+
method: 'POST',
|
|
305
|
+
body: JSON.stringify({ wallet_address: walletAddress, amount_cents: amountCents }),
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ── requestTestnetCredits() ───────────────────────────────────────────────
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Request free testnet credits ($1.00 per wallet per 24 hours).
|
|
313
|
+
* Wallet must be whitelisted during early access phase.
|
|
314
|
+
*
|
|
315
|
+
* @param {string} walletAddress - Wallet address to credit
|
|
316
|
+
* @returns {Promise<object>} { granted_usd, balance_usd, expires_in_days }
|
|
317
|
+
*/
|
|
318
|
+
async requestTestnetCredits(walletAddress) {
|
|
319
|
+
return this._fetch('/testnet/requestCredits', {
|
|
320
|
+
method: 'POST',
|
|
321
|
+
body: JSON.stringify({ wallet_address: walletAddress }),
|
|
322
|
+
});
|
|
323
|
+
}
|
|
275
324
|
}
|
|
276
325
|
|
|
277
326
|
// ── Exports ───────────────────────────────────────────────────────────────────
|