@bounded-sh/client 0.0.48 → 0.0.50

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.
Files changed (67) hide show
  1. package/README.md +21 -0
  2. package/dist/auth/providers/guest-auth-provider.d.ts +7 -0
  3. package/dist/auth/providers/guest-keystore.d.ts +2 -0
  4. package/dist/builds/apps.d.ts +32 -0
  5. package/dist/builds/client.d.ts +74 -0
  6. package/dist/builds/index.d.ts +20 -0
  7. package/dist/builds/types.d.ts +121 -0
  8. package/dist/builds/watch.d.ts +20 -0
  9. package/dist/{email-auth-provider-GRj8IOg2.mjs → email-auth-provider-B7czfBEU.mjs} +2 -2
  10. package/dist/{email-auth-provider-GRj8IOg2.mjs.map → email-auth-provider-B7czfBEU.mjs.map} +1 -1
  11. package/dist/{email-auth-provider-CmunfauO.js → email-auth-provider-CmYs6Dcm.js} +2 -2
  12. package/dist/{email-auth-provider-CmunfauO.js.map → email-auth-provider-CmYs6Dcm.js.map} +1 -1
  13. package/dist/{email-auth-provider-CTyjwhLb.mjs → email-auth-provider-DIZAETBC.mjs} +2 -2
  14. package/dist/{email-auth-provider-CTyjwhLb.mjs.map → email-auth-provider-DIZAETBC.mjs.map} +1 -1
  15. package/dist/{email-auth-provider-DyxZTpx6.js → email-auth-provider-Dj66AuH0.js} +2 -2
  16. package/dist/{email-auth-provider-DyxZTpx6.js.map → email-auth-provider-Dj66AuH0.js.map} +1 -1
  17. package/dist/global.d.ts +3 -1
  18. package/dist/{guest-auth-provider-D54uHbov.js → guest-auth-provider-B5sgg-q5.js} +98 -14
  19. package/dist/guest-auth-provider-B5sgg-q5.js.map +1 -0
  20. package/dist/{guest-auth-provider-Dk_km5tF.mjs → guest-auth-provider-BR0_YL8z.mjs} +98 -14
  21. package/dist/guest-auth-provider-BR0_YL8z.mjs.map +1 -0
  22. package/dist/{guest-auth-provider-C4BuTNIa.mjs → guest-auth-provider-CCpNvX3j.mjs} +98 -14
  23. package/dist/guest-auth-provider-CCpNvX3j.mjs.map +1 -0
  24. package/dist/{guest-auth-provider-B68XT2lU.js → guest-auth-provider-CxsLCznO.js} +98 -14
  25. package/dist/guest-auth-provider-CxsLCznO.js.map +1 -0
  26. package/dist/hooks/useBuildRun.d.ts +13 -0
  27. package/dist/{index.native-CytJPNQV.mjs → index-BYy1tSkr.mjs} +850 -26
  28. package/dist/index-BYy1tSkr.mjs.map +1 -0
  29. package/dist/{index.native-BZCc0gO-.js → index-m42Be5Oj.js} +861 -24
  30. package/dist/index-m42Be5Oj.js.map +1 -0
  31. package/dist/index.d.ts +5 -0
  32. package/dist/index.js +10 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/index.mjs +1 -1
  35. package/dist/{index-C0pR5b7j.mjs → index.native-B-ldAbu2.mjs} +668 -146
  36. package/dist/index.native-B-ldAbu2.mjs.map +1 -0
  37. package/dist/{index-JBeYYsGm.js → index.native-BfoLJCZg.js} +675 -148
  38. package/dist/index.native-BfoLJCZg.js.map +1 -0
  39. package/dist/index.native.d.ts +5 -0
  40. package/dist/index.native.js +10 -1
  41. package/dist/index.native.js.map +1 -1
  42. package/dist/index.native.mjs +1 -1
  43. package/dist/{injected-evm-wallet-provider-_eeYB1ww.js → injected-evm-wallet-provider-BLQzWiBP.js} +2 -2
  44. package/dist/{injected-evm-wallet-provider-_eeYB1ww.js.map → injected-evm-wallet-provider-BLQzWiBP.js.map} +1 -1
  45. package/dist/{injected-evm-wallet-provider-T-EF9C3W.js → injected-evm-wallet-provider-BXj1YFaZ.js} +2 -2
  46. package/dist/{injected-evm-wallet-provider-T-EF9C3W.js.map → injected-evm-wallet-provider-BXj1YFaZ.js.map} +1 -1
  47. package/dist/{injected-evm-wallet-provider-CxAiNN7R.mjs → injected-evm-wallet-provider-sBCSkksr.mjs} +2 -2
  48. package/dist/{injected-evm-wallet-provider-CxAiNN7R.mjs.map → injected-evm-wallet-provider-sBCSkksr.mjs.map} +1 -1
  49. package/dist/{injected-evm-wallet-provider-BOMLGGHM.mjs → injected-evm-wallet-provider-ubsHX217.mjs} +2 -2
  50. package/dist/{injected-evm-wallet-provider-BOMLGGHM.mjs.map → injected-evm-wallet-provider-ubsHX217.mjs.map} +1 -1
  51. package/dist/{injected-wallet-provider-B1uq3r4r.mjs → injected-wallet-provider-BfzoheDy.mjs} +2 -2
  52. package/dist/{injected-wallet-provider-B1uq3r4r.mjs.map → injected-wallet-provider-BfzoheDy.mjs.map} +1 -1
  53. package/dist/{injected-wallet-provider-B2T7JEvn.js → injected-wallet-provider-Cml9TkyV.js} +2 -2
  54. package/dist/{injected-wallet-provider-B2T7JEvn.js.map → injected-wallet-provider-Cml9TkyV.js.map} +1 -1
  55. package/dist/{injected-wallet-provider-DCwygA3j.mjs → injected-wallet-provider-DG87X6AQ.mjs} +2 -2
  56. package/dist/{injected-wallet-provider-DCwygA3j.mjs.map → injected-wallet-provider-DG87X6AQ.mjs.map} +1 -1
  57. package/dist/{injected-wallet-provider-BBZym7YQ.js → injected-wallet-provider-PYcvLO2Z.js} +2 -2
  58. package/dist/{injected-wallet-provider-BBZym7YQ.js.map → injected-wallet-provider-PYcvLO2Z.js.map} +1 -1
  59. package/package.json +2 -2
  60. package/dist/guest-auth-provider-B68XT2lU.js.map +0 -1
  61. package/dist/guest-auth-provider-C4BuTNIa.mjs.map +0 -1
  62. package/dist/guest-auth-provider-D54uHbov.js.map +0 -1
  63. package/dist/guest-auth-provider-Dk_km5tF.mjs.map +0 -1
  64. package/dist/index-C0pR5b7j.mjs.map +0 -1
  65. package/dist/index-JBeYYsGm.js.map +0 -1
  66. package/dist/index.native-BZCc0gO-.js.map +0 -1
  67. package/dist/index.native-CytJPNQV.mjs.map +0 -1
