@ab-org/predicate-market-sdk 2.2.0-beta.1 → 2.2.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,7 +97,7 @@ const policy = createPredicateMarketPolicyAdapter({
97
97
 
98
98
  ## Configure SignInModal
99
99
 
100
- The SDK ships with **bundled auth config** (Google client id, Twitter client id, CubeSigner env/org) so you can call `initSDK` with only `signIn`. Override via env (`NEXT_PUBLIC_*`) or by passing options to `initSDK`.
100
+ The SDK ships with **bundled auth config** (Google client id, Twitter client id, CubeSigner env/org) so you can call `initSDK` with only `signIn`. Override via env (`NEXT_PUBLIC_*`) or by passing options to `initSDK`. Cubist session keepalive also reads **`NEXT_PUBLIC_CUBE_KEEPALIVE_INTERVAL_MS`** and falls back to **`300000`** ms (5 minutes).
101
101
 
102
102
  **Google / X in `SignInModal`** use the SDK's **bundled OIDC relay auth**: a **popup** opens your **`NEXT_PUBLIC_RELAY_ORIGIN`** routes **`/relay/google`** and **`/relay/x`**, then the SDK's built-in **WalletAccount** bridge turns the returned OIDC token into a CubeSigner-backed EVM session provider.
103
103
 
@@ -1,5 +1,5 @@
1
- import { getSDKConfig } from './chunk-JFRRJXOJ.js';
2
- import './chunk-SHLNBZBY.js';
1
+ import { getSDKConfig } from './chunk-55FTUSW7.js';
2
+ import './chunk-ITLN6GHC.js';
3
3
  import './chunk-WHTI52FI.js';
4
4
  import { sessionStore, createDefaultInjectedWalletRegistry, WalletConnector } from '@ab-org/sdk-core';
5
5
  import { CubistSocialProvider } from '@ab-org/sdk-core/social/provider';
@@ -27,7 +27,16 @@ async function doAutoReconnect() {
27
27
  );
28
28
  }
29
29
  const connector = new WalletConnector(adapters);
30
- return connector.tryAutoReconnect();
30
+ try {
31
+ const restoredSession = await connector.tryAutoReconnect();
32
+ if (!restoredSession) {
33
+ sessionStore.clearSession();
34
+ }
35
+ return restoredSession;
36
+ } catch {
37
+ sessionStore.clearSession();
38
+ return null;
39
+ }
31
40
  }
32
41
 
33
42
  export { tryAutoReconnect };
@@ -1,6 +1,6 @@
1
1
  // src/core.ts
2
2
  function tryAutoReconnect() {
3
- return import('./autoReconnect-IFPVI2XU.js').then(({ tryAutoReconnect: reconnect }) => reconnect());
3
+ return import('./autoReconnect-UEPGLSA7.js').then(({ tryAutoReconnect: reconnect }) => reconnect());
4
4
  }
5
5
 
6
6
  export { tryAutoReconnect };
@@ -1,5 +1,7 @@
1
- import { getOptionalEnv, setMerchantBaseUrl } from './chunk-SHLNBZBY.js';
1
+ import { getOptionalEnv, setMerchantBaseUrl } from './chunk-ITLN6GHC.js';
2
2
  import { getSDKConfig, initSDK } from './chunk-WHTI52FI.js';
3
+ import { sessionStore } from '@ab-org/sdk-core';
4
+ import { refreshCubeSignerSessionData } from '@ab-org/sdk-core/social/auth';
3
5
  import axios from 'axios';
4
6
 
5
7
  // src/auth/bundledConfig.ts
@@ -99,11 +101,54 @@ function getFixedAuthConfig() {
99
101
  cubeSigner: cubeSignerFromEnv ?? bundled.cubeSigner
100
102
  };
101
103
  }
