@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.mjs CHANGED
@@ -3780,24 +3780,19 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
3780
3780
  /* ------------------------------------------------------------------ */
3781
3781
  /* ENV helpers */
3782
3782
  /* ------------------------------------------------------------------ */
3783
- // Canonical `BOUNDED_PRIVATE_KEY` (matches the CLI); legacy
3784
- // `BOUNDED_SOLANA_KEYPAIR` still honored. Only consulted when no explicit
3785
- // keypair was provided (createWalletClient passes one).
3786
- const ENV_KEYPAIRS = ["BOUNDED_PRIVATE_KEY", "BOUNDED_SOLANA_KEYPAIR"];
3783
+ // Canonical `BOUNDED_PRIVATE_KEY` (matches the CLI). Only consulted when no
3784
+ // explicit keypair was provided (createWalletClient passes one).
3785
+ const ENV_KEYPAIR = "BOUNDED_PRIVATE_KEY";
3786
+ const LEGACY_ENV_KEYPAIR = "BOUNDED_SOLANA_KEYPAIR";
3787
3787
  function loadKeypairFromEnv() {
3788
- let secret;
3789
- let found;
3790
- for (const name of ENV_KEYPAIRS) {
3791
- const v = process.env[name];
3792
- if (v) {
3793
- secret = v;
3794
- found = name;
3795
- break;
3796
- }
3788
+ if (process.env[LEGACY_ENV_KEYPAIR]) {
3789
+ throw new Error(`${LEGACY_ENV_KEYPAIR} is no longer supported. Set ${ENV_KEYPAIR} instead, ` +
3790
+ `or pass an explicit keypair via createWalletClient({ keypair }).`);
3797
3791
  }
3792
+ const secret = process.env[ENV_KEYPAIR];
3798
3793
  if (!secret) {
3799
3794
  throw new Error(`No server keypair for this top-level call. The top-level get/set/subscribe/etc. use an ` +
3800
- `AMBIENT session — set ${ENV_KEYPAIRS[0]} to a base-58 secret key (or JSON array) to provide one. ` +
3795
+ `AMBIENT session — set ${ENV_KEYPAIR} to a base-58 secret key (or JSON array) to provide one. ` +
3801
3796
  `If you already created a wallet with createWalletClient({ keypair }), call ITS methods instead ` +
3802
3797
  `(client.subscribe / client.set / client.get): that client is self-contained and deliberately does ` +
3803
3798
  `not set the ambient session, so the top-level functions can't see it.`);
@@ -3809,7 +3804,7 @@ function loadKeypairFromEnv() {
3809
3804
  return Keypair.fromSecretKey(secretKey);
3810
3805
  }
3811
3806
  catch (err) {
3812
- throw new Error(`Unable to parse ${found}. Ensure it is valid base-58 or JSON.`);
3807
+ throw new Error(`Unable to parse ${ENV_KEYPAIR}. Ensure it is valid base-58 or JSON.`);
3813
3808
  }
3814
3809
  }
3815
3810
  /* ------------------------------------------------------------------ */
@@ -3876,7 +3871,7 @@ class ServerSessionManager {
3876
3871
  this.session = session;
3877
3872
  }
3878
3873
  /* ---------------------------------------------- *
3879
- * CLEAR (e.g. after logout or 401 retry)
3874
+ * CLEAR (e.g. after explicit logout)
3880
3875
  * ---------------------------------------------- */
3881
3876
  clearSession() {
3882
3877
  this.session = null;
@@ -3900,11 +3895,6 @@ class ServerSessionManager {
3900
3895
  /* The default singleton instance (reads keypair from env) */
3901
3896
  ServerSessionManager.instance = new ServerSessionManager();
3902
3897
 
3903
- var serverSessionManager = /*#__PURE__*/Object.freeze({
3904
- __proto__: null,
3905
- ServerSessionManager: ServerSessionManager
3906
- });
3907
-
3908
3898
  /**
3909
3899
  * Safe base64 helpers for bounded-core.
3910
3900
  *
@@ -4129,13 +4119,6 @@ async function refreshAuthSessionOnce(appId, isServer) {
4129
4119
  async function makeApiRequest(method, urlPath, data, _overrides) {
4130
4120
  var _a, _b, _c, _d, _e, _f, _g, _h;
4131
4121
  const config = await getConfig();
4132
- let hasRetriedAfterServerSessionReset = false;
4133
- const clearServerSession = async () => {
4134
- if (!config.isServer)
4135
- return;
4136
- const { ServerSessionManager } = await Promise.resolve().then(function () { return serverSessionManager; });
4137
- ServerSessionManager.instance.clearSession();
4138
- };
4139
4122
  async function executeRequest() {
4140
4123
  var _a;
4141
4124
  // When _getAuthHeaders is provided (wallet client), use it as the sole auth source.
@@ -4185,13 +4168,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
4185
4168
  }
4186
4169
  return await executeRequest();
4187
4170
  }
4188
- catch (_refreshError) {
4189
- // Server-side fallback: clear global session and retry once
4190
- if (config.isServer && !hasRetriedAfterServerSessionReset) {
4191
- hasRetriedAfterServerSessionReset = true;
4192
- await clearServerSession();
4193
- return await executeRequest();
4194
- }
4171
+ catch (_j) {
4195
4172
  throw error;
4196
4173
  }
4197
4174
  }
@@ -4751,39 +4728,8 @@ async function get(path, opts = {}) {
4751
4728
  }
4752
4729
  // Create a new request promise and store it
4753
4730
  const requestPromise = (async () => {
4754
- var _a;
4755
4731
  try {
4756
- // For realtime chains, prefer WebSocket reads (lower latency, already connected)
4757
- const config = await getConfig();
4758
4732
  const pathIsDocument = normalizedPath.split("/").length % 2 === 0;
4759
- 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) {
4760
- try {
4761
- const { wsGet, wsQuery, hasActiveConnection } = await Promise.resolve().then(function () { return subscriptionV2; });
4762
- if (hasActiveConnection()) {
4763
- if (pathIsDocument) {
4764
- const wsResult = await wsGet(normalizedPath);
4765
- const responseData = normalizeReadResult(wsResult, true);
4766
- if (!opts.bypassCache) {
4767
- getCache[cacheKey] = { data: responseData, expiresAt: now + GET_CACHE_TTL };
4768
- }
4769
- return responseData;
4770
- }
4771
- else if (!opts.limit) {
4772
- const wsResult = await wsQuery(normalizedPath, {
4773
- filter: undefined,
4774
- sort: undefined,
4775
- includeSubPaths: opts.includeSubPaths,
4776
- });
4777
- const responseData = normalizeReadResult(wsResult, false);
4778
- if (!opts.bypassCache) {
4779
- getCache[cacheKey] = { data: responseData, expiresAt: now + GET_CACHE_TTL };
4780
- }
4781
- return responseData;
4782
- }
4783
- }
4784
- }
4785
- catch ( /* fall through to HTTP */_b) { /* fall through to HTTP */ }
4786
- }
4787
4733
  // Cache miss or bypass - proceed with HTTP API request
4788
4734
  let response;
4789
4735
  // Build common query params
@@ -5036,7 +4982,7 @@ async function set(path, document, options) {
5036
4982
  return result;
5037
4983
  }
5038
4984
  async function setMany(many, options) {
5039
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
4985
+ var _a, _b, _c, _d, _e, _f, _g;
5040
4986
  // Returns the data that was set, or undefined if the document was already set.
5041
4987
  try {
5042
4988
  const config = await getConfig();
@@ -5073,40 +5019,13 @@ async function setMany(many, options) {
5073
5019
  }
5074
5020
  let setResponse;
5075
5021
  try {
5076
- // For realtime chains, prefer WebSocket if a connection is active (lower latency)
5077
- const useWs = ((_c = config.chain) === null || _c === void 0 ? void 0 : _c.startsWith('realtime_')) && !config.isServer;
5078
- if (useWs) {
5079
- try {
5080
- const { wsSet, hasActiveConnection } = await Promise.resolve().then(function () { return subscriptionV2; });
5081
- if (hasActiveConnection()) {
5082
- // Connection is active — send via WS. If this throws, the write
5083
- // may have been applied server-side (ack lost). Do NOT fall through
5084
- // to HTTP, as that would double-apply non-idempotent ops (Increment).
5085
- const wsResult = await wsSet(documents);
5086
- setResponse = { data: wsResult, status: 200 };
5087
- }
5088
- }
5089
- catch (wsError) {
5090
- // Only fall through to HTTP if the request was never sent (connection not available).
5091
- // If the request was sent and ack was lost (timeout), the server may have
5092
- // applied it — re-sending via HTTP risks double-write for non-idempotent ops.
5093
- const msg = (_d = wsError === null || wsError === void 0 ? void 0 : wsError.message) !== null && _d !== void 0 ? _d : '';
5094
- const neverSent = msg.includes('not available') || msg.includes('connection timeout');
5095
- if (!neverSent) {
5096
- throw wsError;
5097
- }
5098
- // Safe to retry via HTTP — request was never sent
5099
- }
5100
- }
5101
- if (!setResponse) {
5102
- setResponse = await makeApiRequest('PUT', `items`, { documents }, options === null || options === void 0 ? void 0 : options._overrides);
5103
- }
5022
+ setResponse = await makeApiRequest('PUT', `items`, { documents }, options === null || options === void 0 ? void 0 : options._overrides);
5104
5023
  }
5105
5024
  catch (error) {
5106
5025
  if ((error === null || error === void 0 ? void 0 : error.statusCode) === 402 && (error === null || error === void 0 ? void 0 : error.error) === 'INSUFFICIENT_BALANCE') {
5107
- const deficitLamports = Number((_e = error.deficitLamports) !== null && _e !== void 0 ? _e : 0);
5108
- const deficitSol = Number((_f = error.deficitSol) !== null && _f !== void 0 ? _f : deficitLamports / 1000000000);
5109
- 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);
5026
+ const deficitLamports = Number((_c = error.deficitLamports) !== null && _c !== void 0 ? _c : 0);
5027
+ const deficitSol = Number((_d = error.deficitSol) !== null && _d !== void 0 ? _d : deficitLamports / 1000000000);
5028
+ 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);
5110
5029
  }
5111
5030
  throw error;
5112
5031
  }
@@ -5153,7 +5072,7 @@ async function setMany(many, options) {
5153
5072
  else if (setResponse.data &&
5154
5073
  typeof setResponse.data === 'object' &&
5155
5074
  setResponse.data.success === true) {
5156
- const _k = setResponse.data, { success: _success } = _k, rest = __rest$1(_k, ["success"]);
5075
+ const _h = setResponse.data, { success: _success } = _h, rest = __rest$1(_h, ["success"]);
5157
5076
  return Object.assign(Object.assign(Object.assign({}, documents.map(d => d.document)), rest), { transactionId: null });
5158
5077
  }
5159
5078
  else {
@@ -6681,23 +6600,6 @@ async function wsGetMany(paths) {
6681
6600
  }));
6682
6601
  }
6683
6602
 
6684
- var subscriptionV2 = /*#__PURE__*/Object.freeze({
6685
- __proto__: null,
6686
- clearCacheV2: clearCacheV2,
6687
- closeAllSubscriptionsV2: closeAllSubscriptionsV2,
6688
- getCachedDataV2: getCachedDataV2,
6689
- hasActiveConnection: hasActiveConnection,
6690
- reconnectWithNewAuthV2: reconnectWithNewAuthV2,
6691
- subscribeV2: subscribeV2,
6692
- wsDelete: wsDelete,
6693
- wsGet: wsGet,
6694
- wsGetMany: wsGetMany,
6695
- wsIntent: wsIntent,
6696
- wsIntentReliable: wsIntentReliable,
6697
- wsQuery: wsQuery,
6698
- wsSet: wsSet
6699
- });
6700
-
6701
6603
  /**
6702
6604
  * WebSocket Subscription Module
6703
6605
  *