@@ -4247,6 +4247,41 @@ function setStoredAuthMethod(method) {
4247
4247
  // storage might not be available
4248
4248
  }
4249
4249
  }
4250
+ function getStoredIdToken() {
4251
+ try {
4252
+ return core.getActiveSessionManager().getIdToken();
4253
+ }
4254
+ catch (_a) {
4255
+ return null;
4256
+ }
4257
+ }
4258
+ function idTokenIsGuest(idToken, expectedAddress) {
4259
+ var _a;
4260
+ try {
4261
+ if (!idToken)
4262
+ return false;
4263
+ let b64 = (_a = idToken.split('.')[1]) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '+').replace(/_/g, '/');
4264
+ if (!b64)
4265
+ return false;
4266
+ const pad = b64.length % 4;
4267
+ if (pad === 2)
4268
+ b64 += '==';
4269
+ else if (pad === 3)
4270
+ b64 += '=';
4271
+ const claims = JSON.parse(getPlatform().atob(b64));
4272
+ if ((claims === null || claims === void 0 ? void 0 : claims.is_anonymous) !== true)
4273
+ return false;
4274
+ if (expectedAddress && (claims === null || claims === void 0 ? void 0 : claims['custom:walletAddress']) !== expectedAddress)
4275
+ return false;
4276
+ return true;
4277
+ }
4278
+ catch (_b) {
4279
+ return false;
4280
+ }
4281
+ }
4282
+ function storedSessionIsGuest() {
4283
+ return idTokenIsGuest(getStoredIdToken());
4284
+ }
4250
4285
  /**
4251
4286
  * Pick the provider used for an ordinary `init({ appId })` restore.
4252
4287
  *
@@ -4257,7 +4292,16 @@ function setStoredAuthMethod(method) {
4257
4292
  function authMethodForInit(config) {
4258
4293
  if (config.authMethod != null)
4259
4294
  return config.authMethod;
4260
- return getStoredAuthMethod() === 'guest' ? 'guest' : 'email';
4295
+ if (getStoredAuthMethod() !== 'guest')
4296
+ return 'email';
4297
+ if (storedSessionIsGuest())
4298
+ return 'guest';
4299
+ // A marker is only a restore hint; the bearer is authoritative. Repair a
4300
+ // stale marker (for example, a crash/failed switch while a human session was
4301
+ // still active) instead of relabelling that human bearer as a guest.
4302
+ const hasSession = !!getStoredIdToken();
4303
+ setStoredAuthMethod(hasSession ? 'email' : null);
4304
+ return 'email';
4261
4305
  }
4262
4306
  function objectIdentityKey(value) {
4263
4307
  if (!value || (typeof value !== 'object' && typeof value !== 'function'))
@@ -4422,7 +4466,7 @@ async function getAuthProvider(config) {
4422
4466
  // manager as legacy email sessions. Human login should be started
4423
4467
  // with loginWithRedirect(); this provider is kept as the restore and
4424
4468
  // logout surface for those sessions.
4425
- currentAuthProvider = new (await Promise.resolve().then(function () { return require('./email-auth-provider-CmunfauO.js'); })).EmailAuthProvider();
4469
+ currentAuthProvider = new (await Promise.resolve().then(function () { return require('./email-auth-provider-Dj66AuH0.js'); })).EmailAuthProvider();
4426
4470
  break;
4427
4471
  case "wallet":
4428
4472
  case "phantom": {
@@ -4441,7 +4485,7 @@ async function getAuthProvider(config) {
4441
4485
  if (!isWalletLoginEnabled(config)) {
4442
4486
  throw walletLoginNotEnabledError(authMethod);
4443
4487
  }
4444
- const { InjectedWalletProvider } = await Promise.resolve().then(function () { return require('./injected-wallet-provider-BBZym7YQ.js'); });
4488
+ const { InjectedWalletProvider } = await Promise.resolve().then(function () { return require('./injected-wallet-provider-Cml9TkyV.js'); });
4445
4489
  currentAuthProvider = new InjectedWalletProvider(resolveInjectedWalletConfig(config), rpcUrl, configuredNetwork);
4446
4490
  break;
4447
4491
  }
@@ -4454,7 +4498,7 @@ async function getAuthProvider(config) {
4454
4498
  // Selecting authMethod:'evm-wallet' IS the opt-in — pass evmWalletConfig
4455
4499
  // to point at a specific wallet or set chainId/domain.
4456
4500
  const evmWalletConfig = ((_a = config.evmWalletConfig) !== null && _a !== void 0 ? _a : {});
4457
- const { InjectedEvmWalletProvider } = await Promise.resolve().then(function () { return require('./injected-evm-wallet-provider-T-EF9C3W.js'); });
4501
+ const { InjectedEvmWalletProvider } = await Promise.resolve().then(function () { return require('./injected-evm-wallet-provider-BLQzWiBP.js'); });
4458
4502
  currentAuthProvider = new InjectedEvmWalletProvider(evmWalletConfig);
4459
4503
  break;
4460
4504
  }
@@ -4482,7 +4526,7 @@ async function getAuthProvider(config) {
4482
4526
  break;
4483
4527
  case "guest":
4484
4528
  // Anonymous auth: a device-local ed25519 keypair signs the challenge.
4485
- currentAuthProvider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-B68XT2lU.js'); })).GuestAuthProvider();
4529
+ currentAuthProvider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-B5sgg-q5.js'); })).GuestAuthProvider();
4486
4530
  break;
4487
4531
  }
4488
4532
  if (!currentAuthProvider) {
@@ -4519,19 +4563,108 @@ function assertBrowserAuthEnv(method) {
4519
4563
  * ownership-as-data pattern. `init()` must have run first. Browser/RN only.
4520
4564
  */
