@bounded-sh/core 0.0.13 → 0.0.15

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/dist/index.js CHANGED
@@ -3800,24 +3800,19 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
3800
3800
  /* ------------------------------------------------------------------ */
3801
3801
  /* ENV helpers */
3802
3802
  /* ------------------------------------------------------------------ */
3803
- // Canonical `BOUNDED_PRIVATE_KEY` (matches the CLI); legacy
3804
- // `BOUNDED_SOLANA_KEYPAIR` still honored. Only consulted when no explicit
3805
- // keypair was provided (createWalletClient passes one).
3806
- const ENV_KEYPAIRS = ["BOUNDED_PRIVATE_KEY", "BOUNDED_SOLANA_KEYPAIR"];
3803
+ // Canonical `BOUNDED_PRIVATE_KEY` (matches the CLI). Only consulted when no
3804
+ // explicit keypair was provided (createWalletClient passes one).
3805
+ const ENV_KEYPAIR = "BOUNDED_PRIVATE_KEY";
3806
+ const LEGACY_ENV_KEYPAIR = "BOUNDED_SOLANA_KEYPAIR";
3807
3807
  function loadKeypairFromEnv() {
3808
- let secret;
3809
- let found;
3810
- for (const name of ENV_KEYPAIRS) {
3811
- const v = process.env[name];
3812
- if (v) {
3813
- secret = v;
3814
- found = name;
3815
- break;
3816
- }
3808
+ if (process.env[LEGACY_ENV_KEYPAIR]) {
3809
+ throw new Error(`${LEGACY_ENV_KEYPAIR} is no longer supported. Set ${ENV_KEYPAIR} instead, ` +
3810
+ `or pass an explicit keypair via createWalletClient({ keypair }).`);
3817
3811
  }
3812
+ const secret = process.env[ENV_KEYPAIR];
3818
3813
  if (!secret) {
3819
3814
  throw new Error(`No server keypair for this top-level call. The top-level get/set/subscribe/etc. use an ` +
3820
- `AMBIENT session — set ${ENV_KEYPAIRS[0]} to a base-58 secret key (or JSON array) to provide one. ` +
3815
+ `AMBIENT session — set ${ENV_KEYPAIR} to a base-58 secret key (or JSON array) to provide one. ` +
3821
3816
  `If you already created a wallet with createWalletClient({ keypair }), call ITS methods instead ` +
3822
3817
  `(client.subscribe / client.set / client.get): that client is self-contained and deliberately does ` +
3823
3818
  `not set the ambient session, so the top-level functions can't see it.`);
@@ -3829,7 +3824,7 @@ function loadKeypairFromEnv() {
3829
3824
  return web3_js.Keypair.fromSecretKey(secretKey);
3830
3825
  }
3831
3826
  catch (err) {
3832
- throw new Error(`Unable to parse ${found}. Ensure it is valid base-58 or JSON.`);
3827
+ throw new Error(`Unable to parse ${ENV_KEYPAIR}. Ensure it is valid base-58 or JSON.`);
3833
3828
  }
3834
3829
  }
3835
3830
  /* ------------------------------------------------------------------ */
@@ -3896,7 +3891,7 @@ class ServerSessionManager {
3896
3891
  this.session = session;
3897
3892
  }
3898
3893
  /* ---------------------------------------------- *
3899
- * CLEAR (e.g. after logout or 401 retry)
3894
+ * CLEAR (e.g. after explicit logout)
3900
3895
  * ---------------------------------------------- */
3901
3896
  clearSession() {
3902
3897
  this.session = null;
@@ -3920,11 +3915,6 @@ class ServerSessionManager {
3920
3915
  /* The default singleton instance (reads keypair from env) */
3921
3916
  ServerSessionManager.instance = new ServerSessionManager();
3922
3917
 
3923
- var serverSessionManager = /*#__PURE__*/Object.freeze({
3924
- __proto__: null,
3925
- ServerSessionManager: ServerSessionManager
3926
- });
3927
-
3928
3918
  /**
3929
3919
  * Safe base64 helpers for bounded-core.
3930
3920
  *
@@ -4149,13 +4139,6 @@ async function refreshAuthSessionOnce(appId, isServer) {
4149
4139
  async function makeApiRequest(method, urlPath, data, _overrides) {
4150
4140
  var _a, _b, _c, _d, _e, _f, _g, _h;
4151
4141
  const config = await getConfig();
4152
- let hasRetriedAfterServerSessionReset = false;
4153
- const clearServerSession = async () => {
4154
- if (!config.isServer)
4155
- return;
4156
- const { ServerSessionManager } = await Promise.resolve().then(function () { return serverSessionManager; });
4157
- ServerSessionManager.instance.clearSession();
4158
- };
4159
4142
  async function executeRequest() {
4160
4143
  var _a;
4161
4144
  // When _getAuthHeaders is provided (wallet client), use it as the sole auth source.
@@ -4205,13 +4188,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
4205
4188
  }
4206
4189
  return await executeRequest();
4207
4190
  }
4208
- catch (_refreshError) {
4209
- // Server-side fallback: clear global session and retry once
4210
- if (config.isServer && !hasRetriedAfterServerSessionReset) {
4211
- hasRetriedAfterServerSessionReset = true;
4212
- await clearServerSession();
4213
- return await executeRequest();
4214
- }
4191
+ catch (_j) {
4215
4192
  throw error;
4216
4193
  }
4217
4194
  }
@@ -4771,39 +4748,8 @@ async function get(path, opts = {}) {
4771
4748
  }
4772
4749
  // Create a new request promise and store it
4773
4750
  const requestPromise = (async () => {
4774
- var _a;
4775
4751
  try {
4776
- // For realtime chains, prefer WebSocket reads (lower latency, already connected)
4777
- const config = await getConfig();
4778
4752
  const pathIsDocument = normalizedPath.split("/").length % 2 === 0;
4779
- if (((_a = config.chain) === null || _a === void 0 ? void 0 : _a.startsWith('realtime_')) && !config.isServer && !opts.prompt && !opts.shape && !opts.cursor && !opts.includeSubPaths && !opts.filter && !opts.sort) {
4780
- try {
4781
- const { wsGet, wsQuery, hasActiveConnection } = await Promise.resolve().then(function () { return subscriptionV2; });
4782
- if (hasActiveConnection()) {
4783
- if (pathIsDocument) {
4784
- const wsResult = await wsGet(normalizedPath);
4785
- const responseData = normalizeReadResult(wsResult, true);
4786
- if (!opts.bypassCache) {
4787
- getCache[cacheKey] = { data: responseData, expiresAt: now + GET_CACHE_TTL };
4788
- }
4789
- return responseData;
4790
- }
4791
- else if (!opts.limit) {
4792
- const wsResult = await wsQuery(normalizedPath, {
4793
- filter: undefined,
4794
- sort: undefined,
4795
- includeSubPaths: opts.includeSubPaths,
4796
- });
4797
- const responseData = normalizeReadResult(wsResult, false);
4798
- if (!opts.bypassCache) {
4799
- getCache[cacheKey] = { data: responseData, expiresAt: now + GET_CACHE_TTL };
4800
- }
4801
- return responseData;
4802
- }
4803
- }
4804
- }
4805
- catch ( /* fall through to HTTP */_b) { /* fall through to HTTP */ }
4806
- }
4807
4753
  // Cache miss or bypass - proceed with HTTP API request
4808
4754
  let response;
4809
4755
  // Build common query params
@@ -5056,7 +5002,7 @@ async function set(path, document, options) {
5056
5002
  return result;
5057
5003
  }
5058
5004
  async function setMany(many, options) {
5059
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
5005
+ var _a, _b, _c, _d, _e, _f, _g;
5060
5006
  // Returns the data that was set, or undefined if the document was already set.
5061
5007
  try {
5062
5008
  const config = await getConfig();
@@ -5093,40 +5039,13 @@ async function setMany(many, options) {
5093
5039
  }
5094
5040
  let setResponse;
5095
5041
  try {
5096
- // For realtime chains, prefer WebSocket if a connection is active (lower latency)
5097
- const useWs = ((_c = config.chain) === null || _c === void 0 ? void 0 : _c.startsWith('realtime_')) && !config.isServer;
5098
- if (useWs) {
5099
- try {
5100
- const { wsSet, hasActiveConnection } = await Promise.resolve().then(function () { return subscriptionV2; });
5101
- if (hasActiveConnection()) {
5102
- // Connection is active — send via WS. If this throws, the write
5103
- // may have been applied server-side (ack lost). Do NOT fall through
5104
- // to HTTP, as that would double-apply non-idempotent ops (Increment).
5105
- const wsResult = await wsSet(documents);
5106
- setResponse = { data: wsResult, status: 200 };
5107
- }
5108
- }
5109
- catch (wsError) {
5110
- // Only fall through to HTTP if the request was never sent (connection not available).
5111
- // If the request was sent and ack was lost (timeout), the server may have
5112
- // applied it — re-sending via HTTP risks double-write for non-idempotent ops.
5113
- const msg = (_d = wsError === null || wsError === void 0 ? void 0 : wsError.message) !== null && _d !== void 0 ? _d : '';
5114
- const neverSent = msg.includes('not available') || msg.includes('connection timeout');
5115
- if (!neverSent) {
5116
- throw wsError;
5117
- }
5118
- // Safe to retry via HTTP — request was never sent
5119
- }
5120
- }
5121
- if (!setResponse) {
5122
- setResponse = await makeApiRequest('PUT', `items`, { documents }, options === null || options === void 0 ? void 0 : options._overrides);
5123
- }
5042
+ setResponse = await makeApiRequest('PUT', `items`, { documents }, options === null || options === void 0 ? void 0 : options._overrides);
5124
5043
  }
5125
5044
  catch (error) {
5126
5045
  if ((error === null || error === void 0 ? void 0 : error.statusCode) === 402 && (error === null || error === void 0 ? void 0 : error.error) === 'INSUFFICIENT_BALANCE') {
5127
- const deficitLamports = Number((_e = error.deficitLamports) !== null && _e !== void 0 ? _e : 0);
5128
- const deficitSol = Number((_f = error.deficitSol) !== null && _f !== void 0 ? _f : deficitLamports / 1000000000);
5129
- throw new InsufficientBalanceError(String((_g = error.address) !== null && _g !== void 0 ? _g : ''), Number((_h = error.balanceLamports) !== null && _h !== void 0 ? _h : 0), Number((_j = error.estimatedCostLamports) !== null && _j !== void 0 ? _j : 0), deficitLamports, deficitSol);
5046
+ const deficitLamports = Number((_c = error.deficitLamports) !== null && _c !== void 0 ? _c : 0);
5047
+ const deficitSol = Number((_d = error.deficitSol) !== null && _d !== void 0 ? _d : deficitLamports / 1000000000);
5048
+ throw new InsufficientBalanceError(String((_e = error.address) !== null && _e !== void 0 ? _e : ''), Number((_f = error.balanceLamports) !== null && _f !== void 0 ? _f : 0), Number((_g = error.estimatedCostLamports) !== null && _g !== void 0 ? _g : 0), deficitLamports, deficitSol);
5130
5049
  }
5131
5050
  throw error;
5132
5051
  }
@@ -5173,7 +5092,7 @@ async function setMany(many, options) {
5173
5092
  else if (setResponse.data &&
5174
5093
  typeof setResponse.data === 'object' &&
5175
5094
  setResponse.data.success === true) {
5176
- const _k = setResponse.data, { success: _success } = _k, rest = __rest$1(_k, ["success"]);
5095
+ const _h = setResponse.data, { success: _success } = _h, rest = __rest$1(_h, ["success"]);
5177
5096
  return Object.assign(Object.assign(Object.assign({}, documents.map(d => d.document)), rest), { transactionId: null });
5178
5097
  }
5179
5098
  else {
@@ -6701,23 +6620,6 @@ async function wsGetMany(paths) {
6701
6620
  }));
6702
6621
  }
6703
6622
 
6704
- var subscriptionV2 = /*#__PURE__*/Object.freeze({
6705
- __proto__: null,
6706
- clearCacheV2: clearCacheV2,
6707
- closeAllSubscriptionsV2: closeAllSubscriptionsV2,
6708
- getCachedDataV2: getCachedDataV2,
6709
- hasActiveConnection: hasActiveConnection,
6710
- reconnectWithNewAuthV2: reconnectWithNewAuthV2,
6711
- subscribeV2: subscribeV2,
6712
- wsDelete: wsDelete,
6713
- wsGet: wsGet,
6714
- wsGetMany: wsGetMany,
6715
- wsIntent: wsIntent,
6716
- wsIntentReliable: wsIntentReliable,
6717
- wsQuery: wsQuery,
6718
- wsSet: wsSet
6719
- });
6720
-
6721
6623
  /**
6722
6624
  * WebSocket Subscription Module
6723
6625
  *