@pooflabs/server 0.0.2 → 0.0.3

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
@@ -88,7 +88,6 @@ class WebSessionManager {
88
88
  /* ---------- validate app-id ---------- */
89
89
  const config = await getConfig();
90
90
  if (sessionObj.appId && sessionObj.appId !== config.appId) {
91
- console.warn("Session appId mismatch. Stored session belongs to a different app. Logging out.");
92
91
  this.clearSession();
93
92
  return null;
94
93
  }
@@ -113,7 +112,6 @@ class WebSessionManager {
113
112
  }
114
113
  }
115
114
  catch (err) {
116
- console.error("Error decoding access token:", err);
117
115
  return null;
118
116
  }
119
117
  return { address: sessionObj.address, session: sessionObj };
@@ -164,7 +162,6 @@ class WebSessionManager {
164
162
  /* ---------- app-id guard ---------- */
165
163
  const config = await getConfig();
166
164
  if (sessionObj.appId && sessionObj.appId !== config.appId) {
167
- console.warn("Session appId mismatch during token refresh. Logging out.");
168
165
  this.clearSession();
169
166
  return;
170
167
  }
@@ -6257,7 +6254,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
6257
6254
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
6258
6255
  tx.recentBlockhash = blockhash;
6259
6256
  if (lutKey == null) {
6260
- const computeUnits = await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
6257
+ const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
6258
+ const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
6261
6259
  const computeBudgetIxOptimized = ComputeBudgetProgram.setComputeUnitLimit({
6262
6260
  units: computeUnits ? computeUnits * 1.2 : 1400000,
6263
6261
  }); // 20% buffer
@@ -6267,7 +6265,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
6267
6265
  const { value: table } = await connection.getAddressLookupTable(new PublicKey(lutKey));
6268
6266
  if (!table)
6269
6267
  throw new Error('LUT not found after creation/extend');
6270
- const computeUnits = await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
6268
+ const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
6269
+ const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
6271
6270
  const computeBudgetIxOptimized = ComputeBudgetProgram.setComputeUnitLimit({
6272
6271
  units: computeUnits ? computeUnits * 1.2 : 1400000,
6273
6272
  }); // 20% buffer
@@ -6404,7 +6403,7 @@ function updateIdTokenAndAccessToken(idToken, accessToken) {
6404
6403
  }
6405
6404
 
6406
6405
  async function makeApiRequest(method, urlPath, data, _overrides) {
6407
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
6406
+ var _a, _b, _c, _d, _e, _f;
6408
6407
  const config = await getConfig();
6409
6408
  async function executeRequest() {
6410
6409
  const authHeader = await createAuthHeader(config.isServer);
@@ -6454,8 +6453,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
6454
6453
  return { data: null, status: 404 };
6455
6454
  }
6456
6455
  if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) {
6457
- console.error(`Error in set call with code ${(_e = error.response) === null || _e === void 0 ? void 0 : _e.status} and message ${(_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.message}`);
6458
- throw new Error((_j = (_h = error.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.message);
6456
+ throw new Error((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.message);
6459
6457
  }
6460
6458
  throw error;
6461
6459
  }
@@ -6496,8 +6494,6 @@ function init$1(newConfig) {
6496
6494
  isInitialized = true;
6497
6495
  resolve();
6498
6496
  }).catch((error) => {
6499
- console.error('Failed to authenticate with API key or fetch config for this app:', error);
6500
- console.error('Please check your API key and try again.');
6501
6497
  reject(new Error("Failed to initialize Tarobase app."));
6502
6498
  });
6503
6499
  });
@@ -6601,16 +6597,11 @@ async function get(path, opts = {}) {
6601
6597
  // Helper to clean up expired cache entries
6602
6598
  function cleanupExpiredCache() {
6603
6599
  const now = Date.now();
6604
- let removedCount = 0;
6605
6600
  Object.keys(getCache).forEach(key => {
6606
6601
  if (getCache[key] && getCache[key].expiresAt < now) {
6607
6602
  delete getCache[key];
6608
- removedCount++;
6609
6603
  }
6610
6604
  });
6611
- if (removedCount > 0) {
6612
- console.debug(`Cleaned up ${removedCount} expired cache entries`);
6613
- }
6614
6605
  lastCacheCleanup = now;
6615
6606
  }
6616
6607
  async function runQuery(absolutePath, queryName, queryArgs) {
@@ -6744,7 +6735,6 @@ async function setMany(many, options) {
6744
6735
  }
6745
6736
  }
6746
6737
  catch (error) {
6747
- console.error("Error setting data", error);
6748
6738
  throw error;
6749
6739
  }
6750
6740
  async function handleSolanaTransaction(tx, authProvider, options) {
@@ -6861,9 +6851,7 @@ async function setFile(path, file) {
6861
6851
  });
6862
6852
  // 3) Check if the upload was successful
6863
6853
  if (!uploadResponse.ok) {
6864
- console.error(uploadResponse);
6865
- const errorText = await uploadResponse.text();
6866
- console.error('S3 Error Body:', errorText);
6854
+ await uploadResponse.text();
6867
6855
  throw new Error(`Upload failed with status: ${uploadResponse.status}`);
6868
6856
  }
6869
6857
  // Optionally return the file's public URL or some confirmation
@@ -7551,10 +7539,9 @@ async function subscribe(path, subscriptionOptions) {
7551
7539
  }
7552
7540
  });
