@bounded-sh/server 0.0.18 → 0.0.19

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
@@ -1,21 +1,57 @@
1
- import { convertRemainingAccounts, buildSetDocumentsTransaction, getConfig, init as init$1, getIdToken as getIdToken$1, live, set, setMany, setFile, get, getMany, getFiles, search, runQuery, runQueryMany, runExpression, runExpressionMany, count, aggregate, queryAggregate, subscribe, functions, ServerSessionManager, getWebhookKeysUrl } from '@bounded-sh/core';
2
- export * from '@bounded-sh/core';
3
- export { FunctionInvokeError, InsufficientBalanceError, LiveIntentError, aggregate, count, functions, get, getConfig, getFiles, getMany, invokeFunction, live, liveIntent, liveStatus, queryAggregate, runExpression, runExpressionMany, runQuery, runQueryMany, search, set, setFile, setMany, signAndSubmitTransaction, signMessage, signTransaction, subscribe } from '@bounded-sh/core';
1
+ import { init as init$1, convertRemainingAccounts, buildSetDocumentsTransaction, live as live$1, set as set$1, setMany as setMany$1, setFile as setFile$1, get as get$1, getMany as getMany$1, getFiles as getFiles$1, search as search$1, runQuery as runQuery$1, runQueryMany as runQueryMany$1, runExpression as runExpression$1, runExpressionMany as runExpressionMany$1, count as count$1, aggregate as aggregate$1, queryAggregate as queryAggregate$1, subscribe as subscribe$1, functions as functions$1, getConfig, ServerSessionManager, getWebhookKeysUrl } from '@bounded-sh/core';
2
+ export { FunctionInvokeError, InsufficientBalanceError, LiveIntentError, getConfig, getWebhookKeysUrl } from '@bounded-sh/core';
3
+ import { Connection, VersionedTransaction, ComputeBudgetProgram, SystemProgram, Keypair } from '@solana/web3.js';
4
+ import bs58 from 'bs58';
4
5
  import { Buffer as Buffer$1 } from 'buffer';
5
- import { Connection, VersionedTransaction, ComputeBudgetProgram, Keypair, SystemProgram } from '@solana/web3.js';
6
6
  import * as anchor from '@coral-xyz/anchor';
7
7
  import nacl from 'tweetnacl';
8
- import bs58 from 'bs58';
9
8
  import * as crypto from 'crypto';
10
9
 
11
- /* ------------------------------------------------------------- *
12
- * KEYPAIR ENV-VAR (only consulted when no explicit keypair is given)
13
- *
14
- * Most code should pass a keypair explicitly — `createWalletClient({ keypair })`
15
- * does. The env var is the fallback for the global `set/get` path. `BOUNDED_*`
16
- * is the canonical name (it matches the CLI's `BOUNDED_PRIVATE_KEY`).
17
- * ------------------------------------------------------------- */
18
- const ENV_VARS = ['BOUNDED_PRIVATE_KEY']; // base-58 or JSON array
10
+ async function init(newConfig) {
11
+ await init$1(Object.assign(Object.assign({}, newConfig), { authProvider: null, isServer: true, skipBackendInit: true }));
12
+ }
13
+
14
+ async function getAuthProvider() {
15
+ throw new Error('Server auth providers are not process-global. Use createWalletClient({ keypair }) and call that client\'s methods.');
16
+ }
17
+
18
+ function explicitClientOnly(name) {
19
+ throw new Error(`${name} is not available as a tarobase-server top-level auth operation. ` +
20
+ 'Use createWalletClient({ keypair }) and call the returned client method.');
21
+ }
22
+ async function get(..._args) { explicitClientOnly('get'); }
23
+ async function getMany(..._args) { explicitClientOnly('getMany'); }
24
+ async function set(..._args) { explicitClientOnly('set'); }
25
+ async function setMany(..._args) { explicitClientOnly('setMany'); }
26
+ async function setFile(..._args) { explicitClientOnly('setFile'); }
27
+ async function getFiles(..._args) { explicitClientOnly('getFiles'); }
28
+ async function search(..._args) { explicitClientOnly('search'); }
29
+ async function queryAggregate(..._args) { explicitClientOnly('queryAggregate'); }
30
+ async function runQuery(..._args) { explicitClientOnly('runQuery'); }
31
+ async function runQueryMany(..._args) { explicitClientOnly('runQueryMany'); }
32
+ async function runExpression(..._args) { explicitClientOnly('runExpression'); }
33
+ async function runExpressionMany(..._args) { explicitClientOnly('runExpressionMany'); }
34
+ async function signMessage(..._args) { explicitClientOnly('signMessage'); }
35
+ async function signTransaction(..._args) { explicitClientOnly('signTransaction'); }
36
+ async function signAndSubmitTransaction(..._args) { explicitClientOnly('signAndSubmitTransaction'); }
37
+ async function count(..._args) { explicitClientOnly('count'); }
38
+ async function aggregate(..._args) { explicitClientOnly('aggregate'); }
39
+ async function subscribe(..._args) { explicitClientOnly('subscribe'); }
40
+ async function invokeFunction(..._args) { explicitClientOnly('invokeFunction'); }
41
+ async function liveIntent(..._args) { explicitClientOnly('liveIntent'); }
42
+ async function liveStatus(..._args) { explicitClientOnly('liveStatus'); }
43
+ const functions = {
44
+ invoke: async (..._args) => explicitClientOnly('functions.invoke'),
45
+ };
46
+ const live = {
47
+ intent: async (..._args) => explicitClientOnly('live.intent'),
48
+ status: async (..._args) => explicitClientOnly('live.status'),
49
+ };
50
+
51
+ async function getIdToken() {
52
+ throw new Error('getIdToken is not available as a tarobase-server top-level auth operation. Use createWalletClient({ keypair }) and call the returned client methods.');
53
+ }
54
+
19
55
  const PRESIGNED_BLOCKHASH_ERROR = 'Server signedTransaction blockhash is stale or expired';
