integrate-sdk 0.7.56 → 0.7.58

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
@@ -246,7 +246,7 @@ The SDK implements OAuth 2.0 Authorization Code Flow with PKCE for secure author
246
246
 
247
247
  ```typescript
248
248
  // Check authorization
249
- if (!(await client.isAuthorized("github"))) {
249
+ if (!client.isAuthorized("github")) {
250
250
  await client.authorize("github"); // Opens popup or redirects
251
251
  }
252
252
 
@@ -1613,6 +1613,9 @@ class OAuthManager {
1613
1613
  getAllProviderTokens() {
1614
1614
  return new Map(this.providerTokens);
1615
1615
  }
1616
+ getProviderTokenFromCache(provider) {
1617
+ return this.providerTokens.get(provider);
1618
+ }
1616
1619
  async setProviderToken(provider, tokenData, context) {
1617
1620
  this.providerTokens.set(provider, tokenData);
1618
1621
  await this.saveProviderToken(provider, tokenData, context);
@@ -1707,6 +1710,34 @@ class OAuthManager {
1707
1710
  }
1708
1711
  }
1709
1712
  }
1713
+ loadProviderTokenSync(provider) {
1714
+ if (this.getTokenCallback) {
1715
+ return;
1716
+ }
1717
+ if (typeof window !== "undefined" && window.localStorage) {
1718
+ try {
1719
+ const key = `integrate_token_${provider}`;
1720
+ const stored = window.localStorage.getItem(key);
1721
+ if (stored) {
1722
+ return JSON.parse(stored);
1723
+ }
1724
+ } catch (error) {
1725
+ console.error(`Failed to load token for ${provider} from localStorage:`, error);
1726
+ }
1727
+ }
1728
+ return;
1729
+ }
1730
+ loadAllProviderTokensSync(providers) {
1731
+ if (this.getTokenCallback) {
1732
+ return;
1733
+ }
1734
+ for (const provider of providers) {
1735
+ const tokenData = this.loadProviderTokenSync(provider);
1736
+ if (tokenData) {
1737
+ this.providerTokens.set(provider, tokenData);
1738
+ }
1739
+ }
1740
+ }
1710
1741
  savePendingAuthToStorage(state, pendingAuth) {
1711
1742
  if (typeof window !== "undefined" && window.localStorage) {
1712
1743
  try {
@@ -1903,10 +1934,6 @@ class MCPClientBase {
1903
1934
  getProviderToken: config.getProviderToken,
1904
1935
  setProviderToken: config.setProviderToken
1905
1936
  });
1906
- const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1907
- this.oauthManager.loadAllProviderTokens(providers).catch((error) => {
1908
- console.error("Failed to load provider tokens:", error);
1909
- });
1910
1937
  for (const integration of this.integrations) {
1911
1938
  for (const toolName of integration.tools) {
1912
1939
  this.enabledToolNames.add(toolName);
@@ -1914,13 +1941,41 @@ class MCPClientBase {
1914
1941
  if (integration.oauth) {
1915
1942
  const provider = integration.oauth.provider;
1916
1943
  this.authState.set(provider, { authenticated: false });
1917
- this.oauthManager.getProviderToken(provider).then((tokenData) => {
1918
- if (tokenData) {
1919
- this.authState.set(provider, { authenticated: true });
1944
+ }
1945
+ }
1946
+ const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1947
+ const usingDatabaseCallbacks = !!config.getProviderToken;
1948
+ if (usingDatabaseCallbacks) {
1949
+ this.oauthManager.loadAllProviderTokens(providers).then(async () => {
1950
+ for (const integration of this.integrations) {
1951
+ if (integration.oauth) {
1952
+ const provider = integration.oauth.provider;
1953
+ try {
1954
+ const tokenData = await this.oauthManager.getProviderToken(provider);
1955
+ const currentState = this.authState.get(provider);
1956
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1957
+ this.authState.set(provider, { authenticated: !!tokenData });
1958
+ }
1959
+ } catch (error) {
1960
+ console.error(`Failed to check token for ${provider}:`, error);
1961
+ const currentState = this.authState.get(provider);
1962
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1963
+ this.authState.set(provider, { authenticated: false });
1964
+ }
1965
+ }
1920
1966
  }
1921
- }).catch((error) => {
1922
- console.error(`Failed to check token for ${provider}:`, error);
1923
- });
1967
+ }
1968
+ }).catch((error) => {
1969
+ console.error("Failed to load provider tokens:", error);
1970
+ });
1971
+ } else {
1972
+ this.oauthManager.loadAllProviderTokensSync(providers);
1973
+ for (const integration of this.integrations) {
1974
+ if (integration.oauth) {
1975
+ const provider = integration.oauth.provider;
1976
+ const tokenData = this.oauthManager.getProviderTokenFromCache(provider);
1977
+ this.authState.set(provider, { authenticated: !!tokenData });
1978
+ }
1924
1979
  }
1925
1980
  }
1926
1981
  const integrationIds = this.integrations.map((i) => i.id);
@@ -2230,17 +2285,16 @@ class MCPClientBase {
2230
2285
  isProviderAuthenticated(provider) {
2231
2286
  return this.authState.get(provider)?.authenticated ?? false;
2232
2287
  }
2233
- async isAuthorized(provider) {
2234
- const status = await this.oauthManager.checkAuthStatus(provider);
2235
- return status.authorized;
2288
+ isAuthorized(provider) {
2289
+ return this.authState.get(provider)?.authenticated ?? false;
2236
2290
  }
2237
- async authorizedProviders() {
2291
+ authorizedProviders() {
2238
2292
  const authorized = [];
2239
2293
  for (const integration of this.integrations) {
2240
2294
  if (integration.oauth) {
2241
- const status = await this.oauthManager.checkAuthStatus(integration.oauth.provider);
2242
- if (status.authorized) {
2243
- authorized.push(integration.oauth.provider);
2295
+ const provider = integration.oauth.provider;
2296
+ if (this.authState.get(provider)?.authenticated) {
2297
+ authorized.push(provider);
2244
2298
  }
2245
2299
  }
2246
2300
  }
@@ -1472,6 +1472,9 @@ class OAuthManager {
1472
1472
  getAllProviderTokens() {
1473
1473
  return new Map(this.providerTokens);
1474
1474
  }
1475
+ getProviderTokenFromCache(provider) {
1476
+ return this.providerTokens.get(provider);
1477
+ }
1475
1478
  async setProviderToken(provider, tokenData, context) {
1476
1479
  this.providerTokens.set(provider, tokenData);
1477
1480
  await this.saveProviderToken(provider, tokenData, context);
@@ -1566,6 +1569,34 @@ class OAuthManager {
1566
1569
  }
1567
1570
  }
1568
1571
  }
1572
+ loadProviderTokenSync(provider) {
1573
+ if (this.getTokenCallback) {
1574
+ return;
1575
+ }
1576
+ if (typeof window !== "undefined" && window.localStorage) {
1577
+ try {
1578
+ const key = `integrate_token_${provider}`;
1579
+ const stored = window.localStorage.getItem(key);
1580
+ if (stored) {
1581
+ return JSON.parse(stored);
1582
+ }
1583
+ } catch (error) {
1584
+ console.error(`Failed to load token for ${provider} from localStorage:`, error);
1585
+ }
1586
+ }
1587
+ return;
1588
+ }
1589
+ loadAllProviderTokensSync(providers) {
1590
+ if (this.getTokenCallback) {
1591
+ return;
1592
+ }
1593
+ for (const provider of providers) {
1594
+ const tokenData = this.loadProviderTokenSync(provider);
1595
+ if (tokenData) {
1596
+ this.providerTokens.set(provider, tokenData);
1597
+ }
1598
+ }
1599
+ }
1569
1600
  savePendingAuthToStorage(state, pendingAuth) {
1570
1601
  if (typeof window !== "undefined" && window.localStorage) {
1571
1602
  try {
@@ -1762,10 +1793,6 @@ class MCPClientBase {
1762
1793
  getProviderToken: config.getProviderToken,
1763
1794
  setProviderToken: config.setProviderToken
1764
1795
  });
1765
- const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1766
- this.oauthManager.loadAllProviderTokens(providers).catch((error) => {
1767
- console.error("Failed to load provider tokens:", error);
1768
- });
1769
1796
  for (const integration of this.integrations) {
1770
1797
  for (const toolName of integration.tools) {
1771
1798
  this.enabledToolNames.add(toolName);
@@ -1773,13 +1800,41 @@ class MCPClientBase {
1773
1800
  if (integration.oauth) {
1774
1801
  const provider = integration.oauth.provider;
1775
1802
  this.authState.set(provider, { authenticated: false });
1776
- this.oauthManager.getProviderToken(provider).then((tokenData) => {
1777
- if (tokenData) {
1778
- this.authState.set(provider, { authenticated: true });
1803
+ }
1804
+ }
1805
+ const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1806
+ const usingDatabaseCallbacks = !!config.getProviderToken;
1807
+ if (usingDatabaseCallbacks) {
1808
+ this.oauthManager.loadAllProviderTokens(providers).then(async () => {
1809
+ for (const integration of this.integrations) {
1810
+ if (integration.oauth) {
1811
+ const provider = integration.oauth.provider;
1812
+ try {
1813
+ const tokenData = await this.oauthManager.getProviderToken(provider);
1814
+ const currentState = this.authState.get(provider);
1815
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1816
+ this.authState.set(provider, { authenticated: !!tokenData });
1817
+ }
1818
+ } catch (error) {
1819
+ console.error(`Failed to check token for ${provider}:`, error);
1820
+ const currentState = this.authState.get(provider);
1821
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1822
+ this.authState.set(provider, { authenticated: false });
1823
+ }
1824
+ }
1779
1825
  }
1780
- }).catch((error) => {
1781
- console.error(`Failed to check token for ${provider}:`, error);
1782
- });
1826
+ }
1827
+ }).catch((error) => {
1828
+ console.error("Failed to load provider tokens:", error);
1829
+ });
1830
+ } else {
1831
+ this.oauthManager.loadAllProviderTokensSync(providers);
1832
+ for (const integration of this.integrations) {
1833
+ if (integration.oauth) {
1834
+ const provider = integration.oauth.provider;
1835
+ const tokenData = this.oauthManager.getProviderTokenFromCache(provider);
1836
+ this.authState.set(provider, { authenticated: !!tokenData });
1837
+ }
1783
1838
  }
1784
1839
  }
1785
1840
  const integrationIds = this.integrations.map((i) => i.id);
@@ -2089,17 +2144,16 @@ class MCPClientBase {
2089
2144
  isProviderAuthenticated(provider) {
2090
2145
  return this.authState.get(provider)?.authenticated ?? false;
2091
2146
  }
2092
- async isAuthorized(provider) {
2093
- const status = await this.oauthManager.checkAuthStatus(provider);
2094
- return status.authorized;
2147
+ isAuthorized(provider) {
2148
+ return this.authState.get(provider)?.authenticated ?? false;
2095
2149
  }
2096
- async authorizedProviders() {
2150
+ authorizedProviders() {
2097
2151
  const authorized = [];
2098
2152
  for (const integration of this.integrations) {
2099
2153
  if (integration.oauth) {
2100
- const status = await this.oauthManager.checkAuthStatus(integration.oauth.provider);
2101
- if (status.authorized) {
2102
- authorized.push(integration.oauth.provider);
2154
+ const provider = integration.oauth.provider;
2155
+ if (this.authState.get(provider)?.authenticated) {
2156
+ authorized.push(provider);
2103
2157
  }
2104
2158
  }
2105
2159
  }
@@ -1472,6 +1472,9 @@ class OAuthManager {
1472
1472
  getAllProviderTokens() {
1473
1473
  return new Map(this.providerTokens);
1474
1474
  }
1475
+ getProviderTokenFromCache(provider) {
1476
+ return this.providerTokens.get(provider);
1477
+ }
1475
1478
  async setProviderToken(provider, tokenData, context) {
1476
1479
  this.providerTokens.set(provider, tokenData);
1477
1480
  await this.saveProviderToken(provider, tokenData, context);
@@ -1566,6 +1569,34 @@ class OAuthManager {
1566
1569
  }
1567
1570
  }
1568
1571
  }
1572
+ loadProviderTokenSync(provider) {
1573
+ if (this.getTokenCallback) {
1574
+ return;
1575
+ }
1576
+ if (typeof window !== "undefined" && window.localStorage) {
1577
+ try {
1578
+ const key = `integrate_token_${provider}`;
1579
+ const stored = window.localStorage.getItem(key);
1580
+ if (stored) {
1581
+ return JSON.parse(stored);
1582
+ }
1583
+ } catch (error) {
1584
+ console.error(`Failed to load token for ${provider} from localStorage:`, error);
1585
+ }
1586
+ }
1587
+ return;
1588
+ }
1589
+ loadAllProviderTokensSync(providers) {
1590
+ if (this.getTokenCallback) {
1591
+ return;
1592
+ }
1593
+ for (const provider of providers) {
1594
+ const tokenData = this.loadProviderTokenSync(provider);
1595
+ if (tokenData) {
1596
+ this.providerTokens.set(provider, tokenData);
1597
+ }
1598
+ }
1599
+ }
1569
1600
  savePendingAuthToStorage(state, pendingAuth) {
1570
1601
  if (typeof window !== "undefined" && window.localStorage) {
1571
1602
  try {
@@ -1762,10 +1793,6 @@ class MCPClientBase {
1762
1793
  getProviderToken: config.getProviderToken,
1763
1794
  setProviderToken: config.setProviderToken
1764
1795
  });
1765
- const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1766
- this.oauthManager.loadAllProviderTokens(providers).catch((error) => {
1767
- console.error("Failed to load provider tokens:", error);
1768
- });
1769
1796
  for (const integration of this.integrations) {
1770
1797
  for (const toolName of integration.tools) {
1771
1798
  this.enabledToolNames.add(toolName);
@@ -1773,13 +1800,41 @@ class MCPClientBase {
1773
1800
  if (integration.oauth) {
1774
1801
  const provider = integration.oauth.provider;
1775
1802
  this.authState.set(provider, { authenticated: false });
1776
- this.oauthManager.getProviderToken(provider).then((tokenData) => {
1777
- if (tokenData) {
1778
- this.authState.set(provider, { authenticated: true });
1803
+ }
1804
+ }
1805
+ const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1806
+ const usingDatabaseCallbacks = !!config.getProviderToken;
1807
+ if (usingDatabaseCallbacks) {
1808
+ this.oauthManager.loadAllProviderTokens(providers).then(async () => {
1809
+ for (const integration of this.integrations) {
1810
+ if (integration.oauth) {
1811
+ const provider = integration.oauth.provider;
1812
+ try {
1813
+ const tokenData = await this.oauthManager.getProviderToken(provider);
1814
+ const currentState = this.authState.get(provider);
1815
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1816
+ this.authState.set(provider, { authenticated: !!tokenData });
1817
+ }
1818
+ } catch (error) {
1819
+ console.error(`Failed to check token for ${provider}:`, error);
1820
+ const currentState = this.authState.get(provider);
1821
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1822
+ this.authState.set(provider, { authenticated: false });
1823
+ }
1824
+ }
1779
1825
  }
1780
- }).catch((error) => {
1781
- console.error(`Failed to check token for ${provider}:`, error);
1782
- });
1826
+ }
1827
+ }).catch((error) => {
1828
+ console.error("Failed to load provider tokens:", error);
1829
+ });
1830
+ } else {
1831
+ this.oauthManager.loadAllProviderTokensSync(providers);
1832
+ for (const integration of this.integrations) {
1833
+ if (integration.oauth) {
1834
+ const provider = integration.oauth.provider;
1835
+ const tokenData = this.oauthManager.getProviderTokenFromCache(provider);
1836
+ this.authState.set(provider, { authenticated: !!tokenData });
1837
+ }
1783
1838
  }
1784
1839
  }
1785
1840
  const integrationIds = this.integrations.map((i) => i.id);
@@ -2089,17 +2144,16 @@ class MCPClientBase {
2089
2144
  isProviderAuthenticated(provider) {
2090
2145
  return this.authState.get(provider)?.authenticated ?? false;
2091
2146
  }
2092
- async isAuthorized(provider) {
2093
- const status = await this.oauthManager.checkAuthStatus(provider);
2094
- return status.authorized;
2147
+ isAuthorized(provider) {
2148
+ return this.authState.get(provider)?.authenticated ?? false;
2095
2149
  }
2096
- async authorizedProviders() {
2150
+ authorizedProviders() {
2097
2151
  const authorized = [];
2098
2152
  for (const integration of this.integrations) {
2099
2153
  if (integration.oauth) {
2100
- const status = await this.oauthManager.checkAuthStatus(integration.oauth.provider);
2101
- if (status.authorized) {
2102
- authorized.push(integration.oauth.provider);
2154
+ const provider = integration.oauth.provider;
2155
+ if (this.authState.get(provider)?.authenticated) {
2156
+ authorized.push(provider);
2103
2157
  }
2104
2158
  }
2105
2159
  }
package/dist/index.js CHANGED
@@ -1313,6 +1313,9 @@ class OAuthManager {
1313
1313
  getAllProviderTokens() {
1314
1314
  return new Map(this.providerTokens);
1315
1315
  }
1316
+ getProviderTokenFromCache(provider) {
1317
+ return this.providerTokens.get(provider);
1318
+ }
1316
1319
  async setProviderToken(provider, tokenData, context) {
1317
1320
  this.providerTokens.set(provider, tokenData);
1318
1321
  await this.saveProviderToken(provider, tokenData, context);
@@ -1407,6 +1410,34 @@ class OAuthManager {
1407
1410
  }
1408
1411
  }
1409
1412
  }
1413
+ loadProviderTokenSync(provider) {
1414
+ if (this.getTokenCallback) {
1415
+ return;
1416
+ }
1417
+ if (typeof window !== "undefined" && window.localStorage) {
1418
+ try {
1419
+ const key = `integrate_token_${provider}`;
1420
+ const stored = window.localStorage.getItem(key);
1421
+ if (stored) {
1422
+ return JSON.parse(stored);
1423
+ }
1424
+ } catch (error) {
1425
+ console.error(`Failed to load token for ${provider} from localStorage:`, error);
1426
+ }
1427
+ }
1428
+ return;
1429
+ }
1430
+ loadAllProviderTokensSync(providers) {
1431
+ if (this.getTokenCallback) {
1432
+ return;
1433
+ }
1434
+ for (const provider of providers) {
1435
+ const tokenData = this.loadProviderTokenSync(provider);
1436
+ if (tokenData) {
1437
+ this.providerTokens.set(provider, tokenData);
1438
+ }
1439
+ }
1440
+ }
1410
1441
  savePendingAuthToStorage(state, pendingAuth) {
1411
1442
  if (typeof window !== "undefined" && window.localStorage) {
1412
1443
  try {
@@ -1605,10 +1636,6 @@ class MCPClientBase {
1605
1636
  getProviderToken: config.getProviderToken,
1606
1637
  setProviderToken: config.setProviderToken
1607
1638
  });
1608
- const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1609
- this.oauthManager.loadAllProviderTokens(providers).catch((error) => {
1610
- console.error("Failed to load provider tokens:", error);
1611
- });
1612
1639
  for (const integration of this.integrations) {
1613
1640
  for (const toolName of integration.tools) {
1614
1641
  this.enabledToolNames.add(toolName);
@@ -1616,13 +1643,41 @@ class MCPClientBase {
1616
1643
  if (integration.oauth) {
1617
1644
  const provider = integration.oauth.provider;
1618
1645
  this.authState.set(provider, { authenticated: false });
1619
- this.oauthManager.getProviderToken(provider).then((tokenData) => {
1620
- if (tokenData) {
1621
- this.authState.set(provider, { authenticated: true });
1646
+ }
1647
+ }
1648
+ const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1649
+ const usingDatabaseCallbacks = !!config.getProviderToken;
1650
+ if (usingDatabaseCallbacks) {
1651
+ this.oauthManager.loadAllProviderTokens(providers).then(async () => {
1652
+ for (const integration of this.integrations) {
1653
+ if (integration.oauth) {
1654
+ const provider = integration.oauth.provider;
1655
+ try {
1656
+ const tokenData = await this.oauthManager.getProviderToken(provider);
1657
+ const currentState = this.authState.get(provider);
1658
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1659
+ this.authState.set(provider, { authenticated: !!tokenData });
1660
+ }
1661
+ } catch (error) {
1662
+ console.error(`Failed to check token for ${provider}:`, error);
1663
+ const currentState = this.authState.get(provider);
1664
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1665
+ this.authState.set(provider, { authenticated: false });
1666
+ }
1667
+ }
1622
1668
  }
1623
- }).catch((error) => {
1624
- console.error(`Failed to check token for ${provider}:`, error);
1625
- });
1669
+ }
1670
+ }).catch((error) => {
1671
+ console.error("Failed to load provider tokens:", error);
1672
+ });
1673
+ } else {
1674
+ this.oauthManager.loadAllProviderTokensSync(providers);
1675
+ for (const integration of this.integrations) {
1676
+ if (integration.oauth) {
1677
+ const provider = integration.oauth.provider;
1678
+ const tokenData = this.oauthManager.getProviderTokenFromCache(provider);
1679
+ this.authState.set(provider, { authenticated: !!tokenData });
1680
+ }
1626
1681
  }
1627
1682
  }
1628
1683
  const integrationIds = this.integrations.map((i) => i.id);
@@ -1932,17 +1987,16 @@ class MCPClientBase {
1932
1987
  isProviderAuthenticated(provider) {
1933
1988
  return this.authState.get(provider)?.authenticated ?? false;
1934
1989
  }
1935
- async isAuthorized(provider) {
1936
- const status = await this.oauthManager.checkAuthStatus(provider);
1937
- return status.authorized;
1990
+ isAuthorized(provider) {
1991
+ return this.authState.get(provider)?.authenticated ?? false;
1938
1992
  }
1939
- async authorizedProviders() {
1993
+ authorizedProviders() {
1940
1994
  const authorized = [];
1941
1995
  for (const integration of this.integrations) {
1942
1996
  if (integration.oauth) {
1943
- const status = await this.oauthManager.checkAuthStatus(integration.oauth.provider);
1944
- if (status.authorized) {
1945
- authorized.push(integration.oauth.provider);
1997
+ const provider = integration.oauth.provider;
1998
+ if (this.authState.get(provider)?.authenticated) {
1999
+ authorized.push(provider);
1946
2000
  }
1947
2001
  }
1948
2002
  }
package/dist/server.js CHANGED
@@ -1306,6 +1306,9 @@ class OAuthManager {
1306
1306
  getAllProviderTokens() {
1307
1307
  return new Map(this.providerTokens);
1308
1308
  }
1309
+ getProviderTokenFromCache(provider) {
1310
+ return this.providerTokens.get(provider);
1311
+ }
1309
1312
  async setProviderToken(provider, tokenData, context) {
1310
1313
  this.providerTokens.set(provider, tokenData);
1311
1314
  await this.saveProviderToken(provider, tokenData, context);
@@ -1400,6 +1403,34 @@ class OAuthManager {
1400
1403
  }
1401
1404
  }
1402
1405
  }
1406
+ loadProviderTokenSync(provider) {
1407
+ if (this.getTokenCallback) {
1408
+ return;
1409
+ }
1410
+ if (typeof window !== "undefined" && window.localStorage) {
1411
+ try {
1412
+ const key = `integrate_token_${provider}`;
1413
+ const stored = window.localStorage.getItem(key);
1414
+ if (stored) {
1415
+ return JSON.parse(stored);
1416
+ }
1417
+ } catch (error) {
1418
+ console.error(`Failed to load token for ${provider} from localStorage:`, error);
1419
+ }
1420
+ }
1421
+ return;
1422
+ }
1423
+ loadAllProviderTokensSync(providers) {
1424
+ if (this.getTokenCallback) {
1425
+ return;
1426
+ }
1427
+ for (const provider of providers) {
1428
+ const tokenData = this.loadProviderTokenSync(provider);
1429
+ if (tokenData) {
1430
+ this.providerTokens.set(provider, tokenData);
1431
+ }
1432
+ }
1433
+ }
1403
1434
  savePendingAuthToStorage(state, pendingAuth) {
1404
1435
  if (typeof window !== "undefined" && window.localStorage) {
1405
1436
  try {
@@ -1596,10 +1627,6 @@ class MCPClientBase {
1596
1627
  getProviderToken: config.getProviderToken,
1597
1628
  setProviderToken: config.setProviderToken
1598
1629
  });
1599
- const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1600
- this.oauthManager.loadAllProviderTokens(providers).catch((error) => {
1601
- console.error("Failed to load provider tokens:", error);
1602
- });
1603
1630
  for (const integration of this.integrations) {
1604
1631
  for (const toolName of integration.tools) {
1605
1632
  this.enabledToolNames.add(toolName);
@@ -1607,13 +1634,41 @@ class MCPClientBase {
1607
1634
  if (integration.oauth) {
1608
1635
  const provider = integration.oauth.provider;
1609
1636
  this.authState.set(provider, { authenticated: false });
1610
- this.oauthManager.getProviderToken(provider).then((tokenData) => {
1611
- if (tokenData) {
1612
- this.authState.set(provider, { authenticated: true });
1637
+ }
1638
+ }
1639
+ const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
1640
+ const usingDatabaseCallbacks = !!config.getProviderToken;
1641
+ if (usingDatabaseCallbacks) {
1642
+ this.oauthManager.loadAllProviderTokens(providers).then(async () => {
1643
+ for (const integration of this.integrations) {
1644
+ if (integration.oauth) {
1645
+ const provider = integration.oauth.provider;
1646
+ try {
1647
+ const tokenData = await this.oauthManager.getProviderToken(provider);
1648
+ const currentState = this.authState.get(provider);
1649
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1650
+ this.authState.set(provider, { authenticated: !!tokenData });
1651
+ }
1652
+ } catch (error) {
1653
+ console.error(`Failed to check token for ${provider}:`, error);
1654
+ const currentState = this.authState.get(provider);
1655
+ if (currentState && !currentState.authenticated && !currentState.lastError) {
1656
+ this.authState.set(provider, { authenticated: false });
1657
+ }
1658
+ }
1613
1659
  }
1614
- }).catch((error) => {
1615
- console.error(`Failed to check token for ${provider}:`, error);
1616
- });
1660
+ }
1661
+ }).catch((error) => {
1662
+ console.error("Failed to load provider tokens:", error);
1663
+ });
1664
+ } else {
1665
+ this.oauthManager.loadAllProviderTokensSync(providers);
1666
+ for (const integration of this.integrations) {
1667
+ if (integration.oauth) {
1668
+ const provider = integration.oauth.provider;
1669
+ const tokenData = this.oauthManager.getProviderTokenFromCache(provider);
1670
+ this.authState.set(provider, { authenticated: !!tokenData });
1671
+ }
1617
1672
  }
1618
1673
  }
1619
1674
  const integrationIds = this.integrations.map((i) => i.id);
@@ -1923,17 +1978,16 @@ class MCPClientBase {
1923
1978
  isProviderAuthenticated(provider) {
1924
1979
  return this.authState.get(provider)?.authenticated ?? false;
1925
1980
  }
1926
- async isAuthorized(provider) {
1927
- const status = await this.oauthManager.checkAuthStatus(provider);
1928
- return status.authorized;
1981
+ isAuthorized(provider) {
1982
+ return this.authState.get(provider)?.authenticated ?? false;
1929
1983
  }
1930
- async authorizedProviders() {
1984
+ authorizedProviders() {
1931
1985
  const authorized = [];
1932
1986
  for (const integration of this.integrations) {
1933
1987
  if (integration.oauth) {
1934
- const status = await this.oauthManager.checkAuthStatus(integration.oauth.provider);
1935
- if (status.authorized) {
1936
- authorized.push(integration.oauth.provider);
1988
+ const provider = integration.oauth.provider;
1989
+ if (this.authState.get(provider)?.authenticated) {
1990
+ authorized.push(provider);
1937
1991
  }
1938
1992
  }
1939
1993
  }
@@ -263,29 +263,32 @@ export declare class MCPClientBase<TIntegrations extends readonly MCPIntegration
263
263
  isProviderAuthenticated(provider: string): boolean;
264
264
  /**
265
265
  * Check if a provider is authorized via OAuth
266
- * Queries the MCP server to verify OAuth token validity
266
+ * Returns the cached authorization status that is automatically updated when
267
+ * authorize() or disconnectProvider() are called
267
268
  *
268
269
  * @param provider - Provider name (github, gmail, etc.)
269
- * @returns Authorization status
270
+ * @returns Authorization status from cache
270
271
  *
271
272
  * @example
272
273
  * ```typescript