4521
4565
  async function signInAnonymously() {
4566
+ var _a;
4522
4567
  assertBrowserAuthEnv('signInAnonymously');
4523
- const provider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-B68XT2lU.js'); })).GuestAuthProvider();
4524
- currentAuthProvider = provider;
4525
- currentAuthMethod = 'guest';
4526
- currentAuthProviderConfigKey = 'direct:guest';
4568
+ // Resolve configuration before taking the transaction snapshot. Although
4569
+ // getConfig is normally already resolved after init(), it is asynchronous;
4570
+ // another login that finishes during that await must be part of the prior
4571
+ // state we preserve, not accidentally split across old/new snapshots.
4527
4572
  const coreConfig = await core.getConfig();
4528
- coreConfig.authProvider = provider;
4529
- coreConfig.authMethod = 'guest';
4530
- setAuthProviderInstance(provider);
4531
- setStoredAuthMethod('guest');
4573
+ const previousAuthProvider = currentAuthProvider;
4574
+ const previousAuthMethod = currentAuthMethod;
4575
+ const previousProviderConfigKey = currentAuthProviderConfigKey;
4576
+ const previousStoredAuthMethod = getStoredAuthMethod();
4577
+ const previousGlobalProvider = getAuthProviderInstance();
4578
+ const previousUser = getCurrentUser();
4579
+ const previousCoreProvider = coreConfig.authProvider;
4580
+ const previousCoreAuthMethod = coreConfig.authMethod;
4581
+ const previousIdToken = getStoredIdToken();
4582
+ // Lazy-load the guest provider so its ed25519/web3 dependencies stay out of
4583
+ // the main bundle for data-only apps. Specifier is a static string literal
4584
+ // so bundle-splitting can see it.
4585
+ const provider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-B5sgg-q5.js'); })).GuestAuthProvider();
4532
4586
  setAuthLoading(true); // reflect "signing in…" while the guest keypair session is minted
4587
+ const commit = (user) => {
4588
+ // No await/interleaving inside this block: provider/method/config/marker
4589
+ // become guest before the user notification fires, so listeners and
4590
+ // concurrent imperative calls can never observe a mixed identity.
4591
+ currentAuthProvider = provider;
4592
+ currentAuthMethod = 'guest';
4593
+ currentAuthProviderConfigKey = 'direct:guest';
4594
+ coreConfig.authProvider = provider;
4595
+ coreConfig.authMethod = 'guest';
4596
+ setAuthProviderInstance(provider);
4597
+ setStoredAuthMethod('guest');
4598
+ setCurrentUser(user);
4599
+ };
4533
4600
  try {
4534
- return await provider.login();
4601
+ // Mint/store first while every shared provider surface remains on the
4602
+ // previous identity. The provider also withholds setCurrentUser here.
4603
+ const user = await provider.loginForProviderSwitch();
4604
+ if (!user)
4605
+ return null;
4606
+ // A human login may have completed after the guest request persisted but
4607
+ // before its promise resumed here. Re-check the live bearer immediately
4608
+ // before commit so a late guest result cannot overwrite that newer user.
4609
+ if (!user.address || !idTokenIsGuest(getStoredIdToken(), user.address)) {
4610
+ throw new Error('Anonymous sign-in was superseded by another session.');
4611
+ }
4612
+ commit(user);
4613
+ return user;
4614
+ }
4615
+ catch (error) {
4616
+ const currentIdToken = getStoredIdToken();
4617
+ if (currentIdToken !== previousIdToken && idTokenIsGuest(currentIdToken)) {
4618
+ // Defensive applied-yet-error reconciliation: if storage contains a
4619
+ // valid guest bearer/key despite the thrown write, commit that truth
4620
+ // instead of restoring a human UI over a guest token.
4621
+ let recovered = null;
4622
+ try {
4623
+ recovered = await provider.restoreSessionForProviderSwitch();
4624
+ }
4625
+ catch (_b) {
4626
+ try {
4627
+ core.getActiveSessionManager().clearSession();
4628
+ }
4629
+ catch ( /* fail closed below */_c) { /* fail closed below */ }
4630
+ }
4631
+ if (recovered) {
4632
+ commit(recovered);
4633
+ return recovered;
4634
+ }
4635
+ // restoreSessionForProviderSwitch fails closed and clears a split
4636
+ // bearer. Do not resurrect a user object that no longer has its token.
4637
+ setCurrentUser(null);
4638
+ }
4639
+ else if (currentIdToken === previousIdToken) {
4640
+ // The staged attempt never changed the bearer; every shared provider
4641
+ // surface stayed untouched, so restore the exact prior user/marker.
4642
+ currentAuthProvider = previousAuthProvider;
4643
+ currentAuthMethod = previousAuthMethod;
4644
+ currentAuthProviderConfigKey = previousProviderConfigKey;
4645
+ coreConfig.authProvider = previousCoreProvider;
4646
+ coreConfig.authMethod = previousCoreAuthMethod;
4647
+ setAuthProviderInstance(previousGlobalProvider);
4648
+ setStoredAuthMethod(previousStoredAuthMethod);
4649
+ if (getCurrentUser() !== previousUser)
4650
+ setCurrentUser(previousUser);
4651
+ }
4652
+ else {
4653
+ // A different non-guest token won while this staged guest mint was in
4654
+ // flight (another tab/popup/login). The guest attempt never mutated
4655
+ // shared provider state, so preserve that winner exactly. Align only
4656
+ // this module's private registry to the provider the winner installed;
4657
+ // never overwrite its core/global provider, marker, or user snapshot.
4658
+ const concurrentProvider = (_a = getAuthProviderInstance()) !== null && _a !== void 0 ? _a : coreConfig.authProvider;
4659
+ if (concurrentProvider)
4660
+ currentAuthProvider = concurrentProvider;
4661
+ const concurrentStoredMethod = getStoredAuthMethod();
4662
+ currentAuthMethod = concurrentStoredMethod && concurrentStoredMethod !== 'guest'
4663
+ ? concurrentStoredMethod
4664
+ : (previousAuthMethod && previousAuthMethod !== 'guest' ? previousAuthMethod : 'email');
4665
+ currentAuthProviderConfigKey = previousProviderConfigKey;
4666
+ }
4667
+ throw error;
4535
4668
  }
4536
4669
  finally {
4537
4670
  setAuthLoading(false);
@@ -4828,21 +4961,25 @@ function setCurrentUser(user) {
4828
4961
  function getCurrentUser() {
4829
4962
  return currentUser;
4830
4963
  }
4964
+ /** @internal Snapshot/restore surface for transactional auth-provider switches. */
4965
+ function getAuthProviderInstance() {
4966
+ return authProviderInstance;
4967
+ }
4831
4968
  function setAuthProviderInstance(provider) {
4832
4969
  authProviderInstance = provider;
4833
4970
  }
4834
4971
 
4835
- var _a;
4972
+ var _a$2;
4836
4973
  // Whether we're in a server-side rendering context (no hooks allowed).
4837
4974
  // React Native has no `window` but DOES support hooks.
4838
4975
  // We detect Node SSR specifically via process.versions.node to avoid
4839
4976
  // false positives from Node 21+ which defines `navigator` globally.
4840
- const isSSR = typeof window === 'undefined'
4977
+ const isSSR$2 = typeof window === 'undefined'
4841
4978
  && typeof process !== 'undefined'
4842
- && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
4979
+ && !!((_a$2 = process.versions) === null || _a$2 === void 0 ? void 0 : _a$2.node);
4843
4980
  function useAuth() {
4844
4981
  // Provide a fallback so server render doesn't break
4845
- if (isSSR) {
4982
+ if (isSSR$2) {
4846
4983
  return {
4847
4984
  login: async (_options) => undefined,
4848
4985
  logout: async () => undefined,
@@ -4904,6 +5041,613 @@ function useAuth() {
4904
5041
  };
4905
5042
  }
4906
5043
 
5044
+ var _a$1;
5045
+ // SSR guard (mirrors useAuth): no hooks/subscriptions during Node server render.
5046
+ // React Native has no `window` but DOES support hooks, so detect Node SSR
5047
+ // specifically via process.versions.node.
5048
+ const isSSR$1 = typeof window === 'undefined'
5049
+ && typeof process !== 'undefined'
5050
+ && !!((_a$1 = process.versions) === null || _a$1 === void 0 ? void 0 : _a$1.node);
5051
+ function useQuery(path, options) {
5052
+ if (isSSR$1) {
5053
+ return { data: undefined, loading: true, error: null };
5054
+ }
5055
+ const [data, setData] = React__namespace.useState(undefined);
5056
+ const [loading, setLoading] = React__namespace.useState(true);
5057
+ const [error, setError] = React__namespace.useState(null);
5058
+ // Re-subscribe only when the query actually changes (not on every render).
5059
+ const optionsKey = options ? JSON.stringify(options) : '';
5060
+ React__namespace.useEffect(() => {
5061
+ if (!path) {
5062
+ setData(undefined);
5063
+ setLoading(false);
5064
+ setError(null);
5065
+ return;
5066
+ }
5067
+ let active = true;
5068
+ let unsubscribe;
5069
+ setLoading(true);
5070
+ setError(null);
5071
+ core.subscribe(path, Object.assign(Object.assign({}, options), { onData: (d) => {
5072
+ if (!active)
5073
+ return;
5074
+ // A reconnect can legitimately surface a transport error before the
5075
+ // socket re-authenticates and sends a new authorized snapshot. That
5076
+ // fresh snapshot is the recovery boundary: keep the error visible
5077
+ // until data arrives, then clear it so React does not remain stuck on
5078
+ // a failure page after realtime has recovered.
5079
+ setError(null);
5080
+ setData(d);
5081
+ setLoading(false);
5082
+ }, onError: (e) => {
5083
+ if (!active)
5084
+ return;
5085
+ setError(e instanceof Error ? e : new Error(String(e)));
5086
+ setLoading(false);
5087
+ } }))
5088
+ .then((unsub) => {
5089
+ if (active)
5090
+ unsubscribe = unsub;
5091
+ else
5092
+ void unsub(); // unmounted before subscribe resolved
5093
+ })
5094
+ .catch((e) => {
5095
+ if (!active)
5096
+ return;
5097
+ setError(e instanceof Error ? e : new Error(String(e)));
5098
+ setLoading(false);
5099
+ });
5100
+ return () => {
5101
+ active = false;
5102
+ void (unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
5103
+ };
5104
+ // optionsKey captures the option object's contents; path is the other input.
5105
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5106
+ }, [path, optionsKey]);
5107
+ return { data, loading, error };
5108
+ }
5109
+
5110
+ // Wrapper for getIdToken - passes isServer=false for client-side usage
5111
+ async function getIdToken() {
5112
+ return core.getIdToken(false);
5113
+ }
5114
+
5115
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
5116
+ var t = {};
5117
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5118
+ t[p] = s[p];
5119
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
5120
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
5121
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
5122
+ t[p[i]] = s[p[i]];
5123
+ }
5124
+ return t;
5125
+ };
5126
+ /** A structured non-2xx response from the developer API. */
5127
+ class BuildsApiError extends Error {
5128
+ constructor(init) {
5129
+ super(init.message);
5130
+ this.name = 'BuildsApiError';
5131
+ this.code = init.code;
5132
+ this.retryable = init.retryable;
5133
+ this.status = init.status;
5134
+ this.details = init.details;
5135
+ this.retryAfterMs = init.retryAfterMs;
5136
+ }
5137
+ }
5138
+ const memoryIdempotencyKeys = new Map();
5139
+ const IDEMPOTENCY_STORAGE_PREFIX = 'bounded:build:idempotency:';
5140
+ function retryAfterMs(response) {
5141
+ var _a, _b;
5142
+ const value = (_b = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, 'Retry-After');
5143
+ if (!value)
5144
+ return undefined;
5145
+ const seconds = Number(value);
5146
+ if (Number.isFinite(seconds) && seconds >= 0)
5147
+ return Math.ceil(seconds * 1000);
5148
+ const at = Date.parse(value);
5149
+ if (!Number.isFinite(at))
5150
+ return undefined;
5151
+ return Math.max(0, at - Date.now());
5152
+ }
5153
+ async function responseBody(response) {
5154
+ const text = await response.text();
5155
+ if (!text)
5156
+ return {};
5157
+ try {
5158
+ return JSON.parse(text);
5159
+ }
5160
+ catch (_a) {
5161
+ return { raw: text };
5162
+ }
5163
+ }
5164
+ function apiError(response, body) {
5165
+ const envelope = body;
5166
+ const nested = (envelope === null || envelope === void 0 ? void 0 : envelope.error) && typeof envelope.error === 'object'
5167
+ ? envelope.error
5168
+ : undefined;
5169
+ const hasNestedDetails = !!nested && Object.prototype.hasOwnProperty.call(nested, 'details');
5170
+ const hasTopLevelDetails = !!body
5171
+ && typeof body === 'object'
5172
+ && Object.prototype.hasOwnProperty.call(body, 'details');
5173
+ const legacyCode = typeof (body === null || body === void 0 ? void 0 : body.error) === 'string' ? body.error : undefined;
5174
+ const code = typeof (nested === null || nested === void 0 ? void 0 : nested.code) === 'string'
5175
+ ? nested.code
5176
+ : legacyCode !== null && legacyCode !== void 0 ? legacyCode : `http_${response.status}`;
5177
+ const message = typeof (nested === null || nested === void 0 ? void 0 : nested.message) === 'string'
5178
+ ? nested.message
5179
+ : typeof (body === null || body === void 0 ? void 0 : body.message) === 'string'
5180
+ ? body.message
5181
+ : `Developer API request failed with HTTP ${response.status}`;
5182
+ const retryable = typeof (nested === null || nested === void 0 ? void 0 : nested.retryable) === 'boolean'
5183
+ ? nested.retryable
5184
+ : response.status === 429 || response.status >= 500;
5185
+ return new BuildsApiError(Object.assign(Object.assign({ code,
5186
+ message,
5187
+ retryable, status: response.status }, (hasNestedDetails
5188
+ ? { details: nested === null || nested === void 0 ? void 0 : nested.details }
5189
+ : hasTopLevelDetails
5190
+ ? { details: body.details }
5191
+ : {})), (response.status === 429 ? { retryAfterMs: retryAfterMs(response) } : {})));
5192
+ }
5193
+ /** @internal Shared authenticated developer-api transport for builds and apps. */
5194
+ async function requestDevApi(path, request = {}) {
5195
+ var _a, _b;
5196
+ const config = await core.getConfig();
5197
+ const base = (_a = config.devApiUrl) === null || _a === void 0 ? void 0 : _a.replace(/\/$/, '');
5198
+ if (!base) {
5199
+ throw new Error('Bounded developer API is not configured. Pass devApiUrl or a Bounded network to init().');
5200
+ }
5201
+ // Reuse the exact accessor exposed publicly as getIdToken().
5202
+ const token = await getIdToken();
5203
+ if (!token) {
5204
+ throw new BuildsApiError({
5205
+ code: 'auth_required',
5206
+ message: 'Sign in before calling the Bounded developer API.',
5207
+ retryable: false,
5208
+ status: 401,
5209
+ });
5210
+ }
5211
+ const hasBody = request.body !== undefined;
5212
+ const response = await fetch(`${base}${path}`, Object.assign({ method: (_b = request.method) !== null && _b !== void 0 ? _b : 'GET', headers: Object.assign({ Authorization: `Bearer ${token}` }, (hasBody ? { 'Content-Type': 'application/json' } : {})) }, (hasBody ? { body: JSON.stringify(request.body) } : {})));
5213
+ const body = await responseBody(response);
5214
+ if (!response.ok)
5215
+ throw apiError(response, body);
5216
+ return body;
5217
+ }
5218
+ function intentStorageKey(intentKey) {
5219
+ return `${IDEMPOTENCY_STORAGE_PREFIX}${intentKey}`;
5220
+ }
5221
+ function isValidIdempotencyKey(value) {
5222
+ return typeof value === 'string' && value.length > 0 && value.length <= 256;
5223
+ }
5224
+ function readPersistedIdempotencyKey(intentKey) {
5225
+ var _a;
5226
+ const storageKey = intentStorageKey(intentKey);
5227
+ try {
5228
+ const stored = (_a = globalThis.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem(storageKey);
5229
+ if (isValidIdempotencyKey(stored))
5230
+ return stored;
5231
+ }
5232
+ catch (_b) {
5233
+ // Storage can be disabled by browser privacy policy; use module memory.
5234
+ }
5235
+ const inMemory = memoryIdempotencyKeys.get(storageKey);
5236
+ return isValidIdempotencyKey(inMemory) ? inMemory : undefined;
5237
+ }
5238
+ function persistIdempotencyKey(intentKey, idempotencyKey) {
5239
+ var _a;
5240
+ const storageKey = intentStorageKey(intentKey);
5241
+ memoryIdempotencyKeys.set(storageKey, idempotencyKey);
5242
+ try {
5243
+ (_a = globalThis.sessionStorage) === null || _a === void 0 ? void 0 : _a.setItem(storageKey, idempotencyKey);
5244
+ }
5245
+ catch (_b) {
5246
+ // The in-memory write above is the React Native / disabled-storage fallback.
5247
+ }
5248
+ }
5249
+ function randomHex(bytes) {
5250
+ const cryptoObject = globalThis.crypto;
5251
+ if (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.getRandomValues) {
5252
+ const values = new Uint8Array(bytes);
5253
+ cryptoObject.getRandomValues(values);
5254
+ return Array.from(values, (value) => value.toString(16).padStart(2, '0')).join('');
5255
+ }
5256
+ let value = '';
5257
+ for (let index = 0; index < bytes; index += 1) {
5258
+ value += Math.floor(Math.random() * 256).toString(16).padStart(2, '0');
5259
+ }
5260
+ return value;
5261
+ }
5262
+ function mintIdempotencyKey() {
5263
+ const cryptoObject = globalThis.crypto;
5264
+ if (typeof (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.randomUUID) === 'function') {
5265
+ return `build_${cryptoObject.randomUUID()}`;
5266
+ }
5267
+ return `build_${Date.now().toString(36)}_${randomHex(16)}`;
5268
+ }
5269
+ function actionIdempotencyKey(options, action) {
5270
+ const supplied = options.idempotencyKey;
5271
+ if (supplied !== undefined) {
5272
+ if (!isValidIdempotencyKey(supplied)) {
5273
+ throw new TypeError('idempotencyKey must be between 1 and 256 characters.');
5274
+ }
5275
+ if (options.intentKey)
5276
+ persistIdempotencyKey(options.intentKey, supplied);
5277
+ return supplied;
5278
+ }
5279
+ if (!options.intentKey) {
5280
+ throw new TypeError(`intentKey is required when ${action} auto-mints an idempotency key.`);
5281
+ }
5282
+ const existing = readPersistedIdempotencyKey(options.intentKey);
5283
+ if (existing)
5284
+ return existing;
5285
+ const minted = mintIdempotencyKey();
5286
+ // This is deliberately synchronous and happens before requestDevApi can fetch.
5287
+ persistIdempotencyKey(options.intentKey, minted);
5288
+ return minted;
5289
+ }
5290
+ function appPath(appId) {
5291
+ return `/app/${encodeURIComponent(appId)}/builds`;
5292
+ }
5293
+ async function submit(appId, options) {
5294
+ const idempotencyKey = actionIdempotencyKey(options, 'submit()');
5295
+ const { intentKey: _intentKey, idempotencyKey: _suppliedKey } = options, submission = __rest(options, ["intentKey", "idempotencyKey"]);
5296
+ return requestDevApi(appPath(appId), {
5297
+ method: 'POST',
5298
+ body: Object.assign(Object.assign({}, submission), { idempotencyKey }),
5299
+ });
5300
+ }
5301
+ async function get(appId, runId) {
5302
+ return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}`);
5303
+ }
5304
+ async function events(appId, runId, after = 0) {
5305
+ const cursor = Number.isFinite(after) ? Math.max(0, Math.floor(after)) : 0;
5306
+ return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}/events?after=${cursor}`);
5307
+ }
5308
+ async function cancel(appId, runId) {
5309
+ return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}/cancel`, { method: 'POST' });
5310
+ }
5311
+ async function decideGate(appId, runId, gateId, options) {
5312
+ const idempotencyKey = actionIdempotencyKey(options, 'decideGate()');
5313
+ const { intentKey: _intentKey, idempotencyKey: _suppliedKey } = options, decision = __rest(options, ["intentKey", "idempotencyKey"]);
5314
+ return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}/gates/${encodeURIComponent(gateId)}/decision`, { method: 'POST', body: Object.assign(Object.assign({}, decision), { idempotencyKey }) });
5315
+ }
5316
+ async function topup(appId, runId, options) {
5317
+ return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}/topup`, { method: 'POST', body: options });
5318
+ }
5319
+ async function list$1(appId, limit = 20) {
5320
+ const requestedLimit = Number.isFinite(limit) ? Math.max(1, Math.floor(limit)) : 20;
5321
+ return requestDevApi(`${appPath(appId)}?limit=${requestedLimit}`);
5322
+ }
5323
+
5324
+ // Source of truth for these strings:
5325
+ // packages/cdk/cloudflare/bounded-build/src/types.ts. Keep them string-pinned;
5326
+ // wire:1 remains additive and callers must tolerate unknown response strings.
5327
+ const NON_TERMINAL_STATES = [
5328
+ 'queued',
5329
+ 'admitted',
5330
+ 'executing',
5331
+ 'preview_ready',
5332
+ 'parked',
5333
+ 'resuming',
5334
+ 'promoting',
5335
+ 'quarantined',
5336
+ ];
5337
+ const TERMINAL_STATES = [
5338
+ 'promoted',
5339
+ 'failed',
5340
+ 'canceled',
5341
+ 'rejected',
5342
+ 'expired',
5343
+ 'rebase_required',
5344
+ 'reported',
5345
+ ];
5346
+ const RUN_STATES = [
5347
+ ...NON_TERMINAL_STATES,
5348
+ ...TERMINAL_STATES,
5349
+ ];
5350
+ const PARK_REASONS = ['gate', 'funding'];
5351
+ const FAILURE_REASONS = [
5352
+ 'admission_rejected',
5353
+ 'dispatch_timeout',
5354
+ 'auth_revoked',
5355
+ 'owner_changed',
5356
+ 'policy_changed',
5357
+ 'quarantine_forced',
5358
+ 'bind_failed',
5359
+ 'internal_error',
5360
+ ];
5361
+
5362
+ const NORMAL_POLL_MS = 2000;
5363
+ const PARKED_POLL_MS = 5000;
5364
+ const LONG_RUNNING_POLL_MS = 10000;
5365
+ const TWO_MINUTES_MS = 2 * 60000;
5366
+ const TEN_MINUTES_MS = 10 * 60000;
5367
+ const terminalStates = new Set(TERMINAL_STATES);
5368
+ function pollCadence(state, elapsedMs) {
5369
+ if (elapsedMs >= TEN_MINUTES_MS)
5370
+ return LONG_RUNNING_POLL_MS;
5371
+ if ((state === null || state === void 0 ? void 0 : state.startsWith('parked')) || elapsedMs >= TWO_MINUTES_MS)
5372
+ return PARKED_POLL_MS;
5373
+ return NORMAL_POLL_MS;
5374
+ }
5375
+ function retryCadence(error, state, elapsedMs) {
5376
+ const cadence = pollCadence(state, elapsedMs);
5377
+ if (error instanceof BuildsApiError && error.status === 429 && error.retryAfterMs !== undefined) {
5378
+ return Math.max(cadence, error.retryAfterMs);
5379
+ }
5380
+ return cadence;
5381
+ }
5382
+ function hasRetryAfter(error) {
5383
+ return error instanceof BuildsApiError
5384
+ && error.status === 429
5385
+ && error.retryAfterMs !== undefined;
5386
+ }
5387
+ // A permanent API refusal (expired session, revoked access, unknown run) will
5388
+ // never heal by re-polling; the loop must stop and surface it instead of
5389
+ // retrying forever. 429 stays retryable regardless of the server envelope.
5390
+ function isPermanentError(error) {
5391
+ return error instanceof BuildsApiError
5392
+ && error.status !== 429
5393
+ && error.retryable === false;
5394
+ }
5395
+ function newEvents(rows, lastSeq, seen) {
5396
+ const cursorBeforePoll = lastSeq;
5397
+ const fresh = [];
5398
+ let nextCursor = lastSeq;
5399
+ for (const event of rows) {
5400
+ if (!Number.isFinite(event === null || event === void 0 ? void 0 : event.seq))
5401
+ continue;
5402
+ nextCursor = Math.max(nextCursor, event.seq);
5403
+ if (event.seq <= cursorBeforePoll || seen.has(event.seq))
5404
+ continue;
5405
+ seen.add(event.seq);
5406
+ fresh.push(event);
5407
+ }
5408
+ return { events: fresh, lastSeq: nextCursor };
5409
+ }
5410
+ /**
5411
+ * Poll a build view and its event cursor until stopped or the run reaches a
5412
+ * known terminal state. Unknown state strings remain untouched and nonterminal.
5413
+ */
5414
+ function watch(appId, runId, onUpdate, options = {}) {
5415
+ const startedAt = Date.now();
5416
+ const seenSeqs = new Set();
5417
+ let lastSeq = Number.isFinite(options.after)
5418
+ ? Math.max(0, Math.floor(options.after))
5419
+ : 0;
5420
+ let timer;
5421
+ let active = true;
5422
+ let lastState;
5423
+ const stop = () => {
5424
+ active = false;
5425
+ if (timer !== undefined) {
5426
+ clearTimeout(timer);
5427
+ timer = undefined;
5428
+ }
5429
+ };
5430
+ const schedule = (delayMs) => {
5431
+ if (!active)
5432
+ return;
5433
+ timer = setTimeout(() => {
5434
+ timer = undefined;
5435
+ void poll();
5436
+ }, delayMs);
5437
+ };
5438
+ const reportError = (error) => {
5439
+ var _a;
5440
+ try {
5441
+ (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
5442
+ }
5443
+ catch (_b) {
5444
+ // A consumer error callback must not break the transport loop.
5445
+ }
5446
+ };
5447
+ const publish = (run, events) => {
5448
+ try {
5449
+ onUpdate({ run, events });
5450
+ }
5451
+ catch (_a) {
5452
+ // Polling is transport state; consumer render errors must not strand it.
5453
+ }
5454
+ };
5455
+ const poll = async () => {
5456
+ if (!active)
5457
+ return;
5458
+ let run;
5459
+ try {
5460
+ const view = await get(appId, runId);
5461
+ if (!active)
5462
+ return;
5463
+ run = view.run;
5464
+ lastState = run.state;
5465
+ }
5466
+ catch (error) {
5467
+ if (!active)
5468
+ return;
5469
+ reportError(error);
5470
+ if (isPermanentError(error)) {
5471
+ stop();
5472
+ return;
5473
+ }
5474
+ schedule(retryCadence(error, lastState, Date.now() - startedAt));
5475
+ return;
5476
+ }
5477
+ try {
5478
+ const response = await events(appId, runId, lastSeq);
5479
+ if (!active)
5480
+ return;
5481
+ const deduped = newEvents(Array.isArray(response.events) ? response.events : [], lastSeq, seenSeqs);
5482
+ lastSeq = deduped.lastSeq;
5483
+ publish(run, deduped.events);
5484
+ }
5485
+ catch (error) {
5486
+ if (!active)
5487
+ return;
5488
+ // The view still advances UI state even when event replay is rate-limited.
5489
+ publish(run, []);
5490
+ reportError(error);
5491
+ if (terminalStates.has(run.state)) {
5492
+ // The run itself is done, but a rate-limited final event replay still
5493
+ // owes the caller its unseen seq rows. Honor Retry-After, retry the
5494
+ // piggyback once the limiter permits it, then stop after a successful
5495
+ // replay. Other terminal replay failures stop normally.
5496
+ if (hasRetryAfter(error)) {
5497
+ schedule(retryCadence(error, run.state, Date.now() - startedAt));
5498
+ return;
5499
+ }
5500
+ stop();
5501
+ return;
5502
+ }
5503
+ if (isPermanentError(error)) {
5504
+ stop();
5505
+ return;
5506
+ }
5507
+ schedule(retryCadence(error, run.state, Date.now() - startedAt));
5508
+ return;
5509
+ }
5510
+ if (!active)
5511
+ return;
5512
+ if (terminalStates.has(run.state)) {
5513
+ // Drain the remaining event pages before stopping: a resumed terminal
5514
+ // watch may owe the caller more rows than one page returns. Each page
5515
+ // advances the cursor, so the loop terminates; the cap is a backstop.
5516
+ for (let page = 0; page < 50 && active; page += 1) {
5517
+ let drained;
5518
+ try {
5519
+ const response = await events(appId, runId, lastSeq);
5520
+ if (!active)
5521
+ return;
5522
+ drained = newEvents(Array.isArray(response.events) ? response.events : [], lastSeq, seenSeqs);
5523
+ }
5524
+ catch (error) {
5525
+ reportError(error);
5526
+ break;
5527
+ }
5528
+ if (drained.events.length === 0)
5529
+ break;
5530
+ lastSeq = drained.lastSeq;
5531
+ publish(run, drained.events);
5532
+ }
5533
+ stop();
5534
+ return;
5535
+ }
5536
+ schedule(pollCadence(run.state, Date.now() - startedAt));
5537
+ };
5538
+ void poll();
5539
+ return { stop };
5540
+ }
5541
+
5542
+ var _a;
5543
+ // SSR guard (mirrors useAuth): no hooks/subscriptions during Node server render.
5544
+ // React Native has no `window` but DOES support hooks, so detect Node SSR
5545
+ // specifically via process.versions.node.
5546
+ const isSSR = typeof window === 'undefined'
5547
+ && typeof process !== 'undefined'
5548
+ && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
5549
+ function useBuildRun(appId, runId, options) {
5550
+ if (isSSR) {
5551
+ return { run: null, events: [], loading: true, error: null };
5552
+ }
5553
+ const [run, setRun] = React__namespace.useState(null);
5554
+ const [events, setEvents] = React__namespace.useState([]);
5555
+ const [loading, setLoading] = React__namespace.useState(true);
5556
+ const [error, setError] = React__namespace.useState(null);
5557
+ const optionsKey = options ? JSON.stringify(options) : '';
5558
+ React__namespace.useEffect(() => {
5559
+ setRun(null);
5560
+ setEvents([]);
5561
+ setError(null);
5562
+ if (!appId || !runId) {
5563
+ setLoading(false);
5564
+ return;
5565
+ }
5566
+ let active = true;
5567
+ setLoading(true);
5568
+ const handle = watch(appId, runId, ({ run: nextRun, events: nextEvents }) => {
5569
+ if (!active)
5570
+ return;
5571
+ setRun(nextRun);
5572
+ if (nextEvents.length > 0) {
5573
+ setEvents((current) => {
5574
+ const seen = new Set(current.map((event) => event.seq));
5575
+ return [...current, ...nextEvents.filter((event) => !seen.has(event.seq))];
5576
+ });
5577
+ }
5578
+ setError(null);
5579
+ setLoading(false);
5580
+ }, Object.assign(Object.assign({}, options), { onError: (value) => {
5581
+ if (!active)
5582
+ return;
5583
+ setError(value instanceof Error ? value : new Error(String(value)));
5584
+ setLoading(false);
5585
+ } }));
5586
+ return () => {
5587
+ active = false;
5588
+ handle.stop();
5589
+ };
5590
+ // optionsKey captures the option object's contents; ids are the other inputs.
5591
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5592
+ }, [appId, runId, optionsKey]);
5593
+ return { run, events, loading, error };
5594
+ }
5595
+
5596
+ /**
5597
+ * Platform first-party surfaces only (bounded.sh, oapps.fun, localhost) —
5598
+ * dev-api CORS blocks calls from generated-app origins. Server-side callers unaffected.
5599
+ */
5600
+ const builds = {
5601
+ submit,
5602
+ get,
5603
+ events,
5604
+ cancel,
5605
+ decideGate,
5606
+ topup,
5607
+ list: list$1,
5608
+ watch,
5609
+ };
5610
+
5611
+ async function create(options = {}) {
5612
+ const body = Object.assign(Object.assign(Object.assign(Object.assign({}, (options.name !== undefined ? { name: options.name } : {})), (options.prompt !== undefined ? { prompt: options.prompt } : {})), (options.clientToken !== undefined ? { clientToken: options.clientToken } : {})), (options.intent !== undefined ? { intent: options.intent } : {}));
5613
+ const app = await requestDevApi('/apps/new', {
5614
+ method: 'POST',
5615
+ body,
5616
+ });
5617
+ return Object.assign(Object.assign({ appId: app.appId }, (typeof app.slug === 'string' && app.slug ? { slug: app.slug } : {})), { url: app.url,
5618
+ // Fail closed against an older server response that omitted this field.
5619
+ policySeeded: app.policySeeded === true });
5620
+ }
5621
+ async function list() {
5622
+ // This legacy-compatible action shape is also used by oapps.fun listMyApps.
5623
+ const response = await requestDevApi('/', {
5624
+ method: 'POST',
5625
+ body: { action: 'listApps' },
5626
+ });
5627
+ const rows = Array.isArray(response.apps) ? response.apps : [];
5628
+ return rows
5629
+ .map((value) => {
5630
+ var _a, _b, _c, _d;
5631
+ const row = value && typeof value === 'object'
5632
+ ? value
5633
+ : {};
5634
+ const appId = String((_c = (_b = (_a = row._id) !== null && _a !== void 0 ? _a : row.id) !== null && _b !== void 0 ? _b : row.appId) !== null && _c !== void 0 ? _c : '');
5635
+ if (!/^[a-f0-9]{24}$/i.test(appId))
5636
+ return null;
5637
+ const name = String((_d = row.name) !== null && _d !== void 0 ? _d : '').trim() || '(unnamed app)';
5638
+ const slug = typeof row.slug === 'string' && row.slug ? row.slug : undefined;
5639
+ const url = typeof row.url === 'string' && row.url.trim() ? row.url.trim() : undefined;
5640
+ return Object.assign(Object.assign({ appId,
5641
+ name }, (slug ? { slug } : {})), (url ? { url } : {}));
5642
+ })
5643
+ .filter((app) => app !== null);
5644
+ }
5645
+ /**
5646
+ * Platform first-party surfaces only (bounded.sh, oapps.fun, localhost) —
5647
+ * dev-api CORS blocks calls from generated-app origins. Server-side callers unaffected.
5648
+ */
5649
+ const apps = { create, list };
5650
+
4907
5651
  async function deserializeTransaction(tx) {
4908
5652
  // Literal specifier so bundlers can code-split the lazy chunk.
4909
5653
  const { Transaction, VersionedTransaction } = await import('@solana/web3.js');
@@ -4916,11 +5660,6 @@ async function deserializeTransaction(tx) {
4916
5660
  }
4917
5661
  }
4918
5662
 
4919
- // Wrapper for getIdToken - passes isServer=false for client-side usage
4920
- async function getIdToken() {
4921
- return core.getIdToken(false);
4922
- }
4923
-
4924
5663
  /**
4925
5664
  * Extracts a human-readable error message from Solana transaction logs.
4926
5665
  */
@@ -5316,15 +6055,110 @@ class PrivyExpoProvider {
5316
6055
  }
5317
6056
  }
5318
6057
 
6058
+ /**
6059
+ * Default provider discovery: Phantom-first, then any Wallet-Standard
6060
+ * `window.solana`. Kept tiny + synchronous (no heavy imports) so it works inside
6061
+ * a user gesture and can be eagerly exported from the SDK entry.
6062
+ */
6063
+ function defaultInjectedProvider() {
6064
+ var _a;
6065
+ if (typeof window === 'undefined')
6066
+ return null;
6067
+ const w = window;
6068
+ const phantom = (_a = w === null || w === void 0 ? void 0 : w.phantom) === null || _a === void 0 ? void 0 : _a.solana;
6069
+ if (phantom && typeof phantom.signMessage === 'function')
6070
+ return phantom;
6071
+ const generic = w === null || w === void 0 ? void 0 : w.solana;
6072
+ if (generic && typeof generic.signMessage === 'function')
6073
+ return generic;
6074
+ return null;
6075
+ }
6076
+
6077
+ // injected-evm-wallet-types.ts — tiny, dependency-free surface for the EVM
6078
+ // WALLET LOGIN path (BYO wallet via SIWE). The EVM twin of
6079
+ // injected-wallet-types.ts: kept separate from injected-evm-wallet-provider.ts
6080
+ // so the SDK entry can eagerly export the type surface + the provider-discovery
6081
+ // helper WITHOUT dragging the provider class into the default bundle. The
6082
+ // provider is lazy-loaded by getAuthProvider() when an app opts into
6083
+ // authMethod:'evm-wallet'.
6084
+ //
6085
+ // It rides the standard EIP-1193 injected provider a browser wallet exposes
6086
+ // (MetaMask / Rabby / Coinbase Wallet / any window.ethereum), discovered via
6087
+ // EIP-6963 (multi-wallet, collision-free) with a window.ethereum fallback. It
6088
+ // needs NO viem/ethers and NO React — EIP-1193 request() + hex strings suffice.
6089
+ // EIP-6963 is announcement-based: wallets add an `eip6963:requestProvider`
6090
+ // listener and synchronously dispatch `eip6963:announceProvider` in response. We
6091
+ // keep a persistent collector so announcements (including late ones) are
6092
+ // captured, and re-request on demand.
6093
+ const announcedProviders = [];
6094
+ let announceListenerAttached = false;
6095
+ function attachAnnounceListener() {
6096
+ if (announceListenerAttached || typeof window === 'undefined')
6097
+ return;
6098
+ announceListenerAttached = true;
6099
+ window.addEventListener('eip6963:announceProvider', (event) => {
6100
+ const detail = event === null || event === void 0 ? void 0 : event.detail;
6101
+ if (detail &&
6102
+ detail.provider &&
6103
+ typeof detail.provider.request === 'function' &&
6104
+ !announcedProviders.some((d) => { var _a, _b; return ((_a = d.info) === null || _a === void 0 ? void 0 : _a.uuid) === ((_b = detail.info) === null || _b === void 0 ? void 0 : _b.uuid); })) {
6105
+ announcedProviders.push(detail);
6106
+ }
6107
+ });
6108
+ }
6109
+ /**
6110
+ * Request + collect EIP-6963 providers. Dispatches `eip6963:requestProvider`
6111
+ * (synchronous — already-loaded wallets announce in the same tick) and returns
6112
+ * every wallet announced so far. Kept synchronous so it works inside a user
6113
+ * gesture and can be eagerly exported from the SDK entry.
6114
+ */
6115
+ function requestEip6963Providers() {
6116
+ if (typeof window === 'undefined')
6117
+ return [];
6118
+ attachAnnounceListener();
6119
+ try {
6120
+ window.dispatchEvent(new Event('eip6963:requestProvider'));
6121
+ }
6122
+ catch (_a) {
6123
+ /* older browsers without Event constructor — fall through to window.ethereum */
6124
+ }
6125
+ return announcedProviders.slice();
6126
+ }
6127
+ /**
6128
+ * Default EVM provider discovery: EIP-6963 first (multi-wallet, collision-free),
6129
+ * then legacy `window.ethereum`. Returns null when no injected wallet is present.
6130
+ */
6131
+ function defaultInjectedEvmProvider() {
6132
+ if (typeof window === 'undefined')
6133
+ return null;
6134
+ const details = requestEip6963Providers();
6135
+ if (details.length > 0)
6136
+ return details[0].provider;
6137
+ const eth = window.ethereum;
6138
+ if (eth && typeof eth.request === 'function')
6139
+ return eth;
6140
+ return null;
6141
+ }
6142
+
6143
+ exports.BuildsApiError = BuildsApiError;
5319
6144
  exports.EMBEDDED_WALLET_UNSUPPORTED = EMBEDDED_WALLET_UNSUPPORTED;
6145
+ exports.FAILURE_REASONS = FAILURE_REASONS;
6146
+ exports.NON_TERMINAL_STATES = NON_TERMINAL_STATES;
5320
6147
  exports.OffchainAuthProvider = OffchainAuthProvider;
6148
+ exports.PARK_REASONS = PARK_REASONS;
5321
6149
  exports.PrivyExpoProvider = PrivyExpoProvider;
6150
+ exports.RUN_STATES = RUN_STATES;
5322
6151
  exports.SURFNET_RPC_URL = SURFNET_RPC_URL;
6152
+ exports.TERMINAL_STATES = TERMINAL_STATES;
6153
+ exports.apps = apps;
5323
6154
  exports.bs58 = bs58;
5324
6155
  exports.bufferExports = bufferExports;
6156
+ exports.builds = builds;
5325
6157
  exports.completeLoginFromRedirect = completeLoginFromRedirect;
5326
6158
  exports.completeLoginInPopup = completeLoginInPopup;
5327
6159
  exports.confirmAndCheckTransaction = confirmAndCheckTransaction;
6160
+ exports.defaultInjectedEvmProvider = defaultInjectedEvmProvider;
6161
+ exports.defaultInjectedProvider = defaultInjectedProvider;
5328
6162
  exports.deserializeTransaction = deserializeTransaction;
5329
6163
  exports.embeddedRunEvmTransaction = embeddedRunEvmTransaction;
5330
6164
  exports.embeddedSignAndSubmit = embeddedSignAndSubmit;
@@ -5344,10 +6178,13 @@ exports.logout = logout;
5344
6178
  exports.normalizeSolanaRpcUrl = normalizeSolanaRpcUrl;
5345
6179
  exports.onAuthLoadingChanged = onAuthLoadingChanged;
5346
6180
  exports.onAuthStateChanged = onAuthStateChanged;
6181
+ exports.requestEip6963Providers = requestEip6963Providers;
5347
6182
  exports.resolveSolanaRpcUrl = resolveSolanaRpcUrl;
5348
6183
  exports.setAuthLoading = setAuthLoading;
5349
6184
  exports.setCurrentUser = setCurrentUser;
5350
6185
  exports.setPlatform = setPlatform;
5351
6186
  exports.signInAnonymously = signInAnonymously;
5352
6187
  exports.useAuth = useAuth;
5353
- //# sourceMappingURL=index.native-BZCc0gO-.js.map
6188
+ exports.useBuildRun = useBuildRun;
6189
+ exports.useQuery = useQuery;
6190
+ //# sourceMappingURL=index-m42Be5Oj.js.map