20
56
  const BOUNDED_PROGRAM_MAINNET = 'poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp';
21
57
  const BOUNDED_PROGRAM_DEVNET = 'taro6CvKqwrYrDc16ufYgzQ2NZcyyVKStffbtudrhRu';
@@ -35,32 +71,6 @@ const ALLOWED_BOUNDED_SET_DISCRIMINATORS = new Set([
35
71
  SET_DOCUMENTS_DISCRIMINATOR,
36
72
  SET_DOCUMENTS_V2_DISCRIMINATOR,
37
73
  ]);
38
- function loadKeypairFromEnv() {
39
- var _a;
40
- let secret;
41
- let found;
42
- for (const name of ENV_VARS) {
43
- const v = (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a[name];
44
- if (v) {
45
- secret = v;
46
- found = name;
47
- break;
48
- }
49
- }
50
- if (!secret) {
51
- throw new Error(`No server keypair: set ${ENV_VARS[0]} to a base58 secret key (or JSON array), ` +
52
- `or pass one explicitly via createWalletClient({ keypair }).`);
53
- }
54
- try {
55
- const secretKey = secret.trim().startsWith('[')
56
- ? Uint8Array.from(JSON.parse(secret))
57
- : bs58.decode(secret.trim());
58
- return Keypair.fromSecretKey(secretKey);
59
- }
60
- catch (err) {
61
- throw new Error(`Unable to parse ${found}. Ensure it is valid base58 or a JSON array.`);
62
- }
63
- }
64
74
  /* ──────────────────────────────────────────────────────────
65
75
  * Helper – fetch getPriorityFeeEstimate
66
76
  * ──────────────────────────────────────────────────────── */
@@ -289,13 +299,15 @@ function assertAllowedServerPreInstructions(preInstructions) {
289
299
  }
290
300
  }