104
+ var CUBE_KEEPALIVE_INTERVAL_MS = 5 * 60 * 1e3;
105
+ function getCubistKeepAliveIntervalMs() {
106
+ const rawValue = getOptionalEnv("CUBE_KEEPALIVE_INTERVAL_MS");
107
+ if (!rawValue) return CUBE_KEEPALIVE_INTERVAL_MS;
108
+ const parsed = Number.parseInt(rawValue, 10);
109
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : CUBE_KEEPALIVE_INTERVAL_MS;
110
+ }
111
+ var cubistKeepAliveTimer = null;
112
+ var cubistKeepAlivePending = null;
113
+ function isCubistSession(session) {
114
+ if (!session?.sessionData) return false;
115
+ return session.walletType === "social" || session.authSource === "google" || session.authSource === "twitter";
116
+ }
117
+ function isAuthorizationError(error) {
118
+ return error instanceof Error && /\(401\)|\(403\)/.test(error.message);
119
+ }
120
+ async function refreshActiveCubistSession() {
121
+ const session = sessionStore.getState().session;
122
+ if (!isCubistSession(session)) return;
123
+ try {
124
+ const refreshedSessionData = await refreshCubeSignerSessionData(session.sessionData);
125
+ const latestSession = sessionStore.getState().session;
126
+ if (!latestSession || latestSession.sessionId !== session.sessionId) return;
127
+ sessionStore.setSession({
128
+ ...latestSession,
129
+ sessionData: refreshedSessionData
130
+ });
131
+ } catch (error) {
132
+ if (isAuthorizationError(error)) {
133
+ sessionStore.clearSession();
134
+ }
135
+ }
136
+ }
102
137
  function scheduleAutoReconnect() {
103
138
  if (typeof window === "undefined") return;
104
- void import('./autoReconnect-IFPVI2XU.js').then(({ tryAutoReconnect }) => tryAutoReconnect()).catch(() => {
139
+ void import('./autoReconnect-UEPGLSA7.js').then(({ tryAutoReconnect }) => tryAutoReconnect()).catch(() => {
105
140
  });
106
141
  }
142
+ function scheduleCubistKeepAlive() {
143
+ if (typeof window === "undefined") return;
144
+ if (cubistKeepAliveTimer !== null) return;
145
+ const keepAliveIntervalMs = getCubistKeepAliveIntervalMs();
146
+ cubistKeepAliveTimer = window.setInterval(() => {
147
+ cubistKeepAlivePending ?? (cubistKeepAlivePending = refreshActiveCubistSession().finally(() => {
148
+ cubistKeepAlivePending = null;
149
+ }));
150
+ }, keepAliveIntervalMs);
151
+ }
107
152
  function initSDK2(config = {}) {
108
153
  const { merchantBaseUrl, registerUser, ...rest } = config;
109
154
  const fixed = getFixedAuthConfig();
@@ -141,6 +186,7 @@ function initSDK2(config = {}) {
141
186
  }
142
187
  initSDK(merged);
143
188
  scheduleAutoReconnect();
189
+ scheduleCubistKeepAlive();
144
190
  }
145
191
  function getSDKConfig2() {
146
192
  return getSDKConfig();
@@ -1,4 +1,4 @@
1
- import { getEnv } from './chunk-SHLNBZBY.js';
1
+ import { getEnv } from './chunk-ITLN6GHC.js';
2
2
 
3
3
  // src/constants/chains.ts
4
4
  var TENDERLY_BSC_3131 = {
@@ -1,4 +1,4 @@
1
- import { setMerchantBaseUrl, getMerchantBaseUrl } from './chunk-SHLNBZBY.js';
1
+ import { setMerchantBaseUrl, getMerchantBaseUrl } from './chunk-ITLN6GHC.js';
2
2
  import axios from 'axios';
3
3
 
4
4
  var merchantApiConfig = {};
@@ -1,11 +1,11 @@
1
1
  import { getExplorerUrl } from './chunk-XB2DFS2W.js';
2
- import { getChains, registerPlatform, quote, getWithdrawOrder } from './chunk-TPMI3XWV.js';
3
- import { getEnv } from './chunk-SHLNBZBY.js';
2
+ import { getChains, registerPlatform, quote, getWithdrawOrder } from './chunk-AAFQWHHY.js';
3
+ import { getEnv } from './chunk-ITLN6GHC.js';
4
4
  import { clientIds, stage } from './chunk-6YQEHB6P.js';
5
5
  import { getSDKConfig } from './chunk-WHTI52FI.js';
6
6
  import { cache_exports } from './chunk-YX56ZGDB.js';
7
7
  import { useEffect, useState, useRef, useMemo, useCallback } from 'react';
8
- import { sessionStore, createDefaultInjectedWalletRegistry, WalletConnector } from '@ab-org/sdk-core';
8
+ import { sessionStore, getSupportedChainFromEvmChainId, createSessionCapabilityPolicy, createChainContext, CUBIST_CAPABILITIES, createDefaultInjectedWalletRegistry, WalletConnector } from '@ab-org/sdk-core';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
  import qrcode from 'qrcode-generator';
11
11
 
@@ -812,6 +812,14 @@ var Toast = ({ message, variant = "info", duration, onClose }) => {
812
812
  async function loadWalletAccount2() {
813
813
  return import('./account-F5Z2SMJE.js');
814
814
  }
815
+ var SOCIAL_ADAPTER_ID = "cubist";
816
+ function persistSocialAdapterId() {
817
+ try {
818
+ const storage = typeof localStorage !== "undefined" ? localStorage : null;
819
+ storage?.setItem("ab:wallet:adapterId", SOCIAL_ADAPTER_ID);
820
+ } catch {
821
+ }
822
+ }
815
823
  var SignInModal = ({
816
824
  title = "Welcome to PredicateMarket",
817
825
  socialProviders,
@@ -890,8 +898,6 @@ var SignInModal = ({
890
898
  onSocialClick: async (providerId) => {
891
899
  setSocialLoadingProvider(providerId);
892
900
  sessionStore.clearSession();
893
- let walletAccount = null;
894
- let address = "";
895
901
  try {
896
902
  const { default: WalletAccount2 } = await loadWalletAccount2();
897
903
  WalletAccount2.clearInstance();
@@ -900,19 +906,33 @@ var SignInModal = ({
900
906
  setToastError("Social login failed, please try again");
901
907
  return;
902
908
  }
903
- walletAccount = await WalletAccount2.getInstance(oidcToken);
904
- onCubeSignerSession?.(walletAccount.getCubeSignerSession());
909
+ const walletAccount = await WalletAccount2.getInstance(oidcToken);
910
+ const cubeSignerSession = walletAccount.getCubeSignerSession();
911
+ onCubeSignerSession?.(cubeSignerSession);
905
912
  cache_exports.set("oidcToken", oidcToken, false);
906
- const res = await walletAccount.eth_accounts();
907
- address = res?.[0] || "";
913
+ const [address] = await walletAccount.eth_accounts();
914
+ if (!address) {
915
+ throw new Error("Social wallet did not return an account");
916
+ }
917
+ const chainId = await walletAccount.eth_chainId();
918
+ const chain = getSupportedChainFromEvmChainId(chainId);
908
919
  const authSource = providerId === "x" ? "twitter" : providerId;
920
+ const capabilityPolicy = sdkConfig.cubeSigner?.defaultSessionPolicy ? createSessionCapabilityPolicy(sdkConfig.cubeSigner.defaultSessionPolicy) : void 0;
909
921
  const session = {
910
922
  address,
911
- chain: "BSC",
923
+ chain,
912
924
  provider: walletAccount,
913
925
  walletType: "social",
914
- authSource
926
+ authSource,
927
+ sessionId: `${authSource}:${address.toLowerCase()}`,
928
+ expiresAt: capabilityPolicy?.expiresAt,
929
+ capabilities: CUBIST_CAPABILITIES,
930
+ sessionData: cubeSignerSession.sessionData,
931
+ chainContext: createChainContext(chain),
932
+ capabilityPolicy
915
933
  };
934
+ persistSocialAdapterId();
935
+ sessionStore.setSession(session);
916
936
  onSuccess?.(session);
917
937
  } catch (error) {
918
938
  setToastError(error?.message ?? "Failed to get wallet account, please try again");
@@ -2022,7 +2042,7 @@ var DepositModal = ({
2022
2042
  useEffect(() => {
2023
2043
  if (view !== "transfer") return;
2024
2044
  if (!session?.address || !chain) return;
2025
- const platform_contract_address = getEnv("PLATFORM_CONTRACT_ADDRESS") || session.address;
2045
+ const platform_contract_address = depositAddress || session.address;
2026
2046
  registerPlatform({
2027
2047
  platform_contract_address,
2028
2048
  chain_id: chain
@@ -2032,7 +2052,7 @@ var DepositModal = ({
2032
2052
  }
2033
2053
  }).catch(() => {
2034
2054
  });
2035
- }, [view, chain, session?.address]);
2055
+ }, [view, chain, session?.address, depositAddress]);
2036
2056
  useEffect(() => {
2037
2057
  if (!apiChains?.length || !token || !chain) {
2038
2058
  setApiQuote(null);
@@ -2158,7 +2178,7 @@ var DepositModal = ({
2158
2178
  chain,
2159
2179
  tokenOptions,
2160
2180
  chainOptions,
2161
- depositAddress: depositAddress ?? internalDepositAddress,
2181
+ depositAddress: internalDepositAddress,
2162
2182
  minimumDeposit,
2163
2183
  qrCenterIcon,
2164
2184
  quote: apiQuote,
@@ -3573,7 +3593,12 @@ var WithdrawModal = ({
3573
3593
  ) })
3574
3594
  ]
3575
3595
  }
3576
- )
3596
+ ),
3597
+ !orderSucceeded && /* @__PURE__ */ jsxs("span", { className: "absdk-predicate-withdraw-modal__receive-amount", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textPrimary, opacity: !trackingWithdraw && amount && Number(amount) > 0 ? 1 : 0 }, children: [
3598
+ /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-label", children: "You will receive :" }),
3599
+ " ",
3600
+ /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-value", children: receiveAmount })
3601
+ ] })
3577
3602
  ] }) })
3578
3603
  ]
3579
3604
  }
@@ -3585,12 +3610,7 @@ var WithdrawModal = ({
3585
3610
  )
3586
3611
  ]
3587
3612
  }
3588
- ),
3589
- !orderSucceeded && /* @__PURE__ */ jsxs("span", { className: "absdk-predicate-withdraw-modal__receive-amount", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textPrimary, opacity: !trackingWithdraw && amount && Number(amount) > 0 ? 1 : 0 }, children: [
3590
- /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-label", children: "You will receive :" }),
3591
- " ",
3592
- /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-value", children: receiveAmount })
3593
- ] })
3613
+ )
3594
3614
  ]
