@ab-org/predicate-market-sdk 2.1.2 → 2.2.0-beta.2

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,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