@pooflabs/server 0.0.1 → 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/README.md +3 -3
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/providers/solana-keypair-provider.d.ts +3 -2
- package/dist/global.d.ts +3 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +65 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -254,6 +254,6 @@ This server-side SDK differs from the web SDK in several important ways:
|
|
|
254
254
|
|
|
255
255
|
This package is part of a family of modular SDKs:
|
|
256
256
|
|
|
257
|
-
- **@
|
|
258
|
-
- **@
|
|
259
|
-
- **@
|
|
257
|
+
- **@pooflabs/core**: Core functionality shared between all SDKs
|
|
258
|
+
- **@pooflabs/web**: Browser-focused SDK (identical to original js-sdk)
|
|
259
|
+
- **@pooflabs/server**: Server-side SDK for backend applications
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection, Keypair } from '@solana/web3.js';
|
|
2
|
-
import type { AuthProvider, EVMTransaction, SolTransaction, TransactionResult, User, SetOptions } from '@
|
|
1
|
+
import { Connection, Keypair, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import type { AuthProvider, EVMTransaction, SolTransaction, TransactionResult, User, SetOptions } from '@pooflabs/core';
|
|
3
3
|
export declare class SolanaKeypairProvider implements AuthProvider {
|
|
4
4
|
private readonly networkUrl;
|
|
5
5
|
private readonly connection;
|
|
@@ -9,6 +9,7 @@ export declare class SolanaKeypairProvider implements AuthProvider {
|
|
|
9
9
|
restoreSession(): Promise<User | null>;
|
|
10
10
|
logout(): Promise<void>;
|
|
11
11
|
signMessage(message: string): Promise<string>;
|
|
12
|
+
signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
12
13
|
runTransaction(_evm?: EVMTransaction, sol?: SolTransaction, opts?: SetOptions): Promise<TransactionResult>;
|
|
13
14
|
private runTransactionInner;
|
|
14
15
|
getNativeMethods(): Promise<{
|
package/dist/global.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { ClientConfig } from '@
|
|
1
|
+
import { ClientConfig } from '@pooflabs/core';
|
|
2
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
3
|
export declare function init(newConfig: Partial<ClientConfig>): Promise<void>;
|
|
4
|
+
export declare function signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { init } from "./global";
|
|
2
|
-
export { getConfig } from '@
|
|
1
|
+
export { init, signTransaction } from "./global";
|
|
2
|
+
export { getConfig } from '@pooflabs/core';
|
|
3
3
|
export { getAuthProvider } from './auth';
|
|
4
|
-
export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany } from '@
|
|
5
|
-
export { subscribe } from '@
|
|
6
|
-
export * from '@
|
|
7
|
-
export { getIdToken } from '@
|
|
4
|
+
export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany, runExpression, runExpressionMany } from '@pooflabs/core';
|
|
5
|
+
export { subscribe } from '@pooflabs/core';
|
|
6
|
+
export * from '@pooflabs/core';
|
|
7
|
+
export { getIdToken } from '@pooflabs/core';
|
package/dist/index.js
CHANGED
|
@@ -108,7 +108,6 @@ class WebSessionManager {
|
|
|
108
108
|
/* ---------- validate app-id ---------- */
|
|
109
109
|
const config = await getConfig();
|
|
110
110
|
if (sessionObj.appId && sessionObj.appId !== config.appId) {
|
|
111
|
-
console.warn("Session appId mismatch. Stored session belongs to a different app. Logging out.");
|
|
112
111
|
this.clearSession();
|
|
113
112
|
return null;
|
|
114
113
|
}
|
|
@@ -133,7 +132,6 @@ class WebSessionManager {
|
|
|
133
132
|
}
|
|
134
133
|
}
|
|
135
134
|
catch (err) {
|
|
136
|
-
console.error("Error decoding access token:", err);
|
|
137
135
|
return null;
|
|
138
136
|
}
|
|
139
137
|
return { address: sessionObj.address, session: sessionObj };
|
|
@@ -184,7 +182,6 @@ class WebSessionManager {
|
|
|
184
182
|
/* ---------- app-id guard ---------- */
|
|
185
183
|
const config = await getConfig();
|
|
186
184
|
if (sessionObj.appId && sessionObj.appId !== config.appId) {
|
|
187
|
-
console.warn("Session appId mismatch during token refresh. Logging out.");
|
|
188
185
|
this.clearSession();
|
|
189
186
|
return;
|
|
190
187
|
}
|
|
@@ -6277,7 +6274,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
|
|
|
6277
6274
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
6278
6275
|
tx.recentBlockhash = blockhash;
|
|
6279
6276
|
if (lutKey == null) {
|
|
6280
|
-
const
|
|
6277
|
+
const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
|
|
6278
|
+
const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
|
|
6281
6279
|
const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
6282
6280
|
units: computeUnits ? computeUnits * 1.2 : 1400000,
|
|
6283
6281
|
}); // 20% buffer
|
|
@@ -6287,7 +6285,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
|
|
|
6287
6285
|
const { value: table } = await connection.getAddressLookupTable(new web3_js.PublicKey(lutKey));
|
|
6288
6286
|
if (!table)
|
|
6289
6287
|
throw new Error('LUT not found after creation/extend');
|
|
6290
|
-
const
|
|
6288
|
+
const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
|
|
6289
|
+
const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
|
|
6291
6290
|
const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
6292
6291
|
units: computeUnits ? computeUnits * 1.2 : 1400000,
|
|
6293
6292
|
}); // 20% buffer
|
|
@@ -6424,7 +6423,7 @@ function updateIdTokenAndAccessToken(idToken, accessToken) {
|
|
|
6424
6423
|
}
|
|
6425
6424
|
|
|
6426
6425
|
async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
6427
|
-
var _a, _b, _c, _d, _e, _f
|
|
6426
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6428
6427
|
const config = await getConfig();
|
|
6429
6428
|
async function executeRequest() {
|
|
6430
6429
|
const authHeader = await createAuthHeader(config.isServer);
|
|
@@ -6474,8 +6473,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
6474
6473
|
return { data: null, status: 404 };
|
|
6475
6474
|
}
|
|
6476
6475
|
if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) {
|
|
6477
|
-
|
|
6478
|
-
throw new Error((_j = (_h = error.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.message);
|
|
6476
|
+
throw new Error((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.message);
|
|
6479
6477
|
}
|
|
6480
6478
|
throw error;
|
|
6481
6479
|
}
|
|
@@ -6516,8 +6514,6 @@ function init$1(newConfig) {
|
|
|
6516
6514
|
isInitialized = true;
|
|
6517
6515
|
resolve();
|
|
6518
6516
|
}).catch((error) => {
|
|
6519
|
-
console.error('Failed to authenticate with API key or fetch config for this app:', error);
|
|
6520
|
-
console.error('Please check your API key and try again.');
|
|
6521
6517
|
reject(new Error("Failed to initialize Tarobase app."));
|
|
6522
6518
|
});
|
|
6523
6519
|
});
|
|
@@ -6621,16 +6617,11 @@ async function get(path, opts = {}) {
|
|
|
6621
6617
|
// Helper to clean up expired cache entries
|
|
6622
6618
|
function cleanupExpiredCache() {
|
|
6623
6619
|
const now = Date.now();
|
|
6624
|
-
let removedCount = 0;
|
|
6625
6620
|
Object.keys(getCache).forEach(key => {
|
|
6626
6621
|
if (getCache[key] && getCache[key].expiresAt < now) {
|
|
6627
6622
|
delete getCache[key];
|
|
6628
|
-
removedCount++;
|
|
6629
6623
|
}
|
|
6630
6624
|
});
|
|
6631
|
-
if (removedCount > 0) {
|
|
6632
|
-
console.debug(`Cleaned up ${removedCount} expired cache entries`);
|
|
6633
|
-
}
|
|
6634
6625
|
lastCacheCleanup = now;
|
|
6635
6626
|
}
|
|
6636
6627
|
async function runQuery(absolutePath, queryName, queryArgs) {
|
|
@@ -6655,6 +6646,37 @@ async function runQueryMany(many) {
|
|
|
6655
6646
|
throw error;
|
|
6656
6647
|
}
|
|
6657
6648
|
}
|
|
6649
|
+
// NEW: Ad-hoc expression execution - first-class feature
|
|
6650
|
+
async function runExpression(expression, queryArgs, options) {
|
|
6651
|
+
const results = await runExpressionMany([Object.assign({ expression, queryArgs }, options)]);
|
|
6652
|
+
return results[0];
|
|
6653
|
+
}
|
|
6654
|
+
async function runExpressionMany(many) {
|
|
6655
|
+
try {
|
|
6656
|
+
let queries = [];
|
|
6657
|
+
let overrides = undefined;
|
|
6658
|
+
for (const { expression, queryArgs, returnType, _overrides } of many) {
|
|
6659
|
+
// Collect overrides from first query that has them (all queries share same request)
|
|
6660
|
+
if (_overrides && !overrides) {
|
|
6661
|
+
overrides = _overrides;
|
|
6662
|
+
}
|
|
6663
|
+
queries.push({ queryArgs, expression, returnType });
|
|
6664
|
+
}
|
|
6665
|
+
const response = await makeApiRequest('POST', 'queries', { queries }, overrides);
|
|
6666
|
+
// Map results - trace is automatically included by server for non-mainnet networks
|
|
6667
|
+
return response.data.queries.map((queryResult) => {
|
|
6668
|
+
const result = { result: queryResult.result };
|
|
6669
|
+
// Include trace if present (server includes it for non-mainnet networks)
|
|
6670
|
+
if (queryResult.trace) {
|
|
6671
|
+
result.trace = queryResult.trace;
|
|
6672
|
+
}
|
|
6673
|
+
return result;
|
|
6674
|
+
});
|
|
6675
|
+
}
|
|
6676
|
+
catch (error) {
|
|
6677
|
+
throw error;
|
|
6678
|
+
}
|
|
6679
|
+
}
|
|
6658
6680
|
async function set(path, document, options) {
|
|
6659
6681
|
const result = await setMany([{ path, document }], options);
|
|
6660
6682
|
// Clear cache entries that might be affected by this update
|
|
@@ -6733,7 +6755,6 @@ async function setMany(many, options) {
|
|
|
6733
6755
|
}
|
|
6734
6756
|
}
|
|
6735
6757
|
catch (error) {
|
|
6736
|
-
console.error("Error setting data", error);
|
|
6737
6758
|
throw error;
|
|
6738
6759
|
}
|
|
6739
6760
|
async function handleSolanaTransaction(tx, authProvider, options) {
|
|
@@ -6850,9 +6871,7 @@ async function setFile(path, file) {
|
|
|
6850
6871
|
});
|
|
6851
6872
|
// 3) Check if the upload was successful
|
|
6852
6873
|
if (!uploadResponse.ok) {
|
|
6853
|
-
|
|
6854
|
-
const errorText = await uploadResponse.text();
|
|
6855
|
-
console.error('S3 Error Body:', errorText);
|
|
6874
|
+
await uploadResponse.text();
|
|
6856
6875
|
throw new Error(`Upload failed with status: ${uploadResponse.status}`);
|
|
6857
6876
|
}
|
|
6858
6877
|
// Optionally return the file's public URL or some confirmation
|
|
@@ -7540,10 +7559,9 @@ async function subscribe(path, subscriptionOptions) {
|
|
|
7540
7559
|
}
|
|
7541
7560
|
});
|
|
7542
7561
|
ws.addEventListener('error', (event) => {
|
|
7543
|
-
console.error(`WebSocket error for path: ${connectionKey}`, event);
|
|
7544
7562
|
notifyError(connectionKey, event);
|
|
7545
7563
|
});
|
|
7546
|
-
ws.addEventListener('close', (
|
|
7564
|
+
ws.addEventListener('close', () => {
|
|
7547
7565
|
// Connection will be recreated on next subscription if needed
|
|
7548
7566
|
});
|
|
7549
7567
|
return async () => await removeSubscription(connectionKey, subscriptionOptions);
|
|
@@ -7584,8 +7602,7 @@ async function removeSubscription(connectionKey, subscription) {
|
|
|
7584
7602
|
ws.addEventListener('close', () => {
|
|
7585
7603
|
resolve();
|
|
7586
7604
|
});
|
|
7587
|
-
ws.addEventListener('error', (
|
|
7588
|
-
console.error(`WebSocket closure error for connection: ${connectionKey}`, err);
|
|
7605
|
+
ws.addEventListener('error', () => {
|
|
7589
7606
|
resolve(); // Resolve even on error to avoid hanging
|
|
7590
7607
|
});
|
|
7591
7608
|
ws.close();
|
|
@@ -10230,6 +10247,18 @@ class SolanaKeypairProvider {
|
|
|
10230
10247
|
const sig = nacl.sign.detached(new TextEncoder().encode(message), this.keypair.secretKey);
|
|
10231
10248
|
return Buffer.from(sig).toString('base64');
|
|
10232
10249
|
}
|
|
10250
|
+
/* ----------------------------------------------------------- *
|
|
10251
|
+
* Sign transaction
|
|
10252
|
+
* ----------------------------------------------------------- */
|
|
10253
|
+
async signTransaction(transaction) {
|
|
10254
|
+
if (transaction instanceof web3_js.Transaction) {
|
|
10255
|
+
transaction.partialSign(this.keypair);
|
|
10256
|
+
}
|
|
10257
|
+
else if (transaction instanceof web3_js.VersionedTransaction) {
|
|
10258
|
+
transaction.sign([this.keypair]);
|
|
10259
|
+
}
|
|
10260
|
+
return transaction;
|
|
10261
|
+
}
|
|
10233
10262
|
/* ----------------------------------------------------------- *
|
|
10234
10263
|
* Transaction runner
|
|
10235
10264
|
* ----------------------------------------------------------- */
|
|
@@ -10383,6 +10412,7 @@ class SolanaKeypairProvider {
|
|
|
10383
10412
|
let currentAuthProvider = null;
|
|
10384
10413
|
const SOLANA_DEVNET_RPC_URL$1 = "https://api.devnet.solana.com";
|
|
10385
10414
|
const SOLANA_MAINNET_RPC_URL$1 = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
10415
|
+
const SURFNET_RPC_URL$1 = "https://surfpool.fly.dev";
|
|
10386
10416
|
async function getAuthProvider() {
|
|
10387
10417
|
var _a;
|
|
10388
10418
|
if (currentAuthProvider) {
|
|
@@ -10398,7 +10428,7 @@ async function getAuthProvider() {
|
|
|
10398
10428
|
rpcUrl = SOLANA_MAINNET_RPC_URL$1;
|
|
10399
10429
|
}
|
|
10400
10430
|
else {
|
|
10401
|
-
rpcUrl =
|
|
10431
|
+
rpcUrl = SURFNET_RPC_URL$1;
|
|
10402
10432
|
}
|
|
10403
10433
|
currentAuthProvider = await matchAuthProvider((_a = config.rpcUrl) !== null && _a !== void 0 ? _a : rpcUrl);
|
|
10404
10434
|
return currentAuthProvider;
|
|
@@ -10410,6 +10440,7 @@ async function matchAuthProvider(rpcUrl) {
|
|
|
10410
10440
|
let authProviderInstance = null;
|
|
10411
10441
|
const SOLANA_DEVNET_RPC_URL = "https://api.devnet.solana.com";
|
|
10412
10442
|
const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
10443
|
+
const SURFNET_RPC_URL = "https://surfpool.fly.dev";
|
|
10413
10444
|
async function init(newConfig) {
|
|
10414
10445
|
var _a;
|
|
10415
10446
|
let defaultRpcUrl = '';
|
|
@@ -10420,11 +10451,17 @@ async function init(newConfig) {
|
|
|
10420
10451
|
defaultRpcUrl = SOLANA_MAINNET_RPC_URL;
|
|
10421
10452
|
}
|
|
10422
10453
|
else {
|
|
10423
|
-
defaultRpcUrl =
|
|
10454
|
+
defaultRpcUrl = SURFNET_RPC_URL;
|
|
10424
10455
|
}
|
|
10425
10456
|
authProviderInstance = await matchAuthProvider((_a = newConfig.rpcUrl) !== null && _a !== void 0 ? _a : defaultRpcUrl);
|
|
10426
10457
|
await init$1(Object.assign(Object.assign({}, newConfig), { authProvider: authProviderInstance, isServer: true }));
|
|
10427
10458
|
}
|
|
10459
|
+
async function signTransaction(transaction) {
|
|
10460
|
+
if (!authProviderInstance) {
|
|
10461
|
+
throw new Error('Auth provider not initialized. Please call init() first.');
|
|
10462
|
+
}
|
|
10463
|
+
return await authProviderInstance.signTransaction(transaction);
|
|
10464
|
+
}
|
|
10428
10465
|
|
|
10429
10466
|
exports.ServerSessionManager = ServerSessionManager;
|
|
10430
10467
|
exports.WebSessionManager = WebSessionManager;
|
|
@@ -10440,11 +10477,14 @@ exports.getFiles = getFiles;
|
|
|
10440
10477
|
exports.getIdToken = getIdToken;
|
|
10441
10478
|
exports.init = init;
|
|
10442
10479
|
exports.refreshSession = refreshSession;
|
|
10480
|
+
exports.runExpression = runExpression;
|
|
10481
|
+
exports.runExpressionMany = runExpressionMany;
|
|
10443
10482
|
exports.runQuery = runQuery;
|
|
10444
10483
|
exports.runQueryMany = runQueryMany;
|
|
10445
10484
|
exports.set = set;
|
|
10446
10485
|
exports.setFile = setFile;
|
|
10447
10486
|
exports.setMany = setMany;
|
|
10448
10487
|
exports.signSessionCreateMessage = signSessionCreateMessage;
|
|
10488
|
+
exports.signTransaction = signTransaction;
|
|
10449
10489
|
exports.subscribe = subscribe;
|
|
10450
10490
|
//# sourceMappingURL=index.js.map
|