273
- * const isAuthorized = await client.isAuthorized('github');
274
+ * const isAuthorized = client.isAuthorized('github');
274
275
  * if (!isAuthorized) {
275
276
  * await client.authorize('github');
277
+ * // isAuthorized is now automatically true
278
+ * console.log(client.isAuthorized('github')); // true
276
279
  * }
277
280
  * ```
278
281
  */
279
- isAuthorized(provider: string): Promise<boolean>;
282
+ isAuthorized(provider: string): boolean;
280
283
  /**
281
284
  * Get list of all authorized providers
282
- * Checks all configured OAuth providers and returns names of authorized ones
285
+ * Returns cached authorization status for all configured OAuth providers
283
286
  *
284
287
  * @returns Array of authorized provider names
285
288
  *
286
289
  * @example
287
290
  * ```typescript
288
- * const authorized = await client.authorizedProviders();
291
+ * const authorized = client.authorizedProviders();
289
292
  * console.log('Authorized services:', authorized); // ['github', 'gmail']
290
293
  *
291
294
  * // Check if specific service is in the list
@@ -294,7 +297,7 @@ export declare class MCPClientBase<TIntegrations extends readonly MCPIntegration
294
297
  * }
295
298
  * ```
296
299
  */
297
- authorizedProviders(): Promise<string[]>;
300
+ authorizedProviders(): string[];
298
301
  /**
299
302
  * Get detailed authorization status for a provider
300
303
  *
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,OAAO,EAEP,mBAAmB,EAGpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAiB,eAAe,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACrG,OAAO,EAGL,KAAK,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MAAM,EAAE,eAAe,CAAC,aAAa,CAAC,GACrC,SAAS,CAAC,aAAa,CAAC,CAkE1B;AA0ED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAetD"}
@@ -111,6 +111,13 @@ export declare class OAuthManager {
111
111
  * Get all provider tokens
112
112
  */
113
113
  getAllProviderTokens(): Map<string, ProviderTokenData>;
114
+ /**
115
+ * Get provider token from in-memory cache synchronously
116
+ * Only returns cached tokens, does not call database callbacks
117
+ * Used for immediate synchronous checks after tokens are loaded
118
+ * @param provider - Provider name (e.g., 'github', 'gmail')
119
+ */
120
+ getProviderTokenFromCache(provider: string): ProviderTokenData | undefined;
114
121
  /**
115
122
  * Set provider token (for manual token management)
116
123
  * Uses callback if provided, otherwise uses localStorage
@@ -152,6 +159,19 @@ export declare class OAuthManager {
152
159
  * Load all provider tokens from database (via callback) or localStorage on initialization
153
160
  */
154
161
  loadAllProviderTokens(providers: string[]): Promise<void>;
162
+ /**
163
+ * Load provider token synchronously from localStorage only
164
+ * Returns undefined if not found or if using database callbacks
165
+ * This method is synchronous and should only be used during initialization
166
+ * when database callbacks are NOT configured
167
+ */
168
+ private loadProviderTokenSync;
169
+ /**
170
+ * Load all provider tokens synchronously from localStorage on initialization
171
+ * Only works when database callbacks are NOT configured
172
+ * This ensures tokens are available immediately for isAuthorized() calls
173
+ */
174
+ loadAllProviderTokensSync(providers: string[]): void;
155
175
  /**
156
176
  * Save pending auth to localStorage (for redirect flows)
157
177
  * Uses localStorage instead of sessionStorage because OAuth may open in a new tab,
@@ -1 +1 @@
1
- {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/oauth/manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EACV,eAAe,EAEf,UAAU,EAGV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AACpB,OAAO,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;CAGd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "integrate-sdk",
3
- "version": "0.7.56",
3
+ "version": "0.7.58",
4
4
  "description": "Type-safe 3rd party integration SDK for the Integrate MCP server",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",