3595
3615
  }
3596
3616
  ),
@@ -1,6 +1,6 @@
1
- import { getChainInfo, getFundingTokenAddress, DEFAULT_FUNDING_CHAIN_ID } from './chunk-F2UPP3YC.js';
2
- import { getChains, createOrder } from './chunk-TPMI3XWV.js';
3
- import { getEnv } from './chunk-SHLNBZBY.js';
1
+ import { getChainInfo, getFundingTokenAddress, DEFAULT_FUNDING_CHAIN_ID } from './chunk-6MMOYCWR.js';
2
+ import { getChains, createOrder } from './chunk-AAFQWHHY.js';
3
+ import { getEnv } from './chunk-ITLN6GHC.js';
4
4
  import { sessionStore, createSessionCapabilityPolicy } from '@ab-org/sdk-core';
5
5
  import { formatUnits } from 'viem';
6
6
 
@@ -27,6 +27,11 @@ function readProcessEnvStatic(key) {
27
27
  return pick(process.env.NEXT_PUBLIC_CUBE_REG, process.env.CUBE_REG);
28
28
  case "RELAY_ORIGIN":
29
29
  return pick(process.env.NEXT_PUBLIC_RELAY_ORIGIN, process.env.RELAY_ORIGIN);
30
+ case "CUBE_KEEPALIVE_INTERVAL_MS":
31
+ return pick(
32
+ process.env.NEXT_PUBLIC_CUBE_KEEPALIVE_INTERVAL_MS,
33
+ process.env.CUBE_KEEPALIVE_INTERVAL_MS
34
+ );
30
35
  case "FUNDING_TOKEN_SYMBOL":
31
36
  return pick(process.env.NEXT_PUBLIC_FUNDING_TOKEN_SYMBOL, process.env.FUNDING_TOKEN_SYMBOL) || "USDT";
32
37
  default:
package/dist/core.js CHANGED
@@ -1,6 +1,6 @@
1
- export { tryAutoReconnect } from './chunk-LOJTP47I.js';
2
- export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-F2UPP3YC.js';
1
+ export { tryAutoReconnect } from './chunk-3AR6ZOML.js';
2
+ export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-6MMOYCWR.js';
3
3
  export { getExplorerUrl } from './chunk-XB2DFS2W.js';
4
- export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-JFRRJXOJ.js';
5
- export { getEnv } from './chunk-SHLNBZBY.js';
4
+ export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-55FTUSW7.js';
5
+ export { getEnv } from './chunk-ITLN6GHC.js';
6
6
  import './chunk-WHTI52FI.js';
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  export { notifyTwitterCallback } from './chunk-UAXKA6QC.js';
2
- export { tryAutoReconnect } from './chunk-LOJTP47I.js';
3
- export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-VKONTJQE.js';
4
- export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-F2UPP3YC.js';
5
- export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-5PO7MS5U.js';
2
+ export { tryAutoReconnect } from './chunk-3AR6ZOML.js';
3
+ export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-FIDON2BY.js';
4
+ export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-6MMOYCWR.js';
5
+ export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-CFWENKGK.js';
6
6
  export { getExplorerUrl } from './chunk-XB2DFS2W.js';
7
- export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-TPMI3XWV.js';
8
- export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-JFRRJXOJ.js';
9
- export { getEnv } from './chunk-SHLNBZBY.js';
7
+ export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-AAFQWHHY.js';
8
+ export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-55FTUSW7.js';
9
+ export { getEnv } from './chunk-ITLN6GHC.js';
10
10
  import './chunk-6YQEHB6P.js';
11
11
  import './chunk-WHTI52FI.js';
12
12
  import './chunk-YX56ZGDB.js';
package/dist/merchant.js CHANGED
@@ -1,4 +1,4 @@
1
- export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-VKONTJQE.js';
2
- import './chunk-F2UPP3YC.js';
3
- export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-TPMI3XWV.js';
4
- import './chunk-SHLNBZBY.js';
1
+ export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-FIDON2BY.js';
2
+ import './chunk-6MMOYCWR.js';
3
+ export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-AAFQWHHY.js';
4
+ import './chunk-ITLN6GHC.js';
package/dist/react.js CHANGED
@@ -1,7 +1,7 @@
1
- export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-5PO7MS5U.js';
1
+ export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-CFWENKGK.js';
2
2
  import './chunk-XB2DFS2W.js';
3
- import './chunk-TPMI3XWV.js';
4
- import './chunk-SHLNBZBY.js';
3
+ import './chunk-AAFQWHHY.js';
4
+ import './chunk-ITLN6GHC.js';
5
5
  import './chunk-6YQEHB6P.js';
6
6
  import './chunk-WHTI52FI.js';
7
7
  import './chunk-YX56ZGDB.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ab-org/predicate-market-sdk",
3
- "version": "2.2.0-beta.1",
3
+ "version": "2.2.0-beta.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/**/*",
@@ -39,7 +39,7 @@
39
39
  "axios": "^1.13.6",
40
40
  "qrcode-generator": "^2.0.4",
41
41
  "viem": "2.21.54",
42
- "@ab-org/sdk-core": "0.2.2-beta.0"
42
+ "@ab-org/sdk-core": "0.3.0-beta.1"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "react": ">=18"