291
301
  class SolanaKeypairProvider {
292
- constructor(rpcUrl = null, keypair) {
302
+ constructor(rpcUrl, serverKeypair) {
293
303
  this.rpcUrl = rpcUrl;
294
- this.explicitKeypair = keypair;
304
+ this.serverKeypair = serverKeypair;
295
305
  }
296
306
  get keypair() {
297
- var _a, _b;
298
- return ((_a = this.cachedKeypair) !== null && _a !== void 0 ? _a : (this.cachedKeypair = (_b = this.explicitKeypair) !== null && _b !== void 0 ? _b : loadKeypairFromEnv()));
307
+ if (!this.serverKeypair) {
308
+ throw new Error('Server keypair is required; use createWalletClient({ keypair }) or pass a Keypair to SolanaKeypairProvider.');
309
+ }
310
+ return this.serverKeypair;
299
311
  }
300
312
  /* ----------------------------------------------------------- *
301
313
  * (Auth stubs – fill in later if needed)
@@ -656,44 +668,6 @@ class OffchainAuthProvider {
656
668
  }
657
669
  }
658
670
 
659
- let currentAuthProvider = null;
660
- async function getAuthProvider() {
661
- var _a;
662
- const config = await getConfig();
663
- if (currentAuthProvider) {
664
- // If provider exists but chain is "offchain" and it's not already wrapped, rewrap it
665
- if (config.chain === "offchain" && !(currentAuthProvider instanceof OffchainAuthProvider)) {
666
- currentAuthProvider = new OffchainAuthProvider(currentAuthProvider);
667
- }
668
- return currentAuthProvider;
669
- }
670
- currentAuthProvider = await matchAuthProvider((_a = config.rpcUrl) !== null && _a !== void 0 ? _a : null);
671
- // Wrap with OffchainAuthProvider for offchain chain
672
- if (config.chain === "offchain") {
673
- currentAuthProvider = new OffchainAuthProvider(currentAuthProvider);
674
- }
675
- return currentAuthProvider;
676
- }
677
- async function matchAuthProvider(rpcUrl) {
678
- return new SolanaKeypairProvider(rpcUrl);
679
- }
680
-
681
- let authProviderInstance = null;
682
- async function init(newConfig) {
683
- // Initialize config first so getAuthProvider can access it
684
- // Server-side skips backend init since it already has all needed config
685
- await init$1(Object.assign(Object.assign({}, newConfig), { isServer: true, skipBackendInit: true }));
686
- // Get the auth provider (which will wrap it if chain is "offchain")
687
- authProviderInstance = await getAuthProvider();
688
- // Update config with the wrapped provider
689
- await init$1(Object.assign(Object.assign({}, newConfig), { authProvider: authProviderInstance, isServer: true, skipBackendInit: true }));
690
- }
691
-
692
- // Wrapper for getIdToken - passes isServer=true for server-side usage
693
- async function getIdToken() {
694
- return getIdToken$1(true);
695
- }
696
-
697
671
  var __rest = (undefined && undefined.__rest) || function (s, e) {
698
672
  var t = {};
699
673
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -750,8 +724,8 @@ class WalletClient {
750
724
  this.sessionManager = sessionManager;
751
725
  this.address = address;
752
726
  this.live = {
753
- intent: (roomPath, intent, opts = {}) => live.intent(roomPath, intent, this.mergeLiveIntentOptions(opts)),
754
- status: (roomPath, opts = {}) => live.status(roomPath, Object.assign(Object.assign({}, opts), { headers: this.sanitizeHeaders(opts.headers) })),
727
+ intent: (roomPath, intent, opts = {}) => live$1.intent(roomPath, intent, this.mergeLiveIntentOptions(opts)),
728
+ status: (roomPath, opts = {}) => live$1.status(roomPath, Object.assign(Object.assign({}, opts), { headers: this.sanitizeHeaders(opts.headers) })),
755
729
  };
756
730
  }
757
731
  /* ---- Auth override helpers ---- */
@@ -800,51 +774,50 @@ class WalletClient {
800
774
  }
801
775
  /* ---- Data operations ---- */
802
776
  async set(path, document, options) {
803
- return set(path, document, this.mergeSetOverrides(options));
777
+ return set$1(path, document, this.mergeSetOverrides(options));
804
778
  }
805
779
  async setMany(many, options) {
806
- return setMany(many, this.mergeSetOverrides(options));
780
+ return setMany$1(many, this.mergeSetOverrides(options));
807
781
  }
808
782
  async setFile(path, file, options) {
809
- return setFile(path, file, { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) });
783
+ return setFile$1(path, file, { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) });
810
784
  }
811
785
  async get(path, opts) {
812
- return get(path, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
786
+ return get$1(path, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
813
787
  }
814
788
  async getMany(paths, opts) {
815
- return getMany(paths, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides() }));
789
+ return getMany$1(paths, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides() }));
816
790
  }
817
791
  async getFiles(path, options) {
818
- return getFiles(path, { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) });
792
+ return getFiles$1(path, { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) });
819
793
  }
