@bounded-sh/client 0.0.48 → 0.0.51
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 +21 -0
- package/dist/auth/index.d.ts +8 -1
- package/dist/auth/providers/guest-auth-provider.d.ts +7 -0
- package/dist/auth/providers/guest-keystore.d.ts +2 -0
- package/dist/builds/apps.d.ts +32 -0
- package/dist/builds/client.d.ts +74 -0
- package/dist/builds/index.d.ts +20 -0
- package/dist/builds/types.d.ts +127 -0
- package/dist/builds/watch.d.ts +20 -0
- package/dist/{email-auth-provider-GRj8IOg2.mjs → email-auth-provider-Bh2fDYcb.mjs} +2 -2
- package/dist/{email-auth-provider-GRj8IOg2.mjs.map → email-auth-provider-Bh2fDYcb.mjs.map} +1 -1
- package/dist/{email-auth-provider-DyxZTpx6.js → email-auth-provider-Bm6vmoy3.js} +2 -2
- package/dist/{email-auth-provider-DyxZTpx6.js.map → email-auth-provider-Bm6vmoy3.js.map} +1 -1
- package/dist/{email-auth-provider-CTyjwhLb.mjs → email-auth-provider-CdbhqElf.mjs} +2 -2
- package/dist/{email-auth-provider-CTyjwhLb.mjs.map → email-auth-provider-CdbhqElf.mjs.map} +1 -1
- package/dist/{email-auth-provider-CmunfauO.js → email-auth-provider-CnHsY8U-.js} +2 -2
- package/dist/{email-auth-provider-CmunfauO.js.map → email-auth-provider-CnHsY8U-.js.map} +1 -1
- package/dist/global.d.ts +6 -4
- package/dist/{guest-auth-provider-D54uHbov.js → guest-auth-provider-CHqB_uN0.js} +98 -14
- package/dist/guest-auth-provider-CHqB_uN0.js.map +1 -0
- package/dist/{guest-auth-provider-Dk_km5tF.mjs → guest-auth-provider-Dgmr7e0Z.mjs} +98 -14
- package/dist/guest-auth-provider-Dgmr7e0Z.mjs.map +1 -0
- package/dist/{guest-auth-provider-C4BuTNIa.mjs → guest-auth-provider-Xir8zyfZ.mjs} +98 -14
- package/dist/guest-auth-provider-Xir8zyfZ.mjs.map +1 -0
- package/dist/{guest-auth-provider-B68XT2lU.js → guest-auth-provider-fjOMwfpW.js} +98 -14
- package/dist/guest-auth-provider-fjOMwfpW.js.map +1 -0
- package/dist/hooks/useBuildRun.d.ts +13 -0
- package/dist/{index.native-BZCc0gO-.js → index-BsrZb496.js} +918 -29
- package/dist/index-BsrZb496.js.map +1 -0
- package/dist/{index.native-CytJPNQV.mjs → index-Cy0IRs6U.mjs} +907 -31
- package/dist/index-Cy0IRs6U.mjs.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{index-C0pR5b7j.mjs → index.native-B29WKXlr.mjs} +725 -151
- package/dist/index.native-B29WKXlr.mjs.map +1 -0
- package/dist/{index-JBeYYsGm.js → index.native-BaEZwiWd.js} +732 -153
- package/dist/index.native-BaEZwiWd.js.map +1 -0
- package/dist/index.native.d.ts +5 -0
- package/dist/index.native.js +10 -1
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +1 -1
- package/dist/{injected-evm-wallet-provider-_eeYB1ww.js → injected-evm-wallet-provider-CEWIg-_U.js} +2 -2
- package/dist/{injected-evm-wallet-provider-_eeYB1ww.js.map → injected-evm-wallet-provider-CEWIg-_U.js.map} +1 -1
- package/dist/{injected-evm-wallet-provider-T-EF9C3W.js → injected-evm-wallet-provider-DUyX7Xj9.js} +2 -2
- package/dist/{injected-evm-wallet-provider-T-EF9C3W.js.map → injected-evm-wallet-provider-DUyX7Xj9.js.map} +1 -1
- package/dist/{injected-evm-wallet-provider-BOMLGGHM.mjs → injected-evm-wallet-provider-DWnpa6Yx.mjs} +2 -2
- package/dist/{injected-evm-wallet-provider-BOMLGGHM.mjs.map → injected-evm-wallet-provider-DWnpa6Yx.mjs.map} +1 -1
- package/dist/{injected-evm-wallet-provider-CxAiNN7R.mjs → injected-evm-wallet-provider-DkyIMRce.mjs} +2 -2
- package/dist/{injected-evm-wallet-provider-CxAiNN7R.mjs.map → injected-evm-wallet-provider-DkyIMRce.mjs.map} +1 -1
- package/dist/{injected-wallet-provider-BBZym7YQ.js → injected-wallet-provider-C65NiItg.js} +2 -2
- package/dist/{injected-wallet-provider-BBZym7YQ.js.map → injected-wallet-provider-C65NiItg.js.map} +1 -1
- package/dist/{injected-wallet-provider-B2T7JEvn.js → injected-wallet-provider-DpJvuK73.js} +2 -2
- package/dist/{injected-wallet-provider-B2T7JEvn.js.map → injected-wallet-provider-DpJvuK73.js.map} +1 -1
- package/dist/{injected-wallet-provider-B1uq3r4r.mjs → injected-wallet-provider-DqBpuASt.mjs} +2 -2
- package/dist/{injected-wallet-provider-B1uq3r4r.mjs.map → injected-wallet-provider-DqBpuASt.mjs.map} +1 -1
- package/dist/{injected-wallet-provider-DCwygA3j.mjs → injected-wallet-provider-DsesEVnZ.mjs} +2 -2
- package/dist/{injected-wallet-provider-DCwygA3j.mjs.map → injected-wallet-provider-DsesEVnZ.mjs.map} +1 -1
- package/package.json +2 -2
- package/dist/guest-auth-provider-B68XT2lU.js.map +0 -1
- package/dist/guest-auth-provider-C4BuTNIa.mjs.map +0 -1
- package/dist/guest-auth-provider-D54uHbov.js.map +0 -1
- package/dist/guest-auth-provider-Dk_km5tF.mjs.map +0 -1
- package/dist/index-C0pR5b7j.mjs.map +0 -1
- package/dist/index-JBeYYsGm.js.map +0 -1
- package/dist/index.native-BZCc0gO-.js.map +0 -1
- 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
|
-
|
|
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-
|
|
4469
|
+
currentAuthProvider = new (await Promise.resolve().then(function () { return require('./email-auth-provider-CnHsY8U-.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-
|
|
4488
|
+
const { InjectedWalletProvider } = await Promise.resolve().then(function () { return require('./injected-wallet-provider-C65NiItg.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-
|
|
4501
|
+
const { InjectedEvmWalletProvider } = await Promise.resolve().then(function () { return require('./injected-evm-wallet-provider-DUyX7Xj9.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-
|
|
4529
|
+
currentAuthProvider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-fjOMwfpW.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
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
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
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
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-fjOMwfpW.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
|
-
|
|
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);
|
|
@@ -4625,8 +4758,45 @@ async function login$1(options) {
|
|
|
4625
4758
|
function getCurrentAuthMethod() {
|
|
4626
4759
|
return currentAuthMethod;
|
|
4627
4760
|
}
|
|
4628
|
-
|
|
4629
|
-
|
|
4761
|
+
// The hosted issuer keeps its OWN browser session (the Better Auth cookie on
|
|
4762
|
+
// auth.bounded.sh) — clearing the app-local session alone leaves it alive, so
|
|
4763
|
+
// the next loginWithRedirect() silently re-signs the user in as the SAME
|
|
4764
|
+
// account: "sign out" that never lets you re-choose. The issuer ships
|
|
4765
|
+
// GET /logout for exactly this — it expires the session cookies and bounces
|
|
4766
|
+
// back — but it only redirects to https origins it trusts. Mirror that
|
|
4767
|
+
// allowlist here: on a trusted origin we end the issuer session with a
|
|
4768
|
+
// top-level bounce; anywhere else (custom domains, http dev) we keep the
|
|
4769
|
+
// local-only logout instead of stranding the user on the issuer origin.
|
|
4770
|
+
function issuerLogoutBounceUrl(issuerBase) {
|
|
4771
|
+
if (typeof window === 'undefined' || typeof document === 'undefined')
|
|
4772
|
+
return null; // RN/Node: no shared cookie jar to clear this way
|
|
4773
|
+
try {
|
|
4774
|
+
if (window.top !== window.self)
|
|
4775
|
+
return null; // framed: SameSite=Lax cookies don't ride iframe navigations
|
|
4776
|
+
}
|
|
4777
|
+
catch (_a) {
|
|
4778
|
+
return null;
|
|
4779
|
+
}
|
|
4780
|
+
try {
|
|
4781
|
+
const here = new URL(window.location.href);
|
|
4782
|
+
const host = here.hostname;
|
|
4783
|
+
const isLocalhost = host === 'localhost' || host === '127.0.0.1' || host.endsWith('.localhost');
|
|
4784
|
+
const trusted = here.protocol === 'https:' &&
|
|
4785
|
+
(host === 'bounded.sh' ||
|
|
4786
|
+
host.endsWith('.bounded.sh') ||
|
|
4787
|
+
host.endsWith('.bounded.page') ||
|
|
4788
|
+
host.endsWith('.oapps.fun') ||
|
|
4789
|
+
isLocalhost);
|
|
4790
|
+
if (!trusted)
|
|
4791
|
+
return null;
|
|
4792
|
+
const base = issuerBase.replace(/\/$/, '');
|
|
4793
|
+
return `${base}/logout?redirect_uri=${encodeURIComponent(here.href)}`;
|
|
4794
|
+
}
|
|
4795
|
+
catch (_b) {
|
|
4796
|
+
return null;
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
async function logout$1(options) {
|
|
4630
4800
|
// Re-initialize the provider if it was cleared by a prior logout — the exact mirror
|
|
4631
4801
|
// of login()'s self-heal above. A hosted popup/redirect login (loginWithPopup /
|
|
4632
4802
|
// completeLoginFromRedirect) establishes a session WITHOUT touching the provider
|
|
@@ -4649,13 +4819,28 @@ async function logout$1() {
|
|
|
4649
4819
|
// mistake a local-only logout for server revocation.
|
|
4650
4820
|
const sm = core.getActiveSessionManager();
|
|
4651
4821
|
const refreshToken = sm.getRefreshToken();
|
|
4822
|
+
const sessionIssuer = sm.getIssuer();
|
|
4652
4823
|
if (refreshToken)
|
|
4653
|
-
await core.revokeSession(refreshToken,
|
|
4824
|
+
await core.revokeSession(refreshToken, sessionIssuer !== null && sessionIssuer !== void 0 ? sessionIssuer : undefined);
|
|
4825
|
+
// Hosted sessions ('email' covers the whole hosted surface: email OTP +
|
|
4826
|
+
// social + the OIDC redirect/popup flows) are the ones with an issuer
|
|
4827
|
+
// cookie; wallet and guest sessions have nothing hosted to end.
|
|
4828
|
+
const wasHosted = (currentAuthMethod !== null && currentAuthMethod !== void 0 ? currentAuthMethod : getStoredAuthMethod()) === 'email';
|
|
4654
4829
|
await currentAuthProvider.logout();
|
|
4655
4830
|
setStoredAuthMethod(null);
|
|
4656
4831
|
currentAuthProvider = null;
|
|
4657
4832
|
currentAuthMethod = null;
|
|
4658
4833
|
currentAuthProviderConfigKey = null;
|
|
4834
|
+
if (wasHosted && !(options === null || options === void 0 ? void 0 : options.keepIssuerSession)) {
|
|
4835
|
+
const issuerBase = sessionIssuer
|
|
4836
|
+
|| (await core.getConfig()).humanAuthApiUrl
|
|
4837
|
+
|| 'https://auth.bounded.sh';
|
|
4838
|
+
const bounce = issuerLogoutBounceUrl(issuerBase);
|
|
4839
|
+
// Local state is already cleared, so even if the navigation is stopped
|
|
4840
|
+
// (tab close, extension) the app-side logout has fully happened.
|
|
4841
|
+
if (bounce)
|
|
4842
|
+
window.location.href = bounce;
|
|
4843
|
+
}
|
|
4659
4844
|
}
|
|
4660
4845
|
|
|
4661
4846
|
/**
|
|
@@ -4785,11 +4970,11 @@ async function login(options) {
|
|
|
4785
4970
|
setCurrentUser(loggedInUser);
|
|
4786
4971
|
return currentUser;
|
|
4787
4972
|
}
|
|
4788
|
-
async function logout() {
|
|
4973
|
+
async function logout(options) {
|
|
4789
4974
|
if (!authProviderInstance) {
|
|
4790
4975
|
throw new Error('SDK not initialized. Please call init() first.');
|
|
4791
4976
|
}
|
|
4792
|
-
await logout$1();
|
|
4977
|
+
await logout$1(options);
|
|
4793
4978
|
setCurrentUser(null);
|
|
4794
4979
|
}
|
|
4795
4980
|
var hasRunFirstTime = false;
|
|
@@ -4828,6 +5013,10 @@ function setCurrentUser(user) {
|
|
|
4828
5013
|
function getCurrentUser() {
|
|
4829
5014
|
return currentUser;
|
|
4830
5015
|
}
|
|
5016
|
+
/** @internal Snapshot/restore surface for transactional auth-provider switches. */
|
|
5017
|
+
function getAuthProviderInstance() {
|
|
5018
|
+
return authProviderInstance;
|
|
5019
|
+
}
|
|
4831
5020
|
function setAuthProviderInstance(provider) {
|
|
4832
5021
|
authProviderInstance = provider;
|
|
4833
5022
|
}
|
|
@@ -4904,6 +5093,438 @@ function useAuth() {
|
|
|
4904
5093
|
};
|
|
4905
5094
|
}
|
|
4906
5095
|
|
|
5096
|
+
// Wrapper for getIdToken - passes isServer=false for client-side usage
|
|
5097
|
+
async function getIdToken() {
|
|
5098
|
+
return core.getIdToken(false);
|
|
5099
|
+
}
|
|
5100
|
+
|
|
5101
|
+
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
5102
|
+
var t = {};
|
|
5103
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5104
|
+
t[p] = s[p];
|
|
5105
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
5106
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
5107
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
5108
|
+
t[p[i]] = s[p[i]];
|
|
5109
|
+
}
|
|
5110
|
+
return t;
|
|
5111
|
+
};
|
|
5112
|
+
/** A structured non-2xx response from the developer API. */
|
|
5113
|
+
class BuildsApiError extends Error {
|
|
5114
|
+
constructor(init) {
|
|
5115
|
+
super(init.message);
|
|
5116
|
+
this.name = 'BuildsApiError';
|
|
5117
|
+
this.code = init.code;
|
|
5118
|
+
this.retryable = init.retryable;
|
|
5119
|
+
this.status = init.status;
|
|
5120
|
+
this.details = init.details;
|
|
5121
|
+
this.retryAfterMs = init.retryAfterMs;
|
|
5122
|
+
}
|
|
5123
|
+
}
|
|
5124
|
+
const memoryIdempotencyKeys = new Map();
|
|
5125
|
+
const IDEMPOTENCY_STORAGE_PREFIX = 'bounded:build:idempotency:';
|
|
5126
|
+
function retryAfterMs(response) {
|
|
5127
|
+
var _a, _b;
|
|
5128
|
+
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');
|
|
5129
|
+
if (!value)
|
|
5130
|
+
return undefined;
|
|
5131
|
+
const seconds = Number(value);
|
|
5132
|
+
if (Number.isFinite(seconds) && seconds >= 0)
|
|
5133
|
+
return Math.ceil(seconds * 1000);
|
|
5134
|
+
const at = Date.parse(value);
|
|
5135
|
+
if (!Number.isFinite(at))
|
|
5136
|
+
return undefined;
|
|
5137
|
+
return Math.max(0, at - Date.now());
|
|
5138
|
+
}
|
|
5139
|
+
async function responseBody(response) {
|
|
5140
|
+
const text = await response.text();
|
|
5141
|
+
if (!text)
|
|
5142
|
+
return {};
|
|
5143
|
+
try {
|
|
5144
|
+
return JSON.parse(text);
|
|
5145
|
+
}
|
|
5146
|
+
catch (_a) {
|
|
5147
|
+
return { raw: text };
|
|
5148
|
+
}
|
|
5149
|
+
}
|
|
5150
|
+
function apiError(response, body) {
|
|
5151
|
+
const envelope = body;
|
|
5152
|
+
const nested = (envelope === null || envelope === void 0 ? void 0 : envelope.error) && typeof envelope.error === 'object'
|
|
5153
|
+
? envelope.error
|
|
5154
|
+
: undefined;
|
|
5155
|
+
const hasNestedDetails = !!nested && Object.prototype.hasOwnProperty.call(nested, 'details');
|
|
5156
|
+
const hasTopLevelDetails = !!body
|
|
5157
|
+
&& typeof body === 'object'
|
|
5158
|
+
&& Object.prototype.hasOwnProperty.call(body, 'details');
|
|
5159
|
+
const legacyCode = typeof (body === null || body === void 0 ? void 0 : body.error) === 'string' ? body.error : undefined;
|
|
5160
|
+
const code = typeof (nested === null || nested === void 0 ? void 0 : nested.code) === 'string'
|
|
5161
|
+
? nested.code
|
|
5162
|
+
: legacyCode !== null && legacyCode !== void 0 ? legacyCode : `http_${response.status}`;
|
|
5163
|
+
const message = typeof (nested === null || nested === void 0 ? void 0 : nested.message) === 'string'
|
|
5164
|
+
? nested.message
|
|
5165
|
+
: typeof (body === null || body === void 0 ? void 0 : body.message) === 'string'
|
|
5166
|
+
? body.message
|
|
5167
|
+
: `Developer API request failed with HTTP ${response.status}`;
|
|
5168
|
+
const retryable = typeof (nested === null || nested === void 0 ? void 0 : nested.retryable) === 'boolean'
|
|
5169
|
+
? nested.retryable
|
|
5170
|
+
: response.status === 429 || response.status >= 500;
|
|
5171
|
+
return new BuildsApiError(Object.assign(Object.assign({ code,
|
|
5172
|
+
message,
|
|
5173
|
+
retryable, status: response.status }, (hasNestedDetails
|
|
5174
|
+
? { details: nested === null || nested === void 0 ? void 0 : nested.details }
|
|
5175
|
+
: hasTopLevelDetails
|
|
5176
|
+
? { details: body.details }
|
|
5177
|
+
: {})), (response.status === 429 ? { retryAfterMs: retryAfterMs(response) } : {})));
|
|
5178
|
+
}
|
|
5179
|
+
/** @internal Shared authenticated developer-api transport for builds and apps. */
|
|
5180
|
+
async function requestDevApi(path, request = {}) {
|
|
5181
|
+
var _a, _b;
|
|
5182
|
+
const config = await core.getConfig();
|
|
5183
|
+
const base = (_a = config.devApiUrl) === null || _a === void 0 ? void 0 : _a.replace(/\/$/, '');
|
|
5184
|
+
if (!base) {
|
|
5185
|
+
throw new Error('Bounded developer API is not configured. Pass devApiUrl or a Bounded network to init().');
|
|
5186
|
+
}
|
|
5187
|
+
// Reuse the exact accessor exposed publicly as getIdToken().
|
|
5188
|
+
const token = await getIdToken();
|
|
5189
|
+
if (!token) {
|
|
5190
|
+
throw new BuildsApiError({
|
|
5191
|
+
code: 'auth_required',
|
|
5192
|
+
message: 'Sign in before calling the Bounded developer API.',
|
|
5193
|
+
retryable: false,
|
|
5194
|
+
status: 401,
|
|
5195
|
+
});
|
|
5196
|
+
}
|
|
5197
|
+
const hasBody = request.body !== undefined;
|
|
5198
|
+
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) } : {})));
|
|
5199
|
+
const body = await responseBody(response);
|
|
5200
|
+
if (!response.ok)
|
|
5201
|
+
throw apiError(response, body);
|
|
5202
|
+
return body;
|
|
5203
|
+
}
|
|
5204
|
+
function intentStorageKey(intentKey) {
|
|
5205
|
+
return `${IDEMPOTENCY_STORAGE_PREFIX}${intentKey}`;
|
|
5206
|
+
}
|
|
5207
|
+
function isValidIdempotencyKey(value) {
|
|
5208
|
+
return typeof value === 'string' && value.length > 0 && value.length <= 256;
|
|
5209
|
+
}
|
|
5210
|
+
function readPersistedIdempotencyKey(intentKey) {
|
|
5211
|
+
var _a;
|
|
5212
|
+
const storageKey = intentStorageKey(intentKey);
|
|
5213
|
+
try {
|
|
5214
|
+
const stored = (_a = globalThis.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem(storageKey);
|
|
5215
|
+
if (isValidIdempotencyKey(stored))
|
|
5216
|
+
return stored;
|
|
5217
|
+
}
|
|
5218
|
+
catch (_b) {
|
|
5219
|
+
// Storage can be disabled by browser privacy policy; use module memory.
|
|
5220
|
+
}
|
|
5221
|
+
const inMemory = memoryIdempotencyKeys.get(storageKey);
|
|
5222
|
+
return isValidIdempotencyKey(inMemory) ? inMemory : undefined;
|
|
5223
|
+
}
|
|
5224
|
+
function persistIdempotencyKey(intentKey, idempotencyKey) {
|
|
5225
|
+
var _a;
|
|
5226
|
+
const storageKey = intentStorageKey(intentKey);
|
|
5227
|
+
memoryIdempotencyKeys.set(storageKey, idempotencyKey);
|
|
5228
|
+
try {
|
|
5229
|
+
(_a = globalThis.sessionStorage) === null || _a === void 0 ? void 0 : _a.setItem(storageKey, idempotencyKey);
|
|
5230
|
+
}
|
|
5231
|
+
catch (_b) {
|
|
5232
|
+
// The in-memory write above is the React Native / disabled-storage fallback.
|
|
5233
|
+
}
|
|
5234
|
+
}
|
|
5235
|
+
function randomHex(bytes) {
|
|
5236
|
+
const cryptoObject = globalThis.crypto;
|
|
5237
|
+
if (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.getRandomValues) {
|
|
5238
|
+
const values = new Uint8Array(bytes);
|
|
5239
|
+
cryptoObject.getRandomValues(values);
|
|
5240
|
+
return Array.from(values, (value) => value.toString(16).padStart(2, '0')).join('');
|
|
5241
|
+
}
|
|
5242
|
+
let value = '';
|
|
5243
|
+
for (let index = 0; index < bytes; index += 1) {
|
|
5244
|
+
value += Math.floor(Math.random() * 256).toString(16).padStart(2, '0');
|
|
5245
|
+
}
|
|
5246
|
+
return value;
|
|
5247
|
+
}
|
|
5248
|
+
function mintIdempotencyKey() {
|
|
5249
|
+
const cryptoObject = globalThis.crypto;
|
|
5250
|
+
if (typeof (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.randomUUID) === 'function') {
|
|
5251
|
+
return `build_${cryptoObject.randomUUID()}`;
|
|
5252
|
+
}
|
|
5253
|
+
return `build_${Date.now().toString(36)}_${randomHex(16)}`;
|
|
5254
|
+
}
|
|
5255
|
+
function actionIdempotencyKey(options, action) {
|
|
5256
|
+
const supplied = options.idempotencyKey;
|
|
5257
|
+
if (supplied !== undefined) {
|
|
5258
|
+
if (!isValidIdempotencyKey(supplied)) {
|
|
5259
|
+
throw new TypeError('idempotencyKey must be between 1 and 256 characters.');
|
|
5260
|
+
}
|
|
5261
|
+
if (options.intentKey)
|
|
5262
|
+
persistIdempotencyKey(options.intentKey, supplied);
|
|
5263
|
+
return supplied;
|
|
5264
|
+
}
|
|
5265
|
+
if (!options.intentKey) {
|
|
5266
|
+
throw new TypeError(`intentKey is required when ${action} auto-mints an idempotency key.`);
|
|
5267
|
+
}
|
|
5268
|
+
const existing = readPersistedIdempotencyKey(options.intentKey);
|
|
5269
|
+
if (existing)
|
|
5270
|
+
return existing;
|
|
5271
|
+
const minted = mintIdempotencyKey();
|
|
5272
|
+
// This is deliberately synchronous and happens before requestDevApi can fetch.
|
|
5273
|
+
persistIdempotencyKey(options.intentKey, minted);
|
|
5274
|
+
return minted;
|
|
5275
|
+
}
|
|
5276
|
+
function appPath(appId) {
|
|
5277
|
+
return `/app/${encodeURIComponent(appId)}/builds`;
|
|
5278
|
+
}
|
|
5279
|
+
async function submit(appId, options) {
|
|
5280
|
+
const idempotencyKey = actionIdempotencyKey(options, 'submit()');
|
|
5281
|
+
const { intentKey: _intentKey, idempotencyKey: _suppliedKey } = options, submission = __rest(options, ["intentKey", "idempotencyKey"]);
|
|
5282
|
+
return requestDevApi(appPath(appId), {
|
|
5283
|
+
method: 'POST',
|
|
5284
|
+
body: Object.assign(Object.assign({}, submission), { idempotencyKey }),
|
|
5285
|
+
});
|
|
5286
|
+
}
|
|
5287
|
+
async function get(appId, runId) {
|
|
5288
|
+
return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}`);
|
|
5289
|
+
}
|
|
5290
|
+
async function events(appId, runId, after = 0) {
|
|
5291
|
+
const cursor = Number.isFinite(after) ? Math.max(0, Math.floor(after)) : 0;
|
|
5292
|
+
return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}/events?after=${cursor}`);
|
|
5293
|
+
}
|
|
5294
|
+
async function cancel(appId, runId) {
|
|
5295
|
+
return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}/cancel`, { method: 'POST' });
|
|
5296
|
+
}
|
|
5297
|
+
async function decideGate(appId, runId, gateId, options) {
|
|
5298
|
+
const idempotencyKey = actionIdempotencyKey(options, 'decideGate()');
|
|
5299
|
+
const { intentKey: _intentKey, idempotencyKey: _suppliedKey } = options, decision = __rest(options, ["intentKey", "idempotencyKey"]);
|
|
5300
|
+
return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}/gates/${encodeURIComponent(gateId)}/decision`, { method: 'POST', body: Object.assign(Object.assign({}, decision), { idempotencyKey }) });
|
|
5301
|
+
}
|
|
5302
|
+
async function topup(appId, runId, options) {
|
|
5303
|
+
return requestDevApi(`${appPath(appId)}/${encodeURIComponent(runId)}/topup`, { method: 'POST', body: options });
|
|
5304
|
+
}
|
|
5305
|
+
async function list$1(appId, limit = 20) {
|
|
5306
|
+
const requestedLimit = Number.isFinite(limit) ? Math.max(1, Math.floor(limit)) : 20;
|
|
5307
|
+
return requestDevApi(`${appPath(appId)}?limit=${requestedLimit}`);
|
|
5308
|
+
}
|
|
5309
|
+
|
|
5310
|
+
// Source of truth for these strings:
|
|
5311
|
+
// packages/cdk/cloudflare/bounded-build/src/types.ts. Keep them string-pinned;
|
|
5312
|
+
// wire:1 remains additive and callers must tolerate unknown response strings.
|
|
5313
|
+
const NON_TERMINAL_STATES = [
|
|
5314
|
+
'queued',
|
|
5315
|
+
'admitted',
|
|
5316
|
+
'executing',
|
|
5317
|
+
'preview_ready',
|
|
5318
|
+
'parked',
|
|
5319
|
+
'resuming',
|
|
5320
|
+
'promoting',
|
|
5321
|
+
'quarantined',
|
|
5322
|
+
];
|
|
5323
|
+
const TERMINAL_STATES = [
|
|
5324
|
+
'promoted',
|
|
5325
|
+
'failed',
|
|
5326
|
+
'canceled',
|
|
5327
|
+
'rejected',
|
|
5328
|
+
'expired',
|
|
5329
|
+
'rebase_required',
|
|
5330
|
+
'reported',
|
|
5331
|
+
];
|
|
5332
|
+
const RUN_STATES = [
|
|
5333
|
+
...NON_TERMINAL_STATES,
|
|
5334
|
+
...TERMINAL_STATES,
|
|
5335
|
+
];
|
|
5336
|
+
const PARK_REASONS = ['gate', 'funding'];
|
|
5337
|
+
const FAILURE_REASONS = [
|
|
5338
|
+
'admission_rejected',
|
|
5339
|
+
'dispatch_timeout',
|
|
5340
|
+
'auth_revoked',
|
|
5341
|
+
'owner_changed',
|
|
5342
|
+
'policy_changed',
|
|
5343
|
+
'quarantine_forced',
|
|
5344
|
+
'bind_failed',
|
|
5345
|
+
'internal_error',
|
|
5346
|
+
];
|
|
5347
|
+
|
|
5348
|
+
const NORMAL_POLL_MS = 2000;
|
|
5349
|
+
const PARKED_POLL_MS = 5000;
|
|
5350
|
+
const LONG_RUNNING_POLL_MS = 10000;
|
|
5351
|
+
const TWO_MINUTES_MS = 2 * 60000;
|
|
5352
|
+
const TEN_MINUTES_MS = 10 * 60000;
|
|
5353
|
+
const terminalStates = new Set(TERMINAL_STATES);
|
|
5354
|
+
function pollCadence(state, elapsedMs) {
|
|
5355
|
+
if (elapsedMs >= TEN_MINUTES_MS)
|
|
5356
|
+
return LONG_RUNNING_POLL_MS;
|
|
5357
|
+
if ((state === null || state === void 0 ? void 0 : state.startsWith('parked')) || elapsedMs >= TWO_MINUTES_MS)
|
|
5358
|
+
return PARKED_POLL_MS;
|
|
5359
|
+
return NORMAL_POLL_MS;
|
|
5360
|
+
}
|
|
5361
|
+
function retryCadence(error, state, elapsedMs) {
|
|
5362
|
+
const cadence = pollCadence(state, elapsedMs);
|
|
5363
|
+
if (error instanceof BuildsApiError && error.status === 429 && error.retryAfterMs !== undefined) {
|
|
5364
|
+
return Math.max(cadence, error.retryAfterMs);
|
|
5365
|
+
}
|
|
5366
|
+
return cadence;
|
|
5367
|
+
}
|
|
5368
|
+
function hasRetryAfter(error) {
|
|
5369
|
+
return error instanceof BuildsApiError
|
|
5370
|
+
&& error.status === 429
|
|
5371
|
+
&& error.retryAfterMs !== undefined;
|
|
5372
|
+
}
|
|
5373
|
+
// A permanent API refusal (expired session, revoked access, unknown run) will
|
|
5374
|
+
// never heal by re-polling; the loop must stop and surface it instead of
|
|
5375
|
+
// retrying forever. 429 stays retryable regardless of the server envelope.
|
|
5376
|
+
function isPermanentError(error) {
|
|
5377
|
+
return error instanceof BuildsApiError
|
|
5378
|
+
&& error.status !== 429
|
|
5379
|
+
&& error.retryable === false;
|
|
5380
|
+
}
|
|
5381
|
+
function newEvents(rows, lastSeq, seen) {
|
|
5382
|
+
const cursorBeforePoll = lastSeq;
|
|
5383
|
+
const fresh = [];
|
|
5384
|
+
let nextCursor = lastSeq;
|
|
5385
|
+
for (const event of rows) {
|
|
5386
|
+
if (!Number.isFinite(event === null || event === void 0 ? void 0 : event.seq))
|
|
5387
|
+
continue;
|
|
5388
|
+
nextCursor = Math.max(nextCursor, event.seq);
|
|
5389
|
+
if (event.seq <= cursorBeforePoll || seen.has(event.seq))
|
|
5390
|
+
continue;
|
|
5391
|
+
seen.add(event.seq);
|
|
5392
|
+
fresh.push(event);
|
|
5393
|
+
}
|
|
5394
|
+
return { events: fresh, lastSeq: nextCursor };
|
|
5395
|
+
}
|
|
5396
|
+
/**
|
|
5397
|
+
* Poll a build view and its event cursor until stopped or the run reaches a
|
|
5398
|
+
* known terminal state. Unknown state strings remain untouched and nonterminal.
|
|
5399
|
+
*/
|
|
5400
|
+
function watch(appId, runId, onUpdate, options = {}) {
|
|
5401
|
+
const startedAt = Date.now();
|
|
5402
|
+
const seenSeqs = new Set();
|
|
5403
|
+
let lastSeq = Number.isFinite(options.after)
|
|
5404
|
+
? Math.max(0, Math.floor(options.after))
|
|
5405
|
+
: 0;
|
|
5406
|
+
let timer;
|
|
5407
|
+
let active = true;
|
|
5408
|
+
let lastState;
|
|
5409
|
+
const stop = () => {
|
|
5410
|
+
active = false;
|
|
5411
|
+
if (timer !== undefined) {
|
|
5412
|
+
clearTimeout(timer);
|
|
5413
|
+
timer = undefined;
|
|
5414
|
+
}
|
|
5415
|
+
};
|
|
5416
|
+
const schedule = (delayMs) => {
|
|
5417
|
+
if (!active)
|
|
5418
|
+
return;
|
|
5419
|
+
timer = setTimeout(() => {
|
|
5420
|
+
timer = undefined;
|
|
5421
|
+
void poll();
|
|
5422
|
+
}, delayMs);
|
|
5423
|
+
};
|
|
5424
|
+
const reportError = (error) => {
|
|
5425
|
+
var _a;
|
|
5426
|
+
try {
|
|
5427
|
+
(_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
5428
|
+
}
|
|
5429
|
+
catch (_b) {
|
|
5430
|
+
// A consumer error callback must not break the transport loop.
|
|
5431
|
+
}
|
|
5432
|
+
};
|
|
5433
|
+
const publish = (run, events) => {
|
|
5434
|
+
try {
|
|
5435
|
+
onUpdate({ run, events });
|
|
5436
|
+
}
|
|
5437
|
+
catch (_a) {
|
|
5438
|
+
// Polling is transport state; consumer render errors must not strand it.
|
|
5439
|
+
}
|
|
5440
|
+
};
|
|
5441
|
+
const poll = async () => {
|
|
5442
|
+
if (!active)
|
|
5443
|
+
return;
|
|
5444
|
+
let run;
|
|
5445
|
+
try {
|
|
5446
|
+
const view = await get(appId, runId);
|
|
5447
|
+
if (!active)
|
|
5448
|
+
return;
|
|
5449
|
+
run = view.run;
|
|
5450
|
+
lastState = run.state;
|
|
5451
|
+
}
|
|
5452
|
+
catch (error) {
|
|
5453
|
+
if (!active)
|
|
5454
|
+
return;
|
|
5455
|
+
reportError(error);
|
|
5456
|
+
if (isPermanentError(error)) {
|
|
5457
|
+
stop();
|
|
5458
|
+
return;
|
|
5459
|
+
}
|
|
5460
|
+
schedule(retryCadence(error, lastState, Date.now() - startedAt));
|
|
5461
|
+
return;
|
|
5462
|
+
}
|
|
5463
|
+
try {
|
|
5464
|
+
const response = await events(appId, runId, lastSeq);
|
|
5465
|
+
if (!active)
|
|
5466
|
+
return;
|
|
5467
|
+
const deduped = newEvents(Array.isArray(response.events) ? response.events : [], lastSeq, seenSeqs);
|
|
5468
|
+
lastSeq = deduped.lastSeq;
|
|
5469
|
+
publish(run, deduped.events);
|
|
5470
|
+
}
|
|
5471
|
+
catch (error) {
|
|
5472
|
+
if (!active)
|
|
5473
|
+
return;
|
|
5474
|
+
// The view still advances UI state even when event replay is rate-limited.
|
|
5475
|
+
publish(run, []);
|
|
5476
|
+
reportError(error);
|
|
5477
|
+
if (terminalStates.has(run.state)) {
|
|
5478
|
+
// The run itself is done, but a rate-limited final event replay still
|
|
5479
|
+
// owes the caller its unseen seq rows. Honor Retry-After, retry the
|
|
5480
|
+
// piggyback once the limiter permits it, then stop after a successful
|
|
5481
|
+
// replay. Other terminal replay failures stop normally.
|
|
5482
|
+
if (hasRetryAfter(error)) {
|
|
5483
|
+
schedule(retryCadence(error, run.state, Date.now() - startedAt));
|
|
5484
|
+
return;
|
|
5485
|
+
}
|
|
5486
|
+
stop();
|
|
5487
|
+
return;
|
|
5488
|
+
}
|
|
5489
|
+
if (isPermanentError(error)) {
|
|
5490
|
+
stop();
|
|
5491
|
+
return;
|
|
5492
|
+
}
|
|
5493
|
+
schedule(retryCadence(error, run.state, Date.now() - startedAt));
|
|
5494
|
+
return;
|
|
5495
|
+
}
|
|
5496
|
+
if (!active)
|
|
5497
|
+
return;
|
|
5498
|
+
if (terminalStates.has(run.state)) {
|
|
5499
|
+
// Drain the remaining event pages before stopping: a resumed terminal
|
|
5500
|
+
// watch may owe the caller more rows than one page returns. Each page
|
|
5501
|
+
// advances the cursor, so the loop terminates; the cap is a backstop.
|
|
5502
|
+
for (let page = 0; page < 50 && active; page += 1) {
|
|
5503
|
+
let drained;
|
|
5504
|
+
try {
|
|
5505
|
+
const response = await events(appId, runId, lastSeq);
|
|
5506
|
+
if (!active)
|
|
5507
|
+
return;
|
|
5508
|
+
drained = newEvents(Array.isArray(response.events) ? response.events : [], lastSeq, seenSeqs);
|
|
5509
|
+
}
|
|
5510
|
+
catch (error) {
|
|
5511
|
+
reportError(error);
|
|
5512
|
+
break;
|
|
5513
|
+
}
|
|
5514
|
+
if (drained.events.length === 0)
|
|
5515
|
+
break;
|
|
5516
|
+
lastSeq = drained.lastSeq;
|
|
5517
|
+
publish(run, drained.events);
|
|
5518
|
+
}
|
|
5519
|
+
stop();
|
|
5520
|
+
return;
|
|
5521
|
+
}
|
|
5522
|
+
schedule(pollCadence(run.state, Date.now() - startedAt));
|
|
5523
|
+
};
|
|
5524
|
+
void poll();
|
|
5525
|
+
return { stop };
|
|
5526
|
+
}
|
|
5527
|
+
|
|
4907
5528
|
var _a;
|
|
4908
5529
|
// SSR guard (mirrors useAuth): no hooks/subscriptions during Node server render.
|
|
4909
5530
|
// React Native has no `window` but DOES support hooks, so detect Node SSR
|
|
@@ -4911,65 +5532,108 @@ var _a;
|
|
|
4911
5532
|
const isSSR = typeof window === 'undefined'
|
|
4912
5533
|
&& typeof process !== 'undefined'
|
|
4913
5534
|
&& !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
4914
|
-
function
|
|
5535
|
+
function useBuildRun(appId, runId, options) {
|
|
4915
5536
|
if (isSSR) {
|
|
4916
|
-
return {
|
|
5537
|
+
return { run: null, events: [], loading: true, error: null };
|
|
4917
5538
|
}
|
|
4918
|
-
const [
|
|
5539
|
+
const [run, setRun] = React__namespace.useState(null);
|
|
5540
|
+
const [events, setEvents] = React__namespace.useState([]);
|
|
4919
5541
|
const [loading, setLoading] = React__namespace.useState(true);
|
|
4920
5542
|
const [error, setError] = React__namespace.useState(null);
|
|
4921
|
-
// Re-subscribe only when the query actually changes (not on every render).
|
|
4922
5543
|
const optionsKey = options ? JSON.stringify(options) : '';
|
|
4923
5544
|
React__namespace.useEffect(() => {
|
|
4924
|
-
|
|
4925
|
-
|
|
5545
|
+
setRun(null);
|
|
5546
|
+
setEvents([]);
|
|
5547
|
+
setError(null);
|
|
5548
|
+
if (!appId || !runId) {
|
|
4926
5549
|
setLoading(false);
|
|
4927
|
-
setError(null);
|
|
4928
5550
|
return;
|
|
4929
5551
|
}
|
|
4930
5552
|
let active = true;
|
|
4931
|
-
let unsubscribe;
|
|
4932
5553
|
setLoading(true);
|
|
4933
|
-
|
|
4934
|
-
core.subscribe(path, Object.assign(Object.assign({}, options), { onData: (d) => {
|
|
4935
|
-
if (!active)
|
|
4936
|
-
return;
|
|
4937
|
-
// A reconnect can legitimately surface a transport error before the
|
|
4938
|
-
// socket re-authenticates and sends a new authorized snapshot. That
|
|
4939
|
-
// fresh snapshot is the recovery boundary: keep the error visible
|
|
4940
|
-
// until data arrives, then clear it so React does not remain stuck on
|
|
4941
|
-
// a failure page after realtime has recovered.
|
|
4942
|
-
setError(null);
|
|
4943
|
-
setData(d);
|
|
4944
|
-
setLoading(false);
|
|
4945
|
-
}, onError: (e) => {
|
|
4946
|
-
if (!active)
|
|
4947
|
-
return;
|
|
4948
|
-
setError(e instanceof Error ? e : new Error(String(e)));
|
|
4949
|
-
setLoading(false);
|
|
4950
|
-
} }))
|
|
4951
|
-
.then((unsub) => {
|
|
4952
|
-
if (active)
|
|
4953
|
-
unsubscribe = unsub;
|
|
4954
|
-
else
|
|
4955
|
-
void unsub(); // unmounted before subscribe resolved
|
|
4956
|
-
})
|
|
4957
|
-
.catch((e) => {
|
|
5554
|
+
const handle = watch(appId, runId, ({ run: nextRun, events: nextEvents }) => {
|
|
4958
5555
|
if (!active)
|
|
4959
5556
|
return;
|
|
4960
|
-
|
|
5557
|
+
setRun(nextRun);
|
|
5558
|
+
if (nextEvents.length > 0) {
|
|
5559
|
+
setEvents((current) => {
|
|
5560
|
+
const seen = new Set(current.map((event) => event.seq));
|
|
5561
|
+
return [...current, ...nextEvents.filter((event) => !seen.has(event.seq))];
|
|
5562
|
+
});
|
|
5563
|
+
}
|
|
5564
|
+
setError(null);
|
|
4961
5565
|
setLoading(false);
|
|
4962
|
-
})
|
|
5566
|
+
}, Object.assign(Object.assign({}, options), { onError: (value) => {
|
|
5567
|
+
if (!active)
|
|
5568
|
+
return;
|
|
5569
|
+
setError(value instanceof Error ? value : new Error(String(value)));
|
|
5570
|
+
setLoading(false);
|
|
5571
|
+
} }));
|
|
4963
5572
|
return () => {
|
|
4964
5573
|
active = false;
|
|
4965
|
-
|
|
5574
|
+
handle.stop();
|
|
4966
5575
|
};
|
|
4967
|
-
// optionsKey captures the option object's contents;
|
|
5576
|
+
// optionsKey captures the option object's contents; ids are the other inputs.
|
|
4968
5577
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4969
|
-
}, [
|
|
4970
|
-
return {
|
|
5578
|
+
}, [appId, runId, optionsKey]);
|
|
5579
|
+
return { run, events, loading, error };
|
|
4971
5580
|
}
|
|
4972
5581
|
|
|
5582
|
+
/**
|
|
5583
|
+
* Platform first-party surfaces only (bounded.sh, oapps.fun, localhost) —
|
|
5584
|
+
* dev-api CORS blocks calls from generated-app origins. Server-side callers unaffected.
|
|
5585
|
+
*/
|
|
5586
|
+
const builds = {
|
|
5587
|
+
submit,
|
|
5588
|
+
get,
|
|
5589
|
+
events,
|
|
5590
|
+
cancel,
|
|
5591
|
+
decideGate,
|
|
5592
|
+
topup,
|
|
5593
|
+
list: list$1,
|
|
5594
|
+
watch,
|
|
5595
|
+
};
|
|
5596
|
+
|
|
5597
|
+
async function create(options = {}) {
|
|
5598
|
+
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 } : {}));
|
|
5599
|
+
const app = await requestDevApi('/apps/new', {
|
|
5600
|
+
method: 'POST',
|
|
5601
|
+
body,
|
|
5602
|
+
});
|
|
5603
|
+
return Object.assign(Object.assign({ appId: app.appId }, (typeof app.slug === 'string' && app.slug ? { slug: app.slug } : {})), { url: app.url,
|
|
5604
|
+
// Fail closed against an older server response that omitted this field.
|
|
5605
|
+
policySeeded: app.policySeeded === true });
|
|
5606
|
+
}
|
|
5607
|
+
async function list() {
|
|
5608
|
+
// This legacy-compatible action shape is also used by oapps.fun listMyApps.
|
|
5609
|
+
const response = await requestDevApi('/', {
|
|
5610
|
+
method: 'POST',
|
|
5611
|
+
body: { action: 'listApps' },
|
|
5612
|
+
});
|
|
5613
|
+
const rows = Array.isArray(response.apps) ? response.apps : [];
|
|
5614
|
+
return rows
|
|
5615
|
+
.map((value) => {
|
|
5616
|
+
var _a, _b, _c, _d;
|
|
5617
|
+
const row = value && typeof value === 'object'
|
|
5618
|
+
? value
|
|
5619
|
+
: {};
|
|
5620
|
+
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 : '');
|
|
5621
|
+
if (!/^[a-f0-9]{24}$/i.test(appId))
|
|
5622
|
+
return null;
|
|
5623
|
+
const name = String((_d = row.name) !== null && _d !== void 0 ? _d : '').trim() || '(unnamed app)';
|
|
5624
|
+
const slug = typeof row.slug === 'string' && row.slug ? row.slug : undefined;
|
|
5625
|
+
const url = typeof row.url === 'string' && row.url.trim() ? row.url.trim() : undefined;
|
|
5626
|
+
return Object.assign(Object.assign({ appId,
|
|
5627
|
+
name }, (slug ? { slug } : {})), (url ? { url } : {}));
|
|
5628
|
+
})
|
|
5629
|
+
.filter((app) => app !== null);
|
|
5630
|
+
}
|
|
5631
|
+
/**
|
|
5632
|
+
* Platform first-party surfaces only (bounded.sh, oapps.fun, localhost) —
|
|
5633
|
+
* dev-api CORS blocks calls from generated-app origins. Server-side callers unaffected.
|
|
5634
|
+
*/
|
|
5635
|
+
const apps = { create, list };
|
|
5636
|
+
|
|
4973
5637
|
async function deserializeTransaction(tx) {
|
|
4974
5638
|
// Literal specifier so bundlers can code-split the lazy chunk.
|
|
4975
5639
|
const { Transaction, VersionedTransaction } = await import('@solana/web3.js');
|
|
@@ -4982,11 +5646,6 @@ async function deserializeTransaction(tx) {
|
|
|
4982
5646
|
}
|
|
4983
5647
|
}
|
|
4984
5648
|
|
|
4985
|
-
// Wrapper for getIdToken - passes isServer=false for client-side usage
|
|
4986
|
-
async function getIdToken() {
|
|
4987
|
-
return core.getIdToken(false);
|
|
4988
|
-
}
|
|
4989
|
-
|
|
4990
5649
|
/**
|
|
4991
5650
|
* Extracts a human-readable error message from Solana transaction logs.
|
|
4992
5651
|
*/
|
|
@@ -5382,102 +6041,23 @@ class PrivyExpoProvider {
|
|
|
5382
6041
|
}
|
|
5383
6042
|
}
|
|
5384
6043
|
|
|
5385
|
-
|
|
5386
|
-
* Default provider discovery: Phantom-first, then any Wallet-Standard
|
|
5387
|
-
* `window.solana`. Kept tiny + synchronous (no heavy imports) so it works inside
|
|
5388
|
-
* a user gesture and can be eagerly exported from the SDK entry.
|
|
5389
|
-
*/
|
|
5390
|
-
function defaultInjectedProvider() {
|
|
5391
|
-
var _a;
|
|
5392
|
-
if (typeof window === 'undefined')
|
|
5393
|
-
return null;
|
|
5394
|
-
const w = window;
|
|
5395
|
-
const phantom = (_a = w === null || w === void 0 ? void 0 : w.phantom) === null || _a === void 0 ? void 0 : _a.solana;
|
|
5396
|
-
if (phantom && typeof phantom.signMessage === 'function')
|
|
5397
|
-
return phantom;
|
|
5398
|
-
const generic = w === null || w === void 0 ? void 0 : w.solana;
|
|
5399
|
-
if (generic && typeof generic.signMessage === 'function')
|
|
5400
|
-
return generic;
|
|
5401
|
-
return null;
|
|
5402
|
-
}
|
|
5403
|
-
|
|
5404
|
-
// injected-evm-wallet-types.ts — tiny, dependency-free surface for the EVM
|
|
5405
|
-
// WALLET LOGIN path (BYO wallet via SIWE). The EVM twin of
|
|
5406
|
-
// injected-wallet-types.ts: kept separate from injected-evm-wallet-provider.ts
|
|
5407
|
-
// so the SDK entry can eagerly export the type surface + the provider-discovery
|
|
5408
|
-
// helper WITHOUT dragging the provider class into the default bundle. The
|
|
5409
|
-
// provider is lazy-loaded by getAuthProvider() when an app opts into
|
|
5410
|
-
// authMethod:'evm-wallet'.
|
|
5411
|
-
//
|
|
5412
|
-
// It rides the standard EIP-1193 injected provider a browser wallet exposes
|
|
5413
|
-
// (MetaMask / Rabby / Coinbase Wallet / any window.ethereum), discovered via
|
|
5414
|
-
// EIP-6963 (multi-wallet, collision-free) with a window.ethereum fallback. It
|
|
5415
|
-
// needs NO viem/ethers and NO React — EIP-1193 request() + hex strings suffice.
|
|
5416
|
-
// EIP-6963 is announcement-based: wallets add an `eip6963:requestProvider`
|
|
5417
|
-
// listener and synchronously dispatch `eip6963:announceProvider` in response. We
|
|
5418
|
-
// keep a persistent collector so announcements (including late ones) are
|
|
5419
|
-
// captured, and re-request on demand.
|
|
5420
|
-
const announcedProviders = [];
|
|
5421
|
-
let announceListenerAttached = false;
|
|
5422
|
-
function attachAnnounceListener() {
|
|
5423
|
-
if (announceListenerAttached || typeof window === 'undefined')
|
|
5424
|
-
return;
|
|
5425
|
-
announceListenerAttached = true;
|
|
5426
|
-
window.addEventListener('eip6963:announceProvider', (event) => {
|
|
5427
|
-
const detail = event === null || event === void 0 ? void 0 : event.detail;
|
|
5428
|
-
if (detail &&
|
|
5429
|
-
detail.provider &&
|
|
5430
|
-
typeof detail.provider.request === 'function' &&
|
|
5431
|
-
!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); })) {
|
|
5432
|
-
announcedProviders.push(detail);
|
|
5433
|
-
}
|
|
5434
|
-
});
|
|
5435
|
-
}
|
|
5436
|
-
/**
|
|
5437
|
-
* Request + collect EIP-6963 providers. Dispatches `eip6963:requestProvider`
|
|
5438
|
-
* (synchronous — already-loaded wallets announce in the same tick) and returns
|
|
5439
|
-
* every wallet announced so far. Kept synchronous so it works inside a user
|
|
5440
|
-
* gesture and can be eagerly exported from the SDK entry.
|
|
5441
|
-
*/
|
|
5442
|
-
function requestEip6963Providers() {
|
|
5443
|
-
if (typeof window === 'undefined')
|
|
5444
|
-
return [];
|
|
5445
|
-
attachAnnounceListener();
|
|
5446
|
-
try {
|
|
5447
|
-
window.dispatchEvent(new Event('eip6963:requestProvider'));
|
|
5448
|
-
}
|
|
5449
|
-
catch (_a) {
|
|
5450
|
-
/* older browsers without Event constructor — fall through to window.ethereum */
|
|
5451
|
-
}
|
|
5452
|
-
return announcedProviders.slice();
|
|
5453
|
-
}
|
|
5454
|
-
/**
|
|
5455
|
-
* Default EVM provider discovery: EIP-6963 first (multi-wallet, collision-free),
|
|
5456
|
-
* then legacy `window.ethereum`. Returns null when no injected wallet is present.
|
|
5457
|
-
*/
|
|
5458
|
-
function defaultInjectedEvmProvider() {
|
|
5459
|
-
if (typeof window === 'undefined')
|
|
5460
|
-
return null;
|
|
5461
|
-
const details = requestEip6963Providers();
|
|
5462
|
-
if (details.length > 0)
|
|
5463
|
-
return details[0].provider;
|
|
5464
|
-
const eth = window.ethereum;
|
|
5465
|
-
if (eth && typeof eth.request === 'function')
|
|
5466
|
-
return eth;
|
|
5467
|
-
return null;
|
|
5468
|
-
}
|
|
5469
|
-
|
|
6044
|
+
exports.BuildsApiError = BuildsApiError;
|
|
5470
6045
|
exports.EMBEDDED_WALLET_UNSUPPORTED = EMBEDDED_WALLET_UNSUPPORTED;
|
|
6046
|
+
exports.FAILURE_REASONS = FAILURE_REASONS;
|
|
6047
|
+
exports.NON_TERMINAL_STATES = NON_TERMINAL_STATES;
|
|
5471
6048
|
exports.OffchainAuthProvider = OffchainAuthProvider;
|
|
6049
|
+
exports.PARK_REASONS = PARK_REASONS;
|
|
5472
6050
|
exports.PrivyExpoProvider = PrivyExpoProvider;
|
|
6051
|
+
exports.RUN_STATES = RUN_STATES;
|
|
5473
6052
|
exports.SURFNET_RPC_URL = SURFNET_RPC_URL;
|
|
6053
|
+
exports.TERMINAL_STATES = TERMINAL_STATES;
|
|
6054
|
+
exports.apps = apps;
|
|
5474
6055
|
exports.bs58 = bs58;
|
|
5475
6056
|
exports.bufferExports = bufferExports;
|
|
6057
|
+
exports.builds = builds;
|
|
5476
6058
|
exports.completeLoginFromRedirect = completeLoginFromRedirect;
|
|
5477
6059
|
exports.completeLoginInPopup = completeLoginInPopup;
|
|
5478
6060
|
exports.confirmAndCheckTransaction = confirmAndCheckTransaction;
|
|
5479
|
-
exports.defaultInjectedEvmProvider = defaultInjectedEvmProvider;
|
|
5480
|
-
exports.defaultInjectedProvider = defaultInjectedProvider;
|
|
5481
6061
|
exports.deserializeTransaction = deserializeTransaction;
|
|
5482
6062
|
exports.embeddedRunEvmTransaction = embeddedRunEvmTransaction;
|
|
5483
6063
|
exports.embeddedSignAndSubmit = embeddedSignAndSubmit;
|
|
@@ -5497,12 +6077,11 @@ exports.logout = logout;
|
|
|
5497
6077
|
exports.normalizeSolanaRpcUrl = normalizeSolanaRpcUrl;
|
|
5498
6078
|
exports.onAuthLoadingChanged = onAuthLoadingChanged;
|
|
5499
6079
|
exports.onAuthStateChanged = onAuthStateChanged;
|
|
5500
|
-
exports.requestEip6963Providers = requestEip6963Providers;
|
|
5501
6080
|
exports.resolveSolanaRpcUrl = resolveSolanaRpcUrl;
|
|
5502
6081
|
exports.setAuthLoading = setAuthLoading;
|
|
5503
6082
|
exports.setCurrentUser = setCurrentUser;
|
|
5504
6083
|
exports.setPlatform = setPlatform;
|
|
5505
6084
|
exports.signInAnonymously = signInAnonymously;
|
|
5506
6085
|
exports.useAuth = useAuth;
|
|
5507
|
-
exports.
|
|
5508
|
-
//# sourceMappingURL=index-
|
|
6086
|
+
exports.useBuildRun = useBuildRun;
|
|
6087
|
+
//# sourceMappingURL=index.native-BaEZwiWd.js.map
|