@pooflabs/web 0.0.60 → 0.0.62

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.
@@ -0,0 +1,10 @@
1
+ import { Connection } from '@solana/web3.js';
2
+ /**
3
+ * Extracts a human-readable error message from Solana transaction logs.
4
+ */
5
+ export declare function extractTransactionError(err: any, logMessages?: string[] | null): string;
6
+ /**
7
+ * Polls getSignatureStatuses until the transaction is confirmed, then checks for errors.
8
+ * Throws if the transaction failed on-chain. Returns parsed transaction info on success.
9
+ */
10
+ export declare function confirmAndCheckTransaction(connection: Connection, signature: string): Promise<any>;
@@ -9622,7 +9622,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
9622
9622
  requestConfig.data = data ? JSON.stringify(data) : {};
9623
9623
  }
9624
9624
  const response = await globalAxios(requestConfig);
9625
- return { data: response.data, status: response.status };
9625
+ return { data: response.data, status: response.status, headers: response.headers };
9626
9626
  }
9627
9627
  try {
9628
9628
  return await executeRequest();
@@ -9764,6 +9764,13 @@ const pendingRequests = {};
9764
9764
  const GET_CACHE_TTL = 500; // Adjust this value as needed (in milliseconds)
9765
9765
  // Last time we cleaned up the cache
9766
9766
  let lastCacheCleanup = Date.now();
9767
+ function hashForKey$1(value) {
9768
+ let h = 5381;
9769
+ for (let i = 0; i < value.length; i++) {
9770
+ h = ((h << 5) + h + value.charCodeAt(i)) & 0x7fffffff;
9771
+ }
9772
+ return h.toString(36);
9773
+ }
9767
9774
  async function get$2(path, opts = {}) {
9768
9775
  try {
9769
9776
  let normalizedPath = path.startsWith("/") ? path.slice(1) : path;
@@ -9774,10 +9781,12 @@ async function get$2(path, opts = {}) {
9774
9781
  if (!normalizedPath || normalizedPath.length === 0) {
9775
9782
  return new Error("Invalid path provided.");
9776
9783
  }
9777
- // Create cache key combining path, prompt, includeSubPaths, and shape
9784
+ // Create cache key combining path, prompt, includeSubPaths, shape, limit, and cursor
9778
9785
  const shapeKey = opts.shape ? JSON.stringify(opts.shape) : '';
9779
9786
  const includeSubPathsKey = opts.includeSubPaths ? ':subpaths' : '';
9780
- const cacheKey = `${normalizedPath}:${opts.prompt || ''}${includeSubPathsKey}:${shapeKey}`;
9787
+ const limitKey = opts.limit !== undefined ? `:l${opts.limit}` : '';
9788
+ const cursorKey = opts.cursor ? `:c${hashForKey$1(opts.cursor)}` : '';
9789
+ const cacheKey = `${normalizedPath}:${opts.prompt || ''}${includeSubPathsKey}:${shapeKey}${limitKey}${cursorKey}`;
9781
9790
  const now = Date.now();
9782
9791
  // Check for valid cache entry if not bypassing cache
9783
9792
  if (!opts.bypassCache && getCache[cacheKey] && now < getCache[cacheKey].expiresAt) {
@@ -9801,6 +9810,8 @@ async function get$2(path, opts = {}) {
9801
9810
  // Build common query params
9802
9811
  const includeSubPathsParam = opts.includeSubPaths ? '&includeSubPaths=true' : '';
9803
9812
  const shapeParam = opts.shape ? `&shape=${encodeURIComponent(JSON.stringify(opts.shape))}` : '';
9813
+ const limitParam = opts.limit !== undefined ? `&limit=${opts.limit}` : '';
9814
+ const cursorParam = opts.cursor ? `&cursor=${encodeURIComponent(opts.cursor)}` : '';
9804
9815
  if (pathIsDocument) {
9805
9816
  const itemId = encodeURIComponent(normalizedPath);
9806
9817
  // For documents, query params go after the path
@@ -9811,13 +9822,14 @@ async function get$2(path, opts = {}) {
9811
9822
  else {
9812
9823
  const path = encodeURIComponent(normalizedPath);
9813
9824
  const promptQueryParam = (opts === null || opts === void 0 ? void 0 : opts.prompt) ? `&prompt=${btoa(opts.prompt)}` : "";
9814
- const apiPath = `items?path=${path}${promptQueryParam}${includeSubPathsParam}${shapeParam}`;
9825
+ const apiPath = `items?path=${path}${promptQueryParam}${includeSubPathsParam}${shapeParam}${limitParam}${cursorParam}`;
9815
9826
  response = await makeApiRequest('GET', apiPath, null, opts._overrides);
9816
9827
  }
9828
+ const responseData = response.data;
9817
9829
  // Cache the response (unless bypassing cache)
9818
9830
  if (!opts.bypassCache) {
9819
9831
  getCache[cacheKey] = {
9820
- data: response.data,
9832
+ data: responseData,
9821
9833
  expiresAt: now + GET_CACHE_TTL
9822
9834
  };
9823
9835
  // Periodically clean up expired cache entries (every 5 seconds)
@@ -9827,7 +9839,7 @@ async function get$2(path, opts = {}) {
9827
9839
  }
9828
9840
  }
9829
9841
  // Return the data from the response
9830
- return response.data;
9842
+ return responseData;
9831
9843
  }
9832
9844
  finally {
9833
9845
  // Remove this request from pendingRequests regardless of success/failure
@@ -10124,21 +10136,21 @@ function clearCacheByPrefix(prefix) {
10124
10136
  }
10125
10137
  });
10126
10138
  }
10127
- async function getFiles(path) {
10139
+ async function getFiles(path, options) {
10128
10140
  try {
10129
10141
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
10130
10142
  if (!normalizedPath || normalizedPath.length === 0) {
10131
10143
  return new Error("Invalid path provided.");
10132
10144
  }
10133
10145
  const apiPath = `storage?path=${normalizedPath}`;
10134
- const response = await makeApiRequest('GET', apiPath, null, undefined);
10146
+ const response = await makeApiRequest('GET', apiPath, null, options === null || options === void 0 ? void 0 : options._overrides);
10135
10147
  return response.data;
10136
10148
  }
10137
10149
  catch (error) {
10138
10150
  throw error;
10139
10151
  }
10140
10152
  }
10141
- async function setFile(path, file) {
10153
+ async function setFile(path, file, options) {
10142
10154
  var _a;
10143
10155
  // 1) Get the presigned URL from your backend
10144
10156
  const requestBody = {
@@ -10149,7 +10161,7 @@ async function setFile(path, file) {
10149
10161
  if (file) {
10150
10162
  requestBody.contentLength = file.size;
10151
10163
  }
10152
- const response = await makeApiRequest('POST', 'storage/url', requestBody, undefined);
10164
+ const response = await makeApiRequest('POST', 'storage/url', requestBody, options === null || options === void 0 ? void 0 : options._overrides);
10153
10165
  if (file == null) {
10154
10166
  return true;
10155
10167
  }
@@ -10245,10 +10257,19 @@ let lastBrowserTriggeredReconnectAt = 0;
10245
10257
  function generateSubscriptionId() {
10246
10258
  return `sub_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
10247
10259
  }
10248
- function getCacheKey(path, prompt, shape) {
10260
+ function hashForKey(value) {
10261
+ let h = 5381;
10262
+ for (let i = 0; i < value.length; i++) {
10263
+ h = ((h << 5) + h + value.charCodeAt(i)) & 0x7fffffff;
10264
+ }
10265
+ return h.toString(36);
10266
+ }
10267
+ function getCacheKey(path, prompt, shape, limit, cursor) {
10249
10268
  const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
10250
10269
  const shapeKey = shape && Object.keys(shape).length > 0 ? JSON.stringify(shape) : '';
10251
- return `${normalizedPath}:${prompt || 'default'}:${shapeKey}`;
10270
+ const limitKey = limit !== undefined ? `:l${limit}` : '';
10271
+ const cursorKey = cursor ? `:c${hashForKey(cursor)}` : '';
10272
+ return `${normalizedPath}:${prompt || 'default'}:${shapeKey}${limitKey}${cursorKey}`;
10252
10273
  }
10253
10274
  function isTokenExpired(token) {
10254
10275
  try {
@@ -10389,8 +10410,12 @@ async function getOrCreateConnection(appId, isServer) {
10389
10410
  const wsUrl = new URL(config.wsApiUrl);
10390
10411
  // Always use v2 path
10391
10412
  wsUrl.pathname = WS_V2_PATH;
10392
- // Set appId
10393
- if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
10413
+ // Set appId — prefer the explicit appId passed to getOrCreateConnection,
10414
+ // fall back to window global for legacy callers, then config default
10415
+ if (appId && appId !== config.appId) {
10416
+ wsUrl.searchParams.append('appId', appId);
10417
+ }
10418
+ else if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
10394
10419
  wsUrl.searchParams.append('appId', window.CUSTOM_TAROBASE_APP_ID_HEADER);
10395
10420
  }
10396
10421
  else {
@@ -10463,7 +10488,7 @@ function handleServerMessage(connection, message) {
10463
10488
  // If we already received data for this subscription, treat subscribed
10464
10489
  // as an ack only and avoid regressing to an older snapshot.
10465
10490
  if (subscription.lastData === undefined) {
10466
- const cacheKey = getCacheKey(subscription.path, subscription.prompt, subscription.shape);
10491
+ const cacheKey = getCacheKey(subscription.path, subscription.prompt, subscription.shape, subscription.limit, subscription.cursor);
10467
10492
  responseCache.set(cacheKey, { data: message.data, timestamp: Date.now() });
10468
10493
  subscription.lastData = message.data;
10469
10494
  notifyCallbacks(subscription, message.data);
@@ -10490,7 +10515,7 @@ function handleServerMessage(connection, message) {
10490
10515
  const subscription = connection.subscriptions.get(message.subscriptionId);
10491
10516
  if (subscription) {
10492
10517
  // Update cache
10493
- const cacheKey = getCacheKey(subscription.path, subscription.prompt, subscription.shape);
10518
+ const cacheKey = getCacheKey(subscription.path, subscription.prompt, subscription.shape, subscription.limit, subscription.cursor);
10494
10519
  responseCache.set(cacheKey, { data: message.data, timestamp: Date.now() });
10495
10520
  // Store last data
10496
10521
  subscription.lastData = message.data;
@@ -10547,6 +10572,8 @@ function sendSubscribe(connection, subscription) {
10547
10572
  shape: subscription.shape && Object.keys(subscription.shape).length > 0
10548
10573
  ? subscription.shape
10549
10574
  : undefined,
10575
+ limit: subscription.limit,
10576
+ cursor: subscription.cursor,
10550
10577
  };
10551
10578
  try {
10552
10579
  connection.ws.send(JSON.stringify(message));
@@ -10578,7 +10605,7 @@ function sendUnsubscribe(connection, subscriptionId) {
10578
10605
  async function subscribeV2(path, subscriptionOptions) {
10579
10606
  const config = await getConfig();
10580
10607
  const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
10581
- const cacheKey = getCacheKey(normalizedPath, subscriptionOptions.prompt, subscriptionOptions.shape);
10608
+ const cacheKey = getCacheKey(normalizedPath, subscriptionOptions.prompt, subscriptionOptions.shape, subscriptionOptions.limit, subscriptionOptions.cursor);
10582
10609
  // Deliver cached data immediately if available
10583
10610
  const cachedEntry = responseCache.get(cacheKey);
10584
10611
  if (cachedEntry && Date.now() - cachedEntry.timestamp < CACHE_TTL && subscriptionOptions.onData) {
@@ -10587,14 +10614,16 @@ async function subscribeV2(path, subscriptionOptions) {
10587
10614
  (_a = subscriptionOptions.onData) === null || _a === void 0 ? void 0 : _a.call(subscriptionOptions, cachedEntry.data);
10588
10615
  }, 0);
10589
10616
  }
10617
+ // Use explicit appId override if provided, otherwise fall back to config
10618
+ const effectiveAppId = subscriptionOptions.appId || config.appId;
10590
10619
  // Get or create connection for this appId
10591
- const connection = await getOrCreateConnection(config.appId, config.isServer);
10592
- // Check if we already have a subscription for this path+prompt+shape
10620
+ const connection = await getOrCreateConnection(effectiveAppId, config.isServer);
10621
+ // Check if we already have a subscription for this path+prompt+shape+limit+cursor
10593
10622
  const shapeKey = subscriptionOptions.shape ? JSON.stringify(subscriptionOptions.shape) : '';
10594
10623
  let existingSubscription;
10595
10624
  for (const sub of connection.subscriptions.values()) {
10596
10625
  const subShapeKey = sub.shape ? JSON.stringify(sub.shape) : '';
10597
- if (sub.path === normalizedPath && sub.prompt === subscriptionOptions.prompt && subShapeKey === shapeKey) {
10626
+ if (sub.path === normalizedPath && sub.prompt === subscriptionOptions.prompt && subShapeKey === shapeKey && sub.limit === subscriptionOptions.limit && sub.cursor === subscriptionOptions.cursor) {
10598
10627
  existingSubscription = sub;
10599
10628
  break;
10600
10629
  }
@@ -10620,6 +10649,8 @@ async function subscribeV2(path, subscriptionOptions) {
10620
10649
  path: normalizedPath,
10621
10650
  prompt: subscriptionOptions.prompt,
10622
10651
  shape: subscriptionOptions.shape,
10652
+ limit: subscriptionOptions.limit,
10653
+ cursor: subscriptionOptions.cursor,
10623
10654
  includeSubPaths: false,
10624
10655
  callbacks: [subscriptionOptions],
10625
10656
  lastData: undefined,
@@ -13225,6 +13256,54 @@ function requireBuffer () {
13225
13256
 
13226
13257
  var bufferExports = requireBuffer();
13227
13258
 
13259
+ /**
13260
+ * Extracts a human-readable error message from Solana transaction logs.
13261
+ */
13262
+ function extractTransactionError(err, logMessages) {
13263
+ if (logMessages) {
13264
+ return JSON.stringify(logMessages);
13265
+ }
13266
+ if (err) {
13267
+ try {
13268
+ return JSON.stringify(err);
13269
+ }
13270
+ catch (_a) {
13271
+ return String(err);
13272
+ }
13273
+ }
13274
+ return 'Unknown transaction error';
13275
+ }
13276
+ /**
13277
+ * Polls getSignatureStatuses until the transaction is confirmed, then checks for errors.
13278
+ * Throws if the transaction failed on-chain. Returns parsed transaction info on success.
13279
+ */
13280
+ async function confirmAndCheckTransaction(connection, signature) {
13281
+ var _a;
13282
+ const maxAttempts = 15;
13283
+ for (let i = 0; i < maxAttempts; i++) {
13284
+ const { value } = await connection.getSignatureStatuses([signature]);
13285
+ const status = value[0];
13286
+ if (status) {
13287
+ if (status.err) {
13288
+ const txInfo = await connection.getParsedTransaction(signature, {
13289
+ maxSupportedTransactionVersion: 0,
13290
+ commitment: 'confirmed'
13291
+ });
13292
+ const errorMessage = extractTransactionError(status.err, (_a = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _a === void 0 ? void 0 : _a.logMessages);
13293
+ throw new Error(`Transaction failed: ${errorMessage}`);
13294
+ }
13295
+ if (status.confirmationStatus === 'confirmed' || status.confirmationStatus === 'finalized') {
13296
+ return await connection.getParsedTransaction(signature, {
13297
+ maxSupportedTransactionVersion: 0,
13298
+ commitment: 'confirmed'
13299
+ });
13300
+ }
13301
+ }
13302
+ await new Promise(resolve => setTimeout(resolve, 1000));
13303
+ }
13304
+ throw new Error('Transaction confirmation timeout');
13305
+ }
13306
+
13228
13307
  const VALID_PROVIDERS = ['injected', 'google', 'apple', 'deeplink', 'phantom'];
13229
13308
  // Dynamically import React and Phantom SDK - only when needed
13230
13309
  let React$1;
@@ -13246,7 +13325,7 @@ async function loadDependencies() {
13246
13325
  const [reactModule, reactDomModule, phantomModule] = await Promise.all([
13247
13326
  import('react'),
13248
13327
  import('react-dom/client'),
13249
- import('./index-BU0jcnYK.esm.js')
13328
+ import('./index-B4o54izZ.esm.js')
13250
13329
  ]);
13251
13330
  // Extract default export from ESM module namespace
13252
13331
  // Dynamic import() returns { default: Module, ...exports }, not the module directly
@@ -14081,10 +14160,7 @@ class PhantomWalletProvider {
14081
14160
  };
14082
14161
  }
14083
14162
  const signature = await this.signAndSendViaPhantom(tx);
14084
- const txInfo = await connection.getParsedTransaction(signature, {
14085
- maxSupportedTransactionVersion: 0,
14086
- commitment: 'confirmed'
14087
- });
14163
+ const txInfo = await confirmAndCheckTransaction(connection, signature);
14088
14164
  return {
14089
14165
  transactionSignature: signature,
14090
14166
  blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
@@ -14270,7 +14346,9 @@ class PhantomWalletProvider {
14270
14346
  const { signature } = await this.submitSignedTransactionWithBlockhash(signedTx, connection, blockhash, lastValidBlockHeight);
14271
14347
  return signature;
14272
14348
  }
14273
- return await this.signAndSendViaPhantom(transaction);
14349
+ const signature = await this.signAndSendViaPhantom(transaction);
14350
+ await confirmAndCheckTransaction(connection, signature);
14351
+ return signature;
14274
14352
  }
14275
14353
  catch (error) {
14276
14354
  // Check if this is a connection error - if so, log out
@@ -33229,7 +33307,7 @@ class PrivyWalletProvider {
33229
33307
  await this.privyMethods.logout();
33230
33308
  }
33231
33309
  async runTransaction(_evmTransactionData, solTransactionData, options) {
33232
- var _a;
33310
+ var _a, _b;
33233
33311
  await this.ensureReady({ waitForWallets: true });
33234
33312
  let session = await WebSessionManager.getSession();
33235
33313
  let sessionAddress = session === null || session === void 0 ? void 0 : session.address;
@@ -33311,12 +33389,12 @@ class PrivyWalletProvider {
33311
33389
  };
33312
33390
  }
33313
33391
  // Sign and submit using shared helper
33314
- const txSignature = await this.signAndSubmitInternal(tx, privyWallet, rpcUrl);
33392
+ const { signature, txInfo } = await this.signAndSubmitInternal(tx, privyWallet, rpcUrl, connection);
33315
33393
  return {
33316
- transactionSignature: txSignature,
33317
- blockNumber: 0,
33318
- gasUsed: "0",
33319
- data: ""
33394
+ transactionSignature: signature,
33395
+ blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
33396
+ gasUsed: ((_b = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _b === void 0 ? void 0 : _b.fee.toString()) || '0',
33397
+ data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
33320
33398
  };
33321
33399
  }
33322
33400
  catch (err) {
@@ -33462,7 +33540,8 @@ class PrivyWalletProvider {
33462
33540
  // and cannot be modified after creation
33463
33541
  }
33464
33542
  // Use shared sign and submit logic
33465
- return this.signAndSubmitInternal(transaction, privyWallet, rpcUrl);
33543
+ const { signature } = await this.signAndSubmitInternal(transaction, privyWallet, rpcUrl, connection);
33544
+ return signature;
33466
33545
  }
33467
33546
  // ============ Private Helpers ============
33468
33547
  getRpcUrl(network) {
@@ -33546,15 +33625,14 @@ class PrivyWalletProvider {
33546
33625
  * For Surfnet: sign with signTransactionRaw, then sendRawTransaction
33547
33626
  * For non-Surfnet: use Privy's signAndSendTransaction (combined operation)
33548
33627
  */
33549
- async signAndSubmitInternal(transaction, privyWallet, rpcUrl) {
33628
+ async signAndSubmitInternal(transaction, privyWallet, rpcUrl, connection) {
33550
33629
  var _a;
33551
33630
  const isSurfnet = rpcUrl === SURFNET_RPC_URL$1;
33631
+ let signature;
33552
33632
  if (isSurfnet) {
33553
33633
  // For Surfnet: sign with signTransactionRaw, then sendRawTransaction
33554
33634
  const signedTx = await this.signTransactionRaw(transaction, privyWallet);
33555
- const connection = new Connection(rpcUrl, 'confirmed');
33556
- const signature = await connection.sendRawTransaction(signedTx);
33557
- return signature;
33635
+ signature = await connection.sendRawTransaction(signedTx);
33558
33636
  }
33559
33637
  else {
33560
33638
  // For non-Surfnet: use Privy's combined signAndSendTransaction
@@ -33574,13 +33652,16 @@ class PrivyWalletProvider {
33574
33652
  chain: this.chainId
33575
33653
  }));
33576
33654
  // Handle case where signature might be bytes instead of string
33577
- let signature = result.signature;
33578
- if (signature instanceof Uint8Array || Array.isArray(signature)) {
33579
- // Convert bytes to base58
33580
- signature = bs58.encode(signature instanceof Uint8Array ? signature : new Uint8Array(signature));
33655
+ const rawSig = result.signature;
33656
+ if (rawSig instanceof Uint8Array || Array.isArray(rawSig)) {
33657
+ signature = bs58.encode(rawSig instanceof Uint8Array ? rawSig : new Uint8Array(rawSig));
33658
+ }
33659
+ else {
33660
+ signature = rawSig;
33581
33661
  }
33582
- return signature;
33583
33662
  }
33663
+ const txInfo = await confirmAndCheckTransaction(connection, signature);
33664
+ return { signature, txInfo };
33584
33665
  }
33585
33666
  async signMessage(message) {
33586
33667
  var _a, _b;
@@ -34841,4 +34922,4 @@ async function getIdToken() {
34841
34922
  }
34842
34923
 
34843
34924
  export { PrivyWalletProvider as A, buildSetDocumentsTransaction as B, clearCache as C, DEFAULT_TEST_ADDRESS as D, EventEmitter3 as E, closeAllSubscriptions as F, convertRemainingAccounts as G, createSessionWithPrivy as H, createSessionWithSignature as I, genAuthNonce as J, genSolanaMessage as K, getCachedData as L, MockAuthProvider as M, reconnectWithNewAuth as N, OffchainAuthProvider as O, PhantomWalletProvider as P, refreshSession as Q, signSessionCreateMessage as R, ServerSessionManager as S, WebSessionManager as W, bs58 as a, bufferExports as b, onAuthLoadingChanged as c, getAuthLoading as d, logout as e, getConfig as f, getCurrentUser as g, getAuthProvider as h, init as i, get$2 as j, setMany as k, login as l, setFile as m, getFiles as n, onAuthStateChanged as o, runQueryMany as p, runExpression as q, runQuery as r, set$1 as s, runExpressionMany as t, signMessage as u, signTransaction as v, signAndSubmitTransaction as w, subscribe as x, useAuth as y, getIdToken as z };
34844
- //# sourceMappingURL=index-Bt89WhpV.esm.js.map
34925
+ //# sourceMappingURL=index-7_nqSSXr.esm.js.map