820
794
  async search(path, query, opts = {}) {
821
- return search(path, query, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
795
+ return search$1(path, query, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
822
796
  }
823
797
  async runQuery(absolutePath, queryName, queryArgs, opts) {
824
- return runQuery(absolutePath, queryName, queryArgs, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
798
+ return runQuery$1(absolutePath, queryName, queryArgs, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
825
799
  }
826
800
  async runQueryMany(many, opts) {
827
- return runQueryMany(many, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
801
+ return runQueryMany$1(many, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
828
802
  }
829
803
  async runExpression(expression, queryArgs, options) {
830
- return runExpression(expression, queryArgs, Object.assign(Object.assign({}, options), { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) }));
804
+ return runExpression$1(expression, queryArgs, Object.assign(Object.assign({}, options), { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) }));
831
805
  }
832
806
  async runExpressionMany(many) {
833
807
  const ovr = this.mergeReadOverrides();
834
- return runExpressionMany(many.map(m => (Object.assign(Object.assign({}, m), { _overrides: ovr }))));
808
+ return runExpressionMany$1(many.map(m => (Object.assign(Object.assign({}, m), { _overrides: ovr }))));
835
809
  }
836
810
  async count(path, opts = {}) {
837
- return count(path, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
811
+ return count$1(path, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
838
812
  }
839
813
  async aggregate(path, operation, opts = {}) {
840
- return aggregate(path, operation, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
814
+ return aggregate$1(path, operation, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
841
815
  }
842
816
  async queryAggregate(path, spec, opts = {}) {
843
- return queryAggregate(path, spec, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
817
+ return queryAggregate$1(path, spec, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
844
818
  }
845
819
  /**
846
- * Subscribe to real-time updates as THIS wallet's identity. Unlike the global
847
- * `subscribe`, this needs no `BOUNDED_PRIVATE_KEY` env var — the WS connection
820
+ * Subscribe to real-time updates as THIS wallet's identity. The WS connection
848
821
  * authenticates with the wallet's own session (so read rules see the right
849
822
  * principal), and is scoped to its own connection so it never crosses another
850
823
  * identity. Accepts a bare callback or `{ onData, onError, filter, ... }`.
@@ -853,22 +826,21 @@ class WalletClient {
853
826
  async subscribe(path, options) {
854
827
  const opts = typeof options === 'function' ? { onData: options } : Object.assign({}, options);
855
828
  const ovr = this.buildOverrides();
856
- return subscribe(path, Object.assign(Object.assign({}, opts), { _overrides: {
829
+ return subscribe$1(path, Object.assign(Object.assign({}, opts), { _overrides: {
857
830
  _getAuthHeaders: ovr._getAuthHeaders,
858
831
  _clearAuth: ovr._clearAuth,
859
832
  _walletAddress: ovr._walletAddress,
860
833
  } }));
861
834
  }
862
835
  /**
863
- * Invoke a deployed Bounded Function AS this wallet's identity. Unlike the
864
- * top-level `functions.invoke`, this needs no `BOUNDED_PRIVATE_KEY` env var —
865
- * the dispatcher sees the wallet's verified session, so the function's `auth`
866
- * rule + `ctx.user` reflect this client. Returns the function's JSON; throws
836
+ * Invoke a deployed Bounded Function AS this wallet's identity. The dispatcher
837
+ * sees the wallet's verified session, so the function's `auth` rule +
838
+ * `ctx.user` reflect this client. Returns the function's JSON; throws
867
839
  * `FunctionInvokeError` on 401/403/404/503.
868
840
  */
869
841
  async invoke(name, args = {}, opts = {}) {
870
842
  const ovr = this.buildOverrides();
871
- return functions.invoke(name, args, Object.assign(Object.assign({}, opts), { _overrides: { _getAuthHeaders: ovr._getAuthHeaders } }));
843
+ return functions$1.invoke(name, args, Object.assign(Object.assign({}, opts), { _overrides: { _getAuthHeaders: ovr._getAuthHeaders } }));
872
844
  }
873
845
  /* ---- Signing operations (use provider directly) ---- */
874
846
  async signMessage(message) {
@@ -1159,5 +1131,5 @@ async function verifyWebhook(rawBody, headers, opts = {}) {
1159
1131
  return payload;
1160
1132
  }
1161
1133
 
1162
- export { DEFAULT_WEBHOOK_KEYS_URL, InMemoryReplayStore, WalletClient, WebhookVerificationError, clearWebhookKeyCache, clearWebhookReplayCache, createWalletClient, getAuthProvider, getIdToken, init, verifyWebhook };
1134
+ export { DEFAULT_WEBHOOK_KEYS_URL, InMemoryReplayStore, WalletClient, WebhookVerificationError, aggregate, clearWebhookKeyCache, clearWebhookReplayCache, count, createWalletClient, functions, get, getAuthProvider, getFiles, getIdToken, getMany, init, invokeFunction, live, liveIntent, liveStatus, queryAggregate, runExpression, runExpressionMany, runQuery, runQueryMany, search, set, setFile, setMany, signAndSubmitTransaction, signMessage, signTransaction, subscribe, verifyWebhook };
1163
1135
  //# sourceMappingURL=index.mjs.map