7553
7541
  ws.addEventListener('error', (event) => {
7554
- console.error(`WebSocket error for path: ${connectionKey}`, event);
7555
7542
  notifyError(connectionKey, event);
7556
7543
  });
7557
- ws.addEventListener('close', (event) => {
7544
+ ws.addEventListener('close', () => {
7558
7545
  // Connection will be recreated on next subscription if needed
7559
7546
  });
7560
7547
  return async () => await removeSubscription(connectionKey, subscriptionOptions);
@@ -7595,8 +7582,7 @@ async function removeSubscription(connectionKey, subscription) {
7595
7582
  ws.addEventListener('close', () => {
7596
7583
  resolve();
7597
7584
  });
7598
- ws.addEventListener('error', (err) => {
7599
- console.error(`WebSocket closure error for connection: ${connectionKey}`, err);
7585
+ ws.addEventListener('error', () => {
7600
7586
  resolve(); // Resolve even on error to avoid hanging
7601
7587
  });
7602
7588
  ws.close();
@@ -10241,6 +10227,18 @@ class SolanaKeypairProvider {
10241
10227
  const sig = nacl.sign.detached(new TextEncoder().encode(message), this.keypair.secretKey);
10242
10228
  return Buffer.from(sig).toString('base64');
10243
10229
  }
10230
+ /* ----------------------------------------------------------- *
10231
+ * Sign transaction
10232
+ * ----------------------------------------------------------- */
10233
+ async signTransaction(transaction) {
10234
+ if (transaction instanceof Transaction) {
10235
+ transaction.partialSign(this.keypair);
10236
+ }
10237
+ else if (transaction instanceof VersionedTransaction) {
10238
+ transaction.sign([this.keypair]);
10239
+ }
10240
+ return transaction;
10241
+ }
10244
10242
  /* ----------------------------------------------------------- *
10245
10243
  * Transaction runner
10246
10244
  * ----------------------------------------------------------- */
@@ -10394,6 +10392,7 @@ class SolanaKeypairProvider {
10394
10392
  let currentAuthProvider = null;
10395
10393
  const SOLANA_DEVNET_RPC_URL$1 = "https://api.devnet.solana.com";
10396
10394
  const SOLANA_MAINNET_RPC_URL$1 = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
10395
+ const SURFNET_RPC_URL$1 = "https://surfpool.fly.dev";
10397
10396
  async function getAuthProvider() {
10398
10397
  var _a;
10399
10398
  if (currentAuthProvider) {
@@ -10409,7 +10408,7 @@ async function getAuthProvider() {
10409
10408
  rpcUrl = SOLANA_MAINNET_RPC_URL$1;
10410
10409
  }
10411
10410
  else {
10412
- rpcUrl = SOLANA_DEVNET_RPC_URL$1;
10411
+ rpcUrl = SURFNET_RPC_URL$1;
10413
10412
  }
10414
10413
  currentAuthProvider = await matchAuthProvider((_a = config.rpcUrl) !== null && _a !== void 0 ? _a : rpcUrl);
10415
10414
  return currentAuthProvider;
@@ -10421,6 +10420,7 @@ async function matchAuthProvider(rpcUrl) {
10421
10420
  let authProviderInstance = null;
10422
10421
  const SOLANA_DEVNET_RPC_URL = "https://api.devnet.solana.com";
10423
10422
  const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
10423
+ const SURFNET_RPC_URL = "https://surfpool.fly.dev";
10424
10424
  async function init(newConfig) {
10425
10425
  var _a;
10426
10426
  let defaultRpcUrl = '';
@@ -10431,11 +10431,17 @@ async function init(newConfig) {
10431
10431
  defaultRpcUrl = SOLANA_MAINNET_RPC_URL;
10432
10432
  }
10433
10433
  else {
10434
- defaultRpcUrl = SOLANA_DEVNET_RPC_URL;
10434
+ defaultRpcUrl = SURFNET_RPC_URL;
10435
10435
  }
10436
10436
  authProviderInstance = await matchAuthProvider((_a = newConfig.rpcUrl) !== null && _a !== void 0 ? _a : defaultRpcUrl);
10437
10437
  await init$1(Object.assign(Object.assign({}, newConfig), { authProvider: authProviderInstance, isServer: true }));
10438
10438
  }
10439
+ async function signTransaction(transaction) {
10440
+ if (!authProviderInstance) {
10441
+ throw new Error('Auth provider not initialized. Please call init() first.');
10442
+ }
10443
+ return await authProviderInstance.signTransaction(transaction);
10444
+ }
10439
10445
 
10440
- export { ServerSessionManager, WebSessionManager, buildSetDocumentsTransaction, convertRemainingAccounts, createSessionWithPrivy, createSessionWithSignature, genSolanaMessage, get, getAuthProvider, getConfig, getFiles, getIdToken, init, refreshSession, runExpression, runExpressionMany, runQuery, runQueryMany, set, setFile, setMany, signSessionCreateMessage, subscribe };
10446
+ export { ServerSessionManager, WebSessionManager, buildSetDocumentsTransaction, convertRemainingAccounts, createSessionWithPrivy, createSessionWithSignature, genSolanaMessage, get, getAuthProvider, getConfig, getFiles, getIdToken, init, refreshSession, runExpression, runExpressionMany, runQuery, runQueryMany, set, setFile, setMany, signSessionCreateMessage, signTransaction, subscribe };
10441
10447
  //# sourceMappingURL=index.mjs.map